Rev 519 | Rev 540 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 519 | Rev 521 | ||
---|---|---|---|
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 <ctype.h> |
56 | #include <ctype.h> |
57 | #include <stdio.h> |
57 | #include <stdio.h> |
58 | #include <stdlib.h> |
58 | #include <stdlib.h> |
59 | #include <string.h> |
59 | #include <string.h> |
60 | #include "91x_lib.h" |
60 | #include "91x_lib.h" |
61 | #include "waypoints.h" |
61 | #include "waypoints.h" |
62 | #include "uart1.h" |
62 | #include "uart1.h" |
63 | #include "fat16.h" |
63 | #include "fat16.h" |
64 | #include "main.h" |
64 | #include "main.h" |
65 | #include "spi_slave.h" |
65 | #include "spi_slave.h" |
66 | 66 | ||
67 | 67 | ||
68 | WPL_Store_t WPL_Store; |
68 | WPL_Store_t WPL_Store; |
69 | 69 | ||
70 | // the waypoints list |
70 | // the waypoints list |
71 | #define MAX_LIST_LEN 101 |
71 | #define MAX_LIST_LEN 101 |
72 | 72 | ||
73 | Point_t PointList[MAX_LIST_LEN]; |
73 | Point_t PointList[MAX_LIST_LEN]; |
74 | u8 WPIndex = 0; // list index of GPS point representig the current WP, can be maximal WPCount |
74 | u8 WPIndex = 0; // list index of GPS point representig the current WP, can be maximal WPCount |
75 | u8 POIIndex = 0; // list index of GPS Point representing the current POI, can be maximal WPCount |
75 | u8 POIIndex = 0; // list index of GPS Point representing the current POI, can be maximal WPCount |
76 | u8 WPCount = 0; // number of waypoints |
76 | u8 WPCount = 0; // number of waypoints |
77 | u8 PointCount = 0; // number of points in the list can be maximal equal to MAX_LIST_LEN |
77 | u8 PointCount = 0; // number of points in the list can be maximal equal to MAX_LIST_LEN |
78 | u8 POICount = 0; // number of point of interest in the list |
78 | u8 POICount = 0; // number of point of interest in the list |
79 | s16 HeadingOld = -1; |
79 | s16 HeadingOld = -1; |
80 | 80 | ||
81 | u8 WPActive = FALSE; |
81 | u8 WPActive = FALSE; |
82 | 82 | ||
83 | u8 PointList_Init(void) |
83 | u8 PointList_Init(void) |
84 | { |
84 | { |
85 | return PointList_Clear(); |
85 | return PointList_Clear(); |
86 | } |
86 | } |
87 | 87 | ||
88 | u8 PointList_Clear(void) |
88 | u8 PointList_Clear(void) |
89 | { |
89 | { |
90 | u8 i; |
90 | u8 i; |
91 | WPIndex = 0; // real list position are 1 ,2, 3 ... |
91 | WPIndex = 0; // real list position are 1 ,2, 3 ... |
92 | POIIndex = 0; // real list position are 1 ,2, 3 ... |
92 | POIIndex = 0; // real list position are 1 ,2, 3 ... |
93 | WPCount = 0; // no waypoints |
93 | WPCount = 0; // no waypoints |
94 | POICount = 0; |
94 | POICount = 0; |
95 | PointCount = 0; // no contents |
95 | PointCount = 0; // no contents |
96 | WPActive = FALSE; |
96 | WPActive = FALSE; |
97 | NaviData.WaypointNumber = WPCount; |
97 | NaviData.WaypointNumber = WPCount; |
98 | NaviData.WaypointIndex = 0; |
98 | NaviData.WaypointIndex = 0; |
99 | for(i = 0; i < MAX_LIST_LEN; i++) |
99 | for(i = 0; i < MAX_LIST_LEN; i++) |
100 | { |
100 | { |
101 | PointList[i].Position.Status = INVALID; |
101 | PointList[i].Position.Status = INVALID; |
102 | PointList[i].Position.Latitude = 0; |
102 | PointList[i].Position.Latitude = 0; |
103 | PointList[i].Position.Longitude = 0; |
103 | PointList[i].Position.Longitude = 0; |
104 | PointList[i].Position.Altitude = 0; |
104 | PointList[i].Position.Altitude = 0; |
105 | PointList[i].Heading = 361; // invalid value |
105 | PointList[i].Heading = 361; // invalid value |
106 | PointList[i].ToleranceRadius = 0; // in meters, if the MK is within that range around the target, then the next target is triggered |
106 | PointList[i].ToleranceRadius = 0; // in meters, if the MK is within that range around the target, then the next target is triggered |
107 | PointList[i].HoldTime = 0; // in seconds, if the was once in the tolerance area around a WP, this time defines the delay before the next WP is triggered |
107 | PointList[i].HoldTime = 0; // in seconds, if the was once in the tolerance area around a WP, this time defines the delay before the next WP is triggered |
108 | PointList[i].Event_Flag = 0; // future implementation |
108 | PointList[i].Event_Flag = 0; // future implementation |
109 | PointList[i].Index = 0; |
109 | PointList[i].Index = 0; |
110 | PointList[i].Type = POINT_TYPE_INVALID; |
110 | PointList[i].Type = POINT_TYPE_INVALID; |
111 | PointList[i].WP_EventChannelValue = 0; |
111 | PointList[i].WP_EventChannelValue = 0; |
112 | PointList[i].AltitudeRate = 0; // no change of setpoint |
112 | PointList[i].AltitudeRate = 0; // no change of setpoint |
113 | PointList[i].Speed = 0; |
113 | PointList[i].Speed = 0; |
114 | PointList[i].CamAngle = 0; |
114 | PointList[i].CamAngle = 0; |
115 | PointList[i].Name[0] = 0; |
115 | PointList[i].Name[0] = 0; |
116 | } |
116 | } |
117 | ClearWLP_Name(); |
117 | ClearWLP_Name(); |
118 | return TRUE; |
118 | return TRUE; |
119 | } |
119 | } |
120 | 120 | ||
121 | u8 PointList_GetCount(void) |
121 | u8 PointList_GetCount(void) |
122 | { |
122 | { |
123 | return PointCount; // number of points in the list |
123 | return PointCount; // number of points in the list |
124 | } |
124 | } |
125 | 125 | ||
126 | Point_t* PointList_GetAt(u8 index) |
126 | Point_t* PointList_GetAt(u8 index) |
127 | { |
127 | { |
128 | if((index > 0) && (index <= PointCount)) return(&(PointList[index-1])); // return pointer to this waypoint |
128 | if((index > 0) && (index <= PointCount)) return(&(PointList[index-1])); // return pointer to this waypoint |
129 | else return(NULL); |
129 | else return(NULL); |
130 | } |
130 | } |
131 | 131 | ||
132 | u8 PointList_SetAt(Point_t* pPoint) |
132 | u8 PointList_SetAt(Point_t* pPoint) |
133 | { |
133 | { |
134 | // if index is in range |
134 | // if index is in range |
135 | if((pPoint->Index > 0) && (pPoint->Index <= MAX_LIST_LEN)) |
135 | if((pPoint->Index > 0) && (pPoint->Index <= MAX_LIST_LEN)) |
136 | { |
136 | { |
137 | // check list entry before update |
137 | // check list entry before update |
138 | switch(PointList[pPoint->Index-1].Type) |
138 | switch(PointList[pPoint->Index-1].Type) |
139 | { |
139 | { |
140 | case POINT_TYPE_INVALID: // was invalid |
140 | case POINT_TYPE_INVALID: // was invalid |
141 | switch(pPoint->Type) |
141 | switch(pPoint->Type) |
142 | { |
142 | { |
143 | default: |
143 | default: |
144 | case POINT_TYPE_INVALID: |
144 | case POINT_TYPE_INVALID: |
145 | // nothing to do |
145 | // nothing to do |
146 | break; |
146 | break; |
147 | 147 | ||
148 | case POINT_TYPE_WP: |
148 | case POINT_TYPE_WP: |
149 | WPCount++; |
149 | WPCount++; |
150 | PointCount++; |
150 | PointCount++; |
151 | break; |
151 | break; |
152 | 152 | ||
153 | case POINT_TYPE_POI: |
153 | case POINT_TYPE_POI: |
154 | POICount++; |
154 | POICount++; |
155 | PointCount++; |
155 | PointCount++; |
156 | break; |
156 | break; |
157 | } |
157 | } |
158 | break; |
158 | break; |
159 | 159 | ||
160 | case POINT_TYPE_WP: // was a waypoint |
160 | case POINT_TYPE_WP: // was a waypoint |
161 | switch(pPoint->Type) |
161 | switch(pPoint->Type) |
162 | { |
162 | { |
163 | case POINT_TYPE_INVALID: |
163 | case POINT_TYPE_INVALID: |
164 | WPCount--; |
164 | WPCount--; |
165 | PointCount--; |
165 | PointCount--; |
166 | break; |
166 | break; |
167 | 167 | ||
168 | default: |
168 | default: |
169 | case POINT_TYPE_WP: |
169 | case POINT_TYPE_WP: |
170 | //nothing to do |
170 | //nothing to do |
171 | break; |
171 | break; |
172 | 172 | ||
173 | case POINT_TYPE_POI: |
173 | case POINT_TYPE_POI: |
174 | POICount++; |
174 | POICount++; |
175 | WPCount--; |
175 | WPCount--; |
176 | break; |
176 | break; |
177 | } |
177 | } |
178 | break; |
178 | break; |
179 | 179 | ||
180 | case POINT_TYPE_POI: // was a poi |
180 | case POINT_TYPE_POI: // was a poi |
181 | switch(pPoint->Type) |
181 | switch(pPoint->Type) |
182 | { |
182 | { |
183 | case POINT_TYPE_INVALID: |
183 | case POINT_TYPE_INVALID: |
184 | POICount--; |
184 | POICount--; |
185 | PointCount--; |
185 | PointCount--; |
186 | break; |
186 | break; |
187 | 187 | ||
188 | case POINT_TYPE_WP: |
188 | case POINT_TYPE_WP: |
189 | WPCount++; |
189 | WPCount++; |
190 | POICount--; |
190 | POICount--; |
191 | break; |
191 | break; |
192 | 192 | ||
193 | case POINT_TYPE_POI: |
193 | case POINT_TYPE_POI: |
194 | default: |
194 | default: |
195 | // nothing to do |
195 | // nothing to do |
196 | break; |
196 | break; |
197 | } |
197 | } |
198 | break; |
198 | break; |
199 | } |
199 | } |
200 | memcpy(&PointList[pPoint->Index-1], pPoint, sizeof(Point_t)); // copy data to list entry |
200 | memcpy(&PointList[pPoint->Index-1], pPoint, sizeof(Point_t)); // copy data to list entry |
201 | NaviData.WaypointNumber = WPCount; |
201 | NaviData.WaypointNumber = WPCount; |
202 | return pPoint->Index; |
202 | return pPoint->Index; |
203 | } |
203 | } |
204 | else return(0); |
204 | else return(0); |
205 | } |
205 | } |
206 | 206 | ||
207 | // returns the pointer to the first waypoint within the list |
207 | // returns the pointer to the first waypoint within the list |
208 | Point_t* PointList_WPBegin(void) |
208 | Point_t* PointList_WPBegin(void) |
209 | { |
209 | { |
210 | u8 i; |
210 | u8 i; |
211 | WPIndex = 0; // set list position invalid |
211 | WPIndex = 0; // set list position invalid |
212 | 212 | ||
213 | if(WPActive == FALSE) return(NULL); |
213 | if(WPActive == FALSE) return(NULL); |
214 | 214 | ||
215 | POIIndex = 0; // set invalid POI |
215 | POIIndex = 0; // set invalid POI |
216 | if(PointCount > 0) |
216 | if(PointCount > 0) |
217 | { |
217 | { |
218 | // search for first wp in list |
218 | // search for first wp in list |
219 | for(i = 0; i <MAX_LIST_LEN; i++) |
219 | for(i = 0; i <MAX_LIST_LEN; i++) |
220 | { |
220 | { |
221 | if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) |
221 | if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) |
222 | { |
222 | { |
223 | WPIndex = i + 1; |
223 | WPIndex = i + 1; |
224 | break; |
224 | break; |
225 | } |
225 | } |
226 | } |
226 | } |
227 | if(WPIndex) // found a WP in the list |
227 | if(WPIndex) // found a WP in the list |
228 | { |
228 | { |
229 | NaviData.WaypointIndex = 1; |
229 | NaviData.WaypointIndex = 1; |
230 | // update index to POI |
230 | // update index to POI |
231 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
231 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
232 | else POIIndex = 0; |
232 | else POIIndex = 0; |
233 | } |
233 | } |
234 | else // some points in the list but no WP found |
234 | else // some points in the list but no WP found |
235 | { |
235 | { |
236 | NaviData.WaypointIndex = 0; |
236 | NaviData.WaypointIndex = 0; |
237 | //Check for an existing POI |
237 | //Check for an existing POI |
238 | for(i = 0; i < MAX_LIST_LEN; i++) |
238 | for(i = 0; i < MAX_LIST_LEN; i++) |
239 | { |
239 | { |
240 | if((PointList[i].Type == POINT_TYPE_POI) && (PointList[i].Position.Status != INVALID)) |
240 | if((PointList[i].Type == POINT_TYPE_POI) && (PointList[i].Position.Status != INVALID)) |
241 | { |
241 | { |
242 | POIIndex = i + 1; |
242 | POIIndex = i + 1; |
243 | break; |
243 | break; |
244 | } |
244 | } |
245 | } |
245 | } |
246 | } |
246 | } |
247 | } |
247 | } |
248 | else // no point in the list |
248 | else // no point in the list |
249 | { |
249 | { |
250 | POIIndex = 0; |
250 | POIIndex = 0; |
251 | NaviData.WaypointIndex = 0; |
251 | NaviData.WaypointIndex = 0; |
252 | } |
252 | } |
253 | 253 | ||
254 | if(WPIndex) return(&(PointList[WPIndex-1])); |
254 | if(WPIndex) return(&(PointList[WPIndex-1])); |
255 | else return(NULL); |
255 | else return(NULL); |
256 | } |
256 | } |
257 | 257 | ||
258 | // returns the last waypoint |
258 | // returns the last waypoint |
259 | Point_t* PointList_WPEnd(void) |
259 | Point_t* PointList_WPEnd(void) |
260 | { |
260 | { |
261 | 261 | ||
262 | u8 i; |
262 | u8 i; |
263 | WPIndex = 0; // set list position invalid |
263 | WPIndex = 0; // set list position invalid |
264 | POIIndex = 0; // set invalid |
264 | POIIndex = 0; // set invalid |
265 | 265 | ||
266 | if(WPActive == FALSE) return(NULL); |
266 | if(WPActive == FALSE) return(NULL); |
267 | 267 | ||
268 | if(PointCount > 0) |
268 | if(PointCount > 0) |
269 | { |
269 | { |
270 | // search backward! |
270 | // search backward! |
271 | for(i = 1; i <= MAX_LIST_LEN; i++) |
271 | for(i = 1; i <= MAX_LIST_LEN; i++) |
272 | { |
272 | { |
273 | if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_WP) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID)) |
273 | if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_WP) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID)) |
274 | { |
274 | { |
275 | WPIndex = MAX_LIST_LEN - i + 1; |
275 | WPIndex = MAX_LIST_LEN - i + 1; |
276 | break; |
276 | break; |
277 | } |
277 | } |
278 | } |
278 | } |
279 | if(WPIndex) // found a WP within the list |
279 | if(WPIndex) // found a WP within the list |
280 | { |
280 | { |
281 | NaviData.WaypointIndex = WPCount; |
281 | NaviData.WaypointIndex = WPCount; |
282 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
282 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
283 | else POIIndex = 0; |
283 | else POIIndex = 0; |
284 | } |
284 | } |
285 | else // list contains some points but no WP in the list |
285 | else // list contains some points but no WP in the list |
286 | { |
286 | { |
287 | // search backward for a POI! |
287 | // search backward for a POI! |
288 | for(i = 1; i <= MAX_LIST_LEN; i++) |
288 | for(i = 1; i <= MAX_LIST_LEN; i++) |
289 | { |
289 | { |
290 | if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_POI) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID)) |
290 | if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_POI) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID)) |
291 | { |
291 | { |
292 | POIIndex = MAX_LIST_LEN - i + 1; |
292 | POIIndex = MAX_LIST_LEN - i + 1; |
293 | break; |
293 | break; |
294 | } |
294 | } |
295 | } |
295 | } |
296 | NaviData.WaypointIndex = 0; |
296 | NaviData.WaypointIndex = 0; |
297 | } |
297 | } |
298 | } |
298 | } |
299 | else // no point in the list |
299 | else // no point in the list |
300 | { |
300 | { |
301 | POIIndex = 0; |
301 | POIIndex = 0; |
302 | NaviData.WaypointIndex = 0; |
302 | NaviData.WaypointIndex = 0; |
303 | } |
303 | } |
304 | if(WPIndex) return(&(PointList[WPIndex-1])); |
304 | if(WPIndex) return(&(PointList[WPIndex-1])); |
305 | else return(NULL); |
305 | else return(NULL); |
306 | } |
306 | } |
307 | 307 | ||
308 | // returns a pointer to the next waypoint or NULL if the end of the list has been reached |
308 | // returns a pointer to the next waypoint or NULL if the end of the list has been reached |
309 | Point_t* PointList_WPNext(void) |
309 | Point_t* PointList_WPNext(void) |
310 | { |
310 | { |
311 | u8 wp_found = 0; |
311 | u8 wp_found = 0; |
312 | if(WPActive == FALSE) return(NULL); |
312 | if(WPActive == FALSE) return(NULL); |
313 | 313 | ||
314 | if(WPIndex < MAX_LIST_LEN) // if there is a next entry in the list |
314 | if(WPIndex < MAX_LIST_LEN) // if there is a next entry in the list |
315 | { |
315 | { |
316 | u8 i; |
316 | u8 i; |
317 | for(i = WPIndex; i < MAX_LIST_LEN; i++) // start search for next at next list entry |
317 | for(i = WPIndex; i < MAX_LIST_LEN; i++) // start search for next at next list entry |
318 | { |
318 | { |
319 | if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) // jump over POIs |
319 | if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) // jump over POIs |
320 | { |
320 | { |
321 | wp_found = i+1; |
321 | wp_found = i+1; |
322 | break; |
322 | break; |
323 | } |
323 | } |
324 | } |
324 | } |
325 | } |
325 | } |
326 | if(wp_found) |
326 | if(wp_found) |
327 | { |
327 | { |
328 | WPIndex = wp_found; // update list position |
328 | WPIndex = wp_found; // update list position |
329 | NaviData.WaypointIndex++; |
329 | NaviData.WaypointIndex++; |
330 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
330 | if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading); |
331 | else POIIndex = 0; |
331 | else POIIndex = 0; |
332 | return(&(PointList[WPIndex-1])); // return pointer to this waypoint |
332 | return(&(PointList[WPIndex-1])); // return pointer to this waypoint |
333 | } |
333 | } |
334 | else |
334 | else |
335 | { // no next wp found |
335 | { // no next wp found |
336 | NaviData.WaypointIndex = 0; |
336 | NaviData.WaypointIndex = 0; |
337 | POIIndex = 0; |
337 | POIIndex = 0; |
338 | return(NULL); |
338 | return(NULL); |
339 | } |
339 | } |
340 | } |
340 | } |
341 | 341 | ||
342 | void PointList_WPActive(u8 set) |
342 | void PointList_WPActive(u8 set) |
343 | { |
343 | { |
344 | if(set) |
344 | if(set) |
345 | { |
345 | { |
346 | WPActive = TRUE; |
346 | WPActive = TRUE; |
347 | PointList_WPBegin(); // updates POI index |
347 | PointList_WPBegin(); // updates POI index |
348 | } |
348 | } |
349 | else |
349 | else |
350 | { |
350 | { |
351 | WPActive = FALSE; |
351 | WPActive = FALSE; |
352 | POIIndex = 0; // disable POI also |
352 | POIIndex = 0; // disable POI also |
353 | } |
353 | } |
354 | } |
354 | } |
355 | 355 | ||
356 | Point_t* PointList_GetPOI(void) |
356 | Point_t* PointList_GetPOI(void) |
357 | { |
357 | { |
358 | return PointList_GetAt(POIIndex); |
358 | return PointList_GetAt(POIIndex); |
359 | } |
359 | } |
360 | 360 | ||
361 | 361 | ||
362 | #define LINE_MAX 70 |
362 | #define LINE_MAX 70 |
363 | #define WP_FILE_VERSION_COMPATIBLE 3 |
363 | #define WP_FILE_VERSION_COMPATIBLE 3 |
364 | 364 | ||
365 | u8 PointList_Save(u8 * filename, u8* listname, u8 overwride) |
365 | u8 PointList_Save(u8 * filename, u8* listname, u8 overwride) |
366 | { |
366 | { |
367 | File_t *fp; |
367 | File_t *fp; |
368 | s8 wpline[LINE_MAX]; |
368 | s8 wpline[LINE_MAX]; |
369 | u8 retval = WPL_ERROR; |
369 | u8 retval = WPL_ERROR; |
370 | 370 | ||
371 | UART1_PutString("\n\r Save WPL..."); |
371 | UART1_PutString("\n\r Save WPL..."); |
372 | 372 | ||
373 | if(Fat16_IsValid()) |
373 | if(Fat16_IsValid()) |
374 | { // check if wpl file is existing |
374 | { // check if wpl file is existing |
375 | if(fexist_(filename)) |
375 | if(fexist_(filename)) |
376 | { //file is existent |
376 | { //file is existent |
377 | if(!(overwride)) |
377 | if(!(overwride)) |
378 | { |
378 | { |
379 | UART1_PutString("Error: file exist!\r\n"); |
379 | UART1_PutString("Error: file exist!\r\n"); |
380 | return(WPL_FILEEXIST); |
380 | return(WPL_FILEEXIST); |
381 | } |
381 | } |
382 | } |
382 | } |
383 | fp = fopen_(filename, 'w'); // try to open the file |
383 | fp = fopen_(filename, 'w'); // try to open the file |
384 | if(fp == NULL) |
384 | if(fp == NULL) |
385 | { |
385 | { |
386 | UART1_PutString("ERROR: Creating waypoint file!\r\n"); |
386 | UART1_PutString("ERROR: Creating waypoint file!\r\n"); |
387 | return(retval); |
387 | return(retval); |
388 | } |
388 | } |
389 | // Create general section and key entries |
389 | // Create general section and key entries |
390 | fputs_("[General]\r\n", fp); |
390 | fputs_("[General]\r\n", fp); |
391 | sprintf(wpline, "Name=%s\r\n", listname); |
391 | sprintf(wpline, "Name=%s\r\n", listname); |
392 | fputs_(wpline, fp); |
392 | fputs_(wpline, fp); |
393 | sprintf(wpline, "FileVersion=%d\r\n", WP_FILE_VERSION_COMPATIBLE); |
393 | sprintf(wpline, "FileVersion=%d\r\n", WP_FILE_VERSION_COMPATIBLE); |
394 | fputs_(wpline, fp); |
394 | fputs_(wpline, fp); |
395 | sprintf(wpline, "NumberOfWaypoints=%d\r\n", PointCount); |
395 | sprintf(wpline, "NumberOfWaypoints=%d\r\n", PointCount); |
396 | fputs_(wpline, fp); |
396 | fputs_(wpline, fp); |
397 | // dump all points if existent |
397 | // dump all points if existent |
398 | if(PointCount) |
398 | if(PointCount) |
399 | { |
399 | { |
400 | u8 i, u8_1; |
400 | u8 i, u8_1; |
401 | s32 i32_1, i32_2; |
401 | s32 i32_1, i32_2; |
402 | NewWPL_Name = 1; |
402 | NewWPL_Name = 1; |
403 | for (i = 0; i < PointCount; i++) |
403 | for (i = 0; i < PointCount; i++) |
404 | { |
404 | { |
405 | sprintf(wpline, "[Point%d]\r\n",PointList[i].Index); |
405 | sprintf(wpline, "[Point%d]\r\n",PointList[i].Index); |
406 | fputs_(wpline, fp); |
406 | fputs_(wpline, fp); |
407 | // write latitude in deg |
407 | // write latitude in deg |
408 | if(PointList[i].Position.Latitude < 0) u8_1 = '-'; |
408 | if(PointList[i].Position.Latitude < 0) u8_1 = '-'; |
409 | else u8_1 = '+'; |
409 | else u8_1 = '+'; |
410 | i32_1 = abs(PointList[i].Position.Latitude)/10000000L; |
410 | i32_1 = abs(PointList[i].Position.Latitude)/10000000L; |
411 | i32_2 = abs(PointList[i].Position.Latitude)%10000000L; |
411 | i32_2 = abs(PointList[i].Position.Latitude)%10000000L; |
412 | sprintf(wpline, "Latitude=%c%ld.%07ld\r\n", u8_1, i32_1, i32_2); |
412 | sprintf(wpline, "Latitude=%c%ld.%07ld\r\n", u8_1, i32_1, i32_2); |
413 | fputs_(wpline, fp); |
413 | fputs_(wpline, fp); |
414 | // write longitude in deg |
414 | // write longitude in deg |
415 | if(PointList[i].Position.Longitude < 0) u8_1 = '-'; |
415 | if(PointList[i].Position.Longitude < 0) u8_1 = '-'; |
416 | else u8_1 = '+'; |
416 | else u8_1 = '+'; |
417 | i32_1 = abs(PointList[i].Position.Longitude)/10000000L; |
417 | i32_1 = abs(PointList[i].Position.Longitude)/10000000L; |
418 | i32_2 = abs(PointList[i].Position.Longitude)%10000000L; |
418 | i32_2 = abs(PointList[i].Position.Longitude)%10000000L; |
419 | sprintf(wpline, "Longitude=%c%ld.%07ld\r\n", u8_1, i32_1, i32_2); |
419 | sprintf(wpline, "Longitude=%c%ld.%07ld\r\n", u8_1, i32_1, i32_2); |
420 | fputs_(wpline, fp); |
420 | fputs_(wpline, fp); |
421 | // write tolerace radius in m |
421 | // write tolerace radius in m |
422 | sprintf(wpline, "Radius=%d\r\n", PointList[i].ToleranceRadius); |
422 | sprintf(wpline, "Radius=%d\r\n", PointList[i].ToleranceRadius); |
423 | fputs_(wpline, fp); |
423 | fputs_(wpline, fp); |
424 | // write altitude in m |
424 | // write altitude in m |
425 | if(PointList[i].Position.Altitude < 0) u8_1 = '-'; |
425 | if(PointList[i].Position.Altitude < 0) u8_1 = '-'; |
426 | else u8_1 = '+'; |
426 | else u8_1 = '+'; |
427 | if(PointList[i].Type == POINT_TYPE_POI) |
427 | if(PointList[i].Type == POINT_TYPE_POI) |
428 | { |
428 | { |
429 | i32_1 = abs(PointList[i].Position.Altitude)/100L; // cm --> m |
429 | i32_1 = abs(PointList[i].Position.Altitude)/100L; // cm --> m |
430 | i32_2 = abs(PointList[i].Position.Altitude)%100L; |
430 | i32_2 = abs(PointList[i].Position.Altitude)%100L; |
431 | } |
431 | } |
432 | else |
432 | else |
433 | { |
433 | { |
434 | i32_1 = abs(PointList[i].Position.Altitude)/10L; // dm --> m |
434 | i32_1 = abs(PointList[i].Position.Altitude)/10L; // dm --> m |
435 | i32_2 = abs(PointList[i].Position.Altitude)%10L; |
435 | i32_2 = abs(PointList[i].Position.Altitude)%10L; |
436 | } |
436 | } |
437 | sprintf(wpline, "Altitude=%c%ld.%01ld\r\n", u8_1, i32_1, i32_2); |
437 | sprintf(wpline, "Altitude=%c%ld.%01ld\r\n", u8_1, i32_1, i32_2); |
438 | fputs_(wpline, fp); |
438 | fputs_(wpline, fp); |
439 | // write climb rate in 0.1 m/s |
439 | // write climb rate in 0.1 m/s |
440 | sprintf(wpline, "ClimbRate=%d\r\n", PointList[i].AltitudeRate); |
440 | sprintf(wpline, "ClimbRate=%d\r\n", PointList[i].AltitudeRate); |
441 | fputs_(wpline, fp); |
441 | fputs_(wpline, fp); |
442 | // write hold time in s |
442 | // write hold time in s |
443 | sprintf(wpline, "DelayTime=%d\r\n", PointList[i].HoldTime); |
443 | sprintf(wpline, "DelayTime=%d\r\n", PointList[i].HoldTime); |
444 | fputs_(wpline, fp); |
444 | fputs_(wpline, fp); |
445 | // write event channel value |
445 | // write event channel value |
446 | sprintf(wpline, "WP_Event_Channel_Value=%d\r\n", PointList[i].WP_EventChannelValue); |
446 | sprintf(wpline, "WP_Event_Channel_Value=%d\r\n", PointList[i].WP_EventChannelValue); |
447 | fputs_(wpline, fp); |
447 | fputs_(wpline, fp); |
448 | // write heading in deg (0= nothing, neg. values index to poi) |
448 | // write heading in deg (0= nothing, neg. values index to poi) |
449 | sprintf(wpline, "Heading=%d\r\n", PointList[i].Heading); |
449 | sprintf(wpline, "Heading=%d\r\n", PointList[i].Heading); |
450 | fputs_(wpline, fp); |
450 | fputs_(wpline, fp); |
451 | // write speed in 0.1 m/s |
451 | // write speed in 0.1 m/s |
452 | sprintf(wpline, "Speed=%d\r\n", PointList[i].Speed); |
452 | sprintf(wpline, "Speed=%d\r\n", PointList[i].Speed); |
453 | fputs_(wpline, fp); |
453 | fputs_(wpline, fp); |
454 | // write cam angle in degree (255 -> POI-Automatic) |
454 | // write cam angle in degree (255 -> POI-Automatic) |
455 | sprintf(wpline, "CAM-Nick=%d\r\n", PointList[i].CamAngle); |
455 | sprintf(wpline, "CAM-Nick=%d\r\n", PointList[i].CamAngle); |
456 | fputs_(wpline, fp); |
456 | fputs_(wpline, fp); |
457 | // write point type |
457 | // write point type |
458 | sprintf(wpline, "Type=%d\r\n", PointList[i].Type + 1); |
458 | sprintf(wpline, "Type=%d\r\n", PointList[i].Type + 1); |
459 | fputs_(wpline, fp); |
459 | fputs_(wpline, fp); |
460 | // write prefix |
460 | // write prefix |
461 | sprintf(wpline, "Prefix=%s\r\n", PointList[i].Name); |
461 | sprintf(wpline, "Prefix=%s\r\n", PointList[i].Name); |
462 | fputs_(wpline, fp); |
462 | fputs_(wpline, fp); |
463 | } // EOF loop over all points |
463 | } // EOF loop over all points |
464 | } // EOF if(PointCount) |
464 | } // EOF if(PointCount) |
465 | if(EOF == fclose_(fp)) |
465 | if(EOF == fclose_(fp)) |
466 | { |
466 | { |
467 | UART1_PutString("failed!\r\n"); |
467 | UART1_PutString("failed!\r\n"); |
468 | } |
468 | } |
469 | else |
469 | else |
470 | { |
470 | { |
471 | UART1_PutString("ok\r\n"); |
471 | UART1_PutString("ok\r\n"); |
472 | retval = WPL_OK; |
472 | retval = WPL_OK; |
473 | } |
473 | } |
474 | } // EOF if(Fat16_IsValid()) |
474 | } // EOF if(Fat16_IsValid()) |
475 | else |
475 | else |
476 | { |
476 | { |
477 | UART1_PutString("no file system found!\r\n"); |
477 | UART1_PutString("no file system found!\r\n"); |
478 | retval = WPL_NO_SDCARD_FOUND; |
478 | retval = WPL_NO_SDCARD_FOUND; |
479 | } |
479 | } |
480 | return(retval); |
480 | return(retval); |
481 | } |
481 | } |
482 | 482 | ||
483 | u8 PointList_Load(u8 * filename, u8* listname, u8 listnamelen, u8 use_preset_speed) |
483 | u8 PointList_Load(u8 * filename, u8* listname, u8 listnamelen, u8 use_preset_speed) |
484 | { |
484 | { |
485 | File_t *fp; |
485 | File_t *fp; |
486 | s8 wpline[LINE_MAX]; |
486 | s8 wpline[LINE_MAX]; |
487 | u8 retval = WPL_ERROR; |
487 | u8 retval = WPL_ERROR; |
488 | 488 | ||
489 | s8 *name, *value; |
489 | s8 *name, *value; |
490 | u8 i; |
490 | u8 i; |
491 | 491 | ||
492 | u8 IsGeneralSection = 0; |
492 | u8 IsGeneralSection = 0; |
493 | u8 IsPointSection = 0; |
493 | u8 IsPointSection = 0; |
494 | u8 WPNumber = 0; |
494 | u8 WPNumber = 0; |
495 | 495 | ||
496 | // clear point list first |
496 | // clear point list first |
497 | PointList_Clear(); |
497 | PointList_Clear(); |
498 | HeadingOld = -1; // updates the direction if the new direction is the same like last time |
498 | HeadingOld = -1; // updates the direction if the new direction is the same like last time |
499 | UART1_PutString("\n\r Read "); |
499 | UART1_PutString("\n\r Read "); |
500 | UART1_PutString(filename); |
500 | UART1_PutString(filename); |
501 | UART1_PutString("..."); |
501 | UART1_PutString("..."); |
502 | 502 | ||
503 | if(Fat16_IsValid()) |
503 | if(Fat16_IsValid()) |
504 | { // check if wpl file is existing |
504 | { // check if wpl file is existing |
505 | fp = fopen_(filename, 'r'); // try to open the file |
505 | fp = fopen_(filename, 'r'); // try to open the file |
506 | if(fp == NULL) |
506 | if(fp == NULL) |
507 | { |
507 | { |
508 | UART1_PutString("ERROR: Reading waypoint file!\r\n"); |
508 | UART1_PutString("ERROR: Reading waypoint file!\r\n"); |
509 | return(retval); |
509 | return(retval); |
510 | } |
510 | } |
511 | // read all lines from file |
511 | // read all lines from file |
512 | while(fgets_(wpline, LINE_MAX, fp) != 0) |
512 | while(fgets_(wpline, LINE_MAX, fp) != 0) |
513 | { |
513 | { |
514 | if ( // ignorelines starting with \r,\n,' ',';','#' |
514 | if ( // ignorelines starting with \r,\n,' ',';','#' |
515 | (wpline[0] != '\n') && |
515 | (wpline[0] != '\n') && |
516 | (wpline[0] != '\r') && |
516 | (wpline[0] != '\r') && |
517 | (wpline[0] != ' ' ) && |
517 | (wpline[0] != ' ' ) && |
518 | (wpline[0] != ';' ) && |
518 | (wpline[0] != ';' ) && |
519 | (wpline[0] != '#' ) |
519 | (wpline[0] != '#' ) |
520 | ) |
520 | ) |
521 | { |
521 | { |
522 | // check for section line found |
522 | // check for section line found |
523 | if(wpline[0] == '[') |
523 | if(wpline[0] == '[') |
524 | { |
524 | { |
525 | // next section found |
525 | // next section found |
526 | IsGeneralSection = 0; |
526 | IsGeneralSection = 0; |
527 | IsPointSection = 0; |
527 | IsPointSection = 0; |
528 | 528 | ||
529 | name = strtok(&wpline[1], "]"); |
529 | name = strtok(&wpline[1], "]"); |
530 | if(name != NULL) // if section name |
530 | if(name != NULL) // if section name |
531 | { |
531 | { |
532 | // check section type |
532 | // check section type |
533 | for(i=0; name[i]; i++) name[i] = toupper(name[i]); // convert to upper case |
533 | for(i=0; name[i]; i++) name[i] = toupper(name[i]); // convert to upper case |
534 | 534 | ||
535 | if(strncmp(name, "POINT", 5) == 0) |
535 | if(strncmp(name, "POINT", 5) == 0) |
536 | { |
536 | { |
537 | IsPointSection = (u8)atoi(&name[5]); |
537 | IsPointSection = (u8)atoi(&name[5]); |
538 | PointCount++; |
538 | PointCount++; |
539 | } |
539 | } |
540 | else if(strcmp(name, "GENERAL") == 0) |
540 | else if(strcmp(name, "GENERAL") == 0) |
541 | { |
541 | { |
542 | IsGeneralSection = 1; |
542 | IsGeneralSection = 1; |
543 | } |
543 | } |
544 | else |
544 | else |
545 | { |
545 | { |
546 | UART1_PutString("Unknown section: "); |
546 | UART1_PutString("Unknown section: "); |
547 | UART1_PutString(name); |
547 | UART1_PutString(name); |
548 | UART1_PutString("\r\n"); |
548 | UART1_PutString("\r\n"); |
549 | } |
549 | } |
550 | } |
550 | } |
551 | } // EOF section line |
551 | } // EOF section line |
552 | else |
552 | else |
553 | { // look for key entrys of each sections |
553 | { // look for key entrys of each sections |
554 | name = strtok(wpline, "="); // get name |
554 | name = strtok(wpline, "="); // get name |
555 | value = strtok(NULL, "="); // get value |
555 | value = strtok(NULL, "="); // get value |
556 | if ((name != NULL) && (value != NULL)) |
556 | if ((name != NULL) && (value != NULL)) |
557 | { |
557 | { |
558 | for(i=0; name[i]; i++) name[i] = toupper(name[i]); // convert to upper case |
558 | for(i=0; name[i]; i++) name[i] = toupper(name[i]); // convert to upper case |
559 | if(IsPointSection && (IsPointSection <= WPNumber)) |
559 | if(IsPointSection && (IsPointSection <= WPNumber)) |
560 | { |
560 | { |
561 | if(strcmp(name, "LATITUDE") == 0) |
561 | if(strcmp(name, "LATITUDE") == 0) |
562 | { |
562 | { |
563 | PointList[IsPointSection-1].Position.Latitude = (s32)(atof(value) * 1E7); |
563 | PointList[IsPointSection-1].Position.Latitude = (s32)(atof(value) * 1E7); |
564 | } |
564 | } |
565 | else if(strcmp(name, "LONGITUDE") == 0) |
565 | else if(strcmp(name, "LONGITUDE") == 0) |
566 | { |
566 | { |
567 | PointList[IsPointSection-1].Position.Longitude = (s32)(atof(value) * 1E7); |
567 | PointList[IsPointSection-1].Position.Longitude = (s32)(atof(value) * 1E7); |
568 | } |
568 | } |
569 | else if(strcmp(name, "RADIUS") == 0) |
569 | else if(strcmp(name, "RADIUS") == 0) |
570 | { |
570 | { |
571 | PointList[IsPointSection-1].ToleranceRadius = (u8)atoi(value); |
571 | PointList[IsPointSection-1].ToleranceRadius = (u8)atoi(value); |
572 | } |
572 | } |
573 | else if(strcmp(name, "ALTITUDE") == 0) |
573 | else if(strcmp(name, "ALTITUDE") == 0) |
574 | { |
574 | { |
575 | PointList[IsPointSection-1].Position.Altitude = (s32)(atof(value) * 100.0); // in cm |
575 | PointList[IsPointSection-1].Position.Altitude = (s32)(atof(value) * 100.0); // in cm |
576 | PointList[IsPointSection-1].Position.Status = NEWDATA; |
576 | PointList[IsPointSection-1].Position.Status = NEWDATA; |
577 | } |
577 | } |
578 | else if(strcmp(name, "CLIMBRATE") == 0) |
578 | else if(strcmp(name, "CLIMBRATE") == 0) |
579 | { |
579 | { |
580 | PointList[IsPointSection-1].AltitudeRate = (u8)atoi(value); |
580 | PointList[IsPointSection-1].AltitudeRate = (u8)atoi(value); |
581 | } |
581 | } |
582 | else if(strcmp(name, "DELAYTIME") == 0) |
582 | else if(strcmp(name, "DELAYTIME") == 0) |
583 | { |
583 | { |
584 | PointList[IsPointSection-1].HoldTime = (u8)atoi(value); |
584 | PointList[IsPointSection-1].HoldTime = (u8)atoi(value); |
585 | } |
585 | } |
586 | else if(strcmp(name, "WP_EVENT_CHANNEL_VALUE") == 0) |
586 | else if(strcmp(name, "WP_EVENT_CHANNEL_VALUE") == 0) |
587 | { |
587 | { |
588 | PointList[IsPointSection-1].WP_EventChannelValue = (u8)atoi(value); |
588 | PointList[IsPointSection-1].WP_EventChannelValue = (u8)atoi(value); |
589 | } |
589 | } |
590 | else if(strcmp(name, "HEADING") == 0) |
590 | else if(strcmp(name, "HEADING") == 0) |
591 | { |
591 | { |
592 | PointList[IsPointSection-1].Heading = (s16)atoi(value); |
592 | PointList[IsPointSection-1].Heading = (s16)atoi(value); |
593 | } |
593 | } |
594 | else if(strcmp(name, "SPEED") == 0) |
594 | else if(strcmp(name, "SPEED") == 0) |
595 | { |
595 | { |
596 | if(use_preset_speed) PointList[IsPointSection-1].Speed = use_preset_speed; |
596 | if(use_preset_speed) PointList[IsPointSection-1].Speed = use_preset_speed; |
597 | else PointList[IsPointSection-1].Speed = (u8)atoi(value); |
597 | else PointList[IsPointSection-1].Speed = (u8)atoi(value); |
598 | } |
598 | } |
599 | else if(strcmp(name, "CAM-NICK") == 0) |
599 | else if(strcmp(name, "CAM-NICK") == 0) |
600 | { |
600 | { |
601 | PointList[IsPointSection-1].CamAngle = (u8)atoi(value); |
601 | PointList[IsPointSection-1].CamAngle = (u8)atoi(value); |
602 | } |
602 | } |
603 | else if(strcmp(name, "TYPE") == 0) |
603 | else if(strcmp(name, "TYPE") == 0) |
604 | { |
604 | { |
605 | PointList[IsPointSection-1].Type = (u8)atoi(value); |
605 | PointList[IsPointSection-1].Type = (u8)atoi(value); |
606 | if(PointList[IsPointSection-1].Type > 0) PointList[IsPointSection-1].Type--; // index shift |
606 | if(PointList[IsPointSection-1].Type > 0) PointList[IsPointSection-1].Type--; // index shift |
607 | else PointList[IsPointSection-1].Type = POINT_TYPE_INVALID; |
607 | else PointList[IsPointSection-1].Type = POINT_TYPE_INVALID; |
608 | 608 | ||
609 | switch(PointList[IsPointSection-1].Type) |
609 | switch(PointList[IsPointSection-1].Type) |
610 | { |
610 | { |
611 | case POINT_TYPE_WP: |
611 | case POINT_TYPE_WP: |
612 | // this works only if altitude key is set before point type key in WPL file !! |
612 | // this works only if altitude key is set before point type key in WPL file !! |
613 | PointList[IsPointSection-1].Position.Altitude /= 10; // dm only for WPs |
613 | PointList[IsPointSection-1].Position.Altitude /= 10; // dm only for WPs |
614 | WPCount++; |
614 | WPCount++; |
615 | break; |
615 | break; |
616 | 616 | ||
617 | case POINT_TYPE_POI: |
617 | case POINT_TYPE_POI: |
618 | POICount++; |
618 | POICount++; |
619 | break; |
619 | break; |
620 | } |
620 | } |
621 | } |
621 | } |
622 | else if(strcmp(name, "PREFIX") == 0) |
622 | else if(strcmp(name, "PREFIX") == 0) |
623 | { |
623 | { |
624 | strncpy(PointList[IsPointSection-1].Name, value, 4); |
624 | strncpy(PointList[IsPointSection-1].Name, value, 4); |
625 | PointList[IsPointSection-1].Name[3] = 0; // Terminate string |
625 | PointList[IsPointSection-1].Name[3] = 0; // Terminate string |
626 | } |
626 | } |
627 | else |
627 | else |
628 | { |
628 | { |
629 | UART1_PutString("Unknown key: "); |
629 | UART1_PutString("Unknown key: "); |
630 | UART1_PutString(name); |
630 | UART1_PutString(name); |
631 | UART1_PutString("\r\n"); |
631 | UART1_PutString("\r\n"); |
632 | } |
632 | } |
633 | } // EOF point section |
633 | } // EOF point section |
634 | else if(IsGeneralSection) |
634 | else if(IsGeneralSection) |
635 | { |
635 | { |
636 | if(strcmp(name, "NUMBEROFWAYPOINTS") == 0) |
636 | if(strcmp(name, "NUMBEROFWAYPOINTS") == 0) |
637 | { |
637 | { |
638 | WPNumber = (u8)atoi(value); |
638 | WPNumber = (u8)atoi(value); |
639 | if(!WPNumber) // no waypoints in file |
639 | if(!WPNumber) // no waypoints in file |
640 | { |
640 | { |
641 | return(WPL_NO_WAYPOINTS); // we are done here |
641 | return(WPL_NO_WAYPOINTS); // we are done here |
642 | } |
642 | } |
643 | else if(WPNumber > MAX_LIST_LEN) // number o points larger than ram list |
643 | else if(WPNumber > MAX_LIST_LEN) // number o points larger than ram list |
644 | { |
644 | { |
645 | UART1_PutString("To many points!"); |
645 | UART1_PutString("To many points!"); |
646 | return(WPL_ERROR); |
646 | return(WPL_ERROR); |
647 | } |
647 | } |
648 | } |
648 | } |
649 | else if (strcmp(name, "FILEVERSION") == 0) |
649 | else if (strcmp(name, "FILEVERSION") == 0) |
650 | { |
650 | { |
651 | if((u8)atoi(value) != WP_FILE_VERSION_COMPATIBLE) |
651 | if((u8)atoi(value) != WP_FILE_VERSION_COMPATIBLE) |
652 | { |
652 | { |
653 | PointList_Clear(); |
653 | PointList_Clear(); |
654 | UART1_PutString("Bad file version!\r\n"); |
654 | UART1_PutString("Bad file version!\r\n"); |
655 | return(WPL_ERROR); |
655 | return(WPL_ERROR); |
656 | } |
656 | } |
657 | } |
657 | } |
658 | else if (strcmp(name, "NAME") == 0) |
658 | else if (strcmp(name, "NAME") == 0) |
659 | { |
659 | { |
660 | if(listname) |
660 | if(listname) |
661 | { |
661 | { |
662 | u8 len = strlen(value); |
662 | u8 len = strlen(value); |
663 | if(len) |
663 | if(len) |
664 | { |
664 | { |
665 | if(value[len-1] == '\r') |
665 | if(value[len-1] == '\r') |
666 | { |
666 | { |
667 | value[len-1] = 0; |
667 | value[len-1] = 0; |
668 | len--; |
668 | len--; |
669 | } |
669 | } |
670 | } |
670 | } |
671 | if(len > listnamelen) len = listnamelen; |
671 | if(len > listnamelen) len = listnamelen; |
672 | if(len) |
672 | if(len) |
673 | { |
673 | { |
674 | value[len-1] = 0; // terminate string |
674 | value[len-1] = 0; // terminate string |
675 | if(listname) memcpy(listname, value, len); |
675 | if(listname) memcpy(listname, value, len); |
676 | } |
676 | } |
677 | NewWPL_Name = 1; |
677 | NewWPL_Name = 1; |
678 | } |
678 | } |
679 | } |
679 | } |
680 | else |
680 | else |
681 | { |
681 | { |
682 | UART1_PutString("Unknown key: "); |
682 | UART1_PutString("Unknown key: "); |
683 | UART1_PutString(name); |
683 | UART1_PutString(name); |
684 | UART1_PutString("\r\n"); |
684 | UART1_PutString("\r\n"); |
685 | } |
685 | } |
686 | } // EOF general section |
686 | } // EOF general section |
687 | } // EOF valid key entry |
687 | } // EOF valid key entry |
688 | } // EOF key entry line |
688 | } // EOF key entry line |
689 | } // valid line |
689 | } // valid line |
690 | } // EOF loop over all lines |
690 | } // EOF loop over all lines |
691 | fclose_(fp); |
691 | fclose_(fp); |
692 | NaviData.WaypointNumber = WPCount; |
692 | NaviData.WaypointNumber = WPCount; |
693 | retval = WPL_OK; |
693 | retval = WPL_OK; |
694 | UART1_PutString("ok\r\n"); |
694 | UART1_PutString("ok\r\n"); |
695 | } // EOF if(Fat16_IsValid()) |
695 | } // EOF if(Fat16_IsValid()) |
696 | else |
696 | else |
697 | { |
697 | { |
698 | UART1_PutString("no file system found!\r\n"); |
698 | UART1_PutString("no file system found!\r\n"); |
699 | retval = WPL_NO_SDCARD_FOUND; |
699 | retval = WPL_NO_SDCARD_FOUND; |
700 | } |
700 | } |
701 | return(retval); |
701 | return(retval); |
702 | } |
702 | } |
703 | 703 | ||
704 | // load actual point list from SD card |
704 | // load actual point list from SD card |
705 | u8 PointList_ReadFromFile(WPL_Store_t * pWPL_Store) |
705 | u8 PointList_ReadFromFile(WPL_Store_t * pWPL_Store) |
706 | { |
706 | { |
707 | u8 filename[30]; |
707 | u8 filename[30]; |
708 | 708 | ||
709 | pWPL_Store->Name[0] = 0; // clear current list name |
709 | pWPL_Store->Name[0] = 0; // clear current list name |
710 | 710 | ||
711 | // user absolute path, i.e. leading / |
711 | // user absolute path, i.e. leading / |
712 | if(pWPL_Store->Index == 0) // index 0 looks for a default WPL file in the root |
712 | if(pWPL_Store->Index == 0) // index 0 looks for a default WPL file in the root |
713 | { |
713 | { |
714 | sprintf(filename, "/default.wpl"); |
714 | sprintf(filename, "/default.wpl"); |
715 | } |
715 | } |
716 | else |
716 | else |
717 | { |
717 | { |
718 | sprintf(filename, "/WPL/list_%03d.wpl", pWPL_Store->Index); |
718 | sprintf(filename, "/WPL/list_%03d.wpl", pWPL_Store->Index); |
719 | } |
719 | } |
720 | return PointList_Load(filename, pWPL_Store->Name, sizeof(pWPL_Store->Name),0); |
720 | return PointList_Load(filename, pWPL_Store->Name, sizeof(pWPL_Store->Name),0); |
721 | } |
721 | } |
722 | 722 | ||
723 | // save actual point list to SD card |
723 | // save actual point list to SD card |
724 | u8 PointList_WriteToFile(WPL_Store_t * pWPL_Store) |
724 | u8 PointList_WriteToFile(WPL_Store_t * pWPL_Store) |
725 | { |
725 | { |
726 | u8 filename[30]; |
726 | u8 filename[30]; |
727 | 727 | ||
728 | 728 | ||
729 | if(PointCount == 0) return(WPL_NO_WAYPOINTS); |
729 | if(PointCount == 0) return(WPL_NO_WAYPOINTS); |
730 | // user absolute path, i.e. leading / |
730 | // user absolute path, i.e. leading / |
731 | if(pWPL_Store->Index == 0) |
731 | if(pWPL_Store->Index == 0) |
732 | { |
732 | { |
733 | sprintf(filename, "/default.wpl"); |
733 | sprintf(filename, "/default.wpl"); |
734 | } |
734 | } |
735 | else |
735 | else |
736 | { |
736 | { |
737 | sprintf(filename, "/WPL/list_%03d.wpl", pWPL_Store->Index); |
737 | sprintf(filename, "/WPL/list_%03d.wpl", pWPL_Store->Index); |
738 | } |
738 | } |
739 | return PointList_Save(filename, pWPL_Store->Name, pWPL_Store->OverwriteFile); |
739 | return PointList_Save(filename, pWPL_Store->Name, pWPL_Store->OverwriteFile); |
740 | } |
740 | } |
741 | 741 | ||
742 | 742 | ||
743 | // save actual gps positiin and heading to file |
743 | // save actual gps positiin and heading to file |
744 | u8 PointList_SaveSinglePoint(WPL_Store_t * pWPL_Store) |
744 | u8 PointList_SaveSinglePoint(WPL_Store_t * pWPL_Store) |
745 | { |
745 | { |
746 | u8 retval = WPL_ERROR; |
746 | u8 retval = WPL_ERROR; |
747 | u8 filename[30]; |
747 | u8 filename[30]; |
748 | Point_t WP; |
748 | Point_t WP; |
749 | 749 | ||
750 | UART1_PutString("\n\r write single point\n\r"); |
750 | UART1_PutString("\n\r write single point\n\r"); |
751 | if(GPSData.Position.Status == INVALID) |
751 | if(GPSData.Position.Status == INVALID) |
752 | { |
752 | { |
753 | UART1_PutString("ERROR: No GPS - Fix\n\r"); |
753 | UART1_PutString("ERROR: No GPS - Fix\n\r"); |
754 | return(retval); |
754 | return(retval); |
755 | } |
755 | } |
756 | 756 | ||
757 | // clear current point list |
757 | // clear current point list |
758 | PointList_Clear(); |
758 | PointList_Clear(); |
759 | // prepare WP at current position |
759 | // prepare WP at current position |
760 | 760 | ||
761 | if(NCFlags & NC_FLAG_FREE || NaviData.TargetPositionDeviation.Distance > 7*10) |
761 | if(NCFlags & NC_FLAG_FREE || NaviData.TargetPositionDeviation.Distance > 7*10) |
762 | { // take actual position |
762 | { // take actual position |
763 | GPSPos_Copy(&GPSData.Position, &(WP.Position)); |
763 | GPSPos_Copy(&GPSData.Position, &(WP.Position)); |
764 | } |
764 | } |
765 | else |
765 | else |
766 | { // take last target position |
766 | { // take last target position |
767 | GPSPos_Copy(&NaviData.TargetPosition, &(WP.Position)); |
767 | GPSPos_Copy(&NaviData.TargetPosition, &(WP.Position)); |
768 | } |
768 | } |
769 | 769 | ||
770 | GPSPos_Copy(&GPSData.Position, &(WP.Position)); |
770 | GPSPos_Copy(&GPSData.Position, &(WP.Position)); |
771 | // set heading |
771 | // set heading |
772 | WP.Heading = CompassSetpointCorrected/10; |
772 | WP.Heading = CompassSetpointCorrected/10; |
773 | if(WP.Heading == 0) WP.Heading = 360; |
773 | if(WP.Heading == 0) WP.Heading = 360; |
774 | WP.ToleranceRadius = 120; // 12m |
774 | WP.ToleranceRadius = 120; // 12m |
775 | WP.HoldTime = 2; |
775 | WP.HoldTime = 2; |
776 | WP.Index = 1; |
776 | WP.Index = 1; |
777 | WP.Type = POINT_TYPE_WP; |
777 | WP.Type = POINT_TYPE_WP; |
778 | WP.WP_EventChannelValue = 0; |
778 | WP.WP_EventChannelValue = 0; |
779 | if(FC.StatusFlags & FC_STATUS_FLY && (FromFC_VarioCharacter != ' ')) // only in flight and if the Altitude control is enabled |
779 | if(FC.StatusFlags & FC_STATUS_FLY && (FromFC_VarioCharacter != ' ')) // only in flight and if the Altitude control is enabled |
780 | { |
780 | { |
781 | WP.AltitudeRate = 255; // Auto |
781 | WP.AltitudeRate = 255; // Auto |
782 | // WP.Position.Altitude = NaviData.Altimeter / 2; |
782 | // WP.Position.Altitude = NaviData.Altimeter / 2; |
783 | WP.Position.Altitude = NaviData.SetpointAltitude / 2; |
783 | WP.Position.Altitude = NaviData.SetpointAltitude / 2; |
784 | } |
784 | } |
785 | else |
785 | else |
786 | { |
786 | { |
787 | WP.AltitudeRate = 0; |
787 | WP.AltitudeRate = 0; |
788 | WP.Position.Altitude = 0; |
788 | WP.Position.Altitude = 0; |
789 | } |
789 | } |
790 | WP.Speed = 50; // beim Laden wird der Wert nochmal neu gesetzt |
790 | WP.Speed = 50; // beim Laden wird der Wert nochmal neu gesetzt |
791 | WP.CamAngle = 0; |
791 | WP.CamAngle = 0; |
- | 792 | WP.Name[0] = 'S'; |
|
792 | WP.Name[0] = 'P'; |
793 | WP.Name[1] = 'P'; |
- | 794 | WP.Name[2] = 'T'; |
|
793 | WP.Name[1] = 0; |
795 | WP.Name[3] = 0; |
794 | // add this point to wp list |
796 | // add this point to wp list |
795 | PointList_SetAt(&WP); |
797 | PointList_SetAt(&WP); |
796 | 798 | ||
797 | sprintf(filename, "/POINT/POINT%03d.wpl", pWPL_Store->Index); |
799 | sprintf(filename, "/POINT/POINT%03d.wpl", pWPL_Store->Index); |
798 | UART1_PutString(filename); |
800 | UART1_PutString(filename); |
799 | sprintf(pWPL_Store->Name, "POINT%03d ", pWPL_Store->Index); |
801 | sprintf(pWPL_Store->Name, "POINT%03d ", pWPL_Store->Index); |
800 | retval = PointList_Save(filename, pWPL_Store->Name, 1); |
802 | retval = PointList_Save(filename, pWPL_Store->Name, 1); |
801 | 803 | ||
802 | // clear current point list |
804 | // clear current point list |
803 | if((NC_GPS_ModeCharacter != 'w') && (NC_GPS_ModeCharacter != 'W')) PointList_Clear(); |
805 | if((NC_GPS_ModeCharacter != 'w') && (NC_GPS_ModeCharacter != 'W')) PointList_Clear(); |
804 | else |
806 | else |
805 | { |
807 | { |
806 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
808 | if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE); |
807 | GPS_pWaypoint = PointList_WPBegin(); // updates POI index |
809 | GPS_pWaypoint = PointList_WPBegin(); // updates POI index |
808 | } |
810 | } |
809 | 811 | ||
810 | return(retval); |
812 | return(retval); |
811 | } |
813 | } |
812 | // load target gps posititon and heading from file |
814 | // load target gps posititon and heading from file |
813 | u8 PointList_LoadSinglePoint(WPL_Store_t * pWPL_Store) |
815 | u8 PointList_LoadSinglePoint(WPL_Store_t * pWPL_Store) |
814 | { |
816 | { |
815 | u8 filename[30], result = 0; |
817 | u8 filename[30], result = 0; |
816 | 818 | ||
817 | sprintf(filename, "/POINT/POINT%03d.wpl", pWPL_Store->Index); |
819 | sprintf(filename, "/POINT/POINT%03d.wpl", pWPL_Store->Index); |
818 | pWPL_Store->Name[0] = 0; // clear current list name |
820 | pWPL_Store->Name[0] = 0; // clear current list name |
819 | result = PointList_Load(filename, pWPL_Store->Name, sizeof(pWPL_Store->Name),Parameter.SingleWpSpeed); |
821 | result = PointList_Load(filename, pWPL_Store->Name, sizeof(pWPL_Store->Name),Parameter.SingleWpSpeed); |
820 | if(result) UART1_Request_ReadPoint = 1; // Sends Point 1 to the PC |
822 | if(result) UART1_Request_ReadPoint = 1; // Sends Point 1 to the PC |
821 | return(result); |
823 | return(result); |
822 | } |
824 | } |
823 | 825 | ||
824 | 826 | ||
825 | 827 | ||
826 | void ClearWLP_Name(void) |
828 | void ClearWLP_Name(void) |
827 | { |
829 | { |
828 | u8 i; |
830 | u8 i; |
829 | for(i=0; i<sizeof(WPL_Store.Name);i++) WPL_Store.Name[i] = 0; |
831 | for(i=0; i<sizeof(WPL_Store.Name);i++) WPL_Store.Name[i] = 0; |
830 | NewWPL_Name = 1; |
832 | NewWPL_Name = 1; |
831 | } |
833 | } |
832 | 834 | ||
833 | // move actual point list to ref pos., the point in the list marked by index gets the RefPos afterwards |
835 | // move actual point list to ref pos., the point in the list marked by index gets the RefPos afterwards |
834 | u8 PointList_Move(u8 RefIndex, GPS_Pos_t* pRefPos, u16 RotationAngle) |
836 | u8 PointList_Move(u8 RefIndex, GPS_Pos_t* pRefPos, u16 RotationAngle) |
835 | { |
837 | { |
836 | u8 retval = 0; |
838 | u8 retval = 0; |
837 | s32 altitude; |
839 | s32 altitude; |
838 | GPS_Pos_t OldRefPos; |
840 | GPS_Pos_t OldRefPos; |
839 | GPS_Pos_Deviation_t RefDeviation; |
841 | GPS_Pos_Deviation_t RefDeviation; |
840 | 842 | ||
841 | // check inputs for plausibility; |
843 | // check inputs for plausibility; |
842 | if((RefIndex == 0) || (RefIndex > PointCount)) return(retval); |
844 | if((RefIndex == 0) || (RefIndex > PointCount)) return(retval); |
843 | if(pRefPos == NULL) return(retval); |
845 | if(pRefPos == NULL) return(retval); |
844 | if(pRefPos->Status == INVALID) return(retval); |
846 | if(pRefPos->Status == INVALID) return(retval); |
845 | 847 | ||
846 | if(GPSPos_Copy(&(PointList[RefIndex-1].Position), &OldRefPos)) // backup old reference position |
848 | if(GPSPos_Copy(&(PointList[RefIndex-1].Position), &OldRefPos)) // backup old reference position |
847 | { |
849 | { |
848 | u8 i; |
850 | u8 i; |
849 | // iterate the position list |
851 | // iterate the position list |
850 | for(i = 0; i < PointCount; i++) |
852 | for(i = 0; i < PointCount; i++) |
851 | { |
853 | { |
852 | retval = 0; |
854 | retval = 0; |
853 | // backup altitude of this point |
855 | // backup altitude of this point |
854 | altitude = PointList[i].Position.Altitude; |
856 | altitude = PointList[i].Position.Altitude; |
855 | // calculate deviation form old ref, i.e the north and east shift of each point in the list from the reference position |
857 | // calculate deviation form old ref, i.e the north and east shift of each point in the list from the reference position |
856 | if(!GPSPos_Deviation(&(PointList[i].Position), &OldRefPos, &RefDeviation)) break; |
858 | if(!GPSPos_Deviation(&(PointList[i].Position), &OldRefPos, &RefDeviation)) break; |
857 | // copy of the new reference position into this list place |
859 | // copy of the new reference position into this list place |
858 | if(!GPSPos_Copy(pRefPos, &(PointList[i].Position))) break; |
860 | if(!GPSPos_Copy(pRefPos, &(PointList[i].Position))) break; |
859 | // restore former altitude |
861 | // restore former altitude |
860 | PointList[i].Position.Altitude = altitude; |
862 | PointList[i].Position.Altitude = altitude; |
861 | // move new reference according to the deviation of the old reference |
863 | // move new reference according to the deviation of the old reference |
862 | if(RotationAngle > 0) |
864 | if(RotationAngle > 0) |
863 | { |
865 | { |
864 | retval = GPSPos_ShiftGeodetic(&(PointList[i].Position), (RefDeviation.Bearing + 180 + RotationAngle)%360, RefDeviation.Distance ); |
866 | retval = GPSPos_ShiftGeodetic(&(PointList[i].Position), (RefDeviation.Bearing + 180 + RotationAngle)%360, RefDeviation.Distance ); |
865 | // Now rotate the heading positions if they are fixed angles |
867 | // Now rotate the heading positions if they are fixed angles |
866 | if(PointList[i].Heading >= 0 && PointList[i].Heading <= 360) PointList[i].Heading = (PointList[i].Heading + RotationAngle) % 360; |
868 | if(PointList[i].Heading >= 0 && PointList[i].Heading <= 360) PointList[i].Heading = (PointList[i].Heading + RotationAngle) % 360; |
867 | } |
869 | } |
868 | else // no rotation |
870 | else // no rotation |
869 | { |
871 | { |
870 | // move new reference according to the deviation of the old reference |
872 | // move new reference according to the deviation of the old reference |
871 | retval = GPSPos_ShiftCartesian(&(PointList[i].Position), RefDeviation.North, RefDeviation.East); |
873 | retval = GPSPos_ShiftCartesian(&(PointList[i].Position), RefDeviation.North, RefDeviation.East); |
872 | } |
874 | } |
873 | if(!retval) break; |
875 | if(!retval) break; |
874 | } |
876 | } |
875 | } // else ref pos old not copied! |
877 | } // else ref pos old not copied! |
876 | if(!retval) PointList_Clear(); |
878 | if(!retval) PointList_Clear(); |
877 | return(retval); |
879 | return(retval); |
878 | } |
880 | } |
879 | 881 | ||
880 | 882 | ||
881 | 883 | ||
882 | 884 |