Reworked value reading.
This commit is contained in:
@@ -26,12 +26,13 @@ windows
|
|||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
bc.cpp \
|
bc.cpp \
|
||||||
bcdataitem.cpp \
|
|
||||||
bcdatamanager.cpp \
|
bcdatamanager.cpp \
|
||||||
bcdatamodel.cpp \
|
bcdatamodel.cpp \
|
||||||
|
bcdatavalue.cpp \
|
||||||
bcitemdelegate.cpp \
|
bcitemdelegate.cpp \
|
||||||
bclegacy.cpp \
|
bclegacy.cpp \
|
||||||
bctransmitter.cpp \
|
bctransmitter.cpp \
|
||||||
|
bcvaluetype.cpp \
|
||||||
lib/can_drv_win.c \
|
lib/can_drv_win.c \
|
||||||
bccandriver.cpp \
|
bccandriver.cpp \
|
||||||
bccandrivertinycan.cpp \
|
bccandrivertinycan.cpp \
|
||||||
@@ -42,12 +43,13 @@ HEADERS += \
|
|||||||
bc.h \
|
bc.h \
|
||||||
bccandriver.h \
|
bccandriver.h \
|
||||||
bccandrivertinycan.h \
|
bccandrivertinycan.h \
|
||||||
bcdataitem.h \
|
|
||||||
bcdatamanager.h \
|
bcdatamanager.h \
|
||||||
bcdatamodel.h \
|
bcdatamodel.h \
|
||||||
|
bcdatavalue.h \
|
||||||
bcitemdelegate.h \
|
bcitemdelegate.h \
|
||||||
bcmainwindow.h \
|
bcmainwindow.h \
|
||||||
bctransmitter.h
|
bctransmitter.h \
|
||||||
|
bcvaluetype.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
bcmainwindow.ui
|
bcmainwindow.ui
|
||||||
|
|||||||
@@ -77,8 +77,8 @@ public:
|
|||||||
virtual DriverState loadDriver() = 0;
|
virtual DriverState loadDriver() = 0;
|
||||||
virtual DriverState initDriver() = 0;
|
virtual DriverState initDriver() = 0;
|
||||||
|
|
||||||
virtual uint32_t readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const = 0;
|
virtual uint32_t readRawByte( uint32_t deviceID, uint8_t registerID ) const = 0;
|
||||||
virtual void writeRawValue( BCDevice::ID deviceID, BC::ID registerID, uint8_t value ) const = 0;
|
virtual void writeRawByte( uint32_t deviceID, uint8_t registerID, uint8_t value ) const = 0;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
@@ -97,9 +97,8 @@ protected:
|
|||||||
|
|
||||||
DriverState _driverState{DriverState::NotPresent};
|
DriverState _driverState{DriverState::NotPresent};
|
||||||
|
|
||||||
//??
|
static constexpr int cRetries = 5;
|
||||||
int _retries = 5;
|
static constexpr int cTimeOuts = 20;
|
||||||
int _timeOuts = 20;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -73,21 +73,24 @@ BCCanDriver::DriverState BCCanDriverTinyCan::loadDriver()
|
|||||||
BCCanDriver::DriverState BCCanDriverTinyCan::initDriver()
|
BCCanDriver::DriverState BCCanDriverTinyCan::initDriver()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
uint32_t console = static_cast<uint32_t>(BCDevice::ID::Console);
|
||||||
|
uint8_t slaveFlag = static_cast<uint8_t>(BC::ID::Cons_Status_Slave);
|
||||||
|
|
||||||
qDebug() << "XXX BCCanDriverTinyCan::Driver Init: putting BCDevice::ID::Console in slave mode ... ";
|
qDebug() << "XXX BCCanDriverTinyCan::Driver Init: putting BCDevice::ID::Console in slave mode ... ";
|
||||||
// BCDevice::ID::Console already in slave mode. good!
|
// BCDevice::ID::Console already in slave mode. good!
|
||||||
if( readRawValue( BCDevice::ID::Console, BC::ID::Cons_Status_Slave ) )
|
if( readRawByte( console, slaveFlag ) )
|
||||||
return DriverState::Ready;
|
return DriverState::Ready;
|
||||||
|
|
||||||
qDebug() << "BCCanDriverTinyCan::BCCanDriverTinyCan::XXX Driver Init: putting BCDevice::ID::Console in slave mode ... ";
|
qDebug() << "BCCanDriverTinyCan::BCCanDriverTinyCan::XXX Driver Init: putting BCDevice::ID::Console in slave mode ... ";
|
||||||
|
|
||||||
unsigned int retry = _timeOuts;
|
unsigned int retry = cTimeOuts;
|
||||||
emit statusHint( "Driver Init: putting BCDevice::ID::Console in slave mode ... " );
|
emit statusHint( "Driver Init: putting BCDevice::ID::Console in slave mode ... " );
|
||||||
|
|
||||||
uint32_t isSlave = 0;
|
uint32_t isSlave = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
writeRawValue( BCDevice::ID::Console, BC::ID::Cons_Status_Slave, 1 );
|
writeRawByte( console, slaveFlag, 1 );
|
||||||
isSlave = readRawValue( BCDevice::ID::Console, BC::ID::Cons_Status_Slave );
|
isSlave = readRawByte( console, slaveFlag );
|
||||||
bc::delay_millis( 200 );
|
bc::delay_millis( 200 );
|
||||||
|
|
||||||
} while( retry-- && !isSlave );
|
} while( retry-- && !isSlave );
|
||||||
@@ -105,7 +108,7 @@ BCCanDriver::DriverState BCCanDriverTinyCan::initDriver()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32_t BCCanDriverTinyCan::readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const
|
uint32_t BCCanDriverTinyCan::readRawByte( uint32_t deviceID, uint8_t registerID ) const
|
||||||
{
|
{
|
||||||
|
|
||||||
if( getState() != DriverState::Ready)
|
if( getState() != DriverState::Ready)
|
||||||
@@ -119,22 +122,21 @@ uint32_t BCCanDriverTinyCan::readRawValue( BCDevice::ID deviceID, BC::ID registe
|
|||||||
|
|
||||||
TCanMsg msg;
|
TCanMsg msg;
|
||||||
|
|
||||||
uint32_t device = static_cast<uint32_t>(deviceID);
|
|
||||||
uint8_t reg = static_cast<uint8_t> (registerID);
|
|
||||||
|
|
||||||
// msg verpacken
|
// msg verpacken
|
||||||
msg.MsgFlags = 0L;
|
msg.MsgFlags = 0L;
|
||||||
msg.Id = device;
|
msg.Id = deviceID;
|
||||||
msg.MsgLen = 2;
|
msg.MsgLen = 2;
|
||||||
msg.MsgData[0] = 0x00;
|
msg.MsgData[0] = 0x00;
|
||||||
msg.MsgData[1] = reg;
|
msg.MsgData[1] = registerID;
|
||||||
|
|
||||||
// msg verschicken
|
// msg verschicken
|
||||||
::CanTransmit( 0, &msg, 1 );
|
::CanTransmit( 0, &msg, 1 );
|
||||||
|
|
||||||
int retries = _retries; // 5?
|
int retries = cRetries; // 5?
|
||||||
// _timeOuts (== 20) mal cTIMEOUT_MS (== 10 ms ) Versuche ...
|
// cTimeOuts (== 20) mal cTIMEOUT_MS (== 10 ms ) Versuche ...
|
||||||
int timeOuts = _timeOuts; // 20 ?
|
int timeOuts = cTimeOuts; // 20 ?
|
||||||
|
|
||||||
// ... warten bis der Sendepuffer leer ist
|
// ... warten bis der Sendepuffer leer ist
|
||||||
while( timeOuts-- && ::CanTransmitGetCount( 0 ) )
|
while( timeOuts-- && ::CanTransmitGetCount( 0 ) )
|
||||||
@@ -145,8 +147,8 @@ uint32_t BCCanDriverTinyCan::readRawValue( BCDevice::ID deviceID, BC::ID registe
|
|||||||
|
|
||||||
retry:
|
retry:
|
||||||
|
|
||||||
// _timeOuts (== 20) mal cTIMEOUT_MS (== 10 ms ) Versuche ...
|
// cTimeOuts (== 20) mal cTIMEOUT_MS (== 10 ms ) Versuche ...
|
||||||
timeOuts = _timeOuts;
|
timeOuts = cTimeOuts;
|
||||||
// ... warten, bis der Empfangspuffer nicht mehr leer ist
|
// ... warten, bis der Empfangspuffer nicht mehr leer ist
|
||||||
while( timeOuts-- && !::CanReceiveGetCount( 0 ) )
|
while( timeOuts-- && !::CanReceiveGetCount( 0 ) )
|
||||||
bc::delay_millis( cTIMEOUT_MS );
|
bc::delay_millis( cTIMEOUT_MS );
|
||||||
@@ -156,7 +158,7 @@ retry:
|
|||||||
|
|
||||||
// message empfangen
|
// message empfangen
|
||||||
int err = ::CanReceive( 0, &msg, 1 );
|
int err = ::CanReceive( 0, &msg, 1 );
|
||||||
qDebug() << "HÄÄ ?" << err << "reg: "<< reg <<" timeOuts: " << timeOuts;
|
qDebug() << "HÄÄ ?" << err << "reg: "<< registerID <<" timeOuts: " << timeOuts;
|
||||||
|
|
||||||
if( err < 0 )
|
if( err < 0 )
|
||||||
//throw BCException( "getValue error: could not receive value" );
|
//throw BCException( "getValue error: could not receive value" );
|
||||||
@@ -167,7 +169,7 @@ retry:
|
|||||||
qDebug() << "HÄÄ 2" <<msg.MsgData[1];
|
qDebug() << "HÄÄ 2" <<msg.MsgData[1];
|
||||||
|
|
||||||
//if( err > 0 )
|
//if( err > 0 )
|
||||||
if( --retries && ( msg.Id != BIB || msg.MsgLen != 4 || msg.MsgData[1] != reg ) )
|
if( --retries && ( msg.Id != BIB || msg.MsgLen != 4 || msg.MsgData[1] != registerID ) )
|
||||||
goto retry;
|
goto retry;
|
||||||
|
|
||||||
if( !timeOuts )
|
if( !timeOuts )
|
||||||
@@ -179,7 +181,7 @@ retry:
|
|||||||
|
|
||||||
|
|
||||||
// void BCCanDriverTinyCan::setValue( unsigned char receipient, unsigned char reg, unsigned char value )
|
// void BCCanDriverTinyCan::setValue( unsigned char receipient, unsigned char reg, unsigned char value )
|
||||||
void BCCanDriverTinyCan::writeRawValue( BCDevice::ID deviceID, BC::ID registerID, uint8_t value ) const
|
void BCCanDriverTinyCan::writeRawByte( uint32_t deviceID, uint8_t registerID ,uint8_t value ) const
|
||||||
{
|
{
|
||||||
|
|
||||||
if( getState() != DriverState::Ready)
|
if( getState() != DriverState::Ready)
|
||||||
@@ -188,17 +190,15 @@ void BCCanDriverTinyCan::writeRawValue( BCDevice::ID deviceID, BC::ID registerID
|
|||||||
qDebug() << " --- BCCanDriverTinyCan writeRawValue: " << value;
|
qDebug() << " --- BCCanDriverTinyCan writeRawValue: " << value;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint32_t device = static_cast<uint32_t>(deviceID);
|
|
||||||
uint8_t reg = static_cast<uint8_t> (registerID);
|
|
||||||
|
|
||||||
struct TCanMsg msg;
|
struct TCanMsg msg;
|
||||||
int timeout_count = cTIMEOUT_COUNT;
|
int timeout_count = cTIMEOUT_COUNT;
|
||||||
|
|
||||||
msg.MsgFlags = 0L;
|
msg.MsgFlags = 0L;
|
||||||
msg.Id = device;
|
msg.Id = deviceID;
|
||||||
msg.MsgLen = 4;
|
msg.MsgLen = 4;
|
||||||
msg.MsgData[0] = 0x00;
|
msg.MsgData[0] = 0x00;
|
||||||
msg.MsgData[1] = reg;
|
msg.MsgData[1] = registerID;
|
||||||
msg.MsgData[2] = 0x00;
|
msg.MsgData[2] = 0x00;
|
||||||
msg.MsgData[3] = value;
|
msg.MsgData[3] = value;
|
||||||
|
|
||||||
@@ -208,7 +208,7 @@ void BCCanDriverTinyCan::writeRawValue( BCDevice::ID deviceID, BC::ID registerID
|
|||||||
bc::delay_millis( cTIMEOUT_MS );
|
bc::delay_millis( cTIMEOUT_MS );
|
||||||
|
|
||||||
if( timeout_count == -1 )
|
if( timeout_count == -1 )
|
||||||
emit statusHint( QString( "error: could not send value to %1" ).arg( device ) );
|
emit statusHint( QString( "error: could not send value to %1" ).arg( deviceID ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ public:
|
|||||||
DriverState loadDriver() override;
|
DriverState loadDriver() override;
|
||||||
DriverState initDriver() override;
|
DriverState initDriver() override;
|
||||||
|
|
||||||
uint32_t readRawValue ( BCDevice::ID deviceID, BC::ID registerID ) const override;
|
uint32_t readRawByte ( uint32_t deviceID, uint8_t registerID ) const override;
|
||||||
void writeRawValue( BCDevice::ID deviceID, BC::ID registerID, uint8_t value ) const override;
|
void writeRawByte( uint32_t deviceID, uint8_t registerID, uint8_t value ) const override;
|
||||||
|
|
||||||
QString getNodeName( unsigned char id );
|
QString getNodeName( unsigned char id );
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
|
|
||||||
#include <bcdatamanager.h>
|
#include <bcdatamanager.h>
|
||||||
|
#include <bcvaluetype.h>
|
||||||
|
|
||||||
using namespace Qt::StringLiterals;
|
using namespace Qt::StringLiterals;
|
||||||
|
|
||||||
@@ -47,10 +47,9 @@ using namespace Qt::StringLiterals;
|
|||||||
BCDataManager::BCDataManager(QObject *parent)
|
BCDataManager::BCDataManager(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
createValueTypes();
|
|
||||||
|
|
||||||
//qRegisterMetaType<BCDataItem*>("BCDataItem*");
|
//qRegisterMetaType<BCDataValue*>("BCDataValue*");
|
||||||
qRegisterMetaType<BCDataItem*>();
|
qRegisterMetaType<BCDataValue*>();
|
||||||
|
|
||||||
_transmitter.moveToThread(&_worker);
|
_transmitter.moveToThread(&_worker);
|
||||||
|
|
||||||
@@ -77,52 +76,6 @@ BCDataManager::~BCDataManager()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BCDataManager::createValueTypes()
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
Invalid = 0x0,
|
|
||||||
"Text"
|
|
||||||
"Number"
|
|
||||||
"Float"
|
|
||||||
"Percent"
|
|
||||||
"KWh"
|
|
||||||
"Watt"
|
|
||||||
"Km"
|
|
||||||
"Kmh"
|
|
||||||
"Mm"
|
|
||||||
"Sec"
|
|
||||||
"SoC"
|
|
||||||
"Odo"
|
|
||||||
"Date"
|
|
||||||
|
|
||||||
*/
|
|
||||||
//_dataTypes.insert( { BCDataType::TypeID::Invalid, "Invalid" } );
|
|
||||||
|
|
||||||
/*
|
|
||||||
_dataTypes.insert( "Invalid", { BCDataType::TypeID::Invalid, "Invalid" } );
|
|
||||||
_dataTypes.insert( "Text", { BCDataType::TypeID::Text } );
|
|
||||||
_dataTypes.insert( "Number", { BCDataType::TypeID::Number } );
|
|
||||||
|
|
||||||
_dataTypes.insert( "Byte", { BCDataType::TypeID::Byte } );
|
|
||||||
_dataTypes.insert( "Word", { BCDataType::TypeID::Word } );
|
|
||||||
_dataTypes.insert( "Quad", { BCDataType::TypeID::Quad } );
|
|
||||||
*/
|
|
||||||
|
|
||||||
_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 ODO{{ "km", 1.5625 }} );
|
|
||||||
_dataTypes.insert( "Kmh", new ODO{{ "km/h", 0.1 }} );
|
|
||||||
_dataTypes.insert( "Mm", new ODO{{ "mm", 1.5625 }} );
|
|
||||||
_dataTypes.insert( "Sec", new ODO{{ "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", { BCDataType::TypeID::Date } );
|
|
||||||
}
|
|
||||||
|
|
||||||
void BCDataManager::onCommandFinished(int id, bool success)
|
void BCDataManager::onCommandFinished(int id, bool success)
|
||||||
{
|
{
|
||||||
qDebug() << "[Manager] Command" << id << "finished. Success:" << success;
|
qDebug() << "[Manager] Command" << id << "finished. Success:" << success;
|
||||||
@@ -146,9 +99,9 @@ void BCDataManager::onSyncFromDevice()
|
|||||||
BCDataModel* model = _valueModels[_currentDeviceID];
|
BCDataModel* model = _valueModels[_currentDeviceID];
|
||||||
BCDataList& currentList = model->getValueList();
|
BCDataList& currentList = model->getValueList();
|
||||||
|
|
||||||
//BCDataItem& value = currentList[4];
|
//BCDataValue& value = currentList[4];
|
||||||
|
|
||||||
for( const BCDataItem& value : currentList )
|
for( const BCDataValue& value : currentList )
|
||||||
{
|
{
|
||||||
qDebug() << " --- value: " << value.label;
|
qDebug() << " --- value: " << value.label;
|
||||||
|
|
||||||
@@ -183,7 +136,7 @@ BCTransmitter* BCDataManager::getTransmitter()
|
|||||||
return &_transmitter;
|
return &_transmitter;
|
||||||
};
|
};
|
||||||
|
|
||||||
void BCDataManager::loadBikeData()
|
void BCDataManager::loadXmlBikeData()
|
||||||
{
|
{
|
||||||
auto printAttrs = [](const QXmlStreamReader& xml)
|
auto printAttrs = [](const QXmlStreamReader& xml)
|
||||||
{
|
{
|
||||||
@@ -234,7 +187,7 @@ void BCDataManager::loadBikeData()
|
|||||||
|
|
||||||
_currentDeviceID = BCDevice::ID( deviceID.value() );
|
_currentDeviceID = BCDevice::ID( deviceID.value() );
|
||||||
BCDataList parsedValues;
|
BCDataList parsedValues;
|
||||||
loadDeviceData( parsedValues );
|
loadXmlBikeDeviceData( parsedValues );
|
||||||
if( parsedValues.count() )
|
if( parsedValues.count() )
|
||||||
{
|
{
|
||||||
BCDataModel* valueModel = new BCDataModel( this );
|
BCDataModel* valueModel = new BCDataModel( this );
|
||||||
@@ -263,7 +216,7 @@ void BCDataManager::loadBikeData()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BCDataManager::loadDeviceData( BCDataList& parsedValues )
|
void BCDataManager::loadXmlBikeDeviceData( BCDataList& parsedValues )
|
||||||
{
|
{
|
||||||
auto printAttrs = [](const QXmlStreamReader& xml)
|
auto printAttrs = [](const QXmlStreamReader& xml)
|
||||||
{
|
{
|
||||||
@@ -296,10 +249,10 @@ void BCDataManager::loadDeviceData( BCDataList& parsedValues )
|
|||||||
};
|
};
|
||||||
|
|
||||||
// __fix! können ungültige werte erzeugt werden ?
|
// __fix! können ungültige werte erzeugt werden ?
|
||||||
//BCDataItem newValue = BCData::makeDataItem( _currentDeviceID, params );
|
//BCDataValue newValue = BCData::makeDataValue( _currentDeviceID, params );
|
||||||
//if(newValue)
|
//if(newValue)
|
||||||
// parsedValues.push_back( newValue );
|
// parsedValues.push_back( newValue );
|
||||||
std::optional<BCDataItem> newValue = makeDataItem( _currentDeviceID, params );
|
std::optional<BCDataValue> newValue = makeDataValue( _currentDeviceID, params );
|
||||||
if(newValue)
|
if(newValue)
|
||||||
parsedValues.push_back( *newValue );
|
parsedValues.push_back( *newValue );
|
||||||
}
|
}
|
||||||
@@ -309,7 +262,7 @@ void BCDataManager::loadDeviceData( BCDataList& parsedValues )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<BCDataItem> BCDataManager::makeDataItem( BCDevice::ID deviceID, const BCDataParams& params )
|
std::optional<BCDataValue> BCDataManager::makeDataValue( BCDevice::ID deviceID, const BCDataParams& params )
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -327,6 +280,39 @@ std::optional<BCDataItem> BCDataManager::makeDataItem( BCDevice::ID deviceID, co
|
|||||||
|
|
||||||
static QMetaEnum s_bcValueEnum{QMetaEnum::fromType<BC::ID>()};
|
static QMetaEnum s_bcValueEnum{QMetaEnum::fromType<BC::ID>()};
|
||||||
|
|
||||||
|
static BCValueTypeMap s_bcDataTypes
|
||||||
|
{
|
||||||
|
{ "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 ) },
|
||||||
|
{ "SoC", new BCValueTypeWord( "%", 1.5625 ) },
|
||||||
|
{ "Odo", new BCValueTypeWord( "km", 1.5625 ) },
|
||||||
|
{ "Assist", new BCValueTypeWord( "", 0 ,4 ) },
|
||||||
|
{ "Assist", new BCValueTypeWord( "%" ) },
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
_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 } );
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Wir brauchen:
|
Wir brauchen:
|
||||||
- einen gültige ID String um die enum ID herauszufinden.
|
- einen gültige ID String um die enum ID herauszufinden.
|
||||||
@@ -334,16 +320,16 @@ std::optional<BCDataItem> BCDataManager::makeDataItem( BCDevice::ID deviceID, co
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
std::optional<BCDataItem> newValue;
|
std::optional<BCDataValue> newValue;
|
||||||
|
|
||||||
std::optional<quint64> IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() );
|
std::optional<quint64> IDVal = s_bcValueEnum.keyToValue64( params.ID.toLatin1().constData() );
|
||||||
if( IDVal.has_value() )
|
if( IDVal.has_value() )
|
||||||
{
|
{
|
||||||
if( _dataTypes.contains( params.UnitType ) )
|
if( s_bcDataTypes.contains( params.UnitType ) )
|
||||||
{
|
{
|
||||||
|
|
||||||
const BCDataType& valueType = *_dataTypes[params.UnitType];
|
const BCValueType* valueType = s_bcDataTypes[params.UnitType];
|
||||||
newValue = BCDataItem( valueType, deviceID, static_cast<BC::ID>(IDVal.value()) );
|
newValue = BCDataValue( valueType, deviceID, static_cast<BC::ID>(IDVal.value()) );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
setIfExists( params.Factor, newValue.factor );
|
setIfExists( params.Factor, newValue.factor );
|
||||||
|
|||||||
@@ -58,15 +58,15 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void loadBikeData();
|
void loadXmlBikeData();
|
||||||
void saveBikeData();
|
void saveBikeData();
|
||||||
void onSyncFromDevice();
|
void onSyncFromDevice();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
// Internes Signal, um Daten an den Worker Thread zu senden
|
// Internes Signal, um Daten an den Worker Thread zu senden
|
||||||
void sendValueCommand( BC::OpID, const BCDataItem* cmd);
|
void sendValueCommand( BC::OpID, const BCDataValue* cmd);
|
||||||
//void valuedTouched(const BCDataItem& cmd);
|
//void valuedTouched(const BCDataValue& cmd);
|
||||||
void valueTouched(int rowInModel );
|
void valueTouched(int rowInModel );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
@@ -85,16 +85,15 @@ protected:
|
|||||||
QString UnitType;
|
QString UnitType;
|
||||||
};
|
};
|
||||||
|
|
||||||
void createValueTypes();
|
void loadXmlBikeDeviceData( BCDataList& parsedValues );
|
||||||
void loadDeviceData( BCDataList& parsedValues );
|
|
||||||
|
|
||||||
std::optional<BCDataItem> makeDataItem( BCDevice::ID deviceID, const BCDataParams& params );
|
std::optional<BCDataValue> makeDataValue( BCDevice::ID deviceID, const BCDataParams& params );
|
||||||
|
|
||||||
using BCDeviceModels = QMap<BCDevice::ID, BCDataModel*>;
|
using BCDeviceModels = QMap<BCDevice::ID, BCDataModel*>;
|
||||||
using BCDataTypes = QMap<QString,BCDataType*>;
|
using BCValueTypeMap = QMap<QString,BCValueType*>;
|
||||||
|
|
||||||
QXmlStreamReader _xml;
|
QXmlStreamReader _xml;
|
||||||
BCDataTypes _dataTypes;
|
|
||||||
BCDeviceModels _valueModels;
|
BCDeviceModels _valueModels;
|
||||||
BCDevice::ID _currentDeviceID{BCDevice::ID::Invalid};
|
BCDevice::ID _currentDeviceID{BCDevice::ID::Invalid};
|
||||||
QMetaEnum _bcDeviceEnum{QMetaEnum::fromType<BCDevice::ID>()};
|
QMetaEnum _bcDeviceEnum{QMetaEnum::fromType<BCDevice::ID>()};
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
BCDataModel::BCDataModel(QObject *parent) : QAbstractListModel(parent) {}
|
BCDataModel::BCDataModel(QObject *parent) : QAbstractListModel(parent) {}
|
||||||
|
|
||||||
void BCDataModel::addValue(const BCDataItem& val)
|
void BCDataModel::addValue(const BCDataValue& val)
|
||||||
{
|
{
|
||||||
int row = _valueList.size();
|
int row = _valueList.size();
|
||||||
beginInsertRows(QModelIndex(), row, row);
|
beginInsertRows(QModelIndex(), row, row);
|
||||||
@@ -68,11 +68,11 @@ QVariant BCDataModel::data(const QModelIndex& index, int role) const
|
|||||||
if (!index.isValid() || row >= _valueList.size())
|
if (!index.isValid() || row >= _valueList.size())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
BCDataItem& entry = const_cast<BCDataItem&>(_valueList.at( row ));
|
BCDataValue& entry = const_cast<BCDataValue&>(_valueList.at( row ));
|
||||||
entry.rowInModel = row;
|
entry.rowInModel = row;
|
||||||
|
|
||||||
if (role == Qt::DisplayRole || role == Qt::EditRole)
|
if (role == Qt::DisplayRole || role == Qt::EditRole)
|
||||||
return entry.value;
|
return entry.visibleValue;
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
@@ -91,13 +91,13 @@ bool BCDataModel::setData(const QModelIndex& index, const QVariant& value, int r
|
|||||||
{
|
{
|
||||||
if (index.isValid() && role == Qt::EditRole)
|
if (index.isValid() && role == Qt::EditRole)
|
||||||
{
|
{
|
||||||
BCDataItem item = _valueList[index.row()];
|
BCDataValue item = _valueList[index.row()];
|
||||||
|
|
||||||
// Wir erwarten hier nur den Value-Teil (vom Slider/Editor)
|
// Wir erwarten hier nur den Value-Teil (vom Slider/Editor)
|
||||||
// Checken ob Int oder Double
|
// Checken ob Int oder Double
|
||||||
if (value.canConvert<double>())
|
if (value.canConvert<double>())
|
||||||
{
|
{
|
||||||
item.value = value;
|
item.visibleValue = value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
_valueList[index.row()] = item;
|
_valueList[index.row()] = item;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#include <QAbstractTableModel>
|
#include <QAbstractTableModel>
|
||||||
|
|
||||||
#include <bcdataitem.h>
|
#include <bcdatavalue.h>
|
||||||
|
|
||||||
|
|
||||||
class BCDataModel : public QAbstractListModel
|
class BCDataModel : public QAbstractListModel
|
||||||
@@ -44,7 +44,7 @@ public:
|
|||||||
|
|
||||||
explicit BCDataModel(QObject *parent = nullptr);
|
explicit BCDataModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
void addValue(const BCDataItem& val);
|
void addValue(const BCDataValue& val);
|
||||||
void setValueList(const BCDataList& valueList);
|
void setValueList(const BCDataList& valueList);
|
||||||
BCDataList& getValueList();
|
BCDataList& getValueList();
|
||||||
|
|
||||||
|
|||||||
@@ -29,52 +29,32 @@
|
|||||||
|
|
||||||
#include <QMetaEnum>
|
#include <QMetaEnum>
|
||||||
|
|
||||||
|
#include <bcdatavalue.h>
|
||||||
#include <bcdataitem.h>
|
#include <bcvaluetype.h>
|
||||||
|
|
||||||
BCDataType::BCDataType()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
BCDataType::BCDataType( QString unitLabel_, double factor_, optDouble min_, optDouble max_ )
|
|
||||||
: unitLabel{unitLabel_}, factor{factor_}, min{min_}, max{max_}
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
double BCDataType::readValue( const BCAbstractTransmitter& transmitter )
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BCDataType::writeValue( const BCAbstractTransmitter& transmitter )
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
///-------------------------------
|
///-------------------------------
|
||||||
|
|
||||||
|
|
||||||
BCDataItem::BCDataItem(const BCDataType* valueType_, BCDevice::ID deviceID_, BC::ID registerID_)
|
BCDataValue::BCDataValue(const BCValueType* valueType_, BCDevice::ID deviceID_, BC::ID registerID_)
|
||||||
: valueType{valueType_}, deviceID{deviceID_}, registerID{registerID_}
|
: valueType{valueType_}, deviceID{deviceID_}, registerID{registerID_}
|
||||||
{
|
{
|
||||||
value = "--";
|
visibleValue = "--";
|
||||||
}
|
}
|
||||||
|
|
||||||
void BCDataItem::readRawValueX( const BCAbstractTransmitter& transmitter ) const
|
void BCDataValue::readRawValueX( const BCAbstractTransmitter& transmitter ) const
|
||||||
{
|
{
|
||||||
qDebug() << " --- READ X!";
|
qDebug() << " --- READ X!";
|
||||||
//uint32_t rawValue = transmitter.readRawValue( deviceID, registerID );
|
|
||||||
|
|
||||||
//const BCDataType& xxx = valueType.value().get();
|
uint32_t devID = static_cast<uint32_t>(deviceID);
|
||||||
|
uint8_t regID = static_cast<uint8_t> (registerID);
|
||||||
|
|
||||||
|
visibleValue = valueType->createStringValue( transmitter, devID, regID );
|
||||||
|
|
||||||
//uint32_t result = std::visit( myVisi, BCTypeVariant{valueType} );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BCDataItem::writeRawValueX( const BCAbstractTransmitter& transmitter ) const
|
void BCDataValue::writeRawValueX( const BCAbstractTransmitter& transmitter ) const
|
||||||
{
|
{
|
||||||
|
qDebug() << " --- WRITE X!";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
103
bcdatavalue.h
103
bcdatavalue.h
@@ -28,8 +28,8 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#ifndef BCDATAITEM_H
|
#ifndef BCDATAVALUE_H
|
||||||
#define BCDATAITEM_H
|
#define BCDATAVALUE_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
@@ -41,9 +41,9 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Werte haben verschiedene Längen (1,2 und 4 Byte) und werder auf unterschiedliche Art und Weise
|
Werte haben verschiedene Längen (1,2 und 4 Byte) und werder auf unterschiedliche Art und Weise
|
||||||
ausgelesen und geschrieben (Siehe ODO). Sin können also Wert-Typen zugeordnet werden. Ein Werttyp
|
ausgelesen und geschrieben (Siehe BCValueTypeWord). Sin können also Wert-Typen zugeordnet werden. Ein Werttyp
|
||||||
lässet über eine ID identifizieren, die mit der phyikalische Einheit des Wertes überschneiden kann,
|
lässet über eine ID identifizieren, die mit der phyikalische Einheit des Wertes überschneiden kann,
|
||||||
aber nicht muss: : Km/h, kWh, ODO ... bilden eigene Typen, SoC, Assistence Level sind auch eigene Typen,
|
aber nicht muss: : Km/h, kWh, BCValueTypeWord ... bilden eigene Typen, SoC, Assistence Level sind auch eigene Typen,
|
||||||
Teilen sich jedoch die Einheit '%'.
|
Teilen sich jedoch die Einheit '%'.
|
||||||
|
|
||||||
Das ist natürlich annalog zu den ItemTypes:
|
Das ist natürlich annalog zu den ItemTypes:
|
||||||
@@ -60,115 +60,46 @@ class BCAbstractTransmitter
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//
|
virtual uint32_t readRawByte( uint32_t deviceID, uint8_t registerID ) const = 0;
|
||||||
virtual uint32_t readRawValue( BCDevice::ID deviceID_, BC::ID registerID_ ) const = 0;
|
virtual void writeRawByte( uint32_t deviceID, uint8_t registerID , uint8_t value_ ) const = 0;
|
||||||
virtual void writeRawValue( BCDevice::ID deviceID_, BC::ID registerID_, uint8_t value_ ) const = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class BCDataItem;
|
class BCValueType;
|
||||||
|
|
||||||
using optDouble = std::optional<double>;
|
class BCDataValue
|
||||||
|
|
||||||
struct BCDataType
|
|
||||||
{
|
|
||||||
|
|
||||||
Q_GADGET
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
BCDataType();
|
|
||||||
BCDataType( QString unitLabel_, double factor_= 1.0, optDouble min_=std::nullopt, optDouble max_= std::nullopt );
|
|
||||||
|
|
||||||
QString unitLabel;
|
|
||||||
double factor;
|
|
||||||
optDouble min;
|
|
||||||
optDouble max;
|
|
||||||
|
|
||||||
virtual double readValue( const BCAbstractTransmitter& transmitter ) = 0;
|
|
||||||
virtual void writeValue( const BCAbstractTransmitter& transmitter ) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct BCDataTypeByte : public BCDataType
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
double readValue( const BCAbstractTransmitter& transmitter, const BCDA ) override
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void writeValue( const BCAbstractTransmitter& transmitter ) override;
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ODO : public BCDataType
|
|
||||||
{
|
|
||||||
double readValue( const BCAbstractTransmitter& transmitter ) override
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void writeValue( const BCAbstractTransmitter& transmitter ) override;
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Long : public BCDataType
|
|
||||||
{};
|
|
||||||
|
|
||||||
struct Fitz : public BCDataType
|
|
||||||
{};
|
|
||||||
|
|
||||||
struct Fatz : public BCDataType
|
|
||||||
{};
|
|
||||||
|
|
||||||
using BCTypeVariant = std::variant<BCDataType,ODO,Long,Fitz,Fatz>;
|
|
||||||
|
|
||||||
// really needed?
|
|
||||||
//using BCDataTypeCRef = std::optional<std::reference_wrapper<const BCTypeVariant>>;
|
|
||||||
|
|
||||||
|
|
||||||
class BCDataItem
|
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
BCDataItem( const BCDataType* valueType_, BCDevice::ID deviceID_, BC::ID registerID_ );
|
BCDataValue( const BCValueType* valueType_, BCDevice::ID deviceID_, BC::ID registerID_ );
|
||||||
|
|
||||||
void readRawValueX( const BCAbstractTransmitter& transmitter ) const;
|
void readRawValueX( const BCAbstractTransmitter& transmitter ) const;
|
||||||
void writeRawValueX( const BCAbstractTransmitter& transmitter ) const;
|
void writeRawValueX( const BCAbstractTransmitter& transmitter ) const;
|
||||||
// void reset()
|
// void reset()
|
||||||
|
|
||||||
//const BCDataType& valueType;
|
//const BCValueType& valueType;
|
||||||
//BCDataTypeCRef valueType;
|
//BCValueTypeCRef valueType;
|
||||||
const BCDataType* valueType{};
|
const BCValueType* valueType{};
|
||||||
BCDevice::ID deviceID{BCDevice::ID::Invalid};
|
BCDevice::ID deviceID{BCDevice::ID::Invalid};
|
||||||
BC::ID registerID{BC::ID::Invalid};
|
BC::ID registerID{BC::ID::Invalid};
|
||||||
int rowInModel{-1};
|
int rowInModel{-1};
|
||||||
QString label;
|
QString label;
|
||||||
QVariant value;
|
mutable QString visibleValue;
|
||||||
QVariant defaultValue;
|
QVariant defaultValue;
|
||||||
|
|
||||||
bool inSync{false};
|
bool inSync{false};
|
||||||
bool readOnly{false};
|
bool readOnly{false};
|
||||||
|
|
||||||
mutable std::optional<uint32_t> rawValue;
|
//mutable std::optional<uint32_t> rawValue;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
Q_DECLARE_METATYPE(BCDataItem*)
|
Q_DECLARE_METATYPE(BCDataValue*)
|
||||||
|
|
||||||
|
|
||||||
using BCDataList = QVector<BCDataItem>;
|
using BCDataList = QVector<BCDataValue>;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -192,4 +123,4 @@ constexpr auto to_u(E e) noexcept {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // BCDATAITEM_H
|
#endif // BCDATAVALUE_H
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
#include "bcitemdelegate.h"
|
#include "bcitemdelegate.h"
|
||||||
#include "bcdataitem.h"
|
#include "bcdatavalue.h"
|
||||||
#include "qapplication.h"
|
#include "qapplication.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -27,14 +27,14 @@ BCItemDelegate::BCItemDelegate(QListView *view)
|
|||||||
QString BCItemDelegate::displayText(const QVariant& dataValue, const QLocale& locale) const
|
QString BCItemDelegate::displayText(const QVariant& dataValue, const QLocale& locale) const
|
||||||
{
|
{
|
||||||
// Wir prüfen, ob im Variant unser Struct steckt
|
// Wir prüfen, ob im Variant unser Struct steckt
|
||||||
if (dataValue.canConvert<BCDataItem*>())
|
if (dataValue.canConvert<BCDataValue*>())
|
||||||
{
|
{
|
||||||
BCDataItem& bc = *dataValue.value<BCDataItem*>();
|
BCDataValue& bc = *dataValue.value<BCDataValue*>();
|
||||||
qDebug() << " --- YES: " << bc.label;
|
qDebug() << " --- YES: " << bc.label;
|
||||||
// Hier bauen wir den String zusammen, den man sieht,
|
// Hier bauen wir den String zusammen, den man sieht,
|
||||||
// wenn KEIN Editor offen ist.
|
// wenn KEIN Editor offen ist.
|
||||||
// Format: "Label: Wert Einheit"
|
// Format: "Label: Wert Einheit"
|
||||||
return QString("%1: %2 %3").arg(bc.label, bc.value.toString(), "mmX");
|
return QString("%1: %2 %3").arg(bc.label, bc.visibleValue, "mmX");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -49,10 +49,10 @@ QString BCItemDelegate::displayText(const QVariant& dataValue, const QLocale& lo
|
|||||||
QWidget *BCItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const
|
QWidget *BCItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
QVariant rawData = index.data(Qt::EditRole);
|
QVariant rawData = index.data(Qt::EditRole);
|
||||||
if (!rawData.canConvert<BCDataItem*>())
|
//if (!rawData.canConvert<BCDataValue*>())
|
||||||
return QStyledItemDelegate::createEditor(parent, option, index);
|
return QStyledItemDelegate::createEditor(parent, option, index);
|
||||||
|
/*
|
||||||
const BCDataItem& bc = *rawData.value<BCDataItem*>();
|
const BCDataValue& bc = *rawData.value<BCDataValue*>();
|
||||||
|
|
||||||
// Nur bei Integern den Slider-Editor bauen
|
// Nur bei Integern den Slider-Editor bauen
|
||||||
if (bc.value.typeId() == QMetaType::Int)
|
if (bc.value.typeId() == QMetaType::Int)
|
||||||
@@ -89,25 +89,27 @@ QWidget *BCItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewIte
|
|||||||
});
|
});
|
||||||
|
|
||||||
return container;
|
return container;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return QStyledItemDelegate::createEditor(parent, option, index);
|
return QStyledItemDelegate::createEditor(parent, option, index);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void BCItemDelegate::setEditorData(QWidget *editor, const QModelIndex& index) const
|
void BCItemDelegate::setEditorData(QWidget *editor, const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
// Daten vom Model in den Editor laden
|
// Daten vom Model in den Editor laden
|
||||||
const BCDataItem& bc = *index.data(Qt::EditRole).value<BCDataItem*>();
|
const BCDataValue& bc = *index.data(Qt::EditRole).value<BCDataValue*>();
|
||||||
|
|
||||||
QSlider *slider = editor->findChild<QSlider*>("slider");
|
QSlider *slider = editor->findChild<QSlider*>("slider");
|
||||||
QLabel *lblUnit = editor->findChild<QLabel*>("lblUnit");
|
QLabel *lblUnit = editor->findChild<QLabel*>("lblUnit");
|
||||||
|
|
||||||
if (slider && lblUnit) {
|
if (slider && lblUnit) {
|
||||||
bool olDriverState = slider->blockSignals(true);
|
bool olDriverState = slider->blockSignals(true);
|
||||||
slider->setValue(bc.value.toInt());
|
slider->setValue(bc.visibleValue.toInt());
|
||||||
slider->blockSignals(olDriverState);
|
slider->blockSignals(olDriverState);
|
||||||
|
|
||||||
lblUnit->setText(QString("%1 %2").arg(bc.value.toInt()).arg( "mm3"));
|
lblUnit->setText(QString("%1 %2").arg(bc.visibleValue.toInt()).arg( "mm3"));
|
||||||
} else {
|
} else {
|
||||||
QStyledItemDelegate::setEditorData(editor, index);
|
QStyledItemDelegate::setEditorData(editor, index);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ BCMainWindow::BCMainWindow(QWidget *parent)
|
|||||||
|
|
||||||
_motorlButton->setDefaultAction( _actionMotor);
|
_motorlButton->setDefaultAction( _actionMotor);
|
||||||
|
|
||||||
_valueManager.loadBikeData();
|
_valueManager.loadXmlBikeData();
|
||||||
auto model = _valueManager.getModel( BCDevice::ID::Console );
|
auto model = _valueManager.getModel( BCDevice::ID::Console );
|
||||||
if( model)
|
if( model)
|
||||||
_valueView->setModel( *model );
|
_valueView->setModel( *model );
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ void BCTransmitter::onToggleConnectionState( bool connect )
|
|||||||
if( _canDriver.getState() != BCCanDriver::DriverState::Ready )
|
if( _canDriver.getState() != BCCanDriver::DriverState::Ready )
|
||||||
_canDriver.onStartDriver();
|
_canDriver.onStartDriver();
|
||||||
|
|
||||||
uint32_t hwVersion = _canDriver.readRawValue( BCDevice::ID::Console, BC::ID::Cons_Rev_Hw);
|
// fix!
|
||||||
|
uint32_t hwVersion = _canDriver.readRawByte( (uint32_t)BCDevice::ID::Console, (uint8_t)BC::ID::Cons_Rev_Hw);
|
||||||
|
|
||||||
if(!hwVersion)
|
if(!hwVersion)
|
||||||
{
|
{
|
||||||
@@ -50,7 +51,7 @@ void BCTransmitter::onToggleConnectionState( bool connect )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BCTransmitter::enqueueValueOp(BC::OpID opID, const BCDataItem* value)
|
void BCTransmitter::enqueueValueOp(BC::OpID opID, const BCDataValue* value)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&_mutex);
|
QMutexLocker locker(&_mutex);
|
||||||
_valueQueue.enqueue( value );
|
_valueQueue.enqueue( value );
|
||||||
@@ -83,7 +84,7 @@ void BCTransmitter::processValueOp( BC::OpID opID )
|
|||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
const BCDataItem* currentValue{};
|
const BCDataValue* currentValue{};
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&_mutex);
|
QMutexLocker locker(&_mutex);
|
||||||
if (_valueQueue.isEmpty())
|
if (_valueQueue.isEmpty())
|
||||||
@@ -106,11 +107,11 @@ void BCTransmitter::processValueOp( BC::OpID opID )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t BCTransmitter::readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const
|
uint32_t BCTransmitter::readRawByte( uint32_t deviceID, uint8_t registerID ) const
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return _canDriver.readRawValue( deviceID, registerID );
|
return _canDriver.readRawByte( deviceID, registerID );
|
||||||
}
|
}
|
||||||
catch ( BCException& exception )
|
catch ( BCException& exception )
|
||||||
{
|
{
|
||||||
@@ -119,11 +120,11 @@ uint32_t BCTransmitter::readRawValue( BCDevice::ID deviceID, BC::ID registerID )
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BCTransmitter::writeRawValue( BCDevice::ID deviceID, BC::ID registerID, uint8_t value ) const
|
void BCTransmitter::writeRawByte( uint32_t deviceID, uint8_t registerID , uint8_t value ) const
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_canDriver.writeRawValue( deviceID, registerID, value );
|
_canDriver.writeRawByte( deviceID, registerID, value );
|
||||||
}
|
}
|
||||||
catch ( BCException& exception )
|
catch ( BCException& exception )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
#include <bcdataitem.h>
|
#include <bcdatavalue.h>
|
||||||
#include <bccandrivertinycan.h>
|
#include <bccandrivertinycan.h>
|
||||||
|
|
||||||
// template ...
|
// template ...
|
||||||
@@ -18,13 +18,13 @@ public:
|
|||||||
|
|
||||||
explicit BCTransmitter(QObject *parent = nullptr);
|
explicit BCTransmitter(QObject *parent = nullptr);
|
||||||
|
|
||||||
uint32_t readRawValue( BCDevice::ID deviceID, BC::ID registerID ) const override;
|
uint32_t readRawByte( uint32_t deviceID, uint8_t registerID ) const override;
|
||||||
void writeRawValue(BCDevice::ID deviceID, BC::ID registerID, uint8_t value ) const override;
|
void writeRawByte( uint32_t deviceID, uint8_t registerID, uint8_t value ) const override;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void onToggleConnectionState( bool connect );
|
void onToggleConnectionState( bool connect );
|
||||||
void enqueueValueOp(BC::OpID opID, const BCDataItem* value );
|
void enqueueValueOp(BC::OpID opID, const BCDataValue* value );
|
||||||
void processValueOp(BC::OpID opID);
|
void processValueOp(BC::OpID opID);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@@ -34,7 +34,7 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
using BCDataQueue = QQueue<const BCDataItem*>;
|
using BCDataQueue = QQueue<const BCDataValue*>;
|
||||||
|
|
||||||
BCDataQueue _valueQueue;
|
BCDataQueue _valueQueue;
|
||||||
QMutex _mutex;
|
QMutex _mutex;
|
||||||
|
|||||||
6
main.cpp
6
main.cpp
@@ -40,7 +40,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include <bcmainwindow.h>
|
#include <bcmainwindow.h>
|
||||||
#include <bcdataitem.h>
|
#include <bcdatavalue.h>
|
||||||
#include <bcdatamanager.h>
|
#include <bcdatamanager.h>
|
||||||
|
|
||||||
#include <variant>
|
#include <variant>
|
||||||
@@ -149,9 +149,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
mookoo myMookoo{"",1,1.0};
|
mookoo myMookoo{"",1,1.0};
|
||||||
mookoo myMooko2{"",1};
|
mookoo myMooko2{"",1};
|
||||||
mookoo2 myMooko3{{"superfitze",1},8};
|
mookoo2* myMooko3 = new mookoo2{{"superfitze",1},8};
|
||||||
|
|
||||||
qDebug() << " --- haha: " << myMooko3.a << ": " << myMooko3.hidden;
|
qDebug() << " --- haha: " << myMooko3->a << ": " << myMooko3->hidden;
|
||||||
|
|
||||||
BCMainWindow w;
|
BCMainWindow w;
|
||||||
w.show();
|
w.show();
|
||||||
|
|||||||
@@ -40,10 +40,10 @@
|
|||||||
|
|
||||||
<!--
|
<!--
|
||||||
printf( " odo .....................: Percent0.2f Km" _NL _NL,
|
printf( " odo .....................: Percent0.2f Km" _NL _NL,
|
||||||
((getValue(CONSOLE, CONSOLE_STATS_ODO_1) << 24) +
|
((getValue(CONSOLE, CONSOLE_STATS_BCValueTypeWord_1) << 24) +
|
||||||
(getValue(CONSOLE, CONSOLE_STATS_ODO_2) << 16) +
|
(getValue(CONSOLE, CONSOLE_STATS_BCValueTypeWord_2) << 16) +
|
||||||
(getValue(CONSOLE, CONSOLE_STATS_ODO_3) << 8) +
|
(getValue(CONSOLE, CONSOLE_STATS_BCValueTypeWord_3) << 8) +
|
||||||
(getValue(CONSOLE, CONSOLE_STATS_ODO_4))) / (double)10
|
(getValue(CONSOLE, CONSOLE_STATS_BCValueTypeWord_4))) / (double)10
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user