-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDaqSystem.cpp
More file actions
executable file
·124 lines (97 loc) · 2.7 KB
/
DaqSystem.cpp
File metadata and controls
executable file
·124 lines (97 loc) · 2.7 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "DaqSystem.h"
#include "BaseDevice.h"
#include "DeviceParamsBase.h"
#include "Device/ADC4/DeviceParamsAdc4.h"
#include "Device/ADC4/DeviceAdc4.h"
#include "DataProcessorMemCopy.h"
#include "DataProducer.h"
#include "DataSender.h"
#include "DaqSignal.h"
#include "ThreadWrapper.h"
class MainWindow;
DaqSystem::DaqSystem() : err(0) {
dataProc = new DataProcessorMemCopy; // NOTE!!!! choose data processing
dev = new DeviceAdc4; // NOTE!!!! choose device
sig = new DaqSignal;
dev->setDataProcessor(dataProc);
initializeProducerConsumerModel();
}
DaqSystem::~DaqSystem() {
finalizeProducerConsumerModel();
delete sig;
delete dev;
delete dataProc;
}
void DaqSystem::initializeProducerConsumerModel() {
// init producer
dp = new DataProducer;
dp->setDevice(dev);
dp->setSignal(sig);
// init consumer (store, send via network, and postprocess etc.)
ds = new DataSender;
ds->setSignal(sig);
}
void DaqSystem::finalizeProducerConsumerModel() {
delete ds;
delete dp;
}
void DaqSystem::startDataProducer() {
cout << "DaqSystem::startDataProducer, wait..." << endl;
sig->bRun = true;
std::thread thrDataProd(&DataProducer::start, dp);
ThreadWrapper wrapThrDataProd(thrDataProd);
}
void DaqSystem::stopDataProducer() {
cout << "DaqSystem::stopDataProducer, wait..." << endl;
sig->bRun = false;
}
void DaqSystem::toggleStartDataAcquisition(DeviceParamsBase* params) {
if (!sig->bRun) {
if (sig->bConfig) {
// no need to check the device status, since we do it in "initialize"
//if (dev->isOpened())
// dev->finalize();
dev->initialize(params, &err);
if (err)
return;
sig->bConfig = false;
}
startDataProducer();
}
else {
stopDataProducer();
}
}
bool DaqSystem::isRunning() {
return sig->bRun;
}
void DaqSystem::setConfigRequired() {
sig->bConfig = true;
}
unsigned int DaqSystem::getNumberOfDevices() {
return dev->getDeviceCount();
}
DaqStatusBaseType* DaqSystem::getDeviceStatus() {
return dev->status;
}
void DaqSystem::startDataSender(std::string ip, unsigned short port) {
cout << "DaqSystem::startDataSender, wait..." << endl;
sig->bConnect = true;
std::thread thrDataSend(&DataSender::start, ds, ip, port);
ThreadWrapper wrapThrDataSend(thrDataSend);
}
void DaqSystem::stopDataSender() {
cout << "DaqSystem::stopDataSender, wait..." << endl;
sig->bConnect = false;
}
bool DaqSystem::toggleStartRemoteConnection(std::string ip, int port)
{
if (!ds->connected()) { // not yet started
startDataSender(ip, port);
return true; // connected
}
else { // already started
stopDataSender();
return false; // not connected
}
}