Subversion Repositories FlightCtrl

Rev

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

Rev 1053 Rev 1054
Line 7... Line 7...
7
#include <stdarg.h>
7
#include <stdarg.h>
8
#include <string.h>
8
#include <string.h>
9
#include "main.h"
9
#include "main.h"
10
#include "uart.h"
10
#include "uart.h"
Line -... Line 11...
-
 
11
 
-
 
12
 
-
 
13
#define FC_ADDRESS 1
-
 
14
#define NC_ADDRESS 2
-
 
15
#define MK3MAG_ADDRESS 3
11
 
16
 
12
unsigned char GetExternalControl = 0,DebugDisplayAnforderung1 = 0, DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0, GetPPMChannelAnforderung = 0;
17
unsigned char GetExternalControl = 0,DebugDisplayAnforderung1 = 0, DebugDisplayAnforderung = 0,DebugDataAnforderung = 0,GetVersionAnforderung = 0, GetPPMChannelAnforderung = 0;
13
unsigned char DisplayLine = 0;
18
unsigned char DisplayLine = 0;
14
unsigned volatile char SioTmp = 0;
19
unsigned volatile char SioTmp = 0;
15
unsigned volatile char SendeBuffer[MAX_SENDE_BUFF];
20
unsigned volatile char SendeBuffer[MAX_SENDE_BUFF];
Line 278... Line 283...
278
// --------------------------------------------------------------------------
283
// --------------------------------------------------------------------------
279
void BearbeiteRxDaten(void)
284
void BearbeiteRxDaten(void)
280
{
285
{
281
 if(!NeuerDatensatzEmpfangen) return;
286
 if(!NeuerDatensatzEmpfangen) return;
Line -... Line 287...
-
 
287
 
-
 
288
        switch(RxdBuffer[1]) // check for Slave Address
-
 
289
        {
282
 
290
                case FC_ADDRESS: // FC special commands
-
 
291
                Decode64(); // dekodiere datenblock im Empfangsbuffer
-
 
292
                switch(RxdBuffer[2])
-
 
293
                {
-
 
294
                        case 'K':// Kompasswert
-
 
295
                                        memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue));
-
 
296
                                        KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180;
-
 
297
                                        break;
-
 
298
 
-
 
299
                        case 't':// Motortest
-
 
300
                                        memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest));
-
 
301
                                        while(!UebertragungAbgeschlossen);
-
 
302
                                        SendOutData('T', MeineSlaveAdresse, 0);
-
 
303
                                        PcZugriff = 255;
-
 
304
                                        break;
-
 
305
 
-
 
306
                        case 'p': // get PPM Channels
-
 
307
                                        GetPPMChannelAnforderung = 1;
-
 
308
                                        break;
-
 
309
 
-
 
310
                        case 'q':// "Get"-Anforderung für Settings
-
 
311
                                        // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen
-
 
312
                                        if(pRxData[0] == 0xFF)
-
 
313
                                        {
-
 
314
                                                pRxData[0] = GetActiveParamSetNumber();
-
 
315
                                        }
-
 
316
                                        else // request active parameter set
-
 
317
                                        {
-
 
318
                                                if(pRxData[0] < 1) pRxData[0] = 1; // limit to 5
-
 
319
                                                else if(pRxData[0] > 5) pRxData[0] = 5; // limit to 5
-
 
320
                                                // load requested parameter set
-
 
321
                                                ReadParameterSet(pRxData[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
-
 
322
                                        }
-
 
323
                                        while(!UebertragungAbgeschlossen);
-
 
324
                                        SendOutData('Q', FC_ADDRESS, 2, &pRxData[0], sizeof(unsigned char), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
-
 
325
                                        break;
-
 
326
 
-
 
327
                        case 's': // Parametersatz speichern
-
 
328
                                        if((1 <= pRxData[0]) && (pRxData[0] <= 5)) // check for setting to be in range
-
 
329
                                        {
-
 
330
                                                memcpy((unsigned char *) &EE_Parameter.Kanalbelegung[0], (unsigned char *)&pRxData[1], STRUCT_PARAM_LAENGE);
-
 
331
                                                WriteParameterSet(pRxData[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
-
 
332
                                                eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], RxdBuffer[2] - 'l' + 1);  // aktiven Datensatz merken
-
 
333
                                                Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
-
 
334
                                                Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
-
 
335
                                                Piep(GetActiveParamSetNumber());
-
 
336
                                                while(!UebertragungAbgeschlossen);
-
 
337
                                                SendOutData('S', FC_ADDRESS, 1, &pRxData[0], sizeof(unsigned char));
-
 
338
                                        }
Line 283... Line -...
283
  Decode64(); // dekodiere datenblock im Empfangsbuffer
-
 
284
 
-
 
285
  switch(RxdBuffer[2])
-
 
286
  {
-
 
287
   case 'K':// Kompasswert
-
 
288
            memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue));
-
 
289
            KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180;
-
 
290
                        break;
-
 
291
   case 'a':// Texte der Analogwerte
-
 
292
            DebugTextAnforderung = pRxData[0];
-
 
293
            if (DebugTextAnforderung > 31) DebugTextAnforderung = 31;
-
 
294
            PcZugriff = 255;
-
 
295
                        break;
-
 
296
   case 'b':
-
 
297
                        memcpy((unsigned char *)&ExternControl, (unsigned char *)pRxData, sizeof(ExternControl));
-
 
298
            ConfirmFrame = ExternControl.Frame;
-
 
299
            PcZugriff = 255;
-
 
300
            break;
-
 
301
   case 'd': // Poll the debug data
-
 
302
                        DebugDataIntervall = pRxData[0] * 10;
-
 
303
            if (DebugDataIntervall) DebugDataAnforderung = 1;
-
 
304
            break;
-
 
305
 
-
 
306
   case 'h':// x-1 Displayzeilen
-
 
307
                RemoteKeys |= pRxData[0];
-
 
308
                if(RemoteKeys) DisplayLine = 0;
-
 
309
                        DebugDisplayAnforderung = 1;
-
 
310
                        break;
-
 
311
 
-
 
312
   case 'l':// x-1 Displayzeilen
-
 
313
            MenuePunkt = pRxData[0];
-
 
314
                        DebugDisplayAnforderung1 = 1;
-
 
315
                        break;
-
 
316
   case 't':// Motortest
-
 
317
            memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest));
-
 
318
            while(!UebertragungAbgeschlossen);
-
 
319
            SendOutData('T', MeineSlaveAdresse, 0);
-
 
320
            PcZugriff = 255;
-
 
321
                        break;
-
 
322
   case 'v': // Version-Anforderung     und Ausbaustufe
-
 
323
            GetVersionAnforderung = 1;
-
 
324
            break;
-
 
325
   case 'g'://
-
 
326
                        GetExternalControl = 1;
-
 
327
            break;
-
 
328
   case 'p': // get PPM Channels
-
 
329
                        GetPPMChannelAnforderung = 1;
-
 
330
                        break;
-
 
331
   case 'q':// "Get"-Anforderung für Settings
-
 
332
            // Bei Get werden die vom PC einstellbaren Werte vom PC zurückgelesen
-
 
333
            if(pRxData[0] == 0xFF)
-
 
334
                        {
339
                                        break;
335
                                pRxData[0] = GetActiveParamSetNumber();
340
 
336
                        }
-
 
337
                        else // request active parameter set
-
 
338
                        {
-
 
339
                                if(pRxData[0] < 1) pRxData[0] = 1; // limit to 5
-
 
340
                                else if(pRxData[0] > 5) pRxData[0] = 5; // limit to 5
-
 
341
                                // load requested parameter set
-
 
342
                                ReadParameterSet(pRxData[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
-
 
343
                        }
-
 
344
            while(!UebertragungAbgeschlossen);
-
 
345
            SendOutData('Q', MeineSlaveAdresse, 2, &pRxData[0], sizeof(unsigned char), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
-
 
346
            break;
-
 
347
   case 's': // Parametersatz speichern
-
 
348
                        if((1 <= pRxData[0]) && (pRxData[0] <= 5)) // check for setting to be in range
-
 
349
                        {
-
 
350
                                memcpy((unsigned char *) &EE_Parameter.Kanalbelegung[0], (unsigned char *)&pRxData[1], STRUCT_PARAM_LAENGE);
-
 
351
                                WriteParameterSet(pRxData[0], (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
-
 
352
                                eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], RxdBuffer[2] - 'l' + 1);  // aktiven Datensatz merken
-
 
353
                                Umschlag180Nick = (long) EE_Parameter.WinkelUmschlagNick * 2500L;
-
 
354
                                Umschlag180Roll = (long) EE_Parameter.WinkelUmschlagRoll * 2500L;
-
 
355
                                Piep(GetActiveParamSetNumber());
-
 
356
                                while(!UebertragungAbgeschlossen);
-
 
357
                SendOutData('S', MeineSlaveAdresse, 1, &pRxData[0], sizeof(unsigned char));
-
 
Line -... Line 341...
-
 
341
                }
-
 
342
                break; // case FC_ADDRESS:
-
 
343
 
358
                        }
344
                default: // any Slave Address
-
 
345
                Decode64();
-
 
346
                switch(RxdBuffer[2])
-
 
347
                {
-
 
348
                        // 't' comand placed here only for compatibility to BL
-
 
349
                        case 't':// Motortest
-
 
350
                                        memcpy(&MotorTest[0], (unsigned char *)pRxData, sizeof(MotorTest));
-
 
351
                                        while(!UebertragungAbgeschlossen);
-
 
352
                                        SendOutData('T', MeineSlaveAdresse, 0);
-
 
353
                                        PcZugriff = 255;
-
 
354
                                        break;
-
 
355
                        // 'K' comand placed here only for compatibility to old MK3MAG software, that does not send the right Slave Address
-
 
356
                        case 'K':// Kompasswert
-
 
357
                                        memcpy((unsigned char *)&KompassValue , (unsigned char *)pRxData, sizeof(KompassValue));
-
 
358
                                        KompassRichtung = ((540 + KompassValue - KompassStartwert) % 360) - 180;
-
 
359
                                        break;
359
                        break;
360
 
-
 
361
                        case 'a':// Texte der Analogwerte
-
 
362
                                        DebugTextAnforderung = pRxData[0];
-
 
363
                                        if (DebugTextAnforderung > 31) DebugTextAnforderung = 31;
-
 
364
                                        PcZugriff = 255;
-
 
365
                                        break;
-
 
366
 
-
 
367
                        case 'b':
-
 
368
                                        memcpy((unsigned char *)&ExternControl, (unsigned char *)pRxData, sizeof(ExternControl));
-
 
369
                                        ConfirmFrame = ExternControl.Frame;
-
 
370
                                        PcZugriff = 255;
-
 
371
                                        break;
-
 
372
                        case 'd': // Poll the debug data
-
 
373
                                        DebugDataIntervall = pRxData[0] * 10;
-
 
374
                                        if (DebugDataIntervall) DebugDataAnforderung = 1;
-
 
375
                                        break;
-
 
376
 
-
 
377
                        case 'h':// x-1 Displayzeilen
-
 
378
                                        RemoteKeys |= pRxData[0];
-
 
379
                                        if(RemoteKeys) DisplayLine = 0;
-
 
380
                                        DebugDisplayAnforderung = 1;
-
 
381
                                        break;
-
 
382
 
-
 
383
                        case 'l':// x-1 Displayzeilen
-
 
384
                                        MenuePunkt = pRxData[0];
-
 
385
                                        DebugDisplayAnforderung1 = 1;
-
 
386
                                        break;
-
 
387
                        case 'v': // Version-Anforderung und Ausbaustufe
-
 
388
                                        GetVersionAnforderung = 1;
-
 
389
                                        break;
-
 
390
 
-
 
391
                        case 'g'://
-
 
392
                                        GetExternalControl = 1;
-
 
393
                                        break;
360
 
394
                }
361
  }
395
                break; // default:
362
// DebugOut.AnzahlZyklen =  Debug_Timer_Intervall;
396
        }
363
        NeuerDatensatzEmpfangen = 0;
397
        NeuerDatensatzEmpfangen = 0;
Line 409... Line 443...
409
        //öffnet einen Kanal für printf (STDOUT)
443
        //öffnet einen Kanal für printf (STDOUT)
410
        //fdevopen (uart_putchar, 0);
444
        //fdevopen (uart_putchar, 0);
411
        //sbi(PORTD,4);
445
        //sbi(PORTD,4);
412
        Debug_Timer = SetDelay(DebugDataIntervall);
446
        Debug_Timer = SetDelay(DebugDataIntervall);
413
        Kompass_Timer = SetDelay(220);
447
        Kompass_Timer = SetDelay(220);
414
        MeineSlaveAdresse = 1; // Flight-Ctrl
-
 
Line 415... Line 448...
415
 
448
 
416
        VersionInfo.Major = VERSION_MAJOR;
449
        VersionInfo.Major = VERSION_MAJOR;
417
        VersionInfo.Minor = VERSION_MINOR;
450
        VersionInfo.Minor = VERSION_MINOR;
418
        VersionInfo.Patch = VERSION_PATCH;
451
        VersionInfo.Patch = VERSION_PATCH;
Line 437... Line 470...
437
         {
470
         {
438
                  WinkelOut.Winkel[0] = (int) (IntegralNick / 108);  // etwa in 0,1 Grad
471
                  WinkelOut.Winkel[0] = (int) (IntegralNick / 108);  // etwa in 0,1 Grad
439
                  WinkelOut.Winkel[1] = (int) (IntegralRoll / 108);  // etwa in 0,1 Grad
472
                  WinkelOut.Winkel[1] = (int) (IntegralRoll / 108);  // etwa in 0,1 Grad
440
                  WinkelOut.UserParameter[0] = Parameter_UserParam1;
473
                  WinkelOut.UserParameter[0] = Parameter_UserParam1;
441
                  WinkelOut.UserParameter[1] = Parameter_UserParam2;
474
                  WinkelOut.UserParameter[1] = Parameter_UserParam2;
442
          SendOutData('k',MeineSlaveAdresse, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut));
475
          SendOutData('w', MK3MAG_ADDRESS, 1, (unsigned char *) &WinkelOut,sizeof(WinkelOut));
443
          if(WinkelOut.CalcState > 4)  WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt
476
          if(WinkelOut.CalcState > 4)  WinkelOut.CalcState = 6; // wird dann in SPI auf Null gesetzt
444
          Kompass_Timer = SetDelay(99);
477
          Kompass_Timer = SetDelay(99);
445
         }
478
         }
446
    if((( DebugDataIntervall && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen)
479
    if((( DebugDataIntervall && CheckDelay(Debug_Timer)) || DebugDataAnforderung) && UebertragungAbgeschlossen)
447
         {
480
         {
448
          SendOutData('D',MeineSlaveAdresse, 1, (unsigned char *) &DebugOut,sizeof(DebugOut));
481
          SendOutData('D', FC_ADDRESS, 1, (unsigned char *) &DebugOut,sizeof(DebugOut));
449
          DebugDataAnforderung = 0;
482
          DebugDataAnforderung = 0;
450
          if(DebugDataIntervall) Debug_Timer = SetDelay(DebugDataIntervall);
483
          if(DebugDataIntervall) Debug_Timer = SetDelay(DebugDataIntervall);
451
         }
484
         }
452
    if(DebugTextAnforderung != 255) // Texte für die Analogdaten
485
    if(DebugTextAnforderung != 255) // Texte für die Analogdaten
453
     {
486
     {
454
      SendOutData('A', MeineSlaveAdresse, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),(unsigned char *) ANALOG_TEXT[DebugTextAnforderung], 16);
487
      SendOutData('A', FC_ADDRESS, 2, (unsigned char *)&DebugTextAnforderung, sizeof(DebugTextAnforderung),(unsigned char *) ANALOG_TEXT[DebugTextAnforderung], 16);
455
      DebugTextAnforderung = 255;
488
      DebugTextAnforderung = 255;
456
         }
489
         }
457
     if(ConfirmFrame && UebertragungAbgeschlossen)   // Datensatz bestätigen
490
     if(ConfirmFrame && UebertragungAbgeschlossen)   // Datensatz bestätigen
458
         {
491
         {
459
                SendOutData('B', MeineSlaveAdresse, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame));
492
                SendOutData('B', FC_ADDRESS, 1, (uint8_t*)&ConfirmFrame, sizeof(ConfirmFrame));
460
        ConfirmFrame = 0;
493
        ConfirmFrame = 0;
461
     }
494
     }
Line 462... Line 495...
462
 
495
 
463
     if(DebugDisplayAnforderung && UebertragungAbgeschlossen)
496
     if(DebugDisplayAnforderung && UebertragungAbgeschlossen)
464
         {
497
         {
465
             Menu();
498
             Menu();
466
             SendOutData('H',MeineSlaveAdresse, 2, &DisplayLine, sizeof(DisplayLine), &DisplayBuff[DisplayLine * 20], 20);
499
             SendOutData('H', FC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), &DisplayBuff[DisplayLine * 20], 20);
467
             DisplayLine++;
500
             DisplayLine++;
468
             if(DisplayLine >= 4) DisplayLine = 0;
501
             if(DisplayLine >= 4) DisplayLine = 0;
469
                 DebugDisplayAnforderung = 0;
502
                 DebugDisplayAnforderung = 0;
470
         }
503
         }
471
     if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen)
504
     if(DebugDisplayAnforderung1 && UebertragungAbgeschlossen)
472
         {
505
         {
473
        Menu();
506
        Menu();
474
        SendOutData('L',MeineSlaveAdresse, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff));
507
        SendOutData('L', FC_ADDRESS, 3, &MenuePunkt, sizeof(MenuePunkt), &MaxMenue, sizeof(MaxMenue), DisplayBuff, sizeof(DisplayBuff));
475
                DebugDisplayAnforderung1 = 0;
508
                DebugDisplayAnforderung1 = 0;
476
         }
509
         }
477
    if(GetVersionAnforderung && UebertragungAbgeschlossen)
510
    if(GetVersionAnforderung && UebertragungAbgeschlossen)
478
     {
511
     {
479
      SendOutData('V',MeineSlaveAdresse, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo));
512
      SendOutData('V', FC_ADDRESS, 1, (unsigned char *) &VersionInfo, sizeof(VersionInfo));
480
          GetVersionAnforderung = 0;
513
          GetVersionAnforderung = 0;
481
     }
514
     }
482
     if(GetPPMChannelAnforderung && UebertragungAbgeschlossen)
515
     if(GetPPMChannelAnforderung && UebertragungAbgeschlossen)
483
     {
516
     {
484
                 SendOutData('P',MeineSlaveAdresse, 1, (unsigned char *) &PPM_in, sizeof(PPM_in));
517
                 SendOutData('P', FC_ADDRESS, 1, (unsigned char *) &PPM_in, sizeof(PPM_in));
485
                 GetPPMChannelAnforderung = 0;
518
                 GetPPMChannelAnforderung = 0;
Line 486... Line 519...
486
         }
519
         }