3#include "boost/lexical_cast.hpp"
4#include "boost/algorithm/string.hpp"
7#include "pybind11/stl.h"
8#include "pybind11/pybind11.h"
42 return std::vector<T> ( aVec );
49 std::vector<std::string> sVec;
50 std::vector<T> result;
52 if ( ! aString.empty() )
54 boost::algorithm::split ( sVec, aString, boost::algorithm::is_any_of (
"," ) );
55 result.reserve ( sVec.size() );
57 for (
const auto& x: sVec )
59 result.push_back ( boost::lexical_cast<T> ( x ) );
69 std::vector<std::string> result;
71 if ( ! aString.empty() )
73 boost::algorithm::split ( result, aString, boost::algorithm::is_any_of (
"," ) );
80#if PY_VERSION_HEX >= 0x03000000
86 std::string stringFromUInt ( boost::lexical_cast<std::string> ( aUInt ) );
87 return ( stringFromUInt == std::string(uIntString) );
93 return boost::lexical_cast<uint32_t> ( uIntString );
100 valWord.
value( aValue );
101 valWord.
valid( aValid );
114 py::module_ lSubModule = aModule.def_submodule(
"tests");
122 lSubModule.def (
"convert_str_to_vec_str", pycohal::convert_string_to_vector<std::string> );
123 lSubModule.def (
"convert_str_to_vec_uint32", pycohal::convert_string_to_vector<uint32_t> );
124 lSubModule.def (
"copy_vec_uint32", pycohal::copy_vector<uint32_t> );
140 std::shared_ptr<uhal::ClientInterface>
buildClient(
const std::string& aId,
const std::string& aURI)
148 std::ostringstream osstream;
149 osstream <<
"0x" << std::hex << valWord.
value();
150 return osstream.str();
159 if (i >=
int(valVec.
size()))
160 throw py::index_error();
166 throw py::index_error();
173 size_t start, stop, step, slicelength;
174 if (!aSlice.compute(valVec.
size(), &start, &stop, &step, &slicelength))
175 throw py::error_already_set();
177 std::vector<T> lSliced(slicelength);
178 for (
size_t i = 0; i < slicelength; ++i) {
179 lSliced.at(i) = valVec.
at(start);
188 return boost::lexical_cast<std::string>(valWord.
value());
193 std::ostringstream lStream;
197 for (
size_t i=0; i<valVec.
size(); i++ )
199 lStream << valVec.
at ( i );
201 if ( i!= ( valVec.
size()-1 ) )
208 return lStream.str();
225 throw pybind11::stop_iteration();
257 py::class_<uhal::ValHeader>(m,
"ValHeader")
258 .def (py::init< const uhal::ValHeader& >())
263 py::class_<uhal::ValWord<uint32_t>>( m,
"ValWord_uint32")
264 .def ( py::init<>() )
271#
if PY_VERSION_HEX >= 0x03000000
279 py::class_<uhal::ValVector<uint32_t>>(m,
"ValVector_uint32", py::buffer_protocol())
280 .def ( py::init<>() )
292 const uint32_t* lData(v.
valid() ? v.
data() :
nullptr);
293 if (lData ==
nullptr) {
294 return py::buffer_info();
296 return py::buffer_info(
305 py::class_<uhal::Node>(m,
"Node")
329 .def (
"__iter__", [](
uhal::Node& n) {
return py::make_iterator(n.
begin(), n.
end()); }, py::keep_alive<0, 1>())
333 py::class_< uhal::Node::const_iterator >(m,
"NodeConstIterator")
339 py::class_<uhal::ClientInterface, std::shared_ptr<uhal::ClientInterface>>(m,
"ClientInterface")
358 py::class_<uhal::IPbusCore, uhal::ClientInterface, std::shared_ptr<uhal::IPbusCore>>(m,
"IPbusCore")
363 py::class_<uhal::UDP<uhal::IPbus<1, 3>>,
uhal::IPbusCore, std::shared_ptr<uhal::UDP<uhal::IPbus<1, 3>>>>(m,
"_UDP_IPbus_1_3");
364 py::class_<uhal::UDP<uhal::IPbus<2, 0>>,
uhal::IPbusCore, std::shared_ptr<uhal::UDP<uhal::IPbus<2, 0>>>>(m,
"_UDP_IPbus_2_0");
366 py::class_<uhal::TCP<uhal::IPbus<1, 3>, 1>,
uhal::IPbusCore, std::shared_ptr<uhal::TCP<uhal::IPbus<1, 3>, 1>>>(m,
"_TCP_IPbus_1_3");
367 py::class_<uhal::TCP<uhal::IPbus<2, 0>, 1>,
uhal::IPbusCore, std::shared_ptr<uhal::TCP<uhal::IPbus<2, 0>, 1>>>(m,
"_TCP_IPbus_2_0");
369 py::class_<uhal::TCP<uhal::ControlHub<uhal::IPbus<1, 3> >, 3>,
uhal::IPbusCore, std::shared_ptr<uhal::TCP<uhal::ControlHub<uhal::IPbus<1, 3> >, 3>>>(m,
"_TCP_ControlHub_IPbus_1_3");
370 py::class_<uhal::TCP<uhal::ControlHub<uhal::IPbus<2, 0>>, 3>,
uhal::IPbusCore, std::shared_ptr<uhal::TCP<uhal::ControlHub<uhal::IPbus<2, 0> >, 3>>>(m,
"_TCP_ControlHub_IPbus_2_0");
375 py::class_<uhal::HwInterface> (m,
"HwInterface")
376 .def ( py::init<const uhal::HwInterface&>() )
392 py::class_< uhal::ConnectionManager > (m,
"ConnectionManager")
393 .def ( py::init<const std::string&>() )
394 .def ( py::init<
const std::string&,
const std::vector<std::string>&>() )
const uhal::Node & NextNodeConstIterator(uhal::Node::const_iterator &aIt)
py::object const & pass_through(py::object const &o)
static ClientFactory & getInstance()
Static method to retrieve the single instance of the class.
std::shared_ptr< ClientInterface > getClient(const std::string &aId, const std::string &aUri)
Construct an IPbus client based on the protocol identifier specified.
An abstract base class for defining the interface to the various IPbus clients as well as providing t...
ValHeader write(const uint32_t &aAddr, const uint32_t &aValue)
Write a single, unmasked word to a register.
ValHeader writeBlock(const uint32_t &aAddr, const std::vector< uint32_t > &aValues, const defs::BlockReadWriteMode &aMode=defs::INCREMENTAL)
Write a block of data to a block of registers or a block-write port.
void dispatch()
Method to dispatch all queued transactions, and wait until all corresponding responses have been rece...
void setTimeoutPeriod(const uint32_t &aTimeoutPeriod=0)
A method to modify the timeout period for any pending or future transactions.
ValWord< uint32_t > rmw_bits(const uint32_t &aAddr, const uint32_t &aANDterm, const uint32_t &aORterm)
Read the value of a register, apply the AND-term, apply the OR-term, set the register to this new val...
ValWord< uint32_t > rmw_sum(const uint32_t &aAddr, const int32_t &aAddend)
Read the value of a register, add the addend, set the register to this new value and return a copy of...
ValVector< uint32_t > readBlock(const uint32_t &aAddr, const uint32_t &aSize, const defs::BlockReadWriteMode &aMode=defs::INCREMENTAL)
Read a block of unsigned data from a block of registers or a block-read port.
ValWord< uint32_t > read(const uint32_t &aAddr)
Read a single, unmasked, unsigned word.
const std::string & id() const
Return the identifier of the target for this client.
const std::string & uri() const
Return the url of the target for this client.
uint64_t getTimeoutPeriod()
A method to retrieve the timeout period currently being used.
A class to open and manage XML connection files and wrap up the interfaces to the NodeTreeBuilder and...
static void clearAddressFileCache()
Clears cache of Node tree structure for previously-opened address files (thread safe)
std::vector< std::string > getDevices() const
Return all device IDs known to this connection manager.
HwInterface getDevice(const std::string &aId)
Retrieves protocol, host, and port from the connection file to create an IPbus Client Retrieves the a...
A class which bundles a node tree and an IPbus client interface together providing everything you nee...
std::vector< std::string > getNodes() const
Return all node IDs known to this HwInterface.
const Node & getNode() const
Retrieve the top-level node.
const std::string & id() const
Return the identifier of the target for this client.
void dispatch()
Make the IPbus client issue a dispatch.
ClientInterface & getClient()
Get the underlying IPbus client.
bool hasNode(const std::string &aId) const
uint32_t getTimeoutPeriod()
A method to retrieve the timeout period currently being used.
const std::string & uri() const
Return the url of the target for this client.
void setTimeoutPeriod(const uint32_t &aTimeoutPeriod)
A method to modify the timeout period for any pending or future transactions.
A class providing the core IPbus packing functionality.
ValWord< uint32_t > readConfigurationSpace(const uint32_t &aAddr)
Read a single, unmasked, unsigned word from the configuration address space.
A heirarchical node for navigating heirarchical firmwares.
ClientInterface & getClient() const
Get the underlying IPbus client.
const defs::NodePermission & getPermission() const
Return the read/write access permissions of this node.
const std::unordered_map< std::string, std::string > & getFirmwareInfo() const
Return parameters for inferring the VHDL address decoding.
ValWord< uint32_t > read() const
Read a single, unmasked, unsigned word.
const uint32_t & getMask() const
Return the mask to be applied if this node is a sub-field, rather than an entire register.
const std::string & getId() const
Return the unique ID of the current node.
ValHeader writeBlockOffset(const std::vector< uint32_t > &aValues, const uint32_t &aOffset) const
Write a block of data to a block of registers or a block-write port.
const std::unordered_map< std::string, std::string > & getParameters() const
Return parameters of the current node.
const Node & getNode(const std::string &aId) const
Retrieve the Node given by a full-stop delimeted name path relative, to the current node.
const defs::BlockReadWriteMode & getMode() const
Return whether the node represents a single register, a block of registers or a block-read/write port...
std::string getPath() const
Return the full path to the current node.
ValHeader writeBlock(const std::vector< uint32_t > &aValues) const
Write a block of data to a block of registers or a block-write port.
ValVector< uint32_t > readBlockOffset(const uint32_t &aSize, const uint32_t &aOffset) const
Read a block of unsigned data from a block of registers or a block-read port.
ValHeader write(const uint32_t &aValue) const
Write a single, unmasked word to a register.
const uint32_t & getAddress() const
Return the register address with which this node is associated.
const std::string & getDescription() const
Return the optional description string which the user can specify for the current node.
const_iterator end() const
const uint32_t & getSize() const
Return the maximum size available to a block read/write.
std::vector< std::string > getNodes() const
Return all node IDs known to this HwInterface.
const std::string & getTags() const
Return the optional tags string which the user can specify for the current node.
const_iterator begin() const
const std::string & getModule() const
Return the name of the module in which the current node resides.
ValVector< uint32_t > readBlock(const uint32_t &aSize) const
Read a block of unsigned data from a block of registers or a block-read port.
bool hasNode(const std::string &aId) const
static void blockSIGBUS()
A class which wraps a block of data and marks whether or not it is valid.
const_iterator begin() const
If the memory has previously been marked as valid, return a const iterator to the beginning of the un...
const T * data() const
Return the address of the underlying memory.
bool valid()
Return whether the Validated memory is marked as valid.
const T & at(std::size_t aIndex) const
If the memory has previously been marked as valid, give random access into memory.
const_iterator end() const
If the memory has previously been marked as valid, return a const iterator to the end (one past last ...
std::size_t size() const
Return the size of the underlying memory.
A class which wraps a single word of data and marks whether or not it is valid.
T value() const
Return the value of the validated memory with check on validity.
bool valid()
Return whether the Validated memory is marked as valid.
uint32_t test_convert_str_to_uint32(const std::string &uIntString)
Converts string argument to uint32_t, and returns this value. Used in tests to check that uint32 retu...
void wrap_enums(pybind11::module_ &)
bool test_check_uint32_argument(uint32_t aUInt, const py::bytes &uIntString)
Returns whether uint32 and string arguments represent the same nubmer. Used in tests to check that ui...
std::vector< T > copy_vector(const std::vector< T > &aVec)
Trivial function that returns copy of vector argument in order to test vector to/from list converters...
std::string convert_to_string(const uhal::ValWord< uint32_t > &valWord)
std::shared_ptr< uhal::ClientInterface > buildClient(const std::string &aId, const std::string &aURI)
Constructs a ClientInterface using the ClientFactory.
void wrap_version_and_build_info(pybind11::module_ &)
void wrap_test_functions(py::module_ &aModule)
Wraps functions that are only sed in unti tests. Puts them in "tests" sub-module.
void wrap_logging_functions(pybind11::module_ &)
uhal::ValWord< uint32_t > get_dummy_ValWord(const uint32_t aValue, const bool aValid)
Returns dummy ValWord instance for testing.
void create_sigbus_buard()
const auto const_ref_return_policy
Default return value policy for const references returned attribute 'getter' methods.
std::vector< T > convert_string_to_vector(const std::string &aString)
Returns vector, generated from splitting string argument using "," as delimeter, and converting strin...
void wrap_exceptions(pybind11::module_ &)
Wraps all uHAL exceptions (i.e. creates corresponding Python classes, and regsiters appropriate excep...
py::bytes hex_string(const uhal::ValWord< uint32_t > &valWord)
Returns hex string for ValWord<uint32_t> value.
const auto norm_ref_return_policy
Return value policy for internal references.
BlockReadWriteMode
define whether transactions target a single register, a block of registers, a block-read/write port o...
const uint32_t NOMASK
define what it means to have no mask
double measureFileWriteLatency(const std::string &aFilePath, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aVerbose)
double measureReadLatency(ClientInterface &aClient, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aDispatchEachIteration, bool aVerbose)
double measureFileReadLatency(const std::string &aFilePath, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aVerbose)
double measureWriteLatency(ClientInterface &aClient, uint32_t aBaseAddr, uint32_t aDepth, size_t aNrIterations, bool aDispatchEachIteration, bool aVerbose)
#define PYBIND11_MODULE(name, variable)
\rst This macro creates the entry point that will be invoked when the Python interpreter imports an e...
Struct containing wrapper functions for list-like indexing of ValVector<uint32_t> in python.
static std::vector< T > getSlice(const uhal::ValVector< T > &valVec, const py::slice aSlice)
static const T & getItem(const uhal::ValVector< T > &valVec, int i)