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

Committer:
mehatfie
Date:
Fri Oct 03 17:31:04 2014 +0000
Revision:
15:c944ee3c8a5b
Parent:
11:bc9cd2869f95
Child:
16:2482d226cf4d
- readded mkdir("\sd") line which seemed to have fixed an error in the system where the system could not find any files in the SD Card on power cycle. New SD Cards wouldn't have had this directory made for the "readfileNames()" function

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mehatfie 11:bc9cd2869f95 1 //#include "CAN_Device.hpp"
mehatfie 11:bc9cd2869f95 2 //
mehatfie 11:bc9cd2869f95 3 ////Constructor
mehatfie 11:bc9cd2869f95 4 //CAN_Device::CAN_Device(LineData lineData){
mehatfie 11:bc9cd2869f95 5 //
mehatfie 11:bc9cd2869f95 6 // //Order of Line: Command, Local_Name, CAN_DEVICE, selectedCAN(1,2), freq
mehatfie 11:bc9cd2869f95 7 // //Since we can't return from a constructor, instead we'll flip a flag, and check it after we've added the device in interpretCommand
mehatfie 11:bc9cd2869f95 8 // if (lineData.numWords != 5)
mehatfie 11:bc9cd2869f95 9 // this->errorFlag = 1;
mehatfie 11:bc9cd2869f95 10 //
mehatfie 11:bc9cd2869f95 11 // string channelstr = lineData.word[3], freqstr = lineData.word[4]; //Parameters are numbers
mehatfie 11:bc9cd2869f95 12 // int tempChannel = -1, tempFreq = -1;
mehatfie 11:bc9cd2869f95 13 // int numValuesFound = sscanf(channelstr.c_str(), "%d", &tempChannel);
mehatfie 11:bc9cd2869f95 14 // if (numValuesFound < 1)
mehatfie 11:bc9cd2869f95 15 // this->errorFlag = 1;
mehatfie 11:bc9cd2869f95 16 //
mehatfie 11:bc9cd2869f95 17 // numValuesFound = sscanf(freqstr.c_str(), "%d", &tempFreq);
mehatfie 11:bc9cd2869f95 18 // if (numValuesFound < 1)
mehatfie 11:bc9cd2869f95 19 // this->errorFlag = 1;
mehatfie 11:bc9cd2869f95 20 //
mehatfie 11:bc9cd2869f95 21 // //channel must be either CAN1 or CAN2
mehatfie 11:bc9cd2869f95 22 // if (tempChannel == 1 || tempChannel == 2){
mehatfie 15:c944ee3c8a5b 23 // if (tempChannel == 1){
mehatfie 15:c944ee3c8a5b 24 // this->pinRD = p30;
mehatfie 15:c944ee3c8a5b 25 // this->pinTD = p29;
mehatfie 15:c944ee3c8a5b 26 // }
mehatfie 15:c944ee3c8a5b 27 // else if (tempChannel == 2){
mehatfie 15:c944ee3c8a5b 28 // this->pinRD = p9;
mehatfie 15:c944ee3c8a5b 29 // this->pinTD = p10;
mehatfie 15:c944ee3c8a5b 30 // }
mehatfie 15:c944ee3c8a5b 31 //
mehatfie 15:c944ee3c8a5b 32 // this->selectedCAN = tempChannel;
mehatfie 15:c944ee3c8a5b 33 // }
mehatfie 15:c944ee3c8a5b 34 //
mehatfie 11:bc9cd2869f95 35 // else
mehatfie 11:bc9cd2869f95 36 // this->errorFlag = 1;
mehatfie 11:bc9cd2869f95 37 //
mehatfie 11:bc9cd2869f95 38 // //should have a frequency greater than 0
mehatfie 11:bc9cd2869f95 39 // if (tempFreq > 0)
mehatfie 11:bc9cd2869f95 40 // this->freq = tempFreq;
mehatfie 11:bc9cd2869f95 41 // else
mehatfie 11:bc9cd2869f95 42 // this->errorFlag = 1;
mehatfie 11:bc9cd2869f95 43 //}
mehatfie 11:bc9cd2869f95 44 //
mehatfie 11:bc9cd2869f95 45 //
mehatfie 11:bc9cd2869f95 46 //int CAN_Device::getSelectedCAN(){
mehatfie 11:bc9cd2869f95 47 // return this->selectedCAN;
mehatfie 11:bc9cd2869f95 48 //}
mehatfie 11:bc9cd2869f95 49 //
mehatfie 11:bc9cd2869f95 50 //int CAN_Device::getFreq(){
mehatfie 11:bc9cd2869f95 51 // return this->freq;
mehatfie 11:bc9cd2869f95 52 //}
mehatfie 11:bc9cd2869f95 53 //
mehatfie 11:bc9cd2869f95 54 ////A line consists of [ __(Local_Name)__ __(function)__ __(parameter1)__ __(parameter2)__ __(parameter3)__ ... and so on]
mehatfie 11:bc9cd2869f95 55 //int CAN_Device::CAN_Device(LineData &lineData){
mehatfie 11:bc9cd2869f95 56 //
mehatfie 15:c944ee3c8a5b 57 // //Initialize the CAN device
mehatfie 15:c944ee3c8a5b 58 // CAN canDevice(pinRD, pinTD);
mehatfie 15:c944ee3c8a5b 59 // canDevice.frequency(125000);
mehatfie 15:c944ee3c8a5b 60 //
mehatfie 11:bc9cd2869f95 61 // //Order of Line: Local_Name, Function_Name, Param1, Param2, Param3,.......
mehatfie 11:bc9cd2869f95 62 // string func = lineData.word[1];
mehatfie 11:bc9cd2869f95 63 //
mehatfie 11:bc9cd2869f95 64 // /******************************************************************************/
mehatfie 15:c944ee3c8a5b 65 // /*** <Func: write> ***/
mehatfie 11:bc9cd2869f95 66 // /******************************************************************************/
mehatfie 11:bc9cd2869f95 67 // if (func.compare("write") == 0){
mehatfie 15:c944ee3c8a5b 68 // //line looks like: Local_Name, write, ID_val, length_val, data
mehatfie 15:c944ee3c8a5b 69 // if (lineData.numWords < 5){
mehatfie 11:bc9cd2869f95 70 // ErrorOut("Incorrect number of parameters", lineData.lineNumber);
mehatfie 11:bc9cd2869f95 71 // return -1;
mehatfie 11:bc9cd2869f95 72 // }
mehatfie 11:bc9cd2869f95 73 //
mehatfie 11:bc9cd2869f95 74 // //Initialize and Convert Parameters
mehatfie 15:c944ee3c8a5b 75 // string _id = lineData.word[2];
mehatfie 15:c944ee3c8a5b 76 // string _length = lineData.word[3];
mehatfie 15:c944ee3c8a5b 77 // string _data = lineData.word[4];
mehatfie 15:c944ee3c8a5b 78 // int _idValue = 0;
mehatfie 15:c944ee3c8a5b 79 // char _lengthValue = 0;
mehatfie 15:c944ee3c8a5b 80 //
mehatfie 15:c944ee3c8a5b 81 // int numValuesFound = sscanf(_id.c_str(), "%d", &_idValue);
mehatfie 15:c944ee3c8a5b 82 // if (numValuesFound < 1){
mehatfie 15:c944ee3c8a5b 83 // ErrorOut("Parameter Unknown, id value can't be converted", lineData.lineNumber);
mehatfie 15:c944ee3c8a5b 84 // return -1;
mehatfie 15:c944ee3c8a5b 85 // }
mehatfie 11:bc9cd2869f95 86 //
mehatfie 15:c944ee3c8a5b 87 // int numValuesFound = sscanf(_length.c_str(), "%c", &_lengthValue);
mehatfie 11:bc9cd2869f95 88 // if (numValuesFound < 1){
mehatfie 15:c944ee3c8a5b 89 // ErrorOut("Parameter Unknown, length value can't be converted", lineData.lineNumber);
mehatfie 11:bc9cd2869f95 90 // return -1;
mehatfie 11:bc9cd2869f95 91 // }
mehatfie 11:bc9cd2869f95 92 //
mehatfie 15:c944ee3c8a5b 93 // int numDataVals = numWords - 4; //number of data bytes present in the line
mehatfie 15:c944ee3c8a5b 94 // const char* dataBytes[numDataVals];
mehatfie 15:c944ee3c8a5b 95 // int i = 0;
mehatfie 15:c944ee3c8a5b 96 // for (i = 0; i < numDataVals; i++){
mehatfie 15:c944ee3c8a5b 97 // string thisDataByte = lineData.word[4 + i];
mehatfie 15:c944ee3c8a5b 98 // int numValuesFound = sscanf(thisDataByte.c_str(), "%c", &dataBytes[i]);
mehatfie 15:c944ee3c8a5b 99 // if (numValuesFound < 1){
mehatfie 15:c944ee3c8a5b 100 // ErrorOut("Parameter Unknown, a data byte %d can't be converted", (i + 1), lineData.lineNumber);
mehatfie 15:c944ee3c8a5b 101 // return -1;
mehatfie 15:c944ee3c8a5b 102 // }
mehatfie 15:c944ee3c8a5b 103 // }
mehatfie 15:c944ee3c8a5b 104 //
mehatfie 11:bc9cd2869f95 105 // //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 106 // if (DummyMode)
mehatfie 11:bc9cd2869f95 107 // return 0; //Function operated successfully but doesn't return a value
mehatfie 11:bc9cd2869f95 108 //
mehatfie 15:c944ee3c8a5b 109 //
mehatfie 15:c944ee3c8a5b 110 // canDevice.write(CANMessage(_idValue, &dataBytes, _lengthValue));
mehatfie 11:bc9cd2869f95 111 // }
mehatfie 11:bc9cd2869f95 112 //
mehatfie 11:bc9cd2869f95 113 // /******************************************************************************/
mehatfie 11:bc9cd2869f95 114 // /*** <Func: forceBrake> ***/
mehatfie 11:bc9cd2869f95 115 // /******************************************************************************/
mehatfie 11:bc9cd2869f95 116 // else if (func.compare("forceBrake") == 0){
mehatfie 11:bc9cd2869f95 117 //
mehatfie 11:bc9cd2869f95 118 // if (lineData.numWords != 2){
mehatfie 11:bc9cd2869f95 119 // ErrorOut("Incorrect number of parameters", lineData.lineNumber);
mehatfie 11:bc9cd2869f95 120 // return -1;
mehatfie 11:bc9cd2869f95 121 // }
mehatfie 11:bc9cd2869f95 122 //
mehatfie 11:bc9cd2869f95 123 // //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 124 // if (DummyMode)
mehatfie 11:bc9cd2869f95 125 // return 0; //Function operated successfully but doesn't return a value
mehatfie 11:bc9cd2869f95 126 //
mehatfie 11:bc9cd2869f95 127 // bridges.forceBrake(getMotor());
mehatfie 11:bc9cd2869f95 128 // }
mehatfie 11:bc9cd2869f95 129 //
mehatfie 11:bc9cd2869f95 130 //
mehatfie 11:bc9cd2869f95 131 // /******************************************************************************/
mehatfie 11:bc9cd2869f95 132 // /*** <Func: drive> ***/
mehatfie 11:bc9cd2869f95 133 // /******************************************************************************/
mehatfie 11:bc9cd2869f95 134 // else if (func.compare("drive") == 0){
mehatfie 11:bc9cd2869f95 135 //
mehatfie 11:bc9cd2869f95 136 // if (lineData.numWords != 4){
mehatfie 11:bc9cd2869f95 137 // ErrorOut("Incorrect number of parameters", lineData.lineNumber);
mehatfie 11:bc9cd2869f95 138 // return -1;
mehatfie 11:bc9cd2869f95 139 // }
mehatfie 11:bc9cd2869f95 140 //
mehatfie 11:bc9cd2869f95 141 // //Initialize Parameters
mehatfie 11:bc9cd2869f95 142 // string speed = lineData.word[2];
mehatfie 11:bc9cd2869f95 143 // string dir = lineData.word[3];
mehatfie 11:bc9cd2869f95 144 //
mehatfie 11:bc9cd2869f95 145 // //Initialize Convertion Variables if needed
mehatfie 11:bc9cd2869f95 146 // float speedValue;
mehatfie 11:bc9cd2869f95 147 // int dirValue = 0;
mehatfie 11:bc9cd2869f95 148 //
mehatfie 11:bc9cd2869f95 149 // //Convert string to usable values
mehatfie 11:bc9cd2869f95 150 // int numValuesFound = sscanf(speed.c_str(), "%f", &speedValue);
mehatfie 11:bc9cd2869f95 151 // if (numValuesFound < 1){
mehatfie 11:bc9cd2869f95 152 // ErrorOut("Parameter Unknown, speed value can't be converted", lineData.lineNumber);
mehatfie 11:bc9cd2869f95 153 // return -1;
mehatfie 11:bc9cd2869f95 154 // }
mehatfie 11:bc9cd2869f95 155 //
mehatfie 11:bc9cd2869f95 156 // //Speed is given as a percentage of 100, so convert it to the value needed for the bridge.drive function
mehatfie 11:bc9cd2869f95 157 // speedValue = speedValue / 100;
mehatfie 11:bc9cd2869f95 158 //
mehatfie 11:bc9cd2869f95 159 //
mehatfie 11:bc9cd2869f95 160 // if (speedValue <= 0 && speedValue > 1.0){
mehatfie 11:bc9cd2869f95 161 // ErrorOut("Speed Value must be between 0 - 100", lineData.lineNumber);
mehatfie 11:bc9cd2869f95 162 // return -1;
mehatfie 11:bc9cd2869f95 163 // }
mehatfie 11:bc9cd2869f95 164 //
mehatfie 11:bc9cd2869f95 165 // if (dir.compare("CC") == 0 || dir.compare("cc") == 0)
mehatfie 11:bc9cd2869f95 166 // dirValue = -1; //Turn Clockwise
mehatfie 11:bc9cd2869f95 167 // else if (dir.compare("C") == 0 || dir.compare("c") == 0)
mehatfie 11:bc9cd2869f95 168 // dirValue = 1; //Turn CounterClockwise
mehatfie 11:bc9cd2869f95 169 //
mehatfie 11:bc9cd2869f95 170 // else{
mehatfie 11:bc9cd2869f95 171 // ErrorOut("Direction Value must be C or CC", lineData.lineNumber);
mehatfie 11:bc9cd2869f95 172 // return -1;
mehatfie 11:bc9cd2869f95 173 // }
mehatfie 11:bc9cd2869f95 174 //
mehatfie 11:bc9cd2869f95 175 // //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 176 // if (DummyMode)
mehatfie 11:bc9cd2869f95 177 // return 0; //Function operated successfully but doesn't return a value
mehatfie 11:bc9cd2869f95 178 //
mehatfie 11:bc9cd2869f95 179 // bridges.drive(getMotor(), dirValue, speedValue); //Turn on the Motor
mehatfie 11:bc9cd2869f95 180 // }
mehatfie 11:bc9cd2869f95 181 //
mehatfie 11:bc9cd2869f95 182 //
mehatfie 11:bc9cd2869f95 183 // /******************************************************************************/
mehatfie 11:bc9cd2869f95 184 // /**** <Func: off> ****/
mehatfie 11:bc9cd2869f95 185 // /******************************************************************************/
mehatfie 11:bc9cd2869f95 186 // else if (func.compare("off") == 0){
mehatfie 11:bc9cd2869f95 187 //
mehatfie 11:bc9cd2869f95 188 // if (lineData.numWords != 2){
mehatfie 11:bc9cd2869f95 189 // ErrorOut("Incorrect number of parameters", lineData.lineNumber);
mehatfie 11:bc9cd2869f95 190 // return -1;
mehatfie 11:bc9cd2869f95 191 // }
mehatfie 11:bc9cd2869f95 192 //
mehatfie 11:bc9cd2869f95 193 // //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 194 // if (DummyMode)
mehatfie 11:bc9cd2869f95 195 // return 0; //Function operated successfully but doesn't return a value
mehatfie 11:bc9cd2869f95 196 //
mehatfie 11:bc9cd2869f95 197 // off();
mehatfie 11:bc9cd2869f95 198 // }
mehatfie 11:bc9cd2869f95 199 //
mehatfie 11:bc9cd2869f95 200 // else {
mehatfie 11:bc9cd2869f95 201 // ErrorOut("Unknown Command for Motor Class", lineData.lineNumber);
mehatfie 11:bc9cd2869f95 202 // return -1;
mehatfie 11:bc9cd2869f95 203 // }
mehatfie 11:bc9cd2869f95 204 //
mehatfie 11:bc9cd2869f95 205 // return 0; //Return success as 0 since no condition had to be met
mehatfie 11:bc9cd2869f95 206 //}
mehatfie 11:bc9cd2869f95 207 //
mehatfie 11:bc9cd2869f95 208 //
mehatfie 11:bc9cd2869f95 209 //
mehatfie 11:bc9cd2869f95 210 ////For stopping the entire system if an error occurs, can be called from main
mehatfie 11:bc9cd2869f95 211 //int CAN_Device::off(void){
mehatfie 11:bc9cd2869f95 212 // bridges.drive(getMotor(), 0, 0); //Turn off the Motor
mehatfie 11:bc9cd2869f95 213 // return 0;
mehatfie 11:bc9cd2869f95 214 //}