summaryrefslogtreecommitdiffstats
path: root/host/lib/usrp/usrp2
diff options
context:
space:
mode:
authorNick Foster <nick@nerdnetworks.org>2011-01-17 22:51:14 -0800
committerNick Foster <nick@nerdnetworks.org>2011-01-17 22:51:14 -0800
commit330a014dfc32b34a7fe5555d3ae2d87a25dc2466 (patch)
tree5b744b8cdb13eda776028a046cf4e15dba0a668d /host/lib/usrp/usrp2
parentcaa911aa270ee4aef7244f3159b9fd402a454069 (diff)
downloaduhd-330a014dfc32b34a7fe5555d3ae2d87a25dc2466.tar.gz
uhd-330a014dfc32b34a7fe5555d3ae2d87a25dc2466.tar.bz2
uhd-330a014dfc32b34a7fe5555d3ae2d87a25dc2466.zip
next: generalized the GPS interface to any USRP device. just give it a function to write/read strings to UART.
not sure if i'm happy with the interface; maybe inheriting is cleaner. this works though. gps interface for usrp2 is disabled right now in mboard_impl.
Diffstat (limited to 'host/lib/usrp/usrp2')
-rw-r--r--host/lib/usrp/usrp2/CMakeLists.txt2
-rw-r--r--host/lib/usrp/usrp2/codec_impl.cpp2
-rw-r--r--host/lib/usrp/usrp2/gps_ctrl.cpp208
-rw-r--r--host/lib/usrp/usrp2/gps_ctrl.hpp53
-rw-r--r--host/lib/usrp/usrp2/mboard_impl.cpp5
-rw-r--r--host/lib/usrp/usrp2/usrp2_iface.cpp8
-rw-r--r--host/lib/usrp/usrp2/usrp2_iface.hpp9
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.hpp4
8 files changed, 24 insertions, 267 deletions
diff --git a/host/lib/usrp/usrp2/CMakeLists.txt b/host/lib/usrp/usrp2/CMakeLists.txt
index d83c82063..e8811a8fb 100644
--- a/host/lib/usrp/usrp2/CMakeLists.txt
+++ b/host/lib/usrp/usrp2/CMakeLists.txt
@@ -34,8 +34,6 @@ IF(ENABLE_USRP2)
${CMAKE_CURRENT_SOURCE_DIR}/dboard_impl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/dboard_iface.cpp
${CMAKE_CURRENT_SOURCE_DIR}/dsp_impl.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/gps_ctrl.hpp
- ${CMAKE_CURRENT_SOURCE_DIR}/gps_ctrl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/io_impl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mboard_impl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/usrp2_iface.cpp
diff --git a/host/lib/usrp/usrp2/codec_impl.cpp b/host/lib/usrp/usrp2/codec_impl.cpp
index eda15697b..df4975bb1 100644
--- a/host/lib/usrp/usrp2/codec_impl.cpp
+++ b/host/lib/usrp/usrp2/codec_impl.cpp
@@ -28,7 +28,7 @@ using namespace uhd;
using namespace uhd::usrp;
using namespace boost::assign;
-//this only applies to USRP2P
+//this only applies to N2XX
static const uhd::dict<std::string, gain_range_t> codec_rx_gain_ranges = map_list_of
("analog", gain_range_t(0, 3.5, 3.5))
("digital", gain_range_t(0, 6.0, 0.5))
diff --git a/host/lib/usrp/usrp2/gps_ctrl.cpp b/host/lib/usrp/usrp2/gps_ctrl.cpp
deleted file mode 100644
index 9f9b27954..000000000
--- a/host/lib/usrp/usrp2/gps_ctrl.cpp
+++ /dev/null
@@ -1,208 +0,0 @@
-//
-// Copyright 2010 Ettus Research LLC
-//
-// 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/>.
-//
-
-#include "gps_ctrl.hpp"
-#include <uhd/utils/assert.hpp>
-#include <boost/cstdint.hpp>
-#include <string>
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/thread.hpp>
-#include <boost/algorithm/string/trim.hpp>
-#include <boost/tokenizer.hpp>
-
-using namespace uhd;
-using namespace boost::gregorian;
-using namespace boost::posix_time;
-using namespace boost::algorithm;
-
-/*!
- * A usrp2 GPS control for Jackson Labs devices
- */
-
-//TODO: multiple baud rate support (requires mboard_impl changes for poking UART registers)
-class usrp2_gps_ctrl_impl : public usrp2_gps_ctrl{
-public:
- usrp2_gps_ctrl_impl(usrp2_iface::sptr iface){
- _iface = iface;
-
- std::string reply;
- bool i_heard_some_nmea = false, i_heard_something_weird = false;
-
- gps_type = GPS_TYPE_NONE;
-
-// set_uart_baud_rate(GPS_UART, 115200);
- //first we look for a Jackson Labs Firefly (since that's what we sell with the USRP2+...)
-
- _iface->read_uart(GPS_UART); //get whatever junk is in the rx buffer right now, and throw it away
- _iface->write_uart(GPS_UART, "HAAAY GUYYYYS\n"); //to elicit a response from the Firefly
-
- //then we loop until we either timeout, or until we get a response that indicates we're a JL device
- int timeout = GPS_TIMEOUT_TRIES;
- while(timeout--) {
- reply = safe_gps_read();
- if(trim_right_copy(reply) == "Command Error") {
- gps_type = GPS_TYPE_JACKSON_LABS;
- break;
- }
- 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
- boost::this_thread::sleep(boost::posix_time::milliseconds(FIREFLY_STUPID_DELAY_MS));
- }
-
- if((i_heard_some_nmea) && (gps_type != GPS_TYPE_JACKSON_LABS)) gps_type = GPS_TYPE_GENERIC_NMEA;
-
- //otherwise, we can try some other common baud rates looking to see if a GPS is connected (todo, later)
- if((gps_type == GPS_TYPE_NONE) && i_heard_something_weird) {
- std::cout << "GPS invalid reply \"" << reply << "\", assuming none available" << std::endl;
- }
-
- bool found_gprmc = false;
-
- switch(gps_type) {
- case GPS_TYPE_JACKSON_LABS:
- std::cout << "Found a Jackson Labs GPS" << std::endl;
- //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.
- boost::this_thread::sleep(boost::posix_time::milliseconds(FIREFLY_STUPID_DELAY_MS));
- _iface->write_uart(GPS_UART, "SYST:COMM:SER:ECHO OFF\n");
- boost::this_thread::sleep(boost::posix_time::milliseconds(FIREFLY_STUPID_DELAY_MS));
- _iface->write_uart(GPS_UART, "SYST:COMM:SER:PRO OFF\n");
- boost::this_thread::sleep(boost::posix_time::milliseconds(FIREFLY_STUPID_DELAY_MS));
- _iface->write_uart(GPS_UART, "GPS:GPGGA 0\n");
- boost::this_thread::sleep(boost::posix_time::milliseconds(FIREFLY_STUPID_DELAY_MS));
- _iface->write_uart(GPS_UART, "GPS:GGAST 0\n");
- boost::this_thread::sleep(boost::posix_time::milliseconds(FIREFLY_STUPID_DELAY_MS));
- _iface->write_uart(GPS_UART, "GPS:GPRMC 1\n");
- boost::this_thread::sleep(boost::posix_time::milliseconds(FIREFLY_STUPID_DELAY_MS));
-
-// break;
-
- case GPS_TYPE_GENERIC_NMEA:
- if(gps_type == GPS_TYPE_GENERIC_NMEA) std::cout << "Found a generic NMEA GPS device" << std::endl;
- found_gprmc = false;
- //here we loop around looking for a GPRMC packet. if we don't get one, we don't have a usable GPS.
- timeout = GPS_TIMEOUT_TRIES;
- while(timeout--) {
- reply = safe_gps_read();
- if(reply.substr(0, 6) == "$GPRMC") {
- found_gprmc = true;
- break;
- }
- }
- if(!found_gprmc) {
- if(gps_type == GPS_TYPE_JACKSON_LABS) std::cout << "Firefly GPS not locked or warming up." << std::endl;
- else std::cout << "GPS does not output GPRMC packets. Cannot retrieve time." << std::endl;
- gps_type = GPS_TYPE_NONE;
- }
- break;
-
- case GPS_TYPE_NONE:
- default:
- break;
-
- }
-
-
- }
-
- ~usrp2_gps_ctrl_impl(void){
-
- }
-
- std::string safe_gps_read() {
- std::string reply;
- try {
- reply = _iface->read_uart(GPS_UART);
- //std::cerr << "Got reply from GPS: " << reply.c_str() << " with length = " << reply.length() << std::endl;
- } catch (std::runtime_error err) {
- if(err.what() != std::string("usrp2 no control response")) throw; //sorry can't cope with that
- else { //we don't actually have a GPS installed
- reply = std::string();
- }
- }
- return reply;
- }
-
- ptime get_time(void) {
- std::string reply;
- ptime now;
- boost::tokenizer<boost::escaped_list_separator<char> > tok(reply);
- std::vector<std::string> toked;
- int timeout = GPS_TIMEOUT_TRIES;
- bool found_gprmc = false;
- switch(gps_type) {
- case GPS_TYPE_JACKSON_LABS: //deprecated in favor of a single NMEA parser
- case GPS_TYPE_GENERIC_NMEA:
-
- while(timeout--) {
- reply = safe_gps_read();
- if(reply.substr(0, 6) == "$GPRMC") {
- found_gprmc = true;
- break;
- }
- }
- UHD_ASSERT_THROW(found_gprmc);
-
- tok.assign(reply);
- toked.assign(tok.begin(), tok.end());
-
- UHD_ASSERT_THROW(toked.size() == 11); //if it's not we got something weird in there
-
- now = ptime( date(
- greg_year(boost::lexical_cast<int>(toked[8].substr(4, 2)) + 2000), //just trust me on this one
- greg_month(boost::lexical_cast<int>(toked[8].substr(2, 2))),
- greg_day(boost::lexical_cast<int>(toked[8].substr(0, 2)))
- ),
- hours( boost::lexical_cast<int>(toked[1].substr(0, 2)))
- + minutes(boost::lexical_cast<int>(toked[1].substr(2, 2)))
- + seconds(boost::lexical_cast<int>(toked[1].substr(4, 2)))
- );
- break;
- case GPS_TYPE_NONE:
- default:
- throw std::runtime_error("get_time(): Unsupported GPS or no GPS detected\n");
- break;
- }
- return now;
- }
-
- bool gps_detected(void) {
- return (gps_type != GPS_TYPE_NONE);
- }
-
-private:
- usrp2_iface::sptr _iface;
-
- enum {
- GPS_TYPE_JACKSON_LABS,
- GPS_TYPE_GENERIC_NMEA,
- GPS_TYPE_NONE
- } gps_type;
-
- static const int GPS_UART = 2; //TODO: this should be plucked from fw_common.h or memory_map.h or somewhere in common with the firmware
- static const int GPS_TIMEOUT_TRIES = 5;
- static const int FIREFLY_STUPID_DELAY_MS = 200;
-
-};
-
-/***********************************************************************
- * Public make function for the GPS control
- **********************************************************************/
-usrp2_gps_ctrl::sptr usrp2_gps_ctrl::make(usrp2_iface::sptr iface){
- return sptr(new usrp2_gps_ctrl_impl(iface));
-}
diff --git a/host/lib/usrp/usrp2/gps_ctrl.hpp b/host/lib/usrp/usrp2/gps_ctrl.hpp
deleted file mode 100644
index 5936a6fb6..000000000
--- a/host/lib/usrp/usrp2/gps_ctrl.hpp
+++ /dev/null
@@ -1,53 +0,0 @@
-//
-// Copyright 2010 Ettus Research LLC
-//
-// 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/>.
-//
-
-#ifndef INCLUDED_GPS_CTRL_HPP
-#define INCLUDED_GPS_CTRL_HPP
-
-#include "usrp2_iface.hpp"
-#include <boost/shared_ptr.hpp>
-#include <boost/utility.hpp>
-#include <boost/date_time/posix_time/posix_time_types.hpp>
-
-using namespace boost::posix_time;
-
-class usrp2_gps_ctrl : boost::noncopyable{
-public:
- typedef boost::shared_ptr<usrp2_gps_ctrl> sptr;
-
- /*!
- * Make a GPS config for Jackson Labs or generic NMEA GPS devices
- */
- static sptr make(usrp2_iface::sptr iface);
-
- /*!
- * Get the current GPS time and date
- * \return current GPS time and date as boost::posix_time::ptime object
- */
- virtual ptime get_time(void) = 0;
-
- /*!
- * Tell you if there's a supported GPS connected or not
- * \return true if a supported GPS is connected
- */
- virtual bool gps_detected(void) = 0;
-
- //TODO: other fun things you can do with a GPS.
-
-};
-
-#endif /* INCLUDED_CLOCK_CTRL_HPP */
diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp
index 95a3819b3..95f7013e7 100644
--- a/host/lib/usrp/usrp2/mboard_impl.cpp
+++ b/host/lib/usrp/usrp2/mboard_impl.cpp
@@ -17,6 +17,7 @@
#include "usrp2_impl.hpp"
#include "usrp2_regs.hpp"
+#include <uhd/usrp/gps_ctrl.hpp>
#include <uhd/usrp/misc_utils.hpp>
#include <uhd/usrp/dsp_utils.hpp>
#include <uhd/usrp/mboard_props.hpp>
@@ -65,7 +66,9 @@ usrp2_mboard_impl::usrp2_mboard_impl(
//contruct the interfaces to mboard perifs
_clock_ctrl = usrp2_clock_ctrl::make(_iface);
_codec_ctrl = usrp2_codec_ctrl::make(_iface);
- _gps_ctrl = usrp2_gps_ctrl::make(_iface);
+ //_gps_ctrl = gps_ctrl::make(
+ // _iface->get_gps_write_fn(),
+ // _iface->get_gps_read_fn());
//if(_gps_ctrl->gps_detected()) std::cout << "GPS time: " << _gps_ctrl->get_time() << std::endl;
diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp
index dcb25dc54..149c5011f 100644
--- a/host/lib/usrp/usrp2/usrp2_iface.cpp
+++ b/host/lib/usrp/usrp2/usrp2_iface.cpp
@@ -218,6 +218,14 @@ public:
}
return result;
}
+
+ gps_send_fn_t get_gps_write_fn(void) {
+ return boost::bind(&usrp2_iface_impl::write_uart, this, 2, _1); //2 is the GPS UART port on USRP2
+ }
+
+ gps_recv_fn_t get_gps_read_fn(void) {
+ return boost::bind(&usrp2_iface_impl::read_uart, this, 2); //2 is the GPS UART port on USRP2
+ }
/***********************************************************************
* Send/Recv over control
diff --git a/host/lib/usrp/usrp2/usrp2_iface.hpp b/host/lib/usrp/usrp2/usrp2_iface.hpp
index 2b4378ddf..49cb0e6dc 100644
--- a/host/lib/usrp/usrp2/usrp2_iface.hpp
+++ b/host/lib/usrp/usrp2/usrp2_iface.hpp
@@ -24,11 +24,17 @@
#include <boost/shared_ptr.hpp>
#include <boost/utility.hpp>
#include <boost/cstdint.hpp>
+#include <boost/function.hpp>
#include <utility>
#include <string>
#include "fw_common.h"
#include "usrp2_regs.hpp"
+
+//TODO: kill this crap when you have the top level GPS include file
+typedef boost::function<void(std::string)> gps_send_fn_t;
+typedef boost::function<std::string(void)> gps_recv_fn_t;
+
/*!
* The usrp2 interface class:
* Provides a set of functions to implementation layer.
@@ -100,6 +106,9 @@ public:
virtual void write_uart(boost::uint8_t dev, const std::string &buf) = 0;
virtual std::string read_uart(boost::uint8_t dev) = 0;
+
+ virtual gps_recv_fn_t get_gps_read_fn(void) = 0;
+ virtual gps_send_fn_t get_gps_write_fn(void) = 0;
//! The list of possible revision types
enum rev_type {
diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp
index d0f5ecf37..ad95b2a4a 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.hpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.hpp
@@ -21,7 +21,7 @@
#include "usrp2_iface.hpp"
#include "clock_ctrl.hpp"
#include "codec_ctrl.hpp"
-#include "gps_ctrl.hpp"
+#include <uhd/usrp/gps_ctrl.hpp>
#include <uhd/device.hpp>
#include <uhd/utils/pimpl.hpp>
#include <uhd/types/dict.hpp>
@@ -106,7 +106,7 @@ private:
usrp2_iface::sptr _iface;
usrp2_clock_ctrl::sptr _clock_ctrl;
usrp2_codec_ctrl::sptr _codec_ctrl;
- usrp2_gps_ctrl::sptr _gps_ctrl;
+ gps_ctrl::sptr _gps_ctrl;
//properties for this mboard
void get(const wax::obj &, wax::obj &);