Subversion Repositories NaviCtrl

Rev

Rev 340 | Rev 351 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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