From 23aaee9ecf984c57129810714e413f2814235e43 Mon Sep 17 00:00:00 2001 From: Max Paperno Date: Fri, 6 Jul 2018 14:03:41 -0400 Subject: [PATCH] =?UTF-8?q?[Simulator][TelemetrySimulator]=20Add=20persist?= =?UTF-8?q?ent=20option=20to=20enable=20simulation=20when=20window=20is=20?= =?UTF-8?q?opened;=20Add=20option=20to=20pause=20simulation=20on=20window?= =?UTF-8?q?=20hide=20(was=20always=20true);=20Add=20option=20to=20set=20RS?= =?UTF-8?q?SI=3D0=20on=20simulation=20pause=20to=20trigger=20=E2=80=9Ctele?= =?UTF-8?q?metry=20lost=E2=80=9D=20alarm.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- companion/src/simulation/telemetrysimu.cpp | 83 ++- companion/src/simulation/telemetrysimu.h | 12 +- companion/src/simulation/telemetrysimu.ui | 700 +++++++++++---------- companion/src/storage/appdata.h | 3 + 4 files changed, 431 insertions(+), 367 deletions(-) diff --git a/companion/src/simulation/telemetrysimu.cpp b/companion/src/simulation/telemetrysimu.cpp index 2d5d8f7a4..0cf723c49 100644 --- a/companion/src/simulation/telemetrysimu.cpp +++ b/companion/src/simulation/telemetrysimu.cpp @@ -32,7 +32,6 @@ TelemetrySimulator::TelemetrySimulator(QWidget * parent, SimulatorInterface * si ui(new Ui::TelemetrySimulator), simulator(simulator), m_simuStarted(false), - m_telemEnable(false), m_logReplayEnable(false) { ui->setupUi(this); @@ -48,6 +47,9 @@ TelemetrySimulator::TelemetrySimulator(QWidget * parent, SimulatorInterface * si ui->A1_ratio->setEnabled(false); ui->A2_ratio->setEnabled(false); + ui->Simulate->setChecked(g.currentProfile().telemSimEnabled()); + ui->cbPauseOnHide->setChecked(g.currentProfile().telemSimPauseOnHide()); + ui->cbResetRssiOnStop->setChecked(g.currentProfile().telemSimResetRssiOnStop()); timer.setInterval(10); connect(&timer, &QTimer::timeout, this, &TelemetrySimulator::generateTelemetryFrame); @@ -56,7 +58,12 @@ TelemetrySimulator::TelemetrySimulator(QWidget * parent, SimulatorInterface * si logPlayback = new LogPlaybackController(ui); - connect(ui->Simulate, SIGNAL(toggled(bool)), this, SLOT(onSimulateToggled(bool))); + connect(ui->Simulate, &QCheckBox::toggled, &g.currentProfile(), [=](bool on) { g.currentProfile().telemSimEnabled(on); }); + connect(ui->cbPauseOnHide, &QCheckBox::toggled, &g.currentProfile(), [=](bool on) { g.currentProfile().telemSimPauseOnHide(on); }); + connect(ui->cbResetRssiOnStop, &QCheckBox::toggled, &g.currentProfile(), [=](bool on) { g.currentProfile().telemSimResetRssiOnStop(on); }); + + connect(&g.currentProfile(), &Profile::telemSimEnabledChanged, this, &TelemetrySimulator::onSimulateToggled); + connect(ui->loadLogFile, SIGNAL(released()), this, SLOT(onLoadLogFile())); connect(ui->play, SIGNAL(released()), this, SLOT(onPlay())); connect(ui->rewind, SIGNAL(clicked()), this, SLOT(onRewind())); @@ -73,12 +80,50 @@ TelemetrySimulator::TelemetrySimulator(QWidget * parent, SimulatorInterface * si TelemetrySimulator::~TelemetrySimulator() { - timer.stop(); - logTimer.stop(); + stopTelemetry(); delete logPlayback; delete ui; } +void TelemetrySimulator::hideEvent(QHideEvent *event) +{ + if (g.currentProfile().telemSimPauseOnHide()) + stopTelemetry(); + event->accept(); +} + +void TelemetrySimulator::showEvent(QShowEvent * event) +{ + if (g.currentProfile().telemSimEnabled()) + startTelemetry(); +} + +void TelemetrySimulator::startTelemetry() +{ + timer.start(); + if (m_logReplayEnable) + onPlay(); +} + +void TelemetrySimulator::stopTelemetry() +{ + timer.stop(); + m_logReplayEnable = logTimer.isActive(); + onStop(); + + if (!(g.currentProfile().telemSimResetRssiOnStop() && ui && ui->rssi_inst)) + return; + + bool ok = false; + const int id = ui->rssi_inst->text().toInt(&ok, 0); + if (!ok) + return; + + uint8_t buffer[FRSKY_SPORT_PACKET_SIZE] = {0}; + generateSportPacket(buffer, id - 1, DATA_FRAME, RSSI_ID, 0); + emit telemetryDataChanged(QByteArray((char *)buffer, FRSKY_SPORT_PACKET_SIZE)); +} + void TelemetrySimulator::onSimulatorStarted() { m_simuStarted = true; @@ -92,12 +137,10 @@ void TelemetrySimulator::onSimulatorStopped() void TelemetrySimulator::onSimulateToggled(bool isChecked) { - if (isChecked) { - timer.start(); - } - else { - timer.stop(); - } + if (isChecked) + startTelemetry(); + else + stopTelemetry(); } void TelemetrySimulator::onLogTimerEvent() @@ -113,6 +156,7 @@ void TelemetrySimulator::onLoadLogFile() void TelemetrySimulator::onPlay() { + ui->Simulate->setChecked(true); if (logPlayback->isReady()) { logTimer.start(logPlayback->logFrequency * 1000 / SPEEDS[ui->replayRate->value()]); logPlayback->play(); @@ -166,23 +210,6 @@ void TelemetrySimulator::onReplayRateChanged(int value) } } -void TelemetrySimulator::hideEvent(QHideEvent *event) -{ - m_telemEnable = ui->Simulate->isChecked(); - m_logReplayEnable = logTimer.isActive(); - - ui->Simulate->setChecked(false); - ui->stop->click(); - event->accept(); -} - -void TelemetrySimulator::showEvent(QShowEvent * event) -{ - ui->Simulate->setChecked(m_telemEnable); - if (m_logReplayEnable) - ui->play->click(); -} - #define SET_INSTANCE(control, id, def) ui->control->setText(QString::number(simulator->getSensorInstance(id, ((def) & 0x1F) + 1))) void TelemetrySimulator::setupDataFields() @@ -235,7 +262,7 @@ uint8_t getBit(uint8_t position, uint8_t value) return (value & (uint8_t)(1 << position)) ? 1 : 0; } -bool generateSportPacket(uint8_t * packet, uint8_t dataId, uint8_t prim, uint16_t appId, uint32_t data) +bool TelemetrySimulator::generateSportPacket(uint8_t * packet, uint8_t dataId, uint8_t prim, uint16_t appId, uint32_t data) { if (dataId > 0x1B ) return false; diff --git a/companion/src/simulation/telemetrysimu.h b/companion/src/simulation/telemetrysimu.h index 1ff3c78e4..c317e2fb5 100644 --- a/companion/src/simulation/telemetrysimu.h +++ b/companion/src/simulation/telemetrysimu.h @@ -46,14 +46,18 @@ class TelemetrySimulator : public QWidget explicit TelemetrySimulator(QWidget * parent, SimulatorInterface * simulator); virtual ~TelemetrySimulator(); - signals: + public slots: + bool generateSportPacket(uint8_t * packet, uint8_t dataId, uint8_t prim, uint16_t appId, uint32_t data); + signals: void telemetryDataChanged(const QByteArray data); protected slots: - virtual void hideEvent(QHideEvent *event); - virtual void showEvent(QShowEvent *event); + void hideEvent(QHideEvent *event) override; + void showEvent(QShowEvent *event) override; + void startTelemetry(); + void stopTelemetry(); void onSimulatorStarted(); void onSimulatorStopped(); void setupDataFields(); @@ -77,7 +81,6 @@ class TelemetrySimulator : public QWidget QTimer logTimer; SimulatorInterface *simulator; bool m_simuStarted; - bool m_telemEnable; bool m_logReplayEnable; // protected classes follow @@ -204,7 +207,6 @@ 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 - }; // TelemetrySimulator #endif // _TELEMETRYSIMU_H_ diff --git a/companion/src/simulation/telemetrysimu.ui b/companion/src/simulation/telemetrysimu.ui index 3ad9ae83e..c192c9acb 100644 --- a/companion/src/simulation/telemetrysimu.ui +++ b/companion/src/simulation/telemetrysimu.ui @@ -18,7 +18,7 @@ Telemetry Simulator - + 7 @@ -37,7 +37,7 @@ 7 - + @@ -58,334 +58,7 @@ - - - - - 0 - 0 - - - - - 8 - - - - Replay SD Log File - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - 0 - - - 3 - - - 0 - - - - - - 8 - - - - Replay rate - - - Qt::AlignCenter - - - - - - - - 0 - 0 - - - - Load - - - false - - - - - - - false - - - - 0 - 0 - - - - 8 - - - 1 - - - 4 - - - Qt::Horizontal - - - - - - - 4 - - - - - QLayout::SetMinimumSize - - - - - false - - - - 30 - 16777215 - - - - Qt::StrongFocus - - - |> - - - false - - - true - - - false - - - - - - - false - - - - 30 - 16777215 - - - - Qt::StrongFocus - - - <| - - - false - - - true - - - false - - - - - - - false - - - - 0 - 0 - - - - - 30 - 16777215 - - - - Qt::StrongFocus - - - > - - - true - - - true - - - false - - - - - - - false - - - - 0 - 0 - - - - - 30 - 16777215 - - - - Qt::StrongFocus - - - <- - - - false - - - true - - - false - - - false - - - - - - - false - - - - 30 - 16777215 - - - - Qt::StrongFocus - - - X - - - true - - - true - - - false - - - - - - - - - false - - - Qt::Horizontal - - - - - - - - 8 - - - - Qt::LeftToRight - - - Row # -Timestamp - - - Qt::AlignCenter - - - - - - - - - - 0 - 0 - - - - 1/5x - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - 5x - - - - - - - - 8 - - - - No Log File Currently Loaded - - - - - - - + @@ -434,8 +107,8 @@ Timestamp 0 0 - 346 - 370 + 329 + 412 @@ -1729,8 +1402,8 @@ Timestamp 0 0 - 339 - 370 + 330 + 384 @@ -2954,6 +2627,365 @@ hh:mm:ss + + + + + 0 + 0 + + + + + 8 + + + + Replay SD Log File + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + 0 + + + 3 + + + 0 + + + + + + 8 + + + + Replay rate + + + Qt::AlignCenter + + + + + + + + 0 + 0 + + + + Load + + + false + + + + + + + false + + + + 0 + 0 + + + + 8 + + + 1 + + + 4 + + + Qt::Horizontal + + + + + + + 4 + + + + + QLayout::SetMinimumSize + + + + + false + + + + 30 + 16777215 + + + + Qt::StrongFocus + + + |> + + + false + + + true + + + false + + + + + + + false + + + + 30 + 16777215 + + + + Qt::StrongFocus + + + <| + + + false + + + true + + + false + + + + + + + false + + + + 0 + 0 + + + + + 30 + 16777215 + + + + Qt::StrongFocus + + + > + + + true + + + true + + + false + + + + + + + false + + + + 0 + 0 + + + + + 30 + 16777215 + + + + Qt::StrongFocus + + + <- + + + false + + + true + + + false + + + false + + + + + + + false + + + + 30 + 16777215 + + + + Qt::StrongFocus + + + X + + + true + + + true + + + false + + + + + + + + + false + + + Qt::Horizontal + + + + + + + + 8 + + + + Qt::LeftToRight + + + Row # +Timestamp + + + Qt::AlignCenter + + + + + + + + + + 0 + 0 + + + + 1/5x + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + 5x + + + + + + + + 8 + + + + No Log File Currently Loaded + + + + + + + + + + + 0 + 0 + + + + Setting RSSI to zero simulates telemetry and radio link loss. + + + Set RSSI to zero when paused. + + + + + + + + 0 + 0 + + + + Stop sending telemetry data when the Telemetry Simulator window is hidden. + + + Pause simulation when hidden. + + + diff --git a/companion/src/storage/appdata.h b/companion/src/storage/appdata.h index 8818a416c..5107450a8 100644 --- a/companion/src/storage/appdata.h +++ b/companion/src/storage/appdata.h @@ -383,6 +383,9 @@ class Profile: public CompStoreObj // Simulator variables PROPERTY(SimulatorOptions, simulatorOptions, SimulatorOptions()) + PROPERTY(bool, telemSimEnabled, false) + PROPERTY(bool, telemSimPauseOnHide, true) + PROPERTY(bool, telemSimResetRssiOnStop, false) // Firmware Variables PROPERTYSTR2(beeper, "Beeper")