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