Clean up data types.
This commit is contained in:
2
bc.h
2
bc.h
@@ -748,7 +748,7 @@ public:
|
|||||||
enum class ID : uint8_t
|
enum class ID : uint8_t
|
||||||
{
|
{
|
||||||
Invalid = 0,
|
Invalid = 0,
|
||||||
Console = uint8_t( BC::ID::ID_Console_Slave ),
|
Console = static_cast<uint8_t>( BC::ID::ID_Console_Slave ),
|
||||||
Console_Master = uint8_t( BC::ID::ID_Console_Master),
|
Console_Master = uint8_t( BC::ID::ID_Console_Master),
|
||||||
Battery = uint8_t( BC::ID::ID_Battery),
|
Battery = uint8_t( BC::ID::ID_Battery),
|
||||||
Motor = uint8_t( BC::ID::ID_Motor ),
|
Motor = uint8_t( BC::ID::ID_Motor ),
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ uint BCCanDriverTinyCan::getValue(BCDevice::ID deviceID, BC::ID registerID ) con
|
|||||||
struct TCanMsg msg;
|
struct TCanMsg msg;
|
||||||
|
|
||||||
uint32_t device = static_cast<uint32_t>(deviceID);
|
uint32_t device = static_cast<uint32_t>(deviceID);
|
||||||
uint32_t reg = static_cast<uint32_t>(registerID);
|
uint8_t reg = static_cast<uint8_t> (registerID);
|
||||||
|
|
||||||
// msg verpacken
|
// msg verpacken
|
||||||
msg.MsgFlags = 0L;
|
msg.MsgFlags = 0L;
|
||||||
@@ -128,9 +128,9 @@ uint BCCanDriverTinyCan::getValue(BCDevice::ID deviceID, BC::ID registerID ) con
|
|||||||
// msg verschicken
|
// msg verschicken
|
||||||
::CanTransmit( 0, &msg, 1 );
|
::CanTransmit( 0, &msg, 1 );
|
||||||
|
|
||||||
int retries = _retries;
|
int retries = _retries; // 5?
|
||||||
// _timeOuts (== 20) mal cTIMEOUT_MS (== 10 ms ) Versuche ...
|
// _timeOuts (== 20) mal cTIMEOUT_MS (== 10 ms ) Versuche ...
|
||||||
int timeOuts = _timeOuts;
|
int timeOuts = _timeOuts; // 20 ?
|
||||||
|
|
||||||
// ... warten bis der Sendepuffer leer ist
|
// ... warten bis der Sendepuffer leer ist
|
||||||
while( timeOuts-- && ::CanTransmitGetCount( 0 ) )
|
while( timeOuts-- && ::CanTransmitGetCount( 0 ) )
|
||||||
@@ -170,7 +170,7 @@ retry:
|
|||||||
throw std::runtime_error( "CAN --response errror" );
|
throw std::runtime_error( "CAN --response errror" );
|
||||||
|
|
||||||
return (unsigned int) msg.MsgData[3];
|
return (unsigned int) msg.MsgData[3];
|
||||||
|
//das ist mist!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -181,7 +181,7 @@ void BCCanDriverTinyCan::setValue(BCDevice::ID deviceID, BC::ID registerID, int
|
|||||||
qDebug() << "SaveItem( BCCanDriverTinyCan::CBCItem& item ): ";
|
qDebug() << "SaveItem( BCCanDriverTinyCan::CBCItem& item ): ";
|
||||||
|
|
||||||
uint32_t device = static_cast<uint32_t>(deviceID);
|
uint32_t device = static_cast<uint32_t>(deviceID);
|
||||||
uint32_t reg = static_cast<uint32_t>(registerID);
|
uint8_t reg = static_cast<uint8_t> (registerID);
|
||||||
|
|
||||||
struct TCanMsg msg;
|
struct TCanMsg msg;
|
||||||
int timeout_count = cTIMEOUT_COUNT;
|
int timeout_count = cTIMEOUT_COUNT;
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ 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<BCValue>())
|
if (dataValue.canConvert<BCValue*>())
|
||||||
{
|
{
|
||||||
BCValue bc = dataValue.value<BCValue>();
|
BCValue& bc = *dataValue.value<BCValue*>();
|
||||||
//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.
|
||||||
@@ -45,10 +45,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<BCValue>())
|
if (!rawData.canConvert<BCValue*>())
|
||||||
return QStyledItemDelegate::createEditor(parent, option, index);
|
return QStyledItemDelegate::createEditor(parent, option, index);
|
||||||
|
|
||||||
BCValue bc = rawData.value<BCValue>();
|
const BCValue& bc = *rawData.value<BCValue*>();
|
||||||
|
|
||||||
// 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)
|
||||||
@@ -93,7 +93,7 @@ QWidget *BCItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewIte
|
|||||||
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
|
||||||
BCValue bc = index.data(Qt::EditRole).value<BCValue>();
|
const BCValue& bc = *index.data(Qt::EditRole).value<BCValue*>();
|
||||||
|
|
||||||
QSlider *slider = editor->findChild<QSlider*>("slider");
|
QSlider *slider = editor->findChild<QSlider*>("slider");
|
||||||
QLabel *lblUnit = editor->findChild<QLabel*>("lblUnit");
|
QLabel *lblUnit = editor->findChild<QLabel*>("lblUnit");
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ void BCTransmitter::processValueOp( BC::OpID opID )
|
|||||||
currentValue =_valueQueue.dequeue();
|
currentValue =_valueQueue.dequeue();
|
||||||
} // Mutex wird hier freigegeben! WICHTIG: Execute ohne Lock!
|
} // Mutex wird hier freigegeben! WICHTIG: Execute ohne Lock!
|
||||||
|
|
||||||
std::optional<uint32_t> result;
|
std::optional<bcdata_t> result;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if( opID == BC::OpID::ReadValue )
|
if( opID == BC::OpID::ReadValue )
|
||||||
@@ -107,7 +107,7 @@ void BCTransmitter::processValueOp( BC::OpID opID )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<uint32_t> BCTransmitter::executeRead(const BCValue& value)
|
std::optional<bcdata_t> BCTransmitter::executeRead(const BCValue& value)
|
||||||
{
|
{
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -128,7 +128,7 @@ std::optional<uint32_t> BCTransmitter::executeRead(const BCValue& value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::optional<uint32_t> BCTransmitter::executeWrite(const BCValue& value)
|
std::optional<bcdata_t> BCTransmitter::executeWrite(const BCValue& value)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::optional<uint32_t> executeRead(const BCValue& value);
|
std::optional<bcdata_t> executeRead(const BCValue& value);
|
||||||
std::optional<uint32_t> executeWrite(const BCValue& value);
|
std::optional<bcdata_t> executeWrite(const BCValue& value);
|
||||||
|
|
||||||
using BCValueQueue = QQueue<const BCValue*>;
|
using BCValueQueue = QQueue<const BCValue*>;
|
||||||
|
|
||||||
|
|||||||
@@ -45,11 +45,12 @@ BCValueType::BCValueType( TypeID ID_, QString unitLabel_, optDouble factor_, opt
|
|||||||
///-------------------------------
|
///-------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
BCValue::BCValue()
|
BCValue::BCValue()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
BCValue::BCValue(const BCValueType& valueType_, BCDevice::ID deviceID_, BC::ID targetID_)
|
BCValue::BCValue(const BCValueType& valueType_, BCDevice::ID deviceID_, BC::ID targetID_)
|
||||||
: valueType{valueType_}, deviceID{deviceID_}, targetID{targetID_}
|
: valueType{valueType_}, deviceID{deviceID_}, targetID{targetID_}
|
||||||
|
|||||||
@@ -53,6 +53,7 @@
|
|||||||
-
|
-
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using bcdata_t = uint32_t;
|
||||||
|
|
||||||
class BCAbstractTransmitter
|
class BCAbstractTransmitter
|
||||||
{
|
{
|
||||||
@@ -60,7 +61,7 @@ class BCAbstractTransmitter
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
//
|
//
|
||||||
virtual uint32_t readValue( BCDevice::ID deviceID_, BC::ID targetID_ ) const = 0;
|
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 uint32_t readByte( BCDevice::ID deviceID_, BC::ID targetID_ ) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -109,6 +110,7 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// really needed?
|
||||||
using BCValueTypeCRef = std::optional<std::reference_wrapper<const BCValueType>>;
|
using BCValueTypeCRef = std::optional<std::reference_wrapper<const BCValueType>>;
|
||||||
|
|
||||||
|
|
||||||
@@ -117,7 +119,7 @@ class BCValue
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
BCValue();
|
//BCValue();
|
||||||
BCValue( const BCValueType& valueType_, BCDevice::ID deviceID_, BC::ID targetID_ );
|
BCValue( const BCValueType& valueType_, BCDevice::ID deviceID_, BC::ID targetID_ );
|
||||||
|
|
||||||
void readRawValue( const BCAbstractTransmitter& transmitter ) const;
|
void readRawValue( const BCAbstractTransmitter& transmitter ) const;
|
||||||
@@ -140,7 +142,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
Q_DECLARE_METATYPE(BCValue)
|
Q_DECLARE_METATYPE(BCValue*)
|
||||||
|
|
||||||
|
|
||||||
struct BCValueParams
|
struct BCValueParams
|
||||||
|
|||||||
@@ -49,14 +49,12 @@ BCValueManager::BCValueManager(QObject *parent)
|
|||||||
{
|
{
|
||||||
createValueTypes();
|
createValueTypes();
|
||||||
|
|
||||||
qRegisterMetaType<BCValue>("BCValue");
|
//qRegisterMetaType<BCValue*>("BCValue*");
|
||||||
|
qRegisterMetaType<BCValue*>();
|
||||||
|
|
||||||
_transmitter.moveToThread(&_worker);
|
_transmitter.moveToThread(&_worker);
|
||||||
|
|
||||||
// 4. Verbindungen herstellen (Signal/Slot über Thread-Grenzen)
|
connect(this, &BCValueManager::sendValueCommand, &_transmitter, &BCTransmitter::enqueueValueOp);
|
||||||
|
|
||||||
// A) Befehl senden (Manager -> Runner)
|
|
||||||
connect(this, &BCValueManager::sendValueCommand, &_transmitter, &BCTransmitter::enqueueValueCommand);
|
|
||||||
|
|
||||||
// B) Ergebnisse empfangen (Runner -> Manager)
|
// B) Ergebnisse empfangen (Runner -> Manager)
|
||||||
//connect(&_transmitter, &BCTransmitter::commandFinished, this, &BCValueManager::onCommandFinished);
|
//connect(&_transmitter, &BCTransmitter::commandFinished, this, &BCValueManager::onCommandFinished);
|
||||||
@@ -156,7 +154,7 @@ void BCValueManager::onSyncFromDevice()
|
|||||||
// wir das eleganter über emit sendValueCommand()
|
// wir das eleganter über emit sendValueCommand()
|
||||||
|
|
||||||
//_transmitter.enqueueValueCommand( value );
|
//_transmitter.enqueueValueCommand( value );
|
||||||
emit sendValueCommand( BC::OpID::ReadValue, value);
|
emit sendValueCommand( BC::OpID::ReadValue, &value);
|
||||||
|
|
||||||
emit valueTouched( value.rowInModel );
|
emit valueTouched( value.rowInModel );
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public slots:
|
|||||||
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 BCValue& cmd);
|
void sendValueCommand( BC::OpID, const BCValue* cmd);
|
||||||
//void valuedTouched(const BCValue& cmd);
|
//void valuedTouched(const BCValue& cmd);
|
||||||
void valueTouched(int rowInModel );
|
void valueTouched(int rowInModel );
|
||||||
|
|
||||||
|
|||||||
@@ -144,11 +144,13 @@ unsigned int getValue(unsigned char receipient, unsigned char reg)
|
|||||||
printf("error: could not send value to node %s" _NL, getNodeName(receipient));
|
printf("error: could not send value to node %s" _NL, getNodeName(receipient));
|
||||||
|
|
||||||
retry:
|
retry:
|
||||||
|
|
||||||
timeout = TIMEOUT_VALUE;
|
timeout = TIMEOUT_VALUE;
|
||||||
while(timeout-- && !CanReceiveGetCount(0))
|
while(timeout-- && !CanReceiveGetCount(0))
|
||||||
usleep(TIMEOUT_US);
|
usleep(TIMEOUT_US);
|
||||||
|
|
||||||
if (timeout == -1) {
|
if (timeout == -1)
|
||||||
|
{
|
||||||
printf("error: no response from node %s" _NL, getNodeName(receipient));
|
printf("error: no response from node %s" _NL, getNodeName(receipient));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user