Skip to content

Commit

Permalink
Lev: SpeedSystemInformation: move to core datapage format
Browse files Browse the repository at this point in the history
also optimize display code
  • Loading branch information
cujomalainey committed Feb 5, 2022
1 parent 303911e commit 4b75c24
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,103 @@
#define LEVSPEED_MSB_BYTE 7
#define LEVSPEED_MASK 0x0FFF

LevBaseSpeedSystemInformation::LevBaseSpeedSystemInformation(AntRxDataResponse& dp) :
LevBaseMainDataPage(dp) {}
template<class T>
LevCoreSpeedSystemInformation<T>::LevCoreSpeedSystemInformation() :
CoreDataPage<T>() {}

uint8_t LevBaseSpeedSystemInformation::getCurrentRegenerativeLevel() {
template<class T>
uint8_t LevCoreSpeedSystemInformation<T>::getCurrentRegenerativeLevel() {
return this->get8BitValue(TRAVELMODESTATE_BYTE,
TRAVELMODESTATE_CURRENTREGENERATIVELEVEL_MASK);
}

uint8_t LevBaseSpeedSystemInformation::getCurrentAssistLevel() {
template<class T>
uint8_t LevCoreSpeedSystemInformation<T>::getCurrentAssistLevel() {
return this->get8BitValue(TRAVELMODESTATE_BYTE,
TRAVELMODESTATE_CURRENTASSISTLEVEL_MASK,
TRAVELMODESTATE_CURRENTASSISTLEVEL_SHIFT);
}

uint8_t LevBaseSpeedSystemInformation::getSystemState() {
template<class T>
uint8_t LevCoreSpeedSystemInformation<T>::getSystemState() {
return this->get8BitValue(SYSTEMSTATE_BYTE);
}

uint8_t LevBaseSpeedSystemInformation::getCurrentFrontGear() {
template<class T>
uint8_t LevCoreSpeedSystemInformation<T>::getCurrentFrontGear() {
return this->get8BitValue(GEARSTATE_BYTE, GEARSTATE_CURRENTFRONTGEAR_MASK);
}

uint8_t LevBaseSpeedSystemInformation::getCurrentRearGear() {
template<class T>
uint8_t LevCoreSpeedSystemInformation<T>::getCurrentRearGear() {
return this->get8BitValue(GEARSTATE_BYTE, GEARSTATE_CURRENTREARGEAR_MASK,
GEARSTATE_CURRENTREARGEAR_SHIFT);
}

uint8_t LevBaseSpeedSystemInformation::getManualAutoState() {
template<class T>
uint8_t LevCoreSpeedSystemInformation<T>::getManualAutoState() {
return this->get8BitValue(GEARSTATE_BYTE, GEARSTATE_MANUALAUTO_MASK,
GEARSTATE_MANUALAUTO_SHIFT);
}

uint8_t LevBaseSpeedSystemInformation::getGearExist() {
template<class T>
uint8_t LevCoreSpeedSystemInformation<T>::getGearExist() {
return this->get8BitValue(GEARSTATE_BYTE, GEARSTATE_GEAREXIST_MASK,
GEARSTATE_GEAREXIST_SHIFT);
}

uint16_t LevBaseSpeedSystemInformation::getSpeed() { // in 1/10 km/h
template<class T>
uint16_t LevCoreSpeedSystemInformation<T>::getSpeed() { // in 1/10 km/h
return this->get16BitValue(LEVSPEED_LSB_BYTE, LEVSPEED_MSB_BYTE,
LEVSPEED_MASK);
}

template class LevCoreSpeedSystemInformation<BroadcastData>;
template class LevCoreSpeedSystemInformation<BroadcastDataMsg>;

LevBaseSpeedSystemInformation::LevBaseSpeedSystemInformation(AntRxDataResponse& dp) :
LevBaseMainDataPage(dp),
LevCoreSpeedSystemInformation<BroadcastData>() {}

LevBaseSpeedSystemInformationMsg::LevBaseSpeedSystemInformationMsg(uint8_t dataPageNumber) :
LevBaseMainDataPageMsg<BroadcastDataMsg>(dataPageNumber),
LevCoreSpeedSystemInformation<BroadcastDataMsg>() {}

void LevBaseSpeedSystemInformationMsg::setCurrentRegenerativeLevel(uint8_t level) {
set8BitValue(level, TRAVELMODESTATE_BYTE,
TRAVELMODESTATE_CURRENTREGENERATIVELEVEL_MASK);
}

void LevBaseSpeedSystemInformationMsg::setCurrentAssistLevel(uint8_t level) {
set8BitValue(level, TRAVELMODESTATE_BYTE,
TRAVELMODESTATE_CURRENTASSISTLEVEL_MASK,
TRAVELMODESTATE_CURRENTASSISTLEVEL_SHIFT);
}

void LevBaseSpeedSystemInformationMsg::setSystemState(uint8_t state) {
set8BitValue(state, SYSTEMSTATE_BYTE);
}

void LevBaseSpeedSystemInformationMsg::setCurrentFrontGear(uint8_t gear) {
set8BitValue(gear, GEARSTATE_BYTE, GEARSTATE_CURRENTFRONTGEAR_MASK);
}

void LevBaseSpeedSystemInformationMsg::setCurrentRearGear(uint8_t gear) {
set8BitValue(gear, GEARSTATE_BYTE, GEARSTATE_CURRENTREARGEAR_MASK,
GEARSTATE_CURRENTREARGEAR_SHIFT);
}

void LevBaseSpeedSystemInformationMsg::setManualAutoState(uint8_t state) {
set8BitValue(state, GEARSTATE_BYTE, GEARSTATE_MANUALAUTO_MASK,
GEARSTATE_MANUALAUTO_SHIFT);
}

void LevBaseSpeedSystemInformationMsg::setGearExist(uint8_t exists) {
set8BitValue(exists, GEARSTATE_BYTE, GEARSTATE_GEAREXIST_MASK,
GEARSTATE_GEAREXIST_SHIFT);
}

void LevBaseSpeedSystemInformationMsg::setSpeed(uint16_t speed) { // in 1/10 km/h
set16BitValue(speed, LEVSPEED_LSB_BYTE, LEVSPEED_MSB_BYTE,
LEVSPEED_MASK);
}
23 changes: 21 additions & 2 deletions src/Profiles/Lev/DataPages/ANTPLUS_LevBaseSpeedSystemInformation.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

#include <Profiles/Lev/DataPages/ANTPLUS_LevBaseMainDataPage.h>

class LevBaseSpeedSystemInformation : public LevBaseMainDataPage {
template<class T>
class LevCoreSpeedSystemInformation : virtual public CoreDataPage<T> {
public:
explicit LevBaseSpeedSystemInformation(AntRxDataResponse& dp);
LevCoreSpeedSystemInformation();
uint8_t getCurrentRegenerativeLevel();
uint8_t getCurrentAssistLevel();
uint8_t getSystemState();
Expand All @@ -16,4 +17,22 @@ class LevBaseSpeedSystemInformation : public LevBaseMainDataPage {
uint16_t getSpeed(); // in 1/10 km/h
};

class LevBaseSpeedSystemInformation : public LevBaseMainDataPage, public LevCoreSpeedSystemInformation<BroadcastData> {
public:
explicit LevBaseSpeedSystemInformation(AntRxDataResponse& dp);
};

class LevBaseSpeedSystemInformationMsg : public LevBaseMainDataPageMsg<BroadcastDataMsg>, public LevCoreSpeedSystemInformation<BroadcastDataMsg> {
public:
LevBaseSpeedSystemInformationMsg(uint8_t dataPageNumber);
void setCurrentRegenerativeLevel(uint8_t level);
void setCurrentAssistLevel(uint8_t level);
void setSystemState(uint8_t state);
void setCurrentFrontGear(uint8_t gear);
void setCurrentRearGear(uint8_t gear);
void setManualAutoState(uint8_t state);
void setGearExist(uint8_t exists);
void setSpeed(uint16_t speed); // in 1/10 km/h
};

#endif // ANTPLUS_LEVBASESPEEDSYSTEMINFORMATION_h
60 changes: 52 additions & 8 deletions src/Profiles/Lev/DataPages/ANTPLUS_LevSpeedSystemInformation1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,78 @@
#define TEMPERATURESTATE_MOTORTEMPERATUREALERT_MASK 0x80
#define ERRORMESSAGE_BYTE 5

LevSpeedSystemInformation1::LevSpeedSystemInformation1(AntRxDataResponse& dp) :
LevBaseSpeedSystemInformation(dp) {}
template<class T>
LevBaseSpeedSystemInformation1<T>::LevBaseSpeedSystemInformation1() :
CoreDataPage<T>() {}

uint8_t LevSpeedSystemInformation1::getBatteryTemperatureState() {
template<class T>
uint8_t LevBaseSpeedSystemInformation1<T>::getBatteryTemperatureState() {
return this->get8BitValue(TEMPERATURESTATE_BYTE,
TEMPERATURESTATE_BATTERYTEMPERATURE_MASK);
}

uint8_t LevSpeedSystemInformation1::getBatteryTemperatureAlert() {
template<class T>
uint8_t LevBaseSpeedSystemInformation1<T>::getBatteryTemperatureAlert() {
return this->get8BitValue(TEMPERATURESTATE_BYTE,
TEMPERATURESTATE_BATTERYTEMPERATUREALERT_MASK,
TEMPERATURESTATE_BATTERYTEMPERATUREALERT_SHIFT);
}

uint8_t LevSpeedSystemInformation1::getMotorTemperatureState() {
template<class T>
uint8_t LevBaseSpeedSystemInformation1<T>::getMotorTemperatureState() {
return this->get8BitValue(TEMPERATURESTATE_BYTE,
TEMPERATURESTATE_MOTORTEMPERATURE_MASK,
TEMPERATURESTATE_MOTORTEMPERATURE_SHIFT);
}

uint8_t LevSpeedSystemInformation1::getMotorTemperatureAlert() {
template<class T>
uint8_t LevBaseSpeedSystemInformation1<T>::getMotorTemperatureAlert() {
return this->get8BitValue(TEMPERATURESTATE_BYTE,
TEMPERATURESTATE_MOTORTEMPERATUREALERT_MASK,
TEMPERATURESTATE_MOTORTEMPERATUREALERT_SHIFT);
}


uint8_t LevSpeedSystemInformation1::getErrorMessage() {
template<class T>
uint8_t LevBaseSpeedSystemInformation1<T>::getErrorMessage() {
return this->get8BitValue(ERRORMESSAGE_BYTE);
}

template class LevBaseSpeedSystemInformation1<BroadcastData>;
template class LevBaseSpeedSystemInformation1<BroadcastDataMsg>;

LevSpeedSystemInformation1::LevSpeedSystemInformation1(AntRxDataResponse& dp) :
LevBaseSpeedSystemInformation(dp),
LevBaseSpeedSystemInformation1<BroadcastData>() {
}

LevSpeedSystemInformation1Msg::LevSpeedSystemInformation1Msg() :
LevBaseSpeedSystemInformationMsg(SPEEDSYSTEMINFORMATION1_NUMBER),
LevBaseSpeedSystemInformation1<BroadcastDataMsg>() {}

void LevSpeedSystemInformation1Msg::setBatteryTemperatureState(uint8_t state) {
set8BitValue(state, TEMPERATURESTATE_BYTE,
TEMPERATURESTATE_BATTERYTEMPERATURE_MASK);
}

void LevSpeedSystemInformation1Msg::setBatteryTemperatureAlert(uint8_t alert) {
set8BitValue(alert, TEMPERATURESTATE_BYTE,
TEMPERATURESTATE_BATTERYTEMPERATUREALERT_MASK,
TEMPERATURESTATE_BATTERYTEMPERATUREALERT_SHIFT);
}

void LevSpeedSystemInformation1Msg::setMotorTemperatureState(uint8_t state) {
set8BitValue(state, TEMPERATURESTATE_BYTE,
TEMPERATURESTATE_MOTORTEMPERATURE_MASK,
TEMPERATURESTATE_MOTORTEMPERATURE_SHIFT);
}

void LevSpeedSystemInformation1Msg::setMotorTemperatureAlert(uint8_t alert) {
set8BitValue(alert, TEMPERATURESTATE_BYTE,
TEMPERATURESTATE_MOTORTEMPERATUREALERT_MASK,
TEMPERATURESTATE_MOTORTEMPERATUREALERT_SHIFT);
}

void LevSpeedSystemInformation1Msg::setErrorMessage(uint8_t err) {
set8BitValue(err, ERRORMESSAGE_BYTE);
}

20 changes: 18 additions & 2 deletions src/Profiles/Lev/DataPages/ANTPLUS_LevSpeedSystemInformation1.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,30 @@

#include <Profiles/Lev/DataPages/ANTPLUS_LevBaseSpeedSystemInformation.h>

class LevSpeedSystemInformation1 : public LevBaseSpeedSystemInformation {
template<class T>
class LevBaseSpeedSystemInformation1 : virtual public CoreDataPage<T> {
public:
explicit LevSpeedSystemInformation1(AntRxDataResponse& dp);
LevBaseSpeedSystemInformation1();
uint8_t getBatteryTemperatureState();
uint8_t getBatteryTemperatureAlert();
uint8_t getMotorTemperatureState();
uint8_t getMotorTemperatureAlert();
uint8_t getErrorMessage();
};

class LevSpeedSystemInformation1 : public LevBaseSpeedSystemInformation, public LevBaseSpeedSystemInformation1<BroadcastData> {
public:
explicit LevSpeedSystemInformation1(AntRxDataResponse& dp);
};

class LevSpeedSystemInformation1Msg : public LevBaseSpeedSystemInformationMsg, public LevBaseSpeedSystemInformation1<BroadcastDataMsg> {
public:
LevSpeedSystemInformation1Msg();
void setBatteryTemperatureState(uint8_t state);
void setBatteryTemperatureAlert(uint8_t alert);
void setMotorTemperatureState(uint8_t state);
void setMotorTemperatureAlert(uint8_t alert);
void setErrorMessage(uint8_t err);
};

#endif // ANTPLUS_LEVSPEEDSYSTEMINFORMATION1_h
42 changes: 36 additions & 6 deletions src/Profiles/Lev/DataPages/ANTPLUS_LevSpeedSystemInformation2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,47 @@
#define BATTERYSOC_BATTERYEMPTY_MASK 0x80
#define PERCENTASSIST_BYTE 5

LevSpeedSystemInformation2::LevSpeedSystemInformation2(AntRxDataResponse& dp) :
LevBaseSpeedSystemInformation(dp) {}
template<class T>
LevBaseSpeedSystemInformation2<T>::LevBaseSpeedSystemInformation2() :
CoreDataPage<T>() {}

uint8_t LevSpeedSystemInformation2::getBatterySOC() {
template<class T>
uint8_t LevBaseSpeedSystemInformation2<T>::getBatterySOC() {
return this->get8BitValue(BATTERYSOC_BYTE, BATTERYSOC_STATEOFCHARGE_MASK);
}

uint8_t LevSpeedSystemInformation2::getBatteryEmptyWarning() {
return this->get8BitValue(BATTERYSOC_BYTE, BATTERYSOC_BATTERYEMPTY_MASK, BATTERYSOC_BATTERYEMPTY_SHIFT);
template<class T>
uint8_t LevBaseSpeedSystemInformation2<T>::getBatteryEmptyWarning() {
return this->get8BitValue(BATTERYSOC_BYTE,
BATTERYSOC_BATTERYEMPTY_MASK,
BATTERYSOC_BATTERYEMPTY_SHIFT);
}

uint8_t LevSpeedSystemInformation2::getPercentAssist() {
template<class T>
uint8_t LevBaseSpeedSystemInformation2<T>::getPercentAssist() {
return this->get8BitValue(PERCENTASSIST_BYTE);
}

template class LevBaseSpeedSystemInformation2<BroadcastData>;
template class LevBaseSpeedSystemInformation2<BroadcastDataMsg>;

LevSpeedSystemInformation2::LevSpeedSystemInformation2(AntRxDataResponse& dp) :
LevBaseSpeedSystemInformation(dp),
LevBaseSpeedSystemInformation2<BroadcastData>() {}

LevSpeedSystemInformation2Msg::LevSpeedSystemInformation2Msg() :
LevBaseSpeedSystemInformationMsg(SPEEDSYSTEMINFORMATION2_NUMBER),
LevBaseSpeedSystemInformation2<BroadcastDataMsg>() {}

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

void LevSpeedSystemInformation2Msg::setBatteryEmptyWarning(uint8_t warning) {
set8BitValue(warning, BATTERYSOC_BYTE, BATTERYSOC_BATTERYEMPTY_MASK,
BATTERYSOC_BATTERYEMPTY_SHIFT);
}

void LevSpeedSystemInformation2Msg::setPercentAssist(uint8_t percent) {
set8BitValue(percent, PERCENTASSIST_BYTE);
}
18 changes: 16 additions & 2 deletions src/Profiles/Lev/DataPages/ANTPLUS_LevSpeedSystemInformation2.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,26 @@

#include <Profiles/Lev/DataPages/ANTPLUS_LevBaseSpeedSystemInformation.h>

class LevSpeedSystemInformation2 : public LevBaseSpeedSystemInformation {
template<class T>
class LevBaseSpeedSystemInformation2 : virtual public CoreDataPage<T> {
public:
explicit LevSpeedSystemInformation2(AntRxDataResponse& dp);
LevBaseSpeedSystemInformation2();
uint8_t getBatterySOC();
uint8_t getBatteryEmptyWarning();
uint8_t getPercentAssist();
};

class LevSpeedSystemInformation2 : public LevBaseSpeedSystemInformation, public LevBaseSpeedSystemInformation2<BroadcastData> {
public:
explicit LevSpeedSystemInformation2(AntRxDataResponse& dp);
};

class LevSpeedSystemInformation2Msg : public LevBaseSpeedSystemInformationMsg, public LevBaseSpeedSystemInformation2<BroadcastDataMsg> {
public:
LevSpeedSystemInformation2Msg();
void setBatterySOC(uint8_t soc);
void setBatteryEmptyWarning(uint8_t warning);
void setPercentAssist(uint8_t percent);
};

#endif // ANTPLUS_LEVSPEEDSYSTEMINFORMATION2_h
Loading

0 comments on commit 4b75c24

Please sign in to comment.