Commit 341bf15c authored by Thomas BOUTROUE's avatar Thomas BOUTROUE

Better handling on dirty flag (by queue instead of current transfer)

parent dbe9111a
......@@ -100,7 +100,6 @@ CanOpenSdoTransfer::CanOpenSdoTransfer (void)
, waitingFrame (false)
, useCrc (false)
, checksum (0x0000)
, dirty (false)
{ }
void CanOpenSdoTransfer::createBuffer (const CanOpenDataLen len) {
......@@ -109,24 +108,13 @@ void CanOpenSdoTransfer::createBuffer (const CanOpenDataLen len) {
memset (buffer.data (), 0x00, len);
}
bool CanOpenSdoTransfer::isDirty (void) const {
return dirty;
}
void CanOpenSdoTransfer::markDirty (void) {
dirty = true;
}
void CanOpenSdoTransfer::markClean (void) {
dirty = false;
}
/*** CAN OPEN SDO TRANSFERS QUEUE ***/
CanOpenSdoTransferQueue::CanOpenSdoTransferQueue (const CanOpenNodeId nodeId, QObject * parent)
: QObject (parent)
, _mode (CanOpenSdoModes::SdoNeiter)
, _currentTransfer (Q_NULLPTR)
, _mode (CanOpenSdoModes::SdoNeiter)
, _dirty (false)
, NODE_ID (nodeId)
{
_timerError.setSingleShot (true);
......@@ -162,6 +150,19 @@ void CanOpenSdoTransferQueue::reconfigure (const CanOpenSdoMode mode, const int
_timerError.setInterval (timeout);
}
bool CanOpenSdoTransferQueue::isDirty (void) const {
return _dirty;
}
void CanOpenSdoTransferQueue::markDirty (void) {
_dirty = true;
_timerProcess.start (0);
}
void CanOpenSdoTransferQueue::markClean (void) {
_dirty = false;
}
void CanOpenSdoTransferQueue::killTimeoutWatcher (void) {
if (_timerError.isActive ()) {
_timerError.stop ();
......@@ -177,8 +178,7 @@ void CanOpenSdoTransferQueue::addPendingTransfer (CanOpenSdoTransfer * transfer)
QMutexLocker locker (&_mutex);
if (_currentTransfer == Q_NULLPTR && _transfersQueue.isEmpty ()) {
_currentTransfer = transfer;
transfer->markDirty ();
_timerProcess.start (0);
markDirty ();
}
else {
_transfersQueue.enqueue (transfer);
......@@ -199,8 +199,7 @@ void CanOpenSdoTransferQueue::prepareNextTransfer (void) {
QMutexLocker locker (&_mutex);
if (_currentTransfer == Q_NULLPTR && !_transfersQueue.isEmpty ()) {
_currentTransfer = _transfersQueue.dequeue ();
_currentTransfer->markDirty ();
_timerProcess.start (0);
markDirty ();
}
}
......@@ -209,7 +208,7 @@ void CanOpenSdoTransferQueue::resetCurrentTransfer (void) {
if (_currentTransfer != Q_NULLPTR) {
delete _currentTransfer;
_currentTransfer = Q_NULLPTR;
_timerProcess.start (0);
markDirty ();
}
}
......@@ -218,8 +217,7 @@ void CanOpenSdoTransferQueue::onTimeoutError (void) {
if (_currentTransfer == Q_NULLPTR) {
QMutexLocker sublocker (&_currentTransfer->mutex);
_currentTransfer->errState = CanOpenSdoAbortCodes::ProtocolTimeout;
_currentTransfer->markDirty ();
_timerProcess.start (0);
markDirty ();
}
}
......
......@@ -654,13 +654,6 @@ struct QTCAN_CANOPEN_EXPORT CanOpenSdoTransfer {
QByteArray buffer;
void createBuffer (const CanOpenDataLen len);
bool isDirty (void) const;
void markDirty (void);
void markClean (void);
private:
bool dirty;
};
class QTCAN_CANOPEN_EXPORT CanOpenSdoTransferQueue : public QObject {
......@@ -677,6 +670,10 @@ public:
void reset (void);
void reconfigure (const CanOpenSdoMode mode, const int timeout);
bool isDirty (void) const;
void markDirty (void);
void markClean (void);
void killTimeoutWatcher (void);
void restartTimeoutWatcher (void);
......@@ -694,9 +691,10 @@ private:
QMutex _mutex;
QTimer _timerError;
QTimer _timerProcess;
CanOpenSdoMode _mode;
CanOpenSdoTransfer * _currentTransfer;
QQueue<CanOpenSdoTransfer *> _transfersQueue;
CanOpenSdoTransfer * _currentTransfer;
CanOpenSdoMode _mode;
bool _dirty;
const CanOpenNodeId NODE_ID;
};
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment