Fixed bugs in wildcard search
- init slaves before search - corrected return codes - handle collisions (possibly more bytes than expected) - sync recv frame (tcp vs serial) - add tracing
This commit is contained in:
@ -144,7 +144,7 @@ mbus_tcp_send_frame(mbus_tcp_handle *handle, mbus_frame *frame)
|
||||
// call the send event function, if the callback function is registered
|
||||
//
|
||||
if (_mbus_send_event)
|
||||
_mbus_send_event(MBUS_HANDLE_TYPE_TCP);
|
||||
_mbus_send_event(MBUS_HANDLE_TYPE_TCP, buff, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -176,17 +176,7 @@ mbus_tcp_recv_frame(mbus_tcp_handle *handle, mbus_frame *frame)
|
||||
|
||||
do {
|
||||
|
||||
nread = read(handle->sock, &buff[len], remaining);
|
||||
|
||||
if (nread > 0)
|
||||
{
|
||||
//
|
||||
// call the receive event function, if the callback function is registered
|
||||
//
|
||||
if (_mbus_recv_event)
|
||||
_mbus_recv_event(MBUS_HANDLE_TYPE_TCP);
|
||||
}
|
||||
else if (nread == -1)
|
||||
if ((nread = read(handle->sock, &buff[len], remaining)) == -1)
|
||||
{
|
||||
mbus_error_str_set("M-Bus tcp transport layer failed to read data.");
|
||||
return -1;
|
||||
@ -195,6 +185,18 @@ mbus_tcp_recv_frame(mbus_tcp_handle *handle, mbus_frame *frame)
|
||||
len += nread;
|
||||
|
||||
} while ((remaining = mbus_parse(frame, buff, len)) > 0);
|
||||
|
||||
if (len == 0)
|
||||
{
|
||||
// No data received
|
||||
return -1;
|
||||
}
|
||||
|
||||
//
|
||||
// call the receive event function, if the callback function is registered
|
||||
//
|
||||
if (_mbus_recv_event)
|
||||
_mbus_recv_event(MBUS_HANDLE_TYPE_TCP, buff, len);
|
||||
|
||||
if (remaining < 0)
|
||||
{
|
||||
|
Reference in New Issue
Block a user