Dropped BCAbstractTransmitter, simplified code.
This commit is contained in:
@@ -137,21 +137,17 @@ void BCTransmitter::processValue()
|
||||
|
||||
else if( value.state.testFlag( BCValue::State::ReadMe ) )
|
||||
{
|
||||
|
||||
/*
|
||||
// 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() )
|
||||
{
|
||||
newVisibleValue = valueType.formatValue( result.value() );
|
||||
newVisibleValue = value.formatValue( result.value() );
|
||||
newState = BCValue::State::InSync;
|
||||
}
|
||||
else
|
||||
{
|
||||
newState = BCValue::State::Failed;
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
emit valueUpdated( value.deviceID, value.indexRow, newState, newVisibleValue );
|
||||
@@ -165,30 +161,30 @@ void BCTransmitter::processValue()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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
|
||||
TransmitResult BCTransmitter::readByteValue( uint32_t deviceID, uint8_t registerID )
|
||||
{
|
||||
qDebug() << " --- YES: Read ByteValue: " << registerID;
|
||||
// Wir lesen nur ein Byte und gut.
|
||||
return _canDriver->readRawByte( deviceID, 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
|
||||
TransmitResult BCTransmitter::readWordValue( uint32_t deviceID, uint8_t registerID )
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
* implementiert sein und liest/schreibt Byteweise auf den Bus.
|
||||
*/
|
||||
|
||||
class BCTransmitter : public QObject, public BCAbstractTransmitter
|
||||
class BCTransmitter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -60,8 +60,8 @@ public:
|
||||
|
||||
explicit BCTransmitter(QObject *parent = nullptr);
|
||||
|
||||
TransmitResult readByte( uint32_t deviceID, uint8_t registerID ) const override;
|
||||
TransmitResult writeByte( uint32_t deviceID, uint8_t registerID, uint8_t value ) 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;
|
||||
|
||||
public slots:
|
||||
|
||||
@@ -76,8 +76,11 @@ signals:
|
||||
|
||||
private:
|
||||
|
||||
void readRawValueX ( const BCValue& value ) const;
|
||||
void writeRawValueX( const BCValue& value ) const;
|
||||
TransmitResult readByteValue( uint32_t deviceID, uint8_t registerID );
|
||||
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>;
|
||||
|
||||
|
||||
60
bcvalue.cpp
60
bcvalue.cpp
@@ -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
|
||||
{
|
||||
|
||||
21
bcvalue.h
21
bcvalue.h
@@ -78,8 +78,8 @@ public:
|
||||
{
|
||||
Plain,
|
||||
Bool,
|
||||
Float,
|
||||
Mookoo
|
||||
Number,
|
||||
Float
|
||||
};
|
||||
|
||||
enum class State : uint8_t
|
||||
@@ -130,22 +130,5 @@ Q_DECLARE_METATYPE(const BCValuePtr)
|
||||
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
|
||||
|
||||
@@ -185,34 +185,25 @@ void BCXmlLoader::loadXmlBikeDeviceData(BCDevice::ID deviceID)
|
||||
std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const BCValueParams& params )
|
||||
{
|
||||
|
||||
/*
|
||||
static QHash<QString,ReadValueFunc> s_bcReadValueFunctions
|
||||
{
|
||||
{ "Byte", readByteValue },
|
||||
{ "Word", readWordValue },
|
||||
{ "Assist", readByteValue }
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
if( !s_bcReadValueFunctions.contains( unitTypeKey ) )
|
||||
return std::nullopt;
|
||||
|
||||
return s_bcReadValueFunctions[unitTypeKey];
|
||||
*/
|
||||
auto setIfExists = [&]( QStringView source, OptDouble& target )
|
||||
static QHash<QString,BCValue::ValueType> s_valueTypes
|
||||
{
|
||||
if( !source.isEmpty() )
|
||||
{
|
||||
bool ok;
|
||||
double testVal = source.toDouble(&ok);
|
||||
if (ok)
|
||||
target = testVal;
|
||||
}
|
||||
{ "Plain", BCValue::ValueType::Plain },
|
||||
{ "Bool", BCValue::ValueType::Bool },
|
||||
{ "Number", BCValue::ValueType::Number },
|
||||
{ "Float", BCValue::ValueType::Float }
|
||||
};
|
||||
|
||||
auto setIfExists = [&]<typename T>( QStringView source, T& target )
|
||||
{
|
||||
if( !source.isEmpty() )
|
||||
{
|
||||
bool ok;
|
||||
double testVal = source.toDouble(&ok);
|
||||
if (ok)
|
||||
target = testVal;
|
||||
}
|
||||
};
|
||||
|
||||
static QMetaEnum s_bcValueEnum{QMetaEnum::fromType<BC::ID>()};
|
||||
|
||||
/*
|
||||
Wir brauchen:
|
||||
@@ -224,18 +215,26 @@ std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const B
|
||||
// geht nicht auf qt6.8 von debian trixie
|
||||
//std::optional<quint64> IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() );
|
||||
bool ok;
|
||||
static QMetaEnum s_bcValueEnum{QMetaEnum::fromType<BC::ID>()};
|
||||
int IDVal = s_bcValueEnum.keyToValue( params.ID.toLatin1().constData(), &ok );
|
||||
qDebug() << " --- should create: " << params.Label;
|
||||
//if( IDVal.has_value() )
|
||||
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;
|
||||
@@ -248,10 +247,9 @@ std::optional<BCValuePtr> BCXmlLoader::makeValue( BCDevice::ID deviceID, const B
|
||||
QString ValueType;
|
||||
*/
|
||||
|
||||
|
||||
qDebug() << " --- created: " << params.Label;
|
||||
|
||||
return std::optional<BCValuePtr>( newValue );
|
||||
return std::optional<BCValuePtr>( newValuePtr );
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
|
||||
@@ -15,8 +15,8 @@ QString ValueType;
|
||||
<Device Type="Console">
|
||||
<Value ID='Cons_Rev_Hw' Label='Hardware Version' />
|
||||
<Value ID='Cons_Rev_Sw' Label='Software Version' />
|
||||
<Value ID='Cons_Sn_Product_Hi' Label='Product Number' IsWord='true'/>
|
||||
<Value ID='Cons_Sn_Oem_Hi' Label='OEM Number' IsWord='true' />
|
||||
<Value ID='Cons_Sn_Product_Hi' Label='Product Number' IsWord='1'/>
|
||||
<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_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_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' />
|
||||
</Device>
|
||||
|
||||
<Device Type="Motor">
|
||||
<Value ID='Motor_Rev_Hw' Label='Hardware 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 Serial 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='1' />
|
||||
<Value ID='Motor_Status_Temperature' Label='Motor Temperature' UnitLabel='°C' />
|
||||
<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 Type="Battery">
|
||||
|
||||
Reference in New Issue
Block a user