summaryrefslogtreecommitdiff
path: root/heartbeatclient.c
diff options
context:
space:
mode:
Diffstat (limited to 'heartbeatclient.c')
-rw-r--r--heartbeatclient.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/heartbeatclient.c b/heartbeatclient.c
index 7111525..f663945 100644
--- a/heartbeatclient.c
+++ b/heartbeatclient.c
@@ -37,8 +37,10 @@ int process_cmd(const char* cmd, int fd, cmd_t **cmd_q, client_t* client_lst, op
{
}
-int process_serial(read_buffer_t* buffer, int serial_fd)
+int process_serial(read_buffer_t* buffer, int serial_fd, u_int32_t* time)
{
+ log_printf(DEBUG, "received heartbeat data at %d 1/10 s", *time);
+
int ret = 0;
struct timeval tv;
fd_set fds;
@@ -70,7 +72,9 @@ int process_serial(read_buffer_t* buffer, int serial_fd)
if(strlen(buffer->buf)) {
log_printf(INFO, "heartbeat: '%s'", buffer->buf);
+
// reset heartbeat cnt
+ *time = 0;
}
buffer->offset = 0;
@@ -111,13 +115,14 @@ int main_loop(int serial_fd, int cmd_fd, options_t* opt)
return_value = -1;
}
else {
- log_printf(NOTICE, "connecting as type '%s'", opt->type_);
+ log_printf(NOTICE, "connecting as type heartbeat");
return_value = 0;
}
read_buffer_t serial_buffer;
serial_buffer.offset = 0;
struct timeval timeout;
+ u_int32_t time = 0;
while(!return_value) {
memcpy(&tmpfds, &readfds, sizeof(tmpfds));
@@ -129,19 +134,25 @@ int main_loop(int serial_fd, int cmd_fd, options_t* opt)
return_value = -1;
break;
}
- if(ret == -1 || !ret)
+ if(ret == -1)
continue;
if(!ret) {
- // timeout reached ???
- // if yes send command: "mode standby"
+ time++;
+ if(time >= opt->timeout_) {
+ log_printf(WARNING, "timeout reached");
+ time = 0;
+ }
+ continue;
}
+ log_printf(WARNING, "select has data");
+
if(FD_ISSET(sig_fd, &tmpfds))
if(signal_handle())
return_value = 1;
if(FD_ISSET(serial_fd, &tmpfds)) {
- return_value = process_serial(&serial_buffer, serial_fd);
+ return_value = process_serial(&serial_buffer, serial_fd, &time);
if(return_value)
break;
}