Rev 379 | Rev 421 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 379 | Rev 380 | ||
---|---|---|---|
1 | /*#######################################################################################*/ |
1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
3 | /*#######################################################################################*/ |
3 | /*#######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + www.MikroKopter.com |
5 | // + www.MikroKopter.com |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
7 | // + Software Nutzungsbedingungen (english version: see below) |
7 | // + Software Nutzungsbedingungen (english version: see below) |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
22 | // + des Mitverschuldens offen. |
22 | // + des Mitverschuldens offen. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
30 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
30 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // + Software LICENSING TERMS |
32 | // + Software LICENSING TERMS |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
35 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
35 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
37 | // + The Software may only be used with the Licensor's products. |
37 | // + The Software may only be used with the Licensor's products. |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
40 | // + agreement shall be the property of the Licensor. |
40 | // + agreement shall be the property of the Licensor. |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
43 | // + The customer shall be responsible for taking reasonable precautions |
43 | // + The customer shall be responsible for taking reasonable precautions |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
53 | // + #### END OF LICENSING TERMS #### |
53 | // + #### END OF LICENSING TERMS #### |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | #include <stdio.h> |
56 | #include <stdio.h> |
57 | #include "91x_lib.h" |
57 | #include "91x_lib.h" |
58 | #include "main.h" |
58 | #include "main.h" |
59 | #include "timer1.h" |
59 | #include "timer1.h" |
60 | #include "uart1.h" |
60 | #include "uart1.h" |
61 | #include "kml.h" |
61 | #include "kml.h" |
62 | #include "gpx.h" |
62 | #include "gpx.h" |
63 | #include "ssc.h" |
63 | #include "ssc.h" |
64 | #include "settings.h" |
64 | #include "settings.h" |
65 | #include "led.h" |
65 | #include "led.h" |
- | 66 | #include "logging.h" |
|
- | 67 | ||
66 | 68 | #define MIN_SD_INTERVAL_KML 200 |
|
67 | #define MIN_SD_INTERVAL 500 |
69 | #define MIN_SD_INTERVAL_GPX 500 |
68 | 70 | ||
69 | u8 SD_LoggingError = 0; |
71 | u8 SD_LoggingError = 0; |
70 | 72 | ||
71 | #define LOG_FLUSH_INTERVAL 20000 // 20s //## |
73 | #define LOG_FLUSH_INTERVAL 20000 // 20s //## |
72 | 74 | ||
73 | typedef enum |
75 | typedef enum |
74 | { |
76 | { |
75 | LOGFILE_IDLE, |
77 | LOGFILE_IDLE, |
76 | LOGFILE_START, |
78 | LOGFILE_START, |
77 | LOGFILE_CLOSED, |
79 | LOGFILE_CLOSED, |
78 | LOGFILE_OPENED, |
80 | LOGFILE_OPENED, |
79 | LOGFILE_ERROR |
81 | LOGFILE_ERROR |
80 | } logfilestate_t; |
82 | } logfilestate_t; |
81 | 83 | ||
82 | // logger handler prototypes |
84 | // logger handler prototypes |
83 | logfilestate_t Logging_KML(u32 LogDelay); |
85 | logfilestate_t Logging_KML(u32 LogDelay); |
84 | logfilestate_t Logging_GPX(u32 LogDelay); |
86 | logfilestate_t Logging_GPX(u32 LogDelay); |
85 | - | ||
86 | typedef struct |
- | |
87 | { |
- | |
88 | u32 KML_Interval; // the kml-log interval (0 = off) |
- | |
89 | u32 GPX_Interval; // the gpx-log interval (0 = off) |
- | |
90 | } LogCfg_t; |
- | |
91 | 87 | ||
- | 88 | LogCfg_t LogCfg = {500 , 1000}; |
|
92 | LogCfg_t LogCfg = {500 , 1000}; |
89 | u32 Logged_GPX_Counter = 0, Logged_KML_Counter = 0; |
93 | 90 | ||
94 | 91 | ||
95 | //---------------------------------------------------------------------------------------------------- |
92 | //---------------------------------------------------------------------------------------------------- |
96 | s8* GenerateKMLLogFileName(void) |
93 | s8* GenerateKMLLogFileName(void) |
97 | { |
94 | { |
98 | static u16 filenum = 0; // file name counter |
95 | static u16 filenum = 0; // file name counter |
99 | static s8 filename[35]; |
96 | static s8 filename[35]; |
100 | static DateTime_t LastTime = {0,0,0,0,0,0,0,0}; |
97 | static DateTime_t LastTime = {0,0,0,0,0,0,0,0}; |
101 | 98 | ||
102 | if(SystemTime.Valid) |
99 | if(SystemTime.Valid) |
103 | { |
100 | { |
104 | // if the day has been changed |
101 | // if the day has been changed |
105 | if((LastTime.Year != SystemTime.Year) || (LastTime.Month != SystemTime.Month) || (LastTime.Day != SystemTime.Day)) |
102 | if((LastTime.Year != SystemTime.Year) || (LastTime.Month != SystemTime.Month) || (LastTime.Day != SystemTime.Day)) |
106 | { |
103 | { |
107 | LastTime.Year = SystemTime.Year; |
104 | LastTime.Year = SystemTime.Year; |
108 | LastTime.Month = SystemTime.Month; |
105 | LastTime.Month = SystemTime.Month; |
109 | LastTime.Day = SystemTime.Day; |
106 | LastTime.Day = SystemTime.Day; |
110 | LastTime.Valid = 1; |
107 | LastTime.Valid = 1; |
111 | filenum = 0; // reset file counter |
108 | filenum = 0; // reset file counter |
112 | } |
109 | } |
113 | sprintf(filename, "LOG/%04i%02i%02i/KML/GPS%05i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
110 | sprintf(filename, "LOG/%04i%02i%02i/KML/GPS%05i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
114 | filenum++; |
111 | filenum++; |
115 | return filename; |
112 | return filename; |
116 | } |
113 | } |
117 | else return NULL; |
114 | else return NULL; |
118 | } |
115 | } |
119 | 116 | ||
120 | //---------------------------------------------------------------------------------------------------- |
117 | //---------------------------------------------------------------------------------------------------- |
121 | s8* GenerateGPXLogFileName(void) |
118 | s8* GenerateGPXLogFileName(void) |
122 | { |
119 | { |
123 | static u16 filenum = 0; // file name counter |
120 | static u16 filenum = 0; // file name counter |
124 | static s8 filename[35]; |
121 | static s8 filename[35]; |
125 | static DateTime_t LastTime = {0,0,0,0,0,0,0,0}; |
122 | static DateTime_t LastTime = {0,0,0,0,0,0,0,0}; |
126 | 123 | ||
127 | if(SystemTime.Valid) |
124 | if(SystemTime.Valid) |
128 | { |
125 | { |
129 | // if the day has been changed |
126 | // if the day has been changed |
130 | if((LastTime.Year != SystemTime.Year) || (LastTime.Month != SystemTime.Month) || (LastTime.Day != SystemTime.Day)) |
127 | if((LastTime.Year != SystemTime.Year) || (LastTime.Month != SystemTime.Month) || (LastTime.Day != SystemTime.Day)) |
131 | { |
128 | { |
132 | LastTime.Year = SystemTime.Year; |
129 | LastTime.Year = SystemTime.Year; |
133 | LastTime.Month = SystemTime.Month; |
130 | LastTime.Month = SystemTime.Month; |
134 | LastTime.Day = SystemTime.Day; |
131 | LastTime.Day = SystemTime.Day; |
135 | LastTime.Valid = 1; |
132 | LastTime.Valid = 1; |
136 | filenum = 0; // reset file counter |
133 | filenum = 0; // reset file counter |
137 | } |
134 | } |
138 | sprintf(filename, "LOG/%04i%02i%02i/GPX/GPS%05i.GPX", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
135 | sprintf(filename, "LOG/%04i%02i%02i/GPX/GPS%05i.GPX", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
139 | filenum++; |
136 | filenum++; |
140 | return filename; |
137 | return filename; |
141 | } |
138 | } |
142 | else return NULL; |
139 | else return NULL; |
143 | } |
140 | } |
144 | 141 | ||
145 | 142 | ||
146 | 143 | ||
147 | //---------------------------------------------------------------------------------------------------- |
144 | //---------------------------------------------------------------------------------------------------- |
148 | // logs the current gps position to a kml file |
145 | // logs the current gps position to a kml file |
149 | logfilestate_t Logging_KML(u32 LogDelay) |
146 | logfilestate_t Logging_KML(u32 LogDelay) |
150 | { |
147 | { |
151 | static logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate |
148 | static logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate |
152 | static s8* logfilename = NULL; // the pointer to the logfilename |
149 | static s8* logfilename = NULL; // the pointer to the logfilename |
153 | static u32 logtimer = 0, flushtimer = 0; // the log update timer |
150 | static u32 logtimer = 0, flushtimer = 0; // the log update timer |
154 | static KML_Document_t logfile; // the logfilehandle |
151 | static KML_Document_t logfile; // the logfilehandle |
155 | 152 | ||
156 | // initialize if LogDelay is zero |
153 | // initialize if LogDelay is zero |
157 | if(!LogDelay) |
154 | if(!LogDelay) |
158 | { |
155 | { |
159 | switch(logfilestate) |
156 | switch(logfilestate) |
160 | { |
157 | { |
161 | case LOGFILE_OPENED: |
158 | case LOGFILE_OPENED: |
162 | KML_DocumentClose(&logfile); // try to close it |
159 | KML_DocumentClose(&logfile); // try to close it |
163 | break; |
160 | break; |
164 | default: |
161 | default: |
165 | break; |
162 | break; |
166 | } |
163 | } |
167 | logfilestate = LOGFILE_IDLE; |
164 | logfilestate = LOGFILE_IDLE; |
168 | logfilename = NULL; |
165 | logfilename = NULL; |
169 | KML_DocumentInit(&logfile); |
166 | KML_DocumentInit(&logfile); |
170 | logtimer = SetDelay(0); // set logtimer to now |
167 | logtimer = SetDelay(0); // set logtimer to now |
171 | return logfilestate; |
168 | return logfilestate; |
172 | } |
169 | } |
173 | // no init |
170 | // no init |
174 | if(CheckDelay(logtimer)) |
171 | if(CheckDelay(logtimer)) |
175 | { |
172 | { |
176 | logtimer = SetDelay(LogDelay); // standard interval |
173 | logtimer = SetDelay(LogDelay); // standard interval |
177 | 174 | ||
178 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) |
175 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) |
179 | { |
176 | { |
180 | switch(logfilestate) |
177 | switch(logfilestate) |
181 | { |
178 | { |
182 | case LOGFILE_IDLE: |
179 | case LOGFILE_IDLE: |
183 | case LOGFILE_CLOSED: |
180 | case LOGFILE_CLOSED: |
184 | if((GPSData.Status != INVALID) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D) && (FC.StatusFlags & FC_STATUS_FLY)) |
181 | if((GPSData.Status != INVALID) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D) && (FC.StatusFlags & FC_STATUS_FLY)) |
185 | { |
182 | { |
186 | logfilestate = LOGFILE_START; |
183 | logfilestate = LOGFILE_START; |
187 | } |
184 | } |
188 | break; |
185 | break; |
189 | case LOGFILE_START: |
186 | case LOGFILE_START: |
190 | // find unused logfile name |
187 | // find unused logfile name |
191 | do |
188 | do |
192 | { // try to generate a new logfile name |
189 | { // try to generate a new logfile name |
193 | logfilename = GenerateKMLLogFileName(); |
190 | logfilename = GenerateKMLLogFileName(); |
194 | }while((logfilename != NULL) && fexist_(logfilename)); |
191 | }while((logfilename != NULL) && fexist_(logfilename)); |
195 | // if logfilename exist |
192 | // if logfilename exist |
196 | if(logfilename != NULL) |
193 | if(logfilename != NULL) |
197 | { |
194 | { |
198 | // try to create the log file |
195 | // try to create the log file |
199 | if(KML_DocumentOpen(logfilename, &logfile)) |
196 | if(KML_DocumentOpen(logfilename, &logfile)) |
200 | { |
197 | { |
201 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
198 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
202 | logfilestate = LOGFILE_OPENED; // goto next step |
199 | logfilestate = LOGFILE_OPENED; // goto next step |
203 | UART1_PutString("\r\nOpening kml-file:"); |
200 | UART1_PutString("\r\nOpening kml-file:"); |
204 | UART1_PutString(logfilename); |
201 | UART1_PutString(logfilename); |
205 | UART1_PutString("\r\n"); |
202 | UART1_PutString("\r\n"); |
206 | } |
203 | } |
207 | else // could not be openend |
204 | else // could not be openend |
208 | { |
205 | { |
209 | logfilestate = LOGFILE_ERROR; |
206 | logfilestate = LOGFILE_ERROR; |
210 | UART1_PutString("\r\nError opening kml-file: "); |
207 | UART1_PutString("\r\nError opening kml-file: "); |
211 | UART1_PutString(logfilename); |
208 | UART1_PutString(logfilename); |
212 | UART1_PutString("\r\n"); |
209 | UART1_PutString("\r\n"); |
213 | logtimer = SetDelay(10); // try again in open logfile in 10 mili sec |
210 | logtimer = SetDelay(10); // try again in open logfile in 10 mili sec |
214 | SD_LoggingError = 1; |
211 | SD_LoggingError = 1; |
215 | } |
212 | } |
216 | } |
213 | } |
217 | else |
214 | else |
218 | { |
215 | { |
219 | logfilestate = LOGFILE_ERROR; |
216 | logfilestate = LOGFILE_ERROR; |
220 | UART1_PutString("\r\nError getting free kml-file name\r\n"); |
217 | UART1_PutString("\r\nError getting free kml-file name\r\n"); |
221 | SD_LoggingError = 2; |
218 | SD_LoggingError = 2; |
222 | } |
219 | } |
223 | // else retry in next loop |
220 | // else retry in next loop |
224 | break; |
221 | break; |
225 | case LOGFILE_OPENED: |
222 | case LOGFILE_OPENED: |
226 | // append new gps log data |
223 | // append new gps log data |
227 | if((GPSData.Status != INVALID) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)) |
224 | if((GPSData.Status != INVALID) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)) |
228 | { |
225 | { |
229 | if(!KML_LoggGPSCoordinates(&logfile)) |
226 | if(!KML_LoggGPSCoordinates(&logfile)) |
230 | { // error logging data |
227 | { // error logging data |
231 | UART1_PutString("\r\nError logging to kml-file\r\n"); |
228 | UART1_PutString("\r\nError logging to kml-file\r\n"); |
232 | SD_LoggingError = 3; |
229 | SD_LoggingError = 3; |
233 | KML_DocumentClose(&logfile); |
230 | KML_DocumentClose(&logfile); |
234 | logfilestate = LOGFILE_ERROR; |
231 | logfilestate = LOGFILE_ERROR; |
235 | } |
232 | } |
236 | else // sucessfully logged |
233 | else // sucessfully logged |
237 | { |
234 | { |
238 | SD_LoggingError = 0; |
235 | SD_LoggingError = 0; |
239 | if(CheckDelay(flushtimer)) |
236 | if(CheckDelay(flushtimer)) |
240 | { |
237 | { |
241 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
238 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
242 | fflush_(logfile.file); |
239 | fflush_(logfile.file); |
243 | } |
240 | } |
244 | } |
241 | } |
245 | 242 | ||
246 | } |
243 | } |
247 | break; |
244 | break; |
248 | 245 | ||
249 | case LOGFILE_ERROR: |
246 | case LOGFILE_ERROR: |
250 | break; |
247 | break; |
251 | 248 | ||
252 | default: |
249 | default: |
253 | logfilestate = LOGFILE_IDLE; |
250 | logfilestate = LOGFILE_IDLE; |
254 | break; |
251 | break; |
255 | } |
252 | } |
256 | } // EOF motors are not running |
253 | } // EOF motors are not running |
257 | else // model is not flying |
254 | else // model is not flying |
258 | { // close log file if opened |
255 | { // close log file if opened |
259 | if(logfilestate == LOGFILE_OPENED) |
256 | if(logfilestate == LOGFILE_OPENED) |
260 | { |
257 | { |
261 | if(KML_DocumentClose(&logfile)) |
258 | if(KML_DocumentClose(&logfile)) |
262 | { |
259 | { |
263 | UART1_PutString("\r\nClosing kml-file\r\n"); |
260 | UART1_PutString("\r\nClosing kml-file\r\n"); |
264 | logfilestate = LOGFILE_CLOSED; |
261 | logfilestate = LOGFILE_CLOSED; |
265 | } |
262 | } |
266 | else // could not be closed |
263 | else // could not be closed |
267 | { |
264 | { |
268 | UART1_PutString("\r\nError closing kml-file\r\n"); |
265 | UART1_PutString("\r\nError closing kml-file\r\n"); |
269 | SD_LoggingError = 4; |
266 | SD_LoggingError = 4; |
270 | logfilestate = LOGFILE_ERROR; |
267 | logfilestate = LOGFILE_ERROR; |
271 | } |
268 | } |
272 | } |
269 | } |
273 | } //EOF motors are not running |
270 | } //EOF motors are not running |
274 | } // EOF Check LogTimer |
271 | } // EOF Check LogTimer |
275 | 272 | ||
276 | return logfilestate; |
273 | return logfilestate; |
277 | } |
274 | } |
278 | 275 | ||
279 | //---------------------------------------------------------------------------------------------------- |
276 | //---------------------------------------------------------------------------------------------------- |
280 | // logs gps and state info to a gpx file |
277 | // logs gps and state info to a gpx file |
281 | logfilestate_t Logging_GPX(u32 LogDelay) |
278 | logfilestate_t Logging_GPX(u32 LogDelay) |
282 | { |
279 | { |
283 | static logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate |
280 | static logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate |
284 | static s8* logfilename = NULL; // the pointer to the logfilename |
281 | static s8* logfilename = NULL; // the pointer to the logfilename |
285 | static u32 logtimer = 0, flushtimer = 0; // the log update timer |
282 | static u32 logtimer = 0, flushtimer = 0; // the log update timer |
286 | static GPX_Document_t logfile; // the logfilehandle |
283 | static GPX_Document_t logfile; // the logfilehandle |
287 | static u8 part = 0; |
284 | static u8 part = 0; |
288 | u32 measure_time; |
285 | u32 measure_time; |
289 | 286 | ||
290 | // initialize if LogDelay is zero |
287 | // initialize if LogDelay is zero |
291 | if(!LogDelay) |
288 | if(!LogDelay) |
292 | { |
289 | { |
293 | switch(logfilestate) |
290 | switch(logfilestate) |
294 | { |
291 | { |
295 | case LOGFILE_OPENED: |
292 | case LOGFILE_OPENED: |
296 | GPX_DocumentClose(&logfile); // try to close it |
293 | GPX_DocumentClose(&logfile); // try to close it |
297 | break; |
294 | break; |
298 | default: |
295 | default: |
299 | break; |
296 | break; |
300 | } |
297 | } |
301 | logfilestate = LOGFILE_IDLE; |
298 | logfilestate = LOGFILE_IDLE; |
302 | logfilename = NULL; |
299 | logfilename = NULL; |
303 | GPX_DocumentInit(&logfile); |
300 | GPX_DocumentInit(&logfile); |
304 | logtimer = SetDelay(0); // set logtimer to now |
301 | logtimer = SetDelay(0); // set logtimer to now |
305 | return logfilestate; |
302 | return logfilestate; |
306 | } |
303 | } |
307 | // no init |
304 | // no init |
308 | if(CheckDelay(logtimer) || part) |
305 | if(CheckDelay(logtimer) || part) |
309 | { |
306 | { |
310 | if(!part) logtimer = SetDelay(LogDelay); // standard interval |
307 | if(!part) logtimer = SetDelay(LogDelay); // standard interval |
311 | 308 | ||
312 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN || part) |
309 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN || part) |
313 | { |
310 | { |
314 | switch(logfilestate) |
311 | switch(logfilestate) |
315 | { |
312 | { |
316 | case LOGFILE_IDLE: |
313 | case LOGFILE_IDLE: |
317 | case LOGFILE_CLOSED: |
314 | case LOGFILE_CLOSED: |
318 | if((GPSData.Status != INVALID) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D) && (FC.StatusFlags & FC_STATUS_FLY)) |
315 | if((GPSData.Status != INVALID) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D) && (FC.StatusFlags & FC_STATUS_FLY)) |
319 | { |
316 | { |
320 | logfilestate = LOGFILE_START; |
317 | logfilestate = LOGFILE_START; |
321 | } |
318 | } |
322 | part = 0; |
319 | part = 0; |
323 | break; |
320 | break; |
324 | case LOGFILE_START: |
321 | case LOGFILE_START: |
325 | // find unused logfile name |
322 | // find unused logfile name |
326 | do |
323 | do |
327 | { // try to generate a new logfile name |
324 | { // try to generate a new logfile name |
328 | logfilename = GenerateGPXLogFileName(); |
325 | logfilename = GenerateGPXLogFileName(); |
329 | }while((logfilename != NULL) && fexist_(logfilename)); |
326 | }while((logfilename != NULL) && fexist_(logfilename)); |
330 | // if logfilename exist |
327 | // if logfilename exist |
331 | if(logfilename != NULL) |
328 | if(logfilename != NULL) |
332 | { |
329 | { |
333 | // try to create the log file |
330 | // try to create the log file |
334 | if(GPX_DocumentOpen(logfilename, &logfile)) |
331 | if(GPX_DocumentOpen(logfilename, &logfile)) |
335 | { |
332 | { |
336 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
333 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
337 | logfilestate = LOGFILE_OPENED; // goto next step |
334 | logfilestate = LOGFILE_OPENED; // goto next step |
338 | UART1_PutString("\r\nOpening gpx-file:"); |
335 | UART1_PutString("\r\nOpening gpx-file:"); |
339 | UART1_PutString(logfilename); |
336 | UART1_PutString(logfilename); |
340 | UART1_PutString("\r\n"); |
337 | UART1_PutString("\r\n"); |
341 | } |
338 | } |
342 | else // could not be openend |
339 | else // could not be openend |
343 | { |
340 | { |
344 | logfilestate = LOGFILE_ERROR; |
341 | logfilestate = LOGFILE_ERROR; |
345 | UART1_PutString("\r\nError opening gpx-file: "); |
342 | UART1_PutString("\r\nError opening gpx-file: "); |
346 | UART1_PutString(logfilename); |
343 | UART1_PutString(logfilename); |
347 | UART1_PutString("\r\n"); |
344 | UART1_PutString("\r\n"); |
348 | SD_LoggingError = 11; |
345 | SD_LoggingError = 11; |
349 | logtimer = SetDelay(10); // try again in open logfile in 10 mili sec |
346 | logtimer = SetDelay(10); // try again in open logfile in 10 mili sec |
350 | } |
347 | } |
351 | } |
348 | } |
352 | else |
349 | else |
353 | { |
350 | { |
354 | logfilestate = LOGFILE_ERROR; |
351 | logfilestate = LOGFILE_ERROR; |
355 | UART1_PutString("\r\nError getting free gpx-file name\r\n"); |
352 | UART1_PutString("\r\nError getting free gpx-file name\r\n"); |
356 | SD_LoggingError = 12; |
353 | SD_LoggingError = 12; |
357 | } |
354 | } |
358 | // else retry in next loop |
355 | // else retry in next loop |
359 | part = 0; |
356 | part = 0; |
360 | break; |
357 | break; |
361 | case LOGFILE_OPENED: |
358 | case LOGFILE_OPENED: |
362 | // append new gps log data |
359 | // append new gps log data |
363 | measure_time = CountMilliseconds; |
360 | measure_time = CountMilliseconds; |
364 | if((GPSData.Status != INVALID) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)) |
361 | if((GPSData.Status != INVALID) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)) |
365 | { |
362 | { |
366 | if(!GPX_LoggGPSCoordinates(&logfile,part)) |
363 | if(!GPX_LoggGPSCoordinates(&logfile,part)) |
367 | { // error logging data |
364 | { // error logging data |
368 | UART1_PutString("\r\nError logging to gpx-file\r\n"); |
365 | UART1_PutString("\r\nError logging to gpx-file\r\n"); |
369 | GPX_DocumentClose(&logfile); |
366 | GPX_DocumentClose(&logfile); |
370 | SD_LoggingError = 13; |
367 | SD_LoggingError = 13; |
371 | logfilestate = LOGFILE_ERROR; |
368 | logfilestate = LOGFILE_ERROR; |
372 | } |
369 | } |
373 | else // successful log |
370 | else // successful log |
374 | { |
371 | { |
375 | if(CheckDelay(flushtimer)) |
372 | if(CheckDelay(flushtimer)) |
376 | { |
373 | { |
377 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
374 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
378 | LED_RED_ON; |
- | |
379 | - | ||
380 | fflush_(logfile.file); |
375 | fflush_(logfile.file); |
381 | LED_RED_OFF; |
- | |
382 | - | ||
383 | } |
376 | } |
384 | } |
377 | } |
385 | } |
378 | } |
386 | if(++part == 9) part = 0; |
379 | if(++part == 9) part = 0; |
387 | //DebugOut.Analog[19] = CountMilliseconds - measure_time; |
380 | //DebugOut.Analog[19] = CountMilliseconds - measure_time; |
388 | break; |
381 | break; |
389 | 382 | ||
390 | case LOGFILE_ERROR: |
383 | case LOGFILE_ERROR: |
391 | part = 0; |
384 | part = 0; |
392 | break; |
385 | break; |
393 | 386 | ||
394 | default: |
387 | default: |
395 | part = 0; |
388 | part = 0; |
396 | logfilestate = LOGFILE_IDLE; |
389 | logfilestate = LOGFILE_IDLE; |
397 | break; |
390 | break; |
398 | } |
391 | } |
399 | } // EOF model is flying |
392 | } // EOF model is flying |
400 | else // model is not flying |
393 | else // model is not flying |
401 | { // close log file if opened |
394 | { // close log file if opened |
402 | if(logfilestate == LOGFILE_OPENED) |
395 | if(logfilestate == LOGFILE_OPENED) |
403 | { |
396 | { |
404 | if(GPX_DocumentClose(&logfile)) |
397 | if(GPX_DocumentClose(&logfile)) |
405 | { |
398 | { |
406 | UART1_PutString("\r\nClosing gpx-file\r\n"); |
399 | UART1_PutString("\r\nClosing gpx-file\r\n"); |
407 | logfilestate = LOGFILE_CLOSED; |
400 | logfilestate = LOGFILE_CLOSED; |
408 | part = 0; |
401 | part = 0; |
409 | } |
402 | } |
410 | else // could not be closed |
403 | else // could not be closed |
411 | { |
404 | { |
412 | UART1_PutString("\r\nError closing gpx-file\r\n"); |
405 | UART1_PutString("\r\nError closing gpx-file\r\n"); |
413 | SD_LoggingError = 14; |
406 | SD_LoggingError = 14; |
414 | logfilestate = LOGFILE_ERROR; |
407 | logfilestate = LOGFILE_ERROR; |
415 | part = 0; |
408 | part = 0; |
416 | } |
409 | } |
417 | } |
410 | } |
418 | } //EOF model is not flying |
411 | } //EOF model is not flying |
419 | } // EOF Check LogTimer |
412 | } // EOF Check LogTimer |
420 | 413 | ||
421 | return logfilestate; |
414 | return logfilestate; |
422 | } |
415 | } |
423 | 416 | ||
424 | //---------------------------------------------------------------------------------------------------- |
417 | //---------------------------------------------------------------------------------------------------- |
425 | // initialize logging |
418 | // initialize logging |
426 | void Logging_Init(void) |
419 | void Logging_Init(void) |
427 | { |
420 | { |
428 | SD_LoggingError = 0; |
421 | SD_LoggingError = 0; |
429 | LogCfg.KML_Interval = 1000; //default |
422 | LogCfg.KML_Interval = 1000; //default |
430 | Settings_GetParamValue(PID_KML_LOGGING, (u16*)&LogCfg.KML_Interval); // overwrite by settings value |
423 | Settings_GetParamValue(PID_KML_LOGGING, (u16*)&LogCfg.KML_Interval); // overwrite by settings value |
431 | if(LogCfg.KML_Interval != 0 && LogCfg.KML_Interval < MIN_SD_INTERVAL) LogCfg.KML_Interval = MIN_SD_INTERVAL; |
424 | if(LogCfg.KML_Interval != 0 && LogCfg.KML_Interval < MIN_SD_INTERVAL_KML) LogCfg.KML_Interval = MIN_SD_INTERVAL_KML; |
432 | 425 | ||
433 | Logging_KML(0); // initialize |
426 | Logging_KML(0); // initialize |
434 | LogCfg.GPX_Interval = 0; //default |
427 | LogCfg.GPX_Interval = 0; //default |
435 | Settings_GetParamValue(PID_GPX_LOGGING, (u16*)&LogCfg.GPX_Interval); // overwrite by settings value |
428 | Settings_GetParamValue(PID_GPX_LOGGING, (u16*)&LogCfg.GPX_Interval); // overwrite by settings value |
436 | if(LogCfg.GPX_Interval != 0 && LogCfg.GPX_Interval < MIN_SD_INTERVAL) LogCfg.GPX_Interval = MIN_SD_INTERVAL; |
429 | if(LogCfg.GPX_Interval != 0 && LogCfg.GPX_Interval < MIN_SD_INTERVAL_GPX) LogCfg.GPX_Interval = MIN_SD_INTERVAL_GPX; |
437 | Logging_GPX(0); // initialize |
430 | Logging_GPX(0); // initialize |
438 | } |
431 | } |
439 | 432 | ||
440 | //---------------------------------------------------------------------------------------------------- |
433 | //---------------------------------------------------------------------------------------------------- |
441 | // gobal logging handler |
434 | // gobal logging handler |
442 | void Logging_Update(void) |
435 | void Logging_Update(void) |
443 | { |
436 | { |
444 | static u8 logmodule = 0; |
437 | static u8 logmodule = 0; |
445 | static u32 logtimer = 0; |
438 | static u32 logtimer = 0; |
446 | static logfilestate_t logstate = LOGFILE_IDLE; |
439 | static logfilestate_t logstate = LOGFILE_IDLE; |
447 | 440 | ||
448 | if(SD_SWITCH) // a card is in slot |
441 | if(SD_SWITCH) // a card is in slot |
449 | { |
442 | { |
450 | if((logstate == LOGFILE_ERROR) && (FC.StatusFlags & FC_STATUS_START)) SD_LoggingError = 100; |
443 | if((logstate == LOGFILE_ERROR) && (FC.StatusFlags & FC_STATUS_START)) SD_LoggingError = 100; |
451 | if(CheckDelay(logtimer)) |
444 | if(CheckDelay(logtimer)) |
452 | { |
445 | { |
453 | logtimer = SetDelay(10); // faster makes no sense |
446 | logtimer = SetDelay(10); // faster makes no sense |
454 | // call the logger handlers if no error has occured |
447 | // call the logger handlers if no error has occured |
455 | if(logstate != LOGFILE_ERROR) |
448 | if(logstate != LOGFILE_ERROR) |
456 | { // run only one logging handler per loop |
449 | { // run only one logging handler per loop |
457 | switch(logmodule++) |
450 | switch(logmodule++) |
458 | { |
451 | { |
459 | case 0: |
452 | case 0: |
460 | logstate = Logging_KML(LogCfg.KML_Interval); |
453 | logstate = Logging_KML(LogCfg.KML_Interval); |
461 | break; |
454 | break; |
462 | case 1: |
455 | case 1: |
463 | logstate = Logging_GPX(LogCfg.GPX_Interval); |
456 | logstate = Logging_GPX(LogCfg.GPX_Interval); |
464 | logmodule = 0; // resart with first log module |
457 | logmodule = 0; // resart with first log module |
465 | break; |
458 | break; |
466 | default: |
459 | default: |
467 | logmodule = 0; |
460 | logmodule = 0; |
468 | break; |
461 | break; |
469 | } |
462 | } |
470 | } |
463 | } |
471 | else // a logging error has occured |
464 | else // a logging error has occured |
472 | { |
465 | { |
473 | // /* |
466 | // /* |
474 | // try to reinitialize sd-card when motors are not running |
467 | // try to reinitialize sd-card when motors are not running |
475 | if(!(FC.StatusFlags & FC_STATUS_MOTOR_RUN)) |
468 | if(!(FC.StatusFlags & FC_STATUS_MOTOR_RUN)) |
476 | { |
469 | { |
477 | if(Fat16_IsValid()) // wait for reinizialization of fat16 from outside |
470 | if(Fat16_IsValid()) // wait for reinizialization of fat16 from outside |
478 | { |
471 | { |
479 | Logging_Init(); // initialize the logs |
472 | Logging_Init(); // initialize the logs |
480 | logstate = LOGFILE_IDLE; |
473 | logstate = LOGFILE_IDLE; |
481 | logtimer = SetDelay(100); // try next log in 100 mili sec |
474 | logtimer = SetDelay(100); // try next log in 100 mili sec |
482 | } |
475 | } |
483 | else |
476 | else |
484 | { // retry in 5 seconds |
477 | { // retry in 5 seconds |
485 | logtimer = SetDelay(5000); // try again in 5 sec |
478 | logtimer = SetDelay(5000); // try again in 5 sec |
486 | } |
479 | } |
487 | } // EOF motors are not running |
480 | } // EOF motors are not running |
488 | // */ |
481 | // */ |
489 | } //EOF logfile error |
482 | } //EOF logfile error |
490 | } // EOF CheckDelay |
483 | } // EOF CheckDelay |
491 | }// EOF Card in Slot |
484 | }// EOF Card in Slot |
492 | } |
485 | } |
493 | 486 |