Cleanup datatypes.
This commit is contained in:
@@ -29,6 +29,7 @@ SOURCES += \
|
||||
bcdataitem.cpp \
|
||||
bcdatamodel.cpp \
|
||||
bcitemdelegate.cpp \
|
||||
bclegacy.cpp \
|
||||
bctransmitter.cpp \
|
||||
bcvdatamanager.cpp \
|
||||
lib/can_drv_win.c \
|
||||
|
||||
6
bc.h
6
bc.h
@@ -35,7 +35,7 @@
|
||||
#include <QDebug>
|
||||
#include <QObject> // Nötig für Q_GADGET/Q_ENUM Makros
|
||||
|
||||
using bcdata_t = uint8_t;
|
||||
//uint8_t;
|
||||
|
||||
|
||||
/**
|
||||
@@ -69,11 +69,11 @@ namespace bc
|
||||
|
||||
// misc
|
||||
//#define cbc::Version "CanBusControl 0.0.01 / 02.07.2022"
|
||||
[[maybe_unused]] constexpr static const char* Version = "CanBusControl 0.1.00 / 08.11.2022 © 2022 chris@sourceworx.org";
|
||||
[[maybe_unused]] constexpr static const char* Version = "BionxControl 0.1.00 / 08.11.2022 © 2022 chris@sourceworx.org";
|
||||
|
||||
[[maybe_unused]] constexpr static const char* OrgName = "source::worx";
|
||||
[[maybe_unused]] constexpr static const char* DomainName = "sourceworx.org";
|
||||
[[maybe_unused]] constexpr static const char* AppName = "CanBusControl";
|
||||
[[maybe_unused]] constexpr static const char* AppName = "BionxControl";
|
||||
|
||||
|
||||
// timer
|
||||
|
||||
@@ -77,8 +77,8 @@ public:
|
||||
virtual DriverState loadDriver() = 0;
|
||||
virtual DriverState initDriver() = 0;
|
||||
|
||||
virtual bcdata_t readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const = 0;
|
||||
virtual void writeRawValue( BCDevice::ID deviceID, BC::ID registerID, bcdata_t value ) const = 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;
|
||||
|
||||
signals:
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ BCCanDriver::DriverState BCCanDriverTinyCan::initDriver()
|
||||
unsigned int retry = _timeOuts;
|
||||
emit statusHint( "Driver Init: putting BCDevice::ID::Console in slave mode ... " );
|
||||
|
||||
bcdata_t isSlave = 0;
|
||||
uint32_t isSlave = 0;
|
||||
do
|
||||
{
|
||||
writeRawValue( BCDevice::ID::Console, BC::ID::Cons_Status_Slave, 1 );
|
||||
@@ -105,18 +105,17 @@ BCCanDriver::DriverState BCCanDriverTinyCan::initDriver()
|
||||
}
|
||||
|
||||
|
||||
|
||||
bcdata_t BCCanDriverTinyCan::readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const
|
||||
uint32_t BCCanDriverTinyCan::readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const
|
||||
{
|
||||
|
||||
if( getState() != DriverState::Ready)
|
||||
throw BCException( "readRawValue error: driver not loaded." );
|
||||
|
||||
//bcdata_t result = transmitter.readRawValue( deviceID, registerID );
|
||||
bcdata_t myRandomByte = static_cast<quint8>(QRandomGenerator::global()->bounded(256));
|
||||
//uint32_t result = transmitter.readRawValue( deviceID, registerID );
|
||||
uint32_t myRandomByte = static_cast<uint32_t>(QRandomGenerator::global()->bounded(256));
|
||||
return myRandomByte;
|
||||
|
||||
//value.fromValue<bcdata_t>( myRandomByte );
|
||||
//value.fromValue<uint32_t>( myRandomByte );
|
||||
|
||||
TCanMsg msg;
|
||||
|
||||
@@ -174,13 +173,13 @@ retry:
|
||||
if( !timeOuts )
|
||||
throw BCException( "CAN --response errror" );
|
||||
|
||||
return (bcdata_t) msg.MsgData[3];
|
||||
return (uint32_t) msg.MsgData[3];
|
||||
|
||||
}
|
||||
|
||||
|
||||
// void BCCanDriverTinyCan::setValue( unsigned char receipient, unsigned char reg, unsigned char value )
|
||||
void BCCanDriverTinyCan::writeRawValue( BCDevice::ID deviceID, BC::ID registerID, bcdata_t value ) const
|
||||
void BCCanDriverTinyCan::writeRawValue( BCDevice::ID deviceID, BC::ID registerID, uint8_t value ) const
|
||||
{
|
||||
|
||||
if( getState() != DriverState::Ready)
|
||||
|
||||
@@ -15,8 +15,8 @@ public:
|
||||
DriverState loadDriver() override;
|
||||
DriverState initDriver() override;
|
||||
|
||||
bcdata_t readRawValue ( BCDevice::ID deviceID, BC::ID registerID ) const override;
|
||||
void writeRawValue( BCDevice::ID deviceID, BC::ID registerID, bcdata_t value ) const 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;
|
||||
|
||||
QString getNodeName( unsigned char id );
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ BCDataItem::BCDataItem(const BCDataType& valueType_, BCDevice::ID deviceID_, BC:
|
||||
|
||||
void BCDataItem::readRawValue( const BCAbstractTransmitter& transmitter ) const
|
||||
{
|
||||
bcdata_t rawValue = transmitter.readRawValue( deviceID, registerID );
|
||||
uint32_t rawValue = transmitter.readRawValue( deviceID, registerID );
|
||||
}
|
||||
|
||||
void BCDataItem::writeRawValue( const BCAbstractTransmitter& transmitter ) const
|
||||
|
||||
@@ -61,7 +61,7 @@ class BCAbstractTransmitter
|
||||
public:
|
||||
|
||||
//
|
||||
virtual bcdata_t readRawValue( BCDevice::ID deviceID_, BC::ID registerID_ ) const = 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;
|
||||
};
|
||||
|
||||
@@ -136,7 +136,7 @@ public:
|
||||
bool inSync{false};
|
||||
bool readOnly{false};
|
||||
|
||||
mutable std::optional<bcdata_t> rawValue;
|
||||
mutable std::optional<uint32_t> rawValue;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ void BCTransmitter::onToggleConnectionState( bool connect )
|
||||
if( _canDriver.getState() != BCCanDriver::DriverState::Ready )
|
||||
_canDriver.onStartDriver();
|
||||
|
||||
bcdata_t hwVersion = _canDriver.readRawValue( BCDevice::ID::Console, BC::ID::Cons_Rev_Hw);
|
||||
uint32_t hwVersion = _canDriver.readRawValue( BCDevice::ID::Console, BC::ID::Cons_Rev_Hw);
|
||||
|
||||
if(!hwVersion)
|
||||
{
|
||||
@@ -106,7 +106,7 @@ void BCTransmitter::processValueOp( BC::OpID opID )
|
||||
}
|
||||
}
|
||||
|
||||
bcdata_t BCTransmitter::readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const
|
||||
uint32_t BCTransmitter::readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -119,7 +119,7 @@ bcdata_t BCTransmitter::readRawValue( BCDevice::ID deviceID, BC::ID registerID )
|
||||
|
||||
}
|
||||
|
||||
void BCTransmitter::writeRawValue( BCDevice::ID deviceID, BC::ID registerID, bcdata_t value ) const
|
||||
void BCTransmitter::writeRawValue( BCDevice::ID deviceID, BC::ID registerID, uint8_t value ) const
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -18,8 +18,8 @@ public:
|
||||
|
||||
explicit BCTransmitter(QObject *parent = nullptr);
|
||||
|
||||
bcdata_t readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const override;
|
||||
void writeRawValue(BCDevice::ID deviceID, BC::ID registerID, bcdata_t value ) const 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;
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
76
main.cpp
76
main.cpp
@@ -31,6 +31,8 @@
|
||||
#include <QApplication>
|
||||
#include <QMetaEnum>
|
||||
#include <QFile>
|
||||
#include <QLabel>
|
||||
#include <QProgressBar>
|
||||
|
||||
// main.cpp
|
||||
#include <QCoreApplication>
|
||||
@@ -41,25 +43,8 @@
|
||||
#include <bcdataitem.h>
|
||||
#include <bcvdatamanager.h>
|
||||
|
||||
/*
|
||||
#include <QMetaEnum>
|
||||
|
||||
void parseString(const QString &inputString) {
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<BCData::ID>();
|
||||
|
||||
bool ok = false;
|
||||
// keyToValue parst den String ("x1") und liefert den int-Wert
|
||||
int intVal = metaEnum.keyToValue(inputString.toLatin1().constData(), &ok);
|
||||
|
||||
if (ok) {
|
||||
BCData::ID id = static_cast<BCData::ID>(intVal);
|
||||
// Erfolg!
|
||||
} else {
|
||||
// Fehler: String existiert nicht im Enum
|
||||
qWarning() << "Unbekannter Enum String:" << inputString;
|
||||
}
|
||||
}
|
||||
*/
|
||||
#include <variant>
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
@@ -81,6 +66,59 @@ bool setApplicationStyleSheet( QAnyStringView path )
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
struct moo
|
||||
{
|
||||
QString moo_str {"irgendwas"};
|
||||
};
|
||||
|
||||
// Verschiedene Datentypen für die Sensoren
|
||||
struct Temperature : public moo{ float celsius; };
|
||||
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>;
|
||||
|
||||
|
||||
|
||||
struct UIUpdateVisitor
|
||||
{
|
||||
QLabel* tempLabel;
|
||||
QProgressBar* cpuBar;
|
||||
QLabel* statusLabel;
|
||||
|
||||
// Überladene operator() für jeden Typ in der Variant
|
||||
void operator()(const Temperature& t) const
|
||||
{
|
||||
tempLabel->setText(QString("Temp: %1°C").arg(t.celsius, 0, 'f', 1));
|
||||
tempLabel->setStyleSheet(t.celsius > 40 ? "color: red;" : "color: black;");
|
||||
}
|
||||
|
||||
void operator()(const CpuLoad& c) const
|
||||
{
|
||||
cpuBar->setValue(c.percentage);
|
||||
qDebug() << c.moo_str;
|
||||
}
|
||||
|
||||
void operator()(const Status& s) const
|
||||
{
|
||||
statusLabel->setText(QString::fromStdString(s.message));
|
||||
}
|
||||
};
|
||||
|
||||
void onNewDataReceived(const SensorReading& data)
|
||||
{
|
||||
QLabel* labelTemp = nullptr;
|
||||
QProgressBar* progressCpu = nullptr;
|
||||
QLabel* labelStatus = nullptr;
|
||||
|
||||
// Wir erstellen den Visitor mit Referenzen auf unsere UI-Elemente
|
||||
UIUpdateVisitor visitor { labelTemp, progressCpu, labelStatus };
|
||||
|
||||
// Die Magie: std::visit wählt zur Kompilierzeit die richtige Methode
|
||||
std::visit(visitor, data);
|
||||
}
|
||||
// 2. Datei öffnen und lesen
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user