2020-10-06 19:29:02 +00:00
|
|
|
#include "lasp_cppdaq.h"
|
2020-09-22 17:32:00 +00:00
|
|
|
#include <chrono>
|
|
|
|
#include <iostream>
|
2020-09-27 17:38:49 +00:00
|
|
|
#include <cmath>
|
2020-10-06 19:29:02 +00:00
|
|
|
#include <thread>
|
2020-09-22 17:32:00 +00:00
|
|
|
using std::cout;
|
2020-10-06 19:29:02 +00:00
|
|
|
using std::cerr;
|
2020-09-22 17:32:00 +00:00
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
2020-10-10 16:28:43 +00:00
|
|
|
/* boolvec inChannels = {true, false, false, false}; */
|
|
|
|
auto devinfos = Daq::getDeviceInfo();
|
|
|
|
DeviceInfo devinfo;
|
|
|
|
us i;
|
|
|
|
bool found = false;
|
|
|
|
for(i=0;i<devinfos.size();i++) {
|
|
|
|
if(devinfos[i].api == uldaqapi){
|
|
|
|
cout << string(devinfos[i]) << endl;
|
|
|
|
devinfo = devinfos[i];
|
|
|
|
found = true;
|
2020-10-06 19:29:02 +00:00
|
|
|
}
|
2020-10-10 16:28:43 +00:00
|
|
|
}
|
|
|
|
if(!found) {
|
|
|
|
throw runtime_error("Could not find UlDaq device");
|
|
|
|
}
|
|
|
|
|
|
|
|
DaqConfiguration config(devinfos[0]);
|
|
|
|
boolvec inChannels = {true, true, false, false};
|
|
|
|
boolvec outChannels = {true};
|
|
|
|
double samplerate = 10000;
|
|
|
|
const us samplesPerBlock = 256;
|
|
|
|
|
|
|
|
config.eninchannels = inChannels;
|
|
|
|
config.enoutchannels = outChannels;
|
|
|
|
config.sampleRateIndex = 0;
|
|
|
|
config.monitorOutput = true;
|
|
|
|
config.inputIEPEEnabled = {false, false, false, false};
|
|
|
|
cout << "Inchannnels size: " << config.eninchannels.size() << endl;
|
2020-10-06 19:29:02 +00:00
|
|
|
|
2020-09-22 17:32:00 +00:00
|
|
|
|
2020-10-18 11:58:42 +00:00
|
|
|
Daq* daq = Daq::createDaq(devinfo, config);
|
2020-09-22 17:32:00 +00:00
|
|
|
|
2020-10-10 16:28:43 +00:00
|
|
|
SafeQueue<void*> inqueue;
|
|
|
|
SafeQueue<void*> outqueue;
|
2020-09-27 17:38:49 +00:00
|
|
|
|
2020-10-10 16:28:43 +00:00
|
|
|
double totalTime = 5;
|
|
|
|
double t = 0;
|
|
|
|
double freq = 1000;
|
|
|
|
us nblocks = ((us) totalTime*samplerate/samplesPerBlock) + 10;
|
2020-09-27 17:38:49 +00:00
|
|
|
|
2020-10-10 16:28:43 +00:00
|
|
|
for(us i=0;i<nblocks;i++) {
|
2020-09-27 17:38:49 +00:00
|
|
|
|
2020-10-10 16:28:43 +00:00
|
|
|
double* data = static_cast<double*>(malloc(sizeof(double)*samplesPerBlock));
|
|
|
|
for(us sample=0;sample<samplesPerBlock;sample++) {
|
|
|
|
|
|
|
|
data[sample] = sin(2*M_PI*freq*t);
|
|
|
|
t+= 1.0/samplerate;
|
2020-09-27 17:38:49 +00:00
|
|
|
|
|
|
|
}
|
2020-10-10 16:28:43 +00:00
|
|
|
outqueue.enqueue(data);
|
|
|
|
}
|
2020-09-27 17:38:49 +00:00
|
|
|
|
2020-10-10 16:28:43 +00:00
|
|
|
daq->start(&inqueue, &outqueue);
|
2020-09-22 17:32:00 +00:00
|
|
|
|
2020-10-10 16:28:43 +00:00
|
|
|
std::this_thread::sleep_for(std::chrono::seconds((int) totalTime));
|
2020-09-22 17:32:00 +00:00
|
|
|
|
2020-10-10 16:28:43 +00:00
|
|
|
daq->stop();
|
2020-09-22 17:32:00 +00:00
|
|
|
|
2020-10-10 16:28:43 +00:00
|
|
|
while(!inqueue.empty()) {
|
|
|
|
double* buf = (double*) inqueue.dequeue();
|
|
|
|
for(us i=0;i<samplesPerBlock;i++) {
|
|
|
|
for(us ch=0;ch<daq->neninchannels();ch++) {
|
|
|
|
cout << buf[ch*samplesPerBlock+i] << " ";
|
|
|
|
}
|
|
|
|
cout << endl;
|
2020-09-27 17:38:49 +00:00
|
|
|
}
|
2020-10-10 16:28:43 +00:00
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
while(!outqueue.empty()){
|
|
|
|
void* dat = outqueue.dequeue();
|
|
|
|
free(dat);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2020-09-22 17:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|