Subversion Repositories NaviCtrl

Rev

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

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