Subversion Repositories NaviCtrl

Rev

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

Rev 110 Rev 112
Line 72... Line 72...
72
#include "mkprotocol.h"
72
#include "mkprotocol.h"
Line 73... Line 73...
73
 
73
 
74
#define FALSE   0
74
#define FALSE   0
Line 75... Line -...
75
#define TRUE    1
-
 
76
 
-
 
77
typedef struct
-
 
78
{
-
 
79
        u8 SWMajor;
-
 
80
        u8 SWMinor;
-
 
81
        u8 ProtoMajor;
-
 
82
        u8 ProtoMinor;
-
 
83
        u8 SWPatch;
-
 
84
        u8 Reserved[5];
-
 
Line 85... Line 75...
85
}  __attribute__((packed)) UART_VersionInfo_t;
75
#define TRUE    1
86
 
76
 
87
 
77
 
88
u8 UART1_Request_VersionInfo    = FALSE;
78
u8 UART1_Request_VersionInfo    = FALSE;
Line 96... Line 86...
96
u8 UART1_Request_ErrorMessage   = FALSE;
86
u8 UART1_Request_ErrorMessage   = FALSE;
97
u8 UART1_Request_NewWaypoint    = FALSE;
87
u8 UART1_Request_NewWaypoint    = FALSE;
98
u8 UART1_Request_ReadWaypoint   = 255;
88
u8 UART1_Request_ReadWaypoint   = 255;
99
u8 UART1_Request_Data3D             = FALSE;
89
u8 UART1_Request_Data3D             = FALSE;
100
u8 UART1_Request_Echo               = FALSE;
90
u8 UART1_Request_Echo               = FALSE;
101
 
-
 
102
u8 DisplayLine = 0;
91
u8 UART1_DisplayLine                    = 0;
-
 
92
u8 UART1_ConfirmFrame                   = 0;
Line 103... Line 93...
103
 
93
 
Line 104... Line 94...
104
UART_TypeDef *DebugUART = UART1;
94
UART_TypeDef *DebugUART = UART1;
Line 117... Line 107...
117
 
107
 
Line 118... Line 108...
118
volatile u8 SerialLinkOkay = 0;
108
volatile u8 SerialLinkOkay = 0;
Line 119... Line -...
119
 
-
 
120
u8 text[100];
-
 
121
 
-
 
122
u8 PcAccess = 100;
-
 
123
u8 ConfirmFrame = 0;
-
 
124
 
-
 
125
DebugOut_t DebugOut;
-
 
126
ExternControl_t ExternControl;
-
 
127
UART_VersionInfo_t UART_VersionInfo;
-
 
128
NaviData_t NaviData;
-
 
129
Waypoint_t FollowMe;
-
 
130
Data3D_t Data3D;
-
 
131
u16 Echo; // 2 bytes recieved will be sent back as echo
-
 
132
 
-
 
133
u32 UART1_DebugData_Timer;
-
 
134
u32 UART1_DebugData_Interval = 5000;    // in ms
-
 
135
u32 UART1_NaviData_Timer;
-
 
136
u32 UART1_NaviData_Interval = 5000;     // in ms
-
 
137
u32 UART1_Data3D_Timer = 0;                     // in ms
109
 
138
u32 UART1_Data3D_Interval = 0;
110
u8 text[100];
139
 
111
 
140
const u8 ANALOG_LABEL[32][16] =
112
const u8 ANALOG_LABEL[32][16] =
141
{
113
{
Line 172... Line 144...
172
        "GPS_Nick        ",
144
        "GPS_Nick        ",
173
        "GPS_Roll        ", //30
145
        "GPS_Roll        ", //30
174
        "Used_Sats       "
146
        "Used_Sats       "
175
};
147
};
Line -... Line 148...
-
 
148
 
-
 
149
DebugOut_t DebugOut;
-
 
150
ExternControl_t ExternControl;
-
 
151
UART_VersionInfo_t UART_VersionInfo;
-
 
152
NaviData_t NaviData;
-
 
153
Waypoint_t FollowMe;
-
 
154
Data3D_t Data3D;
-
 
155
u16 Echo; // 2 bytes recieved will be sent back as echo
-
 
156
 
-
 
157
u32 UART1_DebugData_Timer;
-
 
158
u32 UART1_DebugData_Interval = 5000;    // in ms
-
 
159
u32 UART1_NaviData_Timer;
-
 
160
u32 UART1_NaviData_Interval = 5000;     // in ms
-
 
161
u32 UART1_Data3D_Timer = 0;                     // in ms
Line 176... Line 162...
176
 
162
u32 UART1_Data3D_Interval = 0;
177
 
163
 
178
/********************************************************/
164
/********************************************************/
179
/*            Initialization the UART1                  */
165
/*            Initialization the UART1                  */
Line 235... Line 221...
235
        // initialize the debug timer
221
        // initialize the debug timer
236
        UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
222
        UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
237
        UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500;
223
        UART1_NaviData_Timer = SetDelay(UART1_NaviData_Interval)+500;
Line 238... Line 224...
238
       
224
       
239
        // initialize txd buffer
-
 
240
        UART1_tx_buffer.pData = UART1_tbuffer;
225
        // initialize txd buffer
241
        UART1_tx_buffer.Size = UART1_TX_BUFFER_LEN;
-
 
242
        UART1_tx_buffer.Position = 0;
-
 
Line 243... Line 226...
243
        UART1_tx_buffer.Locked = FALSE;
226
        Buffer_Init(&UART1_tx_buffer, UART1_tbuffer, UART1_TX_BUFFER_LEN);
244
       
-
 
245
        // initialize rxd buffer
227
       
246
        UART1_rx_buffer.pData = UART1_rbuffer;
-
 
247
        UART1_rx_buffer.Size = UART1_RX_BUFFER_LEN;
-
 
Line 248... Line 228...
248
        UART1_rx_buffer.Position = 0;
228
        // initialize rxd buffer
249
        UART1_rx_buffer.Locked = FALSE;
229
        Buffer_Init(&UART1_rx_buffer, UART1_rbuffer, UART1_RX_BUFFER_LEN);
250
 
230
 
251
        // Fill Version Info Structure
231
        // Fill Version Info Structure
Line 331... Line 311...
331
        SerialMsg_t SerialMsg;
311
        SerialMsg_t SerialMsg;
332
        // if data in the rxd buffer are not locked immediately return
312
        // if data in the rxd buffer are not locked immediately return
333
        if((UART1_rx_buffer.Locked == FALSE) || (DebugUART != UART1) ) return;
313
        if((UART1_rx_buffer.Locked == FALSE) || (DebugUART != UART1) ) return;
334
        Waypoint_t * pWaypoint = NULL;
314
        Waypoint_t * pWaypoint = NULL;
Line 335... Line -...
335
 
-
 
336
        PcAccess = 255;
315
 
337
        MKProtocol_DecodeSerialFrame(&UART1_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
316
        MKProtocol_DecodeSerialFrame(&UART1_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
338
    if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250;      // reset SerialTimeout, but not in case of the "ping"
317
    if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250;      // reset SerialTimeout, but not in case of the "ping"
339
        switch(SerialMsg.Address) // check for Slave Address
318
        switch(SerialMsg.Address) // check for Slave Address
340
        {
319
        {
Line 419... Line 398...
419
                                if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31;
398
                                if(UART1_Request_DebugLabel > 31) UART1_Request_DebugLabel = 31;
420
                                break;
399
                                break;
Line 421... Line 400...
421
 
400
 
422
                        case 'b': // submit extern control
401
                        case 'b': // submit extern control
423
                                memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl));
402
                                memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl));
424
                                ConfirmFrame = ExternControl.Frame;
403
                                UART1_ConfirmFrame = ExternControl.Frame;
Line 425... Line 404...
425
                                break;
404
                                break;
426
 
405
 
427
                        case 'd': // request for debug data;
406
                        case 'd': // request for debug data;
Line 438... Line 417...
438
                                UART1_Request_ExternalControl = TRUE;
417
                                UART1_Request_ExternalControl = TRUE;
439
                                break;
418
                                break;
Line 440... Line 419...
440
 
419
 
441
                        case 'h':// reqest for display line
420
                        case 'h':// reqest for display line
442
                                RemoteKeys |= SerialMsg.pData[0];
421
                                RemoteKeys |= SerialMsg.pData[0];
443
                                if(RemoteKeys != 0) DisplayLine = 0;
422
                                if(RemoteKeys != 0) UART1_DisplayLine = 0;
444
                                UART1_Request_Display = TRUE;
423
                                UART1_Request_Display = TRUE;
Line 445... Line 424...
445
                                break;
424
                                break;
446
 
425
 
Line 461... Line 440...
461
                                // unsupported command recieved
440
                                // unsupported command recieved
462
                                break;
441
                                break;
463
                }
442
                }
464
                break; // default:
443
                break; // default:
465
        }
444
        }
466
        // unlock the rxd buffer after processing
-
 
467
        UART1_rx_buffer.Position = 0;
445
        Buffer_Clear(&UART1_rx_buffer);
468
        UART1_rx_buffer.Locked = FALSE;
-
 
469
}
446
}
Line 470... Line 447...
470
 
447
 
471
 
448
 
Line 506... Line 483...
506
        if((UART1_tx_buffer.Locked == TRUE) && (UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == RESET))
483
        if((UART1_tx_buffer.Locked == TRUE) && (UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == RESET))
507
        {
484
        {
508
                tmp_tx = UART1_tx_buffer.pData[UART1_tx_buffer.Position++]; // read next byte from txd buffer
485
                tmp_tx = UART1_tx_buffer.pData[UART1_tx_buffer.Position++]; // read next byte from txd buffer
509
                UART_SendData(UART1, tmp_tx); // put character to txd fifo
486
                UART_SendData(UART1, tmp_tx); // put character to txd fifo
510
                // if terminating character or end of txd buffer reached
487
                // if terminating character or end of txd buffer reached
511
                if((tmp_tx == '\r') || (UART1_tx_buffer.Position == UART1_tx_buffer.Size))
488
                if((tmp_tx == '\r') || (UART1_tx_buffer.Position == UART1_tx_buffer.DataBytes))
512
                {
489
                {
513
                        UART1_tx_buffer.Position = 0; // reset txd buffer positon
-
 
514
                        UART1_tx_buffer.Locked = FALSE;// unlock tx buffer
490
                        Buffer_Clear(&UART1_tx_buffer);
515
                }
491
                }
516
        }
492
        }
517
}
493
}
Line 535... Line 511...
535
        if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE))
511
        if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE))
536
        {
512
        {
537
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16);
513
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16);
538
                UART1_Request_DebugLabel = 0xFF;
514
                UART1_Request_DebugLabel = 0xFF;
539
        }
515
        }
540
        if(ConfirmFrame && (UART1_tx_buffer.Locked == FALSE))
516
        if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE))
541
        {
517
        {
542
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &ConfirmFrame, sizeof(ConfirmFrame));
518
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame));
543
                ConfirmFrame = 0;
519
                UART1_ConfirmFrame = 0;
544
        }
520
        }
545
        if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE))
521
        if( (( (UART1_DebugData_Interval > 0) && CheckDelay(UART1_DebugData_Timer)) || UART1_Request_DebugData) && (UART1_tx_buffer.Locked == FALSE))
546
        {
522
        {
547
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut));
523
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut));
548
                UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
524
                UART1_DebugData_Timer = SetDelay(UART1_DebugData_Interval);
Line 562... Line 538...
562
                UART1_Request_ExternalControl = FALSE;
538
                UART1_Request_ExternalControl = FALSE;
563
        }
539
        }
564
        if(UART1_Request_Display && (UART1_tx_buffer.Locked == FALSE))
540
        if(UART1_Request_Display && (UART1_tx_buffer.Locked == FALSE))
565
        {
541
        {
566
                LCD_PrintMenu();
542
                LCD_PrintMenu();
567
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), (u8*)&DisplayBuff[DisplayLine * 20], 20);
543
                MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'H', NC_ADDRESS, 2, &UART1_DisplayLine, sizeof(UART1_DisplayLine), (u8*)&DisplayBuff[UART1_DisplayLine * 20], 20);
568
                DisplayLine++;
544
                UART1_DisplayLine++;
569
                if(DisplayLine >= 4) DisplayLine = 0;
545
                if(UART1_DisplayLine >= 4) UART1_DisplayLine = 0;
570
                UART1_Request_Display = FALSE;
546
                UART1_Request_Display = FALSE;
571
        }
547
        }
572
        if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE))
548
        if(UART1_Request_Display1 && (UART1_tx_buffer.Locked == FALSE))
573
        {
549
        {
574
                LCD_PrintMenu();
550
                LCD_PrintMenu();