Subversion Repositories NaviCtrl

Rev

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

Rev 27 Rev 41
1
/*#######################################################################################*/
1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 2008 Ingo Busker, Holger Buss
5
// + Copyright (c) 2008 Ingo Busker, Holger Buss
6
// + Nur für den privaten Gebrauch
6
// + Nur für den privaten Gebrauch
7
// + FOR NON COMMERCIAL USE ONLY
7
// + FOR NON COMMERCIAL USE ONLY
8
// + www.MikroKopter.com
8
// + www.MikroKopter.com
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), 
10
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
11
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. 
11
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
12
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt 
12
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
13
// + bzgl. der Nutzungsbedingungen aufzunehmen. 
13
// + bzgl. der Nutzungsbedingungen aufzunehmen.
14
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
14
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
15
// + Verkauf von Luftbildaufnahmen, usw.
15
// + Verkauf von Luftbildaufnahmen, usw.
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, 
17
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
18
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
18
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
20
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
21
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
21
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
22
// + eindeutig als Ursprung verlinkt werden
22
// + eindeutig als Ursprung verlinkt werden
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
24
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
25
// + Benutzung auf eigene Gefahr
25
// + Benutzung auf eigene Gefahr
26
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
26
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur 
28
// + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
29
// + mit unserer Zustimmung zulässig
29
// + mit unserer Zustimmung zulässig
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
31
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
32
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, 
33
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
34
// + this list of conditions and the following disclaimer.
34
// + this list of conditions and the following disclaimer.
35
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
35
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
36
// +     from this software without specific prior written permission.
36
// +     from this software without specific prior written permission.
37
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted 
37
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted
38
// +     for non-commercial use (directly or indirectly)
38
// +     for non-commercial use (directly or indirectly)
39
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
39
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
40
// +     with our written permission
40
// +     with our written permission
41
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be 
41
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
42
// +     clearly linked as origin 
42
// +     clearly linked as origin
43
// +   * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed
43
// +   * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed
44
//
44
//
45
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
45
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
46
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
48
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
49
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
50
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
50
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
51
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
52
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
53
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
54
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
55
// +  POSSIBILITY OF SUCH DAMAGE. 
55
// +  POSSIBILITY OF SUCH DAMAGE.
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57
 
-
 
-
 
57
#include <stdlib.h>
58
#include <stdio.h>
58
#include <stdio.h>
59
#include "main.h"
59
#include "91x_lib.h"
60
#include "kml.h"
60
#include "kml.h"
61
#include "kml_header.h"
61
#include "kml_header.h"
62
#include "fat16.h"
-
 
63
 
62
 
64
 
63
 
65
//________________________________________________________________________________________________________________________________________
64
//________________________________________________________________________________________________________________________________________
66
// Module name:                 kml.c 
65
// Module name:                 kml.c
67
// Compiler used:               avr-gcc 3.4.5
66
// Compiler used:               avr-gcc 3.4.5
68
// Last Modifikation:   17.03.2008
67
// Last Modifikation:   20.07.2008
69
// Version:                             1.02
68
// Version:                             1.02
70
// Authors:                             Stephan Busker  
69
// Authors:                             Stephan Busker
71
// Description:                 Source files to write gps-coordinates to a file in the kml (keyhole markup language) fileformat
70
// Description:                 Source files to write gps-coordinates to a file in the kml (keyhole markup language) fileformat
72
//                                              Copyright (C) 2007 Stephan Busker
71
//                                              Copyright (C) 2007 Stephan Busker
73
//........................................................................................................................................
72
//........................................................................................................................................
74
// 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
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
//                                              extern u8       KML_DocumentInit(KML_Document_t *doc)                                                           // initializes the kml-document to resetvalues.
74
//                                              extern u8       KML_DocumentInit(KML_Document_t *doc)                                                           // initializes the kml-document to resetvalues.
76
//                                              extern u8       KML_DocumentOpen(s8 *, KML_Document_t *);                                                       // opens a new kml document. A filename can be specified.
75
//                                              extern u8       KML_DocumentOpen(s8 *, KML_Document_t *);                                                       // opens a new kml document. A filename can be specified.
77
//                                              extern u8       KML_DocumentClose(KML_Document_t *doc);                                                         // closes an open document
76
//                                              extern u8       KML_DocumentClose(KML_Document_t *doc);                                                         // closes an open document
78
//                                              extern u8   KML_PlaceMarkOpen(s8 *name, KML_Document_t *);                                              // opens a new placemark within the specified document
77
//                                              extern u8   KML_PlaceMarkOpen(s8 *name, KML_Document_t *);                                              // opens a new placemark within the specified document
79
//                                              extern u8       KML_PlaceMarkClose( KML_Document_t *);                                                          // Closes the placemark 
78
//                                              extern u8       KML_PlaceMarkClose( KML_Document_t *);                                                          // Closes the placemark
80
//                                              extern u8       KML_LineStringBegin(KML_Document_t *);                                                          // begins a new line within the actual placemark
79
//                                              extern u8       KML_LineStringBegin(KML_Document_t *);                                                          // begins a new line within the actual placemark
81
//                                              extern u8       KML_LineStringEnd(KML_Document_t *doc);                                                         // ends the actual linestring
80
//                                              extern u8       KML_LineStringEnd(KML_Document_t *doc);                                                         // ends the actual linestring
82
//                                              extern u8       KML_LineStringAddPoint(struct str_gps_nav_data, KML_Document_t *);      // adds a new point (gps-coordinates) to 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
//........................................................................................................................................
82
//........................................................................................................................................
84
// ext. functions:              
83
// ext. functions:
85
//                                              
84
//
86
//........................................................................................................................................
85
//........................................................................................................................................
87
//
86
//
88
// URL:                                 www.Mikro-Control.de
87
// URL:                                 www.Mikro-Control.de
89
// mailto:                              stephan.busker@mikro-control.de
88
// mailto:                              stephan.busker@mikro-control.de
90
//________________________________________________________________________________________________________________________________________
89
//________________________________________________________________________________________________________________________________________
91
 
90
 
92
 
91
 
93
 
92
 
94
//________________________________________________________________________________________________________________________________________
93
//________________________________________________________________________________________________________________________________________
95
// Funtion:     KML_DocumentInit(KML_Document_t *)
94
// Function:    KML_DocumentInit(KML_Document_t *)
96
// 
95
//
97
// Description: This function initializes the kml-document for further use.
96
// Description: This function initializes the kml-document for further use.
98
//                              
97
//
99
//
98
//
100
// Returnvalue: '1' if document was initialized
99
// Returnvalue: '1' if document was initialized
101
//________________________________________________________________________________________________________________________________________
100
//________________________________________________________________________________________________________________________________________
102
 
101
 
103
u8 KML_DocumentInit(KML_Document_t *doc)
102
u8 KML_DocumentInit(KML_Document_t *doc)
104
{
103
{
105
        doc->name[0] = 0;                                                                                                                       // name of the document
104
        doc->name[0] = 0;                                                                                                                       // name of the document
106
        doc->state       = DOC_CLOSED;                                                                                                  // state of the kml-document
105
        doc->state       = DOC_CLOSED;                                                                                                  // state of the kml-document
107
        doc->file        = NULL;               
106
        doc->file        = NULL;
108
        doc->place.name[0]=0;
107
        doc->place.name[0]=0;
109
        doc->place.description[0]=0;
108
        doc->place.description[0]=0;
110
        return(1);
109
        return(1);
111
}
110
}
112
 
111
 
113
//________________________________________________________________________________________________________________________________________
112
//________________________________________________________________________________________________________________________________________
114
// Funtion:     KML_Document_Open(void);
113
// Function:    KML_Document_Open(void);
115
// 
114
//
116
// Description: This function opens a new KML- document with the specified name and creates the document header within the file.
115
// Description: This function opens a new KML- document with the specified name and creates the document header within the file.
117
//                              
-
 
118
//
116
//
-
 
117
//
119
// Returnvalue: '1' if the KML- file could be created. 
118
// Returnvalue: '1' if the KML- file could be created.
120
//________________________________________________________________________________________________________________________________________
119
//________________________________________________________________________________________________________________________________________
121
 
120
 
122
u8 KML_DocumentOpen(s8 *name, KML_Document_t *doc)
121
u8 KML_DocumentOpen(s8 *name, KML_Document_t *doc)
123
{
122
{
124
 
123
 
125
        u8 retvalue = 0;
124
        u8 retvalue = 0;
126
       
125
 
-
 
126
        if(doc == NULL) return(0);
-
 
127
 
127
        KML_DocumentInit(doc);                                                                                                                  // intialize the document with resetvalues
128
        KML_DocumentInit(doc);                                                                                                          // intialize the document with resetvalues
128
        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.
129
 
130
 
130
        if(doc->file != NULL)                                                                                                           // could the file be opened?
131
        if(doc->file != NULL)                                                                                                           // could the file be opened?
131
        {
132
        {
132
                retvalue = 1;                                                                                                                   // the document could be created on the drive.
133
                retvalue = 1;                                                                                                                   // the document could be created on the drive.
133
                doc->state = DOC_OPENED;                                                                                                // change document state to opened. At next a placemark has to be opened.
134
                doc->state = DOC_OPENED;                                                                                                // change document state to opened. At next a placemark has to be opened.
134
                fwrite_(KML_DOCUMENT_HEADER, sizeof(KML_DOCUMENT_HEADER)-1,1,doc->file);        // write the KML- footer to the document.
135
                fwrite_((void*)KML_DOCUMENT_HEADER, sizeof(KML_DOCUMENT_HEADER)-1,1,doc->file);// write the KML- footer to the document.
135
        }
136
        }
136
 
137
 
137
        return(retvalue);
138
        return(retvalue);
138
}
139
}
139
 
140
 
140
//________________________________________________________________________________________________________________________________________
141
//________________________________________________________________________________________________________________________________________
141
// Funtion:     DocumentClose(KML_Document_t *doc);
142
// Function:    DocumentClose(KML_Document_t *doc);
142
// 
143
//
143
// Description: This function closes the document specified by doc. 
144
// Description: This function closes the document specified by doc.
144
//                              
-
 
145
//
145
//
-
 
146
//
146
// Returnvalue: none
147
// Returnvalue: '1' if the KML- file could be closed.
147
//________________________________________________________________________________________________________________________________________
148
//________________________________________________________________________________________________________________________________________
148
 
149
 
149
u8 KML_DocumentClose(KML_Document_t *doc)
150
u8 KML_DocumentClose(KML_Document_t *doc)
150
{
151
{
151
 
152
 
-
 
153
        u8 retvalue = 1;
-
 
154
 
152
        u8 retvalue = 0;
155
        if(doc == NULL) return(0);
153
 
156
 
154
        while(doc->state != DOC_CLOSED)                                                         // close linestring, placemark and document before closing the file on the memorycard
157
        while(doc->state != DOC_CLOSED)                                                         // close linestring, placemark and document before closing the file on the memorycard
155
        {                      
158
        {
156
                switch(doc->state)
159
                switch(doc->state)
157
                {
160
                {
158
                        case DOC_LINESTRING_OPENED:
161
                        case DOC_LINESTRING_OPENED:
159
                                KML_LineStringEnd(doc);                                                 // write terminating tag to end linestring.
162
                                KML_LineStringEnd(doc);                                                 // write terminating tag to end linestring.
160
                                doc->state = DOC_PLACEMARK_OPENED;
163
                                doc->state = DOC_PLACEMARK_OPENED;
161
                        break;
164
                                break;
162
 
165
 
163
                        case DOC_PLACEMARK_OPENED:                                                      // write terminating tag to close placemark.
166
                        case DOC_PLACEMARK_OPENED:                                                      // write terminating tag to close placemark.
164
                                KML_PlaceMarkClose(doc);
167
                                KML_PlaceMarkClose(doc);
165
                                doc->state = DOC_OPENED;
168
                                doc->state = DOC_OPENED;
166
                        break;
169
                                break;
167
                       
170
 
168
                        case DOC_OPENED:                                                                        // close the file on the memorycard 
171
                        case DOC_OPENED:                                                                        // close the file on the memorycard
169
                                if(doc->file != NULL)
172
                                if(doc->file != NULL)
170
                                {
173
                                {
171
                                        fwrite_(KML_DOCUMENT_FOOTER, sizeof(KML_DOCUMENT_FOOTER)-1,1,doc->file);        // write the KML- footer to the document.
174
                                        fwrite_((void*)KML_DOCUMENT_FOOTER, sizeof(KML_DOCUMENT_FOOTER)-1,1,doc->file); // write the KML- footer to the document.
172
                                        fclose_(doc->file);                                                    
175
                                        fclose_(doc->file);
173
                                        retvalue = 1;
176
                                        retvalue = 1;
174
                                }
177
                                }
175
                                doc->state = DOC_CLOSED;                                               
178
                                doc->state = DOC_CLOSED;
176
                        break;
179
                                break;
177
                       
-
 
178
                }
-
 
179
        };
-
 
-
 
180
 
-
 
181
                        default:
-
 
182
                                doc->state = DOC_CLOSED;
-
 
183
                                break;
-
 
184
 
-
 
185
                }
180
 
186
        }
181
        return(retvalue);
187
        return(retvalue);
182
}
188
}
183
 
189
 
184
//________________________________________________________________________________________________________________________________________
190
//________________________________________________________________________________________________________________________________________
185
// Funtion:     u8 PlaceMarkOpen(s8 *name, File *file);
191
// Function:    u8 PlaceMarkOpen(s8 *name, File *file);
186
// 
192
//
187
// Description: This function adds a placemark to the document.
193
// Description: This function adds a placemark to the document.
188
//                              
-
 
189
//
194
//
-
 
195
//
190
// Returnvalue: none
196
// Returnvalue: '1' if the PlaceMark could be opened
191
//________________________________________________________________________________________________________________________________________
197
//________________________________________________________________________________________________________________________________________
192
 
198
 
193
u8 KML_PlaceMarkOpen(s8 *name, KML_Document_t *doc)
199
u8 KML_PlaceMarkOpen(s8 *name, KML_Document_t *doc)
194
{
200
{
195
 
201
 
196
        u8 retvalue = 0;
202
        u8 retvalue = 0;
197
 
203
 
198
        if(doc->file != NULL)
204
        if(doc->file != NULL)
199
        {
205
        {
200
                doc->state = DOC_PLACEMARK_OPENED;
206
                doc->state = DOC_PLACEMARK_OPENED;
201
                retvalue = 1;
207
                retvalue = 1;
202
                fwrite_(KML_PLACEMARK_HEADER, sizeof(KML_PLACEMARK_HEADER)-1,1,doc->file);                                             
208
                fwrite_((void*)KML_PLACEMARK_HEADER, sizeof(KML_PLACEMARK_HEADER)-1,1,doc->file);
203
        }
209
        }
204
       
210
 
205
        return(retvalue);
211
        return(retvalue);
206
}
212
}
207
 
213
 
208
//________________________________________________________________________________________________________________________________________
214
//________________________________________________________________________________________________________________________________________
209
// Funtion:     u8 PlaceMarkClose(KML_PlaceMark_t *place, File *file);
215
// Function:    u8 PlaceMarkClose(KML_PlaceMark_t *place, File *file);
210
// 
216
//
211
// Description: This function ends the placemark opened before.
217
// Description: This function ends the placemark opened before.
212
//                              
-
 
213
//
218
//
-
 
219
//
214
// Returnvalue: none
220
// Returnvalue: 1' if the PlaceMark could be closed
215
//________________________________________________________________________________________________________________________________________
221
//________________________________________________________________________________________________________________________________________
216
 
222
 
217
u8 KML_PlaceMarkClose(KML_Document_t *doc)
223
u8 KML_PlaceMarkClose(KML_Document_t *doc)
218
{
224
{
219
 
225
 
220
        u8 retvalue = 0;                                                                                                                        // close the Placemark-tag of the corosponding document.
226
        u8 retvalue = 0;                                                                                                                        // close the Placemark-tag of the corosponding document.
221
 
227
 
222
        if(doc->state == DOC_PLACEMARK_OPENED)
228
        if(doc->state == DOC_PLACEMARK_OPENED)
223
        {
229
        {
224
                if(doc->file != NULL)
230
                if(doc->file != NULL)
225
                {
231
                {
226
                        doc->state =DOC_OPENED;
232
                        doc->state = DOC_OPENED;
227
                        fwrite_(KML_PLACEMARK_FOOTER, sizeof(KML_PLACEMARK_FOOTER)-1,1,doc->file);                                             
233
                        fwrite_((void*)KML_PLACEMARK_FOOTER, sizeof(KML_PLACEMARK_FOOTER)-1,1,doc->file);
228
                        retvalue = 1;
234
                        retvalue = 1;
229
                }
235
                }
230
        }
236
        }
231
       
237
 
232
        return(retvalue);
238
        return(retvalue);
233
}
239
}
234
 
240
 
235
//________________________________________________________________________________________________________________________________________
241
//________________________________________________________________________________________________________________________________________
236
// Funtion:     u8 LineStringBegin(KML_Document_t *doc);
242
// Function:    u8 LineStringBegin(KML_Document_t *doc);
237
// 
243
//
238
// Description: This function ends the placemark opened before.
244
// Description: This function ends the placemark opened before.
239
//                              
-
 
240
//
245
//
-
 
246
//
241
// Returnvalue: none
247
// Returnvalue: '1' if the LineString could be started
242
//________________________________________________________________________________________________________________________________________
248
//________________________________________________________________________________________________________________________________________
243
 
249
 
244
u8 KML_LineStringBegin(KML_Document_t *doc)
250
u8 KML_LineStringBegin(KML_Document_t *doc)
245
{
251
{
246
 
252
 
247
        u8 retvalue = 0;
253
        u8 retvalue = 0;
248
       
254
 
249
        if(doc->file != NULL)
255
        if(doc->file != NULL)
250
        {
256
        {
251
                doc->state = DOC_LINESTRING_OPENED;
257
                doc->state = DOC_LINESTRING_OPENED;
252
                fwrite_(KML_LINESTRING_HEADER, sizeof(KML_LINESTRING_HEADER)-1,1,doc->file);                                           
258
                fwrite_((void*)KML_LINESTRING_HEADER, sizeof(KML_LINESTRING_HEADER)-1,1,doc->file);
253
                retvalue = 1;
259
                retvalue = 1;
254
        }
260
        }
255
 
261
 
256
        return(retvalue);
262
        return(retvalue);
257
}
263
}
258
 
264
 
259
//________________________________________________________________________________________________________________________________________
265
//________________________________________________________________________________________________________________________________________
260
// Funtion:     u8 LineStringEnd(KML_Document_t *doc)
266
// Function:    u8 LineStringEnd(KML_Document_t *doc)
261
// 
267
//
262
// Description: This function ends the placemark opened before.
268
// Description: This function ends the placemark opened before.
263
//                              
-
 
264
//
269
//
-
 
270
//
265
// Returnvalue: none
271
// Returnvalue: '1' if the LineString could be terminated
266
//________________________________________________________________________________________________________________________________________
272
//________________________________________________________________________________________________________________________________________
267
 
273
 
268
u8 KML_LineStringEnd(KML_Document_t *doc)
274
u8 KML_LineStringEnd(KML_Document_t *doc)
269
{
275
{
270
 
276
 
271
        u8 retvalue = 0;
277
        u8 retvalue = 0;
272
       
278
 
273
        if(doc->state == DOC_LINESTRING_OPENED);
279
        if(doc->state == DOC_LINESTRING_OPENED);
274
        if(doc->file != NULL)
280
        if(doc->file != NULL)
275
        {
281
        {
276
                doc->state = DOC_PLACEMARK_OPENED;
282
                doc->state = DOC_PLACEMARK_OPENED;
277
                fwrite_(KML_LINESTRING_FOOTER, sizeof(KML_LINESTRING_FOOTER)-1,1,doc->file);                                           
283
                fwrite_((void*)KML_LINESTRING_FOOTER, sizeof(KML_LINESTRING_FOOTER)-1,1,doc->file);
278
                retvalue = 1;
284
                retvalue = 1;
279
        }
285
        }
280
 
286
 
281
        return(retvalue);
287
        return(retvalue);
282
}
288
}
283
 
289
 
284
//________________________________________________________________________________________________________________________________________
290
//________________________________________________________________________________________________________________________________________
285
// Funtion:     u8 LineStringAddPoint(struct str_GPSPosition, KML_Document_t *doc)
291
// Function:    u8 LineStringAddPoint(gps_data_t, KML_Document_t *doc)
286
// 
292
//
287
// Description: This function adds a point to the specified document.
293
// Description: This function adds a point to the specified document.
288
//                              
-
 
289
//
294
//
-
 
295
//
290
// Returnvalue: none
296
// Returnvalue: '1' if a ppoint was added could be started
291
//________________________________________________________________________________________________________________________________________
297
//________________________________________________________________________________________________________________________________________
292
 
298
 
293
u8 KML_LineStringAddPoint(struct str_gps_nav_data gps_data ,KML_Document_t *doc)
299
u8 KML_LineStringAddPoint(GPS_Pos_t * pGPS_Position ,KML_Document_t *doc)
294
{
300
{
295
 
301
 
296
        u8 retvalue = 0;
302
        u8 retvalue = 0;
297
        s8 string[50];
303
        s8 string[50];
-
 
304
        s32 rel_altitude = 0;
298
       
305
 
299
        if(doc->state == DOC_LINESTRING_OPENED)
306
        if(doc == NULL || pGPS_Position == NULL) return(0);
-
 
307
 
-
 
308
        if((pGPS_Position->Status != INVALID) && (GPS_HomePosition.Status != INVALID))
300
        {
309
        {
301
                if(doc->file != NULL)
310
                if(doc->state == DOC_LINESTRING_OPENED)
302
                {
311
                {
-
 
312
                        if(doc->file != NULL)
-
 
313
                        {
-
 
314
                                s32 i1, i2;
-
 
315
                                i1 = pGPS_Position->Longitude/10000000L;
-
 
316
                                i2 = abs(pGPS_Position->Longitude%10000000L);
-
 
317
                                sprintf(string,"\r\n%ld.%07ld,",i1, i2);
-
 
318
                                fputs_(string, doc->file);
-
 
319
                                i1 = pGPS_Position->Latitude/10000000L;
-
 
320
                                i2 = abs(pGPS_Position->Latitude%10000000L);
-
 
321
                                sprintf(string," %ld.%07ld,",i1, i2);
-
 
322
                                fputs_(string, doc->file);
-
 
323
                                // calculate relative altitude with respect to the altitude of the home position
-
 
324
                                rel_altitude = pGPS_Position->Altitude - GPS_HomePosition.Altitude;
303
                        sprintf(string,"\r\n%d.%d,%d.%d,%d.0",(gps_data.Longitude/10000000),(gps_data.Longitude%10000000),(gps_data.Latitude/10000000),(gps_data.Latitude%10000000),0);
325
                                if(rel_altitude < 0) rel_altitude = 0; // avoid negative altitudes in log
-
 
326
                                i1 = rel_altitude/1000L;
-
 
327
                                i2 = abs(rel_altitude%1000L);
-
 
328
                                sprintf(string," %ld.%03ld",i1, i2);
304
                        fputs_(doc->file,string);
329
                                fputs_(string, doc->file);
305
                        retvalue = 1;
330
                                retvalue = 1;
-
 
331
                        }
306
                }
332
                }
307
        }
333
        }
308
 
334
 
309
        return(retvalue);
335
        return(retvalue);
310
}
336
}
311
 
337
 
312
//________________________________________________________________________________________________________________________________________
338
//________________________________________________________________________________________________________________________________________
313
// Funtion:     u8 KML_LoggGPSCoordinates(struct str_gps_nav_data, KML_Document_t *) 
339
// Function:    u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *)
314
// 
340
//
315
// Description: This function opens adds gpscoordinates to an KML-Document. The document will be opened, if not already done
341
// Description: This function opens adds gpscoordinates to an KML-Document. The document will be opened, if not already done
316
//                              
-
 
317
//
342
//
-
 
343
//
318
// Returnvalue: none
344
// Returnvalue: '1' if an gps coordinate was logged
319
//________________________________________________________________________________________________________________________________________
345
//________________________________________________________________________________________________________________________________________
320
 
346
 
321
u8      KML_LoggGPSCoordinates(struct str_gps_nav_data gps_data, KML_Document_t *doc)
347
u8 KML_LoggGPSCoordinates(GPS_Pos_t* pGPS_Position, KML_Document_t *doc)
-
 
348
{
322
{
349
        u8 retval = 0;
323
        while(doc->state != DOC_LINESTRING_OPENED)                                      // automatic create document with default filename on the card.
350
        while(doc->state != DOC_LINESTRING_OPENED)                                      // automatic create document with default filename on the card.
324
        {                      
351
        {
325
                switch(doc->state)
352
                switch(doc->state)
326
                {
353
                {
327
                        case DOC_CLOSED:                                                                        // document hasn't been opened yet therefore it will be initialized automatically
354
                        case DOC_CLOSED:                                                                        // document hasn't been opened yet therefore it will be initialized automatically
328
                                KML_DocumentInit(doc);                                                  // initialize the document to default values
355
                                KML_DocumentInit(doc);                                                  // initialize the document to default values
329
                                if(KML_DocumentOpen("default.kml",doc))         // open the kml-document with a standardname.                   
356
                                retval = KML_DocumentOpen("default.kml",doc);   // open the kml-document with a standardname.
-
 
357
                                if(retval)
330
                                {
358
                                {
331
                                        doc->state = DOC_OPENED;
359
                                        doc->state = DOC_OPENED;
332
                                }                                              
360
                                }
333
                        break;
361
                        break;
334
 
362
 
335
                        case DOC_OPENED:                                                                        // if a document has been opened before but no placemark exists:
363
                        case DOC_OPENED:                                                                        // if a document has been opened before but no placemark exists:
336
                                if(KML_PlaceMarkOpen("MIKROKOPTER",doc))
364
                                retval = KML_PlaceMarkOpen("MIKROKOPTER",doc);
-
 
365
                                if(retval)
337
                                {
366
                                {
338
                                        doc->state = DOC_PLACEMARK_OPENED;      // add a placemark to the document.
367
                                        doc->state = DOC_PLACEMARK_OPENED;                      // add a placemark to the document.
339
                                }
368
                                }
340
                        break;
369
                        break;
341
 
370
 
342
                        case DOC_PLACEMARK_OPENED:                                                      // add linestring to the placemark
371
                        case DOC_PLACEMARK_OPENED:                                                      // add linestring to the placemark
343
                                if(KML_LineStringBegin(doc))
372
                                retval = KML_LineStringBegin(doc);
-
 
373
                                if(retval)
344
                                {
374
                                {
345
                                        doc->state = DOC_LINESTRING_OPENED;
375
                                        doc->state = DOC_LINESTRING_OPENED;
346
                                }
376
                                }
347
                        break;
377
                        break;
-
 
378
 
-
 
379
                        default:
-
 
380
                                retval = 1;
-
 
381
                        break;
348
 
382
 
-
 
383
                }
349
                }
384
                if(retval != 1) return(retval); // stop on error
350
        };
385
        }
351
 
386
 
352
        if(doc->state == DOC_LINESTRING_OPENED)                                         // if the document was opened add coordinates to the document.
387
        if(doc->state == DOC_LINESTRING_OPENED)                                         // if the document was opened add coordinates to the document.
353
        {
388
        {
354
                KML_LineStringAddPoint(gps_data , doc);                        
389
                retval = KML_LineStringAddPoint(pGPS_Position, doc);
355
        }
390
        }
-
 
391
        return(retval);
356
}
392
}
357
 
393
 
358
 
394