Subversion Repositories NaviCtrl

Compare Revisions

Ignore whitespace Rev 84 → Rev 85

/trunk/Navi-Ctrl.Uv2
38,6 → 38,8
File 1,1,<.\fifo.c><fifo.c>
File 1,1,<.\waypoints.c><waypoints.c>
File 1,1,<.\GPS.c><GPS.c>
File 1,1,<.\logging.c><logging.c>
File 1,1,<.\gpx.c><gpx.c>
File 2,5,<.\ramfunc.h><ramfunc.h>
File 2,5,<.\main.h><main.h>
File 2,5,<.\menu.h><menu.h>
62,6 → 64,9
File 2,5,<.\kml.h><kml.h>
File 2,5,<.\fifo.h><fifo.h>
File 2,5,<.\waypoints.h><waypoints.h>
File 2,5,<.\logging.h><logging.h>
File 2,5,<.\gpx_header.h><gpx_header.h>
File 2,5,<.\gpx.h><gpx.h>
File 3,2,<.\startup912.s><startup912.s>
File 4,1,<.\libstr91x\src\91x_scu.c><91x_scu.c>
File 4,1,<.\libstr91x\src\91x_gpio.c><91x_gpio.c>
/trunk/gpx.c
0,0 → 1,361
/*#######################################################################################*/
/* !!! THIS IS NOT FREE SOFTWARE !!! */
/*#######################################################################################*/
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Copyright (c) 2008 Ingo Busker, Holger Buss
// + Nur für den privaten Gebrauch
// + FOR NON COMMERCIAL USE ONLY
// + www.MikroKopter.com
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
// + bzgl. der Nutzungsbedingungen aufzunehmen.
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
// + Verkauf von Luftbildaufnahmen, usw.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
// + eindeutig als Ursprung verlinkt werden
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
// + Benutzung auf eigene Gefahr
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
// + mit unserer Zustimmung zulässig
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
// + this list of conditions and the following disclaimer.
// + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
// + from this software without specific prior written permission.
// + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted
// + for non-commercial use (directly or indirectly)
// + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
// + with our written permission
// + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
// + clearly linked as origin
// + * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed
//
// + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// + POSSIBILITY OF SUCH DAMAGE.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <stdlib.h>
#include <stdio.h>
#include "91x_lib.h"
#include "gpx.h"
#include "gpx_header.h"
#include "timer.h"
 
//________________________________________________________________________________________________________________________________________
// Function: GPX_DocumentInit(GPX_Document_t *)
//
// Description: This function initializes the gpx-document for further use.
//
//
// Returnvalue: '1' if document was initialized
//________________________________________________________________________________________________________________________________________
 
u8 GPX_DocumentInit(GPX_Document_t *doc)
{
if(doc->state != GPX_DOC_CLOSED) GPX_DocumentClose(doc); // close file if it was opened before
doc->state = GPX_DOC_CLOSED; // init state of the gpx-document
doc->file = NULL;
return(1);
}
 
//________________________________________________________________________________________________________________________________________
// Function: GPX_Document_Open(s8 *name, GPX_Document_t *doc);
//
// Description: This function opens a new gpx-document with the specified name and creates the document header within the file.
//
//
// Returnvalue: '1' if the gpx-file could be created.
//________________________________________________________________________________________________________________________________________
 
u8 GPX_DocumentOpen(s8 *name, GPX_Document_t *doc)
{
 
u8 retvalue = 0;
 
if(doc == NULL) return(0);
GPX_DocumentInit(doc); // intialize the document with resetvalues
doc->file = fopen_(name,'a'); // open a new file with the specified filename on the memorycard.
 
if(doc->file != NULL) // could the file be opened?
{
retvalue = 1; // the document could be created on the drive.
doc->state = GPX_DOC_OPENED; // change document state to opened. At next a placemark has to be opened.
fwrite_((void*)GPX_DOCUMENT_HEADER, sizeof(GPX_DOCUMENT_HEADER)-1,1,doc->file);// write the gpx-header to the document.
}
 
return(retvalue);
}
 
//________________________________________________________________________________________________________________________________________
// Function: DocumentClose(GPX_Document_t *doc);
//
// Description: This function closes the document specified by doc.
//
//
// Returnvalue: '1' if the gpx-file could be closed.
//________________________________________________________________________________________________________________________________________
 
u8 GPX_DocumentClose(GPX_Document_t *doc)
{
 
u8 retvalue = 1;
 
if(doc == NULL) return(0);
 
while(doc->state != GPX_DOC_CLOSED) // close linestring, placemark and document before closing the file on the memorycard
{
switch(doc->state)
{
case GPX_DOC_TRACKSEGMENT_OPENED:
GPX_TrackSegmentEnd(doc); // write terminating tag to end tracksegment.
break;
 
case GPX_DOC_TRACK_OPENED: // write terminating tag to close track.
GPX_TrackEnd(doc);
break;
 
case GPX_DOC_OPENED: // close the file on the memorycard
if(doc->file != NULL)
{
fwrite_((void*)GPX_DOCUMENT_FOOTER, sizeof(GPX_DOCUMENT_FOOTER)-1,1,doc->file); // write the gpx-footer to the document.
fclose_(doc->file);
retvalue = 1;
}
doc->state = GPX_DOC_CLOSED;
break;
 
default:
doc->state = GPX_DOC_CLOSED;
break;
}
}
return(retvalue);
}
 
//________________________________________________________________________________________________________________________________________
// Function: u8 GPX_TrackBegin(GPX_Document_t);
//
// Description: This function adds a track to the document.
//
//
// Returnvalue: '1' if the track could be opened
//________________________________________________________________________________________________________________________________________
 
u8 GPX_TrackBegin(GPX_Document_t *doc)
{
 
u8 retvalue = 0;
if(doc->state == GPX_DOC_OPENED)
{
if(doc->file != NULL)
{
doc->state = GPX_DOC_TRACK_OPENED;
retvalue = 1;
fwrite_((void*)GPX_TRACK_HEADER, sizeof(GPX_TRACK_HEADER)-1,1,doc->file);
}
}
return(retvalue);
}
 
//________________________________________________________________________________________________________________________________________
// Function: u8 GPX_TrackEnd(KML_Document_t *doc)
//
// Description: This function ends the track opened before.
//
//
// Returnvalue: 1' if the track could be closed
//________________________________________________________________________________________________________________________________________
 
u8 GPX_TrackEnd(GPX_Document_t *doc)
{
 
u8 retvalue = 0;
 
if(doc->state == GPX_DOC_TRACK_OPENED)
{
if(doc->file != NULL)
{
doc->state = GPX_DOC_OPENED;
fwrite_((void*)GPX_TRACK_FOOTER, sizeof(GPX_TRACK_FOOTER)-1,1,doc->file);
retvalue = 1;
}
}
 
return(retvalue);
}
 
//________________________________________________________________________________________________________________________________________
// Function: u8 GPX_TrackSegmentBegin(GPX_Document_t *doc);
//
// Description: This function starts a track segment.
//
//
// Returnvalue: '1' if the track segement could be started
//________________________________________________________________________________________________________________________________________
 
u8 GPX_TrackSegmentBegin(GPX_Document_t *doc)
{
 
u8 retvalue = 0;
 
if(doc->state == GPX_DOC_TRACK_OPENED)
{
if(doc->file != NULL)
{
doc->state = GPX_DOC_TRACKSEGMENT_OPENED;
fwrite_((void*)GPX_TRACKSEGMENT_HEADER, sizeof(GPX_TRACKSEGMENT_HEADER)-1,1,doc->file);
retvalue = 1;
}
}
return(retvalue);
}
 
//________________________________________________________________________________________________________________________________________
// Function: u8 GPX_TrackSegmentEnd(GPX_Document_t *doc);
//
// Description: This function ends the tracksegment opened before.
//
//
// Returnvalue: '1' if the track segment could be terminated
//________________________________________________________________________________________________________________________________________
 
u8 GPX_TrackSegmentEnd(GPX_Document_t *doc)
{
 
u8 retvalue = 0;
if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED)
{
if(doc->file != NULL)
{
doc->state = GPX_DOC_TRACK_OPENED;
fwrite_((void*)GPX_TRACKSEGMENT_FOOTER, sizeof(GPX_TRACKSEGMENT_FOOTER)-1,1,doc->file);
retvalue = 1;
}
}
return(retvalue);
}
 
//________________________________________________________________________________________________________________________________________
// Function: u8 GPX_TrackSegementAddPoint(GPS_Pos_t * pGPS_Position ,GPX_Document_t *doc);
//
// Description: This function adds a pointof a track segement to the specified document.
//
//
// Returnvalue: '1' if a point was added
//________________________________________________________________________________________________________________________________________
 
u8 GPX_TrackSegementAddPoint(GPX_Document_t *doc)
{
 
u8 retvalue = 0;
s8 string[50];
s32 rel_altitude = 0;
 
if(doc == NULL) return(0);
 
if((GPSData.Position.Status != INVALID) && (GPS_HomePosition.Status != INVALID))
{
if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED)
{
if(doc->file != NULL)
{
s32 i1, i2;
u8 sign;
// write <trkpt> tag
if(GPSData.Position.Latitude < 0) sign = '-';
else sign = '+';
i1 = abs(GPSData.Position.Latitude)/10000000L;
i2 = abs(GPSData.Position.Latitude)%10000000L;
sprintf(string, "<trkpt lat=\"%c%ld.%07ld\" ",sign, i1, i2);
fputs_(string, doc->file);
if(GPSData.Position.Longitude < 0) sign = '-';
else sign = '+';
i1 = abs(GPSData.Position.Longitude)/10000000L;
i2 = abs(GPSData.Position.Longitude)%10000000L;
sprintf(string, "lon=\"%c%ld.%07ld\">\r\n",sign, i1, i2);
fputs_(string, doc->file);
// write <ele> taga
rel_altitude = GPSData.Position.Altitude - GPS_HomePosition.Altitude;
if(rel_altitude < 0) rel_altitude = 0; // avoid negative altitudes in log
i1 = rel_altitude/1000L;
i2 = rel_altitude%1000L;
sprintf(string,"<ele>%ld.%03ld</ele>\r\n",i1, i2);
fputs_(string, doc->file);
// write <time> tag only at a resolution of one second
sprintf(string, "<time>%04d-%02d-%02dT%02d:%02d:%02dZ</time>\r\n",SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Hour, SystemTime.Min, SystemTime.Sec);
fputs_(string, doc->file);
 
// todo: add <extensions> tag with additional data to be logged
 
sprintf(string, "</trkpt>\r\n");
fputs_(string, doc->file);
retvalue = 1;
}
}
}
return(retvalue);
}
 
//________________________________________________________________________________________________________________________________________
// Function: u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *)
//
// Description: This function opens and adds gpscoordinates to an GPX-Document. The document will be opened, if not already done
//
//
// Returnvalue: '1' if an gps coordinate was logged
//________________________________________________________________________________________________________________________________________
 
u8 GPX_LoggGPSCoordinates(GPX_Document_t *doc)
{
u8 retval = 0;
while(doc->state != GPX_DOC_TRACKSEGMENT_OPENED) // automatic create document with default filename on the card.
{
switch(doc->state)
{
case GPX_DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically
retval = GPX_DocumentOpen("default.gpx",doc); // open the gpx-document with a standardname.
break;
 
case GPX_DOC_OPENED: // if a document has been opened before but no track exists:
retval = GPX_TrackBegin(doc);
break;
 
case GPX_DOC_TRACK_OPENED: // add tracksegement to the track
retval = GPX_TrackSegmentBegin(doc);
break;
 
default:
retval = 0;
break;
 
}
if(retval != 1) return(retval); // stop on error
}
 
if(doc->state == GPX_DOC_TRACKSEGMENT_OPENED) // if the document was opened add coordinates to the document.
{
retval = GPX_TrackSegementAddPoint(doc); // add a track segment point
}
return(retval);
}
 
/trunk/gpx.h
0,0 → 1,36
#ifndef _GPX_H
#define _GPX_H
 
#include "fat16.h"
#include "gps.h"
 
 
// possible state of a gpx-document
typedef enum
{
GPX_DOC_CLOSED,
GPX_DOC_OPENED,
GPX_DOC_TRACK_OPENED,
GPX_DOC_TRACKSEGMENT_OPENED,
GPX_DOC_END
}GPX_DocState_t;
 
 
// structure of an gpx-document
typedef struct gpx_doc
{
GPX_DocState_t state; // state of the gpx-document
File_t *file; // filepointer to the file where the data should be saved.
} GPX_Document_t;
 
u8 GPX_LoggGPSCoordinates(GPX_Document_t *); // intializes the gpx-document with standard filename and adds points to the file
u8 GPX_DocumentInit(GPX_Document_t *); // Init the new gpx-document
u8 GPX_DocumentOpen(s8 *, GPX_Document_t *); // opens a new gpx-document. a new file is created on the sd-memorycard
u8 GPX_DocumentClose(GPX_Document_t *doc); // closes the specified document saving remaining data to the file.
u8 GPX_TrackBegin(GPX_Document_t *doc); // opens a new track within the open gpx-document
u8 GPX_TrackEnd(GPX_Document_t *doc); // ends the actual track
u8 GPX_TrackSegmentBegin(GPX_Document_t *doc); // begins a new tracksegment within the actual track
u8 GPX_TrackSegmentEnd(GPX_Document_t *doc); // ends the actual track segment within the actual track
u8 GPX_TrackSegmentAddPoint(GPX_Document_t *); // adds a point to the tracksegment
 
#endif //_GPX_H
/trunk/gpx_header.h
0,0 → 1,70
//________________________________________________________________________________________________________________________________________
//
// Definition of gpx-header and footer elements for documents
//
//________________________________________________________________________________________________________________________________________
 
 
const s8 GPX_DOCUMENT_HEADER[] =
{
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\r\n"
"<gpx>\r\n"
"\r\n"
"<metadata>\r\n"
"<link href=\"http://www.mikrokopter.de\">\r\n"
"<text>MikroKopter</text>\r\n"
"</link>\r\n"
"</metadata>\r\n"
};
 
//________________________________________________________________________________________________________________________________________
//
// footer of an gpx-file.
//
//________________________________________________________________________________________________________________________________________
const s8 GPX_DOCUMENT_FOOTER[] =
{
"</gpx>\r\n"
};
 
//________________________________________________________________________________________________________________________________________
//
// Header of a track
//
//________________________________________________________________________________________________________________________________________
 
const s8 GPX_TRACK_HEADER[] =
{
"<trk>\r\n"
};
 
//________________________________________________________________________________________________________________________________________
//
// Footer of a track
//
//________________________________________________________________________________________________________________________________________
const s8 GPX_TRACK_FOOTER[] =
{
"</trk>\r\n"
};
 
//________________________________________________________________________________________________________________________________________
//
// Header of a track segment
//
//________________________________________________________________________________________________________________________________________
const s8 GPX_TRACKSEGMENT_HEADER[] =
{
"<trkseg>\r\n"
};
 
//________________________________________________________________________________________________________________________________________
//
// Footer of a track segment
//
//________________________________________________________________________________________________________________________________________
const s8 GPX_TRACKSEGMENT_FOOTER[] =
{
"</trkseg>\r\n"
};
 
/trunk/kml.c
64,9 → 64,9
//________________________________________________________________________________________________________________________________________
// Module name: kml.c
// Compiler used: avr-gcc 3.4.5
// Last Modifikation: 20.07.2008
// Version: 1.02
// Authors: Stephan Busker
// Last Modifikation: 22.03.2009
// Version: 1.03
// Authors: Stephan Busker, Gregor Stobrawa
// Description: Source files to write gps-coordinates to a file in the kml (keyhole markup language) fileformat
// Copyright (C) 2007 Stephan Busker
//........................................................................................................................................
74,8 → 74,8
// extern u8 KML_DocumentInit(KML_Document_t *doc) // initializes the kml-document to resetvalues.
// extern u8 KML_DocumentOpen(s8 *, KML_Document_t *); // opens a new kml document. A filename can be specified.
// extern u8 KML_DocumentClose(KML_Document_t *doc); // closes an open document
// extern u8 KML_PlaceMarkOpen(s8 *name, KML_Document_t *); // opens a new placemark within the specified document
// extern u8 KML_PlaceMarkClose( KML_Document_t *); // Closes the placemark
// extern u8 KML_PlaceMarkOpen(KML_Document_t *); // opens a new placemark within the specified document
// extern u8 KML_PlaceMarkClose(KML_Document_t *); // Closes the placemark
// extern u8 KML_LineStringBegin(KML_Document_t *); // begins a new line within the actual placemark
// extern u8 KML_LineStringEnd(KML_Document_t *doc); // ends the actual linestring
// extern u8 KML_LineStringAddPoint(struct str_gps_nav_data, KML_Document_t *); // adds a new point (gps-coordinates) to the actual linestring
100,12 → 100,9
//________________________________________________________________________________________________________________________________________
 
u8 KML_DocumentInit(KML_Document_t *doc)
{
doc->name[0] = 0; // name of the document
doc->state = DOC_CLOSED; // state of the kml-document
{
doc->state = KML_DOC_CLOSED; // state of the kml-document
doc->file = NULL;
doc->place.name[0]=0;
doc->place.description[0]=0;
return(1);
}
 
131,8 → 128,8
if(doc->file != NULL) // could the file be opened?
{
retvalue = 1; // the document could be created on the drive.
doc->state = DOC_OPENED; // change document state to opened. At next a placemark has to be opened.
fwrite_((void*)KML_DOCUMENT_HEADER, sizeof(KML_DOCUMENT_HEADER)-1,1,doc->file);// write the KML- footer to the document.
doc->state = KML_DOC_OPENED; // change document state to opened. At next a placemark has to be opened.
fwrite_((void*)KML_DOCUMENT_HEADER, sizeof(KML_DOCUMENT_HEADER)-1,1,doc->file);// write the KML-header to the document.
}
 
return(retvalue);
154,21 → 151,19
 
if(doc == NULL) return(0);
 
while(doc->state != DOC_CLOSED) // close linestring, placemark and document before closing the file on the memorycard
while(doc->state != KML_DOC_CLOSED) // close linestring, placemark and document before closing the file on the memorycard
{
switch(doc->state)
{
case DOC_LINESTRING_OPENED:
case KML_DOC_LINESTRING_OPENED:
KML_LineStringEnd(doc); // write terminating tag to end linestring.
doc->state = DOC_PLACEMARK_OPENED;
break;
 
case DOC_PLACEMARK_OPENED: // write terminating tag to close placemark.
case KML_DOC_PLACEMARK_OPENED: // write terminating tag to close placemark.
KML_PlaceMarkClose(doc);
doc->state = DOC_OPENED;
break;
 
case DOC_OPENED: // close the file on the memorycard
case KML_DOC_OPENED: // close the file on the memorycard
if(doc->file != NULL)
{
fwrite_((void*)KML_DOCUMENT_FOOTER, sizeof(KML_DOCUMENT_FOOTER)-1,1,doc->file); // write the KML- footer to the document.
175,11 → 170,11
fclose_(doc->file);
retvalue = 1;
}
doc->state = DOC_CLOSED;
doc->state = KML_DOC_CLOSED;
break;
 
default:
doc->state = DOC_CLOSED;
doc->state = KML_DOC_CLOSED;
break;
 
}
188,7 → 183,7
}
 
//________________________________________________________________________________________________________________________________________
// Function: u8 PlaceMarkOpen(s8 *name, File *file);
// Function: u8 KML_PlaceMarkOpen(KML_Document_t *doc);
//
// Description: This function adds a placemark to the document.
//
196,18 → 191,18
// Returnvalue: '1' if the PlaceMark could be opened
//________________________________________________________________________________________________________________________________________
 
u8 KML_PlaceMarkOpen(s8 *name, KML_Document_t *doc)
u8 KML_PlaceMarkOpen(KML_Document_t *doc)
{
 
u8 retvalue = 0;
 
if(doc->file != NULL)
if(doc->state == KML_DOC_OPENED)
{
doc->state = DOC_PLACEMARK_OPENED;
retvalue = 1;
fwrite_((void*)KML_PLACEMARK_HEADER, sizeof(KML_PLACEMARK_HEADER)-1,1,doc->file);
if(doc->file != NULL)
{
doc->state = KML_DOC_PLACEMARK_OPENED;
retvalue = 1;
fwrite_((void*)KML_PLACEMARK_HEADER, sizeof(KML_PLACEMARK_HEADER)-1,1,doc->file);
}
}
 
return(retvalue);
}
 
225,11 → 220,11
 
u8 retvalue = 0; // close the Placemark-tag of the corosponding document.
 
if(doc->state == DOC_PLACEMARK_OPENED)
if(doc->state == KML_DOC_PLACEMARK_OPENED)
{
if(doc->file != NULL)
{
doc->state = DOC_OPENED;
doc->state = KML_DOC_OPENED;
fwrite_((void*)KML_PLACEMARK_FOOTER, sizeof(KML_PLACEMARK_FOOTER)-1,1,doc->file);
retvalue = 1;
}
252,18 → 247,20
 
u8 retvalue = 0;
 
if(doc->file != NULL)
if(doc->state == KML_DOC_PLACEMARK_OPENED)
{
doc->state = DOC_LINESTRING_OPENED;
fwrite_((void*)KML_LINESTRING_HEADER, sizeof(KML_LINESTRING_HEADER)-1,1,doc->file);
retvalue = 1;
if(doc->file != NULL)
{
doc->state = KML_DOC_LINESTRING_OPENED;
fwrite_((void*)KML_LINESTRING_HEADER, sizeof(KML_LINESTRING_HEADER)-1,1,doc->file);
retvalue = 1;
}
}
 
return(retvalue);
}
 
//________________________________________________________________________________________________________________________________________
// Function: u8 LineStringEnd(KML_Document_t *doc)
// Function: u8 KML_LineStringEnd(KML_Document_t *doc)
//
// Description: This function ends the placemark opened before.
//
276,14 → 273,15
 
u8 retvalue = 0;
 
if(doc->state == DOC_LINESTRING_OPENED);
if(doc->file != NULL)
if(doc->state == KML_DOC_LINESTRING_OPENED)
{
doc->state = DOC_PLACEMARK_OPENED;
fwrite_((void*)KML_LINESTRING_FOOTER, sizeof(KML_LINESTRING_FOOTER)-1,1,doc->file);
retvalue = 1;
if(doc->file != NULL)
{
doc->state = KML_DOC_PLACEMARK_OPENED;
fwrite_((void*)KML_LINESTRING_FOOTER, sizeof(KML_LINESTRING_FOOTER)-1,1,doc->file);
retvalue = 1;
}
}
 
return(retvalue);
}
 
296,7 → 294,7
// Returnvalue: '1' if a ppoint was added could be started
//________________________________________________________________________________________________________________________________________
 
u8 KML_LineStringAddPoint(GPS_Pos_t * pGPS_Position ,KML_Document_t *doc)
u8 KML_LineStringAddPoint(KML_Document_t *doc)
{
 
u8 retvalue = 0;
303,30 → 301,30
s8 string[50];
s32 rel_altitude = 0;
 
if(doc == NULL || pGPS_Position == NULL) return(0);
if(doc == NULL) return(0);
 
if((pGPS_Position->Status != INVALID) && (GPS_HomePosition.Status != INVALID))
if((GPSData.Position.Status != INVALID) && (GPS_HomePosition.Status != INVALID))
{
if(doc->state == DOC_LINESTRING_OPENED)
if(doc->state == KML_DOC_LINESTRING_OPENED)
{
if(doc->file != NULL)
{
s32 i1, i2;
u8 sign;
if(pGPS_Position->Longitude < 0) sign = '-';
if(GPSData.Position.Longitude < 0) sign = '-';
else sign = '+';
i1 = abs(pGPS_Position->Longitude)/10000000L;
i2 = abs(pGPS_Position->Longitude)%10000000L;
i1 = abs(GPSData.Position.Longitude)/10000000L;
i2 = abs(GPSData.Position.Longitude)%10000000L;
sprintf(string,"\r\n%c%ld.%07ld,",sign, i1, i2);
fputs_(string, doc->file);
if(pGPS_Position->Latitude < 0) sign = '-';
if(GPSData.Position.Latitude < 0) sign = '-';
else sign = '+';
i1 = abs(pGPS_Position->Latitude)/10000000L;
i2 = abs(pGPS_Position->Latitude)%10000000L;
i1 = abs(GPSData.Position.Latitude)/10000000L;
i2 = abs(GPSData.Position.Latitude)%10000000L;
sprintf(string,"%c%ld.%07ld,",sign, i1, i2);
fputs_(string, doc->file);
// calculate relative altitude with respect to the altitude of the home position
rel_altitude = pGPS_Position->Altitude - GPS_HomePosition.Altitude;
rel_altitude = GPSData.Position.Altitude - GPS_HomePosition.Altitude;
if(rel_altitude < 0) rel_altitude = 0; // avoid negative altitudes in log
i1 = rel_altitude/1000L;
i2 = rel_altitude%1000L;
349,40 → 347,27
// Returnvalue: '1' if an gps coordinate was logged
//________________________________________________________________________________________________________________________________________
 
u8 KML_LoggGPSCoordinates(GPS_Pos_t* pGPS_Position, KML_Document_t *doc)
u8 KML_LoggGPSCoordinates(KML_Document_t *doc)
{
u8 retval = 0;
while(doc->state != DOC_LINESTRING_OPENED) // automatic create document with default filename on the card.
while(doc->state != KML_DOC_LINESTRING_OPENED) // automatic create document with default filename on the card.
{
switch(doc->state)
{
case DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically
KML_DocumentInit(doc); // initialize the document to default values
case KML_DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically
retval = KML_DocumentOpen("default.kml",doc); // open the kml-document with a standardname.
if(retval)
{
doc->state = DOC_OPENED;
}
break;
 
case DOC_OPENED: // if a document has been opened before but no placemark exists:
retval = KML_PlaceMarkOpen("MIKROKOPTER",doc);
if(retval)
{
doc->state = DOC_PLACEMARK_OPENED; // add a placemark to the document.
}
case KML_DOC_OPENED: // if a document has been opened before but no placemark exists:
retval = KML_PlaceMarkOpen(doc);
break;
 
case DOC_PLACEMARK_OPENED: // add linestring to the placemark
case KML_DOC_PLACEMARK_OPENED: // add linestring to the placemark
retval = KML_LineStringBegin(doc);
if(retval)
{
doc->state = DOC_LINESTRING_OPENED;
}
break;
 
default:
retval = 1;
retval = 0;
break;
 
}
389,9 → 374,9
if(retval != 1) return(retval); // stop on error
}
 
if(doc->state == DOC_LINESTRING_OPENED) // if the document was opened add coordinates to the document.
if(doc->state == KML_DOC_LINESTRING_OPENED) // if the document was opened add coordinates to the document.
{
retval = KML_LineStringAddPoint(pGPS_Position, doc);
retval = KML_LineStringAddPoint(doc);
}
return(retval);
}
/trunk/kml.h
8,43 → 8,30
// possible state of an kml-document
typedef enum
{
DOC_CLOSED,
DOC_OPENED,
DOC_PLACEMARK_OPENED,
DOC_LINESTRING_OPENED,
DOC_END
KML_DOC_CLOSED,
KML_DOC_OPENED,
KML_DOC_PLACEMARK_OPENED,
KML_DOC_LINESTRING_OPENED,
KML_DOC_END
}KML_DocState_t;
 
 
// structure of an kml-placemarkt
typedef struct kml_place
{
s8 name[10]; // the name of the placemark
s8 description[40]; // some text as a description to the placemark
} KML_PlaceMark_t;
 
 
 
// structure of an kml-document
typedef struct kml_doc
{
u8 name[40]; // name of the document
KML_DocState_t state; // state of the kml-document
File_t *file; // filepointer to the file where the data should be saved.
KML_PlaceMark_t place;
} KML_Document_t;
 
 
u8 KML_LoggGPSCoordinates(KML_Document_t *); // intializes the kml-document with standard filename and adds points to the file
u8 KML_DocumentInit(KML_Document_t *); // Init the new kml-document
u8 KML_DocumentOpen(s8 *, KML_Document_t *); // opens a new kml-document. a new file is created on the sd-memorycard
u8 KML_DocumentClose(KML_Document_t *doc); // closes the specified document saving remaining data to the file.
u8 KML_PlaceMarkOpen(KML_Document_t *doc); // opens a new placemark within the open kml-document
u8 KML_PlaceMarkClose(KML_Document_t *doc); // closes the actual placemark
u8 KML_LineStringBegin(KML_Document_t *doc); // begins a new linestring within the actual placemark
u8 KML_LineStringEnd(KML_Document_t *doc); // close the actual linestring within the actual placemark
u8 KML_LineStringAddPoint(KML_Document_t *); // adds a point from the gps (longitude, altitude, height) to the linestring
 
 
u8 KML_LoggGPSCoordinates(GPS_Pos_t* pGPS_Position , KML_Document_t *); // intializes the kml-document with standard filename and adds points to the file
u8 KML_DocumentInit(KML_Document_t *); // Init the new kml-document
u8 KML_DocumentOpen(s8 *, KML_Document_t *); // opens a new kml-document. a new file is created on the sd-memorycard
u8 KML_DocumentClose(KML_Document_t *doc); // closes the specified document saving remaining data to the file.
u8 KML_PlaceMarkOpen(s8 *name, KML_Document_t *doc); // opens a new placemark within the open kml-document
u8 KML_PlaceMarkClose(KML_Document_t *doc); // closes the actual placemark
u8 KML_LineStringBegin(KML_Document_t *doc); // begins a new linestring within the actual placemark
u8 KML_LineStringEnd(KML_Document_t *doc); // close the actual linestring within the actual placemark
u8 KML_LineStringAddPoint(GPS_Pos_t* pGPS_Position, KML_Document_t *); // adds a point from the gps (longitude, altitude, height) to the linestring
 
#endif //_KML_H
/trunk/kml_header.h
3,8 → 3,6
// Definition of KML header and footer elements for documents, placemarks and linestrings
//
//________________________________________________________________________________________________________________________________________
 
 
const s8 KML_DOCUMENT_HEADER[] =
{
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
20,16 → 18,11
"</Style>\r\n"
};
 
 
 
 
//________________________________________________________________________________________________________________________________________
//
// footer of an KML- file.
//
//________________________________________________________________________________________________________________________________________
 
 
const s8 KML_DOCUMENT_FOOTER[] =
{
"</Document>\r\n"
36,14 → 29,11
"</kml>\r\n"
};
 
 
 
//________________________________________________________________________________________________________________________________________
//
// Header of an placemark
//
//________________________________________________________________________________________________________________________________________
 
const s8 KML_PLACEMARK_HEADER[] =
{
"<Placemark>\r\n"
56,7 → 46,6
// Footer of an placemark
//
//________________________________________________________________________________________________________________________________________
 
const s8 KML_PLACEMARK_FOOTER[] =
{
"</Placemark>\r\n"
65,10 → 54,9
 
//________________________________________________________________________________________________________________________________________
//
// Footer of an placemark
// Header of an linestring
//
//________________________________________________________________________________________________________________________________________
 
const s8 KML_LINESTRING_HEADER[] =
{
"<LineString>\r\n"
82,7 → 70,6
// Footer of an linestring
//
//________________________________________________________________________________________________________________________________________
 
const s8 KML_LINESTRING_FOOTER[] =
{
"\r\n</coordinates>"
/trunk/logging.c
60,7 → 60,7
#include "timer.h"
#include "uart1.h"
#include "kml.h"
//#include "gpx.h"
#include "gpx.h"
 
typedef enum
{
84,7 → 84,6
LogCfg_t LogCfg = {500 , 0};
 
 
 
//----------------------------------------------------------------------------------------------------
s8* GenerateKMLLogFileName(void)
{
103,7 → 102,7
LastTime.Valid = 1;
filenum = 0; // reset file counter
}
sprintf(filename, "LOG/%04i%02i%02i/KLM/GPS%05i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum);
sprintf(filename, "LOG/%04i%02i%02i/KML/GPS%05i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum);
filenum++;
return filename;
}
174,7 → 173,7
{
case LOGFILE_IDLE:
case LOGFILE_CLOSED:
if((GPSData.Status != INVALID) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D) && (FC.MKFlags & MKFLAG_FLY))
if((GPSData.Status != INVALID) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D))// && (FC.MKFlags & MKFLAG_FLY))
{
logfilestate = LOGFILE_START;
}
216,7 → 215,7
// append new gps log data
if((GPSData.Status != INVALID) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D))
{
if(!KML_LoggGPSCoordinates(&(GPSData.Position), &logfile))
if(!KML_LoggGPSCoordinates(&logfile))
{ // error logging data
SerialPutString("\r\nError logging to kml-file\r\n");
KML_DocumentClose(&logfile);
258,8 → 257,115
// logs gps and state info to a gpx file
logfilestate_t Logging_GPX(u32 LogDelay)
{
static logfilestate_t logfilestate = LOGFILE_IDLE;
static logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate
static s8* logfilename = NULL; // the pointer to the logfilename
static u32 logtimer = 0; // the log update timer
static GPX_Document_t logfile; // the logfilehandle
 
// initialize if LogDelay os zero
if(!LogDelay)
{
switch(logfilestate)
{
case LOGFILE_OPENED:
GPX_DocumentClose(&logfile); // try to close it
break;
default:
break;
}
logfilestate = LOGFILE_IDLE;
logfilename = NULL;
GPX_DocumentInit(&logfile);
logtimer = SetDelay(0); // set logtimer to now
return logfilestate;
}
// no init
if(CheckDelay(logtimer))
{
logtimer = SetDelay(LogDelay); // standard interval
if(FC.MKFlags & MKFLAG_MOTOR_RUN)
{
switch(logfilestate)
{
case LOGFILE_IDLE:
case LOGFILE_CLOSED:
if((GPSData.Status != INVALID) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D))// && (FC.MKFlags & MKFLAG_FLY))
{
logfilestate = LOGFILE_START;
}
break;
case LOGFILE_START:
// find unused logfile name
do
{ // try to generate a new logfile name
logfilename = GenerateGPXLogFileName();
}while((logfilename != NULL) && fexist_(logfilename));
// if logfilename exist
if(logfilename != NULL)
{
// try to create the log file
if(GPX_DocumentOpen(logfilename, &logfile))
{
logfilestate = LOGFILE_OPENED; // goto next step
SerialPutString("\r\nOpening gpx-file:");
SerialPutString(logfilename);
SerialPutString("\r\n");
}
else // could not be openend
{
logfilestate = LOGFILE_ERROR;
SerialPutString("\r\nError opening gpx-file: ");
SerialPutString(logfilename);
SerialPutString("\r\n");
logtimer = SetDelay(10); // try again in open logfile in 10 mili sec
}
}
else
{
logfilestate = LOGFILE_ERROR;
SerialPutString("\r\nError getting free gpx-file name\r\n");
}
// else retry in next loop
break;
case LOGFILE_OPENED:
// append new gps log data
if((GPSData.Status != INVALID) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D))
{
if(!GPX_LoggGPSCoordinates(&logfile))
{ // error logging data
SerialPutString("\r\nError logging to gpx-file\r\n");
GPX_DocumentClose(&logfile);
logfilestate = LOGFILE_ERROR;
}
}
break;
case LOGFILE_ERROR:
break;
default:
logfilestate = LOGFILE_IDLE;
break;
}
} // EOF model is flying
else // model is not flying
{ // close log file if opened
if(logfilestate == LOGFILE_OPENED)
{
if(GPX_DocumentClose(&logfile))
{
SerialPutString("\r\nClosing gpx-file\r\n");
logfilestate = LOGFILE_CLOSED;
}
else // could not be closed
{
logfilestate = LOGFILE_ERROR;
}
}
} //EOF model is not flying
} // EOF Check LogTimer
 
return logfilestate;
}