Added BCValueType

This commit is contained in:
2025-12-17 17:50:24 +01:00
parent 09ff2f00bb
commit 35112ba334
5 changed files with 123 additions and 67 deletions

5
bc.h
View File

@@ -716,9 +716,6 @@ public:
Reg_Sensor_Rev_Sub = 0x83 // Software Subversion Reg_Sensor_Rev_Sub = 0x83 // Software Subversion
}; };
//const
// SECONDS_PER_DAY = SecsPerDay; //60 * 60 * 24;
Q_ENUM(ID) Q_ENUM(ID)
}; // struct BionxID }; // struct BionxID
@@ -739,7 +736,7 @@ public:
BIB = uint8_t( BC::ID::ID_Bib ), BIB = uint8_t( BC::ID::ID_Bib ),
Sensor = uint8_t( BC::ID::ID_Sensor ) Sensor = uint8_t( BC::ID::ID_Sensor )
}; };
Q_ENUM(ID) Q_ENUM(ID)
}; };
using namespace Qt::Literals::StringLiterals; // Für _L1 using namespace Qt::Literals::StringLiterals; // Für _L1

View File

@@ -47,41 +47,3 @@ uint8_t BCValue::getLongValue()
return 0; 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<BC::ID>()};
/*
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;
}

101
bcvalue.h
View File

@@ -28,39 +28,81 @@
***************************************************************************/ ***************************************************************************/
#ifndef BCRawValue_H #ifndef BCVALUE_H
#define BCRawValue_H #define BCVALUE_H
#include <QObject>
#include <QString> #include <QString>
#include <QList> #include <QList>
#include <QVariant> #include <QVariant>
#include <bc.h> #include <bc.h>
/*
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<double>; using optDouble = std::optional<double>;
struct BCValueParams struct BCValueType
{ {
QString ID; Q_GADGET
QString Label;
QString Default;
QString Current;
QString Enabled;
QString UnitType;
QString Min;
QString Max;
QString Factor;
};
public:
struct BCUnit enum class TypeID : uint8_t
{
enum class ID
{ {
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<UnitID,QString> 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 class BCValue
@@ -79,19 +121,30 @@ public:
BCDevice::ID deviceID{BCDevice::ID::Invalid}; BCDevice::ID deviceID{BCDevice::ID::Invalid};
BC::ID targetID{BC::ID::Invalid}; BC::ID targetID{BC::ID::Invalid};
optDouble min; //BCValueType::ID typeID{BCValueType::ID::Invalid};
optDouble max; BCValueType::TypeID firz;
optDouble factor;
QVariant defaultValue; QVariant defaultValue;
QVariant value; QVariant value;
static BCValue makeValue(BCDevice::ID deviceID, const BCValueParams& params );
}; };
// Damit QVariant dieses Struct transportieren kann: // Damit QVariant dieses Struct transportieren kann:
Q_DECLARE_METATYPE(BCValue) 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: // abbreviations:
// SOC = State Of Charge // SOC = State Of Charge
// LMD = Last Measured Discharge // LMD = Last Measured Discharge
@@ -111,4 +164,4 @@ constexpr auto to_u(E e) noexcept {
using BCValueList = QVector<BCValue>; using BCValueList = QVector<BCValue>;
#endif // BCRawValue_H #endif // BCVALUE_H

View File

@@ -181,7 +181,7 @@ void BCValueManager::readDevice( BCValueList& parsedValues )
//BCValue newValue = BCValue::makeValue( _currentDeviceID, params ); //BCValue newValue = BCValue::makeValue( _currentDeviceID, params );
//if(newValue) //if(newValue)
// parsedValues.push_back( newValue ); // parsedValues.push_back( newValue );
parsedValues.push_back( BCValue::makeValue( _currentDeviceID, params ) ); parsedValues.push_back( makeValue( _currentDeviceID, params ) );
} }
//printAttrs (_xml); //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<BC::ID>()};
/*
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;
}

View File

@@ -52,6 +52,8 @@ public:
std::optional<BCValueModel*> getModel(const QString& key ); std::optional<BCValueModel*> getModel(const QString& key );
BCValue makeValue(BCDevice::ID deviceID, const BCValueParams& params );
protected: protected:
void readDevice( BCValueList& parsedValues ); void readDevice( BCValueList& parsedValues );