Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
391 | Brean | 1 | #include<Handler.h> |
2 | |||
3 | /** |
||
392 | Brean | 4 | * Constructor that gets a communication instance |
5 | */ |
||
6 | Handler::Handler(Communication * com) { |
||
7 | this->com = com; |
||
8 | } |
||
9 | |||
10 | /** |
||
391 | Brean | 11 | * read mixer values from FlightCtrl |
12 | */ |
||
13 | void Handler::read_mixer() { |
||
396 | Brean | 14 | char tx_data[1] = {0}; |
15 | //com->log("read motor mixer"); |
||
16 | com->sendCmd('n', ADDRESS_FC, tx_data, 1, true); |
||
393 | Brean | 17 | } |
18 | |||
396 | Brean | 19 | void Handler::get_motor_config() { |
20 | } |
||
21 | |||
393 | Brean | 22 | void Handler::receive_data(sRxData RX) { |
23 | //extract hardware ID from received Data |
||
24 | int hardwareID = RX.input[1] - 'a'; |
||
25 | switch(hardwareID) |
||
26 | { |
||
27 | case ADDRESS_FC : |
||
28 | switch(RX.input[2]) |
||
29 | { |
||
30 | // Motor-Mixer |
||
31 | case 'N' : |
||
32 | if (Parser::decode64(RX)) |
||
33 | { |
||
34 | com->stopReSend(); |
||
35 | |||
36 | if (RX.decode[0] == VERSION_MIXER) |
||
37 | { |
||
396 | Brean | 38 | //f_MotorMixer->set_MotorConfig(RX); |
393 | Brean | 39 | } |
40 | } |
||
41 | break; |
||
42 | // Motor-Mixer Schreib-Bestätigung |
||
43 | case 'M' : |
||
44 | if (Parser::decode64(RX)) |
||
45 | { |
||
46 | com->stopReSend(); |
||
47 | |||
48 | if (RX.decode[0] == 1) |
||
49 | { |
||
396 | Brean | 50 | //lb_Status->setText(tr("MotorMixer-Daten in FC geschrieben.")); |
393 | Brean | 51 | } |
52 | } |
||
53 | break; |
||
54 | |||
55 | // Stick-Belegung der Fernsteuerung |
||
56 | case 'P' : // DONE 0.71g |
||
57 | if (Parser::decode64(RX)) |
||
58 | { |
||
396 | Brean | 59 | /*f_Settings->pb_K1->setValue(Parser::dataToInt(RX.decode, 2,true)); |
393 | Brean | 60 | f_Settings->pb_K2->setValue(Parser::dataToInt(RX.decode, 4,true)); |
61 | f_Settings->pb_K3->setValue(Parser::dataToInt(RX.decode, 6,true)); |
||
62 | f_Settings->pb_K4->setValue(Parser::dataToInt(RX.decode, 8,true)); |
||
63 | f_Settings->pb_K5->setValue(Parser::dataToInt(RX.decode, 10 ,true)); |
||
64 | f_Settings->pb_K6->setValue(Parser::dataToInt(RX.decode, 12,true)); |
||
65 | f_Settings->pb_K7->setValue(Parser::dataToInt(RX.decode, 14,true)); |
||
396 | Brean | 66 | f_Settings->pb_K8->setValue(Parser::dataToInt(RX.decode, 16,true));*/ |
393 | Brean | 67 | } |
68 | break; |
||
69 | // Settings lesen |
||
70 | case 'Q' : // DONE 0.71g |
||
71 | if (Parser::decode64(RX)) |
||
72 | { |
||
396 | Brean | 73 | com->stopReSend(); |
393 | Brean | 74 | |
75 | if (RX.decode[1] == VERSION_SETTINGS) |
||
76 | { |
||
77 | int Settings_ID = RX.decode[0]; |
||
396 | Brean | 78 | /*for (int a = 0; a < MaxParameter; a++) |
393 | Brean | 79 | { |
80 | FCSettings[a] = RX.decode[a + 2]; |
||
81 | } |
||
82 | f_Settings->show_FCSettings(Settings_ID, FCSettings); |
||
83 | f_Settings->pb_Read->setEnabled(true); |
||
396 | Brean | 84 | f_Settings->pb_Write->setEnabled(true);*/ |
393 | Brean | 85 | } |
86 | else |
||
87 | { |
||
396 | Brean | 88 | /*f_Settings->pb_Read->setDisabled(true); |
393 | Brean | 89 | f_Settings->pb_Write->setDisabled(true); |
90 | |||
91 | QString name = QString("Versionen inkompatibel.\n") + |
||
92 | QString("Version von GroundStation benoetigt: ") + |
||
93 | QString(VERSION_SETTINGS) + |
||
94 | QString("\nVersion auf der FlightCtrl: ") + |
||
95 | QString(RX.decode[1]) + |
||
96 | QString("\nParameterbearbeitung nicht moeglich."); |
||
97 | QMessageBox::warning(this, QA_NAME, |
||
396 | Brean | 98 | name, QMessageBox::Ok);*/ |
393 | Brean | 99 | } |
100 | } |
||
101 | break; |
||
396 | Brean | 102 | // Settings written |
393 | Brean | 103 | case 'S' : // DONE 0.71g |
396 | Brean | 104 | com->stopReSend(); |
105 | //TODO: QMessagebox("settings written successful") ? |
||
393 | Brean | 106 | break; |
107 | } |
||
108 | |||
109 | case ADDRESS_NC : |
||
110 | switch(RX.input[2]) |
||
111 | { |
||
112 | // Navigationsdaten |
||
113 | case 'O' : // NOT DONE 0.12h |
||
114 | if (Parser::decode64(RX)) |
||
115 | { |
||
396 | Brean | 116 | //new_NaviData(RX); |
393 | Brean | 117 | } |
118 | break; |
||
119 | } |
||
120 | // case ADDRESS_MK3MAG : |
||
121 | |||
122 | default : |
||
123 | switch(RX.input[2]) |
||
124 | { |
||
125 | // LCD-Anzeige |
||
126 | case 'L' : // DONE 0.71g |
||
127 | if (Parser::decode64(RX)) |
||
128 | { |
||
396 | Brean | 129 | com->stopReSend(); |
393 | Brean | 130 | |
396 | Brean | 131 | /*int LCD[150]; |
393 | Brean | 132 | memcpy(LCD,RX.decode, sizeof(RX.decode)); |
133 | |||
134 | f_LCD->show_Data(LCD); |
||
135 | |||
136 | LCD_Page = RX.decode[0]; |
||
137 | LCD_MAX_Page = RX.decode[1]; |
||
396 | Brean | 138 | */ |
393 | Brean | 139 | } |
140 | break; |
||
141 | // Analoglabels |
||
142 | case 'A' : // DONE 0.71g |
||
143 | if (Parser::decode64(RX)) |
||
144 | { |
||
396 | Brean | 145 | com->stopReSend(); |
393 | Brean | 146 | |
147 | int Position = RX.decode[0]; |
||
148 | if (Position != 31) |
||
149 | { |
||
396 | Brean | 150 | /* |
393 | Brean | 151 | Settings->Analog1.Label[Position] = ToolBox::dataToQString(RX.decode,1,17).trimmed(); |
152 | if (Settings->Analog1.Label[Position] == "") |
||
153 | { |
||
154 | Settings->Analog1.Label[Position] = "A-" + QString("%1").arg(Position); |
||
155 | } |
||
156 | Position ++; |
||
157 | TX_Data[0] = Position; |
||
396 | Brean | 158 | o_Connection->send_Cmd('a', ADDRESS_ALL, TX_Data, 1, true);*/ |
393 | Brean | 159 | } |
160 | if (Position == 31) |
||
161 | { |
||
396 | Brean | 162 | /* |
393 | Brean | 163 | for (int a = 0; a < MaxAnalog; a++) |
164 | { |
||
165 | lb_Analog[a]->setText(Settings->Analog1.Label[a]); |
||
166 | } |
||
167 | Settings->Analog1.Version = QString(Mode.Version); |
||
168 | Settings->write_Settings_AnalogLabels(HardwareID); |
||
396 | Brean | 169 | config_Plot();*/ |
393 | Brean | 170 | } |
171 | } |
||
172 | break; |
||
173 | // Debug-Daten |
||
174 | case 'D' : // DONE 0.71g |
||
175 | if (Parser::decode64(RX)) |
||
176 | { |
||
177 | for (int i = 0; i < MaxAnalog; i++) |
||
178 | { |
||
396 | Brean | 179 | //AnalogData[i] = Parser::dataToInt(RX.decode, (i * 2) + 2); |
393 | Brean | 180 | } |
396 | Brean | 181 | //show_DebugData(); |
393 | Brean | 182 | } |
183 | break; |
||
184 | // Version |
||
185 | case 'V' : // DONE 0.71h |
||
186 | if (Parser::decode64(RX)) |
||
187 | { |
||
396 | Brean | 188 | com->stopReSend(); |
189 | /* |
||
393 | Brean | 190 | Mode.ID = HardwareID; |
191 | Mode.VERSION_MAJOR = RX.decode[0]; |
||
192 | Mode.VERSION_MINOR = RX.decode[1]; |
||
193 | Mode.VERSION_PATCH = RX.decode[4]; |
||
194 | Mode.VERSION_SERIAL_MAJOR = RX.decode[2]; |
||
195 | Mode.VERSION_SERIAL_MINOR = RX.decode[3]; |
||
196 | |||
197 | Mode.Hardware = HardwareType[Mode.ID]; |
||
198 | //TODO: Funktion im Handler get_version() oder sowas |
||
199 | QString version = QString("%1").arg(RX.decode[0]) + "." + |
||
200 | QString("%1").arg(RX.decode[1]) + |
||
201 | QString(RX.decode[4] + 'a'); |
||
202 | Mode.Version = version.toLatin1().data; |
||
203 | setWindowTitle(QA_NAME + " v" + QA_VERSION + " - " + |
||
204 | Mode.Hardware + " " + |
||
205 | Mode.Version); |
||
206 | |||
207 | if (Mode.VERSION_SERIAL_MAJOR != VERSION_SERIAL_MAJOR) |
||
208 | { |
||
209 | // AllowSend = false; |
||
210 | QMessageBox::warning(this, QA_NAME, |
||
211 | tr("Serielles Protokoll Inkompatibel. \nBitte neue Programmversion installieren,"), QMessageBox::Ok); |
||
212 | } |
||
213 | |||
214 | if (ac_NoDebug->isChecked()) |
||
215 | { |
||
216 | TX_Data[0] = 0; |
||
217 | } |
||
218 | else |
||
219 | if (ac_FastDebug->isChecked()) |
||
220 | { |
||
221 | TX_Data[0] = Settings->Data.Debug_Fast / 10; |
||
222 | } |
||
223 | else |
||
224 | { |
||
225 | TX_Data[0] = Settings->Data.Debug_Slow / 10; |
||
226 | } |
||
227 | |||
228 | o_Connection->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false); |
||
229 | |||
230 | // Wenn MK3MAG dann andauernd Daten neu anfragen. |
||
231 | if (Mode.ID == ADDRESS_MK3MAG) |
||
232 | { |
||
233 | TickerEvent[3] = true; |
||
234 | rb_SelMag->setChecked(true); |
||
235 | } |
||
236 | |||
237 | // Wenn NaviCtrl dann hier. |
||
238 | if (Mode.ID == ADDRESS_NC) |
||
239 | { |
||
240 | rb_SelNC->setChecked(true); |
||
241 | |||
242 | if (ac_NoNavi->isChecked()) |
||
243 | { |
||
244 | TX_Data[0] = 0; |
||
245 | } |
||
246 | else |
||
247 | if (ac_FastNavi->isChecked()) |
||
248 | { |
||
249 | TX_Data[0] = Settings->Data.Navi_Fast / 10; |
||
250 | } |
||
251 | else |
||
252 | { |
||
253 | TX_Data[0] = Settings->Data.Navi_Slow / 10; |
||
254 | } |
||
255 | |||
256 | o_Connection->send_Cmd('o', ADDRESS_NC, TX_Data, 1, false); |
||
257 | } |
||
258 | |||
259 | |||
260 | // Wenn FlightCtrl dann Settings abfragen. |
||
261 | if (Mode.ID == ADDRESS_FC) |
||
262 | { |
||
263 | rb_SelFC->setChecked(true); |
||
264 | { |
||
265 | TX_Data[0] = 0xff; |
||
266 | TX_Data[1] = 0; |
||
267 | |||
268 | // DEP: Raus wenn Resend implementiert. |
||
269 | // ToolBox::Wait(SLEEP); |
||
270 | o_Connection->send_Cmd('q', ADDRESS_FC, TX_Data, 1, true); |
||
271 | qDebug("FC - Get Settings"); |
||
272 | } |
||
273 | } |
||
274 | // Wenn nicht Lesen und Schreiben der Settings deaktivieren. |
||
275 | else |
||
276 | { |
||
277 | f_Settings->pb_Read->setDisabled(true); |
||
278 | f_Settings->pb_Write->setDisabled(true); |
||
279 | } |
||
280 | |||
281 | Settings->read_Settings_Analog(HardwareID); |
||
282 | Settings->read_Settings_AnalogLabels(HardwareID); |
||
283 | |||
284 | if (Settings->Analog1.Version != QString(Mode.Version)) |
||
285 | { |
||
286 | lb_Status->setText(tr("Analoglabel-Version unterschiedlich. Lese Analoglabels neu aus.")); |
||
287 | slot_ac_GetLabels(); |
||
288 | } |
||
289 | else |
||
290 | for (int a = 0; a < MaxAnalog; a++) |
||
291 | { |
||
292 | lb_Analog[a]->setText(Settings->Analog1.Label[a]); |
||
293 | } |
||
396 | Brean | 294 | config_Plot();*/ |
393 | Brean | 295 | } |
296 | break; |
||
297 | } |
||
298 | } |
||
391 | Brean | 299 | } |