Rev 881 |
Blame |
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 <stdio.h>
#include "91x_lib.h"
#include "config.h"
#include "uart1.h"
#include "mkprotocol.h"
#include "gpspos.h"
#include "main.h"
// the tx buffer
#define UART2_TX_BUFFER_LEN 150
u8 UART2_tbuffer[UART2_TX_BUFFER_LEN];
Buffer_t UART2_tx_buffer;
unsigned char NMEA_In_Lat_Txt[16];
unsigned char NMEA_In_Lon_Txt[16];
unsigned char NMEA_In_Alt_Txt[10];
unsigned char NMEA_In_Fix_Txt[10];
u16 NMEA_cnt,NMEA_cnt_gga;
GPS_Pos_t NMEA_Position = {0,0,0, INVALID};
/********************************************************/
/* Initialize UART2 */
/********************************************************/
void UART2_Init(void)
{
UART_InitTypeDef UART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
// UART1_PutString("\r\n UART2 init...");
// initialize txd buffer
Buffer_Init(&UART2_tx_buffer, UART2_tbuffer, UART2_TX_BUFFER_LEN);
SCU_APBPeriphClockConfig(__UART2, ENABLE); // Enable the UART2 Clock
SCU_APBPeriphClockConfig(__GPIO5, ENABLE); // Enable the GPIO5 Clock
/*Configure UART2_Rx pin GPIO5.2*/
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable;
GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; // UART2_RxD
GPIO_Init(GPIO5, &GPIO_InitStructure);
SCU_APBPeriphClockConfig(__GPIO3, ENABLE); // Enable the GPIO3 Clock
/*Configure UART2_Tx pin GPIO3.0*/
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; // UART2_TX
GPIO_Init(GPIO3, &GPIO_InitStructure);
/* UART2 configured as follow:
- Word Length = 8 Bits
- One Stop Bit
- No parity
- BaudRate = 57600 baud
- Hardware flow control Disabled
- Receive and transmit enabled
- Receive and transmit FIFOs are Disabled
*/
UART_StructInit(&UART_InitStructure);
UART_InitStructure.UART_WordLength = UART_WordLength_8D;
UART_InitStructure.UART_StopBits = UART_StopBits_1;
UART_InitStructure.UART_Parity = UART_Parity_No ;
UART_InitStructure.UART_BaudRate = UART2_BAUD_RATE;
UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None;
UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx;
UART_InitStructure.UART_FIFO = UART_FIFO_Enable;
UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2;
UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2;
UART_DeInit(UART2); // reset uart 2 to default
UART_Init(UART2, &UART_InitStructure); // initialize uart 2
// enable uart 2 interrupts selective
UART_ITConfig(UART2, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE);
UART_Cmd(UART2, ENABLE); // enable uart 2
// configure the uart 2 interupt line
VIC_Config(UART2_ITLine, VIC_IRQ, PRIORITY_UART2);
// enable the uart 2 IRQ
VIC_ITCmd(UART2_ITLine, ENABLE);
// UART1_PutString("ok");
}
void UART2_Deinit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
UART1_PutString("\r\n UART2 deinit...");
VIC_ITCmd(UART2_ITLine, DISABLE); // disable the uart 2 IRQ
UART_Cmd(UART2, DISABLE); // disable uart 2
UART_DeInit(UART2); // reset uart 0 to default
SCU_APBPeriphClockConfig(__UART2, DISABLE); // disable the UART2 Clock
SCU_APBPeriphClockConfig(__GPIO5, ENABLE);
// unmap UART2 from FC
// set port pin 5.2 (serial data from FC) to input and disconnect from IP
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable;
GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
GPIO_Init(GPIO5, &GPIO_InitStructure);
SCU_APBPeriphClockConfig(__GPIO3, ENABLE);
// set port pin 3.0 (serial data to FC) to input and disconnect from IP
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
GPIO_InitStructure.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable;
GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
GPIO_Init(GPIO3, &GPIO_InitStructure);
UART1_PutString("ok");
}
u8 CheckAscii(u8 c)
{
if((c >= '0' && c <= '9') || c == '.') return(1);
return(0);
}
u8 CheckNmea(void)
{
u8 i;
if(NMEA_In_Fix_Txt[0] <= '0') return(0);
if(NMEA_In_Lat_Txt[0] == 0) return(0);
if(NMEA_In_Lon_Txt[0] == 0) return(0);
if(NMEA_In_Lat_Txt[3] != '.') return(0);
if(NMEA_In_Lon_Txt[4] != '.') return(0);
for(i = 1; i < 13; i++)
{
if(!CheckAscii(NMEA_In_Lat_Txt[i])) return(0);
if(!CheckAscii(NMEA_In_Lon_Txt[i])) return(0);
}
return(1);
}
u8 AsciiToNum(u8 c)
{
if(c == '.') return(0);
return(c - '0');
}
void ConvertNmeaToPos(GPS_Pos_t *pos)
{
s32 tmp,tmp2,i;
if(!CheckNmea())
{
if(NMEA_Position.Status != INVALID) ErrorNMEAFixLost = 1;
pos->Status = INVALID;
return;
}
tmp = AsciiToNum(NMEA_In_Lat_Txt[1]) * 100000000L;
tmp += AsciiToNum(NMEA_In_Lat_Txt[2]) * 10000000L;
// '.'
tmp2 = AsciiToNum(NMEA_In_Lat_Txt[4]) * 10000000L;
tmp2 += AsciiToNum(NMEA_In_Lat_Txt[5]) * 1000000L;
tmp2 += AsciiToNum(NMEA_In_Lat_Txt[6]) * 100000L;
tmp2 += AsciiToNum(NMEA_In_Lat_Txt[7]) * 10000L;
tmp2 += AsciiToNum(NMEA_In_Lat_Txt[8]) * 1000L;
tmp2 += AsciiToNum(NMEA_In_Lat_Txt[9]) * 100L;
tmp2 += AsciiToNum(NMEA_In_Lat_Txt[10]) * 10L;
tmp2 += AsciiToNum(NMEA_In_Lat_Txt[11]) * 1L;
tmp = tmp + tmp2/6; // to convert from Minutes to Decimal degree
if(NMEA_In_Lat_Txt[0] == '-') pos->Latitude = -tmp; else pos->Latitude = tmp;
tmp = AsciiToNum(NMEA_In_Lon_Txt[1]) * 1000000000L;
tmp += AsciiToNum(NMEA_In_Lon_Txt[2]) * 100000000L;
tmp += AsciiToNum(NMEA_In_Lon_Txt[3]) * 10000000L;
// '.'
tmp2 = AsciiToNum(NMEA_In_Lon_Txt[5]) * 10000000L;
tmp2 += AsciiToNum(NMEA_In_Lon_Txt[6]) * 1000000L;
tmp2 += AsciiToNum(NMEA_In_Lon_Txt[7]) * 100000L;
tmp2 += AsciiToNum(NMEA_In_Lon_Txt[8]) * 10000L;
tmp2 += AsciiToNum(NMEA_In_Lon_Txt[9]) * 1000L;
tmp2 += AsciiToNum(NMEA_In_Lon_Txt[10]) * 100L;
tmp2 += AsciiToNum(NMEA_In_Lon_Txt[11]) * 10L;
tmp2 += AsciiToNum(NMEA_In_Lon_Txt[12]) * 1L;
tmp = tmp + tmp2/6; // to convert from Minutes to Decimal degree
if(NMEA_In_Lon_Txt[0] == '-') pos->Longitude = -tmp; else pos->Longitude = tmp;
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// + Alitutude
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
i = 0;
tmp2 = 1000; // Millimeter
tmp = 0;
if(!CheckAscii(NMEA_In_Alt_Txt[0])) i++; // '-'
while(CheckAscii(NMEA_In_Alt_Txt[i]) && NMEA_In_Alt_Txt[i] != '.')
{
tmp += tmp2 * AsciiToNum(NMEA_In_Alt_Txt[i++]);
tmp2 *= 10;
}
if(NMEA_In_Alt_Txt[i++] == '.') // Zentimeter
{
if(CheckAscii(NMEA_In_Alt_Txt[i]))
{
tmp +=100 * AsciiToNum(NMEA_In_Alt_Txt[i++]);
if(CheckAscii(NMEA_In_Alt_Txt[i]))
{
tmp += 10 * AsciiToNum(NMEA_In_Alt_Txt[i++]);
if(CheckAscii(NMEA_In_Alt_Txt[i])) tmp += 1 * AsciiToNum(NMEA_In_Alt_Txt[i++]);
}
}
}
if(NMEA_In_Alt_Txt[0] == '-') tmp = -tmp;
pos->Altitude = tmp;
pos->Status = NEWDATA;
}
void NEMA_Parser(unsigned char data)
{
static u16 state = 0, fx,la,lo,i,a;
if(data == '$') state = 0;
static unsigned char lat_txt[16], lon_txt[16],fix_txt[10],alt_txt[10];
//$GPGGA,HHMMSS.ss,BBBB.BBBB,b,LLLLL.LLLL,l,Q,NN,D.D,H.H,h,G.G,g,A.A,RRRR*PP
//$GPGGA,191410,4735.5634,N,00739.3538,E,1,04,4.4,351.5,M,48.0,M,,*45
//$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*13
//$GPRMC,HHMMSS.sss,A,BBBB.BBBB,b,LLLLL.LLLL,l,GG.G,RR.R,DDMMYY,M.M,m,F*PP
//http://www.kowoma.de/gps/zusatzerklaerungen/NMEA.htm
switch(state)
{
case 0: if(data == '$') state++;// $
fx = 0;
la = 1;
lo = 1;
fix_txt[0] = 0;
lat_txt[0] = 0;lon_txt[0] = 0;alt_txt[0] = 0;
break;
case 1: if(data == 'G') state++;// $G
break;
case 2: if(data == 'P') state++;// $GP
NMEA_cnt = 3;
break;
//+++++++++++++++++++++++++++++++++++++++++++++++++++
case 3: if(data == 'R') state++;// $GPR
if(data == 'G') state = 6;// $GPG
break;
case 4: if(data == 'M') state++;// $GPRM
break;
case 5: if(data == 'C') state = 100;// $GPRMC
break;
//+++++++++++++++++++++++++++++++++++++++++++++++++++
case 6: if(data == 'G') state++;// $GPGG
break;
case 7: if(data == 'A') state = 200;// $GPGGA
break;
//+++++++++++++++++++++++++++++++++++++++++++++++++++
// $GPRMC (RMC = recommended minimum sentence C, empfohlener Minimumdatensatz)
//+++++++++++++++++++++++++++++++++++++++++++++++++++
/*
case 100: if(data == ',') state++; // $GPRMC,
NMEA_cnt_rmc %= 1000;
NMEA_cnt_rmc++;
break;
case 101: if(data == ',') state = 110; // $GPRMC,162614.123, // time scipped
break;
case 110: if(data == ',') state++;
else fix_txt[0] = data; // $GPRMC,162614.123,A A = Active V = Void
break;
case 111: if(data == ',') state++; // / $GPRMC,162614.123,A,
break;
case 112: if(data == ',') state++; // $GPRMC,162614.123,A,5317.123456789 Latitude
else
{
if(la < 16) lat_txt[la++] = data;
lat_txt[la] = 0;
}
break;
case 113: if(data == ',') state++; //$GPRMC,162614.123,A,5230.5900,N,
if(data == 'N') lat_txt[0] = '+';
if(data == 'S') lat_txt[0] = '-';
break;
case 114: if(data == ',') state++; //$GPRMC,162614.123,A,5230.5900,N,00722.123456789
else
{
if(lo < 16) lon_txt[lo++] = data;
lon_txt[lo] = 0;
}
break;
case 115: if(data == ',') state++; //$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,
if(data == 'O') lon_txt[0] = '+';
if(data == 'E') lon_txt[0] = '+';
if(data == 'W') lon_txt[0] = '-';
break;
case 116: if(data == ',') state++; //$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,
break;
case 117: if(data == ',') state++; //$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,
break;
case 118: if(data == ',') state++; //$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,
break;
case 119:
if(data == ',')
{
state++; //$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,
NMEA_In_Lat_Txt[0] = lat_txt[0];
NMEA_In_Lat_Txt[1] = lat_txt[1];
NMEA_In_Lat_Txt[2] = lat_txt[2];
NMEA_In_Lat_Txt[3] = '.';
NMEA_In_Lat_Txt[4] = lat_txt[3];
NMEA_In_Lat_Txt[5] = lat_txt[4];
for(i=5; i<16; i++)
{
if(lat_txt[i] == '.') i++;
NMEA_In_Lat_Txt[i] = lat_txt[i];
}
NMEA_In_Lon_Txt[0] = lon_txt[0];
NMEA_In_Lon_Txt[1] = lon_txt[1];
NMEA_In_Lon_Txt[2] = lon_txt[2];
NMEA_In_Lon_Txt[3] = lon_txt[3];
NMEA_In_Lon_Txt[4] = '.';
NMEA_In_Lon_Txt[5] = lon_txt[4];
NMEA_In_Lon_Txt[6] = lon_txt[5];
for(i=5; i<16; i++)
{
if(lon_txt[i] == '.') i++;
NMEA_In_Lon_Txt[i] = lon_txt[i];
}
}
break;
case 120: if(data == ',') state++; //$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,
break;
case 121: state = 0; //$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*13
fix_txt[1] = data;
fix_txt[2] = 0;
NMEA_In_Fix_Txt[0] = fix_txt[0];
NMEA_In_Fix_Txt[1] = fix_txt[1];
break;
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++
// $GPGGA
//+++++++++++++++++++++++++++++++++++++++++++++++++++
case 200: if(data == ',') state++; //$GPGGA,
NMEA_cnt_gga %= 1000;
NMEA_cnt_gga++;
break;
case 201: if(data == ',') state = 212; //$GPGGA,191410 // time scipped
break;
case 212: if(data == ',') state++; //$GPGGA,191410,4735.5634 Latitude
else
{
if(la < 16) lat_txt[la++] = data;
lat_txt[la] = 0;
}
break;
case 213: if(data == ',') state++; //$GPGGA,191410,4735.5634,N
if(data == 'N') lat_txt[0] = '+';
if(data == 'S') lat_txt[0] = '-';
break;
case 214: if(data == ',') state++; //$GPGGA,191410,4735.5634,N,00739.3538
else
{
if(lo < 16) lon_txt[lo++] = data;
lon_txt[lo] = 0;
}
break;
case 215: if(data == ',') state++; //$GPGGA,191410,4735.5634,N,00739.3538,E
if(data == 'O') lon_txt[0] = '+';
if(data == 'E') lon_txt[0] = '+';
if(data == 'W') lon_txt[0] = '-';
i = 0; a = 0;
break;
case 216: //$GPGGA,191410,4735.5634,N,00739.3538,E,1 -> 0 = No Fix, 1, = Fix, 2 = DGPS, ...
case 217: //$GPGGA,191410,4735.5634,N,00739.3538,E,1,04 -> Anzahl Sat
case 218: //$GPGGA,191410,4735.5634,N,00739.3538,E,1,04,4.4 HDOP
if(data == ',')
{
if(++state != 219) // letztes Leerzeiten entfernen
fix_txt[i++] = ' '; // komma durch leerzeichen ersetzten
}
else if(i < 9) fix_txt[i++] = data;
fix_txt[i] = 0;
break;
case 219: if(data == ',') state++; //$GPGGA,191410,4735.5634,N,00739.3538,E,1,04,4.4,351.5
else if(a < 9) alt_txt[a++] = data;
fix_txt[i] = 0;
break;
case 220:
if(data == ',')
{
state++; //$GPGGA,191410,4735.5634,N,00739.3538,E,1,04,4.4,351.5,M
NMEA_In_Lat_Txt[0] = lat_txt[0];
NMEA_In_Lat_Txt[1] = lat_txt[1];
NMEA_In_Lat_Txt[2] = lat_txt[2];
NMEA_In_Lat_Txt[3] = '.';
NMEA_In_Lat_Txt[4] = lat_txt[3];
NMEA_In_Lat_Txt[5] = lat_txt[4];
for(i=5; i<16; i++)
{
if(lat_txt[i] == '.') i++;
NMEA_In_Lat_Txt[i] = lat_txt[i];
}
NMEA_In_Lon_Txt[0] = lon_txt[0];
NMEA_In_Lon_Txt[1] = lon_txt[1];
NMEA_In_Lon_Txt[2] = lon_txt[2];
NMEA_In_Lon_Txt[3] = lon_txt[3];
NMEA_In_Lon_Txt[4] = '.';
NMEA_In_Lon_Txt[5] = lon_txt[4];
NMEA_In_Lon_Txt[6] = lon_txt[5];
for(i=6; i<16; i++)
{
if(lon_txt[i] == '.') i++;
NMEA_In_Lon_Txt[i] = lon_txt[i];
}
}
if(NMEA_In_Fix_Txt[i] > '0' && fix_txt[i] == '0') ErrorNMEAFixLost = 1;
for(i=0; i<10; i++)
{
NMEA_In_Alt_Txt[i] = alt_txt[i];
NMEA_In_Fix_Txt[i] = fix_txt[i];
}
if(NMEA_In_Fix_Txt[0] > '0') ErrorNMEAFixLost = 0;
ConvertNmeaToPos(&NMEA_Position);
break;
default: state = 0;
}
}
/********************************************************/
/* UART2 Interrupt Handler */
/********************************************************/
void UART2_IRQHandler(void)
{
// if receive irq or receive timeout irq has occured
if((UART_GetITStatus(UART2, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART2, UART_IT_ReceiveTimeOut) != RESET) )
{
UART_ClearITPendingBit(UART2, UART_IT_Receive); // clear receive interrupt flag
UART_ClearITPendingBit(UART2, UART_IT_ReceiveTimeOut); // clear receive timeout interrupt flag
// if debug UART is UART2 -> old FC connects to FC through the Uart
if((DebugUART == UART2) && (UART_VersionInfo.HWMajor < 30))
{ // forward received data to the UART1 tx buffer
while(UART_GetFlagStatus(UART2, UART_FLAG_RxFIFOEmpty) != SET)
{
// wait for space in the tx buffer of the UART1
while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == SET) {};
// move the byte from the rx buffer of UART2 to the tx buffer of UART1
UART_SendData(UART1, UART_ReceiveData(UART2));
}
}
else
{
// ignore serial data from the FC
while(UART_GetFlagStatus(UART2, UART_FLAG_RxFIFOEmpty) != SET)
{
unsigned char c;
c = UART_ReceiveData(UART2);
if(UART_VersionInfo.HWMajor >= 30) NEMA_Parser(c);
}
}
} // eof receive irq or receive timeout irq
VIC1->VAR = 0xFF; // write any value to VIC1 Vector address register
}
/**************************************************************/
/* Transmit tx buffer via uart2 */
/**************************************************************/
void UART2_Transmit(void)
{
u8 tmp_tx;
if(DebugUART == UART2) return; // no data output if debug uart is rederected to UART2
// if something has to be send and the txd fifo is not full
if((UART2_tx_buffer.Locked == TRUE) && (UART_GetFlagStatus(UART2, UART_FLAG_TxFIFOFull) == RESET))
{
tmp_tx = UART2_tx_buffer.pData[UART2_tx_buffer.Position++]; // read next byte from txd buffer
UART_SendData(UART2, tmp_tx); // put character to txd fifo
// if terminating character or end of txd buffer reached
if((tmp_tx == '\r') || (UART2_tx_buffer.Position == UART2_tx_buffer.Size))
{
Buffer_Clear(&UART2_tx_buffer);
}
}
}
/**************************************************************/
/* Send the answers to incomming commands at the uart2 */
/**************************************************************/
void UART2_TransmitTxData(void)
{
if(DebugUART == UART2) return;
UART2_Transmit(); // output pending bytes in tx buffer
}
void UART2_ProcessRxData(void)
{
}