Reworked value reading.
This commit is contained in:
@@ -38,7 +38,7 @@
|
||||
#include <QElapsedTimer>
|
||||
|
||||
#include <bcdatamanager.h>
|
||||
|
||||
#include <bcvaluetype.h>
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
@@ -47,10 +47,9 @@ using namespace Qt::StringLiterals;
|
||||
BCDataManager::BCDataManager(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
createValueTypes();
|
||||
|
||||
//qRegisterMetaType<BCDataItem*>("BCDataItem*");
|
||||
qRegisterMetaType<BCDataItem*>();
|
||||
//qRegisterMetaType<BCDataValue*>("BCDataValue*");
|
||||
qRegisterMetaType<BCDataValue*>();
|
||||
|
||||
_transmitter.moveToThread(&_worker);
|
||||
|
||||
@@ -77,52 +76,6 @@ BCDataManager::~BCDataManager()
|
||||
}
|
||||
|
||||
|
||||
void BCDataManager::createValueTypes()
|
||||
{
|
||||
/*
|
||||
Invalid = 0x0,
|
||||
"Text"
|
||||
"Number"
|
||||
"Float"
|
||||
"Percent"
|
||||
"KWh"
|
||||
"Watt"
|
||||
"Km"
|
||||
"Kmh"
|
||||
"Mm"
|
||||
"Sec"
|
||||
"SoC"
|
||||
"Odo"
|
||||
"Date"
|
||||
|
||||
*/
|
||||
//_dataTypes.insert( { BCDataType::TypeID::Invalid, "Invalid" } );
|
||||
|
||||
/*
|
||||
_dataTypes.insert( "Invalid", { BCDataType::TypeID::Invalid, "Invalid" } );
|
||||
_dataTypes.insert( "Text", { BCDataType::TypeID::Text } );
|
||||
_dataTypes.insert( "Number", { BCDataType::TypeID::Number } );
|
||||
|
||||
_dataTypes.insert( "Byte", { BCDataType::TypeID::Byte } );
|
||||
_dataTypes.insert( "Word", { BCDataType::TypeID::Word } );
|
||||
_dataTypes.insert( "Quad", { BCDataType::TypeID::Quad } );
|
||||
*/
|
||||
|
||||
_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)
|
||||
{
|
||||
qDebug() << "[Manager] Command" << id << "finished. Success:" << success;
|
||||
@@ -146,9 +99,9 @@ void BCDataManager::onSyncFromDevice()
|
||||
BCDataModel* model = _valueModels[_currentDeviceID];
|
||||
BCDataList& currentList = model->getValueList();
|
||||
|
||||
//BCDataItem& value = currentList[4];
|
||||
//BCDataValue& value = currentList[4];
|
||||
|
||||
for( const BCDataItem& value : currentList )
|
||||
for( const BCDataValue& value : currentList )
|
||||
{
|
||||
qDebug() << " --- value: " << value.label;
|
||||
|
||||
@@ -183,7 +136,7 @@ BCTransmitter* BCDataManager::getTransmitter()
|
||||
return &_transmitter;
|
||||
};
|
||||
|
||||
void BCDataManager::loadBikeData()
|
||||
void BCDataManager::loadXmlBikeData()
|
||||
{
|
||||
auto printAttrs = [](const QXmlStreamReader& xml)
|
||||
{
|
||||
@@ -234,7 +187,7 @@ void BCDataManager::loadBikeData()
|
||||
|
||||
_currentDeviceID = BCDevice::ID( deviceID.value() );
|
||||
BCDataList parsedValues;
|
||||
loadDeviceData( parsedValues );
|
||||
loadXmlBikeDeviceData( parsedValues );
|
||||
if( parsedValues.count() )
|
||||
{
|
||||
BCDataModel* valueModel = new BCDataModel( this );
|
||||
@@ -263,7 +216,7 @@ void BCDataManager::loadBikeData()
|
||||
|
||||
}
|
||||
|
||||
void BCDataManager::loadDeviceData( BCDataList& parsedValues )
|
||||
void BCDataManager::loadXmlBikeDeviceData( BCDataList& parsedValues )
|
||||
{
|
||||
auto printAttrs = [](const QXmlStreamReader& xml)
|
||||
{
|
||||
@@ -296,10 +249,10 @@ void BCDataManager::loadDeviceData( BCDataList& parsedValues )
|
||||
};
|
||||
|
||||
// __fix! können ungültige werte erzeugt werden ?
|
||||
//BCDataItem newValue = BCData::makeDataItem( _currentDeviceID, params );
|
||||
//BCDataValue newValue = BCData::makeDataValue( _currentDeviceID, params );
|
||||
//if(newValue)
|
||||
// parsedValues.push_back( newValue );
|
||||
std::optional<BCDataItem> newValue = makeDataItem( _currentDeviceID, params );
|
||||
std::optional<BCDataValue> newValue = makeDataValue( _currentDeviceID, params );
|
||||
if(newValue)
|
||||
parsedValues.push_back( *newValue );
|
||||
}
|
||||
@@ -309,7 +262,7 @@ void BCDataManager::loadDeviceData( BCDataList& parsedValues )
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<BCDataItem> BCDataManager::makeDataItem( BCDevice::ID deviceID, const BCDataParams& params )
|
||||
std::optional<BCDataValue> BCDataManager::makeDataValue( BCDevice::ID deviceID, const BCDataParams& params )
|
||||
{
|
||||
|
||||
/*
|
||||
@@ -327,6 +280,39 @@ std::optional<BCDataItem> BCDataManager::makeDataItem( BCDevice::ID deviceID, co
|
||||
|
||||
static QMetaEnum s_bcValueEnum{QMetaEnum::fromType<BC::ID>()};
|
||||
|
||||
static BCValueTypeMap s_bcDataTypes
|
||||
{
|
||||
{ "Float", new BCValueTypeWord( "", 1.5625F) },
|
||||
{ "Percent",new BCValueTypeWord( "%", 1.5625 ) },
|
||||
{ "KWh", new BCValueTypeWord( "kwh", 1.5625 ) },
|
||||
{ "Watt", new BCValueTypeWord( "w", 1.5625 ) },
|
||||
{ "Km", new BCValueTypeWord( "km", 1.5625 ) },
|
||||
{ "Kmh", new BCValueTypeWord( "km/h", 0.1 ) },
|
||||
{ "Mm", new BCValueTypeWord( "mm", 1.5625 ) },
|
||||
{ "Sec", new BCValueTypeWord( "s", 1.5625 ) },
|
||||
{ "SoC", new BCValueTypeWord( "%", 1.5625 ) },
|
||||
{ "Odo", new BCValueTypeWord( "km", 1.5625 ) },
|
||||
{ "Assist", new BCValueTypeWord( "", 0 ,4 ) },
|
||||
{ "Assist", new BCValueTypeWord( "%" ) },
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
_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 BCValueTypeWord{{ "km", 1.5625 }} );
|
||||
_dataTypes.insert( "Kmh", new BCValueTypeWord{{ "km/h", 0.1 }} );
|
||||
_dataTypes.insert( "Mm", new BCValueTypeWord{{ "mm", 1.5625 }} );
|
||||
_dataTypes.insert( "Sec", new BCValueTypeWord{{ "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", { BCValueType::TypeID::Date } );
|
||||
*/
|
||||
|
||||
/*
|
||||
Wir brauchen:
|
||||
- einen gültige ID String um die enum ID herauszufinden.
|
||||
@@ -334,16 +320,16 @@ std::optional<BCDataItem> BCDataManager::makeDataItem( BCDevice::ID deviceID, co
|
||||
|
||||
*/
|
||||
|
||||
std::optional<BCDataItem> newValue;
|
||||
std::optional<BCDataValue> newValue;
|
||||
|
||||
std::optional<quint64> IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() );
|
||||
if( IDVal.has_value() )
|
||||
{
|
||||
if( _dataTypes.contains( params.UnitType ) )
|
||||
if( s_bcDataTypes.contains( params.UnitType ) )
|
||||
{
|
||||
|
||||
const BCDataType& valueType = *_dataTypes[params.UnitType];
|
||||
newValue = BCDataItem( valueType, deviceID, static_cast<BC::ID>(IDVal.value()) );
|
||||
const BCValueType* valueType = s_bcDataTypes[params.UnitType];
|
||||
newValue = BCDataValue( valueType, deviceID, static_cast<BC::ID>(IDVal.value()) );
|
||||
|
||||
/*
|
||||
setIfExists( params.Factor, newValue.factor );
|
||||
|
||||
Reference in New Issue
Block a user