Subversion Repositories NaviCtrl

Rev

Rev 378 | Rev 386 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 378 Rev 380
1
/*#######################################################################################*/
1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + www.MikroKopter.com
5
// + www.MikroKopter.com
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7
// + Software Nutzungsbedingungen (english version: see below)
7
// + Software Nutzungsbedingungen (english version: see below)
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
9
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
9
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
10
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
10
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
11
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
11
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
15
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
15
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
16
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
16
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
17
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
17
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
18
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
18
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
19
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
19
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
20
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
20
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
21
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
21
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
22
// + des Mitverschuldens offen.
22
// + des Mitverschuldens offen.
23
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
23
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
24
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
24
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
25
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
25
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
26
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
26
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
27
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
27
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
28
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
28
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
29
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
29
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
30
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
30
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// + Software LICENSING TERMS
32
// + Software LICENSING TERMS
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
35
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware 
35
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware 
36
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
36
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
37
// + The Software may only be used with the Licensor's products.
37
// + The Software may only be used with the Licensor's products.
38
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
38
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
39
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
39
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
40
// + agreement shall be the property of the Licensor.
40
// + agreement shall be the property of the Licensor.
41
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
41
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
42
// + features that can be used to identify the program may not be altered or defaced by the customer.
42
// + features that can be used to identify the program may not be altered or defaced by the customer.
43
// + The customer shall be responsible for taking reasonable precautions
43
// + The customer shall be responsible for taking reasonable precautions
44
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
44
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
45
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
45
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
46
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
46
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
47
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
47
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
48
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
48
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
49
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
49
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
50
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
50
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
51
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
51
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
52
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
52
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
53
// + #### END OF LICENSING TERMS ####
53
// + #### END OF LICENSING TERMS ####
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56
#include <stdlib.h>
56
#include <stdlib.h>
57
#include <stdio.h>
57
#include <stdio.h>
58
#include "91x_lib.h"
58
#include "91x_lib.h"
59
#include "gpx.h"
59
#include "gpx.h"
60
#include "gpx_header.h"
60
#include "gpx_header.h"
61
#include "timer1.h"
61
#include "timer1.h"
62
#include "spi_slave.h"
62
#include "spi_slave.h"
63
#include "main.h"
63
#include "main.h"
64
#include "uart1.h"
64
#include "uart1.h"
65
#include "compass.h"
65
#include "compass.h"
66
#include "analog.h"
66
#include "analog.h"
67
#include "main.h"
67
#include "main.h"
68
#include "led.h"
68
#include "led.h"
69
#include "timer2.h"
69
#include "timer2.h"
-
 
70
#include "logging.h"
70
 
71
 
71
//________________________________________________________________________________________________________________________________________
72
//________________________________________________________________________________________________________________________________________
72
// Function:    GPX_DocumentInit(GPX_Document_t *)
73
// Function:    GPX_DocumentInit(GPX_Document_t *)
73
//
74
//
74
// Description: This function initializes the gpx-document for further use.
75
// Description: This function initializes the gpx-document for further use.
75
//
76
//
76
//
77
//
77
// Returnvalue: '1' if document was initialized
78
// Returnvalue: '1' if document was initialized
78
//________________________________________________________________________________________________________________________________________
79
//________________________________________________________________________________________________________________________________________
79
 
80
 
80
u8 GPX_DocumentInit(GPX_Document_t *doc)
81
u8 GPX_DocumentInit(GPX_Document_t *doc)
81
{
82
{
82
        if(doc->state != GPX_DOC_CLOSED) GPX_DocumentClose(doc);                                                // close file if it was opened before
83
        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->state       = GPX_DOC_CLOSED;                                                                                                      // init state of the gpx-document
84
        doc->file        = NULL;
85
        doc->file        = NULL;
85
        return(1);
86
        return(1);
86
}
87
}
87
 
88
 
88
//________________________________________________________________________________________________________________________________________
89
//________________________________________________________________________________________________________________________________________
89
// Function:    GPX_Document_Open(s8 *name, GPX_Document_t *doc);
90
// Function:    GPX_Document_Open(s8 *name, GPX_Document_t *doc);
90
//
91
//
91
// Description: This function opens a new gpx-document with the specified name and creates the document header within the file.
92
// Description: This function opens a new gpx-document with the specified name and creates the document header within the file.
92
//
93
//
93
//
94
//
94
// Returnvalue: '1' if the gpx-file could be created.
95
// Returnvalue: '1' if the gpx-file could be created.
95
//________________________________________________________________________________________________________________________________________
96
//________________________________________________________________________________________________________________________________________
96
 
97
 
97
 
98
 
98
u8 GPX_DocumentOpen(s8 *name, GPX_Document_t *doc)
99
u8 GPX_DocumentOpen(s8 *name, GPX_Document_t *doc)
99
{
100
{
100
        s8 string[60];
101
        s8 string[60];
101
        u8 retvalue = 0;
102
        u8 retvalue = 0;
102
 
103
 
103
        if(doc == NULL) return(0);
104
        if(doc == NULL) return(0);
104
        GPX_DocumentInit(doc);                                                                                                          // intialize the document with resetvalues
105
        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
        doc->file = fopen_(name,'a');                                                                                           // open a new file with the specified filename on the memorycard.
106
 
107
 
107
        if(doc->file != NULL)                                                                                                           // could the file be opened?
108
        if(doc->file != NULL)                                                                                                           // could the file be opened?
108
        {
109
        {
109
                retvalue = 1;                                                                                                                   // the document could be created on the drive.
110
                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.
111
                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.
112
                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);
113
                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);
114
                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.
115
                fwrite_((void*)GPX_DOCUMENT_HEADER2, sizeof(GPX_DOCUMENT_HEADER2)-1,1,doc->file);// write the gpx-header to the document.
115
        }
116
        }
116
        Logging_FCStatusFlags1 = 0;
117
        Logging_FCStatusFlags1 = 0;
117
        Logging_FCStatusFlags2 = 0;
118
        Logging_FCStatusFlags2 = 0;
-
 
119
    Logged_GPX_Counter = 0;
118
        return(retvalue);
120
        return(retvalue);
119
}
121
}
120
 
122
 
121
//________________________________________________________________________________________________________________________________________
123
//________________________________________________________________________________________________________________________________________
122
// Function:    DocumentClose(GPX_Document_t *doc);
124
// Function:    DocumentClose(GPX_Document_t *doc);
123
//
125
//
124
// Description: This function closes the document specified by doc.
126
// Description: This function closes the document specified by doc.
125
//
127
//
126
//
128
//
127
// Returnvalue: '1' if the gpx-file could be closed.
129
// Returnvalue: '1' if the gpx-file could be closed.
128
//________________________________________________________________________________________________________________________________________
130
//________________________________________________________________________________________________________________________________________
129
 
131
 
130
u8 GPX_DocumentClose(GPX_Document_t *doc)
132
u8 GPX_DocumentClose(GPX_Document_t *doc)
131
{
133
{
132
 
134
 
133
        u8 retvalue = 1;
135
        u8 retvalue = 1;
134
 
136
 
135
        if(doc == NULL) return(0);
137
        if(doc == NULL) return(0);
136
 
138
 
137
        while(doc->state != GPX_DOC_CLOSED)                                                             // close linestring, placemark and document before closing the file on the memorycard
139
        while(doc->state != GPX_DOC_CLOSED)                                                             // close linestring, placemark and document before closing the file on the memorycard
138
        {
140
        {
139
                switch(doc->state)
141
                switch(doc->state)
140
                {
142
                {
141
                        case GPX_DOC_TRACKSEGMENT_OPENED:
143
                        case GPX_DOC_TRACKSEGMENT_OPENED:
142
                                GPX_TrackSegmentEnd(doc);                                               // write terminating tag to end tracksegment.
144
                                GPX_TrackSegmentEnd(doc);                                               // write terminating tag to end tracksegment.
143
                                break;
145
                                break;
144
 
146
 
145
                        case GPX_DOC_TRACK_OPENED:                                                              // write terminating tag to close track.
147
                        case GPX_DOC_TRACK_OPENED:                                                              // write terminating tag to close track.
146
                                GPX_TrackEnd(doc);
148
                                GPX_TrackEnd(doc);
147
                                break;
149
                                break;
148
 
150
 
149
                        case GPX_DOC_OPENED:                                                                    // close the file on the memorycard
151
                        case GPX_DOC_OPENED:                                                                    // close the file on the memorycard
150
                                if(doc->file != NULL)
152
                                if(doc->file != NULL)
151
                                {
153
                                {
152
                                        fwrite_((void*)GPX_DOCUMENT_FOOTER, sizeof(GPX_DOCUMENT_FOOTER)-1,1,doc->file); // write the gpx-footer to the document.
154
                                        fwrite_((void*)GPX_DOCUMENT_FOOTER, sizeof(GPX_DOCUMENT_FOOTER)-1,1,doc->file); // write the gpx-footer to the document.
153
                                        fclose_(doc->file);
155
                                        fclose_(doc->file);
154
                                        retvalue = 1;
156
                                        retvalue = 1;
155
                                }
157
                                }
156
                                doc->state = GPX_DOC_CLOSED;
158
                                doc->state = GPX_DOC_CLOSED;
157
                                break;
159
                                break;
158
 
160
 
159
                        default:
161
                        default:
160
                                doc->state = GPX_DOC_CLOSED;
162
                                doc->state = GPX_DOC_CLOSED;
161
                                break;
163
                                break;
162
                }
164
                }
163
        }
165
        }
164
        return(retvalue);
166
        return(retvalue);
165
}
167
}
166
 
168
 
167
 
169
 
168
 
170
 
169
//________________________________________________________________________________________________________________________________________
171
//________________________________________________________________________________________________________________________________________
170
// Function:    u8 GPX_TrackBegin(GPX_Document_t);
172
// Function:    u8 GPX_TrackBegin(GPX_Document_t);
171
//
173
//
172
// Description: This function adds a track to the document.
174
// Description: This function adds a track to the document.
173
//
175
//
174
//
176
//
175
// Returnvalue: '1' if the track could be opened
177
// Returnvalue: '1' if the track could be opened
176
//________________________________________________________________________________________________________________________________________
178
//________________________________________________________________________________________________________________________________________
177
 
179
 
178
u8 GPX_TrackBegin(GPX_Document_t *doc)
180
u8 GPX_TrackBegin(GPX_Document_t *doc)
179
{
181
{
180
 
182
 
181
        u8 retvalue = 0;
183
        u8 retvalue = 0;
182
        if(doc->state == GPX_DOC_OPENED)
184
        if(doc->state == GPX_DOC_OPENED)
183
        {
185
        {
184
                if(doc->file != NULL)
186
                if(doc->file != NULL)
185
                {
187
                {
186
                        doc->state = GPX_DOC_TRACK_OPENED;
188
                        doc->state = GPX_DOC_TRACK_OPENED;
187
                        retvalue = 1;
189
                        retvalue = 1;
188
                        fwrite_((void*)GPX_TRACK_HEADER, sizeof(GPX_TRACK_HEADER)-1,1,doc->file);
190
                        fwrite_((void*)GPX_TRACK_HEADER, sizeof(GPX_TRACK_HEADER)-1,1,doc->file);
189
                }
191
                }
190
        }
192
        }
191
        return(retvalue);
193
        return(retvalue);
192
}
194
}
193
 
195
 
194
 
196
 
195
//________________________________________________________________________________________________________________________________________
197
//________________________________________________________________________________________________________________________________________
196
// Function:    u8 GPX_TrackEnd(KML_Document_t *doc)
198
// Function:    u8 GPX_TrackEnd(KML_Document_t *doc)
197
//
199
//
198
// Description: This function ends the track opened before.
200
// Description: This function ends the track opened before.
199
//
201
//
200
//
202
//
201
// Returnvalue: 1' if the track could be closed
203
// Returnvalue: 1' if the track could be closed
202
//________________________________________________________________________________________________________________________________________
204
//________________________________________________________________________________________________________________________________________
203
 
205
 
204
u8 GPX_TrackEnd(GPX_Document_t *doc)
206
u8 GPX_TrackEnd(GPX_Document_t *doc)
205
{
207
{
206
 
208
 
207
        u8 retvalue = 0;
209
        u8 retvalue = 0;
208
 
210
 
209
        if(doc->state == GPX_DOC_TRACK_OPENED)
211
        if(doc->state == GPX_DOC_TRACK_OPENED)
210
        {
212
        {
211
                if(doc->file != NULL)
213
                if(doc->file != NULL)
212
                {
214
                {
213
                        doc->state = GPX_DOC_OPENED;
215
                        doc->state = GPX_DOC_OPENED;
214
                        fwrite_((void*)GPX_TRACK_FOOTER, sizeof(GPX_TRACK_FOOTER)-1,1,doc->file);
216
                        fwrite_((void*)GPX_TRACK_FOOTER, sizeof(GPX_TRACK_FOOTER)-1,1,doc->file);
215
                        retvalue = 1;
217
                        retvalue = 1;
216
                }
218
                }
217
        }
219
        }
218
 
220
 
219
        return(retvalue);
221
        return(retvalue);
220
}
222
}
221
 
223
 
222
//________________________________________________________________________________________________________________________________________
224
//________________________________________________________________________________________________________________________________________
223
// Function:    u8 GPX_TrackSegmentBegin(GPX_Document_t *doc);
225
// Function:    u8 GPX_TrackSegmentBegin(GPX_Document_t *doc);
224
//
226
//
225
// Description: This function starts a track segment.
227
// Description: This function starts a track segment.
226
//
228
//
227
//
229
//
228
// Returnvalue: '1' if the track segement could be started
230
// Returnvalue: '1' if the track segement could be started
229
//________________________________________________________________________________________________________________________________________
231
//________________________________________________________________________________________________________________________________________
230
 
232
 
231
u8 GPX_TrackSegmentBegin(GPX_Document_t *doc)
233
u8 GPX_TrackSegmentBegin(GPX_Document_t *doc)
232
{
234
{
233
 
235
 
234
        u8 retvalue = 0;
236
        u8 retvalue = 0;
235
 
237
 
236
        if(doc->state == GPX_DOC_TRACK_OPENED)
238
        if(doc->state == GPX_DOC_TRACK_OPENED)
237
        {
239
        {
238
                if(doc->file != NULL)
240
                if(doc->file != NULL)
239
                {
241
                {
240
                        doc->state = GPX_DOC_TRACKSEGMENT_OPENED;
242
                        doc->state = GPX_DOC_TRACKSEGMENT_OPENED;
241
                        fwrite_((void*)GPX_TRACKSEGMENT_HEADER, sizeof(GPX_TRACKSEGMENT_HEADER)-1,1,doc->file);
243
                        fwrite_((void*)GPX_TRACKSEGMENT_HEADER, sizeof(GPX_TRACKSEGMENT_HEADER)-1,1,doc->file);
242
                        retvalue = 1;
244
                        retvalue = 1;
243
                }
245
                }
244
        }
246
        }
245
        return(retvalue);
247
        return(retvalue);
246
}
248
}
247
 
249
 
248
//________________________________________________________________________________________________________________________________________
250
//________________________________________________________________________________________________________________________________________
249
// Function:    u8 GPX_TrackSegmentEnd(GPX_Document_t *doc);
251
// Function:    u8 GPX_TrackSegmentEnd(GPX_Document_t *doc);
250
//
252
//
251
// Description: This function ends the tracksegment opened before.
253
// Description: This function ends the tracksegment opened before.
252
//
254
//
253
//
255
//
254
// Returnvalue: '1' if the track segment could be terminated
256
// Returnvalue: '1' if the track segment could be terminated
255
//________________________________________________________________________________________________________________________________________
257
//________________________________________________________________________________________________________________________________________
256
 
258
 
257
u8 GPX_TrackSegmentEnd(GPX_Document_t *doc)
259
u8 GPX_TrackSegmentEnd(GPX_Document_t *doc)
258
{
260
{
259
 
261
 
260
        u8 retvalue = 0;
262
        u8 retvalue = 0;
261
        if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED)
263
        if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED)
262
        {
264
        {
263
                if(doc->file != NULL)
265
                if(doc->file != NULL)
264
                {
266
                {
265
                        doc->state = GPX_DOC_TRACK_OPENED;
267
                        doc->state = GPX_DOC_TRACK_OPENED;
266
                        fwrite_((void*)GPX_TRACKSEGMENT_FOOTER, sizeof(GPX_TRACKSEGMENT_FOOTER)-1,1,doc->file);
268
                        fwrite_((void*)GPX_TRACKSEGMENT_FOOTER, sizeof(GPX_TRACKSEGMENT_FOOTER)-1,1,doc->file);
267
                        retvalue = 1;
269
                        retvalue = 1;
268
                }
270
                }
269
        }
271
        }
270
        return(retvalue);
272
        return(retvalue);
271
}
273
}
272
 
274
 
273
//________________________________________________________________________________________________________________________________________
275
//________________________________________________________________________________________________________________________________________
274
// Function:    u8 GPX_TrackSegementAddPoint(GPS_Pos_t * pGPS_Position ,GPX_Document_t *doc);
276
// Function:    u8 GPX_TrackSegementAddPoint(GPS_Pos_t * pGPS_Position ,GPX_Document_t *doc);
275
//
277
//
276
// Description: This function adds a pointof a track segement to the specified document.
278
// Description: This function adds a pointof a track segement to the specified document.
277
//
279
//
278
//
280
//
279
// Returnvalue: '1' if a point was added
281
// Returnvalue: '1' if a point was added
280
//________________________________________________________________________________________________________________________________________
282
//________________________________________________________________________________________________________________________________________
281
 
283
 
282
u8 GPX_TrackSegementAddPoint(GPX_Document_t *doc,unsigned char part)
284
u8 GPX_TrackSegementAddPoint(GPX_Document_t *doc,unsigned char part)
283
{
285
{
284
 
286
 
285
        u8 retvalue = 0;
287
        u8 retvalue = 0;
286
        s8 string[100];
288
        s8 string[100];
287
 
289
 
288
        if(doc == NULL) return(0);
290
        if(doc == NULL) return(0);
289
 
291
 
290
        if((GPSData.Position.Status != INVALID) && (NaviData.HomePosition.Status != INVALID))
292
        if((GPSData.Position.Status != INVALID) && (NaviData.HomePosition.Status != INVALID))
291
        {
293
        {
292
                if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED)
294
                if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED)
293
                {
295
                {
294
                        if(doc->file != NULL)
296
                        if(doc->file != NULL)
295
                        {
297
                        {
296
                                s32 i32_1, i32_2;
298
                                s32 i32_1, i32_2;
297
                                s16 i16_1;
299
                                s16 i16_1;
298
                                u8 u8_1, u8_2;
300
                                u8 u8_1, u8_2;
299
                                // write <trkpt> tag
301
                                // write <trkpt> tag
300
                        switch(part)
302
                        switch(part)
301
                          {
303
                          {
302
                           case 0:
304
                           case 0:
303
DebugOut.Analog[19]++;
305
DebugOut.Analog[19]++;
-
 
306
                                Logged_GPX_Counter++;
304
                                if(GPSData.Position.Latitude < 0) u8_1 = '-';
307
                                if(GPSData.Position.Latitude < 0) u8_1 = '-';
305
                                else u8_1 = '+';
308
                                else u8_1 = '+';
306
                                i32_1 = abs(GPSData.Position.Latitude)/10000000L;
309
                                i32_1 = abs(GPSData.Position.Latitude)/10000000L;
307
                                i32_2 = abs(GPSData.Position.Latitude)%10000000L;
310
                                i32_2 = abs(GPSData.Position.Latitude)%10000000L;
308
                                sprintf(string, "<trkpt lat=\"%c%ld.%07ld\" ",u8_1, i32_1, i32_2);
311
                                sprintf(string, "<trkpt lat=\"%c%ld.%07ld\" ",u8_1, i32_1, i32_2);
309
                                fputs_(string, doc->file);
312
                                fputs_(string, doc->file);
310
                                if(GPSData.Position.Longitude < 0) u8_1 = '-';
313
                                if(GPSData.Position.Longitude < 0) u8_1 = '-';
311
                                else u8_1 = '+';
314
                                else u8_1 = '+';
312
                                i32_1 = abs(GPSData.Position.Longitude)/10000000L;
315
                                i32_1 = abs(GPSData.Position.Longitude)/10000000L;
313
                                i32_2 = abs(GPSData.Position.Longitude)%10000000L;
316
                                i32_2 = abs(GPSData.Position.Longitude)%10000000L;
314
                                sprintf(string, "lon=\"%c%ld.%07ld\">\r\n",u8_1, i32_1, i32_2);
317
                                sprintf(string, "lon=\"%c%ld.%07ld\">\r\n",u8_1, i32_1, i32_2);
315
                                fputs_(string, doc->file);
318
                                fputs_(string, doc->file);
316
                           break;
319
                           break;
317
                           case 1:
320
                           case 1:
318
                                // write <ele> taga
321
                                // write <ele> taga
319
                                i32_2 = GPSData.Position.Altitude - NaviData.HomePosition.Altitude;
322
                                i32_2 = GPSData.Position.Altitude - NaviData.HomePosition.Altitude;
320
                                if(i32_2 < 0) i32_2 = 0; // avoid negative altitudes in log
323
                                if(i32_2 < 0) i32_2 = 0; // avoid negative altitudes in log
321
                                i32_1 = i32_2/1000L;
324
                                i32_1 = i32_2/1000L;
322
                                i32_2 = i32_2%1000L;
325
                                i32_2 = i32_2%1000L;
323
                                sprintf(string,"<ele>%ld.%03ld</ele>\r\n",i32_1, i32_2);
326
                                sprintf(string,"<ele>%ld.%03ld</ele>\r\n",i32_1, i32_2);
324
                                fputs_(string, doc->file);
327
                                fputs_(string, doc->file);
325
                                // write <time> tag     only at a resolution of one second
328
                                // write <time> tag     only at a resolution of one second
326
                                sprintf(string, "<time>%04d-%02d-%02dT%02d:%02d:%02dZ</time>\r\n",SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Hour, SystemTime.Min, SystemTime.Sec);
329
                                sprintf(string, "<time>%04d-%02d-%02dT%02d:%02d:%02dZ</time>\r\n",SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Hour, SystemTime.Min, SystemTime.Sec);
327
                                fputs_(string, doc->file);
330
                                fputs_(string, doc->file);
328
                                // write <sat> tag
331
                                // write <sat> tag
329
                                sprintf(string, "<sat>%d</sat>\r\n", NaviData.SatsInUse);
332
                                sprintf(string, "<sat>%d</sat>\r\n", NaviData.SatsInUse);
330
                                fputs_(string, doc->file);
333
                                fputs_(string, doc->file);
331
                                // todo: add  <extensions> tag with additional data to be logged
334
                                // todo: add  <extensions> tag with additional data to be logged
332
                                sprintf(string, "<extensions>\r\n");
335
                                sprintf(string, "<extensions>\r\n");
333
                                fputs_(string, doc->file);
336
                                fputs_(string, doc->file);
334
                           break;
337
                           break;
335
                           case 2:
338
                           case 2:
336
                                // Altimeter according to air pressure
339
                                // Altimeter according to air pressure
337
                                sprintf(string, "<Altimeter>%d,'%c'</Altimeter>\r\n", NaviData.Altimeter,FromFC_VarioCharacter);
340
                                sprintf(string, "<Altimeter>%d,'%c'</Altimeter>\r\n", NaviData.Altimeter,FromFC_VarioCharacter);
338
                                fputs_(string, doc->file);
341
                                fputs_(string, doc->file);
339
                                // Variometer according to air pressure
342
                                // Variometer according to air pressure
340
                                sprintf(string, "<Variometer>%d</Variometer>\r\n", NaviData.Variometer);
343
                                sprintf(string, "<Variometer>%d</Variometer>\r\n", NaviData.Variometer);
341
                                fputs_(string, doc->file);
344
                                fputs_(string, doc->file);
342
                                // Course in deg
345
                                // Course in deg
343
                                i16_1 = GPSData.Heading/100000L;
346
                                i16_1 = GPSData.Heading/100000L;
344
                                sprintf(string, "<Course>%03d</Course>\r\n", i16_1);
347
                                sprintf(string, "<Course>%03d</Course>\r\n", i16_1);
345
                                fputs_(string, doc->file);
348
                                fputs_(string, doc->file);
346
                                // Ground Speed in cm/s
349
                                // Ground Speed in cm/s
347
                                sprintf(string, "<GroundSpeed>%d</GroundSpeed>\r\n", NaviData.GroundSpeed);
350
                                sprintf(string, "<GroundSpeed>%d</GroundSpeed>\r\n", NaviData.GroundSpeed);
348
                                fputs_(string, doc->file);
351
                                fputs_(string, doc->file);
349
                                // Vertical Speed in cm/s
352
                                // Vertical Speed in cm/s
350
                                sprintf(string, "<VerticalSpeed>%d</VerticalSpeed>\r\n", NaviData.TopSpeed);
353
                                sprintf(string, "<VerticalSpeed>%d</VerticalSpeed>\r\n", NaviData.TopSpeed);
351
                                fputs_(string, doc->file);
354
                                fputs_(string, doc->file);
352
                                // Flight duration
355
                                // Flight duration
353
                                sprintf(string, "<FlightTime>%d</FlightTime>\r\n", NaviData.FlyingTime);
356
                                sprintf(string, "<FlightTime>%d</FlightTime>\r\n", NaviData.FlyingTime);
354
                                fputs_(string, doc->file);
357
                                fputs_(string, doc->file);
355
                           break;
358
                           break;
356
                           case 3:
359
                           case 3:
357
                                // Ubat
360
                                // Ubat
358
                                u8_1 = NaviData.UBat / 10;
361
                                u8_1 = NaviData.UBat / 10;
359
                                u8_2 = NaviData.UBat % 10;
362
                                u8_2 = NaviData.UBat % 10;
360
                                sprintf(string, "<Voltage>%d.%01d</Voltage>\r\n", u8_1, u8_2);
363
                                sprintf(string, "<Voltage>%d.%01d</Voltage>\r\n", u8_1, u8_2);
361
                                fputs_(string, doc->file);
364
                                fputs_(string, doc->file);
362
                                // Current
365
                                // Current
363
                                u8_1 = NaviData.Current / 10;
366
                                u8_1 = NaviData.Current / 10;
364
                                u8_2 = NaviData.Current % 10;
367
                                u8_2 = NaviData.Current % 10;
365
                                sprintf(string, "<Current>%d.%01d</Current>\r\n", u8_1, u8_2);
368
                                sprintf(string, "<Current>%d.%01d</Current>\r\n", u8_1, u8_2);
366
                                fputs_(string, doc->file);
369
                                fputs_(string, doc->file);
367
                                // Capacity
370
                                // Capacity
368
                                sprintf(string, "<Capacity>%d</Capacity>\r\n", NaviData.UsedCapacity);
371
                                sprintf(string, "<Capacity>%d</Capacity>\r\n", NaviData.UsedCapacity);
369
                                fputs_(string, doc->file);
372
                                fputs_(string, doc->file);
370
                                // RC Quality
373
                                // RC Quality
371
                                sprintf(string, "<RCQuality>%d</RCQuality>\r\n", FC.RC_Quality);
374
                                sprintf(string, "<RCQuality>%d</RCQuality>\r\n", FC.RC_Quality);
372
                                fputs_(string, doc->file);
375
                                fputs_(string, doc->file);
373
                                // RC Received Signal Strength Indication
376
                                // RC Received Signal Strength Indication
374
                           break;
377
                           break;
375
                           case 4:
378
                           case 4:
376
                                sprintf(string, "<RCRSSI>%d</RCRSSI>\r\n", FC.RC_RSSI);
379
                                sprintf(string, "<RCRSSI>%d</RCRSSI>\r\n", FC.RC_RSSI);
377
                                fputs_(string, doc->file);
380
                                fputs_(string, doc->file);
378
                                // Compassind deg
381
                                // Compassind deg
379
                                i16_1 = FromFlightCtrl.GyroHeading / 10;
382
                                i16_1 = FromFlightCtrl.GyroHeading / 10;
380
                                sprintf(string, "<Compass>%03d,%03d</Compass>\r\n", i16_1,ToFlightCtrl.CompassHeading);
383
                                sprintf(string, "<Compass>%03d,%03d</Compass>\r\n", i16_1,ToFlightCtrl.CompassHeading);
381
                                fputs_(string, doc->file);
384
                                fputs_(string, doc->file);
382
                                // Nick Angle ind deg
385
                                // Nick Angle ind deg
383
                                sprintf(string, "<NickAngle>%03d</NickAngle>\r\n", NaviData.AngleNick);
386
                                sprintf(string, "<NickAngle>%03d</NickAngle>\r\n", NaviData.AngleNick);
384
                                fputs_(string, doc->file);
387
                                fputs_(string, doc->file);
385
                                // Roll Angle in deg
388
                                // Roll Angle in deg
386
                                sprintf(string, "<RollAngle>%03d</RollAngle>\r\n", NaviData.AngleRoll);
389
                                sprintf(string, "<RollAngle>%03d</RollAngle>\r\n", NaviData.AngleRoll);
387
                                fputs_(string, doc->file);
390
                                fputs_(string, doc->file);
388
                           break;
391
                           break;
389
                           case 5:
392
                           case 5:
390
                                // magnetic field 
393
                                // magnetic field 
391
                                sprintf(string, "<MagnetField>%03d</MagnetField>\r\n",(u16) (EarthMagneticFieldFiltered/5));
394
                                sprintf(string, "<MagnetField>%03d</MagnetField>\r\n",(u16) (EarthMagneticFieldFiltered/5));
392
                                fputs_(string, doc->file);
395
                                fputs_(string, doc->file);
393
                                // magnetic inclination & error 
396
                                // magnetic inclination & error 
394
                                sprintf(string, "<MagnetInclination>%02d,%02d</MagnetInclination>\r\n",(s16)EarthMagneticInclinationFiltered/10,(s16)(EarthMagneticInclinationFiltered/10 - EarthMagneticInclinationTheoretic));
397
                                sprintf(string, "<MagnetInclination>%02d,%02d</MagnetInclination>\r\n",(s16)EarthMagneticInclinationFiltered/10,(s16)(EarthMagneticInclinationFiltered/10 - EarthMagneticInclinationTheoretic));
395
                                fputs_(string, doc->file);
398
                                fputs_(string, doc->file);
396
                                // BL Information
399
                                // BL Information
397
                                sprintf(string, "<MotorCurrent>%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d</MotorCurrent>\r\n",Motor[0].Current,Motor[1].Current,Motor[2].Current,Motor[3].Current,Motor[4].Current,Motor[5].Current,Motor[6].Current,Motor[7].Current,Motor[8].Current,Motor[9].Current,Motor[10].Current,Motor[11].Current);
400
                                sprintf(string, "<MotorCurrent>%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d</MotorCurrent>\r\n",Motor[0].Current,Motor[1].Current,Motor[2].Current,Motor[3].Current,Motor[4].Current,Motor[5].Current,Motor[6].Current,Motor[7].Current,Motor[8].Current,Motor[9].Current,Motor[10].Current,Motor[11].Current);
398
                                fputs_(string, doc->file);
401
                                fputs_(string, doc->file);
399
                                sprintf(string, "<BL_Temperature>%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d</BL_Temperature>\r\n",Motor[0].Temperature,Motor[1].Temperature,Motor[2].Temperature,Motor[3].Temperature,Motor[4].Temperature,Motor[5].Temperature,Motor[6].Temperature,Motor[7].Temperature,Motor[8].Temperature,Motor[9].Temperature,Motor[10].Temperature,Motor[11].Temperature);
402
                                sprintf(string, "<BL_Temperature>%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d</BL_Temperature>\r\n",Motor[0].Temperature,Motor[1].Temperature,Motor[2].Temperature,Motor[3].Temperature,Motor[4].Temperature,Motor[5].Temperature,Motor[6].Temperature,Motor[7].Temperature,Motor[8].Temperature,Motor[9].Temperature,Motor[10].Temperature,Motor[11].Temperature);
400
                                fputs_(string, doc->file);
403
                                fputs_(string, doc->file);
401
                           break;
404
                           break;
402
                           case 6:
405
                           case 6:
403
/*                              sprintf(string, "<BL_State>0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x</BL_State>\r\n",Motor.State[0],Motor.State[1],Motor.State[2],Motor.State[3],Motor.State[4],Motor.State[5],Motor.State[6],Motor.State[7],Motor.State[8],Motor.State[9],Motor.State[10],Motor.State[11]);
406
/*                              sprintf(string, "<BL_State>0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x</BL_State>\r\n",Motor.State[0],Motor.State[1],Motor.State[2],Motor.State[3],Motor.State[4],Motor.State[5],Motor.State[6],Motor.State[7],Motor.State[8],Motor.State[9],Motor.State[10],Motor.State[11]);
404
                                fputs_(string, doc->file);
407
                                fputs_(string, doc->file);
405
                                sprintf(string, "<BL_MaxPWM>%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d</BL_MaxPWM>\r\n",Motor.MaxPWM[0],Motor.MaxPWM[1],Motor.MaxPWM[2],Motor.MaxPWM[3],Motor.MaxPWM[4],Motor.MaxPWM[5],Motor.MaxPWM[6],Motor.MaxPWM[7],Motor.MaxPWM[8],Motor.MaxPWM[9],Motor.MaxPWM[10],Motor.MaxPWM[11]);
408
                                sprintf(string, "<BL_MaxPWM>%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d</BL_MaxPWM>\r\n",Motor.MaxPWM[0],Motor.MaxPWM[1],Motor.MaxPWM[2],Motor.MaxPWM[3],Motor.MaxPWM[4],Motor.MaxPWM[5],Motor.MaxPWM[6],Motor.MaxPWM[7],Motor.MaxPWM[8],Motor.MaxPWM[9],Motor.MaxPWM[10],Motor.MaxPWM[11]);
406
                                fputs_(string, doc->file);
409
                                fputs_(string, doc->file);
407
*/                              sprintf(string, "<AvaiableMotorPower>%03d</AvaiableMotorPower>\r\n",BL_MinOfMaxPWM);
410
*/                              sprintf(string, "<AvaiableMotorPower>%03d</AvaiableMotorPower>\r\n",BL_MinOfMaxPWM);
408
                                fputs_(string, doc->file);
411
                                fputs_(string, doc->file);
409
                                sprintf(string, "<FC_I2C_ErrorCounter>%03d</FC_I2C_ErrorCounter>\r\n",(s16)FC_I2C_ErrorConter);
412
                                sprintf(string, "<FC_I2C_ErrorCounter>%03d</FC_I2C_ErrorCounter>\r\n",(s16)FC_I2C_ErrorConter);
410
                                fputs_(string, doc->file);
413
                                fputs_(string, doc->file);
411
                                // Analog inputs of the NC
414
                                // Analog inputs of the NC
412
                                sprintf(string, "<AnalogInputs>%d,%d,%d,%d</AnalogInputs>\r\n",AnalogData.Ch4,AnalogData.Ch5,AnalogData.Ch6,AnalogData.Ch7);
415
                                sprintf(string, "<AnalogInputs>%d,%d,%d,%d</AnalogInputs>\r\n",AnalogData.Ch4,AnalogData.Ch5,AnalogData.Ch6,AnalogData.Ch7);
413
                                fputs_(string, doc->file);
416
                                fputs_(string, doc->file);
414
                                // NC Mode (contains the status)
417
                                // NC Mode (contains the status)
415
                                sprintf(string, "<NCFlag>0x%02X</NCFlag>\r\n", NCFlags);
418
                                sprintf(string, "<NCFlag>0x%02X</NCFlag>\r\n", NCFlags);
416
                                fputs_(string, doc->file);
419
                                fputs_(string, doc->file);
417
                                sprintf(string, "<Servo>%d,%d,%d</Servo>\r\n", ServoParams.NickControl,ServoParams.RollControl,POI_KameraNick/10);      // Raw Poti-Values of the Servo control and the POI_Nick in 1°
420
                                sprintf(string, "<Servo>%d,%d,%d</Servo>\r\n", ServoParams.NickControl,ServoParams.RollControl,POI_KameraNick/10);      // Raw Poti-Values of the Servo control and the POI_Nick in 1°
418
                                fputs_(string, doc->file);
421
                                fputs_(string, doc->file);
419
                                sprintf(string, "<WP>%d,%d,%d</WP>\r\n",NaviData.WaypointIndex,NaviData.WaypointNumber,FC_WP_EventChannel);      // x of y Waypoints and the actual value of the Event Channel
422
                                sprintf(string, "<WP>%d,%d,%d</WP>\r\n",NaviData.WaypointIndex,NaviData.WaypointNumber,FC_WP_EventChannel);      // x of y Waypoints and the actual value of the Event Channel
420
                                fputs_(string, doc->file);
423
                                fputs_(string, doc->file);
421
                           break;
424
                           break;
422
                           case 7:
425
                           case 7:
423
                                // Flags
426
                                // Flags
424
                                sprintf(string, "<FCFlags2>0x%02x,0x%02x</FCFlags2>\r\n",Logging_FCStatusFlags1,Logging_FCStatusFlags2);
427
                                sprintf(string, "<FCFlags2>0x%02x,0x%02x</FCFlags2>\r\n",Logging_FCStatusFlags1,Logging_FCStatusFlags2);
425
                                fputs_(string, doc->file);
428
                                fputs_(string, doc->file);
426
                                Logging_FCStatusFlags1 = 0;
429
                                Logging_FCStatusFlags1 = 0;
427
                                Logging_FCStatusFlags2 = 0;
430
                                Logging_FCStatusFlags2 = 0;
428
                                // Status of the complete MikroKopter
431
                                // Status of the complete MikroKopter
429
                                sprintf(string, "<ErrorCode>%03d</ErrorCode>\r\n",ErrorCode);
432
                                sprintf(string, "<ErrorCode>%03d</ErrorCode>\r\n",ErrorCode);
430
                                fputs_(string, doc->file);
433
                                fputs_(string, doc->file);
431
                                // Target Bearing in deg
434
                                // Target Bearing in deg
432
                                sprintf(string, "<TargetBearing>%03d</TargetBearing>\r\n", NaviData.TargetPositionDeviation.Bearing);
435
                                sprintf(string, "<TargetBearing>%03d</TargetBearing>\r\n", NaviData.TargetPositionDeviation.Bearing);
433
                                fputs_(string, doc->file);
436
                                fputs_(string, doc->file);
434
                                // Target Distance in dm
437
                                // Target Distance in dm
435
                                sprintf(string, "<TargetDistance>%d</TargetDistance>\r\n", NaviData.TargetPositionDeviation.Distance);
438
                                sprintf(string, "<TargetDistance>%d</TargetDistance>\r\n", NaviData.TargetPositionDeviation.Distance);
436
                                fputs_(string, doc->file);
439
                                fputs_(string, doc->file);
437
                           break;
440
                           break;
438
                           case 8:
441
                           case 8:
439
                                // RC Sticks as Nick/Roll/Yaw
442
                                // RC Sticks as Nick/Roll/Yaw
440
                                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]);
443
                                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]);
441
                                fputs_(string, doc->file);
444
                                fputs_(string, doc->file);
442
                                // GPS Sticks as Nick/Roll/Yaw
445
                                // GPS Sticks as Nick/Roll/Yaw
443
                                sprintf(string, "<GPSSticks>%d,%d,%d,'%c'</GPSSticks>\r\n", ToFlightCtrl.GPSStick.Nick, ToFlightCtrl.GPSStick.Roll, ToFlightCtrl.GPSStick.Yaw,NC_GPS_ModeCharacter);
446
                                sprintf(string, "<GPSSticks>%d,%d,%d,'%c'</GPSSticks>\r\n", ToFlightCtrl.GPSStick.Nick, ToFlightCtrl.GPSStick.Roll, ToFlightCtrl.GPSStick.Yaw,NC_GPS_ModeCharacter);
444
                                fputs_(string, doc->file);
447
                                fputs_(string, doc->file);
445
                                // eof extensions
448
                                // eof extensions
446
                                sprintf(string, "</extensions>\r\n");
449
                                sprintf(string, "</extensions>\r\n");
447
                                fputs_(string, doc->file);
450
                                fputs_(string, doc->file);
448
                                sprintf(string, "</trkpt>\r\n");
451
                                sprintf(string, "</trkpt>\r\n");
449
                                fputs_(string, doc->file);
452
                                fputs_(string, doc->file);
450
                           break;
453
                           break;
451
                          }
454
                          }
452
                        retvalue = 1;
455
                        retvalue = 1;
453
                        }
456
                        }
454
                }
457
                }
455
        }
458
        }
456
        return(retvalue);
459
        return(retvalue);
457
}
460
}
458
 
461
 
459
//________________________________________________________________________________________________________________________________________
462
//________________________________________________________________________________________________________________________________________
460
// Function:    u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *)
463
// Function:    u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *)
461
//
464
//
462
// Description: This function opens and adds gpscoordinates to an GPX-Document. The document will be opened, if not already done
465
// Description: This function opens and adds gpscoordinates to an GPX-Document. The document will be opened, if not already done
463
//
466
//
464
//
467
//
465
// Returnvalue: '1' if an gps coordinate was logged
468
// Returnvalue: '1' if an gps coordinate was logged
466
//________________________________________________________________________________________________________________________________________
469
//________________________________________________________________________________________________________________________________________
467
 
470
 
468
u8 GPX_LoggGPSCoordinates(GPX_Document_t *doc,unsigned char part)
471
u8 GPX_LoggGPSCoordinates(GPX_Document_t *doc,unsigned char part)
469
{
472
{
470
        u8 retval = 0;
473
        u8 retval = 0;
471
        while(doc->state != GPX_DOC_TRACKSEGMENT_OPENED)                                // automatic create document with default filename on the card.
474
        while(doc->state != GPX_DOC_TRACKSEGMENT_OPENED)                                // automatic create document with default filename on the card.
472
        {
475
        {
473
                switch(doc->state)
476
                switch(doc->state)
474
                {
477
                {
475
                        case GPX_DOC_CLOSED:                                                                    // document hasn't been opened yet therefore it will be initialized automatically
478
                        case GPX_DOC_CLOSED:                                                                    // document hasn't been opened yet therefore it will be initialized automatically
476
                                retval = GPX_DocumentOpen("default.gpx",doc);           // open the gpx-document with a standardname.
479
                                retval = GPX_DocumentOpen("default.gpx",doc);           // open the gpx-document with a standardname.
477
                        break;
480
                        break;
478
 
481
 
479
                        case GPX_DOC_OPENED:                                                                    // if a document has been opened before but no track exists:
482
                        case GPX_DOC_OPENED:                                                                    // if a document has been opened before but no track exists:
480
                                retval = GPX_TrackBegin(doc);
483
                                retval = GPX_TrackBegin(doc);
481
                        break;
484
                        break;
482
 
485
 
483
                        case GPX_DOC_TRACK_OPENED:                                                              // add tracksegement to the track
486
                        case GPX_DOC_TRACK_OPENED:                                                              // add tracksegement to the track
484
                                retval = GPX_TrackSegmentBegin(doc);
487
                                retval = GPX_TrackSegmentBegin(doc);
485
                        break;
488
                        break;
486
 
489
 
487
                        default:
490
                        default:
488
                                retval = 0;
491
                                retval = 0;
489
                        break;
492
                        break;
490
 
493
 
491
                }
494
                }
492
                if(retval != 1) return(retval); // stop on error
495
                if(retval != 1) return(retval); // stop on error
493
        }
496
        }
494
 
497
 
495
        if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED)                                           // if the document was opened add coordinates to the document.
498
        if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED)                                           // if the document was opened add coordinates to the document.
496
        {
499
        {
497
                retval = GPX_TrackSegementAddPoint(doc,part);                                           // add a track segment point
500
                retval = GPX_TrackSegementAddPoint(doc,part);                                           // add a track segment point
498
        }
501
        }
499
        return(retval);
502
        return(retval);
500
}
503
}
501
 
504
 
502
 
505