Subversion Repositories NaviCtrl

Rev

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

Rev 676 Rev 686
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
#include "logging.h"
71
#include "ncmag.h"
71
#include "ncmag.h"
72
#include "uart0.h"
72
#include "uart0.h"
73
#include "settings.h"
73
#include "settings.h"
74
 
74
 
75
//________________________________________________________________________________________________________________________________________
75
//________________________________________________________________________________________________________________________________________
76
// Function:    GPX_DocumentInit(GPX_Document_t *)
76
// Function:    GPX_DocumentInit(GPX_Document_t *)
77
//
77
//
78
// Description: This function initializes the gpx-document for further use.
78
// Description: This function initializes the gpx-document for further use.
79
//
79
//
80
//
80
//
81
// Returnvalue: '1' if document was initialized
81
// Returnvalue: '1' if document was initialized
82
//________________________________________________________________________________________________________________________________________
82
//________________________________________________________________________________________________________________________________________
83
 
83
 
84
u8 GPX_DocumentInit(GPX_Document_t *doc)
84
u8 GPX_DocumentInit(GPX_Document_t *doc)
85
{
85
{
86
        if(doc->state != GPX_DOC_CLOSED) GPX_DocumentClose(doc);                                                // close file if it was opened before
86
        if(doc->state != GPX_DOC_CLOSED) GPX_DocumentClose(doc);                                                // close file if it was opened before
87
        doc->state       = GPX_DOC_CLOSED;                                                                                                      // init state of the gpx-document
87
        doc->state       = GPX_DOC_CLOSED;                                                                                                      // init state of the gpx-document
88
        doc->file        = NULL;
88
        doc->file        = NULL;
89
        return(1);
89
        return(1);
90
}
90
}
91
 
91
 
92
//________________________________________________________________________________________________________________________________________
92
//________________________________________________________________________________________________________________________________________
93
// Function:    GPX_Document_Open(s8 *name, GPX_Document_t *doc);
93
// Function:    GPX_Document_Open(s8 *name, GPX_Document_t *doc);
94
//
94
//
95
// Description: This function opens a new gpx-document with the specified name and creates the document header within the file.
95
// Description: This function opens a new gpx-document with the specified name and creates the document header within the file.
96
//
96
//
97
//
97
//
98
// Returnvalue: '1' if the gpx-file could be created.
98
// Returnvalue: '1' if the gpx-file could be created.
99
//________________________________________________________________________________________________________________________________________
99
//________________________________________________________________________________________________________________________________________
100
 
100
 
101
 
101
 
102
u8 GPX_DocumentOpen(s8 *name, GPX_Document_t *doc)
102
u8 GPX_DocumentOpen(s8 *name, GPX_Document_t *doc)
103
{
103
{
104
        s8 string[200];
104
        s8 string[200];
105
        u8 retvalue = 0;
105
        u8 retvalue = 0;
106
        u8 BLv = 1;
106
        u8 BLv = 1;
107
        u16 gps_receive_config;
107
        u16 gps_receive_config;
108
        LicenseS_t *tmp_license;
108
        LicenseS_t *tmp_license;
109
        tmp_license = (LicenseS_t *) LicensePtr;
109
        tmp_license = (LicenseS_t *) LicensePtr;
110
 
110
 
111
        if(doc == NULL) return(0);
111
        if(doc == NULL) return(0);
112
        GPX_DocumentInit(doc);                                                                                                          // intialize the document with resetvalues
112
        GPX_DocumentInit(doc);                                                                                                          // intialize the document with resetvalues
113
        doc->file = fopen_(name,'a');                                                                                           // open a new file with the specified filename on the memorycard.
113
        doc->file = fopen_(name,'a');                                                                                           // open a new file with the specified filename on the memorycard.
114
 
114
 
115
        if(Motor_Version[0] & MOTOR_STATE_BL30) BLv = 3;
115
        if(Motor_Version[0] & MOTOR_STATE_BL30) BLv = 3;
116
        else if(Motor_Version[0] & MOTOR_STATE_NEW_PROTOCOL_MASK) BLv = 2;
116
        else if(Motor_Version[0] & MOTOR_STATE_NEW_PROTOCOL_MASK) BLv = 2;
117
 
117
 
118
        if(doc->file != NULL)                                                                                                           // could the file be opened?
118
        if(doc->file != NULL)                                                                                                           // could the file be opened?
119
        {
119
        {
120
                retvalue = 1;                                                                                                                   // the document could be created on the drive.
120
                retvalue = 1;                                                                                                                   // the document could be created on the drive.
121
                doc->state = GPX_DOC_OPENED;                                                                                            // change document state to opened. At next a placemark has to be opened.
121
                doc->state = GPX_DOC_OPENED;                                                                                            // change document state to opened. At next a placemark has to be opened.
122
                fwrite_((void*)GPX_DOCUMENT_HEADER1, sizeof(GPX_DOCUMENT_HEADER1)-1,1,doc->file);// write the gpx-header to the document.
122
                fwrite_((void*)GPX_DOCUMENT_HEADER1, sizeof(GPX_DOCUMENT_HEADER1)-1,1,doc->file);// write the gpx-header to the document.
123
                sprintf(string, "<desc>FC HW:%d.%d SW:%d.%02d%c + NC HW:%d.%d SW:%d.%02d%c + BL HW:V%d SW:%d.%02d", (FC_Version.Hardware & 0x7F)/10,(FC_Version.Hardware & 0x7F)%10, FC_Version.Major, FC_Version.Minor, 'a'+FC_Version.Patch, UART_VersionInfo.HWMajor/10, UART_VersionInfo.HWMajor%10, VERSION_MAJOR,  VERSION_MINOR, 'a'+ VERSION_PATCH,BLv,UART_VersionInfo.BL_Firmware/100,UART_VersionInfo.BL_Firmware%100);
123
                sprintf(string, "<desc>FC HW:%d.%d SW:%d.%02d%c + NC HW:%d.%d SW:%d.%02d%c + BL HW:V%d SW:%d.%02d", (FC_Version.Hardware & 0x7F)/10,(FC_Version.Hardware & 0x7F)%10, FC_Version.Major, FC_Version.Minor, 'a'+FC_Version.Patch, UART_VersionInfo.HWMajor/10, UART_VersionInfo.HWMajor%10, VERSION_MAJOR,  VERSION_MINOR, 'a'+ VERSION_PATCH,BLv,UART_VersionInfo.BL_Firmware/100,UART_VersionInfo.BL_Firmware%100);
124
                fputs_(string, doc->file);
124
                fputs_(string, doc->file);
125
                if(SimulationFlags) { sprintf(string, " SIMULATED"); fputs_(string, doc->file);};
125
                if(SimulationFlags) { sprintf(string, " SIMULATED"); fputs_(string, doc->file);};
126
                if(FC.StatusFlags3 & FC_STATUS3_REDUNDANCE_AKTIVE) sprintf(string, " (Redundant)</desc>\r\n");
126
                if(FC.StatusFlags3 & FC_STATUS3_REDUNDANCE_AKTIVE) sprintf(string, " (Redundant)</desc>\r\n");
127
                else sprintf(string, "</desc>\r\n");
127
                else sprintf(string, "</desc>\r\n");
128
                fputs_(string, doc->file);
128
                fputs_(string, doc->file);
129
        sprintf(string, "<extensions>\r\n");  fputs_(string, doc->file);
129
        sprintf(string, "<extensions>\r\n");  fputs_(string, doc->file);
130
         sprintf(string, "<MK_Time>%imin</MK_Time>\r\n",FlugMinutenGesamt);fputs_(string, doc->file);
130
         sprintf(string, "<MK_Time>%imin</MK_Time>\r\n",FlugMinutenGesamt);fputs_(string, doc->file);
131
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
131
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
132
     sprintf(string, "<GpsVersion>%d.%03d</GpsVersion>\r\n",GPS_Version/1000,GPS_Version%1000);fputs_(string, doc->file);
132
     sprintf(string, "<GpsVersion>%d.%03d</GpsVersion>\r\n",GPS_Version/1000,GPS_Version%1000);fputs_(string, doc->file);
133
         if(GPS_Version >= 3000)
133
         if(GPS_Version >= 3000)
134
          {
134
          {
135
             Settings_GetParamValue(PID_GPS_SYSTEM_CFG,&gps_receive_config);
135
             Settings_GetParamValue(PID_GPS_SYSTEM_CFG,&gps_receive_config);
136
                 sprintf(string, "<GNSS_System>%d</GNSS_System>\r\n",gps_receive_config);
136
                 sprintf(string, "<GNSS_System>%d</GNSS_System>\r\n",gps_receive_config);
137
                 fputs_(string, doc->file);
137
                 fputs_(string, doc->file);
138
          }
138
          }
139
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
139
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
140
         sprintf(string, "<License>\r\n");      fputs_(string, doc->file);
140
         sprintf(string, "<License>\r\n");      fputs_(string, doc->file);
141
           if(tmp_license->User[0] != 0)
141
           if(tmp_license->User[0] != 0)
142
           {
142
           {
143
                sprintf(string, "<name>%s</name>\r\n",tmp_license->User); fputs_(string, doc->file);
143
                sprintf(string, "<name>%s</name>\r\n",tmp_license->User); fputs_(string, doc->file);
144
                sprintf(string, "<email>%s</email>\r\n",tmp_license->eMail); fputs_(string, doc->file);
144
                sprintf(string, "<email>%s</email>\r\n",tmp_license->eMail); fputs_(string, doc->file);
145
                sprintf(string, "<features>%s</features>\r\n",tmp_license->Feature); fputs_(string, doc->file);
145
                sprintf(string, "<features>%s</features>\r\n",tmp_license->Feature); fputs_(string, doc->file);
146
                sprintf(string, "<expires>%s</expires>\r\n",tmp_license->Expire);fputs_(string, doc->file);
146
                sprintf(string, "<expires>%s</expires>\r\n",tmp_license->Expire);fputs_(string, doc->file);
147
           }
147
           }
148
           else
148
           else
149
           {
149
           {
150
            sprintf(string, "<info>No License installed</info>\r\n");   fputs_(string, doc->file);
150
            sprintf(string, "<info>No License installed</info>\r\n");   fputs_(string, doc->file);
151
           }
151
           }
152
          sprintf(string, "</License>\r\n"); fputs_(string, doc->file);
152
          sprintf(string, "</License>\r\n"); fputs_(string, doc->file);
153
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
153
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
154
          sprintf(string, "<settings>\r\n"); fputs_(string, doc->file);
154
          sprintf(string, "<settings>\r\n"); fputs_(string, doc->file);
155
                sprintf(string, "<Number>%i</Number>\r\n",Parameter.ActiveSetting);fputs_(string, doc->file);
155
                sprintf(string, "<Number>%i</Number>\r\n",Parameter.ActiveSetting);fputs_(string, doc->file);
156
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
156
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
157
        // Reciever     Type
157
        // Reciever     Type
158
                sprintf(string, "<Receiver>");fputs_(string, doc->file);
158
                sprintf(string, "<Receiver>");fputs_(string, doc->file);
159
                switch(Parameter.ReceiverType)
159
                switch(Parameter.ReceiverType)
160
                {
160
                {
161
                case RECEIVER_PPM:                              sprintf(string, "PPM");         break;
161
                case RECEIVER_PPM:                              sprintf(string, "PPM");         break;
162
                case RECEIVER_SPEKTRUM:                 sprintf(string, "SPEKTRUM");    break;
162
                case RECEIVER_SPEKTRUM:                 sprintf(string, "SPEKTRUM");    break;
163
                case RECEIVER_SPEKTRUM_HI_RES:  sprintf(string, "SPEKTRUM_HI_RES");     break;
163
                case RECEIVER_SPEKTRUM_HI_RES:  sprintf(string, "SPEKTRUM_HI_RES");     break;
164
                case RECEIVER_SPEKTRUM_LOW_RES: sprintf(string, "SPEKTRUM_LOW_RES");    break;
164
                case RECEIVER_SPEKTRUM_LOW_RES: sprintf(string, "SPEKTRUM_LOW_RES");    break;
165
                case RECEIVER_JETI:                     sprintf(string, "JETI");        break;
165
                case RECEIVER_JETI:                     sprintf(string, "JETI");        break;
166
                case RECEIVER_ACT_DSL:                  sprintf(string, "ACT_DSL");     break;
166
                case RECEIVER_ACT_DSL:                  sprintf(string, "ACT_DSL");     break;
167
                case RECEIVER_HOTT:                     sprintf(string, "HOTT");        break;
167
                case RECEIVER_HOTT:                     sprintf(string, "HOTT");        break;
168
                case RECEIVER_SBUS:                     sprintf(string, "SBUS");        break;
168
                case RECEIVER_SBUS:                     sprintf(string, "SBUS");        break;
169
                case RECEIVER_USER:                     sprintf(string, "USER");        break;
169
                case RECEIVER_USER:                     sprintf(string, "USER");        break;
170
                default:                                                sprintf(string, "? %d",Parameter.ReceiverType); break;
170
                default:                                                sprintf(string, "? %d",Parameter.ReceiverType); break;
171
                }              
171
                }              
172
                fputs_(string, doc->file);
172
                fputs_(string, doc->file);
173
                sprintf(string, "</Receiver>\r\n"); fputs_(string, doc->file);
173
                sprintf(string, "</Receiver>\r\n"); fputs_(string, doc->file);
174
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++            
174
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++            
175
                if(FC.FromFC_CompassOffset > 30) {sprintf(string, "<CompassOffset>%i !</CompassOffset>\r\n",FC.FromFC_CompassOffset/10);fputs_(string, doc->file);}
175
                if(FC.FromFC_CompassOffset > 30) {sprintf(string, "<CompassOffset>%i !</CompassOffset>\r\n",FC.FromFC_CompassOffset/10);fputs_(string, doc->file);}
176
                else {sprintf(string, "<CompassOffset>%i</CompassOffset>\r\n",FC.FromFC_CompassOffset/10);fputs_(string, doc->file);}
176
                else {sprintf(string, "<CompassOffset>%i</CompassOffset>\r\n",FC.FromFC_CompassOffset/10);fputs_(string, doc->file);}
177
                sprintf(string, "<FCOrientation>%i</FCOrientation>\r\n",Parameter.OrientationAngle*15);fputs_(string, doc->file);
177
                sprintf(string, "<FCOrientation>%i</FCOrientation>\r\n",Parameter.OrientationAngle*15);fputs_(string, doc->file);
178
                sprintf(string, "<GeoMag>%i.%1d</GeoMag>\r\n",GeoMagDec/10,abs(GeoMagDec)%10);fputs_(string, doc->file);
178
                sprintf(string, "<GeoMag>%i.%1d</GeoMag>\r\n",GeoMagDec/10,abs(GeoMagDec)%10);fputs_(string, doc->file);
179
        sprintf(string, "<Neutral>%d,%d,%d</Neutral>\r\n", FC.AdNeutralNick,FC.AdNeutralRoll,FC.AdNeutralYaw);fputs_(string, doc->file);
179
        sprintf(string, "<Neutral>%d,%d,%d</Neutral>\r\n", FC.AdNeutralNick,FC.AdNeutralRoll,FC.AdNeutralYaw);fputs_(string, doc->file);
180
        sprintf(string, "<Kalibr.>%d,%d,%d</Kalibr.>\r\n", FC.BoatNeutralNick,FC.BoatNeutralRoll,FC.BoatNeutralYaw);fputs_(string, doc->file);
180
        sprintf(string, "<Kalibr.>%d,%d,%d</Kalibr.>\r\n", FC.BoatNeutralNick,FC.BoatNeutralRoll,FC.BoatNeutralYaw);fputs_(string, doc->file);
181
                if((FC.StatusFlags3 & FC_STATUS3_BOAT)) {sprintf(string, "<BoatMode>On</BoatMode>\r\n");fputs_(string, doc->file);}
181
                if((FC.StatusFlags3 & FC_STATUS3_BOAT)) {sprintf(string, "<BoatMode>On</BoatMode>\r\n");fputs_(string, doc->file);}
182
                if(Parameter.Driftkomp) {sprintf(string, "<DriftComp>%i</DriftComp>\r\n",Parameter.Driftkomp);fputs_(string, doc->file);};
182
                if(Parameter.Driftkomp) {sprintf(string, "<DriftComp>%i</DriftComp>\r\n",Parameter.Driftkomp);fputs_(string, doc->file);};
183
 
183
 
184
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
184
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
185
        // Magnetometer
185
        // Magnetometer
186
                if(Compass_I2CPort == NCMAG_PORT_EXTERN) sprintf(string, "<MagSensor>external,(%i),",NCMAG_Orientation);
186
                if(Compass_I2CPort == NCMAG_PORT_EXTERN) sprintf(string, "<MagSensor>external2,(%i),",NCMAG_Orientation);
-
 
187
                else if(NCMAG_Compass_use_Orientation) sprintf(string, "<MagSensor>external1,(%i),",NCMAG_Orientation);
187
                else sprintf(string, "<MagSensor>internal,");
188
                else sprintf(string, "<MagSensor>internal,");
-
 
189
 
188
                fputs_(string, doc->file);
190
                fputs_(string, doc->file);
189
                switch(NCMAG_SensorType)
191
                switch(NCMAG_SensorType)
190
                {
192
                {
191
                 case TYPE_HMC5843:             sprintf(string, "HMC");         break;
193
                 case TYPE_HMC5843:             sprintf(string, "HMC");         break;
192
                 case TYPE_LSM303DLH:           sprintf(string, "DLH");         break;
194
                 case TYPE_LSM303DLH:           sprintf(string, "DLH");         break;
193
                 case TYPE_LSM303DLM:           sprintf(string, "DLM");         break;
195
                 case TYPE_LSM303DLM:           sprintf(string, "DLM");         break;
194
                 case TYPE_LSM303D:             sprintf(string, "D");           break;
196
                 case TYPE_LSM303D:             sprintf(string, "D");           break;
195
                 default:  sprintf(string, "? %d",NCMAG_SensorType);    break;
197
                 default:  sprintf(string, "? %d",NCMAG_SensorType);    break;
196
                }
198
                }
197
                fputs_(string, doc->file);
199
                fputs_(string, doc->file);
198
                sprintf(string, "</MagSensor>\r\n");fputs_(string, doc->file);
200
                sprintf(string, "</MagSensor>\r\n");fputs_(string, doc->file);
199
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
201
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
200
                sprintf(string, "<FailSafeTime>%d</FailSafeTime>\r\n",Parameter.FailSafeTime);fputs_(string, doc->file);
202
                sprintf(string, "<FailSafeTime>%d</FailSafeTime>\r\n",Parameter.FailSafeTime);fputs_(string, doc->file);
201
                if(AbsoluteFlyingAltitude) {sprintf(string, "<MaxAltitude>%i</MaxAltitude>\r\n",AbsoluteFlyingAltitude);fputs_(string, doc->file);}
203
                if(AbsoluteFlyingAltitude) {sprintf(string, "<MaxAltitude>%i</MaxAltitude>\r\n",AbsoluteFlyingAltitude);fputs_(string, doc->file);}
202
                if(AbsoluteFlyingRange_m) {sprintf(string, "<FlyRange>%i</FlyRange>\r\n",AbsoluteFlyingRange_m);fputs_(string, doc->file);}
204
                if(AbsoluteFlyingRange_m) {sprintf(string, "<FlyRange>%i</FlyRange>\r\n",AbsoluteFlyingRange_m);fputs_(string, doc->file);}
203
                if(AutoDescendRange_m) {sprintf(string, "<Descend>%i</Descend>\r\n",AutoDescendRange_m);fputs_(string, doc->file);};
205
                if(AutoDescendRange_m) {sprintf(string, "<Descend>%i</Descend>\r\n",AutoDescendRange_m);fputs_(string, doc->file);};
204
 
206
 
205
                if((Parameter.GlobalConfig & FC_CFG_HEADING_HOLD))                      {sprintf(string, "<HeadingHold>ON!</HeadingHold>\r\n");fputs_(string, doc->file);}
207
                if((Parameter.GlobalConfig & FC_CFG_HEADING_HOLD))                      {sprintf(string, "<HeadingHold>ON!</HeadingHold>\r\n");fputs_(string, doc->file);}
206
                if((Parameter.GlobalConfig & FC_CFG_KOMPASS_FIX))                       {sprintf(string, "<KompassFixedValue>ON!</KompassFixedValue>\r\n");fputs_(string, doc->file);}
208
                if((Parameter.GlobalConfig & FC_CFG_KOMPASS_FIX))                       {sprintf(string, "<KompassFixedValue>ON!</KompassFixedValue>\r\n");fputs_(string, doc->file);}
207
                if((Parameter.GlobalConfig & FC_CFG_DREHRATEN_BEGRENZER))       {sprintf(string, "<RotationRateLimiter>ON!</RotationRateLimiter>\r\n");fputs_(string, doc->file);}
209
                if((Parameter.GlobalConfig & FC_CFG_DREHRATEN_BEGRENZER))       {sprintf(string, "<RotationRateLimiter>ON!</RotationRateLimiter>\r\n");fputs_(string, doc->file);}
208
                if(!(Parameter.GlobalConfig & FC_CFG_ACHSENKOPPLUNG_AKTIV)) {sprintf(string, "<AxisCoupling>OFF!</AxisCoupling>\r\n");fputs_(string, doc->file);}
210
                if(!(Parameter.GlobalConfig & FC_CFG_ACHSENKOPPLUNG_AKTIV)) {sprintf(string, "<AxisCoupling>OFF!</AxisCoupling>\r\n");fputs_(string, doc->file);}
209
                if(!(Parameter.GlobalConfig & FC_CFG_KOMPASS_AKTIV))            {sprintf(string, "<CompassActive>OFF!</CompassActive>\r\n");fputs_(string, doc->file);}
211
                if(!(Parameter.GlobalConfig & FC_CFG_KOMPASS_AKTIV))            {sprintf(string, "<CompassActive>OFF!</CompassActive>\r\n");fputs_(string, doc->file);}
210
                if((Parameter.GlobalConfig3 & CFG3_VARIO_FAILSAFE))                     {sprintf(string, "<VarioFailsafe>On</VarioFailsafe>\r\n");fputs_(string, doc->file);}
212
                if((Parameter.GlobalConfig3 & CFG3_VARIO_FAILSAFE))                     {sprintf(string, "<VarioFailsafe>On</VarioFailsafe>\r\n");fputs_(string, doc->file);}
211
                if((Parameter.ExtraConfig & CFG_3_3V_REFERENCE))                        {sprintf(string, "<3.3V_Reference>On</3.3V_Reference>\r\n");fputs_(string, doc->file);}
213
                if((Parameter.ExtraConfig & CFG_3_3V_REFERENCE))                        {sprintf(string, "<3.3V_Reference>On</3.3V_Reference>\r\n");fputs_(string, doc->file);}
212
                if((Parameter.ExtraConfig & CFG_IGNORE_MAG_ERR_AT_STARTUP))     {sprintf(string, "<IgnoreMagnetError>ON!</IgnoreMagnetError>\r\n");fputs_(string, doc->file);}
214
                if((Parameter.ExtraConfig & CFG_IGNORE_MAG_ERR_AT_STARTUP))     {sprintf(string, "<IgnoreMagnetError>ON!</IgnoreMagnetError>\r\n");fputs_(string, doc->file);}
213
                if(FC.FromFC_DisableDeclination)                                                        {sprintf(string, "<DisableDeclinationCalc>ON!</DisableDeclinationCalc>\r\n");fputs_(string, doc->file);}
215
                if(FC.FromFC_DisableDeclination)                                                        {sprintf(string, "<DisableDeclinationCalc>ON!</DisableDeclinationCalc>\r\n");fputs_(string, doc->file);}
214
 
216
 
215
                sprintf(string, "<Bytes>%02x,%02x,%02x</Bytes>\r\n",Parameter.GlobalConfig,Parameter.ExtraConfig,Parameter.GlobalConfig3);fputs_(string, doc->file);
217
                sprintf(string, "<Bytes>%02x,%02x,%02x</Bytes>\r\n",Parameter.GlobalConfig,Parameter.ExtraConfig,Parameter.GlobalConfig3);fputs_(string, doc->file);
216
          sprintf(string, "</settings>\r\n"); fputs_(string, doc->file);
218
          sprintf(string, "</settings>\r\n"); fputs_(string, doc->file);
217
        sprintf(string, "</extensions>\r\n"); fputs_(string, doc->file);
219
        sprintf(string, "</extensions>\r\n"); fputs_(string, doc->file);
218
 
220
 
219
                fwrite_((void*)GPX_DOCUMENT_METADATA_END, sizeof(GPX_DOCUMENT_METADATA_END)-1,1,doc->file);// write the gpx-header to the document.
221
                fwrite_((void*)GPX_DOCUMENT_METADATA_END, sizeof(GPX_DOCUMENT_METADATA_END)-1,1,doc->file);// write the gpx-header to the document.
220
        }
222
        }
221
        Logging_FCStatusFlags1 = 0;
223
        Logging_FCStatusFlags1 = 0;
222
        Logging_FCStatusFlags2 = 0;
224
        Logging_FCStatusFlags2 = 0;
223
    Logged_GPX_Counter = 0;
225
    Logged_GPX_Counter = 0;
224
        LogFC_WP_EventChannel = 0;
226
        LogFC_WP_EventChannel = 0;
225
        Logging_BL_MinOfMaxPWM = BL_MinOfMaxPWM;
227
        Logging_BL_MinOfMaxPWM = BL_MinOfMaxPWM;
226
        return(retvalue);
228
        return(retvalue);
227
}
229
}
228
 
230
 
229
//________________________________________________________________________________________________________________________________________
231
//________________________________________________________________________________________________________________________________________
230
// Function:    DocumentClose(GPX_Document_t *doc);
232
// Function:    DocumentClose(GPX_Document_t *doc);
231
//
233
//
232
// Description: This function closes the document specified by doc.
234
// Description: This function closes the document specified by doc.
233
//
235
//
234
//
236
//
235
// Returnvalue: '1' if the gpx-file could be closed.
237
// Returnvalue: '1' if the gpx-file could be closed.
236
//________________________________________________________________________________________________________________________________________
238
//________________________________________________________________________________________________________________________________________
237
 
239
 
238
u8 GPX_DocumentClose(GPX_Document_t *doc)
240
u8 GPX_DocumentClose(GPX_Document_t *doc)
239
{
241
{
240
 
242
 
241
        u8 retvalue = 1;
243
        u8 retvalue = 1;
242
 
244
 
243
        if(doc == NULL) return(0);
245
        if(doc == NULL) return(0);
244
 
246
 
245
        while(doc->state != GPX_DOC_CLOSED)                                                             // close linestring, placemark and document before closing the file on the memorycard
247
        while(doc->state != GPX_DOC_CLOSED)                                                             // close linestring, placemark and document before closing the file on the memorycard
246
        {
248
        {
247
                switch(doc->state)
249
                switch(doc->state)
248
                {
250
                {
249
                        case GPX_DOC_TRACKSEGMENT_OPENED:
251
                        case GPX_DOC_TRACKSEGMENT_OPENED:
250
                                GPX_TrackSegmentEnd(doc);                                               // write terminating tag to end tracksegment.
252
                                GPX_TrackSegmentEnd(doc);                                               // write terminating tag to end tracksegment.
251
                                break;
253
                                break;
252
 
254
 
253
                        case GPX_DOC_TRACK_OPENED:                                                              // write terminating tag to close track.
255
                        case GPX_DOC_TRACK_OPENED:                                                              // write terminating tag to close track.
254
                                GPX_TrackEnd(doc);
256
                                GPX_TrackEnd(doc);
255
                                break;
257
                                break;
256
 
258
 
257
                        case GPX_DOC_OPENED:                                                                    // close the file on the memorycard
259
                        case GPX_DOC_OPENED:                                                                    // close the file on the memorycard
258
                                if(doc->file != NULL)
260
                                if(doc->file != NULL)
259
                                {
261
                                {
260
                                        fwrite_((void*)GPX_DOCUMENT_FOOTER, sizeof(GPX_DOCUMENT_FOOTER)-1,1,doc->file); // write the gpx-footer to the document.
262
                                        fwrite_((void*)GPX_DOCUMENT_FOOTER, sizeof(GPX_DOCUMENT_FOOTER)-1,1,doc->file); // write the gpx-footer to the document.
261
                                        fclose_(doc->file);
263
                                        fclose_(doc->file);
262
                                        retvalue = 1;
264
                                        retvalue = 1;
263
                                }
265
                                }
264
                                doc->state = GPX_DOC_CLOSED;
266
                                doc->state = GPX_DOC_CLOSED;
265
                                break;
267
                                break;
266
 
268
 
267
                        default:
269
                        default:
268
                                doc->state = GPX_DOC_CLOSED;
270
                                doc->state = GPX_DOC_CLOSED;
269
                                break;
271
                                break;
270
                }
272
                }
271
        }
273
        }
272
        return(retvalue);
274
        return(retvalue);
273
}
275
}
274
 
276
 
275
 
277
 
276
 
278
 
277
//________________________________________________________________________________________________________________________________________
279
//________________________________________________________________________________________________________________________________________
278
// Function:    u8 GPX_TrackBegin(GPX_Document_t);
280
// Function:    u8 GPX_TrackBegin(GPX_Document_t);
279
//
281
//
280
// Description: This function adds a track to the document.
282
// Description: This function adds a track to the document.
281
//
283
//
282
//
284
//
283
// Returnvalue: '1' if the track could be opened
285
// Returnvalue: '1' if the track could be opened
284
//________________________________________________________________________________________________________________________________________
286
//________________________________________________________________________________________________________________________________________
285
 
287
 
286
u8 GPX_TrackBegin(GPX_Document_t *doc)
288
u8 GPX_TrackBegin(GPX_Document_t *doc)
287
{
289
{
288
 
290
 
289
        u8 retvalue = 0;
291
        u8 retvalue = 0;
290
        if(doc->state == GPX_DOC_OPENED)
292
        if(doc->state == GPX_DOC_OPENED)
291
        {
293
        {
292
                if(doc->file != NULL)
294
                if(doc->file != NULL)
293
                {
295
                {
294
                        doc->state = GPX_DOC_TRACK_OPENED;
296
                        doc->state = GPX_DOC_TRACK_OPENED;
295
                        retvalue = 1;
297
                        retvalue = 1;
296
                        fwrite_((void*)GPX_TRACK_HEADER, sizeof(GPX_TRACK_HEADER)-1,1,doc->file);
298
                        fwrite_((void*)GPX_TRACK_HEADER, sizeof(GPX_TRACK_HEADER)-1,1,doc->file);
297
                }
299
                }
298
        }
300
        }
299
        return(retvalue);
301
        return(retvalue);
300
}
302
}
301
 
303
 
302
 
304
 
303
//________________________________________________________________________________________________________________________________________
305
//________________________________________________________________________________________________________________________________________
304
// Function:    u8 GPX_TrackEnd(KML_Document_t *doc)
306
// Function:    u8 GPX_TrackEnd(KML_Document_t *doc)
305
//
307
//
306
// Description: This function ends the track opened before.
308
// Description: This function ends the track opened before.
307
//
309
//
308
//
310
//
309
// Returnvalue: 1' if the track could be closed
311
// Returnvalue: 1' if the track could be closed
310
//________________________________________________________________________________________________________________________________________
312
//________________________________________________________________________________________________________________________________________
311
 
313
 
312
u8 GPX_TrackEnd(GPX_Document_t *doc)
314
u8 GPX_TrackEnd(GPX_Document_t *doc)
313
{
315
{
314
 
316
 
315
        u8 retvalue = 0;
317
        u8 retvalue = 0;
316
 
318
 
317
        if(doc->state == GPX_DOC_TRACK_OPENED)
319
        if(doc->state == GPX_DOC_TRACK_OPENED)
318
        {
320
        {
319
                if(doc->file != NULL)
321
                if(doc->file != NULL)
320
                {
322
                {
321
                        doc->state = GPX_DOC_OPENED;
323
                        doc->state = GPX_DOC_OPENED;
322
                        fwrite_((void*)GPX_TRACK_FOOTER, sizeof(GPX_TRACK_FOOTER)-1,1,doc->file);
324
                        fwrite_((void*)GPX_TRACK_FOOTER, sizeof(GPX_TRACK_FOOTER)-1,1,doc->file);
323
                        retvalue = 1;
325
                        retvalue = 1;
324
                }
326
                }
325
        }
327
        }
326
 
328
 
327
        return(retvalue);
329
        return(retvalue);
328
}
330
}
329
 
331
 
330
//________________________________________________________________________________________________________________________________________
332
//________________________________________________________________________________________________________________________________________
331
// Function:    u8 GPX_TrackSegmentBegin(GPX_Document_t *doc);
333
// Function:    u8 GPX_TrackSegmentBegin(GPX_Document_t *doc);
332
//
334
//
333
// Description: This function starts a track segment.
335
// Description: This function starts a track segment.
334
//
336
//
335
//
337
//
336
// Returnvalue: '1' if the track segement could be started
338
// Returnvalue: '1' if the track segement could be started
337
//________________________________________________________________________________________________________________________________________
339
//________________________________________________________________________________________________________________________________________
338
 
340
 
339
u8 GPX_TrackSegmentBegin(GPX_Document_t *doc)
341
u8 GPX_TrackSegmentBegin(GPX_Document_t *doc)
340
{
342
{
341
 
343
 
342
        u8 retvalue = 0;
344
        u8 retvalue = 0;
343
 
345
 
344
        if(doc->state == GPX_DOC_TRACK_OPENED)
346
        if(doc->state == GPX_DOC_TRACK_OPENED)
345
        {
347
        {
346
                if(doc->file != NULL)
348
                if(doc->file != NULL)
347
                {
349
                {
348
                        doc->state = GPX_DOC_TRACKSEGMENT_OPENED;
350
                        doc->state = GPX_DOC_TRACKSEGMENT_OPENED;
349
                        fwrite_((void*)GPX_TRACKSEGMENT_HEADER, sizeof(GPX_TRACKSEGMENT_HEADER)-1,1,doc->file);
351
                        fwrite_((void*)GPX_TRACKSEGMENT_HEADER, sizeof(GPX_TRACKSEGMENT_HEADER)-1,1,doc->file);
350
                        retvalue = 1;
352
                        retvalue = 1;
351
                }
353
                }
352
        }
354
        }
353
        return(retvalue);
355
        return(retvalue);
354
}
356
}
355
 
357
 
356
//________________________________________________________________________________________________________________________________________
358
//________________________________________________________________________________________________________________________________________
357
// Function:    u8 GPX_TrackSegmentEnd(GPX_Document_t *doc);
359
// Function:    u8 GPX_TrackSegmentEnd(GPX_Document_t *doc);
358
//
360
//
359
// Description: This function ends the tracksegment opened before.
361
// Description: This function ends the tracksegment opened before.
360
//
362
//
361
//
363
//
362
// Returnvalue: '1' if the track segment could be terminated
364
// Returnvalue: '1' if the track segment could be terminated
363
//________________________________________________________________________________________________________________________________________
365
//________________________________________________________________________________________________________________________________________
364
 
366
 
365
u8 GPX_TrackSegmentEnd(GPX_Document_t *doc)
367
u8 GPX_TrackSegmentEnd(GPX_Document_t *doc)
366
{
368
{
367
 
369
 
368
        u8 retvalue = 0;
370
        u8 retvalue = 0;
369
        if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED)
371
        if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED)
370
        {
372
        {
371
                if(doc->file != NULL)
373
                if(doc->file != NULL)
372
                {
374
                {
373
                        doc->state = GPX_DOC_TRACK_OPENED;
375
                        doc->state = GPX_DOC_TRACK_OPENED;
374
                        fwrite_((void*)GPX_TRACKSEGMENT_FOOTER, sizeof(GPX_TRACKSEGMENT_FOOTER)-1,1,doc->file);
376
                        fwrite_((void*)GPX_TRACKSEGMENT_FOOTER, sizeof(GPX_TRACKSEGMENT_FOOTER)-1,1,doc->file);
375
                        retvalue = 1;
377
                        retvalue = 1;
376
                }
378
                }
377
        }
379
        }
378
        return(retvalue);
380
        return(retvalue);
379
}
381
}
380
 
382
 
381
//________________________________________________________________________________________________________________________________________
383
//________________________________________________________________________________________________________________________________________
382
// Function:    u8 GPX_TrackSegementAddPoint(GPS_Pos_t * pGPS_Position ,GPX_Document_t *doc);
384
// Function:    u8 GPX_TrackSegementAddPoint(GPS_Pos_t * pGPS_Position ,GPX_Document_t *doc);
383
//
385
//
384
// Description: This function adds a pointof a track segement to the specified document.
386
// Description: This function adds a pointof a track segement to the specified document.
385
//
387
//
386
//
388
//
387
// Returnvalue: '1' if a point was added
389
// Returnvalue: '1' if a point was added
388
//________________________________________________________________________________________________________________________________________
390
//________________________________________________________________________________________________________________________________________
389
 
391
 
390
u8 GPX_TrackSegementAddPoint(GPX_Document_t *doc,unsigned char part)
392
u8 GPX_TrackSegementAddPoint(GPX_Document_t *doc,unsigned char part)
391
{
393
{
392
 
394
 
393
        u8 retvalue = 0;
395
        u8 retvalue = 0;
394
        static u8 LastLoggedFlags2 = 0;
396
        static u8 LastLoggedFlags2 = 0;
395
        s8 string[120];
397
        s8 string[120];
396
        s8 name[] = "----\0";
398
        s8 name[] = "----\0";
397
 
399
 
398
        if(doc == NULL) return(0);
400
        if(doc == NULL) return(0);
399
 
401
 
400
//      if((GPSData.Position.Status != INVALID) && (NaviData.HomePosition.Status != INVALID))
402
//      if((GPSData.Position.Status != INVALID) && (NaviData.HomePosition.Status != INVALID))
401
        {
403
        {
402
                if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED)
404
                if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED)
403
                {
405
                {
404
                        if(doc->file != NULL)
406
                        if(doc->file != NULL)
405
                        {
407
                        {
406
                                static s32 altitude; // store to make sure they are all recorded in one timestamp
408
                                static s32 altitude; // store to make sure they are all recorded in one timestamp
407
                                s32 i32_1, i32_2;
409
                                s32 i32_1, i32_2;
408
                                s16 i16_1;
410
                                s16 i16_1;
409
                                u8 u8_1, u8_2;
411
                                u8 u8_1, u8_2;
410
                                // write <trkpt> tag
412
                                // write <trkpt> tag
411
                        switch(part)
413
                        switch(part)
412
                          {
414
                          {
413
                           case 0:
415
                           case 0:
414
                                Logged_GPX_Counter++;
416
                                Logged_GPX_Counter++;
415
                    if(GPSData.Position.Status != INVALID)
417
                    if(GPSData.Position.Status != INVALID)
416
                            {
418
                            {
417
                                 if(GPSData.Position.Latitude < 0) u8_1 = '-';
419
                                 if(GPSData.Position.Latitude < 0) u8_1 = '-';
418
                                 else u8_1 = '+';
420
                                 else u8_1 = '+';
419
                                 i32_1 = abs(GPSData.Position.Latitude)/10000000L;
421
                                 i32_1 = abs(GPSData.Position.Latitude)/10000000L;
420
                                 i32_2 = abs(GPSData.Position.Latitude)%10000000L;
422
                                 i32_2 = abs(GPSData.Position.Latitude)%10000000L;
421
                                 sprintf(string, "<trkpt lat=\"%c%ld.%07ld\" ",u8_1, i32_1, i32_2);
423
                                 sprintf(string, "<trkpt lat=\"%c%ld.%07ld\" ",u8_1, i32_1, i32_2);
422
                                 fputs_(string, doc->file);
424
                                 fputs_(string, doc->file);
423
                                 if(GPSData.Position.Longitude < 0) u8_1 = '-';
425
                                 if(GPSData.Position.Longitude < 0) u8_1 = '-';
424
                                 else u8_1 = '+';
426
                                 else u8_1 = '+';
425
                                 i32_1 = abs(GPSData.Position.Longitude)/10000000L;
427
                                 i32_1 = abs(GPSData.Position.Longitude)/10000000L;
426
                                 i32_2 = abs(GPSData.Position.Longitude)%10000000L;
428
                                 i32_2 = abs(GPSData.Position.Longitude)%10000000L;
427
                                 sprintf(string, "lon=\"%c%ld.%07ld\">\r\n",u8_1, i32_1, i32_2);
429
                                 sprintf(string, "lon=\"%c%ld.%07ld\">\r\n",u8_1, i32_1, i32_2);
428
                            } else sprintf(string, "<trkpt lat=\"\" lon=\"\">");
430
                            } else sprintf(string, "<trkpt lat=\"\" lon=\"\">");
429
                           fputs_(string, doc->file);
431
                           fputs_(string, doc->file);
430
                           altitude = GPSData.Position.Altitude;
432
                           altitude = GPSData.Position.Altitude;
431
                           break;
433
                           break;
432
                           case 1:
434
                           case 1:
433
                                // write <ele> tag
435
                                // write <ele> tag
434
                                i32_2 = altitude - NaviData.HomePosition.Altitude;
436
                                i32_2 = altitude - NaviData.HomePosition.Altitude;
435
                    if(GPSData.Position.Status == INVALID) i32_2 = 0;
437
                    if(GPSData.Position.Status == INVALID) i32_2 = 0;
436
                                i32_1 = i32_2/1000L;
438
                                i32_1 = i32_2/1000L;
437
                                i32_2 = i32_2%1000L;
439
                                i32_2 = i32_2%1000L;
438
                                if(altitude - NaviData.HomePosition.Altitude < 0)       sprintf(string,"<ele>-%ld.%03ld</ele>\r\n",labs(i32_1),labs(i32_2));
440
                                if(altitude - NaviData.HomePosition.Altitude < 0)       sprintf(string,"<ele>-%ld.%03ld</ele>\r\n",labs(i32_1),labs(i32_2));
439
                                else                                                                                            sprintf(string,"<ele>%ld.%03ld</ele>\r\n",i32_1,i32_2);
441
                                else                                                                                            sprintf(string,"<ele>%ld.%03ld</ele>\r\n",i32_1,i32_2);
440
                                fputs_(string, doc->file);
442
                                fputs_(string, doc->file);
441
                                // write <time> tag     only at a resolution of 1/100 second
443
                                // write <time> tag     only at a resolution of 1/100 second
442
                                sprintf(string, "<time>%04d-%02d-%02dT%02d:%02d:%02d.%dZ</time>\r\n",SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Hour, SystemTime.Min, SystemTime.Sec,SystemTime.mSec/100);
444
                                sprintf(string, "<time>%04d-%02d-%02dT%02d:%02d:%02d.%dZ</time>\r\n",SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Hour, SystemTime.Min, SystemTime.Sec,SystemTime.mSec/100);
443
                                fputs_(string, doc->file);
445
                                fputs_(string, doc->file);
444
                                // write <sat> tag
446
                                // write <sat> tag
445
                                sprintf(string, "<sat>%d</sat>\r\n", NaviData.SatsInUse);
447
                                sprintf(string, "<sat>%d</sat>\r\n", NaviData.SatsInUse);
446
                                fputs_(string, doc->file);
448
                                fputs_(string, doc->file);
447
                                // todo: add  <extensions> tag with additional data to be logged
449
                                // todo: add  <extensions> tag with additional data to be logged
448
                                sprintf(string, "<extensions>\r\n");
450
                                sprintf(string, "<extensions>\r\n");
449
                                fputs_(string, doc->file);
451
                                fputs_(string, doc->file);
450
                           break;
452
                           break;
451
                           case 2:
453
                           case 2:
452
                                // Flight duration
454
                                // Flight duration
453
                                sprintf(string, "<FlightTime>%d</FlightTime>\r\n", NaviData.FlyingTime);
455
                                sprintf(string, "<FlightTime>%d</FlightTime>\r\n", NaviData.FlyingTime);
454
                                fputs_(string, doc->file);
456
                                fputs_(string, doc->file);
455
                            // Status of the complete MikroKopter
457
                            // Status of the complete MikroKopter
456
                                sprintf(string, "<ErrorCode>%03d</ErrorCode>\r\n",ErrorCode);
458
                                sprintf(string, "<ErrorCode>%03d</ErrorCode>\r\n",ErrorCode);
457
                                fputs_(string, doc->file);
459
                                fputs_(string, doc->file);
458
                                // Flags
460
                                // Flags
459
                                if(LastLoggedFlags2 & FC_STATUS2_OUT1_ACTIVE && !(FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) Logging_FCStatusFlags2 &= ~FC_STATUS2_OUT1_ACTIVE; // to avoid that the OUT-Flags are longer high than required
461
                                if(LastLoggedFlags2 & FC_STATUS2_OUT1_ACTIVE && !(FC.StatusFlags2 & FC_STATUS2_OUT1_ACTIVE)) Logging_FCStatusFlags2 &= ~FC_STATUS2_OUT1_ACTIVE; // to avoid that the OUT-Flags are longer high than required
460
                                if(LastLoggedFlags2 & FC_STATUS2_OUT2_ACTIVE && !(FC.StatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) Logging_FCStatusFlags2 &= ~FC_STATUS2_OUT2_ACTIVE;
462
                                if(LastLoggedFlags2 & FC_STATUS2_OUT2_ACTIVE && !(FC.StatusFlags2 & FC_STATUS2_OUT2_ACTIVE)) Logging_FCStatusFlags2 &= ~FC_STATUS2_OUT2_ACTIVE;
461
                                sprintf(string, "<FCFlags2>0x%02x,0x%02x</FCFlags2>\r\n",Logging_FCStatusFlags1,Logging_FCStatusFlags2);
463
                                sprintf(string, "<FCFlags2>0x%02x,0x%02x</FCFlags2>\r\n",Logging_FCStatusFlags1,Logging_FCStatusFlags2);
462
                                fputs_(string, doc->file);
464
                                fputs_(string, doc->file);
463
                                LastLoggedFlags2 = Logging_FCStatusFlags2;
465
                                LastLoggedFlags2 = Logging_FCStatusFlags2;
464
                                Logging_FCStatusFlags1 = FC.StatusFlags;
466
                                Logging_FCStatusFlags1 = FC.StatusFlags;
465
                                Logging_FCStatusFlags2 = FC.StatusFlags2;
467
                                Logging_FCStatusFlags2 = FC.StatusFlags2;
466
                                // NC Mode (contains the status)
468
                                // NC Mode (contains the status)
467
                                sprintf(string, "<NCFlag>0x%02X</NCFlag>\r\n", NCFlags);
469
                                sprintf(string, "<NCFlag>0x%02X</NCFlag>\r\n", NCFlags);
468
                                fputs_(string, doc->file);
470
                                fputs_(string, doc->file);
469
                                // Altimeter according to air pressure
471
                                // Altimeter according to air pressure
470
                                sprintf(string, "<Speak>%d</Speak>\r\n",FC.FromFC_SpeakHoTT);
472
                                sprintf(string, "<Speak>%d</Speak>\r\n",FC.FromFC_SpeakHoTT);
471
                                FC.FromFC_SpeakHoTT = 0; // can be cleared now
473
                                FC.FromFC_SpeakHoTT = 0; // can be cleared now
472
                                fputs_(string, doc->file);
474
                                fputs_(string, doc->file);
473
                                // Altimeter according to air pressure
475
                                // Altimeter according to air pressure
474
                                sprintf(string, "<Altimeter>%d,'%c'</Altimeter>\r\n", NaviData.Altimeter,FromFC_VarioCharacter);
476
                                sprintf(string, "<Altimeter>%d,'%c'</Altimeter>\r\n", NaviData.Altimeter,FromFC_VarioCharacter);
475
                                fputs_(string, doc->file);
477
                                fputs_(string, doc->file);
476
                                // Variometer according to air pressure
478
                                // Variometer according to air pressure
477
                                sprintf(string, "<Variometer>%d</Variometer>\r\n", NaviData.Variometer);
479
                                sprintf(string, "<Variometer>%d</Variometer>\r\n", NaviData.Variometer);
478
                                fputs_(string, doc->file);
480
                                fputs_(string, doc->file);
479
                           break;
481
                           break;
480
                           case 3:
482
                           case 3:
481
                                // Ubat
483
                                // Ubat
482
                                u8_1 = FC.BAT_Voltage / 10;
484
                                u8_1 = FC.BAT_Voltage / 10;
483
                                u8_2 = FC.BAT_Voltage % 10;
485
                                u8_2 = FC.BAT_Voltage % 10;
484
                                sprintf(string, "<Voltage>%d.%01d</Voltage>\r\n", u8_1, u8_2);
486
                                sprintf(string, "<Voltage>%d.%01d</Voltage>\r\n", u8_1, u8_2);
485
                                fputs_(string, doc->file);
487
                                fputs_(string, doc->file);
486
                                // Current
488
                                // Current
487
                                sprintf(string, "<Current>%d.%01d</Current>\r\n", NaviData.Current / 10, NaviData.Current % 10);
489
                                sprintf(string, "<Current>%d.%01d</Current>\r\n", NaviData.Current / 10, NaviData.Current % 10);
488
                                fputs_(string, doc->file);
490
                                fputs_(string, doc->file);
489
                                // Capacity
491
                                // Capacity
490
                                sprintf(string, "<Capacity>%d</Capacity>\r\n", NaviData.UsedCapacity);
492
                                sprintf(string, "<Capacity>%d</Capacity>\r\n", NaviData.UsedCapacity);
491
                                fputs_(string, doc->file);
493
                                fputs_(string, doc->file);
492
                           break;
494
                           break;
493
                           case 4:
495
                           case 4:
494
                                // Compass in deg
496
                                // Compass in deg
495
                                if(SimulationFlags) sprintf(string, "<Compass>%03d,%03d,%03d.%1d,%03d.0</Compass>\r\n",SimulatedDirection,SimulatedDirection,CompassSetpointCorrected/10,CompassSetpointCorrected%10,SimulatedDirection);
497
                                if(SimulationFlags) sprintf(string, "<Compass>%03d,%03d,%03d.%1d,%03d.0</Compass>\r\n",SimulatedDirection,SimulatedDirection,CompassSetpointCorrected/10,CompassSetpointCorrected%10,SimulatedDirection);
496
                                else sprintf(string, "<Compass>%03d,%03d,%03d.%1d,%03d.%1d</Compass>\r\n",FromFlightCtrl.GyroHeading/10,ToFlightCtrl.CompassHeading,CompassSetpointCorrected/10,CompassSetpointCorrected%10,GyroCompassCorrected/10,GyroCompassCorrected%10);
498
                                else sprintf(string, "<Compass>%03d,%03d,%03d.%1d,%03d.%1d</Compass>\r\n",FromFlightCtrl.GyroHeading/10,ToFlightCtrl.CompassHeading,CompassSetpointCorrected/10,CompassSetpointCorrected%10,GyroCompassCorrected/10,GyroCompassCorrected%10);
497
                                fputs_(string, doc->file);
499
                                fputs_(string, doc->file);
498
                                // magnetic field
500
                                // magnetic field
499
                                sprintf(string, "<MagnetField>%03d</MagnetField>\r\n",(u16) (EarthMagneticFieldFiltered/5));
501
                                sprintf(string, "<MagnetField>%03d</MagnetField>\r\n",(u16) (EarthMagneticFieldFiltered/5));
500
                                fputs_(string, doc->file);
502
                                fputs_(string, doc->file);
501
                                // magnetic inclination & error
503
                                // magnetic inclination & error
502
                                sprintf(string, "<MagnetInclination>%02d,%02d</MagnetInclination>\r\n",(s16)EarthMagneticInclinationFiltered/10,(s16)(EarthMagneticInclinationFiltered/10 - EarthMagneticInclinationTheoretic));
504
                                sprintf(string, "<MagnetInclination>%02d,%02d</MagnetInclination>\r\n",(s16)EarthMagneticInclinationFiltered/10,(s16)(EarthMagneticInclinationFiltered/10 - EarthMagneticInclinationTheoretic));
503
                                fputs_(string, doc->file);
505
                                fputs_(string, doc->file);
504
                                // Nick Angle ind deg
506
                                // Nick Angle ind deg
505
                                i16_1 = abs(FromFlightCtrl.AngleNick);
507
                                i16_1 = abs(FromFlightCtrl.AngleNick);
506
                                if(FromFlightCtrl.AngleNick < 0)        sprintf(string, "<NickAngle>-%d.%d</NickAngle>\r\n",i16_1/10,i16_1%10);
508
                                if(FromFlightCtrl.AngleNick < 0)        sprintf(string, "<NickAngle>-%d.%d</NickAngle>\r\n",i16_1/10,i16_1%10);
507
                                else                                                            sprintf(string, "<NickAngle>%d.%d</NickAngle>\r\n",i16_1/10,i16_1%10);
509
                                else                                                            sprintf(string, "<NickAngle>%d.%d</NickAngle>\r\n",i16_1/10,i16_1%10);
508
                                fputs_(string, doc->file);
510
                                fputs_(string, doc->file);
509
                                // Roll Angle in deg
511
                                // Roll Angle in deg
510
                                i16_1 = abs(FromFlightCtrl.AngleRoll);
512
                                i16_1 = abs(FromFlightCtrl.AngleRoll);
511
                                if(FromFlightCtrl.AngleRoll < 0)        sprintf(string, "<RollAngle>-%d.%d</RollAngle>\r\n",i16_1/10,i16_1%10);
513
                                if(FromFlightCtrl.AngleRoll < 0)        sprintf(string, "<RollAngle>-%d.%d</RollAngle>\r\n",i16_1/10,i16_1%10);
512
                                else                                                            sprintf(string, "<RollAngle>%d.%d</RollAngle>\r\n",i16_1/10,i16_1%10);
514
                                else                                                            sprintf(string, "<RollAngle>%d.%d</RollAngle>\r\n",i16_1/10,i16_1%10);
513
                                fputs_(string, doc->file);
515
                                fputs_(string, doc->file);
514
                           break;
516
                           break;
515
                           case 5:
517
                           case 5:
516
                                // BL Information
518
                                // BL Information
517
                switch(AmountOfMotors)
519
                switch(AmountOfMotors)
518
                                 {
520
                                 {
519
                                  case 4:
521
                                  case 4:
520
                                                sprintf(string, "<MotorCurrent>%d,%d,%d,%d</MotorCurrent>\r\n",BL3_Current(0),BL3_Current(1),BL3_Current(2),BL3_Current(3));
522
                                                sprintf(string, "<MotorCurrent>%d,%d,%d,%d</MotorCurrent>\r\n",BL3_Current(0),BL3_Current(1),BL3_Current(2),BL3_Current(3));
521
                                                fputs_(string, doc->file);
523
                                                fputs_(string, doc->file);
522
                                                sprintf(string, "<BL_Temperature>%d,%d,%d,%d</BL_Temperature>\r\n",Motor[0].Temperature,Motor[1].Temperature,Motor[2].Temperature,Motor[3].Temperature);
524
                                                sprintf(string, "<BL_Temperature>%d,%d,%d,%d</BL_Temperature>\r\n",Motor[0].Temperature,Motor[1].Temperature,Motor[2].Temperature,Motor[3].Temperature);
523
                                                fputs_(string, doc->file);
525
                                                fputs_(string, doc->file);
524
                                                sprintf(string, "<MotorNOK>%d,%d,%d,%d</MotorNOK>\r\n",Motor[0].NotReadyCnt,Motor[1].NotReadyCnt,Motor[2].NotReadyCnt,Motor[3].NotReadyCnt);
526
                                                sprintf(string, "<MotorNOK>%d,%d,%d,%d</MotorNOK>\r\n",Motor[0].NotReadyCnt,Motor[1].NotReadyCnt,Motor[2].NotReadyCnt,Motor[3].NotReadyCnt);
525
                                                fputs_(string, doc->file);
527
                                                fputs_(string, doc->file);
526
                                                break;
528
                                                break;
527
                                  case 6:
529
                                  case 6:
528
                                                sprintf(string, "<MotorCurrent>%d,%d,%d,%d,%d,%d</MotorCurrent>\r\n",BL3_Current(0),BL3_Current(1),BL3_Current(2),BL3_Current(3),BL3_Current(4),BL3_Current(5));
530
                                                sprintf(string, "<MotorCurrent>%d,%d,%d,%d,%d,%d</MotorCurrent>\r\n",BL3_Current(0),BL3_Current(1),BL3_Current(2),BL3_Current(3),BL3_Current(4),BL3_Current(5));
529
                                                fputs_(string, doc->file);
531
                                                fputs_(string, doc->file);
530
                                                sprintf(string, "<BL_Temperature>%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);
532
                                                sprintf(string, "<BL_Temperature>%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);
531
                                                fputs_(string, doc->file);
533
                                                fputs_(string, doc->file);
532
                                                sprintf(string, "<MotorNOK>%d,%d,%d,%d,%d,%d</MotorNOK>\r\n",Motor[0].NotReadyCnt,Motor[1].NotReadyCnt,Motor[2].NotReadyCnt,Motor[3].NotReadyCnt,Motor[4].NotReadyCnt,Motor[5].NotReadyCnt);
534
                                                sprintf(string, "<MotorNOK>%d,%d,%d,%d,%d,%d</MotorNOK>\r\n",Motor[0].NotReadyCnt,Motor[1].NotReadyCnt,Motor[2].NotReadyCnt,Motor[3].NotReadyCnt,Motor[4].NotReadyCnt,Motor[5].NotReadyCnt);
533
                                                fputs_(string, doc->file);
535
                                                fputs_(string, doc->file);
534
                                                break;
536
                                                break;
535
                                  case 8:
537
                                  case 8:
536
                                                sprintf(string, "<MotorCurrent>%d,%d,%d,%d,%d,%d,%d,%d</MotorCurrent>\r\n",BL3_Current(0),BL3_Current(1),BL3_Current(2),BL3_Current(3),BL3_Current(4),BL3_Current(5),BL3_Current(6),BL3_Current(7));
538
                                                sprintf(string, "<MotorCurrent>%d,%d,%d,%d,%d,%d,%d,%d</MotorCurrent>\r\n",BL3_Current(0),BL3_Current(1),BL3_Current(2),BL3_Current(3),BL3_Current(4),BL3_Current(5),BL3_Current(6),BL3_Current(7));
537
                                                fputs_(string, doc->file);
539
                                                fputs_(string, doc->file);
538
                                                sprintf(string, "<BL_Temperature>%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);
540
                                                sprintf(string, "<BL_Temperature>%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);
539
                                                fputs_(string, doc->file);
541
                                                fputs_(string, doc->file);
540
                                                sprintf(string, "<MotorNOK>%d,%d,%d,%d,%d,%d,%d,%d</MotorNOK>\r\n",Motor[0].NotReadyCnt,Motor[1].NotReadyCnt,Motor[2].NotReadyCnt,Motor[3].NotReadyCnt,Motor[4].NotReadyCnt,Motor[5].NotReadyCnt,Motor[6].NotReadyCnt,Motor[7].NotReadyCnt);
542
                                                sprintf(string, "<MotorNOK>%d,%d,%d,%d,%d,%d,%d,%d</MotorNOK>\r\n",Motor[0].NotReadyCnt,Motor[1].NotReadyCnt,Motor[2].NotReadyCnt,Motor[3].NotReadyCnt,Motor[4].NotReadyCnt,Motor[5].NotReadyCnt,Motor[6].NotReadyCnt,Motor[7].NotReadyCnt);
541
                                                fputs_(string, doc->file);
543
                                                fputs_(string, doc->file);
542
                                                break;
544
                                                break;
543
                                  case 10:
545
                                  case 10:
544
                                  case 12:
546
                                  case 12:
545
                                                sprintf(string, "<MotorCurrent>%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d</MotorCurrent>\r\n",BL3_Current(0),BL3_Current(1),BL3_Current(2),BL3_Current(3),BL3_Current(4),BL3_Current(5),BL3_Current(6),BL3_Current(7),BL3_Current(8),BL3_Current(9),BL3_Current(10),BL3_Current(11));
547
                                                sprintf(string, "<MotorCurrent>%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d</MotorCurrent>\r\n",BL3_Current(0),BL3_Current(1),BL3_Current(2),BL3_Current(3),BL3_Current(4),BL3_Current(5),BL3_Current(6),BL3_Current(7),BL3_Current(8),BL3_Current(9),BL3_Current(10),BL3_Current(11));
546
                                                fputs_(string, doc->file);
548
                                                fputs_(string, doc->file);
547
                                                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);
549
                                                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);
548
                                                fputs_(string, doc->file);
550
                                                fputs_(string, doc->file);
549
                                                sprintf(string, "<MotorNOK>%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d</MotorNOK>\r\n",Motor[0].NotReadyCnt,Motor[1].NotReadyCnt,Motor[2].NotReadyCnt,Motor[3].NotReadyCnt,Motor[4].NotReadyCnt,Motor[5].NotReadyCnt,Motor[6].NotReadyCnt,Motor[7].NotReadyCnt,Motor[8].NotReadyCnt,Motor[9].NotReadyCnt,Motor[10].NotReadyCnt,Motor[11].NotReadyCnt);
551
                                                sprintf(string, "<MotorNOK>%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d</MotorNOK>\r\n",Motor[0].NotReadyCnt,Motor[1].NotReadyCnt,Motor[2].NotReadyCnt,Motor[3].NotReadyCnt,Motor[4].NotReadyCnt,Motor[5].NotReadyCnt,Motor[6].NotReadyCnt,Motor[7].NotReadyCnt,Motor[8].NotReadyCnt,Motor[9].NotReadyCnt,Motor[10].NotReadyCnt,Motor[11].NotReadyCnt);
550
                                                fputs_(string, doc->file);
552
                                                fputs_(string, doc->file);
551
                                                break;
553
                                                break;
552
                                  default:
554
                                  default:
553
                                                sprintf(string, "<MotorCurrent>%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d</MotorCurrent>\r\n",BL3_Current(0),BL3_Current(1),BL3_Current(2),BL3_Current(3),BL3_Current(4),BL3_Current(5),BL3_Current(6),BL3_Current(7),BL3_Current(8),BL3_Current(9),BL3_Current(10),BL3_Current(11),BL3_Current(12),BL3_Current(13),BL3_Current(14),BL3_Current(15));
555
                                                sprintf(string, "<MotorCurrent>%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d</MotorCurrent>\r\n",BL3_Current(0),BL3_Current(1),BL3_Current(2),BL3_Current(3),BL3_Current(4),BL3_Current(5),BL3_Current(6),BL3_Current(7),BL3_Current(8),BL3_Current(9),BL3_Current(10),BL3_Current(11),BL3_Current(12),BL3_Current(13),BL3_Current(14),BL3_Current(15));
554
                                                fputs_(string, doc->file);
556
                                                fputs_(string, doc->file);
555
                                                sprintf(string, "<BL_Temperature>%d,%d,%d,%d,%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,Motor[12].Temperature,Motor[13].Temperature,Motor[14].Temperature,Motor[15].Temperature);
557
                                                sprintf(string, "<BL_Temperature>%d,%d,%d,%d,%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,Motor[12].Temperature,Motor[13].Temperature,Motor[14].Temperature,Motor[15].Temperature);
556
                                                fputs_(string, doc->file);
558
                                                fputs_(string, doc->file);
557
                                                sprintf(string, "<MotorNOK>%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d</MotorNOK>\r\n",Motor[0].NotReadyCnt,Motor[1].NotReadyCnt,Motor[2].NotReadyCnt,Motor[3].NotReadyCnt,Motor[4].NotReadyCnt,Motor[5].NotReadyCnt,Motor[6].NotReadyCnt,Motor[7].NotReadyCnt,Motor[8].NotReadyCnt,Motor[9].NotReadyCnt,Motor[10].NotReadyCnt,Motor[11].NotReadyCnt,Motor[12].NotReadyCnt,Motor[13].NotReadyCnt,Motor[14].NotReadyCnt,Motor[15].NotReadyCnt);
559
                                                sprintf(string, "<MotorNOK>%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d</MotorNOK>\r\n",Motor[0].NotReadyCnt,Motor[1].NotReadyCnt,Motor[2].NotReadyCnt,Motor[3].NotReadyCnt,Motor[4].NotReadyCnt,Motor[5].NotReadyCnt,Motor[6].NotReadyCnt,Motor[7].NotReadyCnt,Motor[8].NotReadyCnt,Motor[9].NotReadyCnt,Motor[10].NotReadyCnt,Motor[11].NotReadyCnt,Motor[12].NotReadyCnt,Motor[13].NotReadyCnt,Motor[14].NotReadyCnt,Motor[15].NotReadyCnt);
558
                                                fputs_(string, doc->file);
560
                                                fputs_(string, doc->file);
559
                                                break;
561
                                                break;
560
                                  }
562
                                  }
561
                           break;
563
                           break;
562
                           case 6:
564
                           case 6:
563
/*                              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]);
565
/*                              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]);
564
                                fputs_(string, doc->file);
566
                                fputs_(string, doc->file);
565
                                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]);
567
                                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]);
566
                                fputs_(string, doc->file);
568
                                fputs_(string, doc->file);
567
*/                              sprintf(string, "<AvaiableMotorPower>%03d</AvaiableMotorPower>\r\n",Logging_BL_MinOfMaxPWM);
569
*/                              sprintf(string, "<AvaiableMotorPower>%03d</AvaiableMotorPower>\r\n",Logging_BL_MinOfMaxPWM);
568
                                Logging_BL_MinOfMaxPWM = BL_MinOfMaxPWM;
570
                                Logging_BL_MinOfMaxPWM = BL_MinOfMaxPWM;
569
                                fputs_(string, doc->file);
571
                                fputs_(string, doc->file);
570
 
572
 
571
                                // Gas values 
573
                                // Gas values 
572
                                if(LoggingGasCnt > 1) LoggingGasFilter = LoggingGasFilter / LoggingGasCnt;
574
                                if(LoggingGasCnt > 1) LoggingGasFilter = LoggingGasFilter / LoggingGasCnt;
573
                                sprintf(string, "<Gas>%03d,%03d</Gas>\r\n",(u16)LoggingGasFilter,HoverGas);
575
                                sprintf(string, "<Gas>%03d,%03d</Gas>\r\n",(u16)LoggingGasFilter,HoverGas);
574
                                LoggingGasCnt = 0;
576
                                LoggingGasCnt = 0;
575
 
577
 
576
                                fputs_(string, doc->file);
578
                                fputs_(string, doc->file);
577
                                sprintf(string, "<FC_I2C_ErrorCounter>%03d</FC_I2C_ErrorCounter>\r\n",(s16)FC_I2C_ErrorConter);
579
                                sprintf(string, "<FC_I2C_ErrorCounter>%03d</FC_I2C_ErrorCounter>\r\n",(s16)FC_I2C_ErrorConter);
578
                                fputs_(string, doc->file);
580
                                fputs_(string, doc->file);
579
                                sprintf(string, "<FC_SPI_ErrorCounter>%03d</FC_SPI_ErrorCounter>\r\n",(s16)DebugOut.Analog[12]);
581
                                sprintf(string, "<FC_SPI_ErrorCounter>%03d</FC_SPI_ErrorCounter>\r\n",(s16)DebugOut.Analog[12]);
580
                                fputs_(string, doc->file);
582
                                fputs_(string, doc->file);
581
                                // Analog inputs of the NC
583
                                // Analog inputs of the NC
582
                                sprintf(string, "<AnalogInputs>%d,%d,%d,%d</AnalogInputs>\r\n",AnalogData.Ch4,AnalogData.Ch5,AnalogData.Ch6,AnalogData.Ch7);
584
                                sprintf(string, "<AnalogInputs>%d,%d,%d,%d</AnalogInputs>\r\n",AnalogData.Ch4,AnalogData.Ch5,AnalogData.Ch6,AnalogData.Ch7);
583
                                fputs_(string, doc->file);
585
                                fputs_(string, doc->file);
584
                                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°
586
                                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°
585
                                fputs_(string, doc->file);
587
                                fputs_(string, doc->file);
586
 
588
 
587
                        if(NC_GPS_ModeCharacter == 'F') // Failsafe Point is active
589
                        if(NC_GPS_ModeCharacter == 'F') // Failsafe Point is active
588
                        {
590
                        {
589
                                sprintf(string, "<WP>FAIL,%d,%d,%d</WP>\r\n",NaviData.WaypointIndex,NaviData.WaypointNumber,LogFC_WP_EventChannel);      // x of y Waypoints and the actual value of the Event Channel
591
                                sprintf(string, "<WP>FAIL,%d,%d,%d</WP>\r\n",NaviData.WaypointIndex,NaviData.WaypointNumber,LogFC_WP_EventChannel);      // x of y Waypoints and the actual value of the Event Channel
590
                                LogFC_WP_EventChannel = 0;
592
                                LogFC_WP_EventChannel = 0;
591
                        }
593
                        }
592
                         else
594
                         else
593
                        {
595
                        {
594
                                if(GPS_pWaypoint != NULL) // if WP exist
596
                                if(GPS_pWaypoint != NULL) // if WP exist
595
                                 {                                        // copy that name
597
                                 {                                        // copy that name
596
                                  u8 i;
598
                                  u8 i;
597
                                   for(i=0;i<4;i++)
599
                                   for(i=0;i<4;i++)
598
                                    {
600
                                    {
599
                                         name[i] = GPS_pWaypoint->Name[i];
601
                                         name[i] = GPS_pWaypoint->Name[i];
600
                                         if(name[i] < ' ') name[i] = ' ';
602
                                         if(name[i] < ' ') name[i] = ' ';
601
                                        }
603
                                        }
602
                                 }
604
                                 }
603
                                sprintf(string, "<WP>%s,%d,%d,%d</WP>\r\n",name,NaviData.WaypointIndex,NaviData.WaypointNumber,LogFC_WP_EventChannel);   // x of y Waypoints and the actual value of the Event Channel
605
                                sprintf(string, "<WP>%s,%d,%d,%d</WP>\r\n",name,NaviData.WaypointIndex,NaviData.WaypointNumber,LogFC_WP_EventChannel);   // x of y Waypoints and the actual value of the Event Channel
604
                                LogFC_WP_EventChannel = 0; // can be cleared now
606
                                LogFC_WP_EventChannel = 0; // can be cleared now
605
                          }
607
                          }
606
                                fputs_(string, doc->file);
608
                                fputs_(string, doc->file);
607
 
609
 
608
                                sprintf(string, "<ShutterCnt>%d</ShutterCnt>\r\n",NaviData_Volatile.ShutterCounter);   
610
                                sprintf(string, "<ShutterCnt>%d</ShutterCnt>\r\n",NaviData_Volatile.ShutterCounter);   
609
                                LogFC_WP_EventChannel = 0; // can be cleared now
611
                                LogFC_WP_EventChannel = 0; // can be cleared now
610
                                fputs_(string, doc->file);
612
                                fputs_(string, doc->file);
611
                           break;
613
                           break;
612
                           case 7:
614
                           case 7:
613
                                // Target Bearing in deg
615
                                // Target Bearing in deg
614
                                sprintf(string, "<TargetBearing>%03d</TargetBearing>\r\n", NaviData.TargetPositionDeviation.Bearing);
616
                                sprintf(string, "<TargetBearing>%03d</TargetBearing>\r\n", NaviData.TargetPositionDeviation.Bearing);
615
                                fputs_(string, doc->file);
617
                                fputs_(string, doc->file);
616
                                // Target Distance in dm
618
                                // Target Distance in dm
617
                                sprintf(string, "<TargetDistance>%d</TargetDistance>\r\n", NaviData.TargetPositionDeviation.Distance);
619
                                sprintf(string, "<TargetDistance>%d</TargetDistance>\r\n", NaviData.TargetPositionDeviation.Distance);
618
                                fputs_(string, doc->file);
620
                                fputs_(string, doc->file);
619
                                // Course in deg
621
                                // Course in deg
620
                                sprintf(string, "<Course>%03d</Course>\r\n", NaviData.Heading);
622
                                sprintf(string, "<Course>%03d</Course>\r\n", NaviData.Heading);
621
                                fputs_(string, doc->file);
623
                                fputs_(string, doc->file);
622
                                // Ground Speed in cm/s
624
                                // Ground Speed in cm/s
623
                                sprintf(string, "<GroundSpeed>%d</GroundSpeed>\r\n", NaviData.GroundSpeed);
625
                                sprintf(string, "<GroundSpeed>%d</GroundSpeed>\r\n", NaviData.GroundSpeed);
624
                                fputs_(string, doc->file);
626
                                fputs_(string, doc->file);
625
                                // Vertical Speed in cm/s
627
                                // Vertical Speed in cm/s
626
                                sprintf(string, "<VerticalSpeed>%d</VerticalSpeed>\r\n", NaviData.TopSpeed);
628
                                sprintf(string, "<VerticalSpeed>%d</VerticalSpeed>\r\n", NaviData.TopSpeed);
627
                                fputs_(string, doc->file);
629
                                fputs_(string, doc->file);
628
                                // RC Sticks as Nick/Roll/Yaw
630
                                // RC Sticks as Nick/Roll/Yaw
629
                                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]);
631
                                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]);
630
                                fputs_(string, doc->file);
632
                                fputs_(string, doc->file);
631
                                // GPS Sticks as Nick/Roll/Yaw
633
                                // GPS Sticks as Nick/Roll/Yaw
632
                                sprintf(string, "<GPSSticks>%d,%d,%d,'%c'</GPSSticks>\r\n", ToFlightCtrl.GPSStick.Nick, ToFlightCtrl.GPSStick.Roll, 0 ,NC_GPS_ModeCharacter);
634
                                sprintf(string, "<GPSSticks>%d,%d,%d,'%c'</GPSSticks>\r\n", ToFlightCtrl.GPSStick.Nick, ToFlightCtrl.GPSStick.Roll, 0 ,NC_GPS_ModeCharacter);
633
                                fputs_(string, doc->file);
635
                                fputs_(string, doc->file);
634
                                // RC Quality
636
                                // RC Quality
635
                                sprintf(string, "<RCQuality>%d</RCQuality>\r\n", FC.RC_Quality);
637
                                sprintf(string, "<RCQuality>%d</RCQuality>\r\n", FC.RC_Quality);
636
                                fputs_(string, doc->file);
638
                                fputs_(string, doc->file);
637
                                // raw GPS altitude
639
                                // raw GPS altitude
638
                                i32_2 = altitude;
640
                                i32_2 = altitude;
639
                    if(GPSData.Position.Status == INVALID) i32_2 = 0;
641
                    if(GPSData.Position.Status == INVALID) i32_2 = 0;
640
                                i32_1 = i32_2/1000L;
642
                                i32_1 = i32_2/1000L;
641
                                i32_2 = i32_2%1000L;
643
                                i32_2 = i32_2%1000L;
642
                                if(altitude < 0) sprintf(string,"<ele_raw>-%ld.%03ld</ele_raw>\r\n",labs(i32_1),labs(i32_2));
644
                                if(altitude < 0) sprintf(string,"<ele_raw>-%ld.%03ld</ele_raw>\r\n",labs(i32_1),labs(i32_2));
643
                                else                     sprintf(string,"<ele_raw>%ld.%03ld</ele_raw>\r\n",i32_1,i32_2);
645
                                else                     sprintf(string,"<ele_raw>%ld.%03ld</ele_raw>\r\n",i32_1,i32_2);
644
                                fputs_(string, doc->file);
646
                                fputs_(string, doc->file);
645
                           break;
647
                           break;
646
                           case 8:
648
                           case 8:
647
                                // Drift compensation
649
                                // Drift compensation
648
/*
650
/*
649
                                if(Parameter.Driftkomp)
651
                                if(Parameter.Driftkomp)
650
                                 {
652
                                 {
651
                                  sprintf(string, "<Neutral>%d,%d,%d</Neutral>\r\n", FC.AdNeutralNick,FC.AdNeutralRoll,FC.AdNeutralYaw);
653
                                  sprintf(string, "<Neutral>%d,%d,%d</Neutral>\r\n", FC.AdNeutralNick,FC.AdNeutralRoll,FC.AdNeutralYaw);
652
                                  fputs_(string, doc->file);
654
                                  fputs_(string, doc->file);
653
                                 }
655
                                 }
654
*/
656
*/
655
                                // Navigation Update speed (in 0.1Hz)
657
                                // Navigation Update speed (in 0.1Hz)
656
                                sprintf(string, "<GPSInfo>%d,%d,%d</GPSInfo>\r\n",FreqNewGpsData,GPSData.Flags,GPSData.SatFix); // FreqGpsNavProcessed
658
                                sprintf(string, "<GPSInfo>%d,%d,%d</GPSInfo>\r\n",FreqNewGpsData,GPSData.Flags,GPSData.SatFix); // FreqGpsNavProcessed
657
                                fputs_(string, doc->file);
659
                                fputs_(string, doc->file);
658
                                // eof extensions
660
                                // eof extensions
659
                                sprintf(string, "</extensions>\r\n");
661
                                sprintf(string, "</extensions>\r\n");
660
                                fputs_(string, doc->file);
662
                                fputs_(string, doc->file);
661
                                sprintf(string, "</trkpt>\r\n");
663
                                sprintf(string, "</trkpt>\r\n");
662
                                fputs_(string, doc->file);
664
                                fputs_(string, doc->file);
663
                           break;
665
                           break;
664
                          }
666
                          }
665
                        retvalue = 1;
667
                        retvalue = 1;
666
                        }
668
                        }
667
                }
669
                }
668
        }
670
        }
669
        return(retvalue);
671
        return(retvalue);
670
}
672
}
671
 
673
 
672
//________________________________________________________________________________________________________________________________________
674
//________________________________________________________________________________________________________________________________________
673
// Function:    u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *)
675
// Function:    u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *)
674
//
676
//
675
// Description: This function opens and adds gpscoordinates to an GPX-Document. The document will be opened, if not already done
677
// Description: This function opens and adds gpscoordinates to an GPX-Document. The document will be opened, if not already done
676
//
678
//
677
//
679
//
678
// Returnvalue: '1' if an gps coordinate was logged
680
// Returnvalue: '1' if an gps coordinate was logged
679
//________________________________________________________________________________________________________________________________________
681
//________________________________________________________________________________________________________________________________________
680
 
682
 
681
u8 GPX_LoggGPSCoordinates(GPX_Document_t *doc,unsigned char part)
683
u8 GPX_LoggGPSCoordinates(GPX_Document_t *doc,unsigned char part)
682
{
684
{
683
        u8 retval = 0;
685
        u8 retval = 0;
684
        while(doc->state != GPX_DOC_TRACKSEGMENT_OPENED)                                // automatic create document with default filename on the card.
686
        while(doc->state != GPX_DOC_TRACKSEGMENT_OPENED)                                // automatic create document with default filename on the card.
685
        {
687
        {
686
                switch(doc->state)
688
                switch(doc->state)
687
                {
689
                {
688
                        case GPX_DOC_CLOSED:                                                                    // document hasn't been opened yet therefore it will be initialized automatically
690
                        case GPX_DOC_CLOSED:                                                                    // document hasn't been opened yet therefore it will be initialized automatically
689
                                retval = GPX_DocumentOpen("default.gpx",doc);           // open the gpx-document with a standardname.
691
                                retval = GPX_DocumentOpen("default.gpx",doc);           // open the gpx-document with a standardname.
690
                        break;
692
                        break;
691
 
693
 
692
                        case GPX_DOC_OPENED:                                                                    // if a document has been opened before but no track exists:
694
                        case GPX_DOC_OPENED:                                                                    // if a document has been opened before but no track exists:
693
                                retval = GPX_TrackBegin(doc);
695
                                retval = GPX_TrackBegin(doc);
694
                        break;
696
                        break;
695
 
697
 
696
                        case GPX_DOC_TRACK_OPENED:                                                              // add tracksegement to the track
698
                        case GPX_DOC_TRACK_OPENED:                                                              // add tracksegement to the track
697
                                retval = GPX_TrackSegmentBegin(doc);
699
                                retval = GPX_TrackSegmentBegin(doc);
698
                        break;
700
                        break;
699
 
701
 
700
                        default:
702
                        default:
701
                                retval = 0;
703
                                retval = 0;
702
                        break;
704
                        break;
703
 
705
 
704
                }
706
                }
705
                if(retval != 1) return(retval); // stop on error
707
                if(retval != 1) return(retval); // stop on error
706
        }
708
        }
707
 
709
 
708
        if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED)                                           // if the document was opened add coordinates to the document.
710
        if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED)                                           // if the document was opened add coordinates to the document.
709
        {
711
        {
710
                retval = GPX_TrackSegementAddPoint(doc,part);                                           // add a track segment point
712
                retval = GPX_TrackSegementAddPoint(doc,part);                                           // add a track segment point
711
        }
713
        }
712
        return(retval);
714
        return(retval);
713
}
715
}
714
 
716
 
715
 
717