Skip to content

Commit

Permalink
Save and reload telemetry values in companion telemetry simulator (#1954
Browse files Browse the repository at this point in the history
)

* Users will be able to save and reload telemetry values in companion telemetry simulator. Also, default values set for all sensor values.

* Added file.flush()

* Edited file i/o as per elecpower suggestion
Signed-off-by: dale wheeler <dale@wheeler.net>
  • Loading branch information
dwheeld authored Jun 15, 2022
1 parent f6988c0 commit 940d69f
Show file tree
Hide file tree
Showing 3 changed files with 677 additions and 335 deletions.
234 changes: 234 additions & 0 deletions companion/src/simulation/telemetrysimu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <QRegularExpression>
#include <stdint.h>

#include <QMessageBox> //

TelemetrySimulator::TelemetrySimulator(QWidget * parent, SimulatorInterface * simulator):
QWidget(parent),
ui(new Ui::TelemetrySimulator),
Expand Down Expand Up @@ -1089,3 +1091,235 @@ void TelemetrySimulator::LogPlaybackController::setUiDataValues()
}
}
}

void TelemetrySimulator::on_saveTelemetryvalues_clicked()
{
QString fldr = g.backupDir().trimmed();
if (fldr.isEmpty())
fldr = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);

QString idFileNameAndPath = QFileDialog::getSaveFileName(this, tr("Save Telemetry"), fldr % "/telemetry.txt", tr(".txt Files (*.txt)"));
if (idFileNameAndPath.isEmpty())
return;

QFile file(idFileNameAndPath);
if (!file.open(QIODevice::WriteOnly)){
QMessageBox::critical(this, CPN_STR_APP_NAME, tr("Unable to open file for writing.\n%1").arg(file.errorString()));
return;
}
QTextStream out(&file);

out<< ui -> rxbt -> text();
out<<"\r\n";
out<< ui -> Rssi -> text();
out<<"\r\n";
out<< ui -> Swr -> text();
out<<"\r\n";
out << ui -> A1 -> text();
out<<"\r\n";
out<< ui -> A2 -> text();
out<<"\r\n";
out<< ui -> A3 -> text();
out<<"\r\n";
out << ui -> A4 -> text();
out<<"\r\n";
out << ui -> T1 -> text();
out<<"\r\n";
out << ui -> T2 -> text();
out<<"\r\n";
out << ui -> rpm -> text();
out<<"\r\n";
out << ui -> fuel -> text();
out<<"\r\n";
out << ui -> fuel_qty -> text();
out<<"\r\n";
out << ui -> vspeed -> text();
out<<"\r\n";
out << ui -> valt -> text();
out<<"\r\n";
out << ui -> vfas -> text();
out<<"\r\n";
out << ui -> curr -> text();
out<<"\r\n";
out << ui -> cell1 -> text();
out<<"\r\n";
out << ui -> cell2 -> text();
out<<"\r\n";
out << ui -> cell3 -> text();
out<<"\r\n";
out << ui -> cell4 -> text();
out<<"\r\n";
out << ui -> cell5 -> text();
out<<"\r\n";
out << ui -> cell6 -> text();
out<<"\r\n";
out << ui -> aspeed -> text();
out<<"\r\n";
out << ui -> gps_alt -> text();
out<<"\r\n";
out << ui -> gps_speed -> text();
out<<"\r\n";
out << ui -> gps_course -> text();
out<<"\r\n";
out << ui -> gps_time -> text();
out<<"\r\n";
out << ui -> gps_latlon -> text();
out<<"\r\n";
out << ui -> accx -> text();
out<<"\r\n";
out << ui -> accy -> text();
out<<"\r\n";
out << ui -> accz -> text();
out<<"\r\n";
file.flush();

file.close();

}


void TelemetrySimulator::on_loadTelemetryvalues_clicked()
{
QString fldr = g.backupDir().trimmed();
if (fldr.isEmpty())
fldr = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);

QString idFileNameAndPath = QFileDialog::getOpenFileName(this, tr("Open Telemetry File"), fldr % "/telemetry.txt", tr(".txt Files (*.txt)"));
if (idFileNameAndPath.isEmpty())
return;

QFile file(idFileNameAndPath);

if (!file.open(QIODevice::ReadOnly)){
QMessageBox::critical(this, CPN_STR_APP_NAME, tr("Unable to open file for reading.\n%1").arg(file.errorString()));
return;
}

QTextStream in(&file);

QString n = in.readLine();
double ns = n.toDouble();
ui -> rxbt -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> Rssi -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> Swr -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> A1 -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> A2 -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> A3 -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> A4 -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> T1 -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> T2 -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> rpm -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> fuel -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> fuel_qty -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> vspeed -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> valt -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> vfas -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> curr -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> cell1 -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> cell2 -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> cell3 -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> cell4 -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> cell5 -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> cell6 -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> aspeed -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> gps_alt -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> gps_speed -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> gps_course -> setValue(ns);

n = in.readLine();
ui -> gps_time -> setText(n);

n = in.readLine();
ui -> gps_latlon -> setText(n);

n = in.readLine();
ns = n.toDouble();
ui -> accx -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> accy -> setValue(ns);

n = in.readLine();
ns = n.toDouble();
ui -> accz -> setValue(ns);

file.close();

}

3 changes: 3 additions & 0 deletions companion/src/simulation/telemetrysimu.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ class TelemetrySimulator : public QWidget
uint32_t encodeLatLon(double latLon, bool isLat);
uint32_t encodeDateTime(uint8_t yearOrHour, uint8_t monthOrMinute, uint8_t dayOrSecond, bool isDate);
}; // GPSEmulator
private slots:
void on_saveTelemetryvalues_clicked();
void on_loadTelemetryvalues_clicked();
}; // TelemetrySimulator

#endif // _TELEMETRYSIMU_H_
Expand Down
Loading

0 comments on commit 940d69f

Please sign in to comment.