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