fsfw/src/core/power/PowerComponent.cpp

83 lines
2.2 KiB
C++
Raw Normal View History

2020-08-13 20:53:35 +02:00
#include "PowerComponent.h"
2020-12-03 18:29:28 +01:00
#include "../serialize/SerializeAdapter.h"
2021-03-07 01:35:55 +01:00
2020-12-03 18:29:28 +01:00
PowerComponent::PowerComponent(): switchId1(0xFF), switchId2(0xFF),
doIHaveTwoSwitches(false) {
}
2020-12-03 18:29:28 +01:00
PowerComponent::PowerComponent(object_id_t setId, uint8_t moduleId, float min,
float max, uint8_t switchId1, bool twoSwitches, uint8_t switchId2) :
deviceObjectId(setId), switchId1(switchId1), switchId2(switchId2),
2021-03-09 14:48:41 +01:00
doIHaveTwoSwitches(twoSwitches), minPower(min), maxPower(max),
2020-12-03 18:29:28 +01:00
moduleId(moduleId) {
}
ReturnValue_t PowerComponent::serialize(uint8_t** buffer, size_t* size,
size_t maxSize, Endianness streamEndianness) const {
2021-03-09 14:48:41 +01:00
ReturnValue_t result = SerializeAdapter::serialize(&minPower, buffer,
size, maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
2021-03-09 14:48:41 +01:00
return SerializeAdapter::serialize(&maxPower, buffer, size, maxSize,
streamEndianness);
}
size_t PowerComponent::getSerializedSize() const {
2021-03-09 14:48:41 +01:00
return sizeof(minPower) + sizeof(maxPower);
}
object_id_t PowerComponent::getDeviceObjectId() {
return deviceObjectId;
}
uint8_t PowerComponent::getSwitchId1() {
return switchId1;
}
uint8_t PowerComponent::getSwitchId2() {
return switchId2;
}
bool PowerComponent::hasTwoSwitches() {
return doIHaveTwoSwitches;
}
float PowerComponent::getMin() {
2021-03-09 14:48:41 +01:00
return minPower;
}
float PowerComponent::getMax() {
2021-03-09 14:48:41 +01:00
return maxPower;
}
ReturnValue_t PowerComponent::deSerialize(const uint8_t** buffer, size_t* size,
2020-12-03 18:29:28 +01:00
Endianness streamEndianness) {
2021-03-09 14:48:41 +01:00
ReturnValue_t result = SerializeAdapter::deSerialize(&minPower, buffer,
size, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
2021-03-09 14:48:41 +01:00
return SerializeAdapter::deSerialize(&maxPower, buffer, size, streamEndianness);
}
ReturnValue_t PowerComponent::getParameter(uint8_t domainId, uint8_t uniqueId,
ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues,
uint16_t startAtIndex) {
if (domainId != moduleId) {
return INVALID_DOMAIN_ID;
}
switch (uniqueId) {
case 0:
2021-03-09 14:48:41 +01:00
parameterWrapper->set<>(minPower);
break;
case 1:
2021-03-09 14:48:41 +01:00
parameterWrapper->set<>(maxPower);
break;
default:
2020-12-03 18:29:28 +01:00
return INVALID_IDENTIFIER_ID;
}
return HasReturnvaluesIF::RETURN_OK;
}