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;
|
return _driverState;
|
||||||
}
|
}
|
||||||
@@ -64,6 +64,7 @@ void BCDriverDummy::onStartDriver()
|
|||||||
_driverState = DriverState::DeviceReady;
|
_driverState = DriverState::DeviceReady;
|
||||||
emit driverStateChanged( DriverState::DeviceReady, "Driver Ready." );
|
emit driverStateChanged( DriverState::DeviceReady, "Driver Ready." );
|
||||||
}
|
}
|
||||||
|
// __Fix
|
||||||
/*
|
/*
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -100,12 +101,11 @@ BCDriverDummy::BCDriverDummy( QObject* parent )
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BCDriver::TransmitResult BCDriverDummy::readRawByte( uint32_t deviceID, uint8_t registerID ) const
|
BCDriver::TransmitResult BCDriverDummy::readRawByte( uint32_t deviceID, uint8_t registerID ) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(deviceID)
|
Q_UNUSED(deviceID)
|
||||||
Q_UNUSED(registerID)
|
Q_UNUSED(registerID)
|
||||||
qDebug() << " --- DriverState: " << _driverState;
|
qDebug() << " --- Dummy: readRawByte:DriverState: " << getDriverState();
|
||||||
uint8_t myRandomByte = static_cast<uint8_t>(QRandomGenerator::global()->bounded(256));
|
uint8_t myRandomByte = static_cast<uint8_t>(QRandomGenerator::global()->bounded(256));
|
||||||
return myRandomByte;
|
return myRandomByte;
|
||||||
}
|
}
|
||||||
|
|||||||
11
bcdriver.h
11
bcdriver.h
@@ -100,7 +100,7 @@ public:
|
|||||||
Loaded,
|
Loaded,
|
||||||
Initialized,
|
Initialized,
|
||||||
Opened, // bis hierher: dll vorhanden, Treiber geladen
|
Opened, // bis hierher: dll vorhanden, Treiber geladen
|
||||||
DeviceReady // hier: devices connectable
|
DeviceReady // hier: devices connectable, wir können arbeiten.
|
||||||
};
|
};
|
||||||
Q_ENUM(DriverState)
|
Q_ENUM(DriverState)
|
||||||
|
|
||||||
@@ -112,7 +112,14 @@ public:
|
|||||||
explicit BCDriver( QObject* parent = nullptr );
|
explicit BCDriver( QObject* parent = nullptr );
|
||||||
virtual ~BCDriver() = default;
|
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.
|
||||||
|
|
||||||
|
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 readRawByte ( uint32_t deviceID, uint8_t registerID ) const = 0;
|
||||||
virtual TransmitResult writeRawByte( uint32_t deviceID, uint8_t registerID, uint8_t value ) const = 0;
|
virtual TransmitResult writeRawByte( uint32_t deviceID, uint8_t registerID, uint8_t value ) const = 0;
|
||||||
|
|||||||
@@ -156,9 +156,6 @@ BCDriver::DriverState BCDriverTinyCan::connectDriver()
|
|||||||
{
|
{
|
||||||
::CanDownDriver();
|
::CanDownDriver();
|
||||||
::UnloadDriver();
|
::UnloadDriver();
|
||||||
|
|
||||||
// re-throw
|
|
||||||
throw BCException( except.what() );
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -168,14 +165,11 @@ BCDriver::TransmitResult BCDriverTinyCan::readRawByte( uint32_t deviceID, uint8_
|
|||||||
{
|
{
|
||||||
|
|
||||||
//TransmitResult
|
//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;
|
::TCanMsg msg;
|
||||||
|
|
||||||
// msg verpacken
|
// msg verpacken
|
||||||
@@ -238,11 +232,9 @@ retry:
|
|||||||
BCDriver::TransmitResult BCDriverTinyCan::writeRawByte( uint32_t deviceID, uint8_t registerID ,uint8_t value ) const
|
BCDriver::TransmitResult BCDriverTinyCan::writeRawByte( uint32_t deviceID, uint8_t registerID ,uint8_t value ) const
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
if( getDriverState() != DriverState::DeviceReady)
|
||||||
Nicht hier!
|
return std::unexpected(QString("writeRawValue error: driver not loaded." ) );
|
||||||
if( getState() != DriverState::DeviceReady)
|
|
||||||
throw BCException( "writeRawValue error: driver not loaded." );
|
|
||||||
*/
|
|
||||||
qDebug() << " --- BCDriverTinyCan writeRawValue: " << value;
|
qDebug() << " --- BCDriverTinyCan writeRawValue: " << value;
|
||||||
|
|
||||||
::TCanMsg msg;
|
::TCanMsg msg;
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ void BCTransmitter::onToggleConnectionState( bool connect )
|
|||||||
{
|
{
|
||||||
if( connect )
|
if( connect )
|
||||||
{
|
{
|
||||||
if( _canDriver->getState() != BCDriver::DriverState::DeviceReady )
|
if( _canDriver->getDriverState() != BCDriver::DriverState::DeviceReady )
|
||||||
_canDriver->onStartDriver();
|
_canDriver->onStartDriver();
|
||||||
|
|
||||||
// __fix!
|
// __fix!
|
||||||
@@ -73,7 +73,7 @@ void BCTransmitter::enqueueValueOp(BCValue::OpID opID, const BCValue* value)
|
|||||||
_valueQueue.enqueue( value );
|
_valueQueue.enqueue( value );
|
||||||
|
|
||||||
// wir wollen nicht den ganzen Value verschicken, erstrecht
|
// 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.
|
// in die Hand nehmen, also hantieren wir nur mit den Inidizes.
|
||||||
|
|
||||||
// Trigger processing im Event-Loop des Worker Threads
|
// 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!
|
} // Mutex wird hier freigegeben! WICHTIG: Execute ohne Lock!
|
||||||
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Abkürzung
|
// Abkürzung
|
||||||
const BCValue& val = *currentValue;
|
const BCValue& val = *currentValue;
|
||||||
// Value ist 'under construction'
|
// Value ist 'under construction'
|
||||||
@@ -120,18 +118,11 @@ void BCTransmitter::processValueOp( BCValue::OpID opID )
|
|||||||
QString result = currentValue->readRawValueX( *this );
|
QString result = currentValue->readRawValueX( *this );
|
||||||
emit valueUpdated( val.deviceID, val.indexRow, BCValue::State::InSync, result );
|
emit valueUpdated( val.deviceID, val.indexRow, BCValue::State::InSync, result );
|
||||||
}
|
}
|
||||||
|
|
||||||
else if( opID == BCValue::OpID::WriteValue )
|
else if( opID == BCValue::OpID::WriteValue )
|
||||||
{
|
{
|
||||||
currentValue->writeRawValueX( *this );
|
currentValue->writeRawValueX( *this );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
qDebug() << " --- OUCH!";
|
|
||||||
}
|
|
||||||
|
|
||||||
// __fix
|
// __fix
|
||||||
bc::processEventsFor(50);
|
bc::processEventsFor(50);
|
||||||
|
|
||||||
@@ -142,31 +133,16 @@ void BCTransmitter::processValueOp( BCValue::OpID opID )
|
|||||||
|
|
||||||
uint8_t BCTransmitter::readByte( uint32_t deviceID, uint8_t registerID ) const
|
uint8_t BCTransmitter::readByte( uint32_t deviceID, uint8_t registerID ) const
|
||||||
{
|
{
|
||||||
BCDriver::TransmitResult result;
|
BCDriver::TransmitResult result = _canDriver->readRawByte( deviceID, registerID );
|
||||||
try
|
|
||||||
{
|
|
||||||
result = _canDriver->readRawByte( deviceID, registerID );
|
|
||||||
}
|
|
||||||
catch ( BCException& exception )
|
|
||||||
{
|
|
||||||
qDebug() << " -- OUCH: read exception: " << exception.what();
|
|
||||||
}
|
|
||||||
return result.value();
|
return result.value();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BCTransmitter::writeByte( uint32_t deviceID, uint8_t registerID , uint8_t value ) const
|
void BCTransmitter::writeByte( uint32_t deviceID, uint8_t registerID , uint8_t value ) const
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
_canDriver->writeRawByte( deviceID, registerID, value );
|
_canDriver->writeRawByte( deviceID, registerID, value );
|
||||||
}
|
}
|
||||||
catch ( BCException& exception )
|
|
||||||
{
|
|
||||||
qDebug() << " -- OUCH: write exception: " << exception.what();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
#include <bcvalue.h>
|
#include <bcvalue.h>
|
||||||
#include <bcdrivertinycan.h>
|
#include <bcdrivertinycan.h>
|
||||||
|
|
||||||
// template ... ?
|
|
||||||
class BCTransmitter : public QObject, public BCAbstractTransmitter
|
class BCTransmitter : public QObject, public BCAbstractTransmitter
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ QString BCValue::readRawValueX( const BCAbstractTransmitter& transmitter ) const
|
|||||||
uint32_t devID = static_cast<uint32_t>(deviceID);
|
uint32_t devID = static_cast<uint32_t>(deviceID);
|
||||||
uint8_t regID = static_cast<uint8_t> (registerID);
|
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 )
|
if( valueType->readValueFunc )
|
||||||
{
|
{
|
||||||
uint32_t result = valueType->readValueFunc( transmitter, devID, regID );
|
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;
|
QString readRawValueX( const BCAbstractTransmitter& transmitter ) const;
|
||||||
void writeRawValueX( const BCAbstractTransmitter& transmitter ) const;
|
void writeRawValueX( const BCAbstractTransmitter& transmitter ) const;
|
||||||
// void reset()
|
|
||||||
|
|
||||||
// später vielleicht
|
|
||||||
//protected:
|
|
||||||
|
|
||||||
mutable States state{BCValue::State::NoState};
|
mutable States state{BCValue::State::NoState};
|
||||||
//const BCValueType& valueType;
|
|
||||||
//BCValueTypeCRef valueType;
|
|
||||||
const BCValueType* valueType{};
|
const BCValueType* valueType{};
|
||||||
BCDevice::ID deviceID{BCDevice::ID::Invalid};
|
BCDevice::ID deviceID{BCDevice::ID::Invalid};
|
||||||
BC::ID registerID{BC::ID::Invalid};
|
BC::ID registerID{BC::ID::Invalid};
|
||||||
int indexRow{-1};
|
int indexRow{-1};
|
||||||
QString label;
|
QString label;
|
||||||
// ??
|
|
||||||
mutable QString visibleValue;
|
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_OPERATORS_FOR_FLAGS(BCValue::States)
|
||||||
Q_DECLARE_METATYPE(const BCValue*)
|
Q_DECLARE_METATYPE(const BCValue*)
|
||||||
//Q_DECLARE_METATYPE(const BCValue&)
|
//Q_DECLARE_METATYPE(const BCValue&)
|
||||||
|
|||||||
Reference in New Issue
Block a user