From c1168f40223ca09df23215f2e2fc445a8a03aea9 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 27 Aug 2012 13:32:41 -0700 Subject: [PATCH] altos: Rename drivers/ao_lco to drivers/ao_lco_cmd These contain command line functions for testing the cmac and lco features. Now that there's a telelco-specific ao_lco interface file, it's useful to have both for testing. Signed-off-by: Keith Packard --- src/drivers/{ao_lco.c => ao_lco_cmd.c} | 77 +++++++++++++++++++++++++- src/drivers/{ao_lco.h => ao_lco_cmd.h} | 8 +-- 2 files changed, 79 insertions(+), 6 deletions(-) rename src/drivers/{ao_lco.c => ao_lco_cmd.c} (76%) rename src/drivers/{ao_lco.h => ao_lco_cmd.h} (88%) diff --git a/src/drivers/ao_lco.c b/src/drivers/ao_lco_cmd.c similarity index 76% rename from src/drivers/ao_lco.c rename to src/drivers/ao_lco_cmd.c index f30f3379..3fe0d9cc 100644 --- a/src/drivers/ao_lco.c +++ b/src/drivers/ao_lco_cmd.c @@ -16,7 +16,8 @@ */ #include -#include +#include +#include static __xdata struct ao_launch_command command; static __xdata struct ao_launch_query query; @@ -176,6 +177,78 @@ launch_ignite_cmd(void) __reentrant launch_ignite(); } +static uint8_t +getnibble(void) +{ + int8_t b; + + b = ao_cmd_hexchar(getchar()); + if (b < 0) { + ao_cmd_status = ao_cmd_lex_error; + return 0; + } + return (uint8_t) b; +} + +static uint8_t +getbyte(void) +{ + uint8_t b; + b = getnibble() << 4; + b |= getnibble(); + return b; +} + +static __xdata uint8_t cmac_data[AO_CMAC_MAX_LEN]; + +static void +radio_cmac_send_cmd(void) __reentrant +{ + uint8_t i; + uint8_t len; + + ao_cmd_decimal(); + if (ao_cmd_status != ao_cmd_success) + return; + len = ao_cmd_lex_i; + if (len > AO_CMAC_MAX_LEN) { + ao_cmd_status = ao_cmd_syntax_error; + return; + } + flush(); + len = ao_cmd_lex_i; + for (i = 0; i < len; i++) { + cmac_data[i] = getbyte(); + if (ao_cmd_status != ao_cmd_success) + return; + } + ao_radio_cmac_send(cmac_data, len); +} + +static void +radio_cmac_recv_cmd(void) __reentrant +{ + uint8_t len, i; + uint16_t timeout; + + ao_cmd_decimal(); + if (ao_cmd_status != ao_cmd_success) + return; + len = ao_cmd_lex_i; + ao_cmd_decimal(); + if (ao_cmd_status != ao_cmd_success) + return; + timeout = AO_MS_TO_TICKS(ao_cmd_lex_i); + i = ao_radio_cmac_recv(cmac_data, len, timeout); + if (i == AO_RADIO_CMAC_OK) { + printf ("PACKET "); + for (i = 0; i < len; i++) + printf("%02x", cmac_data[i]); + printf (" %d\n", ao_radio_cmac_rssi); + } else + printf ("ERROR %d %d\n", i, ao_radio_cmac_rssi); +} + static __code struct ao_cmds ao_lco_cmds[] = { { radio_cmac_send_cmd, "s \0Send AES-CMAC packet. Bytes to send follow on next line" }, { radio_cmac_recv_cmd, "S \0Receive AES-CMAC packet. Timeout in ms" }, @@ -187,7 +260,7 @@ static __code struct ao_cmds ao_lco_cmds[] = { }; void -ao_lco_init(void) +ao_lco_cmd_init(void) { ao_cmd_register(&ao_lco_cmds[0]); } diff --git a/src/drivers/ao_lco.h b/src/drivers/ao_lco_cmd.h similarity index 88% rename from src/drivers/ao_lco.h rename to src/drivers/ao_lco_cmd.h index 253f9702..c55448cd 100644 --- a/src/drivers/ao_lco.h +++ b/src/drivers/ao_lco_cmd.h @@ -15,10 +15,10 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#ifndef _AO_LCO_H_ -#define _AO_LCO_H_ +#ifndef _AO_LCO_CMD_H_ +#define _AO_LCO_CMD_H_ void -ao_lco_init(void); +ao_lco_cmd_init(void); -#endif /* _AO_LCO_H_ */ +#endif /* _AO_LCO_CMD_H_ */ -- 2.30.2