aboutsummaryrefslogtreecommitdiffstats
path: root/src/modbuslog.c
diff options
context:
space:
mode:
authorJonathan McCrohan <jmccrohan@gmail.com>2012-03-26 00:16:59 +0100
committerJonathan McCrohan <jmccrohan@gmail.com>2012-03-26 00:16:59 +0100
commit67b3bfe5cf9b13820c934687d8930aa51c2dd902 (patch)
treedf7afe4557683d5d631f57e777b1f6d4d6403d63 /src/modbuslog.c
parent9c16df0e5201b4e36cbfaab00d23534d0d9148f9 (diff)
downloadverteco-67b3bfe5cf9b13820c934687d8930aa51c2dd902.tar.gz
modbuslog: ensure no logs recorded if libmodbus errors
Diffstat (limited to '')
-rw-r--r--src/modbuslog.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/modbuslog.c b/src/modbuslog.c
index 112f9c8..46a1516 100644
--- a/src/modbuslog.c
+++ b/src/modbuslog.c
@@ -268,7 +268,12 @@ int main(int argc, char *argv[]) {
modbus_strerror(errno));
}
retry++;
- } while ((rc != -1) && (retry < (modbus_retry + 1)));
+ } while ((rc == -1) && (retry < (modbus_retry + 1)));
+
+ if (rc == -1){
+ // retried, but still no luck
+ continue;
+ }
//MODBUS_GET_HIGH_BYTE(data);
//MODBUS_GET_LOW_BYTE(data);
@@ -325,15 +330,11 @@ int main(int argc, char *argv[]) {
// bitshifting magic
switch (numbytes) {
case 1:
- registervalue = byte[0];
+ registervalue = (startbyte % 2 == 0) ? byte[0] : byte[1];
break;
case 2:
registervalue = ((byte[0]) << 8) + byte[1];
break;
- case 3:
- registervalue = ((byte[0]) << 16) + ((byte[1]) << 8)
- + byte[2];
- break;
case 4:
registervalue = ((byte[0]) << 24) + ((byte[1]) << 16)
+ ((byte[2]) << 8) + byte[3];