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