Rev 360 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 360 | Rev 380 | ||
---|---|---|---|
1 | /*#######################################################################################*/ |
1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
3 | /*#######################################################################################*/ |
3 | /*#######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + www.MikroKopter.com |
5 | // + www.MikroKopter.com |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
7 | // + Software Nutzungsbedingungen (english version: see below) |
7 | // + Software Nutzungsbedingungen (english version: see below) |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
22 | // + des Mitverschuldens offen. |
22 | // + des Mitverschuldens offen. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
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. |
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
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 |
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
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 | // + 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. |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // + Software LICENSING TERMS |
32 | // + Software LICENSING TERMS |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
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 | // + 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 |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
37 | // + The Software may only be used with the Licensor's products. |
37 | // + The Software may only be used with the Licensor's products. |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
40 | // + agreement shall be the property of the Licensor. |
40 | // + agreement shall be the property of the Licensor. |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
43 | // + The customer shall be responsible for taking reasonable precautions |
43 | // + The customer shall be responsible for taking reasonable precautions |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
53 | // + #### END OF LICENSING TERMS #### |
53 | // + #### END OF LICENSING TERMS #### |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | #include <stdlib.h> |
56 | #include <stdlib.h> |
57 | #include <stdio.h> |
57 | #include <stdio.h> |
58 | #include "91x_lib.h" |
58 | #include "91x_lib.h" |
59 | #include "kml.h" |
59 | #include "kml.h" |
60 | #include "kml_header.h" |
60 | #include "kml_header.h" |
61 | #include "uart1.h" |
61 | #include "uart1.h" |
62 | - | ||
- | 62 | #include "logging.h" |
|
63 | 63 | ||
64 | //________________________________________________________________________________________________________________________________________ |
64 | //________________________________________________________________________________________________________________________________________ |
65 | // Module name: kml.c |
65 | // Module name: kml.c |
66 | // Compiler used: avr-gcc 3.4.5 |
66 | // Compiler used: avr-gcc 3.4.5 |
67 | // Last Modifikation: 22.03.2009 |
67 | // Last Modifikation: 22.03.2009 |
68 | // Version: 1.03 |
68 | // Version: 1.03 |
69 | // Authors: Stephan Busker, Gregor Stobrawa |
69 | // Authors: Stephan Busker, Gregor Stobrawa |
70 | // 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 |
71 | // Copyright (C) 2007 Stephan Busker |
71 | // Copyright (C) 2007 Stephan Busker |
72 | //........................................................................................................................................ |
72 | //........................................................................................................................................ |
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 |
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 |
74 | // 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. |
75 | // 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. |
76 | // 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 |
77 | // 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 |
78 | // extern u8 KML_PlaceMarkClose(KML_Document_t *); // Closes the placemark |
78 | // extern u8 KML_PlaceMarkClose(KML_Document_t *); // Closes the placemark |
79 | // 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 |
80 | // 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 |
81 | // 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 |
82 | //........................................................................................................................................ |
82 | //........................................................................................................................................ |
83 | // ext. functions: |
83 | // ext. functions: |
84 | // |
84 | // |
85 | //........................................................................................................................................ |
85 | //........................................................................................................................................ |
86 | // |
86 | // |
87 | // URL: www.Mikro-Control.de |
87 | // URL: www.Mikro-Control.de |
88 | // mailto: stephan.busker@mikro-control.de |
88 | // mailto: stephan.busker@mikro-control.de |
89 | //________________________________________________________________________________________________________________________________________ |
89 | //________________________________________________________________________________________________________________________________________ |
90 | 90 | ||
91 | 91 | ||
92 | 92 | ||
93 | //________________________________________________________________________________________________________________________________________ |
93 | //________________________________________________________________________________________________________________________________________ |
94 | // Function: KML_DocumentInit(KML_Document_t *) |
94 | // Function: KML_DocumentInit(KML_Document_t *) |
95 | // |
95 | // |
96 | // Description: This function initializes the kml-document for further use. |
96 | // Description: This function initializes the kml-document for further use. |
97 | // |
97 | // |
98 | // |
98 | // |
99 | // Returnvalue: '1' if document was initialized |
99 | // Returnvalue: '1' if document was initialized |
100 | //________________________________________________________________________________________________________________________________________ |
100 | //________________________________________________________________________________________________________________________________________ |
101 | 101 | ||
102 | u8 KML_DocumentInit(KML_Document_t *doc) |
102 | u8 KML_DocumentInit(KML_Document_t *doc) |
103 | { |
103 | { |
104 | doc->state = KML_DOC_CLOSED; // state of the kml-document |
104 | doc->state = KML_DOC_CLOSED; // state of the kml-document |
105 | doc->file = NULL; |
105 | doc->file = NULL; |
106 | return(1); |
106 | return(1); |
107 | } |
107 | } |
108 | 108 | ||
109 | //________________________________________________________________________________________________________________________________________ |
109 | //________________________________________________________________________________________________________________________________________ |
110 | // Function: KML_Document_Open(void); |
110 | // Function: KML_Document_Open(void); |
111 | // |
111 | // |
112 | // 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. |
113 | // |
113 | // |
114 | // |
114 | // |
115 | // Returnvalue: '1' if the KML- file could be created. |
115 | // Returnvalue: '1' if the KML- file could be created. |
116 | //________________________________________________________________________________________________________________________________________ |
116 | //________________________________________________________________________________________________________________________________________ |
117 | 117 | ||
118 | u8 KML_DocumentOpen(s8 *name, KML_Document_t *doc) |
118 | u8 KML_DocumentOpen(s8 *name, KML_Document_t *doc) |
119 | { |
119 | { |
120 | 120 | ||
121 | u8 retvalue = 0; |
121 | u8 retvalue = 0; |
122 | 122 | ||
123 | if(doc == NULL) return(0); |
123 | if(doc == NULL) return(0); |
124 | 124 | ||
125 | KML_DocumentInit(doc); // intialize the document with resetvalues |
125 | KML_DocumentInit(doc); // intialize the document with resetvalues |
126 | 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. |
127 | 127 | ||
128 | if(doc->file != NULL) // could the file be opened? |
128 | if(doc->file != NULL) // could the file be opened? |
129 | { |
129 | { |
130 | retvalue = 1; // the document could be created on the drive. |
130 | retvalue = 1; // the document could be created on the drive. |
131 | 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. |
132 | 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. |
133 | } |
133 | } |
134 | 134 | ||
135 | return(retvalue); |
135 | return(retvalue); |
136 | } |
136 | } |
137 | 137 | ||
138 | //________________________________________________________________________________________________________________________________________ |
138 | //________________________________________________________________________________________________________________________________________ |
139 | // Function: DocumentClose(KML_Document_t *doc); |
139 | // Function: DocumentClose(KML_Document_t *doc); |
140 | // |
140 | // |
141 | // Description: This function closes the document specified by doc. |
141 | // Description: This function closes the document specified by doc. |
142 | // |
142 | // |
143 | // |
143 | // |
144 | // Returnvalue: '1' if the KML- file could be closed. |
144 | // Returnvalue: '1' if the KML- file could be closed. |
145 | //________________________________________________________________________________________________________________________________________ |
145 | //________________________________________________________________________________________________________________________________________ |
146 | 146 | ||
147 | u8 KML_DocumentClose(KML_Document_t *doc) |
147 | u8 KML_DocumentClose(KML_Document_t *doc) |
148 | { |
148 | { |
149 | 149 | ||
150 | u8 retvalue = 1; |
150 | u8 retvalue = 1; |
151 | 151 | ||
152 | if(doc == NULL) return(0); |
152 | if(doc == NULL) return(0); |
153 | 153 | ||
154 | 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 |
155 | { |
155 | { |
156 | switch(doc->state) |
156 | switch(doc->state) |
157 | { |
157 | { |
158 | case KML_DOC_LINESTRING_OPENED: |
158 | case KML_DOC_LINESTRING_OPENED: |
159 | KML_LineStringEnd(doc); // write terminating tag to end linestring. |
159 | KML_LineStringEnd(doc); // write terminating tag to end linestring. |
160 | break; |
160 | break; |
161 | 161 | ||
162 | case KML_DOC_PLACEMARK_OPENED: // write terminating tag to close placemark. |
162 | case KML_DOC_PLACEMARK_OPENED: // write terminating tag to close placemark. |
163 | KML_PlaceMarkClose(doc); |
163 | KML_PlaceMarkClose(doc); |
164 | break; |
164 | break; |
165 | 165 | ||
166 | case KML_DOC_OPENED: // close the file on the memorycard |
166 | case KML_DOC_OPENED: // close the file on the memorycard |
167 | if(doc->file != NULL) |
167 | if(doc->file != NULL) |
168 | { |
168 | { |
169 | 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. |
170 | fclose_(doc->file); |
170 | fclose_(doc->file); |
171 | retvalue = 1; |
171 | retvalue = 1; |
172 | } |
172 | } |
173 | doc->state = KML_DOC_CLOSED; |
173 | doc->state = KML_DOC_CLOSED; |
174 | break; |
174 | break; |
175 | 175 | ||
176 | default: |
176 | default: |
177 | doc->state = KML_DOC_CLOSED; |
177 | doc->state = KML_DOC_CLOSED; |
178 | break; |
178 | break; |
179 | 179 | ||
180 | } |
180 | } |
181 | } |
181 | } |
182 | return(retvalue); |
182 | return(retvalue); |
183 | } |
183 | } |
184 | 184 | ||
185 | //________________________________________________________________________________________________________________________________________ |
185 | //________________________________________________________________________________________________________________________________________ |
186 | // Function: u8 KML_PlaceMarkOpen(KML_Document_t *doc); |
186 | // Function: u8 KML_PlaceMarkOpen(KML_Document_t *doc); |
187 | // |
187 | // |
188 | // Description: This function adds a placemark to the document. |
188 | // Description: This function adds a placemark to the document. |
189 | // |
189 | // |
190 | // |
190 | // |
191 | // Returnvalue: '1' if the PlaceMark could be opened |
191 | // Returnvalue: '1' if the PlaceMark could be opened |
192 | //________________________________________________________________________________________________________________________________________ |
192 | //________________________________________________________________________________________________________________________________________ |
193 | 193 | ||
194 | u8 KML_PlaceMarkOpen(KML_Document_t *doc) |
194 | u8 KML_PlaceMarkOpen(KML_Document_t *doc) |
195 | { |
195 | { |
196 | u8 retvalue = 0; |
196 | u8 retvalue = 0; |
197 | if(doc->state == KML_DOC_OPENED) |
197 | if(doc->state == KML_DOC_OPENED) |
198 | { |
198 | { |
199 | if(doc->file != NULL) |
199 | if(doc->file != NULL) |
200 | { |
200 | { |
201 | doc->state = KML_DOC_PLACEMARK_OPENED; |
201 | doc->state = KML_DOC_PLACEMARK_OPENED; |
202 | retvalue = 1; |
202 | retvalue = 1; |
203 | 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); |
204 | } |
204 | } |
205 | } |
205 | } |
206 | return(retvalue); |
206 | return(retvalue); |
207 | } |
207 | } |
208 | 208 | ||
209 | //________________________________________________________________________________________________________________________________________ |
209 | //________________________________________________________________________________________________________________________________________ |
210 | // Function: u8 PlaceMarkClose(KML_PlaceMark_t *place, File *file); |
210 | // Function: u8 PlaceMarkClose(KML_PlaceMark_t *place, File *file); |
211 | // |
211 | // |
212 | // Description: This function ends the placemark opened before. |
212 | // Description: This function ends the placemark opened before. |
213 | // |
213 | // |
214 | // |
214 | // |
215 | // Returnvalue: 1' if the PlaceMark could be closed |
215 | // Returnvalue: 1' if the PlaceMark could be closed |
216 | //________________________________________________________________________________________________________________________________________ |
216 | //________________________________________________________________________________________________________________________________________ |
217 | 217 | ||
218 | u8 KML_PlaceMarkClose(KML_Document_t *doc) |
218 | u8 KML_PlaceMarkClose(KML_Document_t *doc) |
219 | { |
219 | { |
220 | 220 | ||
221 | u8 retvalue = 0; // close the Placemark-tag of the corosponding document. |
221 | u8 retvalue = 0; // close the Placemark-tag of the corosponding document. |
222 | 222 | ||
223 | if(doc->state == KML_DOC_PLACEMARK_OPENED) |
223 | if(doc->state == KML_DOC_PLACEMARK_OPENED) |
224 | { |
224 | { |
225 | if(doc->file != NULL) |
225 | if(doc->file != NULL) |
226 | { |
226 | { |
227 | doc->state = KML_DOC_OPENED; |
227 | doc->state = KML_DOC_OPENED; |
228 | 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); |
229 | retvalue = 1; |
229 | retvalue = 1; |
230 | } |
230 | } |
231 | } |
231 | } |
232 | 232 | ||
233 | return(retvalue); |
233 | return(retvalue); |
234 | } |
234 | } |
235 | 235 | ||
236 | //________________________________________________________________________________________________________________________________________ |
236 | //________________________________________________________________________________________________________________________________________ |
237 | // Function: u8 LineStringBegin(KML_Document_t *doc); |
237 | // Function: u8 LineStringBegin(KML_Document_t *doc); |
238 | // |
238 | // |
239 | // Description: This function ends the placemark opened before. |
239 | // Description: This function ends the placemark opened before. |
240 | // |
240 | // |
241 | // |
241 | // |
242 | // Returnvalue: '1' if the LineString could be started |
242 | // Returnvalue: '1' if the LineString could be started |
243 | //________________________________________________________________________________________________________________________________________ |
243 | //________________________________________________________________________________________________________________________________________ |
244 | 244 | ||
245 | u8 KML_LineStringBegin(KML_Document_t *doc) |
245 | u8 KML_LineStringBegin(KML_Document_t *doc) |
246 | { |
246 | { |
247 | 247 | ||
248 | u8 retvalue = 0; |
248 | u8 retvalue = 0; |
249 | 249 | ||
250 | if(doc->state == KML_DOC_PLACEMARK_OPENED) |
250 | if(doc->state == KML_DOC_PLACEMARK_OPENED) |
251 | { |
251 | { |
252 | if(doc->file != NULL) |
252 | if(doc->file != NULL) |
253 | { |
253 | { |
254 | doc->state = KML_DOC_LINESTRING_OPENED; |
254 | doc->state = KML_DOC_LINESTRING_OPENED; |
255 | 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); |
- | 256 | Logged_KML_Counter = 0; |
|
256 | retvalue = 1; |
257 | retvalue = 1; |
257 | } |
258 | } |
258 | } |
259 | } |
259 | return(retvalue); |
260 | return(retvalue); |
260 | } |
261 | } |
261 | 262 | ||
262 | //________________________________________________________________________________________________________________________________________ |
263 | //________________________________________________________________________________________________________________________________________ |
263 | // Function: u8 KML_LineStringEnd(KML_Document_t *doc) |
264 | // Function: u8 KML_LineStringEnd(KML_Document_t *doc) |
264 | // |
265 | // |
265 | // Description: This function ends the placemark opened before. |
266 | // Description: This function ends the placemark opened before. |
266 | // |
267 | // |
267 | // |
268 | // |
268 | // Returnvalue: '1' if the LineString could be terminated |
269 | // Returnvalue: '1' if the LineString could be terminated |
269 | //________________________________________________________________________________________________________________________________________ |
270 | //________________________________________________________________________________________________________________________________________ |
270 | 271 | ||
271 | u8 KML_LineStringEnd(KML_Document_t *doc) |
272 | u8 KML_LineStringEnd(KML_Document_t *doc) |
272 | { |
273 | { |
273 | 274 | ||
274 | u8 retvalue = 0; |
275 | u8 retvalue = 0; |
275 | 276 | ||
276 | if(doc->state == KML_DOC_LINESTRING_OPENED) |
277 | if(doc->state == KML_DOC_LINESTRING_OPENED) |
277 | { |
278 | { |
278 | if(doc->file != NULL) |
279 | if(doc->file != NULL) |
279 | { |
280 | { |
280 | doc->state = KML_DOC_PLACEMARK_OPENED; |
281 | doc->state = KML_DOC_PLACEMARK_OPENED; |
281 | fwrite_((void*)KML_LINESTRING_FOOTER, sizeof(KML_LINESTRING_FOOTER)-1,1,doc->file); |
282 | fwrite_((void*)KML_LINESTRING_FOOTER, sizeof(KML_LINESTRING_FOOTER)-1,1,doc->file); |
282 | retvalue = 1; |
283 | retvalue = 1; |
283 | } |
284 | } |
284 | } |
285 | } |
285 | return(retvalue); |
286 | return(retvalue); |
286 | } |
287 | } |
287 | 288 | ||
288 | //________________________________________________________________________________________________________________________________________ |
289 | //________________________________________________________________________________________________________________________________________ |
289 | // Function: u8 LineStringAddPoint(gps_data_t, KML_Document_t *doc) |
290 | // Function: u8 LineStringAddPoint(gps_data_t, KML_Document_t *doc) |
290 | // |
291 | // |
291 | // Description: This function adds a point to the specified document. |
292 | // Description: This function adds a point to the specified document. |
292 | // |
293 | // |
293 | // |
294 | // |
294 | // Returnvalue: '1' if a ppoint was added could be started |
295 | // Returnvalue: '1' if a ppoint was added could be started |
295 | //________________________________________________________________________________________________________________________________________ |
296 | //________________________________________________________________________________________________________________________________________ |
296 | 297 | ||
297 | u8 KML_LineStringAddPoint(KML_Document_t *doc) |
298 | u8 KML_LineStringAddPoint(KML_Document_t *doc) |
298 | { |
299 | { |
299 | 300 | ||
300 | u8 retvalue = 0; |
301 | u8 retvalue = 0; |
301 | s8 string[50]; |
302 | s8 string[50]; |
302 | s32 rel_altitude = 0; |
303 | s32 rel_altitude = 0; |
303 | 304 | ||
304 | if(doc == NULL) return(0); |
305 | if(doc == NULL) return(0); |
305 | 306 | ||
306 | if((GPSData.Position.Status != INVALID) && (NaviData.HomePosition.Status != INVALID)) |
307 | if((GPSData.Position.Status != INVALID) && (NaviData.HomePosition.Status != INVALID)) |
307 | { |
308 | { |
308 | if(doc->state == KML_DOC_LINESTRING_OPENED) |
309 | if(doc->state == KML_DOC_LINESTRING_OPENED) |
309 | { |
310 | { |
310 | if(doc->file != NULL) |
311 | if(doc->file != NULL) |
311 | { |
312 | { |
312 | s32 i1, i2; |
313 | s32 i1, i2; |
313 | u8 sign; |
314 | u8 sign; |
314 | if(GPSData.Position.Longitude < 0) sign = '-'; |
315 | if(GPSData.Position.Longitude < 0) sign = '-'; |
315 | else sign = '+'; |
316 | else sign = '+'; |
316 | i1 = abs(GPSData.Position.Longitude)/10000000L; |
317 | i1 = abs(GPSData.Position.Longitude)/10000000L; |
317 | i2 = abs(GPSData.Position.Longitude)%10000000L; |
318 | i2 = abs(GPSData.Position.Longitude)%10000000L; |
318 | sprintf(string,"\r\n%c%ld.%07ld,",sign, i1, i2); |
319 | sprintf(string,"\r\n%c%ld.%07ld,",sign, i1, i2); |
319 | fputs_(string, doc->file); |
320 | fputs_(string, doc->file); |
320 | if(GPSData.Position.Latitude < 0) sign = '-'; |
321 | if(GPSData.Position.Latitude < 0) sign = '-'; |
321 | else sign = '+'; |
322 | else sign = '+'; |
322 | i1 = abs(GPSData.Position.Latitude)/10000000L; |
323 | i1 = abs(GPSData.Position.Latitude)/10000000L; |
323 | i2 = abs(GPSData.Position.Latitude)%10000000L; |
324 | i2 = abs(GPSData.Position.Latitude)%10000000L; |
324 | sprintf(string,"%c%ld.%07ld,",sign, i1, i2); |
325 | sprintf(string,"%c%ld.%07ld,",sign, i1, i2); |
325 | fputs_(string, doc->file); |
326 | fputs_(string, doc->file); |
326 | // calculate relative altitude with respect to the altitude of the home position |
327 | // calculate relative altitude with respect to the altitude of the home position |
327 | rel_altitude = GPSData.Position.Altitude - NaviData.HomePosition.Altitude; |
328 | rel_altitude = GPSData.Position.Altitude - NaviData.HomePosition.Altitude; |
328 | if(rel_altitude < 0) rel_altitude = 0; // avoid negative altitudes in log |
329 | if(rel_altitude < 0) rel_altitude = 0; // avoid negative altitudes in log |
329 | i1 = rel_altitude/1000L; |
330 | i1 = rel_altitude/1000L; |
330 | i2 = rel_altitude%1000L; |
331 | i2 = rel_altitude%1000L; |
331 | sprintf(string,"%ld.%03ld",i1, i2); |
332 | sprintf(string,"%ld.%03ld",i1, i2); |
332 | fputs_(string, doc->file); |
333 | fputs_(string, doc->file); |
- | 334 | Logged_KML_Counter++; |
|
333 | retvalue = 1; |
335 | retvalue = 1; |
334 | } |
336 | } |
335 | } |
337 | } |
336 | } |
338 | } |
337 | 339 | ||
338 | return(retvalue); |
340 | return(retvalue); |
339 | } |
341 | } |
340 | 342 | ||
341 | //________________________________________________________________________________________________________________________________________ |
343 | //________________________________________________________________________________________________________________________________________ |
342 | // Function: u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *) |
344 | // Function: u8 KML_LoggGPSCoordinates(gps_data_t *, KML_Document_t *) |
343 | // |
345 | // |
344 | // Description: This function opens adds gpscoordinates to an KML-Document. The document will be opened, if not already done |
346 | // Description: This function opens adds gpscoordinates to an KML-Document. The document will be opened, if not already done |
345 | // |
347 | // |
346 | // |
348 | // |
347 | // Returnvalue: '1' if an gps coordinate was logged |
349 | // Returnvalue: '1' if an gps coordinate was logged |
348 | //________________________________________________________________________________________________________________________________________ |
350 | //________________________________________________________________________________________________________________________________________ |
349 | 351 | ||
350 | u8 KML_LoggGPSCoordinates(KML_Document_t *doc) |
352 | u8 KML_LoggGPSCoordinates(KML_Document_t *doc) |
351 | { |
353 | { |
352 | u8 retval = 0; |
354 | u8 retval = 0; |
353 | while(doc->state != KML_DOC_LINESTRING_OPENED) // automatic create document with default filename on the card. |
355 | while(doc->state != KML_DOC_LINESTRING_OPENED) // automatic create document with default filename on the card. |
354 | { |
356 | { |
355 | switch(doc->state) |
357 | switch(doc->state) |
356 | { |
358 | { |
357 | case KML_DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically |
359 | case KML_DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically |
358 | retval = KML_DocumentOpen("default.kml",doc); // open the kml-document with a standardname. |
360 | retval = KML_DocumentOpen("default.kml",doc); // open the kml-document with a standardname. |
359 | break; |
361 | break; |
360 | 362 | ||
361 | case KML_DOC_OPENED: // if a document has been opened before but no placemark exists: |
363 | case KML_DOC_OPENED: // if a document has been opened before but no placemark exists: |
362 | retval = KML_PlaceMarkOpen(doc); |
364 | retval = KML_PlaceMarkOpen(doc); |
363 | break; |
365 | break; |
364 | 366 | ||
365 | case KML_DOC_PLACEMARK_OPENED: // add linestring to the placemark |
367 | case KML_DOC_PLACEMARK_OPENED: // add linestring to the placemark |
366 | retval = KML_LineStringBegin(doc); |
368 | retval = KML_LineStringBegin(doc); |
367 | break; |
369 | break; |
368 | 370 | ||
369 | default: |
371 | default: |
370 | retval = 0; |
372 | retval = 0; |
371 | break; |
373 | break; |
372 | 374 | ||
373 | } |
375 | } |
374 | if(retval != 1) return(retval); // stop on error |
376 | if(retval != 1) return(retval); // stop on error |
375 | } |
377 | } |
376 | 378 | ||
377 | if(doc->state == KML_DOC_LINESTRING_OPENED) // if the document was opened add coordinates to the document. |
379 | if(doc->state == KML_DOC_LINESTRING_OPENED) // if the document was opened add coordinates to the document. |
378 | { |
380 | { |
379 | retval = KML_LineStringAddPoint(doc); |
381 | retval = KML_LineStringAddPoint(doc); |
380 | } |
382 | } |
381 | return(retval); |
383 | return(retval); |
382 | } |
384 | } |
383 | 385 | ||
384 | 386 |