Adopt retransmission for secondary address probing
This commit is contained in:
parent
e6173103e2
commit
663642b7ec
@ -2164,7 +2164,7 @@ mbus_select_secondary_address(mbus_handle * handle, const char *mask)
|
|||||||
int
|
int
|
||||||
mbus_probe_secondary_address(mbus_handle *handle, const char *mask, char *matching_addr)
|
mbus_probe_secondary_address(mbus_handle *handle, const char *mask, char *matching_addr)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret, i;
|
||||||
mbus_frame reply;
|
mbus_frame reply;
|
||||||
|
|
||||||
if (mask == NULL || matching_addr == NULL || strlen(mask) != 16)
|
if (mask == NULL || matching_addr == NULL || strlen(mask) != 16)
|
||||||
@ -2173,68 +2173,77 @@ mbus_probe_secondary_address(mbus_handle *handle, const char *mask, char *matchi
|
|||||||
return MBUS_PROBE_ERROR;
|
return MBUS_PROBE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = mbus_select_secondary_address(handle, mask);
|
for (i = 0; i <= handle->max_search_retry; i++)
|
||||||
|
|
||||||
if (ret == MBUS_PROBE_SINGLE)
|
|
||||||
{
|
{
|
||||||
/* send a data request command to find out the full address */
|
ret = mbus_select_secondary_address(handle, mask);
|
||||||
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__,
|
|
||||||
mask,
|
|
||||||
mbus_error_str());
|
|
||||||
return MBUS_PROBE_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset((void *)&reply, 0, sizeof(mbus_frame));
|
if (ret == MBUS_PROBE_SINGLE)
|
||||||
ret = mbus_recv_frame(handle, &reply);
|
{
|
||||||
|
/* send a data request command to find out the full address */
|
||||||
|
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__,
|
||||||
|
mask,
|
||||||
|
mbus_error_str());
|
||||||
|
return MBUS_PROBE_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
if (ret == MBUS_RECV_RESULT_TIMEOUT)
|
memset((void *)&reply, 0, sizeof(mbus_frame));
|
||||||
{
|
ret = mbus_recv_frame(handle, &reply);
|
||||||
return MBUS_PROBE_NOTHING;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret == MBUS_RECV_RESULT_INVALID)
|
if (ret == MBUS_RECV_RESULT_TIMEOUT)
|
||||||
{
|
|
||||||
/* check for more data (collision) */
|
|
||||||
mbus_purge_frames(handle);
|
|
||||||
return MBUS_PROBE_COLLISION;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check for more data (collision) */
|
|
||||||
if (mbus_purge_frames(handle))
|
|
||||||
{
|
|
||||||
return MBUS_PROBE_COLLISION;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mbus_frame_type(&reply) == MBUS_FRAME_TYPE_LONG)
|
|
||||||
{
|
|
||||||
char *addr = mbus_frame_get_secondary_address(&reply);
|
|
||||||
|
|
||||||
if (addr == NULL)
|
|
||||||
{
|
{
|
||||||
// show error message, but procede with scan
|
|
||||||
MBUS_ERROR("Failed to generate secondary address from M-Bus reply frame: %s\n", mbus_error_str());
|
|
||||||
return MBUS_PROBE_NOTHING;
|
return MBUS_PROBE_NOTHING;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(matching_addr, 17, "%s", addr);
|
if (ret == MBUS_RECV_RESULT_INVALID)
|
||||||
|
|
||||||
if (handle->found_event)
|
|
||||||
{
|
{
|
||||||
handle->found_event(handle,&reply);
|
/* check for more data (collision) */
|
||||||
}
|
mbus_purge_frames(handle);
|
||||||
|
return MBUS_PROBE_COLLISION;
|
||||||
|
}
|
||||||
|
|
||||||
return MBUS_PROBE_SINGLE;
|
/* check for more data (collision) */
|
||||||
}
|
if (mbus_purge_frames(handle))
|
||||||
else
|
{
|
||||||
{
|
return MBUS_PROBE_COLLISION;
|
||||||
MBUS_ERROR("%s: Unexpected reply for address [mask %s]. Expected long frame.\n",
|
}
|
||||||
__PRETTY_FUNCTION__, mask);
|
|
||||||
return MBUS_PROBE_NOTHING;
|
if (mbus_frame_type(&reply) == MBUS_FRAME_TYPE_LONG)
|
||||||
}
|
{
|
||||||
}
|
char *addr = mbus_frame_get_secondary_address(&reply);
|
||||||
|
|
||||||
|
if (addr == NULL)
|
||||||
|
{
|
||||||
|
// show error message, but procede with scan
|
||||||
|
MBUS_ERROR("Failed to generate secondary address from M-Bus reply frame: %s\n",
|
||||||
|
mbus_error_str());
|
||||||
|
return MBUS_PROBE_NOTHING;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(matching_addr, 17, "%s", addr);
|
||||||
|
|
||||||
|
if (handle->found_event)
|
||||||
|
{
|
||||||
|
handle->found_event(handle,&reply);
|
||||||
|
}
|
||||||
|
|
||||||
|
return MBUS_PROBE_SINGLE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MBUS_ERROR("%s: Unexpected reply for address [mask %s]. Expected long frame.\n",
|
||||||
|
__PRETTY_FUNCTION__, mask);
|
||||||
|
return MBUS_PROBE_NOTHING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ((ret == MBUS_PROBE_ERROR) ||
|
||||||
|
(ret == MBUS_PROBE_COLLISION))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user