From: cekstam Date: Tue, 27 Mar 2018 12:11:52 +0000 (+0200) Subject: correcting all the wrongs X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=60280b80416be023d0d4a23a6a967da3f8865b75;p=collectd.git correcting all the wrongs , data->scale, data->shift --- diff --git a/src/modbus.c b/src/modbus.c index cf8b0b29..5b6fed21 100644 --- a/src/modbus.c +++ b/src/modbus.c @@ -394,16 +394,16 @@ static int mb_init_connection(mb_host_t *host) /* {{{ */ } /* }}} int mb_init_connection */ #endif /* !LEGACY_LIBMODBUS */ -#define CAST_TO_VALUE_T(ds, vt, raw) \ +#define CAST_TO_VALUE_T(ds, vt, raw, scale, shift) \ do { \ if ((ds)->ds[0].type == DS_TYPE_COUNTER) \ - (vt).counter = (((counter_t)(raw) * ds[0].scale) + ds[0].shift); \ + (vt).counter = (((counter_t)(raw) * scale) + shift); \ else if ((ds)->ds[0].type == DS_TYPE_GAUGE) \ - (vt).gauge = (((gauge_t)(raw) * ds[0].scale) + ds[0].shift); \ + (vt).gauge = (((gauge_t)(raw) * scale) + shift); \ else if ((ds)->ds[0].type == DS_TYPE_DERIVE) \ - (vt).derive = (((derive_t)(raw) * ds[0].scale) + ds[0].shift); \ + (vt).derive = (((derive_t)(raw) * scale) + shift); \ else /* if (ds->ds[0].type == DS_TYPE_ABSOLUTE) */ \ - (vt).absolute = (((absolute_t)(raw) * ds[0].scale) + ds[0].shift); \ + (vt).absolute = (((absolute_t)(raw) * scale) + shift); \ } while (0) static int mb_read_data(mb_host_t *host, mb_slave_t *slave, /* {{{ */ @@ -532,7 +532,7 @@ static int mb_read_data(mb_host_t *host, mb_slave_t *slave, /* {{{ */ "Returned float value is %g", (double)float_value); - CAST_TO_VALUE_T(ds, vt, float_value); + CAST_TO_VALUE_T(ds, vt, float_value, data->scale, data->shift); mb_submit(host, slave, data, vt); } else if (data->register_type == REG_TYPE_FLOAT_CDAB) { float float_value; @@ -543,7 +543,7 @@ static int mb_read_data(mb_host_t *host, mb_slave_t *slave, /* {{{ */ "Returned float value is %g", (double)float_value); - CAST_TO_VALUE_T(ds, vt, float_value); + CAST_TO_VALUE_T(ds, vt, float_value, data->scale, data->shift); mb_submit(host, slave, data, vt); } else if (data->register_type == REG_TYPE_INT32) { union { @@ -557,7 +557,7 @@ static int mb_read_data(mb_host_t *host, mb_slave_t *slave, /* {{{ */ "Returned int32 value is %" PRIi32, v.i32); - CAST_TO_VALUE_T(ds, vt, v.i32); + CAST_TO_VALUE_T(ds, vt, v.i32, data->scale, data->shift); mb_submit(host, slave, data, vt); } else if (data->register_type == REG_TYPE_INT32_CDAB) { union { @@ -571,7 +571,7 @@ static int mb_read_data(mb_host_t *host, mb_slave_t *slave, /* {{{ */ "Returned int32 value is %" PRIi32, v.i32); - CAST_TO_VALUE_T(ds, vt, v.i32); + CAST_TO_VALUE_T(ds, vt, v.i32, data->scale, data->shift); mb_submit(host, slave, data, vt); } else if (data->register_type == REG_TYPE_INT16) { union { @@ -586,7 +586,7 @@ static int mb_read_data(mb_host_t *host, mb_slave_t *slave, /* {{{ */ "Returned int16 value is %" PRIi16, v.i16); - CAST_TO_VALUE_T(ds, vt, v.i16); + CAST_TO_VALUE_T(ds, vt, v.i16, data->scale, data->shift); mb_submit(host, slave, data, vt); } else if (data->register_type == REG_TYPE_UINT32) { uint32_t v32; @@ -597,7 +597,7 @@ static int mb_read_data(mb_host_t *host, mb_slave_t *slave, /* {{{ */ "Returned uint32 value is %" PRIu32, v32); - CAST_TO_VALUE_T(ds, vt, v32); + CAST_TO_VALUE_T(ds, vt, v32, data->scale, data->shift); mb_submit(host, slave, data, vt); } else if (data->register_type == REG_TYPE_UINT32_CDAB) { uint32_t v32; @@ -608,7 +608,7 @@ static int mb_read_data(mb_host_t *host, mb_slave_t *slave, /* {{{ */ "Returned uint32 value is %" PRIu32, v32); - CAST_TO_VALUE_T(ds, vt, v32); + CAST_TO_VALUE_T(ds, vt, v32, data->scale, data->shift); mb_submit(host, slave, data, vt); } else /* if (data->register_type == REG_TYPE_UINT16) */ { @@ -618,7 +618,7 @@ static int mb_read_data(mb_host_t *host, mb_slave_t *slave, /* {{{ */ "Returned uint16 value is %" PRIu16, values[0]); - CAST_TO_VALUE_T(ds, vt, values[0]); + CAST_TO_VALUE_T(ds, vt, values[0], data->scale, data->shift); mb_submit(host, slave, data, vt); } @@ -741,11 +741,9 @@ static int mb_config_add_data(oconfig_item_t *ci) /* {{{ */ status = cf_util_get_string_buffer(child, data.instance, sizeof(data.instance)); else if (strcasecmp("Scale", child->key) == 0) - status = cf_util_get_string_buffer(child, data.scale, - sizeof(data.scale)); + status = cf_util_get_double(child, &data.scale); else if (strcasecmp("Shift", child->key) == 0) - status = cf_util_get_string_buffer(child, data.shift, - sizeof(data.shift)); + status = cf_util_get_double(child, &data.shift); else if (strcasecmp("RegisterBase", child->key) == 0) status = cf_util_get_int(child, &data.register_base); else if (strcasecmp("RegisterType", child->key) == 0) {