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
107 lines
2.4 KiB
C++
107 lines
2.4 KiB
C++
/**
|
||
* @file DeviceManager.h
|
||
* @brief 设备管理器类定义
|
||
*/
|
||
|
||
#ifndef USB2CAN_DEVICE_MANAGER_H
|
||
#define USB2CAN_DEVICE_MANAGER_H
|
||
|
||
#include "Usb2CanDevice.h"
|
||
#include "../platform/Platform.h"
|
||
|
||
#include <vector>
|
||
#include <memory>
|
||
|
||
namespace usb2can {
|
||
namespace device {
|
||
|
||
/**
|
||
* @brief 设备管理器类
|
||
*/
|
||
class DeviceManager {
|
||
public:
|
||
/**
|
||
* @brief 构造函数
|
||
* @param platform 平台实例
|
||
*/
|
||
explicit DeviceManager(platform::Platform* platform);
|
||
|
||
/**
|
||
* @brief 析构函数
|
||
*/
|
||
~DeviceManager();
|
||
|
||
/**
|
||
* @brief 扫描USB2CAN设备
|
||
* @return 设备数量
|
||
*/
|
||
int scanDevices();
|
||
|
||
/**
|
||
* @brief 获取设备数量
|
||
* @return 设备数量
|
||
*/
|
||
int getDeviceCount() const;
|
||
|
||
/**
|
||
* @brief 获取设备信息
|
||
* @param deviceIndex 设备索引
|
||
* @param[out] info 设备信息
|
||
* @return 获取成功返回true,否则返回false
|
||
*/
|
||
bool getDeviceInfo(int deviceIndex, Usb2CanDeviceInfo& info);
|
||
|
||
/**
|
||
* @brief 打开设备
|
||
* @param deviceIndex 设备索引
|
||
* @return 设备实例,失败返回nullptr
|
||
*/
|
||
Usb2CanDevice* openDevice(int deviceIndex);
|
||
|
||
/**
|
||
* @brief 关闭设备
|
||
* @param device 设备实例
|
||
*/
|
||
void closeDevice(Usb2CanDevice* device);
|
||
|
||
/**
|
||
* @brief 获取所有设备信息
|
||
* @return 设备信息列表
|
||
*/
|
||
std::vector<Usb2CanDeviceInfo> getAllDevicesInfo() const;
|
||
|
||
/**
|
||
* @brief 注册热插拔回调函数
|
||
* @param callback 回调函数
|
||
* @return 注册成功返回true,否则返回false
|
||
*/
|
||
bool registerHotplugCallback(void (*callback)(void));
|
||
|
||
/**
|
||
* @brief 注销热插拔回调函数
|
||
* @return 注销成功返回true,否则返回false
|
||
*/
|
||
bool unregisterHotplugCallback();
|
||
|
||
private:
|
||
platform::Platform* platform_; ///< 平台实例
|
||
std::vector<Usb2CanDeviceInfo> deviceInfos_; ///< 设备信息列表
|
||
std::vector<std::unique_ptr<Usb2CanDevice>> openedDevices_; ///< 已打开的设备列表
|
||
void (*hotplugCallback_)(void); ///< 热插拔回调函数
|
||
bool hotplugCallbackRegistered_; ///< 热插拔回调是否已注册
|
||
|
||
/**
|
||
* @brief 热插拔事件处理函数
|
||
*/
|
||
static void hotplugEventHandler(void* context);
|
||
|
||
/**
|
||
* @brief 更新设备列表
|
||
*/
|
||
void updateDeviceList();
|
||
};
|
||
|
||
} // namespace device
|
||
} // namespace usb2can
|
||
|
||
#endif // USB2CAN_DEVICE_MANAGER_H
|