radio_tool 0.2.1
Loading...
Searching...
No Matches
usb_radio_factory.hpp
1
18#pragma once
19
20#include <radio_tool/radio/radio.hpp>
21
22#include <string>
23#include <vector>
24#include <memory>
25#include <functional>
26#include <thread>
27
28#include <libusb-1.0/libusb.h>
29
30namespace radio_tool::radio
31{
32 class USBRadioInfo : public RadioInfo
33 {
34 public:
35 const std::wstring manufacturer, product;
36 const uint16_t vid, pid, index;
37
39 const CreateRadioOps l,
40 const std::wstring& mfg,
41 const std::wstring& prd,
42 const uint16_t& vid,
43 const uint16_t& pid,
44 const uint16_t& idx)
45 : manufacturer(mfg), product(prd), vid(vid), pid(pid), index(idx), loader(l) {}
46
47 auto ToString() const -> const std::wstring override
48 {
49 std::wstringstream os;
50 os << L"["
51 << std::setfill(L'0') << std::setw(4) << std::hex << vid
52 << L":"
53 << std::setfill(L'0') << std::setw(4) << std::hex << pid
54 << L"]: idx=" << std::setfill(L'0') << std::setw(3) << std::to_wstring(index) << L", "
55 << manufacturer << L" " << product;
56 return os.str();
57 }
58
59 auto OpenDevice() const -> RadioOperations* override
60 {
61 return loader();
62 }
63
64 private:
65 const CreateRadioOps loader;
66 };
67
73 {
74 public:
77 auto ListDevices(const uint16_t& idx_offset) const -> const std::vector<RadioInfo*> override;
78 auto HandleEvents() -> void;
79 private:
80 auto GetDeviceString(const uint8_t&, libusb_device_handle*) const->std::wstring;
81 static auto OpenDevice(const uint8_t& bus, const uint8_t& port)->libusb_device_handle*;
82 static auto CreateContext()->libusb_context*;
83
84 libusb_context* usb_ctx;
85 std::thread events;
86 };
87}