Rev 351 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*#######################################################################################*/
/* !!! THIS IS NOT FREE SOFTWARE !!! */
/*#######################################################################################*/
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + www.MikroKopter.com
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Software Nutzungsbedingungen (english version: see below)
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand
// + des Mitverschuldens offen.
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
// + 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.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Software LICENSING TERMS
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
// + 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
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
// + The Software may only be used with the Licensor's products.
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
// + agreement shall be the property of the Licensor.
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
// + features that can be used to identify the program may not be altered or defaced by the customer.
// + The customer shall be responsible for taking reasonable precautions
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
// + #### END OF LICENSING TERMS ####
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <string.h>
#include "91x_lib.h"
#include "waypoints.h"
#include "uart1.h"
// the waypoints list
#define MAX_LIST_LEN 101
Point_t PointList
[MAX_LIST_LEN
];
u8 WPIndex
= 0; // list index of GPS point representig the current WP, can be maximal WPCount
u8 POIIndex
= 0; // list index of GPS Point representing the current POI, can be maximal WPCount
u8 WPCount
= 0; // number of waypoints
u8 PointCount
= 0; // number of wp in the list can be maximal equal to MAX_LIST_LEN
u8 POICount
= 0;
u8 WPActive
= FALSE
;
u8 PointList_Init
(void)
{
return PointList_Clear
();
}
u8 PointList_Clear
(void)
{
u8 i
;
WPIndex
= 0; // real list position are 1 ,2, 3 ...
POIIndex
= 0; // real list position are 1 ,2, 3 ...
WPCount
= 0; // no waypoints
POICount
= 0;
PointCount
= 0; // no contents
WPActive
= FALSE
;
NaviData.
WaypointNumber = WPCount
;
NaviData.
WaypointIndex = 0;
for(i
= 0; i
< MAX_LIST_LEN
; i
++)
{
PointList
[i
].
Position.
Status = INVALID
;
PointList
[i
].
Position.
Latitude = 0;
PointList
[i
].
Position.
Longitude = 0;
PointList
[i
].
Position.
Altitude = 0;
PointList
[i
].
Heading = 361; // invalid value
PointList
[i
].
ToleranceRadius = 0; // in meters, if the MK is within that range around the target, then the next target is triggered
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
PointList
[i
].
Type = POINT_TYPE_INVALID
;
PointList
[i
].
Event_Flag = 0; // future implementation
PointList
[i
].
AltitudeRate = 0; // no change of setpoint
}
return TRUE
;
}
u8 PointList_GetCount
(void)
{
return PointCount
; // number of points in the list
}
Point_t
* PointList_GetAt
(u8 index
)
{
if((index
> 0) && (index
<= PointCount
)) return(&(PointList
[index
-1])); // return pointer to this waypoint
else return(NULL
);
}
u8 PointList_SetAt
(Point_t
* pPoint
)
{
// if index is in range
if((pPoint
->Index
> 0) && (pPoint
->Index
<= MAX_LIST_LEN
))
{
// check list entry before update
switch(PointList
[pPoint
->Index
-1].
Type)
{
case POINT_TYPE_INVALID
: // was invalid
switch(pPoint
->Type
)
{
default:
case POINT_TYPE_INVALID
:
// nothing to do
break;
case POINT_TYPE_WP
:
WPCount
++;
PointCount
++;
break;
case POINT_TYPE_POI
:
POICount
++;
PointCount
++;
break;
}
break;
case POINT_TYPE_WP
: // was a waypoint
switch(pPoint
->Type
)
{
case POINT_TYPE_INVALID
:
WPCount
--;
PointCount
--;
break;
default:
case POINT_TYPE_WP
:
//nothing to do
break;
case POINT_TYPE_POI
:
POICount
++;
WPCount
--;
break;
}
break;
case POINT_TYPE_POI
: // was a poi
switch(pPoint
->Type
)
{
case POINT_TYPE_INVALID
:
POICount
--;
PointCount
--;
break;
case POINT_TYPE_WP
:
WPCount
++;
POICount
--;
break;
case POINT_TYPE_POI
:
default:
// nothing to do
break;
}
break;
}
memcpy(&PointList
[pPoint
->Index
-1], pPoint
, sizeof(Point_t
)); // copy data to list entry
NaviData.
WaypointNumber = WPCount
;
return pPoint
->Index
;
}
else return(0);
}
// returns the pointer to the first waypoint within the list
Point_t
* PointList_WPBegin
(void)
{
u8 i
;
WPIndex
= 0; // set list position invalid
if(WPActive
== FALSE
) return(NULL
);
POIIndex
= 0; // set invalid POI
if(PointCount
> 0)
{
// search for first wp in list
for(i
= 0; i
<MAX_LIST_LEN
; i
++)
{
if((PointList
[i
].
Type == POINT_TYPE_WP
) && (PointList
[i
].
Position.
Status != INVALID
))
{
WPIndex
= i
+ 1;
break;
}
}
if(WPIndex
) // found a WP in the list
{
NaviData.
WaypointIndex = 1;
// update index to POI
if(PointList
[WPIndex
-1].
Heading < 0) POIIndex
= (u8
)(-PointList
[WPIndex
-1].
Heading);
else POIIndex
= 0;
}
else // some points in the list but no WP found
{
NaviData.
WaypointIndex = 0;
//Check for an existing POI
for(i
= 0; i
< MAX_LIST_LEN
; i
++)
{
if((PointList
[i
].
Type == POINT_TYPE_POI
) && (PointList
[i
].
Position.
Status != INVALID
))
{
POIIndex
= i
+ 1;
break;
}
}
}
}
else // no point in the list
{
POIIndex
= 0;
NaviData.
WaypointIndex = 0;
}
if(WPIndex
) return(&(PointList
[WPIndex
-1]));
else return(NULL
);
}
// returns the last waypoint
Point_t
* PointList_WPEnd
(void)
{
u8 i
;
WPIndex
= 0; // set list position invalid
POIIndex
= 0; // set invalid
if(WPActive
== FALSE
) return(NULL
);
if(PointCount
> 0)
{
// search backward!
for(i
= 1; i
<= MAX_LIST_LEN
; i
++)
{
if((PointList
[MAX_LIST_LEN
- i
].
Type == POINT_TYPE_WP
) && (PointList
[MAX_LIST_LEN
- i
].
Position.
Status != INVALID
))
{
WPIndex
= MAX_LIST_LEN
- i
+ 1;
break;
}
}
if(WPIndex
) // found a WP within the list
{
NaviData.
WaypointIndex = WPCount
;
if(PointList
[WPIndex
-1].
Heading < 0) POIIndex
= (u8
)(-PointList
[WPIndex
-1].
Heading);
else POIIndex
= 0;
}
else // list contains some points but no WP in the list
{
// search backward for a POI!
for(i
= 1; i
<= MAX_LIST_LEN
; i
++)
{
if((PointList
[MAX_LIST_LEN
- i
].
Type == POINT_TYPE_POI
) && (PointList
[MAX_LIST_LEN
- i
].
Position.
Status != INVALID
))
{
POIIndex
= MAX_LIST_LEN
- i
+ 1;
break;
}
}
NaviData.
WaypointIndex = 0;
}
}
else // no point in the list
{
POIIndex
= 0;
NaviData.
WaypointIndex = 0;
}
if(WPIndex
) return(&(PointList
[WPIndex
-1]));
else return(NULL
);
}
// returns a pointer to the next waypoint or NULL if the end of the list has been reached
Point_t
* PointList_WPNext
(void)
{
u8 wp_found
= 0;
if(WPActive
== FALSE
) return(NULL
);
if(WPIndex
< MAX_LIST_LEN
) // if there is a next entry in the list
{
u8 i
;
for(i
= WPIndex
; i
< MAX_LIST_LEN
; i
++) // start search for next at next list entry
{
if((PointList
[i
].
Type == POINT_TYPE_WP
) && (PointList
[i
].
Position.
Status != INVALID
)) // jump over POIs
{
wp_found
= i
+1;
break;
}
}
}
if(wp_found
)
{
WPIndex
= wp_found
; // update list position
NaviData.
WaypointIndex++;
if(PointList
[WPIndex
-1].
Heading < 0) POIIndex
= (u8
)(-PointList
[WPIndex
-1].
Heading);
else POIIndex
= 0;
return(&(PointList
[WPIndex
-1])); // return pointer to this waypoint
}
else
{ // no next wp found
NaviData.
WaypointIndex = 0;
POIIndex
= 0;
return(NULL
);
}
}
void PointList_WPActive
(u8 set
)
{
if(set
)
{
WPActive
= TRUE
;
PointList_WPBegin
(); // uopdates POI index
}
else
{
WPActive
= FALSE
;
POIIndex
= 0; // disable POI also
}
}
Point_t
* PointList_GetPOI
(void)
{
return PointList_GetAt
(POIIndex
);
}