Compiles again, without BCValueType.

This commit is contained in:
2026-01-03 02:50:28 +01:00
parent 6032abb35c
commit c5dc84179b
14 changed files with 353 additions and 568 deletions

View File

@@ -36,7 +36,6 @@ SOURCES += \
bctransmitter.cpp \
bcvalue.cpp \
bcvaluemodel.cpp \
bcvaluetype.cpp \
bcxmlloader.cpp \
lib/can_drv_win.c \
main.cpp \
@@ -52,7 +51,6 @@ HEADERS += \
bctransmitter.h \
bcvalue.h \
bcvaluemodel.h \
bcvaluetype.h \
bcxmlloader.h
FORMS += \

23
bc.h
View File

@@ -770,18 +770,19 @@ using namespace Qt::Literals::StringLiterals; // Für _L1
namespace BCTags
{
inline constexpr auto Device = "Device"_L1;
inline constexpr auto ID = "ID"_L1;
inline constexpr auto Label = "Label"_L1;
inline constexpr auto Default = "Default"_L1;
inline constexpr auto Current = "Current"_L1;
inline constexpr auto Enabled = "Enabled"_L1;
inline constexpr auto UnitType = "UnitType"_L1;
inline constexpr auto Min = "Min"_L1;
inline constexpr auto Max = "Max"_L1;
inline constexpr auto Factor = "Factor"_L1;
inline constexpr auto Device = "Device"_L1;
inline constexpr auto ID = "ID"_L1;
inline constexpr auto Label = "Label"_L1;
inline constexpr auto UnitLabel = "UnitLabel"_L1;
inline constexpr auto IsWord = "IsWord"_L1;
inline constexpr auto Default = "Default"_L1;
inline constexpr auto Current = "Current"_L1;
inline constexpr auto Enabled = "Enabled"_L1;
inline constexpr auto ValueType = "ValueType"_L1;
inline constexpr auto Min = "Min"_L1;
inline constexpr auto Max = "Max"_L1;
inline constexpr auto Factor = "Factor"_L1;
}
#endif // BC_H

View File

@@ -36,7 +36,7 @@
#include <QObject>
#include <expected>
#include <bcvalue.h>
#include <bcvaluetype.h>
/*
int32_t CanInitDriver(char *options);
void CanDownDriver(void);

View File

@@ -34,9 +34,11 @@
#define BCMAINWINDOW_H
#include <QMainWindow>
#include <QThread>
#include <ui_bcmainwindow.h>
#include <bcxmlloader.h>
#include <bctransmitter.h>
class BCDeviceView;

View File

@@ -30,7 +30,6 @@
***************************************************************************/
#include "bcvaluetype.h"
#include <QThread>
#include <QDebug>
@@ -121,7 +120,7 @@ void BCTransmitter::processValue()
// Value ist 'under construction'
//emit valueUpdated( value.deviceID, value.indexRow, BCValue::State::Locked );
const BCValueType& valueType = *value.valueType;
uint32_t devID = static_cast<uint32_t>(value.deviceID);
uint8_t regID = static_cast<uint8_t> (value.registerID);
@@ -139,6 +138,7 @@ void BCTransmitter::processValue()
else if( value.state.testFlag( BCValue::State::ReadMe ) )
{
/*
// wir sind hier im anderen thread! nicht einfach so reinschreiben, nur lesen
TransmitResult result = valueType.readValueFunc( *this, devID, regID );
if( result.has_value() )
@@ -150,6 +150,7 @@ void BCTransmitter::processValue()
{
newState = BCValue::State::Failed;
}
*/
}

View File

@@ -39,7 +39,6 @@
#include <atomic>
#include <bcvalue.h>
#include <bcvaluetype.h>
#include <bcdrivertinycan.h>
/**

View File

@@ -33,16 +33,121 @@
#include <QMetaEnum>
#include <bcvalue.h>
#include <bcvaluetype.h>
///-------------------------------
BCValue::BCValue(const BCValueType* valueType_, BCDevice::ID deviceID_, BC::ID registerID_)
: valueType{valueType_}, deviceID{deviceID_}, registerID{registerID_}
BCValue::BCValue( BCDevice::ID deviceID_, BC::ID registerID_)
: deviceID{deviceID_}, registerID{registerID_}
{
visibleValue = "--";
}
/***************************************************************************
BionxControl
Copyright © 2025 christoph holzheuer
christoph.holzheuer@gmail.com
Using:
mhs_can_drv.c
© 2011 - 2023 by MHS-Elektronik GmbH & Co. KG, Germany
Klaus Demlehner, klaus@mhs-elektronik.de
@see www.mhs-elektronik.de
Based on Bionx data type descriptions from:
BigXionFlasher USB V 0.2.4 rev. 97
© 2011-2013 by Thomas Koenig <info@bigxionflasher.org>
@see www.bigxionflasher.org
Bionx Bike Info
© 2018 Thorsten Schmidt (tschmidt@ts-soft.de)
@see www.ts-soft.de
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
@see https://github.com/bikemike/bionx-bikeinfo
***************************************************************************/
/// reader functions
TransmitResult readDummy( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
{
qDebug() << " --- NO: Read DUMMY: " << registerID;
return std::unexpected( QString("NO: Read DUMMY: %1 : %2 ").arg( deviceID, registerID ) );
}
TransmitResult readByteValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
{
qDebug() << " --- YES: Read ByteValue: " << registerID;
// Wir lesen nur ein Byte und gut.
return transmitter.readByte( deviceID, registerID );
}
TransmitResult readWordValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
{
qDebug() << " --- YES: Read WordValue: " << registerID;
//getValue(CONSOLE, CONSOLE_SN_PN_HI) << 8) + getValue(CONSOLE, CONSOLE_SN_PN_LO)),
uint32_t result{};
// hi byte Leseversuch.
TransmitResult value = transmitter.readByte( deviceID, registerID );
// Fehler? dann weg
if( !value)
return std::unexpected( value.error() );
// hi byte speichern
result = *value << 8;
// low byte, liegt im followup register: +1
value = transmitter.readByte( deviceID, registerID+1 );
if( !value)
return std::unexpected( value.error() );
result += *value;
return result;
}
TransmitResult readSpeedValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
{
return 0x0;
}
TransmitResult readODOValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
{
return 0x0;
}
TransmitResult readVoltValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
{
return 0x0;
}
TransmitResult readCircValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
{
return 0x0;
}
QString BCValue::formatValue( uint32_t value ) const
{
if( factor == 1 )
return QString::number( value );
double result = value * factor;
return QString::number(result, 'f', 2);
}
/// ----

113
bcvalue.h
View File

@@ -38,6 +38,7 @@
#include <QList>
#include <QVariant>
#include <expected>
#include <bc.h>
@@ -57,14 +58,30 @@
using OptDouble = std::optional<double>;
// Enthält den gelesenen Wert oder einen Fehlerstring
using TransmitResult = std::expected<uint32_t,QString>;
// Funktionsobject, um Werte aus der Transmitterschicht zu holden
//using ReadValueFunc = std::function<TransmitResult( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )>;
struct BCValueType;
class BCValue
{
public:
// Aus dem Type ergibt sich
// später der Editor
enum class ValueType : uint8_t
{
Plain,
Bool,
Float,
Mookoo
};
enum class State : uint8_t
{
NoState = 0x00,
@@ -78,16 +95,22 @@ public:
};
Q_DECLARE_FLAGS(States, State )
BCValue( const BCValueType* valueType_, BCDevice::ID deviceID_, BC::ID registerID_ );
mutable States state{BCValue::State::NoState};
const BCValueType* valueType{};
BCDevice::ID deviceID{BCDevice::ID::Invalid};
BC::ID registerID{BC::ID::Invalid};
int indexRow{-1};
QString label;
mutable QString visibleValue;
BCValue( BCDevice::ID deviceID_, BC::ID registerID_ );
QString formatValue( uint32_t value ) const;
mutable States state{BCValue::State::ReadOnly};
BCDevice::ID deviceID{BCDevice::ID::Invalid};
BC::ID registerID{BC::ID::Invalid};
ValueType valueType{ValueType::Plain};
int indexRow{-1};
QString label;
mutable QString visibleValue;
bool isWord{false};
QString unitLabel;
double factor{1};
OptDouble min;
OptDouble max;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(BCValue::States)
@@ -103,71 +126,25 @@ using BCValueList = QList<BCValuePtr>;
Q_DECLARE_METATYPE(const BCValuePtr)
/*
class BCValueList : public QList<BCValue>
Q_DECLARE_METATYPE(BCValueList)
/**
* @brief BCAbstractTransmitter ist das abstrakte Basisinterface für die eigentliche
* Datenübertragung auf Treiberebene.
*/
class BCAbstractTransmitter
{
public:
BCValueList()
{
qDebug() << "BC Construct: " << this;
}
BCValueList(const BCValueList& other)
: QList<BCValue>(other)
{
qDebug() << "BC: Copy from: " << &other << "to" << this;
}
BCValueList(BCValueList&& other) noexcept
: QList<BCValue>( other )
{
qDebug() << "Move from: " << &other << "to" << this;
}
// Copy Assignment Operator
BCValueList& operator=(const BCValueList& other)
{
qDebug() << "BC copy assignment: " << this;
QList<BCValue>::operator=( other );
return *this;
}
// Move Assignment Operator
BCValueList& operator=(BCValueList&& other) noexcept
{
qDebug() << "BC move assignment: " << this;
QList<BCValue>::operator=( other );
return *this;
}
~BCValueList()
{
qDebug() << "Destruct: " << this;
}
virtual TransmitResult readByte ( uint32_t deviceID, uint8_t registerID ) const = 0;
virtual TransmitResult writeByte( uint32_t deviceID, uint8_t registerID, uint8_t value_ ) const = 0;
};
*/
Q_DECLARE_METATYPE(BCValueList)
// abbreviations:
// SOC = State Of Charge
// LMD = Last Measured Discharge
// NIP = ?
/*
Needed ?
#include <type_traits>
template <typename E>
constexpr auto to_u(E e) noexcept {
return static_cast<std::underlying_type_t<E>>(e);
}
*/

View File

@@ -31,7 +31,7 @@
#include <bcvaluemodel.h>
#include <bcvaluetype.h>
/**
* @brief Konstruktor, ohne Besonderheiten
@@ -144,17 +144,17 @@ QVariant BCValueModel::data(const QModelIndex& index, int role) const
if (wrongRole || !index.isValid() || row >= _valueList.size() )
return QVariant();
BCValuePtr value = _valueList.at( row );
const BCValue& value = *(_valueList.at( row ).get());
if( col == 0 )
return value->label;
return value.label;
if( col == 1)
{
if( role == Qt::DisplayRole )
return QString("%1 %2").arg( value->visibleValue, value->valueType->unitLabel);
return QString("%1 %2").arg( value.visibleValue, value.unitLabel);
return value->visibleValue;
return value.visibleValue;
}
return QVariant();

View File

@@ -1,183 +0,0 @@
/***************************************************************************
BionxControl
Copyright © 2025 christoph holzheuer
christoph.holzheuer@gmail.com
Using:
mhs_can_drv.c
© 2011 - 2023 by MHS-Elektronik GmbH & Co. KG, Germany
Klaus Demlehner, klaus@mhs-elektronik.de
@see www.mhs-elektronik.de
Based on Bionx data type descriptions from:
BigXionFlasher USB V 0.2.4 rev. 97
© 2011-2013 by Thomas Koenig <info@bigxionflasher.org>
@see www.bigxionflasher.org
Bionx Bike Info
© 2018 Thorsten Schmidt (tschmidt@ts-soft.de)
@see www.ts-soft.de
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
@see https://github.com/bikemike/bionx-bikeinfo
***************************************************************************/
#include <bcvaluetype.h>
#include <bcvalue.h>
/// reader functions
TransmitResult readDummy( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
{
qDebug() << " --- NO: Read DUMMY: " << registerID;
return std::unexpected( QString("NO: Read DUMMY: %1 : %2 ").arg( deviceID, registerID ) );
}
TransmitResult readByteValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
{
qDebug() << " --- YES: Read ByteValue: " << registerID;
// Wir lesen nur ein Byte und gut.
return transmitter.readByte( deviceID, registerID );
}
TransmitResult readWordValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
{
qDebug() << " --- YES: Read WordValue: " << registerID;
//getValue(CONSOLE, CONSOLE_SN_PN_HI) << 8) + getValue(CONSOLE, CONSOLE_SN_PN_LO)),
uint32_t result{};
// hi byte Leseversuch.
TransmitResult value = transmitter.readByte( deviceID, registerID );
// Fehler? dann weg
if( !value)
return std::unexpected( value.error() );
// hi byte speichern
result = *value << 8;
// low byte, liegt im followup register: +1
value = transmitter.readByte( deviceID, registerID+1 );
if( !value)
return std::unexpected( value.error() );
result += *value;
return result;
}
TransmitResult readSpeedValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
{
return 0x0;
}
TransmitResult readODOValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
{
return 0x0;
}
TransmitResult readVoltValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
{
return 0x0;
}
TransmitResult readCircValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
{
return 0x0;
}
/**
* @brief BCValueType::BCValueType
*/
BCValueType::BCValueType()
{
}
BCValueType::BCValueType(QString unitKey_, QString unitLabel_, double factor_, optDouble min_, optDouble max_ )
: unitLabel{unitLabel_}, factor{factor_}, min{min_}, max{max_}
{
std::optional<ReadValueFunc> readFn = fetchReadValueFunction( unitKey_ );
readValueFunc = readFn.has_value() ? readFn.value() : readDummy;
}
QString BCValueType::formatValue( uint32_t value ) const
{
if( factor == 1 )
return QString::number( value );
double result = value * factor;
return QString::number(result, 'f', 2);
}
std::optional<ReadValueFunc> BCValueType::fetchReadValueFunction( const QString& unitTypeKey )
{
static QHash<QString,ReadValueFunc> s_bcReadValueFunctions
{
{ "Byte", readByteValue },
{ "Word", readWordValue },
{ "Assist", readByteValue },
{ "Kmh", readByteValue },
{ "Percent",readByteValue },
{ "KWh", readByteValue },
{ "Watt", readByteValue },
{ "Km", readByteValue },
{ "Mm", readByteValue },
{ "Sec", readByteValue },
{ "Degree", readByteValue },
{ "SoC", readByteValue },
{ "Odo", readByteValue },
};
if( !s_bcReadValueFunctions.contains( unitTypeKey ) )
return std::nullopt;
return s_bcReadValueFunctions[unitTypeKey];
}
std::optional<BCValueType*> BCValueType::fetchValueType( const QString& unitTypeKey )
{
static QHash<QString,BCValueType*> s_bcDataTypes
{
{ "Byte", new BCValueType( "Byte", "", 1.5625F) },
{ "Word", new BCValueType( "Word", "", 1.5625F) },
{ "Percent", new BCValueType( "Byte", "%", 1.5625 ) },
{ "AssInit", new BCValueType( "Byte", "", 1.0, 0 ,4 ) },
{ "Assist", new BCValueType( "Byte", "%", 0,400 ) }
/*
{ "KWh", new BCValueType( "kwh", 1.5625 ) },
{ "Watt", new BCValueType( "w", 1.5625 ) },
{ "Km", new BCValueType( "km", 1.5625 ) },
{ "Kmh", new BCValueType( "km/h", 0.1 ) },
{ "Mm", new BCValueType( "mm", 1.5625 ) },
{ "Sec", new BCValueType( "s", 1.5625 ) },
{ "Degree", new BCValueType( "°C", 1.0 ) },
{ "SoC", new BCValueType( "%", 1.5625 ) },
{ "Odo", new BCValueType( "km", 1.5625 ) },
{ "Assist", new BCValueType( "%" ) },
*/
};
if( !s_bcDataTypes.contains( unitTypeKey ) )
return std::nullopt;
return s_bcDataTypes[unitTypeKey];
}
/// ----

View File

@@ -1,102 +0,0 @@
/***************************************************************************
BionxControl
Copyright © 2025 christoph holzheuer
christoph.holzheuer@gmail.com
Using:
mhs_can_drv.c
© 2011 - 2023 by MHS-Elektronik GmbH & Co. KG, Germany
Klaus Demlehner, klaus@mhs-elektronik.de
@see www.mhs-elektronik.de
Based on Bionx data type descriptions from:
BigXionFlasher USB V 0.2.4 rev. 97
© 2011-2013 by Thomas Koenig <info@bigxionflasher.org>
@see www.bigxionflasher.org
Bionx Bike Info
© 2018 Thorsten Schmidt (tschmidt@ts-soft.de)
@see www.ts-soft.de
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
@see https://github.com/bikemike/bionx-bikeinfo
***************************************************************************/
#ifndef BCVALUETYPE_H
#define BCVALUETYPE_H
#include <QObject>
#include <QString>
#include <QList>
#include <QVariant>
#include <expected>
#include <bc.h>
class BCValue;
class BCAbstractTransmitter;
using optDouble = std::optional<double>;
// Enthält den gelesenen Wert oder einen Fehlerstring
using TransmitResult = std::expected<uint32_t,QString>;
// Funktionsobject, um Werte aus der Transmitterschicht zu holden
using ReadValueFunc = std::function<TransmitResult( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )>;
/**
* @brief BCAbstractTransmitter ist das abstrakte Basisinterface für die eigentliche
* Datenübertragung auf Treiberebene.
*/
class BCAbstractTransmitter
{
public:
virtual TransmitResult readByte ( uint32_t deviceID, uint8_t registerID ) const = 0;
virtual TransmitResult writeByte( uint32_t deviceID, uint8_t registerID, uint8_t value_ ) const = 0;
};
struct BCValueType
{
Q_GADGET
public:
BCValueType();
BCValueType( QString unitKey_, QString unitLabel_, double factor_= 1.0, optDouble min_=std::nullopt, optDouble max_= std::nullopt );
virtual QString formatValue( uint32_t value ) const;
QString unitLabel;
double factor;
optDouble min;
optDouble max;
ReadValueFunc readValueFunc;
//ReadValueFunc readValueFunc;
static std::optional<BCValueType*> fetchValueType( const QString& unitTypeKey );
static std::optional<ReadValueFunc> fetchReadValueFunction( const QString& unitTypeKey );
};
//using BCTypeVariant = std::variant<BCValueType,BCValueTypeWord,Long,Fitz,Fatz>;
// really needed?
//using BCValueTypeCRef = std::optional<std::reference_wrapper<const BCTypeVariant>>;
#endif // BCVALUETYPE_H

View File

@@ -32,28 +32,20 @@
#include <QFile>
#include <QFileDialog>
#include <QTableView>
#include <QPushButton>
#include <QMessageBox>
#include <QStatusBar>
#include <QApplication>
#include <QElapsedTimer>
#include <QMetaEnum>
#include <QHash>
#include <bcxmlloader.h>
#include <bcvaluetype.h>
using namespace Qt::StringLiterals;
BCXmlLoader::BCXmlLoader(QObject *parent)
: QObject(parent)
{
//qRegisterMetaType<BCValue*>("BCValue*");
//qRegisterMetaType<BCValue*>();
}
@@ -156,17 +148,22 @@ void BCXmlLoader::loadXmlBikeDeviceData(BCDevice::ID deviceID)
if( _xml.attributes().hasAttribute(BCTags::ID) )
{
//qDebug() << " --- found: " << _xml.name() << " : " << _xml.attributes().value(BCTags::ID);
QString id = _xml.attributes().value(BCTags::ID).toString();
// füllen des Parameter packs
BCDataParams params
BCValueParams params
{
.ID = id,
.Label = _xml.attributes().value(BCTags::Label).toString(),
.UnitType = _xml.attributes().value(BCTags::UnitType).toString(),
.ID = _xml.attributes().value(BCTags::ID).toString(),
.Label = _xml.attributes().value(BCTags::Label).toString(),
.UnitLabel = _xml.attributes().value(BCTags::UnitLabel).toString(),
.Factor = _xml.attributes().value(BCTags::Factor).toString(),
.Min = _xml.attributes().value(BCTags::Min).toString(),
.Max = _xml.attributes().value(BCTags::Max).toString(),
.IsWord = _xml.attributes().value(BCTags::IsWord).toString(),
.ValueType = _xml.attributes().value(BCTags::ValueType).toString(),
};
// nur gültige Werte sind vorhanden und können gespeichert werden
std::optional<BCValuePtr> newValue = makeDataValue( deviceID, params );
std::optional<BCValuePtr> newValue = makeValue( deviceID, params );
if(newValue)
{
// wir merken uns gleich den index in der Werteliste
@@ -185,11 +182,26 @@ void BCXmlLoader::loadXmlBikeDeviceData(BCDevice::ID deviceID)
}
std::optional<BCValuePtr> BCXmlLoader::makeDataValue( BCDevice::ID deviceID, const BCDataParams& params )
std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const BCValueParams& params )
{
/*
auto setIfExists = [&]( QStringView source, optDouble& target )
static QHash<QString,ReadValueFunc> s_bcReadValueFunctions
{
{ "Byte", readByteValue },
{ "Word", readWordValue },
{ "Assist", readByteValue }
};
if( !s_bcReadValueFunctions.contains( unitTypeKey ) )
return std::nullopt;
return s_bcReadValueFunctions[unitTypeKey];
*/
auto setIfExists = [&]( QStringView source, OptDouble& target )
{
if( !source.isEmpty() )
{
@@ -199,11 +211,9 @@ std::optional<BCValuePtr> BCXmlLoader::makeDataValue( BCDevice::ID deviceID, con
target = testVal;
}
};
*/
static QMetaEnum s_bcValueEnum{QMetaEnum::fromType<BC::ID>()};
/*
Wir brauchen:
- einen gültige ID String um die enum ID herauszufinden.
@@ -215,69 +225,39 @@ std::optional<BCValuePtr> BCXmlLoader::makeDataValue( BCDevice::ID deviceID, con
//std::optional<quint64> IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() );
bool ok;
int IDVal = s_bcValueEnum.keyToValue( params.ID.toLatin1().constData(), &ok );
qDebug() << " --- should create: " << params.Label << ": " << params.UnitType;
qDebug() << " --- should create: " << params.Label;
//if( IDVal.has_value() )
if( ok )
{
auto valueType = BCValueType::fetchValueType(params.UnitType);
if( valueType.has_value() )
{
BCValuePtr newValue = std::make_shared<BCValue>( *valueType, deviceID, static_cast<BC::ID>(IDVal) );
BCValuePtr newValue = std::make_shared<BCValue>( deviceID, static_cast<BC::ID>(IDVal) );
/*
setIfExists( params.Factor, newValue.factor );
setIfExists( params.Min, newValue.min );
setIfExists( params.Max, newValue.max );
*/
newValue->label = params.Label;
qDebug() << " --- created: " << params.Label;
//setIfExists( params.Factor, newValue->factor );
setIfExists( params.Min, newValue->min );
setIfExists( params.Max, newValue->max );
return std::optional<BCValuePtr>( newValue );
}
newValue->label = params.Label;
/*
QString ID;
QString Label;
QString UnitLabel;
QString Factor;
QString Min;
QString Max;
QString IsWord;
QString ValueType;
*/
qDebug() << " --- created: " << params.Label;
return std::optional<BCValuePtr>( newValue );
}
return std::nullopt;
}
// --- NEU: Speichern mit QXmlStreamWriter ---
void BCXmlLoader::saveBikeData()
{
/*
QString fileName = QFileDialog::getSaveFileName(this, "XML speichern", "", "XML Files (*.xml)");
if (fileName.isEmpty()) return;
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QMessageBox::warning(this, "Fehler", "Datei konnte nicht zum Schreiben geöffnet werden.");
return;
}
QXmlStreamWriter xml(&file);
xml.setAutoFormatting(true); // Sorgt für schöne Einrückungen (Tabs/Spaces)
xml.writeStartDocument();
xml.writeStartElement("devices");
// Daten vom Model holen
const QList<Device> &devices = m_model->getDevices();
for (const Device &d : devices) {
xml.writeStartElement("device");
xml.writeAttribute("name", d.name);
xml.writeAttribute("ip", d.ip);
xml.writeEndElement(); // </device>
}
xml.writeEndElement(); // </devices>
xml.writeEndDocument();
// Prüfen ob alles geschrieben wurde
if (file.error() != QFile::NoError) {
QMessageBox::critical(this, "Fehler", "Fehler beim Schreiben der Datei.");
} else {
statusBar()->showMessage("Datei erfolgreich gespeichert!", 3000);
}
*/
}

View File

@@ -33,15 +33,9 @@
#ifndef BCXMLLOADER_H
#define BCXMLLOADER_H
#include <QHash>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QMetaEnum>
#include <QThread>
#include <bcvaluemodel.h>
#include <bctransmitter.h>
#include <bcvalue.h>
class BCXmlLoader : public QObject
@@ -55,8 +49,7 @@ public:
public slots:
void loadXmlBikeData( const QString& fileName );
void saveBikeData();
void loadXmlBikeData( const QString& fileName );;
signals:
@@ -64,16 +57,21 @@ signals:
protected:
struct BCDataParams
struct BCValueParams
{
QString ID;
QString Label;
QString UnitType;
QString UnitLabel;
QString Factor;
QString Min;
QString Max;
QString IsWord;
QString ValueType;
};
void loadXmlBikeDeviceData( BCDevice::ID deviceID );
std::optional<BCValuePtr> makeDataValue( BCDevice::ID deviceID, const BCDataParams& params );
std::optional<BCValuePtr> makeValue( BCDevice::ID deviceID, const BCValueParams& params );
QXmlStreamReader _xml;

View File

@@ -1,45 +1,56 @@
<?xml version='1.0' encoding='UTF-8'?>
<!--
QString ID;
QString Label;
QString UnitLabel;
QString Factor;
QString Min;
QString Max;
QString IsWord;
QString ValueType;
-->
<Bike name='franken-wheeler'>
<Device Type="Console">
<Value ID='Cons_Rev_Hw' Label='Hardware Version' ReadOnly='true' UnitType='Byte' />
<Value ID='Cons_Rev_Sw' Label='Software Version' ReadOnly='true' UnitType='Byte' />
<Value ID='Cons_Sn_Product_Hi' Label='Product Number' ReadOnly='true' UnitType='Word'/>
<Value ID='Cons_Sn_Oem_Hi' Label='OEM Number' ReadOnly='true' UnitType='Word' />
<Value ID='Cons_Rev_Hw' Label='Hardware Version' />
<Value ID='Cons_Rev_Sw' Label='Software Version' />
<Value ID='Cons_Sn_Product_Hi' Label='Product Number' IsWord='true'/>
<Value ID='Cons_Sn_Oem_Hi' Label='OEM Number' IsWord='true' />
<Value ID='Cons_Assist_Initlevel' Label='Assistance Init Level' ReadOnly='false' UnitType='AssInit'/>
<Value ID='Cons_Assist_Level_1' Label='Assistance Level 1' ReadOnly='true' UnitType='Percent' Factor='1.5625'/>
<Value ID='Cons_Assist_Level_2' Label='Assistance Level 2' ReadOnly='true' UnitType='Percent' Factor='1.5625'/>
<Value ID='Cons_Assist_Level_3' Label='Assistance Level 3' ReadOnly='true' UnitType='Percent' Factor='1.5625'/>
<Value ID='Cons_Assist_Level_4' Label='Assistance Level 4' ReadOnly='true' UnitType='Percent' Factor='1.5625'/>
<Value ID='Cons_Assist_Initlevel' Label='Assistance Init Level' Min='0' Max='4'/>
<Value ID='Cons_Assist_Level_1' Label='Assistance Level 1' Factor='1.5625' UnitLabel='%' Min='0' Max='400' />
<Value ID='Cons_Assist_Level_2' Label='Assistance Level 2' Factor='1.5625' UnitLabel='%' Min='0' Max='400' />
<Value ID='Cons_Assist_Level_3' Label='Assistance Level 3' Factor='1.5625' UnitLabel='%' Min='0' Max='400' />
<Value ID='Cons_Assist_Level_4' Label='Assistance Level 4' Factor='1.5625' UnitLabel='%' Min='0' Max='400' />
<Value ID='Cons_Assist_Maxspeed_Flag' Label='Max Limit Enabled' ReadOnly='false' UnitType='Byte' />
<Value ID='Cons_Assist_Maxspeed_Hi' Label='Max Speed Limit' ReadOnly='false' UnitType='Kmh' Factor='0.1'/>
<Value ID='Cons_Assist_Maxspeed_Flag' Label='Max Limit Enabled' ValueType='bool' />
<Value ID='Cons_Assist_Maxspeed_Hi' Label='Max Speed Limit' UnitLabel='km/h' Factor='0.1' Min='0' Max='70'/>
<Value ID='Cons_Assist_Minspeed_Flag' Label='Min Limit Enabled' ReadOnly='true' UnitType='Byte' />
<Value ID='Cons_Assist_Minspeed' Label='Min Speed Limit' ReadOnly='true' UnitType='Kmh'/>
<Value ID='Cons_Assist_Minspeed_Flag' Label='Min Limit Enabled' ValueType='bool' />
<Value ID='Cons_Assist_Minspeed' Label='Min Speed Limit' UnitLabel='km/h' Min='0' Max='70' />
<Value ID='Cons_Throttle_Maxspeed_Flag' Label='Throttle Limit Enabled' ReadOnly='true' UnitType='Byte'/>
<Value ID='Cons_Throttle_Maxspeed_Hi' Label='Throttle Speed Limit' ReadOnly='true' UnitType='kmh' Factor='0.1'/>
<Value ID='Cons_Throttle_Maxspeed_Flag' Label='Throttle Limit Enabled' ValueType='bool'/>
<Value ID='Cons_Throttle_Maxspeed_Hi' Label='Throttle Speed Limit' UnitLabel='km/h' Factor='0.1' Min='0' Max='70' />
<Value ID='Cons_Geometry_Circ_Hi' Label='Wheel Circumference' ReadOnly='true' UnitType='mm' />
<Value ID='Cons_Assist_Mountain_Cap' Label='Mountain Cap' ReadOnly='true' UnitType='Percent' Factor='1.5625' />
<Value ID='Cons_Geometry_Circ_Hi' Label='Wheel Circumference' IsWord='true' UnitLabel='mm' Min='0' Max='2300' Factor='1.5625' />
<Value ID='Cons_Assist_Mountain_Cap' Label='Mountain Cap' UnitLabel='%' Factor='1.5625' />
</Device>
<Device Type="Motor">
<Value ID='Motor_Rev_Hw' Label='Hardware Version' ReadOnly='true' UnitType='Byte' />
<Value ID='Motor_Rev_Sw' Label='Software Version' ReadOnly='true' UnitType='Byte' />
<Value ID='Motor_Status_Temperature' Label='Motor Temperature' ReadOnly='true' UnitType='Degree'/>
<Value ID='Motor_Assist_Maxspeed' Label='Motor max. Speed' ReadOnly='true' UnitType='Kmh' />
<Value ID='Motor_Sn_Item_Hi' Label='Motor Part Number' ReadOnly='true' UnitType='Word'/>
<Value ID='Motor_Sn_Item_Hi' Label='Motor Serial Number' ReadOnly='true' UnitType='Word' />
<Value ID='Motor_Geometry_Circ_Hi' Label='Motor Gemetry' ReadOnly='true' UnitType='Mm' />
<Value ID='Motor_Rev_Hw' Label='Hardware Version' />
<Value ID='Motor_Rev_Sw' Label='Software Version' />
<Value ID='Motor_Sn_Item_Hi' Label='Motor Part Number' IsWord='true'/>
<Value ID='Motor_Sn_Item_Hi' Label='Motor Serial Number' IsWord='true' />
<Value ID='Motor_Status_Temperature' Label='Motor Temperature' UnitLabel='°C' />
<Value ID='Motor_Assist_Maxspeed' Label='Motor max. Speed' Reader='Kmh' />
<Value ID='Motor_Geometry_Circ_Hi' Label='Wheel Circumference' IsWord='true' UnitLabel='mm' Min='0' Max='2300' Factor='1.5625' />
</Device>
<Device Type="Battery">
<Value ID='Battery_Rev_Hw' Label='Hardware Version' ReadOnly='true' UnitType='Byte' />
<Value ID='Battery_Rev_Sw' Label='Software Version' ReadOnly='true' UnitType='Byte' />
<Value ID='Battery_Rev_Hw' Label='Hardware Version' />
<Value ID='Battery_Rev_Sw' Label='Software Version' />
</Device>
</Bike>
@@ -57,106 +68,104 @@
<Value ID='Cons_Stat_Dist_Hi' Label='' ReadOnly='true' UnitType='mm' Factor='0.1' />
<Value ID='Cons_Stat_Dist_Lo' Label='' ReadOnly='true' UnitType='mm'/>
<Value ID='Cons_Stat_Avgspeed_Hi' Label='' ReadOnly='true' UnitType='mm' Factor='0.1' />
<Value ID='Cons_Stat_Avgspeed_Lo' Label='' ReadOnly='true' UnitType='mm'/>
<Value ID='Cons_Stat_Dist_Hi' Label='' Reader='mm' Factor='0.1' />
<Value ID='Cons_Stat_Dist_Lo' Label='' Reader='mm'/>
<Value ID='Cons_Stat_Avgspeed_Hi' Label='' Reader='mm' Factor='0.1' />
<Value ID='Cons_Stat_Avgspeed_Lo' Label='' Reader='mm'/>
<Value ID='Cons_Stat_Odo_Hihi' Label='' ReadOnly='true' Factor='0.1' />
<Value ID='Cons_Stat_Odo_Hilo' Label='' ReadOnly='true' />
<Value ID='Cons_Stat_Odomoter_Lohi' Label='' ReadOnly='true' />
<Value ID='Cons_Stat_Odo_Lolo' Label='' ReadOnly='true' />
<Value ID='Cons_Stat_Odo_Hihi' Label='' Factor='0.1' />
<Value ID='Cons_Stat_Odo_Hilo' Label='' />
<Value ID='Cons_Stat_Odomoter_Lohi' Label='' />
<Value ID='Cons_Stat_Odo_Lolo' Label='' />
<Value ID='Cons_Preference_Nip_Hihi' Label='' ReadOnly='true' />
<Value ID='Cons_Preference_Nip_Hilo' Label='' ReadOnly='true' />
<Value ID='Cons_Preference_Nip_Lohi' Label='' ReadOnly='true' />
<Value ID='Cons_Preference_Nip_Lolo' Label='' ReadOnly='true' />
<Value ID='Cons_Throttle_Calibrated' Label='' ReadOnly='true' />
<Value ID='Cons_Stat_Chrono_Second' Label='' ReadOnly='true' />
<Value ID='Cons_Stat_Chrono_Minute' Label='' ReadOnly='true' />
<Value ID='Cons_Stat_Chrono_Hour' Label='' ReadOnly='true' />
<Value ID='Cons_Preference_Lcd_Contrast' Label='' ReadOnly='true' />
<Value ID='Cons_Sn_Location' Label='' ReadOnly='true' />
<Value ID='Cons_Sn_Year' Label='' ReadOnly='true' />
<Value ID='Cons_Sn_Month' Label='' ReadOnly='true' />
<Value ID='Cons_Sn_Day' Label='' ReadOnly='true' />
<Value ID='Cons_Preference_Nip_Hihi' Label='' />
<Value ID='Cons_Preference_Nip_Hilo' Label='' />
<Value ID='Cons_Preference_Nip_Lohi' Label='' />
<Value ID='Cons_Preference_Nip_Lolo' Label='' />
<Value ID='Cons_Throttle_Calibrated' Label='' />
<Value ID='Cons_Stat_Chrono_Second' Label='' />
<Value ID='Cons_Stat_Chrono_Minute' Label='' />
<Value ID='Cons_Stat_Chrono_Hour' Label='' />
<Value ID='Cons_Preference_Lcd_Contrast' Label='' />
<Value ID='Cons_Sn_Location' Label='' />
<Value ID='Cons_Sn_Year' Label='' />
<Value ID='Cons_Sn_Month' Label='' />
<Value ID='Cons_Sn_Day' Label='' />
<Value ID='Cons_Sn_Pn_Hi' Label='' ReadOnly='true' />
<Value ID='Cons_Sn_Pn_Lo' Label='' ReadOnly='true' />
<Value ID='Cons_Sn_Item_Hi' Label='' ReadOnly='true' />
<Value ID='Cons_Sn_Item_Lo' Label='' ReadOnly='true' />
<Value ID='Cons_Sn_Pn_Hi' Label='' />
<Value ID='Cons_Sn_Pn_Lo' Label='' />
<Value ID='Cons_Sn_Item_Hi' Label='' />
<Value ID='Cons_Sn_Item_Lo' Label='' />
<Value ID='Cons_Assist_Gauge_Joint' Label='' ReadOnly='true' Min='0' Max='11' />
<Value ID='Cons_Throttle_Min_Hi' Label='' ReadOnly='true' />
<Value ID='Cons_Throttle_Min_Lo' Label='' ReadOnly='true' />
<Value ID='Cons_Throttle_Max_Hi' Label='' ReadOnly='true' />
<Value ID='Cons_Throttle_Max_Lo' Label='' ReadOnly='true' />
<Value ID='Cons_Assist_Gauge_Joint' Label='' Min='0' Max='11' />
<Value ID='Cons_Throttle_Min_Hi' Label='' />
<Value ID='Cons_Throttle_Min_Lo' Label='' />
<Value ID='Cons_Throttle_Max_Hi' Label='' />
<Value ID='Cons_Throttle_Max_Lo' Label='' />
<Value ID='Cons_Preference_Light_On_At_Start' Label='' ReadOnly='true' />
<Value ID='Cons_Preference_Light_On_At_Start' Label='' />
<Value ID='Cons_Assist_Brake_Level' Label='' ReadOnly='true' Min='0' Max='64' UnitType='Percent' Factor='1.5625'/>
<Value ID='Cons_Preference_Trip_To_Empty_Flag' Label='' ReadOnly='true' />
<Value ID='Cons_Assist_Brake_Level' Label='' Min='0' Max='64' Factor='1.5625'/>
<Value ID='Cons_Preference_Trip_To_Empty_Flag' Label='' />
<Value ID='Cons_Preference_Display_Units' Default='1' />
<Value ID='Cons_Throttle_Enabled_Onstrain' Label='' ReadOnly='true' />
<Value ID='Cons_Throttle_Enabled_Onstrain' Label='' />
<Value ID='Cons_Assist_Brake_Flag' Default='1' />
<Value ID='Cons_Assist_Brake_Polarity' Label='' ReadOnly='true' />
<Value ID='Cons_Assist_Gauge_Filter' Label='' ReadOnly='true' Min='0' Max='8' />
<Value ID='Cons_Assist_Brake_Polarity' Label='' />
<Value ID='Cons_Assist_Gauge_Filter' Label='' Min='0' Max='8' />
<Value ID='Cons_Assist_Gauge_Gain' Label='' ReadOnly='true' Min='0.1' Max='4.0' Factor='0.1' />
<Value ID='Cons_Assist_Gain_A' Label='' ReadOnly='true' Min='0.1' Max='4.0' Factor='0.1' />
<Value ID='Cons_Assist_Gain_B' Label='' ReadOnly='true' Min='0.1' Max='25.0' Factor='0.1' />
<Value ID='Cons_Sn_Type' Label='' ReadOnly='true' />
<Value ID='Cons_Preference_Region' Label='' ReadOnly='true' />
<Value ID='Cons_Preference_Configbit_0' Label='' ReadOnly='true' />
<Value ID='Cons_Throttle_Enabled_Boost_Display' Label='' ReadOnly='true' />
<Value ID='Cons_Assist_Autoregen_Flag' Label='' ReadOnly='true' />
<Value ID='Cons_Assist_Gauge_Gain' Label='' Min='0.1' Max='4.0' Factor='0.1' />
<Value ID='Cons_Assist_Gain_A' Label='' Min='0.1' Max='4.0' Factor='0.1' />
<Value ID='Cons_Assist_Gain_B' Label='' Min='0.1' Max='25.0' Factor='0.1' />
<Value ID='Cons_Sn_Type' Label='' />
<Value ID='Cons_Preference_Region' Label='' />
<Value ID='Cons_Preference_Configbit_0' Label='' />
<Value ID='Cons_Throttle_Enabled_Boost_Display' Label='' />
<Value ID='Cons_Assist_Autoregen_Flag' Label='' />
<Value ID='Cons_Rev_Sub' Label='' ReadOnly='true' />
<Value ID='Cons_Preference_Light_Button_Mode' Label='' ReadOnly='true' />
<Value ID='Cons_Preference_Expertmode' Label='' ReadOnly='true' />
<Value ID='Cons_Rev_Sub' Label='' />
<Value ID='Cons_Preference_Light_Button_Mode' Label='' />
<Value ID='Cons_Preference_Expertmode' Label='' />
<Value ID='Cons_Preference_Codes_Hihi' Label='' ReadOnly='true' />
<Value ID='Cons_Preference_Codes_Hilo' Label='' ReadOnly='true' />
<Value ID='Cons_Preference_Codes_Lohi' Label='' ReadOnly='true' />
<Value ID='Cons_Preference_Codes_Lolo' Label='' ReadOnly='true' />
<Value ID='Cons_Preference_Codesrw_Hihi' Label='' ReadOnly='true' />
<Value ID='Cons_Preference_Codesrw_Hilo' Label='' ReadOnly='true' />
<Value ID='Cons_Preference_Codesrw_Lohi' Label='' ReadOnly='true' />
<Value ID='Cons_Preference_Codesrw_Lolo' Label='' ReadOnly='true' />
<Value ID='Cons_Preference_Throttle_Mode' Label='' ReadOnly='true' />
<Value ID='Cons_Preference_Codes_Hihi' Label='' />
<Value ID='Cons_Preference_Codes_Hilo' Label='' />
<Value ID='Cons_Preference_Codes_Lohi' Label='' />
<Value ID='Cons_Preference_Codes_Lolo' Label='' />
<Value ID='Cons_Preference_Codesrw_Hihi' Label='' />
<Value ID='Cons_Preference_Codesrw_Hilo' Label='' />
<Value ID='Cons_Preference_Codesrw_Lohi' Label='' />
<Value ID='Cons_Preference_Codesrw_Lolo' Label='' />
<Value ID='Cons_Preference_Throttle_Mode' Label='' />
<Value ID='Cons_Throttle_Boost_Triggerlevel' Label='' ReadOnly='true' Min='1.5' Max='50.0' UnitType='Percent' Factor='1.5625' />
<Value ID='Cons_Preference_Flip_Side' Label='' ReadOnly='true' />
<Value ID='Cons_Config_Testmode' Label='' ReadOnly='true' />
<Value ID='Cons_Config_Testmode_Hw14' Label='' ReadOnly='true' />
<Value ID='Cons_Throttle_Boost_Triggerlevel' Label='' Min='1.5' Max='50.0' Factor='1.5625' />
<Value ID='Cons_Preference_Flip_Side' Label='' />
<Value ID='Cons_Config_Testmode' Label='' />
<Value ID='Cons_Config_Testmode_Hw14' Label='' />
<Value ID='Cons_Config_Last_Mode' Label='' ReadOnly='true' />
<Value ID='Cons_Assist_Speedgain' Label='' ReadOnly='true' Factor='0.1' />
<Value ID='Cons_Config_Last_Mode' Label='' />
<Value ID='Cons_Assist_Speedgain' Label='' Factor='0.1' />
<Value ID='Cons_Config_Last_Mode_On' Label='' ReadOnly='true' />
<Value ID='Cons_Config_Last_Mode_Off' Label='' ReadOnly='true' />
<Value ID='Cons_Config_Last_Mode_On' Label='' />
<Value ID='Cons_Config_Last_Mode_Off' Label='' />
<Value ID='Cons_Status_Slave' Label='' ReadOnly='true' />
<Value ID='Cons_Status_Slave' Label='' />
<Value ID='Cons_Throttle_Raw_Hi' Label='' ReadOnly='true' />
<Value ID='Cons_Throttle_Raw_Lo' Label='' ReadOnly='true' />
<Value ID='Cons_Throttle_Position' Label='' ReadOnly='true' Factor='1.5625'/>
<Value ID='Cons_Throttle_Raw_Hi' Label='' />
<Value ID='Cons_Throttle_Raw_Lo' Label='' />
<Value ID='Cons_Throttle_Position' Label='' Factor='1.5625'/>
<Value ID='Cons_Assist_Level_Rekuperation_3' Label='' ReadOnly='true' UnitType='Percent' Factor='1.5625'/>
<Value ID='Cons_Assist_Level_Rekuperation_4' Label='' ReadOnly='true' UnitType='Percent' Factor='1.5625'/>
<Value ID='Cons_Config_Service_Timestamp_Hi' Label='' ReadOnly='true' />
<Value ID='Cons_Config_Service_Zimestamp_Lo' Label='' ReadOnly='true' />
<Value ID='Cons_Config_Service_Distance_Hi' Label='' ReadOnly='true' />
<Value ID='Cons_Config_Service_Distance_Lo' Label='' ReadOnly='true' />
<Value ID='Cons_Assist_Level_Rekuperation_3' Label='' Factor='1.5625'/>
<Value ID='Cons_Assist_Level_Rekuperation_4' Label='' Factor='1.5625'/>
<Value ID='Cons_Config_Service_Timestamp_Hi' Label='' />
<Value ID='Cons_Config_Service_Zimestamp_Lo' Label='' />
<Value ID='Cons_Config_Service_Distance_Hi' Label='' />
<Value ID='Cons_Config_Service_Distance_Lo' Label='' />
<Value ID='Cons_Assist_Level_Rekuperation_1' Label='' ReadOnly='true' UnitType='Percent' Factor='1.5625'/>
<Value ID='Cons_Assist_Level_Rekuperation_2' Label='' ReadOnly='true' UnitType='Percent' Factor='1.5625'/>
<Value ID='Cons_Assist_Level_Rekuperation_1' Label='' Factor='1.5625'/>
<Value ID='Cons_Assist_Level_Rekuperation_2' Label='' Factor='1.5625'/>
-->