Dropped BCAbstractTransmitter, simplified code.

This commit is contained in:
2026-01-03 12:48:47 +01:00
parent c5dc84179b
commit 61bf3b2cec
6 changed files with 68 additions and 148 deletions

View File

@@ -185,34 +185,25 @@ void BCXmlLoader::loadXmlBikeDeviceData(BCDevice::ID deviceID)
std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const BCValueParams& params )
{
/*
static QHash<QString,ReadValueFunc> s_bcReadValueFunctions
{
{ "Byte", readByteValue },
{ "Word", readWordValue },
{ "Assist", readByteValue }
};
if( !s_bcReadValueFunctions.contains( unitTypeKey ) )
return std::nullopt;
return s_bcReadValueFunctions[unitTypeKey];
*/
auto setIfExists = [&]( QStringView source, OptDouble& target )
static QHash<QString,BCValue::ValueType> s_valueTypes
{
if( !source.isEmpty() )
{
bool ok;
double testVal = source.toDouble(&ok);
if (ok)
target = testVal;
}
{ "Plain", BCValue::ValueType::Plain },
{ "Bool", BCValue::ValueType::Bool },
{ "Number", BCValue::ValueType::Number },
{ "Float", BCValue::ValueType::Float }
};
auto setIfExists = [&]<typename T>( QStringView source, T& 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:
@@ -224,18 +215,26 @@ std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const B
// geht nicht auf qt6.8 von debian trixie
//std::optional<quint64> IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() );
bool ok;
static QMetaEnum s_bcValueEnum{QMetaEnum::fromType<BC::ID>()};
int IDVal = s_bcValueEnum.keyToValue( params.ID.toLatin1().constData(), &ok );
qDebug() << " --- should create: " << params.Label;
//if( IDVal.has_value() )
if( ok )
{
BCValuePtr newValue = std::make_shared<BCValue>( deviceID, static_cast<BC::ID>(IDVal) );
BCValuePtr newValuePtr = std::make_shared<BCValue>( deviceID, static_cast<BC::ID>(IDVal) );
BCValue& newValue = *newValuePtr.get();
//setIfExists( params.Factor, newValue->factor );
setIfExists( params.Min, newValue->min );
setIfExists( params.Max, newValue->max );
newValue->label = params.Label;
setIfExists( params.Factor, newValue.factor );
setIfExists( params.Min, newValue.min );
setIfExists( params.Max, newValue.max );
setIfExists( params.IsWord, newValue.isWord );
newValue.label = params.Label;
newValue.label = params.UnitLabel;
if( s_valueTypes.contains( params.ValueType ) )
newValue.valueType = s_valueTypes[params.ValueType];
/*
QString ID;
@@ -248,10 +247,9 @@ std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const B
QString ValueType;
*/
qDebug() << " --- created: " << params.Label;
return std::optional<BCValuePtr>( newValue );
return std::optional<BCValuePtr>( newValuePtr );
}
return std::nullopt;