/***************************************************************** *(C) Copyright H.S.J. * * MODULE NAME : iec103_service_cln.h * PRODUCT(S) : IEC60870 * * MODULE DESCRIPTION : * 实现IEC103客户器端链路层规约 * * GLOBAL FUNCTIONS DEFINED IN THIS MODULE : * * * MODIFICATION LOG : * Date Who Rev Comments * -------- --- ------ ---------------------------------- * 2011-12-25 hsj 1.0 创建初版(适用:_WIN32,linux,VXWORKS 三种系统) * *****************************************************************/ #ifndef IEC103_SERVICE_CLN_123_INCLUDED #define IEC103_SERVICE_CLN_123_INCLUDED #ifdef __cplusplus extern "C" { #endif /************************************************************************/ //如果发布,定义这个宏 //#define IEC60870_RELEASE #ifdef IEC60870_RELEASE typedef enum { IEC103_I_CMD_TYPE_HIGH=0, IEC103_I_CMD_TYPE_LOW, } IEC103_I_CMD_TYPE; #else #include "glbtypes.h" #include "iec103_link_cln.h" #endif //注意: 本头文件,必须与发布的头文件同步更新 typedef int (*IEC103_CLN_RECV_ASDU)(unsigned char *recvAsdu, int linkIndex); typedef int (*IEC103_CLN_RECV_CONN)(int linkIndex); typedef int (*IEC103_CLN_RECV_DISCON)(int linkIndex); //如果要启动网络103,配置下面参数 typedef struct { struct { IEC103_CLN_RECV_ASDU fun_recv_asdu; //函数指针,收到I帧的时候调用本函数 IEC103_CLN_RECV_CONN fun_recv_conn; //收到客户端连接 IEC103_CLN_RECV_DISCON fun_recv_discon; //与客户端连接断开 char connect_ip[32]; int connect_port; unsigned char linkAddr; //链路地址 unsigned char commAddr; //asdu地址,一般与上面相同 int monitorChl; //监视数据的通道号 int t1Normal; //2级数据间隔,300 int t1L1; //2级数据间隔,200 int t1Cmd; //2级数据间隔,100 } link_tcp_para; //下面几个参数,用户不要赋值或者更改. 用户可以初始为NULL #ifdef IEC60870_RELEASE struct { void *socket_connect; void *link103_cln; } cln_tcp_property; #else struct { SOCKET_LINK_ATTRIB *socket_connect; IEC103_LINK_CLN *link103_cln; } cln_tcp_property; #endif } IEC103_SERVICE_CLN_TCP; //如果要启动串口103,配置下面参数 typedef struct { struct { IEC103_CLN_RECV_ASDU fun_recv_asdu; //函数指针,收到I帧的时候调用本函数 IEC103_CLN_RECV_CONN fun_recv_conn; //收到客户端连接 IEC103_CLN_RECV_DISCON fun_recv_discon; //与客户端连接断开 int com_index; //串口序号 int com_baud; //波特率 int com_parity; //校验方式 N,O,E int max_conn_num; //客户端数量 unsigned char *linkAddr; //链路地址 int *monitorChl; //监视数据的通道号 int t1Normal; //2级数据间隔,300 int t1L1; //2级数据间隔,200 int t1Cmd; //2级数据间隔,100 } link_serial_para; //下面几个参数,用户不要赋值或者更改. 用户可以初始为NULL #ifdef IEC60870_RELEASE struct { void *serial_link; void *link103_cln; int link103_index; } cln_serial_property; #else struct { SERIAL_ATTRIB *serial_link; //只有一个 IEC103_LINK_CLN *link103_cln; //多个 int link103_index; //目前处理的连接序号 } cln_serial_property; #endif } IEC103_SERVICE_CLN_SERIAL; //如果要启动CAN 103,配置下面参数 typedef struct { struct { IEC103_CLN_RECV_ASDU fun_recv_asdu; //函数指针,收到I帧的时候调用本函数 IEC103_CLN_RECV_CONN fun_recv_conn; //收到客户端连接 IEC103_CLN_RECV_DISCON fun_recv_discon; //与客户端连接断开 int can_index; //串口序号 int can_baud; //波特率 k int localCanID; //本机的CAN编号ID int max_conn_num; //一个CAN客户端,对应多个服务端,根据CANID区分 unsigned char *linkAddr; //链路地址, 多个. 用户根据个数分配内存 int *canID; // CAN还应该有CANID, 多个 int *monitorChl; //监视数据的通道号 int t1Normal; //2级数据间隔,300 int t1L1; //2级数据间隔,200 int t1Cmd; //2级数据间隔,100 } link_can_para; //下面几个参数,用户不要赋值或者更改. 用户可以初始为NULL #ifdef IEC60870_RELEASE struct { void *can_listen; //只有一个 void *can_link; //多个 void *link103_cln; //多个 int link103_index; } cln_can_property; #else struct { CAN_ATTRIB *can_listen; //只有一个 CAN_LINK_ATTRIB *can_link; //多个 IEC103_LINK_CLN *link103_cln; //多个 int link103_index; //目前处理的连接序号 } cln_can_property; #endif } IEC103_SERVICE_CLN_CAN; #ifndef IEC60870_RELEASE int iec103_service_cln_asdu_recv( IEC103_LINK_CLN *iec103_link_cln, unsigned char *recvAsdu ); #endif int iec103_service_cln_init_tcp( IEC103_SERVICE_CLN_TCP *iec103_cln_tcp ); int iec103_service_cln_release_tcp( IEC103_SERVICE_CLN_TCP *iec103_cln_tcp ); int iec103_service_cln_init_serial( IEC103_SERVICE_CLN_SERIAL *iec103_cln_serial ); int iec103_service_cln_release_serial( IEC103_SERVICE_CLN_SERIAL *iec103_cln_serial ); int iec103_service_cln_init_can( IEC103_SERVICE_CLN_CAN *iec103_cln_can ); int iec103_service_cln_release_can( IEC103_SERVICE_CLN_CAN *iec103_cln_can ); int iec103_service_cln_check_status_tcp( IEC103_SERVICE_CLN_TCP *iec103_cln_tcp ); int iec103_service_cln_check_status_serial( IEC103_SERVICE_CLN_SERIAL *iec103_cln_serial ); int iec103_service_cln_check_status_can( IEC103_SERVICE_CLN_CAN *iec103_cln_can ); /*** 向服务器下的指定连接发送I帧,发送的时候会自动填充链路层信息(ti以前)和校验码、结束符 ***/ /*** 如果linkIndex=-1,先所有连接发送 ***/ /*** asduLen是包含校验符和结束符在内的报文总长度 ***/ int iec103_service_cln_asdu_send_tcp(IEC103_SERVICE_CLN_TCP *iec103_cln_tcp, int linkIndex, unsigned char *asdu, int asduLen, IEC103_I_CMD_TYPE type ); int iec103_service_cln_asdu_send_serial(IEC103_SERVICE_CLN_SERIAL *iec103_cln_serial, int linkIndex, unsigned char *asdu, int asduLen, IEC103_I_CMD_TYPE type ); int iec103_service_cln_asdu_send_can(IEC103_SERVICE_CLN_CAN *iec103_cln_can, int linkIndex, unsigned char *asdu, int asduLen, IEC103_I_CMD_TYPE type ); /************************************************************************/ #ifdef __cplusplus } #endif #endif