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