mbus_connect() and mbus_disconnect() return 0 on success and -1 otherwise
This commit is contained in:
parent
5f9052b284
commit
b95f29fcc8
@ -76,7 +76,7 @@ main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mbus_connect(handle))
|
if (mbus_connect(handle) == -1)
|
||||||
{
|
{
|
||||||
printf("Failed to setup connection to M-bus gateway\n");
|
printf("Failed to setup connection to M-bus gateway\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -68,7 +68,7 @@ main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mbus_connect(handle))
|
if (mbus_connect(handle) == -1)
|
||||||
{
|
{
|
||||||
printf("Failed to setup connection to M-bus gateway\n");
|
printf("Failed to setup connection to M-bus gateway\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -59,7 +59,7 @@ main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mbus_connect(handle))
|
if (mbus_connect(handle) == -1)
|
||||||
{
|
{
|
||||||
printf("Failed to setup connection to M-bus gateway\n");
|
printf("Failed to setup connection to M-bus gateway\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -58,7 +58,7 @@ main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mbus_connect(handle))
|
if (mbus_connect(handle) == -1)
|
||||||
{
|
{
|
||||||
printf("Failed to setup connection to M-bus gateway\n");
|
printf("Failed to setup connection to M-bus gateway\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -68,7 +68,7 @@ main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mbus_connect(handle))
|
if (mbus_connect(handle) == -1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to setup connection to M-bus gateway\n");
|
fprintf(stderr, "Failed to setup connection to M-bus gateway\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -68,7 +68,7 @@ main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mbus_connect(handle))
|
if (mbus_connect(handle) == -1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to setup connection to M-bus gateway\n");
|
fprintf(stderr, "Failed to setup connection to M-bus gateway\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -63,7 +63,7 @@ main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mbus_connect(handle))
|
if (mbus_connect(handle) == -1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to setup connection to M-bus gateway\n");
|
fprintf(stderr, "Failed to setup connection to M-bus gateway\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -57,7 +57,7 @@ main(int argc, char **argv)
|
|||||||
return 1;
|
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());
|
printf("Scan failed: Could not setup connection to M-bus gateway: %s\n", mbus_error_str());
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -51,7 +51,7 @@ main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mbus_connect(handle))
|
if (mbus_connect(handle) == -1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to setup connection to M-bus gateway\n");
|
fprintf(stderr, "Failed to setup connection to M-bus gateway\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -1408,7 +1408,7 @@ mbus_connect(mbus_handle * handle)
|
|||||||
if (handle == NULL)
|
if (handle == NULL)
|
||||||
{
|
{
|
||||||
MBUS_ERROR("%s: Invalid M-Bus handle for disconnect.\n", __PRETTY_FUNCTION__);
|
MBUS_ERROR("%s: Invalid M-Bus handle for disconnect.\n", __PRETTY_FUNCTION__);
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return handle->open(handle);
|
return handle->open(handle);
|
||||||
@ -1420,7 +1420,7 @@ mbus_disconnect(mbus_handle * handle)
|
|||||||
if (handle == NULL)
|
if (handle == NULL)
|
||||||
{
|
{
|
||||||
MBUS_ERROR("%s: Invalid M-Bus handle for disconnect.\n", __PRETTY_FUNCTION__);
|
MBUS_ERROR("%s: Invalid M-Bus handle for disconnect.\n", __PRETTY_FUNCTION__);
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return handle->close(handle);
|
return handle->close(handle);
|
||||||
|
@ -37,11 +37,11 @@ mbus_serial_connect(mbus_handle *handle)
|
|||||||
struct termios *term;
|
struct termios *term;
|
||||||
|
|
||||||
if (handle == NULL)
|
if (handle == NULL)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
serial_data = (mbus_serial_data *) handle->auxdata;
|
serial_data = (mbus_serial_data *) handle->auxdata;
|
||||||
if (serial_data == NULL || serial_data->device == NULL)
|
if (serial_data == NULL || serial_data->device == NULL)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
device = serial_data->device;
|
device = serial_data->device;
|
||||||
term = &(serial_data->t);
|
term = &(serial_data->t);
|
||||||
@ -53,7 +53,7 @@ mbus_serial_connect(mbus_handle *handle)
|
|||||||
if ((handle->fd = open(device, O_RDWR | O_NOCTTY)) < 0)
|
if ((handle->fd = open(device, O_RDWR | O_NOCTTY)) < 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s: failed to open tty.", __PRETTY_FUNCTION__);
|
fprintf(stderr, "%s: failed to open tty.", __PRETTY_FUNCTION__);
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(term, 0, sizeof(*term));
|
memset(term, 0, sizeof(*term));
|
||||||
@ -88,7 +88,7 @@ mbus_serial_connect(mbus_handle *handle)
|
|||||||
|
|
||||||
tcsetattr(handle->fd, TCSANOW, term);
|
tcsetattr(handle->fd, TCSANOW, term);
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
@ -41,11 +41,11 @@ mbus_tcp_connect(mbus_handle *handle)
|
|||||||
int port;
|
int port;
|
||||||
|
|
||||||
if (handle == NULL)
|
if (handle == NULL)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
tcp_data = (mbus_tcp_data *) handle->auxdata;
|
tcp_data = (mbus_tcp_data *) handle->auxdata;
|
||||||
if (tcp_data == NULL || tcp_data->host == NULL)
|
if (tcp_data == NULL || tcp_data->host == NULL)
|
||||||
return 0;
|
return -1;
|
||||||
|
|
||||||
host = tcp_data->host;
|
host = tcp_data->host;
|
||||||
port = tcp_data->port;
|
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__);
|
snprintf(error_str, sizeof(error_str), "%s: failed to setup a socket.", __PRETTY_FUNCTION__);
|
||||||
mbus_error_str_set(error_str);
|
mbus_error_str_set(error_str);
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
s.sin_family = AF_INET;
|
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);
|
snprintf(error_str, sizeof(error_str), "%s: unknown host: %s", __PRETTY_FUNCTION__, host);
|
||||||
mbus_error_str_set(error_str);
|
mbus_error_str_set(error_str);
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy((void *)(&s.sin_addr), (void *)(host_addr->h_addr), host_addr->h_length);
|
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);
|
snprintf(error_str, sizeof(error_str), "%s: Failed to establish connection to %s:%d", __PRETTY_FUNCTION__, host, port);
|
||||||
mbus_error_str_set(error_str);
|
mbus_error_str_set(error_str);
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set a timeout
|
// 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_SNDTIMEO, &time_out, sizeof(time_out));
|
||||||
setsockopt(handle->fd, SOL_SOCKET, SO_RCVTIMEO, &time_out, sizeof(time_out));
|
setsockopt(handle->fd, SOL_SOCKET, SO_RCVTIMEO, &time_out, sizeof(time_out));
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user