From 20a13be0d36f238cb6f5bba15c8dbf5b162baf27 Mon Sep 17 00:00:00 2001 From: Bart Van Der Meerssche Date: Wed, 29 Dec 2010 15:29:31 +0100 Subject: [PATCH] avr: flush the ctrl Tx buffer when decoding a new command --- mote/v2/avr/ctrl.c | 11 +++++++++-- mote/v2/avr/ctrl.h | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/mote/v2/avr/ctrl.c b/mote/v2/avr/ctrl.c index b01af32..54adc99 100644 --- a/mote/v2/avr/ctrl.c +++ b/mote/v2/avr/ctrl.c @@ -109,11 +109,16 @@ uint8_t ctrlGetFromRxBuffer(uint8_t* pdata) } } -void ctrlFlushReceiveBuffer(void) +void ctrlFlushRxBuffer(void) { ctrlRxBuffer.datalength = 0; } +void ctrlFlushTxBuffer(void) +{ + ctrlTxBuffer.datalength = 0; +} + uint8_t ctrlReadCharFromRxBuffer(uint8_t* pdata) { uint8_t high_hex, low_hex; @@ -200,6 +205,8 @@ void ctrlDecode(void) { uint8_t cmd[2]; + ctrlFlushTxBuffer(); + if (ctrlGetFromRxBuffer(cmd) && ctrlGetFromRxBuffer(cmd+1)) { ctrlAddToTxBuffer(cmd[0]); ctrlAddToTxBuffer(cmd[1]); @@ -219,7 +226,7 @@ void ctrlDecode(void) ctrlAddToTxBuffer('.'); } - ctrlFlushReceiveBuffer(); + ctrlFlushRxBuffer(); } void ctrlCmdGet(uint8_t cmd) diff --git a/mote/v2/avr/ctrl.h b/mote/v2/avr/ctrl.h index 2cfec86..1e3066c 100644 --- a/mote/v2/avr/ctrl.h +++ b/mote/v2/avr/ctrl.h @@ -90,7 +90,13 @@ uint8_t ctrlGetFromRxBuffer(uint8_t* data); * Flush the ctrl Rx buffer. * */ -void ctrlFlushReceiveBuffer(void); +void ctrlFlushRxBuffer(void); + +/** + * Flush the ctrl Tx buffer. + * + */ +void ctrlFlushTxBuffer(void); /** * Loop all bytes from the ctrl Rx to Tx buffer. @@ -98,7 +104,32 @@ void ctrlFlushReceiveBuffer(void); */ void ctrlRxToTxLoop(void); +/** + * Decode the message in the ctrl Rx buffer and dispatch to either ctrlCmdGet, + * ctrlCmdSet or ctrlCmdCommit. + * + */ void ctrlDecode(void); + +/** + * Execute the get command with parameters present in the ctrl Rx buffer. + * The command's reply is written to the ctrl Tx buffer. + * + * @param cmd get command issued + */ void ctrlCmdGet(uint8_t cmd); + +/** + * Execute the set command with parameters present in the ctrl Rx buffer. + * The command's reply is written to the ctrl Tx buffer. In case of a set + * command this will typically only be the two-letter command ID issued. + * + * @param cmd set command issued + */ void ctrlCmdSet(uint8_t cmd); + +/** + * Commit all previous changes by writing the datastructures to EEPROM. + * + */ void ctrlCmdCommit(void);