From 1a538e73aae15ed308dc39663ec40a64bd2714ce Mon Sep 17 00:00:00 2001 From: Stefan Wahren Date: Sat, 1 Sep 2012 22:51:44 +0200 Subject: [PATCH] New parameter for mbus_send_ping_frame to purge response --- bin/mbus-serial-scan.c | 2 +- bin/mbus-tcp-scan.c | 2 +- mbus/mbus-protocol-aux.c | 14 ++++++++++---- mbus/mbus-protocol-aux.h | 7 ++++--- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/bin/mbus-serial-scan.c b/bin/mbus-serial-scan.c index a2c14c9..2509e89 100755 --- a/bin/mbus-serial-scan.c +++ b/bin/mbus-serial-scan.c @@ -95,7 +95,7 @@ main(int argc, char **argv) fflush(stdout); } - if (mbus_send_ping_frame(handle, address) == -1) + if (mbus_send_ping_frame(handle, address, 0) == -1) { printf("Scan failed. Could not send ping frame: %s\n", mbus_error_str()); return 1; diff --git a/bin/mbus-tcp-scan.c b/bin/mbus-tcp-scan.c index 10d4165..4e72bf5 100755 --- a/bin/mbus-tcp-scan.c +++ b/bin/mbus-tcp-scan.c @@ -78,7 +78,7 @@ main(int argc, char **argv) fflush(stdout); } - if (mbus_send_ping_frame(handle, address) == -1) + if (mbus_send_ping_frame(handle, address, 0) == -1) { printf("Scan failed. Could not send ping frame: %s\n", mbus_error_str()); return 1; diff --git a/mbus/mbus-protocol-aux.c b/mbus/mbus-protocol-aux.c index f6c3bf2..41fd3b0 100755 --- a/mbus/mbus-protocol-aux.c +++ b/mbus/mbus-protocol-aux.c @@ -1786,10 +1786,10 @@ mbus_sendrecv_request(mbus_handle *handle, int address, mbus_frame *reply, int m //------------------------------------------------------------------------------ -// send a data request packet to from master to slave +// send a data request packet to from master to slave and optional purge response //------------------------------------------------------------------------------ int -mbus_send_ping_frame(mbus_handle *handle, int address) +mbus_send_ping_frame(mbus_handle *handle, int address, char purge_response) { int retval = 0; mbus_frame *frame; @@ -1808,8 +1808,14 @@ mbus_send_ping_frame(mbus_handle *handle, int address) if (mbus_send_frame(handle, frame) == -1) { MBUS_ERROR("%s: failed to send mbus frame.\n", __PRETTY_FUNCTION__); - retval = -1; - } + mbus_frame_free(frame); + return -1; + } + + if (purge_response) + { + mbus_purge_frames(handle); + } mbus_frame_free(frame); return retval; diff --git a/mbus/mbus-protocol-aux.h b/mbus/mbus-protocol-aux.h index f5bf56b..5b63188 100755 --- a/mbus/mbus-protocol-aux.h +++ b/mbus/mbus-protocol-aux.h @@ -265,12 +265,13 @@ int mbus_sendrecv_request(mbus_handle *handle, int address, mbus_frame *reply, i /** * Sends ping frame to given slave using "unified" handle * - * @param handle Initialized handle - * @param address Address (0-255) + * @param handle Initialized handle + * @param address Address (0-255) + * @param purge_response Response flag (=0 don't receive response, >0 purge response) * * @return Zero when successful. */ -int mbus_send_ping_frame(mbus_handle *handle, int address); +int mbus_send_ping_frame(mbus_handle *handle, int address, char purge_response); /** * Select slave by secondary address using "unified" handle