Rev 91 | Rev 95 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 91 | Rev 92 | ||
---|---|---|---|
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 <stdio.h> |
57 | #include <stdio.h> |
58 | #include <stdarg.h> |
58 | #include <stdarg.h> |
59 | #include <string.h> |
59 | #include <string.h> |
60 | 60 | ||
61 | #include "91x_lib.h" |
61 | #include "91x_lib.h" |
62 | #include "ramfunc.h" |
62 | #include "ramfunc.h" |
63 | #include "menu.h" |
63 | #include "menu.h" |
64 | #include "printf_P.h" |
64 | #include "printf_P.h" |
65 | #include "GPS.h" |
65 | #include "GPS.h" |
66 | #include "i2c.h" |
66 | #include "i2c.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 "timer.h" |
70 | #include "timer.h" |
71 | #include "usb.h" |
71 | #include "usb.h" |
72 | #include "main.h" |
72 | #include "main.h" |
73 | #include "waypoints.h" |
73 | #include "waypoints.h" |
74 | #include "GPS.h" |
74 | #include "GPS.h" |
75 | 75 | ||
76 | // slave addresses |
76 | // slave addresses |
77 | #define FC_ADDRESS 1 |
77 | #define FC_ADDRESS 1 |
78 | #define NC_ADDRESS 2 |
78 | #define NC_ADDRESS 2 |
79 | #define MK3MAG_ADDRESS 3 |
79 | #define MK3MAG_ADDRESS 3 |
80 | 80 | ||
81 | #define FALSE 0 |
81 | #define FALSE 0 |
82 | #define TRUE 1 |
82 | #define TRUE 1 |
- | 83 | ||
- | 84 | typedef struct |
|
- | 85 | { |
|
- | 86 | u8 SWMajor; |
|
- | 87 | u8 SWMinor; |
|
- | 88 | u8 ProtoMajor; |
|
- | 89 | u8 ProtoMinor; |
|
- | 90 | u8 SWPatch; |
|
- | 91 | u8 Reserved[5]; |
|
- | 92 | } __attribute__((packed)) UART_VersionInfo_t; |
|
- | 93 | ||
83 | 94 | ||
84 | u8 Request_SendFollowMe = FALSE; |
95 | u8 Request_SendFollowMe = FALSE; |
85 | u8 Request_VerInfo = FALSE; |
96 | u8 Request_VerInfo = FALSE; |
86 | u8 Request_ExternalControl = FALSE; |
97 | u8 Request_ExternalControl = FALSE; |
87 | u8 Request_Display = FALSE; |
98 | u8 Request_Display = FALSE; |
88 | u8 Request_Display1 = FALSE; |
99 | u8 Request_Display1 = FALSE; |
89 | u8 Request_DebugData = FALSE; |
100 | u8 Request_DebugData = FALSE; |
90 | u8 Request_DebugLabel = 255; |
101 | u8 Request_DebugLabel = 255; |
91 | u8 Request_ChannelOnly = FALSE; |
102 | u8 Request_ChannelOnly = FALSE; |
92 | u8 Request_NaviData = FALSE; |
103 | u8 Request_NaviData = FALSE; |
93 | u8 Request_ErrorMessage = FALSE; |
104 | u8 Request_ErrorMessage = FALSE; |
94 | u8 Request_NewWaypoint = FALSE; |
105 | u8 Request_NewWaypoint = FALSE; |
- | 106 | u8 Request_ReadWaypoint = 255; |
|
95 | u8 Request_Data3D = FALSE; |
107 | u8 Request_Data3D = FALSE; |
- | 108 | u8 Request_Echo = FALSE; |
|
96 | 109 | ||
97 | u8 DisplayLine = 0; |
110 | u8 DisplayLine = 0; |
98 | 111 | ||
99 | UART_TypeDef *DebugUART = UART1; |
112 | UART_TypeDef *DebugUART = UART1; |
100 | 113 | ||
101 | volatile u8 txd_buffer[TXD_BUFFER_LEN]; |
114 | volatile u8 txd_buffer[TXD_BUFFER_LEN]; |
102 | volatile u8 rxd_buffer_locked = FALSE; |
115 | volatile u8 rxd_buffer_locked = FALSE; |
103 | volatile u8 rxd_buffer[RXD_BUFFER_LEN]; |
116 | volatile u8 rxd_buffer[RXD_BUFFER_LEN]; |
104 | volatile u8 txd_complete = TRUE; |
117 | volatile u8 txd_complete = TRUE; |
105 | volatile u8 ReceivedBytes = 0; |
118 | volatile u8 ReceivedBytes = 0; |
106 | volatile u8 CntCrcError = 0; |
119 | volatile u8 CntCrcError = 0; |
107 | volatile u8 *pRxData = NULL; |
120 | volatile u8 *pRxData = NULL; |
108 | volatile u8 RxDataLen = 0; |
121 | volatile u8 RxDataLen = 0; |
109 | volatile u8 SerialDataOkay = 0; |
122 | volatile u8 SerialLinkOkay = 0; |
110 | 123 | ||
111 | u8 text[100]; |
124 | u8 text[100]; |
112 | 125 | ||
113 | u8 PcAccess = 100; |
126 | u8 PcAccess = 100; |
114 | u8 MotorTest[4] = {0,0,0,0}; |
127 | u8 MotorTest[4] = {0,0,0,0}; |
115 | u8 ConfirmFrame = 0; |
128 | u8 ConfirmFrame = 0; |
116 | 129 | ||
117 | DebugOut_t DebugOut; |
130 | DebugOut_t DebugOut; |
118 | ExternControl_t ExternControl; |
131 | ExternControl_t ExternControl; |
119 | UART_VersionInfo_t UART_VersionInfo; |
132 | UART_VersionInfo_t UART_VersionInfo; |
120 | NaviData_t NaviData; |
133 | NaviData_t NaviData; |
121 | Waypoint_t FollowMe; |
134 | Waypoint_t FollowMe; |
122 | Data3D_t Data3D; |
135 | Data3D_t Data3D; |
- | 136 | u16 Echo; // 2 bytes recieved will be sent back as echo |
|
123 | 137 | ||
124 | u32 DebugData_Timer; |
138 | u32 DebugData_Timer; |
125 | u32 DebugData_Interval = 5000; // in ms |
139 | u32 DebugData_Interval = 5000; // in ms |
126 | u32 NaviData_Timer; |
140 | u32 NaviData_Timer; |
127 | u32 NaviData_Interval = 5000; // in ms |
141 | u32 NaviData_Interval = 5000; // in ms |
128 | u32 Data3D_Timer = 0; // in ms |
142 | u32 Data3D_Timer = 0; // in ms |
129 | u32 Data3D_Interval = 0; |
143 | u32 Data3D_Interval = 0; |
130 | 144 | ||
131 | static u16 ptr_txd_buffer = 0; |
145 | static u16 ptr_txd_buffer = 0; |
132 | 146 | ||
133 | const u8 ANALOG_LABEL[32][16] = |
147 | const u8 ANALOG_LABEL[32][16] = |
134 | { |
148 | { |
135 | //1234567890123456 |
149 | //1234567890123456 |
136 | "AngleNick ", //0 |
150 | "AngleNick ", //0 |
137 | "AngleRoll ", |
151 | "AngleRoll ", |
138 | "AccNick ", |
152 | "AccNick ", |
139 | "AccRoll ", |
153 | "AccRoll ", |
140 | " ", |
154 | " ", |
141 | "MK-Flags ", //5 |
155 | "MK-Flags ", //5 |
142 | " ", |
156 | " ", |
143 | " ", |
157 | " ", |
144 | " ", |
158 | " ", |
145 | "GPS Data ", |
159 | "GPS Data ", |
146 | "CompassHeading ", //10 |
160 | "CompassHeading ", //10 |
147 | "GyroHeading ", |
161 | "GyroHeading ", |
148 | "SPI Error ", |
162 | "SPI Error ", |
149 | "SPI Okay ", |
163 | "SPI Okay ", |
150 | "I2C Error ", |
164 | "I2C Error ", |
151 | "I2C Okay ", //15 |
165 | "I2C Okay ", //15 |
152 | " ",// "FC_Kalman_K ", |
166 | " ",// "FC_Kalman_K ", |
153 | "ACC_Speed_N ", |
167 | "ACC_Speed_N ", |
154 | "ACC_Speed_E ", |
168 | "ACC_Speed_E ", |
155 | " ",// "GPS ACC ", |
169 | " ",// "GPS ACC ", |
156 | " ",// "MAXDrift ", //20 |
170 | " ",// "MAXDrift ", //20 |
157 | "N_Speed ", |
171 | "N_Speed ", |
158 | "E_Speed ", |
172 | "E_Speed ", |
159 | " ",// "KalmDist_N ", |
173 | " ",// "KalmDist_N ", |
160 | " ",// "KalmDist_E ", |
174 | " ",// "KalmDist_E ", |
161 | " ",//25 |
175 | " ",//25 |
162 | "SD-Logs ", |
176 | "SD-Logs ", |
163 | "Distance N ", |
177 | "Distance N ", |
164 | "Distance E ", |
178 | "Distance E ", |
165 | "GPS_Nick ", |
179 | "GPS_Nick ", |
166 | "GPS_Roll ", //30 |
180 | "GPS_Roll ", //30 |
167 | "Used_Sats " |
181 | "Used_Sats " |
168 | }; |
182 | }; |
169 | 183 | ||
170 | 184 | ||
171 | /********************************************************/ |
185 | /********************************************************/ |
172 | /* Initialization the UART1 */ |
186 | /* Initialization the UART1 */ |
173 | /********************************************************/ |
187 | /********************************************************/ |
174 | void UART1_Init (void) |
188 | void UART1_Init (void) |
175 | { |
189 | { |
176 | GPIO_InitTypeDef GPIO_InitStructure; |
190 | GPIO_InitTypeDef GPIO_InitStructure; |
177 | UART_InitTypeDef UART_InitStructure; |
191 | UART_InitTypeDef UART_InitStructure; |
178 | 192 | ||
179 | SCU_APBPeriphClockConfig(__UART1, ENABLE); // Enable the UART1 Clock |
193 | SCU_APBPeriphClockConfig(__UART1, ENABLE); // Enable the UART1 Clock |
180 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); // Enable the GPIO3 Clock |
194 | SCU_APBPeriphClockConfig(__GPIO3, ENABLE); // Enable the GPIO3 Clock |
181 | 195 | ||
182 | /*Configure UART1_Rx pin GPIO3.2*/ |
196 | /*Configure UART1_Rx pin GPIO3.2*/ |
183 | GPIO_StructInit(&GPIO_InitStructure); |
197 | GPIO_StructInit(&GPIO_InitStructure); |
184 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
198 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
185 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
199 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
186 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
200 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
187 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
201 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
188 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; // UART1_RxD |
202 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; // UART1_RxD |
189 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
203 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
190 | 204 | ||
191 | /*Configure UART1_Tx pin GPIO3.3*/ |
205 | /*Configure UART1_Tx pin GPIO3.3*/ |
192 | GPIO_StructInit(&GPIO_InitStructure); |
206 | GPIO_StructInit(&GPIO_InitStructure); |
193 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
207 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
194 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; |
208 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; |
195 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
209 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
196 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; // UART1_TX |
210 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; // UART1_TX |
197 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
211 | GPIO_Init(GPIO3, &GPIO_InitStructure); |
198 | 212 | ||
199 | /* UART1 configured as follow: |
213 | /* UART1 configured as follow: |
200 | - Word Length = 8 Bits |
214 | - Word Length = 8 Bits |
201 | - One Stop Bit |
215 | - One Stop Bit |
202 | - No parity |
216 | - No parity |
203 | - BaudRate = 57600 baud |
217 | - BaudRate = 57600 baud |
204 | - Hardware flow control Disabled |
218 | - Hardware flow control Disabled |
205 | - Receive and transmit enabled |
219 | - Receive and transmit enabled |
206 | - Receive and transmit FIFOs are Disabled |
220 | - Receive and transmit FIFOs are Disabled |
207 | */ |
221 | */ |
208 | UART_StructInit(&UART_InitStructure); |
222 | UART_StructInit(&UART_InitStructure); |
209 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
223 | UART_InitStructure.UART_WordLength = UART_WordLength_8D; |
210 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
224 | UART_InitStructure.UART_StopBits = UART_StopBits_1; |
211 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
225 | UART_InitStructure.UART_Parity = UART_Parity_No ; |
212 | UART_InitStructure.UART_BaudRate = BAUD_RATE; |
226 | UART_InitStructure.UART_BaudRate = BAUD_RATE; |
213 | UART_InitStructure. UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
227 | UART_InitStructure. UART_HardwareFlowControl = UART_HardwareFlowControl_None; |
214 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
228 | UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; |
215 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
229 | UART_InitStructure.UART_FIFO = UART_FIFO_Enable; |
216 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
230 | UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; |
217 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
231 | UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; |
218 | 232 | ||
219 | UART_DeInit(UART1); // reset uart 1 to default |
233 | UART_DeInit(UART1); // reset uart 1 to default |
220 | UART_Init(UART1, &UART_InitStructure); // initialize uart 1 |
234 | UART_Init(UART1, &UART_InitStructure); // initialize uart 1 |
221 | // enable uart 1 interrupts selective |
235 | // enable uart 1 interrupts selective |
222 | UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
236 | UART_ITConfig(UART1, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE); |
223 | UART_Cmd(UART1, ENABLE); // enable uart 1 |
237 | UART_Cmd(UART1, ENABLE); // enable uart 1 |
224 | // configure the uart 1 interupt line as an IRQ with priority 4 (0 is highest) |
238 | // configure the uart 1 interupt line as an IRQ with priority 4 (0 is highest) |
225 | VIC_Config(UART1_ITLine, VIC_IRQ, 4); |
239 | VIC_Config(UART1_ITLine, VIC_IRQ, 4); |
226 | // enable the uart 1 IRQ |
240 | // enable the uart 1 IRQ |
227 | VIC_ITCmd(UART1_ITLine, ENABLE); |
241 | VIC_ITCmd(UART1_ITLine, ENABLE); |
228 | // initialize the debug timer |
242 | // initialize the debug timer |
229 | DebugData_Timer = SetDelay(DebugData_Interval); |
243 | DebugData_Timer = SetDelay(DebugData_Interval); |
230 | NaviData_Timer = SetDelay(NaviData_Interval)+500; |
244 | NaviData_Timer = SetDelay(NaviData_Interval)+500; |
231 | // unlock rxd_buffer |
245 | // unlock rxd_buffer |
232 | rxd_buffer_locked = FALSE; |
246 | rxd_buffer_locked = FALSE; |
233 | pRxData = NULL; |
247 | pRxData = NULL; |
234 | RxDataLen = 0; |
248 | RxDataLen = 0; |
235 | // no bytes to send |
249 | // no bytes to send |
236 | txd_complete = TRUE; |
250 | txd_complete = TRUE; |
237 | // Fill Version Info Structure |
251 | // Fill Version Info Structure |
238 | UART_VersionInfo.SWMajor = VERSION_MAJOR; |
252 | UART_VersionInfo.SWMajor = VERSION_MAJOR; |
239 | UART_VersionInfo.SWMinor = VERSION_MINOR; |
253 | UART_VersionInfo.SWMinor = VERSION_MINOR; |
240 | UART_VersionInfo.SWPatch = VERSION_PATCH; |
254 | UART_VersionInfo.SWPatch = VERSION_PATCH; |
241 | UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
255 | UART_VersionInfo.ProtoMajor = VERSION_SERIAL_MAJOR; |
242 | UART_VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
256 | UART_VersionInfo.ProtoMinor = VERSION_SERIAL_MINOR; |
243 | 257 | ||
244 | NaviData.Version = NAVIDATA_VERSION; |
258 | NaviData.Version = NAVIDATA_VERSION; |
245 | WPList_Clear(); |
- | |
246 | GPS_pWaypoint = WPList_Begin(); |
- | |
- | 259 | ||
247 | SerialPutString("\r\nUART1 init...ok"); |
260 | SerialPutString("\r\nUART1 init...ok"); |
248 | } |
261 | } |
249 | 262 | ||
250 | 263 | ||
251 | /****************************************************************/ |
264 | /****************************************************************/ |
252 | /* USART1 receiver ISR */ |
265 | /* USART1 receiver ISR */ |
253 | /****************************************************************/ |
266 | /****************************************************************/ |
254 | void UART1_IRQHandler(void) |
267 | void UART1_IRQHandler(void) |
255 | { |
268 | { |
256 | static u16 crc; |
269 | static u16 crc; |
257 | static u8 ptr_rxd_buffer = 0; |
270 | static u8 ptr_rxd_buffer = 0; |
258 | static u8 crc1, crc2; |
271 | static u8 crc1, crc2; |
259 | static u8 abortState = 0; |
272 | static u8 abortState = 0; |
260 | u8 c; |
273 | u8 c; |
261 | 274 | ||
262 | if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) ) |
275 | if((UART_GetITStatus(UART1, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART1, UART_IT_ReceiveTimeOut) != RESET) ) |
263 | { |
276 | { |
264 | // clear the pending bits |
277 | // clear the pending bits |
265 | UART_ClearITPendingBit(UART1, UART_IT_Receive); |
278 | UART_ClearITPendingBit(UART1, UART_IT_Receive); |
266 | UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut); |
279 | UART_ClearITPendingBit(UART1, UART_IT_ReceiveTimeOut); |
267 | // if debug UART is not UART1 |
280 | // if debug UART is not UART1 |
268 | if (DebugUART != UART1) |
281 | if (DebugUART != UART1) |
269 | { // forward received data to the debug UART tx buffer |
282 | { // forward received data to the debug UART tx buffer |
270 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
283 | while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) |
271 | { |
284 | { |
272 | // wait for space in the tx buffer of the DebugUART |
285 | // wait for space in the tx buffer of the DebugUART |
273 | while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {}; |
286 | while(UART_GetFlagStatus(DebugUART, UART_FLAG_TxFIFOFull) == SET) {}; |
274 | // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART |
287 | // move the byte from the rx buffer of UART1 to the tx buffer of DebugUART |
275 | c = UART_ReceiveData(UART1); |
288 | c = UART_ReceiveData(UART1); |
276 | 289 | ||
277 | // check for abort condition (ESC ESC 0x55 0xAA 0x00) |
290 | // check for abort condition (ESC ESC 0x55 0xAA 0x00) |
278 | switch (abortState) |
291 | switch (abortState) |
279 | { |
292 | { |
280 | case 0: if (c == 27) abortState++; |
293 | case 0: if (c == 27) abortState++; |
281 | break; |
294 | break; |
282 | case 1: if (c == 27) abortState++; else abortState = 0; |
295 | case 1: if (c == 27) abortState++; else abortState = 0; |
283 | break; |
296 | break; |
284 | case 2: if (c == 0x55) abortState++; else abortState = 0; |
297 | case 2: if (c == 0x55) abortState++; else abortState = 0; |
285 | break; |
298 | break; |
286 | case 3: if (c == 0xAA) abortState++; else abortState = 0; |
299 | case 3: if (c == 0xAA) abortState++; else abortState = 0; |
287 | break; |
300 | break; |
288 | case 4: if (c == 0x00) |
301 | case 4: if (c == 0x00) |
289 | { |
302 | { |
290 | DebugUART = UART1; |
303 | DebugUART = UART1; |
291 | UART0_Connect_to_MKGPS(); |
304 | UART0_Connect_to_MKGPS(); |
292 | } |
305 | } |
293 | abortState = 0; |
306 | abortState = 0; |
294 | break; |
307 | break; |
295 | } |
308 | } |
296 | 309 | ||
297 | if (DebugUART != UART1) UART_SendData(DebugUART, c); |
310 | if (DebugUART != UART1) UART_SendData(DebugUART, c); |
298 | } |
311 | } |
299 | } |
312 | } |
300 | else // DebugUART == UART1 (normal operation) |
313 | else // DebugUART == UART1 (normal operation) |
301 | { |
314 | { |
302 | while ((UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) && (!rxd_buffer_locked)) |
315 | while ((UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET) && (!rxd_buffer_locked)) |
303 | { // some byes in the fifo and rxd buffer not locked |
316 | { // some byes in the fifo and rxd buffer not locked |
304 | // get byte from fifo |
317 | // get byte from fifo |
305 | c = UART_ReceiveData(UART1); |
318 | c = UART_ReceiveData(UART1); |
306 | if((ptr_rxd_buffer == 0) && (c == '#')) // if rxd buffer is empty and syncronisation character is received |
319 | if((ptr_rxd_buffer == 0) && (c == '#')) // if rxd buffer is empty and syncronisation character is received |
307 | { |
320 | { |
308 | rxd_buffer[ptr_rxd_buffer++] = c; // copy 1st byte to buffer |
321 | rxd_buffer[ptr_rxd_buffer++] = c; // copy 1st byte to buffer |
309 | crc = c; // init crc |
322 | crc = c; // init crc |
310 | } |
323 | } |
311 | #if 0 |
324 | #if 0 |
312 | else if (ptr_rxd_buffer == 1) // handle address |
325 | else if (ptr_rxd_buffer == 1) // handle address |
313 | { |
326 | { |
314 | rxd_buffer[ptr_rxd_buffer++] = c; // copy byte to rxd buffer |
327 | rxd_buffer[ptr_rxd_buffer++] = c; // copy byte to rxd buffer |
315 | crc += c; // update crc |
328 | crc += c; // update crc |
316 | } |
329 | } |
317 | #endif |
330 | #endif |
318 | else if (ptr_rxd_buffer < RXD_BUFFER_LEN) // rxd buffer not full |
331 | else if (ptr_rxd_buffer < RXD_BUFFER_LEN) // rxd buffer not full |
319 | { |
332 | { |
320 | if (c != '\r') // no termination character received |
333 | if (c != '\r') // no termination character received |
321 | { |
334 | { |
322 | rxd_buffer[ptr_rxd_buffer++] = c; // copy byte to rxd buffer |
335 | rxd_buffer[ptr_rxd_buffer++] = c; // copy byte to rxd buffer |
323 | crc += c; // update crc |
336 | crc += c; // update crc |
324 | } |
337 | } |
325 | else // termination character received |
338 | else // termination character received |
326 | { |
339 | { |
327 | // the last 2 bytes are no subject for checksum calculation |
340 | // the last 2 bytes are no subject for checksum calculation |
328 | // they are the checksum itself |
341 | // they are the checksum itself |
329 | crc -= rxd_buffer[ptr_rxd_buffer-2]; |
342 | crc -= rxd_buffer[ptr_rxd_buffer-2]; |
330 | crc -= rxd_buffer[ptr_rxd_buffer-1]; |
343 | crc -= rxd_buffer[ptr_rxd_buffer-1]; |
331 | // calculate checksum from transmitted data |
344 | // calculate checksum from transmitted data |
332 | crc %= 4096; |
345 | crc %= 4096; |
333 | crc1 = '=' + crc / 64; |
346 | crc1 = '=' + crc / 64; |
334 | crc2 = '=' + crc % 64; |
347 | crc2 = '=' + crc % 64; |
335 | // compare checksum to transmitted checksum bytes |
348 | // compare checksum to transmitted checksum bytes |
336 | if((crc1 == rxd_buffer[ptr_rxd_buffer-2]) && (crc2 == rxd_buffer[ptr_rxd_buffer-1])) |
349 | if((crc1 == rxd_buffer[ptr_rxd_buffer-2]) && (crc2 == rxd_buffer[ptr_rxd_buffer-1])) |
337 | { // checksum valid |
350 | { // checksum valid |
338 | rxd_buffer_locked = TRUE; // lock the rxd buffer |
351 | rxd_buffer_locked = TRUE; // lock the rxd buffer |
339 | ReceivedBytes = ptr_rxd_buffer + 1; // store number of received bytes |
352 | ReceivedBytes = ptr_rxd_buffer + 1; // store number of received bytes |
340 | rxd_buffer[ptr_rxd_buffer] = '\r'; // set termination character |
353 | rxd_buffer[ptr_rxd_buffer] = '\r'; // set termination character |
341 | SerialDataOkay = 250; |
- | |
342 | // if 2nd byte is an 'R' start bootloader |
354 | // if 2nd byte is an 'R' start bootloader |
343 | if(rxd_buffer[2] == 'R') |
355 | if(rxd_buffer[2] == 'R') |
344 | { |
356 | { |
345 | PowerOff(); |
357 | PowerOff(); |
346 | VIC_DeInit(); |
358 | VIC_DeInit(); |
347 | Execute_Bootloader(); // Reset-Commando - Bootloader starten |
359 | Execute_Bootloader(); // Reset-Commando - Bootloader starten |
348 | } |
360 | } |
349 | } // eof checksum valid |
361 | } // eof checksum valid |
350 | else |
362 | else |
351 | { // checksum invalid |
363 | { // checksum invalid |
352 | rxd_buffer_locked = FALSE; // unlock rxd buffer |
364 | rxd_buffer_locked = FALSE; // unlock rxd buffer |
353 | } // eof checksum invalid |
365 | } // eof checksum invalid |
354 | ptr_rxd_buffer = 0; // reset rxd buffer pointer |
366 | ptr_rxd_buffer = 0; // reset rxd buffer pointer |
355 | } // eof termination character received |
367 | } // eof termination character received |
356 | } // rxd buffer not full |
368 | } // rxd buffer not full |
357 | else // rxd buffer overrun |
369 | else // rxd buffer overrun |
358 | { |
370 | { |
359 | ptr_rxd_buffer = 0; // reset rxd buffer pointer |
371 | ptr_rxd_buffer = 0; // reset rxd buffer pointer |
360 | rxd_buffer_locked = FALSE; // unlock rxd buffer |
372 | rxd_buffer_locked = FALSE; // unlock rxd buffer |
361 | } // eof rxd buffer overrrun |
373 | } // eof rxd buffer overrrun |
362 | } // some byes in the fifo and rxd buffer not locked |
374 | } // some byes in the fifo and rxd buffer not locked |
363 | } // eof DebugUart = UART1 |
375 | } // eof DebugUart = UART1 |
364 | } |
376 | } |
365 | } |
377 | } |
366 | 378 | ||
367 | /**************************************************************/ |
379 | /**************************************************************/ |
368 | /* Transmit tx buffer via debug uart */ |
380 | /* Transmit tx buffer via debug uart */ |
369 | /**************************************************************/ |
381 | /**************************************************************/ |
370 | void UART1_Transmit(void) |
382 | void UART1_Transmit(void) |
371 | { |
383 | { |
372 | u8 tmp_tx; |
384 | u8 tmp_tx; |
373 | // if something has to be send and the txd fifo is not full |
385 | // if something has to be send and the txd fifo is not full |
374 | if((!txd_complete) && (UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == RESET)) |
386 | if((!txd_complete) && (UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == RESET)) |
375 | { |
387 | { |
376 | tmp_tx = txd_buffer[ptr_txd_buffer]; // read byte from txd buffer |
388 | tmp_tx = txd_buffer[ptr_txd_buffer]; // read byte from txd buffer |
377 | // if terminating character or end of txd buffer reached |
389 | // if terminating character or end of txd buffer reached |
378 | if((tmp_tx == '\r') || (ptr_txd_buffer == TXD_BUFFER_LEN)) |
390 | if((tmp_tx == '\r') || (ptr_txd_buffer == TXD_BUFFER_LEN)) |
379 | { |
391 | { |
380 | ptr_txd_buffer = 0; // reset txd buffer pointer |
392 | ptr_txd_buffer = 0; // reset txd buffer pointer |
381 | txd_complete = TRUE;// set complete flag |
393 | txd_complete = TRUE;// set complete flag |
382 | } |
394 | } |
383 | UART_SendData(UART1, tmp_tx); // put character to txd fifo |
395 | UART_SendData(UART1, tmp_tx); // put character to txd fifo |
384 | // set pointer to next byte |
396 | // set pointer to next byte |
385 | ptr_txd_buffer++; |
397 | ptr_txd_buffer++; |
386 | } |
398 | } |
387 | } |
399 | } |
388 | 400 | ||
389 | /**************************************************************/ |
401 | /**************************************************************/ |
390 | /* Add CRC and initiate transmission via debug uart */ |
402 | /* Add CRC and initiate transmission via debug uart */ |
391 | /**************************************************************/ |
403 | /**************************************************************/ |
392 | void AddCRC(u16 datalen) |
404 | void AddCRC(u16 datalen) |
393 | { |
405 | { |
394 | u16 tmpCRC = 0, i; |
406 | u16 tmpCRC = 0, i; |
395 | for(i = 0; i < datalen; i++) |
407 | for(i = 0; i < datalen; i++) |
396 | { |
408 | { |
397 | tmpCRC += txd_buffer[i]; |
409 | tmpCRC += txd_buffer[i]; |
398 | } |
410 | } |
399 | tmpCRC %= 4096; |
411 | tmpCRC %= 4096; |
400 | txd_buffer[i++] = '=' + tmpCRC / 64; |
412 | txd_buffer[i++] = '=' + tmpCRC / 64; |
401 | txd_buffer[i++] = '=' + tmpCRC % 64; |
413 | txd_buffer[i++] = '=' + tmpCRC % 64; |
402 | txd_buffer[i++] = '\r'; |
414 | txd_buffer[i++] = '\r'; |
403 | 415 | ||
404 | ptr_txd_buffer = 0; |
416 | ptr_txd_buffer = 0; |
405 | txd_complete = FALSE; |
417 | txd_complete = FALSE; |
406 | UART_SendData(UART1, txd_buffer[ptr_txd_buffer++]); // send first byte, to be continued in the txd irq |
418 | UART_SendData(UART1, txd_buffer[ptr_txd_buffer++]); // send first byte, to be continued in the txd irq |
407 | } |
419 | } |
408 | 420 | ||
409 | 421 | ||
410 | 422 | ||
411 | /**************************************************************/ |
423 | /**************************************************************/ |
412 | /* Code output data */ |
424 | /* Code output data */ |
413 | /**************************************************************/ |
425 | /**************************************************************/ |
414 | void SendOutData(u8 cmd, u8 Address, u8 numofbuffers , ...) //u8 *data, u8 len, .... |
426 | void SendOutData(u8 cmd, u8 Address, u8 numofbuffers , ...) //u8 *data, u8 len, .... |
415 | { |
427 | { |
416 | va_list ap; |
428 | va_list ap; |
417 | 429 | ||
418 | u16 pt = 0; |
430 | u16 pt = 0; |
419 | u8 a,b,c; |
431 | u8 a,b,c; |
420 | u8 ptr = 0; |
432 | u8 ptr = 0; |
421 | 433 | ||
422 | u8* pdata = NULL; |
434 | u8* pdata = NULL; |
423 | int len = 0; |
435 | int len = 0; |
424 | 436 | ||
425 | txd_buffer[pt++] = '#'; // Start character |
437 | txd_buffer[pt++] = '#'; // Start character |
426 | txd_buffer[pt++] = 'a' + Address; // Address (a=0; b=1,...) |
438 | txd_buffer[pt++] = 'a' + Address; // Address (a=0; b=1,...) |
427 | txd_buffer[pt++] = cmd; // Command |
439 | txd_buffer[pt++] = cmd; // Command |
428 | 440 | ||
429 | va_start(ap, numofbuffers); |
441 | va_start(ap, numofbuffers); |
430 | if(numofbuffers) |
442 | if(numofbuffers) |
431 | { |
443 | { |
432 | pdata = va_arg(ap, u8*); |
444 | pdata = va_arg(ap, u8*); |
433 | len = va_arg(ap, int); |
445 | len = va_arg(ap, int); |
434 | ptr = 0; |
446 | ptr = 0; |
435 | numofbuffers--; |
447 | numofbuffers--; |
436 | } |
448 | } |
437 | while(len) |
449 | while(len) |
438 | { |
450 | { |
439 | if(len) |
451 | if(len) |
440 | { |
452 | { |
441 | a = pdata[ptr++]; |
453 | a = pdata[ptr++]; |
442 | len--; |
454 | len--; |
443 | if((!len) && numofbuffers) // try to jump to next buffer |
455 | if((!len) && numofbuffers) // try to jump to next buffer |
444 | { |
456 | { |
445 | pdata = va_arg(ap, u8*); |
457 | pdata = va_arg(ap, u8*); |
446 | len = va_arg(ap, int); |
458 | len = va_arg(ap, int); |
447 | ptr = 0; |
459 | ptr = 0; |
448 | numofbuffers--; |
460 | numofbuffers--; |
449 | } |
461 | } |
450 | } |
462 | } |
451 | else a = 0; |
463 | else a = 0; |
452 | if(len) |
464 | if(len) |
453 | { |
465 | { |
454 | b = pdata[ptr++]; |
466 | b = pdata[ptr++]; |
455 | len--; |
467 | len--; |
456 | if((!len) && numofbuffers) // try to jump to next buffer |
468 | if((!len) && numofbuffers) // try to jump to next buffer |
457 | { |
469 | { |
458 | pdata = va_arg(ap, u8*); |
470 | pdata = va_arg(ap, u8*); |
459 | len = va_arg(ap, int); |
471 | len = va_arg(ap, int); |
460 | ptr = 0; |
472 | ptr = 0; |
461 | numofbuffers--; |
473 | numofbuffers--; |
462 | } |
474 | } |
463 | } |
475 | } |
464 | else b = 0; |
476 | else b = 0; |
465 | if(len) |
477 | if(len) |
466 | { |
478 | { |
467 | c = pdata[ptr++]; |
479 | c = pdata[ptr++]; |
468 | len--; |
480 | len--; |
469 | if((!len) && numofbuffers) // try to jump to next buffer |
481 | if((!len) && numofbuffers) // try to jump to next buffer |
470 | { |
482 | { |
471 | pdata = va_arg(ap, u8*); |
483 | pdata = va_arg(ap, u8*); |
472 | len = va_arg(ap, int); |
484 | len = va_arg(ap, int); |
473 | ptr = 0; |
485 | ptr = 0; |
474 | numofbuffers--; |
486 | numofbuffers--; |
475 | } |
487 | } |
476 | } |
488 | } |
477 | else c = 0; |
489 | else c = 0; |
478 | txd_buffer[pt++] = '=' + (a >> 2); |
490 | txd_buffer[pt++] = '=' + (a >> 2); |
479 | txd_buffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
491 | txd_buffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
480 | txd_buffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
492 | txd_buffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
481 | txd_buffer[pt++] = '=' + ( c & 0x3f); |
493 | txd_buffer[pt++] = '=' + ( c & 0x3f); |
482 | } |
494 | } |
483 | va_end(ap); |
495 | va_end(ap); |
484 | AddCRC(pt); // add checksum after data block and initates the transmission |
496 | AddCRC(pt); // add checksum after data block and initates the transmission |
485 | } |
497 | } |
486 | 498 | ||
487 | 499 | ||
488 | /**************************************************************/ |
500 | /**************************************************************/ |
489 | /* Decode data */ |
501 | /* Decode data */ |
490 | /**************************************************************/ |
502 | /**************************************************************/ |
491 | void Decode64(void) |
503 | void Decode64(void) |
492 | { |
504 | { |
493 | u8 a,b,c,d; |
505 | u8 a,b,c,d; |
494 | u8 x,y,z; |
506 | u8 x,y,z; |
495 | u8 ptrIn = 3; // start with first data byte in rx buffer |
507 | u8 ptrIn = 3; // start with first data byte in rx buffer |
496 | u8 ptrOut = 3; |
508 | u8 ptrOut = 3; |
497 | u8 len = ReceivedBytes - 6; // must be a multiple of 4 (3 bytes at begin and 3 bytes at end are no payload ) |
509 | u8 len = ReceivedBytes - 6; // must be a multiple of 4 (3 bytes at begin and 3 bytes at end are no payload ) |
498 | while(len) |
510 | while(len) |
499 | { |
511 | { |
500 | a = rxd_buffer[ptrIn++] - '='; |
512 | a = rxd_buffer[ptrIn++] - '='; |
501 | b = rxd_buffer[ptrIn++] - '='; |
513 | b = rxd_buffer[ptrIn++] - '='; |
502 | c = rxd_buffer[ptrIn++] - '='; |
514 | c = rxd_buffer[ptrIn++] - '='; |
503 | d = rxd_buffer[ptrIn++] - '='; |
515 | d = rxd_buffer[ptrIn++] - '='; |
504 | //if(ptrIn > ReceivedBytes - 3) break; |
516 | //if(ptrIn > ReceivedBytes - 3) break; |
505 | 517 | ||
506 | x = (a << 2) | (b >> 4); |
518 | x = (a << 2) | (b >> 4); |
507 | y = ((b & 0x0f) << 4) | (c >> 2); |
519 | y = ((b & 0x0f) << 4) | (c >> 2); |
508 | z = ((c & 0x03) << 6) | d; |
520 | z = ((c & 0x03) << 6) | d; |
509 | 521 | ||
510 | if(len--) rxd_buffer[ptrOut++] = x; else break; |
522 | if(len--) rxd_buffer[ptrOut++] = x; else break; |
511 | if(len--) rxd_buffer[ptrOut++] = y; else break; |
523 | if(len--) rxd_buffer[ptrOut++] = y; else break; |
512 | if(len--) rxd_buffer[ptrOut++] = z; else break; |
524 | if(len--) rxd_buffer[ptrOut++] = z; else break; |
513 | } |
525 | } |
514 | pRxData = &rxd_buffer[3]; |
526 | pRxData = &rxd_buffer[3]; |
515 | RxDataLen = ptrOut - 3; |
527 | RxDataLen = ptrOut - 3; |
516 | } |
528 | } |
517 | 529 | ||
518 | /**************************************************************/ |
530 | /**************************************************************/ |
519 | /* Process incomming data from debug uart */ |
531 | /* Process incomming data from debug uart */ |
520 | /**************************************************************/ |
532 | /**************************************************************/ |
521 | void UART1_ProcessRxData(void) |
533 | void UART1_ProcessRxData(void) |
522 | { |
534 | { |
523 | // if data in the rxd buffer are not locked immediately return |
535 | // if data in the rxd buffer are not locked immediately return |
524 | if((!rxd_buffer_locked) || (DebugUART != UART1) ) return; |
536 | if((!rxd_buffer_locked) || (DebugUART != UART1) ) return; |
525 | Waypoint_t * pWaypoint = NULL; |
537 | Waypoint_t * pWaypoint = NULL; |
526 | 538 | ||
527 | 539 | ||
528 | 540 | ||
529 | PcAccess = 255; |
541 | PcAccess = 255; |
530 | Decode64(); // decode data block in rxd buffer |
542 | Decode64(); // decode data block in rxd buffer |
531 | switch(rxd_buffer[1] - 'a') // check for Slave Address |
543 | switch(rxd_buffer[1] - 'a') // check for Slave Address |
532 | { |
544 | { |
533 | case NC_ADDRESS: // own Slave Address |
545 | case NC_ADDRESS: // own Slave Address |
534 | 546 | ||
535 | switch(rxd_buffer[2]) |
547 | switch(rxd_buffer[2]) |
536 | { |
548 | { |
- | 549 | case 'z': // connection checker |
|
- | 550 | Echo = *((u16*)&pRxData[0]); // copy echo pattern |
|
- | 551 | SerialLinkOkay = 250; // reset SerialTimeout |
|
- | 552 | Request_Echo = TRUE; |
|
- | 553 | break; |
|
- | 554 | ||
537 | case 'e': // request for the text of the error status |
555 | case 'e': // request for the text of the error status |
538 | Request_ErrorMessage = TRUE; |
556 | Request_ErrorMessage = TRUE; |
539 | break; |
557 | break; |
540 | 558 | ||
541 | case 's':// new target position |
559 | case 's':// new target position |
542 | pWaypoint = (Waypoint_t*)&pRxData[0]; |
560 | pWaypoint = (Waypoint_t*)&pRxData[0]; |
543 | BeepTime = 300; |
561 | BeepTime = 300; |
544 | if(pWaypoint->Position.Status == NEWDATA) |
562 | if(pWaypoint->Position.Status == NEWDATA) |
545 | { |
563 | { |
546 | WPList_Clear(); // empty WPList |
564 | WPList_Clear(); // empty WPList |
547 | WPList_Append(pWaypoint); |
565 | WPList_Append(pWaypoint); |
548 | GPS_pWaypoint = WPList_Begin(); |
566 | GPS_pWaypoint = WPList_Begin(); |
549 | } |
567 | } |
550 | break; |
568 | break; |
551 | 569 | ||
552 | case 'u': // redirect debug uart |
570 | case 'u': // redirect debug uart |
553 | switch(pRxData[0]) |
571 | switch(pRxData[0]) |
554 | { |
572 | { |
555 | case UART_FLIGHTCTRL: |
573 | case UART_FLIGHTCTRL: |
556 | UART2_Init(); // initialize UART2 to FC pins |
574 | UART2_Init(); // initialize UART2 to FC pins |
557 | DebugUART = UART2; |
575 | DebugUART = UART2; |
558 | break; |
576 | break; |
559 | case UART_MK3MAG: |
577 | case UART_MK3MAG: |
560 | if(FC.MKFlags & MKFLAG_MOTOR_RUN) break; // not if the motors are running |
578 | if(FC.MKFlags & MKFLAG_MOTOR_RUN) break; // not if the motors are running |
561 | UART0_Connect_to_MK3MAG(); // mux UART0 to MK3MAG pins |
579 | UART0_Connect_to_MK3MAG(); // mux UART0 to MK3MAG pins |
562 | GPSData.Status = INVALID; |
580 | GPSData.Status = INVALID; |
563 | DebugUART = UART0; |
581 | DebugUART = UART0; |
564 | break; |
582 | break; |
565 | case UART_MKGPS: |
583 | case UART_MKGPS: |
566 | if(FC.MKFlags & MKFLAG_MOTOR_RUN) break; // not if the motors are running |
584 | if(FC.MKFlags & MKFLAG_MOTOR_RUN) break; // not if the motors are running |
567 | UART0_Connect_to_MKGPS(); // connect UART0 to MKGPS pins |
585 | UART0_Connect_to_MKGPS(); // connect UART0 to MKGPS pins |
568 | GPSData.Status = INVALID; |
586 | GPSData.Status = INVALID; |
569 | DebugUART = UART0; |
587 | DebugUART = UART0; |
570 | break; |
588 | break; |
571 | } |
589 | } |
572 | break; |
590 | break; |
573 | 591 | ||
574 | case 'w':// new PCPosition for GPSTargetList |
592 | case 'w':// Append Waypoint to List |
575 | pWaypoint = (Waypoint_t*)&pRxData[0]; |
593 | pWaypoint = (Waypoint_t*)&pRxData[0]; |
576 | if(pWaypoint->Position.Status == INVALID) |
594 | if(pWaypoint->Position.Status == INVALID) |
577 | { // clear WP List |
595 | { // clear WP List |
578 | WPList_Clear(); |
596 | WPList_Clear(); |
579 | GPS_pWaypoint = WPList_Begin(); |
597 | GPS_pWaypoint = WPList_Begin(); |
580 | //SerialPutString("\r\nClear WP List\r\n"); |
598 | //SerialPutString("\r\nClear WP List\r\n"); |
581 | } |
599 | } |
582 | else if (pWaypoint->Position.Status == NEWDATA) |
600 | else if (pWaypoint->Position.Status == NEWDATA) |
583 | { // app current WP to the list |
601 | { // app current WP to the list |
584 | WPList_Append(pWaypoint); |
602 | WPList_Append(pWaypoint); |
585 | BeepTime = 500; |
603 | BeepTime = 500; |
586 | //SerialPutString("\r\nAdd WP to List\r\n"); |
604 | //SerialPutString("\r\nAdd WP to List\r\n"); |
587 | } |
605 | } |
588 | Request_NewWaypoint = TRUE; |
606 | Request_NewWaypoint = TRUE; |
589 | break; |
607 | break; |
- | 608 | ||
- | 609 | case 'x':// Read Waypoint from List |
|
- | 610 | Request_ReadWaypoint = pRxData[0]; |
|
- | 611 | break; |
|
590 | 612 | ||
591 | default: |
613 | default: |
592 | // unsupported command recieved |
614 | // unsupported command recieved |
593 | break; |
615 | break; |
594 | } // case NC_ADDRESS |
616 | } // case NC_ADDRESS |
595 | // "break;" is missing here to fall thru to the common commands |
617 | // "break;" is missing here to fall thru to the common commands |
596 | 618 | ||
597 | default: // and any other Slave Address |
619 | default: // and any other Slave Address |
598 | 620 | ||
599 | switch(rxd_buffer[2]) // check CmdID |
621 | switch(rxd_buffer[2]) // check CmdID |
600 | { |
622 | { |
601 | case 'a':// request for the labels of the analog debug outputs |
623 | case 'a':// request for the labels of the analog debug outputs |
602 | Request_DebugLabel = pRxData[0]; |
624 | Request_DebugLabel = pRxData[0]; |
603 | if(Request_DebugLabel > 31) Request_DebugLabel = 31; |
625 | if(Request_DebugLabel > 31) Request_DebugLabel = 31; |
604 | break; |
626 | break; |
605 | 627 | ||
606 | case 'b': // submit extern control |
628 | case 'b': // submit extern control |
607 | memcpy(&ExternControl, (u8*)&pRxData[0], sizeof(ExternControl)); |
629 | memcpy(&ExternControl, (u8*)&pRxData[0], sizeof(ExternControl)); |
608 | ConfirmFrame = ExternControl.Frame; |
630 | ConfirmFrame = ExternControl.Frame; |
609 | break; |
631 | break; |
610 | 632 | ||
611 | case 'd': // request for debug data; |
633 | case 'd': // request for debug data; |
612 | DebugData_Interval = (u32) pRxData[0] * 10; |
634 | DebugData_Interval = (u32) pRxData[0] * 10; |
613 | if(DebugData_Interval > 0) Request_DebugData = TRUE; |
635 | if(DebugData_Interval > 0) Request_DebugData = TRUE; |
614 | break; |
636 | break; |
615 | 637 | ||
616 | case 'c': // request for 3D data; |
638 | case 'c': // request for 3D data; |
617 | Data3D_Interval = (u32) pRxData[0] * 10; |
639 | Data3D_Interval = (u32) pRxData[0] * 10; |
618 | if(Data3D_Interval > 0) Request_Data3D = TRUE; |
640 | if(Data3D_Interval > 0) Request_Data3D = TRUE; |
619 | break; |
641 | break; |
620 | 642 | ||
621 | case 'g':// request for external control data |
643 | case 'g':// request for external control data |
622 | Request_ExternalControl = TRUE; |
644 | Request_ExternalControl = TRUE; |
623 | break; |
645 | break; |
624 | 646 | ||
625 | case 'h':// reqest for display line |
647 | case 'h':// reqest for display line |
626 | RemoteKeys |= pRxData[0]; |
648 | RemoteKeys |= pRxData[0]; |
627 | if(RemoteKeys != 0) DisplayLine = 0; |
649 | if(RemoteKeys != 0) DisplayLine = 0; |
628 | Request_Display = TRUE; |
650 | Request_Display = TRUE; |
629 | break; |
651 | break; |
630 | 652 | ||
631 | case 'l':// reqest for display columns |
653 | case 'l':// reqest for display columns |
632 | MenuItem = pRxData[0]; |
654 | MenuItem = pRxData[0]; |
633 | Request_Display1 = TRUE; |
655 | Request_Display1 = TRUE; |
634 | break; |
656 | break; |
635 | 657 | ||
636 | case 'o': // request for navigation information |
658 | case 'o': // request for navigation information |
637 | NaviData_Interval = (u32) pRxData[0] * 10; |
659 | NaviData_Interval = (u32) pRxData[0] * 10; |
638 | if(NaviData_Interval > 0) Request_NaviData = TRUE; |
660 | if(NaviData_Interval > 0) Request_NaviData = TRUE; |
639 | break; |
661 | break; |
640 | 662 | ||
641 | case 'v': // request for version info |
663 | case 'v': // request for version info |
642 | Request_VerInfo = TRUE; |
664 | Request_VerInfo = TRUE; |
643 | break; |
665 | break; |
644 | default: |
666 | default: |
645 | // unsupported command recieved |
667 | // unsupported command recieved |
646 | break; |
668 | break; |
647 | } |
669 | } |
648 | break; // default: |
670 | break; // default: |
649 | } |
671 | } |
650 | // unlock the rxd buffer after processing |
672 | // unlock the rxd buffer after processing |
651 | pRxData = NULL; |
673 | pRxData = NULL; |
652 | RxDataLen = 0; |
674 | RxDataLen = 0; |
653 | rxd_buffer_locked = FALSE; |
675 | rxd_buffer_locked = FALSE; |
654 | } |
676 | } |
655 | 677 | ||
656 | 678 | ||
657 | /*****************************************************/ |
679 | /*****************************************************/ |
658 | /* Send a character */ |
680 | /* Send a character */ |
659 | /*****************************************************/ |
681 | /*****************************************************/ |
660 | s16 uart_putchar (char c) |
682 | s16 uart_putchar (char c) |
661 | { |
683 | { |
662 | if (c == '\n') uart_putchar('\r'); |
684 | if (c == '\n') uart_putchar('\r'); |
663 | // wait until txd fifo is not full |
685 | // wait until txd fifo is not full |
664 | while (UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET); |
686 | while (UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) != RESET); |
665 | // transmit byte |
687 | // transmit byte |
666 | UART_SendData(UART1, c); |
688 | UART_SendData(UART1, c); |
667 | return (0); |
689 | return (0); |
668 | } |
690 | } |
669 | 691 | ||
670 | /*****************************************************/ |
692 | /*****************************************************/ |
671 | /* Send a string to the debug uart */ |
693 | /* Send a string to the debug uart */ |
672 | /*****************************************************/ |
694 | /*****************************************************/ |
673 | void SerialPutString(u8 *s) |
695 | void SerialPutString(u8 *s) |
674 | { |
696 | { |
675 | if(s == NULL) return; |
697 | if(s == NULL) return; |
676 | while (*s != '\0' && DebugUART == UART1) |
698 | while (*s != '\0' && DebugUART == UART1) |
677 | { |
699 | { |
678 | uart_putchar(*s); |
700 | uart_putchar(*s); |
679 | s ++; |
701 | s ++; |
680 | } |
702 | } |
681 | } |
703 | } |
682 | 704 | ||
683 | 705 | ||
684 | 706 | ||
685 | /**************************************************************/ |
707 | /**************************************************************/ |
686 | /* Send the answers to incomming commands at the debug uart */ |
708 | /* Send the answers to incomming commands at the debug uart */ |
687 | /**************************************************************/ |
709 | /**************************************************************/ |
688 | void UART1_TransmitTxData(void) |
710 | void UART1_TransmitTxData(void) |
689 | { |
711 | { |
690 | if(!txd_complete || (DebugUART != UART1) ) return; |
712 | if(!txd_complete || (DebugUART != UART1) ) return; |
- | 713 | ||
- | 714 | if(Request_Echo && txd_complete) |
|
- | 715 | { |
|
- | 716 | SendOutData('Z', NC_ADDRESS, 1, &Echo, sizeof(Echo)); // answer the echo request |
|
- | 717 | Echo = 0; // reset echo value |
|
- | 718 | Request_Echo = FALSE; |
|
691 | 719 | } |
|
692 | if(Request_DebugLabel != 0xFF) |
720 | if(Request_DebugLabel != 0xFF) |
693 | { |
721 | { |
694 | SendOutData('A', NC_ADDRESS, 2, &Request_DebugLabel, sizeof(Request_DebugLabel), (u8 *) ANALOG_LABEL[Request_DebugLabel], 16); |
722 | SendOutData('A', NC_ADDRESS, 2, &Request_DebugLabel, sizeof(Request_DebugLabel), (u8 *) ANALOG_LABEL[Request_DebugLabel], 16); |
695 | Request_DebugLabel = 0xFF; |
723 | Request_DebugLabel = 0xFF; |
696 | } |
724 | } |
697 | if(ConfirmFrame && txd_complete) |
725 | if(ConfirmFrame && txd_complete) |
698 | { |
726 | { |
699 | SendOutData('B', NC_ADDRESS, 1, &ConfirmFrame, sizeof(ConfirmFrame)); |
727 | SendOutData('B', NC_ADDRESS, 1, &ConfirmFrame, sizeof(ConfirmFrame)); |
700 | ConfirmFrame = 0; |
728 | ConfirmFrame = 0; |
701 | } |
729 | } |
702 | if( (( (DebugData_Interval > 0) && CheckDelay(DebugData_Timer)) || Request_DebugData) && txd_complete) |
730 | if( (( (DebugData_Interval > 0) && CheckDelay(DebugData_Timer)) || Request_DebugData) && txd_complete) |
703 | { |
731 | { |
704 | SendOutData('D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut)); |
732 | SendOutData('D', NC_ADDRESS, 1,(u8 *)&DebugOut, sizeof(DebugOut)); |
705 | DebugData_Timer = SetDelay(DebugData_Interval); |
733 | DebugData_Timer = SetDelay(DebugData_Interval); |
706 | Request_DebugData = FALSE; |
734 | Request_DebugData = FALSE; |
707 | } |
735 | } |
708 | 736 | ||
709 | if((( (Data3D_Interval > 0) && CheckDelay(Data3D_Timer) ) || Request_Data3D) && txd_complete) |
737 | if((( (Data3D_Interval > 0) && CheckDelay(Data3D_Timer) ) || Request_Data3D) && txd_complete) |
710 | { |
738 | { |
711 | SendOutData('C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D)); |
739 | SendOutData('C', NC_ADDRESS, 1,(u8 *)&Data3D, sizeof(Data3D)); |
712 | Data3D_Timer = SetDelay(Data3D_Interval); |
740 | Data3D_Timer = SetDelay(Data3D_Interval); |
713 | Request_Data3D = FALSE; |
741 | Request_Data3D = FALSE; |
714 | } |
742 | } |
715 | 743 | ||
716 | if(Request_ExternalControl && txd_complete) |
744 | if(Request_ExternalControl && txd_complete) |
717 | { |
745 | { |
718 | SendOutData('G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl)); |
746 | SendOutData('G', NC_ADDRESS, 1, (u8 *)&ExternControl, sizeof(ExternControl)); |
719 | Request_ExternalControl = FALSE; |
747 | Request_ExternalControl = FALSE; |
720 | } |
748 | } |
721 | if(Request_Display && txd_complete) |
749 | if(Request_Display && txd_complete) |
722 | { |
750 | { |
723 | LCD_PrintMenu(); |
751 | LCD_PrintMenu(); |
724 | SendOutData('H', NC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), (u8*)&DisplayBuff[DisplayLine * 20], 20); |
752 | SendOutData('H', NC_ADDRESS, 2, &DisplayLine, sizeof(DisplayLine), (u8*)&DisplayBuff[DisplayLine * 20], 20); |
725 | DisplayLine++; |
753 | DisplayLine++; |
726 | if(DisplayLine >= 4) DisplayLine = 0; |
754 | if(DisplayLine >= 4) DisplayLine = 0; |
727 | Request_Display = FALSE; |
755 | Request_Display = FALSE; |
728 | } |
756 | } |
729 | if(Request_Display1 && txd_complete) |
757 | if(Request_Display1 && txd_complete) |
730 | { |
758 | { |
731 | LCD_PrintMenu(); |
759 | LCD_PrintMenu(); |
732 | SendOutData('L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff)); |
760 | SendOutData('L', NC_ADDRESS, 3, (u8*)&MenuItem, sizeof(MenuItem), (u8*)&MaxMenuItem, sizeof(MaxMenuItem),(u8*)DisplayBuff, sizeof(DisplayBuff)); |
733 | Request_Display1 = FALSE; |
761 | Request_Display1 = FALSE; |
734 | } |
762 | } |
735 | if(Request_VerInfo && txd_complete) |
763 | if(Request_VerInfo && txd_complete) |
736 | { |
764 | { |
737 | SendOutData('V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo)); |
765 | SendOutData('V', NC_ADDRESS,1, (u8 *)&UART_VersionInfo, sizeof(UART_VersionInfo)); |
738 | Request_VerInfo = FALSE; |
766 | Request_VerInfo = FALSE; |
739 | } |
767 | } |
740 | if(( (NaviData_Interval && CheckDelay(NaviData_Timer) ) || Request_NaviData) && txd_complete) |
768 | if(( (NaviData_Interval && CheckDelay(NaviData_Timer) ) || Request_NaviData) && txd_complete) |
741 | { |
769 | { |
742 | NaviData.Errorcode = ErrorCode; |
770 | NaviData.Errorcode = ErrorCode; |
743 | SendOutData('O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData)); |
771 | SendOutData('O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData)); |
744 | if (DebugUART == UART1) SendOutData0('O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData)); |
772 | if (DebugUART == UART1) SendOutData0('O', NC_ADDRESS,1, (u8 *)&NaviData, sizeof(NaviData)); |
745 | NaviData_Timer = SetDelay(NaviData_Interval); |
773 | NaviData_Timer = SetDelay(NaviData_Interval); |
746 | Request_NaviData = FALSE; |
774 | Request_NaviData = FALSE; |
747 | } |
775 | } |
748 | if(Request_ErrorMessage && txd_complete) |
776 | if(Request_ErrorMessage && txd_complete) |
749 | { |
777 | { |
750 | SendOutData('E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG)); |
778 | SendOutData('E', NC_ADDRESS, 1, (u8 *)&ErrorMSG, sizeof(ErrorMSG)); |
751 | Request_ErrorMessage = FALSE; |
779 | Request_ErrorMessage = FALSE; |
752 | } |
780 | } |
753 | if(Request_SendFollowMe && txd_complete && (GPSData.NumOfSats >= 4)) // sending for "Follow me" |
781 | if(Request_SendFollowMe && txd_complete && (GPSData.NumOfSats >= 4)) // sending for "Follow me" |
754 | { |
782 | { |
755 | GPS_CopyPosition(&(GPSData.Position),&(FollowMe.Position)); |
783 | GPS_CopyPosition(&(GPSData.Position),&(FollowMe.Position)); |
756 | FollowMe.Position.Status = NEWDATA; |
784 | FollowMe.Position.Status = NEWDATA; |
757 | FollowMe.Heading = -1; |
785 | FollowMe.Heading = -1; |
758 | FollowMe.ToleranceRadius = 1; |
786 | FollowMe.ToleranceRadius = 1; |
759 | FollowMe.HoldTime = 60; |
787 | FollowMe.HoldTime = 60; |
760 | FollowMe.Event_Flag = 0; |
788 | FollowMe.Event_Flag = 0; |
761 | FollowMe.reserve[0] = 0; // reserve |
789 | FollowMe.reserve[0] = 0; // reserve |
762 | FollowMe.reserve[1] = 0; // reserve |
790 | FollowMe.reserve[1] = 0; // reserve |
763 | FollowMe.reserve[2] = 0; // reserve |
791 | FollowMe.reserve[2] = 0; // reserve |
764 | FollowMe.reserve[3] = 0; // reserve |
792 | FollowMe.reserve[3] = 0; // reserve |
765 | SendOutData('s', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe)); |
793 | SendOutData('s', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe)); |
766 | Request_SendFollowMe = FALSE; |
794 | Request_SendFollowMe = FALSE; |
767 | } |
795 | } |
768 | 796 | ||
769 | if(Request_NewWaypoint && txd_complete) |
797 | if(Request_NewWaypoint && txd_complete) |
770 | { |
798 | { |
771 | u8 WPNumber = WPList_GetCount(); |
799 | u8 WPNumber = WPList_GetCount(); |
772 | SendOutData('W', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber)); |
800 | SendOutData('W', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber)); |
773 | Request_NewWaypoint = FALSE; |
801 | Request_NewWaypoint = FALSE; |
774 | } |
802 | } |
- | 803 | ||
- | 804 | if((Request_ReadWaypoint != 0xFF) && txd_complete) |
|
- | 805 | { |
|
- | 806 | u8 WPNumber = WPList_GetCount(); |
|
- | 807 | if (Request_ReadWaypoint < WPNumber) |
|
- | 808 | { |
|
- | 809 | SendOutData('X', NC_ADDRESS, 3, &WPNumber, 1, &Request_ReadWaypoint, 1, WPList_GetAt(Request_ReadWaypoint), sizeof(Waypoint_t)); |
|
- | 810 | } |
|
- | 811 | else |
|
- | 812 | { |
|
- | 813 | SendOutData('X', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber)); |
|
- | 814 | } |
|
- | 815 | Request_ReadWaypoint = 0xFF; |
|
- | 816 | } |
|
775 | 817 | ||
776 | } |
818 | } |
777 | 819 | ||
778 | 820 |