Component Test's Software to work with "Universal Controller Box" - Software is an interpreter or "compiler" for programs to be done with a .txt file and read off of the SD Card

Dependencies:   BridgeDriver FrontPanelButtons MCP23017 SDFileSystem TextLCD mbed

Revision:
10:e8db892fbc52
Parent:
9:5a0c4c6e39c7
Child:
11:bc9cd2869f95
--- a/main.cpp	Wed Sep 24 22:23:00 2014 +0000
+++ b/main.cpp	Wed Sep 24 22:54:36 2014 +0000
@@ -92,7 +92,7 @@
 };
 
 int conditionCommand(FILE *selectedFile, LineData &lineData){
-        
+                
     //Initialize variables    
     LineData param[15];
     vector<ConditionOp> paramCondition;
@@ -283,7 +283,13 @@
         else if (combinedCondition[i].op == OR)
             combinedCondition[i + 1].value = combinedCondition[i].value || combinedCondition[i + 1].value;
     }
-
+    
+    
+    //All syntax checking done by this point, if Dummy then return success in order to check the code within the Condition
+    if (DummyMode)
+        return 0; //Function operated successfully but doesn't return a value
+        
+        
     int conditionSuccess = combinedCondition.back().value; //value is the success(1) or failure(0) of the condition statement
 
     int checkEnd = 0, returnValue;
@@ -367,6 +373,10 @@
         //Increase the loop counter and go back to the beginning of the loop
         if (checkEnd == 3){
             
+            //All syntax checking done by this point, if Dummy then return success in order to check the code, no need to loop again
+            if (DummyMode)
+                return 0; //Function operated successfully but doesn't return a value
+                
             //Output the Avg Cycle Time
             cycleTimer.stop(); 
             totalLoopTime += cycleTimer.read();
@@ -436,6 +446,11 @@
     }
     
     else if (lineData.word[0].compare("delay") == 0){
+        
+        //All syntax checking done by this point, if Dummy then return success in order to check the code, no need wait for a delay
+        if (DummyMode)
+            return 0; //Function operated successfully but doesn't return a value
+            
         string duration = lineData.word[1];
         int durationValue = 0;
         int numValuesFound = sscanf(duration.c_str(), "%d", &durationValue);
@@ -591,56 +606,63 @@
     /******************************************************************************/
     /***          <Start Running through the Program txt File Lines>            ***/
     /******************************************************************************/
-    
-    while(1){  
-            
-        resetLineData(lineData); //Reset the values in the struct that holds the Line Data, in preparation for a new line read
-        lcd.cls(); //clear the display   
+      
+    resetLineData(lineData); //Reset the values in the struct that holds the File / Line Data
+    lcd.cls(); //clear the display   
 
-        int endOfFile = 0, error = 0, returnValue, checkEnd;
+    int endOfFile = 0, error = 0, returnValue, checkEnd;
+    DummyMode = 1; //set Dummy Mode equal to 1 to simulate the first run through of the code 
+    while (!endOfFile){
         
-        while (!endOfFile){
-            
-            //Re-initialize variables
-            returnValue = 0;
-            checkEnd = 0;
+        //Re-initialize variables
+        returnValue = 0;
+        checkEnd = 0;
+        
+        returnValue = getNextLine(selectedFile, lineData); //get the next line of data
+        
+        //if getNextLine returned an error, then return error in main
+        if (returnValue == -1)
+            error = 1;
             
-            returnValue = getNextLine(selectedFile, lineData); //get the next line of data
-            
-            //if getNextLine returned an error, then return error in main
-            if (returnValue == -1)
-                error = 1;
+        checkEnd = interpretCommand(selectedFile, lineData); //interpret the line data
                 
-            checkEnd = interpretCommand(selectedFile, lineData); //interpret the line data
-                    
-            if (checkEnd == 2)
-                endOfFile = 1;
-            else if (checkEnd == -1) //if interpretCommand returned an error, then return error in main
-                error = 1;
-                
-            //Before erroring out, turn all devices off so that they power down
-            if (error){
+        if (checkEnd == 2)
+            endOfFile = 1;
+        else if (checkEnd == -1) //if interpretCommand returned an error, then return error in main
+            error = 1;
+            
+        //Before erroring out, turn all devices off so that they power down
+        if (error){
+            if (!DummyMode){ //if it is Dummy Mode, then no functionality has actually been turned on, so no need to shut anything off
                 for(vector<Device*>::iterator it=devices.begin(); it < devices.end(); it++)  
                     (*it)->off();
-                
-                return -1;
             }
-        
+            
+            return -1;
+        }
+    
+        //Dummy Mode will be turned on for the first run through, set it to 0 after the first run through,
+        //as the syntax will be checked without erroring, and therefore it is possible to try and run the .txt file
+        //Seek back to beginning of file
+        if (DummyMode){
+            DummyMode = 0;
+            rewind(selectedFile); //seek to the beginning of the file
+            resetLineData(lineData); //Reset the values in the struct that holds the File / Line Data
         }
-        
-        lcd.cls(); //clear the display   
-        lcd.setAddress(0,0);
-        lcd.printf("END OF PROGRAM");
-        lcd.setAddress(0,2);
-        lcd.printf("To Restart...");
-        lcd.setAddress(0,3);
-        lcd.printf("Press BACK");
-       
-        while(!buttons.readBack());
-        
-        lcd.setAddress(0,1);
-        //rewind(selectedFile);
     }
+                
+    lcd.cls(); //clear the display   
+    lcd.setAddress(0,0);
+    lcd.printf("END OF PROGRAM");
+    lcd.setAddress(0,2);
+    lcd.printf("To Restart...");
+    lcd.setAddress(0,3);
+    lcd.printf("Press BACK");
+   
+    while(!buttons.readBack());
+    
+    lcd.setAddress(0,1);
+    //rewind(selectedFile);
 
  }