![](/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
Diff: Devices/CAN_Device.cpp
- Revision:
- 11:bc9cd2869f95
- Child:
- 15:c944ee3c8a5b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Devices/CAN_Device.cpp Wed Oct 01 18:11:38 2014 +0000 @@ -0,0 +1,177 @@ +//#include "CAN_Device.hpp" +// +////Constructor +//CAN_Device::CAN_Device(LineData lineData){ +// +// //Order of Line: Command, Local_Name, CAN_DEVICE, selectedCAN(1,2), freq +// //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 +// if (lineData.numWords != 5) +// this->errorFlag = 1; +// +// string channelstr = lineData.word[3], freqstr = lineData.word[4]; //Parameters are numbers +// int tempChannel = -1, tempFreq = -1; +// int numValuesFound = sscanf(channelstr.c_str(), "%d", &tempChannel); +// if (numValuesFound < 1) +// this->errorFlag = 1; +// +// numValuesFound = sscanf(freqstr.c_str(), "%d", &tempFreq); +// if (numValuesFound < 1) +// this->errorFlag = 1; +// +// //channel must be either CAN1 or CAN2 +// if (tempChannel == 1 || tempChannel == 2){ +// this->selectedCAN = tempChannel; +// else +// this->errorFlag = 1; +// +// //should have a frequency greater than 0 +// if (tempFreq > 0) +// this->freq = tempFreq; +// else +// this->errorFlag = 1; +//} +// +// +//int CAN_Device::getSelectedCAN(){ +// return this->selectedCAN; +//} +// +//int CAN_Device::getFreq(){ +// return this->freq; +//} +// +////A line consists of [ __(Local_Name)__ __(function)__ __(parameter1)__ __(parameter2)__ __(parameter3)__ ... and so on] +//int CAN_Device::CAN_Device(LineData &lineData){ +// +// //Order of Line: Local_Name, Function_Name, Param1, Param2, Param3,....... +// string func = lineData.word[1]; +// +// /******************************************************************************/ +// /*** <Func: enableBrake> ***/ +// /******************************************************************************/ +// if (func.compare("write") == 0){ +// //line looks like: Local_Name, write, ID_val, byte +// if (lineData.numWords > 5){ +// ErrorOut("Incorrect number of parameters", lineData.lineNumber); +// return -1; +// } +// +// //Initialize and Convert Parameters +// string enable = lineData.word[2]; +// int enableValue = 0; +// +// int numValuesFound = sscanf(enable.c_str(), "%d", &enableValue); +// if (numValuesFound < 1){ +// 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); +// } +// +// /******************************************************************************/ +// /*** <Func: forceBrake> ***/ +// /******************************************************************************/ +// else if (func.compare("forceBrake") == 0){ +// +// if (lineData.numWords != 2){ +// 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.forceBrake(getMotor()); +// } +// +// +// /******************************************************************************/ +// /*** <Func: drive> ***/ +// /******************************************************************************/ +// else if (func.compare("drive") == 0){ +// +// if (lineData.numWords != 4){ +// ErrorOut("Incorrect number of parameters", lineData.lineNumber); +// return -1; +// } +// +// //Initialize Parameters +// string speed = lineData.word[2]; +// string dir = lineData.word[3]; +// +// //Initialize Convertion Variables if needed +// float speedValue; +// int dirValue = 0; +// +// //Convert string to usable values +// int numValuesFound = sscanf(speed.c_str(), "%f", &speedValue); +// if (numValuesFound < 1){ +// ErrorOut("Parameter Unknown, speed value can't be converted", lineData.lineNumber); +// return -1; +// } +// +// //Speed is given as a percentage of 100, so convert it to the value needed for the bridge.drive function +// speedValue = speedValue / 100; +// +// +// if (speedValue <= 0 && speedValue > 1.0){ +// ErrorOut("Speed Value must be between 0 - 100", lineData.lineNumber); +// return -1; +// } +// +// if (dir.compare("CC") == 0 || dir.compare("cc") == 0) +// dirValue = -1; //Turn Clockwise +// else if (dir.compare("C") == 0 || dir.compare("c") == 0) +// dirValue = 1; //Turn CounterClockwise +// +// else{ +// ErrorOut("Direction Value must be C or CC", 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(getMotor(), dirValue, speedValue); //Turn on the Motor +// } +// +// +// /******************************************************************************/ +// /**** <Func: off> ****/ +// /******************************************************************************/ +// else if (func.compare("off") == 0){ +// +// if (lineData.numWords != 2){ +// 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(); +// } +// +// else { +// ErrorOut("Unknown Command for Motor Class", lineData.lineNumber); +// return -1; +// } +// +// return 0; //Return success as 0 since no condition had to be met +//} +// +// +// +////For stopping the entire system if an error occurs, can be called from main +//int CAN_Device::off(void){ +// bridges.drive(getMotor(), 0, 0); //Turn off the Motor +// return 0; +//}