From d6da7aac9addede066f9d6ea651916c9aaf8fd36 Mon Sep 17 00:00:00 2001 From: "PANIK\\chris" Date: Thu, 8 Jan 2026 20:47:05 +0100 Subject: [PATCH] Fixed Flag handling. --- bc.h | 40 +++++++++++++++++++++------------------- bcdeviceview.cpp | 4 ++-- bcdeviceview.h | 4 +--- bcmainwindow.cpp | 6 +++--- bcmainwindow.h | 2 +- bctransmitter.cpp | 19 +------------------ bctransmitter.h | 1 - bcvalue.h | 2 ++ bcvaluemodel.cpp | 6 +++++- bcvaluemodel.h | 2 +- bcxmlloader.cpp | 4 ++-- 11 files changed, 39 insertions(+), 51 deletions(-) diff --git a/bc.h b/bc.h index 4f1b007..19c2beb 100644 --- a/bc.h +++ b/bc.h @@ -40,6 +40,27 @@ //uint8_t; +using namespace Qt::Literals::StringLiterals; // Für _L1 + +namespace BCTags +{ + inline constexpr auto Bike = "Bike"_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 ReadOnly = "ReadOnly"_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; +} + /** * @brief Simple exception class */ @@ -736,24 +757,5 @@ public: Q_ENUM(ID) }; -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 UnitLabel = "UnitLabel"_L1; - inline constexpr auto IsWord = "IsWord"_L1; - inline constexpr auto ReadOnly = "ReadOnly"_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/bcdeviceview.cpp b/bcdeviceview.cpp index ec75083..fa88cfd 100644 --- a/bcdeviceview.cpp +++ b/bcdeviceview.cpp @@ -98,9 +98,9 @@ void BCDeviceView::onValueListReady( BCDevice::ID deviceID, BCValueList valueLis * @brief SLOT, der aufgerufen wird, wenn ein Value geändert wurde. Gibt dem ItemDelegate Bescheid. */ -void BCDeviceView::updateValue(int index, BCValue::Flag state, uint32_t rawValue ) +void BCDeviceView::updateValue(int index,BCValue::Flags newState, uint32_t rawValue ) { - _valueModel.updateValue( index, state, rawValue ); + _valueModel.updateValue( index, newState, rawValue ); _itemDelegate->onHighlightRow( index ); } diff --git a/bcdeviceview.h b/bcdeviceview.h index 28885b0..b1b275a 100644 --- a/bcdeviceview.h +++ b/bcdeviceview.h @@ -48,15 +48,13 @@ public: explicit BCDeviceView(QWidget *parent = nullptr); - void setDeviceID( BCDevice::ID deviceID ); BCDevice::ID getDeviceID() const; const BCValueList& getValueListX(); bool firstExpose(); - void updateValue( int index, BCValue::Flag state, uint32_t rawValue ); - + void updateValue(int index, BCValue::Flags newState, uint32_t rawValue ); public slots: diff --git a/bcmainwindow.cpp b/bcmainwindow.cpp index bd3bf1a..650be11 100644 --- a/bcmainwindow.cpp +++ b/bcmainwindow.cpp @@ -298,13 +298,13 @@ void BCMainWindow::onConnectButtonToggled(bool checked ) //_dataManager.setDriverConnectionState( checked ); } -void BCMainWindow::onValueUpdated(BCDevice::ID deviceID, int index, BCValue::Flag state, uint32_t rawValue ) +void BCMainWindow::onValueUpdated(BCDevice::ID deviceID, int index, BCValue::Flags newState, uint32_t rawValue ) { - qDebug() << "Reply: from: " << deviceID << " at: " << index << "finished. Success:" << (uint8_t)state << " on:" << rawValue; + qDebug() << "Reply: from: " << deviceID << " at: " << index << "finished. Success:" << (uint8_t)newState << " on:" << rawValue; if( _devicePanels.contains( deviceID ) ) { BCDeviceView& panel = *_devicePanels[deviceID]; - panel.updateValue( index, state, rawValue ); + panel.updateValue( index, newState, rawValue ); } } diff --git a/bcmainwindow.h b/bcmainwindow.h index 37e6c3c..2da826b 100644 --- a/bcmainwindow.h +++ b/bcmainwindow.h @@ -61,7 +61,7 @@ public slots: void onDriverStateChanged( BCDriver::DriverState state, const QString& message="" ); // Slots für Rückmeldungen vom Transmitter - void onValueUpdated( BCDevice::ID deviceID, int index, BCValue::Flag state, uint32_t rawValue ); + void onValueUpdated( BCDevice::ID deviceID, int index, BCValue::Flags newState, uint32_t rawValue ); void onEndOfProcessing(); void onSyncDeviceView(); diff --git a/bctransmitter.cpp b/bctransmitter.cpp index 455c3af..ffe717d 100644 --- a/bctransmitter.cpp +++ b/bctransmitter.cpp @@ -140,34 +140,17 @@ void BCTransmitter::onUpdateValue( BCValuePtrConst valuePtr) // Das klappt aber nur in der hier gewählten Konstellation mit einer Parent-Thread // und einem Worker. - // Wir benutzen doch eine zusätzliche Queue, um erkennen zu können, ob der - // der aktuelle Auftragsblock abgearbeit wurde. - - //_valueQueue.enqueue( valuePtr ); - //qDebug() << " # #### ENQ: " <<_valueQueue.size(); - - // Wir schicken den event gleich wieder weiter ... - //QMetaObject::invokeMethod(this, "onProcessValue", Qt::QueuedConnection); - - - // Kosmetik const BCValue& value = *(valuePtr.get()); - // Kosmetik - //const BCValue& value = *(valuePtr.get()); - //qDebug() << "------- DE.-.QUEUE: " << QThread::currentThreadId() << ": " << value.label; - // Value ist 'under construction' - //emit valueUpdated( value.deviceID, value.indexRow, BCValue::Flag::Locked ); - uint32_t devID = static_cast(value.deviceID); uint8_t regID = static_cast (value.registerID); // Für den Fehlerfall: Wir senden den alten Wert einfach zurück uint32_t newValue = value.rawValue; - BCValue::Flag newState = BCValue::Flag::Failed;; + BCValue::Flag newState = BCValue::Flag::Failed; if(value.valueFlags.testFlag( BCValue::Flag::WriteMe ) ) { diff --git a/bctransmitter.h b/bctransmitter.h index 3ee316e..f58c2ab 100644 --- a/bctransmitter.h +++ b/bctransmitter.h @@ -63,7 +63,6 @@ public slots: void onToggleDriverConnection( bool connect ); void onUpdateValue(BCValuePtrConst valuePtr ); - void onProcessValue(); void onStartNativeDriver(); void onEndOfTransmission(); diff --git a/bcvalue.h b/bcvalue.h index cd97b99..c5ffafe 100644 --- a/bcvalue.h +++ b/bcvalue.h @@ -65,6 +65,7 @@ using TransmitResult = std::expected; class BCValue { + Q_GADGET public: @@ -91,6 +92,7 @@ public: IsWord = 0x80 }; Q_DECLARE_FLAGS(Flags, Flag ) + Q_FLAG(Flags) BCValue( BCDevice::ID deviceID_, BC::ID registerID_ ); diff --git a/bcvaluemodel.cpp b/bcvaluemodel.cpp index 8be7996..f79932b 100644 --- a/bcvaluemodel.cpp +++ b/bcvaluemodel.cpp @@ -81,12 +81,16 @@ void BCValueModel::takeValueList(BCValueList& newValueList) * @param newValue Der neue sichtbare Zahlenwert, formatiert als QString, optionall */ -void BCValueModel::updateValue(int row, BCValue::Flag state, uint32_t rawValue ) +void BCValueModel::updateValue(int row, BCValue::Flags newState, uint32_t rawValue ) { if( row > -1 && row < _valueList.size() ) { const BCValue& value = *(_valueList[row].get()); + BCValue::Flags newFlags1 = BCValue::Flag::NoFlag; + BCValue::Flags newFlags2 = newState; + qDebug() << " ---- XXX1: ValueUpdate: Flags: " << newFlags1; + qDebug() << " ---- XXX2: ValueUpdate: Flags: " << newFlags2; // Obacht hier! //value.valueFlags = state; value.rawValue = rawValue; diff --git a/bcvaluemodel.h b/bcvaluemodel.h index 25fc1bb..71a8d6b 100644 --- a/bcvaluemodel.h +++ b/bcvaluemodel.h @@ -66,7 +66,7 @@ public: Qt::ItemFlags flags(const QModelIndex& index) const override; bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; - void updateValue(int row, BCValue::Flag state, uint32_t rawValue ); + void updateValue(int row, BCValue::Flags newState, uint32_t rawValue ); protected: diff --git a/bcxmlloader.cpp b/bcxmlloader.cpp index 5679f2b..3f14f3a 100644 --- a/bcxmlloader.cpp +++ b/bcxmlloader.cpp @@ -124,7 +124,7 @@ void BCXmlLoader::loadXmlBikeDeviceData(BCDevice::ID deviceID) }; printAttrs (_xml); - Q_ASSERT(_xml.isStartElement() && _xml.name() == "Device"_L1); + Q_ASSERT(_xml.isStartElement() && _xml.name() == BCTags::Device ); // temporäre Wertliste für neues Device BCValueList currentValues; @@ -205,7 +205,7 @@ std::optional BCXmlLoader::makeValue( BCDevice::ID deviceID, const B bool ok; static QMetaEnum s_bcValueEnum{QMetaEnum::fromType()}; QByteArray byteArray = params.ID.toUtf8(); - int IDVal = s_bcValueEnum.keyToValue( byteArray.constData(), &ok ); + int IDVal = s_bcValueEnum.keyToValue( params.ID.toUtf8().constData(), &ok ); qDebug() << " --- should create: " << params.Label; //if( IDVal.has_value() ) if( !ok )