added a udpserver and client for testing

This commit is contained in:
Blake Leverington 2023-09-08 14:42:37 +02:00
parent facb6f7e26
commit 8928a49bf1
55 changed files with 4628 additions and 177 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -21,6 +21,7 @@ debug/dialogtiscan.o
debug/dialogprofiler.o
debug/stepper.o
debug/dialogbeta.o
debug/udpserver.o
debug/moc_mainwindow.o
debug/moc_dialoglogsettings.o
debug/moc_device.o
@ -39,3 +40,4 @@ debug/moc_dialogtiscan.o
debug/moc_dialogprofiler.o
debug/moc_stepper.o
debug/moc_dialogbeta.o
debug/moc_udpserver.o

View File

@ -45,9 +45,9 @@ public:
}
int max_channels() {return 64*max_sensors();}
int nr_channels() {return 64*nr_sensors;}
DeviceConfig() : own_ip({10,0,7,1}), device_ip({10,0,7,2}),
device_id(0), hardware_ver(0), master(1), plane(0), position(0), nr_sensors(0),
period(65535), tint(1), master_delay(1), slave_delay(1), gain(0), dma_bunch(1), eth_bunch(1) {}
DeviceConfig() : own_ip{10,0,7,1}, device_ip{10,0,7,2},
device_id{0}, hardware_ver{0}, master{1}, plane{0}, position{0}, nr_sensors{0},
period{65535}, tint{1}, master_delay{1}, slave_delay{1}, gain{0}, dma_bunch{1}, eth_bunch{1} {}
};

View File

@ -30,6 +30,19 @@ Display::Display(QWidget *parent) :
connect(ui->pushButton_savebkg, &QPushButton::clicked, this, &Display::onSaveBackgroundClicked);
connect(ui->pushButton_loadbkg, &QPushButton::clicked, this, &Display::onLoadBackgroundClicked);
connect(ui->checkBox_subbkg, &QCheckBox::stateChanged, this, &Display::onCheckBoxStateChanged);
connect(ui->pushButton_savecalib, &QPushButton::clicked, this, &Display::onSaveCalibrationClicked);
connect(ui->pushButton_loadcalib, &QPushButton::clicked, this, &Display::onLoadCalibrationClicked);
connect(ui->checkBox_expertmode, &QCheckBox::stateChanged, this, &Display::onExpertModeStateChanged);
// Enable or disable the "Save Background" and "Save Calib" buttons accordingly
ui->pushButton_savebkg->setEnabled(expertModeEnabled);
ui->pushButton_savecalib->setEnabled(expertModeEnabled);
// Gray out the buttons when they are disabled
ui->pushButton_savebkg->setStyleSheet(expertModeEnabled ? "" : "background-color: gray;");
ui->pushButton_savecalib->setStyleSheet(expertModeEnabled ? "" : "background-color: gray;");
}
Display::~Display()
@ -79,12 +92,11 @@ void Display::plot(const QVector<unsigned short> &data)
max = dataY[i];
}
if (subtractBackground && ui->checkBox_subbkg->isChecked()) {
// Check if background subtraction is enabled and the checkbox is checked
QString planeName = ui->lineTitle->text();
planeName.remove(QChar(' '));
if (subtractBackground && ui->checkBox_subbkg->isChecked()) {
// Check if background subtraction is enabled and the checkbox is checked
// Check if background data exists for this plane
if (backgroundDataMap.contains(planeName)) {
const QVector<unsigned short> &backgroundData = backgroundDataMap[planeName];
@ -96,6 +108,22 @@ void Display::plot(const QVector<unsigned short> &data)
}
}
if (applyCalibration && ui->checkBox_enablecalib->isChecked()) {
// Check if calibration is enabled and the checkbox is checked
// Check if calibration data exists
if (calibrationDataMap.contains(planeName) ){
const QVector<unsigned short> &calibrationData = calibrationDataMap[planeName];
// Apply calibration to the current data
for (int i = 0; i < nrPoints; ++i) {
dataY[i] = dataY[i] / calibrationData[i];
}
}
}
//set Y range
if (ui->radioButtonAutoscale->isChecked())
ui->plot->yAxis->setRange(min-0.05*(max-min),max+0.05*(max-min));
else if (ui->radioButtonFixedScale ->isChecked())
@ -224,3 +252,132 @@ void Display::onCheckBoxStateChanged(int state)
subtractBackground = (state == Qt::Checked);
}
void Display::onSaveCalibrationClicked()
{
// Check if there is data to save
if (buffer.isEmpty()) {
// No data to save
return;
}
// Get the plane's name (you might need to adjust how you retrieve it)
QString planeName = ui->lineTitle->text();
// Remove invalid characters from the plane name (e.g., spaces)
planeName.remove(QChar(' '));
// Generate the filename with the plane name appended
QString filename = QString("calib/calibration_%1.txt").arg(planeName);
// Open the file for writing
QFile file(filename);
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream stream(&file);
// Write the data to the file
for (int i = 0; i < buffer.size(); ++i) {
stream << QString::number(buffer[i]) << "\n";
}
// Close the file
file.close();
// Notify the user that the data has been saved
qInfo() << "Calibration data saved for" << planeName;
} else {
// Failed to open the file
qWarning() << "Error: Failed to open" << filename << "for writing";
}
}
void Display::onLoadCalibrationClicked()
{
// Get the plane's name (you might need to adjust how you retrieve it)
QString planeName = ui->lineTitle->text();
// Remove invalid characters from the plane name (e.g., spaces)
planeName.remove(QChar(' '));
// Generate the filename with the plane name appended
QString filename = QString("calib/calibration_%1.txt").arg(planeName);
// Open the file for reading
QFile file(filename);
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream stream(&file);
// Read the data from the file and store it in a vector
QVector<unsigned short> calibrationData;
while (!stream.atEnd()) {
QString line = stream.readLine();
unsigned short value = line.toUShort();
calibrationData.append(value);
}
// Close the file
file.close();
// Normalize the calibration data to the median value of all values greater than zero
QVector<unsigned short> normalizedCalibrationData = calibrationData; // Copy the data
QVector<unsigned short> normalizedCalibrationData2 = calibrationData; // Copy the data again
// Remove values less than 50 (noise or dead channels) before determining the median for live channels
normalizedCalibrationData.erase(std::remove_if(normalizedCalibrationData.begin(), normalizedCalibrationData.end(), [](unsigned short value) {
return value < 50;
}), normalizedCalibrationData.end());
std::sort(normalizedCalibrationData.begin(), normalizedCalibrationData.end()); // Sort the data
int size = normalizedCalibrationData.size();
unsigned short medianValue = 0;
if (size % 2 == 0) {
// If the size is even, take the average of the two middle values
medianValue = (normalizedCalibrationData[size / 2 - 1] + normalizedCalibrationData[size / 2]) / 2;
} else {
// If the size is odd, take the middle value
medianValue = normalizedCalibrationData[size / 2];
}
//use the second copy to return the scaled calibration values.
for (unsigned short &value : normalizedCalibrationData2) {
if (value > 50) {
value /= medianValue;
}
else
{
value = 0;
}
}
// Store the normalized calibration data in the map
calibrationDataMap[planeName] = normalizedCalibrationData2;
// Notify the user that the data has been loaded and normalized
qInfo() << "Calibration data loaded and normalized for" << planeName;
} else {
// Failed to open the file
qWarning() << "Error: Failed to open" << filename << "for reading";
}
}
void Display::onCalibrationCheckBoxChanged(int state) {
// Check the state and update the subtractCalibration flag accordingly
applyCalibration = (state == Qt::Checked);
}
// Slot to handle the state change of the "Expert Mode" checkbox
void Display::onExpertModeStateChanged(int state)
{
// Check if the checkbox is checked (Expert Mode enabled)
expertModeEnabled = (state == Qt::Checked);
// Enable or disable the "Save Background" and "Save Calib" buttons accordingly
ui->pushButton_savebkg->setEnabled(expertModeEnabled);
ui->pushButton_savecalib->setEnabled(expertModeEnabled);
// Gray out the buttons when they are disabled
ui->pushButton_savebkg->setStyleSheet(expertModeEnabled ? "" : "background-color: gray;");
ui->pushButton_savecalib->setStyleSheet(expertModeEnabled ? "" : "background-color: gray;");
}

View File

@ -7,6 +7,7 @@
#include <QButtonGroup>
#include <QTextStream>
#include <QFile>
#include <QCheckBox>
namespace Ui {
class display;
@ -33,6 +34,10 @@ public slots:
void onSaveBackgroundClicked();
void onLoadBackgroundClicked();
void onCheckBoxStateChanged(int state);
void onSaveCalibrationClicked();
void onLoadCalibrationClicked();
void onCalibrationCheckBoxChanged(int state);
void onExpertModeStateChanged(int state);
protected:
int nrPoints = 0;
@ -46,7 +51,11 @@ private:
QMap<QString, QVector<unsigned short>> backgroundDataMap; // Map to store background data for each plane
bool subtractBackground = false; // Flag to track if background subtraction is enabled
QMap<QString, QVector<unsigned short>> calibrationDataMap; // Map to store calibration data for each plane
bool applyCalibration = false; // Flag to track if calibration should be applied
QVector<unsigned short> calibrationData; // Stores the loaded calibration data
QCheckBox *checkBoxExpertMode; // Expert Mode checkbox
bool expertModeEnabled = false; // Flag to track if expert mode is enabled
};
#endif // DISPLAY_H

View File

@ -6,10 +6,16 @@
<rect>
<x>0</x>
<y>0</y>
<width>602</width>
<height>390</height>
<width>609</width>
<height>418</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Online Display</string>
</property>
@ -131,44 +137,93 @@
</item>
</layout>
</widget>
<widget class="QPushButton" name="pushButton_savebkg">
<widget class="Line" name="line_3">
<property name="geometry">
<rect>
<x>510</x>
<y>360</y>
<width>80</width>
<height>24</height>
<x>10</x>
<y>350</y>
<width>581</width>
<height>20</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QWidget" name="horizontalLayoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>370</y>
<width>581</width>
<height>41</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="checkBox_expertmode">
<property name="text">
<string>expert
mode</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_enablecalib">
<property name="text">
<string>enable
calibration</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_loadcalib">
<property name="text">
<string>Load calib</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_savecalib">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>save calib</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_subbkg">
<property name="text">
<string>sub bkg</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_loadbkg">
<property name="text">
<string>load bkg</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_savebkg">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>save bkg</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_loadbkg">
<property name="geometry">
<rect>
<x>420</x>
<y>360</y>
<width>80</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>load bkg</string>
</property>
</widget>
<widget class="QCheckBox" name="checkBox_subbkg">
<property name="geometry">
<rect>
<x>330</x>
<y>360</y>
<width>77</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>sub bkg</string>
</property>
</item>
</layout>
</widget>
</widget>
<customwidgets>

View File

@ -1,4 +1,5 @@
#include "eventbuilder.h"
#include "udpserver.h" // Include the UDP server header
EventBuilder::EventBuilder(QObject *parent) : QObject(parent)
{
@ -9,6 +10,9 @@ EventBuilder::EventBuilder(QObject *parent) : QObject(parent)
connect(this, EventBuilder::sigStartTakingHistos, this, EventBuilder::onStartTakingHistos);
connect(this, EventBuilder::sigStopTakingHistos, this, EventBuilder::onStopTakingHistos);
// Create an instance of your UDP server class
udpServer = new UdpServer(this);
moveToThread(&thread);
thread.start();
init();
@ -22,6 +26,7 @@ EventBuilder::~EventBuilder()
thread.wait();
}
//************************* Data processing framework ********************
//main processing slot
@ -76,6 +81,14 @@ void EventBuilder::onNewData(DataReceiver* receiver)
//************ TODO ************
//Here we can do something more with the complete frame
// I probably want to find the position and focus with the linear regression algorithm, but first, just send data to the udpserver to test.
intensity+=1.0;
position+=0.1;
focus+=0.01;
// Call sendData method of the UDP server
QString dataString = QString::number(intensity) + ',' + QString::number(position) + ',' + QString::number(focus);
QByteArray data = dataString.toUtf8();
udpServer->sendData(data);
}

View File

@ -8,6 +8,7 @@
#include <QThread>
#include <QMutex>
#include <QMutexLocker>
#include "udpserver.h" // Include the UDP server header
//#include "hw.h"
#include "datareceiver.h"
@ -86,6 +87,12 @@ protected slots:
void onStopLogging();
void onStartTakingHistos(int sample_count);
void onStopTakingHistos();
private:
UdpServer* udpServer; // Declare a member variable for the UDP server
double intensity = 0.0;
double position = 0.0;
double focus = 0.0;
};
#endif // EVENTBUILDER_H

View File

@ -36,7 +36,8 @@ SOURCES += main.cpp\
dialogtiscan.cpp \
dialogprofiler.cpp \
stepper.cpp \
dialogbeta.cpp
dialogbeta.cpp \
udpserver.cpp
HEADERS += mainwindow.h \
Q_DebugStream.h \
@ -61,7 +62,8 @@ HEADERS += mainwindow.h \
dialogtiscan.h \
dialogprofiler.h \
stepper.h \
dialogbeta.h
dialogbeta.h \
udpserver.h
FORMS += mainwindow.ui \
dialoglogsettings.ui \

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 11.0.2, 2023-09-07T13:54:45. -->
<!-- Written by QtCreator 11.0.2, 2023-09-08T14:26:46. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@ -1,10 +1,12 @@
#include "mainwindow.h"
#include <QApplication>
#include "udpserver.h" // Include udpserver header
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// Create and start the UDP server
UdpServer udpServer; // Assuming your UdpServer class is properly defined
udpServer.startServer();
// Apply the stylesheet to each display
qDebug() << "App path : " << qApp->applicationDirPath();

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -49,11 +49,15 @@ static constexpr auto qt_meta_stringdata_CLASSDisplayENDCLASS = QtMocHelpers::st
"onSaveBackgroundClicked",
"onLoadBackgroundClicked",
"onCheckBoxStateChanged",
"state"
"state",
"onSaveCalibrationClicked",
"onLoadCalibrationClicked",
"onCalibrationCheckBoxChanged",
"onExpertModeStateChanged"
);
#else // !QT_MOC_HAS_STRING_DATA
struct qt_meta_stringdata_CLASSDisplayENDCLASS_t {
uint offsetsAndSizes[24];
uint offsetsAndSizes[32];
char stringdata0[8];
char stringdata1[10];
char stringdata2[1];
@ -66,6 +70,10 @@ struct qt_meta_stringdata_CLASSDisplayENDCLASS_t {
char stringdata9[24];
char stringdata10[23];
char stringdata11[6];
char stringdata12[25];
char stringdata13[25];
char stringdata14[29];
char stringdata15[25];
};
#define QT_MOC_LITERAL(ofs, len) \
uint(sizeof(qt_meta_stringdata_CLASSDisplayENDCLASS_t::offsetsAndSizes) + ofs), len
@ -82,7 +90,11 @@ Q_CONSTINIT static const qt_meta_stringdata_CLASSDisplayENDCLASS_t qt_meta_strin
QT_MOC_LITERAL(77, 23), // "onSaveBackgroundClicked"
QT_MOC_LITERAL(101, 23), // "onLoadBackgroundClicked"
QT_MOC_LITERAL(125, 22), // "onCheckBoxStateChanged"
QT_MOC_LITERAL(148, 5) // "state"
QT_MOC_LITERAL(148, 5), // "state"
QT_MOC_LITERAL(154, 24), // "onSaveCalibrationClicked"
QT_MOC_LITERAL(179, 24), // "onLoadCalibrationClicked"
QT_MOC_LITERAL(204, 28), // "onCalibrationCheckBoxChanged"
QT_MOC_LITERAL(233, 24) // "onExpertModeStateChanged"
},
"Display",
"showEvent",
@ -95,7 +107,11 @@ Q_CONSTINIT static const qt_meta_stringdata_CLASSDisplayENDCLASS_t qt_meta_strin
"onSaveBackgroundClicked",
"onLoadBackgroundClicked",
"onCheckBoxStateChanged",
"state"
"state",
"onSaveCalibrationClicked",
"onLoadCalibrationClicked",
"onCalibrationCheckBoxChanged",
"onExpertModeStateChanged"
};
#undef QT_MOC_LITERAL
#endif // !QT_MOC_HAS_STRING_DATA
@ -107,7 +123,7 @@ Q_CONSTINIT static const uint qt_meta_data_CLASSDisplayENDCLASS[] = {
11, // revision
0, // classname
0, 0, // classinfo
5, 14, // methods
9, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
@ -115,17 +131,25 @@ Q_CONSTINIT static const uint qt_meta_data_CLASSDisplayENDCLASS[] = {
0, // signalCount
// slots: name, argc, parameters, tag, flags, initial metatype offsets
1, 1, 44, 2, 0x0a, 1 /* Public */,
5, 1, 47, 2, 0x0a, 3 /* Public */,
8, 0, 50, 2, 0x0a, 5 /* Public */,
9, 0, 51, 2, 0x0a, 6 /* Public */,
10, 1, 52, 2, 0x0a, 7 /* Public */,
1, 1, 68, 2, 0x0a, 1 /* Public */,
5, 1, 71, 2, 0x0a, 3 /* Public */,
8, 0, 74, 2, 0x0a, 5 /* Public */,
9, 0, 75, 2, 0x0a, 6 /* Public */,
10, 1, 76, 2, 0x0a, 7 /* Public */,
12, 0, 79, 2, 0x0a, 9 /* Public */,
13, 0, 80, 2, 0x0a, 10 /* Public */,
14, 1, 81, 2, 0x0a, 11 /* Public */,
15, 1, 84, 2, 0x0a, 13 /* Public */,
// slots: parameters
QMetaType::Void, 0x80000000 | 3, 4,
QMetaType::Void, 0x80000000 | 6, 7,
QMetaType::Void,
QMetaType::Void,
QMetaType::Void, QMetaType::Int, 11,
QMetaType::Void,
QMetaType::Void,
QMetaType::Void, QMetaType::Int, 11,
QMetaType::Void, QMetaType::Int, 11,
0 // eod
@ -152,6 +176,16 @@ Q_CONSTINIT const QMetaObject Display::staticMetaObject = { {
QtPrivate::TypeAndForceComplete<void, std::false_type>,
// method 'onCheckBoxStateChanged'
QtPrivate::TypeAndForceComplete<void, std::false_type>,
QtPrivate::TypeAndForceComplete<int, std::false_type>,
// method 'onSaveCalibrationClicked'
QtPrivate::TypeAndForceComplete<void, std::false_type>,
// method 'onLoadCalibrationClicked'
QtPrivate::TypeAndForceComplete<void, std::false_type>,
// method 'onCalibrationCheckBoxChanged'
QtPrivate::TypeAndForceComplete<void, std::false_type>,
QtPrivate::TypeAndForceComplete<int, std::false_type>,
// method 'onExpertModeStateChanged'
QtPrivate::TypeAndForceComplete<void, std::false_type>,
QtPrivate::TypeAndForceComplete<int, std::false_type>
>,
nullptr
@ -168,6 +202,10 @@ void Display::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, voi
case 2: _t->onSaveBackgroundClicked(); break;
case 3: _t->onLoadBackgroundClicked(); break;
case 4: _t->onCheckBoxStateChanged((*reinterpret_cast< std::add_pointer_t<int>>(_a[1]))); break;
case 5: _t->onSaveCalibrationClicked(); break;
case 6: _t->onLoadCalibrationClicked(); break;
case 7: _t->onCalibrationCheckBoxChanged((*reinterpret_cast< std::add_pointer_t<int>>(_a[1]))); break;
case 8: _t->onExpertModeStateChanged((*reinterpret_cast< std::add_pointer_t<int>>(_a[1]))); break;
default: ;
}
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
@ -203,13 +241,13 @@ int Display::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 5)
if (_id < 9)
qt_static_metacall(this, _c, _id, _a);
_id -= 5;
_id -= 9;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 5)
if (_id < 9)
qt_static_metacall(this, _c, _id, _a);
_id -= 5;
_id -= 9;
}
return _id;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -21,6 +21,7 @@ release/dialogtiscan.o
release/dialogprofiler.o
release/stepper.o
release/dialogbeta.o
release/udpserver.o
release/moc_mainwindow.o
release/moc_dialoglogsettings.o
release/moc_device.o
@ -39,3 +40,4 @@ release/moc_dialogtiscan.o
release/moc_dialogprofiler.o
release/moc_stepper.o
release/moc_dialogbeta.o
release/moc_udpserver.o

37
hit2023v2/udpserver.cpp Normal file
View File

@ -0,0 +1,37 @@
#include "udpserver.h"
UdpServer::UdpServer(QObject *parent) : QObject(parent)
{
// Configure the timer for data updates
// connect(&timer, &QTimer::timeout, this, &UdpServer::sendData);
// timer.setInterval(1); // 1 milliseconds (1 kHz)
startServer();
}
void UdpServer::startServer()
{
// Bind the UDP socket to a specific port (replace with your desired port)
// udpSocket.bind(QHostAddress::Any, 12345); // Replace 12345 with your desired port
udpSocket.bind(QHostAddress("10.0.7.1"), 12345); // Use the desired host address and port
// udpSocket.bind(QHostAddress::LocalHost, 12345); // Use "localhost" (127.0.0.1) and port 12345
// Start the timer for data updates
// timer.start();
}
void UdpServer::stopServer()
{
// Stop the timer and close the UDP socket
// timer.stop();
udpSocket.close();
}
void UdpServer::sendData(QByteArray data)
{
// Prepare the data to be sent
// QString dataString = QString::number(intensity) + ',' + QString::number(position) + ',' + QString::number(focus);
// QByteArray data = dataString.toUtf8();
// Send the data to all connected clients (broadcast to all on the same network)
udpSocket.writeDatagram(data, QHostAddress::Broadcast, 12345); // Replace 12345 with your desired port
}

26
hit2023v2/udpserver.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef UDPSERVER_H
#define UDPSERVER_H
#include <QObject>
#include <QUdpSocket>
#include <QTimer> // Add this line to include QTimer
class UdpServer : public QObject
{
Q_OBJECT
public:
explicit UdpServer(QObject *parent = nullptr);
public slots:
void startServer();
void stopServer();
void sendData(QByteArray data); // New slot to send data with custom values
private:
QUdpSocket udpSocket;
QTimer timer;
};
#endif // UDPSERVER_H

View File

@ -41,16 +41,28 @@ public:
QRadioButton *radioButtonFixedScale;
QSpinBox *spinBox_fixedmin;
QSpinBox *spinBox_fixedmax;
QPushButton *pushButton_savebkg;
QPushButton *pushButton_loadbkg;
QFrame *line_3;
QWidget *horizontalLayoutWidget;
QHBoxLayout *horizontalLayout_2;
QCheckBox *checkBox_expertmode;
QCheckBox *checkBox_enablecalib;
QPushButton *pushButton_loadcalib;
QPushButton *pushButton_savecalib;
QCheckBox *checkBox_subbkg;
QPushButton *pushButton_loadbkg;
QPushButton *pushButton_savebkg;
QButtonGroup *buttonGroup;
void setupUi(QDialog *display)
{
if (display->objectName().isEmpty())
display->setObjectName("display");
display->resize(602, 390);
display->resize(609, 418);
QSizePolicy sizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(display->sizePolicy().hasHeightForWidth());
display->setSizePolicy(sizePolicy);
verticalLayoutWidget = new QWidget(display);
verticalLayoutWidget->setObjectName("verticalLayoutWidget");
verticalLayoutWidget->setGeometry(QRect(9, 10, 581, 341));
@ -67,11 +79,11 @@ public:
plot = new QCustomPlot(verticalLayoutWidget);
plot->setObjectName("plot");
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(plot->sizePolicy().hasHeightForWidth());
plot->setSizePolicy(sizePolicy);
QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Expanding);
sizePolicy1.setHorizontalStretch(0);
sizePolicy1.setVerticalStretch(0);
sizePolicy1.setHeightForWidth(plot->sizePolicy().hasHeightForWidth());
plot->setSizePolicy(sizePolicy1);
verticalLayout->addWidget(plot);
@ -133,15 +145,59 @@ public:
verticalLayout->addLayout(horizontalLayout);
pushButton_savebkg = new QPushButton(display);
pushButton_savebkg->setObjectName("pushButton_savebkg");
pushButton_savebkg->setGeometry(QRect(510, 360, 80, 24));
pushButton_loadbkg = new QPushButton(display);
pushButton_loadbkg->setObjectName("pushButton_loadbkg");
pushButton_loadbkg->setGeometry(QRect(420, 360, 80, 24));
checkBox_subbkg = new QCheckBox(display);
line_3 = new QFrame(display);
line_3->setObjectName("line_3");
line_3->setGeometry(QRect(10, 350, 581, 20));
QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Fixed);
sizePolicy2.setHorizontalStretch(0);
sizePolicy2.setVerticalStretch(0);
sizePolicy2.setHeightForWidth(line_3->sizePolicy().hasHeightForWidth());
line_3->setSizePolicy(sizePolicy2);
line_3->setFrameShape(QFrame::HLine);
line_3->setFrameShadow(QFrame::Sunken);
horizontalLayoutWidget = new QWidget(display);
horizontalLayoutWidget->setObjectName("horizontalLayoutWidget");
horizontalLayoutWidget->setGeometry(QRect(10, 370, 581, 41));
horizontalLayout_2 = new QHBoxLayout(horizontalLayoutWidget);
horizontalLayout_2->setObjectName("horizontalLayout_2");
horizontalLayout_2->setContentsMargins(0, 0, 0, 0);
checkBox_expertmode = new QCheckBox(horizontalLayoutWidget);
checkBox_expertmode->setObjectName("checkBox_expertmode");
horizontalLayout_2->addWidget(checkBox_expertmode);
checkBox_enablecalib = new QCheckBox(horizontalLayoutWidget);
checkBox_enablecalib->setObjectName("checkBox_enablecalib");
horizontalLayout_2->addWidget(checkBox_enablecalib);
pushButton_loadcalib = new QPushButton(horizontalLayoutWidget);
pushButton_loadcalib->setObjectName("pushButton_loadcalib");
horizontalLayout_2->addWidget(pushButton_loadcalib);
pushButton_savecalib = new QPushButton(horizontalLayoutWidget);
pushButton_savecalib->setObjectName("pushButton_savecalib");
pushButton_savecalib->setEnabled(false);
horizontalLayout_2->addWidget(pushButton_savecalib);
checkBox_subbkg = new QCheckBox(horizontalLayoutWidget);
checkBox_subbkg->setObjectName("checkBox_subbkg");
checkBox_subbkg->setGeometry(QRect(330, 360, 77, 22));
horizontalLayout_2->addWidget(checkBox_subbkg);
pushButton_loadbkg = new QPushButton(horizontalLayoutWidget);
pushButton_loadbkg->setObjectName("pushButton_loadbkg");
horizontalLayout_2->addWidget(pushButton_loadbkg);
pushButton_savebkg = new QPushButton(horizontalLayoutWidget);
pushButton_savebkg->setObjectName("pushButton_savebkg");
pushButton_savebkg->setEnabled(false);
horizontalLayout_2->addWidget(pushButton_savebkg);
retranslateUi(display);
@ -154,9 +210,15 @@ public:
radioButtonAutoscale->setText(QCoreApplication::translate("display", "Auto Y-Scale", nullptr));
radioButtonMaxScale->setText(QCoreApplication::translate("display", "Max Y-Scale", nullptr));
radioButtonFixedScale->setText(QCoreApplication::translate("display", "Fixed Y-Scale", nullptr));
pushButton_savebkg->setText(QCoreApplication::translate("display", "save bkg", nullptr));
pushButton_loadbkg->setText(QCoreApplication::translate("display", "load bkg", nullptr));
checkBox_expertmode->setText(QCoreApplication::translate("display", "expert\n"
"mode", nullptr));
checkBox_enablecalib->setText(QCoreApplication::translate("display", "enable\n"
"calibration", nullptr));
pushButton_loadcalib->setText(QCoreApplication::translate("display", "Load calib", nullptr));
pushButton_savecalib->setText(QCoreApplication::translate("display", "save calib", nullptr));
checkBox_subbkg->setText(QCoreApplication::translate("display", "sub bkg", nullptr));
pushButton_loadbkg->setText(QCoreApplication::translate("display", "load bkg", nullptr));
pushButton_savebkg->setText(QCoreApplication::translate("display", "save bkg", nullptr));
} // retranslateUi
};

74
hit2023v2_client/.gitignore vendored Normal file
View File

@ -0,0 +1,74 @@
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------
*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash
# qtcreator generated files
*.pro.user*
CMakeLists.txt.user*
# xemacs temporary files
*.flc
# Vim temporary files
.*.swp
# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*
# MinGW generated files
*.Debug
*.Release
# Python byte code
*.pyc
# Binaries
# --------
*.dll
*.exe

View File

@ -0,0 +1,19 @@
QT = core network
CONFIG += c++17 cmdline
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
udpclient.cpp
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
HEADERS += \
udpclient.h

38
hit2023v2_client/main.cpp Normal file
View File

@ -0,0 +1,38 @@
#include <QCoreApplication>
#include <signal.h> // Include the signal header for signal handling
#include "udpclient.h"
// Declare a pointer to the UDP client to ensure it's not destroyed prematurely
UdpClient* udpClient = nullptr;
// Signal handler for Ctrl+C (SIGINT)
void handleSignal(int signal)
{
Q_UNUSED(signal);
// Stop the UDP client gracefully
if (udpClient)
udpClient->stopClient();
// Exit the application
QCoreApplication::exit(0);
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// Create an instance of the UdpClient class
udpClient = new UdpClient;
// Connect the startClient slot to start the client
QObject::connect(udpClient, &UdpClient::startClient, &a, &QCoreApplication::quit);
// Start the UDP client
udpClient->startClient();
// Set up a signal handler for Ctrl+C (SIGINT)
signal(SIGINT, handleSignal);
return a.exec();
}

View File

@ -0,0 +1,41 @@
#include "udpclient.h"
UdpClient::UdpClient(QObject *parent) : QObject(parent)
{
// Create a UDP socket
// udpSocket.bind(QHostAddress::Any, 12345); // Bind to any available port
udpSocket.bind(QHostAddress("10.0.7.1"), 0); // Use the desired host address and let the OS choose an available port
// Set up a signal-slot connection to handle incoming data
connect(&udpSocket, &QUdpSocket::readyRead, this, &UdpClient::processPendingDatagrams);
}
void UdpClient::startClient()
{
qDebug() << "UDP Client is listening for data...";
// You can add additional client-specific logic here if needed.
}
void UdpClient::processPendingDatagrams()
{
while (udpSocket.hasPendingDatagrams()) {
QByteArray datagram;
datagram.resize(udpSocket.pendingDatagramSize());
QHostAddress sender;
quint16 senderPort;
udpSocket.readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);
// Parse and display the received data
QString receivedData = QString::fromUtf8(datagram);
QStringList dataList = receivedData.split(',');
if (dataList.size() == 3) {
double intensity = dataList[0].toDouble();
double position = dataList[1].toDouble();
double focus = dataList[2].toDouble();
qDebug() << "Received data - Intensity:" << intensity << "Position:" << position << "Focus:" << focus;
}
}
}

View File

@ -0,0 +1,27 @@
#ifndef UDPCLIENT_H
#define UDPCLIENT_H
#include <QObject>
#include <QUdpSocket>
#include <signal.h> // Include the signal header for signal handling
class UdpClient : public QObject
{
Q_OBJECT
public:
explicit UdpClient(QObject *parent = nullptr);
public slots:
void startClient();
void stopClient(); // New slot to stop the client gracefully
private:
QUdpSocket udpSocket;
private slots:
void processPendingDatagrams();
};
#endif // UDPCLIENT_H