// lyscan.h : main header file for the HID_DLL_1_1 DLL
//

#ifndef LYSCAN_H_
#define LYSCAN_H_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
	#error include 'stdafx.h' before including this file for PCH
#endif

#include <wtypes.h>


//接口卡类型定义
#define LCAN_USBCAN1		        3
#define LCAN_USBCAN2		        4
#define LCAN_USBCANFDMini           43
#define LCAN_USBCANFD1              42
#define LCAN_USBCANFD2              41
#define LCAN_UTB2601			    61
#define LCAN_UTB2602			    62

#define CAN_DATA_DLC_MAX            8
#define CANFD_DATA_DLC_MAX          64

//函数调用返回状态值
#define	LCAN_STATUS_OK			    1
#define LCAN_STATUS_ERR			    0

//FD FLAG
#define LCAN_CANFD_BRS              0x08
#define LCAN_CANFD_ESI              0x10
//FD FLITER
#define LCAN_FLITER_CMD_CLR         0x00
#define LCAN_FLITER_CMD_ADD         0x01
#define LCAN_FLITER_CMD_ENABLE      0x02
#define LCAN_FLITER_CMD_DISABLE     0x03
#define LCAN_FLITER_CMD_INFO_GET    0x04
#define LCAN_FLITER_CMD_SET_GET     0x05


/////////////////////////////////////////////////////////////////////////////
//1.USBCAN系列设备信息的数据类型。
typedef  struct  _LCAN_BOARD_INFO{
	USHORT	hw_Version;//硬件版本
	USHORT	fw_Version;//固件版本
	USHORT	dr_Version;//驱动程序版本
	USHORT	in_Version;//接口库版本
	USHORT	irq_Num;   //板卡所使用的中断号
	BYTE	can_Num;   //CAN通道数
	CHAR	serialNumber[20];//序列号
	CHAR	str_hw_Type[40]; //硬件型号
	USHORT	reserved[4];
} LCAN_BOARD_INFO,*PLCAN_BOARD_INFO;

//CAN信息帧的数据类型。
typedef  struct  _LCAN_CAN_OBJ{
	UINT	id;
	UINT	timeStamp;
	UCHAR	timeFlag;
	UCHAR	sendType;
	UCHAR	remoteFlag;//是否是远程帧
	UCHAR	externFlag;//是否是扩展帧
	UCHAR	dataLen;
    UCHAR	reserved[3];
	UCHAR	data[CAN_DATA_DLC_MAX];
}LCAN_CAN_OBJ,*PLCAN_CAN_OBJ;

//CANFD信息帧的数据类型。
typedef  struct  _LCAN_CANFD_OBJ{
    UINT	id;
    UINT	timeStamp;
    UCHAR	flag;//CANFD_BRS/ESI
    UCHAR	sendType;
    UCHAR	remoteFlag;//是否是远程帧
    UCHAR	externFlag;//是否是扩展帧
    UCHAR	dataLen;
    UCHAR	reserved[3];
    UCHAR	data[CANFD_DATA_DLC_MAX];
}LCAN_CANFD_OBJ,*PLCAN_CANFD_OBJ;


//定义CAN的配置信息 用于CAN设备
typedef struct _LCAN_INIT_CONFIG{
	UINT	accCode;
	UINT	accMask;
	UINT	reserved;
	UCHAR	filter;
	UCHAR	timing0;	
	UCHAR	timing1;
	UCHAR	mode;
}LCAN_INIT_CONFIG,*PLCAN_INIT_CONFIG;

//定义CANFD的配置信息 用于FD设备
typedef struct _LCAN_INITFD_CONFIG{
    UINT	abitBaudHz;
    UINT	dbitBaudHz;
    UINT	abit_timing;
    UINT	dbit_timing;
    UCHAR	mode;	
    UCHAR	fdEn;
    UCHAR	isoEn;
    UCHAR	rev2;
}LCAN_INITFD_CONFIG,*PLCAN_INITFD_CONFIG;

//定义过滤器信息
typedef struct _LCAN_FLITER_INFO{
    USHORT	cnt;
    UCHAR	enable;
    UCHAR   rev;
}LCAN_FLITER_INFO,*PLCAN_FLITER_INFO;

//定义过滤器配置信息
typedef struct _LCAN_FLITER_CONFIG{
    UCHAR	cmd;
    UCHAR	fliterMode;
    UCHAR	idType;
    UCHAR	rev1;
    UINT	fliterStardId;	
    UINT	fliterEndId;
	UINT    fliterIndex;
}LCAN_FLITER_CONFIG,*PLCAN_FLITER_CONFIG;

//RECORD配置信息
typedef struct _LCAN_RECORD_CONFIG{
    UCHAR       ch;
    UCHAR       fdEn;
    UCHAR		iso;
    UCHAR		listen;
    UCHAR		aClk;
    UCHAR		dClk;
    UCHAR       rev1[2];
    UINT		abit_timing;
    UINT		dbit_timing;
    UCHAR       baudCustomEn;
    UCHAR		fileFormat;
    UCHAR       fileTime;
    UCHAR       chEn;
    UCHAR       diskStrategy;
    UCHAR       rev2[3];
}LCAN_RECORD_CONFIG,*PLCAN_RECORD_CONFIG;

#define FUNC_CALL __stdcall
#ifdef __cplusplus
extern "C"
{
#endif

UINT FUNC_CALL LCAN_OpenDevice(UINT devType, UINT devIndex);
UINT FUNC_CALL LCAN_CloseDevice(UINT devType, UINT devIndex);
UINT FUNC_CALL LCAN_GetReceiveNum(UINT devType,UINT devIndex,UINT canIndex,UCHAR type);
UINT FUNC_CALL LCAN_Receive(UINT devType,UINT devIndex,UINT canIndex,PLCAN_CAN_OBJ pReceive,UINT len,INT waitTime);
UINT FUNC_CALL LCAN_ReceiveFD(UINT devType,UINT devIndex,UINT canIndex,PLCAN_CANFD_OBJ pReceive,UINT len,INT waitTime);
UINT FUNC_CALL LCAN_Transmit(UINT devType,UINT devIndex,UINT canIndex,PLCAN_CAN_OBJ pSend,UINT len);
UINT FUNC_CALL LCAN_TransmitFD(UINT devType,UINT devIndex,UINT canIndex,PLCAN_CANFD_OBJ pSend,UINT len);
UINT FUNC_CALL LCAN_InitCAN(UINT devType, UINT devIndex, UINT canIndex, PLCAN_INIT_CONFIG pInitConfig);
UINT FUNC_CALL LCAN_InitCANFD(UINT devType, UINT devIndex, UINT canIndex, PLCAN_INITFD_CONFIG pInitConfig);
UINT FUNC_CALL LCAN_SetFliter(UINT devType, UINT devIndex, UINT canIndex, PLCAN_FLITER_CONFIG pFliterConfig);
UINT FUNC_CALL LCAN_BoardInfoGet(UINT devType, UINT devIndex,PLCAN_BOARD_INFO pBoardInfo);
UINT FUNC_CALL LCAN_ClearBuffer(UINT devType,UINT devIndex,UINT canIndex);
UINT FUNC_CALL LCAN_DataDirectTransfer(UINT devType, UINT devIndex, UCHAR *data, UINT len);
UINT FUNC_CALL LCAN_RecordSettingSet(UINT devType, UINT devIndex, UINT canIndex, PLCAN_RECORD_CONFIG pInitConfig);
UINT FUNC_CALL LCAN_RecordSettingGet(UINT devType, UINT devIndex, UINT canIndex, PLCAN_RECORD_CONFIG pInitConfig);
UINT FUNC_CALL LCAN_RecordFliterInfoGet(UINT devType, UINT devIndex, UINT canIndex,PLCAN_FLITER_INFO pFliterInfo);
UINT FUNC_CALL LCAN_RecordFliterClr(UINT devType, UINT devIndex, UINT canIndex);
UINT FUNC_CALL LCAN_RecordFliterAdd(UINT devType, UINT devIndex, UINT canIndex, PLCAN_FLITER_CONFIG pFliterConfig);
UINT FUNC_CALL LCAN_RecordFliterEnable(UINT devType, UINT devIndex, UINT canIndex);
UINT FUNC_CALL LCAN_RecordFliterDisable(UINT devType, UINT devIndex, UINT canIndex);
UINT FUNC_CALL LCAN_RecordFliterSettingGet(UINT devType, UINT devIndex, UINT canIndex, 
                                           USHORT fliterIndex,PLCAN_FLITER_CONFIG pFliterConfig);
UINT FUNC_CALL LCAN_RecordCmdExecute(UINT devType, UINT devIndex, UINT canIndex, UINT cmd, 
                                     PLCAN_FLITER_INFO pFliterInfo, PLCAN_FLITER_CONFIG pFliterConfig);

#ifdef __cplusplus
}
#endif


/////////////////////////////////////////////////////////////////////////////
/*------------------------------------------------其他补充函数及数据结构描述------------------------------------------------*/

#endif
