summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.common1
-rw-r--r--include/usrp_uhd/device_addr.hpp4
-rw-r--r--include/usrp_uhd/usrp/dboard/interface.hpp2
-rw-r--r--lib/device_addr.cpp55
-rw-r--r--lib/usrp/dboard/base.cpp8
-rw-r--r--lib/usrp/dboard/basic.cpp8
-rw-r--r--lib/usrp_uhd.cpp2
-rw-r--r--test/.gitignore2
-rw-r--r--test/Makefile.am2
-rw-r--r--test/addr_test.cpp41
-rw-r--r--test/wax_test.cpp2
11 files changed, 92 insertions, 35 deletions
diff --git a/Makefile.common b/Makefile.common
index 8972e4f42..0afe43c7b 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -7,6 +7,7 @@ USRP_UHD_LA = $(abs_top_builddir)/lib/libusrp_uhd.la
USRP_UHD_USRP_DBOARD_LA = $(abs_top_builddir)/lib/usrp/dboard/lib.la
GENERAL_CPPFLAGS = \
+ -W -Wall -Werror -ansi -pedantic \
-I$(top_srcdir)/include \
$(BOOST_CPPFLAGS)
diff --git a/include/usrp_uhd/device_addr.hpp b/include/usrp_uhd/device_addr.hpp
index f0be44c1f..c082d9f84 100644
--- a/include/usrp_uhd/device_addr.hpp
+++ b/include/usrp_uhd/device_addr.hpp
@@ -18,7 +18,7 @@ namespace usrp_uhd{
*/
struct mac_addr_t{
struct ether_addr mac_addr;
- mac_addr_t(const std::string &str = "00:00:00:00:00:00");
+ mac_addr_t(const std::string &mac_addr_str = "00:00:00:00:00:00");
std::string to_string(void) const;
};
@@ -28,7 +28,7 @@ namespace usrp_uhd{
*/
struct ip_addr_t{
struct in_addr ip_addr;
- ip_addr_t(const std::string &str = "0.0.0.0");
+ ip_addr_t(const std::string &ip_addr_str = "0.0.0.0");
std::string to_string(void) const;
};
diff --git a/include/usrp_uhd/usrp/dboard/interface.hpp b/include/usrp_uhd/usrp/dboard/interface.hpp
index e6fdd9ad1..acbfc6d70 100644
--- a/include/usrp_uhd/usrp/dboard/interface.hpp
+++ b/include/usrp_uhd/usrp/dboard/interface.hpp
@@ -23,7 +23,7 @@ public:
//tells the host which device to use
enum spi_dev_t{
SPI_TX_DEV,
- SPI_RX_DEV,
+ SPI_RX_DEV
};
//args for writing spi data
diff --git a/lib/device_addr.cpp b/lib/device_addr.cpp
index ac66c0d25..34c61ede8 100644
--- a/lib/device_addr.cpp
+++ b/lib/device_addr.cpp
@@ -5,36 +5,49 @@
#include <usrp_uhd/device_addr.hpp>
#include <sstream>
#include <cstring>
-#include <cstdio>
#include <stdexcept>
+#include <boost/format.hpp>
+#include <boost/algorithm/string.hpp>
//----------------------- u2 mac addr wrapper ------------------------//
-usrp_uhd::mac_addr_t::mac_addr_t(const std::string &str){
+usrp_uhd::mac_addr_t::mac_addr_t(const std::string &mac_addr_str){
//ether_aton_r(str.c_str(), &mac_addr);
- bool good = false;
- char p[6] = {0x00, 0x50, 0xC2, 0x85, 0x30, 0x00}; // Matt's IAB
+ uint8_t p[6] = {0x00, 0x50, 0xC2, 0x85, 0x30, 0x00}; // Matt's IAB
- switch (str.size()){
- case 5:
- good = sscanf(str.c_str(), "%hhx:%hhx", &p[4], &p[5]) == 2;
- break;
- case 17:
- good = sscanf(str.c_str(), "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
- &p[0], &p[1], &p[2], &p[3], &p[4], &p[5]) == 6;
- break;
+ try{
+ //only allow patterns of xx:xx or xx:xx:xx:xx:xx:xx
+ //the IAB above will fill in for the shorter pattern
+ if (mac_addr_str.size() != 5 and mac_addr_str.size() != 17)
+ throw std::runtime_error("expected exactly 5 or 17 characters");
+
+ //split the mac addr hex string at the colons
+ std::vector<std::string> hex_strs;
+ boost::split(hex_strs, mac_addr_str, boost::is_any_of(":"));
+ for (size_t i = 0; i < hex_strs.size(); i++){
+ int hex_num;
+ std::istringstream iss(hex_strs[i]);
+ iss >> std::hex >> hex_num;
+ p[i] = uint8_t(hex_num);
+ }
+
+ }
+ catch(std::exception const& e){
+ throw std::runtime_error(str(
+ boost::format("Invalid mac address: %s\n\t%s") % mac_addr_str % e.what()
+ ));
}
- if (not good) throw std::runtime_error("Invalid mac address: " + str);
memcpy(&mac_addr, p, sizeof(mac_addr));
}
std::string usrp_uhd::mac_addr_t::to_string(void) const{
- char addr_buf[128];
//ether_ntoa_r(&mac_addr, addr_buf);
const uint8_t *p = reinterpret_cast<const uint8_t *>(&mac_addr);
- sprintf(addr_buf, "%02x:%02x:%02x:%02x:%02x:%02x",
- p[0], p[1], p[2], p[3], p[4], p[5]);
- return std::string(addr_buf);
+ return str(
+ boost::format("%02x:%02x:%02x:%02x:%02x:%02x")
+ % int(p[0]) % int(p[1]) % int(p[2])
+ % int(p[3]) % int(p[4]) % int(p[5])
+ );
}
std::ostream& operator<<(std::ostream &os, const usrp_uhd::mac_addr_t &x){
@@ -43,9 +56,9 @@ std::ostream& operator<<(std::ostream &os, const usrp_uhd::mac_addr_t &x){
}
//----------------------- u2 ipv4 wrapper ----------------------------//
-usrp_uhd::ip_addr_t::ip_addr_t(const std::string &str){
- int ret = inet_pton(AF_INET, str.c_str(), &ip_addr);
- if (ret == 0) throw std::runtime_error("Invalid ip address: " + str);
+usrp_uhd::ip_addr_t::ip_addr_t(const std::string &ip_addr_str){
+ int ret = inet_pton(AF_INET, ip_addr_str.c_str(), &ip_addr);
+ if (ret == 0) throw std::runtime_error("Invalid ip address: " + ip_addr_str);
}
std::string usrp_uhd::ip_addr_t::to_string(void) const{
@@ -73,7 +86,7 @@ usrp_uhd::device_addr_t::device_addr_t(device_addr_type_t device_addr_type){
}
std::string usrp_uhd::device_addr_t::to_string(void) const{
- std::stringstream out;
+ std::ostringstream out;
out << "USRP Type: ";
switch(type){
case DEVICE_ADDR_TYPE_AUTO:
diff --git a/lib/usrp/dboard/base.cpp b/lib/usrp/dboard/base.cpp
index 3166cdedc..c3fc332c9 100644
--- a/lib/usrp/dboard/base.cpp
+++ b/lib/usrp/dboard/base.cpp
@@ -38,11 +38,11 @@ rx_base::~rx_base(void){
/* NOP */
}
-void rx_base::tx_get(const wax::type &key, wax::type &val){
+void rx_base::tx_get(const wax::type &, wax::type &){
throw std::runtime_error("cannot call tx_get on a rx dboard");
}
-void rx_base::tx_set(const wax::type &key, const wax::type &val){
+void rx_base::tx_set(const wax::type &, const wax::type &){
throw std::runtime_error("cannot call tx_set on a rx dboard");
}
@@ -58,10 +58,10 @@ tx_base::~tx_base(void){
/* NOP */
}
-void tx_base::rx_get(const wax::type &key, wax::type &val){
+void tx_base::rx_get(const wax::type &, wax::type &){
throw std::runtime_error("cannot call rx_get on a tx dboard");
}
-void tx_base::rx_set(const wax::type &key, const wax::type &val){
+void tx_base::rx_set(const wax::type &, const wax::type &){
throw std::runtime_error("cannot call rx_set on a tx dboard");
}
diff --git a/lib/usrp/dboard/basic.cpp b/lib/usrp/dboard/basic.cpp
index 120b637b2..1c746815c 100644
--- a/lib/usrp/dboard/basic.cpp
+++ b/lib/usrp/dboard/basic.cpp
@@ -16,11 +16,11 @@ basic_rx::~basic_rx(void){
/* NOP */
}
-void basic_rx::rx_get(const wax::type &key, wax::type &val){
+void basic_rx::rx_get(const wax::type &, wax::type &){
/* TODO */
}
-void basic_rx::rx_set(const wax::type &key, const wax::type &val){
+void basic_rx::rx_set(const wax::type &, const wax::type &){
/* TODO */
}
@@ -36,10 +36,10 @@ basic_tx::~basic_tx(void){
/* NOP */
}
-void basic_tx::tx_get(const wax::type &key, wax::type &val){
+void basic_tx::tx_get(const wax::type &, wax::type &){
/* TODO */
}
-void basic_tx::tx_set(const wax::type &key, const wax::type &val){
+void basic_tx::tx_set(const wax::type &, const wax::type &){
/* TODO */
}
diff --git a/lib/usrp_uhd.cpp b/lib/usrp_uhd.cpp
index a838b717b..7d1e62a13 100644
--- a/lib/usrp_uhd.cpp
+++ b/lib/usrp_uhd.cpp
@@ -4,5 +4,5 @@
#include <usrp_uhd.hpp>
-usrp_uhd::usrp_uhd::usrp_uhd(device_addr_t device_addr){}
+usrp_uhd::usrp_uhd::usrp_uhd(device_addr_t){}
usrp_uhd::usrp_uhd::~usrp_uhd(void){}
diff --git a/test/.gitignore b/test/.gitignore
index 3d6649c66..28c7c29da 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -1,3 +1,3 @@
/Makefile
/Makefile.in
-/wax_test
+/*_test
diff --git a/test/Makefile.am b/test/Makefile.am
index e5b1bc1e1..31deb7391 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -13,8 +13,10 @@ LDADD = \
$(USRP_UHD_LA)
noinst_PROGRAMS = \
+ addr_test \
wax_test
+addr_test_SOURCES = addr_test.cpp
wax_test_SOURCES = wax_test.cpp
TESTS = $(noinst_PROGRAMS)
diff --git a/test/addr_test.cpp b/test/addr_test.cpp
new file mode 100644
index 000000000..11fe8c1dd
--- /dev/null
+++ b/test/addr_test.cpp
@@ -0,0 +1,41 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+
+#include <usrp_uhd/device_addr.hpp>
+#include <iostream>
+#include <stdexcept>
+#include <boost/format.hpp>
+#include <boost/current_function.hpp>
+
+#define THROW_ASSERT(expr) \
+if (not (expr)){ \
+ throw std::runtime_error(str( \
+ boost::format("%s %s %s %s") \
+ % #expr % BOOST_CURRENT_FUNCTION % __FILE__ % __LINE__ \
+ )); \
+}
+
+int main(void){
+ try{
+ std::cout << "Testing mac addr:" << std::endl;
+ const std::string mac_addr_str("00:01:23:45:67:89");
+ usrp_uhd::mac_addr_t mac_addr(mac_addr_str);
+ std::cout << "Input: " << mac_addr_str << std::endl;
+ std::cout << "Output: " << mac_addr << std::endl;
+ THROW_ASSERT(mac_addr.to_string() == mac_addr_str);
+
+ std::cout << "Testing ip addr:" << std::endl;
+ const std::string ip_addr_str("192.168.1.10");
+ usrp_uhd::ip_addr_t ip_addr(ip_addr_str);
+ std::cout << "Input: " << ip_addr_str << std::endl;
+ std::cout << "Output: " << ip_addr << std::endl;
+ THROW_ASSERT(ip_addr.to_string() == ip_addr_str);
+
+ std::cout << "done" << std::endl;
+ }catch(std::exception const& e){
+ std::cerr << "Exception: " << e.what() << std::endl;
+ return ~0;
+ }
+ return 0;
+}
diff --git a/test/wax_test.cpp b/test/wax_test.cpp
index 88c9e0f32..06f17b9b7 100644
--- a/test/wax_test.cpp
+++ b/test/wax_test.cpp
@@ -74,7 +74,7 @@ int main(void){
std::cout << test_type << std::endl;
std::cout << "done" << std::endl;
}catch(std::exception const& e){
- std::cout << "Exception: " << e.what() << std::endl;
+ std::cerr << "Exception: " << e.what() << std::endl;
return ~0;
}
return 0;