PothosUtilDeviceInfo.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (c) 2013-2017 Josh Blum
  2. // SPDX-License-Identifier: BSL-1.0
  3. #include "PothosUtil.hpp"
  4. #include <Pothos/Plugin.hpp>
  5. #include <Pothos/Proxy.hpp>
  6. #include <Poco/Path.h>
  7. #include <sstream>
  8. #include <fstream>
  9. #include <iostream>
  10. #include <json.hpp>
  11. using json = nlohmann::json;
  12. void PothosUtilBase::printDeviceInfo(void)
  13. {
  14. Pothos::ScopedInit init;
  15. const auto deviceType = this->config().getString("deviceType");
  16. if (deviceType.empty())
  17. {
  18. std::cout << std::endl;
  19. std::cout << ">>> Specify --device-info=deviceType for more information..." << std::endl;
  20. std::cout << ">>> Available device types in the plugin tree are: " << std::endl;
  21. for (const auto &name : Pothos::PluginRegistry::list("/devices"))
  22. {
  23. std::cout << " * " << name << std::endl;
  24. }
  25. std::cout << std::endl;
  26. return;
  27. }
  28. //extract the JSON device information
  29. auto path = Pothos::PluginPath("/devices").join(deviceType).join("info");
  30. std::cout << ">>> Querying device info: " << path.toString() << std::endl;
  31. auto plugin = Pothos::PluginRegistry::get(path);
  32. auto call = plugin.getObject().extract<Pothos::Callable>();
  33. auto info = json::parse(call.call<std::string>());
  34. //dump the information to file
  35. if (this->config().has("outputFile"))
  36. {
  37. const auto infoFile = this->config().getString("outputFile");
  38. std::cout << ">>> Dumping info: " << infoFile << std::endl;
  39. std::ofstream ofs(Poco::Path::expand(infoFile));
  40. ofs << info.dump(4);
  41. }
  42. //or otherwise to stdout
  43. else
  44. {
  45. std::cout << info.dump(4) << std::endl;
  46. }
  47. }