From cb9eb8c3feb9a38dc09fb62d6ac1b018f2c4ef3c Mon Sep 17 00:00:00 2001 From: "PANIK\\chris" Date: Sun, 21 Dec 2025 14:40:38 +0100 Subject: [PATCH] Reworked data types. --- bc.h | 2 ++ bccandriver.cpp | 7 ------- bccandriver.h | 4 ++-- bccandrivertinycan.cpp | 33 ++++++++++----------------------- bccandrivertinycan.h | 4 ++-- bctransmitter.cpp | 39 +++++++++++++-------------------------- bctransmitter.h | 6 +++--- bcvalue.cpp | 7 ++++--- bcvalue.h | 12 ++++++------ 9 files changed, 42 insertions(+), 72 deletions(-) diff --git a/bc.h b/bc.h index 75068c8..adb0e6b 100644 --- a/bc.h +++ b/bc.h @@ -35,6 +35,8 @@ #include #include // Nötig für Q_GADGET/Q_ENUM Makros +using bcdata_t = uint8_t; + namespace bc { [[maybe_unused]] constexpr static double UNLIMITED_SPEED_VALUE = 70; // Km/h diff --git a/bccandriver.cpp b/bccandriver.cpp index 78c7718..cffbac7 100644 --- a/bccandriver.cpp +++ b/bccandriver.cpp @@ -78,11 +78,4 @@ void BCCanDriver::onStartDriver() } -/* -void BCCanDriver::onLoadItem( CBCItem& item ) -{ - item.setValue( 99.99 ); - emit itemLoaded( item ); -} -*/ diff --git a/bccandriver.h b/bccandriver.h index 7e3672e..37cd8f2 100644 --- a/bccandriver.h +++ b/bccandriver.h @@ -82,8 +82,8 @@ public: virtual BCCanDriver::dState loadDriver() = 0; virtual BCCanDriver::dState initDriver() = 0; - virtual uint getValue( BCDevice::ID dev, BC::ID reg ) const = 0; - virtual void setValue( BCDevice::ID dev, BC::ID reg, int value ) const = 0; + virtual std::optional readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const = 0; + virtual void writeRawValue( BCDevice::ID deviceID, BC::ID registerID, bcdata_t value ) const = 0; signals: diff --git a/bccandrivertinycan.cpp b/bccandrivertinycan.cpp index 48ee2b8..43bf86a 100644 --- a/bccandrivertinycan.cpp +++ b/bccandrivertinycan.cpp @@ -80,7 +80,7 @@ BCCanDriver::dState BCCanDriverTinyCan::initDriver() qDebug() << "XXX BCCanDriverTinyCan::Driver Init: putting BCDevice::ID::Console in slave mode ... "; // BCDevice::ID::Console already in slave mode. good! - if( getValue( BCDevice::ID::Console, BC::ID::Cons_Status_Slave ) ) + if( readRawValue( BCDevice::ID::Console, BC::ID::Cons_Status_Slave ) ) return BCCanDriver::sReady; qDebug() << "BCCanDriverTinyCan::BCCanDriverTinyCan::XXX Driver Init: putting BCDevice::ID::Console in slave mode ... "; @@ -88,11 +88,11 @@ BCCanDriver::dState BCCanDriverTinyCan::initDriver() unsigned int retry = _timeOuts; emit statusHint( "Driver Init: putting BCDevice::ID::Console in slave mode ... " ); - int isSlave = 0; + bcdata_t isSlave = 0; do { - setValue( BCDevice::ID::Console, BC::ID::Cons_Status_Slave, 1 ); - isSlave = getValue( BCDevice::ID::Console, BC::ID::Cons_Status_Slave ); + writeRawValue( BCDevice::ID::Console, BC::ID::Cons_Status_Slave, 1 ); + isSlave = *readRawValue( BCDevice::ID::Console, BC::ID::Cons_Status_Slave ); bc::delay_millis( 200 ); } while( retry-- && !isSlave ); @@ -109,8 +109,8 @@ BCCanDriver::dState BCCanDriverTinyCan::initDriver() } -//unsigned int BCCanDriverTinyCan::getValue( unsigned char receipient, unsigned char reg ) -uint BCCanDriverTinyCan::getValue(BCDevice::ID deviceID, BC::ID registerID ) const + +std::optional BCCanDriverTinyCan::readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const { struct TCanMsg msg; @@ -169,16 +169,16 @@ retry: if( !timeOuts ) throw std::runtime_error( "CAN --response errror" ); - return (unsigned int) msg.MsgData[3]; -//das ist mist! + return (bcdata_t) msg.MsgData[3]; + } // void BCCanDriverTinyCan::setValue( unsigned char receipient, unsigned char reg, unsigned char value ) -void BCCanDriverTinyCan::setValue(BCDevice::ID deviceID, BC::ID registerID, int value ) const +void BCCanDriverTinyCan::writeRawValue( BCDevice::ID deviceID, BC::ID registerID, bcdata_t value ) const { - qDebug() << "SaveItem( BCCanDriverTinyCan::CBCItem& item ): "; + qDebug() << " --- BCCanDriverTinyCan writeRawValue: " << value; uint32_t device = static_cast(deviceID); uint8_t reg = static_cast (registerID); @@ -204,16 +204,3 @@ void BCCanDriverTinyCan::setValue(BCDevice::ID deviceID, BC::ID registerID, int } - - - -void BCCanDriverTinyCan::awaitReceiveBuf( int timeout ) -{ - -} - -void BCCanDriverTinyCan::awaitSendBuf(int timeout ) -{ - -} - diff --git a/bccandrivertinycan.h b/bccandrivertinycan.h index 45d26dd..ddfa37d 100644 --- a/bccandrivertinycan.h +++ b/bccandrivertinycan.h @@ -15,8 +15,8 @@ public: BCCanDriver::dState loadDriver() override; BCCanDriver::dState initDriver() override; - uint getValue( BCDevice::ID dev, BC::ID reg ) const override; - void setValue( BCDevice::ID dev, BC::ID reg, int value ) const override; + std::optional readRawValue ( BCDevice::ID deviceID, BC::ID registerID ) const override; + void writeRawValue( BCDevice::ID deviceID, BC::ID registerID, bcdata_t value ) const override; QString getNodeName( unsigned char id ); diff --git a/bctransmitter.cpp b/bctransmitter.cpp index bb5e8c2..e5272d0 100644 --- a/bctransmitter.cpp +++ b/bctransmitter.cpp @@ -17,9 +17,9 @@ void BCTransmitter::onToggleConnectionState( bool connect ) if( BCCanDriver::sIdle == _canDriver.getState() ) _canDriver.onStartDriver(); - int hwVersion = _canDriver.getValue( BCDevice::ID::Console, BC::ID::Cons_Rev_Hw); + std::optional hwVersion = _canDriver.readRawValue( BCDevice::ID::Console, BC::ID::Cons_Rev_Hw); - if (hwVersion == 0) + if(!hwVersion.has_value()) { qDebug() << "Console not responding"; } @@ -94,41 +94,28 @@ void BCTransmitter::processValueOp( BC::OpID opID ) currentValue =_valueQueue.dequeue(); } // Mutex wird hier freigegeben! WICHTIG: Execute ohne Lock! - std::optional result; -/* if( opID == BC::OpID::ReadValue ) - result = executeRead(currentValue); + currentValue->readRawValue( *this ); else if( opID == BC::OpID::WriteValue ) - result = executeRead(currentValue); -*/ + currentValue->writeRawValue( *this ); + + //emit commandFinished(cmd.id, true); //emit commandFinished(0, true); } } -std::optional BCTransmitter::executeRead(const BCValue& value) +std::optional BCTransmitter::readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const { + return _canDriver.readRawValue( deviceID, registerID ); +} - return 0; - - std::optional result; - switch( value.deviceID ) - { - // hier lacht der blaue riesenhase! - case BCDevice::ID::Invalid: - case BCDevice::ID::Console: - case BCDevice::ID::Console_Master: - case BCDevice::ID::Battery: - case BCDevice::ID::Motor: - case BCDevice::ID::BIB: - case BCDevice::ID::Sensor: - break; - }; +void BCTransmitter::writeRawValue( BCDevice::ID deviceID, BC::ID registerID, bcdata_t value ) const +{ + _canDriver.writeRawValue( deviceID, registerID, value ); } -std::optional BCTransmitter::executeWrite(const BCValue& value) -{ -} + diff --git a/bctransmitter.h b/bctransmitter.h index a4cfbde..2f97116 100644 --- a/bctransmitter.h +++ b/bctransmitter.h @@ -4,7 +4,6 @@ #include #include #include -#include #include #include @@ -18,6 +17,8 @@ public: explicit BCTransmitter(QObject *parent = nullptr); + std::optional readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const override; + void writeRawValue(BCDevice::ID deviceID, BC::ID registerID, bcdata_t value ) const override; public slots: @@ -32,8 +33,7 @@ signals: private: - std::optional executeRead(const BCValue& value); - std::optional executeWrite(const BCValue& value); + using BCValueQueue = QQueue; diff --git a/bcvalue.cpp b/bcvalue.cpp index b021014..8f5bb7a 100644 --- a/bcvalue.cpp +++ b/bcvalue.cpp @@ -52,15 +52,16 @@ BCValue::BCValue() } */ -BCValue::BCValue(const BCValueType& valueType_, BCDevice::ID deviceID_, BC::ID targetID_) - : valueType{valueType_}, deviceID{deviceID_}, targetID{targetID_} +BCValue::BCValue(const BCValueType& valueType_, BCDevice::ID deviceID_, BC::ID registerID_) + : valueType{valueType_}, deviceID{deviceID_}, registerID{registerID_} { } void BCValue::readRawValue( const BCAbstractTransmitter& transmitter ) const { - transmitter.readValue( deviceID, targetID ); + std::optional result = transmitter.readRawValue( deviceID, registerID ); + } void BCValue::writeRawValue( const BCAbstractTransmitter& transmitter ) const diff --git a/bcvalue.h b/bcvalue.h index 6bc5fa5..0718a8e 100644 --- a/bcvalue.h +++ b/bcvalue.h @@ -53,7 +53,7 @@ - */ -using bcdata_t = uint32_t; + class BCAbstractTransmitter { @@ -61,8 +61,8 @@ class BCAbstractTransmitter public: // - virtual bcdata_t readValue( BCDevice::ID deviceID_, BC::ID targetID_ ) const { return 0;}; - ///virtual uint32_t readByte( BCDevice::ID deviceID_, BC::ID targetID_ ) const = 0; + virtual std::optional readRawValue( BCDevice::ID deviceID_, BC::ID registerID_ ) const = 0; + virtual void writeRawValue( BCDevice::ID deviceID_, BC::ID registerID_, uint8_t value_ ) const = 0; }; @@ -120,7 +120,7 @@ class BCValue public: //BCValue(); - BCValue( const BCValueType& valueType_, BCDevice::ID deviceID_, BC::ID targetID_ ); + BCValue( const BCValueType& valueType_, BCDevice::ID deviceID_, BC::ID registerID_ ); void readRawValue( const BCAbstractTransmitter& transmitter ) const; void writeRawValue( const BCAbstractTransmitter& transmitter ) const; @@ -128,7 +128,7 @@ public: BCValueTypeCRef valueType; BCDevice::ID deviceID{BCDevice::ID::Invalid}; - BC::ID targetID{BC::ID::Invalid}; + BC::ID registerID{BC::ID::Invalid}; int rowInModel{-1}; QString label; QVariant value; @@ -137,7 +137,7 @@ public: bool inSync{false}; bool readOnly{false}; - mutable double rawValue{}; + mutable std::optional rawValue;