diff options
author | Nick Foster <nick@nerdnetworks.org> | 2010-08-13 16:16:22 -0700 |
---|---|---|
committer | Nick Foster <nick@nerdnetworks.org> | 2010-08-13 16:16:22 -0700 |
commit | 727d8711f94bf7fe634fc33659b77bc4b4884d9c (patch) | |
tree | 7c0761dbcd0f47d1fd350190ecde1ced5d30f947 /host/lib/usrp | |
parent | 5ab3f053529bb8d85a7f1ba9e1dd113c1f6eb813 (diff) | |
download | uhd-727d8711f94bf7fe634fc33659b77bc4b4884d9c.tar.gz uhd-727d8711f94bf7fe634fc33659b77bc4b4884d9c.tar.bz2 uhd-727d8711f94bf7fe634fc33659b77bc4b4884d9c.zip |
Support for NMEA reads. Uses NMEA parsing instead of Jackson Labs parsing.
No multibaud support yet. read/write_uart() now do multiple-packet writes in multiples of 20 bytes (hardcoded).
Diffstat (limited to 'host/lib/usrp')
-rw-r--r-- | host/lib/usrp/usrp2/gps_ctrl.cpp | 65 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/mboard_impl.cpp | 4 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/usrp2_iface.cpp | 29 | ||||
-rw-r--r-- | host/lib/usrp/usrp2/usrp2_iface.hpp | 2 |
4 files changed, 62 insertions, 38 deletions
diff --git a/host/lib/usrp/usrp2/gps_ctrl.cpp b/host/lib/usrp/usrp2/gps_ctrl.cpp index 7152800aa..20d670f81 100644 --- a/host/lib/usrp/usrp2/gps_ctrl.cpp +++ b/host/lib/usrp/usrp2/gps_ctrl.cpp @@ -20,10 +20,14 @@ #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 @@ -42,9 +46,10 @@ public: //TODO: try multiple baud rates (many GPS's are set up for 4800bps, you're fixed at 115200bps 8N1 right now) //you have to poke registers in order to set baud rate, there's no dude/bro interface for it + _iface->read_uart(GPS_UART); //flush it out _iface->write_uart(GPS_UART, "HAAAY GUYYYYS\n"); try { - reply = _iface->read_uart(GPS_UART, 20); + 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 @@ -53,7 +58,7 @@ public: } } - if(reply == "Command Error") gps_type = GPS_TYPE_JACKSON_LABS; + if(trim_right_copy(reply) == "Command Error") gps_type = GPS_TYPE_JACKSON_LABS; else gps_type = GPS_TYPE_NONE; //we'll add NMEA support later switch(gps_type) { @@ -61,12 +66,18 @@ public: std::cerr << "Found a Jackson Labs GPS" << std::endl; //issue some setup stuff so it quits spewing data out when not asked to //none of these should issue replies so we don't bother looking for it - _iface->write_uart(GPS_UART, "SYST:COMM:SER:"); - _iface->write_uart(GPS_UART, "ECHO OFF\n"); //we split lines before 20 chars right now -- TODO: fix driver to split writes/reads for you - _iface->write_uart(GPS_UART, "SYST:COMM:SER:"); - _iface->write_uart(GPS_UART, "PRO OFF\n"); + //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(200)); + _iface->write_uart(GPS_UART, "SYST:COMM:SER:ECHO OFF\n"); + boost::this_thread::sleep(boost::posix_time::milliseconds(200)); + _iface->write_uart(GPS_UART, "SYST:COMM:SER:PRO OFF\n"); + boost::this_thread::sleep(boost::posix_time::milliseconds(200)); _iface->write_uart(GPS_UART, "GPS:GPGGA 0\n"); + boost::this_thread::sleep(boost::posix_time::milliseconds(200)); _iface->write_uart(GPS_UART, "GPS:GGAST 0\n"); + boost::this_thread::sleep(boost::posix_time::milliseconds(200)); + _iface->write_uart(GPS_UART, "GPS:GPRMC 1\n"); + boost::this_thread::sleep(boost::posix_time::milliseconds(200)); break; case GPS_TYPE_GENERIC_NMEA: @@ -84,13 +95,27 @@ public: ptime get_time(void) { std::string reply; ptime now; + boost::tokenizer<boost::escaped_list_separator<char> > tok(reply); + std::vector<std::string> toked; switch(gps_type) { - case GPS_TYPE_JACKSON_LABS: - _iface->write_uart(GPS_UART, "PTIME:TIME\n"); - reply = _iface->read_uart(GPS_UART, 20); - now = ptime(get_date(), duration_from_string(reply)); - break; + case GPS_TYPE_JACKSON_LABS: //deprecated in favor of a single NMEA parser case GPS_TYPE_GENERIC_NMEA: + while(reply.length() == 0) reply = _iface->read_uart(GPS_UART); //loop until we hear something + 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"); @@ -99,24 +124,6 @@ public: return now; } - date get_date(void) { - std::string reply; - date today; - switch(gps_type) { - case GPS_TYPE_JACKSON_LABS: - _iface->write_uart(GPS_UART, "PTIME:DATE\n"); - reply = _iface->read_uart(GPS_UART, 20); - today = from_string(reply); - break; - case GPS_TYPE_GENERIC_NMEA: - case GPS_TYPE_NONE: - default: - throw std::runtime_error("get_date(): Unsupported GPS or no GPS detected\n"); - break; - } - return today; - } - bool gps_detected(void) { return (gps_type != GPS_TYPE_NONE); } diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index ed6398405..6c4234641 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -26,9 +26,11 @@ #include <boost/bind.hpp> #include <boost/asio/ip/address_v4.hpp> #include <iostream> +#include <boost/date_time/posix_time/posix_time.hpp> using namespace uhd; using namespace uhd::usrp; +using namespace boost::posix_time; /*********************************************************************** * Structors @@ -57,6 +59,8 @@ usrp2_mboard_impl::usrp2_mboard_impl( _serdes_ctrl = usrp2_serdes_ctrl::make(_iface); _gps_ctrl = usrp2_gps_ctrl::make(_iface); + if(_gps_ctrl->gps_detected()) std::cout << "GPS time: " << _gps_ctrl->get_time() << std::endl; + //TODO move to dsp impl... //load the allowed decim/interp rates //_USRP2_RATES = range(4, 128+1, 1) + range(130, 256+1, 2) + range(260, 512+1, 4) diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index f4d354204..0771c4945 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -24,6 +24,7 @@ #include <boost/asio.hpp> //used for htonl and ntohl #include <boost/assign/list_of.hpp> #include <boost/format.hpp> +#include <boost/tokenizer.hpp> #include <stdexcept> #include <algorithm> @@ -176,40 +177,52 @@ public: * UART **********************************************************************/ void write_uart(boost::uint8_t dev, const std::string &buf){ + //first tokenize the string into 20-byte substrings + boost::offset_separator f(20, 1, true, true); + boost::tokenizer<boost::offset_separator> tok(buf, f); + std::vector<std::string> queue(tok.begin(), tok.end()); + + BOOST_FOREACH(std::string item, queue) { //setup the out data usrp2_ctrl_data_t out_data; out_data.id = htonl(USRP2_CTRL_ID_HEY_WRITE_THIS_UART_FOR_ME_BRO); out_data.data.uart_args.dev = dev; - out_data.data.uart_args.bytes = buf.size(); + out_data.data.uart_args.bytes = item.size(); //limitation of uart transaction size - UHD_ASSERT_THROW(buf.size() <= sizeof(out_data.data.uart_args.data)); + UHD_ASSERT_THROW(item.size() <= sizeof(out_data.data.uart_args.data)); //copy in the data - std::copy(buf.begin(), buf.end(), out_data.data.uart_args.data); + std::copy(item.begin(), item.end(), out_data.data.uart_args.data); //send and recv usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data); UHD_ASSERT_THROW(ntohl(in_data.id) == USRP2_CTRL_ID_MAN_I_TOTALLY_WROTE_THAT_UART_DUDE); + } } - std::string read_uart(boost::uint8_t dev, size_t num_bytes){ + std::string read_uart(boost::uint8_t dev){ + int readlen = 20; + std::string result; + while(readlen == 20) { //while we keep receiving full packets //setup the out data usrp2_ctrl_data_t out_data; out_data.id = htonl(USRP2_CTRL_ID_SO_LIKE_CAN_YOU_READ_THIS_UART_BRO); out_data.data.uart_args.dev = dev; - out_data.data.uart_args.bytes = num_bytes; + out_data.data.uart_args.bytes = 20; //limitation of uart transaction size - UHD_ASSERT_THROW(num_bytes <= sizeof(out_data.data.uart_args.data)); + //UHD_ASSERT_THROW(num_bytes <= sizeof(out_data.data.uart_args.data)); //send and recv usrp2_ctrl_data_t in_data = this->ctrl_send_and_recv(out_data); UHD_ASSERT_THROW(ntohl(in_data.id) == USRP2_CTRL_ID_I_HELLA_READ_THAT_UART_DUDE); + readlen = in_data.data.uart_args.bytes; //copy out the data - std::string result((const char *)in_data.data.uart_args.data, (size_t)in_data.data.uart_args.bytes); - return result; + result += std::string((const char *)in_data.data.uart_args.data, (size_t)readlen); + } + return result; } /*********************************************************************** diff --git a/host/lib/usrp/usrp2/usrp2_iface.hpp b/host/lib/usrp/usrp2/usrp2_iface.hpp index cb247f074..55fbfa7e4 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.hpp +++ b/host/lib/usrp/usrp2/usrp2_iface.hpp @@ -106,7 +106,7 @@ public: virtual void write_uart(boost::uint8_t dev, const std::string &buf) = 0; - virtual std::string read_uart(boost::uint8_t dev, size_t num_bytes) = 0; + virtual std::string read_uart(boost::uint8_t dev) = 0; /*! * Set the hardware revision number. Also selects the proper register set for the device. |