Subversion Repositories Projects

Rev

Rev 2236 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2236 Rev 2250
Line 48... Line 48...
48
 
48
 
49
namespace MKLiveView
49
namespace MKLiveView
50
{
50
{
51
    public partial class MainForm : Form
51
    public partial class MainForm : Form
-
 
52
    {
-
 
53
        String[] NC_Error = new string[44]
-
 
54
        {
-
 
55
            "No Error",
-
 
56
            "FC not compatible" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A1_.22FC_not_compatible_.22",
-
 
57
            "MK3Mag not compatible" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A2_.22MK3Mag_not_compatible_.22",
-
 
58
            "no FC communication" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A3_.22no_FC_communication_.22",
-
 
59
            "no compass communication" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A4_.22no_compass_communication_.22",
-
 
60
            "no GPS communication" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A5_.22no_GPS_communication_.22",
-
 
61
            "bad compass value" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A6_.22bad_compass_value.22",
-
 
62
            "RC Signal lost" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A7_.22RC_Signal_lost_.22",
-
 
63
            "FC spi rx error" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A8_.22FC_spi_rx_error_.22",
-
 
64
            "ERR: no NC communication" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A9:_.22ERR:_no_NC_communication.22",
-
 
65
            "ERR: FC Nick Gyro" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A10_.22ERR:_FC_Nick_Gyro.22",
-
 
66
            "ERR: FC Roll Gyro" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A11_.22ERR:_FC_Roll_Gyro.22",
-
 
67
            "ERR: FC Yaw Gyro" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A12_.22ERR:_FC_Yaw_Gyro.22",
-
 
68
            "ERR: FC Nick ACC" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A13_.22ERR:_FC_Nick_ACC.22",
-
 
69
            "ERR: FC Roll ACC" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A14_.22ERR:_FC_Roll_ACC.22",
-
 
70
            "ERR: FC Z-ACC" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A15_.22ERR:_FC_Z-ACC.22",
-
 
71
            "ERR: Pressure sensor" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A16_.22ERR:_Pressure_sensor.22",
-
 
72
            "ERR: FC I2C" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A17_.22ERR:_FC_I2C.22",
-
 
73
            "ERR: Bl Missing" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A18_.22ERR:_Bl_Missing.22",
-
 
74
            "Mixer Error" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A19_.22Mixer_Error.22",
-
 
75
            "FC: Carefree Error" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A20_.22FC:_Carefree_Error.22",
-
 
76
            "ERR: GPS lost" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A21_.22ERR:_GPS_lost.22",
-
 
77
            "ERR: Magnet Error" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A22_.22ERR:_Magnet_Error.22",
-
 
78
            "Motor restart" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A23_.22Motor_restart.22",
-
 
79
            "BL Limitation" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A24_.22BL_Limitation.22",
-
 
80
            "Waypoint range" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A25_.22Waypoint_range.22",
-
 
81
            "ERR:No SD-Card" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A26_.22ERR:No_SD-Card.22",
-
 
82
            "ERR:SD Logging aborted" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A27_.22ERR:SD_Logging_aborted.22",
-
 
83
            "ERR:Flying range!" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A28_.22ERR:Flying_range.21.22",
-
 
84
            "ERR:Max Altitude" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A29_.22ERR:Max_Altitude.22",
-
 
85
            "No GPS Fix" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A30_.22No_GPS_Fix.22",
-
 
86
            "compass not calibrated" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A31_.22compass_not_calibrated.22",
-
 
87
            "ERR:BL selftest" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A32_.22ERR:BL_selftest.22",
-
 
88
            "no ext. compass" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A33_.22no_ext._compass.22",
-
 
89
            "compass sensor" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A34_.22compass_sensor.22",
-
 
90
            "FAILSAFE pos.!" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A35_.22FAILSAFE_pos..21__.22",
-
 
91
            "ERR:Redundancy" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A36_.22ERR:Redundancy__.22",
-
 
92
            "Redundancy test" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A37_.22Redundancy_test_.22",
-
 
93
            "GPS Update rate" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A38_.22GPS_Update_rate.22",
-
 
94
            "ERR:Canbus" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A39_.22ERR:Canbus.22",
-
 
95
            "ERR: 5V RC-Supply" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A40_.22ERR:_5V_RC-Supply.22",
-
 
96
            "ERR:Power-Supply" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A41_.22ERR:Power-Supply.22",
-
 
97
            "ACC not calibr." + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A42_.22ACC_not_calibr..22",
-
 
98
            "ERR:Parachute!" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A43_.22ERR:Parachute.21.22"
Line 52... Line 99...
52
    {
99
        };
53
 
100
 
54
        [FlagsAttribute]
101
        [FlagsAttribute]
55
        enum NC_HWError0 : short
102
        enum NC_HWError0 : short
Line 128... Line 175...
128
        byte OSDInterval = 85;
175
        byte OSDInterval = 85;
129
        /// <summary>
176
        /// <summary>
130
        /// datatable for the debug data array - displayed on settings tabpage in datagridview
177
        /// datatable for the debug data array - displayed on settings tabpage in datagridview
131
        /// </summary>
178
        /// </summary>
132
        DataTable dtAnalog = new DataTable();
179
        DataTable dtAnalog = new DataTable();
-
 
180
 
-
 
181
        DataTable dtMotors1 = new DataTable();
-
 
182
        DataTable dtMotors2 = new DataTable();
-
 
183
 
133
        public MainForm()
184
        public MainForm()
134
        {
185
        {
135
            InitializeComponent();
186
            InitializeComponent();
136
            _readIni();
187
            _readIni();
137
            dtAnalog.Columns.Add("ID");
188
            dtAnalog.Columns.Add("ID");
138
            dtAnalog.Columns.Add("Value");
189
            dtAnalog.Columns.Add("Value");
139
            dataGridView1.DataSource = dtAnalog;
190
            dataGridView1.DataSource = dtAnalog;
-
 
191
            dtMotors1.Columns.Add("#");
-
 
192
            dtMotors1.Columns.Add("Current");
-
 
193
            dtMotors1.Columns.Add("Temp");
-
 
194
            dtMotors2.Columns.Add("#");
-
 
195
            dtMotors2.Columns.Add("Current");
-
 
196
            dtMotors2.Columns.Add("Temp");
-
 
197
            dgvMotors1.DataSource = dtMotors1;
-
 
198
            dgvMotors2.DataSource = dtMotors2;
-
 
199
            _initDTMotors();
-
 
200
            dgvMotors1.Columns[0].Width = 24;
-
 
201
            dgvMotors1.Columns[1].Width = 74;
-
 
202
            dgvMotors1.Columns[2].Width = 74;
-
 
203
            dgvMotors2.Columns[0].Width = 24;
-
 
204
            dgvMotors2.Columns[1].Width = 74;
-
 
205
            dgvMotors2.Columns[2].Width = 74;
140
            simpleSerialPort.PortClosed += SimpleSerialPort_PortClosed;
206
            simpleSerialPort.PortClosed += SimpleSerialPort_PortClosed;
141
            simpleSerialPort.PortOpened += SimpleSerialPort_PortOpened;
207
            simpleSerialPort.PortOpened += SimpleSerialPort_PortOpened;
142
            simpleSerialPort.DataReceived += processMessage;
208
            simpleSerialPort.DataReceived += processMessage;
143
            chkbAutoBL.Checked = _blctrlDataAutorefresh;
209
            chkbAutoBL.Checked = _blctrlDataAutorefresh;
144
            chkbAutoDbg.Checked = _debugDataAutorefresh;
210
            chkbAutoDbg.Checked = _debugDataAutorefresh;
Line 153... Line 219...
153
        #region events
219
        #region events
154
        private void MainForm_Shown(object sender, EventArgs e)
220
        private void MainForm_Shown(object sender, EventArgs e)
155
        {
221
        {
156
            _loadLabelNames();
222
            _loadLabelNames();
157
            _init = false;
223
            _init = false;
-
 
224
            splitContainer1.SplitterDistance = 514;
158
        }
225
        }
159
        private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
226
        private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
160
        {
227
        {
161
            _writeIni();
228
            _writeIni();
162
        }
229
        }
Line 183... Line 250...
183
        {
250
        {
184
            if(bReadContinously)
251
            if(bReadContinously)
185
            {
252
            {
186
                if (_debugDataAutorefresh) { _readDebugData(true); Thread.Sleep(10); }
253
                if (_debugDataAutorefresh) { _readDebugData(true); Thread.Sleep(10); }
Line 187... Line 254...
187
 
254
 
Line 188... Line 255...
188
                if (_blctrlDataAutorefresh && _iCtrlAct == 2) { _readBLCtrl(true); Thread.Sleep(10); }
255
                if (_blctrlDataAutorefresh) { _readBLCtrl(true); Thread.Sleep(10); }
189
               
256
               
190
                if (_navCtrlDataAutorefresh && _iCtrlAct == 2) { _readNavData(true); Thread.Sleep(10); }
257
                if (_navCtrlDataAutorefresh && _iCtrlAct == 2) { _readNavData(true); Thread.Sleep(10); }
191
                check_HWError = true;
258
                check_HWError = true;
Line 207... Line 274...
207
        private void cbOSD_SelectedIndexChanged(object sender, EventArgs e)
274
        private void cbOSD_SelectedIndexChanged(object sender, EventArgs e)
208
        {
275
        {
209
            if (!_bCBInit && cbOSD.SelectedIndex > -1)
276
            if (!_bCBInit && cbOSD.SelectedIndex > -1)
210
                _OSDMenue(cbOSD.SelectedIndex);
277
                _OSDMenue(cbOSD.SelectedIndex);
211
        }
278
        }
212
 
-
 
213
        private void chkbAutoDbg_CheckedChanged(object sender, EventArgs e)
279
        private void chkbAutoDbg_CheckedChanged(object sender, EventArgs e)
214
        {
280
        {
215
            if(!_init) _debugDataAutorefresh = chkbAutoDbg.Checked;
281
            if(!_init) _debugDataAutorefresh = chkbAutoDbg.Checked;
216
        }
282
        }
217
        private void chkbAutoNav_CheckedChanged(object sender, EventArgs e)
283
        private void chkbAutoNav_CheckedChanged(object sender, EventArgs e)
Line 224... Line 290...
224
        }
290
        }
225
        private void chkbAutoOSD_CheckedChanged(object sender, EventArgs e)
291
        private void chkbAutoOSD_CheckedChanged(object sender, EventArgs e)
226
        {
292
        {
227
            if (!_init) _OSDAutorefresh = chkbAutoOSD.Checked;
293
            if (!_init) _OSDAutorefresh = chkbAutoOSD.Checked;
228
        }
294
        }
229
 
-
 
230
        private void cbTimingDebug_SelectedIndexChanged(object sender, EventArgs e)
295
        private void cbTimingDebug_SelectedIndexChanged(object sender, EventArgs e)
231
        {
296
        {
232
            if (cbTimingDebug.SelectedIndex > -1)
297
            if (cbTimingDebug.SelectedIndex > -1)
233
            {
298
            {
234
                debugInterval = (byte)(Convert.ToInt16(cbTimingDebug.SelectedItem) / 10);
299
                debugInterval = (byte)(Convert.ToInt16(cbTimingDebug.SelectedItem) / 10);
Line 315... Line 380...
315
            }));
380
            }));
316
        }
381
        }
Line 317... Line 382...
317
 
382
 
Line -... Line 383...
-
 
383
        #region functions        
318
        #region functions        
384
 
-
 
385
        #region processing received data
-
 
386
        /// <summary> Processing the messages and displaying them in the according form controls 
319
 
387
        /// function called by simpleSerialPort.DataReceived event
320
        /// <summary> Processing the messages and displaying them in the according form controls </summary>
388
        /// </summary>
321
        /// <param name="message"> message bytearray recieved by SimpleSerialPort class </param>
389
        /// <param name="message"> message bytearray recieved by SimpleSerialPort class </param>
322
        private void processMessage(byte[] message)
390
        private void processMessage(byte[] message)
323
        {
391
        {
Line 338... Line 406...
338
                    FlightControllerMessage.ParseMessage(message, out cmdID, out adr, out data);
406
                    FlightControllerMessage.ParseMessage(message, out cmdID, out adr, out data);
Line 339... Line 407...
339
 
407
 
340
                    if (adr == 255) { crcError++; }
408
                    if (adr == 255) { crcError++; }
341
                    else crcError = 0;
409
                    else crcError = 0;
342
                    lblCRCErr.Invoke((Action)(() => lblCRCErr.Text = crcError.ToString()));
-
 
-
 
410
                    lblCRCErr.Invoke((Action)(() => lblCRCErr.Text = crcError.ToString()));
343
 
411
                    //display the active controller (FC / NC) 
344
                    if (adr > 0 && adr < 3 && adr != _iCtrlAct) //adr < 3: temporary workaround cause when I've connected the FC alone it always switches between mk3mag & FC every second...???
412
                    if (adr > 0 && adr < 3 && adr != _iCtrlAct) //adr < 3: temporary workaround cause when I've connected the FC alone it always switches between mk3mag & FC every second...???
345
                    {
413
                    {
346
                        _iCtrlAct = adr;
414
                        _iCtrlAct = adr;
347
                        switch (adr)
415
                        switch (adr)
Line 363... Line 431...
363
                                break;
431
                                break;
364
                            default:
432
                            default:
365
                                lblCtrl.Invoke((Action)(() => lblCtrl.Text = "...."));
433
                                lblCtrl.Invoke((Action)(() => lblCtrl.Text = "...."));
366
                                break;
434
                                break;
367
                        }
435
                        }
368
                        _loadLabelNames();
436
                        _loadLabelNames();
369
                    }
437
                    }
370
                   // else
438
                   // else
371
                   //     Debug.Print("Address == 0?");
439
                   //     Debug.Print("Address == 0?");
Line 372... Line 440...
372
 
440
 
Line 375... Line 443...
375
                        s = new string(ASCIIEncoding.ASCII.GetChars(data, 1, data.Length - 1));
443
                        s = new string(ASCIIEncoding.ASCII.GetChars(data, 1, data.Length - 1));
376
                        s = s.Trim('\0', '\n');
444
                        s = s.Trim('\0', '\n');
Line 377... Line 445...
377
 
445
 
378
                        switch (cmdID)
446
                        switch (cmdID)
379
                        {
447
                        {
380
                            case 'A':
-
 
381
                                if (iLableIndex < 32)
-
 
382
                                {
-
 
383
                                    sAnalogLabel[iLableIndex] = s;
-
 
384
                                    if (dtAnalog.Rows.Count < 32)
-
 
385
                                        dtAnalog.Rows.Add(s, "");
-
 
386
                                    else
-
 
387
                                        dtAnalog.Rows[iLableIndex].SetField(0, s);
-
 
388
 
-
 
389
                                    _getAnalogLabels(iLableIndex + 1);
-
 
390
                                }
448
                            case 'A': //Label names
391
                                Debug.Print(s);
-
 
392
 
-
 
393
                                break;
-
 
394
                            case 'D':
-
 
395
                                if (data.Length == 66)
-
 
396
                                {
-
 
397
                                    int[] iAnalogData = new int[32];
-
 
398
 
-
 
399
                                    int index = 0;
-
 
400
                                    Int16 i16 = 0;
-
 
401
                                    double dTemp = 0;
-
 
402
                                    for (int i = 2; i < 66; i += 2)
-
 
403
                                    {
-
 
404
                                        i16 = data[i + 1];
-
 
405
                                        i16 = (Int16)(i16 << 8);
-
 
406
                                        iAnalogData[index] = data[i] + i16;
-
 
407
                                        sAnalogData[index] = (data[i] + i16).ToString();
-
 
408
                                        dtAnalog.Rows[index].SetField(1, sAnalogData[index]);
-
 
409
 
-
 
410
                                        if (adr == 2) //NC
-
 
411
                                        {
-
 
412
                                            switch (index)
-
 
413
                                            {
-
 
414
                                                case 0: //pitch (German: nick)
-
 
415
                                                    artificialHorizon1.Invoke((Action)(() => artificialHorizon1.pitch_angle = ((double)iAnalogData[index] / (double)10)));
-
 
416
                                                    lblNCPitch.Invoke((Action)(() => lblNCPitch.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0°")));
-
 
417
                                                    break;
-
 
418
                                                case 1: //roll
-
 
419
                                                    artificialHorizon1.Invoke((Action)(() => artificialHorizon1.roll_angle = ((double)iAnalogData[index] / (double)10)));
-
 
420
                                                    lblNCRoll.Invoke((Action)(() => lblNCRoll.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0°")));
-
 
421
                                                    break;
-
 
422
                                                case 4: //altitude
-
 
423
                                                    lblNCAlt.Invoke((Action)(() => lblNCAlt.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 m")));
-
 
424
                                                    break;
-
 
425
                                                case 7: //Voltage
-
 
426
                                                    lblNCVolt.Invoke((Action)(() => lblNCVolt.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 V")));
-
 
427
                                                    break;
-
 
428
                                                case 8: // Current
-
 
429
                                                    lblNCCur.Invoke((Action)(() => lblNCCur.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 A")));
-
 
430
                                                    break;
-
 
431
                                                case 10: //heading
-
 
432
                                                    lblNCCompass.Invoke((Action)(() => lblNCCompass.Text = sAnalogData[index] + "°"));
-
 
433
                                                    headingIndicator1.Invoke((Action)(() => headingIndicator1.SetHeadingIndicatorParameters(iAnalogData[index])));
-
 
434
                                                    break;
-
 
435
                                                case 12: // SPI error
-
 
436
                                                    lblNCSPI.Invoke((Action)(() => lblNCSPI.Text = sAnalogData[index]));
-
 
437
                                                    break;
-
 
438
                                                case 14: //i2c error
-
 
439
                                                    lblNCI2C.Invoke((Action)(() => lblNCI2C.Text = sAnalogData[index]));
-
 
440
                                                    break;
-
 
441
                                                case 20: //Earthmagnet field
-
 
442
                                                    lblNCMF.Invoke((Action)(() => lblNCMF.Text = sAnalogData[index] + "%"));
-
 
443
                                                    break;
-
 
444
                                                case 21: //GroundSpeed
-
 
445
                                                    lblNCGSpeed.Invoke((Action)(() => lblNCGSpeed.Text = ((double)iAnalogData[index] / (double)100).ToString("0.00 m/s")));
-
 
446
                                                    break;
-
 
447
                                                case 28: //Distance East from saved home position -> calculate distance with distance N + height
-
 
448
                                                    dTemp = Math.Pow((double)iAnalogData[index],2) + Math.Pow((double)iAnalogData[index - 1],2);
-
 
449
                                                    dTemp = Math.Sqrt(dTemp)/ (double)10; //'flat' distance from HP with N/E
-
 
450
                                                  //  lblNCDist.Invoke((Action)(() => lblNCDist.Text = dTemp.ToString("0.00")));
-
 
451
                                                    dTemp = Math.Pow(dTemp, 2) + Math.Pow(((double)iAnalogData[4] / (double)10), 2); //adding 'height' into calculation
-
 
452
                                                    dTemp = Math.Sqrt(dTemp);
-
 
453
                                                    lblNCDist.Invoke((Action)(() => lblNCDist.Text = dTemp.ToString("0 m")));
-
 
454
                                                    break;
-
 
455
                                                case 31: //Sats used
-
 
456
                                                    lblNCSat.Invoke((Action)(() => lblNCSat.Text = sAnalogData[index]));
-
 
457
                                                    break;
-
 
458
                                            }
-
 
459
                                        }
-
 
460
                                        if (adr == 1) //FC
-
 
461
                                        {
-
 
462
                                            switch (index)
-
 
463
                                            {
-
 
464
                                                case 0: //pitch (German: nick)
-
 
465
                                                    artificialHorizon1.Invoke((Action)(() => artificialHorizon1.pitch_angle = ((double)iAnalogData[index] / (double)10)));
-
 
466
                                                    lblNCPitch.Invoke((Action)(() => lblNCPitch.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0°")));
-
 
467
                                                    break;
-
 
468
                                                case 1: //roll
-
 
469
                                                    artificialHorizon1.Invoke((Action)(() => artificialHorizon1.roll_angle = ((double)iAnalogData[index] / (double)10)));
-
 
470
                                                    lblNCRoll.Invoke((Action)(() => lblNCRoll.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0°")));
-
 
471
                                                    break;
-
 
472
                                                case 5: //altitude
-
 
473
                                                    lblNCAlt.Invoke((Action)(() => lblNCAlt.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 m")));
-
 
474
                                                    break;
-
 
475
                                                case 8: //heading
-
 
476
                                                    lblNCCompass.Invoke((Action)(() => lblNCCompass.Text = sAnalogData[index] + "°"));
-
 
477
                                                    headingIndicator1.Invoke((Action)(() => headingIndicator1.SetHeadingIndicatorParameters(iAnalogData[index])));
-
 
478
                                                    break;
-
 
479
                                                case 9: //Voltage
-
 
480
                                                    lblNCVolt.Invoke((Action)(() => lblNCVolt.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 V")));
-
 
481
                                                    break;
-
 
482
                                                case 10: //Receiver quality
-
 
483
                                                    lblNCRC.Invoke((Action)(() => lblNCRC.Text = sAnalogData[index]));
-
 
484
                                                    break;
-
 
485
                                                case 22: // Current
-
 
486
                                                    lblNCCur.Invoke((Action)(() => lblNCCur.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 A")));
-
 
487
                                                    break;
-
 
488
                                                case 23: //capacity used
-
 
489
                                                    lblNCCap.Invoke((Action)(() => lblNCCap.Text = (iAnalogData[index]).ToString("0 mAh")));
-
 
490
                                                    break;
-
 
491
                                                case 27: // SPI error
-
 
492
                                                    lblNCSPI.Invoke((Action)(() => lblNCSPI.Text = sAnalogData[index]));
-
 
493
                                                    break;
-
 
494
                                                case 28: //i2c error
-
 
495
                                                    lblNCI2C.Invoke((Action)(() => lblNCI2C.Text = sAnalogData[index]));
-
 
496
                                                    break;
-
 
497
                                            }
-
 
498
                                        }
-
 
499
                                        index++;
-
 
500
                                    }
-
 
501
                                }
-
 
502
                                else
-
 
503
                                    Debug.Print("wrong data-length (66): " + data.Length.ToString());
449
                                _processLabelNames(s);
504
                                break;
-
 
505
 
-
 
506
                            case 'V':
-
 
507
                                if (data.Length == 12)
-
 
508
                                {
-
 
509
                                    if (!check_HWError)
-
 
510
                                    {
-
 
511
                                        string[] sVersionStruct = new string[10] { "SWMajor: ", "SWMinor: ", "ProtoMajor: ", "LabelTextCRC: ", "SWPatch: ", "HardwareError 1: ", "HardwareError 2: ", "HWMajor: ", "BL_Firmware: ", "Flags: " };
-
 
512
                                        string sVersion = "";
-
 
513
                                        //sbyte[] signed = Array.ConvertAll(data, b => unchecked((sbyte)b));
-
 
514
                                        Log(LogMsgType.Warning, (adr == 1 ? "FC-" : "NC-") + "Version: ");
-
 
515
                                        sVersion = "HW V" + (data[7] / 10).ToString() + "." + (data[7] % 10).ToString();
-
 
516
                                        Log(LogMsgType.Incoming, sVersion);
-
 
517
                                        sVersion = "SW V" + (data[0]).ToString() + "." + (data[1]).ToString() + ((char)(data[4] + 'a')).ToString();
-
 
518
                                        Log(LogMsgType.Incoming, sVersion);
-
 
519
                                        Log(LogMsgType.Incoming, "BL-Firmware: V" + (data[8] / 100).ToString() + "." + (data[8] % 100).ToString());
-
 
520
                                    }
-
 
521
                                    if(data[5] > 0) //error0 
-
 
522
                                    {
-
 
523
                                        if(adr == 1)
-
 
524
                                            ErrorLog(LogMsgType.Error, "FC - HW-Error " + data[5].ToString() + ": " + ((FC_HWError0)data[5]).ToString());
-
 
525
                                        if (adr == 2)
-
 
526
                                            ErrorLog(LogMsgType.Error, "NC - HW-Error " + data[5].ToString() + ": " + ((NC_HWError0)data[5]).ToString());
-
 
527
                                    }
-
 
528
                                    if (data[6] > 0) //error1 
-
 
529
                                    {
-
 
530
                                        if (adr == 1)
-
 
531
                                            ErrorLog(LogMsgType.Error, "FC - HW-Error " + data[6].ToString() + ": " + ((FC_HWError1)data[6]).ToString());
-
 
532
                                        if (adr == 2)
-
 
533
                                            ErrorLog(LogMsgType.Error, "NC - Unknown HW-ERROR: " + data[6].ToString()); //@moment NC has only one error field
-
 
534
                                    }
-
 
535
 
-
 
536
                                }
-
 
537
                                check_HWError = false;
-
 
538
                                break;
-
 
539
 
-
 
540
                            case 'K'://BL-CTRL debug data from NC
-
 
541
                                if (data.Length == 6 && data[0] < 8)
-
 
542
                                {
-
 
543
                                    Label lbCur = new Label(), lbTemp = new Label();
-
 
544
                                    switch (data[0])
-
 
545
                                    {
-
 
546
                                        case 0:
-
 
547
                                            lbCur = LBLNCM1Cur;
-
 
548
                                            lbTemp = LBLNCM1Temp;
-
 
549
                                            break;
-
 
550
                                        case 1:
-
 
551
                                            lbCur = LBLNCM2Cur;
-
 
552
                                            lbTemp = LBLNCM2Temp;
-
 
553
                                            break;
-
 
554
                                        case 2:
-
 
555
                                            lbCur = LBLNCM3Cur;
-
 
556
                                            lbTemp = LBLNCM3Temp;
-
 
557
                                            break;
-
 
558
                                        case 3:
-
 
559
                                            lbCur = LBLNCM4Cur;
-
 
560
                                            lbTemp = LBLNCM4Temp;
-
 
561
                                            break;
-
 
562
                                        case 4:
-
 
563
                                            lbCur = LBLNCM5Cur;
-
 
564
                                            lbTemp = LBLNCM5Temp;
-
 
565
                                            break;
-
 
566
                                        case 5:
-
 
567
                                            lbCur = LBLNCM6Cur;
-
 
568
                                            lbTemp = LBLNCM6Temp;
-
 
569
                                            break;
-
 
570
                                        case 6:
-
 
571
                                            lbCur = LBLNCM7Cur;
-
 
572
                                            lbTemp = LBLNCM7Temp;
-
 
573
                                            break;
-
 
574
                                        case 7:
-
 
575
                                            lbCur = LBLNCM8Cur;
-
 
576
                                            lbTemp = LBLNCM8Temp;
-
 
577
                                            break;
-
 
578
                                    }
-
 
579
                                    if (lbCur != null)
-
 
580
                                        lbCur.Invoke((Action)(() => lbCur.Text = ((double)data[1] / (double)10).ToString("0.0 A")));
-
 
581
                                    if (lbTemp != null)
-
 
Line -... Line 450...
-
 
450
                                break;
-
 
451
 
582
                                        lbTemp.Invoke((Action)(() => lbTemp.Text = data[2].ToString("0 °C")));
452
                            case 'D': //Debug data
Line -... Line 453...
-
 
453
                                _processDebugVals(adr,data);
-
 
454
                                break;
-
 
455
 
-
 
456
                            case 'V': //Version
-
 
457
                                _processVersion(adr, data);
-
 
458
                                break;
583
 
459
 
Line 584... Line 460...
584
                                }
460
                            case 'K'://BL-CTRL data
585
 
-
 
586
                                break;
-
 
587
 
-
 
588
                            case 'O': //NC Data
-
 
589
                                int i_16,iVal;
-
 
590
                                i_16 = data[81];
-
 
591
                                i_16 = (Int16)(i_16 << 8);
-
 
592
                                iVal = data[80] + i_16;
-
 
593
                                lblNCCap.Invoke((Action)(() => lblNCCap.Text = iVal.ToString() + " mAh")); //Capacity used
-
 
594
 
-
 
595
                                i_16 = data[56];
-
 
596
                                i_16 = (Int16)(i_16 << 8);
-
 
597
                                iVal = data[55] + i_16;
-
 
598
                                TimeSpan t = TimeSpan.FromSeconds(iVal);
-
 
599
                                string Text = t.Hours.ToString("D2") + ":" + t.Minutes.ToString("D2") + ":" + t.Seconds.ToString("D2");
-
 
600
                                lblNCFlTime.Invoke((Action)(() => lblNCFlTime.Text = Text.ToString())); //Flying time
-
 
601
 
461
                                _processBLCtrl(data);
602
                                lblNCRC.Invoke((Action)(() => lblNCRC.Text = data[66].ToString())); //RC quality
462
                                break;
Line 603... Line 463...
603
                                lblNCErrNmbr.Invoke((Action)(() => lblNCErrNmbr.Text = data[69].ToString()));   //NC Errornumber
463
 
604
                                if (data[69] > 0)
464
                            case 'O': //NC Data
-
 
465
                                _processNCData(data);
Line -... Line 466...
-
 
466
                                break;
-
 
467
 
605
                                    _readNCError();
468
                            case 'E': //NC error-string
Line 606... Line -...
606
                                break;
-
 
607
 
-
 
608
                            case 'E': //NC error-string
-
 
609
                                ErrorLog(LogMsgType.Error, "NC Error: " + s);
-
 
610
 
469
                                ErrorLog(LogMsgType.Error, "NC Error: " + s);
611
                                break;
470
                                break;
612
 
-
 
613
                            case 'L':
-
 
614
                                if(data.Length == 84)
-
 
615
                                {
-
 
616
                                    string sMessage = "";
-
 
617
                                    iOSDPage = data[0];
-
 
618
                                    iOSDMax = data[1];
-
 
619
                                    if (cbOSD.Items.Count != iOSDMax) _initOSDCB();
-
 
620
                                    sMessage = new string(ASCIIEncoding.ASCII.GetChars(data, 2, data.Length - 4));
-
 
621
                                    OSD(LogMsgType.Incoming, sMessage.Substring(0,20));
-
 
622
                                    OSD(LogMsgType.Incoming, sMessage.Substring(20,20));
-
 
623
                                    OSD(LogMsgType.Incoming, sMessage.Substring(40,20));
-
 
624
                                    OSD(LogMsgType.Incoming, sMessage.Substring(60,20));
-
 
625
                                    lblOSDPageNr.Invoke((Action)(()=>lblOSDPageNr.Text = iOSDPage.ToString("[0]")));
-
 
626
 
-
 
627
                                }
-
 
628
                                else
-
 
629
                                    OSD(LogMsgType.Incoming,"Wrong length: " + data.Length + " (should be 84)");
-
 
630
                                break;
-
 
631
                            case 'H':
-
 
632
                                if(data.Length == 81)
-
 
633
                                {
-
 
634
                                    string sMessage = "";
-
 
635
                                    sMessage = new string(ASCIIEncoding.ASCII.GetChars(data, 0, data.Length - 1));
-
 
636
                                    OSD(LogMsgType.Incoming, sMessage.Substring(0,20));
-
 
637
                                    OSD(LogMsgType.Incoming, sMessage.Substring(20,20));
471
 
Line 638... Line 472...
638
                                    OSD(LogMsgType.Incoming, sMessage.Substring(40,20));
472
                            case 'L': //OSD Menue (called by pagenumber)
639
                                    OSD(LogMsgType.Incoming, sMessage.Substring(60,20));
473
                                _processOSDSingle(data);
640
 
474
                                break;
Line 655... Line 489...
655
                    //    Log(LogMsgType.Incoming, BitConverter.ToString(data));
489
                    //    Log(LogMsgType.Incoming, BitConverter.ToString(data));
656
                    //}
490
                    //}
657
                }
491
                }
658
            }
492
            }
659
        }
493
        }
-
 
494
        /// <summary>
-
 
495
        /// Analog label names 'A'
-
 
496
        /// each label name is returned as a single string 
-
 
497
        /// and added to string array sAnalogLabel[]
-
 
498
        /// and the datatable dtAnalog
-
 
499
        /// </summary>
-
 
500
        /// <param name="s">the label name</param>
-
 
501
        void _processLabelNames(string s)
-
 
502
        {
-
 
503
            if (iLableIndex < 32)
-
 
504
            {
-
 
505
                sAnalogLabel[iLableIndex] = s;
-
 
506
                if (dtAnalog.Rows.Count < 32)
-
 
507
                    dtAnalog.Rows.Add(s, "");
-
 
508
                else
-
 
509
                    dtAnalog.Rows[iLableIndex].SetField(0, s);
-
 
510
 
-
 
511
                _getAnalogLabels(iLableIndex + 1);
-
 
512
            }
-
 
513
            Debug.Print(s);
-
 
514
        }
-
 
515
        /// <summary>
-
 
516
        /// Debug values 'D'
-
 
517
        /// </summary>
-
 
518
        /// <param name="adr">adress of the active controller (1-FC, 2-NC)</param>
-
 
519
        /// <param name="data">the received byte array to process</param>
-
 
520
        void _processDebugVals(byte adr,byte[] data)
-
 
521
        {
-
 
522
            if (data.Length == 66)
-
 
523
            {
-
 
524
                int[] iAnalogData = new int[32];
-
 
525
 
-
 
526
                int index = 0;
-
 
527
                Int16 i16 = 0;
-
 
528
                double dTemp = 0;
-
 
529
                for (int i = 2; i < 66; i += 2)
-
 
530
                {
-
 
531
                    i16 = data[i + 1];
-
 
532
                    i16 = (Int16)(i16 << 8);
-
 
533
                    iAnalogData[index] = data[i] + i16;
-
 
534
                    sAnalogData[index] = (data[i] + i16).ToString();
-
 
535
                    dtAnalog.Rows[index].SetField(1, sAnalogData[index]);
-
 
536
 
-
 
537
                    if (adr == 2) //NC
-
 
538
                    {
-
 
539
                        switch (index)
-
 
540
                        {
-
 
541
                            case 0: //pitch (German: nick)
-
 
542
                                artificialHorizon1.Invoke((Action)(() => artificialHorizon1.pitch_angle = ((double)iAnalogData[index] / (double)10)));
-
 
543
                                lblNCPitch.Invoke((Action)(() => lblNCPitch.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0°")));
-
 
544
                                break;
-
 
545
                            case 1: //roll
-
 
546
                                artificialHorizon1.Invoke((Action)(() => artificialHorizon1.roll_angle = ((double)iAnalogData[index] / (double)10)));
-
 
547
                                lblNCRoll.Invoke((Action)(() => lblNCRoll.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0°")));
-
 
548
                                break;
-
 
549
                            case 4: //altitude
-
 
550
                                lblNCAlt.Invoke((Action)(() => lblNCAlt.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 m")));
-
 
551
                                break;
-
 
552
                            case 7: //Voltage
-
 
553
                                lblNCVolt.Invoke((Action)(() => lblNCVolt.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 V")));
-
 
554
                                break;
-
 
555
                            case 8: // Current
-
 
556
                                lblNCCur.Invoke((Action)(() => lblNCCur.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 A")));
-
 
557
                                break;
-
 
558
                            case 10: //heading
-
 
559
                                lblNCCompass.Invoke((Action)(() => lblNCCompass.Text = sAnalogData[index] + "°"));
-
 
560
                                headingIndicator1.Invoke((Action)(() => headingIndicator1.SetHeadingIndicatorParameters(iAnalogData[index])));
-
 
561
                                break;
-
 
562
                            case 12: // SPI error
-
 
563
                                lblNCSPI.Invoke((Action)(() => lblNCSPI.Text = sAnalogData[index]));
-
 
564
                                break;
-
 
565
                            case 14: //i2c error
-
 
566
                                lblNCI2C.Invoke((Action)(() => lblNCI2C.Text = sAnalogData[index]));
-
 
567
                                break;
-
 
568
                            case 20: //Earthmagnet field
-
 
569
                                lblNCMF.Invoke((Action)(() => lblNCMF.Text = sAnalogData[index] + "%"));
-
 
570
                                break;
-
 
571
                            case 21: //GroundSpeed
-
 
572
                                lblNCGSpeed.Invoke((Action)(() => lblNCGSpeed.Text = ((double)iAnalogData[index] / (double)100).ToString("0.00 m/s")));
-
 
573
                                break;
-
 
574
                            case 28: //Distance East from saved home position -> calculate distance with distance N + height
-
 
575
                                dTemp = Math.Pow((double)iAnalogData[index], 2) + Math.Pow((double)iAnalogData[index - 1], 2);
-
 
576
                                dTemp = Math.Sqrt(dTemp) / (double)10; //'flat' distance from HP with N/E
-
 
577
                                                                       //  lblNCDist.Invoke((Action)(() => lblNCDist.Text = dTemp.ToString("0.00")));
-
 
578
                                dTemp = Math.Pow(dTemp, 2) + Math.Pow(((double)iAnalogData[4] / (double)10), 2); //adding 'height' into calculation
-
 
579
                                dTemp = Math.Sqrt(dTemp);
-
 
580
                                lblNCDistHP.Invoke((Action)(() => lblNCDistHP.Text = dTemp.ToString("0 m")));
-
 
581
                                break;
-
 
582
                            case 31: //Sats used
-
 
583
                                lblNCSat.Invoke((Action)(() => lblNCSat.Text = sAnalogData[index]));
-
 
584
                                break;
-
 
585
                        }
-
 
586
                    }
-
 
587
                    if (adr == 1) //FC
-
 
588
                    {
-
 
589
                        switch (index)
-
 
590
                        {
-
 
591
                            case 0: //pitch (German: nick)
-
 
592
                                artificialHorizon1.Invoke((Action)(() => artificialHorizon1.pitch_angle = ((double)iAnalogData[index] / (double)10)));
-
 
593
                                lblNCPitch.Invoke((Action)(() => lblNCPitch.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0°")));
-
 
594
                                break;
-
 
595
                            case 1: //roll
-
 
596
                                artificialHorizon1.Invoke((Action)(() => artificialHorizon1.roll_angle = ((double)iAnalogData[index] / (double)10)));
-
 
597
                                lblNCRoll.Invoke((Action)(() => lblNCRoll.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0°")));
-
 
598
                                break;
-
 
599
                            case 5: //altitude
-
 
600
                                lblNCAlt.Invoke((Action)(() => lblNCAlt.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 m")));
-
 
601
                                break;
-
 
602
                            case 8: //heading
-
 
603
                                lblNCCompass.Invoke((Action)(() => lblNCCompass.Text = sAnalogData[index] + "°"));
-
 
604
                                headingIndicator1.Invoke((Action)(() => headingIndicator1.SetHeadingIndicatorParameters(iAnalogData[index])));
-
 
605
                                break;
-
 
606
                            case 9: //Voltage
-
 
607
                                lblNCVolt.Invoke((Action)(() => lblNCVolt.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 V")));
-
 
608
                                break;
-
 
609
                            case 10: //Receiver quality
-
 
610
                                lblNCRC.Invoke((Action)(() => lblNCRC.Text = sAnalogData[index]));
-
 
611
                                break;
-
 
612
                            case 22: // Current
-
 
613
                                lblNCCur.Invoke((Action)(() => lblNCCur.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 A")));
-
 
614
                                break;
-
 
615
                            case 23: //capacity used
-
 
616
                                lblNCCap.Invoke((Action)(() => lblNCCap.Text = (iAnalogData[index]).ToString("0 mAh")));
-
 
617
                                break;
-
 
618
                            case 27: // SPI error
-
 
619
                                lblNCSPI.Invoke((Action)(() => lblNCSPI.Text = sAnalogData[index]));
-
 
620
                                break;
-
 
621
                            case 28: //i2c error
-
 
622
                                lblNCI2C.Invoke((Action)(() => lblNCI2C.Text = sAnalogData[index]));
-
 
623
                                break;
-
 
624
                        }
-
 
625
                    }
-
 
626
                    index++;
-
 
627
                }
-
 
628
            }
-
 
629
            else
-
 
630
                Debug.Print("wrong data-length (66): " + data.Length.ToString());
-
 
631
        }
-
 
632
        /// <summary>
-
 
633
        /// Version string 'V'
-
 
634
        /// </summary>
-
 
635
        /// <param name="adr">adress of the active controller (1-FC, 2-NC)</param>
-
 
636
        /// <param name="data">the received byte array to process</param>
-
 
637
        void _processVersion(byte adr,byte[] data)
-
 
638
        {
-
 
639
            if (data.Length == 12)
-
 
640
            {
-
 
641
                if (!check_HWError)
-
 
642
                {
-
 
643
                    string[] sVersionStruct = new string[10] { "SWMajor: ", "SWMinor: ", "ProtoMajor: ", "LabelTextCRC: ", "SWPatch: ", "HardwareError 1: ", "HardwareError 2: ", "HWMajor: ", "BL_Firmware: ", "Flags: " };
-
 
644
                    string sVersion = "";
-
 
645
                    //sbyte[] signed = Array.ConvertAll(data, b => unchecked((sbyte)b));
-
 
646
                    Log(LogMsgType.Warning, (adr == 1 ? "FC-" : "NC-") + "Version: ");
-
 
647
                    sVersion = "HW V" + (data[7] / 10).ToString() + "." + (data[7] % 10).ToString();
-
 
648
                    Log(LogMsgType.Incoming, sVersion);
-
 
649
                    sVersion = "SW V" + (data[0]).ToString() + "." + (data[1]).ToString() + ((char)(data[4] + 'a')).ToString();
-
 
650
                    Log(LogMsgType.Incoming, sVersion);
-
 
651
                    Log(LogMsgType.Incoming, "BL-Firmware: V" + (data[8] / 100).ToString() + "." + (data[8] % 100).ToString());
-
 
652
                }
-
 
653
                if (data[5] > 0) //error0 
-
 
654
                {
-
 
655
                    if (adr == 1)
-
 
656
                        ErrorLog(LogMsgType.Error, "FC - HW-Error " + data[5].ToString() + ": " + ((FC_HWError0)data[5]).ToString());
-
 
657
                    if (adr == 2)
-
 
658
                        ErrorLog(LogMsgType.Error, "NC - HW-Error " + data[5].ToString() + ": " + ((NC_HWError0)data[5]).ToString());
-
 
659
                }
-
 
660
                if (data[6] > 0) //error1 
-
 
661
                {
-
 
662
                    if (adr == 1)
-
 
663
                        ErrorLog(LogMsgType.Error, "FC - HW-Error " + data[6].ToString() + ": " + ((FC_HWError1)data[6]).ToString());
-
 
664
                    if (adr == 2)
-
 
665
                        ErrorLog(LogMsgType.Error, "NC - Unknown HW-ERROR: " + data[6].ToString()); //@moment NC has only one error field
-
 
666
                }
-
 
667
 
-
 
668
            }
-
 
669
            check_HWError = false;
-
 
670
        }
-
 
671
        /// <summary>
-
 
672
        /// BL-Ctrl data 'K'
-
 
673
        /// for FC you have to use a customized firmware
-
 
674
        /// </summary>
-
 
675
        /// <param name="data">the received byte array to process</param>
-
 
676
        void _processBLCtrl(byte[] data)
-
 
677
        {
-
 
678
            if (data.Length % 6 == 0) //data.Length up to 96 (16 motors x 6 byte data) --> new datastruct in FC -> not standard!
-
 
679
            {
-
 
680
                bool bAvailable = false;
-
 
681
                for (int i = 0; i < data.Length && data[i] < 8; i += 6) // data[i] < 8 --> at moment there are 8 display fields for motors
-
 
682
                {
-
 
683
 
-
 
684
                    if ((data[i + 4] & 128) == 128) //Status bit at pos 7 = 128 dec -- if true, motor is available
-
 
685
                        bAvailable = true;
-
 
686
                    else
-
 
687
                        bAvailable = false;
-
 
688
 
-
 
689
                    if (data[i] < 4)
-
 
690
                    {
-
 
691
                        if (bAvailable)
-
 
692
                        {
-
 
693
                            dtMotors1.Rows[data[i]].SetField(1, ((double)data[i + 1] / (double)10).ToString("0.0 A"));
-
 
694
                            dtMotors1.Rows[data[i]].SetField(2, data[i + 2].ToString("0 °C"));
-
 
695
                        }
-
 
696
                        else
-
 
697
                        {
-
 
698
                            dtMotors1.Rows[data[i]].SetField(1, "NA");
-
 
699
                            dtMotors1.Rows[data[i]].SetField(2, "NA");
-
 
700
                        }
-
 
701
                    }
-
 
702
                    if (data[i] > 3 && data[i] < 8)
-
 
703
                    {
-
 
704
                        if (bAvailable)
-
 
705
                        {
-
 
706
                            dtMotors2.Rows[data[i] - 4].SetField(1, ((double)data[i + 1] / (double)10).ToString("0.0 A"));
-
 
707
                            dtMotors2.Rows[data[i] - 4].SetField(2, data[i + 2].ToString("0 °C"));
-
 
708
                        }
-
 
709
                        else
-
 
710
                        {
-
 
711
                            dtMotors2.Rows[data[i] - 4].SetField(1, "NA");
-
 
712
                            dtMotors2.Rows[data[i] - 4].SetField(2, "NA");
-
 
713
                        }
-
 
714
                    }
-
 
715
                }
-
 
716
            }
-
 
717
 
-
 
718
        }
-
 
719
        /// <summary>
-
 
720
        /// Navi-Ctrl data 'O'
-
 
721
        /// GPS-Position, capacatiy, flying time...
-
 
722
        /// </summary>
-
 
723
        /// <param name="data">the received byte array to process</param>
-
 
724
        void _processNCData(byte[] data)
-
 
725
        {
-
 
726
            int i_32, i_16, iVal;
-
 
727
            double d;
-
 
728
            i_32 = data[4];
-
 
729
            iVal = i_32 << 24;
-
 
730
            i_32 = data[3];
-
 
731
            iVal += i_32 << 16;
-
 
732
            i_32 = data[2];
-
 
733
            iVal += i_32 << 8;
-
 
734
            iVal += data[1];
-
 
735
            d = (double)iVal / Math.Pow(10, 7);
-
 
736
            lblNCGPSLong.Invoke((Action)(() => lblNCGPSLong.Text = d.ToString("0.######°"))); //GPS-Position: Longitude in decimal degree
-
 
737
            //lblNCGPSLong.Invoke((Action)(() => lblNCGPSLong.Text = _convertDegree(d))); //GPS-Position: Longitude in minutes, seconds
-
 
738
 
-
 
739
            i_32 = data[8];
-
 
740
            iVal = i_32 << 24;
-
 
741
            i_32 = data[7];
-
 
742
            iVal += i_32 << 16;
-
 
743
            i_32 = data[6];
-
 
744
            iVal += i_32 << 8;
-
 
745
            iVal += data[5];
-
 
746
            d = (double)iVal / Math.Pow(10, 7);
-
 
747
            lblNCGPSLat.Invoke((Action)(() => lblNCGPSLat.Text = d.ToString("0.######°"))); //GPS-Position: Latitude in decimal degree
-
 
748
            //lblNCGPSLat.Invoke((Action)(() => lblNCGPSLat.Text = _convertDegree(d))); //GPS-Position: Latitude in minutes, seconds
-
 
749
 
-
 
750
            i_16 = data[81];
-
 
751
            i_16 = (Int16)(i_16 << 8);
-
 
752
            iVal = data[80] + i_16;
-
 
753
            lblNCCap.Invoke((Action)(() => lblNCCap.Text = iVal.ToString() + " mAh")); //Capacity used
-
 
754
 
-
 
755
            i_16 = data[56];
-
 
756
            i_16 = (Int16)(i_16 << 8);
-
 
757
            iVal = data[55] + i_16;
-
 
758
            TimeSpan t = TimeSpan.FromSeconds(iVal);
-
 
759
            string Text = t.Hours.ToString("D2") + ":" + t.Minutes.ToString("D2") + ":" + t.Seconds.ToString("D2");
-
 
760
            lblNCFlTime.Invoke((Action)(() => lblNCFlTime.Text = Text.ToString())); //Flying time
-
 
761
 
-
 
762
            lblNCRC.Invoke((Action)(() => lblNCRC.Text = data[66].ToString())); //RC quality
-
 
763
            lblNCErrNmbr.Invoke((Action)(() => lblNCErrNmbr.Text = data[69].ToString()));   //NC Errornumber
-
 
764
            //if (data[69] > 0)
-
 
765
            //    _readNCError();
-
 
766
            //break;
-
 
767
            if (data[69] > 0 & data[69] < 44)
-
 
768
                ErrorLog(LogMsgType.Error, "NC Error [" + data[69].ToString() + "]: " + NC_Error[data[69]]);
-
 
769
 
-
 
770
        }
-
 
771
        /// <summary>
-
 
772
        /// OSD Menue 'L'
-
 
773
        /// single page called by pagenumber
-
 
774
        /// no autoupdate
-
 
775
        /// </summary>
-
 
776
        /// <param name="data">the received byte array to process</param>
-
 
777
        void _processOSDSingle(byte[] data)
-
 
778
        {
-
 
779
            if (data.Length == 84)
-
 
780
            {
-
 
781
                string sMessage = "";
-
 
782
                iOSDPage = data[0];
-
 
783
                iOSDMax = data[1];
-
 
784
                if (cbOSD.Items.Count != iOSDMax) _initOSDCB();
-
 
785
                sMessage = new string(ASCIIEncoding.ASCII.GetChars(data, 2, data.Length - 4));
-
 
786
                OSD(LogMsgType.Incoming, sMessage.Substring(0, 20));
-
 
787
                OSD(LogMsgType.Incoming, sMessage.Substring(20, 20));
-
 
788
                OSD(LogMsgType.Incoming, sMessage.Substring(40, 20));
-
 
789
                OSD(LogMsgType.Incoming, sMessage.Substring(60, 20));
-
 
790
                lblOSDPageNr.Invoke((Action)(() => lblOSDPageNr.Text = iOSDPage.ToString("[0]")));
-
 
791
 
-
 
792
            }
-
 
793
            else
-
 
794
                OSD(LogMsgType.Incoming, "Wrong length: " + data.Length + " (should be 84)");
-
 
795
 
-
 
796
        }
-
 
797
        /// <summary>
-
 
798
        /// OSD Menue 'H'
-
 
799
        /// called by keys (0x01,0x02,0x03,0x04)
-
 
800
        /// autoupdate
-
 
801
        /// </summary>
-
 
802
        /// <param name="data">the received byte array to process</param>
-
 
803
        void _processOSDAuto(byte[] data)
-
 
804
        {
-
 
805
            if (data.Length == 81)
-
 
806
            {
-
 
807
                string sMessage = "";
-
 
808
                sMessage = new string(ASCIIEncoding.ASCII.GetChars(data, 0, data.Length - 1));
-
 
809
                OSD(LogMsgType.Incoming, sMessage.Substring(0, 20));
-
 
810
                OSD(LogMsgType.Incoming, sMessage.Substring(20, 20));
-
 
811
                OSD(LogMsgType.Incoming, sMessage.Substring(40, 20));
-
 
812
                OSD(LogMsgType.Incoming, sMessage.Substring(60, 20));
-
 
813
 
-
 
814
            }
-
 
815
            else
-
 
816
                OSD(LogMsgType.Incoming, "Wrong length: " + data.Length + " (should be 81)");
-
 
817
        }
-
 
818
        #endregion processing received data
Line 660... Line 819...
660
 
819
 
661
        /// <summary> send message to controller to request data
820
        /// <summary> send message to controller to request data
662
        /// for detailed info see http://wiki.mikrokopter.de/en/SerialProtocol/
821
        /// for detailed info see http://wiki.mikrokopter.de/en/SerialProtocol/
663
        /// </summary>
822
        /// </summary>
Line 911... Line 1070...
911
            bReadContinously = b;
1070
            bReadContinously = b;
912
            btnReadDebugCont.Invoke((Action)(() => btnReadDebugCont.Text = bReadContinously ? "stop automatic" + Environment.NewLine + "data refresh" : "start automatic" + Environment.NewLine + "data refresh"));
1071
            btnReadDebugCont.Invoke((Action)(() => btnReadDebugCont.Text = bReadContinously ? "stop automatic" + Environment.NewLine + "data refresh" : "start automatic" + Environment.NewLine + "data refresh"));
913
            btnReadDebugCont.Invoke((Action)(() => btnReadDebugCont.BackColor = bReadContinously ? Color.FromArgb(192, 255, 192) : Color.FromArgb(224, 224, 224)));
1072
            btnReadDebugCont.Invoke((Action)(() => btnReadDebugCont.BackColor = bReadContinously ? Color.FromArgb(192, 255, 192) : Color.FromArgb(224, 224, 224)));
914
            if (bReadContinously)
1073
            if (bReadContinously)
915
            {
1074
            {
916
                _readDebugData(true);
1075
                if (_debugDataAutorefresh) { _readDebugData(true); Thread.Sleep(10); }
917
                if (_iCtrlAct == 2) { Thread.Sleep(10); _readBLCtrl(true);}
1076
                if (_blctrlDataAutorefresh) { _readBLCtrl(true); Thread.Sleep(10); }
918
                if (_iCtrlAct == 2) { Thread.Sleep(10); _readNavData(true);}
1077
                if (_navCtrlDataAutorefresh && _iCtrlAct == 2) { _readNavData(true); Thread.Sleep(10); }
919
                Thread.Sleep(10);
-
 
920
                _OSDMenueAutoRefresh();
1078
                if (_OSDAutorefresh) { _OSDMenueAutoRefresh(); Thread.Sleep(10);}
921
                lblLifeCounter.Invoke((Action)(() => lblLifeCounter.BackColor = Color.FromArgb(0, 224, 0)));
1079
                lblLifeCounter.Invoke((Action)(() => lblLifeCounter.BackColor = Color.FromArgb(0, 224, 0)));
922
            }
1080
            }
923
            else
1081
            else
924
                lblLifeCounter.Invoke((Action)(() => lblLifeCounter.BackColor = Color.FromArgb(224, 224, 224)));
1082
                lblLifeCounter.Invoke((Action)(() => lblLifeCounter.BackColor = Color.FromArgb(224, 224, 224)));
925
            _iLifeCounter = 0;
1083
            _iLifeCounter = 0;
926
        }
1084
        }
927
        /// <summary>
1085
        /// <summary>
928
        /// set fieldtexts to "NA" when not available with FC
1086
        /// set values to "NA" when not available with FC
929
        /// </summary>
1087
        /// </summary>
930
        void _setFieldsNA()
1088
        void _setFieldsNA()
931
        {
1089
        {
932
            Thread.Sleep(100);
1090
            Thread.Sleep(100);
933
            Label lbCur = new Label(), lbTemp = new Label();
-
 
934
            for (int i = 0; i < 8; i++)
-
 
935
            {
-
 
936
                //BL-Ctrl Temp & Current
-
 
937
                switch (i)
1091
            _initDTMotors();
938
                {
-
 
939
                    case 0:
-
 
940
                        lbCur = LBLNCM1Cur;
-
 
941
                        lbTemp = LBLNCM1Temp;
-
 
942
                        break;
-
 
943
                    case 1:
-
 
944
                        lbCur = LBLNCM2Cur;
-
 
945
                        lbTemp = LBLNCM2Temp;
-
 
946
                        break;
-
 
947
                    case 2:
-
 
948
                        lbCur = LBLNCM3Cur;
-
 
949
                        lbTemp = LBLNCM3Temp;
-
 
950
                        break;
-
 
951
                    case 3:
-
 
952
                        lbCur = LBLNCM4Cur;
-
 
953
                        lbTemp = LBLNCM4Temp;
-
 
954
                        break;
-
 
955
                    case 4:
-
 
956
                        lbCur = LBLNCM5Cur;
-
 
957
                        lbTemp = LBLNCM5Temp;
-
 
958
                        break;
-
 
959
                    case 5:
-
 
960
                        lbCur = LBLNCM6Cur;
-
 
961
                        lbTemp = LBLNCM6Temp;
-
 
962
                        break;
-
 
963
                    case 6:
-
 
964
                        lbCur = LBLNCM7Cur;
-
 
965
                        lbTemp = LBLNCM7Temp;
-
 
966
                        break;
-
 
967
                    case 7:
-
 
968
                        lbCur = LBLNCM8Cur;
-
 
969
                        lbTemp = LBLNCM8Temp;
-
 
970
                        break;
-
 
971
                }
-
 
972
                if (lbCur != null)
-
 
973
                    lbCur.Invoke((Action)(() => lbCur.Text = "NA"));
-
 
974
                if (lbTemp != null)
-
 
975
                    lbTemp.Invoke((Action)(() => lbTemp.Text = "NA"));
-
 
976
 
-
 
977
            }
-
 
978
            lblNCFlTime.Invoke((Action)(() => lblNCFlTime.Text = "NA"));    //FlightTime
1092
            lblNCFlTime.Invoke((Action)(() => lblNCFlTime.Text = "NA"));    //FlightTime
979
            lblNCErrNmbr.Invoke((Action)(() => lblNCErrNmbr.Text = "NA")); //NC ErrorNr
1093
            lblNCErrNmbr.Invoke((Action)(() => lblNCErrNmbr.Text = "NA"));  //NC ErrorNr
980
            lblNCMF.Invoke((Action)(() => lblNCMF.Text = "NA"));           //earth magnet field
1094
            lblNCMF.Invoke((Action)(() => lblNCMF.Text = "NA"));            //earth magnet field
981
            lblNCGSpeed.Invoke((Action)(() => lblNCGSpeed.Text = "NA")); //GroundSpeed
1095
            lblNCGSpeed.Invoke((Action)(() => lblNCGSpeed.Text = "NA"));    //GroundSpeed
982
            lblNCDist.Invoke((Action)(() => lblNCDist.Text = "NA")); //Distance to HP
1096
            lblNCDistHP.Invoke((Action)(() => lblNCDistHP.Text = "NA"));    //Distance to HP
983
            lblNCSat.Invoke((Action)(() => lblNCSat.Text = "NA"));      //Sats used
1097
            lblNCSat.Invoke((Action)(() => lblNCSat.Text = "NA"));          //Sats used
-
 
1098
            lblNCGPSLong.Invoke((Action)(() => lblNCGPSLong.Text = "NA"));  //GPS position - longitude
-
 
1099
            lblNCGPSLat.Invoke((Action)(() => lblNCGPSLat.Text = "NA"));    //GPS position - latitude
984
        }
1100
        }
985
        /// <summary>
1101
        /// <summary>
986
        /// one time query of the OSD Menue with pagenumber
1102
        /// one time query of the OSD Menue with pagenumber
987
        /// </summary>
1103
        /// </summary>
988
        /// <param name="iMenue">Menue page</param>
1104
        /// <param name="iMenue">Menue page</param>
Line 1075... Line 1191...
1075
            ini.IniWriteValue("default", "IntervalNavCtrlData", navctrlInterval.ToString());
1191
            ini.IniWriteValue("default", "IntervalNavCtrlData", navctrlInterval.ToString());
1076
            ini.IniWriteValue("default", "IntervalBLCtrlData", blctrlInterval.ToString());
1192
            ini.IniWriteValue("default", "IntervalBLCtrlData", blctrlInterval.ToString());
1077
            ini.IniWriteValue("default", "IntervalOSDData", OSDInterval.ToString());
1193
            ini.IniWriteValue("default", "IntervalOSDData", OSDInterval.ToString());
1078
        }
1194
        }
Line -... Line 1195...
-
 
1195
 
-
 
1196
        /// <summary>
-
 
1197
        /// initialize the 2 datatables for motor values
-
 
1198
        /// dtMotors1 - motor 1 - 4
-
 
1199
        /// dtMotors2 - motor 5 - 8
-
 
1200
        /// DataGridView dgvMotors1/2 are bound to dtMotors1/2 
-
 
1201
        /// </summary>
-
 
1202
        void _initDTMotors()
-
 
1203
        {
-
 
1204
            for(int i = 0; i < 4; i++)
-
 
1205
            {
-
 
1206
                if (dtMotors1.Rows.Count < 4)
-
 
1207
                    dtMotors1.Rows.Add((i + 1).ToString(), "NA", "NA");
-
 
1208
                else
-
 
1209
                {
-
 
1210
                    dtMotors1.Rows[i].SetField(1, "NA");
-
 
1211
                    dtMotors1.Rows[i].SetField(2, "NA");
-
 
1212
                }
-
 
1213
                if (dtMotors2.Rows.Count < 4)
-
 
1214
                    dtMotors2.Rows.Add((i + 5).ToString(), "NA", "NA");
-
 
1215
                else
-
 
1216
                {
-
 
1217
                    dtMotors2.Rows[i].SetField(1, "NA");
-
 
1218
                    dtMotors2.Rows[i].SetField(2, "NA");
-
 
1219
                }
-
 
1220
            }
-
 
1221
            dgvMotors1.Invoke((Action)(() => dgvMotors1.Refresh()));
-
 
1222
            dgvMotors2.Invoke((Action)(() => dgvMotors2.Refresh()));
-
 
1223
        }
-
 
1224
 
-
 
1225
        /// <summary>
-
 
1226
        /// Convert decimal degrees to degrees, minutes, seconds, milliseconds 
-
 
1227
        /// </summary>
-
 
1228
        /// <param name="coord">the degree value as double</param>
-
 
1229
        /// <returns>0° 0' 0,0"</returns>
-
 
1230
        string _convertDegree(double coord)
-
 
1231
        {
-
 
1232
            //double minutes = (degree - Math.Floor(degree)) * 60.0;
-
 
1233
            //double seconds = (minutes - Math.Floor(minutes)) * 60.0;
-
 
1234
            //double tenths = (seconds - Math.Floor(seconds)) * 10.0;
-
 
1235
            //// get rid of fractional part
-
 
1236
            //minutes = Math.Floor(minutes);
-
 
1237
            //seconds = Math.Floor(seconds);
-
 
1238
            //tenths = Math.Floor(tenths);
-
 
1239
 
-
 
1240
 
-
 
1241
            //int sec = (int)Math.Round(coord * 3600);
-
 
1242
            //int deg = sec / 3600;
-
 
1243
            //sec = Math.Abs(sec % 3600);
-
 
1244
            //int min = sec / 60;
-
 
1245
            //sec %= 60;
-
 
1246
 
-
 
1247
            var ts = TimeSpan.FromHours(Math.Abs(coord));
-
 
1248
            double deg = Math.Sign(coord) * Math.Floor(ts.TotalHours);
-
 
1249
            int min = ts.Minutes;
-
 
1250
            int sec = ts.Seconds;
-
 
1251
            int milli = ts.Milliseconds;
-
 
1252
 
-
 
1253
            return deg.ToString("0° ") + min.ToString("0") + "' " + sec.ToString("0") + "," + milli.ToString() + "\"";
1079
 
1254
        }
Line 1080... Line 1255...
1080
        #endregion functions
1255
        #endregion functions
1081
 
1256
 
1082
        #region buttons
1257
        #region buttons
Line 1197... Line 1372...
1197
        private void btnOSDEnter_Click(object sender, EventArgs e)
1372
        private void btnOSDEnter_Click(object sender, EventArgs e)
1198
        {
1373
        {
1199
            _OSDMenueAutoRefresh(4);
1374
            _OSDMenueAutoRefresh(4);
1200
        }
1375
        }
1201
        #endregion buttons
1376
        #endregion buttons
1202
 
-
 
1203
    }
1377
    }
1204
    public class IniFile
1378
    public class IniFile
1205
    {
1379
    {
1206
        public string path;
1380
        public string path;