summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2009-11-18 13:29:06 (GMT)
committerChristian Pointner <equinox@helsinki.at>2009-11-18 13:29:06 (GMT)
commit56d755c55d99cd0ae170a35348ba5dbfd68ebddd (patch)
tree4ac2c70ffb40f0ba1f0faaa6c0ec484667555526
parentdd316ece61cd5f240bca8f3243f4770f48139ce5 (diff)
added timeout counter to heartbeatclient
-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;
}