From 3fa71c497a5bf576974e70af06762f75734e6699 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 9 Sep 2012 13:50:56 -0700 Subject: [PATCH] altos: Try to get remote cmac time closer to reality Record the time after the packet was sent, but before the return packet arrives to try and more closely approximate the time the packet arrived at the other end. Signed-off-by: Keith Packard --- src/drivers/ao_lco_func.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/drivers/ao_lco_func.c b/src/drivers/ao_lco_func.c index 152b5d1b..99e58b76 100644 --- a/src/drivers/ao_lco_func.c +++ b/src/drivers/ao_lco_func.c @@ -28,18 +28,18 @@ ao_lco_query(uint16_t box, struct ao_pad_query *query, uint16_t *tick_offset) { uint8_t i; int8_t r; - uint16_t time; + uint16_t sent_time; ao_mutex_get(&ao_lco_mutex); - time = ao_time(); - command.tick = time; + command.tick = ao_time() - *tick_offset; command.box = box; command.cmd = AO_LAUNCH_QUERY; command.channels = 0; ao_radio_cmac_send(&command, sizeof (command)); - r = ao_radio_cmac_recv(query, sizeof (*query), AO_MS_TO_TICKS(500)); + sent_time = ao_time(); + r = ao_radio_cmac_recv(query, sizeof (*query), AO_MS_TO_TICKS(20)); if (r == AO_RADIO_CMAC_OK) - *tick_offset = time - query->tick; + *tick_offset = sent_time - query->tick; ao_mutex_put(&ao_lco_mutex); return r; } -- 2.30.2