From 59ed6e1a0f9710c7bfca0a348d07f8c96f9f6bc0 Mon Sep 17 00:00:00 2001 From: michael-west Date: Mon, 18 Jul 2016 14:34:00 -0700 Subject: GPSDO: Make sure read_uart() returns only complete strings for all devices. --- host/lib/transport/udp_simple.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'host/lib/transport') diff --git a/host/lib/transport/udp_simple.cpp b/host/lib/transport/udp_simple.cpp index 347373c71..8b6e5eb2b 100644 --- a/host/lib/transport/udp_simple.cpp +++ b/host/lib/transport/udp_simple.cpp @@ -114,9 +114,16 @@ public: do{ //drain anything in current buffer while (_off < _len){ - const char ch = _buf[_off]; _off++; - line += std::string(1, ch); - if (ch == '\n' or ch == '\r') return line; + const char ch = _buf[_off++]; + if (ch == '\r') continue; + if (ch == '\n' and _line.empty()) continue; + _line += ch; + if (ch == '\n') + { + line = _line; + _line.clear(); + return line; + } } //recv a new packet into the buffer @@ -131,6 +138,7 @@ private: udp_simple::sptr _udp; size_t _len, _off; boost::uint8_t _buf[udp_simple::mtu]; + std::string _line; }; uhd::uart_iface::sptr udp_simple::make_uart(sptr udp){ -- cgit v1.2.3 From 27d0c654ac11158827d17d338da42db1549e56d4 Mon Sep 17 00:00:00 2001 From: michael-west Date: Mon, 15 Aug 2016 11:25:05 -0700 Subject: N200: Simplify GPSDO UART so it does not strip or add characters --- host/lib/transport/udp_simple.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'host/lib/transport') diff --git a/host/lib/transport/udp_simple.cpp b/host/lib/transport/udp_simple.cpp index 8b6e5eb2b..43414feaa 100644 --- a/host/lib/transport/udp_simple.cpp +++ b/host/lib/transport/udp_simple.cpp @@ -115,13 +115,10 @@ public: //drain anything in current buffer while (_off < _len){ const char ch = _buf[_off++]; - if (ch == '\r') continue; - if (ch == '\n' and _line.empty()) continue; _line += ch; if (ch == '\n') { - line = _line; - _line.clear(); + line.swap(_line); return line; } } -- cgit v1.2.3