Subversion Repositories NaviCtrl

Rev

Rev 351 | Rev 490 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 351 Rev 360
1
/*#######################################################################################*/
1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 2008 Ingo Busker, Holger Buss
-
 
6
// + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY
-
 
7
// + FOR NON COMMERCIAL USE ONLY
-
 
8
// + www.MikroKopter.com
5
// + www.MikroKopter.com
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
7
// + Software Nutzungsbedingungen (english version: see below)
10
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
11
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist.
9
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
12
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
10
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
13
// + bzgl. der Nutzungsbedingungen aufzunehmen.
11
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
14
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
15
// + Verkauf von Luftbildaufnahmen, usw.
-
 
16
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
18
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
15
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
20
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
17
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
21
// + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
18
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
22
// + eindeutig als Ursprung verlinkt werden
19
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
24
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
21
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
25
// + Benutzung auf eigene Gefahr
22
// + des Mitverschuldens offen.
-
 
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.
26
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
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
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
28
// + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
28
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
29
// + mit unserer Zustimmung zulässig
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
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
32
// + Software LICENSING TERMS
32
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
34
// + this list of conditions and the following disclaimer.
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
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
36
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
36
// +     from this software without specific prior written permission.
37
// + The Software may only be used with the Licensor's products.
37
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permitted
38
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
38
// +     for non-commercial use (directly or indirectly)
-
 
39
// +     Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
39
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
40
// +     with our written permission
40
// + agreement shall be the property of the Licensor.
41
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
41
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
42
// +     clearly linked as origin
-
 
43
// +   * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
42
// + features that can be used to identify the program may not be altered or defaced by the customer.
44
//
-
 
45
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43
// + The customer shall be responsible for taking reasonable precautions
46
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
47
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
48
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
46
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
49
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
47
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
50
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
48
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
51
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
49
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
52
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
50
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
53
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
54
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
52
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
55
// +  POSSIBILITY OF SUCH DAMAGE.
53
// + #### END OF LICENSING TERMS ####
-
 
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
56
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
57
         
56
         
58
#include <string.h>
57
#include <string.h>
59
#include "91x_lib.h"
58
#include "91x_lib.h"
60
#include "waypoints.h"
59
#include "waypoints.h"
61
#include "uart1.h"
60
#include "uart1.h"
62
 
61
 
63
// the waypoints list
62
// the waypoints list
64
#define MAX_LIST_LEN 101
63
#define MAX_LIST_LEN 101
65
 
64
 
66
Point_t PointList[MAX_LIST_LEN];
65
Point_t PointList[MAX_LIST_LEN];
67
u8 WPIndex = 0;         // list index of GPS point representig the current WP, can be maximal WPCount
66
u8 WPIndex = 0;         // list index of GPS point representig the current WP, can be maximal WPCount
68
u8 POIIndex = 0;        // list index of GPS Point representing the current POI, can be maximal WPCount
67
u8 POIIndex = 0;        // list index of GPS Point representing the current POI, can be maximal WPCount
69
u8 WPCount = 0;         // number of waypoints
68
u8 WPCount = 0;         // number of waypoints
70
u8 PointCount = 0;              // number of wp in the list can be maximal equal to MAX_LIST_LEN
69
u8 PointCount = 0;              // number of wp in the list can be maximal equal to MAX_LIST_LEN
71
u8 POICount = 0;
70
u8 POICount = 0;
72
 
71
 
73
u8 WPActive = FALSE;
72
u8 WPActive = FALSE;
74
 
73
 
75
u8 PointList_Init(void)
74
u8 PointList_Init(void)
76
{
75
{
77
        return PointList_Clear();
76
        return PointList_Clear();
78
}
77
}
79
 
78
 
80
u8 PointList_Clear(void)
79
u8 PointList_Clear(void)
81
{
80
{
82
        u8 i;
81
        u8 i;
83
        WPIndex = 0;    // real list position are 1 ,2, 3 ...
82
        WPIndex = 0;    // real list position are 1 ,2, 3 ...
84
        POIIndex = 0;   // real list position are 1 ,2, 3 ...
83
        POIIndex = 0;   // real list position are 1 ,2, 3 ...
85
        WPCount = 0;    // no waypoints
84
        WPCount = 0;    // no waypoints
86
    POICount = 0;
85
    POICount = 0;
87
        PointCount = 0; // no contents
86
        PointCount = 0; // no contents
88
        WPActive = FALSE;
87
        WPActive = FALSE;
89
        NaviData.WaypointNumber = WPCount;
88
        NaviData.WaypointNumber = WPCount;
90
        NaviData.WaypointIndex = 0;
89
        NaviData.WaypointIndex = 0;
91
 
90
 
92
        for(i = 0; i < MAX_LIST_LEN; i++)
91
        for(i = 0; i < MAX_LIST_LEN; i++)
93
        {
92
        {
94
                PointList[i].Position.Status = INVALID;
93
                PointList[i].Position.Status = INVALID;
95
                PointList[i].Position.Latitude = 0;
94
                PointList[i].Position.Latitude = 0;
96
                PointList[i].Position.Longitude = 0;
95
                PointList[i].Position.Longitude = 0;
97
                PointList[i].Position.Altitude = 0;
96
                PointList[i].Position.Altitude = 0;
98
                PointList[i].Heading = 361;             // invalid value
97
                PointList[i].Heading = 361;             // invalid value
99
                PointList[i].ToleranceRadius = 0;       // in meters, if the MK is within that range around the target, then the next target is triggered
98
                PointList[i].ToleranceRadius = 0;       // in meters, if the MK is within that range around the target, then the next target is triggered
100
                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
99
                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
101
                PointList[i].Type = POINT_TYPE_INVALID;
100
                PointList[i].Type = POINT_TYPE_INVALID;
102
                PointList[i].Event_Flag = 0;            // future implementation
101
                PointList[i].Event_Flag = 0;            // future implementation
103
                PointList[i].AltitudeRate = 0;          // no change of setpoint
102
                PointList[i].AltitudeRate = 0;          // no change of setpoint
104
        }
103
        }
105
        return TRUE;           
104
        return TRUE;           
106
}
105
}
107
 
106
 
108
u8 PointList_GetCount(void)
107
u8 PointList_GetCount(void)
109
{
108
{
110
        return PointCount; // number of points in the list
109
        return PointCount; // number of points in the list
111
}
110
}
112
 
111
 
113
Point_t* PointList_GetAt(u8 index)
112
Point_t* PointList_GetAt(u8 index)
114
{
113
{
115
        if((index > 0) && (index <= PointCount)) return(&(PointList[index-1])); // return pointer to this waypoint
114
        if((index > 0) && (index <= PointCount)) return(&(PointList[index-1])); // return pointer to this waypoint
116
        else return(NULL);
115
        else return(NULL);
117
}
116
}
118
 
117
 
119
u8 PointList_SetAt(Point_t* pPoint)
118
u8 PointList_SetAt(Point_t* pPoint)
120
{
119
{
121
        // if index is in range
120
        // if index is in range
122
        if((pPoint->Index > 0) && (pPoint->Index <= MAX_LIST_LEN))
121
        if((pPoint->Index > 0) && (pPoint->Index <= MAX_LIST_LEN))
123
        {
122
        {
124
                // check list entry before update
123
                // check list entry before update
125
                switch(PointList[pPoint->Index-1].Type)
124
                switch(PointList[pPoint->Index-1].Type)
126
                {
125
                {
127
                        case POINT_TYPE_INVALID: // was invalid
126
                        case POINT_TYPE_INVALID: // was invalid
128
                                switch(pPoint->Type)
127
                                switch(pPoint->Type)
129
                                {
128
                                {
130
                                        default:
129
                                        default:
131
                                        case POINT_TYPE_INVALID:
130
                                        case POINT_TYPE_INVALID:
132
                                                // nothing to do
131
                                                // nothing to do
133
                                                break;
132
                                                break;
134
 
133
 
135
                                        case POINT_TYPE_WP:
134
                                        case POINT_TYPE_WP:
136
                                                WPCount++;
135
                                                WPCount++;
137
                                                PointCount++;
136
                                                PointCount++;
138
                                                break;
137
                                                break;
139
                                       
138
                                       
140
                                        case POINT_TYPE_POI:
139
                                        case POINT_TYPE_POI:
141
                                                POICount++;
140
                                                POICount++;
142
                                                PointCount++;
141
                                                PointCount++;
143
                                                break;
142
                                                break;
144
                                }
143
                                }
145
                                break;
144
                                break;
146
                               
145
                               
147
                        case POINT_TYPE_WP: // was  a waypoint
146
                        case POINT_TYPE_WP: // was  a waypoint
148
                                switch(pPoint->Type)
147
                                switch(pPoint->Type)
149
                                {
148
                                {
150
                                        case POINT_TYPE_INVALID:
149
                                        case POINT_TYPE_INVALID:
151
                                                WPCount--;
150
                                                WPCount--;
152
                                                PointCount--;
151
                                                PointCount--;
153
                                                break;
152
                                                break;
154
 
153
 
155
                                        default:
154
                                        default:
156
                                        case POINT_TYPE_WP:
155
                                        case POINT_TYPE_WP:
157
                                                //nothing to do
156
                                                //nothing to do
158
                                                break;
157
                                                break;
159
                                       
158
                                       
160
                                        case POINT_TYPE_POI:
159
                                        case POINT_TYPE_POI:
161
                                                POICount++;
160
                                                POICount++;
162
                                                WPCount--;
161
                                                WPCount--;
163
                                                break;
162
                                                break;
164
                                }
163
                                }
165
                                break;
164
                                break;
166
                               
165
                               
167
                        case POINT_TYPE_POI: // was a poi
166
                        case POINT_TYPE_POI: // was a poi
168
                                switch(pPoint->Type)
167
                                switch(pPoint->Type)
169
                                {
168
                                {
170
                                        case POINT_TYPE_INVALID:
169
                                        case POINT_TYPE_INVALID:
171
                                                POICount--;
170
                                                POICount--;
172
                                                PointCount--;
171
                                                PointCount--;
173
                                                break;
172
                                                break;
174
 
173
 
175
                                        case POINT_TYPE_WP:
174
                                        case POINT_TYPE_WP:
176
                                                WPCount++;
175
                                                WPCount++;
177
                                                POICount--;
176
                                                POICount--;
178
                                                break;
177
                                                break;
179
                                       
178
                                       
180
                                        case POINT_TYPE_POI:
179
                                        case POINT_TYPE_POI:
181
                                        default:
180
                                        default:
182
                                                // nothing to do
181
                                                // nothing to do
183
                                                break;
182
                                                break;
184
                                }
183
                                }
185
                                break;         
184
                                break;         
186
                }
185
                }
187
                memcpy(&PointList[pPoint->Index-1], pPoint, sizeof(Point_t)); // copy data to list entry                                                                                
186
                memcpy(&PointList[pPoint->Index-1], pPoint, sizeof(Point_t)); // copy data to list entry                                                                                
188
                NaviData.WaypointNumber = WPCount;
187
                NaviData.WaypointNumber = WPCount;
189
                return pPoint->Index;
188
                return pPoint->Index;
190
        }
189
        }
191
        else return(0);
190
        else return(0);
192
}
191
}
193
 
192
 
194
// returns the pointer to the first waypoint within the list
193
// returns the pointer to the first waypoint within the list
195
Point_t* PointList_WPBegin(void)
194
Point_t* PointList_WPBegin(void)
196
{
195
{
197
        u8 i;
196
        u8 i;
198
        WPIndex = 0; // set list position invalid
197
        WPIndex = 0; // set list position invalid
199
 
198
 
200
        if(WPActive == FALSE) return(NULL);
199
        if(WPActive == FALSE) return(NULL);
201
 
200
 
202
        POIIndex = 0; // set invalid POI
201
        POIIndex = 0; // set invalid POI
203
        if(PointCount > 0)
202
        if(PointCount > 0)
204
        {
203
        {
205
                // search for first wp in list
204
                // search for first wp in list
206
                for(i = 0; i <MAX_LIST_LEN; i++)
205
                for(i = 0; i <MAX_LIST_LEN; i++)
207
                {
206
                {
208
                        if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID))
207
                        if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID))
209
                        {
208
                        {
210
                                WPIndex = i + 1;
209
                                WPIndex = i + 1;
211
                                break;
210
                                break;
212
                        }
211
                        }
213
                }
212
                }
214
                if(WPIndex) // found a WP in the list
213
                if(WPIndex) // found a WP in the list
215
                {
214
                {
216
                        NaviData.WaypointIndex = 1;
215
                        NaviData.WaypointIndex = 1;
217
                        // update index to POI
216
                        // update index to POI
218
                        if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading);
217
                        if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading);
219
                        else POIIndex = 0;                     
218
                        else POIIndex = 0;                     
220
                }
219
                }
221
                else // some points in the list but no WP found
220
                else // some points in the list but no WP found
222
                {
221
                {
223
                        NaviData.WaypointIndex = 0;
222
                        NaviData.WaypointIndex = 0;
224
                        //Check for an existing POI
223
                        //Check for an existing POI
225
                        for(i = 0; i < MAX_LIST_LEN; i++)
224
                        for(i = 0; i < MAX_LIST_LEN; i++)
226
                        {
225
                        {
227
                                if((PointList[i].Type == POINT_TYPE_POI) && (PointList[i].Position.Status != INVALID))
226
                                if((PointList[i].Type == POINT_TYPE_POI) && (PointList[i].Position.Status != INVALID))
228
                                {
227
                                {
229
                                        POIIndex = i + 1;
228
                                        POIIndex = i + 1;
230
                                        break;
229
                                        break;
231
                                }
230
                                }
232
                        }
231
                        }
233
                }
232
                }
234
        }
233
        }
235
        else // no point in the list
234
        else // no point in the list
236
        {
235
        {
237
                POIIndex = 0;
236
                POIIndex = 0;
238
                NaviData.WaypointIndex = 0;    
237
                NaviData.WaypointIndex = 0;    
239
        }
238
        }
240
 
239
 
241
        if(WPIndex) return(&(PointList[WPIndex-1]));
240
        if(WPIndex) return(&(PointList[WPIndex-1]));
242
        else return(NULL);
241
        else return(NULL);
243
}
242
}
244
 
243
 
245
// returns the last waypoint
244
// returns the last waypoint
246
Point_t* PointList_WPEnd(void)
245
Point_t* PointList_WPEnd(void)
247
{
246
{
248
       
247
       
249
        u8 i;
248
        u8 i;
250
        WPIndex = 0; // set list position invalid
249
        WPIndex = 0; // set list position invalid
251
        POIIndex = 0; // set invalid
250
        POIIndex = 0; // set invalid
252
 
251
 
253
        if(WPActive == FALSE) return(NULL);
252
        if(WPActive == FALSE) return(NULL);
254
 
253
 
255
        if(PointCount > 0)
254
        if(PointCount > 0)
256
        {
255
        {
257
                // search backward!
256
                // search backward!
258
                for(i = 1; i <= MAX_LIST_LEN; i++)
257
                for(i = 1; i <= MAX_LIST_LEN; i++)
259
                {
258
                {
260
                        if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_WP) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID))
259
                        if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_WP) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID))
261
                        {      
260
                        {      
262
                                WPIndex = MAX_LIST_LEN - i + 1;
261
                                WPIndex = MAX_LIST_LEN - i + 1;
263
                                break;
262
                                break;
264
                        }
263
                        }
265
                }
264
                }
266
                if(WPIndex) // found a WP within the list
265
                if(WPIndex) // found a WP within the list
267
                {
266
                {
268
                        NaviData.WaypointIndex = WPCount;
267
                        NaviData.WaypointIndex = WPCount;
269
                        if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading);
268
                        if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading);
270
                        else POIIndex = 0;     
269
                        else POIIndex = 0;     
271
                }
270
                }
272
                else // list contains some points but no WP in the list
271
                else // list contains some points but no WP in the list
273
                {
272
                {
274
                        // search backward for a POI!
273
                        // search backward for a POI!
275
                        for(i = 1; i <= MAX_LIST_LEN; i++)
274
                        for(i = 1; i <= MAX_LIST_LEN; i++)
276
                        {
275
                        {
277
                                if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_POI) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID))
276
                                if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_POI) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID))
278
                                {      
277
                                {      
279
                                        POIIndex = MAX_LIST_LEN - i + 1;
278
                                        POIIndex = MAX_LIST_LEN - i + 1;
280
                                        break;
279
                                        break;
281
                                }
280
                                }
282
                        }
281
                        }
283
                        NaviData.WaypointIndex = 0;    
282
                        NaviData.WaypointIndex = 0;    
284
                }
283
                }
285
        }
284
        }
286
        else // no point in the list
285
        else // no point in the list
287
        {
286
        {
288
                POIIndex = 0;
287
                POIIndex = 0;
289
                NaviData.WaypointIndex = 0;
288
                NaviData.WaypointIndex = 0;
290
        }
289
        }
291
        if(WPIndex) return(&(PointList[WPIndex-1]));
290
        if(WPIndex) return(&(PointList[WPIndex-1]));
292
        else return(NULL);
291
        else return(NULL);
293
}
292
}
294
 
293
 
295
// returns a pointer to the next waypoint or NULL if the end of the list has been reached
294
// returns a pointer to the next waypoint or NULL if the end of the list has been reached
296
Point_t* PointList_WPNext(void)
295
Point_t* PointList_WPNext(void)
297
{
296
{
298
        u8 wp_found = 0;
297
        u8 wp_found = 0;
299
        if(WPActive == FALSE) return(NULL);
298
        if(WPActive == FALSE) return(NULL);
300
               
299
               
301
        if(WPIndex < MAX_LIST_LEN) // if there is a next entry in the list
300
        if(WPIndex < MAX_LIST_LEN) // if there is a next entry in the list
302
        {
301
        {
303
                u8 i;
302
                u8 i;
304
                for(i = WPIndex; i < MAX_LIST_LEN; i++) // start search for next at next list entry
303
                for(i = WPIndex; i < MAX_LIST_LEN; i++) // start search for next at next list entry
305
                {
304
                {
306
                        if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) // jump over POIs
305
                        if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) // jump over POIs
307
                        {
306
                        {
308
                                wp_found = i+1;
307
                                wp_found = i+1;
309
                                break;
308
                                break;
310
                        }
309
                        }
311
                }
310
                }
312
        }
311
        }
313
        if(wp_found)
312
        if(wp_found)
314
        {
313
        {
315
                WPIndex = wp_found; // update list position
314
                WPIndex = wp_found; // update list position
316
                NaviData.WaypointIndex++;
315
                NaviData.WaypointIndex++;
317
                if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading);
316
                if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading);
318
                else POIIndex = 0;
317
                else POIIndex = 0;
319
                return(&(PointList[WPIndex-1]));        // return pointer to this waypoint
318
                return(&(PointList[WPIndex-1]));        // return pointer to this waypoint
320
        }
319
        }
321
        else
320
        else
322
        {  // no next wp found
321
        {  // no next wp found
323
                NaviData.WaypointIndex = 0;    
322
                NaviData.WaypointIndex = 0;    
324
                POIIndex = 0;
323
                POIIndex = 0;
325
                return(NULL);
324
                return(NULL);
326
        }
325
        }
327
}      
326
}      
328
 
327
 
329
void PointList_WPActive(u8 set)
328
void PointList_WPActive(u8 set)
330
{
329
{
331
        if(set)
330
        if(set)
332
        {      
331
        {      
333
                WPActive = TRUE;
332
                WPActive = TRUE;
334
                PointList_WPBegin(); // uopdates POI index
333
                PointList_WPBegin(); // uopdates POI index
335
        }
334
        }
336
        else
335
        else
337
        {
336
        {
338
                WPActive = FALSE;
337
                WPActive = FALSE;
339
                POIIndex = 0;  // disable POI also
338
                POIIndex = 0;  // disable POI also
340
        }
339
        }
341
}
340
}
342
 
341
 
343
Point_t* PointList_GetPOI(void)
342
Point_t* PointList_GetPOI(void)
344
{
343
{
345
        return PointList_GetAt(POIIndex);      
344
        return PointList_GetAt(POIIndex);      
346
}
345
}
347
 
346
 
348
 
347