Rev 304 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
85 | killagreg | 1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
||
3 | /*#######################################################################################*/ |
||
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
||
171 | ingob | 6 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
85 | killagreg | 7 | // + FOR NON COMMERCIAL USE ONLY |
8 | // + www.MikroKopter.com |
||
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
||
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
||
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
||
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
||
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
||
15 | // + Verkauf von Luftbildaufnahmen, usw. |
||
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
||
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
||
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
||
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
||
22 | // + eindeutig als Ursprung verlinkt werden |
||
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
||
25 | // + Benutzung auf eigene Gefahr |
||
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
||
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
171 | ingob | 28 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
85 | killagreg | 29 | // + mit unserer Zustimmung zulässig |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
||
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
||
34 | // + this list of conditions and the following disclaimer. |
||
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
||
36 | // + from this software without specific prior written permission. |
||
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
||
38 | // + for non-commercial use (directly or indirectly) |
||
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
||
40 | // + with our written permission |
||
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
||
42 | // + clearly linked as origin |
||
171 | ingob | 43 | // + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
85 | killagreg | 44 | // |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
55 | // + POSSIBILITY OF SUCH DAMAGE. |
||
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
57 | #include <stdlib.h> |
||
58 | #include <stdio.h> |
||
59 | #include "91x_lib.h" |
||
60 | #include "gpx.h" |
||
61 | #include "gpx_header.h" |
||
119 | killagreg | 62 | #include "timer1.h" |
86 | killagreg | 63 | #include "spi_slave.h" |
64 | #include "main.h" |
||
65 | #include "uart1.h" |
||
85 | killagreg | 66 | |
67 | //________________________________________________________________________________________________________________________________________ |
||
68 | // Function: GPX_DocumentInit(GPX_Document_t *) |
||
69 | // |
||
70 | // Description: This function initializes the gpx-document for further use. |
||
71 | // |
||
72 | // |
||
73 | // Returnvalue: '1' if document was initialized |
||
74 | //________________________________________________________________________________________________________________________________________ |
||
75 | |||
76 | u8 GPX_DocumentInit(GPX_Document_t *doc) |
||
77 | { |
||
78 | if(doc->state != GPX_DOC_CLOSED) GPX_DocumentClose(doc); // close file if it was opened before |
||
79 | doc->state = GPX_DOC_CLOSED; // init state of the gpx-document |
||
80 | doc->file = NULL; |
||
81 | return(1); |
||
82 | } |
||
83 | |||
84 | //________________________________________________________________________________________________________________________________________ |
||
85 | // Function: GPX_Document_Open(s8 *name, GPX_Document_t *doc); |
||
86 | // |
||
87 | // Description: This function opens a new gpx-document with the specified name and creates the document header within the file. |
||
88 | // |
||
89 | // |
||
90 | // Returnvalue: '1' if the gpx-file could be created. |
||
91 | //________________________________________________________________________________________________________________________________________ |
||
92 | |||
93 | u8 GPX_DocumentOpen(s8 *name, GPX_Document_t *doc) |
||
94 | { |
||
95 | |||
96 | u8 retvalue = 0; |
||
97 | |||
98 | if(doc == NULL) return(0); |
||
99 | GPX_DocumentInit(doc); // intialize the document with resetvalues |
||
100 | doc->file = fopen_(name,'a'); // open a new file with the specified filename on the memorycard. |
||
101 | |||
102 | if(doc->file != NULL) // could the file be opened? |
||
103 | { |
||
104 | retvalue = 1; // the document could be created on the drive. |
||
105 | doc->state = GPX_DOC_OPENED; // change document state to opened. At next a placemark has to be opened. |
||
106 | fwrite_((void*)GPX_DOCUMENT_HEADER, sizeof(GPX_DOCUMENT_HEADER)-1,1,doc->file);// write the gpx-header to the document. |
||
107 | } |
||
108 | |||
109 | return(retvalue); |
||
110 | } |
||
111 | |||
112 | //________________________________________________________________________________________________________________________________________ |
||
113 | // Function: DocumentClose(GPX_Document_t *doc); |
||
114 | // |
||
115 | // Description: This function closes the document specified by doc. |
||
116 | // |
||
117 | // |
||
118 | // Returnvalue: '1' if the gpx-file could be closed. |
||
119 | //________________________________________________________________________________________________________________________________________ |
||
120 | |||
121 | u8 GPX_DocumentClose(GPX_Document_t *doc) |
||
122 | { |
||
123 | |||
124 | u8 retvalue = 1; |
||
125 | |||
126 | if(doc == NULL) return(0); |
||
127 | |||
128 | while(doc->state != GPX_DOC_CLOSED) // close linestring, placemark and document before closing the file on the memorycard |
||
94 | killagreg | 129 | { |
85 | killagreg | 130 | switch(doc->state) |
131 | { |
||
132 | case GPX_DOC_TRACKSEGMENT_OPENED: |
||
133 | GPX_TrackSegmentEnd(doc); // write terminating tag to end tracksegment. |
||
134 | break; |
||
135 | |||
104 | killagreg | 136 | case GPX_DOC_TRACK_OPENED: // write terminating tag to close track. |
85 | killagreg | 137 | GPX_TrackEnd(doc); |
138 | break; |
||
139 | |||
140 | case GPX_DOC_OPENED: // close the file on the memorycard |
||
141 | if(doc->file != NULL) |
||
142 | { |
||
143 | fwrite_((void*)GPX_DOCUMENT_FOOTER, sizeof(GPX_DOCUMENT_FOOTER)-1,1,doc->file); // write the gpx-footer to the document. |
||
144 | fclose_(doc->file); |
||
145 | retvalue = 1; |
||
146 | } |
||
147 | doc->state = GPX_DOC_CLOSED; |
||
148 | break; |
||
149 | |||
150 | default: |
||
151 | doc->state = GPX_DOC_CLOSED; |
||
152 | break; |
||
153 | } |
||
154 | } |
||
155 | return(retvalue); |
||
156 | } |
||
157 | |||
158 | //________________________________________________________________________________________________________________________________________ |
||
159 | // Function: u8 GPX_TrackBegin(GPX_Document_t); |
||
160 | // |
||
161 | // Description: This function adds a track to the document. |
||
162 | // |
||
163 | // |
||
164 | // Returnvalue: '1' if the track could be opened |
||
165 | //________________________________________________________________________________________________________________________________________ |
||
166 | |||
167 | u8 GPX_TrackBegin(GPX_Document_t *doc) |
||
168 | { |
||
169 | |||
170 | u8 retvalue = 0; |
||
171 | if(doc->state == GPX_DOC_OPENED) |
||
172 | { |
||
173 | if(doc->file != NULL) |
||
174 | { |
||
175 | doc->state = GPX_DOC_TRACK_OPENED; |
||
176 | retvalue = 1; |
||
177 | fwrite_((void*)GPX_TRACK_HEADER, sizeof(GPX_TRACK_HEADER)-1,1,doc->file); |
||
178 | } |
||
179 | } |
||
180 | return(retvalue); |
||
181 | } |
||
182 | |||
183 | //________________________________________________________________________________________________________________________________________ |
||
184 | // Function: u8 GPX_TrackEnd(KML_Document_t *doc) |
||
185 | // |
||
186 | // Description: This function ends the track opened before. |
||
187 | // |
||
188 | // |
||
189 | // Returnvalue: 1' if the track could be closed |
||
190 | //________________________________________________________________________________________________________________________________________ |
||
191 | |||
192 | u8 GPX_TrackEnd(GPX_Document_t *doc) |
||
193 | { |
||
194 | |||
195 | u8 retvalue = 0; |
||
196 | |||
197 | if(doc->state == GPX_DOC_TRACK_OPENED) |
||
198 | { |
||
199 | if(doc->file != NULL) |
||
200 | { |
||
201 | doc->state = GPX_DOC_OPENED; |
||
202 | fwrite_((void*)GPX_TRACK_FOOTER, sizeof(GPX_TRACK_FOOTER)-1,1,doc->file); |
||
203 | retvalue = 1; |
||
204 | } |
||
205 | } |
||
206 | |||
207 | return(retvalue); |
||
208 | } |
||
209 | |||
210 | //________________________________________________________________________________________________________________________________________ |
||
211 | // Function: u8 GPX_TrackSegmentBegin(GPX_Document_t *doc); |
||
212 | // |
||
213 | // Description: This function starts a track segment. |
||
214 | // |
||
215 | // |
||
216 | // Returnvalue: '1' if the track segement could be started |
||
217 | //________________________________________________________________________________________________________________________________________ |
||
218 | |||
219 | u8 GPX_TrackSegmentBegin(GPX_Document_t *doc) |
||
220 | { |
||
221 | |||
222 | u8 retvalue = 0; |
||
223 | |||
224 | if(doc->state == GPX_DOC_TRACK_OPENED) |
||
225 | { |
||
226 | if(doc->file != NULL) |
||
227 | { |
||
228 | doc->state = GPX_DOC_TRACKSEGMENT_OPENED; |
||
229 | fwrite_((void*)GPX_TRACKSEGMENT_HEADER, sizeof(GPX_TRACKSEGMENT_HEADER)-1,1,doc->file); |
||
230 | retvalue = 1; |
||
231 | } |
||
232 | } |
||
233 | return(retvalue); |
||
234 | } |
||
235 | |||
236 | //________________________________________________________________________________________________________________________________________ |
||
237 | // Function: u8 GPX_TrackSegmentEnd(GPX_Document_t *doc); |
||
238 | // |
||
239 | // Description: This function ends the tracksegment opened before. |
||
240 | // |
||
241 | // |
||
242 | // Returnvalue: '1' if the track segment could be terminated |
||
243 | //________________________________________________________________________________________________________________________________________ |
||
244 | |||
245 | u8 GPX_TrackSegmentEnd(GPX_Document_t *doc) |
||
246 | { |
||
247 | |||
248 | u8 retvalue = 0; |
||
249 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) |
||
250 | { |
||
251 | if(doc->file != NULL) |
||
252 | { |
||
253 | doc->state = GPX_DOC_TRACK_OPENED; |
||
254 | fwrite_((void*)GPX_TRACKSEGMENT_FOOTER, sizeof(GPX_TRACKSEGMENT_FOOTER)-1,1,doc->file); |
||
255 | retvalue = 1; |
||
256 | } |
||
257 | } |
||
258 | return(retvalue); |
||
259 | } |
||
260 | |||
261 | //________________________________________________________________________________________________________________________________________ |
||
262 | // Function: u8 GPX_TrackSegementAddPoint(GPS_Pos_t * pGPS_Position ,GPX_Document_t *doc); |
||
263 | // |
||
264 | // Description: This function adds a pointof a track segement to the specified document. |
||
265 | // |
||
266 | // |
||
267 | // Returnvalue: '1' if a point was added |
||
268 | //________________________________________________________________________________________________________________________________________ |
||
269 | |||
270 | u8 GPX_TrackSegementAddPoint(GPX_Document_t *doc) |
||
271 | { |
||
272 | |||
273 | u8 retvalue = 0; |
||
274 | s8 string[50]; |
||
275 | |||
276 | if(doc == NULL) return(0); |
||
277 | |||
215 | killagreg | 278 | if((GPSData.Position.Status != INVALID) && (NaviData.HomePosition.Status != INVALID)) |
85 | killagreg | 279 | { |
280 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) |
||
281 | { |
||
282 | if(doc->file != NULL) |
||
283 | { |
||
86 | killagreg | 284 | s32 i32_1, i32_2; |
285 | s16 i16_1; |
||
286 | u8 u8_1, u8_2; |
||
85 | killagreg | 287 | // write <trkpt> tag |
86 | killagreg | 288 | if(GPSData.Position.Latitude < 0) u8_1 = '-'; |
289 | else u8_1 = '+'; |
||
290 | i32_1 = abs(GPSData.Position.Latitude)/10000000L; |
||
291 | i32_2 = abs(GPSData.Position.Latitude)%10000000L; |
||
292 | sprintf(string, "<trkpt lat=\"%c%ld.%07ld\" ",u8_1, i32_1, i32_2); |
||
85 | killagreg | 293 | fputs_(string, doc->file); |
86 | killagreg | 294 | if(GPSData.Position.Longitude < 0) u8_1 = '-'; |
295 | else u8_1 = '+'; |
||
296 | i32_1 = abs(GPSData.Position.Longitude)/10000000L; |
||
297 | i32_2 = abs(GPSData.Position.Longitude)%10000000L; |
||
298 | sprintf(string, "lon=\"%c%ld.%07ld\">\r\n",u8_1, i32_1, i32_2); |
||
85 | killagreg | 299 | fputs_(string, doc->file); |
300 | // write <ele> taga |
||
215 | killagreg | 301 | i32_2 = GPSData.Position.Altitude - NaviData.HomePosition.Altitude; |
86 | killagreg | 302 | if(i32_2 < 0) i32_2 = 0; // avoid negative altitudes in log |
303 | i32_1 = i32_2/1000L; |
||
304 | i32_2 = i32_2%1000L; |
||
305 | sprintf(string,"<ele>%ld.%03ld</ele>\r\n",i32_1, i32_2); |
||
85 | killagreg | 306 | fputs_(string, doc->file); |
307 | // write <time> tag only at a resolution of one second |
||
308 | sprintf(string, "<time>%04d-%02d-%02dT%02d:%02d:%02dZ</time>\r\n",SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Hour, SystemTime.Min, SystemTime.Sec); |
||
309 | fputs_(string, doc->file); |
||
86 | killagreg | 310 | // write <sat> tag |
311 | sprintf(string, "<sat>%d</sat>\r\n", NaviData.SatsInUse); |
||
312 | fputs_(string, doc->file); |
||
94 | killagreg | 313 | // todo: add <extensions> tag with additional data to be logged |
86 | killagreg | 314 | sprintf(string, "<extensions>\r\n"); |
315 | fputs_(string, doc->file); |
||
125 | killagreg | 316 | // Altimeter according to air pressure |
317 | sprintf(string, "<Altimeter>%d</Altimeter>\r\n", NaviData.Altimeter); |
||
126 | killagreg | 318 | fputs_(string, doc->file); |
140 | killagreg | 319 | // Variometer according to air pressure |
320 | sprintf(string, "<Variometer>%d</Variometer>\r\n", NaviData.Variometer); |
||
321 | fputs_(string, doc->file); |
||
92 | killagreg | 322 | // Course in deg |
86 | killagreg | 323 | i16_1 = GPSData.Heading/100000L; |
324 | sprintf(string, "<Course>%03d</Course>\r\n", i16_1); |
||
325 | fputs_(string, doc->file); |
||
92 | killagreg | 326 | // Ground Speed in cm/s |
86 | killagreg | 327 | sprintf(string, "<GroundSpeed>%d</GroundSpeed>\r\n", NaviData.GroundSpeed); |
328 | fputs_(string, doc->file); |
||
140 | killagreg | 329 | // Vertical Speed in cm/s |
330 | sprintf(string, "<VerticalSpeed>%d</VerticalSpeed>\r\n", NaviData.TopSpeed); |
||
331 | fputs_(string, doc->file); |
||
332 | // Flight duration |
||
101 | holgerb | 333 | sprintf(string, "<FlightTime>%d</FlightTime>\r\n", NaviData.FlyingTime); |
334 | fputs_(string, doc->file); |
||
86 | killagreg | 335 | // Ubat |
336 | u8_1 = NaviData.UBat / 10; |
||
337 | u8_2 = NaviData.UBat % 10; |
||
338 | sprintf(string, "<Voltage>%d.%01d</Voltage>\r\n", u8_1, u8_2); |
||
339 | fputs_(string, doc->file); |
||
206 | killagreg | 340 | // Current |
341 | u8_1 = NaviData.Current / 10; |
||
342 | u8_2 = NaviData.Current % 10; |
||
343 | sprintf(string, "<Current>%d.%01d</Current>\r\n", u8_1, u8_2); |
||
344 | fputs_(string, doc->file); |
||
345 | // Capacity |
||
346 | sprintf(string, "<Capacity>%d</Capacity>\r\n", NaviData.UsedCapacity); |
||
347 | fputs_(string, doc->file); |
||
86 | killagreg | 348 | // RC Quality |
349 | sprintf(string, "<RCQuality>%d</RCQuality>\r\n", FC.RC_Quality); |
||
350 | fputs_(string, doc->file); |
||
125 | killagreg | 351 | // RC Received Signal Strength Indication |
352 | sprintf(string, "<RCRSSI>%d</RCRSSI>\r\n", FC.RC_RSSI); |
||
353 | fputs_(string, doc->file); |
||
92 | killagreg | 354 | // Compassind deg |
86 | killagreg | 355 | i16_1 = FromFlightCtrl.GyroHeading / 10; |
356 | sprintf(string, "<Compass>%03d</Compass>\r\n", i16_1); |
||
357 | fputs_(string, doc->file); |
||
92 | killagreg | 358 | // Nick Angle ind deg |
86 | killagreg | 359 | sprintf(string, "<NickAngle>%03d</NickAngle>\r\n", NaviData.AngleNick); |
360 | fputs_(string, doc->file); |
||
92 | killagreg | 361 | // Roll Angle in deg |
86 | killagreg | 362 | sprintf(string, "<RollAngle>%03d</RollAngle>\r\n", NaviData.AngleRoll); |
363 | fputs_(string, doc->file); |
||
92 | killagreg | 364 | // NC Mode (contains the status) |
365 | sprintf(string, "<NCFlag>%02X</NCFlag>\r\n", NCFlags); |
||
86 | killagreg | 366 | fputs_(string, doc->file); |
233 | holgerb | 367 | // Status of the complete MikroKopter |
368 | sprintf(string, "<ErrorCode>%03d</ErrorCode>\r\n",ErrorCode); |
||
369 | fputs_(string, doc->file); |
||
92 | killagreg | 370 | // Target Bearing in deg |
86 | killagreg | 371 | sprintf(string, "<TargetBearing>%03d</TargetBearing>\r\n", NaviData.TargetPositionDeviation.Bearing); |
372 | fputs_(string, doc->file); |
||
92 | killagreg | 373 | // Target Distance in dm |
86 | killagreg | 374 | sprintf(string, "<TargetDistance>%d</TargetDistance>\r\n", NaviData.TargetPositionDeviation.Distance); |
375 | fputs_(string, doc->file); |
||
101 | holgerb | 376 | // RC Sticks as Nick/Roll/Yaw |
377 | sprintf(string, "<RCSticks>%d, %d, %d</RCSticks>\r\n", FC.StickNick,FC.StickRoll, FC.StickYaw); |
||
378 | fputs_(string, doc->file); |
||
94 | killagreg | 379 | // GPS Sticks as Nick/Roll/Yaw |
215 | killagreg | 380 | sprintf(string, "<GPSSticks>%d, %d, %d</GPSSticks>\r\n", ToFlightCtrl.GPSStick.Nick, ToFlightCtrl.GPSStick.Roll, ToFlightCtrl.GPSStick.Yaw); |
94 | killagreg | 381 | fputs_(string, doc->file); |
101 | holgerb | 382 | |
86 | killagreg | 383 | // eof extensions |
384 | sprintf(string, "</extensions>\r\n"); |
||
385 | fputs_(string, doc->file); |
||
85 | killagreg | 386 | sprintf(string, "</trkpt>\r\n"); |
387 | fputs_(string, doc->file); |
||
388 | retvalue = 1; |
||
389 | } |
||
390 | } |
||
391 | } |
||
392 | return(retvalue); |
||
393 | } |
||
394 | |||
395 | //________________________________________________________________________________________________________________________________________ |
||
396 | // Function: u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *) |
||
397 | // |
||
398 | // Description: This function opens and adds gpscoordinates to an GPX-Document. The document will be opened, if not already done |
||
399 | // |
||
400 | // |
||
401 | // Returnvalue: '1' if an gps coordinate was logged |
||
402 | //________________________________________________________________________________________________________________________________________ |
||
403 | |||
404 | u8 GPX_LoggGPSCoordinates(GPX_Document_t *doc) |
||
405 | { |
||
406 | u8 retval = 0; |
||
407 | while(doc->state != GPX_DOC_TRACKSEGMENT_OPENED) // automatic create document with default filename on the card. |
||
408 | { |
||
409 | switch(doc->state) |
||
410 | { |
||
411 | case GPX_DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically |
||
412 | retval = GPX_DocumentOpen("default.gpx",doc); // open the gpx-document with a standardname. |
||
413 | break; |
||
414 | |||
415 | case GPX_DOC_OPENED: // if a document has been opened before but no track exists: |
||
416 | retval = GPX_TrackBegin(doc); |
||
417 | break; |
||
418 | |||
419 | case GPX_DOC_TRACK_OPENED: // add tracksegement to the track |
||
420 | retval = GPX_TrackSegmentBegin(doc); |
||
421 | break; |
||
422 | |||
423 | default: |
||
424 | retval = 0; |
||
425 | break; |
||
426 | |||
427 | } |
||
428 | if(retval != 1) return(retval); // stop on error |
||
429 | } |
||
430 | |||
431 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) // if the document was opened add coordinates to the document. |
||
432 | { |
||
433 | retval = GPX_TrackSegementAddPoint(doc); // add a track segment point |
||
434 | } |
||
435 | return(retval); |
||
436 | } |
||
437 |