Skip to content

Commit

Permalink
Lev: Fixes found during validation
Browse files Browse the repository at this point in the history
Also fix a bitfield design error, disjoint fields are the worst
  • Loading branch information
cujomalainey committed Feb 6, 2022
1 parent 590c6ab commit f6b4e05
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 15 deletions.
1 change: 1 addition & 0 deletions examples/LEVDisplay/LEVDisplay.ino
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ void levSpeedSystemInformation2Handler(LevSpeedSystemInformation2& msg, uintptr_
} else {
Serial.println(percent);
}
printCommonSpeedSystemInformation(msg);
}

void levBatteryInformation(LevBatteryInformation& msg, uintptr_t data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ LevCoreSpeedDistanceInformation<T>::LevCoreSpeedDistanceInformation() :

template<class T>
uint32_t LevCoreSpeedDistanceInformation<T>::getOdometer() { // in km
return this->get32BitValue(ODOMETER_LSB_BYTE, ODOMETER_MSB_BYTE);
return this->get24BitValue(ODOMETER_LSB_BYTE, ODOMETER_MSB_BYTE);
}

template<class T>
Expand All @@ -35,7 +35,7 @@ LevBaseSpeedDistanceInformationMsg::LevBaseSpeedDistanceInformationMsg(uint8_t d
LevCoreSpeedDistanceInformation<BroadcastDataMsg>() {}

void LevBaseSpeedDistanceInformationMsg::setOdometer(uint32_t odometer) {
set32BitValue(odometer, ODOMETER_LSB_BYTE, ODOMETER_MSB_BYTE);
set24BitValue(odometer, ODOMETER_LSB_BYTE, ODOMETER_MSB_BYTE);
}

void LevBaseSpeedDistanceInformationMsg::setLevSpeed(uint16_t speed) {
Expand Down
23 changes: 13 additions & 10 deletions src/Profiles/Lev/DataPages/ANTPLUS_LevBatteryInformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#define CHARGINGCYCLECOUNT_MSB_BYTE 3
#define CHARGINGCYCLECOUNT_MASK 0x0FFF
#define FUELCONSUMPTION_LSB_BYTE 4
#define FUELCONSUMPTION_MSB_BYTE 3
#define FUELCONSUMPTION_MASK 0xF0
#define FUELCONSUMPTION_SHIFT 4
#define FUELCONSUMPTION_MSN_BYTE 3
#define FUELCONSUMPTION_MSN_MASK 0xF0
#define FUELCONSUMPTION_MSN_SHIFT 4
#define BATTERYVOLTAGE_BYTE 5
#define DISTANCEONCURRENTCHARGE_LSB_BYTE 6
#define DISTANCEONCURRENTCHARGE_MSB_BYTE 7
Expand All @@ -23,11 +23,13 @@ uint16_t LevBaseBatteryInformation<T>::getChargingCycleCount() {
CHARGINGCYCLECOUNT_MSB_BYTE, CHARGINGCYCLECOUNT_MASK);
}

// NOTE this a bit inverted field which results in the non-sense below
template<class T>
uint16_t LevBaseBatteryInformation<T>::getFuelConsumption() {
return this->get16BitValue(FUELCONSUMPTION_LSB_BYTE,
FUELCONSUMPTION_MSB_BYTE, FUELCONSUMPTION_MASK,
FUELCONSUMPTION_SHIFT);
return this->get8BitValue(FUELCONSUMPTION_LSB_BYTE) |
(((uint16_t)this->get8BitValue(FUELCONSUMPTION_MSN_BYTE,
FUELCONSUMPTION_MSN_MASK,
FUELCONSUMPTION_MSN_SHIFT)) << BITS_IN_BYTE);
}

template<class T>
Expand Down Expand Up @@ -60,11 +62,12 @@ void LevBatteryInformationMsg::setChargingCycleCount(uint16_t cycleCount) {
CHARGINGCYCLECOUNT_MASK);
}

// NOTE this a bit inverted field which results in the non-sense below
void LevBatteryInformationMsg::setFuelConsumption(uint16_t consumption) {
set16BitValue(consumption, FUELCONSUMPTION_LSB_BYTE,
FUELCONSUMPTION_MSB_BYTE,
FUELCONSUMPTION_MASK,
FUELCONSUMPTION_SHIFT);
set8BitValue(consumption & 0xFF, FUELCONSUMPTION_LSB_BYTE);
set8BitValue(consumption >> BITS_IN_BYTE, FUELCONSUMPTION_MSN_BYTE,
FUELCONSUMPTION_MSN_MASK,
FUELCONSUMPTION_MSN_SHIFT);
}

void LevBatteryInformationMsg::setBatteryVoltage(uint8_t voltage) {
Expand Down
2 changes: 1 addition & 1 deletion src/Profiles/Lev/DataPages/ANTPLUS_LevCapabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define TRAVELMODESSUPPORTED_NUMBERREGENERATIVEMODES_MASK 0x7
#define WHEELCIRCUMFERENCE_LSB_BYTE 3
#define WHEELCIRCUMFERENCE_MSB_BYTE 4
#define WHEELCIRCUMFERENCE_MASK 0xF
#define WHEELCIRCUMFERENCE_MASK 0xFFF

template<class T>
LevBaseCapabilities<T>::LevBaseCapabilities() : CoreDataPage<T>() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#define TEMPERATURESTATE_MOTORTEMPERATUREALERT_SHIFT 7
#define TEMPERATURESTATE_MOTORTEMPERATUREALERT_MASK 0x80
#define ERRORMESSAGE_BYTE 5
#define RESERVED_BYTE 7
#define RESERVED_MASK 0xF
#define RESERVED_SHIFT 4

template<class T>
LevBaseSpeedSystemInformation1<T>::LevBaseSpeedSystemInformation1() :
Expand Down Expand Up @@ -57,7 +60,9 @@ LevSpeedSystemInformation1::LevSpeedSystemInformation1(AntRxDataResponse& dp) :

LevSpeedSystemInformation1Msg::LevSpeedSystemInformation1Msg() :
LevBaseSpeedSystemInformationMsg(ANTPLUS_LEV_DATAPAGE_SPEEDSYSTEMINFORMATION1_NUMBER),
LevBaseSpeedSystemInformation1<BroadcastDataMsg>() {}
LevBaseSpeedSystemInformation1<BroadcastDataMsg>() {
set8BitValue(RESERVED_BYTE, RESERVED_MASK, RESERVED_SHIFT);
}

void LevSpeedSystemInformation1Msg::setBatteryTemperatureState(uint8_t state) {
set8BitValue(state, TEMPERATURESTATE_BYTE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#define BATTERYSOC_BATTERYEMPTY_SHIFT 7
#define BATTERYSOC_BATTERYEMPTY_MASK 0x80
#define PERCENTASSIST_BYTE 5
#define RESERVED_BYTE 7
#define RESERVED_MASK 0xF
#define RESERVED_SHIFT 4

template<class T>
LevBaseSpeedSystemInformation2<T>::LevBaseSpeedSystemInformation2() :
Expand Down Expand Up @@ -37,7 +40,9 @@ LevSpeedSystemInformation2::LevSpeedSystemInformation2(AntRxDataResponse& dp) :

LevSpeedSystemInformation2Msg::LevSpeedSystemInformation2Msg() :
LevBaseSpeedSystemInformationMsg(ANTPLUS_LEV_DATAPAGE_SPEEDSYSTEMINFORMATION2_NUMBER),
LevBaseSpeedSystemInformation2<BroadcastDataMsg>() {}
LevBaseSpeedSystemInformation2<BroadcastDataMsg>() {
set8BitValue(RESERVED_BYTE, RESERVED_MASK, RESERVED_SHIFT);
}

void LevSpeedSystemInformation2Msg::setBatterySOC(uint8_t soc) {
set8BitValue(soc, BATTERYSOC_BYTE, BATTERYSOC_STATEOFCHARGE_MASK);
Expand Down

0 comments on commit f6b4e05

Please sign in to comment.