Extended mbus_recv_frame() error codes, improved collision handling

- handling TCP connection reset and read(2) timeout
This commit is contained in:
jakubovsky
2012-07-03 14:35:07 +02:00
parent 82aec2ff97
commit 5d079254cc
10 changed files with 78 additions and 82 deletions

2
bin/mbus-serial-request-data.c Normal file → Executable file
View File

@ -126,7 +126,7 @@ main(int argc, char **argv)
}
}
if (mbus_recv_frame(handle, &reply) == -1)
if (mbus_recv_frame(handle, &reply) != 0)
{
fprintf(stderr, "Failed to receive M-Bus response frame.\n");
return 1;

13
bin/mbus-serial-scan.c Normal file → Executable file
View File

@ -97,7 +97,7 @@ main(int argc, char **argv)
ret = mbus_recv_frame(handle, &reply);
if (ret == -1)
if (ret == -3)
{
continue;
}
@ -108,22 +108,15 @@ main(int argc, char **argv)
if (ret == -2)
{
/* check for more data (collision) */
while (mbus_recv_frame(handle, &reply) != -1);
mbus_recv_frame_dummy(handle);
printf("Collision at address %d\n", address);
continue;
}
if (mbus_frame_type(&reply) == MBUS_FRAME_TYPE_ACK)
{
/* check for more data (collision) */
while (mbus_recv_frame(handle, &reply) != -1)
{
ret = -2;
}
if (ret == -2)
if (mbus_recv_frame_dummy(handle))
{
printf("Collision at address %d\n", address);

4
bin/mbus-serial-select-secondary.c Normal file → Executable file
View File

@ -73,7 +73,7 @@ main(int argc, char **argv)
ret = mbus_recv_frame(handle, &reply);
if (ret == -1)
if (ret == -3)
{
printf("No reply from device with secondary address %s: %s\n", argv[2], mbus_error_str());
return 1;
@ -93,7 +93,7 @@ main(int argc, char **argv)
return 1;
}
if (mbus_recv_frame(handle, &reply) == -1)
if (mbus_recv_frame(handle, &reply) != 0)
{
printf("Failed to recieve reply from selected secondary device: %s\n", mbus_error_str());
return 1;

2
bin/mbus-serial-switch-baudrate.c Normal file → Executable file
View File

@ -72,7 +72,7 @@ main(int argc, char **argv)
ret = mbus_recv_frame(handle, &reply);
if (ret == -1)
if (ret == -3)
{
printf("No reply from device\n");
return 1;

6
bin/mbus-tcp-request-data.c Normal file → Executable file
View File

@ -111,11 +111,11 @@ main(int argc, char **argv)
}
}
if (mbus_recv_frame(handle, &reply) == -1)
if (mbus_recv_frame(handle, &reply) != 0)
{
fprintf(stderr, "Failed to receive M-Bus response frame.\n");
fprintf(stderr, "Failed to receive M-Bus response frame: %s\n", mbus_error_str());
return 1;
}
}
//
// parse data and print in XML format

17
bin/mbus-tcp-scan.c Normal file → Executable file
View File

@ -17,7 +17,6 @@
#include <stdio.h>
#include <mbus/mbus.h>
//------------------------------------------------------------------------------
// Execution starts here:
//------------------------------------------------------------------------------
@ -81,7 +80,7 @@ main(int argc, char **argv)
ret = mbus_recv_frame(handle, &reply);
if (ret == -1)
if (ret == -3)
{
continue;
}
@ -92,28 +91,20 @@ main(int argc, char **argv)
if (ret == -2)
{
/* check for more data (collision) */
while (mbus_recv_frame(handle, &reply) != -1);
mbus_recv_frame_dummy(handle);
printf("Collision at address %d\n", address);
continue;
}
if (mbus_frame_type(&reply) == MBUS_FRAME_TYPE_ACK)
{
/* check for more data (collision) */
while (mbus_recv_frame(handle, &reply) != -1)
{
ret = -2;
}
if (ret == -2)
if (mbus_recv_frame_dummy(handle))
{
printf("Collision at address %d\n", address);
continue;
}
printf("Found a M-Bus device at address %d\n", address);
}
}

4
bin/mbus-tcp-select-secondary.c Normal file → Executable file
View File

@ -59,7 +59,7 @@ main(int argc, char **argv)
ret = mbus_recv_frame(handle, &reply);
if (ret == -1)
if (ret == -3)
{
printf("No reply from device with secondary address %s: %s\n", argv[3], mbus_error_str());
return 1;
@ -79,7 +79,7 @@ main(int argc, char **argv)
return 1;
}
if (mbus_recv_frame(handle, &reply) == -1)
if (mbus_recv_frame(handle, &reply) != 0)
{
printf("Failed to recieve reply from selected secondary device: %s\n", mbus_error_str());
return 1;