From c5dc84179b6cca93c8d409916497cae128d930d8 Mon Sep 17 00:00:00 2001 From: "DIASPORA\\chris" Date: Sat, 3 Jan 2026 02:50:28 +0100 Subject: [PATCH 1/2] Compiles again, without BCValueType. --- BionxControl.pro | 2 - bc.h | 23 ++--- bcdriver.h | 2 +- bcmainwindow.h | 2 + bctransmitter.cpp | 5 +- bctransmitter.h | 1 - bcvalue.cpp | 111 ++++++++++++++++++++- bcvalue.h | 113 +++++++++------------ bcvaluemodel.cpp | 10 +- bcvaluetype.cpp | 183 ---------------------------------- bcvaluetype.h | 102 ------------------- bcxmlloader.cpp | 128 ++++++++++-------------- bcxmlloader.h | 22 ++--- resources/bikeinfo.xml | 217 +++++++++++++++++++++-------------------- 14 files changed, 353 insertions(+), 568 deletions(-) delete mode 100644 bcvaluetype.cpp delete mode 100644 bcvaluetype.h diff --git a/BionxControl.pro b/BionxControl.pro index ffbfca8..064e17c 100644 --- a/BionxControl.pro +++ b/BionxControl.pro @@ -36,7 +36,6 @@ SOURCES += \ bctransmitter.cpp \ bcvalue.cpp \ bcvaluemodel.cpp \ - bcvaluetype.cpp \ bcxmlloader.cpp \ lib/can_drv_win.c \ main.cpp \ @@ -52,7 +51,6 @@ HEADERS += \ bctransmitter.h \ bcvalue.h \ bcvaluemodel.h \ - bcvaluetype.h \ bcxmlloader.h FORMS += \ diff --git a/bc.h b/bc.h index 42f2917..5058ebe 100644 --- a/bc.h +++ b/bc.h @@ -770,18 +770,19 @@ using namespace Qt::Literals::StringLiterals; // Für _L1 namespace BCTags { - inline constexpr auto Device = "Device"_L1; - inline constexpr auto ID = "ID"_L1; - inline constexpr auto Label = "Label"_L1; - inline constexpr auto Default = "Default"_L1; - inline constexpr auto Current = "Current"_L1; - inline constexpr auto Enabled = "Enabled"_L1; - inline constexpr auto UnitType = "UnitType"_L1; - inline constexpr auto Min = "Min"_L1; - inline constexpr auto Max = "Max"_L1; - inline constexpr auto Factor = "Factor"_L1; - + inline constexpr auto Device = "Device"_L1; + inline constexpr auto ID = "ID"_L1; + inline constexpr auto Label = "Label"_L1; + inline constexpr auto UnitLabel = "UnitLabel"_L1; + inline constexpr auto IsWord = "IsWord"_L1; + inline constexpr auto Default = "Default"_L1; + inline constexpr auto Current = "Current"_L1; + inline constexpr auto Enabled = "Enabled"_L1; + inline constexpr auto ValueType = "ValueType"_L1; + inline constexpr auto Min = "Min"_L1; + inline constexpr auto Max = "Max"_L1; + inline constexpr auto Factor = "Factor"_L1; } #endif // BC_H diff --git a/bcdriver.h b/bcdriver.h index ebd57cf..9363b9a 100644 --- a/bcdriver.h +++ b/bcdriver.h @@ -36,7 +36,7 @@ #include #include #include -#include + /* int32_t CanInitDriver(char *options); void CanDownDriver(void); diff --git a/bcmainwindow.h b/bcmainwindow.h index 02b2358..9604227 100644 --- a/bcmainwindow.h +++ b/bcmainwindow.h @@ -34,9 +34,11 @@ #define BCMAINWINDOW_H #include +#include #include #include +#include class BCDeviceView; diff --git a/bctransmitter.cpp b/bctransmitter.cpp index a7cb4f5..0cce74b 100644 --- a/bctransmitter.cpp +++ b/bctransmitter.cpp @@ -30,7 +30,6 @@ ***************************************************************************/ -#include "bcvaluetype.h" #include #include @@ -121,7 +120,7 @@ void BCTransmitter::processValue() // Value ist 'under construction' //emit valueUpdated( value.deviceID, value.indexRow, BCValue::State::Locked ); - const BCValueType& valueType = *value.valueType; + uint32_t devID = static_cast(value.deviceID); uint8_t regID = static_cast (value.registerID); @@ -139,6 +138,7 @@ void BCTransmitter::processValue() else if( value.state.testFlag( BCValue::State::ReadMe ) ) { + /* // wir sind hier im anderen thread! nicht einfach so reinschreiben, nur lesen TransmitResult result = valueType.readValueFunc( *this, devID, regID ); if( result.has_value() ) @@ -150,6 +150,7 @@ void BCTransmitter::processValue() { newState = BCValue::State::Failed; } +*/ } diff --git a/bctransmitter.h b/bctransmitter.h index be420e8..192c6fb 100644 --- a/bctransmitter.h +++ b/bctransmitter.h @@ -39,7 +39,6 @@ #include #include -#include #include /** diff --git a/bcvalue.cpp b/bcvalue.cpp index 6909fac..f888ee2 100644 --- a/bcvalue.cpp +++ b/bcvalue.cpp @@ -33,16 +33,121 @@ #include #include -#include + ///------------------------------- -BCValue::BCValue(const BCValueType* valueType_, BCDevice::ID deviceID_, BC::ID registerID_) - : valueType{valueType_}, deviceID{deviceID_}, registerID{registerID_} +BCValue::BCValue( BCDevice::ID deviceID_, BC::ID registerID_) + : deviceID{deviceID_}, registerID{registerID_} { visibleValue = "--"; } +/*************************************************************************** + +BionxControl +Copyright © 2025 christoph holzheuer +christoph.holzheuer@gmail.com + +Using: + +mhs_can_drv.c +© 2011 - 2023 by MHS-Elektronik GmbH & Co. KG, Germany +Klaus Demlehner, klaus@mhs-elektronik.de +@see www.mhs-elektronik.de + +Based on Bionx data type descriptions from: + +BigXionFlasher USB V 0.2.4 rev. 97 +© 2011-2013 by Thomas Koenig +@see www.bigxionflasher.org + +Bionx Bike Info +© 2018 Thorsten Schmidt (tschmidt@ts-soft.de) +@see www.ts-soft.de + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. +@see https://github.com/bikemike/bionx-bikeinfo + + ***************************************************************************/ + + + +/// reader functions + + + +TransmitResult readDummy( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) +{ + qDebug() << " --- NO: Read DUMMY: " << registerID; + return std::unexpected( QString("NO: Read DUMMY: %1 : %2 ").arg( deviceID, registerID ) ); +} + +TransmitResult readByteValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) +{ + qDebug() << " --- YES: Read ByteValue: " << registerID; + // Wir lesen nur ein Byte und gut. + return transmitter.readByte( deviceID, registerID ); +} + + +TransmitResult readWordValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) +{ + qDebug() << " --- YES: Read WordValue: " << registerID; + + //getValue(CONSOLE, CONSOLE_SN_PN_HI) << 8) + getValue(CONSOLE, CONSOLE_SN_PN_LO)), + uint32_t result{}; + // hi byte Leseversuch. + TransmitResult value = transmitter.readByte( deviceID, registerID ); + // Fehler? dann weg + if( !value) + return std::unexpected( value.error() ); + // hi byte speichern + result = *value << 8; + // low byte, liegt im followup register: +1 + value = transmitter.readByte( deviceID, registerID+1 ); + if( !value) + return std::unexpected( value.error() ); + result += *value; + return result; +} + +TransmitResult readSpeedValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) +{ + return 0x0; +} + +TransmitResult readODOValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) +{ + return 0x0; +} + +TransmitResult readVoltValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) +{ + return 0x0; +} + +TransmitResult readCircValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) +{ + return 0x0; +} + + + +QString BCValue::formatValue( uint32_t value ) const +{ + if( factor == 1 ) + return QString::number( value ); + + double result = value * factor; + return QString::number(result, 'f', 2); +} + + +/// ---- diff --git a/bcvalue.h b/bcvalue.h index 70823ac..b7b9b70 100644 --- a/bcvalue.h +++ b/bcvalue.h @@ -38,6 +38,7 @@ #include #include +#include #include @@ -57,14 +58,30 @@ +using OptDouble = std::optional; + +// Enthält den gelesenen Wert oder einen Fehlerstring +using TransmitResult = std::expected; +// Funktionsobject, um Werte aus der Transmitterschicht zu holden +//using ReadValueFunc = std::function; + -struct BCValueType; class BCValue { public: + // Aus dem Type ergibt sich + // später der Editor + enum class ValueType : uint8_t + { + Plain, + Bool, + Float, + Mookoo + }; + enum class State : uint8_t { NoState = 0x00, @@ -78,16 +95,22 @@ public: }; Q_DECLARE_FLAGS(States, State ) - BCValue( const BCValueType* valueType_, BCDevice::ID deviceID_, BC::ID registerID_ ); - - mutable States state{BCValue::State::NoState}; - const BCValueType* valueType{}; - BCDevice::ID deviceID{BCDevice::ID::Invalid}; - BC::ID registerID{BC::ID::Invalid}; - int indexRow{-1}; - QString label; - mutable QString visibleValue; + BCValue( BCDevice::ID deviceID_, BC::ID registerID_ ); + QString formatValue( uint32_t value ) const; + + mutable States state{BCValue::State::ReadOnly}; + BCDevice::ID deviceID{BCDevice::ID::Invalid}; + BC::ID registerID{BC::ID::Invalid}; + ValueType valueType{ValueType::Plain}; + int indexRow{-1}; + QString label; + mutable QString visibleValue; + bool isWord{false}; + QString unitLabel; + double factor{1}; + OptDouble min; + OptDouble max; }; Q_DECLARE_OPERATORS_FOR_FLAGS(BCValue::States) @@ -103,71 +126,25 @@ using BCValueList = QList; Q_DECLARE_METATYPE(const BCValuePtr) -/* -class BCValueList : public QList + +Q_DECLARE_METATYPE(BCValueList) + + +/** + * @brief BCAbstractTransmitter ist das abstrakte Basisinterface für die eigentliche + * Datenübertragung auf Treiberebene. + */ + +class BCAbstractTransmitter { public: - BCValueList() - { - qDebug() << "BC Construct: " << this; - } - - BCValueList(const BCValueList& other) - : QList(other) - { - qDebug() << "BC: Copy from: " << &other << "to" << this; - } - - BCValueList(BCValueList&& other) noexcept - : QList( other ) - { - qDebug() << "Move from: " << &other << "to" << this; - } - - // Copy Assignment Operator - BCValueList& operator=(const BCValueList& other) - { - qDebug() << "BC copy assignment: " << this; - QList::operator=( other ); - return *this; - } - - // Move Assignment Operator - BCValueList& operator=(BCValueList&& other) noexcept - { - qDebug() << "BC move assignment: " << this; - QList::operator=( other ); - return *this; - } - - ~BCValueList() - { - qDebug() << "Destruct: " << this; - } - + virtual TransmitResult readByte ( uint32_t deviceID, uint8_t registerID ) const = 0; + virtual TransmitResult writeByte( uint32_t deviceID, uint8_t registerID, uint8_t value_ ) const = 0; }; -*/ -Q_DECLARE_METATYPE(BCValueList) -// abbreviations: -// SOC = State Of Charge -// LMD = Last Measured Discharge -// NIP = ? - -/* - -Needed ? -#include - -template -constexpr auto to_u(E e) noexcept { - return static_cast>(e); -} -*/ - diff --git a/bcvaluemodel.cpp b/bcvaluemodel.cpp index 2f2d0ba..31f863d 100644 --- a/bcvaluemodel.cpp +++ b/bcvaluemodel.cpp @@ -31,7 +31,7 @@ #include -#include + /** * @brief Konstruktor, ohne Besonderheiten @@ -144,17 +144,17 @@ QVariant BCValueModel::data(const QModelIndex& index, int role) const if (wrongRole || !index.isValid() || row >= _valueList.size() ) return QVariant(); - BCValuePtr value = _valueList.at( row ); + const BCValue& value = *(_valueList.at( row ).get()); if( col == 0 ) - return value->label; + return value.label; if( col == 1) { if( role == Qt::DisplayRole ) - return QString("%1 %2").arg( value->visibleValue, value->valueType->unitLabel); + return QString("%1 %2").arg( value.visibleValue, value.unitLabel); - return value->visibleValue; + return value.visibleValue; } return QVariant(); diff --git a/bcvaluetype.cpp b/bcvaluetype.cpp deleted file mode 100644 index 5a3efdf..0000000 --- a/bcvaluetype.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/*************************************************************************** - - BionxControl - Copyright © 2025 christoph holzheuer - christoph.holzheuer@gmail.com - - Using: - - mhs_can_drv.c - © 2011 - 2023 by MHS-Elektronik GmbH & Co. KG, Germany - Klaus Demlehner, klaus@mhs-elektronik.de - @see www.mhs-elektronik.de - - Based on Bionx data type descriptions from: - - BigXionFlasher USB V 0.2.4 rev. 97 - © 2011-2013 by Thomas Koenig - @see www.bigxionflasher.org - - Bionx Bike Info - © 2018 Thorsten Schmidt (tschmidt@ts-soft.de) - @see www.ts-soft.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - @see https://github.com/bikemike/bionx-bikeinfo - - ***************************************************************************/ - - -#include -#include - - -/// reader functions - - - -TransmitResult readDummy( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) -{ - qDebug() << " --- NO: Read DUMMY: " << registerID; - return std::unexpected( QString("NO: Read DUMMY: %1 : %2 ").arg( deviceID, registerID ) ); -} - -TransmitResult readByteValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) -{ - qDebug() << " --- YES: Read ByteValue: " << registerID; - // Wir lesen nur ein Byte und gut. - return transmitter.readByte( deviceID, registerID ); -} - - -TransmitResult readWordValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) -{ - qDebug() << " --- YES: Read WordValue: " << registerID; - - //getValue(CONSOLE, CONSOLE_SN_PN_HI) << 8) + getValue(CONSOLE, CONSOLE_SN_PN_LO)), - uint32_t result{}; - // hi byte Leseversuch. - TransmitResult value = transmitter.readByte( deviceID, registerID ); - // Fehler? dann weg - if( !value) - return std::unexpected( value.error() ); - // hi byte speichern - result = *value << 8; - // low byte, liegt im followup register: +1 - value = transmitter.readByte( deviceID, registerID+1 ); - if( !value) - return std::unexpected( value.error() ); - result += *value; - return result; -} - -TransmitResult readSpeedValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) -{ - return 0x0; -} - -TransmitResult readODOValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) -{ - return 0x0; -} - -TransmitResult readVoltValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) -{ - return 0x0; -} - -TransmitResult readCircValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) -{ - return 0x0; -} - -/** - * @brief BCValueType::BCValueType - */ - -BCValueType::BCValueType() -{ - -} - - -BCValueType::BCValueType(QString unitKey_, QString unitLabel_, double factor_, optDouble min_, optDouble max_ ) - : unitLabel{unitLabel_}, factor{factor_}, min{min_}, max{max_} -{ - std::optional readFn = fetchReadValueFunction( unitKey_ ); - readValueFunc = readFn.has_value() ? readFn.value() : readDummy; -} - - -QString BCValueType::formatValue( uint32_t value ) const -{ - if( factor == 1 ) - return QString::number( value ); - - double result = value * factor; - return QString::number(result, 'f', 2); -} - -std::optional BCValueType::fetchReadValueFunction( const QString& unitTypeKey ) -{ - static QHash s_bcReadValueFunctions - { - { "Byte", readByteValue }, - { "Word", readWordValue }, - { "Assist", readByteValue }, - - { "Kmh", readByteValue }, - { "Percent",readByteValue }, - { "KWh", readByteValue }, - { "Watt", readByteValue }, - { "Km", readByteValue }, - - { "Mm", readByteValue }, - { "Sec", readByteValue }, - { "Degree", readByteValue }, - { "SoC", readByteValue }, - { "Odo", readByteValue }, - - }; - - if( !s_bcReadValueFunctions.contains( unitTypeKey ) ) - return std::nullopt; - - return s_bcReadValueFunctions[unitTypeKey]; -} - -std::optional BCValueType::fetchValueType( const QString& unitTypeKey ) -{ - static QHash s_bcDataTypes - { - { "Byte", new BCValueType( "Byte", "", 1.5625F) }, - { "Word", new BCValueType( "Word", "", 1.5625F) }, - { "Percent", new BCValueType( "Byte", "%", 1.5625 ) }, - { "AssInit", new BCValueType( "Byte", "", 1.0, 0 ,4 ) }, - { "Assist", new BCValueType( "Byte", "%", 0,400 ) } - /* - { "KWh", new BCValueType( "kwh", 1.5625 ) }, - { "Watt", new BCValueType( "w", 1.5625 ) }, - { "Km", new BCValueType( "km", 1.5625 ) }, - { "Kmh", new BCValueType( "km/h", 0.1 ) }, - { "Mm", new BCValueType( "mm", 1.5625 ) }, - { "Sec", new BCValueType( "s", 1.5625 ) }, - { "Degree", new BCValueType( "°C", 1.0 ) }, - { "SoC", new BCValueType( "%", 1.5625 ) }, - { "Odo", new BCValueType( "km", 1.5625 ) }, - - { "Assist", new BCValueType( "%" ) }, - */ - }; - - if( !s_bcDataTypes.contains( unitTypeKey ) ) - return std::nullopt; - - return s_bcDataTypes[unitTypeKey]; - -} - -/// ---- - diff --git a/bcvaluetype.h b/bcvaluetype.h deleted file mode 100644 index b4a5ca3..0000000 --- a/bcvaluetype.h +++ /dev/null @@ -1,102 +0,0 @@ -/*************************************************************************** - - BionxControl - Copyright © 2025 christoph holzheuer - christoph.holzheuer@gmail.com - - Using: - - mhs_can_drv.c - © 2011 - 2023 by MHS-Elektronik GmbH & Co. KG, Germany - Klaus Demlehner, klaus@mhs-elektronik.de - @see www.mhs-elektronik.de - - Based on Bionx data type descriptions from: - - BigXionFlasher USB V 0.2.4 rev. 97 - © 2011-2013 by Thomas Koenig - @see www.bigxionflasher.org - - Bionx Bike Info - © 2018 Thorsten Schmidt (tschmidt@ts-soft.de) - @see www.ts-soft.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - @see https://github.com/bikemike/bionx-bikeinfo - - ***************************************************************************/ - - -#ifndef BCVALUETYPE_H -#define BCVALUETYPE_H - -#include -#include -#include -#include -#include - -#include - -class BCValue; -class BCAbstractTransmitter; - -using optDouble = std::optional; - -// Enthält den gelesenen Wert oder einen Fehlerstring -using TransmitResult = std::expected; -// Funktionsobject, um Werte aus der Transmitterschicht zu holden -using ReadValueFunc = std::function; - - -/** - * @brief BCAbstractTransmitter ist das abstrakte Basisinterface für die eigentliche - * Datenübertragung auf Treiberebene. - */ - -class BCAbstractTransmitter -{ - -public: - - virtual TransmitResult readByte ( uint32_t deviceID, uint8_t registerID ) const = 0; - virtual TransmitResult writeByte( uint32_t deviceID, uint8_t registerID, uint8_t value_ ) const = 0; -}; - - -struct BCValueType -{ - Q_GADGET - -public: - - BCValueType(); - BCValueType( QString unitKey_, QString unitLabel_, double factor_= 1.0, optDouble min_=std::nullopt, optDouble max_= std::nullopt ); - - virtual QString formatValue( uint32_t value ) const; - - QString unitLabel; - double factor; - optDouble min; - optDouble max; - ReadValueFunc readValueFunc; - //ReadValueFunc readValueFunc; - - - static std::optional fetchValueType( const QString& unitTypeKey ); - static std::optional fetchReadValueFunction( const QString& unitTypeKey ); -}; - - - - - //using BCTypeVariant = std::variant; - -// really needed? -//using BCValueTypeCRef = std::optional>; - - -#endif // BCVALUETYPE_H diff --git a/bcxmlloader.cpp b/bcxmlloader.cpp index 3e90034..a5c8025 100644 --- a/bcxmlloader.cpp +++ b/bcxmlloader.cpp @@ -32,28 +32,20 @@ #include #include -#include -#include #include -#include -#include -#include +#include +#include #include -#include + using namespace Qt::StringLiterals; - - BCXmlLoader::BCXmlLoader(QObject *parent) : QObject(parent) { - //qRegisterMetaType("BCValue*"); //qRegisterMetaType(); - - } @@ -156,17 +148,22 @@ void BCXmlLoader::loadXmlBikeDeviceData(BCDevice::ID deviceID) if( _xml.attributes().hasAttribute(BCTags::ID) ) { //qDebug() << " --- found: " << _xml.name() << " : " << _xml.attributes().value(BCTags::ID); - QString id = _xml.attributes().value(BCTags::ID).toString(); + // füllen des Parameter packs - BCDataParams params + BCValueParams params { - .ID = id, - .Label = _xml.attributes().value(BCTags::Label).toString(), - .UnitType = _xml.attributes().value(BCTags::UnitType).toString(), + .ID = _xml.attributes().value(BCTags::ID).toString(), + .Label = _xml.attributes().value(BCTags::Label).toString(), + .UnitLabel = _xml.attributes().value(BCTags::UnitLabel).toString(), + .Factor = _xml.attributes().value(BCTags::Factor).toString(), + .Min = _xml.attributes().value(BCTags::Min).toString(), + .Max = _xml.attributes().value(BCTags::Max).toString(), + .IsWord = _xml.attributes().value(BCTags::IsWord).toString(), + .ValueType = _xml.attributes().value(BCTags::ValueType).toString(), }; // nur gültige Werte sind vorhanden und können gespeichert werden - std::optional newValue = makeDataValue( deviceID, params ); + std::optional newValue = makeValue( deviceID, params ); if(newValue) { // wir merken uns gleich den index in der Werteliste @@ -185,11 +182,26 @@ void BCXmlLoader::loadXmlBikeDeviceData(BCDevice::ID deviceID) } -std::optional BCXmlLoader::makeDataValue( BCDevice::ID deviceID, const BCDataParams& params ) +std::optional BCXmlLoader::makeValue( BCDevice::ID deviceID, const BCValueParams& params ) { /* - auto setIfExists = [&]( QStringView source, optDouble& target ) + static QHash 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 ) { if( !source.isEmpty() ) { @@ -199,11 +211,9 @@ std::optional BCXmlLoader::makeDataValue( BCDevice::ID deviceID, con target = testVal; } }; - */ static QMetaEnum s_bcValueEnum{QMetaEnum::fromType()}; - /* Wir brauchen: - einen gültige ID String um die enum ID herauszufinden. @@ -215,69 +225,39 @@ std::optional BCXmlLoader::makeDataValue( BCDevice::ID deviceID, con //std::optional IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() ); bool ok; int IDVal = s_bcValueEnum.keyToValue( params.ID.toLatin1().constData(), &ok ); - qDebug() << " --- should create: " << params.Label << ": " << params.UnitType; + qDebug() << " --- should create: " << params.Label; //if( IDVal.has_value() ) if( ok ) { - auto valueType = BCValueType::fetchValueType(params.UnitType); - if( valueType.has_value() ) - { - BCValuePtr newValue = std::make_shared( *valueType, deviceID, static_cast(IDVal) ); + BCValuePtr newValue = std::make_shared( deviceID, static_cast(IDVal) ); - /* - setIfExists( params.Factor, newValue.factor ); - setIfExists( params.Min, newValue.min ); - setIfExists( params.Max, newValue.max ); - */ - newValue->label = params.Label; - qDebug() << " --- created: " << params.Label; + //setIfExists( params.Factor, newValue->factor ); + setIfExists( params.Min, newValue->min ); + setIfExists( params.Max, newValue->max ); - return std::optional( newValue ); - } + newValue->label = params.Label; + + /* + QString ID; + QString Label; + QString UnitLabel; + QString Factor; + QString Min; + QString Max; + QString IsWord; + QString ValueType; +*/ + + + qDebug() << " --- created: " << params.Label; + + return std::optional( newValue ); } return std::nullopt; } - // --- NEU: Speichern mit QXmlStreamWriter --- -void BCXmlLoader::saveBikeData() -{ - /* - QString fileName = QFileDialog::getSaveFileName(this, "XML speichern", "", "XML Files (*.xml)"); - if (fileName.isEmpty()) return; - - QFile file(fileName); - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { - QMessageBox::warning(this, "Fehler", "Datei konnte nicht zum Schreiben geöffnet werden."); - return; - } - - QXmlStreamWriter xml(&file); - xml.setAutoFormatting(true); // Sorgt für schöne Einrückungen (Tabs/Spaces) - xml.writeStartDocument(); - xml.writeStartElement("devices"); - - // Daten vom Model holen - const QList &devices = m_model->getDevices(); - - for (const Device &d : devices) { - xml.writeStartElement("device"); - xml.writeAttribute("name", d.name); - xml.writeAttribute("ip", d.ip); - xml.writeEndElement(); // - } - - xml.writeEndElement(); // - xml.writeEndDocument(); - - // Prüfen ob alles geschrieben wurde - if (file.error() != QFile::NoError) { - QMessageBox::critical(this, "Fehler", "Fehler beim Schreiben der Datei."); - } else { - statusBar()->showMessage("Datei erfolgreich gespeichert!", 3000); - } - */ -} + diff --git a/bcxmlloader.h b/bcxmlloader.h index ed1f339..7f779c3 100644 --- a/bcxmlloader.h +++ b/bcxmlloader.h @@ -33,15 +33,9 @@ #ifndef BCXMLLOADER_H #define BCXMLLOADER_H -#include #include -#include -#include -#include -#include - -#include +#include class BCXmlLoader : public QObject @@ -55,8 +49,7 @@ public: public slots: - void loadXmlBikeData( const QString& fileName ); - void saveBikeData(); + void loadXmlBikeData( const QString& fileName );; signals: @@ -64,16 +57,21 @@ signals: protected: - struct BCDataParams + struct BCValueParams { QString ID; QString Label; - QString UnitType; + QString UnitLabel; + QString Factor; + QString Min; + QString Max; + QString IsWord; + QString ValueType; }; void loadXmlBikeDeviceData( BCDevice::ID deviceID ); - std::optional makeDataValue( BCDevice::ID deviceID, const BCDataParams& params ); + std::optional makeValue( BCDevice::ID deviceID, const BCValueParams& params ); QXmlStreamReader _xml; diff --git a/resources/bikeinfo.xml b/resources/bikeinfo.xml index 9b55d5f..a16f03d 100644 --- a/resources/bikeinfo.xml +++ b/resources/bikeinfo.xml @@ -1,45 +1,56 @@ + - - - - + + + + - - - - - + + + + + - - + + - - + + - - + + - - + + - - - - - - - + + + + + + + + - - + + @@ -57,106 +68,104 @@ - - - - + + + + - - - - + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - + + + + - - - - - + + + + + - + - - - - + + - + - - + + - - - - - - - - + + + + + + + + - - - + + + - - - - - - - - - + + + + + + + + + - - - - + + + + - - + + - - + + - + - - - + + + - - - - - - + + + + + + - - + + --> From 61bf3b2cec00e7b265549f708d99e93abd46953e Mon Sep 17 00:00:00 2001 From: "DIASPORA\\chris" Date: Sat, 3 Jan 2026 12:48:47 +0100 Subject: [PATCH 2/2] Dropped BCAbstractTransmitter, simplified code. --- bctransmitter.cpp | 48 +++++++++++++++----------------- bctransmitter.h | 13 +++++---- bcvalue.cpp | 60 ---------------------------------------- bcvalue.h | 21 ++------------ bcxmlloader.cpp | 62 ++++++++++++++++++++---------------------- resources/bikeinfo.xml | 12 ++++---- 6 files changed, 68 insertions(+), 148 deletions(-) diff --git a/bctransmitter.cpp b/bctransmitter.cpp index 0cce74b..4cd1815 100644 --- a/bctransmitter.cpp +++ b/bctransmitter.cpp @@ -137,21 +137,17 @@ void BCTransmitter::processValue() else if( value.state.testFlag( BCValue::State::ReadMe ) ) { - - /* // wir sind hier im anderen thread! nicht einfach so reinschreiben, nur lesen - TransmitResult result = valueType.readValueFunc( *this, devID, regID ); + TransmitResult result = value.isWord ? readWordValue( devID, regID ) : readByteValue( devID, regID ); if( result.has_value() ) { - newVisibleValue = valueType.formatValue( result.value() ); + newVisibleValue = value.formatValue( result.value() ); newState = BCValue::State::InSync; } else { newState = BCValue::State::Failed; } -*/ - } emit valueUpdated( value.deviceID, value.indexRow, newState, newVisibleValue ); @@ -165,30 +161,30 @@ void BCTransmitter::processValue() } -/** - * @brief BCTransmitter::readByte - * NEIN NEIN NEIN! - * Reicht den read request an den aktuellen Treiber weiter. Wird von aussen, von der readValueFunc des ValueTypes - * aufgerufen, deshalb public. - */ - -TransmitResult BCTransmitter::readByte( uint32_t deviceID, uint8_t registerID ) const +TransmitResult BCTransmitter::readByteValue( uint32_t deviceID, uint8_t registerID ) { + qDebug() << " --- YES: Read ByteValue: " << registerID; + // Wir lesen nur ein Byte und gut. return _canDriver->readRawByte( deviceID, registerID ); } -/** - * @brief BCTransmitter::writeByte - * Reicht den write request an den aktuellen Treiber weiter. Wird von aussen, von der writeValueFunc des ValueTypes - * aufgerufen, deshalb public. - */ - -TransmitResult BCTransmitter::writeByte( uint32_t deviceID, uint8_t registerID , uint8_t value ) const +TransmitResult BCTransmitter::readWordValue( uint32_t deviceID, uint8_t registerID ) { - return _canDriver->writeRawByte( deviceID, registerID, value ); + qDebug() << " --- YES: Read WordValue: " << registerID; + + uint32_t result{}; + // hi byte Leseversuch. + TransmitResult value = _canDriver->readRawByte( deviceID, registerID ); + // Fehler? dann weg + if( !value) + return std::unexpected( value.error() ); + // hi byte speichern + result = *value << 8; + // low byte, liegt im followup register: +1 + value = _canDriver->readRawByte( deviceID, registerID+1 ); + if( !value) + return std::unexpected( value.error() ); + result += *value; + return result; } - - - - diff --git a/bctransmitter.h b/bctransmitter.h index 192c6fb..08f57b2 100644 --- a/bctransmitter.h +++ b/bctransmitter.h @@ -52,7 +52,7 @@ * implementiert sein und liest/schreibt Byteweise auf den Bus. */ -class BCTransmitter : public QObject, public BCAbstractTransmitter +class BCTransmitter : public QObject { Q_OBJECT @@ -60,8 +60,8 @@ public: explicit BCTransmitter(QObject *parent = nullptr); - TransmitResult readByte( uint32_t deviceID, uint8_t registerID ) const override; - TransmitResult writeByte( uint32_t deviceID, uint8_t registerID, uint8_t value ) const override; + //TransmitResult readByte( uint32_t deviceID, uint8_t registerID ) const override; + //TransmitResult writeByte( uint32_t deviceID, uint8_t registerID, uint8_t value ) const override; public slots: @@ -76,8 +76,11 @@ signals: private: - void readRawValueX ( const BCValue& value ) const; - void writeRawValueX( const BCValue& value ) const; + TransmitResult readByteValue( uint32_t deviceID, uint8_t registerID ); + TransmitResult readWordValue( uint32_t deviceID, uint8_t registerID ); + //TransmitResult writeByteValue( uint32_t deviceID, uint8_t registerID ); + //TransmitResult writeWordValue( uint32_t deviceID, uint8_t registerID ); + using BCDataQueue = QQueue; diff --git a/bcvalue.cpp b/bcvalue.cpp index f888ee2..16a1cf9 100644 --- a/bcvalue.cpp +++ b/bcvalue.cpp @@ -79,66 +79,6 @@ the Free Software Foundation; either version 3 of the License, or -/// reader functions - - - -TransmitResult readDummy( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) -{ - qDebug() << " --- NO: Read DUMMY: " << registerID; - return std::unexpected( QString("NO: Read DUMMY: %1 : %2 ").arg( deviceID, registerID ) ); -} - -TransmitResult readByteValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) -{ - qDebug() << " --- YES: Read ByteValue: " << registerID; - // Wir lesen nur ein Byte und gut. - return transmitter.readByte( deviceID, registerID ); -} - - -TransmitResult readWordValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) -{ - qDebug() << " --- YES: Read WordValue: " << registerID; - - //getValue(CONSOLE, CONSOLE_SN_PN_HI) << 8) + getValue(CONSOLE, CONSOLE_SN_PN_LO)), - uint32_t result{}; - // hi byte Leseversuch. - TransmitResult value = transmitter.readByte( deviceID, registerID ); - // Fehler? dann weg - if( !value) - return std::unexpected( value.error() ); - // hi byte speichern - result = *value << 8; - // low byte, liegt im followup register: +1 - value = transmitter.readByte( deviceID, registerID+1 ); - if( !value) - return std::unexpected( value.error() ); - result += *value; - return result; -} - -TransmitResult readSpeedValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) -{ - return 0x0; -} - -TransmitResult readODOValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) -{ - return 0x0; -} - -TransmitResult readVoltValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) -{ - return 0x0; -} - -TransmitResult readCircValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) -{ - return 0x0; -} - - QString BCValue::formatValue( uint32_t value ) const { diff --git a/bcvalue.h b/bcvalue.h index b7b9b70..1b41ed0 100644 --- a/bcvalue.h +++ b/bcvalue.h @@ -78,8 +78,8 @@ public: { Plain, Bool, - Float, - Mookoo + Number, + Float }; enum class State : uint8_t @@ -130,22 +130,5 @@ Q_DECLARE_METATYPE(const BCValuePtr) Q_DECLARE_METATYPE(BCValueList) -/** - * @brief BCAbstractTransmitter ist das abstrakte Basisinterface für die eigentliche - * Datenübertragung auf Treiberebene. - */ - -class BCAbstractTransmitter -{ - -public: - - virtual TransmitResult readByte ( uint32_t deviceID, uint8_t registerID ) const = 0; - virtual TransmitResult writeByte( uint32_t deviceID, uint8_t registerID, uint8_t value_ ) const = 0; -}; - - - - #endif // BCVALUE_H diff --git a/bcxmlloader.cpp b/bcxmlloader.cpp index a5c8025..f3108bf 100644 --- a/bcxmlloader.cpp +++ b/bcxmlloader.cpp @@ -185,34 +185,25 @@ void BCXmlLoader::loadXmlBikeDeviceData(BCDevice::ID deviceID) std::optional BCXmlLoader::makeValue( BCDevice::ID deviceID, const BCValueParams& params ) { - /* - static QHash 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 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 = [&]( QStringView source, T& target ) + { + if( !source.isEmpty() ) + { + bool ok; + double testVal = source.toDouble(&ok); + if (ok) + target = testVal; + } }; - static QMetaEnum s_bcValueEnum{QMetaEnum::fromType()}; /* Wir brauchen: @@ -224,18 +215,26 @@ std::optional BCXmlLoader::makeValue( BCDevice::ID deviceID, const B // geht nicht auf qt6.8 von debian trixie //std::optional IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() ); bool ok; + static QMetaEnum s_bcValueEnum{QMetaEnum::fromType()}; 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( deviceID, static_cast(IDVal) ); + BCValuePtr newValuePtr = std::make_shared( deviceID, static_cast(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 BCXmlLoader::makeValue( BCDevice::ID deviceID, const B QString ValueType; */ - qDebug() << " --- created: " << params.Label; - return std::optional( newValue ); + return std::optional( newValuePtr ); } return std::nullopt; diff --git a/resources/bikeinfo.xml b/resources/bikeinfo.xml index a16f03d..a3319df 100644 --- a/resources/bikeinfo.xml +++ b/resources/bikeinfo.xml @@ -15,8 +15,8 @@ QString ValueType; - - + + @@ -33,19 +33,19 @@ QString ValueType; - + - - + + - +