Rev 114 | Rev 136 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 114 | Rev 119 | ||
---|---|---|---|
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 |
6 | // + Nur für den privaten Gebrauch |
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 der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
28 | // + Die PORTIERUNG 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 this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed |
43 | // + * PORTING this software (or part of it) to systems (other than 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 "main.h" |
59 | #include "main.h" |
60 | #include "uart1.h" |
60 | #include "uart1.h" |
61 | #include "usb.h" |
61 | #include "usb.h" |
62 | #include "mkprotocol.h" |
62 | #include "mkprotocol.h" |
63 | #include "waypoints.h" |
63 | #include "waypoints.h" |
64 | #include "gps.h" |
64 | #include "gps.h" |
65 | #include "timer.h" |
65 | #include "timer1.h" |
66 | #include "uart0.h" |
66 | #include "uart0.h" |
67 | #include "uart1.h" |
67 | #include "uart1.h" |
68 | #include "uart2.h" |
68 | #include "uart2.h" |
69 | #include "menu.h" |
69 | #include "menu.h" |
70 | 70 | ||
71 | 71 | ||
72 | // the tx buffer |
72 | // the tx buffer |
73 | #define USB_TX_BUFFER_LEN 150 |
73 | #define USB_TX_BUFFER_LEN 150 |
74 | u8 USB_tbuffer[USB_TX_BUFFER_LEN]; |
74 | u8 USB_tbuffer[USB_TX_BUFFER_LEN]; |
75 | Buffer_t USB_tx_buffer; |
75 | Buffer_t USB_tx_buffer; |
76 | 76 | ||
77 | // the rx buffer |
77 | // the rx buffer |
78 | #define USB_RX_BUFFER_LEN 150 |
78 | #define USB_RX_BUFFER_LEN 150 |
79 | u8 USB_rbuffer[USB_RX_BUFFER_LEN]; |
79 | u8 USB_rbuffer[USB_RX_BUFFER_LEN]; |
80 | Buffer_t USB_rx_buffer; |
80 | Buffer_t USB_rx_buffer; |
81 | 81 | ||
82 | u8 USB_Request_VersionInfo = FALSE; |
82 | u8 USB_Request_VersionInfo = FALSE; |
83 | u8 USB_Request_SendFollowMe = FALSE; |
83 | u8 USB_Request_SendFollowMe = FALSE; |
84 | u8 USB_Request_ExternalControl= FALSE; |
84 | u8 USB_Request_ExternalControl= FALSE; |
85 | u8 USB_Request_Display = FALSE; |
85 | u8 USB_Request_Display = FALSE; |
86 | u8 USB_Request_Display1 = FALSE; |
86 | u8 USB_Request_Display1 = FALSE; |
87 | u8 USB_Request_DebugData = FALSE; |
87 | u8 USB_Request_DebugData = FALSE; |
88 | u8 USB_Request_DebugLabel = 255; |
88 | u8 USB_Request_DebugLabel = 255; |
89 | u8 USB_Request_NaviData = FALSE; |
89 | u8 USB_Request_NaviData = FALSE; |
90 | u8 USB_Request_ErrorMessage = FALSE; |
90 | u8 USB_Request_ErrorMessage = FALSE; |
91 | u8 USB_Request_NewWaypoint = FALSE; |
91 | u8 USB_Request_NewWaypoint = FALSE; |
92 | u8 USB_Request_ReadWaypoint = 255; |
92 | u8 USB_Request_ReadWaypoint = 255; |
93 | u8 USB_Request_Data3D = FALSE; |
93 | u8 USB_Request_Data3D = FALSE; |
94 | u8 USB_Request_Echo = FALSE; |
94 | u8 USB_Request_Echo = FALSE; |
95 | 95 | ||
96 | u8 USB_DisplayLine = 0; |
96 | u8 USB_DisplayLine = 0; |
97 | u8 USB_ConfirmFrame = 0; |
97 | u8 USB_ConfirmFrame = 0; |
98 | 98 | ||
99 | u32 USB_DebugData_Timer = 0; |
99 | u32 USB_DebugData_Timer = 0; |
100 | u32 USB_DebugData_Interval = 0; // in ms |
100 | u32 USB_DebugData_Interval = 0; // in ms |
101 | u32 USB_NaviData_Timer = 0; |
101 | u32 USB_NaviData_Timer = 0; |
102 | u32 USB_NaviData_Interval = 0; // in ms |
102 | u32 USB_NaviData_Interval = 0; // in ms |
103 | u32 USB_Data3D_Timer = 0; // in ms |
103 | u32 USB_Data3D_Timer = 0; // in ms |
104 | u32 USB_Data3D_Interval = 0; |
104 | u32 USB_Data3D_Interval = 0; |
105 | 105 | ||
106 | //----------------------------------------------------------------- |
106 | //----------------------------------------------------------------- |
107 | void USB_ConfigInit(void) |
107 | void USB_ConfigInit(void) |
108 | { |
108 | { |
109 | GPIO_InitTypeDef GPIO_InitStructure; |
109 | GPIO_InitTypeDef GPIO_InitStructure; |
110 | 110 | ||
111 | UART1_PutString("\r\n USB init..."); |
111 | UART1_PutString("\r\n USB init..."); |
112 | #ifdef MCLK96MHZ |
112 | #ifdef MCLK96MHZ |
113 | //USB clock = MCLK/2 = 48MHz |
113 | //USB clock = MCLK/2 = 48MHz |
114 | SCU_USBCLKConfig(SCU_USBCLK_MCLK2); |
114 | SCU_USBCLKConfig(SCU_USBCLK_MCLK2); |
115 | #else |
115 | #else |
116 | //USB clock = MCLK = 48MHz |
116 | //USB clock = MCLK = 48MHz |
117 | SCU_USBCLKConfig(SCU_USBCLK_MCLK); |
117 | SCU_USBCLKConfig(SCU_USBCLK_MCLK); |
118 | #endif |
118 | #endif |
119 | //Enable USB clock |
119 | //Enable USB clock |
120 | SCU_AHBPeriphClockConfig(__USB,ENABLE); |
120 | SCU_AHBPeriphClockConfig(__USB,ENABLE); |
121 | SCU_AHBPeriphReset(__USB,DISABLE); |
121 | SCU_AHBPeriphReset(__USB,DISABLE); |
122 | SCU_AHBPeriphClockConfig(__USB48M,ENABLE); |
122 | SCU_AHBPeriphClockConfig(__USB48M,ENABLE); |
123 | 123 | ||
124 | //Configure GPIO0 (D+ Pull-Up on P0.1) |
124 | //Configure GPIO0 (D+ Pull-Up on P0.1) |
125 | SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE); |
125 | SCU_APBPeriphClockConfig(__GPIO0 ,ENABLE); |
126 | SCU_APBPeriphReset(__GPIO0,DISABLE); |
126 | SCU_APBPeriphReset(__GPIO0,DISABLE); |
127 | 127 | ||
128 | // GPIO_DeInit(P0.1); |
128 | // GPIO_DeInit(P0.1); |
129 | GPIO_StructInit(&GPIO_InitStructure); |
129 | GPIO_StructInit(&GPIO_InitStructure); |
130 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
130 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
131 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
131 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; |
132 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
132 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
133 | GPIO_InitStructure.GPIO_IPConnected=GPIO_IPConnected_Enable; |
133 | GPIO_InitStructure.GPIO_IPConnected=GPIO_IPConnected_Enable; |
134 | GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1; |
134 | GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1; |
135 | GPIO_Init (GPIO0, &GPIO_InitStructure); |
135 | GPIO_Init (GPIO0, &GPIO_InitStructure); |
136 | 136 | ||
137 | // initialize txd buffer |
137 | // initialize txd buffer |
138 | Buffer_Init(&USB_tx_buffer, USB_tbuffer, USB_TX_BUFFER_LEN); |
138 | Buffer_Init(&USB_tx_buffer, USB_tbuffer, USB_TX_BUFFER_LEN); |
139 | 139 | ||
140 | // initialize rxd buffer |
140 | // initialize rxd buffer |
141 | Buffer_Init(&USB_rx_buffer, USB_rbuffer, USB_RX_BUFFER_LEN); |
141 | Buffer_Init(&USB_rx_buffer, USB_rbuffer, USB_RX_BUFFER_LEN); |
142 | 142 | ||
143 | PowerOff(); |
143 | PowerOff(); |
144 | Virtual_Com_Port_Reset(); |
144 | Virtual_Com_Port_Reset(); |
145 | 145 | ||
146 | VIC_Config(USBLP_ITLine, VIC_IRQ, 2); |
146 | VIC_Config(USBLP_ITLine, VIC_IRQ, 2); |
147 | VIC_ITCmd(USBLP_ITLine, ENABLE); |
147 | VIC_ITCmd(USBLP_ITLine, ENABLE); |
148 | 148 | ||
149 | USB_Init(); |
149 | USB_Init(); |
150 | 150 | ||
151 | UART1_PutString("ok"); |
151 | UART1_PutString("ok"); |
152 | } |
152 | } |
153 | 153 | ||
154 | 154 | ||
155 | /**************************************************************/ |
155 | /**************************************************************/ |
156 | /* Process incomming data from debug uart */ |
156 | /* Process incomming data from debug uart */ |
157 | /**************************************************************/ |
157 | /**************************************************************/ |
158 | void USB_ProcessRxData(void) |
158 | void USB_ProcessRxData(void) |
159 | { |
159 | { |
160 | SerialMsg_t SerialMsg; |
160 | SerialMsg_t SerialMsg; |
161 | Waypoint_t * pWaypoint = NULL; |
161 | Waypoint_t * pWaypoint = NULL; |
162 | // if data in the rxd buffer are not locked immediately return |
162 | // if data in the rxd buffer are not locked immediately return |
163 | if((USB_rx_buffer.Locked == FALSE) || (DebugUART != UART1) ) return; |
163 | if((USB_rx_buffer.Locked == FALSE) || (DebugUART != UART1) ) return; |
164 | 164 | ||
165 | MKProtocol_DecodeSerialFrame(&USB_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
165 | MKProtocol_DecodeSerialFrame(&USB_rx_buffer, &SerialMsg); // decode serial frame in rxd buffer |
166 | 166 | ||
167 | if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250; // reset SerialTimeout, but not in case of the "ping" |
167 | if(SerialMsg.CmdID != 'z') SerialLinkOkay = 250; // reset SerialTimeout, but not in case of the "ping" |
168 | switch(SerialMsg.Address) // check for Slave Address |
168 | switch(SerialMsg.Address) // check for Slave Address |
169 | { |
169 | { |
170 | case NC_ADDRESS: // own Slave Address |
170 | case NC_ADDRESS: // own Slave Address |
171 | switch(SerialMsg.CmdID) |
171 | switch(SerialMsg.CmdID) |
172 | { |
172 | { |
173 | case 'e': // request for the text of the error status |
173 | case 'e': // request for the text of the error status |
174 | USB_Request_ErrorMessage = TRUE; |
174 | USB_Request_ErrorMessage = TRUE; |
175 | break; |
175 | break; |
176 | 176 | ||
177 | case 's':// new target position |
177 | case 's':// new target position |
178 | pWaypoint = (Waypoint_t*)SerialMsg.pData; |
178 | pWaypoint = (Waypoint_t*)SerialMsg.pData; |
179 | BeepTime = 300; |
179 | BeepTime = 300; |
180 | if(pWaypoint->Position.Status == NEWDATA) |
180 | if(pWaypoint->Position.Status == NEWDATA) |
181 | { |
181 | { |
182 | WPList_Clear(); // empty WPList |
182 | WPList_Clear(); // empty WPList |
183 | WPList_Append(pWaypoint); |
183 | WPList_Append(pWaypoint); |
184 | GPS_pWaypoint = WPList_Begin(); |
184 | GPS_pWaypoint = WPList_Begin(); |
185 | } |
185 | } |
186 | break; |
186 | break; |
187 | /* |
187 | /* |
188 | case 'u': // redirect debug uart |
188 | case 'u': // redirect debug uart |
189 | switch(SerialMsg.pData[0]) |
189 | switch(SerialMsg.pData[0]) |
190 | { |
190 | { |
191 | case UART_FLIGHTCTRL: |
191 | case UART_FLIGHTCTRL: |
192 | UART2_Init(); // initialize UART2 to FC pins |
192 | UART2_Init(); // initialize UART2 to FC pins |
193 | DebugUART = UART2; |
193 | DebugUART = UART2; |
194 | break; |
194 | break; |
195 | case UART_MK3MAG: |
195 | case UART_MK3MAG: |
196 | if(FC.MKFlags & MKFLAG_MOTOR_RUN) break; // not if the motors are running |
196 | if(FC.MKFlags & MKFLAG_MOTOR_RUN) break; // not if the motors are running |
197 | UART0_Connect_to_MK3MAG(); // mux UART0 to MK3MAG pins |
197 | UART0_Connect_to_MK3MAG(); // mux UART0 to MK3MAG pins |
198 | GPSData.Status = INVALID; |
198 | GPSData.Status = INVALID; |
199 | DebugUART = UART0; |
199 | DebugUART = UART0; |
200 | break; |
200 | break; |
201 | case UART_MKGPS: |
201 | case UART_MKGPS: |
202 | if(FC.MKFlags & MKFLAG_MOTOR_RUN) break; // not if the motors are running |
202 | if(FC.MKFlags & MKFLAG_MOTOR_RUN) break; // not if the motors are running |
203 | UART0_Connect_to_MKGPS(); // connect UART0 to MKGPS pins |
203 | UART0_Connect_to_MKGPS(); // connect UART0 to MKGPS pins |
204 | GPSData.Status = INVALID; |
204 | GPSData.Status = INVALID; |
205 | DebugUART = UART0; |
205 | DebugUART = UART0; |
206 | break; |
206 | break; |
207 | } |
207 | } |
208 | break; |
208 | break; |
209 | */ |
209 | */ |
210 | case 'w':// Append Waypoint to List |
210 | case 'w':// Append Waypoint to List |
211 | pWaypoint = (Waypoint_t*)SerialMsg.pData; |
211 | pWaypoint = (Waypoint_t*)SerialMsg.pData; |
212 | if(pWaypoint->Position.Status == INVALID) |
212 | if(pWaypoint->Position.Status == INVALID) |
213 | { // clear WP List |
213 | { // clear WP List |
214 | WPList_Clear(); |
214 | WPList_Clear(); |
215 | GPS_pWaypoint = WPList_Begin(); |
215 | GPS_pWaypoint = WPList_Begin(); |
216 | //UART1_PutString("\r\nClear WP List\r\n"); |
216 | //UART1_PutString("\r\nClear WP List\r\n"); |
217 | } |
217 | } |
218 | else if (pWaypoint->Position.Status == NEWDATA) |
218 | else if (pWaypoint->Position.Status == NEWDATA) |
219 | { // app current WP to the list |
219 | { // app current WP to the list |
220 | WPList_Append(pWaypoint); |
220 | WPList_Append(pWaypoint); |
221 | BeepTime = 500; |
221 | BeepTime = 500; |
222 | //UART1_PutString("\r\nAdd WP to List\r\n"); |
222 | //UART1_PutString("\r\nAdd WP to List\r\n"); |
223 | } |
223 | } |
224 | USB_Request_NewWaypoint = TRUE; |
224 | USB_Request_NewWaypoint = TRUE; |
225 | break; |
225 | break; |
226 | 226 | ||
227 | case 'x':// Read Waypoint from List |
227 | case 'x':// Read Waypoint from List |
228 | USB_Request_ReadWaypoint = SerialMsg.pData[0]; |
228 | USB_Request_ReadWaypoint = SerialMsg.pData[0]; |
229 | break; |
229 | break; |
230 | 230 | ||
231 | default: |
231 | default: |
232 | // unsupported command recieved |
232 | // unsupported command recieved |
233 | break; |
233 | break; |
234 | } // case NC_ADDRESS |
234 | } // case NC_ADDRESS |
235 | // "break;" is missing here to fall thru to the common commands |
235 | // "break;" is missing here to fall thru to the common commands |
236 | 236 | ||
237 | default: // and any other Slave Address |
237 | default: // and any other Slave Address |
238 | 238 | ||
239 | switch(SerialMsg.CmdID) // check CmdID |
239 | switch(SerialMsg.CmdID) // check CmdID |
240 | { |
240 | { |
241 | case 'a':// request for the labels of the analog debug outputs |
241 | case 'a':// request for the labels of the analog debug outputs |
242 | USB_Request_DebugLabel = SerialMsg.pData[0]; |
242 | USB_Request_DebugLabel = SerialMsg.pData[0]; |
243 | if(USB_Request_DebugLabel > 31) USB_Request_DebugLabel = 31; |
243 | if(USB_Request_DebugLabel > 31) USB_Request_DebugLabel = 31; |
244 | break; |
244 | break; |
245 | 245 | ||
246 | case 'b': // submit extern control |
246 | case 'b': // submit extern control |
247 | memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl)); |
247 | memcpy(&ExternControl, SerialMsg.pData, sizeof(ExternControl)); |
248 | USB_ConfirmFrame = ExternControl.Frame; |
248 | USB_ConfirmFrame = ExternControl.Frame; |
249 | break; |
249 | break; |
250 | 250 | ||
251 | case 'd': // request for debug data; |
251 | case 'd': // request for debug data; |
252 | USB_DebugData_Interval = (u32) SerialMsg.pData[0] * 10; |
252 | USB_DebugData_Interval = (u32) SerialMsg.pData[0] * 10; |
253 | if(USB_DebugData_Interval > 0) USB_Request_DebugData = TRUE; |
253 | if(USB_DebugData_Interval > 0) USB_Request_DebugData = TRUE; |
254 | break; |
254 | break; |
255 | 255 | ||
256 | case 'c': // request for 3D data; |
256 | case 'c': // request for 3D data; |
257 | USB_Data3D_Interval = (u32) SerialMsg.pData[0] * 10; |
257 | USB_Data3D_Interval = (u32) SerialMsg.pData[0] * 10; |
258 | if(USB_Data3D_Interval > 0) USB_Request_Data3D = TRUE; |
258 | if(USB_Data3D_Interval > 0) USB_Request_Data3D = TRUE; |
259 | break; |
259 | break; |
260 | 260 | ||
261 | case 'g':// request for external control data |
261 | case 'g':// request for external control data |
262 | USB_Request_ExternalControl = TRUE; |
262 | USB_Request_ExternalControl = TRUE; |
263 | break; |
263 | break; |
264 | 264 | ||
265 | case 'h':// reqest for display line |
265 | case 'h':// reqest for display line |
266 | RemoteKeys |= SerialMsg.pData[0]; |
266 | RemoteKeys |= SerialMsg.pData[0]; |
267 | if(RemoteKeys != 0) USB_DisplayLine = 0; |
267 | if(RemoteKeys != 0) USB_DisplayLine = 0; |
268 | USB_Request_Display = TRUE; |
268 | USB_Request_Display = TRUE; |
269 | break; |
269 | break; |
270 | 270 | ||
271 | case 'l':// reqest for display columns |
271 | case 'l':// reqest for display columns |
272 | MenuItem = SerialMsg.pData[0]; |
272 | MenuItem = SerialMsg.pData[0]; |
273 | USB_Request_Display1 = TRUE; |
273 | USB_Request_Display1 = TRUE; |
274 | break; |
274 | break; |
275 | 275 | ||
276 | case 'o': // request for navigation information |
276 | case 'o': // request for navigation information |
277 | USB_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
277 | USB_NaviData_Interval = (u32) SerialMsg.pData[0] * 10; |
278 | if(USB_NaviData_Interval > 0) USB_Request_NaviData = TRUE; |
278 | if(USB_NaviData_Interval > 0) USB_Request_NaviData = TRUE; |
279 | break; |
279 | break; |
280 | 280 | ||
281 | case 'v': // request for version info |
281 | case 'v': // request for version info |
282 | USB_Request_VersionInfo = TRUE; |
282 | USB_Request_VersionInfo = TRUE; |
283 | break; |
283 | break; |
284 | default: |
284 | default: |
285 | // unsupported command recieved |
285 | // unsupported command recieved |
286 | break; |
286 | break; |
287 | } |
287 | } |
288 | break; // default: |
288 | break; // default: |
289 | } |
289 | } |
290 | Buffer_Clear(&USB_rx_buffer); |
290 | Buffer_Clear(&USB_rx_buffer); |
291 | } |
291 | } |
292 | 292 | ||
293 | 293 | ||
294 | //----------------------------------------------------------------- |
294 | //----------------------------------------------------------------- |
295 | void USB_CableConfig(FunctionalState NewState) |
295 | void USB_CableConfig(FunctionalState NewState) |
296 | { |
296 | { |
297 | if (NewState == ENABLE) |
297 | if (NewState == ENABLE) |
298 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET); |
298 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_RESET); |
299 | else |
299 | else |
300 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET); |
300 | GPIO_WriteBit(GPIO0, GPIO_Pin_1, Bit_SET); |
301 | } |
301 | } |
302 | 302 | ||
303 | //----------------------------------------------------------------- |
303 | //----------------------------------------------------------------- |
304 | void USB_PutString(u8 *string) |
304 | void USB_PutString(u8 *string) |
305 | { |
305 | { |
306 | u8 i = 0; |
306 | u8 i = 0; |
307 | u16 timeout = 0; |
307 | u16 timeout = 0; |
308 | 308 | ||
309 | while (string[i++] != 0){} // get string len |
309 | while (string[i++] != 0){} // get string len |
310 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
310 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
311 | UserToPMABufferCopy(string, ENDP1_TXADDR, ++i); // copy string to usb buffer |
311 | UserToPMABufferCopy(string, ENDP1_TXADDR, ++i); // copy string to usb buffer |
312 | SetEPTxCount(ENDP1,i); |
312 | SetEPTxCount(ENDP1,i); |
313 | SetEPTxValid(ENDP1); |
313 | SetEPTxValid(ENDP1); |
314 | } |
314 | } |
315 | 315 | ||
316 | //----------------------------------------------------------------- |
316 | //----------------------------------------------------------------- |
317 | void USB_PutChar(u8 c) |
317 | void USB_PutChar(u8 c) |
318 | { |
318 | { |
319 | u16 timeout = 0; |
319 | u16 timeout = 0; |
320 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
320 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
321 | UserToPMABufferCopy(&c, ENDP1_TXADDR, 2); |
321 | UserToPMABufferCopy(&c, ENDP1_TXADDR, 2); |
322 | SetEPTxCount(ENDP1,2); |
322 | SetEPTxCount(ENDP1,2); |
323 | SetEPTxValid(ENDP1); |
323 | SetEPTxValid(ENDP1); |
324 | } |
324 | } |
325 | 325 | ||
326 | //----------------------------------------------------------------- |
326 | //----------------------------------------------------------------- |
327 | void USB_SendData(u8 *pdata, u16 count) |
327 | void USB_SendData(u8 *pdata, u16 count) |
328 | { |
328 | { |
329 | u8 i; |
329 | u8 i; |
330 | count++; |
330 | count++; |
331 | u16 timeout = 0; |
331 | u16 timeout = 0; |
332 | 332 | ||
333 | for (i=0;i< (count/64)+1;i++) |
333 | for (i=0;i< (count/64)+1;i++) |
334 | { |
334 | { |
335 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){if (timeout++ > 60000) return;} |
335 | while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){if (timeout++ > 60000) return;} |
336 | if (i < (count/64)) |
336 | if (i < (count/64)) |
337 | { |
337 | { |
338 | UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, 64); |
338 | UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, 64); |
339 | SetEPTxCount(ENDP1,64); |
339 | SetEPTxCount(ENDP1,64); |
340 | } |
340 | } |
341 | else |
341 | else |
342 | { |
342 | { |
343 | UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, count % 64); |
343 | UserToPMABufferCopy(&pdata[i*64], ENDP1_TXADDR, count % 64); |
344 | SetEPTxCount(ENDP1, count % 64); |
344 | SetEPTxCount(ENDP1, count % 64); |
345 | } |
345 | } |
346 | SetEPTxValid(ENDP1); |
346 | SetEPTxValid(ENDP1); |
347 | } |
347 | } |
348 | } |
348 | } |
349 | 349 | ||
350 | /**************************************************************/ |
350 | /**************************************************************/ |
351 | /* Transmit tx buffer via usb */ |
351 | /* Transmit tx buffer via usb */ |
352 | /**************************************************************/ |
352 | /**************************************************************/ |
353 | void USB_Transmit(void) |
353 | void USB_Transmit(void) |
354 | { // nur blockweises kopieren des sendebuffers, nicht alles mit einem mal |
354 | { // nur blockweises kopieren des sendebuffers, nicht alles mit einem mal |
355 | // if something has to be send and the txd fifo is not full |
355 | // if something has to be send and the txd fifo is not full |
356 | u16 i; |
356 | u16 i; |
357 | if(USB_tx_buffer.Locked == TRUE) |
357 | if(USB_tx_buffer.Locked == TRUE) |
358 | { |
358 | { |
359 | if(_GetEPTxStatus(ENDP1) == EP_TX_NAK) |
359 | if(_GetEPTxStatus(ENDP1) == EP_TX_NAK) |
360 | //if(_GetEPTxStatus(ENDP1) != EP_TX_VALID) // ready to send |
360 | //if(_GetEPTxStatus(ENDP1) != EP_TX_VALID) // ready to send |
361 | { |
361 | { |
362 | if(USB_tx_buffer.Position < USB_tx_buffer.DataBytes) |
362 | if(USB_tx_buffer.Position < USB_tx_buffer.DataBytes) |
363 | { |
363 | { |
364 | i = USB_tx_buffer.DataBytes - USB_tx_buffer.Position; // bytes to send |
364 | i = USB_tx_buffer.DataBytes - USB_tx_buffer.Position; // bytes to send |
365 | if(i > 64) i = 64; // limit packet size to 64 bytes |
365 | if(i > 64) i = 64; // limit packet size to 64 bytes |
366 | UserToPMABufferCopy(&(USB_tx_buffer.pData[USB_tx_buffer.Position]), ENDP1_TXADDR, i); |
366 | UserToPMABufferCopy(&(USB_tx_buffer.pData[USB_tx_buffer.Position]), ENDP1_TXADDR, i); |
367 | SetEPTxCount(ENDP1,i); |
367 | SetEPTxCount(ENDP1,i); |
368 | SetEPTxValid(ENDP1); |
368 | SetEPTxValid(ENDP1); |
369 | USB_tx_buffer.Position += i; |
369 | USB_tx_buffer.Position += i; |
370 | } |
370 | } |
371 | } |
371 | } |
372 | if(USB_tx_buffer.Position >= USB_tx_buffer.DataBytes) // all bytes transfered |
372 | if(USB_tx_buffer.Position >= USB_tx_buffer.DataBytes) // all bytes transfered |
373 | { |
373 | { |
374 | Buffer_Clear(&USB_tx_buffer); // clear buffer |
374 | Buffer_Clear(&USB_tx_buffer); // clear buffer |
375 | } |
375 | } |
376 | } |
376 | } |
377 | } |
377 | } |
378 | 378 | ||
379 | /**************************************************************/ |
379 | /**************************************************************/ |
380 | /* Send the answers to incomming commands at the debug uart */ |
380 | /* Send the answers to incomming commands at the debug uart */ |
381 | /**************************************************************/ |
381 | /**************************************************************/ |
382 | void USB_TransmitTxData(void) |
382 | void USB_TransmitTxData(void) |
383 | { |
383 | { |
384 | USB_Transmit(); // output pending bytes in tx buffer |
384 | USB_Transmit(); // output pending bytes in tx buffer |
385 | if((USB_tx_buffer.Locked == TRUE)) return; |
385 | if((USB_tx_buffer.Locked == TRUE)) return; |
386 | 386 | ||
387 | if((USB_Request_DebugLabel != 0xFF) && (USB_tx_buffer.Locked == FALSE)) |
387 | if((USB_Request_DebugLabel != 0xFF) && (USB_tx_buffer.Locked == FALSE)) |
388 | { |
388 | { |
389 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'A', NC_ADDRESS, 2, &USB_Request_DebugLabel, sizeof(USB_Request_DebugLabel), (u8 *) ANALOG_LABEL[USB_Request_DebugLabel], 16); |
389 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'A', NC_ADDRESS, 2, &USB_Request_DebugLabel, sizeof(USB_Request_DebugLabel), (u8 *) ANALOG_LABEL[USB_Request_DebugLabel], 16); |
390 | USB_Request_DebugLabel = 0xFF; |
390 | USB_Request_DebugLabel = 0xFF; |
391 | } |
391 | } |
392 | if(USB_ConfirmFrame && (USB_tx_buffer.Locked == FALSE)) |
392 | if(USB_ConfirmFrame && (USB_tx_buffer.Locked == FALSE)) |
393 | { |
393 | { |
394 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'B', NC_ADDRESS, 1, &USB_ConfirmFrame, sizeof(USB_ConfirmFrame)); |
394 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'B', NC_ADDRESS, 1, &USB_ConfirmFrame, sizeof(USB_ConfirmFrame)); |
395 | USB_ConfirmFrame = 0; |
395 | USB_ConfirmFrame = 0; |
396 | } |
396 | } |
397 | if( (( (USB_DebugData_Interval > 0) && CheckDelay(USB_DebugData_Timer)) || USB_Request_DebugData) && (USB_tx_buffer.Locked == FALSE)) |
397 | if( (( (USB_DebugData_Interval > 0) && CheckDelay(USB_DebugData_Timer)) || USB_Request_DebugData) && (USB_tx_buffer.Locked == FALSE)) |
398 | { |
398 | { |
399 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut)); |
399 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut)); |
400 | USB_DebugData_Timer = SetDelay(USB_DebugData_Interval); |
400 | USB_DebugData_Timer = SetDelay(USB_DebugData_Interval); |
401 | USB_Request_DebugData = FALSE; |
401 | USB_Request_DebugData = FALSE; |
402 | } |
402 | } |
403 | 403 | ||
404 | if((( (USB_Data3D_Interval > 0) && CheckDelay(USB_Data3D_Timer) ) || USB_Request_Data3D) && (USB_tx_buffer.Locked == FALSE)) |
404 | if((( (USB_Data3D_Interval > 0) && CheckDelay(USB_Data3D_Timer) ) || USB_Request_Data3D) && (USB_tx_buffer.Locked == FALSE)) |
405 | { |
405 | { |
406 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D)); |
406 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D)); |
407 | USB_Data3D_Timer = SetDelay(USB_Data3D_Interval); |
407 | USB_Data3D_Timer = SetDelay(USB_Data3D_Interval); |
408 | USB_Request_Data3D = FALSE; |
408 | USB_Request_Data3D = FALSE; |
409 | } |
409 | } |
410 | 410 | ||
411 | if(USB_Request_ExternalControl && (USB_tx_buffer.Locked == FALSE)) |
411 | if(USB_Request_ExternalControl && (USB_tx_buffer.Locked == FALSE)) |
412 | { |
412 | { |
413 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl)); |
413 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl)); |
414 | USB_Request_ExternalControl = FALSE; |
414 | USB_Request_ExternalControl = FALSE; |
415 | } |
415 | } |
416 | if(USB_Request_Display && (USB_tx_buffer.Locked == FALSE)) |
416 | if(USB_Request_Display && (USB_tx_buffer.Locked == FALSE)) |
417 | { |
417 | { |
418 | LCD_PrintMenu(); |
418 | LCD_PrintMenu(); |
419 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'H', NC_ADDRESS, 2, &USB_DisplayLine, sizeof(USB_DisplayLine), (u8*)&DisplayBuff[USB_DisplayLine * 20], 20); |
419 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'H', NC_ADDRESS, 2, &USB_DisplayLine, sizeof(USB_DisplayLine), (u8*)&DisplayBuff[USB_DisplayLine * 20], 20); |
420 | USB_DisplayLine++; |
420 | USB_DisplayLine++; |
421 | if(USB_DisplayLine >= 4) USB_DisplayLine = 0; |
421 | if(USB_DisplayLine >= 4) USB_DisplayLine = 0; |
422 | USB_Request_Display = FALSE; |
422 | USB_Request_Display = FALSE; |
423 | } |
423 | } |
424 | if(USB_Request_Display1 && (USB_tx_buffer.Locked == FALSE)) |
424 | if(USB_Request_Display1 && (USB_tx_buffer.Locked == FALSE)) |
425 | { |
425 | { |
426 | LCD_PrintMenu(); |
426 | LCD_PrintMenu(); |
427 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff)); |
427 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff)); |
428 | USB_Request_Display1 = FALSE; |
428 | USB_Request_Display1 = FALSE; |
429 | } |
429 | } |
430 | if(USB_Request_VersionInfo && (USB_tx_buffer.Locked == FALSE)) |
430 | if(USB_Request_VersionInfo && (USB_tx_buffer.Locked == FALSE)) |
431 | { |
431 | { |
432 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo)); |
432 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo)); |
433 | USB_Request_VersionInfo = FALSE; |
433 | USB_Request_VersionInfo = FALSE; |
434 | } |
434 | } |
435 | if(( (USB_NaviData_Interval && CheckDelay(USB_NaviData_Timer) ) || USB_Request_NaviData) && (USB_tx_buffer.Locked == FALSE)) |
435 | if(( (USB_NaviData_Interval && CheckDelay(USB_NaviData_Timer) ) || USB_Request_NaviData) && (USB_tx_buffer.Locked == FALSE)) |
436 | { |
436 | { |
437 | NaviData.Errorcode = ErrorCode; |
437 | NaviData.Errorcode = ErrorCode; |
438 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData)); |
438 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData)); |
439 | USB_NaviData_Timer = SetDelay(USB_NaviData_Interval); |
439 | USB_NaviData_Timer = SetDelay(USB_NaviData_Interval); |
440 | USB_Request_NaviData = FALSE; |
440 | USB_Request_NaviData = FALSE; |
441 | } |
441 | } |
442 | if(USB_Request_ErrorMessage && (USB_tx_buffer.Locked == FALSE)) |
442 | if(USB_Request_ErrorMessage && (USB_tx_buffer.Locked == FALSE)) |
443 | { |
443 | { |
444 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG)); |
444 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG)); |
445 | USB_Request_ErrorMessage = FALSE; |
445 | USB_Request_ErrorMessage = FALSE; |
446 | } |
446 | } |
447 | if(USB_Request_NewWaypoint && (USB_tx_buffer.Locked == FALSE)) |
447 | if(USB_Request_NewWaypoint && (USB_tx_buffer.Locked == FALSE)) |
448 | { |
448 | { |
449 | u8 WPNumber = WPList_GetCount(); |
449 | u8 WPNumber = WPList_GetCount(); |
450 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'W', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber)); |
450 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'W', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber)); |
451 | USB_Request_NewWaypoint = FALSE; |
451 | USB_Request_NewWaypoint = FALSE; |
452 | } |
452 | } |
453 | if((USB_Request_ReadWaypoint != 0xFF) && (USB_tx_buffer.Locked == FALSE)) |
453 | if((USB_Request_ReadWaypoint != 0xFF) && (USB_tx_buffer.Locked == FALSE)) |
454 | { |
454 | { |
455 | u8 WPNumber = WPList_GetCount(); |
455 | u8 WPNumber = WPList_GetCount(); |
456 | if (USB_Request_ReadWaypoint < WPNumber) |
456 | if (USB_Request_ReadWaypoint < WPNumber) |
457 | { |
457 | { |
458 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'X', NC_ADDRESS, 3, &WPNumber, 1, &USB_Request_ReadWaypoint, 1, WPList_GetAt(USB_Request_ReadWaypoint), sizeof(Waypoint_t)); |
458 | MKProtocol_CreateSerialFrame(&USB_tx_buffer, 'X', NC_ADDRESS, 3, &WPNumber, 1, &USB_Request_ReadWaypoint, 1, WPList_GetAt(USB_Request_ReadWaypoint), sizeof(Waypoint_t)); |
459 | } |
459 | } |
460 | else |
460 | else |
461 | { |
461 | { |
462 | MKProtocol_CreateSerialFrame(&USB_tx_buffer,'X', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber)); |
462 | MKProtocol_CreateSerialFrame(&USB_tx_buffer,'X', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber)); |
463 | } |
463 | } |
464 | USB_Request_ReadWaypoint = 0xFF; |
464 | USB_Request_ReadWaypoint = 0xFF; |
465 | } |
465 | } |
466 | USB_Transmit(); // output pending bytes in tx buffer |
466 | USB_Transmit(); // output pending bytes in tx buffer |
467 | } |
467 | } |
468 | 468 |