A scripting environment used to define precise output/input temporal relationships.

Dependencies:   SMARTWAV mbed HelloWorld

Dependents:   perturbRoom_legacy

Fork of HelloWorld by Simon Ford

Committer:
mkarlsso
Date:
Tue Jul 08 21:51:16 2014 +0000
Revision:
2:298679fff37c
Child:
4:34aca2142df9
first commit

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