2010-08-13 18:34:07 +00:00
|
|
|
//
|
2011-03-24 01:48:30 +00:00
|
|
|
// Copyright 2010-2011 Ettus Research LLC
|
2010-08-13 18:34:07 +00:00
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
//
|
|
|
|
|
|
2011-01-18 06:51:14 +00:00
|
|
|
#include <uhd/usrp/gps_ctrl.hpp>
|
2011-05-05 02:53:01 +00:00
|
|
|
#include <uhd/utils/msg.hpp>
|
2011-02-24 22:54:24 +00:00
|
|
|
#include <uhd/exception.hpp>
|
2011-06-17 20:01:07 +00:00
|
|
|
#include <uhd/types/sensors.hpp>
|
|
|
|
|
#include <boost/algorithm/string.hpp>
|
2011-06-17 22:38:20 +00:00
|
|
|
#include <boost/assign/list_of.hpp>
|
2010-08-13 18:34:07 +00:00
|
|
|
#include <boost/cstdint.hpp>
|
|
|
|
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
2011-02-24 22:54:24 +00:00
|
|
|
#include <boost/thread/thread.hpp>
|
2010-08-13 23:16:22 +00:00
|
|
|
#include <boost/tokenizer.hpp>
|
2011-08-11 20:30:25 +00:00
|
|
|
#include <boost/format.hpp>
|
2012-10-18 18:24:28 +00:00
|
|
|
#include <boost/regex.hpp>
|
|
|
|
|
|
|
|
|
|
#include "boost/tuple/tuple.hpp"
|
|
|
|
|
#include "boost/foreach.hpp"
|
2010-08-13 18:34:07 +00:00
|
|
|
|
|
|
|
|
using namespace uhd;
|
|
|
|
|
using namespace boost::gregorian;
|
|
|
|
|
using namespace boost::posix_time;
|
2010-08-13 23:16:22 +00:00
|
|
|
using namespace boost::algorithm;
|
2011-06-17 22:38:20 +00:00
|
|
|
using namespace boost::this_thread;
|
2010-08-13 18:34:07 +00:00
|
|
|
|
|
|
|
|
/*!
|
2014-02-04 19:04:07 +00:00
|
|
|
* A control for GPSDO devices
|
2010-08-13 18:34:07 +00:00
|
|
|
*/
|
|
|
|
|
|
2011-01-18 06:51:14 +00:00
|
|
|
class gps_ctrl_impl : public gps_ctrl{
|
2012-10-18 18:24:28 +00:00
|
|
|
private:
|
|
|
|
|
std::map<std::string, boost::tuple<std::string, boost::system_time, bool> > sensors;
|
|
|
|
|
|
|
|
|
|
std::string get_cached_sensor(const std::string sensor, const int freshness, const bool once, const bool touch=true) {
|
|
|
|
|
boost::system_time time = boost::get_system_time();
|
|
|
|
|
try {
|
|
|
|
|
// this is nasty ...
|
|
|
|
|
//std::cout << boost::format("Requested %s - seen? ") % sensor << sensors[sensor].get<2>() << " once? " << once << std::endl;
|
|
|
|
|
if(time - sensors[sensor].get<1>() < milliseconds(freshness) && (!once or !sensors[sensor].get<2>())) {
|
|
|
|
|
sensors[sensor] = boost::make_tuple(sensors[sensor].get<0>(), sensors[sensor].get<1>(), touch);
|
|
|
|
|
return sensors[sensor].get<0>();
|
|
|
|
|
} else {
|
|
|
|
|
return update_cached_sensors(sensor);
|
|
|
|
|
}
|
|
|
|
|
} catch(std::exception &e) {
|
|
|
|
|
UHD_MSG(warning) << "get_cached_sensor: " << e.what();
|
|
|
|
|
}
|
|
|
|
|
return std::string();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string update_cached_sensors(const std::string sensor) {
|
2014-02-04 19:04:07 +00:00
|
|
|
if(not gps_detected() || (gps_type != GPS_TYPE_INTERNAL_GPSDO)) {
|
2012-10-18 18:24:28 +00:00
|
|
|
UHD_MSG(error) << "get_stat(): unsupported GPS or no GPS detected";
|
|
|
|
|
return std::string();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-14 20:05:07 +00:00
|
|
|
const std::list<std::string> list = boost::assign::list_of("GPGGA")("GPRMC")("SERVO");
|
2012-10-18 18:24:28 +00:00
|
|
|
static const boost::regex status_regex("\\d\\d-\\d\\d-\\d\\d");
|
2014-02-14 20:05:07 +00:00
|
|
|
std::map<std::string,std::string> msgs;
|
|
|
|
|
|
|
|
|
|
// Get all GPSDO messages available
|
|
|
|
|
// Creating a map here because we only want the latest of each message type
|
2014-05-06 23:11:10 +00:00
|
|
|
for (std::string msg = _recv(); msg.length(); msg = _recv())
|
2014-02-14 20:05:07 +00:00
|
|
|
{
|
2014-05-06 23:11:10 +00:00
|
|
|
if (msg.length() < 6)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Strip any end of line characters
|
|
|
|
|
erase_all(msg, "\r");
|
|
|
|
|
erase_all(msg, "\n");
|
|
|
|
|
|
2014-02-14 20:05:07 +00:00
|
|
|
// Look for SERVO message
|
|
|
|
|
if (boost::regex_search(msg, status_regex, boost::regex_constants::match_continuous))
|
|
|
|
|
msgs["SERVO"] = msg;
|
|
|
|
|
else
|
|
|
|
|
msgs[msg.substr(1,5)] = msg;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-18 18:24:28 +00:00
|
|
|
boost::system_time time = boost::get_system_time();
|
|
|
|
|
|
2014-02-14 20:05:07 +00:00
|
|
|
// Update sensors with newly read data
|
2012-10-18 18:24:28 +00:00
|
|
|
BOOST_FOREACH(std::string key, list) {
|
2014-02-14 20:05:07 +00:00
|
|
|
if (msgs[key].length())
|
|
|
|
|
sensors[key] = boost::make_tuple(msgs[key], time, !sensor.compare(key));
|
2012-10-18 18:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
2014-02-14 20:05:07 +00:00
|
|
|
// Return requested sensor if it was updated
|
|
|
|
|
if (msgs[sensor].length())
|
|
|
|
|
return msgs[sensor];
|
|
|
|
|
|
2012-10-18 18:24:28 +00:00
|
|
|
return std::string();
|
|
|
|
|
}
|
2014-02-14 20:05:07 +00:00
|
|
|
|
2010-08-13 18:34:07 +00:00
|
|
|
public:
|
2011-09-09 20:39:52 +00:00
|
|
|
gps_ctrl_impl(uart_iface::sptr uart){
|
|
|
|
|
_uart = uart;
|
2010-08-13 18:34:07 +00:00
|
|
|
|
2012-10-18 18:24:28 +00:00
|
|
|
|
2010-08-13 18:34:07 +00:00
|
|
|
std::string reply;
|
2010-08-16 23:09:52 +00:00
|
|
|
bool i_heard_some_nmea = false, i_heard_something_weird = false;
|
|
|
|
|
gps_type = GPS_TYPE_NONE;
|
2012-10-18 18:24:28 +00:00
|
|
|
|
2014-02-04 19:04:07 +00:00
|
|
|
//first we look for an internal GPSDO
|
2011-09-09 20:39:52 +00:00
|
|
|
_flush(); //get whatever junk is in the rx buffer right now, and throw it away
|
2013-12-20 00:13:41 +00:00
|
|
|
_send("HAAAY GUYYYYS\n"); //to elicit a response from the GPSDO
|
2010-08-16 23:09:52 +00:00
|
|
|
|
2011-09-09 20:39:52 +00:00
|
|
|
//wait for _send(...) to return
|
2014-02-04 19:04:07 +00:00
|
|
|
sleep(milliseconds(GPSDO_STUPID_DELAY_MS));
|
2011-08-05 17:17:50 +00:00
|
|
|
|
2010-08-16 23:09:52 +00:00
|
|
|
//then we loop until we either timeout, or until we get a response that indicates we're a JL device
|
2011-09-22 18:34:58 +00:00
|
|
|
const boost::system_time comm_timeout = boost::get_system_time() + milliseconds(GPS_COMM_TIMEOUT_MS);
|
|
|
|
|
while(boost::get_system_time() < comm_timeout) {
|
2011-06-17 22:38:20 +00:00
|
|
|
reply = _recv();
|
|
|
|
|
if(reply.find("Command Error") != std::string::npos) {
|
2014-02-04 19:04:07 +00:00
|
|
|
gps_type = GPS_TYPE_INTERNAL_GPSDO;
|
2010-08-16 23:09:52 +00:00
|
|
|
break;
|
2012-10-18 18:24:28 +00:00
|
|
|
}
|
2010-08-16 23:09:52 +00:00
|
|
|
else if(reply.substr(0, 3) == "$GP") i_heard_some_nmea = true; //but keep looking for that "Command Error" response
|
|
|
|
|
else if(reply.length() != 0) i_heard_something_weird = true; //probably wrong baud rate
|
2011-09-22 18:34:58 +00:00
|
|
|
sleep(milliseconds(GPS_TIMEOUT_DELAY_MS));
|
2010-08-13 18:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
2014-02-04 19:04:07 +00:00
|
|
|
if((i_heard_some_nmea) && (gps_type != GPS_TYPE_INTERNAL_GPSDO)) gps_type = GPS_TYPE_GENERIC_NMEA;
|
2010-08-16 23:09:52 +00:00
|
|
|
|
|
|
|
|
if((gps_type == GPS_TYPE_NONE) && i_heard_something_weird) {
|
2011-05-05 02:53:01 +00:00
|
|
|
UHD_MSG(error) << "GPS invalid reply \"" << reply << "\", assuming none available" << std::endl;
|
2010-08-16 23:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
2010-08-13 18:34:07 +00:00
|
|
|
switch(gps_type) {
|
2014-02-04 19:04:07 +00:00
|
|
|
case GPS_TYPE_INTERNAL_GPSDO:
|
|
|
|
|
UHD_MSG(status) << "Found an internal GPSDO" << std::endl;
|
2013-12-20 00:13:41 +00:00
|
|
|
init_gpsdo();
|
2011-08-11 20:30:25 +00:00
|
|
|
break;
|
2010-08-13 18:34:07 +00:00
|
|
|
|
|
|
|
|
case GPS_TYPE_GENERIC_NMEA:
|
2014-02-04 19:04:07 +00:00
|
|
|
UHD_MSG(status) << "Found a generic NMEA GPS device" << std::endl;
|
2010-08-16 23:09:52 +00:00
|
|
|
break;
|
|
|
|
|
|
2010-08-13 18:34:07 +00:00
|
|
|
case GPS_TYPE_NONE:
|
|
|
|
|
default:
|
2014-02-04 19:04:07 +00:00
|
|
|
UHD_MSG(status) << "No GPSDO found" << std::endl;
|
2010-08-13 18:34:07 +00:00
|
|
|
break;
|
2010-08-16 23:09:52 +00:00
|
|
|
|
2010-08-13 18:34:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-18 06:51:14 +00:00
|
|
|
~gps_ctrl_impl(void){
|
2011-06-17 22:38:20 +00:00
|
|
|
/* NOP */
|
2010-08-13 18:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
2011-06-17 22:38:20 +00:00
|
|
|
//return a list of supported sensors
|
|
|
|
|
std::vector<std::string> get_sensors(void) {
|
|
|
|
|
std::vector<std::string> ret = boost::assign::list_of
|
|
|
|
|
("gps_gpgga")
|
|
|
|
|
("gps_gprmc")
|
|
|
|
|
("gps_time")
|
2012-10-18 18:24:28 +00:00
|
|
|
("gps_locked")
|
|
|
|
|
("gps_servo");
|
2011-06-17 22:38:20 +00:00
|
|
|
return ret;
|
2010-08-16 23:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
2011-06-17 22:38:20 +00:00
|
|
|
uhd::sensor_value_t get_sensor(std::string key) {
|
|
|
|
|
if(key == "gps_gpgga"
|
2012-05-14 23:37:23 +00:00
|
|
|
or key == "gps_gprmc") {
|
2011-06-17 22:38:20 +00:00
|
|
|
return sensor_value_t(
|
|
|
|
|
boost::to_upper_copy(key),
|
2012-10-18 18:24:28 +00:00
|
|
|
get_cached_sensor(boost::to_upper_copy(key.substr(4,8)), GPS_NMEA_NORMAL_FRESHNESS, false, false),
|
2011-06-17 22:38:20 +00:00
|
|
|
"");
|
2011-06-17 20:01:07 +00:00
|
|
|
}
|
2011-06-17 22:38:20 +00:00
|
|
|
else if(key == "gps_time") {
|
|
|
|
|
return sensor_value_t("GPS epoch time", int(get_epoch_time()), "seconds");
|
|
|
|
|
}
|
|
|
|
|
else if(key == "gps_locked") {
|
|
|
|
|
return sensor_value_t("GPS lock status", locked(), "locked", "unlocked");
|
|
|
|
|
}
|
2012-10-18 18:24:28 +00:00
|
|
|
else if(key == "gps_servo") {
|
|
|
|
|
return sensor_value_t("GPS servo status", get_servo(), "");
|
|
|
|
|
}
|
2011-06-17 22:38:20 +00:00
|
|
|
else {
|
2011-11-08 00:53:47 +00:00
|
|
|
throw uhd::value_error("gps ctrl get_sensor unknown key: " + key);
|
2011-06-17 20:01:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-17 22:38:20 +00:00
|
|
|
private:
|
2013-12-20 00:13:41 +00:00
|
|
|
void init_gpsdo(void) {
|
2011-06-17 22:38:20 +00:00
|
|
|
//issue some setup stuff so it spits out the appropriate data
|
|
|
|
|
//none of these should issue replies so we don't bother looking for them
|
|
|
|
|
//we have to sleep between commands because the JL device, despite not acking, takes considerable time to process each command.
|
2014-02-04 19:04:07 +00:00
|
|
|
sleep(milliseconds(GPSDO_STUPID_DELAY_MS));
|
2011-06-17 22:38:20 +00:00
|
|
|
_send("SYST:COMM:SER:ECHO OFF\n");
|
2014-02-04 19:04:07 +00:00
|
|
|
sleep(milliseconds(GPSDO_STUPID_DELAY_MS));
|
2011-06-17 22:38:20 +00:00
|
|
|
_send("SYST:COMM:SER:PRO OFF\n");
|
2014-02-04 19:04:07 +00:00
|
|
|
sleep(milliseconds(GPSDO_STUPID_DELAY_MS));
|
2011-06-17 22:38:20 +00:00
|
|
|
_send("GPS:GPGGA 1\n");
|
2014-02-04 19:04:07 +00:00
|
|
|
sleep(milliseconds(GPSDO_STUPID_DELAY_MS));
|
2011-06-17 22:38:20 +00:00
|
|
|
_send("GPS:GGAST 0\n");
|
2014-02-04 19:04:07 +00:00
|
|
|
sleep(milliseconds(GPSDO_STUPID_DELAY_MS));
|
2011-06-17 22:38:20 +00:00
|
|
|
_send("GPS:GPRMC 1\n");
|
2014-02-04 19:04:07 +00:00
|
|
|
sleep(milliseconds(GPSDO_STUPID_DELAY_MS));
|
2013-04-10 01:34:23 +00:00
|
|
|
_send("SERV:TRAC 0\n");
|
2014-02-04 19:04:07 +00:00
|
|
|
sleep(milliseconds(GPSDO_STUPID_DELAY_MS));
|
2011-06-17 22:38:20 +00:00
|
|
|
}
|
2012-10-18 18:24:28 +00:00
|
|
|
|
2011-06-17 22:38:20 +00:00
|
|
|
//retrieve a raw NMEA sentence
|
|
|
|
|
std::string get_nmea(std::string msgtype) {
|
2011-06-17 20:01:07 +00:00
|
|
|
std::string reply;
|
2011-08-11 20:30:25 +00:00
|
|
|
|
2011-09-22 18:34:58 +00:00
|
|
|
const boost::system_time comm_timeout = boost::get_system_time() + milliseconds(GPS_COMM_TIMEOUT_MS);
|
|
|
|
|
while(boost::get_system_time() < comm_timeout) {
|
2012-10-18 18:24:28 +00:00
|
|
|
if(!msgtype.compare("GPRMC")) {
|
|
|
|
|
reply = get_cached_sensor(msgtype, GPS_NMEA_FRESHNESS, true);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
reply = get_cached_sensor(msgtype, GPS_NMEA_LOW_FRESHNESS, false);
|
|
|
|
|
}
|
|
|
|
|
if(reply.size()) {
|
|
|
|
|
if(reply.substr(1, 5) == msgtype) return reply;
|
|
|
|
|
}
|
2011-06-17 22:38:20 +00:00
|
|
|
boost::this_thread::sleep(milliseconds(GPS_TIMEOUT_DELAY_MS));
|
2010-08-13 18:34:07 +00:00
|
|
|
}
|
2011-08-11 20:30:25 +00:00
|
|
|
throw uhd::value_error(str(boost::format("get_nmea(): no %s message found") % msgtype));
|
2010-08-13 18:34:07 +00:00
|
|
|
}
|
2011-06-17 22:38:20 +00:00
|
|
|
|
|
|
|
|
//helper function to retrieve a field from an NMEA sentence
|
|
|
|
|
std::string get_token(std::string sentence, size_t offset) {
|
|
|
|
|
boost::tokenizer<boost::escaped_list_separator<char> > tok(sentence);
|
|
|
|
|
std::vector<std::string> toked;
|
2011-08-11 20:30:25 +00:00
|
|
|
tok.assign(sentence); //this can throw
|
2011-06-17 22:38:20 +00:00
|
|
|
toked.assign(tok.begin(), tok.end());
|
|
|
|
|
|
|
|
|
|
if(toked.size() <= offset) {
|
2011-08-11 20:30:25 +00:00
|
|
|
throw uhd::value_error(str(boost::format("Invalid response \"%s\"") % sentence));
|
2011-06-17 22:38:20 +00:00
|
|
|
}
|
|
|
|
|
return toked[offset];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ptime get_time(void) {
|
2013-04-10 01:34:23 +00:00
|
|
|
_flush();
|
2011-08-11 20:30:25 +00:00
|
|
|
int error_cnt = 0;
|
|
|
|
|
ptime gps_time;
|
2012-11-13 22:47:06 +00:00
|
|
|
while(error_cnt < 2) {
|
2011-08-11 20:30:25 +00:00
|
|
|
try {
|
|
|
|
|
std::string reply = get_nmea("GPRMC");
|
2011-06-17 22:38:20 +00:00
|
|
|
|
2011-08-11 20:30:25 +00:00
|
|
|
std::string datestr = get_token(reply, 9);
|
|
|
|
|
std::string timestr = get_token(reply, 1);
|
2011-06-17 22:38:20 +00:00
|
|
|
|
2011-08-11 20:30:25 +00:00
|
|
|
if(datestr.size() == 0 or timestr.size() == 0) {
|
|
|
|
|
throw uhd::value_error(str(boost::format("Invalid response \"%s\"") % reply));
|
|
|
|
|
}
|
2012-10-18 18:24:28 +00:00
|
|
|
|
2011-08-11 20:30:25 +00:00
|
|
|
//just trust me on this one
|
2012-10-18 18:24:28 +00:00
|
|
|
gps_time = ptime( date(
|
2011-08-11 20:30:25 +00:00
|
|
|
greg_year(boost::lexical_cast<int>(datestr.substr(4, 2)) + 2000),
|
2012-10-18 18:24:28 +00:00
|
|
|
greg_month(boost::lexical_cast<int>(datestr.substr(2, 2))),
|
|
|
|
|
greg_day(boost::lexical_cast<int>(datestr.substr(0, 2)))
|
2011-08-11 20:30:25 +00:00
|
|
|
),
|
|
|
|
|
hours( boost::lexical_cast<int>(timestr.substr(0, 2)))
|
|
|
|
|
+ minutes(boost::lexical_cast<int>(timestr.substr(2, 2)))
|
|
|
|
|
+ seconds(boost::lexical_cast<int>(timestr.substr(4, 2)))
|
|
|
|
|
);
|
|
|
|
|
return gps_time;
|
2012-10-18 18:24:28 +00:00
|
|
|
|
2011-08-11 20:30:25 +00:00
|
|
|
} catch(std::exception &e) {
|
|
|
|
|
UHD_MSG(warning) << "get_time: " << e.what();
|
2012-10-18 18:24:28 +00:00
|
|
|
_flush();
|
2011-08-11 20:30:25 +00:00
|
|
|
error_cnt++;
|
|
|
|
|
}
|
2011-06-17 22:38:20 +00:00
|
|
|
}
|
2011-08-11 20:30:25 +00:00
|
|
|
throw uhd::value_error("Timeout after no valid message found");
|
2012-10-18 18:24:28 +00:00
|
|
|
|
2011-08-11 20:30:25 +00:00
|
|
|
return gps_time; //keep gcc from complaining
|
2011-06-17 22:38:20 +00:00
|
|
|
}
|
2012-10-18 18:24:28 +00:00
|
|
|
|
2011-04-08 21:59:46 +00:00
|
|
|
time_t get_epoch_time(void) {
|
2011-06-17 22:38:20 +00:00
|
|
|
return (get_time() - from_time_t(0)).total_seconds();
|
2011-04-08 21:59:46 +00:00
|
|
|
}
|
2010-08-13 18:34:07 +00:00
|
|
|
|
|
|
|
|
bool gps_detected(void) {
|
|
|
|
|
return (gps_type != GPS_TYPE_NONE);
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-17 22:09:16 +00:00
|
|
|
bool locked(void) {
|
2011-08-11 20:30:25 +00:00
|
|
|
int error_cnt = 0;
|
|
|
|
|
while(error_cnt < 3) {
|
|
|
|
|
try {
|
2012-10-18 18:24:28 +00:00
|
|
|
std::string reply = get_cached_sensor("GPGGA", GPS_LOCK_FRESHNESS, false, false);
|
2011-08-11 20:30:25 +00:00
|
|
|
if(reply.size() <= 1) return false;
|
2011-06-17 22:09:16 +00:00
|
|
|
|
2011-08-11 20:30:25 +00:00
|
|
|
return (get_token(reply, 6) != "0");
|
|
|
|
|
} catch(std::exception &e) {
|
|
|
|
|
UHD_MSG(warning) << "locked: " << e.what();
|
|
|
|
|
error_cnt++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
throw uhd::value_error("Timeout after no valid message found");
|
|
|
|
|
return false;
|
2011-06-17 20:01:07 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-18 18:24:28 +00:00
|
|
|
std::string get_servo(void) {
|
2013-04-10 02:20:26 +00:00
|
|
|
|
|
|
|
|
//enable servo reporting
|
|
|
|
|
_send("SERV:TRAC 1\n");
|
2014-02-04 19:04:07 +00:00
|
|
|
sleep(milliseconds(GPSDO_STUPID_DELAY_MS));
|
2013-04-10 02:20:26 +00:00
|
|
|
|
2012-10-18 18:24:28 +00:00
|
|
|
std::string reply;
|
|
|
|
|
|
|
|
|
|
const boost::system_time comm_timeout = boost::get_system_time() + milliseconds(GPS_COMM_TIMEOUT_MS);
|
|
|
|
|
while(boost::get_system_time() < comm_timeout) {
|
2013-04-10 02:20:26 +00:00
|
|
|
reply = get_cached_sensor("SERVO", GPS_NMEA_LOW_FRESHNESS, false);
|
2012-10-18 18:24:28 +00:00
|
|
|
if(reply.size())
|
2013-04-10 02:20:26 +00:00
|
|
|
{
|
|
|
|
|
//disable it before leaving function
|
|
|
|
|
_send("SERV:TRAC 0\n");
|
|
|
|
|
return reply;
|
|
|
|
|
}
|
2012-10-18 18:24:28 +00:00
|
|
|
boost::this_thread::sleep(milliseconds(GPS_TIMEOUT_DELAY_MS));
|
|
|
|
|
}
|
|
|
|
|
throw uhd::value_error("get_stat(): no servo message found");
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-09 20:39:52 +00:00
|
|
|
uart_iface::sptr _uart;
|
|
|
|
|
|
|
|
|
|
void _flush(void){
|
|
|
|
|
while (not _uart->read_uart(0.0).empty()){
|
|
|
|
|
//NOP
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-14 20:05:07 +00:00
|
|
|
std::string _recv(double timeout = GPS_TIMEOUT_DELAY_MS/1000.){
|
|
|
|
|
return _uart->read_uart(timeout);
|
2011-09-09 20:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _send(const std::string &buf){
|
|
|
|
|
return _uart->write_uart(buf);
|
|
|
|
|
}
|
2010-08-13 18:34:07 +00:00
|
|
|
|
|
|
|
|
enum {
|
2014-02-04 19:04:07 +00:00
|
|
|
GPS_TYPE_INTERNAL_GPSDO,
|
2010-08-13 18:34:07 +00:00
|
|
|
GPS_TYPE_GENERIC_NMEA,
|
|
|
|
|
GPS_TYPE_NONE
|
|
|
|
|
} gps_type;
|
|
|
|
|
|
2012-10-18 18:24:28 +00:00
|
|
|
static const int GPS_COMM_TIMEOUT_MS = 1300;
|
|
|
|
|
static const int GPS_NMEA_FRESHNESS = 10;
|
|
|
|
|
static const int GPS_NMEA_LOW_FRESHNESS = 2500;
|
|
|
|
|
static const int GPS_NMEA_NORMAL_FRESHNESS = 1000;
|
|
|
|
|
static const int GPS_SERVO_FRESHNESS = 2500;
|
|
|
|
|
static const int GPS_LOCK_FRESHNESS = 2500;
|
2011-01-18 06:51:14 +00:00
|
|
|
static const int GPS_TIMEOUT_DELAY_MS = 200;
|
2014-02-04 19:04:07 +00:00
|
|
|
static const int GPSDO_STUPID_DELAY_MS = 200;
|
2010-08-13 18:34:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
|
* Public make function for the GPS control
|
|
|
|
|
**********************************************************************/
|
2011-09-09 20:39:52 +00:00
|
|
|
gps_ctrl::sptr gps_ctrl::make(uart_iface::sptr uart){
|
|
|
|
|
return sptr(new gps_ctrl_impl(uart));
|
2010-08-13 18:34:07 +00:00
|
|
|
}
|