Microcontroller firmware that uses a simple, yet powerful scripting language to control the timing of input and output events with high temporal resolution. Written by Mattias Karlsson
behave.cpp@1:3a050d26d4f6, 2015-06-03 (annotated)
- Committer:
- mkarlsso
- Date:
- Wed Jun 03 22:54:25 2015 +0000
- Revision:
- 1:3a050d26d4f6
- Parent:
- 0:8dbd6bd9167f
fixing digital in interrupt pausing during update. Not a working version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mkarlsso | 0:8dbd6bd9167f | 1 | #include "behave.h" |
mkarlsso | 0:8dbd6bd9167f | 2 | #include "hardwareInterface.h" |
mkarlsso | 0:8dbd6bd9167f | 3 | #include <ctype.h> |
mkarlsso | 0:8dbd6bd9167f | 4 | #include <sstream> |
mkarlsso | 0:8dbd6bd9167f | 5 | #include <string.h> |
mkarlsso | 0:8dbd6bd9167f | 6 | #include <cstdlib> |
mkarlsso | 0:8dbd6bd9167f | 7 | |
mkarlsso | 0:8dbd6bd9167f | 8 | using namespace std; |
mkarlsso | 0:8dbd6bd9167f | 9 | |
mkarlsso | 0:8dbd6bd9167f | 10 | int16_t randomSeedCounter; //used for seeding random numbers |
mkarlsso | 0:8dbd6bd9167f | 11 | |
mkarlsso | 0:8dbd6bd9167f | 12 | //digitalPort* portVector[NUMPORTS+1]; //a list of pointers to the digital ports |
mkarlsso | 0:8dbd6bd9167f | 13 | |
mkarlsso | 0:8dbd6bd9167f | 14 | //Main event queue |
mkarlsso | 0:8dbd6bd9167f | 15 | eventQueue mainQueue; |
mkarlsso | 0:8dbd6bd9167f | 16 | |
mkarlsso | 0:8dbd6bd9167f | 17 | //The script parser |
mkarlsso | 0:8dbd6bd9167f | 18 | //scriptStream parser(portVector, NUMPORTS, &mainQueue); |
mkarlsso | 0:8dbd6bd9167f | 19 | |
mkarlsso | 0:8dbd6bd9167f | 20 | //globals defined in hardwareInterface.cpp |
mkarlsso | 0:8dbd6bd9167f | 21 | extern uint32_t timeKeeper; //the master clock |
mkarlsso | 0:8dbd6bd9167f | 22 | extern bool resetTimer; |
mkarlsso | 0:8dbd6bd9167f | 23 | extern bool clockSlave; |
mkarlsso | 0:8dbd6bd9167f | 24 | extern bool changeToSlave; |
mkarlsso | 0:8dbd6bd9167f | 25 | extern bool changeToStandAlone; |
mkarlsso | 0:8dbd6bd9167f | 26 | extern outputStream textDisplay; |
mkarlsso | 0:8dbd6bd9167f | 27 | |
mkarlsso | 0:8dbd6bd9167f | 28 | //extern int currentDIOstate[2]; |
mkarlsso | 0:8dbd6bd9167f | 29 | bool broadCastStateChanges; |
mkarlsso | 0:8dbd6bd9167f | 30 | bool textStreaming; |
mkarlsso | 0:8dbd6bd9167f | 31 | |
mkarlsso | 0:8dbd6bd9167f | 32 | |
mkarlsso | 0:8dbd6bd9167f | 33 | |
mkarlsso | 0:8dbd6bd9167f | 34 | //These items may be placed in hardware-specific parts of memory |
mkarlsso | 0:8dbd6bd9167f | 35 | |
mkarlsso | 0:8dbd6bd9167f | 36 | #ifdef MBEDHARDWARE |
mkarlsso | 0:8dbd6bd9167f | 37 | //__attribute((section("AHBSRAM0"),aligned)) outputStream textDisplay(512); |
mkarlsso | 0:8dbd6bd9167f | 38 | __attribute((section("AHBSRAM0"),aligned)) char buffer[256]; |
mkarlsso | 0:8dbd6bd9167f | 39 | __attribute((section("AHBSRAM1"),aligned)) event eventBlock[NUMEVENTS]; |
mkarlsso | 0:8dbd6bd9167f | 40 | __attribute((section("AHBSRAM1"),aligned)) condition conditionBlock[NUMCONDITIONS]; |
mkarlsso | 0:8dbd6bd9167f | 41 | __attribute((section("AHBSRAM1"),aligned)) intCompare intCompareBlock[NUMINTCOMPARE]; |
mkarlsso | 0:8dbd6bd9167f | 42 | __attribute((section("AHBSRAM0"),aligned)) action actionBlock[NUMACTIONS]; |
mkarlsso | 0:8dbd6bd9167f | 43 | __attribute((section("AHBSRAM0"),aligned)) portMessage portMessageBlock[NUMPORTMESSAGES]; |
mkarlsso | 1:3a050d26d4f6 | 44 | __attribute((section("AHBSRAM1"),aligned)) intVariable globalVarBlock[NUMINTVARS]; |
mkarlsso | 0:8dbd6bd9167f | 45 | __attribute((section("AHBSRAM0"),aligned)) intOperation intOperationBlock[NUMINTOPERATIONS]; |
mkarlsso | 0:8dbd6bd9167f | 46 | __attribute((section("AHBSRAM0"),aligned)) displayAction displayActionBlock[NUMDISPLAYACTIONS]; |
mkarlsso | 0:8dbd6bd9167f | 47 | __attribute((section("AHBSRAM0"),aligned)) triggerFunctionAction triggerFunctionActionBlock[NUMTRIGGERACTIONS]; |
mkarlsso | 1:3a050d26d4f6 | 48 | __attribute((section("AHBSRAM1"),aligned)) char charBuffer[INPUTCHARBUFFERSIZE]; |
mkarlsso | 1:3a050d26d4f6 | 49 | |
mkarlsso | 1:3a050d26d4f6 | 50 | |
mkarlsso | 0:8dbd6bd9167f | 51 | #endif |
mkarlsso | 0:8dbd6bd9167f | 52 | |
mkarlsso | 0:8dbd6bd9167f | 53 | #ifdef FPGAHARDWARE |
mkarlsso | 0:8dbd6bd9167f | 54 | |
mkarlsso | 0:8dbd6bd9167f | 55 | char buffer[256]; |
mkarlsso | 0:8dbd6bd9167f | 56 | event eventBlock[NUMEVENTS]; |
mkarlsso | 0:8dbd6bd9167f | 57 | condition conditionBlock[NUMCONDITIONS]; |
mkarlsso | 0:8dbd6bd9167f | 58 | intCompare intCompareBlock[NUMINTCOMPARE]; |
mkarlsso | 0:8dbd6bd9167f | 59 | action actionBlock[NUMACTIONS]; |
mkarlsso | 0:8dbd6bd9167f | 60 | portMessage portMessageBlock[NUMPORTMESSAGES]; |
mkarlsso | 1:3a050d26d4f6 | 61 | intVariable globalVarBlock[NUMINTVARS]; |
mkarlsso | 0:8dbd6bd9167f | 62 | intOperation intOperationBlock[NUMINTOPERATIONS]; |
mkarlsso | 0:8dbd6bd9167f | 63 | displayAction displayActionBlock[NUMDISPLAYACTIONS]; |
mkarlsso | 0:8dbd6bd9167f | 64 | triggerFunctionAction triggerFunctionActionBlock[NUMTRIGGERACTIONS]; |
mkarlsso | 1:3a050d26d4f6 | 65 | char charBuffer[INPUTCHARBUFFERSIZE]; |
mkarlsso | 0:8dbd6bd9167f | 66 | #endif |
mkarlsso | 0:8dbd6bd9167f | 67 | |
mkarlsso | 0:8dbd6bd9167f | 68 | |
mkarlsso | 0:8dbd6bd9167f | 69 | event* functionEventArray[NUMFUNCTIONS]; |
mkarlsso | 0:8dbd6bd9167f | 70 | bool functionSpotTaken[NUMFUNCTIONS]; |
mkarlsso | 0:8dbd6bd9167f | 71 | |
mkarlsso | 0:8dbd6bd9167f | 72 | |
mkarlsso | 0:8dbd6bd9167f | 73 | //----------------------------------------------- |
mkarlsso | 0:8dbd6bd9167f | 74 | //This is the main loop of the program |
mkarlsso | 0:8dbd6bd9167f | 75 | mainLoop::mainLoop(){ |
mkarlsso | 0:8dbd6bd9167f | 76 | |
mkarlsso | 0:8dbd6bd9167f | 77 | |
mkarlsso | 0:8dbd6bd9167f | 78 | } |
mkarlsso | 0:8dbd6bd9167f | 79 | |
mkarlsso | 0:8dbd6bd9167f | 80 | void mainLoop::init() { |
mkarlsso | 0:8dbd6bd9167f | 81 | currentDIOstate[0] = 0; |
mkarlsso | 0:8dbd6bd9167f | 82 | currentDIOstate[1] = 0; |
mkarlsso | 0:8dbd6bd9167f | 83 | digitalInChanged = false; |
mkarlsso | 0:8dbd6bd9167f | 84 | digitalOutChanged = false; |
mkarlsso | 0:8dbd6bd9167f | 85 | textStreaming = true; |
mkarlsso | 0:8dbd6bd9167f | 86 | eraseBuffer(); |
mkarlsso | 0:8dbd6bd9167f | 87 | broadCastStateChanges = true; |
mkarlsso | 0:8dbd6bd9167f | 88 | |
mkarlsso | 0:8dbd6bd9167f | 89 | |
mkarlsso | 0:8dbd6bd9167f | 90 | |
mkarlsso | 0:8dbd6bd9167f | 91 | //section for MBED hardware |
mkarlsso | 0:8dbd6bd9167f | 92 | #ifdef MBEDHARDWARE |
mkarlsso | 0:8dbd6bd9167f | 93 | hardware = new MBEDSystem(); |
mkarlsso | 0:8dbd6bd9167f | 94 | hardware->timerinit(); |
mkarlsso | 0:8dbd6bd9167f | 95 | pc = new MBEDSerialPort(); |
mkarlsso | 0:8dbd6bd9167f | 96 | pc->init(); |
mkarlsso | 0:8dbd6bd9167f | 97 | textDisplay.setSerial(pc); |
mkarlsso | 0:8dbd6bd9167f | 98 | |
mkarlsso | 0:8dbd6bd9167f | 99 | #endif |
mkarlsso | 0:8dbd6bd9167f | 100 | |
mkarlsso | 0:8dbd6bd9167f | 101 | #ifdef FPGAHARDWARE |
mkarlsso | 0:8dbd6bd9167f | 102 | pc = new FPGASerialPort(); |
mkarlsso | 0:8dbd6bd9167f | 103 | pc->init(); |
mkarlsso | 0:8dbd6bd9167f | 104 | |
mkarlsso | 0:8dbd6bd9167f | 105 | hardware = new FPGASystem(); |
mkarlsso | 0:8dbd6bd9167f | 106 | hardware->timerinit(); |
mkarlsso | 0:8dbd6bd9167f | 107 | |
mkarlsso | 0:8dbd6bd9167f | 108 | textDisplay.setSerial(pc); |
mkarlsso | 0:8dbd6bd9167f | 109 | |
mkarlsso | 0:8dbd6bd9167f | 110 | DIO_DCR = DIO_DCR_IE; // enable DIO edge interrupts |
mkarlsso | 0:8dbd6bd9167f | 111 | #endif |
mkarlsso | 0:8dbd6bd9167f | 112 | |
mkarlsso | 0:8dbd6bd9167f | 113 | for (int i = 0; i < NUMPORTS; i++) { |
mkarlsso | 0:8dbd6bd9167f | 114 | //Set up the ports. Each has two pointers to the harware implementations |
mkarlsso | 0:8dbd6bd9167f | 115 | //of a digital out and digital in. |
mkarlsso | 0:8dbd6bd9167f | 116 | ports[i].init(hardware->getDigitalOutPtr(i),hardware->getDigitalInPtr(i)); |
mkarlsso | 0:8dbd6bd9167f | 117 | } |
mkarlsso | 0:8dbd6bd9167f | 118 | |
mkarlsso | 0:8dbd6bd9167f | 119 | |
mkarlsso | 0:8dbd6bd9167f | 120 | parser = new scriptStream(ports, NUMPORTS, &mainQueue, hardware); |
mkarlsso | 0:8dbd6bd9167f | 121 | |
mkarlsso | 0:8dbd6bd9167f | 122 | } |
mkarlsso | 0:8dbd6bd9167f | 123 | |
mkarlsso | 0:8dbd6bd9167f | 124 | void mainLoop::exec() { |
mkarlsso | 1:3a050d26d4f6 | 125 | //Start the main loop. |
mkarlsso | 1:3a050d26d4f6 | 126 | |
mkarlsso | 0:8dbd6bd9167f | 127 | bool digitalInChanged = false; |
mkarlsso | 0:8dbd6bd9167f | 128 | bool digitalOutChanged = false; |
mkarlsso | 0:8dbd6bd9167f | 129 | uint32_t changeTime; |
mkarlsso | 0:8dbd6bd9167f | 130 | timeKeeper = 0; //set main clock to 0; |
mkarlsso | 0:8dbd6bd9167f | 131 | |
mkarlsso | 0:8dbd6bd9167f | 132 | int bufferPos = 0; |
mkarlsso | 0:8dbd6bd9167f | 133 | |
mkarlsso | 1:3a050d26d4f6 | 134 | //ostringstream timeConvert; // stream used for the conversion |
mkarlsso | 1:3a050d26d4f6 | 135 | //ostringstream stateConvert; |
mkarlsso | 0:8dbd6bd9167f | 136 | int tmpChar; |
mkarlsso | 0:8dbd6bd9167f | 137 | int junkChar; |
mkarlsso | 0:8dbd6bd9167f | 138 | |
mkarlsso | 0:8dbd6bd9167f | 139 | uint16_t shortcutTriggers[PENDINGTRIGGERBUFFERSIZE]; |
mkarlsso | 0:8dbd6bd9167f | 140 | int numTriggersToProcess; |
mkarlsso | 0:8dbd6bd9167f | 141 | |
mkarlsso | 0:8dbd6bd9167f | 142 | while (pc->readable()) { |
mkarlsso | 0:8dbd6bd9167f | 143 | junkChar = pc->readChar(); |
mkarlsso | 0:8dbd6bd9167f | 144 | } |
mkarlsso | 0:8dbd6bd9167f | 145 | |
mkarlsso | 0:8dbd6bd9167f | 146 | #ifdef MBEDHARDWARE |
mkarlsso | 0:8dbd6bd9167f | 147 | LocalFileSystem local("local"); |
mkarlsso | 0:8dbd6bd9167f | 148 | |
mkarlsso | 0:8dbd6bd9167f | 149 | FILE *fp = fopen("/local/STARTUP.TXT", "r"); |
mkarlsso | 0:8dbd6bd9167f | 150 | if (fp != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 151 | |
mkarlsso | 0:8dbd6bd9167f | 152 | textDisplay.send("Executing startup script...\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 153 | |
mkarlsso | 0:8dbd6bd9167f | 154 | do { |
mkarlsso | 0:8dbd6bd9167f | 155 | tmpChar = fgetc(fp); |
mkarlsso | 0:8dbd6bd9167f | 156 | if ((tmpChar >= 32) && (tmpChar <= 126)) { |
mkarlsso | 0:8dbd6bd9167f | 157 | buffer[bufferPos] = tmpChar; |
mkarlsso | 0:8dbd6bd9167f | 158 | bufferPos++; |
mkarlsso | 0:8dbd6bd9167f | 159 | } |
mkarlsso | 0:8dbd6bd9167f | 160 | if ((tmpChar == 13) || (tmpChar == 10)) { //carrriage return |
mkarlsso | 0:8dbd6bd9167f | 161 | parser->addLineToCurrentBlock(buffer); |
mkarlsso | 0:8dbd6bd9167f | 162 | bufferPos = 0; |
mkarlsso | 0:8dbd6bd9167f | 163 | eraseBuffer(); |
mkarlsso | 0:8dbd6bd9167f | 164 | } |
mkarlsso | 0:8dbd6bd9167f | 165 | //pc.putc(tmpChar); |
mkarlsso | 0:8dbd6bd9167f | 166 | } while (tmpChar != EOF); |
mkarlsso | 0:8dbd6bd9167f | 167 | |
mkarlsso | 0:8dbd6bd9167f | 168 | buffer[bufferPos] = 59; |
mkarlsso | 0:8dbd6bd9167f | 169 | parser->addLineToCurrentBlock(buffer); |
mkarlsso | 0:8dbd6bd9167f | 170 | eraseBuffer(); |
mkarlsso | 0:8dbd6bd9167f | 171 | fclose(fp); |
mkarlsso | 0:8dbd6bd9167f | 172 | } else { |
mkarlsso | 0:8dbd6bd9167f | 173 | textDisplay.send("No startup script found.\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 174 | } |
mkarlsso | 0:8dbd6bd9167f | 175 | #endif |
mkarlsso | 0:8dbd6bd9167f | 176 | |
mkarlsso | 0:8dbd6bd9167f | 177 | //Get the initial state of all input pins |
mkarlsso | 0:8dbd6bd9167f | 178 | for (int i = 0; i < NUMPORTS; i++) { |
mkarlsso | 0:8dbd6bd9167f | 179 | |
mkarlsso | 0:8dbd6bd9167f | 180 | if (ports[i].getDigitalIn() == 1) { |
mkarlsso | 0:8dbd6bd9167f | 181 | currentDIOstate[0] |= (1 << i); |
mkarlsso | 0:8dbd6bd9167f | 182 | } else { |
mkarlsso | 0:8dbd6bd9167f | 183 | currentDIOstate[0] &= ~(1 << i); |
mkarlsso | 0:8dbd6bd9167f | 184 | } |
mkarlsso | 0:8dbd6bd9167f | 185 | } |
mkarlsso | 0:8dbd6bd9167f | 186 | |
mkarlsso | 0:8dbd6bd9167f | 187 | |
mkarlsso | 0:8dbd6bd9167f | 188 | //main loop |
mkarlsso | 0:8dbd6bd9167f | 189 | while(1) { |
mkarlsso | 0:8dbd6bd9167f | 190 | //check the main event queue to see if anything needs to be done |
mkarlsso | 0:8dbd6bd9167f | 191 | |
mkarlsso | 0:8dbd6bd9167f | 192 | mainQueue.check(); |
mkarlsso | 0:8dbd6bd9167f | 193 | |
mkarlsso | 0:8dbd6bd9167f | 194 | //check if anything has been written to the serial input |
mkarlsso | 0:8dbd6bd9167f | 195 | while (pc->readable()) { |
mkarlsso | 0:8dbd6bd9167f | 196 | |
mkarlsso | 0:8dbd6bd9167f | 197 | buffer[bufferPos] = pc->readChar(); |
mkarlsso | 0:8dbd6bd9167f | 198 | bufferPos++; |
mkarlsso | 0:8dbd6bd9167f | 199 | |
mkarlsso | 0:8dbd6bd9167f | 200 | |
mkarlsso | 0:8dbd6bd9167f | 201 | //'Return' key pressed |
mkarlsso | 0:8dbd6bd9167f | 202 | if ((buffer[bufferPos-1] == 13) || (buffer[bufferPos-1] == 10)) { |
mkarlsso | 0:8dbd6bd9167f | 203 | |
mkarlsso | 0:8dbd6bd9167f | 204 | buffer[bufferPos-1] = '\0'; |
mkarlsso | 0:8dbd6bd9167f | 205 | |
mkarlsso | 0:8dbd6bd9167f | 206 | parser->addLineToCurrentBlock(buffer); |
mkarlsso | 0:8dbd6bd9167f | 207 | bufferPos = 0; |
mkarlsso | 0:8dbd6bd9167f | 208 | eraseBuffer(); |
mkarlsso | 0:8dbd6bd9167f | 209 | |
mkarlsso | 0:8dbd6bd9167f | 210 | } else { |
mkarlsso | 0:8dbd6bd9167f | 211 | |
mkarlsso | 0:8dbd6bd9167f | 212 | //Backspace was pressed |
mkarlsso | 0:8dbd6bd9167f | 213 | if (((buffer[bufferPos-1] == 127)||(buffer[bufferPos-1] == 8))) { |
mkarlsso | 0:8dbd6bd9167f | 214 | if (bufferPos > 1) { |
mkarlsso | 0:8dbd6bd9167f | 215 | bufferPos = bufferPos-2; //erase the backspace char plus the one before |
mkarlsso | 0:8dbd6bd9167f | 216 | } else { |
mkarlsso | 0:8dbd6bd9167f | 217 | bufferPos = bufferPos-1; //beginning of line, so nothing to erase |
mkarlsso | 0:8dbd6bd9167f | 218 | } |
mkarlsso | 0:8dbd6bd9167f | 219 | } |
mkarlsso | 0:8dbd6bd9167f | 220 | } |
mkarlsso | 0:8dbd6bd9167f | 221 | } |
mkarlsso | 0:8dbd6bd9167f | 222 | |
mkarlsso | 0:8dbd6bd9167f | 223 | //Check all the digital ports to see if anything has changed. In the update routine, the port's |
mkarlsso | 0:8dbd6bd9167f | 224 | //script callbacks are called if the port was triggered |
mkarlsso | 0:8dbd6bd9167f | 225 | digitalInChanged = false; |
mkarlsso | 0:8dbd6bd9167f | 226 | digitalOutChanged = false; |
mkarlsso | 0:8dbd6bd9167f | 227 | changeTime = timeKeeper; |
mkarlsso | 1:3a050d26d4f6 | 228 | //hardware->pauseInterrupts(); |
mkarlsso | 0:8dbd6bd9167f | 229 | for (int i = 0; i < NUMPORTS; i++) { |
mkarlsso | 1:3a050d26d4f6 | 230 | //hardware->pauseInterrupts(); |
mkarlsso | 0:8dbd6bd9167f | 231 | if (ports[i].update()) { |
mkarlsso | 0:8dbd6bd9167f | 232 | |
mkarlsso | 0:8dbd6bd9167f | 233 | digitalInChanged = true; |
mkarlsso | 0:8dbd6bd9167f | 234 | changeTime = min(changeTime,ports[i].lastChangeTime); |
mkarlsso | 0:8dbd6bd9167f | 235 | |
mkarlsso | 0:8dbd6bd9167f | 236 | |
mkarlsso | 0:8dbd6bd9167f | 237 | //The input state of all the ports in condensed into one number (each bit contains the info) |
mkarlsso | 0:8dbd6bd9167f | 238 | if (ports[i].getLastChangeState() == 1) { |
mkarlsso | 0:8dbd6bd9167f | 239 | currentDIOstate[0] |= (1 << i); |
mkarlsso | 0:8dbd6bd9167f | 240 | } else { |
mkarlsso | 0:8dbd6bd9167f | 241 | currentDIOstate[0] &= ~(1 << i); |
mkarlsso | 0:8dbd6bd9167f | 242 | } |
mkarlsso | 0:8dbd6bd9167f | 243 | } |
mkarlsso | 1:3a050d26d4f6 | 244 | //hardware->resumeInterrupts(); |
mkarlsso | 0:8dbd6bd9167f | 245 | if (ports[i].outStateChanged) { |
mkarlsso | 0:8dbd6bd9167f | 246 | digitalOutChanged = true; |
mkarlsso | 0:8dbd6bd9167f | 247 | changeTime = min(changeTime,ports[i].lastOutChangeTime); |
mkarlsso | 0:8dbd6bd9167f | 248 | //The out state of all the ports is condensed into one number (each bit contains the info) |
mkarlsso | 0:8dbd6bd9167f | 249 | if (ports[i].outState == 1) { |
mkarlsso | 0:8dbd6bd9167f | 250 | currentDIOstate[1] |= (1 << i); |
mkarlsso | 0:8dbd6bd9167f | 251 | } else { |
mkarlsso | 0:8dbd6bd9167f | 252 | currentDIOstate[1] &= ~(1 << i); |
mkarlsso | 0:8dbd6bd9167f | 253 | } |
mkarlsso | 0:8dbd6bd9167f | 254 | ports[i].outStateChanged = false; |
mkarlsso | 0:8dbd6bd9167f | 255 | } |
mkarlsso | 0:8dbd6bd9167f | 256 | } |
mkarlsso | 0:8dbd6bd9167f | 257 | |
mkarlsso | 0:8dbd6bd9167f | 258 | //If anything changed, we write the new values to the serial port (this can be turned off |
mkarlsso | 0:8dbd6bd9167f | 259 | //with broadCastStateChanges) |
mkarlsso | 0:8dbd6bd9167f | 260 | if ( (digitalInChanged||digitalOutChanged) && broadCastStateChanges) { |
mkarlsso | 0:8dbd6bd9167f | 261 | textDisplay << changeTime << " " << currentDIOstate[0] << " " << currentDIOstate[1] << "\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 262 | |
mkarlsso | 0:8dbd6bd9167f | 263 | /* |
mkarlsso | 0:8dbd6bd9167f | 264 | timeConvert << changeTime; //broadcast the earliest timestamp when a change occured |
mkarlsso | 0:8dbd6bd9167f | 265 | //stateConvert << currentDIOstate[0] << " " << currentDIOstate[1]; |
mkarlsso | 0:8dbd6bd9167f | 266 | stateConvert << currentDIOstate[0] << " " << currentDIOstate[1] << " "; |
mkarlsso | 0:8dbd6bd9167f | 267 | |
mkarlsso | 0:8dbd6bd9167f | 268 | textDisplay.send(timeConvert.str() + " " + stateConvert.str() + "\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 269 | timeConvert.clear(); |
mkarlsso | 0:8dbd6bd9167f | 270 | timeConvert.seekp(0); |
mkarlsso | 0:8dbd6bd9167f | 271 | stateConvert.clear(); |
mkarlsso | 0:8dbd6bd9167f | 272 | stateConvert.seekp(0); |
mkarlsso | 0:8dbd6bd9167f | 273 | */ |
mkarlsso | 0:8dbd6bd9167f | 274 | digitalInChanged = false; |
mkarlsso | 0:8dbd6bd9167f | 275 | digitalOutChanged = false; |
mkarlsso | 0:8dbd6bd9167f | 276 | } |
mkarlsso | 0:8dbd6bd9167f | 277 | |
mkarlsso | 0:8dbd6bd9167f | 278 | //We use a buffer to send text via the serial port. For every loop |
mkarlsso | 0:8dbd6bd9167f | 279 | //in the main loop, we send one character if there is enything to send. |
mkarlsso | 0:8dbd6bd9167f | 280 | //This way, outputting text to serial does not hold up other time-sensitive |
mkarlsso | 0:8dbd6bd9167f | 281 | //things in the event queue |
mkarlsso | 0:8dbd6bd9167f | 282 | if ((textDisplay.unsentData) && (textStreaming)) { |
mkarlsso | 0:8dbd6bd9167f | 283 | pc->writeChar(textDisplay.getNextChar()); |
mkarlsso | 0:8dbd6bd9167f | 284 | } |
mkarlsso | 0:8dbd6bd9167f | 285 | |
mkarlsso | 0:8dbd6bd9167f | 286 | //Here is how we toggle between standalone and slave mode for the clock updating. |
mkarlsso | 0:8dbd6bd9167f | 287 | if (changeToSlave) { |
mkarlsso | 0:8dbd6bd9167f | 288 | hardware->setSlaveClock(); |
mkarlsso | 0:8dbd6bd9167f | 289 | } else if (changeToStandAlone) { |
mkarlsso | 0:8dbd6bd9167f | 290 | hardware->setStandAloneClock(); |
mkarlsso | 0:8dbd6bd9167f | 291 | } |
mkarlsso | 0:8dbd6bd9167f | 292 | |
mkarlsso | 0:8dbd6bd9167f | 293 | //anything extra to do, defined by the hardware |
mkarlsso | 0:8dbd6bd9167f | 294 | hardware->mainLoopToDo(); |
mkarlsso | 0:8dbd6bd9167f | 295 | |
mkarlsso | 0:8dbd6bd9167f | 296 | //check for shortcut triggers |
mkarlsso | 0:8dbd6bd9167f | 297 | numTriggersToProcess = hardware->getPendingFunctionTriggers(shortcutTriggers); |
mkarlsso | 0:8dbd6bd9167f | 298 | for (int i = 0; i < numTriggersToProcess; i++) { |
mkarlsso | 0:8dbd6bd9167f | 299 | if (shortcutTriggers[i] < NUMTRIGGERACTIONS && functionSpotTaken[i]) { |
mkarlsso | 0:8dbd6bd9167f | 300 | functionEventArray[i]->execute(); |
mkarlsso | 0:8dbd6bd9167f | 301 | } |
mkarlsso | 0:8dbd6bd9167f | 302 | } |
mkarlsso | 0:8dbd6bd9167f | 303 | |
mkarlsso | 0:8dbd6bd9167f | 304 | } |
mkarlsso | 0:8dbd6bd9167f | 305 | |
mkarlsso | 0:8dbd6bd9167f | 306 | } |
mkarlsso | 0:8dbd6bd9167f | 307 | |
mkarlsso | 0:8dbd6bd9167f | 308 | void mainLoop::eraseBuffer() { |
mkarlsso | 0:8dbd6bd9167f | 309 | for (int i = 0; i < 256; i++) { |
mkarlsso | 0:8dbd6bd9167f | 310 | buffer[i] = NULL; |
mkarlsso | 0:8dbd6bd9167f | 311 | } |
mkarlsso | 0:8dbd6bd9167f | 312 | } |
mkarlsso | 0:8dbd6bd9167f | 313 | |
mkarlsso | 0:8dbd6bd9167f | 314 | //------------------------------------------------- |
mkarlsso | 0:8dbd6bd9167f | 315 | |
mkarlsso | 0:8dbd6bd9167f | 316 | //used to find the first available object in the staticly defined pools of memory |
mkarlsso | 0:8dbd6bd9167f | 317 | template<class T> T* findFirstUnUsed(T a[], const int arrayLength) { |
mkarlsso | 0:8dbd6bd9167f | 318 | |
mkarlsso | 0:8dbd6bd9167f | 319 | T* returnPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 320 | for (int i = 0; i < arrayLength; i++) { |
mkarlsso | 0:8dbd6bd9167f | 321 | if (!a[i].isUsed) { |
mkarlsso | 0:8dbd6bd9167f | 322 | returnPtr = &a[i]; |
mkarlsso | 0:8dbd6bd9167f | 323 | break; |
mkarlsso | 0:8dbd6bd9167f | 324 | } |
mkarlsso | 0:8dbd6bd9167f | 325 | } |
mkarlsso | 0:8dbd6bd9167f | 326 | return returnPtr; |
mkarlsso | 0:8dbd6bd9167f | 327 | } |
mkarlsso | 0:8dbd6bd9167f | 328 | |
mkarlsso | 0:8dbd6bd9167f | 329 | //used to count the number of available objects in the memory pool |
mkarlsso | 0:8dbd6bd9167f | 330 | template<class T> int countUnUsed(T a[], const int arrayLength) { |
mkarlsso | 0:8dbd6bd9167f | 331 | |
mkarlsso | 0:8dbd6bd9167f | 332 | int count = 0; |
mkarlsso | 0:8dbd6bd9167f | 333 | for (int i = 0; i < arrayLength; i++) { |
mkarlsso | 0:8dbd6bd9167f | 334 | if (!a[i].isUsed) { |
mkarlsso | 0:8dbd6bd9167f | 335 | count++; |
mkarlsso | 0:8dbd6bd9167f | 336 | } |
mkarlsso | 0:8dbd6bd9167f | 337 | } |
mkarlsso | 0:8dbd6bd9167f | 338 | return count; |
mkarlsso | 0:8dbd6bd9167f | 339 | } |
mkarlsso | 0:8dbd6bd9167f | 340 | |
mkarlsso | 0:8dbd6bd9167f | 341 | |
mkarlsso | 0:8dbd6bd9167f | 342 | void displayMemoryLeft(void) { |
mkarlsso | 0:8dbd6bd9167f | 343 | textDisplay << "Available slots left in memory\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 344 | textDisplay << " Blocks: " << countUnUsed(eventBlock, NUMEVENTS) << "\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 345 | textDisplay << " Condition containers: " << countUnUsed(conditionBlock, NUMCONDITIONS) << "\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 346 | textDisplay << " Int compare conditions: " << countUnUsed(intCompareBlock, NUMINTCOMPARE) << "\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 347 | textDisplay << " Command containers: " << countUnUsed(actionBlock, NUMACTIONS) << "\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 348 | textDisplay << " Port commands: "<< countUnUsed(portMessageBlock, NUMPORTMESSAGES) << "\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 349 | textDisplay << " Integer operater commands: " << countUnUsed(intOperationBlock, NUMINTOPERATIONS) << "\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 350 | textDisplay << " Text display commands: " << countUnUsed(displayActionBlock, NUMDISPLAYACTIONS) << "\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 351 | } |
mkarlsso | 0:8dbd6bd9167f | 352 | |
mkarlsso | 0:8dbd6bd9167f | 353 | bool isNumber(const std::string& s) { |
mkarlsso | 0:8dbd6bd9167f | 354 | std::string::const_iterator it = s.begin(); |
mkarlsso | 0:8dbd6bd9167f | 355 | while (it != s.end() && isdigit(*it)) ++it; |
mkarlsso | 0:8dbd6bd9167f | 356 | return !s.empty() && it == s.end(); |
mkarlsso | 0:8dbd6bd9167f | 357 | } |
mkarlsso | 0:8dbd6bd9167f | 358 | |
mkarlsso | 0:8dbd6bd9167f | 359 | void tokenize(const string& str, |
mkarlsso | 0:8dbd6bd9167f | 360 | vector<string>& tokens, |
mkarlsso | 0:8dbd6bd9167f | 361 | const string& delimiters = " ") |
mkarlsso | 0:8dbd6bd9167f | 362 | { |
mkarlsso | 0:8dbd6bd9167f | 363 | // Skip delimiters at beginning. |
mkarlsso | 0:8dbd6bd9167f | 364 | string::size_type lastPos = str.find_first_not_of(delimiters, 0); |
mkarlsso | 0:8dbd6bd9167f | 365 | // Find first "non-delimiter". |
mkarlsso | 0:8dbd6bd9167f | 366 | string::size_type pos = str.find_first_of(delimiters, lastPos); |
mkarlsso | 0:8dbd6bd9167f | 367 | |
mkarlsso | 0:8dbd6bd9167f | 368 | while (string::npos != pos || string::npos != lastPos) |
mkarlsso | 0:8dbd6bd9167f | 369 | { |
mkarlsso | 0:8dbd6bd9167f | 370 | // Found a token, add it to the vector. |
mkarlsso | 0:8dbd6bd9167f | 371 | tokens.push_back(str.substr(lastPos, pos - lastPos)); |
mkarlsso | 0:8dbd6bd9167f | 372 | // Skip delimiters. Note the "not_of" |
mkarlsso | 0:8dbd6bd9167f | 373 | lastPos = str.find_first_not_of(delimiters, pos); |
mkarlsso | 0:8dbd6bd9167f | 374 | // Find next "non-delimiter" |
mkarlsso | 0:8dbd6bd9167f | 375 | pos = str.find_first_of(delimiters, lastPos); |
mkarlsso | 0:8dbd6bd9167f | 376 | } |
mkarlsso | 0:8dbd6bd9167f | 377 | } |
mkarlsso | 0:8dbd6bd9167f | 378 | |
mkarlsso | 0:8dbd6bd9167f | 379 | |
mkarlsso | 0:8dbd6bd9167f | 380 | digitalPort::digitalPort(): |
mkarlsso | 0:8dbd6bd9167f | 381 | outPin(NULL), |
mkarlsso | 0:8dbd6bd9167f | 382 | inPin(NULL), |
mkarlsso | 0:8dbd6bd9167f | 383 | outState(0){ |
mkarlsso | 0:8dbd6bd9167f | 384 | |
mkarlsso | 0:8dbd6bd9167f | 385 | } |
mkarlsso | 0:8dbd6bd9167f | 386 | |
mkarlsso | 0:8dbd6bd9167f | 387 | void digitalPort::init(sDigitalOut *DOP, sDigitalIn *DIP) { |
mkarlsso | 0:8dbd6bd9167f | 388 | outPin = DOP; |
mkarlsso | 0:8dbd6bd9167f | 389 | inPin = DIP; |
mkarlsso | 0:8dbd6bd9167f | 390 | lastInState = getDigitalIn(); |
mkarlsso | 0:8dbd6bd9167f | 391 | inState = getDigitalIn(); |
mkarlsso | 0:8dbd6bd9167f | 392 | lastChangeTime = 0; |
mkarlsso | 0:8dbd6bd9167f | 393 | lastOutChangeTime = 0; |
mkarlsso | 0:8dbd6bd9167f | 394 | lastChangeInterval = 0; |
mkarlsso | 0:8dbd6bd9167f | 395 | triggerUpEventPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 396 | triggerDownEventPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 397 | outStateChanged = false; |
mkarlsso | 0:8dbd6bd9167f | 398 | |
mkarlsso | 0:8dbd6bd9167f | 399 | } |
mkarlsso | 0:8dbd6bd9167f | 400 | |
mkarlsso | 0:8dbd6bd9167f | 401 | |
mkarlsso | 0:8dbd6bd9167f | 402 | void digitalPort::setTriggerUpEvent(event* eventInput) { |
mkarlsso | 0:8dbd6bd9167f | 403 | if (triggerUpEventPtr != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 404 | //delete triggerUpEventPtr; |
mkarlsso | 0:8dbd6bd9167f | 405 | triggerUpEventPtr->release(); |
mkarlsso | 0:8dbd6bd9167f | 406 | } |
mkarlsso | 0:8dbd6bd9167f | 407 | triggerUpEventPtr = eventInput; |
mkarlsso | 0:8dbd6bd9167f | 408 | } |
mkarlsso | 0:8dbd6bd9167f | 409 | |
mkarlsso | 0:8dbd6bd9167f | 410 | void digitalPort::setTriggerDownEvent(event* eventInput) { |
mkarlsso | 0:8dbd6bd9167f | 411 | if (triggerDownEventPtr != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 412 | //delete triggerDownEventPtr; |
mkarlsso | 0:8dbd6bd9167f | 413 | triggerDownEventPtr->release(); |
mkarlsso | 0:8dbd6bd9167f | 414 | |
mkarlsso | 0:8dbd6bd9167f | 415 | } |
mkarlsso | 0:8dbd6bd9167f | 416 | triggerDownEventPtr = eventInput; |
mkarlsso | 0:8dbd6bd9167f | 417 | } |
mkarlsso | 0:8dbd6bd9167f | 418 | |
mkarlsso | 0:8dbd6bd9167f | 419 | |
mkarlsso | 0:8dbd6bd9167f | 420 | int digitalPort::getDigitalIn() { |
mkarlsso | 0:8dbd6bd9167f | 421 | return inPin->read(); |
mkarlsso | 0:8dbd6bd9167f | 422 | } |
mkarlsso | 0:8dbd6bd9167f | 423 | |
mkarlsso | 0:8dbd6bd9167f | 424 | |
mkarlsso | 0:8dbd6bd9167f | 425 | void digitalPort::setDigitalOut(int outVal) { |
mkarlsso | 0:8dbd6bd9167f | 426 | if (outVal == -1) { |
mkarlsso | 0:8dbd6bd9167f | 427 | outVal = 1-outState; |
mkarlsso | 0:8dbd6bd9167f | 428 | } |
mkarlsso | 0:8dbd6bd9167f | 429 | outPin->write(outVal); |
mkarlsso | 0:8dbd6bd9167f | 430 | if (outState != outVal) { |
mkarlsso | 0:8dbd6bd9167f | 431 | outStateChanged = true; |
mkarlsso | 0:8dbd6bd9167f | 432 | lastOutChangeTime = timeKeeper; |
mkarlsso | 0:8dbd6bd9167f | 433 | } |
mkarlsso | 0:8dbd6bd9167f | 434 | outState = outVal; |
mkarlsso | 0:8dbd6bd9167f | 435 | } |
mkarlsso | 0:8dbd6bd9167f | 436 | |
mkarlsso | 0:8dbd6bd9167f | 437 | bool digitalPort::update() { |
mkarlsso | 0:8dbd6bd9167f | 438 | |
mkarlsso | 0:8dbd6bd9167f | 439 | bool changed = false; |
mkarlsso | 1:3a050d26d4f6 | 440 | bool execUp = false; |
mkarlsso | 1:3a050d26d4f6 | 441 | bool execDown = false; |
mkarlsso | 0:8dbd6bd9167f | 442 | if ((timeKeeper - lastChangeTime) > 1) { //prevents flutter triggers when button is pressed |
mkarlsso | 0:8dbd6bd9167f | 443 | |
mkarlsso | 0:8dbd6bd9167f | 444 | //changed = (lastInState != inState); |
mkarlsso | 0:8dbd6bd9167f | 445 | |
mkarlsso | 1:3a050d26d4f6 | 446 | changed = (inPin->lastUpEvent.triggered || inPin->lastDownEvent.triggered); //Either a down or up event happened |
mkarlsso | 0:8dbd6bd9167f | 447 | if (changed) { |
mkarlsso | 1:3a050d26d4f6 | 448 | inPin->setUpdate(true); //Once we get the state of the pin, we buffer any pin changes until we are done checking |
mkarlsso | 0:8dbd6bd9167f | 449 | inState = getDigitalIn(); |
mkarlsso | 0:8dbd6bd9167f | 450 | |
mkarlsso | 0:8dbd6bd9167f | 451 | //We need to ignore flutter when levers/beam breaks are triggered. So |
mkarlsso | 0:8dbd6bd9167f | 452 | //if the current state if different than the last logged state, we only |
mkarlsso | 0:8dbd6bd9167f | 453 | //consider the first edge that brough us to the current state |
mkarlsso | 0:8dbd6bd9167f | 454 | if (lastInState != inState) { |
mkarlsso | 0:8dbd6bd9167f | 455 | |
mkarlsso | 0:8dbd6bd9167f | 456 | if (inState == 1) { |
mkarlsso | 0:8dbd6bd9167f | 457 | |
mkarlsso | 0:8dbd6bd9167f | 458 | lastChangeInterval = inPin->lastUpEvent.timeStamp - lastChangeTime; |
mkarlsso | 0:8dbd6bd9167f | 459 | lastChangeTime = inPin->lastUpEvent.timeStamp; |
mkarlsso | 0:8dbd6bd9167f | 460 | |
mkarlsso | 0:8dbd6bd9167f | 461 | /* |
mkarlsso | 0:8dbd6bd9167f | 462 | if (inPin->lastUpEvent.triggered) { |
mkarlsso | 0:8dbd6bd9167f | 463 | //there were hardware triggers since the last main loop. We use that time |
mkarlsso | 0:8dbd6bd9167f | 464 | lastChangeInterval = inPin->lastUpEvent.timeStamp - lastChangeTime; |
mkarlsso | 0:8dbd6bd9167f | 465 | lastChangeTime = inPin->lastUpEvent.timeStamp; |
mkarlsso | 0:8dbd6bd9167f | 466 | } else { |
mkarlsso | 0:8dbd6bd9167f | 467 | //otherwise we use the current time |
mkarlsso | 0:8dbd6bd9167f | 468 | lastChangeInterval = timeKeeper - lastChangeTime; |
mkarlsso | 0:8dbd6bd9167f | 469 | lastChangeTime = timeKeeper; |
mkarlsso | 0:8dbd6bd9167f | 470 | } |
mkarlsso | 0:8dbd6bd9167f | 471 | */ |
mkarlsso | 1:3a050d26d4f6 | 472 | if (triggerUpEventPtr != NULL) {execUp = true;} |
mkarlsso | 0:8dbd6bd9167f | 473 | } else if (inState == 0) { |
mkarlsso | 0:8dbd6bd9167f | 474 | |
mkarlsso | 0:8dbd6bd9167f | 475 | lastChangeInterval = inPin->lastDownEvent.timeStamp - lastChangeTime; |
mkarlsso | 0:8dbd6bd9167f | 476 | lastChangeTime = inPin->lastDownEvent.timeStamp; |
mkarlsso | 0:8dbd6bd9167f | 477 | |
mkarlsso | 0:8dbd6bd9167f | 478 | /* |
mkarlsso | 0:8dbd6bd9167f | 479 | if (inPin->lastDownEvent.triggered) { |
mkarlsso | 0:8dbd6bd9167f | 480 | lastChangeInterval = inPin->lastDownEvent.timeStamp - lastChangeTime; |
mkarlsso | 0:8dbd6bd9167f | 481 | lastChangeTime = inPin->lastDownEvent.timeStamp; |
mkarlsso | 0:8dbd6bd9167f | 482 | } else { |
mkarlsso | 0:8dbd6bd9167f | 483 | lastChangeInterval = timeKeeper - lastChangeTime; |
mkarlsso | 0:8dbd6bd9167f | 484 | lastChangeTime = timeKeeper; |
mkarlsso | 0:8dbd6bd9167f | 485 | }*/ |
mkarlsso | 0:8dbd6bd9167f | 486 | |
mkarlsso | 1:3a050d26d4f6 | 487 | if (triggerDownEventPtr != NULL) {execDown = true;} |
mkarlsso | 0:8dbd6bd9167f | 488 | } |
mkarlsso | 0:8dbd6bd9167f | 489 | } else if (lastInState == inState) { |
mkarlsso | 0:8dbd6bd9167f | 490 | |
mkarlsso | 1:3a050d26d4f6 | 491 | //Both up and down triggers must have happened, so we consider both (and execute in the right order) |
mkarlsso | 0:8dbd6bd9167f | 492 | if (inState == 1) { |
mkarlsso | 0:8dbd6bd9167f | 493 | |
mkarlsso | 0:8dbd6bd9167f | 494 | lastChangeInterval = inPin->lastUpEvent.timeStamp - inPin->lastDownEvent.timeStamp; |
mkarlsso | 0:8dbd6bd9167f | 495 | lastChangeTime = inPin->lastUpEvent.timeStamp; |
mkarlsso | 0:8dbd6bd9167f | 496 | |
mkarlsso | 0:8dbd6bd9167f | 497 | if (triggerDownEventPtr != NULL) {triggerDownEventPtr->execute();} |
mkarlsso | 0:8dbd6bd9167f | 498 | if (triggerUpEventPtr != NULL) {triggerUpEventPtr->execute();} |
mkarlsso | 0:8dbd6bd9167f | 499 | } else if (inState == 0) { |
mkarlsso | 0:8dbd6bd9167f | 500 | |
mkarlsso | 0:8dbd6bd9167f | 501 | lastChangeInterval = inPin->lastDownEvent.timeStamp - inPin->lastUpEvent.timeStamp; |
mkarlsso | 0:8dbd6bd9167f | 502 | lastChangeTime = inPin->lastDownEvent.timeStamp; |
mkarlsso | 0:8dbd6bd9167f | 503 | |
mkarlsso | 0:8dbd6bd9167f | 504 | if (triggerUpEventPtr != NULL) {triggerUpEventPtr->execute();} |
mkarlsso | 0:8dbd6bd9167f | 505 | if (triggerDownEventPtr != NULL) {triggerDownEventPtr->execute();} |
mkarlsso | 0:8dbd6bd9167f | 506 | } |
mkarlsso | 0:8dbd6bd9167f | 507 | } |
mkarlsso | 0:8dbd6bd9167f | 508 | |
mkarlsso | 1:3a050d26d4f6 | 509 | lastInState = inState; |
mkarlsso | 1:3a050d26d4f6 | 510 | inPin->lastUpEvent.triggered = false; |
mkarlsso | 1:3a050d26d4f6 | 511 | inPin->lastDownEvent.triggered = false; |
mkarlsso | 1:3a050d26d4f6 | 512 | |
mkarlsso | 1:3a050d26d4f6 | 513 | inPin->setUpdate(false); //This also checks if there were any buffered changes that occured |
mkarlsso | 1:3a050d26d4f6 | 514 | |
mkarlsso | 0:8dbd6bd9167f | 515 | } |
mkarlsso | 1:3a050d26d4f6 | 516 | } |
mkarlsso | 1:3a050d26d4f6 | 517 | if (execUp) { |
mkarlsso | 1:3a050d26d4f6 | 518 | triggerUpEventPtr->execute(); |
mkarlsso | 1:3a050d26d4f6 | 519 | } |
mkarlsso | 1:3a050d26d4f6 | 520 | |
mkarlsso | 1:3a050d26d4f6 | 521 | if (execDown) { |
mkarlsso | 1:3a050d26d4f6 | 522 | triggerDownEventPtr->execute(); |
mkarlsso | 0:8dbd6bd9167f | 523 | } |
mkarlsso | 0:8dbd6bd9167f | 524 | |
mkarlsso | 0:8dbd6bd9167f | 525 | return changed; |
mkarlsso | 0:8dbd6bd9167f | 526 | } |
mkarlsso | 0:8dbd6bd9167f | 527 | |
mkarlsso | 0:8dbd6bd9167f | 528 | int digitalPort::getLastChangeState() { |
mkarlsso | 0:8dbd6bd9167f | 529 | return lastInState; |
mkarlsso | 0:8dbd6bd9167f | 530 | } |
mkarlsso | 0:8dbd6bd9167f | 531 | uint32_t digitalPort::getTimeSinceLastChange() { |
mkarlsso | 0:8dbd6bd9167f | 532 | return lastChangeInterval; |
mkarlsso | 0:8dbd6bd9167f | 533 | |
mkarlsso | 0:8dbd6bd9167f | 534 | } |
mkarlsso | 0:8dbd6bd9167f | 535 | |
mkarlsso | 0:8dbd6bd9167f | 536 | intVariable::intVariable(): |
mkarlsso | 0:8dbd6bd9167f | 537 | value(0) { |
mkarlsso | 0:8dbd6bd9167f | 538 | isUsed = false; |
mkarlsso | 0:8dbd6bd9167f | 539 | } |
mkarlsso | 0:8dbd6bd9167f | 540 | |
mkarlsso | 0:8dbd6bd9167f | 541 | intVariable::intVariable(std::string& tagInput, int initialValue): |
mkarlsso | 0:8dbd6bd9167f | 542 | value(initialValue) |
mkarlsso | 0:8dbd6bd9167f | 543 | { |
mkarlsso | 0:8dbd6bd9167f | 544 | strncpy(tag,tagInput.data(),MAXVARNAMESIZE); |
mkarlsso | 0:8dbd6bd9167f | 545 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 546 | } |
mkarlsso | 0:8dbd6bd9167f | 547 | |
mkarlsso | 1:3a050d26d4f6 | 548 | void intVariable::set(const char* tagInput, int initialValue) { |
mkarlsso | 0:8dbd6bd9167f | 549 | value = initialValue; |
mkarlsso | 0:8dbd6bd9167f | 550 | //tag = string(tagInput); |
mkarlsso | 1:3a050d26d4f6 | 551 | strncpy(tag,tagInput,MAXVARNAMESIZE); |
mkarlsso | 0:8dbd6bd9167f | 552 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 553 | } |
mkarlsso | 0:8dbd6bd9167f | 554 | |
mkarlsso | 1:3a050d26d4f6 | 555 | void intVariable::release() { |
mkarlsso | 1:3a050d26d4f6 | 556 | isUsed = false; |
mkarlsso | 1:3a050d26d4f6 | 557 | } |
mkarlsso | 1:3a050d26d4f6 | 558 | |
mkarlsso | 0:8dbd6bd9167f | 559 | displayAction::displayAction(): |
mkarlsso | 0:8dbd6bd9167f | 560 | dText(string("--------------------------------------------------")){ |
mkarlsso | 0:8dbd6bd9167f | 561 | dVariable = NULL; |
mkarlsso | 0:8dbd6bd9167f | 562 | isUsed = false; |
mkarlsso | 0:8dbd6bd9167f | 563 | } |
mkarlsso | 0:8dbd6bd9167f | 564 | |
mkarlsso | 0:8dbd6bd9167f | 565 | void displayAction::release() { |
mkarlsso | 0:8dbd6bd9167f | 566 | dText = "--------------------------------------------------"; |
mkarlsso | 0:8dbd6bd9167f | 567 | dVariable = NULL; |
mkarlsso | 0:8dbd6bd9167f | 568 | isUsed = false; |
mkarlsso | 0:8dbd6bd9167f | 569 | } |
mkarlsso | 0:8dbd6bd9167f | 570 | |
mkarlsso | 0:8dbd6bd9167f | 571 | |
mkarlsso | 0:8dbd6bd9167f | 572 | void displayAction::set(int* variable, string varNameInput) { |
mkarlsso | 0:8dbd6bd9167f | 573 | dVariable = variable; |
mkarlsso | 0:8dbd6bd9167f | 574 | dText = varNameInput; |
mkarlsso | 0:8dbd6bd9167f | 575 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 576 | |
mkarlsso | 0:8dbd6bd9167f | 577 | } |
mkarlsso | 0:8dbd6bd9167f | 578 | |
mkarlsso | 0:8dbd6bd9167f | 579 | void displayAction::set(string text) { |
mkarlsso | 0:8dbd6bd9167f | 580 | dText = text; |
mkarlsso | 0:8dbd6bd9167f | 581 | dVariable = NULL; |
mkarlsso | 0:8dbd6bd9167f | 582 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 583 | } |
mkarlsso | 0:8dbd6bd9167f | 584 | |
mkarlsso | 0:8dbd6bd9167f | 585 | void displayAction::execute() { |
mkarlsso | 0:8dbd6bd9167f | 586 | |
mkarlsso | 0:8dbd6bd9167f | 587 | if (dVariable != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 588 | textDisplay << timeKeeper << " " << dText << " = " << *dVariable << "\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 589 | } else { |
mkarlsso | 0:8dbd6bd9167f | 590 | textDisplay << timeKeeper << " " << dText << "\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 591 | } |
mkarlsso | 0:8dbd6bd9167f | 592 | } |
mkarlsso | 0:8dbd6bd9167f | 593 | |
mkarlsso | 0:8dbd6bd9167f | 594 | triggerFunctionAction::triggerFunctionAction(): |
mkarlsso | 0:8dbd6bd9167f | 595 | functionNum(0) { |
mkarlsso | 0:8dbd6bd9167f | 596 | isUsed = false; |
mkarlsso | 0:8dbd6bd9167f | 597 | } |
mkarlsso | 0:8dbd6bd9167f | 598 | |
mkarlsso | 0:8dbd6bd9167f | 599 | triggerFunctionAction::triggerFunctionAction(int funcNum): |
mkarlsso | 0:8dbd6bd9167f | 600 | functionNum(funcNum) { |
mkarlsso | 0:8dbd6bd9167f | 601 | |
mkarlsso | 0:8dbd6bd9167f | 602 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 603 | |
mkarlsso | 0:8dbd6bd9167f | 604 | } |
mkarlsso | 0:8dbd6bd9167f | 605 | |
mkarlsso | 0:8dbd6bd9167f | 606 | void triggerFunctionAction::set(int funcNum) { |
mkarlsso | 0:8dbd6bd9167f | 607 | functionNum = funcNum; |
mkarlsso | 0:8dbd6bd9167f | 608 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 609 | } |
mkarlsso | 0:8dbd6bd9167f | 610 | |
mkarlsso | 0:8dbd6bd9167f | 611 | void triggerFunctionAction::execute() { |
mkarlsso | 0:8dbd6bd9167f | 612 | |
mkarlsso | 0:8dbd6bd9167f | 613 | if (functionSpotTaken[functionNum]) { |
mkarlsso | 0:8dbd6bd9167f | 614 | functionEventArray[functionNum]->execute(); |
mkarlsso | 0:8dbd6bd9167f | 615 | } |
mkarlsso | 0:8dbd6bd9167f | 616 | |
mkarlsso | 0:8dbd6bd9167f | 617 | } |
mkarlsso | 0:8dbd6bd9167f | 618 | |
mkarlsso | 0:8dbd6bd9167f | 619 | void triggerFunctionAction::release() { |
mkarlsso | 0:8dbd6bd9167f | 620 | isUsed = false; |
mkarlsso | 0:8dbd6bd9167f | 621 | } |
mkarlsso | 0:8dbd6bd9167f | 622 | |
mkarlsso | 0:8dbd6bd9167f | 623 | |
mkarlsso | 0:8dbd6bd9167f | 624 | |
mkarlsso | 0:8dbd6bd9167f | 625 | intCompare::intCompare(): |
mkarlsso | 0:8dbd6bd9167f | 626 | port(NULL) { |
mkarlsso | 0:8dbd6bd9167f | 627 | cmpVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 628 | cmpValGlobal = false; |
mkarlsso | 0:8dbd6bd9167f | 629 | intVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 630 | intOp = NULL; |
mkarlsso | 0:8dbd6bd9167f | 631 | portValPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 632 | isUsed = false; |
mkarlsso | 0:8dbd6bd9167f | 633 | |
mkarlsso | 0:8dbd6bd9167f | 634 | } |
mkarlsso | 0:8dbd6bd9167f | 635 | intCompare::intCompare(digitalPort* portInput, const char* cmpString, int cmpValInput, int whichToUse): |
mkarlsso | 0:8dbd6bd9167f | 636 | port(portInput) { |
mkarlsso | 0:8dbd6bd9167f | 637 | cmpVal = new int(cmpValInput); |
mkarlsso | 0:8dbd6bd9167f | 638 | cmpValGlobal = false; |
mkarlsso | 0:8dbd6bd9167f | 639 | intVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 640 | intOp = NULL; |
mkarlsso | 0:8dbd6bd9167f | 641 | setPointer(cmpString); |
mkarlsso | 0:8dbd6bd9167f | 642 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 643 | if (whichToUse == 1) { |
mkarlsso | 0:8dbd6bd9167f | 644 | portValPtr = &port->inState; |
mkarlsso | 0:8dbd6bd9167f | 645 | } else { |
mkarlsso | 0:8dbd6bd9167f | 646 | portValPtr = &port->outState; |
mkarlsso | 0:8dbd6bd9167f | 647 | } |
mkarlsso | 0:8dbd6bd9167f | 648 | } |
mkarlsso | 0:8dbd6bd9167f | 649 | |
mkarlsso | 0:8dbd6bd9167f | 650 | intCompare::intCompare(digitalPort* portInput, const char* cmpString, int* cmpIntVarInput, int whichToUse): |
mkarlsso | 0:8dbd6bd9167f | 651 | port(portInput), |
mkarlsso | 0:8dbd6bd9167f | 652 | cmpVal(cmpIntVarInput) { |
mkarlsso | 0:8dbd6bd9167f | 653 | cmpValGlobal = true; |
mkarlsso | 0:8dbd6bd9167f | 654 | intVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 655 | intOp = NULL; |
mkarlsso | 0:8dbd6bd9167f | 656 | setPointer(cmpString); |
mkarlsso | 0:8dbd6bd9167f | 657 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 658 | if (whichToUse == 1) { |
mkarlsso | 0:8dbd6bd9167f | 659 | portValPtr = &port->inState; |
mkarlsso | 0:8dbd6bd9167f | 660 | } else { |
mkarlsso | 0:8dbd6bd9167f | 661 | portValPtr = &port->outState; |
mkarlsso | 0:8dbd6bd9167f | 662 | } |
mkarlsso | 0:8dbd6bd9167f | 663 | } |
mkarlsso | 0:8dbd6bd9167f | 664 | |
mkarlsso | 0:8dbd6bd9167f | 665 | intCompare::intCompare(int* intVarInput, const char* cmpString, int* cmpIntVarInput): |
mkarlsso | 0:8dbd6bd9167f | 666 | cmpVal(cmpIntVarInput), |
mkarlsso | 0:8dbd6bd9167f | 667 | intVal(intVarInput) { |
mkarlsso | 0:8dbd6bd9167f | 668 | cmpValGlobal = true; |
mkarlsso | 0:8dbd6bd9167f | 669 | port = NULL; |
mkarlsso | 0:8dbd6bd9167f | 670 | intOp = NULL; |
mkarlsso | 0:8dbd6bd9167f | 671 | portValPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 672 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 673 | setPointer(cmpString); |
mkarlsso | 0:8dbd6bd9167f | 674 | } |
mkarlsso | 0:8dbd6bd9167f | 675 | |
mkarlsso | 0:8dbd6bd9167f | 676 | intCompare::intCompare(int* intVarInput, const char* cmpString, int cmpValInput): |
mkarlsso | 0:8dbd6bd9167f | 677 | intVal(intVarInput){ |
mkarlsso | 0:8dbd6bd9167f | 678 | cmpVal = new int(cmpValInput); |
mkarlsso | 0:8dbd6bd9167f | 679 | cmpValGlobal = false; |
mkarlsso | 0:8dbd6bd9167f | 680 | port = NULL; |
mkarlsso | 0:8dbd6bd9167f | 681 | intOp = NULL; |
mkarlsso | 0:8dbd6bd9167f | 682 | portValPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 683 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 684 | setPointer(cmpString); |
mkarlsso | 0:8dbd6bd9167f | 685 | } |
mkarlsso | 0:8dbd6bd9167f | 686 | |
mkarlsso | 0:8dbd6bd9167f | 687 | intCompare::intCompare(int* intVarInput, const char* cmpString, intOperation* cmpIntOpInput): |
mkarlsso | 0:8dbd6bd9167f | 688 | intVal(intVarInput) { |
mkarlsso | 0:8dbd6bd9167f | 689 | cmpVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 690 | port = NULL; |
mkarlsso | 0:8dbd6bd9167f | 691 | portValPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 692 | cmpValGlobal = true; |
mkarlsso | 0:8dbd6bd9167f | 693 | intOp = cmpIntOpInput; |
mkarlsso | 0:8dbd6bd9167f | 694 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 695 | setPointer_operation(cmpString); |
mkarlsso | 0:8dbd6bd9167f | 696 | } |
mkarlsso | 0:8dbd6bd9167f | 697 | |
mkarlsso | 0:8dbd6bd9167f | 698 | intCompare::intCompare(digitalPort* portInput, const char* cmpString, intOperation* cmpIntOpInput, int whichToUse): |
mkarlsso | 0:8dbd6bd9167f | 699 | port(portInput) { |
mkarlsso | 0:8dbd6bd9167f | 700 | cmpVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 701 | intVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 702 | cmpValGlobal = true; |
mkarlsso | 0:8dbd6bd9167f | 703 | intOp = cmpIntOpInput; |
mkarlsso | 0:8dbd6bd9167f | 704 | setPointer_operation(cmpString); |
mkarlsso | 0:8dbd6bd9167f | 705 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 706 | if (whichToUse == 1) { |
mkarlsso | 0:8dbd6bd9167f | 707 | portValPtr = &port->inState; |
mkarlsso | 0:8dbd6bd9167f | 708 | } else { |
mkarlsso | 0:8dbd6bd9167f | 709 | portValPtr = &port->outState; |
mkarlsso | 0:8dbd6bd9167f | 710 | } |
mkarlsso | 0:8dbd6bd9167f | 711 | } |
mkarlsso | 0:8dbd6bd9167f | 712 | |
mkarlsso | 0:8dbd6bd9167f | 713 | |
mkarlsso | 0:8dbd6bd9167f | 714 | |
mkarlsso | 0:8dbd6bd9167f | 715 | void intCompare::set(digitalPort* portInput, const char* cmpString, int cmpValInput, int whichToUse) { |
mkarlsso | 0:8dbd6bd9167f | 716 | port = portInput; |
mkarlsso | 0:8dbd6bd9167f | 717 | cmpVal = new int(cmpValInput); |
mkarlsso | 0:8dbd6bd9167f | 718 | cmpValGlobal = false; |
mkarlsso | 0:8dbd6bd9167f | 719 | intVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 720 | intOp = NULL; |
mkarlsso | 0:8dbd6bd9167f | 721 | setPointer(cmpString); |
mkarlsso | 0:8dbd6bd9167f | 722 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 723 | if (whichToUse == 1) { |
mkarlsso | 0:8dbd6bd9167f | 724 | portValPtr = &port->inState; |
mkarlsso | 0:8dbd6bd9167f | 725 | } else { |
mkarlsso | 0:8dbd6bd9167f | 726 | portValPtr = &port->outState; |
mkarlsso | 0:8dbd6bd9167f | 727 | } |
mkarlsso | 0:8dbd6bd9167f | 728 | } |
mkarlsso | 0:8dbd6bd9167f | 729 | |
mkarlsso | 0:8dbd6bd9167f | 730 | void intCompare::set(digitalPort* portInput, const char* cmpString, int* cmpIntVarInput, int whichToUse) { |
mkarlsso | 0:8dbd6bd9167f | 731 | port = portInput; |
mkarlsso | 0:8dbd6bd9167f | 732 | cmpVal = cmpIntVarInput; |
mkarlsso | 0:8dbd6bd9167f | 733 | cmpValGlobal = true; |
mkarlsso | 0:8dbd6bd9167f | 734 | intVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 735 | intOp = NULL; |
mkarlsso | 0:8dbd6bd9167f | 736 | setPointer(cmpString); |
mkarlsso | 0:8dbd6bd9167f | 737 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 738 | if (whichToUse == 1) { |
mkarlsso | 0:8dbd6bd9167f | 739 | portValPtr = &port->inState; |
mkarlsso | 0:8dbd6bd9167f | 740 | } else { |
mkarlsso | 0:8dbd6bd9167f | 741 | portValPtr = &port->outState; |
mkarlsso | 0:8dbd6bd9167f | 742 | } |
mkarlsso | 0:8dbd6bd9167f | 743 | } |
mkarlsso | 0:8dbd6bd9167f | 744 | |
mkarlsso | 0:8dbd6bd9167f | 745 | void intCompare::set(int* intVarInput, const char* cmpString, int* cmpIntVarInput) { |
mkarlsso | 0:8dbd6bd9167f | 746 | cmpVal = cmpIntVarInput; |
mkarlsso | 0:8dbd6bd9167f | 747 | intVal = intVarInput; |
mkarlsso | 0:8dbd6bd9167f | 748 | cmpValGlobal = true; |
mkarlsso | 0:8dbd6bd9167f | 749 | port = NULL; |
mkarlsso | 0:8dbd6bd9167f | 750 | intOp = NULL; |
mkarlsso | 0:8dbd6bd9167f | 751 | portValPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 752 | setPointer(cmpString); |
mkarlsso | 0:8dbd6bd9167f | 753 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 754 | } |
mkarlsso | 0:8dbd6bd9167f | 755 | |
mkarlsso | 0:8dbd6bd9167f | 756 | void intCompare::set(int* intVarInput, const char* cmpString, int cmpValInput) { |
mkarlsso | 0:8dbd6bd9167f | 757 | intVal = intVarInput; |
mkarlsso | 0:8dbd6bd9167f | 758 | cmpVal = new int(cmpValInput); |
mkarlsso | 0:8dbd6bd9167f | 759 | cmpValGlobal = false; |
mkarlsso | 0:8dbd6bd9167f | 760 | port = NULL; |
mkarlsso | 0:8dbd6bd9167f | 761 | intOp = NULL; |
mkarlsso | 0:8dbd6bd9167f | 762 | portValPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 763 | setPointer(cmpString); |
mkarlsso | 0:8dbd6bd9167f | 764 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 765 | } |
mkarlsso | 0:8dbd6bd9167f | 766 | |
mkarlsso | 0:8dbd6bd9167f | 767 | void intCompare::set(int* intVarInput, const char* cmpString, intOperation* cmpIntOpInput) { |
mkarlsso | 0:8dbd6bd9167f | 768 | intVal = intVarInput; |
mkarlsso | 0:8dbd6bd9167f | 769 | cmpVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 770 | port = NULL; |
mkarlsso | 0:8dbd6bd9167f | 771 | portValPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 772 | cmpValGlobal = true; |
mkarlsso | 0:8dbd6bd9167f | 773 | intOp = cmpIntOpInput; |
mkarlsso | 0:8dbd6bd9167f | 774 | setPointer_operation(cmpString); |
mkarlsso | 0:8dbd6bd9167f | 775 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 776 | } |
mkarlsso | 0:8dbd6bd9167f | 777 | |
mkarlsso | 0:8dbd6bd9167f | 778 | void intCompare::set(digitalPort* portInput, const char* cmpString, intOperation* cmpIntOpInput, int whichToUse) { |
mkarlsso | 0:8dbd6bd9167f | 779 | port = portInput; |
mkarlsso | 0:8dbd6bd9167f | 780 | cmpVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 781 | intVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 782 | cmpValGlobal = true; |
mkarlsso | 0:8dbd6bd9167f | 783 | intOp = cmpIntOpInput; |
mkarlsso | 0:8dbd6bd9167f | 784 | setPointer_operation(cmpString); |
mkarlsso | 0:8dbd6bd9167f | 785 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 786 | if (whichToUse == 1) { |
mkarlsso | 0:8dbd6bd9167f | 787 | portValPtr = &port->inState; |
mkarlsso | 0:8dbd6bd9167f | 788 | } else { |
mkarlsso | 0:8dbd6bd9167f | 789 | portValPtr = &port->outState; |
mkarlsso | 0:8dbd6bd9167f | 790 | } |
mkarlsso | 0:8dbd6bd9167f | 791 | } |
mkarlsso | 0:8dbd6bd9167f | 792 | |
mkarlsso | 0:8dbd6bd9167f | 793 | |
mkarlsso | 0:8dbd6bd9167f | 794 | |
mkarlsso | 0:8dbd6bd9167f | 795 | intCompare::~intCompare() { |
mkarlsso | 0:8dbd6bd9167f | 796 | if (!cmpValGlobal) delete cmpVal; //we only delete the intCompare object if it was created locally |
mkarlsso | 0:8dbd6bd9167f | 797 | delete intOp; |
mkarlsso | 0:8dbd6bd9167f | 798 | } |
mkarlsso | 0:8dbd6bd9167f | 799 | |
mkarlsso | 0:8dbd6bd9167f | 800 | void intCompare::release() { |
mkarlsso | 0:8dbd6bd9167f | 801 | if (!cmpValGlobal) delete cmpVal; //we only delete the intCompare object if it was created locally |
mkarlsso | 0:8dbd6bd9167f | 802 | if (intOp != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 803 | intOp->release(); |
mkarlsso | 0:8dbd6bd9167f | 804 | } |
mkarlsso | 0:8dbd6bd9167f | 805 | port = NULL; |
mkarlsso | 0:8dbd6bd9167f | 806 | cmpVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 807 | cmpValGlobal = false; |
mkarlsso | 0:8dbd6bd9167f | 808 | intVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 809 | intOp = NULL; |
mkarlsso | 0:8dbd6bd9167f | 810 | portValPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 811 | isUsed = false; |
mkarlsso | 0:8dbd6bd9167f | 812 | } |
mkarlsso | 0:8dbd6bd9167f | 813 | |
mkarlsso | 0:8dbd6bd9167f | 814 | |
mkarlsso | 0:8dbd6bd9167f | 815 | void intCompare::setPointer(const char* cmpString) { |
mkarlsso | 0:8dbd6bd9167f | 816 | if (strcmp(cmpString, ">") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 817 | isTruePtr = &intCompare::greaterThan; |
mkarlsso | 0:8dbd6bd9167f | 818 | }else if (strcmp(cmpString, ">=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 819 | isTruePtr = &intCompare::greaterOrEqual; |
mkarlsso | 0:8dbd6bd9167f | 820 | }else if (strcmp(cmpString, "<") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 821 | isTruePtr = &intCompare::lessThan; |
mkarlsso | 0:8dbd6bd9167f | 822 | }else if (strcmp(cmpString, "<=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 823 | isTruePtr = &intCompare::lessOrEqual; |
mkarlsso | 0:8dbd6bd9167f | 824 | }else if (strcmp(cmpString, "==") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 825 | isTruePtr = &intCompare::equal; |
mkarlsso | 0:8dbd6bd9167f | 826 | }else if (strcmp(cmpString, "!=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 827 | isTruePtr = &intCompare::notEqual; |
mkarlsso | 0:8dbd6bd9167f | 828 | } |
mkarlsso | 0:8dbd6bd9167f | 829 | } |
mkarlsso | 0:8dbd6bd9167f | 830 | |
mkarlsso | 0:8dbd6bd9167f | 831 | void intCompare::setPointer_operation(const char* cmpString) { |
mkarlsso | 0:8dbd6bd9167f | 832 | if (strcmp(cmpString, ">") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 833 | isTruePtr = &intCompare::greaterThan_op; |
mkarlsso | 0:8dbd6bd9167f | 834 | }else if (strcmp(cmpString, ">=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 835 | isTruePtr = &intCompare::greaterOrEqual_op; |
mkarlsso | 0:8dbd6bd9167f | 836 | }else if (strcmp(cmpString, "<") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 837 | isTruePtr = &intCompare::lessThan_op; |
mkarlsso | 0:8dbd6bd9167f | 838 | }else if (strcmp(cmpString, "<=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 839 | isTruePtr = &intCompare::lessOrEqual_op; |
mkarlsso | 0:8dbd6bd9167f | 840 | }else if (strcmp(cmpString, "==") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 841 | isTruePtr = &intCompare::equal_op; |
mkarlsso | 0:8dbd6bd9167f | 842 | }else if (strcmp(cmpString, "!=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 843 | isTruePtr = &intCompare::notEqual_op; |
mkarlsso | 0:8dbd6bd9167f | 844 | } |
mkarlsso | 0:8dbd6bd9167f | 845 | } |
mkarlsso | 0:8dbd6bd9167f | 846 | |
mkarlsso | 0:8dbd6bd9167f | 847 | bool intCompare::isTrue() { |
mkarlsso | 0:8dbd6bd9167f | 848 | return (this->*isTruePtr)(); |
mkarlsso | 0:8dbd6bd9167f | 849 | |
mkarlsso | 0:8dbd6bd9167f | 850 | } |
mkarlsso | 0:8dbd6bd9167f | 851 | |
mkarlsso | 0:8dbd6bd9167f | 852 | bool intCompare::notEqual() { |
mkarlsso | 0:8dbd6bd9167f | 853 | if (intVal != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 854 | return (*intVal != *cmpVal); |
mkarlsso | 0:8dbd6bd9167f | 855 | } else { |
mkarlsso | 0:8dbd6bd9167f | 856 | return (*portValPtr != *cmpVal); |
mkarlsso | 0:8dbd6bd9167f | 857 | } |
mkarlsso | 0:8dbd6bd9167f | 858 | } |
mkarlsso | 0:8dbd6bd9167f | 859 | |
mkarlsso | 0:8dbd6bd9167f | 860 | bool intCompare::greaterThan() { |
mkarlsso | 0:8dbd6bd9167f | 861 | if (intVal != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 862 | return (*intVal > *cmpVal); |
mkarlsso | 0:8dbd6bd9167f | 863 | } else { |
mkarlsso | 0:8dbd6bd9167f | 864 | return (*portValPtr > *cmpVal); |
mkarlsso | 0:8dbd6bd9167f | 865 | } |
mkarlsso | 0:8dbd6bd9167f | 866 | } |
mkarlsso | 0:8dbd6bd9167f | 867 | |
mkarlsso | 0:8dbd6bd9167f | 868 | bool intCompare::greaterOrEqual() { |
mkarlsso | 0:8dbd6bd9167f | 869 | if (intVal != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 870 | return (*intVal >= *cmpVal); |
mkarlsso | 0:8dbd6bd9167f | 871 | } else { |
mkarlsso | 0:8dbd6bd9167f | 872 | return (*portValPtr >= *cmpVal); |
mkarlsso | 0:8dbd6bd9167f | 873 | } |
mkarlsso | 0:8dbd6bd9167f | 874 | } |
mkarlsso | 0:8dbd6bd9167f | 875 | |
mkarlsso | 0:8dbd6bd9167f | 876 | bool intCompare::lessThan() { |
mkarlsso | 0:8dbd6bd9167f | 877 | if (intVal != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 878 | return (*intVal < *cmpVal); |
mkarlsso | 0:8dbd6bd9167f | 879 | } else { |
mkarlsso | 0:8dbd6bd9167f | 880 | return (*portValPtr < *cmpVal); |
mkarlsso | 0:8dbd6bd9167f | 881 | } |
mkarlsso | 0:8dbd6bd9167f | 882 | } |
mkarlsso | 0:8dbd6bd9167f | 883 | |
mkarlsso | 0:8dbd6bd9167f | 884 | bool intCompare::lessOrEqual() { |
mkarlsso | 0:8dbd6bd9167f | 885 | if (intVal != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 886 | return (*intVal <= *cmpVal); |
mkarlsso | 0:8dbd6bd9167f | 887 | } else { |
mkarlsso | 0:8dbd6bd9167f | 888 | return (*portValPtr <= *cmpVal); |
mkarlsso | 0:8dbd6bd9167f | 889 | } |
mkarlsso | 0:8dbd6bd9167f | 890 | } |
mkarlsso | 0:8dbd6bd9167f | 891 | |
mkarlsso | 0:8dbd6bd9167f | 892 | bool intCompare::equal() { |
mkarlsso | 0:8dbd6bd9167f | 893 | if (intVal != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 894 | return (*intVal == *cmpVal); |
mkarlsso | 0:8dbd6bd9167f | 895 | } else { |
mkarlsso | 0:8dbd6bd9167f | 896 | return (*portValPtr == *cmpVal); |
mkarlsso | 0:8dbd6bd9167f | 897 | } |
mkarlsso | 0:8dbd6bd9167f | 898 | } |
mkarlsso | 0:8dbd6bd9167f | 899 | |
mkarlsso | 0:8dbd6bd9167f | 900 | bool intCompare::notEqual_op() { |
mkarlsso | 0:8dbd6bd9167f | 901 | if (intVal != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 902 | return (*intVal != intOp->execute()); |
mkarlsso | 0:8dbd6bd9167f | 903 | } else { |
mkarlsso | 0:8dbd6bd9167f | 904 | return (*portValPtr != intOp->execute()); |
mkarlsso | 0:8dbd6bd9167f | 905 | } |
mkarlsso | 0:8dbd6bd9167f | 906 | } |
mkarlsso | 0:8dbd6bd9167f | 907 | |
mkarlsso | 0:8dbd6bd9167f | 908 | bool intCompare::greaterThan_op() { |
mkarlsso | 0:8dbd6bd9167f | 909 | if (intVal != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 910 | return (*intVal > intOp->execute()); |
mkarlsso | 0:8dbd6bd9167f | 911 | } else { |
mkarlsso | 0:8dbd6bd9167f | 912 | return (*portValPtr > intOp->execute()); |
mkarlsso | 0:8dbd6bd9167f | 913 | } |
mkarlsso | 0:8dbd6bd9167f | 914 | } |
mkarlsso | 0:8dbd6bd9167f | 915 | |
mkarlsso | 0:8dbd6bd9167f | 916 | bool intCompare::greaterOrEqual_op() { |
mkarlsso | 0:8dbd6bd9167f | 917 | if (intVal != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 918 | return (*intVal >= intOp->execute()); |
mkarlsso | 0:8dbd6bd9167f | 919 | } else { |
mkarlsso | 0:8dbd6bd9167f | 920 | return (*portValPtr >= intOp->execute()); |
mkarlsso | 0:8dbd6bd9167f | 921 | } |
mkarlsso | 0:8dbd6bd9167f | 922 | } |
mkarlsso | 0:8dbd6bd9167f | 923 | |
mkarlsso | 0:8dbd6bd9167f | 924 | bool intCompare::lessThan_op() { |
mkarlsso | 0:8dbd6bd9167f | 925 | if (intVal != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 926 | return (*intVal < intOp->execute()); |
mkarlsso | 0:8dbd6bd9167f | 927 | } else { |
mkarlsso | 0:8dbd6bd9167f | 928 | return (*portValPtr < intOp->execute()); |
mkarlsso | 0:8dbd6bd9167f | 929 | } |
mkarlsso | 0:8dbd6bd9167f | 930 | } |
mkarlsso | 0:8dbd6bd9167f | 931 | |
mkarlsso | 0:8dbd6bd9167f | 932 | bool intCompare::lessOrEqual_op() { |
mkarlsso | 0:8dbd6bd9167f | 933 | if (intVal != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 934 | return (*intVal <= intOp->execute()); |
mkarlsso | 0:8dbd6bd9167f | 935 | } else { |
mkarlsso | 0:8dbd6bd9167f | 936 | return (*portValPtr <= intOp->execute()); |
mkarlsso | 0:8dbd6bd9167f | 937 | } |
mkarlsso | 0:8dbd6bd9167f | 938 | } |
mkarlsso | 0:8dbd6bd9167f | 939 | |
mkarlsso | 0:8dbd6bd9167f | 940 | bool intCompare::equal_op() { |
mkarlsso | 0:8dbd6bd9167f | 941 | if (intVal != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 942 | return (*intVal == intOp->execute()); |
mkarlsso | 0:8dbd6bd9167f | 943 | } else { |
mkarlsso | 0:8dbd6bd9167f | 944 | return (*portValPtr == intOp->execute()); |
mkarlsso | 0:8dbd6bd9167f | 945 | } |
mkarlsso | 0:8dbd6bd9167f | 946 | } |
mkarlsso | 0:8dbd6bd9167f | 947 | |
mkarlsso | 0:8dbd6bd9167f | 948 | intOperation::intOperation(): |
mkarlsso | 0:8dbd6bd9167f | 949 | randHigh(-1) { |
mkarlsso | 0:8dbd6bd9167f | 950 | cmpVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 951 | intVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 952 | opPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 953 | executePtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 954 | cmpValGlobal = false; |
mkarlsso | 0:8dbd6bd9167f | 955 | isUsed = false; |
mkarlsso | 0:8dbd6bd9167f | 956 | isClockAssign = false; |
mkarlsso | 0:8dbd6bd9167f | 957 | inputsFlipped = false; |
mkarlsso | 0:8dbd6bd9167f | 958 | |
mkarlsso | 0:8dbd6bd9167f | 959 | } |
mkarlsso | 0:8dbd6bd9167f | 960 | |
mkarlsso | 0:8dbd6bd9167f | 961 | /* |
mkarlsso | 0:8dbd6bd9167f | 962 | intOperation::intOperation(int randParam, const char* cmpString, int cmpValInput): |
mkarlsso | 0:8dbd6bd9167f | 963 | randHigh(randParam) { |
mkarlsso | 0:8dbd6bd9167f | 964 | cmpVal = new int(cmpValInput); |
mkarlsso | 0:8dbd6bd9167f | 965 | intVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 966 | opPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 967 | cmpValGlobal = false; |
mkarlsso | 0:8dbd6bd9167f | 968 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 969 | if (strcmp(cmpString, "+") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 970 | executePtr = &intOperation::add; |
mkarlsso | 0:8dbd6bd9167f | 971 | }else if (strcmp(cmpString, "-") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 972 | executePtr = &intOperation::subtract; |
mkarlsso | 0:8dbd6bd9167f | 973 | }else if (strcmp(cmpString, "+=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 974 | executePtr = &intOperation::addAndStore; |
mkarlsso | 0:8dbd6bd9167f | 975 | }else if (strcmp(cmpString, "-=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 976 | executePtr = &intOperation::subtractAndStore; |
mkarlsso | 0:8dbd6bd9167f | 977 | }else if (strcmp(cmpString, "=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 978 | executePtr = &intOperation::equals; |
mkarlsso | 0:8dbd6bd9167f | 979 | } |
mkarlsso | 0:8dbd6bd9167f | 980 | |
mkarlsso | 0:8dbd6bd9167f | 981 | } |
mkarlsso | 0:8dbd6bd9167f | 982 | |
mkarlsso | 0:8dbd6bd9167f | 983 | intOperation::intOperation(int randParam, const char* cmpString, int* cmpIntVarInput): |
mkarlsso | 0:8dbd6bd9167f | 984 | randHigh(randParam), |
mkarlsso | 0:8dbd6bd9167f | 985 | cmpVal(cmpIntVarInput) { |
mkarlsso | 0:8dbd6bd9167f | 986 | intVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 987 | opPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 988 | cmpValGlobal = true; |
mkarlsso | 0:8dbd6bd9167f | 989 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 990 | if (strcmp(cmpString, "+") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 991 | executePtr = &intOperation::add; |
mkarlsso | 0:8dbd6bd9167f | 992 | }else if (strcmp(cmpString, "-") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 993 | executePtr = &intOperation::subtract; |
mkarlsso | 0:8dbd6bd9167f | 994 | }else if (strcmp(cmpString, "+=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 995 | executePtr = &intOperation::addAndStore; |
mkarlsso | 0:8dbd6bd9167f | 996 | }else if (strcmp(cmpString, "-=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 997 | executePtr = &intOperation::subtractAndStore; |
mkarlsso | 0:8dbd6bd9167f | 998 | }else if (strcmp(cmpString, "=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 999 | executePtr = &intOperation::equals; |
mkarlsso | 0:8dbd6bd9167f | 1000 | } |
mkarlsso | 0:8dbd6bd9167f | 1001 | } |
mkarlsso | 0:8dbd6bd9167f | 1002 | |
mkarlsso | 0:8dbd6bd9167f | 1003 | intOperation::intOperation(int* intVarInput, const char* cmpString, int cmpValInput): |
mkarlsso | 0:8dbd6bd9167f | 1004 | intVal(intVarInput) { |
mkarlsso | 0:8dbd6bd9167f | 1005 | cmpVal = new int(cmpValInput); |
mkarlsso | 0:8dbd6bd9167f | 1006 | randHigh = -1; |
mkarlsso | 0:8dbd6bd9167f | 1007 | opPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1008 | cmpValGlobal = false; |
mkarlsso | 0:8dbd6bd9167f | 1009 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1010 | if (strcmp(cmpString, "+") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1011 | executePtr = &intOperation::add; |
mkarlsso | 0:8dbd6bd9167f | 1012 | }else if (strcmp(cmpString, "-") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1013 | executePtr = &intOperation::subtract; |
mkarlsso | 0:8dbd6bd9167f | 1014 | }else if (strcmp(cmpString, "+=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1015 | executePtr = &intOperation::addAndStore; |
mkarlsso | 0:8dbd6bd9167f | 1016 | }else if (strcmp(cmpString, "-=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1017 | executePtr = &intOperation::subtractAndStore; |
mkarlsso | 0:8dbd6bd9167f | 1018 | }else if (strcmp(cmpString, "=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1019 | executePtr = &intOperation::equals; |
mkarlsso | 0:8dbd6bd9167f | 1020 | } |
mkarlsso | 0:8dbd6bd9167f | 1021 | } |
mkarlsso | 0:8dbd6bd9167f | 1022 | |
mkarlsso | 0:8dbd6bd9167f | 1023 | intOperation::intOperation(int* intVarInput, const char* cmpString, int* cmpIntVarInput): |
mkarlsso | 0:8dbd6bd9167f | 1024 | cmpVal(cmpIntVarInput), |
mkarlsso | 0:8dbd6bd9167f | 1025 | intVal(intVarInput) { |
mkarlsso | 0:8dbd6bd9167f | 1026 | randHigh = -1; |
mkarlsso | 0:8dbd6bd9167f | 1027 | opPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1028 | cmpValGlobal = true; |
mkarlsso | 0:8dbd6bd9167f | 1029 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1030 | if (strcmp(cmpString, "+") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1031 | executePtr = &intOperation::add; |
mkarlsso | 0:8dbd6bd9167f | 1032 | }else if (strcmp(cmpString, "-") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1033 | executePtr = &intOperation::subtract; |
mkarlsso | 0:8dbd6bd9167f | 1034 | }else if (strcmp(cmpString, "+=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1035 | executePtr = &intOperation::addAndStore; |
mkarlsso | 0:8dbd6bd9167f | 1036 | }else if (strcmp(cmpString, "-=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1037 | executePtr = &intOperation::subtractAndStore; |
mkarlsso | 0:8dbd6bd9167f | 1038 | }else if (strcmp(cmpString, "=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1039 | executePtr = &intOperation::equals; |
mkarlsso | 0:8dbd6bd9167f | 1040 | } |
mkarlsso | 0:8dbd6bd9167f | 1041 | } |
mkarlsso | 0:8dbd6bd9167f | 1042 | |
mkarlsso | 0:8dbd6bd9167f | 1043 | intOperation::intOperation(int* intVarInput, intOperation* operationInput): |
mkarlsso | 0:8dbd6bd9167f | 1044 | intVal(intVarInput) { |
mkarlsso | 0:8dbd6bd9167f | 1045 | cmpVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1046 | randHigh = -1; |
mkarlsso | 0:8dbd6bd9167f | 1047 | opPtr = operationInput; |
mkarlsso | 0:8dbd6bd9167f | 1048 | executePtr = &intOperation::equals; |
mkarlsso | 0:8dbd6bd9167f | 1049 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1050 | } |
mkarlsso | 0:8dbd6bd9167f | 1051 | */ |
mkarlsso | 0:8dbd6bd9167f | 1052 | |
mkarlsso | 0:8dbd6bd9167f | 1053 | void intOperation::setRandOp(int randParam, const char* cmpString, int cmpValInput, bool flipped) { |
mkarlsso | 0:8dbd6bd9167f | 1054 | randHigh = randParam; |
mkarlsso | 0:8dbd6bd9167f | 1055 | cmpVal = new int(cmpValInput); |
mkarlsso | 0:8dbd6bd9167f | 1056 | intVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1057 | opPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1058 | cmpValGlobal = false; |
mkarlsso | 0:8dbd6bd9167f | 1059 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1060 | inputsFlipped = flipped; |
mkarlsso | 0:8dbd6bd9167f | 1061 | if (strcmp(cmpString, "+") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1062 | executePtr = &intOperation::add; |
mkarlsso | 0:8dbd6bd9167f | 1063 | }else if (strcmp(cmpString, "-") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1064 | executePtr = &intOperation::subtract; |
mkarlsso | 0:8dbd6bd9167f | 1065 | }else if (strcmp(cmpString, "=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1066 | executePtr = &intOperation::equals; |
mkarlsso | 0:8dbd6bd9167f | 1067 | } |
mkarlsso | 0:8dbd6bd9167f | 1068 | |
mkarlsso | 0:8dbd6bd9167f | 1069 | } |
mkarlsso | 0:8dbd6bd9167f | 1070 | |
mkarlsso | 0:8dbd6bd9167f | 1071 | void intOperation::setRandOp(int randParam, const char* cmpString, int* cmpIntVarInput, bool flipped) { |
mkarlsso | 0:8dbd6bd9167f | 1072 | randHigh = randParam; |
mkarlsso | 0:8dbd6bd9167f | 1073 | cmpVal = cmpIntVarInput; |
mkarlsso | 0:8dbd6bd9167f | 1074 | intVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1075 | opPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1076 | cmpValGlobal = true; |
mkarlsso | 0:8dbd6bd9167f | 1077 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1078 | inputsFlipped = flipped; |
mkarlsso | 0:8dbd6bd9167f | 1079 | if (strcmp(cmpString, "+") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1080 | executePtr = &intOperation::add; |
mkarlsso | 0:8dbd6bd9167f | 1081 | }else if (strcmp(cmpString, "-") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1082 | executePtr = &intOperation::subtract; |
mkarlsso | 0:8dbd6bd9167f | 1083 | }else if (strcmp(cmpString, "=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1084 | executePtr = &intOperation::equals; |
mkarlsso | 0:8dbd6bd9167f | 1085 | } |
mkarlsso | 0:8dbd6bd9167f | 1086 | } |
mkarlsso | 0:8dbd6bd9167f | 1087 | |
mkarlsso | 0:8dbd6bd9167f | 1088 | void intOperation::set(int* intVarInput, const char* cmpString, int cmpValInput) { |
mkarlsso | 0:8dbd6bd9167f | 1089 | |
mkarlsso | 0:8dbd6bd9167f | 1090 | intVal = intVarInput; |
mkarlsso | 0:8dbd6bd9167f | 1091 | cmpVal = new int(cmpValInput); |
mkarlsso | 0:8dbd6bd9167f | 1092 | randHigh = -1; |
mkarlsso | 0:8dbd6bd9167f | 1093 | opPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1094 | cmpValGlobal = false; |
mkarlsso | 0:8dbd6bd9167f | 1095 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1096 | if (strcmp(cmpString, "+") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1097 | executePtr = &intOperation::add; |
mkarlsso | 0:8dbd6bd9167f | 1098 | }else if (strcmp(cmpString, "-") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1099 | executePtr = &intOperation::subtract; |
mkarlsso | 0:8dbd6bd9167f | 1100 | }else if (strcmp(cmpString, "+=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1101 | executePtr = &intOperation::addAndStore; |
mkarlsso | 0:8dbd6bd9167f | 1102 | }else if (strcmp(cmpString, "-=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1103 | executePtr = &intOperation::subtractAndStore; |
mkarlsso | 0:8dbd6bd9167f | 1104 | }else if (strcmp(cmpString, "=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1105 | executePtr = &intOperation::equals; |
mkarlsso | 0:8dbd6bd9167f | 1106 | } |
mkarlsso | 0:8dbd6bd9167f | 1107 | } |
mkarlsso | 0:8dbd6bd9167f | 1108 | |
mkarlsso | 0:8dbd6bd9167f | 1109 | void intOperation::set(int* intVarInput, const char* cmpString, int* cmpIntVarInput) { |
mkarlsso | 0:8dbd6bd9167f | 1110 | cmpVal = cmpIntVarInput; |
mkarlsso | 0:8dbd6bd9167f | 1111 | intVal =intVarInput; |
mkarlsso | 0:8dbd6bd9167f | 1112 | randHigh = -1; |
mkarlsso | 0:8dbd6bd9167f | 1113 | opPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1114 | cmpValGlobal = true; |
mkarlsso | 0:8dbd6bd9167f | 1115 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1116 | if (strcmp(cmpString, "+") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1117 | executePtr = &intOperation::add; |
mkarlsso | 0:8dbd6bd9167f | 1118 | }else if (strcmp(cmpString, "-") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1119 | executePtr = &intOperation::subtract; |
mkarlsso | 0:8dbd6bd9167f | 1120 | }else if (strcmp(cmpString, "+=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1121 | executePtr = &intOperation::addAndStore; |
mkarlsso | 0:8dbd6bd9167f | 1122 | }else if (strcmp(cmpString, "-=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1123 | executePtr = &intOperation::subtractAndStore; |
mkarlsso | 0:8dbd6bd9167f | 1124 | }else if (strcmp(cmpString, "=") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1125 | executePtr = &intOperation::equals; |
mkarlsso | 0:8dbd6bd9167f | 1126 | } |
mkarlsso | 0:8dbd6bd9167f | 1127 | } |
mkarlsso | 0:8dbd6bd9167f | 1128 | |
mkarlsso | 0:8dbd6bd9167f | 1129 | void intOperation::set(int* intVarInput, intOperation* operationInput) { |
mkarlsso | 0:8dbd6bd9167f | 1130 | |
mkarlsso | 0:8dbd6bd9167f | 1131 | intVal = intVarInput; |
mkarlsso | 0:8dbd6bd9167f | 1132 | cmpVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1133 | randHigh = -1; |
mkarlsso | 0:8dbd6bd9167f | 1134 | opPtr = operationInput; |
mkarlsso | 0:8dbd6bd9167f | 1135 | executePtr = &intOperation::equals; |
mkarlsso | 0:8dbd6bd9167f | 1136 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1137 | |
mkarlsso | 0:8dbd6bd9167f | 1138 | } |
mkarlsso | 0:8dbd6bd9167f | 1139 | |
mkarlsso | 0:8dbd6bd9167f | 1140 | void intOperation::setClockOp(int* intVarInput) { |
mkarlsso | 0:8dbd6bd9167f | 1141 | //used to assign current clock to variable |
mkarlsso | 0:8dbd6bd9167f | 1142 | intVal = intVarInput; |
mkarlsso | 0:8dbd6bd9167f | 1143 | cmpVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1144 | randHigh = -1; |
mkarlsso | 0:8dbd6bd9167f | 1145 | opPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1146 | cmpValGlobal = false; |
mkarlsso | 0:8dbd6bd9167f | 1147 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1148 | isClockAssign = true; |
mkarlsso | 0:8dbd6bd9167f | 1149 | executePtr = &intOperation::equals; |
mkarlsso | 0:8dbd6bd9167f | 1150 | |
mkarlsso | 0:8dbd6bd9167f | 1151 | } |
mkarlsso | 0:8dbd6bd9167f | 1152 | |
mkarlsso | 0:8dbd6bd9167f | 1153 | void intOperation::setClockOp(const char* cmpString, int cmpValInput, bool flip) { |
mkarlsso | 0:8dbd6bd9167f | 1154 | //used to add an integer to the current clock value |
mkarlsso | 0:8dbd6bd9167f | 1155 | |
mkarlsso | 0:8dbd6bd9167f | 1156 | intVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1157 | cmpVal = new int(cmpValInput); |
mkarlsso | 0:8dbd6bd9167f | 1158 | randHigh = -1; |
mkarlsso | 0:8dbd6bd9167f | 1159 | opPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1160 | cmpValGlobal = false; |
mkarlsso | 0:8dbd6bd9167f | 1161 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1162 | isClockAssign = true; |
mkarlsso | 0:8dbd6bd9167f | 1163 | inputsFlipped = flip; |
mkarlsso | 0:8dbd6bd9167f | 1164 | if (strcmp(cmpString, "+") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1165 | executePtr = &intOperation::add; |
mkarlsso | 0:8dbd6bd9167f | 1166 | }else if (strcmp(cmpString, "-") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1167 | executePtr = &intOperation::subtract; |
mkarlsso | 0:8dbd6bd9167f | 1168 | } |
mkarlsso | 0:8dbd6bd9167f | 1169 | } |
mkarlsso | 0:8dbd6bd9167f | 1170 | |
mkarlsso | 0:8dbd6bd9167f | 1171 | void intOperation::setClockOp(const char* cmpString, int* cmpIntVarInput, bool flip) { |
mkarlsso | 0:8dbd6bd9167f | 1172 | //used to add a variable to the current clock value |
mkarlsso | 0:8dbd6bd9167f | 1173 | |
mkarlsso | 0:8dbd6bd9167f | 1174 | cmpVal = cmpIntVarInput; |
mkarlsso | 0:8dbd6bd9167f | 1175 | intVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1176 | randHigh = -1; |
mkarlsso | 0:8dbd6bd9167f | 1177 | opPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1178 | isClockAssign = true; |
mkarlsso | 0:8dbd6bd9167f | 1179 | cmpValGlobal = true; |
mkarlsso | 0:8dbd6bd9167f | 1180 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1181 | inputsFlipped = flip; |
mkarlsso | 0:8dbd6bd9167f | 1182 | if (strcmp(cmpString, "+") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1183 | executePtr = &intOperation::add; |
mkarlsso | 0:8dbd6bd9167f | 1184 | }else if (strcmp(cmpString, "-") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 1185 | executePtr = &intOperation::subtract; |
mkarlsso | 0:8dbd6bd9167f | 1186 | } |
mkarlsso | 0:8dbd6bd9167f | 1187 | } |
mkarlsso | 0:8dbd6bd9167f | 1188 | |
mkarlsso | 0:8dbd6bd9167f | 1189 | |
mkarlsso | 0:8dbd6bd9167f | 1190 | intOperation::~intOperation() { |
mkarlsso | 0:8dbd6bd9167f | 1191 | if (!cmpValGlobal) delete cmpVal; |
mkarlsso | 0:8dbd6bd9167f | 1192 | delete opPtr; |
mkarlsso | 0:8dbd6bd9167f | 1193 | } |
mkarlsso | 0:8dbd6bd9167f | 1194 | |
mkarlsso | 0:8dbd6bd9167f | 1195 | void intOperation::release() { |
mkarlsso | 0:8dbd6bd9167f | 1196 | if (!cmpValGlobal) delete cmpVal; |
mkarlsso | 0:8dbd6bd9167f | 1197 | if (opPtr != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 1198 | opPtr->release(); |
mkarlsso | 0:8dbd6bd9167f | 1199 | } |
mkarlsso | 0:8dbd6bd9167f | 1200 | randHigh = -1; |
mkarlsso | 0:8dbd6bd9167f | 1201 | cmpVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1202 | intVal = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1203 | opPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1204 | executePtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1205 | isClockAssign = false; |
mkarlsso | 0:8dbd6bd9167f | 1206 | cmpValGlobal = false; |
mkarlsso | 0:8dbd6bd9167f | 1207 | isUsed = false; |
mkarlsso | 0:8dbd6bd9167f | 1208 | } |
mkarlsso | 0:8dbd6bd9167f | 1209 | |
mkarlsso | 0:8dbd6bd9167f | 1210 | |
mkarlsso | 0:8dbd6bd9167f | 1211 | int intOperation::execute() { |
mkarlsso | 0:8dbd6bd9167f | 1212 | |
mkarlsso | 0:8dbd6bd9167f | 1213 | return (this->*executePtr)(); |
mkarlsso | 0:8dbd6bd9167f | 1214 | |
mkarlsso | 0:8dbd6bd9167f | 1215 | |
mkarlsso | 0:8dbd6bd9167f | 1216 | } |
mkarlsso | 0:8dbd6bd9167f | 1217 | |
mkarlsso | 0:8dbd6bd9167f | 1218 | int intOperation::add() { |
mkarlsso | 0:8dbd6bd9167f | 1219 | |
mkarlsso | 0:8dbd6bd9167f | 1220 | if ((intVal != NULL) && (!isClockAssign)) { |
mkarlsso | 0:8dbd6bd9167f | 1221 | return (*intVal + *cmpVal); |
mkarlsso | 0:8dbd6bd9167f | 1222 | } else if ((intVal == NULL) && (isClockAssign)) { |
mkarlsso | 0:8dbd6bd9167f | 1223 | return (timeKeeper + *cmpVal); |
mkarlsso | 0:8dbd6bd9167f | 1224 | } else { |
mkarlsso | 0:8dbd6bd9167f | 1225 | //srand(time(NULL)); |
mkarlsso | 0:8dbd6bd9167f | 1226 | srand(timeKeeper); |
mkarlsso | 0:8dbd6bd9167f | 1227 | return (rand() % (randHigh+1)) + *cmpVal; |
mkarlsso | 0:8dbd6bd9167f | 1228 | //return (port->getState() + *cmpVal); |
mkarlsso | 0:8dbd6bd9167f | 1229 | } |
mkarlsso | 0:8dbd6bd9167f | 1230 | } |
mkarlsso | 0:8dbd6bd9167f | 1231 | |
mkarlsso | 0:8dbd6bd9167f | 1232 | int intOperation::subtract() { |
mkarlsso | 0:8dbd6bd9167f | 1233 | if ((intVal != NULL) && (!isClockAssign)) { |
mkarlsso | 0:8dbd6bd9167f | 1234 | return (*intVal - *cmpVal); |
mkarlsso | 0:8dbd6bd9167f | 1235 | } else if ((intVal == NULL) && (isClockAssign)) { |
mkarlsso | 0:8dbd6bd9167f | 1236 | if (inputsFlipped) { |
mkarlsso | 0:8dbd6bd9167f | 1237 | return (*cmpVal-timeKeeper); |
mkarlsso | 0:8dbd6bd9167f | 1238 | } else { |
mkarlsso | 0:8dbd6bd9167f | 1239 | return (timeKeeper - *cmpVal); |
mkarlsso | 0:8dbd6bd9167f | 1240 | } |
mkarlsso | 0:8dbd6bd9167f | 1241 | } else { |
mkarlsso | 0:8dbd6bd9167f | 1242 | srand(timeKeeper); |
mkarlsso | 0:8dbd6bd9167f | 1243 | if (inputsFlipped) { |
mkarlsso | 0:8dbd6bd9167f | 1244 | return (*cmpVal-(rand() % (randHigh+1))); |
mkarlsso | 0:8dbd6bd9167f | 1245 | } else { |
mkarlsso | 0:8dbd6bd9167f | 1246 | return (rand() % (randHigh+1)) - *cmpVal; |
mkarlsso | 0:8dbd6bd9167f | 1247 | } |
mkarlsso | 0:8dbd6bd9167f | 1248 | //return (port->getState() - *cmpVal); |
mkarlsso | 0:8dbd6bd9167f | 1249 | } |
mkarlsso | 0:8dbd6bd9167f | 1250 | } |
mkarlsso | 0:8dbd6bd9167f | 1251 | |
mkarlsso | 0:8dbd6bd9167f | 1252 | int intOperation::addAndStore() { |
mkarlsso | 0:8dbd6bd9167f | 1253 | if (intVal != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 1254 | *intVal = *intVal + *cmpVal; |
mkarlsso | 0:8dbd6bd9167f | 1255 | return *intVal; |
mkarlsso | 0:8dbd6bd9167f | 1256 | } |
mkarlsso | 0:8dbd6bd9167f | 1257 | else { |
mkarlsso | 0:8dbd6bd9167f | 1258 | |
mkarlsso | 0:8dbd6bd9167f | 1259 | //Doesn't happen |
mkarlsso | 0:8dbd6bd9167f | 1260 | return 0; |
mkarlsso | 0:8dbd6bd9167f | 1261 | //port->setState(port->getState() + *cmpVal); |
mkarlsso | 0:8dbd6bd9167f | 1262 | //return port->getState(); |
mkarlsso | 0:8dbd6bd9167f | 1263 | } |
mkarlsso | 0:8dbd6bd9167f | 1264 | |
mkarlsso | 0:8dbd6bd9167f | 1265 | } |
mkarlsso | 0:8dbd6bd9167f | 1266 | |
mkarlsso | 0:8dbd6bd9167f | 1267 | int intOperation::subtractAndStore() { |
mkarlsso | 0:8dbd6bd9167f | 1268 | if (intVal != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 1269 | *intVal = *intVal - *cmpVal; |
mkarlsso | 0:8dbd6bd9167f | 1270 | return *intVal; |
mkarlsso | 0:8dbd6bd9167f | 1271 | } else { |
mkarlsso | 0:8dbd6bd9167f | 1272 | //doesn't happen |
mkarlsso | 0:8dbd6bd9167f | 1273 | return 0; |
mkarlsso | 0:8dbd6bd9167f | 1274 | //port->setState(port->getState() - *cmpVal); |
mkarlsso | 0:8dbd6bd9167f | 1275 | //return port->getState(); |
mkarlsso | 0:8dbd6bd9167f | 1276 | } |
mkarlsso | 0:8dbd6bd9167f | 1277 | } |
mkarlsso | 0:8dbd6bd9167f | 1278 | |
mkarlsso | 0:8dbd6bd9167f | 1279 | int intOperation::equals() { |
mkarlsso | 0:8dbd6bd9167f | 1280 | if ((intVal != NULL) && (opPtr == NULL) && (!isClockAssign)) { |
mkarlsso | 0:8dbd6bd9167f | 1281 | *intVal = *cmpVal; |
mkarlsso | 0:8dbd6bd9167f | 1282 | return *intVal; |
mkarlsso | 0:8dbd6bd9167f | 1283 | } else if ((intVal != NULL) && (opPtr != NULL)) { |
mkarlsso | 0:8dbd6bd9167f | 1284 | |
mkarlsso | 0:8dbd6bd9167f | 1285 | *intVal = opPtr->execute(); |
mkarlsso | 0:8dbd6bd9167f | 1286 | return *intVal; |
mkarlsso | 0:8dbd6bd9167f | 1287 | } else if ((intVal != NULL) && (opPtr == NULL) && (isClockAssign)) { |
mkarlsso | 0:8dbd6bd9167f | 1288 | *intVal = timeKeeper; //assign the current time to the variable |
mkarlsso | 0:8dbd6bd9167f | 1289 | return *intVal; |
mkarlsso | 0:8dbd6bd9167f | 1290 | } else if ((cmpVal != NULL)&& (!isClockAssign)){ |
mkarlsso | 0:8dbd6bd9167f | 1291 | |
mkarlsso | 0:8dbd6bd9167f | 1292 | srand(timeKeeper+randomSeedCounter); |
mkarlsso | 0:8dbd6bd9167f | 1293 | randomSeedCounter++; //for seeding the next rand call, just in case it happens before the clock advances |
mkarlsso | 0:8dbd6bd9167f | 1294 | *cmpVal = (rand() % (randHigh+1)); //this is how we assign a random number to variable |
mkarlsso | 0:8dbd6bd9167f | 1295 | return *cmpVal; |
mkarlsso | 0:8dbd6bd9167f | 1296 | |
mkarlsso | 0:8dbd6bd9167f | 1297 | } |
mkarlsso | 0:8dbd6bd9167f | 1298 | return -1; |
mkarlsso | 0:8dbd6bd9167f | 1299 | } |
mkarlsso | 0:8dbd6bd9167f | 1300 | |
mkarlsso | 0:8dbd6bd9167f | 1301 | condition::condition() { |
mkarlsso | 0:8dbd6bd9167f | 1302 | intCmp = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1303 | conditionPtrs[0] = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1304 | conditionPtrs[1] = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1305 | isUsed = false; |
mkarlsso | 0:8dbd6bd9167f | 1306 | conditionType = ARITHMATIC_CONDITION; |
mkarlsso | 0:8dbd6bd9167f | 1307 | } |
mkarlsso | 0:8dbd6bd9167f | 1308 | |
mkarlsso | 0:8dbd6bd9167f | 1309 | condition::condition(intCompare* compareInput) { |
mkarlsso | 0:8dbd6bd9167f | 1310 | |
mkarlsso | 0:8dbd6bd9167f | 1311 | intCmp = compareInput; |
mkarlsso | 0:8dbd6bd9167f | 1312 | conditionPtrs[0] = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1313 | conditionPtrs[1] = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1314 | |
mkarlsso | 0:8dbd6bd9167f | 1315 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1316 | conditionType = ARITHMATIC_CONDITION; |
mkarlsso | 0:8dbd6bd9167f | 1317 | |
mkarlsso | 0:8dbd6bd9167f | 1318 | } |
mkarlsso | 0:8dbd6bd9167f | 1319 | |
mkarlsso | 0:8dbd6bd9167f | 1320 | condition::condition(condition* condition1, char condType, condition* condition2) { |
mkarlsso | 0:8dbd6bd9167f | 1321 | intCmp = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1322 | conditionPtrs[0] = condition1; |
mkarlsso | 0:8dbd6bd9167f | 1323 | conditionPtrs[1] = condition2; |
mkarlsso | 0:8dbd6bd9167f | 1324 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1325 | conditionType = condType; |
mkarlsso | 0:8dbd6bd9167f | 1326 | } |
mkarlsso | 0:8dbd6bd9167f | 1327 | |
mkarlsso | 0:8dbd6bd9167f | 1328 | condition::~condition() { |
mkarlsso | 0:8dbd6bd9167f | 1329 | if (intCmp != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 1330 | delete intCmp; |
mkarlsso | 0:8dbd6bd9167f | 1331 | } |
mkarlsso | 0:8dbd6bd9167f | 1332 | } |
mkarlsso | 0:8dbd6bd9167f | 1333 | |
mkarlsso | 0:8dbd6bd9167f | 1334 | void condition::release() { |
mkarlsso | 0:8dbd6bd9167f | 1335 | if (intCmp != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 1336 | intCmp->release(); |
mkarlsso | 0:8dbd6bd9167f | 1337 | intCmp=NULL; |
mkarlsso | 0:8dbd6bd9167f | 1338 | } |
mkarlsso | 0:8dbd6bd9167f | 1339 | if (conditionPtrs[0] != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 1340 | conditionPtrs[0]->release(); |
mkarlsso | 0:8dbd6bd9167f | 1341 | conditionPtrs[1]->release(); |
mkarlsso | 0:8dbd6bd9167f | 1342 | conditionPtrs[0]=NULL; |
mkarlsso | 0:8dbd6bd9167f | 1343 | conditionPtrs[1]=NULL; |
mkarlsso | 0:8dbd6bd9167f | 1344 | } |
mkarlsso | 0:8dbd6bd9167f | 1345 | isUsed = false; |
mkarlsso | 0:8dbd6bd9167f | 1346 | } |
mkarlsso | 0:8dbd6bd9167f | 1347 | |
mkarlsso | 0:8dbd6bd9167f | 1348 | void condition::set(intCompare* compareInput) { |
mkarlsso | 0:8dbd6bd9167f | 1349 | release(); |
mkarlsso | 0:8dbd6bd9167f | 1350 | intCmp = compareInput; |
mkarlsso | 0:8dbd6bd9167f | 1351 | conditionPtrs[0] = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1352 | conditionPtrs[1] = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1353 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1354 | conditionType = ARITHMATIC_CONDITION; |
mkarlsso | 0:8dbd6bd9167f | 1355 | } |
mkarlsso | 0:8dbd6bd9167f | 1356 | |
mkarlsso | 0:8dbd6bd9167f | 1357 | void condition::set(condition* condition1, char condType, condition* condition2) { |
mkarlsso | 0:8dbd6bd9167f | 1358 | release(); |
mkarlsso | 0:8dbd6bd9167f | 1359 | intCmp = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1360 | conditionPtrs[0] = condition1; |
mkarlsso | 0:8dbd6bd9167f | 1361 | conditionPtrs[1] = condition2; |
mkarlsso | 0:8dbd6bd9167f | 1362 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1363 | conditionType = condType; |
mkarlsso | 0:8dbd6bd9167f | 1364 | } |
mkarlsso | 0:8dbd6bd9167f | 1365 | |
mkarlsso | 0:8dbd6bd9167f | 1366 | bool condition::isTrue() { |
mkarlsso | 0:8dbd6bd9167f | 1367 | |
mkarlsso | 0:8dbd6bd9167f | 1368 | |
mkarlsso | 0:8dbd6bd9167f | 1369 | bool result = true; |
mkarlsso | 0:8dbd6bd9167f | 1370 | if (conditionType == ARITHMATIC_CONDITION) { |
mkarlsso | 0:8dbd6bd9167f | 1371 | |
mkarlsso | 0:8dbd6bd9167f | 1372 | result = (intCmp->isTrue)(); |
mkarlsso | 0:8dbd6bd9167f | 1373 | } else if (conditionType == AND_CONDITION) { |
mkarlsso | 0:8dbd6bd9167f | 1374 | |
mkarlsso | 0:8dbd6bd9167f | 1375 | result = conditionPtrs[0]->isTrue() && conditionPtrs[1]->isTrue(); |
mkarlsso | 0:8dbd6bd9167f | 1376 | } else if (conditionType == OR_CONDITION) { |
mkarlsso | 0:8dbd6bd9167f | 1377 | |
mkarlsso | 0:8dbd6bd9167f | 1378 | result = conditionPtrs[0]->isTrue() || conditionPtrs[1]->isTrue(); |
mkarlsso | 0:8dbd6bd9167f | 1379 | } |
mkarlsso | 0:8dbd6bd9167f | 1380 | return result; |
mkarlsso | 0:8dbd6bd9167f | 1381 | |
mkarlsso | 0:8dbd6bd9167f | 1382 | } |
mkarlsso | 0:8dbd6bd9167f | 1383 | |
mkarlsso | 0:8dbd6bd9167f | 1384 | portMessage::portMessage(): |
mkarlsso | 0:8dbd6bd9167f | 1385 | whichToSet(0), |
mkarlsso | 0:8dbd6bd9167f | 1386 | value(0), |
mkarlsso | 0:8dbd6bd9167f | 1387 | port(NULL) { |
mkarlsso | 0:8dbd6bd9167f | 1388 | isUsed = false; |
mkarlsso | 0:8dbd6bd9167f | 1389 | } |
mkarlsso | 0:8dbd6bd9167f | 1390 | |
mkarlsso | 0:8dbd6bd9167f | 1391 | void portMessage::release() { |
mkarlsso | 0:8dbd6bd9167f | 1392 | |
mkarlsso | 0:8dbd6bd9167f | 1393 | whichToSet = 0; |
mkarlsso | 0:8dbd6bd9167f | 1394 | value = 0; |
mkarlsso | 0:8dbd6bd9167f | 1395 | port = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1396 | isUsed = false; |
mkarlsso | 0:8dbd6bd9167f | 1397 | } |
mkarlsso | 0:8dbd6bd9167f | 1398 | |
mkarlsso | 0:8dbd6bd9167f | 1399 | /* |
mkarlsso | 0:8dbd6bd9167f | 1400 | portMessage::portMessage(digitalPort* portIn, int whichToSetIn, int valueIn): |
mkarlsso | 0:8dbd6bd9167f | 1401 | whichToSet(whichToSetIn), |
mkarlsso | 0:8dbd6bd9167f | 1402 | value(valueIn), |
mkarlsso | 0:8dbd6bd9167f | 1403 | port(portIn) { |
mkarlsso | 0:8dbd6bd9167f | 1404 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1405 | } |
mkarlsso | 0:8dbd6bd9167f | 1406 | |
mkarlsso | 0:8dbd6bd9167f | 1407 | void portMessage::setMessage(digitalPort* portIn, int whichToSetIn, int valueIn) { |
mkarlsso | 0:8dbd6bd9167f | 1408 | whichToSet = whichToSetIn; |
mkarlsso | 0:8dbd6bd9167f | 1409 | value = valueIn; |
mkarlsso | 0:8dbd6bd9167f | 1410 | port = portIn; |
mkarlsso | 0:8dbd6bd9167f | 1411 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1412 | }*/ |
mkarlsso | 0:8dbd6bd9167f | 1413 | |
mkarlsso | 0:8dbd6bd9167f | 1414 | /* |
mkarlsso | 0:8dbd6bd9167f | 1415 | portMessage::portMessage(int* portIn, int whichToSetIn, int valueIn): |
mkarlsso | 0:8dbd6bd9167f | 1416 | whichToSet(whichToSetIn), |
mkarlsso | 0:8dbd6bd9167f | 1417 | value(valueIn), |
mkarlsso | 0:8dbd6bd9167f | 1418 | port(portIn) { |
mkarlsso | 0:8dbd6bd9167f | 1419 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1420 | }*/ |
mkarlsso | 0:8dbd6bd9167f | 1421 | |
mkarlsso | 0:8dbd6bd9167f | 1422 | void portMessage::setMessage(int* portIn, int whichToSetIn, int valueIn, digitalPort* portVectorIn) { |
mkarlsso | 0:8dbd6bd9167f | 1423 | whichToSet = whichToSetIn; |
mkarlsso | 0:8dbd6bd9167f | 1424 | value = valueIn; |
mkarlsso | 0:8dbd6bd9167f | 1425 | port = portIn; |
mkarlsso | 0:8dbd6bd9167f | 1426 | portVector = portVectorIn; |
mkarlsso | 0:8dbd6bd9167f | 1427 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1428 | } |
mkarlsso | 0:8dbd6bd9167f | 1429 | |
mkarlsso | 0:8dbd6bd9167f | 1430 | void portMessage::execute() { |
mkarlsso | 0:8dbd6bd9167f | 1431 | |
mkarlsso | 0:8dbd6bd9167f | 1432 | if (port != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 1433 | if ((*port > 0) && (*port <= NUMPORTS)) { |
mkarlsso | 0:8dbd6bd9167f | 1434 | portVector[*port-1].setDigitalOut(value); |
mkarlsso | 0:8dbd6bd9167f | 1435 | } else { |
mkarlsso | 0:8dbd6bd9167f | 1436 | textDisplay << "Error: port index assigned by variable does not exist.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 1437 | } |
mkarlsso | 0:8dbd6bd9167f | 1438 | } else { |
mkarlsso | 0:8dbd6bd9167f | 1439 | portVector[whichToSet-1].setDigitalOut(value); |
mkarlsso | 0:8dbd6bd9167f | 1440 | } |
mkarlsso | 0:8dbd6bd9167f | 1441 | |
mkarlsso | 0:8dbd6bd9167f | 1442 | } |
mkarlsso | 0:8dbd6bd9167f | 1443 | |
mkarlsso | 0:8dbd6bd9167f | 1444 | action::action(): |
mkarlsso | 0:8dbd6bd9167f | 1445 | actionType(0) { |
mkarlsso | 0:8dbd6bd9167f | 1446 | op = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1447 | message = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1448 | eventToCreate = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1449 | displayActionPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1450 | //eventDelay = 0; |
mkarlsso | 0:8dbd6bd9167f | 1451 | sound = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1452 | triggerFunc = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1453 | sysCommand = -1; |
mkarlsso | 0:8dbd6bd9167f | 1454 | isUsed = false; |
mkarlsso | 0:8dbd6bd9167f | 1455 | |
mkarlsso | 0:8dbd6bd9167f | 1456 | } |
mkarlsso | 0:8dbd6bd9167f | 1457 | |
mkarlsso | 0:8dbd6bd9167f | 1458 | action::~action() { |
mkarlsso | 0:8dbd6bd9167f | 1459 | if (eventToCreate != NULL) delete eventToCreate; |
mkarlsso | 0:8dbd6bd9167f | 1460 | if (op != NULL) delete op; |
mkarlsso | 0:8dbd6bd9167f | 1461 | if (message != NULL) delete message; |
mkarlsso | 0:8dbd6bd9167f | 1462 | delete displayActionPtr; |
mkarlsso | 0:8dbd6bd9167f | 1463 | delete sound; |
mkarlsso | 0:8dbd6bd9167f | 1464 | } |
mkarlsso | 0:8dbd6bd9167f | 1465 | |
mkarlsso | 0:8dbd6bd9167f | 1466 | void action::release() { |
mkarlsso | 0:8dbd6bd9167f | 1467 | if (eventToCreate != NULL) eventToCreate->release(); |
mkarlsso | 0:8dbd6bd9167f | 1468 | if (op != NULL) op->release(); |
mkarlsso | 0:8dbd6bd9167f | 1469 | if (message != NULL) message->release(); |
mkarlsso | 0:8dbd6bd9167f | 1470 | if (displayActionPtr != NULL) displayActionPtr->release(); |
mkarlsso | 0:8dbd6bd9167f | 1471 | if (triggerFunc != NULL) triggerFunc->release(); |
mkarlsso | 0:8dbd6bd9167f | 1472 | delete sound; //still need to make a static soundControl array |
mkarlsso | 0:8dbd6bd9167f | 1473 | |
mkarlsso | 0:8dbd6bd9167f | 1474 | actionType = 0; |
mkarlsso | 0:8dbd6bd9167f | 1475 | op = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1476 | message = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1477 | eventToCreate = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1478 | displayActionPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1479 | //eventDelay = 0; |
mkarlsso | 0:8dbd6bd9167f | 1480 | sound = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1481 | triggerFunc = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1482 | sysCommand = -1; |
mkarlsso | 0:8dbd6bd9167f | 1483 | isUsed = false; |
mkarlsso | 0:8dbd6bd9167f | 1484 | } |
mkarlsso | 0:8dbd6bd9167f | 1485 | |
mkarlsso | 0:8dbd6bd9167f | 1486 | action::action(intOperation* opInput): |
mkarlsso | 0:8dbd6bd9167f | 1487 | actionType(1) { |
mkarlsso | 0:8dbd6bd9167f | 1488 | op = opInput; |
mkarlsso | 0:8dbd6bd9167f | 1489 | message = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1490 | eventToCreate = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1491 | displayActionPtr= NULL; |
mkarlsso | 0:8dbd6bd9167f | 1492 | //eventDelay = 0; |
mkarlsso | 0:8dbd6bd9167f | 1493 | sound = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1494 | triggerFunc = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1495 | sysCommand = -1; |
mkarlsso | 0:8dbd6bd9167f | 1496 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1497 | } |
mkarlsso | 0:8dbd6bd9167f | 1498 | |
mkarlsso | 0:8dbd6bd9167f | 1499 | action::action(portMessage* messageInput): |
mkarlsso | 0:8dbd6bd9167f | 1500 | actionType(2) { |
mkarlsso | 0:8dbd6bd9167f | 1501 | op = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1502 | eventToCreate = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1503 | message = messageInput; |
mkarlsso | 0:8dbd6bd9167f | 1504 | displayActionPtr= NULL; |
mkarlsso | 0:8dbd6bd9167f | 1505 | //eventDelay = 0; |
mkarlsso | 0:8dbd6bd9167f | 1506 | sound = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1507 | triggerFunc = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1508 | sysCommand = -1; |
mkarlsso | 0:8dbd6bd9167f | 1509 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1510 | |
mkarlsso | 0:8dbd6bd9167f | 1511 | } |
mkarlsso | 0:8dbd6bd9167f | 1512 | |
mkarlsso | 0:8dbd6bd9167f | 1513 | action::action(event* eventInput): |
mkarlsso | 0:8dbd6bd9167f | 1514 | actionType(3) { |
mkarlsso | 0:8dbd6bd9167f | 1515 | op = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1516 | message = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1517 | eventToCreate = eventInput; |
mkarlsso | 0:8dbd6bd9167f | 1518 | displayActionPtr= NULL; |
mkarlsso | 0:8dbd6bd9167f | 1519 | sound = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1520 | triggerFunc = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1521 | |
mkarlsso | 0:8dbd6bd9167f | 1522 | //eventDelay = eventInput->timeLag; |
mkarlsso | 0:8dbd6bd9167f | 1523 | |
mkarlsso | 0:8dbd6bd9167f | 1524 | |
mkarlsso | 0:8dbd6bd9167f | 1525 | sysCommand = -1; |
mkarlsso | 0:8dbd6bd9167f | 1526 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1527 | } |
mkarlsso | 0:8dbd6bd9167f | 1528 | |
mkarlsso | 0:8dbd6bd9167f | 1529 | /* |
mkarlsso | 0:8dbd6bd9167f | 1530 | action::action(event* eventInput, uint32_t delay): |
mkarlsso | 0:8dbd6bd9167f | 1531 | actionType(3) { |
mkarlsso | 0:8dbd6bd9167f | 1532 | op = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1533 | message = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1534 | eventToCreate = eventInput; |
mkarlsso | 0:8dbd6bd9167f | 1535 | displayActionPtr= NULL; |
mkarlsso | 0:8dbd6bd9167f | 1536 | sound = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1537 | eventDelay = delay; |
mkarlsso | 0:8dbd6bd9167f | 1538 | sysCommand = -1; |
mkarlsso | 0:8dbd6bd9167f | 1539 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1540 | |
mkarlsso | 0:8dbd6bd9167f | 1541 | }*/ |
mkarlsso | 0:8dbd6bd9167f | 1542 | |
mkarlsso | 0:8dbd6bd9167f | 1543 | |
mkarlsso | 0:8dbd6bd9167f | 1544 | |
mkarlsso | 0:8dbd6bd9167f | 1545 | action::action(displayAction* displayInput): |
mkarlsso | 0:8dbd6bd9167f | 1546 | actionType(4) { |
mkarlsso | 0:8dbd6bd9167f | 1547 | op = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1548 | message = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1549 | eventToCreate = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1550 | sound = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1551 | triggerFunc = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1552 | displayActionPtr = displayInput; |
mkarlsso | 0:8dbd6bd9167f | 1553 | //eventDelay = 0; |
mkarlsso | 0:8dbd6bd9167f | 1554 | sysCommand = -1; |
mkarlsso | 0:8dbd6bd9167f | 1555 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1556 | } |
mkarlsso | 0:8dbd6bd9167f | 1557 | |
mkarlsso | 0:8dbd6bd9167f | 1558 | action::action(sSound* soundInput): |
mkarlsso | 0:8dbd6bd9167f | 1559 | actionType(5) { |
mkarlsso | 0:8dbd6bd9167f | 1560 | op = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1561 | message = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1562 | eventToCreate = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1563 | sound = soundInput; |
mkarlsso | 0:8dbd6bd9167f | 1564 | triggerFunc = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1565 | displayActionPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1566 | //eventDelay = 0; |
mkarlsso | 0:8dbd6bd9167f | 1567 | sysCommand = -1; |
mkarlsso | 0:8dbd6bd9167f | 1568 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1569 | } |
mkarlsso | 0:8dbd6bd9167f | 1570 | |
mkarlsso | 0:8dbd6bd9167f | 1571 | action::action(triggerFunctionAction* triggerFuncInput): |
mkarlsso | 0:8dbd6bd9167f | 1572 | actionType(7) { |
mkarlsso | 0:8dbd6bd9167f | 1573 | op = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1574 | message = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1575 | eventToCreate = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1576 | sound = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1577 | triggerFunc = triggerFuncInput; |
mkarlsso | 0:8dbd6bd9167f | 1578 | displayActionPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1579 | //eventDelay = 0; |
mkarlsso | 0:8dbd6bd9167f | 1580 | sysCommand = -1; |
mkarlsso | 0:8dbd6bd9167f | 1581 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1582 | } |
mkarlsso | 0:8dbd6bd9167f | 1583 | |
mkarlsso | 0:8dbd6bd9167f | 1584 | action::action(int8_t sysCommandInput): |
mkarlsso | 0:8dbd6bd9167f | 1585 | actionType(6) { |
mkarlsso | 0:8dbd6bd9167f | 1586 | op = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1587 | message = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1588 | eventToCreate = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1589 | sound = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1590 | displayActionPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1591 | //eventDelay = 0; |
mkarlsso | 0:8dbd6bd9167f | 1592 | sysCommand = sysCommandInput; |
mkarlsso | 0:8dbd6bd9167f | 1593 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1594 | } |
mkarlsso | 0:8dbd6bd9167f | 1595 | |
mkarlsso | 0:8dbd6bd9167f | 1596 | void action::set(intOperation* opInput) { |
mkarlsso | 0:8dbd6bd9167f | 1597 | actionType = 1; |
mkarlsso | 0:8dbd6bd9167f | 1598 | op = opInput; |
mkarlsso | 0:8dbd6bd9167f | 1599 | //eventDelay = 0; |
mkarlsso | 0:8dbd6bd9167f | 1600 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1601 | |
mkarlsso | 0:8dbd6bd9167f | 1602 | } |
mkarlsso | 0:8dbd6bd9167f | 1603 | |
mkarlsso | 0:8dbd6bd9167f | 1604 | void action::set(portMessage* messageInput) { |
mkarlsso | 0:8dbd6bd9167f | 1605 | actionType = 2; |
mkarlsso | 0:8dbd6bd9167f | 1606 | message = messageInput; |
mkarlsso | 0:8dbd6bd9167f | 1607 | //eventDelay = 0; |
mkarlsso | 0:8dbd6bd9167f | 1608 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1609 | |
mkarlsso | 0:8dbd6bd9167f | 1610 | } |
mkarlsso | 0:8dbd6bd9167f | 1611 | |
mkarlsso | 0:8dbd6bd9167f | 1612 | void action::set(event* eventInput) { |
mkarlsso | 0:8dbd6bd9167f | 1613 | actionType = 3; |
mkarlsso | 0:8dbd6bd9167f | 1614 | eventToCreate = eventInput; |
mkarlsso | 0:8dbd6bd9167f | 1615 | //eventDelay = eventInput->timeLag; |
mkarlsso | 0:8dbd6bd9167f | 1616 | |
mkarlsso | 0:8dbd6bd9167f | 1617 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1618 | |
mkarlsso | 0:8dbd6bd9167f | 1619 | } |
mkarlsso | 0:8dbd6bd9167f | 1620 | |
mkarlsso | 0:8dbd6bd9167f | 1621 | /* |
mkarlsso | 0:8dbd6bd9167f | 1622 | void action::set(event* eventInput, uint32_t delay) { |
mkarlsso | 0:8dbd6bd9167f | 1623 | actionType = 3; |
mkarlsso | 0:8dbd6bd9167f | 1624 | eventToCreate = eventInput; |
mkarlsso | 0:8dbd6bd9167f | 1625 | eventDelay = delay; |
mkarlsso | 0:8dbd6bd9167f | 1626 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1627 | |
mkarlsso | 0:8dbd6bd9167f | 1628 | }*/ |
mkarlsso | 0:8dbd6bd9167f | 1629 | |
mkarlsso | 0:8dbd6bd9167f | 1630 | |
mkarlsso | 0:8dbd6bd9167f | 1631 | |
mkarlsso | 0:8dbd6bd9167f | 1632 | void action::set(displayAction* displayInput) { |
mkarlsso | 0:8dbd6bd9167f | 1633 | actionType = 4; |
mkarlsso | 0:8dbd6bd9167f | 1634 | displayActionPtr = displayInput; |
mkarlsso | 0:8dbd6bd9167f | 1635 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1636 | } |
mkarlsso | 0:8dbd6bd9167f | 1637 | |
mkarlsso | 0:8dbd6bd9167f | 1638 | void action::set(sSound* soundInput) { |
mkarlsso | 0:8dbd6bd9167f | 1639 | actionType = 5; |
mkarlsso | 0:8dbd6bd9167f | 1640 | sound = soundInput; |
mkarlsso | 0:8dbd6bd9167f | 1641 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1642 | } |
mkarlsso | 0:8dbd6bd9167f | 1643 | |
mkarlsso | 0:8dbd6bd9167f | 1644 | void action::set(triggerFunctionAction* triggerFuncInput) { |
mkarlsso | 0:8dbd6bd9167f | 1645 | |
mkarlsso | 0:8dbd6bd9167f | 1646 | actionType = 7; |
mkarlsso | 0:8dbd6bd9167f | 1647 | triggerFunc = triggerFuncInput; |
mkarlsso | 0:8dbd6bd9167f | 1648 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1649 | } |
mkarlsso | 0:8dbd6bd9167f | 1650 | |
mkarlsso | 0:8dbd6bd9167f | 1651 | void action::set(int8_t sysCommandInput) { |
mkarlsso | 0:8dbd6bd9167f | 1652 | actionType = 6; |
mkarlsso | 0:8dbd6bd9167f | 1653 | sysCommand = sysCommandInput; |
mkarlsso | 0:8dbd6bd9167f | 1654 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1655 | } |
mkarlsso | 0:8dbd6bd9167f | 1656 | |
mkarlsso | 0:8dbd6bd9167f | 1657 | void action::execute() { |
mkarlsso | 0:8dbd6bd9167f | 1658 | |
mkarlsso | 0:8dbd6bd9167f | 1659 | if (actionType == 1) { |
mkarlsso | 0:8dbd6bd9167f | 1660 | op->execute(); |
mkarlsso | 0:8dbd6bd9167f | 1661 | } else if (actionType == 2) { |
mkarlsso | 0:8dbd6bd9167f | 1662 | message->execute(); |
mkarlsso | 0:8dbd6bd9167f | 1663 | } else if (actionType == 3) { |
mkarlsso | 0:8dbd6bd9167f | 1664 | this->execute(timeKeeper); //route to the other overloaded method |
mkarlsso | 0:8dbd6bd9167f | 1665 | } else if (actionType == 4) { |
mkarlsso | 0:8dbd6bd9167f | 1666 | displayActionPtr->execute(); //send text via serial |
mkarlsso | 0:8dbd6bd9167f | 1667 | } else if (actionType == 5) { |
mkarlsso | 0:8dbd6bd9167f | 1668 | sound->execute(); //operate sound device |
mkarlsso | 0:8dbd6bd9167f | 1669 | } else if (actionType == 6) { |
mkarlsso | 0:8dbd6bd9167f | 1670 | switch(sysCommand) { |
mkarlsso | 0:8dbd6bd9167f | 1671 | case 0: |
mkarlsso | 0:8dbd6bd9167f | 1672 | mainQueue.eraseQueue(); |
mkarlsso | 0:8dbd6bd9167f | 1673 | break; |
mkarlsso | 0:8dbd6bd9167f | 1674 | case 1: |
mkarlsso | 0:8dbd6bd9167f | 1675 | textStreaming = true; |
mkarlsso | 0:8dbd6bd9167f | 1676 | break; |
mkarlsso | 0:8dbd6bd9167f | 1677 | case 2: |
mkarlsso | 0:8dbd6bd9167f | 1678 | textStreaming = false; |
mkarlsso | 0:8dbd6bd9167f | 1679 | break; |
mkarlsso | 0:8dbd6bd9167f | 1680 | case 3: |
mkarlsso | 0:8dbd6bd9167f | 1681 | broadCastStateChanges = true; |
mkarlsso | 0:8dbd6bd9167f | 1682 | break; |
mkarlsso | 0:8dbd6bd9167f | 1683 | case 4: |
mkarlsso | 0:8dbd6bd9167f | 1684 | broadCastStateChanges = false; |
mkarlsso | 0:8dbd6bd9167f | 1685 | break; |
mkarlsso | 0:8dbd6bd9167f | 1686 | } |
mkarlsso | 0:8dbd6bd9167f | 1687 | |
mkarlsso | 0:8dbd6bd9167f | 1688 | } else if (actionType == 7) { |
mkarlsso | 0:8dbd6bd9167f | 1689 | triggerFunc->execute(); //execute function |
mkarlsso | 0:8dbd6bd9167f | 1690 | } |
mkarlsso | 0:8dbd6bd9167f | 1691 | } |
mkarlsso | 0:8dbd6bd9167f | 1692 | |
mkarlsso | 0:8dbd6bd9167f | 1693 | void action::execute(uint32_t blockExecTime) { |
mkarlsso | 0:8dbd6bd9167f | 1694 | |
mkarlsso | 0:8dbd6bd9167f | 1695 | if (actionType == 1) { |
mkarlsso | 0:8dbd6bd9167f | 1696 | op->execute(); |
mkarlsso | 0:8dbd6bd9167f | 1697 | } else if (actionType == 2) { |
mkarlsso | 0:8dbd6bd9167f | 1698 | message->execute(); |
mkarlsso | 0:8dbd6bd9167f | 1699 | } else if (actionType == 3) { //an event block |
mkarlsso | 0:8dbd6bd9167f | 1700 | //Because time will pass from the begining of the block, any defined delays should be updated |
mkarlsso | 0:8dbd6bd9167f | 1701 | |
mkarlsso | 0:8dbd6bd9167f | 1702 | //int newDelay = eventDelay-(*globalTimeKeeperPtr-blockExecTime); |
mkarlsso | 0:8dbd6bd9167f | 1703 | int newDelay; |
mkarlsso | 0:8dbd6bd9167f | 1704 | if (eventToCreate->timeLagIsConstant) { |
mkarlsso | 0:8dbd6bd9167f | 1705 | newDelay = eventToCreate->timeLag - (timeKeeper-blockExecTime); |
mkarlsso | 0:8dbd6bd9167f | 1706 | } else { |
mkarlsso | 0:8dbd6bd9167f | 1707 | newDelay = *eventToCreate->timeLagVar - (timeKeeper-blockExecTime); |
mkarlsso | 0:8dbd6bd9167f | 1708 | } |
mkarlsso | 0:8dbd6bd9167f | 1709 | if (newDelay < 0) {newDelay = 0;} |
mkarlsso | 0:8dbd6bd9167f | 1710 | eventToCreate->addToQueue(newDelay); //add the event to the queue to be executed later |
mkarlsso | 0:8dbd6bd9167f | 1711 | |
mkarlsso | 0:8dbd6bd9167f | 1712 | if (eventToCreate->hasWhileLoop) { //this is a while loop |
mkarlsso | 0:8dbd6bd9167f | 1713 | if (eventToCreate->isConditionTrue()) { |
mkarlsso | 0:8dbd6bd9167f | 1714 | //newDelay = (blockExecTime + eventToCreate->whileLoopPeriod) - *globalTimeKeeperPtr; |
mkarlsso | 0:8dbd6bd9167f | 1715 | int tmpPeriod; |
mkarlsso | 0:8dbd6bd9167f | 1716 | if (eventToCreate->whileLoopPeriodIsConstant) { //constant while loop period |
mkarlsso | 0:8dbd6bd9167f | 1717 | newDelay = (blockExecTime + eventToCreate->whileLoopPeriod); |
mkarlsso | 0:8dbd6bd9167f | 1718 | tmpPeriod = eventToCreate->whileLoopPeriod; |
mkarlsso | 0:8dbd6bd9167f | 1719 | } else { |
mkarlsso | 0:8dbd6bd9167f | 1720 | tmpPeriod = *eventToCreate->whileLoopPeriodVar; |
mkarlsso | 0:8dbd6bd9167f | 1721 | if (tmpPeriod < 0) { |
mkarlsso | 0:8dbd6bd9167f | 1722 | tmpPeriod = 0; |
mkarlsso | 0:8dbd6bd9167f | 1723 | } |
mkarlsso | 0:8dbd6bd9167f | 1724 | newDelay = (blockExecTime + tmpPeriod); |
mkarlsso | 0:8dbd6bd9167f | 1725 | } |
mkarlsso | 0:8dbd6bd9167f | 1726 | while ( (newDelay-timeKeeper < 0) && (eventToCreate->isConditionTrue()) ) { |
mkarlsso | 0:8dbd6bd9167f | 1727 | eventToCreate->execute(); |
mkarlsso | 0:8dbd6bd9167f | 1728 | newDelay = newDelay + tmpPeriod; |
mkarlsso | 0:8dbd6bd9167f | 1729 | |
mkarlsso | 0:8dbd6bd9167f | 1730 | } |
mkarlsso | 0:8dbd6bd9167f | 1731 | newDelay = newDelay-timeKeeper; |
mkarlsso | 0:8dbd6bd9167f | 1732 | if (newDelay > 0) { |
mkarlsso | 0:8dbd6bd9167f | 1733 | eventToCreate->addToQueue(newDelay); |
mkarlsso | 0:8dbd6bd9167f | 1734 | } else { |
mkarlsso | 0:8dbd6bd9167f | 1735 | eventToCreate->addToQueue(1); |
mkarlsso | 0:8dbd6bd9167f | 1736 | } |
mkarlsso | 0:8dbd6bd9167f | 1737 | } else if (eventToCreate->nextElseEventPtr != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 1738 | eventToCreate->nextElseEventPtr->addToQueue(); |
mkarlsso | 0:8dbd6bd9167f | 1739 | |
mkarlsso | 0:8dbd6bd9167f | 1740 | } |
mkarlsso | 0:8dbd6bd9167f | 1741 | } |
mkarlsso | 0:8dbd6bd9167f | 1742 | } else if (actionType == 4) { |
mkarlsso | 0:8dbd6bd9167f | 1743 | displayActionPtr->execute(); //send text via serial |
mkarlsso | 0:8dbd6bd9167f | 1744 | } else if (actionType == 5) { |
mkarlsso | 0:8dbd6bd9167f | 1745 | sound->execute(); //operate sound device |
mkarlsso | 0:8dbd6bd9167f | 1746 | } else if (actionType == 6) { |
mkarlsso | 0:8dbd6bd9167f | 1747 | switch(sysCommand) { |
mkarlsso | 0:8dbd6bd9167f | 1748 | case 0: |
mkarlsso | 0:8dbd6bd9167f | 1749 | mainQueue.eraseQueue(); |
mkarlsso | 0:8dbd6bd9167f | 1750 | break; |
mkarlsso | 0:8dbd6bd9167f | 1751 | case 1: |
mkarlsso | 0:8dbd6bd9167f | 1752 | textStreaming = true; |
mkarlsso | 0:8dbd6bd9167f | 1753 | break; |
mkarlsso | 0:8dbd6bd9167f | 1754 | case 2: |
mkarlsso | 0:8dbd6bd9167f | 1755 | textStreaming = false; |
mkarlsso | 0:8dbd6bd9167f | 1756 | break; |
mkarlsso | 0:8dbd6bd9167f | 1757 | case 3: |
mkarlsso | 0:8dbd6bd9167f | 1758 | broadCastStateChanges = true; |
mkarlsso | 0:8dbd6bd9167f | 1759 | break; |
mkarlsso | 0:8dbd6bd9167f | 1760 | case 4: |
mkarlsso | 0:8dbd6bd9167f | 1761 | broadCastStateChanges = false; |
mkarlsso | 0:8dbd6bd9167f | 1762 | break; |
mkarlsso | 0:8dbd6bd9167f | 1763 | } |
mkarlsso | 0:8dbd6bd9167f | 1764 | } else if (actionType == 7) { |
mkarlsso | 0:8dbd6bd9167f | 1765 | |
mkarlsso | 0:8dbd6bd9167f | 1766 | textDisplay.flush(); |
mkarlsso | 0:8dbd6bd9167f | 1767 | triggerFunc->execute(); //operate sound device |
mkarlsso | 0:8dbd6bd9167f | 1768 | } |
mkarlsso | 0:8dbd6bd9167f | 1769 | } |
mkarlsso | 0:8dbd6bd9167f | 1770 | |
mkarlsso | 0:8dbd6bd9167f | 1771 | eventQueue::eventQueue() { |
mkarlsso | 0:8dbd6bd9167f | 1772 | |
mkarlsso | 0:8dbd6bd9167f | 1773 | queueItem blankEvent; |
mkarlsso | 0:8dbd6bd9167f | 1774 | blankEvent.timeToExecute = 0; |
mkarlsso | 0:8dbd6bd9167f | 1775 | blankEvent.eventPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1776 | queueSize = 100; |
mkarlsso | 0:8dbd6bd9167f | 1777 | events.resize(queueSize,blankEvent); |
mkarlsso | 0:8dbd6bd9167f | 1778 | |
mkarlsso | 0:8dbd6bd9167f | 1779 | |
mkarlsso | 0:8dbd6bd9167f | 1780 | } |
mkarlsso | 0:8dbd6bd9167f | 1781 | |
mkarlsso | 0:8dbd6bd9167f | 1782 | void eventQueue::addEventToQueue(event* eventInput, uint32_t delay) { |
mkarlsso | 0:8dbd6bd9167f | 1783 | //*updateSlavePtr = false; |
mkarlsso | 0:8dbd6bd9167f | 1784 | uint32_t eventTime = timeKeeper + delay; |
mkarlsso | 0:8dbd6bd9167f | 1785 | //*updateSlavePtr = true; |
mkarlsso | 0:8dbd6bd9167f | 1786 | //std::vector<queueItem>::size_type sz = events.size(); |
mkarlsso | 0:8dbd6bd9167f | 1787 | //Look for the first empty slot in the queue and place the event there. |
mkarlsso | 0:8dbd6bd9167f | 1788 | //This means that the events in the queue are out of order, but |
mkarlsso | 0:8dbd6bd9167f | 1789 | //it prevents us from having to push_pack and pop off all the time. |
mkarlsso | 0:8dbd6bd9167f | 1790 | for (unsigned i = 0; i < queueSize; i++) { |
mkarlsso | 0:8dbd6bd9167f | 1791 | if (events[i].eventPtr == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 1792 | events[i].eventPtr = eventInput; |
mkarlsso | 0:8dbd6bd9167f | 1793 | events[i].timeToExecute = eventTime; |
mkarlsso | 0:8dbd6bd9167f | 1794 | break; |
mkarlsso | 0:8dbd6bd9167f | 1795 | } |
mkarlsso | 0:8dbd6bd9167f | 1796 | } |
mkarlsso | 0:8dbd6bd9167f | 1797 | } |
mkarlsso | 0:8dbd6bd9167f | 1798 | |
mkarlsso | 0:8dbd6bd9167f | 1799 | void eventQueue::eraseQueue() { |
mkarlsso | 0:8dbd6bd9167f | 1800 | //Erase all events in the queue |
mkarlsso | 0:8dbd6bd9167f | 1801 | std::vector<queueItem>::size_type sz = events.size(); |
mkarlsso | 0:8dbd6bd9167f | 1802 | for (unsigned i = 0; i < sz; i++) { |
mkarlsso | 0:8dbd6bd9167f | 1803 | events[i].eventPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1804 | |
mkarlsso | 0:8dbd6bd9167f | 1805 | } |
mkarlsso | 0:8dbd6bd9167f | 1806 | } |
mkarlsso | 0:8dbd6bd9167f | 1807 | |
mkarlsso | 0:8dbd6bd9167f | 1808 | |
mkarlsso | 0:8dbd6bd9167f | 1809 | //check if any of the events in the queue are up for execution |
mkarlsso | 0:8dbd6bd9167f | 1810 | void eventQueue::check(void) { |
mkarlsso | 0:8dbd6bd9167f | 1811 | |
mkarlsso | 0:8dbd6bd9167f | 1812 | //*updateSlavePtr = false; |
mkarlsso | 0:8dbd6bd9167f | 1813 | uint32_t currentTime = timeKeeper; |
mkarlsso | 0:8dbd6bd9167f | 1814 | //*updateSlavePtr = true; |
mkarlsso | 0:8dbd6bd9167f | 1815 | //std::vector<queueItem>::size_type sz = events.size(); |
mkarlsso | 0:8dbd6bd9167f | 1816 | for (unsigned i = 0; i < queueSize; i++) { |
mkarlsso | 0:8dbd6bd9167f | 1817 | if (events[i].eventPtr != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 1818 | if(events[i].timeToExecute <= currentTime) { |
mkarlsso | 0:8dbd6bd9167f | 1819 | if (!events[i].eventPtr->hasWhileLoop) { |
mkarlsso | 0:8dbd6bd9167f | 1820 | //this is not a while loop, so no need to check if the condition is still true |
mkarlsso | 0:8dbd6bd9167f | 1821 | events[i].eventPtr->execute(); |
mkarlsso | 0:8dbd6bd9167f | 1822 | } else if (events[i].eventPtr->isConditionTrue()){ |
mkarlsso | 0:8dbd6bd9167f | 1823 | //The event is part of a while loop, so recheck the condition before executing |
mkarlsso | 0:8dbd6bd9167f | 1824 | events[i].eventPtr->execute(); |
mkarlsso | 0:8dbd6bd9167f | 1825 | //if (events[i].eventPtr->isConditionTrue()) { //is the condition still true? |
mkarlsso | 0:8dbd6bd9167f | 1826 | int nextTime; |
mkarlsso | 0:8dbd6bd9167f | 1827 | int tmpPeriod; |
mkarlsso | 0:8dbd6bd9167f | 1828 | if (events[i].eventPtr->whileLoopPeriodIsConstant) { |
mkarlsso | 0:8dbd6bd9167f | 1829 | nextTime = (events[i].timeToExecute + events[i].eventPtr->whileLoopPeriod); |
mkarlsso | 0:8dbd6bd9167f | 1830 | tmpPeriod = events[i].eventPtr->whileLoopPeriod; |
mkarlsso | 0:8dbd6bd9167f | 1831 | } else { |
mkarlsso | 0:8dbd6bd9167f | 1832 | tmpPeriod = *events[i].eventPtr->whileLoopPeriodVar; |
mkarlsso | 0:8dbd6bd9167f | 1833 | if (tmpPeriod < 0) { |
mkarlsso | 0:8dbd6bd9167f | 1834 | tmpPeriod = 0; |
mkarlsso | 0:8dbd6bd9167f | 1835 | } |
mkarlsso | 0:8dbd6bd9167f | 1836 | nextTime = (events[i].timeToExecute + tmpPeriod); |
mkarlsso | 0:8dbd6bd9167f | 1837 | |
mkarlsso | 0:8dbd6bd9167f | 1838 | } |
mkarlsso | 0:8dbd6bd9167f | 1839 | //Just in case we are not keeping up, execute the event until we have cought up |
mkarlsso | 0:8dbd6bd9167f | 1840 | while ((nextTime-timeKeeper <= 0) && (events[i].eventPtr->isConditionTrue())) { |
mkarlsso | 0:8dbd6bd9167f | 1841 | events[i].eventPtr->execute(); |
mkarlsso | 0:8dbd6bd9167f | 1842 | nextTime = nextTime+tmpPeriod; |
mkarlsso | 0:8dbd6bd9167f | 1843 | |
mkarlsso | 0:8dbd6bd9167f | 1844 | } |
mkarlsso | 0:8dbd6bd9167f | 1845 | nextTime = nextTime - timeKeeper; |
mkarlsso | 0:8dbd6bd9167f | 1846 | if (nextTime > 0) { |
mkarlsso | 0:8dbd6bd9167f | 1847 | //we add the event to the queue (but the condition is rechecked first) |
mkarlsso | 0:8dbd6bd9167f | 1848 | //if the condition is false, the 'then' statement is added to the queue instead |
mkarlsso | 0:8dbd6bd9167f | 1849 | events[i].eventPtr->addToQueue(nextTime); |
mkarlsso | 0:8dbd6bd9167f | 1850 | } else { |
mkarlsso | 0:8dbd6bd9167f | 1851 | //if we are having trouble keeping up, just add the next event in 1 ms |
mkarlsso | 0:8dbd6bd9167f | 1852 | events[i].eventPtr->addToQueue(1); |
mkarlsso | 0:8dbd6bd9167f | 1853 | } |
mkarlsso | 0:8dbd6bd9167f | 1854 | /* |
mkarlsso | 0:8dbd6bd9167f | 1855 | } else { |
mkarlsso | 0:8dbd6bd9167f | 1856 | if (events[i].eventPtr->nextElseEventPtr != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 1857 | events[i].eventPtr->nextElseEventPtr->addToQueue(); |
mkarlsso | 0:8dbd6bd9167f | 1858 | } |
mkarlsso | 0:8dbd6bd9167f | 1859 | }*/ |
mkarlsso | 0:8dbd6bd9167f | 1860 | |
mkarlsso | 0:8dbd6bd9167f | 1861 | } else { |
mkarlsso | 0:8dbd6bd9167f | 1862 | if (events[i].eventPtr->nextElseEventPtr != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 1863 | events[i].eventPtr->nextElseEventPtr->addToQueue(); |
mkarlsso | 0:8dbd6bd9167f | 1864 | } |
mkarlsso | 0:8dbd6bd9167f | 1865 | } |
mkarlsso | 0:8dbd6bd9167f | 1866 | events[i].eventPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1867 | } |
mkarlsso | 0:8dbd6bd9167f | 1868 | } |
mkarlsso | 0:8dbd6bd9167f | 1869 | } |
mkarlsso | 0:8dbd6bd9167f | 1870 | } |
mkarlsso | 0:8dbd6bd9167f | 1871 | |
mkarlsso | 0:8dbd6bd9167f | 1872 | |
mkarlsso | 0:8dbd6bd9167f | 1873 | event::event(): |
mkarlsso | 0:8dbd6bd9167f | 1874 | timeLag(0), |
mkarlsso | 0:8dbd6bd9167f | 1875 | queuePtr(&mainQueue) { |
mkarlsso | 0:8dbd6bd9167f | 1876 | |
mkarlsso | 0:8dbd6bd9167f | 1877 | nextElseEventPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1878 | conditionToCheck = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1879 | blockType = 0; |
mkarlsso | 0:8dbd6bd9167f | 1880 | whileLoopPeriod = 0; |
mkarlsso | 0:8dbd6bd9167f | 1881 | numConditions = 0; |
mkarlsso | 0:8dbd6bd9167f | 1882 | numActions = 0; |
mkarlsso | 0:8dbd6bd9167f | 1883 | isUsed = false; |
mkarlsso | 0:8dbd6bd9167f | 1884 | timeLagVar = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1885 | timeLagIsConstant = true; |
mkarlsso | 0:8dbd6bd9167f | 1886 | whileLoopPeriodIsConstant = true; |
mkarlsso | 0:8dbd6bd9167f | 1887 | hasWhileLoop = false; |
mkarlsso | 0:8dbd6bd9167f | 1888 | whileLoopPeriodVar = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1889 | |
mkarlsso | 0:8dbd6bd9167f | 1890 | } |
mkarlsso | 0:8dbd6bd9167f | 1891 | |
mkarlsso | 0:8dbd6bd9167f | 1892 | event::event(eventQueue* queueInput): |
mkarlsso | 0:8dbd6bd9167f | 1893 | timeLag(0), |
mkarlsso | 0:8dbd6bd9167f | 1894 | queuePtr(&mainQueue) { |
mkarlsso | 0:8dbd6bd9167f | 1895 | |
mkarlsso | 0:8dbd6bd9167f | 1896 | nextElseEventPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1897 | conditionToCheck = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1898 | blockType = 0; |
mkarlsso | 0:8dbd6bd9167f | 1899 | whileLoopPeriod = 0; |
mkarlsso | 0:8dbd6bd9167f | 1900 | numConditions = 0; |
mkarlsso | 0:8dbd6bd9167f | 1901 | numActions = 0; |
mkarlsso | 0:8dbd6bd9167f | 1902 | isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 1903 | timeLagVar = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1904 | timeLagIsConstant = true; |
mkarlsso | 0:8dbd6bd9167f | 1905 | whileLoopPeriodIsConstant = true; |
mkarlsso | 0:8dbd6bd9167f | 1906 | hasWhileLoop = false; |
mkarlsso | 0:8dbd6bd9167f | 1907 | whileLoopPeriodVar = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1908 | |
mkarlsso | 0:8dbd6bd9167f | 1909 | } |
mkarlsso | 0:8dbd6bd9167f | 1910 | |
mkarlsso | 0:8dbd6bd9167f | 1911 | event::~event() { |
mkarlsso | 0:8dbd6bd9167f | 1912 | /* |
mkarlsso | 0:8dbd6bd9167f | 1913 | while (!conditionArray.empty()) |
mkarlsso | 0:8dbd6bd9167f | 1914 | { |
mkarlsso | 0:8dbd6bd9167f | 1915 | delete conditionArray.back(); |
mkarlsso | 0:8dbd6bd9167f | 1916 | conditionArray.pop_back(); |
mkarlsso | 0:8dbd6bd9167f | 1917 | } |
mkarlsso | 0:8dbd6bd9167f | 1918 | |
mkarlsso | 0:8dbd6bd9167f | 1919 | while (!actionArray.empty()) |
mkarlsso | 0:8dbd6bd9167f | 1920 | { |
mkarlsso | 0:8dbd6bd9167f | 1921 | delete actionArray.back(); |
mkarlsso | 0:8dbd6bd9167f | 1922 | actionArray.pop_back(); |
mkarlsso | 0:8dbd6bd9167f | 1923 | } |
mkarlsso | 0:8dbd6bd9167f | 1924 | |
mkarlsso | 0:8dbd6bd9167f | 1925 | delete nextElseEventPtr; |
mkarlsso | 0:8dbd6bd9167f | 1926 | */ |
mkarlsso | 0:8dbd6bd9167f | 1927 | |
mkarlsso | 0:8dbd6bd9167f | 1928 | } |
mkarlsso | 0:8dbd6bd9167f | 1929 | |
mkarlsso | 0:8dbd6bd9167f | 1930 | void event::release() { |
mkarlsso | 0:8dbd6bd9167f | 1931 | |
mkarlsso | 0:8dbd6bd9167f | 1932 | for (int i = 0; i < numActions; i++) { |
mkarlsso | 0:8dbd6bd9167f | 1933 | actionArray[i]->release(); |
mkarlsso | 0:8dbd6bd9167f | 1934 | } |
mkarlsso | 0:8dbd6bd9167f | 1935 | |
mkarlsso | 0:8dbd6bd9167f | 1936 | if (conditionToCheck != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 1937 | conditionToCheck->release(); |
mkarlsso | 0:8dbd6bd9167f | 1938 | conditionToCheck = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1939 | } |
mkarlsso | 0:8dbd6bd9167f | 1940 | |
mkarlsso | 0:8dbd6bd9167f | 1941 | if (nextElseEventPtr != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 1942 | nextElseEventPtr->release(); |
mkarlsso | 0:8dbd6bd9167f | 1943 | } |
mkarlsso | 0:8dbd6bd9167f | 1944 | timeLag = 0; |
mkarlsso | 0:8dbd6bd9167f | 1945 | nextElseEventPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1946 | blockType = 0; |
mkarlsso | 0:8dbd6bd9167f | 1947 | whileLoopPeriod = 0; |
mkarlsso | 0:8dbd6bd9167f | 1948 | numConditions = 0; |
mkarlsso | 0:8dbd6bd9167f | 1949 | numActions = 0; |
mkarlsso | 0:8dbd6bd9167f | 1950 | isUsed = false; |
mkarlsso | 0:8dbd6bd9167f | 1951 | timeLagVar = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1952 | timeLagIsConstant = true; |
mkarlsso | 0:8dbd6bd9167f | 1953 | whileLoopPeriodIsConstant = true; |
mkarlsso | 0:8dbd6bd9167f | 1954 | hasWhileLoop = false; |
mkarlsso | 0:8dbd6bd9167f | 1955 | whileLoopPeriodVar = NULL; |
mkarlsso | 0:8dbd6bd9167f | 1956 | } |
mkarlsso | 0:8dbd6bd9167f | 1957 | |
mkarlsso | 0:8dbd6bd9167f | 1958 | void event::setTimeLag(uint32_t timeLagInput) { |
mkarlsso | 0:8dbd6bd9167f | 1959 | timeLag = timeLagInput; |
mkarlsso | 0:8dbd6bd9167f | 1960 | timeLagIsConstant = true; |
mkarlsso | 0:8dbd6bd9167f | 1961 | } |
mkarlsso | 0:8dbd6bd9167f | 1962 | |
mkarlsso | 0:8dbd6bd9167f | 1963 | void event::setTimeLag(int* timeLagInput) { |
mkarlsso | 0:8dbd6bd9167f | 1964 | timeLagVar = timeLagInput; |
mkarlsso | 0:8dbd6bd9167f | 1965 | timeLagIsConstant = false; //time lag is not defined by a constant |
mkarlsso | 0:8dbd6bd9167f | 1966 | } |
mkarlsso | 0:8dbd6bd9167f | 1967 | |
mkarlsso | 0:8dbd6bd9167f | 1968 | void event::setWhileLoopPeriod(uint32_t period) { |
mkarlsso | 0:8dbd6bd9167f | 1969 | whileLoopPeriodIsConstant = true; |
mkarlsso | 0:8dbd6bd9167f | 1970 | hasWhileLoop = true; |
mkarlsso | 0:8dbd6bd9167f | 1971 | whileLoopPeriod = period; |
mkarlsso | 0:8dbd6bd9167f | 1972 | |
mkarlsso | 0:8dbd6bd9167f | 1973 | } |
mkarlsso | 0:8dbd6bd9167f | 1974 | |
mkarlsso | 0:8dbd6bd9167f | 1975 | void event::setWhileLoopPeriod(int* period) { |
mkarlsso | 0:8dbd6bd9167f | 1976 | whileLoopPeriodIsConstant = false; |
mkarlsso | 0:8dbd6bd9167f | 1977 | hasWhileLoop = true; |
mkarlsso | 0:8dbd6bd9167f | 1978 | whileLoopPeriodVar = period; |
mkarlsso | 0:8dbd6bd9167f | 1979 | |
mkarlsso | 0:8dbd6bd9167f | 1980 | } |
mkarlsso | 0:8dbd6bd9167f | 1981 | |
mkarlsso | 0:8dbd6bd9167f | 1982 | void event::addCondition(condition* conditionInput) { |
mkarlsso | 0:8dbd6bd9167f | 1983 | if (conditionToCheck != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 1984 | conditionToCheck->release(); |
mkarlsso | 0:8dbd6bd9167f | 1985 | } |
mkarlsso | 0:8dbd6bd9167f | 1986 | conditionToCheck = conditionInput; |
mkarlsso | 0:8dbd6bd9167f | 1987 | |
mkarlsso | 0:8dbd6bd9167f | 1988 | //conditionArray.push_back(conditionInput); |
mkarlsso | 0:8dbd6bd9167f | 1989 | } |
mkarlsso | 0:8dbd6bd9167f | 1990 | |
mkarlsso | 0:8dbd6bd9167f | 1991 | void event::addAction(action* actionInput) { |
mkarlsso | 0:8dbd6bd9167f | 1992 | actionArray[numActions] = actionInput; |
mkarlsso | 0:8dbd6bd9167f | 1993 | numActions++; |
mkarlsso | 0:8dbd6bd9167f | 1994 | //actionArray.push_back(actionInput); |
mkarlsso | 0:8dbd6bd9167f | 1995 | } |
mkarlsso | 0:8dbd6bd9167f | 1996 | |
mkarlsso | 0:8dbd6bd9167f | 1997 | bool event::isConditionTrue(void) { |
mkarlsso | 0:8dbd6bd9167f | 1998 | //if statement (can be left empty, which is interpreted as 'true') |
mkarlsso | 0:8dbd6bd9167f | 1999 | bool result = true; |
mkarlsso | 0:8dbd6bd9167f | 2000 | |
mkarlsso | 0:8dbd6bd9167f | 2001 | if ((conditionToCheck!=NULL)&&(!conditionToCheck->isTrue())) { |
mkarlsso | 0:8dbd6bd9167f | 2002 | result = false; |
mkarlsso | 0:8dbd6bd9167f | 2003 | } |
mkarlsso | 0:8dbd6bd9167f | 2004 | |
mkarlsso | 0:8dbd6bd9167f | 2005 | return result; |
mkarlsso | 0:8dbd6bd9167f | 2006 | } |
mkarlsso | 0:8dbd6bd9167f | 2007 | |
mkarlsso | 0:8dbd6bd9167f | 2008 | void event::execute(void) { |
mkarlsso | 0:8dbd6bd9167f | 2009 | //called from the event queue. The condition is bypassed because it was already checked |
mkarlsso | 0:8dbd6bd9167f | 2010 | |
mkarlsso | 0:8dbd6bd9167f | 2011 | uint32_t timeAtStartExec = timeKeeper; |
mkarlsso | 0:8dbd6bd9167f | 2012 | for (unsigned i = 0; i < numActions; i++) { |
mkarlsso | 0:8dbd6bd9167f | 2013 | actionArray[i]->execute(timeAtStartExec); |
mkarlsso | 0:8dbd6bd9167f | 2014 | |
mkarlsso | 0:8dbd6bd9167f | 2015 | } |
mkarlsso | 0:8dbd6bd9167f | 2016 | |
mkarlsso | 0:8dbd6bd9167f | 2017 | } |
mkarlsso | 0:8dbd6bd9167f | 2018 | |
mkarlsso | 0:8dbd6bd9167f | 2019 | //Attach an 'else' statement to the event |
mkarlsso | 0:8dbd6bd9167f | 2020 | void event::setNextElseEvent(event* eventInput) { |
mkarlsso | 0:8dbd6bd9167f | 2021 | nextElseEventPtr = eventInput; |
mkarlsso | 0:8dbd6bd9167f | 2022 | } |
mkarlsso | 0:8dbd6bd9167f | 2023 | |
mkarlsso | 0:8dbd6bd9167f | 2024 | |
mkarlsso | 0:8dbd6bd9167f | 2025 | //When we we call addToQueue() the condition is checked. If true, the event is added |
mkarlsso | 0:8dbd6bd9167f | 2026 | //to the queue, otherwise we check if there was an 'else' statement attached to the event. |
mkarlsso | 0:8dbd6bd9167f | 2027 | void event::addToQueue(void) { |
mkarlsso | 0:8dbd6bd9167f | 2028 | if (isConditionTrue()) { |
mkarlsso | 0:8dbd6bd9167f | 2029 | if ((timeLagIsConstant)&&(timeLag == 0)) { |
mkarlsso | 0:8dbd6bd9167f | 2030 | execute(); |
mkarlsso | 0:8dbd6bd9167f | 2031 | |
mkarlsso | 0:8dbd6bd9167f | 2032 | } else if (timeLagIsConstant) { |
mkarlsso | 0:8dbd6bd9167f | 2033 | queuePtr->addEventToQueue(this, this->timeLag); |
mkarlsso | 0:8dbd6bd9167f | 2034 | } else if ((!timeLagIsConstant)&&(*timeLagVar <= 0)) { |
mkarlsso | 0:8dbd6bd9167f | 2035 | execute(); |
mkarlsso | 0:8dbd6bd9167f | 2036 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2037 | queuePtr->addEventToQueue(this, *timeLagVar); |
mkarlsso | 0:8dbd6bd9167f | 2038 | } |
mkarlsso | 0:8dbd6bd9167f | 2039 | } else if ((this->nextElseEventPtr != NULL)&&(whileLoopPeriod == 0)) { |
mkarlsso | 0:8dbd6bd9167f | 2040 | this->nextElseEventPtr->addToQueue(); |
mkarlsso | 0:8dbd6bd9167f | 2041 | } |
mkarlsso | 0:8dbd6bd9167f | 2042 | } |
mkarlsso | 0:8dbd6bd9167f | 2043 | |
mkarlsso | 0:8dbd6bd9167f | 2044 | //We can override the timeLag field and use another delay |
mkarlsso | 0:8dbd6bd9167f | 2045 | void event::addToQueue(uint32_t delay) { |
mkarlsso | 0:8dbd6bd9167f | 2046 | if (this->isConditionTrue()) { |
mkarlsso | 0:8dbd6bd9167f | 2047 | //if ((delay == 0) && (whileLoopPeriod == 0)) { |
mkarlsso | 0:8dbd6bd9167f | 2048 | if ((delay == 0)) { |
mkarlsso | 0:8dbd6bd9167f | 2049 | this->execute(); |
mkarlsso | 0:8dbd6bd9167f | 2050 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2051 | queuePtr->addEventToQueue(this, delay); |
mkarlsso | 0:8dbd6bd9167f | 2052 | } |
mkarlsso | 0:8dbd6bd9167f | 2053 | } else if ((this->nextElseEventPtr != NULL)) { //&&(!hasWhileLoop)) { |
mkarlsso | 0:8dbd6bd9167f | 2054 | this->nextElseEventPtr->addToQueue(); |
mkarlsso | 0:8dbd6bd9167f | 2055 | } |
mkarlsso | 0:8dbd6bd9167f | 2056 | } |
mkarlsso | 0:8dbd6bd9167f | 2057 | |
mkarlsso | 0:8dbd6bd9167f | 2058 | |
mkarlsso | 0:8dbd6bd9167f | 2059 | |
mkarlsso | 0:8dbd6bd9167f | 2060 | functionItem::functionItem(action* actionInput, string tagInput): |
mkarlsso | 0:8dbd6bd9167f | 2061 | tag(tagInput), |
mkarlsso | 0:8dbd6bd9167f | 2062 | actionPtr(actionInput) { |
mkarlsso | 0:8dbd6bd9167f | 2063 | } |
mkarlsso | 0:8dbd6bd9167f | 2064 | |
mkarlsso | 0:8dbd6bd9167f | 2065 | functionItem::~functionItem() { |
mkarlsso | 0:8dbd6bd9167f | 2066 | delete actionPtr; |
mkarlsso | 0:8dbd6bd9167f | 2067 | } |
mkarlsso | 0:8dbd6bd9167f | 2068 | |
mkarlsso | 0:8dbd6bd9167f | 2069 | blockBuffer::blockBuffer() { |
mkarlsso | 0:8dbd6bd9167f | 2070 | bufferWritePos = 0; |
mkarlsso | 0:8dbd6bd9167f | 2071 | bufferReadPos = 0; |
mkarlsso | 0:8dbd6bd9167f | 2072 | _linesAvailable = 0; |
mkarlsso | 0:8dbd6bd9167f | 2073 | |
mkarlsso | 1:3a050d26d4f6 | 2074 | writeLine = 0; |
mkarlsso | 1:3a050d26d4f6 | 2075 | readLine = 0; |
mkarlsso | 1:3a050d26d4f6 | 2076 | for (int i=0; i < 200; i++) { |
mkarlsso | 1:3a050d26d4f6 | 2077 | lines[i] = NULL; |
mkarlsso | 1:3a050d26d4f6 | 2078 | } |
mkarlsso | 1:3a050d26d4f6 | 2079 | |
mkarlsso | 0:8dbd6bd9167f | 2080 | } |
mkarlsso | 0:8dbd6bd9167f | 2081 | |
mkarlsso | 0:8dbd6bd9167f | 2082 | bool blockBuffer::addLine(char *input, int numChars) { |
mkarlsso | 0:8dbd6bd9167f | 2083 | |
mkarlsso | 1:3a050d26d4f6 | 2084 | if (writeLine < 200) { |
mkarlsso | 1:3a050d26d4f6 | 2085 | lines[writeLine] = (char*) malloc (numChars+1); |
mkarlsso | 1:3a050d26d4f6 | 2086 | if (lines[writeLine] == NULL) { |
mkarlsso | 1:3a050d26d4f6 | 2087 | textDisplay << "Could noy allocate memory for line."; |
mkarlsso | 1:3a050d26d4f6 | 2088 | textDisplay.flush(); |
mkarlsso | 1:3a050d26d4f6 | 2089 | return false; |
mkarlsso | 1:3a050d26d4f6 | 2090 | } |
mkarlsso | 1:3a050d26d4f6 | 2091 | strcpy(lines[writeLine],input); |
mkarlsso | 1:3a050d26d4f6 | 2092 | writeLine++; |
mkarlsso | 1:3a050d26d4f6 | 2093 | _linesAvailable++; |
mkarlsso | 1:3a050d26d4f6 | 2094 | } else { |
mkarlsso | 1:3a050d26d4f6 | 2095 | return false; |
mkarlsso | 1:3a050d26d4f6 | 2096 | } |
mkarlsso | 1:3a050d26d4f6 | 2097 | |
mkarlsso | 1:3a050d26d4f6 | 2098 | /* |
mkarlsso | 0:8dbd6bd9167f | 2099 | if (bufferWritePos+numChars >= INPUTCHARBUFFERSIZE) { |
mkarlsso | 0:8dbd6bd9167f | 2100 | return false; |
mkarlsso | 0:8dbd6bd9167f | 2101 | } |
mkarlsso | 0:8dbd6bd9167f | 2102 | for(int i=0;i<numChars;i++) { |
mkarlsso | 0:8dbd6bd9167f | 2103 | charBuffer[bufferWritePos] = input[i]; |
mkarlsso | 0:8dbd6bd9167f | 2104 | bufferWritePos++; |
mkarlsso | 0:8dbd6bd9167f | 2105 | } |
mkarlsso | 0:8dbd6bd9167f | 2106 | _linesAvailable++; |
mkarlsso | 0:8dbd6bd9167f | 2107 | return true; |
mkarlsso | 1:3a050d26d4f6 | 2108 | */ |
mkarlsso | 0:8dbd6bd9167f | 2109 | } |
mkarlsso | 0:8dbd6bd9167f | 2110 | |
mkarlsso | 1:3a050d26d4f6 | 2111 | char* blockBuffer::getNextLine() { |
mkarlsso | 1:3a050d26d4f6 | 2112 | |
mkarlsso | 1:3a050d26d4f6 | 2113 | if (readLine < writeLine) { |
mkarlsso | 1:3a050d26d4f6 | 2114 | |
mkarlsso | 1:3a050d26d4f6 | 2115 | readLine++; |
mkarlsso | 1:3a050d26d4f6 | 2116 | _linesAvailable--; |
mkarlsso | 1:3a050d26d4f6 | 2117 | |
mkarlsso | 1:3a050d26d4f6 | 2118 | return lines[readLine-1]; |
mkarlsso | 1:3a050d26d4f6 | 2119 | } else { |
mkarlsso | 1:3a050d26d4f6 | 2120 | return NULL; |
mkarlsso | 1:3a050d26d4f6 | 2121 | } |
mkarlsso | 1:3a050d26d4f6 | 2122 | |
mkarlsso | 1:3a050d26d4f6 | 2123 | } |
mkarlsso | 1:3a050d26d4f6 | 2124 | |
mkarlsso | 1:3a050d26d4f6 | 2125 | /* |
mkarlsso | 0:8dbd6bd9167f | 2126 | string blockBuffer::getNextLine() { |
mkarlsso | 0:8dbd6bd9167f | 2127 | |
mkarlsso | 0:8dbd6bd9167f | 2128 | string outputLine; |
mkarlsso | 1:3a050d26d4f6 | 2129 | |
mkarlsso | 0:8dbd6bd9167f | 2130 | int endOfLinePos = bufferReadPos; |
mkarlsso | 0:8dbd6bd9167f | 2131 | bool endOfLineFound = false; |
mkarlsso | 0:8dbd6bd9167f | 2132 | |
mkarlsso | 0:8dbd6bd9167f | 2133 | if (_linesAvailable > 0) { |
mkarlsso | 0:8dbd6bd9167f | 2134 | //Find the end of the next line |
mkarlsso | 0:8dbd6bd9167f | 2135 | |
mkarlsso | 0:8dbd6bd9167f | 2136 | while (endOfLinePos < INPUTCHARBUFFERSIZE) { |
mkarlsso | 0:8dbd6bd9167f | 2137 | |
mkarlsso | 0:8dbd6bd9167f | 2138 | if (charBuffer[endOfLinePos] == '\0') { |
mkarlsso | 0:8dbd6bd9167f | 2139 | endOfLineFound = true; |
mkarlsso | 0:8dbd6bd9167f | 2140 | break; |
mkarlsso | 0:8dbd6bd9167f | 2141 | } |
mkarlsso | 0:8dbd6bd9167f | 2142 | endOfLinePos++; |
mkarlsso | 0:8dbd6bd9167f | 2143 | } |
mkarlsso | 0:8dbd6bd9167f | 2144 | |
mkarlsso | 0:8dbd6bd9167f | 2145 | //If the end was found, copy to output string |
mkarlsso | 0:8dbd6bd9167f | 2146 | if (endOfLineFound) { |
mkarlsso | 0:8dbd6bd9167f | 2147 | |
mkarlsso | 0:8dbd6bd9167f | 2148 | outputLine.append(charBuffer+bufferReadPos,endOfLinePos-bufferReadPos); |
mkarlsso | 0:8dbd6bd9167f | 2149 | bufferReadPos = endOfLinePos+1; |
mkarlsso | 0:8dbd6bd9167f | 2150 | _linesAvailable--; |
mkarlsso | 0:8dbd6bd9167f | 2151 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2152 | textDisplay << "Error: No end of line found!"; |
mkarlsso | 0:8dbd6bd9167f | 2153 | textDisplay.flush(); |
mkarlsso | 0:8dbd6bd9167f | 2154 | } |
mkarlsso | 0:8dbd6bd9167f | 2155 | } |
mkarlsso | 0:8dbd6bd9167f | 2156 | if (_linesAvailable == 0) { |
mkarlsso | 0:8dbd6bd9167f | 2157 | //we have read out all of the lines, so reset the buffer for the next block. |
mkarlsso | 0:8dbd6bd9167f | 2158 | resetBuffer(); |
mkarlsso | 0:8dbd6bd9167f | 2159 | } |
mkarlsso | 0:8dbd6bd9167f | 2160 | return outputLine; |
mkarlsso | 0:8dbd6bd9167f | 2161 | |
mkarlsso | 1:3a050d26d4f6 | 2162 | |
mkarlsso | 0:8dbd6bd9167f | 2163 | } |
mkarlsso | 1:3a050d26d4f6 | 2164 | */ |
mkarlsso | 0:8dbd6bd9167f | 2165 | |
mkarlsso | 0:8dbd6bd9167f | 2166 | int16_t blockBuffer::linesAvailable() { |
mkarlsso | 0:8dbd6bd9167f | 2167 | return _linesAvailable; |
mkarlsso | 0:8dbd6bd9167f | 2168 | } |
mkarlsso | 0:8dbd6bd9167f | 2169 | |
mkarlsso | 0:8dbd6bd9167f | 2170 | void blockBuffer::resetBuffer() { |
mkarlsso | 0:8dbd6bd9167f | 2171 | _linesAvailable = 0; |
mkarlsso | 0:8dbd6bd9167f | 2172 | bufferReadPos = 0; |
mkarlsso | 0:8dbd6bd9167f | 2173 | bufferWritePos = 0; |
mkarlsso | 1:3a050d26d4f6 | 2174 | |
mkarlsso | 1:3a050d26d4f6 | 2175 | writeLine = 0; |
mkarlsso | 1:3a050d26d4f6 | 2176 | readLine = 0; |
mkarlsso | 1:3a050d26d4f6 | 2177 | for (int i=0; i< 200; i++) { |
mkarlsso | 1:3a050d26d4f6 | 2178 | //delete [] lines[i]; |
mkarlsso | 1:3a050d26d4f6 | 2179 | free (lines[i]); |
mkarlsso | 1:3a050d26d4f6 | 2180 | lines[i] = NULL; |
mkarlsso | 1:3a050d26d4f6 | 2181 | } |
mkarlsso | 0:8dbd6bd9167f | 2182 | } |
mkarlsso | 0:8dbd6bd9167f | 2183 | |
mkarlsso | 0:8dbd6bd9167f | 2184 | bool blockBuffer::empty() { |
mkarlsso | 0:8dbd6bd9167f | 2185 | return (_linesAvailable == 0); |
mkarlsso | 0:8dbd6bd9167f | 2186 | } |
mkarlsso | 0:8dbd6bd9167f | 2187 | |
mkarlsso | 0:8dbd6bd9167f | 2188 | |
mkarlsso | 0:8dbd6bd9167f | 2189 | scriptStream::scriptStream(digitalPort* portVectorInput, int numPortsInput, eventQueue* queueInput, sSystem *system): |
mkarlsso | 0:8dbd6bd9167f | 2190 | portVector(portVectorInput), |
mkarlsso | 0:8dbd6bd9167f | 2191 | numPorts(numPortsInput), |
mkarlsso | 0:8dbd6bd9167f | 2192 | queuePtr(queueInput), |
mkarlsso | 0:8dbd6bd9167f | 2193 | system(system) { |
mkarlsso | 0:8dbd6bd9167f | 2194 | |
mkarlsso | 0:8dbd6bd9167f | 2195 | currentPort = -1; |
mkarlsso | 0:8dbd6bd9167f | 2196 | currentTriggerPort = -1; |
mkarlsso | 0:8dbd6bd9167f | 2197 | currentTriggerDir = 1; |
mkarlsso | 0:8dbd6bd9167f | 2198 | currentFunction = -1; |
mkarlsso | 0:8dbd6bd9167f | 2199 | |
mkarlsso | 0:8dbd6bd9167f | 2200 | randomSeedCounter = 0; //used for seeding random numbers |
mkarlsso | 0:8dbd6bd9167f | 2201 | |
mkarlsso | 0:8dbd6bd9167f | 2202 | lineError = false; |
mkarlsso | 0:8dbd6bd9167f | 2203 | blockDepth = 0; |
mkarlsso | 0:8dbd6bd9167f | 2204 | ifBlockInit = false; |
mkarlsso | 0:8dbd6bd9167f | 2205 | whileBlockInit = false; |
mkarlsso | 0:8dbd6bd9167f | 2206 | expectingDoStatement = false; |
mkarlsso | 0:8dbd6bd9167f | 2207 | elseFlag = false; |
mkarlsso | 0:8dbd6bd9167f | 2208 | thenFlag = false; |
mkarlsso | 0:8dbd6bd9167f | 2209 | currentDelay = 0; |
mkarlsso | 0:8dbd6bd9167f | 2210 | |
mkarlsso | 0:8dbd6bd9167f | 2211 | for (int i = 0; i < NUMFUNCTIONS; i++) { |
mkarlsso | 0:8dbd6bd9167f | 2212 | functionSpotTaken[i] = false; |
mkarlsso | 0:8dbd6bd9167f | 2213 | functionEventArray[i] = NULL; |
mkarlsso | 0:8dbd6bd9167f | 2214 | } |
mkarlsso | 0:8dbd6bd9167f | 2215 | |
mkarlsso | 0:8dbd6bd9167f | 2216 | } |
mkarlsso | 0:8dbd6bd9167f | 2217 | |
mkarlsso | 0:8dbd6bd9167f | 2218 | |
mkarlsso | 0:8dbd6bd9167f | 2219 | void scriptStream::addLineToCurrentBlock(char* lineInput) { |
mkarlsso | 0:8dbd6bd9167f | 2220 | |
mkarlsso | 0:8dbd6bd9167f | 2221 | bool compile = false; |
mkarlsso | 0:8dbd6bd9167f | 2222 | bool keep = false; |
mkarlsso | 0:8dbd6bd9167f | 2223 | int numCharInLine = 0; |
mkarlsso | 0:8dbd6bd9167f | 2224 | //A line ending with ';' then carriage return initiates the compile sequence |
mkarlsso | 0:8dbd6bd9167f | 2225 | //Otherwise, add the line to the buffer and compile later |
mkarlsso | 0:8dbd6bd9167f | 2226 | for (int i = 0; i < 256; i++) { |
mkarlsso | 0:8dbd6bd9167f | 2227 | numCharInLine++; |
mkarlsso | 0:8dbd6bd9167f | 2228 | if (lineInput[i] == ';') { |
mkarlsso | 0:8dbd6bd9167f | 2229 | compile = true; |
mkarlsso | 0:8dbd6bd9167f | 2230 | } else if (lineInput[i] == ' ') { |
mkarlsso | 0:8dbd6bd9167f | 2231 | continue; |
mkarlsso | 0:8dbd6bd9167f | 2232 | } else if (lineInput[i] == '\0') { |
mkarlsso | 0:8dbd6bd9167f | 2233 | break; |
mkarlsso | 0:8dbd6bd9167f | 2234 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2235 | keep = true; |
mkarlsso | 0:8dbd6bd9167f | 2236 | compile = false; |
mkarlsso | 0:8dbd6bd9167f | 2237 | } |
mkarlsso | 0:8dbd6bd9167f | 2238 | |
mkarlsso | 0:8dbd6bd9167f | 2239 | } |
mkarlsso | 0:8dbd6bd9167f | 2240 | |
mkarlsso | 0:8dbd6bd9167f | 2241 | //if (keep) currentBlock.insert(currentBlock.begin(),string(lineInput)); |
mkarlsso | 0:8dbd6bd9167f | 2242 | if (keep) { |
mkarlsso | 0:8dbd6bd9167f | 2243 | if (!currentBlock.addLine(lineInput,numCharInLine)) { |
mkarlsso | 0:8dbd6bd9167f | 2244 | textDisplay << "Error: script input buffer full. The block is too long.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2245 | currentBlock.resetBuffer(); |
mkarlsso | 0:8dbd6bd9167f | 2246 | compile = false; |
mkarlsso | 0:8dbd6bd9167f | 2247 | } |
mkarlsso | 0:8dbd6bd9167f | 2248 | } |
mkarlsso | 0:8dbd6bd9167f | 2249 | if (compile) { |
mkarlsso | 0:8dbd6bd9167f | 2250 | parseBlock(); |
mkarlsso | 1:3a050d26d4f6 | 2251 | currentBlock.resetBuffer(); |
mkarlsso | 0:8dbd6bd9167f | 2252 | } |
mkarlsso | 0:8dbd6bd9167f | 2253 | |
mkarlsso | 0:8dbd6bd9167f | 2254 | } |
mkarlsso | 0:8dbd6bd9167f | 2255 | |
mkarlsso | 0:8dbd6bd9167f | 2256 | |
mkarlsso | 0:8dbd6bd9167f | 2257 | //SCRIPT PARSING - all script commands are defined here. |
mkarlsso | 0:8dbd6bd9167f | 2258 | //------------------------------------------------------- |
mkarlsso | 0:8dbd6bd9167f | 2259 | void scriptStream::parseBlock() { |
mkarlsso | 0:8dbd6bd9167f | 2260 | |
mkarlsso | 0:8dbd6bd9167f | 2261 | |
mkarlsso | 0:8dbd6bd9167f | 2262 | lineError = false; |
mkarlsso | 0:8dbd6bd9167f | 2263 | blockDepth = 0; |
mkarlsso | 0:8dbd6bd9167f | 2264 | ifBlockInit = false; |
mkarlsso | 0:8dbd6bd9167f | 2265 | whileBlockInit = false; |
mkarlsso | 0:8dbd6bd9167f | 2266 | expectingDoStatement = false; |
mkarlsso | 0:8dbd6bd9167f | 2267 | elseFlag = false; |
mkarlsso | 0:8dbd6bd9167f | 2268 | thenFlag = false; |
mkarlsso | 0:8dbd6bd9167f | 2269 | currentDelay = 0; |
mkarlsso | 0:8dbd6bd9167f | 2270 | |
mkarlsso | 0:8dbd6bd9167f | 2271 | |
mkarlsso | 0:8dbd6bd9167f | 2272 | std::size_t stringInd = 0; |
mkarlsso | 0:8dbd6bd9167f | 2273 | |
mkarlsso | 0:8dbd6bd9167f | 2274 | bool wholeLineEvaluated = false; |
mkarlsso | 0:8dbd6bd9167f | 2275 | |
mkarlsso | 0:8dbd6bd9167f | 2276 | while (!currentBlock.empty()) { |
mkarlsso | 0:8dbd6bd9167f | 2277 | |
mkarlsso | 0:8dbd6bd9167f | 2278 | wholeLineEvaluated = false; |
mkarlsso | 1:3a050d26d4f6 | 2279 | |
mkarlsso | 1:3a050d26d4f6 | 2280 | //tmpLine = currentBlock.getNextLine(); |
mkarlsso | 1:3a050d26d4f6 | 2281 | |
mkarlsso | 1:3a050d26d4f6 | 2282 | tmpLine.assign(currentBlock.getNextLine()); |
mkarlsso | 1:3a050d26d4f6 | 2283 | |
mkarlsso | 0:8dbd6bd9167f | 2284 | |
mkarlsso | 0:8dbd6bd9167f | 2285 | lineError = false; |
mkarlsso | 0:8dbd6bd9167f | 2286 | //remove tabs |
mkarlsso | 0:8dbd6bd9167f | 2287 | std::size_t found = tmpLine.find_first_of(9); //tab |
mkarlsso | 0:8dbd6bd9167f | 2288 | while (found!=std::string::npos) { |
mkarlsso | 0:8dbd6bd9167f | 2289 | tmpLine[found]= ' '; |
mkarlsso | 0:8dbd6bd9167f | 2290 | found=tmpLine.find_first_of(9,found+1); |
mkarlsso | 0:8dbd6bd9167f | 2291 | } |
mkarlsso | 0:8dbd6bd9167f | 2292 | |
mkarlsso | 0:8dbd6bd9167f | 2293 | found = tmpLine.find_first_of(37); //% for commenting |
mkarlsso | 0:8dbd6bd9167f | 2294 | if (found!=std::string::npos) { |
mkarlsso | 0:8dbd6bd9167f | 2295 | for (int p=found; p<tmpLine.size() ;p++) { |
mkarlsso | 0:8dbd6bd9167f | 2296 | tmpLine[p]= ' '; |
mkarlsso | 0:8dbd6bd9167f | 2297 | } |
mkarlsso | 0:8dbd6bd9167f | 2298 | } |
mkarlsso | 0:8dbd6bd9167f | 2299 | |
mkarlsso | 0:8dbd6bd9167f | 2300 | //break up the line into tokens separated by spaces |
mkarlsso | 0:8dbd6bd9167f | 2301 | tokenize(tmpLine,tokens," ;"); |
mkarlsso | 0:8dbd6bd9167f | 2302 | |
mkarlsso | 0:8dbd6bd9167f | 2303 | std::vector<string>::size_type sz = tokens.size(); |
mkarlsso | 0:8dbd6bd9167f | 2304 | |
mkarlsso | 0:8dbd6bd9167f | 2305 | for (unsigned i = 0; i < sz; i++) { |
mkarlsso | 0:8dbd6bd9167f | 2306 | |
mkarlsso | 0:8dbd6bd9167f | 2307 | |
mkarlsso | 0:8dbd6bd9167f | 2308 | |
mkarlsso | 0:8dbd6bd9167f | 2309 | //end statement signals the end of a block----------------------------------------- |
mkarlsso | 0:8dbd6bd9167f | 2310 | if (tokens[i].compare("end") == 0) { //ends the current block |
mkarlsso | 0:8dbd6bd9167f | 2311 | |
mkarlsso | 0:8dbd6bd9167f | 2312 | if (ifBlockInit || whileBlockInit || expectingDoStatement) { |
mkarlsso | 0:8dbd6bd9167f | 2313 | textDisplay << "Error: expected a 'do' statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2314 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2315 | } |
mkarlsso | 0:8dbd6bd9167f | 2316 | |
mkarlsso | 0:8dbd6bd9167f | 2317 | ifBlockInit = false; |
mkarlsso | 0:8dbd6bd9167f | 2318 | whileBlockInit = false; |
mkarlsso | 0:8dbd6bd9167f | 2319 | expectingDoStatement = false; |
mkarlsso | 0:8dbd6bd9167f | 2320 | elseFlag = false; |
mkarlsso | 0:8dbd6bd9167f | 2321 | |
mkarlsso | 0:8dbd6bd9167f | 2322 | if (blockDepth > 0) { |
mkarlsso | 0:8dbd6bd9167f | 2323 | textDisplay.debug("End statement\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 2324 | if (blockDepth == 1) { |
mkarlsso | 0:8dbd6bd9167f | 2325 | |
mkarlsso | 0:8dbd6bd9167f | 2326 | |
mkarlsso | 0:8dbd6bd9167f | 2327 | currentTriggerPort = -1; |
mkarlsso | 0:8dbd6bd9167f | 2328 | currentFunction = -1; |
mkarlsso | 0:8dbd6bd9167f | 2329 | |
mkarlsso | 0:8dbd6bd9167f | 2330 | |
mkarlsso | 0:8dbd6bd9167f | 2331 | |
mkarlsso | 0:8dbd6bd9167f | 2332 | blockDepth = 0; |
mkarlsso | 0:8dbd6bd9167f | 2333 | } else if (blockDepth > 1) { |
mkarlsso | 0:8dbd6bd9167f | 2334 | blockDepth = blockDepth - 1; |
mkarlsso | 0:8dbd6bd9167f | 2335 | } |
mkarlsso | 0:8dbd6bd9167f | 2336 | |
mkarlsso | 0:8dbd6bd9167f | 2337 | while ((tmpEventPtrArray.back()->blockType == 3) || (tmpEventPtrArray.back()->blockType == 4)){ |
mkarlsso | 0:8dbd6bd9167f | 2338 | tmpEventPtrArray.pop_back(); //recursively remove the pointers to all else blocks |
mkarlsso | 0:8dbd6bd9167f | 2339 | } |
mkarlsso | 0:8dbd6bd9167f | 2340 | tmpEventPtrArray.pop_back(); //remove the pointer to the finished block |
mkarlsso | 0:8dbd6bd9167f | 2341 | |
mkarlsso | 0:8dbd6bd9167f | 2342 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2343 | textDisplay << "Error: End statement without block\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2344 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2345 | } |
mkarlsso | 0:8dbd6bd9167f | 2346 | |
mkarlsso | 0:8dbd6bd9167f | 2347 | |
mkarlsso | 0:8dbd6bd9167f | 2348 | |
mkarlsso | 0:8dbd6bd9167f | 2349 | //sound statement used to play wave files------------------------------------------------ |
mkarlsso | 0:8dbd6bd9167f | 2350 | //example: sound('soundfile') |
mkarlsso | 0:8dbd6bd9167f | 2351 | // sound(stop) |
mkarlsso | 0:8dbd6bd9167f | 2352 | } else if (tokens[i].find("sound(") != std::string::npos) { |
mkarlsso | 0:8dbd6bd9167f | 2353 | if (ifBlockInit || whileBlockInit || elseFlag || expectingDoStatement) { |
mkarlsso | 0:8dbd6bd9167f | 2354 | textDisplay << "Error: expected a 'do' statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2355 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2356 | } |
mkarlsso | 0:8dbd6bd9167f | 2357 | wholeLineEvaluated = true; |
mkarlsso | 0:8dbd6bd9167f | 2358 | int pos1 = tmpLine.find("sound(")+6; |
mkarlsso | 0:8dbd6bd9167f | 2359 | int pos2 = tmpLine.find_first_of(")",pos1); |
mkarlsso | 0:8dbd6bd9167f | 2360 | string dispVar = tmpLine.substr(pos1,pos2-pos1); |
mkarlsso | 1:3a050d26d4f6 | 2361 | //int* tmpVar = findIntVariable(dispVar); |
mkarlsso | 1:3a050d26d4f6 | 2362 | int* tmpVar = findIntVariable(tmpLine.data(),pos1,pos2-1); |
mkarlsso | 1:3a050d26d4f6 | 2363 | |
mkarlsso | 0:8dbd6bd9167f | 2364 | bool isText = false; |
mkarlsso | 0:8dbd6bd9167f | 2365 | bool stopSignal = false; |
mkarlsso | 0:8dbd6bd9167f | 2366 | bool resetSignal = false; |
mkarlsso | 0:8dbd6bd9167f | 2367 | if (tmpVar == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 2368 | if ((tmpLine.compare(pos1,1,"'")==0) && (tmpLine.compare(pos2-1,1,"'")==0)) { |
mkarlsso | 0:8dbd6bd9167f | 2369 | isText = true; |
mkarlsso | 0:8dbd6bd9167f | 2370 | } else if (dispVar.compare("stop") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 2371 | stopSignal = true; |
mkarlsso | 0:8dbd6bd9167f | 2372 | } else if (dispVar.compare("reset") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 2373 | resetSignal = true; |
mkarlsso | 0:8dbd6bd9167f | 2374 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2375 | textDisplay << "Error: variable input to sound() does not exist\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2376 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2377 | } |
mkarlsso | 0:8dbd6bd9167f | 2378 | } |
mkarlsso | 0:8dbd6bd9167f | 2379 | action* tmpAction = findFirstUnUsed(actionBlock, NUMACTIONS); |
mkarlsso | 0:8dbd6bd9167f | 2380 | if (tmpAction == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 2381 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2382 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2383 | } |
mkarlsso | 0:8dbd6bd9167f | 2384 | if (!lineError && (blockDepth == 0)) { |
mkarlsso | 0:8dbd6bd9167f | 2385 | //we are not inside a block structure, so play sound now |
mkarlsso | 0:8dbd6bd9167f | 2386 | if (stopSignal) { |
mkarlsso | 0:8dbd6bd9167f | 2387 | sSound* S = system->createNewSoundAction(); |
mkarlsso | 0:8dbd6bd9167f | 2388 | S->setPlayback(false); |
mkarlsso | 0:8dbd6bd9167f | 2389 | S->execute(); |
mkarlsso | 0:8dbd6bd9167f | 2390 | delete S; |
mkarlsso | 0:8dbd6bd9167f | 2391 | } else if (resetSignal) { |
mkarlsso | 0:8dbd6bd9167f | 2392 | sSound* S = system->createNewSoundAction(); |
mkarlsso | 0:8dbd6bd9167f | 2393 | S->setReset(); |
mkarlsso | 0:8dbd6bd9167f | 2394 | S->execute(); |
mkarlsso | 0:8dbd6bd9167f | 2395 | delete S; |
mkarlsso | 0:8dbd6bd9167f | 2396 | } else if (isText) { |
mkarlsso | 0:8dbd6bd9167f | 2397 | |
mkarlsso | 0:8dbd6bd9167f | 2398 | if (pos2-pos1-2 <= 20) { |
mkarlsso | 0:8dbd6bd9167f | 2399 | |
mkarlsso | 0:8dbd6bd9167f | 2400 | sSound* S = system->createNewSoundAction(); |
mkarlsso | 0:8dbd6bd9167f | 2401 | S->setFile(tmpLine.substr(pos1+1,pos2-pos1-2)); |
mkarlsso | 0:8dbd6bd9167f | 2402 | S->execute(); |
mkarlsso | 0:8dbd6bd9167f | 2403 | delete S; |
mkarlsso | 0:8dbd6bd9167f | 2404 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2405 | textDisplay << "Error: sound file names must be 20 characters or less.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2406 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2407 | } |
mkarlsso | 0:8dbd6bd9167f | 2408 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2409 | textDisplay << "Error: variable input to sound() not yet supported. Enter a string in single quotes.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2410 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2411 | } |
mkarlsso | 0:8dbd6bd9167f | 2412 | |
mkarlsso | 0:8dbd6bd9167f | 2413 | } else if (!lineError && (blockDepth > 0) ){ |
mkarlsso | 0:8dbd6bd9167f | 2414 | //the disp function was put inside a block |
mkarlsso | 0:8dbd6bd9167f | 2415 | textDisplay.debug("Sound statement\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 2416 | if (stopSignal) { |
mkarlsso | 0:8dbd6bd9167f | 2417 | sSound* sPtr = system->createNewSoundAction(); |
mkarlsso | 0:8dbd6bd9167f | 2418 | sPtr->setPlayback(false); |
mkarlsso | 0:8dbd6bd9167f | 2419 | //action* tmpAction = new action(sPtr); |
mkarlsso | 0:8dbd6bd9167f | 2420 | tmpAction->set(sPtr); |
mkarlsso | 0:8dbd6bd9167f | 2421 | tmpEventPtrArray.back()->addAction(tmpAction); |
mkarlsso | 0:8dbd6bd9167f | 2422 | } else if (resetSignal) { |
mkarlsso | 0:8dbd6bd9167f | 2423 | sSound* sPtr = system->createNewSoundAction(); |
mkarlsso | 0:8dbd6bd9167f | 2424 | sPtr->setReset(); |
mkarlsso | 0:8dbd6bd9167f | 2425 | //action* tmpAction = new action(sPtr); |
mkarlsso | 0:8dbd6bd9167f | 2426 | tmpAction->set(sPtr); |
mkarlsso | 0:8dbd6bd9167f | 2427 | tmpEventPtrArray.back()->addAction(tmpAction); |
mkarlsso | 0:8dbd6bd9167f | 2428 | } else if (isText) { |
mkarlsso | 0:8dbd6bd9167f | 2429 | |
mkarlsso | 0:8dbd6bd9167f | 2430 | if (pos2-pos1-2 <= 20) { |
mkarlsso | 0:8dbd6bd9167f | 2431 | sSound* sPtr = system->createNewSoundAction(); |
mkarlsso | 0:8dbd6bd9167f | 2432 | sPtr->setFile(tmpLine.substr(pos1+1,pos2-pos1-2)); |
mkarlsso | 0:8dbd6bd9167f | 2433 | //action* tmpAction = new action(sPtr); |
mkarlsso | 0:8dbd6bd9167f | 2434 | tmpAction->set(sPtr); |
mkarlsso | 0:8dbd6bd9167f | 2435 | tmpEventPtrArray.back()->addAction(tmpAction); |
mkarlsso | 0:8dbd6bd9167f | 2436 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2437 | textDisplay << "Error: sound file names must be 20 characters or less.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2438 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2439 | } |
mkarlsso | 0:8dbd6bd9167f | 2440 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2441 | textDisplay << "Error: variable input to sound() not yet supported. Enter a string in single quotes.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2442 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2443 | } |
mkarlsso | 0:8dbd6bd9167f | 2444 | |
mkarlsso | 0:8dbd6bd9167f | 2445 | |
mkarlsso | 0:8dbd6bd9167f | 2446 | } |
mkarlsso | 0:8dbd6bd9167f | 2447 | |
mkarlsso | 0:8dbd6bd9167f | 2448 | } else if (tokens[i].find("volume(") != std::string::npos) { |
mkarlsso | 0:8dbd6bd9167f | 2449 | if (ifBlockInit || whileBlockInit || elseFlag || expectingDoStatement) { |
mkarlsso | 0:8dbd6bd9167f | 2450 | textDisplay << "Error: expected a 'do' statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2451 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2452 | } |
mkarlsso | 0:8dbd6bd9167f | 2453 | wholeLineEvaluated = true; |
mkarlsso | 0:8dbd6bd9167f | 2454 | int pos1 = tmpLine.find("volume(")+7; |
mkarlsso | 0:8dbd6bd9167f | 2455 | int pos2 = tmpLine.find_first_of(")",pos1); |
mkarlsso | 0:8dbd6bd9167f | 2456 | string dispVar = tmpLine.substr(pos1,pos2-pos1); |
mkarlsso | 1:3a050d26d4f6 | 2457 | //int* tmpVar = findIntVariable(dispVar); |
mkarlsso | 1:3a050d26d4f6 | 2458 | int* tmpVar = findIntVariable(tmpLine.data(),pos1,pos2-1); |
mkarlsso | 0:8dbd6bd9167f | 2459 | bool isText = false; |
mkarlsso | 0:8dbd6bd9167f | 2460 | if (tmpVar == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 2461 | if (isNumber(dispVar)) { |
mkarlsso | 0:8dbd6bd9167f | 2462 | isText = true; |
mkarlsso | 0:8dbd6bd9167f | 2463 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2464 | textDisplay << "Error: variable input to volume() does not exist\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2465 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2466 | } |
mkarlsso | 0:8dbd6bd9167f | 2467 | } |
mkarlsso | 0:8dbd6bd9167f | 2468 | action* tmpAction = findFirstUnUsed(actionBlock, NUMACTIONS); |
mkarlsso | 0:8dbd6bd9167f | 2469 | if (tmpAction == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 2470 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2471 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2472 | } |
mkarlsso | 0:8dbd6bd9167f | 2473 | if (!lineError && (blockDepth == 0)) { |
mkarlsso | 0:8dbd6bd9167f | 2474 | //we are not inside a block structure, so play sound now |
mkarlsso | 0:8dbd6bd9167f | 2475 | if (isText) { |
mkarlsso | 0:8dbd6bd9167f | 2476 | int newVolume = atoi(dispVar.data()); |
mkarlsso | 0:8dbd6bd9167f | 2477 | if ((newVolume >=0)&&(newVolume <= 255)) { |
mkarlsso | 0:8dbd6bd9167f | 2478 | sSound* S = system->createNewSoundAction(); |
mkarlsso | 0:8dbd6bd9167f | 2479 | S->setVolume(newVolume); |
mkarlsso | 0:8dbd6bd9167f | 2480 | S->execute(); |
mkarlsso | 0:8dbd6bd9167f | 2481 | delete S; |
mkarlsso | 0:8dbd6bd9167f | 2482 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2483 | textDisplay << "Error: sound volume must be between 0 and 255 .\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2484 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2485 | } |
mkarlsso | 0:8dbd6bd9167f | 2486 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2487 | sSound* S = system->createNewSoundAction(); |
mkarlsso | 0:8dbd6bd9167f | 2488 | S->setVolume(tmpVar); |
mkarlsso | 0:8dbd6bd9167f | 2489 | S->execute(); |
mkarlsso | 0:8dbd6bd9167f | 2490 | delete S; |
mkarlsso | 0:8dbd6bd9167f | 2491 | } |
mkarlsso | 0:8dbd6bd9167f | 2492 | |
mkarlsso | 0:8dbd6bd9167f | 2493 | } else if (!lineError && (blockDepth > 0) ){ |
mkarlsso | 0:8dbd6bd9167f | 2494 | //the disp function was put inside a block |
mkarlsso | 0:8dbd6bd9167f | 2495 | textDisplay.debug("Volume statement\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 2496 | if (isText) { |
mkarlsso | 0:8dbd6bd9167f | 2497 | int newVolume = atoi(dispVar.data()); |
mkarlsso | 0:8dbd6bd9167f | 2498 | |
mkarlsso | 0:8dbd6bd9167f | 2499 | sSound* sPtr = system->createNewSoundAction(); |
mkarlsso | 0:8dbd6bd9167f | 2500 | sPtr->setVolume(newVolume); |
mkarlsso | 0:8dbd6bd9167f | 2501 | |
mkarlsso | 0:8dbd6bd9167f | 2502 | //action* tmpAction = new action(sPtr); |
mkarlsso | 0:8dbd6bd9167f | 2503 | tmpAction->set(sPtr); |
mkarlsso | 0:8dbd6bd9167f | 2504 | tmpEventPtrArray.back()->addAction(tmpAction); |
mkarlsso | 0:8dbd6bd9167f | 2505 | |
mkarlsso | 0:8dbd6bd9167f | 2506 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2507 | sSound* sPtr = system->createNewSoundAction(); |
mkarlsso | 0:8dbd6bd9167f | 2508 | sPtr->setVolume(tmpVar); |
mkarlsso | 0:8dbd6bd9167f | 2509 | //action* tmpAction = new action(sPtr); |
mkarlsso | 0:8dbd6bd9167f | 2510 | tmpAction->set(sPtr); |
mkarlsso | 0:8dbd6bd9167f | 2511 | tmpEventPtrArray.back()->addAction(tmpAction); |
mkarlsso | 0:8dbd6bd9167f | 2512 | } |
mkarlsso | 0:8dbd6bd9167f | 2513 | |
mkarlsso | 0:8dbd6bd9167f | 2514 | |
mkarlsso | 0:8dbd6bd9167f | 2515 | } |
mkarlsso | 0:8dbd6bd9167f | 2516 | //clock statement used to is used to control the clock------------------------- |
mkarlsso | 0:8dbd6bd9167f | 2517 | //example: clock(reset); clock(slave); clock(standalone) |
mkarlsso | 0:8dbd6bd9167f | 2518 | } else if (tokens[i].find("clock(") != std::string::npos) { //clock commands |
mkarlsso | 0:8dbd6bd9167f | 2519 | if (ifBlockInit || whileBlockInit || elseFlag || expectingDoStatement) { |
mkarlsso | 0:8dbd6bd9167f | 2520 | textDisplay << "Error: expected a 'do' statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2521 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2522 | } |
mkarlsso | 0:8dbd6bd9167f | 2523 | if (blockDepth > 0) { |
mkarlsso | 0:8dbd6bd9167f | 2524 | textDisplay << "Error: clock commands only allowed outside of block structure\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2525 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2526 | } |
mkarlsso | 0:8dbd6bd9167f | 2527 | |
mkarlsso | 0:8dbd6bd9167f | 2528 | if (!lineError) { |
mkarlsso | 0:8dbd6bd9167f | 2529 | int pos1 = tmpLine.find("clock(")+6; |
mkarlsso | 0:8dbd6bd9167f | 2530 | int pos2 = tmpLine.find_first_of(")",pos1); |
mkarlsso | 0:8dbd6bd9167f | 2531 | string dispVar = tmpLine.substr(pos1,pos2-pos1); |
mkarlsso | 0:8dbd6bd9167f | 2532 | |
mkarlsso | 0:8dbd6bd9167f | 2533 | |
mkarlsso | 0:8dbd6bd9167f | 2534 | if (blockDepth == 0) { |
mkarlsso | 0:8dbd6bd9167f | 2535 | if (dispVar.compare("reset") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 2536 | resetTimer = true; |
mkarlsso | 0:8dbd6bd9167f | 2537 | queuePtr->eraseQueue(); |
mkarlsso | 0:8dbd6bd9167f | 2538 | textDisplay.send(string("Clock reset to 0\r\n")); |
mkarlsso | 0:8dbd6bd9167f | 2539 | |
mkarlsso | 0:8dbd6bd9167f | 2540 | } else if (dispVar.compare("slave") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 2541 | if (!clockSlave) { |
mkarlsso | 0:8dbd6bd9167f | 2542 | changeToSlave = true; |
mkarlsso | 0:8dbd6bd9167f | 2543 | textDisplay.send(string("Slave mode\r\n")); |
mkarlsso | 0:8dbd6bd9167f | 2544 | |
mkarlsso | 0:8dbd6bd9167f | 2545 | } |
mkarlsso | 0:8dbd6bd9167f | 2546 | } else if (dispVar.compare("standalone") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 2547 | if (clockSlave) { |
mkarlsso | 0:8dbd6bd9167f | 2548 | changeToStandAlone = true; |
mkarlsso | 0:8dbd6bd9167f | 2549 | textDisplay.send(string("Standalone mode\r\n")); |
mkarlsso | 0:8dbd6bd9167f | 2550 | |
mkarlsso | 0:8dbd6bd9167f | 2551 | } |
mkarlsso | 0:8dbd6bd9167f | 2552 | } else if (dispVar.compare("") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 2553 | //The user needs the current time displayed. |
mkarlsso | 0:8dbd6bd9167f | 2554 | |
mkarlsso | 0:8dbd6bd9167f | 2555 | //textDisplay.send(string("Current Clock\r\n")); |
mkarlsso | 0:8dbd6bd9167f | 2556 | textDisplay << timeKeeper << " current time\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2557 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2558 | textDisplay << "Error: Clock control statement not understood\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2559 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2560 | } |
mkarlsso | 0:8dbd6bd9167f | 2561 | } |
mkarlsso | 0:8dbd6bd9167f | 2562 | } |
mkarlsso | 0:8dbd6bd9167f | 2563 | |
mkarlsso | 0:8dbd6bd9167f | 2564 | //disp command used to display text via serial--------------------------------------- |
mkarlsso | 0:8dbd6bd9167f | 2565 | //example: disp('hello'); disp(myVar) |
mkarlsso | 0:8dbd6bd9167f | 2566 | } else if (tokens[i].find("disp(") != std::string::npos) { //display value of variable |
mkarlsso | 0:8dbd6bd9167f | 2567 | |
mkarlsso | 0:8dbd6bd9167f | 2568 | if (ifBlockInit || whileBlockInit || elseFlag || expectingDoStatement) { |
mkarlsso | 0:8dbd6bd9167f | 2569 | textDisplay <<"Error: expected a 'do' statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2570 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2571 | } |
mkarlsso | 0:8dbd6bd9167f | 2572 | |
mkarlsso | 0:8dbd6bd9167f | 2573 | //int pos1 = tokens[i].find("disp(")+5; |
mkarlsso | 0:8dbd6bd9167f | 2574 | //int pos2 = tokens[i].find_first_of(")",pos1); |
mkarlsso | 0:8dbd6bd9167f | 2575 | //string dispVar = tokens[i].substr(pos1,pos2-pos1); |
mkarlsso | 0:8dbd6bd9167f | 2576 | |
mkarlsso | 0:8dbd6bd9167f | 2577 | wholeLineEvaluated = true; |
mkarlsso | 0:8dbd6bd9167f | 2578 | int pos1 = tmpLine.find("disp(")+5; |
mkarlsso | 0:8dbd6bd9167f | 2579 | int pos2 = tmpLine.find_first_of(")",pos1); |
mkarlsso | 0:8dbd6bd9167f | 2580 | if (pos2 == std::string::npos) { |
mkarlsso | 0:8dbd6bd9167f | 2581 | textDisplay <<"Error: expected a ) character\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2582 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2583 | } |
mkarlsso | 1:3a050d26d4f6 | 2584 | |
mkarlsso | 0:8dbd6bd9167f | 2585 | if (!lineError) { |
mkarlsso | 0:8dbd6bd9167f | 2586 | string dispVar = tmpLine.substr(pos1,pos2-pos1); |
mkarlsso | 1:3a050d26d4f6 | 2587 | //int* tmpVar = findIntVariable(dispVar); |
mkarlsso | 1:3a050d26d4f6 | 2588 | int* tmpVar = findIntVariable(tmpLine.data(),pos1,pos2-1); |
mkarlsso | 0:8dbd6bd9167f | 2589 | bool isText = false; |
mkarlsso | 0:8dbd6bd9167f | 2590 | if (tmpVar == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 2591 | if ((tmpLine.compare(pos1,1,"'")==0) && (tmpLine.compare(pos2-1,1,"'")==0)) { |
mkarlsso | 0:8dbd6bd9167f | 2592 | isText = true; |
mkarlsso | 0:8dbd6bd9167f | 2593 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2594 | textDisplay << "Error: variable to display does not exist\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2595 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2596 | } |
mkarlsso | 0:8dbd6bd9167f | 2597 | } |
mkarlsso | 0:8dbd6bd9167f | 2598 | displayAction* dPtr = findFirstUnUsed(displayActionBlock, NUMDISPLAYACTIONS); |
mkarlsso | 0:8dbd6bd9167f | 2599 | if (dPtr == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 2600 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2601 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2602 | } |
mkarlsso | 1:3a050d26d4f6 | 2603 | |
mkarlsso | 0:8dbd6bd9167f | 2604 | if (!lineError && (blockDepth == 0)) { |
mkarlsso | 0:8dbd6bd9167f | 2605 | //we are not inside a block structure, so display now |
mkarlsso | 1:3a050d26d4f6 | 2606 | |
mkarlsso | 0:8dbd6bd9167f | 2607 | if (isText) { |
mkarlsso | 0:8dbd6bd9167f | 2608 | //displayAction* dPtr = new displayAction(tmpLine.substr(pos1+1,pos2-pos1-2), pcPtr); |
mkarlsso | 0:8dbd6bd9167f | 2609 | dPtr->set(tmpLine.substr(pos1+1,pos2-pos1-2)); |
mkarlsso | 0:8dbd6bd9167f | 2610 | dPtr->execute(); |
mkarlsso | 0:8dbd6bd9167f | 2611 | //delete dPtr; |
mkarlsso | 0:8dbd6bd9167f | 2612 | dPtr->release(); |
mkarlsso | 0:8dbd6bd9167f | 2613 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2614 | //displayAction* dPtr = new displayAction(tmpVar, dispVar, pcPtr); |
mkarlsso | 0:8dbd6bd9167f | 2615 | dPtr->set(tmpVar, dispVar); |
mkarlsso | 0:8dbd6bd9167f | 2616 | dPtr->execute(); |
mkarlsso | 0:8dbd6bd9167f | 2617 | //delete dPtr; |
mkarlsso | 0:8dbd6bd9167f | 2618 | dPtr->release(); |
mkarlsso | 0:8dbd6bd9167f | 2619 | } |
mkarlsso | 1:3a050d26d4f6 | 2620 | |
mkarlsso | 0:8dbd6bd9167f | 2621 | } else if (!lineError && (blockDepth > 0) ){ |
mkarlsso | 0:8dbd6bd9167f | 2622 | //the disp function was put inside a block |
mkarlsso | 0:8dbd6bd9167f | 2623 | textDisplay.debug("Display statement\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 2624 | action* tmpAction = findFirstUnUsed(actionBlock, NUMACTIONS); |
mkarlsso | 0:8dbd6bd9167f | 2625 | if (tmpAction == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 2626 | textDisplay <<"Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2627 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2628 | } |
mkarlsso | 0:8dbd6bd9167f | 2629 | if (!lineError && isText) { |
mkarlsso | 0:8dbd6bd9167f | 2630 | //displayAction* dPtr = new displayAction(tmpLine.substr(pos1+1,pos2-pos1-2), pcPtr); |
mkarlsso | 0:8dbd6bd9167f | 2631 | dPtr->set(tmpLine.substr(pos1+1,pos2-pos1-2)); |
mkarlsso | 0:8dbd6bd9167f | 2632 | tmpAction->set(dPtr); |
mkarlsso | 0:8dbd6bd9167f | 2633 | //action* tmpAction = new action(dPtr); |
mkarlsso | 0:8dbd6bd9167f | 2634 | tmpEventPtrArray.back()->addAction(tmpAction); |
mkarlsso | 0:8dbd6bd9167f | 2635 | } else if (!lineError) { |
mkarlsso | 0:8dbd6bd9167f | 2636 | //displayAction* dPtr = new displayAction(tmpVar, dispVar, pcPtr); |
mkarlsso | 0:8dbd6bd9167f | 2637 | dPtr->set(tmpVar, dispVar); |
mkarlsso | 0:8dbd6bd9167f | 2638 | tmpAction->set(dPtr); |
mkarlsso | 0:8dbd6bd9167f | 2639 | //action* tmpAction = new action(dPtr); |
mkarlsso | 0:8dbd6bd9167f | 2640 | tmpEventPtrArray.back()->addAction(tmpAction); |
mkarlsso | 0:8dbd6bd9167f | 2641 | } |
mkarlsso | 1:3a050d26d4f6 | 2642 | |
mkarlsso | 1:3a050d26d4f6 | 2643 | |
mkarlsso | 0:8dbd6bd9167f | 2644 | } |
mkarlsso | 0:8dbd6bd9167f | 2645 | } |
mkarlsso | 0:8dbd6bd9167f | 2646 | //---------------------------------------------- |
mkarlsso | 0:8dbd6bd9167f | 2647 | //The trigger command is used like this: |
mkarlsso | 0:8dbd6bd9167f | 2648 | //trigger(n) |
mkarlsso | 0:8dbd6bd9167f | 2649 | //Where n is an integer corresponding to a "function n" block |
mkarlsso | 0:8dbd6bd9167f | 2650 | //When "trigger" is called, the corresponding function is executed. |
mkarlsso | 0:8dbd6bd9167f | 2651 | } else if (tokens[i].find("trigger(") != std::string::npos) { //trigger a function |
mkarlsso | 0:8dbd6bd9167f | 2652 | |
mkarlsso | 0:8dbd6bd9167f | 2653 | if (ifBlockInit || whileBlockInit || elseFlag || expectingDoStatement) { |
mkarlsso | 0:8dbd6bd9167f | 2654 | textDisplay << "Error: expected a 'do' statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2655 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2656 | } |
mkarlsso | 0:8dbd6bd9167f | 2657 | |
mkarlsso | 0:8dbd6bd9167f | 2658 | |
mkarlsso | 0:8dbd6bd9167f | 2659 | wholeLineEvaluated = true; |
mkarlsso | 0:8dbd6bd9167f | 2660 | int pos1 = tmpLine.find("trigger(")+8; |
mkarlsso | 0:8dbd6bd9167f | 2661 | int pos2 = tmpLine.find_first_of(")",pos1); |
mkarlsso | 0:8dbd6bd9167f | 2662 | int funcNum = atoi(tmpLine.substr(pos1,pos2-pos1).data()); |
mkarlsso | 0:8dbd6bd9167f | 2663 | if ((funcNum > 0) && (funcNum < NUMFUNCTIONS+1)) { |
mkarlsso | 0:8dbd6bd9167f | 2664 | if (functionSpotTaken[funcNum-1]) { |
mkarlsso | 0:8dbd6bd9167f | 2665 | |
mkarlsso | 0:8dbd6bd9167f | 2666 | |
mkarlsso | 0:8dbd6bd9167f | 2667 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2668 | textDisplay << "Error: function number does not exist\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2669 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2670 | } |
mkarlsso | 0:8dbd6bd9167f | 2671 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2672 | textDisplay << "Error: not a valid function number\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2673 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2674 | } |
mkarlsso | 0:8dbd6bd9167f | 2675 | |
mkarlsso | 0:8dbd6bd9167f | 2676 | funcNum--; //change to 0-based index |
mkarlsso | 0:8dbd6bd9167f | 2677 | if (!lineError && (blockDepth == 0)) { |
mkarlsso | 0:8dbd6bd9167f | 2678 | //we are not inside a block structure, so execute function now |
mkarlsso | 0:8dbd6bd9167f | 2679 | //textDisplay << "Exectuting function"; |
mkarlsso | 0:8dbd6bd9167f | 2680 | //textDisplay.flush(); |
mkarlsso | 0:8dbd6bd9167f | 2681 | |
mkarlsso | 0:8dbd6bd9167f | 2682 | functionEventArray[funcNum]->execute(); |
mkarlsso | 0:8dbd6bd9167f | 2683 | |
mkarlsso | 0:8dbd6bd9167f | 2684 | } else if (!lineError && (blockDepth > 0) ){ |
mkarlsso | 0:8dbd6bd9167f | 2685 | //the trigger function was put inside a block, so we need to create a new action |
mkarlsso | 0:8dbd6bd9167f | 2686 | textDisplay.debug("Trigger statement\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 2687 | triggerFunctionAction* tPtr = findFirstUnUsed(triggerFunctionActionBlock, NUMTRIGGERACTIONS); |
mkarlsso | 0:8dbd6bd9167f | 2688 | if (tPtr == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 2689 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2690 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2691 | } |
mkarlsso | 0:8dbd6bd9167f | 2692 | |
mkarlsso | 0:8dbd6bd9167f | 2693 | if (!lineError) { |
mkarlsso | 0:8dbd6bd9167f | 2694 | //we only give provide it the function number, instead |
mkarlsso | 0:8dbd6bd9167f | 2695 | //of a pointer to the event. That way, if the user modifies |
mkarlsso | 0:8dbd6bd9167f | 2696 | //the function (which would change the pointer), all callbacks |
mkarlsso | 0:8dbd6bd9167f | 2697 | //still using that function number will use the new function. |
mkarlsso | 0:8dbd6bd9167f | 2698 | tPtr->set(funcNum); |
mkarlsso | 0:8dbd6bd9167f | 2699 | action* tmpAction = findFirstUnUsed(actionBlock, NUMACTIONS); |
mkarlsso | 0:8dbd6bd9167f | 2700 | if (tmpAction == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 2701 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2702 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2703 | } |
mkarlsso | 0:8dbd6bd9167f | 2704 | if (!lineError) { |
mkarlsso | 0:8dbd6bd9167f | 2705 | |
mkarlsso | 0:8dbd6bd9167f | 2706 | tmpAction->set(tPtr); |
mkarlsso | 0:8dbd6bd9167f | 2707 | tmpEventPtrArray.back()->addAction(tmpAction); |
mkarlsso | 0:8dbd6bd9167f | 2708 | } |
mkarlsso | 0:8dbd6bd9167f | 2709 | } |
mkarlsso | 0:8dbd6bd9167f | 2710 | |
mkarlsso | 0:8dbd6bd9167f | 2711 | |
mkarlsso | 0:8dbd6bd9167f | 2712 | } |
mkarlsso | 0:8dbd6bd9167f | 2713 | |
mkarlsso | 0:8dbd6bd9167f | 2714 | |
mkarlsso | 0:8dbd6bd9167f | 2715 | |
mkarlsso | 0:8dbd6bd9167f | 2716 | |
mkarlsso | 0:8dbd6bd9167f | 2717 | //int is used to decalar new variables. Only allowed outside of callbacks------------------- |
mkarlsso | 0:8dbd6bd9167f | 2718 | //example: int a; int b = 9 |
mkarlsso | 0:8dbd6bd9167f | 2719 | } else if (tokens[i].compare("int") == 0) { //define a new integer variable |
mkarlsso | 0:8dbd6bd9167f | 2720 | textDisplay.debug("Int statement\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 2721 | if (ifBlockInit || whileBlockInit || expectingDoStatement) { |
mkarlsso | 0:8dbd6bd9167f | 2722 | textDisplay << "Error: expected a 'do' statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2723 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2724 | } |
mkarlsso | 0:8dbd6bd9167f | 2725 | tmpString = ""; |
mkarlsso | 0:8dbd6bd9167f | 2726 | wholeLineEvaluated = true; |
mkarlsso | 0:8dbd6bd9167f | 2727 | int spacesBeforeEqualSign = 0; |
mkarlsso | 0:8dbd6bd9167f | 2728 | bool countSpaces = true; |
mkarlsso | 0:8dbd6bd9167f | 2729 | //combine the tokens without whitespaces |
mkarlsso | 0:8dbd6bd9167f | 2730 | for (unsigned j = i+1; j < sz; j++) { |
mkarlsso | 0:8dbd6bd9167f | 2731 | tmpString.append(tokens[j]); |
mkarlsso | 0:8dbd6bd9167f | 2732 | if (tokens[j].find_first_of("=") != std::string::npos) { |
mkarlsso | 0:8dbd6bd9167f | 2733 | if (tokens[j].find_first_of("=") > 0) spacesBeforeEqualSign++; |
mkarlsso | 0:8dbd6bd9167f | 2734 | countSpaces = false; |
mkarlsso | 0:8dbd6bd9167f | 2735 | } else if (countSpaces) { |
mkarlsso | 0:8dbd6bd9167f | 2736 | spacesBeforeEqualSign++; |
mkarlsso | 0:8dbd6bd9167f | 2737 | } |
mkarlsso | 0:8dbd6bd9167f | 2738 | } |
mkarlsso | 0:8dbd6bd9167f | 2739 | |
mkarlsso | 0:8dbd6bd9167f | 2740 | if (blockDepth > 0) { |
mkarlsso | 0:8dbd6bd9167f | 2741 | textDisplay << "Error: Variables can only be first declared outside of callbacks.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2742 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2743 | } |
mkarlsso | 0:8dbd6bd9167f | 2744 | |
mkarlsso | 0:8dbd6bd9167f | 2745 | if ((!lineError) && (spacesBeforeEqualSign > 1)) { |
mkarlsso | 0:8dbd6bd9167f | 2746 | textDisplay << "Error: Variable can't have a space in it.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2747 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2748 | } |
mkarlsso | 0:8dbd6bd9167f | 2749 | stringInd = tmpString.find_first_of("="); |
mkarlsso | 0:8dbd6bd9167f | 2750 | |
mkarlsso | 0:8dbd6bd9167f | 2751 | bool variableCreated = false; |
mkarlsso | 0:8dbd6bd9167f | 2752 | if (!lineError) { |
mkarlsso | 0:8dbd6bd9167f | 2753 | if (((stringInd == std::string::npos) && (sz == 2)) || (stringInd != std::string::npos)) { |
mkarlsso | 0:8dbd6bd9167f | 2754 | |
mkarlsso | 0:8dbd6bd9167f | 2755 | if ((stringInd != std::string::npos) && (stringInd > MAXVARNAMESIZE)) { |
mkarlsso | 0:8dbd6bd9167f | 2756 | textDisplay << "Error: variable names must be under 30 characters.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2757 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2758 | } else if (createIntVariable(tmpString.substr(0,stringInd))) { |
mkarlsso | 0:8dbd6bd9167f | 2759 | textDisplay.debug("Created new variable\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 2760 | variableCreated = true; |
mkarlsso | 0:8dbd6bd9167f | 2761 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2762 | textDisplay.debug("Attempting to use existing variable\r\n"); |
mkarlsso | 1:3a050d26d4f6 | 2763 | //int* tmpVar = findIntVariable(tmpString.substr(0,stringInd)); |
mkarlsso | 1:3a050d26d4f6 | 2764 | int* tmpVar = findIntVariable(tmpString.data(),0,stringInd-1); |
mkarlsso | 1:3a050d26d4f6 | 2765 | |
mkarlsso | 0:8dbd6bd9167f | 2766 | *tmpVar = 0; |
mkarlsso | 0:8dbd6bd9167f | 2767 | //lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2768 | } |
mkarlsso | 0:8dbd6bd9167f | 2769 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2770 | textDisplay << "Error: variable declaration not understood.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2771 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2772 | } |
mkarlsso | 0:8dbd6bd9167f | 2773 | } |
mkarlsso | 1:3a050d26d4f6 | 2774 | |
mkarlsso | 0:8dbd6bd9167f | 2775 | if ((!lineError) && (stringInd != std::string::npos)) { //evaluate the expression |
mkarlsso | 0:8dbd6bd9167f | 2776 | //action* tmpAction = evaluateAssignmentForAction(tmpString); |
mkarlsso | 0:8dbd6bd9167f | 2777 | action* tmpAction = evaluateAssignmentForAction(tmpString.data()); |
mkarlsso | 0:8dbd6bd9167f | 2778 | if (tmpAction != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 2779 | tmpAction->execute(); |
mkarlsso | 0:8dbd6bd9167f | 2780 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 2781 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 2782 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2783 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2784 | if (variableCreated) { |
mkarlsso | 0:8dbd6bd9167f | 2785 | delete globalVariables.back(); |
mkarlsso | 0:8dbd6bd9167f | 2786 | globalVariables.pop_back(); |
mkarlsso | 0:8dbd6bd9167f | 2787 | } |
mkarlsso | 0:8dbd6bd9167f | 2788 | } |
mkarlsso | 0:8dbd6bd9167f | 2789 | } |
mkarlsso | 0:8dbd6bd9167f | 2790 | |
mkarlsso | 0:8dbd6bd9167f | 2791 | //serial command is used to toggle whether or not to buffer up output text---------------- |
mkarlsso | 0:8dbd6bd9167f | 2792 | //examples: serial buffer; serial send |
mkarlsso | 0:8dbd6bd9167f | 2793 | } else if (tokens[i].compare("serial") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 2794 | if (ifBlockInit || whileBlockInit || elseFlag || expectingDoStatement) { |
mkarlsso | 0:8dbd6bd9167f | 2795 | textDisplay << "Error: expected a 'do' statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2796 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2797 | } |
mkarlsso | 0:8dbd6bd9167f | 2798 | bool stream = true; |
mkarlsso | 0:8dbd6bd9167f | 2799 | if ((!lineError)&&(i+1 < sz)){ |
mkarlsso | 0:8dbd6bd9167f | 2800 | if (tokens[i+1].compare("buffer") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 2801 | stream = false; |
mkarlsso | 0:8dbd6bd9167f | 2802 | } else if (tokens[i+1].compare("send") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 2803 | stream = true; |
mkarlsso | 0:8dbd6bd9167f | 2804 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2805 | textDisplay << "Error: 'serial' useage: 'serial buffer' or 'serial send'\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2806 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2807 | } |
mkarlsso | 0:8dbd6bd9167f | 2808 | } |
mkarlsso | 0:8dbd6bd9167f | 2809 | i++; |
mkarlsso | 0:8dbd6bd9167f | 2810 | if ((!lineError) && (blockDepth == 0)) { |
mkarlsso | 0:8dbd6bd9167f | 2811 | if (stream) { |
mkarlsso | 0:8dbd6bd9167f | 2812 | textStreaming = true; |
mkarlsso | 0:8dbd6bd9167f | 2813 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2814 | textStreaming = false; |
mkarlsso | 0:8dbd6bd9167f | 2815 | } |
mkarlsso | 0:8dbd6bd9167f | 2816 | } else if ((!lineError) && (blockDepth > 0)) { |
mkarlsso | 0:8dbd6bd9167f | 2817 | if (stream) { |
mkarlsso | 0:8dbd6bd9167f | 2818 | //action* tmpAction = new action(1); //code 1 = turn on text streaming |
mkarlsso | 0:8dbd6bd9167f | 2819 | action* tmpAction = findFirstUnUsed(actionBlock, NUMACTIONS); |
mkarlsso | 0:8dbd6bd9167f | 2820 | if (tmpAction == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 2821 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2822 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2823 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2824 | tmpAction->set(1); |
mkarlsso | 0:8dbd6bd9167f | 2825 | tmpEventPtrArray.back()->addAction(tmpAction); |
mkarlsso | 0:8dbd6bd9167f | 2826 | } |
mkarlsso | 0:8dbd6bd9167f | 2827 | |
mkarlsso | 0:8dbd6bd9167f | 2828 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2829 | //action* tmpAction = new action(2); //code 2 = turn on text buffering |
mkarlsso | 0:8dbd6bd9167f | 2830 | action* tmpAction = findFirstUnUsed(actionBlock, NUMACTIONS); |
mkarlsso | 0:8dbd6bd9167f | 2831 | if (tmpAction == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 2832 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2833 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2834 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2835 | tmpAction->set(2); |
mkarlsso | 0:8dbd6bd9167f | 2836 | tmpEventPtrArray.back()->addAction(tmpAction); |
mkarlsso | 0:8dbd6bd9167f | 2837 | } |
mkarlsso | 0:8dbd6bd9167f | 2838 | } |
mkarlsso | 0:8dbd6bd9167f | 2839 | } |
mkarlsso | 0:8dbd6bd9167f | 2840 | |
mkarlsso | 0:8dbd6bd9167f | 2841 | //updates command toggles the DIO update messages upon a change------------------ |
mkarlsso | 0:8dbd6bd9167f | 2842 | //examples: updates on; updates off |
mkarlsso | 0:8dbd6bd9167f | 2843 | } else if (tokens[i].compare("updates") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 2844 | if (ifBlockInit || whileBlockInit || elseFlag || expectingDoStatement) { |
mkarlsso | 0:8dbd6bd9167f | 2845 | textDisplay << "Error: expected a 'do' statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2846 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2847 | } |
mkarlsso | 0:8dbd6bd9167f | 2848 | bool stream = true; |
mkarlsso | 0:8dbd6bd9167f | 2849 | if ((!lineError)&&(i+1 < sz)){ |
mkarlsso | 0:8dbd6bd9167f | 2850 | if (tokens[i+1].compare("on") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 2851 | stream = true; |
mkarlsso | 0:8dbd6bd9167f | 2852 | } else if (tokens[i+1].compare("off") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 2853 | stream = false; |
mkarlsso | 0:8dbd6bd9167f | 2854 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2855 | textDisplay << "Error: 'updates' useage: 'updates on' or 'updates off'\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2856 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2857 | } |
mkarlsso | 0:8dbd6bd9167f | 2858 | } |
mkarlsso | 0:8dbd6bd9167f | 2859 | i++; |
mkarlsso | 0:8dbd6bd9167f | 2860 | if ((!lineError) && (blockDepth == 0)) { |
mkarlsso | 0:8dbd6bd9167f | 2861 | if (stream) { |
mkarlsso | 0:8dbd6bd9167f | 2862 | broadCastStateChanges = true; |
mkarlsso | 0:8dbd6bd9167f | 2863 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2864 | broadCastStateChanges = false; |
mkarlsso | 0:8dbd6bd9167f | 2865 | } |
mkarlsso | 0:8dbd6bd9167f | 2866 | } else if ((!lineError) && (blockDepth > 0)) { |
mkarlsso | 0:8dbd6bd9167f | 2867 | if (stream) { |
mkarlsso | 0:8dbd6bd9167f | 2868 | //action* tmpAction = new action(3); //code 3 = turn on updates |
mkarlsso | 0:8dbd6bd9167f | 2869 | action* tmpAction = findFirstUnUsed(actionBlock, NUMACTIONS); |
mkarlsso | 0:8dbd6bd9167f | 2870 | if (tmpAction == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 2871 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2872 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2873 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2874 | tmpAction->set(3); |
mkarlsso | 0:8dbd6bd9167f | 2875 | tmpEventPtrArray.back()->addAction(tmpAction); |
mkarlsso | 0:8dbd6bd9167f | 2876 | } |
mkarlsso | 0:8dbd6bd9167f | 2877 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2878 | //action* tmpAction = new action(4); //code 4 = turn off updates |
mkarlsso | 0:8dbd6bd9167f | 2879 | action* tmpAction = findFirstUnUsed(actionBlock, NUMACTIONS); |
mkarlsso | 0:8dbd6bd9167f | 2880 | if (tmpAction == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 2881 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2882 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2883 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2884 | tmpAction->set(4); |
mkarlsso | 0:8dbd6bd9167f | 2885 | tmpEventPtrArray.back()->addAction(tmpAction); |
mkarlsso | 0:8dbd6bd9167f | 2886 | } |
mkarlsso | 0:8dbd6bd9167f | 2887 | |
mkarlsso | 0:8dbd6bd9167f | 2888 | } |
mkarlsso | 0:8dbd6bd9167f | 2889 | } |
mkarlsso | 0:8dbd6bd9167f | 2890 | |
mkarlsso | 0:8dbd6bd9167f | 2891 | } else if (tokens[i].compare("memory") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 2892 | if (ifBlockInit || whileBlockInit || elseFlag || expectingDoStatement) { |
mkarlsso | 0:8dbd6bd9167f | 2893 | textDisplay << "Error: expected a 'do' statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2894 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2895 | } |
mkarlsso | 0:8dbd6bd9167f | 2896 | if ((!lineError) && (blockDepth > 0)) { |
mkarlsso | 0:8dbd6bd9167f | 2897 | textDisplay << "Error: memory statement is not allowed inside a block.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2898 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2899 | } |
mkarlsso | 0:8dbd6bd9167f | 2900 | if (!lineError) { |
mkarlsso | 0:8dbd6bd9167f | 2901 | displayMemoryLeft(); |
mkarlsso | 0:8dbd6bd9167f | 2902 | } |
mkarlsso | 0:8dbd6bd9167f | 2903 | |
mkarlsso | 0:8dbd6bd9167f | 2904 | |
mkarlsso | 0:8dbd6bd9167f | 2905 | //clear is used to clear things from memory--------------------------------- |
mkarlsso | 0:8dbd6bd9167f | 2906 | //examples: clear all; clear callbacks; clear queue |
mkarlsso | 0:8dbd6bd9167f | 2907 | |
mkarlsso | 0:8dbd6bd9167f | 2908 | } else if (tokens[i].compare("clear") == 0) { //delete all created events and variables |
mkarlsso | 0:8dbd6bd9167f | 2909 | if (ifBlockInit || whileBlockInit || elseFlag || expectingDoStatement) { |
mkarlsso | 0:8dbd6bd9167f | 2910 | textDisplay << "Error: expected a 'do' statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2911 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2912 | } |
mkarlsso | 0:8dbd6bd9167f | 2913 | int clearMode = 0; |
mkarlsso | 0:8dbd6bd9167f | 2914 | if ((!lineError)&&(i+1 < sz)){ |
mkarlsso | 0:8dbd6bd9167f | 2915 | if (tokens[i+1].compare("all") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 2916 | clearMode = 1; |
mkarlsso | 0:8dbd6bd9167f | 2917 | } else if (tokens[i+1].compare("blocks") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 2918 | clearMode = 2; |
mkarlsso | 0:8dbd6bd9167f | 2919 | } else if (tokens[i+1].compare("queue") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 2920 | clearMode = 3; |
mkarlsso | 0:8dbd6bd9167f | 2921 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2922 | textDisplay << "Error: clear what: all, blocks, or queue? \r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2923 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2924 | } |
mkarlsso | 0:8dbd6bd9167f | 2925 | } else { |
mkarlsso | 0:8dbd6bd9167f | 2926 | textDisplay << "Error: clear what: all, blocks, or queue? \r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2927 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2928 | } |
mkarlsso | 0:8dbd6bd9167f | 2929 | |
mkarlsso | 0:8dbd6bd9167f | 2930 | |
mkarlsso | 0:8dbd6bd9167f | 2931 | if ((!lineError) && (clearMode < 3) && (blockDepth > 0)) { |
mkarlsso | 0:8dbd6bd9167f | 2932 | textDisplay << "Error: 'clear all' and 'clear blocks' only allowed outside of block structures\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 2933 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 2934 | } |
mkarlsso | 0:8dbd6bd9167f | 2935 | if (!lineError) { |
mkarlsso | 0:8dbd6bd9167f | 2936 | //i++; |
mkarlsso | 0:8dbd6bd9167f | 2937 | //clear variables |
mkarlsso | 0:8dbd6bd9167f | 2938 | if (clearMode == 1) { |
mkarlsso | 0:8dbd6bd9167f | 2939 | while (!globalVariables.empty()) { |
mkarlsso | 0:8dbd6bd9167f | 2940 | delete globalVariables.back(); |
mkarlsso | 0:8dbd6bd9167f | 2941 | globalVariables.pop_back(); |
mkarlsso | 0:8dbd6bd9167f | 2942 | } |
mkarlsso | 0:8dbd6bd9167f | 2943 | } |
mkarlsso | 0:8dbd6bd9167f | 2944 | |
mkarlsso | 0:8dbd6bd9167f | 2945 | //clear callbacks, functions, and queue |
mkarlsso | 0:8dbd6bd9167f | 2946 | if (clearMode < 3) { |
mkarlsso | 0:8dbd6bd9167f | 2947 | for (int pNum = 0; pNum < NUMPORTS; pNum++) { |
mkarlsso | 0:8dbd6bd9167f | 2948 | //delete portVector[pNum]->triggerUpEventPtr; |
mkarlsso | 0:8dbd6bd9167f | 2949 | if (portVector[pNum].triggerUpEventPtr != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 2950 | portVector[pNum].triggerUpEventPtr->release(); |
mkarlsso | 0:8dbd6bd9167f | 2951 | } |
mkarlsso | 0:8dbd6bd9167f | 2952 | portVector[pNum].triggerUpEventPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 2953 | |
mkarlsso | 0:8dbd6bd9167f | 2954 | //delete portVector[pNum]->triggerDownEventPtr; |
mkarlsso | 0:8dbd6bd9167f | 2955 | if (portVector[pNum].triggerDownEventPtr != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 2956 | portVector[pNum].triggerDownEventPtr->release(); |
mkarlsso | 0:8dbd6bd9167f | 2957 | } |
mkarlsso | 0:8dbd6bd9167f | 2958 | portVector[pNum].triggerDownEventPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 2959 | |
mkarlsso | 0:8dbd6bd9167f | 2960 | |
mkarlsso | 0:8dbd6bd9167f | 2961 | /* |
mkarlsso | 0:8dbd6bd9167f | 2962 | while (!functionArray.empty()) { |
mkarlsso | 0:8dbd6bd9167f | 2963 | delete functionArray.back(); |
mkarlsso | 0:8dbd6bd9167f | 2964 | functionArray.pop_back(); |
mkarlsso | 0:8dbd6bd9167f | 2965 | } */ |
mkarlsso | 0:8dbd6bd9167f | 2966 | } |
mkarlsso | 0:8dbd6bd9167f | 2967 | for (int i = 0; i < NUMFUNCTIONS; i++) { |
mkarlsso | 0:8dbd6bd9167f | 2968 | functionSpotTaken[i] = false; |
mkarlsso | 0:8dbd6bd9167f | 2969 | functionEventArray[i] = NULL; |
mkarlsso | 0:8dbd6bd9167f | 2970 | } |
mkarlsso | 0:8dbd6bd9167f | 2971 | for (int i = 0; i < NUMEVENTS; i++) { |
mkarlsso | 0:8dbd6bd9167f | 2972 | eventBlock[i].release(); |
mkarlsso | 0:8dbd6bd9167f | 2973 | } |
mkarlsso | 0:8dbd6bd9167f | 2974 | for (int i = 0; i < NUMCONDITIONS; i++) { |
mkarlsso | 0:8dbd6bd9167f | 2975 | conditionBlock[i].release(); |
mkarlsso | 0:8dbd6bd9167f | 2976 | } |
mkarlsso | 0:8dbd6bd9167f | 2977 | for (int i = 0; i < NUMINTCOMPARE; i++) { |
mkarlsso | 0:8dbd6bd9167f | 2978 | intCompareBlock[i].release(); |
mkarlsso | 0:8dbd6bd9167f | 2979 | } |
mkarlsso | 0:8dbd6bd9167f | 2980 | for (int i = 0; i < NUMACTIONS; i++) { |
mkarlsso | 0:8dbd6bd9167f | 2981 | actionBlock[i].release(); |
mkarlsso | 0:8dbd6bd9167f | 2982 | } |
mkarlsso | 0:8dbd6bd9167f | 2983 | for (int i = 0; i < NUMPORTMESSAGES; i++) { |
mkarlsso | 0:8dbd6bd9167f | 2984 | portMessageBlock[i].release(); |
mkarlsso | 0:8dbd6bd9167f | 2985 | } |
mkarlsso | 0:8dbd6bd9167f | 2986 | for (int i = 0; i < NUMINTOPERATIONS; i++) { |
mkarlsso | 0:8dbd6bd9167f | 2987 | intOperationBlock[i].release(); |
mkarlsso | 0:8dbd6bd9167f | 2988 | } |
mkarlsso | 0:8dbd6bd9167f | 2989 | for (int i = 0; i < NUMDISPLAYACTIONS; i++) { |
mkarlsso | 0:8dbd6bd9167f | 2990 | displayActionBlock[i].release(); |
mkarlsso | 0:8dbd6bd9167f | 2991 | } |
mkarlsso | 0:8dbd6bd9167f | 2992 | for (int i = 0; i <NUMTRIGGERACTIONS; i++) { |
mkarlsso | 0:8dbd6bd9167f | 2993 | triggerFunctionActionBlock[i].release(); |
mkarlsso | 0:8dbd6bd9167f | 2994 | } |
mkarlsso | 0:8dbd6bd9167f | 2995 | |
mkarlsso | 0:8dbd6bd9167f | 2996 | queuePtr->eraseQueue(); |
mkarlsso | 0:8dbd6bd9167f | 2997 | } |
mkarlsso | 0:8dbd6bd9167f | 2998 | |
mkarlsso | 0:8dbd6bd9167f | 2999 | if (clearMode == 4) { |
mkarlsso | 0:8dbd6bd9167f | 3000 | if (blockDepth > 0) { //we are inside a block |
mkarlsso | 0:8dbd6bd9167f | 3001 | action* tmpAction = findFirstUnUsed(actionBlock, NUMACTIONS); |
mkarlsso | 0:8dbd6bd9167f | 3002 | if (tmpAction == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 3003 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3004 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3005 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3006 | |
mkarlsso | 0:8dbd6bd9167f | 3007 | int8_t code = 0; |
mkarlsso | 0:8dbd6bd9167f | 3008 | tmpAction->set(code); |
mkarlsso | 0:8dbd6bd9167f | 3009 | //action* tmpAction = new action(code); //code 0 = clear queue |
mkarlsso | 0:8dbd6bd9167f | 3010 | tmpEventPtrArray.back()->addAction(tmpAction); |
mkarlsso | 0:8dbd6bd9167f | 3011 | } |
mkarlsso | 0:8dbd6bd9167f | 3012 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3013 | //clear queue now |
mkarlsso | 0:8dbd6bd9167f | 3014 | queuePtr->eraseQueue(); |
mkarlsso | 0:8dbd6bd9167f | 3015 | } |
mkarlsso | 0:8dbd6bd9167f | 3016 | } |
mkarlsso | 0:8dbd6bd9167f | 3017 | wholeLineEvaluated = true; |
mkarlsso | 0:8dbd6bd9167f | 3018 | |
mkarlsso | 0:8dbd6bd9167f | 3019 | |
mkarlsso | 0:8dbd6bd9167f | 3020 | } |
mkarlsso | 0:8dbd6bd9167f | 3021 | |
mkarlsso | 0:8dbd6bd9167f | 3022 | //do starts a block--------------------------------------------------------- |
mkarlsso | 0:8dbd6bd9167f | 3023 | //example: do in 500 |
mkarlsso | 0:8dbd6bd9167f | 3024 | // ... |
mkarlsso | 0:8dbd6bd9167f | 3025 | // end |
mkarlsso | 0:8dbd6bd9167f | 3026 | |
mkarlsso | 0:8dbd6bd9167f | 3027 | } else if (tokens[i].compare("do") == 0) { //the start of a block |
mkarlsso | 0:8dbd6bd9167f | 3028 | |
mkarlsso | 0:8dbd6bd9167f | 3029 | if (!ifBlockInit && !whileBlockInit) { |
mkarlsso | 0:8dbd6bd9167f | 3030 | |
mkarlsso | 0:8dbd6bd9167f | 3031 | if ((currentTriggerPort > 0) || (currentFunction > -1)) { //check to make sure we are inside a trigger block |
mkarlsso | 0:8dbd6bd9167f | 3032 | |
mkarlsso | 0:8dbd6bd9167f | 3033 | |
mkarlsso | 0:8dbd6bd9167f | 3034 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3035 | textDisplay << "Error: a statement block must be placed inside a callback or function.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3036 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3037 | } |
mkarlsso | 0:8dbd6bd9167f | 3038 | |
mkarlsso | 0:8dbd6bd9167f | 3039 | } |
mkarlsso | 0:8dbd6bd9167f | 3040 | expectingDoStatement = false; |
mkarlsso | 0:8dbd6bd9167f | 3041 | tmpEvent = findFirstUnUsed(eventBlock, NUMEVENTS); |
mkarlsso | 0:8dbd6bd9167f | 3042 | action* tmpAction = findFirstUnUsed(actionBlock, NUMACTIONS); |
mkarlsso | 0:8dbd6bd9167f | 3043 | bool eventReserved = false; |
mkarlsso | 0:8dbd6bd9167f | 3044 | if ((tmpEvent == NULL)||(tmpAction == NULL)) { |
mkarlsso | 0:8dbd6bd9167f | 3045 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3046 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3047 | |
mkarlsso | 0:8dbd6bd9167f | 3048 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3049 | |
mkarlsso | 0:8dbd6bd9167f | 3050 | |
mkarlsso | 0:8dbd6bd9167f | 3051 | } |
mkarlsso | 0:8dbd6bd9167f | 3052 | |
mkarlsso | 0:8dbd6bd9167f | 3053 | if (i+2 < sz) { //a time delay in the block |
mkarlsso | 0:8dbd6bd9167f | 3054 | |
mkarlsso | 0:8dbd6bd9167f | 3055 | if ((!lineError) && (tokens[i+1].compare("in") == 0) && (isNumber(tokens[i+2]))) { |
mkarlsso | 0:8dbd6bd9167f | 3056 | textDisplay.debug("Do in number statement\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 3057 | currentDelay = atoi(tokens[i+2].data()); |
mkarlsso | 0:8dbd6bd9167f | 3058 | if (currentDelay < 0) { |
mkarlsso | 0:8dbd6bd9167f | 3059 | textDisplay <<"Error: block delay time must be a positive integer\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3060 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3061 | } else if (!ifBlockInit) { //a standalone do block |
mkarlsso | 0:8dbd6bd9167f | 3062 | //tmpEvent = new event(queuePtr); |
mkarlsso | 0:8dbd6bd9167f | 3063 | tmpEvent->isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 3064 | eventReserved = true; |
mkarlsso | 0:8dbd6bd9167f | 3065 | tmpEvent->setTimeLag(currentDelay); |
mkarlsso | 0:8dbd6bd9167f | 3066 | |
mkarlsso | 0:8dbd6bd9167f | 3067 | if ((!elseFlag) && ((!thenFlag))) { |
mkarlsso | 0:8dbd6bd9167f | 3068 | //tmpEventPtrArray.back()->addAction(new action(tmpEvent)); |
mkarlsso | 0:8dbd6bd9167f | 3069 | tmpAction->set(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3070 | tmpEventPtrArray.back()->addAction(tmpAction); |
mkarlsso | 0:8dbd6bd9167f | 3071 | tmpEventPtrArray.push_back(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3072 | tmpEventPtrArray.back()->blockType = 2; //this is a do block |
mkarlsso | 0:8dbd6bd9167f | 3073 | blockDepth = blockDepth+1; |
mkarlsso | 0:8dbd6bd9167f | 3074 | } else if (elseFlag) { |
mkarlsso | 0:8dbd6bd9167f | 3075 | tmpEventPtrArray.back()->setNextElseEvent(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3076 | tmpEventPtrArray.push_back(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3077 | tmpEventPtrArray.back()->blockType = 4; //an else block |
mkarlsso | 0:8dbd6bd9167f | 3078 | } else if (thenFlag) { |
mkarlsso | 0:8dbd6bd9167f | 3079 | |
mkarlsso | 0:8dbd6bd9167f | 3080 | tmpEventPtrArray.back()->setNextElseEvent(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3081 | tmpEventPtrArray.push_back(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3082 | tmpEventPtrArray.back()->blockType = 8; //a then block |
mkarlsso | 0:8dbd6bd9167f | 3083 | } |
mkarlsso | 0:8dbd6bd9167f | 3084 | |
mkarlsso | 0:8dbd6bd9167f | 3085 | } else { //an if block |
mkarlsso | 0:8dbd6bd9167f | 3086 | tmpEventPtrArray.back()->setTimeLag(currentDelay); |
mkarlsso | 0:8dbd6bd9167f | 3087 | |
mkarlsso | 0:8dbd6bd9167f | 3088 | if (!elseFlag && !thenFlag) { |
mkarlsso | 0:8dbd6bd9167f | 3089 | if (blockDepth > 1) { //this is a nested block, so add it as an action to the parent block |
mkarlsso | 0:8dbd6bd9167f | 3090 | tmpAction->set(tmpEventPtrArray.back()); |
mkarlsso | 0:8dbd6bd9167f | 3091 | tmpEventPtrArray.at(tmpEventPtrArray.size()-2)->addAction(tmpAction); |
mkarlsso | 0:8dbd6bd9167f | 3092 | //tmpEventPtrArray.at(tmpEventPtrArray.size()-2)->addAction(new action(tmpEventPtrArray.back())); |
mkarlsso | 0:8dbd6bd9167f | 3093 | } |
mkarlsso | 0:8dbd6bd9167f | 3094 | } else if (elseFlag){ |
mkarlsso | 0:8dbd6bd9167f | 3095 | tmpEventPtrArray.at(tmpEventPtrArray.size()-2)->setNextElseEvent(tmpEventPtrArray.back()); |
mkarlsso | 0:8dbd6bd9167f | 3096 | } else if (thenFlag){ |
mkarlsso | 0:8dbd6bd9167f | 3097 | tmpEventPtrArray.at(tmpEventPtrArray.size()-2)->setNextElseEvent(tmpEventPtrArray.back()); |
mkarlsso | 0:8dbd6bd9167f | 3098 | |
mkarlsso | 0:8dbd6bd9167f | 3099 | } |
mkarlsso | 0:8dbd6bd9167f | 3100 | |
mkarlsso | 0:8dbd6bd9167f | 3101 | |
mkarlsso | 0:8dbd6bd9167f | 3102 | } |
mkarlsso | 0:8dbd6bd9167f | 3103 | |
mkarlsso | 1:3a050d26d4f6 | 3104 | } else if ((!lineError) && (tokens[i+1].compare("in") == 0) && (findIntVariable(tokens[i+2].data())!=NULL)) { |
mkarlsso | 0:8dbd6bd9167f | 3105 | textDisplay.debug("Do in VAR statement\r\n"); |
mkarlsso | 1:3a050d26d4f6 | 3106 | int* delayVar = findIntVariable(tokens[i+2].data()); |
mkarlsso | 0:8dbd6bd9167f | 3107 | //currentDelay = atoi(tokens[i+2].data()); |
mkarlsso | 0:8dbd6bd9167f | 3108 | if (!ifBlockInit) { //a standalone do block |
mkarlsso | 0:8dbd6bd9167f | 3109 | //tmpEvent = new event(queuePtr); |
mkarlsso | 0:8dbd6bd9167f | 3110 | tmpEvent->isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 3111 | eventReserved = true; |
mkarlsso | 0:8dbd6bd9167f | 3112 | tmpEvent->setTimeLag(delayVar); |
mkarlsso | 0:8dbd6bd9167f | 3113 | |
mkarlsso | 0:8dbd6bd9167f | 3114 | if ((!elseFlag) && ((!thenFlag))) { |
mkarlsso | 0:8dbd6bd9167f | 3115 | //tmpEventPtrArray.back()->addAction(new action(tmpEvent)); |
mkarlsso | 0:8dbd6bd9167f | 3116 | tmpAction->set(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3117 | tmpEventPtrArray.back()->addAction(tmpAction); |
mkarlsso | 0:8dbd6bd9167f | 3118 | tmpEventPtrArray.push_back(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3119 | tmpEventPtrArray.back()->blockType = 2; //this is a do block |
mkarlsso | 0:8dbd6bd9167f | 3120 | blockDepth = blockDepth+1; |
mkarlsso | 0:8dbd6bd9167f | 3121 | } else if (elseFlag) { |
mkarlsso | 0:8dbd6bd9167f | 3122 | tmpEventPtrArray.back()->setNextElseEvent(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3123 | tmpEventPtrArray.push_back(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3124 | tmpEventPtrArray.back()->blockType = 4; //an else block |
mkarlsso | 0:8dbd6bd9167f | 3125 | } else if (thenFlag) { |
mkarlsso | 0:8dbd6bd9167f | 3126 | |
mkarlsso | 0:8dbd6bd9167f | 3127 | tmpEventPtrArray.back()->setNextElseEvent(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3128 | tmpEventPtrArray.push_back(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3129 | tmpEventPtrArray.back()->blockType = 8; //a then block |
mkarlsso | 0:8dbd6bd9167f | 3130 | } |
mkarlsso | 0:8dbd6bd9167f | 3131 | |
mkarlsso | 0:8dbd6bd9167f | 3132 | } else { //an if block |
mkarlsso | 0:8dbd6bd9167f | 3133 | tmpEventPtrArray.back()->setTimeLag(delayVar); |
mkarlsso | 0:8dbd6bd9167f | 3134 | |
mkarlsso | 0:8dbd6bd9167f | 3135 | if (!elseFlag && !thenFlag) { |
mkarlsso | 0:8dbd6bd9167f | 3136 | if (blockDepth > 1) { //this is a nested block, so add it as an action to the parent block |
mkarlsso | 0:8dbd6bd9167f | 3137 | tmpAction->set(tmpEventPtrArray.back()); |
mkarlsso | 0:8dbd6bd9167f | 3138 | tmpEventPtrArray.at(tmpEventPtrArray.size()-2)->addAction(tmpAction); |
mkarlsso | 0:8dbd6bd9167f | 3139 | //tmpEventPtrArray.at(tmpEventPtrArray.size()-2)->addAction(new action(tmpEventPtrArray.back())); |
mkarlsso | 0:8dbd6bd9167f | 3140 | } |
mkarlsso | 0:8dbd6bd9167f | 3141 | } else if (elseFlag){ |
mkarlsso | 0:8dbd6bd9167f | 3142 | tmpEventPtrArray.at(tmpEventPtrArray.size()-2)->setNextElseEvent(tmpEventPtrArray.back()); |
mkarlsso | 0:8dbd6bd9167f | 3143 | } else if (thenFlag){ |
mkarlsso | 0:8dbd6bd9167f | 3144 | tmpEventPtrArray.at(tmpEventPtrArray.size()-2)->setNextElseEvent(tmpEventPtrArray.back()); |
mkarlsso | 0:8dbd6bd9167f | 3145 | |
mkarlsso | 0:8dbd6bd9167f | 3146 | } |
mkarlsso | 0:8dbd6bd9167f | 3147 | |
mkarlsso | 0:8dbd6bd9167f | 3148 | |
mkarlsso | 0:8dbd6bd9167f | 3149 | } |
mkarlsso | 0:8dbd6bd9167f | 3150 | |
mkarlsso | 0:8dbd6bd9167f | 3151 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3152 | textDisplay << "Error: block delay time must be a positive integer or a variable\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3153 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3154 | } |
mkarlsso | 0:8dbd6bd9167f | 3155 | } else if (!lineError && !ifBlockInit) { //no time delay given, standalone do |
mkarlsso | 0:8dbd6bd9167f | 3156 | textDisplay.debug("Do statement\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 3157 | currentDelay = 0; |
mkarlsso | 0:8dbd6bd9167f | 3158 | //tmpEvent = new event(queuePtr); |
mkarlsso | 0:8dbd6bd9167f | 3159 | tmpEvent->isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 3160 | eventReserved = true; |
mkarlsso | 0:8dbd6bd9167f | 3161 | tmpEvent->setTimeLag(currentDelay); |
mkarlsso | 0:8dbd6bd9167f | 3162 | if (!elseFlag && !thenFlag) { |
mkarlsso | 0:8dbd6bd9167f | 3163 | tmpAction->set(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3164 | tmpEventPtrArray.back()->addAction(tmpAction); |
mkarlsso | 0:8dbd6bd9167f | 3165 | //tmpEventPtrArray.back()->addAction(new action(tmpEvent)); |
mkarlsso | 0:8dbd6bd9167f | 3166 | tmpEventPtrArray.push_back(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3167 | blockDepth = blockDepth+1; |
mkarlsso | 0:8dbd6bd9167f | 3168 | } else if (elseFlag) { |
mkarlsso | 0:8dbd6bd9167f | 3169 | tmpEventPtrArray.back()->setNextElseEvent(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3170 | tmpEventPtrArray.push_back(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3171 | tmpEventPtrArray.back()->blockType = 4; //an else block |
mkarlsso | 0:8dbd6bd9167f | 3172 | } else if (thenFlag) { |
mkarlsso | 0:8dbd6bd9167f | 3173 | tmpEventPtrArray.back()->setNextElseEvent(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3174 | tmpEventPtrArray.push_back(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3175 | tmpEventPtrArray.back()->blockType = 8; //a then block |
mkarlsso | 0:8dbd6bd9167f | 3176 | } |
mkarlsso | 0:8dbd6bd9167f | 3177 | |
mkarlsso | 0:8dbd6bd9167f | 3178 | } else if (!lineError) { //no time delay, if block |
mkarlsso | 0:8dbd6bd9167f | 3179 | |
mkarlsso | 0:8dbd6bd9167f | 3180 | currentDelay = 0; |
mkarlsso | 0:8dbd6bd9167f | 3181 | tmpEventPtrArray.back()->setTimeLag(currentDelay); |
mkarlsso | 0:8dbd6bd9167f | 3182 | |
mkarlsso | 0:8dbd6bd9167f | 3183 | |
mkarlsso | 0:8dbd6bd9167f | 3184 | if (!elseFlag && !thenFlag) { |
mkarlsso | 0:8dbd6bd9167f | 3185 | if (blockDepth > 1) { |
mkarlsso | 0:8dbd6bd9167f | 3186 | tmpAction->set(tmpEventPtrArray.back()); |
mkarlsso | 0:8dbd6bd9167f | 3187 | tmpEventPtrArray.at(tmpEventPtrArray.size()-2)->addAction(tmpAction); |
mkarlsso | 0:8dbd6bd9167f | 3188 | //tmpEventPtrArray.at(tmpEventPtrArray.size()-2)->addAction(new action(tmpEventPtrArray.back())); |
mkarlsso | 0:8dbd6bd9167f | 3189 | } |
mkarlsso | 0:8dbd6bd9167f | 3190 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3191 | tmpEventPtrArray.at(tmpEventPtrArray.size()-2)->setNextElseEvent(tmpEventPtrArray.back()); |
mkarlsso | 0:8dbd6bd9167f | 3192 | } |
mkarlsso | 0:8dbd6bd9167f | 3193 | |
mkarlsso | 0:8dbd6bd9167f | 3194 | } |
mkarlsso | 0:8dbd6bd9167f | 3195 | if (lineError && eventReserved) { |
mkarlsso | 0:8dbd6bd9167f | 3196 | tmpEvent->release(); |
mkarlsso | 0:8dbd6bd9167f | 3197 | } |
mkarlsso | 0:8dbd6bd9167f | 3198 | //close block initiation |
mkarlsso | 0:8dbd6bd9167f | 3199 | ifBlockInit = false; |
mkarlsso | 0:8dbd6bd9167f | 3200 | whileBlockInit = false; |
mkarlsso | 0:8dbd6bd9167f | 3201 | wholeLineEvaluated = true; |
mkarlsso | 0:8dbd6bd9167f | 3202 | elseFlag = false; |
mkarlsso | 0:8dbd6bd9167f | 3203 | thenFlag = false; |
mkarlsso | 0:8dbd6bd9167f | 3204 | |
mkarlsso | 0:8dbd6bd9167f | 3205 | //currently, there are two types of root-level blocks: functions and callbacks |
mkarlsso | 0:8dbd6bd9167f | 3206 | // |
mkarlsso | 0:8dbd6bd9167f | 3207 | //A function can be triggered with a command, a callback is tied to a hardware event |
mkarlsso | 0:8dbd6bd9167f | 3208 | } else if (tokens[i].compare("function") == 0) { //a new function block |
mkarlsso | 0:8dbd6bd9167f | 3209 | if (ifBlockInit || whileBlockInit || elseFlag || expectingDoStatement) { |
mkarlsso | 0:8dbd6bd9167f | 3210 | textDisplay << "Error: expected a 'do' statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3211 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3212 | } |
mkarlsso | 0:8dbd6bd9167f | 3213 | if (blockDepth != 0) { |
mkarlsso | 0:8dbd6bd9167f | 3214 | textDisplay <<"Error: Can't declare a function block within another block\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3215 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3216 | } |
mkarlsso | 0:8dbd6bd9167f | 3217 | if (!lineError) { |
mkarlsso | 0:8dbd6bd9167f | 3218 | textDisplay.debug("Function statement\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 3219 | wholeLineEvaluated = true; |
mkarlsso | 0:8dbd6bd9167f | 3220 | if (i+1 < sz) { |
mkarlsso | 0:8dbd6bd9167f | 3221 | int tempFuncNum = atoi(tokens[i+1].data()); |
mkarlsso | 0:8dbd6bd9167f | 3222 | if ((tempFuncNum > 0) && (tempFuncNum < NUMFUNCTIONS+1)) { |
mkarlsso | 0:8dbd6bd9167f | 3223 | currentFunction = tempFuncNum-1; |
mkarlsso | 0:8dbd6bd9167f | 3224 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3225 | textDisplay << "Error: not a valid function number\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3226 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3227 | } |
mkarlsso | 0:8dbd6bd9167f | 3228 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3229 | if (!lineError) textDisplay << "Error: Not enough arguments for function statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3230 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3231 | } |
mkarlsso | 0:8dbd6bd9167f | 3232 | if (sz > 2) { |
mkarlsso | 0:8dbd6bd9167f | 3233 | if (!((sz == 3) && (tokens[i+2].compare("do") == 0))) { |
mkarlsso | 0:8dbd6bd9167f | 3234 | textDisplay << "Error: Too many arguments in function statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3235 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3236 | } |
mkarlsso | 0:8dbd6bd9167f | 3237 | } |
mkarlsso | 0:8dbd6bd9167f | 3238 | |
mkarlsso | 0:8dbd6bd9167f | 3239 | tmpEvent = findFirstUnUsed(eventBlock, NUMEVENTS); |
mkarlsso | 0:8dbd6bd9167f | 3240 | if (tmpEvent != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 3241 | tmpEvent->isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 3242 | |
mkarlsso | 0:8dbd6bd9167f | 3243 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3244 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3245 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3246 | } |
mkarlsso | 0:8dbd6bd9167f | 3247 | if (!lineError) { |
mkarlsso | 0:8dbd6bd9167f | 3248 | |
mkarlsso | 0:8dbd6bd9167f | 3249 | blockDepth = 1; |
mkarlsso | 0:8dbd6bd9167f | 3250 | i = i+2; |
mkarlsso | 0:8dbd6bd9167f | 3251 | //create new event and attach it to the port |
mkarlsso | 0:8dbd6bd9167f | 3252 | //tmpEventPtrArray.push_back(new event(queuePtr)); |
mkarlsso | 0:8dbd6bd9167f | 3253 | tmpEventPtrArray.push_back(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3254 | |
mkarlsso | 0:8dbd6bd9167f | 3255 | if (functionSpotTaken[currentFunction]) { |
mkarlsso | 0:8dbd6bd9167f | 3256 | functionEventArray[currentFunction]->release(); |
mkarlsso | 0:8dbd6bd9167f | 3257 | } |
mkarlsso | 0:8dbd6bd9167f | 3258 | functionEventArray[currentFunction] = tmpEvent; |
mkarlsso | 0:8dbd6bd9167f | 3259 | functionSpotTaken[currentFunction] = true; |
mkarlsso | 0:8dbd6bd9167f | 3260 | |
mkarlsso | 0:8dbd6bd9167f | 3261 | } |
mkarlsso | 0:8dbd6bd9167f | 3262 | } |
mkarlsso | 0:8dbd6bd9167f | 3263 | |
mkarlsso | 0:8dbd6bd9167f | 3264 | |
mkarlsso | 0:8dbd6bd9167f | 3265 | //callback starts a callback block------------------------------------------ |
mkarlsso | 0:8dbd6bd9167f | 3266 | //exmaple: callback portin(1) down |
mkarlsso | 0:8dbd6bd9167f | 3267 | // ... |
mkarlsso | 0:8dbd6bd9167f | 3268 | // end |
mkarlsso | 0:8dbd6bd9167f | 3269 | } else if (tokens[i].compare("callback") == 0) { //a new callback block |
mkarlsso | 0:8dbd6bd9167f | 3270 | if (ifBlockInit || whileBlockInit || elseFlag || expectingDoStatement) { |
mkarlsso | 0:8dbd6bd9167f | 3271 | textDisplay << "Error: expected a 'do' statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3272 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3273 | } |
mkarlsso | 0:8dbd6bd9167f | 3274 | if (blockDepth != 0) { |
mkarlsso | 0:8dbd6bd9167f | 3275 | textDisplay << "Error: Can't declare a callback block within another block\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3276 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3277 | } |
mkarlsso | 0:8dbd6bd9167f | 3278 | if (!lineError) { |
mkarlsso | 0:8dbd6bd9167f | 3279 | textDisplay.debug("Callback statement\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 3280 | wholeLineEvaluated = true; |
mkarlsso | 0:8dbd6bd9167f | 3281 | if (i+2 < sz) { |
mkarlsso | 0:8dbd6bd9167f | 3282 | if ((tokens[i+1].find("portin[") != std::string::npos) && (tokens[i+1].size() > 8) ) { //callback for a digital port |
mkarlsso | 0:8dbd6bd9167f | 3283 | int pos1 = tokens[i+1].find("portin[")+7; |
mkarlsso | 0:8dbd6bd9167f | 3284 | int pos2 = tokens[i+1].find_first_of("]",pos1); |
mkarlsso | 0:8dbd6bd9167f | 3285 | currentTriggerPort = atoi(tokens[i+1].substr(pos1,pos2-pos1).data()); |
mkarlsso | 0:8dbd6bd9167f | 3286 | |
mkarlsso | 0:8dbd6bd9167f | 3287 | if (currentTriggerPort <= 0) { |
mkarlsso | 0:8dbd6bd9167f | 3288 | currentTriggerPort = -1; |
mkarlsso | 0:8dbd6bd9167f | 3289 | textDisplay << "Error: Not a valid port number\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3290 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3291 | } |
mkarlsso | 0:8dbd6bd9167f | 3292 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3293 | textDisplay << "Error: Not a valid callback input\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3294 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3295 | } |
mkarlsso | 0:8dbd6bd9167f | 3296 | if (tokens[i+2].compare("up") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 3297 | currentTriggerDir = 1; |
mkarlsso | 0:8dbd6bd9167f | 3298 | } else if (tokens[i+2].compare("down") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 3299 | currentTriggerDir = -1; |
mkarlsso | 0:8dbd6bd9167f | 3300 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3301 | textDisplay << "Error: No trigger direction given\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3302 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3303 | } |
mkarlsso | 0:8dbd6bd9167f | 3304 | |
mkarlsso | 0:8dbd6bd9167f | 3305 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3306 | if (!lineError) textDisplay << "Error: Not enough arguments for callback statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3307 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3308 | } |
mkarlsso | 0:8dbd6bd9167f | 3309 | if (sz > 3) { |
mkarlsso | 0:8dbd6bd9167f | 3310 | if (!((sz == 4) && (tokens[i+3].compare("do") == 0))) { |
mkarlsso | 0:8dbd6bd9167f | 3311 | textDisplay << "Error: Too many arguments in callback statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3312 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3313 | } |
mkarlsso | 0:8dbd6bd9167f | 3314 | } |
mkarlsso | 0:8dbd6bd9167f | 3315 | |
mkarlsso | 0:8dbd6bd9167f | 3316 | tmpEvent = findFirstUnUsed(eventBlock, NUMEVENTS); |
mkarlsso | 0:8dbd6bd9167f | 3317 | if (tmpEvent != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 3318 | tmpEvent->isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 3319 | |
mkarlsso | 0:8dbd6bd9167f | 3320 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3321 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3322 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3323 | } |
mkarlsso | 0:8dbd6bd9167f | 3324 | if (!lineError) { |
mkarlsso | 0:8dbd6bd9167f | 3325 | |
mkarlsso | 0:8dbd6bd9167f | 3326 | blockDepth = 1; |
mkarlsso | 0:8dbd6bd9167f | 3327 | i = i+2; |
mkarlsso | 0:8dbd6bd9167f | 3328 | //create new event and attach it to the port |
mkarlsso | 0:8dbd6bd9167f | 3329 | //tmpEventPtrArray.push_back(new event(queuePtr)); |
mkarlsso | 0:8dbd6bd9167f | 3330 | tmpEventPtrArray.push_back(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3331 | if (currentTriggerDir == 1) { |
mkarlsso | 0:8dbd6bd9167f | 3332 | |
mkarlsso | 0:8dbd6bd9167f | 3333 | portVector[currentTriggerPort-1].setTriggerUpEvent(tmpEventPtrArray.back()); |
mkarlsso | 0:8dbd6bd9167f | 3334 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3335 | |
mkarlsso | 0:8dbd6bd9167f | 3336 | portVector[currentTriggerPort-1].setTriggerDownEvent(tmpEventPtrArray.back()); |
mkarlsso | 0:8dbd6bd9167f | 3337 | } |
mkarlsso | 0:8dbd6bd9167f | 3338 | |
mkarlsso | 0:8dbd6bd9167f | 3339 | } |
mkarlsso | 0:8dbd6bd9167f | 3340 | } |
mkarlsso | 0:8dbd6bd9167f | 3341 | |
mkarlsso | 0:8dbd6bd9167f | 3342 | //if starts an if block---------------------------------------------- |
mkarlsso | 0:8dbd6bd9167f | 3343 | //examples: if x < 10 && y == 1 do; if a==1 do in 1000 |
mkarlsso | 0:8dbd6bd9167f | 3344 | } else if (tokens[i].compare("if") == 0) { //a new if block |
mkarlsso | 0:8dbd6bd9167f | 3345 | if (ifBlockInit || whileBlockInit) { |
mkarlsso | 0:8dbd6bd9167f | 3346 | textDisplay << "Error: expected a 'do' statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3347 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3348 | } |
mkarlsso | 0:8dbd6bd9167f | 3349 | |
mkarlsso | 0:8dbd6bd9167f | 3350 | ifBlockInit = true; |
mkarlsso | 0:8dbd6bd9167f | 3351 | currentDelay = 0; |
mkarlsso | 0:8dbd6bd9167f | 3352 | bool eventDefined = false; |
mkarlsso | 0:8dbd6bd9167f | 3353 | tmpEvent = findFirstUnUsed(eventBlock, NUMEVENTS); |
mkarlsso | 0:8dbd6bd9167f | 3354 | if (tmpEvent != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 3355 | tmpEvent->isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 3356 | eventDefined = true; |
mkarlsso | 0:8dbd6bd9167f | 3357 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3358 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3359 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3360 | } |
mkarlsso | 0:8dbd6bd9167f | 3361 | if (!lineError) { |
mkarlsso | 0:8dbd6bd9167f | 3362 | textDisplay.debug("If statement\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 3363 | //this is a regular event |
mkarlsso | 0:8dbd6bd9167f | 3364 | //tmpEventPtrArray.push_back(new event(queuePtr)); |
mkarlsso | 0:8dbd6bd9167f | 3365 | tmpEventPtrArray.push_back(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3366 | |
mkarlsso | 0:8dbd6bd9167f | 3367 | if ((!elseFlag) && ((!thenFlag))) { |
mkarlsso | 0:8dbd6bd9167f | 3368 | tmpEventPtrArray.back()->blockType = 1; //this is an if block |
mkarlsso | 0:8dbd6bd9167f | 3369 | blockDepth = blockDepth + 1; |
mkarlsso | 0:8dbd6bd9167f | 3370 | } else if (elseFlag) { |
mkarlsso | 0:8dbd6bd9167f | 3371 | tmpEventPtrArray.back()->blockType = 3; //this is an else if block |
mkarlsso | 0:8dbd6bd9167f | 3372 | } else if (thenFlag) { |
mkarlsso | 0:8dbd6bd9167f | 3373 | tmpEventPtrArray.back()->blockType = 7; //this is a then if block |
mkarlsso | 0:8dbd6bd9167f | 3374 | } |
mkarlsso | 0:8dbd6bd9167f | 3375 | } |
mkarlsso | 0:8dbd6bd9167f | 3376 | |
mkarlsso | 0:8dbd6bd9167f | 3377 | if (!lineError) { |
mkarlsso | 0:8dbd6bd9167f | 3378 | //combine the condition tokens without whitespaces |
mkarlsso | 0:8dbd6bd9167f | 3379 | tmpString = ""; |
mkarlsso | 0:8dbd6bd9167f | 3380 | for (unsigned j = i+1; j < sz; j++) { |
mkarlsso | 0:8dbd6bd9167f | 3381 | if (tokens[j].compare("do") != 0) { |
mkarlsso | 0:8dbd6bd9167f | 3382 | i++; |
mkarlsso | 0:8dbd6bd9167f | 3383 | tmpString.append(tokens[j]); |
mkarlsso | 0:8dbd6bd9167f | 3384 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3385 | break; |
mkarlsso | 0:8dbd6bd9167f | 3386 | } |
mkarlsso | 0:8dbd6bd9167f | 3387 | } |
mkarlsso | 0:8dbd6bd9167f | 3388 | //adds the conditions to the current event |
mkarlsso | 0:8dbd6bd9167f | 3389 | |
mkarlsso | 0:8dbd6bd9167f | 3390 | if (!evaluateConditions(tmpString, tmpEventPtrArray.back())) lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3391 | } |
mkarlsso | 0:8dbd6bd9167f | 3392 | |
mkarlsso | 0:8dbd6bd9167f | 3393 | if (lineError && eventDefined) { |
mkarlsso | 0:8dbd6bd9167f | 3394 | tmpEvent->release(); |
mkarlsso | 0:8dbd6bd9167f | 3395 | } |
mkarlsso | 0:8dbd6bd9167f | 3396 | |
mkarlsso | 0:8dbd6bd9167f | 3397 | |
mkarlsso | 0:8dbd6bd9167f | 3398 | //else starts an else block------------------------------------- |
mkarlsso | 0:8dbd6bd9167f | 3399 | //examples: else do in 500; else if x==7 do |
mkarlsso | 0:8dbd6bd9167f | 3400 | } else if (tokens[i].compare("else") == 0) { //an else block |
mkarlsso | 0:8dbd6bd9167f | 3401 | if (ifBlockInit || whileBlockInit || expectingDoStatement) { |
mkarlsso | 0:8dbd6bd9167f | 3402 | textDisplay << "Error: expected a 'do' statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3403 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3404 | } |
mkarlsso | 0:8dbd6bd9167f | 3405 | textDisplay.debug("Else statement\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 3406 | //callbacks can't have else conditions |
mkarlsso | 0:8dbd6bd9167f | 3407 | if ((!lineError) && (blockDepth < 2) && ((currentTriggerPort > -1)||(currentFunction > -1))) { |
mkarlsso | 0:8dbd6bd9167f | 3408 | textDisplay << "Error: else statement can not occur after a trigger block or outside a block\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3409 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3410 | } |
mkarlsso | 0:8dbd6bd9167f | 3411 | |
mkarlsso | 0:8dbd6bd9167f | 3412 | //check to make sure we are in an 'if' block |
mkarlsso | 0:8dbd6bd9167f | 3413 | if ((!lineError) && (tmpEventPtrArray.back()->blockType != 1) && (tmpEventPtrArray.back()->blockType != 3)) { //not currently in an 'if' or 'else if' block |
mkarlsso | 0:8dbd6bd9167f | 3414 | textDisplay << "Error: else statement can only occur in an 'if' block\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3415 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3416 | } |
mkarlsso | 0:8dbd6bd9167f | 3417 | if (!lineError) { |
mkarlsso | 0:8dbd6bd9167f | 3418 | elseFlag = true; |
mkarlsso | 0:8dbd6bd9167f | 3419 | expectingDoStatement = true; |
mkarlsso | 0:8dbd6bd9167f | 3420 | |
mkarlsso | 0:8dbd6bd9167f | 3421 | } |
mkarlsso | 0:8dbd6bd9167f | 3422 | } else if (tokens[i].compare("then") == 0) { //a then block |
mkarlsso | 0:8dbd6bd9167f | 3423 | if (ifBlockInit || whileBlockInit) { |
mkarlsso | 0:8dbd6bd9167f | 3424 | textDisplay << "Error: expected a 'do' statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3425 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3426 | } |
mkarlsso | 0:8dbd6bd9167f | 3427 | |
mkarlsso | 0:8dbd6bd9167f | 3428 | //trigger blocks can't have else conditions |
mkarlsso | 0:8dbd6bd9167f | 3429 | if ((!lineError) && (blockDepth < 2) && (currentTriggerPort > -1)) { |
mkarlsso | 0:8dbd6bd9167f | 3430 | textDisplay << "Error: 'then' statement can only occur after a 'while' block\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3431 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3432 | } |
mkarlsso | 0:8dbd6bd9167f | 3433 | |
mkarlsso | 0:8dbd6bd9167f | 3434 | //check to make sure we are in a 'while' block |
mkarlsso | 0:8dbd6bd9167f | 3435 | if ((!lineError) && (tmpEventPtrArray.back()->blockType != 5)) { //not currently in a while block |
mkarlsso | 0:8dbd6bd9167f | 3436 | textDisplay << "Error: 'then' statement can only occur in a 'while' block\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3437 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3438 | } |
mkarlsso | 0:8dbd6bd9167f | 3439 | if (!lineError) { |
mkarlsso | 0:8dbd6bd9167f | 3440 | thenFlag = true; |
mkarlsso | 0:8dbd6bd9167f | 3441 | expectingDoStatement = true; |
mkarlsso | 0:8dbd6bd9167f | 3442 | |
mkarlsso | 0:8dbd6bd9167f | 3443 | } |
mkarlsso | 0:8dbd6bd9167f | 3444 | //while starts a while block---------------------------------------- |
mkarlsso | 0:8dbd6bd9167f | 3445 | //example: while x<10 do every 100 |
mkarlsso | 0:8dbd6bd9167f | 3446 | // ... |
mkarlsso | 0:8dbd6bd9167f | 3447 | // end |
mkarlsso | 0:8dbd6bd9167f | 3448 | } else if (tokens[i].compare("while") == 0) { //a new while block |
mkarlsso | 0:8dbd6bd9167f | 3449 | if (ifBlockInit || whileBlockInit) { |
mkarlsso | 0:8dbd6bd9167f | 3450 | textDisplay << "Error: expected a 'do' statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3451 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3452 | } |
mkarlsso | 0:8dbd6bd9167f | 3453 | textDisplay.debug("While statement\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 3454 | |
mkarlsso | 0:8dbd6bd9167f | 3455 | if ((currentTriggerPort > 0) || (currentFunction > -1)) { //check to make sure we are inside a trigger block |
mkarlsso | 0:8dbd6bd9167f | 3456 | |
mkarlsso | 0:8dbd6bd9167f | 3457 | |
mkarlsso | 0:8dbd6bd9167f | 3458 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3459 | textDisplay << "Error: a statement block must be placed inside a callback or function.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3460 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3461 | } |
mkarlsso | 0:8dbd6bd9167f | 3462 | //whileBlockInit = true; |
mkarlsso | 0:8dbd6bd9167f | 3463 | currentDelay = 0; |
mkarlsso | 0:8dbd6bd9167f | 3464 | |
mkarlsso | 0:8dbd6bd9167f | 3465 | tmpEvent = findFirstUnUsed(eventBlock, NUMEVENTS); |
mkarlsso | 0:8dbd6bd9167f | 3466 | if (tmpEvent != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 3467 | tmpEvent->isUsed = true; |
mkarlsso | 0:8dbd6bd9167f | 3468 | tmpEvent->setTimeLag(currentDelay); |
mkarlsso | 0:8dbd6bd9167f | 3469 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3470 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3471 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3472 | } |
mkarlsso | 0:8dbd6bd9167f | 3473 | |
mkarlsso | 0:8dbd6bd9167f | 3474 | //tmpEvent = new event(queuePtr); |
mkarlsso | 0:8dbd6bd9167f | 3475 | |
mkarlsso | 0:8dbd6bd9167f | 3476 | |
mkarlsso | 0:8dbd6bd9167f | 3477 | if (!lineError) { |
mkarlsso | 0:8dbd6bd9167f | 3478 | //combine the condition tokens without whitespaces |
mkarlsso | 0:8dbd6bd9167f | 3479 | tmpString = ""; |
mkarlsso | 0:8dbd6bd9167f | 3480 | for (unsigned j = i+1; j < sz; j++) { |
mkarlsso | 0:8dbd6bd9167f | 3481 | if (tokens[j].compare("do") != 0) { |
mkarlsso | 0:8dbd6bd9167f | 3482 | i++; |
mkarlsso | 0:8dbd6bd9167f | 3483 | tmpString.append(tokens[j]); |
mkarlsso | 0:8dbd6bd9167f | 3484 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3485 | break; |
mkarlsso | 0:8dbd6bd9167f | 3486 | } |
mkarlsso | 0:8dbd6bd9167f | 3487 | } |
mkarlsso | 0:8dbd6bd9167f | 3488 | //adds the conditions to the current event |
mkarlsso | 0:8dbd6bd9167f | 3489 | if (!evaluateConditions(tmpString, tmpEvent)) lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3490 | } |
mkarlsso | 0:8dbd6bd9167f | 3491 | |
mkarlsso | 0:8dbd6bd9167f | 3492 | if (!lineError) { |
mkarlsso | 0:8dbd6bd9167f | 3493 | if ((i+3) < sz) { |
mkarlsso | 0:8dbd6bd9167f | 3494 | if ((tokens[i+1].compare("do") == 0) && (tokens[i+2].compare("every") == 0)) { |
mkarlsso | 0:8dbd6bd9167f | 3495 | |
mkarlsso | 0:8dbd6bd9167f | 3496 | if (isNumber(tokens[i+3])) { |
mkarlsso | 0:8dbd6bd9167f | 3497 | uint32_t period = atoi(tokens[i+3].data()); |
mkarlsso | 0:8dbd6bd9167f | 3498 | if (period > 0) { |
mkarlsso | 0:8dbd6bd9167f | 3499 | |
mkarlsso | 0:8dbd6bd9167f | 3500 | |
mkarlsso | 0:8dbd6bd9167f | 3501 | //tmpEvent->whileLoopPeriod = period; |
mkarlsso | 0:8dbd6bd9167f | 3502 | tmpEvent->setWhileLoopPeriod(period); |
mkarlsso | 0:8dbd6bd9167f | 3503 | if (!elseFlag) { |
mkarlsso | 0:8dbd6bd9167f | 3504 | tmpEvent->blockType = 5; //this is a while block |
mkarlsso | 0:8dbd6bd9167f | 3505 | |
mkarlsso | 0:8dbd6bd9167f | 3506 | action* tmpAction = findFirstUnUsed(actionBlock, NUMACTIONS); |
mkarlsso | 0:8dbd6bd9167f | 3507 | if (tmpAction == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 3508 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3509 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3510 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3511 | tmpAction->set(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3512 | } |
mkarlsso | 0:8dbd6bd9167f | 3513 | //tmpEventPtrArray.back()->addAction(new action(tmpEvent)); |
mkarlsso | 0:8dbd6bd9167f | 3514 | tmpEventPtrArray.back()->addAction(tmpAction); |
mkarlsso | 0:8dbd6bd9167f | 3515 | |
mkarlsso | 0:8dbd6bd9167f | 3516 | tmpEventPtrArray.push_back(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3517 | blockDepth = blockDepth+1; |
mkarlsso | 0:8dbd6bd9167f | 3518 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3519 | tmpEvent->blockType = 6; //this is an else while block |
mkarlsso | 0:8dbd6bd9167f | 3520 | tmpEventPtrArray.back()->setNextElseEvent(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3521 | tmpEventPtrArray.push_back(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3522 | } |
mkarlsso | 0:8dbd6bd9167f | 3523 | wholeLineEvaluated = true; |
mkarlsso | 0:8dbd6bd9167f | 3524 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3525 | textDisplay << "Error: loop period must be a positive integer.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3526 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3527 | } |
mkarlsso | 1:3a050d26d4f6 | 3528 | } else if (findIntVariable(tokens[i+3].data())!=NULL) { |
mkarlsso | 1:3a050d26d4f6 | 3529 | |
mkarlsso | 1:3a050d26d4f6 | 3530 | int* period = findIntVariable(tokens[i+3].data()); |
mkarlsso | 0:8dbd6bd9167f | 3531 | //tmpEvent->whileLoopPeriodVar = period; |
mkarlsso | 0:8dbd6bd9167f | 3532 | tmpEvent->setWhileLoopPeriod(period); |
mkarlsso | 0:8dbd6bd9167f | 3533 | if (!elseFlag) { |
mkarlsso | 0:8dbd6bd9167f | 3534 | tmpEvent->blockType = 5; //this is a while block |
mkarlsso | 0:8dbd6bd9167f | 3535 | |
mkarlsso | 0:8dbd6bd9167f | 3536 | action* tmpAction = findFirstUnUsed(actionBlock, NUMACTIONS); |
mkarlsso | 0:8dbd6bd9167f | 3537 | if (tmpAction == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 3538 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3539 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3540 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3541 | tmpAction->set(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3542 | } |
mkarlsso | 0:8dbd6bd9167f | 3543 | //tmpEventPtrArray.back()->addAction(new action(tmpEvent)); |
mkarlsso | 0:8dbd6bd9167f | 3544 | tmpEventPtrArray.back()->addAction(tmpAction); |
mkarlsso | 0:8dbd6bd9167f | 3545 | |
mkarlsso | 0:8dbd6bd9167f | 3546 | tmpEventPtrArray.push_back(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3547 | blockDepth = blockDepth+1; |
mkarlsso | 0:8dbd6bd9167f | 3548 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3549 | tmpEvent->blockType = 6; //this is an else while block |
mkarlsso | 0:8dbd6bd9167f | 3550 | tmpEventPtrArray.back()->setNextElseEvent(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3551 | tmpEventPtrArray.push_back(tmpEvent); |
mkarlsso | 0:8dbd6bd9167f | 3552 | } |
mkarlsso | 0:8dbd6bd9167f | 3553 | wholeLineEvaluated = true; |
mkarlsso | 0:8dbd6bd9167f | 3554 | } |
mkarlsso | 0:8dbd6bd9167f | 3555 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3556 | textDisplay << "Error: expected a 'do every' statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3557 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3558 | } |
mkarlsso | 0:8dbd6bd9167f | 3559 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3560 | textDisplay << "Error: expected a 'do every' statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3561 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3562 | } |
mkarlsso | 0:8dbd6bd9167f | 3563 | } |
mkarlsso | 0:8dbd6bd9167f | 3564 | |
mkarlsso | 0:8dbd6bd9167f | 3565 | //if the line contains an '=' sign,the equality is evaulated------------------------- |
mkarlsso | 0:8dbd6bd9167f | 3566 | //examples: a = 1; a = b + 5; a = random(100); portout[2] = 1; portout[2] = flip |
mkarlsso | 0:8dbd6bd9167f | 3567 | } else if ((tmpLine.find_first_of("=") != std::string::npos) ) { //an expression |
mkarlsso | 0:8dbd6bd9167f | 3568 | if (ifBlockInit || whileBlockInit || elseFlag || expectingDoStatement) { |
mkarlsso | 0:8dbd6bd9167f | 3569 | textDisplay << "Error: expected a 'do' statement\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3570 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3571 | } |
mkarlsso | 0:8dbd6bd9167f | 3572 | |
mkarlsso | 0:8dbd6bd9167f | 3573 | wholeLineEvaluated = true; |
mkarlsso | 0:8dbd6bd9167f | 3574 | tmpString = ""; |
mkarlsso | 0:8dbd6bd9167f | 3575 | int spacesBeforeEqualSign = 0; |
mkarlsso | 0:8dbd6bd9167f | 3576 | bool countSpaces = true; |
mkarlsso | 0:8dbd6bd9167f | 3577 | //combine the tokens without whitespaces |
mkarlsso | 0:8dbd6bd9167f | 3578 | for (unsigned j = i; j < sz; j++) { |
mkarlsso | 0:8dbd6bd9167f | 3579 | tmpString.append(tokens[j]); |
mkarlsso | 0:8dbd6bd9167f | 3580 | if (tokens[j].find_first_of("=") != std::string::npos) { |
mkarlsso | 0:8dbd6bd9167f | 3581 | if (tokens[j].find_first_of("=") > 0) spacesBeforeEqualSign++; |
mkarlsso | 0:8dbd6bd9167f | 3582 | countSpaces = false; |
mkarlsso | 0:8dbd6bd9167f | 3583 | } else if (countSpaces) { |
mkarlsso | 0:8dbd6bd9167f | 3584 | spacesBeforeEqualSign++; |
mkarlsso | 0:8dbd6bd9167f | 3585 | } |
mkarlsso | 0:8dbd6bd9167f | 3586 | } |
mkarlsso | 0:8dbd6bd9167f | 3587 | if (!lineError && spacesBeforeEqualSign > 1) { |
mkarlsso | 0:8dbd6bd9167f | 3588 | textDisplay << "Error: Variable can't have a space in it.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3589 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3590 | } |
mkarlsso | 0:8dbd6bd9167f | 3591 | |
mkarlsso | 0:8dbd6bd9167f | 3592 | if (!lineError) { |
mkarlsso | 0:8dbd6bd9167f | 3593 | if (blockDepth > 0) { |
mkarlsso | 0:8dbd6bd9167f | 3594 | textDisplay.debug("Variable assignment statement\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 3595 | //action* tmpAction = evaluateAssignmentForAction(tmpString); |
mkarlsso | 0:8dbd6bd9167f | 3596 | action* tmpAction = evaluateAssignmentForAction(tmpString.data()); |
mkarlsso | 0:8dbd6bd9167f | 3597 | if (tmpAction != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 3598 | tmpEventPtrArray.back()->addAction(tmpAction); |
mkarlsso | 0:8dbd6bd9167f | 3599 | |
mkarlsso | 0:8dbd6bd9167f | 3600 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3601 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3602 | } |
mkarlsso | 0:8dbd6bd9167f | 3603 | |
mkarlsso | 0:8dbd6bd9167f | 3604 | } else { //assignment was written outside of any block structure, so execute now |
mkarlsso | 0:8dbd6bd9167f | 3605 | |
mkarlsso | 0:8dbd6bd9167f | 3606 | |
mkarlsso | 0:8dbd6bd9167f | 3607 | //action* tmpAction = evaluateAssignmentForAction(tmpString); |
mkarlsso | 0:8dbd6bd9167f | 3608 | action* tmpAction = evaluateAssignmentForAction(tmpString.data()); |
mkarlsso | 0:8dbd6bd9167f | 3609 | |
mkarlsso | 0:8dbd6bd9167f | 3610 | if (tmpAction != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 3611 | tmpAction->execute(); |
mkarlsso | 0:8dbd6bd9167f | 3612 | |
mkarlsso | 0:8dbd6bd9167f | 3613 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 3614 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 3615 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3616 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3617 | } |
mkarlsso | 0:8dbd6bd9167f | 3618 | } |
mkarlsso | 0:8dbd6bd9167f | 3619 | } |
mkarlsso | 0:8dbd6bd9167f | 3620 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3621 | //if there was no match to any of the above, an error is given |
mkarlsso | 0:8dbd6bd9167f | 3622 | textDisplay << "Error: statement not understood.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3623 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3624 | } |
mkarlsso | 0:8dbd6bd9167f | 3625 | |
mkarlsso | 0:8dbd6bd9167f | 3626 | if (lineError) { |
mkarlsso | 0:8dbd6bd9167f | 3627 | break; //stop parsing the rest of the line if an error was detected |
mkarlsso | 0:8dbd6bd9167f | 3628 | } |
mkarlsso | 0:8dbd6bd9167f | 3629 | if (wholeLineEvaluated) { //some of the tokens forces the whole line to be avaluated at once |
mkarlsso | 0:8dbd6bd9167f | 3630 | i = sz; //skip ahead to end of the line |
mkarlsso | 0:8dbd6bd9167f | 3631 | } |
mkarlsso | 0:8dbd6bd9167f | 3632 | |
mkarlsso | 0:8dbd6bd9167f | 3633 | } |
mkarlsso | 0:8dbd6bd9167f | 3634 | |
mkarlsso | 0:8dbd6bd9167f | 3635 | //if there was an error, we quit compiling the code |
mkarlsso | 0:8dbd6bd9167f | 3636 | if (lineError) { |
mkarlsso | 0:8dbd6bd9167f | 3637 | textDisplay << "Line text: "; |
mkarlsso | 0:8dbd6bd9167f | 3638 | while (!tokens.empty()) { |
mkarlsso | 0:8dbd6bd9167f | 3639 | textDisplay << tokens.front()<< " "; |
mkarlsso | 0:8dbd6bd9167f | 3640 | tokens.erase(tokens.begin()); |
mkarlsso | 0:8dbd6bd9167f | 3641 | } |
mkarlsso | 0:8dbd6bd9167f | 3642 | textDisplay << "\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3643 | currentBlock.resetBuffer(); |
mkarlsso | 0:8dbd6bd9167f | 3644 | while (!tokens.empty()) { |
mkarlsso | 0:8dbd6bd9167f | 3645 | tokens.pop_back(); |
mkarlsso | 0:8dbd6bd9167f | 3646 | } |
mkarlsso | 0:8dbd6bd9167f | 3647 | delete tmpEvent; |
mkarlsso | 0:8dbd6bd9167f | 3648 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3649 | |
mkarlsso | 0:8dbd6bd9167f | 3650 | while (!tokens.empty()) { |
mkarlsso | 0:8dbd6bd9167f | 3651 | tokens.pop_back(); |
mkarlsso | 0:8dbd6bd9167f | 3652 | } |
mkarlsso | 0:8dbd6bd9167f | 3653 | //currentBlock.pop_back(); |
mkarlsso | 0:8dbd6bd9167f | 3654 | |
mkarlsso | 0:8dbd6bd9167f | 3655 | } |
mkarlsso | 0:8dbd6bd9167f | 3656 | |
mkarlsso | 0:8dbd6bd9167f | 3657 | } |
mkarlsso | 0:8dbd6bd9167f | 3658 | |
mkarlsso | 0:8dbd6bd9167f | 3659 | //make sure that all blocks have a matching end statement |
mkarlsso | 0:8dbd6bd9167f | 3660 | |
mkarlsso | 0:8dbd6bd9167f | 3661 | |
mkarlsso | 0:8dbd6bd9167f | 3662 | if ((!lineError)&&(blockDepth > 0)) { |
mkarlsso | 0:8dbd6bd9167f | 3663 | textDisplay << "Error: Missing 1 or more end statements\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3664 | lineError = true; |
mkarlsso | 0:8dbd6bd9167f | 3665 | currentBlock.resetBuffer(); |
mkarlsso | 0:8dbd6bd9167f | 3666 | } |
mkarlsso | 0:8dbd6bd9167f | 3667 | |
mkarlsso | 0:8dbd6bd9167f | 3668 | if ((!lineError)&&(blockDepth == 0)) { |
mkarlsso | 0:8dbd6bd9167f | 3669 | textDisplay.send("~~~\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 3670 | } |
mkarlsso | 0:8dbd6bd9167f | 3671 | |
mkarlsso | 0:8dbd6bd9167f | 3672 | //displayMemoryLeft(); |
mkarlsso | 0:8dbd6bd9167f | 3673 | //DisplayRAMBanks(); |
mkarlsso | 0:8dbd6bd9167f | 3674 | |
mkarlsso | 0:8dbd6bd9167f | 3675 | } |
mkarlsso | 0:8dbd6bd9167f | 3676 | |
mkarlsso | 1:3a050d26d4f6 | 3677 | /* |
mkarlsso | 0:8dbd6bd9167f | 3678 | //used to return a pointer to a variable, if it exists |
mkarlsso | 0:8dbd6bd9167f | 3679 | int* scriptStream::findIntVariable(string nameInput) { |
mkarlsso | 0:8dbd6bd9167f | 3680 | |
mkarlsso | 0:8dbd6bd9167f | 3681 | textDisplay.debug("Finding variable: "); |
mkarlsso | 0:8dbd6bd9167f | 3682 | textDisplay.debug(nameInput.data()); |
mkarlsso | 0:8dbd6bd9167f | 3683 | int* outPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 3684 | bool foundIt = false; |
mkarlsso | 0:8dbd6bd9167f | 3685 | if (nameInput.find("portout") != std::string::npos) { |
mkarlsso | 0:8dbd6bd9167f | 3686 | int pos1 = nameInput.find("portout[")+8; |
mkarlsso | 0:8dbd6bd9167f | 3687 | int pos2 = nameInput.find_first_of("]",pos1); |
mkarlsso | 0:8dbd6bd9167f | 3688 | int portnum = atoi(nameInput.substr(pos1,pos2-pos1).data()); |
mkarlsso | 0:8dbd6bd9167f | 3689 | int portVal = 0; |
mkarlsso | 0:8dbd6bd9167f | 3690 | if ((portnum > 0) && (portnum <= numPorts)) { |
mkarlsso | 0:8dbd6bd9167f | 3691 | outPtr = &portVector[portnum-1].outState; |
mkarlsso | 0:8dbd6bd9167f | 3692 | foundIt = true; |
mkarlsso | 0:8dbd6bd9167f | 3693 | } |
mkarlsso | 0:8dbd6bd9167f | 3694 | } else if (nameInput.find("portin") != std::string::npos) { |
mkarlsso | 0:8dbd6bd9167f | 3695 | int pos1 = nameInput.find("portin[")+7; |
mkarlsso | 0:8dbd6bd9167f | 3696 | int pos2 = nameInput.find_first_of("]",pos1); |
mkarlsso | 0:8dbd6bd9167f | 3697 | int portnum = atoi(nameInput.substr(pos1,pos2-pos1).data()); |
mkarlsso | 0:8dbd6bd9167f | 3698 | int portVal = 0; |
mkarlsso | 0:8dbd6bd9167f | 3699 | if ((portnum > 0) && (portnum <= numPorts)) { |
mkarlsso | 0:8dbd6bd9167f | 3700 | outPtr = &portVector[portnum-1].inState; |
mkarlsso | 0:8dbd6bd9167f | 3701 | foundIt = true; |
mkarlsso | 0:8dbd6bd9167f | 3702 | } |
mkarlsso | 0:8dbd6bd9167f | 3703 | } |
mkarlsso | 0:8dbd6bd9167f | 3704 | |
mkarlsso | 0:8dbd6bd9167f | 3705 | if (!foundIt) { |
mkarlsso | 0:8dbd6bd9167f | 3706 | std::vector<intVariable*>::size_type sz = globalVariables.size(); |
mkarlsso | 0:8dbd6bd9167f | 3707 | int start = 0; |
mkarlsso | 0:8dbd6bd9167f | 3708 | int end = nameInput.length()-1; |
mkarlsso | 0:8dbd6bd9167f | 3709 | |
mkarlsso | 0:8dbd6bd9167f | 3710 | for (unsigned i = 0; i < sz; i++) { |
mkarlsso | 0:8dbd6bd9167f | 3711 | |
mkarlsso | 0:8dbd6bd9167f | 3712 | |
mkarlsso | 0:8dbd6bd9167f | 3713 | if ((findStringLoc(nameInput.data(),globalVariables[i]->tag,start,end) != -1) && (strlen(globalVariables[i]->tag)==(end-start+1))) { |
mkarlsso | 0:8dbd6bd9167f | 3714 | outPtr = &globalVariables[i]->value; |
mkarlsso | 0:8dbd6bd9167f | 3715 | break; |
mkarlsso | 0:8dbd6bd9167f | 3716 | } |
mkarlsso | 1:3a050d26d4f6 | 3717 | |
mkarlsso | 0:8dbd6bd9167f | 3718 | } |
mkarlsso | 0:8dbd6bd9167f | 3719 | } |
mkarlsso | 0:8dbd6bd9167f | 3720 | textDisplay.debug("...done\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 3721 | |
mkarlsso | 0:8dbd6bd9167f | 3722 | return outPtr; |
mkarlsso | 0:8dbd6bd9167f | 3723 | } |
mkarlsso | 1:3a050d26d4f6 | 3724 | */ |
mkarlsso | 1:3a050d26d4f6 | 3725 | |
mkarlsso | 1:3a050d26d4f6 | 3726 | int* scriptStream::findIntVariable(const char *nameInput) { |
mkarlsso | 1:3a050d26d4f6 | 3727 | return findIntVariable(nameInput,0,strlen(nameInput)-1); |
mkarlsso | 1:3a050d26d4f6 | 3728 | } |
mkarlsso | 1:3a050d26d4f6 | 3729 | |
mkarlsso | 1:3a050d26d4f6 | 3730 | /* |
mkarlsso | 0:8dbd6bd9167f | 3731 | //used to return a pointer to a variable, if it exists |
mkarlsso | 0:8dbd6bd9167f | 3732 | int* scriptStream::findIntVariable(const char* nameInput, int start, int end) { |
mkarlsso | 0:8dbd6bd9167f | 3733 | |
mkarlsso | 0:8dbd6bd9167f | 3734 | textDisplay.debug("Finding variable..."); |
mkarlsso | 0:8dbd6bd9167f | 3735 | int* outPtr = NULL; |
mkarlsso | 0:8dbd6bd9167f | 3736 | bool foundIt = false; |
mkarlsso | 0:8dbd6bd9167f | 3737 | |
mkarlsso | 0:8dbd6bd9167f | 3738 | if (findStringLoc(nameInput,"portout[",start,end) != -1) { |
mkarlsso | 0:8dbd6bd9167f | 3739 | int pos1 = findStringLoc(nameInput,"portout[",start,end)+8; |
mkarlsso | 0:8dbd6bd9167f | 3740 | int pos2 = findStringLoc(nameInput, "]",pos1,end); |
mkarlsso | 0:8dbd6bd9167f | 3741 | if ((pos1 == -1)||(pos2 == -1)) { |
mkarlsso | 0:8dbd6bd9167f | 3742 | //syntax error |
mkarlsso | 0:8dbd6bd9167f | 3743 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 3744 | } |
mkarlsso | 0:8dbd6bd9167f | 3745 | |
mkarlsso | 0:8dbd6bd9167f | 3746 | //int portnum = atoi(nameInput.substr(pos1,pos2-pos1).data()); |
mkarlsso | 0:8dbd6bd9167f | 3747 | long int portnum = strtol(nameInput+pos1,NULL,10); |
mkarlsso | 0:8dbd6bd9167f | 3748 | if ((portnum > 0) && (portnum <= numPorts)) { |
mkarlsso | 0:8dbd6bd9167f | 3749 | outPtr = &portVector[(int)portnum-1].outState; |
mkarlsso | 0:8dbd6bd9167f | 3750 | foundIt = true; |
mkarlsso | 0:8dbd6bd9167f | 3751 | } |
mkarlsso | 0:8dbd6bd9167f | 3752 | } else if (findStringLoc(nameInput,"portin[",start,end) != -1) { |
mkarlsso | 0:8dbd6bd9167f | 3753 | int pos1 = findStringLoc(nameInput,"portin[",start,end)+7; |
mkarlsso | 0:8dbd6bd9167f | 3754 | int pos2 = findStringLoc(nameInput, "]",pos1,end); |
mkarlsso | 0:8dbd6bd9167f | 3755 | if ((pos1 == -1)||(pos2 == -1)) { |
mkarlsso | 0:8dbd6bd9167f | 3756 | //syntax error |
mkarlsso | 0:8dbd6bd9167f | 3757 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 3758 | } |
mkarlsso | 0:8dbd6bd9167f | 3759 | long int portnum = strtol(nameInput+pos1,NULL,10); |
mkarlsso | 0:8dbd6bd9167f | 3760 | |
mkarlsso | 0:8dbd6bd9167f | 3761 | if ((portnum > 0) && (portnum <= numPorts)) { |
mkarlsso | 0:8dbd6bd9167f | 3762 | outPtr = &portVector[(int)portnum-1].inState; |
mkarlsso | 0:8dbd6bd9167f | 3763 | foundIt = true; |
mkarlsso | 0:8dbd6bd9167f | 3764 | } |
mkarlsso | 0:8dbd6bd9167f | 3765 | } |
mkarlsso | 0:8dbd6bd9167f | 3766 | |
mkarlsso | 0:8dbd6bd9167f | 3767 | if (!foundIt) { |
mkarlsso | 0:8dbd6bd9167f | 3768 | std::vector<intVariable*>::size_type sz = globalVariables.size(); |
mkarlsso | 0:8dbd6bd9167f | 3769 | for (unsigned i = 0; i < sz; i++) { |
mkarlsso | 0:8dbd6bd9167f | 3770 | //const char* varName = globalVariables[i]->tag.data(); |
mkarlsso | 0:8dbd6bd9167f | 3771 | if ((findStringLoc(nameInput,globalVariables[i]->tag,start,end) != -1) && (strlen(globalVariables[i]->tag)==(end-start+1))) { |
mkarlsso | 0:8dbd6bd9167f | 3772 | outPtr = &globalVariables[i]->value; |
mkarlsso | 0:8dbd6bd9167f | 3773 | break; |
mkarlsso | 0:8dbd6bd9167f | 3774 | } |
mkarlsso | 0:8dbd6bd9167f | 3775 | } |
mkarlsso | 0:8dbd6bd9167f | 3776 | } |
mkarlsso | 0:8dbd6bd9167f | 3777 | textDisplay.debug("done\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 3778 | |
mkarlsso | 0:8dbd6bd9167f | 3779 | return outPtr; |
mkarlsso | 1:3a050d26d4f6 | 3780 | }*/ |
mkarlsso | 1:3a050d26d4f6 | 3781 | |
mkarlsso | 1:3a050d26d4f6 | 3782 | //used to return a pointer to a variable, if it exists |
mkarlsso | 1:3a050d26d4f6 | 3783 | int* scriptStream::findIntVariable(const char* nameInput, int start, int end) { |
mkarlsso | 1:3a050d26d4f6 | 3784 | |
mkarlsso | 1:3a050d26d4f6 | 3785 | textDisplay.debug("Finding variable..."); |
mkarlsso | 1:3a050d26d4f6 | 3786 | int* outPtr = NULL; |
mkarlsso | 1:3a050d26d4f6 | 3787 | bool foundIt = false; |
mkarlsso | 1:3a050d26d4f6 | 3788 | |
mkarlsso | 1:3a050d26d4f6 | 3789 | if (findStringLoc(nameInput,"portout[",start,end) != -1) { |
mkarlsso | 1:3a050d26d4f6 | 3790 | int pos1 = findStringLoc(nameInput,"portout[",start,end)+8; |
mkarlsso | 1:3a050d26d4f6 | 3791 | int pos2 = findStringLoc(nameInput, "]",pos1,end); |
mkarlsso | 1:3a050d26d4f6 | 3792 | if ((pos1 == -1)||(pos2 == -1)) { |
mkarlsso | 1:3a050d26d4f6 | 3793 | //syntax error |
mkarlsso | 1:3a050d26d4f6 | 3794 | return NULL; |
mkarlsso | 1:3a050d26d4f6 | 3795 | } |
mkarlsso | 1:3a050d26d4f6 | 3796 | |
mkarlsso | 1:3a050d26d4f6 | 3797 | //int portnum = atoi(nameInput.substr(pos1,pos2-pos1).data()); |
mkarlsso | 1:3a050d26d4f6 | 3798 | long int portnum = strtol(nameInput+pos1,NULL,10); |
mkarlsso | 1:3a050d26d4f6 | 3799 | if ((portnum > 0) && (portnum <= numPorts)) { |
mkarlsso | 1:3a050d26d4f6 | 3800 | outPtr = &portVector[(int)portnum-1].outState; |
mkarlsso | 1:3a050d26d4f6 | 3801 | foundIt = true; |
mkarlsso | 1:3a050d26d4f6 | 3802 | } |
mkarlsso | 1:3a050d26d4f6 | 3803 | } else if (findStringLoc(nameInput,"portin[",start,end) != -1) { |
mkarlsso | 1:3a050d26d4f6 | 3804 | int pos1 = findStringLoc(nameInput,"portin[",start,end)+7; |
mkarlsso | 1:3a050d26d4f6 | 3805 | int pos2 = findStringLoc(nameInput, "]",pos1,end); |
mkarlsso | 1:3a050d26d4f6 | 3806 | if ((pos1 == -1)||(pos2 == -1)) { |
mkarlsso | 1:3a050d26d4f6 | 3807 | //syntax error |
mkarlsso | 1:3a050d26d4f6 | 3808 | return NULL; |
mkarlsso | 1:3a050d26d4f6 | 3809 | } |
mkarlsso | 1:3a050d26d4f6 | 3810 | long int portnum = strtol(nameInput+pos1,NULL,10); |
mkarlsso | 1:3a050d26d4f6 | 3811 | |
mkarlsso | 1:3a050d26d4f6 | 3812 | if ((portnum > 0) && (portnum <= numPorts)) { |
mkarlsso | 1:3a050d26d4f6 | 3813 | outPtr = &portVector[(int)portnum-1].inState; |
mkarlsso | 1:3a050d26d4f6 | 3814 | foundIt = true; |
mkarlsso | 1:3a050d26d4f6 | 3815 | } |
mkarlsso | 1:3a050d26d4f6 | 3816 | } |
mkarlsso | 1:3a050d26d4f6 | 3817 | |
mkarlsso | 1:3a050d26d4f6 | 3818 | if (!foundIt) { |
mkarlsso | 1:3a050d26d4f6 | 3819 | //std::vector<intVariable*>::size_type sz = globalVariables.size(); |
mkarlsso | 1:3a050d26d4f6 | 3820 | for (unsigned i = 0; i < NUMINTVARS; i++) { |
mkarlsso | 1:3a050d26d4f6 | 3821 | //const char* varName = globalVariables[i]->tag.data(); |
mkarlsso | 1:3a050d26d4f6 | 3822 | if ((findStringLoc(nameInput,globalVarBlock[i].tag,start,end) != -1) && (strlen(globalVarBlock[i].tag)==(end-start+1))) { |
mkarlsso | 1:3a050d26d4f6 | 3823 | outPtr = &globalVarBlock[i].value; |
mkarlsso | 1:3a050d26d4f6 | 3824 | textDisplay.debug("Variable already exists.\r\n"); |
mkarlsso | 1:3a050d26d4f6 | 3825 | break; |
mkarlsso | 1:3a050d26d4f6 | 3826 | } |
mkarlsso | 1:3a050d26d4f6 | 3827 | } |
mkarlsso | 1:3a050d26d4f6 | 3828 | } |
mkarlsso | 1:3a050d26d4f6 | 3829 | //textDisplay.debug("done\r\n"); |
mkarlsso | 1:3a050d26d4f6 | 3830 | |
mkarlsso | 1:3a050d26d4f6 | 3831 | return outPtr; |
mkarlsso | 0:8dbd6bd9167f | 3832 | } |
mkarlsso | 0:8dbd6bd9167f | 3833 | |
mkarlsso | 1:3a050d26d4f6 | 3834 | |
mkarlsso | 1:3a050d26d4f6 | 3835 | bool scriptStream::createIntVariable(const string& nameInput) { |
mkarlsso | 1:3a050d26d4f6 | 3836 | if (findIntVariable(nameInput.data()) == NULL) { |
mkarlsso | 1:3a050d26d4f6 | 3837 | //globalVariables.push_back(new intVariable(nameInput, 0)); |
mkarlsso | 1:3a050d26d4f6 | 3838 | intVariable* tmpVar = findFirstUnUsed(globalVarBlock, NUMINTVARS); |
mkarlsso | 1:3a050d26d4f6 | 3839 | if (tmpVar == NULL) { |
mkarlsso | 1:3a050d26d4f6 | 3840 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 1:3a050d26d4f6 | 3841 | return false; |
mkarlsso | 1:3a050d26d4f6 | 3842 | } |
mkarlsso | 1:3a050d26d4f6 | 3843 | tmpVar->set(nameInput.data(),0); |
mkarlsso | 1:3a050d26d4f6 | 3844 | |
mkarlsso | 0:8dbd6bd9167f | 3845 | return true; |
mkarlsso | 0:8dbd6bd9167f | 3846 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3847 | return false; |
mkarlsso | 0:8dbd6bd9167f | 3848 | } |
mkarlsso | 0:8dbd6bd9167f | 3849 | } |
mkarlsso | 0:8dbd6bd9167f | 3850 | |
mkarlsso | 0:8dbd6bd9167f | 3851 | action* scriptStream::evaluateAssignmentForAction(const char* expression) { |
mkarlsso | 0:8dbd6bd9167f | 3852 | |
mkarlsso | 0:8dbd6bd9167f | 3853 | //action* tmpAction = new action(); //create a new action |
mkarlsso | 0:8dbd6bd9167f | 3854 | action* tmpAction = findFirstUnUsed(actionBlock, NUMACTIONS); |
mkarlsso | 0:8dbd6bd9167f | 3855 | if (tmpAction == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 3856 | textDisplay << "Error: no action memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3857 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 3858 | } |
mkarlsso | 0:8dbd6bd9167f | 3859 | int stringInd; |
mkarlsso | 0:8dbd6bd9167f | 3860 | int stringInd2; |
mkarlsso | 0:8dbd6bd9167f | 3861 | int afterEqualLoc; |
mkarlsso | 0:8dbd6bd9167f | 3862 | int beforeEqualLoc; |
mkarlsso | 0:8dbd6bd9167f | 3863 | int lastCharLoc = strlen(expression)-1; |
mkarlsso | 0:8dbd6bd9167f | 3864 | int multiplierInt = 1; |
mkarlsso | 0:8dbd6bd9167f | 3865 | //string afterEqual; |
mkarlsso | 0:8dbd6bd9167f | 3866 | //string beforeEqual; |
mkarlsso | 0:8dbd6bd9167f | 3867 | //The expression might have up to three variables |
mkarlsso | 0:8dbd6bd9167f | 3868 | int* tmpVar; |
mkarlsso | 0:8dbd6bd9167f | 3869 | int* tmpVar2; |
mkarlsso | 0:8dbd6bd9167f | 3870 | int* tmpVar3; |
mkarlsso | 0:8dbd6bd9167f | 3871 | |
mkarlsso | 0:8dbd6bd9167f | 3872 | stringInd = findStringLoc(expression,"=",0,strlen(expression)-1); //location of = sign, if it exists |
mkarlsso | 0:8dbd6bd9167f | 3873 | if (stringInd == -1) { |
mkarlsso | 0:8dbd6bd9167f | 3874 | //Make sure there is an equal sign |
mkarlsso | 0:8dbd6bd9167f | 3875 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 3876 | } |
mkarlsso | 0:8dbd6bd9167f | 3877 | |
mkarlsso | 0:8dbd6bd9167f | 3878 | beforeEqualLoc = stringInd-1; |
mkarlsso | 0:8dbd6bd9167f | 3879 | afterEqualLoc = stringInd+1; |
mkarlsso | 0:8dbd6bd9167f | 3880 | |
mkarlsso | 0:8dbd6bd9167f | 3881 | //location of +/- sign (only one allowed) |
mkarlsso | 0:8dbd6bd9167f | 3882 | stringInd2 = findStringLoc(expression,"+",afterEqualLoc,strlen(expression)-1); |
mkarlsso | 0:8dbd6bd9167f | 3883 | if (stringInd2 == -1) { |
mkarlsso | 0:8dbd6bd9167f | 3884 | stringInd2 = findStringLoc(expression,"-",afterEqualLoc,strlen(expression)-1); |
mkarlsso | 0:8dbd6bd9167f | 3885 | multiplierInt = -1; |
mkarlsso | 0:8dbd6bd9167f | 3886 | |
mkarlsso | 0:8dbd6bd9167f | 3887 | } |
mkarlsso | 1:3a050d26d4f6 | 3888 | |
mkarlsso | 0:8dbd6bd9167f | 3889 | tmpVar = findIntVariable(expression,0,beforeEqualLoc); //returns pointer to the variable |
mkarlsso | 1:3a050d26d4f6 | 3890 | |
mkarlsso | 0:8dbd6bd9167f | 3891 | if (findStringLoc(expression,"portout[",0,beforeEqualLoc) != -1) { //set the output of a digital port |
mkarlsso | 0:8dbd6bd9167f | 3892 | textDisplay.debug("Portout assignment\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 3893 | int pos1 = findStringLoc(expression,"portout[",0,beforeEqualLoc)+8; |
mkarlsso | 0:8dbd6bd9167f | 3894 | int pos2 = findStringLoc(expression,"]",pos1,beforeEqualLoc)-1; |
mkarlsso | 0:8dbd6bd9167f | 3895 | if (pos2 < pos1) { |
mkarlsso | 0:8dbd6bd9167f | 3896 | textDisplay << "Error: expected a ] character\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3897 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 3898 | } |
mkarlsso | 0:8dbd6bd9167f | 3899 | |
mkarlsso | 0:8dbd6bd9167f | 3900 | int portnum = -1; |
mkarlsso | 0:8dbd6bd9167f | 3901 | if (isNum(expression,pos1,pos2)) { |
mkarlsso | 0:8dbd6bd9167f | 3902 | portnum = atoi(expression+pos1); |
mkarlsso | 0:8dbd6bd9167f | 3903 | } |
mkarlsso | 0:8dbd6bd9167f | 3904 | int* tmpVar = findIntVariable(expression, pos1,pos2); //returns pointer to the variable, if given |
mkarlsso | 0:8dbd6bd9167f | 3905 | int portVal = 0; |
mkarlsso | 0:8dbd6bd9167f | 3906 | if ((tmpVar != NULL)||((portnum > 0) && (portnum <= numPorts))) { |
mkarlsso | 0:8dbd6bd9167f | 3907 | if (isNum(expression,afterEqualLoc,lastCharLoc)) { //a simple numeric assign |
mkarlsso | 0:8dbd6bd9167f | 3908 | portVal = atoi(expression+afterEqualLoc); |
mkarlsso | 0:8dbd6bd9167f | 3909 | if ((portVal == 0) || (portVal == 1)) { |
mkarlsso | 0:8dbd6bd9167f | 3910 | //portMessage* tmpMessage = new portMessage(portVector[portnum],1,portVal); |
mkarlsso | 0:8dbd6bd9167f | 3911 | portMessage* tmpMessage = findFirstUnUsed(portMessageBlock, NUMPORTMESSAGES); |
mkarlsso | 0:8dbd6bd9167f | 3912 | if (tmpMessage == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 3913 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3914 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 3915 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 3916 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3917 | //tmpMessage->setMessage(portVector[portnum],1,portVal); |
mkarlsso | 0:8dbd6bd9167f | 3918 | if (tmpVar == NULL) { //a constant port number was given |
mkarlsso | 0:8dbd6bd9167f | 3919 | tmpMessage->setMessage(NULL,portnum,portVal,portVector); |
mkarlsso | 0:8dbd6bd9167f | 3920 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3921 | tmpMessage->setMessage(tmpVar,0,portVal,portVector); |
mkarlsso | 0:8dbd6bd9167f | 3922 | } |
mkarlsso | 0:8dbd6bd9167f | 3923 | } |
mkarlsso | 0:8dbd6bd9167f | 3924 | |
mkarlsso | 0:8dbd6bd9167f | 3925 | |
mkarlsso | 0:8dbd6bd9167f | 3926 | tmpAction->set(tmpMessage); |
mkarlsso | 0:8dbd6bd9167f | 3927 | |
mkarlsso | 0:8dbd6bd9167f | 3928 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3929 | textDisplay << "Error: portouts can only be directly assigned a 1, 0 or 'flip'\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3930 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 3931 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 3932 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 3933 | } |
mkarlsso | 0:8dbd6bd9167f | 3934 | } else if (findStringLoc(expression,"flip",afterEqualLoc,lastCharLoc)!=-1) { |
mkarlsso | 0:8dbd6bd9167f | 3935 | //portMessage* tmpMessage = new portMessage(portVector[portnum],1,-1); |
mkarlsso | 0:8dbd6bd9167f | 3936 | portMessage* tmpMessage = findFirstUnUsed(portMessageBlock, NUMPORTMESSAGES); |
mkarlsso | 0:8dbd6bd9167f | 3937 | if (tmpMessage == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 3938 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3939 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 3940 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 3941 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3942 | //tmpMessage->setMessage(portVector[portnum],1,-1); |
mkarlsso | 0:8dbd6bd9167f | 3943 | if (tmpVar == NULL) { //a constant port number was given |
mkarlsso | 0:8dbd6bd9167f | 3944 | tmpMessage->setMessage(NULL,portnum,-1,portVector); |
mkarlsso | 0:8dbd6bd9167f | 3945 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3946 | tmpMessage->setMessage(tmpVar,0,-1,portVector); |
mkarlsso | 0:8dbd6bd9167f | 3947 | } |
mkarlsso | 0:8dbd6bd9167f | 3948 | } |
mkarlsso | 0:8dbd6bd9167f | 3949 | tmpAction->set(tmpMessage); |
mkarlsso | 0:8dbd6bd9167f | 3950 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3951 | textDisplay << "Error: portouts can only be directly assigned a 1, 0, or 'flip'\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3952 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 3953 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 3954 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 3955 | } |
mkarlsso | 0:8dbd6bd9167f | 3956 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3957 | textDisplay << "Port number not found (must be between 1 and " << numPorts << " or an existing variable)\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3958 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 3959 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 3960 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 3961 | } |
mkarlsso | 0:8dbd6bd9167f | 3962 | } else if (findStringLoc(expression,"portin",0,stringInd)!=-1) { |
mkarlsso | 0:8dbd6bd9167f | 3963 | textDisplay << "Error: portins can not be set\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3964 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 3965 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 3966 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 3967 | } else if (tmpVar != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 3968 | intOperation* tmpOp; |
mkarlsso | 0:8dbd6bd9167f | 3969 | intOperation* tmpOp2; |
mkarlsso | 0:8dbd6bd9167f | 3970 | if (isNum(expression,afterEqualLoc,lastCharLoc)) { //a simple numeric assign |
mkarlsso | 0:8dbd6bd9167f | 3971 | textDisplay.debug("Numeric assignment\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 3972 | //tmpOp = new intOperation(tmpVar, "=", atoi(afterEqual.data())); |
mkarlsso | 0:8dbd6bd9167f | 3973 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 3974 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 3975 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3976 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 3977 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 3978 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3979 | tmpOp->set(tmpVar, "=", atoi(expression+afterEqualLoc)); |
mkarlsso | 0:8dbd6bd9167f | 3980 | } |
mkarlsso | 0:8dbd6bd9167f | 3981 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 3982 | |
mkarlsso | 0:8dbd6bd9167f | 3983 | } else if ((stringInd2 == -1)&&(findStringLoc(expression,"random",afterEqualLoc,lastCharLoc)!=-1)) { |
mkarlsso | 0:8dbd6bd9167f | 3984 | //assign random number |
mkarlsso | 0:8dbd6bd9167f | 3985 | //no +/- detected, so its a simple assign |
mkarlsso | 0:8dbd6bd9167f | 3986 | textDisplay.debug("Random number assignment\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 3987 | int highVal = getRandomParam(expression,afterEqualLoc,lastCharLoc); |
mkarlsso | 0:8dbd6bd9167f | 3988 | |
mkarlsso | 0:8dbd6bd9167f | 3989 | if (highVal > 0) { |
mkarlsso | 0:8dbd6bd9167f | 3990 | //tmpOp = new intOperation(highVal, "=", tmpVar); //for random assignment, we reverse the input order (because of overloading uniqueness) |
mkarlsso | 0:8dbd6bd9167f | 3991 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 3992 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 3993 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 3994 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 3995 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 3996 | } else { |
mkarlsso | 0:8dbd6bd9167f | 3997 | tmpOp->setRandOp(highVal, "=", tmpVar, false); |
mkarlsso | 0:8dbd6bd9167f | 3998 | } |
mkarlsso | 0:8dbd6bd9167f | 3999 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4000 | |
mkarlsso | 0:8dbd6bd9167f | 4001 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4002 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 4003 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4004 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4005 | } |
mkarlsso | 0:8dbd6bd9167f | 4006 | } else if ((stringInd2 == -1)&&(findStringLoc(expression,"clock()",afterEqualLoc,lastCharLoc)!=-1)) { |
mkarlsso | 0:8dbd6bd9167f | 4007 | //assign clock value |
mkarlsso | 0:8dbd6bd9167f | 4008 | //no +/- detected, so its a simple assign |
mkarlsso | 0:8dbd6bd9167f | 4009 | textDisplay.debug("Clock assignment to variable\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 4010 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4011 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4012 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4013 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4014 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4015 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4016 | tmpOp->setClockOp(tmpVar); //assigns the current clock value to tmpVar |
mkarlsso | 0:8dbd6bd9167f | 4017 | } |
mkarlsso | 0:8dbd6bd9167f | 4018 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4019 | |
mkarlsso | 0:8dbd6bd9167f | 4020 | } else if (stringInd2 != -1) { //a +/- operation is there |
mkarlsso | 0:8dbd6bd9167f | 4021 | textDisplay.debug("equation assignment\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 4022 | //string multiplier("+"); |
mkarlsso | 0:8dbd6bd9167f | 4023 | char multiplier[3]; |
mkarlsso | 0:8dbd6bd9167f | 4024 | if (multiplierInt==1) { |
mkarlsso | 0:8dbd6bd9167f | 4025 | strcpy(multiplier,"+"); |
mkarlsso | 0:8dbd6bd9167f | 4026 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4027 | strcpy(multiplier,"-"); |
mkarlsso | 0:8dbd6bd9167f | 4028 | } |
mkarlsso | 0:8dbd6bd9167f | 4029 | |
mkarlsso | 0:8dbd6bd9167f | 4030 | /* |
mkarlsso | 0:8dbd6bd9167f | 4031 | if (afterEqual[stringInd2] == '-') { |
mkarlsso | 0:8dbd6bd9167f | 4032 | multiplier = "-"; |
mkarlsso | 0:8dbd6bd9167f | 4033 | multiplierInt = -1; |
mkarlsso | 0:8dbd6bd9167f | 4034 | }*/ |
mkarlsso | 0:8dbd6bd9167f | 4035 | tmpVar2 = findIntVariable(expression,afterEqualLoc,stringInd2-1); //before the +/- sign |
mkarlsso | 0:8dbd6bd9167f | 4036 | tmpVar3 = findIntVariable(expression,stringInd2+1,lastCharLoc); //after the +/- sign |
mkarlsso | 0:8dbd6bd9167f | 4037 | |
mkarlsso | 0:8dbd6bd9167f | 4038 | if ((tmpVar2 != NULL) && isNum(expression,stringInd2+1,lastCharLoc)) { //variable +/- number |
mkarlsso | 0:8dbd6bd9167f | 4039 | if (tmpVar2 == tmpVar) { |
mkarlsso | 0:8dbd6bd9167f | 4040 | //final sign is += or -= |
mkarlsso | 0:8dbd6bd9167f | 4041 | if (multiplierInt==1) { |
mkarlsso | 0:8dbd6bd9167f | 4042 | strcpy(multiplier,"+="); |
mkarlsso | 0:8dbd6bd9167f | 4043 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4044 | strcpy(multiplier,"-="); |
mkarlsso | 0:8dbd6bd9167f | 4045 | } |
mkarlsso | 0:8dbd6bd9167f | 4046 | |
mkarlsso | 0:8dbd6bd9167f | 4047 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4048 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4049 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4050 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4051 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4052 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4053 | tmpOp->set(tmpVar, multiplier, atoi(expression+stringInd2+1)); |
mkarlsso | 0:8dbd6bd9167f | 4054 | } |
mkarlsso | 0:8dbd6bd9167f | 4055 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4056 | |
mkarlsso | 0:8dbd6bd9167f | 4057 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4058 | |
mkarlsso | 0:8dbd6bd9167f | 4059 | tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4060 | if (tmpOp2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4061 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4062 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4063 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4064 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4065 | |
mkarlsso | 0:8dbd6bd9167f | 4066 | tmpOp2->set(tmpVar2,multiplier, atoi(expression+stringInd2+1)); |
mkarlsso | 0:8dbd6bd9167f | 4067 | //tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4068 | } |
mkarlsso | 0:8dbd6bd9167f | 4069 | |
mkarlsso | 0:8dbd6bd9167f | 4070 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4071 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4072 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4073 | tmpOp2->release(); |
mkarlsso | 0:8dbd6bd9167f | 4074 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4075 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4076 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4077 | tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4078 | } |
mkarlsso | 0:8dbd6bd9167f | 4079 | |
mkarlsso | 0:8dbd6bd9167f | 4080 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4081 | |
mkarlsso | 0:8dbd6bd9167f | 4082 | } |
mkarlsso | 0:8dbd6bd9167f | 4083 | |
mkarlsso | 0:8dbd6bd9167f | 4084 | } else if ((tmpVar3 != NULL) && isNum(expression,afterEqualLoc,stringInd2-1)) { //number +/- variable |
mkarlsso | 0:8dbd6bd9167f | 4085 | if (tmpVar3 == tmpVar) { |
mkarlsso | 0:8dbd6bd9167f | 4086 | //final sign is += or -= |
mkarlsso | 0:8dbd6bd9167f | 4087 | if (multiplierInt==1) { |
mkarlsso | 0:8dbd6bd9167f | 4088 | strcpy(multiplier,"+="); |
mkarlsso | 0:8dbd6bd9167f | 4089 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4090 | strcpy(multiplier,"-="); |
mkarlsso | 0:8dbd6bd9167f | 4091 | } |
mkarlsso | 0:8dbd6bd9167f | 4092 | |
mkarlsso | 0:8dbd6bd9167f | 4093 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4094 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4095 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4096 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4097 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4098 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4099 | tmpOp->set(tmpVar, multiplier, atoi(expression+afterEqualLoc)); |
mkarlsso | 0:8dbd6bd9167f | 4100 | } |
mkarlsso | 0:8dbd6bd9167f | 4101 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4102 | |
mkarlsso | 0:8dbd6bd9167f | 4103 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4104 | |
mkarlsso | 0:8dbd6bd9167f | 4105 | tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4106 | if (tmpOp2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4107 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4108 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4109 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4110 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4111 | tmpOp2->set(tmpVar3, multiplier, atoi(expression+afterEqualLoc)); |
mkarlsso | 0:8dbd6bd9167f | 4112 | } |
mkarlsso | 0:8dbd6bd9167f | 4113 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4114 | |
mkarlsso | 0:8dbd6bd9167f | 4115 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4116 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4117 | tmpOp2->release(); |
mkarlsso | 0:8dbd6bd9167f | 4118 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4119 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4120 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4121 | tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4122 | } |
mkarlsso | 0:8dbd6bd9167f | 4123 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4124 | |
mkarlsso | 0:8dbd6bd9167f | 4125 | } |
mkarlsso | 0:8dbd6bd9167f | 4126 | |
mkarlsso | 0:8dbd6bd9167f | 4127 | } else if ((tmpVar2 != NULL) && (tmpVar3 != NULL)) { //variable +/- variable |
mkarlsso | 0:8dbd6bd9167f | 4128 | |
mkarlsso | 0:8dbd6bd9167f | 4129 | tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4130 | if (tmpOp2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4131 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4132 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4133 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4134 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4135 | tmpOp2->set(tmpVar2, multiplier, tmpVar3); |
mkarlsso | 0:8dbd6bd9167f | 4136 | } |
mkarlsso | 0:8dbd6bd9167f | 4137 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4138 | |
mkarlsso | 0:8dbd6bd9167f | 4139 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4140 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4141 | tmpOp2->release(); |
mkarlsso | 0:8dbd6bd9167f | 4142 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4143 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4144 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4145 | |
mkarlsso | 0:8dbd6bd9167f | 4146 | tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4147 | } |
mkarlsso | 0:8dbd6bd9167f | 4148 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4149 | |
mkarlsso | 0:8dbd6bd9167f | 4150 | } else if ( isNum(expression,stringInd2+1,lastCharLoc) && isNum(expression,afterEqualLoc,stringInd2-1) ) { //number +/- number |
mkarlsso | 0:8dbd6bd9167f | 4151 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4152 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4153 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4154 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4155 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4156 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4157 | tmpOp->set(tmpVar, "=", atoi(expression+afterEqualLoc) + (multiplierInt * atoi(expression+stringInd2+1)) ); |
mkarlsso | 0:8dbd6bd9167f | 4158 | } |
mkarlsso | 0:8dbd6bd9167f | 4159 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4160 | |
mkarlsso | 0:8dbd6bd9167f | 4161 | } else if ((findStringLoc(expression,"random", afterEqualLoc,stringInd2-1)!=-1) && isNum(expression,stringInd2+1,lastCharLoc)) { //random +/- number |
mkarlsso | 0:8dbd6bd9167f | 4162 | int highVal = getRandomParam(expression,afterEqualLoc,stringInd2-1); |
mkarlsso | 0:8dbd6bd9167f | 4163 | |
mkarlsso | 0:8dbd6bd9167f | 4164 | if (highVal > 0) { |
mkarlsso | 0:8dbd6bd9167f | 4165 | |
mkarlsso | 0:8dbd6bd9167f | 4166 | |
mkarlsso | 0:8dbd6bd9167f | 4167 | tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4168 | if (tmpOp2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4169 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4170 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4171 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4172 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4173 | tmpOp2->setRandOp(highVal, multiplier, atoi(expression+stringInd2+1),false); |
mkarlsso | 0:8dbd6bd9167f | 4174 | } |
mkarlsso | 0:8dbd6bd9167f | 4175 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4176 | |
mkarlsso | 0:8dbd6bd9167f | 4177 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4178 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4179 | tmpOp2->release(); |
mkarlsso | 0:8dbd6bd9167f | 4180 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4181 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4182 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4183 | tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4184 | } |
mkarlsso | 0:8dbd6bd9167f | 4185 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4186 | |
mkarlsso | 0:8dbd6bd9167f | 4187 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4188 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 4189 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4190 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4191 | } |
mkarlsso | 0:8dbd6bd9167f | 4192 | } else if ((findStringLoc(expression,"random",afterEqualLoc,stringInd2-1)!=-1) && (tmpVar3 != NULL)) { //random +/- variable |
mkarlsso | 0:8dbd6bd9167f | 4193 | int highVal = getRandomParam(expression,afterEqualLoc,stringInd2-1); |
mkarlsso | 0:8dbd6bd9167f | 4194 | |
mkarlsso | 0:8dbd6bd9167f | 4195 | if (highVal > 0) { |
mkarlsso | 0:8dbd6bd9167f | 4196 | |
mkarlsso | 0:8dbd6bd9167f | 4197 | |
mkarlsso | 0:8dbd6bd9167f | 4198 | tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4199 | if (tmpOp2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4200 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4201 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4202 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4203 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4204 | tmpOp2->setRandOp(highVal, multiplier, tmpVar3, false); |
mkarlsso | 0:8dbd6bd9167f | 4205 | } |
mkarlsso | 0:8dbd6bd9167f | 4206 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4207 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4208 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4209 | tmpOp2->release(); |
mkarlsso | 0:8dbd6bd9167f | 4210 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4211 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4212 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4213 | tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4214 | } |
mkarlsso | 0:8dbd6bd9167f | 4215 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4216 | |
mkarlsso | 0:8dbd6bd9167f | 4217 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4218 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 4219 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4220 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4221 | } |
mkarlsso | 0:8dbd6bd9167f | 4222 | |
mkarlsso | 0:8dbd6bd9167f | 4223 | |
mkarlsso | 0:8dbd6bd9167f | 4224 | } else if ((findStringLoc(expression,"random",stringInd2+1,lastCharLoc)!=-1) && isNum(expression,afterEqualLoc,stringInd2-1)) { //number +/- random |
mkarlsso | 0:8dbd6bd9167f | 4225 | int highVal = getRandomParam(expression,stringInd2+1,lastCharLoc); |
mkarlsso | 0:8dbd6bd9167f | 4226 | |
mkarlsso | 0:8dbd6bd9167f | 4227 | if (highVal > 0) { |
mkarlsso | 0:8dbd6bd9167f | 4228 | |
mkarlsso | 0:8dbd6bd9167f | 4229 | |
mkarlsso | 0:8dbd6bd9167f | 4230 | tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4231 | if (tmpOp2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4232 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4233 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4234 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4235 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4236 | |
mkarlsso | 0:8dbd6bd9167f | 4237 | tmpOp2->setRandOp(highVal, multiplier, atoi(expression+afterEqualLoc),true); //the "true" signifies that the rand value came last |
mkarlsso | 0:8dbd6bd9167f | 4238 | } |
mkarlsso | 0:8dbd6bd9167f | 4239 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4240 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4241 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4242 | tmpOp2->release(); |
mkarlsso | 0:8dbd6bd9167f | 4243 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4244 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4245 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4246 | tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4247 | } |
mkarlsso | 0:8dbd6bd9167f | 4248 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4249 | |
mkarlsso | 0:8dbd6bd9167f | 4250 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4251 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 4252 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4253 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4254 | } |
mkarlsso | 0:8dbd6bd9167f | 4255 | } else if ((findStringLoc(expression,"random",stringInd2+1,lastCharLoc)!=-1) && (tmpVar2 != NULL)) { //variable +/- random |
mkarlsso | 0:8dbd6bd9167f | 4256 | int highVal = getRandomParam(expression,stringInd2+1,lastCharLoc); |
mkarlsso | 0:8dbd6bd9167f | 4257 | |
mkarlsso | 0:8dbd6bd9167f | 4258 | if (highVal > 0) { |
mkarlsso | 0:8dbd6bd9167f | 4259 | |
mkarlsso | 0:8dbd6bd9167f | 4260 | |
mkarlsso | 0:8dbd6bd9167f | 4261 | tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4262 | if (tmpOp2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4263 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4264 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4265 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4266 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4267 | |
mkarlsso | 0:8dbd6bd9167f | 4268 | tmpOp2->setRandOp(highVal, multiplier, tmpVar2, true); //the "true" signifies that the rand value came last |
mkarlsso | 0:8dbd6bd9167f | 4269 | } |
mkarlsso | 0:8dbd6bd9167f | 4270 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4271 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4272 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4273 | tmpOp2->release(); |
mkarlsso | 0:8dbd6bd9167f | 4274 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4275 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4276 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4277 | tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4278 | } |
mkarlsso | 0:8dbd6bd9167f | 4279 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4280 | |
mkarlsso | 0:8dbd6bd9167f | 4281 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4282 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 4283 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4284 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4285 | } |
mkarlsso | 0:8dbd6bd9167f | 4286 | } |
mkarlsso | 0:8dbd6bd9167f | 4287 | |
mkarlsso | 0:8dbd6bd9167f | 4288 | |
mkarlsso | 0:8dbd6bd9167f | 4289 | else if ((findStringLoc(expression,"clock()",afterEqualLoc,stringInd2-1)!=-1) && isNum(expression,stringInd2+1,lastCharLoc)) { //clock() +/- number |
mkarlsso | 0:8dbd6bd9167f | 4290 | |
mkarlsso | 0:8dbd6bd9167f | 4291 | tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4292 | if (tmpOp2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4293 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4294 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4295 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4296 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4297 | tmpOp2->setClockOp(multiplier, atoi(expression+stringInd2+1),false); |
mkarlsso | 0:8dbd6bd9167f | 4298 | } |
mkarlsso | 0:8dbd6bd9167f | 4299 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4300 | |
mkarlsso | 0:8dbd6bd9167f | 4301 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4302 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4303 | tmpOp2->release(); |
mkarlsso | 0:8dbd6bd9167f | 4304 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4305 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4306 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4307 | tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4308 | } |
mkarlsso | 0:8dbd6bd9167f | 4309 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4310 | |
mkarlsso | 0:8dbd6bd9167f | 4311 | |
mkarlsso | 0:8dbd6bd9167f | 4312 | } else if ((findStringLoc(expression,"clock()",afterEqualLoc,stringInd2-1)!=-1) && (tmpVar3 != NULL)) { //clock() +/- variable |
mkarlsso | 0:8dbd6bd9167f | 4313 | |
mkarlsso | 0:8dbd6bd9167f | 4314 | |
mkarlsso | 0:8dbd6bd9167f | 4315 | |
mkarlsso | 0:8dbd6bd9167f | 4316 | tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4317 | if (tmpOp2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4318 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4319 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4320 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4321 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4322 | tmpOp2->setClockOp(multiplier, tmpVar3, false); |
mkarlsso | 0:8dbd6bd9167f | 4323 | } |
mkarlsso | 0:8dbd6bd9167f | 4324 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4325 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4326 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4327 | tmpOp2->release(); |
mkarlsso | 0:8dbd6bd9167f | 4328 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4329 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4330 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4331 | tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4332 | } |
mkarlsso | 0:8dbd6bd9167f | 4333 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4334 | |
mkarlsso | 0:8dbd6bd9167f | 4335 | } else if ((findStringLoc(expression,"clock()",stringInd2+1,lastCharLoc)!=-1) && isNum(expression,afterEqualLoc,lastCharLoc)) { //number +/- clock() |
mkarlsso | 0:8dbd6bd9167f | 4336 | |
mkarlsso | 0:8dbd6bd9167f | 4337 | tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4338 | if (tmpOp2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4339 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4340 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4341 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4342 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4343 | |
mkarlsso | 0:8dbd6bd9167f | 4344 | tmpOp2->setClockOp(multiplier, atoi(expression+afterEqualLoc), true); //the "true" signifies that clock() came last |
mkarlsso | 0:8dbd6bd9167f | 4345 | } |
mkarlsso | 0:8dbd6bd9167f | 4346 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4347 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4348 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4349 | tmpOp2->release(); |
mkarlsso | 0:8dbd6bd9167f | 4350 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4351 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4352 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4353 | tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4354 | } |
mkarlsso | 0:8dbd6bd9167f | 4355 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4356 | |
mkarlsso | 0:8dbd6bd9167f | 4357 | |
mkarlsso | 0:8dbd6bd9167f | 4358 | } else if ((findStringLoc(expression,"clock()",stringInd2+1,lastCharLoc)!=-1) && (tmpVar2 != NULL)) { //variable +/- clock() |
mkarlsso | 0:8dbd6bd9167f | 4359 | |
mkarlsso | 0:8dbd6bd9167f | 4360 | |
mkarlsso | 0:8dbd6bd9167f | 4361 | tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4362 | if (tmpOp2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4363 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4364 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4365 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4366 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4367 | |
mkarlsso | 0:8dbd6bd9167f | 4368 | tmpOp2->setClockOp(multiplier, tmpVar2, true); //the "true" signifies that clock() came last |
mkarlsso | 0:8dbd6bd9167f | 4369 | } |
mkarlsso | 0:8dbd6bd9167f | 4370 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4371 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4372 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4373 | tmpOp2->release(); |
mkarlsso | 0:8dbd6bd9167f | 4374 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4375 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4376 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4377 | tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4378 | } |
mkarlsso | 0:8dbd6bd9167f | 4379 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4380 | |
mkarlsso | 0:8dbd6bd9167f | 4381 | |
mkarlsso | 0:8dbd6bd9167f | 4382 | } |
mkarlsso | 0:8dbd6bd9167f | 4383 | |
mkarlsso | 0:8dbd6bd9167f | 4384 | else { |
mkarlsso | 0:8dbd6bd9167f | 4385 | textDisplay << "Expression not understood: " << expression << "\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4386 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 4387 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4388 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4389 | } |
mkarlsso | 0:8dbd6bd9167f | 4390 | |
mkarlsso | 0:8dbd6bd9167f | 4391 | } else if (findIntVariable(expression,afterEqualLoc,lastCharLoc) != NULL) { //assign value of another variable |
mkarlsso | 0:8dbd6bd9167f | 4392 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4393 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4394 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4395 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4396 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4397 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4398 | tmpOp->set(tmpVar, "=", findIntVariable(expression,afterEqualLoc,lastCharLoc)); |
mkarlsso | 0:8dbd6bd9167f | 4399 | } |
mkarlsso | 0:8dbd6bd9167f | 4400 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4401 | |
mkarlsso | 0:8dbd6bd9167f | 4402 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4403 | textDisplay << "Variable not found: " << expression+afterEqualLoc << "\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4404 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4405 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4406 | } |
mkarlsso | 0:8dbd6bd9167f | 4407 | |
mkarlsso | 0:8dbd6bd9167f | 4408 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4409 | textDisplay << "Variable not found\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4410 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4411 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4412 | } |
mkarlsso | 0:8dbd6bd9167f | 4413 | textDisplay.debug("Assignment successful\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 4414 | return tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 4415 | } |
mkarlsso | 0:8dbd6bd9167f | 4416 | |
mkarlsso | 1:3a050d26d4f6 | 4417 | /* |
mkarlsso | 0:8dbd6bd9167f | 4418 | action* scriptStream::evaluateAssignmentForAction(string expression) { |
mkarlsso | 0:8dbd6bd9167f | 4419 | |
mkarlsso | 0:8dbd6bd9167f | 4420 | //action* tmpAction = new action(); //create a new action |
mkarlsso | 0:8dbd6bd9167f | 4421 | action* tmpAction = findFirstUnUsed(actionBlock, NUMACTIONS); |
mkarlsso | 0:8dbd6bd9167f | 4422 | if (tmpAction == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4423 | textDisplay << "Error: no action memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4424 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4425 | } |
mkarlsso | 0:8dbd6bd9167f | 4426 | std::size_t stringInd; |
mkarlsso | 0:8dbd6bd9167f | 4427 | std::size_t stringInd2; |
mkarlsso | 0:8dbd6bd9167f | 4428 | string afterEqual; |
mkarlsso | 0:8dbd6bd9167f | 4429 | string beforeEqual; |
mkarlsso | 0:8dbd6bd9167f | 4430 | //The expression might have up to three variables |
mkarlsso | 0:8dbd6bd9167f | 4431 | int* tmpVar; |
mkarlsso | 0:8dbd6bd9167f | 4432 | int* tmpVar2; |
mkarlsso | 0:8dbd6bd9167f | 4433 | int* tmpVar3; |
mkarlsso | 0:8dbd6bd9167f | 4434 | stringInd = expression.find_first_of("="); //location of = sign, if it exists |
mkarlsso | 0:8dbd6bd9167f | 4435 | beforeEqual = expression.substr(0,stringInd); // the string after the = sign |
mkarlsso | 0:8dbd6bd9167f | 4436 | afterEqual = expression.substr(stringInd+1,std::string::npos); // the string after the = sign |
mkarlsso | 0:8dbd6bd9167f | 4437 | stringInd2 = afterEqual.find_first_of("+-"); //location of +/- sign (only one allowed) |
mkarlsso | 0:8dbd6bd9167f | 4438 | tmpVar = findIntVariable(expression.substr(0,stringInd)); //returns pointer to the variable |
mkarlsso | 0:8dbd6bd9167f | 4439 | |
mkarlsso | 0:8dbd6bd9167f | 4440 | if (beforeEqual.find("portout[") != std::string::npos) { //set the output of a digital port |
mkarlsso | 0:8dbd6bd9167f | 4441 | textDisplay.debug("Portout assignment\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 4442 | int pos1 = beforeEqual.find("portout[")+8; |
mkarlsso | 0:8dbd6bd9167f | 4443 | int pos2 = beforeEqual.find_first_of("]",pos1); |
mkarlsso | 0:8dbd6bd9167f | 4444 | int portnum = atoi(beforeEqual.substr(pos1,pos2-pos1).data()); |
mkarlsso | 0:8dbd6bd9167f | 4445 | int* tmpVar = findIntVariable(beforeEqual.substr(pos1,pos2-pos1)); //returns pointer to the variable, if given |
mkarlsso | 0:8dbd6bd9167f | 4446 | int portVal = 0; |
mkarlsso | 0:8dbd6bd9167f | 4447 | if ((tmpVar != NULL)||((portnum > 0) && (portnum <= numPorts))) { |
mkarlsso | 0:8dbd6bd9167f | 4448 | if (isNumber(afterEqual)) { //a simple numeric assign |
mkarlsso | 0:8dbd6bd9167f | 4449 | portVal = atoi(afterEqual.data()); |
mkarlsso | 0:8dbd6bd9167f | 4450 | if ((portVal == 0) || (portVal == 1)) { |
mkarlsso | 0:8dbd6bd9167f | 4451 | //portMessage* tmpMessage = new portMessage(portVector[portnum],1,portVal); |
mkarlsso | 0:8dbd6bd9167f | 4452 | portMessage* tmpMessage = findFirstUnUsed(portMessageBlock, NUMPORTMESSAGES); |
mkarlsso | 0:8dbd6bd9167f | 4453 | if (tmpMessage == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4454 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4455 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4456 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4457 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4458 | //tmpMessage->setMessage(portVector[portnum],1,portVal); |
mkarlsso | 0:8dbd6bd9167f | 4459 | if (tmpVar == NULL) { //a constant port number was given |
mkarlsso | 0:8dbd6bd9167f | 4460 | tmpMessage->setMessage(NULL,portnum,portVal,portVector); |
mkarlsso | 0:8dbd6bd9167f | 4461 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4462 | tmpMessage->setMessage(tmpVar,0,portVal,portVector); |
mkarlsso | 0:8dbd6bd9167f | 4463 | } |
mkarlsso | 0:8dbd6bd9167f | 4464 | } |
mkarlsso | 0:8dbd6bd9167f | 4465 | |
mkarlsso | 0:8dbd6bd9167f | 4466 | |
mkarlsso | 0:8dbd6bd9167f | 4467 | tmpAction->set(tmpMessage); |
mkarlsso | 0:8dbd6bd9167f | 4468 | |
mkarlsso | 0:8dbd6bd9167f | 4469 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4470 | textDisplay << "Error: portouts can only be directly assigned a 1, 0 or 'flip'\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4471 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 4472 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4473 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4474 | } |
mkarlsso | 0:8dbd6bd9167f | 4475 | } else if (afterEqual.compare("flip") == 0) { |
mkarlsso | 0:8dbd6bd9167f | 4476 | //portMessage* tmpMessage = new portMessage(portVector[portnum],1,-1); |
mkarlsso | 0:8dbd6bd9167f | 4477 | portMessage* tmpMessage = findFirstUnUsed(portMessageBlock, NUMPORTMESSAGES); |
mkarlsso | 0:8dbd6bd9167f | 4478 | if (tmpMessage == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4479 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4480 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4481 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4482 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4483 | //tmpMessage->setMessage(portVector[portnum],1,-1); |
mkarlsso | 0:8dbd6bd9167f | 4484 | if (tmpVar == NULL) { //a constant port number was given |
mkarlsso | 0:8dbd6bd9167f | 4485 | tmpMessage->setMessage(NULL,portnum,-1,portVector); |
mkarlsso | 0:8dbd6bd9167f | 4486 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4487 | tmpMessage->setMessage(tmpVar,0,-1,portVector); |
mkarlsso | 0:8dbd6bd9167f | 4488 | } |
mkarlsso | 0:8dbd6bd9167f | 4489 | } |
mkarlsso | 0:8dbd6bd9167f | 4490 | tmpAction->set(tmpMessage); |
mkarlsso | 0:8dbd6bd9167f | 4491 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4492 | textDisplay << "Error: portouts can only be directly assigned a 1, 0, or 'flip'\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4493 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 4494 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4495 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4496 | } |
mkarlsso | 0:8dbd6bd9167f | 4497 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4498 | textDisplay << "Port number not found (must be between 1 and " << numPorts << " or an existing variable)\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4499 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 4500 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4501 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4502 | } |
mkarlsso | 0:8dbd6bd9167f | 4503 | } else if (beforeEqual.find("portin") != std::string::npos) { |
mkarlsso | 0:8dbd6bd9167f | 4504 | textDisplay << "Error: portins can not be set\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4505 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 4506 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4507 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4508 | } else if (tmpVar != NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4509 | intOperation* tmpOp; |
mkarlsso | 0:8dbd6bd9167f | 4510 | intOperation* tmpOp2; |
mkarlsso | 0:8dbd6bd9167f | 4511 | if (isNumber(afterEqual)) { //a simple numeric assign |
mkarlsso | 0:8dbd6bd9167f | 4512 | textDisplay.debug("Numeric assignment\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 4513 | //tmpOp = new intOperation(tmpVar, "=", atoi(afterEqual.data())); |
mkarlsso | 0:8dbd6bd9167f | 4514 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4515 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4516 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4517 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4518 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4519 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4520 | tmpOp->set(tmpVar, "=", atoi(afterEqual.data())); |
mkarlsso | 0:8dbd6bd9167f | 4521 | } |
mkarlsso | 0:8dbd6bd9167f | 4522 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4523 | |
mkarlsso | 0:8dbd6bd9167f | 4524 | } else if ((stringInd2 == std::string::npos)&&(afterEqual.find("random") != std::string::npos)) { |
mkarlsso | 0:8dbd6bd9167f | 4525 | //assign random number |
mkarlsso | 0:8dbd6bd9167f | 4526 | //no +/- detected, so its a simple assign |
mkarlsso | 0:8dbd6bd9167f | 4527 | textDisplay.debug("Random number assignment\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 4528 | int highVal = getRandomParam(afterEqual); |
mkarlsso | 0:8dbd6bd9167f | 4529 | |
mkarlsso | 0:8dbd6bd9167f | 4530 | if (highVal > 0) { |
mkarlsso | 0:8dbd6bd9167f | 4531 | //tmpOp = new intOperation(highVal, "=", tmpVar); //for random assignment, we reverse the input order (because of overloading uniqueness) |
mkarlsso | 0:8dbd6bd9167f | 4532 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4533 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4534 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4535 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4536 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4537 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4538 | tmpOp->setRandOp(highVal, "=", tmpVar, false); |
mkarlsso | 0:8dbd6bd9167f | 4539 | } |
mkarlsso | 0:8dbd6bd9167f | 4540 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4541 | |
mkarlsso | 0:8dbd6bd9167f | 4542 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4543 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 4544 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4545 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4546 | } |
mkarlsso | 0:8dbd6bd9167f | 4547 | } else if ((stringInd2 == std::string::npos)&&(afterEqual.find("clock()") != std::string::npos)) { |
mkarlsso | 0:8dbd6bd9167f | 4548 | //assign clock value |
mkarlsso | 0:8dbd6bd9167f | 4549 | //no +/- detected, so its a simple assign |
mkarlsso | 0:8dbd6bd9167f | 4550 | textDisplay.debug("Clock assignment to variable\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 4551 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4552 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4553 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4554 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4555 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4556 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4557 | tmpOp->setClockOp(tmpVar); //assigns the current clock value to tmpVar |
mkarlsso | 0:8dbd6bd9167f | 4558 | } |
mkarlsso | 0:8dbd6bd9167f | 4559 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4560 | |
mkarlsso | 0:8dbd6bd9167f | 4561 | } else if (stringInd2 != std::string::npos) { //a +/- operation is there |
mkarlsso | 0:8dbd6bd9167f | 4562 | textDisplay.debug("equation assignment\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 4563 | string multiplier("+"); |
mkarlsso | 0:8dbd6bd9167f | 4564 | int multiplierInt = 1; |
mkarlsso | 0:8dbd6bd9167f | 4565 | if (afterEqual[stringInd2] == '-') { |
mkarlsso | 0:8dbd6bd9167f | 4566 | multiplier = "-"; |
mkarlsso | 0:8dbd6bd9167f | 4567 | multiplierInt = -1; |
mkarlsso | 0:8dbd6bd9167f | 4568 | } |
mkarlsso | 0:8dbd6bd9167f | 4569 | tmpVar2 = findIntVariable(afterEqual.substr(0,stringInd2)); //before the +/- sign |
mkarlsso | 0:8dbd6bd9167f | 4570 | tmpVar3 = findIntVariable(afterEqual.substr(stringInd2+1,std::string::npos)); //after the +/- sign |
mkarlsso | 0:8dbd6bd9167f | 4571 | |
mkarlsso | 0:8dbd6bd9167f | 4572 | if ((tmpVar2 != NULL) && isNumber(afterEqual.substr(stringInd2+1,std::string::npos))) { //variable +/- number |
mkarlsso | 0:8dbd6bd9167f | 4573 | if (tmpVar2 == tmpVar) { |
mkarlsso | 0:8dbd6bd9167f | 4574 | multiplier.append("="); //final sign is += or -= |
mkarlsso | 0:8dbd6bd9167f | 4575 | //tmpOp = new intOperation(tmpVar, multiplier.data(), atoi(afterEqual.substr(stringInd2+1,std::string::npos).data())); |
mkarlsso | 0:8dbd6bd9167f | 4576 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4577 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4578 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4579 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4580 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4581 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4582 | tmpOp->set(tmpVar, multiplier.data(), atoi(afterEqual.substr(stringInd2+1,std::string::npos).data())); |
mkarlsso | 0:8dbd6bd9167f | 4583 | } |
mkarlsso | 0:8dbd6bd9167f | 4584 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4585 | |
mkarlsso | 0:8dbd6bd9167f | 4586 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4587 | |
mkarlsso | 0:8dbd6bd9167f | 4588 | tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4589 | if (tmpOp2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4590 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4591 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4592 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4593 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4594 | |
mkarlsso | 0:8dbd6bd9167f | 4595 | tmpOp2->set(tmpVar2,multiplier.data(), atoi(afterEqual.substr(stringInd2+1,std::string::npos).data())); |
mkarlsso | 0:8dbd6bd9167f | 4596 | //tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4597 | } |
mkarlsso | 0:8dbd6bd9167f | 4598 | |
mkarlsso | 0:8dbd6bd9167f | 4599 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4600 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4601 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4602 | tmpOp2->release(); |
mkarlsso | 0:8dbd6bd9167f | 4603 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4604 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4605 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4606 | tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4607 | } |
mkarlsso | 0:8dbd6bd9167f | 4608 | |
mkarlsso | 0:8dbd6bd9167f | 4609 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4610 | |
mkarlsso | 0:8dbd6bd9167f | 4611 | } |
mkarlsso | 0:8dbd6bd9167f | 4612 | |
mkarlsso | 0:8dbd6bd9167f | 4613 | } else if ((tmpVar3 != NULL) && isNumber(afterEqual.substr(0,stringInd2))) { //number +/- variable |
mkarlsso | 0:8dbd6bd9167f | 4614 | if (tmpVar3 == tmpVar) { |
mkarlsso | 0:8dbd6bd9167f | 4615 | multiplier.append("="); //makes "+=" or "-=" |
mkarlsso | 0:8dbd6bd9167f | 4616 | //tmpOp = new intOperation(tmpVar, multiplier.data(), atoi(afterEqual.substr(0,stringInd2).data())); |
mkarlsso | 0:8dbd6bd9167f | 4617 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4618 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4619 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4620 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4621 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4622 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4623 | tmpOp->set(tmpVar, multiplier.data(), atoi(afterEqual.substr(0,stringInd2).data())); |
mkarlsso | 0:8dbd6bd9167f | 4624 | } |
mkarlsso | 0:8dbd6bd9167f | 4625 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4626 | |
mkarlsso | 0:8dbd6bd9167f | 4627 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4628 | |
mkarlsso | 0:8dbd6bd9167f | 4629 | tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4630 | if (tmpOp2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4631 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4632 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4633 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4634 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4635 | tmpOp2->set(tmpVar3, multiplier.data(), atoi(afterEqual.substr(0, stringInd2).data())); |
mkarlsso | 0:8dbd6bd9167f | 4636 | } |
mkarlsso | 0:8dbd6bd9167f | 4637 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4638 | |
mkarlsso | 0:8dbd6bd9167f | 4639 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4640 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4641 | tmpOp2->release(); |
mkarlsso | 0:8dbd6bd9167f | 4642 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4643 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4644 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4645 | tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4646 | } |
mkarlsso | 0:8dbd6bd9167f | 4647 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4648 | |
mkarlsso | 0:8dbd6bd9167f | 4649 | } |
mkarlsso | 0:8dbd6bd9167f | 4650 | |
mkarlsso | 0:8dbd6bd9167f | 4651 | } else if ((tmpVar2 != NULL) && (tmpVar3 != NULL)) { //variable +/- variable |
mkarlsso | 0:8dbd6bd9167f | 4652 | |
mkarlsso | 0:8dbd6bd9167f | 4653 | tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4654 | if (tmpOp2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4655 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4656 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4657 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4658 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4659 | tmpOp2->set(tmpVar2, multiplier.data(), tmpVar3); |
mkarlsso | 0:8dbd6bd9167f | 4660 | } |
mkarlsso | 0:8dbd6bd9167f | 4661 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4662 | |
mkarlsso | 0:8dbd6bd9167f | 4663 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4664 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4665 | tmpOp2->release(); |
mkarlsso | 0:8dbd6bd9167f | 4666 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4667 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4668 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4669 | |
mkarlsso | 0:8dbd6bd9167f | 4670 | tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4671 | } |
mkarlsso | 0:8dbd6bd9167f | 4672 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4673 | |
mkarlsso | 0:8dbd6bd9167f | 4674 | } else if ( isNumber(afterEqual.substr(stringInd2+1,std::string::npos)) && isNumber(afterEqual.substr(0,stringInd2)) ) { //number +/- number |
mkarlsso | 0:8dbd6bd9167f | 4675 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4676 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4677 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4678 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4679 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4680 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4681 | tmpOp->set(tmpVar, "=", atoi(afterEqual.substr(0,stringInd2).data()) + (multiplierInt * atoi(afterEqual.substr(stringInd2+1,std::string::npos).data()))); |
mkarlsso | 0:8dbd6bd9167f | 4682 | } |
mkarlsso | 0:8dbd6bd9167f | 4683 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4684 | |
mkarlsso | 0:8dbd6bd9167f | 4685 | } else if ((afterEqual.substr(0,stringInd2).find("random") != std::string::npos) && isNumber(afterEqual.substr(stringInd2+1,std::string::npos))) { //random +/- number |
mkarlsso | 0:8dbd6bd9167f | 4686 | int highVal = getRandomParam(afterEqual.substr(0,stringInd2)); |
mkarlsso | 0:8dbd6bd9167f | 4687 | |
mkarlsso | 0:8dbd6bd9167f | 4688 | if (highVal > 0) { |
mkarlsso | 0:8dbd6bd9167f | 4689 | |
mkarlsso | 0:8dbd6bd9167f | 4690 | |
mkarlsso | 0:8dbd6bd9167f | 4691 | tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4692 | if (tmpOp2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4693 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4694 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4695 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4696 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4697 | tmpOp2->setRandOp(highVal, multiplier.data(), atoi(afterEqual.substr(stringInd2+1,std::string::npos).data()),false); |
mkarlsso | 0:8dbd6bd9167f | 4698 | } |
mkarlsso | 0:8dbd6bd9167f | 4699 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4700 | |
mkarlsso | 0:8dbd6bd9167f | 4701 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4702 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4703 | tmpOp2->release(); |
mkarlsso | 0:8dbd6bd9167f | 4704 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4705 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4706 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4707 | tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4708 | } |
mkarlsso | 0:8dbd6bd9167f | 4709 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4710 | |
mkarlsso | 0:8dbd6bd9167f | 4711 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4712 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 4713 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4714 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4715 | } |
mkarlsso | 0:8dbd6bd9167f | 4716 | } else if ((afterEqual.substr(0,stringInd2).find("random") != std::string::npos) && (tmpVar3 != NULL)) { //random +/- variable |
mkarlsso | 0:8dbd6bd9167f | 4717 | int highVal = getRandomParam(afterEqual.substr(0,stringInd2)); |
mkarlsso | 0:8dbd6bd9167f | 4718 | |
mkarlsso | 0:8dbd6bd9167f | 4719 | if (highVal > 0) { |
mkarlsso | 0:8dbd6bd9167f | 4720 | |
mkarlsso | 0:8dbd6bd9167f | 4721 | |
mkarlsso | 0:8dbd6bd9167f | 4722 | tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4723 | if (tmpOp2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4724 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4725 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4726 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4727 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4728 | tmpOp2->setRandOp(highVal, multiplier.data(), tmpVar3, false); |
mkarlsso | 0:8dbd6bd9167f | 4729 | } |
mkarlsso | 0:8dbd6bd9167f | 4730 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4731 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4732 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4733 | tmpOp2->release(); |
mkarlsso | 0:8dbd6bd9167f | 4734 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4735 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4736 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4737 | tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4738 | } |
mkarlsso | 0:8dbd6bd9167f | 4739 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4740 | |
mkarlsso | 0:8dbd6bd9167f | 4741 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4742 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 4743 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4744 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4745 | } |
mkarlsso | 0:8dbd6bd9167f | 4746 | |
mkarlsso | 0:8dbd6bd9167f | 4747 | |
mkarlsso | 0:8dbd6bd9167f | 4748 | } else if ((afterEqual.substr(stringInd2+1,std::string::npos).find("random") != std::string::npos) && isNumber(afterEqual.substr(0,stringInd2))) { //number +/- random |
mkarlsso | 0:8dbd6bd9167f | 4749 | int highVal = getRandomParam(afterEqual.substr(stringInd2+1,std::string::npos)); |
mkarlsso | 0:8dbd6bd9167f | 4750 | |
mkarlsso | 0:8dbd6bd9167f | 4751 | if (highVal > 0) { |
mkarlsso | 0:8dbd6bd9167f | 4752 | |
mkarlsso | 0:8dbd6bd9167f | 4753 | |
mkarlsso | 0:8dbd6bd9167f | 4754 | tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4755 | if (tmpOp2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4756 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4757 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4758 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4759 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4760 | |
mkarlsso | 0:8dbd6bd9167f | 4761 | tmpOp2->setRandOp(highVal, multiplier.data(), atoi(afterEqual.substr(0, stringInd2).data()),true); //the "true" signifies that the rand value came last |
mkarlsso | 0:8dbd6bd9167f | 4762 | } |
mkarlsso | 0:8dbd6bd9167f | 4763 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4764 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4765 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4766 | tmpOp2->release(); |
mkarlsso | 0:8dbd6bd9167f | 4767 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4768 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4769 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4770 | tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4771 | } |
mkarlsso | 0:8dbd6bd9167f | 4772 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4773 | |
mkarlsso | 0:8dbd6bd9167f | 4774 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4775 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 4776 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4777 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4778 | } |
mkarlsso | 0:8dbd6bd9167f | 4779 | } else if ((afterEqual.substr(stringInd2+1,std::string::npos).find("random") != std::string::npos) && (tmpVar2 != NULL)) { //variable +/- random |
mkarlsso | 0:8dbd6bd9167f | 4780 | int highVal = getRandomParam(afterEqual.substr(stringInd2+1,std::string::npos)); |
mkarlsso | 0:8dbd6bd9167f | 4781 | |
mkarlsso | 0:8dbd6bd9167f | 4782 | if (highVal > 0) { |
mkarlsso | 0:8dbd6bd9167f | 4783 | |
mkarlsso | 0:8dbd6bd9167f | 4784 | |
mkarlsso | 0:8dbd6bd9167f | 4785 | tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4786 | if (tmpOp2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4787 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4788 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4789 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4790 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4791 | |
mkarlsso | 0:8dbd6bd9167f | 4792 | tmpOp2->setRandOp(highVal, multiplier.data(), tmpVar2, true); //the "true" signifies that the rand value came last |
mkarlsso | 0:8dbd6bd9167f | 4793 | } |
mkarlsso | 0:8dbd6bd9167f | 4794 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4795 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4796 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4797 | tmpOp2->release(); |
mkarlsso | 0:8dbd6bd9167f | 4798 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4799 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4800 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4801 | tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4802 | } |
mkarlsso | 0:8dbd6bd9167f | 4803 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4804 | |
mkarlsso | 0:8dbd6bd9167f | 4805 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4806 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 4807 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4808 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4809 | } |
mkarlsso | 0:8dbd6bd9167f | 4810 | } |
mkarlsso | 0:8dbd6bd9167f | 4811 | |
mkarlsso | 0:8dbd6bd9167f | 4812 | |
mkarlsso | 0:8dbd6bd9167f | 4813 | |
mkarlsso | 0:8dbd6bd9167f | 4814 | |
mkarlsso | 0:8dbd6bd9167f | 4815 | |
mkarlsso | 0:8dbd6bd9167f | 4816 | else if ((afterEqual.substr(0,stringInd2).find("clock()") != std::string::npos) && isNumber(afterEqual.substr(stringInd2+1,std::string::npos))) { //clock() +/- number |
mkarlsso | 0:8dbd6bd9167f | 4817 | |
mkarlsso | 0:8dbd6bd9167f | 4818 | |
mkarlsso | 0:8dbd6bd9167f | 4819 | |
mkarlsso | 0:8dbd6bd9167f | 4820 | tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4821 | if (tmpOp2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4822 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4823 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4824 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4825 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4826 | tmpOp2->setClockOp(multiplier.data(), atoi(afterEqual.substr(stringInd2+1,std::string::npos).data()),false); |
mkarlsso | 0:8dbd6bd9167f | 4827 | } |
mkarlsso | 0:8dbd6bd9167f | 4828 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4829 | |
mkarlsso | 0:8dbd6bd9167f | 4830 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4831 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4832 | tmpOp2->release(); |
mkarlsso | 0:8dbd6bd9167f | 4833 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4834 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4835 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4836 | tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4837 | } |
mkarlsso | 0:8dbd6bd9167f | 4838 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4839 | |
mkarlsso | 0:8dbd6bd9167f | 4840 | |
mkarlsso | 0:8dbd6bd9167f | 4841 | } else if ((afterEqual.substr(0,stringInd2).find("clock()") != std::string::npos) && (tmpVar3 != NULL)) { //clock() +/- variable |
mkarlsso | 0:8dbd6bd9167f | 4842 | |
mkarlsso | 0:8dbd6bd9167f | 4843 | |
mkarlsso | 0:8dbd6bd9167f | 4844 | |
mkarlsso | 0:8dbd6bd9167f | 4845 | tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4846 | if (tmpOp2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4847 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4848 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4849 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4850 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4851 | tmpOp2->setClockOp(multiplier.data(), tmpVar3, false); |
mkarlsso | 0:8dbd6bd9167f | 4852 | } |
mkarlsso | 0:8dbd6bd9167f | 4853 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4854 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4855 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4856 | tmpOp2->release(); |
mkarlsso | 0:8dbd6bd9167f | 4857 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4858 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4859 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4860 | tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4861 | } |
mkarlsso | 0:8dbd6bd9167f | 4862 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4863 | |
mkarlsso | 0:8dbd6bd9167f | 4864 | |
mkarlsso | 0:8dbd6bd9167f | 4865 | |
mkarlsso | 0:8dbd6bd9167f | 4866 | |
mkarlsso | 0:8dbd6bd9167f | 4867 | } else if ((afterEqual.substr(stringInd2+1,std::string::npos).find("clock()") != std::string::npos) && isNumber(afterEqual.substr(0,stringInd2))) { //number +/- clock() |
mkarlsso | 0:8dbd6bd9167f | 4868 | |
mkarlsso | 0:8dbd6bd9167f | 4869 | |
mkarlsso | 0:8dbd6bd9167f | 4870 | |
mkarlsso | 0:8dbd6bd9167f | 4871 | tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4872 | if (tmpOp2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4873 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4874 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4875 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4876 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4877 | |
mkarlsso | 0:8dbd6bd9167f | 4878 | tmpOp2->setClockOp(multiplier.data(), atoi(afterEqual.substr(0, stringInd2).data()),true); //the "true" signifies that clock() came last |
mkarlsso | 0:8dbd6bd9167f | 4879 | } |
mkarlsso | 0:8dbd6bd9167f | 4880 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4881 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4882 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4883 | tmpOp2->release(); |
mkarlsso | 0:8dbd6bd9167f | 4884 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4885 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4886 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4887 | tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4888 | } |
mkarlsso | 0:8dbd6bd9167f | 4889 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4890 | |
mkarlsso | 0:8dbd6bd9167f | 4891 | |
mkarlsso | 0:8dbd6bd9167f | 4892 | } else if ((afterEqual.substr(stringInd2+1,std::string::npos).find("clock()") != std::string::npos) && (tmpVar2 != NULL)) { //variable +/- clock() |
mkarlsso | 0:8dbd6bd9167f | 4893 | |
mkarlsso | 0:8dbd6bd9167f | 4894 | |
mkarlsso | 0:8dbd6bd9167f | 4895 | tmpOp2 = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4896 | if (tmpOp2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4897 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4898 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4899 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4900 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4901 | |
mkarlsso | 0:8dbd6bd9167f | 4902 | tmpOp2->setClockOp(multiplier.data(), tmpVar2, true); //the "true" signifies that clock() came last |
mkarlsso | 0:8dbd6bd9167f | 4903 | } |
mkarlsso | 0:8dbd6bd9167f | 4904 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4905 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4906 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4907 | tmpOp2->release(); |
mkarlsso | 0:8dbd6bd9167f | 4908 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4909 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4910 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4911 | tmpOp->set(tmpVar, tmpOp2); |
mkarlsso | 0:8dbd6bd9167f | 4912 | } |
mkarlsso | 0:8dbd6bd9167f | 4913 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4914 | |
mkarlsso | 0:8dbd6bd9167f | 4915 | |
mkarlsso | 0:8dbd6bd9167f | 4916 | } |
mkarlsso | 0:8dbd6bd9167f | 4917 | |
mkarlsso | 0:8dbd6bd9167f | 4918 | else { |
mkarlsso | 0:8dbd6bd9167f | 4919 | textDisplay << "Expression not understood: " << afterEqual << "\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4920 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 4921 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4922 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4923 | } |
mkarlsso | 0:8dbd6bd9167f | 4924 | |
mkarlsso | 0:8dbd6bd9167f | 4925 | } else if (findIntVariable(afterEqual) != NULL) { //assign value of another variable |
mkarlsso | 0:8dbd6bd9167f | 4926 | //tmpOp = new intOperation(tmpVar, "=", findIntVariable(afterEqual)); |
mkarlsso | 0:8dbd6bd9167f | 4927 | tmpOp = findFirstUnUsed(intOperationBlock, NUMINTOPERATIONS); |
mkarlsso | 0:8dbd6bd9167f | 4928 | if (tmpOp == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 4929 | textDisplay << "Error: no memory slots available.\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4930 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4931 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4932 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4933 | tmpOp->set(tmpVar, "=", findIntVariable(afterEqual)); |
mkarlsso | 0:8dbd6bd9167f | 4934 | } |
mkarlsso | 0:8dbd6bd9167f | 4935 | tmpAction->set(tmpOp); |
mkarlsso | 0:8dbd6bd9167f | 4936 | |
mkarlsso | 0:8dbd6bd9167f | 4937 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4938 | textDisplay << "Variable not found: " << afterEqual << "\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4939 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 4940 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4941 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4942 | } |
mkarlsso | 0:8dbd6bd9167f | 4943 | |
mkarlsso | 0:8dbd6bd9167f | 4944 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4945 | textDisplay << "Variable not found\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 4946 | //delete tmpAction; |
mkarlsso | 0:8dbd6bd9167f | 4947 | tmpAction->release(); |
mkarlsso | 0:8dbd6bd9167f | 4948 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 4949 | } |
mkarlsso | 0:8dbd6bd9167f | 4950 | textDisplay.debug("Assignment successful\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 4951 | return tmpAction; |
mkarlsso | 1:3a050d26d4f6 | 4952 | }*/ |
mkarlsso | 0:8dbd6bd9167f | 4953 | |
mkarlsso | 0:8dbd6bd9167f | 4954 | /* |
mkarlsso | 0:8dbd6bd9167f | 4955 | bool scriptStream::isOutsideParenth(string& expression,std::size_t foundItem) { |
mkarlsso | 0:8dbd6bd9167f | 4956 | |
mkarlsso | 0:8dbd6bd9167f | 4957 | int pDepth = 0; // How many nested parentheses |
mkarlsso | 0:8dbd6bd9167f | 4958 | |
mkarlsso | 0:8dbd6bd9167f | 4959 | if (foundItem < expression.length()) { |
mkarlsso | 0:8dbd6bd9167f | 4960 | for (int i = 0; i <= foundItem; i++) { |
mkarlsso | 0:8dbd6bd9167f | 4961 | if (expression[i] == '(') { |
mkarlsso | 0:8dbd6bd9167f | 4962 | pDepth++; |
mkarlsso | 0:8dbd6bd9167f | 4963 | } else if (expression[i] == ')') { |
mkarlsso | 0:8dbd6bd9167f | 4964 | pDepth--; |
mkarlsso | 0:8dbd6bd9167f | 4965 | } |
mkarlsso | 0:8dbd6bd9167f | 4966 | } |
mkarlsso | 0:8dbd6bd9167f | 4967 | if (pDepth<=0) { |
mkarlsso | 0:8dbd6bd9167f | 4968 | |
mkarlsso | 0:8dbd6bd9167f | 4969 | return true; |
mkarlsso | 0:8dbd6bd9167f | 4970 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4971 | |
mkarlsso | 0:8dbd6bd9167f | 4972 | return false; |
mkarlsso | 0:8dbd6bd9167f | 4973 | } |
mkarlsso | 0:8dbd6bd9167f | 4974 | } else { |
mkarlsso | 0:8dbd6bd9167f | 4975 | return true; |
mkarlsso | 0:8dbd6bd9167f | 4976 | } |
mkarlsso | 0:8dbd6bd9167f | 4977 | |
mkarlsso | 0:8dbd6bd9167f | 4978 | } |
mkarlsso | 0:8dbd6bd9167f | 4979 | |
mkarlsso | 0:8dbd6bd9167f | 4980 | std::size_t scriptStream::findFirstOrOutsideParenth(string& expression) { |
mkarlsso | 0:8dbd6bd9167f | 4981 | |
mkarlsso | 0:8dbd6bd9167f | 4982 | std::size_t foundItem = expression.find("||"); |
mkarlsso | 0:8dbd6bd9167f | 4983 | while (foundItem != std::string::npos) { |
mkarlsso | 0:8dbd6bd9167f | 4984 | if (isOutsideParenth(expression,foundItem)) { |
mkarlsso | 0:8dbd6bd9167f | 4985 | break; |
mkarlsso | 0:8dbd6bd9167f | 4986 | } |
mkarlsso | 0:8dbd6bd9167f | 4987 | foundItem = expression.find("||",foundItem+1); |
mkarlsso | 0:8dbd6bd9167f | 4988 | } |
mkarlsso | 0:8dbd6bd9167f | 4989 | return foundItem; |
mkarlsso | 0:8dbd6bd9167f | 4990 | } |
mkarlsso | 0:8dbd6bd9167f | 4991 | |
mkarlsso | 0:8dbd6bd9167f | 4992 | std::size_t scriptStream::findFirstAndOutsideParenth(string& expression) { |
mkarlsso | 0:8dbd6bd9167f | 4993 | |
mkarlsso | 0:8dbd6bd9167f | 4994 | std::size_t foundItem = expression.find("&&"); |
mkarlsso | 0:8dbd6bd9167f | 4995 | while (foundItem != std::string::npos) { |
mkarlsso | 0:8dbd6bd9167f | 4996 | if (isOutsideParenth(expression,foundItem)){ |
mkarlsso | 0:8dbd6bd9167f | 4997 | break; |
mkarlsso | 0:8dbd6bd9167f | 4998 | } |
mkarlsso | 0:8dbd6bd9167f | 4999 | foundItem = expression.find("&&",foundItem+1); |
mkarlsso | 0:8dbd6bd9167f | 5000 | } |
mkarlsso | 0:8dbd6bd9167f | 5001 | return foundItem; |
mkarlsso | 0:8dbd6bd9167f | 5002 | } |
mkarlsso | 0:8dbd6bd9167f | 5003 | |
mkarlsso | 0:8dbd6bd9167f | 5004 | condition* scriptStream::parseConditions(string& expression) { |
mkarlsso | 0:8dbd6bd9167f | 5005 | //This function is used to parse a condition string |
mkarlsso | 0:8dbd6bd9167f | 5006 | //such as (x < y && x != z) || (y == 2) |
mkarlsso | 0:8dbd6bd9167f | 5007 | //This function first identifies the root node of the logic tree |
mkarlsso | 0:8dbd6bd9167f | 5008 | //based on operator precedence ( () > && > || ), and then recursively calls itself |
mkarlsso | 0:8dbd6bd9167f | 5009 | //to find the nodes of the branches. The basic building blocks of |
mkarlsso | 0:8dbd6bd9167f | 5010 | //the final condition object are arithmatic comparitors (a > b) and |
mkarlsso | 0:8dbd6bd9167f | 5011 | //other condition objects. |
mkarlsso | 0:8dbd6bd9167f | 5012 | |
mkarlsso | 0:8dbd6bd9167f | 5013 | |
mkarlsso | 0:8dbd6bd9167f | 5014 | |
mkarlsso | 0:8dbd6bd9167f | 5015 | condition* newCondition = NULL; |
mkarlsso | 0:8dbd6bd9167f | 5016 | bool singleCondition = false; //no compound conditions |
mkarlsso | 0:8dbd6bd9167f | 5017 | string afterComparator; |
mkarlsso | 0:8dbd6bd9167f | 5018 | string beforeComparator; |
mkarlsso | 0:8dbd6bd9167f | 5019 | |
mkarlsso | 0:8dbd6bd9167f | 5020 | std::size_t found; |
mkarlsso | 0:8dbd6bd9167f | 5021 | |
mkarlsso | 0:8dbd6bd9167f | 5022 | //To make a parse tree, we start by looking for operators with the lowest precendence |
mkarlsso | 0:8dbd6bd9167f | 5023 | //so we look for OR conditions first |
mkarlsso | 0:8dbd6bd9167f | 5024 | char currentOperator = OR_CONDITION; |
mkarlsso | 0:8dbd6bd9167f | 5025 | |
mkarlsso | 0:8dbd6bd9167f | 5026 | found = findFirstOrOutsideParenth(expression); |
mkarlsso | 0:8dbd6bd9167f | 5027 | if (found==std::string::npos) { //no or conditions outside parentheses found, so we look for AND conditions |
mkarlsso | 0:8dbd6bd9167f | 5028 | currentOperator = AND_CONDITION; |
mkarlsso | 0:8dbd6bd9167f | 5029 | |
mkarlsso | 0:8dbd6bd9167f | 5030 | found = findFirstAndOutsideParenth(expression); |
mkarlsso | 0:8dbd6bd9167f | 5031 | } |
mkarlsso | 0:8dbd6bd9167f | 5032 | if (found==std::string::npos) { //no or/and conditions outside parentheses found |
mkarlsso | 0:8dbd6bd9167f | 5033 | //if the expression is encapsulated in parentheses, remove the parentheses |
mkarlsso | 0:8dbd6bd9167f | 5034 | bool removedParenth = false; |
mkarlsso | 0:8dbd6bd9167f | 5035 | if ((expression[0] == '(') && (expression[expression.length()-1] == ')')) { |
mkarlsso | 0:8dbd6bd9167f | 5036 | |
mkarlsso | 0:8dbd6bd9167f | 5037 | expression = expression.substr(1,expression.length()-2); |
mkarlsso | 0:8dbd6bd9167f | 5038 | removedParenth = true; |
mkarlsso | 0:8dbd6bd9167f | 5039 | } |
mkarlsso | 0:8dbd6bd9167f | 5040 | if (removedParenth) { //we removed parentheses, so try again |
mkarlsso | 0:8dbd6bd9167f | 5041 | textDisplay.debug("Condition: parenth removed\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 5042 | return parseConditions(expression); |
mkarlsso | 0:8dbd6bd9167f | 5043 | } else { |
mkarlsso | 0:8dbd6bd9167f | 5044 | singleCondition = true; //we assume that the condition is non-compound, i.e., a>b |
mkarlsso | 0:8dbd6bd9167f | 5045 | } |
mkarlsso | 0:8dbd6bd9167f | 5046 | } |
mkarlsso | 0:8dbd6bd9167f | 5047 | |
mkarlsso | 0:8dbd6bd9167f | 5048 | if (singleCondition) { //no compound conditions found |
mkarlsso | 0:8dbd6bd9167f | 5049 | textDisplay.debug("Single condition: "); |
mkarlsso | 0:8dbd6bd9167f | 5050 | std::size_t equalStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5051 | std::size_t greaterOrEqualStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5052 | std::size_t lessThanOrEqualStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5053 | std::size_t notEqualStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5054 | std::size_t greaterThanStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5055 | std::size_t lessThanStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5056 | std::size_t generalCompareStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5057 | |
mkarlsso | 0:8dbd6bd9167f | 5058 | |
mkarlsso | 0:8dbd6bd9167f | 5059 | string tmpCondition = expression; |
mkarlsso | 0:8dbd6bd9167f | 5060 | string compareString; |
mkarlsso | 0:8dbd6bd9167f | 5061 | //The expression might have up to three variables |
mkarlsso | 0:8dbd6bd9167f | 5062 | int* tmpVar; |
mkarlsso | 0:8dbd6bd9167f | 5063 | int* tmpVar2; |
mkarlsso | 0:8dbd6bd9167f | 5064 | int* tmpVar3; |
mkarlsso | 0:8dbd6bd9167f | 5065 | |
mkarlsso | 0:8dbd6bd9167f | 5066 | int offset = 0; |
mkarlsso | 0:8dbd6bd9167f | 5067 | equalStringInd = tmpCondition.find("=="); //location of comparator |
mkarlsso | 0:8dbd6bd9167f | 5068 | greaterOrEqualStringInd = tmpCondition.find(">="); //location of comparator |
mkarlsso | 0:8dbd6bd9167f | 5069 | lessThanOrEqualStringInd = tmpCondition.find("<="); //location of comparator |
mkarlsso | 0:8dbd6bd9167f | 5070 | notEqualStringInd = tmpCondition.find("!="); //location of comparator |
mkarlsso | 0:8dbd6bd9167f | 5071 | greaterThanStringInd = tmpCondition.find_first_of(">"); //location of comparator |
mkarlsso | 0:8dbd6bd9167f | 5072 | lessThanStringInd = tmpCondition.find_first_of("<"); //location of comparator |
mkarlsso | 0:8dbd6bd9167f | 5073 | |
mkarlsso | 0:8dbd6bd9167f | 5074 | if ((equalStringInd != std::string::npos) && (greaterOrEqualStringInd == std::string::npos) && |
mkarlsso | 0:8dbd6bd9167f | 5075 | (lessThanOrEqualStringInd == std::string::npos) && (notEqualStringInd == std::string::npos)){ |
mkarlsso | 0:8dbd6bd9167f | 5076 | |
mkarlsso | 0:8dbd6bd9167f | 5077 | generalCompareStringInd = equalStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5078 | compareString = "=="; |
mkarlsso | 0:8dbd6bd9167f | 5079 | textDisplay.debug("==\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 5080 | } else if ((equalStringInd == std::string::npos) && (greaterOrEqualStringInd != std::string::npos) && |
mkarlsso | 0:8dbd6bd9167f | 5081 | (lessThanOrEqualStringInd == std::string::npos) && (notEqualStringInd == std::string::npos)){ |
mkarlsso | 0:8dbd6bd9167f | 5082 | |
mkarlsso | 0:8dbd6bd9167f | 5083 | generalCompareStringInd = greaterOrEqualStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5084 | compareString = ">="; |
mkarlsso | 0:8dbd6bd9167f | 5085 | textDisplay.debug(">=\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 5086 | } else if ((equalStringInd == std::string::npos) && (greaterOrEqualStringInd == std::string::npos) && |
mkarlsso | 0:8dbd6bd9167f | 5087 | (lessThanOrEqualStringInd != std::string::npos) && (notEqualStringInd == std::string::npos)){ |
mkarlsso | 0:8dbd6bd9167f | 5088 | |
mkarlsso | 0:8dbd6bd9167f | 5089 | generalCompareStringInd = lessThanOrEqualStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5090 | compareString = "<="; |
mkarlsso | 0:8dbd6bd9167f | 5091 | textDisplay.debug("<=\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 5092 | } else if ((equalStringInd == std::string::npos) && (greaterOrEqualStringInd == std::string::npos) && |
mkarlsso | 0:8dbd6bd9167f | 5093 | (lessThanOrEqualStringInd == std::string::npos) && (notEqualStringInd != std::string::npos)){ |
mkarlsso | 0:8dbd6bd9167f | 5094 | |
mkarlsso | 0:8dbd6bd9167f | 5095 | generalCompareStringInd = notEqualStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5096 | compareString = "!="; |
mkarlsso | 0:8dbd6bd9167f | 5097 | textDisplay.debug("!=\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 5098 | } else if ((equalStringInd == std::string::npos) && (greaterOrEqualStringInd == std::string::npos) && |
mkarlsso | 0:8dbd6bd9167f | 5099 | (lessThanOrEqualStringInd == std::string::npos) && (notEqualStringInd == std::string::npos) && |
mkarlsso | 0:8dbd6bd9167f | 5100 | (greaterThanStringInd != std::string::npos) && (lessThanStringInd == std::string::npos)){ |
mkarlsso | 0:8dbd6bd9167f | 5101 | |
mkarlsso | 0:8dbd6bd9167f | 5102 | generalCompareStringInd = greaterThanStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5103 | compareString = ">"; |
mkarlsso | 0:8dbd6bd9167f | 5104 | offset = 1; |
mkarlsso | 0:8dbd6bd9167f | 5105 | textDisplay.debug(">\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 5106 | } else if ((equalStringInd == std::string::npos) && (greaterOrEqualStringInd == std::string::npos) && |
mkarlsso | 0:8dbd6bd9167f | 5107 | (lessThanOrEqualStringInd == std::string::npos) && (notEqualStringInd == std::string::npos) && |
mkarlsso | 0:8dbd6bd9167f | 5108 | (greaterThanStringInd == std::string::npos) && (lessThanStringInd != std::string::npos)){ |
mkarlsso | 0:8dbd6bd9167f | 5109 | |
mkarlsso | 0:8dbd6bd9167f | 5110 | generalCompareStringInd = lessThanStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5111 | compareString = "<"; |
mkarlsso | 0:8dbd6bd9167f | 5112 | offset = 1; |
mkarlsso | 0:8dbd6bd9167f | 5113 | textDisplay.debug("<\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 5114 | |
mkarlsso | 0:8dbd6bd9167f | 5115 | }else { |
mkarlsso | 0:8dbd6bd9167f | 5116 | textDisplay << "Condition not understood: " << expression << "\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 5117 | return 0; |
mkarlsso | 0:8dbd6bd9167f | 5118 | } |
mkarlsso | 0:8dbd6bd9167f | 5119 | textDisplay.debug("Allocating memory for condition..."); |
mkarlsso | 0:8dbd6bd9167f | 5120 | intCompare* newCompare = findFirstUnUsed(intCompareBlock, NUMINTCOMPARE); |
mkarlsso | 0:8dbd6bd9167f | 5121 | |
mkarlsso | 0:8dbd6bd9167f | 5122 | if (newCompare == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 5123 | textDisplay << "Error: No memory slots available."; |
mkarlsso | 0:8dbd6bd9167f | 5124 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 5125 | } |
mkarlsso | 0:8dbd6bd9167f | 5126 | newCondition = findFirstUnUsed(conditionBlock, NUMCONDITIONS); |
mkarlsso | 0:8dbd6bd9167f | 5127 | if (newCondition == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 5128 | textDisplay << "Error: No memory slots available."; |
mkarlsso | 0:8dbd6bd9167f | 5129 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 5130 | } |
mkarlsso | 0:8dbd6bd9167f | 5131 | textDisplay.debug("success.\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 5132 | beforeComparator.reserve(tmpCondition.length()); |
mkarlsso | 0:8dbd6bd9167f | 5133 | textDisplay << beforeComparator.capacity(); |
mkarlsso | 0:8dbd6bd9167f | 5134 | textDisplay.flush(); |
mkarlsso | 0:8dbd6bd9167f | 5135 | |
mkarlsso | 0:8dbd6bd9167f | 5136 | afterComparator = tmpCondition.substr(generalCompareStringInd+2-offset,std::string::npos); |
mkarlsso | 0:8dbd6bd9167f | 5137 | |
mkarlsso | 0:8dbd6bd9167f | 5138 | beforeComparator = tmpCondition.substr(0,generalCompareStringInd); |
mkarlsso | 0:8dbd6bd9167f | 5139 | |
mkarlsso | 0:8dbd6bd9167f | 5140 | tmpVar = findIntVariable(beforeComparator); //returns pointer to the variable |
mkarlsso | 0:8dbd6bd9167f | 5141 | if (tmpVar != NULL) { //before the comparator is a single variable |
mkarlsso | 0:8dbd6bd9167f | 5142 | tmpVar2 = findIntVariable(afterComparator); //returns pointer to the variable |
mkarlsso | 0:8dbd6bd9167f | 5143 | if (tmpVar2 != NULL) { //we are comapring a single variable to another |
mkarlsso | 0:8dbd6bd9167f | 5144 | //intCompare* newCompare = new intCompare(tmpVar,compareString.data(),tmpVar2); |
mkarlsso | 0:8dbd6bd9167f | 5145 | //currentEvent->addCondition(new condition(newCompare)); |
mkarlsso | 0:8dbd6bd9167f | 5146 | textDisplay.debug("Compare variable to variable\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 5147 | newCompare->set(tmpVar,compareString.data(),tmpVar2); |
mkarlsso | 0:8dbd6bd9167f | 5148 | newCondition->set(newCompare); |
mkarlsso | 0:8dbd6bd9167f | 5149 | |
mkarlsso | 0:8dbd6bd9167f | 5150 | |
mkarlsso | 0:8dbd6bd9167f | 5151 | } else if (isNumber(afterComparator)) { |
mkarlsso | 0:8dbd6bd9167f | 5152 | //intCompare* newCompare = new intCompare(tmpVar,compareString.data(),atoi(afterComparator.data())); |
mkarlsso | 0:8dbd6bd9167f | 5153 | //currentEvent->addCondition(new condition(newCompare)); |
mkarlsso | 0:8dbd6bd9167f | 5154 | textDisplay.debug("Compare variable to number\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 5155 | newCompare->set(tmpVar,compareString.data(),atoi(afterComparator.data())); |
mkarlsso | 0:8dbd6bd9167f | 5156 | newCondition->set(newCompare); |
mkarlsso | 0:8dbd6bd9167f | 5157 | |
mkarlsso | 0:8dbd6bd9167f | 5158 | |
mkarlsso | 0:8dbd6bd9167f | 5159 | } //more here |
mkarlsso | 0:8dbd6bd9167f | 5160 | |
mkarlsso | 0:8dbd6bd9167f | 5161 | } else { |
mkarlsso | 0:8dbd6bd9167f | 5162 | textDisplay << "Condition not understood: " << expression << "\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 5163 | |
mkarlsso | 0:8dbd6bd9167f | 5164 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 5165 | } |
mkarlsso | 0:8dbd6bd9167f | 5166 | |
mkarlsso | 0:8dbd6bd9167f | 5167 | } else { //this is a compound condition (with either && or ||) |
mkarlsso | 0:8dbd6bd9167f | 5168 | textDisplay.debug("Compound condition\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 5169 | afterComparator = expression.substr(found+2,std::string::npos); |
mkarlsso | 0:8dbd6bd9167f | 5170 | beforeComparator = expression.substr(0,found); |
mkarlsso | 0:8dbd6bd9167f | 5171 | newCondition = findFirstUnUsed(conditionBlock, NUMCONDITIONS); |
mkarlsso | 0:8dbd6bd9167f | 5172 | if (newCondition == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 5173 | textDisplay << "Error: No memory slots available."; |
mkarlsso | 0:8dbd6bd9167f | 5174 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 5175 | } else { |
mkarlsso | 0:8dbd6bd9167f | 5176 | newCondition->isUsed = true; //reserve the condition slot; |
mkarlsso | 0:8dbd6bd9167f | 5177 | } |
mkarlsso | 0:8dbd6bd9167f | 5178 | //recursively call this function to parse the sub conditions |
mkarlsso | 0:8dbd6bd9167f | 5179 | condition* cond1 = parseConditions(beforeComparator); |
mkarlsso | 0:8dbd6bd9167f | 5180 | if (cond1 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 5181 | newCondition->release(); |
mkarlsso | 0:8dbd6bd9167f | 5182 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 5183 | } |
mkarlsso | 0:8dbd6bd9167f | 5184 | condition* cond2 = parseConditions(afterComparator); |
mkarlsso | 0:8dbd6bd9167f | 5185 | if (cond2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 5186 | newCondition->release(); |
mkarlsso | 0:8dbd6bd9167f | 5187 | cond1->release(); |
mkarlsso | 0:8dbd6bd9167f | 5188 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 5189 | } |
mkarlsso | 0:8dbd6bd9167f | 5190 | newCondition->set(cond1,currentOperator, cond2); |
mkarlsso | 0:8dbd6bd9167f | 5191 | |
mkarlsso | 0:8dbd6bd9167f | 5192 | } |
mkarlsso | 0:8dbd6bd9167f | 5193 | |
mkarlsso | 0:8dbd6bd9167f | 5194 | return newCondition; //all went well, so return the newly made condition |
mkarlsso | 0:8dbd6bd9167f | 5195 | |
mkarlsso | 0:8dbd6bd9167f | 5196 | }*/ |
mkarlsso | 0:8dbd6bd9167f | 5197 | |
mkarlsso | 0:8dbd6bd9167f | 5198 | |
mkarlsso | 0:8dbd6bd9167f | 5199 | bool scriptStream::isOutsideParenth(const char* expression,int foundItem,int start, int end) { |
mkarlsso | 0:8dbd6bd9167f | 5200 | |
mkarlsso | 0:8dbd6bd9167f | 5201 | int pDepth = 0; // How many nested parentheses |
mkarlsso | 0:8dbd6bd9167f | 5202 | |
mkarlsso | 0:8dbd6bd9167f | 5203 | if ((foundItem >= start)&&(foundItem<=end)&&(foundItem < strlen(expression))&&(end < strlen(expression))&&(start <= end)&&(start>=0)) { |
mkarlsso | 0:8dbd6bd9167f | 5204 | for (int i = start; i <= foundItem; i++) { |
mkarlsso | 0:8dbd6bd9167f | 5205 | if (expression[i] == '(') { |
mkarlsso | 0:8dbd6bd9167f | 5206 | pDepth++; |
mkarlsso | 0:8dbd6bd9167f | 5207 | } else if (expression[i] == ')') { |
mkarlsso | 0:8dbd6bd9167f | 5208 | pDepth--; |
mkarlsso | 0:8dbd6bd9167f | 5209 | } |
mkarlsso | 0:8dbd6bd9167f | 5210 | } |
mkarlsso | 0:8dbd6bd9167f | 5211 | if (pDepth<=0) { |
mkarlsso | 0:8dbd6bd9167f | 5212 | |
mkarlsso | 0:8dbd6bd9167f | 5213 | return true; |
mkarlsso | 0:8dbd6bd9167f | 5214 | } else { |
mkarlsso | 0:8dbd6bd9167f | 5215 | |
mkarlsso | 0:8dbd6bd9167f | 5216 | return false; |
mkarlsso | 0:8dbd6bd9167f | 5217 | } |
mkarlsso | 0:8dbd6bd9167f | 5218 | } else { |
mkarlsso | 0:8dbd6bd9167f | 5219 | //error handling defaults in a true condition |
mkarlsso | 0:8dbd6bd9167f | 5220 | return true; |
mkarlsso | 0:8dbd6bd9167f | 5221 | } |
mkarlsso | 0:8dbd6bd9167f | 5222 | |
mkarlsso | 0:8dbd6bd9167f | 5223 | } |
mkarlsso | 0:8dbd6bd9167f | 5224 | |
mkarlsso | 0:8dbd6bd9167f | 5225 | int scriptStream::findFirstOrOutsideParenth(const char* expression,int start, int end) { |
mkarlsso | 0:8dbd6bd9167f | 5226 | |
mkarlsso | 0:8dbd6bd9167f | 5227 | int foundItem = findStringLoc(expression,"||",start,end); |
mkarlsso | 0:8dbd6bd9167f | 5228 | while (foundItem != -1) { |
mkarlsso | 0:8dbd6bd9167f | 5229 | if (isOutsideParenth(expression,foundItem,start,end)) { |
mkarlsso | 0:8dbd6bd9167f | 5230 | //it's out side of () |
mkarlsso | 0:8dbd6bd9167f | 5231 | break; |
mkarlsso | 0:8dbd6bd9167f | 5232 | } |
mkarlsso | 0:8dbd6bd9167f | 5233 | //not outside () |
mkarlsso | 0:8dbd6bd9167f | 5234 | foundItem = findStringLoc(expression,"||",foundItem+1,end); |
mkarlsso | 0:8dbd6bd9167f | 5235 | } |
mkarlsso | 0:8dbd6bd9167f | 5236 | return foundItem; |
mkarlsso | 0:8dbd6bd9167f | 5237 | } |
mkarlsso | 0:8dbd6bd9167f | 5238 | |
mkarlsso | 0:8dbd6bd9167f | 5239 | int scriptStream::findFirstAndOutsideParenth(const char* expression,int start, int end) { |
mkarlsso | 0:8dbd6bd9167f | 5240 | |
mkarlsso | 0:8dbd6bd9167f | 5241 | int foundItem = findStringLoc(expression,"&&",start,end); |
mkarlsso | 0:8dbd6bd9167f | 5242 | while (foundItem != -1) { |
mkarlsso | 0:8dbd6bd9167f | 5243 | if (isOutsideParenth(expression,foundItem,start,end)){ |
mkarlsso | 0:8dbd6bd9167f | 5244 | break; |
mkarlsso | 0:8dbd6bd9167f | 5245 | } |
mkarlsso | 0:8dbd6bd9167f | 5246 | foundItem = findStringLoc(expression,"||",foundItem+1,end); |
mkarlsso | 0:8dbd6bd9167f | 5247 | } |
mkarlsso | 0:8dbd6bd9167f | 5248 | return foundItem; |
mkarlsso | 0:8dbd6bd9167f | 5249 | } |
mkarlsso | 0:8dbd6bd9167f | 5250 | |
mkarlsso | 0:8dbd6bd9167f | 5251 | |
mkarlsso | 0:8dbd6bd9167f | 5252 | condition* scriptStream::parseConditions(const char* expression,int start, int end) { |
mkarlsso | 0:8dbd6bd9167f | 5253 | |
mkarlsso | 0:8dbd6bd9167f | 5254 | |
mkarlsso | 0:8dbd6bd9167f | 5255 | //This function is used to parse a condition string |
mkarlsso | 0:8dbd6bd9167f | 5256 | //such as (x < y && x != z) || (y == 2) |
mkarlsso | 0:8dbd6bd9167f | 5257 | //This function first identifies the root node of the logic tree |
mkarlsso | 0:8dbd6bd9167f | 5258 | //based on operator precedence ( () > && > || ), and then recursively calls itself |
mkarlsso | 0:8dbd6bd9167f | 5259 | //to find the nodes of the branches. The basic building blocks of |
mkarlsso | 0:8dbd6bd9167f | 5260 | //the final condition object are arithmatic comparitors (a > b) and |
mkarlsso | 0:8dbd6bd9167f | 5261 | //other condition objects. |
mkarlsso | 0:8dbd6bd9167f | 5262 | |
mkarlsso | 0:8dbd6bd9167f | 5263 | |
mkarlsso | 0:8dbd6bd9167f | 5264 | |
mkarlsso | 0:8dbd6bd9167f | 5265 | condition* newCondition = NULL; |
mkarlsso | 0:8dbd6bd9167f | 5266 | bool singleCondition = false; //no compound conditions |
mkarlsso | 0:8dbd6bd9167f | 5267 | //string afterComparator; |
mkarlsso | 0:8dbd6bd9167f | 5268 | //string beforeComparator; |
mkarlsso | 0:8dbd6bd9167f | 5269 | int afterComparatorLoc; |
mkarlsso | 0:8dbd6bd9167f | 5270 | int beforeComparatorLoc; |
mkarlsso | 0:8dbd6bd9167f | 5271 | |
mkarlsso | 0:8dbd6bd9167f | 5272 | |
mkarlsso | 0:8dbd6bd9167f | 5273 | |
mkarlsso | 0:8dbd6bd9167f | 5274 | int found; |
mkarlsso | 0:8dbd6bd9167f | 5275 | |
mkarlsso | 0:8dbd6bd9167f | 5276 | //To make a parse tree, we start by looking for operators with the lowest precendence |
mkarlsso | 0:8dbd6bd9167f | 5277 | //so we look for OR conditions first |
mkarlsso | 0:8dbd6bd9167f | 5278 | char currentOperator = OR_CONDITION; |
mkarlsso | 0:8dbd6bd9167f | 5279 | |
mkarlsso | 0:8dbd6bd9167f | 5280 | found = findFirstOrOutsideParenth(expression,start,end); |
mkarlsso | 0:8dbd6bd9167f | 5281 | if (found==-1) { //no or conditions outside parentheses found, so we look for AND conditions |
mkarlsso | 0:8dbd6bd9167f | 5282 | currentOperator = AND_CONDITION; |
mkarlsso | 0:8dbd6bd9167f | 5283 | |
mkarlsso | 0:8dbd6bd9167f | 5284 | found = findFirstAndOutsideParenth(expression,start,end); |
mkarlsso | 0:8dbd6bd9167f | 5285 | } |
mkarlsso | 0:8dbd6bd9167f | 5286 | if (found==-1) { //no or/and conditions outside parentheses found |
mkarlsso | 0:8dbd6bd9167f | 5287 | //if the expression is encapsulated in parentheses, remove the parentheses |
mkarlsso | 0:8dbd6bd9167f | 5288 | bool removedParenth = false; |
mkarlsso | 0:8dbd6bd9167f | 5289 | if ((expression[start] == '(') && (expression[end] == ')')) { |
mkarlsso | 0:8dbd6bd9167f | 5290 | |
mkarlsso | 0:8dbd6bd9167f | 5291 | start++; |
mkarlsso | 0:8dbd6bd9167f | 5292 | end--; |
mkarlsso | 0:8dbd6bd9167f | 5293 | |
mkarlsso | 0:8dbd6bd9167f | 5294 | //expression = expression.substr(1,expression.length()-2); |
mkarlsso | 0:8dbd6bd9167f | 5295 | removedParenth = true; |
mkarlsso | 0:8dbd6bd9167f | 5296 | } |
mkarlsso | 0:8dbd6bd9167f | 5297 | if (removedParenth) { //we removed parentheses, so try again |
mkarlsso | 0:8dbd6bd9167f | 5298 | textDisplay.debug("Condition: parenth removed\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 5299 | return parseConditions(expression,start,end); |
mkarlsso | 0:8dbd6bd9167f | 5300 | } else { |
mkarlsso | 0:8dbd6bd9167f | 5301 | singleCondition = true; //we assume that the condition is non-compound, i.e., a>b |
mkarlsso | 0:8dbd6bd9167f | 5302 | } |
mkarlsso | 0:8dbd6bd9167f | 5303 | } |
mkarlsso | 0:8dbd6bd9167f | 5304 | |
mkarlsso | 0:8dbd6bd9167f | 5305 | if (singleCondition) { //no compound conditions found |
mkarlsso | 0:8dbd6bd9167f | 5306 | textDisplay.debug("Single condition: "); |
mkarlsso | 0:8dbd6bd9167f | 5307 | int equalStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5308 | int greaterOrEqualStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5309 | int lessThanOrEqualStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5310 | int notEqualStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5311 | int greaterThanStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5312 | int lessThanStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5313 | int generalCompareStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5314 | |
mkarlsso | 0:8dbd6bd9167f | 5315 | |
mkarlsso | 0:8dbd6bd9167f | 5316 | //string tmpCondition = expression; |
mkarlsso | 0:8dbd6bd9167f | 5317 | char compareString[3]; |
mkarlsso | 0:8dbd6bd9167f | 5318 | //The expression might have up to three variables |
mkarlsso | 0:8dbd6bd9167f | 5319 | int* tmpVar; |
mkarlsso | 0:8dbd6bd9167f | 5320 | int* tmpVar2; |
mkarlsso | 0:8dbd6bd9167f | 5321 | //int* tmpVar3; |
mkarlsso | 0:8dbd6bd9167f | 5322 | |
mkarlsso | 0:8dbd6bd9167f | 5323 | int offset = 0; |
mkarlsso | 0:8dbd6bd9167f | 5324 | equalStringInd = findStringLoc(expression,"==",start,end); //location of comparator |
mkarlsso | 0:8dbd6bd9167f | 5325 | greaterOrEqualStringInd = findStringLoc(expression,">=",start,end); //location of comparator |
mkarlsso | 0:8dbd6bd9167f | 5326 | lessThanOrEqualStringInd = findStringLoc(expression,"<=",start,end); //location of comparator |
mkarlsso | 0:8dbd6bd9167f | 5327 | notEqualStringInd = findStringLoc(expression,"!=",start,end); //location of comparator |
mkarlsso | 0:8dbd6bd9167f | 5328 | greaterThanStringInd = findStringLoc(expression,">",start,end); //location of comparator |
mkarlsso | 0:8dbd6bd9167f | 5329 | lessThanStringInd = findStringLoc(expression,"<",start,end); //location of comparator |
mkarlsso | 0:8dbd6bd9167f | 5330 | |
mkarlsso | 0:8dbd6bd9167f | 5331 | if ((equalStringInd != -1) && (greaterOrEqualStringInd == -1) && |
mkarlsso | 0:8dbd6bd9167f | 5332 | (lessThanOrEqualStringInd == -1) && (notEqualStringInd == -1)){ |
mkarlsso | 0:8dbd6bd9167f | 5333 | |
mkarlsso | 0:8dbd6bd9167f | 5334 | generalCompareStringInd = equalStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5335 | strcpy(compareString,"=="); |
mkarlsso | 0:8dbd6bd9167f | 5336 | //compareString = "=="; |
mkarlsso | 0:8dbd6bd9167f | 5337 | textDisplay.debug("==\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 5338 | } else if ((equalStringInd == -1) && (greaterOrEqualStringInd != -1) && |
mkarlsso | 0:8dbd6bd9167f | 5339 | (lessThanOrEqualStringInd == -1) && (notEqualStringInd == -1)){ |
mkarlsso | 0:8dbd6bd9167f | 5340 | |
mkarlsso | 0:8dbd6bd9167f | 5341 | generalCompareStringInd = greaterOrEqualStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5342 | strcpy(compareString,">="); |
mkarlsso | 0:8dbd6bd9167f | 5343 | //compareString = ">="; |
mkarlsso | 0:8dbd6bd9167f | 5344 | textDisplay.debug(">=\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 5345 | } else if ((equalStringInd == -1) && (greaterOrEqualStringInd == -1) && |
mkarlsso | 0:8dbd6bd9167f | 5346 | (lessThanOrEqualStringInd != -1) && (notEqualStringInd == -1)){ |
mkarlsso | 0:8dbd6bd9167f | 5347 | |
mkarlsso | 0:8dbd6bd9167f | 5348 | generalCompareStringInd = lessThanOrEqualStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5349 | strcpy(compareString,"<="); |
mkarlsso | 0:8dbd6bd9167f | 5350 | //compareString = "<="; |
mkarlsso | 0:8dbd6bd9167f | 5351 | textDisplay.debug("<=\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 5352 | } else if ((equalStringInd == -1) && (greaterOrEqualStringInd == -1) && |
mkarlsso | 0:8dbd6bd9167f | 5353 | (lessThanOrEqualStringInd == -1) && (notEqualStringInd != -1)){ |
mkarlsso | 0:8dbd6bd9167f | 5354 | |
mkarlsso | 0:8dbd6bd9167f | 5355 | generalCompareStringInd = notEqualStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5356 | strcpy(compareString,"!="); |
mkarlsso | 0:8dbd6bd9167f | 5357 | //compareString = "!="; |
mkarlsso | 0:8dbd6bd9167f | 5358 | textDisplay.debug("!=\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 5359 | } else if ((equalStringInd == -1) && (greaterOrEqualStringInd == -1) && |
mkarlsso | 0:8dbd6bd9167f | 5360 | (lessThanOrEqualStringInd == -1) && (notEqualStringInd == -1) && |
mkarlsso | 0:8dbd6bd9167f | 5361 | (greaterThanStringInd != -1) && (lessThanStringInd == -1)){ |
mkarlsso | 0:8dbd6bd9167f | 5362 | |
mkarlsso | 0:8dbd6bd9167f | 5363 | generalCompareStringInd = greaterThanStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5364 | strcpy(compareString,">"); |
mkarlsso | 0:8dbd6bd9167f | 5365 | //compareString = ">"; |
mkarlsso | 0:8dbd6bd9167f | 5366 | offset = 1; |
mkarlsso | 0:8dbd6bd9167f | 5367 | textDisplay.debug(">\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 5368 | } else if ((equalStringInd == -1) && (greaterOrEqualStringInd == -1) && |
mkarlsso | 0:8dbd6bd9167f | 5369 | (lessThanOrEqualStringInd == -1) && (notEqualStringInd == -1) && |
mkarlsso | 0:8dbd6bd9167f | 5370 | (greaterThanStringInd == -1) && (lessThanStringInd != -1)){ |
mkarlsso | 0:8dbd6bd9167f | 5371 | |
mkarlsso | 0:8dbd6bd9167f | 5372 | generalCompareStringInd = lessThanStringInd; |
mkarlsso | 0:8dbd6bd9167f | 5373 | strcpy(compareString,"<"); |
mkarlsso | 0:8dbd6bd9167f | 5374 | //compareString = "<"; |
mkarlsso | 0:8dbd6bd9167f | 5375 | offset = 1; |
mkarlsso | 0:8dbd6bd9167f | 5376 | textDisplay.debug("<\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 5377 | |
mkarlsso | 0:8dbd6bd9167f | 5378 | }else { |
mkarlsso | 0:8dbd6bd9167f | 5379 | textDisplay << "Condition not understood: " << expression << "\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 5380 | return 0; |
mkarlsso | 0:8dbd6bd9167f | 5381 | } |
mkarlsso | 0:8dbd6bd9167f | 5382 | textDisplay.debug("Allocating memory for condition..."); |
mkarlsso | 0:8dbd6bd9167f | 5383 | intCompare* newCompare = findFirstUnUsed(intCompareBlock, NUMINTCOMPARE); |
mkarlsso | 0:8dbd6bd9167f | 5384 | |
mkarlsso | 0:8dbd6bd9167f | 5385 | if (newCompare == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 5386 | textDisplay << "Error: No memory slots available."; |
mkarlsso | 0:8dbd6bd9167f | 5387 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 5388 | } |
mkarlsso | 0:8dbd6bd9167f | 5389 | newCondition = findFirstUnUsed(conditionBlock, NUMCONDITIONS); |
mkarlsso | 0:8dbd6bd9167f | 5390 | if (newCondition == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 5391 | textDisplay << "Error: No memory slots available."; |
mkarlsso | 0:8dbd6bd9167f | 5392 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 5393 | } |
mkarlsso | 0:8dbd6bd9167f | 5394 | textDisplay.debug("success.\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 5395 | //beforeComparator.reserve(tmpCondition.length()); |
mkarlsso | 0:8dbd6bd9167f | 5396 | //textDisplay << beforeComparator.capacity(); |
mkarlsso | 0:8dbd6bd9167f | 5397 | //textDisplay.flush(); |
mkarlsso | 0:8dbd6bd9167f | 5398 | |
mkarlsso | 0:8dbd6bd9167f | 5399 | afterComparatorLoc = generalCompareStringInd+2-offset; |
mkarlsso | 0:8dbd6bd9167f | 5400 | beforeComparatorLoc = generalCompareStringInd-1; |
mkarlsso | 0:8dbd6bd9167f | 5401 | |
mkarlsso | 0:8dbd6bd9167f | 5402 | //afterComparator = tmpCondition.substr(generalCompareStringInd+2-offset,std::string::npos); |
mkarlsso | 0:8dbd6bd9167f | 5403 | //beforeComparator = tmpCondition.substr(0,generalCompareStringInd); |
mkarlsso | 0:8dbd6bd9167f | 5404 | |
mkarlsso | 0:8dbd6bd9167f | 5405 | //tmpVar = findIntVariable(beforeComparator); //returns pointer to the variable |
mkarlsso | 0:8dbd6bd9167f | 5406 | tmpVar = findIntVariable(expression,start,beforeComparatorLoc); |
mkarlsso | 0:8dbd6bd9167f | 5407 | |
mkarlsso | 0:8dbd6bd9167f | 5408 | if (tmpVar != NULL) { //before the comparator is a single variable |
mkarlsso | 0:8dbd6bd9167f | 5409 | tmpVar2 = findIntVariable(expression, afterComparatorLoc, end); //returns pointer to the variable |
mkarlsso | 0:8dbd6bd9167f | 5410 | if (tmpVar2 != NULL) { //we are comapring a single variable to another |
mkarlsso | 0:8dbd6bd9167f | 5411 | //intCompare* newCompare = new intCompare(tmpVar,compareString.data(),tmpVar2); |
mkarlsso | 0:8dbd6bd9167f | 5412 | //currentEvent->addCondition(new condition(newCompare)); |
mkarlsso | 0:8dbd6bd9167f | 5413 | textDisplay.debug("Compare variable to variable\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 5414 | newCompare->set(tmpVar,compareString,tmpVar2); |
mkarlsso | 0:8dbd6bd9167f | 5415 | newCondition->set(newCompare); |
mkarlsso | 0:8dbd6bd9167f | 5416 | |
mkarlsso | 0:8dbd6bd9167f | 5417 | |
mkarlsso | 0:8dbd6bd9167f | 5418 | } else if (isNum(expression, afterComparatorLoc, end)) { |
mkarlsso | 0:8dbd6bd9167f | 5419 | //intCompare* newCompare = new intCompare(tmpVar,compareString.data(),atoi(afterComparator.data())); |
mkarlsso | 0:8dbd6bd9167f | 5420 | //currentEvent->addCondition(new condition(newCompare)); |
mkarlsso | 0:8dbd6bd9167f | 5421 | textDisplay.debug("Compare variable to number\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 5422 | newCompare->set(tmpVar,compareString,atoi(expression+afterComparatorLoc)); |
mkarlsso | 0:8dbd6bd9167f | 5423 | newCondition->set(newCompare); |
mkarlsso | 0:8dbd6bd9167f | 5424 | |
mkarlsso | 0:8dbd6bd9167f | 5425 | |
mkarlsso | 0:8dbd6bd9167f | 5426 | } else { |
mkarlsso | 0:8dbd6bd9167f | 5427 | textDisplay << "Condition not understood: " << expression << "\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 5428 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 5429 | }//more here |
mkarlsso | 0:8dbd6bd9167f | 5430 | |
mkarlsso | 0:8dbd6bd9167f | 5431 | } else { |
mkarlsso | 0:8dbd6bd9167f | 5432 | textDisplay << "Condition not understood: " << expression << "\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 5433 | |
mkarlsso | 0:8dbd6bd9167f | 5434 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 5435 | } |
mkarlsso | 0:8dbd6bd9167f | 5436 | |
mkarlsso | 0:8dbd6bd9167f | 5437 | } else { //this is a compound condition (with either && or ||) |
mkarlsso | 0:8dbd6bd9167f | 5438 | textDisplay.debug("Compound condition\r\n"); |
mkarlsso | 0:8dbd6bd9167f | 5439 | afterComparatorLoc = found+2; |
mkarlsso | 0:8dbd6bd9167f | 5440 | beforeComparatorLoc = found-1; |
mkarlsso | 0:8dbd6bd9167f | 5441 | //afterComparator = expression.substr(found+2,std::string::npos); |
mkarlsso | 0:8dbd6bd9167f | 5442 | //beforeComparator = expression.substr(0,found); |
mkarlsso | 0:8dbd6bd9167f | 5443 | newCondition = findFirstUnUsed(conditionBlock, NUMCONDITIONS); |
mkarlsso | 0:8dbd6bd9167f | 5444 | if (newCondition == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 5445 | textDisplay << "Error: No memory slots available."; |
mkarlsso | 0:8dbd6bd9167f | 5446 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 5447 | } else { |
mkarlsso | 0:8dbd6bd9167f | 5448 | newCondition->isUsed = true; //reserve the condition slot; |
mkarlsso | 0:8dbd6bd9167f | 5449 | } |
mkarlsso | 0:8dbd6bd9167f | 5450 | //recursively call this function to parse the sub conditions |
mkarlsso | 0:8dbd6bd9167f | 5451 | condition* cond1 = parseConditions(expression,start,beforeComparatorLoc); |
mkarlsso | 0:8dbd6bd9167f | 5452 | if (cond1 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 5453 | newCondition->release(); |
mkarlsso | 0:8dbd6bd9167f | 5454 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 5455 | } |
mkarlsso | 0:8dbd6bd9167f | 5456 | condition* cond2 = parseConditions(expression,afterComparatorLoc,end); |
mkarlsso | 0:8dbd6bd9167f | 5457 | if (cond2 == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 5458 | newCondition->release(); |
mkarlsso | 0:8dbd6bd9167f | 5459 | cond1->release(); |
mkarlsso | 0:8dbd6bd9167f | 5460 | return NULL; |
mkarlsso | 0:8dbd6bd9167f | 5461 | } |
mkarlsso | 0:8dbd6bd9167f | 5462 | newCondition->set(cond1,currentOperator, cond2); |
mkarlsso | 0:8dbd6bd9167f | 5463 | |
mkarlsso | 0:8dbd6bd9167f | 5464 | } |
mkarlsso | 0:8dbd6bd9167f | 5465 | |
mkarlsso | 0:8dbd6bd9167f | 5466 | return newCondition; //all went well, so return the newly made condition |
mkarlsso | 0:8dbd6bd9167f | 5467 | |
mkarlsso | 0:8dbd6bd9167f | 5468 | |
mkarlsso | 0:8dbd6bd9167f | 5469 | } |
mkarlsso | 0:8dbd6bd9167f | 5470 | |
mkarlsso | 0:8dbd6bd9167f | 5471 | |
mkarlsso | 0:8dbd6bd9167f | 5472 | |
mkarlsso | 0:8dbd6bd9167f | 5473 | |
mkarlsso | 0:8dbd6bd9167f | 5474 | bool scriptStream::evaluateConditions(string& expression, event* currentEvent) { |
mkarlsso | 0:8dbd6bd9167f | 5475 | //calls the function to parse the condition string. The condition pointer is then |
mkarlsso | 0:8dbd6bd9167f | 5476 | //attached to the event |
mkarlsso | 0:8dbd6bd9167f | 5477 | |
mkarlsso | 0:8dbd6bd9167f | 5478 | condition* newCondition = NULL; |
mkarlsso | 0:8dbd6bd9167f | 5479 | //newCondition = parseConditions(expression); |
mkarlsso | 0:8dbd6bd9167f | 5480 | newCondition = parseConditions(expression.data(),0,expression.length()-1); |
mkarlsso | 0:8dbd6bd9167f | 5481 | if (newCondition == NULL) { |
mkarlsso | 0:8dbd6bd9167f | 5482 | return false; |
mkarlsso | 0:8dbd6bd9167f | 5483 | } else { |
mkarlsso | 0:8dbd6bd9167f | 5484 | currentEvent->addCondition(newCondition); |
mkarlsso | 0:8dbd6bd9167f | 5485 | return true; |
mkarlsso | 0:8dbd6bd9167f | 5486 | } |
mkarlsso | 0:8dbd6bd9167f | 5487 | } |
mkarlsso | 0:8dbd6bd9167f | 5488 | |
mkarlsso | 0:8dbd6bd9167f | 5489 | int scriptStream::getRandomParam(const char* expression,int start, int end) { |
mkarlsso | 0:8dbd6bd9167f | 5490 | |
mkarlsso | 0:8dbd6bd9167f | 5491 | int pos1 = findStringLoc(expression,"random(",start,end)+7; |
mkarlsso | 0:8dbd6bd9167f | 5492 | int pos2 = findStringLoc(expression,")",pos1,end); |
mkarlsso | 0:8dbd6bd9167f | 5493 | if (pos2 == -1) { |
mkarlsso | 0:8dbd6bd9167f | 5494 | textDisplay << "Error: bad syntax\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 5495 | return 0; |
mkarlsso | 0:8dbd6bd9167f | 5496 | } |
mkarlsso | 0:8dbd6bd9167f | 5497 | |
mkarlsso | 0:8dbd6bd9167f | 5498 | int highVal = atoi(expression+pos1); |
mkarlsso | 0:8dbd6bd9167f | 5499 | |
mkarlsso | 0:8dbd6bd9167f | 5500 | if ((highVal > 0)) { |
mkarlsso | 0:8dbd6bd9167f | 5501 | return highVal; |
mkarlsso | 0:8dbd6bd9167f | 5502 | } else { |
mkarlsso | 0:8dbd6bd9167f | 5503 | textDisplay << "Error: random parameter must be 1 or more\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 5504 | return 0; |
mkarlsso | 0:8dbd6bd9167f | 5505 | } |
mkarlsso | 0:8dbd6bd9167f | 5506 | } |
mkarlsso | 0:8dbd6bd9167f | 5507 | |
mkarlsso | 0:8dbd6bd9167f | 5508 | int scriptStream::getRandomParam(string expression) { |
mkarlsso | 0:8dbd6bd9167f | 5509 | |
mkarlsso | 0:8dbd6bd9167f | 5510 | int pos1 = expression.find("random(")+7; |
mkarlsso | 0:8dbd6bd9167f | 5511 | int pos2 = expression.find_first_of(")",pos1); |
mkarlsso | 0:8dbd6bd9167f | 5512 | int highVal = atoi(expression.substr(pos1,pos2-pos1).data()); |
mkarlsso | 0:8dbd6bd9167f | 5513 | |
mkarlsso | 0:8dbd6bd9167f | 5514 | if ((highVal > 0)) { |
mkarlsso | 0:8dbd6bd9167f | 5515 | return highVal; |
mkarlsso | 0:8dbd6bd9167f | 5516 | } else { |
mkarlsso | 0:8dbd6bd9167f | 5517 | textDisplay << "Error: random parameter must be 1 or more\r\n"; |
mkarlsso | 0:8dbd6bd9167f | 5518 | return 0; |
mkarlsso | 0:8dbd6bd9167f | 5519 | } |
mkarlsso | 0:8dbd6bd9167f | 5520 | } |
mkarlsso | 0:8dbd6bd9167f | 5521 | |
mkarlsso | 0:8dbd6bd9167f | 5522 | int scriptStream::findStringLoc(const char *refString, const char *findString,int start,int end) { |
mkarlsso | 0:8dbd6bd9167f | 5523 | //look for 'findString' inside 'refString', only considering characters in between 'start' and 'end' |
mkarlsso | 0:8dbd6bd9167f | 5524 | //return -1 if not found |
mkarlsso | 0:8dbd6bd9167f | 5525 | |
mkarlsso | 0:8dbd6bd9167f | 5526 | if ((start < strlen(refString))&&(end < strlen(refString))&&(end >= start)) { |
mkarlsso | 0:8dbd6bd9167f | 5527 | const char* charPtr = strstr(refString+start,findString); |
mkarlsso | 0:8dbd6bd9167f | 5528 | //if found, make sure it was containted within the start and end bounds |
mkarlsso | 0:8dbd6bd9167f | 5529 | if ((charPtr != NULL) && ((int)(charPtr-refString) <= (end-strlen(findString)+1))) { |
mkarlsso | 0:8dbd6bd9167f | 5530 | return (int)(charPtr-refString); |
mkarlsso | 0:8dbd6bd9167f | 5531 | } |
mkarlsso | 0:8dbd6bd9167f | 5532 | } |
mkarlsso | 0:8dbd6bd9167f | 5533 | return -1; |
mkarlsso | 0:8dbd6bd9167f | 5534 | } |
mkarlsso | 0:8dbd6bd9167f | 5535 | |
mkarlsso | 0:8dbd6bd9167f | 5536 | bool scriptStream::isNum(const char *expression, int start, int end) { |
mkarlsso | 0:8dbd6bd9167f | 5537 | |
mkarlsso | 0:8dbd6bd9167f | 5538 | if ((start>0)&&(end<strlen(expression))&&(start<=end)) { |
mkarlsso | 0:8dbd6bd9167f | 5539 | |
mkarlsso | 0:8dbd6bd9167f | 5540 | bool outcome = true; |
mkarlsso | 0:8dbd6bd9167f | 5541 | while (start <= end) { |
mkarlsso | 0:8dbd6bd9167f | 5542 | //look for any digit, or a - sign |
mkarlsso | 0:8dbd6bd9167f | 5543 | if (!((expression[start] >= 45) && (expression[start] <= 57) && (expression[start] != 46) && (expression[start] != 47))) { |
mkarlsso | 0:8dbd6bd9167f | 5544 | outcome = false; |
mkarlsso | 0:8dbd6bd9167f | 5545 | break; |
mkarlsso | 0:8dbd6bd9167f | 5546 | } |
mkarlsso | 0:8dbd6bd9167f | 5547 | start++; |
mkarlsso | 0:8dbd6bd9167f | 5548 | } |
mkarlsso | 0:8dbd6bd9167f | 5549 | return outcome; |
mkarlsso | 0:8dbd6bd9167f | 5550 | } |
mkarlsso | 0:8dbd6bd9167f | 5551 | return false; |
mkarlsso | 0:8dbd6bd9167f | 5552 | } |
mkarlsso | 0:8dbd6bd9167f | 5553 | |
mkarlsso | 0:8dbd6bd9167f | 5554 | bool scriptStream::areStringsSame(const char *str1, const char *str2, int start, int end) { |
mkarlsso | 0:8dbd6bd9167f | 5555 | if ((findStringLoc(str1,str2,start,end) != -1) && (strlen(str2)==(end-start+1))) { |
mkarlsso | 0:8dbd6bd9167f | 5556 | return true; |
mkarlsso | 0:8dbd6bd9167f | 5557 | } else { |
mkarlsso | 0:8dbd6bd9167f | 5558 | return false; |
mkarlsso | 0:8dbd6bd9167f | 5559 | } |
mkarlsso | 0:8dbd6bd9167f | 5560 | |
mkarlsso | 0:8dbd6bd9167f | 5561 | |
mkarlsso | 0:8dbd6bd9167f | 5562 | } |
mkarlsso | 0:8dbd6bd9167f | 5563 |