Rev 338 | Go to most recent revision | 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" |
||
338 | holgerb | 66 | #include "compass.h" |
67 | #include "analog.h" |
||
68 | #include "main.h" |
||
69 | #include "led.h" |
||
85 | killagreg | 70 | |
71 | //________________________________________________________________________________________________________________________________________ |
||
72 | // Function: GPX_DocumentInit(GPX_Document_t *) |
||
73 | // |
||
74 | // Description: This function initializes the gpx-document for further use. |
||
75 | // |
||
76 | // |
||
77 | // Returnvalue: '1' if document was initialized |
||
78 | //________________________________________________________________________________________________________________________________________ |
||
79 | |||
80 | u8 GPX_DocumentInit(GPX_Document_t *doc) |
||
81 | { |
||
82 | if(doc->state != GPX_DOC_CLOSED) GPX_DocumentClose(doc); // close file if it was opened before |
||
83 | doc->state = GPX_DOC_CLOSED; // init state of the gpx-document |
||
84 | doc->file = NULL; |
||
85 | return(1); |
||
86 | } |
||
87 | |||
88 | //________________________________________________________________________________________________________________________________________ |
||
89 | // Function: GPX_Document_Open(s8 *name, GPX_Document_t *doc); |
||
90 | // |
||
91 | // Description: This function opens a new gpx-document with the specified name and creates the document header within the file. |
||
92 | // |
||
93 | // |
||
94 | // Returnvalue: '1' if the gpx-file could be created. |
||
95 | //________________________________________________________________________________________________________________________________________ |
||
96 | |||
338 | holgerb | 97 | |
85 | killagreg | 98 | u8 GPX_DocumentOpen(s8 *name, GPX_Document_t *doc) |
99 | { |
||
338 | holgerb | 100 | s8 string[60]; |
85 | killagreg | 101 | u8 retvalue = 0; |
102 | |||
103 | if(doc == NULL) return(0); |
||
104 | GPX_DocumentInit(doc); // intialize the document with resetvalues |
||
105 | doc->file = fopen_(name,'a'); // open a new file with the specified filename on the memorycard. |
||
106 | |||
107 | if(doc->file != NULL) // could the file be opened? |
||
108 | { |
||
109 | retvalue = 1; // the document could be created on the drive. |
||
110 | doc->state = GPX_DOC_OPENED; // change document state to opened. At next a placemark has to be opened. |
||
338 | holgerb | 111 | fwrite_((void*)GPX_DOCUMENT_HEADER1, sizeof(GPX_DOCUMENT_HEADER1)-1,1,doc->file);// write the gpx-header to the document. |
339 | holgerb | 112 | sprintf(string, "<desc>FC HW:%d.%d SW:%d.%d%c + NC HW:%d.%d SW:%d.%d%c</desc>\r\n", FC_Version.Hardware/10,FC_Version.Hardware%10, FC_Version.Major, FC_Version.Minor, 'a'+FC_Version.Patch, Version_HW/10, Version_HW%10, VERSION_MAJOR, VERSION_MINOR, 'a'+ VERSION_PATCH); |
338 | holgerb | 113 | fputs_(string, doc->file); |
114 | fwrite_((void*)GPX_DOCUMENT_HEADER2, sizeof(GPX_DOCUMENT_HEADER2)-1,1,doc->file);// write the gpx-header to the document. |
||
85 | killagreg | 115 | } |
338 | holgerb | 116 | Logging_FCStatusFlags1 = 0; |
117 | Logging_FCStatusFlags2 = 0; |
||
85 | killagreg | 118 | return(retvalue); |
119 | } |
||
120 | |||
121 | //________________________________________________________________________________________________________________________________________ |
||
122 | // Function: DocumentClose(GPX_Document_t *doc); |
||
123 | // |
||
124 | // Description: This function closes the document specified by doc. |
||
125 | // |
||
126 | // |
||
127 | // Returnvalue: '1' if the gpx-file could be closed. |
||
128 | //________________________________________________________________________________________________________________________________________ |
||
129 | |||
130 | u8 GPX_DocumentClose(GPX_Document_t *doc) |
||
131 | { |
||
132 | |||
133 | u8 retvalue = 1; |
||
134 | |||
135 | if(doc == NULL) return(0); |
||
136 | |||
137 | while(doc->state != GPX_DOC_CLOSED) // close linestring, placemark and document before closing the file on the memorycard |
||
94 | killagreg | 138 | { |
85 | killagreg | 139 | switch(doc->state) |
140 | { |
||
141 | case GPX_DOC_TRACKSEGMENT_OPENED: |
||
142 | GPX_TrackSegmentEnd(doc); // write terminating tag to end tracksegment. |
||
143 | break; |
||
144 | |||
104 | killagreg | 145 | case GPX_DOC_TRACK_OPENED: // write terminating tag to close track. |
85 | killagreg | 146 | GPX_TrackEnd(doc); |
147 | break; |
||
148 | |||
149 | case GPX_DOC_OPENED: // close the file on the memorycard |
||
150 | if(doc->file != NULL) |
||
151 | { |
||
152 | fwrite_((void*)GPX_DOCUMENT_FOOTER, sizeof(GPX_DOCUMENT_FOOTER)-1,1,doc->file); // write the gpx-footer to the document. |
||
153 | fclose_(doc->file); |
||
154 | retvalue = 1; |
||
155 | } |
||
156 | doc->state = GPX_DOC_CLOSED; |
||
157 | break; |
||
158 | |||
159 | default: |
||
160 | doc->state = GPX_DOC_CLOSED; |
||
161 | break; |
||
162 | } |
||
163 | } |
||
164 | return(retvalue); |
||
165 | } |
||
166 | |||
338 | holgerb | 167 | |
168 | |||
85 | killagreg | 169 | //________________________________________________________________________________________________________________________________________ |
170 | // Function: u8 GPX_TrackBegin(GPX_Document_t); |
||
171 | // |
||
172 | // Description: This function adds a track to the document. |
||
173 | // |
||
174 | // |
||
175 | // Returnvalue: '1' if the track could be opened |
||
176 | //________________________________________________________________________________________________________________________________________ |
||
177 | |||
178 | u8 GPX_TrackBegin(GPX_Document_t *doc) |
||
179 | { |
||
180 | |||
181 | u8 retvalue = 0; |
||
182 | if(doc->state == GPX_DOC_OPENED) |
||
183 | { |
||
184 | if(doc->file != NULL) |
||
185 | { |
||
186 | doc->state = GPX_DOC_TRACK_OPENED; |
||
187 | retvalue = 1; |
||
188 | fwrite_((void*)GPX_TRACK_HEADER, sizeof(GPX_TRACK_HEADER)-1,1,doc->file); |
||
189 | } |
||
190 | } |
||
191 | return(retvalue); |
||
192 | } |
||
193 | |||
338 | holgerb | 194 | |
85 | killagreg | 195 | //________________________________________________________________________________________________________________________________________ |
196 | // Function: u8 GPX_TrackEnd(KML_Document_t *doc) |
||
197 | // |
||
198 | // Description: This function ends the track opened before. |
||
199 | // |
||
200 | // |
||
201 | // Returnvalue: 1' if the track could be closed |
||
202 | //________________________________________________________________________________________________________________________________________ |
||
203 | |||
204 | u8 GPX_TrackEnd(GPX_Document_t *doc) |
||
205 | { |
||
206 | |||
207 | u8 retvalue = 0; |
||
208 | |||
209 | if(doc->state == GPX_DOC_TRACK_OPENED) |
||
210 | { |
||
211 | if(doc->file != NULL) |
||
212 | { |
||
213 | doc->state = GPX_DOC_OPENED; |
||
214 | fwrite_((void*)GPX_TRACK_FOOTER, sizeof(GPX_TRACK_FOOTER)-1,1,doc->file); |
||
215 | retvalue = 1; |
||
216 | } |
||
217 | } |
||
218 | |||
219 | return(retvalue); |
||
220 | } |
||
221 | |||
222 | //________________________________________________________________________________________________________________________________________ |
||
223 | // Function: u8 GPX_TrackSegmentBegin(GPX_Document_t *doc); |
||
224 | // |
||
225 | // Description: This function starts a track segment. |
||
226 | // |
||
227 | // |
||
228 | // Returnvalue: '1' if the track segement could be started |
||
229 | //________________________________________________________________________________________________________________________________________ |
||
230 | |||
231 | u8 GPX_TrackSegmentBegin(GPX_Document_t *doc) |
||
232 | { |
||
233 | |||
234 | u8 retvalue = 0; |
||
235 | |||
236 | if(doc->state == GPX_DOC_TRACK_OPENED) |
||
237 | { |
||
238 | if(doc->file != NULL) |
||
239 | { |
||
240 | doc->state = GPX_DOC_TRACKSEGMENT_OPENED; |
||
241 | fwrite_((void*)GPX_TRACKSEGMENT_HEADER, sizeof(GPX_TRACKSEGMENT_HEADER)-1,1,doc->file); |
||
242 | retvalue = 1; |
||
243 | } |
||
244 | } |
||
245 | return(retvalue); |
||
246 | } |
||
247 | |||
248 | //________________________________________________________________________________________________________________________________________ |
||
249 | // Function: u8 GPX_TrackSegmentEnd(GPX_Document_t *doc); |
||
250 | // |
||
251 | // Description: This function ends the tracksegment opened before. |
||
252 | // |
||
253 | // |
||
254 | // Returnvalue: '1' if the track segment could be terminated |
||
255 | //________________________________________________________________________________________________________________________________________ |
||
256 | |||
257 | u8 GPX_TrackSegmentEnd(GPX_Document_t *doc) |
||
258 | { |
||
259 | |||
260 | u8 retvalue = 0; |
||
261 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) |
||
262 | { |
||
263 | if(doc->file != NULL) |
||
264 | { |
||
265 | doc->state = GPX_DOC_TRACK_OPENED; |
||
266 | fwrite_((void*)GPX_TRACKSEGMENT_FOOTER, sizeof(GPX_TRACKSEGMENT_FOOTER)-1,1,doc->file); |
||
267 | retvalue = 1; |
||
268 | } |
||
269 | } |
||
270 | return(retvalue); |
||
271 | } |
||
272 | |||
273 | //________________________________________________________________________________________________________________________________________ |
||
274 | // Function: u8 GPX_TrackSegementAddPoint(GPS_Pos_t * pGPS_Position ,GPX_Document_t *doc); |
||
275 | // |
||
276 | // Description: This function adds a pointof a track segement to the specified document. |
||
277 | // |
||
278 | // |
||
279 | // Returnvalue: '1' if a point was added |
||
280 | //________________________________________________________________________________________________________________________________________ |
||
281 | |||
282 | u8 GPX_TrackSegementAddPoint(GPX_Document_t *doc) |
||
283 | { |
||
284 | |||
285 | u8 retvalue = 0; |
||
338 | holgerb | 286 | s8 string[100]; |
85 | killagreg | 287 | |
288 | if(doc == NULL) return(0); |
||
289 | |||
215 | killagreg | 290 | if((GPSData.Position.Status != INVALID) && (NaviData.HomePosition.Status != INVALID)) |
85 | killagreg | 291 | { |
292 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) |
||
293 | { |
||
294 | if(doc->file != NULL) |
||
295 | { |
||
86 | killagreg | 296 | s32 i32_1, i32_2; |
297 | s16 i16_1; |
||
298 | u8 u8_1, u8_2; |
||
85 | killagreg | 299 | // write <trkpt> tag |
86 | killagreg | 300 | if(GPSData.Position.Latitude < 0) u8_1 = '-'; |
301 | else u8_1 = '+'; |
||
302 | i32_1 = abs(GPSData.Position.Latitude)/10000000L; |
||
303 | i32_2 = abs(GPSData.Position.Latitude)%10000000L; |
||
304 | sprintf(string, "<trkpt lat=\"%c%ld.%07ld\" ",u8_1, i32_1, i32_2); |
||
85 | killagreg | 305 | fputs_(string, doc->file); |
86 | killagreg | 306 | if(GPSData.Position.Longitude < 0) u8_1 = '-'; |
307 | else u8_1 = '+'; |
||
308 | i32_1 = abs(GPSData.Position.Longitude)/10000000L; |
||
309 | i32_2 = abs(GPSData.Position.Longitude)%10000000L; |
||
310 | sprintf(string, "lon=\"%c%ld.%07ld\">\r\n",u8_1, i32_1, i32_2); |
||
85 | killagreg | 311 | fputs_(string, doc->file); |
312 | // write <ele> taga |
||
215 | killagreg | 313 | i32_2 = GPSData.Position.Altitude - NaviData.HomePosition.Altitude; |
86 | killagreg | 314 | if(i32_2 < 0) i32_2 = 0; // avoid negative altitudes in log |
315 | i32_1 = i32_2/1000L; |
||
316 | i32_2 = i32_2%1000L; |
||
317 | sprintf(string,"<ele>%ld.%03ld</ele>\r\n",i32_1, i32_2); |
||
85 | killagreg | 318 | fputs_(string, doc->file); |
319 | // write <time> tag only at a resolution of one second |
||
320 | sprintf(string, "<time>%04d-%02d-%02dT%02d:%02d:%02dZ</time>\r\n",SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Hour, SystemTime.Min, SystemTime.Sec); |
||
321 | fputs_(string, doc->file); |
||
86 | killagreg | 322 | // write <sat> tag |
323 | sprintf(string, "<sat>%d</sat>\r\n", NaviData.SatsInUse); |
||
324 | fputs_(string, doc->file); |
||
94 | killagreg | 325 | // todo: add <extensions> tag with additional data to be logged |
86 | killagreg | 326 | sprintf(string, "<extensions>\r\n"); |
327 | fputs_(string, doc->file); |
||
125 | killagreg | 328 | // Altimeter according to air pressure |
338 | holgerb | 329 | sprintf(string, "<Altimeter>%d,'%c'</Altimeter>\r\n", NaviData.Altimeter,FromFC_VarioCharacter); |
126 | killagreg | 330 | fputs_(string, doc->file); |
140 | killagreg | 331 | // Variometer according to air pressure |
332 | sprintf(string, "<Variometer>%d</Variometer>\r\n", NaviData.Variometer); |
||
333 | fputs_(string, doc->file); |
||
92 | killagreg | 334 | // Course in deg |
86 | killagreg | 335 | i16_1 = GPSData.Heading/100000L; |
336 | sprintf(string, "<Course>%03d</Course>\r\n", i16_1); |
||
337 | fputs_(string, doc->file); |
||
92 | killagreg | 338 | // Ground Speed in cm/s |
86 | killagreg | 339 | sprintf(string, "<GroundSpeed>%d</GroundSpeed>\r\n", NaviData.GroundSpeed); |
340 | fputs_(string, doc->file); |
||
140 | killagreg | 341 | // Vertical Speed in cm/s |
342 | sprintf(string, "<VerticalSpeed>%d</VerticalSpeed>\r\n", NaviData.TopSpeed); |
||
343 | fputs_(string, doc->file); |
||
344 | // Flight duration |
||
101 | holgerb | 345 | sprintf(string, "<FlightTime>%d</FlightTime>\r\n", NaviData.FlyingTime); |
346 | fputs_(string, doc->file); |
||
86 | killagreg | 347 | // Ubat |
348 | u8_1 = NaviData.UBat / 10; |
||
349 | u8_2 = NaviData.UBat % 10; |
||
350 | sprintf(string, "<Voltage>%d.%01d</Voltage>\r\n", u8_1, u8_2); |
||
351 | fputs_(string, doc->file); |
||
206 | killagreg | 352 | // Current |
353 | u8_1 = NaviData.Current / 10; |
||
354 | u8_2 = NaviData.Current % 10; |
||
355 | sprintf(string, "<Current>%d.%01d</Current>\r\n", u8_1, u8_2); |
||
356 | fputs_(string, doc->file); |
||
357 | // Capacity |
||
358 | sprintf(string, "<Capacity>%d</Capacity>\r\n", NaviData.UsedCapacity); |
||
359 | fputs_(string, doc->file); |
||
86 | killagreg | 360 | // RC Quality |
361 | sprintf(string, "<RCQuality>%d</RCQuality>\r\n", FC.RC_Quality); |
||
362 | fputs_(string, doc->file); |
||
125 | killagreg | 363 | // RC Received Signal Strength Indication |
364 | sprintf(string, "<RCRSSI>%d</RCRSSI>\r\n", FC.RC_RSSI); |
||
365 | fputs_(string, doc->file); |
||
92 | killagreg | 366 | // Compassind deg |
86 | killagreg | 367 | i16_1 = FromFlightCtrl.GyroHeading / 10; |
338 | holgerb | 368 | sprintf(string, "<Compass>%03d,%03d</Compass>\r\n", i16_1,ToFlightCtrl.CompassHeading); |
86 | killagreg | 369 | fputs_(string, doc->file); |
92 | killagreg | 370 | // Nick Angle ind deg |
86 | killagreg | 371 | sprintf(string, "<NickAngle>%03d</NickAngle>\r\n", NaviData.AngleNick); |
372 | fputs_(string, doc->file); |
||
92 | killagreg | 373 | // Roll Angle in deg |
86 | killagreg | 374 | sprintf(string, "<RollAngle>%03d</RollAngle>\r\n", NaviData.AngleRoll); |
375 | fputs_(string, doc->file); |
||
338 | holgerb | 376 | // magnetic field |
377 | sprintf(string, "<MagnetField>%03d</MagnetField>\r\n",(u16) (EarthMagneticField/5)); |
||
378 | fputs_(string, doc->file); |
||
379 | // magnetic inclination & error |
||
380 | sprintf(string, "<MagnetInclination>%02d,%02d</MagnetInclination>\r\n",(s16)EarthMagneticInclination,(s16)(EarthMagneticInclination - EarthMagneticInclinationTheoretic)); |
||
381 | fputs_(string, doc->file); |
||
382 | // BL Information |
||
383 | sprintf(string, "<MotorCurrent>%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d</MotorCurrent>\r\n",MotorCurrent[0],MotorCurrent[1],MotorCurrent[2],MotorCurrent[3],MotorCurrent[4],MotorCurrent[5],MotorCurrent[6],MotorCurrent[7],MotorCurrent[8],MotorCurrent[9],MotorCurrent[10],MotorCurrent[11]); |
||
384 | fputs_(string, doc->file); |
||
385 | sprintf(string, "<BL_Temperature>%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d</BL_Temperature>\r\n",MotorTemperature[0],MotorTemperature[1],MotorTemperature[2],MotorTemperature[3],MotorTemperature[4],MotorTemperature[5],MotorTemperature[6],MotorTemperature[7],MotorTemperature[8],MotorTemperature[9],MotorTemperature[10],MotorTemperature[11]); |
||
386 | fputs_(string, doc->file); |
||
387 | sprintf(string, "<AvaiableMotorPower>%03d</AvaiableMotorPower>\r\n",BL_MinOfMaxPWM); |
||
388 | fputs_(string, doc->file); |
||
389 | sprintf(string, "<FC_I2C_ErrorCounter>%03d</FC_I2C_ErrorCounter>\r\n",(s16)FC_I2C_ErrorConter); |
||
390 | fputs_(string, doc->file); |
||
391 | // Analog inputs of the NC |
||
392 | sprintf(string, "<AnalogInputs>%d,%d,%d,%d</AnalogInputs>\r\n",AnalogData.Ch4,AnalogData.Ch5,AnalogData.Ch6,AnalogData.Ch7); |
||
393 | fputs_(string, doc->file); |
||
92 | killagreg | 394 | // NC Mode (contains the status) |
338 | holgerb | 395 | sprintf(string, "<NCFlag>0x%02X</NCFlag>\r\n", NCFlags); |
86 | killagreg | 396 | fputs_(string, doc->file); |
338 | holgerb | 397 | // Flags |
398 | sprintf(string, "<FCFlags2>0x%02x,0x%02x</FCFlags2>\r\n",Logging_FCStatusFlags1,Logging_FCStatusFlags2); |
||
399 | fputs_(string, doc->file); |
||
400 | Logging_FCStatusFlags1 = 0; |
||
401 | Logging_FCStatusFlags2 = 0; |
||
233 | holgerb | 402 | // Status of the complete MikroKopter |
403 | sprintf(string, "<ErrorCode>%03d</ErrorCode>\r\n",ErrorCode); |
||
404 | fputs_(string, doc->file); |
||
92 | killagreg | 405 | // Target Bearing in deg |
86 | killagreg | 406 | sprintf(string, "<TargetBearing>%03d</TargetBearing>\r\n", NaviData.TargetPositionDeviation.Bearing); |
407 | fputs_(string, doc->file); |
||
92 | killagreg | 408 | // Target Distance in dm |
86 | killagreg | 409 | sprintf(string, "<TargetDistance>%d</TargetDistance>\r\n", NaviData.TargetPositionDeviation.Distance); |
410 | fputs_(string, doc->file); |
||
101 | holgerb | 411 | // RC Sticks as Nick/Roll/Yaw |
338 | holgerb | 412 | sprintf(string, "<RCSticks>%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d</RCSticks>\r\n", FC.StickNick,FC.StickRoll, FC.StickYaw, FC.StickGas,FC.Poti[0],FC.Poti[1],FC.Poti[2],FC.Poti[3],FC.Poti[4],FC.Poti[5],FC.Poti[6],FC.Poti[7]); |
101 | holgerb | 413 | fputs_(string, doc->file); |
94 | killagreg | 414 | // GPS Sticks as Nick/Roll/Yaw |
338 | holgerb | 415 | sprintf(string, "<GPSSticks>%d,%d,%d,'%c'</GPSSticks>\r\n", ToFlightCtrl.GPSStick.Nick, ToFlightCtrl.GPSStick.Roll, ToFlightCtrl.GPSStick.Yaw,NC_GPS_ModeCharacter); |
94 | killagreg | 416 | fputs_(string, doc->file); |
86 | killagreg | 417 | // eof extensions |
418 | sprintf(string, "</extensions>\r\n"); |
||
419 | fputs_(string, doc->file); |
||
85 | killagreg | 420 | sprintf(string, "</trkpt>\r\n"); |
421 | fputs_(string, doc->file); |
||
422 | retvalue = 1; |
||
423 | } |
||
424 | } |
||
425 | } |
||
426 | return(retvalue); |
||
427 | } |
||
428 | |||
429 | //________________________________________________________________________________________________________________________________________ |
||
430 | // Function: u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *) |
||
431 | // |
||
432 | // Description: This function opens and adds gpscoordinates to an GPX-Document. The document will be opened, if not already done |
||
433 | // |
||
434 | // |
||
435 | // Returnvalue: '1' if an gps coordinate was logged |
||
436 | //________________________________________________________________________________________________________________________________________ |
||
437 | |||
438 | u8 GPX_LoggGPSCoordinates(GPX_Document_t *doc) |
||
439 | { |
||
440 | u8 retval = 0; |
||
441 | while(doc->state != GPX_DOC_TRACKSEGMENT_OPENED) // automatic create document with default filename on the card. |
||
442 | { |
||
443 | switch(doc->state) |
||
444 | { |
||
445 | case GPX_DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically |
||
324 | killagreg | 446 | retval = GPX_DocumentOpen("default.gpx",doc); // open the gpx-document with a standardname. |
85 | killagreg | 447 | break; |
448 | |||
449 | case GPX_DOC_OPENED: // if a document has been opened before but no track exists: |
||
450 | retval = GPX_TrackBegin(doc); |
||
451 | break; |
||
452 | |||
453 | case GPX_DOC_TRACK_OPENED: // add tracksegement to the track |
||
454 | retval = GPX_TrackSegmentBegin(doc); |
||
455 | break; |
||
456 | |||
457 | default: |
||
458 | retval = 0; |
||
459 | break; |
||
460 | |||
461 | } |
||
462 | if(retval != 1) return(retval); // stop on error |
||
463 | } |
||
464 | |||
465 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) // if the document was opened add coordinates to the document. |
||
466 | { |
||
467 | retval = GPX_TrackSegementAddPoint(doc); // add a track segment point |
||
468 | } |
||
469 | return(retval); |
||
470 | } |
||
471 |