Fixed primary address scan

- scan only normal addresses (0-250)
- show collisions in scan result
This commit is contained in:
Stefan Wahren
2012-05-20 03:35:04 +02:00
parent eb96afcd7c
commit 1fb68d1e05

View File

@ -28,6 +28,7 @@ main(int argc, char **argv)
mbus_handle *handle; mbus_handle *handle;
char *device; char *device;
int address, baudrate = 9600; int address, baudrate = 9600;
int ret;
if (argc == 2) if (argc == 2)
{ {
@ -76,7 +77,7 @@ main(int argc, char **argv)
if (debug) if (debug)
printf("Scanning primary addresses:\n"); printf("Scanning primary addresses:\n");
for (address = 0; address < 254; address++) for (address = 0; address <= 250; address++)
{ {
mbus_frame reply; mbus_frame reply;
@ -94,15 +95,40 @@ main(int argc, char **argv)
return 1; return 1;
} }
if (mbus_recv_frame(handle, &reply) == -1) ret = mbus_recv_frame(handle, &reply);
if (ret == -1)
{ {
continue; continue;
} }
if (debug)
printf("\n");
if (ret == -2)
{
/* check for more data (collision) */
while (mbus_recv_frame(handle, &reply) != -1);
printf("Collision at address %d\n", address);
continue;
}
if (mbus_frame_type(&reply) == MBUS_FRAME_TYPE_ACK) if (mbus_frame_type(&reply) == MBUS_FRAME_TYPE_ACK)
{ {
if (debug) /* check for more data (collision) */
printf("\n"); while (mbus_recv_frame(handle, &reply) != -1)
{
ret = -2;
}
if (ret == -2)
{
printf("Collision at address %d\n", address);
continue;
}
printf("Found a M-Bus device at address %d\n", address); printf("Found a M-Bus device at address %d\n", address);
} }