added a debug/verbose flag to the primary address scan utils
This commit is contained in:
@ -25,20 +25,31 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
mbus_handle *handle;
|
mbus_handle *handle;
|
||||||
char *device;
|
char *device;
|
||||||
int address, baudrate = 9600;
|
int address, baudrate = 9600, debug = 0;
|
||||||
|
|
||||||
if (argc == 2)
|
if (argc == 2)
|
||||||
{
|
{
|
||||||
device = argv[1];
|
device = argv[1];
|
||||||
}
|
}
|
||||||
|
else if (argc == 3 && strcmp(argv[1], "-d") == 0)
|
||||||
|
{
|
||||||
|
debug = 1;
|
||||||
|
device = argv[2];
|
||||||
|
}
|
||||||
else if (argc == 4 && strcmp(argv[1], "-b") == 0)
|
else if (argc == 4 && strcmp(argv[1], "-b") == 0)
|
||||||
{
|
{
|
||||||
baudrate = atoi(argv[2]);
|
baudrate = atoi(argv[2]);
|
||||||
device = argv[3];
|
device = argv[3];
|
||||||
}
|
}
|
||||||
|
else if (argc == 5 && strcmp(argv[1], "-d") == 0 && strcmp(argv[2], "-b") == 0)
|
||||||
|
{
|
||||||
|
debug = 1;
|
||||||
|
baudrate = atoi(argv[3]);
|
||||||
|
device = argv[4];
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage: %s [-b BAUDRATE] device\n", argv[0]);
|
fprintf(stderr, "usage: %s [-d] [-b BAUDRATE] device\n", argv[0]);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,6 +65,8 @@ main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (debug)
|
||||||
|
printf("Scanning primary addresses:\n");
|
||||||
|
|
||||||
for (address = 0; address < 254; address++)
|
for (address = 0; address < 254; address++)
|
||||||
{
|
{
|
||||||
@ -61,6 +74,12 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
memset((void *)&reply, 0, sizeof(mbus_frame));
|
memset((void *)&reply, 0, sizeof(mbus_frame));
|
||||||
|
|
||||||
|
if (debug)
|
||||||
|
{
|
||||||
|
printf("%d ", address);
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
|
||||||
if (mbus_send_ping_frame(handle, address) == -1)
|
if (mbus_send_ping_frame(handle, address) == -1)
|
||||||
{
|
{
|
||||||
printf("Scan failed. Could not send ping frame: %s\n", mbus_error_str());
|
printf("Scan failed. Could not send ping frame: %s\n", mbus_error_str());
|
||||||
@ -74,6 +93,9 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
if (mbus_frame_type(&reply) == MBUS_FRAME_TYPE_ACK)
|
if (mbus_frame_type(&reply) == MBUS_FRAME_TYPE_ACK)
|
||||||
{
|
{
|
||||||
|
if (debug)
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
printf("Found a M-Bus device at address %d\n", address);
|
printf("Found a M-Bus device at address %d\n", address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,16 +26,24 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
mbus_handle *handle;
|
mbus_handle *handle;
|
||||||
char *host;
|
char *host;
|
||||||
int port, address;
|
int port, address, debug = 0;
|
||||||
|
|
||||||
if (argc != 3)
|
if (argc == 3)
|
||||||
{
|
{
|
||||||
printf("usage: %s host port\n", argv[0]);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
host = argv[1];
|
host = argv[1];
|
||||||
port = atoi(argv[2]);
|
port = atoi(argv[2]);
|
||||||
|
}
|
||||||
|
else if (argc == 4 && strcmp(argv[1], "-d") == 0)
|
||||||
|
{
|
||||||
|
debug = 1;
|
||||||
|
host = argv[2];
|
||||||
|
port = atoi(argv[3]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("usage: %s [-d] host port\n", argv[0]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if ((handle = mbus_connect_tcp(host, port)) == NULL)
|
if ((handle = mbus_connect_tcp(host, port)) == NULL)
|
||||||
{
|
{
|
||||||
@ -43,10 +51,19 @@ main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (debug)
|
||||||
|
printf("Scanning primary addresses:\n");
|
||||||
|
|
||||||
for (address = 0; address < 254; address++)
|
for (address = 0; address < 254; address++)
|
||||||
{
|
{
|
||||||
mbus_frame reply;
|
mbus_frame reply;
|
||||||
|
|
||||||
|
if (debug)
|
||||||
|
{
|
||||||
|
printf("%d ", address);
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
|
||||||
if (mbus_send_ping_frame(handle, address) == -1)
|
if (mbus_send_ping_frame(handle, address) == -1)
|
||||||
{
|
{
|
||||||
printf("Scan failed. Could not send ping frame: %s\n", mbus_error_str());
|
printf("Scan failed. Could not send ping frame: %s\n", mbus_error_str());
|
||||||
@ -60,6 +77,9 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
if (mbus_frame_type(&reply) == MBUS_FRAME_TYPE_ACK)
|
if (mbus_frame_type(&reply) == MBUS_FRAME_TYPE_ACK)
|
||||||
{
|
{
|
||||||
|
if (debug)
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
printf("Found a M-Bus device at address %d\n", address);
|
printf("Found a M-Bus device at address %d\n", address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user