Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 2462 → Rev 2463

/I2C_Telemetry/trunk/uart.c
57,6 → 57,7
#include <util/delay_basic.h>
#include "main.h"
#include "uart.h"
#include "ubx.h"
#include "libtel.h"
#include "eeprom.h"
#include "ftphelper.h"
64,7 → 65,9
 
#define ABO_TIMEOUT 4000 // disable abo after 4 seconds
 
#define UART_MKGPS 2
 
 
#define BLPARAM_REVISION 1
#define MASK_SET_PWM_SCALING 0x01
#define MASK_SET_CURRENT_LIMIT 0x02
96,6 → 99,7
uint8_t Request_MotorTest = 0;
uint8_t DisplayLine = 0;
uint8_t DisplayKeys = 0;
uint8_t RedirectGPStoPC = 0;
 
uint8_t PcAccess = 100;
uint16_t AboTimeOut = 0;
108,6 → 112,8
struct str_DebugOut DebugOut;
struct str_VersionInfo UART_VersionInfo;
 
extern void UBXConfigSVInfo(uint8_t state);
 
uint16_t DebugData_Timer;
uint16_t Data3D_Timer;
uint16_t Display_Timer;
178,10 → 184,38
ISR(USART0_RX_vect)
{
uint8_t c;
static uint8_t abortState = 0;
 
c = UDR0;
MKProtocol_CollectSerialFrame(&UART0_rx_buffer, c); // ckeck for MK-Frame
UBX_Parser(c); // and check ubx protocol parser for gpx data
switch (abortState)
{
case 0:
if (c == 27) abortState++;
break;
case 1:
if (c == 27) abortState++;
else abortState = 0;
break;
case 2:
if (c == 0x55) abortState++;
else abortState = 0;
break;
case 3:
if (c == 0xAA) abortState++;
else abortState = 0;
break;
case 4:
if (c == 0x00)
{
RedirectGPStoPC = 0;
//UBXConfigSVInfo(0);
}
abortState = 0;
break;
} // end switch abort state
}
 
 
292,6 → 326,29
void USART0_ProcessRxData(void)
{
unsigned char tempchar1, tempchar2;
static unsigned char gpsinfo_count = 0;
unsigned char GPS_Packets[] = { UBX_ID_SOL, UBX_ID_POSLLH, UBX_ID_SVINFO, UBX_ID_POSLLH } ;
if(RedirectGPStoPC && UbxMsg.Status == NEWDATA)
{
DebugOut.Analog[2]++;
UART0_UBXSendMsg((uint8_t*)&UbxMsg.Hdr, UbxMsg.Hdr.Length);
UbxMsg.Hdr.Id = GPS_Packets[gpsinfo_count++];
if (gpsinfo_count >= sizeof(GPS_Packets)) gpsinfo_count = 0;
UbxMsg.Status = PROCESSED; // ready for new data
}
if(RedirectGPStoPC) return; // do not process more - just GPS info for MK-Tool
// check for new data frame
if(UART0_rx_buffer.Locked)
{
402,7 → 459,28
case 'v': // Version-Anforderung und Ausbaustufe
Request_VerInfo = 1;
break;
case 'u': // Umschaltung auf GPS (GPS-Daten werden zusätzlich zum PC übertragen
if (SerialMsg.pData[0] == UART_MKGPS)
{
Buffer_Clear(&UART0_rx_buffer);
UBXConfigSVInfo(2);
RedirectGPStoPC = 1;
UbxMsg.Hdr.Class = 0x01;
UbxMsg.ClassMask = 0xFF;
UbxMsg.IdMask = 0xFF;
UbxMsg.Hdr.Id = UBX_ID_SOL;
}
break;
 
 
default:
//unsupported command received
break;
/I2C_Telemetry/trunk/ubx.c
28,16 → 28,8
 
#define LEAP_SECONDS_FROM_1980 16
 
// message sync bytes
#define UBX_SYNC1_CHAR 0xB5
#define UBX_SYNC2_CHAR 0x62
// protocoll identifier
#define UBX_CLASS_NAV 0x01
// message id
#define UBX_ID_POSLLH 0x02
#define UBX_ID_SOL 0x06
#define UBX_ID_VELNED 0x12
 
 
// ------------------------------------------------------------------------------------------------
// typedefs
 
105,6 → 97,9
uint8_t Status; // invalid/newdata/processed
} __attribute__((packed)) ubx_nav_posllh_t;
 
 
 
 
//------------------------------------------------------------------------------------
// global variables
 
113,9 → 108,14
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 ubxmsg_t UbxMsg;
//volatile ubx_nav_svinfo_t UbxSVInfo;
 
 
 
void UBX_Setup(void);
 
static uint8_t RxData[UBX_MSG_DATA_SIZE];
 
// shared buffer
gps_data_t GPSData = {200,{0,0,0,INVALID},0,0,0,0,0,0,0, INVALID};
DateTime_t GPSDateTime = {0,0,0,0,0,0,0, INVALID};
219,7 → 219,7
UbxVelNed.Status = INVALID;
UbxMsg.Status = INVALID;
GPSData.Status = INVALID;
 
UBX_Setup();
 
UBX_Timeout = SetDelay(2 * UBX_Timeout);
275,6 → 275,8
UbxVelNed.Status = PROCESSED; // ready for new data
} // EOF all itow are equal
} // EOF all ubx messages received
}
 
/********************************************************/
284,7 → 286,7
{
static ubxState_t ubxState = UBXSTATE_IDLE;
static ubxmsghdr_t RxHdr;
static uint8_t RxData[UBX_MSG_DATA_SIZE];
static uint16_t RxBytes = 0;
static uint8_t cka, ckb;
 
376,12 → 378,20
case UBX_ID_VELNED: // velocity vector in tangent plane
memcpy((uint8_t*)&UbxVelNed, RxData, RxHdr.Length);
UbxVelNed.Status = NEWDATA;
 
break;
 
case UBX_ID_SOL: // navigation solution
memcpy((uint8_t*)&UbxSol, RxData, RxHdr.Length);
UbxSol.Status = NEWDATA;
break;
case UBX_ID_SVINFO: // sv info data for MK-Tool
DebugOut.Analog[1]++;
break;
 
default:
break;
404,7 → 414,7
UbxMsg.Hdr.Length = RxHdr.Length;
if(UbxMsg.Hdr.Length <= UBX_MSG_DATA_SIZE)
{ // copy data block
memcpy(UbxMsg.Data, RxData, RxHdr.Length);
memcpy((uint8_t*)UbxMsg.Data, RxData, RxHdr.Length);
UbxMsg.Status = NEWDATA;
}
} // EOF filter matches
/I2C_Telemetry/trunk/ubx.h
22,6 → 22,17
#define NEWDATA 0x01
#define PROCESSED 0x02
 
// message sync bytes
#define UBX_SYNC1_CHAR 0xB5
#define UBX_SYNC2_CHAR 0x62
// protocoll identifier
#define UBX_CLASS_NAV 0x01
// message id
#define UBX_ID_POSLLH 0x02
#define UBX_ID_SOL 0x06
#define UBX_ID_VELNED 0x12
#define UBX_ID_SVINFO 0x30
 
typedef struct
{
int32_t Longitude; // in 1E-7 deg
65,7 → 76,7
uint16_t Length;
} __attribute__((packed)) ubxmsghdr_t;
 
#define UBX_MSG_DATA_SIZE 200
#define UBX_MSG_DATA_SIZE 400
typedef struct
{
uint8_t ClassMask;
84,5 → 95,15
extern void UBX_Parser(uint8_t c);
extern uint8_t UBX_CreateMsg(Buffer_t* pBuff, uint8_t* pData, uint16_t Len);
 
/*typedef struct
{
uint8_t classid, id;
uint16_t len;
uint8_t data[392];
uint8_t Status; // invalid/newdata/processed
} __attribute__((packed)) ubx_nav_svinfo_t;
extern volatile ubx_nav_svinfo_t UbxSVInfo;
*/
 
#endif // _UBX_H