Skip to content

Commit

Permalink
add optional -r flag to reset device to mbus-serial-request-data-mult…
Browse files Browse the repository at this point in the history
…i-reply
  • Loading branch information
arska committed Feb 5, 2016
1 parent 3d015fb commit 085d981
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions bin/mbus-serial-request-data-multi-reply.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <mbus/mbus.h>

static int debug = 0;
static int reset = 0;

// Default value for the maximum number of frames
#define MAXFRAMES 16
Expand All @@ -28,6 +29,7 @@ parse_abort(char **argv)
fprintf(stderr, " optional flag -d for debug printout\n");
fprintf(stderr, " optional flag -b for selecting baudrate\n");
fprintf(stderr, " optional flag -f for selecting the maximal number of frames\n");
fprintf(stderr, " optional flag -r to reset (SND_NKE) the device before querying. Silenty ignored for secondary addresses.\n");
exit(1);
}

Expand All @@ -53,6 +55,10 @@ main(int argc, char **argv)
{
debug = 1;
}
else if (strcmp(argv[c], "-r") == 0)
{
reset = 1;
}
else if (strcmp(argv[c], "-b") == 0)
{
c++;
Expand Down Expand Up @@ -147,6 +153,19 @@ main(int argc, char **argv)
{
// primary addressing
address = atoi(addr_str);
if (reset) {
// send a reset SND_NKE to the device before requesting data
// this does not make sense for devices that are accessed by secondary addressing
// as the reset de-selects the device
if (mbus_init_slave(handle,address,debug) == 0)
{
fprintf(stderr,"Failed to init slave.\n");
mbus_disconnect(handle);
mbus_context_free(handle);
mbus_frame_free(reply.next);
return 1;
}
}
}

// instead of the send and recv, use this sendrecv function that
Expand Down

0 comments on commit 085d981

Please sign in to comment.