-\r
-\r
-\r
- /* Each time there is an element, check which comand should be\r
- run and if enough data is available to run that command.\r
- There are 1-byte, 2-byte, 3-byte, 4-byte commands, and 5-byte commands\r
- Remember that the "which command" byte counts as 1 */\r
- if (Rx_Buffer.Elements == 0) {\r
- // do nothing, wait for data\r
- } else {\r
- tempByte = Buffer_PeekElement(&Rx_Buffer); // peek at first element\r
-\r
- /* make sure the issued command and associated data are all ready */\r
- if (Rx_Buffer.Elements == 1) { // zero data byte command\r
- if ((tempByte == 'P') | (tempByte == 'a') | (tempByte == 'm') |\r
- (tempByte == 'R') | (tempByte == 'd') | (tempByte == 'e') |\r
- (tempByte == 'L') | (tempByte == 's') | (tempByte == 't') | \r
- (tempByte == 'S') | (tempByte == 'V') | (tempByte == 'v') |\r
- (tempByte == 'p') | (tempByte == 'F')) {\r
- processHostSPIRequest(); // command has enough data, process it\r
- }\r
- } else if (Rx_Buffer.Elements == 2) { // one data byte command\r
- if ((tempByte == 'T') | (tempByte == 'c') | (tempByte == 'C') |\r
- (tempByte == 'D') | (tempByte == 'l') | (tempByte == 'f') |\r
- (tempByte == 'x') | (tempByte == 'y')) {\r
- processHostSPIRequest(); // command has enough data, process it\r
- }\r
- } else if (Rx_Buffer.Elements == 3) { // two data byte command\r
- if ((tempByte == 'A') | (tempByte == 'Z')) {\r
- processHostSPIRequest(); // command has enough data, process it\r
- }\r
- } else if (Rx_Buffer.Elements == 4) { // three data byte command\r
- if ((tempByte == ':')) {\r
- processHostSPIRequest(); // command has enough data, process it\r
- }\r
- } else if (Rx_Buffer.Elements == 5) { // four data byte command\r
- if ((tempByte == '.')) {\r
- processHostSPIRequest(); // command has enough data, process it\r
- }\r
- } else {\r
- // do nothing\r
- }\r
+ /* Run the given command once enough data is available. */\r
+ if (Rx_Buffer.Elements)\r
+ {\r
+ const uint8_t ZeroDataByteCommands[] = {'P', 'a', 'm', 'R', 'd', 'e', 'L', 's', 't', 'S', 'V', 'v', 'p', 'F'};\r
+ const uint8_t OneDataByteCommands[] = {'T', 'c', 'C', 'D', 'l', 'f', 'x', 'y'};\r
+ const uint8_t TwoDataByteCommands[] = {'A', 'Z'};\r
+ const uint8_t ThreeDataByteCommands[] = {':'};\r
+ const uint8_t FourDataByteCommands[] = {'.'};\r
+ \r
+ const struct\r
+ {\r
+ const uint8_t TotalCommands;\r
+ const uint8_t* CommandBytes;\r
+ } AVR910Commands[] = {{sizeof(ZeroDataByteCommands), ZeroDataByteCommands},\r
+ {sizeof(OneDataByteCommands), OneDataByteCommands},\r
+ {sizeof(TwoDataByteCommands), TwoDataByteCommands},\r
+ {sizeof(ThreeDataByteCommands), ThreeDataByteCommands},\r
+ {sizeof(FourDataByteCommands), FourDataByteCommands}};\r
+ \r
+ /* Determine the data length of the issued command */\r
+ uint8_t CommandDataLength = (Rx_Buffer.Elements - 1);\r
+ \r
+ /* Loop through each of the possible command bytes allowable from the given command data length */\r
+ for (uint8_t CurrentCommand = 0; CurrentCommand < AVR910Commands[CommandDataLength].TotalCommands; CurrentCommand++)\r
+ {\r
+ /* If issues command matches an allowable command, process it */\r
+ if (Buffer_PeekElement(&Rx_Buffer) == AVR910Commands[CommandDataLength].CommandBytes[CurrentCommand])\r
+ processHostSPIRequest();\r
+ }\r