Simplified value handling.

This commit is contained in:
2025-12-21 20:46:16 +01:00
parent e3c26ffa34
commit 59f6137bbe
5 changed files with 31 additions and 14 deletions

1
bc.h
View File

@@ -49,6 +49,7 @@ public:
BCException( const QString& what, const QString& param="" ); BCException( const QString& what, const QString& param="" );
BCException( const QString& what, int errCode ); BCException( const QString& what, int errCode );
}; };
namespace bc namespace bc

View File

@@ -29,12 +29,12 @@ BCCanDriver::DriverState BCCanDriverTinyCan::loadDriver()
struct ::TDeviceStatus status; struct ::TDeviceStatus status;
if( ::LoadDriver( NULL ) < 0 ) if( ::LoadDriver( NULL ) < 0 )
throw std::runtime_error( "Driver Error: 'LoadDriver'" ); throw BCException( "Driver Error: 'LoadDriver'" );
setState(BCCanDriver::DriverState::Loaded); setState(BCCanDriver::DriverState::Loaded);
if( ::CanInitDriver( NULL ) < 0 ) if( ::CanInitDriver( NULL ) < 0 )
throw std::runtime_error( "Driver Error: 'InitDriver'" ); throw BCException( "Driver Error: 'InitDriver'" );
if( ::CanDeviceOpen( 0, NULL ) < 0 ) if( ::CanDeviceOpen( 0, NULL ) < 0 )
throw std::runtime_error( "Driver Error: 'DeviceOpen'" ); throw std::runtime_error( "Driver Error: 'DeviceOpen'" );
@@ -46,12 +46,12 @@ BCCanDriver::DriverState BCCanDriverTinyCan::loadDriver()
setState(BCCanDriver::DriverState::Initialized); setState(BCCanDriver::DriverState::Initialized);
if( status.DrvStatus < DRV_STATUS_CAN_OPEN ) if( status.DrvStatus < DRV_STATUS_CAN_OPEN )
throw std::runtime_error( "Driver Error: could not open device." ); throw BCException( "Driver Error: could not open device." );
if( status.CanStatus == CAN_STATUS_BUS_OFF ) if( status.CanStatus == CAN_STATUS_BUS_OFF )
{ {
::CanSetMode( 0, OP_CAN_RESET, CAN_CMD_NONE ); ::CanSetMode( 0, OP_CAN_RESET, CAN_CMD_NONE );
throw std::runtime_error( "Driver Error: CAN Status 'BusOff'" ); throw BCException( "Driver Error: CAN Status 'BusOff'" );
} }
setState(BCCanDriver::DriverState::Ready); setState(BCCanDriver::DriverState::Ready);
@@ -74,7 +74,7 @@ BCCanDriver::DriverState BCCanDriverTinyCan::loadDriver()
::UnloadDriver(); ::UnloadDriver();
// re-throw // re-throw
throw std::runtime_error( except.what() ); throw BCException( except.what() );
} }
*/ */
@@ -156,14 +156,14 @@ retry:
bc::delay_millis( cTIMEOUT_MS ); bc::delay_millis( cTIMEOUT_MS );
if( timeOuts == -1 ) if( timeOuts == -1 )
throw std::runtime_error( "getValue error: no response from node" ); throw BCException( "getValue error: no response from node" );
// message empfangen // message empfangen
int err = ::CanReceive( 0, &msg, 1 ); int err = ::CanReceive( 0, &msg, 1 );
qDebug() << "HÄÄ ?" << err << "reg: "<< reg <<" timeOuts: " << timeOuts; qDebug() << "HÄÄ ?" << err << "reg: "<< reg <<" timeOuts: " << timeOuts;
if( err < 0 ) if( err < 0 )
//throw std::runtime_error( "getValue error: could not receive value" ); //throw BCException( "getValue error: could not receive value" );
qDebug( "getValue error: could not receive value" ); qDebug( "getValue error: could not receive value" );
qDebug() << "HÄÄ 2" <<msg.Id; qDebug() << "HÄÄ 2" <<msg.Id;
@@ -175,7 +175,7 @@ retry:
goto retry; goto retry;
if( !timeOuts ) if( !timeOuts )
throw std::runtime_error( "CAN --response errror" ); throw BCException( "CAN --response errror" );
return (bcdata_t) msg.MsgData[3]; return (bcdata_t) msg.MsgData[3];

View File

@@ -108,12 +108,28 @@ void BCTransmitter::processValueOp( BC::OpID opID )
bcdata_t BCTransmitter::readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const bcdata_t BCTransmitter::readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const
{ {
try
{
return _canDriver.readRawValue( deviceID, registerID ); return _canDriver.readRawValue( deviceID, registerID );
}
catch ( BCException& exception )
{
qDebug() << " -- OUCH: read exception: " << exception.what();
}
} }
void BCTransmitter::writeRawValue( BCDevice::ID deviceID, BC::ID registerID, bcdata_t value ) const void BCTransmitter::writeRawValue( BCDevice::ID deviceID, BC::ID registerID, bcdata_t value ) const
{ {
try
{
_canDriver.writeRawValue( deviceID, registerID, value ); _canDriver.writeRawValue( deviceID, registerID, value );
}
catch ( BCException& exception )
{
qDebug() << " -- OUCH: write exception: " << exception.what();
}
} }

View File

@@ -33,8 +33,6 @@ signals:
private: private:
using BCValueQueue = QQueue<const BCValue*>; using BCValueQueue = QQueue<const BCValue*>;
BCValueQueue _valueQueue; BCValueQueue _valueQueue;

View File

@@ -28,6 +28,7 @@
***************************************************************************/ ***************************************************************************/
#include <QMetaEnum> #include <QMetaEnum>
#include <QRandomGenerator>
#include <bcvalue.h> #include <bcvalue.h>
@@ -60,8 +61,9 @@ BCValue::BCValue(const BCValueType& valueType_, BCDevice::ID deviceID_, BC::ID r
void BCValue::readRawValue( const BCAbstractTransmitter& transmitter ) const void BCValue::readRawValue( const BCAbstractTransmitter& transmitter ) const
{ {
bcdata_t result = transmitter.readRawValue( deviceID, registerID ); //bcdata_t result = transmitter.readRawValue( deviceID, registerID );
bcdata_t myRandomByte = static_cast<quint8>(QRandomGenerator::global()->bounded(256));
value.fromValue<bcdata_t>( myRandomByte );
} }
void BCValue::writeRawValue( const BCAbstractTransmitter& transmitter ) const void BCValue::writeRawValue( const BCAbstractTransmitter& transmitter ) const