Subversion Repositories NaviCtrl

Rev

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

Rev 199 Rev 201
1
/*#######################################################################################*/
1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 2008 Ingo Busker, Holger Buss
5
// + Copyright (c) 2008 Ingo Busker, Holger Buss
6
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
6
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
7
// + FOR NON COMMERCIAL USE ONLY
7
// + FOR NON COMMERCIAL USE ONLY
8
// + www.MikroKopter.com
8
// + www.MikroKopter.com
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), 
10
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), 
11
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. 
11
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. 
12
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt 
12
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt 
13
// + bzgl. der Nutzungsbedingungen aufzunehmen. 
13
// + bzgl. der Nutzungsbedingungen aufzunehmen. 
14
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
14
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
15
// + Verkauf von Luftbildaufnahmen, usw.
15
// + Verkauf von Luftbildaufnahmen, usw.
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, 
17
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, 
18
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
18
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
20
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
21
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
21
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
22
// + eindeutig als Ursprung verlinkt werden
22
// + eindeutig als Ursprung verlinkt werden
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
24
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
25
// + Benutzung auf eigene Gefahr
25
// + Benutzung auf eigene Gefahr
26
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
26
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur 
28
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur 
29
// + mit unserer Zustimmung zulässig
29
// + mit unserer Zustimmung zulässig
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
31
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
32
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, 
33
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, 
34
// + this list of conditions and the following disclaimer.
34
// + this list of conditions and the following disclaimer.
35
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
35
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
36
// +     from this software without specific prior written permission.
36
// +     from this software without specific prior written permission.
37
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted 
37
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted 
38
// +     for non-commercial use (directly or indirectly)
38
// +     for non-commercial use (directly or indirectly)
39
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
39
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
40
// +     with our written permission
40
// +     with our written permission
41
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be 
41
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be 
42
// +     clearly linked as origin 
42
// +     clearly linked as origin 
43
// +   * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
43
// +   * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
44
//
44
//
45
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
45
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
46
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
48
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
49
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
50
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
50
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
51
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
52
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
53
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
54
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
55
// +  POSSIBILITY OF SUCH DAMAGE. 
55
// +  POSSIBILITY OF SUCH DAMAGE. 
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57
#include <string.h>
57
#include <string.h>
58
#include "91x_lib.h"
58
#include "91x_lib.h"
59
#include "config.h"
59
#include "config.h"
60
#include "main.h"
60
#include "main.h"
61
#include "uart1.h"
61
#include "uart1.h"
62
#include "usb.h"
62
#include "usb.h"
63
#include "mkprotocol.h"
63
#include "mkprotocol.h"
64
#include "waypoints.h"
64
#include "waypoints.h"
65
#include "gps.h"
65
#include "gps.h"
66
#include "timer1.h"
66
#include "timer1.h"
67
#include "uart0.h"
67
#include "uart0.h"
68
#include "uart1.h"
68
#include "uart1.h"
69
#include "uart2.h"
69
#include "uart2.h"
70
#include "menu.h"
70
#include "menu.h"
-
 
71
 
-
 
72
#define ABO_TIMEOUT 4000 // disable abo after 4 seconds
71
 
73
u32 USB_AboTimeOut = 0;
72
 
74
 
73
// the tx buffer
75
// the tx buffer
74
#define USB_TX_BUFFER_LEN  150
76
#define USB_TX_BUFFER_LEN  150
75
u8 USB_tbuffer[USB_TX_BUFFER_LEN];
77
u8 USB_tbuffer[USB_TX_BUFFER_LEN];
76
Buffer_t USB_tx_buffer;
78
Buffer_t USB_tx_buffer;
77
 
79
 
78
// the rx buffer
80
// the rx buffer
79
#define USB_RX_BUFFER_LEN  150
81
#define USB_RX_BUFFER_LEN  150
80
u8 USB_rbuffer[USB_RX_BUFFER_LEN];
82
u8 USB_rbuffer[USB_RX_BUFFER_LEN];
81
Buffer_t USB_rx_buffer;
83
Buffer_t USB_rx_buffer;
82
 
84
 
83
u8 USB_Request_VersionInfo      = FALSE;
85
u8 USB_Request_VersionInfo      = FALSE;
84
u8 USB_Request_SendFollowMe     = FALSE;
86
u8 USB_Request_SendFollowMe     = FALSE;
85
u8 USB_Request_ExternalControl= FALSE;
87
u8 USB_Request_ExternalControl= FALSE;
86
u8 USB_Request_Display          = FALSE;
88
u8 USB_Request_Display          = FALSE;
87
u8 USB_Request_Display1         = FALSE;
89
u8 USB_Request_Display1         = FALSE;
88
u8 USB_Request_DebugData        = FALSE;
90
u8 USB_Request_DebugData        = FALSE;
89
u8 USB_Request_DebugLabel       = 255;
91
u8 USB_Request_DebugLabel       = 255;
90
u8 USB_Request_NaviData         = FALSE;
92
u8 USB_Request_NaviData         = FALSE;
91
u8 USB_Request_ErrorMessage     = FALSE;
93
u8 USB_Request_ErrorMessage     = FALSE;
92
u8 USB_Request_NewWaypoint      = FALSE;
94
u8 USB_Request_NewWaypoint      = FALSE;
93
u8 USB_Request_ReadWaypoint     = 255;
95
u8 USB_Request_ReadWaypoint     = 255;
94
u8 USB_Request_Data3D           = FALSE;
96
u8 USB_Request_Data3D           = FALSE;
95
u8 USB_Request_Echo                 = FALSE;
97
u8 USB_Request_Echo                 = FALSE;
96
 
98
 
97
u8 USB_DisplayLine = 0;
99
u8 USB_DisplayKeys = 0;
98
u8 USB_ConfirmFrame = 0;
100
u8 USB_ConfirmFrame = 0;
99
 
101
 
100
u32 USB_DebugData_Timer = 0;
102
u32 USB_DebugData_Timer = 0;
101
u32 USB_DebugData_Interval = 0; // in ms
103
u32 USB_DebugData_Interval = 0; // in ms
102
u32 USB_NaviData_Timer = 0;
104
u32 USB_NaviData_Timer = 0;
103
u32 USB_NaviData_Interval = 0;  // in ms
105
u32 USB_NaviData_Interval = 0;  // in ms
104
u32 USB_Data3D_Timer = 0;               // in ms
106
u32 USB_Data3D_Timer = 0;              
105
u32 USB_Data3D_Interval = 0;
107
u32 USB_Data3D_Interval = 0;    // in ms
-
 
108
u32 USB_Display_Timer = 0;
-
 
109
u32 USB_Display_Interval = 0;   // in ms
106
 
110
 
107
//-----------------------------------------------------------------
111
//-----------------------------------------------------------------
108
void USB_ConfigInit(void)
112
void USB_ConfigInit(void)
109
{
113
{
110
        GPIO_InitTypeDef GPIO_InitStructure;
114
        GPIO_InitTypeDef GPIO_InitStructure;
111
 
115
 
112
        UART1_PutString("\r\n USB init...");
116
        UART1_PutString("\r\n USB init...");
113
        #ifdef MCLK96MHZ
117
        #ifdef MCLK96MHZ
114
        //USB clock = MCLK/2 = 48MHz
118
        //USB clock = MCLK/2 = 48MHz
115
        SCU_USBCLKConfig(SCU_USBCLK_MCLK2);
119
        SCU_USBCLKConfig(SCU_USBCLK_MCLK2);
116
        #else
120
        #else
117
        //USB clock = MCLK = 48MHz
121
        //USB clock = MCLK = 48MHz
118
        SCU_USBCLKConfig(SCU_USBCLK_MCLK);
122
        SCU_USBCLKConfig(SCU_USBCLK_MCLK);
119
        #endif
123
        #endif
120
        //Enable USB clock
124
        //Enable USB clock
121
        SCU_AHBPeriphClockConfig(__USB,ENABLE);
125
        SCU_AHBPeriphClockConfig(__USB,ENABLE);
122
        SCU_AHBPeriphReset(__USB,DISABLE);
126
        SCU_AHBPeriphReset(__USB,DISABLE);
123
        SCU_AHBPeriphClockConfig(__USB48M,ENABLE);
127
        SCU_AHBPeriphClockConfig(__USB48M,ENABLE);
124
 
128
 
125
        //Configure GPIO0 (D+ Pull-Up on P0.1)
129
        //Configure GPIO0 (D+ Pull-Up on P0.1)
126
        SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE);
130
        SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE);
127
        SCU_APBPeriphReset(__GPIO0,DISABLE);
131
        SCU_APBPeriphReset(__GPIO0,DISABLE);
128
 
132
 
129
        // GPIO_DeInit(P0.1);
133
        // GPIO_DeInit(P0.1);
130
        GPIO_StructInit(&GPIO_InitStructure);
134
        GPIO_StructInit(&GPIO_InitStructure);
131
        GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
135
        GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
132
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
136
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
133
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
137
        GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ;
134
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
138
        GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
135
        GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1;
139
        GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1;
136
        GPIO_Init (GPIO0, &GPIO_InitStructure);
140
        GPIO_Init (GPIO0, &GPIO_InitStructure);
137
 
141
 
138
        // initialize txd buffer
142
        // initialize txd buffer
139
        Buffer_Init(&USB_tx_buffer, USB_tbuffer, USB_TX_BUFFER_LEN);
143
        Buffer_Init(&USB_tx_buffer, USB_tbuffer, USB_TX_BUFFER_LEN);
140
       
144
       
141
        // initialize rxd buffer
145
        // initialize rxd buffer
142
        Buffer_Init(&USB_rx_buffer, USB_rbuffer, USB_RX_BUFFER_LEN);
146
        Buffer_Init(&USB_rx_buffer, USB_rbuffer, USB_RX_BUFFER_LEN);
143
 
147
 
144
        PowerOff();
148
        PowerOff();
145
        Virtual_Com_Port_Reset();
149
        Virtual_Com_Port_Reset();
146
 
150
 
147
        VIC_Config(USBLP_ITLine, VIC_IRQ, PRIORITY_USB);
151
        VIC_Config(USBLP_ITLine, VIC_IRQ, PRIORITY_USB);
148
        VIC_ITCmd(USBLP_ITLine, ENABLE);
152
        VIC_ITCmd(USBLP_ITLine, ENABLE);
149
 
153
 
150
        USB_Init();
154
        USB_Init();
151
 
155
 
152
        UART1_PutString("ok");  
156
        UART1_PutString("ok");  
153
}
157
}
154
 
158
 
155
 
159
 
156
/**************************************************************/
160
/**************************************************************/
157
/* Process incomming data from debug uart                     */
161
/* Process incomming data from debug uart                     */
158
/**************************************************************/
162
/**************************************************************/
159
void USB_ProcessRxData(void)
163
void USB_ProcessRxData(void)
160
{
164
{
161
        SerialMsg_t SerialMsg;
165
        SerialMsg_t SerialMsg;
162
        Waypoint_t * pWaypoint = NULL;
166
        Waypoint_t * pWaypoint = NULL;
163
        // if data in the rxd buffer are not locked immediately return
167
        // if data in the rxd buffer are not locked immediately return
164
        if((USB_rx_buffer.Locked == FALSE) || (DebugUART != UART1) ) return;
168
        if((USB_rx_buffer.Locked == FALSE) || (DebugUART != UART1) ) return;
165
 
169
 
166
        MKProtocol_DecodeSerialFrameHeader(&USB_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
170
        MKProtocol_DecodeSerialFrameHeader(&USB_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
167
        MKProtocol_DecodeSerialFrameData(&USB_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
171
        MKProtocol_DecodeSerialFrameData(&USB_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer
168
 
172
 
169
    if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250;      // reset SerialTimeout, but not in case of the "ping"
173
    if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250;      // reset SerialTimeout, but not in case of the "ping"
170
        switch(SerialMsg.Address) // check for Slave Address
174
        switch(SerialMsg.Address) // check for Slave Address
171
        {
175
        {
172
                case NC_ADDRESS:  // own Slave Address
176
                case NC_ADDRESS:  // own Slave Address
173
                switch(SerialMsg.CmdID)
177
                switch(SerialMsg.CmdID)
174
                {
178
                {
175
                        case 'e': // request for the text of the error status
179
                        case 'e': // request for the text of the error status
176
                                USB_Request_ErrorMessage = TRUE;
180
                                USB_Request_ErrorMessage = TRUE;
177
                                break;
181
                                break;
178
 
182
 
179
                        case 's'://  new target position
183
                        case 's'://  new target position
180
                                pWaypoint = (Waypoint_t*)SerialMsg.pData;
184
                                pWaypoint = (Waypoint_t*)SerialMsg.pData;
181
                                BeepTime = 300;
185
                                BeepTime = 300;
182
                                if(pWaypoint->Position.Status == NEWDATA)
186
                                if(pWaypoint->Position.Status == NEWDATA)
183
                                {
187
                                {
184
                                        WPList_Clear(); // empty WPList
188
                                        WPList_Clear(); // empty WPList
185
                                        WPList_Append(pWaypoint);
189
                                        WPList_Append(pWaypoint);
186
                                        GPS_pWaypoint = WPList_Begin();
190
                                        GPS_pWaypoint = WPList_Begin();
187
                                }
191
                                }
188
                                break;
192
                                break;
189
                   /*
193
                   /*
190
                        case 'u': // redirect debug uart
194
                        case 'u': // redirect debug uart
191
                                switch(SerialMsg.pData[0])
195
                                switch(SerialMsg.pData[0])
192
                                {
196
                                {
193
                                        case UART_FLIGHTCTRL:
197
                                        case UART_FLIGHTCTRL:
194
                                                UART2_Init();                           // initialize UART2 to FC pins
198
                                                UART2_Init();                           // initialize UART2 to FC pins
195
                                                DebugUART = UART2;
199
                                                DebugUART = UART2;
196
                                                break;
200
                                                break;
197
                                        case UART_MK3MAG:
201
                                        case UART_MK3MAG:
198
                                                if(FC.Flags & FCFLAG_MOTOR_RUN) break; // not if the motors are running
202
                                                if(FC.Flags & FCFLAG_MOTOR_RUN) break; // not if the motors are running
199
                                                UART0_Connect_to_MK3MAG();      // mux UART0 to MK3MAG pins
203
                                                UART0_Connect_to_MK3MAG();      // mux UART0 to MK3MAG pins
200
                                                GPSData.Status = INVALID;
204
                                                GPSData.Status = INVALID;
201
                                                DebugUART = UART0;
205
                                                DebugUART = UART0;
202
                                                break;
206
                                                break;
203
                                        case UART_MKGPS:
207
                                        case UART_MKGPS:
204
                                                if(FC.Flags & FCFLAG_MOTOR_RUN) break; // not if the motors are running
208
                                                if(FC.Flags & FCFLAG_MOTOR_RUN) break; // not if the motors are running
205
                                                UART0_Connect_to_MKGPS();       // connect UART0 to MKGPS pins
209
                                                UART0_Connect_to_MKGPS();       // connect UART0 to MKGPS pins
206
                                                GPSData.Status = INVALID;
210
                                                GPSData.Status = INVALID;
207
                                                DebugUART = UART0;
211
                                                DebugUART = UART0;
208
                                                break;
212
                                                break;
209
                                }
213
                                }
210
                                break;
214
                                break;
211
                         */
215
                         */
212
                        case 'w'://  Append Waypoint to List
216
                        case 'w'://  Append Waypoint to List
213
                                pWaypoint = (Waypoint_t*)SerialMsg.pData;
217
                                pWaypoint = (Waypoint_t*)SerialMsg.pData;
214
                                if(pWaypoint->Position.Status == INVALID)
218
                                if(pWaypoint->Position.Status == INVALID)
215
                                {  // clear WP List
219
                                {  // clear WP List
216
                                        WPList_Clear();
220
                                        WPList_Clear();
217
                                        GPS_pWaypoint = WPList_Begin();
221
                                        GPS_pWaypoint = WPList_Begin();
218
                                        //UART1_PutString("\r\nClear WP List\r\n");
222
                                        //UART1_PutString("\r\nClear WP List\r\n");
219
                                }
223
                                }
220
                                else if (pWaypoint->Position.Status == NEWDATA)
224
                                else if (pWaypoint->Position.Status == NEWDATA)
221
                                {  // app current WP to the list
225
                                {  // app current WP to the list
222
                                        WPList_Append(pWaypoint);
226
                                        WPList_Append(pWaypoint);
223
                                        BeepTime = 500;
227
                                        BeepTime = 500;
224
                                        //UART1_PutString("\r\nAdd WP to List\r\n");
228
                                        //UART1_PutString("\r\nAdd WP to List\r\n");
225
                                }
229
                                }
226
                                USB_Request_NewWaypoint = TRUE;
230
                                USB_Request_NewWaypoint = TRUE;
227
                                break;
231
                                break;
228
 
232
 
229
                        case 'x'://  Read Waypoint from List
233
                        case 'x'://  Read Waypoint from List
230
                                USB_Request_ReadWaypoint = SerialMsg.pData[0];
234
                                USB_Request_ReadWaypoint = SerialMsg.pData[0];
231
                                break;
235
                                break;
232
 
236
 
233
                        default:
237
                        default:
234
                                // unsupported command recieved
238
                                // unsupported command recieved
235
                                break;
239
                                break;
236
                } // case NC_ADDRESS
240
                } // case NC_ADDRESS
237
                // "break;" is missing here to fall thru to the common commands
241
                // "break;" is missing here to fall thru to the common commands
238
 
242
 
239
                default:  // and any other Slave Address
243
                default:  // and any other Slave Address
240
 
244
 
241
                switch(SerialMsg.CmdID) // check CmdID
245
                switch(SerialMsg.CmdID) // check CmdID
242
                {
246
                {
243
                        case 'a':// request for the labels of the analog debug outputs
247
                        case 'a':// request for the labels of the analog debug outputs
244
                                USB_Request_DebugLabel = SerialMsg.pData[0];
248
                                USB_Request_DebugLabel = SerialMsg.pData[0];
245
                                if(USB_Request_DebugLabel > 31) USB_Request_DebugLabel = 31;
249
                                if(USB_Request_DebugLabel > 31) USB_Request_DebugLabel = 31;
246
                                break;
250
                                break;
247
 
251
                        /*
248
                        case 'b': // submit extern control
252
                        case 'b': // submit extern control
249
                                memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl));
253
                                memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl));
250
                                USB_ConfirmFrame = ExternControl.Frame;
254
                                USB_ConfirmFrame = ExternControl.Frame;
251
                                break;
255
                                break;
252
 
256
                        */
253
                        case 'd': // request for debug data;
257
                        case 'd': // request for debug data;
254
                                USB_DebugData_Interval = (u32) SerialMsg.pData[0] * 10;
258
                                USB_DebugData_Interval = (u32) SerialMsg.pData[0] * 10;
-
 
259
                                USB_AboTimeOut = SetDelay(ABO_TIMEOUT);
255
                                if(USB_DebugData_Interval > 0) USB_Request_DebugData = TRUE;
260
                                if(USB_DebugData_Interval > 0) USB_Request_DebugData = TRUE;
256
                                break;
261
                                break;
257
 
262
 
258
                        case 'c': // request for 3D data;
263
                        case 'c': // request for 3D data;
259
                                USB_Data3D_Interval = (u32) SerialMsg.pData[0] * 10;
264
                                USB_Data3D_Interval = (u32) SerialMsg.pData[0] * 10;
-
 
265
                                USB_AboTimeOut = SetDelay(ABO_TIMEOUT);
260
                                if(USB_Data3D_Interval > 0) USB_Request_Data3D = TRUE;
266
                                if(USB_Data3D_Interval > 0) USB_Request_Data3D = TRUE;
261
                                break;
267
                                break;
262
 
268
                        /*
263
                        case 'g':// request for external control data
269
                        case 'g':// request for external control data
264
                                USB_Request_ExternalControl = TRUE;
270
                                USB_Request_ExternalControl = TRUE;
265
                                break;
271
                                break;
266
 
272
                        */
267
                        case 'h':// reqest for display line
273
                        case 'h':// reqest for display line
268
                                RemoteKeys |= SerialMsg.pData[0];
274
                                USB_DisplayKeys |= ~SerialMsg.pData[0];
269
                                if(RemoteKeys != 0) USB_DisplayLine = 0;
275
                                USB_Display_Interval = (u32) SerialMsg.pData[1] * 10;
-
 
276
                                USB_AboTimeOut = SetDelay(ABO_TIMEOUT);
270
                                USB_Request_Display = TRUE;
277
                                USB_Request_Display = TRUE;
271
                                break;
278
                                break;
272
 
279
 
273
                        case 'l':// reqest for display columns
280
                        case 'l':// reqest for display columns
274
                                MenuItem = SerialMsg.pData[0];
281
                                MenuItem = SerialMsg.pData[0];
275
                                USB_Request_Display1 = TRUE;
282
                                USB_Request_Display1 = TRUE;
276
                                break;
283
                                break;
277
 
284
 
278
                        case 'o': // request for navigation information
285
                        case 'o': // request for navigation information
279
                                USB_NaviData_Interval = (u32) SerialMsg.pData[0] * 10;
286
                                USB_NaviData_Interval = (u32) SerialMsg.pData[0] * 10;
-
 
287
                                USB_AboTimeOut = SetDelay(ABO_TIMEOUT);
280
                                if(USB_NaviData_Interval > 0) USB_Request_NaviData = TRUE;
288
                                if(USB_NaviData_Interval > 0) USB_Request_NaviData = TRUE;
281
                                break;
289
                                break;
282
 
290
 
283
                        case 'v': // request for version info
291
                        case 'v': // request for version info
284
                                USB_Request_VersionInfo = TRUE;
292
                                USB_Request_VersionInfo = TRUE;
285
                                break;
293
                                break;
286
                        default:
294
                        default:
287
                                // unsupported command recieved
295
                                // unsupported command recieved
288
                                break;
296
                                break;
289
                }
297
                }
290
                break; // default:
298
                break; // default:
291
        }
299
        }
292
        Buffer_Clear(&USB_rx_buffer);
300
        Buffer_Clear(&USB_rx_buffer);
293
}
301
}
294
 
302
 
295
 
303
 
296
//-----------------------------------------------------------------
304
//-----------------------------------------------------------------
297
void USB_CableConfig(FunctionalState NewState)
305
void USB_CableConfig(FunctionalState NewState)
298
{
306
{
299
        if (NewState == ENABLE)
307
        if (NewState == ENABLE)
300
        GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET);
308
        GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET);
301
        else
309
        else
302
        GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET);
310
        GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET);
303
}
311
}
304
 
312
 
305
//-----------------------------------------------------------------
313
//-----------------------------------------------------------------
306
void USB_PutString(u8 *string)
314
void USB_PutString(u8 *string)
307
{
315
{
308
        u8 i = 0;
316
        u8 i = 0;
309
        u16 timeout = 0;
317
        u16 timeout = 0;
310
       
318
       
311
        while (string[i++] != 0){} // get string len
319
        while (string[i++] != 0){} // get string len
312
        while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;}
320
        while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;}
313
        UserToPMABufferCopy(string, ENDP1_TXADDR, ++i); // copy string to usb buffer
321
        UserToPMABufferCopy(string, ENDP1_TXADDR, ++i); // copy string to usb buffer
314
        SetEPTxCount(ENDP1,i);
322
        SetEPTxCount(ENDP1,i);
315
        SetEPTxValid(ENDP1);
323
        SetEPTxValid(ENDP1);
316
}
324
}
317
 
325
 
318
//-----------------------------------------------------------------
326
//-----------------------------------------------------------------
319
void USB_PutChar(u8 c)
327
void USB_PutChar(u8 c)
320
{
328
{
321
        u16 timeout = 0;
329
        u16 timeout = 0;
322
        while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;}
330
        while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;}
323
        UserToPMABufferCopy(&c, ENDP1_TXADDR, 2);
331
        UserToPMABufferCopy(&c, ENDP1_TXADDR, 2);
324
        SetEPTxCount(ENDP1,2);
332
        SetEPTxCount(ENDP1,2);
325
        SetEPTxValid(ENDP1);
333
        SetEPTxValid(ENDP1);
326
}
334
}
327
 
335
 
328
//-----------------------------------------------------------------
336
//-----------------------------------------------------------------
329
void USB_SendData(u8 *pdata, u16 count)
337
void USB_SendData(u8 *pdata, u16 count)
330
{
338
{
331
        u8 i;
339
        u8 i;
332
        count++;
340
        count++;
333
        u16 timeout = 0;
341
        u16 timeout = 0;
334
       
342
       
335
        for (i=0;i< (count/64)+1;i++)  
343
        for (i=0;i< (count/64)+1;i++)  
336
        {
344
        {
337
                while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){if (timeout++ > 60000) return;}             
345
                while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){if (timeout++ > 60000) return;}             
338
                if (i < (count/64))
346
                if (i < (count/64))
339
                {
347
                {
340
                        UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, 64);
348
                        UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, 64);
341
                        SetEPTxCount(ENDP1,64);
349
                        SetEPTxCount(ENDP1,64);
342
                }
350
                }
343
                else
351
                else
344
                {
352
                {
345
                        UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, count % 64);
353
                        UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, count % 64);
346
                        SetEPTxCount(ENDP1, count % 64);
354
                        SetEPTxCount(ENDP1, count % 64);
347
                }
355
                }
348
                SetEPTxValid(ENDP1);
356
                SetEPTxValid(ENDP1);
349
        }
357
        }
350
}
358
}
351
 
359
 
352
/**************************************************************/
360
/**************************************************************/
353
/*         Transmit tx buffer via usb                         */
361
/*         Transmit tx buffer via usb                         */
354
/**************************************************************/
362
/**************************************************************/
355
void USB_Transmit(void)
363
void USB_Transmit(void)
356
{   // nur blockweises kopieren des sendebuffers, nicht alles mit einem mal
364
{   // nur blockweises kopieren des sendebuffers, nicht alles mit einem mal
357
        // if something has to be send and the txd fifo is not full
365
        // if something has to be send and the txd fifo is not full
358
        u16 i;
366
        u16 i;
359
        if(USB_tx_buffer.Locked == TRUE)
367
        if(USB_tx_buffer.Locked == TRUE)
360
        {
368
        {
361
                if(_GetEPTxStatus(ENDP1) == EP_TX_NAK)
369
                if(_GetEPTxStatus(ENDP1) == EP_TX_NAK)
362
                //if(_GetEPTxStatus(ENDP1) != EP_TX_VALID) // ready to send
370
                //if(_GetEPTxStatus(ENDP1) != EP_TX_VALID) // ready to send
363
                {
371
                {
364
                        if(USB_tx_buffer.Position < USB_tx_buffer.DataBytes)
372
                        if(USB_tx_buffer.Position < USB_tx_buffer.DataBytes)
365
                        {
373
                        {
366
                                i = USB_tx_buffer.DataBytes - USB_tx_buffer.Position; // bytes to send
374
                                i = USB_tx_buffer.DataBytes - USB_tx_buffer.Position; // bytes to send
367
                                if(i > 64) i = 64; // limit packet size to 64 bytes
375
                                if(i > 64) i = 64; // limit packet size to 64 bytes
368
                                UserToPMABufferCopy(&(USB_tx_buffer.pData[USB_tx_buffer.Position]), ENDP1_TXADDR, i);
376
                                UserToPMABufferCopy(&(USB_tx_buffer.pData[USB_tx_buffer.Position]), ENDP1_TXADDR, i);
369
                                SetEPTxCount(ENDP1,i);
377
                                SetEPTxCount(ENDP1,i);
370
                                SetEPTxValid(ENDP1);   
378
                                SetEPTxValid(ENDP1);   
371
                        USB_tx_buffer.Position += i;
379
                        USB_tx_buffer.Position += i;
372
                        }
380
                        }
373
                }
381
                }
374
                if(USB_tx_buffer.Position >= USB_tx_buffer.DataBytes) // all bytes transfered
382
                if(USB_tx_buffer.Position >= USB_tx_buffer.DataBytes) // all bytes transfered
375
                {
383
                {
376
                        Buffer_Clear(&USB_tx_buffer); // clear buffer
384
                        Buffer_Clear(&USB_tx_buffer); // clear buffer
377
                }
385
                }
378
        }
386
        }
379
}
387
}
380
 
388
 
381
/**************************************************************/
389
/**************************************************************/
382
/* Send the answers to incomming commands at the debug uart   */
390
/* Send the answers to incomming commands at the debug uart   */
383
/**************************************************************/
391
/**************************************************************/
384
void USB_TransmitTxData(void)
392
void USB_TransmitTxData(void)
385
{
393
{
386
        USB_Transmit(); // output pending bytes in tx buffer
394
        USB_Transmit(); // output pending bytes in tx buffer
387
        if((USB_tx_buffer.Locked == TRUE)) return;
395
        if((USB_tx_buffer.Locked == TRUE)) return;
-
 
396
 
-
 
397
        if(CheckDelay(USB_AboTimeOut))
-
 
398
        {
-
 
399
                USB_DebugData_Interval = 0;
-
 
400
                USB_NaviData_Interval = 0;
-
 
401
                USB_Data3D_Interval = 0;
-
 
402
                USB_Display_Interval = 0;
-
 
403
        }
388
 
404
 
389
        if((USB_Request_DebugLabel != 0xFF) && (USB_tx_buffer.Locked == FALSE))
405
        if((USB_Request_DebugLabel != 0xFF) && (USB_tx_buffer.Locked == FALSE))
390
        {
406
        {
391
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'A', NC_ADDRESS, 2, &USB_Request_DebugLabel, sizeof(USB_Request_DebugLabel), (u8 *) ANALOG_LABEL[USB_Request_DebugLabel], 16);
407
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'A', NC_ADDRESS, 2, &USB_Request_DebugLabel, sizeof(USB_Request_DebugLabel), (u8 *) ANALOG_LABEL[USB_Request_DebugLabel], 16);
392
                USB_Request_DebugLabel = 0xFF;
408
                USB_Request_DebugLabel = 0xFF;
393
        }
409
        }
394
        if(USB_ConfirmFrame && (USB_tx_buffer.Locked == FALSE))
410
        else if(USB_ConfirmFrame && (USB_tx_buffer.Locked == FALSE))
395
        {
411
        {
396
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'B', NC_ADDRESS, 1, &USB_ConfirmFrame, sizeof(USB_ConfirmFrame));
412
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'B', NC_ADDRESS, 1, &USB_ConfirmFrame, sizeof(USB_ConfirmFrame));
397
                USB_ConfirmFrame = 0;
413
                USB_ConfirmFrame = 0;
398
        }
414
        }
399
        if( (( (USB_DebugData_Interval > 0) && CheckDelay(USB_DebugData_Timer)) || USB_Request_DebugData) && (USB_tx_buffer.Locked == FALSE))
415
        else if( (( (USB_DebugData_Interval > 0) && CheckDelay(USB_DebugData_Timer)) || USB_Request_DebugData) && (USB_tx_buffer.Locked == FALSE))
400
        {
416
        {
401
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut));
417
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut));
402
                USB_DebugData_Timer = SetDelay(USB_DebugData_Interval);
418
                USB_DebugData_Timer = SetDelay(USB_DebugData_Interval);
403
                USB_Request_DebugData = FALSE;
419
                USB_Request_DebugData = FALSE;
404
        }
420
        }
405
 
-
 
406
        if((( (USB_Data3D_Interval > 0) && CheckDelay(USB_Data3D_Timer) ) || USB_Request_Data3D) && (USB_tx_buffer.Locked == FALSE))
421
        else if((( (USB_Data3D_Interval > 0) && CheckDelay(USB_Data3D_Timer) ) || USB_Request_Data3D) && (USB_tx_buffer.Locked == FALSE))
407
        {
422
        {
408
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D));
423
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D));
409
                USB_Data3D_Timer = SetDelay(USB_Data3D_Interval);
424
                USB_Data3D_Timer = SetDelay(USB_Data3D_Interval);
410
                USB_Request_Data3D = FALSE;
425
                USB_Request_Data3D = FALSE;
411
        }
426
        }
412
 
-
 
413
        if(USB_Request_ExternalControl && (USB_tx_buffer.Locked == FALSE))
427
        else if(USB_Request_ExternalControl && (USB_tx_buffer.Locked == FALSE))
414
        {
428
        {
415
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl));
429
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl));
416
                USB_Request_ExternalControl = FALSE;
430
                USB_Request_ExternalControl = FALSE;
417
        }
431
        }
418
        if(USB_Request_Display && (USB_tx_buffer.Locked == FALSE))
432
        else if( (( (USB_Display_Interval > 0) && CheckDelay(USB_Display_Timer)) || USB_Request_Display) && (USB_tx_buffer.Locked == FALSE))
419
        {
433
        {
420
                LCD_PrintMenu();
434
                Menu_Update(USB_DisplayKeys);
421
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'H', NC_ADDRESS, 2, &USB_DisplayLine, sizeof(USB_DisplayLine), (u8*)&DisplayBuff[USB_DisplayLine * 20], 20);
-
 
422
                USB_DisplayLine++;
435
                USB_DisplayKeys = 0;
423
                if(USB_DisplayLine >= 4) USB_DisplayLine = 0;
436
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'H', NC_ADDRESS, 1, (u8*)DisplayBuff, sizeof(DisplayBuff));
424
                USB_Request_Display = FALSE;
437
                USB_Request_Display = FALSE;
425
        }
438
        }
426
        if(USB_Request_Display1 && (USB_tx_buffer.Locked == FALSE))
439
        else if(USB_Request_Display1 && (USB_tx_buffer.Locked == FALSE))
427
        {
440
        {
428
                LCD_PrintMenu();
441
                Menu_Update(0);
429
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff));
442
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff));
430
                USB_Request_Display1 = FALSE;
443
                USB_Request_Display1 = FALSE;
431
        }
444
        }
432
        if(USB_Request_VersionInfo && (USB_tx_buffer.Locked == FALSE))
445
        else if(USB_Request_VersionInfo && (USB_tx_buffer.Locked == FALSE))
433
        {
446
        {
434
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo));
447
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo));
435
                USB_Request_VersionInfo = FALSE;
448
                USB_Request_VersionInfo = FALSE;
436
        }
449
        }
437
        if(( (USB_NaviData_Interval && CheckDelay(USB_NaviData_Timer) ) || USB_Request_NaviData) && (USB_tx_buffer.Locked == FALSE))
450
        else if(( (USB_NaviData_Interval && CheckDelay(USB_NaviData_Timer) ) || USB_Request_NaviData) && (USB_tx_buffer.Locked == FALSE))
438
        {
451
        {
439
                NaviData.Errorcode = ErrorCode;
452
                NaviData.Errorcode = ErrorCode;
440
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData));
453
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData));
441
                USB_NaviData_Timer = SetDelay(USB_NaviData_Interval);
454
                USB_NaviData_Timer = SetDelay(USB_NaviData_Interval);
442
                USB_Request_NaviData = FALSE;
455
                USB_Request_NaviData = FALSE;
443
        }
456
        }
444
        if(USB_Request_ErrorMessage && (USB_tx_buffer.Locked == FALSE))
457
        else if(USB_Request_ErrorMessage && (USB_tx_buffer.Locked == FALSE))
445
        {
458
        {
446
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG));
459
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG));
447
                USB_Request_ErrorMessage = FALSE;
460
                USB_Request_ErrorMessage = FALSE;
448
        }
461
        }
449
        if(USB_Request_NewWaypoint && (USB_tx_buffer.Locked == FALSE))
462
        else if(USB_Request_NewWaypoint && (USB_tx_buffer.Locked == FALSE))
450
        {
463
        {
451
                u8 WPNumber = WPList_GetCount();
464
                u8 WPNumber = WPList_GetCount();
452
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'W', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber));
465
                MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'W', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber));
453
                USB_Request_NewWaypoint = FALSE;
466
                USB_Request_NewWaypoint = FALSE;
454
        }
467
        }
455
        if((USB_Request_ReadWaypoint != 0xFF) && (USB_tx_buffer.Locked == FALSE))
468
        else if((USB_Request_ReadWaypoint != 0xFF) && (USB_tx_buffer.Locked == FALSE))
456
        {
469
        {
457
                u8 WPNumber = WPList_GetCount();
470
                u8 WPNumber = WPList_GetCount();
458
                if (USB_Request_ReadWaypoint < WPNumber)
471
                if (USB_Request_ReadWaypoint < WPNumber)
459
                {
472
                {
460
                        MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'X', NC_ADDRESS, 3, &WPNumber, 1, &USB_Request_ReadWaypoint, 1, WPList_GetAt(USB_Request_ReadWaypoint), sizeof(Waypoint_t));
473
                        MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'X', NC_ADDRESS, 3, &WPNumber, 1, &USB_Request_ReadWaypoint, 1, WPList_GetAt(USB_Request_ReadWaypoint), sizeof(Waypoint_t));
461
                }
474
                }
462
                else
475
                else
463
                {
476
                {
464
                        MKProtocol_CreateSerialFrame(&USB_tx_buffer,'X', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber));
477
                        MKProtocol_CreateSerialFrame(&USB_tx_buffer,'X', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber));
465
                }
478
                }
466
                USB_Request_ReadWaypoint = 0xFF;
479
                USB_Request_ReadWaypoint = 0xFF;
467
        }
480
        }
468
        USB_Transmit(); // output pending bytes in tx buffer
481
        USB_Transmit(); // output pending bytes in tx buffer
469
}
482
}
470
 
483