Subversion Repositories NaviCtrl

Compare Revisions

Ignore whitespace Rev 489 → Rev 490

/trunk/usb.h
File deleted
/trunk/main.c
586,6 → 586,8
Settings_GetParamValue(PID_SEND_NMEA, &NMEA_Interval);
UART1_PutString("\r\n");
CompassValueErrorCount = 0;
 
//PointList_ReadFromFile(1);
for (;;) // the endless main loop
{
PollingTimeout = 5;
/trunk/uart1.c
490,6 → 490,7
 
if((pPoint->Position.Status == INVALID) && (pPoint->Index == 0))
{
//PointList_SaveToFile(1); // save to file before clearing the list
PointList_Clear();
GPS_pWaypoint = PointList_WPBegin();
UART1_Request_WritePoint = 0; // return new point count
497,12 → 498,11
else
{ // update WP in list at index
if(pPoint->Index > MaxNumberOfWaypoints)
{
UART1_Request_WritePoint = 254;
pPoint->Index = MaxNumberOfWaypoints;
}
else
UART1_Request_WritePoint = PointList_SetAt(pPoint);
{
UART1_Request_WritePoint = 254;
pPoint->Index = MaxNumberOfWaypoints;
}
else UART1_Request_WritePoint = PointList_SetAt(pPoint);
if(FC.StatusFlags & FC_STATUS_FLY) PointList_WPActive(TRUE);
if(UART1_Request_WritePoint == pPoint->Index)
{
/trunk/waypoints.c
53,11 → 53,14
// + #### END OF LICENSING TERMS ####
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "91x_lib.h"
#include "waypoints.h"
#include "uart1.h"
#include "fat16.h"
 
// the waypoints list
#define MAX_LIST_LEN 101
97,9 → 100,14
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].Event_Flag = 0; // future implementation
PointList[i].Index = 0;
PointList[i].Type = POINT_TYPE_INVALID;
PointList[i].Event_Flag = 0; // future implementation
PointList[i].WP_EventChannelValue = 0;
PointList[i].AltitudeRate = 0; // no change of setpoint
PointList[i].Speed = 0;
PointList[i].CamAngle = 0;
PointList[i].Name[0] = 0;
}
return TRUE;
}
143,7 → 151,7
}
break;
case POINT_TYPE_WP: // was a waypoint
case POINT_TYPE_WP: // was a waypoint
switch(pPoint->Type)
{
case POINT_TYPE_INVALID:
344,3 → 352,313
return PointList_GetAt(POIIndex);
}
 
#define LINE_MAX 70
#define WP_FILE_VERSION_COMPATIBLE 3
// save actual point list to SD card
u8 PointList_SaveToFile(u8 place)
{
File_t *fp;
s8 wpline[LINE_MAX], retval = 0;
// user absolute path, i.e. leading /
 
sprintf(wpline, "/list_%03d.wpl", place);
 
UART1_PutString("\n\r Write ");
UART1_PutString(wpline);
UART1_PutString("...");
 
UART1_PutString("\n\r Save WPL...");
 
if(Fat16_IsValid())
{ // check if wpl file is existing
fp = fopen_(wpline, 'w'); // try to open the file
if(fp == NULL)
{
UART1_PutString("ERROR: Creating waypoint file!\r\n");
return(retval);
}
// Create general section and key entries
fputs_("[General]\r\n", fp);
sprintf(wpline, "FileVersion=%d\r\n", WP_FILE_VERSION_COMPATIBLE);
fputs_(wpline, fp);
sprintf(wpline, "NumberOfWaypoints=%d\r\n", PointCount);
fputs_(wpline, fp);
// dump all points if existent
if(PointCount)
{
u8 i, u8_1;
s32 i32_1, i32_2;
 
for (i = 0; i < PointCount; i++)
{
sprintf(wpline, "[Point%d]\r\n",PointList[i].Index);
fputs_(wpline, fp);
// write latitude in deg
if(PointList[i].Position.Latitude < 0) u8_1 = '-';
else u8_1 = '+';
i32_1 = abs(PointList[i].Position.Latitude)/10000000L;
i32_2 = abs(PointList[i].Position.Latitude)%10000000L;
sprintf(wpline, "Latitude=%c%ld.%07ld\r\n", u8_1, i32_1, i32_2);
fputs_(wpline, fp);
// write longitude in deg
if(PointList[i].Position.Longitude < 0) u8_1 = '-';
else u8_1 = '+';
i32_1 = abs(PointList[i].Position.Longitude)/10000000L;
i32_2 = abs(PointList[i].Position.Longitude)%10000000L;
sprintf(wpline, "Longitude=%c%ld.%07ld\r\n", u8_1, i32_1, i32_2);
fputs_(wpline, fp);
// write tolerace radius in m
sprintf(wpline, "Radius=%d\r\n", PointList[i].ToleranceRadius);
fputs_(wpline, fp);
// write altitude in m
if(PointList[i].Position.Altitude < 0) u8_1 = '-';
else u8_1 = '+';
if(PointList[i].Type == POINT_TYPE_POI)
{
i32_1 = abs(PointList[i].Position.Altitude)/100L; // cm --> m
i32_2 = abs(PointList[i].Position.Altitude)%100L;
}
else
{
i32_1 = abs(PointList[i].Position.Altitude)/10L; // dm --> m
i32_2 = abs(PointList[i].Position.Altitude)%10L;
}
sprintf(wpline, "Altitude=%c%ld.%01ld\r\n", u8_1, i32_1, i32_2);
fputs_(wpline, fp);
// write climb rate in 0.1 m/s
sprintf(wpline, "ClimbRate=%d\r\n", PointList[i].AltitudeRate);
fputs_(wpline, fp);
// write hold time in s
sprintf(wpline, "DelayTime=%d\r\n", PointList[i].HoldTime);
fputs_(wpline, fp);
// write event channel value
sprintf(wpline, "WP_Event_Channel_Value=%d\r\n", PointList[i].WP_EventChannelValue);
fputs_(wpline, fp);
// write heading in deg (0= nothing, neg. values index to poi)
sprintf(wpline, "Heading=%d\r\n", PointList[i].Heading);
fputs_(wpline, fp);
// write speed in 0.1 m/s
sprintf(wpline, "Speed=%d\r\n", PointList[i].Speed);
fputs_(wpline, fp);
// write cam angle in degree (255 -> POI-Automatic)
sprintf(wpline, "CAM-Nick=%d\r\n", PointList[i].CamAngle);
fputs_(wpline, fp);
// write point type
sprintf(wpline, "Type=%d\r\n", PointList[i].Type + 1);
fputs_(wpline, fp);
// write prefix
//if(PointList[i].Type == POINT_TYPE_WP) u8_1 = 'P';
//else u8_1 = '0';
sprintf(wpline, "Prefix=%s\r\n", PointList[i].Name);
fputs_(wpline, fp);
} // EOF loop over all points
} // EOF if(PointCount)
if(EOF == fclose_(fp))
{
UART1_PutString("failed!\r\n");
}
else
{
UART1_PutString("ok\r\n");
retval = 1;
}
} // EOF if(Fat16_IsValid())
UART1_PutString("no file system found!\r\n");
return(retval);
}
 
// load actual point list from SD card
u8 PointList_ReadFromFile(u8 place)
{
File_t *fp;
s8 wpline[LINE_MAX], retval = 0;
s8 *name, *value;
u8 i;
 
u8 IsGeneralSection = 0;
u8 IsPointSection = 0;
u8 WPNumber = 0;
 
// user absolute path, i.e. leading /
sprintf(wpline, "/list_%03d.wpl", place);
 
UART1_PutString("\n\r Read ");
UART1_PutString(wpline);
UART1_PutString("...");
 
if(Fat16_IsValid())
{ // check if wpl file is existing
fp = fopen_(wpline, 'r'); // try to open the file
if(fp == NULL)
{
UART1_PutString("ERROR: Reading waypoint file!\r\n");
return(0);
}
// clear point list first
PointList_Clear();
// read all lines from file
while(fgets_(wpline, LINE_MAX, fp) != 0)
{
if ( // ignorelines starting with \r,\n,' ',';','#'
(wpline[0] != '\n') &&
(wpline[0] != '\r') &&
(wpline[0] != ' ' ) &&
(wpline[0] != ';' ) &&
(wpline[0] != '#' )
)
{
// check for section line found
if(wpline[0] == '[')
{
// next section found
IsGeneralSection = 0;
IsPointSection = 0;
 
name = strtok(&wpline[1], "]");
if(name != NULL) // if section name
{
// check section type
for(i=0; name[i]; i++) name[i] = toupper(name[i]); // convert to upper case
 
if(strncmp(name, "POINT", 5) == 0)
{
IsPointSection = (u8)atoi(&name[5]);
PointCount++;
}
else if(strcmp(name, "GENERAL") == 0)
{
IsGeneralSection = 1;
}
else
{
UART1_PutString("Unknown section: ");
UART1_PutString(name);
UART1_PutString("\r\n");
}
}
} // EOF section line
else
{ // look for key entrys of each sections
name = strtok(wpline, "="); // get name
value = strtok(NULL, "="); // get value
if ((name != NULL) && (value != NULL))
{
for(i=0; name[i]; i++) name[i] = toupper(name[i]); // convert to upper case
if(IsPointSection && (IsPointSection <= WPNumber))
{
if(strcmp(name, "LATITUDE") == 0)
{
PointList[IsPointSection-1].Position.Latitude = (s32)(atof(value) * 1E7);
}
else if(strcmp(name, "LONGITUDE") == 0)
{
PointList[IsPointSection-1].Position.Longitude = (s32)(atof(value) * 1E7);
}
else if(strcmp(name, "RADIUS") == 0)
{
PointList[IsPointSection-1].ToleranceRadius = (u8)atoi(value);
}
else if(strcmp(name, "ALTITUDE") == 0)
{
PointList[IsPointSection-1].Position.Altitude = (s32)(atof(value) * 100.0); // in cm
PointList[IsPointSection-1].Position.Status = NEWDATA;
}
else if(strcmp(name, "CLIMBRATE") == 0)
{
PointList[IsPointSection-1].AltitudeRate = (u8)atoi(value);
}
else if(strcmp(name, "DELAYTIME") == 0)
{
PointList[IsPointSection-1].HoldTime = (u8)atoi(value);
}
else if(strcmp(name, "WP_EVENT_CHANNEL_VALUE") == 0)
{
PointList[IsPointSection-1].WP_EventChannelValue = (u8)atoi(value);
}
else if(strcmp(name, "HEADING") == 0)
{
PointList[IsPointSection-1].Heading = (s16)atoi(value);
}
else if(strcmp(name, "SPEED") == 0)
{
PointList[IsPointSection-1].Speed = (u8)atoi(value);
}
else if(strcmp(name, "CAM-NICK") == 0)
{
PointList[IsPointSection-1].CamAngle = (u8)atoi(value);
}
else if(strcmp(name, "TYPE") == 0)
{
PointList[IsPointSection-1].Type = (u8)atoi(value);
if(PointList[IsPointSection-1].Type > 0) PointList[IsPointSection-1].Type--; // index shift
else PointList[IsPointSection-1].Type = POINT_TYPE_INVALID;
switch(PointList[IsPointSection-1].Type)
{
case POINT_TYPE_WP:
// this works only if altitude key is set before point type key in WPL file !!
PointList[IsPointSection-1].Position.Altitude /= 10; // dm only for WPs
WPCount++;
break;
 
case POINT_TYPE_POI:
POICount++;
break;
}
}
else if(strcmp(name, "PREFIX") == 0)
{
strncpy(PointList[IsPointSection-1].Name, value, 4);
PointList[IsPointSection-1].Name[3] = 0; // Terminate string
}
else
{
UART1_PutString("Unknown key: ");
UART1_PutString(name);
UART1_PutString("\r\n");
}
} // EOF point section
else if(IsGeneralSection)
{
if(strcmp(name, "NUMBEROFWAYPOINTS") == 0)
{
WPNumber = (u8)atoi(value);
if(!WPNumber) // no waypoints in file
{
return(1); // we are done here
}
else if(WPNumber > MAX_LIST_LEN) // number o points larger than ram list
{
UART1_PutString("To much points!");
return(0);
}
}
else if (strcmp(name, "FILEVERSION") == 0)
{
if((u8)atoi(value) != WP_FILE_VERSION_COMPATIBLE)
{
UART1_PutString("Bad file version!\r\n");
return(0);
}
}
else
{
UART1_PutString("Unknown key: ");
UART1_PutString(name);
UART1_PutString("\r\n");
}
} // EOF general section
} // EOF valid key entry
} // EOF key entry line
} // valid line
} // EOF loop over all lines
fclose_(fp);
NaviData.WaypointNumber = WPCount;
UART1_PutString("ok\r\n");
retval = 1;
} // EOF if(Fat16_IsValid())
else UART1_PutString("no file system found!\r\n");
return(retval);
}
 
/trunk/waypoints.h
44,6 → 44,10
void PointList_WPActive(u8 set);
// returns pointer to actual POI
Point_t* PointList_GetPOI(void);
// save actual point list to SD card
u8 PointList_SaveToFile(u8 place);
// load actual point list from SD card
u8 PointList_ReadFromFile(u8 place);
 
 
#endif // _WAYPOINTS_H