Fixed Flag handling.

This commit is contained in:
2026-01-08 20:47:05 +01:00
parent 6b03797600
commit d6da7aac9a
11 changed files with 39 additions and 51 deletions

40
bc.h
View File

@@ -40,6 +40,27 @@
//uint8_t; //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 * @brief Simple exception class
*/ */
@@ -736,24 +757,5 @@ public:
Q_ENUM(ID) 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 #endif // BC_H

View File

@@ -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. * @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 ); _itemDelegate->onHighlightRow( index );
} }

View File

@@ -48,15 +48,13 @@ public:
explicit BCDeviceView(QWidget *parent = nullptr); explicit BCDeviceView(QWidget *parent = nullptr);
void setDeviceID( BCDevice::ID deviceID ); void setDeviceID( BCDevice::ID deviceID );
BCDevice::ID getDeviceID() const; BCDevice::ID getDeviceID() const;
const BCValueList& getValueListX(); const BCValueList& getValueListX();
bool firstExpose(); bool firstExpose();
void updateValue( int index, BCValue::Flag state, uint32_t rawValue ); void updateValue(int index, BCValue::Flags newState, uint32_t rawValue );
public slots: public slots:

View File

@@ -298,13 +298,13 @@ void BCMainWindow::onConnectButtonToggled(bool checked )
//_dataManager.setDriverConnectionState( 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 ) ) if( _devicePanels.contains( deviceID ) )
{ {
BCDeviceView& panel = *_devicePanels[deviceID]; BCDeviceView& panel = *_devicePanels[deviceID];
panel.updateValue( index, state, rawValue ); panel.updateValue( index, newState, rawValue );
} }
} }

View File

@@ -61,7 +61,7 @@ public slots:
void onDriverStateChanged( BCDriver::DriverState state, const QString& message="" ); void onDriverStateChanged( BCDriver::DriverState state, const QString& message="" );
// Slots für Rückmeldungen vom Transmitter // 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 onEndOfProcessing();
void onSyncDeviceView(); void onSyncDeviceView();

View File

@@ -140,34 +140,17 @@ void BCTransmitter::onUpdateValue( BCValuePtrConst valuePtr)
// Das klappt aber nur in der hier gewählten Konstellation mit einer Parent-Thread // Das klappt aber nur in der hier gewählten Konstellation mit einer Parent-Thread
// und einem Worker. // 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 // Kosmetik
const BCValue& value = *(valuePtr.get()); const BCValue& value = *(valuePtr.get());
// Kosmetik
//const BCValue& value = *(valuePtr.get());
//qDebug() << "------- DE.-.QUEUE: " << QThread::currentThreadId() << ": " << value.label; //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<uint32_t>(value.deviceID); uint32_t devID = static_cast<uint32_t>(value.deviceID);
uint8_t regID = static_cast<uint8_t> (value.registerID); uint8_t regID = static_cast<uint8_t> (value.registerID);
// Für den Fehlerfall: Wir senden den alten Wert einfach zurück // Für den Fehlerfall: Wir senden den alten Wert einfach zurück
uint32_t newValue = value.rawValue; uint32_t newValue = value.rawValue;
BCValue::Flag newState = BCValue::Flag::Failed;; BCValue::Flag newState = BCValue::Flag::Failed;
if(value.valueFlags.testFlag( BCValue::Flag::WriteMe ) ) if(value.valueFlags.testFlag( BCValue::Flag::WriteMe ) )
{ {

View File

@@ -63,7 +63,6 @@ public slots:
void onToggleDriverConnection( bool connect ); void onToggleDriverConnection( bool connect );
void onUpdateValue(BCValuePtrConst valuePtr ); void onUpdateValue(BCValuePtrConst valuePtr );
void onProcessValue();
void onStartNativeDriver(); void onStartNativeDriver();
void onEndOfTransmission(); void onEndOfTransmission();

View File

@@ -65,6 +65,7 @@ using TransmitResult = std::expected<uint32_t,QString>;
class BCValue class BCValue
{ {
Q_GADGET
public: public:
@@ -91,6 +92,7 @@ public:
IsWord = 0x80 IsWord = 0x80
}; };
Q_DECLARE_FLAGS(Flags, Flag ) Q_DECLARE_FLAGS(Flags, Flag )
Q_FLAG(Flags)
BCValue( BCDevice::ID deviceID_, BC::ID registerID_ ); BCValue( BCDevice::ID deviceID_, BC::ID registerID_ );

View File

@@ -81,12 +81,16 @@ void BCValueModel::takeValueList(BCValueList& newValueList)
* @param newValue Der neue sichtbare Zahlenwert, formatiert als QString, optionall * @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() ) if( row > -1 && row < _valueList.size() )
{ {
const BCValue& value = *(_valueList[row].get()); 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! // Obacht hier!
//value.valueFlags = state; //value.valueFlags = state;
value.rawValue = rawValue; value.rawValue = rawValue;

View File

@@ -66,7 +66,7 @@ public:
Qt::ItemFlags flags(const QModelIndex& index) const override; Qt::ItemFlags flags(const QModelIndex& index) const override;
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) 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: protected:

View File

@@ -124,7 +124,7 @@ void BCXmlLoader::loadXmlBikeDeviceData(BCDevice::ID deviceID)
}; };
printAttrs (_xml); 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 // temporäre Wertliste für neues Device
BCValueList currentValues; BCValueList currentValues;
@@ -205,7 +205,7 @@ std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const B
bool ok; bool ok;
static QMetaEnum s_bcValueEnum{QMetaEnum::fromType<BC::ID>()}; static QMetaEnum s_bcValueEnum{QMetaEnum::fromType<BC::ID>()};
QByteArray byteArray = params.ID.toUtf8(); 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; qDebug() << " --- should create: " << params.Label;
//if( IDVal.has_value() ) //if( IDVal.has_value() )
if( !ok ) if( !ok )