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