X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fmodbus.c;h=d2b0a535ff9a0dd135f05fe2b217145ccc9c0315;hb=5293f334d4bbdc746b42d3dfebd5ef1680b58d05;hp=589193811c3a827514a9a5d008ea6c3be419cb8e;hpb=de9cbff39b893f445d678c0a3bc3f8fb0456f42b;p=collectd.git diff --git a/src/modbus.c b/src/modbus.c index 58919381..d2b0a535 100644 --- a/src/modbus.c +++ b/src/modbus.c @@ -27,7 +27,7 @@ #include -#include +#include #ifndef LIBMODBUS_VERSION_CHECK /* Assume version 2.0.3 */ @@ -47,9 +47,9 @@ /* * * RegisterBase 1234 + * RegisterCmd ReadHolding * RegisterType float * Type gauge - * ModbusRegisterType holding * Instance "..." * * @@ -426,7 +426,7 @@ static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */ uint16_t values[2]; int values_num; const data_set_t *ds; - int status; + int status = 0; if ((host == NULL) || (slave == NULL) || (data == NULL)) return (EINVAL); @@ -440,7 +440,7 @@ static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */ if (ds->ds_num != 1) { - ERROR ("Modbus plugin: The type \"%s\" has %i data sources. " + ERROR ("Modbus plugin: The type \"%s\" has %zu data sources. " "I can only handle data sets with only one data source.", data->type, ds->ds_num); return (-1); @@ -463,7 +463,6 @@ static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */ else values_num = 1; - status = 0; if (host->connection == NULL) { status = EBADF; @@ -733,7 +732,6 @@ static int mb_config_add_data (oconfig_item_t *ci) /* {{{ */ for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; - status = 0; if (strcasecmp ("Type", child->key) == 0) status = cf_util_get_string_buffer (child, @@ -765,19 +763,19 @@ static int mb_config_add_data (oconfig_item_t *ci) /* {{{ */ status = -1; } } - else if (strcasecmp ("ModbusRegisterType", child->key) == 0) + else if (strcasecmp ("RegisterCmd", child->key) == 0) { #if LEGACY_LIBMODBUS - ERROR("Modbus plugin: ModbusRegisterType parameter can not be used " + ERROR("Modbus plugin: RegisterCmd parameter can not be used " "with your libmodbus version"); #else char tmp[16]; status = cf_util_get_string_buffer (child, tmp, sizeof (tmp)); if (status != 0) /* do nothing */; - else if (strcasecmp ("holding", tmp) == 0) + else if (strcasecmp ("ReadHolding", tmp) == 0) data.modbus_register_type = MREG_HOLDING; - else if (strcasecmp ("input", tmp) == 0) + else if (strcasecmp ("ReadInput", tmp) == 0) data.modbus_register_type = MREG_INPUT; else { @@ -894,7 +892,6 @@ static int mb_config_add_slave (mb_host_t *host, oconfig_item_t *ci) /* {{{ */ for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; - status = 0; if (strcasecmp ("Instance", child->key) == 0) status = cf_util_get_string_buffer (child, @@ -945,9 +942,15 @@ static int mb_config_add_host (oconfig_item_t *ci) /* {{{ */ status = cf_util_get_string_buffer (ci, host->host, sizeof (host->host)); if (status != 0) + { + sfree (host); return (status); + } if (host->host[0] == 0) + { + sfree (host); return (EINVAL); + } for (i = 0; i < ci->children_num; i++) { @@ -1017,18 +1020,15 @@ static int mb_config_add_host (oconfig_item_t *ci) /* {{{ */ { user_data_t ud; char name[1024]; - struct timespec interval = { 0, 0 }; ud.data = host; ud.free_func = host_free; ssnprintf (name, sizeof (name), "modbus-%s", host->host); - CDTIME_T_TO_TIMESPEC (host->interval, &interval); - plugin_register_complex_read (/* group = */ NULL, name, /* callback = */ mb_read, - /* interval = */ (host->interval > 0) ? &interval : NULL, + /* interval = */ host->interval, &ud); } else