Subversion Repositories Projects

Rev

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

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