Backup.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
101
bcdataitem.h
101
bcdataitem.h
@@ -66,6 +66,8 @@ public:
|
||||
};
|
||||
|
||||
|
||||
class BCDataItem;
|
||||
|
||||
using optDouble = std::optional<double>;
|
||||
|
||||
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<BCDataType,ODO,Long,Fitz,Fatz>;
|
||||
|
||||
// really needed?
|
||||
using BCDataTypeCRef = std::optional<std::reference_wrapper<const BCDataType>>;
|
||||
//using BCDataTypeCRef = std::optional<std::reference_wrapper<const BCTypeVariant>>;
|
||||
|
||||
|
||||
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<BCDataItem>;
|
||||
|
||||
|
||||
|
||||
|
||||
// abbreviations:
|
||||
// SOC = State Of Charge
|
||||
@@ -168,7 +189,7 @@ constexpr auto to_u(E e) noexcept {
|
||||
}
|
||||
*/
|
||||
|
||||
using BCDataList = QVector<BCDataItem>;
|
||||
|
||||
|
||||
|
||||
#endif // BCDATAITEM_H
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
#include <QApplication>
|
||||
#include <QElapsedTimer>
|
||||
|
||||
#include <bcvdatamanager.h>
|
||||
#include <bcdatamanager.h>
|
||||
|
||||
|
||||
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<BCDataItem> BCDataManager::makeDataItem( BCDevice::ID deviceID, co
|
||||
std::optional<quint64> 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<BC::ID>(IDVal.value()) );
|
||||
|
||||
/*
|
||||
@@ -28,8 +28,8 @@
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef BCVDATAMANAGER_H
|
||||
#define BCVDATAMANAGER_H
|
||||
#ifndef BCDATAMANAGER_H
|
||||
#define BCDATAMANAGER_H
|
||||
|
||||
#include <QMap>
|
||||
#include <QXmlStreamReader>
|
||||
@@ -41,6 +41,7 @@
|
||||
|
||||
#include <bctransmitter.h>
|
||||
|
||||
|
||||
class BCDataManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -53,7 +54,7 @@ public:
|
||||
std::optional<BCDataModel*> getModel(BCDevice::ID deviceID );
|
||||
BCTransmitter* getTransmitter();
|
||||
|
||||
std::optional<BCDataItem> 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<BCDataItem> makeDataItem( BCDevice::ID deviceID, const BCDataParams& params );
|
||||
|
||||
using BCDeviceModels = QMap<BCDevice::ID, BCDataModel*>;
|
||||
using BCDataTypes = QMap<QString,BCDataType>;
|
||||
using BCDataTypes = QMap<QString,BCDataType*>;
|
||||
|
||||
QXmlStreamReader _xml;
|
||||
BCDataTypes _valueTypes;
|
||||
BCDataTypes _dataTypes;
|
||||
BCDeviceModels _valueModels;
|
||||
BCDevice::ID _currentDeviceID{BCDevice::ID::Invalid};
|
||||
QMetaEnum _bcDeviceEnum{QMetaEnum::fromType<BCDevice::ID>()};
|
||||
@@ -93,4 +104,4 @@ protected:
|
||||
|
||||
};
|
||||
|
||||
#endif // BCVDATAMANAGER_H
|
||||
#endif // BCDATAMANAGER_H
|
||||
@@ -38,7 +38,7 @@ QString BCItemDelegate::displayText(const QVariant& dataValue, const QLocale& lo
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << " --- Nö!";
|
||||
//qDebug() << " --- Nö!";
|
||||
}
|
||||
|
||||
// Fallback für normale Strings/Zahlen
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#include <QMainWindow>
|
||||
|
||||
#include <ui_bcmainwindow.h>
|
||||
#include <bcvdatamanager.h>
|
||||
#include <bcdatamanager.h>
|
||||
|
||||
|
||||
class AnimatedDelegate;
|
||||
|
||||
@@ -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);
|
||||
|
||||
BIN
doc/~$_ConsoleInformation.docx
Normal file
BIN
doc/~$_ConsoleInformation.docx
Normal file
Binary file not shown.
54
main.cpp
54
main.cpp
@@ -41,7 +41,7 @@
|
||||
|
||||
#include <bcmainwindow.h>
|
||||
#include <bcdataitem.h>
|
||||
#include <bcvdatamanager.h>
|
||||
#include <bcdatamanager.h>
|
||||
|
||||
#include <variant>
|
||||
#include <string>
|
||||
@@ -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<Temperature, CpuLoad, Status>;
|
||||
using SensorReadingPtr = std::variant<Temperature*, CpuLoad*, Status*>;
|
||||
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user