diff options
author | Bjørn Mork <bjorn@mork.no> | 2019-05-25 17:53:26 +0200 |
---|---|---|
committer | Bjørn Mork <bjorn@mork.no> | 2019-05-25 17:53:26 +0200 |
commit | 8e23ba0dfdbaa015a05d9fb70ed9d2e148c6dba7 (patch) | |
tree | 4bb7d41faf9c4570fccc653aa456f47d1cc15342 | |
parent | 53d507626e65512951de719d62da678f33543c3d (diff) |
multiply instead of divide to allow scaling both up and down
Signed-off-by: Bjørn Mork <bjorn@mork.no>
-rw-r--r-- | aidon_v0001.json | 28 | ||||
-rw-r--r-- | kaifa_v0001.json | 28 | ||||
-rw-r--r-- | kamstrup_v0001.json | 28 | ||||
-rw-r--r-- | obinsectd.c | 25 |
4 files changed, 54 insertions, 55 deletions
diff --git a/aidon_v0001.json b/aidon_v0001.json index abfff17..628c053 100644 --- a/aidon_v0001.json +++ b/aidon_v0001.json @@ -2,20 +2,20 @@ "1-1:0.2.129.255" : { "name" : "ListId", "value" : "AIDON_V0001" }, "0-0:96.1.0.255" : { "name" : "SerialNumber" }, "0-0:96.1.7.255" : { "name" : "Model" }, - "1-0:1.7.0.255" : { "name" : "Power", "unit" : "kW", "scale" : 1000 }, - "1-0:2.7.0.255" : { "name" : "PowerExport", "unit" : "kW", "scale" : 1000 }, - "1-0:3.7.0.255" : { "name" : "ReactivePower", "unit" : "kW", "scale" : 1000 }, - "1-0:4.7.0.255" : { "name" : "ReactivePowerExport", "unit" : "kW", "scale" : 1000 }, - "1-0:31.7.0.255" : { "name" : "CurrentL1", "unit" : "A", "scale" : 10 }, - "1-0:51.7.0.255" : { "name" : "CurrentL2", "unit" : "A", "scale" : 10 }, - "1-0:71.7.0.255" : { "name" : "CurrentL3", "unit" : "A", "scale" : 10 }, - "1-0:32.7.0.255" : { "name" : "VoltageL1", "unit" : "V", "scale" : 10 }, - "1-0:52.7.0.255" : { "name" : "VoltageL2", "unit" : "V", "scale" : 10 }, - "1-0:72.7.0.255" : { "name" : "VoltageL3", "unit" : "V", "scale" : 10 }, + "1-0:1.7.0.255" : { "name" : "Power", "unit" : "kW", "scale" : 0.001 }, + "1-0:2.7.0.255" : { "name" : "PowerExport", "unit" : "kW", "scale" : 0.001 }, + "1-0:3.7.0.255" : { "name" : "ReactivePower", "unit" : "kW", "scale" : 0.001 }, + "1-0:4.7.0.255" : { "name" : "ReactivePowerExport", "unit" : "kW", "scale" : 0.001 }, + "1-0:31.7.0.255" : { "name" : "CurrentL1", "unit" : "A", "scale" : 0.1 }, + "1-0:51.7.0.255" : { "name" : "CurrentL2", "unit" : "A", "scale" : 0.1 }, + "1-0:71.7.0.255" : { "name" : "CurrentL3", "unit" : "A", "scale" : 0.1 }, + "1-0:32.7.0.255" : { "name" : "VoltageL1", "unit" : "V", "scale" : 0.1 }, + "1-0:52.7.0.255" : { "name" : "VoltageL2", "unit" : "V", "scale" : 0.1 }, + "1-0:72.7.0.255" : { "name" : "VoltageL3", "unit" : "V", "scale" : 0.1 }, "0-0:1.0.0.255" : { "name" : "MeterTime" }, - "1-0:1.8.0.255" : { "name" : "CumulativeEnergy", "unit" : "kWh", "scale" : 100 }, - "1-0:2.8.0.255" : { "name" : "CumulativeEnergyExport", "unit" : "kWh", "scale" : 100 }, - "1-0:3.8.0.255" : { "name" : "CumulativeReactiveEnergy", "unit" : "kVArh", "scale" : 100 }, - "1-0:4.8.0.255" : { "name" : "CumulativeReactiveEnergyExport", "unit" : "kVArh", "scale" : 100 } + "1-0:1.8.0.255" : { "name" : "CumulativeEnergy", "unit" : "kWh", "scale" : 0.01 }, + "1-0:2.8.0.255" : { "name" : "CumulativeEnergyExport", "unit" : "kWh", "scale" : 0.01 }, + "1-0:3.8.0.255" : { "name" : "CumulativeReactiveEnergy", "unit" : "kVArh", "scale" : 0.01 }, + "1-0:4.8.0.255" : { "name" : "CumulativeReactiveEnergyExport", "unit" : "kVArh", "scale" : 0.01 } } diff --git a/kaifa_v0001.json b/kaifa_v0001.json index d6e0092..b04957f 100644 --- a/kaifa_v0001.json +++ b/kaifa_v0001.json @@ -2,20 +2,20 @@ "1-1:0.2.129.255" : { "name" : "ListId", "value" : "KFM_001" }, "0-0:96.1.0.255" : { "name" : "SerialNumber" }, "0-0:96.1.7.255" : { "name" : "Model" }, - "1-0:1.7.0.255" : { "name" : "Power", "unit" : "kW", "scale" : 1000 }, - "1-0:2.7.0.255" : { "name" : "PowerExport", "unit" : "kW", "scale" : 1000 }, - "1-0:3.7.0.255" : { "name" : "ReactivePower", "unit" : "kW", "scale" : 1000 }, - "1-0:4.7.0.255" : { "name" : "ReactivePowerExport", "unit" : "kW", "scale" : 1000 }, - "1-0:31.7.0.255" : { "name" : "CurrentL1", "unit" : "A", "scale" : 10 }, - "1-0:51.7.0.255" : { "name" : "CurrentL2", "unit" : "A", "scale" : 10 }, - "1-0:71.7.0.255" : { "name" : "CurrentL3", "unit" : "A", "scale" : 10 }, - "1-0:32.7.0.255" : { "name" : "VoltageL1", "unit" : "V", "scale" : 10 }, - "1-0:52.7.0.255" : { "name" : "VoltageL2", "unit" : "V", "scale" : 10 }, - "1-0:72.7.0.255" : { "name" : "VoltageL3", "unit" : "V", "scale" : 10 }, + "1-0:1.7.0.255" : { "name" : "Power", "unit" : "kW", "scale" : 0.001 }, + "1-0:2.7.0.255" : { "name" : "PowerExport", "unit" : "kW", "scale" : 0.001 }, + "1-0:3.7.0.255" : { "name" : "ReactivePower", "unit" : "kW", "scale" : 0.001 }, + "1-0:4.7.0.255" : { "name" : "ReactivePowerExport", "unit" : "kW", "scale" : 0.001 }, + "1-0:31.7.0.255" : { "name" : "CurrentL1", "unit" : "A", "scale" : 0.1 }, + "1-0:51.7.0.255" : { "name" : "CurrentL2", "unit" : "A", "scale" : 0.1 }, + "1-0:71.7.0.255" : { "name" : "CurrentL3", "unit" : "A", "scale" : 0.1 }, + "1-0:32.7.0.255" : { "name" : "VoltageL1", "unit" : "V", "scale" : 0.1 }, + "1-0:52.7.0.255" : { "name" : "VoltageL2", "unit" : "V", "scale" : 0.1 }, + "1-0:72.7.0.255" : { "name" : "VoltageL3", "unit" : "V", "scale" : 0.1 }, "0-0:1.0.0.255" : { "name" : "MeterTime" }, - "1-0:1.8.0.255" : { "name" : "CumulativeEnergy", "unit" : "kWh", "scale" : 1000 }, - "1-0:2.8.0.255" : { "name" : "CumulativeEnergyExport", "unit" : "kWh", "scale" : 1000 }, - "1-0:3.8.0.255" : { "name" : "CumulativeReactiveEnergy", "unit" : "kVArh", "scale" : 1000 }, - "1-0:4.8.0.255" : { "name" : "CumulativeReactiveEnergyExport", "unit" : "kVArh", "scale" : 1000 } + "1-0:1.8.0.255" : { "name" : "CumulativeEnergy", "unit" : "kWh", "scale" : 0.001 }, + "1-0:2.8.0.255" : { "name" : "CumulativeEnergyExport", "unit" : "kWh", "scale" : 0.001 }, + "1-0:3.8.0.255" : { "name" : "CumulativeReactiveEnergy", "unit" : "kVArh", "scale" : 0.001 }, + "1-0:4.8.0.255" : { "name" : "CumulativeReactiveEnergyExport", "unit" : "kVArh", "scale" : 0.001 } } diff --git a/kamstrup_v0001.json b/kamstrup_v0001.json index 2482895..cb6282b 100644 --- a/kamstrup_v0001.json +++ b/kamstrup_v0001.json @@ -2,19 +2,19 @@ "1-1:0.2.129.255" : { "name" : "ListId", "value" : "Kamstrup_V0001" }, "1-1:0.0.5.255" : { "name" : "SerialNumber" }, "1-1:96.1.1.255" : { "name" : "Model" }, - "1-1:1.7.0.255" : { "name" : "Power", "unit" : "kW", "scale" : 1000 }, - "1-1:2.7.0.255" : { "name" : "PowerExport", "unit" : "kW", "scale" : 1000 }, - "1-1:3.7.0.255" : { "name" : "ReactivePower", "unit" : "kW", "scale" : 1000 }, - "1-1:4.7.0.255" : { "name" : "ReactivePowerExport", "unit" : "kW", "scale" : 1000 }, - "1-1:31.7.0.255" : { "name" : "CurrentL1", "unit" : "A", "scale" : 100 }, - "1-1:51.7.0.255" : { "name" : "CurrentL2", "unit" : "A", "scale" : 100 }, - "1-1:71.7.0.255" : { "name" : "CurrentL3", "unit" : "A", "scale" : 100 }, - "1-1:32.7.0.255" : { "name" : "VoltageL1", "unit" : "V", "scale" : 1 }, - "1-1:52.7.0.255" : { "name" : "VoltageL2", "unit" : "V", "scale" : 1 }, - "1-1:72.7.0.255" : { "name" : "VoltageL3", "unit" : "V", "scale" : 1 }, + "1-1:1.7.0.255" : { "name" : "Power", "unit" : "kW", "scale" : 0.001 }, + "1-1:2.7.0.255" : { "name" : "PowerExport", "unit" : "kW", "scale" : 0.001 }, + "1-1:3.7.0.255" : { "name" : "ReactivePower", "unit" : "kW", "scale" : 0.001 }, + "1-1:4.7.0.255" : { "name" : "ReactivePowerExport", "unit" : "kW", "scale" : 0.001 }, + "1-1:31.7.0.255" : { "name" : "CurrentL1", "unit" : "A", "scale" : 0.01 }, + "1-1:51.7.0.255" : { "name" : "CurrentL2", "unit" : "A", "scale" : 0.01 }, + "1-1:71.7.0.255" : { "name" : "CurrentL3", "unit" : "A", "scale" : 0.01 }, + "1-1:32.7.0.255" : { "name" : "VoltageL1", "unit" : "V" }, + "1-1:52.7.0.255" : { "name" : "VoltageL2", "unit" : "V" }, + "1-1:72.7.0.255" : { "name" : "VoltageL3", "unit" : "V" }, "0-1:1.0.0.255" : { "name" : "MeterTime" }, - "1-1:1.8.0.255" : { "name" : "CumulativeEnergy", "unit" : "kWh", "scale" : 100 }, - "1-1:2.8.0.255" : { "name" : "CumulativeEnergyExport", "unit" : "kWh", "scale" : 100 }, - "1-1:3.8.0.255" : { "name" : "CumulativeReactiveEnergy", "unit" : "kVArh", "scale" : 100 }, - "1-1:4.8.0.255" : { "name" : "CumulativeReactiveEnergyExport", "unit" : "kVArh", "scale" : 100 } + "1-1:1.8.0.255" : { "name" : "CumulativeEnergy", "unit" : "kWh", "scale" : 0.01 }, + "1-1:2.8.0.255" : { "name" : "CumulativeEnergyExport", "unit" : "kWh", "scale" : 0.01 }, + "1-1:3.8.0.255" : { "name" : "CumulativeReactiveEnergy", "unit" : "kVArh", "scale" : 0.01 }, + "1-1:4.8.0.255" : { "name" : "CumulativeReactiveEnergyExport", "unit" : "kVArh", "scale" : 0.01 } } diff --git a/obinsectd.c b/obinsectd.c index 4f588fc..67d0348 100644 --- a/obinsectd.c +++ b/obinsectd.c @@ -964,17 +964,17 @@ static json_object *obis_get_val(const char *key, json_object *val) return json_object_get(val); } -static int get_scale(const char *key) +static double get_scale(const char *key) { json_object *scale, *ret; if (!current_list) - return 1; + return 0; if (!json_object_object_get_ex(current_list, "scale", &scale)) - return 1; + return 0; if (json_object_object_get_ex(scale, key, &ret)) - return json_object_get_int(ret); - return 1; + return json_object_get_double(ret); + return 0; } static const char *get_alias(const char *key) @@ -1033,16 +1033,13 @@ static void add_obis(json_object *pubcfg, json_object *pub, const char *key, jso { const char *alias = get_alias(key); json_object *normal, *newval = val; - int scale = get_scale(key); - double f; + double scale = get_scale(key); debug("*** adding %s ***\n", key); if (!current_list && !strcmp(key, "1-1:0.2.129.255")) set_current_list(json_object_get_string(val)); - if (scale > 1) { - f = (double)json_object_get_int(val) / scale; - newval = json_object_new_double(f); - } + if (scale) + newval = json_object_new_double(json_object_get_int(val) * scale); if (json_object_object_get_ex(pub, "normal", &normal)) json_object_object_add(normal, key, newval); add_keyval(pubcfg, pub, key, newval, true); @@ -1527,7 +1524,7 @@ static json_object *parse_obisfile(json_object *lists, const char *fname, char * static json_object *read_config(const char *fname, char *buf, size_t bufsize) { - json_object *tmp, *obis, *list, *ret; + json_object *tmp, *obis, *list, *ret, *parsed; const char *name; int i ; @@ -1546,7 +1543,9 @@ static json_object *read_config(const char *fname, char *buf, size_t bufsize) for (i = 0; i < json_object_array_length(tmp); i++) { name = json_object_get_string(json_object_array_get_idx(tmp, i)); - json_object_object_add(obis, name, parse_obisfile(list, name, buf, bufsize)); + parsed = parse_obisfile(list, name, buf, bufsize); + if (parsed) + json_object_object_add(obis, name, parsed); } } |