From c5661ba35f1cd72afa0c0cce45c568986b1d1bf2 Mon Sep 17 00:00:00 2001 From: Stefan Wahren Date: Wed, 19 Dec 2012 11:30:17 +0100 Subject: [PATCH 1/4] Add mbus-tcp-raw-send to clean up script --- .gitignore | 1 + bin/Makefile.am | 1 + bin/libmbus.pod | 8 ++++++++ bin/mbus-tcp-raw-send.1 | 2 ++ clean.sh | 1 + 5 files changed, 13 insertions(+) create mode 100644 bin/mbus-tcp-raw-send.1 diff --git a/.gitignore b/.gitignore index 2bb98e8..2e10929 100644 --- a/.gitignore +++ b/.gitignore @@ -53,6 +53,7 @@ bin/mbus-serial-scan bin/mbus-serial-scan-secondary bin/mbus-serial-select-secondary bin/mbus-serial-switch-baudrate +bin/mbus-tcp-raw-send bin/mbus-tcp-request-data bin/mbus-tcp-request-data-multi-reply bin/mbus-tcp-scan diff --git a/bin/Makefile.am b/bin/Makefile.am index 3078f5b..82b8446 100644 --- a/bin/Makefile.am +++ b/bin/Makefile.am @@ -77,6 +77,7 @@ dist_man_MANS = libmbus.1 \ mbus-tcp-request-data-multi-reply.1 \ mbus-tcp-select-secondary.1 \ mbus-tcp-scan-secondary.1 \ + mbus-tcp-raw-send.1 \ mbus-serial-scan.1 \ mbus-serial-request-data.1 \ mbus-serial-request-data-multi-reply.1 \ diff --git a/bin/libmbus.pod b/bin/libmbus.pod index ecd109e..634e4ea 100644 --- a/bin/libmbus.pod +++ b/bin/libmbus.pod @@ -30,6 +30,8 @@ B [-b BAUDRATE] device secondary-mbus-address B host port secondary-mbus-address +B [-d] host port mbus-address [file] + =head1 DESCRIPTION B - attempts to switch the communication speed of @@ -52,6 +54,8 @@ Supports both primary and secondary address types. B, B - perform single secondary address select to check what device responds. +B - send a single raw hex frame to a MBus device. + =head1 OPTIONS There are following options/parameters: @@ -113,6 +117,10 @@ MBus secondary address of the device. Sixteen digit hexadecimal number. For serial communication, the baudrate to which the device should be switched. +=item B + +Path to an file with hex values. + =back diff --git a/bin/mbus-tcp-raw-send.1 b/bin/mbus-tcp-raw-send.1 new file mode 100644 index 0000000..df8a67a --- /dev/null +++ b/bin/mbus-tcp-raw-send.1 @@ -0,0 +1,2 @@ +.so man1/libmbus.1 + diff --git a/clean.sh b/clean.sh index fda07d3..4cfb33a 100755 --- a/clean.sh +++ b/clean.sh @@ -34,6 +34,7 @@ true \ && rm -f bin/mbus-serial-scan-secondary \ && rm -f bin/mbus-serial-select-secondary \ && rm -f bin/mbus-serial-switch-baudrate \ + && rm -f bin/mbus-tcp-raw-send \ && rm -f bin/mbus-tcp-request-data \ && rm -f bin/mbus-tcp-request-data-multi-reply \ && rm -f bin/mbus-tcp-scan \ From 48a5b2bab785f4943c8948cf43f0debe678fa8f6 Mon Sep 17 00:00:00 2001 From: Stefan Wahren Date: Wed, 19 Dec 2012 21:20:38 +0100 Subject: [PATCH 2/4] Extend clean up script (based on the changes from tmtom) --- .gitignore | 1 + bin/Makefile.am | 1 + bin/libmbus.pod | 8 ++++++++ bin/mbus-tcp-raw-send.1 | 2 ++ clean.sh | 19 ++++++++++++++++++- 5 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 bin/mbus-tcp-raw-send.1 diff --git a/.gitignore b/.gitignore index 2bb98e8..2e10929 100644 --- a/.gitignore +++ b/.gitignore @@ -53,6 +53,7 @@ bin/mbus-serial-scan bin/mbus-serial-scan-secondary bin/mbus-serial-select-secondary bin/mbus-serial-switch-baudrate +bin/mbus-tcp-raw-send bin/mbus-tcp-request-data bin/mbus-tcp-request-data-multi-reply bin/mbus-tcp-scan diff --git a/bin/Makefile.am b/bin/Makefile.am index 3078f5b..82b8446 100644 --- a/bin/Makefile.am +++ b/bin/Makefile.am @@ -77,6 +77,7 @@ dist_man_MANS = libmbus.1 \ mbus-tcp-request-data-multi-reply.1 \ mbus-tcp-select-secondary.1 \ mbus-tcp-scan-secondary.1 \ + mbus-tcp-raw-send.1 \ mbus-serial-scan.1 \ mbus-serial-request-data.1 \ mbus-serial-request-data-multi-reply.1 \ diff --git a/bin/libmbus.pod b/bin/libmbus.pod index ecd109e..634e4ea 100644 --- a/bin/libmbus.pod +++ b/bin/libmbus.pod @@ -30,6 +30,8 @@ B [-b BAUDRATE] device secondary-mbus-address B host port secondary-mbus-address +B [-d] host port mbus-address [file] + =head1 DESCRIPTION B - attempts to switch the communication speed of @@ -52,6 +54,8 @@ Supports both primary and secondary address types. B, B - perform single secondary address select to check what device responds. +B - send a single raw hex frame to a MBus device. + =head1 OPTIONS There are following options/parameters: @@ -113,6 +117,10 @@ MBus secondary address of the device. Sixteen digit hexadecimal number. For serial communication, the baudrate to which the device should be switched. +=item B + +Path to an file with hex values. + =back diff --git a/bin/mbus-tcp-raw-send.1 b/bin/mbus-tcp-raw-send.1 new file mode 100644 index 0000000..df8a67a --- /dev/null +++ b/bin/mbus-tcp-raw-send.1 @@ -0,0 +1,2 @@ +.so man1/libmbus.1 + diff --git a/clean.sh b/clean.sh index fda07d3..c895f64 100755 --- a/clean.sh +++ b/clean.sh @@ -20,13 +20,16 @@ true \ && rm -f ltmain.sh \ && rm -f missing \ && rm -f stamp-h1 \ + && rm -f *~ \ && rm -f -r autom4te.cache \ && rm -f -r libltdl \ && rm -f -r m4 \ + && rm -f -r bin/.deps \ && rm -f -r bin/.libs \ && rm -f bin/Makefile \ && rm -f bin/Makefile.in \ && rm -f bin/*.o \ + && rm -f bin/*~ \ && rm -f bin/libmbus.1 \ && rm -f bin/mbus-serial-request-data \ && rm -f bin/mbus-serial-request-data-multi-reply \ @@ -34,17 +37,31 @@ true \ && rm -f bin/mbus-serial-scan-secondary \ && rm -f bin/mbus-serial-select-secondary \ && rm -f bin/mbus-serial-switch-baudrate \ + && rm -f bin/mbus-tcp-raw-send \ && rm -f bin/mbus-tcp-request-data \ && rm -f bin/mbus-tcp-request-data-multi-reply \ && rm -f bin/mbus-tcp-scan \ && rm -f bin/mbus-tcp-scan-secondary \ && rm -f bin/mbus-tcp-select-secondary \ - && rm -f -r bin/.libs \ + && rm -f -r mbus/.deps \ + && rm -f -r mbus/.libs \ && rm -f mbus/Makefile \ && rm -f mbus/Makefile.in \ && rm -f mbus/*.o \ && rm -f mbus/*.lo \ && rm -f mbus/*.la \ + && rm -f mbus/*~ \ + && rm -f -r test/.deps \ + && rm -f -r test/.libs \ + && rm -f test/Makefile \ + && rm -f test/Makefile.in \ + && rm -f test/*.o \ + && rm -f test/*.lo \ + && rm -f test/*.la \ + && rm -f test/*~ \ + && rm -f test/mbus_parse \ + && rm -f test/mbus_parse_hex \ + && rm -f test/mbus_unit_test1 \ && rm -f -r debian/libmbus-dev \ && rm -f -r debian/libmbus1 \ && rm -f -r debian/tmp \ From a4e92f6eab2549316997ea73afbef03e19881caf Mon Sep 17 00:00:00 2001 From: Stefan Wahren Date: Thu, 20 Dec 2012 20:12:19 +0100 Subject: [PATCH 3/4] replace magic number with define --- bin/mbus-serial-request-data-multi-reply.c | 2 +- bin/mbus-serial-request-data.c | 2 +- bin/mbus-serial-select-secondary.c | 2 +- bin/mbus-tcp-raw-send.c | 2 +- bin/mbus-tcp-request-data-multi-reply.c | 2 +- bin/mbus-tcp-request-data.c | 2 +- bin/mbus-tcp-select-secondary.c | 2 +- mbus/mbus-protocol-aux.c | 4 ++-- mbus/mbus-protocol.c | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bin/mbus-serial-request-data-multi-reply.c b/bin/mbus-serial-request-data-multi-reply.c index 91a2642..2213755 100755 --- a/bin/mbus-serial-request-data-multi-reply.c +++ b/bin/mbus-serial-request-data-multi-reply.c @@ -146,7 +146,7 @@ main(int argc, char **argv) } // else MBUS_PROBE_SINGLE - address = 253; + address = MBUS_ADDRESS_NETWORK_LAYER; } else { diff --git a/bin/mbus-serial-request-data.c b/bin/mbus-serial-request-data.c index f1eaaf0..e4e22e1 100755 --- a/bin/mbus-serial-request-data.c +++ b/bin/mbus-serial-request-data.c @@ -113,7 +113,7 @@ main(int argc, char **argv) } // else MBUS_PROBE_SINGLE - if (mbus_send_request_frame(handle, 253) == -1) + if (mbus_send_request_frame(handle, MBUS_ADDRESS_NETWORK_LAYER) == -1) { fprintf(stderr, "Failed to send M-Bus request frame.\n"); return 1; diff --git a/bin/mbus-serial-select-secondary.c b/bin/mbus-serial-select-secondary.c index 628d45b..ad4a883 100755 --- a/bin/mbus-serial-select-secondary.c +++ b/bin/mbus-serial-select-secondary.c @@ -95,7 +95,7 @@ main(int argc, char **argv) if (mbus_frame_type(&reply) == MBUS_FRAME_TYPE_ACK) { - if (mbus_send_request_frame(handle, 253) == -1) + if (mbus_send_request_frame(handle, MBUS_ADDRESS_NETWORK_LAYER) == -1) { printf("Failed to send request to selected secondary device: %s\n", mbus_error_str()); return 1; diff --git a/bin/mbus-tcp-raw-send.c b/bin/mbus-tcp-raw-send.c index 8cc84f7..8f58b97 100644 --- a/bin/mbus-tcp-raw-send.c +++ b/bin/mbus-tcp-raw-send.c @@ -112,7 +112,7 @@ main(int argc, char **argv) fprintf(stderr, "%s: Error: Failed to select secondary address [%s].\n", __PRETTY_FUNCTION__, addr_str); return 1; } - address = 253; + address = MBUS_ADDRESS_NETWORK_LAYER; } else { diff --git a/bin/mbus-tcp-request-data-multi-reply.c b/bin/mbus-tcp-request-data-multi-reply.c index 4d932eb..e682c1e 100755 --- a/bin/mbus-tcp-request-data-multi-reply.c +++ b/bin/mbus-tcp-request-data-multi-reply.c @@ -106,7 +106,7 @@ main(int argc, char **argv) } // else MBUS_PROBE_SINGLE - address = 253; + address = MBUS_ADDRESS_NETWORK_LAYER; } else { diff --git a/bin/mbus-tcp-request-data.c b/bin/mbus-tcp-request-data.c index 08fbca8..70aa4ee 100755 --- a/bin/mbus-tcp-request-data.c +++ b/bin/mbus-tcp-request-data.c @@ -95,7 +95,7 @@ main(int argc, char **argv) } // else MBUS_PROBE_SINGLE - if (mbus_send_request_frame(handle, 253) == -1) + if (mbus_send_request_frame(handle, MBUS_ADDRESS_NETWORK_LAYER) == -1) { fprintf(stderr, "Failed to send M-Bus request frame.\n"); return 1; diff --git a/bin/mbus-tcp-select-secondary.c b/bin/mbus-tcp-select-secondary.c index 2970f98..e894a97 100755 --- a/bin/mbus-tcp-select-secondary.c +++ b/bin/mbus-tcp-select-secondary.c @@ -80,7 +80,7 @@ main(int argc, char **argv) if (mbus_frame_type(&reply) == MBUS_FRAME_TYPE_ACK) { - if (mbus_send_request_frame(handle, 253) == -1) + if (mbus_send_request_frame(handle, MBUS_ADDRESS_NETWORK_LAYER) == -1) { printf("Failed to send request to 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 0d2645e..ed6df91 100755 --- a/mbus/mbus-protocol-aux.c +++ b/mbus/mbus-protocol-aux.c @@ -1983,7 +1983,7 @@ mbus_probe_secondary_address(mbus_handle * handle, const char *mask, char *match if (ret == MBUS_PROBE_SINGLE) { /* send a data request command to find out the full address */ - if (mbus_send_request_frame(handle, 253) == -1) + if (mbus_send_request_frame(handle, MBUS_ADDRESS_NETWORK_LAYER) == -1) { MBUS_ERROR("%s: Failed to send request to selected secondary device [mask %s]: %s.\n", __PRETTY_FUNCTION__, @@ -2082,7 +2082,7 @@ int mbus_read_slave(mbus_handle * handle, mbus_address *address, mbus_frame * re } /* else MBUS_PROBE_SINGLE */ - if (mbus_send_request_frame(handle, 253) == -1) + if (mbus_send_request_frame(handle, MBUS_ADDRESS_NETWORK_LAYER) == -1) { MBUS_ERROR("%s: Failed to send M-Bus request frame.\n", __PRETTY_FUNCTION__); diff --git a/mbus/mbus-protocol.c b/mbus/mbus-protocol.c index 1876444..a3a9e46 100755 --- a/mbus/mbus-protocol.c +++ b/mbus/mbus-protocol.c @@ -3956,7 +3956,7 @@ mbus_frame_select_secondary_pack(mbus_frame *frame, char *address) } frame->control = MBUS_CONTROL_MASK_SND_UD | MBUS_CONTROL_MASK_DIR_M2S | MBUS_CONTROL_MASK_FCB; - frame->address = 253; // for addressing secondary slaves + frame->address = MBUS_ADDRESS_NETWORK_LAYER; // for addressing secondary slaves frame->control_information = 0x52; // mode 1 frame->data_size = 8; From 404e245af5ae9a9ccc45d613e5b9fc9d13a4a452 Mon Sep 17 00:00:00 2001 From: Stefan Wahren Date: Thu, 20 Dec 2012 20:42:10 +0100 Subject: [PATCH 4/4] replace magic number with define --- bin/mbus-serial-request-data-multi-reply.c | 2 +- bin/mbus-serial-request-data.c | 2 +- bin/mbus-serial-select-secondary.c | 2 +- bin/mbus-tcp-raw-send.c | 2 +- bin/mbus-tcp-request-data-multi-reply.c | 2 +- bin/mbus-tcp-request-data.c | 2 +- bin/mbus-tcp-select-secondary.c | 2 +- mbus/mbus-protocol-aux.c | 4 ++-- mbus/mbus-protocol.c | 4 ++-- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bin/mbus-serial-request-data-multi-reply.c b/bin/mbus-serial-request-data-multi-reply.c index 91a2642..2213755 100755 --- a/bin/mbus-serial-request-data-multi-reply.c +++ b/bin/mbus-serial-request-data-multi-reply.c @@ -146,7 +146,7 @@ main(int argc, char **argv) } // else MBUS_PROBE_SINGLE - address = 253; + address = MBUS_ADDRESS_NETWORK_LAYER; } else { diff --git a/bin/mbus-serial-request-data.c b/bin/mbus-serial-request-data.c index f1eaaf0..e4e22e1 100755 --- a/bin/mbus-serial-request-data.c +++ b/bin/mbus-serial-request-data.c @@ -113,7 +113,7 @@ main(int argc, char **argv) } // else MBUS_PROBE_SINGLE - if (mbus_send_request_frame(handle, 253) == -1) + if (mbus_send_request_frame(handle, MBUS_ADDRESS_NETWORK_LAYER) == -1) { fprintf(stderr, "Failed to send M-Bus request frame.\n"); return 1; diff --git a/bin/mbus-serial-select-secondary.c b/bin/mbus-serial-select-secondary.c index 628d45b..ad4a883 100755 --- a/bin/mbus-serial-select-secondary.c +++ b/bin/mbus-serial-select-secondary.c @@ -95,7 +95,7 @@ main(int argc, char **argv) if (mbus_frame_type(&reply) == MBUS_FRAME_TYPE_ACK) { - if (mbus_send_request_frame(handle, 253) == -1) + if (mbus_send_request_frame(handle, MBUS_ADDRESS_NETWORK_LAYER) == -1) { printf("Failed to send request to selected secondary device: %s\n", mbus_error_str()); return 1; diff --git a/bin/mbus-tcp-raw-send.c b/bin/mbus-tcp-raw-send.c index 8cc84f7..8f58b97 100644 --- a/bin/mbus-tcp-raw-send.c +++ b/bin/mbus-tcp-raw-send.c @@ -112,7 +112,7 @@ main(int argc, char **argv) fprintf(stderr, "%s: Error: Failed to select secondary address [%s].\n", __PRETTY_FUNCTION__, addr_str); return 1; } - address = 253; + address = MBUS_ADDRESS_NETWORK_LAYER; } else { diff --git a/bin/mbus-tcp-request-data-multi-reply.c b/bin/mbus-tcp-request-data-multi-reply.c index 4d932eb..e682c1e 100755 --- a/bin/mbus-tcp-request-data-multi-reply.c +++ b/bin/mbus-tcp-request-data-multi-reply.c @@ -106,7 +106,7 @@ main(int argc, char **argv) } // else MBUS_PROBE_SINGLE - address = 253; + address = MBUS_ADDRESS_NETWORK_LAYER; } else { diff --git a/bin/mbus-tcp-request-data.c b/bin/mbus-tcp-request-data.c index 08fbca8..70aa4ee 100755 --- a/bin/mbus-tcp-request-data.c +++ b/bin/mbus-tcp-request-data.c @@ -95,7 +95,7 @@ main(int argc, char **argv) } // else MBUS_PROBE_SINGLE - if (mbus_send_request_frame(handle, 253) == -1) + if (mbus_send_request_frame(handle, MBUS_ADDRESS_NETWORK_LAYER) == -1) { fprintf(stderr, "Failed to send M-Bus request frame.\n"); return 1; diff --git a/bin/mbus-tcp-select-secondary.c b/bin/mbus-tcp-select-secondary.c index 2970f98..e894a97 100755 --- a/bin/mbus-tcp-select-secondary.c +++ b/bin/mbus-tcp-select-secondary.c @@ -80,7 +80,7 @@ main(int argc, char **argv) if (mbus_frame_type(&reply) == MBUS_FRAME_TYPE_ACK) { - if (mbus_send_request_frame(handle, 253) == -1) + if (mbus_send_request_frame(handle, MBUS_ADDRESS_NETWORK_LAYER) == -1) { printf("Failed to send request to 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 0d2645e..ed6df91 100755 --- a/mbus/mbus-protocol-aux.c +++ b/mbus/mbus-protocol-aux.c @@ -1983,7 +1983,7 @@ mbus_probe_secondary_address(mbus_handle * handle, const char *mask, char *match if (ret == MBUS_PROBE_SINGLE) { /* send a data request command to find out the full address */ - if (mbus_send_request_frame(handle, 253) == -1) + if (mbus_send_request_frame(handle, MBUS_ADDRESS_NETWORK_LAYER) == -1) { MBUS_ERROR("%s: Failed to send request to selected secondary device [mask %s]: %s.\n", __PRETTY_FUNCTION__, @@ -2082,7 +2082,7 @@ int mbus_read_slave(mbus_handle * handle, mbus_address *address, mbus_frame * re } /* else MBUS_PROBE_SINGLE */ - if (mbus_send_request_frame(handle, 253) == -1) + if (mbus_send_request_frame(handle, MBUS_ADDRESS_NETWORK_LAYER) == -1) { MBUS_ERROR("%s: Failed to send M-Bus request frame.\n", __PRETTY_FUNCTION__); diff --git a/mbus/mbus-protocol.c b/mbus/mbus-protocol.c index 1876444..9fec668 100755 --- a/mbus/mbus-protocol.c +++ b/mbus/mbus-protocol.c @@ -3956,8 +3956,8 @@ mbus_frame_select_secondary_pack(mbus_frame *frame, char *address) } frame->control = MBUS_CONTROL_MASK_SND_UD | MBUS_CONTROL_MASK_DIR_M2S | MBUS_CONTROL_MASK_FCB; - frame->address = 253; // for addressing secondary slaves - frame->control_information = 0x52; // mode 1 + frame->address = MBUS_ADDRESS_NETWORK_LAYER; // for addressing secondary slaves + frame->control_information = MBUS_CONTROL_INFO_SELECT_SLAVE; // mode 1 frame->data_size = 8;