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

Committer:
dreamselec
Date:
Tue Dec 01 23:50:29 2015 +0000
Revision:
30:c0bc92d009fe
Parent:
29:9c0339e3c593
Child:
32:9a4046224b11
All functions appear to be ... functioning. Need to test set new haz block mode with hardware.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dreamselec 6:98fe30430194 1 //
dreamselec 6:98fe30430194 2 // commander.cpp
dreamselec 6:98fe30430194 3 // Created by Chandan Siyag on 14/11/2015.
dreamselec 6:98fe30430194 4 #include <iostream>
lordlycastle 5:6ef2d954fca3 5 #include <string>
dreamselec 2:7a55cb10259f 6 #include "commander.h"
dreamselec 2:7a55cb10259f 7
dreamselec 6:98fe30430194 8 using namespace std;
dreamselec 15:777390eb5afd 9 #define _DEBUG_
dreamselec 6:98fe30430194 10
dreamselec 9:dc8f155b71c8 11 //const int kCommandBufferSize = 40;
dreamselec 13:4f24da6e2f8e 12 const int kCommandValueBufferSize = 80;
dreamselec 8:e1da2ae62885 13 const int kObjectBufferSize = 20;
dreamselec 8:e1da2ae62885 14
dreamselec 23:db91aaa43a9e 15 string CommandObjectValue [6] = { "mbed", "pc", "colour_sensor", "servos", "port", "break_beam" };
dreamselec 23:db91aaa43a9e 16 string CommandObjectCommandsValue [6][kMaxCommandCount] = {
dreamselec 30:c0bc92d009fe 17 {"mbed", "haz-block", "read-current-block", "mode", "sort", "reading-count", "", "", "", ""},
dreamselec 30:c0bc92d009fe 18 {"pc", "connect", "disconnect", "", "", "", "", "", "reply-commands", "exit"},
dreamselec 30:c0bc92d009fe 19 {"colour_sensor", "i-time", "preview", "value", "block-value", "test", "", "", "", ""},
dreamselec 30:c0bc92d009fe 20 {"servos", "test", "reset", "toggle", "", "", "", "", "", ""},
dreamselec 30:c0bc92d009fe 21 {"port", "init", "b-rate", "parity", "", "", "", "", "", ""},
dreamselec 30:c0bc92d009fe 22 {"break_beam", "test", "", "", "", "", "", "", "", ""},
dreamselec 13:4f24da6e2f8e 23 };
dreamselec 8:e1da2ae62885 24
dreamselec 15:777390eb5afd 25 Commander::Commander()
dreamselec 15:777390eb5afd 26 {
dreamselec 30:c0bc92d009fe 27 replyCommands = false;
dreamselec 30:c0bc92d009fe 28 this->resetVariables();
dreamselec 6:98fe30430194 29 }
dreamselec 6:98fe30430194 30
dreamselec 15:777390eb5afd 31 Commander::~Commander()
dreamselec 15:777390eb5afd 32 {
dreamselec 12:f485796016f8 33
dreamselec 2:7a55cb10259f 34 }
dreamselec 2:7a55cb10259f 35
dreamselec 15:777390eb5afd 36 void Commander::decodeCommand(CommandTypeRaw type)
dreamselec 15:777390eb5afd 37 {
dreamselec 30:c0bc92d009fe 38 this->resetVariables();
dreamselec 30:c0bc92d009fe 39 this->typeRaw = type;
dreamselec 30:c0bc92d009fe 40 this->typeChar = CommandTypeValue[type];
dreamselec 14:cf2f255b5560 41
dreamselec 30:c0bc92d009fe 42 this->readCommandObject();
dreamselec 30:c0bc92d009fe 43 if (this->objectRaw == InvalidObject) {
dreamselec 30:c0bc92d009fe 44 pc.printf("DEBUG:Invalid command object.\n");
dreamselec 30:c0bc92d009fe 45 return;
dreamselec 30:c0bc92d009fe 46 }
dreamselec 6:98fe30430194 47
dreamselec 30:c0bc92d009fe 48 if (this->readCommand(this->objectRaw) == false) {
dreamselec 30:c0bc92d009fe 49 // this->description();
dreamselec 30:c0bc92d009fe 50 pc.printf("DEBUG:Invalid command.\n");
dreamselec 30:c0bc92d009fe 51 return;
dreamselec 30:c0bc92d009fe 52 } else if (connectedToPC == true || (this->typeRaw == Set && this->objectRaw == PC && this->commandIndex[0] == 1)) {
dreamselec 30:c0bc92d009fe 53 this->executeCommand();
dreamselec 30:c0bc92d009fe 54 if (this->replyCommands == true) {
dreamselec 30:c0bc92d009fe 55 pc.printf("VALUE:%s:VALUE\n", this->description().c_str());
dreamselec 30:c0bc92d009fe 56 }
dreamselec 30:c0bc92d009fe 57 //TODO: Send request with response descriptor.
dreamselec 30:c0bc92d009fe 58 // pc.("DEBUG:Finished executine command");
dreamselec 30:c0bc92d009fe 59 return;
dreamselec 30:c0bc92d009fe 60 }
dreamselec 16:4a41cb9e525f 61
dreamselec 30:c0bc92d009fe 62 pc.printf("INFO:Not connected to PC. %i\n", this->commandIndex[0]);
dreamselec 30:c0bc92d009fe 63 return;
dreamselec 8:e1da2ae62885 64 }
dreamselec 8:e1da2ae62885 65
dreamselec 25:792540d69c49 66 //TODO: Fix format
dreamselec 15:777390eb5afd 67 std::string Commander::description()
dreamselec 15:777390eb5afd 68 {
dreamselec 30:c0bc92d009fe 69 string str;
dreamselec 30:c0bc92d009fe 70 str.append("Type:\t\t");
dreamselec 30:c0bc92d009fe 71 str.append(&this->typeChar);
dreamselec 30:c0bc92d009fe 72 str.append("\nObject:\t\t" + this->object);
dreamselec 8:e1da2ae62885 73
dreamselec 30:c0bc92d009fe 74 for (int i = 0; i < sizeof(this->command)/sizeof(*this->command); i++) {
dreamselec 30:c0bc92d009fe 75 if (this->command[i] == "") {
dreamselec 30:c0bc92d009fe 76 break;
dreamselec 30:c0bc92d009fe 77 }
dreamselec 30:c0bc92d009fe 78 str.append("\nCommand:\t" + this->command[i] + "\nValue:\t\t" + this->commandValue[i].c_str() + " \n");
dreamselec 30:c0bc92d009fe 79 }
dreamselec 30:c0bc92d009fe 80 return str;
dreamselec 15:777390eb5afd 81 }
dreamselec 15:777390eb5afd 82
dreamselec 15:777390eb5afd 83 void Commander::readCommandObject()
dreamselec 15:777390eb5afd 84 {
dreamselec 30:c0bc92d009fe 85 char objectInitiator = '<';
dreamselec 30:c0bc92d009fe 86 char objectTerminator = '>';
dreamselec 15:777390eb5afd 87
dreamselec 30:c0bc92d009fe 88 char nextChar = '\0';
dreamselec 13:4f24da6e2f8e 89
dreamselec 30:c0bc92d009fe 90 do {
dreamselec 30:c0bc92d009fe 91 nextChar = pc.getc();
dreamselec 30:c0bc92d009fe 92 } while (nextChar != objectInitiator);
dreamselec 13:4f24da6e2f8e 93
dreamselec 30:c0bc92d009fe 94 char objectCharArray [kObjectBufferSize] = "";
dreamselec 30:c0bc92d009fe 95 int i = 0;
dreamselec 30:c0bc92d009fe 96 while (i < kObjectBufferSize) {
dreamselec 30:c0bc92d009fe 97 nextChar = pc.getc();
dreamselec 30:c0bc92d009fe 98 if (nextChar == '\n' || nextChar == '\r' || nextChar == ' ') {
dreamselec 30:c0bc92d009fe 99 continue;
dreamselec 30:c0bc92d009fe 100 }
dreamselec 30:c0bc92d009fe 101 if (nextChar == objectTerminator)
dreamselec 30:c0bc92d009fe 102 break;
dreamselec 30:c0bc92d009fe 103 objectCharArray[i] = nextChar;
dreamselec 30:c0bc92d009fe 104 i++;
dreamselec 30:c0bc92d009fe 105 }
dreamselec 30:c0bc92d009fe 106 string tempStr(objectCharArray);
dreamselec 30:c0bc92d009fe 107 this->object = tempStr;
dreamselec 8:e1da2ae62885 108
dreamselec 30:c0bc92d009fe 109 for (int i = 0; i < (sizeof(CommandObjectValue)/sizeof(*CommandObjectValue)); i++) {
dreamselec 30:c0bc92d009fe 110 if (CommandObjectValue[i] == this->object) {
dreamselec 30:c0bc92d009fe 111 this->objectRaw = static_cast<CommandObjectRaw>(i);
dreamselec 30:c0bc92d009fe 112 return;
dreamselec 30:c0bc92d009fe 113 }
dreamselec 30:c0bc92d009fe 114 }
dreamselec 8:e1da2ae62885 115
dreamselec 30:c0bc92d009fe 116 this->objectRaw = InvalidObject;
dreamselec 30:c0bc92d009fe 117 return;
dreamselec 13:4f24da6e2f8e 118 }
dreamselec 2:7a55cb10259f 119
dreamselec 15:777390eb5afd 120 bool Commander::readCommand(CommandObjectRaw objectRaw)
dreamselec 15:777390eb5afd 121 {
dreamselec 30:c0bc92d009fe 122 char nextChar = '\0';
dreamselec 30:c0bc92d009fe 123 char commandCharArray [kMaxCommandCount - 1][kCommandValueBufferSize] = { '\0' };
dreamselec 30:c0bc92d009fe 124 char commandValueArray [kMaxCommandCount -1][kCommandValueBufferSize] = { '\0' };
dreamselec 15:777390eb5afd 125
dreamselec 30:c0bc92d009fe 126 int charIndex = 0;
dreamselec 30:c0bc92d009fe 127 int valueCharIndex = 0;
dreamselec 30:c0bc92d009fe 128 int commandValueIndex = 0;
dreamselec 30:c0bc92d009fe 129 bool commandComplete = false;
dreamselec 30:c0bc92d009fe 130 while (charIndex < kCommandValueBufferSize - 1 && valueCharIndex < kCommandValueBufferSize - 1) {
dreamselec 30:c0bc92d009fe 131 nextChar = pc.getc();
dreamselec 16:4a41cb9e525f 132
dreamselec 30:c0bc92d009fe 133 if (nextChar == '\n' || nextChar == '\r' || nextChar == ' ') {
dreamselec 30:c0bc92d009fe 134 continue;
dreamselec 30:c0bc92d009fe 135 } else if (nextChar == kCommandTerminator) {
dreamselec 30:c0bc92d009fe 136 break;
dreamselec 30:c0bc92d009fe 137 } else if (nextChar == '=') {
dreamselec 30:c0bc92d009fe 138 commandComplete = true;
dreamselec 30:c0bc92d009fe 139 } else if (nextChar == ',') {
dreamselec 30:c0bc92d009fe 140 commandComplete = false;
dreamselec 30:c0bc92d009fe 141 commandValueIndex++;
dreamselec 30:c0bc92d009fe 142 charIndex = 0;
dreamselec 30:c0bc92d009fe 143 valueCharIndex = 0;
dreamselec 30:c0bc92d009fe 144 }
dreamselec 15:777390eb5afd 145
dreamselec 30:c0bc92d009fe 146 if (commandComplete == false && nextChar != ',') {
dreamselec 30:c0bc92d009fe 147 commandCharArray[commandValueIndex][charIndex] = nextChar;
dreamselec 30:c0bc92d009fe 148 charIndex++;
dreamselec 30:c0bc92d009fe 149 } else if (commandComplete == true && nextChar != '=') {
dreamselec 30:c0bc92d009fe 150 commandValueArray[commandValueIndex][valueCharIndex] = nextChar;
dreamselec 30:c0bc92d009fe 151 valueCharIndex++;
dreamselec 30:c0bc92d009fe 152 }
dreamselec 30:c0bc92d009fe 153 }
dreamselec 15:777390eb5afd 154
dreamselec 30:c0bc92d009fe 155 for (int i = 0; i < kMaxCommandCount - 1; i++) {
dreamselec 30:c0bc92d009fe 156 // pc.printf("i: %i\n", i);
dreamselec 30:c0bc92d009fe 157 if (commandCharArray[i][0] == '\0') {
dreamselec 30:c0bc92d009fe 158 break;
dreamselec 30:c0bc92d009fe 159 }
dreamselec 30:c0bc92d009fe 160 string tempCommandStr(commandCharArray[i]);
dreamselec 30:c0bc92d009fe 161 string tempValueStr(commandValueArray[i]);
dreamselec 30:c0bc92d009fe 162 // pc.printf("%s\n", tempCommandStr.c_str());
dreamselec 30:c0bc92d009fe 163 int row = this->objectRaw;
dreamselec 30:c0bc92d009fe 164 // pc.printf("Row: %i\n", this->objectRaw);
dreamselec 30:c0bc92d009fe 165 int column = 1;
dreamselec 30:c0bc92d009fe 166 // pc.printf("Column: %i\n", column);
dreamselec 30:c0bc92d009fe 167 for (; column < kMaxCommandCount - 1; column++) {
dreamselec 30:c0bc92d009fe 168 // pc.printf("%i\n", column);
dreamselec 30:c0bc92d009fe 169 if (CommandObjectCommandsValue[row][column] == tempCommandStr) {
dreamselec 30:c0bc92d009fe 170 // pc.printf("Found matching command.\n");
dreamselec 30:c0bc92d009fe 171 this->command[i] = tempCommandStr;
dreamselec 30:c0bc92d009fe 172 // pc.printf("%s\n", this->command[i].c_str());
dreamselec 30:c0bc92d009fe 173 this->commandIndex[i] = column;
dreamselec 30:c0bc92d009fe 174 // pc.printf("%i\n", this->commandIndex[i]);
dreamselec 30:c0bc92d009fe 175 this->commandValue[i] = tempValueStr;
dreamselec 30:c0bc92d009fe 176 // pc.printf("%s\n", this->commandValue[i].c_str());
dreamselec 30:c0bc92d009fe 177 // pc.printf("%s\n", this->description().c_str());
dreamselec 30:c0bc92d009fe 178 break;
dreamselec 30:c0bc92d009fe 179 }
dreamselec 30:c0bc92d009fe 180 }
dreamselec 30:c0bc92d009fe 181 if (this->commandIndex[i] == -1) {
dreamselec 30:c0bc92d009fe 182 // pc.printf("index = -1\n");
dreamselec 30:c0bc92d009fe 183 return false;
dreamselec 30:c0bc92d009fe 184 }
dreamselec 30:c0bc92d009fe 185 }
dreamselec 16:4a41cb9e525f 186
dreamselec 30:c0bc92d009fe 187 // pc.printf("Returning\n");
dreamselec 30:c0bc92d009fe 188 return true;
dreamselec 15:777390eb5afd 189 }
dreamselec 14:cf2f255b5560 190
dreamselec 15:777390eb5afd 191 void Commander::executeCommand()
dreamselec 15:777390eb5afd 192 {
dreamselec 30:c0bc92d009fe 193 switch (this->objectRaw) {
dreamselec 30:c0bc92d009fe 194 case MBED:
dreamselec 30:c0bc92d009fe 195 for (int i = 0; i < sizeof(this->command)/sizeof(*this->command); i++) {
dreamselec 30:c0bc92d009fe 196 if (this->commandIndex[i] == -1 || this->commandIndex[i] == 0) {
dreamselec 30:c0bc92d009fe 197 break;
dreamselec 30:c0bc92d009fe 198 }
dreamselec 30:c0bc92d009fe 199 if (this->commandIndex[i] == 1) {
dreamselec 30:c0bc92d009fe 200 if (this->typeRaw == Set) {
dreamselec 30:c0bc92d009fe 201 if (this->commandValue[i] == "start") {
dreamselec 30:c0bc92d009fe 202 hazBlock(this->typeRaw);
dreamselec 30:c0bc92d009fe 203 } else if (this->commandValue[i] == "pause") {
dreamselec 30:c0bc92d009fe 204 pc.printf("DEBUG: Exited set new haz block mode.\n");
dreamselec 30:c0bc92d009fe 205 setNewHazBlock = false;
dreamselec 30:c0bc92d009fe 206 }
dreamselec 30:c0bc92d009fe 207 } else if (this->typeRaw == Query) {
dreamselec 30:c0bc92d009fe 208 hazBlock(this->typeRaw);
dreamselec 30:c0bc92d009fe 209 }
dreamselec 30:c0bc92d009fe 210 } else if (this->commandIndex[i] == 2) {
dreamselec 30:c0bc92d009fe 211 getCurrentBlock(this->typeRaw);
dreamselec 30:c0bc92d009fe 212 } else if (this->commandIndex[i] == 3) {
dreamselec 30:c0bc92d009fe 213 if (this->commandValue[i] == "maintanence") {
dreamselec 30:c0bc92d009fe 214 currentMode = Maintanence;
dreamselec 30:c0bc92d009fe 215 pc.printf("INFO:Running in maintanence mode.\n");
dreamselec 30:c0bc92d009fe 216 } else if (this->commandValue[i] == "normal") {
dreamselec 30:c0bc92d009fe 217 currentMode = Normal;
dreamselec 30:c0bc92d009fe 218 pc.printf("INFO:Running in nomal mode.\n");
dreamselec 30:c0bc92d009fe 219 } else if (this->commandValue[i] == "none") {
dreamselec 30:c0bc92d009fe 220 currentMode = None;
dreamselec 30:c0bc92d009fe 221 pc.printf("INFo:Running in none mode.\n");
dreamselec 30:c0bc92d009fe 222 }
dreamselec 30:c0bc92d009fe 223 } else if (this->commandIndex[i] == 4 && currentMode == Normal) {
dreamselec 30:c0bc92d009fe 224 if (this->commandValue[i] == "start") {
dreamselec 30:c0bc92d009fe 225 currentState = Start;
dreamselec 30:c0bc92d009fe 226 pc.printf("INFO:Starting sorting.\n");
dreamselec 30:c0bc92d009fe 227 } else if (this->commandValue[i] == "pause") {
dreamselec 30:c0bc92d009fe 228 currentState = Pause;
dreamselec 30:c0bc92d009fe 229 pc.printf("INFO:Pausing sorting.\n");
dreamselec 30:c0bc92d009fe 230 }
dreamselec 30:c0bc92d009fe 231 } else if (this->commandIndex[i] == 5) {
dreamselec 30:c0bc92d009fe 232 int readingCount = 0;
dreamselec 30:c0bc92d009fe 233 sscanf(this->commandValue[i].c_str(), "%i", readingCount);
dreamselec 30:c0bc92d009fe 234 hazReadingCount = readingCount;
dreamselec 30:c0bc92d009fe 235 }
dreamselec 30:c0bc92d009fe 236 }
dreamselec 30:c0bc92d009fe 237 break;
dreamselec 30:c0bc92d009fe 238 case PC:
dreamselec 30:c0bc92d009fe 239 for (int i = 0; i < sizeof(this->command)/sizeof(*this->command); i++) {
dreamselec 30:c0bc92d009fe 240 if (this->commandIndex[i] == -1 || this->commandIndex[i] == 0) {
dreamselec 30:c0bc92d009fe 241 break;
dreamselec 30:c0bc92d009fe 242 }
dreamselec 30:c0bc92d009fe 243 if (this->commandIndex[i] == 1) {
dreamselec 30:c0bc92d009fe 244 connectToPC(this->typeRaw);
dreamselec 30:c0bc92d009fe 245 } else if (this->commandIndex[i] == 2) {
dreamselec 30:c0bc92d009fe 246 disconnectToPC(this->typeRaw);
dreamselec 30:c0bc92d009fe 247 } else if (this->commandIndex[i] == 8) {
dreamselec 30:c0bc92d009fe 248 if (this->commandValue[i] == "ON") {
dreamselec 30:c0bc92d009fe 249 this->replyCommands = true;
dreamselec 30:c0bc92d009fe 250 } else if (this->commandValue[i] == "OFF") {
dreamselec 30:c0bc92d009fe 251 this->replyCommands = false;
dreamselec 30:c0bc92d009fe 252 }
dreamselec 30:c0bc92d009fe 253 }
dreamselec 30:c0bc92d009fe 254 }
dreamselec 30:c0bc92d009fe 255 break;
dreamselec 30:c0bc92d009fe 256 case ColourSensor:
dreamselec 30:c0bc92d009fe 257 for (int i = 0; i < sizeof(this->command)/sizeof(*this->command); i++) {
dreamselec 30:c0bc92d009fe 258 if (this->commandIndex[i] == -1 || this->commandIndex[i] == 0) {
dreamselec 30:c0bc92d009fe 259 break;
dreamselec 30:c0bc92d009fe 260 }
dreamselec 30:c0bc92d009fe 261 if (this->commandIndex[i] == 1) {
dreamselec 30:c0bc92d009fe 262 float integrationTime;
dreamselec 30:c0bc92d009fe 263 sscanf(this->commandValue[i].c_str(), "%f", &integrationTime);
dreamselec 30:c0bc92d009fe 264 if (integrationTime < 2.4 || integrationTime > 600) {
dreamselec 30:c0bc92d009fe 265 pc.printf("ERROR:Integration Time invalid: %.3f\n", integrationTime);
dreamselec 30:c0bc92d009fe 266 continue;
dreamselec 30:c0bc92d009fe 267 }
dreamselec 30:c0bc92d009fe 268 setIntegrationTimeTo(integrationTime);
dreamselec 30:c0bc92d009fe 269 } else if (this->commandIndex[i] == 2) {
dreamselec 30:c0bc92d009fe 270 if (this->commandValue[i] == "ON") {
dreamselec 30:c0bc92d009fe 271 previewOnPC(true);
dreamselec 30:c0bc92d009fe 272 } else if (this->commandValue[i] == "OFF") {
dreamselec 30:c0bc92d009fe 273 previewOnPC(false);
dreamselec 30:c0bc92d009fe 274 }
dreamselec 30:c0bc92d009fe 275 } else if (this->commandIndex[i] == 3 && runColourSensorTest == true && getColourSensorValue == false) {
dreamselec 30:c0bc92d009fe 276 getColourSensorValue = true;
dreamselec 30:c0bc92d009fe 277 } else if (this->commandIndex[i] == 4 && runColourSensorTest == true && getBlockColourValue == false) {
dreamselec 30:c0bc92d009fe 278 getBlockColourValue = true;
dreamselec 30:c0bc92d009fe 279 } else if (this->commandIndex[i] == 5) {
dreamselec 30:c0bc92d009fe 280 if (this->commandValue[i] == "start") {
dreamselec 30:c0bc92d009fe 281 testColourSensor(Start);
dreamselec 30:c0bc92d009fe 282 } else if (this->commandValue[i] == "pause") {
dreamselec 30:c0bc92d009fe 283 testColourSensor(Pause);
dreamselec 30:c0bc92d009fe 284 }
dreamselec 30:c0bc92d009fe 285 }
dreamselec 30:c0bc92d009fe 286 }
dreamselec 30:c0bc92d009fe 287 break;
dreamselec 30:c0bc92d009fe 288 case Servos:
dreamselec 30:c0bc92d009fe 289 for (int i = 0; i < sizeof(this->command)/sizeof(*this->command); i++) {
dreamselec 30:c0bc92d009fe 290 if (this->commandIndex[i] == -1 || this->commandIndex[i] == 0) {
dreamselec 30:c0bc92d009fe 291 break;
dreamselec 30:c0bc92d009fe 292 }
dreamselec 30:c0bc92d009fe 293 if (this->commandIndex[i] == 1) {
dreamselec 30:c0bc92d009fe 294 if (this->commandValue[i] == "start") {
dreamselec 30:c0bc92d009fe 295 testServos(Start);
dreamselec 30:c0bc92d009fe 296 } else if (this->commandValue[i] == "pause") {
dreamselec 30:c0bc92d009fe 297 testServos(Pause);
dreamselec 30:c0bc92d009fe 298 }
dreamselec 30:c0bc92d009fe 299 } else if (this->commandIndex[i] == 2) {
dreamselec 30:c0bc92d009fe 300 resetServos();
dreamselec 30:c0bc92d009fe 301 } else if (this->commandIndex[i] == 3) {
dreamselec 30:c0bc92d009fe 302 if (this->commandValue[i] == "1") {
dreamselec 30:c0bc92d009fe 303 pc.printf("INFO: Moving top servo.\n");
dreamselec 30:c0bc92d009fe 304 gToggleServoNumber = 1;
dreamselec 30:c0bc92d009fe 305 } else if (this->commandValue[i] == "2") {
dreamselec 30:c0bc92d009fe 306 pc.printf("INFO: Moving bottom servo.\n");
dreamselec 30:c0bc92d009fe 307 gToggleServoNumber = 2;
dreamselec 30:c0bc92d009fe 308 } else if (this->commandValue[i] == "3") {
dreamselec 30:c0bc92d009fe 309 pc.printf("INFO: Moving both servos.\n");
dreamselec 30:c0bc92d009fe 310 gToggleServoNumber = 3;
dreamselec 30:c0bc92d009fe 311 }
dreamselec 30:c0bc92d009fe 312 }
dreamselec 30:c0bc92d009fe 313 }
dreamselec 30:c0bc92d009fe 314 break;
dreamselec 30:c0bc92d009fe 315 case Port:
dreamselec 30:c0bc92d009fe 316 for (int i = 0; i < sizeof(this->command)/sizeof(*this->command); i++) {
dreamselec 30:c0bc92d009fe 317 if (this->commandIndex[i] == -1 || this->commandIndex[i] == 0) {
dreamselec 30:c0bc92d009fe 318 break;
dreamselec 30:c0bc92d009fe 319 }
dreamselec 30:c0bc92d009fe 320 if (this->commandIndex[i] == 1) {
dreamselec 30:c0bc92d009fe 321 getPortInfo();
dreamselec 30:c0bc92d009fe 322 } else if (this->commandIndex[i] == 2) {
dreamselec 30:c0bc92d009fe 323 int baudRate;
dreamselec 30:c0bc92d009fe 324 sscanf(this->commandValue[i].c_str(), "%i", &baudRate);
dreamselec 30:c0bc92d009fe 325 setPortBaudRate(baudRate);
dreamselec 30:c0bc92d009fe 326 } else if (this->commandIndex[i] == 3) {
dreamselec 30:c0bc92d009fe 327 int parity = 0;
dreamselec 30:c0bc92d009fe 328 sscanf(this->commandValue[i].c_str(), "%i", &parity);
dreamselec 30:c0bc92d009fe 329 setPortParity(parity);
dreamselec 30:c0bc92d009fe 330 }
dreamselec 30:c0bc92d009fe 331 }
dreamselec 30:c0bc92d009fe 332 break;
dreamselec 30:c0bc92d009fe 333 case BreakBeam:
dreamselec 30:c0bc92d009fe 334 for (int i = 0; i < sizeof(this->command)/sizeof(*this->command); i++) {
dreamselec 30:c0bc92d009fe 335 if (this->commandIndex[i] == -1 || this->commandIndex[i] == 0) {
dreamselec 30:c0bc92d009fe 336 break;
dreamselec 30:c0bc92d009fe 337 }
dreamselec 30:c0bc92d009fe 338 if (this->commandIndex[i] == 1) {
dreamselec 30:c0bc92d009fe 339 if (this->commandValue[i] == "start") {
dreamselec 30:c0bc92d009fe 340 testBreakBeams(Start);
dreamselec 30:c0bc92d009fe 341 } else if (this->commandValue[i] == "pause") {
dreamselec 30:c0bc92d009fe 342 testBreakBeams(Pause);
dreamselec 30:c0bc92d009fe 343 }
dreamselec 30:c0bc92d009fe 344 }
dreamselec 30:c0bc92d009fe 345 }
dreamselec 30:c0bc92d009fe 346 default:
dreamselec 30:c0bc92d009fe 347 break;
dreamselec 30:c0bc92d009fe 348 }
dreamselec 30:c0bc92d009fe 349 return;
dreamselec 15:777390eb5afd 350 }
dreamselec 8:e1da2ae62885 351
dreamselec 13:4f24da6e2f8e 352
dreamselec 15:777390eb5afd 353 void Commander::resetVariables()
dreamselec 15:777390eb5afd 354 {
dreamselec 30:c0bc92d009fe 355 this->object = "";
dreamselec 30:c0bc92d009fe 356 this->objectRaw = InvalidObject;
dreamselec 30:c0bc92d009fe 357 for (int i = 0; i < sizeof(this->command)/sizeof(*this->command); i ++) {
dreamselec 30:c0bc92d009fe 358 this->command[i].clear();
dreamselec 30:c0bc92d009fe 359 this->commandValue[i].clear();
dreamselec 30:c0bc92d009fe 360 this->commandIndex[i] = -1;
dreamselec 30:c0bc92d009fe 361 }
dreamselec 30:c0bc92d009fe 362 this->typeRaw = InvalidType;
dreamselec 30:c0bc92d009fe 363 this->typeChar = '\0';
dreamselec 15:777390eb5afd 364 }