aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--modbuslog.c57
1 files changed, 39 insertions, 18 deletions
diff --git a/modbuslog.c b/modbuslog.c
index db40244..248b8cc 100644
--- a/modbuslog.c
+++ b/modbuslog.c
@@ -18,6 +18,7 @@
*/
// gcc modbuslog.c -o modbuslog `pkg-config --libs --cflags libmodbus libconfig`
+
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
@@ -148,6 +149,10 @@ int main(int argc, char *argv[]) {
&intervalvalue);
//printf("%d", intervalvalue);
+ int registertype;
+ config_setting_lookup_int(register_element, "registertype",
+ &registertype);
+
int startaddress;
config_setting_lookup_int(register_element, "startaddress",
&startaddress);
@@ -191,15 +196,30 @@ int main(int argc, char *argv[]) {
//return -1;
}
- rc = modbus_read_input_registers(ctx, startaddress,
- numregisters, tab_reg);
-
- if (rc == -1) {
- fprintf(stderr, "ERROR: %s\n", modbus_strerror(errno));
- //return -1;
- rc = modbus_read_input_registers(ctx, startaddress,
- numregisters, tab_reg);
- }
+ int retry = 0;
+ do {
+ switch (registertype) {
+
+ case 3:
+ rc = modbus_read_registers(ctx, startaddress,
+ numregisters, tab_reg);
+ break;
+
+ case 4:
+ rc = modbus_read_input_registers(ctx, startaddress,
+ numregisters, tab_reg);
+ break;
+
+ default:
+ rc = modbus_read_registers(ctx, startaddress,
+ numregisters, tab_reg);
+ break;
+ }
+ if (rc == -1) {
+ fprintf(stderr, "ERROR: %s\n", modbus_strerror(errno));
+ }
+ retry++;
+ } while ((rc != -1) && (retry < 2));
//MODBUS_GET_HIGH_BYTE(data);
//MODBUS_GET_LOW_BYTE(data);
@@ -212,7 +232,8 @@ int main(int argc, char *argv[]) {
char filename[50];
- sprintf(filename, "/var/modbuslog/%s_%04i_%02i_%02i_%02i_%02i_%02i.log",
+ sprintf(filename,
+ "/var/modbuslog/%s_%04i_%02i_%02i_%02i_%02i_%02i.log",
mac_address(), midnight.tm_year + 1900,
midnight.tm_mon + 1, midnight.tm_mday, midnight.tm_hour,
midnight.tm_min, midnight.tm_sec);
@@ -260,22 +281,22 @@ int main(int argc, char *argv[]) {
struct tm utc = *gmtime(&unixtime_min);
struct tm lc = *localtime(&unixtime_min);
-
int intervalid;
- FILE *intervalfile = fopen("/var/modbuslog/interval.txt", "w+");
+ FILE *intervalfile = fopen("/var/modbuslog/interval.txt", "r+");
fscanf(intervalfile, "%d", &intervalid);
intervalid++;
+ rewind(intervalfile);
fprintf(intervalfile, "%d", intervalid);
fclose(intervalfile);
-
-
+
fprintf(
filehandle,
"%i|%04i%02i%02i|%02i%02i%02i|%04i%02i%02i|%02i%02i%02i|%i|%i|%i\n",
- intervalid,utc.tm_year + 1900, utc.tm_mon + 1, utc.tm_mday,
- utc.tm_hour, utc.tm_min, utc.tm_sec, lc.tm_year + 1900,
- lc.tm_mon + 1, lc.tm_mday, lc.tm_hour, lc.tm_min,
- lc.tm_sec, slaveid, startaddress, registervalue);
+ intervalid, utc.tm_year + 1900, utc.tm_mon + 1,
+ utc.tm_mday, utc.tm_hour, utc.tm_min, utc.tm_sec,
+ lc.tm_year + 1900, lc.tm_mon + 1, lc.tm_mday,
+ lc.tm_hour, lc.tm_min, lc.tm_sec, slaveid, startaddress,
+ registervalue);
fclose(filehandle);
modbus_close(ctx);
843b832f4c299b855f42de2a5a6b2248f0f71&follow=1'>d/control: update Standards Version to 3.9.6Jonathan McCrohan2-1/+3 2014-10-15d/control: add Build-Depends on dvb-toolsJonathan McCrohan2-1/+2 2014-10-15New Upstream Snapshot (commit d26b627)Jonathan McCrohan1-0/+10 2014-10-15Imported Upstream version 0+git20141009.d26b627upstream/0+git20141009.d26b627Jonathan McCrohan2010-11120/+159271 2014-07-23Release 0+git20140611.14bd6c7-1debian/0+git20140611.14bd6c7-1Jonathan McCrohan1-2/+2 2014-07-23New Upstream Snapshot (commit 14bd6c7)Jonathan McCrohan1-2/+3 2014-07-23Imported Upstream version 0+git20140611.14bd6c7upstream/0+git20140611.14bd6c7Jonathan McCrohan7-11/+60 2014-05-13New Upstream Snapshot (commit 1246b27)Jonathan McCrohan1-0/+6 2014-05-13Imported Upstream version 0+git20140512.1246b27upstream/0+git20140512.1246b27Jonathan McCrohan391-301/+3983 2014-04-05Release 0+git20140326.cfc2975-1debian/0+git20140326.cfc2975-1Jonathan McCrohan1-2/+2 2014-04-05d/control: update Homepage (upstream has moved from Gitweb to cgit)Jonathan McCrohan2-1/+2 2014-04-05New Upstream Snapshot (commit cfc2975)Jonathan McCrohan1-0/+6 2014-04-05Imported Upstream version 0+git20140326.cfc2975upstream/0+git20140326.cfc2975Jonathan McCrohan118-656/+877 2014-01-16Release 0+git20140107.1850cf8-1debian/0+git20140107.1850cf8-1Jonathan McCrohan1-2/+2 2014-01-16Update Standards Version to 3.9.5Jonathan McCrohan2-1/+9