diff --git a/bin/mbus-serial-request-data.c b/bin/mbus-serial-request-data.c
index 46526a7..b6a9834 100755
--- a/bin/mbus-serial-request-data.c
+++ b/bin/mbus-serial-request-data.c
@@ -132,7 +132,7 @@ main(int argc, char **argv)
}
}
- if (mbus_recv_frame(handle, &reply) != 0)
+ if (mbus_recv_frame(handle, &reply) != MBUS_RECV_RESULT_OK)
{
fprintf(stderr, "Failed to receive M-Bus response frame.\n");
return 1;
diff --git a/bin/mbus-serial-scan.c b/bin/mbus-serial-scan.c
index 1d2d0f8..a2c14c9 100755
--- a/bin/mbus-serial-scan.c
+++ b/bin/mbus-serial-scan.c
@@ -103,7 +103,7 @@ main(int argc, char **argv)
ret = mbus_recv_frame(handle, &reply);
- if (ret == -3)
+ if (ret == MBUS_RECV_RESULT_TIMEOUT)
{
continue;
}
@@ -111,7 +111,7 @@ main(int argc, char **argv)
if (debug)
printf("\n");
- if (ret == -2)
+ if (ret == MBUS_RECV_RESULT_INVALID)
{
/* check for more data (collision) */
mbus_purge_frames(handle);
diff --git a/bin/mbus-serial-select-secondary.c b/bin/mbus-serial-select-secondary.c
index 624a384..66b4d4b 100755
--- a/bin/mbus-serial-select-secondary.c
+++ b/bin/mbus-serial-select-secondary.c
@@ -79,13 +79,13 @@ main(int argc, char **argv)
ret = mbus_recv_frame(handle, &reply);
- if (ret == -3)
+ if (ret == MBUS_RECV_RESULT_TIMEOUT)
{
printf("No reply from device with secondary address %s: %s\n", argv[2], mbus_error_str());
return 1;
}
- if (ret == -2)
+ if (ret == MBUS_RECV_RESULT_INVALID)
{
printf("Invalid reply from %s: The address address probably match more than one device: %s\n", argv[2], mbus_error_str());
return 1;
@@ -99,7 +99,7 @@ main(int argc, char **argv)
return 1;
}
- if (mbus_recv_frame(handle, &reply) != 0)
+ if (mbus_recv_frame(handle, &reply) != MBUS_RECV_RESULT_OK)
{
printf("Failed to recieve reply from selected secondary device: %s\n", mbus_error_str());
return 1;
diff --git a/bin/mbus-serial-switch-baudrate.c b/bin/mbus-serial-switch-baudrate.c
index e67b98c..49cc969 100755
--- a/bin/mbus-serial-switch-baudrate.c
+++ b/bin/mbus-serial-switch-baudrate.c
@@ -78,7 +78,7 @@ main(int argc, char **argv)
ret = mbus_recv_frame(handle, &reply);
- if (ret == -3)
+ if (ret == MBUS_RECV_RESULT_TIMEOUT)
{
printf("No reply from device\n");
return 1;
diff --git a/bin/mbus-tcp-request-data.c b/bin/mbus-tcp-request-data.c
index 1ed504f..2e23c5d 100755
--- a/bin/mbus-tcp-request-data.c
+++ b/bin/mbus-tcp-request-data.c
@@ -117,7 +117,7 @@ main(int argc, char **argv)
}
}
- if (mbus_recv_frame(handle, &reply) != 0)
+ if (mbus_recv_frame(handle, &reply) != MBUS_RECV_RESULT_OK)
{
fprintf(stderr, "Failed to receive M-Bus response frame: %s\n", mbus_error_str());
return 1;
diff --git a/bin/mbus-tcp-scan.c b/bin/mbus-tcp-scan.c
index 2776018..10d4165 100755
--- a/bin/mbus-tcp-scan.c
+++ b/bin/mbus-tcp-scan.c
@@ -86,7 +86,7 @@ main(int argc, char **argv)
ret = mbus_recv_frame(handle, &reply);
- if (ret == -3)
+ if (ret == MBUS_RECV_RESULT_TIMEOUT)
{
continue;
}
@@ -94,7 +94,7 @@ main(int argc, char **argv)
if (debug)
printf("\n");
- if (ret == -2)
+ if (ret == MBUS_RECV_RESULT_INVALID)
{
/* check for more data (collision) */
mbus_purge_frames(handle);
diff --git a/bin/mbus-tcp-select-secondary.c b/bin/mbus-tcp-select-secondary.c
index 5268650..5795d83 100755
--- a/bin/mbus-tcp-select-secondary.c
+++ b/bin/mbus-tcp-select-secondary.c
@@ -65,13 +65,13 @@ main(int argc, char **argv)
ret = mbus_recv_frame(handle, &reply);
- if (ret == -3)
+ if (ret == MBUS_RECV_RESULT_TIMEOUT)
{
printf("No reply from device with secondary address %s: %s\n", argv[3], mbus_error_str());
return 1;
}
- if (ret == -2)
+ if (ret == MBUS_RECV_RESULT_INVALID)
{
printf("Invalid reply from %s: The address address probably match more than one device: %s\n", argv[3], mbus_error_str());
return 1;
@@ -85,7 +85,7 @@ main(int argc, char **argv)
return 1;
}
- if (mbus_recv_frame(handle, &reply) != 0)
+ if (mbus_recv_frame(handle, &reply) != MBUS_RECV_RESULT_OK)
{
printf("Failed to recieve reply from selected secondary device: %s\n", mbus_error_str());
return 1;
diff --git a/mbus/mbus-protocol-aux.c b/mbus/mbus-protocol-aux.c
index cb11257..f7f9dc9 100755
--- a/mbus/mbus-protocol-aux.c
+++ b/mbus/mbus-protocol-aux.c
@@ -1434,13 +1434,13 @@ mbus_recv_frame(mbus_handle * handle, mbus_frame *frame)
if (handle == NULL)
{
MBUS_ERROR("%s: Invalid M-Bus handle for receive.\n", __PRETTY_FUNCTION__);
- return -1;
+ return MBUS_RECV_RESULT_ERROR;
}
if (frame == NULL)
{
MBUS_ERROR("%s: Invalid frame.\n", __PRETTY_FUNCTION__);
- return -1;
+ return MBUS_RECV_RESULT_ERROR;
}
result = handle->recv(handle, frame);
@@ -1463,7 +1463,8 @@ int mbus_purge_frames(mbus_handle *handle)
while (1)
{
err = mbus_recv_frame(handle, &reply);
- if (err != -2 && err != 0)
+ if (err != MBUS_RECV_RESULT_OK &&
+ err != MBUS_RECV_RESULT_INVALID)
break;
received = 1;
@@ -1660,7 +1661,7 @@ mbus_sendrecv_request(mbus_handle *handle, int address, mbus_frame *reply, int m
if (debug)
printf("%s: debug: receiving response frame #%d\n", __PRETTY_FUNCTION__, frame_count);
- if (mbus_recv_frame(handle, next_frame) != 0)
+ if (mbus_recv_frame(handle, next_frame) != MBUS_RECV_RESULT_OK)
{
MBUS_ERROR("%s: Failed to receive M-Bus response frame.\n", __PRETTY_FUNCTION__);
retval = 1;
@@ -1802,12 +1803,12 @@ mbus_select_secondary_address(mbus_handle * handle, const char *mask)
ret = mbus_recv_frame(handle, &reply);
- if (ret == -3)
+ if (ret == MBUS_RECV_RESULT_TIMEOUT)
{
return MBUS_PROBE_NOTHING;
}
- if (ret == -2)
+ if (ret == MBUS_RECV_RESULT_INVALID)
{
/* check for more data (collision) */
mbus_purge_frames(handle);
@@ -1862,12 +1863,12 @@ mbus_probe_secondary_address(mbus_handle * handle, const char *mask, char *match
ret = mbus_recv_frame(handle, &reply);
- if (ret == -3)
+ if (ret == MBUS_RECV_RESULT_TIMEOUT)
{
return MBUS_PROBE_NOTHING;
}
- if (ret == -2)
+ if (ret == MBUS_RECV_RESULT_INVALID)
{
return MBUS_PROBE_COLLISION;
}
diff --git a/mbus/mbus-protocol.h b/mbus/mbus-protocol.h
index 5fa5298..6742100 100755
--- a/mbus/mbus-protocol.h
+++ b/mbus/mbus-protocol.h
@@ -106,6 +106,15 @@ typedef struct _mbus_slave_data {
#define MBUS_HANDLE_TYPE_TCP 0
#define MBUS_HANDLE_TYPE_SERIAL 1
+//
+// Resultcodes for mbus_recv_frame
+//
+#define MBUS_RECV_RESULT_OK 0
+#define MBUS_RECV_RESULT_ERROR -1
+#define MBUS_RECV_RESULT_INVALID -2
+#define MBUS_RECV_RESULT_TIMEOUT -3
+#define MBUS_RECV_RESULT_RESET -4
+
//------------------------------------------------------------------------------
// MBUS FRAME DATA FORMATS
//
diff --git a/mbus/mbus-serial.c b/mbus/mbus-serial.c
index d28e7eb..5880e27 100755
--- a/mbus/mbus-serial.c
+++ b/mbus/mbus-serial.c
@@ -245,7 +245,7 @@ mbus_serial_recv_frame(mbus_handle *handle, mbus_frame *frame)
if (handle == NULL || frame == NULL)
{
fprintf(stderr, "%s: Invalid parameter.\n", __PRETTY_FUNCTION__);
- return -1;
+ return MBUS_RECV_RESULT_ERROR;
}
memset((void *)buff, 0, sizeof(buff));
@@ -264,7 +264,7 @@ mbus_serial_recv_frame(mbus_handle *handle, mbus_frame *frame)
{
// fprintf(stderr, "%s: aborting recv frame (remaining = %d, len = %d, nread = %d)\n",
// __PRETTY_FUNCTION__, remaining, len, nread);
- return -1;
+ return MBUS_RECV_RESULT_ERROR;
}
// printf("%s: Got %d byte [remaining %d, len %d]\n", __PRETTY_FUNCTION__, nread, remaining, len);
@@ -288,7 +288,7 @@ mbus_serial_recv_frame(mbus_handle *handle, mbus_frame *frame)
if (len == 0)
{
// No data received
- return -1;
+ return MBUS_RECV_RESULT_TIMEOUT;
}
//
@@ -301,16 +301,16 @@ mbus_serial_recv_frame(mbus_handle *handle, mbus_frame *frame)
{
// Would be OK when e.g. scanning the bus, otherwise it is a failure.
// printf("%s: M-Bus layer failed to receive complete data.\n", __PRETTY_FUNCTION__);
- return -2;
+ return MBUS_RECV_RESULT_INVALID;
}
if (len == -1)
{
fprintf(stderr, "%s: M-Bus layer failed to parse data.\n", __PRETTY_FUNCTION__);
- return -1;
+ return MBUS_RECV_RESULT_ERROR;
}
- return 0;
+ return MBUS_RECV_RESULT_OK;
}
diff --git a/mbus/mbus-tcp.c b/mbus/mbus-tcp.c
index f81a1cd..5dde42b 100755
--- a/mbus/mbus-tcp.c
+++ b/mbus/mbus-tcp.c
@@ -169,7 +169,7 @@ int mbus_tcp_recv_frame(mbus_handle *handle, mbus_frame *frame)
if (handle == NULL || frame == NULL) {
fprintf(stderr, "%s: Invalid parameter.\n", __PRETTY_FUNCTION__);
- return -1;
+ return MBUS_RECV_RESULT_ERROR;
}
memset((void *) buff, 0, sizeof(buff));
@@ -190,14 +190,14 @@ retry:
if (errno == EAGAIN || errno == EWOULDBLOCK) {
mbus_error_str_set("M-Bus tcp transport layer response timeout has been reached.");
- return -3;
+ return MBUS_RECV_RESULT_TIMEOUT;
}
mbus_error_str_set("M-Bus tcp transport layer failed to read data.");
- return -1;
+ return MBUS_RECV_RESULT_ERROR;
case 0:
mbus_error_str_set("M-Bus tcp transport layer connection closed by remote host.");
- return -4;
+ return MBUS_RECV_RESULT_RESET;
default:
len += nread;
}
@@ -211,10 +211,10 @@ retry:
if (remaining < 0) {
mbus_error_str_set("M-Bus layer failed to parse data.");
- return -2;
+ return MBUS_RECV_RESULT_INVALID;
}
- return 0;
+ return MBUS_RECV_RESULT_OK;
}
diff --git a/test/test-frames/abb_f95.hex b/test/test-frames/abb_f95.hex
new file mode 100644
index 0000000..7fd8852
--- /dev/null
+++ b/test/test-frames/abb_f95.hex
@@ -0,0 +1 @@
+68 5E 5E 68 08 00 72 90 85 71 26 24 23 28 04 73 50 00 00 0C 05 00 00 00 00 0C 12 42 07 00 00 3C 2A DD B4 EB DD 3B 3A DD B4 EB 0A 5A 04 02 0A 5E 04 02 0A 62 00 00 04 6D 22 10 8D 11 4C 05 00 00 00 00 44 6D 3B 17 7E 14 44 ED 7E 3B 17 9E 14 8C 01 05 00 00 00 00 84 01 6D 3B 17 7F 1C 0B 26 53 65 08 04 16
diff --git a/test/test-frames/abb_f95.xml b/test/test-frames/abb_f95.xml
new file mode 100644
index 0000000..1545820
--- /dev/null
+++ b/test/test-frames/abb_f95.xml
@@ -0,0 +1,97 @@
+
+
+
+ 26718590
+ HYD
+ 40
+ Heat: Outlet
+ 115
+ 50
+ 0000
+
+
+
+ Instantaneous value
+ Energy (100 Wh)
+ 0
+
+
+
+ Instantaneous value
+ Volume (1e-4 m^3)
+ 742
+
+
+
+ Value during error state
+ Power (1e-1 W)
+ 144521543
+
+
+
+ Value during error state
+ Volume flow (1e-4 m^3/h)
+ 1521543
+
+
+
+ Instantaneous value
+ Flow temperature (1e-1 deg C)
+ 204
+
+
+
+ Instantaneous value
+ Return temperature (1e-1 deg C)
+ 204
+
+
+
+ Instantaneous value
+ Temperature Difference (1e-1 deg C)
+ 0
+
+
+
+ Instantaneous value
+ Time Point (time & date)
+ 2012-01-13T16:34:00
+
+
+
+ Instantaneous value
+ Energy (100 Wh)
+ 0
+
+
+
+ Instantaneous value
+ Time Point (time & date)
+ 2011-04-30T23:59:00
+
+
+
+ Instantaneous value
+ Time Point (time & date)
+ 2012-04-30T23:59:00
+
+
+
+ Instantaneous value
+ Energy (100 Wh)
+ 0
+
+
+
+ Instantaneous value
+ Time Point (time & date)
+ 2011-12-31T23:59:00
+
+
+
+ Instantaneous value
+ Operating time (hours)
+ 86553
+
+
+
diff --git a/test/test-frames/allmess_cf50.hex b/test/test-frames/allmess_cf50.hex
new file mode 100644
index 0000000..0eacd31
--- /dev/null
+++ b/test/test-frames/allmess_cf50.hex
@@ -0,0 +1,2 @@
+68 3D 3D 68 08 01 72 00 51 20 02 82 4D 02 04 00 88 00 00 04 07 00 00 00 00 0C 15 03 00 00 00 0B 2E 00 00 00 0B 3B 00 00 00 0A 5A 88 12 0A 5E 16 05 0B 61 23 77 00 02 6C 8C 11 02 27 37 0D 0F 60 00 67 16
+
diff --git a/test/test-frames/allmess_cf50.xml b/test/test-frames/allmess_cf50.xml
new file mode 100644
index 0000000..c2cb03a
--- /dev/null
+++ b/test/test-frames/allmess_cf50.xml
@@ -0,0 +1,72 @@
+
+
+
+ 2205100
+ SLB
+ 2
+ Heat: Outlet
+ 0
+ 88
+ 0000
+
+
+
+ Instantaneous value
+ Energy (10 kWh)
+ 0
+
+
+
+ Instantaneous value
+ Volume (1e-1 m^3)
+ 3
+
+
+
+ Instantaneous value
+ Power (kW)
+ 0
+
+
+
+ Instantaneous value
+ Volume flow (m m^3/h)
+ 0
+
+
+
+ Instantaneous value
+ Flow temperature (1e-1 deg C)
+ 1288
+
+
+
+ Instantaneous value
+ Return temperature (1e-1 deg C)
+ 516
+
+
+
+ Instantaneous value
+ Temperature Difference (1e-2 deg C)
+ 7723
+
+
+
+ Instantaneous value
+ Time Point (date)
+ 2012-01-12
+
+
+
+ Instantaneous value
+ Operating time (days)
+ 3383
+
+
+
+ Manufacturer specific
+ 60 00
+
+
+
diff --git a/test/test-frames/els_tmpa_telegramm1.hex b/test/test-frames/els_tmpa_telegramm1.hex
new file mode 100644
index 0000000..863eb72
--- /dev/null
+++ b/test/test-frames/els_tmpa_telegramm1.hex
@@ -0,0 +1 @@
+68 2C 2C 68 08 01 72 45 23 11 70 93 15 02 07 02 00 00 00 0C 13 67 45 23 01 04 6D 3A 0D E6 02 42 6C E1 01 4C 13 51 69 45 00 42 EC 7E 01 11 0F 00 61 16
\ No newline at end of file
diff --git a/test/test-frames/els_tmpa_telegramm1.xml b/test/test-frames/els_tmpa_telegramm1.xml
new file mode 100644
index 0000000..872df93
--- /dev/null
+++ b/test/test-frames/els_tmpa_telegramm1.xml
@@ -0,0 +1,48 @@
+
+
+
+ 70112345
+ ELS
+ 2
+ Water
+ 2
+ 00
+ 0000
+
+
+
+ Instantaneous value
+ Volume (m m^3)
+ 1234567
+
+
+
+ Instantaneous value
+ Time Point (time & date)
+ 2007-02-06T13:58:00
+
+
+
+ Instantaneous value
+ Time Point (date)
+ 2007-01-01
+
+
+
+ Instantaneous value
+ Volume (m m^3)
+ 456951
+
+
+
+ Instantaneous value
+ Time Point (date)
+ 2008-01-01
+
+
+
+ Manufacturer specific
+ 00
+
+
+
diff --git a/test/test-frames/emh_diz.hex b/test/test-frames/emh_diz.hex
new file mode 100644
index 0000000..8f4cc6a
--- /dev/null
+++ b/test/test-frames/emh_diz.hex
@@ -0,0 +1 @@
+68 21 21 68 08 01 72 02 37 62 00 A8 15 00 02 07 00 00 00 8C 10 04 09 04 00 00 C4 00 2A 00 00 00 00 01 FD 17 00 8C 16
diff --git a/test/test-frames/emh_diz.xml b/test/test-frames/emh_diz.xml
new file mode 100644
index 0000000..9b37129
--- /dev/null
+++ b/test/test-frames/emh_diz.xml
@@ -0,0 +1,31 @@
+
+
+
+ 623702
+ EMH
+ 0
+ Electricity
+ 7
+ 00
+ 0000
+
+
+
+ Instantaneous value
+ Energy (10 Wh)
+ 409
+
+
+
+ Instantaneous value
+ Power (1e-1 W)
+ 0
+
+
+
+ Instantaneous value
+ Error flags
+ 0
+
+
+
diff --git a/test/test-frames/nzr_dhz_5_63.hex b/test/test-frames/nzr_dhz_5_63.hex
new file mode 100644
index 0000000..6a00750
--- /dev/null
+++ b/test/test-frames/nzr_dhz_5_63.hex
@@ -0,0 +1 @@
+68 32 32 68 08 05 72 08 06 10 30 52 3B 01 02 01 00 00 00 04 03 FA 04 00 00 04 83 7F FA 04 00 00 02 FD 48 44 09 02 FD 5B 00 00 02 2B 00 00 0C 78 08 06 10 30 0F 0E 71 16
diff --git a/test/test-frames/nzr_dhz_5_63.xml b/test/test-frames/nzr_dhz_5_63.xml
new file mode 100644
index 0000000..e5361f0
--- /dev/null
+++ b/test/test-frames/nzr_dhz_5_63.xml
@@ -0,0 +1,54 @@
+
+
+
+ 30100608
+ NZR
+ 1
+ Electricity
+ 1
+ 00
+ 0000
+
+
+
+ Instantaneous value
+ Energy (Wh)
+ 1274
+
+
+
+ Instantaneous value
+ Energy (Wh)
+ 1274
+
+
+
+ Instantaneous value
+ 1e-1 V
+ 2372
+
+
+
+ Instantaneous value
+ 1e-1 A
+ 0
+
+
+
+ Instantaneous value
+ Power (W)
+ 0
+
+
+
+ Instantaneous value
+ Fabrication number
+ 30100608
+
+
+
+ Manufacturer specific
+ 0E
+
+
+