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;
|
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
|
// init slave to get really the beginning of the records
|
||||||
//
|
//
|
||||||
@ -44,6 +46,19 @@ init_slaves(mbus_handle *handle)
|
|||||||
return 1;
|
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.
|
// Scan for devices using secondary addressing.
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@ -57,41 +72,39 @@ main(int argc, char **argv)
|
|||||||
char *device, *addr_str, *xml_result;
|
char *device, *addr_str, *xml_result;
|
||||||
int address;
|
int address;
|
||||||
long baudrate = 9600;
|
long baudrate = 9600;
|
||||||
|
int maxframes = MAXFRAMES;
|
||||||
|
|
||||||
memset((void *)&reply, 0, sizeof(mbus_frame));
|
memset((void *)&reply, 0, sizeof(mbus_frame));
|
||||||
memset((void *)&reply_data, 0, sizeof(mbus_frame_data));
|
memset((void *)&reply_data, 0, sizeof(mbus_frame_data));
|
||||||
|
int c;
|
||||||
if (argc == 3)
|
for (c=1; c<argc-2; c++)
|
||||||
{
|
{
|
||||||
device = argv[1];
|
if (strcmp(argv[c], "-d") == 0)
|
||||||
addr_str = argv[2];
|
|
||||||
}
|
|
||||||
else if (argc == 4 && strcmp(argv[1], "-d") == 0)
|
|
||||||
{
|
{
|
||||||
device = argv[2];
|
|
||||||
addr_str = argv[3];
|
|
||||||
debug = 1;
|
debug = 1;
|
||||||
}
|
}
|
||||||
else if (argc == 5 && strcmp(argv[1], "-b") == 0)
|
else if (strcmp(argv[c], "-b") == 0)
|
||||||
{
|
{
|
||||||
baudrate = atol(argv[2]);
|
c++;
|
||||||
device = argv[3];
|
baudrate = atol(argv[c]);
|
||||||
addr_str = argv[4];
|
|
||||||
}
|
}
|
||||||
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]);
|
c++;
|
||||||
device = argv[4];
|
maxframes = atoi(argv[c]);
|
||||||
addr_str = argv[5];
|
|
||||||
debug = 1;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage: %s [-d] [-b BAUDRATE] device mbus-address\n", argv[0]);
|
parse_abort(argv);
|
||||||
fprintf(stderr, " optional flag -d for debug printout\n");
|
|
||||||
fprintf(stderr, " optional flag -b for selecting baudrate\n");
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (c > argc-2)
|
||||||
|
{
|
||||||
|
parse_abort(argv);
|
||||||
|
}
|
||||||
|
device = argv[c];
|
||||||
|
addr_str = argv[c+1];
|
||||||
|
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
{
|
{
|
||||||
@ -157,7 +170,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) != 0)
|
if (mbus_sendrecv_request(handle, address, &reply, maxframes) != 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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user