Fixed primary address scan
- scan only normal addresses (0-250) - show collisions in scan result
This commit is contained in:
parent
eb96afcd7c
commit
1fb68d1e05
@ -28,6 +28,7 @@ main(int argc, char **argv)
|
||||
mbus_handle *handle;
|
||||
char *device;
|
||||
int address, baudrate = 9600;
|
||||
int ret;
|
||||
|
||||
if (argc == 2)
|
||||
{
|
||||
@ -76,7 +77,7 @@ main(int argc, char **argv)
|
||||
if (debug)
|
||||
printf("Scanning primary addresses:\n");
|
||||
|
||||
for (address = 0; address < 254; address++)
|
||||
for (address = 0; address <= 250; address++)
|
||||
{
|
||||
mbus_frame reply;
|
||||
|
||||
@ -93,16 +94,41 @@ main(int argc, char **argv)
|
||||
printf("Scan failed. Could not send ping frame: %s\n", mbus_error_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
ret = mbus_recv_frame(handle, &reply);
|
||||
|
||||
if (mbus_recv_frame(handle, &reply) == -1)
|
||||
if (ret == -1)
|
||||
{
|
||||
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 (debug)
|
||||
printf("\n");
|
||||
/* check for more data (collision) */
|
||||
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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user