2020-08-13 20:53:35 +02:00
|
|
|
#include "PowerComponent.h"
|
2020-12-03 18:29:28 +01:00
|
|
|
#include "../serialize/SerializeAdapter.h"
|
2018-07-12 16:29:32 +02:00
|
|
|
|
2021-03-07 01:35:55 +01:00
|
|
|
|
2020-12-03 18:29:28 +01:00
|
|
|
PowerComponent::PowerComponent(): switchId1(0xFF), switchId2(0xFF),
|
|
|
|
doIHaveTwoSwitches(false) {
|
2018-07-12 16:29:32 +02:00
|
|
|
}
|
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-07 01:35:55 +01:00
|
|
|
doIHaveTwoSwitches(twoSwitches), minVoltage(min), maxVoltage(max),
|
2020-12-03 18:29:28 +01:00
|
|
|
moduleId(moduleId) {
|
2018-07-12 16:29:32 +02:00
|
|
|
}
|
|
|
|
|
2020-04-21 22:28:43 +02:00
|
|
|
ReturnValue_t PowerComponent::serialize(uint8_t** buffer, size_t* size,
|
|
|
|
size_t maxSize, Endianness streamEndianness) const {
|
2021-03-07 01:35:55 +01:00
|
|
|
ReturnValue_t result = SerializeAdapter::serialize(&minVoltage, buffer,
|
2020-04-21 22:28:43 +02:00
|
|
|
size, maxSize, streamEndianness);
|
2018-07-12 16:29:32 +02:00
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
2021-03-07 01:35:55 +01:00
|
|
|
return SerializeAdapter::serialize(&maxVoltage, buffer, size, maxSize,
|
2020-04-21 22:28:43 +02:00
|
|
|
streamEndianness);
|
2018-07-12 16:29:32 +02:00
|
|
|
}
|
|
|
|
|
2020-04-21 22:28:43 +02:00
|
|
|
size_t PowerComponent::getSerializedSize() const {
|
2021-03-07 01:35:55 +01:00
|
|
|
return sizeof(minVoltage) + sizeof(maxVoltage);
|
2018-07-12 16:29:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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-07 01:35:55 +01:00
|
|
|
return minVoltage;
|
2018-07-12 16:29:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
float PowerComponent::getMax() {
|
2021-03-07 01:35:55 +01:00
|
|
|
return maxVoltage;
|
2018-07-12 16:29:32 +02:00
|
|
|
}
|
|
|
|
|
2020-04-21 22:28:43 +02:00
|
|
|
ReturnValue_t PowerComponent::deSerialize(const uint8_t** buffer, size_t* size,
|
2020-12-03 18:29:28 +01:00
|
|
|
Endianness streamEndianness) {
|
2021-03-07 01:35:55 +01:00
|
|
|
ReturnValue_t result = SerializeAdapter::deSerialize(&minVoltage, buffer,
|
2020-04-21 22:28:43 +02:00
|
|
|
size, streamEndianness);
|
2018-07-12 16:29:32 +02:00
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
2021-03-07 01:35:55 +01:00
|
|
|
return SerializeAdapter::deSerialize(&maxVoltage, buffer, size, streamEndianness);
|
2018-07-12 16:29:32 +02:00
|
|
|
}
|
|
|
|
|
2021-01-29 22:45:53 +01:00
|
|
|
ReturnValue_t PowerComponent::getParameter(uint8_t domainId, uint8_t uniqueId,
|
|
|
|
ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues,
|
|
|
|
uint16_t startAtIndex) {
|
2018-07-12 16:29:32 +02:00
|
|
|
if (domainId != moduleId) {
|
|
|
|
return INVALID_DOMAIN_ID;
|
|
|
|
}
|
2021-01-29 22:45:53 +01:00
|
|
|
switch (uniqueId) {
|
2018-07-12 16:29:32 +02:00
|
|
|
case 0:
|
2021-03-07 01:35:55 +01:00
|
|
|
parameterWrapper->set<>(minVoltage);
|
2018-07-12 16:29:32 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
2021-03-07 01:35:55 +01:00
|
|
|
parameterWrapper->set<>(maxVoltage);
|
2018-07-12 16:29:32 +02:00
|
|
|
break;
|
|
|
|
default:
|
2020-12-03 18:29:28 +01:00
|
|
|
return INVALID_IDENTIFIER_ID;
|
2018-07-12 16:29:32 +02:00
|
|
|
}
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|