Subversion Repositories Projects

Rev

Rev 393 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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