Added dummy can driver.
This commit is contained in:
42
bcdriver.cpp
42
bcdriver.cpp
@@ -31,6 +31,7 @@
|
||||
|
||||
|
||||
#include <QDebug>
|
||||
#include <QRandomGenerator>
|
||||
|
||||
#include <bcdriver.h>
|
||||
|
||||
@@ -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<uint32_t>(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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
19
bcdriver.h
19
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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
|
||||
#include <QDebug>
|
||||
#include <QRandomGenerator>
|
||||
|
||||
|
||||
#include <bcdrivertinycan.h>
|
||||
#include <can_drv.h>
|
||||
@@ -143,9 +143,6 @@ BCDriver::DriverState BCDriverTinyCan::initDriver()
|
||||
uint32_t BCDriverTinyCan::readRawByte( uint32_t deviceID, uint8_t registerID ) const
|
||||
{
|
||||
|
||||
uint32_t myRandomByte = static_cast<uint32_t>(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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -35,10 +35,11 @@
|
||||
|
||||
#include <bctransmitter.h>
|
||||
|
||||
|
||||
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 )
|
||||
{
|
||||
|
||||
@@ -72,7 +72,8 @@ private:
|
||||
QMutex _mutex;
|
||||
std::atomic<bool> _isBusy{ false };
|
||||
|
||||
BCDriverTinyCan _canDriver;
|
||||
BCDriver* _canDriver{};
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user