2013-02-04 15:57:12 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
*
|
2016-03-03 12:12:11 +01:00
|
|
|
* Copyright (c) 2013-2016 PX4 Development Team. All rights reserved.
|
2013-02-04 15:57:12 +01:00
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
|
* distribution.
|
|
|
|
|
* 3. Neither the name PX4 nor the names of its contributors may be
|
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
|
* without specific prior written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @file gps.cpp
|
2013-02-04 16:27:01 -08:00
|
|
|
* Driver for the GPS on a serial port
|
2013-02-04 15:57:12 +01:00
|
|
|
*/
|
|
|
|
|
|
2016-04-06 10:02:21 +02:00
|
|
|
#ifdef __PX4_NUTTX
|
2013-02-08 11:05:57 -08:00
|
|
|
#include <nuttx/clock.h>
|
2016-03-03 12:12:11 +01:00
|
|
|
#include <nuttx/arch.h>
|
2016-04-06 10:02:21 +02:00
|
|
|
#endif
|
2016-04-25 14:04:29 +02:00
|
|
|
|
2016-03-03 12:12:11 +01:00
|
|
|
|
2016-04-19 16:22:53 +02:00
|
|
|
#ifndef __PX4_QURT
|
|
|
|
|
#include <termios.h>
|
|
|
|
|
#include <poll.h>
|
|
|
|
|
#else
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
#include <dev_fs_lib_serial.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2016-04-25 14:04:29 +02:00
|
|
|
#include <fcntl.h>
|
2013-02-04 15:57:12 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <stdint.h>
|
2013-02-05 13:47:31 +01:00
|
|
|
#include <stdio.h>
|
2013-02-04 15:57:12 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <poll.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <unistd.h>
|
2015-03-11 12:16:44 -07:00
|
|
|
#include <px4_config.h>
|
2016-04-19 16:22:53 +02:00
|
|
|
#include <px4_time.h>
|
2013-02-04 15:57:12 +01:00
|
|
|
#include <arch/board/board.h>
|
|
|
|
|
#include <drivers/drv_hrt.h>
|
2016-04-22 09:40:29 +02:00
|
|
|
#include <mathlib/mathlib.h>
|
2014-05-16 10:46:10 +02:00
|
|
|
#include <systemlib/systemlib.h>
|
2013-02-04 15:57:12 +01:00
|
|
|
#include <systemlib/scheduling_priorities.h>
|
|
|
|
|
#include <systemlib/err.h>
|
|
|
|
|
#include <drivers/drv_gps.h>
|
2013-02-08 11:05:57 -08:00
|
|
|
#include <uORB/uORB.h>
|
2013-02-04 15:57:12 +01:00
|
|
|
#include <uORB/topics/vehicle_gps_position.h>
|
2014-06-08 14:05:35 +02:00
|
|
|
#include <uORB/topics/satellite_info.h>
|
2016-04-19 16:22:53 +02:00
|
|
|
#include <uORB/topics/gps_inject_data.h>
|
2013-02-04 15:57:12 +01:00
|
|
|
|
2014-05-13 09:41:41 -07:00
|
|
|
#include <board_config.h>
|
|
|
|
|
|
2016-04-19 16:22:53 +02:00
|
|
|
#include "devices/src/ubx.h"
|
|
|
|
|
#include "devices/src/mtk.h"
|
|
|
|
|
#include "devices/src/ashtech.h"
|
2013-02-04 15:57:12 +01:00
|
|
|
|
|
|
|
|
|
2013-03-09 13:21:23 +01:00
|
|
|
#define TIMEOUT_5HZ 500
|
2013-02-08 11:05:57 -08:00
|
|
|
#define RATE_MEASUREMENT_PERIOD 5000000
|
2016-04-19 16:22:53 +02:00
|
|
|
#define GPS_WAIT_BEFORE_READ 20 // ms, wait before reading to save read() calls
|
2013-02-04 15:57:12 +01:00
|
|
|
|
2016-03-03 12:12:11 +01:00
|
|
|
|
2014-06-13 14:05:47 +02:00
|
|
|
/* class for dynamic allocation of satellite info data */
|
|
|
|
|
class GPS_Sat_Info
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
struct satellite_info_s _data;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2016-03-03 12:12:11 +01:00
|
|
|
class GPS
|
2013-02-04 15:57:12 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2016-04-18 16:30:28 +02:00
|
|
|
GPS(const char *uart_path, bool fake_gps, bool enable_sat_info, int gps_num);
|
2013-03-09 21:07:29 +01:00
|
|
|
virtual ~GPS();
|
2013-02-04 15:57:12 +01:00
|
|
|
|
|
|
|
|
virtual int init();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Diagnostics - print some basic information about the driver.
|
|
|
|
|
*/
|
|
|
|
|
void print_info();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
2013-02-05 13:47:31 +01:00
|
|
|
bool _task_should_exit; ///< flag to make the main worker task exit
|
|
|
|
|
int _serial_fd; ///< serial interface to GPS
|
|
|
|
|
unsigned _baudrate; ///< current baudrate
|
|
|
|
|
char _port[20]; ///< device / serial port path
|
2014-07-02 11:39:56 +02:00
|
|
|
volatile int _task; ///< worker task
|
2013-02-07 14:48:00 -08:00
|
|
|
bool _healthy; ///< flag to signal if the GPS is ok
|
2014-06-13 14:05:47 +02:00
|
|
|
bool _baudrate_changed; ///< flag to signal that the baudrate with the GPS has changed
|
2013-02-05 13:47:31 +01:00
|
|
|
bool _mode_changed; ///< flag that the GPS mode has changed
|
|
|
|
|
gps_driver_mode_t _mode; ///< current mode
|
2016-04-19 16:22:53 +02:00
|
|
|
GPSHelper *_helper; ///< instance of GPS parser
|
|
|
|
|
GPS_Sat_Info *_sat_info; ///< instance of GPS sat info data object
|
2014-06-13 14:05:47 +02:00
|
|
|
struct vehicle_gps_position_s _report_gps_pos; ///< uORB topic for gps position
|
2016-04-26 11:11:49 +02:00
|
|
|
orb_advert_t _report_gps_pos_pub; ///< uORB pub for gps position
|
|
|
|
|
int _gps_orb_instance; ///< uORB multi-topic instance
|
2014-06-13 14:05:47 +02:00
|
|
|
struct satellite_info_s *_p_report_sat_info; ///< pointer to uORB topic for satellite info
|
2014-06-08 14:05:35 +02:00
|
|
|
orb_advert_t _report_sat_info_pub; ///< uORB pub for satellite info
|
2013-02-05 13:47:31 +01:00
|
|
|
float _rate; ///< position update rate
|
2016-04-25 13:03:33 +02:00
|
|
|
float _rate_rtcm_injection; ///< RTCM message injection rate
|
|
|
|
|
unsigned _last_rate_rtcm_injection_count; ///< counter for number of RTCM messages
|
2014-01-11 00:46:45 +01:00
|
|
|
bool _fake_gps; ///< fake gps output
|
2016-04-18 16:30:28 +02:00
|
|
|
int _gps_num; ///< number of GPS connected
|
2013-02-04 15:57:12 +01:00
|
|
|
|
2016-04-21 09:56:31 +02:00
|
|
|
static const int _orb_inject_data_fd_count = 4;
|
|
|
|
|
int _orb_inject_data_fd[_orb_inject_data_fd_count];
|
2016-04-19 16:22:53 +02:00
|
|
|
int _orb_inject_data_next = 0;
|
2013-02-04 15:57:12 +01:00
|
|
|
|
2013-02-04 16:27:01 -08:00
|
|
|
/**
|
|
|
|
|
* Try to configure the GPS, handle outgoing communication to the GPS
|
|
|
|
|
*/
|
2016-04-19 16:22:53 +02:00
|
|
|
void config();
|
2013-02-04 15:57:12 +01:00
|
|
|
|
2013-02-04 16:27:01 -08:00
|
|
|
/**
|
|
|
|
|
* Trampoline to the worker task
|
|
|
|
|
*/
|
2016-05-04 09:13:37 +02:00
|
|
|
static void task_main_trampoline(int argc, char *argv[]);
|
2013-02-04 15:57:12 +01:00
|
|
|
|
|
|
|
|
/**
|
2013-02-04 16:27:01 -08:00
|
|
|
* Worker task: main GPS thread that configures the GPS and parses incoming data, always running
|
2013-02-04 15:57:12 +01:00
|
|
|
*/
|
2016-04-19 16:22:53 +02:00
|
|
|
void task_main(void);
|
2013-02-04 15:57:12 +01:00
|
|
|
|
2013-02-04 17:55:58 +01:00
|
|
|
/**
|
2013-02-04 16:27:01 -08:00
|
|
|
* Set the baudrate of the UART to the GPS
|
2013-02-04 17:55:58 +01:00
|
|
|
*/
|
2016-04-19 16:22:53 +02:00
|
|
|
int set_baudrate(unsigned baud);
|
2013-02-04 15:57:12 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send a reset command to the GPS
|
|
|
|
|
*/
|
2016-04-19 16:22:53 +02:00
|
|
|
void cmd_reset();
|
|
|
|
|
|
2016-04-18 16:30:28 +02:00
|
|
|
/**
|
|
|
|
|
* Publish the gps struct
|
|
|
|
|
*/
|
|
|
|
|
void publish();
|
|
|
|
|
|
2016-04-19 16:22:53 +02:00
|
|
|
/**
|
|
|
|
|
* This is an abstraction for the poll on serial used.
|
|
|
|
|
*
|
|
|
|
|
* @param buf: pointer to read buffer
|
|
|
|
|
* @param buf_length: size of read buffer
|
|
|
|
|
* @param timeout: timeout in ms
|
|
|
|
|
* @return: 0 for nothing read, or poll timed out
|
|
|
|
|
* < 0 for error
|
|
|
|
|
* > 0 number of bytes read
|
|
|
|
|
*/
|
|
|
|
|
int pollOrRead(uint8_t *buf, size_t buf_length, int timeout);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* check for new messages on the inject data topic & handle them
|
|
|
|
|
*/
|
|
|
|
|
void handleInjectDataTopic();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* send data to the device, such as an RTCM stream
|
|
|
|
|
* @param data
|
|
|
|
|
* @param len
|
|
|
|
|
*/
|
|
|
|
|
inline bool injectData(uint8_t *data, size_t len);
|
2013-02-04 15:57:12 +01:00
|
|
|
|
2016-04-19 16:22:53 +02:00
|
|
|
/**
|
|
|
|
|
* set the Baudrate
|
|
|
|
|
* @param baud
|
|
|
|
|
* @return 0 on success, <0 on error
|
|
|
|
|
*/
|
|
|
|
|
int setBaudrate(unsigned baud);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* callback from the driver for the platform specific stuff
|
|
|
|
|
*/
|
|
|
|
|
static int callback(GPSCallbackType type, void *data1, int data2, void *user);
|
2013-02-04 15:57:12 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Driver 'main' command.
|
|
|
|
|
*/
|
|
|
|
|
extern "C" __EXPORT int gps_main(int argc, char *argv[]);
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
|
2016-05-04 09:13:37 +02:00
|
|
|
GPS *g_dev[2] = {nullptr, nullptr};
|
2013-02-04 15:57:12 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-18 16:30:28 +02:00
|
|
|
|
|
|
|
|
GPS::GPS(const char *uart_path, bool fake_gps, bool enable_sat_info, int gps_num) :
|
2013-02-04 15:57:12 +01:00
|
|
|
_task_should_exit(false),
|
2013-02-07 14:48:00 -08:00
|
|
|
_healthy(false),
|
2013-02-06 20:04:49 -08:00
|
|
|
_mode_changed(false),
|
2013-02-08 11:05:57 -08:00
|
|
|
_mode(GPS_DRIVER_MODE_UBX),
|
2016-04-19 16:22:53 +02:00
|
|
|
_helper(nullptr),
|
|
|
|
|
_sat_info(nullptr),
|
2016-04-26 11:11:49 +02:00
|
|
|
_report_gps_pos_pub{nullptr},
|
|
|
|
|
_gps_orb_instance(-1),
|
2014-06-13 14:05:47 +02:00
|
|
|
_p_report_sat_info(nullptr),
|
2015-05-25 22:21:23 -07:00
|
|
|
_report_sat_info_pub(nullptr),
|
2014-01-11 00:46:45 +01:00
|
|
|
_rate(0.0f),
|
2016-04-25 13:03:33 +02:00
|
|
|
_rate_rtcm_injection(0.0f),
|
|
|
|
|
_last_rate_rtcm_injection_count(0),
|
2016-04-18 16:30:28 +02:00
|
|
|
_fake_gps(fake_gps),
|
|
|
|
|
_gps_num(gps_num)
|
2013-02-04 15:57:12 +01:00
|
|
|
{
|
2013-02-05 13:47:31 +01:00
|
|
|
/* store port name */
|
|
|
|
|
strncpy(_port, uart_path, sizeof(_port));
|
|
|
|
|
/* enforce null termination */
|
|
|
|
|
_port[sizeof(_port) - 1] = '\0';
|
|
|
|
|
|
2013-02-04 15:57:12 +01:00
|
|
|
/* we need this potentially before it could be set in task_main */
|
2014-06-08 14:05:35 +02:00
|
|
|
memset(&_report_gps_pos, 0, sizeof(_report_gps_pos));
|
2014-06-13 14:05:47 +02:00
|
|
|
|
|
|
|
|
/* create satellite info data object if requested */
|
|
|
|
|
if (enable_sat_info) {
|
2016-04-19 16:22:53 +02:00
|
|
|
_sat_info = new GPS_Sat_Info();
|
|
|
|
|
_p_report_sat_info = &_sat_info->_data;
|
2014-06-13 14:05:47 +02:00
|
|
|
memset(_p_report_sat_info, 0, sizeof(*_p_report_sat_info));
|
|
|
|
|
}
|
2016-04-19 16:22:53 +02:00
|
|
|
|
2016-04-21 09:56:31 +02:00
|
|
|
for (int i = 0; i < _orb_inject_data_fd_count; ++i) {
|
2016-04-25 13:08:21 +02:00
|
|
|
_orb_inject_data_fd[i] = -1;
|
2016-04-19 16:22:53 +02:00
|
|
|
}
|
2013-02-04 15:57:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GPS::~GPS()
|
|
|
|
|
{
|
|
|
|
|
/* tell the task we want it to go away */
|
|
|
|
|
_task_should_exit = true;
|
|
|
|
|
|
|
|
|
|
/* spin waiting for the task to stop */
|
|
|
|
|
for (unsigned i = 0; (i < 10) && (_task != -1); i++) {
|
|
|
|
|
/* give it another 100ms */
|
|
|
|
|
usleep(100000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* well, kill it anyway, though this will probably crash */
|
2015-10-19 13:16:11 +02:00
|
|
|
if (_task != -1) {
|
2016-03-03 12:12:11 +01:00
|
|
|
px4_task_delete(_task);
|
2015-10-19 13:16:11 +02:00
|
|
|
}
|
2013-09-21 08:59:04 +02:00
|
|
|
|
2016-04-19 16:22:53 +02:00
|
|
|
if (_sat_info) {
|
|
|
|
|
delete(_sat_info);
|
2016-04-06 14:26:10 +02:00
|
|
|
}
|
2016-04-06 10:02:21 +02:00
|
|
|
|
2013-02-05 13:47:31 +01:00
|
|
|
|
2013-02-04 15:57:12 +01:00
|
|
|
}
|
|
|
|
|
|
2016-04-19 16:22:53 +02:00
|
|
|
int GPS::init()
|
2013-02-04 15:57:12 +01:00
|
|
|
{
|
|
|
|
|
|
2016-05-04 09:13:37 +02:00
|
|
|
char gps_num;
|
|
|
|
|
sprintf(&gps_num, "%d", _gps_num);
|
|
|
|
|
|
|
|
|
|
static char *gps_num_ptr;
|
|
|
|
|
gps_num_ptr = &gps_num;
|
|
|
|
|
|
|
|
|
|
|
2013-02-04 16:27:01 -08:00
|
|
|
/* start the GPS driver worker task */
|
2015-05-06 14:43:11 -07:00
|
|
|
_task = px4_task_spawn_cmd("gps", SCHED_DEFAULT,
|
2016-05-04 09:13:37 +02:00
|
|
|
SCHED_PRIORITY_SLOW_DRIVER, 1200, (px4_main_t)&GPS::task_main_trampoline, &gps_num_ptr);
|
2013-02-04 15:57:12 +01:00
|
|
|
|
|
|
|
|
if (_task < 0) {
|
2016-03-03 12:12:11 +01:00
|
|
|
PX4_WARN("task start failed: %d", errno);
|
2013-02-04 15:57:12 +01:00
|
|
|
return -errno;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-03 12:12:11 +01:00
|
|
|
return OK;
|
2013-02-04 15:57:12 +01:00
|
|
|
}
|
|
|
|
|
|
2016-05-04 09:13:37 +02:00
|
|
|
void GPS::task_main_trampoline(int argc, char *argv[])
|
2013-02-04 15:57:12 +01:00
|
|
|
{
|
2016-05-04 09:13:37 +02:00
|
|
|
warnx("arg = %i %c %i", argc, *argv[0], *argv[0]);
|
|
|
|
|
if (!strcmp(argv[1], "1"))
|
|
|
|
|
g_dev[0]->task_main();
|
|
|
|
|
else if (!strcmp(argv[1], "2"))
|
|
|
|
|
g_dev[1]->task_main();
|
2013-02-04 15:57:12 +01:00
|
|
|
}
|
|
|
|
|
|
2016-04-19 16:22:53 +02:00
|
|
|
int GPS::callback(GPSCallbackType type, void *data1, int data2, void *user)
|
|
|
|
|
{
|
|
|
|
|
GPS *gps = (GPS *)user;
|
|
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
case GPSCallbackType::readDeviceData:
|
|
|
|
|
return gps->pollOrRead((uint8_t *)data1, data2, *((int *)data1));
|
|
|
|
|
|
|
|
|
|
case GPSCallbackType::writeDeviceData:
|
|
|
|
|
return write(gps->_serial_fd, data1, (size_t)data2);
|
|
|
|
|
|
|
|
|
|
case GPSCallbackType::setBaudrate:
|
|
|
|
|
return gps->setBaudrate(data2);
|
|
|
|
|
|
|
|
|
|
case GPSCallbackType::gotRTCMMessage:
|
|
|
|
|
/* not used */
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GPSCallbackType::surveyInStatus:
|
|
|
|
|
/* not used */
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GPSCallbackType::setClock:
|
|
|
|
|
px4_clock_settime(CLOCK_REALTIME, (timespec *)data1);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int GPS::pollOrRead(uint8_t *buf, size_t buf_length, int timeout)
|
|
|
|
|
{
|
|
|
|
|
handleInjectDataTopic();
|
|
|
|
|
|
|
|
|
|
#ifndef __PX4_QURT
|
|
|
|
|
|
|
|
|
|
/* For non QURT, use the usual polling. */
|
|
|
|
|
|
2016-04-22 09:40:29 +02:00
|
|
|
//Poll only for the serial data. In the same thread we also need to handle orb messages,
|
|
|
|
|
//so ideally we would poll on both, the serial fd and orb subscription. Unfortunately the
|
|
|
|
|
//two pollings use different underlying mechanisms (at least under posix), which makes this
|
|
|
|
|
//impossible. Instead we limit the maximum polling interval and regularly check for new orb
|
|
|
|
|
//messages.
|
|
|
|
|
//FIXME: add a unified poll() API
|
|
|
|
|
const int max_timeout = 50;
|
|
|
|
|
|
2016-04-19 16:22:53 +02:00
|
|
|
pollfd fds[1];
|
|
|
|
|
fds[0].fd = _serial_fd;
|
|
|
|
|
fds[0].events = POLLIN;
|
|
|
|
|
|
2016-04-22 09:40:29 +02:00
|
|
|
int ret = poll(fds, sizeof(fds) / sizeof(fds[0]), math::min(max_timeout, timeout));
|
2016-04-19 16:22:53 +02:00
|
|
|
|
|
|
|
|
if (ret > 0) {
|
|
|
|
|
/* if we have new data from GPS, go handle it */
|
|
|
|
|
if (fds[0].revents & POLLIN) {
|
|
|
|
|
/*
|
|
|
|
|
* We are here because poll says there is some data, so this
|
|
|
|
|
* won't block even on a blocking device. But don't read immediately
|
|
|
|
|
* by 1-2 bytes, wait for some more data to save expensive read() calls.
|
|
|
|
|
* If more bytes are available, we'll go back to poll() again.
|
|
|
|
|
*/
|
|
|
|
|
usleep(GPS_WAIT_BEFORE_READ * 1000);
|
2016-04-22 09:40:29 +02:00
|
|
|
ret = ::read(_serial_fd, buf, buf_length);
|
2016-04-19 16:22:53 +02:00
|
|
|
|
|
|
|
|
} else {
|
2016-04-22 09:40:29 +02:00
|
|
|
ret = -1;
|
2016-04-19 16:22:53 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-22 09:40:29 +02:00
|
|
|
return ret;
|
|
|
|
|
|
2016-04-19 16:22:53 +02:00
|
|
|
#else
|
|
|
|
|
/* For QURT, just use read for now, since this doesn't block, we need to slow it down
|
|
|
|
|
* just a bit. */
|
|
|
|
|
usleep(10000);
|
|
|
|
|
return ::read(_serial_fd, buf, buf_length);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GPS::handleInjectDataTopic()
|
|
|
|
|
{
|
|
|
|
|
if (_orb_inject_data_fd[0] == -1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool updated = false;
|
|
|
|
|
|
2016-04-20 09:50:22 +02:00
|
|
|
do {
|
|
|
|
|
int orb_inject_data_cur_fd = _orb_inject_data_fd[_orb_inject_data_next];
|
|
|
|
|
orb_check(orb_inject_data_cur_fd, &updated);
|
2016-04-19 16:22:53 +02:00
|
|
|
|
2016-04-20 09:50:22 +02:00
|
|
|
if (updated) {
|
|
|
|
|
struct gps_inject_data_s msg;
|
|
|
|
|
orb_copy(ORB_ID(gps_inject_data), orb_inject_data_cur_fd, &msg);
|
|
|
|
|
injectData(msg.data, msg.len);
|
2016-04-19 16:22:53 +02:00
|
|
|
|
2016-04-21 09:56:31 +02:00
|
|
|
_orb_inject_data_next = (_orb_inject_data_next + 1) % _orb_inject_data_fd_count;
|
2016-04-20 09:50:22 +02:00
|
|
|
|
2016-04-25 13:03:33 +02:00
|
|
|
++_last_rate_rtcm_injection_count;
|
2016-04-20 09:50:22 +02:00
|
|
|
}
|
|
|
|
|
} while (updated);
|
2016-04-19 16:22:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GPS::injectData(uint8_t *data, size_t len)
|
|
|
|
|
{
|
|
|
|
|
return ::write(_serial_fd, data, len) == len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int GPS::setBaudrate(unsigned baud)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
#if __PX4_QURT
|
|
|
|
|
// TODO: currently QURT does not support configuration with termios.
|
|
|
|
|
dspal_serial_ioctl_data_rate data_rate;
|
|
|
|
|
|
|
|
|
|
switch (baud) {
|
|
|
|
|
case 9600: data_rate.bit_rate = DSPAL_SIO_BITRATE_9600; break;
|
|
|
|
|
|
|
|
|
|
case 19200: data_rate.bit_rate = DSPAL_SIO_BITRATE_19200; break;
|
|
|
|
|
|
|
|
|
|
case 38400: data_rate.bit_rate = DSPAL_SIO_BITRATE_38400; break;
|
|
|
|
|
|
|
|
|
|
case 57600: data_rate.bit_rate = DSPAL_SIO_BITRATE_57600; break;
|
|
|
|
|
|
|
|
|
|
case 115200: data_rate.bit_rate = DSPAL_SIO_BITRATE_115200; break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
PX4_ERR("ERR: unknown baudrate: %d", baud);
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ret = ::ioctl(_serial_fd, SERIAL_IOCTL_SET_DATA_RATE, (void *)&data_rate);
|
|
|
|
|
|
|
|
|
|
if (ret != 0) {
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
/* process baud rate */
|
|
|
|
|
int speed;
|
|
|
|
|
|
|
|
|
|
switch (baud) {
|
|
|
|
|
case 9600: speed = B9600; break;
|
|
|
|
|
|
|
|
|
|
case 19200: speed = B19200; break;
|
|
|
|
|
|
|
|
|
|
case 38400: speed = B38400; break;
|
|
|
|
|
|
|
|
|
|
case 57600: speed = B57600; break;
|
|
|
|
|
|
|
|
|
|
case 115200: speed = B115200; break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
PX4_ERR("ERR: unknown baudrate: %d", baud);
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct termios uart_config;
|
|
|
|
|
|
|
|
|
|
int termios_state;
|
|
|
|
|
|
|
|
|
|
/* fill the struct for the new configuration */
|
|
|
|
|
tcgetattr(_serial_fd, &uart_config);
|
|
|
|
|
|
|
|
|
|
/* properly configure the terminal (see also https://en.wikibooks.org/wiki/Serial_Programming/termios ) */
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Input flags - Turn off input processing
|
|
|
|
|
//
|
|
|
|
|
// convert break to null byte, no CR to NL translation,
|
|
|
|
|
// no NL to CR translation, don't mark parity errors or breaks
|
|
|
|
|
// no input parity check, don't strip high bit off,
|
|
|
|
|
// no XON/XOFF software flow control
|
|
|
|
|
//
|
|
|
|
|
uart_config.c_iflag &= ~(IGNBRK | BRKINT | ICRNL |
|
|
|
|
|
INLCR | PARMRK | INPCK | ISTRIP | IXON);
|
|
|
|
|
//
|
|
|
|
|
// Output flags - Turn off output processing
|
|
|
|
|
//
|
|
|
|
|
// no CR to NL translation, no NL to CR-NL translation,
|
|
|
|
|
// no NL to CR translation, no column 0 CR suppression,
|
|
|
|
|
// no Ctrl-D suppression, no fill characters, no case mapping,
|
|
|
|
|
// no local output processing
|
|
|
|
|
//
|
|
|
|
|
// config.c_oflag &= ~(OCRNL | ONLCR | ONLRET |
|
|
|
|
|
// ONOCR | ONOEOT| OFILL | OLCUC | OPOST);
|
|
|
|
|
uart_config.c_oflag = 0;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// No line processing
|
|
|
|
|
//
|
|
|
|
|
// echo off, echo newline off, canonical mode off,
|
|
|
|
|
// extended input processing off, signal chars off
|
|
|
|
|
//
|
|
|
|
|
uart_config.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG);
|
|
|
|
|
|
|
|
|
|
/* no parity, one stop bit */
|
|
|
|
|
uart_config.c_cflag &= ~(CSTOPB | PARENB);
|
|
|
|
|
|
|
|
|
|
/* set baud rate */
|
|
|
|
|
if ((termios_state = cfsetispeed(&uart_config, speed)) < 0) {
|
|
|
|
|
GPS_ERR("ERR: %d (cfsetispeed)", termios_state);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((termios_state = cfsetospeed(&uart_config, speed)) < 0) {
|
|
|
|
|
GPS_ERR("ERR: %d (cfsetospeed)", termios_state);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((termios_state = tcsetattr(_serial_fd, TCSANOW, &uart_config)) < 0) {
|
|
|
|
|
GPS_ERR("ERR: %d (tcsetattr)", termios_state);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-02-04 15:57:12 +01:00
|
|
|
void
|
|
|
|
|
GPS::task_main()
|
|
|
|
|
{
|
|
|
|
|
/* open the serial port */
|
2016-04-19 16:22:53 +02:00
|
|
|
_serial_fd = ::open(_port, O_RDWR | O_NOCTTY);
|
2013-02-04 15:57:12 +01:00
|
|
|
|
|
|
|
|
if (_serial_fd < 0) {
|
2016-04-06 10:02:21 +02:00
|
|
|
PX4_ERR("GPS: failed to open serial port: %s err: %d", _port, errno);
|
2016-03-03 12:12:11 +01:00
|
|
|
|
2013-02-04 17:55:58 +01:00
|
|
|
/* tell the dtor that we are exiting, set error code */
|
|
|
|
|
_task = -1;
|
2016-04-06 10:02:21 +02:00
|
|
|
px4_task_exit(1);
|
2013-02-04 15:57:12 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-03 12:12:11 +01:00
|
|
|
#ifndef __PX4_QURT
|
|
|
|
|
// TODO: this call is not supported on Snapdragon just yet.
|
|
|
|
|
// However it seems to be nonblocking anyway and working.
|
|
|
|
|
int flags = fcntl(_serial_fd, F_GETFL, 0);
|
|
|
|
|
fcntl(_serial_fd, F_SETFL, flags | O_NONBLOCK);
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-04-25 13:08:21 +02:00
|
|
|
for (int i = 0; i < _orb_inject_data_fd_count; ++i) {
|
|
|
|
|
_orb_inject_data_fd[i] = orb_subscribe_multi(ORB_ID(gps_inject_data), i);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-04 17:55:58 +01:00
|
|
|
uint64_t last_rate_measurement = hrt_absolute_time();
|
|
|
|
|
unsigned last_rate_count = 0;
|
|
|
|
|
|
2013-02-04 16:27:01 -08:00
|
|
|
/* loop handling received serial bytes and also configuring in between */
|
2013-02-04 15:57:12 +01:00
|
|
|
while (!_task_should_exit) {
|
|
|
|
|
|
2014-01-11 00:46:45 +01:00
|
|
|
if (_fake_gps) {
|
2015-02-13 14:29:59 +01:00
|
|
|
_report_gps_pos.timestamp_position = hrt_absolute_time();
|
|
|
|
|
_report_gps_pos.lat = (int32_t)47.378301e7f;
|
|
|
|
|
_report_gps_pos.lon = (int32_t)8.538777e7f;
|
|
|
|
|
_report_gps_pos.alt = (int32_t)1200e3f;
|
|
|
|
|
_report_gps_pos.timestamp_variance = hrt_absolute_time();
|
|
|
|
|
_report_gps_pos.s_variance_m_s = 10.0f;
|
|
|
|
|
_report_gps_pos.c_variance_rad = 0.1f;
|
|
|
|
|
_report_gps_pos.fix_type = 3;
|
|
|
|
|
_report_gps_pos.eph = 0.9f;
|
|
|
|
|
_report_gps_pos.epv = 1.8f;
|
|
|
|
|
_report_gps_pos.timestamp_velocity = hrt_absolute_time();
|
|
|
|
|
_report_gps_pos.vel_n_m_s = 0.0f;
|
|
|
|
|
_report_gps_pos.vel_e_m_s = 0.0f;
|
|
|
|
|
_report_gps_pos.vel_d_m_s = 0.0f;
|
2015-10-19 13:16:11 +02:00
|
|
|
_report_gps_pos.vel_m_s = sqrtf(_report_gps_pos.vel_n_m_s * _report_gps_pos.vel_n_m_s + _report_gps_pos.vel_e_m_s *
|
|
|
|
|
_report_gps_pos.vel_e_m_s + _report_gps_pos.vel_d_m_s * _report_gps_pos.vel_d_m_s);
|
2015-02-13 14:29:59 +01:00
|
|
|
_report_gps_pos.cog_rad = 0.0f;
|
2015-10-19 13:16:11 +02:00
|
|
|
_report_gps_pos.vel_ned_valid = true;
|
2014-01-11 00:46:45 +01:00
|
|
|
|
2015-07-17 21:19:32 +02:00
|
|
|
/* no time and satellite information simulated */
|
2014-01-11 00:46:45 +01:00
|
|
|
|
2015-02-11 17:57:33 +01:00
|
|
|
|
2016-04-18 16:30:28 +02:00
|
|
|
publish();
|
2014-01-11 00:08:02 +01:00
|
|
|
|
2014-01-11 00:46:45 +01:00
|
|
|
usleep(2e5);
|
2014-01-11 00:08:02 +01:00
|
|
|
|
2014-01-11 00:46:45 +01:00
|
|
|
} else {
|
2013-02-06 20:04:49 -08:00
|
|
|
|
2016-04-19 16:22:53 +02:00
|
|
|
if (_helper != nullptr) {
|
|
|
|
|
delete(_helper);
|
2014-01-11 00:46:45 +01:00
|
|
|
/* set to zero to ensure parser is not used while not instantiated */
|
2016-04-19 16:22:53 +02:00
|
|
|
_helper = nullptr;
|
2014-01-11 00:46:45 +01:00
|
|
|
}
|
2013-09-21 08:59:04 +02:00
|
|
|
|
2014-01-11 00:46:45 +01:00
|
|
|
switch (_mode) {
|
|
|
|
|
case GPS_DRIVER_MODE_UBX:
|
2016-04-19 16:22:53 +02:00
|
|
|
_helper = new GPSDriverUBX(&GPS::callback, this, &_report_gps_pos, _p_report_sat_info);
|
2014-01-11 00:46:45 +01:00
|
|
|
break;
|
2013-09-21 08:59:04 +02:00
|
|
|
|
2014-01-11 00:46:45 +01:00
|
|
|
case GPS_DRIVER_MODE_MTK:
|
2016-04-19 16:22:53 +02:00
|
|
|
_helper = new GPSDriverMTK(&GPS::callback, this, &_report_gps_pos);
|
2014-01-11 00:46:45 +01:00
|
|
|
break;
|
2013-09-21 08:59:04 +02:00
|
|
|
|
2014-09-30 15:44:47 +04:00
|
|
|
case GPS_DRIVER_MODE_ASHTECH:
|
2016-04-19 16:22:53 +02:00
|
|
|
_helper = new GPSDriverAshtech(&GPS::callback, this, &_report_gps_pos, _p_report_sat_info);
|
2014-09-30 15:44:47 +04:00
|
|
|
break;
|
|
|
|
|
|
2014-01-11 00:46:45 +01:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-09-21 08:59:04 +02:00
|
|
|
|
2013-05-05 12:57:21 +02:00
|
|
|
|
2015-07-17 21:19:32 +02:00
|
|
|
/* the Ashtech driver lies about successful configuration and the
|
|
|
|
|
* MTK driver is not well tested, so we really only trust the UBX
|
|
|
|
|
* driver for an advance publication
|
|
|
|
|
*/
|
2016-04-19 16:22:53 +02:00
|
|
|
if (_helper->configure(_baudrate, GPSHelper::OutputMode::GPS) == 0) {
|
2013-05-05 12:57:21 +02:00
|
|
|
|
2015-07-17 21:19:32 +02:00
|
|
|
/* reset report */
|
2015-05-18 12:48:40 +02:00
|
|
|
memset(&_report_gps_pos, 0, sizeof(_report_gps_pos));
|
|
|
|
|
|
2016-01-25 09:30:45 +01:00
|
|
|
if (_mode == GPS_DRIVER_MODE_UBX) {
|
|
|
|
|
/* Publish initial report that we have access to a GPS,
|
|
|
|
|
* but set all critical state fields to indicate we have
|
|
|
|
|
* no valid position lock
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
_report_gps_pos.timestamp_time = hrt_absolute_time();
|
|
|
|
|
|
|
|
|
|
/* reset the timestamps for data, because we have no data yet */
|
|
|
|
|
_report_gps_pos.timestamp_position = 0;
|
|
|
|
|
_report_gps_pos.timestamp_variance = 0;
|
|
|
|
|
_report_gps_pos.timestamp_velocity = 0;
|
|
|
|
|
|
|
|
|
|
/* set a massive variance */
|
|
|
|
|
_report_gps_pos.eph = 10000.0f;
|
|
|
|
|
_report_gps_pos.epv = 10000.0f;
|
|
|
|
|
_report_gps_pos.fix_type = 0;
|
|
|
|
|
|
2016-04-18 16:30:28 +02:00
|
|
|
publish();
|
2016-01-25 09:30:45 +01:00
|
|
|
|
|
|
|
|
/* GPS is obviously detected successfully, reset statistics */
|
2016-04-19 16:22:53 +02:00
|
|
|
_helper->resetUpdateRates();
|
2016-01-25 09:30:45 +01:00
|
|
|
}
|
2013-09-21 08:59:04 +02:00
|
|
|
|
2014-06-08 14:05:35 +02:00
|
|
|
int helper_ret;
|
2015-10-19 13:16:11 +02:00
|
|
|
|
2016-04-19 16:22:53 +02:00
|
|
|
while ((helper_ret = _helper->receive(TIMEOUT_5HZ)) > 0 && !_task_should_exit) {
|
2013-02-04 15:57:12 +01:00
|
|
|
|
2016-03-03 12:12:11 +01:00
|
|
|
if (helper_ret & 1) {
|
2016-04-18 16:30:28 +02:00
|
|
|
publish();
|
2016-04-19 17:05:37 +02:00
|
|
|
|
2016-04-19 16:22:53 +02:00
|
|
|
last_rate_count++;
|
2016-03-03 12:12:11 +01:00
|
|
|
}
|
2015-10-19 13:16:11 +02:00
|
|
|
|
2016-03-03 12:12:11 +01:00
|
|
|
if (_p_report_sat_info && (helper_ret & 2)) {
|
2016-04-18 16:30:28 +02:00
|
|
|
publish();
|
2014-01-11 00:46:45 +01:00
|
|
|
}
|
2013-02-04 15:57:12 +01:00
|
|
|
|
2014-01-11 00:46:45 +01:00
|
|
|
/* measure update rate every 5 seconds */
|
|
|
|
|
if (hrt_absolute_time() - last_rate_measurement > RATE_MEASUREMENT_PERIOD) {
|
2016-04-25 13:03:33 +02:00
|
|
|
float dt = (float)((hrt_absolute_time() - last_rate_measurement)) / 1000000.0f;
|
|
|
|
|
_rate = last_rate_count / dt;
|
|
|
|
|
_rate_rtcm_injection = _last_rate_rtcm_injection_count / dt;
|
2014-01-11 00:46:45 +01:00
|
|
|
last_rate_measurement = hrt_absolute_time();
|
|
|
|
|
last_rate_count = 0;
|
2016-04-25 13:03:33 +02:00
|
|
|
_last_rate_rtcm_injection_count = 0;
|
2016-04-19 16:22:53 +02:00
|
|
|
_helper->storeUpdateRates();
|
|
|
|
|
_helper->resetUpdateRates();
|
2014-01-11 00:46:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_healthy) {
|
2016-03-13 15:40:39 +01:00
|
|
|
// Helpful for debugging, but too verbose for normal ops
|
2016-03-12 17:14:27 +01:00
|
|
|
// const char *mode_str = "unknown";
|
|
|
|
|
//
|
|
|
|
|
// switch (_mode) {
|
|
|
|
|
// case GPS_DRIVER_MODE_UBX:
|
|
|
|
|
// mode_str = "UBX";
|
|
|
|
|
// break;
|
|
|
|
|
//
|
|
|
|
|
// case GPS_DRIVER_MODE_MTK:
|
|
|
|
|
// mode_str = "MTK";
|
|
|
|
|
// break;
|
|
|
|
|
//
|
|
|
|
|
// case GPS_DRIVER_MODE_ASHTECH:
|
|
|
|
|
// mode_str = "ASHTECH";
|
|
|
|
|
// break;
|
|
|
|
|
//
|
|
|
|
|
// default:
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// PX4_WARN("module found: %s", mode_str);
|
2014-01-11 00:46:45 +01:00
|
|
|
_healthy = true;
|
2013-09-21 08:59:04 +02:00
|
|
|
}
|
2014-01-11 00:46:45 +01:00
|
|
|
}
|
2013-09-21 08:59:04 +02:00
|
|
|
|
2014-01-11 00:46:45 +01:00
|
|
|
if (_healthy) {
|
2016-04-19 16:22:53 +02:00
|
|
|
PX4_WARN("GPS module lost");
|
2014-01-11 00:46:45 +01:00
|
|
|
_healthy = false;
|
|
|
|
|
_rate = 0.0f;
|
2016-04-25 13:03:33 +02:00
|
|
|
_rate_rtcm_injection = 0.0f;
|
2013-02-04 15:57:12 +01:00
|
|
|
}
|
2013-02-07 14:48:00 -08:00
|
|
|
}
|
2013-02-08 11:05:57 -08:00
|
|
|
|
2014-01-11 00:46:45 +01:00
|
|
|
/* select next mode */
|
|
|
|
|
switch (_mode) {
|
|
|
|
|
case GPS_DRIVER_MODE_UBX:
|
|
|
|
|
_mode = GPS_DRIVER_MODE_MTK;
|
|
|
|
|
break;
|
2013-02-08 11:05:57 -08:00
|
|
|
|
2014-01-11 00:46:45 +01:00
|
|
|
case GPS_DRIVER_MODE_MTK:
|
2014-10-09 11:15:11 +04:00
|
|
|
_mode = GPS_DRIVER_MODE_ASHTECH;
|
|
|
|
|
break;
|
2014-09-30 15:44:47 +04:00
|
|
|
|
2014-10-09 11:15:11 +04:00
|
|
|
case GPS_DRIVER_MODE_ASHTECH:
|
2014-01-11 00:46:45 +01:00
|
|
|
_mode = GPS_DRIVER_MODE_UBX;
|
|
|
|
|
break;
|
2013-09-21 08:59:04 +02:00
|
|
|
|
2014-01-11 00:46:45 +01:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-02-08 11:05:57 -08:00
|
|
|
}
|
|
|
|
|
|
2013-02-04 15:57:12 +01:00
|
|
|
}
|
2013-09-21 08:59:04 +02:00
|
|
|
|
2016-03-03 12:12:11 +01:00
|
|
|
PX4_WARN("exiting");
|
2013-02-04 15:57:12 +01:00
|
|
|
|
2016-04-25 13:08:21 +02:00
|
|
|
for (size_t i = 0; i < _orb_inject_data_fd_count; ++i) {
|
|
|
|
|
orb_unsubscribe(_orb_inject_data_fd[i]);
|
|
|
|
|
_orb_inject_data_fd[i] = -1;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-04 15:57:12 +01:00
|
|
|
::close(_serial_fd);
|
|
|
|
|
|
2016-05-04 09:13:37 +02:00
|
|
|
orb_unadvertise(_report_gps_pos_pub);
|
|
|
|
|
|
2013-02-04 15:57:12 +01:00
|
|
|
/* tell the dtor that we are exiting */
|
|
|
|
|
_task = -1;
|
2016-03-03 12:12:11 +01:00
|
|
|
px4_task_exit(0);
|
2013-02-04 15:57:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
GPS::cmd_reset()
|
|
|
|
|
{
|
2014-05-13 09:41:41 -07:00
|
|
|
#ifdef GPIO_GPS_NRESET
|
2016-03-03 12:12:11 +01:00
|
|
|
PX4_WARN("Toggling GPS reset pin");
|
2014-05-13 09:41:41 -07:00
|
|
|
stm32_configgpio(GPIO_GPS_NRESET);
|
|
|
|
|
stm32_gpiowrite(GPIO_GPS_NRESET, 0);
|
|
|
|
|
usleep(100);
|
|
|
|
|
stm32_gpiowrite(GPIO_GPS_NRESET, 1);
|
2016-03-03 12:12:11 +01:00
|
|
|
PX4_WARN("Toggled GPS reset pin");
|
2014-05-13 09:41:41 -07:00
|
|
|
#endif
|
2013-02-04 15:57:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
GPS::print_info()
|
|
|
|
|
{
|
2015-02-11 17:57:33 +01:00
|
|
|
//GPS Mode
|
2015-10-19 13:16:11 +02:00
|
|
|
if (_fake_gps) {
|
2016-03-03 12:12:11 +01:00
|
|
|
PX4_WARN("protocol: SIMULATED");
|
2015-02-11 17:57:33 +01:00
|
|
|
}
|
2013-09-21 08:59:04 +02:00
|
|
|
|
2015-02-11 17:57:33 +01:00
|
|
|
else {
|
|
|
|
|
switch (_mode) {
|
|
|
|
|
case GPS_DRIVER_MODE_UBX:
|
2016-03-03 12:12:11 +01:00
|
|
|
PX4_WARN("protocol: UBX");
|
2015-02-11 17:57:33 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GPS_DRIVER_MODE_MTK:
|
2016-03-03 12:12:11 +01:00
|
|
|
PX4_WARN("protocol: MTK");
|
2015-02-11 17:57:33 +01:00
|
|
|
break;
|
2013-09-21 08:59:04 +02:00
|
|
|
|
2015-10-19 13:16:11 +02:00
|
|
|
case GPS_DRIVER_MODE_ASHTECH:
|
2016-03-03 12:12:11 +01:00
|
|
|
PX4_WARN("protocol: ASHTECH");
|
2015-10-19 13:16:11 +02:00
|
|
|
break;
|
2014-09-30 15:44:47 +04:00
|
|
|
|
2015-02-11 17:57:33 +01:00
|
|
|
default:
|
|
|
|
|
break;
|
2015-10-19 13:16:11 +02:00
|
|
|
}
|
2013-02-04 17:55:58 +01:00
|
|
|
}
|
2013-09-21 08:59:04 +02:00
|
|
|
|
2016-03-03 12:12:11 +01:00
|
|
|
PX4_WARN("port: %s, baudrate: %d, status: %s", _port, _baudrate, (_healthy) ? "OK" : "NOT OK");
|
|
|
|
|
PX4_WARN("sat info: %s, noise: %d, jamming detected: %s",
|
|
|
|
|
(_p_report_sat_info != nullptr) ? "enabled" : "disabled",
|
|
|
|
|
_report_gps_pos.noise_per_ms,
|
|
|
|
|
_report_gps_pos.jamming_indicator == 255 ? "YES" : "NO");
|
2013-09-21 08:59:04 +02:00
|
|
|
|
2014-06-08 14:05:35 +02:00
|
|
|
if (_report_gps_pos.timestamp_position != 0) {
|
2016-04-19 16:22:53 +02:00
|
|
|
PX4_WARN("position lock: %d, satellites: %d, last update: %8.4fms ago", (int)_report_gps_pos.fix_type,
|
2016-03-03 12:12:11 +01:00
|
|
|
_report_gps_pos.satellites_used, (double)(hrt_absolute_time() - _report_gps_pos.timestamp_position) / 1000.0);
|
|
|
|
|
PX4_WARN("lat: %d, lon: %d, alt: %d", _report_gps_pos.lat, _report_gps_pos.lon, _report_gps_pos.alt);
|
|
|
|
|
PX4_WARN("vel: %.2fm/s, %.2fm/s, %.2fm/s", (double)_report_gps_pos.vel_n_m_s,
|
|
|
|
|
(double)_report_gps_pos.vel_e_m_s, (double)_report_gps_pos.vel_d_m_s);
|
|
|
|
|
PX4_WARN("hdop: %.2f, vdop: %.2f", (double)_report_gps_pos.hdop, (double)_report_gps_pos.vdop);
|
|
|
|
|
PX4_WARN("eph: %.2fm, epv: %.2fm", (double)_report_gps_pos.eph, (double)_report_gps_pos.epv);
|
2016-04-25 13:03:33 +02:00
|
|
|
PX4_WARN("rate position: \t\t%6.2f Hz", (double)_helper->getPositionUpdateRate());
|
|
|
|
|
PX4_WARN("rate velocity: \t\t%6.2f Hz", (double)_helper->getVelocityUpdateRate());
|
|
|
|
|
PX4_WARN("rate publication:\t\t%6.2f Hz", (double)_rate);
|
|
|
|
|
PX4_WARN("rate RTCM injection:\t%6.2f Hz", (double)_rate_rtcm_injection);
|
2013-05-05 12:57:21 +02:00
|
|
|
|
2013-02-04 17:55:58 +01:00
|
|
|
}
|
2013-02-04 16:27:01 -08:00
|
|
|
|
|
|
|
|
usleep(100000);
|
2013-02-04 15:57:12 +01:00
|
|
|
}
|
|
|
|
|
|
2016-04-18 16:30:28 +02:00
|
|
|
void
|
|
|
|
|
GPS::publish()
|
|
|
|
|
{
|
2016-04-28 08:43:37 +02:00
|
|
|
orb_publish_auto(ORB_ID(vehicle_gps_position), &_report_gps_pos_pub, &_report_gps_pos, &_gps_orb_instance,
|
|
|
|
|
ORB_PRIO_DEFAULT);
|
2016-04-18 16:30:28 +02:00
|
|
|
}
|
|
|
|
|
|
2013-02-04 15:57:12 +01:00
|
|
|
/**
|
|
|
|
|
* Local functions in support of the shell command.
|
|
|
|
|
*/
|
|
|
|
|
namespace gps
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
2016-04-18 16:30:28 +02:00
|
|
|
void start(const char *uart_path, bool fake_gps, bool enable_sat_info, int gps_num);
|
2013-02-04 15:57:12 +01:00
|
|
|
void stop();
|
|
|
|
|
void test();
|
|
|
|
|
void reset();
|
|
|
|
|
void info();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Start the driver.
|
|
|
|
|
*/
|
|
|
|
|
void
|
2016-04-18 16:30:28 +02:00
|
|
|
start(const char *uart_path, bool fake_gps, bool enable_sat_info, int gps_num)
|
2013-02-04 15:57:12 +01:00
|
|
|
{
|
2016-04-18 16:30:28 +02:00
|
|
|
if (gps_num == 1) {
|
2016-05-04 09:50:07 +02:00
|
|
|
if (g_dev[0] != nullptr) {
|
2016-04-18 16:30:28 +02:00
|
|
|
PX4_WARN("GPS 1 already started");
|
2016-05-04 09:13:37 +02:00
|
|
|
return;
|
2016-04-18 16:30:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* create the driver */
|
2016-05-04 09:50:07 +02:00
|
|
|
g_dev[0] = new GPS(uart_path, fake_gps, enable_sat_info, gps_num);
|
2016-04-18 16:30:28 +02:00
|
|
|
|
2016-05-04 09:50:07 +02:00
|
|
|
if (g_dev[0] == nullptr) {
|
2016-04-18 16:30:28 +02:00
|
|
|
goto fail1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-04 09:50:07 +02:00
|
|
|
if (OK != g_dev[0]->init()) {
|
2016-04-18 16:30:28 +02:00
|
|
|
goto fail1;
|
|
|
|
|
}
|
2016-04-19 16:22:53 +02:00
|
|
|
return;
|
2013-02-04 15:57:12 +01:00
|
|
|
|
2016-04-18 16:30:28 +02:00
|
|
|
} else {
|
|
|
|
|
if (gps_num == 2) {
|
2016-05-04 09:50:07 +02:00
|
|
|
if (g_dev[1] != nullptr) {
|
2016-04-18 16:30:28 +02:00
|
|
|
PX4_WARN("GPS 2 already started");
|
2016-05-04 09:13:37 +02:00
|
|
|
return;
|
2016-04-18 16:30:28 +02:00
|
|
|
}
|
2013-02-04 15:57:12 +01:00
|
|
|
|
2016-04-18 16:30:28 +02:00
|
|
|
/* create the driver */
|
2016-05-04 09:50:07 +02:00
|
|
|
g_dev[1] = new GPS(uart_path, fake_gps, enable_sat_info, gps_num);
|
2016-04-18 16:30:28 +02:00
|
|
|
|
2016-05-04 09:50:07 +02:00
|
|
|
if (g_dev[1] == nullptr) {
|
2016-04-18 16:30:28 +02:00
|
|
|
goto fail2;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-04 09:50:07 +02:00
|
|
|
if (OK != g_dev[1]->init()) {
|
2016-04-18 16:30:28 +02:00
|
|
|
goto fail2;
|
|
|
|
|
}
|
|
|
|
|
return;
|
2016-05-04 09:13:37 +02:00
|
|
|
|
2016-04-18 16:30:28 +02:00
|
|
|
}
|
2015-10-19 13:16:11 +02:00
|
|
|
}
|
2013-02-04 15:57:12 +01:00
|
|
|
|
|
|
|
|
|
2016-04-18 16:30:28 +02:00
|
|
|
fail1:
|
2013-02-04 15:57:12 +01:00
|
|
|
|
2016-05-04 09:50:07 +02:00
|
|
|
if (g_dev[0] != nullptr) {
|
|
|
|
|
delete g_dev[0];
|
|
|
|
|
g_dev[0] = nullptr;
|
2013-02-04 15:57:12 +01:00
|
|
|
}
|
|
|
|
|
|
2016-04-18 16:30:28 +02:00
|
|
|
PX4_ERR("start of GPS 1 failed");
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
fail2:
|
|
|
|
|
|
2016-05-04 09:50:07 +02:00
|
|
|
if (g_dev[1] != nullptr) {
|
|
|
|
|
delete g_dev[1];
|
|
|
|
|
g_dev[1] = nullptr;
|
2016-04-18 16:30:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PX4_ERR("start of GPS 2 failed");
|
2016-03-03 12:12:11 +01:00
|
|
|
return;
|
2013-02-04 15:57:12 +01:00
|
|
|
}
|
|
|
|
|
|
2013-02-04 16:27:01 -08:00
|
|
|
/**
|
|
|
|
|
* Stop the driver.
|
|
|
|
|
*/
|
2013-02-04 15:57:12 +01:00
|
|
|
void
|
|
|
|
|
stop()
|
|
|
|
|
{
|
2016-05-04 09:50:07 +02:00
|
|
|
delete g_dev[0];
|
|
|
|
|
g_dev[0] = nullptr;
|
2016-04-18 16:30:28 +02:00
|
|
|
|
2016-05-04 09:50:07 +02:00
|
|
|
if (g_dev[1] != nullptr) {
|
|
|
|
|
delete g_dev[1];
|
2016-04-18 16:30:28 +02:00
|
|
|
}
|
2016-04-28 08:43:37 +02:00
|
|
|
|
2016-05-04 09:50:07 +02:00
|
|
|
g_dev[1] = nullptr;
|
2016-04-18 16:30:28 +02:00
|
|
|
|
|
|
|
|
px4_task_exit(0);
|
2013-02-04 15:57:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Perform some basic functional tests on the driver;
|
|
|
|
|
* make sure we can collect data from the sensor in polled
|
|
|
|
|
* and automatic modes.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
test()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
errx(0, "PASS");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reset the driver.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
reset()
|
|
|
|
|
{
|
2016-03-03 12:12:11 +01:00
|
|
|
PX4_ERR("GPS reset not supported");
|
|
|
|
|
return;
|
2013-02-04 15:57:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Print the status of the driver.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
info()
|
|
|
|
|
{
|
2016-05-04 09:50:07 +02:00
|
|
|
if (g_dev[0] == nullptr) {
|
2016-04-06 10:02:21 +02:00
|
|
|
PX4_ERR("GPS Not running");
|
|
|
|
|
return;
|
2015-10-19 13:16:11 +02:00
|
|
|
}
|
2013-02-04 15:57:12 +01:00
|
|
|
|
2016-05-04 09:50:07 +02:00
|
|
|
g_dev[0]->print_info();
|
2016-04-18 16:30:28 +02:00
|
|
|
|
2016-05-04 09:50:07 +02:00
|
|
|
if (g_dev[1] != nullptr) {
|
|
|
|
|
g_dev[1]->print_info();
|
2016-04-18 16:30:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
2013-02-04 15:57:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
gps_main(int argc, char *argv[])
|
|
|
|
|
{
|
2013-02-05 13:47:31 +01:00
|
|
|
/* set to default */
|
2014-06-08 14:05:35 +02:00
|
|
|
const char *device_name = GPS_DEFAULT_UART_PORT;
|
2016-04-18 16:30:28 +02:00
|
|
|
const char *device_name2 = nullptr;
|
2014-01-11 00:46:45 +01:00
|
|
|
bool fake_gps = false;
|
2014-06-08 17:54:50 +02:00
|
|
|
bool enable_sat_info = false;
|
2013-02-05 13:47:31 +01:00
|
|
|
|
2016-04-19 08:37:30 +03:00
|
|
|
if (argc < 2) {
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-04 15:57:12 +01:00
|
|
|
/*
|
|
|
|
|
* Start/load the driver.
|
|
|
|
|
*/
|
2013-02-05 13:47:31 +01:00
|
|
|
if (!strcmp(argv[1], "start")) {
|
|
|
|
|
/* work around getopt unreliability */
|
|
|
|
|
if (argc > 3) {
|
|
|
|
|
if (!strcmp(argv[2], "-d")) {
|
|
|
|
|
device_name = argv[3];
|
2013-09-21 08:59:04 +02:00
|
|
|
|
2013-02-05 13:47:31 +01:00
|
|
|
} else {
|
2016-03-03 12:12:11 +01:00
|
|
|
PX4_ERR("DID NOT GET -d");
|
2013-02-05 13:47:31 +01:00
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-21 08:59:04 +02:00
|
|
|
|
2014-01-11 00:46:45 +01:00
|
|
|
/* Detect fake gps option */
|
|
|
|
|
for (int i = 2; i < argc; i++) {
|
2015-10-19 13:16:11 +02:00
|
|
|
if (!strcmp(argv[i], "-f")) {
|
2014-01-11 00:46:45 +01:00
|
|
|
fake_gps = true;
|
2015-10-19 13:16:11 +02:00
|
|
|
}
|
2014-01-11 00:46:45 +01:00
|
|
|
}
|
|
|
|
|
|
2014-06-08 17:54:50 +02:00
|
|
|
/* Detect sat info option */
|
|
|
|
|
for (int i = 2; i < argc; i++) {
|
2015-10-19 13:16:11 +02:00
|
|
|
if (!strcmp(argv[i], "-s")) {
|
2014-06-08 17:54:50 +02:00
|
|
|
enable_sat_info = true;
|
2015-10-19 13:16:11 +02:00
|
|
|
}
|
2014-06-08 17:54:50 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-18 16:30:28 +02:00
|
|
|
/* Allow to use a second gps device */
|
|
|
|
|
for (int i = 2; i < argc; i++) {
|
|
|
|
|
if (!strcmp(argv[i], "-dualgps")) {
|
|
|
|
|
if (argc > i + 1) {
|
|
|
|
|
device_name2 = argv[i + 1];
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
PX4_ERR("Did not get second device address");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gps::start(device_name, fake_gps, enable_sat_info, 1);
|
|
|
|
|
|
|
|
|
|
if (!(device_name2 == nullptr)) {
|
|
|
|
|
gps::start(device_name2, fake_gps, enable_sat_info, 2);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-05 13:47:31 +01:00
|
|
|
}
|
2013-02-04 15:57:12 +01:00
|
|
|
|
2015-10-19 13:16:11 +02:00
|
|
|
if (!strcmp(argv[1], "stop")) {
|
2013-02-04 15:57:12 +01:00
|
|
|
gps::stop();
|
2015-10-19 13:16:11 +02:00
|
|
|
}
|
2013-09-21 08:59:04 +02:00
|
|
|
|
2013-02-04 15:57:12 +01:00
|
|
|
/*
|
|
|
|
|
* Test the driver/device.
|
|
|
|
|
*/
|
2015-10-19 13:16:11 +02:00
|
|
|
if (!strcmp(argv[1], "test")) {
|
2013-02-04 15:57:12 +01:00
|
|
|
gps::test();
|
2015-10-19 13:16:11 +02:00
|
|
|
}
|
2013-02-04 15:57:12 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Reset the driver.
|
|
|
|
|
*/
|
2015-10-19 13:16:11 +02:00
|
|
|
if (!strcmp(argv[1], "reset")) {
|
2013-02-04 15:57:12 +01:00
|
|
|
gps::reset();
|
2015-10-19 13:16:11 +02:00
|
|
|
}
|
2013-02-04 15:57:12 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Print driver status.
|
|
|
|
|
*/
|
2015-10-19 13:16:11 +02:00
|
|
|
if (!strcmp(argv[1], "status")) {
|
2013-02-04 15:57:12 +01:00
|
|
|
gps::info();
|
2015-10-19 13:16:11 +02:00
|
|
|
}
|
2013-02-04 15:57:12 +01:00
|
|
|
|
2016-03-03 12:12:11 +01:00
|
|
|
return 0;
|
|
|
|
|
|
2013-02-05 13:47:31 +01:00
|
|
|
out:
|
2016-03-03 12:12:11 +01:00
|
|
|
PX4_ERR("unrecognized command, try 'start', 'stop', 'test', 'reset' or 'status'\n [-d /dev/ttyS0-n][-f (for enabling fake)][-s (to enable sat info)]");
|
|
|
|
|
return 1;
|
2013-02-04 15:57:12 +01:00
|
|
|
}
|