Skip to content

Commit

Permalink
Merge branch 'WIP' of https://github.com/jrickard/GEVCU into WIP
Browse files Browse the repository at this point in the history
Conflicts:
	CodaMotorController.cpp
	DmocMotorController.cpp
	GEVCU.h
	GEVCU.ino
	SerialConsole.cpp
  • Loading branch information
collin80 committed Aug 14, 2015
2 parents 1934ce1 + 3b6eb83 commit b4e4233
Show file tree
Hide file tree
Showing 109 changed files with 1,372 additions and 180 deletions.
2 changes: 2 additions & 0 deletions BatteryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,5 @@ signed int BatteryManager::getPackCurrent()
return packCurrent;
}



2 changes: 2 additions & 0 deletions BatteryManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ class BatteryManager : public Device {
};

#endif


2 changes: 2 additions & 0 deletions BrusaMotorController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,5 @@ void BrusaMotorController::saveConfiguration() {
// prefsHandler->write(EEMC_, config->enableOscillationLimiter);
prefsHandler->saveChecksum();
}


2 changes: 2 additions & 0 deletions BrusaMotorController.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,5 @@ class BrusaMotorController: public MotorController, CanObserver {
};

#endif /* BRUSAMOTORCONTROLLER_H_ */


2 changes: 2 additions & 0 deletions CanBrake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,5 @@ void CanBrake::saveConfiguration() {
prefsHandler->write(EETH_CAR_TYPE, config->carType);
prefsHandler->saveChecksum();
}


2 changes: 2 additions & 0 deletions CanBrake.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ class CanBrake: public Throttle, CanObserver {
};

#endif /* CAN_BRAKE_H_ */


70 changes: 63 additions & 7 deletions CanHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,15 @@ void CanHandler::detach(CanObserver* observer, uint32_t id, uint32_t mask) {
* \param frame - the received can frame to log
*/
void CanHandler::logFrame(CAN_FRAME& frame) {
if (Logger::isDebug()) {
Logger::debug("CAN: dlc=%X fid=%X id=%X ide=%X rtr=%X data=%X,%X,%X,%X,%X,%X,%X,%X",
frame.length, frame.fid, frame.id, frame.extended, frame.rtr,
frame.data.bytes[0], frame.data.bytes[1], frame.data.bytes[2], frame.data.bytes[3],
frame.data.bytes[4], frame.data.bytes[5], frame.data.bytes[6], frame.data.bytes[7]);
}
if (Logger::isDebug()) {
Logger::debug("CAN: dlc=%X fid=%X id=%X ide=%X rtr=%X data=%X,%X,%X,%X,%X,%X,%X,%X",
frame.length, frame.fid, frame.id, frame.extended, frame.rtr,
frame.data.bytes[0], frame.data.bytes[1], frame.data.bytes[2], frame.data.bytes[3],
frame.data.bytes[4], frame.data.bytes[5], frame.data.bytes[6], frame.data.bytes[7]);
}
}


/*
* Find a observerData entry which is not in use.
*
Expand Down Expand Up @@ -194,14 +195,17 @@ void CanHandler::process() {

if (bus->rx_avail()) {
bus->get_rx_buff(frame);
logFrame(frame);
//logFrame(frame);

for (int i = 0; i < CFG_CAN_NUM_OBSERVERS; i++) {
if (observerData[i].observer != NULL) {
// Apply mask to frame.id and observer.id. If they match, forward the frame to the observer
if ((frame.id & observerData[i].mask) == (observerData[i].id & observerData[i].mask))
observerData[i].observer->handleCanFrame(&frame);
}

if(frame.id==CAN_SWITCH)CANIO(frame);

}
}
}
Expand All @@ -210,6 +214,7 @@ void CanHandler::process() {
//(whatever happens to be open) or queue it to send (if nothing is open)
void CanHandler::sendFrame(CAN_FRAME& frame) {
bus->sendFrame(frame);
// logFrame(frame);
}

/*
Expand All @@ -219,3 +224,54 @@ void CanHandler::sendFrame(CAN_FRAME& frame) {
void CanObserver::handleCanFrame(CAN_FRAME *frame) {
Logger::error("CanObserver does not implement handleCanFrame(), frame.id=%d", frame->id);
}


void CanHandler::CANIO(CAN_FRAME& frame) {

static CAN_FRAME CANioFrame;

CANioFrame.id = CAN_OUTPUTS;
CANioFrame.length = 8;
CANioFrame.extended = 0; //standard frame
CANioFrame.rtr = 0;

for(int i=0;i==8;i++)
{
if(frame.data.bytes[i]==0x88)setOutput(i,true);
if(frame.data.bytes[i]==0xFF)setOutput(i,false);
}

for(int i=0;i==8;i++)
{
if(getOutput(i))CANioFrame.data.bytes[i]=0x88;
else CANioFrame.data.bytes[i]=0xFF;
}

sendFrame(CANioFrame);


CANioFrame.id = CAN_ANALOG_INPUTS;
int i=0;
uint16_t anaVal;

for(int j=0;j>6;j+=2)
{
anaVal=getAnalog(i++);
CANioFrame.data.bytes[j]=highByte (anaVal);
CANioFrame.data.bytes[j+1]=lowByte(anaVal);
}

sendFrame(CANioFrame);

CANioFrame.id = CAN_DIGITAL_INPUTS;
CANioFrame.length = 4;

for(int i=0;i==4;i++)
{
if (getDigital(i))CANioFrame.data.bytes[i]=0x88;
else CANioFrame.data.bytes[i]=0xff;
}

sendFrame(CANioFrame);
}

4 changes: 4 additions & 0 deletions CanHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <DueTimer.h>
#include "Logger.h"
#include "DeviceManager.h"
#include "sys_io.h"

class Device;

Expand All @@ -54,6 +55,7 @@ class CanHandler {
void detach(CanObserver *observer, uint32_t id, uint32_t mask);
void process();
void sendFrame(CAN_FRAME& frame);
void CANIO(CAN_FRAME& frame);
static CanHandler *getInstanceCar();
static CanHandler *getInstanceEV();
protected:
Expand All @@ -80,3 +82,5 @@ class CanHandler {
};

#endif /* CAN_HANDLER_H_ */


2 changes: 2 additions & 0 deletions CanPIDListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,5 @@ void CanPIDListener::saveConfiguration() {
//prefsHandler->saveChecksum();
}



4 changes: 3 additions & 1 deletion CanPIDListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,6 @@ class CanPIDListener: public Device, CanObserver {
bool processShowCustomData(CAN_FRAME* inFrame, CAN_FRAME& outFrame);
};

#endif //CAN_PID_H_
#endif //CAN_PID_H_


2 changes: 2 additions & 0 deletions CanThrottle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,5 @@ void CanThrottle::saveConfiguration() {
prefsHandler->write(EETH_CAR_TYPE, config->carType);
prefsHandler->saveChecksum();
}


2 changes: 2 additions & 0 deletions CanThrottle.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ class CanThrottle: public Throttle, CanObserver {
};

#endif /* CAN_THROTTLE_H_ */


23 changes: 15 additions & 8 deletions CodaMotorController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,21 @@ void CodaMotorController::handleCanFrame(CAN_FRAME *frame)


void CodaMotorController::handleTick() {

MotorController::handleTick(); //kick the ball up to papa
sendCmd1(); //Send our lone torque command
if (millis()-mss>2000 && online==0)
{
running=false; // We haven't received any UQM frames for over 2 seconds. Otherwise online would be 1.
mss=millis(); //So we've lost communications. Let's turn off the running light.
faultHandler.raiseFault(CODAUQM, FAULT_MOTORCTRL_COMM, true);
}
online=0;//This flag will be set to 1 by received frames.

if(!online) //This routine checks to see if we have received any frames from the inverter. If so, ONLINE would be true and
{ //we set the RUNNING light on. If no frames are received for 2 seconds, we set running OFF.
if (millis()-mss>2000)
{
running=false; // We haven't received any frames for over 2 seconds. Otherwise online would be true.
mss=millis(); //Reset our 2 second timer
}
}
else running=true;
online=false;//This flag will be set to true by received frames

}


Expand Down Expand Up @@ -330,3 +335,5 @@ void CodaMotorController::timestamp()
// Serial<<buffer<<"\n";
}



2 changes: 2 additions & 0 deletions CodaMotorController.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,5 @@ class CodaMotorController: public MotorController, CanObserver {

#endif /* CODA_H_ */



145 changes: 145 additions & 0 deletions DCDCController.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
* Delphi DC-DC Converter Controller.cpp
*
* CAN Interface to the Delphi DC-DC converter - Handles sending of commands and reception of status frames to drive the DC-DC converter and set its output voltage. SB following.
*
Copyright (c) 2014 Jack Rickard
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/



#include "DCDCController.h"
template<class T> inline Print &operator <<(Print &obj, T arg) { obj.print(arg); return obj; }



DCDCController::DCDCController() : Device()
{
prefsHandler = new PrefHandler(DCDC);
//prefsHandler->setEnabledStatus(true);

commonName = "Delphi DC-DC Converter";

}



void DCDCController::handleCanFrame(CAN_FRAME *frame)
{
Logger::debug("DCDC msg: %X", frame->id);
Logger::debug("DCDC data: %X%X%X%X%X%X%X%X", frame->data.bytes[0],frame->data.bytes[1],frame->data.bytes[2],frame->data.bytes[3],frame->data.bytes[4],frame->data.bytes[5],frame->data.bytes[6],frame->data.bytes[7]);
}



void DCDCController::setup()
{
TickHandler::getInstance()->detach(this);

loadConfiguration();
Device::setup(); // run the parent class version of this function

CanHandler::getInstanceCar()->attach(this, 0x1D5, 0x7ff, false);
//Watch for 0x1D5 messages from Delphi converter
TickHandler::getInstance()->attach(this, CFG_TICK_INTERVAL_DCDC);
}


void DCDCController::handleTick() {

Device::handleTick(); //kick the ball up to papa

sendCmd(); //Send our Delphi voltage control command

}


/*
1D7 08 80 77 00 00 00 00 00 00
For 13.0 vdc output.
1D7 08 80 8E 00 00 00 00 00 00
For 13.5 vdc output.
To request 14.0 vdc, the message was:
1D7 08 80 A5 00 00 00 00 00 00
*/

void DCDCController::sendCmd()
{
DCDCConfiguration *config = (DCDCConfiguration *)getConfiguration();

CAN_FRAME output;
output.length = 8;
output.id = 0x1D7;
output.extended = 0; //standard frame
output.rtr = 0;
output.fid = 0;
output.data.bytes[0] = 0x80;
output.data.bytes[1] = 0x8E;
output.data.bytes[2] = 0;
output.data.bytes[3] = 0;
output.data.bytes[4] = 0;
output.data.bytes[5] = 0;
output.data.bytes[6] = 0;
output.data.bytes[7] = 0x00;

CanHandler::getInstanceCar()->sendFrame(output);
timestamp();
Logger::debug("Delphi DC-DC cmd: %X %X %X %X %X %X %X %X %X %d:%d:%d.%d",output.id, output.data.bytes[0],
output.data.bytes[1],output.data.bytes[2],output.data.bytes[3],output.data.bytes[4],output.data.bytes[5],output.data.bytes[6],output.data.bytes[7], hours, minutes, seconds, milliseconds);
}

DeviceId DCDCController::getId() {
return (DCDC);
}

uint32_t DCDCController::getTickInterval()
{
return CFG_TICK_INTERVAL_DCDC;
}

void DCDCController::loadConfiguration() {
DCDCConfiguration *config = (DCDCConfiguration *)getConfiguration();

if (!config) {
config = new DCDCConfiguration();
setConfiguration(config);
}

Device::loadConfiguration(); // call parent
}

void DCDCController::saveConfiguration() {
Device::saveConfiguration();
}

void DCDCController::timestamp()
{
milliseconds = (int) (millis()/1) %1000 ;
seconds = (int) (millis() / 1000) % 60 ;
minutes = (int) ((millis() / (1000*60)) % 60);
hours = (int) ((millis() / (1000*60*60)) % 24);
}


Loading

0 comments on commit b4e4233

Please sign in to comment.