Make TX volatge for simu more flexible (#7124)
[opentx.git] / companion / src / firmwares / radiodataconversionstate.h
blobdd319d115245ae850561847c0a8cc1820d7fc171
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
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 RADIODATACONVERSIONSTATE_H
22 #define RADIODATACONVERSIONSTATE_H
24 #include "boards.h"
25 #include <QtCore>
27 class ModelData;
28 class GeneralSettings;
29 class RadioData;
30 class QStandardItemModel;
32 class RadioDataConversionState
34 Q_DECLARE_TR_FUNCTIONS(RadioDataConversionState)
36 public:
37 enum EventType {
38 EVT_NONE, // does not get logged
39 EVT_DBG, // debug
40 EVT_INF, // misc. info
41 EVT_WRN, // misc. warning, place warning-level events after this and before EVT_ERR
42 EVT_CVRT, // something was converted (A->B)
43 EVT_ERR, // misc. error, place error-level events after this
44 EVT_INV, // invalid, control/etc not available on destination radio
47 enum LogFieldType {
48 FLD_EVT_TYPE, // EventType
49 FLD_ORIGIN, // General Settings or Model with name
50 FLD_COMP, // Input/Mix/LS/CF/etc
51 FLD_SUB_COMP, // Mix channel/Input line/LS number/etc
52 FLD_COMP_FIELD, // optional item within subcomponent, eg. LS V1/V2/AND, etc
53 FLD_ITM_TYPE, // Source/Switch
54 FLD_ITM_BEFORE, // item before conversion
55 FLD_MSG, // conversion details
56 FLD_ITM_AFTER, // item after conversion
57 FLD_ENUM_COUNT
60 struct LogField {
61 LogField(int id = 0, const QString & name = QString()) : id(id), name(name) {}
62 void clear() { id = 0; name.clear(); }
63 int id;
64 QString name;
67 struct LogRecord
69 LogRecord() { fields.resize(FLD_ENUM_COUNT); }
70 QVector<LogField> fields; // collected data fields indexed by LogColumn value
73 RadioDataConversionState(Board::Type before = Board::BOARD_UNKNOWN, Board::Type after = Board::BOARD_UNKNOWN, RadioData * rdata = NULL);
74 ~RadioDataConversionState();
76 RadioDataConversionState & withModelIndex(int index);
77 RadioDataConversionState & withComponentIndex(int index);
78 RadioDataConversionState & withComponentField(const QString & name);
80 bool convert();
81 void setRadioData(RadioData * rdata);
82 void setLogField(LogFieldType type, const LogField & data = LogField(), bool clearRest = true);
83 inline void setOrigin(const QString & name = QString()) { setLogField(FLD_ORIGIN, LogField(modelIdx, name)); }
84 inline void setSubComp(const QString & name = QString()) { setLogField(FLD_SUB_COMP, LogField(subCompIdx, name)); }
85 inline void setComponent(const QString & name = QString(), int id = 0) { setLogField(FLD_COMP, LogField(id, name)); }
86 inline void setItemType(const QString & name = QString(), int id = 0) { setLogField(FLD_ITM_TYPE, LogField(id, name)); }
88 void addLogEntry(EventType event, const QString & msg = QString());
89 void setInvalid(const LogField & item);
90 void setConverted(const LogField & from, const LogField & to);
91 void setMoved(const LogField & from, const LogField & to);
92 inline void setDbg(const QString & msg) { addLogEntry(EVT_DBG, msg); }
93 inline void setInf(const QString & msg) { addLogEntry(EVT_INF, msg); }
94 inline void setWrn(const QString & msg) { addLogEntry(EVT_WRN, msg); }
95 inline void setErr(const QString & msg) { addLogEntry(EVT_ERR, msg); }
97 const ModelData * toModel() const;
98 const ModelData * fromModel() const;
99 const GeneralSettings * toGS() const;
100 const GeneralSettings * fromGS() const;
101 bool hasLogEntries(EventType logLevel = EVT_INF) const;
103 QString eventTypeToString(int type) const;
104 QString eventTypeToColor(int type) const;
105 QString getFieldName(int field) const;
106 QStandardItemModel * getLogModel(EventType logLevel = EVT_INF, QObject *parent = Q_NULLPTR) const;
108 Board::Type fromType; // board type before conversion
109 Board::Type toType; // board type after
110 Boards fromBoard;
111 Boards toBoard;
112 RadioData * rd; // pointer to data struct being converted
113 RadioData * rdCopy; // copy of original radio data before conversion
114 QVector<LogRecord> log; // logged events
115 LogRecord logCache; // buffer for holding event data before logging
116 EventType maxEventType; // most severe event type recorded
117 int modelIdx; // model index in radio data array, -1 if none
118 int subCompIdx; // current row index within component (eg. model.mixData[componentIdx]), -1 if none
121 #endif // RADIODATACONVERSIONSTATE_H