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