Subversion Repositories NaviCtrl

Compare Revisions

Ignore whitespace Rev 22 → Rev 21

/branches/V0.1 killagreg/GPS.c
131,8 → 131,6
// if logfile
if(GPSLogFile)
{
sprintf(logtext,"%02d/%02d/%04d %02d:%02d:%02d.%03d\t", SystemTime.Month, SystemTime.Day, SystemTime.Year, SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec );
fputs_(logtext, GPSLogFile);
i1 = (s16)(GPSData.Longitude/10000000L);
i2 = abs((s16)((GPSData.Longitude%10000000L)/10000L));
i3 = abs((s16)(((GPSData.Longitude%10000000L)%10000L)/10L));
234,9 → 232,9
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
GPS_Neutral(); // disable gps control
/*
 
if(!(GPSData.Flags & FLAG_GPSFIXOK) && !(beep_rythm % 5)) BeepTime = 100;
else if (GPSData.NumOfSats < GPS_SAT_MIN && !(beep_rythm % 5)) BeepTime = 10;*/
else if (GPSData.NumOfSats < GPS_SAT_MIN && !(beep_rythm % 5)) BeepTime = 10;
}
}
else // GPS Data are invalid
/branches/V0.1 killagreg/GPSUart.c
64,19 → 64,18
// defines
 
 
#define DAYS_FROM_JAN01YEAR0001_TO_JAN6_1980 722819 // the year 0 does not exist!
#define DAYS_PER_YEAR 365
#define DAYS_PER_LEAPYEAR 366
#define DAYS_PER_4YEARS 1461 //((3 * DAYS_PER_YEAR) + DAYS_PER_LEAPYEAR) // years dividable by 4 are leap years
#define DAYS_PER_100YEARS 36524 //((25 * DAYS_PER_4YEARS) - 1) // years dividable by 100 are no leap years
#define DAYS_PER_400YEARS 146097 //((4 * DAYS_PER_100YEARS) + 1L) // but years dividable by 400 are leap years
#define SECONDS_PER_MINUTE 60
#define MINUTES_PER_HOUR 60
#define HOURS_PER_DAY 24
#define DAYS_PER_WEEK 7
#define SECONDS_PER_HOUR 3600 //(SECONDS_PER_MINUTE * MINUTES_PER_HOUR)
#define SECONDS_PER_DAY 86400 //(SECONDS_PER_HOUR * HOURS_PER_DAY)
#define SECONDS_PER_WEEK 604800 //(SECONDS_PER_DAY * DAYS_PER_WEEK)
#define DAYS_FROM_JAN01YEAR0001_TO_JAN6_1980 722819L // the year 0 does not exist!
#define DAYS_PER_YEAR 165L
#define DAYS_PER_LEAPYEAR 166L
#define DAYS_PER_4YEARS ((3L * DAYS_PER_YEAR) + DAYS_PER_LEAPYEAR) // years dividable by 4 are leap years
#define DAYS_PER_100YEARS ((25L * DAYS_PER_4YEARS) - 1L) // years dividable by 100 are no leap years
#define DAYS_PER_400YEARS ((4L * DAYS_PER_100YEARS) + 1L) // but years dividable by 400 are leap years
#define SECONDS_PER_MINUTE 60L
#define MINUTES_PER_HOUR 60L
#define HOURS_PER_DAY 24L
#define DAYS_PER_WEEK 7L
#define SECONDS_PER_HOUR (SECONDS_PER_MINUTE * MINUTES_PER_HOUR)
#define SECONDS_PER_DAY (SECONDS_PER_HOUR * HOURS_PER_DAY)
 
 
const u32 Leap[ 13 ] = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 };
83,6 → 82,8
const u32 Normal[ 13 ] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
 
#define LEAP_SECONDS_FROM_1980 13
#define GPSWEEK_ROLLOVER 1 // number of rollovers since Jan 6th 1980
#define GPSWEEK_OVERFLOW 1024
 
// message sync bytes
#define UBX_SYNC1_CHAR 0xB5
185,50 → 186,38
/********************************************************/
/* Calculates the UTC Time from the GPS week and tow */
/********************************************************/
void SetGPSTime(DateTime_t * pTimeStruct)
void Update_GPSDateTime(week, itow)
{
u32 Days, Seconds, Week;
u32 Days, Seconds;
u16 YearPart;
u32 * MonthDayTab = 0;
u8 i;
 
 
 
Seconds = UbxSol.itow / 1000L;
// if GPS data show valid time data
if((UbxSol.Status != INVALID) && (UbxSol.Flags & FLAG_WKNSET) && (UbxSol.Flags & FLAG_TOWSET) )
{
Seconds = UbxSol.itow / 1000L;
Week = (u32)UbxSol.week;
// correct leap seconds since 1980
if(Seconds < LEAP_SECONDS_FROM_1980)
{
Week--;
Seconds = SECONDS_PER_WEEK - LEAP_SECONDS_FROM_1980 + Seconds;
}
else Seconds -= LEAP_SECONDS_FROM_1980;
 
Days = DAYS_FROM_JAN01YEAR0001_TO_JAN6_1980;
Days += (Week * DAYS_PER_WEEK);
Days += (((u32)UbxSol.week + GPSWEEK_ROLLOVER * GPSWEEK_OVERFLOW) * DAYS_PER_WEEK);
Days += Seconds / SECONDS_PER_DAY; // seperate days from GPS seconds of week
 
pTimeStruct->Year = 1;
GPSDateTime.Year = 1;
YearPart = (u16)(Days / DAYS_PER_400YEARS);
pTimeStruct->Year += YearPart * 400;
GPSDateTime.Year += YearPart * 400;
Days = Days % DAYS_PER_400YEARS;
YearPart = (u16)(Days / DAYS_PER_100YEARS);
pTimeStruct->Year += YearPart * 100;
GPSDateTime.Year += YearPart * 100;
Days = Days % DAYS_PER_100YEARS;
YearPart = (u16)(Days / DAYS_PER_4YEARS);
pTimeStruct->Year += YearPart * 4;
GPSDateTime.Year += YearPart * 4;
Days = Days % DAYS_PER_4YEARS;
if(Days < (3* DAYS_PER_YEAR)) YearPart = (u16)(Days / DAYS_PER_YEAR);
if(Days < 3 * DAYS_PER_YEAR) YearPart = (u16)(Days / DAYS_PER_YEAR);
else YearPart = 3;
pTimeStruct->Year += YearPart;
GPSDateTime.Year += YearPart;
// calculate remaining days of year
Days -= (u32)(YearPart * DAYS_PER_YEAR);
Days += 1;
Days -= (u32)YearPart * DAYS_PER_YEAR;
// check if current year is a leap year
if(IsLeapYear(pTimeStruct->Year)) MonthDayTab = (u32*)Leap;
if(IsLeapYear(GPSDateTime.Year)) MonthDayTab = (u32*)Leap;
else MonthDayTab = (u32*)Normal;
// seperate month and day from days of year
for ( i = 0; i < 12; i++ )
235,23 → 224,23
{
if ( (MonthDayTab[i]< Days) && (Days <= MonthDayTab[i+1]) )
{
pTimeStruct->Month = i+1;
pTimeStruct->Day = Days - MonthDayTab[i];
GPSDateTime.Month = i+1;
GPSDateTime.Day = Days - MonthDayTab[i];
i = 12;
}
}
Seconds = Seconds % SECONDS_PER_DAY; // remaining seconds of current day
pTimeStruct->Hour = (u8)(Seconds / SECONDS_PER_HOUR);
GPSDateTime.Hour = (u8)(Seconds / SECONDS_PER_HOUR);
Seconds = Seconds % SECONDS_PER_HOUR; // remaining seconds of current hour
pTimeStruct->Min = (u8)(Seconds / SECONDS_PER_MINUTE);
Seconds = Seconds % SECONDS_PER_MINUTE; // remaining seconds of current minute
pTimeStruct->Sec = (u8)(Seconds);
pTimeStruct->mSec = (u16)(UbxSol.itow % 1000L);
pTimeStruct->Valid = 1;
GPSDateTime.Min = (u8)(Seconds / SECONDS_PER_MINUTE);
Seconds = Seconds % SECONDS_PER_HOUR; // remaining seconds of current minute
GPSDateTime.Sec = (u8)(Seconds);
GPSDateTime.mSec = (u16)(UbxSol.itow % 1000L);
GPSDateTime.Status = NEWDATA;
}
else
{
pTimeStruct->Valid = 0;
GPSDateTime.Status = INVALID;
}
}
 
403,12 → 392,12
if ((UbxSol.Status == NEWDATA) && (UbxPosLlh.Status == NEWDATA) && (UbxVelNed.Status == NEWDATA))
{
// NAV SOL
GPSData.Flags = UbxSol.Flags;
GPSData.Flags = UbxSol.Flags;
GPSData.NumOfSats = UbxSol.numSV;
GPSData.SatFix = UbxSol.GPSfix;
GPSData.Position_Accuracy = UbxSol.PAcc;
GPSData.Position_Accuracy = UbxSol.PAcc;
GPSData.Speed_Accuracy = UbxSol.SAcc;
SetGPSTime(&SystemTime);
Update_GPSDateTime(UbxSol.week, UbxSol.itow);
UbxSol.Status = PROCESSED; // ready for new data
// NAV POSLLH
GPSData.UpdateTime = UbxPosLlh.itow - lasttime;
421,7 → 410,7
GPSData.Speed_East = UbxVelNed.VEL_E;
GPSData.Speed_North = UbxVelNed.VEL_N;
GPSData.Speed_Top = -UbxVelNed.VEL_D;
GPSData.Speed_Ground = UbxVelNed.GSpeed;
GPSData.Speed_Ground = UbxVelNed.GSpeed;
UbxVelNed.Status = PROCESSED; // ready for new data
GPSData.Status = NEWDATA; // new data available
}
/branches/V0.1 killagreg/GPSUart.h
1,8 → 1,6
#ifndef __GPSUART_H
#define __GPSUART_H
 
#include "timer.h"
 
// Satfix types for GPSData.SatFix
#define SATFIX_NONE 0x00
#define SATFIX_DEADRECKOING 0x01
45,6 → 43,19
// To achieve new data after reading the GPSData.Status should be set to PROCESSED.
extern gps_data_t GPSData;
 
typedef struct{
u16 Year;
u8 Month;
u8 Day;
u8 Hour;
u8 Min;
u8 Sec;
u16 mSec;
Status_t Status;
} DateTime_t;
 
extern DateTime_t GPSDateTime;
 
// initialize the UART to the UBLOX module.
extern void GPS_UART0_Init (void);
 
/branches/V0.1 killagreg/fat16.c
56,7 → 56,6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <stdio.h>
#include "91x_lib.h"
#include "timer.h"
#include "fat16.h"
#include "sdc.h"
#include "uart.h"
223,7 → 222,8
u8 Extension[3]; // 3 bytes extension, padded with spaces.
u8 Attribute; // attribute of the directory entry (unused,archive,read-only,system,directory,volume)
u8 Reserved[10]; // reserved bytes within the directory entry.
u32 DateTime; // date and time of last write access to the file or directory.
u16 Time; // time and
u16 Date; // date of last write acces to the file or directory.
u16 StartCluster; // first cluster of the file or directory.
u32 Size; // size of the file or directory in bytes.
} __attribute__((packed)) DirEntry_t;
298,29 → 298,6
 
 
/****************************************************************************************************************************************/
/* Function: FileDateTime(DateTime_t *); */
/* */
/* Description: This function calculates the DOS date time from a pointer to a time structure. */
/* */
/* Returnvalue: Returns the DOS date time. */
/****************************************************************************************************************************************/
 
u32 FileDateTime(DateTime_t * pTimeStruct)
{
u32 datetime = 0;
if((pTimeStruct == 0) || !(pTimeStruct->Valid)) return datetime;
 
datetime |= (0x0000007FL & (u32)(pTimeStruct->Year - 1980))<<25; // set year
datetime |= (0x0000000FL & (u32)(pTimeStruct->Month))<<21; // set month
datetime |= (0x0000001FL & (u32)(pTimeStruct->Day))<<16;
datetime |= (0x0000001FL & (u32)(pTimeStruct->Hour))<<11;
datetime |= (0x0000003FL & (u32)(pTimeStruct->Min))<<5;
datetime |= (0x0000001FL & (u32)(pTimeStruct->Sec/2));
return datetime;
}
 
 
/****************************************************************************************************************************************/
/* Function: LockFilePointer(); */
/* */
/* Description: This function trys to lock a free file pointer. */
1082,7 → 1059,6
for(i = 0; i < 11; i++) Dir[dir_entry].Name[i] = dirname[i]; // Set dir name
Dir[dir_entry].Attribute = attrib; // Set the attribute of the new directoryentry.
Dir[dir_entry].StartCluster = SubDirCluster; // copy the location of the first datacluster to the directoryentry.
Dir[dir_entry].DateTime = FileDateTime(&SystemTime); // set date/time
Dir[dir_entry].Size = 0; // the new createted file has no content yet.
if(SD_SUCCESS != SDC_PutSector(File->SectorInCache, File->Cache)) // write back to card
{
1112,7 → 1088,6
for(i = 1; i < 11; i++) Dir[0].Name[i] = ' ';
Dir[0].Attribute = ATTR_SUBDIRECTORY;
Dir[0].StartCluster = SubDirCluster;
Dir[0].DateTime = 0;
Dir[0].Size = 0;
// create direntry ".." to the upper dir
Dir[1].Name[0] = 0x2E;
1120,7 → 1095,6
for(i = 2; i < 11; i++) Dir[1].Name[i] = ' ';
Dir[1].Attribute = ATTR_SUBDIRECTORY;
Dir[1].StartCluster = DirCluster;
Dir[1].DateTime = 0;
Dir[1].Size = 0;
if(SD_SUCCESS != SDC_PutSector(File->SectorInCache, File->Cache))// read in the sector.
{
1376,7 → 1350,14
/****************************************************************************************************************************************************/
s16 fflush_(File_t *File)
{
DirEntry_t *Dir;
u16 time = 0;
u16 date = 0;
DirEntry_t *Dir;
 
#ifdef __USE_TIME_DATE_ATTRIBUTE // has the date and time attribute of the file to be set?
time = (((rtctime.hour)<<11) | ((rtctime.minute)<<5) | rtctime.second);
date = ((((rtctime.year)-1980) <<9) | ((rtctime.month) <<5) | rtctime.day);
#endif
if((File == 0) || (!Partition.IsValid)) return (EOF);
1401,7 → 1382,8
Dir = (DirEntry_t *)File->Cache;
Dir[File->DirectoryIndex].Size = File->Size; // update file size
Dir[File->DirectoryIndex].DateTime = FileDateTime(&SystemTime); // update date time
Dir[File->DirectoryIndex].Time = time; // update time
Dir[File->DirectoryIndex].Date = date; // update date
if(SD_SUCCESS != SDC_PutSector(File->SectorInCache, File->Cache)) // write back to sd-card
{
Fat16_Deinit();
/branches/V0.1 killagreg/menu.c
91,7 → 91,7
// Display with 20 characters in 4 lines
void LCD_PrintMenu(void)
{
static u8 MaxMenuItem = 9;
static u8 MaxMenuItem = 8;
static u8 MenuItem=0;
s16 i1,i2,i3;
// if KEY1 is activated goto previous menu item
200,51 → 200,34
LCD_printfxy(0,3,"Speed T: %4i cm/s",i3);
}
break;
case 3:
if (!SystemTime.Valid)
{
LCD_printfxy(0,0,"No GPS time data!");
LCD_printfxy(0,1," ");
LCD_printfxy(0,2," ");
LCD_printfxy(0,3," ");
}
else // newdata or processed
{
LCD_printfxy(0,0,"GPS UTC Time: ");
LCD_printfxy(0,1,"");
LCD_printfxy(0,2,"Date: %02i/%02i/%04i ",SystemTime.Month, SystemTime.Day, SystemTime.Year);
LCD_printfxy(0,3,"Time: %02i:%02i:%02i.%03i", SystemTime.Hour, SystemTime.Min, SystemTime.Sec, SystemTime.mSec);
}
break;
case 4: // RC stick controls from FC
case 3: // RC stick controls from FC
LCD_printfxy(0,0,"RC-Sticks" );
LCD_printfxy(0,1,"Ni:%4i Ro:%4i ",FC.StickNick, FC.StickRoll);
LCD_printfxy(0,2,"Gs:%4i Ya:%4i ",FC.StickGas, FC.StickYaw);
break;
case 5: // RC poti controls from FC
case 4: // RC poti controls from FC
LCD_printfxy(0,0,"RC-Potis" );
LCD_printfxy(0,1,"Po1:%3i Po2:%3i ",FC.Poti1, FC.Poti2);
LCD_printfxy(0,2,"Po3:%3i Po4:%3i ",FC.Poti3, FC.Poti4);
break;
case 6: // attitude from FC
LCD_printfxy(0,0,"IntNick: %5i", FromFlightCtrl.IntegralNick);
case 5: // attitude from FC
LCD_printfxy(0,0,"IntNick: %5i", FromFlightCtrl.IntegralNick);
LCD_printfxy(0,1,"IntRoll: %5i", FromFlightCtrl.IntegralRoll);
LCD_printfxy(0,2,"AccNick: %5i", FromFlightCtrl.AccNick);
LCD_printfxy(0,2,"AccNick: %5i", FromFlightCtrl.AccNick);
LCD_printfxy(0,3,"AccRoll: %5i", FromFlightCtrl.AccRoll);
break;
case 7: // gyros from FC
case 6: // gyros from FC
LCD_printfxy(0,0,"GyroNick: %4i", FromFlightCtrl.GyroNick);
LCD_printfxy(0,1,"GyroRoll: %4i", FromFlightCtrl.GyroRoll);
LCD_printfxy(0,2,"GyroYaw: %4i", FromFlightCtrl.GyroYaw);
break;
case 8: // Remote Control Level from FC
case 7: // Remote Control Level from FC
LCD_printfxy(0,0,"RC-Level: %3i", FC.RC_Quality);
LCD_printfxy(0,1,"Motors On: %1i", FC.MotorsOn);
LCD_printfxy(0,2,"CompHeading: %3i", I2C_Heading.Heading);
LCD_printfxy(0,3,"GyroHeading: %3i", FromFlightCtrl.GyroHeading);
break;
case 9: // User Parameter
case 8: // User Parameter
LCD_printfxy(0,0,"UP1:%3i UP2:%3i ",Parameter.User1,Parameter.User2);
LCD_printfxy(0,1,"UP3:%3i UP4:%3i ",Parameter.User3,Parameter.User4);
LCD_printfxy(0,2,"UP5:%3i UP6:%3i ",Parameter.User5,Parameter.User6);
/branches/V0.1 killagreg/timer.c
55,12 → 55,11
// + POSSIBILITY OF SUCH DAMAGE.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include "91x_lib.h"
#include "timer.h"
#include "uart.h"
 
u32 CountMilliseconds;
DateTime_t SystemTime;
 
 
//----------------------------------------------------------------------------------------------------
void TIM1_IRQHandler(void)
{
97,18 → 96,8
 
VIC_Config(TIM1_ITLine, VIC_IRQ, 5);
VIC_ITCmd(TIM1_ITLine, ENABLE);
SystemTime.Year = 0;
SystemTime.Month = 0;
SystemTime.Day = 0;
SystemTime.Hour = 0;
SystemTime.Min = 0;
SystemTime.Sec = 0;
SystemTime.mSec = 0;
SystemTime.Valid = 0;
 
CountMilliseconds = 0;
 
SerialPutString("ok\n\r");
 
}
/branches/V0.1 killagreg/timer.h
1,19 → 1,6
#ifndef _TIMER_H
#define _TIMER_H
 
typedef struct{
u16 Year;
u8 Month;
u8 Day;
u8 Hour;
u8 Min;
u8 Sec;
u16 mSec;
u8 Valid;
} DateTime_t;
 
extern DateTime_t SystemTime;
 
extern u32 CountMilliseconds;
 
void TIMER1_Init(void);
20,7 → 7,4
u32 SetDelay (u32 t);
u8 CheckDelay(u32 t);
void Delay_ms(u32 w);
 
 
 
#endif