5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #ifndef _TELEMETRYSIMU_H_
22 #define _TELEMETRYSIMU_H_
24 #include <QCloseEvent>
28 #include <QtCore/qmath.h>
29 #include <QFileDialog>
31 #include "simulatorinterface.h"
33 static double const SPEEDS
[] = { 0.2, 0.4, 0.6, 0.8, 1, 2, 3, 4, 5 };
34 template<class t
> t
LIMIT(t mi
, t x
, t ma
) { return std::min(std::max(mi
, x
), ma
); }
37 class TelemetrySimulator
;
40 class TelemetrySimulator
: public QWidget
46 explicit TelemetrySimulator(QWidget
* parent
, SimulatorInterface
* simulator
);
47 virtual ~TelemetrySimulator();
51 void telemetryDataChanged(const QByteArray data
);
55 virtual void hideEvent(QHideEvent
*event
);
56 virtual void showEvent(QShowEvent
*event
);
57 void onSimulatorStarted();
58 void onSimulatorStopped();
59 void setupDataFields();
60 void onSimulateToggled(bool isChecked
);
61 void onLogTimerEvent();
68 void onPositionIndicatorChanged(int value
);
69 void onReplayRateChanged(int value
);
70 void refreshSensorRatios();
71 void generateTelemetryFrame();
75 Ui::TelemetrySimulator
* ui
;
78 SimulatorInterface
*simulator
;
81 bool m_logReplayEnable
;
83 // protected classes follow
85 class LogPlaybackController
88 LogPlaybackController(Ui::TelemetrySimulator
* ui
);
94 void stepForward(bool focusOnStop
= false);
96 void updatePositionLabel(int32_t percentage
);
97 void setUiDataValues();
98 double logFrequency
; // in seconds
99 bool logFileGpsCordsInDecimalFormat
;
140 struct DATA_TO_FUNC_XREF
{
141 CONVERT_TYPE functionIndex
;
145 double convertFeetToMeters(QString input
);
146 double convertFahrenheitToCelsius(QString input
);
147 QString
convertGPSDate(QString input
);
148 QString
convertGPS(QString input
);
149 void addColumnHash(QString key
, CONVERT_TYPE functionIndex
);
150 double convertDegMin(QString input
);
151 QDateTime
parseTransmittterTimestamp(QString row
);
152 void calcLogFrequency();
153 void checkGpsFormat();
155 QMap
<QString
, CONVERT_TYPE
> colToFuncMap
; // contains all 'known' column headings and how they are to be processed
156 Ui::TelemetrySimulator
* ui
;
157 QStringList csvRecords
; // contents of the log file (one string per line);
158 QStringList columnNames
;
159 QList
<DATA_TO_FUNC_XREF
> supportedCols
;
162 }; // LogPlaybackController
164 LogPlaybackController
*logPlayback
;
169 uint32_t setAllCells_GetNextPair(double cellValues
[6]);
170 static const uint32_t MAXCELLS
= 6;
173 void encodeAllCells();
174 void splitIntoCells(double totalVolts
);
175 static uint32_t encodeCellPair(uint8_t cellNum
, uint8_t firstCellNo
, double cell1
, double cell2
);
176 double cellFloats
[6];
177 uint32_t nextCellNum
;
188 uint32_t getNextPacketData(uint32_t packetType
);
189 void setGPSDateTime(QString dateTime
);
190 void setGPSLatLon(QString latLon
);
191 void setGPSCourse(double course
);
192 void setGPSSpeedKMH(double speed
);
193 void setGPSAltitude(double altitude
);
203 double altitude
; // in meters
204 uint32_t encodeLatLon(double latLon
, bool isLat
);
205 uint32_t encodeDateTime(uint8_t yearOrHour
, uint8_t monthOrMinute
, uint8_t dayOrSecond
, bool isDate
);
208 }; // TelemetrySimulator
210 #endif // _TELEMETRYSIMU_H_