Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
gps_udp.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2011 The Paparazzi Team
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
22 #include "subsystems/gps.h"
23 
25 
26 
27 #include "fms/fms_network.h"
28 #include <string.h>
29 #include <stdio.h>
30 
31 #if GPS_USE_LATLONG
34 #endif
35 
36 //Check if variables are set and else define them
37 #ifndef GPS_UDP_HOST
38 #define GPS_UDP_HOST "192.168.1.2"
39 #endif
40 
41 #define GPS_UDP_MSG_LEN (11*4)
42 
43 //Define the buffer, check bytes and FmsNetwork
44 unsigned char gps_udp_read_buffer[256];
45 struct FmsNetwork* gps_network = NULL;
46 
47 void gps_impl_init(void) {
50  gps_network = network_new(GPS_UDP_HOST, 6000 /*out*/, 7000 /*in*/, TRUE);
51 }
52 
53 #define STX 99
54 
55 #define UDP_GPS_INT(_udp_gps_payload) (int32_t)(*((uint8_t*)_udp_gps_payload)|*((uint8_t*)_udp_gps_payload+1)<<8|((int32_t)*((uint8_t*)_udp_gps_payload+2))<<16|((int32_t)*((uint8_t*)_udp_gps_payload+3))<<24)
56 
57 void gps_parse(void) {
58  if (gps_network == NULL) return;
59 
60  //Read from the network
61  int size = network_read( gps_network, &gps_udp_read_buffer[0], 256);
62 
63  if(size > 0)
64  {
65  // Correct MSG
66  if ((size == GPS_UDP_MSG_LEN) && (gps_udp_read_buffer[0] == STX))
67  {
72 
76 
80 
81  gps.fix = GPS_FIX_3D;
83 
84 #if GPS_USE_LATLONG
85  // Computes from (lat, long) in the referenced UTM zone
86  struct LlaCoor_f lla_f;
88  struct UtmCoor_f utm_f;
89  utm_f.zone = nav_utm_zone0;
90  // convert to utm
91  utm_of_lla_f(&utm_f, &lla_f);
92  // copy results of utm conversion
93  gps.utm_pos.east = utm_f.east*100;
94  gps.utm_pos.north = utm_f.north*100;
97 #endif
98 
99  }
100  else
101  {
102  printf("gps_udp error: msg len invalid %d bytes\n",size);
103  }
104  memset(&gps_udp_read_buffer[0], 0, sizeof(gps_udp_read_buffer));
105  }
106 }
107 
int32_t y
in centimeters
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition: gps.h:65
int32_t lat
in degrees*1e7
struct EcefCoor_i ecef_vel
speed ECEF in cm/s
Definition: gps.h:68
uint8_t zone
UTM zone number.
uint8_t nav_utm_zone0
Definition: common_nav.c:44
int32_t hmsl
height above mean sea level in mm
Definition: gps.h:67
uint8_t fix
status of fix
Definition: gps.h:78
#define GPS_FIX_3D
Definition: gps.h:43
int32_t z
in centimeters
struct EcefCoor_i ecef_pos
position in ECEF in cm
Definition: gps.h:64
vector in Latitude, Longitude and Altitude
#define FALSE
Definition: imu_chimu.h:141
int32_t alt
in millimeters above WGS84 reference ellipsoid
Paparazzi floating point math for geodetic calculations.
uint8_t zone
UTM zone number.
float north
in meters
#define GPS_FIX_NONE
Definition: gps.h:41
#define STX
Definition: gps_udp.c:53
Device independent GPS code (interface)
void gps_impl_init(void)
GPS initialization.
Definition: gps_udp.c:47
position in UTM coordinates Units: meters
int32_t alt
in millimeters above WGS84 reference ellipsoid
#define GPS_UDP_HOST
Definition: gps_udp.c:38
#define UDP_GPS_INT(_udp_gps_payload)
Definition: gps_udp.c:55
int32_t north
in centimeters
int32_t x
in centimeters
#define TRUE
Definition: imu_chimu.h:144
int32_t east
in centimeters
#define GPS_UDP_MSG_LEN
Definition: gps_udp.c:41
int32_t lon
in degrees*1e7
#define LLA_FLOAT_OF_BFP(_o, _i)
bool_t gps_available
Is set to TRUE when a new REMOTE_GPS packet is received and parsed.
Definition: gps_udp.c:24
struct UtmCoor_i utm_pos
position in UTM (north,east: cm; alt: mm over ellipsoid)
Definition: gps.h:66
struct FmsNetwork * gps_network
Definition: gps_udp.c:45
unsigned char gps_udp_read_buffer[256]
Definition: gps_udp.c:44
float east
in meters
struct GpsState gps
global GPS state
Definition: gps.c:41
void gps_parse(void)
Definition: gps_udp.c:57
void utm_of_lla_f(struct UtmCoor_f *utm, struct LlaCoor_f *lla)