added a debug/verbose flag to the primary address scan utils

This commit is contained in:
Robert Johansson
2012-05-13 16:34:34 +09:00
parent 726f837d2d
commit dadf3b4823
2 changed files with 51 additions and 9 deletions

View File

@ -26,27 +26,44 @@ main(int argc, char **argv)
{
mbus_handle *handle;
char *host;
int port, address;
int port, address, debug = 0;
if (argc != 3)
if (argc == 3)
{
printf("usage: %s host port\n", argv[0]);
host = argv[1];
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;
}
host = argv[1];
port = atoi(argv[2]);
if ((handle = mbus_connect_tcp(host, port)) == NULL)
{
printf("Scan failed: Could not setup connection to M-bus gateway: %s\n", mbus_error_str());
return 1;
}
if (debug)
printf("Scanning primary addresses:\n");
for (address = 0; address < 254; address++)
{
mbus_frame reply;
if (debug)
{
printf("%d ", address);
fflush(stdout);
}
if (mbus_send_ping_frame(handle, address) == -1)
{
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 (debug)
printf("\n");
printf("Found a M-Bus device at address %d\n", address);
}
}