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:
Tue May 19 15:45:42 2015 +0000
Revision:
0:8dbd6bd9167f
Child:
1:3a050d26d4f6
Child:
2:35266b266eaa
initial commit

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