Subversion Repositories NaviCtrl

Rev

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

Rev 516 Rev 764
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 "kml.h"
59
#include "kml.h"
60
#include "kml_header.h"
60
#include "kml_header.h"
61
#include "uart1.h"
61
#include "uart1.h"
62
#include "logging.h"
62
#include "logging.h"
63
#include "timer1.h"
63
#include "timer1.h"
-
 
64
#include "main.h"
-
 
65
 
64
 
66
 
65
 
67
 
66
//________________________________________________________________________________________________________________________________________
68
//________________________________________________________________________________________________________________________________________
67
// Module name:                 kml.c
69
// Module name:                 kml.c
68
// Compiler used:               avr-gcc 3.4.5
70
// Compiler used:               avr-gcc 3.4.5
69
// Last Modifikation:   22.03.2009
71
// Last Modifikation:   22.03.2009
70
// Version:                             1.03
72
// Version:                             1.03
71
// Authors:                             Stephan Busker, Gregor Stobrawa
73
// Authors:                             Stephan Busker, Gregor Stobrawa
72
// Description:                 Source files to write gps-coordinates to a file in the kml (keyhole markup language) fileformat
74
// Description:                 Source files to write gps-coordinates to a file in the kml (keyhole markup language) fileformat
73
//                                              Copyright (C) 2007 Stephan Busker
75
//                                              Copyright (C) 2007 Stephan Busker
74
//........................................................................................................................................
76
//........................................................................................................................................
75
// Functions:                   extern u8       KML_LoggGPSCoordinates(struct str_gps_nav_data , KML_Document_t *);     // intializes the kml-document with standard filename and adds points to the file
77
// Functions:                   extern u8       KML_LoggGPSCoordinates(struct str_gps_nav_data , KML_Document_t *);     // intializes the kml-document with standard filename and adds points to the file
76
//                                              extern u8       KML_DocumentInit(KML_Document_t *doc)                                                           // initializes the kml-document to resetvalues.
78
//                                              extern u8       KML_DocumentInit(KML_Document_t *doc)                                                           // initializes the kml-document to resetvalues.
77
//                                              extern u8       KML_DocumentOpen(s8 *, KML_Document_t *);                                                       // opens a new kml document. A filename can be specified.
79
//                                              extern u8       KML_DocumentOpen(s8 *, KML_Document_t *);                                                       // opens a new kml document. A filename can be specified.
78
//                                              extern u8       KML_DocumentClose(KML_Document_t *doc);                                                         // closes an open document
80
//                                              extern u8       KML_DocumentClose(KML_Document_t *doc);                                                         // closes an open document
79
//                                              extern u8   KML_PlaceMarkOpen(KML_Document_t *);                                                                // opens a new placemark within the specified document
81
//                                              extern u8   KML_PlaceMarkOpen(KML_Document_t *);                                                                // opens a new placemark within the specified document
80
//                                              extern u8       KML_PlaceMarkClose(KML_Document_t *);                                                           // Closes the placemark
82
//                                              extern u8       KML_PlaceMarkClose(KML_Document_t *);                                                           // Closes the placemark
81
//                                              extern u8       KML_LineStringBegin(KML_Document_t *);                                                          // begins a new line within the actual placemark
83
//                                              extern u8       KML_LineStringBegin(KML_Document_t *);                                                          // begins a new line within the actual placemark
82
//                                              extern u8       KML_LineStringEnd(KML_Document_t *doc);                                                         // ends the actual linestring
84
//                                              extern u8       KML_LineStringEnd(KML_Document_t *doc);                                                         // ends the actual linestring
83
//                                              extern u8       KML_LineStringAddPoint(struct str_gps_nav_data, KML_Document_t *);      // adds a new point (gps-coordinates) to the actual linestring
85
//                                              extern u8       KML_LineStringAddPoint(struct str_gps_nav_data, KML_Document_t *);      // adds a new point (gps-coordinates) to the actual linestring
84
//........................................................................................................................................
86
//........................................................................................................................................
85
// ext. functions:
87
// ext. functions:
86
//
88
//
87
//........................................................................................................................................
89
//........................................................................................................................................
88
//
90
//
89
// URL:                                 www.Mikro-Control.de
91
// URL:                                 www.Mikro-Control.de
90
// mailto:                              stephan.busker@mikro-control.de
92
// mailto:                              stephan.busker@mikro-control.de
91
//________________________________________________________________________________________________________________________________________
93
//________________________________________________________________________________________________________________________________________
92
 
94
 
93
 
95
 
94
 
96
 
95
//________________________________________________________________________________________________________________________________________
97
//________________________________________________________________________________________________________________________________________
96
// Function:    KML_DocumentInit(KML_Document_t *)
98
// Function:    KML_DocumentInit(KML_Document_t *)
97
//
99
//
98
// Description: This function initializes the kml-document for further use.
100
// Description: This function initializes the kml-document for further use.
99
//
101
//
100
//
102
//
101
// Returnvalue: '1' if document was initialized
103
// Returnvalue: '1' if document was initialized
102
//________________________________________________________________________________________________________________________________________
104
//________________________________________________________________________________________________________________________________________
103
 
105
 
104
u8 KML_DocumentInit(KML_Document_t *doc)
106
u8 KML_DocumentInit(KML_Document_t *doc)
105
{                                                                                                              
107
{                                                                                                              
106
        doc->state       = KML_DOC_CLOSED;                                                                                                      // state of the kml-document
108
        doc->state       = KML_DOC_CLOSED;                                                                                                      // state of the kml-document
107
        doc->file        = NULL;
109
        doc->file        = NULL;
108
        return(1);
110
        return(1);
109
}
111
}
110
 
112
 
111
//________________________________________________________________________________________________________________________________________
113
//________________________________________________________________________________________________________________________________________
112
// Function:    KML_Document_Open(void);
114
// Function:    KML_Document_Open(void);
113
//
115
//
114
// Description: This function opens a new KML- document with the specified name and creates the document header within the file.
116
// Description: This function opens a new KML- document with the specified name and creates the document header within the file.
115
//
117
//
116
//
118
//
117
// Returnvalue: '1' if the KML- file could be created.
119
// Returnvalue: '1' if the KML- file could be created.
118
//________________________________________________________________________________________________________________________________________
120
//________________________________________________________________________________________________________________________________________
119
 
121
 
120
u8 KML_DocumentOpen(s8 *name, KML_Document_t *doc)
122
u8 KML_DocumentOpen(s8 *name, KML_Document_t *doc)
121
{
123
{
122
 
124
 
123
        u8 retvalue = 0;
125
        u8 retvalue = 0;
124
        s8 string[50];
126
        s8 string[50];
125
 
127
 
126
        if(doc == NULL) return(0);
128
        if(doc == NULL) return(0);
127
 
129
 
128
        KML_DocumentInit(doc);                                                                                                          // intialize the document with resetvalues
130
        KML_DocumentInit(doc);                                                                                                          // intialize the document with resetvalues
129
        doc->file = fopen_(name,'a');                                                                                           // open a new file with the specified filename on the memorycard.
131
        doc->file = fopen_(name,'a');                                                                                           // open a new file with the specified filename on the memorycard.
130
 
132
 
131
        if(doc->file != NULL)                                                                                                           // could the file be opened?
133
        if(doc->file != NULL)                                                                                                           // could the file be opened?
132
        {
134
        {
133
                retvalue = 1;                                                                                                                   // the document could be created on the drive.
135
                retvalue = 1;                                                                                                                   // the document could be created on the drive.
134
                doc->state = KML_DOC_OPENED;                                                                                            // change document state to opened. At next a placemark has to be opened.
136
                doc->state = KML_DOC_OPENED;                                                                                            // change document state to opened. At next a placemark has to be opened.
135
                fwrite_((void*)KML_DOCUMENT_HEADER1, sizeof(KML_DOCUMENT_HEADER1)-1,1,doc->file);// write the KML-header to the document.
137
                fwrite_((void*)KML_DOCUMENT_HEADER1, sizeof(KML_DOCUMENT_HEADER1)-1,1,doc->file);// write the KML-header to the document.
-
 
138
                if(OEM_String[0] == 255) { sprintf(string, "MikroKopter "); fputs_(string, doc->file); }
-
 
139
            else {      sprintf(string, "%s ",OEM_String);      fputs_(string, doc->file); }
136
                sprintf(string, "%4i.%02i.%02i Nr:%i (%02i%02i%02i%02i)", SystemTime.Year, SystemTime.Month, SystemTime.Day, KML_Filenum, SystemTime.Year%100, SystemTime.Month, SystemTime.Day, KML_Filenum);
140
                sprintf(string, "%4i.%02i.%02i Nr:%i (%02i%02i%02i%02i)", SystemTime.Year, SystemTime.Month, SystemTime.Day, KML_Filenum, SystemTime.Year%100, SystemTime.Month, SystemTime.Day, KML_Filenum);
137
                fputs_(string, doc->file);
141
                fputs_(string, doc->file);
138
                fwrite_((void*)KML_DOCUMENT_HEADER2, sizeof(KML_DOCUMENT_HEADER2)-1,1,doc->file);// write the KML-header to the document.
142
                fwrite_((void*)KML_DOCUMENT_HEADER2, sizeof(KML_DOCUMENT_HEADER2)-1,1,doc->file);// write the KML-header to the document.
139
        }
143
        }
140
 
144
 
141
        return(retvalue);
145
        return(retvalue);
142
}
146
}
143
 
147
 
144
//________________________________________________________________________________________________________________________________________
148
//________________________________________________________________________________________________________________________________________
145
// Function:    DocumentClose(KML_Document_t *doc);
149
// Function:    DocumentClose(KML_Document_t *doc);
146
//
150
//
147
// Description: This function closes the document specified by doc.
151
// Description: This function closes the document specified by doc.
148
//
152
//
149
//
153
//
150
// Returnvalue: '1' if the KML- file could be closed.
154
// Returnvalue: '1' if the KML- file could be closed.
151
//________________________________________________________________________________________________________________________________________
155
//________________________________________________________________________________________________________________________________________
152
 
156
 
153
u8 KML_DocumentClose(KML_Document_t *doc)
157
u8 KML_DocumentClose(KML_Document_t *doc)
154
{
158
{
155
 
159
 
156
        u8 retvalue = 1;
160
        u8 retvalue = 1;
157
 
161
 
158
        if(doc == NULL) return(0);
162
        if(doc == NULL) return(0);
159
 
163
 
160
        while(doc->state != KML_DOC_CLOSED)                                                             // close linestring, placemark and document before closing the file on the memorycard
164
        while(doc->state != KML_DOC_CLOSED)                                                             // close linestring, placemark and document before closing the file on the memorycard
161
        {
165
        {
162
                switch(doc->state)
166
                switch(doc->state)
163
                {
167
                {
164
                        case KML_DOC_LINESTRING_OPENED:
168
                        case KML_DOC_LINESTRING_OPENED:
165
                                KML_LineStringEnd(doc);                                                 // write terminating tag to end linestring.
169
                                KML_LineStringEnd(doc);                                                 // write terminating tag to end linestring.
166
                                break;
170
                                break;
167
 
171
 
168
                        case KML_DOC_PLACEMARK_OPENED:                                                  // write terminating tag to close placemark.
172
                        case KML_DOC_PLACEMARK_OPENED:                                                  // write terminating tag to close placemark.
169
                                KML_PlaceMarkClose(doc);
173
                                KML_PlaceMarkClose(doc);
170
                                break;
174
                                break;
171
 
175
 
172
                        case KML_DOC_OPENED:                                                                    // close the file on the memorycard
176
                        case KML_DOC_OPENED:                                                                    // close the file on the memorycard
173
                                if(doc->file != NULL)
177
                                if(doc->file != NULL)
174
                                {
178
                                {
175
                                        fwrite_((void*)KML_DOCUMENT_FOOTER, sizeof(KML_DOCUMENT_FOOTER)-1,1,doc->file); // write the KML- footer to the document.
179
                                        fwrite_((void*)KML_DOCUMENT_FOOTER, sizeof(KML_DOCUMENT_FOOTER)-1,1,doc->file); // write the KML- footer to the document.
176
                                        fclose_(doc->file);
180
                                        fclose_(doc->file);
177
                                        retvalue = 1;
181
                                        retvalue = 1;
178
                                }
182
                                }
179
                                doc->state = KML_DOC_CLOSED;
183
                                doc->state = KML_DOC_CLOSED;
180
                                break;
184
                                break;
181
 
185
 
182
                        default:
186
                        default:
183
                                doc->state = KML_DOC_CLOSED;
187
                                doc->state = KML_DOC_CLOSED;
184
                                break;
188
                                break;
185
 
189
 
186
                }
190
                }
187
        }
191
        }
188
        return(retvalue);
192
        return(retvalue);
189
}
193
}
190
 
194
 
191
//________________________________________________________________________________________________________________________________________
195
//________________________________________________________________________________________________________________________________________
192
// Function:    u8 KML_PlaceMarkOpen(KML_Document_t *doc);
196
// Function:    u8 KML_PlaceMarkOpen(KML_Document_t *doc);
193
//
197
//
194
// Description: This function adds a placemark to the document.
198
// Description: This function adds a placemark to the document.
195
//
199
//
196
//
200
//
197
// Returnvalue: '1' if the PlaceMark could be opened
201
// Returnvalue: '1' if the PlaceMark could be opened
198
//________________________________________________________________________________________________________________________________________
202
//________________________________________________________________________________________________________________________________________
199
 
203
 
200
u8 KML_PlaceMarkOpen(KML_Document_t *doc)
204
u8 KML_PlaceMarkOpen(KML_Document_t *doc)
201
{
205
{
202
        u8 retvalue = 0;
206
        u8 retvalue = 0;
203
        if(doc->state == KML_DOC_OPENED)
207
        if(doc->state == KML_DOC_OPENED)
204
        {
208
        {
205
                if(doc->file != NULL)
209
                if(doc->file != NULL)
206
                {
210
                {
207
                        doc->state = KML_DOC_PLACEMARK_OPENED;
211
                        doc->state = KML_DOC_PLACEMARK_OPENED;
208
                        retvalue = 1;
212
                        retvalue = 1;
209
                        fwrite_((void*)KML_PLACEMARK_HEADER, sizeof(KML_PLACEMARK_HEADER)-1,1,doc->file);
213
                        fwrite_((void*)KML_PLACEMARK_HEADER, sizeof(KML_PLACEMARK_HEADER)-1,1,doc->file);
210
                }
214
                }
211
        }
215
        }
212
        return(retvalue);
216
        return(retvalue);
213
}
217
}
214
 
218
 
215
//________________________________________________________________________________________________________________________________________
219
//________________________________________________________________________________________________________________________________________
216
// Function:    u8 PlaceMarkClose(KML_PlaceMark_t *place, File *file);
220
// Function:    u8 PlaceMarkClose(KML_PlaceMark_t *place, File *file);
217
//
221
//
218
// Description: This function ends the placemark opened before.
222
// Description: This function ends the placemark opened before.
219
//
223
//
220
//
224
//
221
// Returnvalue: 1' if the PlaceMark could be closed
225
// Returnvalue: 1' if the PlaceMark could be closed
222
//________________________________________________________________________________________________________________________________________
226
//________________________________________________________________________________________________________________________________________
223
 
227
 
224
u8 KML_PlaceMarkClose(KML_Document_t *doc)
228
u8 KML_PlaceMarkClose(KML_Document_t *doc)
225
{
229
{
226
 
230
 
227
        u8 retvalue = 0;                                                                                                                        // close the Placemark-tag of the corosponding document.
231
        u8 retvalue = 0;                                                                                                                        // close the Placemark-tag of the corosponding document.
228
 
232
 
229
        if(doc->state == KML_DOC_PLACEMARK_OPENED)
233
        if(doc->state == KML_DOC_PLACEMARK_OPENED)
230
        {
234
        {
231
                if(doc->file != NULL)
235
                if(doc->file != NULL)
232
                {
236
                {
233
                        doc->state = KML_DOC_OPENED;
237
                        doc->state = KML_DOC_OPENED;
234
                        fwrite_((void*)KML_PLACEMARK_FOOTER, sizeof(KML_PLACEMARK_FOOTER)-1,1,doc->file);
238
                        fwrite_((void*)KML_PLACEMARK_FOOTER, sizeof(KML_PLACEMARK_FOOTER)-1,1,doc->file);
235
                        retvalue = 1;
239
                        retvalue = 1;
236
                }
240
                }
237
        }
241
        }
238
 
242
 
239
        return(retvalue);
243
        return(retvalue);
240
}
244
}
241
 
245
 
242
//________________________________________________________________________________________________________________________________________
246
//________________________________________________________________________________________________________________________________________
243
// Function:    u8 LineStringBegin(KML_Document_t *doc);
247
// Function:    u8 LineStringBegin(KML_Document_t *doc);
244
//
248
//
245
// Description: This function ends the placemark opened before.
249
// Description: This function ends the placemark opened before.
246
//
250
//
247
//
251
//
248
// Returnvalue: '1' if the LineString could be started
252
// Returnvalue: '1' if the LineString could be started
249
//________________________________________________________________________________________________________________________________________
253
//________________________________________________________________________________________________________________________________________
250
 
254
 
251
u8 KML_LineStringBegin(KML_Document_t *doc)
255
u8 KML_LineStringBegin(KML_Document_t *doc)
252
{
256
{
253
 
257
 
254
        u8 retvalue = 0;
258
        u8 retvalue = 0;
255
 
259
 
256
        if(doc->state == KML_DOC_PLACEMARK_OPENED)
260
        if(doc->state == KML_DOC_PLACEMARK_OPENED)
257
        {
261
        {
258
                if(doc->file != NULL)
262
                if(doc->file != NULL)
259
                {
263
                {
260
                        doc->state = KML_DOC_LINESTRING_OPENED;
264
                        doc->state = KML_DOC_LINESTRING_OPENED;
261
                        fwrite_((void*)KML_LINESTRING_HEADER, sizeof(KML_LINESTRING_HEADER)-1,1,doc->file);
265
                        fwrite_((void*)KML_LINESTRING_HEADER, sizeof(KML_LINESTRING_HEADER)-1,1,doc->file);
262
                        Logged_KML_Counter = 0;
266
                        Logged_KML_Counter = 0;
263
                        retvalue = 1;
267
                        retvalue = 1;
264
                }
268
                }
265
        }
269
        }
266
        return(retvalue);
270
        return(retvalue);
267
}
271
}
268
 
272
 
269
//________________________________________________________________________________________________________________________________________
273
//________________________________________________________________________________________________________________________________________
270
// Function:    u8 KML_LineStringEnd(KML_Document_t *doc)
274
// Function:    u8 KML_LineStringEnd(KML_Document_t *doc)
271
//
275
//
272
// Description: This function ends the placemark opened before.
276
// Description: This function ends the placemark opened before.
273
//
277
//
274
//
278
//
275
// Returnvalue: '1' if the LineString could be terminated
279
// Returnvalue: '1' if the LineString could be terminated
276
//________________________________________________________________________________________________________________________________________
280
//________________________________________________________________________________________________________________________________________
277
 
281
 
278
u8 KML_LineStringEnd(KML_Document_t *doc)
282
u8 KML_LineStringEnd(KML_Document_t *doc)
279
{
283
{
280
 
284
 
281
        u8 retvalue = 0;
285
        u8 retvalue = 0;
282
 
286
 
283
        if(doc->state == KML_DOC_LINESTRING_OPENED)
287
        if(doc->state == KML_DOC_LINESTRING_OPENED)
284
        {
288
        {
285
                if(doc->file != NULL)
289
                if(doc->file != NULL)
286
                {
290
                {
287
                        doc->state = KML_DOC_PLACEMARK_OPENED;
291
                        doc->state = KML_DOC_PLACEMARK_OPENED;
288
                        fwrite_((void*)KML_LINESTRING_FOOTER, sizeof(KML_LINESTRING_FOOTER)-1,1,doc->file);
292
                        fwrite_((void*)KML_LINESTRING_FOOTER, sizeof(KML_LINESTRING_FOOTER)-1,1,doc->file);
289
                        retvalue = 1;
293
                        retvalue = 1;
290
                }
294
                }
291
        }
295
        }
292
        return(retvalue);
296
        return(retvalue);
293
}
297
}
294
 
298
 
295
//________________________________________________________________________________________________________________________________________
299
//________________________________________________________________________________________________________________________________________
296
// Function:    u8 LineStringAddPoint(gps_data_t, KML_Document_t *doc)
300
// Function:    u8 LineStringAddPoint(gps_data_t, KML_Document_t *doc)
297
//
301
//
298
// Description: This function adds a point to the specified document.
302
// Description: This function adds a point to the specified document.
299
//
303
//
300
//
304
//
301
// Returnvalue: '1' if a ppoint was added could be started
305
// Returnvalue: '1' if a ppoint was added could be started
302
//________________________________________________________________________________________________________________________________________
306
//________________________________________________________________________________________________________________________________________
303
 
307
 
304
u8 KML_LineStringAddPoint(KML_Document_t *doc)
308
u8 KML_LineStringAddPoint(KML_Document_t *doc)
305
{
309
{
306
 
310
 
307
        u8 retvalue = 0;
311
        u8 retvalue = 0;
308
        s8 string[50];
312
        s8 string[50];
309
        s32 rel_altitude = 0;
313
        s32 rel_altitude = 0;
310
 
314
 
311
        if(doc == NULL) return(0);
315
        if(doc == NULL) return(0);
312
 
316
 
313
        if(GPSData.Position.Status != INVALID)
317
        if(GPSData.Position.Status != INVALID)
314
        {
318
        {
315
                if(doc->state == KML_DOC_LINESTRING_OPENED)
319
                if(doc->state == KML_DOC_LINESTRING_OPENED)
316
                {
320
                {
317
                        if(doc->file != NULL)
321
                        if(doc->file != NULL)
318
                        {
322
                        {
319
                                s32 i1, i2;
323
                                s32 i1, i2;
320
                                u8 sign;
324
                                u8 sign;
321
                                if(GPSData.Position.Longitude < 0) sign = '-';
325
                                if(GPSData.Position.Longitude < 0) sign = '-';
322
                                else sign = '+';
326
                                else sign = '+';
323
                                i1 = abs(GPSData.Position.Longitude)/10000000L;
327
                                i1 = abs(GPSData.Position.Longitude)/10000000L;
324
                                i2 = abs(GPSData.Position.Longitude)%10000000L;
328
                                i2 = abs(GPSData.Position.Longitude)%10000000L;
325
                                sprintf(string,"\r\n%c%ld.%07ld,",sign, i1, i2);
329
                                sprintf(string,"\r\n%c%ld.%07ld,",sign, i1, i2);
326
                                fputs_(string, doc->file);
330
                                fputs_(string, doc->file);
327
                                if(GPSData.Position.Latitude < 0) sign = '-';
331
                                if(GPSData.Position.Latitude < 0) sign = '-';
328
                                else sign = '+';
332
                                else sign = '+';
329
                                i1 = abs(GPSData.Position.Latitude)/10000000L;
333
                                i1 = abs(GPSData.Position.Latitude)/10000000L;
330
                                i2 = abs(GPSData.Position.Latitude)%10000000L;
334
                                i2 = abs(GPSData.Position.Latitude)%10000000L;
331
                                sprintf(string,"%c%ld.%07ld,",sign, i1, i2);
335
                                sprintf(string,"%c%ld.%07ld,",sign, i1, i2);
332
                                fputs_(string, doc->file);
336
                                fputs_(string, doc->file);
333
                                // calculate relative altitude with respect to the altitude of the home position
337
                                // calculate relative altitude with respect to the altitude of the home position
334
                                rel_altitude = GPSData.Position.Altitude - NaviData.HomePosition.Altitude;
338
                                rel_altitude = GPSData.Position.Altitude - NaviData.HomePosition.Altitude;
335
                                if(rel_altitude < 0) rel_altitude = 0; // avoid negative altitudes in log
339
                                if(rel_altitude < 0) rel_altitude = 0; // avoid negative altitudes in log
336
                                i1 = rel_altitude/1000L;
340
                                i1 = rel_altitude/1000L;
337
                                i2 = rel_altitude%1000L;
341
                                i2 = rel_altitude%1000L;
338
                                sprintf(string,"%ld.%03ld",i1, i2);
342
                                sprintf(string,"%ld.%03ld",i1, i2);
339
                                fputs_(string, doc->file);
343
                                fputs_(string, doc->file);
340
                                Logged_KML_Counter++;
344
                                Logged_KML_Counter++;
341
                                retvalue = 1;
345
                                retvalue = 1;
342
                        }
346
                        }
343
                }
347
                }
344
        }
348
        }
345
        else
349
        else
346
        {
350
        {
347
                if(doc->state == KML_DOC_LINESTRING_OPENED)
351
                if(doc->state == KML_DOC_LINESTRING_OPENED)
348
                {
352
                {
349
                        if(doc->file != NULL)
353
                        if(doc->file != NULL)
350
                        {
354
                        {
351
                                sprintf(string,"\r\n");
355
                                sprintf(string,"\r\n");
352
                                fputs_(string, doc->file);
356
                                fputs_(string, doc->file);
353
                                Logged_KML_Counter++;
357
                                Logged_KML_Counter++;
354
                                retvalue = 1;
358
                                retvalue = 1;
355
                        }
359
                        }
356
                }
360
                }
357
        }
361
        }
358
        return(retvalue);
362
        return(retvalue);
359
}
363
}
360
 
364
 
361
//________________________________________________________________________________________________________________________________________
365
//________________________________________________________________________________________________________________________________________
362
// Function:    u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *)
366
// Function:    u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *)
363
//
367
//
364
// Description: This function opens adds gpscoordinates to an KML-Document. The document will be opened, if not already done
368
// Description: This function opens adds gpscoordinates to an KML-Document. The document will be opened, if not already done
365
//
369
//
366
//
370
//
367
// Returnvalue: '1' if an gps coordinate was logged
371
// Returnvalue: '1' if an gps coordinate was logged
368
//________________________________________________________________________________________________________________________________________
372
//________________________________________________________________________________________________________________________________________
369
 
373
 
370
u8 KML_LoggGPSCoordinates(KML_Document_t *doc)
374
u8 KML_LoggGPSCoordinates(KML_Document_t *doc)
371
{
375
{
372
        u8 retval = 0;
376
        u8 retval = 0;
373
        while(doc->state != KML_DOC_LINESTRING_OPENED)                                  // automatic create document with default filename on the card.
377
        while(doc->state != KML_DOC_LINESTRING_OPENED)                                  // automatic create document with default filename on the card.
374
        {
378
        {
375
                switch(doc->state)
379
                switch(doc->state)
376
                {
380
                {
377
                        case KML_DOC_CLOSED:                                                                    // document hasn't been opened yet therefore it will be initialized automatically
381
                        case KML_DOC_CLOSED:                                                                    // document hasn't been opened yet therefore it will be initialized automatically
378
                                retval = KML_DocumentOpen("default.kml",doc);   // open the kml-document with a standardname.
382
                                retval = KML_DocumentOpen("default.kml",doc);   // open the kml-document with a standardname.
379
                        break;
383
                        break;
380
 
384
 
381
                        case KML_DOC_OPENED:                                                                    // if a document has been opened before but no placemark exists:
385
                        case KML_DOC_OPENED:                                                                    // if a document has been opened before but no placemark exists:
382
                                retval = KML_PlaceMarkOpen(doc);
386
                                retval = KML_PlaceMarkOpen(doc);
383
                        break;
387
                        break;
384
 
388
 
385
                        case KML_DOC_PLACEMARK_OPENED:                                                  // add linestring to the placemark
389
                        case KML_DOC_PLACEMARK_OPENED:                                                  // add linestring to the placemark
386
                                retval = KML_LineStringBegin(doc);
390
                                retval = KML_LineStringBegin(doc);
387
                        break;
391
                        break;
388
 
392
 
389
                        default:
393
                        default:
390
                                retval = 0;
394
                                retval = 0;
391
                        break;
395
                        break;
392
 
396
 
393
                }
397
                }
394
                if(retval != 1) return(retval); // stop on error
398
                if(retval != 1) return(retval); // stop on error
395
        }
399
        }
396
 
400
 
397
        if(doc->state == KML_DOC_LINESTRING_OPENED)                                             // if the document was opened add coordinates to the document.
401
        if(doc->state == KML_DOC_LINESTRING_OPENED)                                             // if the document was opened add coordinates to the document.
398
        {
402
        {
399
                retval = KML_LineStringAddPoint(doc);
403
                retval = KML_LineStringAddPoint(doc);
400
        }
404
        }
401
        return(retval);
405
        return(retval);
402
}
406
}
403
 
407
 
404
 
408