Reworked data types, part II

This commit is contained in:
2025-12-21 18:31:16 +01:00
parent cb9eb8c3fe
commit e3c26ffa34
12 changed files with 85 additions and 68 deletions

View File

@@ -21,7 +21,7 @@ BCCanDriverTinyCan::BCCanDriverTinyCan( QObject* parent )
}
BCCanDriver::dState BCCanDriverTinyCan::loadDriver()
BCCanDriver::DriverState BCCanDriverTinyCan::loadDriver()
{
//qDebug() << "CanBusControl " << cbc::Version << '\n' << "based on BigXionFlasher (c) 2011-2013 by Thomas Koenig <info@bigxionflasher.org> - www.bigxionflasher.org";
@@ -31,8 +31,10 @@ BCCanDriver::dState BCCanDriverTinyCan::loadDriver()
if( ::LoadDriver( NULL ) < 0 )
throw std::runtime_error( "Driver Error: 'LoadDriver'" );
setState(BCCanDriver::DriverState::Loaded);
if( ::CanInitDriver( NULL ) < 0 )
throw std::runtime_error( "Driver Error: 'InitDriver'" );
throw std::runtime_error( "Driver Error: 'InitDriver'" );
if( ::CanDeviceOpen( 0, NULL ) < 0 )
throw std::runtime_error( "Driver Error: 'DeviceOpen'" );
@@ -41,6 +43,8 @@ BCCanDriver::dState BCCanDriverTinyCan::loadDriver()
::CanSetMode( 0, OP_CAN_START, CAN_CMD_ALL_CLEAR );
::CanGetDeviceStatus( 0, &status );
setState(BCCanDriver::DriverState::Initialized);
if( status.DrvStatus < DRV_STATUS_CAN_OPEN )
throw std::runtime_error( "Driver Error: could not open device." );
@@ -50,9 +54,9 @@ BCCanDriver::dState BCCanDriverTinyCan::loadDriver()
throw std::runtime_error( "Driver Error: CAN Status 'BusOff'" );
}
setState(BCCanDriver::sLoaded);
setState(BCCanDriver::DriverState::Ready);
return BCCanDriver::sLoaded;
return BCCanDriver::DriverState::Ready;
}
@@ -75,13 +79,13 @@ BCCanDriver::dState BCCanDriverTinyCan::loadDriver()
*/
BCCanDriver::dState BCCanDriverTinyCan::initDriver()
BCCanDriver::DriverState BCCanDriverTinyCan::initDriver()
{
qDebug() << "XXX BCCanDriverTinyCan::Driver Init: putting BCDevice::ID::Console in slave mode ... ";
// BCDevice::ID::Console already in slave mode. good!
if( readRawValue( BCDevice::ID::Console, BC::ID::Cons_Status_Slave ) )
return BCCanDriver::sReady;
return DriverState::Ready;
qDebug() << "BCCanDriverTinyCan::BCCanDriverTinyCan::XXX Driver Init: putting BCDevice::ID::Console in slave mode ... ";
@@ -92,7 +96,7 @@ BCCanDriver::dState BCCanDriverTinyCan::initDriver()
do
{
writeRawValue( BCDevice::ID::Console, BC::ID::Cons_Status_Slave, 1 );
isSlave = *readRawValue( BCDevice::ID::Console, BC::ID::Cons_Status_Slave );
isSlave = readRawValue( BCDevice::ID::Console, BC::ID::Cons_Status_Slave );
bc::delay_millis( 200 );
} while( retry-- && !isSlave );
@@ -100,20 +104,24 @@ BCCanDriver::dState BCCanDriverTinyCan::initDriver()
bc::delay_millis( 500 ); // give the Console some time to settle
//if( !isSlave )
emit statusHint( QString("putting BCDevice::ID::Console in slave mode ") + (isSlave ? "done" : "failed") );
// ist das jetzt irgendwie schlimm, wenn wir keine slave BCDevice::ID::Console haben
//return isSlave ? BCCanDriver::connected
return BCCanDriver::sReady;
return DriverState::Ready;
}
std::optional<bcdata_t> BCCanDriverTinyCan::readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const
bcdata_t BCCanDriverTinyCan::readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const
{
struct TCanMsg msg;
if( getState() != DriverState::Ready)
throw BCException( "readRawValue error: driver not loaded." );
TCanMsg msg;
uint32_t device = static_cast<uint32_t>(deviceID);
uint8_t reg = static_cast<uint8_t> (registerID);
@@ -137,7 +145,7 @@ std::optional<bcdata_t> BCCanDriverTinyCan::readRawValue( BCDevice::ID deviceID,
bc::delay_millis( cTIMEOUT_MS );
if( timeOuts == -1 )
throw std::runtime_error( "getValue error: could not send value" );
throw BCException( "readRawValue error: could not send value" );
retry:
@@ -178,6 +186,9 @@ retry:
void BCCanDriverTinyCan::writeRawValue( BCDevice::ID deviceID, BC::ID registerID, bcdata_t value ) const
{
if( getState() != DriverState::Ready)
throw BCException( "writeRawValue error: driver not loaded." );
qDebug() << " --- BCCanDriverTinyCan writeRawValue: " << value;
uint32_t device = static_cast<uint32_t>(deviceID);