altos: For telelco discovery packets, retry 5 times with shorter timeout
authorKeith Packard <keithp@keithp.com>
Thu, 1 May 2014 05:14:37 +0000 (22:14 -0700)
committerKeith Packard <keithp@keithp.com>
Thu, 1 May 2014 05:14:37 +0000 (22:14 -0700)
A timeout of 10ms is more than enough to receive a query packet, but
if we miss it during device discovery, it's a pain, so retry 5 times
to make sure we find everyone.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/drivers/ao_lco_func.c
src/telelco-v0.2/ao_lco.c

index a5d28e615234bd509dbca8566c179e200f30d866..9e64283696eaf3c25c68510764e57c79750ca1f4 100644 (file)
@@ -36,7 +36,7 @@ ao_lco_query(uint16_t box, struct ao_pad_query *query, uint16_t *tick_offset)
        command.channels = 0;
        ao_radio_cmac_send(&command, sizeof (command));
        sent_time = ao_time();
-       r = ao_radio_cmac_recv(query, sizeof (*query), AO_MS_TO_TICKS(20));
+       r = ao_radio_cmac_recv(query, sizeof (*query), AO_MS_TO_TICKS(10));
        if (r == AO_RADIO_CMAC_OK)
                *tick_offset = sent_time - query->tick;
        ao_mutex_put(&ao_lco_mutex);
index 0bbb76f10218d651cc53d6b8ac5b88978c4ad626..b3f5bb169cab5bf7a8a573672c1baf87d37f7991 100644 (file)
@@ -251,18 +251,22 @@ ao_lco_search(void)
 {
        uint16_t        tick_offset;
        int8_t          r;
+       int8_t          try;
        uint8_t         box;
 
        ao_lco_box_reset_present();
        for (box = 0; box < AO_PAD_MAX_BOXES; box++) {
                if ((box % 10) == 0)
                        ao_lco_set_box(box);
-               tick_offset = 0;
-               r = ao_lco_query(box, &ao_pad_query, &tick_offset);
-               PRINTD("box %d result %d\n", box, r);
-               if (r == AO_RADIO_CMAC_OK) {
-                       ao_lco_box_set_present(box);
-                       ao_delay(AO_MS_TO_TICKS(30));
+               for (try = 0; try < 5; try++) {
+                       tick_offset = 0;
+                       r = ao_lco_query(box, &ao_pad_query, &tick_offset);
+                       PRINTD("box %d result %d\n", box, r);
+                       if (r == AO_RADIO_CMAC_OK) {
+                               ao_lco_box_set_present(box);
+                               ao_delay(AO_MS_TO_TICKS(30));
+                               break;
+                       }
                }
        }
        if (ao_lco_min_box <= ao_lco_max_box)