Rev 828 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
41 | ingob | 1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
||
3 | /*#######################################################################################*/ |
||
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
5 | // + www.MikroKopter.com |
||
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
360 | holgerb | 7 | // + Software Nutzungsbedingungen (english version: see below) |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
||
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
||
516 | holgerb | 10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
360 | holgerb | 11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
||
41 | ingob | 13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
360 | holgerb | 14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
||
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
||
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
||
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
||
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
||
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
||
516 | holgerb | 21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
360 | holgerb | 22 | // + des Mitverschuldens offen. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
||
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
||
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
||
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
||
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
||
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
||
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
||
30 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
||
41 | ingob | 31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
360 | holgerb | 32 | // + Software LICENSING TERMS |
41 | ingob | 33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
360 | holgerb | 34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
516 | holgerb | 35 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
360 | holgerb | 36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
37 | // + The Software may only be used with the Licensor's products. |
||
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
||
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
||
40 | // + agreement shall be the property of the Licensor. |
||
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
||
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
||
43 | // + The customer shall be responsible for taking reasonable precautions |
||
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
||
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
||
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
||
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
||
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
||
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
||
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
||
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
||
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
||
53 | // + #### END OF LICENSING TERMS #### |
||
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
||
41 | ingob | 55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
490 | killagreg | 56 | #include <ctype.h> |
57 | #include <stdio.h> |
||
516 | holgerb | 58 | #include <stdlib.h> |
41 | ingob | 59 | #include <string.h> |
60 | #include "91x_lib.h" |
||
61 | #include "waypoints.h" |
||
62 | #include "uart1.h" |
||
490 | killagreg | 63 | #include "fat16.h" |
504 | holgerb | 64 | #include "main.h" |
513 | killagreg | 65 | #include "spi_slave.h" |
41 | ingob | 66 | |
496 | killagreg | 67 | |
68 | WPL_Store_t WPL_Store; |
||
69 | |||
280 | killagreg | 70 | Point_t PointList[MAX_LIST_LEN]; |
71 | u8 WPIndex = 0; // list index of GPS point representig the current WP, can be maximal WPCount |
||
72 | u8 POIIndex = 0; // list index of GPS Point representing the current POI, can be maximal WPCount |
||
73 | u8 WPCount = 0; // number of waypoints |
||
491 | killagreg | 74 | u8 PointCount = 0; // number of points in the list can be maximal equal to MAX_LIST_LEN |
75 | u8 POICount = 0; // number of point of interest in the list |
||
601 | holgerb | 76 | u8 FsPointCnt = 0; |
802 | holgerb | 77 | u8 FlyzonePointCnt = 0; |
517 | holgerb | 78 | s16 HeadingOld = -1; |
577 | holgerb | 79 | u32 SD_WaypointTimeout = 5; // Setting on SD-Card |
41 | ingob | 80 | |
296 | killagreg | 81 | u8 WPActive = FALSE; |
280 | killagreg | 82 | |
83 | u8 PointList_Init(void) |
||
41 | ingob | 84 | { |
516 | holgerb | 85 | return PointList_Clear(); |
41 | ingob | 86 | } |
87 | |||
280 | killagreg | 88 | u8 PointList_Clear(void) |
41 | ingob | 89 | { |
90 | u8 i; |
||
227 | killagreg | 91 | WPIndex = 0; // real list position are 1 ,2, 3 ... |
92 | POIIndex = 0; // real list position are 1 ,2, 3 ... |
||
802 | holgerb | 93 | |
280 | killagreg | 94 | WPCount = 0; // no waypoints |
601 | holgerb | 95 | FsPointCnt = 0; |
516 | holgerb | 96 | POICount = 0; |
280 | killagreg | 97 | PointCount = 0; // no contents |
802 | holgerb | 98 | FlyzonePointCnt = 0; |
99 | |||
296 | killagreg | 100 | WPActive = FALSE; |
280 | killagreg | 101 | NaviData.WaypointNumber = WPCount; |
102 | NaviData.WaypointIndex = 0; |
||
103 | for(i = 0; i < MAX_LIST_LEN; i++) |
||
41 | ingob | 104 | { |
280 | killagreg | 105 | PointList[i].Position.Status = INVALID; |
106 | PointList[i].Position.Latitude = 0; |
||
107 | PointList[i].Position.Longitude = 0; |
||
108 | PointList[i].Position.Altitude = 0; |
||
109 | PointList[i].Heading = 361; // invalid value |
||
110 | PointList[i].ToleranceRadius = 0; // in meters, if the MK is within that range around the target, then the next target is triggered |
||
111 | PointList[i].HoldTime = 0; // in seconds, if the was once in the tolerance area around a WP, this time defines the delay before the next WP is triggered |
||
490 | killagreg | 112 | PointList[i].Event_Flag = 0; // future implementation |
113 | PointList[i].Index = 0; |
||
286 | killagreg | 114 | PointList[i].Type = POINT_TYPE_INVALID; |
490 | killagreg | 115 | PointList[i].WP_EventChannelValue = 0; |
286 | killagreg | 116 | PointList[i].AltitudeRate = 0; // no change of setpoint |
490 | killagreg | 117 | PointList[i].Speed = 0; |
118 | PointList[i].CamAngle = 0; |
||
119 | PointList[i].Name[0] = 0; |
||
41 | ingob | 120 | } |
504 | holgerb | 121 | ClearWLP_Name(); |
516 | holgerb | 122 | return TRUE; |
41 | ingob | 123 | } |
124 | |||
802 | holgerb | 125 | |
126 | s32 CheckPositionInFlyzone(s32 Longitude, s32 Latitude, u8 UpdateTimer) |
||
127 | { |
||
128 | #define POINTS 31 |
||
129 | static Vec2D_t poly[POINTS+1]; |
||
130 | Vec2D_t check_pos; |
||
131 | u32 z = 0; |
||
132 | u32 i; |
||
133 | s32 wn; |
||
134 | if(FlyzonePointCnt < 3) return(100); // too small - return 100 |
||
135 | |||
136 | check_pos.x = Longitude >> 8; |
||
137 | check_pos.y = Latitude >> 8; |
||
138 | |||
139 | if(UpdateTimer == 0) |
||
140 | { |
||
141 | for(i=0; i < PointCount; i++) |
||
142 | { |
||
143 | if(PointList[i].Type == POINT_TYPE_FLYZONE) |
||
144 | { |
||
145 | poly[z].x = PointList[i].Position.Longitude >> 8; |
||
146 | poly[z].y = PointList[i].Position.Latitude >> 8; |
||
147 | z++; |
||
148 | if(z >= FlyzonePointCnt) break; // we found them all |
||
149 | if(z >= POINTS) break; // too many |
||
150 | } |
||
151 | } |
||
152 | // close polygon |
||
153 | poly[z].x = poly[0].x; |
||
154 | poly[z].y = poly[0].y; |
||
155 | } |
||
156 | wn = PointPolyCheck(check_pos,poly,FlyzonePointCnt); |
||
828 | holgerb | 157 | if(wn == 1 || wn == -1) return(1); |
158 | else return(0); // gekreuzte Polygone können 2 oder -2 zurück geben |
||
802 | holgerb | 159 | } |
160 | |||
161 | |||
280 | killagreg | 162 | u8 PointList_GetCount(void) |
41 | ingob | 163 | { |
280 | killagreg | 164 | return PointCount; // number of points in the list |
41 | ingob | 165 | } |
166 | |||
295 | killagreg | 167 | Point_t* PointList_GetAt(u8 index) |
41 | ingob | 168 | { |
295 | killagreg | 169 | if((index > 0) && (index <= PointCount)) return(&(PointList[index-1])); // return pointer to this waypoint |
170 | else return(NULL); |
||
171 | } |
||
172 | |||
173 | u8 PointList_SetAt(Point_t* pPoint) |
||
174 | { |
||
175 | // if index is in range |
||
296 | killagreg | 176 | if((pPoint->Index > 0) && (pPoint->Index <= MAX_LIST_LEN)) |
41 | ingob | 177 | { |
802 | holgerb | 178 | UpdateFlyzoneTimer = 2; // makes an update of the flightzone in some milliseconds |
295 | killagreg | 179 | // check list entry before update |
180 | switch(PointList[pPoint->Index-1].Type) |
||
277 | killagreg | 181 | { |
295 | killagreg | 182 | case POINT_TYPE_INVALID: // was invalid |
183 | switch(pPoint->Type) |
||
184 | { |
||
185 | default: |
||
186 | case POINT_TYPE_INVALID: |
||
187 | // nothing to do |
||
188 | break; |
||
189 | |||
785 | holgerb | 190 | case POINT_TYPE_LAND: |
191 | FsPointCnt++; // break fehlt absichtlich |
||
295 | killagreg | 192 | case POINT_TYPE_WP: |
193 | WPCount++; |
||
194 | PointCount++; |
||
195 | break; |
||
516 | holgerb | 196 | |
295 | killagreg | 197 | case POINT_TYPE_POI: |
198 | POICount++; |
||
199 | PointCount++; |
||
200 | break; |
||
601 | holgerb | 201 | case POINT_TYPE_FS: |
202 | FsPointCnt++; |
||
203 | PointCount++; |
||
204 | break; |
||
802 | holgerb | 205 | case POINT_TYPE_FLYZONE: |
206 | FlyzonePointCnt++; |
||
207 | PointCount++; |
||
208 | break; |
||
295 | killagreg | 209 | } |
516 | holgerb | 210 | break; |
211 | |||
785 | holgerb | 212 | case POINT_TYPE_LAND: // was a landing point |
295 | killagreg | 213 | switch(pPoint->Type) |
214 | { |
||
215 | case POINT_TYPE_INVALID: |
||
216 | WPCount--; |
||
217 | PointCount--; |
||
218 | break; |
||
219 | default: |
||
785 | holgerb | 220 | case POINT_TYPE_LAND: |
221 | break; |
||
295 | killagreg | 222 | case POINT_TYPE_WP: |
802 | holgerb | 223 | FsPointCnt--; // the landing point is also a Failsafe-Pt |
785 | holgerb | 224 | break; |
225 | case POINT_TYPE_FS: |
||
226 | FsPointCnt++; |
||
227 | WPCount--; |
||
228 | break; |
||
229 | case POINT_TYPE_POI: |
||
230 | POICount++; |
||
231 | WPCount--; |
||
232 | break; |
||
802 | holgerb | 233 | case POINT_TYPE_FLYZONE: |
234 | FlyzonePointCnt++; |
||
235 | WPCount--; |
||
236 | break; |
||
785 | holgerb | 237 | } |
238 | break; |
||
239 | case POINT_TYPE_WP: |
||
240 | switch(pPoint->Type) |
||
241 | { |
||
242 | case POINT_TYPE_INVALID: |
||
243 | WPCount--; |
||
244 | PointCount--; |
||
245 | break; |
||
246 | |||
247 | default: |
||
248 | case POINT_TYPE_LAND: |
||
802 | holgerb | 249 | FsPointCnt++; // the landing point is also a Failsafe-Pt |
785 | holgerb | 250 | break; |
251 | case POINT_TYPE_WP: |
||
295 | killagreg | 252 | //nothing to do |
253 | break; |
||
601 | holgerb | 254 | case POINT_TYPE_FS: |
255 | FsPointCnt++; |
||
256 | WPCount--; |
||
257 | break; |
||
295 | killagreg | 258 | case POINT_TYPE_POI: |
259 | POICount++; |
||
260 | WPCount--; |
||
261 | break; |
||
802 | holgerb | 262 | case POINT_TYPE_FLYZONE: |
263 | FlyzonePointCnt++; |
||
264 | WPCount--; |
||
265 | break; |
||
295 | killagreg | 266 | } |
267 | break; |
||
802 | holgerb | 268 | case POINT_TYPE_FLYZONE: |
269 | switch(pPoint->Type) |
||
270 | { |
||
271 | case POINT_TYPE_INVALID: |
||
272 | FlyzonePointCnt--; |
||
273 | PointCount--; |
||
274 | break; |
||
275 | default: |
||
276 | case POINT_TYPE_LAND: |
||
277 | FsPointCnt++; // the landing point is also a Failsafe-Pt |
||
278 | break; |
||
279 | case POINT_TYPE_WP: |
||
280 | WPCount++; |
||
281 | FlyzonePointCnt--; |
||
282 | break; |
||
283 | case POINT_TYPE_FLYZONE: |
||
284 | //nothing to do |
||
285 | break; |
||
286 | case POINT_TYPE_FS: |
||
287 | FsPointCnt++; |
||
288 | FlyzonePointCnt--; |
||
289 | break; |
||
290 | case POINT_TYPE_POI: |
||
291 | POICount++; |
||
292 | FlyzonePointCnt--; |
||
293 | break; |
||
294 | } |
||
295 | break; |
||
516 | holgerb | 296 | |
295 | killagreg | 297 | case POINT_TYPE_POI: // was a poi |
298 | switch(pPoint->Type) |
||
299 | { |
||
300 | case POINT_TYPE_INVALID: |
||
301 | POICount--; |
||
302 | PointCount--; |
||
303 | break; |
||
802 | holgerb | 304 | case POINT_TYPE_FS: |
305 | FsPointCnt++; |
||
306 | POICount--; |
||
307 | break; |
||
295 | killagreg | 308 | |
785 | holgerb | 309 | case POINT_TYPE_LAND: |
310 | FsPointCnt++; // break fehlt absichtlich |
||
295 | killagreg | 311 | case POINT_TYPE_WP: |
312 | WPCount++; |
||
313 | POICount--; |
||
314 | break; |
||
802 | holgerb | 315 | case POINT_TYPE_FLYZONE: |
316 | FlyzonePointCnt++; |
||
601 | holgerb | 317 | POICount--; |
318 | break; |
||
295 | killagreg | 319 | case POINT_TYPE_POI: |
320 | default: |
||
321 | // nothing to do |
||
322 | break; |
||
323 | } |
||
601 | holgerb | 324 | case POINT_TYPE_FS: // was a Failsafe |
325 | switch(pPoint->Type) |
||
326 | { |
||
327 | case POINT_TYPE_INVALID: |
||
328 | FsPointCnt--; |
||
329 | PointCount--; |
||
330 | break; |
||
785 | holgerb | 331 | case POINT_TYPE_LAND: |
802 | holgerb | 332 | FsPointCnt++; // (wird gleich wieder abgezogen) |
601 | holgerb | 333 | case POINT_TYPE_WP: |
334 | WPCount++; |
||
335 | FsPointCnt--; |
||
336 | break; |
||
337 | case POINT_TYPE_POI: |
||
338 | POICount++; |
||
339 | FsPointCnt--; |
||
340 | break; |
||
802 | holgerb | 341 | case POINT_TYPE_FLYZONE: |
342 | FlyzonePointCnt++; |
||
343 | FsPointCnt--; |
||
344 | break; |
||
601 | holgerb | 345 | case POINT_TYPE_FS: |
346 | break; |
||
347 | default: |
||
348 | // nothing to do |
||
349 | break; |
||
350 | } |
||
516 | holgerb | 351 | break; |
277 | killagreg | 352 | } |
516 | holgerb | 353 | memcpy(&PointList[pPoint->Index-1], pPoint, sizeof(Point_t)); // copy data to list entry |
295 | killagreg | 354 | NaviData.WaypointNumber = WPCount; |
355 | return pPoint->Index; |
||
41 | ingob | 356 | } |
296 | killagreg | 357 | else return(0); |
41 | ingob | 358 | } |
359 | |||
227 | killagreg | 360 | // returns the pointer to the first waypoint within the list |
785 | holgerb | 361 | Point_t* PointList_WPBegin(u32 start) |
41 | ingob | 362 | { |
786 | holgerb | 363 | u8 i, wp_nr = 0; |
227 | killagreg | 364 | WPIndex = 0; // set list position invalid |
295 | killagreg | 365 | |
283 | holgerb | 366 | if(WPActive == FALSE) return(NULL); |
295 | killagreg | 367 | |
277 | killagreg | 368 | POIIndex = 0; // set invalid POI |
785 | holgerb | 369 | if(PointCount > start) |
152 | killagreg | 370 | { |
225 | killagreg | 371 | // search for first wp in list |
786 | holgerb | 372 | for(i = 0; i <MAX_LIST_LEN; i++) |
225 | killagreg | 373 | { |
785 | holgerb | 374 | if(((PointList[i].Type == POINT_TYPE_WP)||(PointList[i].Type == POINT_TYPE_LAND)) && (PointList[i].Position.Status != INVALID)) // jump over POIs and FS-Positions |
225 | killagreg | 375 | { |
227 | killagreg | 376 | WPIndex = i + 1; |
786 | holgerb | 377 | wp_nr++; // count the number of scipped WPs to make sure that the Index in the NaviData is correct |
378 | if(i >= start) break; |
||
225 | killagreg | 379 | } |
380 | } |
||
277 | killagreg | 381 | if(WPIndex) // found a WP in the list |
382 | { |
||
786 | holgerb | 383 | NaviData.WaypointIndex = wp_nr; |
549 | holgerb | 384 | NewWaypointsReceived = 1; // activates the Waypoint list as soon as CH is started |
277 | killagreg | 385 | // update index to POI |
280 | killagreg | 386 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
516 | holgerb | 387 | else POIIndex = 0; |
277 | killagreg | 388 | } |
389 | else // some points in the list but no WP found |
||
390 | { |
||
280 | killagreg | 391 | NaviData.WaypointIndex = 0; |
277 | killagreg | 392 | //Check for an existing POI |
295 | killagreg | 393 | for(i = 0; i < MAX_LIST_LEN; i++) |
277 | killagreg | 394 | { |
280 | killagreg | 395 | if((PointList[i].Type == POINT_TYPE_POI) && (PointList[i].Position.Status != INVALID)) |
277 | killagreg | 396 | { |
397 | POIIndex = i + 1; |
||
398 | break; |
||
399 | } |
||
400 | } |
||
401 | } |
||
152 | killagreg | 402 | } |
277 | killagreg | 403 | else // no point in the list |
152 | killagreg | 404 | { |
516 | holgerb | 405 | POIIndex = 0; |
406 | NaviData.WaypointIndex = 0; |
||
227 | killagreg | 407 | } |
295 | killagreg | 408 | |
409 | if(WPIndex) return(&(PointList[WPIndex-1])); |
||
410 | else return(NULL); |
||
41 | ingob | 411 | } |
412 | |||
225 | killagreg | 413 | // returns the last waypoint |
280 | killagreg | 414 | Point_t* PointList_WPEnd(void) |
151 | killagreg | 415 | { |
516 | holgerb | 416 | |
277 | killagreg | 417 | u8 i; |
227 | killagreg | 418 | WPIndex = 0; // set list position invalid |
277 | killagreg | 419 | POIIndex = 0; // set invalid |
283 | holgerb | 420 | |
280 | killagreg | 421 | if(WPActive == FALSE) return(NULL); |
277 | killagreg | 422 | |
280 | killagreg | 423 | if(PointCount > 0) |
151 | killagreg | 424 | { |
227 | killagreg | 425 | // search backward! |
295 | killagreg | 426 | for(i = 1; i <= MAX_LIST_LEN; i++) |
225 | killagreg | 427 | { |
785 | holgerb | 428 | if(((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_WP) || (PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_LAND)) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID)) |
516 | holgerb | 429 | { |
295 | killagreg | 430 | WPIndex = MAX_LIST_LEN - i + 1; |
225 | killagreg | 431 | break; |
432 | } |
||
433 | } |
||
277 | killagreg | 434 | if(WPIndex) // found a WP within the list |
435 | { |
||
280 | killagreg | 436 | NaviData.WaypointIndex = WPCount; |
437 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
||
516 | holgerb | 438 | else POIIndex = 0; |
277 | killagreg | 439 | } |
278 | killagreg | 440 | else // list contains some points but no WP in the list |
277 | killagreg | 441 | { |
442 | // search backward for a POI! |
||
295 | killagreg | 443 | for(i = 1; i <= MAX_LIST_LEN; i++) |
277 | killagreg | 444 | { |
295 | killagreg | 445 | if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_POI) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID)) |
516 | holgerb | 446 | { |
295 | killagreg | 447 | POIIndex = MAX_LIST_LEN - i + 1; |
277 | killagreg | 448 | break; |
449 | } |
||
450 | } |
||
516 | holgerb | 451 | NaviData.WaypointIndex = 0; |
277 | killagreg | 452 | } |
151 | killagreg | 453 | } |
277 | killagreg | 454 | else // no point in the list |
227 | killagreg | 455 | { |
280 | killagreg | 456 | POIIndex = 0; |
457 | NaviData.WaypointIndex = 0; |
||
227 | killagreg | 458 | } |
295 | killagreg | 459 | if(WPIndex) return(&(PointList[WPIndex-1])); |
460 | else return(NULL); |
||
151 | killagreg | 461 | } |
462 | |||
41 | ingob | 463 | // returns a pointer to the next waypoint or NULL if the end of the list has been reached |
280 | killagreg | 464 | Point_t* PointList_WPNext(void) |
41 | ingob | 465 | { |
227 | killagreg | 466 | u8 wp_found = 0; |
280 | killagreg | 467 | if(WPActive == FALSE) return(NULL); |
516 | holgerb | 468 | |
295 | killagreg | 469 | if(WPIndex < MAX_LIST_LEN) // if there is a next entry in the list |
41 | ingob | 470 | { |
227 | killagreg | 471 | u8 i; |
295 | killagreg | 472 | for(i = WPIndex; i < MAX_LIST_LEN; i++) // start search for next at next list entry |
225 | killagreg | 473 | { |
785 | holgerb | 474 | if(((PointList[i].Type == POINT_TYPE_WP) || (PointList[i].Type == POINT_TYPE_LAND)) && (PointList[i].Position.Status != INVALID)) // jump over POIs and FS-Positions |
225 | killagreg | 475 | { |
227 | killagreg | 476 | wp_found = i+1; |
225 | killagreg | 477 | break; |
478 | } |
||
601 | holgerb | 479 | /* |
480 | else |
||
481 | if((PointList[i].Type == POINT_TYPE_FS) && (PointList[i].Position.Status != INVALID)) // jump over POIs |
||
482 | { |
||
483 | GPSPos_Copy(&(PointList[i].Position), &GPS_FailsafePosition); |
||
484 | } |
||
485 | */ |
||
225 | killagreg | 486 | } |
41 | ingob | 487 | } |
227 | killagreg | 488 | if(wp_found) |
489 | { |
||
490 | WPIndex = wp_found; // update list position |
||
280 | killagreg | 491 | NaviData.WaypointIndex++; |
492 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
||
227 | killagreg | 493 | else POIIndex = 0; |
280 | killagreg | 494 | return(&(PointList[WPIndex-1])); // return pointer to this waypoint |
227 | killagreg | 495 | } |
516 | holgerb | 496 | else |
280 | killagreg | 497 | { // no next wp found |
516 | holgerb | 498 | NaviData.WaypointIndex = 0; |
277 | killagreg | 499 | POIIndex = 0; |
500 | return(NULL); |
||
501 | } |
||
516 | holgerb | 502 | } |
280 | killagreg | 503 | |
504 | void PointList_WPActive(u8 set) |
||
505 | { |
||
295 | killagreg | 506 | if(set) |
516 | holgerb | 507 | { |
295 | killagreg | 508 | WPActive = TRUE; |
785 | holgerb | 509 | PointList_WPBegin(0); // updates POI index |
295 | killagreg | 510 | } |
511 | else |
||
512 | { |
||
513 | WPActive = FALSE; |
||
514 | POIIndex = 0; // disable POI also |
||
515 | } |
||
280 | killagreg | 516 | } |
516 | holgerb | 517 | |
280 | killagreg | 518 | Point_t* PointList_GetPOI(void) |
224 | killagreg | 519 | { |
516 | holgerb | 520 | return PointList_GetAt(POIIndex); |
224 | killagreg | 521 | } |
522 | |||
513 | killagreg | 523 | |
490 | killagreg | 524 | #define LINE_MAX 70 |
525 | #define WP_FILE_VERSION_COMPATIBLE 3 |
||
513 | killagreg | 526 | |
527 | u8 PointList_Save(u8 * filename, u8* listname, u8 overwride) |
||
490 | killagreg | 528 | { |
529 | File_t *fp; |
||
495 | killagreg | 530 | s8 wpline[LINE_MAX]; |
531 | u8 retval = WPL_ERROR; |
||
513 | killagreg | 532 | |
767 | holgerb | 533 | UART1_PutString("\r\n Save WPL..."); |
490 | killagreg | 534 | |
535 | if(Fat16_IsValid()) |
||
536 | { // check if wpl file is existing |
||
513 | killagreg | 537 | if(fexist_(filename)) |
495 | killagreg | 538 | { //file is existent |
516 | holgerb | 539 | if(!(overwride)) |
495 | killagreg | 540 | { |
541 | UART1_PutString("Error: file exist!\r\n"); |
||
542 | return(WPL_FILEEXIST); |
||
516 | holgerb | 543 | } |
495 | killagreg | 544 | } |
513 | killagreg | 545 | fp = fopen_(filename, 'w'); // try to open the file |
490 | killagreg | 546 | if(fp == NULL) |
547 | { |
||
548 | UART1_PutString("ERROR: Creating waypoint file!\r\n"); |
||
549 | return(retval); |
||
550 | } |
||
551 | // Create general section and key entries |
||
552 | fputs_("[General]\r\n", fp); |
||
516 | holgerb | 553 | sprintf(wpline, "Name=%s\r\n", listname); |
494 | killagreg | 554 | fputs_(wpline, fp); |
516 | holgerb | 555 | sprintf(wpline, "FileVersion=%d\r\n", WP_FILE_VERSION_COMPATIBLE); |
490 | killagreg | 556 | fputs_(wpline, fp); |
557 | sprintf(wpline, "NumberOfWaypoints=%d\r\n", PointCount); |
||
558 | fputs_(wpline, fp); |
||
559 | // dump all points if existent |
||
560 | if(PointCount) |
||
561 | { |
||
562 | u8 i, u8_1; |
||
563 | s32 i32_1, i32_2; |
||
504 | holgerb | 564 | NewWPL_Name = 1; |
490 | killagreg | 565 | for (i = 0; i < PointCount; i++) |
566 | { |
||
567 | sprintf(wpline, "[Point%d]\r\n",PointList[i].Index); |
||
568 | fputs_(wpline, fp); |
||
569 | // write latitude in deg |
||
570 | if(PointList[i].Position.Latitude < 0) u8_1 = '-'; |
||
571 | else u8_1 = '+'; |
||
572 | i32_1 = abs(PointList[i].Position.Latitude)/10000000L; |
||
573 | i32_2 = abs(PointList[i].Position.Latitude)%10000000L; |
||
574 | sprintf(wpline, "Latitude=%c%ld.%07ld\r\n", u8_1, i32_1, i32_2); |
||
575 | fputs_(wpline, fp); |
||
576 | // write longitude in deg |
||
577 | if(PointList[i].Position.Longitude < 0) u8_1 = '-'; |
||
578 | else u8_1 = '+'; |
||
579 | i32_1 = abs(PointList[i].Position.Longitude)/10000000L; |
||
580 | i32_2 = abs(PointList[i].Position.Longitude)%10000000L; |
||
581 | sprintf(wpline, "Longitude=%c%ld.%07ld\r\n", u8_1, i32_1, i32_2); |
||
582 | fputs_(wpline, fp); |
||
583 | // write tolerace radius in m |
||
584 | sprintf(wpline, "Radius=%d\r\n", PointList[i].ToleranceRadius); |
||
585 | fputs_(wpline, fp); |
||
586 | // write altitude in m |
||
587 | if(PointList[i].Position.Altitude < 0) u8_1 = '-'; |
||
588 | else u8_1 = '+'; |
||
589 | if(PointList[i].Type == POINT_TYPE_POI) |
||
590 | { |
||
591 | i32_1 = abs(PointList[i].Position.Altitude)/100L; // cm --> m |
||
592 | i32_2 = abs(PointList[i].Position.Altitude)%100L; |
||
593 | } |
||
594 | else |
||
595 | { |
||
596 | i32_1 = abs(PointList[i].Position.Altitude)/10L; // dm --> m |
||
597 | i32_2 = abs(PointList[i].Position.Altitude)%10L; |
||
598 | } |
||
599 | sprintf(wpline, "Altitude=%c%ld.%01ld\r\n", u8_1, i32_1, i32_2); |
||
600 | fputs_(wpline, fp); |
||
601 | // write climb rate in 0.1 m/s |
||
602 | sprintf(wpline, "ClimbRate=%d\r\n", PointList[i].AltitudeRate); |
||
603 | fputs_(wpline, fp); |
||
604 | // write hold time in s |
||
605 | sprintf(wpline, "DelayTime=%d\r\n", PointList[i].HoldTime); |
||
606 | fputs_(wpline, fp); |
||
607 | // write event channel value |
||
608 | sprintf(wpline, "WP_Event_Channel_Value=%d\r\n", PointList[i].WP_EventChannelValue); |
||
609 | fputs_(wpline, fp); |
||
610 | // write heading in deg (0= nothing, neg. values index to poi) |
||
611 | sprintf(wpline, "Heading=%d\r\n", PointList[i].Heading); |
||
612 | fputs_(wpline, fp); |
||
613 | // write speed in 0.1 m/s |
||
614 | sprintf(wpline, "Speed=%d\r\n", PointList[i].Speed); |
||
615 | fputs_(wpline, fp); |
||
616 | // write cam angle in degree (255 -> POI-Automatic) |
||
617 | sprintf(wpline, "CAM-Nick=%d\r\n", PointList[i].CamAngle); |
||
618 | fputs_(wpline, fp); |
||
619 | // write point type |
||
620 | sprintf(wpline, "Type=%d\r\n", PointList[i].Type + 1); |
||
516 | holgerb | 621 | fputs_(wpline, fp); |
622 | // write prefix |
||
490 | killagreg | 623 | sprintf(wpline, "Prefix=%s\r\n", PointList[i].Name); |
624 | fputs_(wpline, fp); |
||
642 | holgerb | 625 | sprintf(wpline, "AutoTrigger=%d\r\n", PointList[i].AutoPhotoDistance); |
626 | fputs_(wpline, fp); |
||
490 | killagreg | 627 | } // EOF loop over all points |
628 | } // EOF if(PointCount) |
||
629 | if(EOF == fclose_(fp)) |
||
630 | { |
||
631 | UART1_PutString("failed!\r\n"); |
||
632 | } |
||
633 | else |
||
634 | { |
||
635 | UART1_PutString("ok\r\n"); |
||
495 | killagreg | 636 | retval = WPL_OK; |
516 | holgerb | 637 | } |
490 | killagreg | 638 | } // EOF if(Fat16_IsValid()) |
516 | holgerb | 639 | else |
497 | killagreg | 640 | { |
641 | UART1_PutString("no file system found!\r\n"); |
||
642 | retval = WPL_NO_SDCARD_FOUND; |
||
643 | } |
||
490 | killagreg | 644 | return(retval); |
645 | } |
||
646 | |||
519 | holgerb | 647 | u8 PointList_Load(u8 * filename, u8* listname, u8 listnamelen, u8 use_preset_speed) |
490 | killagreg | 648 | { |
649 | File_t *fp; |
||
496 | killagreg | 650 | s8 wpline[LINE_MAX]; |
651 | u8 retval = WPL_ERROR; |
||
516 | holgerb | 652 | |
490 | killagreg | 653 | s8 *name, *value; |
654 | u8 i; |
||
655 | |||
656 | u8 IsGeneralSection = 0; |
||
657 | u8 IsPointSection = 0; |
||
658 | u8 WPNumber = 0; |
||
498 | killagreg | 659 | |
660 | // clear point list first |
||
661 | PointList_Clear(); |
||
517 | holgerb | 662 | HeadingOld = -1; // updates the direction if the new direction is the same like last time |
767 | holgerb | 663 | UART1_PutString("\r\n Read "); |
516 | holgerb | 664 | UART1_PutString(filename); |
490 | killagreg | 665 | UART1_PutString("..."); |
666 | |||
667 | if(Fat16_IsValid()) |
||
668 | { // check if wpl file is existing |
||
513 | killagreg | 669 | fp = fopen_(filename, 'r'); // try to open the file |
490 | killagreg | 670 | if(fp == NULL) |
671 | { |
||
672 | UART1_PutString("ERROR: Reading waypoint file!\r\n"); |
||
496 | killagreg | 673 | return(retval); |
490 | killagreg | 674 | } |
675 | // read all lines from file |
||
676 | while(fgets_(wpline, LINE_MAX, fp) != 0) |
||
677 | { |
||
678 | if ( // ignorelines starting with \r,\n,' ',';','#' |
||
679 | (wpline[0] != '\n') && |
||
680 | (wpline[0] != '\r') && |
||
681 | (wpline[0] != ' ' ) && |
||
682 | (wpline[0] != ';' ) && |
||
683 | (wpline[0] != '#' ) |
||
684 | ) |
||
685 | { |
||
686 | // check for section line found |
||
687 | if(wpline[0] == '[') |
||
688 | { |
||
689 | // next section found |
||
690 | IsGeneralSection = 0; |
||
691 | IsPointSection = 0; |
||
692 | |||
693 | name = strtok(&wpline[1], "]"); |
||
694 | if(name != NULL) // if section name |
||
695 | { |
||
696 | // check section type |
||
697 | for(i=0; name[i]; i++) name[i] = toupper(name[i]); // convert to upper case |
||
698 | |||
699 | if(strncmp(name, "POINT", 5) == 0) |
||
700 | { |
||
701 | IsPointSection = (u8)atoi(&name[5]); |
||
702 | PointCount++; |
||
703 | } |
||
704 | else if(strcmp(name, "GENERAL") == 0) |
||
705 | { |
||
706 | IsGeneralSection = 1; |
||
707 | } |
||
708 | else |
||
709 | { |
||
710 | UART1_PutString("Unknown section: "); |
||
711 | UART1_PutString(name); |
||
712 | UART1_PutString("\r\n"); |
||
713 | } |
||
714 | } |
||
715 | } // EOF section line |
||
716 | else |
||
717 | { // look for key entrys of each sections |
||
718 | name = strtok(wpline, "="); // get name |
||
719 | value = strtok(NULL, "="); // get value |
||
720 | if ((name != NULL) && (value != NULL)) |
||
721 | { |
||
722 | for(i=0; name[i]; i++) name[i] = toupper(name[i]); // convert to upper case |
||
723 | if(IsPointSection && (IsPointSection <= WPNumber)) |
||
724 | { |
||
725 | if(strcmp(name, "LATITUDE") == 0) |
||
726 | { |
||
727 | PointList[IsPointSection-1].Position.Latitude = (s32)(atof(value) * 1E7); |
||
728 | } |
||
729 | else if(strcmp(name, "LONGITUDE") == 0) |
||
730 | { |
||
731 | PointList[IsPointSection-1].Position.Longitude = (s32)(atof(value) * 1E7); |
||
732 | } |
||
733 | else if(strcmp(name, "RADIUS") == 0) |
||
734 | { |
||
735 | PointList[IsPointSection-1].ToleranceRadius = (u8)atoi(value); |
||
736 | } |
||
737 | else if(strcmp(name, "ALTITUDE") == 0) |
||
738 | { |
||
739 | PointList[IsPointSection-1].Position.Altitude = (s32)(atof(value) * 100.0); // in cm |
||
740 | PointList[IsPointSection-1].Position.Status = NEWDATA; |
||
741 | } |
||
742 | else if(strcmp(name, "CLIMBRATE") == 0) |
||
743 | { |
||
744 | PointList[IsPointSection-1].AltitudeRate = (u8)atoi(value); |
||
745 | } |
||
746 | else if(strcmp(name, "DELAYTIME") == 0) |
||
747 | { |
||
748 | PointList[IsPointSection-1].HoldTime = (u8)atoi(value); |
||
749 | } |
||
750 | else if(strcmp(name, "WP_EVENT_CHANNEL_VALUE") == 0) |
||
751 | { |
||
752 | PointList[IsPointSection-1].WP_EventChannelValue = (u8)atoi(value); |
||
753 | } |
||
754 | else if(strcmp(name, "HEADING") == 0) |
||
755 | { |
||
756 | PointList[IsPointSection-1].Heading = (s16)atoi(value); |
||
757 | } |
||
758 | else if(strcmp(name, "SPEED") == 0) |
||
759 | { |
||
519 | holgerb | 760 | if(use_preset_speed) PointList[IsPointSection-1].Speed = use_preset_speed; |
761 | else PointList[IsPointSection-1].Speed = (u8)atoi(value); |
||
490 | killagreg | 762 | } |
763 | else if(strcmp(name, "CAM-NICK") == 0) |
||
764 | { |
||
765 | PointList[IsPointSection-1].CamAngle = (u8)atoi(value); |
||
766 | } |
||
767 | else if(strcmp(name, "TYPE") == 0) |
||
768 | { |
||
769 | PointList[IsPointSection-1].Type = (u8)atoi(value); |
||
770 | if(PointList[IsPointSection-1].Type > 0) PointList[IsPointSection-1].Type--; // index shift |
||
771 | else PointList[IsPointSection-1].Type = POINT_TYPE_INVALID; |
||
516 | holgerb | 772 | |
490 | killagreg | 773 | switch(PointList[IsPointSection-1].Type) |
774 | { |
||
785 | holgerb | 775 | case POINT_TYPE_LAND: |
776 | FsPointCnt++; // break fehlt absichtlich |
||
490 | killagreg | 777 | case POINT_TYPE_WP: |
778 | // this works only if altitude key is set before point type key in WPL file !! |
||
516 | holgerb | 779 | PointList[IsPointSection-1].Position.Altitude /= 10; // dm only for WPs |
490 | killagreg | 780 | WPCount++; |
781 | break; |
||
601 | holgerb | 782 | case POINT_TYPE_FS: |
783 | FsPointCnt++; |
||
784 | break; |
||
490 | killagreg | 785 | case POINT_TYPE_POI: |
786 | POICount++; |
||
787 | break; |
||
802 | holgerb | 788 | case POINT_TYPE_FLYZONE: |
789 | FlyzonePointCnt++; |
||
790 | break; |
||
490 | killagreg | 791 | } |
792 | } |
||
793 | else if(strcmp(name, "PREFIX") == 0) |
||
794 | { |
||
795 | strncpy(PointList[IsPointSection-1].Name, value, 4); |
||
796 | PointList[IsPointSection-1].Name[3] = 0; // Terminate string |
||
797 | } |
||
642 | holgerb | 798 | else if(strcmp(name, "AUTOTRIGGER") == 0) |
799 | { |
||
800 | PointList[IsPointSection-1].AutoPhotoDistance = (u8)atoi(value); |
||
801 | } |
||
490 | killagreg | 802 | else |
803 | { |
||
804 | UART1_PutString("Unknown key: "); |
||
805 | UART1_PutString(name); |
||
806 | UART1_PutString("\r\n"); |
||
516 | holgerb | 807 | } |
490 | killagreg | 808 | } // EOF point section |
809 | else if(IsGeneralSection) |
||
810 | { |
||
811 | if(strcmp(name, "NUMBEROFWAYPOINTS") == 0) |
||
516 | holgerb | 812 | { |
490 | killagreg | 813 | WPNumber = (u8)atoi(value); |
814 | if(!WPNumber) // no waypoints in file |
||
815 | { |
||
516 | holgerb | 816 | return(WPL_NO_WAYPOINTS); // we are done here |
490 | killagreg | 817 | } |
818 | else if(WPNumber > MAX_LIST_LEN) // number o points larger than ram list |
||
819 | { |
||
514 | holgerb | 820 | UART1_PutString("To many points!"); |
497 | killagreg | 821 | return(WPL_ERROR); |
516 | holgerb | 822 | } |
490 | killagreg | 823 | } |
824 | else if (strcmp(name, "FILEVERSION") == 0) |
||
825 | { |
||
826 | if((u8)atoi(value) != WP_FILE_VERSION_COMPATIBLE) |
||
827 | { |
||
496 | killagreg | 828 | PointList_Clear(); |
490 | killagreg | 829 | UART1_PutString("Bad file version!\r\n"); |
516 | holgerb | 830 | return(WPL_ERROR); |
490 | killagreg | 831 | } |
832 | } |
||
495 | killagreg | 833 | else if (strcmp(name, "NAME") == 0) |
834 | { |
||
513 | killagreg | 835 | if(listname) |
498 | killagreg | 836 | { |
513 | killagreg | 837 | u8 len = strlen(value); |
838 | if(len) |
||
839 | { |
||
840 | if(value[len-1] == '\r') |
||
841 | { |
||
842 | value[len-1] = 0; |
||
540 | holgerb | 843 | // len--; |
513 | killagreg | 844 | } |
845 | } |
||
846 | if(len > listnamelen) len = listnamelen; |
||
847 | if(len) |
||
848 | { |
||
849 | value[len-1] = 0; // terminate string |
||
850 | if(listname) memcpy(listname, value, len); |
||
851 | } |
||
852 | NewWPL_Name = 1; |
||
498 | killagreg | 853 | } |
495 | killagreg | 854 | } |
490 | killagreg | 855 | else |
856 | { |
||
857 | UART1_PutString("Unknown key: "); |
||
858 | UART1_PutString(name); |
||
859 | UART1_PutString("\r\n"); |
||
860 | } |
||
861 | } // EOF general section |
||
862 | } // EOF valid key entry |
||
863 | } // EOF key entry line |
||
864 | } // valid line |
||
865 | } // EOF loop over all lines |
||
866 | fclose_(fp); |
||
867 | NaviData.WaypointNumber = WPCount; |
||
516 | holgerb | 868 | retval = WPL_OK; |
869 | UART1_PutString("ok\r\n"); |
||
490 | killagreg | 870 | } // EOF if(Fat16_IsValid()) |
516 | holgerb | 871 | else |
497 | killagreg | 872 | { |
873 | UART1_PutString("no file system found!\r\n"); |
||
874 | retval = WPL_NO_SDCARD_FOUND; |
||
516 | holgerb | 875 | } |
490 | killagreg | 876 | return(retval); |
491 | killagreg | 877 | } |
490 | killagreg | 878 | |
513 | killagreg | 879 | // load actual point list from SD card |
880 | u8 PointList_ReadFromFile(WPL_Store_t * pWPL_Store) |
||
881 | { |
||
516 | holgerb | 882 | u8 filename[30]; |
513 | killagreg | 883 | |
884 | pWPL_Store->Name[0] = 0; // clear current list name |
||
885 | |||
886 | // user absolute path, i.e. leading / |
||
887 | if(pWPL_Store->Index == 0) // index 0 looks for a default WPL file in the root |
||
888 | { |
||
516 | holgerb | 889 | sprintf(filename, "/default.wpl"); |
513 | killagreg | 890 | } |
891 | else |
||
892 | { |
||
893 | sprintf(filename, "/WPL/list_%03d.wpl", pWPL_Store->Index); |
||
894 | } |
||
519 | holgerb | 895 | return PointList_Load(filename, pWPL_Store->Name, sizeof(pWPL_Store->Name),0); |
513 | killagreg | 896 | } |
897 | |||
898 | // save actual point list to SD card |
||
899 | u8 PointList_WriteToFile(WPL_Store_t * pWPL_Store) |
||
900 | { |
||
901 | u8 filename[30]; |
||
516 | holgerb | 902 | |
903 | |||
513 | killagreg | 904 | if(PointCount == 0) return(WPL_NO_WAYPOINTS); |
516 | holgerb | 905 | // user absolute path, i.e. leading / |
513 | killagreg | 906 | if(pWPL_Store->Index == 0) |
907 | { |
||
908 | sprintf(filename, "/default.wpl"); |
||
909 | } |
||
910 | else |
||
911 | { |
||
912 | sprintf(filename, "/WPL/list_%03d.wpl", pWPL_Store->Index); |
||
913 | } |
||
914 | return PointList_Save(filename, pWPL_Store->Name, pWPL_Store->OverwriteFile); |
||
915 | } |
||
916 | |||
917 | |||
516 | holgerb | 918 | // save actual gps positiin and heading to file |
513 | killagreg | 919 | u8 PointList_SaveSinglePoint(WPL_Store_t * pWPL_Store) |
920 | { |
||
921 | u8 retval = WPL_ERROR; |
||
922 | u8 filename[30]; |
||
923 | Point_t WP; |
||
924 | |||
767 | holgerb | 925 | UART1_PutString("\r\n write single point\r\n"); |
516 | holgerb | 926 | if(GPSData.Position.Status == INVALID) |
927 | { |
||
767 | holgerb | 928 | UART1_PutString("ERROR: No GPS - Fix\r\n"); |
514 | holgerb | 929 | return(retval); |
516 | holgerb | 930 | } |
513 | killagreg | 931 | |
932 | // clear current point list |
||
933 | PointList_Clear(); |
||
934 | // prepare WP at current position |
||
519 | holgerb | 935 | |
737 | holgerb | 936 | if(NCFlags & NC_FLAG_FREE || NaviData.TargetPositionDeviation.Distance_dm > 7*10) |
519 | holgerb | 937 | { // take actual position |
938 | GPSPos_Copy(&GPSData.Position, &(WP.Position)); |
||
939 | } |
||
940 | else |
||
941 | { // take last target position |
||
942 | GPSPos_Copy(&NaviData.TargetPosition, &(WP.Position)); |
||
943 | } |
||
944 | |||
513 | killagreg | 945 | GPSPos_Copy(&GPSData.Position, &(WP.Position)); |
946 | // set heading |
||
545 | holgerb | 947 | WP.Heading = (CompassSetpointCorrected/10 + Parameter.CamOrientation * 15) % 360; |
513 | killagreg | 948 | if(WP.Heading == 0) WP.Heading = 360; |
519 | holgerb | 949 | WP.ToleranceRadius = 120; // 12m |
950 | WP.HoldTime = 2; |
||
513 | killagreg | 951 | WP.Index = 1; |
952 | WP.Type = POINT_TYPE_WP; |
||
695 | holgerb | 953 | WP.WP_EventChannelValue = 100; |
576 | holgerb | 954 | if(FC.StatusFlags & FC_STATUS_FLY && ((FromFC_VarioCharacter != ' ') || (SimulationFlags & SIMULATION_ACTIVE))) // only in flight and if the Altitude control is enabled |
516 | holgerb | 955 | { |
519 | holgerb | 956 | WP.AltitudeRate = 255; // Auto |
957 | WP.Position.Altitude = NaviData.SetpointAltitude / 2; |
||
516 | holgerb | 958 | } |
959 | else |
||
514 | holgerb | 960 | { |
516 | holgerb | 961 | WP.AltitudeRate = 0; |
962 | WP.Position.Altitude = 0; |
||
514 | holgerb | 963 | } |
519 | holgerb | 964 | WP.Speed = 50; // beim Laden wird der Wert nochmal neu gesetzt |
513 | killagreg | 965 | WP.CamAngle = 0; |
521 | holgerb | 966 | WP.Name[0] = 'S'; |
967 | WP.Name[1] = 'P'; |
||
968 | WP.Name[2] = 'T'; |
||
969 | WP.Name[3] = 0; |
||
513 | killagreg | 970 | // add this point to wp list |
971 | PointList_SetAt(&WP); |
||
514 | holgerb | 972 | |
973 | sprintf(filename, "/POINT/POINT%03d.wpl", pWPL_Store->Index); |
||
516 | holgerb | 974 | UART1_PutString(filename); |
514 | holgerb | 975 | sprintf(pWPL_Store->Name, "POINT%03d ", pWPL_Store->Index); |
513 | killagreg | 976 | retval = PointList_Save(filename, pWPL_Store->Name, 1); |
514 | holgerb | 977 | |
978 | // clear current point list |
||
519 | holgerb | 979 | if((NC_GPS_ModeCharacter != 'w') && (NC_GPS_ModeCharacter != 'W')) PointList_Clear(); |
549 | holgerb | 980 | else // es ist gearde ein Wegpunktflug aktiv -> updaten |
519 | holgerb | 981 | { |
982 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
||
785 | holgerb | 983 | GPS_pWaypoint = PointList_WPBegin(0); // updates POI index |
519 | holgerb | 984 | } |
985 | |||
513 | killagreg | 986 | return(retval); |
987 | } |
||
988 | // load target gps posititon and heading from file |
||
989 | u8 PointList_LoadSinglePoint(WPL_Store_t * pWPL_Store) |
||
990 | { |
||
519 | holgerb | 991 | u8 filename[30], result = 0; |
516 | holgerb | 992 | |
514 | holgerb | 993 | sprintf(filename, "/POINT/POINT%03d.wpl", pWPL_Store->Index); |
513 | killagreg | 994 | pWPL_Store->Name[0] = 0; // clear current list name |
519 | holgerb | 995 | result = PointList_Load(filename, pWPL_Store->Name, sizeof(pWPL_Store->Name),Parameter.SingleWpSpeed); |
996 | if(result) UART1_Request_ReadPoint = 1; // Sends Point 1 to the PC |
||
997 | return(result); |
||
513 | killagreg | 998 | } |
999 | |||
1000 | |||
516 | holgerb | 1001 | |
504 | holgerb | 1002 | void ClearWLP_Name(void) |
1003 | { |
||
513 | killagreg | 1004 | u8 i; |
1005 | for(i=0; i<sizeof(WPL_Store.Name);i++) WPL_Store.Name[i] = 0; |
||
1006 | NewWPL_Name = 1; |
||
504 | holgerb | 1007 | } |
513 | killagreg | 1008 | |
491 | killagreg | 1009 | // move actual point list to ref pos., the point in the list marked by index gets the RefPos afterwards |
503 | holgerb | 1010 | u8 PointList_Move(u8 RefIndex, GPS_Pos_t* pRefPos, u16 RotationAngle) |
491 | killagreg | 1011 | { |
1012 | u8 retval = 0; |
||
513 | killagreg | 1013 | s32 altitude; |
1014 | GPS_Pos_t OldRefPos; |
||
491 | killagreg | 1015 | GPS_Pos_Deviation_t RefDeviation; |
516 | holgerb | 1016 | |
491 | killagreg | 1017 | // check inputs for plausibility; |
516 | holgerb | 1018 | if((RefIndex == 0) || (RefIndex > PointCount)) return(retval); |
491 | killagreg | 1019 | if(pRefPos == NULL) return(retval); |
1020 | if(pRefPos->Status == INVALID) return(retval); |
||
1021 | |||
513 | killagreg | 1022 | if(GPSPos_Copy(&(PointList[RefIndex-1].Position), &OldRefPos)) // backup old reference position |
491 | killagreg | 1023 | { |
1024 | u8 i; |
||
513 | killagreg | 1025 | // iterate the position list |
491 | killagreg | 1026 | for(i = 0; i < PointCount; i++) |
1027 | { |
||
1028 | retval = 0; |
||
513 | killagreg | 1029 | // backup altitude of this point |
1030 | altitude = PointList[i].Position.Altitude; |
||
1031 | // calculate deviation form old ref, i.e the north and east shift of each point in the list from the reference position |
||
1032 | if(!GPSPos_Deviation(&(PointList[i].Position), &OldRefPos, &RefDeviation)) break; |
||
491 | killagreg | 1033 | // copy of the new reference position into this list place |
1034 | if(!GPSPos_Copy(pRefPos, &(PointList[i].Position))) break; |
||
516 | holgerb | 1035 | // restore former altitude |
513 | killagreg | 1036 | PointList[i].Position.Altitude = altitude; |
491 | killagreg | 1037 | // move new reference according to the deviation of the old reference |
513 | killagreg | 1038 | if(RotationAngle > 0) |
1039 | { |
||
737 | holgerb | 1040 | retval = GPSPos_ShiftGeodetic(&(PointList[i].Position), (RefDeviation.Bearing + 180 + RotationAngle)%360, RefDeviation.Distance_cm ); |
513 | killagreg | 1041 | // Now rotate the heading positions if they are fixed angles |
1042 | if(PointList[i].Heading >= 0 && PointList[i].Heading <= 360) PointList[i].Heading = (PointList[i].Heading + RotationAngle) % 360; |
||
1043 | } |
||
1044 | else // no rotation |
||
1045 | { |
||
1046 | // move new reference according to the deviation of the old reference |
||
1047 | retval = GPSPos_ShiftCartesian(&(PointList[i].Position), RefDeviation.North, RefDeviation.East); |
||
1048 | } |
||
516 | holgerb | 1049 | if(!retval) break; |
491 | killagreg | 1050 | } |
1051 | } // else ref pos old not copied! |
||
1052 | if(!retval) PointList_Clear(); |
||
1053 | return(retval); |
||
1054 | } |
||
1055 | |||
516 | holgerb | 1056 | |
491 | killagreg | 1057 |