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