![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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
Devices/TimerDevice.cpp@16:2482d226cf4d, 2014-10-03 (annotated)
- Committer:
- mehatfie
- Date:
- Fri Oct 03 21:33:46 2014 +0000
- Revision:
- 16:2482d226cf4d
- Parent:
- 11:bc9cd2869f95
- Updated Errors; - Initializes SD Card to work every time; - Cycle timer starts immediately on first cycle
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mehatfie | 11:bc9cd2869f95 | 1 | #include "TimerDevice.hpp" |
mehatfie | 11:bc9cd2869f95 | 2 | |
mehatfie | 11:bc9cd2869f95 | 3 | //Constructor |
mehatfie | 11:bc9cd2869f95 | 4 | TimerDevice::TimerDevice(LineData lineData){ |
mehatfie | 11:bc9cd2869f95 | 5 | //No Constructor needed... functionality already exists in mBed library |
mehatfie | 11:bc9cd2869f95 | 6 | } |
mehatfie | 11:bc9cd2869f95 | 7 | |
mehatfie | 11:bc9cd2869f95 | 8 | |
mehatfie | 11:bc9cd2869f95 | 9 | //A line consists of [ __(Local_Name)__ __(function)__ __(parameter1)__ __(parameter2)__ __(parameter3)__ ... and so on] |
mehatfie | 11:bc9cd2869f95 | 10 | int TimerDevice::interpret(LineData &lineData){ |
mehatfie | 11:bc9cd2869f95 | 11 | |
mehatfie | 11:bc9cd2869f95 | 12 | |
mehatfie | 11:bc9cd2869f95 | 13 | |
mehatfie | 11:bc9cd2869f95 | 14 | //Order of line: local_name, function_name, param1, param2, param3,....... |
mehatfie | 11:bc9cd2869f95 | 15 | string func = lineData.word[1]; |
mehatfie | 11:bc9cd2869f95 | 16 | |
mehatfie | 11:bc9cd2869f95 | 17 | /******************************************************************************/ |
mehatfie | 11:bc9cd2869f95 | 18 | /*** <func: start> ***/ |
mehatfie | 11:bc9cd2869f95 | 19 | /******************************************************************************/ |
mehatfie | 11:bc9cd2869f95 | 20 | if (func.compare("start") == 0){ |
mehatfie | 11:bc9cd2869f95 | 21 | |
mehatfie | 11:bc9cd2869f95 | 22 | if (lineData.numWords != 2){ |
mehatfie | 11:bc9cd2869f95 | 23 | ErrorOut("Incorrect number of parameters", lineData.lineNumber); |
mehatfie | 11:bc9cd2869f95 | 24 | return -1; |
mehatfie | 11:bc9cd2869f95 | 25 | } |
mehatfie | 11:bc9cd2869f95 | 26 | |
mehatfie | 11:bc9cd2869f95 | 27 | //All syntax checking done by this point, if Dummy then return success in order to check the code, no need to perform functionality |
mehatfie | 11:bc9cd2869f95 | 28 | if (DummyMode) |
mehatfie | 11:bc9cd2869f95 | 29 | return 0; //Function operated successfully but doesn't return a value |
mehatfie | 11:bc9cd2869f95 | 30 | |
mehatfie | 11:bc9cd2869f95 | 31 | this->Timer.start(); |
mehatfie | 11:bc9cd2869f95 | 32 | } |
mehatfie | 11:bc9cd2869f95 | 33 | |
mehatfie | 11:bc9cd2869f95 | 34 | |
mehatfie | 11:bc9cd2869f95 | 35 | /******************************************************************************/ |
mehatfie | 11:bc9cd2869f95 | 36 | /*** <func: stop> ***/ |
mehatfie | 11:bc9cd2869f95 | 37 | /******************************************************************************/ |
mehatfie | 11:bc9cd2869f95 | 38 | else if (func.compare("stop") == 0){ |
mehatfie | 11:bc9cd2869f95 | 39 | |
mehatfie | 11:bc9cd2869f95 | 40 | if (lineData.numWords != 2){ |
mehatfie | 11:bc9cd2869f95 | 41 | ErrorOut("Incorrect number of parameters", lineData.lineNumber); |
mehatfie | 11:bc9cd2869f95 | 42 | return -1; |
mehatfie | 11:bc9cd2869f95 | 43 | } |
mehatfie | 11:bc9cd2869f95 | 44 | |
mehatfie | 11:bc9cd2869f95 | 45 | //All syntax checking done by this point, if Dummy then return success in order to check the code, no need to perform functionality |
mehatfie | 11:bc9cd2869f95 | 46 | if (DummyMode) |
mehatfie | 11:bc9cd2869f95 | 47 | return 0; //Function operated successfully but doesn't return a value |
mehatfie | 11:bc9cd2869f95 | 48 | |
mehatfie | 11:bc9cd2869f95 | 49 | this->Timer.stop(); |
mehatfie | 11:bc9cd2869f95 | 50 | } |
mehatfie | 11:bc9cd2869f95 | 51 | |
mehatfie | 11:bc9cd2869f95 | 52 | /******************************************************************************/ |
mehatfie | 11:bc9cd2869f95 | 53 | /*** <func: reset> ***/ |
mehatfie | 11:bc9cd2869f95 | 54 | /******************************************************************************/ |
mehatfie | 11:bc9cd2869f95 | 55 | else if (func.compare("reset") == 0){ |
mehatfie | 11:bc9cd2869f95 | 56 | |
mehatfie | 11:bc9cd2869f95 | 57 | if (lineData.numWords != 2){ |
mehatfie | 11:bc9cd2869f95 | 58 | ErrorOut("Incorrect number of parameters", lineData.lineNumber); |
mehatfie | 11:bc9cd2869f95 | 59 | return -1; |
mehatfie | 11:bc9cd2869f95 | 60 | } |
mehatfie | 11:bc9cd2869f95 | 61 | |
mehatfie | 11:bc9cd2869f95 | 62 | //All syntax checking done by this point, if Dummy then return success in order to check the code, no need to perform functionality |
mehatfie | 11:bc9cd2869f95 | 63 | if (DummyMode) |
mehatfie | 11:bc9cd2869f95 | 64 | return 0; //Function operated successfully but doesn't return a value |
mehatfie | 11:bc9cd2869f95 | 65 | |
mehatfie | 11:bc9cd2869f95 | 66 | this->Timer.stop(); |
mehatfie | 11:bc9cd2869f95 | 67 | this->Timer.reset(); |
mehatfie | 11:bc9cd2869f95 | 68 | this->Timer.start(); |
mehatfie | 11:bc9cd2869f95 | 69 | } |
mehatfie | 11:bc9cd2869f95 | 70 | |
mehatfie | 11:bc9cd2869f95 | 71 | /******************************************************************************/ |
mehatfie | 11:bc9cd2869f95 | 72 | /**** <func: val> ****/ |
mehatfie | 11:bc9cd2869f95 | 73 | /******************************************************************************/ |
mehatfie | 11:bc9cd2869f95 | 74 | else if (func.compare("val") == 0){ |
mehatfie | 11:bc9cd2869f95 | 75 | |
mehatfie | 11:bc9cd2869f95 | 76 | //line looks like: local_name, val, comparison_characteristics (<, >, =) |
mehatfie | 11:bc9cd2869f95 | 77 | if (lineData.numWords != 4){ |
mehatfie | 11:bc9cd2869f95 | 78 | ErrorOut("Incorrect number of parameters", lineData.lineNumber); |
mehatfie | 11:bc9cd2869f95 | 79 | return -1; |
mehatfie | 11:bc9cd2869f95 | 80 | } |
mehatfie | 11:bc9cd2869f95 | 81 | |
mehatfie | 11:bc9cd2869f95 | 82 | string cmpChar = lineData.word[2]; //Get the comparison characteristic value |
mehatfie | 11:bc9cd2869f95 | 83 | |
mehatfie | 11:bc9cd2869f95 | 84 | string timestr = lineData.word[3]; //Parameter is a number |
mehatfie | 11:bc9cd2869f95 | 85 | int timeValue = 0; //Time value to compare in ms |
mehatfie | 11:bc9cd2869f95 | 86 | int numValuesFound = sscanf(timestr.c_str(), "%d", &timeValue); |
mehatfie | 11:bc9cd2869f95 | 87 | if (numValuesFound < 1){ |
mehatfie | 11:bc9cd2869f95 | 88 | ErrorOut("Parameter Unknown, time value can't be converted", lineData.lineNumber); |
mehatfie | 11:bc9cd2869f95 | 89 | return -1; |
mehatfie | 11:bc9cd2869f95 | 90 | } |
mehatfie | 11:bc9cd2869f95 | 91 | |
mehatfie | 11:bc9cd2869f95 | 92 | //Error check comparision characteristic |
mehatfie | 11:bc9cd2869f95 | 93 | if (cmpChar.compare("<") != 0 && cmpChar.compare(">") != 0 && cmpChar.compare("=") != 0){ |
mehatfie | 11:bc9cd2869f95 | 94 | ErrorOut("Parameter Unknown, comparison character can't be converted", lineData.lineNumber); |
mehatfie | 11:bc9cd2869f95 | 95 | return -1; |
mehatfie | 11:bc9cd2869f95 | 96 | } |
mehatfie | 11:bc9cd2869f95 | 97 | |
mehatfie | 11:bc9cd2869f95 | 98 | //All syntax checking done by this point, if Dummy then return success in order to check the code, no need to perform functionality |
mehatfie | 11:bc9cd2869f95 | 99 | if (DummyMode) |
mehatfie | 11:bc9cd2869f95 | 100 | return 0; //Function operated successfully but doesn't return a value |
mehatfie | 11:bc9cd2869f95 | 101 | |
mehatfie | 11:bc9cd2869f95 | 102 | if (cmpChar.compare("<") == 0){ |
mehatfie | 11:bc9cd2869f95 | 103 | if (this->Timer.read_ms() < timeValue) |
mehatfie | 11:bc9cd2869f95 | 104 | return 1; //met condition |
mehatfie | 11:bc9cd2869f95 | 105 | } |
mehatfie | 11:bc9cd2869f95 | 106 | else if (cmpChar.compare(">") == 0){ |
mehatfie | 11:bc9cd2869f95 | 107 | if (this->Timer.read_ms() > timeValue) |
mehatfie | 11:bc9cd2869f95 | 108 | return 1; //met condition |
mehatfie | 11:bc9cd2869f95 | 109 | } |
mehatfie | 11:bc9cd2869f95 | 110 | else if (cmpChar.compare("=") == 0){ |
mehatfie | 11:bc9cd2869f95 | 111 | if (this->Timer.read_ms() == timeValue) |
mehatfie | 11:bc9cd2869f95 | 112 | return 1; //met condition |
mehatfie | 11:bc9cd2869f95 | 113 | } |
mehatfie | 11:bc9cd2869f95 | 114 | |
mehatfie | 11:bc9cd2869f95 | 115 | } |
mehatfie | 11:bc9cd2869f95 | 116 | |
mehatfie | 11:bc9cd2869f95 | 117 | |
mehatfie | 11:bc9cd2869f95 | 118 | else { |
mehatfie | 11:bc9cd2869f95 | 119 | ErrorOut("Unknown Command for Voltage Driver Class", lineData.lineNumber); |
mehatfie | 11:bc9cd2869f95 | 120 | return -1; |
mehatfie | 11:bc9cd2869f95 | 121 | } |
mehatfie | 11:bc9cd2869f95 | 122 | |
mehatfie | 11:bc9cd2869f95 | 123 | return 0; //Return success as 0 since no condition had to be met |
mehatfie | 11:bc9cd2869f95 | 124 | } |
mehatfie | 11:bc9cd2869f95 | 125 | |
mehatfie | 11:bc9cd2869f95 | 126 | |
mehatfie | 11:bc9cd2869f95 | 127 | //For stopping the entire system if an error occurs, can be called from main |
mehatfie | 11:bc9cd2869f95 | 128 | int TimerDevice::off(void){ |
mehatfie | 11:bc9cd2869f95 | 129 | this->Timer.stop(); |
mehatfie | 11:bc9cd2869f95 | 130 | return 0; |
mehatfie | 11:bc9cd2869f95 | 131 | } |
mehatfie | 11:bc9cd2869f95 | 132 | |
mehatfie | 11:bc9cd2869f95 | 133 | |
mehatfie | 11:bc9cd2869f95 | 134 | //Pause the timer |
mehatfie | 11:bc9cd2869f95 | 135 | int TimerDevice::pause(void){ |
mehatfie | 11:bc9cd2869f95 | 136 | this->Timer.stop(); |
mehatfie | 11:bc9cd2869f95 | 137 | return 0; |
mehatfie | 11:bc9cd2869f95 | 138 | } |
mehatfie | 11:bc9cd2869f95 | 139 | |
mehatfie | 11:bc9cd2869f95 | 140 | //Resume the timer |
mehatfie | 11:bc9cd2869f95 | 141 | int TimerDevice::resume(void){ |
mehatfie | 11:bc9cd2869f95 | 142 | this->Timer.start(); |
mehatfie | 11:bc9cd2869f95 | 143 | return 0; |
mehatfie | 11:bc9cd2869f95 | 144 | } |
mehatfie | 11:bc9cd2869f95 | 145 | |
mehatfie | 11:bc9cd2869f95 | 146 |