#pragma once #include "ThreadLogging.h" #include "SimpleLogger.h" namespace Incart::Usb { #include "libusb-1.0/no_warnings_libusb.h" static constexpr int VENDOR_ID = 0x0483; static constexpr int PRODUCT_ID = 0x7503; static constexpr unsigned char CMD_OUT_ENDPOINT = 0x04; static constexpr unsigned char CMD_INP_ENDPOINT = 0x85; static constexpr unsigned char VIS_INP_ENDPOINT = 0x83; static constexpr unsigned char DATA_OUT_ENDPOINT = 0x07; static constexpr unsigned char DATA_INP_ENDPOINT = 0x86; class UsbContext { protected: Common::ThreadLogging* m_log; Common::SimpleLogger* m_errorLogger; libusb_device_handle* m_deviceHandle = nullptr; std::atomic m_lastTransferStatus; public: UsbContext(Common::ThreadLogging* log, Common::SimpleLogger* errorLogger) : m_log(log), m_errorLogger(errorLogger) { m_lastTransferStatus.store(libusb_transfer_status::LIBUSB_TRANSFER_NO_DEVICE); } public: Common::ThreadLogging* getLog() { return m_log; } Common::SimpleLogger* getErrorLoger() { return m_errorLogger; } libusb_device_handle* getDeviceHandle() { return m_deviceHandle; } void setDeviceHandle(libusb_device_handle* dh) { m_deviceHandle = dh; } int32_t getLastTransferStatus() { return m_lastTransferStatus.load(); } void setLastTransferStatus(int32_t status) { m_lastTransferStatus.store(status); } void logError(const std::string& errorMessage) { *m_log << errorMessage << '\n'; m_errorLogger->write(errorMessage); } void logInfo(const std::string& record) { *m_log << record << '\n'; } }; } // namespace Incart::Usb