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:
Stefan Wahren
2012-05-15 23:30:55 +02:00
parent 980bbb1862
commit f14b3beb84
4 changed files with 89 additions and 27 deletions

View File

@ -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)
{