summaryrefslogtreecommitdiff
path: root/client/main.c
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-06-02 17:22:48 +0200
committerlonkaars <loek@pipeframe.xyz>2022-06-02 17:22:48 +0200
commit14779cb187dac9ed4a0b6e7645e76e78587ad024 (patch)
treeae523d0216d0d9dce7155296bbe915a6f8f22c22 /client/main.c
parent052be3db6fbb855be63e95291a270ba707796739 (diff)
ping working
Diffstat (limited to 'client/main.c')
-rw-r--r--client/main.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/client/main.c b/client/main.c
index 8fe6d8e..00f686a 100644
--- a/client/main.c
+++ b/client/main.c
@@ -1,10 +1,15 @@
#include "main.h"
#include "../shared/errcatch.h"
+#include "../shared/consts.h"
#include "serial.h"
#include "setup.h"
#include "ui.h"
+#include "time.h"
+#include "commands.h"
-w2_s_client_state g_w2_state;
+w2_s_client_state g_w2_state = {
+ .ping_received = true
+};
int main(int argc, char **argv) {
w2_client_setup(argc, argv);
@@ -13,5 +18,17 @@ int main(int argc, char **argv) {
w2_serial_main();
w2_errcatch_main();
w2_ui_main();
+
+ if (!g_w2_state.ping_received && w2_timer_end(W2_TIMER_PING) > W2_PING_TIMEOUT) {
+ g_w2_state.ping_timeout = true;
+ g_w2_state.connected = false;
+ w2_errcatch_throw(W2_E_WARN_PING_TIMEOUT);
+ }
+
+ if ((g_w2_state.ping_received && w2_timer_end(W2_TIMER_PING) > W2_PING_FREQUENCY) || g_w2_state.ping_timeout) {
+ g_w2_state.ping_timeout = false;
+ g_w2_state.ping_received = false;
+ w2_send_ping();
+ }
}
}