git-svn-id: https://bucket.mit.edu/svn/nilm/acquisition/ethstream@8321 ddd99763-3ecb-0310-9145-efcb8ce7c51ftags/ethstream-1.3
@@ -5,4 +5,6 @@ | |||||
#define CONVERT_VOLTS 1 | #define CONVERT_VOLTS 1 | ||||
#define CONVERT_HEX 2 | #define CONVERT_HEX 2 | ||||
#define TIMEOUT 5 /* Timeout for connect/send/recv, in seconds */ | |||||
#endif | #endif |
@@ -25,8 +25,6 @@ | |||||
#include "netutil.h" | #include "netutil.h" | ||||
#include "ethstream.h" | #include "ethstream.h" | ||||
#define NERDJACK_TIMEOUT 5 /* Timeout for connect/send/recv, in seconds */ | |||||
#define NERD_HEADER_SIZE 8 | #define NERD_HEADER_SIZE 8 | ||||
#define MAX_SOCKETS 32 | #define MAX_SOCKETS 32 | ||||
@@ -312,7 +310,7 @@ int nerdjack_detect(char *ipAddress) | |||||
recvfrom_timeout(receivesock, incomingData, sizeof(incomingData), 0, | recvfrom_timeout(receivesock, incomingData, sizeof(incomingData), 0, | ||||
(struct sockaddr *)&sFromAddr, &lFromLen, | (struct sockaddr *)&sFromAddr, &lFromLen, | ||||
&(struct timeval) { | &(struct timeval) { | ||||
.tv_sec = NERDJACK_TIMEOUT})) { | |||||
.tv_sec = TIMEOUT})) { | |||||
close(receivesock); | close(receivesock); | ||||
return -1; | return -1; | ||||
} | } | ||||
@@ -341,14 +339,14 @@ int nerd_get_version(const char *address) | |||||
/* Send request */ | /* Send request */ | ||||
ret = send_all_timeout(fd_command, "VERS", 4, 0, &(struct timeval) { | ret = send_all_timeout(fd_command, "VERS", 4, 0, &(struct timeval) { | ||||
.tv_sec = NERDJACK_TIMEOUT}); | |||||
.tv_sec = TIMEOUT}); | |||||
if (ret < 0) { | if (ret < 0) { | ||||
verb("short send %d\n", (int)ret); | verb("short send %d\n", (int)ret); | ||||
return -1; | return -1; | ||||
} | } | ||||
ret = recv_all_timeout(fd_command, buf, 200, 0, &(struct timeval) { | ret = recv_all_timeout(fd_command, buf, 200, 0, &(struct timeval) { | ||||
.tv_sec = NERDJACK_TIMEOUT}); | |||||
.tv_sec = TIMEOUT}); | |||||
nerd_close_conn(fd_command); | nerd_close_conn(fd_command); | ||||
@@ -380,14 +378,14 @@ int nerd_send_command(const char *address, void *command, int length) | |||||
/* Send request */ | /* Send request */ | ||||
ret = send_all_timeout(fd_command, command, length, 0, &(struct timeval) { | ret = send_all_timeout(fd_command, command, length, 0, &(struct timeval) { | ||||
.tv_sec = NERDJACK_TIMEOUT}); | |||||
.tv_sec = TIMEOUT}); | |||||
if (ret < 0 || ret != length) { | if (ret < 0 || ret != length) { | ||||
verb("short send %d\n", (int)ret); | verb("short send %d\n", (int)ret); | ||||
return -1; | return -1; | ||||
} | } | ||||
ret = recv_all_timeout(fd_command, buf, 3, 0, &(struct timeval) { | ret = recv_all_timeout(fd_command, buf, 3, 0, &(struct timeval) { | ||||
.tv_sec = NERDJACK_TIMEOUT}); | |||||
.tv_sec = TIMEOUT}); | |||||
nerd_close_conn(fd_command); | nerd_close_conn(fd_command); | ||||
@@ -24,8 +24,7 @@ | |||||
#include "ue9error.h" | #include "ue9error.h" | ||||
#include "util.h" | #include "util.h" | ||||
#include "netutil.h" | #include "netutil.h" | ||||
#define UE9_TIMEOUT 5 /* Timeout for connect/send/recv, in seconds */ | |||||
#include "ethstream.h" | |||||
/* Fill checksums in data buffers, with "normal" checksum format */ | /* Fill checksums in data buffers, with "normal" checksum format */ | ||||
void ue9_checksum_normal(uint8_t * buffer, size_t len) | void ue9_checksum_normal(uint8_t * buffer, size_t len) | ||||
@@ -183,7 +182,7 @@ int ue9_command(int fd, uint8_t * out, uint8_t * in, int inlen) | |||||
/* Send request */ | /* Send request */ | ||||
ret = send_all_timeout(fd, out, outlen, 0, &(struct timeval) { | ret = send_all_timeout(fd, out, outlen, 0, &(struct timeval) { | ||||
.tv_sec = UE9_TIMEOUT}); | |||||
.tv_sec = TIMEOUT}); | |||||
if (ret < 0 || ret != outlen) { | if (ret < 0 || ret != outlen) { | ||||
verb("short send %d\n", (int)ret); | verb("short send %d\n", (int)ret); | ||||
return -1; | return -1; | ||||
@@ -197,7 +196,7 @@ int ue9_command(int fd, uint8_t * out, uint8_t * in, int inlen) | |||||
/* Receive result */ | /* Receive result */ | ||||
ret = recv_all_timeout(fd, in, inlen, 0, &(struct timeval) { | ret = recv_all_timeout(fd, in, inlen, 0, &(struct timeval) { | ||||
.tv_sec = UE9_TIMEOUT}); | |||||
.tv_sec = TIMEOUT}); | |||||
if (ret < 0 || ret != inlen) { | if (ret < 0 || ret != inlen) { | ||||
verb("short recv %d\n", (int)ret); | verb("short recv %d\n", (int)ret); | ||||
return -1; | return -1; | ||||
@@ -399,11 +398,13 @@ int ue9_open(const char *host, int port) | |||||
/* Connect */ | /* Connect */ | ||||
if (connect_timeout(fd, (struct sockaddr *)&address, sizeof(address), | if (connect_timeout(fd, (struct sockaddr *)&address, sizeof(address), | ||||
&(struct timeval) { | &(struct timeval) { | ||||
.tv_sec = UE9_TIMEOUT}) < 0) { | |||||
.tv_sec = TIMEOUT}) < 0) { | |||||
verb("connection to %s:%d failed: %s\n", | verb("connection to %s:%d failed: %s\n", | ||||
inet_ntoa(address.sin_addr), port, compat_strerror(errno)); | inet_ntoa(address.sin_addr), port, compat_strerror(errno)); | ||||
return -1; | return -1; | ||||
} | } | ||||
debug("Connected to port %d\n", htons(port)); | |||||
return fd; | return fd; | ||||
} | } | ||||
@@ -650,7 +651,7 @@ ue9_stream_data(int fd, int channels, ue9_stream_cb_t callback, void *context) | |||||
for (;;) { | for (;;) { | ||||
/* Receive data */ | /* Receive data */ | ||||
ret = recv_all_timeout(fd, buf, 46, 0, &(struct timeval) { | ret = recv_all_timeout(fd, buf, 46, 0, &(struct timeval) { | ||||
.tv_sec = UE9_TIMEOUT}); | |||||
.tv_sec = TIMEOUT}); | |||||
/* Verify packet format */ | /* Verify packet format */ | ||||
if (ret != 46) { | if (ret != 46) { | ||||