3rd year group project. Electronic and Electrical Engineering. Heriot-Watt University. This is the code for the mbed for the Automatic Little Object Organiser (ALOO).
Dependencies: MCP23017 TCS3472_I2C WattBob_TextLCD mbed
Diff: commander.cpp
- Revision:
- 3:843b830ee8bd
- Parent:
- 2:7a55cb10259f
- Child:
- 5:6ef2d954fca3
--- a/commander.cpp Fri Oct 30 07:51:47 2015 +0000 +++ b/commander.cpp Wed Nov 11 03:45:30 2015 +0000 @@ -11,23 +11,26 @@ @return -1:not correct prefix, otherwise 0:QUERY, 1:SET, 2:REPLY*/ Type listenForCommand(){ char commandType; - + pc.printf("In listen"); commandType = pc.getc(); - if (commandType == '?') + + if (commandType == '?'){ return QUERY; - else if (commandType == '!') + } + else if (commandType == '!'){ return SET; - else if (commandType == '=') + } + else if (commandType == '='){ return REPLY; - else + } + else{ return INVALID; + } } void recieveCommand(Command *cmd, Type type){ -// cmd->inputString; -// cmd->outputString; +// pc.printf("In recieve command\n"); - cmd->typeEnum = type; switch (type) { case QUERY: cmd->inputString[0] = '?'; @@ -38,8 +41,8 @@ cmd->commandType[0] = '!'; break; case REPLY: - cmd->inputString[0] = '='; - cmd->commandType[0] = '='; + cmd->inputString[0] = ':'; + cmd->commandType[0] = ':'; break; default: break; @@ -57,7 +60,9 @@ cmd->inputString[i] = nextChar; if (nextChar == gCommandTerminator){ - cmd->commandString[commandStringIdx - 1] = '\0'; + pc.printf("nextChar == Terminator\r\n"); + pc.printf("%s\r\n", cmd->inputString); +// cmd->commandString[commandStringIdx - 1] = '\0'; break; } @@ -87,19 +92,17 @@ void decodeCommand(Command *cmd) { switch (cmd->typeEnum) { - case QUERY: - { - switch (cmd->objectEnum) { - case MBED: - { - string commandString = cmd->commandString; + case QUERY: { + switch (cmd->objectEnum) { + case MBED: { + string commandString = cmd->commandString; const string init = "init"; - if (cmd->commandString == "init"){ - // Convert gParity from Pairty to string - pc.printf("%s<%s>baudRate:%f,parity:none,stopbits:%i;\r\n", cmd->commandType, cmd->commandObject, gBaudRate, gStopBits); + if (cmd->commandString == "init") { + // Convert gParity from Pairty to string + pc.printf("%s<%s>baudRate:%f,parity:none,stopbits:%i;\r\n", cmd->commandType, cmd->commandObject, gBaudRate, gStopBits); } break; - } + } default: pc.printf("Going to 2rd default\r\n"); break;