diff --git a/bcdriver.cpp b/bcdriver.cpp index 5845e4d..a3a6bb0 100644 --- a/bcdriver.cpp +++ b/bcdriver.cpp @@ -31,6 +31,7 @@ #include +#include #include @@ -93,4 +94,45 @@ void BCDriver::onStartDriver() } +/// ----------------------------------------------------------------------------------- +/// ----------------------------------------------------------------------------------- + +/** + * @brief BCDriverDummy::BCDriverDummy + * @param parent + */ + +BCDriverDummy::BCDriverDummy( QObject* parent ) + : BCDriver(parent) +{ +} + +BCDriver::DriverState BCDriverDummy::loadDriver() +{ + return BCDriver::DriverState::Ready; +} +BCDriver::DriverState BCDriverDummy::initDriver() +{ + return DriverState::Ready; +} + +uint32_t BCDriverDummy::readRawByte( uint32_t deviceID, uint8_t registerID ) const +{ + //if( getState() != DriverState::Ready) + // throw BCException( "readRawValue error: driver not loaded." ); + + uint32_t myRandomByte = static_cast(QRandomGenerator::global()->bounded(256)); + return myRandomByte; + +} + +void BCDriverDummy::writeRawByte( uint32_t deviceID, uint8_t registerID, uint8_t value ) const +{ + if( getState() != DriverState::Ready) + throw BCException( "readRawValue error: driver not loaded." ); + + qDebug() << " --- BCDriverTinyCan writeRawValue: " << value; + return; +} + diff --git a/bcdriver.h b/bcdriver.h index 096b671..afd3f48 100644 --- a/bcdriver.h +++ b/bcdriver.h @@ -130,8 +130,23 @@ protected: DriverState _driverState{DriverState::NotPresent}; - static constexpr int cRetries = 5; - static constexpr int cTimeOuts = 20; +}; + + +class BCDriverDummy : public BCDriver +{ + Q_OBJECT + +public: + + + explicit BCDriverDummy( QObject* parent = nullptr ); + + DriverState loadDriver() override; + DriverState initDriver() override; + + uint32_t readRawByte( uint32_t deviceID, uint8_t registerID ) const override; + void writeRawByte( uint32_t deviceID, uint8_t registerID, uint8_t value ) const override; }; diff --git a/bcdrivertinycan.cpp b/bcdrivertinycan.cpp index d7095f1..277b722 100644 --- a/bcdrivertinycan.cpp +++ b/bcdrivertinycan.cpp @@ -31,7 +31,7 @@ #include -#include + #include #include @@ -143,9 +143,6 @@ BCDriver::DriverState BCDriverTinyCan::initDriver() uint32_t BCDriverTinyCan::readRawByte( uint32_t deviceID, uint8_t registerID ) const { - uint32_t myRandomByte = static_cast(QRandomGenerator::global()->bounded(256)); - return myRandomByte; - if( getState() != DriverState::Ready) throw BCException( "readRawValue error: driver not loaded." ); @@ -155,8 +152,6 @@ uint32_t BCDriverTinyCan::readRawByte( uint32_t deviceID, uint8_t registerID ) c TCanMsg msg; - - // msg verpacken msg.MsgFlags = 0L; msg.Id = deviceID; @@ -223,7 +218,6 @@ void BCDriverTinyCan::writeRawByte( uint32_t deviceID, uint8_t registerID ,uint8 qDebug() << " --- BCDriverTinyCan writeRawValue: " << value; return; - struct TCanMsg msg; int timeout_count = cTIMEOUT_COUNT; diff --git a/bcdrivertinycan.h b/bcdrivertinycan.h index cb86e08..49a19a0 100644 --- a/bcdrivertinycan.h +++ b/bcdrivertinycan.h @@ -64,6 +64,10 @@ protected: const char* CBCDLL_LIN = "libmhstcan.so"; const char* CBCDLL_WIN = "mhstcan.dll"; + + static constexpr int cRetries = 5; + static constexpr int cTimeOuts = 20; + static constexpr int cTIMEOUT_MS = 10; // 10ms static constexpr int cTIMEOUT_COUNT = 10; diff --git a/bctransmitter.cpp b/bctransmitter.cpp index 9c73d26..d5a501a 100644 --- a/bctransmitter.cpp +++ b/bctransmitter.cpp @@ -35,10 +35,11 @@ #include - BCTransmitter::BCTransmitter(QObject *parent) : QObject(parent), _isBusy(false) { + //_canDriver = new BCDriverTinyCan{this}; + _canDriver = new BCDriverDummy{this}; } @@ -46,11 +47,11 @@ void BCTransmitter::onToggleConnectionState( bool connect ) { if( connect ) { - if( _canDriver.getState() != BCDriver::DriverState::Ready ) - _canDriver.onStartDriver(); + if( _canDriver->getState() != BCDriver::DriverState::Ready ) + _canDriver->onStartDriver(); // fix! - uint32_t hwVersion = _canDriver.readRawByte( (uint32_t)BCDevice::ID::Console, (uint8_t)BC::ID::Cons_Rev_Hw); + uint32_t hwVersion = _canDriver->readRawByte( (uint32_t)BCDevice::ID::Console, (uint8_t)BC::ID::Cons_Rev_Hw); if(!hwVersion) { @@ -158,7 +159,7 @@ uint32_t BCTransmitter::readRawByte( uint32_t deviceID, uint8_t registerID ) c uint32_t result{}; try { - result = _canDriver.readRawByte( deviceID, registerID ); + result = _canDriver->readRawByte( deviceID, registerID ); } catch ( BCException& exception ) { @@ -172,7 +173,7 @@ void BCTransmitter::writeRawByte( uint32_t deviceID, uint8_t registerID , uint8_ { try { - _canDriver.writeRawByte( deviceID, registerID, value ); + _canDriver->writeRawByte( deviceID, registerID, value ); } catch ( BCException& exception ) { diff --git a/bctransmitter.h b/bctransmitter.h index b0e0f58..45c5eea 100644 --- a/bctransmitter.h +++ b/bctransmitter.h @@ -72,7 +72,8 @@ private: QMutex _mutex; std::atomic _isBusy{ false }; - BCDriverTinyCan _canDriver; + BCDriver* _canDriver{}; + };