Reworked transmitter.

This commit is contained in:
2026-01-02 22:15:50 +01:00
parent 4b5518de5d
commit f5ad48faf2
7 changed files with 91 additions and 12 deletions

View File

@@ -164,14 +164,18 @@ void BCMainWindow::initMainWindow()
_worker.start(); _worker.start();
// die Daten des eBikes laden // die Daten des eBikes laden
_dataManager.loadXmlBikeData(":/bikeinfo.xml"_L1); _dataManager.loadXmlBikeData(":/bikeinfo.xml"_L1);
_consoleAction->trigger(); _consoleAction->trigger();
connect( &_transmitter, &BCTransmitter::driverStateChanged, this, &BCMainWindow::onDriverStateChanged );
// --- STATUSBAR SETUP ---
}
void BCMainWindow::initStatusBar()
{
// __fix
QStatusBar *statBar = statusBar(); QStatusBar *statBar = statusBar();
// Optional: Normale Nachricht links // Optional: Normale Nachricht links
@@ -199,6 +203,18 @@ void BCMainWindow::initMainWindow()
} }
void BCMainWindow::autoConnect()
{
// __fix!
// if( !connect)
// fallBack
}
void BCMainWindow::onDriverStateChanged( BCDriver::DriverState state, const QString& message )
{
qDebug() << " --- on DriverStatusChanged: " << state << ":" << message;
}
void BCMainWindow::onShowDevicePanel( BCDevice::ID deviceID ) void BCMainWindow::onShowDevicePanel( BCDevice::ID deviceID )
{ {
qDebug() << " --- onShowDevicePanel:" << deviceID; qDebug() << " --- onShowDevicePanel:" << deviceID;

View File

@@ -56,6 +56,7 @@ public slots:
//void onValueListReady( BCDevice::ID deviceID ); //void onValueListReady( BCDevice::ID deviceID );
void onShowDevicePanel( BCDevice::ID deviceID ); void onShowDevicePanel( BCDevice::ID deviceID );
void onConnectButtonToggled(bool active ); void onConnectButtonToggled(bool active );
void onDriverStateChanged( BCDriver::DriverState state, const QString& message="" );
// Slots für Rückmeldungen vom Runner // Slots für Rückmeldungen vom Runner
void onValueUpdated( BCDevice::ID deviceID, int index, BCValue::State state, const QString& newValue="" ); void onValueUpdated( BCDevice::ID deviceID, int index, BCValue::State state, const QString& newValue="" );
@@ -69,6 +70,8 @@ signals:
protected: protected:
void initMainWindow(); void initMainWindow();
void initStatusBar();
void autoConnect();
BCXmlLoader _dataManager; BCXmlLoader _dataManager;

View File

@@ -39,8 +39,10 @@
BCTransmitter::BCTransmitter(QObject *parent) BCTransmitter::BCTransmitter(QObject *parent)
: QObject(parent), _isBusy(false) : QObject(parent), _isBusy(false)
{ {
_canDriver = new BCDriverTinyCan{this}; //_canDriver = new BCDriverTinyCan{this};
//_canDriver = new BCDriverDummy{this}; _canDriver = new BCDriverDummy{this};
// forward driver state
connect( _canDriver, &BCDriver::driverStateChanged, this, &BCTransmitter::driverStateChanged );
} }
@@ -82,11 +84,14 @@ void BCTransmitter::enqueueValue( BCValuePtrConst value)
// invokeMethod mit QueuedConnection entkoppelt den Aufruf, // invokeMethod mit QueuedConnection entkoppelt den Aufruf,
// damit enqueueValue sofort zurückkehrt (non-blocking für den Aufrufer). // damit enqueueValue sofort zurückkehrt (non-blocking für den Aufrufer).
//QMetaObject::invokeMethod(this, "processValue", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "processValue", Qt::QueuedConnection);
/*
QMetaObject::invokeMethod(this, [this]() QMetaObject::invokeMethod(this, [this]()
{ {
processValue(); processValue();
}, Qt::QueuedConnection ); }, Qt::QueuedConnection );
*/
} }
void BCTransmitter::processValue() void BCTransmitter::processValue()
@@ -114,13 +119,15 @@ void BCTransmitter::processValue()
const BCValue& value = *(valuePtr.get()); const BCValue& value = *(valuePtr.get());
// Value ist 'under construction' // Value ist 'under construction'
//emit valueUpdated( val.deviceID, val.indexRow, BCValue::State::Locked ); //emit valueUpdated( value.deviceID, value.indexRow, BCValue::State::Locked );
const BCValueType& valueType = *value.valueType; const BCValueType& valueType = *value.valueType;
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);
QString newVisibleValue; QString newVisibleValue;
BCValue::State newState = BCValue::State::NoState;
if(value.state.testFlag( BCValue::State::WriteMe ) ) if(value.state.testFlag( BCValue::State::WriteMe ) )
{ {
@@ -135,11 +142,18 @@ void BCTransmitter::processValue()
// wir sind hier im anderen thread! nicht einfach so reinschreiben, nur lesen // wir sind hier im anderen thread! nicht einfach so reinschreiben, nur lesen
TransmitResult result = valueType.readValueFunc( *this, devID, regID ); TransmitResult result = valueType.readValueFunc( *this, devID, regID );
if( result.has_value() ) if( result.has_value() )
{
newVisibleValue = valueType.formatValue( result.value() ); newVisibleValue = valueType.formatValue( result.value() );
//emit valueUpdated( value.deviceID, value.indexRow, BCValue::State::InSync, result ); newState = BCValue::State::InSync;
}
else
{
newState = BCValue::State::Failed;
} }
// emit valueUpdated( value->deviceID, value->indexRow, BCValue::State::InSync, "fitze!"); }
emit valueUpdated( value.deviceID, value.indexRow, newState, newVisibleValue );
// __fix // __fix
bc::processEventsFor(50); bc::processEventsFor(50);

View File

@@ -86,6 +86,7 @@ private:
QMutex _mutex; QMutex _mutex;
std::atomic<bool> _isBusy{ false }; std::atomic<bool> _isBusy{ false };
// __fix! set two
BCDriver* _canDriver{}; BCDriver* _canDriver{};
}; };

View File

@@ -58,7 +58,7 @@
class BCValueType; struct BCValueType;
class BCValue class BCValue
{ {

45
doc/challenges.txt Normal file
View File

@@ -0,0 +1,45 @@
Challenges
-------------------------------------------------------------------------------------------------
Aufgabe:
Ansatz:
-------------------------------------------------------------------------------------------------
Aufgabe:
Ansatz:
-------------------------------------------------------------------------------------------------
Aufgabe:
Ansatz:
-------------------------------------------------------------------------------------------------
Aufgabe:
Ansatz:
-------------------------------------------------------------------------------------------------
Aufgabe:
Ansatz:
-------------------------------------------------------------------------------------------------
Aufgabe:
Ansatz:
-------------------------------------------------------------------------------------------------