From 1fa5e202fb5af6c343d0597693185aa406dda7a9 Mon Sep 17 00:00:00 2001 From: Stefan Wahren Date: Wed, 4 Jul 2012 21:14:00 +0200 Subject: [PATCH] Fix problem with multiple selected devices (secondary address) resend --- bin/mbus-serial-request-data-multi-reply.c | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/bin/mbus-serial-request-data-multi-reply.c b/bin/mbus-serial-request-data-multi-reply.c index 5666527..36831bc 100644 --- a/bin/mbus-serial-request-data-multi-reply.c +++ b/bin/mbus-serial-request-data-multi-reply.c @@ -101,7 +101,7 @@ main(int argc, char **argv) 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) { @@ -110,8 +110,27 @@ 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) { // secondary addressing