From bf65e0b2a1299b49adc2d339ab9d9c7599aded9e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 30 Oct 2009 23:52:22 -0700 Subject: [PATCH] Send SYN packet to set sequence numbers --- src/ao.h | 1 + src/ao_packet.c | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/ao.h b/src/ao.h index 2e2fb589..e2f137bd 100644 --- a/src/ao.h +++ b/src/ao.h @@ -981,6 +981,7 @@ struct ao_fifo { */ #define AO_PACKET_MAX 8 +#define AO_PACKET_SYN 0xff struct ao_packet { uint8_t addr; diff --git a/src/ao_packet.c b/src/ao_packet.c index da33bb4c..620cd001 100644 --- a/src/ao_packet.c +++ b/src/ao_packet.c @@ -83,14 +83,22 @@ ao_packet_recv(void) ao_mutex_put(&ao_radio_mutex); if (dma_done & AO_DMA_DONE) { - printf ("rssi %d status %x\n", rx_packet.rssi, rx_packet.status); flush(); if (!(rx_packet.status & PKT_APPEND_STATUS_1_CRC_OK)) { printf ("bad crc\n"); flush(); -// return AO_DMA_ABORTED; + return AO_DMA_ABORTED; } - if (rx_packet.packet.len) { + if (rx_packet.packet.len == AO_PACKET_SYN) { + rx_seq = rx_packet.packet.seq; + tx_packet.seq = rx_packet.packet.ack; + tx_packet.ack = rx_seq; + } else if (rx_packet.packet.len) { if (rx_packet.packet.seq == rx_seq + 1 && rx_used == rx_len) { + printf ("rx len %3d seq %3d ack %3d\n", + rx_packet.packet.len, + rx_packet.packet.seq, + rx_packet.packet.ack); + flush(); memcpy(rx_data, rx_packet.packet.d, rx_packet.packet.len); rx_used = 0; rx_len = rx_packet.packet.len; @@ -110,14 +118,17 @@ ao_packet_recv(void) void ao_packet_slave(void) { - tx_packet.addr = ao_serial_number; ao_radio_set_packet(); + tx_packet.addr = ao_serial_number; + tx_packet.len = AO_PACKET_SYN; while (ao_packet_enable) { + ao_led_on(AO_LED_GREEN); ao_packet_recv(); - ao_led_toggle(AO_LED_GREEN); + ao_led_off(AO_LED_GREEN); + ao_led_on(AO_LED_RED); ao_delay(AO_MS_TO_TICKS(100)); ao_packet_send(); - ao_led_toggle(AO_LED_RED); + ao_led_off(AO_LED_RED); } ao_exit(); } -- 2.30.2