diff --git a/BionxControl.pro b/BionxControl.pro index 0dcdf40..d615417 100644 --- a/BionxControl.pro +++ b/BionxControl.pro @@ -27,11 +27,11 @@ windows SOURCES += \ bc.cpp \ bcdataitem.cpp \ + bcdatamanager.cpp \ bcdatamodel.cpp \ bcitemdelegate.cpp \ bclegacy.cpp \ bctransmitter.cpp \ - bcvdatamanager.cpp \ lib/can_drv_win.c \ bccandriver.cpp \ bccandrivertinycan.cpp \ @@ -43,11 +43,11 @@ HEADERS += \ bccandriver.h \ bccandrivertinycan.h \ bcdataitem.h \ + bcdatamanager.h \ bcdatamodel.h \ bcitemdelegate.h \ bcmainwindow.h \ - bctransmitter.h \ - bcvdatamanager.h + bctransmitter.h FORMS += \ bcmainwindow.ui diff --git a/bcdataitem.cpp b/bcdataitem.cpp index 9c8cebc..3899254 100644 --- a/bcdataitem.cpp +++ b/bcdataitem.cpp @@ -37,8 +37,18 @@ BCDataType::BCDataType() } -BCDataType::BCDataType( TypeID ID_, QString unitLabel_, optDouble factor_, optDouble min_, optDouble max_ ) - : ID{ID_}, unitLabel{unitLabel_}, factor{factor_}, min{min_}, max{max_} +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 ) { } @@ -46,19 +56,25 @@ BCDataType::BCDataType( TypeID ID_, QString unitLabel_, optDouble factor_, optDo ///------------------------------- -BCDataItem::BCDataItem(const BCDataType& valueType_, BCDevice::ID deviceID_, BC::ID registerID_) +BCDataItem::BCDataItem(const BCDataType* valueType_, BCDevice::ID deviceID_, BC::ID registerID_) : valueType{valueType_}, deviceID{deviceID_}, registerID{registerID_} { value = "--"; } -void BCDataItem::readRawValue( const BCAbstractTransmitter& transmitter ) const +void BCDataItem::readRawValueX( const BCAbstractTransmitter& transmitter ) const { - uint32_t rawValue = transmitter.readRawValue( deviceID, registerID ); + qDebug() << " --- READ X!"; + //uint32_t rawValue = transmitter.readRawValue( deviceID, registerID ); + + //const BCDataType& xxx = valueType.value().get(); + + //uint32_t result = std::visit( myVisi, BCTypeVariant{valueType} ); } -void BCDataItem::writeRawValue( const BCAbstractTransmitter& transmitter ) const +void BCDataItem::writeRawValueX( const BCAbstractTransmitter& transmitter ) const { } + diff --git a/bcdataitem.h b/bcdataitem.h index b4af777..efcae78 100644 --- a/bcdataitem.h +++ b/bcdataitem.h @@ -66,6 +66,8 @@ public: }; +class BCDataItem; + using optDouble = std::optional; struct BCDataType @@ -75,43 +77,63 @@ struct BCDataType public: - enum class TypeID : uint8_t - { - Invalid = 0x0, - Text, - Number, - Float, - Byte, - Word, - Quad, - Percent, - KWh, - Watt, - Km, - Kmh, - Mm, - Sec, - SoC, - Odo, - Assist, - AssistFac, - Date - }; - Q_ENUM(TypeID) - BCDataType(); - BCDataType( TypeID ID_, QString unitLabel_="", optDouble factor_=std::nullopt, optDouble min_=std::nullopt, optDouble max_= std::nullopt ); + BCDataType( QString unitLabel_, double factor_= 1.0, optDouble min_=std::nullopt, optDouble max_= std::nullopt ); - TypeID ID{TypeID::Invalid}; QString unitLabel; - optDouble factor; + 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>; +//using BCDataTypeCRef = std::optional>; class BCDataItem @@ -119,13 +141,15 @@ class BCDataItem public: - BCDataItem( const BCDataType& valueType_, BCDevice::ID deviceID_, BC::ID registerID_ ); + BCDataItem( const BCDataType* valueType_, BCDevice::ID deviceID_, BC::ID registerID_ ); - void readRawValue( const BCAbstractTransmitter& transmitter ) const; - void writeRawValue( const BCAbstractTransmitter& transmitter ) const; + void readRawValueX( const BCAbstractTransmitter& transmitter ) const; + void writeRawValueX( const BCAbstractTransmitter& transmitter ) const; // void reset() - BCDataTypeCRef valueType; + //const BCDataType& valueType; + //BCDataTypeCRef valueType; + const BCDataType* valueType{}; BCDevice::ID deviceID{BCDevice::ID::Invalid}; BC::ID registerID{BC::ID::Invalid}; int rowInModel{-1}; @@ -144,13 +168,10 @@ public: Q_DECLARE_METATYPE(BCDataItem*) -struct BCDataParams -{ - QString ID; - QString Label; - QString Default; - QString UnitType; -}; +using BCDataList = QVector; + + + // abbreviations: // SOC = State Of Charge @@ -168,7 +189,7 @@ constexpr auto to_u(E e) noexcept { } */ -using BCDataList = QVector; + #endif // BCDATAITEM_H diff --git a/bcvdatamanager.cpp b/bcdatamanager.cpp similarity index 86% rename from bcvdatamanager.cpp rename to bcdatamanager.cpp index 12990df..eec5b3d 100644 --- a/bcvdatamanager.cpp +++ b/bcdatamanager.cpp @@ -37,7 +37,7 @@ #include #include -#include +#include using namespace Qt::StringLiterals; @@ -96,29 +96,31 @@ void BCDataManager::createValueTypes() "Date" */ - //_valueTypes.insert( { BCDataType::TypeID::Invalid, "Invalid" } ); + //_dataTypes.insert( { BCDataType::TypeID::Invalid, "Invalid" } ); - _valueTypes.insert( "Invalid", { BCDataType::TypeID::Invalid, "Invalid" } ); - _valueTypes.insert( "Text", { BCDataType::TypeID::Text } ); - _valueTypes.insert( "Number", { BCDataType::TypeID::Number } ); + /* + _dataTypes.insert( "Invalid", { BCDataType::TypeID::Invalid, "Invalid" } ); + _dataTypes.insert( "Text", { BCDataType::TypeID::Text } ); + _dataTypes.insert( "Number", { BCDataType::TypeID::Number } ); - _valueTypes.insert( "Byte", { BCDataType::TypeID::Byte } ); - _valueTypes.insert( "Word", { BCDataType::TypeID::Word } ); - _valueTypes.insert( "Quad", { BCDataType::TypeID::Quad } ); + _dataTypes.insert( "Byte", { BCDataType::TypeID::Byte } ); + _dataTypes.insert( "Word", { BCDataType::TypeID::Word } ); + _dataTypes.insert( "Quad", { BCDataType::TypeID::Quad } ); +*/ - _valueTypes.insert( "Float", { BCDataType::TypeID::Float, "", 1.5625} ); - _valueTypes.insert( "Percent",{ BCDataType::TypeID::Percent, "%", 1.5625 } ); - _valueTypes.insert( "KWh", { BCDataType::TypeID::KWh, "kwh", 1.5625 } ); - _valueTypes.insert( "Watt", { BCDataType::TypeID::Watt, "w", 1.5625 } ); - _valueTypes.insert( "Km", { BCDataType::TypeID::Km, "km", 1.5625 } ); - _valueTypes.insert( "Kmh", { BCDataType::TypeID::Kmh, "km/h", 0.1 } ); - _valueTypes.insert( "Mm", { BCDataType::TypeID::Mm, "mm", 1.5625 } ); - _valueTypes.insert( "Sec", { BCDataType::TypeID::Sec, "s", 1.5625 } ); - _valueTypes.insert( "SoC", { BCDataType::TypeID::SoC, "%", 1.5625 } ); - _valueTypes.insert( "Odo", { BCDataType::TypeID::Odo, "km", 1.5625 } ); - _valueTypes.insert( "Assist", { BCDataType::TypeID::Assist, "", 0 ,4 } ); - _valueTypes.insert( "Assist", { BCDataType::TypeID::AssistFac, "%" } ); - _valueTypes.insert( "Date", { BCDataType::TypeID::Date } ); + _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) @@ -337,10 +339,10 @@ std::optional BCDataManager::makeDataItem( BCDevice::ID deviceID, co std::optional IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() ); if( IDVal.has_value() ) { - if( _valueTypes.contains( params.UnitType ) ) + if( _dataTypes.contains( params.UnitType ) ) { - const BCDataType& valueType = _valueTypes[params.UnitType]; + const BCDataType& valueType = *_dataTypes[params.UnitType]; newValue = BCDataItem( valueType, deviceID, static_cast(IDVal.value()) ); /* diff --git a/bcvdatamanager.h b/bcdatamanager.h similarity index 89% rename from bcvdatamanager.h rename to bcdatamanager.h index 9515996..bd7fdce 100644 --- a/bcvdatamanager.h +++ b/bcdatamanager.h @@ -28,8 +28,8 @@ ***************************************************************************/ -#ifndef BCVDATAMANAGER_H -#define BCVDATAMANAGER_H +#ifndef BCDATAMANAGER_H +#define BCDATAMANAGER_H #include #include @@ -41,6 +41,7 @@ #include + class BCDataManager : public QObject { Q_OBJECT @@ -53,7 +54,7 @@ public: std::optional getModel(BCDevice::ID deviceID ); BCTransmitter* getTransmitter(); - std::optional makeDataItem( BCDevice::ID deviceID, const BCDataParams& params ); + public slots: @@ -76,14 +77,24 @@ private slots: protected: + struct BCDataParams + { + QString ID; + QString Label; + QString Default; + QString UnitType; + }; + void createValueTypes(); void loadDeviceData( BCDataList& parsedValues ); + std::optional makeDataItem( BCDevice::ID deviceID, const BCDataParams& params ); + using BCDeviceModels = QMap; - using BCDataTypes = QMap; + using BCDataTypes = QMap; QXmlStreamReader _xml; - BCDataTypes _valueTypes; + BCDataTypes _dataTypes; BCDeviceModels _valueModels; BCDevice::ID _currentDeviceID{BCDevice::ID::Invalid}; QMetaEnum _bcDeviceEnum{QMetaEnum::fromType()}; @@ -93,4 +104,4 @@ protected: }; -#endif // BCVDATAMANAGER_H +#endif // BCDATAMANAGER_H diff --git a/bcitemdelegate.cpp b/bcitemdelegate.cpp index 05b45fb..1973013 100644 --- a/bcitemdelegate.cpp +++ b/bcitemdelegate.cpp @@ -38,7 +38,7 @@ QString BCItemDelegate::displayText(const QVariant& dataValue, const QLocale& lo } else { - qDebug() << " --- Nö!"; + //qDebug() << " --- Nö!"; } // Fallback für normale Strings/Zahlen diff --git a/bcmainwindow.h b/bcmainwindow.h index 33e2269..ff7f7c2 100644 --- a/bcmainwindow.h +++ b/bcmainwindow.h @@ -33,7 +33,7 @@ #include #include -#include +#include class AnimatedDelegate; diff --git a/bctransmitter.cpp b/bctransmitter.cpp index f0b06cf..66e3ddc 100644 --- a/bctransmitter.cpp +++ b/bctransmitter.cpp @@ -96,9 +96,9 @@ void BCTransmitter::processValueOp( BC::OpID opID ) if( opID == BC::OpID::ReadValue ) - currentValue->readRawValue( *this ); + currentValue->readRawValueX( *this ); else if( opID == BC::OpID::WriteValue ) - currentValue->writeRawValue( *this ); + currentValue->writeRawValueX( *this ); //emit commandFinished(cmd.id, true); diff --git a/doc/~$_ConsoleInformation.docx b/doc/~$_ConsoleInformation.docx new file mode 100644 index 0000000..fcd1843 Binary files /dev/null and b/doc/~$_ConsoleInformation.docx differ diff --git a/main.cpp b/main.cpp index c2fab7e..32cccbf 100644 --- a/main.cpp +++ b/main.cpp @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include @@ -78,7 +78,7 @@ struct CpuLoad : public moo{ int percentage; }; struct Status : public moo{ std::string message; }; // Die Variant als universeller Datencontainer -using SensorReading = std::variant; +using SensorReadingPtr = std::variant; @@ -89,25 +89,28 @@ struct UIUpdateVisitor QLabel* statusLabel; // Überladene operator() für jeden Typ in der Variant - void operator()(const Temperature& t) const + double operator()(Temperature* t) const { - tempLabel->setText(QString("Temp: %1°C").arg(t.celsius, 0, 'f', 1)); - tempLabel->setStyleSheet(t.celsius > 40 ? "color: red;" : "color: black;"); + //tempLabel->setText(QString("Temp: %1°C").arg(t.celsius, 0, 'f', 1)); + //tempLabel->setStyleSheet(t.celsius > 40 ? "color: red;" : "color: black;"); + return -1; } - void operator()(const CpuLoad& c) const + double operator()(CpuLoad* c) const { - cpuBar->setValue(c.percentage); - qDebug() << c.moo_str; + cpuBar->setValue(c->percentage); + qDebug() << c->moo_str; + return -42.0; } - void operator()(const Status& s) const + double operator()(const Status* s) const { - statusLabel->setText(QString::fromStdString(s.message)); + //statusLabel->setText(QString::fromStdString(s.message)); + return -1; } }; -void onNewDataReceived(const SensorReading& data) +void onNewDataReceived(const SensorReadingPtr& data) { QLabel* labelTemp = nullptr; QProgressBar* progressCpu = nullptr; @@ -117,14 +120,39 @@ void onNewDataReceived(const SensorReading& data) UIUpdateVisitor visitor { labelTemp, progressCpu, labelStatus }; // Die Magie: std::visit wählt zur Kompilierzeit die richtige Methode - std::visit(visitor, data); + double result = std::visit(visitor, data); + Q_UNUSED(result) + + + Temperature myTemp{}; + SensorReadingPtr xxx{&myTemp}; + double result2 = std::visit(visitor, SensorReadingPtr{&myTemp} ); } -// 2. Datei öffnen und lesen + +struct mookoo +{ + QString a="firz"; + int b=2; + double c=1.0; + QString hidden{"Fatz!"}; +}; + +struct mookoo2 : public mookoo +{ + int another; +}; + int main(int argc, char *argv[]) { QApplication app(argc, argv); setApplicationStyleSheet( ":/bionxcontrol.qss"_L1 ); + mookoo myMookoo{"",1,1.0}; + mookoo myMooko2{"",1}; + mookoo2 myMooko3{{"superfitze",1},8}; + + qDebug() << " --- haha: " << myMooko3.a << ": " << myMooko3.hidden; + BCMainWindow w; w.show();