Paparazzi UAS  v5.18.0_stable
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 "subsystems/gps.h"
23 #include "subsystems/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 
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 }
LlaCoor_i::lon
int32_t lon
in degrees*1e7
Definition: pprz_geodetic_int.h:61
GpsState::valid_fields
uint8_t valid_fields
bitfield indicating valid fields (GPS_VALID_x_BIT)
Definition: gps.h:88
LlaCoor_i::alt
int32_t alt
in millimeters above WGS84 reference ellipsoid
Definition: pprz_geodetic_int.h:62
gps_udp_parse
void gps_udp_parse(void)
Definition: gps_udp.c:52
abi.h
GpsState
data structure for GPS information
Definition: gps.h:87
EcefCoor_i::x
int32_t x
in centimeters
Definition: pprz_geodetic_int.h:51
GPS_UDP_ID
#define GPS_UDP_ID
Definition: abi_sender_ids.h:244
uint32_t
unsigned long uint32_t
Definition: types.h:18
gps_network
struct FmsNetwork * gps_network
Definition: gps_udp.c:38
GPS_UDP_MSG_LEN
#define GPS_UDP_MSG_LEN
Definition: gps_udp.c:34
EcefCoor_i::y
int32_t y
in centimeters
Definition: pprz_geodetic_int.h:52
GPS_VALID_POS_LLA_BIT
#define GPS_VALID_POS_LLA_BIT
Definition: gps.h:49
get_sys_time_usec
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:68
LlaCoor_i::lat
int32_t lat
in degrees*1e7
Definition: pprz_geodetic_int.h:60
GPS_UDP_HOST
#define GPS_UDP_HOST
Definition: gps_udp.c:31
GpsState::last_msg_ticks
uint32_t last_msg_ticks
cpu time ticks at last received GPS message
Definition: gps.h:116
EcefCoor_i::z
int32_t z
in centimeters
Definition: pprz_geodetic_int.h:53
gps.h
Device independent GPS code (interface)
GpsState::fix
uint8_t fix
status of fix
Definition: gps.h:107
gps_udp_init
void gps_udp_init(void)
Definition: gps_udp.c:42
gps_udp_read_buffer
unsigned char gps_udp_read_buffer[256]
Definition: gps_udp.c:37
gps_udp
struct GpsState gps_udp
Definition: gps_udp.c:40
GpsState::last_3dfix_time
uint32_t last_3dfix_time
cpu time in sec at last valid 3D fix
Definition: gps.h:115
GpsState::last_3dfix_ticks
uint32_t last_3dfix_ticks
cpu time ticks at last valid 3D fix
Definition: gps.h:114
GpsState::last_msg_time
uint32_t last_msg_time
cpu time in sec at last received GPS message
Definition: gps.h:117
GpsState::ecef_pos
struct EcefCoor_i ecef_pos
position in ECEF in cm
Definition: gps.h:91
GpsState::lla_pos
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition: gps.h:92
GPS_VALID_VEL_ECEF_BIT
#define GPS_VALID_VEL_ECEF_BIT
Definition: gps.h:51
sys_time
Definition: sys_time.h:71
sys_time::nb_sec_rem
volatile uint32_t nb_sec_rem
remainder of seconds since startup in CPU_TICKS
Definition: sys_time.h:73
GpsState::hmsl
int32_t hmsl
height above mean sea level (MSL) in mm
Definition: gps.h:94
GPS_VALID_POS_ECEF_BIT
#define GPS_VALID_POS_ECEF_BIT
Definition: gps.h:48
sys_time::nb_sec
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:72
GpsState::ecef_vel
struct EcefCoor_i ecef_vel
speed ECEF in cm/s
Definition: gps.h:95
TRUE
#define TRUE
Definition: std.h:4
GPS_FIX_NONE
#define GPS_FIX_NONE
No GPS fix.
Definition: gps.h:37
GPS_FIX_3D
#define GPS_FIX_3D
3D GPS fix
Definition: gps.h:39
GPS_VALID_HMSL_BIT
#define GPS_VALID_HMSL_BIT
Definition: gps.h:53
STX
#define STX
Definition: gps_udp.c:48
UDP_GPS_INT
#define UDP_GPS_INT(_udp_gps_payload)
Definition: gps_udp.c:50