Rev 426 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 426 | Rev 434 | ||
---|---|---|---|
Line 116... | Line 116... | ||
116 | 116 | ||
117 | uint8_t KML_DocumentOpen(int8_t *name, KML_Document_t *doc) |
117 | uint8_t KML_DocumentOpen(int8_t *name, KML_Document_t *doc) |
Line 118... | Line 118... | ||
118 | { |
118 | { |
- | 119 | ||
- | 120 | uint8_t retvalue = 0; |
|
- | 121 | uint16_t i; |
|
Line 119... | Line 122... | ||
119 | 122 | int8_t c; |
|
Line 120... | Line 123... | ||
120 | uint8_t retvalue = 0; |
123 | const prog_char *str; |
121 | 124 | ||
Line 122... | Line 125... | ||
122 | if(doc == NULL) return(0); |
125 | if(doc == NULL) return(0); |
123 | 126 | ||
124 | KML_DocumentInit(doc); // intialize the document with resetvalues |
127 | KML_DocumentInit(doc); // intialize the document with resetvalues |
125 | doc->file = fopen_(name,'a'); // open a new file with the specified filename on the memorycard. |
128 | doc->file = fopen_(name,'a'); // open a new file with the specified filename on the memorycard. |
126 | 129 | ||
- | 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 = KML_DOC_OPENED; // change document state to opened. At next a placemark has to be opened. |
|
- | 134 | str = KML_DOCUMENT_HEADER; // write the KML-header to the document. |
|
127 | if(doc->file != NULL) // could the file be opened? |
135 | for(i= 0; i < sizeof(KML_DOCUMENT_HEADER); i++) |
128 | { |
- | |
129 | retvalue = 1; // the document could be created on the drive. |
136 | { |
130 | doc->state = KML_DOC_OPENED; // change document state to opened. At next a placemark has to be opened. |
137 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
Line 131... | Line 138... | ||
131 | fwrite_((void*)KML_DOCUMENT_HEADER, sizeof(KML_DOCUMENT_HEADER)-1,1,doc->file);// write the KML-header to the document. |
138 | fputc_(c, doc->file); // and write that to sd-card |
132 | } |
139 | } |
Line 145... | Line 152... | ||
145 | 152 | ||
146 | uint8_t KML_DocumentClose(KML_Document_t *doc) |
153 | uint8_t KML_DocumentClose(KML_Document_t *doc) |
Line 147... | Line 154... | ||
147 | { |
154 | { |
- | 155 | ||
- | 156 | uint8_t retvalue = 1; |
|
- | 157 | uint16_t i; |
|
Line 148... | Line 158... | ||
148 | 158 | int8_t c; |
|
Line 149... | Line 159... | ||
149 | uint8_t retvalue = 1; |
159 | const prog_char *str; |
150 | 160 | ||
Line 163... | Line 173... | ||
163 | break; |
173 | break; |
Line 164... | Line 174... | ||
164 | 174 | ||
165 | case KML_DOC_OPENED: // close the file on the memorycard |
175 | case KML_DOC_OPENED: // close the file on the memorycard |
166 | if(doc->file != NULL) |
176 | if(doc->file != NULL) |
167 | { |
177 | { |
- | 178 | str = KML_DOCUMENT_FOOTER; // write the KML- footer to the document. |
|
- | 179 | for(i= 0; i < sizeof(KML_DOCUMENT_FOOTER); i++) |
|
- | 180 | { |
|
- | 181 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
|
- | 182 | fputc_(c, doc->file); // and write that to sd-card |
|
168 | fwrite_((void*)KML_DOCUMENT_FOOTER, sizeof(KML_DOCUMENT_FOOTER)-1,1,doc->file); // write the KML- footer to the document. |
183 | } |
169 | fclose_(doc->file); |
184 | fclose_(doc->file); |
170 | retvalue = 1; |
185 | retvalue = 1; |
171 | } |
186 | } |
172 | doc->state = KML_DOC_CLOSED; |
187 | doc->state = KML_DOC_CLOSED; |
Line 191... | Line 206... | ||
191 | //________________________________________________________________________________________________________________________________________ |
206 | //________________________________________________________________________________________________________________________________________ |
Line 192... | Line 207... | ||
192 | 207 | ||
193 | uint8_t KML_PlaceMarkOpen(KML_Document_t *doc) |
208 | uint8_t KML_PlaceMarkOpen(KML_Document_t *doc) |
194 | { |
209 | { |
- | 210 | uint8_t retvalue = 0; |
|
- | 211 | uint16_t i; |
|
- | 212 | int8_t c; |
|
- | 213 | const prog_char *str; |
|
195 | uint8_t retvalue = 0; |
214 | |
196 | if(doc->state == KML_DOC_OPENED) |
215 | if(doc->state == KML_DOC_OPENED) |
197 | { |
216 | { |
198 | if(doc->file != NULL) |
217 | if(doc->file != NULL) |
199 | { |
218 | { |
200 | doc->state = KML_DOC_PLACEMARK_OPENED; |
219 | doc->state = KML_DOC_PLACEMARK_OPENED; |
- | 220 | retvalue = 1; |
|
201 | retvalue = 1; |
221 | str = KML_PLACEMARK_HEADER; |
- | 222 | for(i= 0; i < sizeof(KML_PLACEMARK_HEADER); i++) |
|
- | 223 | { |
|
- | 224 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
|
- | 225 | fputc_(c, doc->file); // and write that to sd-card |
|
202 | fwrite_((void*)KML_PLACEMARK_HEADER, sizeof(KML_PLACEMARK_HEADER)-1,1,doc->file); |
226 | } |
203 | } |
227 | } |
204 | } |
228 | } |
205 | return(retvalue); |
229 | return(retvalue); |
Line 215... | Line 239... | ||
215 | //________________________________________________________________________________________________________________________________________ |
239 | //________________________________________________________________________________________________________________________________________ |
Line 216... | Line 240... | ||
216 | 240 | ||
217 | uint8_t KML_PlaceMarkClose(KML_Document_t *doc) |
241 | uint8_t KML_PlaceMarkClose(KML_Document_t *doc) |
Line 218... | Line 242... | ||
218 | { |
242 | { |
- | 243 | ||
- | 244 | uint8_t retvalue = 0; |
|
- | 245 | uint16_t i; |
|
Line 219... | Line 246... | ||
219 | 246 | int8_t c; |
|
220 | uint8_t retvalue = 0; // close the Placemark-tag of the corosponding document. |
247 | const prog_char *str; |
221 | 248 | ||
222 | if(doc->state == KML_DOC_PLACEMARK_OPENED) |
249 | if(doc->state == KML_DOC_PLACEMARK_OPENED) |
223 | { |
250 | { |
- | 251 | if(doc->file != NULL) |
|
224 | if(doc->file != NULL) |
252 | { |
- | 253 | doc->state = KML_DOC_OPENED; |
|
- | 254 | str = KML_PLACEMARK_FOOTER; |
|
- | 255 | for(i= 0; i < sizeof(KML_PLACEMARK_FOOTER); i++) |
|
- | 256 | { |
|
225 | { |
257 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
226 | doc->state = KML_DOC_OPENED; |
258 | fputc_(c, doc->file); // and write that to sd-card |
227 | fwrite_((void*)KML_PLACEMARK_FOOTER, sizeof(KML_PLACEMARK_FOOTER)-1,1,doc->file); |
259 | } |
228 | retvalue = 1; |
- | |
229 | } |
260 | retvalue = 1; |
230 | } |
261 | } |
Line 231... | Line 262... | ||
231 | 262 | } |
|
232 | return(retvalue); |
263 | return(retvalue); |
Line 243... | Line 274... | ||
243 | 274 | ||
244 | uint8_t KML_LineStringBegin(KML_Document_t *doc) |
275 | uint8_t KML_LineStringBegin(KML_Document_t *doc) |
Line 245... | Line 276... | ||
245 | { |
276 | { |
- | 277 | ||
- | 278 | uint8_t retvalue = 0; |
|
- | 279 | uint16_t i; |
|
Line 246... | Line 280... | ||
246 | 280 | int8_t c; |
|
247 | uint8_t retvalue = 0; |
281 | const prog_char *str; |
248 | 282 | ||
249 | if(doc->state == KML_DOC_PLACEMARK_OPENED) |
283 | if(doc->state == KML_DOC_PLACEMARK_OPENED) |
250 | { |
284 | { |
- | 285 | if(doc->file != NULL) |
|
251 | if(doc->file != NULL) |
286 | { |
- | 287 | doc->state = KML_DOC_LINESTRING_OPENED; |
|
- | 288 | str = KML_LINESTRING_HEADER; |
|
- | 289 | for(i= 0; i < sizeof(KML_LINESTRING_HEADER); i++) |
|
- | 290 | { |
|
252 | { |
291 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
253 | doc->state = KML_DOC_LINESTRING_OPENED; |
292 | fputc_(c, doc->file); // and write that to sd-card |
254 | fwrite_((void*)KML_LINESTRING_HEADER, sizeof(KML_LINESTRING_HEADER)-1,1,doc->file); |
293 | } |
255 | retvalue = 1; |
294 | retvalue = 1; |
256 | } |
295 | } |
Line 269... | Line 308... | ||
269 | 308 | ||
270 | uint8_t KML_LineStringEnd(KML_Document_t *doc) |
309 | uint8_t KML_LineStringEnd(KML_Document_t *doc) |
Line 271... | Line 310... | ||
271 | { |
310 | { |
- | 311 | ||
- | 312 | uint8_t retvalue = 0; |
|
- | 313 | uint16_t i; |
|
Line 272... | Line 314... | ||
272 | 314 | int8_t c; |
|
273 | uint8_t retvalue = 0; |
315 | const prog_char *str; |
274 | 316 | ||
275 | if(doc->state == KML_DOC_LINESTRING_OPENED) |
317 | if(doc->state == KML_DOC_LINESTRING_OPENED) |
276 | { |
318 | { |
- | 319 | if(doc->file != NULL) |
|
277 | if(doc->file != NULL) |
320 | { |
- | 321 | doc->state = KML_DOC_PLACEMARK_OPENED; |
|
- | 322 | str = KML_LINESTRING_FOOTER; |
|
- | 323 | for(i= 0; i < sizeof(KML_LINESTRING_FOOTER); i++) |
|
- | 324 | { |
|
278 | { |
325 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
279 | doc->state = KML_DOC_PLACEMARK_OPENED; |
326 | fputc_(c, doc->file); // and write that to sd-card |
280 | fwrite_((void*)KML_LINESTRING_FOOTER, sizeof(KML_LINESTRING_FOOTER)-1,1,doc->file); |
327 | } |
281 | retvalue = 1; |
328 | retvalue = 1; |
282 | } |
329 | } |
Line 296... | Line 343... | ||
296 | uint8_t KML_LineStringAddPoint(KML_Document_t *doc) |
343 | uint8_t KML_LineStringAddPoint(KML_Document_t *doc) |
297 | { |
344 | { |
Line 298... | Line 345... | ||
298 | 345 | ||
299 | uint8_t retvalue = 0; |
346 | uint8_t retvalue = 0; |
300 | int8_t string[50]; |
- | |
Line 301... | Line 347... | ||
301 | // int32_t rel_altitude = 0; |
347 | int8_t string[50]; |
Line 302... | Line 348... | ||
302 | 348 | ||
303 | if(doc == NULL) return(0); |
349 | if(doc == NULL) return(0); |
Line 329... | Line 375... | ||
329 | fputs_(string, doc->file); |
375 | fputs_(string, doc->file); |
330 | retvalue = 1; |
376 | retvalue = 1; |
331 | } |
377 | } |
332 | } |
378 | } |
333 | } |
379 | } |
334 | - | ||
335 | return(retvalue); |
380 | return(retvalue); |
336 | } |
381 | } |
Line 337... | Line 382... | ||
337 | 382 | ||
338 | //________________________________________________________________________________________________________________________________________ |
383 | //________________________________________________________________________________________________________________________________________ |
Line 350... | Line 395... | ||
350 | while(doc->state != KML_DOC_LINESTRING_OPENED) // automatic create document with default filename on the card. |
395 | while(doc->state != KML_DOC_LINESTRING_OPENED) // automatic create document with default filename on the card. |
351 | { |
396 | { |
352 | switch(doc->state) |
397 | switch(doc->state) |
353 | { |
398 | { |
354 | case KML_DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically |
399 | case KML_DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically |
355 | retval = KML_DocumentOpen("default.kml",doc); // open the kml-document with a standardname. |
400 | retval = KML_DocumentOpen("default.kml",doc); // open the kml-document with a standardname. |
356 | break; |
401 | break; |
Line 357... | Line 402... | ||
357 | 402 | ||
358 | case KML_DOC_OPENED: // if a document has been opened before but no placemark exists: |
403 | case KML_DOC_OPENED: // if a document has been opened before but no placemark exists: |
359 | retval = KML_PlaceMarkOpen(doc); |
404 | retval = KML_PlaceMarkOpen(doc); |