Rev 324 | Rev 339 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 324 | Rev 338 | ||
---|---|---|---|
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 / NON-COMMERCIAL USE ONLY |
6 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
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 oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
28 | // + Die Portierung oder Nutzung 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 the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
43 | // + * porting the sources to other systems or using the software on other systems (except 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 "timer1.h" |
62 | #include "timer1.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 "compass.h" |
|
- | 67 | #include "analog.h" |
|
- | 68 | #include "main.h" |
|
- | 69 | #include "led.h" |
|
66 | 70 | ||
67 | //________________________________________________________________________________________________________________________________________ |
71 | //________________________________________________________________________________________________________________________________________ |
68 | // Function: GPX_DocumentInit(GPX_Document_t *) |
72 | // Function: GPX_DocumentInit(GPX_Document_t *) |
69 | // |
73 | // |
70 | // Description: This function initializes the gpx-document for further use. |
74 | // Description: This function initializes the gpx-document for further use. |
71 | // |
75 | // |
72 | // |
76 | // |
73 | // Returnvalue: '1' if document was initialized |
77 | // Returnvalue: '1' if document was initialized |
74 | //________________________________________________________________________________________________________________________________________ |
78 | //________________________________________________________________________________________________________________________________________ |
75 | 79 | ||
76 | u8 GPX_DocumentInit(GPX_Document_t *doc) |
80 | u8 GPX_DocumentInit(GPX_Document_t *doc) |
77 | { |
81 | { |
78 | if(doc->state != GPX_DOC_CLOSED) GPX_DocumentClose(doc); // close file if it was opened before |
82 | if(doc->state != GPX_DOC_CLOSED) GPX_DocumentClose(doc); // close file if it was opened before |
79 | doc->state = GPX_DOC_CLOSED; // init state of the gpx-document |
83 | doc->state = GPX_DOC_CLOSED; // init state of the gpx-document |
80 | doc->file = NULL; |
84 | doc->file = NULL; |
81 | return(1); |
85 | return(1); |
82 | } |
86 | } |
83 | 87 | ||
84 | //________________________________________________________________________________________________________________________________________ |
88 | //________________________________________________________________________________________________________________________________________ |
85 | // Function: GPX_Document_Open(s8 *name, GPX_Document_t *doc); |
89 | // Function: GPX_Document_Open(s8 *name, GPX_Document_t *doc); |
86 | // |
90 | // |
87 | // Description: This function opens a new gpx-document with the specified name and creates the document header within the file. |
91 | // Description: This function opens a new gpx-document with the specified name and creates the document header within the file. |
88 | // |
92 | // |
89 | // |
93 | // |
90 | // Returnvalue: '1' if the gpx-file could be created. |
94 | // Returnvalue: '1' if the gpx-file could be created. |
91 | //________________________________________________________________________________________________________________________________________ |
95 | //________________________________________________________________________________________________________________________________________ |
- | 96 | ||
92 | 97 | ||
93 | u8 GPX_DocumentOpen(s8 *name, GPX_Document_t *doc) |
98 | u8 GPX_DocumentOpen(s8 *name, GPX_Document_t *doc) |
94 | { |
99 | { |
95 | 100 | s8 string[60]; |
|
96 | u8 retvalue = 0; |
101 | u8 retvalue = 0; |
97 | 102 | ||
98 | if(doc == NULL) return(0); |
103 | if(doc == NULL) return(0); |
99 | GPX_DocumentInit(doc); // intialize the document with resetvalues |
104 | GPX_DocumentInit(doc); // intialize the document with resetvalues |
100 | doc->file = fopen_(name,'a'); // open a new file with the specified filename on the memorycard. |
105 | doc->file = fopen_(name,'a'); // open a new file with the specified filename on the memorycard. |
101 | 106 | ||
102 | if(doc->file != NULL) // could the file be opened? |
107 | if(doc->file != NULL) // could the file be opened? |
103 | { |
108 | { |
104 | retvalue = 1; // the document could be created on the drive. |
109 | retvalue = 1; // the document could be created on the drive. |
105 | doc->state = GPX_DOC_OPENED; // change document state to opened. At next a placemark has to be opened. |
110 | doc->state = GPX_DOC_OPENED; // change document state to opened. At next a placemark has to be opened. |
106 | fwrite_((void*)GPX_DOCUMENT_HEADER, sizeof(GPX_DOCUMENT_HEADER)-1,1,doc->file);// write the gpx-header to the document. |
111 | fwrite_((void*)GPX_DOCUMENT_HEADER1, sizeof(GPX_DOCUMENT_HEADER1)-1,1,doc->file);// write the gpx-header to the document. |
- | 112 | sprintf(string, "<desc>FC HW:%d.%d SW:%d.%d%c & NC HW:%d.%d SW:%d.%d%c</desc>\r\n", FC_Version.Hardware/10,FC_Version.Hardware%10, FC_Version.Major, FC_Version.Minor, 'a'+FC_Version.Patch, Version_HW/10, Version_HW%10, VERSION_MAJOR, VERSION_MINOR, 'a'+ VERSION_PATCH); |
|
- | 113 | fputs_(string, doc->file); |
|
- | 114 | fwrite_((void*)GPX_DOCUMENT_HEADER2, sizeof(GPX_DOCUMENT_HEADER2)-1,1,doc->file);// write the gpx-header to the document. |
|
107 | } |
115 | } |
108 | - | ||
- | 116 | Logging_FCStatusFlags1 = 0; |
|
- | 117 | Logging_FCStatusFlags2 = 0; |
|
109 | return(retvalue); |
118 | return(retvalue); |
110 | } |
119 | } |
111 | 120 | ||
112 | //________________________________________________________________________________________________________________________________________ |
121 | //________________________________________________________________________________________________________________________________________ |
113 | // Function: DocumentClose(GPX_Document_t *doc); |
122 | // Function: DocumentClose(GPX_Document_t *doc); |
114 | // |
123 | // |
115 | // Description: This function closes the document specified by doc. |
124 | // Description: This function closes the document specified by doc. |
116 | // |
125 | // |
117 | // |
126 | // |
118 | // Returnvalue: '1' if the gpx-file could be closed. |
127 | // Returnvalue: '1' if the gpx-file could be closed. |
119 | //________________________________________________________________________________________________________________________________________ |
128 | //________________________________________________________________________________________________________________________________________ |
120 | 129 | ||
121 | u8 GPX_DocumentClose(GPX_Document_t *doc) |
130 | u8 GPX_DocumentClose(GPX_Document_t *doc) |
122 | { |
131 | { |
123 | 132 | ||
124 | u8 retvalue = 1; |
133 | u8 retvalue = 1; |
125 | 134 | ||
126 | if(doc == NULL) return(0); |
135 | if(doc == NULL) return(0); |
127 | 136 | ||
128 | 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 |
129 | { |
138 | { |
130 | switch(doc->state) |
139 | switch(doc->state) |
131 | { |
140 | { |
132 | case GPX_DOC_TRACKSEGMENT_OPENED: |
141 | case GPX_DOC_TRACKSEGMENT_OPENED: |
133 | GPX_TrackSegmentEnd(doc); // write terminating tag to end tracksegment. |
142 | GPX_TrackSegmentEnd(doc); // write terminating tag to end tracksegment. |
134 | break; |
143 | break; |
135 | 144 | ||
136 | case GPX_DOC_TRACK_OPENED: // write terminating tag to close track. |
145 | case GPX_DOC_TRACK_OPENED: // write terminating tag to close track. |
137 | GPX_TrackEnd(doc); |
146 | GPX_TrackEnd(doc); |
138 | break; |
147 | break; |
139 | 148 | ||
140 | case GPX_DOC_OPENED: // close the file on the memorycard |
149 | case GPX_DOC_OPENED: // close the file on the memorycard |
141 | if(doc->file != NULL) |
150 | if(doc->file != NULL) |
142 | { |
151 | { |
143 | fwrite_((void*)GPX_DOCUMENT_FOOTER, sizeof(GPX_DOCUMENT_FOOTER)-1,1,doc->file); // write the gpx-footer to the document. |
152 | fwrite_((void*)GPX_DOCUMENT_FOOTER, sizeof(GPX_DOCUMENT_FOOTER)-1,1,doc->file); // write the gpx-footer to the document. |
144 | fclose_(doc->file); |
153 | fclose_(doc->file); |
145 | retvalue = 1; |
154 | retvalue = 1; |
146 | } |
155 | } |
147 | doc->state = GPX_DOC_CLOSED; |
156 | doc->state = GPX_DOC_CLOSED; |
148 | break; |
157 | break; |
149 | 158 | ||
150 | default: |
159 | default: |
151 | doc->state = GPX_DOC_CLOSED; |
160 | doc->state = GPX_DOC_CLOSED; |
152 | break; |
161 | break; |
153 | } |
162 | } |
154 | } |
163 | } |
155 | return(retvalue); |
164 | return(retvalue); |
156 | } |
165 | } |
- | 166 | ||
- | 167 | ||
157 | 168 | ||
158 | //________________________________________________________________________________________________________________________________________ |
169 | //________________________________________________________________________________________________________________________________________ |
159 | // Function: u8 GPX_TrackBegin(GPX_Document_t); |
170 | // Function: u8 GPX_TrackBegin(GPX_Document_t); |
160 | // |
171 | // |
161 | // Description: This function adds a track to the document. |
172 | // Description: This function adds a track to the document. |
162 | // |
173 | // |
163 | // |
174 | // |
164 | // Returnvalue: '1' if the track could be opened |
175 | // Returnvalue: '1' if the track could be opened |
165 | //________________________________________________________________________________________________________________________________________ |
176 | //________________________________________________________________________________________________________________________________________ |
166 | 177 | ||
167 | u8 GPX_TrackBegin(GPX_Document_t *doc) |
178 | u8 GPX_TrackBegin(GPX_Document_t *doc) |
168 | { |
179 | { |
169 | 180 | ||
170 | u8 retvalue = 0; |
181 | u8 retvalue = 0; |
171 | if(doc->state == GPX_DOC_OPENED) |
182 | if(doc->state == GPX_DOC_OPENED) |
172 | { |
183 | { |
173 | if(doc->file != NULL) |
184 | if(doc->file != NULL) |
174 | { |
185 | { |
175 | doc->state = GPX_DOC_TRACK_OPENED; |
186 | doc->state = GPX_DOC_TRACK_OPENED; |
176 | retvalue = 1; |
187 | retvalue = 1; |
177 | fwrite_((void*)GPX_TRACK_HEADER, sizeof(GPX_TRACK_HEADER)-1,1,doc->file); |
188 | fwrite_((void*)GPX_TRACK_HEADER, sizeof(GPX_TRACK_HEADER)-1,1,doc->file); |
178 | } |
189 | } |
179 | } |
190 | } |
180 | return(retvalue); |
191 | return(retvalue); |
181 | } |
192 | } |
- | 193 | ||
182 | 194 | ||
183 | //________________________________________________________________________________________________________________________________________ |
195 | //________________________________________________________________________________________________________________________________________ |
184 | // Function: u8 GPX_TrackEnd(KML_Document_t *doc) |
196 | // Function: u8 GPX_TrackEnd(KML_Document_t *doc) |
185 | // |
197 | // |
186 | // Description: This function ends the track opened before. |
198 | // Description: This function ends the track opened before. |
187 | // |
199 | // |
188 | // |
200 | // |
189 | // Returnvalue: 1' if the track could be closed |
201 | // Returnvalue: 1' if the track could be closed |
190 | //________________________________________________________________________________________________________________________________________ |
202 | //________________________________________________________________________________________________________________________________________ |
191 | 203 | ||
192 | u8 GPX_TrackEnd(GPX_Document_t *doc) |
204 | u8 GPX_TrackEnd(GPX_Document_t *doc) |
193 | { |
205 | { |
194 | 206 | ||
195 | u8 retvalue = 0; |
207 | u8 retvalue = 0; |
196 | 208 | ||
197 | if(doc->state == GPX_DOC_TRACK_OPENED) |
209 | if(doc->state == GPX_DOC_TRACK_OPENED) |
198 | { |
210 | { |
199 | if(doc->file != NULL) |
211 | if(doc->file != NULL) |
200 | { |
212 | { |
201 | doc->state = GPX_DOC_OPENED; |
213 | doc->state = GPX_DOC_OPENED; |
202 | fwrite_((void*)GPX_TRACK_FOOTER, sizeof(GPX_TRACK_FOOTER)-1,1,doc->file); |
214 | fwrite_((void*)GPX_TRACK_FOOTER, sizeof(GPX_TRACK_FOOTER)-1,1,doc->file); |
203 | retvalue = 1; |
215 | retvalue = 1; |
204 | } |
216 | } |
205 | } |
217 | } |
206 | 218 | ||
207 | return(retvalue); |
219 | return(retvalue); |
208 | } |
220 | } |
209 | 221 | ||
210 | //________________________________________________________________________________________________________________________________________ |
222 | //________________________________________________________________________________________________________________________________________ |
211 | // Function: u8 GPX_TrackSegmentBegin(GPX_Document_t *doc); |
223 | // Function: u8 GPX_TrackSegmentBegin(GPX_Document_t *doc); |
212 | // |
224 | // |
213 | // Description: This function starts a track segment. |
225 | // Description: This function starts a track segment. |
214 | // |
226 | // |
215 | // |
227 | // |
216 | // Returnvalue: '1' if the track segement could be started |
228 | // Returnvalue: '1' if the track segement could be started |
217 | //________________________________________________________________________________________________________________________________________ |
229 | //________________________________________________________________________________________________________________________________________ |
218 | 230 | ||
219 | u8 GPX_TrackSegmentBegin(GPX_Document_t *doc) |
231 | u8 GPX_TrackSegmentBegin(GPX_Document_t *doc) |
220 | { |
232 | { |
221 | 233 | ||
222 | u8 retvalue = 0; |
234 | u8 retvalue = 0; |
223 | 235 | ||
224 | if(doc->state == GPX_DOC_TRACK_OPENED) |
236 | if(doc->state == GPX_DOC_TRACK_OPENED) |
225 | { |
237 | { |
226 | if(doc->file != NULL) |
238 | if(doc->file != NULL) |
227 | { |
239 | { |
228 | doc->state = GPX_DOC_TRACKSEGMENT_OPENED; |
240 | doc->state = GPX_DOC_TRACKSEGMENT_OPENED; |
229 | fwrite_((void*)GPX_TRACKSEGMENT_HEADER, sizeof(GPX_TRACKSEGMENT_HEADER)-1,1,doc->file); |
241 | fwrite_((void*)GPX_TRACKSEGMENT_HEADER, sizeof(GPX_TRACKSEGMENT_HEADER)-1,1,doc->file); |
230 | retvalue = 1; |
242 | retvalue = 1; |
231 | } |
243 | } |
232 | } |
244 | } |
233 | return(retvalue); |
245 | return(retvalue); |
234 | } |
246 | } |
235 | 247 | ||
236 | //________________________________________________________________________________________________________________________________________ |
248 | //________________________________________________________________________________________________________________________________________ |
237 | // Function: u8 GPX_TrackSegmentEnd(GPX_Document_t *doc); |
249 | // Function: u8 GPX_TrackSegmentEnd(GPX_Document_t *doc); |
238 | // |
250 | // |
239 | // Description: This function ends the tracksegment opened before. |
251 | // Description: This function ends the tracksegment opened before. |
240 | // |
252 | // |
241 | // |
253 | // |
242 | // Returnvalue: '1' if the track segment could be terminated |
254 | // Returnvalue: '1' if the track segment could be terminated |
243 | //________________________________________________________________________________________________________________________________________ |
255 | //________________________________________________________________________________________________________________________________________ |
244 | 256 | ||
245 | u8 GPX_TrackSegmentEnd(GPX_Document_t *doc) |
257 | u8 GPX_TrackSegmentEnd(GPX_Document_t *doc) |
246 | { |
258 | { |
247 | 259 | ||
248 | u8 retvalue = 0; |
260 | u8 retvalue = 0; |
249 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) |
261 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) |
250 | { |
262 | { |
251 | if(doc->file != NULL) |
263 | if(doc->file != NULL) |
252 | { |
264 | { |
253 | doc->state = GPX_DOC_TRACK_OPENED; |
265 | doc->state = GPX_DOC_TRACK_OPENED; |
254 | fwrite_((void*)GPX_TRACKSEGMENT_FOOTER, sizeof(GPX_TRACKSEGMENT_FOOTER)-1,1,doc->file); |
266 | fwrite_((void*)GPX_TRACKSEGMENT_FOOTER, sizeof(GPX_TRACKSEGMENT_FOOTER)-1,1,doc->file); |
255 | retvalue = 1; |
267 | retvalue = 1; |
256 | } |
268 | } |
257 | } |
269 | } |
258 | return(retvalue); |
270 | return(retvalue); |
259 | } |
271 | } |
260 | 272 | ||
261 | //________________________________________________________________________________________________________________________________________ |
273 | //________________________________________________________________________________________________________________________________________ |
262 | // Function: u8 GPX_TrackSegementAddPoint(GPS_Pos_t * pGPS_Position ,GPX_Document_t *doc); |
274 | // Function: u8 GPX_TrackSegementAddPoint(GPS_Pos_t * pGPS_Position ,GPX_Document_t *doc); |
263 | // |
275 | // |
264 | // Description: This function adds a pointof a track segement to the specified document. |
276 | // Description: This function adds a pointof a track segement to the specified document. |
265 | // |
277 | // |
266 | // |
278 | // |
267 | // Returnvalue: '1' if a point was added |
279 | // Returnvalue: '1' if a point was added |
268 | //________________________________________________________________________________________________________________________________________ |
280 | //________________________________________________________________________________________________________________________________________ |
269 | 281 | ||
270 | u8 GPX_TrackSegementAddPoint(GPX_Document_t *doc) |
282 | u8 GPX_TrackSegementAddPoint(GPX_Document_t *doc) |
271 | { |
283 | { |
272 | 284 | ||
273 | u8 retvalue = 0; |
285 | u8 retvalue = 0; |
274 | s8 string[50]; |
286 | s8 string[100]; |
275 | 287 | ||
276 | if(doc == NULL) return(0); |
288 | if(doc == NULL) return(0); |
277 | 289 | ||
278 | if((GPSData.Position.Status != INVALID) && (NaviData.HomePosition.Status != INVALID)) |
290 | if((GPSData.Position.Status != INVALID) && (NaviData.HomePosition.Status != INVALID)) |
279 | { |
291 | { |
280 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) |
292 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) |
281 | { |
293 | { |
282 | if(doc->file != NULL) |
294 | if(doc->file != NULL) |
283 | { |
295 | { |
284 | s32 i32_1, i32_2; |
296 | s32 i32_1, i32_2; |
285 | s16 i16_1; |
297 | s16 i16_1; |
286 | u8 u8_1, u8_2; |
298 | u8 u8_1, u8_2; |
287 | // write <trkpt> tag |
299 | // write <trkpt> tag |
288 | if(GPSData.Position.Latitude < 0) u8_1 = '-'; |
300 | if(GPSData.Position.Latitude < 0) u8_1 = '-'; |
289 | else u8_1 = '+'; |
301 | else u8_1 = '+'; |
290 | i32_1 = abs(GPSData.Position.Latitude)/10000000L; |
302 | i32_1 = abs(GPSData.Position.Latitude)/10000000L; |
291 | i32_2 = abs(GPSData.Position.Latitude)%10000000L; |
303 | i32_2 = abs(GPSData.Position.Latitude)%10000000L; |
292 | sprintf(string, "<trkpt lat=\"%c%ld.%07ld\" ",u8_1, i32_1, i32_2); |
304 | sprintf(string, "<trkpt lat=\"%c%ld.%07ld\" ",u8_1, i32_1, i32_2); |
293 | fputs_(string, doc->file); |
305 | fputs_(string, doc->file); |
294 | if(GPSData.Position.Longitude < 0) u8_1 = '-'; |
306 | if(GPSData.Position.Longitude < 0) u8_1 = '-'; |
295 | else u8_1 = '+'; |
307 | else u8_1 = '+'; |
296 | i32_1 = abs(GPSData.Position.Longitude)/10000000L; |
308 | i32_1 = abs(GPSData.Position.Longitude)/10000000L; |
297 | i32_2 = abs(GPSData.Position.Longitude)%10000000L; |
309 | i32_2 = abs(GPSData.Position.Longitude)%10000000L; |
298 | sprintf(string, "lon=\"%c%ld.%07ld\">\r\n",u8_1, i32_1, i32_2); |
310 | sprintf(string, "lon=\"%c%ld.%07ld\">\r\n",u8_1, i32_1, i32_2); |
299 | fputs_(string, doc->file); |
311 | fputs_(string, doc->file); |
300 | // write <ele> taga |
312 | // write <ele> taga |
301 | i32_2 = GPSData.Position.Altitude - NaviData.HomePosition.Altitude; |
313 | i32_2 = GPSData.Position.Altitude - NaviData.HomePosition.Altitude; |
302 | if(i32_2 < 0) i32_2 = 0; // avoid negative altitudes in log |
314 | if(i32_2 < 0) i32_2 = 0; // avoid negative altitudes in log |
303 | i32_1 = i32_2/1000L; |
315 | i32_1 = i32_2/1000L; |
304 | i32_2 = i32_2%1000L; |
316 | i32_2 = i32_2%1000L; |
305 | sprintf(string,"<ele>%ld.%03ld</ele>\r\n",i32_1, i32_2); |
317 | sprintf(string,"<ele>%ld.%03ld</ele>\r\n",i32_1, i32_2); |
306 | fputs_(string, doc->file); |
318 | fputs_(string, doc->file); |
307 | // write <time> tag only at a resolution of one second |
319 | // write <time> tag only at a resolution of one second |
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); |
320 | sprintf(string, "<time>%04d-%02d-%02dT%02d:%02d:%02dZ</time>\r\n",SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Hour, SystemTime.Min, SystemTime.Sec); |
309 | fputs_(string, doc->file); |
321 | fputs_(string, doc->file); |
310 | // write <sat> tag |
322 | // write <sat> tag |
311 | sprintf(string, "<sat>%d</sat>\r\n", NaviData.SatsInUse); |
323 | sprintf(string, "<sat>%d</sat>\r\n", NaviData.SatsInUse); |
312 | fputs_(string, doc->file); |
324 | fputs_(string, doc->file); |
313 | // todo: add <extensions> tag with additional data to be logged |
325 | // todo: add <extensions> tag with additional data to be logged |
314 | sprintf(string, "<extensions>\r\n"); |
326 | sprintf(string, "<extensions>\r\n"); |
315 | fputs_(string, doc->file); |
327 | fputs_(string, doc->file); |
316 | // Altimeter according to air pressure |
328 | // Altimeter according to air pressure |
317 | sprintf(string, "<Altimeter>%d</Altimeter>\r\n", NaviData.Altimeter); |
329 | sprintf(string, "<Altimeter>%d,'%c'</Altimeter>\r\n", NaviData.Altimeter,FromFC_VarioCharacter); |
318 | fputs_(string, doc->file); |
330 | fputs_(string, doc->file); |
319 | // Variometer according to air pressure |
331 | // Variometer according to air pressure |
320 | sprintf(string, "<Variometer>%d</Variometer>\r\n", NaviData.Variometer); |
332 | sprintf(string, "<Variometer>%d</Variometer>\r\n", NaviData.Variometer); |
321 | fputs_(string, doc->file); |
333 | fputs_(string, doc->file); |
322 | // Course in deg |
334 | // Course in deg |
323 | i16_1 = GPSData.Heading/100000L; |
335 | i16_1 = GPSData.Heading/100000L; |
324 | sprintf(string, "<Course>%03d</Course>\r\n", i16_1); |
336 | sprintf(string, "<Course>%03d</Course>\r\n", i16_1); |
325 | fputs_(string, doc->file); |
337 | fputs_(string, doc->file); |
326 | // Ground Speed in cm/s |
338 | // Ground Speed in cm/s |
327 | sprintf(string, "<GroundSpeed>%d</GroundSpeed>\r\n", NaviData.GroundSpeed); |
339 | sprintf(string, "<GroundSpeed>%d</GroundSpeed>\r\n", NaviData.GroundSpeed); |
328 | fputs_(string, doc->file); |
340 | fputs_(string, doc->file); |
329 | // Vertical Speed in cm/s |
341 | // Vertical Speed in cm/s |
330 | sprintf(string, "<VerticalSpeed>%d</VerticalSpeed>\r\n", NaviData.TopSpeed); |
342 | sprintf(string, "<VerticalSpeed>%d</VerticalSpeed>\r\n", NaviData.TopSpeed); |
331 | fputs_(string, doc->file); |
343 | fputs_(string, doc->file); |
332 | // Flight duration |
344 | // Flight duration |
333 | sprintf(string, "<FlightTime>%d</FlightTime>\r\n", NaviData.FlyingTime); |
345 | sprintf(string, "<FlightTime>%d</FlightTime>\r\n", NaviData.FlyingTime); |
334 | fputs_(string, doc->file); |
346 | fputs_(string, doc->file); |
335 | // Ubat |
347 | // Ubat |
336 | u8_1 = NaviData.UBat / 10; |
348 | u8_1 = NaviData.UBat / 10; |
337 | u8_2 = NaviData.UBat % 10; |
349 | u8_2 = NaviData.UBat % 10; |
338 | sprintf(string, "<Voltage>%d.%01d</Voltage>\r\n", u8_1, u8_2); |
350 | sprintf(string, "<Voltage>%d.%01d</Voltage>\r\n", u8_1, u8_2); |
339 | fputs_(string, doc->file); |
351 | fputs_(string, doc->file); |
340 | // Current |
352 | // Current |
341 | u8_1 = NaviData.Current / 10; |
353 | u8_1 = NaviData.Current / 10; |
342 | u8_2 = NaviData.Current % 10; |
354 | u8_2 = NaviData.Current % 10; |
343 | sprintf(string, "<Current>%d.%01d</Current>\r\n", u8_1, u8_2); |
355 | sprintf(string, "<Current>%d.%01d</Current>\r\n", u8_1, u8_2); |
344 | fputs_(string, doc->file); |
356 | fputs_(string, doc->file); |
345 | // Capacity |
357 | // Capacity |
346 | sprintf(string, "<Capacity>%d</Capacity>\r\n", NaviData.UsedCapacity); |
358 | sprintf(string, "<Capacity>%d</Capacity>\r\n", NaviData.UsedCapacity); |
347 | fputs_(string, doc->file); |
359 | fputs_(string, doc->file); |
348 | // RC Quality |
360 | // RC Quality |
349 | sprintf(string, "<RCQuality>%d</RCQuality>\r\n", FC.RC_Quality); |
361 | sprintf(string, "<RCQuality>%d</RCQuality>\r\n", FC.RC_Quality); |
350 | fputs_(string, doc->file); |
362 | fputs_(string, doc->file); |
351 | // RC Received Signal Strength Indication |
363 | // RC Received Signal Strength Indication |
352 | sprintf(string, "<RCRSSI>%d</RCRSSI>\r\n", FC.RC_RSSI); |
364 | sprintf(string, "<RCRSSI>%d</RCRSSI>\r\n", FC.RC_RSSI); |
353 | fputs_(string, doc->file); |
365 | fputs_(string, doc->file); |
354 | // Compassind deg |
366 | // Compassind deg |
355 | i16_1 = FromFlightCtrl.GyroHeading / 10; |
367 | i16_1 = FromFlightCtrl.GyroHeading / 10; |
356 | sprintf(string, "<Compass>%03d</Compass>\r\n", i16_1); |
368 | sprintf(string, "<Compass>%03d,%03d</Compass>\r\n", i16_1,ToFlightCtrl.CompassHeading); |
357 | fputs_(string, doc->file); |
369 | fputs_(string, doc->file); |
358 | // Nick Angle ind deg |
370 | // Nick Angle ind deg |
359 | sprintf(string, "<NickAngle>%03d</NickAngle>\r\n", NaviData.AngleNick); |
371 | sprintf(string, "<NickAngle>%03d</NickAngle>\r\n", NaviData.AngleNick); |
360 | fputs_(string, doc->file); |
372 | fputs_(string, doc->file); |
361 | // Roll Angle in deg |
373 | // Roll Angle in deg |
362 | sprintf(string, "<RollAngle>%03d</RollAngle>\r\n", NaviData.AngleRoll); |
374 | sprintf(string, "<RollAngle>%03d</RollAngle>\r\n", NaviData.AngleRoll); |
363 | fputs_(string, doc->file); |
375 | fputs_(string, doc->file); |
- | 376 | // magnetic field |
|
- | 377 | sprintf(string, "<MagnetField>%03d</MagnetField>\r\n",(u16) (EarthMagneticField/5)); |
|
- | 378 | fputs_(string, doc->file); |
|
- | 379 | // magnetic inclination & error |
|
- | 380 | sprintf(string, "<MagnetInclination>%02d,%02d</MagnetInclination>\r\n",(s16)EarthMagneticInclination,(s16)(EarthMagneticInclination - EarthMagneticInclinationTheoretic)); |
|
- | 381 | fputs_(string, doc->file); |
|
- | 382 | // BL Information |
|
- | 383 | sprintf(string, "<MotorCurrent>%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d</MotorCurrent>\r\n",MotorCurrent[0],MotorCurrent[1],MotorCurrent[2],MotorCurrent[3],MotorCurrent[4],MotorCurrent[5],MotorCurrent[6],MotorCurrent[7],MotorCurrent[8],MotorCurrent[9],MotorCurrent[10],MotorCurrent[11]); |
|
- | 384 | fputs_(string, doc->file); |
|
- | 385 | sprintf(string, "<BL_Temperature>%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d</BL_Temperature>\r\n",MotorTemperature[0],MotorTemperature[1],MotorTemperature[2],MotorTemperature[3],MotorTemperature[4],MotorTemperature[5],MotorTemperature[6],MotorTemperature[7],MotorTemperature[8],MotorTemperature[9],MotorTemperature[10],MotorTemperature[11]); |
|
- | 386 | fputs_(string, doc->file); |
|
- | 387 | sprintf(string, "<AvaiableMotorPower>%03d</AvaiableMotorPower>\r\n",BL_MinOfMaxPWM); |
|
- | 388 | fputs_(string, doc->file); |
|
- | 389 | sprintf(string, "<FC_I2C_ErrorCounter>%03d</FC_I2C_ErrorCounter>\r\n",(s16)FC_I2C_ErrorConter); |
|
- | 390 | fputs_(string, doc->file); |
|
- | 391 | // Analog inputs of the NC |
|
- | 392 | sprintf(string, "<AnalogInputs>%d,%d,%d,%d</AnalogInputs>\r\n",AnalogData.Ch4,AnalogData.Ch5,AnalogData.Ch6,AnalogData.Ch7); |
|
- | 393 | fputs_(string, doc->file); |
|
364 | // NC Mode (contains the status) |
394 | // NC Mode (contains the status) |
365 | sprintf(string, "<NCFlag>%02X</NCFlag>\r\n", NCFlags); |
395 | sprintf(string, "<NCFlag>0x%02X</NCFlag>\r\n", NCFlags); |
- | 396 | fputs_(string, doc->file); |
|
- | 397 | // Flags |
|
- | 398 | sprintf(string, "<FCFlags2>0x%02x,0x%02x</FCFlags2>\r\n",Logging_FCStatusFlags1,Logging_FCStatusFlags2); |
|
366 | fputs_(string, doc->file); |
399 | fputs_(string, doc->file); |
- | 400 | Logging_FCStatusFlags1 = 0; |
|
- | 401 | Logging_FCStatusFlags2 = 0; |
|
367 | // Status of the complete MikroKopter |
402 | // Status of the complete MikroKopter |
368 | sprintf(string, "<ErrorCode>%03d</ErrorCode>\r\n",ErrorCode); |
403 | sprintf(string, "<ErrorCode>%03d</ErrorCode>\r\n",ErrorCode); |
369 | fputs_(string, doc->file); |
404 | fputs_(string, doc->file); |
370 | // Target Bearing in deg |
405 | // Target Bearing in deg |
371 | sprintf(string, "<TargetBearing>%03d</TargetBearing>\r\n", NaviData.TargetPositionDeviation.Bearing); |
406 | sprintf(string, "<TargetBearing>%03d</TargetBearing>\r\n", NaviData.TargetPositionDeviation.Bearing); |
372 | fputs_(string, doc->file); |
407 | fputs_(string, doc->file); |
373 | // Target Distance in dm |
408 | // Target Distance in dm |
374 | sprintf(string, "<TargetDistance>%d</TargetDistance>\r\n", NaviData.TargetPositionDeviation.Distance); |
409 | sprintf(string, "<TargetDistance>%d</TargetDistance>\r\n", NaviData.TargetPositionDeviation.Distance); |
375 | fputs_(string, doc->file); |
410 | fputs_(string, doc->file); |
376 | // RC Sticks as Nick/Roll/Yaw |
411 | // RC Sticks as Nick/Roll/Yaw |
377 | sprintf(string, "<RCSticks>%d, %d, %d</RCSticks>\r\n", FC.StickNick,FC.StickRoll, FC.StickYaw); |
412 | sprintf(string, "<RCSticks>%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d</RCSticks>\r\n", FC.StickNick,FC.StickRoll, FC.StickYaw, FC.StickGas,FC.Poti[0],FC.Poti[1],FC.Poti[2],FC.Poti[3],FC.Poti[4],FC.Poti[5],FC.Poti[6],FC.Poti[7]); |
378 | fputs_(string, doc->file); |
413 | fputs_(string, doc->file); |
379 | // GPS Sticks as Nick/Roll/Yaw |
414 | // GPS Sticks as Nick/Roll/Yaw |
380 | sprintf(string, "<GPSSticks>%d, %d, %d</GPSSticks>\r\n", ToFlightCtrl.GPSStick.Nick, ToFlightCtrl.GPSStick.Roll, ToFlightCtrl.GPSStick.Yaw); |
415 | sprintf(string, "<GPSSticks>%d,%d,%d,'%c'</GPSSticks>\r\n", ToFlightCtrl.GPSStick.Nick, ToFlightCtrl.GPSStick.Roll, ToFlightCtrl.GPSStick.Yaw,NC_GPS_ModeCharacter); |
381 | fputs_(string, doc->file); |
416 | fputs_(string, doc->file); |
382 | - | ||
383 | // eof extensions |
417 | // eof extensions |
384 | sprintf(string, "</extensions>\r\n"); |
418 | sprintf(string, "</extensions>\r\n"); |
385 | fputs_(string, doc->file); |
419 | fputs_(string, doc->file); |
386 | sprintf(string, "</trkpt>\r\n"); |
420 | sprintf(string, "</trkpt>\r\n"); |
387 | fputs_(string, doc->file); |
421 | fputs_(string, doc->file); |
388 | retvalue = 1; |
422 | retvalue = 1; |
389 | } |
423 | } |
390 | } |
424 | } |
391 | } |
425 | } |
392 | return(retvalue); |
426 | return(retvalue); |
393 | } |
427 | } |
394 | 428 | ||
395 | //________________________________________________________________________________________________________________________________________ |
429 | //________________________________________________________________________________________________________________________________________ |
396 | // Function: u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *) |
430 | // Function: u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *) |
397 | // |
431 | // |
398 | // Description: This function opens and adds gpscoordinates to an GPX-Document. The document will be opened, if not already done |
432 | // Description: This function opens and adds gpscoordinates to an GPX-Document. The document will be opened, if not already done |
399 | // |
433 | // |
400 | // |
434 | // |
401 | // Returnvalue: '1' if an gps coordinate was logged |
435 | // Returnvalue: '1' if an gps coordinate was logged |
402 | //________________________________________________________________________________________________________________________________________ |
436 | //________________________________________________________________________________________________________________________________________ |
403 | 437 | ||
404 | u8 GPX_LoggGPSCoordinates(GPX_Document_t *doc) |
438 | u8 GPX_LoggGPSCoordinates(GPX_Document_t *doc) |
405 | { |
439 | { |
406 | u8 retval = 0; |
440 | u8 retval = 0; |
407 | while(doc->state != GPX_DOC_TRACKSEGMENT_OPENED) // automatic create document with default filename on the card. |
441 | while(doc->state != GPX_DOC_TRACKSEGMENT_OPENED) // automatic create document with default filename on the card. |
408 | { |
442 | { |
409 | switch(doc->state) |
443 | switch(doc->state) |
410 | { |
444 | { |
411 | case GPX_DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically |
445 | case GPX_DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically |
412 | retval = GPX_DocumentOpen("default.gpx",doc); // open the gpx-document with a standardname. |
446 | retval = GPX_DocumentOpen("default.gpx",doc); // open the gpx-document with a standardname. |
413 | break; |
447 | break; |
414 | 448 | ||
415 | case GPX_DOC_OPENED: // if a document has been opened before but no track exists: |
449 | case GPX_DOC_OPENED: // if a document has been opened before but no track exists: |
416 | retval = GPX_TrackBegin(doc); |
450 | retval = GPX_TrackBegin(doc); |
417 | break; |
451 | break; |
418 | 452 | ||
419 | case GPX_DOC_TRACK_OPENED: // add tracksegement to the track |
453 | case GPX_DOC_TRACK_OPENED: // add tracksegement to the track |
420 | retval = GPX_TrackSegmentBegin(doc); |
454 | retval = GPX_TrackSegmentBegin(doc); |
421 | break; |
455 | break; |
422 | 456 | ||
423 | default: |
457 | default: |
424 | retval = 0; |
458 | retval = 0; |
425 | break; |
459 | break; |
426 | 460 | ||
427 | } |
461 | } |
428 | if(retval != 1) return(retval); // stop on error |
462 | if(retval != 1) return(retval); // stop on error |
429 | } |
463 | } |
430 | 464 | ||
431 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) // if the document was opened add coordinates to the document. |
465 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) // if the document was opened add coordinates to the document. |
432 | { |
466 | { |
433 | retval = GPX_TrackSegementAddPoint(doc); // add a track segment point |
467 | retval = GPX_TrackSegementAddPoint(doc); // add a track segment point |
434 | } |
468 | } |
435 | return(retval); |
469 | return(retval); |
436 | } |
470 | } |
437 | 471 | ||
438 | 472 |