Subversion Repositories MK3Mag

Rev

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

Rev 43 Rev 44
Line 97... Line 97...
97
uint8_t ConfirmFrame = 0;
97
uint8_t ConfirmFrame = 0;
Line 98... Line 98...
98
 
98
 
99
uint8_t PC_Connected = 0;
99
uint8_t PC_Connected = 0;
Line 100... Line -...
100
uint8_t FC_Connected = 0;
-
 
101
 
-
 
Line 102... Line 100...
102
uint8_t MySlaveAddr = MK3MAG_ADDRESS;
100
uint8_t FC_Connected = 0;
103
 
101
 
104
 
102
 
105
DebugOut_t              DebugOut;
103
DebugOut_t              DebugOut;
Line 224... Line 222...
224
        UART_VersionInfo.Major = VERSION_MAJOR;
222
        UART_VersionInfo.Major = VERSION_MAJOR;
225
        UART_VersionInfo.Minor = VERSION_MINOR;
223
        UART_VersionInfo.Minor = VERSION_MINOR;
226
        UART_VersionInfo.Patch = VERSION_PATCH;
224
        UART_VersionInfo.Patch = VERSION_PATCH;
227
        UART_VersionInfo.Compatible = VERSION_SERIAL_COMPATIBLE;
225
        UART_VersionInfo.Compatible = VERSION_SERIAL_COMPATIBLE;
Line 228... Line -...
228
 
-
 
229
        MySlaveAddr = MK3MAG_ADDRESS;
-
 
230
 
226
 
231
        // Version beim Start ausgeben (nicht schön, aber geht... )
227
        // Version beim Start ausgeben (nicht schön, aber geht... )
232
        USART0_putchar ('\n');
228
        USART0_putchar ('\n');
233
        USART0_putchar ('C');
229
        USART0_putchar ('C');
234
        USART0_putchar ('P');
230
        USART0_putchar ('P');
Line 498... Line 494...
498
void USART0_ProcessRxData(void)
494
void USART0_ProcessRxData(void)
499
{
495
{
500
        // if data in the rxd buffer are not locked immediately return
496
        // if data in the rxd buffer are not locked immediately return
501
        if(!rxd_buffer_locked) return;
497
        if(!rxd_buffer_locked) return;
Line 502... Line -...
502
 
-
 
503
        Decode64(); // decode data block in rxd_buffer
-
 
504
 
498
 
505
        switch(rxd_buffer[2])
499
        switch(rxd_buffer[1]) // check Slave Address
-
 
500
        {
-
 
501
                case MK3MAG_ADDRESS:
-
 
502
                Decode64(); // decode data block in rxd_buffer
-
 
503
                switch(rxd_buffer[2]) // check for CmdID
506
        {
504
                {
507
                case 'w': // old style
505
                        case 'w': // old style
508
                case 'k':// Attitude info from FC
506
                        case 'k': // Attitude info from FC
509
                        memcpy(&ExternData, (uint8_t*)pRxData, sizeof(ExternData));
507
                                memcpy(&ExternData, (uint8_t*)pRxData, sizeof(ExternData));
510
                        RequestFlags |= RQST_COMPASS_HEADING;
508
                                RequestFlags |= RQST_COMPASS_HEADING;
511
                        AttitudeSource = ATTITUDE_SOURCE_UART;
509
                                AttitudeSource = ATTITUDE_SOURCE_UART;
512
                        Orientation = ExternData.Orientation;
510
                                Orientation = ExternData.Orientation;
-
 
511
                                FC_Connected = 255;
-
 
512
                                break;
-
 
513
 
-
 
514
                        default:
513
                        FC_Connected = 255;
515
                                // unsupported command
-
 
516
                                break;
-
 
517
                }
514
                        break;
518
                break; // case MK3MAG_ADDRESS:
-
 
519
 
515
 
520
                default: // any Slave Adress
-
 
521
                Decode64(); // decode data block in rxd_buffer
-
 
522
                switch(rxd_buffer[2]) // check for CmdID
516
        // used only for debug proposes at serial port
523
                {
517
                case 'b': // extern control
524
                        case 'b': // extern control
518
                        memcpy(&ExternControl, (uint8_t*)pRxData, sizeof(ExternControl));
525
                                memcpy(&ExternControl, (uint8_t*)pRxData, sizeof(ExternControl));
519
                        #define KEY1    0x01
526
                                #define KEY1    0x01
520
                        #define KEY2    0x02
527
                                #define KEY2    0x02
521
                        #define KEY3    0x04
528
                                #define KEY3    0x04
522
                        #define KEY4    0x08
529
                                #define KEY4    0x08
523
                        #define KEY5    0x10
530
                                #define KEY5    0x10
524
                        // use right arrow at display for switching the calstate
531
                                // use right arrow at display for switching the calstate
525
                        if(ExternControl.RemoteButtons & KEY2)
532
                                if(ExternControl.RemoteButtons & KEY2)
526
                        {
533
                                {
527
                                ExternData.CalState++;
534
                                        ExternData.CalState++;
528
                                if(ExternData.CalState == 6) ExternData.CalState = 0;
535
                                        if(ExternData.CalState == 6) ExternData.CalState = 0;
529
                        }
536
                                }
530
                        ConfirmFrame = ExternControl.Frame;
537
                                ConfirmFrame = ExternControl.Frame;
531
                        PC_Connected = 255;
538
                                PC_Connected = 255;
532
                        break;
539
                                break;
533
 
540
 
534
                case 'd': // request for the debug data
541
                        case 'd': // request for the debug data
535
                        DebugData_Interval = (uint16_t) pRxData[0] * 10;
542
                                DebugData_Interval = (uint16_t) pRxData[0] * 10;
536
                        if(DebugData_Interval) RequestFlags |= RQST_DEBUG_DATA;
543
                                if(DebugData_Interval) RequestFlags |= RQST_DEBUG_DATA;
537
                        PC_Connected = 255;
544
                                PC_Connected = 255;
538
                        break;
545
                                break;
539
 
546
 
540
                case 'v': // request version and board release
547
                        case 'v': // request version and board release
541
                        RequestFlags |= RQST_VERSION_INFO;
548
                                RequestFlags |= RQST_VERSION_INFO;
542
                        PC_Connected = 255;
549
                                PC_Connected = 255;
543
                        break;
550
                                break;
544
 
551
 
545
                case 'a':// Labels of the Analog Debug outputs
552
                        case 'a':// Labels of the Analog Debug outputs
546
                        RequestDebugLabel = pRxData[0];
553
                                RequestDebugLabel = pRxData[0];
547
                        RequestFlags |= RQST_DEBUG_LABEL;
554
                                RequestFlags |= RQST_DEBUG_LABEL;
548
                        PC_Connected = 255;
555
                                PC_Connected = 255;
549
                        break;
556
                                break;
550
 
557
 
551
                case 'g':// get extern control data
558
                        case 'g':// get extern control data
552
                        RequestFlags |= RQST_EXTERN_CTRL;
559
                                RequestFlags |= RQST_EXTERN_CTRL;
-
 
560
                                PC_Connected = 255;
-
 
561
                                break;
-
 
562
 
-
 
563
                        default:
553
                        PC_Connected = 255;
564
                                // unsupported command
-
 
565
                                break;
-
 
566
                }
554
                        break;
567
                break; // default:
555
        }
568
        }
556
        // unlock the rxd buffer after processing
569
        // unlock the rxd buffer after processing
557
        pRxData = 0;
570
        pRxData = 0;
558
        RxDataLen = 0;
571
        RxDataLen = 0;
Line 568... Line 581...
568
 
581
 
Line 569... Line 582...
569
        if(!txd_complete) return;
582
        if(!txd_complete) return;
570
 
583
 
571
        if((RequestFlags & RQST_DEBUG_LABEL) && txd_complete)
584
        if((RequestFlags & RQST_DEBUG_LABEL) && txd_complete)
572
        {
585
        {
573
                SendOutData('A', MySlaveAddr, 2, (uint8_t *)&RequestDebugLabel, sizeof(RequestDebugLabel), (uint8_t *) ANALOG_LABEL[RequestDebugLabel], 16);
586
                SendOutData('A', MK3MAG_ADDRESS, 2, (uint8_t *)&RequestDebugLabel, sizeof(RequestDebugLabel), (uint8_t *) ANALOG_LABEL[RequestDebugLabel], 16);
574
                RequestDebugLabel = 0xFF;
587
                RequestDebugLabel = 0xFF;
Line 575... Line 588...
575
                RequestFlags &= ~RQST_DEBUG_LABEL;
588
                RequestFlags &= ~RQST_DEBUG_LABEL;
576
        }
589
        }
577
 
590
 
578
        if(ConfirmFrame && txd_complete)
591
        if(ConfirmFrame && txd_complete)
579
        {
592
        {
Line 580... Line 593...
580
                SendOutData('B',MySlaveAddr, 1, (uint8_t *) &ConfirmFrame, sizeof(ConfirmFrame));
593
                SendOutData('B', MK3MAG_ADDRESS, 1, (uint8_t *) &ConfirmFrame, sizeof(ConfirmFrame));
581
                ConfirmFrame = 0;
594
                ConfirmFrame = 0;
582
        }
595
        }
583
 
596
 
584
        if(( (DebugData_Interval && CheckDelay(DebugData_Timer)) || (RequestFlags & RQST_DEBUG_DATA)) && txd_complete)
597
        if(( (DebugData_Interval && CheckDelay(DebugData_Timer)) || (RequestFlags & RQST_DEBUG_DATA)) && txd_complete)
585
        {
598
        {
586
                SetDebugValues();
599
                SetDebugValues();
Line 587... Line 600...
587
                SendOutData('D', MySlaveAddr, 1, (uint8_t *) &DebugOut, sizeof(DebugOut));
600
                SendOutData('D', MK3MAG_ADDRESS, 1, (uint8_t *) &DebugOut, sizeof(DebugOut));
588
                DebugData_Timer = SetDelay(DebugData_Interval);
601
                DebugData_Timer = SetDelay(DebugData_Interval);
589
                RequestFlags &= ~RQST_DEBUG_DATA;
602
                RequestFlags &= ~RQST_DEBUG_DATA;
590
        }
603
        }
591
 
604
 
Line 592... Line 605...
592
 
605
 
593
        if((RequestFlags & RQST_EXTERN_CTRL) && txd_complete)
606
        if((RequestFlags & RQST_EXTERN_CTRL) && txd_complete)
594
        {
607
        {
595
                SendOutData('G',MySlaveAddr, 1, (uint8_t *) &ExternControl,sizeof(ExternControl));
608
                SendOutData('G', MK3MAG_ADDRESS, 1, (uint8_t *) &ExternControl,sizeof(ExternControl));
596
                RequestFlags &= ~RQST_EXTERN_CTRL;
609
                RequestFlags &= ~RQST_EXTERN_CTRL;
Line 597... Line 610...
597
        }
610
        }
598
 
611
 
599
        if((RequestFlags & RQST_COMPASS_HEADING) && txd_complete)
612
        if((RequestFlags & RQST_COMPASS_HEADING) && txd_complete)
600
        {
613
        {
601
                SendOutData('K',MySlaveAddr, 1, (uint8_t *) &I2C_Heading, sizeof(I2C_Heading));
614
                SendOutData('K', FC_ADDRESS, 1, (uint8_t *) &I2C_Heading, sizeof(I2C_Heading)); // send compass heading to FC
602
                RequestFlags &= ~RQST_COMPASS_HEADING;
615
                RequestFlags &= ~RQST_COMPASS_HEADING;