diff --git a/BionxControl.pro b/BionxControl.pro index d615417..8c4a8ff 100644 --- a/BionxControl.pro +++ b/BionxControl.pro @@ -26,12 +26,13 @@ windows SOURCES += \ bc.cpp \ - bcdataitem.cpp \ bcdatamanager.cpp \ bcdatamodel.cpp \ + bcdatavalue.cpp \ bcitemdelegate.cpp \ bclegacy.cpp \ bctransmitter.cpp \ + bcvaluetype.cpp \ lib/can_drv_win.c \ bccandriver.cpp \ bccandrivertinycan.cpp \ @@ -42,12 +43,13 @@ HEADERS += \ bc.h \ bccandriver.h \ bccandrivertinycan.h \ - bcdataitem.h \ bcdatamanager.h \ bcdatamodel.h \ + bcdatavalue.h \ bcitemdelegate.h \ bcmainwindow.h \ - bctransmitter.h + bctransmitter.h \ + bcvaluetype.h FORMS += \ bcmainwindow.ui diff --git a/bccandriver.h b/bccandriver.h index a19b4f8..a74b7cd 100644 --- a/bccandriver.h +++ b/bccandriver.h @@ -77,8 +77,8 @@ public: virtual DriverState loadDriver() = 0; virtual DriverState initDriver() = 0; - virtual uint32_t readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const = 0; - virtual void writeRawValue( BCDevice::ID deviceID, BC::ID registerID, uint8_t value ) const = 0; + virtual uint32_t readRawByte( uint32_t deviceID, uint8_t registerID ) const = 0; + virtual void writeRawByte( uint32_t deviceID, uint8_t registerID, uint8_t value ) const = 0; signals: @@ -97,9 +97,8 @@ protected: DriverState _driverState{DriverState::NotPresent}; - //?? - int _retries = 5; - int _timeOuts = 20; + static constexpr int cRetries = 5; + static constexpr int cTimeOuts = 20; }; diff --git a/bccandrivertinycan.cpp b/bccandrivertinycan.cpp index 382d032..002c598 100644 --- a/bccandrivertinycan.cpp +++ b/bccandrivertinycan.cpp @@ -73,21 +73,24 @@ BCCanDriver::DriverState BCCanDriverTinyCan::loadDriver() BCCanDriver::DriverState BCCanDriverTinyCan::initDriver() { + uint32_t console = static_cast(BCDevice::ID::Console); + uint8_t slaveFlag = static_cast(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(deviceID); - uint8_t reg = static_cast (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" < 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(deviceID); - uint8_t reg = static_cast (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 ) ); } diff --git a/bccandrivertinycan.h b/bccandrivertinycan.h index 04e86cb..3af404e 100644 --- a/bccandrivertinycan.h +++ b/bccandrivertinycan.h @@ -15,8 +15,8 @@ public: DriverState loadDriver() override; DriverState initDriver() override; - uint32_t readRawValue ( BCDevice::ID deviceID, BC::ID registerID ) const override; - void writeRawValue( BCDevice::ID deviceID, BC::ID registerID, uint8_t value ) const 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; QString getNodeName( unsigned char id ); diff --git a/bcdatamanager.cpp b/bcdatamanager.cpp index eec5b3d..e4763a7 100644 --- a/bcdatamanager.cpp +++ b/bcdatamanager.cpp @@ -38,7 +38,7 @@ #include #include - +#include using namespace Qt::StringLiterals; @@ -47,10 +47,9 @@ using namespace Qt::StringLiterals; BCDataManager::BCDataManager(QObject *parent) : QObject(parent) { - createValueTypes(); - //qRegisterMetaType("BCDataItem*"); - qRegisterMetaType(); + //qRegisterMetaType("BCDataValue*"); + qRegisterMetaType(); _transmitter.moveToThread(&_worker); @@ -77,52 +76,6 @@ BCDataManager::~BCDataManager() } -void BCDataManager::createValueTypes() -{ - /* - Invalid = 0x0, - "Text" - "Number" - "Float" - "Percent" - "KWh" - "Watt" - "Km" - "Kmh" - "Mm" - "Sec" - "SoC" - "Odo" - "Date" - - */ - //_dataTypes.insert( { BCDataType::TypeID::Invalid, "Invalid" } ); - - /* - _dataTypes.insert( "Invalid", { BCDataType::TypeID::Invalid, "Invalid" } ); - _dataTypes.insert( "Text", { BCDataType::TypeID::Text } ); - _dataTypes.insert( "Number", { BCDataType::TypeID::Number } ); - - _dataTypes.insert( "Byte", { BCDataType::TypeID::Byte } ); - _dataTypes.insert( "Word", { BCDataType::TypeID::Word } ); - _dataTypes.insert( "Quad", { BCDataType::TypeID::Quad } ); -*/ - - _dataTypes.insert( "Float", new Fitz{{ "", 1.5625F}} ); - _dataTypes.insert( "Percent",new Fatz{{ "%", 1.5625 }} ); - _dataTypes.insert( "KWh", new Fatz{{ "kwh", 1.5625 }} ); - _dataTypes.insert( "Watt", new Long{{ "w", 1.5625 }} ); - _dataTypes.insert( "Km", new ODO{{ "km", 1.5625 }} ); - _dataTypes.insert( "Kmh", new ODO{{ "km/h", 0.1 }} ); - _dataTypes.insert( "Mm", new ODO{{ "mm", 1.5625 }} ); - _dataTypes.insert( "Sec", new ODO{{ "s", 1.5625 }} ); - _dataTypes.insert( "SoC", new Long{{ "%", 1.5625 }} ); - _dataTypes.insert( "Odo", new Fitz{{ "km", 1.5625 }} ); - _dataTypes.insert( "Assist", new Fatz{{ "", 0 ,4 }} ); - _dataTypes.insert( "Assist", new Fatz{{ "%" }} ); - //_dataTypes.insert( "Date", { BCDataType::TypeID::Date } ); -} - void BCDataManager::onCommandFinished(int id, bool success) { qDebug() << "[Manager] Command" << id << "finished. Success:" << success; @@ -146,9 +99,9 @@ void BCDataManager::onSyncFromDevice() BCDataModel* model = _valueModels[_currentDeviceID]; BCDataList& currentList = model->getValueList(); - //BCDataItem& value = currentList[4]; + //BCDataValue& value = currentList[4]; - for( const BCDataItem& value : currentList ) + for( const BCDataValue& value : currentList ) { qDebug() << " --- value: " << value.label; @@ -183,7 +136,7 @@ BCTransmitter* BCDataManager::getTransmitter() return &_transmitter; }; -void BCDataManager::loadBikeData() +void BCDataManager::loadXmlBikeData() { auto printAttrs = [](const QXmlStreamReader& xml) { @@ -234,7 +187,7 @@ void BCDataManager::loadBikeData() _currentDeviceID = BCDevice::ID( deviceID.value() ); BCDataList parsedValues; - loadDeviceData( parsedValues ); + loadXmlBikeDeviceData( parsedValues ); if( parsedValues.count() ) { BCDataModel* valueModel = new BCDataModel( this ); @@ -263,7 +216,7 @@ void BCDataManager::loadBikeData() } -void BCDataManager::loadDeviceData( BCDataList& parsedValues ) +void BCDataManager::loadXmlBikeDeviceData( BCDataList& parsedValues ) { auto printAttrs = [](const QXmlStreamReader& xml) { @@ -296,10 +249,10 @@ void BCDataManager::loadDeviceData( BCDataList& parsedValues ) }; // __fix! können ungültige werte erzeugt werden ? - //BCDataItem newValue = BCData::makeDataItem( _currentDeviceID, params ); + //BCDataValue newValue = BCData::makeDataValue( _currentDeviceID, params ); //if(newValue) // parsedValues.push_back( newValue ); - std::optional newValue = makeDataItem( _currentDeviceID, params ); + std::optional newValue = makeDataValue( _currentDeviceID, params ); if(newValue) parsedValues.push_back( *newValue ); } @@ -309,7 +262,7 @@ void BCDataManager::loadDeviceData( BCDataList& parsedValues ) } } -std::optional BCDataManager::makeDataItem( BCDevice::ID deviceID, const BCDataParams& params ) +std::optional BCDataManager::makeDataValue( BCDevice::ID deviceID, const BCDataParams& params ) { /* @@ -327,6 +280,39 @@ std::optional BCDataManager::makeDataItem( BCDevice::ID deviceID, co static QMetaEnum s_bcValueEnum{QMetaEnum::fromType()}; + static BCValueTypeMap s_bcDataTypes + { + { "Float", new BCValueTypeWord( "", 1.5625F) }, + { "Percent",new BCValueTypeWord( "%", 1.5625 ) }, + { "KWh", new BCValueTypeWord( "kwh", 1.5625 ) }, + { "Watt", new BCValueTypeWord( "w", 1.5625 ) }, + { "Km", new BCValueTypeWord( "km", 1.5625 ) }, + { "Kmh", new BCValueTypeWord( "km/h", 0.1 ) }, + { "Mm", new BCValueTypeWord( "mm", 1.5625 ) }, + { "Sec", new BCValueTypeWord( "s", 1.5625 ) }, + { "SoC", new BCValueTypeWord( "%", 1.5625 ) }, + { "Odo", new BCValueTypeWord( "km", 1.5625 ) }, + { "Assist", new BCValueTypeWord( "", 0 ,4 ) }, + { "Assist", new BCValueTypeWord( "%" ) }, + }; + + + /* + _dataTypes.insert( "Float", new Fitz{{ "", 1.5625F}} ); + _dataTypes.insert( "Percent",new Fatz{{ "%", 1.5625 }} ); + _dataTypes.insert( "KWh", new Fatz{{ "kwh", 1.5625 }} ); + _dataTypes.insert( "Watt", new Long{{ "w", 1.5625 }} ); + _dataTypes.insert( "Km", new BCValueTypeWord{{ "km", 1.5625 }} ); + _dataTypes.insert( "Kmh", new BCValueTypeWord{{ "km/h", 0.1 }} ); + _dataTypes.insert( "Mm", new BCValueTypeWord{{ "mm", 1.5625 }} ); + _dataTypes.insert( "Sec", new BCValueTypeWord{{ "s", 1.5625 }} ); + _dataTypes.insert( "SoC", new Long{{ "%", 1.5625 }} ); + _dataTypes.insert( "Odo", new Fitz{{ "km", 1.5625 }} ); + _dataTypes.insert( "Assist", new Fatz{{ "", 0 ,4 }} ); + _dataTypes.insert( "Assist", new Fatz{{ "%" }} ); + //_dataTypes.insert( "Date", { BCValueType::TypeID::Date } ); + */ + /* Wir brauchen: - einen gültige ID String um die enum ID herauszufinden. @@ -334,16 +320,16 @@ std::optional BCDataManager::makeDataItem( BCDevice::ID deviceID, co */ - std::optional newValue; + std::optional newValue; std::optional IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() ); if( IDVal.has_value() ) { - if( _dataTypes.contains( params.UnitType ) ) + if( s_bcDataTypes.contains( params.UnitType ) ) { - const BCDataType& valueType = *_dataTypes[params.UnitType]; - newValue = BCDataItem( valueType, deviceID, static_cast(IDVal.value()) ); + const BCValueType* valueType = s_bcDataTypes[params.UnitType]; + newValue = BCDataValue( valueType, deviceID, static_cast(IDVal.value()) ); /* setIfExists( params.Factor, newValue.factor ); diff --git a/bcdatamanager.h b/bcdatamanager.h index bd7fdce..8fd3f3d 100644 --- a/bcdatamanager.h +++ b/bcdatamanager.h @@ -58,15 +58,15 @@ public: public slots: - void loadBikeData(); + void loadXmlBikeData(); void saveBikeData(); void onSyncFromDevice(); signals: // Internes Signal, um Daten an den Worker Thread zu senden - void sendValueCommand( BC::OpID, const BCDataItem* cmd); - //void valuedTouched(const BCDataItem& cmd); + void sendValueCommand( BC::OpID, const BCDataValue* cmd); + //void valuedTouched(const BCDataValue& cmd); void valueTouched(int rowInModel ); private slots: @@ -85,16 +85,15 @@ protected: QString UnitType; }; - void createValueTypes(); - void loadDeviceData( BCDataList& parsedValues ); + void loadXmlBikeDeviceData( BCDataList& parsedValues ); - std::optional makeDataItem( BCDevice::ID deviceID, const BCDataParams& params ); + std::optional makeDataValue( BCDevice::ID deviceID, const BCDataParams& params ); using BCDeviceModels = QMap; - using BCDataTypes = QMap; + using BCValueTypeMap = QMap; QXmlStreamReader _xml; - BCDataTypes _dataTypes; + BCDeviceModels _valueModels; BCDevice::ID _currentDeviceID{BCDevice::ID::Invalid}; QMetaEnum _bcDeviceEnum{QMetaEnum::fromType()}; diff --git a/bcdatamodel.cpp b/bcdatamodel.cpp index 34af9e5..0d30745 100644 --- a/bcdatamodel.cpp +++ b/bcdatamodel.cpp @@ -35,7 +35,7 @@ BCDataModel::BCDataModel(QObject *parent) : QAbstractListModel(parent) {} -void BCDataModel::addValue(const BCDataItem& val) +void BCDataModel::addValue(const BCDataValue& val) { int row = _valueList.size(); beginInsertRows(QModelIndex(), row, row); @@ -68,11 +68,11 @@ QVariant BCDataModel::data(const QModelIndex& index, int role) const if (!index.isValid() || row >= _valueList.size()) return QVariant(); - BCDataItem& entry = const_cast(_valueList.at( row )); + BCDataValue& entry = const_cast(_valueList.at( row )); entry.rowInModel = row; if (role == Qt::DisplayRole || role == Qt::EditRole) - return entry.value; + return entry.visibleValue; return QVariant(); } @@ -91,13 +91,13 @@ bool BCDataModel::setData(const QModelIndex& index, const QVariant& value, int r { if (index.isValid() && role == Qt::EditRole) { - BCDataItem item = _valueList[index.row()]; + BCDataValue item = _valueList[index.row()]; // Wir erwarten hier nur den Value-Teil (vom Slider/Editor) // Checken ob Int oder Double if (value.canConvert()) { - item.value = value; + item.visibleValue = value.toString(); } _valueList[index.row()] = item; diff --git a/bcdatamodel.h b/bcdatamodel.h index 6faa45d..4b7c6c9 100644 --- a/bcdatamodel.h +++ b/bcdatamodel.h @@ -33,7 +33,7 @@ #include -#include +#include class BCDataModel : public QAbstractListModel @@ -44,7 +44,7 @@ public: explicit BCDataModel(QObject *parent = nullptr); - void addValue(const BCDataItem& val); + void addValue(const BCDataValue& val); void setValueList(const BCDataList& valueList); BCDataList& getValueList(); diff --git a/bcdatavalue.cpp b/bcdatavalue.cpp index 3899254..18ac5ec 100644 --- a/bcdatavalue.cpp +++ b/bcdatavalue.cpp @@ -29,52 +29,32 @@ #include - -#include - -BCDataType::BCDataType() -{ - -} - -BCDataType::BCDataType( QString unitLabel_, double factor_, optDouble min_, optDouble max_ ) - : unitLabel{unitLabel_}, factor{factor_}, min{min_}, max{max_} -{ - -} - -double BCDataType::readValue( const BCAbstractTransmitter& transmitter ) -{ - return 0; -} - -void BCDataType::writeValue( const BCAbstractTransmitter& transmitter ) -{ - -} +#include +#include ///------------------------------- -BCDataItem::BCDataItem(const BCDataType* valueType_, BCDevice::ID deviceID_, BC::ID registerID_) +BCDataValue::BCDataValue(const BCValueType* valueType_, BCDevice::ID deviceID_, BC::ID registerID_) : valueType{valueType_}, deviceID{deviceID_}, registerID{registerID_} { - value = "--"; + visibleValue = "--"; } -void BCDataItem::readRawValueX( const BCAbstractTransmitter& transmitter ) const +void BCDataValue::readRawValueX( const BCAbstractTransmitter& transmitter ) const { qDebug() << " --- READ X!"; - //uint32_t rawValue = transmitter.readRawValue( deviceID, registerID ); - //const BCDataType& xxx = valueType.value().get(); + uint32_t devID = static_cast(deviceID); + uint8_t regID = static_cast (registerID); + + visibleValue = valueType->createStringValue( transmitter, devID, regID ); - //uint32_t result = std::visit( myVisi, BCTypeVariant{valueType} ); } -void BCDataItem::writeRawValueX( const BCAbstractTransmitter& transmitter ) const +void BCDataValue::writeRawValueX( const BCAbstractTransmitter& transmitter ) const { - + qDebug() << " --- WRITE X!"; } diff --git a/bcdatavalue.h b/bcdatavalue.h index efcae78..1975d62 100644 --- a/bcdatavalue.h +++ b/bcdatavalue.h @@ -28,8 +28,8 @@ ***************************************************************************/ -#ifndef BCDATAITEM_H -#define BCDATAITEM_H +#ifndef BCDATAVALUE_H +#define BCDATAVALUE_H #include #include @@ -41,9 +41,9 @@ /* Werte haben verschiedene Längen (1,2 und 4 Byte) und werder auf unterschiedliche Art und Weise - ausgelesen und geschrieben (Siehe ODO). Sin können also Wert-Typen zugeordnet werden. Ein Werttyp + ausgelesen und geschrieben (Siehe BCValueTypeWord). Sin können also Wert-Typen zugeordnet werden. Ein Werttyp lässet über eine ID identifizieren, die mit der phyikalische Einheit des Wertes überschneiden kann, - aber nicht muss: : Km/h, kWh, ODO ... bilden eigene Typen, SoC, Assistence Level sind auch eigene Typen, + aber nicht muss: : Km/h, kWh, BCValueTypeWord ... bilden eigene Typen, SoC, Assistence Level sind auch eigene Typen, Teilen sich jedoch die Einheit '%'. Das ist natürlich annalog zu den ItemTypes: @@ -60,115 +60,46 @@ class BCAbstractTransmitter public: - // - virtual uint32_t readRawValue( BCDevice::ID deviceID_, BC::ID registerID_ ) const = 0; - virtual void writeRawValue( BCDevice::ID deviceID_, BC::ID registerID_, uint8_t value_ ) const = 0; + virtual uint32_t readRawByte( uint32_t deviceID, uint8_t registerID ) const = 0; + virtual void writeRawByte( uint32_t deviceID, uint8_t registerID , uint8_t value_ ) const = 0; }; -class BCDataItem; +class BCValueType; -using optDouble = std::optional; - -struct BCDataType -{ - - Q_GADGET - -public: - - BCDataType(); - BCDataType( QString unitLabel_, double factor_= 1.0, optDouble min_=std::nullopt, optDouble max_= std::nullopt ); - - QString unitLabel; - double factor; - optDouble min; - optDouble max; - - virtual double readValue( const BCAbstractTransmitter& transmitter ) = 0; - virtual void writeValue( const BCAbstractTransmitter& transmitter ) = 0; -}; - - - -struct BCDataTypeByte : public BCDataType -{ - /* - double readValue( const BCAbstractTransmitter& transmitter, const BCDA ) override - { - return 0; - } - - void writeValue( const BCAbstractTransmitter& transmitter ) override; - { - - } -*/ - -}; - -struct ODO : public BCDataType -{ - double readValue( const BCAbstractTransmitter& transmitter ) override - { - return 0; - } - - void writeValue( const BCAbstractTransmitter& transmitter ) override; - { - - } - -}; - -struct Long : public BCDataType -{}; - -struct Fitz : public BCDataType -{}; - -struct Fatz : public BCDataType -{}; - -using BCTypeVariant = std::variant; - -// really needed? -//using BCDataTypeCRef = std::optional>; - - -class BCDataItem +class BCDataValue { public: - BCDataItem( const BCDataType* valueType_, BCDevice::ID deviceID_, BC::ID registerID_ ); + BCDataValue( const BCValueType* valueType_, BCDevice::ID deviceID_, BC::ID registerID_ ); void readRawValueX( const BCAbstractTransmitter& transmitter ) const; void writeRawValueX( const BCAbstractTransmitter& transmitter ) const; // void reset() - //const BCDataType& valueType; - //BCDataTypeCRef valueType; - const BCDataType* valueType{}; - BCDevice::ID deviceID{BCDevice::ID::Invalid}; - BC::ID registerID{BC::ID::Invalid}; - int rowInModel{-1}; - QString label; - QVariant value; - QVariant defaultValue; + //const BCValueType& valueType; + //BCValueTypeCRef valueType; + const BCValueType* valueType{}; + BCDevice::ID deviceID{BCDevice::ID::Invalid}; + BC::ID registerID{BC::ID::Invalid}; + int rowInModel{-1}; + QString label; + mutable QString visibleValue; + QVariant defaultValue; - bool inSync{false}; - bool readOnly{false}; + bool inSync{false}; + bool readOnly{false}; - mutable std::optional rawValue; + //mutable std::optional rawValue; }; -Q_DECLARE_METATYPE(BCDataItem*) +Q_DECLARE_METATYPE(BCDataValue*) -using BCDataList = QVector; +using BCDataList = QVector; @@ -192,4 +123,4 @@ constexpr auto to_u(E e) noexcept { -#endif // BCDATAITEM_H +#endif // BCDATAVALUE_H diff --git a/bcitemdelegate.cpp b/bcitemdelegate.cpp index 1973013..3f0a5c3 100644 --- a/bcitemdelegate.cpp +++ b/bcitemdelegate.cpp @@ -12,7 +12,7 @@ #include #include "bcitemdelegate.h" -#include "bcdataitem.h" +#include "bcdatavalue.h" #include "qapplication.h" @@ -27,14 +27,14 @@ BCItemDelegate::BCItemDelegate(QListView *view) QString BCItemDelegate::displayText(const QVariant& dataValue, const QLocale& locale) const { // Wir prüfen, ob im Variant unser Struct steckt - if (dataValue.canConvert()) + if (dataValue.canConvert()) { - BCDataItem& bc = *dataValue.value(); + BCDataValue& bc = *dataValue.value(); qDebug() << " --- YES: " << bc.label; // Hier bauen wir den String zusammen, den man sieht, // wenn KEIN Editor offen ist. // Format: "Label: Wert Einheit" - return QString("%1: %2 %3").arg(bc.label, bc.value.toString(), "mmX"); + return QString("%1: %2 %3").arg(bc.label, bc.visibleValue, "mmX"); } else { @@ -49,10 +49,10 @@ QString BCItemDelegate::displayText(const QVariant& dataValue, const QLocale& lo QWidget *BCItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const { QVariant rawData = index.data(Qt::EditRole); - if (!rawData.canConvert()) + //if (!rawData.canConvert()) return QStyledItemDelegate::createEditor(parent, option, index); - - const BCDataItem& bc = *rawData.value(); +/* + const BCDataValue& bc = *rawData.value(); // Nur bei Integern den Slider-Editor bauen if (bc.value.typeId() == QMetaType::Int) @@ -89,25 +89,27 @@ QWidget *BCItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewIte }); return container; + } return QStyledItemDelegate::createEditor(parent, option, index); + */ } void BCItemDelegate::setEditorData(QWidget *editor, const QModelIndex& index) const { // Daten vom Model in den Editor laden - const BCDataItem& bc = *index.data(Qt::EditRole).value(); + const BCDataValue& bc = *index.data(Qt::EditRole).value(); QSlider *slider = editor->findChild("slider"); QLabel *lblUnit = editor->findChild("lblUnit"); if (slider && lblUnit) { bool olDriverState = slider->blockSignals(true); - slider->setValue(bc.value.toInt()); + slider->setValue(bc.visibleValue.toInt()); slider->blockSignals(olDriverState); - lblUnit->setText(QString("%1 %2").arg(bc.value.toInt()).arg( "mm3")); + lblUnit->setText(QString("%1 %2").arg(bc.visibleValue.toInt()).arg( "mm3")); } else { QStyledItemDelegate::setEditorData(editor, index); } diff --git a/bcmainwindow.cpp b/bcmainwindow.cpp index c467ad6..1c66b0f 100644 --- a/bcmainwindow.cpp +++ b/bcmainwindow.cpp @@ -40,7 +40,7 @@ BCMainWindow::BCMainWindow(QWidget *parent) _motorlButton->setDefaultAction( _actionMotor); - _valueManager.loadBikeData(); + _valueManager.loadXmlBikeData(); auto model = _valueManager.getModel( BCDevice::ID::Console ); if( model) _valueView->setModel( *model ); diff --git a/bctransmitter.cpp b/bctransmitter.cpp index 66e3ddc..bb58187 100644 --- a/bctransmitter.cpp +++ b/bctransmitter.cpp @@ -17,7 +17,8 @@ void BCTransmitter::onToggleConnectionState( bool connect ) if( _canDriver.getState() != BCCanDriver::DriverState::Ready ) _canDriver.onStartDriver(); - uint32_t hwVersion = _canDriver.readRawValue( BCDevice::ID::Console, BC::ID::Cons_Rev_Hw); + // fix! + uint32_t hwVersion = _canDriver.readRawByte( (uint32_t)BCDevice::ID::Console, (uint8_t)BC::ID::Cons_Rev_Hw); if(!hwVersion) { @@ -50,7 +51,7 @@ void BCTransmitter::onToggleConnectionState( bool connect ) } -void BCTransmitter::enqueueValueOp(BC::OpID opID, const BCDataItem* value) +void BCTransmitter::enqueueValueOp(BC::OpID opID, const BCDataValue* value) { QMutexLocker locker(&_mutex); _valueQueue.enqueue( value ); @@ -83,7 +84,7 @@ void BCTransmitter::processValueOp( BC::OpID opID ) while (true) { - const BCDataItem* currentValue{}; + const BCDataValue* currentValue{}; { QMutexLocker locker(&_mutex); if (_valueQueue.isEmpty()) @@ -106,11 +107,11 @@ void BCTransmitter::processValueOp( BC::OpID opID ) } } -uint32_t BCTransmitter::readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const +uint32_t BCTransmitter::readRawByte( uint32_t deviceID, uint8_t registerID ) const { try { - return _canDriver.readRawValue( deviceID, registerID ); + return _canDriver.readRawByte( deviceID, registerID ); } catch ( BCException& exception ) { @@ -119,11 +120,11 @@ uint32_t BCTransmitter::readRawValue( BCDevice::ID deviceID, BC::ID registerID ) } -void BCTransmitter::writeRawValue( BCDevice::ID deviceID, BC::ID registerID, uint8_t value ) const +void BCTransmitter::writeRawByte( uint32_t deviceID, uint8_t registerID , uint8_t value ) const { try { - _canDriver.writeRawValue( deviceID, registerID, value ); + _canDriver.writeRawByte( deviceID, registerID, value ); } catch ( BCException& exception ) { diff --git a/bctransmitter.h b/bctransmitter.h index 37aeec6..7424304 100644 --- a/bctransmitter.h +++ b/bctransmitter.h @@ -6,7 +6,7 @@ #include #include -#include +#include #include // template ... @@ -18,13 +18,13 @@ public: explicit BCTransmitter(QObject *parent = nullptr); - uint32_t readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const override; - void writeRawValue(BCDevice::ID deviceID, BC::ID registerID, uint8_t value ) const 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; public slots: void onToggleConnectionState( bool connect ); - void enqueueValueOp(BC::OpID opID, const BCDataItem* value ); + void enqueueValueOp(BC::OpID opID, const BCDataValue* value ); void processValueOp(BC::OpID opID); signals: @@ -34,7 +34,7 @@ signals: private: - using BCDataQueue = QQueue; + using BCDataQueue = QQueue; BCDataQueue _valueQueue; QMutex _mutex; diff --git a/main.cpp b/main.cpp index 32cccbf..3f81bad 100644 --- a/main.cpp +++ b/main.cpp @@ -40,7 +40,7 @@ #include #include -#include +#include #include #include @@ -149,9 +149,9 @@ int main(int argc, char *argv[]) mookoo myMookoo{"",1,1.0}; mookoo myMooko2{"",1}; - mookoo2 myMooko3{{"superfitze",1},8}; + mookoo2* myMooko3 = new mookoo2{{"superfitze",1},8}; - qDebug() << " --- haha: " << myMooko3.a << ": " << myMooko3.hidden; + qDebug() << " --- haha: " << myMooko3->a << ": " << myMooko3->hidden; BCMainWindow w; w.show(); diff --git a/resources/bikeinfo.xml b/resources/bikeinfo.xml index 2196263..202cade 100644 --- a/resources/bikeinfo.xml +++ b/resources/bikeinfo.xml @@ -40,10 +40,10 @@