commCPU_SUPV/code/general/inc/general_can.h
2025-04-30 16:24:29 +08:00

90 lines
2.0 KiB
C
Raw Permalink 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.

#ifndef GENERAL_CAN_123_INCLUDED
#define GENERAL_CAN_123_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
/************************************************************************/
#include "glbtypes.h"
//接收缓冲区长度
#define CAN_RECVBUF_LEN (256+8)
//每个打开的CAN最多支持12个连接
#define CAN_ATTRIB_LINK_MAX 16
/****串口连接属性结构体****/
typedef struct
{
//通知外部,打开成功
ST_INT flagOpenSuccess;
ST_INT canHandle; /***串口**/
ST_UINT localCanID; /* 本地CAN id */
ST_UINT sendCanID;
ST_UINT recvCanID;
ST_INT status; /**当前连接属性 0没有打开1打开成功2打开失败**/
//所有连接个数,和所有的连接
ST_VOID *canLinkAttrib[CAN_ATTRIB_LINK_MAX];
//出现错误,重新打开的间隔
ST_DOUBLE record_time_reopen;
ST_DOUBLE space_reopen;
//下面的变量用于设置串口属性
int canNo;
int baudrate;
} CAN_ATTRIB;
typedef struct
{
ST_UINT canID; //目的ID即对方的ID
ST_UINT recvCount; /**接收的帧数,累计*/
/***由于缓冲比较大,是否多连接共用缓冲,收到数据立刻处理?? ***/
ST_INT recvDataLen; /***接收到的数据长度**/
ST_UCHAR recvDataBuf[CAN_RECVBUF_LEN]; /**接收到的数据缓冲**/
CAN_ATTRIB *can_attrib;
} CAN_LINK_ATTRIB;
ST_RET can_attrib_init( CAN_ATTRIB *can_attrib );
ST_RET can_attrib_release( CAN_ATTRIB *can_attrib );
ST_RET can_attrib_set( CAN_ATTRIB *can_attrib, int canNo,int baudrate, unsigned int localCanID );
ST_RET can_link_attrib_set( CAN_LINK_ATTRIB *can_link_attrib, int canID, CAN_ATTRIB *can_attrib );
/**** 循环调用,读取数据 ****/
ST_RET can_attrib_check( CAN_ATTRIB *can_attrib );
ST_RET can_send(CAN_ATTRIB *can_attrib, ST_UCHAR *sendBuf, ST_INT sendLen, ST_INT sendCanId );
ST_RET can_link_send(CAN_LINK_ATTRIB *can_link, ST_UCHAR *sendBuf, ST_INT sendLen );
ST_RET can_bus_reset( CAN_LINK_ATTRIB *can_link_attrib );
ST_RET can_bus_check_error( CAN_LINK_ATTRIB *can_link_attrib );
ST_RET can_bus_reset_attrib( CAN_ATTRIB *can_attrib );
/************************************************************************/
#ifdef __cplusplus
}
#endif
#endif