From 60c6bf9f6916b6ae2c05a499675ff54480256ece Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Fri, 11 Sep 2015 19:40:33 +0200 Subject: more towards views --- xml/test/camera.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'xml') diff --git a/xml/test/camera.xml b/xml/test/camera.xml index 5b486ee..815a50e 100644 --- a/xml/test/camera.xml +++ b/xml/test/camera.xml @@ -277,9 +277,9 @@ 16 R sensor_temperature - - formuu1 - formuu2 + + formuu1 + formuu2 enumm2 -- cgit v1.2.3 From 2dfb23016c39a331bf5ed4111b630dffa330edbb Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Mon, 14 Sep 2015 11:56:38 +0200 Subject: views working fine, units in progress --- pcilib/CMakeLists.txt | 4 +-- pcilib/pci.c | 14 +++++--- pcilib/pci.h | 5 ++- pcilib/unit.c | 34 ++++++++++++++++++ pcilib/unit.h | 30 ++++++++++++++++ pcilib/views.c | 99 +++++++++++++++++++++++++++++---------------------- pcilib/views.h | 3 ++ pcilib/xml.c | 71 ++++++++++++++++++++++++++++++++++-- pcitool/cli.c | 67 ++++++++++++++++++++++++++++------ xml/test/camera.xml | 4 +-- 10 files changed, 267 insertions(+), 64 deletions(-) create mode 100644 pcilib/unit.c create mode 100644 pcilib/unit.h (limited to 'xml') diff --git a/pcilib/CMakeLists.txt b/pcilib/CMakeLists.txt index 48363f6..1f3e646 100644 --- a/pcilib/CMakeLists.txt +++ b/pcilib/CMakeLists.txt @@ -9,9 +9,9 @@ include_directories( set(HEADERS pcilib.h pci.h export.h bar.h fifo.h model.h bank.h register.h views.h xml.h kmem.h irq.h locking.h lock.h dma.h event.h plugin.h tools.h error.h -debug.h env.h version.h config.h ) +debug.h env.h version.h config.h unit.h) add_library(pcilib SHARED pci.c export.c bar.c fifo.c model.c bank.c -register.c views.c xml.c kmem.c irq.c locking.c lock.c dma.c event.c plugin.c tools.c error.c debug.c env.c ) +register.c views.c xml.c kmem.c irq.c locking.c lock.c dma.c event.c plugin.c tools.c error.c debug.c env.c unit.c) target_link_libraries(pcilib dma protocols ${CMAKE_THREAD_LIBS_INIT} ${UFODECODE_LIBRARIES} ${CMAKE_DL_LIBS} ${EXTRA_SYSTEM_LIBS} ${LIBXML2_LIBRARIES} ${PYTHON_LIBRARIES}) diff --git a/pcilib/pci.c b/pcilib/pci.c index 8c178f6..2742240 100644 --- a/pcilib/pci.c +++ b/pcilib/pci.c @@ -145,19 +145,24 @@ pcilib_t *pcilib_open(const char *device, const char *model) { ctx->register_ctx = (pcilib_register_context_t *)malloc(PCILIB_DEFAULT_REGISTER_SPACE * sizeof(pcilib_register_context_t)); ctx->enum_views = (pcilib_view_enum2_t *)malloc(PCILIB_DEFAULT_VIEW_SPACE * sizeof(pcilib_view_enum2_t)); ctx->formula_views = (pcilib_view_formula_t*)malloc(PCILIB_DEFAULT_VIEW_SPACE * sizeof(pcilib_view_formula_t)); + ctx->alloc_units=PCILIB_DEFAULT_UNIT_SPACE; + ctx->units=(pcilib_unit_t*)malloc(PCILIB_DEFAULT_UNIT_SPACE * sizeof(pcilib_unit_t)); + + if ((!ctx->registers)||(!ctx->register_ctx)) { pcilib_error("Error allocating memory for register model"); pcilib_close(ctx); return NULL; } - if((!ctx->enum_views)||(!ctx->formula_views)){ - pcilib_error("Error allocating memory for views"); - pcilib_close(ctx); - return NULL; + /* i think we need a better error handling here, because, it's not that a problem to not have views working, but how to block the use if the memory here was not good?, and we could have only one type of views that is working*/ + if((!ctx->enum_views)||(!ctx->formula_views) || (!ctx->units)){ + pcilib_warning("Error allocating memory for views"); } + + memset(ctx->registers, 0, sizeof(pcilib_register_description_t)); memset(ctx->banks, 0, sizeof(pcilib_register_bank_description_t)); memset(ctx->ranges, 0, sizeof(pcilib_register_range_t)); @@ -166,6 +171,7 @@ pcilib_t *pcilib_open(const char *device, const char *model) { memset(ctx->enum_views,0,sizeof(pcilib_view_enum2_t)); memset(ctx->formula_views,0,sizeof(pcilib_view_formula_t)); + memset(ctx->units,0,sizeof(pcilib_unit_t)); for (i = 0; pcilib_protocols[i].api; i++); memcpy(ctx->protocols, pcilib_protocols, i * sizeof(pcilib_register_protocol_description_t)); diff --git a/pcilib/pci.h b/pcilib/pci.h index 3b1c0e8..a62e1cc 100644 --- a/pcilib/pci.h +++ b/pcilib/pci.h @@ -9,6 +9,7 @@ #define PCILIB_MAX_BARS 6 /**< this is defined by PCI specification */ #define PCILIB_DEFAULT_REGISTER_SPACE 1024 /**< number of registers to allocate on init */ #define PCILIB_DEFAULT_VIEW_SPACE 128 /**< number of views to allocate on init */ +#define PCILIB_DEFAULT_UNIT_SPACE 128 /** number of units to allocate on init*/ #define PCILIB_MAX_REGISTER_BANKS 32 /**< maximum number of register banks to allocate space for */ #define PCILIB_MAX_REGISTER_RANGES 32 /**< maximum number of register ranges to allocate space for */ #define PCILIB_MAX_REGISTER_PROTOCOLS 32 /**< maximum number of register protocols to support */ @@ -27,6 +28,7 @@ #include "export.h" #include "locking.h" #include "xml.h" +#include "unit.h" typedef struct { uint8_t max_link_speed, link_speed; @@ -65,7 +67,7 @@ struct pcilib_s { size_t dyn_banks; /**< Number of configured dynamic banks */ size_t num_enum_views,alloc_enum_views; /**< Number of configured and allocated views of type enum*/ size_t num_formula_views,alloc_formula_views; /**< Number of configured and allocated views of type formula*/ - + size_t num_units,alloc_units; /**< Number of configured and allocated units*/ pcilib_register_description_t *registers; /**< List of currently defined registers (from all sources) */ pcilib_register_bank_description_t banks[PCILIB_MAX_REGISTER_BANKS + 1]; /**< List of currently defined register banks (from all sources) */ pcilib_register_range_t ranges[PCILIB_MAX_REGISTER_RANGES + 1]; /**< List of currently defined register ranges (from all sources) */ @@ -87,6 +89,7 @@ struct pcilib_s { pcilib_view_enum2_t* enum_views; /**< list of currently defined views of type enum*/ pcilib_view_formula_t* formula_views; /**< list of currently defined views of type formula*/ + pcilib_unit_t* units; /** list of currently defined units*/ #ifdef PCILIB_FILE_IO int file_io_handle; #endif /* PCILIB_FILE_IO */ diff --git a/pcilib/unit.c b/pcilib/unit.c new file mode 100644 index 0000000..a9766ed --- /dev/null +++ b/pcilib/unit.c @@ -0,0 +1,34 @@ +#include "pcilib.h" +#include "pci.h" +#include "stdio.h" +#include +#include "error.h" +#include "unit.h" + +int pcilib_add_units(pcilib_t *ctx, size_t n, const pcilib_unit_t* units) { + + pcilib_unit_t *units2; + size_t size; + + if (!n) { + for (n = 0; units[n].name[0]; n++); + } + + if ((ctx->num_units + n + 1) > ctx->alloc_units) { + for (size = ctx->alloc_units; size < 2 * (n + ctx->num_units + 1); size<<=1); + + units2 = (pcilib_unit_t*)realloc(ctx->units, size * sizeof(pcilib_unit_t)); + if (!units2) return PCILIB_ERROR_MEMORY; + + ctx->units = units2; + ctx->alloc_units = size; + } + + memcpy(ctx->units + ctx->num_units, units, n * sizeof(pcilib_unit_t)); + memset(ctx->units + ctx->num_units + n, 0, sizeof(pcilib_unit_t)); + + ctx->num_units += n; + + return 0; +} + diff --git a/pcilib/unit.h b/pcilib/unit.h new file mode 100644 index 0000000..f9991f1 --- /dev/null +++ b/pcilib/unit.h @@ -0,0 +1,30 @@ +#ifndef _PCILIB_UNITS_H +#define _PCILIB_UNITS_H + +#include "pcilib.h" + +typedef struct pcilib_unit_s pcilib_unit_t; +typedef struct pcilib_transform_unit_s pcilib_transform_unit_t; + +/** + * type to save a transformation unit in the pcitool program + */ +struct pcilib_transform_unit_s{ + char *name; + char *transform_formula; +}; + +/** + * type to save a unit in the pcitool programm + */ +struct pcilib_unit_s{ + char* name; + pcilib_transform_unit_t* other_units; +}; + +/** + * function to populate the ctx with units + */ +int pcilib_add_units(pcilib_t* ctx, size_t n, const pcilib_unit_t* units); + +#endif diff --git a/pcilib/views.c b/pcilib/views.c index 038b48d..c9ad4d3 100644 --- a/pcilib/views.c +++ b/pcilib/views.c @@ -6,6 +6,7 @@ #include "error.h" #include #include +#include "unit.h" /** * @@ -81,7 +82,7 @@ pcilib_view_formula_replace (const char *txt, const char *before, const char *af * @param[in] end the ending index of the substring. * @return the extracted substring. */ -static char* +char* pcilib_view_str_sub (const char *s, unsigned int start, unsigned int end) { char *new_s = NULL; @@ -108,6 +109,39 @@ pcilib_view_str_sub (const char *s, unsigned int start, unsigned int end) return new_s; } +/** + * function to apply a unit for the views of type formula + *@param[in] view - the view we want to get the units supported + *@param[in] base_unit - the base unit of the formulas of the view + *@param[in] unit - the requested unit in which we want to get the value + *@param[in,out] value - the number that needs to get transformed + * +static int +pcilib_view_apply_unit(pcilib_view_formula_t* view, char* base_unit, char* unit,int* value){ + char* formula; + char temp[66]; + int i,j,k; + k=1; + /*we iterate through all the units of the given view to find the corresponding unit, and so the formula to transform it; then we evaluate value with the formula* + for(i=0;view->units[i].name[0];i++){ + if(!(strcasecmp(base_unit,view->units[i].name))){ + for(j=0;view->units[i].other_units[j].name[0];j++){ + if(!(strcasecmp(unit,view->units[i].other_units[j].name))){ + formula=malloc(strlen(units[i].other_units[j].transform_formula)*sizeof(char)); + strcpy(formula,units[i].other_units[j].transform_formula); + sprintf(temp,"%i",*value); + formula=pcilib_view_formula_replace(formula,"@self",temp); + *value=(int)pcilib_view_eval_formula(formula); + return 0; + } + } + } + } + + pcilib_error("no unit corresponds to the base unit asked"); + return PCILIB_ERROR_INVALID_REQUEST; +}*/ + /** * get the bank name associated with a register name */ @@ -162,46 +196,25 @@ pcilib_view_compute_plain_registers(pcilib_t* ctx, char* formula){ */ static pcilib_register_value_t pcilib_view_eval_formula(char* formula){ - setenv("PYTHONPATH",".",1); - PyObject *pName, *pModule, *pDict, *pFunc, *pValue, *presult=NULL; - char* pythonfile; + + // setenv("PYTHONPATH",".",1); - /* path to the python file, we may need a way to set it, maybe with a variable like PCILIB_PYTHON_PATH*/ - pythonfile="pythonscripts.py"; - /* initialization of python interpreter*/ Py_Initialize(); - - pName = PyUnicode_FromString(pythonfile); - pModule = PyImport_Import(pName); /* get the python file*/ - if(!pModule) { - pcilib_error("no python file found for python evaluation of formulas\n"); - PyErr_Print(); - return -1; - } - pDict = PyModule_GetDict(pModule); /*useless but needed*/ - - pFunc = PyDict_GetItemString(pDict, (char*)"evaluate"); /*getting of the function "evaluate" in the script*/ - /* if the function is ok, then call it*/ - if (PyCallable_Check(pFunc)) - { - /* execution of the function*/ - pValue=Py_BuildValue("(z)",formula); - PyErr_Print(); - presult=PyObject_CallObject(pFunc,pValue); - PyErr_Print(); - } else - { - PyErr_Print(); - } - /* remove memory*/ - Py_DECREF(pModule); - Py_DECREF(pName); + /*compilation of the formula as python string*/ + PyCodeObject* code=(PyCodeObject*)Py_CompileString(formula,"test",Py_eval_input); + PyObject* main_module = PyImport_AddModule("__parser__"); + PyObject* global_dict = PyModule_GetDict(main_module); + PyObject* local_dict = PyDict_New(); + /*evaluation of formula*/ + PyObject* obj = PyEval_EvalCode(code, global_dict, local_dict); + double c=PyFloat_AsDouble(obj); + /* close interpreter*/ Py_Finalize(); - - return (pcilib_register_value_t)PyLong_AsUnsignedLong(presult); /*this function is due to python 3.3, as PyLong_AsInt was there in python 2.7 and is no more there, resulting in using cast futhermore*/ + pcilib_register_value_t value=(pcilib_register_value_t)c; + return value; } @@ -227,7 +240,6 @@ pcilib_view_apply_formula(pcilib_t* ctx, char* formula, pcilib_register_value_t formula=pcilib_view_compute_plain_registers(ctx,formula); /* computation of @reg with register value*/ formula=pcilib_view_formula_replace(formula,"@reg",reg_value_string); - /* evaluation of the formula*/ *out_value= pcilib_view_eval_formula(formula); @@ -246,8 +258,10 @@ int pcilib_read_view(pcilib_t *ctx, const char *bank, const char *regname, const } /* we get the value of the register, as we will apply the view on it*/ - if((err==pcilib_read_register_by_id(ctx,i,&temp_value))>0){ - pcilib_error("can't read the register %s value before applying views",regname); + err=pcilib_read_register_by_id(ctx,i,&temp_value); + if(err){ + pcilib_error("can't read the register %s value before applying views : error %i",regname); + return PCILIB_ERROR_INVALID_REQUEST; } /*in the case we don't ask for a view's name, we know it will be for views of type enum. Especially, it's faster to search directly on the values of those views instead of a given name. we iterate so through the views of type enum to verify if the value we have corresponds to an enum command*/ @@ -255,13 +269,15 @@ int pcilib_read_view(pcilib_t *ctx, const char *bank, const char *regname, const for(j=0; ctx->register_ctx[i].enums[j].value;j++){ if((temp_value >= ctx->register_ctx[i].enums[j].min) && (temp_value <= ctx->register_ctx[i].enums[j].max)){ value_size=strlen(ctx->register_ctx[i].enums[j].name)*sizeof(char); - value=malloc(sizeof(value_size)); + value=(char*)realloc(value,sizeof(value_size)); if(!(value)){ pcilib_error("can't allocate memory for the returning value of the view %s",view); return PCILIB_ERROR_MEMORY; } /* in the case the value of register is between min and max, then we return the correponding enum command*/ strncpy((char*)value,ctx->register_ctx[i].enums[j].name, strlen(ctx->register_ctx[i].enums[j].name)); + /* make sure the string is correctly terminated*/ + ((char*)value)[value_size]='\0'; return 0; } } @@ -271,8 +287,7 @@ int pcilib_read_view(pcilib_t *ctx, const char *bank, const char *regname, const /** in the other case we ask for a view of type formula. Indeed, wa can't directly ask for a formula, so we have to provide a name for those views*/ j=0; - while((ctx->register_ctx[i].formulas[j].name)){ - if(!(strcasecmp(ctx->register_ctx[i].formulas[j].name,view))){ + if(!(strcasecmp(ctx->register_ctx[i].formulas[0].name,view))){ /* when we have found the correct view of type formula, we apply the formula, that get the good value for return*/ formula=malloc(sizeof(char)*strlen(ctx->register_ctx[i].formulas[j].read_formula)); strncpy(formula,ctx->register_ctx[i].formulas[j].read_formula,strlen(ctx->register_ctx[i].formulas[j].read_formula)); @@ -281,8 +296,6 @@ int pcilib_read_view(pcilib_t *ctx, const char *bank, const char *regname, const value_size=sizeof(int); return 0; } - j++; - } pcilib_warning("the view asked and the register do not correspond"); return PCILIB_ERROR_NOTAVAILABLE; diff --git a/pcilib/views.h b/pcilib/views.h index dfc9f70..f186336 100644 --- a/pcilib/views.h +++ b/pcilib/views.h @@ -2,6 +2,7 @@ #define _PCILIB_VIEWS_H #include "pcilib.h" +#include "unit.h" typedef struct pcilib_view_enum_s pcilib_view_enum_t; @@ -37,6 +38,7 @@ struct pcilib_view_formula_s { const char *write_formula; /**units[0].other_units.name[0];i++){ + for(j=0;ctx->units[j].name[0];i++){ + if(!(strcasecmp(myview->units[0].other_units.name,ctx->units[i].name))){ + myview.units=realloc(myview.units,k*sizeof(pcilib_unit_t)); + myview.units[k-1]=ctx->units[i]; + k++; + } + } + } + }*/ + /** * get the associated views of a register, to fill its register context */ @@ -490,7 +507,52 @@ static int pcilib_xml_create_bank(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo return 0; } +/*static int pcilib_xml_create_unit(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) { + int err; + + int override = 0; + pcilib_unit_t desc = {0}; + xmlNodePtr cur; + char *value, *name, *value2; + char *endptr; + xmlXPathObjectPtr nodes; + xmlNodeSetPtr nodeset; + xmlAttr *attr; + int i=0; + + /* we get the attribute type of the view node* + attr=node->properties; + value=(char*)attr->children->content; + desc.name=value; + desc.other_units=malloc(sizeof(pcilib_transform_unit_t)); + + for (cur = node->children; cur != NULL; cur = cur->next) { + if (!cur->children) continue; + if (!xmlNodeIsText(cur->children)) continue; + + name = (char*)cur->name; + value = (char*)cur->children->content; + attr= cur->properties; + value2=(char*)attr->children->content; + if (!value || !attr) continue; + + if (!strcasecmp(name, "convert_unit")) { + desc.other_units=realloc(des.other_units,sizeof((i+1)*sizeof(pcilib_transform_unit_t))); + desc.other_units[i].name=value2; + desc.other_units[i].transform_formula=value; + } + } + + err = pcilib_add_units(ctx, 1, &desc); + if (err) { + pcilib_error("Error adding unit (%s) specified in the XML", desc.name); + return err; + } + + return 0; +} +*/ /** * function that create a view from a view node, and populate ctx views list */ @@ -505,6 +567,7 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo char *endptr; xmlAttr *attr; int i=0; + int ok_min=0, ok_max=0; /*must i initialize? i think it's only needed if we want to include a description property*/ enum_desc.name="default"; @@ -573,15 +636,19 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo return PCILIB_ERROR_INVALID_DATA; } complete_enum_desc.enums_list[i].min=dat_min; + ok_min=1; }else if(!(strcasecmp(name,"max"))){ pcilib_register_value_t dat_max = strtol(value, &endptr, 0); if ((strlen(endptr) > 0)) { pcilib_error("Invalid max (%s) is specified in the XML enum node", value); return PCILIB_ERROR_INVALID_DATA; } - complete_enum_desc.enums_list[i].max=dat_max; + ok_max=1; } + if(ok_min==0) complete_enum_desc.enums_list[i].min=complete_enum_desc.enums_list[i].value; + if(ok_max==0) complete_enum_desc.enums_list[i].max=complete_enum_desc.enums_list[i].value; + } i++; } diff --git a/pcitool/cli.c b/pcitool/cli.c index 7014190..6af70e4 100644 --- a/pcitool/cli.c +++ b/pcitool/cli.c @@ -1024,13 +1024,14 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, int i; int err; const char *format; + char *s1,*s2,*s3; + pcilib_register_bank_t bank_id; pcilib_register_bank_addr_t bank_addr = 0; pcilib_register_value_t value; - - if (reg) { + if (reg && !(strchr(reg,'/'))) { pcilib_register_t regid = pcilib_find_register(handle, bank, reg); bank_id = pcilib_find_register_bank_by_addr(handle, model_info->registers[regid].bank); format = model_info->banks[bank_id].format; @@ -1044,7 +1045,36 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, printf(format, value); printf("\n"); } + }else if(reg && (s1=strchr(reg,'/'))){ + char* enum_command=malloc(sizeof(char*)); + if(!enum_command){ + printf("Error allocating memory for the result\n"); + return PCILIB_ERROR_MEMORY; + } + s2=pcilib_view_str_sub(reg,0,s1-reg-1); + s3=pcilib_view_str_sub(reg,s1-reg+1,strlen(reg)); + if(!(strcasecmp(s3,"name"))){ + err = pcilib_read_view(handle,bank,s2,NULL,sizeof(char*),enum_command); + if (err) printf("Error reading register %s\n", reg); + else { + printf("%s = %s\n", reg, (char*)enum_command); + } + }else{ + pcilib_register_t regid = pcilib_find_register(handle, bank, s2); + bank_id = pcilib_find_register_bank_by_addr(handle, model_info->registers[regid].bank); + format = model_info->banks[bank_id].format; + if (!format) format = "%lu"; + + err = pcilib_read_view(handle,bank,s2,s3,sizeof(pcilib_register_value_t),&value); + if (err) printf("Error reading register %s\n", reg); + else { + printf("%s = ", reg); + printf(format, value); + printf("\n"); + } + } } else { + printf("da\n"); // Adding DMA registers pcilib_get_dma_description(handle); @@ -1254,6 +1284,7 @@ int WriteRegister(pcilib_t *handle, const pcilib_model_description_t *model_info pcilib_register_value_t value; const char *format = NULL; + char *s1; pcilib_register_t regid = pcilib_find_register(handle, bank, reg); if (regid == PCILIB_REGISTER_INVALID) Error("Can't find register (%s) from bank (%s)", reg, bank?bank:"autodetected"); @@ -1281,14 +1312,27 @@ int WriteRegister(pcilib_t *handle, const pcilib_model_description_t *model_info format = "0x%lx"; } else { - Error("Can't parse data value (%s) is not valid decimal number", *data); + err = pcilib_write_view(handle,bank,reg,*data,0,NULL); + if(err) Error("can't write to the register using an enum view"); + else return 0; } + /* } else { + Error("Can't parse data value (%s) is not valid decimal number", *data); + }*/ value = val; - - err = pcilib_write_register(handle, bank, reg, value); - if (err) Error("Error writting register %s\n", reg); + if((s1=strchr(reg,'/'))){ + char *s3,*s2; + s2=pcilib_view_str_sub(reg,0,s1-reg-1); + s3=pcilib_view_str_sub(reg,s1-reg+1,strlen(reg)); + err = pcilib_write_view(handle,bank,s2,s3,sizeof(pcilib_register_value_t),&value); + if (err) printf("Error writing register %s using view %s\n",s2,s3); + }else{ + err = pcilib_write_register(handle, bank, reg, value); + if (err) Error("Error writting register %s\n", reg); + } + if ((model_info->registers[regid].mode&PCILIB_REGISTER_RW) == PCILIB_REGISTER_RW) { err = pcilib_read_register(handle, bank, reg, &value); if (err) Error("Error reading back register %s for verification\n", reg); @@ -3249,7 +3293,10 @@ int main(int argc, char **argv) { ++mode; } } - } else { + } else if(strchr(addr,'/')) { + reg=addr; + ++mode; + }else { if (pcilib_find_register(handle, bank, addr) == PCILIB_REGISTER_INVALID) { Usage(argc, argv, "Invalid address (%s) is specified", addr); } else { @@ -3349,12 +3396,12 @@ int main(int argc, char **argv) { } else if (addr) { err = ReadData(handle, amode, flags, dma, bar, start, size, access, endianess, (size_t)-1, ofile); } else { - Error("Address to read is not specified"); + Error("Address to read is not specified"); } break; case MODE_READ_REGISTER: - if ((reg)||(!addr)) ReadRegister(handle, model_info, bank, reg); - else ReadRegisterRange(handle, model_info, bank, start, addr_shift, size, ofile); + if ((reg)||(!addr)) ReadRegister(handle, model_info, bank, reg); + else ReadRegisterRange(handle, model_info, bank, start, addr_shift, size, ofile); break; case MODE_WRITE: WriteData(handle, amode, dma, bar, start, size, access, endianess, data, verify); diff --git a/xml/test/camera.xml b/xml/test/camera.xml index 815a50e..bf26d80 100644 --- a/xml/test/camera.xml +++ b/xml/test/camera.xml @@ -466,14 +466,14 @@ formuu2 C - ((1./4)*(@reg - 1200)) if @freq==0 else ((3./10)*(@reg - 1000)) + ((1./4)*(@reg + 1200)) if @freq==0 else ((3./10)*(@reg + 1000)) 4*@value + 1200 if @freq==0 else (10./3)*@value + 1000 formula to get real sensor temperature from the sensor_temperature register in decimal enumm2 high - low + low enum towards sensor_temperature register -- cgit v1.2.3 From a1bf5e300e2345b642d0a13e7e26d22c56156e47 Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Mon, 14 Sep 2015 15:49:46 +0200 Subject: views with units functionnal (beware, as formulas are completely crap now, we could get segfault, for example if we want to write a negative value in register) --- pcilib/views.c | 148 +++++++++++++++++++++++++++++----------------------- pcilib/views.h | 6 +-- pcilib/xml.c | 97 ++++++++++++++++++++++------------ pcitool/cli.c | 20 ++++--- xml/model.xsd | 24 ++++++++- xml/test/camera.xml | 34 ++++++++++++ 6 files changed, 221 insertions(+), 108 deletions(-) (limited to 'xml') diff --git a/pcilib/views.c b/pcilib/views.c index c9ad4d3..1f26b52 100644 --- a/pcilib/views.c +++ b/pcilib/views.c @@ -109,38 +109,6 @@ pcilib_view_str_sub (const char *s, unsigned int start, unsigned int end) return new_s; } -/** - * function to apply a unit for the views of type formula - *@param[in] view - the view we want to get the units supported - *@param[in] base_unit - the base unit of the formulas of the view - *@param[in] unit - the requested unit in which we want to get the value - *@param[in,out] value - the number that needs to get transformed - * -static int -pcilib_view_apply_unit(pcilib_view_formula_t* view, char* base_unit, char* unit,int* value){ - char* formula; - char temp[66]; - int i,j,k; - k=1; - /*we iterate through all the units of the given view to find the corresponding unit, and so the formula to transform it; then we evaluate value with the formula* - for(i=0;view->units[i].name[0];i++){ - if(!(strcasecmp(base_unit,view->units[i].name))){ - for(j=0;view->units[i].other_units[j].name[0];j++){ - if(!(strcasecmp(unit,view->units[i].other_units[j].name))){ - formula=malloc(strlen(units[i].other_units[j].transform_formula)*sizeof(char)); - strcpy(formula,units[i].other_units[j].transform_formula); - sprintf(temp,"%i",*value); - formula=pcilib_view_formula_replace(formula,"@self",temp); - *value=(int)pcilib_view_eval_formula(formula); - return 0; - } - } - } - } - - pcilib_error("no unit corresponds to the base unit asked"); - return PCILIB_ERROR_INVALID_REQUEST; -}*/ /** * get the bank name associated with a register name @@ -160,7 +128,7 @@ pcilib_view_get_bank_from_reg_name(pcilib_t* ctx,char* reg_name){ * replace plain registers name in a formula by their value */ static char* -pcilib_view_compute_plain_registers(pcilib_t* ctx, char* formula){ +pcilib_view_compute_plain_registers(pcilib_t* ctx, char* formula, int direction){ int j,k; char *substr, *substr2; char temp[66]; @@ -175,15 +143,24 @@ pcilib_view_compute_plain_registers(pcilib_t* ctx, char* formula){ } substr2=pcilib_view_str_sub((char*)formula,j,k-1); /**< we get the name of the register+@*/ substr=pcilib_view_str_sub(substr2,1,k-j/*length of substr2*/); /**< we get the name of the register*/ - - if((strcasecmp(substr,"reg"))){ + if(direction==0){ + if((strcasecmp(substr,"reg"))){ /* we get the bank name associated to the register, and read its value*/ pcilib_read_register(ctx, pcilib_view_get_bank_from_reg_name(ctx, substr),substr,&value); /* we put the value in formula*/ sprintf(temp,"%i",value); formula = pcilib_view_formula_replace(formula,substr2,temp); + } } - + else if(direction==1){ + if((strcasecmp(substr,"value"))){ + /* we get the bank name associated to the register, and read its value*/ + pcilib_read_register(ctx, pcilib_view_get_bank_from_reg_name(ctx, substr),substr,&value); + /* we put the value in formula*/ + sprintf(temp,"%i",value); + formula = pcilib_view_formula_replace(formula,substr2,temp); + } + } } } return formula; @@ -197,8 +174,6 @@ pcilib_view_compute_plain_registers(pcilib_t* ctx, char* formula){ static pcilib_register_value_t pcilib_view_eval_formula(char* formula){ - // setenv("PYTHONPATH",".",1); - /* initialization of python interpreter*/ Py_Initialize(); @@ -217,9 +192,27 @@ pcilib_view_eval_formula(char* formula){ return value; } +/** + * function to apply a unit for the views of type formula + *@param[in] view - the view we want to get the units supported + *@param[in] unit - the requested unit in which we want to get the value + *@param[in,out] value - the number that needs to get transformed + */ +static void +pcilib_view_apply_unit(pcilib_transform_unit_t unit_desc, const char* unit,pcilib_register_value_t* value){ + char* formula; + char temp[66]; + + formula=malloc(strlen(unit_desc.transform_formula)*sizeof(char)); + strcpy(formula,unit_desc.transform_formula); + sprintf(temp,"%i",*value); + formula=pcilib_view_formula_replace(formula,"@self",temp); + *value=(int)pcilib_view_eval_formula(formula); +} + static void -pcilib_view_apply_formula(pcilib_t* ctx, char* formula, pcilib_register_value_t reg_value, pcilib_register_value_t* out_value) +pcilib_view_apply_formula(pcilib_t* ctx, char* formula, pcilib_register_value_t reg_value, pcilib_register_value_t* out_value, int direction) { /* when applying a formula, we need to: 1) compute the values of all registers present in plain name in the formulas and replace their name with their value : for example, if we have the formula" ((1./4)*(@reg - 1200)) if @freq==0 else ((3./10)*(@reg - 1000)) " we need to get the value of the register "freq" @@ -237,15 +230,15 @@ pcilib_view_apply_formula(pcilib_t* ctx, char* formula, pcilib_register_value_t sprintf(reg_value_string,"%u",reg_value); /*computation of plain registers in the formula*/ - formula=pcilib_view_compute_plain_registers(ctx,formula); + formula=pcilib_view_compute_plain_registers(ctx,formula,direction); /* computation of @reg with register value*/ - formula=pcilib_view_formula_replace(formula,"@reg",reg_value_string); + if(direction==0) formula=pcilib_view_formula_replace(formula,"@reg",reg_value_string); + else if (direction==1) formula=pcilib_view_formula_replace(formula,"@value",reg_value_string); /* evaluation of the formula*/ *out_value= pcilib_view_eval_formula(formula); - } -int pcilib_read_view(pcilib_t *ctx, const char *bank, const char *regname, const char *view/*, const char *unit*/, size_t value_size, void *value) +int pcilib_read_view(pcilib_t *ctx, const char *bank, const char *regname, const char *unit, size_t value_size, void *value) { int i,j,err=0; pcilib_register_value_t temp_value; @@ -265,13 +258,13 @@ int pcilib_read_view(pcilib_t *ctx, const char *bank, const char *regname, const } /*in the case we don't ask for a view's name, we know it will be for views of type enum. Especially, it's faster to search directly on the values of those views instead of a given name. we iterate so through the views of type enum to verify if the value we have corresponds to an enum command*/ - if(!(view)){ + if(!(unit)){ for(j=0; ctx->register_ctx[i].enums[j].value;j++){ if((temp_value >= ctx->register_ctx[i].enums[j].min) && (temp_value <= ctx->register_ctx[i].enums[j].max)){ value_size=strlen(ctx->register_ctx[i].enums[j].name)*sizeof(char); value=(char*)realloc(value,sizeof(value_size)); if(!(value)){ - pcilib_error("can't allocate memory for the returning value of the view %s",view); + pcilib_error("can't allocate memory for the returning value of the view"); return PCILIB_ERROR_MEMORY; } /* in the case the value of register is between min and max, then we return the correponding enum command*/ @@ -287,15 +280,33 @@ int pcilib_read_view(pcilib_t *ctx, const char *bank, const char *regname, const /** in the other case we ask for a view of type formula. Indeed, wa can't directly ask for a formula, so we have to provide a name for those views*/ j=0; - if(!(strcasecmp(ctx->register_ctx[i].formulas[0].name,view))){ + if(!(strcasecmp(unit, ctx->register_ctx[i].formulas[0].base_unit.name))){ + formula=malloc(sizeof(char)*strlen(ctx->register_ctx[i].formulas[0].read_formula)); + if(!(formula)){ + pcilib_error("can't allocate memory for the formula"); + return PCILIB_ERROR_MEMORY; + } + strncpy(formula,ctx->register_ctx[i].formulas[0].read_formula,strlen(ctx->register_ctx[i].formulas[0].read_formula)); + pcilib_view_apply_formula(ctx,formula,temp_value,value,0); + value_size=sizeof(int); + return 0; + } + + for(j=0; ctx->register_ctx[i].formulas[0].base_unit.other_units[j].name;j++){ + if(!(strcasecmp(ctx->register_ctx[i].formulas[0].base_unit.other_units[j].name,unit))){ /* when we have found the correct view of type formula, we apply the formula, that get the good value for return*/ - formula=malloc(sizeof(char)*strlen(ctx->register_ctx[i].formulas[j].read_formula)); - strncpy(formula,ctx->register_ctx[i].formulas[j].read_formula,strlen(ctx->register_ctx[i].formulas[j].read_formula)); - // pcilib_view_apply_formula(ctx, ctx->register_ctx[i].formulas[j].read_formula,temp_value,value); - pcilib_view_apply_formula(ctx, formula,temp_value,value); + formula=malloc(sizeof(char)*strlen(ctx->register_ctx[i].formulas[0].read_formula)); + if(!(formula)){ + pcilib_error("can't allocate memory for the formula"); + return PCILIB_ERROR_MEMORY; + } + strncpy(formula,ctx->register_ctx[i].formulas[0].read_formula,strlen(ctx->register_ctx[i].formulas[0].read_formula)); + pcilib_view_apply_formula(ctx,formula,temp_value,value,0); + pcilib_view_apply_unit(ctx->register_ctx[i].formulas[0].base_unit.other_units[j],unit,value); value_size=sizeof(int); return 0; } + } pcilib_warning("the view asked and the register do not correspond"); return PCILIB_ERROR_NOTAVAILABLE; @@ -305,11 +316,11 @@ int pcilib_read_view(pcilib_t *ctx, const char *bank, const char *regname, const /** * function to write to a register using a view */ -int pcilib_write_view(pcilib_t *ctx, const char *bank, const char *regname, const char *view, size_t value_size,void* value/*, const char *unit*/){ +int pcilib_write_view(pcilib_t *ctx, const char *bank, const char *regname, const char *unit, size_t value_size,void* value){ int i,j; pcilib_register_value_t temp_value; char *formula; - + /* we get the index of the register to find the corresponding register context*/ if((i=pcilib_find_register(ctx,bank,regname))==PCILIB_REGISTER_INVALID){ pcilib_error("can't get the index of the register %s", regname); @@ -318,28 +329,37 @@ int pcilib_write_view(pcilib_t *ctx, const char *bank, const char *regname, cons /*here, in the case of views of type enum, view will correspond to the enum command. we iterate so through the views of type enum to get the value corresponding to the enum command*/ - for(j=0; ctx->register_ctx[i].enums[j].value;j++){ - if(!(strcasecmp(ctx->register_ctx[i].enums[j].name,view))){ + for(j=0; ctx->register_ctx[i].enums[j].name;j++){ + /* we should maybe have another to do it there*/ + if(!(strcasecmp(ctx->register_ctx[i].enums[j].name,unit))){ pcilib_write_register(ctx,bank,regname,ctx->register_ctx[i].enums[j].value); return 0; } } - + /** in the other case we ask for a view of type formula. Indeed, wa can't directly ask for a formula, so we have to provide a name for those views in view, and the value we want to write in value*/ j=0; - while((ctx->register_ctx[i].formulas[j].name)){ - if(!(strcasecmp(ctx->register_ctx[i].formulas[j].name,view))){ + if(!(strcasecmp(unit, ctx->register_ctx[i].formulas[0].base_unit.name))){ + formula=malloc(sizeof(char)*strlen(ctx->register_ctx[i].formulas[0].write_formula)); + strncpy(formula,ctx->register_ctx[i].formulas[0].write_formula,strlen(ctx->register_ctx[i].formulas[0].write_formula)); + pcilib_view_apply_formula(ctx,formula,*(pcilib_register_value_t*)value,&temp_value,1); + pcilib_write_register(ctx,bank,regname,temp_value); + return 0; + } + + for(j=0; ctx->register_ctx[i].formulas[0].base_unit.other_units[j].name;j++){ + if(!(strcasecmp(ctx->register_ctx[i].formulas[0].base_unit.other_units[j].name,unit))){ /* when we have found the correct view of type formula, we apply the formula, that get the good value for return*/ - formula=malloc(sizeof(char)*strlen(ctx->register_ctx[i].formulas[j].write_formula)); - strncpy(formula,ctx->register_ctx[i].formulas[j].write_formula,strlen(ctx->register_ctx[i].formulas[j].write_formula)); - // pcilib_view_apply_formula(ctx, ctx->register_ctx[i].formulas[j].write_formula,(pcilib_register_value_t*)value,temp_value); - pcilib_view_apply_formula(ctx,formula,*(pcilib_register_value_t*)value,&temp_value); + formula=malloc(sizeof(char)*strlen(ctx->register_ctx[i].formulas[0].write_formula)); + strncpy(formula,ctx->register_ctx[i].formulas[0].write_formula,strlen(ctx->register_ctx[i].formulas[0].write_formula)); + pcilib_view_apply_unit(ctx->register_ctx[i].formulas[0].base_unit.other_units[j],unit,value); + pcilib_view_apply_formula(ctx,formula,*(pcilib_register_value_t*)value,&temp_value,1); + /* we maybe need some error checking there , like temp_value >min and num_formula_views + n + 1) > ctx->alloc_formula_views) { diff --git a/pcilib/views.h b/pcilib/views.h index f186336..33bcf4c 100644 --- a/pcilib/views.h +++ b/pcilib/views.h @@ -38,18 +38,18 @@ struct pcilib_view_formula_s { const char *write_formula; /**units[0].other_units.name[0];i++){ - for(j=0;ctx->units[j].name[0];i++){ - if(!(strcasecmp(myview->units[0].other_units.name,ctx->units[i].name))){ - myview.units=realloc(myview.units,k*sizeof(pcilib_unit_t)); - myview.units[k-1]=ctx->units[i]; - k++; - } - } +pcilib_get_unit_of_view(pcilib_t* ctx,pcilib_view_formula_t* myview, char* base_unit){ + int j; + + for(j=0;ctx->units[j].name;j++){ + if(!(strcasecmp(base_unit,ctx->units[j].name))){ + myview->base_unit=ctx->units[j]; + break; + } } - }*/ + +} /** * get the associated views of a register, to fill its register context @@ -141,7 +141,7 @@ pcilib_get_associated_views(pcilib_t* ctx, const char* reg_name,xmlXPathContextP } /*here it is for formula, i assume we have only one formula view per register*/ - for(k=0; ctx->formula_views[k].name[0];k++){ + for(k=0; ctx->formula_views[k].name;k++){ if(!(strcasecmp(view_name,ctx->formula_views[k].name))){ ctx->register_ctx[id].formulas=malloc(sizeof(pcilib_view_formula_t)); @@ -149,7 +149,7 @@ pcilib_get_associated_views(pcilib_t* ctx, const char* reg_name,xmlXPathContextP pcilib_error("error allocating memory for formula views in register context %i",id); return PCILIB_ERROR_MEMORY; } - + pcilib_get_unit_of_view(ctx,&(ctx->formula_views[k]),ctx->formula_views[k].base_unit.name); ctx->register_ctx[id].formulas[0]=ctx->formula_views[k]; break; } @@ -273,8 +273,6 @@ static int pcilib_xml_parse_register(pcilib_t *ctx, pcilib_xml_register_descript static int pcilib_xml_create_register(pcilib_t *ctx, pcilib_register_bank_t bank, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) { int err; int views_ok=0; - int h; - xmlXPathObjectPtr nodes; xmlNodeSetPtr nodeset; @@ -507,28 +505,33 @@ static int pcilib_xml_create_bank(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo return 0; } -/*static int pcilib_xml_create_unit(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) { +/** + * function to create a unit from a unit xml node, then populating ctx with it + *@param[in,out] ctx - the pcilib_t running + *@param[in] xpath - the xpath context of the unis xml file + *@param[in] doc - the AST of the unit xml file + *@param[in] node - the node representing the unit + *@return an error code: 0 if evrythinh is ok + */ +static int +pcilib_xml_create_unit(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) { int err; - int override = 0; pcilib_unit_t desc = {0}; xmlNodePtr cur; char *value, *name, *value2; - char *endptr; - xmlXPathObjectPtr nodes; - xmlNodeSetPtr nodeset; xmlAttr *attr; int i=0; - /* we get the attribute type of the view node* + /* we get the attribute type of the view node*/ attr=node->properties; value=(char*)attr->children->content; desc.name=value; desc.other_units=malloc(sizeof(pcilib_transform_unit_t)); for (cur = node->children; cur != NULL; cur = cur->next) { - if (!cur->children) continue; + if (!cur->children) continue; if (!xmlNodeIsText(cur->children)) continue; name = (char*)cur->name; @@ -536,11 +539,12 @@ static int pcilib_xml_create_bank(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo attr= cur->properties; value2=(char*)attr->children->content; if (!value || !attr) continue; - + if (!strcasecmp(name, "convert_unit")) { - desc.other_units=realloc(des.other_units,sizeof((i+1)*sizeof(pcilib_transform_unit_t))); + desc.other_units=realloc(desc.other_units,(i+1)*sizeof(pcilib_transform_unit_t)); desc.other_units[i].name=value2; desc.other_units[i].transform_formula=value; + i++; } } @@ -552,7 +556,7 @@ static int pcilib_xml_create_bank(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo return 0; } -*/ + /** * function that create a view from a view node, and populate ctx views list */ @@ -678,8 +682,11 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo formula_desc.write_formula=value; }else if (!(strcasecmp((char*)name,"description"))) { formula_desc.description=value; + }else if (!(strcasecmp((char*)name,"unit"))){ + formula_desc.base_unit.name=value; } } + err=pcilib_add_views_formula(ctx,1,&formula_desc); if (err) { pcilib_error("Error (%i) adding a new formula view (%s) to the pcilib_t", err, formula_desc.name); @@ -700,17 +707,28 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo * @param[in] pci the pcilib_t running, which will be filled */ static int pcilib_xml_process_document(pcilib_t *ctx, xmlDocPtr doc, xmlXPathContextPtr xpath) { - xmlXPathObjectPtr bank_nodes,views_nodes; + xmlXPathObjectPtr bank_nodes,views_nodes, units_nodes; xmlNodeSetPtr nodeset; int i; xmlErrorPtr xmlerr; + + units_nodes=xmlXPathEvalExpression(UNITS_PATH,xpath); + if(!units_nodes){ + goto views; + } + + nodeset=units_nodes->nodesetval; + if(!xmlXPathNodeSetIsEmpty(nodeset)){ + for(i=0;i < nodeset->nodeNr; i++){ + pcilib_xml_create_unit(ctx,xpath,doc,nodeset->nodeTab[i]); + } + } + xmlXPathFreeObject(units_nodes); + views: views_nodes=xmlXPathEvalExpression(VIEWS_PATH,xpath); if(!views_nodes){ - xmlerr = xmlGetLastError(); - if (xmlerr) pcilib_error("Failed to parse XPath expression %s, xmlXPathEvalExpression reported error %d - %s", BANKS_PATH, xmlerr->code, xmlerr->message); - else pcilib_error("Failed to parse XPath expression %s", BANKS_PATH); - return PCILIB_ERROR_FAILED; + goto banks; } nodeset=views_nodes->nodesetval; @@ -720,7 +738,7 @@ static int pcilib_xml_process_document(pcilib_t *ctx, xmlDocPtr doc, xmlXPathCon } } xmlXPathFreeObject(views_nodes); - + banks: bank_nodes = xmlXPathEvalExpression(BANKS_PATH, xpath); if (!bank_nodes) { xmlerr = xmlGetLastError(); @@ -850,6 +868,8 @@ int pcilib_process_xml(pcilib_t *ctx, const char *location) { struct dirent *file = NULL; char *model_dir, *model_path; + int i; + model_dir = getenv("PCILIB_MODEL_DIR"); if (!model_dir) model_dir = PCILIB_MODEL_DIR; @@ -870,6 +890,17 @@ int pcilib_process_xml(pcilib_t *ctx, const char *location) { if (err) pcilib_error("Error processing XML file %s", file->d_name); } + for(i=0;inum_formula_views;i++){ + pcilib_get_unit_of_view(ctx,&(ctx->formula_views[i]),ctx->formula_views[i].base_unit.name); + } + + for(i=0;inum_reg;i++){ + if(ctx->register_ctx[i].formulas){ + pcilib_get_unit_of_view(ctx,&(ctx->register_ctx[i].formulas[0]),ctx->register_ctx[i].formulas[0].base_unit.name); + } + } + + closedir(rep); return 0; diff --git a/pcitool/cli.c b/pcitool/cli.c index 6af70e4..bd52270 100644 --- a/pcitool/cli.c +++ b/pcitool/cli.c @@ -1054,7 +1054,7 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, s2=pcilib_view_str_sub(reg,0,s1-reg-1); s3=pcilib_view_str_sub(reg,s1-reg+1,strlen(reg)); if(!(strcasecmp(s3,"name"))){ - err = pcilib_read_view(handle,bank,s2,NULL,sizeof(char*),enum_command); + err = pcilib_read_view(handle,bank,s2,NULL,sizeof(char*),enum_command); if (err) printf("Error reading register %s\n", reg); else { printf("%s = %s\n", reg, (char*)enum_command); @@ -1282,11 +1282,17 @@ int WriteRegister(pcilib_t *handle, const pcilib_model_description_t *model_info unsigned long val; pcilib_register_value_t value; + pcilib_register_t regid; const char *format = NULL; - char *s1; - - pcilib_register_t regid = pcilib_find_register(handle, bank, reg); + char *s1,*s2=NULL; + + if((s1=strchr(reg,'/'))){ + s2=pcilib_view_str_sub(reg,0,s1-reg-1); + regid=pcilib_find_register(handle,bank,s2); + }else{ + regid = pcilib_find_register(handle, bank, reg); + } if (regid == PCILIB_REGISTER_INVALID) Error("Can't find register (%s) from bank (%s)", reg, bank?bank:"autodetected"); /* @@ -1316,15 +1322,15 @@ int WriteRegister(pcilib_t *handle, const pcilib_model_description_t *model_info if(err) Error("can't write to the register using an enum view"); else return 0; } - /* } else { + /* should i put strchr not null here? + } else { Error("Can't parse data value (%s) is not valid decimal number", *data); }*/ value = val; if((s1=strchr(reg,'/'))){ - char *s3,*s2; - s2=pcilib_view_str_sub(reg,0,s1-reg-1); + char *s3; s3=pcilib_view_str_sub(reg,s1-reg+1,strlen(reg)); err = pcilib_write_view(handle,bank,s2,s3,sizeof(pcilib_register_value_t),&value); if (err) printf("Error writing register %s using view %s\n",s2,s3); diff --git a/xml/model.xsd b/xml/model.xsd index 5febd1a..cd0b4b0 100644 --- a/xml/model.xsd +++ b/xml/model.xsd @@ -4,8 +4,9 @@ - + + @@ -107,8 +108,29 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/xml/test/camera.xml b/xml/test/camera.xml index bf26d80..ed01014 100644 --- a/xml/test/camera.xml +++ b/xml/test/camera.xml @@ -491,4 +491,38 @@ enum towards cmosis_exp_register register + + + @self+273.15 + @self*(9./5)+32 + + + @self-273.15 + (@self-273.15)*(9./5)+32 + + + (@self-32)*5./9 + (@self+273.15-32)*5./9 + + + @self*1000 + @self*1000000 + @self*1000000000 + + + @self/1000 + @self*1000 + @self*1000000 + + + @self/1000000 + @self/1000 + @self*1000 + + + @self/1000000000 + @self/1000000 + @self/1000 + + -- cgit v1.2.3 From aaadfff471f02444b2936d824b055e2354b6c725 Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Mon, 14 Sep 2015 19:52:48 +0200 Subject: just crap --- pcilib/views.c | 41 +++++++++++++++++++++++++++++++++-------- xml/model.xsd | 2 +- 2 files changed, 34 insertions(+), 9 deletions(-) (limited to 'xml') diff --git a/pcilib/views.c b/pcilib/views.c index 9dde46b..0e3d26d 100644 --- a/pcilib/views.c +++ b/pcilib/views.c @@ -320,17 +320,40 @@ int pcilib_write_view(pcilib_t *ctx, const char *bank, const char *regname, cons int i,j; pcilib_register_value_t temp_value; char *formula; + int err; /* we get the index of the register to find the corresponding register context*/ if((i=pcilib_find_register(ctx,bank,regname))==PCILIB_REGISTER_INVALID){ pcilib_error("can't get the index of the register %s", regname); return PCILIB_ERROR_INVALID_REQUEST; } - + + for(j=0;ctx>register_ctx[i].views[j].name;j++){ + if(!(strcasecmp(ctx->register_ctx[i].views[j].base_unit,unit))){ + err=ctx->register_ctx[i].views[j].op(ctx,ctx->register_ctx[i].views[j].parameters,unit,1,&temp_value,value); + temp_value=ctx->register_ctx[i].views[value].value; + if(err){ + pcilib_error("can't write to the register with the enum view"); + return PCILIB_ERROR_FAILED; + } + break; + }else if(!(strcasecmp(ctx->register_ctx[i].views[j].name,unit))){ + err=ctx->register_ctx[i].views[j].op(ctx,ctx->register_ctx[i].views[j].parameters, unit, 1, &temp_value,0,&(ctx->register_ctx[i].views[j])); + if(err){ + pcilib_error("can't write to the register with the formula view %s", unit); + return PCILIB_ERROR_FAILED; + } + break; + } + pcilib_write_register(ctx,bank,regname,temp_value); + return 0; + } + + /*here, in the case of views of type enum, view will correspond to the enum command. - we iterate so through the views of type enum to get the value corresponding to the enum command*/ + we iterate so through the views of type enum to get the value corresponding to the enum command* for(j=0; ctx->register_ctx[i].enums[j].name;j++){ - /* we should maybe have another to do it there*/ + /* we should maybe have another to do it there* if(!(strcasecmp(ctx->register_ctx[i].enums[j].name,unit))){ pcilib_write_register(ctx,bank,regname,ctx->register_ctx[i].enums[j].value); return 0; @@ -338,7 +361,7 @@ int pcilib_write_view(pcilib_t *ctx, const char *bank, const char *regname, cons } /** in the other case we ask for a view of type formula. Indeed, wa can't directly ask for a formula, so we have to provide a name for those views in view, and the value we want to write in value*/ - j=0; + /* j=0; if(!(strcasecmp(unit, ctx->register_ctx[i].formulas[0].base_unit.name))){ formula=malloc(sizeof(char)*strlen(ctx->register_ctx[i].formulas[0].write_formula)); strncpy(formula,ctx->register_ctx[i].formulas[0].write_formula,strlen(ctx->register_ctx[i].formulas[0].write_formula)); @@ -349,20 +372,21 @@ int pcilib_write_view(pcilib_t *ctx, const char *bank, const char *regname, cons for(j=0; ctx->register_ctx[i].formulas[0].base_unit.other_units[j].name;j++){ if(!(strcasecmp(ctx->register_ctx[i].formulas[0].base_unit.other_units[j].name,unit))){ - /* when we have found the correct view of type formula, we apply the formula, that get the good value for return*/ + /* when we have found the correct view of type formula, we apply the formula, that get the good value for return* formula=malloc(sizeof(char)*strlen(ctx->register_ctx[i].formulas[0].write_formula)); strncpy(formula,ctx->register_ctx[i].formulas[0].write_formula,strlen(ctx->register_ctx[i].formulas[0].write_formula)); pcilib_view_apply_unit(ctx->register_ctx[i].formulas[0].base_unit.other_units[j],unit,value); pcilib_view_apply_formula(ctx,formula,*(pcilib_register_value_t*)value,&temp_value,1); - /* we maybe need some error checking there , like temp_value >min and min and - + -- cgit v1.2.3 From 1234f4a7e2410b127120aaa20dfe3c996ad34ef4 Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Tue, 15 Sep 2015 14:17:23 +0200 Subject: correction of some fails to load correct --- pcilib/xml.c | 22 ++++++++++++---------- xml/test/camera.xml | 22 ++++++++++++++++------ 2 files changed, 28 insertions(+), 16 deletions(-) (limited to 'xml') diff --git a/pcilib/xml.c b/pcilib/xml.c index ebef91e..31b9926 100644 --- a/pcilib/xml.c +++ b/pcilib/xml.c @@ -121,20 +121,22 @@ pcilib_get_associated_views(pcilib_t* ctx, const char* reg_name,xmlXPathContextP } if (!xmlXPathNodeSetIsEmpty(nodeset)) { - int i,k; + int i,k,l=0; /*if we correctly get a nodeset, then we iterate through the nodeset to get all views, using their names*/ for (i = 0; i < nodeset->nodeNr; i++) { view_name=(char*)nodeset->nodeTab[i]->children->content; - /* if the view name obtained is for an enum view, we get all pcilib_enum_t corresponding to the register*/ for(k=0; ctx->views[k].name; k++){ if(!(strcasecmp(view_name, ctx->views[k].name))){ - ctx->register_ctx[id].views=realloc(ctx->register_ctx[id].views,(k+1)*sizeof(pcilib_enum_t)); - ctx->register_ctx[id].views[k]=ctx->views[k]; + ctx->register_ctx[id].views=realloc(ctx->register_ctx[id].views,(l+1)*sizeof(pcilib_view_t)); + ctx->register_ctx[id].views[l]=ctx->views[k]; + l++; } } - } + ctx->register_ctx[id].views=realloc(ctx->register_ctx[id].views,(l+1)*sizeof(pcilib_view_t)); + ctx->register_ctx[id].views[l].name=NULL; + } xmlXPathFreeObject(nodes); @@ -305,6 +307,7 @@ static int pcilib_xml_create_register(pcilib_t *ctx, pcilib_register_bank_t bank int i; for (i = 0; i < nodeset->nodeNr; i++) { + views_ok=0; memset(&fdesc, 0, sizeof(pcilib_xml_register_description_t)); fdesc.base.bank = desc.base.bank; @@ -575,7 +578,6 @@ static int pcilib_xml_create_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDo desc.description = value; }else if (!(strcasecmp((char*)name,"enum"))) { - desc.parameters=realloc(desc.parameters,(i+1)*sizeof(pcilib_enum_t)); ((pcilib_enum_t*)(desc.parameters))[i].name=value; @@ -700,6 +702,7 @@ static int pcilib_xml_process_document(pcilib_t *ctx, xmlDocPtr doc, xmlXPathCon pcilib_xml_create_view(ctx,xpath,doc,nodeset->nodeTab[i]); } } + xmlXPathFreeObject(views_nodes); banks: bank_nodes = xmlXPathEvalExpression(BANKS_PATH, xpath); @@ -718,7 +721,6 @@ static int pcilib_xml_process_document(pcilib_t *ctx, xmlDocPtr doc, xmlXPathCon } } xmlXPathFreeObject(bank_nodes); - return 0; } @@ -852,20 +854,20 @@ int pcilib_process_xml(pcilib_t *ctx, const char *location) { err = pcilib_xml_load_file(ctx, model_path, file->d_name); if (err) pcilib_error("Error processing XML file %s", file->d_name); } - + for(i=0;inum_views;i++){ pcilib_get_unit_of_view(ctx,&(ctx->views[i]),ctx->views[i].base_unit.name); } for(i=0;inum_reg;i++){ + if(!(ctx->register_ctx[i].views)) continue; for(j=0;jnum_views;j++){ if(!(ctx->register_ctx[i].views[j].name)) break; - if(ctx->register_ctx[i].views){ + if(ctx->register_ctx[i].views[j].name){ pcilib_get_unit_of_view(ctx,&(ctx->register_ctx[i].views[j]),ctx->register_ctx[i].views[j].base_unit.name); } } } - closedir(rep); return 0; diff --git a/xml/test/camera.xml b/xml/test/camera.xml index ed01014..021ed61 100644 --- a/xml/test/camera.xml +++ b/xml/test/camera.xml @@ -253,6 +253,10 @@ all RW fr_num_lines_thr + + formuu2 + enumm2 +
0x100
@@ -278,8 +282,8 @@ R sensor_temperature - formuu1 - formuu2 + formuu1 + formuu2 enumm2 @@ -294,10 +298,6 @@ 10 RW fpga_temperature - - formuu1 - enumm1 - 29 @@ -348,6 +348,11 @@ 5 RW motor_phi + + formuu1 + enumm3 + + 5 @@ -392,6 +397,11 @@ 0 RW num_triggers + + formuu1 + formuu3 + enumm3 +
0x180
-- cgit v1.2.3 From e43b676d8294f37410ea0fa1f9fa39d10df64408 Mon Sep 17 00:00:00 2001 From: "nicolas.zilio@hotmail.fr" <> Date: Tue, 15 Sep 2015 17:27:27 +0200 Subject: not perfect but working --- pcilib/views.c | 93 ++++++++++++++++++++++++++++++++--------------------- pcilib/xml.c | 1 - pcitool/cli.c | 6 ++-- xml/test/camera.xml | 26 +++++++-------- 4 files changed, 71 insertions(+), 55 deletions(-) (limited to 'xml') diff --git a/pcilib/views.c b/pcilib/views.c index 12c09e5..83c5827 100644 --- a/pcilib/views.c +++ b/pcilib/views.c @@ -50,7 +50,7 @@ pcilib_view_compute_formula(pcilib_t* ctx, char* formula,char* reg_value_string) while(1){ reg = strchr(src, '@'); if (!reg) { - strcpy(dst, src); + strcpy(dst+offset, src); break; } regend = strchr(reg + 1, '@'); @@ -64,10 +64,9 @@ pcilib_view_compute_formula(pcilib_t* ctx, char* formula,char* reg_value_string) /* Now (reg + 1) contains the proper register name, you can compare it to reg/value and either get the value of current register or the specified one. Add it to the register*/ - if(!(strcasecmp(reg,"@value")) || !(strcasecmp(reg,"@reg")) || !(strcasecmp(reg,"@self"))){ + if(!(strcasecmp(reg+1,"value")) || !(strcasecmp(reg+1,"reg")) || !(strcasecmp(reg+1,"self"))){ strncpy(dst+offset,reg_value_string,strlen(reg_value_string)); offset+=strlen(reg_value_string); - }else{ pcilib_read_register(ctx, NULL,reg+1,&value); sprintf(temp,"%i",value); @@ -76,7 +75,6 @@ specified one. Add it to the register*/ } src = regend + 1; } - return dst; } @@ -89,8 +87,8 @@ pcilib_view_apply_formula(pcilib_t* ctx, char* formula, pcilib_register_value_t* char reg_value_string[66]; /* to register reg_value as a string, need to check the length*/ sprintf(reg_value_string,"%u",*reg_value); - formula=pcilib_view_compute_formula(ctx,formula,reg_value_string); + if(!(formula)){ pcilib_error("computing of formula failed"); return PCILIB_ERROR_INVALID_DATA; @@ -122,7 +120,7 @@ pcilib_view_apply_unit(pcilib_transform_unit_t unit_desc, const char* unit,pcili int pcilib_read_view(pcilib_t *ctx, const char *bank, const char *regname, const char *unit, size_t value_size, void *value) { - int i,j,err=0; + int i,j,k,err=0; pcilib_register_value_t temp_value; /* we get the index of the register to find the corresponding register context*/ @@ -139,37 +137,37 @@ int pcilib_read_view(pcilib_t *ctx, const char *bank, const char *regname, const } - for(j=0;ctx->num_views;j++){ - if(!(ctx->register_ctx[i].views[j].name)) break; - if(ctx->register_ctx[i].views[j].name) printf("name %s\n",ctx->register_ctx[i].views[j].name); - } - - for(j=0;ctx->num_views;j++){ - if(!(ctx->register_ctx[i].views[j].name)) break; - if(ctx->register_ctx[i].views[j].name){ - printf("unit %s, view %s\n",unit,ctx->register_ctx[i].views[j].name); - if(!(strcasecmp(ctx->register_ctx[i].views[j].base_unit.name,unit))){/*if we asked for the unit "name"*/ - printf("in unit\n"); + for(j=0;ctx->register_ctx[i].views[j].name;j++){ + if(!(strcasecmp("name",ctx->register_ctx[i].views[j].base_unit.name))){/*if we asked for the unit "name"*/ err=ctx->register_ctx[i].views[j].op(ctx,ctx->register_ctx[i].views[j].parameters,value/*the command name*/,0,&temp_value,0,&(ctx->register_ctx[i].views[j])); if(err){ - pcilib_error("can't write to the register with the enum view"); + pcilib_error("can't read from the register with the enum view"); return PCILIB_ERROR_FAILED; } - - break; - }else if(!(strcasecmp(ctx->register_ctx[i].views[j].name,(char*)unit))){/*in this case we asked for the name of the view in unit*/ - printf("pass here2\n"); + return 0; + }else if(!(strcasecmp(ctx->register_ctx[i].views[j].base_unit.name,(char*)unit))){/*in this case we asked for the name of the view in unit*/ err=ctx->register_ctx[i].views[j].op(ctx,ctx->register_ctx[i].views[j].parameters,(char*)unit, 0, &temp_value,0,&(ctx->register_ctx[i].views[j])); if(err){ - pcilib_error("can't write to the register with the formula view %s", unit); + pcilib_error("can't read from the register with the formula view %s", unit); return PCILIB_ERROR_FAILED; } *(pcilib_register_value_t*)value=temp_value; - break; + return 0; + }else{ + for(k=0;ctx->register_ctx[i].views[j].base_unit.transforms[k].name;k++){ + if(!(strcasecmp(ctx->register_ctx[i].views[j].base_unit.transforms[k].name,(char*)unit))){ + err=ctx->register_ctx[i].views[j].op(ctx,ctx->register_ctx[i].views[j].parameters,(char*)unit, 0, &temp_value,0,&(ctx->register_ctx[i].views[j])); + if(err){ + pcilib_error("can't write to the register with the formula view %s", unit); + return PCILIB_ERROR_FAILED; + } + *(pcilib_register_value_t*)value=temp_value; + return 0; + } + } } - return 0; - } } + pcilib_error("the view asked and the register do not correspond"); return PCILIB_ERROR_NOTAVAILABLE; } @@ -179,43 +177,64 @@ int pcilib_read_view(pcilib_t *ctx, const char *bank, const char *regname, const * function to write to a register using a view */ int pcilib_write_view(pcilib_t *ctx, const char *bank, const char *regname, const char *unit, size_t value_size,void* value){ - int i,j; + int i,j,k; pcilib_register_value_t temp_value; int err; + int next=1,ok=0; /* we get the index of the register to find the corresponding register context*/ if((i=pcilib_find_register(ctx,bank,regname))==PCILIB_REGISTER_INVALID){ pcilib_error("can't get the index of the register %s", regname); return PCILIB_ERROR_INVALID_REQUEST; } - + for(j=0;ctx->register_ctx[i].views[j].name;j++){ - if(!(strcasecmp(ctx->register_ctx[i].views[j].base_unit.name,unit))){/*if we asked for the unit "name"*/ - err=ctx->register_ctx[i].views[j].op(ctx,ctx->register_ctx[i].views[j].parameters,value/*the command name*/,1,&temp_value,0,&(ctx->register_ctx[i].views[j])); + if(!(strcasecmp(ctx->register_ctx[i].views[j].base_unit.name,"name"))){/*if we asked for the unit "name"*/ + err=ctx->register_ctx[i].views[j].op(ctx,ctx->register_ctx[i].views[j].parameters,(char*)unit/*the command name*/,1,&temp_value,0,&(ctx->register_ctx[i].views[j])); if(err){ pcilib_error("can't write to the register with the enum view"); return PCILIB_ERROR_FAILED; } + ok=1; break; - }else if(!(strcasecmp(ctx->register_ctx[i].views[j].name,(char*)unit))){/*in this case we asked for then name of the view in unit*/ + }else if(!(strcasecmp(ctx->register_ctx[i].views[j].base_unit.name,(char*)unit))){/*in this case we asked for then name of the view in unit*/ temp_value=*(pcilib_register_value_t*)value /*the value to put in the register*/; err=ctx->register_ctx[i].views[j].op(ctx,ctx->register_ctx[i].views[j].parameters, (char*)unit, 1, &temp_value,0,&(ctx->register_ctx[i].views[j])); if(err){ pcilib_error("can't write to the register with the formula view %s", unit); return PCILIB_ERROR_FAILED; } + ok=1; break; - } + }else{ + for(k=0;ctx->register_ctx[i].views[j].base_unit.transforms[k].name;k++){ + if(!(strcasecmp(ctx->register_ctx[i].views[j].base_unit.transforms[k].name,(char*)unit))){ + err=ctx->register_ctx[i].views[j].op(ctx,ctx->register_ctx[i].views[j].parameters, (char*)unit, 1, &temp_value,0,&(ctx->register_ctx[i].views[j])); + if(err){ + pcilib_error("can't write to the register with the formula view %s", unit); + return PCILIB_ERROR_FAILED; + } + next=0; + ok=1; + break; + } + } + if(next==0)break; + } + } + + if(ok==1) { pcilib_write_register(ctx,bank,regname,temp_value); + printf("value %i written in register\n",temp_value); return 0; } - + pcilib_error("the view asked and the register do not correspond"); return PCILIB_ERROR_NOTAVAILABLE; } /** - * always: viewval=view params=view params + * always : viewval=view params=view params * write: name=enum command regval:the value corresponding to the command */ int operation_enum(pcilib_t *ctx, void *params, char* name, int view2reg, pcilib_register_value_t *regval, size_t viewval_size, void* viewval){ @@ -229,7 +248,7 @@ int operation_enum(pcilib_t *ctx, void *params, char* name, int view2reg, pcilib } }else if (view2reg==0){ for(j=0; ((pcilib_enum_t*)(params))[j].name;j++){ - if (*regval<((pcilib_enum_t*)(params))[j].max && *regval>((pcilib_enum_t*)(params))[j].min){ + if (*regval<=((pcilib_enum_t*)(params))[j].max && *regval>=((pcilib_enum_t*)(params))[j].min){ name=(char*)realloc(name,strlen(((pcilib_enum_t*)(params))[j].name)*sizeof(char)); strncpy(name,((pcilib_enum_t*)(params))[j].name, strlen(((pcilib_enum_t*)(params))[j].name)); k=strlen(((pcilib_enum_t*)(params))[j].name); @@ -250,7 +269,7 @@ int operation_formula(pcilib_t *ctx, void *params, char* unit, int view2reg, pci char* formula=NULL; if(view2reg==0){ - if(!(strcasecmp(unit, ((pcilib_view_t*)viewval)->base_unit.name))){ + if(!(strcasecmp(unit,((pcilib_view_t*)viewval)->base_unit.name))){ formula=malloc(sizeof(char)*strlen(((pcilib_formula_t*)params)->read_formula)); if(!(formula)){ pcilib_error("can't allocate memory for the formula"); @@ -271,7 +290,7 @@ int operation_formula(pcilib_t *ctx, void *params, char* unit, int view2reg, pci } strncpy(formula,((pcilib_formula_t*)params)->read_formula,strlen(((pcilib_formula_t*)params)->read_formula)); pcilib_view_apply_formula(ctx,formula, regval); - pcilib_view_apply_unit(((pcilib_view_t*)viewval)->base_unit.transforms[j],unit,&value); + pcilib_view_apply_unit(((pcilib_view_t*)viewval)->base_unit.transforms[j],unit,regval); return 0; } } diff --git a/pcilib/xml.c b/pcilib/xml.c index 47bcf5c..31b9926 100644 --- a/pcilib/xml.c +++ b/pcilib/xml.c @@ -864,7 +864,6 @@ int pcilib_process_xml(pcilib_t *ctx, const char *location) { for(j=0;jnum_views;j++){ if(!(ctx->register_ctx[i].views[j].name)) break; if(ctx->register_ctx[i].views[j].name){ - printf("register %s view %s\n",ctx->registers[i].name,ctx->register_ctx[i].views[j].name); pcilib_get_unit_of_view(ctx,&(ctx->register_ctx[i].views[j]),ctx->register_ctx[i].views[j].base_unit.name); } } diff --git a/pcitool/cli.c b/pcitool/cli.c index 69151b6..aa80b72 100644 --- a/pcitool/cli.c +++ b/pcitool/cli.c @@ -1033,7 +1033,6 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, pcilib_register_value_t value; if (reg && !(strchr(fullreg,'/'))) { - printf("pass1\n"); pcilib_register_t regid = pcilib_find_register(handle, bank, reg); bank_id = pcilib_find_register_bank_by_addr(handle, model_info->registers[regid].bank); format = model_info->banks[bank_id].format; @@ -1048,7 +1047,6 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, printf("\n"); } }else if(reg && (s1=strchr(fullreg,'/'))){ - printf("pass2\n"); char* enum_command=malloc(sizeof(char*)); if(!enum_command){ printf("Error allocating memory for the result\n"); @@ -1062,7 +1060,7 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, err = pcilib_read_view(handle,bank,regname,viewname,sizeof(char*),enum_command); if (err) printf("Error reading register %s with an enum view\n", reg); else { - printf("%s = %s\n", reg, (char*)enum_command); + printf("%s = %s\n", regname, (char*)enum_command); } free(enum_command); }else{ @@ -1339,7 +1337,7 @@ int WriteRegister(pcilib_t *handle, const pcilib_model_description_t *model_info if((regname)){ char *view_name; - view_name=fullregister+1;; + view_name=s1+1;; err = pcilib_write_view(handle,bank,regname,view_name,sizeof(pcilib_register_value_t),&value); if (err) printf("Error writing register %s using view %s\n",regname,view_name); free(fullregister); diff --git a/xml/test/camera.xml b/xml/test/camera.xml index 021ed61..6506467 100644 --- a/xml/test/camera.xml +++ b/xml/test/camera.xml @@ -463,8 +463,8 @@ formuu1 C - (503975./1024000)*@reg - 27315./100 - (@value + 27315./100)*(102400./503975) + (503975./1024000)*@reg@ - 27315./100 + (@value@ + 27315./100)*(102400./503975) formula to get real fpga temperature from the fpga_temperature register in decimal @@ -476,8 +476,8 @@ formuu2 C - ((1./4)*(@reg + 1200)) if @freq==0 else ((3./10)*(@reg + 1000)) - 4*@value + 1200 if @freq==0 else (10./3)*@value + 1000 + ((1./4)*(@reg@ + 1200)) if @freq@==0 else ((3./10)*(@reg@ + 1000)) + 4*@value@ + 1200 if @freq@==0 else (10./3)*@value@ + 1000 formula to get real sensor temperature from the sensor_temperature register in decimal @@ -503,21 +503,21 @@ - @self+273.15 - @self*(9./5)+32 + @self@+273.15 + @self@*(9./5)+32 - @self-273.15 - (@self-273.15)*(9./5)+32 + @self@-273.15 + (@self@-273.15)*(9./5)+32 - (@self-32)*5./9 - (@self+273.15-32)*5./9 + (@self@-32)*5./9 + (@self@+273.15-32)*5./9 - @self*1000 - @self*1000000 - @self*1000000000 + @self@*1000 + @self@*1000000 + @self@*1000000000 @self/1000 -- cgit v1.2.3