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