228 lines
5.9 KiB
C++
228 lines
5.9 KiB
C++
/***************************************************************************
|
|
|
|
BionxControl
|
|
Copyright © 2025 christoph holzheuer
|
|
christoph.holzheuer@gmail.com
|
|
|
|
Using:
|
|
|
|
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
|
|
|
|
mhs_can_drv.c 3.00
|
|
© 2011 - 2015 by MHS-Elektronik GmbH & Co. KG, Germany
|
|
Demlehner Klaus, info@mhs-elektronik.de
|
|
@see www.mhs-elektronik.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 <QFile>
|
|
#include <QFileDialog>
|
|
#include <QTableView>
|
|
|
|
#include <QVBoxLayout>
|
|
#include <QPushButton>
|
|
#include <QMessageBox>
|
|
#include <QHeaderView>
|
|
#include <QStatusBar>
|
|
#include <bcvaluemanager.h>
|
|
|
|
|
|
using namespace Qt::StringLiterals;
|
|
|
|
|
|
BCValueManager::BCValueManager()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BCValueManager::~BCValueManager()
|
|
{
|
|
// nothing to do here for now,
|
|
// our models are autokilled.
|
|
}
|
|
|
|
void BCValueManager::loadXml()
|
|
{
|
|
auto printAttrs = [](const QXmlStreamReader& xml)
|
|
{
|
|
QStringList parts;
|
|
for (const auto &attr : xml.attributes()) {
|
|
parts << attr.name().toString() + "=\"" + attr.value().toString() + "\"";
|
|
}
|
|
qDebug().noquote() << parts.join(" ");
|
|
};
|
|
/*
|
|
QString fileName = QFileDialog::getOpenFileName(this, "XML öffnen", "", "XML Files (*.xml)");
|
|
if (fileName.isEmpty())
|
|
return;
|
|
*/
|
|
|
|
QFile file(":/bikeinfo.xml");
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
|
{
|
|
// __fix throw
|
|
QMessageBox::warning(nullptr, "Fehler", "Datei konnte nicht geöffnet werden.");
|
|
return;
|
|
}
|
|
|
|
_xml.setDevice(&file);
|
|
|
|
if (_xml.readNextStartElement())
|
|
{
|
|
if (_xml.name() != "Bike"_L1 )
|
|
// fix throw
|
|
_xml.raiseError(QObject::tr("The file is not an 'Bike' file."));
|
|
}
|
|
// ??
|
|
Q_ASSERT(_xml.isStartElement() && _xml.name() == "Bike"_L1);
|
|
|
|
|
|
while (!_xml.atEnd() && !_xml.hasError())
|
|
{
|
|
QXmlStreamReader::TokenType token = _xml.readNext();
|
|
if (token == QXmlStreamReader::StartElement)
|
|
{
|
|
qDebug() << " --- Device: " << _xml.name() << ": " << _xml.attributes().value("Type"_L1);
|
|
printAttrs (_xml);
|
|
const char* deviceKey = _xml.attributes().value("Type"_L1).toLatin1().constData();
|
|
auto deviceID = _bcDeviceEnum.keyToValue64(deviceKey);
|
|
//_currentDeviceID = BCDevice::ID( deviceID.value_or( BCDevice::ID::Invalid ) );
|
|
_currentDeviceID = deviceID.has_value() ? BCDevice::ID( deviceID.value() ) : BCDevice::ID::Invalid;
|
|
readDevice();
|
|
}
|
|
}
|
|
|
|
/*
|
|
if (xml.hasError())
|
|
{
|
|
QMessageBox::critical(nullptr, "Parsing Fehler", xml.errorString());
|
|
}
|
|
else
|
|
{
|
|
m_model->setDevices(parsedValues);
|
|
}
|
|
*/
|
|
|
|
// create & add new model to the model map
|
|
|
|
}
|
|
|
|
void BCValueManager::readDevice()
|
|
{
|
|
auto printAttrs = [](const QXmlStreamReader& xml)
|
|
{
|
|
QStringList parts;
|
|
for (const auto &attr : xml.attributes()) {
|
|
parts << attr.name().toString() + "=\"" + attr.value().toString() + "\"";
|
|
}
|
|
qDebug().noquote() << parts.join(" ");
|
|
};
|
|
|
|
printAttrs (_xml);
|
|
Q_ASSERT(_xml.isStartElement() && _xml.name() == "Device"_L1);
|
|
qDebug() << " ---------------";
|
|
|
|
BCValueList parsedValues;
|
|
|
|
//while (!_xml.atEnd() && !_xml.hasError())
|
|
while( _xml.readNextStartElement() )
|
|
{
|
|
const char* key = _xml.attributes().value("I##D"_L1).toLatin1().constData();
|
|
qDebug() << " --- blub: " << _xml.name() << " : " << key << ":" <<_xml.attributes().value("ID"_L1);
|
|
if(key)
|
|
makeValue(parsedValues);
|
|
else
|
|
qDebug() << " --- fitz";
|
|
|
|
//printAttrs (_xml);
|
|
_xml.skipCurrentElement();
|
|
/*
|
|
if (token == QXmlStreamReader::StartElement )
|
|
{
|
|
qDebug() << " --- moo: " << _xml.name();
|
|
//Q_ASSERT(_xml.name() == "Value"_L1);
|
|
//makeValue();
|
|
//d.name = xml.attributes().value(u"name")
|
|
}
|
|
*/
|
|
}
|
|
|
|
//qDebug()xml.attributes().value(u"name").toString();
|
|
/*
|
|
Device d;
|
|
d.name = xml.attributes().value(u"name").toString();
|
|
d.ip = xml.attributes().value(u"ip").toString();
|
|
parsedValues.append(d);
|
|
*/
|
|
|
|
}
|
|
|
|
void BCValueManager::makeValue(BCValueList& parsedValues)
|
|
{
|
|
// ID='Cons_Stat_Dist_Hi' Default='' Current='' Enabled='true' UnitType='mm' Factor='0.1' Min Max
|
|
const char* ID = _xml.attributes().value("firz"_L1).toLatin1().constData();
|
|
auto enumVal = _bcValueEnum.keyToValue64( ID);
|
|
if( enumVal.has_value() )
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
// --- NEU: Speichern mit QXmlStreamWriter ---
|
|
void BCValueManager::saveXml()
|
|
{
|
|
/*
|
|
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);
|
|
}
|
|
*/
|
|
}
|