Subversion Repositories NaviCtrl

Rev

Rev 225 | Rev 230 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 225 Rev 227
Line 60... Line 60...
60
#include "waypoints.h"
60
#include "waypoints.h"
61
#include "uart1.h"
61
#include "uart1.h"
Line 62... Line 62...
62
 
62
 
63
// the waypoints list
63
// the waypoints list
64
#define WPLISTLEN 21
-
 
-
 
64
#define WPLISTLEN 21
65
#define MAXWPNUMBER (WPLISTLEN-1)
65
 
66
Waypoint_t WPList[WPLISTLEN];
66
Waypoint_t WPList[WPLISTLEN];
67
u8 WPIndex = 0;         // index of GPS point representig the WP
67
u8 WPIndex = 0;         // list index of GPS point representig the current WP, can be maximal WPNumber
68
u8 POIIndex = 0;        // index of GPS Point representing the current POI
68
u8 POIIndex = 0;        // list index of GPS Point representing the current POI, can be maximal WPNumber
Line 69... Line 69...
69
u8 WPNumber = 0;
69
u8 WPNumber = 0;        // number of wp in the list can be maximal equal to WPLISTLEN
70
 
70
 
71
u8 WPList_Init(void)
71
u8 WPList_Init(void)
72
{
72
{
Line 73... Line 73...
73
        return WPList_Clear();
73
        return WPList_Clear();
74
}
74
}
75
 
75
 
76
u8 WPList_Clear(void)
76
u8 WPList_Clear(void)
77
{
77
{
78
        u8 i;
78
        u8 i;
79
        WPIndex = 0;    // invalid index
79
        WPIndex = 0;    // real list position are 1 ,2, 3 ...
80
        POIIndex = 0;   // invalid index
80
        POIIndex = 0;   // real list position are 1 ,2, 3 ...
Line 81... Line 81...
81
        WPNumber = 0;   // no contents
81
        WPNumber = 0;   // no contents
82
        NaviData.WaypointNumber = WPNumber;
82
        NaviData.WaypointNumber = WPNumber;
83
        NaviData.WaypointIndex = WPIndex;
83
        NaviData.WaypointIndex = WPIndex;
84
 
84
 
85
        for(i = 0; i < WPLISTLEN; i++)
85
        for(i = 0; i < WPLISTLEN; i++)
86
        {
86
        {
87
                WPList[i].Position.Status = INVALID;
87
                WPList[i].Position.Status = INVALID;
88
                WPList[i].Position.Latitude = 0;
88
                WPList[i].Position.Latitude = 0;
89
                WPList[i].Position.Longitude = 0;
89
                WPList[i].Position.Longitude = 0;
90
                WPList[i].Position.Altitude = 0;
90
                WPList[i].Position.Altitude = 0;
-
 
91
                WPList[i].Heading = 361;                // invalid value
91
                WPList[i].Heading = -1;
92
                WPList[i].ToleranceRadius = 0;  // in meters, if the MK is within that range around the target, then the next target is triggered
92
                WPList[i].ToleranceRadius = 0;  // in meters, if the MK is within that range around the target, then the next target is triggered
93
                WPList[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
93
                WPList[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
94
                WPList[i].Event_Flag = 0;               // future implementation
Line 94... Line 95...
94
                WPList[i].Event_Flag = 0;               // future implementation
95
                WPList[i].Type = POINT_TYPE_WP;
95
        }
96
        }
96
        return TRUE;           
97
        return TRUE;           
97
}
98
}
Line 98... Line 99...
98
 
99
 
99
u8 WPList_GetCount(void)
100
u8 WPList_GetCount(void)
100
{
101
{
101
        return WPNumber;
102
        return WPNumber; // number of points in the list
102
}
103
}
103
 
-
 
104
u8 WPList_Append(Waypoint_t* pwp)
104
 
105
{
105
u8 WPList_Append(Waypoint_t* pwp)
106
        if(WPNumber < MAXWPNUMBER) // there is still some space in the list
106
{
107
        {
107
        if(WPNumber < WPLISTLEN) // there is still some space in the list
108
                memcpy(&WPList[WPNumber], pwp, sizeof(Waypoint_t)); // copy wp data to list entry
108
        {
109
                WPList[WPNumber].Position.Status = NEWDATA;             // mark as new data                                                                             // increment list length
109
                memcpy(&WPList[WPNumber], pwp, sizeof(Waypoint_t)); // copy wp data to list entry                                                                               // increment list length
Line 110... Line 110...
110
                WPNumber++;
110
                WPNumber++;
111
                NaviData.WaypointNumber = WPNumber;
111
                NaviData.WaypointNumber = WPNumber;
112
                return TRUE;
112
                return TRUE;
-
 
113
        }
-
 
114
        else return FALSE;
113
        }
115
}
114
        else return FALSE;
116
 
115
}
117
// returns the pointer to the first waypoint within the list
116
 
118
Waypoint_t* WPList_Begin(void)
117
// returns the first waypoint
119
{
118
Waypoint_t* WPList_Begin(void)
120
        WPIndex = 0; // set list position invalid
119
{
121
       
120
        if(WPNumber > 0)
122
        if(WPNumber > 0)
121
        {
123
        {
122
                u8 i, wp_found = 0;
124
                u8 i;
123
                // search for first wp in list
125
                // search for first wp in list
124
                for(i = 0; i < WPNumber; i++)
126
                for(i = 0; i < WPNumber; i++)
125
                {
-
 
126
                        if(WPList[i].Type == POINT_TYPE_WP)
-
 
127
                        {
-
 
128
                                wp_found = 1;
-
 
129
                                break;
-
 
130
                        }
-
 
131
                }
-
 
132
                if(wp_found) // found a WP in the list
-
 
133
                {
-
 
134
                        WPIndex = i+1;
-
 
135
                        NaviData.WaypointIndex = WPIndex;
-
 
136
                        if(WPList[WPIndex-1].Heading < 0) POIIndex = (u8)(-WPList[WPIndex-1].Heading);
-
 
137
                        else POIIndex = 0;     
-
 
138
                        return(&(WPList[WPIndex-1])); // if list is not empty return pointer to first waypoint in the list              
-
 
139
                }
-
 
140
                else  // found no WP within the list
127
                {
-
 
128
                        if((WPList[i].Type == POINT_TYPE_WP) && (WPList[i].Position.Status != INVALID))
-
 
129
                        {
-
 
130
                                WPIndex = i + 1;
-
 
131
                                break;
-
 
132
                        }
141
                {
133
                }
-
 
134
        }
-
 
135
        if(WPIndex) // found a WP in the list
-
 
136
        {
142
                        WPIndex = 0;
137
                NaviData.WaypointIndex = WPIndex;
143
                        POIIndex = 0;
-
 
144
                        NaviData.WaypointIndex = WPIndex;
138
                // update index to POI
145
                        return NULL;
139
                if(WPList[WPIndex-1].Heading < 0) POIIndex = (u8)(-WPList[WPIndex-1].Heading);
146
                }
140
                else POIIndex = 0;     
147
        }
141
                return(&(WPList[WPIndex-1])); // if list is not empty return pointer to first waypoint in the list              
148
        else // empty list
-
 
149
        {
142
        }
Line 150... Line 143...
150
                WPIndex = 0; // invalid index
143
        else
151
                POIIndex = 0;
144
        {
152
                NaviData.WaypointIndex = WPIndex;
145
                POIIndex = 0;
-
 
146
                NaviData.WaypointIndex = WPIndex;
153
                return NULL;
147
                return NULL;
154
        }
148
        }
155
 
149
}
156
}
150
 
157
 
151
// returns the last waypoint
158
// returns the last waypoint
152
Waypoint_t* WPList_End(void)
159
Waypoint_t* WPList_End(void)
153
{
160
{
154
        WPIndex = 0; // set list position invalid
161
        if(WPNumber > 0)
155
        if(WPNumber > 0)
162
        {
156
        {
163
                // search backward
157
                // search backward!
164
                u8 i, wp_found = 0;
158
                u8 i;
-
 
159
                for(i = 1; i <= WPNumber; i++)
165
                for(i = 1; i <= WPNumber; i++)
160
                {
166
                {
161
                        if((WPList[WPNumber - i].Type == POINT_TYPE_WP) && (WPList[WPNumber - i].Position.Status != INVALID))
167
                        if(WPList[WPNumber - i].Type == POINT_TYPE_WP)
-
 
168
                        {      
162
                        {      
169
                                wp_found = 1;
163
                                WPIndex = WPNumber - i + 1;
170
                                break;
164
                                break;
171
                        }
165
                        }
172
                }
-
 
173
                if(wp_found) // found a WP within the list
-
 
174
                {
-
 
175
                        WPIndex = WPNumber - i + 1;
-
 
176
                        NaviData.WaypointIndex = WPIndex;
-
 
177
                        if(WPList[WPIndex-1].Heading < 0) POIIndex = (u8)(-WPList[WPIndex-1].Heading);
-
 
178
                        else POIIndex = 0;     
-
 
179
                        return(&(WPList[WPIndex-1]));
-
 
180
                }
166
                }
181
                else
167
        }
182
                {
168
        if(WPIndex) // found a WP within the list
183
                        WPIndex = 0;
-
 
184
                        POIIndex = 0;
169
        {
185
                        NaviData.WaypointIndex = WPIndex;
170
                NaviData.WaypointIndex = WPIndex;
186
                        return NULL;   
171
                if(WPList[WPIndex-1].Heading < 0) POIIndex = (u8)(-WPList[WPIndex-1].Heading);
187
                }
172
                else POIIndex = 0;     
188
        }
173
                return(&(WPList[WPIndex-1]));
Line 189... Line 174...
189
        else
174
        }
190
        {
175
        else
191
                WPIndex = 0;
176
        {
192
                POIIndex = 0;
177
                POIIndex = 0;
-
 
178
                NaviData.WaypointIndex = WPIndex;
193
                NaviData.WaypointIndex = WPIndex;
179
                return NULL;   
194
                return NULL;
180
        }
195
        }
181
}
196
}
182
 
197
 
183
// returns a pointer to the next waypoint or NULL if the end of the list has been reached
198
// returns a pointer to the next waypoint or NULL if the end of the list has been reached
184
Waypoint_t* WPList_Next(void)
199
Waypoint_t* WPList_Next(void)
185
{
200
{
186
        u8 wp_found = 0;
201
        if(WPNumber == 0) return NULL;
187
               
202
        if((WPIndex > 0) && (WPIndex < WPNumber)) // if the next WP exist
188
        if(WPIndex < WPNumber) // if there is a next entry in the list
203
        {
189
        {
-
 
190
                u8 i;
204
                u8 i, wp_found = 0;
191
                for(i = WPIndex; i < WPNumber; i++)     // start search for next at next list entry
205
                for(i = WPIndex; i < WPNumber; i++)
192
                {
206
                {
193
                        if((WPList[i].Type == POINT_TYPE_WP) && (WPList[i].Position.Status != INVALID)) // jump over POIs
207
                        if(WPList[i].Type == POINT_TYPE_WP) // jump over POIs
194
                        {
208
                        {
195
                                wp_found = i+1;
209
                                wp_found = 1;
196
                                break;
210
                                break;
197
                        }
211
                        }
-
 
212
                }
-
 
213
                if(wp_found)
198
                }
214
                {
199
        }
215
                        WPIndex = i+1;
200
        if(wp_found)
Line 216... Line 201...
216
                        NaviData.WaypointIndex = WPIndex;
201
        {