Rev 24 | Rev 41 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
24 | StephanB | 1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
||
3 | /*#######################################################################################*/ |
||
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
||
6 | // + Nur für den privaten Gebrauch |
||
7 | // + FOR NON COMMERCIAL USE ONLY |
||
8 | // + www.MikroKopter.com |
||
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
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. |
||
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
||
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
||
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
||
15 | // + Verkauf von Luftbildaufnahmen, usw. |
||
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
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 |
||
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
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" |
||
22 | // + eindeutig als Ursprung verlinkt werden |
||
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
||
25 | // + Benutzung auf eigene Gefahr |
||
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
||
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
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 |
||
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
||
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
||
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 |
||
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 |
||
38 | // + for non-commercial use (directly or indirectly) |
||
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
||
40 | // + with our written permission |
||
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
||
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 |
||
44 | // |
||
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 |
||
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
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 |
||
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 |
||
55 | // + POSSIBILITY OF SUCH DAMAGE. |
||
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
57 | |||
58 | #include <stdio.h> |
||
59 | #include "main.h" |
||
60 | #include "kml.h" |
||
61 | #include "kml_header.h" |
||
62 | #include "fat16.h" |
||
63 | |||
64 | |||
65 | //________________________________________________________________________________________________________________________________________ |
||
66 | // Module name: kml.c |
||
67 | // Compiler used: avr-gcc 3.4.5 |
||
68 | // Last Modifikation: 17.03.2008 |
||
69 | // Version: 1.02 |
||
70 | // Authors: Stephan Busker |
||
71 | // Description: Source files to write gps-coordinates to a file in the kml (keyhole markup language) fileformat |
||
72 | // Copyright (C) 2007 Stephan Busker |
||
73 | //........................................................................................................................................ |
||
74 | // Functions: extern u8 KML_LoggGPSCoordinates(struct str_gps_nav_data , KML_Document_t *); // intializes the kml-document with standard filename and adds points to the file |
||
75 | // extern u8 KML_DocumentInit(KML_Document_t *doc) // initializes the kml-document to resetvalues. |
||
76 | // extern u8 KML_DocumentOpen(s8 *, KML_Document_t *); // opens a new kml document. A filename can be specified. |
||
77 | // extern u8 KML_DocumentClose(KML_Document_t *doc); // closes an open document |
||
78 | // extern u8 KML_PlaceMarkOpen(s8 *name, KML_Document_t *); // opens a new placemark within the specified document |
||
79 | // extern u8 KML_PlaceMarkClose( KML_Document_t *); // Closes the placemark |
||
80 | // extern u8 KML_LineStringBegin(KML_Document_t *); // begins a new line within the actual placemark |
||
81 | // extern u8 KML_LineStringEnd(KML_Document_t *doc); // ends the actual linestring |
||
82 | // extern u8 KML_LineStringAddPoint(struct str_gps_nav_data, KML_Document_t *); // adds a new point (gps-coordinates) to the actual linestring |
||
83 | //........................................................................................................................................ |
||
84 | // ext. functions: |
||
85 | // |
||
86 | //........................................................................................................................................ |
||
87 | // |
||
88 | // URL: www.Mikro-Control.de |
||
89 | // mailto: stephan.busker@mikro-control.de |
||
90 | //________________________________________________________________________________________________________________________________________ |
||
91 | |||
92 | |||
93 | |||
94 | //________________________________________________________________________________________________________________________________________ |
||
95 | // Funtion: KML_DocumentInit(KML_Document_t *) |
||
96 | // |
||
97 | // Description: This function initializes the kml-document for further use. |
||
98 | // |
||
99 | // |
||
100 | // Returnvalue: '1' if document was initialized |
||
101 | //________________________________________________________________________________________________________________________________________ |
||
102 | |||
103 | u8 KML_DocumentInit(KML_Document_t *doc) |
||
104 | { |
||
105 | doc->name[0] = 0; // name of the document |
||
106 | doc->state = DOC_CLOSED; // state of the kml-document |
||
107 | doc->file = NULL; |
||
108 | doc->place.name[0]=0; |
||
109 | doc->place.description[0]=0; |
||
110 | return(1); |
||
111 | } |
||
112 | |||
113 | //________________________________________________________________________________________________________________________________________ |
||
114 | // Funtion: KML_Document_Open(void); |
||
115 | // |
||
116 | // Description: This function opens a new KML- document with the specified name and creates the document header within the file. |
||
117 | // |
||
118 | // |
||
119 | // Returnvalue: '1' if the KML- file could be created. |
||
120 | //________________________________________________________________________________________________________________________________________ |
||
121 | |||
122 | u8 KML_DocumentOpen(s8 *name, KML_Document_t *doc) |
||
123 | { |
||
124 | |||
125 | u8 retvalue = 0; |
||
126 | |||
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. |
||
129 | |||
130 | if(doc->file != NULL) // could the file be opened? |
||
131 | { |
||
132 | retvalue = 1; // the document could be created on the drive. |
||
133 | doc->state = DOC_OPENED; // change document state to opened. At next a placemark has to be opened. |
||
134 | fwrite_(KML_DOCUMENT_HEADER, sizeof(KML_DOCUMENT_HEADER)-1,1,doc->file); // write the KML- footer to the document. |
||
135 | } |
||
136 | |||
137 | return(retvalue); |
||
138 | } |
||
139 | |||
140 | //________________________________________________________________________________________________________________________________________ |
||
141 | // Funtion: DocumentClose(KML_Document_t *doc); |
||
142 | // |
||
143 | // Description: This function closes the document specified by doc. |
||
144 | // |
||
145 | // |
||
146 | // Returnvalue: none |
||
147 | //________________________________________________________________________________________________________________________________________ |
||
148 | |||
149 | u8 KML_DocumentClose(KML_Document_t *doc) |
||
150 | { |
||
151 | |||
152 | u8 retvalue = 0; |
||
153 | |||
154 | while(doc->state != DOC_CLOSED) // close linestring, placemark and document before closing the file on the memorycard |
||
155 | { |
||
156 | switch(doc->state) |
||
157 | { |
||
158 | case DOC_LINESTRING_OPENED: |
||
159 | KML_LineStringEnd(doc); // write terminating tag to end linestring. |
||
160 | doc->state = DOC_PLACEMARK_OPENED; |
||
161 | break; |
||
162 | |||
163 | case DOC_PLACEMARK_OPENED: // write terminating tag to close placemark. |
||
164 | KML_PlaceMarkClose(doc); |
||
165 | doc->state = DOC_OPENED; |
||
166 | break; |
||
167 | |||
168 | case DOC_OPENED: // close the file on the memorycard |
||
169 | if(doc->file != NULL) |
||
170 | { |
||
171 | fwrite_(KML_DOCUMENT_FOOTER, sizeof(KML_DOCUMENT_FOOTER)-1,1,doc->file); // write the KML- footer to the document. |
||
172 | fclose_(doc->file); |
||
173 | retvalue = 1; |
||
174 | } |
||
175 | doc->state = DOC_CLOSED; |
||
176 | break; |
||
177 | |||
178 | } |
||
179 | }; |
||
180 | |||
181 | return(retvalue); |
||
182 | } |
||
183 | |||
184 | //________________________________________________________________________________________________________________________________________ |
||
185 | // Funtion: u8 PlaceMarkOpen(s8 *name, File *file); |
||
186 | // |
||
187 | // Description: This function adds a placemark to the document. |
||
188 | // |
||
189 | // |
||
190 | // Returnvalue: none |
||
191 | //________________________________________________________________________________________________________________________________________ |
||
192 | |||
193 | u8 KML_PlaceMarkOpen(s8 *name, KML_Document_t *doc) |
||
194 | { |
||
195 | |||
196 | u8 retvalue = 0; |
||
197 | |||
198 | if(doc->file != NULL) |
||
199 | { |
||
200 | doc->state = DOC_PLACEMARK_OPENED; |
||
201 | retvalue = 1; |
||
202 | fwrite_(KML_PLACEMARK_HEADER, sizeof(KML_PLACEMARK_HEADER)-1,1,doc->file); |
||
203 | } |
||
204 | |||
205 | return(retvalue); |
||
206 | } |
||
207 | |||
208 | //________________________________________________________________________________________________________________________________________ |
||
209 | // Funtion: u8 PlaceMarkClose(KML_PlaceMark_t *place, File *file); |
||
210 | // |
||
211 | // Description: This function ends the placemark opened before. |
||
212 | // |
||
213 | // |
||
214 | // Returnvalue: none |
||
215 | //________________________________________________________________________________________________________________________________________ |
||
216 | |||
217 | u8 KML_PlaceMarkClose(KML_Document_t *doc) |
||
218 | { |
||
219 | |||
220 | u8 retvalue = 0; // close the Placemark-tag of the corosponding document. |
||
221 | |||
222 | if(doc->state == DOC_PLACEMARK_OPENED) |
||
223 | { |
||
224 | if(doc->file != NULL) |
||
225 | { |
||
226 | doc->state =DOC_OPENED; |
||
227 | fwrite_(KML_PLACEMARK_FOOTER, sizeof(KML_PLACEMARK_FOOTER)-1,1,doc->file); |
||
228 | retvalue = 1; |
||
229 | } |
||
230 | } |
||
231 | |||
232 | return(retvalue); |
||
233 | } |
||
234 | |||
235 | //________________________________________________________________________________________________________________________________________ |
||
236 | // Funtion: u8 LineStringBegin(KML_Document_t *doc); |
||
237 | // |
||
238 | // Description: This function ends the placemark opened before. |
||
239 | // |
||
240 | // |
||
241 | // Returnvalue: none |
||
242 | //________________________________________________________________________________________________________________________________________ |
||
243 | |||
244 | u8 KML_LineStringBegin(KML_Document_t *doc) |
||
245 | { |
||
246 | |||
247 | u8 retvalue = 0; |
||
248 | |||
249 | if(doc->file != NULL) |
||
250 | { |
||
251 | doc->state = DOC_LINESTRING_OPENED; |
||
252 | fwrite_(KML_LINESTRING_HEADER, sizeof(KML_LINESTRING_HEADER)-1,1,doc->file); |
||
253 | retvalue = 1; |
||
254 | } |
||
255 | |||
256 | return(retvalue); |
||
257 | } |
||
258 | |||
259 | //________________________________________________________________________________________________________________________________________ |
||
260 | // Funtion: u8 LineStringEnd(KML_Document_t *doc) |
||
261 | // |
||
262 | // Description: This function ends the placemark opened before. |
||
263 | // |
||
264 | // |
||
265 | // Returnvalue: none |
||
266 | //________________________________________________________________________________________________________________________________________ |
||
267 | |||
268 | u8 KML_LineStringEnd(KML_Document_t *doc) |
||
269 | { |
||
270 | |||
271 | u8 retvalue = 0; |
||
272 | |||
273 | if(doc->state == DOC_LINESTRING_OPENED); |
||
274 | if(doc->file != NULL) |
||
275 | { |
||
276 | doc->state = DOC_PLACEMARK_OPENED; |
||
277 | fwrite_(KML_LINESTRING_FOOTER, sizeof(KML_LINESTRING_FOOTER)-1,1,doc->file); |
||
278 | retvalue = 1; |
||
279 | } |
||
280 | |||
281 | return(retvalue); |
||
282 | } |
||
283 | |||
284 | //________________________________________________________________________________________________________________________________________ |
||
285 | // Funtion: u8 LineStringAddPoint(struct str_GPSPosition, KML_Document_t *doc) |
||
286 | // |
||
287 | // Description: This function adds a point to the specified document. |
||
288 | // |
||
289 | // |
||
290 | // Returnvalue: none |
||
291 | //________________________________________________________________________________________________________________________________________ |
||
292 | |||
293 | u8 KML_LineStringAddPoint(struct str_gps_nav_data gps_data ,KML_Document_t *doc) |
||
294 | { |
||
295 | |||
296 | u8 retvalue = 0; |
||
297 | s8 string[50]; |
||
298 | |||
299 | if(doc->state == DOC_LINESTRING_OPENED) |
||
300 | { |
||
301 | if(doc->file != NULL) |
||
302 | { |
||
303 | sprintf(string,"\r\n%d.%d,%d.%d,%d.0",(gps_data.Longitude/10000000),(gps_data.Longitude%10000000),(gps_data.Latitude/10000000),(gps_data.Latitude%10000000),0); |
||
304 | fputs_(doc->file,string); |
||
305 | retvalue = 1; |
||
306 | } |
||
307 | } |
||
308 | |||
309 | return(retvalue); |
||
310 | } |
||
311 | |||
312 | //________________________________________________________________________________________________________________________________________ |
||
313 | // Funtion: u8 KML_LoggGPSCoordinates(struct str_gps_nav_data, KML_Document_t *) |
||
314 | // |
||
315 | // Description: This function opens adds gpscoordinates to an KML-Document. The document will be opened, if not already done |
||
316 | // |
||
317 | // |
||
318 | // Returnvalue: none |
||
319 | //________________________________________________________________________________________________________________________________________ |
||
320 | |||
321 | u8 KML_LoggGPSCoordinates(struct str_gps_nav_data gps_data, KML_Document_t *doc) |
||
322 | { |
||
323 | while(doc->state != DOC_LINESTRING_OPENED) // automatic create document with default filename on the card. |
||
324 | { |
||
325 | switch(doc->state) |
||
326 | { |
||
327 | case DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically |
||
328 | KML_DocumentInit(doc); // initialize the document to default values |
||
329 | if(KML_DocumentOpen("default.kml",doc)) // open the kml-document with a standardname. |
||
330 | { |
||
331 | doc->state = DOC_OPENED; |
||
332 | } |
||
333 | break; |
||
334 | |||
335 | case DOC_OPENED: // if a document has been opened before but no placemark exists: |
||
336 | if(KML_PlaceMarkOpen("MIKROKOPTER",doc)) |
||
337 | { |
||
338 | doc->state = DOC_PLACEMARK_OPENED; // add a placemark to the document. |
||
339 | } |
||
340 | break; |
||
341 | |||
342 | case DOC_PLACEMARK_OPENED: // add linestring to the placemark |
||
343 | if(KML_LineStringBegin(doc)) |
||
344 | { |
||
345 | doc->state = DOC_LINESTRING_OPENED; |
||
346 | } |
||
347 | break; |
||
348 | |||
349 | } |
||
350 | }; |
||
351 | |||
352 | if(doc->state == DOC_LINESTRING_OPENED) // if the document was opened add coordinates to the document. |
||
353 | { |
||
354 | KML_LineStringAddPoint(gps_data , doc); |
||
355 | } |
||
356 | } |
||
27 | holgerb | 357 |