Subversion Repositories NaviCtrl

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
41 ingob 1
/*#######################################################################################*/
2
/* !!! THIS IS NOT FREE SOFTWARE !!!                                                     */
3
/*#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + www.MikroKopter.com
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
360 holgerb 7
// + Software Nutzungsbedingungen (english version: see below)
8
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
9
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
10
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
11
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
12
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
41 ingob 13
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
360 holgerb 14
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
15
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
16
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
17
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
18
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
19
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
20
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
21
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
22
// + des Mitverschuldens offen.
23
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
24
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
25
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
26
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
27
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
28
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
29
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
30
// +  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.
41 ingob 31
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
360 holgerb 32
// + Software LICENSING TERMS
41 ingob 33
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
360 holgerb 34
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
35
// + 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 
36
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
37
// + The Software may only be used with the Licensor's products.
38
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
39
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
40
// + agreement shall be the property of the Licensor.
41
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
42
// + features that can be used to identify the program may not be altered or defaced by the customer.
43
// + The customer shall be responsible for taking reasonable precautions
44
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
45
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
46
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
47
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
48
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
49
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
50
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
51
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
52
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
53
// + #### END OF LICENSING TERMS ####
54
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
41 ingob 55
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56
//#include <stdio.h>
57
#include "91x_lib.h"
136 killagreg 58
#include "config.h"
41 ingob 59
#include "uart1.h"
190 killagreg 60
#include "mkprotocol.h"
881 holgerb 61
#include "gpspos.h"
62
#include "main.h"
41 ingob 63
 
190 killagreg 64
// the tx buffer
65
#define UART2_TX_BUFFER_LEN  150
66
u8 UART2_tbuffer[UART2_TX_BUFFER_LEN];
67
Buffer_t UART2_tx_buffer;
68
 
880 holgerb 69
unsigned char NMEA_In_Lat_Txt[16];
70
unsigned char NMEA_In_Lon_Txt[16];
71
unsigned char NMEA_In_Alt_Txt[10];
72
unsigned char NMEA_In_Fix_Txt[10];
73
u16 NMEA_cnt,NMEA_cnt_gga;
74
 
881 holgerb 75
GPS_Pos_t NMEA_Position = {0,0,0, INVALID};            
880 holgerb 76
 
41 ingob 77
/********************************************************/
78
/*                  Initialize UART2                    */
79
/********************************************************/
80
void UART2_Init(void)
81
{
82
    UART_InitTypeDef UART_InitStructure;
83
        GPIO_InitTypeDef GPIO_InitStructure;
84
 
580 holgerb 85
//      UART1_PutString("\r\n UART2 init...");
41 ingob 86
 
190 killagreg 87
        // initialize txd buffer
88
        Buffer_Init(&UART2_tx_buffer, UART2_tbuffer, UART2_TX_BUFFER_LEN);
89
 
41 ingob 90
        SCU_APBPeriphClockConfig(__UART2, ENABLE);  // Enable the UART2 Clock
91
 
92
        SCU_APBPeriphClockConfig(__GPIO5, ENABLE);  // Enable the GPIO5 Clock
93
    /*Configure UART2_Rx pin GPIO5.2*/
94
        GPIO_StructInit(&GPIO_InitStructure);
95
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
96
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_2;
97
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
196 killagreg 98
    GPIO_InitStructure.GPIO_IPInputConnected =  GPIO_IPInputConnected_Enable;
41 ingob 99
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1; // UART2_RxD
100
    GPIO_Init(GPIO5, &GPIO_InitStructure);
101
 
102
        SCU_APBPeriphClockConfig(__GPIO3, ENABLE);  // Enable the GPIO3 Clock
103
    /*Configure UART2_Tx pin GPIO3.0*/
104
        GPIO_StructInit(&GPIO_InitStructure);
105
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinOutput;
106
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_0;
107
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
108
    GPIO_InitStructure.GPIO_Alternate =         GPIO_OutputAlt2; // UART2_TX
109
    GPIO_Init(GPIO3, &GPIO_InitStructure);
110
 
111
 
112
        /* UART2 configured as follow:
113
          - Word Length = 8 Bits
114
          - One Stop Bit
115
          - No parity
116
          - BaudRate = 57600 baud
117
          - Hardware flow control Disabled
118
          - Receive and transmit enabled
119
          - Receive and transmit FIFOs are Disabled
120
    */
121
        UART_StructInit(&UART_InitStructure);
122
    UART_InitStructure.UART_WordLength =                        UART_WordLength_8D;
123
    UART_InitStructure.UART_StopBits =                          UART_StopBits_1;
124
    UART_InitStructure.UART_Parity =                            UART_Parity_No ;
110 killagreg 125
    UART_InitStructure.UART_BaudRate =                          UART2_BAUD_RATE;
41 ingob 126
    UART_InitStructure.UART_HardwareFlowControl =       UART_HardwareFlowControl_None;
127
    UART_InitStructure.UART_Mode =                                      UART_Mode_Tx_Rx;
128
    UART_InitStructure.UART_FIFO =                                      UART_FIFO_Enable;
129
    UART_InitStructure.UART_TxFIFOLevel =                       UART_FIFOLevel_1_2;
139 killagreg 130
    UART_InitStructure.UART_RxFIFOLevel =                       UART_FIFOLevel_1_2;
41 ingob 131
 
132
        UART_DeInit(UART2);     // reset uart 2 to default
133
    UART_Init(UART2, &UART_InitStructure);  // initialize uart 2
134
 
135
        // enable uart 2 interrupts selective
136
    UART_ITConfig(UART2, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE);
137
        UART_Cmd(UART2, ENABLE); // enable uart 2
136 killagreg 138
        // configure the uart 2 interupt line
139
        VIC_Config(UART2_ITLine, VIC_IRQ, PRIORITY_UART2);
41 ingob 140
        // enable the uart 2 IRQ
141
        VIC_ITCmd(UART2_ITLine, ENABLE);
142
 
580 holgerb 143
//      UART1_PutString("ok");
41 ingob 144
}
145
 
146
 
147
void UART2_Deinit(void)
148
{
149
        GPIO_InitTypeDef GPIO_InitStructure;
150
 
110 killagreg 151
        UART1_PutString("\r\n UART2 deinit...");
41 ingob 152
        VIC_ITCmd(UART2_ITLine, DISABLE); // disable the uart 2 IRQ
153
        UART_Cmd(UART2, DISABLE); // disable uart 2
154
        UART_DeInit(UART2);     // reset uart 0 to default
155
 
156
        SCU_APBPeriphClockConfig(__UART2, DISABLE);  // disable the UART2 Clock
157
 
158
        SCU_APBPeriphClockConfig(__GPIO5, ENABLE);
159
        // unmap UART2 from FC
160
        // set port pin 5.2 (serial data from FC) to input and disconnect from IP
161
        GPIO_StructInit(&GPIO_InitStructure);
162
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
163
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_2;
164
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
196 killagreg 165
    GPIO_InitStructure.GPIO_IPInputConnected =  GPIO_IPInputConnected_Disable;
41 ingob 166
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1;
167
    GPIO_Init(GPIO5, &GPIO_InitStructure);
168
 
169
        SCU_APBPeriphClockConfig(__GPIO3, ENABLE);
170
        // set port pin 3.0 (serial data to FC) to input and disconnect from IP
171
        GPIO_StructInit(&GPIO_InitStructure);
172
        GPIO_InitStructure.GPIO_Direction =     GPIO_PinInput;
173
    GPIO_InitStructure.GPIO_Pin =                       GPIO_Pin_0;
174
    GPIO_InitStructure.GPIO_Type =                      GPIO_Type_PushPull;
196 killagreg 175
        GPIO_InitStructure.GPIO_IPInputConnected =      GPIO_IPInputConnected_Disable;
41 ingob 176
    GPIO_InitStructure.GPIO_Alternate =         GPIO_InputAlt1;
177
    GPIO_Init(GPIO3, &GPIO_InitStructure);
178
 
110 killagreg 179
        UART1_PutString("ok");
41 ingob 180
}
181
 
880 holgerb 182
 
881 holgerb 183
u8 CheckAscii(u8 c)
184
{
185
 if((c >= '0' && c <= '9') || c == '.') return(1);
186
 return(0);
187
}
188
 
189
u8 CheckNmea(void)
190
{
191
 u8 i;
192
   if(NMEA_In_Fix_Txt[0] <= '0') return(0);
193
   if(NMEA_In_Lat_Txt[0] == 0)   return(0);
194
   if(NMEA_In_Lon_Txt[0] == 0)   return(0);
195
   if(NMEA_In_Lat_Txt[3] != '.') return(0);
196
   if(NMEA_In_Lon_Txt[4] != '.') return(0);
197
 for(i = 1; i < 13; i++)
198
  {
199
   if(!CheckAscii(NMEA_In_Lat_Txt[i])) return(0);
200
   if(!CheckAscii(NMEA_In_Lon_Txt[i])) return(0);
201
  }
202
 return(1);
203
}
204
 
205
u8 AsciiToNum(u8 c)
206
{
207
 if(c == '.') return(0);
208
 return(c - '0');
209
}
210
 
211
void ConvertNmeaToPos(GPS_Pos_t *pos)
212
{
213
 s32 tmp,tmp2,i;
214
 if(!CheckNmea())
215
  {
216
   if(NMEA_Position.Status != INVALID) ErrorNMEAFixLost = 1;
217
   pos->Status = INVALID;
218
   return;
219
  }
220
 
221
 tmp =  AsciiToNum(NMEA_In_Lat_Txt[1]) * 100000000L;
222
 tmp += AsciiToNum(NMEA_In_Lat_Txt[2]) * 10000000L;
223
 // '.'
224
 tmp2  = AsciiToNum(NMEA_In_Lat_Txt[4]) * 10000000L;
225
 tmp2 += AsciiToNum(NMEA_In_Lat_Txt[5]) * 1000000L;
226
 tmp2 += AsciiToNum(NMEA_In_Lat_Txt[6]) * 100000L;
227
 tmp2 += AsciiToNum(NMEA_In_Lat_Txt[7]) * 10000L;
228
 tmp2 += AsciiToNum(NMEA_In_Lat_Txt[8]) * 1000L;
229
 tmp2 += AsciiToNum(NMEA_In_Lat_Txt[9]) * 100L;
230
 tmp2 += AsciiToNum(NMEA_In_Lat_Txt[10]) * 10L;
231
 tmp2 += AsciiToNum(NMEA_In_Lat_Txt[11]) * 1L;
232
 
233
 tmp = tmp + tmp2/6;  // to convert from Minutes to Decimal degree  
234
 if(NMEA_In_Lat_Txt[0] == '-') pos->Latitude = -tmp; else pos->Latitude = tmp;
235
 
236
 tmp =  AsciiToNum(NMEA_In_Lon_Txt[1]) * 1000000000L;
237
 tmp += AsciiToNum(NMEA_In_Lon_Txt[2]) * 100000000L;
238
 tmp += AsciiToNum(NMEA_In_Lon_Txt[3]) * 10000000L;
239
 // '.'
240
 tmp2  = AsciiToNum(NMEA_In_Lon_Txt[5]) * 10000000L;
241
 tmp2 += AsciiToNum(NMEA_In_Lon_Txt[6]) * 1000000L;
242
 tmp2 += AsciiToNum(NMEA_In_Lon_Txt[7]) * 100000L;
243
 tmp2 += AsciiToNum(NMEA_In_Lon_Txt[8]) * 10000L;
244
 tmp2 += AsciiToNum(NMEA_In_Lon_Txt[9]) * 1000L;
245
 tmp2 += AsciiToNum(NMEA_In_Lon_Txt[10]) * 100L;
246
 tmp2 += AsciiToNum(NMEA_In_Lon_Txt[11]) * 10L;
247
 tmp2 += AsciiToNum(NMEA_In_Lon_Txt[12]) * 1L;
248
 
249
 tmp = tmp + tmp2/6;  // to convert from Minutes to Decimal degree
250
 if(NMEA_In_Lon_Txt[0] == '-') pos->Longitude = -tmp; else pos->Longitude = tmp;
251
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
252
// + Alitutude
253
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
254
 i = 0;
255
 tmp2 = 1000; //  Millimeter
256
 tmp = 0;
257
 if(!CheckAscii(NMEA_In_Alt_Txt[0])) i++; //  '-' 
258
 while(CheckAscii(NMEA_In_Alt_Txt[i]) && NMEA_In_Alt_Txt[i] != '.')
259
  {
260
   tmp += tmp2 * AsciiToNum(NMEA_In_Alt_Txt[i++]);
261
   tmp2 *= 10;
262
  }
263
 if(NMEA_In_Alt_Txt[i++] == '.')  // Zentimeter
264
  {
265
   if(CheckAscii(NMEA_In_Alt_Txt[i]))
266
    {
267
         tmp +=100 * AsciiToNum(NMEA_In_Alt_Txt[i++]);
268
     if(CheckAscii(NMEA_In_Alt_Txt[i]))
269
          {
270
           tmp += 10 * AsciiToNum(NMEA_In_Alt_Txt[i++]);
271
           if(CheckAscii(NMEA_In_Alt_Txt[i])) tmp +=  1 * AsciiToNum(NMEA_In_Alt_Txt[i++]);
272
          }
273
        }
274
  }
275
 if(NMEA_In_Alt_Txt[0] == '-') tmp = -tmp;
276
 pos->Altitude = tmp;
277
 pos->Status = NEWDATA;
278
}
279
 
280
 
880 holgerb 281
void NEMA_Parser(unsigned char data)
282
{
283
static u16 state = 0, fx,la,lo,i,a;
284
if(data  == '$') state = 0;
285
static unsigned char lat_txt[16], lon_txt[16],fix_txt[10],alt_txt[10];
286
 
287
//$GPGGA,HHMMSS.ss,BBBB.BBBB,b,LLLLL.LLLL,l,Q,NN,D.D,H.H,h,G.G,g,A.A,RRRR*PP
288
//$GPGGA,191410,4735.5634,N,00739.3538,E,1,04,4.4,351.5,M,48.0,M,,*45
289
//$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*13
290
//$GPRMC,HHMMSS.sss,A,BBBB.BBBB,b,LLLLL.LLLL,l,GG.G,RR.R,DDMMYY,M.M,m,F*PP
291
//http://www.kowoma.de/gps/zusatzerklaerungen/NMEA.htm
292
 switch(state)
293
  {
294
   case 0: if(data == '$') state++;// $
295
                   fx = 0;
296
                   la = 1;
297
                   lo = 1;
298
                   fix_txt[0] = 0;
299
                   lat_txt[0] = 0;lon_txt[0] = 0;alt_txt[0] = 0;
300
                   break;
301
   case 1: if(data == 'G') state++;// $G
302
                   break;
303
   case 2: if(data == 'P') state++;// $GP
304
                   NMEA_cnt = 3;
305
                   break;
306
//+++++++++++++++++++++++++++++++++++++++++++++++++++
307
   case 3: if(data == 'R') state++;// $GPR
308
                   if(data == 'G') state = 6;// $GPG
309
                   break;
310
   case 4: if(data == 'M') state++;// $GPRM
311
                   break;
312
   case 5: if(data == 'C') state = 100;// $GPRMC
313
                   break;
314
//+++++++++++++++++++++++++++++++++++++++++++++++++++
315
   case 6: if(data == 'G') state++;// $GPGG
316
                   break;
317
   case 7: if(data == 'A') state = 200;// $GPGGA
318
                   break;
319
//+++++++++++++++++++++++++++++++++++++++++++++++++++
320
// $GPRMC        (RMC = recommended minimum sentence C, empfohlener Minimumdatensatz)
321
//+++++++++++++++++++++++++++++++++++++++++++++++++++
322
/*
323
   case 100: if(data == ',') state++;   // $GPRMC,
324
                   NMEA_cnt_rmc %= 1000;
325
                   NMEA_cnt_rmc++;
326
                   break;
327
   case 101: if(data == ',') state = 110;       // $GPRMC,162614.123, // time scipped
328
                   break;
329
   case 110: if(data == ',') state++;
330
                         else fix_txt[0] = data;                // $GPRMC,162614.123,A   A = Active  V = Void
331
                   break;
332
   case 111: if(data == ',') state++;           // / $GPRMC,162614.123,A,
333
                   break;        
334
   case 112: if(data == ',') state++;           // $GPRMC,162614.123,A,5317.123456789    Latitude
335
                         else
336
                         {
337
                   if(la < 16) lat_txt[la++] = data;
338
                           lat_txt[la] = 0;
339
                         }
340
                   break;
341
   case 113: if(data == ',') state++;           //$GPRMC,162614.123,A,5230.5900,N,
342
                         if(data == 'N') lat_txt[0] = '+';
343
                         if(data == 'S') lat_txt[0] = '-';
344
                   break;        
345
   case 114: if(data == ',') state++;           //$GPRMC,162614.123,A,5230.5900,N,00722.123456789
346
                         else
347
                         {
348
                   if(lo < 16) lon_txt[lo++] = data;
349
                           lon_txt[lo] = 0;
350
                         }
351
                   break;
352
   case 115: if(data == ',') state++;           //$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,
353
                         if(data == 'O') lon_txt[0] = '+';
354
                         if(data == 'E') lon_txt[0] = '+';
355
                         if(data == 'W') lon_txt[0] = '-';
356
                   break;        
357
   case 116: if(data == ',') state++;           //$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,
358
                   break;        
359
   case 117: if(data == ',') state++;           //$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,
360
                   break;        
361
   case 118: if(data == ',') state++;           //$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,
362
                   break;        
363
   case 119:
364
           if(data == ',')
365
            {
366
                        state++;                //$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,
367
                        NMEA_In_Lat_Txt[0] = lat_txt[0];
368
                        NMEA_In_Lat_Txt[1] = lat_txt[1];
369
                        NMEA_In_Lat_Txt[2] = lat_txt[2];
370
                        NMEA_In_Lat_Txt[3] = '.';
371
                        NMEA_In_Lat_Txt[4] = lat_txt[3];
372
                        NMEA_In_Lat_Txt[5] = lat_txt[4];
373
                        for(i=5; i<16; i++)
374
                         {
375
                          if(lat_txt[i] == '.') i++;
376
                          NMEA_In_Lat_Txt[i] = lat_txt[i];
377
                         }
378
                        NMEA_In_Lon_Txt[0] = lon_txt[0];
379
                        NMEA_In_Lon_Txt[1] = lon_txt[1];
380
                        NMEA_In_Lon_Txt[2] = lon_txt[2];
381
                        NMEA_In_Lon_Txt[3] = lon_txt[3];
382
                        NMEA_In_Lon_Txt[4] = '.';
383
                        NMEA_In_Lon_Txt[5] = lon_txt[4];
384
                        NMEA_In_Lon_Txt[6] = lon_txt[5];
385
                        for(i=5; i<16; i++)
386
                         {
387
                          if(lon_txt[i] == '.') i++;
388
                          NMEA_In_Lon_Txt[i] = lon_txt[i];
389
                         }
390
                        }
391
                   break;        
392
   case 120: if(data == ',') state++;           //$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,
393
                   break;        
394
   case 121:  state = 0;                //$GPRMC,162614.123,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*13
395
                   fix_txt[1] = data;
396
                   fix_txt[2] = 0;
397
                   NMEA_In_Fix_Txt[0] = fix_txt[0];
398
                   NMEA_In_Fix_Txt[1] = fix_txt[1];
399
                   break;        
400
*/
401
//+++++++++++++++++++++++++++++++++++++++++++++++++++
402
// $GPGGA 
403
//+++++++++++++++++++++++++++++++++++++++++++++++++++
404
   case 200: if(data == ',') state++;   //$GPGGA,
405
                   NMEA_cnt_gga %= 1000;
406
                   NMEA_cnt_gga++;
407
                   break;
408
   case 201: if(data == ',') state = 212;       //$GPGGA,191410 // time scipped
409
                   break;
410
   case 212: if(data == ',') state++;           //$GPGGA,191410,4735.5634    Latitude
411
                         else
412
                         {
413
                   if(la < 16) lat_txt[la++] = data;
414
                           lat_txt[la] = 0;
415
                         }
416
                   break;
417
   case 213: if(data == ',') state++;           //$GPGGA,191410,4735.5634,N
418
                         if(data == 'N') lat_txt[0] = '+';
419
                         if(data == 'S') lat_txt[0] = '-';
420
                   break;        
421
   case 214: if(data == ',') state++;           //$GPGGA,191410,4735.5634,N,00739.3538
422
                         else
423
                         {
424
                   if(lo < 16) lon_txt[lo++] = data;
425
                           lon_txt[lo] = 0;
426
                         }
427
                   break;
428
   case 215: if(data == ',') state++;           //$GPGGA,191410,4735.5634,N,00739.3538,E
429
                         if(data == 'O') lon_txt[0] = '+';
430
                         if(data == 'E') lon_txt[0] = '+';
431
                         if(data == 'W') lon_txt[0] = '-';
432
                         i = 0; a = 0;
433
                   break;        
434
   case 216:                                                             //$GPGGA,191410,4735.5634,N,00739.3538,E,1 -> 0 = No Fix, 1, = Fix, 2 = DGPS, ...
435
   case 217:                                                             //$GPGGA,191410,4735.5634,N,00739.3538,E,1,04 -> Anzahl Sat
436
   case 218:                                                             //$GPGGA,191410,4735.5634,N,00739.3538,E,1,04,4.4 HDOP
437
             if(data == ',')
438
                          {
439
                           if(++state != 219)    // letztes Leerzeiten entfernen
440
                             fix_txt[i++] = ' '; // komma durch leerzeichen ersetzten
441
                          }
442
                          else if(i < 9) fix_txt[i++] = data;
443
                          fix_txt[i] = 0;
444
                   break;        
445
   case 219: if(data == ',') state++;           //$GPGGA,191410,4735.5634,N,00739.3538,E,1,04,4.4,351.5
446
                        else if(a < 9) alt_txt[a++] = data;
447
                        fix_txt[i] = 0;
448
                   break;        
449
   case 220:
450
           if(data == ',')
451
            {
452
                        state++;                                                        //$GPGGA,191410,4735.5634,N,00739.3538,E,1,04,4.4,351.5,M
453
                        NMEA_In_Lat_Txt[0] = lat_txt[0];
454
                        NMEA_In_Lat_Txt[1] = lat_txt[1];
455
                        NMEA_In_Lat_Txt[2] = lat_txt[2];
456
                        NMEA_In_Lat_Txt[3] = '.';
457
                        NMEA_In_Lat_Txt[4] = lat_txt[3];
458
                        NMEA_In_Lat_Txt[5] = lat_txt[4];
459
                        for(i=5; i<16; i++)
460
                         {
461
                          if(lat_txt[i] == '.') i++;
462
                          NMEA_In_Lat_Txt[i] = lat_txt[i];
463
                         }
464
                        NMEA_In_Lon_Txt[0] = lon_txt[0];
465
                        NMEA_In_Lon_Txt[1] = lon_txt[1];
466
                        NMEA_In_Lon_Txt[2] = lon_txt[2];
467
                        NMEA_In_Lon_Txt[3] = lon_txt[3];
468
                        NMEA_In_Lon_Txt[4] = '.';
469
                        NMEA_In_Lon_Txt[5] = lon_txt[4];
470
                        NMEA_In_Lon_Txt[6] = lon_txt[5];
471
                        for(i=6; i<16; i++)
472
                         {
473
                          if(lon_txt[i] == '.') i++;
474
                          NMEA_In_Lon_Txt[i] = lon_txt[i];
475
                         }
476
                        }
881 holgerb 477
                        if(NMEA_In_Fix_Txt[i] > '0' && fix_txt[i] == '0') ErrorNMEAFixLost = 1;
880 holgerb 478
                        for(i=0; i<10; i++)
479
                         {
480
                          NMEA_In_Alt_Txt[i] = alt_txt[i];
481
                      NMEA_In_Fix_Txt[i] = fix_txt[i];
482
                         }
881 holgerb 483
                        if(NMEA_In_Fix_Txt[0] > '0') ErrorNMEAFixLost = 0;
484
ConvertNmeaToPos(&NMEA_Position);
880 holgerb 485
                   break;        
486
   default: state = 0;
487
  }
488
}
489
 
490
 
41 ingob 491
/********************************************************/
492
/*            UART2 Interrupt Handler                   */
493
/********************************************************/
494
void UART2_IRQHandler(void)
495
{
496
        // if receive irq or receive timeout irq has occured
497
        if((UART_GetITStatus(UART2, UART_IT_Receive) != RESET) || (UART_GetITStatus(UART2, UART_IT_ReceiveTimeOut) != RESET) )
498
        {
499
                UART_ClearITPendingBit(UART2, UART_IT_Receive);                 // clear receive interrupt flag
500
                UART_ClearITPendingBit(UART2, UART_IT_ReceiveTimeOut);  // clear receive timeout interrupt flag
501
 
881 holgerb 502
                // if debug UART is UART2 -> old FC connects to FC through the Uart 
503
                if((DebugUART == UART2) && (UART_VersionInfo.HWMajor < 30))
41 ingob 504
                {       // forward received data to the UART1 tx buffer
505
                        while(UART_GetFlagStatus(UART2, UART_FLAG_RxFIFOEmpty) != SET)
506
                        {
507
                                // wait for space in the tx buffer of the UART1
508
                                while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == SET) {};
509
                                // move the byte from the rx buffer of UART2 to the tx buffer of UART1
881 holgerb 510
                                UART_SendData(UART1, UART_ReceiveData(UART2)); 
41 ingob 511
                        }
512
                }
513
                else
514
                {
515
                        // ignore serial data from the FC
516
                        while(UART_GetFlagStatus(UART2, UART_FLAG_RxFIFOEmpty) != SET)
190 killagreg 517
                        {
880 holgerb 518
                         unsigned char c;
519
                         c = UART_ReceiveData(UART2);
520
                         if(UART_VersionInfo.HWMajor >= 30) NEMA_Parser(c);
190 killagreg 521
                        }
41 ingob 522
                }
523
        } // eof receive irq or receive timeout irq
195 killagreg 524
 
380 holgerb 525
 
378 holgerb 526
        VIC1->VAR = 0xFF; // write any value to VIC1 Vector address register
41 ingob 527
}
190 killagreg 528
 
529
/**************************************************************/
530
/*         Transmit tx buffer via uart2                       */
531
/**************************************************************/
532
void UART2_Transmit(void)
533
{
534
        u8 tmp_tx;
535
        if(DebugUART == UART2) return; // no data output if debug uart is rederected to UART2
536
        // if something has to be send and the txd fifo is not full
537
        if((UART2_tx_buffer.Locked == TRUE) && (UART_GetFlagStatus(UART2, UART_FLAG_TxFIFOFull) == RESET))
538
        {
539
                tmp_tx = UART2_tx_buffer.pData[UART2_tx_buffer.Position++]; // read next byte from txd buffer
540
                UART_SendData(UART2, tmp_tx); // put character to txd fifo
541
                // if terminating character or end of txd buffer reached
542
                if((tmp_tx == '\r') || (UART2_tx_buffer.Position == UART2_tx_buffer.Size))
543
                {
544
                        Buffer_Clear(&UART2_tx_buffer);
545
                }
546
        }
547
}
548
 
549
/**************************************************************/
550
/* Send the answers to incomming commands at the uart2        */
551
/**************************************************************/
552
void UART2_TransmitTxData(void)
553
{
554
        if(DebugUART == UART2) return;
555
        UART2_Transmit(); // output pending bytes in tx buffer
556
}
557
 
558
 
559
void UART2_ProcessRxData(void)
560
{
561
 
562
}