Rev 721 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 721 | Rev 722 | ||
---|---|---|---|
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" |
66 | #include "logging.h" |
67 | #include "triggerlog.h" |
67 | #include "triggerlog.h" |
68 | 68 | ||
69 | #define MIN_SD_INTERVAL_KML 200 |
69 | #define MIN_SD_INTERVAL_KML 200 |
70 | #define MIN_SD_INTERVAL_GPX 200 |
70 | #define MIN_SD_INTERVAL_GPX 200 |
71 | 71 | ||
72 | u8 SD_LoggingError = 0; |
72 | u8 SD_LoggingError = 0; |
73 | 73 | ||
74 | - | ||
75 | typedef enum |
74 | |
76 | { |
- | |
77 | LOGFILE_IDLE, |
- | |
78 | LOGFILE_START, |
- | |
79 | LOGFILE_CLOSED, |
- | |
80 | LOGFILE_OPENED, |
- | |
81 | LOGFILE_ERROR |
- | |
82 | } logfilestate_t; |
75 | |
83 | 76 | ||
84 | // logger handler prototypes |
77 | // logger handler prototypes |
85 | logfilestate_t Logging_KML(u32 LogDelay); |
78 | logfilestate_t Logging_KML(u32 LogDelay); |
86 | logfilestate_t Logging_GPX(u32 LogDelay); |
79 | logfilestate_t Logging_GPX(u32 LogDelay); |
87 | 80 | ||
88 | LogCfg_t LogCfg = {500 , 1000}; |
81 | LogCfg_t LogCfg = {500 , 1000}; |
89 | u32 Logged_GPX_Counter = 0, Logged_KML_Counter = 0; |
82 | u32 Logged_GPX_Counter = 0, Logged_KML_Counter = 0; |
90 | u16 KML_Filenum = 0, GPX_Filenum = 0, GPX_logging_active = 0; |
83 | u16 KML_Filenum = 0, GPX_Filenum = 0, GPX_logging_active = 0; |
91 | 84 | ||
92 | //---------------------------------------------------------------------------------------------------- |
85 | //---------------------------------------------------------------------------------------------------- |
93 | s8* GenerateKMLLogFileName(void) |
86 | s8* GenerateKMLLogFileName(void) |
94 | { |
87 | { |
95 | static u16 filenum = 0; // file name counter |
88 | static u16 filenum = 0; // file name counter |
96 | static s8 filename[40]; |
89 | static s8 filename[40]; |
97 | static DateTime_t LastTime = {0,0,0,0,0,0,0,0}; |
90 | static DateTime_t LastTime = {0,0,0,0,0,0,0,0}; |
98 | 91 | ||
99 | if(SystemTime.Valid) |
92 | if(SystemTime.Valid) |
100 | { |
93 | { |
101 | // if the day has been changed |
94 | // if the day has been changed |
102 | if((LastTime.Year != SystemTime.Year) || (LastTime.Month != SystemTime.Month) || (LastTime.Day != SystemTime.Day)) |
95 | if((LastTime.Year != SystemTime.Year) || (LastTime.Month != SystemTime.Month) || (LastTime.Day != SystemTime.Day)) |
103 | { |
96 | { |
104 | LastTime.Year = SystemTime.Year; |
97 | LastTime.Year = SystemTime.Year; |
105 | LastTime.Month = SystemTime.Month; |
98 | LastTime.Month = SystemTime.Month; |
106 | LastTime.Day = SystemTime.Day; |
99 | LastTime.Day = SystemTime.Day; |
107 | LastTime.Valid = 1; |
100 | LastTime.Valid = 1; |
108 | filenum = 0; // reset file counter |
101 | filenum = 0; // reset file counter |
109 | } |
102 | } |
110 | if(!(SimulationFlags & SIMULATION_ACTIVE)) |
103 | if(!(SimulationFlags & SIMULATION_ACTIVE)) |
111 | { |
104 | { |
112 | if(filenum < 100) sprintf(filename, "/LOG/%04i%02i%02i/KML/%02i%02i%02i%02i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Year % 100, SystemTime.Month, SystemTime.Day, filenum); |
105 | if(filenum < 100) sprintf(filename, "/LOG/%04i%02i%02i/KML/%02i%02i%02i%02i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Year % 100, SystemTime.Month, SystemTime.Day, filenum); |
113 | else sprintf(filename, "/LOG/%04i%02i%02i/KML/GPS%05i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
106 | else sprintf(filename, "/LOG/%04i%02i%02i/KML/GPS%05i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
114 | } |
107 | } |
115 | else |
108 | else |
116 | { |
109 | { |
117 | if(filenum < 100&& SystemTime.Year > 2000) sprintf(filename, "/SIMULATE/%04i%02i%02i/KML/S%1i%02i%02i%02i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Year % 10, SystemTime.Month, SystemTime.Day, filenum); |
110 | if(filenum < 100&& SystemTime.Year > 2000) sprintf(filename, "/SIMULATE/%04i%02i%02i/KML/S%1i%02i%02i%02i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Year % 10, SystemTime.Month, SystemTime.Day, filenum); |
118 | else sprintf(filename, "/SIMULATE/%04i%02i%02i/KML/SIM%05i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
111 | else sprintf(filename, "/SIMULATE/%04i%02i%02i/KML/SIM%05i.KML", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
119 | } |
112 | } |
120 | 113 | ||
121 | filenum++; |
114 | filenum++; |
122 | KML_Filenum = filenum; |
115 | KML_Filenum = filenum; |
123 | return filename; |
116 | return filename; |
124 | } |
117 | } |
125 | else return NULL; |
118 | else return NULL; |
126 | } |
119 | } |
127 | 120 | ||
128 | //---------------------------------------------------------------------------------------------------- |
121 | //---------------------------------------------------------------------------------------------------- |
129 | s8* GenerateGPXLogFileName(void) |
122 | s8* GenerateGPXLogFileName(void) |
130 | { |
123 | { |
131 | static u16 filenum = 0; // file name counter |
124 | static u16 filenum = 0; // file name counter |
132 | static s8 filename[40]; |
125 | static s8 filename[40]; |
133 | static DateTime_t LastTime = {0,0,0,0,0,0,0,0}; |
126 | static DateTime_t LastTime = {0,0,0,0,0,0,0,0}; |
134 | 127 | ||
135 | if(SystemTime.Valid) |
128 | if(SystemTime.Valid) |
136 | { |
129 | { |
137 | // if the day has been changed |
130 | // if the day has been changed |
138 | if((LastTime.Year != SystemTime.Year) || (LastTime.Month != SystemTime.Month) || (LastTime.Day != SystemTime.Day)) |
131 | if((LastTime.Year != SystemTime.Year) || (LastTime.Month != SystemTime.Month) || (LastTime.Day != SystemTime.Day)) |
139 | { |
132 | { |
140 | LastTime.Year = SystemTime.Year; |
133 | LastTime.Year = SystemTime.Year; |
141 | LastTime.Month = SystemTime.Month; |
134 | LastTime.Month = SystemTime.Month; |
142 | LastTime.Day = SystemTime.Day; |
135 | LastTime.Day = SystemTime.Day; |
143 | LastTime.Valid = 1; |
136 | LastTime.Valid = 1; |
144 | filenum = 0; // reset file counter |
137 | filenum = 0; // reset file counter |
145 | } |
138 | } |
146 | if(!(SimulationFlags & SIMULATION_ACTIVE)) |
139 | if(!(SimulationFlags & SIMULATION_ACTIVE)) |
147 | { |
140 | { |
148 | if(filenum < 100) sprintf(filename, "/LOG/%04i%02i%02i/GPX/%02i%02i%02i%02i.GPX", SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Year % 100, SystemTime.Month, SystemTime.Day, filenum); |
141 | if(filenum < 100) sprintf(filename, "/LOG/%04i%02i%02i/GPX/%02i%02i%02i%02i.GPX", SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Year % 100, SystemTime.Month, SystemTime.Day, filenum); |
149 | else sprintf(filename, "/LOG/%04i%02i%02i/GPX/GPS%05i.GPX", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
142 | else sprintf(filename, "/LOG/%04i%02i%02i/GPX/GPS%05i.GPX", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
150 | } |
143 | } |
151 | else |
144 | else |
152 | { |
145 | { |
153 | if(filenum < 100 && SystemTime.Year > 2000) sprintf(filename, "/SIMULATE/%04i%02i%02i/GPX/S%i%02i%02i%02i.GPX", SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Year % 10, SystemTime.Month, SystemTime.Day, filenum); |
146 | if(filenum < 100 && SystemTime.Year > 2000) sprintf(filename, "/SIMULATE/%04i%02i%02i/GPX/S%i%02i%02i%02i.GPX", SystemTime.Year, SystemTime.Month, SystemTime.Day, SystemTime.Year % 10, SystemTime.Month, SystemTime.Day, filenum); |
154 | else sprintf(filename, "/SIMULATE/%04i%02i%02i/GPX/SIM%05i.GPX", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
147 | else sprintf(filename, "/SIMULATE/%04i%02i%02i/GPX/SIM%05i.GPX", SystemTime.Year, SystemTime.Month, SystemTime.Day, filenum); |
155 | } |
148 | } |
156 | GPX_Filenum = filenum; |
149 | GPX_Filenum = filenum; |
157 | filenum++; |
150 | filenum++; |
158 | return filename; |
151 | return filename; |
159 | } |
152 | } |
160 | else return NULL; |
153 | else return NULL; |
161 | } |
154 | } |
162 | 155 | ||
163 | 156 | ||
164 | 157 | ||
165 | //---------------------------------------------------------------------------------------------------- |
158 | //---------------------------------------------------------------------------------------------------- |
166 | // logs the current gps position to a kml file |
159 | // logs the current gps position to a kml file |
167 | logfilestate_t Logging_KML(u32 LogDelay) |
160 | logfilestate_t Logging_KML(u32 LogDelay) |
168 | { |
161 | { |
169 | static logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate |
162 | static logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate |
170 | static s8* logfilename = NULL; // the pointer to the logfilename |
163 | static s8* logfilename = NULL; // the pointer to the logfilename |
171 | static u32 logtimer = 0, flushtimer = 0; // the log update timer |
164 | static u32 logtimer = 0, flushtimer = 0; // the log update timer |
172 | static KML_Document_t logfile; // the logfilehandle |
165 | static KML_Document_t logfile; // the logfilehandle |
173 | static u32 appendtimer = 0; // the log update timer |
166 | static u32 appendtimer = 0; // the log update timer |
174 | static u8 logging_active = 0; |
167 | static u8 logging_active = 0; |
175 | 168 | ||
176 | // initialize if LogDelay is zero |
169 | // initialize if LogDelay is zero |
177 | if(!LogDelay) |
170 | if(!LogDelay) |
178 | { |
171 | { |
179 | switch(logfilestate) |
172 | switch(logfilestate) |
180 | { |
173 | { |
181 | case LOGFILE_OPENED: |
174 | case LOGFILE_OPENED: |
182 | KML_DocumentClose(&logfile); // try to close it |
175 | KML_DocumentClose(&logfile); // try to close it |
183 | break; |
176 | break; |
184 | default: |
177 | default: |
185 | break; |
178 | break; |
186 | } |
179 | } |
187 | logfilestate = LOGFILE_IDLE; |
180 | logfilestate = LOGFILE_IDLE; |
188 | logfilename = NULL; |
181 | logfilename = NULL; |
189 | KML_DocumentInit(&logfile); |
182 | KML_DocumentInit(&logfile); |
190 | logtimer = SetDelay(0); // set logtimer to now |
183 | logtimer = SetDelay(0); // set logtimer to now |
191 | return logfilestate; |
184 | return logfilestate; |
192 | } |
185 | } |
193 | // no init |
186 | // no init |
194 | if(CheckDelay(logtimer)) |
187 | if(CheckDelay(logtimer)) |
195 | { |
188 | { |
196 | logtimer = SetDelay(LogDelay); // standard interval |
189 | logtimer = SetDelay(LogDelay); // standard interval |
197 | 190 | ||
198 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) |
191 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) |
199 | { |
192 | { |
200 | logging_active = 1; |
193 | logging_active = 1; |
201 | appendtimer = SetDelay(APPEND_LOG_TIME_MS); |
194 | appendtimer = SetDelay(APPEND_LOG_TIME_MS); |
202 | } |
195 | } |
203 | else |
196 | else |
204 | { |
197 | { |
205 | if(CheckDelay(appendtimer)) logging_active = 0; |
198 | if(CheckDelay(appendtimer)) logging_active = 0; |
206 | } |
199 | } |
207 | 200 | ||
208 | if(logging_active) |
201 | if(logging_active) |
209 | { |
202 | { |
210 | switch(logfilestate) |
203 | switch(logfilestate) |
211 | { |
204 | { |
212 | case LOGFILE_IDLE: |
205 | case LOGFILE_IDLE: |
213 | case LOGFILE_CLOSED: |
206 | case LOGFILE_CLOSED: |
214 | if((GPSData.Status != INVALID) && (SystemTime.Valid) && /*(GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)*/ (FC.StatusFlags & FC_STATUS_FLY)) |
207 | if((GPSData.Status != INVALID) && (SystemTime.Valid) && /*(GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)*/ (FC.StatusFlags & FC_STATUS_FLY)) |
215 | { |
208 | { |
216 | logfilestate = LOGFILE_START; |
209 | logfilestate = LOGFILE_START; |
217 | } |
210 | } |
218 | break; |
211 | break; |
219 | case LOGFILE_START: |
212 | case LOGFILE_START: |
220 | // find unused logfile name |
213 | // find unused logfile name |
221 | do |
214 | do |
222 | { // try to generate a new logfile name |
215 | { // try to generate a new logfile name |
223 | logfilename = GenerateKMLLogFileName(); |
216 | logfilename = GenerateKMLLogFileName(); |
224 | }while((logfilename != NULL) && fexist_(logfilename)); |
217 | }while((logfilename != NULL) && fexist_(logfilename)); |
225 | // if logfilename exist |
218 | // if logfilename exist |
226 | if(logfilename != NULL) |
219 | if(logfilename != NULL) |
227 | { |
220 | { |
228 | // try to create the log file |
221 | // try to create the log file |
229 | if(KML_DocumentOpen(logfilename, &logfile)) |
222 | if(KML_DocumentOpen(logfilename, &logfile)) |
230 | { |
223 | { |
231 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
224 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
232 | logfilestate = LOGFILE_OPENED; // goto next step |
225 | logfilestate = LOGFILE_OPENED; // goto next step |
233 | UART1_PutString("\r\nOpening kml-file:"); |
226 | UART1_PutString("\r\nOpening kml-file:"); |
234 | UART1_PutString(logfilename); |
227 | UART1_PutString(logfilename); |
235 | UART1_PutString("\r\n"); |
228 | UART1_PutString("\r\n"); |
236 | } |
229 | } |
237 | else // could not be openend |
230 | else // could not be openend |
238 | { |
231 | { |
239 | logfilestate = LOGFILE_ERROR; |
232 | logfilestate = LOGFILE_ERROR; |
240 | UART1_PutString("\r\nError opening kml-file: "); |
233 | UART1_PutString("\r\nError opening kml-file: "); |
241 | UART1_PutString(logfilename); |
234 | UART1_PutString(logfilename); |
242 | UART1_PutString("\r\n"); |
235 | UART1_PutString("\r\n"); |
243 | logtimer = SetDelay(10); // try again in open logfile in 10 mili sec |
236 | logtimer = SetDelay(10); // try again in open logfile in 10 mili sec |
244 | SD_LoggingError = 1; |
237 | SD_LoggingError = 1; |
245 | } |
238 | } |
246 | } |
239 | } |
247 | else |
240 | else |
248 | { |
241 | { |
249 | logfilestate = LOGFILE_ERROR; |
242 | logfilestate = LOGFILE_ERROR; |
250 | UART1_PutString("\r\nError getting free kml-file name\r\n"); |
243 | UART1_PutString("\r\nError getting free kml-file name\r\n"); |
251 | SD_LoggingError = 2; |
244 | SD_LoggingError = 2; |
252 | } |
245 | } |
253 | // else retry in next loop |
246 | // else retry in next loop |
254 | break; |
247 | break; |
255 | case LOGFILE_OPENED: |
248 | case LOGFILE_OPENED: |
256 | // append new gps log data |
249 | // append new gps log data |
257 | if((GPSData.Status != INVALID))// && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)) |
250 | if((GPSData.Status != INVALID))// && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)) |
258 | { |
251 | { |
259 | if(!KML_LoggGPSCoordinates(&logfile)) |
252 | if(!KML_LoggGPSCoordinates(&logfile)) |
260 | { // error logging data |
253 | { // error logging data |
261 | UART1_PutString("\r\nError logging to kml-file\r\n"); |
254 | UART1_PutString("\r\nError logging to kml-file\r\n"); |
262 | SD_LoggingError = 3; |
255 | SD_LoggingError = 3; |
263 | KML_DocumentClose(&logfile); |
256 | KML_DocumentClose(&logfile); |
264 | logfilestate = LOGFILE_ERROR; |
257 | logfilestate = LOGFILE_ERROR; |
265 | } |
258 | } |
266 | else // sucessfully logged |
259 | else // sucessfully logged |
267 | { |
260 | { |
268 | SD_LoggingError = 0; |
261 | SD_LoggingError = 0; |
269 | if(CheckDelay(flushtimer)) |
262 | if(CheckDelay(flushtimer)) |
270 | { |
263 | { |
271 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
264 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
272 | fflush_(logfile.file); |
265 | fflush_(logfile.file); |
273 | } |
266 | } |
274 | } |
267 | } |
275 | 268 | ||
276 | } |
269 | } |
277 | break; |
270 | break; |
278 | 271 | ||
279 | case LOGFILE_ERROR: |
272 | case LOGFILE_ERROR: |
280 | break; |
273 | break; |
281 | 274 | ||
282 | default: |
275 | default: |
283 | logfilestate = LOGFILE_IDLE; |
276 | logfilestate = LOGFILE_IDLE; |
284 | break; |
277 | break; |
285 | } |
278 | } |
286 | } // EOF motors are not running |
279 | } // EOF motors are not running |
287 | else // model is not flying |
280 | else // model is not flying |
288 | { // close log file if opened |
281 | { // close log file if opened |
289 | if(logfilestate == LOGFILE_OPENED) |
282 | if(logfilestate == LOGFILE_OPENED) |
290 | { |
283 | { |
291 | if(KML_DocumentClose(&logfile)) |
284 | if(KML_DocumentClose(&logfile)) |
292 | { |
285 | { |
293 | UART1_PutString("\r\nClosing kml-file\r\n"); |
286 | UART1_PutString("\r\nClosing kml-file\r\n"); |
294 | logfilestate = LOGFILE_CLOSED; |
287 | logfilestate = LOGFILE_CLOSED; |
295 | } |
288 | } |
296 | else // could not be closed |
289 | else // could not be closed |
297 | { |
290 | { |
298 | UART1_PutString("\r\nError closing kml-file\r\n"); |
291 | UART1_PutString("\r\nError closing kml-file\r\n"); |
299 | SD_LoggingError = 4; |
292 | SD_LoggingError = 4; |
300 | logfilestate = LOGFILE_ERROR; |
293 | logfilestate = LOGFILE_ERROR; |
301 | } |
294 | } |
302 | } |
295 | } |
303 | } //EOF motors are not running |
296 | } //EOF motors are not running |
304 | } // EOF Check LogTimer |
297 | } // EOF Check LogTimer |
305 | 298 | ||
306 | return logfilestate; |
299 | return logfilestate; |
307 | } |
300 | } |
308 | 301 | ||
309 | //---------------------------------------------------------------------------------------------------- |
302 | //---------------------------------------------------------------------------------------------------- |
310 | // logs gps and state info to a gpx file |
303 | // logs gps and state info to a gpx file |
311 | logfilestate_t Logging_GPX(u32 LogDelay) |
304 | logfilestate_t Logging_GPX(u32 LogDelay) |
312 | { |
305 | { |
313 | static logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate |
306 | static logfilestate_t logfilestate = LOGFILE_IDLE; // the current logfilestate |
314 | static s8* logfilename = NULL; // the pointer to the logfilename |
307 | static s8* logfilename = NULL; // the pointer to the logfilename |
315 | static u32 logtimer = 0, flushtimer = 0, appendtimer = 0; // the log update timer |
308 | static u32 logtimer = 0, flushtimer = 0, appendtimer = 0; // the log update timer |
316 | static GPX_Document_t logfile; // the logfilehandle |
309 | static GPX_Document_t logfile; // the logfilehandle |
317 | static u8 part = 0, old_errorcode = 0; |
310 | static u8 part = 0, old_errorcode = 0; |
318 | // u32 measure_time; |
311 | // u32 measure_time; |
319 | 312 | ||
320 | // initialize if LogDelay is zero |
313 | // initialize if LogDelay is zero |
321 | if(!LogDelay) |
314 | if(!LogDelay) |
322 | { |
315 | { |
323 | switch(logfilestate) |
316 | switch(logfilestate) |
324 | { |
317 | { |
325 | case LOGFILE_OPENED: |
318 | case LOGFILE_OPENED: |
326 | GPX_DocumentClose(&logfile); // try to close it |
319 | GPX_DocumentClose(&logfile); // try to close it |
327 | break; |
320 | break; |
328 | default: |
321 | default: |
329 | break; |
322 | break; |
330 | } |
323 | } |
331 | logfilestate = LOGFILE_IDLE; |
324 | logfilestate = LOGFILE_IDLE; |
332 | logfilename = NULL; |
325 | logfilename = NULL; |
333 | GPX_DocumentInit(&logfile); |
326 | GPX_DocumentInit(&logfile); |
334 | logtimer = SetDelay(0); // set logtimer to now |
327 | logtimer = SetDelay(0); // set logtimer to now |
335 | return logfilestate; |
328 | return logfilestate; |
336 | } |
329 | } |
337 | // no init |
330 | // no init |
338 | if(CheckDelay(logtimer) || part) |
331 | if(CheckDelay(logtimer) || part) |
339 | { |
332 | { |
340 | if(!part) logtimer = SetDelay(LogDelay); // standard interval |
333 | if(!part) logtimer = SetDelay(LogDelay); // standard interval |
341 | 334 | ||
342 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) |
335 | if(FC.StatusFlags & FC_STATUS_MOTOR_RUN) |
343 | { |
336 | { |
344 | if(!GPX_logging_active) GPX_logging_active = 1; |
337 | if(!GPX_logging_active) GPX_logging_active = 1; |
345 | appendtimer = SetDelay(APPEND_LOG_TIME_MS); |
338 | appendtimer = SetDelay(APPEND_LOG_TIME_MS); |
346 | } |
339 | } |
347 | else |
340 | else |
348 | { |
341 | { |
349 | if(CheckDelay(appendtimer)) GPX_logging_active = 0; |
342 | if(CheckDelay(appendtimer)) GPX_logging_active = 0; |
350 | } |
343 | } |
351 | 344 | ||
352 | if(GPX_logging_active || part) |
345 | if(GPX_logging_active || part) |
353 | { |
346 | { |
354 | switch(logfilestate) |
347 | switch(logfilestate) |
355 | { |
348 | { |
356 | case LOGFILE_IDLE: |
349 | case LOGFILE_IDLE: |
357 | case LOGFILE_CLOSED: |
350 | case LOGFILE_CLOSED: |
358 | if((GPSData.Status != INVALID) && (SystemTime.Valid) && |
351 | if((GPSData.Status != INVALID) && (SystemTime.Valid) && |
359 | ((FC.StatusFlags & FC_STATUS_FLY) || (LogCfg.StartAtMotorrun && (FC.StatusFlags & FC_STATUS_MOTOR_RUN)))) |
352 | ((FC.StatusFlags & FC_STATUS_FLY) || (LogCfg.StartAtMotorrun && (FC.StatusFlags & FC_STATUS_MOTOR_RUN)))) |
360 | { |
353 | { |
361 | logfilestate = LOGFILE_START; |
354 | logfilestate = LOGFILE_START; |
362 | } |
355 | } |
363 | part = 0; |
356 | part = 0; |
364 | break; |
357 | break; |
365 | case LOGFILE_START: |
358 | case LOGFILE_START: |
366 | // find unused logfile name |
359 | // find unused logfile name |
367 | do |
360 | do |
368 | { // try to generate a new logfile name |
361 | { // try to generate a new logfile name |
369 | logfilename = GenerateGPXLogFileName(); |
362 | logfilename = GenerateGPXLogFileName(); |
370 | }while((logfilename != NULL) && fexist_(logfilename)); |
363 | }while((logfilename != NULL) && fexist_(logfilename)); |
371 | // if logfilename exist |
364 | // if logfilename exist |
372 | if(logfilename != NULL) |
365 | if(logfilename != NULL) |
373 | { |
366 | { |
374 | // try to create the log file |
367 | // try to create the log file |
375 | if(GPX_DocumentOpen(logfilename, &logfile)) |
368 | if(GPX_DocumentOpen(logfilename, &logfile)) |
376 | { |
369 | { |
377 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
370 | flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
378 | logfilestate = LOGFILE_OPENED; // goto next step |
371 | logfilestate = LOGFILE_OPENED; // goto next step |
379 | UART1_PutString("\r\nOpening gpx-file:"); |
372 | UART1_PutString("\r\nOpening gpx-file:"); |
380 | UART1_PutString(logfilename); |
373 | UART1_PutString(logfilename); |
381 | UART1_PutString("\r\n"); |
374 | UART1_PutString("\r\n"); |
382 | GPX_logging_active = 2; |
375 | GPX_logging_active = 2; |
383 | } |
376 | } |
384 | else // could not be openend |
377 | else // could not be openend |
385 | { |
378 | { |
386 | logfilestate = LOGFILE_ERROR; |
379 | logfilestate = LOGFILE_ERROR; |
387 | UART1_PutString("\r\nError opening gpx-file: "); |
380 | UART1_PutString("\r\nError opening gpx-file: "); |
388 | UART1_PutString(logfilename); |
381 | UART1_PutString(logfilename); |
389 | UART1_PutString("\r\n"); |
382 | UART1_PutString("\r\n"); |
390 | SD_LoggingError = 11; |
383 | SD_LoggingError = 11; |
391 | logtimer = SetDelay(10); // try again in open logfile in 10 mili sec |
384 | logtimer = SetDelay(10); // try again in open logfile in 10 mili sec |
392 | } |
385 | } |
393 | old_errorcode = ErrorCode; |
386 | old_errorcode = ErrorCode; |
394 | } |
387 | } |
395 | else |
388 | else |
396 | { |
389 | { |
397 | logfilestate = LOGFILE_ERROR; |
390 | logfilestate = LOGFILE_ERROR; |
398 | UART1_PutString("\r\nError getting free gpx-file name\r\n"); |
391 | UART1_PutString("\r\nError getting free gpx-file name\r\n"); |
399 | SD_LoggingError = 12; |
392 | SD_LoggingError = 12; |
400 | } |
393 | } |
401 | // else retry in next loop |
394 | // else retry in next loop |
402 | part = 0; |
395 | part = 0; |
403 | break; |
396 | break; |
404 | case LOGFILE_OPENED: |
397 | case LOGFILE_OPENED: |
405 | // append new gps log data |
398 | // append new gps log data |
406 | // measure_time = CountMilliseconds; |
399 | // measure_time = CountMilliseconds; |
407 | if((GPSData.Status != INVALID))// && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)) |
400 | if((GPSData.Status != INVALID))// && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)) |
408 | { |
401 | { |
409 | if(!GPX_LoggGPSCoordinates(&logfile,part)) |
402 | if(!GPX_LoggGPSCoordinates(&logfile,part)) |
410 | { // error logging data |
403 | { // error logging data |
411 | UART1_PutString("\r\nError logging to gpx-file\r\n"); |
404 | UART1_PutString("\r\nError logging to gpx-file\r\n"); |
412 | GPX_DocumentClose(&logfile); |
405 | GPX_DocumentClose(&logfile); |
413 | SD_LoggingError = 13; |
406 | SD_LoggingError = 13; |
414 | logfilestate = LOGFILE_ERROR; |
407 | logfilestate = LOGFILE_ERROR; |
415 | } |
408 | } |
416 | else // successful log |
409 | else // successful log |
417 | { |
410 | { |
418 | if(ErrorCode != old_errorcode || CheckDelay(flushtimer) || part == 8) |
411 | if(ErrorCode != old_errorcode || CheckDelay(flushtimer) || part == 8) |
419 | { |
412 | { |
420 | if(ErrorCode) { while(++part < 9) GPX_LoggGPSCoordinates(&logfile,part); }; // close this chapter |
413 | if(ErrorCode) { while(++part < 9) GPX_LoggGPSCoordinates(&logfile,part); }; // close this chapter |
421 | if(ErrorCode != old_errorcode) flushtimer = SetDelay(1000); |
414 | if(ErrorCode != old_errorcode) flushtimer = SetDelay(1000); |
422 | else flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
415 | else flushtimer = SetDelay(LOG_FLUSH_INTERVAL); |
423 | fflush_(logfile.file); |
416 | fflush_(logfile.file); |
424 | old_errorcode = ErrorCode; |
417 | old_errorcode = ErrorCode; |
425 | } |
418 | } |
426 | } |
419 | } |
427 | } |
420 | } |
428 | if(++part >= 9) part = 0; |
421 | if(++part >= 9) part = 0; |
429 | //DebugOut.Analog[] = CountMilliseconds - measure_time; |
422 | //DebugOut.Analog[] = CountMilliseconds - measure_time; |
430 | break; |
423 | break; |
431 | 424 | ||
432 | case LOGFILE_ERROR: |
425 | case LOGFILE_ERROR: |
433 | part = 0; |
426 | part = 0; |
434 | break; |
427 | break; |
435 | 428 | ||
436 | default: |
429 | default: |
437 | part = 0; |
430 | part = 0; |
438 | logfilestate = LOGFILE_IDLE; |
431 | logfilestate = LOGFILE_IDLE; |
439 | break; |
432 | break; |
440 | } |
433 | } |
441 | } // EOF model is flying |
434 | } // EOF model is flying |
442 | else // model is not flying |
435 | else // model is not flying |
443 | { // close log file if opened |
436 | { // close log file if opened |
444 | if(logfilestate == LOGFILE_OPENED) |
437 | if(logfilestate == LOGFILE_OPENED) |
445 | { |
438 | { |
446 | if(GPX_DocumentClose(&logfile)) |
439 | if(GPX_DocumentClose(&logfile)) |
447 | { |
440 | { |
448 | UART1_PutString("\r\nClosing gpx-file\r\n"); |
441 | UART1_PutString("\r\nClosing gpx-file\r\n"); |
449 | logfilestate = LOGFILE_CLOSED; |
442 | logfilestate = LOGFILE_CLOSED; |
450 | part = 0; |
443 | part = 0; |
451 | } |
444 | } |
452 | else // could not be closed |
445 | else // could not be closed |
453 | { |
446 | { |
454 | UART1_PutString("\r\nError closing gpx-file\r\n"); |
447 | UART1_PutString("\r\nError closing gpx-file\r\n"); |
455 | SD_LoggingError = 14; |
448 | SD_LoggingError = 14; |
456 | logfilestate = LOGFILE_ERROR; |
449 | logfilestate = LOGFILE_ERROR; |
457 | part = 0; |
450 | part = 0; |
458 | } |
451 | } |
459 | } |
452 | } |
460 | } //EOF model is not flying |
453 | } //EOF model is not flying |
461 | } // EOF Check LogTimer |
454 | } // EOF Check LogTimer |
462 | 455 | ||
463 | return logfilestate; |
456 | return logfilestate; |
464 | } |
457 | } |
465 | 458 | ||
466 | //---------------------------------------------------------------------------------------------------- |
459 | //---------------------------------------------------------------------------------------------------- |
467 | // initialize logging |
460 | // initialize logging |
468 | void Logging_Init(void) |
461 | void Logging_Init(void) |
469 | { |
462 | { |
470 | SD_LoggingError = 0; |
463 | SD_LoggingError = 0; |
471 | LogCfg.KML_Interval = 1000; //default |
464 | LogCfg.KML_Interval = 1000; //default |
472 | Settings_GetParamValue(PID_KML_LOGGING, (u16*)&LogCfg.KML_Interval); // overwrite by settings value |
465 | Settings_GetParamValue(PID_KML_LOGGING, (u16*)&LogCfg.KML_Interval); // overwrite by settings value |
473 | if(LogCfg.KML_Interval != 0 && LogCfg.KML_Interval < MIN_SD_INTERVAL_KML) LogCfg.KML_Interval = MIN_SD_INTERVAL_KML; |
466 | if(LogCfg.KML_Interval != 0 && LogCfg.KML_Interval < MIN_SD_INTERVAL_KML) LogCfg.KML_Interval = MIN_SD_INTERVAL_KML; |
474 | 467 | ||
475 | Logging_KML(0); // initialize |
468 | Logging_KML(0); // initialize |
476 | LogCfg.GPX_Interval = 0; //default |
469 | LogCfg.GPX_Interval = 0; //default |
477 | Settings_GetParamValue(PID_GPX_LOGGING, (u16*)&LogCfg.GPX_Interval); // overwrite by settings value |
470 | Settings_GetParamValue(PID_GPX_LOGGING, (u16*)&LogCfg.GPX_Interval); // overwrite by settings value |
478 | Settings_GetParamValue(PID_LOG_AT_MOTORRUN, (u16*)&LogCfg.StartAtMotorrun); // overwrite by settings value |
471 | Settings_GetParamValue(PID_LOG_AT_MOTORRUN, (u16*)&LogCfg.StartAtMotorrun); // overwrite by settings value |
479 | if(LogCfg.GPX_Interval != 0 && LogCfg.GPX_Interval < MIN_SD_INTERVAL_GPX) LogCfg.GPX_Interval = MIN_SD_INTERVAL_GPX; |
472 | if(LogCfg.GPX_Interval != 0 && LogCfg.GPX_Interval < MIN_SD_INTERVAL_GPX) LogCfg.GPX_Interval = MIN_SD_INTERVAL_GPX; |
480 | Logging_GPX(0); // initialize |
473 | Logging_GPX(0); // initialize |
481 | } |
474 | } |
482 | 475 | ||
483 | //---------------------------------------------------------------------------------------------------- |
476 | //---------------------------------------------------------------------------------------------------- |
484 | // gobal logging handler |
477 | // gobal logging handler |
485 | void Logging_Update(void) |
478 | void Logging_Update(void) |
486 | { |
479 | { |
487 | static u8 logmodule = 0; |
480 | static u8 logmodule = 0; |
488 | static u32 logtimer = 0; |
481 | static u32 logtimer = 0; |
489 | static logfilestate_t logstate = LOGFILE_IDLE; |
482 | static logfilestate_t logstate = LOGFILE_IDLE; |
490 | 483 | ||
491 | if(SD_SWITCH) // a card is in slot |
484 | if(SD_SWITCH) // a card is in slot |
492 | { |
485 | { |
493 | if((logstate == LOGFILE_ERROR) && (FC.StatusFlags & FC_STATUS_START)) SD_LoggingError = 100; |
486 | if((logstate == LOGFILE_ERROR) && (FC.StatusFlags & FC_STATUS_START)) SD_LoggingError = 100; |
494 | if(CheckDelay(logtimer)) |
487 | if(CheckDelay(logtimer)) |
495 | { |
488 | { |
496 | logtimer = SetDelay(10); // faster makes no sense |
489 | logtimer = SetDelay(10); // faster makes no sense |
497 | // call the logger handlers if no error has occured |
490 | // call the logger handlers if no error has occured |
498 | if(logstate != LOGFILE_ERROR) |
491 | if(logstate != LOGFILE_ERROR) |
499 | { // run only one logging handler per loop |
492 | { // run only one logging handler per loop |
500 | switch(logmodule++) |
493 | switch(logmodule++) |
501 | { |
494 | { |
502 | case 0: |
495 | case 0: |
503 | logstate = Logging_KML(LogCfg.KML_Interval); |
496 | logstate = Logging_KML(LogCfg.KML_Interval); |
504 | break; |
497 | break; |
505 | case 1: |
498 | case 1: |
506 | logstate = Logging_GPX(LogCfg.GPX_Interval); |
499 | logstate = Logging_GPX(LogCfg.GPX_Interval); |
507 | break; |
500 | break; |
508 | case 2: |
501 | case 2: |
509 | if(UART_VersionInfo.HWMajor >= 30) logstate = LoggingTrigger(200); |
502 | if(UART_VersionInfo.HWMajor >= 30) logstate = LoggingTrigger(200); |
510 | logmodule = 0; // resart with first log module |
503 | logmodule = 0; // resart with first log module |
511 | break; |
504 | break; |
512 | default: |
505 | default: |
513 | logmodule = 0; |
506 | logmodule = 0; |
514 | break; |
507 | break; |
515 | } |
508 | } |
516 | } |
509 | } |
517 | else // a logging error has occured |
510 | else // a logging error has occured |
518 | { |
511 | { |
519 | // /* |
512 | // /* |
520 | // try to reinitialize sd-card when motors are not running |
513 | // try to reinitialize sd-card when motors are not running |
521 | if(!(FC.StatusFlags & FC_STATUS_MOTOR_RUN)) |
514 | if(!(FC.StatusFlags & FC_STATUS_MOTOR_RUN)) |
522 | { |
515 | { |
523 | if(Fat16_IsValid()) // wait for reinizialization of fat16 from outside |
516 | if(Fat16_IsValid()) // wait for reinizialization of fat16 from outside |
524 | { |
517 | { |
525 | Logging_Init(); // initialize the logs |
518 | Logging_Init(); // initialize the logs |
526 | logstate = LOGFILE_IDLE; |
519 | logstate = LOGFILE_IDLE; |
527 | logtimer = SetDelay(100); // try next log in 100 mili sec |
520 | logtimer = SetDelay(100); // try next log in 100 mili sec |
528 | } |
521 | } |
529 | else |
522 | else |
530 | { // retry in 5 seconds |
523 | { // retry in 5 seconds |
531 | logtimer = SetDelay(5000); // try again in 5 sec |
524 | logtimer = SetDelay(5000); // try again in 5 sec |
532 | } |
525 | } |
533 | } // EOF motors are not running |
526 | } // EOF motors are not running |
534 | // */ |
527 | // */ |
535 | } //EOF logfile error |
528 | } //EOF logfile error |
536 | } // EOF CheckDelay |
529 | } // EOF CheckDelay |
537 | }// EOF Card in Slot |
530 | }// EOF Card in Slot |
538 | } |
531 | } |
539 | 532 |