/branches/V0.1 killagreg/GPS.c |
---|
35,11 → 35,11 |
typedef struct |
{ |
s32 North; |
s32 East; |
s32 Bearing; |
s32 Distance; |
} __attribute__((packed)) GPS_Deviation_t; |
s32 North; // in cm |
s32 East; // in cm |
s32 Bearing; // in deg |
s32 Distance; // in cm |
} __attribute__((packed)) GPS_Deviation_t; |
GPS_Stick_t GPS_Stick; |
GPS_Parameter_t GPS_Parameter; |
183,7 → 183,7 |
{ |
s32 bearing; |
bearing = (s32)(atan2(northdev, eastdev) / M_PI_180); |
bearing = (270 - bearing)%360; |
bearing = (270L - bearing)%360L; |
return(bearing); |
} |
/branches/V0.1 killagreg/Navi-Ctrl.Uv2 |
---|
72,8 → 72,8 |
File 4,1,<.\libstr91x\src\91x_wiu.c><91x_wiu.c> |
File 6,1,<.\usblibrary\src\usb_regs.c><usb_regs.c> |
File 6,1,<.\usblibrary\src\usb_core.c><usb_core.c> |
File 6,1,<.\usblibrary\src\usb_int.c><usb_int.c> |
File 6,1,<.\usblibrary\src\usb_init.c><usb_init.c> |
File 6,1,<.\usblibrary\src\usb_int.c><usb_int.c> |
File 6,1,<.\usblibrary\src\usb_mem.c><usb_mem.c> |
File 6,5,<.\usbinc\usb_pwr.h><usb_pwr.h> |
File 6,5,<.\usbinc\hw_config.h><hw_config.h> |
/branches/V0.1 killagreg/fat16.c |
---|
197,7 → 197,7 |
u16 BytesPerSector; // Bytes Per Sector |
u8 SectorsPerCluster; // Sectors Per Cluster |
u16 ReservedSectors; // Reserved Sectors |
u8 NoFATCopies; // Nuber of Copies of FAT |
u8 NoFATCopies; // Number of Copies of FAT |
u16 MaxRootEntries; // Maximum Root Directory Entries |
u16 NoSectorsInPartSml32MB; // Number of Sectors in Partition Smaller than 32 MB |
u8 MediaDescriptor; // Media Descriptor (0xF8 for Hard Disks) |
393,19 → 393,19 |
/* into the needed format ('test.txt' -> 'TEST TXT') */ |
/* The subpath is the pointer to the remaining substring if the filepath */ |
/* */ |
/* Returnvalue: Return 0 on error or pointer to subpath */ |
/* Returnvalue: Return NULL on error or pointer to subpath */ |
/****************************************************************************************************************************************/ |
s8* SeperateDirName(const s8 *filepath, s8 *dirname) |
{ |
s8* subpath = 0; |
s8* subpath = NULL; |
u8 readpointer = 0; |
u8 writepointer = 0; |
// search subpath from beginning of filepath |
subpath = 0; |
subpath = NULL; |
readpointer = 0; |
if(filepath[0] == '/') readpointer = 1; // ignore first '/' |
while(!subpath) // search the filepath until a subpath was found. |
while(subpath == NULL) // search the filepath until a subpath was found. |
{ |
if(((filepath[readpointer] == 0) || (filepath[readpointer] == '/'))) // if '/' found or end of filepath reached |
{ |
423,7 → 423,7 |
if(filepath[0] == '/') readpointer = 1; // ignore first '/' |
while( &filepath[readpointer] < subpath) |
{ |
if(writepointer >= 11) return 0; // dirname to long |
if(writepointer >= 11) return(NULL); // dirname to long |
if(filepath[readpointer] == '.') // seperating dirname and extension. |
{ |
if(writepointer <= 8) |
431,7 → 431,7 |
readpointer++; // next character in filename |
writepointer = 8; // jump to start of extension |
} |
else return (0); // dirbasename to long |
else return(NULL); // dirbasename to long |
} |
else |
{ |
447,7 → 447,7 |
writepointer++; |
} |
} |
return (subpath); |
return(subpath); |
} |
523,7 → 523,6 |
File_t *file; |
u8 result = 0; |
SerialPutString("\r\n FAT16 init..."); |
Partition.IsValid = 0; |
1219,7 → 1218,7 |
/********************************************************************************************************************************************/ |
/* Function: FileExist(const s8* filename, u8 attribfilter, u8 attribmask, File_t *file); */ |
/* */ |
/* Description: This function looks for the specified filemincluding its subdirectories beginning */ |
/* Description: This function looks for the specified file including its subdirectories beginning */ |
/* in the rootdirectory of the drive. If the file is found the Filepointer properties are */ |
/* updated. */ |
/* */ |
1230,7 → 1229,7 |
s8* path = 0; |
s8* subpath = 0; |
u8 af, am, file_exist = 0; |
s8 dirname[12]; |
s8 dirname[12]; // 8+3 + temination character |
// if incomming pointers are useless return immediatly |
if ((filename == 0) || (file == NULL) || (!Partition.IsValid)) return 0; |
1242,7 → 1241,8 |
// as long as the file was not found and the remaining path is not empty |
while((*path != 0) && !file_exist) |
{ // separate dirname and subpath from filepath string |
if(subpath != 0) |
subpath = SeperateDirName(path, dirname); |
if(subpath != NULL) |
{ |
if(*subpath == 0) |
{ // empty subpath indicates last element of dir chain |
1303,7 → 1303,8 |
// as long as the file was not created and the remaining file path is not empty |
while((*path != 0) && !file_created) |
{ // separate dirname and subpath from filepath string |
if(subpath != 0) |
subpath = SeperateDirName(path, dirname); |
if(subpath != NULL) |
{ |
if(*subpath == 0) |
{ // empty subpath indicates last element of dir chain |
/branches/V0.1 killagreg/kml.c |
---|
313,11 → 313,11 |
s32 i1, i2; |
i1 = GPSData.Longitude/10000000L; |
i2 = abs(GPSData.Longitude%10000000L); |
sprintf(string,"\r\n%+3ld.%07ld,",i1, i2); |
sprintf(string,"\r\n%ld.%07ld,",i1, i2); |
fputs_(string, doc->file); |
i1 = GPSData.Latitude/10000000L; |
i2 = abs(GPSData.Latitude%10000000L); |
sprintf(string," +%3ld.%07ld,",i1, i2); |
sprintf(string," +%ld.%07ld,",i1, i2); |
fputs_(string, doc->file); |
i1 = GPSData.Altitude/1000L; |
i2 = abs(GPSData.Altitude%1000L); |
/branches/V0.1 killagreg/kml_header.h |
---|
47,7 → 47,7 |
const s8 KML_PLACEMARK_HEADER[] = |
{ |
"<Placemark>\r\n" |
"<name>flight</name>\r\n" |
"<name>Flight</name>\r\n" |
"<styleUrl>#MK_gps-style</styleUrl>\r\n" |
}; |
/branches/V0.1 killagreg/main.c |
---|
133,11 → 133,12 |
KML_Document_t gpslogfile; |
u16 gpslogfilenum = 0; |
s8 gpslogfilename[13]; |
/* Configure the system clocks */ |
SCU_Config(); |
KML_DocumentInit(&gpslogfile); // Initialize the new kml-document for further use. |
sprintf(gpslogfilename, "gps%05i.klm", gpslogfilenum); // initialize gps logfile name |
sprintf(gpslogfilename, "gps%05i.kml", gpslogfilenum); // initialize gps logfile name |
/* Fill Version Info Structure */ |
172,7 → 173,7 |
GPS_Init(); |
// initialize fat16 partition on sd card (needs Timer 1) |
Fat16_Init(); |
// get version from MK3MAG |
I2C_Version.Major = 0xFF; |
I2C_Version.Minor = 0xFF; |
235,7 → 236,7 |
// ---------------- KML Timing ------------------------------------ |
if(CheckDelay(TimerKmlAddPointDelay)) |
{ |
TimerKmlAddPointDelay = SetDelay(500); |
TimerKmlAddPointDelay = SetDelay(500); // every 500 ms |
if(FC.MKFlags & MKFLAG_FLY) // model is flying |
{ |
243,56 → 244,57 |
{ |
case LOGFILE_IDLE: |
case LOGFILE_CLOSED: |
// find unused logfile name |
while(fexist_(gpslogfilename)) |
{ // generate new logfile name |
gpslogfilenum++; |
sprintf(gpslogfilename, "gps%05i.klm", gpslogfilenum); |
} |
// try to create the log file |
if(KML_DocumentOpen(gpslogfilename,&gpslogfile)) |
{ |
SerialPutString("\r\nopening kml-file\r\nadding data"); |
logfilestate = LOGFILE_OPENED; // goto next step |
} |
else |
{ |
logfilestate = LOGFILE_ERROR; |
SerialPutString("\r\nError opening kml-file"); |
TimerKmlAddPointDelay = SetDelay(10); // try again in open logfile in 10 mili sec |
} |
break; |
// find unused logfile name |
while(fexist_(gpslogfilename)) |
{ // generate new logfile name |
gpslogfilenum++; |
sprintf(gpslogfilename, "gps%05i.kml", gpslogfilenum); |
} |
// try to create the log file |
if(KML_DocumentOpen(gpslogfilename, &gpslogfile)) |
{ |
SerialPutString("\r\nOpening kml-file\r\n"); |
logfilestate = LOGFILE_OPENED; // goto next step |
} |
else |
{ |
logfilestate = LOGFILE_ERROR; |
SerialPutString("\r\nError opening kml-file\r\n"); |
TimerKmlAddPointDelay = SetDelay(10); // try again in open logfile in 10 mili sec |
} |
break; |
case LOGFILE_OPENED: |
// append new gps log data |
if((GPSData.Status != INVALID) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)) |
{ |
if(!KML_LoggGPSCoordinates(&GPSData, &gpslogfile)) |
{ // error logging data |
KML_DocumentClose(&gpslogfile); |
logfilestate = LOGFILE_ERROR; |
// append new gps log data |
if((GPSData.Status != INVALID) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D)) |
{ |
if(!KML_LoggGPSCoordinates(&GPSData, &gpslogfile)) |
{ // error logging data |
SerialPutString("\r\nError Logging GPS data\r\n"); |
KML_DocumentClose(&gpslogfile); |
logfilestate = LOGFILE_ERROR; |
} |
} |
} |
break; |
case LOGFILE_ERROR: |
// try to reinitialize the fat16 filesystem |
if(0 == Fat16_Init()) |
{ |
logfilestate = LOGFILE_IDLE; |
TimerKmlAddPointDelay = SetDelay(10); // try again in open logfile in 10 mili sec |
} |
else |
{ |
logfilestate = LOGFILE_ERROR; |
TimerKmlAddPointDelay = SetDelay(5000); // try again in 5 sec |
} |
break; |
// try to reinitialize the fat16 filesystem |
if(0 == Fat16_Init()) |
{ |
logfilestate = LOGFILE_IDLE; |
TimerKmlAddPointDelay = SetDelay(10); // try again in open logfile in 10 mili sec |
} |
else |
{ |
logfilestate = LOGFILE_ERROR; |
TimerKmlAddPointDelay = SetDelay(5000); // try again in 5 sec |
} |
break; |
default: |
break; |
break; |
} |
} // EOF model is flying |
else // model is not flying |
301,6 → 303,7 |
{ |
if(KML_DocumentClose(&gpslogfile)) |
{ |
SerialPutString("\r\nClosing kml-file\r\n"); |
logfilestate = LOGFILE_CLOSED; |
} |
else |
/branches/V0.1 killagreg/ubx.c |
---|
77,7 → 77,7 |
#define SECONDS_PER_DAY 86400 //(SECONDS_PER_HOUR * HOURS_PER_DAY) |
#define SECONDS_PER_WEEK 604800 //(SECONDS_PER_DAY * DAYS_PER_WEEK) |
// days per month in normal and leap years |
const u32 Leap[ 13 ] = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }; |
const u32 Normal[ 13 ] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }; |
167,11 → 167,11 |
// local buffers for the incomming ubx messages |
volatile ubx_nav_sol_t UbxSol = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, INVALID}; |
volatile ubx_nav_posllh_t UbxPosLlh = {0,0,0,0,0,0,0, INVALID}; |
volatile ubx_nav_velned_t UbxVelNed = {0,0,0,0,0,0,0,0,0, INVALID}; |
volatile ubx_nav_posllh_t UbxPosLlh = {0,0,0,0,0,0,0, INVALID}; |
volatile ubx_nav_velned_t UbxVelNed = {0,0,0,0,0,0,0,0,0, INVALID}; |
// shared buffer |
volatile gps_data_t GPSData = {0,0,0,0,0,0,0,0,0,0, INVALID}; |
gps_data_t GPSData = {0,0,0,0,0,0,0,0,0,0, INVALID}; |
DateTime_t GPSDateTime = {0,0,0,0,0,0,0, INVALID}; |
315,6 → 315,7 |
GPSData.Speed_North = UbxVelNed.VEL_N; |
GPSData.Speed_Top = -UbxVelNed.VEL_D; |
GPSData.Speed_Ground = UbxVelNed.GSpeed; |
GPSData.Heading = UbxVelNed.Heading; |
GPSData.Status = NEWDATA; // new data available |
} // EOF if(GPSData.Status != NEWDATA) |
/branches/V0.1 killagreg/ubx.h |
---|
34,6 → 34,7 |
s32 Speed_East; // in cm/s |
s32 Speed_Top; // in cm/s |
u32 Speed_Ground; // 2D ground speed in cm/s |
s32 Heading; // 1e-05 deg Heading 2-D (curent flight direction) |
u32 Speed_Accuracy; // in cm/s 3d velocity accuracy |
Status_t Status; // status of data |
} __attribute__((packed)) gps_data_t; |
40,7 → 41,7 |
// The data are valid if the GPSData.Status is NEWDATA or PROCESSED. |
// To achieve new data after reading the GPSData.Status should be set to PROCESSED. |
extern volatile gps_data_t GPSData; |
extern gps_data_t GPSData; |
void UBX_Init(void); |
void UBX_Parser(u8 c); |
/branches/V0.1 killagreg/usb.c |
---|
114,9 → 114,9 |
u8 i = 0; |
u16 timeout = 0; |
while (StrPtr[i++] !=0){} |
while (StrPtr[i++] !=0){} // get string len |
while (_GetEPTxStatus(ENDP1) != EP_TX_NAK){ if (timeout++ > 60000) return;} |
UserToPMABufferCopy(StrPtr, ENDP1_TXADDR, ++i); |
UserToPMABufferCopy(StrPtr, ENDP1_TXADDR, ++i); // copy string to usb buffer |
SetEPTxCount(ENDP1,i); |
SetEPTxValid(ENDP1); |
} |
/branches/V0.1 killagreg/usb_endp.c |
---|
40,14 → 40,15 |
*******************************************************************************/ |
void EP3_OUT_Callback(void) |
{ |
//USB_BufferRxCount= GetEPRxCount(ENDP3); |
ReceivedBytes = GetEPRxCount(ENDP3); |
//PMAToUserBufferCopy(USB_BufferRx, ENDP3_RXADDR, AnzahlEmpfangsBytes ); |
PMAToUserBufferCopy((u8*) rxd_buffer, ENDP3_RXADDR, ReceivedBytes); |
rxd_buffer_locked = 1; |
//USB_BufferRx[AnzahlEmpfangsBytes] = 0; |
USB_BufferRxCount= GetEPRxCount(ENDP3); |
//ReceivedBytes = GetEPRxCount(ENDP3); |
PMAToUserBufferCopy(USB_BufferRx, ENDP3_RXADDR, USB_BufferRxCount ); |
//PMAToUserBufferCopy((u8*) rxd_buffer, ENDP3_RXADDR, ReceivedBytes); |
//rxd_buffer_locked = 1; |
USB_BufferRx[USB_BufferRxCount] = 0; // terminate buffer contents |
SetEPRxValid(ENDP3); |
sprintf(text,"USB (%d): %s\n\r", ReceivedBytes, rxd_buffer ); SerialPutString(text); |
sprintf(text,"USB (%ld): %s\n\r", USB_BufferRxCount, USB_BufferRx); |
SerialPutString(text); |
// USB_Send_Data(RxdBuffer, AnzahlEmpfangsBytes); |
// USB_Send_String("Rx.\0"); |