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

@ -28,6 +28,7 @@ main(int argc, char **argv)
char *device, *addr_mask;
int baudrate = 9600;
mbus_handle *handle = NULL;
mbus_frame *frame = NULL, *reply = NULL;
if (argc == 2)
{
@ -111,6 +112,42 @@ main(int argc, char **argv)
return 1;
}
frame = mbus_frame_new(MBUS_FRAME_TYPE_SHORT);
if (frame == NULL)
{
fprintf(stderr, "Failed to allocate mbus frame.\n");
return 1;
}
//
// init slaves
//
frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S;
frame->address = 0xFD;
if (mbus_send_frame(handle, frame) == -1)
{
fprintf(stderr, "Failed to send SND_NKE #1.\n");
mbus_frame_free(frame);
return 1;
}
(void) mbus_recv_frame(handle, reply);
frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S;
frame->address = 0xFF;
if (mbus_send_frame(handle, frame) == -1)
{
fprintf(stderr, "Failed to send SND_NKE #2.\n");
mbus_frame_free(frame);
return 1;
}
(void) mbus_recv_frame(handle, reply);
mbus_scan_2nd_address_range(handle, 0, addr_mask);
mbus_disconnect(handle);