Reworked data types.
This commit is contained in:
2
bc.h
2
bc.h
@@ -35,6 +35,8 @@
|
||||
#include <QDebug>
|
||||
#include <QObject> // Nötig für Q_GADGET/Q_ENUM Makros
|
||||
|
||||
using bcdata_t = uint8_t;
|
||||
|
||||
namespace bc
|
||||
{
|
||||
[[maybe_unused]] constexpr static double UNLIMITED_SPEED_VALUE = 70; // Km/h
|
||||
|
||||
@@ -78,11 +78,4 @@ void BCCanDriver::onStartDriver()
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
void BCCanDriver::onLoadItem( CBCItem& item )
|
||||
{
|
||||
|
||||
item.setValue( 99.99 );
|
||||
emit itemLoaded( item );
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -82,8 +82,8 @@ public:
|
||||
virtual BCCanDriver::dState loadDriver() = 0;
|
||||
virtual BCCanDriver::dState initDriver() = 0;
|
||||
|
||||
virtual uint getValue( BCDevice::ID dev, BC::ID reg ) const = 0;
|
||||
virtual void setValue( BCDevice::ID dev, BC::ID reg, int value ) const = 0;
|
||||
virtual std::optional<bcdata_t> readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const = 0;
|
||||
virtual void writeRawValue( BCDevice::ID deviceID, BC::ID registerID, bcdata_t value ) const = 0;
|
||||
|
||||
signals:
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ BCCanDriver::dState BCCanDriverTinyCan::initDriver()
|
||||
|
||||
qDebug() << "XXX BCCanDriverTinyCan::Driver Init: putting BCDevice::ID::Console in slave mode ... ";
|
||||
// BCDevice::ID::Console already in slave mode. good!
|
||||
if( getValue( BCDevice::ID::Console, BC::ID::Cons_Status_Slave ) )
|
||||
if( readRawValue( BCDevice::ID::Console, BC::ID::Cons_Status_Slave ) )
|
||||
return BCCanDriver::sReady;
|
||||
|
||||
qDebug() << "BCCanDriverTinyCan::BCCanDriverTinyCan::XXX Driver Init: putting BCDevice::ID::Console in slave mode ... ";
|
||||
@@ -88,11 +88,11 @@ BCCanDriver::dState BCCanDriverTinyCan::initDriver()
|
||||
unsigned int retry = _timeOuts;
|
||||
emit statusHint( "Driver Init: putting BCDevice::ID::Console in slave mode ... " );
|
||||
|
||||
int isSlave = 0;
|
||||
bcdata_t isSlave = 0;
|
||||
do
|
||||
{
|
||||
setValue( BCDevice::ID::Console, BC::ID::Cons_Status_Slave, 1 );
|
||||
isSlave = getValue( BCDevice::ID::Console, BC::ID::Cons_Status_Slave );
|
||||
writeRawValue( BCDevice::ID::Console, BC::ID::Cons_Status_Slave, 1 );
|
||||
isSlave = *readRawValue( BCDevice::ID::Console, BC::ID::Cons_Status_Slave );
|
||||
bc::delay_millis( 200 );
|
||||
|
||||
} while( retry-- && !isSlave );
|
||||
@@ -109,8 +109,8 @@ BCCanDriver::dState BCCanDriverTinyCan::initDriver()
|
||||
}
|
||||
|
||||
|
||||
//unsigned int BCCanDriverTinyCan::getValue( unsigned char receipient, unsigned char reg )
|
||||
uint BCCanDriverTinyCan::getValue(BCDevice::ID deviceID, BC::ID registerID ) const
|
||||
|
||||
std::optional<bcdata_t> BCCanDriverTinyCan::readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const
|
||||
{
|
||||
|
||||
struct TCanMsg msg;
|
||||
@@ -169,16 +169,16 @@ retry:
|
||||
if( !timeOuts )
|
||||
throw std::runtime_error( "CAN --response errror" );
|
||||
|
||||
return (unsigned int) msg.MsgData[3];
|
||||
//das ist mist!
|
||||
return (bcdata_t) msg.MsgData[3];
|
||||
|
||||
}
|
||||
|
||||
|
||||
// void BCCanDriverTinyCan::setValue( unsigned char receipient, unsigned char reg, unsigned char value )
|
||||
void BCCanDriverTinyCan::setValue(BCDevice::ID deviceID, BC::ID registerID, int value ) const
|
||||
void BCCanDriverTinyCan::writeRawValue( BCDevice::ID deviceID, BC::ID registerID, bcdata_t value ) const
|
||||
{
|
||||
|
||||
qDebug() << "SaveItem( BCCanDriverTinyCan::CBCItem& item ): ";
|
||||
qDebug() << " --- BCCanDriverTinyCan writeRawValue: " << value;
|
||||
|
||||
uint32_t device = static_cast<uint32_t>(deviceID);
|
||||
uint8_t reg = static_cast<uint8_t> (registerID);
|
||||
@@ -204,16 +204,3 @@ void BCCanDriverTinyCan::setValue(BCDevice::ID deviceID, BC::ID registerID, int
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void BCCanDriverTinyCan::awaitReceiveBuf( int timeout )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void BCCanDriverTinyCan::awaitSendBuf(int timeout )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ public:
|
||||
BCCanDriver::dState loadDriver() override;
|
||||
BCCanDriver::dState initDriver() override;
|
||||
|
||||
uint getValue( BCDevice::ID dev, BC::ID reg ) const override;
|
||||
void setValue( BCDevice::ID dev, BC::ID reg, int value ) const override;
|
||||
std::optional<bcdata_t> readRawValue ( BCDevice::ID deviceID, BC::ID registerID ) const override;
|
||||
void writeRawValue( BCDevice::ID deviceID, BC::ID registerID, bcdata_t value ) const override;
|
||||
|
||||
QString getNodeName( unsigned char id );
|
||||
|
||||
|
||||
@@ -17,9 +17,9 @@ void BCTransmitter::onToggleConnectionState( bool connect )
|
||||
if( BCCanDriver::sIdle == _canDriver.getState() )
|
||||
_canDriver.onStartDriver();
|
||||
|
||||
int hwVersion = _canDriver.getValue( BCDevice::ID::Console, BC::ID::Cons_Rev_Hw);
|
||||
std::optional<bcdata_t> hwVersion = _canDriver.readRawValue( BCDevice::ID::Console, BC::ID::Cons_Rev_Hw);
|
||||
|
||||
if (hwVersion == 0)
|
||||
if(!hwVersion.has_value())
|
||||
{
|
||||
qDebug() << "Console not responding";
|
||||
}
|
||||
@@ -94,41 +94,28 @@ void BCTransmitter::processValueOp( BC::OpID opID )
|
||||
currentValue =_valueQueue.dequeue();
|
||||
} // Mutex wird hier freigegeben! WICHTIG: Execute ohne Lock!
|
||||
|
||||
std::optional<bcdata_t> result;
|
||||
|
||||
/*
|
||||
if( opID == BC::OpID::ReadValue )
|
||||
result = executeRead(currentValue);
|
||||
currentValue->readRawValue( *this );
|
||||
else if( opID == BC::OpID::WriteValue )
|
||||
result = executeRead(currentValue);
|
||||
*/
|
||||
currentValue->writeRawValue( *this );
|
||||
|
||||
|
||||
//emit commandFinished(cmd.id, true);
|
||||
//emit commandFinished(0, true);
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<bcdata_t> BCTransmitter::executeRead(const BCValue& value)
|
||||
std::optional<bcdata_t> BCTransmitter::readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const
|
||||
{
|
||||
return _canDriver.readRawValue( deviceID, registerID );
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
std::optional<uint32_t> result;
|
||||
switch( value.deviceID )
|
||||
void BCTransmitter::writeRawValue( BCDevice::ID deviceID, BC::ID registerID, bcdata_t value ) const
|
||||
{
|
||||
// hier lacht der blaue riesenhase!
|
||||
case BCDevice::ID::Invalid:
|
||||
case BCDevice::ID::Console:
|
||||
case BCDevice::ID::Console_Master:
|
||||
case BCDevice::ID::Battery:
|
||||
case BCDevice::ID::Motor:
|
||||
case BCDevice::ID::BIB:
|
||||
case BCDevice::ID::Sensor:
|
||||
break;
|
||||
};
|
||||
_canDriver.writeRawValue( deviceID, registerID, value );
|
||||
}
|
||||
|
||||
|
||||
std::optional<bcdata_t> BCTransmitter::executeWrite(const BCValue& value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <QObject>
|
||||
#include <QQueue>
|
||||
#include <QMutex>
|
||||
#include <functional>
|
||||
#include <atomic>
|
||||
|
||||
#include <bcvalue.h>
|
||||
@@ -18,6 +17,8 @@ public:
|
||||
|
||||
explicit BCTransmitter(QObject *parent = nullptr);
|
||||
|
||||
std::optional<bcdata_t> readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const override;
|
||||
void writeRawValue(BCDevice::ID deviceID, BC::ID registerID, bcdata_t value ) const override;
|
||||
|
||||
public slots:
|
||||
|
||||
@@ -32,8 +33,7 @@ signals:
|
||||
|
||||
private:
|
||||
|
||||
std::optional<bcdata_t> executeRead(const BCValue& value);
|
||||
std::optional<bcdata_t> executeWrite(const BCValue& value);
|
||||
|
||||
|
||||
using BCValueQueue = QQueue<const BCValue*>;
|
||||
|
||||
|
||||
@@ -52,15 +52,16 @@ BCValue::BCValue()
|
||||
}
|
||||
*/
|
||||
|
||||
BCValue::BCValue(const BCValueType& valueType_, BCDevice::ID deviceID_, BC::ID targetID_)
|
||||
: valueType{valueType_}, deviceID{deviceID_}, targetID{targetID_}
|
||||
BCValue::BCValue(const BCValueType& valueType_, BCDevice::ID deviceID_, BC::ID registerID_)
|
||||
: valueType{valueType_}, deviceID{deviceID_}, registerID{registerID_}
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void BCValue::readRawValue( const BCAbstractTransmitter& transmitter ) const
|
||||
{
|
||||
transmitter.readValue( deviceID, targetID );
|
||||
std::optional<uint32_t> result = transmitter.readRawValue( deviceID, registerID );
|
||||
|
||||
}
|
||||
|
||||
void BCValue::writeRawValue( const BCAbstractTransmitter& transmitter ) const
|
||||
|
||||
12
bcvalue.h
12
bcvalue.h
@@ -53,7 +53,7 @@
|
||||
-
|
||||
*/
|
||||
|
||||
using bcdata_t = uint32_t;
|
||||
|
||||
|
||||
class BCAbstractTransmitter
|
||||
{
|
||||
@@ -61,8 +61,8 @@ class BCAbstractTransmitter
|
||||
public:
|
||||
|
||||
//
|
||||
virtual bcdata_t readValue( BCDevice::ID deviceID_, BC::ID targetID_ ) const { return 0;};
|
||||
///virtual uint32_t readByte( BCDevice::ID deviceID_, BC::ID targetID_ ) const = 0;
|
||||
virtual std::optional<bcdata_t> readRawValue( BCDevice::ID deviceID_, BC::ID registerID_ ) const = 0;
|
||||
virtual void writeRawValue( BCDevice::ID deviceID_, BC::ID registerID_, uint8_t value_ ) const = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ class BCValue
|
||||
public:
|
||||
|
||||
//BCValue();
|
||||
BCValue( const BCValueType& valueType_, BCDevice::ID deviceID_, BC::ID targetID_ );
|
||||
BCValue( const BCValueType& valueType_, BCDevice::ID deviceID_, BC::ID registerID_ );
|
||||
|
||||
void readRawValue( const BCAbstractTransmitter& transmitter ) const;
|
||||
void writeRawValue( const BCAbstractTransmitter& transmitter ) const;
|
||||
@@ -128,7 +128,7 @@ public:
|
||||
|
||||
BCValueTypeCRef valueType;
|
||||
BCDevice::ID deviceID{BCDevice::ID::Invalid};
|
||||
BC::ID targetID{BC::ID::Invalid};
|
||||
BC::ID registerID{BC::ID::Invalid};
|
||||
int rowInModel{-1};
|
||||
QString label;
|
||||
QVariant value;
|
||||
@@ -137,7 +137,7 @@ public:
|
||||
bool inSync{false};
|
||||
bool readOnly{false};
|
||||
|
||||
mutable double rawValue{};
|
||||
mutable std::optional<bcdata_t> rawValue;
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user