Rev 434 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 434 | Rev 436 | ||
---|---|---|---|
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; |
121 | uint16_t i; |
122 | int8_t c; |
122 | int8_t c; |
123 | const prog_char *str; |
123 | const prog_char *str; |
124 | 124 | ||
125 | if(doc == NULL) return(0); |
125 | if(doc == NULL) return(0); |
126 | 126 | ||
127 | KML_DocumentInit(doc); // intialize the document with resetvalues |
127 | KML_DocumentInit(doc); // intialize the document with resetvalues |
128 | doc->file = fopen_(name,'a'); // open a new file with the specified filename on the memorycard. |
128 | doc->file = fopen_(name,'a'); // open a new file with the specified filename on the memorycard. |
129 | 129 | ||
130 | if(doc->file != NULL) // could the file be opened? |
130 | if(doc->file != NULL) // could the file be opened? |
131 | { |
131 | { |
132 | retvalue = 1; // the document could be created on the drive. |
132 | retvalue = 1; // the document could be created on the drive. |
133 | 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. |
134 | str = KML_DOCUMENT_HEADER; // 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++) |
135 | for(i= 0; i < sizeof(KML_DOCUMENT_HEADER)-1; i++) |
136 | { |
136 | { |
137 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
137 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
138 | fputc_(c, doc->file); // and write that to sd-card |
138 | fputc_(c, doc->file); // and write that to sd-card |
139 | } |
139 | } |
140 | } |
140 | } |
141 | return(retvalue); |
141 | return(retvalue); |
142 | } |
142 | } |
143 | 143 | ||
144 | //________________________________________________________________________________________________________________________________________ |
144 | //________________________________________________________________________________________________________________________________________ |
145 | // Function: DocumentClose(KML_Document_t *doc); |
145 | // Function: DocumentClose(KML_Document_t *doc); |
146 | // |
146 | // |
147 | // Description: This function closes the document specified by doc. |
147 | // Description: This function closes the document specified by doc. |
148 | // |
148 | // |
149 | // |
149 | // |
150 | // Returnvalue: '1' if the KML- file could be closed. |
150 | // Returnvalue: '1' if the KML- file could be closed. |
151 | //________________________________________________________________________________________________________________________________________ |
151 | //________________________________________________________________________________________________________________________________________ |
152 | 152 | ||
153 | uint8_t KML_DocumentClose(KML_Document_t *doc) |
153 | uint8_t KML_DocumentClose(KML_Document_t *doc) |
154 | { |
154 | { |
155 | 155 | ||
156 | uint8_t retvalue = 1; |
156 | uint8_t retvalue = 1; |
157 | uint16_t i; |
157 | uint16_t i; |
158 | int8_t c; |
158 | int8_t c; |
159 | const prog_char *str; |
159 | const prog_char *str; |
160 | 160 | ||
161 | if(doc == NULL) return(0); |
161 | if(doc == NULL) return(0); |
162 | 162 | ||
163 | 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 |
164 | { |
164 | { |
165 | switch(doc->state) |
165 | switch(doc->state) |
166 | { |
166 | { |
167 | case KML_DOC_LINESTRING_OPENED: |
167 | case KML_DOC_LINESTRING_OPENED: |
168 | KML_LineStringEnd(doc); // write terminating tag to end linestring. |
168 | KML_LineStringEnd(doc); // write terminating tag to end linestring. |
169 | break; |
169 | break; |
170 | 170 | ||
171 | case KML_DOC_PLACEMARK_OPENED: // write terminating tag to close placemark. |
171 | case KML_DOC_PLACEMARK_OPENED: // write terminating tag to close placemark. |
172 | KML_PlaceMarkClose(doc); |
172 | KML_PlaceMarkClose(doc); |
173 | break; |
173 | break; |
174 | 174 | ||
175 | case KML_DOC_OPENED: // close the file on the memorycard |
175 | case KML_DOC_OPENED: // close the file on the memorycard |
176 | if(doc->file != NULL) |
176 | if(doc->file != NULL) |
177 | { |
177 | { |
178 | str = KML_DOCUMENT_FOOTER; // 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++) |
179 | for(i= 0; i < sizeof(KML_DOCUMENT_FOOTER)-1; i++) |
180 | { |
180 | { |
181 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
181 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
182 | fputc_(c, doc->file); // and write that to sd-card |
182 | fputc_(c, doc->file); // and write that to sd-card |
183 | } |
183 | } |
184 | fclose_(doc->file); |
184 | fclose_(doc->file); |
185 | retvalue = 1; |
185 | retvalue = 1; |
186 | } |
186 | } |
187 | doc->state = KML_DOC_CLOSED; |
187 | doc->state = KML_DOC_CLOSED; |
188 | break; |
188 | break; |
189 | 189 | ||
190 | default: |
190 | default: |
191 | doc->state = KML_DOC_CLOSED; |
191 | doc->state = KML_DOC_CLOSED; |
192 | break; |
192 | break; |
193 | 193 | ||
194 | } |
194 | } |
195 | } |
195 | } |
196 | return(retvalue); |
196 | return(retvalue); |
197 | } |
197 | } |
198 | 198 | ||
199 | //________________________________________________________________________________________________________________________________________ |
199 | //________________________________________________________________________________________________________________________________________ |
200 | // Function: u8 KML_PlaceMarkOpen(KML_Document_t *doc); |
200 | // Function: u8 KML_PlaceMarkOpen(KML_Document_t *doc); |
201 | // |
201 | // |
202 | // Description: This function adds a placemark to the document. |
202 | // Description: This function adds a placemark to the document. |
203 | // |
203 | // |
204 | // |
204 | // |
205 | // Returnvalue: '1' if the PlaceMark could be opened |
205 | // Returnvalue: '1' if the PlaceMark could be opened |
206 | //________________________________________________________________________________________________________________________________________ |
206 | //________________________________________________________________________________________________________________________________________ |
207 | 207 | ||
208 | uint8_t KML_PlaceMarkOpen(KML_Document_t *doc) |
208 | uint8_t KML_PlaceMarkOpen(KML_Document_t *doc) |
209 | { |
209 | { |
210 | uint8_t retvalue = 0; |
210 | uint8_t retvalue = 0; |
211 | uint16_t i; |
211 | uint16_t i; |
212 | int8_t c; |
212 | int8_t c; |
213 | const prog_char *str; |
213 | const prog_char *str; |
214 | 214 | ||
215 | if(doc->state == KML_DOC_OPENED) |
215 | if(doc->state == KML_DOC_OPENED) |
216 | { |
216 | { |
217 | if(doc->file != NULL) |
217 | if(doc->file != NULL) |
218 | { |
218 | { |
219 | doc->state = KML_DOC_PLACEMARK_OPENED; |
219 | doc->state = KML_DOC_PLACEMARK_OPENED; |
220 | retvalue = 1; |
220 | retvalue = 1; |
221 | str = KML_PLACEMARK_HEADER; |
221 | str = KML_PLACEMARK_HEADER; |
222 | for(i= 0; i < sizeof(KML_PLACEMARK_HEADER); i++) |
222 | for(i= 0; i < sizeof(KML_PLACEMARK_HEADER)-1; i++) |
223 | { |
223 | { |
224 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
224 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
225 | fputc_(c, doc->file); // and write that to sd-card |
225 | fputc_(c, doc->file); // and write that to sd-card |
226 | } |
226 | } |
227 | } |
227 | } |
228 | } |
228 | } |
229 | return(retvalue); |
229 | return(retvalue); |
230 | } |
230 | } |
231 | 231 | ||
232 | //________________________________________________________________________________________________________________________________________ |
232 | //________________________________________________________________________________________________________________________________________ |
233 | // Function: u8 PlaceMarkClose(KML_PlaceMark_t *place, File *file); |
233 | // Function: u8 PlaceMarkClose(KML_PlaceMark_t *place, File *file); |
234 | // |
234 | // |
235 | // Description: This function ends the placemark opened before. |
235 | // Description: This function ends the placemark opened before. |
236 | // |
236 | // |
237 | // |
237 | // |
238 | // Returnvalue: 1' if the PlaceMark could be closed |
238 | // Returnvalue: 1' if the PlaceMark could be closed |
239 | //________________________________________________________________________________________________________________________________________ |
239 | //________________________________________________________________________________________________________________________________________ |
240 | 240 | ||
241 | uint8_t KML_PlaceMarkClose(KML_Document_t *doc) |
241 | uint8_t KML_PlaceMarkClose(KML_Document_t *doc) |
242 | { |
242 | { |
243 | 243 | ||
244 | uint8_t retvalue = 0; |
244 | uint8_t retvalue = 0; |
245 | uint16_t i; |
245 | uint16_t i; |
246 | int8_t c; |
246 | int8_t c; |
247 | const prog_char *str; |
247 | const prog_char *str; |
248 | 248 | ||
249 | if(doc->state == KML_DOC_PLACEMARK_OPENED) |
249 | if(doc->state == KML_DOC_PLACEMARK_OPENED) |
250 | { |
250 | { |
251 | if(doc->file != NULL) |
251 | if(doc->file != NULL) |
252 | { |
252 | { |
253 | doc->state = KML_DOC_OPENED; |
253 | doc->state = KML_DOC_OPENED; |
254 | str = KML_PLACEMARK_FOOTER; |
254 | str = KML_PLACEMARK_FOOTER; |
255 | for(i= 0; i < sizeof(KML_PLACEMARK_FOOTER); i++) |
255 | for(i= 0; i < sizeof(KML_PLACEMARK_FOOTER)-1; i++) |
256 | { |
256 | { |
257 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
257 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
258 | fputc_(c, doc->file); // and write that to sd-card |
258 | fputc_(c, doc->file); // and write that to sd-card |
259 | } |
259 | } |
260 | retvalue = 1; |
260 | retvalue = 1; |
261 | } |
261 | } |
262 | } |
262 | } |
263 | return(retvalue); |
263 | return(retvalue); |
264 | } |
264 | } |
265 | 265 | ||
266 | //________________________________________________________________________________________________________________________________________ |
266 | //________________________________________________________________________________________________________________________________________ |
267 | // Function: u8 LineStringBegin(KML_Document_t *doc); |
267 | // Function: u8 LineStringBegin(KML_Document_t *doc); |
268 | // |
268 | // |
269 | // Description: This function ends the placemark opened before. |
269 | // Description: This function ends the placemark opened before. |
270 | // |
270 | // |
271 | // |
271 | // |
272 | // Returnvalue: '1' if the LineString could be started |
272 | // Returnvalue: '1' if the LineString could be started |
273 | //________________________________________________________________________________________________________________________________________ |
273 | //________________________________________________________________________________________________________________________________________ |
274 | 274 | ||
275 | uint8_t KML_LineStringBegin(KML_Document_t *doc) |
275 | uint8_t KML_LineStringBegin(KML_Document_t *doc) |
276 | { |
276 | { |
277 | 277 | ||
278 | uint8_t retvalue = 0; |
278 | uint8_t retvalue = 0; |
279 | uint16_t i; |
279 | uint16_t i; |
280 | int8_t c; |
280 | int8_t c; |
281 | const prog_char *str; |
281 | const prog_char *str; |
282 | 282 | ||
283 | if(doc->state == KML_DOC_PLACEMARK_OPENED) |
283 | if(doc->state == KML_DOC_PLACEMARK_OPENED) |
284 | { |
284 | { |
285 | if(doc->file != NULL) |
285 | if(doc->file != NULL) |
286 | { |
286 | { |
287 | doc->state = KML_DOC_LINESTRING_OPENED; |
287 | doc->state = KML_DOC_LINESTRING_OPENED; |
288 | str = KML_LINESTRING_HEADER; |
288 | str = KML_LINESTRING_HEADER; |
289 | for(i= 0; i < sizeof(KML_LINESTRING_HEADER); i++) |
289 | for(i= 0; i < sizeof(KML_LINESTRING_HEADER)-1; i++) |
290 | { |
290 | { |
291 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
291 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
292 | fputc_(c, doc->file); // and write that to sd-card |
292 | fputc_(c, doc->file); // and write that to sd-card |
293 | } |
293 | } |
294 | retvalue = 1; |
294 | retvalue = 1; |
295 | } |
295 | } |
296 | } |
296 | } |
297 | return(retvalue); |
297 | return(retvalue); |
298 | } |
298 | } |
299 | 299 | ||
300 | //________________________________________________________________________________________________________________________________________ |
300 | //________________________________________________________________________________________________________________________________________ |
301 | // Function: u8 KML_LineStringEnd(KML_Document_t *doc) |
301 | // Function: u8 KML_LineStringEnd(KML_Document_t *doc) |
302 | // |
302 | // |
303 | // Description: This function ends the placemark opened before. |
303 | // Description: This function ends the placemark opened before. |
304 | // |
304 | // |
305 | // |
305 | // |
306 | // Returnvalue: '1' if the LineString could be terminated |
306 | // Returnvalue: '1' if the LineString could be terminated |
307 | //________________________________________________________________________________________________________________________________________ |
307 | //________________________________________________________________________________________________________________________________________ |
308 | 308 | ||
309 | uint8_t KML_LineStringEnd(KML_Document_t *doc) |
309 | uint8_t KML_LineStringEnd(KML_Document_t *doc) |
310 | { |
310 | { |
311 | 311 | ||
312 | uint8_t retvalue = 0; |
312 | uint8_t retvalue = 0; |
313 | uint16_t i; |
313 | uint16_t i; |
314 | int8_t c; |
314 | int8_t c; |
315 | const prog_char *str; |
315 | const prog_char *str; |
316 | 316 | ||
317 | if(doc->state == KML_DOC_LINESTRING_OPENED) |
317 | if(doc->state == KML_DOC_LINESTRING_OPENED) |
318 | { |
318 | { |
319 | if(doc->file != NULL) |
319 | if(doc->file != NULL) |
320 | { |
320 | { |
321 | doc->state = KML_DOC_PLACEMARK_OPENED; |
321 | doc->state = KML_DOC_PLACEMARK_OPENED; |
322 | str = KML_LINESTRING_FOOTER; |
322 | str = KML_LINESTRING_FOOTER; |
323 | for(i= 0; i < sizeof(KML_LINESTRING_FOOTER); i++) |
323 | for(i= 0; i < sizeof(KML_LINESTRING_FOOTER)-1; i++) |
324 | { |
324 | { |
325 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
325 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
326 | fputc_(c, doc->file); // and write that to sd-card |
326 | fputc_(c, doc->file); // and write that to sd-card |
327 | } |
327 | } |
328 | retvalue = 1; |
328 | retvalue = 1; |
329 | } |
329 | } |
330 | } |
330 | } |
331 | return(retvalue); |
331 | return(retvalue); |
332 | } |
332 | } |
333 | 333 | ||
334 | //________________________________________________________________________________________________________________________________________ |
334 | //________________________________________________________________________________________________________________________________________ |
335 | // Function: u8 LineStringAddPoint(gps_data_t, KML_Document_t *doc) |
335 | // Function: u8 LineStringAddPoint(gps_data_t, KML_Document_t *doc) |
336 | // |
336 | // |
337 | // Description: This function adds a point to the specified document. |
337 | // Description: This function adds a point to the specified document. |
338 | // |
338 | // |
339 | // |
339 | // |
340 | // Returnvalue: '1' if a ppoint was added could be started |
340 | // Returnvalue: '1' if a ppoint was added could be started |
341 | //________________________________________________________________________________________________________________________________________ |
341 | //________________________________________________________________________________________________________________________________________ |
342 | 342 | ||
343 | uint8_t KML_LineStringAddPoint(KML_Document_t *doc) |
343 | uint8_t KML_LineStringAddPoint(KML_Document_t *doc) |
344 | { |
344 | { |
345 | 345 | ||
346 | uint8_t retvalue = 0; |
346 | uint8_t retvalue = 0; |
347 | int8_t string[50]; |
347 | int8_t string[50]; |
348 | 348 | ||
349 | if(doc == NULL) return(0); |
349 | if(doc == NULL) return(0); |
350 | 350 | ||
351 | if(GPSData.Position.Status != INVALID) |
351 | if(GPSData.Position.Status != INVALID) |
352 | { |
352 | { |
353 | if(doc->state == KML_DOC_LINESTRING_OPENED) |
353 | if(doc->state == KML_DOC_LINESTRING_OPENED) |
354 | { |
354 | { |
355 | if(doc->file != NULL) |
355 | if(doc->file != NULL) |
356 | { |
356 | { |
357 | int16_t i1, i2, i3; |
357 | int16_t i1, i2, i3; |
358 | uint8_t sign; |
358 | uint8_t sign; |
359 | if(GPSData.Position.Longitude < 0) sign = '-'; |
359 | if(GPSData.Position.Longitude < 0) sign = '-'; |
360 | else sign = '+'; |
360 | else sign = '+'; |
361 | i1 = abs((int16_t)(GPSData.Position.Longitude/10000000L)); |
361 | i1 = abs((int16_t)(GPSData.Position.Longitude/10000000L)); |
362 | i2 = abs((int16_t)((GPSData.Position.Longitude%10000000L)/10000L)); |
362 | i2 = abs((int16_t)((GPSData.Position.Longitude%10000000L)/10000L)); |
363 | i3 = abs((int16_t)(((GPSData.Position.Longitude%10000000L)%10000L)/10L)); |
363 | i3 = abs((int16_t)(((GPSData.Position.Longitude%10000000L)%10000L)/10L)); |
364 | 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); |
365 | fputs_(string, doc->file); |
365 | fputs_(string, doc->file); |
366 | if(GPSData.Position.Latitude < 0) sign = '-'; |
366 | if(GPSData.Position.Latitude < 0) sign = '-'; |
367 | else sign = '+'; |
367 | else sign = '+'; |
368 | i1 = abs((int16_t)(GPSData.Position.Latitude/10000000L)); |
368 | i1 = abs((int16_t)(GPSData.Position.Latitude/10000000L)); |
369 | i2 = abs((int16_t)((GPSData.Position.Latitude%10000000L)/10000L)); |
369 | i2 = abs((int16_t)((GPSData.Position.Latitude%10000000L)/10000L)); |
370 | i3 = abs((int16_t)(((GPSData.Position.Latitude%10000000L)%10000L)/10L)); |
370 | i3 = abs((int16_t)(((GPSData.Position.Latitude%10000000L)%10000L)/10L)); |
371 | sprintf(string,"%c%d.%.3d%.3d,",sign, i1, i2, i3); |
371 | sprintf(string,"%c%d.%.3d%.3d,",sign, i1, i2, i3); |
372 | fputs_(string, doc->file); |
372 | fputs_(string, doc->file); |
373 | sign = '+'; |
373 | sign = '+'; |
374 | sprintf(string,"%c%d.%.3d",sign, 0, 0); |
374 | sprintf(string,"%c%d.%.3d",sign, 0, 0); |
375 | fputs_(string, doc->file); |
375 | fputs_(string, doc->file); |
376 | retvalue = 1; |
376 | retvalue = 1; |
377 | } |
377 | } |
378 | } |
378 | } |
379 | } |
379 | } |
380 | return(retvalue); |
380 | return(retvalue); |
381 | } |
381 | } |
382 | 382 | ||
383 | //________________________________________________________________________________________________________________________________________ |
383 | //________________________________________________________________________________________________________________________________________ |
384 | // Function: u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *) |
384 | // Function: u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *) |
385 | // |
385 | // |
386 | // 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 |
387 | // |
387 | // |
388 | // |
388 | // |
389 | // Returnvalue: '1' if an gps coordinate was logged |
389 | // Returnvalue: '1' if an gps coordinate was logged |
390 | //________________________________________________________________________________________________________________________________________ |
390 | //________________________________________________________________________________________________________________________________________ |
391 | 391 | ||
392 | uint8_t KML_LoggGPSCoordinates(KML_Document_t *doc) |
392 | uint8_t KML_LoggGPSCoordinates(KML_Document_t *doc) |
393 | { |
393 | { |
394 | uint8_t retval = 0; |
394 | uint8_t retval = 0; |
395 | 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. |
396 | { |
396 | { |
397 | switch(doc->state) |
397 | switch(doc->state) |
398 | { |
398 | { |
399 | 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 |
400 | 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. |
401 | break; |
401 | break; |
402 | 402 | ||
403 | 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: |
404 | retval = KML_PlaceMarkOpen(doc); |
404 | retval = KML_PlaceMarkOpen(doc); |
405 | break; |
405 | break; |
406 | 406 | ||
407 | case KML_DOC_PLACEMARK_OPENED: // add linestring to the placemark |
407 | case KML_DOC_PLACEMARK_OPENED: // add linestring to the placemark |
408 | retval = KML_LineStringBegin(doc); |
408 | retval = KML_LineStringBegin(doc); |
409 | break; |
409 | break; |
410 | 410 | ||
411 | default: |
411 | default: |
412 | retval = 0; |
412 | retval = 0; |
413 | break; |
413 | break; |
414 | 414 | ||
415 | } |
415 | } |
416 | if(retval != 1) return(retval); // stop on error |
416 | if(retval != 1) return(retval); // stop on error |
417 | } |
417 | } |
418 | 418 | ||
419 | 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. |
420 | { |
420 | { |
421 | retval = KML_LineStringAddPoint(doc); |
421 | retval = KML_LineStringAddPoint(doc); |
422 | } |
422 | } |
423 | return(retval); |
423 | return(retval); |
424 | } |
424 | } |
425 | 425 | ||
426 | 426 |