avr: flush the ctrl Tx buffer when decoding a new command

This commit is contained in:
Bart Van Der Meerssche 2010-12-29 15:29:31 +01:00
parent 9c5842f262
commit 20a13be0d3
2 changed files with 41 additions and 3 deletions

View File

@ -109,11 +109,16 @@ uint8_t ctrlGetFromRxBuffer(uint8_t* pdata)
} }
} }
void ctrlFlushReceiveBuffer(void) void ctrlFlushRxBuffer(void)
{ {
ctrlRxBuffer.datalength = 0; ctrlRxBuffer.datalength = 0;
} }
void ctrlFlushTxBuffer(void)
{
ctrlTxBuffer.datalength = 0;
}
uint8_t ctrlReadCharFromRxBuffer(uint8_t* pdata) uint8_t ctrlReadCharFromRxBuffer(uint8_t* pdata)
{ {
uint8_t high_hex, low_hex; uint8_t high_hex, low_hex;
@ -200,6 +205,8 @@ void ctrlDecode(void)
{ {
uint8_t cmd[2]; uint8_t cmd[2];
ctrlFlushTxBuffer();
if (ctrlGetFromRxBuffer(cmd) && ctrlGetFromRxBuffer(cmd+1)) { if (ctrlGetFromRxBuffer(cmd) && ctrlGetFromRxBuffer(cmd+1)) {
ctrlAddToTxBuffer(cmd[0]); ctrlAddToTxBuffer(cmd[0]);
ctrlAddToTxBuffer(cmd[1]); ctrlAddToTxBuffer(cmd[1]);
@ -219,7 +226,7 @@ void ctrlDecode(void)
ctrlAddToTxBuffer('.'); ctrlAddToTxBuffer('.');
} }
ctrlFlushReceiveBuffer(); ctrlFlushRxBuffer();
} }
void ctrlCmdGet(uint8_t cmd) void ctrlCmdGet(uint8_t cmd)

View File

@ -90,7 +90,13 @@ uint8_t ctrlGetFromRxBuffer(uint8_t* data);
* Flush the ctrl Rx buffer. * 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. * Loop all bytes from the ctrl Rx to Tx buffer.
@ -98,7 +104,32 @@ void ctrlFlushReceiveBuffer(void);
*/ */
void ctrlRxToTxLoop(void); void ctrlRxToTxLoop(void);
/**
* Decode the message in the ctrl Rx buffer and dispatch to either ctrlCmdGet,
* ctrlCmdSet or ctrlCmdCommit.
*
*/
void ctrlDecode(void); 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); 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); void ctrlCmdSet(uint8_t cmd);
/**
* Commit all previous changes by writing the datastructures to EEPROM.
*
*/
void ctrlCmdCommit(void); void ctrlCmdCommit(void);