Fixed Flag handling.
This commit is contained in:
40
bc.h
40
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
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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<uint32_t>(value.deviceID);
|
||||
uint8_t regID = static_cast<uint8_t> (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 ) )
|
||||
{
|
||||
|
||||
@@ -63,7 +63,6 @@ public slots:
|
||||
|
||||
void onToggleDriverConnection( bool connect );
|
||||
void onUpdateValue(BCValuePtrConst valuePtr );
|
||||
void onProcessValue();
|
||||
void onStartNativeDriver();
|
||||
void onEndOfTransmission();
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ using TransmitResult = std::expected<uint32_t,QString>;
|
||||
|
||||
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_ );
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -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<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const B
|
||||
bool ok;
|
||||
static QMetaEnum s_bcValueEnum{QMetaEnum::fromType<BC::ID>()};
|
||||
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 )
|
||||
|
||||
Reference in New Issue
Block a user