Subversion Repositories NaviCtrl

Rev

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

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