Reworked value handling.

This commit is contained in:
2026-01-01 22:27:48 +01:00
parent 6e860d8d05
commit a3dac8e4f8
6 changed files with 313 additions and 211 deletions

View File

@@ -34,6 +34,46 @@
#include <bcvalue.h>
/// reader functions
uint32_t readByteValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
{
return transmitter.readByte( deviceID, registerID );
}
uint32_t readWordValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t 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 );
return result;
}
uint32_t readODOValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
{
return 0x0;
}
uint32_t readVoltValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
{
return 0x0;
}
uint32_t readCircValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
{
return 0x0;
}
/**
* @brief BCValueType::BCValueType
*/
BCValueType::BCValueType()
{
@@ -69,26 +109,52 @@ QString BCValueType::formatValue( uint32_t value ) const
_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
{
{ "Byte", readByteValue },
{ "Word", readWordValue },
{ "Percent",readByteValue },
{ "KWh", readByteValue },
{ "Watt", readByteValue },
{ "Km", readByteValue },
{ "Kmh", readByteValue },
{ "Mm", readByteValue },
{ "Sec", readByteValue },
{ "Degree", readByteValue },
{ "SoC", readByteValue },
{ "Odo", readByteValue },
{ "Assist", readByteValue },
{ "Assist", 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 BCValueTypeWord( "", 1.5625F) },
{ "Word", new BCValueTypeWord( "", 1.5625F) },
{ "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 ) },
{ "Degree", new BCValueTypeByte( "°C", 1.0 ) },
{ "SoC", new BCValueTypeWord( "%", 1.5625 ) },
{ "Odo", new BCValueTypeWord( "km", 1.5625 ) },
{ "Assist", new BCValueTypeWord( "", 0 ,4 ) },
{ "Assist", new BCValueTypeWord( "%" ) },
{ "Byte", new BCValueType( "", 1.5625F) },
{ "Word", new BCValueType( "", 1.5625F) },
{ "Float", new BCValueType( "", 1.5625F) },
{ "Percent",new BCValueType( "%", 1.5625 ) },
{ "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( "", 0 ,4 ) },
{ "Assist", new BCValueType( "%" ) },
};
if( !s_bcDataTypes.contains( unitTypeKey ) )
@@ -100,47 +166,3 @@ std::optional<BCValueType*> BCValueType::fetchValueType( const QString& unitType
/// ----
BCValueTypeByte::BCValueTypeByte( QString unitLabel_, double factor_, optDouble min_, optDouble max_ )
: BCValueType{ unitLabel_, factor_, min_, max_}
{
}
QString BCValueTypeByte::createStringValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) const
{
uint8_t result = transmitter.readByte( deviceID, registerID );
return formatValue( result );
}
/// ----
BCValueTypeWord::BCValueTypeWord( QString unitLabel_, double factor_, optDouble min_, optDouble max_ )
: BCValueType{ unitLabel_, factor_, min_, max_}
{
}
QString BCValueTypeWord::createStringValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) const
{
//getValue(CONSOLE, CONSOLE_SN_PN_HI) << 8) + getValue(CONSOLE, CONSOLE_SN_PN_LO)),
// hi byte
uint8_t result = transmitter.readByte( deviceID, registerID ) << 8;
// low byte, use followup register: +1
result += transmitter.readByte( deviceID, registerID+1 );
return formatValue( result );
}
/// ----
BCValueTypeODO::BCValueTypeODO( QString unitLabel_, double factor_, optDouble min_, optDouble max_ )
: BCValueType{ unitLabel_, factor_, min_, max_}
{
}
QString BCValueTypeODO::createStringValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) const
{
return "0x0";
}