Rev 503 | Rev 513 | Go to most recent revision | 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 |
||
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
||
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 |
||
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
||
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 - |
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 |
||
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> |
||
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" |
41 | ingob | 65 | |
496 | killagreg | 66 | |
67 | WPL_Store_t WPL_Store; |
||
68 | |||
41 | ingob | 69 | // the waypoints list |
351 | holgerb | 70 | #define MAX_LIST_LEN 101 |
227 | killagreg | 71 | |
280 | killagreg | 72 | Point_t PointList[MAX_LIST_LEN]; |
73 | u8 WPIndex = 0; // list index of GPS point representig the current WP, can be maximal WPCount |
||
74 | u8 POIIndex = 0; // list index of GPS Point representing the current POI, can be maximal WPCount |
||
75 | u8 WPCount = 0; // number of waypoints |
||
491 | killagreg | 76 | u8 PointCount = 0; // number of points in the list can be maximal equal to MAX_LIST_LEN |
77 | u8 POICount = 0; // number of point of interest in the list |
||
41 | ingob | 78 | |
296 | killagreg | 79 | u8 WPActive = FALSE; |
280 | killagreg | 80 | |
81 | u8 PointList_Init(void) |
||
41 | ingob | 82 | { |
280 | killagreg | 83 | return PointList_Clear(); |
41 | ingob | 84 | } |
85 | |||
280 | killagreg | 86 | u8 PointList_Clear(void) |
41 | ingob | 87 | { |
88 | u8 i; |
||
227 | killagreg | 89 | WPIndex = 0; // real list position are 1 ,2, 3 ... |
90 | POIIndex = 0; // real list position are 1 ,2, 3 ... |
||
280 | killagreg | 91 | WPCount = 0; // no waypoints |
283 | holgerb | 92 | POICount = 0; |
280 | killagreg | 93 | PointCount = 0; // no contents |
296 | killagreg | 94 | WPActive = FALSE; |
280 | killagreg | 95 | NaviData.WaypointNumber = WPCount; |
96 | NaviData.WaypointIndex = 0; |
||
41 | ingob | 97 | |
280 | killagreg | 98 | for(i = 0; i < MAX_LIST_LEN; i++) |
41 | ingob | 99 | { |
280 | killagreg | 100 | PointList[i].Position.Status = INVALID; |
101 | PointList[i].Position.Latitude = 0; |
||
102 | PointList[i].Position.Longitude = 0; |
||
103 | PointList[i].Position.Altitude = 0; |
||
104 | PointList[i].Heading = 361; // invalid value |
||
105 | PointList[i].ToleranceRadius = 0; // in meters, if the MK is within that range around the target, then the next target is triggered |
||
106 | 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 | 107 | PointList[i].Event_Flag = 0; // future implementation |
108 | PointList[i].Index = 0; |
||
286 | killagreg | 109 | PointList[i].Type = POINT_TYPE_INVALID; |
490 | killagreg | 110 | PointList[i].WP_EventChannelValue = 0; |
286 | killagreg | 111 | PointList[i].AltitudeRate = 0; // no change of setpoint |
490 | killagreg | 112 | PointList[i].Speed = 0; |
113 | PointList[i].CamAngle = 0; |
||
114 | PointList[i].Name[0] = 0; |
||
41 | ingob | 115 | } |
504 | holgerb | 116 | ClearWLP_Name(); |
41 | ingob | 117 | return TRUE; |
118 | } |
||
119 | |||
280 | killagreg | 120 | u8 PointList_GetCount(void) |
41 | ingob | 121 | { |
280 | killagreg | 122 | return PointCount; // number of points in the list |
41 | ingob | 123 | } |
124 | |||
295 | killagreg | 125 | Point_t* PointList_GetAt(u8 index) |
41 | ingob | 126 | { |
295 | killagreg | 127 | if((index > 0) && (index <= PointCount)) return(&(PointList[index-1])); // return pointer to this waypoint |
128 | else return(NULL); |
||
129 | } |
||
130 | |||
131 | u8 PointList_SetAt(Point_t* pPoint) |
||
132 | { |
||
133 | // if index is in range |
||
296 | killagreg | 134 | if((pPoint->Index > 0) && (pPoint->Index <= MAX_LIST_LEN)) |
41 | ingob | 135 | { |
295 | killagreg | 136 | // check list entry before update |
137 | switch(PointList[pPoint->Index-1].Type) |
||
277 | killagreg | 138 | { |
295 | killagreg | 139 | case POINT_TYPE_INVALID: // was invalid |
140 | switch(pPoint->Type) |
||
141 | { |
||
142 | default: |
||
143 | case POINT_TYPE_INVALID: |
||
144 | // nothing to do |
||
145 | break; |
||
146 | |||
147 | case POINT_TYPE_WP: |
||
148 | WPCount++; |
||
149 | PointCount++; |
||
150 | break; |
||
151 | |||
152 | case POINT_TYPE_POI: |
||
153 | POICount++; |
||
154 | PointCount++; |
||
155 | break; |
||
156 | } |
||
157 | break; |
||
277 | killagreg | 158 | |
490 | killagreg | 159 | case POINT_TYPE_WP: // was a waypoint |
295 | killagreg | 160 | switch(pPoint->Type) |
161 | { |
||
162 | case POINT_TYPE_INVALID: |
||
163 | WPCount--; |
||
164 | PointCount--; |
||
165 | break; |
||
277 | killagreg | 166 | |
295 | killagreg | 167 | default: |
168 | case POINT_TYPE_WP: |
||
169 | //nothing to do |
||
170 | break; |
||
171 | |||
172 | case POINT_TYPE_POI: |
||
173 | POICount++; |
||
174 | WPCount--; |
||
175 | break; |
||
176 | } |
||
177 | break; |
||
178 | |||
179 | case POINT_TYPE_POI: // was a poi |
||
180 | switch(pPoint->Type) |
||
181 | { |
||
182 | case POINT_TYPE_INVALID: |
||
183 | POICount--; |
||
184 | PointCount--; |
||
185 | break; |
||
186 | |||
187 | case POINT_TYPE_WP: |
||
188 | WPCount++; |
||
189 | POICount--; |
||
190 | break; |
||
191 | |||
192 | case POINT_TYPE_POI: |
||
193 | default: |
||
194 | // nothing to do |
||
195 | break; |
||
196 | } |
||
197 | break; |
||
277 | killagreg | 198 | } |
295 | killagreg | 199 | memcpy(&PointList[pPoint->Index-1], pPoint, sizeof(Point_t)); // copy data to list entry |
200 | NaviData.WaypointNumber = WPCount; |
||
201 | return pPoint->Index; |
||
41 | ingob | 202 | } |
296 | killagreg | 203 | else return(0); |
41 | ingob | 204 | } |
205 | |||
227 | killagreg | 206 | // returns the pointer to the first waypoint within the list |
280 | killagreg | 207 | Point_t* PointList_WPBegin(void) |
41 | ingob | 208 | { |
277 | killagreg | 209 | u8 i; |
227 | killagreg | 210 | WPIndex = 0; // set list position invalid |
295 | killagreg | 211 | |
283 | holgerb | 212 | if(WPActive == FALSE) return(NULL); |
295 | killagreg | 213 | |
277 | killagreg | 214 | POIIndex = 0; // set invalid POI |
280 | killagreg | 215 | if(PointCount > 0) |
152 | killagreg | 216 | { |
225 | killagreg | 217 | // search for first wp in list |
295 | killagreg | 218 | for(i = 0; i <MAX_LIST_LEN; i++) |
225 | killagreg | 219 | { |
280 | killagreg | 220 | if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) |
225 | killagreg | 221 | { |
227 | killagreg | 222 | WPIndex = i + 1; |
225 | killagreg | 223 | break; |
224 | } |
||
225 | } |
||
277 | killagreg | 226 | if(WPIndex) // found a WP in the list |
227 | { |
||
280 | killagreg | 228 | NaviData.WaypointIndex = 1; |
277 | killagreg | 229 | // update index to POI |
280 | killagreg | 230 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
296 | killagreg | 231 | else POIIndex = 0; |
277 | killagreg | 232 | } |
233 | else // some points in the list but no WP found |
||
234 | { |
||
280 | killagreg | 235 | NaviData.WaypointIndex = 0; |
277 | killagreg | 236 | //Check for an existing POI |
295 | killagreg | 237 | for(i = 0; i < MAX_LIST_LEN; i++) |
277 | killagreg | 238 | { |
280 | killagreg | 239 | if((PointList[i].Type == POINT_TYPE_POI) && (PointList[i].Position.Status != INVALID)) |
277 | killagreg | 240 | { |
241 | POIIndex = i + 1; |
||
242 | break; |
||
243 | } |
||
244 | } |
||
245 | } |
||
152 | killagreg | 246 | } |
277 | killagreg | 247 | else // no point in the list |
152 | killagreg | 248 | { |
277 | killagreg | 249 | POIIndex = 0; |
295 | killagreg | 250 | NaviData.WaypointIndex = 0; |
227 | killagreg | 251 | } |
295 | killagreg | 252 | |
253 | if(WPIndex) return(&(PointList[WPIndex-1])); |
||
254 | else return(NULL); |
||
41 | ingob | 255 | } |
256 | |||
225 | killagreg | 257 | // returns the last waypoint |
280 | killagreg | 258 | Point_t* PointList_WPEnd(void) |
151 | killagreg | 259 | { |
277 | killagreg | 260 | |
261 | u8 i; |
||
227 | killagreg | 262 | WPIndex = 0; // set list position invalid |
277 | killagreg | 263 | POIIndex = 0; // set invalid |
283 | holgerb | 264 | |
280 | killagreg | 265 | if(WPActive == FALSE) return(NULL); |
277 | killagreg | 266 | |
280 | killagreg | 267 | if(PointCount > 0) |
151 | killagreg | 268 | { |
227 | killagreg | 269 | // search backward! |
295 | killagreg | 270 | for(i = 1; i <= MAX_LIST_LEN; i++) |
225 | killagreg | 271 | { |
295 | killagreg | 272 | if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_WP) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID)) |
225 | killagreg | 273 | { |
295 | killagreg | 274 | WPIndex = MAX_LIST_LEN - i + 1; |
225 | killagreg | 275 | break; |
276 | } |
||
277 | } |
||
277 | killagreg | 278 | if(WPIndex) // found a WP within the list |
279 | { |
||
280 | killagreg | 280 | NaviData.WaypointIndex = WPCount; |
281 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
||
277 | killagreg | 282 | else POIIndex = 0; |
283 | } |
||
278 | killagreg | 284 | else // list contains some points but no WP in the list |
277 | killagreg | 285 | { |
286 | // search backward for a POI! |
||
295 | killagreg | 287 | for(i = 1; i <= MAX_LIST_LEN; i++) |
277 | killagreg | 288 | { |
295 | killagreg | 289 | if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_POI) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID)) |
277 | killagreg | 290 | { |
295 | killagreg | 291 | POIIndex = MAX_LIST_LEN - i + 1; |
277 | killagreg | 292 | break; |
293 | } |
||
294 | } |
||
295 | killagreg | 295 | NaviData.WaypointIndex = 0; |
277 | killagreg | 296 | } |
151 | killagreg | 297 | } |
277 | killagreg | 298 | else // no point in the list |
227 | killagreg | 299 | { |
280 | killagreg | 300 | POIIndex = 0; |
301 | NaviData.WaypointIndex = 0; |
||
227 | killagreg | 302 | } |
295 | killagreg | 303 | if(WPIndex) return(&(PointList[WPIndex-1])); |
304 | else return(NULL); |
||
151 | killagreg | 305 | } |
306 | |||
41 | ingob | 307 | // returns a pointer to the next waypoint or NULL if the end of the list has been reached |
280 | killagreg | 308 | Point_t* PointList_WPNext(void) |
41 | ingob | 309 | { |
227 | killagreg | 310 | u8 wp_found = 0; |
280 | killagreg | 311 | if(WPActive == FALSE) return(NULL); |
227 | killagreg | 312 | |
295 | killagreg | 313 | if(WPIndex < MAX_LIST_LEN) // if there is a next entry in the list |
41 | ingob | 314 | { |
227 | killagreg | 315 | u8 i; |
295 | killagreg | 316 | for(i = WPIndex; i < MAX_LIST_LEN; i++) // start search for next at next list entry |
225 | killagreg | 317 | { |
280 | killagreg | 318 | if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) // jump over POIs |
225 | killagreg | 319 | { |
227 | killagreg | 320 | wp_found = i+1; |
225 | killagreg | 321 | break; |
322 | } |
||
323 | } |
||
41 | ingob | 324 | } |
227 | killagreg | 325 | if(wp_found) |
326 | { |
||
327 | WPIndex = wp_found; // update list position |
||
280 | killagreg | 328 | NaviData.WaypointIndex++; |
329 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
||
227 | killagreg | 330 | else POIIndex = 0; |
280 | killagreg | 331 | return(&(PointList[WPIndex-1])); // return pointer to this waypoint |
227 | killagreg | 332 | } |
277 | killagreg | 333 | else |
280 | killagreg | 334 | { // no next wp found |
335 | NaviData.WaypointIndex = 0; |
||
277 | killagreg | 336 | POIIndex = 0; |
337 | return(NULL); |
||
338 | } |
||
41 | ingob | 339 | } |
280 | killagreg | 340 | |
341 | void PointList_WPActive(u8 set) |
||
342 | { |
||
295 | killagreg | 343 | if(set) |
344 | { |
||
345 | WPActive = TRUE; |
||
491 | killagreg | 346 | PointList_WPBegin(); // updates POI index |
295 | killagreg | 347 | } |
348 | else |
||
349 | { |
||
350 | WPActive = FALSE; |
||
351 | POIIndex = 0; // disable POI also |
||
352 | } |
||
280 | killagreg | 353 | } |
41 | ingob | 354 | |
280 | killagreg | 355 | Point_t* PointList_GetPOI(void) |
224 | killagreg | 356 | { |
280 | killagreg | 357 | return PointList_GetAt(POIIndex); |
224 | killagreg | 358 | } |
359 | |||
490 | killagreg | 360 | #define LINE_MAX 70 |
361 | #define WP_FILE_VERSION_COMPATIBLE 3 |
||
362 | // save actual point list to SD card |
||
495 | killagreg | 363 | u8 PointList_SaveToFile(WPL_Store_t * pWPL_Store) |
490 | killagreg | 364 | { |
365 | File_t *fp; |
||
495 | killagreg | 366 | s8 wpline[LINE_MAX]; |
367 | u8 retval = WPL_ERROR; |
||
368 | |||
497 | killagreg | 369 | if(PointCount == 0) return(WPL_NO_WAYPOINTS); |
496 | killagreg | 370 | // user absolute path, i.e. leading / |
371 | if(pWPL_Store->Index == 0) |
||
372 | { |
||
373 | sprintf(wpline, "/default.wpl"); |
||
374 | } |
||
375 | else |
||
376 | { |
||
377 | sprintf(wpline, "/WPL/list_%03d.wpl", pWPL_Store->Index); |
||
378 | } |
||
490 | killagreg | 379 | UART1_PutString("\n\r Save WPL..."); |
380 | |||
381 | if(Fat16_IsValid()) |
||
382 | { // check if wpl file is existing |
||
495 | killagreg | 383 | if(fexist_(wpline)) |
384 | { //file is existent |
||
385 | if(!(pWPL_Store->OverwriteFile)) |
||
386 | { |
||
387 | UART1_PutString("Error: file exist!\r\n"); |
||
388 | return(WPL_FILEEXIST); |
||
389 | } |
||
390 | } |
||
490 | killagreg | 391 | fp = fopen_(wpline, 'w'); // try to open the file |
392 | if(fp == NULL) |
||
393 | { |
||
394 | UART1_PutString("ERROR: Creating waypoint file!\r\n"); |
||
395 | return(retval); |
||
396 | } |
||
397 | // Create general section and key entries |
||
398 | fputs_("[General]\r\n", fp); |
||
495 | killagreg | 399 | sprintf(wpline, "Name=%s\r\n", pWPL_Store->Name); |
494 | killagreg | 400 | fputs_(wpline, fp); |
490 | killagreg | 401 | sprintf(wpline, "FileVersion=%d\r\n", WP_FILE_VERSION_COMPATIBLE); |
402 | fputs_(wpline, fp); |
||
403 | sprintf(wpline, "NumberOfWaypoints=%d\r\n", PointCount); |
||
404 | fputs_(wpline, fp); |
||
405 | // dump all points if existent |
||
406 | if(PointCount) |
||
407 | { |
||
408 | u8 i, u8_1; |
||
409 | s32 i32_1, i32_2; |
||
504 | holgerb | 410 | NewWPL_Name = 1; |
490 | killagreg | 411 | for (i = 0; i < PointCount; i++) |
412 | { |
||
413 | sprintf(wpline, "[Point%d]\r\n",PointList[i].Index); |
||
414 | fputs_(wpline, fp); |
||
415 | // write latitude in deg |
||
416 | if(PointList[i].Position.Latitude < 0) u8_1 = '-'; |
||
417 | else u8_1 = '+'; |
||
418 | i32_1 = abs(PointList[i].Position.Latitude)/10000000L; |
||
419 | i32_2 = abs(PointList[i].Position.Latitude)%10000000L; |
||
420 | sprintf(wpline, "Latitude=%c%ld.%07ld\r\n", u8_1, i32_1, i32_2); |
||
421 | fputs_(wpline, fp); |
||
422 | // write longitude in deg |
||
423 | if(PointList[i].Position.Longitude < 0) u8_1 = '-'; |
||
424 | else u8_1 = '+'; |
||
425 | i32_1 = abs(PointList[i].Position.Longitude)/10000000L; |
||
426 | i32_2 = abs(PointList[i].Position.Longitude)%10000000L; |
||
427 | sprintf(wpline, "Longitude=%c%ld.%07ld\r\n", u8_1, i32_1, i32_2); |
||
428 | fputs_(wpline, fp); |
||
429 | // write tolerace radius in m |
||
430 | sprintf(wpline, "Radius=%d\r\n", PointList[i].ToleranceRadius); |
||
431 | fputs_(wpline, fp); |
||
432 | // write altitude in m |
||
433 | if(PointList[i].Position.Altitude < 0) u8_1 = '-'; |
||
434 | else u8_1 = '+'; |
||
435 | if(PointList[i].Type == POINT_TYPE_POI) |
||
436 | { |
||
437 | i32_1 = abs(PointList[i].Position.Altitude)/100L; // cm --> m |
||
438 | i32_2 = abs(PointList[i].Position.Altitude)%100L; |
||
439 | } |
||
440 | else |
||
441 | { |
||
442 | i32_1 = abs(PointList[i].Position.Altitude)/10L; // dm --> m |
||
443 | i32_2 = abs(PointList[i].Position.Altitude)%10L; |
||
444 | } |
||
445 | sprintf(wpline, "Altitude=%c%ld.%01ld\r\n", u8_1, i32_1, i32_2); |
||
446 | fputs_(wpline, fp); |
||
447 | // write climb rate in 0.1 m/s |
||
448 | sprintf(wpline, "ClimbRate=%d\r\n", PointList[i].AltitudeRate); |
||
449 | fputs_(wpline, fp); |
||
450 | // write hold time in s |
||
451 | sprintf(wpline, "DelayTime=%d\r\n", PointList[i].HoldTime); |
||
452 | fputs_(wpline, fp); |
||
453 | // write event channel value |
||
454 | sprintf(wpline, "WP_Event_Channel_Value=%d\r\n", PointList[i].WP_EventChannelValue); |
||
455 | fputs_(wpline, fp); |
||
456 | // write heading in deg (0= nothing, neg. values index to poi) |
||
457 | sprintf(wpline, "Heading=%d\r\n", PointList[i].Heading); |
||
458 | fputs_(wpline, fp); |
||
459 | // write speed in 0.1 m/s |
||
460 | sprintf(wpline, "Speed=%d\r\n", PointList[i].Speed); |
||
461 | fputs_(wpline, fp); |
||
462 | // write cam angle in degree (255 -> POI-Automatic) |
||
463 | sprintf(wpline, "CAM-Nick=%d\r\n", PointList[i].CamAngle); |
||
464 | fputs_(wpline, fp); |
||
465 | // write point type |
||
466 | sprintf(wpline, "Type=%d\r\n", PointList[i].Type + 1); |
||
467 | fputs_(wpline, fp); |
||
468 | // write prefix |
||
469 | sprintf(wpline, "Prefix=%s\r\n", PointList[i].Name); |
||
470 | fputs_(wpline, fp); |
||
471 | } // EOF loop over all points |
||
472 | } // EOF if(PointCount) |
||
473 | if(EOF == fclose_(fp)) |
||
474 | { |
||
475 | UART1_PutString("failed!\r\n"); |
||
476 | } |
||
477 | else |
||
478 | { |
||
479 | UART1_PutString("ok\r\n"); |
||
495 | killagreg | 480 | retval = WPL_OK; |
490 | killagreg | 481 | } |
482 | } // EOF if(Fat16_IsValid()) |
||
497 | killagreg | 483 | else |
484 | { |
||
485 | UART1_PutString("no file system found!\r\n"); |
||
486 | retval = WPL_NO_SDCARD_FOUND; |
||
487 | } |
||
490 | killagreg | 488 | return(retval); |
489 | } |
||
490 | |||
491 | // load actual point list from SD card |
||
495 | killagreg | 492 | u8 PointList_ReadFromFile(WPL_Store_t * pWPL_Store) |
490 | killagreg | 493 | { |
494 | File_t *fp; |
||
496 | killagreg | 495 | s8 wpline[LINE_MAX]; |
496 | u8 retval = WPL_ERROR; |
||
490 | killagreg | 497 | |
498 | s8 *name, *value; |
||
499 | u8 i; |
||
500 | |||
501 | u8 IsGeneralSection = 0; |
||
502 | u8 IsPointSection = 0; |
||
503 | u8 WPNumber = 0; |
||
497 | killagreg | 504 | |
498 | killagreg | 505 | |
506 | // clear point list first |
||
507 | PointList_Clear(); |
||
508 | pWPL_Store->Name[0] = 0; // clear current list name |
||
509 | |||
490 | killagreg | 510 | // user absolute path, i.e. leading / |
496 | killagreg | 511 | if(pWPL_Store->Index == 0) // index 0 looks for a default WPL file in the root |
512 | { |
||
513 | sprintf(wpline, "/default.wpl"); |
||
514 | } |
||
515 | else |
||
516 | { |
||
517 | sprintf(wpline, "/WPL/list_%03d.wpl", pWPL_Store->Index); |
||
518 | } |
||
490 | killagreg | 519 | |
520 | UART1_PutString("\n\r Read "); |
||
521 | UART1_PutString(wpline); |
||
522 | UART1_PutString("..."); |
||
523 | |||
524 | if(Fat16_IsValid()) |
||
525 | { // check if wpl file is existing |
||
526 | fp = fopen_(wpline, 'r'); // try to open the file |
||
527 | if(fp == NULL) |
||
528 | { |
||
529 | UART1_PutString("ERROR: Reading waypoint file!\r\n"); |
||
496 | killagreg | 530 | return(retval); |
490 | killagreg | 531 | } |
532 | // read all lines from file |
||
533 | while(fgets_(wpline, LINE_MAX, fp) != 0) |
||
534 | { |
||
535 | if ( // ignorelines starting with \r,\n,' ',';','#' |
||
536 | (wpline[0] != '\n') && |
||
537 | (wpline[0] != '\r') && |
||
538 | (wpline[0] != ' ' ) && |
||
539 | (wpline[0] != ';' ) && |
||
540 | (wpline[0] != '#' ) |
||
541 | ) |
||
542 | { |
||
543 | // check for section line found |
||
544 | if(wpline[0] == '[') |
||
545 | { |
||
546 | // next section found |
||
547 | IsGeneralSection = 0; |
||
548 | IsPointSection = 0; |
||
549 | |||
550 | name = strtok(&wpline[1], "]"); |
||
551 | if(name != NULL) // if section name |
||
552 | { |
||
553 | // check section type |
||
554 | for(i=0; name[i]; i++) name[i] = toupper(name[i]); // convert to upper case |
||
555 | |||
556 | if(strncmp(name, "POINT", 5) == 0) |
||
557 | { |
||
558 | IsPointSection = (u8)atoi(&name[5]); |
||
559 | PointCount++; |
||
560 | } |
||
561 | else if(strcmp(name, "GENERAL") == 0) |
||
562 | { |
||
563 | IsGeneralSection = 1; |
||
564 | } |
||
565 | else |
||
566 | { |
||
567 | UART1_PutString("Unknown section: "); |
||
568 | UART1_PutString(name); |
||
569 | UART1_PutString("\r\n"); |
||
570 | } |
||
571 | } |
||
572 | } // EOF section line |
||
573 | else |
||
574 | { // look for key entrys of each sections |
||
575 | name = strtok(wpline, "="); // get name |
||
576 | value = strtok(NULL, "="); // get value |
||
577 | if ((name != NULL) && (value != NULL)) |
||
578 | { |
||
579 | for(i=0; name[i]; i++) name[i] = toupper(name[i]); // convert to upper case |
||
580 | if(IsPointSection && (IsPointSection <= WPNumber)) |
||
581 | { |
||
582 | if(strcmp(name, "LATITUDE") == 0) |
||
583 | { |
||
584 | PointList[IsPointSection-1].Position.Latitude = (s32)(atof(value) * 1E7); |
||
585 | } |
||
586 | else if(strcmp(name, "LONGITUDE") == 0) |
||
587 | { |
||
588 | PointList[IsPointSection-1].Position.Longitude = (s32)(atof(value) * 1E7); |
||
589 | } |
||
590 | else if(strcmp(name, "RADIUS") == 0) |
||
591 | { |
||
592 | PointList[IsPointSection-1].ToleranceRadius = (u8)atoi(value); |
||
593 | } |
||
594 | else if(strcmp(name, "ALTITUDE") == 0) |
||
595 | { |
||
596 | PointList[IsPointSection-1].Position.Altitude = (s32)(atof(value) * 100.0); // in cm |
||
597 | PointList[IsPointSection-1].Position.Status = NEWDATA; |
||
598 | } |
||
599 | else if(strcmp(name, "CLIMBRATE") == 0) |
||
600 | { |
||
601 | PointList[IsPointSection-1].AltitudeRate = (u8)atoi(value); |
||
602 | } |
||
603 | else if(strcmp(name, "DELAYTIME") == 0) |
||
604 | { |
||
605 | PointList[IsPointSection-1].HoldTime = (u8)atoi(value); |
||
606 | } |
||
607 | else if(strcmp(name, "WP_EVENT_CHANNEL_VALUE") == 0) |
||
608 | { |
||
609 | PointList[IsPointSection-1].WP_EventChannelValue = (u8)atoi(value); |
||
610 | } |
||
611 | else if(strcmp(name, "HEADING") == 0) |
||
612 | { |
||
613 | PointList[IsPointSection-1].Heading = (s16)atoi(value); |
||
614 | } |
||
615 | else if(strcmp(name, "SPEED") == 0) |
||
616 | { |
||
617 | PointList[IsPointSection-1].Speed = (u8)atoi(value); |
||
618 | } |
||
619 | else if(strcmp(name, "CAM-NICK") == 0) |
||
620 | { |
||
621 | PointList[IsPointSection-1].CamAngle = (u8)atoi(value); |
||
622 | } |
||
623 | else if(strcmp(name, "TYPE") == 0) |
||
624 | { |
||
625 | PointList[IsPointSection-1].Type = (u8)atoi(value); |
||
626 | if(PointList[IsPointSection-1].Type > 0) PointList[IsPointSection-1].Type--; // index shift |
||
627 | else PointList[IsPointSection-1].Type = POINT_TYPE_INVALID; |
||
628 | |||
629 | switch(PointList[IsPointSection-1].Type) |
||
630 | { |
||
631 | case POINT_TYPE_WP: |
||
632 | // this works only if altitude key is set before point type key in WPL file !! |
||
633 | PointList[IsPointSection-1].Position.Altitude /= 10; // dm only for WPs |
||
634 | WPCount++; |
||
635 | break; |
||
636 | |||
637 | case POINT_TYPE_POI: |
||
638 | POICount++; |
||
639 | break; |
||
640 | } |
||
641 | } |
||
642 | else if(strcmp(name, "PREFIX") == 0) |
||
643 | { |
||
644 | strncpy(PointList[IsPointSection-1].Name, value, 4); |
||
645 | PointList[IsPointSection-1].Name[3] = 0; // Terminate string |
||
646 | } |
||
647 | else |
||
648 | { |
||
649 | UART1_PutString("Unknown key: "); |
||
650 | UART1_PutString(name); |
||
651 | UART1_PutString("\r\n"); |
||
652 | } |
||
653 | } // EOF point section |
||
654 | else if(IsGeneralSection) |
||
655 | { |
||
656 | if(strcmp(name, "NUMBEROFWAYPOINTS") == 0) |
||
657 | { |
||
658 | WPNumber = (u8)atoi(value); |
||
659 | if(!WPNumber) // no waypoints in file |
||
660 | { |
||
497 | killagreg | 661 | return(WPL_NO_WAYPOINTS); // we are done here |
490 | killagreg | 662 | } |
663 | else if(WPNumber > MAX_LIST_LEN) // number o points larger than ram list |
||
664 | { |
||
665 | UART1_PutString("To much points!"); |
||
497 | killagreg | 666 | return(WPL_ERROR); |
490 | killagreg | 667 | } |
668 | } |
||
669 | else if (strcmp(name, "FILEVERSION") == 0) |
||
670 | { |
||
671 | if((u8)atoi(value) != WP_FILE_VERSION_COMPATIBLE) |
||
672 | { |
||
496 | killagreg | 673 | PointList_Clear(); |
490 | killagreg | 674 | UART1_PutString("Bad file version!\r\n"); |
496 | killagreg | 675 | return(WPL_ERROR); |
490 | killagreg | 676 | } |
677 | } |
||
495 | killagreg | 678 | else if (strcmp(name, "NAME") == 0) |
679 | { |
||
680 | u8 len = strlen(value); |
||
498 | killagreg | 681 | if(value[len-1] == '\r') |
682 | { |
||
683 | value[len-1] = 0; |
||
684 | len--; |
||
685 | } |
||
686 | if(len > 11) value[11] = 0; |
||
504 | holgerb | 687 | else for(;len < 11; len++) value[len] = ' '; |
495 | killagreg | 688 | memcpy(pWPL_Store->Name, value, 12); |
504 | holgerb | 689 | NewWPL_Name = 1; |
495 | killagreg | 690 | } |
490 | killagreg | 691 | else |
692 | { |
||
693 | UART1_PutString("Unknown key: "); |
||
694 | UART1_PutString(name); |
||
695 | UART1_PutString("\r\n"); |
||
696 | } |
||
697 | } // EOF general section |
||
698 | } // EOF valid key entry |
||
699 | } // EOF key entry line |
||
700 | } // valid line |
||
701 | } // EOF loop over all lines |
||
702 | fclose_(fp); |
||
703 | NaviData.WaypointNumber = WPCount; |
||
497 | killagreg | 704 | retval = WPL_OK; |
705 | UART1_PutString("ok\r\n"); |
||
490 | killagreg | 706 | } // EOF if(Fat16_IsValid()) |
497 | killagreg | 707 | else |
708 | { |
||
709 | UART1_PutString("no file system found!\r\n"); |
||
710 | retval = WPL_NO_SDCARD_FOUND; |
||
711 | } |
||
490 | killagreg | 712 | return(retval); |
491 | killagreg | 713 | } |
490 | killagreg | 714 | |
504 | holgerb | 715 | void ClearWLP_Name(void) |
716 | { |
||
717 | unsigned char i; |
||
718 | for(i=0; i<sizeof(WPL_Store.Name);i++) WPL_Store.Name[i] = 0; |
||
719 | NewWPL_Name = 1; |
||
720 | } |
||
491 | killagreg | 721 | // move actual point list to ref pos., the point in the list marked by index gets the RefPos afterwards |
503 | holgerb | 722 | u8 PointList_Move(u8 RefIndex, GPS_Pos_t* pRefPos, u16 RotationAngle) |
491 | killagreg | 723 | { |
724 | u8 retval = 0; |
||
503 | holgerb | 725 | GPS_Pos_t FirstPoint; |
491 | killagreg | 726 | GPS_Pos_Deviation_t RefDeviation; |
727 | |||
728 | // check inputs for plausibility; |
||
729 | if((RefIndex == 0) || (RefIndex > PointCount)) return(retval); |
||
730 | if(pRefPos == NULL) return(retval); |
||
731 | if(pRefPos->Status == INVALID) return(retval); |
||
732 | |||
733 | // try to copy the old reference in point list to a local buffer |
||
503 | holgerb | 734 | if(GPSPos_Copy(&(PointList[RefIndex-1].Position), &FirstPoint)) |
491 | killagreg | 735 | { |
736 | u8 i; |
||
737 | // for each point position in the list |
||
738 | for(i = 0; i < PointCount; i++) |
||
739 | { |
||
740 | retval = 0; |
||
503 | holgerb | 741 | // Save altitude of that point |
742 | pRefPos->Altitude = PointList[i].Position.Altitude; |
||
491 | killagreg | 743 | // calculate deviation form old ref, i.e the north and east shift of each point in the list from the reference position |
503 | holgerb | 744 | if(!GPSPos_Deviation(&(PointList[i].Position), &FirstPoint, &RefDeviation)) break; |
491 | killagreg | 745 | // copy of the new reference position into this list place |
746 | if(!GPSPos_Copy(pRefPos, &(PointList[i].Position))) break; |
||
747 | // move new reference according to the deviation of the old reference |
||
748 | retval = GPSPos_ShiftCartesian(&(PointList[i].Position), RefDeviation.North, RefDeviation.East); |
||
749 | if(!retval) break; |
||
750 | } |
||
503 | holgerb | 751 | // ++++++++++++++++++++++++++++++++++++++++++++++ |
752 | // Now rotate around the reference point |
||
753 | // ++++++++++++++++++++++++++++++++++++++++++++++ |
||
754 | if(RotationAngle > 0) |
||
755 | { |
||
756 | GPSPos_Copy(&(PointList[RefIndex-1].Position), &FirstPoint); // Rotate around the reference point |
||
757 | for(i = 0; i < PointCount; i++) |
||
758 | { |
||
759 | retval = 0; |
||
760 | // Save altitude of that point |
||
761 | pRefPos->Altitude = PointList[i].Position.Altitude; |
||
762 | // calculate deviation form old ref, i.e the north and east shift of each point in the list from the reference position |
||
763 | if(!GPSPos_Deviation(&(PointList[i].Position), &FirstPoint, &RefDeviation)) break; |
||
764 | // copy of the new reference position into this list place |
||
765 | if(!GPSPos_Copy(pRefPos, &(PointList[i].Position))) break; |
||
766 | // move new reference according to the deviation of the old reference |
||
767 | retval = GPSPos_ShiftGeodetic(&(PointList[i].Position), (RefDeviation.Bearing + 180 + RotationAngle)%360,RefDeviation.Distance ); |
||
768 | // Now rotate the heading positions if they are fixed angles |
||
769 | if(PointList[i].Heading >= 0 && PointList[i].Heading <= 360) PointList[i].Heading = (PointList[i].Heading + RotationAngle) % 360; |
||
770 | if(!retval) break; |
||
771 | } |
||
772 | } |
||
773 | // ++++++++++++++++++++++++++++++++++++++++++++++ |
||
491 | killagreg | 774 | } // else ref pos old not copied! |
775 | if(!retval) PointList_Clear(); |
||
776 | return(retval); |
||
777 | } |
||
778 | |||
779 | |||
780 |