summaryrefslogtreecommitdiffstats
path: root/host/lib
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
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')
-rw-r--r--host/lib/usrp/CMakeLists.txt1
-rw-r--r--host/lib/usrp/gps_ctrl.cpp (renamed from host/lib/usrp/usrp2/gps_ctrl.cpp)42
-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.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
9 files changed, 47 insertions, 79 deletions
diff --git a/host/lib/usrp/CMakeLists.txt b/host/lib/usrp/CMakeLists.txt
index 9dc74a5fe..bd25aec2b 100644
--- a/host/lib/usrp/CMakeLists.txt
+++ b/host/lib/usrp/CMakeLists.txt
@@ -25,6 +25,7 @@ LIBUHD_APPEND_SOURCES(
${CMAKE_CURRENT_SOURCE_DIR}/dboard_iface.cpp
${CMAKE_CURRENT_SOURCE_DIR}/dboard_manager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/dsp_utils.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/gps_ctrl.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mboard_eeprom.cpp
${CMAKE_CURRENT_SOURCE_DIR}/misc_utils.cpp
${CMAKE_CURRENT_SOURCE_DIR}/multi_usrp.cpp
diff --git a/host/lib/usrp/usrp2/gps_ctrl.cpp b/host/lib/usrp/gps_ctrl.cpp
index 9f9b27954..3c7c00134 100644
--- a/host/lib/usrp/usrp2/gps_ctrl.cpp
+++ b/host/lib/usrp/gps_ctrl.cpp
@@ -15,7 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
-#include "gps_ctrl.hpp"
+#include <uhd/usrp/gps_ctrl.hpp>
#include <uhd/utils/assert.hpp>
#include <boost/cstdint.hpp>
#include <string>
@@ -30,14 +30,15 @@ using namespace boost::posix_time;
using namespace boost::algorithm;
/*!
- * A usrp2 GPS control for Jackson Labs devices
+ * A GPS control for Jackson Labs devices (and other NMEA compatible GPS's)
*/
//TODO: multiple baud rate support (requires mboard_impl changes for poking UART registers)
-class usrp2_gps_ctrl_impl : public usrp2_gps_ctrl{
+class gps_ctrl_impl : public gps_ctrl{
public:
- usrp2_gps_ctrl_impl(usrp2_iface::sptr iface){
- _iface = iface;
+ gps_ctrl_impl(gps_send_fn_t send, gps_recv_fn_t recv){
+ _send = send;
+ _recv = recv;
std::string reply;
bool i_heard_some_nmea = false, i_heard_something_weird = false;
@@ -47,8 +48,8 @@ public:
// 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
+ _recv(); //get whatever junk is in the rx buffer right now, and throw it away
+ _send("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;
@@ -60,7 +61,7 @@ public:
}
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));
+ boost::this_thread::sleep(boost::posix_time::milliseconds(200));
}
if((i_heard_some_nmea) && (gps_type != GPS_TYPE_JACKSON_LABS)) gps_type = GPS_TYPE_GENERIC_NMEA;
@@ -79,15 +80,15 @@ public:
//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");
+ _send("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");
+ _send("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");
+ _send("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");
+ _send("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");
+ _send("GPS:GPRMC 1\n");
boost::this_thread::sleep(boost::posix_time::milliseconds(FIREFLY_STUPID_DELAY_MS));
// break;
@@ -120,15 +121,15 @@ public:
}
- ~usrp2_gps_ctrl_impl(void){
+ ~gps_ctrl_impl(void){
}
+//TODO: this isn't generalizeable to non-USRP2 USRPs.
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;
+ reply = _recv();
} 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
@@ -186,7 +187,8 @@ public:
}
private:
- usrp2_iface::sptr _iface;
+ gps_send_fn_t _send;
+ gps_recv_fn_t _recv;
enum {
GPS_TYPE_JACKSON_LABS,
@@ -194,8 +196,8 @@ private:
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 GPS_TIMEOUT_DELAY_MS = 200;
static const int FIREFLY_STUPID_DELAY_MS = 200;
};
@@ -203,6 +205,6 @@ private:
/***********************************************************************
* 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));
+gps_ctrl::sptr gps_ctrl::make(gps_send_fn_t send, gps_recv_fn_t recv){
+ return sptr(new gps_ctrl_impl(send, recv));
}
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.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 &);