diff options
| author | Keith Packard <keithp@keithp.com> | 2012-08-27 13:32:41 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2012-08-27 13:32:41 -0700 | 
| commit | c1168f40223ca09df23215f2e2fc445a8a03aea9 (patch) | |
| tree | 50eb80f1d513c835da729d10aa77c5ada6a0a4ca | |
| parent | f89e7de20374141b367205aa517a08ee203bfaf3 (diff) | |
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 <keithp@keithp.com>
| -rw-r--r-- | src/drivers/ao_lco_cmd.c (renamed from src/drivers/ao_lco.c) | 77 | ||||
| -rw-r--r-- | src/drivers/ao_lco_cmd.h (renamed from src/drivers/ao_lco.h) | 8 | 
2 files changed, 79 insertions, 6 deletions
| diff --git a/src/drivers/ao_lco.c b/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 <ao.h> -#include <ao_lco.h> +#include <ao_lco_cmd.h> +#include <ao_radio_cmac.h>  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 <length>\0Send AES-CMAC packet. Bytes to send follow on next line" },  	{ radio_cmac_recv_cmd,	"S <length> <timeout>\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 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_ */ | 
