Added frame option to mbus-serial-request-data-multi-reply
Improved parsing
This commit is contained in:
parent
158208c2b1
commit
a61714d26d
@ -15,6 +15,8 @@
|
||||
|
||||
static int debug = 0;
|
||||
|
||||
// Default value for the maximum number of frames
|
||||
#define MAXFRAMES 16
|
||||
//
|
||||
// init slave to get really the beginning of the records
|
||||
//
|
||||
@ -44,6 +46,19 @@ init_slaves(mbus_handle *handle)
|
||||
return 1;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Wrapper for argument parsing errors
|
||||
//------------------------------------------------------------------------------
|
||||
int
|
||||
parse_abort(char **argv)
|
||||
{
|
||||
fprintf(stderr, "usage: %s [-d] [-b BAUDRATE] [-f FRAMES] device mbus-address\n", argv[0]);
|
||||
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");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Scan for devices using secondary addressing.
|
||||
//------------------------------------------------------------------------------
|
||||
@ -57,41 +72,39 @@ main(int argc, char **argv)
|
||||
char *device, *addr_str, *xml_result;
|
||||
int address;
|
||||
long baudrate = 9600;
|
||||
int maxframes = MAXFRAMES;
|
||||
|
||||
memset((void *)&reply, 0, sizeof(mbus_frame));
|
||||
memset((void *)&reply_data, 0, sizeof(mbus_frame_data));
|
||||
|
||||
if (argc == 3)
|
||||
int c;
|
||||
for (c=1; c<argc-2; c++)
|
||||
{
|
||||
device = argv[1];
|
||||
addr_str = argv[2];
|
||||
}
|
||||
else if (argc == 4 && strcmp(argv[1], "-d") == 0)
|
||||
if (strcmp(argv[c], "-d") == 0)
|
||||
{
|
||||
device = argv[2];
|
||||
addr_str = argv[3];
|
||||
debug = 1;
|
||||
}
|
||||
else if (argc == 5 && strcmp(argv[1], "-b") == 0)
|
||||
else if (strcmp(argv[c], "-b") == 0)
|
||||
{
|
||||
baudrate = atol(argv[2]);
|
||||
device = argv[3];
|
||||
addr_str = argv[4];
|
||||
c++;
|
||||
baudrate = atol(argv[c]);
|
||||
}
|
||||
else if (argc == 6 && strcmp(argv[1], "-d") == 0 && strcmp(argv[2], "-b") == 0)
|
||||
else if (strcmp(argv[c], "-f") == 0)
|
||||
{
|
||||
baudrate = atol(argv[3]);
|
||||
device = argv[4];
|
||||
addr_str = argv[5];
|
||||
debug = 1;
|
||||
c++;
|
||||
maxframes = atoi(argv[c]);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "usage: %s [-d] [-b BAUDRATE] device mbus-address\n", argv[0]);
|
||||
fprintf(stderr, " optional flag -d for debug printout\n");
|
||||
fprintf(stderr, " optional flag -b for selecting baudrate\n");
|
||||
return 0;
|
||||
parse_abort(argv);
|
||||
}
|
||||
}
|
||||
if (c > argc-2)
|
||||
{
|
||||
parse_abort(argv);
|
||||
}
|
||||
device = argv[c];
|
||||
addr_str = argv[c+1];
|
||||
|
||||
|
||||
if (debug)
|
||||
{
|
||||
@ -157,7 +170,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) != 0)
|
||||
if (mbus_sendrecv_request(handle, address, &reply, maxframes) != 0)
|
||||
{
|
||||
fprintf(stderr, "Failed to send/receive M-Bus request.\n");
|
||||
return 1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user