Rev 722 | Rev 738 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 722 | Rev 726 | ||
---|---|---|---|
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 <stdio.h> |
56 | #include <stdio.h> |
57 | #include <stdlib.h> |
57 | #include <stdlib.h> |
58 | #include "91x_lib.h" |
58 | #include "91x_lib.h" |
59 | #include "main.h" |
59 | #include "main.h" |
60 | #include "timer1.h" |
60 | #include "timer1.h" |
61 | #include "timer2.h" |
61 | #include "timer2.h" |
62 | #include "uart1.h" |
62 | #include "uart1.h" |
63 | #include "triggerlog.h" |
63 | #include "triggerlog.h" |
64 | #include "gpx.h" |
64 | #include "gpx.h" |
65 | #include "ssc.h" |
65 | #include "ssc.h" |
66 | #include "settings.h" |
66 | #include "settings.h" |
67 | #include "led.h" |
67 | #include "led.h" |
68 | #include "logging.h" |
68 | #include "logging.h" |
69 | #include "timer1.h" |
69 | #include "timer1.h" |
70 | #include "gps.h" |
70 | #include "gps.h" |
71 | #include "spi_slave.h" |
71 | #include "spi_slave.h" |
72 | 72 | ||
73 | u16 Logged_TRIG_Counter = 0; |
73 | u16 Logged_TRIG_Counter = 0; |
74 | u16 TRIG_Filenum = 0; |
74 | u16 TRIG_Filenum = 0; |
75 | u8 BlitzSchuhConnected = 1; |
75 | u8 BlitzSchuhConnected = 1; |
76 | 76 | ||
77 | TrigLog_t TrigLogging; |
77 | TrigLog_t TrigLogging; |
78 | 78 | ||
79 | void TriggerInput(void) // triggerinput on IO1 |
79 | void TriggerInput(void) // triggerinput on IO1 |
80 | { |
80 | { |
81 | TrigLogging.Longitude = GPSData.Position.Longitude; |
81 | TrigLogging.Longitude = GPSData.Position.Longitude; |
82 | TrigLogging.Latitude = GPSData.Position.Latitude; |
82 | TrigLogging.Latitude = GPSData.Position.Latitude; |
83 | TrigLogging.Count++; |
83 | TrigLogging.Count++; |
- | 84 | if(BlitzSchuhConnected) TrigLogging.CountExternal++; |
|
- | 85 | else TrigLogging.CountExternal = 0; |
|
84 | TrigLogging.AltiBaro = NaviData.Altimeter * 5; // in cm |
86 | TrigLogging.AltiBaro = NaviData.Altimeter * 5; // in cm |
85 | TrigLogging.AltiGPS = GPSData.Position.Altitude; |
87 | TrigLogging.AltiGPS = GPSData.Position.Altitude; |
86 | TrigLogging.ShutterCounter = NaviData_Volatile.ShutterCounter; |
88 | TrigLogging.ShutterCounter = NaviData_Volatile.ShutterCounter; |
87 | 89 | ||
88 | TrigLogging.Hour = SystemTime.Hour; |
90 | TrigLogging.Hour = SystemTime.Hour; |
89 | TrigLogging.Min = SystemTime.Min; |
91 | TrigLogging.Min = SystemTime.Min; |
90 | TrigLogging.Sec = SystemTime.Sec; |
92 | TrigLogging.Sec = SystemTime.Sec; |
91 | TrigLogging.mSec = SystemTime.mSec; |
93 | TrigLogging.mSec = SystemTime.mSec; |
92 | TrigLogging.ServoControlNick = ServoParams.NickControl; |
94 | TrigLogging.ServoControlNick = ServoParams.NickControl; |
93 | TrigLogging.ServoControlPoi = POI_KameraNick; |
95 | TrigLogging.ServoControlPoi = POI_KameraNick; |
94 | if(SimulationFlags) TrigLogging.Yaw = CompassSetpointCorrected; |
96 | if(SimulationFlags) TrigLogging.Yaw = CompassSetpointCorrected; |
95 | else TrigLogging.Yaw = GyroCompassCorrected; |
97 | else TrigLogging.Yaw = GyroCompassCorrected; |
96 | TrigLogging.NewData++; |
98 | TrigLogging.NewData++; |
97 | } |
99 | } |
98 | 100 | ||
99 | const s8 TRIG_DOCUMENT_FOOTER[] = |
101 | const s8 TRIG_DOCUMENT_FOOTER[] = |
100 | { |
102 | { |
101 | "\r\n" |
103 | "\r\n" |
102 | "#Triggerlogfile closed\r\n" |
104 | "#Triggerlogfile closed\r\n" |
103 | }; |
105 | }; |
104 | 106 | ||
105 | //________________________________________________________________________________________________________________________________________ |
107 | //________________________________________________________________________________________________________________________________________ |
106 | // Function: TRIG_DocumentInit(TRIG_Document_t *) |
108 | // Function: TRIG_DocumentInit(TRIG_Document_t *) |
107 | // |
109 | // |
108 | // Description: This function initializes the kml-document for further use. |
110 | // Description: This function initializes the kml-document for further use. |
109 | // |
111 | // |
110 | // |
112 | // |
111 | // Returnvalue: '1' if document was initialized |
113 | // Returnvalue: '1' if document was initialized |
112 | //________________________________________________________________________________________________________________________________________ |
114 | //________________________________________________________________________________________________________________________________________ |
113 | 115 | ||
114 | u8 TRIG_DocumentInit(TRIG_Document_t *doc) |
116 | u8 TRIG_DocumentInit(TRIG_Document_t *doc) |
115 | { |
117 | { |
116 | doc->state = TRIG_DOC_CLOSED; // state of the kml-document |
118 | doc->state = TRIG_DOC_CLOSED; // state of the kml-document |
117 | doc->file = NULL; |
119 | doc->file = NULL; |
118 | return(1); |
120 | return(1); |
119 | } |
121 | } |
120 | 122 | ||
121 | 123 | ||
122 | //________________________________________________________________________________________________________________________________________ |
124 | //________________________________________________________________________________________________________________________________________ |
123 | // Function: DocumentClose(TRIG_Document_t *doc); |
125 | // Function: DocumentClose(TRIG_Document_t *doc); |
124 | // |
126 | // |
125 | // Description: This function closes the document specified by doc. |
127 | // Description: This function closes the document specified by doc. |
126 | // |
128 | // |
127 | // |
129 | // |
128 | // Returnvalue: '1' if the KML- file could be closed. |
130 | // Returnvalue: '1' if the KML- file could be closed. |
129 | //________________________________________________________________________________________________________________________________________ |
131 | //________________________________________________________________________________________________________________________________________ |
130 | 132 | ||
131 | u8 TRIG_DocumentClose(TRIG_Document_t *doc) |
133 | u8 TRIG_DocumentClose(TRIG_Document_t *doc) |
132 | { |
134 | { |
133 | 135 | ||
134 | u8 retvalue = 1; |
136 | u8 retvalue = 1; |
135 | 137 | ||
136 | if(doc == NULL) return(0); |
138 | if(doc == NULL) return(0); |
137 | 139 | ||
138 | while(doc->state != TRIG_DOC_CLOSED) // close linestring, placemark and document before closing the file on the memorycard |
140 | while(doc->state != TRIG_DOC_CLOSED) // close linestring, placemark and document before closing the file on the memorycard |
139 | { |
141 | { |
140 | switch(doc->state) |
142 | switch(doc->state) |
141 | { |
143 | { |
142 | case TRIG_DOC_LINESTRING_OPENED: |
144 | case TRIG_DOC_LINESTRING_OPENED: |
143 | TRIG_LineStringEnd(doc); // write terminating tag to end linestring. |
145 | TRIG_LineStringEnd(doc); // write terminating tag to end linestring. |
144 | break; |
146 | break; |
145 | 147 | ||
146 | case TRIG_DOC_PLACEMARK_OPENED: // write terminating tag to close placemark. |
148 | case TRIG_DOC_PLACEMARK_OPENED: // write terminating tag to close placemark. |
147 | TRIG_PlaceMarkClose(doc); |
149 | TRIG_PlaceMarkClose(doc); |
148 | break; |
150 | break; |
149 | 151 | ||
150 | case TRIG_DOC_OPENED: // close the file on the memorycard |
152 | case TRIG_DOC_OPENED: // close the file on the memorycard |
151 | if(doc->file != NULL) |
153 | if(doc->file != NULL) |
152 | { |
154 | { |
153 | fwrite_((void*)TRIG_DOCUMENT_FOOTER, sizeof(TRIG_DOCUMENT_FOOTER)-1,1,doc->file); // write the KML- footer to the document. |
155 | fwrite_((void*)TRIG_DOCUMENT_FOOTER, sizeof(TRIG_DOCUMENT_FOOTER)-1,1,doc->file); // write the KML- footer to the document. |
154 | fclose_(doc->file); |
156 | fclose_(doc->file); |
155 | retvalue = 1; |
157 | retvalue = 1; |
156 | } |
158 | } |
157 | doc->state = TRIG_DOC_CLOSED; |
159 | doc->state = TRIG_DOC_CLOSED; |
158 | break; |
160 | break; |
159 | 161 | ||
160 | default: |
162 | default: |
161 | doc->state = TRIG_DOC_CLOSED; |
163 | doc->state = TRIG_DOC_CLOSED; |
162 | break; |
164 | break; |
163 | 165 | ||
164 | } |
166 | } |
165 | } |
167 | } |
166 | return(retvalue); |
168 | return(retvalue); |
167 | } |
169 | } |
168 | 170 | ||
169 | //________________________________________________________________________________________________________________________________________ |
171 | //________________________________________________________________________________________________________________________________________ |
170 | // Function: u8 TRIG_PlaceMarkOpen(TRIG_Document_t *doc); |
172 | // Function: u8 TRIG_PlaceMarkOpen(TRIG_Document_t *doc); |
171 | // |
173 | // |
172 | // Description: This function adds a placemark to the document. |
174 | // Description: This function adds a placemark to the document. |
173 | // |
175 | // |
174 | // |
176 | // |
175 | // Returnvalue: '1' if the PlaceMark could be opened |
177 | // Returnvalue: '1' if the PlaceMark could be opened |
176 | //________________________________________________________________________________________________________________________________________ |
178 | //________________________________________________________________________________________________________________________________________ |
177 | 179 | ||
178 | u8 TRIG_PlaceMarkOpen(TRIG_Document_t *doc) |
180 | u8 TRIG_PlaceMarkOpen(TRIG_Document_t *doc) |
179 | { |
181 | { |
180 | u8 retvalue = 0; |
182 | u8 retvalue = 0; |
181 | if(doc->state == TRIG_DOC_OPENED) |
183 | if(doc->state == TRIG_DOC_OPENED) |
182 | { |
184 | { |
183 | if(doc->file != NULL) |
185 | if(doc->file != NULL) |
184 | { |
186 | { |
185 | doc->state = TRIG_DOC_PLACEMARK_OPENED; |
187 | doc->state = TRIG_DOC_PLACEMARK_OPENED; |
186 | retvalue = 1; |
188 | retvalue = 1; |
187 | // fwrite_((void*)TRIG_PLACEMARK_HEADER, sizeof(TRIG_PLACEMARK_HEADER)-1,1,doc->file); |
189 | // fwrite_((void*)TRIG_PLACEMARK_HEADER, sizeof(TRIG_PLACEMARK_HEADER)-1,1,doc->file); |
188 | } |
190 | } |
189 | } |
191 | } |
190 | return(retvalue); |
192 | return(retvalue); |
191 | } |
193 | } |
192 | 194 | ||
193 | //________________________________________________________________________________________________________________________________________ |
195 | //________________________________________________________________________________________________________________________________________ |
194 | // Function: u8 PlaceMarkClose(TRIG_PlaceMark_t *place, File *file); |
196 | // Function: u8 PlaceMarkClose(TRIG_PlaceMark_t *place, File *file); |
195 | // |
197 | // |
196 | // Description: This function ends the placemark opened before. |
198 | // Description: This function ends the placemark opened before. |
197 | // |
199 | // |
198 | // |
200 | // |
199 | // Returnvalue: 1' if the PlaceMark could be closed |
201 | // Returnvalue: 1' if the PlaceMark could be closed |
200 | //________________________________________________________________________________________________________________________________________ |
202 | //________________________________________________________________________________________________________________________________________ |
201 | 203 | ||
202 | u8 TRIG_PlaceMarkClose(TRIG_Document_t *doc) |
204 | u8 TRIG_PlaceMarkClose(TRIG_Document_t *doc) |
203 | { |
205 | { |
204 | 206 | ||
205 | u8 retvalue = 0; // close the Placemark-tag of the corosponding document. |
207 | u8 retvalue = 0; // close the Placemark-tag of the corosponding document. |
206 | 208 | ||
207 | if(doc->state == TRIG_DOC_PLACEMARK_OPENED) |
209 | if(doc->state == TRIG_DOC_PLACEMARK_OPENED) |
208 | { |
210 | { |
209 | if(doc->file != NULL) |
211 | if(doc->file != NULL) |
210 | { |
212 | { |
211 | doc->state = TRIG_DOC_OPENED; |
213 | doc->state = TRIG_DOC_OPENED; |
212 | // fwrite_((void*)TRIG_PLACEMARK_FOOTER, sizeof(TRIG_PLACEMARK_FOOTER)-1,1,doc->file); |
214 | // fwrite_((void*)TRIG_PLACEMARK_FOOTER, sizeof(TRIG_PLACEMARK_FOOTER)-1,1,doc->file); |
213 | retvalue = 1; |
215 | retvalue = 1; |
214 | } |
216 | } |
215 | } |
217 | } |
216 | 218 | ||
217 | return(retvalue); |
219 | return(retvalue); |
218 | } |
220 | } |
219 | 221 | ||
220 | //________________________________________________________________________________________________________________________________________ |
222 | //________________________________________________________________________________________________________________________________________ |
221 | // Function: u8 LineStringBegin(TRIG_Document_t *doc); |
223 | // Function: u8 LineStringBegin(TRIG_Document_t *doc); |
222 | // |
224 | // |
223 | // Description: This function ends the placemark opened before. |
225 | // Description: This function ends the placemark opened before. |
224 | // |
226 | // |
225 | // |
227 | // |
226 | // Returnvalue: '1' if the LineString could be started |
228 | // Returnvalue: '1' if the LineString could be started |
227 | //________________________________________________________________________________________________________________________________________ |
229 | //________________________________________________________________________________________________________________________________________ |
228 | 230 | ||
229 | u8 TRIG_LineStringBegin(TRIG_Document_t *doc) |
231 | u8 TRIG_LineStringBegin(TRIG_Document_t *doc) |
230 | { |
232 | { |
231 | 233 | ||
232 | u8 retvalue = 0; |
234 | u8 retvalue = 0; |
233 | 235 | ||
234 | if(doc->state == TRIG_DOC_PLACEMARK_OPENED) |
236 | if(doc->state == TRIG_DOC_PLACEMARK_OPENED) |
235 | { |
237 | { |
236 | if(doc->file != NULL) |
238 | if(doc->file != NULL) |
237 | { |
239 | { |
238 | doc->state = TRIG_DOC_LINESTRING_OPENED; |
240 | doc->state = TRIG_DOC_LINESTRING_OPENED; |
239 | // fwrite_((void*)TRIG_LINESTRING_HEADER, sizeof(TRIG_LINESTRING_HEADER)-1,1,doc->file); |
241 | // fwrite_((void*)TRIG_LINESTRING_HEADER, sizeof(TRIG_LINESTRING_HEADER)-1,1,doc->file); |
240 | Logged_TRIG_Counter = 0; |
242 | Logged_TRIG_Counter = 0; |
241 | TrigLogging.NewData = 0; |
243 | TrigLogging.NewData = 0; |
242 | retvalue = 1; |
244 | retvalue = 1; |
243 | } |
245 | } |
244 | } |
246 | } |
245 | return(retvalue); |
247 | return(retvalue); |
246 | } |
248 | } |
247 | 249 | ||
248 | //________________________________________________________________________________________________________________________________________ |
250 | //________________________________________________________________________________________________________________________________________ |
249 | // Function: u8 TRIG_LineStringEnd(TRIG_Document_t *doc) |
251 | // Function: u8 TRIG_LineStringEnd(TRIG_Document_t *doc) |
250 | // |
252 | // |
251 | // Description: This function ends the placemark opened before. |
253 | // Description: This function ends the placemark opened before. |
252 | // |
254 | // |
253 | // |
255 | // |
254 | // Returnvalue: '1' if the LineString could be terminated |
256 | // Returnvalue: '1' if the LineString could be terminated |
255 | //________________________________________________________________________________________________________________________________________ |
257 | //________________________________________________________________________________________________________________________________________ |
256 | 258 | ||
257 | u8 TRIG_LineStringEnd(TRIG_Document_t *doc) |
259 | u8 TRIG_LineStringEnd(TRIG_Document_t *doc) |
258 | { |
260 | { |
259 | u8 retvalue = 0; |
261 | u8 retvalue = 0; |
260 | if(doc->state == TRIG_DOC_LINESTRING_OPENED) |
262 | if(doc->state == TRIG_DOC_LINESTRING_OPENED) |
261 | { |
263 | { |
262 | if(doc->file != NULL) |
264 | if(doc->file != NULL) |
263 | { |
265 | { |
264 | doc->state = TRIG_DOC_PLACEMARK_OPENED; |
266 | doc->state = TRIG_DOC_PLACEMARK_OPENED; |
265 | // fwrite_((void*)TRIG_LINESTRING_FOOTER, sizeof(TRIG_LINESTRING_FOOTER)-1,1,doc->file); |
267 | // fwrite_((void*)TRIG_LINESTRING_FOOTER, sizeof(TRIG_LINESTRING_FOOTER)-1,1,doc->file); |
266 | retvalue = 1; |
268 | retvalue = 1; |
267 | } |
269 | } |
268 | } |
270 | } |
269 | return(retvalue); |
271 | return(retvalue); |
270 | } |
272 | } |
271 | 273 | ||
272 | //________________________________________________________________________________________________________________________________________ |
274 | //________________________________________________________________________________________________________________________________________ |
273 | // Function: TRIG_Document_Open(void); |
275 | // Function: TRIG_Document_Open(void); |
274 | // |
276 | // |
275 | // Description: This function opens a new KML- document with the specified name and creates the document header within the file. |
277 | // Description: This function opens a new KML- document with the specified name and creates the document header within the file. |
276 | // |
278 | // |
277 | // |
279 | // |
278 | // Returnvalue: '1' if the KML- file could be created. |
280 | // Returnvalue: '1' if the KML- file could be created. |
279 | //________________________________________________________________________________________________________________________________________ |
281 | //________________________________________________________________________________________________________________________________________ |
280 | 282 | ||
281 | u8 TRIG_DocumentOpen(s8 *name, TRIG_Document_t *doc) |
283 | u8 TRIG_DocumentOpen(s8 *name, TRIG_Document_t *doc) |
282 | { |
284 | { |
283 | 285 | ||
284 | u8 retvalue = 0; |
286 | u8 retvalue = 0; |
285 | s8 string[150]; |
287 | s8 string[150]; |
286 | 288 | ||
287 | if(doc == NULL) return(0); |
289 | if(doc == NULL) return(0); |
288 | 290 | ||
289 | TRIG_DocumentInit(doc); // intialize the document with resetvalues |
291 | TRIG_DocumentInit(doc); // intialize the document with resetvalues |
290 | doc->file = fopen_(name,'a'); // open a new file with the specified filename on the memorycard. |
292 | doc->file = fopen_(name,'a'); // open a new file with the specified filename on the memorycard. |
291 | 293 | ||
292 | if(doc->file != NULL) // could the file be opened? |
294 | if(doc->file != NULL) // could the file be opened? |
293 | { |
295 | { |
294 | retvalue = 1; // the document could be created on the drive. |
296 | retvalue = 1; // the document could be created on the drive. |
295 | doc->state = TRIG_DOC_OPENED; // change document state to opened. At next a placemark has to be opened. |
297 | doc->state = TRIG_DOC_OPENED; // change document state to opened. At next a placemark has to be opened. |
296 | sprintf(string, "#Counter;Time;Longitude;Latitude;GPSAltitude[m](raw);BaroAltitude[m];Compass[deg];ServoSetpoint(raw);ServoPoi[deg]"); |
298 | sprintf(string, "#Counter;Time;Longitude;Latitude;GPSAltitude[m](raw);BaroAltitude[m];Compass[deg];ServoSetpoint(raw);ServoPoi[deg]"); |
297 | fputs_(string, doc->file); |
299 | fputs_(string, doc->file); |
298 | sprintf(string, "\r\n#%4i.%02i.%02i Nr:%i (%02i%02i%02i%02i.GPX)", SystemTime.Year, SystemTime.Month, SystemTime.Day, TRIG_Filenum, SystemTime.Year%100, SystemTime.Month, SystemTime.Day, GPX_Filenum); |
300 | sprintf(string, "\r\n#%4i.%02i.%02i Nr:%i (%02i%02i%02i%02i.GPX)", SystemTime.Year, SystemTime.Month, SystemTime.Day, TRIG_Filenum, SystemTime.Year%100, SystemTime.Month, SystemTime.Day, GPX_Filenum); |
299 | fputs_(string, doc->file); |
301 | fputs_(string, doc->file); |
300 | if(SimulationFlags) { sprintf(string, " SIMULATED"); fputs_(string, doc->file);}; |
302 | if(SimulationFlags) { sprintf(string, " SIMULATED"); fputs_(string, doc->file);}; |
301 | if(BlitzSchuhConnected){ sprintf(string, "\r\n#External hotshoe sensor connected"); fputs_(string, doc->file);}; |
303 | if(BlitzSchuhConnected){ sprintf(string, "\r\n#External hotshoe sensor connected"); fputs_(string, doc->file);}; |
302 | } |
304 | } |
303 | return(retvalue); |
305 | return(retvalue); |
304 | } |
306 | } |
305 | 307 | ||
306 | 308 | ||
307 | //________________________________________________________________________________________________________________________________________ |
309 | //________________________________________________________________________________________________________________________________________ |
308 | // Function: u8 LineStringAddPoint(gps_data_t, TRIG_Document_t *doc) |
310 | // Function: u8 LineStringAddPoint(gps_data_t, TRIG_Document_t *doc) |
309 | // |
311 | // |
310 | // Description: This function adds a point to the specified document. |
312 | // Description: This function adds a point to the specified document. |
311 | // |
313 | // |
312 | // |
314 | // |
313 | // Returnvalue: '1' if a ppoint was added could be started |
315 | // Returnvalue: '1' if a ppoint was added could be started |
314 | //________________________________________________________________________________________________________________________________________ |
316 | //________________________________________________________________________________________________________________________________________ |
315 | 317 | ||
316 | u8 TRIG_LineStringAddPoint(TRIG_Document_t *doc) |
318 | u8 TRIG_LineStringAddPoint(TRIG_Document_t *doc) |
317 | { |
319 | { |
318 | 320 | ||
319 | u8 retvalue = 0; |
321 | u8 retvalue = 0; |
320 | s8 string[70]; |
322 | s8 string[70]; |
321 | s32 rel_altitude = 0; |
323 | s32 rel_altitude = 0; |
322 | 324 | ||
323 | if(doc == NULL) return(0); |
325 | if(doc == NULL) return(0); |
324 | 326 | ||
325 | if(GPSData.Position.Status != INVALID) |
327 | if(GPSData.Position.Status != INVALID) |
326 | { |
328 | { |
327 | if(doc->state == TRIG_DOC_LINESTRING_OPENED) |
329 | if(doc->state == TRIG_DOC_LINESTRING_OPENED) |
328 | { |
330 | { |
329 | if(doc->file != NULL) |
331 | if(doc->file != NULL) |
330 | { |
332 | { |
331 | s32 i1, i2; |
333 | s32 i1, i2; |
332 | u8 sign; |
334 | u8 sign; |
333 | // Counter |
335 | // Counter |
334 | sprintf(string,"\r\n%d",TrigLogging.Count); |
336 | sprintf(string,"\r\n%d",TrigLogging.Count); |
335 | fputs_(string, doc->file); |
337 | fputs_(string, doc->file); |
336 | // Time |
338 | // Time |
337 | sprintf(string, ";%04d-%02d-%02dT%02d:%02d:%02d.%dZ",SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Hour, SystemTime.Min, SystemTime.Sec,SystemTime.mSec/100); |
339 | sprintf(string, ";%04d-%02d-%02dT%02d:%02d:%02d.%dZ",SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Hour, SystemTime.Min, SystemTime.Sec,SystemTime.mSec/100); |
338 | fputs_(string, doc->file); |
340 | fputs_(string, doc->file); |
339 | // Position |
341 | // Position |
340 | if(TrigLogging.Latitude < 0) sign = '-'; |
342 | if(TrigLogging.Latitude < 0) sign = '-'; |
341 | else sign = '+'; |
343 | else sign = '+'; |
342 | i1 = abs(TrigLogging.Latitude)/10000000L; |
344 | i1 = abs(TrigLogging.Latitude)/10000000L; |
343 | i2 = abs(TrigLogging.Latitude)%10000000L; |
345 | i2 = abs(TrigLogging.Latitude)%10000000L; |
344 | sprintf(string,";%c%ld.%07ld",sign, i1, i2); |
346 | sprintf(string,";%c%ld.%07ld",sign, i1, i2); |
345 | fputs_(string, doc->file); |
347 | fputs_(string, doc->file); |
346 | 348 | ||
347 | if(TrigLogging.Longitude < 0) sign = '-'; |
349 | if(TrigLogging.Longitude < 0) sign = '-'; |
348 | else sign = '+'; |
350 | else sign = '+'; |
349 | i1 = abs(TrigLogging.Longitude)/10000000L; |
351 | i1 = abs(TrigLogging.Longitude)/10000000L; |
350 | i2 = abs(TrigLogging.Longitude)%10000000L; |
352 | i2 = abs(TrigLogging.Longitude)%10000000L; |
351 | sprintf(string,";%c%ld.%07ld",sign, i1, i2); |
353 | sprintf(string,";%c%ld.%07ld",sign, i1, i2); |
352 | fputs_(string, doc->file); |
354 | fputs_(string, doc->file); |
353 | // calculate relative altitude with respect to the altitude of the home position |
355 | // calculate relative altitude with respect to the altitude of the home position |
354 | // Altitude GPS |
356 | // Altitude GPS |
355 | rel_altitude = TrigLogging.AltiGPS;// - NaviData.HomePosition.Altitude; |
357 | rel_altitude = TrigLogging.AltiGPS;// - NaviData.HomePosition.Altitude; |
356 | // if(rel_altitude < 0) rel_altitude = 0; // avoid negative altitudes in log |
358 | // if(rel_altitude < 0) rel_altitude = 0; // avoid negative altitudes in log |
357 | i1 = rel_altitude/1000L; |
359 | i1 = rel_altitude/1000L; |
358 | i2 = rel_altitude%1000L; |
360 | i2 = rel_altitude%1000L; |
359 | sprintf(string,";%ld.%03ld",i1, labs(i2)); |
361 | sprintf(string,";%ld.%03ld",i1, labs(i2)); |
360 | fputs_(string, doc->file); |
362 | fputs_(string, doc->file); |
361 | // Altitude Baro |
363 | // Altitude Baro |
362 | sprintf(string,";%ld.%02d",TrigLogging.AltiBaro/100,abs(TrigLogging.AltiBaro%100)); |
364 | sprintf(string,";%ld.%02d",TrigLogging.AltiBaro/100,abs(TrigLogging.AltiBaro%100)); |
363 | fputs_(string, doc->file); |
365 | fputs_(string, doc->file); |
364 | // Yaw angle |
366 | // Yaw angle |
365 | sprintf(string,";%d.%d",TrigLogging.Yaw/10,abs(TrigLogging.Yaw%10)); |
367 | sprintf(string,";%d.%d",TrigLogging.Yaw/10,abs(TrigLogging.Yaw%10)); |
366 | fputs_(string, doc->file); |
368 | fputs_(string, doc->file); |
367 | // ServoSet; ServoPoi |
369 | // ServoSet; ServoPoi |
368 | sprintf(string,";%d;%d.%d",TrigLogging.ServoControlNick,TrigLogging.ServoControlPoi/10,abs(TrigLogging.ServoControlPoi%10)); |
370 | sprintf(string,";%d;%d.%d",TrigLogging.ServoControlNick,TrigLogging.ServoControlPoi/10,abs(TrigLogging.ServoControlPoi%10)); |
369 | fputs_(string, doc->file); |
371 | fputs_(string, doc->file); |
370 | 372 | ||
371 | Logged_TRIG_Counter++; |
373 | Logged_TRIG_Counter++; |
372 | retvalue = 1; |
374 | retvalue = 1; |
373 | } |
375 | } |
374 | } |
376 | } |
375 | } |
377 | } |
376 | else |
378 | else |
377 | { |
379 | { |
378 | if(doc->state == TRIG_DOC_LINESTRING_OPENED) |
380 | if(doc->state == TRIG_DOC_LINESTRING_OPENED) |
379 | { |
381 | { |
380 | if(doc->file != NULL) |
382 | if(doc->file != NULL) |
381 | { |
383 | { |
382 | sprintf(string,"\r\n"); |
384 | sprintf(string,"\r\n"); |
383 | fputs_(string, doc->file); |
385 | fputs_(string, doc->file); |
384 | Logged_TRIG_Counter++; |
386 | Logged_TRIG_Counter++; |
385 | retvalue = 1; |
387 | retvalue = 1; |
386 | } |
388 | } |
387 | } |
389 | } |
388 | } |
390 | } |
389 | return(retvalue); |
391 | return(retvalue); |
390 | } |
392 | } |
391 | 393 | ||
392 | //________________________________________________________________________________________________________________________________________ |
394 | //________________________________________________________________________________________________________________________________________ |
393 | // Function: u8 TRIG_LoggGPSCoordinates(gps_data_t *, TRIG_Document_t *) |
395 | // Function: u8 TRIG_LoggGPSCoordinates(gps_data_t *, TRIG_Document_t *) |
394 | // |
396 | // |
395 | // Description: This function opens adds gpscoordinates to an KML-Document. The document will be opened, if not already done |
397 | // Description: This function opens adds gpscoordinates to an KML-Document. The document will be opened, if not already done |
396 | // |
398 | // |
397 | // |
399 | // |
398 | // Returnvalue: '1' if an gps coordinate was logged |
400 | // Returnvalue: '1' if an gps coordinate was logged |
399 | //________________________________________________________________________________________________________________________________________ |
401 | //________________________________________________________________________________________________________________________________________ |
400 | 402 | ||
401 | u8 TRIG_LoggGPSCoordinates(TRIG_Document_t *doc) |
403 | u8 TRIG_LoggGPSCoordinates(TRIG_Document_t *doc) |
402 | { |
404 | { |
403 | u8 retval = 0; |
405 | u8 retval = 0; |
404 | while(doc->state != TRIG_DOC_LINESTRING_OPENED) // automatic create document with default filename on the card. |
406 | while(doc->state != TRIG_DOC_LINESTRING_OPENED) // automatic create document with default filename on the card. |
405 | { |
407 | { |
406 | switch(doc->state) |
408 | switch(doc->state) |
407 | { |
409 | { |
408 | case TRIG_DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically |
410 | case TRIG_DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically |
409 | // retval = TRIG_DocumentOpen("default.kml",doc); // open the kml-document with a standardname. |
411 | // retval = TRIG_DocumentOpen("default.kml",doc); // open the kml-document with a standardname. |
410 | break; |
412 | break; |
411 | 413 | ||
412 | case TRIG_DOC_OPENED: // if a document has been opened before but no placemark exists: |
414 | case TRIG_DOC_OPENED: // if a document has been opened before but no placemark exists: |
413 | retval = TRIG_PlaceMarkOpen(doc); |
415 | retval = TRIG_PlaceMarkOpen(doc); |
414 | break; |
416 | break; |
415 | 417 | ||
416 | case TRIG_DOC_PLACEMARK_OPENED: // add linestring to the placemark |
418 | case TRIG_DOC_PLACEMARK_OPENED: // add linestring to the placemark |
417 | retval = TRIG_LineStringBegin(doc); |
419 | retval = TRIG_LineStringBegin(doc); |
418 | break; |
420 | break; |
419 | 421 | ||
420 | default: |
422 | default: |
421 | retval = 0; |
423 | retval = 0; |
422 | break; |
424 | break; |
423 | 425 | ||
424 | } |
426 | } |
425 | if(retval != 1) return(retval); // stop on error |
427 | if(retval != 1) return(retval); // stop on error |
426 | } |
428 | } |
427 | 429 | ||
428 | if(doc->state == TRIG_DOC_LINESTRING_OPENED) // if the document was opened add coordinates to the document. |
430 | if(doc->state == TRIG_DOC_LINESTRING_OPENED) // if the document was opened add coordinates to the document. |
429 | { |
431 | { |
430 | retval = TRIG_LineStringAddPoint(doc); |
432 | retval = TRIG_LineStringAddPoint(doc); |
431 | } |
433 | } |
432 | return(retval); |
434 | return(retval); |
433 | } |
435 | } |
434 | 436 | ||
435 | 437 | ||
436 | 438 | ||
437 | //---------------------------------------------------------------------------------------------------- |
439 | //---------------------------------------------------------------------------------------------------- |
438 | s8* GenerateTriggLogFileName(void) |
440 | s8* GenerateTriggLogFileName(void) |
439 | { |
441 | { |
440 | static u16 filenum = 0; // file name counter |
442 | static u16 filenum = 0; // file name counter |
441 | static s8 filename[40]; |
443 | static s8 filename[40]; |
442 | 444 | ||
443 | static DateTime_t LastTime = {0,0,0,0,0,0,0,0}; |
445 | static DateTime_t LastTime = {0,0,0,0,0,0,0,0}; |
444 | if(filenum < GPX_Filenum) filenum = GPX_Filenum; |
446 | if(filenum < GPX_Filenum) filenum = GPX_Filenum; |
445 | if(SystemTime.Valid) |
447 | if(SystemTime.Valid) |
446 | { |
448 | { |
447 | // if the day has been changed |
449 | // if the day has been changed |
448 | if((LastTime.Year != SystemTime.Year) || (LastTime.Month != SystemTime.Month) || (LastTime.Day != SystemTime.Day)) |
450 | if((LastTime.Year != SystemTime.Year) || (LastTime.Month != SystemTime.Month) || (LastTime.Day != SystemTime.Day)) |
449 | { |
451 | { |
450 | LastTime.Year = SystemTime.Year; |
452 | LastTime.Year = SystemTime.Year; |
451 | LastTime.Month = SystemTime.Month; |
453 | LastTime.Month = SystemTime.Month; |
452 | LastTime.Day = SystemTime.Day; |
454 | LastTime.Day = SystemTime.Day; |
453 | LastTime.Valid = 1; |
455 | LastTime.Valid = 1; |
454 | filenum = 0; // reset file counter |
456 | filenum = 0; // reset file counter |
455 | } |
457 | } |
456 | if(!(SimulationFlags & SIMULATION_ACTIVE)) |
458 | if(!(SimulationFlags & SIMULATION_ACTIVE)) |
457 | { |
459 | { |
458 | if(filenum < 100) sprintf(filename, "/LOG/%04i%02i%02i/GPX/%02i%02i%02i%02i.TXT", SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Year % 100, SystemTime.Month, SystemTime.Day, filenum); |
460 | if(filenum < 100) sprintf(filename, "/LOG/%04i%02i%02i/GPX/%02i%02i%02i%02i.TXT", SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Year % 100, SystemTime.Month, SystemTime.Day, filenum); |
459 | else sprintf(filename, "/LOG/%04i%02i%02i/GPX/GPS%05i.TXT", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
461 | else sprintf(filename, "/LOG/%04i%02i%02i/GPX/GPS%05i.TXT", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
460 | } |
462 | } |
461 | else |
463 | else |
462 | { |
464 | { |
463 | if(filenum < 100 && SystemTime.Year > 2000) sprintf(filename, "/SIMULATE/%04i%02i%02i/GPX/S%i%02i%02i%02i.TXT", SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Year % 10, SystemTime.Month, SystemTime.Day, filenum); |
465 | if(filenum < 100 && SystemTime.Year > 2000) sprintf(filename, "/SIMULATE/%04i%02i%02i/GPX/S%i%02i%02i%02i.TXT", SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Year % 10, SystemTime.Month, SystemTime.Day, filenum); |
464 | else sprintf(filename, "/SIMULATE/%04i%02i%02i/GPX/SIM%05i.TXT", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
466 | else sprintf(filename, "/SIMULATE/%04i%02i%02i/GPX/SIM%05i.TXT", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
465 | } |
467 | } |
466 | TRIG_Filenum = filenum; |
468 | TRIG_Filenum = filenum; |
467 | filenum++; |
469 | filenum++; |
468 | return filename; |
470 | return filename; |
469 | } |
471 | } |
470 | else return NULL; |
472 | else return NULL; |
471 | } |
473 | } |
472 | 474 | ||
473 | 475 | ||
474 | 476 | ||
475 | //---------------------------------------------------------------------------------------------------- |
477 | //---------------------------------------------------------------------------------------------------- |
476 | // logs the current gps position to a csv file |
478 | // logs the current gps position to a csv file |
477 | logfilestate_t LoggingTrigger(u32 LogDelay) |
479 | logfilestate_t LoggingTrigger(u32 LogDelay) |
478 | { |
480 | { |
479 | static logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate |
481 | static logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate |
480 | static s8* logfilename = NULL; // the pointer to the logfilename |
482 | static s8* logfilename = NULL; // the pointer to the logfilename |
481 | static u32 logtimer = 0, flushtimer = 0; // the log update timer |
483 | static u32 logtimer = 0, flushtimer = 0; // the log update timer |
482 | static TRIG_Document_t logfile; // the logfilehandle |
484 | static TRIG_Document_t logfile; // the logfilehandle |
483 | static u32 appendtimer = 0; // the log update timer |
485 | static u32 appendtimer = 0; // the log update timer |
484 | static u8 logging_active = 0; |
486 | static u8 logging_active = 0; |
485 | 487 | ||
486 | // initialize if LogDelay is zero |
488 | // initialize if LogDelay is zero |
487 | if(!LogDelay) |
489 | if(!LogDelay) |
488 | { |
490 | { |
489 | switch(logfilestate) |
491 | switch(logfilestate) |
490 | { |
492 | { |
491 | case LOGFILE_OPENED: |
493 | case LOGFILE_OPENED: |
492 | TRIG_DocumentClose(&logfile); // try to close it |
494 | TRIG_DocumentClose(&logfile); // try to close it |
493 | break; |
495 | break; |
494 | default: |
496 | default: |
495 | break; |
497 | break; |
496 | } |
498 | } |
497 | logfilestate = LOGFILE_IDLE; |
499 | logfilestate = LOGFILE_IDLE; |
498 | logfilename = NULL; |
500 | logfilename = NULL; |
499 | TRIG_DocumentInit(&logfile); |
501 | TRIG_DocumentInit(&logfile); |
500 | logtimer = SetDelay(0); // set logtimer to now |
502 | logtimer = SetDelay(0); // set logtimer to now |
501 | return logfilestate; |
503 | return logfilestate; |
502 | } |
504 | } |
503 | // no init |
505 | // no init |
504 | if(CheckDelay(logtimer) || (TrigLogging.NewData && logging_active)) |
506 | if(CheckDelay(logtimer) || (TrigLogging.NewData && logging_active)) |
505 | { |
507 | { |
506 | logtimer = SetDelay(LogDelay); // standard interval |
508 | logtimer = SetDelay(LogDelay); // standard interval |
507 | 509 | ||
508 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) |
510 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) |
509 | { |
511 | { |
510 | logging_active = 1; |
512 | logging_active = 1; |
511 | appendtimer = SetDelay(APPEND_LOG_TIME_MS); |
513 | appendtimer = SetDelay(APPEND_LOG_TIME_MS); |
512 | } |
514 | } |
513 | else |
515 | else |
514 | { |
516 | { |
515 | if(CheckDelay(appendtimer)) logging_active = 0; |
517 | if(CheckDelay(appendtimer)) logging_active = 0; |
516 | } |
518 | } |
517 | 519 | ||
518 | if(logging_active) |
520 | if(logging_active) |
519 | { |
521 | { |
520 | switch(logfilestate) |
522 | switch(logfilestate) |
521 | { |
523 | { |
522 | case LOGFILE_IDLE: |
524 | case LOGFILE_IDLE: |
523 | case LOGFILE_CLOSED: |
525 | case LOGFILE_CLOSED: |
524 | if(GPX_logging_active == 2) // start after GPX-Log |
526 | if(GPX_logging_active == 2) // start after GPX-Log |
525 | { |
527 | { |
526 | logfilestate = LOGFILE_START; |
528 | logfilestate = LOGFILE_START; |
527 | } |
529 | } |
528 | break; |
530 | break; |
529 | case LOGFILE_START: |
531 | case LOGFILE_START: |
530 | // find unused logfile name |
532 | // find unused logfile name |
531 | do |
533 | do |
532 | { // try to generate a new logfile name |
534 | { // try to generate a new logfile name |
533 | logfilename = GenerateTriggLogFileName(); |
535 | logfilename = GenerateTriggLogFileName(); |
534 | }while((logfilename != NULL) && fexist_(logfilename)); |
536 | }while((logfilename != NULL) && fexist_(logfilename)); |
535 | // if logfilename exist |
537 | // if logfilename exist |
536 | if(logfilename != NULL) |
538 | if(logfilename != NULL) |
537 | { |
539 | { |
538 | // try to create the log file |
540 | // try to create the log file |
539 | if(TRIG_DocumentOpen(logfilename, &logfile)) |
541 | if(TRIG_DocumentOpen(logfilename, &logfile)) |
540 | { |
542 | { |
541 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
543 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
542 | logfilestate = LOGFILE_OPENED; // goto next step |
544 | logfilestate = LOGFILE_OPENED; // goto next step |
543 | UART1_PutString("\r\nOpening trigger-file:"); |
545 | UART1_PutString("\r\nOpening trigger-file:"); |
544 | UART1_PutString(logfilename); |
546 | UART1_PutString(logfilename); |
545 | UART1_PutString("\r\n"); |
547 | UART1_PutString("\r\n"); |
546 | TrigLogging.NewData = 0; |
548 | TrigLogging.NewData = 0; |
547 | TrigLogging.Count = 0; |
549 | TrigLogging.Count = 0; |
- | 550 | TrigLogging.CountExternal = 0; |
|
548 | fflush_(logfile.file); |
551 | fflush_(logfile.file); |
549 | } |
552 | } |
550 | else // could not be openend |
553 | else // could not be openend |
551 | { |
554 | { |
552 | logfilestate = LOGFILE_ERROR; |
555 | logfilestate = LOGFILE_ERROR; |
553 | UART1_PutString("\r\nError opening trigger-file: "); |
556 | UART1_PutString("\r\nError opening trigger-file: "); |
554 | UART1_PutString(logfilename); |
557 | UART1_PutString(logfilename); |
555 | UART1_PutString("\r\n"); |
558 | UART1_PutString("\r\n"); |
556 | logtimer = SetDelay(10); // try again in open logfile in 10 mili sec |
559 | logtimer = SetDelay(10); // try again in open logfile in 10 mili sec |
557 | SD_LoggingError = 1; |
560 | SD_LoggingError = 1; |
558 | } |
561 | } |
559 | } |
562 | } |
560 | else |
563 | else |
561 | { |
564 | { |
562 | logfilestate = LOGFILE_ERROR; |
565 | logfilestate = LOGFILE_ERROR; |
563 | UART1_PutString("\r\nError getting free trigger-file name\r\n"); |
566 | UART1_PutString("\r\nError getting free trigger-file name\r\n"); |
564 | SD_LoggingError = 2; |
567 | SD_LoggingError = 2; |
565 | } |
568 | } |
566 | // else retry in next loop |
569 | // else retry in next loop |
567 | break; |
570 | break; |
568 | case LOGFILE_OPENED: |
571 | case LOGFILE_OPENED: |
569 | // append new gps log data |
572 | // append new gps log data |
570 | if(TrigLogging.NewData) |
573 | if(TrigLogging.NewData) |
571 | { |
574 | { |
572 | TrigLogging.NewData--; |
575 | TrigLogging.NewData--; |
573 | if((GPSData.Status != INVALID))// && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)) |
576 | if((GPSData.Status != INVALID))// && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)) |
574 | { |
577 | { |
575 | if(!TRIG_LoggGPSCoordinates(&logfile)) |
578 | if(!TRIG_LoggGPSCoordinates(&logfile)) |
576 | { // error logging data |
579 | { // error logging data |
577 | UART1_PutString("\r\nError logging to trigger-file\r\n"); |
580 | UART1_PutString("\r\nError logging to trigger-file\r\n"); |
578 | SD_LoggingError = 3; |
581 | SD_LoggingError = 3; |
579 | TRIG_DocumentClose(&logfile); |
582 | TRIG_DocumentClose(&logfile); |
580 | logfilestate = LOGFILE_ERROR; |
583 | logfilestate = LOGFILE_ERROR; |
581 | TrigLogging.NewData = 0; |
584 | TrigLogging.NewData = 0; |
582 | } |
585 | } |
583 | else // sucessfully logged |
586 | else // sucessfully logged |
584 | { |
587 | { |
585 | SD_LoggingError = 0; |
588 | SD_LoggingError = 0; |
586 | // if(CheckDelay(flushtimer)) |
589 | // if(CheckDelay(flushtimer)) |
587 | { |
590 | { |
588 | // flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
591 | // flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
589 | fflush_(logfile.file); |
592 | fflush_(logfile.file); |
590 | } |
593 | } |
591 | } |
594 | } |
592 | 595 | ||
593 | } |
596 | } |
594 | } |
597 | } |
595 | break; |
598 | break; |
596 | 599 | ||
597 | case LOGFILE_ERROR: |
600 | case LOGFILE_ERROR: |
598 | break; |
601 | break; |
599 | 602 | ||
600 | default: |
603 | default: |
601 | logfilestate = LOGFILE_IDLE; |
604 | logfilestate = LOGFILE_IDLE; |
602 | break; |
605 | break; |
603 | } |
606 | } |
604 | } // EOF motors are not running |
607 | } // EOF motors are not running |
605 | else // model is not flying |
608 | else // model is not flying |
606 | { // close log file if opened |
609 | { // close log file if opened |
607 | if(logfilestate == LOGFILE_OPENED) |
610 | if(logfilestate == LOGFILE_OPENED) |
608 | { |
611 | { |
609 | if(TRIG_DocumentClose(&logfile)) |
612 | if(TRIG_DocumentClose(&logfile)) |
610 | { |
613 | { |
611 | UART1_PutString("\r\nClosing trigger-file\r\n"); |
614 | UART1_PutString("\r\nClosing trigger-file\r\n"); |
612 | logfilestate = LOGFILE_CLOSED; |
615 | logfilestate = LOGFILE_CLOSED; |
613 | } |
616 | } |
614 | else // could not be closed |
617 | else // could not be closed |
615 | { |
618 | { |
616 | UART1_PutString("\r\nError closing trigger-file\r\n"); |
619 | UART1_PutString("\r\nError closing trigger-file\r\n"); |
617 | SD_LoggingError = 4; |
620 | SD_LoggingError = 4; |
618 | logfilestate = LOGFILE_ERROR; |
621 | logfilestate = LOGFILE_ERROR; |
619 | } |
622 | } |
620 | } |
623 | } |
621 | } //EOF motors are not running |
624 | } //EOF motors are not running |
622 | } // EOF Check LogTimer |
625 | } // EOF Check LogTimer |
623 | 626 | ||
624 | return logfilestate; |
627 | return logfilestate; |
625 | } |
628 | } |
626 | 629 | ||
627 | 630 | ||
628 | 631 | ||
629 | 632 |