1 /**
2 * collectd - src/modbus.c
3 * Copyright (C) 2010 noris network AG
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 *
18 * Authors:
19 * Florian Forster <octo at noris.net>
20 **/
22 #include "collectd.h"
23 #include "common.h"
24 #include "plugin.h"
25 #include "configfile.h"
27 #include <netdb.h>
29 #include <modbus/modbus.h>
31 #ifndef MODBUS_TCP_DEFAULT_PORT
32 # ifdef MODBUS_TCP_PORT
33 # define MODBUS_TCP_DEFAULT_PORT MODBUS_TCP_PORT
34 # else
35 # define MODBUS_TCP_DEFAULT_PORT 502
36 # endif
37 #endif
39 /*
40 * <Data "data_name">
41 * RegisterBase 1234
42 * RegisterType float
43 * Type gauge
44 * Instance "..."
45 * </Data>
46 *
47 * <Host "name">
48 * Address "addr"
49 * Port "1234"
50 * Interval 60
51 *
52 * <Slave 1>
53 * Instance "foobar" # optional
54 * Collect "data_name"
55 * </Slave>
56 * </Host>
57 */
59 /*
60 * Data structures
61 */
62 enum mb_register_type_e /* {{{ */
63 {
64 REG_TYPE_UINT16,
65 REG_TYPE_UINT32,
66 REG_TYPE_FLOAT
67 }; /* }}} */
68 typedef enum mb_register_type_e mb_register_type_t;
70 struct mb_data_s;
71 typedef struct mb_data_s mb_data_t;
72 struct mb_data_s /* {{{ */
73 {
74 char *name;
75 int register_base;
76 mb_register_type_t register_type;
77 char type[DATA_MAX_NAME_LEN];
78 char instance[DATA_MAX_NAME_LEN];
80 mb_data_t *next;
81 }; /* }}} */
83 struct mb_slave_s /* {{{ */
84 {
85 int id;
86 char instance[DATA_MAX_NAME_LEN];
87 mb_data_t *collect;
88 }; /* }}} */
89 typedef struct mb_slave_s mb_slave_t;
91 struct mb_host_s /* {{{ */
92 {
93 char host[DATA_MAX_NAME_LEN];
94 char node[NI_MAXHOST];
95 /* char service[NI_MAXSERV]; */
96 int port;
97 int interval;
99 mb_slave_t *slaves;
100 size_t slaves_num;
102 modbus_param_t connection;
103 _Bool is_connected;
104 _Bool have_reconnected;
105 }; /* }}} */
106 typedef struct mb_host_s mb_host_t;
108 struct mb_data_group_s;
109 typedef struct mb_data_group_s mb_data_group_t;
110 struct mb_data_group_s /* {{{ */
111 {
112 mb_data_t *registers;
113 size_t registers_num;
115 mb_data_group_t *next;
116 }; /* }}} */
118 /*
119 * Global variables
120 */
121 static mb_data_t *data_definitions = NULL;
123 /*
124 * Functions
125 */
126 static mb_data_t *data_get_by_name (mb_data_t *src, /* {{{ */
127 const char *name)
128 {
129 mb_data_t *ptr;
131 if (name == NULL)
132 return (NULL);
134 for (ptr = src; ptr != NULL; ptr = ptr->next)
135 if (strcasecmp (ptr->name, name) == 0)
136 return (ptr);
138 return (NULL);
139 } /* }}} mb_data_t *data_get_by_name */
141 static int data_append (mb_data_t **dst, mb_data_t *src) /* {{{ */
142 {
143 mb_data_t *ptr;
145 if ((dst == NULL) || (src == NULL))
146 return (EINVAL);
148 ptr = *dst;
150 if (ptr == NULL)
151 {
152 *dst = src;
153 return (0);
154 }
156 while (ptr->next != NULL)
157 ptr = ptr->next;
159 ptr->next = src;
161 return (0);
162 } /* }}} int data_append */
164 /* Copy a single mb_data_t and append it to another list. */
165 static int data_copy (mb_data_t **dst, const mb_data_t *src) /* {{{ */
166 {
167 mb_data_t *tmp;
168 int status;
170 if ((dst == NULL) || (src == NULL))
171 return (EINVAL);
173 tmp = malloc (sizeof (*tmp));
174 if (tmp == NULL)
175 return (ENOMEM);
176 memcpy (tmp, src, sizeof (*tmp));
177 tmp->name = NULL;
178 tmp->next = NULL;
180 tmp->name = strdup (src->name);
181 if (tmp->name == NULL)
182 {
183 sfree (tmp);
184 return (ENOMEM);
185 }
187 status = data_append (dst, tmp);
188 if (status != 0)
189 {
190 sfree (tmp->name);
191 sfree (tmp);
192 return (status);
193 }
195 return (0);
196 } /* }}} int data_copy */
198 /* Lookup a single mb_data_t instance, copy it and append the copy to another
199 * list. */
200 static int data_copy_by_name (mb_data_t **dst, mb_data_t *src, /* {{{ */
201 const char *name)
202 {
203 mb_data_t *ptr;
205 if ((dst == NULL) || (src == NULL) || (name == NULL))
206 return (EINVAL);
208 ptr = data_get_by_name (src, name);
209 if (ptr == NULL)
210 return (ENOENT);
212 return (data_copy (dst, ptr));
213 } /* }}} int data_copy_by_name */
215 /* Read functions */
217 static int mb_submit (mb_host_t *host, mb_slave_t *slave, /* {{{ */
218 mb_data_t *data, value_t value)
219 {
220 value_list_t vl = VALUE_LIST_INIT;
222 if ((host == NULL) || (slave == NULL) || (data == NULL))
223 return (EINVAL);
225 if (host->interval <= 0)
226 host->interval = interval_g;
228 if (slave->instance[0] == 0)
229 ssnprintf (slave->instance, sizeof (slave->instance), "slave_%i",
230 slave->id);
232 vl.values = &value;
233 vl.values_len = 1;
234 vl.interval = host->interval;
235 sstrncpy (vl.host, host->host, sizeof (vl.host));
236 sstrncpy (vl.plugin, "modbus", sizeof (vl.plugin));
237 sstrncpy (vl.plugin_instance, slave->instance, sizeof (vl.plugin_instance));
238 sstrncpy (vl.type, data->type, sizeof (vl.type));
239 sstrncpy (vl.type_instance, data->instance, sizeof (vl.type_instance));
241 return (plugin_dispatch_values (&vl));
242 } /* }}} int mb_submit */
244 static float mb_register_to_float (uint16_t hi, uint16_t lo) /* {{{ */
245 {
246 union
247 {
248 uint8_t b[4];
249 float f;
250 } conv;
252 #if BYTE_ORDER == LITTLE_ENDIAN
253 /* little endian */
254 conv.b[0] = lo & 0x00ff;
255 conv.b[1] = (lo >> 8) & 0x00ff;
256 conv.b[2] = hi & 0x00ff;
257 conv.b[3] = (hi >> 8) & 0x00ff;
258 #else
259 conv.b[3] = lo & 0x00ff;
260 conv.b[2] = (lo >> 8) & 0x00ff;
261 conv.b[1] = hi & 0x00ff;
262 conv.b[0] = (hi >> 8) & 0x00ff;
263 #endif
265 return (conv.f);
266 } /* }}} float mb_register_to_float */
268 static int mb_init_connection (mb_host_t *host) /* {{{ */
269 {
270 int status;
272 if (host == NULL)
273 return (EINVAL);
275 if (host->is_connected)
276 return (0);
278 /* Only reconnect once per interval. */
279 if (host->have_reconnected)
280 return (-1);
282 modbus_set_debug (&host->connection, 1);
284 /* We'll do the error handling ourselves. */
285 modbus_set_error_handling (&host->connection, NOP_ON_ERROR);
287 if ((host->port < 1) || (host->port > 65535))
288 host->port = MODBUS_TCP_DEFAULT_PORT;
290 DEBUG ("Modbus plugin: Trying to connect to \"%s\", port %i.",
291 host->node, host->port);
293 modbus_init_tcp (&host->connection,
294 /* host = */ host->node,
295 /* port = */ host->port);
297 status = modbus_connect (&host->connection);
298 if (status != 0)
299 {
300 ERROR ("Modbus plugin: modbus_connect (%s, %i) failed with status %i.",
301 host->node, host->port, status);
302 return (status);
303 }
305 host->is_connected = 1;
306 host->have_reconnected = 1;
307 return (0);
308 } /* }}} int mb_init_connection */
310 #define CAST_TO_VALUE_T(ds,vt,raw) do { \
311 if ((ds)->ds[0].type == DS_TYPE_COUNTER) \
312 (vt).counter = (counter_t) (raw); \
313 else if ((ds)->ds[0].type == DS_TYPE_GAUGE) \
314 (vt).gauge = (gauge_t) (raw); \
315 else if ((ds)->ds[0].type == DS_TYPE_DERIVE) \
316 (vt).derive = (derive_t) (raw); \
317 else /* if (ds->ds[0].type == DS_TYPE_ABSOLUTE) */ \
318 (vt).absolute = (absolute_t) (raw); \
319 } while (0)
321 static int mb_read_data (mb_host_t *host, mb_slave_t *slave, /* {{{ */
322 mb_data_t *data)
323 {
324 uint16_t values[2];
325 int values_num;
326 const data_set_t *ds;
327 int status;
328 int i;
330 if ((host == NULL) || (slave == NULL) || (data == NULL))
331 return (EINVAL);
333 ds = plugin_get_ds (data->type);
334 if (ds == NULL)
335 {
336 ERROR ("Modbus plugin: Type \"%s\" is not defined.", data->type);
337 return (-1);
338 }
340 if (ds->ds_num != 1)
341 {
342 ERROR ("Modbus plugin: The type \"%s\" has %i data sources. "
343 "I can only handle data sets with only one data source.",
344 data->type, ds->ds_num);
345 return (-1);
346 }
348 if ((ds->ds[0].type != DS_TYPE_GAUGE)
349 && (data->register_type != REG_TYPE_UINT32))
350 {
351 NOTICE ("Modbus plugin: The data source of type \"%s\" is %s, not gauge. "
352 "This will most likely result in problems, because the register type "
353 "is not UINT32.", data->type, DS_TYPE_TO_STRING (ds->ds[0].type));
354 }
356 memset (values, 0, sizeof (values));
357 if ((data->register_type == REG_TYPE_UINT32)
358 || (data->register_type == REG_TYPE_FLOAT))
359 values_num = 2;
360 else
361 values_num = 1;
363 for (i = 0; i < 2; i++)
364 {
365 status = read_holding_registers (&host->connection,
366 /* slave = */ slave->id, /* start_addr = */ data->register_base,
367 /* num_registers = */ values_num, /* buffer = */ values);
368 if (status > 0)
369 break;
371 if (host->is_connected)
372 modbus_close (&host->connection);
373 host->is_connected = 0;
375 /* If we already tried reconnecting this round, give up. */
376 if (host->have_reconnected)
377 {
378 ERROR ("Modbus plugin: read_holding_registers (%s) failed. "
379 "Reconnecting has already been tried. Giving up.", host->host);
380 return (-1);
381 }
383 /* Maybe the device closed the connection during the waiting interval.
384 * Try re-establishing the connection. */
385 status = mb_init_connection (host);
386 if (status != 0)
387 {
388 ERROR ("Modbus plugin: read_holding_registers (%s) failed. "
389 "While trying to reconnect, connecting to \"%s\" failed. "
390 "Giving up.",
391 host->host, host->node);
392 return (-1);
393 }
395 DEBUG ("Modbus plugin: Re-established connection to %s", host->host);
397 /* try again */
398 continue;
399 } /* for (i = 0, 1) */
401 DEBUG ("Modbus plugin: mb_read_data: Success! "
402 "read_holding_registers returned with status %i.", status);
404 if (data->register_type == REG_TYPE_FLOAT)
405 {
406 float float_value;
407 value_t vt;
409 float_value = mb_register_to_float (values[0], values[1]);
410 DEBUG ("Modbus plugin: mb_read_data: "
411 "Returned float value is %g", (double) float_value);
413 CAST_TO_VALUE_T (ds, vt, float_value);
414 mb_submit (host, slave, data, vt);
415 }
416 else if (data->register_type == REG_TYPE_UINT32)
417 {
418 uint32_t v32;
419 value_t vt;
421 v32 = (values[0] << 16) | values[1];
422 DEBUG ("Modbus plugin: mb_read_data: "
423 "Returned uint32 value is %"PRIu32, v32);
425 CAST_TO_VALUE_T (ds, vt, v32);
426 mb_submit (host, slave, data, vt);
427 }
428 else /* if (data->register_type == REG_TYPE_UINT16) */
429 {
430 value_t vt;
432 DEBUG ("Modbus plugin: mb_read_data: "
433 "Returned uint16 value is %"PRIu16, values[0]);
435 CAST_TO_VALUE_T (ds, vt, values[0]);
436 mb_submit (host, slave, data, vt);
437 }
439 return (0);
440 } /* }}} int mb_read_data */
442 static int mb_read_slave (mb_host_t *host, mb_slave_t *slave) /* {{{ */
443 {
444 mb_data_t *data;
445 int success;
446 int status;
448 if ((host == NULL) || (slave == NULL))
449 return (EINVAL);
451 success = 0;
452 for (data = slave->collect; data != NULL; data = data->next)
453 {
454 status = mb_read_data (host, slave, data);
455 if (status == 0)
456 success++;
457 }
459 if (success == 0)
460 return (-1);
461 else
462 return (0);
463 } /* }}} int mb_read_slave */
465 static int mb_read (user_data_t *user_data) /* {{{ */
466 {
467 mb_host_t *host;
468 size_t i;
469 int success;
470 int status;
472 if ((user_data == NULL) || (user_data->data == NULL))
473 return (EINVAL);
475 host = user_data->data;
477 /* Clear the reconnect flag. */
478 host->have_reconnected = 0;
480 success = 0;
481 for (i = 0; i < host->slaves_num; i++)
482 {
483 status = mb_read_slave (host, host->slaves + i);
484 if (status == 0)
485 success++;
486 }
488 if (success == 0)
489 return (-1);
490 else
491 return (0);
492 } /* }}} int mb_read */
494 /* Free functions */
496 static void data_free_one (mb_data_t *data) /* {{{ */
497 {
498 if (data == NULL)
499 return;
501 sfree (data->name);
502 sfree (data);
503 } /* }}} void data_free_one */
505 static void data_free_all (mb_data_t *data) /* {{{ */
506 {
507 mb_data_t *next;
509 if (data == NULL)
510 return;
512 next = data->next;
513 data_free_one (data);
515 data_free_all (next);
516 } /* }}} void data_free_all */
518 static void slaves_free_all (mb_slave_t *slaves, size_t slaves_num) /* {{{ */
519 {
520 size_t i;
522 if (slaves == NULL)
523 return;
525 for (i = 0; i < slaves_num; i++)
526 data_free_all (slaves[i].collect);
527 sfree (slaves);
528 } /* }}} void slaves_free_all */
530 static void host_free (void *void_host) /* {{{ */
531 {
532 mb_host_t *host = void_host;
534 if (host == NULL)
535 return;
537 slaves_free_all (host->slaves, host->slaves_num);
538 sfree (host);
539 } /* }}} void host_free */
541 /* Config functions */
543 static int mb_config_add_data (oconfig_item_t *ci) /* {{{ */
544 {
545 mb_data_t data;
546 int status;
547 int i;
549 memset (&data, 0, sizeof (data));
550 data.name = NULL;
551 data.register_type = REG_TYPE_UINT16;
552 data.next = NULL;
554 status = cf_util_get_string (ci, &data.name);
555 if (status != 0)
556 return (status);
558 for (i = 0; i < ci->children_num; i++)
559 {
560 oconfig_item_t *child = ci->children + i;
561 status = 0;
563 if (strcasecmp ("Type", child->key) == 0)
564 status = cf_util_get_string_buffer (child,
565 data.type, sizeof (data.type));
566 else if (strcasecmp ("Instance", child->key) == 0)
567 status = cf_util_get_string_buffer (child,
568 data.instance, sizeof (data.instance));
569 else if (strcasecmp ("RegisterBase", child->key) == 0)
570 status = cf_util_get_int (child, &data.register_base);
571 else if (strcasecmp ("RegisterType", child->key) == 0)
572 {
573 char tmp[16];
574 status = cf_util_get_string_buffer (child, tmp, sizeof (tmp));
575 if (status != 0)
576 /* do nothing */;
577 else if (strcasecmp ("Uint16", tmp) == 0)
578 data.register_type = REG_TYPE_UINT16;
579 else if (strcasecmp ("Uint32", tmp) == 0)
580 data.register_type = REG_TYPE_UINT32;
581 else if (strcasecmp ("Float", tmp) == 0)
582 data.register_type = REG_TYPE_FLOAT;
583 else
584 {
585 ERROR ("Modbus plugin: The register type \"%s\" is unknown.", tmp);
586 status = -1;
587 }
588 }
589 else
590 {
591 ERROR ("Modbus plugin: Unknown configuration option: %s", child->key);
592 status = -1;
593 }
595 if (status != 0)
596 break;
597 } /* for (i = 0; i < ci->children_num; i++) */
599 assert (data.name != NULL);
600 if (data.type[0] == 0)
601 {
602 ERROR ("Modbus plugin: Data block \"%s\": No type has been specified.",
603 data.name);
604 status = -1;
605 }
607 if (status == 0)
608 data_copy (&data_definitions, &data);
610 sfree (data.name);
612 return (status);
613 } /* }}} int mb_config_add_data */
615 static int mb_config_set_host_address (mb_host_t *host, /* {{{ */
616 const char *address)
617 {
618 struct addrinfo *ai_list;
619 struct addrinfo *ai_ptr;
620 struct addrinfo ai_hints;
621 int status;
623 if ((host == NULL) || (address == NULL))
624 return (EINVAL);
626 memset (&ai_hints, 0, sizeof (ai_hints));
627 #if AI_ADDRCONFIG
628 ai_hints.ai_flags |= AI_ADDRCONFIG;
629 #endif
630 /* XXX: libmodbus can only handle IPv4 addresses. */
631 ai_hints.ai_family = AF_INET;
632 ai_hints.ai_addr = NULL;
633 ai_hints.ai_canonname = NULL;
634 ai_hints.ai_next = NULL;
636 ai_list = NULL;
637 status = getaddrinfo (address, /* service = */ NULL,
638 &ai_hints, &ai_list);
639 if (status != 0)
640 {
641 char errbuf[1024];
642 ERROR ("Modbus plugin: getaddrinfo failed: %s",
643 (status == EAI_SYSTEM)
644 ? sstrerror (errno, errbuf, sizeof (errbuf))
645 : gai_strerror (status));
646 return (status);
647 }
649 for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
650 {
651 status = getnameinfo (ai_ptr->ai_addr, ai_ptr->ai_addrlen,
652 host->node, sizeof (host->node),
653 /* service = */ NULL, /* length = */ 0,
654 /* flags = */ NI_NUMERICHOST);
655 if (status == 0)
656 break;
657 } /* for (ai_ptr) */
659 freeaddrinfo (ai_list);
661 if (status != 0)
662 ERROR ("Modbus plugin: Unable to translate node name: \"%s\"", address);
663 else /* if (status == 0) */
664 {
665 DEBUG ("Modbus plugin: mb_config_set_host_address: %s -> %s",
666 address, host->node);
667 }
669 return (status);
670 } /* }}} int mb_config_set_host_address */
672 static int mb_config_add_slave (mb_host_t *host, oconfig_item_t *ci) /* {{{ */
673 {
674 mb_slave_t *slave;
675 int status;
676 int i;
678 if ((host == NULL) || (ci == NULL))
679 return (EINVAL);
681 slave = realloc (host->slaves, sizeof (*slave) * (host->slaves_num + 1));
682 if (slave == NULL)
683 return (ENOMEM);
684 host->slaves = slave;
685 slave = host->slaves + host->slaves_num;
686 memset (slave, 0, sizeof (*slave));
687 slave->collect = NULL;
689 status = cf_util_get_int (ci, &slave->id);
690 if (status != 0)
691 return (status);
693 for (i = 0; i < ci->children_num; i++)
694 {
695 oconfig_item_t *child = ci->children + i;
696 status = 0;
698 if (strcasecmp ("Instance", child->key) == 0)
699 status = cf_util_get_string_buffer (child,
700 slave->instance, sizeof (slave->instance));
701 else if (strcasecmp ("Collect", child->key) == 0)
702 {
703 char buffer[1024];
704 status = cf_util_get_string_buffer (child, buffer, sizeof (buffer));
705 if (status == 0)
706 data_copy_by_name (&slave->collect, data_definitions, buffer);
707 status = 0; /* continue after failure. */
708 }
709 else
710 {
711 ERROR ("Modbus plugin: Unknown configuration option: %s", child->key);
712 status = -1;
713 }
715 if (status != 0)
716 break;
717 }
719 if ((status == 0) && (slave->collect == NULL))
720 status = EINVAL;
722 if (slave->id < 0)
723 status = EINVAL;
725 if (status == 0)
726 host->slaves_num++;
727 else /* if (status != 0) */
728 data_free_all (slave->collect);
730 return (status);
731 } /* }}} int mb_config_add_slave */
733 static int mb_config_add_host (oconfig_item_t *ci) /* {{{ */
734 {
735 mb_host_t *host;
736 int status;
737 int i;
739 host = malloc (sizeof (*host));
740 if (host == NULL)
741 return (ENOMEM);
742 memset (host, 0, sizeof (*host));
743 host->slaves = NULL;
745 status = cf_util_get_string_buffer (ci, host->host, sizeof (host->host));
746 if (status != 0)
747 return (status);
748 if (host->host[0] == 0)
749 return (EINVAL);
751 for (i = 0; i < ci->children_num; i++)
752 {
753 oconfig_item_t *child = ci->children + i;
754 status = 0;
756 if (strcasecmp ("Address", child->key) == 0)
757 {
758 char buffer[NI_MAXHOST];
759 status = cf_util_get_string_buffer (child, buffer, sizeof (buffer));
760 if (status == 0)
761 status = mb_config_set_host_address (host, buffer);
762 }
763 else if (strcasecmp ("Port", child->key) == 0)
764 {
765 host->port = cf_util_get_port_number (child);
766 if (host->port <= 0)
767 status = -1;
768 }
769 else if (strcasecmp ("Interval", child->key) == 0)
770 status = cf_util_get_int (child, &host->interval);
771 else if (strcasecmp ("Slave", child->key) == 0)
772 /* Don't set status: Gracefully continue if a slave fails. */
773 mb_config_add_slave (host, child);
774 else
775 {
776 ERROR ("Modbus plugin: Unknown configuration option: %s", child->key);
777 status = -1;
778 }
780 if (status != 0)
781 break;
782 } /* for (i = 0; i < ci->children_num; i++) */
784 assert (host->host[0] != 0);
785 if (host->host[0] == 0)
786 {
787 ERROR ("Modbus plugin: Data block \"%s\": No type has been specified.",
788 host->host);
789 status = -1;
790 }
792 if (status == 0)
793 {
794 user_data_t ud;
795 char name[1024];
796 struct timespec interval;
798 ud.data = host;
799 ud.free_func = host_free;
801 ssnprintf (name, sizeof (name), "modbus-%s", host->host);
803 interval.tv_nsec = 0;
804 if (host->interval > 0)
805 interval.tv_sec = host->interval;
806 else
807 interval.tv_sec = 0;
809 plugin_register_complex_read (/* group = */ NULL, name,
810 mb_read, (interval.tv_sec > 0) ? &interval : NULL, &ud);
811 }
812 else
813 {
814 host_free (host);
815 }
817 return (status);
818 } /* }}} int mb_config_add_host */
820 static int mb_config (oconfig_item_t *ci) /* {{{ */
821 {
822 int i;
824 if (ci == NULL)
825 return (EINVAL);
827 for (i = 0; i < ci->children_num; i++)
828 {
829 oconfig_item_t *child = ci->children + i;
831 if (strcasecmp ("Data", child->key) == 0)
832 mb_config_add_data (child);
833 else if (strcasecmp ("Host", child->key) == 0)
834 mb_config_add_host (child);
835 else
836 ERROR ("Modbus plugin: Unknown configuration option: %s", child->key);
837 }
839 return (0);
840 } /* }}} int mb_config */
842 /* ========= */
844 static int mb_shutdown (void) /* {{{ */
845 {
846 data_free_all (data_definitions);
847 data_definitions = NULL;
849 return (0);
850 } /* }}} int mb_shutdown */
852 void module_register (void)
853 {
854 plugin_register_complex_config ("modbus", mb_config);
855 plugin_register_shutdown ("modbus", mb_shutdown);
856 } /* void module_register */
858 /* vim: set sw=2 sts=2 et fdm=marker : */