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