stateScript for Nucleo-F401RE board

Dependencies:   SOMO_II mbed

Committer:
alustig3
Date:
Mon Feb 08 18:56:09 2016 +0000
Revision:
0:ecf80f0172d0
initial commit

Who changed what in which revision?

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