Debug updates.
This commit is contained in:
31
bc.h
31
bc.h
@@ -73,15 +73,6 @@ namespace bc
|
|||||||
[[maybe_unused]] constexpr static double NORMALIZED_VOLTAGE_OFFSET = 20.8333;
|
[[maybe_unused]] constexpr static double NORMALIZED_VOLTAGE_OFFSET = 20.8333;
|
||||||
[[maybe_unused]] constexpr static double NORMALIZED_VOLTAGE_FAKTOR = 0.416667;
|
[[maybe_unused]] constexpr static double NORMALIZED_VOLTAGE_FAKTOR = 0.416667;
|
||||||
|
|
||||||
// misc
|
|
||||||
//#define cbc::Version "CanBusControl 0.0.01 / 02.07.2022"
|
|
||||||
[[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 = "BionxControl";
|
|
||||||
|
|
||||||
|
|
||||||
// timer
|
// timer
|
||||||
void delay_seconds( uint32_t );
|
void delay_seconds( uint32_t );
|
||||||
void delay_millis( uint32_t );
|
void delay_millis( uint32_t );
|
||||||
@@ -91,27 +82,6 @@ namespace bc
|
|||||||
QString formatInt( int count, int len );
|
QString formatInt( int count, int len );
|
||||||
} // namespace bc
|
} // namespace bc
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// constants.h
|
|
||||||
#pragma once
|
|
||||||
#include <QLatin1StringView>
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct BC
|
struct BC
|
||||||
{
|
{
|
||||||
@@ -775,6 +745,7 @@ namespace BCTags
|
|||||||
inline constexpr auto Label = "Label"_L1;
|
inline constexpr auto Label = "Label"_L1;
|
||||||
inline constexpr auto UnitLabel = "UnitLabel"_L1;
|
inline constexpr auto UnitLabel = "UnitLabel"_L1;
|
||||||
inline constexpr auto IsWord = "IsWord"_L1;
|
inline constexpr auto IsWord = "IsWord"_L1;
|
||||||
|
inline constexpr auto ReadOnly = "ReadOnly"_L1;
|
||||||
inline constexpr auto Default = "Default"_L1;
|
inline constexpr auto Default = "Default"_L1;
|
||||||
|
|
||||||
inline constexpr auto Current = "Current"_L1;
|
inline constexpr auto Current = "Current"_L1;
|
||||||
|
|||||||
@@ -202,13 +202,18 @@ void BCAnimatedDelegate::paint(QPainter *painter, const QStyleOptionViewItem& op
|
|||||||
case 1:
|
case 1:
|
||||||
|
|
||||||
if(_rowOpacities.contains(row))
|
if(_rowOpacities.contains(row))
|
||||||
paintHighlightRow(painter,option,index);
|
paintHighlightRow(painter,option,index.row());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
|
|
||||||
if( row>-1 && row <= _valueList.size() )
|
if( row>-1 && row <= _valueList.size() )
|
||||||
paintSliderIndicator(painter,option,index);
|
{
|
||||||
|
const BCValue& bcValue = *(_valueList[ index.row()].get());
|
||||||
|
qDebug() << " --- paintSLider: " << bcValue.label << " type: " << (int)bcValue.valueType << " flags:" << bcValue.valueFlags.toInt() << " RO: " << bcValue.isReadOnly();
|
||||||
|
if( !bcValue.isReadOnly())
|
||||||
|
paintSliderIndicator(painter,option,bcValue);
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -216,35 +221,39 @@ void BCAnimatedDelegate::paint(QPainter *painter, const QStyleOptionViewItem& op
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BCAnimatedDelegate::paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
void BCAnimatedDelegate::paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, int row) const
|
||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->setRenderHint(QPainter::Antialiasing);
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
int row = index.row();
|
|
||||||
qreal opacity =_rowOpacities.value(row);
|
qreal opacity =_rowOpacities.value(row);
|
||||||
painter->setOpacity(opacity);
|
painter->setOpacity(opacity);
|
||||||
// Margin von 4px
|
// Margin von 4px
|
||||||
QRect itemRect = option.rect.adjusted(3, 3, -3, -3);
|
QRect itemRect = option.rect.adjusted(3, 3, -3, -3);
|
||||||
|
|
||||||
// Border (2px solid #2196F3)
|
// Border (2px solid #2196F3)
|
||||||
QPen borderPen( Qt::red, 1);
|
// oranger rahmen
|
||||||
|
QPen borderPen( QColor(0xFF8C00), 1);
|
||||||
painter->setPen(borderPen);
|
painter->setPen(borderPen);
|
||||||
painter->setBrush(Qt::NoBrush);
|
painter->setBrush(Qt::NoBrush);
|
||||||
|
|
||||||
|
// highlight background
|
||||||
|
//QColor highlightColor = option.palette.highlight().color();
|
||||||
|
//highlightColor.setAlphaF(0.3); // 0.0 bis 1.0 (float ist oft lesbarer)
|
||||||
|
//painter->fillRect(option.rect, highlightColor);
|
||||||
|
|
||||||
painter->drawRoundedRect(itemRect, 2, 2);
|
painter->drawRoundedRect(itemRect, 2, 2);
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BCAnimatedDelegate::paintSliderIndicator(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
void BCAnimatedDelegate::paintSliderIndicator(QPainter* painter, const QStyleOptionViewItem& option, const BCValue& bcValue) const
|
||||||
{
|
{
|
||||||
const BCValue& bcValue = *(_valueList[ index.row()].get());
|
|
||||||
|
|
||||||
qDebug() << " --- paintSLider: " << bcValue.label << ": " << (int)bcValue.valueType;
|
|
||||||
// wenn Werte readOnly sind, dann brauchen keinen EditHint
|
// wenn Werte readOnly sind, dann brauchen keinen EditHint
|
||||||
if( bcValue.flags.testFlag(BCValue::Flag::ReadOnly) )
|
//if( bcValue.valueFlags.testFlag(BCValue::Flag::ReadOnly) )
|
||||||
// || bcValue.valueType == BCValue::ValueType::Plain )
|
// || bcValue.valueType == BCValue::ValueType::Plain )
|
||||||
return;
|
// return;
|
||||||
|
|
||||||
// Hintergrund
|
// Hintergrund
|
||||||
if (option.state & QStyle::State_Selected)
|
if (option.state & QStyle::State_Selected)
|
||||||
|
|||||||
@@ -75,8 +75,8 @@ signals:
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
void updateRow(int row);
|
void updateRow(int row);
|
||||||
void paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
void paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, int row) const;
|
||||||
void paintSliderIndicator(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
void paintSliderIndicator(QPainter* painter, const QStyleOptionViewItem& option, const BCValue& bcValue) const;
|
||||||
|
|
||||||
// Das ist ein Quickhack, der Delegate sollte
|
// Das ist ein Quickhack, der Delegate sollte
|
||||||
// nichts über die Originaldaten wissen. Die
|
// nichts über die Originaldaten wissen. Die
|
||||||
|
|||||||
@@ -71,6 +71,17 @@ const BCValueList& BCDeviceView::getValueListX()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Flag, ob diese View schonmal angezeigt wurde.
|
||||||
|
*/
|
||||||
|
|
||||||
|
bool BCDeviceView::firstExpose()
|
||||||
|
{
|
||||||
|
bool stored = _firstExpose;
|
||||||
|
_firstExpose = false;
|
||||||
|
return stored;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief SLOT, der aufgerufen wird, wenn die ValueList vom XML-Lader fertig geladen wurde.
|
* @brief SLOT, der aufgerufen wird, wenn die ValueList vom XML-Lader fertig geladen wurde.
|
||||||
* Die DeviceView nimmt die ValueList dann in Besitz.
|
* Die DeviceView nimmt die ValueList dann in Besitz.
|
||||||
@@ -93,6 +104,10 @@ void BCDeviceView::updateValue(int index, BCValue::Flag state, uint32_t rawValue
|
|||||||
_itemDelegate->onHighlightRow( index );
|
_itemDelegate->onHighlightRow( index );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Die Spalte mit dem Label soll immer bei 60% der Gesamtbreite liegen.
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
|
||||||
void BCDeviceView::resizeEvent(QResizeEvent *event)
|
void BCDeviceView::resizeEvent(QResizeEvent *event)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public:
|
|||||||
|
|
||||||
const BCValueList& getValueListX();
|
const BCValueList& getValueListX();
|
||||||
|
|
||||||
bool hasContent();
|
bool firstExpose();
|
||||||
void updateValue( int index, BCValue::Flag state, uint32_t rawValue );
|
void updateValue( int index, BCValue::Flag state, uint32_t rawValue );
|
||||||
|
|
||||||
|
|
||||||
@@ -66,10 +66,12 @@ protected:
|
|||||||
|
|
||||||
void resizeEvent(QResizeEvent *event) override;
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|
||||||
|
bool _firstExpose{true};
|
||||||
BCDevice::ID _devideID{BCDevice::ID::Invalid};
|
BCDevice::ID _devideID{BCDevice::ID::Invalid};
|
||||||
BCValueModel _valueModel;
|
BCValueModel _valueModel;
|
||||||
BCAnimatedDelegate* _itemDelegate{};
|
BCAnimatedDelegate* _itemDelegate{};
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BCDEVICEVIEW_H
|
#endif // BCDEVICEVIEW_H
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ void BCDriverStateWidget::updateStyle()
|
|||||||
// FLUENT GRAY (Neutral)
|
// FLUENT GRAY (Neutral)
|
||||||
// Wir machen es dunkelgrau mit hellem Rand -> "Ausgeschaltet"-Look
|
// Wir machen es dunkelgrau mit hellem Rand -> "Ausgeschaltet"-Look
|
||||||
ledStyle = "background-color: #3B3B3B; border: 1px solid #606060;";
|
ledStyle = "background-color: #3B3B3B; border: 1px solid #606060;";
|
||||||
toolTipText = "Treiber nicht geladen.";
|
toolTipText = "Kein Treiber geladen.";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BCDriver::DriverState::Error:
|
case BCDriver::DriverState::Error:
|
||||||
@@ -149,9 +149,9 @@ void BCDriverStateWidget::updateStyle()
|
|||||||
case BCDriver::DriverState::Loaded:
|
case BCDriver::DriverState::Loaded:
|
||||||
case BCDriver::DriverState::Initialized:
|
case BCDriver::DriverState::Initialized:
|
||||||
case BCDriver::DriverState::Opened:
|
case BCDriver::DriverState::Opened:
|
||||||
// FLUENT RED (Critical)
|
// ORANGE
|
||||||
ledStyle = "background-color: #FF8C00; border: 1px solid #A80000;";
|
ledStyle = "background-color: #FF8C00; border: 1px solid #A80000;";
|
||||||
toolTipText = "Fehler beim Laden des Treibers.";
|
toolTipText = "Kein Gerät verbunden.";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BCDriver::DriverState::DeviceReady:
|
case BCDriver::DriverState::DeviceReady:
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "qassert.h"
|
#include "qassert.h"
|
||||||
#include <bcmainwindow.h>
|
#include <bcmainwindow.h>
|
||||||
@@ -139,16 +140,27 @@ void BCMainWindow::initMainWindow()
|
|||||||
_transmitter.moveToThread(&_worker);
|
_transmitter.moveToThread(&_worker);
|
||||||
_worker.start();
|
_worker.start();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
// die Daten des eBikes laden
|
// die Daten des eBikes laden
|
||||||
_dataManager.loadXmlBikeData(":/bikeinfo.xml"_L1);
|
_dataManager.loadXmlBikeData(":/bikeinfo.xml"_L1);
|
||||||
|
}
|
||||||
|
catch( BCException& exception )
|
||||||
|
{
|
||||||
|
QMessageBox::critical( this, "Ladefehler", exception.what() );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Konsolendaten als erstes anzeigen
|
||||||
_consoleAction->trigger();
|
_consoleAction->trigger();
|
||||||
//_batteryAction->trigger();
|
//_batteryAction->trigger();
|
||||||
|
|
||||||
|
/*
|
||||||
// Dummy sync beim starten
|
// Dummy sync beim starten
|
||||||
QTimer::singleShot(1000, this, [this]()
|
QTimer::singleShot(1000, this, [this]()
|
||||||
{
|
{
|
||||||
onSyncDeviceView();
|
onSyncDeviceView();
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,8 +277,15 @@ void BCMainWindow::onShowDevicePanel( BCDevice::ID deviceID )
|
|||||||
{
|
{
|
||||||
_currentPanel = nxtPanel;
|
_currentPanel = nxtPanel;
|
||||||
setHeaderLabel( _currentPanel->property( cBCKeyHeaderLabel ).toString() );
|
setHeaderLabel( _currentPanel->property( cBCKeyHeaderLabel ).toString() );
|
||||||
_stackedWidget->setCurrentWidget( nxtPanel );
|
_stackedWidget->setCurrentWidget( _currentPanel );
|
||||||
|
if( _currentPanel->firstExpose() )
|
||||||
|
{
|
||||||
|
// Dummy sync beim starten
|
||||||
|
QTimer::singleShot(1000, this, [this]()
|
||||||
|
{
|
||||||
|
onSyncDeviceView();
|
||||||
|
});
|
||||||
|
}
|
||||||
// knopf auch abschalten?
|
// knopf auch abschalten?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -312,7 +331,7 @@ void BCMainWindow::onSyncDeviceView()
|
|||||||
{
|
{
|
||||||
qDebug() << " --- ### begin sync of value: " << QThread::currentThreadId() << " : " << value->label;
|
qDebug() << " --- ### begin sync of value: " << QThread::currentThreadId() << " : " << value->label;
|
||||||
// wir setzen auf 'lesen'
|
// wir setzen auf 'lesen'
|
||||||
value->flags.setFlag( BCValue::Flag::ReadMe );
|
value->valueFlags.setFlag( BCValue::Flag::ReadMe );
|
||||||
|
|
||||||
_syncButton->setEnabled( false );
|
_syncButton->setEnabled( false );
|
||||||
|
|
||||||
|
|||||||
@@ -179,7 +179,6 @@ void BCTransmitter::onProcessValue()
|
|||||||
// Value ist 'under construction'
|
// Value ist 'under construction'
|
||||||
//emit valueUpdated( value.deviceID, value.indexRow, BCValue::Flag::Locked );
|
//emit valueUpdated( value.deviceID, value.indexRow, BCValue::Flag::Locked );
|
||||||
|
|
||||||
|
|
||||||
uint32_t devID = static_cast<uint32_t>(value.deviceID);
|
uint32_t devID = static_cast<uint32_t>(value.deviceID);
|
||||||
uint8_t regID = static_cast<uint8_t> (value.registerID);
|
uint8_t regID = static_cast<uint8_t> (value.registerID);
|
||||||
|
|
||||||
@@ -187,7 +186,7 @@ void BCTransmitter::onProcessValue()
|
|||||||
uint32_t newValue = value.rawValue;
|
uint32_t newValue = value.rawValue;
|
||||||
BCValue::Flag newState = BCValue::Flag::Failed;;
|
BCValue::Flag newState = BCValue::Flag::Failed;;
|
||||||
|
|
||||||
if(value.flags.testFlag( BCValue::Flag::WriteMe ) )
|
if(value.valueFlags.testFlag( BCValue::Flag::WriteMe ) )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
@@ -195,7 +194,7 @@ void BCTransmitter::onProcessValue()
|
|||||||
// oder sollen wir hier beides erlauben ? readFlag & writeFlag ?
|
// oder sollen wir hier beides erlauben ? readFlag & writeFlag ?
|
||||||
// Was kommt dann zuerst? Schreiben und lesen als verify ?
|
// Was kommt dann zuerst? Schreiben und lesen als verify ?
|
||||||
|
|
||||||
else if( value.flags.testFlag( BCValue::Flag::ReadMe ) )
|
else if( value.valueFlags.testFlag( BCValue::Flag::ReadMe ) )
|
||||||
{
|
{
|
||||||
// wir sind hier im anderen thread! nicht einfach so reinschreiben, nur lesen
|
// wir sind hier im anderen thread! nicht einfach so reinschreiben, nur lesen
|
||||||
TransmitResult result = value.isWord() ? readWordValue( devID, regID ) : readByteValue( devID, regID );
|
TransmitResult result = value.isWord() ? readWordValue( devID, regID ) : readByteValue( devID, regID );
|
||||||
|
|||||||
10
bcvalue.cpp
10
bcvalue.cpp
@@ -55,9 +55,15 @@ QString BCValue::formatValue() const
|
|||||||
|
|
||||||
bool BCValue::isWord() const
|
bool BCValue::isWord() const
|
||||||
{
|
{
|
||||||
return flags.testFlag(BCValue::Flag::IsWord);
|
return valueFlags.testFlag(BCValue::Flag::IsWord);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BCValue::isReadOnly() const
|
||||||
|
{
|
||||||
|
return valueFlags.testFlag(BCValue::Flag::ReadOnly);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
double BCValue::calcRatio() const
|
double BCValue::calcRatio() const
|
||||||
{
|
{
|
||||||
return 0.33;
|
return 0.33;
|
||||||
@@ -88,7 +94,7 @@ void BCValue::dumpValue() const
|
|||||||
|
|
||||||
qDebug() << "DeviceID: " << deviceID << " Register: " << registerID << " state:" " << state << " << " label: " << label;
|
qDebug() << "DeviceID: " << deviceID << " Register: " << registerID << " state:" " << state << " << " label: " << label;
|
||||||
qDebug() << "formattedValue: " << formatValue() << " min: " << optMin << " max: " << optMax << " factor: " << factor << " ValueType: " << (char)valueType << " ";
|
qDebug() << "formattedValue: " << formatValue() << " min: " << optMin << " max: " << optMax << " factor: " << factor << " ValueType: " << (char)valueType << " ";
|
||||||
qDebug() << "indexRow: " << indexRow << " isWord: " << isWord();
|
qDebug() << "indexRow: " << indexRow << " isWord: " << isWord() << " isRO: " << isReadOnly();
|
||||||
qDebug();
|
qDebug();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
10
bcvalue.h
10
bcvalue.h
@@ -98,8 +98,9 @@ public:
|
|||||||
double calcRatio() const;
|
double calcRatio() const;
|
||||||
void dumpValue() const;
|
void dumpValue() const;
|
||||||
bool isWord() const;
|
bool isWord() const;
|
||||||
|
bool isReadOnly() const;
|
||||||
|
|
||||||
mutable Flags flags{BCValue::Flag::ReadOnly};
|
mutable Flags valueFlags{BCValue::Flag::NoFlag};
|
||||||
BCDevice::ID deviceID{BCDevice::ID::Invalid};
|
BCDevice::ID deviceID{BCDevice::ID::Invalid};
|
||||||
BC::ID registerID{BC::ID::Invalid};
|
BC::ID registerID{BC::ID::Invalid};
|
||||||
ValueType valueType{ValueType::Plain};
|
ValueType valueType{ValueType::Plain};
|
||||||
@@ -113,19 +114,12 @@ public:
|
|||||||
};
|
};
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(BCValue::Flags)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(BCValue::Flags)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Q_DECLARE_METATYPE(const BCValue&)
|
|
||||||
|
|
||||||
using BCValuePtr = std::shared_ptr<BCValue>;
|
using BCValuePtr = std::shared_ptr<BCValue>;
|
||||||
using BCValuePtrConst = std::shared_ptr<const BCValue>;
|
using BCValuePtrConst = std::shared_ptr<const BCValue>;
|
||||||
|
|
||||||
//using BCValueList = QList<BCValue>;
|
//using BCValueList = QList<BCValue>;
|
||||||
using BCValueList = QList<BCValuePtr>;
|
using BCValueList = QList<BCValuePtr>;
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(const BCValuePtr)
|
Q_DECLARE_METATYPE(const BCValuePtr)
|
||||||
|
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(BCValueList)
|
Q_DECLARE_METATYPE(BCValueList)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,8 @@ void BCValueModel::updateValue(int row, BCValue::Flag state, uint32_t rawValue )
|
|||||||
{
|
{
|
||||||
const BCValue& value = *(_valueList[row].get());
|
const BCValue& value = *(_valueList[row].get());
|
||||||
|
|
||||||
value.flags = state;
|
// Obacht hier!
|
||||||
|
//value.valueFlags = state;
|
||||||
value.rawValue = rawValue;
|
value.rawValue = rawValue;
|
||||||
|
|
||||||
QModelIndex idx1 = index(row,1);
|
QModelIndex idx1 = index(row,1);
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ void BCXmlLoader::loadXmlBikeData( const QString& fileName )
|
|||||||
auto printAttrs = [](const QXmlStreamReader& xml)
|
auto printAttrs = [](const QXmlStreamReader& xml)
|
||||||
{
|
{
|
||||||
QStringList parts;
|
QStringList parts;
|
||||||
for (const auto &attr : xml.attributes()) {
|
for (const auto &attr : xml.attributes())
|
||||||
|
{
|
||||||
parts << attr.name().toString() + "=\"" + attr.value().toString() + "\"";
|
parts << attr.name().toString() + "=\"" + attr.value().toString() + "\"";
|
||||||
}
|
}
|
||||||
qDebug().noquote() << parts.join(" ");
|
qDebug().noquote() << parts.join(" ");
|
||||||
@@ -64,19 +65,14 @@ void BCXmlLoader::loadXmlBikeData( const QString& fileName )
|
|||||||
|
|
||||||
QFile file(fileName);
|
QFile file(fileName);
|
||||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
{
|
throw BCException( "Fehler", "Datei konnte nicht geöffnet werden.");
|
||||||
// __fix throw
|
|
||||||
QMessageBox::warning(nullptr, "Fehler", "Datei konnte nicht geöffnet werden.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_xml.setDevice(&file);
|
_xml.setDevice(&file);
|
||||||
|
|
||||||
if (_xml.readNextStartElement())
|
if (_xml.readNextStartElement())
|
||||||
{
|
{
|
||||||
if (_xml.name() != "Bike"_L1 )
|
if (_xml.name() != "Bike"_L1 )
|
||||||
// fix throw
|
throw BCException( "Fehler", "Falsches Datenformat.");
|
||||||
_xml.raiseError(QObject::tr("The file is not an 'Bike' file."));
|
|
||||||
}
|
}
|
||||||
// ??
|
// ??
|
||||||
Q_ASSERT(_xml.isStartElement() && _xml.name() == "Bike"_L1);
|
Q_ASSERT(_xml.isStartElement() && _xml.name() == "Bike"_L1);
|
||||||
@@ -93,26 +89,22 @@ void BCXmlLoader::loadXmlBikeData( const QString& fileName )
|
|||||||
|
|
||||||
// Wir wollen die Device-ID aus dem XML Tag ermitteln
|
// Wir wollen die Device-ID aus dem XML Tag ermitteln
|
||||||
if( deviceType.isEmpty() )
|
if( deviceType.isEmpty() )
|
||||||
{
|
|
||||||
printAttrs (_xml);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
QByteArray byteArray = deviceType.toUtf8();
|
QByteArray byteArray = deviceType.toUtf8();
|
||||||
const char* deviceKey = byteArray.constData();
|
const char* deviceKey = byteArray.constData();
|
||||||
bool ok=false;
|
bool ok=false;
|
||||||
auto optDeviceID = bcDeviceEnum.keyToValue(deviceKey,&ok);
|
auto optDeviceID = bcDeviceEnum.keyToValue(deviceKey,&ok);
|
||||||
//_currentDeviceID = BCDevice::ID( deviceID.value_or( BCDevice::ID::Invalid ) );
|
//_currentDeviceID = BCDevice::ID( deviceID.value_or( BCDevice::ID::Invalid ) );
|
||||||
//if( optDeviceID.has_value())
|
//if( optDeviceID.has_value())
|
||||||
if(ok)
|
if(!ok)
|
||||||
{
|
throw BCException( "Fehler", QString("Devicetype %1 existiert nicht.").arg(deviceType) );
|
||||||
qDebug() << " --- FETCH 2: Device: " << deviceType << " : " << optDeviceID;
|
qDebug() << " --- FETCH 2: Device: " << deviceType << " : " << optDeviceID;
|
||||||
//BCDevice::ID currentDeviceID = BCDevice::ID( optDeviceID.value() );
|
//BCDevice::ID currentDeviceID = BCDevice::ID( optDeviceID.value() );
|
||||||
BCDevice::ID currentDeviceID = BCDevice::ID( optDeviceID );
|
BCDevice::ID currentDeviceID = BCDevice::ID( optDeviceID );
|
||||||
loadXmlBikeDeviceData(currentDeviceID);
|
loadXmlBikeDeviceData(currentDeviceID);
|
||||||
}
|
} // if startElement
|
||||||
|
} // end while
|
||||||
} // if start element
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -126,9 +118,8 @@ void BCXmlLoader::loadXmlBikeDeviceData(BCDevice::ID deviceID)
|
|||||||
auto printAttrs = [](const QXmlStreamReader& xml)
|
auto printAttrs = [](const QXmlStreamReader& xml)
|
||||||
{
|
{
|
||||||
QStringList parts;
|
QStringList parts;
|
||||||
for (const auto &attr : xml.attributes()) {
|
for (const auto &attr : xml.attributes())
|
||||||
parts << attr.name().toString() + "=\"" + attr.value().toString() + "\"";
|
parts << attr.name().toString() + "=\"" + attr.value().toString() + "\"";
|
||||||
}
|
|
||||||
qDebug().noquote() << parts.join(" ");
|
qDebug().noquote() << parts.join(" ");
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -154,6 +145,7 @@ void BCXmlLoader::loadXmlBikeDeviceData(BCDevice::ID deviceID)
|
|||||||
.Min = _xml.attributes().value(BCTags::Min).toString(),
|
.Min = _xml.attributes().value(BCTags::Min).toString(),
|
||||||
.Max = _xml.attributes().value(BCTags::Max).toString(),
|
.Max = _xml.attributes().value(BCTags::Max).toString(),
|
||||||
.IsWord = _xml.attributes().value(BCTags::IsWord).toString(),
|
.IsWord = _xml.attributes().value(BCTags::IsWord).toString(),
|
||||||
|
.ReadOnly = _xml.attributes().value(BCTags::ReadOnly).toString(),
|
||||||
.ValueType = _xml.attributes().value(BCTags::ValueType).toString(),
|
.ValueType = _xml.attributes().value(BCTags::ValueType).toString(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -193,7 +185,7 @@ std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const B
|
|||||||
{ "Float", BCValue::ValueType::Float }
|
{ "Float", BCValue::ValueType::Float }
|
||||||
};
|
};
|
||||||
|
|
||||||
auto setIfExists = [&]<typename T>( QStringView source, T& target )
|
auto setIfExists = [&]<typename T>( T& target, QStringView source )
|
||||||
{
|
{
|
||||||
if( !source.isEmpty() )
|
if( !source.isEmpty() )
|
||||||
{
|
{
|
||||||
@@ -216,29 +208,36 @@ std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const B
|
|||||||
int IDVal = s_bcValueEnum.keyToValue( byteArray.constData(), &ok );
|
int IDVal = s_bcValueEnum.keyToValue( byteArray.constData(), &ok );
|
||||||
qDebug() << " --- should create: " << params.Label;
|
qDebug() << " --- should create: " << params.Label;
|
||||||
//if( IDVal.has_value() )
|
//if( IDVal.has_value() )
|
||||||
if( ok )
|
if( !ok )
|
||||||
{
|
throw BCException( "Fehler", QString("Devicetype %1 existiert nicht.").arg(params.ID) );
|
||||||
|
|
||||||
BCValuePtr newValuePtr = std::make_shared<BCValue>( deviceID, static_cast<BC::ID>(IDVal) );
|
BCValuePtr newValuePtr = std::make_shared<BCValue>( deviceID, static_cast<BC::ID>(IDVal) );
|
||||||
BCValue& newValue = *newValuePtr.get();
|
BCValue& newValue = *newValuePtr.get();
|
||||||
|
|
||||||
setIfExists( params.Factor, newValue.factor );
|
// ValueType
|
||||||
setIfExists( params.Min, newValue.optMin );
|
if( !s_valueTypes.contains( params.ValueType ) )
|
||||||
setIfExists( params.Max, newValue.optMax );
|
throw BCException( "Fehler", QString("ValueType %1 existiert nicht.").arg(params.ValueType) );
|
||||||
//setIfExists( params.IsWord, newValue.isWord );
|
|
||||||
|
newValue.valueType = s_valueTypes[params.ValueType];
|
||||||
|
|
||||||
newValue.label = params.Label;
|
newValue.label = params.Label;
|
||||||
newValue.unitLabel = params.UnitLabel;
|
newValue.unitLabel = params.UnitLabel;
|
||||||
|
|
||||||
if( s_valueTypes.contains( params.ValueType ) )
|
setIfExists( newValue.factor, params.Factor );
|
||||||
newValue.valueType = s_valueTypes[params.ValueType];
|
setIfExists( newValue.optMin, params.Min );
|
||||||
|
setIfExists( newValue.optMax, params.Max );
|
||||||
|
|
||||||
|
if( params.IsWord == "true")
|
||||||
|
newValue.valueFlags.setFlag( BCValue::Flag::IsWord, true );
|
||||||
|
|
||||||
|
if( params.ReadOnly == "true")
|
||||||
|
newValue.valueFlags.setFlag( BCValue::Flag::ReadOnly, true );
|
||||||
|
|
||||||
qDebug() << " --- created: " << params.Label;
|
qDebug() << " --- created: " << params.Label;
|
||||||
newValue.dumpValue();
|
newValue.dumpValue();
|
||||||
|
|
||||||
return std::optional<BCValuePtr>( newValuePtr );
|
return std::optional<BCValuePtr>( newValuePtr );
|
||||||
}
|
|
||||||
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ protected:
|
|||||||
QString Min;
|
QString Min;
|
||||||
QString Max;
|
QString Max;
|
||||||
QString IsWord;
|
QString IsWord;
|
||||||
|
QString ReadOnly;
|
||||||
QString ValueType;
|
QString ValueType;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,27 +2,28 @@
|
|||||||
|
|
||||||
<Bike name='franken-wheeler'>
|
<Bike name='franken-wheeler'>
|
||||||
|
|
||||||
<Device Type='Battery'>
|
|
||||||
<Value ID='Battery_Rev_Hw' Label='Hardware Version' ValueType='Plain' />
|
|
||||||
<Value ID='Battery_Rev_Sw' Label='Software Version' ValueType='Plain' />
|
|
||||||
</Device>
|
|
||||||
|
|
||||||
<Device Type='Motor'>
|
<Device Type='Motor'>
|
||||||
<Value ID='Motor_Rev_Hw' Label='Hardware Version' ValueType='Plain'/>
|
<Value ID='Motor_Rev_Hw' Label='Hardware Version' ValueType='Plain' ReadOnly='true' />
|
||||||
<Value ID='Motor_Rev_Sw' Label='Software Version' ValueType='Plain'/>
|
<Value ID='Motor_Rev_Sw' Label='Software Version' ValueType='Plain' ReadOnly='true' />
|
||||||
<Value ID='Motor_Sn_Item_Hi' Label='Motor Part Number' ValueType='Plain' IsWord='1'/>
|
<Value ID='Motor_Sn_Item_Hi' Label='Motor Part Number' ValueType='Plain' IsWord='true' ReadOnly='true' />
|
||||||
<Value ID='Motor_Sn_Item_Hi' Label='Motor Serial Number' ValueType='Plain' IsWord='1' />
|
<Value ID='Motor_Sn_Item_Hi' Label='Motor Serial Number' ValueType='Plain' IsWord='true' ReadOnly='true' />
|
||||||
<Value ID='Motor_Status_Temperature' Label='Motor Temperature' ValueType='Float' UnitLabel='°C' />
|
<Value ID='Motor_Status_Temperature' Label='Motor Temperature' ValueType='Float' UnitLabel='°C' />
|
||||||
<Value ID='Motor_Assist_Maxspeed' Label='Motor max. Speed' UnitLabel='km/h' Factor='0.1' Min='0' Max='70' ValueType='Float' />
|
<Value ID='Motor_Assist_Maxspeed' Label='Motor max. Speed' UnitLabel='km/h' Factor='0.1' Min='0' Max='70' ValueType='Float' />
|
||||||
<Value ID='Motor_Geometry_Circ_Hi' Label='Wheel Circumference' IsWord='1' UnitLabel='mm' Min='0' Max='2300' ValueType='Number' Factor='1.5625' />
|
<Value ID='Motor_Geometry_Circ_Hi' Label='Wheel Circumference' IsWord='true' UnitLabel='mm' Min='0' Max='2300' ValueType='Number' Factor='1.5625' />
|
||||||
</Device>
|
</Device>
|
||||||
|
|
||||||
|
<Device Type='Battery'>
|
||||||
|
<Value ID='Reg_Battery_Rev_Hw' Label='Hardware Version' ValueType='Plain' ReadOnly='true' />
|
||||||
|
<Value ID='Reg_Battery_Rev_Sw' Label='Software Version' ValueType='Plain' ReadOnly='true' />
|
||||||
|
</Device>
|
||||||
|
|
||||||
<Device Type='Console'>
|
<Device Type='Console'>
|
||||||
<Value ID='Cons_Rev_Hw' Label='Hardware Version' ValueType='Plain'/>
|
<Value ID='Cons_Rev_Hw' Label='Hardware Version' ValueType='Plain' ReadOnly='true' />
|
||||||
<Value ID='Cons_Rev_Sw' Label='Software Version' ValueType='Plain'/>
|
<Value ID='Cons_Rev_Sw' Label='Software Version' ValueType='Plain' ReadOnly='true' />
|
||||||
|
|
||||||
<Value ID='Cons_Sn_Product_Hi' Label='Product Number' IsWord='1' ValueType='Plain'/>
|
<Value ID='Cons_Sn_Product_Hi' Label='Product Number' IsWord='true' ValueType='Plain' ReadOnly='true'/>
|
||||||
<Value ID='Cons_Sn_Oem_Hi' Label='OEM Number' IsWord='1' ValueType='Plain'/>
|
<Value ID='Cons_Sn_Oem_Hi' Label='OEM Number' IsWord='true' ValueType='Plain' ReadOnly='true' />
|
||||||
|
|
||||||
<Value ID='Cons_Assist_Initlevel' Label='Assistance Init Level' Min='0' Max='4' ValueType='Number'/>
|
<Value ID='Cons_Assist_Initlevel' Label='Assistance Init Level' Min='0' Max='4' ValueType='Number'/>
|
||||||
|
|
||||||
@@ -40,11 +41,10 @@
|
|||||||
<Value ID='Cons_Throttle_Maxspeed_Flag' Label='Throttle Limit Enabled' ValueType='Bool'/>
|
<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' ValueType='Float'/>
|
<Value ID='Cons_Throttle_Maxspeed_Hi' Label='Throttle Speed Limit' UnitLabel='km/h' Factor='0.1' Min='0' Max='70' ValueType='Float'/>
|
||||||
|
|
||||||
<Value ID='Cons_Geometry_Circ_Hi' Label='Wheel Circumference' IsWord='1' UnitLabel='mm' Min='0' Max='2300' Factor='1.5625' ValueType='Number'/>
|
<Value ID='Cons_Geometry_Circ_Hi' Label='Wheel Circumference' IsWord='true' UnitLabel='mm' Min='0' Max='2300' Factor='1.5625' ValueType='Number'/>
|
||||||
<Value ID='Cons_Assist_Mountain_Cap' Label='Mountain Cap' UnitLabel='%' Factor='1.5625' ValueType='Float'/>
|
<Value ID='Cons_Assist_Mountain_Cap' Label='Mountain Cap' UnitLabel='%' Factor='1.5625' ValueType='Float'/>
|
||||||
</Device>
|
</Device>
|
||||||
|
|
||||||
|
|
||||||
</Bike>
|
</Bike>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
|||||||
Reference in New Issue
Block a user