Files
hcanview/include/can/CanController.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.5 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 CanController.h
* @brief CAN控制器接口定义
*/
#ifndef USB2CAN_CAN_CONTROLLER_H
#define USB2CAN_CAN_CONTROLLER_H
#include "CanMessage.h"
#include "../usb/UsbDevice.h"
#include <vector>
namespace usb2can {
namespace can {
/**
* @brief CAN控制器接口类
*/
class CanController {
public:
virtual ~CanController() = default;
/**
* @brief 初始化CAN控制器
* @param usbDevice USB设备
* @param config CAN配置
* @return 初始化成功返回true否则返回false
*/
virtual bool initialize(usb::UsbDevice* usbDevice, const CanConfig& config) = 0;
/**
* @brief 关闭CAN控制器
*/
virtual void shutdown() = 0;
/**
* @brief 检查CAN控制器是否已初始化
* @return 已初始化返回true否则返回false
*/
virtual bool isInitialized() const = 0;
/**
* @brief 发送CAN消息
* @param message CAN消息
* @param timeout 超时时间(毫秒)
* @return 发送成功返回true否则返回false
*/
virtual bool sendMessage(const CanMessage& message, int timeout = 1000) = 0;
/**
* @brief 接收CAN消息
* @param[out] message CAN消息
* @param timeout 超时时间(毫秒)
* @return 接收成功返回true否则返回false
*/
virtual bool receiveMessage(CanMessage& message, int timeout = 1000) = 0;
/**
* @brief 批量发送CAN消息
* @param messages CAN消息列表
* @param count 消息数量
* @param timeout 超时时间(毫秒)
* @return 实际发送的消息数量,失败返回-1
*/
virtual int sendMessages(const CanMessage* messages, int count, int timeout = 1000) = 0;
/**
* @brief 批量接收CAN消息
* @param[out] messages CAN消息列表
* @param count 最大接收消息数量
* @param timeout 超时时间(毫秒)
* @return 实际接收的消息数量,失败返回-1
*/
virtual int receiveMessages(CanMessage* messages, int count, int timeout = 1000) = 0;
/**
* @brief 获取接收缓冲区中的消息数量
* @return 接收缓冲区中的消息数量,失败返回-1
*/
virtual int getReceiveQueueCount() = 0;
/**
* @brief 设置CAN过滤器
* @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 复位CAN控制器
* @return 复位成功返回true否则返回false
*/
virtual bool reset() = 0;
/**
* @brief 获取CAN控制器状态
* @param[out] status CAN状态
* @return 获取成功返回true否则返回false
*/
virtual bool getStatus(CanStatus& status) = 0;
/**
* @brief 获取CAN控制器配置
* @param[out] config CAN配置
* @return 获取成功返回true否则返回false
*/
virtual bool getConfig(CanConfig& config) = 0;
/**
* @brief 设置CAN控制器配置
* @param config CAN配置
* @return 设置成功返回true否则返回false
*/
virtual bool setConfig(const CanConfig& config) = 0;
/**
* @brief 创建CAN控制器实例
* @return CAN控制器实例
*/
static CanController* createCanController();
};
} // namespace can
} // namespace usb2can
#endif // USB2CAN_CAN_CONTROLLER_H