From fef774d98d8d4271965e192f36fb98b8f098c21b Mon Sep 17 00:00:00 2001 From: Stefan Wahren Date: Thu, 4 Oct 2012 22:33:22 +0200 Subject: [PATCH] Purge behavior as new context parameter (default = purge master to slave) --- mbus/mbus-protocol-aux.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mbus/mbus-protocol-aux.c b/mbus/mbus-protocol-aux.c index dd6ddb5..ec0f6f0 100755 --- a/mbus/mbus-protocol-aux.c +++ b/mbus/mbus-protocol-aux.c @@ -1353,6 +1353,7 @@ mbus_context_serial(const char *device) handle->max_retry = 3; handle->is_serial = 1; + handle->purge_first_frame = MBUS_FRAME_PURGE_M2S; handle->auxdata = serial_data; handle->open = mbus_serial_connect; handle->close = mbus_serial_disconnect; @@ -1395,6 +1396,7 @@ mbus_context_tcp(const char *host, int port) handle->max_retry = 3; handle->is_serial = 0; + handle->purge_first_frame = MBUS_FRAME_PURGE_M2S; handle->auxdata = tcp_data; handle->open = mbus_tcp_connect; handle->close = mbus_tcp_disconnect; @@ -1468,11 +1470,16 @@ mbus_recv_frame(mbus_handle * handle, mbus_frame *frame) result = handle->recv(handle, frame); - /* frame valid, but wrong direction */ - if (mbus_frame_direction(frame) == MBUS_CONTROL_MASK_DIR_M2S) + switch (mbus_frame_direction(frame)) { - /* purge echo and retry (echo cancelation) */ - result = handle->recv(handle, frame); + case MBUS_CONTROL_MASK_DIR_M2S: + if (handle->purge_first_frame == MBUS_FRAME_PURGE_M2S) + result = handle->recv(handle, frame); // purge echo and retry + break; + case MBUS_CONTROL_MASK_DIR_S2M: + if (handle->purge_first_frame == MBUS_FRAME_PURGE_S2M) + result = handle->recv(handle, frame); // purge echo and retry + break; } if (frame != NULL)