Skip to content

Commit

Permalink
Simplify CAN callbacks to use bytes rather than 32-bit words
Browse files Browse the repository at this point in the history
Virtually all CAN callbacks cast the two 32-bit words
the libopeninv library presents an incoming CAN
frame in to bytes. Rather than repeat this cast all over
the place replace with one central cast and change
the interface of the DecodeCAN callback methods.

The exceptions which require reverse casts of byte-
arrays back to 32-bit words are:
 - FCChademo
 - E65_Lever
 - OutlanderInverter

These could be changed to access the bytes directly but
this would require greater understanding and testing of
the code.

The changes are mechanical in nature and should not
affect the operation of the code.

Where applicable "override" is used for virtual methods
to make it clear to the compiler that virtual functions
are being overridden.

Tests:
 - Build for STM32 and Linux
  • Loading branch information
davefiddes committed Sep 28, 2024
1 parent 0f1153d commit c40635f
Show file tree
Hide file tree
Showing 66 changed files with 198 additions and 269 deletions.
2 changes: 1 addition & 1 deletion include/BMW_E31.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BMW_E31: public Vehicle
void Task1Ms();
void SetRevCounter(int s);
void SetTemperatureGauge(float temp);
void DecodeCAN(int id, uint32_t* data);
void DecodeCAN(int id, const uint8_t bytes[8]) override;
bool Ready();
bool Start();

Expand Down
2 changes: 1 addition & 1 deletion include/BMW_E39.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BMW_E39: public Vehicle
void Task100Ms();
void SetRevCounter(int s) { speed = s; }
void SetTemperatureGauge(float temp);
void DecodeCAN(int id, uint32_t* data);
void DecodeCAN(int id, const uint8_t bytes[8]) override;
bool Ready();
bool Start();
void SetE46(bool e46) { isE46 = e46; }
Expand Down
10 changes: 5 additions & 5 deletions include/BMW_E65.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class BMW_E65: public Vehicle
void Task200Ms();
void SetRevCounter(int speed) { revCounter = speed; }
void SetTemperatureGauge(float temp) { temperature = temp; }
void DecodeCAN(int, uint32_t* data);
void DecodeCAN(int id, const uint8_t bytes[8]) override;
bool Ready() { return terminal15On; }
bool Start() { return terminal15On; }
void DashOff();
void handle130(uint32_t data[2]);
void handle1A0(uint32_t data[2]);
void handle2FC(uint32_t data[2]);
void handle480(uint32_t data[2]);
void handle130(const uint8_t bytes[8]);
void handle1A0(const uint8_t bytes[8]);
void handle2FC(const uint8_t bytes[8]);
void handle480(const uint8_t bytes[8]);
void SetE90(bool e90) { isE90 = e90; }
void Engine_Data();
void SetFuelGauge(float level);
Expand Down
4 changes: 2 additions & 2 deletions include/CPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class CPCClass: public Chargerint

public:
void SetCanInterface(CanHardware* c);
void DecodeCAN(int id, uint32_t data[2]);
void DecodeCAN(int id, const uint8_t bytes[8]) override;
void Task10Ms();
void Task100Ms();
void Task200Ms();
bool DCFCRequest(bool RunCh);
bool ACRequest(bool RunCh);

private:
static void handle357(uint32_t data[2]);
static void handle357(const uint8_t bytes[8]);

static void Chg_Timers();
};
Expand Down
2 changes: 1 addition & 1 deletion include/Can_OBD2.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Can_OBD2
{
public:
void SetCanInterface(CanHardware *c);
void DecodeCAN(int id, uint32_t data[2]);
void DecodeCAN(int id, const uint8_t bytes[8]);

protected:
CanHardware *can;
Expand Down
2 changes: 1 addition & 1 deletion include/Can_OI.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Can_OI: public Inverter
{
public:
void Task100Ms() override;
void DecodeCAN(int, uint32_t*) override;
void DecodeCAN(int id, const uint8_t bytes[8]) override;
void SetTorque(float torquePercent) override;
float GetMotorTemperature() override { return motor_temp; }
float GetInverterTemperature() override { return inv_temp; }
Expand Down
2 changes: 1 addition & 1 deletion include/E65_Lever.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class E65_Lever: public Shifter

void Task10Ms();
void Task100Ms();
void DecodeCAN(int, uint32_t*);
void DecodeCAN(int id, const uint8_t bytes[8]) override;
bool GetGear(Shifter::Sgear& outGear);//if shifter class knows gear return true and set dir
void SetCanInterface(CanHardware* c);

Expand Down
4 changes: 2 additions & 2 deletions include/ElconCharger.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class ElconCharger: public Chargerhw
{

public:
void DecodeCAN(int id, uint32_t data[2]);
void DecodeCAN(int id, const uint8_t bytes[8]) override;
void Task200Ms();
bool ControlCharge(bool RunCh, bool ACReq);
void SetCanInterface(CanHardware* c);
void handle18FF50E5(uint32_t data[2]);
void handle18FF50E5(const uint8_t bytes[8]);
/*
static void handle108(uint32_t data[2]);
static bool HVreq;
Expand Down
2 changes: 1 addition & 1 deletion include/F30_Lever.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class F30_Lever: public Shifter

void Task10Ms();
void Task100Ms();
void DecodeCAN(int, uint32_t*);
void DecodeCAN(int id, const uint8_t bytes[8]) override;
bool GetGear(Shifter::Sgear& outGear);//if shifter class knows gear return true and set dir
void SetCanInterface(CanHardware* c);

Expand Down
8 changes: 4 additions & 4 deletions include/Focci.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class FocciClass: public Chargerint

public:
void SetCanInterface(CanHardware* c);
void DecodeCAN(int id, uint32_t data[2]);
void DecodeCAN(int id, const uint8_t bytes[8]) override;
void Task10Ms();
void Task100Ms();
void Task200Ms();
Expand All @@ -31,9 +31,9 @@ class FocciClass: public Chargerint
void CCS_Pwr_Con();

private:
static void handle357(uint32_t data[2]);
static void handle109(uint32_t data[2]);
static void handle596(uint32_t data[2]);
static void handle357(const uint8_t bytes[8]);
static void handle109(const uint8_t bytes[8]);
static void handle596(const uint8_t bytes[8]);
static void Chg_Timers();
};

Expand Down
2 changes: 1 addition & 1 deletion include/JLR_G1.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class JLR_G1: public Shifter

void Task10Ms();
void Task100Ms();
void DecodeCAN(int, uint32_t*);
void DecodeCAN(int id, const uint8_t bytes[8]) override;
bool GetGear(Shifter::Sgear& outGear);//if shifter class knows gear return true and set dir
void SetCanInterface(CanHardware* c);

Expand Down
2 changes: 1 addition & 1 deletion include/JLR_G2.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class JLR_G2: public Shifter

void Task10Ms();
void Task100Ms();
void DecodeCAN(int, uint32_t*);
void DecodeCAN(int id, const uint8_t bytes[8]) override;
bool GetGear(Shifter::Sgear& outGear);//if shifter class knows gear return true and set dir
void SetCanInterface(CanHardware* c);

Expand Down
2 changes: 1 addition & 1 deletion include/NissanPDM.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
class NissanPDM: public Chargerhw
{
public:
void DecodeCAN(int id, uint32_t data[2]);
void DecodeCAN(int id, const uint8_t bytes[8]) override;
void Task10Ms();
void Task100Ms();
bool ControlCharge(bool RunCh, bool ACReq);
Expand Down
4 changes: 2 additions & 2 deletions include/OutlanderCanHeater.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class OutlanderCanHeater : public Heater
public:
void SetTargetTemperature(float temp);
void SetCanInterface(CanHardware* c);
void DecodeCAN(int id, uint32_t data[2]);
void DecodeCAN(int id, const uint8_t bytes[8]);
void SetPower(uint16_t power, bool HeatReq);
void Task100Ms();

Expand All @@ -37,7 +37,7 @@ class OutlanderCanHeater : public Heater
int8_t desiredTemperature;

bool shouldHeat;
static void handle398(uint32_t data[2]);
static void handle398(const uint8_t bytes[8]);

};

Expand Down
2 changes: 1 addition & 1 deletion include/bms.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
class BMS
{
public:
virtual void DecodeCAN(int, uint8_t *) {};
virtual void DecodeCAN(int, const uint8_t[8]) {};
virtual void DeInit() {};
virtual float MaxChargeCurrent() { return 9999.0; };
virtual void Task100Ms() {
Expand Down
8 changes: 4 additions & 4 deletions include/bmw_sbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SBOX

public:
static void RegisterCanMessages(CanHardware* can);
static void DecodeCAN(int id, uint32_t data[2]);
static void DecodeCAN(int id, const uint8_t bytes[8]);
static void ControlContactors(int opmode, CanHardware* can);

static int32_t Voltage;
Expand All @@ -37,9 +37,9 @@ class SBOX
private:


static void handle200(uint32_t data[2]);
static void handle210(uint32_t data[2]);
static void handle220(uint32_t data[2]);
static void handle200(const uint8_t bytes[8]);
static void handle210(const uint8_t bytes[8]);
static void handle220(const uint8_t bytes[8]);

};

Expand Down
2 changes: 1 addition & 1 deletion include/chademo.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class FCChademo: public Chargerint
{
public:
void DecodeCAN(int id, uint32_t data[2]);
void DecodeCAN(int id, const uint8_t bytes[8]) override;
void Task100Ms();//Must be called every 100ms
void Task200Ms();
bool DCFCRequest(bool RunCh);
Expand Down
2 changes: 1 addition & 1 deletion include/chargerhw.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Chargerhw
virtual void Task10Ms() {} //Default does nothing
virtual void Task100Ms() {} //Default does nothing
virtual void Task200Ms() {} //Default does nothing
virtual void DecodeCAN(int, uint32_t*) {};
virtual void DecodeCAN(int, const uint8_t[8]) {};
virtual bool ControlCharge(bool, bool) {return false;};
virtual void DeInit() {} //called when switching to another charger, similar to a destructor
virtual void SetCanInterface(CanHardware* c) { can = c; }
Expand Down
2 changes: 1 addition & 1 deletion include/chargerint.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Chargerint
virtual void Task10Ms() {} //Default does nothing
virtual void Task100Ms() {} //Default does nothing
virtual void Task200Ms() {} //Default does nothing
virtual void DecodeCAN(int, uint32_t*) {};
virtual void DecodeCAN(int, const uint8_t[8]) {};
virtual bool DCFCRequest(bool) {return false;};
virtual bool ACRequest(bool) {return false;};
virtual void DeInit() {} //called when switching to another charger, similar to a destructor
Expand Down
2 changes: 1 addition & 1 deletion include/daisychainbms.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DaisychainBMS: public BMS
{
public:
void SetCanInterface(CanHardware* c) override;
void DecodeCAN(int id, uint8_t * data) override;
void DecodeCAN(int id, const uint8_t data[8]) override;
float MaxChargeCurrent() override;
void Task100Ms() override;
private:
Expand Down
2 changes: 1 addition & 1 deletion include/dcdc.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class DCDC
{
public:
virtual void DecodeCAN(int, uint8_t *) {};
virtual void DecodeCAN(int, const uint8_t[8]) {};
virtual void DeInit() {};
virtual void Task1Ms() {};
virtual void Task10Ms() {};
Expand Down
2 changes: 1 addition & 1 deletion include/heater.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class Heater
{
public:
virtual void DecodeCAN(int, uint32_t*) {};
virtual void DecodeCAN(int, const uint8_t[8]) {};
virtual float GetTemperature() { return 0; }
virtual void SetTargetTemperature(float temp) = 0; //target temperature in °C
virtual void SetPower(uint16_t power, bool HeatReq) = 0; //Must be called cyclically with power in watts
Expand Down
12 changes: 6 additions & 6 deletions include/i3LIM.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ class i3LIMClass: public Chargerint
{
public:
void SetCanInterface(CanHardware* c) override;
void DecodeCAN(int id, uint32_t* data) override;
void DecodeCAN(int id, const uint8_t bytes[8]) override;
void Task10Ms() override;
void Task100Ms() override;
void Task200Ms() override;
bool DCFCRequest(bool RunCh) override;
bool ACRequest(bool RunCh) override;

private:
void handle3B4(uint32_t data[2]);
void handle29E(uint32_t data[2]);
void handle2B2(uint32_t data[2]);
void handle2EF(uint32_t data[2]);
void handle272(uint32_t data[2]);
void handle3B4(const uint8_t bytes[8]);
void handle29E(const uint8_t bytes[8]);
void handle2B2(const uint8_t bytes[8]);
void handle2EF(const uint8_t bytes[8]);
void handle272(const uint8_t bytes[8]);
void CCS_Pwr_Con();
void Chg_Timers();
};
Expand Down
2 changes: 1 addition & 1 deletion include/inverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Inverter
virtual void Task1Ms() {} //Default does nothing
virtual void Task10Ms() {} //Default does nothing
virtual void Task100Ms() {} //Default does nothing
virtual void DecodeCAN(int, uint32_t*) {};
virtual void DecodeCAN(int, const uint8_t[8]) {};
virtual void SetTorque(float torquePercent) = 0;
virtual float GetMotorTemperature() = 0;
virtual float GetInverterTemperature() = 0;
Expand Down
18 changes: 9 additions & 9 deletions include/isa_shunt.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ISA
static void START(CanHardware* can);
static void RESTART(CanHardware* can);
static void deFAULT(CanHardware* can);
static void DecodeCAN(int id, uint32_t data[2]);
static void DecodeCAN(int id, const uint8_t bytes[8]);

static int32_t Voltage;
static int32_t Voltage2;
Expand All @@ -42,14 +42,14 @@ class ISA


private:
static void handle521(uint32_t data[2]);
static void handle522(uint32_t data[2]);
static void handle523(uint32_t data[2]);
static void handle524(uint32_t data[2]);
static void handle525(uint32_t data[2]);
static void handle526(uint32_t data[2]);
static void handle527(uint32_t data[2]);
static void handle528(uint32_t data[2]);
static void handle521(const uint8_t bytes[8]);
static void handle522(const uint8_t bytes[8]);
static void handle523(const uint8_t bytes[8]);
static void handle524(const uint8_t bytes[8]);
static void handle525(const uint8_t bytes[8]);
static void handle526(const uint8_t bytes[8]);
static void handle527(const uint8_t bytes[8]);
static void handle528(const uint8_t bytes[8]);
};

#endif /* SimpleISA_h */
2 changes: 1 addition & 1 deletion include/kangoobms.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class KangooBMS: public BMS
{
public:
void SetCanInterface(CanHardware* c) override;
void DecodeCAN(int id, uint8_t * data) override;
void DecodeCAN(int id, const uint8_t data[8]) override;
float MaxChargeCurrent() override;
void Task100Ms() override;

Expand Down
2 changes: 1 addition & 1 deletion include/leafbms.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class LeafBMS: public BMS
{
public:
void SetCanInterface(CanHardware* can) override;
void DecodeCAN(int id, uint8_t * data) override;
void DecodeCAN(int id, const uint8_t bytes[8]) override;
};

#endif // LEAFBMS_H
2 changes: 1 addition & 1 deletion include/leafinv.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
class LeafINV: public Inverter
{
public:
void DecodeCAN(int id, uint32_t data[2]);
void DecodeCAN(int id, const uint8_t bytes[8]) override;
void Task10Ms();
void Task100Ms();
static bool ControlCharge(bool RunCh);
Expand Down
8 changes: 4 additions & 4 deletions include/outlanderCharger.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class outlanderCharger: public Chargerhw
{

public:
void DecodeCAN(int id, uint32_t data[2]);
void DecodeCAN(int id, const uint8_t bytes[8]) override;
void Task100Ms();
bool ControlCharge(bool RunCh, bool ACReq);
void SetCanInterface(CanHardware* c);
Expand All @@ -51,9 +51,9 @@ static uint8_t chgStatus , evseDuty;
static float dcBusV , temp_1 , temp_2 , ACVolts , DCAmps , ACAmps;
static float LV_Volts , LV_Amps;

static void handle377(uint32_t data[2]);
static void handle389(uint32_t data[2]);
static void handle38A(uint32_t data[2]);
static void handle377(const uint8_t bytes[8]);
static void handle389(const uint8_t bytes[8]);
static void handle38A(const uint8_t bytes[8]);
};

#endif // OUTLANDERCHARGER_H
2 changes: 1 addition & 1 deletion include/outlanderinverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class OutlanderInverter : public Inverter
public:
OutlanderInverter();
void SetCanInterface(CanHardware* c);
void DecodeCAN(int id, uint32_t data[2]);
void DecodeCAN(int id, const uint8_t bytes[8]) override;
void Task10Ms();
void Task100Ms();
void SetTorque(float torque);
Expand Down
2 changes: 1 addition & 1 deletion include/rearoutlanderinverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class RearOutlanderInverter : public Inverter
public:
RearOutlanderInverter();
void SetCanInterface(CanHardware* c);
void DecodeCAN(int id, uint32_t data[2]);
void DecodeCAN(int id, const uint8_t bytes[8]) override;
void Task10Ms();
void Task100Ms();
void SetTorque(float torque);
Expand Down
Loading

0 comments on commit c40635f

Please sign in to comment.