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:
- 15:c944ee3c8a5b
- Parent:
- 11:bc9cd2869f95
- Child:
- 16:2482d226cf4d
diff -r 953820302fb7 -r c944ee3c8a5b Devices/CAN_Device.cpp --- a/Devices/CAN_Device.cpp Thu Oct 02 23:49:44 2014 +0000 +++ b/Devices/CAN_Device.cpp Fri Oct 03 17:31:04 2014 +0000 @@ -20,7 +20,18 @@ // // //channel must be either CAN1 or CAN2 // if (tempChannel == 1 || tempChannel == 2){ -// this->selectedCAN = tempChannel; +// if (tempChannel == 1){ +// this->pinRD = p30; +// this->pinTD = p29; +// } +// else if (tempChannel == 2){ +// this->pinRD = p9; +// this->pinTD = p10; +// } +// +// this->selectedCAN = tempChannel; +// } +// // else // this->errorFlag = 1; // @@ -43,34 +54,60 @@ ////A line consists of [ __(Local_Name)__ __(function)__ __(parameter1)__ __(parameter2)__ __(parameter3)__ ... and so on] //int CAN_Device::CAN_Device(LineData &lineData){ // +// //Initialize the CAN device +// CAN canDevice(pinRD, pinTD); +// canDevice.frequency(125000); +// // //Order of Line: Local_Name, Function_Name, Param1, Param2, Param3,....... // string func = lineData.word[1]; // // /******************************************************************************/ -// /*** <Func: enableBrake> ***/ +// /*** <Func: write> ***/ // /******************************************************************************/ // if (func.compare("write") == 0){ -// //line looks like: Local_Name, write, ID_val, byte -// if (lineData.numWords > 5){ +// //line looks like: Local_Name, write, ID_val, length_val, data +// 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; +// string _id = lineData.word[2]; +// string _length = lineData.word[3]; +// string _data = lineData.word[4]; +// int _idValue = 0; +// char _lengthValue = 0; +// +// int numValuesFound = sscanf(_id.c_str(), "%d", &_idValue); +// if (numValuesFound < 1){ +// ErrorOut("Parameter Unknown, id value can't be converted", lineData.lineNumber); +// return -1; +// } // -// int numValuesFound = sscanf(enable.c_str(), "%d", &enableValue); +// int numValuesFound = sscanf(_length.c_str(), "%c", &_lengthValue); // if (numValuesFound < 1){ -// ErrorOut("Parameter Unknown, enableBrake value can't be converted", lineData.lineNumber); +// ErrorOut("Parameter Unknown, length value can't be converted", lineData.lineNumber); // return -1; // } // +// int numDataVals = numWords - 4; //number of data bytes present in the line +// const char* dataBytes[numDataVals]; +// int i = 0; +// for (i = 0; i < numDataVals; i++){ +// string thisDataByte = lineData.word[4 + i]; +// int numValuesFound = sscanf(thisDataByte.c_str(), "%c", &dataBytes[i]); +// if (numValuesFound < 1){ +// ErrorOut("Parameter Unknown, a data byte %d can't be converted", (i + 1), 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); +// +// canDevice.write(CANMessage(_idValue, &dataBytes, _lengthValue)); // } // // /******************************************************************************/