From ef630f2e5de203b18bd21edc039a8f41b093c13d Mon Sep 17 00:00:00 2001 From: Stefan Wahren Date: Sun, 20 May 2012 03:52:15 +0200 Subject: [PATCH] Added a new function to select a device by it's secondary address --- mbus/mbus-protocol-aux.c | 45 +++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/mbus/mbus-protocol-aux.c b/mbus/mbus-protocol-aux.c index 0c11a09..6fd052c 100644 --- a/mbus/mbus-protocol-aux.c +++ b/mbus/mbus-protocol-aux.c @@ -1695,16 +1695,15 @@ mbus_send_ping_frame(mbus_handle *handle, int address) } //------------------------------------------------------------------------------ -// Prove for the presence of a device(s) using the supplied secondary address -// (mask). +// Select a device using the supplied secondary address (mask). //------------------------------------------------------------------------------ -int -mbus_probe_secondary_address(mbus_handle * handle, const char *mask, char *matching_addr) +int +mbus_select_secondary_address(mbus_handle * handle, const char *mask) { int ret; mbus_frame reply; - if (mask == NULL || matching_addr == NULL || strlen(mask) != 16) + if (mask == NULL || strlen(mask) != 16) { MBUS_ERROR("%s: Invalid address masks.\n", __PRETTY_FUNCTION__); return MBUS_PROBE_ERROR; @@ -1746,10 +1745,38 @@ mbus_probe_secondary_address(mbus_handle * handle, const char *mask, char *match { return MBUS_PROBE_COLLISION; } + + return MBUS_PROBE_SINGLE; + } + + MBUS_ERROR("%s: Unexpected reply for address [%s].\n", __PRETTY_FUNCTION__, mask); + return MBUS_PROBE_NOTHING; +} + +//------------------------------------------------------------------------------ +// Prove for the presence of a device(s) using the supplied secondary address +// (mask). +//------------------------------------------------------------------------------ +int +mbus_probe_secondary_address(mbus_handle * handle, const char *mask, char *matching_addr) +{ + int ret; + mbus_frame reply; + + if (mask == NULL || matching_addr == NULL || strlen(mask) != 16) + { + MBUS_ERROR("%s: Invalid address masks.\n", __PRETTY_FUNCTION__); + return MBUS_PROBE_ERROR; + } + + ret = mbus_select_secondary_address(handle, mask); + + if (ret == MBUS_PROBE_SINGLE) + { /* send a data request command to find out the full address */ if (mbus_send_request_frame(handle, 253) == -1) - { + { MBUS_ERROR("%s: Failed to send request to selected secondary device [mask %s]: %s.\n", __PRETTY_FUNCTION__, mask, @@ -1787,10 +1814,8 @@ mbus_probe_secondary_address(mbus_handle * handle, const char *mask, char *match return MBUS_PROBE_NOTHING; } } - - MBUS_ERROR("%s: Unexpected reply for address [%s].\n", __PRETTY_FUNCTION__, mask); - - return MBUS_PROBE_NOTHING; + + return ret; }