From 35112ba3346ba8efab1d0eb1238c21d4e726ee40 Mon Sep 17 00:00:00 2001 From: "PANIK\\chris" Date: Wed, 17 Dec 2025 17:50:24 +0100 Subject: [PATCH] Added BCValueType --- bc.h | 5 +-- bcvalue.cpp | 38 ----------------- bcvalue.h | 101 ++++++++++++++++++++++++++++++++++----------- bcvaluemanager.cpp | 44 +++++++++++++++++++- bcvaluemanager.h | 2 + 5 files changed, 123 insertions(+), 67 deletions(-) diff --git a/bc.h b/bc.h index 568422c..ab3aee2 100644 --- a/bc.h +++ b/bc.h @@ -716,9 +716,6 @@ public: Reg_Sensor_Rev_Sub = 0x83 // Software Subversion }; - //const - // SECONDS_PER_DAY = SecsPerDay; //60 * 60 * 24; - Q_ENUM(ID) }; // struct BionxID @@ -739,7 +736,7 @@ public: BIB = uint8_t( BC::ID::ID_Bib ), Sensor = uint8_t( BC::ID::ID_Sensor ) }; - Q_ENUM(ID) + Q_ENUM(ID) }; using namespace Qt::Literals::StringLiterals; // Für _L1 diff --git a/bcvalue.cpp b/bcvalue.cpp index 1c7016b..d80e7ba 100644 --- a/bcvalue.cpp +++ b/bcvalue.cpp @@ -47,41 +47,3 @@ uint8_t BCValue::getLongValue() return 0; } - -BCValue BCValue::makeValue( BCDevice::ID deviceID, const BCValueParams& params ) -{ - - auto setIfExists = [&]( QStringView source, optDouble& target ) - { - if( !source.isEmpty() ) - { - bool ok; - double testVal = source.toDouble(&ok); - if (ok) - target = testVal; - } - }; - - static QMetaEnum s_bcValueEnum{QMetaEnum::fromType()}; - - /* - Wir brauchen: - - eine gültige ID - - */ - BCValue newValue{}; - - auto IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() ); - if( IDVal.has_value() ) - { - newValue = BCValue( deviceID, BC::ID( IDVal.value() ) ); - setIfExists( params.Factor, newValue.factor ); - setIfExists( params.Min, newValue.min ); - setIfExists( params.Max, newValue.max ); - newValue.defaultValue.setValue( params.Label ); - newValue.value.setValue( params.Current ); - newValue.label = params.Label; - } - - return newValue; -} diff --git a/bcvalue.h b/bcvalue.h index 11e0b00..d39af87 100644 --- a/bcvalue.h +++ b/bcvalue.h @@ -28,39 +28,81 @@ ***************************************************************************/ -#ifndef BCRawValue_H -#define BCRawValue_H - +#ifndef BCVALUE_H +#define BCVALUE_H +#include #include #include #include #include + +/* + + Das ist natürlich annalog zu den ItemTypes: + - ein Value hat einen ValueType, der bestimmt folgendes: + - long or short + - unit (mm, km/h, odo ... ) + - + + +*/ using optDouble = std::optional; -struct BCValueParams +struct BCValueType { - QString ID; - QString Label; - QString Default; - QString Current; - QString Enabled; - QString UnitType; - QString Min; - QString Max; - QString Factor; -}; + Q_GADGET +public: -struct BCUnit -{ - enum class ID + enum class TypeID : uint8_t { - + Invalid = 0x0, }; + Q_ENUM(TypeID) + enum class UnitID : uint8_t + { + Invalid = 0x0, + Text, + Number, + Float, + Percent, + KWh, + Km, + Mm, + Sec, + SOC, + Date + }; + Q_ENUM(UnitID) + + + static QString getUnitName( UnitID unitID) + { + static QMap s_unitNames + { + {UnitID::Invalid, "" }, + {UnitID::Text, ""}, + {UnitID::Number, ""}, + {UnitID::Float, "" }, + {UnitID::Percent, "%"}, + {UnitID::KWh, "kWh" }, + {UnitID::Km, "km"}, + {UnitID::Mm, "mm"}, + {UnitID::Sec, "s"}, + {UnitID::SOC, "%"}, + {UnitID::Date, ""} + }; + return s_unitNames[unitID]; + } + + UnitID ID; + optDouble min; + optDouble max; + optDouble factor; }; class BCValue @@ -79,19 +121,30 @@ public: BCDevice::ID deviceID{BCDevice::ID::Invalid}; BC::ID targetID{BC::ID::Invalid}; - optDouble min; - optDouble max; - optDouble factor; + //BCValueType::ID typeID{BCValueType::ID::Invalid}; + BCValueType::TypeID firz; QVariant defaultValue; QVariant value; - static BCValue makeValue(BCDevice::ID deviceID, const BCValueParams& params ); - }; // Damit QVariant dieses Struct transportieren kann: Q_DECLARE_METATYPE(BCValue) + +struct BCValueParams +{ + QString ID; + QString Label; + QString Default; + QString Current; + QString Enabled; + QString UnitType; + QString Min; + QString Max; + QString Factor; +}; + // abbreviations: // SOC = State Of Charge // LMD = Last Measured Discharge @@ -111,4 +164,4 @@ constexpr auto to_u(E e) noexcept { using BCValueList = QVector; -#endif // BCRawValue_H +#endif // BCVALUE_H diff --git a/bcvaluemanager.cpp b/bcvaluemanager.cpp index 0eecb0c..691f13a 100644 --- a/bcvaluemanager.cpp +++ b/bcvaluemanager.cpp @@ -181,7 +181,7 @@ void BCValueManager::readDevice( BCValueList& parsedValues ) //BCValue newValue = BCValue::makeValue( _currentDeviceID, params ); //if(newValue) // parsedValues.push_back( newValue ); - parsedValues.push_back( BCValue::makeValue( _currentDeviceID, params ) ); + parsedValues.push_back( makeValue( _currentDeviceID, params ) ); } //printAttrs (_xml); @@ -229,3 +229,45 @@ void BCValueManager::saveXml() } */ } + + + +BCValue BCValueManager::makeValue( BCDevice::ID deviceID, const BCValueParams& params ) +{ + + auto setIfExists = [&]( QStringView source, optDouble& target ) + { + if( !source.isEmpty() ) + { + bool ok; + double testVal = source.toDouble(&ok); + if (ok) + target = testVal; + } + }; + + static QMetaEnum s_bcValueEnum{QMetaEnum::fromType()}; + + /* + Wir brauchen: + - eine gültige ID + + */ + BCValue newValue{}; + + auto IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() ); + if( IDVal.has_value() ) + { + newValue = BCValue( deviceID, BC::ID( IDVal.value() ) ); + /* + setIfExists( params.Factor, newValue.factor ); + setIfExists( params.Min, newValue.min ); + setIfExists( params.Max, newValue.max ); + */ + newValue.defaultValue.setValue( params.Label ); + newValue.value.setValue( params.Current ); + newValue.label = params.Label; + } + + return newValue; +} diff --git a/bcvaluemanager.h b/bcvaluemanager.h index 805f218..980c625 100644 --- a/bcvaluemanager.h +++ b/bcvaluemanager.h @@ -52,6 +52,8 @@ public: std::optional getModel(const QString& key ); + BCValue makeValue(BCDevice::ID deviceID, const BCValueParams& params ); + protected: void readDevice( BCValueList& parsedValues );