Cleanups.
This commit is contained in:
@@ -38,34 +38,57 @@
|
||||
|
||||
|
||||
|
||||
uint32_t readByteValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
|
||||
TransmitResult readDummy( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
|
||||
{
|
||||
return transmitter.readByte( deviceID, 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 );
|
||||
}
|
||||
|
||||
|
||||
uint32_t readWordValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t 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)),
|
||||
// hi byte
|
||||
uint32_t result = transmitter.readByte( deviceID, registerID ) << 8;
|
||||
// low byte, use followup register: +1
|
||||
result += transmitter.readByte( deviceID, registerID+1 );
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
uint32_t readODOValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
|
||||
TransmitResult readSpeedValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
|
||||
{
|
||||
return 0x0;
|
||||
}
|
||||
|
||||
uint32_t readVoltValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
|
||||
TransmitResult readODOValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
|
||||
{
|
||||
return 0x0;
|
||||
}
|
||||
|
||||
uint32_t readCircValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
|
||||
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;
|
||||
}
|
||||
@@ -79,10 +102,34 @@ BCValueType::BCValueType()
|
||||
|
||||
}
|
||||
|
||||
BCValueType::BCValueType( QString unitLabel_, double factor_, optDouble min_, optDouble max_ )
|
||||
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::readRawValueX(const BCAbstractTransmitter& transmitter , const BCValue& value) const
|
||||
{
|
||||
qDebug() << " --- READ X!";
|
||||
/*
|
||||
uint32_t devID = static_cast<uint32_t>(deviceID);
|
||||
uint8_t regID = static_cast<uint8_t> (registerID);
|
||||
|
||||
// wir sind hier im anderen thread! nicht einfach so reinschreiben, nur lesen
|
||||
if( valueType->readValueFunc )
|
||||
{
|
||||
uint32_t result = valueType->readValueFunc( transmitter, devID, regID );
|
||||
return valueType->formatValue( result );
|
||||
}
|
||||
*/
|
||||
return QString();
|
||||
}
|
||||
|
||||
void BCValueType::writeRawValueX( const BCAbstractTransmitter& transmitter, const BCValue& value ) const
|
||||
{
|
||||
qDebug() << " --- WRITE X!";
|
||||
}
|
||||
|
||||
QString BCValueType::formatValue( uint32_t value ) const
|
||||
@@ -94,22 +141,6 @@ QString BCValueType::formatValue( uint32_t value ) const
|
||||
return QString::number(result, 'f', 2);
|
||||
}
|
||||
|
||||
/*
|
||||
_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 } );
|
||||
*/
|
||||
|
||||
std::optional<ReadValueFunc> BCValueType::fetchReadValueFunction( const QString& unitTypeKey )
|
||||
{
|
||||
static QHash<QString,ReadValueFunc> s_bcReadValueFunctions
|
||||
@@ -126,8 +157,7 @@ std::optional<ReadValueFunc> BCValueType::fetchReadValueFunction( const QString&
|
||||
{ "Degree", readByteValue },
|
||||
{ "SoC", readByteValue },
|
||||
{ "Odo", readByteValue },
|
||||
{ "Assist", readByteValue },
|
||||
{ "Assist", readByteValue },
|
||||
{ "Assist", readByteValue }
|
||||
};
|
||||
|
||||
if( !s_bcReadValueFunctions.contains( unitTypeKey ) )
|
||||
@@ -140,8 +170,9 @@ std::optional<BCValueType*> BCValueType::fetchValueType( const QString& unitType
|
||||
{
|
||||
static QHash<QString,BCValueType*> s_bcDataTypes
|
||||
{
|
||||
{ "Byte", new BCValueType( "", 1.5625F) },
|
||||
{ "Word", new BCValueType( "", 1.5625F) },
|
||||
{ "Byte", new BCValueType( "Byte", "", 1.5625F) },
|
||||
{ "Word", new BCValueType( "Word", "", 1.5625F) }
|
||||
/*
|
||||
{ "Float", new BCValueType( "", 1.5625F) },
|
||||
{ "Percent",new BCValueType( "%", 1.5625 ) },
|
||||
{ "KWh", new BCValueType( "kwh", 1.5625 ) },
|
||||
@@ -155,6 +186,7 @@ std::optional<BCValueType*> BCValueType::fetchValueType( const QString& unitType
|
||||
{ "Odo", new BCValueType( "km", 1.5625 ) },
|
||||
{ "Assist", new BCValueType( "", 0 ,4 ) },
|
||||
{ "Assist", new BCValueType( "%" ) },
|
||||
*/
|
||||
};
|
||||
|
||||
if( !s_bcDataTypes.contains( unitTypeKey ) )
|
||||
|
||||
Reference in New Issue
Block a user