print all errors on stderr in all binaries
This commit is contained in:
parent
ea0c6c3455
commit
f6601ca40f
@ -106,13 +106,13 @@ main(int argc, char **argv)
|
||||
|
||||
if (mbus_connect(handle) == -1)
|
||||
{
|
||||
printf("Failed to setup connection to M-bus gateway\n");
|
||||
fprintf(stderr,"Failed to setup connection to M-bus gateway\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mbus_serial_set_baudrate(handle, baudrate) == -1)
|
||||
{
|
||||
printf("Failed to set baud rate.\n");
|
||||
fprintf(stderr,"Failed to set baud rate.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -77,13 +77,13 @@ main(int argc, char **argv)
|
||||
|
||||
if (mbus_connect(handle) == -1)
|
||||
{
|
||||
printf("Failed to setup connection to M-bus gateway\n");
|
||||
fprintf(stderr,"Failed to setup connection to M-bus gateway\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mbus_serial_set_baudrate(handle, baudrate) == -1)
|
||||
{
|
||||
printf("Failed to set baud rate.\n");
|
||||
fprintf(stderr,"Failed to set baud rate.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ main(int argc, char **argv)
|
||||
|
||||
if (mbus_connect(handle) == -1)
|
||||
{
|
||||
printf("Failed to setup connection to M-bus gateway\n");
|
||||
fprintf(stderr,"Failed to setup connection to M-bus gateway\n");
|
||||
free(addr_mask);
|
||||
return 1;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ int ping_address(mbus_handle *handle, mbus_frame *reply, int address)
|
||||
|
||||
if (mbus_send_ping_frame(handle, address, 0) == -1)
|
||||
{
|
||||
printf("Scan failed. Could not send ping frame: %s\n", mbus_error_str());
|
||||
fprintf(stderr,"Scan failed. Could not send ping frame: %s\n", mbus_error_str());
|
||||
return MBUS_RECV_RESULT_ERROR;
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("usage: %s [-d] [-b BAUDRATE] [-r RETRIES] device\n", argv[0]);
|
||||
fprintf(stderr,"usage: %s [-d] [-b BAUDRATE] [-r RETRIES] device\n", argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -115,25 +115,25 @@ main(int argc, char **argv)
|
||||
|
||||
if ((handle = mbus_context_serial(device)) == NULL)
|
||||
{
|
||||
printf("Scan failed: Could not initialize M-Bus context: %s\n", mbus_error_str());
|
||||
fprintf(stderr,"Scan failed: Could not initialize M-Bus context: %s\n", mbus_error_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mbus_connect(handle) == -1)
|
||||
{
|
||||
printf("Scan failed: Could not setup connection to M-bus gateway: %s\n", mbus_error_str());
|
||||
fprintf(stderr,"Scan failed: Could not setup connection to M-bus gateway: %s\n", mbus_error_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mbus_context_set_option(handle, MBUS_OPTION_MAX_RETRY, retries) == -1)
|
||||
{
|
||||
printf("Failed to set retry count\n");
|
||||
fprintf(stderr,"Failed to set retry count\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mbus_serial_set_baudrate(handle, baudrate) == -1)
|
||||
{
|
||||
printf("Failed to set baud rate.\n");
|
||||
fprintf(stderr,"Failed to set baud rate.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ main(int argc, char **argv)
|
||||
|
||||
if (mbus_is_secondary_address(addr) == 0)
|
||||
{
|
||||
printf("Misformatted secondary address. Must be 16 character HEX number.\n");
|
||||
fprintf(stderr,"Misformatted secondary address. Must be 16 character HEX number.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -63,19 +63,19 @@ main(int argc, char **argv)
|
||||
|
||||
if (mbus_connect(handle) == -1)
|
||||
{
|
||||
printf("Failed to setup connection to M-bus gateway\n");
|
||||
fprintf(stderr,"Failed to setup connection to M-bus gateway\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mbus_serial_set_baudrate(handle, baudrate) == -1)
|
||||
{
|
||||
printf("Failed to set baud rate.\n");
|
||||
fprintf(stderr,"Failed to set baud rate.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mbus_send_select_frame(handle, addr) == -1)
|
||||
{
|
||||
printf("Failed to send selection frame: %s\n", mbus_error_str());
|
||||
fprintf(stderr,"Failed to send selection frame: %s\n", mbus_error_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -83,13 +83,13 @@ main(int argc, char **argv)
|
||||
|
||||
if (ret == MBUS_RECV_RESULT_TIMEOUT)
|
||||
{
|
||||
printf("No reply from device with secondary address %s: %s\n", argv[2], mbus_error_str());
|
||||
fprintf(stderr,"No reply from device with secondary address %s: %s\n", argv[2], mbus_error_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (ret == MBUS_RECV_RESULT_INVALID)
|
||||
{
|
||||
printf("Invalid reply from %s: The address address probably match more than one device: %s\n", argv[2], mbus_error_str());
|
||||
fprintf(stderr,"Invalid reply from %s: The address address probably match more than one device: %s\n", argv[2], mbus_error_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -97,13 +97,13 @@ main(int argc, char **argv)
|
||||
{
|
||||
if (mbus_send_request_frame(handle, MBUS_ADDRESS_NETWORK_LAYER) == -1)
|
||||
{
|
||||
printf("Failed to send request to selected secondary device: %s\n", mbus_error_str());
|
||||
fprintf(stderr,"Failed to send request to selected secondary device: %s\n", mbus_error_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mbus_recv_frame(handle, &reply) != MBUS_RECV_RESULT_OK)
|
||||
{
|
||||
printf("Failed to recieve reply from selected secondary device: %s\n", mbus_error_str());
|
||||
fprintf(stderr,"Failed to recieve reply from selected secondary device: %s\n", mbus_error_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -115,7 +115,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unknown reply:\n");
|
||||
fprintf(stderr,"Unknown reply:\n");
|
||||
mbus_frame_print(&reply);
|
||||
}
|
||||
|
||||
|
@ -56,19 +56,19 @@ main(int argc, char **argv)
|
||||
|
||||
if (mbus_connect(handle) == -1)
|
||||
{
|
||||
printf("Failed to setup connection to M-bus gateway\n");
|
||||
fprintf(stderr,"Failed to setup connection to M-bus gateway\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mbus_serial_set_baudrate(handle, source_baudrate) == -1)
|
||||
{
|
||||
printf("Failed to set baud rate.\n");
|
||||
fprintf(stderr,"Failed to set baud rate.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mbus_send_switch_baudrate_frame(handle, address, target_baudrate) == -1)
|
||||
{
|
||||
printf("Failed to send switch baudrate frame: %s\n", mbus_error_str());
|
||||
fprintf(stderr,"Failed to send switch baudrate frame: %s\n", mbus_error_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -76,12 +76,12 @@ main(int argc, char **argv)
|
||||
|
||||
if (ret == MBUS_RECV_RESULT_TIMEOUT)
|
||||
{
|
||||
printf("No reply from device\n");
|
||||
fprintf(stderr,"No reply from device\n");
|
||||
return 1;
|
||||
}
|
||||
else if (mbus_frame_type(&reply) != MBUS_FRAME_TYPE_ACK)
|
||||
{
|
||||
printf("Unknown reply:\n");
|
||||
fprintf(stderr,"Unknown reply:\n");
|
||||
mbus_frame_print(&reply);
|
||||
}
|
||||
else
|
||||
|
@ -31,7 +31,7 @@ int ping_address(mbus_handle *handle, mbus_frame *reply, int address)
|
||||
|
||||
if (mbus_send_ping_frame(handle, address, 0) == -1)
|
||||
{
|
||||
printf("Scan failed. Could not send ping frame: %s\n", mbus_error_str());
|
||||
fprintf(stderr,"Scan failed. Could not send ping frame: %s\n", mbus_error_str());
|
||||
return MBUS_RECV_RESULT_ERROR;
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("usage: %s [-d] [-r RETRIES] host port\n", argv[0]);
|
||||
fprintf(stderr,"usage: %s [-d] [-r RETRIES] host port\n", argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -95,19 +95,19 @@ main(int argc, char **argv)
|
||||
|
||||
if ((handle = mbus_context_tcp(host, port)) == NULL)
|
||||
{
|
||||
printf("Scan failed: Could not initialize M-Bus context: %s\n", mbus_error_str());
|
||||
fprintf(stderr,"Scan failed: Could not initialize M-Bus context: %s\n", mbus_error_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mbus_connect(handle) == -1)
|
||||
{
|
||||
printf("Scan failed: Could not setup connection to M-bus gateway: %s\n", mbus_error_str());
|
||||
fprintf(stderr,"Scan failed: Could not setup connection to M-bus gateway: %s\n", mbus_error_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mbus_context_set_option(handle, MBUS_OPTION_MAX_RETRY, retries) == -1)
|
||||
{
|
||||
printf("Failed to set retry count\n");
|
||||
fprintf(stderr,"Failed to set retry count\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ main(int argc, char **argv)
|
||||
|
||||
if (argc != 4)
|
||||
{
|
||||
printf("usage: %s host port secondary-mbus-address\n", argv[0]);
|
||||
fprintf(stderr,"usage: %s host port secondary-mbus-address\n", argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ main(int argc, char **argv)
|
||||
|
||||
if (mbus_is_secondary_address(addr) == 0)
|
||||
{
|
||||
printf("Misformatted secondary address. Must be 16 character HEX number.\n");
|
||||
fprintf(stderr,"Misformatted secondary address. Must be 16 character HEX number.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ main(int argc, char **argv)
|
||||
|
||||
if (mbus_send_select_frame(handle, addr) == -1)
|
||||
{
|
||||
printf("Failed to send selection frame: %s\n", mbus_error_str());
|
||||
fprintf(stderr,"Failed to send selection frame: %s\n", mbus_error_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -68,13 +68,13 @@ main(int argc, char **argv)
|
||||
|
||||
if (ret == MBUS_RECV_RESULT_TIMEOUT)
|
||||
{
|
||||
printf("No reply from device with secondary address %s: %s\n", argv[3], mbus_error_str());
|
||||
fprintf(stderr,"No reply from device with secondary address %s: %s\n", argv[3], mbus_error_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (ret == MBUS_RECV_RESULT_INVALID)
|
||||
{
|
||||
printf("Invalid reply from %s: The address address probably match more than one device: %s\n", argv[3], mbus_error_str());
|
||||
fprintf(stderr,"Invalid reply from %s: The address address probably match more than one device: %s\n", argv[3], mbus_error_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -82,13 +82,13 @@ main(int argc, char **argv)
|
||||
{
|
||||
if (mbus_send_request_frame(handle, MBUS_ADDRESS_NETWORK_LAYER) == -1)
|
||||
{
|
||||
printf("Failed to send request to selected secondary device: %s\n", mbus_error_str());
|
||||
fprintf(stderr,"Failed to send request to selected secondary device: %s\n", mbus_error_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mbus_recv_frame(handle, &reply) != MBUS_RECV_RESULT_OK)
|
||||
{
|
||||
printf("Failed to recieve reply from selected secondary device: %s\n", mbus_error_str());
|
||||
fprintf(stderr,"Failed to recieve reply from selected secondary device: %s\n", mbus_error_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Unknown reply:\n");
|
||||
fprintf(stderr,"Unknown reply:\n");
|
||||
mbus_frame_print(&reply);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user