aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-01-06 12:52:53 -0800
committerJosh Blum <josh@joshknows.com>2011-01-06 12:52:53 -0800
commitef8d79673d29f2bd62e36b7b71d2e0430d3faf0b (patch)
tree6029e0a0eabb08cd00328a1719e83bb8ee028c0b
parentfd9962af9ed6682117c3ab224548298907f59c49 (diff)
downloaduhd-ef8d79673d29f2bd62e36b7b71d2e0430d3faf0b.tar.gz
uhd-ef8d79673d29f2bd62e36b7b71d2e0430d3faf0b.tar.bz2
uhd-ef8d79673d29f2bd62e36b7b71d2e0430d3faf0b.zip
uhd: split types into multiple files as it was getting unwieldy
-rw-r--r--host/lib/types/CMakeLists.txt6
-rw-r--r--host/lib/types/clock_config.cpp44
-rw-r--r--host/lib/types/device_addr.cpp77
-rw-r--r--host/lib/types/mac_addr.cpp76
-rw-r--r--host/lib/types/serial.cpp56
-rw-r--r--host/lib/types/time_spec.cpp86
-rw-r--r--host/lib/types/tune.cpp52
-rw-r--r--host/lib/types/types.cpp273
8 files changed, 397 insertions, 273 deletions
diff --git a/host/lib/types/CMakeLists.txt b/host/lib/types/CMakeLists.txt
index 7a8093ed5..dfb7cf903 100644
--- a/host/lib/types/CMakeLists.txt
+++ b/host/lib/types/CMakeLists.txt
@@ -19,7 +19,13 @@
# This file included, use CMake directory variables
########################################################################
LIBUHD_APPEND_SOURCES(
+ ${CMAKE_CURRENT_SOURCE_DIR}/clock_config.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/device_addr.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/mac_addr.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ranges.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sensors.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/serial.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/time_spec.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/tune.cpp
${CMAKE_CURRENT_SOURCE_DIR}/types.cpp
)
diff --git a/host/lib/types/clock_config.cpp b/host/lib/types/clock_config.cpp
new file mode 100644
index 000000000..db40fb045
--- /dev/null
+++ b/host/lib/types/clock_config.cpp
@@ -0,0 +1,44 @@
+//
+// Copyright 2010-2011 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/>.
+//
+
+#include <uhd/types/clock_config.hpp>
+
+using namespace uhd;
+
+clock_config_t clock_config_t::external(void){
+ clock_config_t clock_config;
+ clock_config.ref_source = clock_config_t::REF_SMA;
+ clock_config.pps_source = clock_config_t::PPS_SMA;
+ clock_config.pps_polarity = clock_config_t::PPS_POS;
+ return clock_config;
+}
+
+clock_config_t clock_config_t::internal(void){
+ clock_config_t clock_config;
+ clock_config.ref_source = clock_config_t::REF_INT;
+ clock_config.pps_source = clock_config_t::PPS_INT;
+ clock_config.pps_polarity = clock_config_t::PPS_POS;
+ return clock_config;
+}
+
+clock_config_t::clock_config_t(void):
+ ref_source(REF_INT),
+ pps_source(PPS_INT),
+ pps_polarity(PPS_POS)
+{
+ /* NOP */
+}
diff --git a/host/lib/types/device_addr.cpp b/host/lib/types/device_addr.cpp
new file mode 100644
index 000000000..098fb3bc6
--- /dev/null
+++ b/host/lib/types/device_addr.cpp
@@ -0,0 +1,77 @@
+//
+// Copyright 2010-2011 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/>.
+//
+
+#include <uhd/types/device_addr.hpp>
+#include <boost/algorithm/string.hpp> //for trim
+#include <boost/tokenizer.hpp>
+#include <boost/foreach.hpp>
+#include <boost/format.hpp>
+#include <stdexcept>
+#include <sstream>
+
+using namespace uhd;
+
+static const std::string arg_delim = ",";
+static const std::string pair_delim = "=";
+
+static std::string trim(const std::string &in){
+ return boost::algorithm::trim_copy(in);
+}
+
+static boost::tokenizer<boost::char_separator<char> > tokenize(
+ const std::string &input, const std::string &tok
+){
+ return boost::tokenizer<boost::char_separator<char> >(
+ input, boost::char_separator<char>(tok.c_str())
+ );
+}
+
+device_addr_t::device_addr_t(const std::string &args){
+ BOOST_FOREACH(const std::string &pair, tokenize(args, arg_delim)){
+ if (trim(pair) == "") continue;
+ std::string key;
+ BOOST_FOREACH(const std::string &tok, tokenize(pair, pair_delim)){
+ if (key.empty()) key = tok;
+ else{
+ this->set(trim(key), trim(tok));
+ goto continue_next_arg;
+ }
+ }
+ throw std::runtime_error("invalid args string: "+args);
+ continue_next_arg: continue;
+ }
+}
+
+std::string device_addr_t::to_pp_string(void) const{
+ if (this->size() == 0) return "Empty Device Address";
+
+ std::stringstream ss;
+ ss << "Device Address:" << std::endl;
+ BOOST_FOREACH(std::string key, this->keys()){
+ ss << boost::format(" %s: %s") % key % this->get(key) << std::endl;
+ }
+ return ss.str();
+}
+
+std::string device_addr_t::to_string(void) const{
+ std::string args_str;
+ size_t count = 0;
+ BOOST_FOREACH(const std::string &key, this->keys()){
+ args_str += ((count++)? arg_delim : "") + key + pair_delim + this->get(key);
+ }
+ return args_str;
+}
diff --git a/host/lib/types/mac_addr.cpp b/host/lib/types/mac_addr.cpp
new file mode 100644
index 000000000..d16045a5d
--- /dev/null
+++ b/host/lib/types/mac_addr.cpp
@@ -0,0 +1,76 @@
+//
+// Copyright 2010-2011 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/>.
+//
+
+#include <uhd/types/mac_addr.hpp>
+#include <uhd/utils/assert.hpp>
+#include <boost/tokenizer.hpp>
+#include <boost/foreach.hpp>
+#include <boost/format.hpp>
+#include <boost/cstdint.hpp>
+#include <stdexcept>
+#include <sstream>
+
+using namespace uhd;
+
+mac_addr_t::mac_addr_t(const byte_vector_t &bytes) : _bytes(bytes){
+ UHD_ASSERT_THROW(_bytes.size() == 6);
+}
+
+mac_addr_t mac_addr_t::from_bytes(const byte_vector_t &bytes){
+ return mac_addr_t(bytes);
+}
+
+mac_addr_t mac_addr_t::from_string(const std::string &mac_addr_str){
+
+ byte_vector_t bytes;
+
+ try{
+ if (mac_addr_str.size() != 17){
+ throw std::runtime_error("expected exactly 17 characters");
+ }
+
+ //split the mac addr hex string at the colons
+ boost::tokenizer<boost::char_separator<char> > hex_num_toks(
+ mac_addr_str, boost::char_separator<char>(":"));
+ BOOST_FOREACH(const std::string &hex_str, hex_num_toks){
+ int hex_num;
+ std::istringstream iss(hex_str);
+ iss >> std::hex >> hex_num;
+ bytes.push_back(boost::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()
+ ));
+ }
+
+ return mac_addr_t::from_bytes(bytes);
+}
+
+byte_vector_t mac_addr_t::to_bytes(void) const{
+ return _bytes;
+}
+
+std::string mac_addr_t::to_string(void) const{
+ std::string addr = "";
+ BOOST_FOREACH(boost::uint8_t byte, this->to_bytes()){
+ addr += str(boost::format("%s%02x") % ((addr == "")?"":":") % int(byte));
+ }
+ return addr;
+}
diff --git a/host/lib/types/serial.cpp b/host/lib/types/serial.cpp
new file mode 100644
index 000000000..5923e9fb2
--- /dev/null
+++ b/host/lib/types/serial.cpp
@@ -0,0 +1,56 @@
+//
+// Copyright 2010-2011 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/>.
+//
+
+#include <uhd/types/serial.hpp>
+#include <boost/thread.hpp> //for sleeping
+#include <boost/assign/list_of.hpp>
+
+using namespace uhd;
+
+spi_config_t::spi_config_t(edge_t edge):
+ mosi_edge(edge),
+ miso_edge(edge)
+{
+ /* NOP */
+}
+
+void i2c_iface::write_eeprom(
+ boost::uint8_t addr,
+ boost::uint8_t offset,
+ const byte_vector_t &bytes
+){
+ for (size_t i = 0; i < bytes.size(); i++){
+ //write a byte at a time, its easy that way
+ byte_vector_t cmd = boost::assign::list_of(offset+i)(bytes[i]);
+ this->write_i2c(addr, cmd);
+ boost::this_thread::sleep(boost::posix_time::milliseconds(10)); //worst case write
+ }
+}
+
+byte_vector_t i2c_iface::read_eeprom(
+ boost::uint8_t addr,
+ boost::uint8_t offset,
+ size_t num_bytes
+){
+ byte_vector_t bytes;
+ for (size_t i = 0; i < num_bytes; i++){
+ //do a zero byte write to start read cycle
+ this->write_i2c(addr, byte_vector_t(1, offset+i));
+ bytes.push_back(this->read_i2c(addr, 1).at(0));
+ }
+ return bytes;
+}
diff --git a/host/lib/types/time_spec.cpp b/host/lib/types/time_spec.cpp
new file mode 100644
index 000000000..d3aba5bdd
--- /dev/null
+++ b/host/lib/types/time_spec.cpp
@@ -0,0 +1,86 @@
+//
+// Copyright 2010-2011 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/>.
+//
+
+#include <uhd/types/time_spec.hpp>
+#include <boost/math/special_functions/round.hpp>
+
+using namespace uhd;
+time_spec_t::time_spec_t(double secs):
+ _full_secs(0),
+ _frac_secs(secs)
+{
+ /* NOP */
+}
+
+time_spec_t::time_spec_t(time_t full_secs, double frac_secs):
+ _full_secs(full_secs),
+ _frac_secs(frac_secs)
+{
+ /* NOP */
+}
+
+time_spec_t::time_spec_t(time_t full_secs, long tick_count, double tick_rate):
+ _full_secs(full_secs),
+ _frac_secs(double(tick_count)/tick_rate)
+{
+ /* NOP */
+}
+
+long time_spec_t::get_tick_count(double tick_rate) const{
+ return boost::math::iround(this->get_frac_secs()*tick_rate);
+}
+
+double time_spec_t::get_real_secs(void) const{
+ return this->_full_secs + this->_frac_secs;
+}
+
+time_t time_spec_t::get_full_secs(void) const{
+ double intpart;
+ std::modf(this->_frac_secs, &intpart);
+ return this->_full_secs + time_t(intpart);
+}
+
+double time_spec_t::get_frac_secs(void) const{
+ return std::fmod(this->_frac_secs, 1.0);
+}
+
+time_spec_t &time_spec_t::operator+=(const time_spec_t &rhs){
+ this->_full_secs += rhs.get_full_secs();
+ this->_frac_secs += rhs.get_frac_secs();
+ return *this;
+}
+
+time_spec_t &time_spec_t::operator-=(const time_spec_t &rhs){
+ this->_full_secs -= rhs.get_full_secs();
+ this->_frac_secs -= rhs.get_frac_secs();
+ return *this;
+}
+
+bool uhd::operator==(const time_spec_t &lhs, const time_spec_t &rhs){
+ return
+ lhs.get_full_secs() == rhs.get_full_secs() and
+ lhs.get_frac_secs() == rhs.get_frac_secs()
+ ;
+}
+
+bool uhd::operator<(const time_spec_t &lhs, const time_spec_t &rhs){
+ return (
+ (lhs.get_full_secs() < rhs.get_full_secs()) or (
+ (lhs.get_full_secs() == rhs.get_full_secs()) and
+ (lhs.get_frac_secs() < rhs.get_frac_secs())
+ ));
+}
diff --git a/host/lib/types/tune.cpp b/host/lib/types/tune.cpp
new file mode 100644
index 000000000..5a1654932
--- /dev/null
+++ b/host/lib/types/tune.cpp
@@ -0,0 +1,52 @@
+//
+// Copyright 2010-2011 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/>.
+//
+
+#include <uhd/types/tune_request.hpp>
+#include <uhd/types/tune_result.hpp>
+#include <boost/format.hpp>
+
+using namespace uhd;
+
+tune_request_t::tune_request_t(double target_freq):
+ target_freq(target_freq),
+ inter_freq_policy(POLICY_AUTO),
+ dsp_freq_policy(POLICY_AUTO)
+{
+ /* NOP */
+}
+
+tune_request_t::tune_request_t(double target_freq, double lo_off):
+ target_freq(target_freq),
+ inter_freq_policy(POLICY_MANUAL),
+ inter_freq(target_freq + lo_off),
+ dsp_freq_policy(POLICY_AUTO)
+{
+ /* NOP */
+}
+
+std::string tune_result_t::to_pp_string(void) const{
+ return str(boost::format(
+ "Tune Result:\n"
+ " Target Intermediate Freq: %f (MHz)\n"
+ " Actual Intermediate Freq: %f (MHz)\n"
+ " Target DSP Freq Shift: %f (MHz)\n"
+ " Actual DSP Freq Shift: %f (MHz)\n"
+ )
+ % (target_inter_freq/1e6) % (actual_inter_freq/1e6)
+ % (target_dsp_freq/1e6) % (actual_dsp_freq/1e6)
+ );
+}
diff --git a/host/lib/types/types.cpp b/host/lib/types/types.cpp
index dce8d0828..69a1e40e5 100644
--- a/host/lib/types/types.cpp
+++ b/host/lib/types/types.cpp
@@ -15,94 +15,17 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
-#include <uhd/utils/assert.hpp>
-#include <uhd/types/tune_request.hpp>
-#include <uhd/types/tune_result.hpp>
-#include <uhd/types/clock_config.hpp>
#include <uhd/types/stream_cmd.hpp>
#include <uhd/types/metadata.hpp>
-#include <uhd/types/time_spec.hpp>
-#include <uhd/types/device_addr.hpp>
-#include <uhd/types/mac_addr.hpp>
#include <uhd/types/otw_type.hpp>
#include <uhd/types/io_type.hpp>
-#include <uhd/types/serial.hpp>
-#include <boost/math/special_functions/round.hpp>
-#include <boost/foreach.hpp>
-#include <boost/format.hpp>
#include <boost/cstdint.hpp>
-#include <boost/assign/list_of.hpp>
-#include <boost/thread.hpp>
#include <stdexcept>
#include <complex>
-#include <sstream>
using namespace uhd;
/***********************************************************************
- * tune request
- **********************************************************************/
-tune_request_t::tune_request_t(double target_freq):
- target_freq(target_freq),
- inter_freq_policy(POLICY_AUTO),
- dsp_freq_policy(POLICY_AUTO)
-{
- /* NOP */
-}
-
-tune_request_t::tune_request_t(double target_freq, double lo_off):
- target_freq(target_freq),
- inter_freq_policy(POLICY_MANUAL),
- inter_freq(target_freq + lo_off),
- dsp_freq_policy(POLICY_AUTO)
-{
- /* NOP */
-}
-
-/***********************************************************************
- * tune result
- **********************************************************************/
-std::string tune_result_t::to_pp_string(void) const{
- return str(boost::format(
- "Tune Result:\n"
- " Target Intermediate Freq: %f (MHz)\n"
- " Actual Intermediate Freq: %f (MHz)\n"
- " Target DSP Freq Shift: %f (MHz)\n"
- " Actual DSP Freq Shift: %f (MHz)\n"
- )
- % (target_inter_freq/1e6) % (actual_inter_freq/1e6)
- % (target_dsp_freq/1e6) % (actual_dsp_freq/1e6)
- );
-}
-
-/***********************************************************************
- * clock config
- **********************************************************************/
-clock_config_t clock_config_t::external(void){
- clock_config_t clock_config;
- clock_config.ref_source = clock_config_t::REF_SMA;
- clock_config.pps_source = clock_config_t::PPS_SMA;
- clock_config.pps_polarity = clock_config_t::PPS_POS;
- return clock_config;
-}
-
-clock_config_t clock_config_t::internal(void){
- clock_config_t clock_config;
- clock_config.ref_source = clock_config_t::REF_INT;
- clock_config.pps_source = clock_config_t::PPS_INT;
- clock_config.pps_polarity = clock_config_t::PPS_POS;
- return clock_config;
-}
-
-clock_config_t::clock_config_t(void):
- ref_source(REF_INT),
- pps_source(PPS_INT),
- pps_polarity(PPS_POS)
-{
- /* NOP */
-}
-
-/***********************************************************************
* stream command
**********************************************************************/
stream_cmd_t::stream_cmd_t(const stream_mode_t &stream_mode):
@@ -126,165 +49,6 @@ tx_metadata_t::tx_metadata_t(void):
}
/***********************************************************************
- * time spec
- **********************************************************************/
-time_spec_t::time_spec_t(double secs):
- _full_secs(0),
- _frac_secs(secs)
-{
- /* NOP */
-}
-
-time_spec_t::time_spec_t(time_t full_secs, double frac_secs):
- _full_secs(full_secs),
- _frac_secs(frac_secs)
-{
- /* NOP */
-}
-
-time_spec_t::time_spec_t(time_t full_secs, long tick_count, double tick_rate):
- _full_secs(full_secs),
- _frac_secs(double(tick_count)/tick_rate)
-{
- /* NOP */
-}
-
-long time_spec_t::get_tick_count(double tick_rate) const{
- return boost::math::iround(this->get_frac_secs()*tick_rate);
-}
-
-double time_spec_t::get_real_secs(void) const{
- return this->_full_secs + this->_frac_secs;
-}
-
-time_t time_spec_t::get_full_secs(void) const{
- double intpart;
- std::modf(this->_frac_secs, &intpart);
- return this->_full_secs + time_t(intpart);
-}
-
-double time_spec_t::get_frac_secs(void) const{
- return std::fmod(this->_frac_secs, 1.0);
-}
-
-time_spec_t &time_spec_t::operator+=(const time_spec_t &rhs){
- this->_full_secs += rhs.get_full_secs();
- this->_frac_secs += rhs.get_frac_secs();
- return *this;
-}
-
-time_spec_t &time_spec_t::operator-=(const time_spec_t &rhs){
- this->_full_secs -= rhs.get_full_secs();
- this->_frac_secs -= rhs.get_frac_secs();
- return *this;
-}
-
-bool uhd::operator==(const time_spec_t &lhs, const time_spec_t &rhs){
- return
- lhs.get_full_secs() == rhs.get_full_secs() and
- lhs.get_frac_secs() == rhs.get_frac_secs()
- ;
-}
-
-bool uhd::operator<(const time_spec_t &lhs, const time_spec_t &rhs){
- return (
- (lhs.get_full_secs() < rhs.get_full_secs()) or (
- (lhs.get_full_secs() == rhs.get_full_secs()) and
- (lhs.get_frac_secs() < rhs.get_frac_secs())
- ));
-}
-
-/***********************************************************************
- * device addr
- **********************************************************************/
-static const std::string arg_delim = ",";
-static const std::string pair_delim = "=";
-
-static std::string trim(const std::string &in){
- return boost::algorithm::trim_copy(in);
-}
-
-device_addr_t::device_addr_t(const std::string &args){
- BOOST_FOREACH(const std::string &pair, std::split_string(args, arg_delim)){
- if (trim(pair) == "") continue;
-
- std::vector<std::string> key_val = std::split_string(pair, pair_delim);
- if (key_val.size() != 2) throw std::runtime_error("invalid args string: "+args);
- (*this)[trim(key_val.front())] = trim(key_val.back());
- }
-}
-
-std::string device_addr_t::to_pp_string(void) const{
- if (this->size() == 0) return "Empty Device Address";
-
- std::stringstream ss;
- ss << "Device Address:" << std::endl;
- BOOST_FOREACH(std::string key, this->keys()){
- ss << boost::format(" %s: %s") % key % (*this)[key] << std::endl;
- }
- return ss.str();
-}
-
-std::string device_addr_t::to_string(void) const{
- std::string args_str;
- size_t count = 0;
- BOOST_FOREACH(const std::string &key, this->keys()){
- args_str += ((count++)? arg_delim : "") + key + pair_delim + (*this)[key];
- }
- return args_str;
-}
-
-/***********************************************************************
- * mac addr
- **********************************************************************/
-mac_addr_t::mac_addr_t(const byte_vector_t &bytes) : _bytes(bytes){
- UHD_ASSERT_THROW(_bytes.size() == 6);
-}
-
-mac_addr_t mac_addr_t::from_bytes(const byte_vector_t &bytes){
- return mac_addr_t(bytes);
-}
-
-mac_addr_t mac_addr_t::from_string(const std::string &mac_addr_str){
-
- byte_vector_t bytes;
-
- try{
- if (mac_addr_str.size() != 17){
- throw std::runtime_error("expected exactly 17 characters");
- }
-
- //split the mac addr hex string at the colons
- BOOST_FOREACH(const std::string &hex_str, std::split_string(mac_addr_str, ":")){
- int hex_num;
- std::istringstream iss(hex_str);
- iss >> std::hex >> hex_num;
- bytes.push_back(boost::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()
- ));
- }
-
- return mac_addr_t::from_bytes(bytes);
-}
-
-byte_vector_t mac_addr_t::to_bytes(void) const{
- return _bytes;
-}
-
-std::string mac_addr_t::to_string(void) const{
- std::string addr = "";
- BOOST_FOREACH(boost::uint8_t byte, this->to_bytes()){
- addr += str(boost::format("%s%02x") % ((addr == "")?"":":") % int(byte));
- }
- return addr;
-}
-
-/***********************************************************************
* otw type
**********************************************************************/
size_t otw_type_t::get_sample_size(void) const{
@@ -320,40 +84,3 @@ io_type_t::io_type_t(size_t size)
: size(size), tid(CUSTOM_TYPE){
/* NOP */
}
-
-/***********************************************************************
- * serial
- **********************************************************************/
-spi_config_t::spi_config_t(edge_t edge):
- mosi_edge(edge),
- miso_edge(edge)
-{
- /* NOP */
-}
-
-void i2c_iface::write_eeprom(
- boost::uint8_t addr,
- boost::uint8_t offset,
- const byte_vector_t &bytes
-){
- for (size_t i = 0; i < bytes.size(); i++){
- //write a byte at a time, its easy that way
- byte_vector_t cmd = boost::assign::list_of(offset+i)(bytes[i]);
- this->write_i2c(addr, cmd);
- boost::this_thread::sleep(boost::posix_time::milliseconds(10)); //worst case write
- }
-}
-
-byte_vector_t i2c_iface::read_eeprom(
- boost::uint8_t addr,
- boost::uint8_t offset,
- size_t num_bytes
-){
- byte_vector_t bytes;
- for (size_t i = 0; i < num_bytes; i++){
- //do a zero byte write to start read cycle
- this->write_i2c(addr, byte_vector_t(1, offset+i));
- bytes.push_back(this->read_i2c(addr, 1).at(0));
- }
- return bytes;
-}