Reworked value reading.

This commit is contained in:
2025-12-24 12:11:59 +01:00
parent 4eb3b494fe
commit e948c9103c
16 changed files with 163 additions and 263 deletions

View File

@@ -73,21 +73,24 @@ BCCanDriver::DriverState BCCanDriverTinyCan::loadDriver()
BCCanDriver::DriverState BCCanDriverTinyCan::initDriver()
{
uint32_t console = static_cast<uint32_t>(BCDevice::ID::Console);
uint8_t slaveFlag = static_cast<uint8_t>(BC::ID::Cons_Status_Slave);
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 ) )
if( readRawByte( console, slaveFlag ) )
return DriverState::Ready;
qDebug() << "BCCanDriverTinyCan::BCCanDriverTinyCan::XXX Driver Init: putting BCDevice::ID::Console in slave mode ... ";
unsigned int retry = _timeOuts;
unsigned int retry = cTimeOuts;
emit statusHint( "Driver Init: putting BCDevice::ID::Console in slave mode ... " );
uint32_t isSlave = 0;
do
{
writeRawValue( BCDevice::ID::Console, BC::ID::Cons_Status_Slave, 1 );
isSlave = readRawValue( BCDevice::ID::Console, BC::ID::Cons_Status_Slave );
writeRawByte( console, slaveFlag, 1 );
isSlave = readRawByte( console, slaveFlag );
bc::delay_millis( 200 );
} while( retry-- && !isSlave );
@@ -105,7 +108,7 @@ BCCanDriver::DriverState BCCanDriverTinyCan::initDriver()
}
uint32_t BCCanDriverTinyCan::readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const
uint32_t BCCanDriverTinyCan::readRawByte( uint32_t deviceID, uint8_t registerID ) const
{
if( getState() != DriverState::Ready)
@@ -119,22 +122,21 @@ uint32_t BCCanDriverTinyCan::readRawValue( BCDevice::ID deviceID, BC::ID registe
TCanMsg msg;
uint32_t device = static_cast<uint32_t>(deviceID);
uint8_t reg = static_cast<uint8_t> (registerID);
// msg verpacken
msg.MsgFlags = 0L;
msg.Id = device;
msg.Id = deviceID;
msg.MsgLen = 2;
msg.MsgData[0] = 0x00;
msg.MsgData[1] = reg;
msg.MsgData[1] = registerID;
// msg verschicken
::CanTransmit( 0, &msg, 1 );
int retries = _retries; // 5?
// _timeOuts (== 20) mal cTIMEOUT_MS (== 10 ms ) Versuche ...
int timeOuts = _timeOuts; // 20 ?
int retries = cRetries; // 5?
// cTimeOuts (== 20) mal cTIMEOUT_MS (== 10 ms ) Versuche ...
int timeOuts = cTimeOuts; // 20 ?
// ... warten bis der Sendepuffer leer ist
while( timeOuts-- && ::CanTransmitGetCount( 0 ) )
@@ -145,8 +147,8 @@ uint32_t BCCanDriverTinyCan::readRawValue( BCDevice::ID deviceID, BC::ID registe
retry:
// _timeOuts (== 20) mal cTIMEOUT_MS (== 10 ms ) Versuche ...
timeOuts = _timeOuts;
// cTimeOuts (== 20) mal cTIMEOUT_MS (== 10 ms ) Versuche ...
timeOuts = cTimeOuts;
// ... warten, bis der Empfangspuffer nicht mehr leer ist
while( timeOuts-- && !::CanReceiveGetCount( 0 ) )
bc::delay_millis( cTIMEOUT_MS );
@@ -156,7 +158,7 @@ retry:
// message empfangen
int err = ::CanReceive( 0, &msg, 1 );
qDebug() << "HÄÄ ?" << err << "reg: "<< reg <<" timeOuts: " << timeOuts;
qDebug() << "HÄÄ ?" << err << "reg: "<< registerID <<" timeOuts: " << timeOuts;
if( err < 0 )
//throw BCException( "getValue error: could not receive value" );
@@ -167,7 +169,7 @@ retry:
qDebug() << "HÄÄ 2" <<msg.MsgData[1];
//if( err > 0 )
if( --retries && ( msg.Id != BIB || msg.MsgLen != 4 || msg.MsgData[1] != reg ) )
if( --retries && ( msg.Id != BIB || msg.MsgLen != 4 || msg.MsgData[1] != registerID ) )
goto retry;
if( !timeOuts )
@@ -179,7 +181,7 @@ retry:
// void BCCanDriverTinyCan::setValue( unsigned char receipient, unsigned char reg, unsigned char value )
void BCCanDriverTinyCan::writeRawValue( BCDevice::ID deviceID, BC::ID registerID, uint8_t value ) const
void BCCanDriverTinyCan::writeRawByte( uint32_t deviceID, uint8_t registerID ,uint8_t value ) const
{
if( getState() != DriverState::Ready)
@@ -188,17 +190,15 @@ void BCCanDriverTinyCan::writeRawValue( BCDevice::ID deviceID, BC::ID registerID
qDebug() << " --- BCCanDriverTinyCan writeRawValue: " << value;
return;
uint32_t device = static_cast<uint32_t>(deviceID);
uint8_t reg = static_cast<uint8_t> (registerID);
struct TCanMsg msg;
int timeout_count = cTIMEOUT_COUNT;
msg.MsgFlags = 0L;
msg.Id = device;
msg.Id = deviceID;
msg.MsgLen = 4;
msg.MsgData[0] = 0x00;
msg.MsgData[1] = reg;
msg.MsgData[1] = registerID;
msg.MsgData[2] = 0x00;
msg.MsgData[3] = value;
@@ -208,7 +208,7 @@ void BCCanDriverTinyCan::writeRawValue( BCDevice::ID deviceID, BC::ID registerID
bc::delay_millis( cTIMEOUT_MS );
if( timeout_count == -1 )
emit statusHint( QString( "error: could not send value to %1" ).arg( device ) );
emit statusHint( QString( "error: could not send value to %1" ).arg( deviceID ) );
}