Skip to content

Commit

Permalink
Lev: BatteryInformation: format refector
Browse files Browse the repository at this point in the history
  • Loading branch information
cujomalainey committed Feb 3, 2022
1 parent e5a2627 commit 303911e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 9 deletions.
54 changes: 47 additions & 7 deletions src/Profiles/Lev/DataPages/ANTPLUS_LevBatteryInformation.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <Profiles/Lev/DataPages/ANTPLUS_LevBatteryInformation.h>
#include <Profiles/Lev/ANTPLUS_LevPrivateDefines.h>

#define RESERVED_BYTE 1
#define RESERVED_VALUE 0xFF
#define CHARGINGCYCLECOUNT_LSB_BYTE 2
#define CHARGINGCYCLECOUNT_MSB_BYTE 3
#define CHARGINGCYCLECOUNT_MASK 0x0FFF
Expand All @@ -12,26 +14,64 @@
#define DISTANCEONCURRENTCHARGE_LSB_BYTE 6
#define DISTANCEONCURRENTCHARGE_MSB_BYTE 7

LevBatteryInformation::LevBatteryInformation(AntRxDataResponse& dp) :
LevBaseMainDataPage(dp) {}
template<class T>
LevBaseBatteryInformation<T>::LevBaseBatteryInformation() : CoreDataPage<T>() {}

uint16_t LevBatteryInformation::getChargingCycleCount() {
template<class T>
uint16_t LevBaseBatteryInformation<T>::getChargingCycleCount() {
return this->get16BitValue(CHARGINGCYCLECOUNT_LSB_BYTE,
CHARGINGCYCLECOUNT_MSB_BYTE, CHARGINGCYCLECOUNT_MASK);
}

// TODO check this in testing
uint16_t LevBatteryInformation::getFuelConsumption() {
template<class T>
uint16_t LevBaseBatteryInformation<T>::getFuelConsumption() {
return this->get16BitValue(FUELCONSUMPTION_LSB_BYTE,
FUELCONSUMPTION_MSB_BYTE, FUELCONSUMPTION_MASK,
FUELCONSUMPTION_SHIFT);
}

uint8_t LevBatteryInformation::getBatteryVoltage() {
template<class T>
uint8_t LevBaseBatteryInformation<T>::getBatteryVoltage() {
return this->get8BitValue(BATTERYVOLTAGE_BYTE);
}

uint16_t LevBatteryInformation::getDistanceOnCurrentCharge() {
template<class T>
uint16_t LevBaseBatteryInformation<T>::getDistanceOnCurrentCharge() {
return this->get16BitValue(DISTANCEONCURRENTCHARGE_LSB_BYTE,
DISTANCEONCURRENTCHARGE_MSB_BYTE);
}

template class LevBaseBatteryInformation<BroadcastData>;
template class LevBaseBatteryInformation<BroadcastDataMsg>;

LevBatteryInformation::LevBatteryInformation(AntRxDataResponse& dp) :
LevBaseMainDataPage(dp),
LevBaseBatteryInformation<BroadcastData>() {}

LevBatteryInformationMsg::LevBatteryInformationMsg() :
LevBaseMainDataPageMsg<BroadcastDataMsg>(BATTERYINFORMATION_NUMBER),
LevBaseBatteryInformation<BroadcastDataMsg>() {
set8BitValue(RESERVED_VALUE, RESERVED_BYTE);
}

void LevBatteryInformationMsg::setChargingCycleCount(uint16_t cycleCount) {
set16BitValue(cycleCount, CHARGINGCYCLECOUNT_LSB_BYTE,
CHARGINGCYCLECOUNT_MSB_BYTE,
CHARGINGCYCLECOUNT_MASK);
}

void LevBatteryInformationMsg::setFuelConsumption(uint16_t consumption) {
set16BitValue(consumption, FUELCONSUMPTION_LSB_BYTE,
FUELCONSUMPTION_MSB_BYTE,
FUELCONSUMPTION_MASK,
FUELCONSUMPTION_SHIFT);
}

void LevBatteryInformationMsg::setBatteryVoltage(uint8_t voltage) {
set8BitValue(voltage, BATTERYVOLTAGE_BYTE);
}

void LevBatteryInformationMsg::setDistanceOnCurrentCharge(uint16_t distance) {
set16BitValue(distance, DISTANCEONCURRENTCHARGE_LSB_BYTE,
DISTANCEONCURRENTCHARGE_MSB_BYTE);
}
18 changes: 16 additions & 2 deletions src/Profiles/Lev/DataPages/ANTPLUS_LevBatteryInformation.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,27 @@

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

class LevBatteryInformation : public LevBaseMainDataPage {
template<class T>
class LevBaseBatteryInformation : virtual public CoreDataPage<T> {
public:
explicit LevBatteryInformation(AntRxDataResponse& dp);
LevBaseBatteryInformation();
uint16_t getChargingCycleCount();
uint16_t getFuelConsumption();
uint8_t getBatteryVoltage();
uint16_t getDistanceOnCurrentCharge();
};

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

class LevBatteryInformationMsg : public LevBaseMainDataPageMsg<BroadcastDataMsg>, public LevBaseBatteryInformation<BroadcastDataMsg> {
public:
LevBatteryInformationMsg();
void setChargingCycleCount(uint16_t cycleCount);
void setFuelConsumption(uint16_t consumption);
void setBatteryVoltage(uint8_t voltage);
void setDistanceOnCurrentCharge(uint16_t distance);
};
#endif // ANTPLUS_LEVBATTERYINFORMATION_h

0 comments on commit 303911e

Please sign in to comment.