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