Dropped BCAbstractTransmitter, simplified code.

This commit is contained in:
2026-01-03 12:48:47 +01:00
parent c5dc84179b
commit 61bf3b2cec
6 changed files with 68 additions and 148 deletions

View File

@@ -137,21 +137,17 @@ void BCTransmitter::processValue()
else if( value.state.testFlag( BCValue::State::ReadMe ) ) else if( value.state.testFlag( BCValue::State::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 = valueType.readValueFunc( *this, devID, regID ); TransmitResult result = value.isWord ? readWordValue( devID, regID ) : readByteValue( devID, regID );
if( result.has_value() ) if( result.has_value() )
{ {
newVisibleValue = valueType.formatValue( result.value() ); newVisibleValue = value.formatValue( result.value() );
newState = BCValue::State::InSync; newState = BCValue::State::InSync;
} }
else else
{ {
newState = BCValue::State::Failed; newState = BCValue::State::Failed;
} }
*/
} }
emit valueUpdated( value.deviceID, value.indexRow, newState, newVisibleValue ); emit valueUpdated( value.deviceID, value.indexRow, newState, newVisibleValue );
@@ -165,30 +161,30 @@ void BCTransmitter::processValue()
} }
/** TransmitResult BCTransmitter::readByteValue( uint32_t deviceID, uint8_t registerID )
* @brief BCTransmitter::readByte
* NEIN NEIN NEIN!
* Reicht den read request an den aktuellen Treiber weiter. Wird von aussen, von der readValueFunc des ValueTypes
* aufgerufen, deshalb public.
*/
TransmitResult BCTransmitter::readByte( uint32_t deviceID, uint8_t registerID ) const
{ {
qDebug() << " --- YES: Read ByteValue: " << registerID;
// Wir lesen nur ein Byte und gut.
return _canDriver->readRawByte( deviceID, registerID ); return _canDriver->readRawByte( deviceID, registerID );
} }
/** TransmitResult BCTransmitter::readWordValue( uint32_t deviceID, uint8_t registerID )
* @brief BCTransmitter::writeByte
* Reicht den write request an den aktuellen Treiber weiter. Wird von aussen, von der writeValueFunc des ValueTypes
* aufgerufen, deshalb public.
*/
TransmitResult BCTransmitter::writeByte( uint32_t deviceID, uint8_t registerID , uint8_t value ) const
{ {
return _canDriver->writeRawByte( deviceID, registerID, value ); qDebug() << " --- YES: Read WordValue: " << registerID;
uint32_t result{};
// hi byte Leseversuch.
TransmitResult value = _canDriver->readRawByte( 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 = _canDriver->readRawByte( deviceID, registerID+1 );
if( !value)
return std::unexpected( value.error() );
result += *value;
return result;
} }

View File

@@ -52,7 +52,7 @@
* implementiert sein und liest/schreibt Byteweise auf den Bus. * implementiert sein und liest/schreibt Byteweise auf den Bus.
*/ */
class BCTransmitter : public QObject, public BCAbstractTransmitter class BCTransmitter : public QObject
{ {
Q_OBJECT Q_OBJECT
@@ -60,8 +60,8 @@ public:
explicit BCTransmitter(QObject *parent = nullptr); explicit BCTransmitter(QObject *parent = nullptr);
TransmitResult readByte( uint32_t deviceID, uint8_t registerID ) const override; //TransmitResult readByte( uint32_t deviceID, uint8_t registerID ) const override;
TransmitResult writeByte( uint32_t deviceID, uint8_t registerID, uint8_t value ) const override; //TransmitResult writeByte( uint32_t deviceID, uint8_t registerID, uint8_t value ) const override;
public slots: public slots:
@@ -76,8 +76,11 @@ signals:
private: private:
void readRawValueX ( const BCValue& value ) const; TransmitResult readByteValue( uint32_t deviceID, uint8_t registerID );
void writeRawValueX( const BCValue& value ) const; TransmitResult readWordValue( uint32_t deviceID, uint8_t registerID );
//TransmitResult writeByteValue( uint32_t deviceID, uint8_t registerID );
//TransmitResult writeWordValue( uint32_t deviceID, uint8_t registerID );
using BCDataQueue = QQueue<BCValuePtrConst>; using BCDataQueue = QQueue<BCValuePtrConst>;

View File

@@ -79,66 +79,6 @@ the Free Software Foundation; either version 3 of the License, or
/// reader functions
TransmitResult readDummy( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t 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 );
}
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)),
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;
}
TransmitResult readSpeedValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
{
return 0x0;
}
TransmitResult readODOValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID )
{
return 0x0;
}
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;
}
QString BCValue::formatValue( uint32_t value ) const QString BCValue::formatValue( uint32_t value ) const
{ {

View File

@@ -78,8 +78,8 @@ public:
{ {
Plain, Plain,
Bool, Bool,
Float, Number,
Mookoo Float
}; };
enum class State : uint8_t enum class State : uint8_t
@@ -130,22 +130,5 @@ Q_DECLARE_METATYPE(const BCValuePtr)
Q_DECLARE_METATYPE(BCValueList) Q_DECLARE_METATYPE(BCValueList)
/**
* @brief BCAbstractTransmitter ist das abstrakte Basisinterface für die eigentliche
* Datenübertragung auf Treiberebene.
*/
class BCAbstractTransmitter
{
public:
virtual TransmitResult readByte ( uint32_t deviceID, uint8_t registerID ) const = 0;
virtual TransmitResult writeByte( uint32_t deviceID, uint8_t registerID, uint8_t value_ ) const = 0;
};
#endif // BCVALUE_H #endif // BCVALUE_H

View File

@@ -185,23 +185,15 @@ void BCXmlLoader::loadXmlBikeDeviceData(BCDevice::ID deviceID)
std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const BCValueParams& params ) std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const BCValueParams& params )
{ {
/* static QHash<QString,BCValue::ValueType> s_valueTypes
static QHash<QString,ReadValueFunc> s_bcReadValueFunctions
{ {
{ "Byte", readByteValue }, { "Plain", BCValue::ValueType::Plain },
{ "Word", readWordValue }, { "Bool", BCValue::ValueType::Bool },
{ "Assist", readByteValue } { "Number", BCValue::ValueType::Number },
{ "Float", BCValue::ValueType::Float }
}; };
auto setIfExists = [&]<typename T>( QStringView source, T& target )
if( !s_bcReadValueFunctions.contains( unitTypeKey ) )
return std::nullopt;
return s_bcReadValueFunctions[unitTypeKey];
*/
auto setIfExists = [&]( QStringView source, OptDouble& target )
{ {
if( !source.isEmpty() ) if( !source.isEmpty() )
{ {
@@ -212,7 +204,6 @@ std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const B
} }
}; };
static QMetaEnum s_bcValueEnum{QMetaEnum::fromType<BC::ID>()};
/* /*
Wir brauchen: Wir brauchen:
@@ -224,18 +215,26 @@ std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const B
// geht nicht auf qt6.8 von debian trixie // geht nicht auf qt6.8 von debian trixie
//std::optional<quint64> IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() ); //std::optional<quint64> IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() );
bool ok; bool ok;
static QMetaEnum s_bcValueEnum{QMetaEnum::fromType<BC::ID>()};
int IDVal = s_bcValueEnum.keyToValue( params.ID.toLatin1().constData(), &ok ); int IDVal = s_bcValueEnum.keyToValue( params.ID.toLatin1().constData(), &ok );
qDebug() << " --- should create: " << params.Label; qDebug() << " --- should create: " << params.Label;
//if( IDVal.has_value() ) //if( IDVal.has_value() )
if( ok ) if( ok )
{ {
BCValuePtr newValue = 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();
//setIfExists( params.Factor, newValue->factor );
setIfExists( params.Min, newValue->min );
setIfExists( params.Max, newValue->max );
newValue->label = params.Label; setIfExists( params.Factor, newValue.factor );
setIfExists( params.Min, newValue.min );
setIfExists( params.Max, newValue.max );
setIfExists( params.IsWord, newValue.isWord );
newValue.label = params.Label;
newValue.label = params.UnitLabel;
if( s_valueTypes.contains( params.ValueType ) )
newValue.valueType = s_valueTypes[params.ValueType];
/* /*
QString ID; QString ID;
@@ -248,10 +247,9 @@ std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const B
QString ValueType; QString ValueType;
*/ */
qDebug() << " --- created: " << params.Label; qDebug() << " --- created: " << params.Label;
return std::optional<BCValuePtr>( newValue ); return std::optional<BCValuePtr>( newValuePtr );
} }
return std::nullopt; return std::nullopt;

View File

@@ -15,8 +15,8 @@ QString ValueType;
<Device Type="Console"> <Device Type="Console">
<Value ID='Cons_Rev_Hw' Label='Hardware Version' /> <Value ID='Cons_Rev_Hw' Label='Hardware Version' />
<Value ID='Cons_Rev_Sw' Label='Software Version' /> <Value ID='Cons_Rev_Sw' Label='Software Version' />
<Value ID='Cons_Sn_Product_Hi' Label='Product Number' IsWord='true'/> <Value ID='Cons_Sn_Product_Hi' Label='Product Number' IsWord='1'/>
<Value ID='Cons_Sn_Oem_Hi' Label='OEM Number' IsWord='true' /> <Value ID='Cons_Sn_Oem_Hi' Label='OEM Number' IsWord='1' />
<Value ID='Cons_Assist_Initlevel' Label='Assistance Init Level' Min='0' Max='4'/> <Value ID='Cons_Assist_Initlevel' Label='Assistance Init Level' Min='0' Max='4'/>
<Value ID='Cons_Assist_Level_1' Label='Assistance Level 1' Factor='1.5625' UnitLabel='%' Min='0' Max='400' /> <Value ID='Cons_Assist_Level_1' Label='Assistance Level 1' Factor='1.5625' UnitLabel='%' Min='0' Max='400' />
@@ -33,19 +33,19 @@ QString ValueType;
<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' /> <Value ID='Cons_Throttle_Maxspeed_Hi' Label='Throttle Speed Limit' UnitLabel='km/h' Factor='0.1' Min='0' Max='70' />
<Value ID='Cons_Geometry_Circ_Hi' Label='Wheel Circumference' IsWord='true' UnitLabel='mm' Min='0' Max='2300' Factor='1.5625' /> <Value ID='Cons_Geometry_Circ_Hi' Label='Wheel Circumference' IsWord='1' UnitLabel='mm' Min='0' Max='2300' Factor='1.5625' />
<Value ID='Cons_Assist_Mountain_Cap' Label='Mountain Cap' UnitLabel='%' Factor='1.5625' /> <Value ID='Cons_Assist_Mountain_Cap' Label='Mountain Cap' UnitLabel='%' Factor='1.5625' />
</Device> </Device>
<Device Type="Motor"> <Device Type="Motor">
<Value ID='Motor_Rev_Hw' Label='Hardware Version' /> <Value ID='Motor_Rev_Hw' Label='Hardware Version' />
<Value ID='Motor_Rev_Sw' Label='Software Version' /> <Value ID='Motor_Rev_Sw' Label='Software Version' />
<Value ID='Motor_Sn_Item_Hi' Label='Motor Part Number' IsWord='true'/> <Value ID='Motor_Sn_Item_Hi' Label='Motor Part Number' IsWord='1'/>
<Value ID='Motor_Sn_Item_Hi' Label='Motor Serial Number' IsWord='true' /> <Value ID='Motor_Sn_Item_Hi' Label='Motor Serial Number' IsWord='1' />
<Value ID='Motor_Status_Temperature' Label='Motor Temperature' UnitLabel='°C' /> <Value ID='Motor_Status_Temperature' Label='Motor Temperature' UnitLabel='°C' />
<Value ID='Motor_Assist_Maxspeed' Label='Motor max. Speed' Reader='Kmh' /> <Value ID='Motor_Assist_Maxspeed' Label='Motor max. Speed' Reader='Kmh' />
<Value ID='Motor_Geometry_Circ_Hi' Label='Wheel Circumference' IsWord='true' UnitLabel='mm' Min='0' Max='2300' Factor='1.5625' /> <Value ID='Motor_Geometry_Circ_Hi' Label='Wheel Circumference' IsWord='1' UnitLabel='mm' Min='0' Max='2300' Factor='1.5625' />
</Device> </Device>
<Device Type="Battery"> <Device Type="Battery">