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

210 lines
5.8 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.

/*****************************************************************
*(C) Copyright H.S.J.
*
* MODULE NAME : iec104_service_cln.h
* PRODUCT(S) : IEC60870
*
* MODULE DESCRIPTION :
* 实现IEC104客户器端链路层规约
*
* GLOBAL FUNCTIONS DEFINED IN THIS MODULE :
*
*
* MODIFICATION LOG :
* Date Who Rev Comments
* -------- --- ------ ----------------------------------
* 2011-12-25 hsj 1.0 创建初版(适用_WIN32linuxVXWORKS 三种系统)
*
*****************************************************************/
#ifndef IEC104_SERVICE_CLN_123_INCLUDED
#define IEC104_SERVICE_CLN_123_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
/************************************************************************/
//如果发布,定义这个宏
//#define IEC60870_RELEASE
#ifdef IEC60870_RELEASE
typedef enum
{
IEC104_I_CMD_TYPE_HIGH=0,
IEC104_I_CMD_TYPE_LOW,
} IEC104_I_CMD_TYPE;
#else
#include "glbtypes.h"
#include "iec104_link_cln.h"
#endif
//注意: 本头文件,必须与发布的头文件同步更新
typedef int (*IEC104_CLN_RECV_ASDU)(unsigned char *recvAsdu, int linkIndex);
typedef int (*IEC104_CLN_RECV_CONN)(int linkIndex);
typedef int (*IEC104_CLN_RECV_DISCON)(int linkIndex);
//如果要启动网络104配置下面参数
typedef struct
{
struct
{
IEC104_CLN_RECV_ASDU fun_recv_asdu; //函数指针,收到I帧的时候调用本函数
IEC104_CLN_RECV_CONN fun_recv_conn; //收到客户端连接
IEC104_CLN_RECV_DISCON fun_recv_discon; //与客户端连接断开
char connect_ip[32];
int connect_port;
unsigned char commAddr; //公共地址 发送总召唤和对时使用
unsigned char devAddr; //装置地址
int monitorChl; //监视数据的通道号
} link_tcp_para;
//下面几个参数,用户不要赋值或者更改. 用户可以初始为NULL
#ifdef IEC60870_RELEASE
struct
{
void *socket_connect;
void *link104_cln;
} cln_tcp_property;
#else
struct
{
SOCKET_LINK_ATTRIB *socket_connect;
IEC104_LINK_CLN *link104_cln;
} cln_tcp_property;
#endif
} IEC104_SERVICE_CLN_TCP;
//如果要启动串口104配置下面参数(104不能用在串口上,这里仅保留结构体,没有实现)
typedef struct
{
struct
{
IEC104_CLN_RECV_ASDU fun_recv_asdu; //函数指针,收到I帧的时候调用本函数
IEC104_CLN_RECV_CONN fun_recv_conn; //收到客户端连接
IEC104_CLN_RECV_DISCON fun_recv_discon; //与客户端连接断开
int com_index; //串口序号
int com_baud; //波特率
int com_parity; //校验方式 N,O,E
int max_conn_num; //一条总线上,挂接多个
unsigned char *commAddr; //公共地址 发送总召唤和对时使用
unsigned char *devAddr; //装置地址
int *monitorChl; //监视数据的通道号
} link_serial_para;
//下面几个参数,用户不要赋值或者更改. 用户可以初始为NULL
#ifdef IEC60870_RELEASE
struct
{
void *serial_link;
void *link104_cln;
int link104_index;
} cln_serial_property;
#else
struct
{
SERIAL_ATTRIB *serial_link; //只有一个
IEC104_LINK_CLN *link104_cln; //多个
int link104_index; //目前处理的连接序号
} cln_serial_property;
#endif
} IEC104_SERVICE_CLN_SERIAL;
//如果要启动CAN 104配置下面参数(这里仅保留结构体,没有实现)
typedef struct
{
struct
{
IEC104_CLN_RECV_ASDU fun_recv_asdu; //函数指针,收到I帧的时候调用本函数
IEC104_CLN_RECV_CONN fun_recv_conn; //收到客户端连接
IEC104_CLN_RECV_DISCON fun_recv_discon; //与客户端连接断开
int can_index; //串口序号
int can_baud; //波特率 k
int max_conn_num; //一个CAN服务器端,对应多个服务端,根据CANID区分
unsigned char *commAddr;
unsigned char *devAddr; //链路地址, 多个. 用户根据个数分配内存
int *canID; // CAN还应该有CANID, 多个
int *monitorChl; //监视数据的通道号
} link_can_para;
//下面几个参数,用户不要赋值或者更改. 用户可以初始为NULL
#ifdef IEC60870_RELEASE
struct
{
void *can_listen; //只有一个
void *can_link; //多个
void *link104_cln; //多个
int link104_index;
} cln_can_property;
#else
struct
{
CAN_ATTRIB *can_listen; //只有一个
CAN_LINK_ATTRIB *can_link; //多个
IEC104_LINK_CLN *link104_cln; //多个
int link104_index; //目前处理的连接序号
} cln_can_property;
#endif
} IEC104_SERVICE_CLN_CAN;
#ifndef IEC60870_RELEASE
int iec104_service_cln_asdu_recv( IEC104_LINK_CLN *iec104_link_cln, unsigned char *recvAsdu );
#endif
int iec104_service_cln_init_tcp( IEC104_SERVICE_CLN_TCP *iec104_cln_tcp );
int iec104_service_cln_release_tcp( IEC104_SERVICE_CLN_TCP *iec104_cln_tcp );
// int iec104_service_cln_init_serial( IEC104_SERVICE_CLN_SERIAL *iec104_cln_serial );
// int iec104_service_cln_release_serial( IEC104_SERVICE_CLN_SERIAL *iec104_cln_serial );
// int iec104_service_cln_init_can( IEC104_SERVICE_CLN_CAN *iec104_cln_can );
// int iec104_service_cln_release_can( IEC104_SERVICE_CLN_CAN *iec104_cln_can );
int iec104_service_cln_check_status_tcp( IEC104_SERVICE_CLN_TCP *iec104_cln_tcp );
// int iec104_service_cln_check_status_serial( IEC104_SERVICE_CLN_SERIAL *iec104_cln_serial );
// int iec104_service_cln_check_status_can( IEC104_SERVICE_CLN_CAN *iec104_cln_can );
/*** 向服务器下的指定连接发送I帧发送的时候会自动填充链路层信息(ti以前)和校验码、结束符 ***/
/*** 如果linkIndex=-1先所有连接发送 ***/
/*** asduLen是包含校验符和结束符在内的报文总长度 ***/
int iec104_service_cln_asdu_send_tcp(IEC104_SERVICE_CLN_TCP *iec104_cln_tcp, int linkIndex,
unsigned char *asdu, int asduLen, IEC104_I_CMD_TYPE type );
// int iec104_service_cln_asdu_send_serial(IEC104_SERVICE_CLN_SERIAL *iec104_cln_serial, int linkIndex,
// unsigned char *asdu, int asduLen, IEC104_I_CMD_TYPE type );
// int iec104_service_cln_asdu_send_can(IEC104_SERVICE_CLN_CAN *iec104_cln_can, int linkIndex,
// unsigned char *asdu, int asduLen, IEC104_I_CMD_TYPE type );
/** 主动关闭连接 **/
int iec104_service_cln_close_tcp( IEC104_SERVICE_CLN_TCP *iec104_cln_tcp, int linkIndex );
/************************************************************************/
#ifdef __cplusplus
}
#endif
#endif