Subversion Repositories NaviCtrl

Rev

Rev 27 | Rev 51 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 27 Rev 41
Line 52... Line 52...
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
 
-
 
-
 
57
#include <stdlib.h>
58
#include <stdio.h>
58
#include <stdio.h>
59
#include "main.h"
59
#include "91x_lib.h"
60
#include "kml.h"
60
#include "kml.h"
61
#include "kml_header.h"
61
#include "kml_header.h"
62
#include "fat16.h"
-
 
Line 63... Line 62...
63
 
62
 
64
 
63
 
65
//________________________________________________________________________________________________________________________________________
64
//________________________________________________________________________________________________________________________________________
66
// Module name:                 kml.c 
65
// Module name:                 kml.c
67
// Compiler used:               avr-gcc 3.4.5
66
// Compiler used:               avr-gcc 3.4.5
68
// Last Modifikation:   17.03.2008
67
// Last Modifikation:   20.07.2008
69
// Version:                             1.02
68
// Version:                             1.02
70
// Authors:                             Stephan Busker  
69
// Authors:                             Stephan Busker
71
// Description:                 Source files to write gps-coordinates to a file in the kml (keyhole markup language) fileformat
70
// Description:                 Source files to write gps-coordinates to a file in the kml (keyhole markup language) fileformat
Line 90... Line 89...
90
//________________________________________________________________________________________________________________________________________
89
//________________________________________________________________________________________________________________________________________
Line 91... Line 90...
91
 
90
 
92
 
91
 
93
 
92
 
94
//________________________________________________________________________________________________________________________________________
93
//________________________________________________________________________________________________________________________________________
95
// Funtion:     KML_DocumentInit(KML_Document_t *)
94
// Function:    KML_DocumentInit(KML_Document_t *)
96
// 
95
//
97
// Description: This function initializes the kml-document for further use.
96
// Description: This function initializes the kml-document for further use.
Line 109... Line 108...
109
        doc->place.description[0]=0;
108
        doc->place.description[0]=0;
110
        return(1);
109
        return(1);
111
}
110
}
Line 112... Line 111...
112
 
111
 
113
//________________________________________________________________________________________________________________________________________
112
//________________________________________________________________________________________________________________________________________
114
// Funtion:     KML_Document_Open(void);
113
// Function:    KML_Document_Open(void);
115
// 
114
//
116
// Description: This function opens a new KML- document with the specified name and creates the document header within the file.
115
// Description: This function opens a new KML- document with the specified name and creates the document header within the file.
117
//                              
116
//
118
//
117
//
Line 122... Line 121...
122
u8 KML_DocumentOpen(s8 *name, KML_Document_t *doc)
121
u8 KML_DocumentOpen(s8 *name, KML_Document_t *doc)
123
{
122
{
Line 124... Line 123...
124
 
123
 
Line -... Line 124...
-
 
124
        u8 retvalue = 0;
-
 
125
 
125
        u8 retvalue = 0;
126
        if(doc == NULL) return(0);
126
       
127
 
Line 127... Line 128...
127
        KML_DocumentInit(doc);                                                                                                                  // intialize the document with resetvalues
128
        KML_DocumentInit(doc);                                                                                                          // intialize the document with resetvalues
128
        doc->file = fopen_(name,'a');                                                                                                   // open a new file with the specified filename on the memorycard.
129
        doc->file = fopen_(name,'a');                                                                                           // open a new file with the specified filename on the memorycard.
129
 
130
 
130
        if(doc->file != NULL)                                                                                                           // could the file be opened?
131
        if(doc->file != NULL)                                                                                                           // could the file be opened?
131
        {
132
        {
132
                retvalue = 1;                                                                                                                   // the document could be created on the drive.
133
                retvalue = 1;                                                                                                                   // the document could be created on the drive.
Line 133... Line 134...
133
                doc->state = DOC_OPENED;                                                                                                // change document state to opened. At next a placemark has to be opened.
134
                doc->state = DOC_OPENED;                                                                                                // change document state to opened. At next a placemark has to be opened.
134
                fwrite_(KML_DOCUMENT_HEADER, sizeof(KML_DOCUMENT_HEADER)-1,1,doc->file);        // write the KML- footer to the document.
135
                fwrite_((void*)KML_DOCUMENT_HEADER, sizeof(KML_DOCUMENT_HEADER)-1,1,doc->file);// write the KML- footer to the document.
Line 135... Line 136...
135
        }
136
        }
136
 
137
 
137
        return(retvalue);
138
        return(retvalue);
138
}
139
}
139
 
140
 
140
//________________________________________________________________________________________________________________________________________
141
//________________________________________________________________________________________________________________________________________
141
// Funtion:     DocumentClose(KML_Document_t *doc);
142
// Function:    DocumentClose(KML_Document_t *doc);
142
// 
143
//
Line 143... Line 144...
143
// Description: This function closes the document specified by doc. 
144
// Description: This function closes the document specified by doc.
144
//                              
145
//
Line 145... Line 146...
145
//
146
//
-
 
147
// Returnvalue: '1' if the KML- file could be closed.
-
 
148
//________________________________________________________________________________________________________________________________________
Line 146... Line 149...
146
// Returnvalue: none
149
 
147
//________________________________________________________________________________________________________________________________________
150
u8 KML_DocumentClose(KML_Document_t *doc)
148
 
151
{
149
u8 KML_DocumentClose(KML_Document_t *doc)
152
 
Line 166... Line 169...
166
                        break;
169
                                break;
Line 167... Line 170...
167
                       
170
 
168
                        case DOC_OPENED:                                                                        // close the file on the memorycard 
171
                        case DOC_OPENED:                                                                        // close the file on the memorycard
169
                                if(doc->file != NULL)
172
                                if(doc->file != NULL)
170
                                {
173
                                {
171
                                        fwrite_(KML_DOCUMENT_FOOTER, sizeof(KML_DOCUMENT_FOOTER)-1,1,doc->file);        // write the KML- footer to the document.
174
                                        fwrite_((void*)KML_DOCUMENT_FOOTER, sizeof(KML_DOCUMENT_FOOTER)-1,1,doc->file); // write the KML- footer to the document.
172
                                        fclose_(doc->file);                                                    
175
                                        fclose_(doc->file);
173
                                        retvalue = 1;
176
                                        retvalue = 1;
174
                                }
177
                                }
175
                                doc->state = DOC_CLOSED;                                               
178
                                doc->state = DOC_CLOSED;
Line 176... Line 179...
176
                        break;
179
                                break;
-
 
180
 
177
                       
181
                        default:
Line -... Line 182...
-
 
182
                                doc->state = DOC_CLOSED;
-
 
183
                                break;
178
                }
184
 
179
        };
185
                }
Line 180... Line 186...
180
 
186
        }
181
        return(retvalue);
187
        return(retvalue);
182
}
188
}
183
 
189
 
184
//________________________________________________________________________________________________________________________________________
190
//________________________________________________________________________________________________________________________________________
185
// Funtion:     u8 PlaceMarkOpen(s8 *name, File *file);
191
// Function:    u8 PlaceMarkOpen(s8 *name, File *file);
186
// 
192
//
187
// Description: This function adds a placemark to the document.
193
// Description: This function adds a placemark to the document.
Line 188... Line 194...
188
//                              
194
//
189
//
195
//
Line 197... Line 203...
197
 
203
 
198
        if(doc->file != NULL)
204
        if(doc->file != NULL)
199
        {
205
        {
200
                doc->state = DOC_PLACEMARK_OPENED;
206
                doc->state = DOC_PLACEMARK_OPENED;
201
                retvalue = 1;
207
                retvalue = 1;
202
                fwrite_(KML_PLACEMARK_HEADER, sizeof(KML_PLACEMARK_HEADER)-1,1,doc->file);                                             
208
                fwrite_((void*)KML_PLACEMARK_HEADER, sizeof(KML_PLACEMARK_HEADER)-1,1,doc->file);
Line 203... Line 209...
203
        }
209
        }
204
       
210
 
Line 205... Line 211...
205
        return(retvalue);
211
        return(retvalue);
206
}
212
}
207
 
213
 
208
//________________________________________________________________________________________________________________________________________
214
//________________________________________________________________________________________________________________________________________
209
// Funtion:     u8 PlaceMarkClose(KML_PlaceMark_t *place, File *file);
215
// Function:    u8 PlaceMarkClose(KML_PlaceMark_t *place, File *file);
210
// 
216
//
211
// Description: This function ends the placemark opened before.
217
// Description: This function ends the placemark opened before.
212
//                              
218
//
Line 213... Line 219...
213
//
219
//
214
// Returnvalue: none
220
// Returnvalue: 1' if the PlaceMark could be closed
Line 222... Line 228...
222
        if(doc->state == DOC_PLACEMARK_OPENED)
228
        if(doc->state == DOC_PLACEMARK_OPENED)
223
        {
229
        {
224
                if(doc->file != NULL)
230
                if(doc->file != NULL)
225
                {
231
                {
226
                        doc->state =DOC_OPENED;
232
                        doc->state = DOC_OPENED;
227
                        fwrite_(KML_PLACEMARK_FOOTER, sizeof(KML_PLACEMARK_FOOTER)-1,1,doc->file);                                             
233
                        fwrite_((void*)KML_PLACEMARK_FOOTER, sizeof(KML_PLACEMARK_FOOTER)-1,1,doc->file);
228
                        retvalue = 1;
234
                        retvalue = 1;
229
                }
235
                }
230
        }
236
        }
Line 231... Line 237...
231
       
237
 
232
        return(retvalue);
238
        return(retvalue);
Line 233... Line 239...
233
}
239
}
234
 
240
 
235
//________________________________________________________________________________________________________________________________________
241
//________________________________________________________________________________________________________________________________________
236
// Funtion:     u8 LineStringBegin(KML_Document_t *doc);
242
// Function:    u8 LineStringBegin(KML_Document_t *doc);
237
// 
243
//
238
// Description: This function ends the placemark opened before.
244
// Description: This function ends the placemark opened before.
239
//                              
245
//
240
//
246
//
Line 241... Line 247...
241
// Returnvalue: none
247
// Returnvalue: '1' if the LineString could be started
242
//________________________________________________________________________________________________________________________________________
248
//________________________________________________________________________________________________________________________________________
Line 243... Line 249...
243
 
249
 
Line 244... Line 250...
244
u8 KML_LineStringBegin(KML_Document_t *doc)
250
u8 KML_LineStringBegin(KML_Document_t *doc)
245
{
251
{
246
 
252
 
247
        u8 retvalue = 0;
253
        u8 retvalue = 0;
248
       
254
 
249
        if(doc->file != NULL)
255
        if(doc->file != NULL)
Line 250... Line 256...
250
        {
256
        {
251
                doc->state = DOC_LINESTRING_OPENED;
257
                doc->state = DOC_LINESTRING_OPENED;
Line 252... Line 258...
252
                fwrite_(KML_LINESTRING_HEADER, sizeof(KML_LINESTRING_HEADER)-1,1,doc->file);                                           
258
                fwrite_((void*)KML_LINESTRING_HEADER, sizeof(KML_LINESTRING_HEADER)-1,1,doc->file);
253
                retvalue = 1;
259
                retvalue = 1;
254
        }
260
        }
255
 
261
 
256
        return(retvalue);
262
        return(retvalue);
257
}
263
}
258
 
264
 
259
//________________________________________________________________________________________________________________________________________
265
//________________________________________________________________________________________________________________________________________
Line 260... Line 266...
260
// Funtion:     u8 LineStringEnd(KML_Document_t *doc)
266
// Function:    u8 LineStringEnd(KML_Document_t *doc)
261
// 
267
//
Line 272... Line 278...
272
       
278
 
273
        if(doc->state == DOC_LINESTRING_OPENED);
279
        if(doc->state == DOC_LINESTRING_OPENED);
274
        if(doc->file != NULL)
280
        if(doc->file != NULL)
275
        {
281
        {
276
                doc->state = DOC_PLACEMARK_OPENED;
282
                doc->state = DOC_PLACEMARK_OPENED;
277
                fwrite_(KML_LINESTRING_FOOTER, sizeof(KML_LINESTRING_FOOTER)-1,1,doc->file);                                           
283
                fwrite_((void*)KML_LINESTRING_FOOTER, sizeof(KML_LINESTRING_FOOTER)-1,1,doc->file);
278
                retvalue = 1;
284
                retvalue = 1;
Line 279... Line 285...
279
        }
285
        }
280
 
286
 
Line 281... Line 287...
281
        return(retvalue);
287
        return(retvalue);
282
}
288
}
283
 
289
 
284
//________________________________________________________________________________________________________________________________________
290
//________________________________________________________________________________________________________________________________________
285
// Funtion:     u8 LineStringAddPoint(struct str_GPSPosition, KML_Document_t *doc)
291
// Function:    u8 LineStringAddPoint(gps_data_t, KML_Document_t *doc)
286
// 
292
//
287
// Description: This function adds a point to the specified document.
293
// Description: This function adds a point to the specified document.
288
//                              
294
//
Line 289... Line 295...
289
//
295
//
290
// Returnvalue: none
296
// Returnvalue: '1' if a ppoint was added could be started
Line 291... Line 297...
291
//________________________________________________________________________________________________________________________________________
297
//________________________________________________________________________________________________________________________________________
292
 
298
 
-
 
299
u8 KML_LineStringAddPoint(GPS_Pos_t * pGPS_Position ,KML_Document_t *doc)
-
 
300
{
-
 
301
 
Line -... Line 302...
-
 
302
        u8 retvalue = 0;
-
 
303
        s8 string[50];
293
u8 KML_LineStringAddPoint(struct str_gps_nav_data gps_data ,KML_Document_t *doc)
304
        s32 rel_altitude = 0;
294
{
305
 
295
 
306
        if(doc == NULL || pGPS_Position == NULL) return(0);
296
        u8 retvalue = 0;
307
 
-
 
308
        if((pGPS_Position->Status != INVALID) && (GPS_HomePosition.Status != INVALID))
-
 
309
        {
-
 
310
                if(doc->state == DOC_LINESTRING_OPENED)
-
 
311
                {
-
 
312
                        if(doc->file != NULL)
-
 
313
                        {
-
 
314
                                s32 i1, i2;
-
 
315
                                i1 = pGPS_Position->Longitude/10000000L;
-
 
316
                                i2 = abs(pGPS_Position->Longitude%10000000L);
-
 
317
                                sprintf(string,"\r\n%ld.%07ld,",i1, i2);
-
 
318
                                fputs_(string, doc->file);
297
        s8 string[50];
319
                                i1 = pGPS_Position->Latitude/10000000L;
-
 
320
                                i2 = abs(pGPS_Position->Latitude%10000000L);
-
 
321
                                sprintf(string," %ld.%07ld,",i1, i2);
-
 
322
                                fputs_(string, doc->file);
298
       
323
                                // calculate relative altitude with respect to the altitude of the home position
299
        if(doc->state == DOC_LINESTRING_OPENED)
324
                                rel_altitude = pGPS_Position->Altitude - GPS_HomePosition.Altitude;
300
        {
325
                                if(rel_altitude < 0) rel_altitude = 0; // avoid negative altitudes in log
301
                if(doc->file != NULL)
326
                                i1 = rel_altitude/1000L;
-
 
327
                                i2 = abs(rel_altitude%1000L);
Line 302... Line 328...
302
                {
328
                                sprintf(string," %ld.%03ld",i1, i2);
303
                        sprintf(string,"\r\n%d.%d,%d.%d,%d.0",(gps_data.Longitude/10000000),(gps_data.Longitude%10000000),(gps_data.Latitude/10000000),(gps_data.Latitude%10000000),0);
329
                                fputs_(string, doc->file);
Line 304... Line 330...
304
                        fputs_(doc->file,string);
330
                                retvalue = 1;
305
                        retvalue = 1;
331
                        }
306
                }
332
                }
307
        }
333
        }
308
 
334
 
309
        return(retvalue);
335
        return(retvalue);
310
}
336
}
311
 
337
 
Line 312... Line 338...
312
//________________________________________________________________________________________________________________________________________
338
//________________________________________________________________________________________________________________________________________
313
// Funtion:     u8 KML_LoggGPSCoordinates(struct str_gps_nav_data, KML_Document_t *) 
339
// Function:    u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *)
-
 
340
//
314
// 
341
// Description: This function opens adds gpscoordinates to an KML-Document. The document will be opened, if not already done
315
// Description: This function opens adds gpscoordinates to an KML-Document. The document will be opened, if not already done
342
//
316
//                              
343
//
317
//
344
// Returnvalue: '1' if an gps coordinate was logged
318
// Returnvalue: none
345
//________________________________________________________________________________________________________________________________________
319
//________________________________________________________________________________________________________________________________________
346
 
320
 
347
u8 KML_LoggGPSCoordinates(GPS_Pos_t* pGPS_Position, KML_Document_t *doc)
-
 
348
{
321
u8      KML_LoggGPSCoordinates(struct str_gps_nav_data gps_data, KML_Document_t *doc)
349
        u8 retval = 0;
322
{
350
        while(doc->state != DOC_LINESTRING_OPENED)                                      // automatic create document with default filename on the card.
323
        while(doc->state != DOC_LINESTRING_OPENED)                                      // automatic create document with default filename on the card.
351
        {
324
        {                      
352
                switch(doc->state)
Line 325... Line 353...
325
                switch(doc->state)
353
                {
326
                {
354
                        case DOC_CLOSED:                                                                        // document hasn't been opened yet therefore it will be initialized automatically
-
 
355
                                KML_DocumentInit(doc);                                                  // initialize the document to default values
327
                        case DOC_CLOSED:                                                                        // document hasn't been opened yet therefore it will be initialized automatically
356
                                retval = KML_DocumentOpen("default.kml",doc);   // open the kml-document with a standardname.
328
                                KML_DocumentInit(doc);                                                  // initialize the document to default values
357
                                if(retval)
329
                                if(KML_DocumentOpen("default.kml",doc))         // open the kml-document with a standardname.                   
358
                                {
330
                                {
359
                                        doc->state = DOC_OPENED;
Line 331... Line 360...
331
                                        doc->state = DOC_OPENED;
360
                                }
332
                                }                                              
361
                        break;
-
 
362
 
333
                        break;
363
                        case DOC_OPENED:                                                                        // if a document has been opened before but no placemark exists:
334
 
364
                                retval = KML_PlaceMarkOpen("MIKROKOPTER",doc);
335
                        case DOC_OPENED:                                                                        // if a document has been opened before but no placemark exists:
365
                                if(retval)
336
                                if(KML_PlaceMarkOpen("MIKROKOPTER",doc))
366
                                {
Line -... Line 367...
-
 
367
                                        doc->state = DOC_PLACEMARK_OPENED;                      // add a placemark to the document.
-
 
368
                                }
-
 
369
                        break;
-
 
370
 
-
 
371
                        case DOC_PLACEMARK_OPENED:                                                      // add linestring to the placemark
-
 
372
                                retval = KML_LineStringBegin(doc);
337
                                {
373
                                if(retval)
338
                                        doc->state = DOC_PLACEMARK_OPENED;      // add a placemark to the document.
-
 
Line 339... Line 374...
339
                                }
374
                                {
340
                        break;
375
                                        doc->state = DOC_LINESTRING_OPENED;
341
 
376
                                }
342
                        case DOC_PLACEMARK_OPENED:                                                      // add linestring to the placemark
377
                        break;
-
 
378
 
343
                                if(KML_LineStringBegin(doc))
379
                        default: