2023-08-03 11:01:50 +02:00
|
|
|
#include "dialogdevices.h"
|
|
|
|
#include "ui_dialogdevices.h"
|
|
|
|
#include "helpers.h"
|
|
|
|
|
|
|
|
DialogDevices::DialogDevices(QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::DialogDevices)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
DialogDevices::~DialogDevices()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************** Initialization ******************
|
|
|
|
|
|
|
|
void DialogDevices::showEvent(QShowEvent * event)
|
|
|
|
{
|
|
|
|
if (!event->spontaneous())
|
|
|
|
{
|
|
|
|
|
|
|
|
if (deviceSettings != NULL)
|
|
|
|
{
|
|
|
|
top(deviceSettings);
|
|
|
|
deviceSettings->beginGroup("Global");
|
|
|
|
|
|
|
|
ui->spinNrDevices->setValue(deviceSettings->value("NrDevices", int(1)).toInt());
|
|
|
|
|
2023-09-06 17:28:35 +02:00
|
|
|
ui->tableDevices->setColumnCount(8);
|
2023-08-03 11:01:50 +02:00
|
|
|
QStringList h_header;
|
|
|
|
h_header.append("IP Address");
|
2023-09-06 17:28:35 +02:00
|
|
|
h_header.append("Hardware ver.");
|
|
|
|
|
2023-08-03 11:01:50 +02:00
|
|
|
h_header.append("Layer");
|
|
|
|
h_header.append("Position");
|
|
|
|
h_header.append("Sensors");
|
|
|
|
h_header.append("Master");
|
|
|
|
h_header.append("Master dly");
|
|
|
|
h_header.append("Slave dly");
|
|
|
|
ui->tableDevices->setHorizontalHeaderLabels(h_header);
|
|
|
|
|
|
|
|
importSettings();
|
|
|
|
}
|
|
|
|
initialized = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDialog::showEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
//***************** Processing ******************
|
|
|
|
|
|
|
|
void DialogDevices::accept()
|
|
|
|
{
|
2023-09-06 17:28:35 +02:00
|
|
|
// qInfo("Accepted!");
|
2023-08-03 11:01:50 +02:00
|
|
|
|
|
|
|
if (validateAndSave())
|
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogDevices::importSettings()
|
|
|
|
{
|
|
|
|
int nr_devices = ui->spinNrDevices->value();
|
|
|
|
|
|
|
|
ui->tableDevices->setRowCount(nr_devices);
|
|
|
|
|
|
|
|
for (int dev_nr = 0; dev_nr < nr_devices; dev_nr++)
|
|
|
|
{
|
|
|
|
if (dev_nr >= last_nr_devices) //update only new rows!
|
|
|
|
{
|
|
|
|
top(deviceSettings);
|
|
|
|
QString group_label = QString("Device%1").arg(dev_nr);
|
|
|
|
deviceSettings->beginGroup(group_label);
|
|
|
|
|
|
|
|
QTableWidgetItem* newItem;
|
|
|
|
newItem = new QTableWidgetItem(deviceSettings->value("IP","0.0.0.0").toString());
|
|
|
|
ui->tableDevices->setItem(dev_nr, 0, newItem );
|
2023-09-06 17:28:35 +02:00
|
|
|
newItem = new QTableWidgetItem(deviceSettings->value("HardwareVer","2").toString());
|
2023-08-03 11:01:50 +02:00
|
|
|
ui->tableDevices->setItem(dev_nr, 1, newItem );
|
2023-09-06 17:28:35 +02:00
|
|
|
newItem = new QTableWidgetItem(deviceSettings->value("Plane","0").toString());
|
2023-08-03 11:01:50 +02:00
|
|
|
ui->tableDevices->setItem(dev_nr, 2, newItem );
|
2023-09-06 17:28:35 +02:00
|
|
|
newItem = new QTableWidgetItem(deviceSettings->value("Position","0").toString());
|
2023-08-03 11:01:50 +02:00
|
|
|
ui->tableDevices->setItem(dev_nr, 3, newItem );
|
2023-09-06 17:28:35 +02:00
|
|
|
newItem = new QTableWidgetItem(deviceSettings->value("Sensors","5").toString());
|
2023-08-03 11:01:50 +02:00
|
|
|
ui->tableDevices->setItem(dev_nr, 4, newItem );
|
2023-09-06 17:28:35 +02:00
|
|
|
newItem = new QTableWidgetItem(deviceSettings->value("Master","1").toString());
|
2023-08-03 11:01:50 +02:00
|
|
|
ui->tableDevices->setItem(dev_nr, 5, newItem );
|
2023-09-06 17:28:35 +02:00
|
|
|
newItem = new QTableWidgetItem(deviceSettings->value("MasterDelay","62").toString());
|
2023-08-03 11:01:50 +02:00
|
|
|
ui->tableDevices->setItem(dev_nr, 6, newItem );
|
2023-09-06 17:28:35 +02:00
|
|
|
newItem = new QTableWidgetItem(deviceSettings->value("SlaveDelay","34").toString());
|
|
|
|
ui->tableDevices->setItem(dev_nr, 7, newItem );
|
2023-08-03 11:01:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
last_nr_devices = nr_devices;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DialogDevices::validateAndSave()
|
|
|
|
{
|
|
|
|
if (deviceSettings == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
int nr_devices = ui->spinNrDevices->value();
|
|
|
|
int data_ok = 1;
|
|
|
|
|
2023-09-06 17:28:35 +02:00
|
|
|
//check each table row
|
2023-08-03 11:01:50 +02:00
|
|
|
for (int dev_nr = 0; dev_nr < nr_devices; dev_nr++)
|
|
|
|
{
|
2023-09-06 17:28:35 +02:00
|
|
|
//first the IP
|
2023-08-03 11:01:50 +02:00
|
|
|
QString user_data = ui->tableDevices->item(dev_nr,0)->text();
|
|
|
|
QString generated = ip2num(user_data);
|
|
|
|
//if the strings are identical, save the value and return 1
|
|
|
|
if (generated.compare(user_data) != 0)
|
|
|
|
data_ok = 0;
|
|
|
|
ui->tableDevices->item(dev_nr,0)->setText(generated);
|
|
|
|
|
2023-09-06 17:28:35 +02:00
|
|
|
//hardware version
|
2023-08-03 11:01:50 +02:00
|
|
|
user_data = ui->tableDevices->item(dev_nr,1)->text();
|
2023-09-06 17:28:35 +02:00
|
|
|
int num_hw = user_data.toInt();
|
|
|
|
if (num_hw < 1)
|
|
|
|
num_hw = 1;
|
|
|
|
if (num_hw > 2)
|
|
|
|
num_hw = 2;
|
|
|
|
generated = QString("%1").arg(num_hw);
|
|
|
|
//if the strings are identical, save the value and return 1
|
|
|
|
if (generated.compare(user_data) != 0)
|
|
|
|
data_ok = 0;
|
|
|
|
ui->tableDevices->item(dev_nr,1)->setText(generated);
|
|
|
|
|
|
|
|
|
|
|
|
//now the plane
|
|
|
|
user_data = ui->tableDevices->item(dev_nr,2)->text();
|
2023-08-03 11:01:50 +02:00
|
|
|
int num_value = user_data.toInt();
|
|
|
|
if (num_value < 0)
|
|
|
|
num_value = 0;
|
|
|
|
generated = QString("%1").arg(num_value);
|
|
|
|
//if the strings are identical, save the value and return 1
|
|
|
|
if (generated.compare(user_data) != 0)
|
|
|
|
data_ok = 0;
|
2023-09-06 17:28:35 +02:00
|
|
|
ui->tableDevices->item(dev_nr,2)->setText(generated);
|
2023-08-03 11:01:50 +02:00
|
|
|
|
2023-09-06 17:28:35 +02:00
|
|
|
//now physical position
|
|
|
|
user_data = ui->tableDevices->item(dev_nr,3)->text();
|
2023-08-03 11:01:50 +02:00
|
|
|
num_value = user_data.toInt();
|
|
|
|
if (num_value < 0)
|
|
|
|
num_value = 0;
|
|
|
|
generated = QString("%1").arg(num_value);
|
|
|
|
//if the strings are identical, save the value and return 1
|
|
|
|
if (generated.compare(user_data) != 0)
|
|
|
|
data_ok = 0;
|
2023-09-06 17:28:35 +02:00
|
|
|
ui->tableDevices->item(dev_nr,3)->setText(generated);
|
2023-08-03 11:01:50 +02:00
|
|
|
|
2023-09-06 17:28:35 +02:00
|
|
|
//now number of sensors
|
|
|
|
user_data = ui->tableDevices->item(dev_nr,4)->text();
|
2023-08-03 11:01:50 +02:00
|
|
|
num_value = user_data.toInt();
|
2023-09-06 17:28:35 +02:00
|
|
|
int max_sensors = (num_hw == 1) ? 2 : 5;
|
|
|
|
|
2023-08-03 11:01:50 +02:00
|
|
|
if (num_value < 1)
|
|
|
|
num_value = 1;
|
2023-09-06 17:28:35 +02:00
|
|
|
if (num_value > max_sensors)
|
|
|
|
num_value = max_sensors;
|
2023-08-03 11:01:50 +02:00
|
|
|
generated = QString("%1").arg(num_value);
|
|
|
|
//if the strings are identical, save the value and return 1
|
|
|
|
if (generated.compare(user_data) != 0)
|
|
|
|
data_ok = 0;
|
2023-09-06 17:28:35 +02:00
|
|
|
ui->tableDevices->item(dev_nr,4)->setText(generated);
|
2023-08-03 11:01:50 +02:00
|
|
|
|
2023-09-06 17:28:35 +02:00
|
|
|
//now master selector
|
|
|
|
user_data = ui->tableDevices->item(dev_nr,5)->text();
|
2023-08-03 11:01:50 +02:00
|
|
|
num_value = user_data.toInt();
|
|
|
|
if (num_value < 0)
|
|
|
|
num_value = 0;
|
|
|
|
if (num_value > 1)
|
|
|
|
num_value = 1;
|
|
|
|
generated = QString("%1").arg(num_value);
|
|
|
|
//if the strings are identical, save the value and return 1
|
|
|
|
if (generated.compare(user_data) != 0)
|
|
|
|
data_ok = 0;
|
2023-09-06 17:28:35 +02:00
|
|
|
ui->tableDevices->item(dev_nr,5)->setText(generated);
|
2023-08-03 11:01:50 +02:00
|
|
|
|
2023-09-06 17:28:35 +02:00
|
|
|
//now master delay
|
|
|
|
user_data = ui->tableDevices->item(dev_nr,6)->text();
|
2023-08-03 11:01:50 +02:00
|
|
|
num_value = user_data.toInt();
|
|
|
|
if (num_value < 1)
|
|
|
|
num_value = 1;
|
|
|
|
if (num_value > 255)
|
|
|
|
num_value = 255;
|
|
|
|
generated = QString("%1").arg(num_value);
|
|
|
|
//if the strings are identical, save the value and return 1
|
|
|
|
if (generated.compare(user_data) != 0)
|
|
|
|
data_ok = 0;
|
2023-09-06 17:28:35 +02:00
|
|
|
ui->tableDevices->item(dev_nr,6)->setText(generated);
|
2023-08-03 11:01:50 +02:00
|
|
|
|
2023-09-06 17:28:35 +02:00
|
|
|
//now slave delay
|
|
|
|
user_data = ui->tableDevices->item(dev_nr,7)->text();
|
2023-08-03 11:01:50 +02:00
|
|
|
num_value = user_data.toInt();
|
|
|
|
if (num_value < 1)
|
|
|
|
num_value = 1;
|
|
|
|
if (num_value > 255)
|
|
|
|
num_value = 255;
|
|
|
|
generated = QString("%1").arg(num_value);
|
|
|
|
//if the strings are identical, save the value and return 1
|
|
|
|
if (generated.compare(user_data) != 0)
|
|
|
|
data_ok = 0;
|
2023-09-06 17:28:35 +02:00
|
|
|
ui->tableDevices->item(dev_nr,7)->setText(generated);
|
2023-08-03 11:01:50 +02:00
|
|
|
}
|
|
|
|
|
2023-09-06 17:28:35 +02:00
|
|
|
//now store the data
|
2023-08-03 11:01:50 +02:00
|
|
|
if (!data_ok)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
top(deviceSettings);
|
|
|
|
deviceSettings->beginGroup("Global");
|
|
|
|
deviceSettings->setValue("NrDevices", nr_devices);
|
|
|
|
|
|
|
|
for (int dev_nr = 0; dev_nr < nr_devices; dev_nr++)
|
|
|
|
{
|
|
|
|
top(deviceSettings);
|
|
|
|
QString group_label = QString("Device%1").arg(dev_nr);
|
|
|
|
deviceSettings->beginGroup(group_label);
|
|
|
|
|
|
|
|
deviceSettings->setValue("IP", ui->tableDevices->item(dev_nr,0)->text());
|
2023-09-06 17:28:35 +02:00
|
|
|
deviceSettings->setValue("HardwareVer", ui->tableDevices->item(dev_nr,1)->text());
|
|
|
|
deviceSettings->setValue("Plane", ui->tableDevices->item(dev_nr,2)->text());
|
|
|
|
deviceSettings->setValue("Position", ui->tableDevices->item(dev_nr,3)->text());
|
|
|
|
deviceSettings->setValue("Sensors", ui->tableDevices->item(dev_nr,4)->text());
|
|
|
|
deviceSettings->setValue("Master", ui->tableDevices->item(dev_nr,5)->text());
|
|
|
|
deviceSettings->setValue("MasterDelay", ui->tableDevices->item(dev_nr,6)->text());
|
|
|
|
deviceSettings->setValue("SlaveDelay", ui->tableDevices->item(dev_nr,7)->text());
|
|
|
|
}
|
2023-08-03 11:01:50 +02:00
|
|
|
|
2023-09-06 17:28:35 +02:00
|
|
|
//TODO
|
2023-08-03 11:01:50 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DialogDevices::on_spinNrDevices_valueChanged(int arg1)
|
|
|
|
{
|
|
|
|
if (initialized)
|
|
|
|
importSettings();
|
|
|
|
}
|