summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2015-10-18 04:47:09 +0200
committerSuren A. Chilingaryan <csa@suren.me>2015-10-18 04:47:09 +0200
commit6a4a556b15bda7e0c737f247c8282c1b3a9d1e0d (patch)
treeb7a115d7b931ec9e63bb54fc85c476cf55a90064
parent1c52a32779de1569ea41267ac6fc8f51c5a8b7fd (diff)
downloadpcitool-6a4a556b15bda7e0c737f247c8282c1b3a9d1e0d.tar.gz
pcitool-6a4a556b15bda7e0c737f247c8282c1b3a9d1e0d.tar.bz2
pcitool-6a4a556b15bda7e0c737f247c8282c1b3a9d1e0d.tar.xz
pcitool-6a4a556b15bda7e0c737f247c8282c1b3a9d1e0d.zip
Support properties in transform formulas
-rw-r--r--pcilib/py.c31
-rw-r--r--xml/test/camera.xml2
2 files changed, 26 insertions, 7 deletions
diff --git a/pcilib/py.c b/pcilib/py.c
index def050e..5ec122f 100644
--- a/pcilib/py.c
+++ b/pcilib/py.c
@@ -108,7 +108,17 @@ static char *pcilib_py_parse_string(pcilib_t *ctx, const char *codestr, pcilib_v
// find the end of the register name
reg++;
- for (i = 0; isalnum(reg[i])||(reg[i] == '_'); i++);
+ if (*reg == '{') {
+ reg++;
+ for (i = 0; (reg[i])&&(reg[i] != '}'); i++);
+ if (!reg[i]) {
+ pcilib_error("Python formula (%s) contains unterminated variable reference", codestr);
+ err = PCILIB_ERROR_INVALID_DATA;
+ break;
+ }
+ } else {
+ for (i = 0; isalnum(reg[i])||(reg[i] == '_'); i++);
+ }
save = reg[i];
reg[i] = 0;
@@ -122,14 +132,23 @@ static char *pcilib_py_parse_string(pcilib_t *ctx, const char *codestr, pcilib_v
strcpy(dst + offset, val.sval);
} else {
- err = pcilib_read_register(ctx, NULL, reg, &regval);
- if (err) break;
-
- sprintf(dst + offset, "0x%x", regval);
+ if (*reg == '/') {
+ pcilib_value_t val = {0};
+ err = pcilib_get_property(ctx, reg, &val);
+ if (err) break;
+ err = pcilib_convert_value_type(ctx, &val, PCILIB_TYPE_STRING);
+ if (err) break;
+ sprintf(dst + offset, "%s", val.sval);
+ } else {
+ err = pcilib_read_register(ctx, NULL, reg, &regval);
+ if (err) break;
+ sprintf(dst + offset, "0x%x", regval);
+ }
}
offset += strlen(dst + offset);
- reg[i] = save;
+ if (save == '}') i++;
+ else reg[i] = save;
// Advance to the next register if any
cur = reg + i;
diff --git a/xml/test/camera.xml b/xml/test/camera.xml
index 9df8de2..14d1510 100644
--- a/xml/test/camera.xml
+++ b/xml/test/camera.xml
@@ -106,7 +106,7 @@
<register address="0x1b0" offset="0" size="32" default="0" rwmask="0" mode="R" name="ddr_num_frames"/>
</bank>
<bank bar="0" size="0x0200" protocol="software_registers" read_address="0x0" write_address="0x0" word_size="32" endianess="little" format="0x%lx" name="dma" description="DMA Registers"/>
- <transform path="/test/prop1" unit="C" read_from_register="(503975./1024000)*$sensor_temperature - 27315./100" write_to_register="($sensor_temperature + 27315./100)*(1024000./503975)" description="formula to get real fpga temperature from the fpga_temperature register in decimal"/>
+ <transform path="/test/prop1" unit="C" read_from_register="(503975./1024000)*${/registers/fpga/sensor_temperature:C} - 27315./100" write_to_register="(${/registers/fpga/sensor_temperature:C} + 27315./100)*(1024000./503975)" description="formula to get real fpga temperature from the fpga_temperature register in decimal"/>
<transform name="formuu1" unit="C" read_from_register="(503975./1024000)*$value - 27315./100" write_to_register="($value + 27315./100)*(1024000./503975)" description="formula to get real fpga temperature from the fpga_temperature register in decimal"/>
<transform name="formuu2" unit="C1" read_from_register="((1./4)*($value - 1200)) if $freq==0 else ((3./10)*($value - 1000))" write_to_register="4*$value + 1200 if $freq==0 else (10./3)*$value + 1000" description="formula to get real sensor temperature from the sensor_temperature register in decimal"/>
<transform name="formuu3" unit="us" read_from_register="($value+(43./100))*129./(40*1000000)if $freq==0 else ($value+(43./100))*129./(48*1000000)" write_to_register="$value/129.*(40*1000000) - 43./100 if $freq==0 else $value/129.*(48*1000000) - 43./100" description="formula to get real exposure time from the cmosis_exp_time register in decimal"/>