-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpumpcommandworker.cpp
More file actions
34 lines (29 loc) · 935 Bytes
/
pumpcommandworker.cpp
File metadata and controls
34 lines (29 loc) · 935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "pumpcommandworker.h"
#include "pumpinterface.h"
#include <QDebug>
PumpCommandWorker::PumpCommandWorker(PumpInterface* interface, QObject* parent)
: QObject(parent), pumpInterface(interface) {
connect(pumpInterface, &PumpInterface::dataReceived,
this, &PumpCommandWorker::onResponseReceived);
}
void PumpCommandWorker::enqueueCommand(const AddressedCommand& command) {
commandQueue.enqueue(command);
if (!processing) {
processNext();
}
}
void PumpCommandWorker::processNext() {
if (commandQueue.isEmpty()) {
// emit message that queue is complete?
processing = false;
return;
}
AddressedCommand cmd = commandQueue.dequeue();
emit pumpCommandReady(cmd.name, cmd.cmd, cmd.value);
processing = true;
}
void PumpCommandWorker::onResponseReceived(const QString& response) {
Q_UNUSED(response)
processing = false;
processNext();
}