1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

iec60870: fix coding style

Signed-off-by: Steffen Vogel <steffen.vogel@opal-rt.com>
This commit is contained in:
Steffen Vogel 2023-04-03 13:03:38 +00:00 committed by Philipp Jungkamp
parent 88fb57df8e
commit a709a8a0fb

View file

@ -22,8 +22,8 @@ using namespace std::literals::chrono_literals;
static CP56Time2a timespec_to_cp56time2a(timespec time) {
time_t time_ms =
static_cast<time_t> (time.tv_sec) * 1000
+ static_cast<time_t> (time.tv_nsec) / 1000000;
static_cast<time_t>(time.tv_sec) * 1000
+ static_cast<time_t>(time.tv_nsec) / 1000000;
return CP56Time2a_createFromMsTimestamp(NULL, time_ms);
}
@ -148,7 +148,7 @@ SignalType ASDUData::signalType() const
std::optional<ASDUData::Sample> ASDUData::checkASDU(CS101_ASDU const &asdu) const
{
if (CS101_ASDU_getTypeID(asdu) != static_cast<int> (descriptor->type))
if (CS101_ASDU_getTypeID(asdu) != static_cast<int>(descriptor->type))
return std::nullopt;
for (int i = 0; i < CS101_ASDU_getNumberOfElements(asdu); i++) {
@ -163,41 +163,41 @@ std::optional<ASDUData::Sample> ASDUData::checkASDU(CS101_ASDU const &asdu) cons
QualityDescriptor quality;
switch (typeWithoutTimestamp()) {
case ASDUData::SCALED_INT: {
auto scaled_int = reinterpret_cast<MeasuredValueScaled> (io);
auto scaled_int = reinterpret_cast<MeasuredValueScaled>(io);
int scaled_int_value = MeasuredValueScaled_getValue(scaled_int);
signal_data.i = static_cast<int64_t> (scaled_int_value);
signal_data.i = static_cast<int64_t>(scaled_int_value);
quality = MeasuredValueScaled_getQuality(scaled_int);
break;
}
case ASDUData::NORMALIZED_FLOAT: {
auto normalized_float = reinterpret_cast<MeasuredValueNormalized> (io);
auto normalized_float = reinterpret_cast<MeasuredValueNormalized>(io);
float normalized_float_value = MeasuredValueNormalized_getValue(normalized_float);
signal_data.f = static_cast<double> (normalized_float_value);
signal_data.f = static_cast<double>(normalized_float_value);
quality = MeasuredValueNormalized_getQuality(normalized_float);
break;
}
case ASDUData::DOUBLE_POINT: {
auto double_point = reinterpret_cast<DoublePointInformation> (io);
auto double_point = reinterpret_cast<DoublePointInformation>(io);
DoublePointValue double_point_value = DoublePointInformation_getValue(double_point);
signal_data.i = static_cast<int64_t> (double_point_value);
signal_data.i = static_cast<int64_t>(double_point_value);
quality = DoublePointInformation_getQuality(double_point);
break;
}
case ASDUData::SINGLE_POINT: {
auto single_point = reinterpret_cast<SinglePointInformation> (io);
auto single_point = reinterpret_cast<SinglePointInformation>(io);
bool single_point_value = SinglePointInformation_getValue(single_point);
signal_data.b = static_cast<bool> (single_point_value);
signal_data.b = static_cast<bool>(single_point_value);
quality = SinglePointInformation_getQuality(single_point);
break;
}
case ASDUData::SHORT_FLOAT: {
auto short_float = reinterpret_cast<MeasuredValueShort> (io);
auto short_float = reinterpret_cast<MeasuredValueShort>(io);
float short_float_value = MeasuredValueShort_getValue(short_float);
signal_data.f = static_cast<double> (short_float_value);
signal_data.f = static_cast<double>(short_float_value);
quality = MeasuredValueShort_getQuality(short_float);
break;
}
@ -209,31 +209,31 @@ std::optional<ASDUData::Sample> ASDUData::checkASDU(CS101_ASDU const &asdu) cons
std::optional<CP56Time2a> time_cp56;
switch (type()) {
case ASDUData::SCALED_INT_WITH_TIMESTAMP: {
auto scaled_int = reinterpret_cast<MeasuredValueScaledWithCP56Time2a> (io);
auto scaled_int = reinterpret_cast<MeasuredValueScaledWithCP56Time2a>(io);
time_cp56 = MeasuredValueScaledWithCP56Time2a_getTimestamp(scaled_int);
break;
}
case ASDUData::NORMALIZED_FLOAT_WITH_TIMESTAMP: {
auto normalized_float = reinterpret_cast<MeasuredValueNormalizedWithCP56Time2a> (io);
auto normalized_float = reinterpret_cast<MeasuredValueNormalizedWithCP56Time2a>(io);
time_cp56 = MeasuredValueNormalizedWithCP56Time2a_getTimestamp(normalized_float);
break;
}
case ASDUData::DOUBLE_POINT_WITH_TIMESTAMP: {
auto double_point = reinterpret_cast<DoublePointWithCP56Time2a> (io);
auto double_point = reinterpret_cast<DoublePointWithCP56Time2a>(io);
time_cp56 = DoublePointWithCP56Time2a_getTimestamp(double_point);
break;
}
case ASDUData::SINGLE_POINT_WITH_TIMESTAMP: {
auto single_point = reinterpret_cast<SinglePointWithCP56Time2a> (io);
auto single_point = reinterpret_cast<SinglePointWithCP56Time2a>(io);
time_cp56 = SinglePointWithCP56Time2a_getTimestamp(single_point);
break;
}
case ASDUData::SHORT_FLOAT_WITH_TIMESTAMP: {
auto short_float = reinterpret_cast<MeasuredValueShortWithCP56Time2a> (io);
auto short_float = reinterpret_cast<MeasuredValueShortWithCP56Time2a>(io);
time_cp56 = MeasuredValueShortWithCP56Time2a_getTimestamp(short_float);
break;
}
@ -263,72 +263,72 @@ bool ASDUData::addSampleToASDU(CS101_ASDU &asdu, ASDUData::Sample sample) const
InformationObject io;
switch (descriptor->type) {
case ASDUData::SCALED_INT: {
auto scaled_int_value = static_cast<int16_t> (sample.signal_data.i & 0xFFFF);
auto scaled_int_value = static_cast<int16_t>(sample.signal_data.i & 0xFFFF);
auto scaled_int = MeasuredValueScaled_create(NULL, ioa, scaled_int_value, sample.quality);
io = reinterpret_cast<InformationObject> (scaled_int);
io = reinterpret_cast<InformationObject>(scaled_int);
break;
}
case ASDUData::NORMALIZED_FLOAT: {
auto normalized_float_value = static_cast<float> (sample.signal_data.f);
auto normalized_float_value = static_cast<float>(sample.signal_data.f);
auto normalized_float = MeasuredValueNormalized_create(NULL, ioa, normalized_float_value, sample.quality);
io = reinterpret_cast<InformationObject> (normalized_float);
io = reinterpret_cast<InformationObject>(normalized_float);
break;
}
case ASDUData::DOUBLE_POINT: {
auto double_point_value = static_cast<DoublePointValue> (sample.signal_data.i & 0x3);
auto double_point_value = static_cast<DoublePointValue>(sample.signal_data.i & 0x3);
auto double_point = DoublePointInformation_create(NULL, ioa, double_point_value, sample.quality);
io = reinterpret_cast<InformationObject> (double_point);
io = reinterpret_cast<InformationObject>(double_point);
break;
}
case ASDUData::SINGLE_POINT: {
auto single_point_value = sample.signal_data.b;
auto single_point = SinglePointInformation_create(NULL, ioa, single_point_value, sample.quality);
io = reinterpret_cast<InformationObject> (single_point);
io = reinterpret_cast<InformationObject>(single_point);
break;
}
case ASDUData::SHORT_FLOAT: {
auto short_float_value = static_cast<float> (sample.signal_data.f);
auto short_float_value = static_cast<float>(sample.signal_data.f);
auto short_float = MeasuredValueShort_create(NULL, ioa, short_float_value, sample.quality);
io = reinterpret_cast<InformationObject> (short_float);
io = reinterpret_cast<InformationObject>(short_float);
break;
}
case ASDUData::SCALED_INT_WITH_TIMESTAMP: {
auto scaled_int_value = static_cast<int16_t> (sample.signal_data.i & 0xFFFF);
auto scaled_int_value = static_cast<int16_t>(sample.signal_data.i & 0xFFFF);
auto scaled_int = MeasuredValueScaledWithCP56Time2a_create(NULL, ioa, scaled_int_value, sample.quality, timestamp.value());
io = reinterpret_cast<InformationObject> (scaled_int);
io = reinterpret_cast<InformationObject>(scaled_int);
break;
}
case ASDUData::NORMALIZED_FLOAT_WITH_TIMESTAMP: {
auto normalized_float_value = static_cast<float> (sample.signal_data.f);
auto normalized_float_value = static_cast<float>(sample.signal_data.f);
auto normalized_float = MeasuredValueNormalizedWithCP56Time2a_create(NULL, ioa, normalized_float_value, sample.quality, timestamp.value());
io = reinterpret_cast<InformationObject> (normalized_float);
io = reinterpret_cast<InformationObject>(normalized_float);
break;
}
case ASDUData::DOUBLE_POINT_WITH_TIMESTAMP: {
auto double_point_value = static_cast<DoublePointValue> (sample.signal_data.i & 0x3);
auto double_point_value = static_cast<DoublePointValue>(sample.signal_data.i & 0x3);
auto double_point = DoublePointWithCP56Time2a_create(NULL, ioa, double_point_value, sample.quality, timestamp.value());
io = reinterpret_cast<InformationObject> (double_point);
io = reinterpret_cast<InformationObject>(double_point);
break;
}
case ASDUData::SINGLE_POINT_WITH_TIMESTAMP: {
auto single_point_value = sample.signal_data.b;
auto single_point = SinglePointWithCP56Time2a_create(NULL, ioa, single_point_value, sample.quality, timestamp.value());
io = reinterpret_cast<InformationObject> (single_point);
io = reinterpret_cast<InformationObject>(single_point);
break;
}
case ASDUData::SHORT_FLOAT_WITH_TIMESTAMP: {
auto short_float_value = static_cast<float> (sample.signal_data.f);
auto short_float_value = static_cast<float>(sample.signal_data.f);
auto short_float = MeasuredValueShortWithCP56Time2a_create(NULL, ioa, short_float_value, sample.quality, timestamp.value());
io = reinterpret_cast<InformationObject> (short_float);
io = reinterpret_cast<InformationObject>(short_float);
break;
}
@ -383,27 +383,27 @@ void SlaveNode::createSlave() noexcept
// Setup callbacks into the class
CS104_Slave_setClockSyncHandler(server.slave, [] (void *tcp_node, IMasterConnection connection, CS101_ASDU asdu, CP56Time2a new_time) {
auto self = static_cast<SlaveNode const *> (tcp_node);
auto self = static_cast<SlaveNode const *>(tcp_node);
return self->onClockSync(connection, asdu, new_time);
}, this);
CS104_Slave_setInterrogationHandler(server.slave, [] (void *tcp_node, IMasterConnection connection, CS101_ASDU asdu, QualifierOfInterrogation qoi) {
auto self = static_cast<SlaveNode const *> (tcp_node);
auto self = static_cast<SlaveNode const *>(tcp_node);
return self->onInterrogation(connection, asdu, qoi);
}, this);
CS104_Slave_setASDUHandler(server.slave, [] (void *tcp_node, IMasterConnection connection, CS101_ASDU asdu) {
auto self = static_cast<SlaveNode const *> (tcp_node);
auto self = static_cast<SlaveNode const *>(tcp_node);
return self->onASDU(connection, asdu);
}, this);
CS104_Slave_setConnectionEventHandler(server.slave, [](void *tcp_node, IMasterConnection connection, CS104_PeerConnectionEvent event){
auto self = static_cast<SlaveNode const *> (tcp_node);
auto self = static_cast<SlaveNode const *>(tcp_node);
self->debugPrintConnection(connection, event);
}, this);
CS104_Slave_setRawMessageHandler(server.slave, [](void *tcp_node, IMasterConnection connection, uint8_t *message, int message_size, bool sent){
auto self = static_cast<SlaveNode const *> (tcp_node);
auto self = static_cast<SlaveNode const *>(tcp_node);
self->debugPrintMessage(connection, message, message_size, sent);
}, this);