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

Dependencies:   SMARTWAV mbed

Committer:
mkarlsso
Date:
Fri Jan 15 22:13:23 2016 +0000
Revision:
4:abee20c0bf2a
Parent:
3:d7b0a0890d96
Child:
5:67d67d452545
Fixed an issue where syntax errors caused the program to crash instead of just reporting the syntax error.

Who changed what in which revision?

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