Rev 434 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 434 | Rev 436 | ||
---|---|---|---|
1 | /*#######################################################################################*/ |
1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
3 | /*#######################################################################################*/ |
3 | /*#######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
6 | // + Nur für den privaten Gebrauch |
6 | // + Nur für den privaten Gebrauch |
7 | // + FOR NON COMMERCIAL USE ONLY |
7 | // + FOR NON COMMERCIAL USE ONLY |
8 | // + www.MikroKopter.com |
8 | // + www.MikroKopter.com |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
22 | // + eindeutig als Ursprung verlinkt werden |
22 | // + eindeutig als Ursprung verlinkt werden |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
25 | // + Benutzung auf eigene Gefahr |
25 | // + Benutzung auf eigene Gefahr |
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
28 | // + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
29 | // + mit unserer Zustimmung zulässig |
29 | // + mit unserer Zustimmung zulässig |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
34 | // + this list of conditions and the following disclaimer. |
34 | // + this list of conditions and the following disclaimer. |
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
36 | // + from this software without specific prior written permission. |
36 | // + from this software without specific prior written permission. |
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
38 | // + for non-commercial use (directly or indirectly) |
38 | // + for non-commercial use (directly or indirectly) |
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
40 | // + with our written permission |
40 | // + with our written permission |
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
42 | // + clearly linked as origin |
42 | // + clearly linked as origin |
43 | // + * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed |
43 | // + * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed |
44 | // |
44 | // |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
57 | #include <stdlib.h> |
57 | #include <stdlib.h> |
58 | #include <stdio.h> |
58 | #include <stdio.h> |
59 | #include <string.h> |
59 | #include <string.h> |
60 | #include "gpx.h" |
60 | #include "gpx.h" |
61 | #include "gpx_header.h" |
61 | #include "gpx_header.h" |
62 | #include "timer0.h" |
62 | #include "timer0.h" |
63 | #include "main.h" |
63 | #include "main.h" |
64 | 64 | ||
65 | //________________________________________________________________________________________________________________________________________ |
65 | //________________________________________________________________________________________________________________________________________ |
66 | // Function: GPX_DocumentInit(GPX_Document_t *) |
66 | // Function: GPX_DocumentInit(GPX_Document_t *) |
67 | // |
67 | // |
68 | // Description: This function initializes the gpx-document for further use. |
68 | // Description: This function initializes the gpx-document for further use. |
69 | // |
69 | // |
70 | // |
70 | // |
71 | // Returnvalue: '1' if document was initialized |
71 | // Returnvalue: '1' if document was initialized |
72 | //________________________________________________________________________________________________________________________________________ |
72 | //________________________________________________________________________________________________________________________________________ |
73 | 73 | ||
74 | uint8_t GPX_DocumentInit(GPX_Document_t *doc) |
74 | uint8_t GPX_DocumentInit(GPX_Document_t *doc) |
75 | { |
75 | { |
76 | if(doc->state != GPX_DOC_CLOSED) GPX_DocumentClose(doc); // close file if it was opened before |
76 | if(doc->state != GPX_DOC_CLOSED) GPX_DocumentClose(doc); // close file if it was opened before |
77 | doc->state = GPX_DOC_CLOSED; // init state of the gpx-document |
77 | doc->state = GPX_DOC_CLOSED; // init state of the gpx-document |
78 | doc->file = NULL; |
78 | doc->file = NULL; |
79 | return(1); |
79 | return(1); |
80 | } |
80 | } |
81 | 81 | ||
82 | //________________________________________________________________________________________________________________________________________ |
82 | //________________________________________________________________________________________________________________________________________ |
83 | // Function: GPX_Document_Open(s8 *name, GPX_Document_t *doc); |
83 | // Function: GPX_Document_Open(s8 *name, GPX_Document_t *doc); |
84 | // |
84 | // |
85 | // Description: This function opens a new gpx-document with the specified name and creates the document header within the file. |
85 | // Description: This function opens a new gpx-document with the specified name and creates the document header within the file. |
86 | // |
86 | // |
87 | // |
87 | // |
88 | // Returnvalue: '1' if the gpx-file could be created. |
88 | // Returnvalue: '1' if the gpx-file could be created. |
89 | //________________________________________________________________________________________________________________________________________ |
89 | //________________________________________________________________________________________________________________________________________ |
90 | 90 | ||
91 | uint8_t GPX_DocumentOpen(int8_t *name, GPX_Document_t *doc) |
91 | uint8_t GPX_DocumentOpen(int8_t *name, GPX_Document_t *doc) |
92 | { |
92 | { |
93 | 93 | ||
94 | uint8_t retvalue = 0; |
94 | uint8_t retvalue = 0; |
95 | uint16_t i; |
95 | uint16_t i; |
96 | int8_t c; |
96 | int8_t c; |
97 | const prog_char *str; |
97 | const prog_char *str; |
98 | 98 | ||
99 | if(doc == NULL) return(0); |
99 | if(doc == NULL) return(0); |
100 | GPX_DocumentInit(doc); // intialize the document with resetvalues |
100 | GPX_DocumentInit(doc); // intialize the document with resetvalues |
101 | doc->file = fopen_(name,'a'); // open a new file with the specified filename on the memorycard. |
101 | doc->file = fopen_(name,'a'); // open a new file with the specified filename on the memorycard. |
102 | 102 | ||
103 | if(doc->file != NULL) // could the file be opened? |
103 | if(doc->file != NULL) // could the file be opened? |
104 | { |
104 | { |
105 | retvalue = 1; // the document could be created on the drive. |
105 | retvalue = 1; // the document could be created on the drive. |
106 | doc->state = GPX_DOC_OPENED; // change document state to opened. At next a placemark has to be opened. |
106 | doc->state = GPX_DOC_OPENED; // change document state to opened. At next a placemark has to be opened. |
107 | str = GPX_DOCUMENT_HEADER; // write the gpx-header to the document.. |
107 | str = GPX_DOCUMENT_HEADER; // write the gpx-header to the document.. |
108 | for(i= 0; i < sizeof(GPX_DOCUMENT_HEADER); i++) |
108 | for(i= 0; i < sizeof(GPX_DOCUMENT_HEADER)-1; i++) |
109 | { |
109 | { |
110 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
110 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
111 | fputc_(c, doc->file); // and write that to sd-card |
111 | fputc_(c, doc->file); // and write that to sd-card |
112 | } |
112 | } |
113 | } |
113 | } |
114 | 114 | ||
115 | return(retvalue); |
115 | return(retvalue); |
116 | } |
116 | } |
117 | 117 | ||
118 | //________________________________________________________________________________________________________________________________________ |
118 | //________________________________________________________________________________________________________________________________________ |
119 | // Function: DocumentClose(GPX_Document_t *doc); |
119 | // Function: DocumentClose(GPX_Document_t *doc); |
120 | // |
120 | // |
121 | // Description: This function closes the document specified by doc. |
121 | // Description: This function closes the document specified by doc. |
122 | // |
122 | // |
123 | // |
123 | // |
124 | // Returnvalue: '1' if the gpx-file could be closed. |
124 | // Returnvalue: '1' if the gpx-file could be closed. |
125 | //________________________________________________________________________________________________________________________________________ |
125 | //________________________________________________________________________________________________________________________________________ |
126 | 126 | ||
127 | uint8_t GPX_DocumentClose(GPX_Document_t *doc) |
127 | uint8_t GPX_DocumentClose(GPX_Document_t *doc) |
128 | { |
128 | { |
129 | 129 | ||
130 | uint8_t retvalue = 1; |
130 | uint8_t retvalue = 1; |
131 | uint16_t i; |
131 | uint16_t i; |
132 | int8_t c; |
132 | int8_t c; |
133 | const prog_char *str; |
133 | const prog_char *str; |
134 | 134 | ||
135 | if(doc == NULL) return(0); |
135 | if(doc == NULL) return(0); |
136 | 136 | ||
137 | while(doc->state != GPX_DOC_CLOSED) // close linestring, placemark and document before closing the file on the memorycard |
137 | while(doc->state != GPX_DOC_CLOSED) // close linestring, placemark and document before closing the file on the memorycard |
138 | { |
138 | { |
139 | switch(doc->state) |
139 | switch(doc->state) |
140 | { |
140 | { |
141 | case GPX_DOC_TRACKSEGMENT_OPENED: |
141 | case GPX_DOC_TRACKSEGMENT_OPENED: |
142 | GPX_TrackSegmentEnd(doc); // write terminating tag to end tracksegment. |
142 | GPX_TrackSegmentEnd(doc); // write terminating tag to end tracksegment. |
143 | break; |
143 | break; |
144 | 144 | ||
145 | case GPX_DOC_TRACK_OPENED: // write terminating tag to close track. |
145 | case GPX_DOC_TRACK_OPENED: // write terminating tag to close track. |
146 | GPX_TrackEnd(doc); |
146 | GPX_TrackEnd(doc); |
147 | break; |
147 | break; |
148 | 148 | ||
149 | case GPX_DOC_OPENED: // close the file on the memorycard |
149 | case GPX_DOC_OPENED: // close the file on the memorycard |
150 | if(doc->file != NULL) |
150 | if(doc->file != NULL) |
151 | { |
151 | { |
152 | str = GPX_DOCUMENT_FOOTER; // write the gpx-footer to the document. |
152 | str = GPX_DOCUMENT_FOOTER; // write the gpx-footer to the document. |
153 | for(i= 0; i < sizeof(GPX_DOCUMENT_FOOTER); i++) |
153 | for(i= 0; i < sizeof(GPX_DOCUMENT_FOOTER)-1; i++) |
154 | { |
154 | { |
155 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
155 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
156 | fputc_(c, doc->file); // and write that to sd-card |
156 | fputc_(c, doc->file); // and write that to sd-card |
157 | } |
157 | } |
158 | fclose_(doc->file); |
158 | fclose_(doc->file); |
159 | retvalue = 1; |
159 | retvalue = 1; |
160 | } |
160 | } |
161 | doc->state = GPX_DOC_CLOSED; |
161 | doc->state = GPX_DOC_CLOSED; |
162 | break; |
162 | break; |
163 | 163 | ||
164 | default: |
164 | default: |
165 | doc->state = GPX_DOC_CLOSED; |
165 | doc->state = GPX_DOC_CLOSED; |
166 | break; |
166 | break; |
167 | } |
167 | } |
168 | } |
168 | } |
169 | return(retvalue); |
169 | return(retvalue); |
170 | } |
170 | } |
171 | 171 | ||
172 | //________________________________________________________________________________________________________________________________________ |
172 | //________________________________________________________________________________________________________________________________________ |
173 | // Function: u8 GPX_TrackBegin(GPX_Document_t); |
173 | // Function: u8 GPX_TrackBegin(GPX_Document_t); |
174 | // |
174 | // |
175 | // Description: This function adds a track to the document. |
175 | // Description: This function adds a track to the document. |
176 | // |
176 | // |
177 | // |
177 | // |
178 | // Returnvalue: '1' if the track could be opened |
178 | // Returnvalue: '1' if the track could be opened |
179 | //________________________________________________________________________________________________________________________________________ |
179 | //________________________________________________________________________________________________________________________________________ |
180 | 180 | ||
181 | uint8_t GPX_TrackBegin(GPX_Document_t *doc) |
181 | uint8_t GPX_TrackBegin(GPX_Document_t *doc) |
182 | { |
182 | { |
183 | 183 | ||
184 | uint8_t retvalue = 0; |
184 | uint8_t retvalue = 0; |
185 | uint16_t i; |
185 | uint16_t i; |
186 | int8_t c; |
186 | int8_t c; |
187 | const prog_char *str; |
187 | const prog_char *str; |
188 | 188 | ||
189 | 189 | ||
190 | if(doc->state == GPX_DOC_OPENED) |
190 | if(doc->state == GPX_DOC_OPENED) |
191 | { |
191 | { |
192 | if(doc->file != NULL) |
192 | if(doc->file != NULL) |
193 | { |
193 | { |
194 | doc->state = GPX_DOC_TRACK_OPENED; |
194 | doc->state = GPX_DOC_TRACK_OPENED; |
195 | retvalue = 1; |
195 | retvalue = 1; |
196 | str = GPX_TRACK_HEADER; |
196 | str = GPX_TRACK_HEADER; |
197 | for(i= 0; i < sizeof(GPX_TRACK_HEADER); i++) |
197 | for(i= 0; i < sizeof(GPX_TRACK_HEADER)-1; i++) |
198 | { |
198 | { |
199 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
199 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
200 | fputc_(c, doc->file); // and write that to sd-card |
200 | fputc_(c, doc->file); // and write that to sd-card |
201 | } |
201 | } |
202 | } |
202 | } |
203 | } |
203 | } |
204 | return(retvalue); |
204 | return(retvalue); |
205 | } |
205 | } |
206 | 206 | ||
207 | //________________________________________________________________________________________________________________________________________ |
207 | //________________________________________________________________________________________________________________________________________ |
208 | // Function: u8 GPX_TrackEnd(KML_Document_t *doc) |
208 | // Function: u8 GPX_TrackEnd(KML_Document_t *doc) |
209 | // |
209 | // |
210 | // Description: This function ends the track opened before. |
210 | // Description: This function ends the track opened before. |
211 | // |
211 | // |
212 | // |
212 | // |
213 | // Returnvalue: 1' if the track could be closed |
213 | // Returnvalue: 1' if the track could be closed |
214 | //________________________________________________________________________________________________________________________________________ |
214 | //________________________________________________________________________________________________________________________________________ |
215 | 215 | ||
216 | uint8_t GPX_TrackEnd(GPX_Document_t *doc) |
216 | uint8_t GPX_TrackEnd(GPX_Document_t *doc) |
217 | { |
217 | { |
218 | 218 | ||
219 | uint8_t retvalue = 0; |
219 | uint8_t retvalue = 0; |
220 | uint16_t i; |
220 | uint16_t i; |
221 | int8_t c; |
221 | int8_t c; |
222 | const prog_char *str; |
222 | const prog_char *str; |
223 | 223 | ||
224 | if(doc->state == GPX_DOC_TRACK_OPENED) |
224 | if(doc->state == GPX_DOC_TRACK_OPENED) |
225 | { |
225 | { |
226 | if(doc->file != NULL) |
226 | if(doc->file != NULL) |
227 | { |
227 | { |
228 | doc->state = GPX_DOC_OPENED; |
228 | doc->state = GPX_DOC_OPENED; |
229 | str = GPX_TRACK_FOOTER; |
229 | str = GPX_TRACK_FOOTER; |
230 | for(i= 0; i < sizeof(GPX_TRACK_FOOTER); i++) |
230 | for(i= 0; i < sizeof(GPX_TRACK_FOOTER)-1; i++) |
231 | { |
231 | { |
232 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
232 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
233 | fputc_(c, doc->file); // and write that to sd-card |
233 | fputc_(c, doc->file); // and write that to sd-card |
234 | } |
234 | } |
235 | } |
235 | } |
236 | } |
236 | } |
237 | 237 | ||
238 | return(retvalue); |
238 | return(retvalue); |
239 | } |
239 | } |
240 | 240 | ||
241 | //________________________________________________________________________________________________________________________________________ |
241 | //________________________________________________________________________________________________________________________________________ |
242 | // Function: u8 GPX_TrackSegmentBegin(GPX_Document_t *doc); |
242 | // Function: u8 GPX_TrackSegmentBegin(GPX_Document_t *doc); |
243 | // |
243 | // |
244 | // Description: This function starts a track segment. |
244 | // Description: This function starts a track segment. |
245 | // |
245 | // |
246 | // |
246 | // |
247 | // Returnvalue: '1' if the track segement could be started |
247 | // Returnvalue: '1' if the track segement could be started |
248 | //________________________________________________________________________________________________________________________________________ |
248 | //________________________________________________________________________________________________________________________________________ |
249 | 249 | ||
250 | uint8_t GPX_TrackSegmentBegin(GPX_Document_t *doc) |
250 | uint8_t GPX_TrackSegmentBegin(GPX_Document_t *doc) |
251 | { |
251 | { |
252 | 252 | ||
253 | uint8_t retvalue = 0; |
253 | uint8_t retvalue = 0; |
254 | uint16_t i; |
254 | uint16_t i; |
255 | int8_t c; |
255 | int8_t c; |
256 | const prog_char *str; |
256 | const prog_char *str; |
257 | 257 | ||
258 | if(doc->state == GPX_DOC_TRACK_OPENED) |
258 | if(doc->state == GPX_DOC_TRACK_OPENED) |
259 | { |
259 | { |
260 | if(doc->file != NULL) |
260 | if(doc->file != NULL) |
261 | { |
261 | { |
262 | doc->state = GPX_DOC_TRACKSEGMENT_OPENED; |
262 | doc->state = GPX_DOC_TRACKSEGMENT_OPENED; |
263 | str = GPX_TRACKSEGMENT_HEADER; |
263 | str = GPX_TRACKSEGMENT_HEADER; |
264 | for(i = 0; i < sizeof(GPX_TRACKSEGMENT_HEADER); i++) |
264 | for(i = 0; i < sizeof(GPX_TRACKSEGMENT_HEADER)-1; i++) |
265 | { |
265 | { |
266 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
266 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
267 | fputc_(c, doc->file); // and write that to sd-card |
267 | fputc_(c, doc->file); // and write that to sd-card |
268 | } |
268 | } |
269 | retvalue = 1; |
269 | retvalue = 1; |
270 | } |
270 | } |
271 | } |
271 | } |
272 | return(retvalue); |
272 | return(retvalue); |
273 | } |
273 | } |
274 | 274 | ||
275 | //________________________________________________________________________________________________________________________________________ |
275 | //________________________________________________________________________________________________________________________________________ |
276 | // Function: u8 GPX_TrackSegmentEnd(GPX_Document_t *doc); |
276 | // Function: u8 GPX_TrackSegmentEnd(GPX_Document_t *doc); |
277 | // |
277 | // |
278 | // Description: This function ends the tracksegment opened before. |
278 | // Description: This function ends the tracksegment opened before. |
279 | // |
279 | // |
280 | // |
280 | // |
281 | // Returnvalue: '1' if the track segment could be terminated |
281 | // Returnvalue: '1' if the track segment could be terminated |
282 | //________________________________________________________________________________________________________________________________________ |
282 | //________________________________________________________________________________________________________________________________________ |
283 | 283 | ||
284 | uint8_t GPX_TrackSegmentEnd(GPX_Document_t *doc) |
284 | uint8_t GPX_TrackSegmentEnd(GPX_Document_t *doc) |
285 | { |
285 | { |
286 | 286 | ||
287 | uint8_t retvalue = 0; |
287 | uint8_t retvalue = 0; |
288 | uint16_t i; |
288 | uint16_t i; |
289 | int8_t c; |
289 | int8_t c; |
290 | const prog_char *str; |
290 | const prog_char *str; |
291 | 291 | ||
292 | 292 | ||
293 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) |
293 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) |
294 | { |
294 | { |
295 | if(doc->file != NULL) |
295 | if(doc->file != NULL) |
296 | { |
296 | { |
297 | doc->state = GPX_DOC_TRACK_OPENED; |
297 | doc->state = GPX_DOC_TRACK_OPENED; |
298 | str = GPX_TRACKSEGMENT_FOOTER; |
298 | str = GPX_TRACKSEGMENT_FOOTER; |
299 | for(i = 0; i < sizeof(GPX_TRACKSEGMENT_FOOTER); i++) |
299 | for(i = 0; i < sizeof(GPX_TRACKSEGMENT_FOOTER)-1; i++) |
300 | { |
300 | { |
301 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
301 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
302 | fputc_(c, doc->file); // and write that to sd-card |
302 | fputc_(c, doc->file); // and write that to sd-card |
303 | } |
303 | } |
304 | retvalue = 1; |
304 | retvalue = 1; |
305 | } |
305 | } |
306 | } |
306 | } |
307 | return(retvalue); |
307 | return(retvalue); |
308 | } |
308 | } |
309 | 309 | ||
310 | //________________________________________________________________________________________________________________________________________ |
310 | //________________________________________________________________________________________________________________________________________ |
311 | // Function: u8 GPX_TrackSegementAddPoint(GPS_Pos_t * pGPS_Position ,GPX_Document_t *doc); |
311 | // Function: u8 GPX_TrackSegementAddPoint(GPS_Pos_t * pGPS_Position ,GPX_Document_t *doc); |
312 | // |
312 | // |
313 | // Description: This function adds a pointof a track segement to the specified document. |
313 | // Description: This function adds a pointof a track segement to the specified document. |
314 | // |
314 | // |
315 | // |
315 | // |
316 | // Returnvalue: '1' if a point was added |
316 | // Returnvalue: '1' if a point was added |
317 | //________________________________________________________________________________________________________________________________________ |
317 | //________________________________________________________________________________________________________________________________________ |
318 | 318 | ||
319 | uint8_t GPX_TrackSegementAddPoint(GPX_Document_t *doc) |
319 | uint8_t GPX_TrackSegementAddPoint(GPX_Document_t *doc) |
320 | { |
320 | { |
321 | 321 | ||
322 | uint8_t retvalue = 0; |
322 | uint8_t retvalue = 0; |
323 | int8_t string[100]; |
323 | int8_t string[100]; |
324 | 324 | ||
325 | if(doc == NULL) return(0); |
325 | if(doc == NULL) return(0); |
326 | 326 | ||
327 | if(GPSData.Position.Status != INVALID) |
327 | if(GPSData.Position.Status != INVALID) |
328 | { |
328 | { |
329 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) |
329 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) |
330 | { |
330 | { |
331 | if(doc->file != NULL) |
331 | if(doc->file != NULL) |
332 | { |
332 | { |
333 | int16_t i16_1, i16_2, i16_3; |
333 | int16_t i16_1, i16_2, i16_3; |
334 | uint8_t u8_1, u8_2; |
334 | uint8_t u8_1, u8_2; |
335 | // write <trkpt> tag |
335 | // write <trkpt> tag |
336 | if(GPSData.Position.Latitude < 0) u8_1 = '-'; |
336 | if(GPSData.Position.Latitude < 0) u8_1 = '-'; |
337 | else u8_1 = '+'; |
337 | else u8_1 = '+'; |
338 | i16_1 = abs((int16_t)(GPSData.Position.Latitude/10000000L)); |
338 | i16_1 = abs((int16_t)(GPSData.Position.Latitude/10000000L)); |
339 | i16_2 = abs((int16_t)((GPSData.Position.Latitude%10000000L)/10000L)); |
339 | i16_2 = abs((int16_t)((GPSData.Position.Latitude%10000000L)/10000L)); |
340 | i16_3 = abs((int16_t)(((GPSData.Position.Latitude%10000000L)%10000L)/10L)); |
340 | i16_3 = abs((int16_t)(((GPSData.Position.Latitude%10000000L)%10000L)/10L)); |
341 | sprintf(string, "<trkpt lat=\"%c%d.%.3d%.3d\" ",u8_1, i16_1, i16_2, i16_3); |
341 | sprintf(string, "<trkpt lat=\"%c%d.%.3d%.3d\" ",u8_1, i16_1, i16_2, i16_3); |
342 | fputs_(string, doc->file); |
342 | fputs_(string, doc->file); |
343 | 343 | ||
344 | if(GPSData.Position.Longitude < 0) u8_1 = '-'; |
344 | if(GPSData.Position.Longitude < 0) u8_1 = '-'; |
345 | else u8_1 = '+'; |
345 | else u8_1 = '+'; |
346 | i16_1 = abs((int16_t)(GPSData.Position.Longitude/10000000L)); |
346 | i16_1 = abs((int16_t)(GPSData.Position.Longitude/10000000L)); |
347 | i16_2 = abs((int16_t)((GPSData.Position.Longitude%10000000L)/10000L)); |
347 | i16_2 = abs((int16_t)((GPSData.Position.Longitude%10000000L)/10000L)); |
348 | i16_3 = abs((int16_t)(((GPSData.Position.Longitude%10000000L)%10000L)/10L)); |
348 | i16_3 = abs((int16_t)(((GPSData.Position.Longitude%10000000L)%10000L)/10L)); |
349 | sprintf(string, "<lon=\"%c%d.%.3d%.3d\" ",u8_1, i16_1, i16_2, i16_3); |
349 | sprintf(string, "lon=\"%c%d.%.3d%.3d\" >\r\n",u8_1, i16_1, i16_2, i16_3); |
350 | fputs_(string, doc->file); |
350 | fputs_(string, doc->file); |
351 | 351 | ||
352 | // write <time> tag only at a resolution of one second |
352 | // write <time> tag only at a resolution of one second |
353 | sprintf(string, "<time>%04d-%02d-%02dT%02d:%02d:%02dZ</time>\r\n",SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Hour, SystemTime.Min, SystemTime.Sec); |
353 | sprintf(string, "<time>%04d-%02d-%02dT%02d:%02d:%02dZ</time>\r\n",SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Hour, SystemTime.Min, SystemTime.Sec); |
354 | fputs_(string, doc->file); |
354 | fputs_(string, doc->file); |
355 | // write <sat> tag |
355 | // write <sat> tag |
356 | sprintf(string, "<sat>%d</sat>\r\n", GPSData.NumOfSats); |
356 | sprintf(string, "<sat>%d</sat>\r\n", GPSData.NumOfSats); |
357 | fputs_(string, doc->file); |
357 | fputs_(string, doc->file); |
358 | // todo: add <extensions> tag with additional data to be logged |
358 | // todo: add <extensions> tag with additional data to be logged |
359 | sprintf(string, "<extensions>\r\n"); |
359 | sprintf(string, "<extensions>\r\n"); |
360 | fputs_(string, doc->file); |
360 | fputs_(string, doc->file); |
361 | // Course in deg |
361 | // Course in deg |
362 | i16_1 = (int16_t)(GPSData.Heading/100000L); |
362 | i16_1 = (int16_t)(GPSData.Heading/100000L); |
363 | sprintf(string, "<Course>%03d</Course>\r\n", i16_1); |
363 | sprintf(string, "<Course>%03d</Course>\r\n", i16_1); |
364 | fputs_(string, doc->file); |
364 | fputs_(string, doc->file); |
365 | // Ground Speed in cm/s |
365 | // Ground Speed in cm/s |
366 | sprintf(string, "<GroundSpeed>%d</GroundSpeed>\r\n", (uint16_t)GPSData.Speed_Ground); |
366 | sprintf(string, "<GroundSpeed>%d</GroundSpeed>\r\n", (uint16_t)GPSData.Speed_Ground); |
367 | fputs_(string, doc->file); |
367 | fputs_(string, doc->file); |
368 | // Ubat |
368 | // Ubat |
369 | u8_1 = UBat / 10; |
369 | u8_1 = UBat / 10; |
370 | u8_2 = UBat % 10; |
370 | u8_2 = UBat % 10; |
371 | sprintf(string, "<Voltage>%d.%01d</Voltage>\r\n", u8_1, u8_2); |
371 | sprintf(string, "<Voltage>%d.%01d</Voltage>\r\n", u8_1, u8_2); |
372 | fputs_(string, doc->file); |
372 | fputs_(string, doc->file); |
373 | 373 | ||
374 | // eof extensions |
374 | // eof extensions |
375 | sprintf(string, "</extensions>\r\n"); |
375 | sprintf(string, "</extensions>\r\n"); |
376 | fputs_(string, doc->file); |
376 | fputs_(string, doc->file); |
377 | sprintf(string, "</trkpt>\r\n"); |
377 | sprintf(string, "</trkpt>\r\n"); |
378 | fputs_(string, doc->file); |
378 | fputs_(string, doc->file); |
379 | retvalue = 1; |
379 | retvalue = 1; |
380 | } |
380 | } |
381 | } |
381 | } |
382 | } |
382 | } |
383 | return(retvalue); |
383 | return(retvalue); |
384 | } |
384 | } |
385 | 385 | ||
386 | //________________________________________________________________________________________________________________________________________ |
386 | //________________________________________________________________________________________________________________________________________ |
387 | // Function: u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *) |
387 | // Function: u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *) |
388 | // |
388 | // |
389 | // Description: This function opens and adds gpscoordinates to an GPX-Document. The document will be opened, if not already done |
389 | // Description: This function opens and adds gpscoordinates to an GPX-Document. The document will be opened, if not already done |
390 | // |
390 | // |
391 | // |
391 | // |
392 | // Returnvalue: '1' if an gps coordinate was logged |
392 | // Returnvalue: '1' if an gps coordinate was logged |
393 | //________________________________________________________________________________________________________________________________________ |
393 | //________________________________________________________________________________________________________________________________________ |
394 | 394 | ||
395 | uint8_t GPX_LoggGPSCoordinates(GPX_Document_t *doc) |
395 | uint8_t GPX_LoggGPSCoordinates(GPX_Document_t *doc) |
396 | { |
396 | { |
397 | uint8_t retval = 0; |
397 | uint8_t retval = 0; |
398 | while(doc->state != GPX_DOC_TRACKSEGMENT_OPENED) // automatic create document with default filename on the card. |
398 | while(doc->state != GPX_DOC_TRACKSEGMENT_OPENED) // automatic create document with default filename on the card. |
399 | { |
399 | { |
400 | switch(doc->state) |
400 | switch(doc->state) |
401 | { |
401 | { |
402 | case GPX_DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically |
402 | case GPX_DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically |
403 | retval = GPX_DocumentOpen("default.gpx",doc); // open the gpx-document with a standardname. |
403 | retval = GPX_DocumentOpen("default.gpx",doc); // open the gpx-document with a standardname. |
404 | break; |
404 | break; |
405 | 405 | ||
406 | case GPX_DOC_OPENED: // if a document has been opened before but no track exists: |
406 | case GPX_DOC_OPENED: // if a document has been opened before but no track exists: |
407 | retval = GPX_TrackBegin(doc); |
407 | retval = GPX_TrackBegin(doc); |
408 | break; |
408 | break; |
409 | 409 | ||
410 | case GPX_DOC_TRACK_OPENED: // add tracksegement to the track |
410 | case GPX_DOC_TRACK_OPENED: // add tracksegement to the track |
411 | retval = GPX_TrackSegmentBegin(doc); |
411 | retval = GPX_TrackSegmentBegin(doc); |
412 | break; |
412 | break; |
413 | 413 | ||
414 | default: |
414 | default: |
415 | retval = 0; |
415 | retval = 0; |
416 | break; |
416 | break; |
417 | 417 | ||
418 | } |
418 | } |
419 | if(retval != 1) return(retval); // stop on error |
419 | if(retval != 1) return(retval); // stop on error |
420 | } |
420 | } |
421 | 421 | ||
422 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) // if the document was opened add coordinates to the document. |
422 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) // if the document was opened add coordinates to the document. |
423 | { |
423 | { |
424 | retval = GPX_TrackSegementAddPoint(doc); // add a track segment point |
424 | retval = GPX_TrackSegementAddPoint(doc); // add a track segment point |
425 | } |
425 | } |
426 | return(retval); |
426 | return(retval); |
427 | } |
427 | } |
428 | 428 | ||
429 | 429 |