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:
- 32:9a4046224b11
- Parent:
- 30:c0bc92d009fe
--- a/commander.cpp Thu Dec 03 15:50:14 2015 +0000 +++ b/commander.cpp Thu Dec 17 17:23:24 2015 +0100 @@ -6,13 +6,13 @@ #include "commander.h" using namespace std; -#define _DEBUG_ -//const int kCommandBufferSize = 40; const int kCommandValueBufferSize = 80; const int kObjectBufferSize = 20; +/// All objects that can recieve commands string CommandObjectValue [6] = { "mbed", "pc", "colour_sensor", "servos", "port", "break_beam" }; +/// All object(fist column) and their possible commands(respective row). string CommandObjectCommandsValue [6][kMaxCommandCount] = { {"mbed", "haz-block", "read-current-block", "mode", "sort", "reading-count", "", "", "", ""}, {"pc", "connect", "disconnect", "", "", "", "", "", "reply-commands", "exit"}, @@ -22,17 +22,19 @@ {"break_beam", "test", "", "", "", "", "", "", "", ""}, }; +/// Creates new commander object Commander::Commander() { replyCommands = false; this->resetVariables(); } - +/// Desctructor Commander::~Commander() { } +/// Recieves and decodes the command void Commander::decodeCommand(CommandTypeRaw type) { this->resetVariables(); @@ -46,7 +48,6 @@ } if (this->readCommand(this->objectRaw) == false) { - // this->description(); pc.printf("DEBUG:Invalid command.\n"); return; } else if (connectedToPC == true || (this->typeRaw == Set && this->objectRaw == PC && this->commandIndex[0] == 1)) { @@ -63,6 +64,7 @@ return; } +/// Get the information about the parsed command in a readable manner. //TODO: Fix format std::string Commander::description() { @@ -80,6 +82,7 @@ return str; } +/// Reads and assignes the imminent commanding object. void Commander::readCommandObject() { char objectInitiator = '<'; @@ -117,6 +120,8 @@ return; } +/// Reads the command for the previouly read object. +/// Return true if is a possible command, false otherwise. bool Commander::readCommand(CommandObjectRaw objectRaw) { char nextChar = '\0'; @@ -159,35 +164,25 @@ } string tempCommandStr(commandCharArray[i]); string tempValueStr(commandValueArray[i]); - // pc.printf("%s\n", tempCommandStr.c_str()); int row = this->objectRaw; - // pc.printf("Row: %i\n", this->objectRaw); int column = 1; - // pc.printf("Column: %i\n", column); for (; column < kMaxCommandCount - 1; column++) { - // pc.printf("%i\n", column); if (CommandObjectCommandsValue[row][column] == tempCommandStr) { - // pc.printf("Found matching command.\n"); this->command[i] = tempCommandStr; - // pc.printf("%s\n", this->command[i].c_str()); this->commandIndex[i] = column; - // pc.printf("%i\n", this->commandIndex[i]); this->commandValue[i] = tempValueStr; - // pc.printf("%s\n", this->commandValue[i].c_str()); - // pc.printf("%s\n", this->description().c_str()); break; } } if (this->commandIndex[i] == -1) { - // pc.printf("index = -1\n"); return false; } } - // pc.printf("Returning\n"); return true; } +/// Executes the previously read command with the object. void Commander::executeCommand() { switch (this->objectRaw) { @@ -349,7 +344,7 @@ return; } - +// Cleans all the properties, ready to recieved next command. void Commander::resetVariables() { this->object = "";