From: Pavel Rochnyack Date: Thu, 24 May 2018 14:27:59 +0000 (+0700) Subject: Merge pull request #2729 from cekstam/add-scale-and-shift-to-modbus X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=0d5f3a040375be8936a85614e31c589f668cebaf;p=collectd.git Merge pull request #2729 from cekstam/add-scale-and-shift-to-modbus --- 0d5f3a040375be8936a85614e31c589f668cebaf diff --cc src/collectd.conf.in index 30791bd6,6ec61f32..662b4835 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@@ -834,6 -809,6 +834,8 @@@ # RegisterType float # Type gauge # Instance "..." ++# #Scale 1.0 ++# #Shift 0.0 # # # diff --cc src/collectd.conf.pod index 36794cd1,329671ee..7a21ba2c --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@@ -4242,8 -4059,8 +4242,9 @@@ which the sizes of physical memory vary The B connects to a Modbus "slave" via Modbus/TCP or Modbus/RTU and reads register values. It supports reading single registers (unsigned 16Ebit --values), large integer values (unsigned 32Ebit values) and floating point --values (two registers interpreted as IEEE floats in big endian notation). ++values), large integer values (unsigned 32Ebit and 64Ebit values) and ++floating point values (two registers interpreted as IEEE floats in big endian ++notation). B @@@ -4253,6 -4070,6 +4254,8 @@@ RegisterCmd ReadHolding Type voltage Instance "input-1" ++ #Scale 1.0 ++ #Shift 0.0 @@@ -4341,9 -4155,19 +4344,19 @@@ supported =item B I --Sets the type instance to use when dispatching the value to I. If ++Sets the type instance to use when dispatching the value to I. If unset, an empty string (no type instance) is used. + =item B I + -The values taken from collectd are multiplied by I. The field is optional ++The values taken from device are multiplied by I. The field is optional + and the default is B<1.0>. + + =item B I + -I is added to values from collectd after they have been multiplied by ++I is added to values from device after they have been multiplied by + B value. The field is optional and the default value is B<0.0>. + =back =item EB IE blocks diff --cc src/modbus.c index 40e0079e,64227741..bb9eaa0f --- a/src/modbus.c +++ b/src/modbus.c @@@ -613,35 -608,8 +615,35 @@@ static int mb_read_data(mb_host_t *host "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_UINT64) { + uint64_t v64; + value_t vt; + + v64 = (((uint64_t)values[0]) << 48) | (((uint64_t)values[1]) << 32) | + (((uint64_t)values[2]) << 16) | (((uint64_t)values[3])); + DEBUG("Modbus plugin: mb_read_data: " + "Returned uint64 value is %" PRIu64, + v64); + - CAST_TO_VALUE_T(ds, vt, v64); ++ CAST_TO_VALUE_T(ds, vt, v64, data->scale, data->shift); + mb_submit(host, slave, data, vt); + } else if (data->register_type == REG_TYPE_INT64) { + union { + uint64_t u64; + int64_t i64; + } v; + value_t vt; + + v.u64 = (((uint64_t)values[0]) << 48) | (((uint64_t)values[1]) << 32) | + (((uint64_t)values[2]) << 16) | ((uint64_t)values[3]); + DEBUG("Modbus plugin: mb_read_data: " + "Returned uint64 value is %" PRIi64, + v.i64); + - CAST_TO_VALUE_T(ds, vt, v.i64); ++ CAST_TO_VALUE_T(ds, vt, v.i64, data->scale, data->shift); + mb_submit(host, slave, data, vt); } else /* if (data->register_type == REG_TYPE_UINT16) */ { value_t vt;