Subversion Repositories NaviCtrl

Rev

Rev 351 | Rev 490 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
41 ingob 1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + www.MikroKopter.com
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
360 holgerb 7
// + Software Nutzungsbedingungen (english version: see below)
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
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.
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
41 ingob 13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
360 holgerb 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.
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.
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.
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 
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.
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
// + 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.
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.
41 ingob 31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
360 holgerb 32
// + Software LICENSING TERMS
41 ingob 33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
360 holgerb 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 
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.
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
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
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
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
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.
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.
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.
52
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
53
// + #### END OF LICENSING TERMS ####
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
41 ingob 55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56
 
57
#include <string.h>
58
#include "91x_lib.h"
59
#include "waypoints.h"
60
#include "uart1.h"
61
 
62
// the waypoints list
351 holgerb 63
#define MAX_LIST_LEN 101
227 killagreg 64
 
280 killagreg 65
Point_t PointList[MAX_LIST_LEN];
66
u8 WPIndex = 0;         // list index of GPS point representig the current WP, can be maximal WPCount
67
u8 POIIndex = 0;        // list index of GPS Point representing the current POI, can be maximal WPCount
68
u8 WPCount = 0;         // number of waypoints
69
u8 PointCount = 0;              // number of wp in the list can be maximal equal to MAX_LIST_LEN
283 holgerb 70
u8 POICount = 0;
41 ingob 71
 
296 killagreg 72
u8 WPActive = FALSE;
280 killagreg 73
 
74
u8 PointList_Init(void)
41 ingob 75
{
280 killagreg 76
        return PointList_Clear();
41 ingob 77
}
78
 
280 killagreg 79
u8 PointList_Clear(void)
41 ingob 80
{
81
        u8 i;
227 killagreg 82
        WPIndex = 0;    // real list position are 1 ,2, 3 ...
83
        POIIndex = 0;   // real list position are 1 ,2, 3 ...
280 killagreg 84
        WPCount = 0;    // no waypoints
283 holgerb 85
    POICount = 0;
280 killagreg 86
        PointCount = 0; // no contents
296 killagreg 87
        WPActive = FALSE;
280 killagreg 88
        NaviData.WaypointNumber = WPCount;
89
        NaviData.WaypointIndex = 0;
41 ingob 90
 
280 killagreg 91
        for(i = 0; i < MAX_LIST_LEN; i++)
41 ingob 92
        {
280 killagreg 93
                PointList[i].Position.Status = INVALID;
94
                PointList[i].Position.Latitude = 0;
95
                PointList[i].Position.Longitude = 0;
96
                PointList[i].Position.Altitude = 0;
97
                PointList[i].Heading = 361;             // invalid value
98
                PointList[i].ToleranceRadius = 0;       // in meters, if the MK is within that range around the target, then the next target 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
286 killagreg 100
                PointList[i].Type = POINT_TYPE_INVALID;
280 killagreg 101
                PointList[i].Event_Flag = 0;            // future implementation
286 killagreg 102
                PointList[i].AltitudeRate = 0;          // no change of setpoint
41 ingob 103
        }
104
        return TRUE;           
105
}
106
 
280 killagreg 107
u8 PointList_GetCount(void)
41 ingob 108
{
280 killagreg 109
        return PointCount; // number of points in the list
41 ingob 110
}
111
 
295 killagreg 112
Point_t* PointList_GetAt(u8 index)
41 ingob 113
{
295 killagreg 114
        if((index > 0) && (index <= PointCount)) return(&(PointList[index-1])); // return pointer to this waypoint
115
        else return(NULL);
116
}
117
 
118
u8 PointList_SetAt(Point_t* pPoint)
119
{
120
        // if index is in range
296 killagreg 121
        if((pPoint->Index > 0) && (pPoint->Index <= MAX_LIST_LEN))
41 ingob 122
        {
295 killagreg 123
                // check list entry before update
124
                switch(PointList[pPoint->Index-1].Type)
277 killagreg 125
                {
295 killagreg 126
                        case POINT_TYPE_INVALID: // was invalid
127
                                switch(pPoint->Type)
128
                                {
129
                                        default:
130
                                        case POINT_TYPE_INVALID:
131
                                                // nothing to do
132
                                                break;
133
 
134
                                        case POINT_TYPE_WP:
135
                                                WPCount++;
136
                                                PointCount++;
137
                                                break;
138
 
139
                                        case POINT_TYPE_POI:
140
                                                POICount++;
141
                                                PointCount++;
142
                                                break;
143
                                }
144
                                break;
277 killagreg 145
 
295 killagreg 146
                        case POINT_TYPE_WP: // was  a waypoint
147
                                switch(pPoint->Type)
148
                                {
149
                                        case POINT_TYPE_INVALID:
150
                                                WPCount--;
151
                                                PointCount--;
152
                                                break;
277 killagreg 153
 
295 killagreg 154
                                        default:
155
                                        case POINT_TYPE_WP:
156
                                                //nothing to do
157
                                                break;
158
 
159
                                        case POINT_TYPE_POI:
160
                                                POICount++;
161
                                                WPCount--;
162
                                                break;
163
                                }
164
                                break;
165
 
166
                        case POINT_TYPE_POI: // was a poi
167
                                switch(pPoint->Type)
168
                                {
169
                                        case POINT_TYPE_INVALID:
170
                                                POICount--;
171
                                                PointCount--;
172
                                                break;
173
 
174
                                        case POINT_TYPE_WP:
175
                                                WPCount++;
176
                                                POICount--;
177
                                                break;
178
 
179
                                        case POINT_TYPE_POI:
180
                                        default:
181
                                                // nothing to do
182
                                                break;
183
                                }
184
                                break;         
277 killagreg 185
                }
295 killagreg 186
                memcpy(&PointList[pPoint->Index-1], pPoint, sizeof(Point_t)); // copy data to list entry                                                                                
187
                NaviData.WaypointNumber = WPCount;
188
                return pPoint->Index;
41 ingob 189
        }
296 killagreg 190
        else return(0);
41 ingob 191
}
192
 
227 killagreg 193
// returns the pointer to the first waypoint within the list
280 killagreg 194
Point_t* PointList_WPBegin(void)
41 ingob 195
{
277 killagreg 196
        u8 i;
227 killagreg 197
        WPIndex = 0; // set list position invalid
295 killagreg 198
 
283 holgerb 199
        if(WPActive == FALSE) return(NULL);
295 killagreg 200
 
277 killagreg 201
        POIIndex = 0; // set invalid POI
280 killagreg 202
        if(PointCount > 0)
152 killagreg 203
        {
225 killagreg 204
                // search for first wp in list
295 killagreg 205
                for(i = 0; i <MAX_LIST_LEN; i++)
225 killagreg 206
                {
280 killagreg 207
                        if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID))
225 killagreg 208
                        {
227 killagreg 209
                                WPIndex = i + 1;
225 killagreg 210
                                break;
211
                        }
212
                }
277 killagreg 213
                if(WPIndex) // found a WP in the list
214
                {
280 killagreg 215
                        NaviData.WaypointIndex = 1;
277 killagreg 216
                        // update index to POI
280 killagreg 217
                        if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading);
296 killagreg 218
                        else POIIndex = 0;                     
277 killagreg 219
                }
220
                else // some points in the list but no WP found
221
                {
280 killagreg 222
                        NaviData.WaypointIndex = 0;
277 killagreg 223
                        //Check for an existing POI
295 killagreg 224
                        for(i = 0; i < MAX_LIST_LEN; i++)
277 killagreg 225
                        {
280 killagreg 226
                                if((PointList[i].Type == POINT_TYPE_POI) && (PointList[i].Position.Status != INVALID))
277 killagreg 227
                                {
228
                                        POIIndex = i + 1;
229
                                        break;
230
                                }
231
                        }
232
                }
152 killagreg 233
        }
277 killagreg 234
        else // no point in the list
152 killagreg 235
        {
277 killagreg 236
                POIIndex = 0;
295 killagreg 237
                NaviData.WaypointIndex = 0;    
227 killagreg 238
        }
295 killagreg 239
 
240
        if(WPIndex) return(&(PointList[WPIndex-1]));
241
        else return(NULL);
41 ingob 242
}
243
 
225 killagreg 244
// returns the last waypoint
280 killagreg 245
Point_t* PointList_WPEnd(void)
151 killagreg 246
{
277 killagreg 247
 
248
        u8 i;
227 killagreg 249
        WPIndex = 0; // set list position invalid
277 killagreg 250
        POIIndex = 0; // set invalid
283 holgerb 251
 
280 killagreg 252
        if(WPActive == FALSE) return(NULL);
277 killagreg 253
 
280 killagreg 254
        if(PointCount > 0)
151 killagreg 255
        {
227 killagreg 256
                // search backward!
295 killagreg 257
                for(i = 1; i <= MAX_LIST_LEN; i++)
225 killagreg 258
                {
295 killagreg 259
                        if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_WP) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID))
225 killagreg 260
                        {      
295 killagreg 261
                                WPIndex = MAX_LIST_LEN - i + 1;
225 killagreg 262
                                break;
263
                        }
264
                }
277 killagreg 265
                if(WPIndex) // found a WP within the list
266
                {
280 killagreg 267
                        NaviData.WaypointIndex = WPCount;
268
                        if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading);
277 killagreg 269
                        else POIIndex = 0;     
270
                }
278 killagreg 271
                else // list contains some points but no WP in the list
277 killagreg 272
                {
273
                        // search backward for a POI!
295 killagreg 274
                        for(i = 1; i <= MAX_LIST_LEN; i++)
277 killagreg 275
                        {
295 killagreg 276
                                if((PointList[MAX_LIST_LEN - i].Type == POINT_TYPE_POI) && (PointList[MAX_LIST_LEN - i].Position.Status != INVALID))
277 killagreg 277
                                {      
295 killagreg 278
                                        POIIndex = MAX_LIST_LEN - i + 1;
277 killagreg 279
                                        break;
280
                                }
281
                        }
295 killagreg 282
                        NaviData.WaypointIndex = 0;    
277 killagreg 283
                }
151 killagreg 284
        }
277 killagreg 285
        else // no point in the list
227 killagreg 286
        {
280 killagreg 287
                POIIndex = 0;
288
                NaviData.WaypointIndex = 0;
227 killagreg 289
        }
295 killagreg 290
        if(WPIndex) return(&(PointList[WPIndex-1]));
291
        else return(NULL);
151 killagreg 292
}
293
 
41 ingob 294
// returns a pointer to the next waypoint or NULL if the end of the list has been reached
280 killagreg 295
Point_t* PointList_WPNext(void)
41 ingob 296
{
227 killagreg 297
        u8 wp_found = 0;
280 killagreg 298
        if(WPActive == FALSE) return(NULL);
227 killagreg 299
 
295 killagreg 300
        if(WPIndex < MAX_LIST_LEN) // if there is a next entry in the list
41 ingob 301
        {
227 killagreg 302
                u8 i;
295 killagreg 303
                for(i = WPIndex; i < MAX_LIST_LEN; i++) // start search for next at next list entry
225 killagreg 304
                {
280 killagreg 305
                        if((PointList[i].Type == POINT_TYPE_WP) && (PointList[i].Position.Status != INVALID)) // jump over POIs
225 killagreg 306
                        {
227 killagreg 307
                                wp_found = i+1;
225 killagreg 308
                                break;
309
                        }
310
                }
41 ingob 311
        }
227 killagreg 312
        if(wp_found)
313
        {
314
                WPIndex = wp_found; // update list position
280 killagreg 315
                NaviData.WaypointIndex++;
316
                if(PointList[WPIndex-1].Heading < 0) POIIndex = (u8)(-PointList[WPIndex-1].Heading);
227 killagreg 317
                else POIIndex = 0;
280 killagreg 318
                return(&(PointList[WPIndex-1]));        // return pointer to this waypoint
227 killagreg 319
        }
277 killagreg 320
        else
280 killagreg 321
        {  // no next wp found
322
                NaviData.WaypointIndex = 0;    
277 killagreg 323
                POIIndex = 0;
324
                return(NULL);
325
        }
41 ingob 326
}      
280 killagreg 327
 
328
void PointList_WPActive(u8 set)
329
{
295 killagreg 330
        if(set)
331
        {      
332
                WPActive = TRUE;
333
                PointList_WPBegin(); // uopdates POI index
334
        }
335
        else
336
        {
337
                WPActive = FALSE;
338
                POIIndex = 0;  // disable POI also
339
        }
280 killagreg 340
}
41 ingob 341
 
280 killagreg 342
Point_t* PointList_GetPOI(void)
224 killagreg 343
{
280 killagreg 344
        return PointList_GetAt(POIIndex);      
224 killagreg 345
}
346