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