Rev 426 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 426 | Rev 434 | ||
---|---|---|---|
Line 58... | Line 58... | ||
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" |
- | |
64 | #include "main.h" |
63 | #include "main.h" |
65 | #include "uart1.h" |
- | |
66 | #include "ubx.h" |
- | |
Line 67... | Line 64... | ||
67 | 64 | ||
68 | //________________________________________________________________________________________________________________________________________ |
65 | //________________________________________________________________________________________________________________________________________ |
69 | // Function: GPX_DocumentInit(GPX_Document_t *) |
66 | // Function: GPX_DocumentInit(GPX_Document_t *) |
70 | // |
67 | // |
Line 93... | Line 90... | ||
93 | 90 | ||
94 | uint8_t GPX_DocumentOpen(int8_t *name, GPX_Document_t *doc) |
91 | uint8_t GPX_DocumentOpen(int8_t *name, GPX_Document_t *doc) |
Line 95... | Line 92... | ||
95 | { |
92 | { |
- | 93 | ||
- | 94 | uint8_t retvalue = 0; |
|
- | 95 | uint16_t i; |
|
Line 96... | Line 96... | ||
96 | 96 | int8_t c; |
|
97 | uint8_t retvalue = 0; |
97 | const prog_char *str; |
98 | 98 | ||
Line 99... | Line 99... | ||
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 | { |
|
- | 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. |
|
- | 107 | str = GPX_DOCUMENT_HEADER; // write the gpx-header to the document.. |
|
- | 108 | for(i= 0; i < sizeof(GPX_DOCUMENT_HEADER); i++) |
|
104 | { |
109 | { |
Line 105... | Line 110... | ||
105 | retvalue = 1; // the document could be created on the drive. |
110 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
106 | doc->state = GPX_DOC_OPENED; // change document state to opened. At next a placemark has to be opened. |
111 | fputc_(c, doc->file); // and write that to sd-card |
Line 121... | Line 126... | ||
121 | 126 | ||
122 | uint8_t GPX_DocumentClose(GPX_Document_t *doc) |
127 | uint8_t GPX_DocumentClose(GPX_Document_t *doc) |
Line 123... | Line 128... | ||
123 | { |
128 | { |
- | 129 | ||
- | 130 | uint8_t retvalue = 1; |
|
- | 131 | uint16_t i; |
|
Line 124... | Line 132... | ||
124 | 132 | int8_t c; |
|
Line 125... | Line 133... | ||
125 | uint8_t retvalue = 1; |
133 | const prog_char *str; |
126 | 134 | ||
Line 139... | Line 147... | ||
139 | break; |
147 | break; |
Line 140... | Line 148... | ||
140 | 148 | ||
141 | case GPX_DOC_OPENED: // close the file on the memorycard |
149 | case GPX_DOC_OPENED: // close the file on the memorycard |
142 | if(doc->file != NULL) |
150 | if(doc->file != NULL) |
143 | { |
151 | { |
- | 152 | str = GPX_DOCUMENT_FOOTER; // write the gpx-footer to the document. |
|
- | 153 | for(i= 0; i < sizeof(GPX_DOCUMENT_FOOTER); i++) |
|
- | 154 | { |
|
- | 155 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
|
- | 156 | fputc_(c, doc->file); // and write that to sd-card |
|
144 | fwrite_((void*)GPX_DOCUMENT_FOOTER, sizeof(GPX_DOCUMENT_FOOTER)-1,1,doc->file); // write the gpx-footer to the document. |
157 | } |
145 | fclose_(doc->file); |
158 | fclose_(doc->file); |
146 | retvalue = 1; |
159 | retvalue = 1; |
147 | } |
160 | } |
148 | doc->state = GPX_DOC_CLOSED; |
161 | doc->state = GPX_DOC_CLOSED; |
Line 167... | Line 180... | ||
167 | 180 | ||
168 | uint8_t GPX_TrackBegin(GPX_Document_t *doc) |
181 | uint8_t GPX_TrackBegin(GPX_Document_t *doc) |
Line 169... | Line 182... | ||
169 | { |
182 | { |
- | 183 | ||
- | 184 | uint8_t retvalue = 0; |
|
- | 185 | uint16_t i; |
|
- | 186 | int8_t c; |
|
- | 187 | const prog_char *str; |
|
170 | 188 | ||
171 | uint8_t retvalue = 0; |
189 | |
172 | if(doc->state == GPX_DOC_OPENED) |
190 | if(doc->state == GPX_DOC_OPENED) |
173 | { |
191 | { |
174 | if(doc->file != NULL) |
192 | if(doc->file != NULL) |
175 | { |
193 | { |
- | 194 | doc->state = GPX_DOC_TRACK_OPENED; |
|
176 | doc->state = GPX_DOC_TRACK_OPENED; |
195 | retvalue = 1; |
- | 196 | str = GPX_TRACK_HEADER; |
|
- | 197 | for(i= 0; i < sizeof(GPX_TRACK_HEADER); i++) |
|
- | 198 | { |
|
- | 199 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
|
177 | retvalue = 1; |
200 | fputc_(c, doc->file); // and write that to sd-card |
178 | fwrite_((void*)GPX_TRACK_HEADER, sizeof(GPX_TRACK_HEADER)-1,1,doc->file); |
201 | } |
179 | } |
202 | } |
180 | } |
203 | } |
Line 192... | Line 215... | ||
192 | 215 | ||
193 | uint8_t GPX_TrackEnd(GPX_Document_t *doc) |
216 | uint8_t GPX_TrackEnd(GPX_Document_t *doc) |
Line 194... | Line 217... | ||
194 | { |
217 | { |
- | 218 | ||
- | 219 | uint8_t retvalue = 0; |
|
- | 220 | uint16_t i; |
|
Line 195... | Line 221... | ||
195 | 221 | int8_t c; |
|
196 | uint8_t retvalue = 0; |
222 | const prog_char *str; |
197 | 223 | ||
198 | if(doc->state == GPX_DOC_TRACK_OPENED) |
224 | if(doc->state == GPX_DOC_TRACK_OPENED) |
199 | { |
225 | { |
- | 226 | if(doc->file != NULL) |
|
200 | if(doc->file != NULL) |
227 | { |
201 | { |
228 | doc->state = GPX_DOC_OPENED; |
- | 229 | str = GPX_TRACK_FOOTER; |
|
- | 230 | for(i= 0; i < sizeof(GPX_TRACK_FOOTER); i++) |
|
- | 231 | { |
|
202 | doc->state = GPX_DOC_OPENED; |
232 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
203 | fwrite_((void*)GPX_TRACK_FOOTER, sizeof(GPX_TRACK_FOOTER)-1,1,doc->file); |
233 | fputc_(c, doc->file); // and write that to sd-card |
Line 204... | Line 234... | ||
204 | retvalue = 1; |
234 | } |
205 | } |
235 | } |
Line 219... | Line 249... | ||
219 | 249 | ||
220 | uint8_t GPX_TrackSegmentBegin(GPX_Document_t *doc) |
250 | uint8_t GPX_TrackSegmentBegin(GPX_Document_t *doc) |
Line 221... | Line 251... | ||
221 | { |
251 | { |
- | 252 | ||
- | 253 | uint8_t retvalue = 0; |
|
- | 254 | uint16_t i; |
|
Line 222... | Line 255... | ||
222 | 255 | int8_t c; |
|
223 | uint8_t retvalue = 0; |
256 | const prog_char *str; |
224 | 257 | ||
225 | if(doc->state == GPX_DOC_TRACK_OPENED) |
258 | if(doc->state == GPX_DOC_TRACK_OPENED) |
226 | { |
259 | { |
- | 260 | if(doc->file != NULL) |
|
227 | if(doc->file != NULL) |
261 | { |
- | 262 | doc->state = GPX_DOC_TRACKSEGMENT_OPENED; |
|
- | 263 | str = GPX_TRACKSEGMENT_HEADER; |
|
- | 264 | for(i = 0; i < sizeof(GPX_TRACKSEGMENT_HEADER); i++) |
|
- | 265 | { |
|
228 | { |
266 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
229 | doc->state = GPX_DOC_TRACKSEGMENT_OPENED; |
267 | fputc_(c, doc->file); // and write that to sd-card |
230 | fwrite_((void*)GPX_TRACKSEGMENT_HEADER, sizeof(GPX_TRACKSEGMENT_HEADER)-1,1,doc->file); |
268 | } |
231 | retvalue = 1; |
269 | retvalue = 1; |
232 | } |
270 | } |
Line 245... | Line 283... | ||
245 | 283 | ||
246 | uint8_t GPX_TrackSegmentEnd(GPX_Document_t *doc) |
284 | uint8_t GPX_TrackSegmentEnd(GPX_Document_t *doc) |
Line 247... | Line 285... | ||
247 | { |
285 | { |
- | 286 | ||
- | 287 | uint8_t retvalue = 0; |
|
- | 288 | uint16_t i; |
|
- | 289 | int8_t c; |
|
- | 290 | const prog_char *str; |
|
248 | 291 | ||
249 | uint8_t retvalue = 0; |
292 | |
250 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) |
293 | if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) |
251 | { |
294 | { |
252 | if(doc->file != NULL) |
295 | if(doc->file != NULL) |
- | 296 | { |
|
253 | { |
297 | doc->state = GPX_DOC_TRACK_OPENED; |
- | 298 | str = GPX_TRACKSEGMENT_FOOTER; |
|
- | 299 | for(i = 0; i < sizeof(GPX_TRACKSEGMENT_FOOTER); i++) |
|
- | 300 | { |
|
- | 301 | c = (int8_t)pgm_read_byte(str++); // get byte from flash |
|
254 | doc->state = GPX_DOC_TRACK_OPENED; |
302 | fputc_(c, doc->file); // and write that to sd-card |
255 | fwrite_((void*)GPX_TRACKSEGMENT_FOOTER, sizeof(GPX_TRACKSEGMENT_FOOTER)-1,1,doc->file); |
303 | } |
256 | retvalue = 1; |
304 | retvalue = 1; |
257 | } |
305 | } |
258 | } |
306 | } |