Rev 406 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 406 | Rev 420 | ||
---|---|---|---|
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 "spi_slave.h" |
63 | //#include "spi_slave.h" |
64 | #include "main.h" |
64 | #include "main.h" |
65 | #include "uart1.h" |
65 | #include "uart1.h" |
66 | #include "ubx.h" |
66 | #include "ubx.h" |
67 | 67 | ||
68 | //________________________________________________________________________________________________________________________________________ |
68 | //________________________________________________________________________________________________________________________________________ |
69 | // Function: GPX_DocumentInit(GPX_Document_t *) |
69 | // Function: GPX_DocumentInit(GPX_Document_t *) |
70 | // |
70 | // |
71 | // Description: This function initializes the gpx-document for further use. |
71 | // Description: This function initializes the gpx-document for further use. |
72 | // |
72 | // |
73 | // |
73 | // |
74 | // Returnvalue: '1' if document was initialized |
74 | // Returnvalue: '1' if document was initialized |
75 | //________________________________________________________________________________________________________________________________________ |
75 | //________________________________________________________________________________________________________________________________________ |
76 | 76 | ||
77 | uint8_t GPX_DocumentInit(GPX_Document_t *doc) |
77 | uint8_t GPX_DocumentInit(GPX_Document_t *doc) |
78 | { |
78 | { |
79 | if(doc->state != GPX_DOC_CLOSED) GPX_DocumentClose(doc); // close file if it was opened before |
79 | if(doc->state != GPX_DOC_CLOSED) GPX_DocumentClose(doc); // close file if it was opened before |
80 | doc->state = GPX_DOC_CLOSED; // init state of the gpx-document |
80 | doc->state = GPX_DOC_CLOSED; // init state of the gpx-document |
81 | doc->file = NULL; |
81 | doc->file = NULL; |
82 | return(1); |
82 | return(1); |
83 | } |
83 | } |
84 | 84 | ||
85 | //________________________________________________________________________________________________________________________________________ |
85 | //________________________________________________________________________________________________________________________________________ |
86 | // Function: GPX_Document_Open(s8 *name, GPX_Document_t *doc); |
86 | // Function: GPX_Document_Open(s8 *name, GPX_Document_t *doc); |
87 | // |
87 | // |
88 | // Description: This function opens a new gpx-document with the specified name and creates the document header within the file. |
88 | // Description: This function opens a new gpx-document with the specified name and creates the document header within the file. |
89 | // |
89 | // |
90 | // |
90 | // |
91 | // Returnvalue: '1' if the gpx-file could be created. |
91 | // Returnvalue: '1' if the gpx-file could be created. |
92 | //________________________________________________________________________________________________________________________________________ |
92 | //________________________________________________________________________________________________________________________________________ |
93 | 93 | ||
94 | uint8_t GPX_DocumentOpen(int8_t *name, GPX_Document_t *doc) |
94 | uint8_t GPX_DocumentOpen(int8_t *name, GPX_Document_t *doc) |
95 | { |
95 | { |
96 | 96 | ||
97 | uint8_t retvalue = 0; |
97 | uint8_t retvalue = 0; |
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 | fwrite_((void*)GPX_DOCUMENT_HEADER, sizeof(GPX_DOCUMENT_HEADER)-1,1,doc->file);// write the gpx-header to the document. |
107 | fwrite_((void*)GPX_DOCUMENT_HEADER, sizeof(GPX_DOCUMENT_HEADER)-1,1,doc->file);// write the gpx-header to the document. |
108 | } |
108 | } |
109 | 109 | ||
110 | return(retvalue); |
110 | return(retvalue); |
111 | } |
111 | } |
112 | 112 | ||
113 | //________________________________________________________________________________________________________________________________________ |
113 | //________________________________________________________________________________________________________________________________________ |
114 | // Function: DocumentClose(GPX_Document_t *doc); |
114 | // Function: DocumentClose(GPX_Document_t *doc); |
115 | // |
115 | // |
116 | // Description: This function closes the document specified by doc. |
116 | // Description: This function closes the document specified by doc. |
117 | // |
117 | // |
118 | // |
118 | // |
119 | // Returnvalue: '1' if the gpx-file could be closed. |
119 | // Returnvalue: '1' if the gpx-file could be closed. |
120 | //________________________________________________________________________________________________________________________________________ |
120 | //________________________________________________________________________________________________________________________________________ |
121 | 121 | ||
122 | uint8_t GPX_DocumentClose(GPX_Document_t *doc) |
122 | uint8_t GPX_DocumentClose(GPX_Document_t *doc) |
123 | { |
123 | { |
124 | 124 | ||
125 | uint8_t retvalue = 1; |
125 | uint8_t retvalue = 1; |
126 | 126 | ||
127 | if(doc == NULL) return(0); |
127 | if(doc == NULL) return(0); |
128 | 128 | ||
129 | while(doc->state != GPX_DOC_CLOSED) // close linestring, placemark and document before closing the file on the memorycard |
129 | while(doc->state != GPX_DOC_CLOSED) // close linestring, placemark and document before closing the file on the memorycard |
130 | { |
130 | { |
131 | switch(doc->state) |
131 | switch(doc->state) |
132 | { |
132 | { |
133 | case GPX_DOC_TRACKSEGMENT_OPENED: |
133 | case GPX_DOC_TRACKSEGMENT_OPENED: |
134 | GPX_TrackSegmentEnd(doc); // write terminating tag to end tracksegment. |
134 | GPX_TrackSegmentEnd(doc); // write terminating tag to end tracksegment. |
135 | break; |
135 | break; |
136 | 136 | ||
137 | case GPX_DOC_TRACK_OPENED: // write terminating tag to close track. |
137 | case GPX_DOC_TRACK_OPENED: // write terminating tag to close track. |
138 | GPX_TrackEnd(doc); |
138 | GPX_TrackEnd(doc); |
139 | break; |
139 | break; |
140 | 140 | ||
141 | case GPX_DOC_OPENED: // close the file on the memorycard |
141 | case GPX_DOC_OPENED: // close the file on the memorycard |
142 | if(doc->file != NULL) |
142 | if(doc->file != NULL) |
143 | { |
143 | { |
144 | fwrite_((void*)GPX_DOCUMENT_FOOTER, sizeof(GPX_DOCUMENT_FOOTER)-1,1,doc->file); // write the gpx-footer to the document. |
144 | fwrite_((void*)GPX_DOCUMENT_FOOTER, sizeof(GPX_DOCUMENT_FOOTER)-1,1,doc->file); // write the gpx-footer to the document. |
145 | fclose_(doc->file); |
145 | fclose_(doc->file); |
146 | retvalue = 1; |
146 | retvalue = 1; |
147 | } |
147 | } |
148 | doc->state = GPX_DOC_CLOSED; |
148 | doc->state = GPX_DOC_CLOSED; |
149 | break; |
149 | break; |
150 | 150 | ||
151 | default: |
151 | default: |
152 | doc->state = GPX_DOC_CLOSED; |
152 | doc->state = GPX_DOC_CLOSED; |
153 | break; |
153 | break; |
154 | } |
154 | } |
155 | } |
155 | } |
156 | return(retvalue); |
156 | return(retvalue); |
157 | } |
157 | } |
158 | 158 | ||
159 | //________________________________________________________________________________________________________________________________________ |
159 | //________________________________________________________________________________________________________________________________________ |
160 | // Function: u8 GPX_TrackBegin(GPX_Document_t); |
160 | // Function: u8 GPX_TrackBegin(GPX_Document_t); |
161 | // |
161 | // |
162 | // Description: This function adds a track to the document. |
162 | // Description: This function adds a track to the document. |
163 | // |
163 | // |
164 | // |
164 | // |
165 | // Returnvalue: '1' if the track could be opened |
165 | // Returnvalue: '1' if the track could be opened |
166 | //________________________________________________________________________________________________________________________________________ |
166 | //________________________________________________________________________________________________________________________________________ |
167 | 167 | ||
168 | uint8_t GPX_TrackBegin(GPX_Document_t *doc) |
168 | uint8_t GPX_TrackBegin(GPX_Document_t *doc) |
169 | { |
169 | { |
170 | 170 | ||
171 | uint8_t retvalue = 0; |
171 | uint8_t retvalue = 0; |
172 | if(doc->state == GPX_DOC_OPENED) |
172 | if(doc->state == GPX_DOC_OPENED) |
173 | { |
173 | { |
174 | if(doc->file != NULL) |
174 | if(doc->file != NULL) |
175 | { |
175 | { |
176 | doc->state = GPX_DOC_TRACK_OPENED; |
176 | doc->state = GPX_DOC_TRACK_OPENED; |
177 | retvalue = 1; |
177 | retvalue = 1; |
178 | fwrite_((void*)GPX_TRACK_HEADER, sizeof(GPX_TRACK_HEADER)-1,1,doc->file); |
178 | fwrite_((void*)GPX_TRACK_HEADER, sizeof(GPX_TRACK_HEADER)-1,1,doc->file); |
179 | } |
179 | } |
180 | } |
180 | } |
181 | return(retvalue); |
181 | return(retvalue); |
182 | } |
182 | } |
183 | 183 | ||
184 | //________________________________________________________________________________________________________________________________________ |
184 | //________________________________________________________________________________________________________________________________________ |
185 | // Function: u8 GPX_TrackEnd(KML_Document_t *doc) |
185 | // Function: u8 GPX_TrackEnd(KML_Document_t *doc) |
186 | // |
186 | // |
187 | // Description: This function ends the track opened before. |
187 | // Description: This function ends the track opened before. |
188 | // |
188 | // |
189 | // |
189 | // |
190 | // Returnvalue: 1' if the track could be closed |
190 | // Returnvalue: 1' if the track could be closed |
191 | //________________________________________________________________________________________________________________________________________ |
191 | //________________________________________________________________________________________________________________________________________ |
192 | 192 | ||
193 | uint8_t GPX_TrackEnd(GPX_Document_t *doc) |
193 | uint8_t GPX_TrackEnd(GPX_Document_t *doc) |
194 | { |
194 | { |
195 | 195 | ||
196 | uint8_t retvalue = 0; |
196 | uint8_t retvalue = 0; |
197 | 197 | ||
198 | if(doc->state == GPX_DOC_TRACK_OPENED) |
198 | if(doc->state == GPX_DOC_TRACK_OPENED) |
199 | { |
199 | { |
200 | if(doc->file != NULL) |
200 | if(doc->file != NULL) |
201 | { |
201 | { |
202 | doc->state = GPX_DOC_OPENED; |
202 | doc->state = GPX_DOC_OPENED; |
203 | fwrite_((void*)GPX_TRACK_FOOTER, sizeof(GPX_TRACK_FOOTER)-1,1,doc->file); |
203 | fwrite_((void*)GPX_TRACK_FOOTER, sizeof(GPX_TRACK_FOOTER)-1,1,doc->file); |
204 | retvalue = 1; |
204 | retvalue = 1; |
205 | } |
205 | } |
206 | } |
206 | } |
207 | 207 | ||
208 | return(retvalue); |
208 | return(retvalue); |
209 | } |
209 | } |
210 | 210 | ||
211 | //________________________________________________________________________________________________________________________________________ |
211 | //________________________________________________________________________________________________________________________________________ |
212 | // Function: u8 GPX_TrackSegmentBegin(GPX_Document_t *doc); |
212 | // Function: u8 GPX_TrackSegmentBegin(GPX_Document_t *doc); |
213 | // |
213 | // |
214 | // Description: This function starts a track segment. |
214 | // Description: This function starts a track segment. |
215 | // |
215 | // |
216 | // |
216 | // |
217 | // Returnvalue: '1' if the track segement could be started |
217 | // Returnvalue: '1' if the track segement could be started |
218 | //________________________________________________________________________________________________________________________________________ |
218 | //________________________________________________________________________________________________________________________________________ |
219 | 219 | ||
220 | uint8_t GPX_TrackSegmentBegin(GPX_Document_t *doc) |
220 | uint8_t GPX_TrackSegmentBegin(GPX_Document_t *doc) |
221 | { |
221 | { |
222 | 222 | ||
223 | uint8_t retvalue = 0; |
223 | uint8_t retvalue = 0; |
224 | 224 | ||
225 | if(doc->state == GPX_DOC_TRACK_OPENED) |
225 | if(doc->state == GPX_DOC_TRACK_OPENED) |
226 | { |
226 | { |
227 | if(doc->file != NULL) |
227 | if(doc->file != NULL) |
228 | { |
228 | { |
229 | doc->state = GPX_DOC_TRACKSEGMENT_OPENED; |
229 | doc->state = GPX_DOC_TRACKSEGMENT_OPENED; |
230 | fwrite_((void*)GPX_TRACKSEGMENT_HEADER, sizeof(GPX_TRACKSEGMENT_HEADER)-1,1,doc->file); |
230 | fwrite_((void*)GPX_TRACKSEGMENT_HEADER, sizeof(GPX_TRACKSEGMENT_HEADER)-1,1,doc->file); |
231 | retvalue = 1; |
231 | retvalue = 1; |
232 | } |
232 | } |
233 | } |
233 | } |
234 | return(retvalue); |
234 | return(retvalue); |
235 | } |
235 | } |
236 | 236 | ||
237 | //________________________________________________________________________________________________________________________________________ |
237 | //________________________________________________________________________________________________________________________________________ |
238 | // Function: u8 GPX_TrackSegmentEnd(GPX_Document_t *doc); |
238 | // Function: u8 GPX_TrackSegmentEnd(GPX_Document_t *doc); |
239 | // |
239 | // |
240 | // Description: This function ends the tracksegment opened before. |
240 | // Description: This function ends the tracksegment opened before. |
241 | // |
241 | // |
242 | // |
242 | // |
243 | // Returnvalue: '1' if the track segment could be terminated |
243 | // Returnvalue: '1' if the track segment could be terminated |
244 | //________________________________________________________________________________________________________________________________________ |
244 | //________________________________________________________________________________________________________________________________________ |
245 | 245 | ||
246 | uint8_t GPX_TrackSegmentEnd(GPX_Document_t *doc) |
246 | uint8_t GPX_TrackSegmentEnd(GPX_Document_t *doc) |
247 | { |
247 | { |
248 | 248 | ||
249 | uint8_t retvalue = 0; |
249 | uint8_t retvalue = 0; |
250 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) |
250 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) |
251 | { |
251 | { |
252 | if(doc->file != NULL) |
252 | if(doc->file != NULL) |
253 | { |
253 | { |
254 | doc->state = GPX_DOC_TRACK_OPENED; |
254 | doc->state = GPX_DOC_TRACK_OPENED; |
255 | fwrite_((void*)GPX_TRACKSEGMENT_FOOTER, sizeof(GPX_TRACKSEGMENT_FOOTER)-1,1,doc->file); |
255 | fwrite_((void*)GPX_TRACKSEGMENT_FOOTER, sizeof(GPX_TRACKSEGMENT_FOOTER)-1,1,doc->file); |
256 | retvalue = 1; |
256 | retvalue = 1; |
257 | } |
257 | } |
258 | } |
258 | } |
259 | return(retvalue); |
259 | return(retvalue); |
260 | } |
260 | } |
261 | 261 | ||
262 | //________________________________________________________________________________________________________________________________________ |
262 | //________________________________________________________________________________________________________________________________________ |
263 | // Function: u8 GPX_TrackSegementAddPoint(GPS_Pos_t * pGPS_Position ,GPX_Document_t *doc); |
263 | // Function: u8 GPX_TrackSegementAddPoint(GPS_Pos_t * pGPS_Position ,GPX_Document_t *doc); |
264 | // |
264 | // |
265 | // Description: This function adds a pointof a track segement to the specified document. |
265 | // Description: This function adds a pointof a track segement to the specified document. |
266 | // |
266 | // |
267 | // |
267 | // |
268 | // Returnvalue: '1' if a point was added |
268 | // Returnvalue: '1' if a point was added |
269 | //________________________________________________________________________________________________________________________________________ |
269 | //________________________________________________________________________________________________________________________________________ |
270 | 270 | ||
271 | uint8_t GPX_TrackSegementAddPoint(GPX_Document_t *doc) |
271 | uint8_t GPX_TrackSegementAddPoint(GPX_Document_t *doc) |
272 | { |
272 | { |
273 | 273 | ||
274 | uint8_t retvalue = 0; |
274 | uint8_t retvalue = 0; |
275 | int8_t string[50]; |
275 | int8_t string[50]; |
276 | 276 | ||
277 | if(doc == NULL) return(0); |
277 | if(doc == NULL) return(0); |
278 | 278 | ||
279 | // if((GPSData.Position.Status != INVALID) && (GPS_HomePosition.Status != INVALID)) |
279 | if(GPSData.Position.Status != INVALID) |
280 | { |
280 | { |
281 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) |
281 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) |
282 | { |
282 | { |
283 | if(doc->file != NULL) |
283 | if(doc->file != NULL) |
284 | { |
284 | { |
285 | int32_t i32_1, i32_2; |
285 | int16_t i16_1, i16_2, i16_3; |
286 | int16_t i16_1; |
- | |
287 | uint8_t u8_1, u8_2; |
286 | uint8_t u8_1, u8_2; |
288 | // write <trkpt> tag |
287 | // write <trkpt> tag |
289 | if(GPSData.Position.Latitude < 0) u8_1 = '-'; |
288 | if(GPSData.Position.Latitude < 0) u8_1 = '-'; |
290 | else u8_1 = '+'; |
289 | else u8_1 = '+'; |
291 | i32_1 = abs(GPSData.Position.Latitude)/10000000L; |
290 | i16_1 = abs((int16_t)(GPSData.Position.Latitude/10000000L)); |
292 | i32_2 = abs(GPSData.Position.Latitude)%10000000L; |
291 | i16_2 = abs((int16_t)((GPSData.Position.Latitude%10000000L)/10000L)); |
- | 292 | i16_3 = abs((int16_t)(((GPSData.Position.Latitude%10000000L)%10000L)/10L)); |
|
293 | sprintf(string, "<trkpt lat=\"%c%ld.%07ld\" ",u8_1, i32_1, i32_2); |
293 | sprintf(string, "<trkpt lat=\"%c%d.%.3d%.3d\" ",u8_1, i16_1, i16_2, i16_3); |
294 | fputs_(string, doc->file); |
294 | fputs_(string, doc->file); |
- | 295 | ||
295 | if(GPSData.Position.Longitude < 0) u8_1 = '-'; |
296 | if(GPSData.Position.Longitude < 0) u8_1 = '-'; |
296 | else u8_1 = '+'; |
297 | else u8_1 = '+'; |
297 | i32_1 = abs(GPSData.Position.Longitude)/10000000L; |
298 | i16_1 = abs((int16_t)(GPSData.Position.Longitude/10000000L)); |
298 | i32_2 = abs(GPSData.Position.Longitude)%10000000L; |
299 | i16_2 = abs((int16_t)((GPSData.Position.Longitude%10000000L)/10000L)); |
- | 300 | i16_3 = abs((int16_t)(((GPSData.Position.Longitude%10000000L)%10000L)/10L)); |
|
299 | sprintf(string, "lon=\"%c%ld.%07ld\">\r\n",u8_1, i32_1, i32_2); |
301 | sprintf(string, "<lon=\"%c%d.%.3d%.3d\" ",u8_1, i16_1, i16_2, i16_3); |
300 | fputs_(string, doc->file); |
302 | fputs_(string, doc->file); |
- | 303 | ||
301 | // write <time> tag only at a resolution of one second |
304 | // write <time> tag only at a resolution of one second |
302 | sprintf(string, "<time>%04d-%02d-%02dT%02d:%02d:%02dZ</time>\r\n",SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Hour, SystemTime.Min, SystemTime.Sec); |
305 | sprintf(string, "<time>%04d-%02d-%02dT%02d:%02d:%02dZ</time>\r\n",SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Hour, SystemTime.Min, SystemTime.Sec); |
303 | fputs_(string, doc->file); |
306 | fputs_(string, doc->file); |
304 | // write <sat> tag |
307 | // write <sat> tag |
305 | sprintf(string, "<sat>%d</sat>\r\n", GPSData.NumOfSats); |
308 | sprintf(string, "<sat>%d</sat>\r\n", GPSData.NumOfSats); |
306 | fputs_(string, doc->file); |
309 | fputs_(string, doc->file); |
307 | // todo: add <extensions> tag with additional data to be logged |
310 | // todo: add <extensions> tag with additional data to be logged |
308 | sprintf(string, "<extensions>\r\n"); |
311 | sprintf(string, "<extensions>\r\n"); |
309 | fputs_(string, doc->file); |
312 | fputs_(string, doc->file); |
310 | // Course in deg |
313 | // Course in deg |
311 | i16_1 = GPSData.Heading/100000L; |
314 | i16_1 = (int16_t)(GPSData.Heading/100000L); |
312 | sprintf(string, "<Course>%03d</Course>\r\n", i16_1); |
315 | sprintf(string, "<Course>%03d</Course>\r\n", i16_1); |
313 | fputs_(string, doc->file); |
316 | fputs_(string, doc->file); |
314 | // Ground Speed in cm/s |
317 | // Ground Speed in cm/s |
315 | sprintf(string, "<GroundSpeed>%d</GroundSpeed>\r\n", GPSData.Speed_Ground); |
318 | sprintf(string, "<GroundSpeed>%d</GroundSpeed>\r\n", (uint16_t)GPSData.Speed_Ground); |
316 | fputs_(string, doc->file); |
319 | fputs_(string, doc->file); |
317 | // Ubat |
320 | // Ubat |
318 | u8_1 = UBat / 10; |
321 | u8_1 = UBat / 10; |
319 | u8_2 = UBat % 10; |
322 | u8_2 = UBat % 10; |
320 | sprintf(string, "<Voltage>%d.%01d</Voltage>\r\n", u8_1, u8_2); |
323 | sprintf(string, "<Voltage>%d.%01d</Voltage>\r\n", u8_1, u8_2); |
321 | fputs_(string, doc->file); |
324 | fputs_(string, doc->file); |
322 | 325 | ||
323 | // eof extensions |
326 | // eof extensions |
324 | sprintf(string, "</extensions>\r\n"); |
327 | sprintf(string, "</extensions>\r\n"); |
325 | fputs_(string, doc->file); |
328 | fputs_(string, doc->file); |
326 | sprintf(string, "</trkpt>\r\n"); |
329 | sprintf(string, "</trkpt>\r\n"); |
327 | fputs_(string, doc->file); |
330 | fputs_(string, doc->file); |
328 | retvalue = 1; |
331 | retvalue = 1; |
329 | } |
332 | } |
330 | } |
333 | } |
331 | } |
334 | } |
332 | return(retvalue); |
335 | return(retvalue); |
333 | } |
336 | } |
334 | 337 | ||
335 | //________________________________________________________________________________________________________________________________________ |
338 | //________________________________________________________________________________________________________________________________________ |
336 | // Function: u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *) |
339 | // Function: u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *) |
337 | // |
340 | // |
338 | // Description: This function opens and adds gpscoordinates to an GPX-Document. The document will be opened, if not already done |
341 | // Description: This function opens and adds gpscoordinates to an GPX-Document. The document will be opened, if not already done |
339 | // |
342 | // |
340 | // |
343 | // |
341 | // Returnvalue: '1' if an gps coordinate was logged |
344 | // Returnvalue: '1' if an gps coordinate was logged |
342 | //________________________________________________________________________________________________________________________________________ |
345 | //________________________________________________________________________________________________________________________________________ |
343 | 346 | ||
344 | uint8_t GPX_LoggGPSCoordinates(GPX_Document_t *doc) |
347 | uint8_t GPX_LoggGPSCoordinates(GPX_Document_t *doc) |
345 | { |
348 | { |
346 | uint8_t retval = 0; |
349 | uint8_t retval = 0; |
347 | while(doc->state != GPX_DOC_TRACKSEGMENT_OPENED) // automatic create document with default filename on the card. |
350 | while(doc->state != GPX_DOC_TRACKSEGMENT_OPENED) // automatic create document with default filename on the card. |
348 | { |
351 | { |
349 | switch(doc->state) |
352 | switch(doc->state) |
350 | { |
353 | { |
351 | case GPX_DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically |
354 | case GPX_DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically |
352 | retval = GPX_DocumentOpen("default.gpx",doc); // open the gpx-document with a standardname. |
355 | retval = GPX_DocumentOpen("default.gpx",doc); // open the gpx-document with a standardname. |
353 | break; |
356 | break; |
354 | 357 | ||
355 | case GPX_DOC_OPENED: // if a document has been opened before but no track exists: |
358 | case GPX_DOC_OPENED: // if a document has been opened before but no track exists: |
356 | retval = GPX_TrackBegin(doc); |
359 | retval = GPX_TrackBegin(doc); |
357 | break; |
360 | break; |
358 | 361 | ||
359 | case GPX_DOC_TRACK_OPENED: // add tracksegement to the track |
362 | case GPX_DOC_TRACK_OPENED: // add tracksegement to the track |
360 | retval = GPX_TrackSegmentBegin(doc); |
363 | retval = GPX_TrackSegmentBegin(doc); |
361 | break; |
364 | break; |
362 | 365 | ||
363 | default: |
366 | default: |
364 | retval = 0; |
367 | retval = 0; |
365 | break; |
368 | break; |
366 | 369 | ||
367 | } |
370 | } |
368 | if(retval != 1) return(retval); // stop on error |
371 | if(retval != 1) return(retval); // stop on error |
369 | } |
372 | } |
370 | 373 | ||
371 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) // if the document was opened add coordinates to the document. |
374 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) // if the document was opened add coordinates to the document. |
372 | { |
375 | { |
373 | retval = GPX_TrackSegementAddPoint(doc); // add a track segment point |
376 | retval = GPX_TrackSegementAddPoint(doc); // add a track segment point |
374 | } |
377 | } |
375 | return(retval); |
378 | return(retval); |
376 | } |
379 | } |
377 | 380 | ||
378 | 381 |