Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
6b2d43617f
@ -104,10 +104,10 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
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)
|
||||
printf("%s: debug: sending init frame\n", __PRETTY_FUNCTION__);
|
||||
printf("%s: debug: sending init frame #1\n", __PRETTY_FUNCTION__);
|
||||
|
||||
if (mbus_send_frame(handle, frame) == -1)
|
||||
{
|
||||
@ -116,7 +116,26 @@ main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
mbus_recv_frame(handle, &reply);
|
||||
while (mbus_recv_frame(handle, &reply) != -1);
|
||||
|
||||
//
|
||||
// resend SND_NKE, maybe the first get lost
|
||||
//
|
||||
|
||||
frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S;
|
||||
frame->address = MBUS_ADDRESS_NETWORK_LAYER;
|
||||
|
||||
if (debug)
|
||||
printf("%s: debug: sending init frame #2\n", __PRETTY_FUNCTION__);
|
||||
|
||||
if (mbus_send_frame(handle, frame) == -1)
|
||||
{
|
||||
fprintf(stderr, "Failed to send mbus frame.\n");
|
||||
mbus_frame_free(frame);
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (mbus_recv_frame(handle, &reply) != -1);
|
||||
|
||||
if (strlen(addr_str) == 16)
|
||||
{
|
||||
@ -153,7 +172,7 @@ main(int argc, char **argv)
|
||||
|
||||
// instead of the send and recv, use this sendrecv function that
|
||||
// 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");
|
||||
return 1;
|
||||
|
@ -133,7 +133,7 @@ main(int argc, char **argv)
|
||||
// init slaves
|
||||
//
|
||||
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)
|
||||
{
|
||||
@ -145,7 +145,7 @@ main(int argc, char **argv)
|
||||
(void) mbus_recv_frame(handle, &reply);
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -136,7 +136,7 @@ main(int argc, char **argv)
|
||||
|
||||
// instead of the send and recv, use this sendrecv function that
|
||||
// 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");
|
||||
return 1;
|
||||
|
@ -81,7 +81,7 @@ main(int argc, char **argv)
|
||||
// init slaves
|
||||
//
|
||||
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)
|
||||
{
|
||||
@ -94,7 +94,7 @@ main(int argc, char **argv)
|
||||
sleep(1);
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -1437,6 +1437,12 @@ mbus_recv_frame(mbus_handle * handle, mbus_frame *frame)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (frame == NULL)
|
||||
{
|
||||
MBUS_ERROR("%s: Invalid frame.\n", __PRETTY_FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
result = handle->recv(handle, frame);
|
||||
|
||||
if (frame != NULL)
|
||||
@ -1645,6 +1651,8 @@ mbus_sendrecv_request(mbus_handle *handle, int address, mbus_frame *reply, int m
|
||||
//
|
||||
next_frame = reply;
|
||||
|
||||
memset((void *)&reply_data, 0, sizeof(mbus_frame_data));
|
||||
|
||||
while (more_frames)
|
||||
{
|
||||
frame_count++;
|
||||
|
Loading…
x
Reference in New Issue
Block a user