Rev 24 | Rev 41 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 24 | Rev 27 | ||
---|---|---|---|
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 | 57 | ||
58 | #include <stdio.h> |
58 | #include <stdio.h> |
59 | #include "main.h" |
59 | #include "main.h" |
60 | #include "kml.h" |
60 | #include "kml.h" |
61 | #include "kml_header.h" |
61 | #include "kml_header.h" |
62 | #include "fat16.h" |
62 | #include "fat16.h" |
63 | 63 | ||
64 | 64 | ||
65 | //________________________________________________________________________________________________________________________________________ |
65 | //________________________________________________________________________________________________________________________________________ |
66 | // Module name: kml.c |
66 | // Module name: kml.c |
67 | // Compiler used: avr-gcc 3.4.5 |
67 | // Compiler used: avr-gcc 3.4.5 |
68 | // Last Modifikation: 17.03.2008 |
68 | // Last Modifikation: 17.03.2008 |
69 | // Version: 1.02 |
69 | // Version: 1.02 |
70 | // Authors: Stephan Busker |
70 | // Authors: Stephan Busker |
71 | // Description: Source files to write gps-coordinates to a file in the kml (keyhole markup language) fileformat |
71 | // Description: Source files to write gps-coordinates to a file in the kml (keyhole markup language) fileformat |
72 | // Copyright (C) 2007 Stephan Busker |
72 | // Copyright (C) 2007 Stephan Busker |
73 | //........................................................................................................................................ |
73 | //........................................................................................................................................ |
74 | // Functions: extern u8 KML_LoggGPSCoordinates(struct str_gps_nav_data , KML_Document_t *); // intializes the kml-document with standard filename and adds points to the file |
74 | // Functions: extern u8 KML_LoggGPSCoordinates(struct str_gps_nav_data , KML_Document_t *); // intializes the kml-document with standard filename and adds points to the file |
75 | // extern u8 KML_DocumentInit(KML_Document_t *doc) // initializes the kml-document to resetvalues. |
75 | // extern u8 KML_DocumentInit(KML_Document_t *doc) // initializes the kml-document to resetvalues. |
76 | // extern u8 KML_DocumentOpen(s8 *, KML_Document_t *); // opens a new kml document. A filename can be specified. |
76 | // extern u8 KML_DocumentOpen(s8 *, KML_Document_t *); // opens a new kml document. A filename can be specified. |
77 | // extern u8 KML_DocumentClose(KML_Document_t *doc); // closes an open document |
77 | // extern u8 KML_DocumentClose(KML_Document_t *doc); // closes an open document |
78 | // extern u8 KML_PlaceMarkOpen(s8 *name, KML_Document_t *); // opens a new placemark within the specified 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 |
79 | // extern u8 KML_PlaceMarkClose( KML_Document_t *); // Closes the placemark |
80 | // extern u8 KML_LineStringBegin(KML_Document_t *); // begins a new line within the actual placemark |
80 | // extern u8 KML_LineStringBegin(KML_Document_t *); // begins a new line within the actual placemark |
81 | // extern u8 KML_LineStringEnd(KML_Document_t *doc); // ends the actual linestring |
81 | // extern u8 KML_LineStringEnd(KML_Document_t *doc); // ends the actual linestring |
82 | // extern u8 KML_LineStringAddPoint(struct str_gps_nav_data, KML_Document_t *); // adds a new point (gps-coordinates) to the actual linestring |
82 | // extern u8 KML_LineStringAddPoint(struct str_gps_nav_data, KML_Document_t *); // adds a new point (gps-coordinates) to the actual linestring |
83 | //........................................................................................................................................ |
83 | //........................................................................................................................................ |
84 | // ext. functions: |
84 | // ext. functions: |
85 | // |
85 | // |
86 | //........................................................................................................................................ |
86 | //........................................................................................................................................ |
87 | // |
87 | // |
88 | // URL: www.Mikro-Control.de |
88 | // URL: www.Mikro-Control.de |
89 | // mailto: stephan.busker@mikro-control.de |
89 | // mailto: stephan.busker@mikro-control.de |
90 | //________________________________________________________________________________________________________________________________________ |
90 | //________________________________________________________________________________________________________________________________________ |
91 | 91 | ||
92 | 92 | ||
93 | 93 | ||
94 | //________________________________________________________________________________________________________________________________________ |
94 | //________________________________________________________________________________________________________________________________________ |
95 | // Funtion: KML_DocumentInit(KML_Document_t *) |
95 | // Funtion: KML_DocumentInit(KML_Document_t *) |
96 | // |
96 | // |
97 | // Description: This function initializes the kml-document for further use. |
97 | // Description: This function initializes the kml-document for further use. |
98 | // |
98 | // |
99 | // |
99 | // |
100 | // Returnvalue: '1' if document was initialized |
100 | // Returnvalue: '1' if document was initialized |
101 | //________________________________________________________________________________________________________________________________________ |
101 | //________________________________________________________________________________________________________________________________________ |
102 | 102 | ||
103 | u8 KML_DocumentInit(KML_Document_t *doc) |
103 | u8 KML_DocumentInit(KML_Document_t *doc) |
104 | { |
104 | { |
105 | doc->name[0] = 0; // name of the document |
105 | doc->name[0] = 0; // name of the document |
106 | doc->state = DOC_CLOSED; // state of the kml-document |
106 | doc->state = DOC_CLOSED; // state of the kml-document |
107 | doc->file = NULL; |
107 | doc->file = NULL; |
108 | doc->place.name[0]=0; |
108 | doc->place.name[0]=0; |
109 | doc->place.description[0]=0; |
109 | doc->place.description[0]=0; |
110 | return(1); |
110 | return(1); |
111 | } |
111 | } |
112 | 112 | ||
113 | //________________________________________________________________________________________________________________________________________ |
113 | //________________________________________________________________________________________________________________________________________ |
114 | // Funtion: KML_Document_Open(void); |
114 | // Funtion: KML_Document_Open(void); |
115 | // |
115 | // |
116 | // Description: This function opens a new KML- document with the specified name and creates the document header within the file. |
116 | // Description: This function opens a new KML- document with the specified name and creates the document header within the file. |
117 | // |
117 | // |
118 | // |
118 | // |
119 | // Returnvalue: '1' if the KML- file could be created. |
119 | // Returnvalue: '1' if the KML- file could be created. |
120 | //________________________________________________________________________________________________________________________________________ |
120 | //________________________________________________________________________________________________________________________________________ |
121 | 121 | ||
122 | u8 KML_DocumentOpen(s8 *name, KML_Document_t *doc) |
122 | u8 KML_DocumentOpen(s8 *name, KML_Document_t *doc) |
123 | { |
123 | { |
124 | 124 | ||
125 | u8 retvalue = 0; |
125 | u8 retvalue = 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 = DOC_OPENED; // change document state to opened. At next a placemark has to be opened. |
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. |
134 | fwrite_(KML_DOCUMENT_HEADER, sizeof(KML_DOCUMENT_HEADER)-1,1,doc->file); // write the KML- footer to the document. |
135 | } |
135 | } |
136 | 136 | ||
137 | return(retvalue); |
137 | return(retvalue); |
138 | } |
138 | } |
139 | 139 | ||
140 | //________________________________________________________________________________________________________________________________________ |
140 | //________________________________________________________________________________________________________________________________________ |
141 | // Funtion: DocumentClose(KML_Document_t *doc); |
141 | // Funtion: DocumentClose(KML_Document_t *doc); |
142 | // |
142 | // |
143 | // Description: This function closes the document specified by doc. |
143 | // Description: This function closes the document specified by doc. |
144 | // |
144 | // |
145 | // |
145 | // |
146 | // Returnvalue: none |
146 | // Returnvalue: none |
147 | //________________________________________________________________________________________________________________________________________ |
147 | //________________________________________________________________________________________________________________________________________ |
148 | 148 | ||
149 | u8 KML_DocumentClose(KML_Document_t *doc) |
149 | u8 KML_DocumentClose(KML_Document_t *doc) |
150 | { |
150 | { |
151 | 151 | ||
152 | u8 retvalue = 0; |
152 | u8 retvalue = 0; |
153 | 153 | ||
154 | while(doc->state != DOC_CLOSED) // close linestring, placemark and document before closing the file on the memorycard |
154 | while(doc->state != DOC_CLOSED) // close linestring, placemark and document before closing the file on the memorycard |
155 | { |
155 | { |
156 | switch(doc->state) |
156 | switch(doc->state) |
157 | { |
157 | { |
158 | case DOC_LINESTRING_OPENED: |
158 | case DOC_LINESTRING_OPENED: |
159 | KML_LineStringEnd(doc); // write terminating tag to end linestring. |
159 | KML_LineStringEnd(doc); // write terminating tag to end linestring. |
160 | doc->state = DOC_PLACEMARK_OPENED; |
160 | doc->state = DOC_PLACEMARK_OPENED; |
161 | break; |
161 | break; |
162 | 162 | ||
163 | case DOC_PLACEMARK_OPENED: // write terminating tag to close placemark. |
163 | case DOC_PLACEMARK_OPENED: // write terminating tag to close placemark. |
164 | KML_PlaceMarkClose(doc); |
164 | KML_PlaceMarkClose(doc); |
165 | doc->state = DOC_OPENED; |
165 | doc->state = DOC_OPENED; |
166 | break; |
166 | break; |
167 | 167 | ||
168 | case DOC_OPENED: // close the file on the memorycard |
168 | case DOC_OPENED: // close the file on the memorycard |
169 | if(doc->file != NULL) |
169 | if(doc->file != NULL) |
170 | { |
170 | { |
171 | fwrite_(KML_DOCUMENT_FOOTER, sizeof(KML_DOCUMENT_FOOTER)-1,1,doc->file); // write the KML- footer to the document. |
171 | fwrite_(KML_DOCUMENT_FOOTER, sizeof(KML_DOCUMENT_FOOTER)-1,1,doc->file); // write the KML- footer to the document. |
172 | fclose_(doc->file); |
172 | fclose_(doc->file); |
173 | retvalue = 1; |
173 | retvalue = 1; |
174 | } |
174 | } |
175 | doc->state = DOC_CLOSED; |
175 | doc->state = DOC_CLOSED; |
176 | break; |
176 | break; |
177 | 177 | ||
178 | } |
178 | } |
179 | }; |
179 | }; |
180 | 180 | ||
181 | return(retvalue); |
181 | return(retvalue); |
182 | } |
182 | } |
183 | 183 | ||
184 | //________________________________________________________________________________________________________________________________________ |
184 | //________________________________________________________________________________________________________________________________________ |
185 | // Funtion: u8 PlaceMarkOpen(s8 *name, File *file); |
185 | // Funtion: u8 PlaceMarkOpen(s8 *name, File *file); |
186 | // |
186 | // |
187 | // Description: This function adds a placemark to the document. |
187 | // Description: This function adds a placemark to the document. |
188 | // |
188 | // |
189 | // |
189 | // |
190 | // Returnvalue: none |
190 | // Returnvalue: none |
191 | //________________________________________________________________________________________________________________________________________ |
191 | //________________________________________________________________________________________________________________________________________ |
192 | 192 | ||
193 | u8 KML_PlaceMarkOpen(s8 *name, KML_Document_t *doc) |
193 | u8 KML_PlaceMarkOpen(s8 *name, KML_Document_t *doc) |
194 | { |
194 | { |
195 | 195 | ||
196 | u8 retvalue = 0; |
196 | u8 retvalue = 0; |
197 | 197 | ||
198 | if(doc->file != NULL) |
198 | if(doc->file != NULL) |
199 | { |
199 | { |
200 | doc->state = DOC_PLACEMARK_OPENED; |
200 | doc->state = DOC_PLACEMARK_OPENED; |
201 | retvalue = 1; |
201 | retvalue = 1; |
202 | fwrite_(KML_PLACEMARK_HEADER, sizeof(KML_PLACEMARK_HEADER)-1,1,doc->file); |
202 | fwrite_(KML_PLACEMARK_HEADER, sizeof(KML_PLACEMARK_HEADER)-1,1,doc->file); |
203 | } |
203 | } |
204 | 204 | ||
205 | return(retvalue); |
205 | return(retvalue); |
206 | } |
206 | } |
207 | 207 | ||
208 | //________________________________________________________________________________________________________________________________________ |
208 | //________________________________________________________________________________________________________________________________________ |
209 | // Funtion: u8 PlaceMarkClose(KML_PlaceMark_t *place, File *file); |
209 | // Funtion: u8 PlaceMarkClose(KML_PlaceMark_t *place, File *file); |
210 | // |
210 | // |
211 | // Description: This function ends the placemark opened before. |
211 | // Description: This function ends the placemark opened before. |
212 | // |
212 | // |
213 | // |
213 | // |
214 | // Returnvalue: none |
214 | // Returnvalue: none |
215 | //________________________________________________________________________________________________________________________________________ |
215 | //________________________________________________________________________________________________________________________________________ |
216 | 216 | ||
217 | u8 KML_PlaceMarkClose(KML_Document_t *doc) |
217 | u8 KML_PlaceMarkClose(KML_Document_t *doc) |
218 | { |
218 | { |
219 | 219 | ||
220 | u8 retvalue = 0; // close the Placemark-tag of the corosponding document. |
220 | u8 retvalue = 0; // close the Placemark-tag of the corosponding document. |
221 | 221 | ||
222 | if(doc->state == DOC_PLACEMARK_OPENED) |
222 | if(doc->state == DOC_PLACEMARK_OPENED) |
223 | { |
223 | { |
224 | if(doc->file != NULL) |
224 | if(doc->file != NULL) |
225 | { |
225 | { |
226 | doc->state =DOC_OPENED; |
226 | doc->state =DOC_OPENED; |
227 | fwrite_(KML_PLACEMARK_FOOTER, sizeof(KML_PLACEMARK_FOOTER)-1,1,doc->file); |
227 | fwrite_(KML_PLACEMARK_FOOTER, sizeof(KML_PLACEMARK_FOOTER)-1,1,doc->file); |
228 | retvalue = 1; |
228 | retvalue = 1; |
229 | } |
229 | } |
230 | } |
230 | } |
231 | 231 | ||
232 | return(retvalue); |
232 | return(retvalue); |
233 | } |
233 | } |
234 | 234 | ||
235 | //________________________________________________________________________________________________________________________________________ |
235 | //________________________________________________________________________________________________________________________________________ |
236 | // Funtion: u8 LineStringBegin(KML_Document_t *doc); |
236 | // Funtion: u8 LineStringBegin(KML_Document_t *doc); |
237 | // |
237 | // |
238 | // Description: This function ends the placemark opened before. |
238 | // Description: This function ends the placemark opened before. |
239 | // |
239 | // |
240 | // |
240 | // |
241 | // Returnvalue: none |
241 | // Returnvalue: none |
242 | //________________________________________________________________________________________________________________________________________ |
242 | //________________________________________________________________________________________________________________________________________ |
243 | 243 | ||
244 | u8 KML_LineStringBegin(KML_Document_t *doc) |
244 | u8 KML_LineStringBegin(KML_Document_t *doc) |
245 | { |
245 | { |
246 | 246 | ||
247 | u8 retvalue = 0; |
247 | u8 retvalue = 0; |
248 | 248 | ||
249 | if(doc->file != NULL) |
249 | if(doc->file != NULL) |
250 | { |
250 | { |
251 | doc->state = DOC_LINESTRING_OPENED; |
251 | doc->state = DOC_LINESTRING_OPENED; |
252 | fwrite_(KML_LINESTRING_HEADER, sizeof(KML_LINESTRING_HEADER)-1,1,doc->file); |
252 | fwrite_(KML_LINESTRING_HEADER, sizeof(KML_LINESTRING_HEADER)-1,1,doc->file); |
253 | retvalue = 1; |
253 | retvalue = 1; |
254 | } |
254 | } |
255 | 255 | ||
256 | return(retvalue); |
256 | return(retvalue); |
257 | } |
257 | } |
258 | 258 | ||
259 | //________________________________________________________________________________________________________________________________________ |
259 | //________________________________________________________________________________________________________________________________________ |
260 | // Funtion: u8 LineStringEnd(KML_Document_t *doc) |
260 | // Funtion: u8 LineStringEnd(KML_Document_t *doc) |
261 | // |
261 | // |
262 | // Description: This function ends the placemark opened before. |
262 | // Description: This function ends the placemark opened before. |
263 | // |
263 | // |
264 | // |
264 | // |
265 | // Returnvalue: none |
265 | // Returnvalue: none |
266 | //________________________________________________________________________________________________________________________________________ |
266 | //________________________________________________________________________________________________________________________________________ |
267 | 267 | ||
268 | u8 KML_LineStringEnd(KML_Document_t *doc) |
268 | u8 KML_LineStringEnd(KML_Document_t *doc) |
269 | { |
269 | { |
270 | 270 | ||
271 | u8 retvalue = 0; |
271 | u8 retvalue = 0; |
272 | 272 | ||
273 | if(doc->state == DOC_LINESTRING_OPENED); |
273 | if(doc->state == DOC_LINESTRING_OPENED); |
274 | if(doc->file != NULL) |
274 | if(doc->file != NULL) |
275 | { |
275 | { |
276 | doc->state = DOC_PLACEMARK_OPENED; |
276 | doc->state = DOC_PLACEMARK_OPENED; |
277 | fwrite_(KML_LINESTRING_FOOTER, sizeof(KML_LINESTRING_FOOTER)-1,1,doc->file); |
277 | fwrite_(KML_LINESTRING_FOOTER, sizeof(KML_LINESTRING_FOOTER)-1,1,doc->file); |
278 | retvalue = 1; |
278 | retvalue = 1; |
279 | } |
279 | } |
280 | 280 | ||
281 | return(retvalue); |
281 | return(retvalue); |
282 | } |
282 | } |
283 | 283 | ||
284 | //________________________________________________________________________________________________________________________________________ |
284 | //________________________________________________________________________________________________________________________________________ |
285 | // Funtion: u8 LineStringAddPoint(struct str_GPSPosition, KML_Document_t *doc) |
285 | // Funtion: u8 LineStringAddPoint(struct str_GPSPosition, KML_Document_t *doc) |
286 | // |
286 | // |
287 | // Description: This function adds a point to the specified document. |
287 | // Description: This function adds a point to the specified document. |
288 | // |
288 | // |
289 | // |
289 | // |
290 | // Returnvalue: none |
290 | // Returnvalue: none |
291 | //________________________________________________________________________________________________________________________________________ |
291 | //________________________________________________________________________________________________________________________________________ |
292 | 292 | ||
293 | u8 KML_LineStringAddPoint(struct str_gps_nav_data gps_data ,KML_Document_t *doc) |
293 | u8 KML_LineStringAddPoint(struct str_gps_nav_data gps_data ,KML_Document_t *doc) |
294 | { |
294 | { |
295 | 295 | ||
296 | u8 retvalue = 0; |
296 | u8 retvalue = 0; |
297 | s8 string[50]; |
297 | s8 string[50]; |
298 | 298 | ||
299 | if(doc->state == DOC_LINESTRING_OPENED) |
299 | if(doc->state == DOC_LINESTRING_OPENED) |
300 | { |
300 | { |
301 | if(doc->file != NULL) |
301 | if(doc->file != NULL) |
302 | { |
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); |
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); |
304 | fputs_(doc->file,string); |
305 | retvalue = 1; |
305 | retvalue = 1; |
306 | } |
306 | } |
307 | } |
307 | } |
308 | 308 | ||
309 | return(retvalue); |
309 | return(retvalue); |
310 | } |
310 | } |
311 | 311 | ||
312 | //________________________________________________________________________________________________________________________________________ |
312 | //________________________________________________________________________________________________________________________________________ |
313 | // Funtion: u8 KML_LoggGPSCoordinates(struct str_gps_nav_data, KML_Document_t *) |
313 | // Funtion: u8 KML_LoggGPSCoordinates(struct str_gps_nav_data, KML_Document_t *) |
314 | // |
314 | // |
315 | // Description: This function opens adds gpscoordinates to an KML-Document. The document will be opened, if not already done |
315 | // Description: This function opens adds gpscoordinates to an KML-Document. The document will be opened, if not already done |
316 | // |
316 | // |
317 | // |
317 | // |
318 | // Returnvalue: none |
318 | // Returnvalue: none |
319 | //________________________________________________________________________________________________________________________________________ |
319 | //________________________________________________________________________________________________________________________________________ |
320 | 320 | ||
321 | u8 KML_LoggGPSCoordinates(struct str_gps_nav_data gps_data, KML_Document_t *doc) |
321 | u8 KML_LoggGPSCoordinates(struct str_gps_nav_data gps_data, KML_Document_t *doc) |
322 | { |
322 | { |
323 | while(doc->state != DOC_LINESTRING_OPENED) // automatic create document with default filename on the card. |
323 | while(doc->state != DOC_LINESTRING_OPENED) // automatic create document with default filename on the card. |
324 | { |
324 | { |
325 | switch(doc->state) |
325 | switch(doc->state) |
326 | { |
326 | { |
327 | case DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically |
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 |
328 | KML_DocumentInit(doc); // initialize the document to default values |
329 | if(KML_DocumentOpen("default.kml",doc)) // open the kml-document with a standardname. |
329 | if(KML_DocumentOpen("default.kml",doc)) // open the kml-document with a standardname. |
330 | { |
330 | { |
331 | doc->state = DOC_OPENED; |
331 | doc->state = DOC_OPENED; |
332 | } |
332 | } |
333 | break; |
333 | break; |
334 | 334 | ||
335 | case DOC_OPENED: // if a document has been opened before but no placemark exists: |
335 | case DOC_OPENED: // if a document has been opened before but no placemark exists: |
336 | if(KML_PlaceMarkOpen("MIKROKOPTER",doc)) |
336 | if(KML_PlaceMarkOpen("MIKROKOPTER",doc)) |
337 | { |
337 | { |
338 | doc->state = DOC_PLACEMARK_OPENED; // add a placemark to the document. |
338 | doc->state = DOC_PLACEMARK_OPENED; // add a placemark to the document. |
339 | } |
339 | } |
340 | break; |
340 | break; |
341 | 341 | ||
342 | case DOC_PLACEMARK_OPENED: // add linestring to the placemark |
342 | case DOC_PLACEMARK_OPENED: // add linestring to the placemark |
343 | if(KML_LineStringBegin(doc)) |
343 | if(KML_LineStringBegin(doc)) |
344 | { |
344 | { |
345 | doc->state = DOC_LINESTRING_OPENED; |
345 | doc->state = DOC_LINESTRING_OPENED; |
346 | } |
346 | } |
347 | break; |
347 | break; |
348 | 348 | ||
349 | } |
349 | } |
350 | }; |
350 | }; |
351 | 351 | ||
352 | if(doc->state == DOC_LINESTRING_OPENED) // if the document was opened add coordinates to the document. |
352 | if(doc->state == DOC_LINESTRING_OPENED) // if the document was opened add coordinates to the document. |
353 | { |
353 | { |
354 | KML_LineStringAddPoint(gps_data , doc); |
354 | KML_LineStringAddPoint(gps_data , doc); |
355 | } |
355 | } |
356 | } |
356 | } |
357 | - | ||
358 | 357 | ||
- | 358 |