Component Test's Software to work with "Universal Controller Box" - Software is an interpreter or "compiler" for programs to be done with a .txt file and read off of the SD Card
Dependencies: BridgeDriver FrontPanelButtons MCP23017 SDFileSystem TextLCD mbed
mainFunctions.cpp@9:5a0c4c6e39c7, 2014-09-24 (annotated)
- Committer:
- mehatfie
- Date:
- Wed Sep 24 22:23:00 2014 +0000
- Revision:
- 9:5a0c4c6e39c7
- System error checking and syntax checking should be completed; --- Compiled code still functions correctly; --- All error checking has not been checked that they indeed error out / not error out and function as planned
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mehatfie | 9:5a0c4c6e39c7 | 1 | //#include "mainFunctions.hpp" |
mehatfie | 9:5a0c4c6e39c7 | 2 | // |
mehatfie | 9:5a0c4c6e39c7 | 3 | ///******************************************************************************/ |
mehatfie | 9:5a0c4c6e39c7 | 4 | ///*** <Function: cyclePrograms> ***/ |
mehatfie | 9:5a0c4c6e39c7 | 5 | ///******************************************************************************/ |
mehatfie | 9:5a0c4c6e39c7 | 6 | // |
mehatfie | 9:5a0c4c6e39c7 | 7 | //int cyclePrograms(vector<string> files, int SIZE, int currIndex, int direction){ |
mehatfie | 9:5a0c4c6e39c7 | 8 | // |
mehatfie | 9:5a0c4c6e39c7 | 9 | // int nextIndex = 0; |
mehatfie | 9:5a0c4c6e39c7 | 10 | // switch(direction){ |
mehatfie | 9:5a0c4c6e39c7 | 11 | // case 0: //Cycle Back one File |
mehatfie | 9:5a0c4c6e39c7 | 12 | // if ((currIndex - 1) < 0) |
mehatfie | 9:5a0c4c6e39c7 | 13 | // nextIndex = SIZE - 1; |
mehatfie | 9:5a0c4c6e39c7 | 14 | // else |
mehatfie | 9:5a0c4c6e39c7 | 15 | // nextIndex = currIndex - 1; |
mehatfie | 9:5a0c4c6e39c7 | 16 | // break; |
mehatfie | 9:5a0c4c6e39c7 | 17 | // case 1: //Cycle Forward one File |
mehatfie | 9:5a0c4c6e39c7 | 18 | // if ((currIndex + 1) >= SIZE) |
mehatfie | 9:5a0c4c6e39c7 | 19 | // nextIndex = 0; |
mehatfie | 9:5a0c4c6e39c7 | 20 | // else |
mehatfie | 9:5a0c4c6e39c7 | 21 | // nextIndex = currIndex + 1; |
mehatfie | 9:5a0c4c6e39c7 | 22 | // break; |
mehatfie | 9:5a0c4c6e39c7 | 23 | // case -1: //set the selectedFile to the currIndex (used for initialization) |
mehatfie | 9:5a0c4c6e39c7 | 24 | // nextIndex = currIndex; |
mehatfie | 9:5a0c4c6e39c7 | 25 | // break; |
mehatfie | 9:5a0c4c6e39c7 | 26 | // } |
mehatfie | 9:5a0c4c6e39c7 | 27 | // |
mehatfie | 9:5a0c4c6e39c7 | 28 | // //Output file on Display |
mehatfie | 9:5a0c4c6e39c7 | 29 | // lcd.setAddress(0,3); |
mehatfie | 9:5a0c4c6e39c7 | 30 | // lcd.printf(" "); // Clear the Line using Spaces (Emptyness) - Note one line is 20 Characters |
mehatfie | 9:5a0c4c6e39c7 | 31 | // wait(.2); |
mehatfie | 9:5a0c4c6e39c7 | 32 | // lcd.setAddress(0,3); |
mehatfie | 9:5a0c4c6e39c7 | 33 | // lcd.printf("%s", files[nextIndex]); |
mehatfie | 9:5a0c4c6e39c7 | 34 | // |
mehatfie | 9:5a0c4c6e39c7 | 35 | // return nextIndex; // Return the file index in the Array |
mehatfie | 9:5a0c4c6e39c7 | 36 | //} |
mehatfie | 9:5a0c4c6e39c7 | 37 | // |
mehatfie | 9:5a0c4c6e39c7 | 38 | ///******************************************************************************/ |
mehatfie | 9:5a0c4c6e39c7 | 39 | ///*** <Function: resetLineData> ***/ |
mehatfie | 9:5a0c4c6e39c7 | 40 | ///******************************************************************************/ |
mehatfie | 9:5a0c4c6e39c7 | 41 | // |
mehatfie | 9:5a0c4c6e39c7 | 42 | //void resetLineData(LineData &lineData){ |
mehatfie | 9:5a0c4c6e39c7 | 43 | // |
mehatfie | 9:5a0c4c6e39c7 | 44 | // lineData.lineNumber = 0; |
mehatfie | 9:5a0c4c6e39c7 | 45 | // lineData.numWords = 0; |
mehatfie | 9:5a0c4c6e39c7 | 46 | // lineData.lineAddress = 0; |
mehatfie | 9:5a0c4c6e39c7 | 47 | //} |
mehatfie | 9:5a0c4c6e39c7 | 48 | // |
mehatfie | 9:5a0c4c6e39c7 | 49 | ///******************************************************************************/ |
mehatfie | 9:5a0c4c6e39c7 | 50 | ///*** <Function: interpretCommand> ***/ |
mehatfie | 9:5a0c4c6e39c7 | 51 | ///******************************************************************************/ |
mehatfie | 9:5a0c4c6e39c7 | 52 | // |
mehatfie | 9:5a0c4c6e39c7 | 53 | //int interpretCommand(FILE *selectedFile, LineData &lineData){ |
mehatfie | 9:5a0c4c6e39c7 | 54 | // |
mehatfie | 9:5a0c4c6e39c7 | 55 | // if (lineData.word[0].compare("device") == 0){ |
mehatfie | 9:5a0c4c6e39c7 | 56 | // |
mehatfie | 9:5a0c4c6e39c7 | 57 | // int i = 0, deviceFound = -1; |
mehatfie | 9:5a0c4c6e39c7 | 58 | // for (i = 0; i < numDevices; i++){ |
mehatfie | 9:5a0c4c6e39c7 | 59 | // if (lineData.word[2].compare(DeviceNames[i]) == 0){ |
mehatfie | 9:5a0c4c6e39c7 | 60 | // deviceFound = i; |
mehatfie | 9:5a0c4c6e39c7 | 61 | // } |
mehatfie | 9:5a0c4c6e39c7 | 62 | // } |
mehatfie | 9:5a0c4c6e39c7 | 63 | // |
mehatfie | 9:5a0c4c6e39c7 | 64 | // //if the device type does not match any known type, error out |
mehatfie | 9:5a0c4c6e39c7 | 65 | // if (deviceFound == -1){ |
mehatfie | 9:5a0c4c6e39c7 | 66 | // //Error Out since the device Name was not matched with anything ************************* |
mehatfie | 9:5a0c4c6e39c7 | 67 | // } |
mehatfie | 9:5a0c4c6e39c7 | 68 | // |
mehatfie | 9:5a0c4c6e39c7 | 69 | // //Add device to the array of devices and initialize it |
mehatfie | 9:5a0c4c6e39c7 | 70 | // else{ |
mehatfie | 9:5a0c4c6e39c7 | 71 | // devices.push_back(Device::newDevice(deviceFound, lineData.word[1], lineData)); |
mehatfie | 9:5a0c4c6e39c7 | 72 | // devices.back()->name = lineData.word[1]; |
mehatfie | 9:5a0c4c6e39c7 | 73 | // } |
mehatfie | 9:5a0c4c6e39c7 | 74 | // } |
mehatfie | 9:5a0c4c6e39c7 | 75 | // |
mehatfie | 9:5a0c4c6e39c7 | 76 | // else if (lineData.word[0].compare("delay") == 0){ |
mehatfie | 9:5a0c4c6e39c7 | 77 | // string duration = lineData.word[1]; |
mehatfie | 9:5a0c4c6e39c7 | 78 | // int durationValue = 0; |
mehatfie | 9:5a0c4c6e39c7 | 79 | // sscanf(duration.c_str(), "%d", &durationValue); |
mehatfie | 9:5a0c4c6e39c7 | 80 | // |
mehatfie | 9:5a0c4c6e39c7 | 81 | // if (durationValue){ |
mehatfie | 9:5a0c4c6e39c7 | 82 | // timer.reset(); |
mehatfie | 9:5a0c4c6e39c7 | 83 | // timer.start(); |
mehatfie | 9:5a0c4c6e39c7 | 84 | // while (timer.read_ms() < durationValue); //Do Nothing while the timer has not reached the duration |
mehatfie | 9:5a0c4c6e39c7 | 85 | // timer.stop(); //Stop the Timer |
mehatfie | 9:5a0c4c6e39c7 | 86 | // } |
mehatfie | 9:5a0c4c6e39c7 | 87 | // else{ |
mehatfie | 9:5a0c4c6e39c7 | 88 | // //Error Out |
mehatfie | 9:5a0c4c6e39c7 | 89 | // return -1; |
mehatfie | 9:5a0c4c6e39c7 | 90 | // } |
mehatfie | 9:5a0c4c6e39c7 | 91 | // } |
mehatfie | 9:5a0c4c6e39c7 | 92 | // |
mehatfie | 9:5a0c4c6e39c7 | 93 | // else if (lineData.word[0].compare("loop") == 0){ |
mehatfie | 9:5a0c4c6e39c7 | 94 | // int checkLoopEnd = loopCommand(selectedFile, lineData); |
mehatfie | 9:5a0c4c6e39c7 | 95 | // if (checkLoopEnd == 1) |
mehatfie | 9:5a0c4c6e39c7 | 96 | // return 1; |
mehatfie | 9:5a0c4c6e39c7 | 97 | // } |
mehatfie | 9:5a0c4c6e39c7 | 98 | // |
mehatfie | 9:5a0c4c6e39c7 | 99 | // else if (lineData.word[0].compare("condition") == 0){ |
mehatfie | 9:5a0c4c6e39c7 | 100 | // int checkLoopEnd = conditionCommand(selectedFile, lineData); |
mehatfie | 9:5a0c4c6e39c7 | 101 | // if (checkLoopEnd == 1) |
mehatfie | 9:5a0c4c6e39c7 | 102 | // return 2; |
mehatfie | 9:5a0c4c6e39c7 | 103 | // } |
mehatfie | 9:5a0c4c6e39c7 | 104 | // // end with custom return value for specific function |
mehatfie | 9:5a0c4c6e39c7 | 105 | // else if (lineData.word[0].compare("end") == 0){ |
mehatfie | 9:5a0c4c6e39c7 | 106 | // if (lineData.word[1].compare("program") == 0){ |
mehatfie | 9:5a0c4c6e39c7 | 107 | // return 2; |
mehatfie | 9:5a0c4c6e39c7 | 108 | // } |
mehatfie | 9:5a0c4c6e39c7 | 109 | // else if (lineData.word[1].compare("loop") == 0){ |
mehatfie | 9:5a0c4c6e39c7 | 110 | // return 3; |
mehatfie | 9:5a0c4c6e39c7 | 111 | // } |
mehatfie | 9:5a0c4c6e39c7 | 112 | // else if (lineData.word[1].compare("condition") == 0){ |
mehatfie | 9:5a0c4c6e39c7 | 113 | // return 4; |
mehatfie | 9:5a0c4c6e39c7 | 114 | // } |
mehatfie | 9:5a0c4c6e39c7 | 115 | // } |
mehatfie | 9:5a0c4c6e39c7 | 116 | // |
mehatfie | 9:5a0c4c6e39c7 | 117 | // //not a keyword so check if it's a localName for a device |
mehatfie | 9:5a0c4c6e39c7 | 118 | // else{ |
mehatfie | 9:5a0c4c6e39c7 | 119 | // |
mehatfie | 9:5a0c4c6e39c7 | 120 | // int i = 0, deviceFound = -1; |
mehatfie | 9:5a0c4c6e39c7 | 121 | // for (i = 0; i < devices.size(); i++){ |
mehatfie | 9:5a0c4c6e39c7 | 122 | // if (lineData.word[0].compare(devices[i]->name) == 0) |
mehatfie | 9:5a0c4c6e39c7 | 123 | // deviceFound = i; |
mehatfie | 9:5a0c4c6e39c7 | 124 | // } |
mehatfie | 9:5a0c4c6e39c7 | 125 | // |
mehatfie | 9:5a0c4c6e39c7 | 126 | // //no device was found that matched the local name, and this is also the last error check, meaning it can match no other potential keywords |
mehatfie | 9:5a0c4c6e39c7 | 127 | // if (deviceFound == -1){ |
mehatfie | 9:5a0c4c6e39c7 | 128 | // lcd.setAddress(0,3); |
mehatfie | 9:5a0c4c6e39c7 | 129 | // lcd.printf("Final ERROR!"); |
mehatfie | 9:5a0c4c6e39c7 | 130 | // wait(10); |
mehatfie | 9:5a0c4c6e39c7 | 131 | // } |
mehatfie | 9:5a0c4c6e39c7 | 132 | // |
mehatfie | 9:5a0c4c6e39c7 | 133 | // //Local Name matches a device, send line to that device in order to process the functionality |
mehatfie | 9:5a0c4c6e39c7 | 134 | // else{ |
mehatfie | 9:5a0c4c6e39c7 | 135 | // //addDevice(deviceFound); |
mehatfie | 9:5a0c4c6e39c7 | 136 | // return devices[deviceFound]->interpret(lineData); |
mehatfie | 9:5a0c4c6e39c7 | 137 | // } |
mehatfie | 9:5a0c4c6e39c7 | 138 | // } |
mehatfie | 9:5a0c4c6e39c7 | 139 | // |
mehatfie | 9:5a0c4c6e39c7 | 140 | // return -1; |
mehatfie | 9:5a0c4c6e39c7 | 141 | //} |
mehatfie | 9:5a0c4c6e39c7 | 142 | // |
mehatfie | 9:5a0c4c6e39c7 | 143 | ///******************************************************************************/ |
mehatfie | 9:5a0c4c6e39c7 | 144 | ///*** <Function: loopCommand> ***/ |
mehatfie | 9:5a0c4c6e39c7 | 145 | ///******************************************************************************/ |
mehatfie | 9:5a0c4c6e39c7 | 146 | // |
mehatfie | 9:5a0c4c6e39c7 | 147 | //int loopCommand(FILE *selectedFile, LineData &lineData){ |
mehatfie | 9:5a0c4c6e39c7 | 148 | // |
mehatfie | 9:5a0c4c6e39c7 | 149 | // //Get the Condition value for number of times to loop |
mehatfie | 9:5a0c4c6e39c7 | 150 | // string loopCondition = lineData.word[1]; |
mehatfie | 9:5a0c4c6e39c7 | 151 | // int loopConditionValue = 0; |
mehatfie | 9:5a0c4c6e39c7 | 152 | // sscanf(loopCondition.c_str(), "%d", &loopConditionValue); |
mehatfie | 9:5a0c4c6e39c7 | 153 | // |
mehatfie | 9:5a0c4c6e39c7 | 154 | // int loopStartAddress = 0, loopLineNumber = 0, firstLineOfLoop = 1; |
mehatfie | 9:5a0c4c6e39c7 | 155 | // |
mehatfie | 9:5a0c4c6e39c7 | 156 | // lcd.setAddress(0,0); |
mehatfie | 9:5a0c4c6e39c7 | 157 | // lcd.printf("Cycle 1 of %d", loopConditionValue); |
mehatfie | 9:5a0c4c6e39c7 | 158 | // |
mehatfie | 9:5a0c4c6e39c7 | 159 | // Timer cycleTimer; |
mehatfie | 9:5a0c4c6e39c7 | 160 | // float totalLoopTime = 0; |
mehatfie | 9:5a0c4c6e39c7 | 161 | // cycleTimer.reset(); |
mehatfie | 9:5a0c4c6e39c7 | 162 | // cycleTimer.start(); |
mehatfie | 9:5a0c4c6e39c7 | 163 | // |
mehatfie | 9:5a0c4c6e39c7 | 164 | // int counter = 1, checkEnd = 0; |
mehatfie | 9:5a0c4c6e39c7 | 165 | // while (counter <= loopConditionValue){ |
mehatfie | 9:5a0c4c6e39c7 | 166 | // |
mehatfie | 9:5a0c4c6e39c7 | 167 | // getNextLine(selectedFile, lineData); |
mehatfie | 9:5a0c4c6e39c7 | 168 | // |
mehatfie | 9:5a0c4c6e39c7 | 169 | // //Must get the address before entering the interpret command |
mehatfie | 9:5a0c4c6e39c7 | 170 | // // if a Condition command is immediately after, and the condition fails, then |
mehatfie | 9:5a0c4c6e39c7 | 171 | // // the interpret command will return the line at the "end condition" line, and therefore |
mehatfie | 9:5a0c4c6e39c7 | 172 | // // set the loop's first line to be the "end condition" line, if interpretCommand is called BEFORE setting the first loop line address |
mehatfie | 9:5a0c4c6e39c7 | 173 | // if (firstLineOfLoop){ |
mehatfie | 9:5a0c4c6e39c7 | 174 | // loopStartAddress = lineData.lineAddress; //Save the Line Address |
mehatfie | 9:5a0c4c6e39c7 | 175 | // loopLineNumber = lineData.lineNumber; //Save the Line Number |
mehatfie | 9:5a0c4c6e39c7 | 176 | // firstLineOfLoop = 0; |
mehatfie | 9:5a0c4c6e39c7 | 177 | // } |
mehatfie | 9:5a0c4c6e39c7 | 178 | // |
mehatfie | 9:5a0c4c6e39c7 | 179 | // checkEnd = interpretCommand(selectedFile, lineData); |
mehatfie | 9:5a0c4c6e39c7 | 180 | // |
mehatfie | 9:5a0c4c6e39c7 | 181 | // //Increase the loop counter and go back to the beginning of the loop |
mehatfie | 9:5a0c4c6e39c7 | 182 | // if (checkEnd == 3){ |
mehatfie | 9:5a0c4c6e39c7 | 183 | // |
mehatfie | 9:5a0c4c6e39c7 | 184 | // //Output the Avg Cycle Time |
mehatfie | 9:5a0c4c6e39c7 | 185 | // cycleTimer.stop(); |
mehatfie | 9:5a0c4c6e39c7 | 186 | // totalLoopTime += cycleTimer.read(); |
mehatfie | 9:5a0c4c6e39c7 | 187 | // |
mehatfie | 9:5a0c4c6e39c7 | 188 | // lcd.setAddress(0,1); |
mehatfie | 9:5a0c4c6e39c7 | 189 | // lcd.printf("Avg t(sec): %1.3f", (totalLoopTime / counter)); |
mehatfie | 9:5a0c4c6e39c7 | 190 | // |
mehatfie | 9:5a0c4c6e39c7 | 191 | // //Output Cycle Number |
mehatfie | 9:5a0c4c6e39c7 | 192 | // counter++; |
mehatfie | 9:5a0c4c6e39c7 | 193 | // lcd.setAddress(0,0); |
mehatfie | 9:5a0c4c6e39c7 | 194 | // lcd.printf("Cycle %d of %d", counter, loopConditionValue); |
mehatfie | 9:5a0c4c6e39c7 | 195 | // |
mehatfie | 9:5a0c4c6e39c7 | 196 | // fseek(selectedFile, loopStartAddress, SEEK_SET); |
mehatfie | 9:5a0c4c6e39c7 | 197 | // lineData.lineNumber = loopLineNumber - 2; |
mehatfie | 9:5a0c4c6e39c7 | 198 | // checkEnd = 0; |
mehatfie | 9:5a0c4c6e39c7 | 199 | // |
mehatfie | 9:5a0c4c6e39c7 | 200 | // //Restart the timer for the next loop |
mehatfie | 9:5a0c4c6e39c7 | 201 | // cycleTimer.reset(); |
mehatfie | 9:5a0c4c6e39c7 | 202 | // cycleTimer.start(); |
mehatfie | 9:5a0c4c6e39c7 | 203 | // } |
mehatfie | 9:5a0c4c6e39c7 | 204 | // } |
mehatfie | 9:5a0c4c6e39c7 | 205 | // |
mehatfie | 9:5a0c4c6e39c7 | 206 | // return 1; |
mehatfie | 9:5a0c4c6e39c7 | 207 | // } |
mehatfie | 9:5a0c4c6e39c7 | 208 | // |
mehatfie | 9:5a0c4c6e39c7 | 209 | ///******************************************************************************/ |
mehatfie | 9:5a0c4c6e39c7 | 210 | ///*** <Function: conditionCommand> ***/ |
mehatfie | 9:5a0c4c6e39c7 | 211 | ///******************************************************************************/ |
mehatfie | 9:5a0c4c6e39c7 | 212 | // |
mehatfie | 9:5a0c4c6e39c7 | 213 | //int conditionCommand(FILE *selectedFile, LineData &lineData){ |
mehatfie | 9:5a0c4c6e39c7 | 214 | // |
mehatfie | 9:5a0c4c6e39c7 | 215 | // //Get the number of condition parameters |
mehatfie | 9:5a0c4c6e39c7 | 216 | // string numConditionVals = lineData.word[1]; |
mehatfie | 9:5a0c4c6e39c7 | 217 | // int numConditionValues = 0; |
mehatfie | 9:5a0c4c6e39c7 | 218 | // sscanf(numConditionVals.c_str(), "%d", &numConditionValues); |
mehatfie | 9:5a0c4c6e39c7 | 219 | // |
mehatfie | 9:5a0c4c6e39c7 | 220 | // //LineData tempLineData; |
mehatfie | 9:5a0c4c6e39c7 | 221 | // LineData param[15]; |
mehatfie | 9:5a0c4c6e39c7 | 222 | // //vector<LineData> param; |
mehatfie | 9:5a0c4c6e39c7 | 223 | // vector<ConditionOp> paramCondition; |
mehatfie | 9:5a0c4c6e39c7 | 224 | // |
mehatfie | 9:5a0c4c6e39c7 | 225 | // |
mehatfie | 9:5a0c4c6e39c7 | 226 | // //Fill the param Vector with Line structs of each individual device, this way we can send the Line struct to the appropriate interpret function without modification within the function itself |
mehatfie | 9:5a0c4c6e39c7 | 227 | // int i = 2, numParam = 0, paramNumWords = 0; |
mehatfie | 9:5a0c4c6e39c7 | 228 | // for (i = 2; i < lineData.numWords; i++){ |
mehatfie | 9:5a0c4c6e39c7 | 229 | // |
mehatfie | 9:5a0c4c6e39c7 | 230 | // // if the word is not an AND or an OR, it must mean it's for the specific function |
mehatfie | 9:5a0c4c6e39c7 | 231 | // // set the current parameter's next word to be equal to the current word we're checking |
mehatfie | 9:5a0c4c6e39c7 | 232 | // // increase number of words that the parameter has |
mehatfie | 9:5a0c4c6e39c7 | 233 | // if (lineData.word[i] != "AND" && lineData.word[i] != "xAND" && lineData.word[i] != "OR" && lineData.word[i] != "xOR"){ |
mehatfie | 9:5a0c4c6e39c7 | 234 | // |
mehatfie | 9:5a0c4c6e39c7 | 235 | // //tempLineData.word[paramNumWords] = lineData.word[i]; |
mehatfie | 9:5a0c4c6e39c7 | 236 | // param[numParam].word[paramNumWords] = lineData.word[i]; |
mehatfie | 9:5a0c4c6e39c7 | 237 | // paramNumWords++; |
mehatfie | 9:5a0c4c6e39c7 | 238 | // |
mehatfie | 9:5a0c4c6e39c7 | 239 | // //if this is the last word in the line.... |
mehatfie | 9:5a0c4c6e39c7 | 240 | // if(i == (lineData.numWords - 1)){ |
mehatfie | 9:5a0c4c6e39c7 | 241 | // param[numParam].numWords = paramNumWords; |
mehatfie | 9:5a0c4c6e39c7 | 242 | // paramCondition[numParam].op = NONE; |
mehatfie | 9:5a0c4c6e39c7 | 243 | // numParam++; |
mehatfie | 9:5a0c4c6e39c7 | 244 | // } |
mehatfie | 9:5a0c4c6e39c7 | 245 | // |
mehatfie | 9:5a0c4c6e39c7 | 246 | // } |
mehatfie | 9:5a0c4c6e39c7 | 247 | // |
mehatfie | 9:5a0c4c6e39c7 | 248 | // // if the word is an AND or an OR, it must mean the last function has been completely identified |
mehatfie | 9:5a0c4c6e39c7 | 249 | // // set the parameters number of Words value to the calculated value |
mehatfie | 9:5a0c4c6e39c7 | 250 | // // increase the number of Parameters (the current parameter function we're filling) |
mehatfie | 9:5a0c4c6e39c7 | 251 | // else if (lineData.word[i].compare("AND") == 0 || lineData.word[i].compare("xAND") == 0 || lineData.word[i].compare("OR") == 0 || lineData.word[i].compare("xOR") == 0){ |
mehatfie | 9:5a0c4c6e39c7 | 252 | // |
mehatfie | 9:5a0c4c6e39c7 | 253 | // //tempLineData.numWords = paramNumWords; |
mehatfie | 9:5a0c4c6e39c7 | 254 | // param[numParam].numWords = paramNumWords; |
mehatfie | 9:5a0c4c6e39c7 | 255 | // |
mehatfie | 9:5a0c4c6e39c7 | 256 | // paramCondition.push_back(ConditionOp()); |
mehatfie | 9:5a0c4c6e39c7 | 257 | // if (lineData.word[i].compare("AND") == 0) |
mehatfie | 9:5a0c4c6e39c7 | 258 | // paramCondition[numParam].op = AND; |
mehatfie | 9:5a0c4c6e39c7 | 259 | // else if (lineData.word[i].compare("xAND") == 0) |
mehatfie | 9:5a0c4c6e39c7 | 260 | // paramCondition[numParam].op = xAND; |
mehatfie | 9:5a0c4c6e39c7 | 261 | // else if (lineData.word[i].compare("OR") == 0) |
mehatfie | 9:5a0c4c6e39c7 | 262 | // paramCondition[numParam].op = OR; |
mehatfie | 9:5a0c4c6e39c7 | 263 | // else if (lineData.word[i].compare("xOR") == 0) |
mehatfie | 9:5a0c4c6e39c7 | 264 | // paramCondition[numParam].op = xOR; |
mehatfie | 9:5a0c4c6e39c7 | 265 | // |
mehatfie | 9:5a0c4c6e39c7 | 266 | // //param.push_back(LineData()); |
mehatfie | 9:5a0c4c6e39c7 | 267 | // //param[numParam] = tempLineData; |
mehatfie | 9:5a0c4c6e39c7 | 268 | // //param.push_back(tempLineData); //add it to the vector list of parameters |
mehatfie | 9:5a0c4c6e39c7 | 269 | // //tempLineData = LineData(); //reset |
mehatfie | 9:5a0c4c6e39c7 | 270 | // numParam++; // increase the index of param |
mehatfie | 9:5a0c4c6e39c7 | 271 | // paramNumWords = 0; // reset the number of words |
mehatfie | 9:5a0c4c6e39c7 | 272 | // } |
mehatfie | 9:5a0c4c6e39c7 | 273 | // } |
mehatfie | 9:5a0c4c6e39c7 | 274 | // |
mehatfie | 9:5a0c4c6e39c7 | 275 | // |
mehatfie | 9:5a0c4c6e39c7 | 276 | // vector<ConditionOp> combinedCondition; |
mehatfie | 9:5a0c4c6e39c7 | 277 | // ConditionOp tempCombinedCondition; |
mehatfie | 9:5a0c4c6e39c7 | 278 | // int j = 0, k = 0; |
mehatfie | 9:5a0c4c6e39c7 | 279 | // for (j = 0; j < numParam; j++){ |
mehatfie | 9:5a0c4c6e39c7 | 280 | // paramCondition[j].value = interpretCommand(selectedFile, param[j]); |
mehatfie | 9:5a0c4c6e39c7 | 281 | // } |
mehatfie | 9:5a0c4c6e39c7 | 282 | // |
mehatfie | 9:5a0c4c6e39c7 | 283 | // //create the combined Condition vector (take care of this xAND and xOR statements and combine them into one so that the whole vector is just AND's and OR's) |
mehatfie | 9:5a0c4c6e39c7 | 284 | // //this should make the xAND's / xOR's into a single member of the combinedCondition vector |
mehatfie | 9:5a0c4c6e39c7 | 285 | // enum ConditionType prevCondition = NONE; |
mehatfie | 9:5a0c4c6e39c7 | 286 | // int first = 1, last = 0; |
mehatfie | 9:5a0c4c6e39c7 | 287 | // for (k = 0; k < numParam; k++){ |
mehatfie | 9:5a0c4c6e39c7 | 288 | // |
mehatfie | 9:5a0c4c6e39c7 | 289 | // if (k == numParam - 1) |
mehatfie | 9:5a0c4c6e39c7 | 290 | // last = 1; |
mehatfie | 9:5a0c4c6e39c7 | 291 | // |
mehatfie | 9:5a0c4c6e39c7 | 292 | // if (!last){ |
mehatfie | 9:5a0c4c6e39c7 | 293 | // if (paramCondition[k].op != xAND && paramCondition[k].op != xOR && paramCondition[k + 1].op != xAND && paramCondition[k + 1].op != xOR){ |
mehatfie | 9:5a0c4c6e39c7 | 294 | // //AND |
mehatfie | 9:5a0c4c6e39c7 | 295 | // if (paramCondition[k].op == AND){ |
mehatfie | 9:5a0c4c6e39c7 | 296 | // if (!first && prevCondition != xAND && prevCondition != xOR) |
mehatfie | 9:5a0c4c6e39c7 | 297 | // combinedCondition.back().value = combinedCondition.back().value && paramCondition[k + 1].value; |
mehatfie | 9:5a0c4c6e39c7 | 298 | // else if (first || prevCondition == xAND || prevCondition == xOR){ |
mehatfie | 9:5a0c4c6e39c7 | 299 | // tempCombinedCondition.value = paramCondition[k].value && paramCondition[k + 1].value; |
mehatfie | 9:5a0c4c6e39c7 | 300 | // combinedCondition.push_back(tempCombinedCondition); |
mehatfie | 9:5a0c4c6e39c7 | 301 | // first = 0; |
mehatfie | 9:5a0c4c6e39c7 | 302 | // } |
mehatfie | 9:5a0c4c6e39c7 | 303 | // prevCondition = AND; |
mehatfie | 9:5a0c4c6e39c7 | 304 | // } |
mehatfie | 9:5a0c4c6e39c7 | 305 | // |
mehatfie | 9:5a0c4c6e39c7 | 306 | // //OR |
mehatfie | 9:5a0c4c6e39c7 | 307 | // else if (paramCondition[k].op == OR){ |
mehatfie | 9:5a0c4c6e39c7 | 308 | // if (!first && prevCondition != xAND && prevCondition != xOR) |
mehatfie | 9:5a0c4c6e39c7 | 309 | // combinedCondition.back().value = combinedCondition.back().value || paramCondition[k + 1].value; |
mehatfie | 9:5a0c4c6e39c7 | 310 | // else if (first || prevCondition == xAND || prevCondition == xOR){ |
mehatfie | 9:5a0c4c6e39c7 | 311 | // tempCombinedCondition.value = paramCondition[k].value || paramCondition[k + 1].value; |
mehatfie | 9:5a0c4c6e39c7 | 312 | // combinedCondition.push_back(tempCombinedCondition); |
mehatfie | 9:5a0c4c6e39c7 | 313 | // first = 0; |
mehatfie | 9:5a0c4c6e39c7 | 314 | // } |
mehatfie | 9:5a0c4c6e39c7 | 315 | // prevCondition = OR; |
mehatfie | 9:5a0c4c6e39c7 | 316 | // } |
mehatfie | 9:5a0c4c6e39c7 | 317 | // } |
mehatfie | 9:5a0c4c6e39c7 | 318 | // |
mehatfie | 9:5a0c4c6e39c7 | 319 | // // first value is something, not exclusive, but next values are exclusive |
mehatfie | 9:5a0c4c6e39c7 | 320 | // else if (first && (paramCondition[k].op == AND || paramCondition[k].op == OR) && (paramCondition[k + 1].op == xAND || paramCondition[k + 1].op == xOR)){ |
mehatfie | 9:5a0c4c6e39c7 | 321 | // tempCombinedCondition.value = paramCondition[k].value; |
mehatfie | 9:5a0c4c6e39c7 | 322 | // tempCombinedCondition.op = paramCondition[k].op; |
mehatfie | 9:5a0c4c6e39c7 | 323 | // combinedCondition.push_back(tempCombinedCondition); |
mehatfie | 9:5a0c4c6e39c7 | 324 | // prevCondition = paramCondition[k].op; |
mehatfie | 9:5a0c4c6e39c7 | 325 | // first = 0; |
mehatfie | 9:5a0c4c6e39c7 | 326 | // } |
mehatfie | 9:5a0c4c6e39c7 | 327 | // |
mehatfie | 9:5a0c4c6e39c7 | 328 | // else{ |
mehatfie | 9:5a0c4c6e39c7 | 329 | // //xAND |
mehatfie | 9:5a0c4c6e39c7 | 330 | // if (paramCondition[k].op == xAND){ |
mehatfie | 9:5a0c4c6e39c7 | 331 | // if (combinedCondition.size() == 0){ // No values so start a new combinedCondition |
mehatfie | 9:5a0c4c6e39c7 | 332 | // tempCombinedCondition.value = paramCondition[k].value && paramCondition[k + 1].value; |
mehatfie | 9:5a0c4c6e39c7 | 333 | // tempCombinedCondition.op = xAND; |
mehatfie | 9:5a0c4c6e39c7 | 334 | // combinedCondition.push_back(tempCombinedCondition); |
mehatfie | 9:5a0c4c6e39c7 | 335 | // prevCondition = xAND; |
mehatfie | 9:5a0c4c6e39c7 | 336 | // } |
mehatfie | 9:5a0c4c6e39c7 | 337 | // else{ |
mehatfie | 9:5a0c4c6e39c7 | 338 | // if (combinedCondition.back().op == xAND){ // AND the value to the back most combinedCondition |
mehatfie | 9:5a0c4c6e39c7 | 339 | // combinedCondition.back().value = combinedCondition.back().value && paramCondition[k + 1].value; |
mehatfie | 9:5a0c4c6e39c7 | 340 | // prevCondition = xAND; |
mehatfie | 9:5a0c4c6e39c7 | 341 | // } |
mehatfie | 9:5a0c4c6e39c7 | 342 | // else if (combinedCondition.back().op != xAND){ // Start a new combinedCondition |
mehatfie | 9:5a0c4c6e39c7 | 343 | // tempCombinedCondition.value = paramCondition[k].value && paramCondition[k + 1].value; |
mehatfie | 9:5a0c4c6e39c7 | 344 | // tempCombinedCondition.op = xAND; |
mehatfie | 9:5a0c4c6e39c7 | 345 | // combinedCondition.push_back(tempCombinedCondition); |
mehatfie | 9:5a0c4c6e39c7 | 346 | // prevCondition = xAND; |
mehatfie | 9:5a0c4c6e39c7 | 347 | // } |
mehatfie | 9:5a0c4c6e39c7 | 348 | // } |
mehatfie | 9:5a0c4c6e39c7 | 349 | // |
mehatfie | 9:5a0c4c6e39c7 | 350 | // } |
mehatfie | 9:5a0c4c6e39c7 | 351 | // |
mehatfie | 9:5a0c4c6e39c7 | 352 | // //xOR |
mehatfie | 9:5a0c4c6e39c7 | 353 | // else if (paramCondition[k].op == xOR){ |
mehatfie | 9:5a0c4c6e39c7 | 354 | // if (combinedCondition.size() == 0){ // No values so start a new combinedCondition |
mehatfie | 9:5a0c4c6e39c7 | 355 | // tempCombinedCondition.value = paramCondition[k].value || paramCondition[k + 1].value; |
mehatfie | 9:5a0c4c6e39c7 | 356 | // tempCombinedCondition.op = xOR; |
mehatfie | 9:5a0c4c6e39c7 | 357 | // combinedCondition.push_back(tempCombinedCondition); |
mehatfie | 9:5a0c4c6e39c7 | 358 | // prevCondition = xOR; |
mehatfie | 9:5a0c4c6e39c7 | 359 | // } |
mehatfie | 9:5a0c4c6e39c7 | 360 | // else{ |
mehatfie | 9:5a0c4c6e39c7 | 361 | // if (combinedCondition.back().op == xOR){ // OR the value to the back most combinedCondition |
mehatfie | 9:5a0c4c6e39c7 | 362 | // combinedCondition.back().value = combinedCondition.back().value || paramCondition[k + 1].value; |
mehatfie | 9:5a0c4c6e39c7 | 363 | // prevCondition = xOR; |
mehatfie | 9:5a0c4c6e39c7 | 364 | // } |
mehatfie | 9:5a0c4c6e39c7 | 365 | // else if (combinedCondition.back().op != xOR){ // Start a new combinedCondition |
mehatfie | 9:5a0c4c6e39c7 | 366 | // tempCombinedCondition.value = paramCondition[k].value || paramCondition[k + 1].value; |
mehatfie | 9:5a0c4c6e39c7 | 367 | // tempCombinedCondition.op = xOR; |
mehatfie | 9:5a0c4c6e39c7 | 368 | // combinedCondition.push_back(tempCombinedCondition); |
mehatfie | 9:5a0c4c6e39c7 | 369 | // prevCondition = xOR; |
mehatfie | 9:5a0c4c6e39c7 | 370 | // } |
mehatfie | 9:5a0c4c6e39c7 | 371 | // } |
mehatfie | 9:5a0c4c6e39c7 | 372 | // |
mehatfie | 9:5a0c4c6e39c7 | 373 | // } |
mehatfie | 9:5a0c4c6e39c7 | 374 | // |
mehatfie | 9:5a0c4c6e39c7 | 375 | // // Since the k + 1 value is included in the xAND or xOR exclusively, skip checking that value, and add the appropriate AND / OR as the |
mehatfie | 9:5a0c4c6e39c7 | 376 | // // operator of this exclusive xAND / xOR set |
mehatfie | 9:5a0c4c6e39c7 | 377 | // if ((paramCondition[k + 1].op == AND || paramCondition[k + 1].op == OR) && (prevCondition == xAND || prevCondition == xOR)){ |
mehatfie | 9:5a0c4c6e39c7 | 378 | // combinedCondition.back().op = paramCondition[k + 1].op; |
mehatfie | 9:5a0c4c6e39c7 | 379 | // k++; |
mehatfie | 9:5a0c4c6e39c7 | 380 | // } |
mehatfie | 9:5a0c4c6e39c7 | 381 | // |
mehatfie | 9:5a0c4c6e39c7 | 382 | // } |
mehatfie | 9:5a0c4c6e39c7 | 383 | // } |
mehatfie | 9:5a0c4c6e39c7 | 384 | // |
mehatfie | 9:5a0c4c6e39c7 | 385 | // |
mehatfie | 9:5a0c4c6e39c7 | 386 | // // the last value was not included in any combination, since directly before the last value was an xAND / xOR set that |
mehatfie | 9:5a0c4c6e39c7 | 387 | // // included the very last AND / OR as the set's operator, yet there is still another value that has not been combined, as it is supposed |
mehatfie | 9:5a0c4c6e39c7 | 388 | // // to be AND /OR to the exclusive xAND / xOR set |
mehatfie | 9:5a0c4c6e39c7 | 389 | // else if (last && (prevCondition == xAND || prevCondition == xOR) && (combinedCondition.back().op == AND || combinedCondition.back().op == OR)){ |
mehatfie | 9:5a0c4c6e39c7 | 390 | // tempCombinedCondition.value = paramCondition[k].value; |
mehatfie | 9:5a0c4c6e39c7 | 391 | // tempCombinedCondition.op = NONE; |
mehatfie | 9:5a0c4c6e39c7 | 392 | // combinedCondition.push_back(tempCombinedCondition); |
mehatfie | 9:5a0c4c6e39c7 | 393 | // } |
mehatfie | 9:5a0c4c6e39c7 | 394 | // |
mehatfie | 9:5a0c4c6e39c7 | 395 | // //reset the tempCombinedCondition variable |
mehatfie | 9:5a0c4c6e39c7 | 396 | // tempCombinedCondition = ConditionOp(); |
mehatfie | 9:5a0c4c6e39c7 | 397 | // } |
mehatfie | 9:5a0c4c6e39c7 | 398 | // |
mehatfie | 9:5a0c4c6e39c7 | 399 | // |
mehatfie | 9:5a0c4c6e39c7 | 400 | // // run through all values in the combined Condition vector, AND'ing / OR'ing as appropriate |
mehatfie | 9:5a0c4c6e39c7 | 401 | // // in the end, the last value in the array should be the final condition of the Condition statement... whether it was successful or failed |
mehatfie | 9:5a0c4c6e39c7 | 402 | // for (i = 0; i < (combinedCondition.size() - 1); i++){ |
mehatfie | 9:5a0c4c6e39c7 | 403 | // if (combinedCondition[i].op == AND) |
mehatfie | 9:5a0c4c6e39c7 | 404 | // combinedCondition[i + 1].value = combinedCondition[i].value && combinedCondition[i + 1].value; |
mehatfie | 9:5a0c4c6e39c7 | 405 | // else if (combinedCondition[i].op == OR) |
mehatfie | 9:5a0c4c6e39c7 | 406 | // combinedCondition[i + 1].value = combinedCondition[i].value || combinedCondition[i + 1].value; |
mehatfie | 9:5a0c4c6e39c7 | 407 | // } |
mehatfie | 9:5a0c4c6e39c7 | 408 | // |
mehatfie | 9:5a0c4c6e39c7 | 409 | // int conditionSuccess = combinedCondition.back().value; //value is the success(1) or failure(0) of the condition statement |
mehatfie | 9:5a0c4c6e39c7 | 410 | // |
mehatfie | 9:5a0c4c6e39c7 | 411 | // int checkEnd = 0; |
mehatfie | 9:5a0c4c6e39c7 | 412 | // if (!conditionSuccess){ |
mehatfie | 9:5a0c4c6e39c7 | 413 | // |
mehatfie | 9:5a0c4c6e39c7 | 414 | // while (checkEnd != 4){ |
mehatfie | 9:5a0c4c6e39c7 | 415 | // |
mehatfie | 9:5a0c4c6e39c7 | 416 | // getNextLine(selectedFile, lineData); |
mehatfie | 9:5a0c4c6e39c7 | 417 | // |
mehatfie | 9:5a0c4c6e39c7 | 418 | // // check if the first word is an end command (avoids interpreting functions that perform actions) |
mehatfie | 9:5a0c4c6e39c7 | 419 | // if (lineData.word[0].compare("end") == 0) |
mehatfie | 9:5a0c4c6e39c7 | 420 | // checkEnd = interpretCommand(selectedFile, lineData); |
mehatfie | 9:5a0c4c6e39c7 | 421 | // |
mehatfie | 9:5a0c4c6e39c7 | 422 | // if (checkEnd == 4) // custom return value for this function |
mehatfie | 9:5a0c4c6e39c7 | 423 | // return 0; |
mehatfie | 9:5a0c4c6e39c7 | 424 | // } |
mehatfie | 9:5a0c4c6e39c7 | 425 | // } |
mehatfie | 9:5a0c4c6e39c7 | 426 | // |
mehatfie | 9:5a0c4c6e39c7 | 427 | // // Return success as the function either met the condition and will continue from the next line, or |
mehatfie | 9:5a0c4c6e39c7 | 428 | // // failed to meet the condition and ran through the lines inside the condition until "end condition" was found, therefore |
mehatfie | 9:5a0c4c6e39c7 | 429 | // // the program will proceed from the line after the "end condition" line |
mehatfie | 9:5a0c4c6e39c7 | 430 | // return 1; |
mehatfie | 9:5a0c4c6e39c7 | 431 | //} |