Backup.
This commit is contained in:
@@ -43,7 +43,7 @@ BCDriver::BCDriver(QObject* parent )
|
||||
|
||||
}
|
||||
|
||||
BCDriver::DriverState BCDriver::getState() const
|
||||
BCDriver::DriverState BCDriver::getDriverState() const
|
||||
{
|
||||
return _driverState;
|
||||
}
|
||||
@@ -64,6 +64,7 @@ void BCDriverDummy::onStartDriver()
|
||||
_driverState = DriverState::DeviceReady;
|
||||
emit driverStateChanged( DriverState::DeviceReady, "Driver Ready." );
|
||||
}
|
||||
// __Fix
|
||||
/*
|
||||
try
|
||||
{
|
||||
@@ -100,12 +101,11 @@ BCDriverDummy::BCDriverDummy( QObject* parent )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BCDriver::TransmitResult BCDriverDummy::readRawByte( uint32_t deviceID, uint8_t registerID ) const
|
||||
{
|
||||
Q_UNUSED(deviceID)
|
||||
Q_UNUSED(registerID)
|
||||
qDebug() << " --- DriverState: " << _driverState;
|
||||
qDebug() << " --- Dummy: readRawByte:DriverState: " << getDriverState();
|
||||
uint8_t myRandomByte = static_cast<uint8_t>(QRandomGenerator::global()->bounded(256));
|
||||
return myRandomByte;
|
||||
}
|
||||
|
||||
15
bcdriver.h
15
bcdriver.h
@@ -100,7 +100,7 @@ public:
|
||||
Loaded,
|
||||
Initialized,
|
||||
Opened, // bis hierher: dll vorhanden, Treiber geladen
|
||||
DeviceReady // hier: devices connectable
|
||||
DeviceReady // hier: devices connectable, wir können arbeiten.
|
||||
};
|
||||
Q_ENUM(DriverState)
|
||||
|
||||
@@ -112,10 +112,17 @@ public:
|
||||
explicit BCDriver( QObject* parent = nullptr );
|
||||
virtual ~BCDriver() = default;
|
||||
|
||||
DriverState getState() const;
|
||||
// Gibt den aktuelle Zustand des Treibers zurück. Der DriverState
|
||||
// muss auf DeviceReady stehen, um Werte lesen & schreiben zu können.
|
||||
// Dazu muss das Bionx-System eingeschaltet sein.
|
||||
|
||||
virtual TransmitResult readRawByte( uint32_t deviceID, uint8_t registerID ) const = 0;
|
||||
virtual TransmitResult writeRawByte(uint32_t deviceID, uint8_t registerID, uint8_t value ) const = 0;
|
||||
DriverState getDriverState() const;
|
||||
|
||||
// Abstrakte Methoden für das tatsächliche Lesen & Schreiben über den CAN-Bus. In der Implementierungs-
|
||||
// Klasse 'BCDriverTinyCan' werden die C-Funktionen der Treiber DLL gekapselt.
|
||||
|
||||
virtual TransmitResult readRawByte ( uint32_t deviceID, uint8_t registerID ) const = 0;
|
||||
virtual TransmitResult writeRawByte( uint32_t deviceID, uint8_t registerID, uint8_t value ) const = 0;
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
@@ -156,9 +156,6 @@ BCDriver::DriverState BCDriverTinyCan::connectDriver()
|
||||
{
|
||||
::CanDownDriver();
|
||||
::UnloadDriver();
|
||||
|
||||
// re-throw
|
||||
throw BCException( except.what() );
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -168,14 +165,11 @@ BCDriver::TransmitResult BCDriverTinyCan::readRawByte( uint32_t deviceID, uint8_
|
||||
{
|
||||
|
||||
//TransmitResult
|
||||
qDebug() << " --- DriverState: " << _driverState;
|
||||
qDebug() << " --- BCDriverTinyCan::readRawByte DriverState: " << getDriverState();
|
||||
|
||||
if( getDriverState() != DriverState::DeviceReady)
|
||||
return std::unexpected(QString("readRawValue error: driver not loaded." ) );
|
||||
|
||||
/*
|
||||
Nicht hier!
|
||||
if( getState() != DriverState::DeviceReady)
|
||||
//throw BCException( "readRawValue error: driver not loaded." );
|
||||
return std::nullopt;
|
||||
*/
|
||||
::TCanMsg msg;
|
||||
|
||||
// msg verpacken
|
||||
@@ -238,11 +232,9 @@ retry:
|
||||
BCDriver::TransmitResult BCDriverTinyCan::writeRawByte( uint32_t deviceID, uint8_t registerID ,uint8_t value ) const
|
||||
{
|
||||
|
||||
/*
|
||||
Nicht hier!
|
||||
if( getState() != DriverState::DeviceReady)
|
||||
throw BCException( "writeRawValue error: driver not loaded." );
|
||||
*/
|
||||
if( getDriverState() != DriverState::DeviceReady)
|
||||
return std::unexpected(QString("writeRawValue error: driver not loaded." ) );
|
||||
|
||||
qDebug() << " --- BCDriverTinyCan writeRawValue: " << value;
|
||||
|
||||
::TCanMsg msg;
|
||||
|
||||
@@ -47,7 +47,7 @@ void BCTransmitter::onToggleConnectionState( bool connect )
|
||||
{
|
||||
if( connect )
|
||||
{
|
||||
if( _canDriver->getState() != BCDriver::DriverState::DeviceReady )
|
||||
if( _canDriver->getDriverState() != BCDriver::DriverState::DeviceReady )
|
||||
_canDriver->onStartDriver();
|
||||
|
||||
// __fix!
|
||||
@@ -73,7 +73,7 @@ void BCTransmitter::enqueueValueOp(BCValue::OpID opID, const BCValue* value)
|
||||
_valueQueue.enqueue( value );
|
||||
|
||||
// wir wollen nicht den ganzen Value verschicken, erstrecht
|
||||
// wollen wir den Value in verschiedenen Threads gleichzeitig
|
||||
// wollen wir nicht den Value in verschiedenen Threads gleichzeitig
|
||||
// in die Hand nehmen, also hantieren wir nur mit den Inidizes.
|
||||
|
||||
// Trigger processing im Event-Loop des Worker Threads
|
||||
@@ -109,8 +109,6 @@ void BCTransmitter::processValueOp( BCValue::OpID opID )
|
||||
} // Mutex wird hier freigegeben! WICHTIG: Execute ohne Lock!
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
// Abkürzung
|
||||
const BCValue& val = *currentValue;
|
||||
// Value ist 'under construction'
|
||||
@@ -120,18 +118,11 @@ void BCTransmitter::processValueOp( BCValue::OpID opID )
|
||||
QString result = currentValue->readRawValueX( *this );
|
||||
emit valueUpdated( val.deviceID, val.indexRow, BCValue::State::InSync, result );
|
||||
}
|
||||
|
||||
else if( opID == BCValue::OpID::WriteValue )
|
||||
{
|
||||
currentValue->writeRawValueX( *this );
|
||||
}
|
||||
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
qDebug() << " --- OUCH!";
|
||||
}
|
||||
|
||||
// __fix
|
||||
bc::processEventsFor(50);
|
||||
|
||||
@@ -142,30 +133,15 @@ void BCTransmitter::processValueOp( BCValue::OpID opID )
|
||||
|
||||
uint8_t BCTransmitter::readByte( uint32_t deviceID, uint8_t registerID ) const
|
||||
{
|
||||
BCDriver::TransmitResult result;
|
||||
try
|
||||
{
|
||||
result = _canDriver->readRawByte( deviceID, registerID );
|
||||
}
|
||||
catch ( BCException& exception )
|
||||
{
|
||||
qDebug() << " -- OUCH: read exception: " << exception.what();
|
||||
}
|
||||
BCDriver::TransmitResult result = _canDriver->readRawByte( deviceID, registerID );
|
||||
|
||||
return result.value();
|
||||
|
||||
}
|
||||
|
||||
void BCTransmitter::writeByte( uint32_t deviceID, uint8_t registerID , uint8_t value ) const
|
||||
{
|
||||
try
|
||||
{
|
||||
_canDriver->writeRawByte( deviceID, registerID, value );
|
||||
}
|
||||
catch ( BCException& exception )
|
||||
{
|
||||
qDebug() << " -- OUCH: write exception: " << exception.what();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
#include <bcvalue.h>
|
||||
#include <bcdrivertinycan.h>
|
||||
|
||||
// template ... ?
|
||||
|
||||
class BCTransmitter : public QObject, public BCAbstractTransmitter
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -51,7 +51,7 @@ QString BCValue::readRawValueX( const BCAbstractTransmitter& transmitter ) const
|
||||
uint32_t devID = static_cast<uint32_t>(deviceID);
|
||||
uint8_t regID = static_cast<uint8_t> (registerID);
|
||||
|
||||
// wir sind hier im anderen thread! nicht einfach so reinschreiben
|
||||
// wir sind hier im anderen thread! nicht einfach so reinschreiben, nur lesen
|
||||
if( valueType->readValueFunc )
|
||||
{
|
||||
uint32_t result = valueType->readValueFunc( transmitter, devID, regID );
|
||||
|
||||
14
bcvalue.h
14
bcvalue.h
@@ -99,29 +99,17 @@ public:
|
||||
|
||||
QString readRawValueX( const BCAbstractTransmitter& transmitter ) const;
|
||||
void writeRawValueX( const BCAbstractTransmitter& transmitter ) const;
|
||||
// void reset()
|
||||
|
||||
// später vielleicht
|
||||
//protected:
|
||||
|
||||
mutable States state{BCValue::State::NoState};
|
||||
//const BCValueType& valueType;
|
||||
//BCValueTypeCRef valueType;
|
||||
const BCValueType* valueType{};
|
||||
BCDevice::ID deviceID{BCDevice::ID::Invalid};
|
||||
BC::ID registerID{BC::ID::Invalid};
|
||||
int indexRow{-1};
|
||||
QString label;
|
||||
// ??
|
||||
mutable QString visibleValue;
|
||||
QVariant defaultValue;
|
||||
//??
|
||||
bool inSync{false};
|
||||
bool readOnly{false};
|
||||
|
||||
//mutable std::optional<uint32_t> rawValue;
|
||||
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(BCValue::States)
|
||||
Q_DECLARE_METATYPE(const BCValue*)
|
||||
//Q_DECLARE_METATYPE(const BCValue&)
|
||||
|
||||
Reference in New Issue
Block a user