• muyue007
    了解作者
  • C/C++
    开发工具
  • 8KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 10
    下载次数
  • 2019-07-26 11:43
    上传日期
104规约应用层软件,在单片机上完美运行
104.rar
  • 104.c
    52.2KB
内容介绍
#include "sys.h" #include "dbase.h" #define MAX_MASTER_NUM 10 /* Maximal allowed master stations. */ #define IEC104_TSK_PRI 80 /* Task prorioty. */ #define SZ_IEC_104_STK 32000 /* IEC104 protocol task statk. */ #define SZ_TCP_SVR_STK 4096 /* TCP server task statk. */ #define SZ_104_FRM_LEN 255 #define YC_OBJ_LEN 6 #define YX_OBJ_LEN 4 #define MC_OBJ_LEN 8 #define SOE_OBJ_LEN 7 /* TODO: these should be in parameters. */ #define DB_Yc_MaxNmb 256 #define DB_Yx_MaxNmb 512 #define DB_yxNmb 64 #define DB_ycNmb 64 #define DB_ymNmb 32 #define DB_ykNmb 64 /* To deal YC data for this protocol. */ typedef struct { uint8 ucStatus; /* Not used now. */ uint8 ucRptFlag; /* Reported flag. */ int16 nRptValue; /* Last time reported value. */ } AI_BUF; /* To deal YX data for this protocol. */ typedef struct { uint8 ucRptFlag; /* Reported flag. */ uint8 ucRptClose; /* Last time reported value. */ } DI_BUF; typedef struct { uint8 ucHiAsduAddr; uint8 ucLoAsduAddr; uint8 ucUseGPS; /* Flag of using GPS time. */ #define MY_CLK 0 #define USE_GPS 1 uint8 ucVerFlag; #define YX_DP_TRANS 0x01 /* Transmit all YX as DP signal. */ #define YX_ONLY_SOE 0x02 /* Only transmit SOE signal of YX. */ #define USE_SEQ_ADDR 0x04 /* Allow Seq. address mode. */ #define CYC_TX_MC 0x08 /* Cycle transmit MC signal. */ #define MC_RESP_IC 0x10 /* MC signal response to IC. */ #define ME_TB_TRANS 0x20 /* Transmit YC as M_ME_TB_1(ASDU 11). */ SY_USER_CLOCK clkMy; /* My clock for the remote station. */ SY_DATE_TIME dttmDoOp; int16 nSock; /* TCP socket. */ uint8 aucMasterIp[4]; /* IP address of master station. */ uint8 aucMasterIpb[4]; /* IP address of master station. *///2003 uint8 ucComFg; #define SOCK_OK 0x01 #define EN_TX_I 0x02 #define FIND_YX_CHG 0x04 uint8 ucDisCtrlFg; #define DIS_DO 0x01 #define DIS_AO 0x02 uint16 unDoTout; uint16 unDoIdx; uint8 ucDoOp; uint8 ykstat; //2003 uint16 unSoeIdx; AI_BUF aaibuf[DB_Yc_MaxNmb]; DI_BUF adibuf[DB_Yx_MaxNmb]; uint16 unAiDeadZone; uint16 unTxCyc; uint16 unSecCnt; uint32 ulChkTime; uint16 unTxSN, unRxSN; uint16 unAckRxDelay, unTxWaitAck; uint16 unTxAcked, unAckRx; uint8 ucTestCnt; uint8 ucHostId; /* Host ID, 1-10 use config 0x300-0x780. */ NU_SEMAPHORE semSyn; } PRTC_DATA_104; /* Parameters for the protocol working. */ /********************************************************************************/ /* TODO: change these parameters in diffrent projects. */ /********************************************************************************/ #define REMOTE_IP 0x0a010102L /* IP address of remote machine. */ #define REMOTE_IPb 0x0a010202L /* IP address of remote machine. */// 2003 /* Select from these bits: * (YX_DP_TRANS | YX_ONLY_SOE | USE_SEQ_ADDR | CYC_TX_MC | MC_RESP_IC | ME_TB_TRANS) */ #define VER_FLAG_104 (YX_ONLY_SOE | USE_SEQ_ADDR | ME_TB_TRANS | CYC_TX_MC) //2003 #define USE_GPS_104 USE_GPS /* or MY_CLK2003. */ #define DIS_CTRL_104 (DIS_AO) /* (DIS_DO | DIS_AO) */ #define OBJ_ADDR_3RD 0x00 /* 3rd byte of structure object address. */ #define YX_BGN_ADDR 0x0001 #define YC_BGN_ADDR 0x0701 #define MC_BGN_ADDR 0x0C01 #define YK_BGN_ADDR 0x0B01 #define DO_TIMEOUT 10 /* Max wait DO operation time(sec). */ #define DEAD_ZONE_104 128 /* Deadzone of YC data. */ #define TX_CYC_104 30 /* Cycle Tx time(seconds). */ #define ASDU_ADDR_104 1 /* ASDU address. */ #define ACK_DELAY 10 /* t2 Max ack RX message delay sec. */ #define TX_WAIT_ACK 15 /* t1 Max TX wait ack sec. */ #define TEST_COUNT 20 // T3 /********************************************************************************/ /* End of project parameters. */ /********************************************************************************/ static void Iec104_Task(UNSIGNED ulConfig, VOID *pvDMem); static PS_STATUS N104_Com_Open(PRTC_DATA_104 *pdat104); static void N104_Com_Close(PRTC_DATA_104 *pdat104); static void N104_Send(PRTC_DATA_104 *pdat104, uint8 *pucBuf, uint16 unLen); static PS_STATUS N104_Recv(PRTC_DATA_104 *pdat104, uint8 *pucBuf, uint16 *punLen); /* What to do when DI change. */ static void N104_DI_Chg(uint16 unIndex, DB_DI_REC *pdiOld, DB_DI_REC *pdiNew, void *pvParm); static void N104_Edit_DI(uint8 *pucMsg, uint16 unIndex, PRTC_DATA_104 *pdat104); static void N104_Edit_AI(uint8 *pucMsg, uint16 unIndex, PRTC_DATA_104 *pdat104); static void N104_Edit_PI(uint8 *pucMsg, uint16 unIndex); static void Iec104_Deal_Cmd(PRTC_DATA_104 *pdat104, uint8 *pucSndBuf, uint8 *pucMsg, uint16 unMsgLen); static void N104_Trans_All_Yx(PRTC_DATA_104 *pdat104, uint8 *pucSndBuf, uint8 ucCot); static void N104_Trans_All_Yc(PRTC_DATA_104 *pdat104, uint8 *pucSndBuf, uint8 ucCot); static void N104_Trans_All_Mc(PRTC_DATA_104 *pdat104, uint8 *pucSndBuf, uint8 ucCot); /* Search new SOE and send them. */ static void N104_Trans_New_Soe(PRTC_DATA_104 *pdat104, uint8 *pucSndBuf); /* Search changed AI and send them. */ static void N104_Trans_Chg_Yc(PRTC_DATA_104 *pdat104, uint8 *pucSndBuf); /* Search changed DI and send them. */ static void N104_Trans_Chg_Yx(PRTC_DATA_104 *pdat104, uint8 *pucSndBuf); /* Initilize the IEC870-5-104 protocol module. * Parameters: * ulConfig, first config address in the parameter. * Return value: * PS_SUCCESS, initialize the protocol module. * PS_BUF_ERR, not enough memory. * PS_SYS_ERR, other unexpected error. */ PS_STATUS Iec104_Init(uint32 ulConfig) { NU_TASK *ptskIec104; int8 aucTaskName[8]="104 RTU"; uint16 unPortNum; STATUS stsRslt; if (NU_Allocate_Memory(&System_Memory, &ptskIec104, sizeof(NU_TASK)+SZ_IEC_104_STK, NU_NO_SUSPEND)!=NU_SUCCESS) return PS_BUF_ERR; stsRslt=SY_Read_Config(ulConfig+2, &unPortNum, 2); assert(stsRslt==PS_SUCCESS); aucTaskName[0]='1'; aucTaskName[1]='0'; aucTaskName[2]='4'; aucTaskName[3]='-'; sprintf(&aucTaskName[4], "%04X", unPortNum); #ifndef NU_NO_ERROR_CHECKING memset(ptskIec104, 0, sizeof(NU_TASK)); #endif if (NU_Create_Task(ptskIec104, aucTaskName, Iec104_Task, ulConfig, ptskIec104, ptskIec104+1, SZ_IEC_104_STK, IEC104_TSK_PRI, 0, NU_NO_PREEMPT, NU_START)!=NU_SUCCESS) { NU_Deallocate_Memory(ptskIec104); return PS_SYS_ERR; }
评论
    相关推荐
    • 南瑞的IEC104规约实现的源码.rar
      IEC104名字解析,104从站协议解析
    • 103规约源代码.rar
      很好用的IEC103通信程序VC++语言编写
    • 阿里云javasdk源码-bs-service:bs-服务
      sdk源码 bs-service 前台页面请跳转至 项目仓库查看 后台页面请跳转至 项目仓库查看 项目架构及功能模块图 后端所用技术 Spring Boot Spring Cloud MyBatis MySQL Redis Elasticsearch RabbitMQ Druid Undertow ...
    • PMA通信协议分析及仿真软件V6.1正式版.rar
      规约连接前的操作规约的选择 为了适应当前电力系统的各种规约,PMA2.0首先推出了下拉式菜单选项(文件->协议配置)来选择你所需要的规约。当你选择了规约后,会有一个对话框,需要填写的内容根据各种规约的不同而...
    • 积分管理系统java源码-hfs:高频
      驼峰格式分割单词:类名(以及类别、协议名)应首字母大写;方法;变量名应该以小写字母开头;常量大写;包小写。 [三、代码格式] code style formatter. [四、OOP规约] 当一个类有多个构造方法,或者多个同名方法,这些...
    • dlt698.45规约源代码
      电力行业698通信协议,其中698.45协议面向对象的互操作性数据交换协议,本部分规定了电能信息采集与管理系统主站(以下简称“主站”)、采集终端或电能表(以下简称“终端”)之间,采用的面向对象具有互操作性的...
    • ICE104规约Java解析源码
      ICE104Java解析源码,自己使用的,解析从站发送的遥信、遥测数据进行解析,自己可以在我的基础上写自己的处理代码。
    • ajax基础教程及源码
      美国Ryan Asleson,Nathaniel T.Schutta合著的Foundations of Ajax(Ajax基础教程)
    • java版商城源码下载-xboot:启动
      java版商城源码下载 X-Boot 作者目前大四 能力经验有限 如有错误欢迎指正 期待您的捐赠支持! 作者亲自制作 可接单做视频... 视频已上传至 在线Demo 前台为基于Vue+iView的独立项目请跳转至 项目仓库查看 项目简介 ...
    • android从bootloader到launcher启动流程整理
      讲述android 开机流程 从boot rom---bootloader---init--zygote---systemserver---ams 并附上自己整理的每个流程的流程图 ,清晰熟悉android 启动流程