Files
hcanview/include/can/CanFdController.h
yemai 81bee50cd9 Initial commit: Complete USB2CAN cross-platform framework
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
2025-09-11 17:56:26 +08:00

131 lines
3.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* @file CanFdController.h
* @brief CANFD控制器接口定义
*/
#ifndef USB2CAN_CAN_FD_CONTROLLER_H
#define USB2CAN_CAN_FD_CONTROLLER_H
#include "CanMessage.h"
#include "../usb/UsbDevice.h"
#include <vector>
namespace usb2can {
namespace can {
/**
* @brief CANFD控制器接口类
*/
class CanFdController {
public:
virtual ~CanFdController() = default;
/**
* @brief 初始化CANFD控制器
* @param usbDevice USB设备
* @param config CANFD配置
* @return 初始化成功返回true否则返回false
*/
virtual bool initialize(usb::UsbDevice* usbDevice, const CanFdConfig& config) = 0;
/**
* @brief 关闭CANFD控制器
*/
virtual void shutdown() = 0;
/**
* @brief 检查CANFD控制器是否已初始化
* @return 已初始化返回true否则返回false
*/
virtual bool isInitialized() const = 0;
/**
* @brief 发送CANFD消息
* @param message CANFD消息
* @param timeout 超时时间(毫秒)
* @return 发送成功返回true否则返回false
*/
virtual bool sendMessage(const CanFdMessage& message, int timeout = 1000) = 0;
/**
* @brief 接收CANFD消息
* @param[out] message CANFD消息
* @param timeout 超时时间(毫秒)
* @return 接收成功返回true否则返回false
*/
virtual bool receiveMessage(CanFdMessage& message, int timeout = 1000) = 0;
/**
* @brief 批量发送CANFD消息
* @param messages CANFD消息列表
* @param count 消息数量
* @param timeout 超时时间(毫秒)
* @return 实际发送的消息数量,失败返回-1
*/
virtual int sendMessages(const CanFdMessage* messages, int count, int timeout = 1000) = 0;
/**
* @brief 批量接收CANFD消息
* @param[out] messages CANFD消息列表
* @param count 最大接收消息数量
* @param timeout 超时时间(毫秒)
* @return 实际接收的消息数量,失败返回-1
*/
virtual int receiveMessages(CanFdMessage* messages, int count, int timeout = 1000) = 0;
/**
* @brief 获取接收缓冲区中的消息数量
* @return 接收缓冲区中的消息数量,失败返回-1
*/
virtual int getReceiveQueueCount() = 0;
/**
* @brief 设置CANFD过滤器
* @param filterId 过滤器ID
* @param type 过滤器类型
* @param id 过滤ID
* @param mask 过滤掩码
* @param enable 是否启用过滤器
* @return 设置成功返回true否则返回false
*/
virtual bool setFilter(uint8_t filterId, uint8_t type, uint32_t id, uint32_t mask, bool enable) = 0;
/**
* @brief 复位CANFD控制器
* @return 复位成功返回true否则返回false
*/
virtual bool reset() = 0;
/**
* @brief 获取CANFD控制器状态
* @param[out] status CAN状态
* @return 获取成功返回true否则返回false
*/
virtual bool getStatus(CanStatus& status) = 0;
/**
* @brief 获取CANFD控制器配置
* @param[out] config CANFD配置
* @return 获取成功返回true否则返回false
*/
virtual bool getConfig(CanFdConfig& config) = 0;
/**
* @brief 设置CANFD控制器配置
* @param config CANFD配置
* @return 设置成功返回true否则返回false
*/
virtual bool setConfig(const CanFdConfig& config) = 0;
/**
* @brief 创建CANFD控制器实例
* @return CANFD控制器实例
*/
static CanFdController* createCanFdController();
};
} // namespace can
} // namespace usb2can
#endif // USB2CAN_CAN_FD_CONTROLLER_H