From: Scott Worley Date: Tue, 10 Oct 2023 09:27:57 +0000 (-0700) Subject: client: Change wire format!: Expand `ago` field: 16 bits → 32 bits X-Git-Tag: v0.1.0~23 X-Git-Url: http://git.scottworley.com/tattlekey/commitdiff_plain/9266b741959871619b5431a2b4e4ebdad5567a3d?ds=inline client: Change wire format!: Expand `ago` field: 16 bits → 32 bits 16-bit values of seconds only go up to 18 hours, and sometimes a little more than that would be nice. 32 is overkill. 24 would have been fine, but would have been slightly annoying to encode and parse. --- diff --git a/client/config.c b/client/config.c index 61d64ce..a708df4 100644 --- a/client/config.c +++ b/client/config.c @@ -39,12 +39,7 @@ const u32_t config_minimum_seconds_between_button_presses = 1; * etc. * This provides some robustness against network outages, automatically * replaying the log periodically to be collected after connectivity - * is restored. - * - * Values above 17 are currently not recommended because the current - * wire format uses a 16-bit field for a duration in seconds, which wraps - * at 18 hours. - * */ + * is restored. */ const uint config_resend_count = 16; /* These control the size of the per-send-count press queues. diff --git a/client/config.h b/client/config.h index 8d23169..3a61793 100644 --- a/client/config.h +++ b/client/config.h @@ -59,12 +59,7 @@ extern const u32_t config_minimum_seconds_between_button_presses; * etc. * This provides some robustness against network outages, automatically * replaying the log periodically to be collected after connectivity - * is restored. - * - * Values above 17 are currently not recommended because the current - * wire format uses a 16-bit field for a duration in seconds, which wraps - * at 18 hours. - * */ + * is restored. */ extern const uint config_resend_count; /* These control the size of the per-send-count press queues. diff --git a/client/net.c b/client/net.c index 6253d61..1e0790e 100644 --- a/client/net.c +++ b/client/net.c @@ -47,10 +47,10 @@ static void initialize_the_pcb() { struct tattle_message_wire_format { u16_t sender; u16_t seq; - u16_t ago; + u32_t ago; }; -void send_report_packet(u16_t seq, u16_t ago) { +void send_report_packet(u16_t seq, u32_t ago) { cyw43_arch_lwip_begin(); initialize_the_pcb(); @@ -64,7 +64,7 @@ void send_report_packet(u16_t seq, u16_t ago) { (struct tattle_message_wire_format *)(p->payload); msg->sender = htons(config_this_tattler_identity); msg->seq = htons(seq); - msg->ago = htons(ago); + msg->ago = htonl(ago); if (udp_send(the_pcb, p) != ERR_OK) signal_error_by_blinking(); diff --git a/client/net.h b/client/net.h index 30a6e03..9b8fc1f 100644 --- a/client/net.h +++ b/client/net.h @@ -20,6 +20,6 @@ #include "lwip/arch.h" -void send_report_packet(u16_t seq, u16_t ago); +void send_report_packet(u16_t seq, u32_t ago); #endif diff --git a/client/tattlekey.c b/client/tattlekey.c index 9d25585..f9b74c1 100644 --- a/client/tattlekey.c +++ b/client/tattlekey.c @@ -94,7 +94,7 @@ void service_sleeps(int alarm, press_pile_t *pp) { press_t press; if (!get_press_due_for_resend(pp, now, &press)) signal_error_by_blinking(); - uint32_t ago = now - press.timestamp; + u32_t ago = now - press.timestamp; send_report_packet(press.seq, ago); press.send_count++; if (press.send_count < config_resend_count) {