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

Files at this revision

API Documentation at this revision

Comitter:
mehatfie
Date:
Wed Sep 24 22:54:36 2014 +0000
Parent:
9:5a0c4c6e39c7
Child:
11:bc9cd2869f95
Commit message:
- Dummy Mode implemented with code functioning after compile; --- goes through all of the code, but doesn't actually turn anything on or run any physical functionality, it simple performs syntax checking on the entire programming, and resets and runs

Changed in this revision

Devices/Motor.cpp Show annotated file Show diff for this revision Revisions of this file
Devices/PinIN.cpp Show annotated file Show diff for this revision Revisions of this file
Devices/VoltageDriver.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Devices/Motor.cpp	Wed Sep 24 22:23:00 2014 +0000
+++ b/Devices/Motor.cpp	Wed Sep 24 22:54:36 2014 +0000
@@ -56,7 +56,11 @@
             ErrorOut("Parameter Unknown, enableBrake value can't be converted", lineData.lineNumber);
             return -1;
         }
-    
+        
+        //All syntax checking done by this point, if Dummy then return success in order to check the code, no need to perform functionality
+        if (DummyMode)
+            return 0; //Function operated successfully but doesn't return a value
+            
         bridges.enableBraking(getMotor(), enableValue);
     }
         
@@ -70,6 +74,10 @@
             return -1;
         }
         
+        //All syntax checking done by this point, if Dummy then return success in order to check the code, no need to perform functionality
+        if (DummyMode)
+            return 0; //Function operated successfully but doesn't return a value
+            
         bridges.forceBrake(getMotor());
     }
     
@@ -118,6 +126,10 @@
             return -1;
         }
         
+        //All syntax checking done by this point, if Dummy then return success in order to check the code, no need to perform functionality
+        if (DummyMode)
+            return 0; //Function operated successfully but doesn't return a value
+            
         bridges.drive(getMotor(), dirValue, speedValue); //Turn on the Motor
     }
     
@@ -131,7 +143,11 @@
             ErrorOut("Incorrect number of parameters", lineData.lineNumber);
             return -1;
         }
-             
+        
+        //All syntax checking done by this point, if Dummy then return success in order to check the code, no need to perform functionality
+        if (DummyMode)
+            return 0; //Function operated successfully but doesn't return a value
+            
         off();
     }
     
@@ -148,6 +164,7 @@
 //For stopping the entire system if an error occurs, can be called from main
 int Motor::off(void){
     bridges.drive(getMotor(), 0, 0); //Turn off the Motor
+    return 0;
 }
 
 
--- a/Devices/PinIN.cpp	Wed Sep 24 22:23:00 2014 +0000
+++ b/Devices/PinIN.cpp	Wed Sep 24 22:54:36 2014 +0000
@@ -104,6 +104,10 @@
             return -1;
         }
         
+        //All syntax checking done by this point, if Dummy then return success in order to check the code, no need to perform functionality
+        if (DummyMode)
+            return 0; //Function operated successfully but doesn't return a value
+            
         //Wait on the signal to turn to the specified value
         while(signal.read() != pinValue_Value);
     }
@@ -134,6 +138,10 @@
             return -1;
         }
         
+        //All syntax checking done by this point, if Dummy then return success in order to check the code, no need to perform functionality
+        if (DummyMode)
+            return 0; //Function operated successfully but doesn't return a value
+            
         //Return one if value meets the wanted pin value, return 0 if it doesn't
         if(signal.read() == checkValue_Value)
             return 1;
@@ -151,4 +159,5 @@
 
 int PinIN::off(void){
     //Do Nothing as you don't need to turn a Pin off
+    return 0;
 }
\ No newline at end of file
--- a/Devices/VoltageDriver.cpp	Wed Sep 24 22:23:00 2014 +0000
+++ b/Devices/VoltageDriver.cpp	Wed Sep 24 22:54:36 2014 +0000
@@ -65,6 +65,10 @@
             return -1;
         }
         
+        //All syntax checking done by this point, if Dummy then return success in order to check the code, no need to perform functionality
+        if (DummyMode)
+            return 0; //Function operated successfully but doesn't return a value
+            
         bridges.forceBrake(channel);
     }
     
@@ -79,7 +83,11 @@
             ErrorOut("Incorrect number of parameters", lineData.lineNumber);
             return -1;
         }
-                 
+        
+        //All syntax checking done by this point, if Dummy then return success in order to check the code, no need to perform functionality
+        if (DummyMode)
+            return 0; //Function operated successfully but doesn't return a value
+               
         bridges.drive(channel, 1); //turn channel on
     }
     
@@ -94,6 +102,10 @@
             return -1;
         }
         
+        //All syntax checking done by this point, if Dummy then return success in order to check the code, no need to perform functionality
+        if (DummyMode)
+            return 0; //Function operated successfully but doesn't return a value
+            
         off();
     }
     
@@ -110,5 +122,6 @@
 //For stopping the entire system if an error occurs, can be called from main
 int VoltageDriver::off(void){
     bridges.drive(getChannel(), 0); //turn channel off
+    return 0;
 }
 
--- 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);
 
  }