Microcontroller firmware that uses a simple, yet powerful scripting language to control the timing of input and output events with high temporal resolution. Written by Mattias Karlsson

Dependencies:   SMARTWAV mbed

Committer:
mkarlsso
Date:
Tue Feb 07 19:40:32 2017 +0000
Revision:
8:872b843a3053
Parent:
7:5fe7329751d4
Added "version command"

Who changed what in which revision?

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