perturh room legacy

Dependencies:   SMARTWAV USBDevice mbed stateScript

Fork of stateScript by Mattias Karlsson

Committer:
alustig3
Date:
Sat May 16 23:41:46 2015 +0000
Revision:
5:e62cd80aa22f
Parent:
4:34aca2142df9
changes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mkarlsso 2:298679fff37c 1 #include "mbed.h"
mkarlsso 2:298679fff37c 2 #include <stdint.h>
mkarlsso 2:298679fff37c 3 #include <string.h>
mkarlsso 2:298679fff37c 4 #include <string>
mkarlsso 2:298679fff37c 5 #include <vector>
mkarlsso 2:298679fff37c 6 #include <list>
mkarlsso 2:298679fff37c 7 #include <deque>
mkarlsso 2:298679fff37c 8 #include <queue>
mkarlsso 2:298679fff37c 9 #include "soundControl.h"
alustig3 5:e62cd80aa22f 10 #include "USBSerial.h"
mkarlsso 2:298679fff37c 11
mkarlsso 2:298679fff37c 12
mkarlsso 2:298679fff37c 13 #define NUMEVENTS 50
mkarlsso 2:298679fff37c 14 #define NUMCONDITIONS 150
mkarlsso 2:298679fff37c 15 #define NUMINTCOMPARE 150
mkarlsso 2:298679fff37c 16 #define NUMACTIONS 150
mkarlsso 2:298679fff37c 17 #define NUMPORTMESSAGES 150
mkarlsso 2:298679fff37c 18 #define NUMINTOPERATIONS 150
mkarlsso 2:298679fff37c 19 #define NUMDISPLAYACTIONS 30
mkarlsso 2:298679fff37c 20
mkarlsso 2:298679fff37c 21 #define ARITHMATIC_CONDITION 0
mkarlsso 2:298679fff37c 22 #define OR_CONDITION 1
mkarlsso 2:298679fff37c 23 #define AND_CONDITION 2
mkarlsso 2:298679fff37c 24
alustig3 5:e62cd80aa22f 25 #define NUMPORTS 5
mkarlsso 2:298679fff37c 26
alustig3 5:e62cd80aa22f 27 extern "C" void mbed_reset();//MAX and ANDY
mkarlsso 2:298679fff37c 28 class event; //we foreward declare this because of class interdependencies
mkarlsso 2:298679fff37c 29
mkarlsso 2:298679fff37c 30 //used in the digital port class to organize digital change events
mkarlsso 2:298679fff37c 31 struct changeEvent {
mkarlsso 2:298679fff37c 32 uint32_t timeStamp;
mkarlsso 2:298679fff37c 33 bool triggered;
mkarlsso 2:298679fff37c 34 };
mkarlsso 2:298679fff37c 35
mkarlsso 2:298679fff37c 36 //The digitalPort object directly controls and keeps data about the port. Each port has
mkarlsso 2:298679fff37c 37 //one digital out and one digital in.
mkarlsso 2:298679fff37c 38 class digitalPort {
mkarlsso 2:298679fff37c 39 public:
mkarlsso 2:298679fff37c 40 digitalPort(DigitalOut* DOP, DigitalIn* DIP);
alustig3 5:e62cd80aa22f 41 digitalPort(DigitalOut* DOP);
mkarlsso 2:298679fff37c 42 void setDigitalOut(int outVal);
mkarlsso 2:298679fff37c 43 //int getDigitalOut();
mkarlsso 2:298679fff37c 44 int getDigitalIn();
mkarlsso 2:298679fff37c 45 int getLastChangeState();
mkarlsso 2:298679fff37c 46 uint32_t getTimeSinceLastChange();
mkarlsso 2:298679fff37c 47 uint32_t lastChangeTime;
mkarlsso 2:298679fff37c 48 uint32_t lastOutChangeTime;
mkarlsso 2:298679fff37c 49
mkarlsso 2:298679fff37c 50 void setTriggerUpEvent(event* eventInput); //attahces a routine to an upward change
mkarlsso 2:298679fff37c 51 void setTriggerDownEvent(event* eventInput); //attahces a routine to a downward change
mkarlsso 2:298679fff37c 52 void addStateChange(int newState, uint32_t timeStamp);
mkarlsso 2:298679fff37c 53
mkarlsso 2:298679fff37c 54 bool update(); //called from the main loop
mkarlsso 2:298679fff37c 55
mkarlsso 2:298679fff37c 56 int inState;
mkarlsso 2:298679fff37c 57 int outState;
mkarlsso 2:298679fff37c 58
mkarlsso 2:298679fff37c 59 bool outStateChanged;
mkarlsso 2:298679fff37c 60
mkarlsso 2:298679fff37c 61 event* triggerUpEventPtr;
mkarlsso 2:298679fff37c 62 event* triggerDownEventPtr;
mkarlsso 2:298679fff37c 63
mkarlsso 2:298679fff37c 64 private:
mkarlsso 2:298679fff37c 65
mkarlsso 2:298679fff37c 66 DigitalOut* outPin;
mkarlsso 2:298679fff37c 67 DigitalIn* inPin;
mkarlsso 2:298679fff37c 68 int lastInState;
mkarlsso 2:298679fff37c 69 uint32_t lastChangeInterval;
mkarlsso 2:298679fff37c 70
mkarlsso 2:298679fff37c 71 changeEvent lastUpEvent;
mkarlsso 2:298679fff37c 72 changeEvent lastDownEvent;
mkarlsso 2:298679fff37c 73 };
mkarlsso 2:298679fff37c 74
mkarlsso 2:298679fff37c 75
mkarlsso 2:298679fff37c 76 //an intVariable contains an integer value and the name of that variable within the script
mkarlsso 2:298679fff37c 77 class intVariable {
mkarlsso 2:298679fff37c 78
mkarlsso 2:298679fff37c 79 public:
mkarlsso 2:298679fff37c 80 intVariable();
mkarlsso 2:298679fff37c 81 intVariable(string tagInput, int initialValue);
mkarlsso 2:298679fff37c 82 void set(string tagInput, int initialValue);
mkarlsso 2:298679fff37c 83 int value;
mkarlsso 2:298679fff37c 84 string tag;
mkarlsso 2:298679fff37c 85 bool isUsed;
mkarlsso 2:298679fff37c 86
mkarlsso 2:298679fff37c 87 };
mkarlsso 2:298679fff37c 88
mkarlsso 2:298679fff37c 89
mkarlsso 2:298679fff37c 90 //ACTION SECTION-- an 'action' is a command in the script. It can be a single command,
mkarlsso 2:298679fff37c 91 //or a block containing a set of actions
mkarlsso 2:298679fff37c 92 //------------------------------------------------------------------------------------
mkarlsso 2:298679fff37c 93
mkarlsso 2:298679fff37c 94 //display actions are used to output text messages via the serial port. The user can display
mkarlsso 2:298679fff37c 95 //either a static text string or the value of a single variable.
mkarlsso 2:298679fff37c 96 class displayAction {
mkarlsso 2:298679fff37c 97
mkarlsso 2:298679fff37c 98 public:
mkarlsso 2:298679fff37c 99 displayAction();
alustig3 5:e62cd80aa22f 100 displayAction(int* variable, string varNameInput, USBSerial* pcPtrInput);
alustig3 5:e62cd80aa22f 101 displayAction(string text, USBSerial* pcPtrInput);
alustig3 5:e62cd80aa22f 102 void set(int* variable, string varNameInput, USBSerial* pcPtrInput);
alustig3 5:e62cd80aa22f 103 void set(string text, USBSerial* pcPtrInput);
mkarlsso 2:298679fff37c 104 bool isUsed;
mkarlsso 2:298679fff37c 105 void execute();
mkarlsso 2:298679fff37c 106 void release();
mkarlsso 2:298679fff37c 107
mkarlsso 2:298679fff37c 108 private:
mkarlsso 2:298679fff37c 109 int* dVariable;
mkarlsso 2:298679fff37c 110 string dText;
alustig3 5:e62cd80aa22f 111 USBSerial* pcPtr;
mkarlsso 2:298679fff37c 112 };
mkarlsso 2:298679fff37c 113
mkarlsso 2:298679fff37c 114 //intOpertaion is an action that does addition or subtraction of integers and returns/stores the result
mkarlsso 2:298679fff37c 115 //these operation are very limited so far (only + or - allowed, and only one operation per object,
mkarlsso 2:298679fff37c 116 //for example a = b + b works but a = b + c + d does not. The output value can also be set to a random number.
mkarlsso 2:298679fff37c 117 class intOperation {
mkarlsso 2:298679fff37c 118
mkarlsso 2:298679fff37c 119 public:
mkarlsso 2:298679fff37c 120 intOperation();
mkarlsso 2:298679fff37c 121 intOperation(int randParam, const char* cmpString, int cmpValInput);
mkarlsso 2:298679fff37c 122 intOperation(int randParam, const char* cmpString, int* cmpIntVarInput);
mkarlsso 2:298679fff37c 123 intOperation(int* intVarInput, const char* cmpString, int cmpValInput);
mkarlsso 2:298679fff37c 124 intOperation(int* intVarInput, const char* cmpString, int* cmpIntVarInput);
mkarlsso 2:298679fff37c 125 intOperation(int* intVarInput, intOperation* operationInput);
mkarlsso 2:298679fff37c 126
mkarlsso 2:298679fff37c 127 ~intOperation();
mkarlsso 2:298679fff37c 128
mkarlsso 2:298679fff37c 129 void set(int randParam, const char* cmpString, int cmpValInput);
mkarlsso 2:298679fff37c 130 void set(int randParam, const char* cmpString, int* cmpIntVarInput);
mkarlsso 2:298679fff37c 131 void set(int* intVarInput, const char* cmpString, int cmpValInput);
mkarlsso 2:298679fff37c 132 void set(int* intVarInput, const char* cmpString, int* cmpIntVarInput);
mkarlsso 2:298679fff37c 133 void set(int* intVarInput, intOperation* operationInput);
mkarlsso 2:298679fff37c 134 void release();
mkarlsso 2:298679fff37c 135 bool isUsed;
mkarlsso 2:298679fff37c 136 int execute();
mkarlsso 2:298679fff37c 137
mkarlsso 2:298679fff37c 138 private:
mkarlsso 2:298679fff37c 139 int randHigh;
mkarlsso 2:298679fff37c 140 int* cmpVal;
mkarlsso 2:298679fff37c 141 int* intVal;
mkarlsso 2:298679fff37c 142 intOperation* opPtr;
mkarlsso 2:298679fff37c 143 bool cmpValGlobal;
mkarlsso 2:298679fff37c 144 int (intOperation::*executePtr)();
mkarlsso 2:298679fff37c 145 int addAndStore();
mkarlsso 2:298679fff37c 146 int subtractAndStore();
mkarlsso 2:298679fff37c 147 int add();
mkarlsso 2:298679fff37c 148 int subtract();
mkarlsso 2:298679fff37c 149 int equals();
mkarlsso 2:298679fff37c 150
mkarlsso 2:298679fff37c 151 };
mkarlsso 2:298679fff37c 152
mkarlsso 2:298679fff37c 153 //portMessage is an action to change a digital port. So far, You can only change the digital out (0 or 1)
mkarlsso 2:298679fff37c 154 class portMessage {
mkarlsso 2:298679fff37c 155 public:
mkarlsso 2:298679fff37c 156
mkarlsso 2:298679fff37c 157 portMessage();
mkarlsso 2:298679fff37c 158 //portMessage(digitalPort* portIn, int whichToSet, int value); //whichToSet: 1 DigitalOut; 2 State
mkarlsso 2:298679fff37c 159 //void setMessage(digitalPort* portIn, int whichToSet, int value); //whichToSet: 1 DigitalOut; 2 State
mkarlsso 2:298679fff37c 160 portMessage(int* portIn, int whichToSet, int value); //whichToSet:
mkarlsso 2:298679fff37c 161 void setMessage(int* portIn, int whichToSet, int value); //whichToSet:
mkarlsso 2:298679fff37c 162
mkarlsso 2:298679fff37c 163 void execute();
mkarlsso 2:298679fff37c 164 void release();
mkarlsso 2:298679fff37c 165 bool isUsed;
mkarlsso 2:298679fff37c 166
mkarlsso 2:298679fff37c 167 private:
mkarlsso 2:298679fff37c 168 int whichToSet; //hard coded port number
mkarlsso 2:298679fff37c 169 int* port; //alternative variable port number
mkarlsso 2:298679fff37c 170 int value;
mkarlsso 2:298679fff37c 171 //digitalPort* port;
mkarlsso 2:298679fff37c 172
mkarlsso 2:298679fff37c 173 };
mkarlsso 2:298679fff37c 174
mkarlsso 2:298679fff37c 175 //holder class for all possible actions. This include general system commands.
mkarlsso 2:298679fff37c 176 class action {
mkarlsso 2:298679fff37c 177 public:
mkarlsso 2:298679fff37c 178
mkarlsso 2:298679fff37c 179 action();
mkarlsso 2:298679fff37c 180 ~action();
mkarlsso 2:298679fff37c 181 action(intOperation* opInput);
mkarlsso 2:298679fff37c 182 action(portMessage* messageInput);
mkarlsso 2:298679fff37c 183 action(event* eventInput);
mkarlsso 2:298679fff37c 184 //action(event* eventInput, uint32_t delay);
mkarlsso 2:298679fff37c 185 action(displayAction* displayInput);
mkarlsso 2:298679fff37c 186 action(soundControl* soundInput);
mkarlsso 2:298679fff37c 187 action(int8_t sysCommandInput); //for general system commands
mkarlsso 2:298679fff37c 188
mkarlsso 2:298679fff37c 189 void set(intOperation* opInput);
mkarlsso 2:298679fff37c 190 void set(portMessage* messageInput);
mkarlsso 2:298679fff37c 191 void set(event* eventInput);
mkarlsso 2:298679fff37c 192 //void set(event* eventInput, uint32_t delay);
mkarlsso 2:298679fff37c 193
mkarlsso 2:298679fff37c 194 void set(displayAction* displayInput);
mkarlsso 2:298679fff37c 195 void set(soundControl* soundInput);
mkarlsso 2:298679fff37c 196 void set(int8_t sysCommandInput);
mkarlsso 2:298679fff37c 197 void execute();
mkarlsso 2:298679fff37c 198 void execute(uint32_t blockExecTime);
mkarlsso 2:298679fff37c 199 void release();
mkarlsso 2:298679fff37c 200 bool isUsed;
mkarlsso 2:298679fff37c 201
mkarlsso 2:298679fff37c 202 private:
mkarlsso 2:298679fff37c 203 intOperation* op;
mkarlsso 2:298679fff37c 204 portMessage* message;
mkarlsso 2:298679fff37c 205 event* eventToCreate;
mkarlsso 2:298679fff37c 206 displayAction* displayActionPtr;
mkarlsso 2:298679fff37c 207 soundControl* sound;
mkarlsso 2:298679fff37c 208 //uint32_t eventDelay;
mkarlsso 2:298679fff37c 209 int8_t sysCommand;
mkarlsso 2:298679fff37c 210 char actionType;
mkarlsso 2:298679fff37c 211
mkarlsso 2:298679fff37c 212 };
mkarlsso 2:298679fff37c 213 //-----------------------------------------------------
mkarlsso 2:298679fff37c 214
mkarlsso 2:298679fff37c 215 //CONDITION SECTION-- a 'condition' is used in the beginning of a block (if-else blocks or while blocks)
mkarlsso 2:298679fff37c 216 //If the condition is true, the block is exectuted during a callback
mkarlsso 2:298679fff37c 217 //------------------------------------------------------------------------------------
mkarlsso 2:298679fff37c 218
mkarlsso 2:298679fff37c 219
mkarlsso 2:298679fff37c 220 //intCompare is a condition class that compares the state value of a port or
mkarlsso 2:298679fff37c 221 //an integer variable to another integer variable or operation output
mkarlsso 2:298679fff37c 222 class intCompare {
mkarlsso 2:298679fff37c 223
mkarlsso 2:298679fff37c 224 public:
mkarlsso 2:298679fff37c 225 intCompare();
mkarlsso 2:298679fff37c 226 intCompare(digitalPort* portInput, const char* cmpString, int cmpValInput, int whichToUse);
mkarlsso 2:298679fff37c 227 intCompare(digitalPort* portInput, const char* cmpString, int* cmpIntVarInput, int whichToUse);
mkarlsso 2:298679fff37c 228 intCompare(int* intVarInput, const char* cmpString, int cmpValInput);
mkarlsso 2:298679fff37c 229 intCompare(int* intVarInput, const char* cmpString, int* cmpIntVarInput);
mkarlsso 2:298679fff37c 230 intCompare(int* intVarInput, const char* cmpString, intOperation* cmpIntOpInput);
mkarlsso 2:298679fff37c 231 intCompare(digitalPort* portInput, const char* cmpString, intOperation* cmpIntOpInput, int whichToUse);
mkarlsso 2:298679fff37c 232
mkarlsso 2:298679fff37c 233 void set(digitalPort* portInput, const char* cmpString, int cmpValInput, int whichToUse);
mkarlsso 2:298679fff37c 234 void set(digitalPort* portInput, const char* cmpString, int* cmpIntVarInput, int whichToUse);
mkarlsso 2:298679fff37c 235 void set(int* intVarInput, const char* cmpString, int cmpValInput);
mkarlsso 2:298679fff37c 236 void set(int* intVarInput, const char* cmpString, int* cmpIntVarInput);
mkarlsso 2:298679fff37c 237 void set(int* intVarInput, const char* cmpString, intOperation* cmpIntOpInput);
mkarlsso 2:298679fff37c 238 void set(digitalPort* portInput, const char* cmpString, intOperation* cmpIntOpInput, int whichToUse);
mkarlsso 2:298679fff37c 239
mkarlsso 2:298679fff37c 240 void release();
mkarlsso 2:298679fff37c 241
mkarlsso 2:298679fff37c 242 ~intCompare();
mkarlsso 2:298679fff37c 243 bool isTrue();
mkarlsso 2:298679fff37c 244 bool isUsed;
mkarlsso 2:298679fff37c 245
mkarlsso 2:298679fff37c 246 private:
mkarlsso 2:298679fff37c 247 digitalPort* port;
mkarlsso 2:298679fff37c 248 int* portValPtr;
mkarlsso 2:298679fff37c 249 int* cmpVal;
mkarlsso 2:298679fff37c 250 int* intVal;
mkarlsso 2:298679fff37c 251 intOperation* intOp;
mkarlsso 2:298679fff37c 252 void setPointer(const char* cmpString);
mkarlsso 2:298679fff37c 253 void setPointer_operation(const char* cmpString);
mkarlsso 2:298679fff37c 254 bool (intCompare::*isTruePtr)();
mkarlsso 2:298679fff37c 255 bool cmpValGlobal;
mkarlsso 2:298679fff37c 256 bool greaterThan();
mkarlsso 2:298679fff37c 257 bool greaterOrEqual();
mkarlsso 2:298679fff37c 258 bool lessThan();
mkarlsso 2:298679fff37c 259 bool lessOrEqual();
mkarlsso 2:298679fff37c 260 bool equal();
mkarlsso 2:298679fff37c 261 bool notEqual();
mkarlsso 2:298679fff37c 262 bool greaterThan_op();
mkarlsso 2:298679fff37c 263 bool greaterOrEqual_op();
mkarlsso 2:298679fff37c 264 bool lessThan_op();
mkarlsso 2:298679fff37c 265 bool lessOrEqual_op();
mkarlsso 2:298679fff37c 266 bool equal_op();
mkarlsso 2:298679fff37c 267 bool notEqual_op();
mkarlsso 2:298679fff37c 268 };
mkarlsso 2:298679fff37c 269
mkarlsso 2:298679fff37c 270
mkarlsso 2:298679fff37c 271 //holder class for all possible conditions (so far only intCompare)
mkarlsso 2:298679fff37c 272 class condition {
mkarlsso 2:298679fff37c 273 public:
mkarlsso 2:298679fff37c 274
mkarlsso 2:298679fff37c 275 condition();
mkarlsso 2:298679fff37c 276 condition(intCompare* compareInput);
mkarlsso 2:298679fff37c 277 condition(condition* condition1, char condType, condition* condition2);
mkarlsso 2:298679fff37c 278 ~condition();
mkarlsso 2:298679fff37c 279 void set(intCompare* compareInput);
mkarlsso 2:298679fff37c 280 void set(condition* condition1, char condType, condition* condition2);
mkarlsso 2:298679fff37c 281 bool isTrue();
mkarlsso 2:298679fff37c 282 bool isUsed;
mkarlsso 2:298679fff37c 283 void release(); //called when the event is no longer being used;
mkarlsso 2:298679fff37c 284 private:
mkarlsso 2:298679fff37c 285
mkarlsso 2:298679fff37c 286 //char conditionType; //1 for intCompare
mkarlsso 2:298679fff37c 287 intCompare* intCmp;
mkarlsso 2:298679fff37c 288 condition* conditionPtrs[2];
mkarlsso 2:298679fff37c 289 char conditionType;
mkarlsso 2:298679fff37c 290
mkarlsso 2:298679fff37c 291
mkarlsso 2:298679fff37c 292 };
mkarlsso 2:298679fff37c 293 //--------------------------------------------
mkarlsso 2:298679fff37c 294
mkarlsso 2:298679fff37c 295
mkarlsso 2:298679fff37c 296 //queueItem connects a pre-defined event with an exectution time.
mkarlsso 2:298679fff37c 297 //They are placed in the eventQueue
mkarlsso 2:298679fff37c 298 struct queueItem {
mkarlsso 2:298679fff37c 299 uint32_t timeToExecute;
mkarlsso 2:298679fff37c 300 event* eventPtr;
mkarlsso 2:298679fff37c 301 };
mkarlsso 2:298679fff37c 302
mkarlsso 2:298679fff37c 303
mkarlsso 2:298679fff37c 304 //Organizes events in a temporal queue. check() is called from the main loop.
mkarlsso 2:298679fff37c 305 //If the execution time of the event has passed, then the event is exectuted.
mkarlsso 2:298679fff37c 306 class eventQueue {
mkarlsso 2:298679fff37c 307 public:
mkarlsso 2:298679fff37c 308 eventQueue(digitalPort** portVectorInput, uint32_t* timeKeeperSlaveInput);
mkarlsso 2:298679fff37c 309 void addEventToQueue(event* eventInput, uint32_t delay);
mkarlsso 2:298679fff37c 310 void eraseQueue(); //clear all future events
mkarlsso 2:298679fff37c 311 void check(void);
mkarlsso 2:298679fff37c 312
mkarlsso 2:298679fff37c 313 private:
mkarlsso 2:298679fff37c 314 std::vector<queueItem> events;
mkarlsso 2:298679fff37c 315 digitalPort** portVector;
mkarlsso 2:298679fff37c 316 uint32_t* timeKeeperPtr;
mkarlsso 2:298679fff37c 317 int queueSize;
mkarlsso 2:298679fff37c 318
mkarlsso 2:298679fff37c 319 };
mkarlsso 2:298679fff37c 320
mkarlsso 2:298679fff37c 321 //An 'event' is a block of 'actions' that can be gated with a boolean 'condition' set. All
mkarlsso 2:298679fff37c 322 //conditions in the set must be true for the block of actions to be executed. Right now,
mkarlsso 2:298679fff37c 323 //there is no OR logic (||), only AND (&&).
mkarlsso 2:298679fff37c 324 //The entire event is placed on the event queue to be executed at a given delay.
mkarlsso 2:298679fff37c 325 //At that future time, the condition is checked and if true, the block of actions
mkarlsso 2:298679fff37c 326 //is exectuted. Note: an 'action' can be another event (or even the parent event), allowing
mkarlsso 2:298679fff37c 327 //nested 'if' and 'while' statements.
mkarlsso 2:298679fff37c 328 class event {
mkarlsso 2:298679fff37c 329 public:
mkarlsso 2:298679fff37c 330
mkarlsso 2:298679fff37c 331 event();
mkarlsso 2:298679fff37c 332 event(eventQueue* queueInput);
mkarlsso 2:298679fff37c 333 ~event();
mkarlsso 2:298679fff37c 334 void setTimeLag(uint32_t timeLagInput); //the event will be exectuted at this time from now
mkarlsso 2:298679fff37c 335 void setTimeLag(int* timeLagInput); //the event will be exectuted at this time from now
mkarlsso 2:298679fff37c 336 void setWhileLoopPeriod(uint32_t period);
mkarlsso 2:298679fff37c 337 void setWhileLoopPeriod(int* period);
mkarlsso 2:298679fff37c 338 void addCondition(condition* conditionInput); //contains a set of conditions to check and a truth table
mkarlsso 2:298679fff37c 339 bool isConditionTrue(void); //checks if the condition is true
mkarlsso 2:298679fff37c 340 void addAction(action* actionInput); //called during script parsing, when the block is being defined
mkarlsso 2:298679fff37c 341 void addToQueue(void); //places the event on the event queue with default time lag. When the time
mkarlsso 2:298679fff37c 342 //lag has expired, the the block is executed
mkarlsso 2:298679fff37c 343 void addToQueue(uint32_t delay);
mkarlsso 2:298679fff37c 344 void execute(void); //Execute without checking the condition. Called only from the event queue
mkarlsso 2:298679fff37c 345 void setNextElseEvent(event* eventInput); //allows for else event block
mkarlsso 2:298679fff37c 346 uint32_t timeLag; //default time from now when the event will be executed (this is ignored once placed in event queue)
mkarlsso 2:298679fff37c 347 int* timeLagVar; //exectution time lab defined by a variable
mkarlsso 2:298679fff37c 348 eventQueue* queuePtr;
mkarlsso 2:298679fff37c 349 void release(); //called when the event is no longer being used;
mkarlsso 2:298679fff37c 350
mkarlsso 2:298679fff37c 351 char blockType; //0 callback
mkarlsso 2:298679fff37c 352 //1 if ... do block (with conditions)
mkarlsso 2:298679fff37c 353 //2 do block (no conditions)
mkarlsso 2:298679fff37c 354 //3 else if ... do block
mkarlsso 2:298679fff37c 355 //4 else do (no conditions)
mkarlsso 2:298679fff37c 356 //5 while ... do every ... block
mkarlsso 2:298679fff37c 357 //6 else while ... do every ... block
mkarlsso 2:298679fff37c 358 //7 then if ... do block
mkarlsso 2:298679fff37c 359 //8 then do (no conditions)
mkarlsso 2:298679fff37c 360
mkarlsso 2:298679fff37c 361 uint32_t whileLoopPeriod; //if non-zero, the block is a while loop (executed at regular intervals)
mkarlsso 2:298679fff37c 362 int* whileLoopPeriodVar;
mkarlsso 2:298679fff37c 363 event* nextElseEventPtr;
mkarlsso 2:298679fff37c 364 bool isUsed;
mkarlsso 2:298679fff37c 365 bool timeLagIsConstant;
mkarlsso 2:298679fff37c 366 bool whileLoopPeriodIsConstant;
mkarlsso 2:298679fff37c 367 bool hasWhileLoop;
mkarlsso 2:298679fff37c 368
mkarlsso 2:298679fff37c 369 private:
mkarlsso 2:298679fff37c 370 int numConditions;
mkarlsso 2:298679fff37c 371 int numActions;
mkarlsso 2:298679fff37c 372 condition* conditionToCheck;
mkarlsso 2:298679fff37c 373 action* actionArray[20];
mkarlsso 2:298679fff37c 374
mkarlsso 2:298679fff37c 375 //if statement (can be left empty, which is interpreted as 'true')
mkarlsso 2:298679fff37c 376 //std::vector<condition*> conditionArray;
mkarlsso 2:298679fff37c 377 //std::deque<action*> actionArray;
mkarlsso 2:298679fff37c 378
mkarlsso 2:298679fff37c 379 };
mkarlsso 2:298679fff37c 380
mkarlsso 2:298679fff37c 381 //each functionItem help a poiter to an action, and the name of the function
mkarlsso 2:298679fff37c 382 class functionItem {
mkarlsso 2:298679fff37c 383 public:
mkarlsso 2:298679fff37c 384 functionItem(action* actionInput, string tagInput);
mkarlsso 2:298679fff37c 385 ~functionItem();
mkarlsso 2:298679fff37c 386 string tag;
mkarlsso 2:298679fff37c 387 action* actionPtr;
mkarlsso 2:298679fff37c 388 };
mkarlsso 2:298679fff37c 389
mkarlsso 2:298679fff37c 390 //Parser for the incoming text. The parser is called when a line terminates with a semicolon (;).
mkarlsso 2:298679fff37c 391 //Only the final line in a callback block should have a semicolon.
mkarlsso 2:298679fff37c 392 class scriptStream {
mkarlsso 2:298679fff37c 393 public:
alustig3 5:e62cd80aa22f 394 scriptStream(USBSerial* serialInput, digitalPort** portVectorInput, int numPortsInput, eventQueue* queueInput);
mkarlsso 2:298679fff37c 395 void parseBlock();
mkarlsso 2:298679fff37c 396 void addLineToCurrentBlock(char* lineInput); // if the line did not end with a semicolon, add it to the current block
mkarlsso 2:298679fff37c 397 int* findIntVariable(string nameInput); //used to retrieve the pointer to the designated variable if it exists
mkarlsso 2:298679fff37c 398 bool createIntVariable(string nameInput); // creates a new interger variable
mkarlsso 2:298679fff37c 399 action* evaluateAssignmentForAction(string expression); //parses a numerical assignment or operation (a = b - c)
mkarlsso 2:298679fff37c 400 bool evaluateConditions(string expression, event* currentEvent); //parses a condition statement (a == b && c > d)
mkarlsso 2:298679fff37c 401 condition* parseConditions(string expression); //parses a condition statement (a == b && c > d)
mkarlsso 2:298679fff37c 402 std::size_t findFirstOrOutsideParenth(string expression);
mkarlsso 2:298679fff37c 403 std::size_t findFirstAndOutsideParenth(string expression);
mkarlsso 2:298679fff37c 404 bool isOutsideParenth(string expression,std::size_t foundItem);
mkarlsso 2:298679fff37c 405
mkarlsso 2:298679fff37c 406 int getRandomParam(string expression);
mkarlsso 2:298679fff37c 407
mkarlsso 2:298679fff37c 408 private:
mkarlsso 2:298679fff37c 409
mkarlsso 2:298679fff37c 410 int currentTriggerPort;
mkarlsso 2:298679fff37c 411 int currentTriggerDir;
mkarlsso 2:298679fff37c 412 int currentPort;
mkarlsso 2:298679fff37c 413 int currentFunction;
alustig3 5:e62cd80aa22f 414
mkarlsso 2:298679fff37c 415 string tmpLine;
mkarlsso 2:298679fff37c 416 vector<string> tokens;
mkarlsso 2:298679fff37c 417
mkarlsso 2:298679fff37c 418 bool lineError;
mkarlsso 2:298679fff37c 419 int blockDepth;
mkarlsso 2:298679fff37c 420 bool ifBlockInit;
mkarlsso 2:298679fff37c 421 bool whileBlockInit;
mkarlsso 2:298679fff37c 422 bool elseFlag;
mkarlsso 2:298679fff37c 423 bool thenFlag;
mkarlsso 2:298679fff37c 424 int currentDelay;
mkarlsso 2:298679fff37c 425 event* tmpEvent;
mkarlsso 2:298679fff37c 426 string tmpString;
mkarlsso 2:298679fff37c 427
mkarlsso 2:298679fff37c 428 vector<intVariable*> globalVariables;
mkarlsso 2:298679fff37c 429 vector<event*> tmpEventPtrArray;
mkarlsso 2:298679fff37c 430 vector<functionItem*> functionArray; //any blocks declared outsite callback blocks are stored here
alustig3 5:e62cd80aa22f 431 list<string> currentBlock;
mkarlsso 2:298679fff37c 432 digitalPort** portVector;
mkarlsso 2:298679fff37c 433
mkarlsso 2:298679fff37c 434
mkarlsso 2:298679fff37c 435 int numPorts;
alustig3 5:e62cd80aa22f 436 USBSerial* pcPtr;
mkarlsso 2:298679fff37c 437 eventQueue* queuePtr;
mkarlsso 2:298679fff37c 438
mkarlsso 2:298679fff37c 439 };
mkarlsso 2:298679fff37c 440
mkarlsso 2:298679fff37c 441
mkarlsso 2:298679fff37c 442 //Used to buffer output text. Used mainly for 'display' commands within the script,
mkarlsso 2:298679fff37c 443 //and alloed the reset of the block to execute quickly instead. The text is then streamed out
mkarlsso 2:298679fff37c 444 //slowly via serial (one character per main loop execution). outputStream is a simple circular
mkarlsso 2:298679fff37c 445 //buffer that cannot be resized after initiation.
mkarlsso 2:298679fff37c 446 class outputStream {
mkarlsso 2:298679fff37c 447
mkarlsso 2:298679fff37c 448 public:
mkarlsso 2:298679fff37c 449 outputStream(int bufferSizeIn);
mkarlsso 2:298679fff37c 450 ~outputStream();
mkarlsso 2:298679fff37c 451 void send(string outputString);
mkarlsso 2:298679fff37c 452 char getNextChar();
mkarlsso 2:298679fff37c 453 bool unsentData;
mkarlsso 2:298679fff37c 454
mkarlsso 2:298679fff37c 455 private:
mkarlsso 2:298679fff37c 456 int readHead;
mkarlsso 2:298679fff37c 457 int writeHead;
mkarlsso 2:298679fff37c 458 int totalWriteHead;
mkarlsso 2:298679fff37c 459 int totalReadHead;
mkarlsso 2:298679fff37c 460 int bufferSize;
mkarlsso 2:298679fff37c 461 char tmpOut;
mkarlsso 2:298679fff37c 462 char* outputBuffer;
mkarlsso 2:298679fff37c 463 };