Features: - Cross-platform support (Windows/Linux/macOS) - CAN and CANFD protocol support - USB communication (WinUSB/libusb) - Device management and configuration - Message transmission and reception - Filter configuration - CMake build system - Comprehensive examples and tests
83 lines
2.4 KiB
C++
83 lines
2.4 KiB
C++
/**
|
||
* @file WindowsPlatform.h
|
||
* @brief Windows平台实现
|
||
*/
|
||
|
||
#ifndef USB2CAN_WINDOWS_PLATFORM_H
|
||
#define USB2CAN_WINDOWS_PLATFORM_H
|
||
|
||
#include "Platform.h"
|
||
|
||
#ifdef _WIN32
|
||
#include <windows.h>
|
||
#include <setupapi.h>
|
||
#include <winusb.h>
|
||
#endif
|
||
|
||
namespace usb2can {
|
||
namespace platform {
|
||
|
||
/**
|
||
* @brief Windows平台实现类
|
||
*/
|
||
class WindowsPlatform : public Platform {
|
||
public:
|
||
WindowsPlatform();
|
||
~WindowsPlatform() override;
|
||
|
||
PlatformType getType() const override;
|
||
bool initialize() override;
|
||
std::vector<std::string> scanUsbDevices(uint16_t vendorId, uint16_t productId) override;
|
||
void* openUsbDevice(const std::string& devicePath) override;
|
||
bool closeUsbDevice(void* deviceHandle) override;
|
||
int writeUsbData(void* deviceHandle, const uint8_t* data, size_t size, int timeout) override;
|
||
int readUsbData(void* deviceHandle, uint8_t* data, size_t size, int timeout) override;
|
||
bool getDeviceInfo(void* deviceHandle, DeviceInfo& info) override;
|
||
|
||
private:
|
||
/**
|
||
* @brief Windows设备句柄结构体
|
||
*/
|
||
struct WindowsDeviceHandle {
|
||
HANDLE deviceHandle; ///< 设备句柄
|
||
WINUSB_INTERFACE_HANDLE winUsbHandle; ///< WinUSB接口句柄
|
||
std::string devicePath; ///< 设备路径
|
||
};
|
||
|
||
/**
|
||
* @brief 获取设备接口路径
|
||
* @param deviceInfoSet 设备信息集
|
||
* @param deviceInfoData 设备信息数据
|
||
* @return 设备接口路径
|
||
*/
|
||
std::string getDeviceInterfacePath(HDEVINFO deviceInfoSet, SP_DEVINFO_DATA deviceInfoData);
|
||
|
||
/**
|
||
* @brief 打开WinUSB设备
|
||
* @param devicePath 设备路径
|
||
* @return WinUSB设备句柄
|
||
*/
|
||
WindowsDeviceHandle* openWinUsbDevice(const std::string& devicePath);
|
||
|
||
/**
|
||
* @brief 获取WinUSB设备描述符
|
||
* @param winUsbHandle WinUSB接口句柄
|
||
* @param descriptor 设备描述符
|
||
* @return 操作成功返回true,否则返回false
|
||
*/
|
||
bool getWinUsbDescriptor(WINUSB_INTERFACE_HANDLE winUsbHandle, USB_DEVICE_DESCRIPTOR& descriptor);
|
||
|
||
/**
|
||
* @brief 获取WinUSB管道信息
|
||
* @param winUsbHandle WinUSB接口句柄
|
||
* @param pipeId 管道ID
|
||
* @param pipeInfo 管道信息
|
||
* @return 操作成功返回true,否则返回false
|
||
*/
|
||
bool getWinUsbPipeInfo(WINUSB_INTERFACE_HANDLE winUsbHandle, UCHAR pipeId, WINUSB_PIPE_INFORMATION& pipeInfo);
|
||
};
|
||
|
||
} // namespace platform
|
||
} // namespace usb2can
|
||
|
||
#endif // USB2CAN_WINDOWS_PLATFORM_H
|