diff options
Diffstat (limited to '')
-rw-r--r-- | modbuslog.c | 61 |
1 files changed, 54 insertions, 7 deletions
diff --git a/modbuslog.c b/modbuslog.c index 0649215..ec0acc4 100644 --- a/modbuslog.c +++ b/modbuslog.c @@ -24,6 +24,10 @@ #include <unistd.h> #include <stdlib.h> #include <errno.h> +#include <time.h> +#include <unistd.h> +#include <sys/select.h> +#include <signal.h> #include <libconfig.h> #include <modbus.h> @@ -33,10 +37,18 @@ #define NUMBER_REGISTERS 14 #define DEBUG 1 +void minute_check(int signum){ + alarm(60); +} + + + + + int main(int argc, char *argv[]) { -const char *CONFIG_FILE = "modbuslog.cfg"; + const char *CONFIG_FILE = "modbuslog.cfg"; config_t cfg; //config_setting_t *setting; @@ -59,18 +71,13 @@ const char *CONFIG_FILE = "modbuslog.cfg"; return -1; } - modbus_t *ctx; - uint16_t tab_reg[64]; - int rc; - int i; - if(!(config_lookup_string(&cfg, "modbus.device", &modbus_device_address) && config_lookup_int(&cfg, "modbus.baud", &modbus_baud_rate) && config_lookup_int(&cfg, "modbus.data_bits", &modbus_data_bits) && config_lookup_string(&cfg, "modbus.parity", &modbus_parity) && config_lookup_int(&cfg, "modbus.stop_bits", &modbus_stop_bits)) ){ - fprintf(stderr, "Check modbus configuration in configuration file.\n"); + fprintf(stderr, "Incomplete modbus configuration. Check configuration file.\n"); return -1; } @@ -78,6 +85,44 @@ const char *CONFIG_FILE = "modbuslog.cfg"; printf("%s %d %c %d %d\n",modbus_device_address, modbus_baud_rate, modbus_parity[0], modbus_data_bits, modbus_stop_bits); } + + modbus_t *ctx; + uint16_t tab_reg[64]; + int rc; + int i; + + + signal(SIGALRM, minute_check); + alarm(60); + + for (;;){ + select(0, NULL, NULL, NULL, NULL); + + time_t t = time(NULL); + //int unixtime_min = (((int) t)/60*60); + int unixtime = (int) t; + printf("%d\n", unixtime); + + config_setting_t *registers; + + registers = config_lookup(&cfg, "register"); + + unsigned int num_registers = config_setting_length(registers); + + int i; + for(i = 0; i < num_registers; ++i){ + config_setting_t *register_element = config_setting_get_elem(registers, i); + int slaveid; + config_setting_lookup_int(register_element, "slaveid", &slaveid); + printf("%d ", slaveid); + } + printf("\n"); + } +} + + +/* + ctx = modbus_new_rtu(modbus_device_address, modbus_baud_rate, modbus_parity[0], modbus_data_bits, modbus_stop_bits); modbus_set_slave(ctx, SLAVE_ID); @@ -114,3 +159,5 @@ modbus_free(ctx); return 0; } + +*/ |