From f13615ec140aec508501d21a21190782318c360a Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Thu, 5 Mar 2020 11:35:14 -0800 Subject: uhd: cal: Add database class This class contains methods to store and retrieve data from the local calibration database. Note that in this case, the "database" is just a bunch of files on the local filesystem. --- host/lib/cal/cal_python.hpp | 61 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 host/lib/cal/cal_python.hpp (limited to 'host/lib/cal/cal_python.hpp') diff --git a/host/lib/cal/cal_python.hpp b/host/lib/cal/cal_python.hpp new file mode 100644 index 000000000..0fe87046f --- /dev/null +++ b/host/lib/cal/cal_python.hpp @@ -0,0 +1,61 @@ +// +// Copyright 2020 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#ifndef INCLUDED_UHD_CAL_PYTHON_HPP +#define INCLUDED_UHD_CAL_PYTHON_HPP + +#include + +std::vector pybytes_to_vector(const py::bytes& data) +{ + const std::string data_str = std::string(data); + return std::vector(data_str.cbegin(), data_str.cend()); +} + +py::bytes vector_to_pybytes(const std::vector& data) +{ + return py::bytes(std::string(data.cbegin(), data.cend())); +} + +void export_cal(py::module& m) +{ + using namespace uhd::usrp::cal; + + // Cal Database + using database = uhd::usrp::cal::database; + using source = uhd::usrp::cal::source; + + py::enum_(m, "source") + .value("ANY", source::ANY) + .value("RC", source::RC) + .value("FILESYSTEM", source::FILESYSTEM) + .value("FLASH", source::FLASH) + .value("USER", source::USER) + .value("NONE", source::NONE); + + py::class_(m, "database") + .def_static("read_cal_data", + [](const std::string& key, + const std::string& serial, + const source source_type) { + return vector_to_pybytes( + database::read_cal_data(key, serial, source_type)); + }, + py::arg("key"), + py::arg("serial"), + py::arg("source_type") = source::ANY) + .def_static("has_cal_data", + &database::has_cal_data, + py::arg("key"), + py::arg("serial"), + py::arg("source_type") = source::ANY) + .def_static("write_cal_data", + [](const std::string& key, const std::string& serial, const py::bytes data) { + database::write_cal_data(key, serial, pybytes_to_vector(data)); + }); +} + +#endif /* INCLUDED_UHD_CAL_PYTHON_HPP */ -- cgit v1.2.3