Subversion Repositories Projects

Rev

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

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