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