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:
	ichip_2128.cpp
  • Loading branch information
jrickard committed Sep 21, 2014
1 parent e9bfdc2 commit 1a47d7c
Show file tree
Hide file tree
Showing 41 changed files with 868 additions and 194 deletions.
2 changes: 1 addition & 1 deletion CanHandler.cpp
Expand Up @@ -44,7 +44,7 @@ CanHandler::CanHandler(CanBusNode canBusNode) {
else
bus = &CAN;

for (int i; i < CFG_CAN_NUM_OBSERVERS; i++)
for (int i=0; i < CFG_CAN_NUM_OBSERVERS; i++)
observerData[i].observer = NULL;
}

Expand Down
3 changes: 2 additions & 1 deletion CanPIDListener.cpp
Expand Up @@ -101,7 +101,7 @@ void CanPIDListener::handleCanFrame(CAN_FRAME *frame) {
CAN_FRAME outputFrame;
bool ret;

if ((frame->id == 0x7E0) || (frame->id = 0x7DF)) {
if ((frame->id == 0x7E0) || (frame->id == 0x7DF)) {
//Do some common setup for our output - we won't pull the trigger unless we need to.
outputFrame.id = 0x7E8; //first ECU replying - TODO: Perhaps allow this to be configured from 0x7E8 - 0x7EF
outputFrame.data.bytes[1] = frame->data.bytes[1] + 0x40; //to show that this is a response
Expand Down Expand Up @@ -282,6 +282,7 @@ bool CanPIDListener::processShowCustomData(CAN_FRAME* inFrame, CAN_FRAME& outFra
int pid = inFrame->data.bytes[2] * 256 + inFrame->data.bytes[3];
switch (pid) {
}
return false;
}

DeviceId CanPIDListener::getId() {
Expand Down
1 change: 1 addition & 0 deletions Device.h
Expand Up @@ -33,6 +33,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "eeprom_layout.h"
#include "PrefHandler.h"
#include "Sys_Messages.h"
#include "FaultHandler.h"

/*
* A abstract class to hold device configuration. It is to be accessed
Expand Down
37 changes: 37 additions & 0 deletions DeviceManager.cpp
Expand Up @@ -292,3 +292,40 @@ void DeviceManager::printDeviceList() {
}
}
}


void DeviceManager::updateWifi() {

sendMessage(DEVICE_WIFI, ICHIP2128, MSG_CONFIG_CHANGE, NULL); //Load all our other parameters first

char param [2][20]; //A two element array containing id and enable state
char *paramPtr[2] = { &param[0][0], &param[1][0] }; //A two element array of pointers, pointing to the addresses of row 1 and row 2 of array.
//paramPtr[0] then contains address of param row 0 element 0
//paramPtr[1] then contains address of param row 1 element 0.


for (int i = 0; i < CFG_DEV_MGR_MAX_DEVICES; i++) { //Find all devices that are enabled and load into array
if (devices[i] && devices[i]->isEnabled())
{
sprintf(paramPtr[0],"x%X",devices[i]->getId());
sprintf(paramPtr[1],"255");
// Logger::console(" Device: %s value %s", paramPtr[0], paramPtr[1]);

sendMessage(DEVICE_WIFI, ICHIP2128, MSG_SET_PARAM, paramPtr); //Send the array to ichip by id (ie 1031) 255 indicates enabled
}
}

for (int i = 0; i < CFG_DEV_MGR_MAX_DEVICES; i++) { //Find all devices that are NOT enabled and load into array
if (devices[i] && !devices[i]->isEnabled())
{
sprintf(paramPtr[0],"x%X",devices[i]->getId());
sprintf(paramPtr[1],"0");
// Logger::console(" Device: %s value %s", paramPtr[0], paramPtr[1]);
sendMessage(DEVICE_WIFI, ICHIP2128, MSG_SET_PARAM, paramPtr); //Send array to ichip by id (ie 1002) 0 indicates disabled
}
}


}


2 changes: 2 additions & 0 deletions DeviceManager.h
Expand Up @@ -57,6 +57,8 @@ class DeviceManager {
Device *getDeviceByID(DeviceId);
Device *getDeviceByType(DeviceType);
void printDeviceList();
void updateWifi();
Device *updateWifiByID(DeviceId);

protected:

Expand Down
23 changes: 12 additions & 11 deletions DmocMotorController.cpp
Expand Up @@ -54,6 +54,7 @@ DmocMotorController::DmocMotorController() : MotorController() {
operationState = DISABLED;
actualState = DISABLED;
online = 0;
wentEnabled = false;
activityCount = 0;
// maxTorque = 2000;
commonName = "DMOC645 Inverter";
Expand All @@ -73,6 +74,7 @@ void DmocMotorController::setup() {

actualGear = NEUTRAL;
running = true;
setPowerMode(modeTorque);

TickHandler::getInstance()->attach(this, CFG_TICK_INTERVAL_MOTOR_CONTROLLER_DMOC);
}
Expand Down Expand Up @@ -165,18 +167,17 @@ void DmocMotorController::handleTick() {
if (activityCount > 0) {
activityCount--;
if (activityCount > 60) activityCount = 60;
if (actualState == DISABLED && activityCount > 40) {
setOpState(ENABLE);
setGear(DRIVE);
}
}
if (actualState == DISABLED && activityCount > 40 && !wentEnabled) {
if (getEnableIn() >= 0 && getEnableIn() < 4) setOpState(ENABLE);
if (getReverseIn() >= 0 && getReverseIn() < 4)setGear(DRIVE);
wentEnabled = true;
}
}
else {
setGear(NEUTRAL);
wentEnabled = false;
}

setPowerMode(modeTorque);


//if (online == 1) { //only send out commands if the controller is really there.
step = CHAL_RESP;
sendCmd1();
Expand All @@ -200,7 +201,7 @@ void DmocMotorController::sendCmd1() {
output.extended = 0; //standard frame
output.rtr = 0;

if (throttleRequested > 0 && operationState == ENABLE && selectedGear != NEUTRAL && powerMode == modeSpeed)
if (throttleRequested > 0 && operationState == ENABLE && selectedGear != NEUTRAL && config->motorMode == modeSpeed)
speedRequested = 20000 + (((long) throttleRequested * (long) config->speedMax) / 1000);
else
speedRequested = 20000;
Expand Down Expand Up @@ -247,11 +248,11 @@ void DmocMotorController::sendCmd2() {
//torqueRequested = 30000L + (((long)throttleRequested * (long)MaxTorque) / 1000L);

torqueCommand = 30000; //set offset for zero torque commanded
if (powerMode == modeTorque) {
if (config->motorMode == modeTorque) {
torqueRequested=0;
if (actualState == ENABLE) { //don't even try sending torque commands until the DMOC reports it is ready
if (selectedGear == DRIVE)
torqueRequested = (((long) throttleRequested * (long) config->torqueMax) / 1000L);
torqueRequested = (((long) throttleRequested * (long) config->torqueMax) / 1000L);
if (selectedGear == REVERSE)
torqueRequested = (((long) throttleRequested * (long) config->torqueMax) / 1000L);
}
Expand Down
7 changes: 4 additions & 3 deletions DmocMotorController.h
Expand Up @@ -80,9 +80,10 @@ class DmocMotorController: public MotorController, CanObserver {
byte online; //counter for whether DMOC appears to be operating
byte alive;
int activityCount;
uint16_t torqueCommand;
void timestamp();

uint16_t torqueCommand;
bool wentEnabled;

void timestamp();
void sendCmd1();
void sendCmd2();
void sendCmd3();
Expand Down
2 changes: 1 addition & 1 deletion ELM327Processor.cpp
Expand Up @@ -77,7 +77,7 @@ String ELM327Processor::processELMCmd(char *cmd) {
uint8_t pidnum = (uint8_t)(valu & 0xFF);
uint8_t mode = (uint8_t)((valu >> 8) & 0xFF);
Logger::debug(ELM327EMU, "Mode: %i, PID: %i", mode, pidnum);
char out[6];
char out[7];
char buff[10];
if (obd2Handler->processRequest(mode, pidnum, NULL, out)) {
if (bHeader) {
Expand Down
2 changes: 1 addition & 1 deletion ELM327_Emu.cpp
Expand Up @@ -167,7 +167,7 @@ DeviceId ELM327Emu::getId() {
}

void ELM327Emu::loadConfiguration() {
ELM327Configuration *config = new ELM327Configuration();
ELM327Configuration *config = (ELM327Configuration *)getConfiguration();

if (prefsHandler->checksumValid()) { //checksum is good, read in the values stored in EEPROM
Logger::debug(ELM327EMU, "Valid checksum so using stored elm327 emulator config values");
Expand Down
168 changes: 168 additions & 0 deletions FaultCodes.h
@@ -0,0 +1,168 @@
/*
* config.h
*
* Defines the allowable fault codes
Copyright (c) 2014 Collin Kidder, Michael Neuweiler, Charles Galpin, 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.
*
*/

#ifndef FAULTCODES_H_
#define FAULTCODES_H_

/*
Format these fault codes in DTC format.
DTC uses 16 bits to store a code
Byte A is the first byte, B is the second byte
A7-6 = Which fault system (00=P=PowerTrain, 01=C=Chassis, 10=B=Body, 11=U=Network)
A5-4 = First Digit (0-3)
A3-0 = Second Digit (0-F)
B7-4 = Third Digit (0-F)
B3-0 = Last / Fourth Digit (0-F)
Many codes are already used in ICE vehicles but rarely with hex digits so exclusively use
codes with hex digits to avoid overlap
*/

enum FAULTCODE {
FAULT_NONE = 0,

//The A throttle seems to be stuck low
FAULT_THROTTLE_LOW_A = 0x0F01, //P0F01

//The A throttle seems to be stuck high
FAULT_THROTTLE_HIGH_A = 0x0F02, //P0F02

//The B throttle seems to be stuck low
FAULT_THROTTLE_LOW_B = 0x0F06, //P0F06

//The B throttle seems to be stuck high
FAULT_THROTTLE_HIGH_B = 0x0F07, //P0F07

//The C throttle seems to be stuck low
FAULT_THROTTLE_LOW_C = 0x0F0A, //P0F0A

//The C throttle seems to be stuck high
FAULT_THROTTLE_HIGH_C = 0x0F0B, //P0F0B

//Throttles A and B do not match
FAULT_THROTTLE_MISMATCH_AB = 0x0F11, //P0F11

//Throttles A and C do not match
FAULT_THROTTLE_MISMATCH_AC = 0x0F12, //P0F12

//Throttles B and C do not match
FAULT_THROTTLE_MISMATCH_BC = 0x0F13, //P0F13

//There was a general fault in the throttle
FAULT_THROTTLE_MISC = 0x0F40, //P0F40

//There was a problem communicating with an external throttle module
FAULT_THROTTLE_COMM = 0x0F60, //P0F60

//The brake input seems to be stuck low
FAULT_BRAKE_LOW = 0x0B01, //P0B01

//The brake input seems to be stuck high
FAULT_BRAKE_HIGH = 0x0B02, //P0B02

//There was a problem communicating with an external brake module
FAULT_BRAKE_COMM = 0x0B60, //P0B60

//The +12V battery or DC/DC system seems to have excessively high voltage
FAULT_12V_BATT_HIGH = 0x0A01, //P0A01

//The +12V battery or DC/DC system seems to have excessively low voltage
FAULT_12V_BATT_LOW = 0x0A02, //P0A02

//The HV battery has too high of a voltage
FAULT_HV_BATT_HIGH = 0x0A11, //P0A11

//The HV battery has too low of a voltage
FAULT_HV_BATT_LOW = 0x0A12, //P0A12

//A request has been made for more current than allowable from the HV battery
FAULT_HV_BATT_OVERCURR = 0x0A30, //P0A30

//The HV battery is too cold
FAULT_HV_BATT_UNDERTEMP = 0x0A50, //P0A50

//The HV battery is too hot
FAULT_HV_BATT_OVERTEMP = 0x0A51, //P0A51

//There is a problem with isolation of HV from the chassis
FAULT_HV_BATT_ISOLATION = 0x0A70, //P0A70

//A cell in the HV pack is too high of a voltage
FAULT_HV_CELL_HIGH = 0x0AA1, //P0AA1

//A cell in the HV pack is too low of a voltage
FAULT_HV_CELL_LOW = 0x0AA2, //P0AA2

//A cell in the HV pack is too cold
FAULT_HV_CELL_UNDERTEMP = 0x0AB0, //P0AB0

//A cell in the HV pack is too hot
FAULT_HV_CELL_OVERTEMP = 0x0AB1, //P0AB1

//There was a problem communicating with the BMS
FAULT_BMS_COMM = 0xCC60, //U0C60

//There was a general fault at the BMS
FAULT_BMS_MISC = 0xCC40, //U0C40

//The motor is too hot
FAULT_MOTOR_OVERTEMP = 0x0D50, //P0D50

//The motor controller is too hot
FAULT_MOTORCTRL_OVERTEMP = 0x0D80, //P0D80

//There was a problem communicating with the motor controller
FAULT_MOTORCTRL_COMM = 0x0D60, //P0D60

//There was a general fault in the motor controller
FAULT_MOTORCTRL_MISC = 0x0D40, //P0D40

//The motor and controller cannot satisfy the torque request
FAULT_MOTORCTRL_INSUFF_TORQUE = 0x0D10, //P0D10

//The motor is spinning faster that it should be
FAULT_MOTORCTRL_EXCESSIVE_SPEED = 0x0D20, //P0D20

//The motor is providing more torque than it should be (didn't request this much)
FAULT_MOTORCTRL_EXCESSIVE_TORQUE = 0x0D25, //P0D25

//It seems that we cannot enable the motor controller though we've tried.
FAULT_MOTORCTRL_CANT_ENABLE = 0x0DA0, //P0DA0

//It seems we cannot go into drive even though we asked to go into drive
FAULT_MOTORCTRL_CANT_DRIVE = 0x0DA4, //P0DA4

//It seems we cannot go into reverse even though we asked to go into reverse
FAULT_MOTORCTRL_CANT_REVERSE = 0x0DA8, //P0DA8

//there was a request for power from the motor but the controller is not in a state to provide power
FAULT_MOTORCTRL_POWERREQ_INV = 0x0DB0 //P0DB0
};


#endif

0 comments on commit 1a47d7c

Please sign in to comment.