158 lines
4.6 KiB
C++
158 lines
4.6 KiB
C++
#include "displayserver.h"
|
|
#include "helpers.h"
|
|
|
|
DisplayServer::DisplayServer(QObject *parent) : QObject(parent)
|
|
{
|
|
|
|
}
|
|
|
|
DisplayServer::~DisplayServer()
|
|
{
|
|
unsetup();
|
|
}
|
|
|
|
//********************************************
|
|
|
|
PlaneConfig* DisplayServer::findPlane(int plane_nr)
|
|
{
|
|
for (int plane = 0; plane < planeConfig.length(); plane++)
|
|
{
|
|
if (planeConfig[plane]->nr == plane_nr)
|
|
return planeConfig[plane];
|
|
}
|
|
|
|
//create new plane if not found
|
|
PlaneConfig* new_plane = new PlaneConfig;
|
|
new_plane->nr = plane_nr;
|
|
new_plane->name = QString("Plane %1").arg(plane_nr);
|
|
new_plane->nr_devices = 0;
|
|
new_plane->nr_sensors = 0;
|
|
planeConfig.append(new_plane);
|
|
return new_plane;
|
|
}
|
|
|
|
|
|
void DisplayServer::setup(HW* hw)
|
|
{
|
|
unsetup(); //hide is inside;)
|
|
theHW = hw;
|
|
|
|
for (int dev_nr = 0; dev_nr < theHW->devices.length(); dev_nr++)
|
|
{
|
|
PlaneConfig* current_plane = findPlane(theHW->devices[dev_nr]->deviceConfig.plane);
|
|
|
|
current_plane->devices.append(theHW->devices[dev_nr]);
|
|
current_plane->nr_devices++;
|
|
current_plane->nr_sensors += theHW->devices[dev_nr]->deviceConfig.nr_sensors;
|
|
}
|
|
}
|
|
|
|
void DisplayServer::unsetup()
|
|
{
|
|
hide();
|
|
for (int plane_nr = 0; plane_nr < planeConfig.length(); plane_nr++)
|
|
{
|
|
delete planeConfig[plane_nr];
|
|
planeConfig[plane_nr] = NULL;
|
|
}
|
|
planeConfig.clear();
|
|
|
|
}
|
|
|
|
//********************************************
|
|
|
|
void DisplayServer::show()
|
|
{
|
|
hide();
|
|
displays.clear();
|
|
for (int plane = 0; plane < planeConfig.length(); plane++)
|
|
{
|
|
BPMDisplay* newDisplay = new BPMDisplay;
|
|
newDisplay->setTitle(planeConfig[plane]->name);
|
|
newDisplay->show();
|
|
displays.append(newDisplay);
|
|
}
|
|
active = 1;
|
|
}
|
|
|
|
void DisplayServer::hide()
|
|
{
|
|
if (active)
|
|
{
|
|
for (int plane = 0; plane < displays.length(); plane++)
|
|
{
|
|
displays[plane]->close();
|
|
delete displays[plane];
|
|
}
|
|
displays.clear();
|
|
|
|
active = 0;
|
|
}
|
|
}
|
|
|
|
void DisplayServer::plot()
|
|
{
|
|
if (!active)
|
|
return;
|
|
|
|
QVector<BufferData> lastFrame = theHW->eventBuilder.getLastFrame();
|
|
if (lastFrame.length() == 0)
|
|
return;
|
|
|
|
for (int plane = 0; plane < planeConfig.length(); plane++)
|
|
{
|
|
//initialize buffer
|
|
displays[plane]->buffer.resize(planeConfig[plane]->nr_sensors*64);
|
|
displays[plane]->rmsbuffer.resize(4);
|
|
|
|
//fill with data
|
|
int current_base = 0;
|
|
// Assuming 'sensor_data' is an array of ints and 'buffer' is a QVector<short>
|
|
BufferData::SensorData rawValue;
|
|
|
|
|
|
for (int dev_nr = 0; dev_nr < planeConfig[plane]->nr_devices; dev_nr++)
|
|
{
|
|
int dev_id = planeConfig[plane]->devices[dev_nr]->deviceConfig.device_id;
|
|
int nr_channels = planeConfig[plane]->devices[dev_nr]->deviceConfig.nr_channels();
|
|
if (nr_channels > lastFrame[dev_id].buffer_size)
|
|
nr_channels = lastFrame[dev_id].buffer_size; //check if there's really some data in the buffer
|
|
//WARNING!!! Device order is not yet implemented!!! (probably)
|
|
for (int i = 0; i < int(nr_channels/2); i++){ //should be 32
|
|
//displays[plane]->buffer[current_base+i] = lastFrame[dev_id].sensor_data[i]; //old code
|
|
// Use RAW values (index 2*i) or CAL values (index 2*i + 1)
|
|
rawValue = lastFrame[dev_id].sensorData[i]; // Get int(RAW1+RAW2)
|
|
std::cerr << rawValue.raw1 << " " << rawValue.raw2 << " " <<rawValue.cal1 << " " <<rawValue.cal2 << " " <<std::endl;
|
|
if (showRawData) //RAW1, RAW2, ...
|
|
{
|
|
displays[plane]->buffer[current_base + i] = static_cast<short>(rawValue.raw1);
|
|
displays[plane]->buffer[current_base + i + 1] = static_cast<short>(rawValue.raw2);
|
|
}
|
|
else //CAL1, CAL2
|
|
{
|
|
displays[plane]->buffer[current_base + i] = static_cast<short>(rawValue.cal1);
|
|
displays[plane]->buffer[current_base + i + 1] = static_cast<short>(rawValue.cal2);
|
|
}
|
|
|
|
|
|
}
|
|
current_base += nr_channels;
|
|
displays[plane]->rmsbuffer[0] = lastFrame[dev_id].rms_frame.mean;
|
|
displays[plane]->rmsbuffer[1] = lastFrame[dev_id].rms_frame.sigma;
|
|
displays[plane]->rmsbuffer[2] = lastFrame[dev_id].rms_frame.max;
|
|
displays[plane]->rmsbuffer[3] = lastFrame[dev_id].rms_frame.status;
|
|
|
|
}
|
|
//plot
|
|
displays[plane]->plot();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
int DisplayServer::isActive()
|
|
{
|
|
return active;
|
|
}
|