mbus_connect() and mbus_disconnect() return 0 on success and -1 otherwise

This commit is contained in:
jakubovsky 2012-07-09 12:33:32 +02:00
parent 5f9052b284
commit b95f29fcc8
12 changed files with 21 additions and 21 deletions

View File

@ -76,7 +76,7 @@ main(int argc, char **argv)
return 1;
}
if (!mbus_connect(handle))
if (mbus_connect(handle) == -1)
{
printf("Failed to setup connection to M-bus gateway\n");
return 1;

View File

@ -68,7 +68,7 @@ main(int argc, char **argv)
return 1;
}
if (!mbus_connect(handle))
if (mbus_connect(handle) == -1)
{
printf("Failed to setup connection to M-bus gateway\n");
return 1;

View File

@ -59,7 +59,7 @@ main(int argc, char **argv)
return 1;
}
if (!mbus_connect(handle))
if (mbus_connect(handle) == -1)
{
printf("Failed to setup connection to M-bus gateway\n");
return 1;

View File

@ -58,7 +58,7 @@ main(int argc, char **argv)
return 1;
}
if (!mbus_connect(handle))
if (mbus_connect(handle) == -1)
{
printf("Failed to setup connection to M-bus gateway\n");
return 1;

View File

@ -68,7 +68,7 @@ main(int argc, char **argv)
return 1;
}
if (!mbus_connect(handle))
if (mbus_connect(handle) == -1)
{
fprintf(stderr, "Failed to setup connection to M-bus gateway\n");
return 1;

View File

@ -68,7 +68,7 @@ main(int argc, char **argv)
return 1;
}
if (!mbus_connect(handle))
if (mbus_connect(handle) == -1)
{
fprintf(stderr, "Failed to setup connection to M-bus gateway\n");
return 1;

View File

@ -63,7 +63,7 @@ main(int argc, char **argv)
return 1;
}
if (!mbus_connect(handle))
if (mbus_connect(handle) == -1)
{
fprintf(stderr, "Failed to setup connection to M-bus gateway\n");
return 1;

View File

@ -57,7 +57,7 @@ main(int argc, char **argv)
return 1;
}
if (!mbus_connect(handle))
if (mbus_connect(handle) == -1)
{
printf("Scan failed: Could not setup connection to M-bus gateway: %s\n", mbus_error_str());
return 1;

View File

@ -51,7 +51,7 @@ main(int argc, char **argv)
return 1;
}
if (!mbus_connect(handle))
if (mbus_connect(handle) == -1)
{
fprintf(stderr, "Failed to setup connection to M-bus gateway\n");
return 1;

View File

@ -1408,7 +1408,7 @@ mbus_connect(mbus_handle * handle)
if (handle == NULL)
{
MBUS_ERROR("%s: Invalid M-Bus handle for disconnect.\n", __PRETTY_FUNCTION__);
return 0;
return -1;
}
return handle->open(handle);
@ -1420,7 +1420,7 @@ mbus_disconnect(mbus_handle * handle)
if (handle == NULL)
{
MBUS_ERROR("%s: Invalid M-Bus handle for disconnect.\n", __PRETTY_FUNCTION__);
return 0;
return -1;
}
return handle->close(handle);

View File

@ -37,11 +37,11 @@ mbus_serial_connect(mbus_handle *handle)
struct termios *term;
if (handle == NULL)
return 0;
return -1;
serial_data = (mbus_serial_data *) handle->auxdata;
if (serial_data == NULL || serial_data->device == NULL)
return 0;
return -1;
device = serial_data->device;
term = &(serial_data->t);
@ -53,7 +53,7 @@ mbus_serial_connect(mbus_handle *handle)
if ((handle->fd = open(device, O_RDWR | O_NOCTTY)) < 0)
{
fprintf(stderr, "%s: failed to open tty.", __PRETTY_FUNCTION__);
return 0;
return -1;
}
memset(term, 0, sizeof(*term));
@ -88,7 +88,7 @@ mbus_serial_connect(mbus_handle *handle)
tcsetattr(handle->fd, TCSANOW, term);
return 1;
return 0;
}
//------------------------------------------------------------------------------

View File

@ -41,11 +41,11 @@ mbus_tcp_connect(mbus_handle *handle)
int port;
if (handle == NULL)
return 0;
return -1;
tcp_data = (mbus_tcp_data *) handle->auxdata;
if (tcp_data == NULL || tcp_data->host == NULL)
return 0;
return -1;
host = tcp_data->host;
port = tcp_data->port;
@ -57,7 +57,7 @@ mbus_tcp_connect(mbus_handle *handle)
{
snprintf(error_str, sizeof(error_str), "%s: failed to setup a socket.", __PRETTY_FUNCTION__);
mbus_error_str_set(error_str);
return 0;
return -1;
}
s.sin_family = AF_INET;
@ -68,7 +68,7 @@ mbus_tcp_connect(mbus_handle *handle)
{
snprintf(error_str, sizeof(error_str), "%s: unknown host: %s", __PRETTY_FUNCTION__, host);
mbus_error_str_set(error_str);
return 0;
return -1;
}
memcpy((void *)(&s.sin_addr), (void *)(host_addr->h_addr), host_addr->h_length);
@ -77,7 +77,7 @@ mbus_tcp_connect(mbus_handle *handle)
{
snprintf(error_str, sizeof(error_str), "%s: Failed to establish connection to %s:%d", __PRETTY_FUNCTION__, host, port);
mbus_error_str_set(error_str);
return 0;
return -1;
}
// Set a timeout
@ -86,7 +86,7 @@ mbus_tcp_connect(mbus_handle *handle)
setsockopt(handle->fd, SOL_SOCKET, SO_SNDTIMEO, &time_out, sizeof(time_out));
setsockopt(handle->fd, SOL_SOCKET, SO_RCVTIMEO, &time_out, sizeof(time_out));
return 1;
return 0;
}
void