aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/usrp/e300/e300_impl.cpp
diff options
context:
space:
mode:
authorMoritz Fischer <moritz.fischer@ettus.com>2015-04-16 16:12:40 -0500
committerMartin Braun <martin.braun@ettus.com>2015-07-29 18:13:45 -0700
commit1cac345b5c7b6d576da87dc321af4223d515df51 (patch)
tree0da09b7bde4e215674c8c31c4b5a0c4830811034 /host/lib/usrp/e300/e300_impl.cpp
parent463fc8985e29d12e2edba25008e7c0def5ce60cd (diff)
downloaduhd-1cac345b5c7b6d576da87dc321af4223d515df51.tar.gz
uhd-1cac345b5c7b6d576da87dc321af4223d515df51.tar.bz2
uhd-1cac345b5c7b6d576da87dc321af4223d515df51.zip
gps: gpsd: Adding gpsd_iface to interface with gpsd.
The gpsd_iface class might be useful for more than just e3x0, it therefore belongs into lib/usrp instead of lib/usrp/e300. A new UHD component is being registered, to cope with the additional dependency. If libgps is not found, UHD and E300 will be compiled without GPS support. This has several consequences: - The E310 GPSDO should now work transparently over network - Users can use the GPS through gpsd for other applications *while* running UHD applications - We now have a dependency on libgps We need currently at least version 3.11 (while running 3.14), on the device. Older versions do work if 3.10 runs on both sides e.g Reviewed-by: Martin Braun <martin.braun@ettus.com> Reviewed-by: Ashish Chaudhari <ashish.chaudhari@ettus.com> Signed-off-by: Moritz Fischer <moritz.fischer@ettus.com>
Diffstat (limited to 'host/lib/usrp/e300/e300_impl.cpp')
-rw-r--r--host/lib/usrp/e300/e300_impl.cpp70
1 files changed, 57 insertions, 13 deletions
diff --git a/host/lib/usrp/e300/e300_impl.cpp b/host/lib/usrp/e300/e300_impl.cpp
index 9a695b57e..ee4ee5ca4 100644
--- a/host/lib/usrp/e300/e300_impl.cpp
+++ b/host/lib/usrp/e300/e300_impl.cpp
@@ -394,19 +394,35 @@ e300_impl::e300_impl(const uhd::device_addr_t &device_addr)
// This is horrible ... why do I have to sleep here?
boost::this_thread::sleep(boost::posix_time::milliseconds(100));
_eeprom_manager = boost::make_shared<e300_eeprom_manager>(i2c::make_i2cdev(E300_I2CDEV_DEVICE));
+ _sensor_manager = e300_sensor_manager::make_local(_global_regs);
}
_codec_mgr = ad936x_manager::make(_codec_ctrl, fpga::NUM_RADIOS);
- UHD_MSG(status) << "Detecting internal GPSDO.... " << std::flush;
- if (_xport_path == AXI) {
- try {
- _gps = gps::ublox::ubx::control::make("/dev/ttyPS1", 9600);
- } catch (std::exception &e) {
- UHD_MSG(error) << "An error occured making GPSDO control: " << e.what() << std::endl;
+#ifdef E300_GPSD
+ UHD_MSG(status) << "Detecting internal GPSDO " << std::flush;
+ try {
+ if (_xport_path == AXI)
+ _gps = gpsd_iface::make("localhost", 2947);
+ else
+ _gps = gpsd_iface::make(device_addr["addr"], 2947);
+ } catch (std::exception &e) {
+ UHD_MSG(error) << "An error occured making GPSDd interface: " << e.what() << std::endl;
+ }
+
+ if (_gps) {
+ for (size_t i = 0; i < _GPS_TIMEOUT; i++)
+ {
+ boost::this_thread::sleep(boost::posix_time::seconds(1));
+ if (!_gps->gps_detected())
+ std::cout << "." << std::flush;
+ else {
+ std::cout << ".... " << std::flush;
+ break;
+ }
}
- _sensor_manager = e300_sensor_manager::make_local(_gps, _global_regs);
+ UHD_MSG(status) << (_gps->gps_detected() ? "found" : "not found") << std::endl;
}
- UHD_MSG(status) << (_sensor_manager->get_gps_found() ? "found" : "not found") << std::endl;
+#endif
// Verify we can talk to the e300 core control registers ...
UHD_MSG(status) << "Initializing core control..." << std::endl;
@@ -451,6 +467,15 @@ e300_impl::e300_impl(const uhd::device_addr_t &device_addr)
_tree->create<sensor_value_t>(mb_path / "sensors" / name)
.publish(boost::bind(&e300_sensor_manager::get_sensor, _sensor_manager, name));
}
+#ifdef E300_GPSD
+ if (_gps) {
+ BOOST_FOREACH(const std::string &name, _gps->get_sensors())
+ {
+ _tree->create<sensor_value_t>(mb_path / "sensors" / name)
+ .publish(boost::bind(&gpsd_iface::get_sensor, _gps, name));
+ }
+ }
+#endif
////////////////////////////////////////////////////////////////////
// setup the mboard eeprom
@@ -513,7 +538,11 @@ e300_impl::e300_impl(const uhd::device_addr_t &device_addr)
_tree->create<std::string>(mb_path / "time_source" / "value")
.subscribe(boost::bind(&e300_impl::_update_time_source, this, _1))
.set(e300::DEFAULT_TIME_SRC);
+#ifdef E300_GPSD
static const std::vector<std::string> time_sources = boost::assign::list_of("none")("internal")("external")("gpsdo");
+#else
+ static const std::vector<std::string> time_sources = boost::assign::list_of("none")("internal")("external");
+#endif
_tree->create<std::vector<std::string> >(mb_path / "time_source" / "options").set(time_sources);
//setup reference source props
_tree->create<std::string>(mb_path / "clock_source" / "value")
@@ -593,12 +622,25 @@ e300_impl::e300_impl(const uhd::device_addr_t &device_addr)
_tree->access<subdev_spec_t>(mb_path / "rx_subdev_spec").set(rx_spec);
_tree->access<subdev_spec_t>(mb_path / "tx_subdev_spec").set(tx_spec);
- UHD_MSG(status) << "Initializing time to the internal GPSDO" << std::endl;
- const time_t tp = time_t(_sensor_manager->get_sensor("gps_time").to_int()+1);
- _tree->access<time_spec_t>(mb_path / "time" / "pps").set(time_spec_t(tp));
+#ifdef E300_GPSD
+ //GPS installed: use external ref, time, and init time spec
+ if (_gps and _gps->gps_detected()) {
+ UHD_MSG(status) << "Setting references to the internal GPSDO"
+ << std::endl;
+ _tree->access<std::string>(mb_path / "time_source" / "value").set("gpsdo");
+ UHD_MSG(status) << "Initializing time to the internal GPSDO"
+ << std::endl;
+ const time_t tp = time_t(_gps->get_sensor("gps_time").to_int()+1);
+ _tree->access<time_spec_t>(mb_path / "time" / "pps").set(time_spec_t(tp));
+
+ // wait for time to be actually set
+ boost::this_thread::sleep(boost::posix_time::seconds(1));
+ }
+#else
+ //init to internal clock and time source
+ _tree->access<std::string>(mb_path / "time_source/value").set("internal");
+#endif// E300_GPSD
- // wait for time to be actually set
- boost::this_thread::sleep(boost::posix_time::seconds(1));
}
boost::uint8_t e300_impl::_get_internal_gpio(gpio_core_200::sptr gpio)
@@ -792,8 +834,10 @@ void e300_impl::_update_time_source(const std::string &source)
UHD_MSG(status) << boost::format("Setting time source to %s") % source << std::endl;
if (source == "none" or source == "internal") {
_misc.pps_sel = global_regs::PPS_INT;
+#ifdef E300_GPSD
} else if (source == "gpsdo") {
_misc.pps_sel = global_regs::PPS_GPS;
+#endif
} else if (source == "external") {
_misc.pps_sel = global_regs::PPS_EXT;
} else {