Subversion Repositories Projects

Rev

Rev 513 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 513 Rev 524
1
#include "Handler.h"
1
#include "Handler.h"
2
#include "FlightLog.h"
2
#include "FlightLog.h"
3
#include <sstream>
3
#include <sstream>
4
#include <string>
4
#include <string>
5
 
5
 
6
/**
6
/**
7
 * Constructor that gets a communication instance
7
 * Constructor that gets a communication instance
8
 */
8
 */
9
Handler::Handler(Communication * com, KopterData * data) {
9
Handler::Handler(Communication * com, KopterData * data) {
10
    this->com = com;
10
    this->com = com;
11
    this->data = data;
11
    this->data = data;
12
}
12
}
13
 
13
 
14
//-------------FlightCtrl commands--------------------
14
//-------------FlightCtrl commands--------------------
15
/**
15
/**
16
 * read settings from FlightCtrl (settings index 0x00-0x05)
16
 * read settings from FlightCtrl (settings index 0x00-0x05)
17
 */
17
 */
18
void Handler::get_flightctrl_settings(int index) {
18
void Handler::get_flightctrl_settings(int index) {
19
    FlightLog::info_FC("getting FlightCtrl settings");
19
    FlightLog::info_FC("getting FlightCtrl settings");
20
    char tx_data[2] = {index, 0};
20
    char tx_data[2] = {index, 0};
21
    com->send_cmd('q', ADDRESS_FC, tx_data, 1, true);
21
    com->send_cmd('q', ADDRESS_FC, tx_data, 1, true);
22
}
22
}
23
 
23
 
24
/**
24
/**
25
 * write settings to FlightCtrl
25
 * write settings to FlightCtrl
26
 */
26
 */
27
void Handler::set_flightctrl_settings(char * tx_data) {
27
void Handler::set_flightctrl_settings(char * tx_data) {
28
    FlightLog::info_FC("setting FlightCtrl settings");
28
    FlightLog::info_FC("setting FlightCtrl settings");
29
    com->send_cmd('s', ADDRESS_FC, tx_data, MaxParameter+2, true);
29
    com->send_cmd('s', ADDRESS_FC, tx_data, MaxParameter+2, true);
30
}
30
}
31
 
31
 
32
/**
32
/**
33
 * test one or more motors
33
 * test one or more motors
34
 */
34
 */
35
void Handler::motor_test(sMotorData motor) {
35
void Handler::motor_test(sMotorData motor) {
36
    char tx_data[MAX_MOTORS];
36
    char tx_data[MAX_MOTORS];
37
    for (int z = 0; z<MAX_MOTORS; z++)
37
    for (int z = 0; z<MAX_MOTORS; z++)
38
    {
38
    {
39
        tx_data[z] = motor.desired_speed[z];
39
        tx_data[z] = motor.desired_speed[z];
40
    }
40
    }
41
    FlightLog::info_FC("testing motor");
41
    FlightLog::info_FC("testing motor");
42
    com->send_cmd('t', ADDRESS_FC, tx_data, MAX_MOTORS, false);
42
    com->send_cmd('t', ADDRESS_FC, tx_data, MAX_MOTORS, false);
43
}
43
}
44
 
44
 
45
void Handler::reset_motor() {
45
void Handler::reset_motor() {
46
    for (int z = 0; z<MAX_MOTORS; z++)
46
    for (int z = 0; z<MAX_MOTORS; z++)
47
    {
47
    {
48
        data->motor.desired_speed[z] = 0;
48
        data->motor.desired_speed[z] = 0;
49
    }
49
    }
50
 
50
 
51
    motor_test(data->motor);
51
    motor_test(data->motor);
52
}
52
}
53
 
53
 
54
/**
54
/**
55
 * read mixer values from FlightCtrl
55
 * read mixer values from FlightCtrl
56
 */
56
 */
57
void Handler::read_motor_mixer() {
57
void Handler::read_motor_mixer() {
58
    FlightLog::info_FC("reading motor mixer values");
58
    FlightLog::info_FC("reading motor mixer values");
59
    char tx_data[1] = {0};
59
    char tx_data[1] = {0};
60
    //com->log("read motor mixer");
60
    //com->log("read motor mixer");
61
    com->send_cmd('n', ADDRESS_FC, tx_data, 1, true);
61
    com->send_cmd('n', ADDRESS_FC, tx_data, 1, true);
62
}
62
}
63
 
63
 
64
/**
64
/**
65
 * write motor mixer values to FlightCtrl
65
 * write motor mixer values to FlightCtrl
66
 */
66
 */
67
void Handler::write_motor_mixer(char * tx_data, int length) {
67
void Handler::write_motor_mixer(char * tx_data, int length) {
68
    FlightLog::info_FC("setting motor mixer values");
68
    FlightLog::info_FC("setting motor mixer values");
69
    com->send_cmd('m', ADDRESS_FC, tx_data, length, true);
69
    com->send_cmd('m', ADDRESS_FC, tx_data, length, true);
70
}
70
}
-
 
71
 
71
 
72
//FIXME: implement me!
-
 
73
int Handler::get_motor_config(char * tx_data) {
72
int Handler::get_motor_config(char * tx_data) {
74
    FlightLog::error("get motor config not implemented");
73
    return -1;
75
    return -1;
74
}
76
}
75
 
77
 
76
//-------------NaviCtrl commands--------------------
78
//-------------NaviCtrl commands--------------------
77
/**
79
/**
78
 * set debug values for NaviCtrl
80
 * set debug values for NaviCtrl
79
 */
81
 */
80
void Handler::set_navictrl_debug(int speed) {
82
void Handler::set_navictrl_debug(int speed) {
81
    FlightLog::info_NC("setting NaviCtrl debug speed");
83
    FlightLog::info_NC("setting NaviCtrl debug speed");
82
    char tx_data[1] = { speed };
84
    char tx_data[1] = { speed };
83
    com->send_cmd('o', ADDRESS_NC, tx_data, 1, false);
85
    com->send_cmd('o', ADDRESS_NC, tx_data, 1, false);
84
}
86
}
85
 
87
 
86
/**
88
/**
87
 * stop debug for NaviCtrl
89
 * stop debug for NaviCtrl
88
 */
90
 */
89
void Handler::stop_navictrl_debug() {
91
void Handler::stop_navictrl_debug() {
90
    set_navictrl_debug(0);
92
    set_navictrl_debug(0);
91
}
93
}
92
 
94
 
93
/**
95
/**
94
 * send a waypoint to the NaviCtrl (the MikroKopter will fly to the position emidiately)
96
 * send a waypoint to the NaviCtrl (the MikroKopter will fly to the position emidiately)
95
 */
97
 */
96
void Handler::send_waypoint(Waypoint_t desired_pos) {
98
void Handler::send_waypoint(Waypoint_t desired_pos) {
97
    FlightLog::info_GPS("sending Waypoint");
99
    FlightLog::info_GPS("sending Waypoint");
98
    com->send_cmd('s', ADDRESS_NC, (char *)&desired_pos, sizeof(desired_pos), false);
100
    com->send_cmd('s', ADDRESS_NC, (char *)&desired_pos, sizeof(desired_pos), false);
99
}
101
}
100
 
102
 
101
/**
103
/**
102
 * add waypoint to waypoint list
104
 * add waypoint to waypoint list
103
 */
105
 */
104
void Handler::add_waypoint(Waypoint_t wp) {
106
void Handler::add_waypoint(Waypoint_t wp) {
105
    FlightLog::info_GPS("adding Waypoint");
107
    FlightLog::info_GPS("adding Waypoint");
106
    com->send_cmd('w', ADDRESS_NC, (char *)&wp, sizeof(wp), false);
108
    com->send_cmd('w', ADDRESS_NC, (char *)&wp, sizeof(wp), false);
107
}
109
}
108
 
110
 
109
/**
111
/**
110
 * clear waypoint list on MK
112
 * clear waypoint list on MK
111
 */
113
 */
112
void Handler::delete_waypoints() {
114
void Handler::delete_waypoints() {
113
    Waypoint_t wp;
115
    Waypoint_t wp;
114
    wp.Position.Status = INVALID;
116
    wp.Position.Status = INVALID;
115
    send_waypoint(wp);
117
    send_waypoint(wp);
116
}
118
}
117
//-------------switch between Hardware--------------------
119
//-------------switch between Hardware--------------------
118
void Handler::switch_navictrl() {
120
void Handler::switch_navictrl() {
119
    FlightLog::info("switching to NaviCtrl");
121
    FlightLog::info("switching to NaviCtrl");
120
    char tx_data[6] = { 0x1B, 0x1B, 0x55, 0xAA, 0x00, '\r'};
122
    char tx_data[6] = { 0x1B, 0x1B, 0x55, 0xAA, 0x00, '\r'};
121
    com->send_cmd('#', ADDRESS_NC, tx_data, 6, false);
123
    com->send_cmd('#', ADDRESS_NC, tx_data, 6, false);
122
}
124
}
123
 
125
 
124
void Handler::switch_flightctrl() {
126
void Handler::switch_flightctrl() {
125
    FlightLog::info("switching to FlightCtrl");
127
    FlightLog::info("switching to FlightCtrl");
126
    char tx_data[1] = { 0 };
128
    char tx_data[1] = { 0 };
127
    com->send_cmd('u', ADDRESS_NC, tx_data, 1, false);
129
    com->send_cmd('u', ADDRESS_NC, tx_data, 1, false);
128
}
130
}
129
 
131
 
130
void Handler::switch_mk3mag() {
132
void Handler::switch_mk3mag() {
131
    FlightLog::info("switching to MK3MAG");
133
    FlightLog::info("switching to MK3MAG");
132
    char tx_data[1] = { 1 };
134
    char tx_data[1] = { 1 };
133
    com->send_cmd('u', ADDRESS_NC, tx_data, 1, false);
135
    com->send_cmd('u', ADDRESS_NC, tx_data, 1, false);
134
}
136
}
135
 
137
 
136
//-------------commands for MK3MAG-----------------
138
//-------------commands for MK3MAG-----------------
137
 
139
 
138
 
140
 
139
//-------------commands for all--------------------
141
//-------------commands for all--------------------
140
 
142
 
141
/**
143
/**
142
 * set debug values for all components
144
 * set debug values for all components
143
 */
145
 */
144
void Handler::set_all_debug(int speed) {
146
void Handler::set_all_debug(int speed) {
145
    FlightLog::info("setting debug speed");
147
    FlightLog::info("setting debug speed");
146
    char tx_data[1] = { speed };
148
    char tx_data[1] = { speed };
147
    com->send_cmd('d', ADDRESS_ALL, tx_data, 1, false);
149
    com->send_cmd('d', ADDRESS_ALL, tx_data, 1, false);
148
}
150
}
149
 
151
 
150
/**
152
/**
151
 * stop debug for all components
153
 * stop debug for all components
152
 */
154
 */
153
void Handler::stop_all_debug() {
155
void Handler::stop_all_debug() {
154
    set_all_debug(0);
156
    set_all_debug(0);
155
}
157
}
156
 
158
 
157
/**
159
/**
158
 * get all analog labels
160
 * get all analog labels
159
 */
161
 */
160
void Handler::get_analog() {
162
void Handler::get_analog() {
161
    FlightLog::info("get analog values");
163
    FlightLog::info("get analog values");
162
    char tx_data[1] = { 0 };
164
    char tx_data[1] = { 0 };
163
    com->send_cmd('a', ADDRESS_ALL, tx_data, 1, true);
165
    com->send_cmd('a', ADDRESS_ALL, tx_data, 1, true);
164
}
166
}
165
 
167
 
166
/**
168
/**
167
 * get values from LCD / show LCD
169
 * get values from LCD / show LCD
168
 */
170
 */
169
void Handler::show_lcd() {
171
void Handler::show_lcd() {
170
    FlightLog::info("show LCD");
172
    FlightLog::info("show LCD");
171
    char tx_data[1] = {0};
173
    char tx_data[1] = {0};
172
    com->send_cmd('l', ADDRESS_ALL, tx_data, 1, true);
174
    com->send_cmd('l', ADDRESS_ALL, tx_data, 1, true);
173
}
175
}
174
 
176
 
175
/**
177
/**
176
 * got to next LCD Page
178
 * got to next LCD Page
177
 */
179
 */
178
void Handler::lcd_up() {
180
void Handler::lcd_up() {
179
    FlightLog::info("going up one LCD page");
181
    FlightLog::info("going up one LCD page");
180
    char tx_data[2] = { 0, 0 };
182
    char tx_data[2] = { 0, 0 };
181
    if (data->lcd_cur != data->lcd_max)
183
    if (data->lcd_cur != data->lcd_max)
182
        tx_data[0] = data->lcd_cur+1;
184
        tx_data[0] = data->lcd_cur+1;
183
    com->send_cmd('l', ADDRESS_ALL, tx_data, 1, true);
185
    com->send_cmd('l', ADDRESS_ALL, tx_data, 1, true);
184
}
186
}
185
 
187
 
186
/**
188
/**
187
 * got to previous LCD Page
189
 * got to previous LCD Page
188
 */
190
 */
189
void Handler::lcd_down() {
191
void Handler::lcd_down() {
190
    FlightLog::info("going down one LCD page");
192
    FlightLog::info("going down one LCD page");
191
    char tx_data[2] = { 0, 0 };
193
    char tx_data[2] = { 0, 0 };
192
    if (data->lcd_cur != 0)
194
    if (data->lcd_cur != 0)
193
        tx_data[0] = data->lcd_cur-1;
195
        tx_data[0] = data->lcd_cur-1;
194
    com->send_cmd('l', ADDRESS_ALL, tx_data, 1, true);
196
    com->send_cmd('l', ADDRESS_ALL, tx_data, 1, true);
195
}
197
}
196
 
198
 
197
void Handler::get_version() {
199
void Handler::get_version() {
198
    FlightLog::info("get version");
200
    FlightLog::info("get version");
199
    //TODO: Check if is this correct or do we need data from switch_...
201
    //TODO: Check if is this correct or do we need data from switch_...
200
    char tx_data[1] = { 0 };
202
    char tx_data[1] = { 0 };
201
    com->send_cmd('v', ADDRESS_ALL, tx_data, 0, true);
203
    com->send_cmd('v', ADDRESS_ALL, tx_data, 0, true);
202
}
204
}
203
 
205
 
204
void Handler::get_ppm_channels() {
206
void Handler::get_ppm_channels() {
205
     FlightLog::info("get PPM channels");
207
     FlightLog::info("get PPM channels");
206
    char tx_data[1] = { 0 };
208
    char tx_data[1] = { 0 };
207
    com->send_cmd('p', ADDRESS_ALL, tx_data, 0, false);
209
    com->send_cmd('p', ADDRESS_ALL, tx_data, 0, false);
208
}
210
}
209
 
211
 
210
void Handler::new_navi_data(char * data) {
212
void Handler::new_navi_data(char * data) {
211
    std::string mode;
213
    std::string mode;
212
    switch(data[N_NC_FLAGS])
214
    switch(data[N_NC_FLAGS])
213
    {
215
    {
214
        case 0x01 : mode = "Free"; break;
216
        case 0x01 : mode = "Free"; break;
215
        case 0x02 : mode = "Position Hold"; break;
217
        case 0x02 : mode = "Position Hold"; break;
216
        case 0x04 : mode = "Coming Home"; break;
218
        case 0x04 : mode = "Coming Home"; break;
217
        case 0x08 : mode = "Range Limit"; break;
219
        case 0x08 : mode = "Range Limit"; break;
218
        case 0x10 : mode = "Serial Error"; break;
220
        case 0x10 : mode = "Serial Error"; break;
219
        case 0x20 : mode = "Target reached"; break;
221
        case 0x20 : mode = "Target reached"; break;
220
        case 0x40 : mode = "Manual Control"; break;
222
        case 0x40 : mode = "Manual Control"; break;
221
    }
223
    }
222
   
224
   
223
}
225
}
224
 
226
 
225
/**
227
/**
226
 * receive data
228
 * receive data
227
 */
229
 */
228
void Handler::receive_data(char * incomming, int length) {
230
void Handler::receive_data(char * incomming, int length) {
229
    if (incomming[0] != '#') {
231
    if (incomming[0] != '#') {
230
        FlightLog::error("this frame is not correct");
232
        FlightLog::error("this frame is not correct");
231
        FlightLog::info(incomming);
233
        FlightLog::info(incomming);
232
        return;
234
        return;
233
    }
235
    }
234
    int hardwareID = incomming[1] - 'a';
236
    int hardwareID = incomming[1] - 'a';
235
 
237
 
236
    //The cmd is also known as ID-Byte (or ID for short) in the wiki-dokumentation
238
    //The cmd is also known as ID-Byte (or ID for short) in the wiki-dokumentation
237
    char cmd = incomming[2];
239
    char cmd = incomming[2];
238
    //decoded data
240
    //decoded data
239
    unsigned char data[MAX_DATA_SIZE];
241
    unsigned char data[MAX_DATA_SIZE];
240
 
242
 
241
    Parser::decode64(incomming, length, data, 3);
243
    Parser::decode64(incomming, length, data, 3);
242
 
244
 
243
    switch(hardwareID)
245
    switch(hardwareID)
244
    {
246
    {
245
        case ADDRESS_FC :
247
        case ADDRESS_FC :
246
            switch(cmd)
248
            switch(cmd)
247
            {
249
            {
248
                // Motor-Mixer
250
                // Motor-Mixer
249
                case 'N' :
251
                case 'N' :
250
                    com->stop_resend();
252
                    com->stop_resend();
251
                    //decoded data
253
                    //decoded data
252
                    FlightLog::info_FC("received motortest values from FlightCtrl");
254
                    FlightLog::info_FC("received motortest values from FlightCtrl");
253
                    if (data[0] == VERSION_MIXER)
255
                    if (data[0] == VERSION_MIXER)
254
                    {
256
                    {
255
                        //TODO: Handler::receivedMotorConfig(incomming)
257
                        //TODO: Handler::receivedMotorConfig(incomming)
256
                        //f_MotorMixer->set_MotorConfig(RX);
258
                        //f_MotorMixer->set_MotorConfig(RX);
257
                    }
259
                    }
258
                    break;
260
                    break;
259
                // Motor-Mixer Schreib-Bestätigung
261
                // Motor-Mixer Schreib-Bestätigung
260
                case 'M' :
262
                case 'M' :
261
                    com->stop_resend();
263
                    com->stop_resend();
262
 
264
 
263
                    if (data[0] == 1)
265
                    if (data[0] == 1)
264
                    {
266
                    {
265
                        FlightLog::info_FC("motor values written to FlightCtrl.");
267
                        FlightLog::info_FC("motor values written to FlightCtrl.");
266
                        //lb_Status->setText(tr("MotorMixer-Daten in FC geschrieben."));
268
                        //lb_Status->setText(tr("MotorMixer-Daten in FC geschrieben."));
267
                    } else {
269
                    } else {
268
                        FlightLog::warning("could not write motor values to FlightCtrl!");
270
                        FlightLog::warning("could not write motor values to FlightCtrl!");
269
                    }
271
                    }
270
                    break;
272
                    break;
271
 
273
 
272
                // Stick-Belegung der Fernsteuerung
274
                // Stick-Belegung der Fernsteuerung
273
                case 'P' : // DONE 0.71g
275
                case 'P' : // DONE 0.71g
274
                    FlightLog::info_FC("received stick-settings:");
276
                    FlightLog::info_FC("received stick-settings:");
275
                    for (int i = 1; i <= 8; i++) {
277
                    for (int i = 1; i <= 8; i++) {
276
                        std::stringstream d;
278
                        std::stringstream d;
277
                        d << "Stickvalue for Stick nr. " << i << ": " << Parser::dataToInt((char *)data, i*2, true);;
279
                        d << "Stickvalue for Stick nr. " << i << ": " << Parser::dataToInt((char *)data, i*2, true);;
278
                        std::string val;
280
                        std::string val;
279
                        d >> val;
281
                        d >> val;
280
                        FlightLog::info_FC((char *)val.c_str());
282
                        FlightLog::info_FC((char *)val.c_str());
281
                    }
283
                    }
282
                    /*f_Settings->pb_K1->setValue(Parser::dataToInt(RX.decode,  2,true));
284
                    /*f_Settings->pb_K1->setValue(Parser::dataToInt(RX.decode,  2,true));
283
                    f_Settings->pb_K2->setValue(Parser::dataToInt(RX.decode,  4,true));
285
                    f_Settings->pb_K2->setValue(Parser::dataToInt(RX.decode,  4,true));
284
                    f_Settings->pb_K3->setValue(Parser::dataToInt(RX.decode,  6,true));
286
                    f_Settings->pb_K3->setValue(Parser::dataToInt(RX.decode,  6,true));
285
                    f_Settings->pb_K4->setValue(Parser::dataToInt(RX.decode,  8,true));
287
                    f_Settings->pb_K4->setValue(Parser::dataToInt(RX.decode,  8,true));
286
                    f_Settings->pb_K5->setValue(Parser::dataToInt(RX.decode, 10 ,true));
288
                    f_Settings->pb_K5->setValue(Parser::dataToInt(RX.decode, 10 ,true));
287
                    f_Settings->pb_K6->setValue(Parser::dataToInt(RX.decode, 12,true));
289
                    f_Settings->pb_K6->setValue(Parser::dataToInt(RX.decode, 12,true));
288
                    f_Settings->pb_K7->setValue(Parser::dataToInt(RX.decode, 14,true));
290
                    f_Settings->pb_K7->setValue(Parser::dataToInt(RX.decode, 14,true));
289
                    f_Settings->pb_K8->setValue(Parser::dataToInt(RX.decode, 16,true));*/
291
                    f_Settings->pb_K8->setValue(Parser::dataToInt(RX.decode, 16,true));*/
290
                    break;
292
                    break;
291
                // Settings lesen
293
                // Settings lesen
292
                case 'Q' : // DONE 0.71g
294
                case 'Q' : // DONE 0.71g
293
                    com->stop_resend();
295
                    com->stop_resend();
294
                    FlightLog::info_FC("received settings");
296
                    FlightLog::info_FC("received settings");
295
                    if (data[1] == VERSION_SETTINGS)
297
                    if (data[1] == VERSION_SETTINGS)
296
                    {
298
                    {
297
                        int settings_id = data[0];
299
                        int settings_id = data[0];
298
                        std::stringstream d;
300
                        std::stringstream d;
299
                        d << "Settings-ID: " << settings_id;
301
                        d << "Settings-ID: " << settings_id;
300
                        std::string val;
302
                        std::string val;
301
                        d >> val;
303
                        d >> val;
302
                        FlightLog::info_FC((char *)val.c_str());
304
                        FlightLog::info_FC((char *)val.c_str());
303
                        for (int i = 0; i < MaxParameter; i++) {
305
                        for (int i = 0; i < MaxParameter; i++) {
304
                            d.flush();
306
                            d.flush();
305
                            d << "Value for Parameter nr. " << i << ": " << (int)data[i+2];
307
                            d << "Value for Parameter nr. " << i << ": " << (int)data[i+2];
306
                            d >> val;
308
                            d >> val;
307
                            FlightLog::info_FC((char *)val.c_str());
309
                            FlightLog::info_FC((char *)val.c_str());
308
                        }
310
                        }
309
                       
311
                       
310
                        /*for (int a = 0; a < MaxParameter; a++)
312
                        /*for (int a = 0; a < MaxParameter; a++)
311
                        {
313
                        {
312
                            FCSettings[a] = RX.decode[a + 2];
314
                            FCSettings[a] = RX.decode[a + 2];
313
                        }
315
                        }
314
                        f_Settings->show_FCSettings(Settings_ID, FCSettings);
316
                        f_Settings->show_FCSettings(Settings_ID, FCSettings);
315
                        f_Settings->pb_Read->setEnabled(true);
317
                        f_Settings->pb_Read->setEnabled(true);
316
                        f_Settings->pb_Write->setEnabled(true);*/
318
                        f_Settings->pb_Write->setEnabled(true);*/
317
                    }
319
                    }
318
                    else
320
                    else
319
                    {
321
                    {
320
                        FlightLog::error("wrong FlightCtrl version");
322
                        FlightLog::error("wrong FlightCtrl version");
321
                        /*f_Settings->pb_Read->setDisabled(true);
323
                        /*f_Settings->pb_Read->setDisabled(true);
322
                        f_Settings->pb_Write->setDisabled(true);
324
                        f_Settings->pb_Write->setDisabled(true);
323
 
325
 
324
                        QString name = QString("Versionen inkompatibel.\n") +
326
                        QString name = QString("Versionen inkompatibel.\n") +
325
                                    QString("Version von GroundStation benoetigt: ") +
327
                                    QString("Version von GroundStation benoetigt: ") +
326
                                    QString(VERSION_SETTINGS) +
328
                                    QString(VERSION_SETTINGS) +
327
                                    QString("\nVersion auf der FlightCtrl: ") +
329
                                    QString("\nVersion auf der FlightCtrl: ") +
328
                                    QString(RX.decode[1]) +
330
                                    QString(RX.decode[1]) +
329
                                    QString("\nParameterbearbeitung nicht moeglich.");
331
                                    QString("\nParameterbearbeitung nicht moeglich.");
330
                        QMessageBox::warning(this, QA_NAME,
332
                        QMessageBox::warning(this, QA_NAME,
331
                                name, QMessageBox::Ok);*/
333
                                name, QMessageBox::Ok);*/
332
                    }
334
                    }
333
                    break;
335
                    break;
334
                // Settings written
336
                // Settings written
335
                case 'S' : // DONE 0.71g
337
                case 'S' : // DONE 0.71g
336
                    com->stop_resend();
338
                    com->stop_resend();
337
                    FlightLog::info_FC("settings written successfully");
339
                    FlightLog::info_FC("settings written successfully");
338
                    //TODO: QMessagebox("settings written successful") ?
340
                    //TODO: QMessagebox("settings written successful") ?
339
                    break;
341
                    break;
340
            }
342
            }
341
 
343
 
342
        case ADDRESS_NC :
344
        case ADDRESS_NC :
343
            switch(cmd)
345
            switch(cmd)
344
            {
346
            {
345
                // Navigationsdaten
347
                // Navigationsdaten
346
                case 'O' : // NOT DONE 0.12h
348
                case 'O' : // NOT DONE 0.12h
347
                    //new_NaviData(RX);
349
                    //new_NaviData(RX);
348
                    FlightLog::info_NC("received navigation data");
350
                    FlightLog::info_NC("received navigation data");
349
                    break;
351
                    break;
350
            }
352
            }
351
//        case ADDRESS_MK3MAG :
353
//        case ADDRESS_MK3MAG :
352
 
354
 
353
        default :
355
        default :
354
            switch(cmd)
356
            switch(cmd)
355
            {
357
            {
356
                // LCD-Anzeige
358
                // LCD-Anzeige
357
                case 'L' : // DONE 0.71g
359
                case 'L' : // DONE 0.71g
358
                    com->stop_resend();
360
                    com->stop_resend();
359
                    FlightLog::info("received LCD page.");
361
                    FlightLog::info("received LCD page.");
360
                    /*int LCD[MAX_DATA_SIZE];
362
                    /*int LCD[MAX_DATA_SIZE];
361
                    memcpy(LCD,RX.decode, sizeof(RX.decode));
363
                    memcpy(LCD,RX.decode, sizeof(RX.decode));
362
 
364
 
363
                    f_LCD->show_Data(LCD);
365
                    f_LCD->show_Data(LCD);
364
 
366
 
365
                    LCD_Page     = RX.decode[0];
367
                    LCD_Page     = RX.decode[0];
366
                    LCD_MAX_Page = RX.decode[1];
368
                    LCD_MAX_Page = RX.decode[1];
367
                    */
369
                    */
368
                    break;
370
                    break;
369
                // Analoglabels
371
                // Analoglabels
370
                case 'A' : // DONE 0.71g
372
                case 'A' : // DONE 0.71g
371
                    com->stop_resend();
373
                    com->stop_resend();
372
                    FlightLog::info("received analog labels");
374
                    FlightLog::info("received analog labels");
373
                    //check position
375
                    //check position
374
                    if (data[0] != 31) {
376
                    if (data[0] != 31) {
375
                        /*
377
                        /*
376
                        Settings->Analog1.Label[Position] = ToolBox::dataToQString(RX.decode,1,17).trimmed();
378
                        Settings->Analog1.Label[Position] = ToolBox::dataToQString(RX.decode,1,17).trimmed();
377
                        if (Settings->Analog1.Label[Position] == "")
379
                        if (Settings->Analog1.Label[Position] == "")
378
                        {
380
                        {
379
                            Settings->Analog1.Label[Position] = "A-" + QString("%1").arg(Position);
381
                            Settings->Analog1.Label[Position] = "A-" + QString("%1").arg(Position);
380
                        }
382
                        }
381
                        Position ++;
383
                        Position ++;
382
                        TX_Data[0] = Position;
384
                        TX_Data[0] = Position;
383
                        o_Connection->send_Cmd('a', ADDRESS_ALL, TX_Data, 1, true);*/
385
                        o_Connection->send_Cmd('a', ADDRESS_ALL, TX_Data, 1, true);*/
384
                    } else {
386
                    } else {
385
                        /*
387
                        /*
386
                        for (int a = 0; a < MaxAnalog; a++)
388
                        for (int a = 0; a < MaxAnalog; a++)
387
                        {
389
                        {
388
                            lb_Analog[a]->setText(Settings->Analog1.Label[a]);
390
                            lb_Analog[a]->setText(Settings->Analog1.Label[a]);
389
                        }
391
                        }
390
                        Settings->Analog1.Version = QString(Mode.Version);
392
                        Settings->Analog1.Version = QString(Mode.Version);
391
                        Settings->write_Settings_AnalogLabels(HardwareID);
393
                        Settings->write_Settings_AnalogLabels(HardwareID);
392
                        config_Plot();*/
394
                        config_Plot();*/
393
                    }
395
                    }
394
                    break;
396
                    break;
395
                // Debug-Daten
397
                // Debug-Daten
396
                case 'D' : // DONE 0.71g
398
                case 'D' : // DONE 0.71g
397
                    FlightLog::info("received debug data:");
399
                    FlightLog::info("received debug data:");
398
                    for (int i = 0; i < MaxAnalog; i++) {
400
                    for (int i = 0; i < MaxAnalog; i++) {
399
                        /*
401
                        /*
400
                        Parser::dataToInt((char *)data, (i * 2) + 2, false);
402
                        Parser::dataToInt((char *)data, (i * 2) + 2, false);
401
                        */
403
                        */
402
                    }
404
                    }
403
                    //show_DebugData();
405
                    //show_DebugData();
404
                    break;
406
                    break;
405
                // Version
407
                // Version
406
                case 'V' : // DONE 0.71h
408
                case 'V' : // DONE 0.71h
407
                    com->stop_resend();
409
                    com->stop_resend();
408
                    FlightLog::info("received version");
410
                    FlightLog::info("received version");
409
                    /*
411
                    /*
410
                    Mode.ID            = HardwareID;
412
                    Mode.ID            = HardwareID;
411
                    Mode.VERSION_MAJOR = RX.decode[0];
413
                    Mode.VERSION_MAJOR = RX.decode[0];
412
                    Mode.VERSION_MINOR = RX.decode[1];
414
                    Mode.VERSION_MINOR = RX.decode[1];
413
                    Mode.VERSION_PATCH = RX.decode[4];
415
                    Mode.VERSION_PATCH = RX.decode[4];
414
                    Mode.VERSION_SERIAL_MAJOR = RX.decode[2];
416
                    Mode.VERSION_SERIAL_MAJOR = RX.decode[2];
415
                    Mode.VERSION_SERIAL_MINOR = RX.decode[3];
417
                    Mode.VERSION_SERIAL_MINOR = RX.decode[3];
416
 
418
 
417
                    Mode.Hardware   = HardwareType[Mode.ID];
419
                    Mode.Hardware   = HardwareType[Mode.ID];
418
                    //TODO: Funktion im Handler get_version() oder sowas
420
                    //TODO: Funktion im Handler get_version() oder sowas
419
                    QString version = QString("%1").arg(RX.decode[0]) + "." +
421
                    QString version = QString("%1").arg(RX.decode[0]) + "." +
420
                                        QString("%1").arg(RX.decode[1]) +
422
                                        QString("%1").arg(RX.decode[1]) +
421
                                        QString(RX.decode[4] + 'a');
423
                                        QString(RX.decode[4] + 'a');
422
                    Mode.Version = version.toLatin1().data;
424
                    Mode.Version = version.toLatin1().data;
423
                    setWindowTitle(QA_NAME + " v" + QA_VERSION + " - " +
425
                    setWindowTitle(QA_NAME + " v" + QA_VERSION + " - " +
424
                                Mode.Hardware + " " +
426
                                Mode.Hardware + " " +
425
                                Mode.Version);
427
                                Mode.Version);
426
 
428
 
427
                    if (Mode.VERSION_SERIAL_MAJOR != VERSION_SERIAL_MAJOR)
429
                    if (Mode.VERSION_SERIAL_MAJOR != VERSION_SERIAL_MAJOR)
428
                    {
430
                    {
429
//                                AllowSend = false;
431
//                                AllowSend = false;
430
                            QMessageBox::warning(this, QA_NAME,
432
                            QMessageBox::warning(this, QA_NAME,
431
                            tr("Serielles Protokoll Inkompatibel. \nBitte neue Programmversion installieren,"), QMessageBox::Ok);
433
                            tr("Serielles Protokoll Inkompatibel. \nBitte neue Programmversion installieren,"), QMessageBox::Ok);
432
                    }
434
                    }
433
 
435
 
434
                    if (ac_NoDebug->isChecked())
436
                    if (ac_NoDebug->isChecked())
435
                    {
437
                    {
436
                        TX_Data[0] = 0;
438
                        TX_Data[0] = 0;
437
                    }
439
                    }
438
                    else
440
                    else
439
                    if (ac_FastDebug->isChecked())
441
                    if (ac_FastDebug->isChecked())
440
                    {
442
                    {
441
                        TX_Data[0] = Settings->Data.Debug_Fast / 10;
443
                        TX_Data[0] = Settings->Data.Debug_Fast / 10;
442
                    }
444
                    }
443
                    else
445
                    else
444
                    {
446
                    {
445
                        TX_Data[0] = Settings->Data.Debug_Slow / 10;
447
                        TX_Data[0] = Settings->Data.Debug_Slow / 10;
446
                    }
448
                    }
447
 
449
 
448
                    o_Connection->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false);
450
                    o_Connection->send_Cmd('d', ADDRESS_ALL, TX_Data, 1, false);
449
 
451
 
450
                    // Wenn MK3MAG dann andauernd Daten neu anfragen.
452
                    // Wenn MK3MAG dann andauernd Daten neu anfragen.
451
                    if (Mode.ID == ADDRESS_MK3MAG)
453
                    if (Mode.ID == ADDRESS_MK3MAG)
452
                    {
454
                    {
453
                        TickerEvent[3] = true;
455
                        TickerEvent[3] = true;
454
                        rb_SelMag->setChecked(true);
456
                        rb_SelMag->setChecked(true);
455
                    }
457
                    }
456
 
458
 
457
                    // Wenn NaviCtrl dann hier.
459
                    // Wenn NaviCtrl dann hier.
458
                    if (Mode.ID == ADDRESS_NC)
460
                    if (Mode.ID == ADDRESS_NC)
459
                    {
461
                    {
460
                        rb_SelNC->setChecked(true);
462
                        rb_SelNC->setChecked(true);
461
 
463
 
462
                        if (ac_NoNavi->isChecked())
464
                        if (ac_NoNavi->isChecked())
463
                        {
465
                        {
464
                            TX_Data[0] = 0;
466
                            TX_Data[0] = 0;
465
                        }
467
                        }
466
                        else
468
                        else
467
                        if (ac_FastNavi->isChecked())
469
                        if (ac_FastNavi->isChecked())
468
                        {
470
                        {
469
                            TX_Data[0] = Settings->Data.Navi_Fast / 10;
471
                            TX_Data[0] = Settings->Data.Navi_Fast / 10;
470
                        }
472
                        }
471
                        else
473
                        else
472
                        {
474
                        {
473
                            TX_Data[0] = Settings->Data.Navi_Slow / 10;
475
                            TX_Data[0] = Settings->Data.Navi_Slow / 10;
474
                        }
476
                        }
475
 
477
 
476
                        o_Connection->send_Cmd('o', ADDRESS_NC, TX_Data, 1, false);
478
                        o_Connection->send_Cmd('o', ADDRESS_NC, TX_Data, 1, false);
477
                    }
479
                    }
478
 
480
 
479
 
481
 
480
                    // Wenn FlightCtrl dann Settings abfragen.
482
                    // Wenn FlightCtrl dann Settings abfragen.
481
                    if (Mode.ID == ADDRESS_FC)
483
                    if (Mode.ID == ADDRESS_FC)
482
                    {
484
                    {
483
                        rb_SelFC->setChecked(true);
485
                        rb_SelFC->setChecked(true);
484
                        {
486
                        {
485
                            TX_Data[0] = 0xff;
487
                            TX_Data[0] = 0xff;
486
                            TX_Data[1] = 0;
488
                            TX_Data[1] = 0;
487
 
489
 
488
                            // DEP: Raus wenn Resend implementiert.
490
                            // DEP: Raus wenn Resend implementiert.
489
//                                ToolBox::Wait(SLEEP);
491
//                                ToolBox::Wait(SLEEP);
490
                            o_Connection->send_Cmd('q', ADDRESS_FC, TX_Data, 1, true);
492
                            o_Connection->send_Cmd('q', ADDRESS_FC, TX_Data, 1, true);
491
                            qDebug("FC - Get Settings");
493
                            qDebug("FC - Get Settings");
492
                        }
494
                        }
493
                    }
495
                    }
494
                    // Wenn nicht Lesen und Schreiben der Settings deaktivieren.
496
                    // Wenn nicht Lesen und Schreiben der Settings deaktivieren.
495
                    else
497
                    else
496
                    {
498
                    {
497
                            f_Settings->pb_Read->setDisabled(true);
499
                            f_Settings->pb_Read->setDisabled(true);
498
                            f_Settings->pb_Write->setDisabled(true);
500
                            f_Settings->pb_Write->setDisabled(true);
499
                    }
501
                    }
500
 
502
 
501
                    Settings->read_Settings_Analog(HardwareID);
503
                    Settings->read_Settings_Analog(HardwareID);
502
                    Settings->read_Settings_AnalogLabels(HardwareID);
504
                    Settings->read_Settings_AnalogLabels(HardwareID);
503
 
505
 
504
                    if (Settings->Analog1.Version != QString(Mode.Version))
506
                    if (Settings->Analog1.Version != QString(Mode.Version))
505
                    {
507
                    {
506
                        lb_Status->setText(tr("Analoglabel-Version unterschiedlich. Lese Analoglabels neu aus."));
508
                        lb_Status->setText(tr("Analoglabel-Version unterschiedlich. Lese Analoglabels neu aus."));
507
                        slot_ac_GetLabels();
509
                        slot_ac_GetLabels();
508
                    }
510
                    }
509
                    else
511
                    else
510
                    for (int a = 0; a < MaxAnalog; a++)
512
                    for (int a = 0; a < MaxAnalog; a++)
511
                    {
513
                    {
512
                        lb_Analog[a]->setText(Settings->Analog1.Label[a]);
514
                        lb_Analog[a]->setText(Settings->Analog1.Label[a]);
513
                    }
515
                    }
514
                    config_Plot();*/
516
                    config_Plot();*/
515
                    break;
517
                    break;
516
            }
518
            }
517
    }
519
    }
518
}
520
}