Rev 352 | Rev 380 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 352 | Rev 360 | ||
---|---|---|---|
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 |
- | |
6 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
- | |
7 | // + FOR NON COMMERCIAL USE ONLY |
- | |
8 | // + www.MikroKopter.com |
5 | // + www.MikroKopter.com |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
- | 7 | // + Software Nutzungsbedingungen (english version: see below) |
|
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
- | |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
22 | // + eindeutig als Ursprung verlinkt werden |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
25 | // + Benutzung auf eigene Gefahr |
22 | // + des Mitverschuldens offen. |
- | 23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
|
- | 24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
|
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
- | 26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
|
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
28 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
29 | // + mit unserer Zustimmung zulässig |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
- | 30 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
|
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
32 | // + Software LICENSING TERMS |
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
34 | // + this list of conditions and the following disclaimer. |
35 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
36 | // + from this software without specific prior written permission. |
37 | // + The Software may only be used with the Licensor's products. |
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
38 | // + for non-commercial use (directly or indirectly) |
- | |
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
40 | // + with our written permission |
40 | // + agreement shall be the property of the Licensor. |
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
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 |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
44 | // |
- | |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
43 | // + The customer shall be responsible for taking reasonable precautions |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
53 | // + #### END OF LICENSING TERMS #### |
- | 54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
|
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
57 | #include <stdlib.h> |
56 | #include <stdlib.h> |
58 | #include <stdio.h> |
57 | #include <stdio.h> |
59 | #include "91x_lib.h" |
58 | #include "91x_lib.h" |
60 | #include "kml.h" |
59 | #include "kml.h" |
61 | #include "kml_header.h" |
60 | #include "kml_header.h" |
62 | #include "uart1.h" |
61 | #include "uart1.h" |
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: 22.03.2009 |
67 | // Last Modifikation: 22.03.2009 |
69 | // Version: 1.03 |
68 | // Version: 1.03 |
70 | // Authors: Stephan Busker, Gregor Stobrawa |
69 | // Authors: Stephan Busker, Gregor Stobrawa |
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 |
72 | // Copyright (C) 2007 Stephan Busker |
71 | // Copyright (C) 2007 Stephan Busker |
73 | //........................................................................................................................................ |
72 | //........................................................................................................................................ |
74 | // Functions: extern u8 KML_LoggGPSCoordinates(struct str_gps_nav_data , KML_Document_t *); // intializes the kml-document with standard filename and adds points to the file |
73 | // Functions: extern u8 KML_LoggGPSCoordinates(struct str_gps_nav_data , KML_Document_t *); // intializes the kml-document with standard filename and adds points to the file |
75 | // extern u8 KML_DocumentInit(KML_Document_t *doc) // initializes the kml-document to resetvalues. |
74 | // extern u8 KML_DocumentInit(KML_Document_t *doc) // initializes the kml-document to resetvalues. |
76 | // extern u8 KML_DocumentOpen(s8 *, KML_Document_t *); // opens a new kml document. A filename can be specified. |
75 | // extern u8 KML_DocumentOpen(s8 *, KML_Document_t *); // opens a new kml document. A filename can be specified. |
77 | // extern u8 KML_DocumentClose(KML_Document_t *doc); // closes an open document |
76 | // extern u8 KML_DocumentClose(KML_Document_t *doc); // closes an open document |
78 | // extern u8 KML_PlaceMarkOpen(KML_Document_t *); // opens a new placemark within the specified document |
77 | // extern u8 KML_PlaceMarkOpen(KML_Document_t *); // opens a new placemark within the specified document |
79 | // extern u8 KML_PlaceMarkClose(KML_Document_t *); // Closes the placemark |
78 | // extern u8 KML_PlaceMarkClose(KML_Document_t *); // Closes the placemark |
80 | // extern u8 KML_LineStringBegin(KML_Document_t *); // begins a new line within the actual placemark |
79 | // extern u8 KML_LineStringBegin(KML_Document_t *); // begins a new line within the actual placemark |
81 | // extern u8 KML_LineStringEnd(KML_Document_t *doc); // ends the actual linestring |
80 | // extern u8 KML_LineStringEnd(KML_Document_t *doc); // ends the actual linestring |
82 | // extern u8 KML_LineStringAddPoint(struct str_gps_nav_data, KML_Document_t *); // adds a new point (gps-coordinates) to the actual linestring |
81 | // extern u8 KML_LineStringAddPoint(struct str_gps_nav_data, KML_Document_t *); // adds a new point (gps-coordinates) to the actual linestring |
83 | //........................................................................................................................................ |
82 | //........................................................................................................................................ |
84 | // ext. functions: |
83 | // ext. functions: |
85 | // |
84 | // |
86 | //........................................................................................................................................ |
85 | //........................................................................................................................................ |
87 | // |
86 | // |
88 | // URL: www.Mikro-Control.de |
87 | // URL: www.Mikro-Control.de |
89 | // mailto: stephan.busker@mikro-control.de |
88 | // mailto: stephan.busker@mikro-control.de |
90 | //________________________________________________________________________________________________________________________________________ |
89 | //________________________________________________________________________________________________________________________________________ |
91 | 90 | ||
92 | 91 | ||
93 | 92 | ||
94 | //________________________________________________________________________________________________________________________________________ |
93 | //________________________________________________________________________________________________________________________________________ |
95 | // Function: 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. |
98 | // |
97 | // |
99 | // |
98 | // |
100 | // Returnvalue: '1' if document was initialized |
99 | // Returnvalue: '1' if document was initialized |
101 | //________________________________________________________________________________________________________________________________________ |
100 | //________________________________________________________________________________________________________________________________________ |
102 | 101 | ||
103 | u8 KML_DocumentInit(KML_Document_t *doc) |
102 | u8 KML_DocumentInit(KML_Document_t *doc) |
104 | { |
103 | { |
105 | doc->state = KML_DOC_CLOSED; // state of the kml-document |
104 | doc->state = KML_DOC_CLOSED; // state of the kml-document |
106 | doc->file = NULL; |
105 | doc->file = NULL; |
107 | return(1); |
106 | return(1); |
108 | } |
107 | } |
109 | 108 | ||
110 | //________________________________________________________________________________________________________________________________________ |
109 | //________________________________________________________________________________________________________________________________________ |
111 | // Function: KML_Document_Open(void); |
110 | // Function: KML_Document_Open(void); |
112 | // |
111 | // |
113 | // Description: This function opens a new KML- document with the specified name and creates the document header within the file. |
112 | // Description: This function opens a new KML- document with the specified name and creates the document header within the file. |
114 | // |
113 | // |
115 | // |
114 | // |
116 | // Returnvalue: '1' if the KML- file could be created. |
115 | // Returnvalue: '1' if the KML- file could be created. |
117 | //________________________________________________________________________________________________________________________________________ |
116 | //________________________________________________________________________________________________________________________________________ |
118 | 117 | ||
119 | u8 KML_DocumentOpen(s8 *name, KML_Document_t *doc) |
118 | u8 KML_DocumentOpen(s8 *name, KML_Document_t *doc) |
120 | { |
119 | { |
121 | 120 | ||
122 | u8 retvalue = 0; |
121 | u8 retvalue = 0; |
123 | 122 | ||
124 | if(doc == NULL) return(0); |
123 | if(doc == NULL) return(0); |
125 | 124 | ||
126 | KML_DocumentInit(doc); // intialize the document with resetvalues |
125 | KML_DocumentInit(doc); // intialize the document with resetvalues |
127 | doc->file = fopen_(name,'a'); // open a new file with the specified filename on the memorycard. |
126 | doc->file = fopen_(name,'a'); // open a new file with the specified filename on the memorycard. |
128 | 127 | ||
129 | if(doc->file != NULL) // could the file be opened? |
128 | if(doc->file != NULL) // could the file be opened? |
130 | { |
129 | { |
131 | retvalue = 1; // the document could be created on the drive. |
130 | retvalue = 1; // the document could be created on the drive. |
132 | doc->state = KML_DOC_OPENED; // change document state to opened. At next a placemark has to be opened. |
131 | doc->state = KML_DOC_OPENED; // change document state to opened. At next a placemark has to be opened. |
133 | fwrite_((void*)KML_DOCUMENT_HEADER, sizeof(KML_DOCUMENT_HEADER)-1,1,doc->file);// write the KML-header to the document. |
132 | fwrite_((void*)KML_DOCUMENT_HEADER, sizeof(KML_DOCUMENT_HEADER)-1,1,doc->file);// write the KML-header to the document. |
134 | } |
133 | } |
135 | 134 | ||
136 | return(retvalue); |
135 | return(retvalue); |
137 | } |
136 | } |
138 | 137 | ||
139 | //________________________________________________________________________________________________________________________________________ |
138 | //________________________________________________________________________________________________________________________________________ |
140 | // Function: DocumentClose(KML_Document_t *doc); |
139 | // Function: DocumentClose(KML_Document_t *doc); |
141 | // |
140 | // |
142 | // Description: This function closes the document specified by doc. |
141 | // Description: This function closes the document specified by doc. |
143 | // |
142 | // |
144 | // |
143 | // |
145 | // Returnvalue: '1' if the KML- file could be closed. |
144 | // Returnvalue: '1' if the KML- file could be closed. |
146 | //________________________________________________________________________________________________________________________________________ |
145 | //________________________________________________________________________________________________________________________________________ |
147 | 146 | ||
148 | u8 KML_DocumentClose(KML_Document_t *doc) |
147 | u8 KML_DocumentClose(KML_Document_t *doc) |
149 | { |
148 | { |
150 | 149 | ||
151 | u8 retvalue = 1; |
150 | u8 retvalue = 1; |
152 | 151 | ||
153 | if(doc == NULL) return(0); |
152 | if(doc == NULL) return(0); |
154 | 153 | ||
155 | while(doc->state != KML_DOC_CLOSED) // close linestring, placemark and document before closing the file on the memorycard |
154 | while(doc->state != KML_DOC_CLOSED) // close linestring, placemark and document before closing the file on the memorycard |
156 | { |
155 | { |
157 | switch(doc->state) |
156 | switch(doc->state) |
158 | { |
157 | { |
159 | case KML_DOC_LINESTRING_OPENED: |
158 | case KML_DOC_LINESTRING_OPENED: |
160 | KML_LineStringEnd(doc); // write terminating tag to end linestring. |
159 | KML_LineStringEnd(doc); // write terminating tag to end linestring. |
161 | break; |
160 | break; |
162 | 161 | ||
163 | case KML_DOC_PLACEMARK_OPENED: // write terminating tag to close placemark. |
162 | case KML_DOC_PLACEMARK_OPENED: // write terminating tag to close placemark. |
164 | KML_PlaceMarkClose(doc); |
163 | KML_PlaceMarkClose(doc); |
165 | break; |
164 | break; |
166 | 165 | ||
167 | case KML_DOC_OPENED: // close the file on the memorycard |
166 | case KML_DOC_OPENED: // close the file on the memorycard |
168 | if(doc->file != NULL) |
167 | if(doc->file != NULL) |
169 | { |
168 | { |
170 | fwrite_((void*)KML_DOCUMENT_FOOTER, sizeof(KML_DOCUMENT_FOOTER)-1,1,doc->file); // write the KML- footer to the document. |
169 | fwrite_((void*)KML_DOCUMENT_FOOTER, sizeof(KML_DOCUMENT_FOOTER)-1,1,doc->file); // write the KML- footer to the document. |
171 | fclose_(doc->file); |
170 | fclose_(doc->file); |
172 | retvalue = 1; |
171 | retvalue = 1; |
173 | } |
172 | } |
174 | doc->state = KML_DOC_CLOSED; |
173 | doc->state = KML_DOC_CLOSED; |
175 | break; |
174 | break; |
176 | 175 | ||
177 | default: |
176 | default: |
178 | doc->state = KML_DOC_CLOSED; |
177 | doc->state = KML_DOC_CLOSED; |
179 | break; |
178 | break; |
180 | 179 | ||
181 | } |
180 | } |
182 | } |
181 | } |
183 | return(retvalue); |
182 | return(retvalue); |
184 | } |
183 | } |
185 | 184 | ||
186 | //________________________________________________________________________________________________________________________________________ |
185 | //________________________________________________________________________________________________________________________________________ |
187 | // Function: u8 KML_PlaceMarkOpen(KML_Document_t *doc); |
186 | // Function: u8 KML_PlaceMarkOpen(KML_Document_t *doc); |
188 | // |
187 | // |
189 | // Description: This function adds a placemark to the document. |
188 | // Description: This function adds a placemark to the document. |
190 | // |
189 | // |
191 | // |
190 | // |
192 | // Returnvalue: '1' if the PlaceMark could be opened |
191 | // Returnvalue: '1' if the PlaceMark could be opened |
193 | //________________________________________________________________________________________________________________________________________ |
192 | //________________________________________________________________________________________________________________________________________ |
194 | 193 | ||
195 | u8 KML_PlaceMarkOpen(KML_Document_t *doc) |
194 | u8 KML_PlaceMarkOpen(KML_Document_t *doc) |
196 | { |
195 | { |
197 | u8 retvalue = 0; |
196 | u8 retvalue = 0; |
198 | if(doc->state == KML_DOC_OPENED) |
197 | if(doc->state == KML_DOC_OPENED) |
199 | { |
198 | { |
200 | if(doc->file != NULL) |
199 | if(doc->file != NULL) |
201 | { |
200 | { |
202 | doc->state = KML_DOC_PLACEMARK_OPENED; |
201 | doc->state = KML_DOC_PLACEMARK_OPENED; |
203 | retvalue = 1; |
202 | retvalue = 1; |
204 | fwrite_((void*)KML_PLACEMARK_HEADER, sizeof(KML_PLACEMARK_HEADER)-1,1,doc->file); |
203 | fwrite_((void*)KML_PLACEMARK_HEADER, sizeof(KML_PLACEMARK_HEADER)-1,1,doc->file); |
205 | } |
204 | } |
206 | } |
205 | } |
207 | return(retvalue); |
206 | return(retvalue); |
208 | } |
207 | } |
209 | 208 | ||
210 | //________________________________________________________________________________________________________________________________________ |
209 | //________________________________________________________________________________________________________________________________________ |
211 | // Function: u8 PlaceMarkClose(KML_PlaceMark_t *place, File *file); |
210 | // Function: u8 PlaceMarkClose(KML_PlaceMark_t *place, File *file); |
212 | // |
211 | // |
213 | // Description: This function ends the placemark opened before. |
212 | // Description: This function ends the placemark opened before. |
214 | // |
213 | // |
215 | // |
214 | // |
216 | // Returnvalue: 1' if the PlaceMark could be closed |
215 | // Returnvalue: 1' if the PlaceMark could be closed |
217 | //________________________________________________________________________________________________________________________________________ |
216 | //________________________________________________________________________________________________________________________________________ |
218 | 217 | ||
219 | u8 KML_PlaceMarkClose(KML_Document_t *doc) |
218 | u8 KML_PlaceMarkClose(KML_Document_t *doc) |
220 | { |
219 | { |
221 | 220 | ||
222 | u8 retvalue = 0; // close the Placemark-tag of the corosponding document. |
221 | u8 retvalue = 0; // close the Placemark-tag of the corosponding document. |
223 | 222 | ||
224 | if(doc->state == KML_DOC_PLACEMARK_OPENED) |
223 | if(doc->state == KML_DOC_PLACEMARK_OPENED) |
225 | { |
224 | { |
226 | if(doc->file != NULL) |
225 | if(doc->file != NULL) |
227 | { |
226 | { |
228 | doc->state = KML_DOC_OPENED; |
227 | doc->state = KML_DOC_OPENED; |
229 | fwrite_((void*)KML_PLACEMARK_FOOTER, sizeof(KML_PLACEMARK_FOOTER)-1,1,doc->file); |
228 | fwrite_((void*)KML_PLACEMARK_FOOTER, sizeof(KML_PLACEMARK_FOOTER)-1,1,doc->file); |
230 | retvalue = 1; |
229 | retvalue = 1; |
231 | } |
230 | } |
232 | } |
231 | } |
233 | 232 | ||
234 | return(retvalue); |
233 | return(retvalue); |
235 | } |
234 | } |
236 | 235 | ||
237 | //________________________________________________________________________________________________________________________________________ |
236 | //________________________________________________________________________________________________________________________________________ |
238 | // Function: u8 LineStringBegin(KML_Document_t *doc); |
237 | // Function: u8 LineStringBegin(KML_Document_t *doc); |
239 | // |
238 | // |
240 | // Description: This function ends the placemark opened before. |
239 | // Description: This function ends the placemark opened before. |
241 | // |
240 | // |
242 | // |
241 | // |
243 | // Returnvalue: '1' if the LineString could be started |
242 | // Returnvalue: '1' if the LineString could be started |
244 | //________________________________________________________________________________________________________________________________________ |
243 | //________________________________________________________________________________________________________________________________________ |
245 | 244 | ||
246 | u8 KML_LineStringBegin(KML_Document_t *doc) |
245 | u8 KML_LineStringBegin(KML_Document_t *doc) |
247 | { |
246 | { |
248 | 247 | ||
249 | u8 retvalue = 0; |
248 | u8 retvalue = 0; |
250 | 249 | ||
251 | if(doc->state == KML_DOC_PLACEMARK_OPENED) |
250 | if(doc->state == KML_DOC_PLACEMARK_OPENED) |
252 | { |
251 | { |
253 | if(doc->file != NULL) |
252 | if(doc->file != NULL) |
254 | { |
253 | { |
255 | doc->state = KML_DOC_LINESTRING_OPENED; |
254 | doc->state = KML_DOC_LINESTRING_OPENED; |
256 | fwrite_((void*)KML_LINESTRING_HEADER, sizeof(KML_LINESTRING_HEADER)-1,1,doc->file); |
255 | fwrite_((void*)KML_LINESTRING_HEADER, sizeof(KML_LINESTRING_HEADER)-1,1,doc->file); |
257 | retvalue = 1; |
256 | retvalue = 1; |
258 | } |
257 | } |
259 | } |
258 | } |
260 | return(retvalue); |
259 | return(retvalue); |
261 | } |
260 | } |
262 | 261 | ||
263 | //________________________________________________________________________________________________________________________________________ |
262 | //________________________________________________________________________________________________________________________________________ |
264 | // Function: u8 KML_LineStringEnd(KML_Document_t *doc) |
263 | // Function: u8 KML_LineStringEnd(KML_Document_t *doc) |
265 | // |
264 | // |
266 | // Description: This function ends the placemark opened before. |
265 | // Description: This function ends the placemark opened before. |
267 | // |
266 | // |
268 | // |
267 | // |
269 | // Returnvalue: '1' if the LineString could be terminated |
268 | // Returnvalue: '1' if the LineString could be terminated |
270 | //________________________________________________________________________________________________________________________________________ |
269 | //________________________________________________________________________________________________________________________________________ |
271 | 270 | ||
272 | u8 KML_LineStringEnd(KML_Document_t *doc) |
271 | u8 KML_LineStringEnd(KML_Document_t *doc) |
273 | { |
272 | { |
274 | 273 | ||
275 | u8 retvalue = 0; |
274 | u8 retvalue = 0; |
276 | 275 | ||
277 | if(doc->state == KML_DOC_LINESTRING_OPENED) |
276 | if(doc->state == KML_DOC_LINESTRING_OPENED) |
278 | { |
277 | { |
279 | if(doc->file != NULL) |
278 | if(doc->file != NULL) |
280 | { |
279 | { |
281 | doc->state = KML_DOC_PLACEMARK_OPENED; |
280 | doc->state = KML_DOC_PLACEMARK_OPENED; |
282 | fwrite_((void*)KML_LINESTRING_FOOTER, sizeof(KML_LINESTRING_FOOTER)-1,1,doc->file); |
281 | fwrite_((void*)KML_LINESTRING_FOOTER, sizeof(KML_LINESTRING_FOOTER)-1,1,doc->file); |
283 | retvalue = 1; |
282 | retvalue = 1; |
284 | } |
283 | } |
285 | } |
284 | } |
286 | return(retvalue); |
285 | return(retvalue); |
287 | } |
286 | } |
288 | 287 | ||
289 | //________________________________________________________________________________________________________________________________________ |
288 | //________________________________________________________________________________________________________________________________________ |
290 | // Function: u8 LineStringAddPoint(gps_data_t, KML_Document_t *doc) |
289 | // Function: u8 LineStringAddPoint(gps_data_t, KML_Document_t *doc) |
291 | // |
290 | // |
292 | // Description: This function adds a point to the specified document. |
291 | // Description: This function adds a point to the specified document. |
293 | // |
292 | // |
294 | // |
293 | // |
295 | // Returnvalue: '1' if a ppoint was added could be started |
294 | // Returnvalue: '1' if a ppoint was added could be started |
296 | //________________________________________________________________________________________________________________________________________ |
295 | //________________________________________________________________________________________________________________________________________ |
297 | 296 | ||
298 | u8 KML_LineStringAddPoint(KML_Document_t *doc) |
297 | u8 KML_LineStringAddPoint(KML_Document_t *doc) |
299 | { |
298 | { |
300 | 299 | ||
301 | u8 retvalue = 0; |
300 | u8 retvalue = 0; |
302 | s8 string[50]; |
301 | s8 string[50]; |
303 | s32 rel_altitude = 0; |
302 | s32 rel_altitude = 0; |
304 | 303 | ||
305 | if(doc == NULL) return(0); |
304 | if(doc == NULL) return(0); |
306 | 305 | ||
307 | if((GPSData.Position.Status != INVALID) && (NaviData.HomePosition.Status != INVALID)) |
306 | if((GPSData.Position.Status != INVALID) && (NaviData.HomePosition.Status != INVALID)) |
308 | { |
307 | { |
309 | if(doc->state == KML_DOC_LINESTRING_OPENED) |
308 | if(doc->state == KML_DOC_LINESTRING_OPENED) |
310 | { |
309 | { |
311 | if(doc->file != NULL) |
310 | if(doc->file != NULL) |
312 | { |
311 | { |
313 | s32 i1, i2; |
312 | s32 i1, i2; |
314 | u8 sign; |
313 | u8 sign; |
315 | if(GPSData.Position.Longitude < 0) sign = '-'; |
314 | if(GPSData.Position.Longitude < 0) sign = '-'; |
316 | else sign = '+'; |
315 | else sign = '+'; |
317 | i1 = abs(GPSData.Position.Longitude)/10000000L; |
316 | i1 = abs(GPSData.Position.Longitude)/10000000L; |
318 | i2 = abs(GPSData.Position.Longitude)%10000000L; |
317 | i2 = abs(GPSData.Position.Longitude)%10000000L; |
319 | sprintf(string,"\r\n%c%ld.%07ld,",sign, i1, i2); |
318 | sprintf(string,"\r\n%c%ld.%07ld,",sign, i1, i2); |
320 | fputs_(string, doc->file); |
319 | fputs_(string, doc->file); |
321 | if(GPSData.Position.Latitude < 0) sign = '-'; |
320 | if(GPSData.Position.Latitude < 0) sign = '-'; |
322 | else sign = '+'; |
321 | else sign = '+'; |
323 | i1 = abs(GPSData.Position.Latitude)/10000000L; |
322 | i1 = abs(GPSData.Position.Latitude)/10000000L; |
324 | i2 = abs(GPSData.Position.Latitude)%10000000L; |
323 | i2 = abs(GPSData.Position.Latitude)%10000000L; |
325 | sprintf(string,"%c%ld.%07ld,",sign, i1, i2); |
324 | sprintf(string,"%c%ld.%07ld,",sign, i1, i2); |
326 | fputs_(string, doc->file); |
325 | fputs_(string, doc->file); |
327 | // calculate relative altitude with respect to the altitude of the home position |
326 | // calculate relative altitude with respect to the altitude of the home position |
328 | rel_altitude = GPSData.Position.Altitude - NaviData.HomePosition.Altitude; |
327 | rel_altitude = GPSData.Position.Altitude - NaviData.HomePosition.Altitude; |
329 | if(rel_altitude < 0) rel_altitude = 0; // avoid negative altitudes in log |
328 | if(rel_altitude < 0) rel_altitude = 0; // avoid negative altitudes in log |
330 | i1 = rel_altitude/1000L; |
329 | i1 = rel_altitude/1000L; |
331 | i2 = rel_altitude%1000L; |
330 | i2 = rel_altitude%1000L; |
332 | sprintf(string,"%ld.%03ld",i1, i2); |
331 | sprintf(string,"%ld.%03ld",i1, i2); |
333 | fputs_(string, doc->file); |
332 | fputs_(string, doc->file); |
334 | retvalue = 1; |
333 | retvalue = 1; |
335 | } |
334 | } |
336 | } |
335 | } |
337 | } |
336 | } |
338 | 337 | ||
339 | return(retvalue); |
338 | return(retvalue); |
340 | } |
339 | } |
341 | 340 | ||
342 | //________________________________________________________________________________________________________________________________________ |
341 | //________________________________________________________________________________________________________________________________________ |
343 | // Function: u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *) |
342 | // Function: u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *) |
344 | // |
343 | // |
345 | // Description: This function opens adds gpscoordinates to an KML-Document. The document will be opened, if not already done |
344 | // Description: This function opens adds gpscoordinates to an KML-Document. The document will be opened, if not already done |
346 | // |
345 | // |
347 | // |
346 | // |
348 | // Returnvalue: '1' if an gps coordinate was logged |
347 | // Returnvalue: '1' if an gps coordinate was logged |
349 | //________________________________________________________________________________________________________________________________________ |
348 | //________________________________________________________________________________________________________________________________________ |
350 | 349 | ||
351 | u8 KML_LoggGPSCoordinates(KML_Document_t *doc) |
350 | u8 KML_LoggGPSCoordinates(KML_Document_t *doc) |
352 | { |
351 | { |
353 | u8 retval = 0; |
352 | u8 retval = 0; |
354 | while(doc->state != KML_DOC_LINESTRING_OPENED) // automatic create document with default filename on the card. |
353 | while(doc->state != KML_DOC_LINESTRING_OPENED) // automatic create document with default filename on the card. |
355 | { |
354 | { |
356 | switch(doc->state) |
355 | switch(doc->state) |
357 | { |
356 | { |
358 | case KML_DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically |
357 | case KML_DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically |
359 | retval = KML_DocumentOpen("default.kml",doc); // open the kml-document with a standardname. |
358 | retval = KML_DocumentOpen("default.kml",doc); // open the kml-document with a standardname. |
360 | break; |
359 | break; |
361 | 360 | ||
362 | case KML_DOC_OPENED: // if a document has been opened before but no placemark exists: |
361 | case KML_DOC_OPENED: // if a document has been opened before but no placemark exists: |
363 | retval = KML_PlaceMarkOpen(doc); |
362 | retval = KML_PlaceMarkOpen(doc); |
364 | break; |
363 | break; |
365 | 364 | ||
366 | case KML_DOC_PLACEMARK_OPENED: // add linestring to the placemark |
365 | case KML_DOC_PLACEMARK_OPENED: // add linestring to the placemark |
367 | retval = KML_LineStringBegin(doc); |
366 | retval = KML_LineStringBegin(doc); |
368 | break; |
367 | break; |
369 | 368 | ||
370 | default: |
369 | default: |
371 | retval = 0; |
370 | retval = 0; |
372 | break; |
371 | break; |
373 | 372 | ||
374 | } |
373 | } |
375 | if(retval != 1) return(retval); // stop on error |
374 | if(retval != 1) return(retval); // stop on error |
376 | } |
375 | } |
377 | 376 | ||
378 | if(doc->state == KML_DOC_LINESTRING_OPENED) // if the document was opened add coordinates to the document. |
377 | if(doc->state == KML_DOC_LINESTRING_OPENED) // if the document was opened add coordinates to the document. |
379 | { |
378 | { |
380 | retval = KML_LineStringAddPoint(doc); |
379 | retval = KML_LineStringAddPoint(doc); |
381 | } |
380 | } |
382 | return(retval); |
381 | return(retval); |
383 | } |
382 | } |
384 | 383 | ||
385 | 384 |