Subversion Repositories NaviCtrl

Rev

Rev 340 | Rev 351 | 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
 
345 holgerb 282
u8 GPX_TrackSegementAddPoint(GPX_Document_t *doc,unsigned char part)
85 killagreg 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
345 holgerb 300
                        switch(part)
301
                          {
302
                           case 0:
86 killagreg 303
                                if(GPSData.Position.Latitude < 0) u8_1 = '-';
304
                                else u8_1 = '+';
305
                                i32_1 = abs(GPSData.Position.Latitude)/10000000L;
306
                                i32_2 = abs(GPSData.Position.Latitude)%10000000L;
307
                                sprintf(string, "<trkpt lat=\"%c%ld.%07ld\" ",u8_1, i32_1, i32_2);
85 killagreg 308
                                fputs_(string, doc->file);
86 killagreg 309
                                if(GPSData.Position.Longitude < 0) u8_1 = '-';
310
                                else u8_1 = '+';
311
                                i32_1 = abs(GPSData.Position.Longitude)/10000000L;
312
                                i32_2 = abs(GPSData.Position.Longitude)%10000000L;
313
                                sprintf(string, "lon=\"%c%ld.%07ld\">\r\n",u8_1, i32_1, i32_2);
85 killagreg 314
                                fputs_(string, doc->file);
345 holgerb 315
                           break;
316
                           case 1:
85 killagreg 317
                                // write <ele> taga
215 killagreg 318
                                i32_2 = GPSData.Position.Altitude - NaviData.HomePosition.Altitude;
86 killagreg 319
                                if(i32_2 < 0) i32_2 = 0; // avoid negative altitudes in log
320
                                i32_1 = i32_2/1000L;
321
                                i32_2 = i32_2%1000L;
322
                                sprintf(string,"<ele>%ld.%03ld</ele>\r\n",i32_1, i32_2);
85 killagreg 323
                                fputs_(string, doc->file);
324
                                // write <time> tag     only at a resolution of one second
325
                                sprintf(string, "<time>%04d-%02d-%02dT%02d:%02d:%02dZ</time>\r\n",SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Hour, SystemTime.Min, SystemTime.Sec);
326
                                fputs_(string, doc->file);
86 killagreg 327
                                // write <sat> tag
328
                                sprintf(string, "<sat>%d</sat>\r\n", NaviData.SatsInUse);
329
                                fputs_(string, doc->file);
94 killagreg 330
                                // todo: add  <extensions> tag with additional data to be logged
86 killagreg 331
                                sprintf(string, "<extensions>\r\n");
332
                                fputs_(string, doc->file);
345 holgerb 333
                           break;
334
                           case 2:
125 killagreg 335
                                // Altimeter according to air pressure
338 holgerb 336
                                sprintf(string, "<Altimeter>%d,'%c'</Altimeter>\r\n", NaviData.Altimeter,FromFC_VarioCharacter);
126 killagreg 337
                                fputs_(string, doc->file);
140 killagreg 338
                                // Variometer according to air pressure
339
                                sprintf(string, "<Variometer>%d</Variometer>\r\n", NaviData.Variometer);
340
                                fputs_(string, doc->file);
92 killagreg 341
                                // Course in deg
86 killagreg 342
                                i16_1 = GPSData.Heading/100000L;
343
                                sprintf(string, "<Course>%03d</Course>\r\n", i16_1);
344
                                fputs_(string, doc->file);
92 killagreg 345
                                // Ground Speed in cm/s
86 killagreg 346
                                sprintf(string, "<GroundSpeed>%d</GroundSpeed>\r\n", NaviData.GroundSpeed);
347
                                fputs_(string, doc->file);
140 killagreg 348
                                // Vertical Speed in cm/s
349
                                sprintf(string, "<VerticalSpeed>%d</VerticalSpeed>\r\n", NaviData.TopSpeed);
350
                                fputs_(string, doc->file);
351
                                // Flight duration
101 holgerb 352
                                sprintf(string, "<FlightTime>%d</FlightTime>\r\n", NaviData.FlyingTime);
353
                                fputs_(string, doc->file);
345 holgerb 354
                           break;
355
                           case 3:
86 killagreg 356
                                // Ubat
357
                                u8_1 = NaviData.UBat / 10;
358
                                u8_2 = NaviData.UBat % 10;
359
                                sprintf(string, "<Voltage>%d.%01d</Voltage>\r\n", u8_1, u8_2);
360
                                fputs_(string, doc->file);
206 killagreg 361
                                // Current
362
                                u8_1 = NaviData.Current / 10;
363
                                u8_2 = NaviData.Current % 10;
364
                                sprintf(string, "<Current>%d.%01d</Current>\r\n", u8_1, u8_2);
365
                                fputs_(string, doc->file);
366
                                // Capacity
367
                                sprintf(string, "<Capacity>%d</Capacity>\r\n", NaviData.UsedCapacity);
368
                                fputs_(string, doc->file);
86 killagreg 369
                                // RC Quality
370
                                sprintf(string, "<RCQuality>%d</RCQuality>\r\n", FC.RC_Quality);
371
                                fputs_(string, doc->file);
125 killagreg 372
                                // RC Received Signal Strength Indication
345 holgerb 373
                           break;
374
                           case 4:
125 killagreg 375
                                sprintf(string, "<RCRSSI>%d</RCRSSI>\r\n", FC.RC_RSSI);
376
                                fputs_(string, doc->file);
92 killagreg 377
                                // Compassind deg
86 killagreg 378
                                i16_1 = FromFlightCtrl.GyroHeading / 10;
338 holgerb 379
                                sprintf(string, "<Compass>%03d,%03d</Compass>\r\n", i16_1,ToFlightCtrl.CompassHeading);
86 killagreg 380
                                fputs_(string, doc->file);
92 killagreg 381
                                // Nick Angle ind deg
86 killagreg 382
                                sprintf(string, "<NickAngle>%03d</NickAngle>\r\n", NaviData.AngleNick);
383
                                fputs_(string, doc->file);
92 killagreg 384
                                // Roll Angle in deg
86 killagreg 385
                                sprintf(string, "<RollAngle>%03d</RollAngle>\r\n", NaviData.AngleRoll);
386
                                fputs_(string, doc->file);
345 holgerb 387
                           break;
388
                           case 5:
338 holgerb 389
                                // magnetic field 
340 holgerb 390
                                sprintf(string, "<MagnetField>%03d</MagnetField>\r\n",(u16) (EarthMagneticFieldFiltered/5));
338 holgerb 391
                                fputs_(string, doc->file);
392
                                // magnetic inclination & error 
340 holgerb 393
                                sprintf(string, "<MagnetInclination>%02d,%02d</MagnetInclination>\r\n",(s16)EarthMagneticInclinationFiltered/10,(s16)(EarthMagneticInclinationFiltered/10 - EarthMagneticInclinationTheoretic));
338 holgerb 394
                                fputs_(string, doc->file);
395
                                // BL Information
396
                                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]);
397
                                fputs_(string, doc->file);
398
                                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]);
399
                                fputs_(string, doc->file);
345 holgerb 400
                           break;
401
                           case 6:
338 holgerb 402
                                sprintf(string, "<AvaiableMotorPower>%03d</AvaiableMotorPower>\r\n",BL_MinOfMaxPWM);
403
                                fputs_(string, doc->file);
404
                                sprintf(string, "<FC_I2C_ErrorCounter>%03d</FC_I2C_ErrorCounter>\r\n",(s16)FC_I2C_ErrorConter);
405
                                fputs_(string, doc->file);
406
                                // Analog inputs of the NC
407
                                sprintf(string, "<AnalogInputs>%d,%d,%d,%d</AnalogInputs>\r\n",AnalogData.Ch4,AnalogData.Ch5,AnalogData.Ch6,AnalogData.Ch7);
408
                                fputs_(string, doc->file);
92 killagreg 409
                                // NC Mode (contains the status)
338 holgerb 410
                                sprintf(string, "<NCFlag>0x%02X</NCFlag>\r\n", NCFlags);
86 killagreg 411
                                fputs_(string, doc->file);
345 holgerb 412
                           break;
413
                           case 7:
338 holgerb 414
                                // Flags
415
                                sprintf(string, "<FCFlags2>0x%02x,0x%02x</FCFlags2>\r\n",Logging_FCStatusFlags1,Logging_FCStatusFlags2);
416
                                fputs_(string, doc->file);
417
                                Logging_FCStatusFlags1 = 0;
418
                                Logging_FCStatusFlags2 = 0;
233 holgerb 419
                                // Status of the complete MikroKopter
420
                                sprintf(string, "<ErrorCode>%03d</ErrorCode>\r\n",ErrorCode);
421
                                fputs_(string, doc->file);
92 killagreg 422
                                // Target Bearing in deg
86 killagreg 423
                                sprintf(string, "<TargetBearing>%03d</TargetBearing>\r\n", NaviData.TargetPositionDeviation.Bearing);
424
                                fputs_(string, doc->file);
92 killagreg 425
                                // Target Distance in dm
86 killagreg 426
                                sprintf(string, "<TargetDistance>%d</TargetDistance>\r\n", NaviData.TargetPositionDeviation.Distance);
427
                                fputs_(string, doc->file);
345 holgerb 428
                           break;
429
                           case 8:
101 holgerb 430
                                // RC Sticks as Nick/Roll/Yaw
338 holgerb 431
                                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 432
                                fputs_(string, doc->file);
94 killagreg 433
                                // GPS Sticks as Nick/Roll/Yaw
338 holgerb 434
                                sprintf(string, "<GPSSticks>%d,%d,%d,'%c'</GPSSticks>\r\n", ToFlightCtrl.GPSStick.Nick, ToFlightCtrl.GPSStick.Roll, ToFlightCtrl.GPSStick.Yaw,NC_GPS_ModeCharacter);
94 killagreg 435
                                fputs_(string, doc->file);
86 killagreg 436
                                // eof extensions
437
                                sprintf(string, "</extensions>\r\n");
438
                                fputs_(string, doc->file);
85 killagreg 439
                                sprintf(string, "</trkpt>\r\n");
440
                                fputs_(string, doc->file);
345 holgerb 441
                           break;
442
                          }
443
                        retvalue = 1;
85 killagreg 444
                        }
445
                }
446
        }
447
        return(retvalue);
448
}
449
 
450
//________________________________________________________________________________________________________________________________________
451
// Function:    u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *)
452
//
453
// Description: This function opens and adds gpscoordinates to an GPX-Document. The document will be opened, if not already done
454
//
455
//
456
// Returnvalue: '1' if an gps coordinate was logged
457
//________________________________________________________________________________________________________________________________________
458
 
345 holgerb 459
u8 GPX_LoggGPSCoordinates(GPX_Document_t *doc,unsigned char part)
85 killagreg 460
{
461
        u8 retval = 0;
462
        while(doc->state != GPX_DOC_TRACKSEGMENT_OPENED)                                // automatic create document with default filename on the card.
463
        {
464
                switch(doc->state)
465
                {
466
                        case GPX_DOC_CLOSED:                                                                    // document hasn't been opened yet therefore it will be initialized automatically
324 killagreg 467
                                retval = GPX_DocumentOpen("default.gpx",doc);           // open the gpx-document with a standardname.
85 killagreg 468
                        break;
469
 
470
                        case GPX_DOC_OPENED:                                                                    // if a document has been opened before but no track exists:
471
                                retval = GPX_TrackBegin(doc);
472
                        break;
473
 
474
                        case GPX_DOC_TRACK_OPENED:                                                              // add tracksegement to the track
475
                                retval = GPX_TrackSegmentBegin(doc);
476
                        break;
477
 
478
                        default:
479
                                retval = 0;
480
                        break;
481
 
482
                }
483
                if(retval != 1) return(retval); // stop on error
484
        }
485
 
486
        if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED)                                           // if the document was opened add coordinates to the document.
487
        {
345 holgerb 488
                retval = GPX_TrackSegementAddPoint(doc,part);                                           // add a track segment point
85 killagreg 489
        }
490
        return(retval);
491
}
492