- fixed check of mbus_sendrecv_request and mbus_recv_frame

- initialized memory in mbus_sendrecv_request
- used defines for special address instead of magic numbers
This commit is contained in:
Stefan Wahren
2012-06-20 00:23:25 +02:00
parent 0d610b6a27
commit d025b27b07
6 changed files with 9 additions and 9 deletions

View File

@ -98,7 +98,7 @@ main(int argc, char **argv)
} }
frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S; frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S;
frame->address = MBUS_ADDRESS_BROADCAST_NOREPLY; frame->address = MBUS_ADDRESS_NETWORK_LAYER;
if (debug) if (debug)
printf("%s: debug: sending init frame\n", __PRETTY_FUNCTION__); printf("%s: debug: sending init frame\n", __PRETTY_FUNCTION__);
@ -147,7 +147,7 @@ main(int argc, char **argv)
// instead of the send and recv, use this sendrecv function that // instead of the send and recv, use this sendrecv function that
// takes care of the possibility of multi-telegram replies (limit = 16 frames) // takes care of the possibility of multi-telegram replies (limit = 16 frames)
if (mbus_sendrecv_request(handle, address, &reply, 16) == -1) if (mbus_sendrecv_request(handle, address, &reply, 16) != 0)
{ {
fprintf(stderr, "Failed to send/receive M-Bus request.\n"); fprintf(stderr, "Failed to send/receive M-Bus request.\n");
return 1; return 1;

View File

@ -126,7 +126,7 @@ main(int argc, char **argv)
} }
} }
if (mbus_recv_frame(handle, &reply) == -1) if (mbus_recv_frame(handle, &reply) != 0)
{ {
fprintf(stderr, "Failed to receive M-Bus response frame.\n"); fprintf(stderr, "Failed to receive M-Bus response frame.\n");
return 1; return 1;

View File

@ -127,7 +127,7 @@ main(int argc, char **argv)
// init slaves // init slaves
// //
frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S; frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S;
frame->address = 0xFD; frame->address = MBUS_ADDRESS_NETWORK_LAYER;
if (mbus_send_frame(handle, frame) == -1) if (mbus_send_frame(handle, frame) == -1)
{ {
@ -139,7 +139,7 @@ main(int argc, char **argv)
(void) mbus_recv_frame(handle, &reply); (void) mbus_recv_frame(handle, &reply);
frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S; frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S;
frame->address = 0xFF; frame->address = MBUS_ADDRESS_BROADCAST_NOREPLY;
if (mbus_send_frame(handle, frame) == -1) if (mbus_send_frame(handle, frame) == -1)
{ {

View File

@ -130,7 +130,7 @@ main(int argc, char **argv)
// instead of the send and recv, use this sendrecv function that // instead of the send and recv, use this sendrecv function that
// takes care of the possibility of multi-telegram replies (limit = 16 frames) // takes care of the possibility of multi-telegram replies (limit = 16 frames)
if (mbus_sendrecv_request(handle, address, &reply, 16) == -1) if (mbus_sendrecv_request(handle, address, &reply, 16) != 0)
{ {
fprintf(stderr, "Failed to send/receive M-Bus request.\n"); fprintf(stderr, "Failed to send/receive M-Bus request.\n");
return 1; return 1;

View File

@ -111,7 +111,7 @@ main(int argc, char **argv)
} }
} }
if (mbus_recv_frame(handle, &reply) == -1) if (mbus_recv_frame(handle, &reply) != 0)
{ {
fprintf(stderr, "Failed to receive M-Bus response frame.\n"); fprintf(stderr, "Failed to receive M-Bus response frame.\n");
return 1; return 1;

View File

@ -75,7 +75,7 @@ main(int argc, char **argv)
// init slaves // init slaves
// //
frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S; frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S;
frame->address = 0xFD; frame->address = MBUS_ADDRESS_NETWORK_LAYER;
if (mbus_send_frame(handle, frame) == -1) if (mbus_send_frame(handle, frame) == -1)
{ {
@ -88,7 +88,7 @@ main(int argc, char **argv)
sleep(1); sleep(1);
frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S; frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S;
frame->address = 0xFF; frame->address = MBUS_ADDRESS_BROADCAST_NOREPLY;
if (mbus_send_frame(handle, frame) == -1) if (mbus_send_frame(handle, frame) == -1)
{ {