Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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 "modules/gps/gps.h"
23 #include "modules/core/abi.h"
24 
25 #include "fms/fms_network.h"
26 #include <string.h>
27 #include <stdio.h>
28 
29 //Check if variables are set and else define them
30 #ifndef GPS_UDP_HOST
31 #define GPS_UDP_HOST 192.168.1.2
32 #endif
33 
34 #define GPS_UDP_MSG_LEN (11*4)
35 
36 //Define the buffer, check bytes and FmsNetwork
37 unsigned char gps_udp_read_buffer[256];
38 struct FmsNetwork *gps_network = NULL;
39 
40 struct GpsState gps_udp;
41 
42 void gps_udp_init(void)
43 {
45  gps_network = network_new(STRINGIFY(GPS_UDP_HOST), 6000 /*out*/, 7000 /*in*/, TRUE);
46 }
47 
48 #define STX 99
49 
50 #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)
51 
52 void gps_udp_parse(void)
53 {
54  if (gps_network == NULL) { return; }
55 
56  //Read from the network
57  int size = network_read(gps_network, &gps_udp_read_buffer[0], 256);
58 
59  if (size > 0) {
60  // Correct MSG
61  if ((size == GPS_UDP_MSG_LEN) && (gps_udp_read_buffer[0] == STX)) {
66 
69 
74 
79 
81 
82  // publish new GPS data
83  uint32_t now_ts = get_sys_time_usec();
86  if (gps_udp.fix == GPS_FIX_3D) {
89  }
90  AbiSendMsgGPS(GPS_UDP_ID, now_ts, &gps_udp);
91 
92  } else {
93  printf("gps_udp error: msg len invalid %d bytes\n", size);
94  }
95  memset(&gps_udp_read_buffer[0], 0, sizeof(gps_udp_read_buffer));
96  }
97 }
Main include for ABI (AirBorneInterface).
#define GPS_UDP_ID
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:71
Device independent GPS code (interface)
int32_t hmsl
height above mean sea level (MSL) in mm
Definition: gps.h:93
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition: gps.h:91
#define GPS_VALID_VEL_ECEF_BIT
Definition: gps.h:50
struct EcefCoor_i ecef_pos
position in ECEF in cm
Definition: gps.h:90
#define GPS_VALID_POS_LLA_BIT
Definition: gps.h:48
uint32_t last_3dfix_ticks
cpu time ticks at last valid 3D fix
Definition: gps.h:113
struct EcefCoor_i ecef_vel
speed ECEF in cm/s
Definition: gps.h:94
#define GPS_FIX_NONE
No GPS fix.
Definition: gps.h:41
#define GPS_VALID_POS_ECEF_BIT
Definition: gps.h:47
#define GPS_VALID_HMSL_BIT
Definition: gps.h:52
uint32_t last_msg_time
cpu time in sec at last received GPS message
Definition: gps.h:116
uint32_t last_3dfix_time
cpu time in sec at last valid 3D fix
Definition: gps.h:114
uint8_t valid_fields
bitfield indicating valid fields (GPS_VALID_x_BIT)
Definition: gps.h:87
#define GPS_FIX_3D
3D GPS fix
Definition: gps.h:43
uint32_t last_msg_ticks
cpu time ticks at last received GPS message
Definition: gps.h:115
uint8_t fix
status of fix
Definition: gps.h:106
data structure for GPS information
Definition: gps.h:86
struct FmsNetwork * gps_network
Definition: gps_udp.c:38
#define GPS_UDP_MSG_LEN
Definition: gps_udp.c:34
#define GPS_UDP_HOST
Definition: gps_udp.c:31
struct GpsState gps_udp
Definition: gps_udp.c:40
#define UDP_GPS_INT(_udp_gps_payload)
Definition: gps_udp.c:50
void gps_udp_init(void)
Definition: gps_udp.c:42
void gps_udp_parse(void)
Definition: gps_udp.c:52
unsigned char gps_udp_read_buffer[256]
Definition: gps_udp.c:37
#define STX
Definition: gps_udp.c:48
int32_t lat
in degrees*1e7
int32_t alt
in millimeters above WGS84 reference ellipsoid
int32_t z
in centimeters
int32_t x
in centimeters
int32_t y
in centimeters
int32_t lon
in degrees*1e7
#define TRUE
Definition: std.h:4
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:72
volatile uint32_t nb_sec_rem
remainder of seconds since startup in CPU_TICKS
Definition: sys_time.h:73
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78