Commu_IEC103_Interface.c
上传用户:yuadon
上传日期:2022-05-24
资源大小:7k
文件大小:27k
- ///////////////////////////////////////////////////////////////
- // 2009-11-26 19:00
- // 与张洁的接口
- //
- ///////////////////////////////////////////////////////////////
- #include "Commu_IEC103_Interface.h"
- TCONTROL_INFO yk_ctrlinfo;
- uint16 Global_YC_Num;
- /*
- IRQ_AD_Simult
- //收发数据
- comm_RecSendProcess();
- //报文解析,组包
- comm_Proc_InMainCycle();
- //收发数据
- comm_RecSendProcess();
- Comm[i].RecSendProcess(&Comm[i].MsgBuff.BuffBase);
- COMM_PORT_NET1: 485: NET485A_Process
- COMM_PORT_NET2: 485: NET485B_Process
- COMM_PORT_NET1: CAN: NETCANA_Process
- COMM_PORT_NET2: CAN: NETCANB_Process
- NET485A_Process:
- NetAPort_OnRecieve(Rxbuf, rxffst);
- NetAPort_OnSend();
- hd_NetA1Error_Proc();
- ---------------------------------
- comm_Proc_InMainCycle(); //报文解析,组包
- 1 //计数器改至主循环处理 zhang
- void COM_ProcessInMain(void)
- 2 //新报文及通讯超时处理
- 3 Comm[i].ProcInMainCycle(&Comm[i].MsgBuff.BuffBase);
- //ProcInMainCycle = DBJ_ProcInMainCycle
- = MODBUS_ProcInMainCycle
- = IEC103_ProcInMainCycle
-
- */
- /*************************IEC103 遥测组,遥脉组,保护测量组定义************************/
- //const IEC103_Measure_Group IEC103_ProtMeas_Index[ ] = {
- //IEC103对所有保护测量量的初始化配置
- const IEC103_Measure_Group IEC103_ProtMeas_Index[ ] = {
- { MEAS_PROT_Ia, IEC103_DATATYPE_INT16, 0 }, //Ia
- { MEAS_PROT_Ib, IEC103_DATATYPE_INT16, 0 }, //Ib
- { MEAS_PROT_Ic, IEC103_DATATYPE_INT16, 0 }, //Ic
- { MEAS_PROT_I0, IEC103_DATATYPE_INT16, 0 }, //I0
- { MEAS_MEAS_Ia, IEC103_DATATYPE_INT16, 0 }, //Ia
- { MEAS_MEAS_Ib, IEC103_DATATYPE_INT16, 0 }, //Ib
- { MEAS_MEAS_Ic, IEC103_DATATYPE_INT16, 0 }, //Ic
- { MEAS_MEAS_Ua, IEC103_DATATYPE_INT16, 0 }, //Ua
- { MEAS_MEAS_Ub, IEC103_DATATYPE_INT16, 0 }, //Ub
- { MEAS_MEAS_Uc, IEC103_DATATYPE_INT16, 0 }, //Uc
- { MEAS_MEAS_Uab, IEC103_DATATYPE_INT16, 0 }, //Uab
- { MEAS_MEAS_Ubc, IEC103_DATATYPE_INT16, 0 }, //Ubc
- { MEAS_MEAS_Uca, IEC103_DATATYPE_INT16, 0 }, //Uca
- { MEAS_MEAS_P_L, IEC103_DATATYPE_INT32, 1000 },
- // { MEAS_MEAS_P_H, IEC103_DATATYPE_INT32, 1000 },
- { MEAS_MEAS_Q_L, IEC103_DATATYPE_INT32, 1000 },
- // { MEAS_MEAS_Q_H, IEC103_DATATYPE_INT32, 1000 },
- { MEAS_MEAS_S_L, IEC103_DATATYPE_INT32, 1000 },
- // { MEAS_MEAS_S_H, IEC103_DATATYPE_INT32, 1000 },
- { MEAS_MEAS_FACT, IEC103_DATATYPE_INT16, 0 }, //测量量功率因素
- { MEAS_MEAS_Pa_L, IEC103_DATATYPE_INT32, 1000 }, //测量量有功
- // { MEAS_MEAS_Pa_H, IEC103_DATATYPE_INT32, 1000 },
- { MEAS_MEAS_Qa_L, IEC103_DATATYPE_INT32, 1000 }, //测量量无功
- // { MEAS_MEAS_Qa_H, IEC103_DATATYPE_INT32, 1000 },
- { MEAS_MEAS_Sa_L, IEC103_DATATYPE_INT32, 1000 },
- // { MEAS_MEAS_Sa_H, IEC103_DATATYPE_INT32, 1000 },
- { MEAS_MEAS_FACTa, IEC103_DATATYPE_INT16, 0 }, //测量量功率因素
-
- { MEAS_MEAS_Pb_L, IEC103_DATATYPE_INT32, 1000 }, //测量量有功
- // { MEAS_MEAS_Pb_H, IEC103_DATATYPE_INT32, 1000 },
- { MEAS_MEAS_Qb_L, IEC103_DATATYPE_INT32, 1000 }, //测量量无功
- // { MEAS_MEAS_Qb_H, IEC103_DATATYPE_INT32, 1000 },
- { MEAS_MEAS_Sb_L, IEC103_DATATYPE_INT32, 1000 },
- // { MEAS_MEAS_Sb_H, IEC103_DATATYPE_INT32, 1000 },
- { MEAS_MEAS_FACTb, IEC103_DATATYPE_INT16, 0 }, //测量量功率因素,
-
- { MEAS_MEAS_Pc_L, IEC103_DATATYPE_INT32, 1000 }, //测量量有功
- // { MEAS_MEAS_Pc_H, IEC103_DATATYPE_INT32, 1000 },
- { MEAS_MEAS_Qc_L, IEC103_DATATYPE_INT32, 1000 }, //测量量无功
- // { MEAS_MEAS_Qc_H, IEC103_DATATYPE_INT32, 1000 },
- { MEAS_MEAS_Sc_L, IEC103_DATATYPE_INT32, 1000 },
- // { MEAS_MEAS_Sc_H, IEC103_DATATYPE_INT32, 1000 },
- { MEAS_MEAS_FACTc, IEC103_DATATYPE_INT16, 0 }, //测量量功率因素,
- { MEAS_PE_L, IEC103_DATATYPE_UINT32, 1 }, //有功电能高位
- // { MEAS_PE_H, IEC103_DATATYPE_UINT32, 1 }, //有功电能地位
- { MEAS_QE_L, IEC103_DATATYPE_UINT32, 1 }, //无功电能高位
- // { MEAS_QE_H, IEC103_DATATYPE_UINT32, 1 }, //无功电能低位
- { MEAS_PEa_L, IEC103_DATATYPE_UINT32, 1 }, //有功电能高位
- // { MEAS_PEa_H, IEC103_DATATYPE_UINT32, 1 }, //有功电能地位
- { MEAS_QEa_L, IEC103_DATATYPE_UINT32, 1 }, //无功电能高位
- // { MEAS_QEa_H, IEC103_DATATYPE_UINT32, 1 }, //无功电能低位
- { MEAS_PEb_L, IEC103_DATATYPE_UINT32, 1 }, //有功电能高位
- // { MEAS_PEb_H, IEC103_DATATYPE_UINT32, 1 }, //有功电能地位
- { MEAS_QEb_L, IEC103_DATATYPE_UINT32, 1 }, //无功电能高位
- // { MEAS_QEb_H, IEC103_DATATYPE_UINT32, 1 }, //无功电能低位
- { MEAS_PEc_L, IEC103_DATATYPE_UINT32, 1 }, //有功电能高位
- // { MEAS_PEc_H, IEC103_DATATYPE_UINT32, 1 }, //有功电能地位
- { MEAS_QEc_L, IEC103_DATATYPE_UINT32, 1 }, //无功电能高位
- // { MEAS_QEc_H, IEC103_DATATYPE_UINT32, 1 }, //无功电能低位
- { MEAS_PHS_Ia, IEC103_DATATYPE_INT16, 0 }, //Ia相角
- { MEAS_PHS_Ib, IEC103_DATATYPE_INT16, 0 }, //Ib相角
- { MEAS_PHS_Ic, IEC103_DATATYPE_INT16, 0 }, //Ic相角
- { MEAS_PHS_Ua, IEC103_DATATYPE_INT16, 0 }, //Ua相角
- { MEAS_PHS_Ub, IEC103_DATATYPE_INT16, 0 }, //Ub相角
- { MEAS_PHS_Uc, IEC103_DATATYPE_INT16, 0 }, //Uc相角
- { MEAS_F, IEC103_DATATYPE_INT16, 0 }, //频率 f
- { MEAS_ELSE_LED, IEC103_DATATYPE_UINT16, 0 }, //灯
- { MEAS_ELSE_STATUS, IEC103_DATATYPE_UINT16, 0 }, //状态
- { MEAS_SIGNAL_DI, IEC103_DATATYPE_UINT16, 0 }, //开入遥信
- { MEAS_SIGNAL_DIEX, IEC103_DATATYPE_UINT16, 0 }, //扩展遥信 - 预留
- { MEAS_SIGNAL_PROT, IEC103_DATATYPE_UINT16, 0 }, //保护动作信号1
- { MEAS_SIGNAL_PROTEX, IEC103_DATATYPE_UINT16, 0 }, //保护动作信号2 - 预留
- { MEAS_SIGNAL_SELFCHK, IEC103_DATATYPE_UINT16, 0 }, //自检信号1
- { MEAS_SIGNAL_SELFCHKEX,IEC103_DATATYPE_UINT16, 0 }, //自检信号2 - 预留
- { MEAS_SIGNAL_TOTAL, IEC103_DATATYPE_UINT16, 0 }, //总信号
- { MEAS_SIGNAL_DO, IEC103_DATATYPE_UINT16, 0 } //开出信号
- };
- /*
- 2009-12-21 14:23 从上述量中选出IEC103信息表中需要上送的测量量,
- 类似于MEAS_MEAS_P_L与MEAS_MEAS_P_H使用两个数据表示一个量的选取
- 头一个数据的编号,调用时进行合成的特殊处理。
- */
- /***遥测上送量***/
- uint16 IEC103_Measure_YC_Index[NUM_YC_MAXNUM] ={
- MEAS_MEAS_Uab,
- MEAS_MEAS_Ubc,
- MEAS_MEAS_Uca,
- MEAS_MEAS_Ia,
- MEAS_MEAS_Ib,
- MEAS_MEAS_Ic,
- MEAS_MEAS_P_L,
- MEAS_MEAS_Q_L,
- MEAS_MEAS_FACT,
- MEAS_F
- };
-
- /***遥脉电能定义***/
- const uint16 IEC103_Measure_YM_Index[]=
- {
- MEAS_PE_L, //用有功电能低位代表有功电能
- MEAS_QE_L, //用无功电能低位代表无功电能
- MEAS_PEa_L, //用A相有功电能低位代表A相有功电能
- MEAS_QEa_L, //用A相无功电能低位代表A相无功电能
- MEAS_PEb_L, //用B相有功电能低位代表B相有功电能
- MEAS_QEb_L, //用B相无功电能低位代表B相无功电能
- MEAS_PEc_L, //用C相有功电能低位代表C相有功电能
- MEAS_QEc_L //用C相无功电能低位代表C相无功电能
- };
- /*************************IEC103 遥测组,遥脉组,保护测量组定义************************/
- /******************** 通用分类服务组的条目 ********************/
- /*注意:
- LpcRes.c文件占用空间太大,为减小代码空间,通用分类服务组的条目的名称在此
- 进行了定义,但必须与显示模块一致,因此名称应该与LpcRes.c文件中的名称定义相同。
- */
- //定值及系统设置的枚举值的所有文本字符串都必须包括在以下的结构体数组中
- IEC103_Enum_Text IEC103_Enum_String [ ] = {
- ///////////////////定值枚举文本//////////////////
- { ID_STRING_SETVAL_EXIT, "退出", "Exit" },
- { ID_STRING_SETVAL_WARNING, "报警", "Warn" },
- { ID_STRING_SETVAL_TRIP, "停车", "Stop" },
-
- { ID_STRING_OVERLOAD_TYPE_DEF, "定时限", "Definite Time" },
- { ID_STRING_OVERLOAD_TYPE_IMDT, "超常反时限", "Very IDMT" },
-
- { ID_STRING_SETVAL_DEVOTE, "投入", "On" },
-
- { ID_STRING_LOCAL, "本地", "Local" },
- { ID_STRING_REMOTE, "远程", "Remote" },
- { ID_STRING_BYDI, "根据外部开入", "By DI" },
- { ID_STRING_CONTRLIMIT_BYPROFIBUS,"根据Profibus","By Profibus" },
-
- { ID_STRING_COMM, "通信", "Communication" },
-
- ///////////////////系统设置枚举文本//////////////////
- { ID_STRING_NONE, "", "" },
- { ID_STRING_SC_COMM_PROTOCOL_DBJ, "DBJ 2.0", "DBJ 2.0" },
- { ID_STRING_SC_COMM_PROTOCOL_MODBUS,"MODBUS", "MODBUS" },
- { ID_STRING_SC_COMM_PROTOCOL_IEC103,"IEC103", "IEC103" },
-
- { ID_STRING_SC_COMM_BAUDRATE_4800, "485~4800", "485 - 4800" },
- { ID_STRING_SC_COMM_BAUDRATE_9600, "485~9600", "485 - 9600" },
- { ID_STRING_SC_COMM_BAUDRATE_19200, "485~19200", "485 - 19200" },
- { ID_STRING_SC_COMM_BAUDRATE_38400, "485~38400", "485 - 38400" },
- { ID_STRING_SC_COMM_BAUDRATE_57600, "485~57600", "485 - 57600" },
- { ID_STRING_SC_COMM_BAUDRATE_115200,"485~115200","485 - 115200" },
- // { ID_STRING_SC_COMM_BAUDRATE_10K, "CAN~10K", "CAN - 10K" },
- // { ID_STRING_SC_COMM_BAUDRATE_20K, "CAN~20K", "CAN - 20K" },
- { ID_STRING_SC_COMM_BAUDRATE_50K, "CAN~50K", "CAN - 50K" },
- { ID_STRING_SC_COMM_BAUDRATE_80K, "CAN~80K", "CAN - 80K" },
- { ID_STRING_SC_COMM_BAUDRATE_100K, "CAN~100K", "CAN - 100K" },
- { ID_STRING_SC_COMM_BAUDRATE_125K, "CAN~125K", "CAN - 125K" },
- { ID_STRING_SC_COMM_BAUDRATE_250K, "CAN~250K", "CAN - 250K" },
- { ID_STRING_SC_COMM_BAUDRATE_500K, "CAN~500K", "CAN - 500K" },
-
- { ID_STRING_IA, "IA", "IA" },
- { ID_STRING_IB, "IB", "IB" },
- { ID_STRING_IC, "IC", "IC" },
- { ID_STRING_IAV, "IAv", "IAv" },
- { ID_STRING_IPUN, "IPun", "IPun" },
- { ID_STRING_UAB, "UAB", "UAB" },
- { ID_STRING_UBC, "UBC", "UBC" },
- { ID_STRING_UCA, "UCA", "UCA" },
- { ID_STRING_UAV, "Uav", "Uav" },
- { ID_STRING_F, "F ", "F " },
- { ID_STRING_P, "P ", "P " },
-
- { ID_STRING_SC_LANGUAGE_CN, "中文", "Chinese" },
- { ID_STRING_SC_LANGUAGE_EN, "英文", "English" },
-
- { ID_STRING_WAVE_SEND_DISNABLE, "禁止上送", "Disable" }, //禁止上送
- { ID_STRING_WAVE_SEND_ENABLE, "允许上送", "Enable" } //允许上送
- };
- /******************** 通用分类服务组的条目的描述 ********************/
- //装置描述: 为节省代码空间,可以在函数实现时再定义 “装置描述”的条目名称。
- Description_Resource IEC103_DESCRIPTION_KOD10[ ] = {
- { "装置描述" , "DEVICE DESCRIPTION" },
- { "制造厂家" , "Manufacture" },
- { "装置型号" , "Device Type" },
- { "软件版本" , "Software Version" },
- { "程序形成时间" , "Software Build Time" },
- { "程序加载时间" , "Software Load Time" }
- };
- //装置定值名称
- Description_Resource IEC103_SetPoint_KOD10[NUM_SETTINGS+1] = {
- { "定值" , "DEVICE SETPOINT" },
- { "接地保护电流整定值" , "Earth Fault Curr. Setting" },
- { "接地保护动作时间" , "Earth Fault Time Setting" },
- { "接地保护动作方式" , "Earth Fault Act Mode" },
- { "DO1时间定义" , "DO1 Pulse Width" },
- { "DO2时间定义" , "DO2 Pulse Width" },
- { "DO3时间定义" , "DO3 Pulse Width" },
- { "两态控制权限" , "Two Control Limit" },
- { "三态控制权限" , "Three Control Limit" },
- { "开关合跳超时" , "Switch OverTime" }
- };
-
- //装置参数
- Description_Resource IEC103_SysCfg_KOD10[ ] = {
- { "装置参数" , "SYSTEM CONFIG" },
- { "密码" , "PassWord Set" },
- { "端口1通讯协议" , "Com. Port 1 Protocol" },
- { "端口1通讯地址" , "Com. Port 1 Address" },
- { "端口1波特率" , "Com. Port 1 BaudRate" },
- { "端口2通讯协议" , "Com. Port 2 Protocol" },
- { "端口2通讯地址" , "Com. Port 2 Address" },
- { "端口2波特率" , "Com. Port 2 BaudRate" },
- { "4~20mA交流量输出1定义" , "4-20mA Output1 Define" },
- { "4~20mA交流量输出1倍数" , "AO1 Ratio" },
- { "语言选择" , "Language" },
- { "CT变比" , "TA Scale" },
- { "PT变比" , "TV Scale" },
- { "零序CT变比" , "I0CT_scale" },
- { "录波信息上送" , "Send WaveData Enable" },
- { "调试录波时间" , "Debug WaveData Time" }
- };
-
- //动作元件
- Description_Resource IEC103_Action_KOD10[ ] = {
- { "动作元件", "PROTECT ACTION" },
- { "接地保护", "Earthing" }
- };
- //运行告警
- Description_Resource IEC103_SelfCheck_KOD10[ ] = {
- { "运行告警", "DEVICE ABNORMAL" },
- { "EEPROM", "EEPROM" },
- { "RAM", "RAM" },
- { "时钟", "CLOCK" },
- { "定值", "SETTING" },
- { "保护精度系数","Prot. Gains" },
- { "测量精度系数","Meas. Gains" },
- { "系统设置", "System Cfg." },
- { "工程配置", "Field Cfg." },
- { "开入开出配置","DI/DO Cfg." },
- { "开出24V电源", "24V Monitor" },
- { "外部接线", "CTRL Circuit " },
- { "可执行代码", "Exe. Code" }
- };
- //遥信,目前只有12+8个,以后增加时需要更改。
- Description_Resource IEC103_YX_KOD10[ ] = {
- { "遥信", "REMOTE SIGNAL" },
- { "开入1", "Digital In SIGNAL 1" },
- { "开入2", "Digital In SIGNAL 2" },
- { "开入3", "Digital In SIGNAL 3" },
- { "开入4", "Digital In SIGNAL 4" },
- { "开入5", "Digital In SIGNAL 5" },
- { "开入6", "Digital In SIGNAL 6" },
- { "开入7", "Digital In SIGNAL 7" },
- { "开入8", "Digital In SIGNAL 8" },
- { "开入9", "Digital In SIGNAL 9" },
- { "开入10", "Digital In SIGNAL 10" },
- { "开入11", "Digital In SIGNAL 11" },
- { "开入12", "Digital In SIGNAL 12" }
- };
- //保护测量
- Description_Resource IEC103_ProtMeas_KOD10[ ] = {
- { "保护测量", "PROTECTION MEASURE" }
- };
- //遥测
- Description_Resource IEC103_YC_KOD10[ ] = {
- { "遥测", "REMOTE MEASURE" }
- };
- //遥控
- Description_Resource IEC103_YK_KOD10[ ] = {
- { "遥控", "REMOTE CONTROL" },
- #ifdef FOUROBJECTS
- { "通信合闸", "Communication Close" },
- { "通信分闸", "Communication Trip" },
- { "通信合通用1", "Com. Switch on Universal 1" },
- { "通信分通用1", "Com. Switch off Universal 1" },
- { "通信合通用2", "Com. Switch on Universal 2" },
- { "通信分通用2", "Com. Switch off Universal 2" },
- { "通信合通用3", "Com. Switch on Universal 3" },
- { "通信分通用3", "Com. Switch off Universal 3" }
- #else
- #ifdef TWOOBJECTS
- { "远方遥信启动A", "Remote DI Startup A" },
- { "远方遥信停止A", "Remote DI Stop A" },
- { "远方遥信启动B", "Remote DI Startup B" },
- { "远方遥信停止B", "Remote DI Stop B" }
- #else
- { "远方遥信启动A", "Remote DI Startup A" },
- { "远方遥信停止A", "Remote DI Stop A" }
- #endif
- #endif
- };
- //遥脉
- Description_Resource IEC103_YM_KOD10[ ] = {
- { "遥脉", "REMOTE ENERGY" },
- { "有功电能", "Active Energy" },
- { "无功电能", "ReActive Energy" },
- { "A相有功电能", "Phase A Active Energy" },
- { "A相无功电能", "Phase A ReActive Energy" },
- { "B相有功电能", "Phase B Active Energy" },
- { "B相无功电能", "Phase B ReActive Energy" },
- { "C相有功电能", "Phase C Active Energy" },
- { "C相无功电能", "Phase C ReActive Energy" }
- };
- //扰动信息
- Description_Resource IEC103_Disturb_KOD10[ ] = {
- { "扰动数据说明", "DISTURB MESSAGE" }
- };
- Description_Resource IEC103_VPT_KOD10[ ] = {
- { "遥信", "VERTUAL SIGNAL" }
- // { "事故总信号", "Trip Signal" },
- // { "告警总信号", "Warning Signal" },
- // { "自检总信号", "Selfcheck Signal" }
- };
- /******************** 通用分类服务组的条目的描述 ********************/
- //查找定值或系统设置的枚举值的字符串。
- const char * GetEnumString( uint16 stringid )
- {
- uint16 i;
- const char *psz = NULL;
- for(i=0; i<sizeof(IEC103_Enum_String)/sizeof(IEC103_Enum_Text); i++)
- {
- if( stringid == IEC103_Enum_String[i].StringId )
- {
- if(GetSysCfgValue(ID_SYS_LANGUAGE) == LANG_CN)
- { psz = IEC103_Enum_String[i].cn; }
- else
- { psz = IEC103_Enum_String[i].en; }
- break;
- }
- }
- return psz;
- }
- uint16 FindPosInPROTMEAS(uint16 nID)
- {
- uint16 i;
- for(i=0; i<sizeof(IEC103_ProtMeas_Index)/sizeof(IEC103_Measure_Group); i++)//NUM_MEASURES
- {
- if(nID==IEC103_ProtMeas_Index[i].nID)
- {
- //*datatype = IEC103_ProtMeas_Index[i].datatype;
- //*combineflag = IEC103_ProtMeas_Index[i].bcombine;
- return i;
- }
- }
- }
- ////////////////////////////////////////////////////////////////////
- /*****************************SOE处理函数**************************/
- #define SOE_SI_OVERTIME 20000 //20S超时
- TSOE_SI_DEAL_STRUCT _soe_si_struct;
- //取消对应端口的SOE发送态,发送指针恢复(主要用于SOE发送不成功后的处理)
- void soe_si_CancelSOESend(uint16 uPort)
- {
- memset(&_soe_si_struct.SoePort[uPort], 0, sizeof(TSOE_SI_PORT));
- _soe_si_struct.SoePort[uPort].bInSoeSend = FALSE;
- // _soe_si_struct.SoePort[uPort].nOpenSoeCount = 0;
- // _soe_si_struct.SoePort[uPort].nSendSoeType = 0;
- }
- /*
- uint32 soe_si_HaveSOEToSend(uint8 uPort)
- {
- // TSOESave *psoesave = &(Ram.Eeprom.SOESave);
- TSOESave *psoesave = &(ExramSOESave.SOESave);
- if(_soe_si_struct.SoePort[uPort].bInSoeSend)
- { return TRUE; }
- else if(
- (psoesave->ActionSOESave.comm_index[uPort] !=psoesave->ActionSOESave.current_index)
- ||(psoesave->AbnormalSOESave.comm_index[uPort] !=psoesave->AbnormalSOESave.current_index)
- ||(psoesave->DigitalSOESave.comm_index[uPort] !=psoesave->DigitalSOESave.current_index) )
- { return TRUE; }
- return FALSE;
- }
- */
- uint32 IEC103_SOE_DealFlag(uint8 uPort)
- {
- uint16 newsoe_num = 0;
- uint16 newsoe_type = 0;
- uint16 soe_mask = (1<<SOE_ACTION)|(1<<SOE_DIGITAL)|(1<<SOE_ABNORMAL);
- // TSOESave *psoesave = &(Ram.Eeprom.SOESave);
- TSOESave *psoesave = &(ExramSOESave.SOESave);
- if(!_soe_si_struct.SoePort[uPort].bInSoeSend) //if(*pSoeNeedSendType == 0)
- {
- if(psoesave->ActionSOESave.comm_index[uPort] !=psoesave->ActionSOESave.current_index)
- {
- newsoe_type = 1<<SOE_ACTION;
- newsoe_num = ( NUM_ACTIONSOE + psoesave->ActionSOESave.current_index
- - psoesave->ActionSOESave.comm_index[uPort])%NUM_ACTIONSOE;
- }
- else if(psoesave->AbnormalSOESave.comm_index[uPort] !=psoesave->AbnormalSOESave.current_index)
- {
- newsoe_type = 1<<SOE_ABNORMAL;
- newsoe_num = ( NUM_ABNORMALSOE + psoesave->AbnormalSOESave.current_index
- - psoesave->AbnormalSOESave.comm_index[uPort])%NUM_ABNORMALSOE;
- }
- else if(psoesave->DigitalSOESave.comm_index[uPort] !=psoesave->DigitalSOESave.current_index)
- {
- newsoe_type = 1<<SOE_DIGITAL;
- newsoe_num = ( NUM_DIGITALSOE + psoesave->DigitalSOESave.current_index
- - psoesave->DigitalSOESave.comm_index[uPort])%NUM_DIGITALSOE;
- }
-
- _soe_si_struct.SoePort[uPort].nSendSoeType = newsoe_type&soe_mask;
- _soe_si_struct.SoePort[uPort].nSendSoeCount = newsoe_num;
- }
-
- return _soe_si_struct.SoePort[uPort].nSendSoeType;
- }
- //上次组包的SOE发送完毕
- void soe_si_ConfirmSOESend(uint16 uPort)
- {
- TSOE_SI_PORT * pSoePort = &_soe_si_struct.SoePort[uPort];
- uint16 i,opencnt;
-
- opencnt = pSoePort->nOpenSoeCount;
- i = opencnt;
- if(pSoePort->nSendSoeType & (1<<SOE_ACTION) )
- {
- while(i--)
- {
- // eepwri_SentOneActionSOE(uPort);
- exramwri_SentOneActionSOE(uPort);
- }
- }
- else if(pSoePort->nSendSoeType & (1<<SOE_ABNORMAL) )
- {
- while(i--)
- {
- // eepwri_SentOneAbnormalSOE(uPort);
- exramwri_SentOneAbnormalSOE(uPort);
- }
- }
- else if(pSoePort->nSendSoeType & (1<<SOE_DIGITAL) )
- {
- while(i--)
- {
- // eepwri_SentOneDigitalSOE(uPort);
- exramwri_SentOneDigitalSOE(uPort);
- }
- }
- pSoePort->bInSoeSend = FALSE;
- pSoePort->nSendSoeType = 0;
- pSoePort->nSendSoeCount = 0;
- pSoePort->nOpenSoeCount = 0;
-
- pSoePort->nTimer = 0;
- // pSoePort->pSendSoePtr = NULL;
- }
- //通讯任务中接口调用处理(可以不进行该接口调用)
- void soe_si_DealProc_InTask(uint32 nms,uint16 uPort)
- {
- // TSOESave *psoesave = &(Ram.Eeprom.SOESave);
- TSOE_SI_PORT * pSoePort = &_soe_si_struct.SoePort[uPort];
-
- //NET1/2
- if(pSoePort->bInSoeSend)
- {
- pSoePort->nTimer+=nms;
- if(pSoePort->nTimer > SOE_SI_OVERTIME)
- {
- soe_si_CancelSOESend(uPort); //超时取消SOE发送
- }
- }
- else
- {
- pSoePort->nTimer = 0;
- //需要调用?
- IEC103_SOE_DealFlag(uPort);
- }
- }
- ////////////////////////////////////////////////////////////////////
- /*****************************遥控处理函数**************************/
- // 定义遥控操作超时
- #define TIME_CONTROL_OVERTIME 10000 //(5*OS_TICKS_PER_SEC) // 5S超时
- //(TBuffDBJ * pBuff, uint16 * pInfo)
- //ctrl中为指令,info中为结果或错误标志
- void IEC103_RCtrl_Logic(uint8 nCtrlCode, uint8 nFUN, uint8 nINF, uint8 dpi_code, int32 * ctrl, int32 * info)
- {
- int16 control_obj;
- uint16 nType,nCommand,nCheckResult;
- int16 nResult=-1;
- int32 nOverTime = TIME_CONTROL_OVERTIME;
- //检查装置当前控制权限是就地还是远方
- if (GetDeviceModelValue(ID_DEVICEMODEL_NumControlLimit)==TWO_CONTROLLIMIT)
- {
- if(GetCurrentControlLimit()!=CONTROL_LMT_REMOTE)
- {
- *info=ID_CTRLRESULT_UNREMOTE; //报错,装置不在远方,不允许通讯控制
- return ;
- }
- }
- else if (GetDeviceModelValue(ID_DEVICEMODEL_NumControlLimit)==THREE_CONTROLLIMIT)
- {
- if(GetCurrentControlLimit()!=CONTROL_LMT_COMM)
- {
- *info=ID_CTRLRESULT_DISABLE; //报错,装置不在通讯,不允许通讯控制
- return ;
- }
- }
-
- /*****
- 遥控报文结构
- 控制指令(选择/执行/撤销)
- 控制FUN
- 控制INF
- 控制类型(合/分 升/降/停...)
- ******/
- if(nCtrlCode == DR_REMOTE_CTRL_C_CANCEL) //遥控撤销指令
- {
- //遥控撤销指令,撤销当前控制
- //ResetControlCode();
- memset(&yk_ctrlinfo, 0, sizeof(TCONTROL_INFO));
- *info=ID_CTRLRESULT_SUCCESS; //撤销成功
- *ctrl = DR_REMOTE_CTRL_R_CANCEL;
- return;
- }
-
- /*** 根据控制指令处理,遥控指令返回 ***/
- switch(nCtrlCode)
- {
- case DR_REMOTE_CTRL_C_SELECT:
- {
- *ctrl = DR_REMOTE_CTRL_R_SELECT;
- }
- break;
- case DR_REMOTE_CTRL_C_EXEC:
- {
- *ctrl = DR_REMOTE_CTRL_R_EXEC;
- }
- break;
- default:
- {
- *ctrl = nCtrlCode;
- *info=ID_CTRLRESULT_COMMAND; //未知指令,返回NAK
- return;
- }
- }
- control_obj = -1;
-
- //根据FUN和INF检索当前是否存在此对象
- if( (nFUN==IEC103_YK_FUN) &&(nINF>=IEC103_YK_FIRSTINF) && (nINF<=IEC103_YK_FIRSTINF+CTRLCMD_OBJECT_NUM-CTRLCMD_OBJECT1) )
- { control_obj = nINF - IEC103_YK_FIRSTINF + CTRLCMD_OBJECT1; }
-
- if(control_obj == -1) // 对象不存在
- {
- *info=ID_CTRLRESULT_OBJECT; // 对象不存在
- return;
- }
- else if(dpi_code!=CTRLCMD_TRIP && dpi_code!=CTRLCMD_CLOSE)
- {
- *info=ID_CTRLRESULT_COMMAND; // 指令错误
- return;
- }
- else
- {
- if(control_obj==CTRLCMD_OBJECT1)
- {
- if(dpi_code==CTRLCMD_CLOSE)
- {
- nCommand=CTRLCMD_ASTARTUP;
- nType=CONTROL_ASTARTUP_COMM;
- }
- else if(dpi_code==CTRLCMD_TRIP)
- {
- nCommand=CTRLCMD_STOP;
- nType=CONTROL_STOP_COMM;
- }
- }
- //#if(CTRLCMD_OBJECT_NUM==2)
- #ifdef TWOOBJECTS
- else if(control_obj==CTRLCMD_OBJECT2)
- {
- if(dpi_code==CTRLCMD_CLOSE)
- {
- nCommand=CTRLCMD_BSTARTUP;
- nType=CONTROL_BSTARTUP_COMM;
- }
- else if(dpi_code==CTRLCMD_TRIP)
- {
- nCommand=CTRLCMD_STOP;
- nType=CONTROL_STOP_COMM;
- }
- }
- #endif
- //#if CTRLCMD_OBJECT_NUM==4 //FOUROBJECTS
- #ifdef FOUROBJECTS
- else if(control_obj==CTRLCMD_OBJECT2)
- {
- if(dpi_code==CTRLCMD_CLOSE)
- {
- nCommand=CTRLCMD_UNIVERSAL1ON;
- nType=CONTROL_UNIVERSAL1ON_COMM;
- }
- else if(dpi_code==CTRLCMD_TRIP)
- {
- nCommand=CTRLCMD_UNIVERSAL1OFF;
- nType=CONTROL_UNIVERSAL1OFF_COMM;
- }
- }
- else if(control_obj==CTRLCMD_OBJECT3)
- {
- if(dpi_code==CTRLCMD_CLOSE)
- {
- nCommand=CTRLCMD_UNIVERSAL2ON;
- nType=CONTROL_UNIVERSAL2ON_COMM;
- }
- else if(dpi_code==CTRLCMD_TRIP)
- {
- nCommand=CTRLCMD_UNIVERSAL2OFF;
- nType=CONTROL_UNIVERSAL2OFF_COMM;
- }
- }
- else if(control_obj==CTRLCMD_OBJECT4)
- {
- if(dpi_code==CTRLCMD_CLOSE)
- {
- nCommand=CTRLCMD_UNIVERSAL3ON;
- nType=CONTROL_UNIVERSAL3ON_COMM;
- }
- else if(dpi_code==CTRLCMD_TRIP)
- {
- nCommand=CTRLCMD_UNIVERSAL3OFF;
- nType=CONTROL_UNIVERSAL3OFF_COMM;
- }
- }
- #endif
- else
- {
- *info=ID_CTRLRESULT_OBJECT;
- return;
- }
- }
-
- //检查完成,可以处理遥控选择与遥控执行了!
- /*** 遥控选择处理 ***/
- if(nCtrlCode == DR_REMOTE_CTRL_C_SELECT)
- {
- //ClearControlCode(); //不管怎样,先清指令
- //SetCtrlResult(ID_CTRLRESULT_SUCCESS); //成功,总是选择成功
- //nResult = GetCurrentControlResult();
-
- //设置当前控制选择指令
- yk_ctrlinfo.nCtrlObjID = control_obj;
- yk_ctrlinfo.nCtrlCmd = nCommand;
- yk_ctrlinfo.bComplete = FALSE;
- yk_ctrlinfo.nCtrlCode = DR_REMOTE_CTRL_C_SELECT;
-
- yk_ctrlinfo.nCtrlResult = ID_CTRLRESULT_SUCCESS;
- yk_ctrlinfo.nCtrlCode = 0;
- yk_ctrlinfo.bComplete = TRUE;
-
- nResult = yk_ctrlinfo.nCtrlResult;
- }
- /*** 遥控执行处理 ***/
- else if(nCtrlCode == DR_REMOTE_CTRL_C_EXEC)
- {
- //命令检查,和前面的遥控选择匹配 zhongwei 2009-03-11 软压板和遥控同样需要先发送遥控选择指令
- if( yk_ctrlinfo.nCtrlObjID == control_obj && yk_ctrlinfo.nCtrlCmd==nCommand )
- {
- //设置当前控制执行指令
- yk_ctrlinfo.bComplete = FALSE;
- yk_ctrlinfo.nCtrlCode = DR_REMOTE_CTRL_C_EXEC;
- }
- else
- {
- //与前次选择不匹配,或者没有进行选择直接执行
- *info=ID_CTRLRESULT_SEQUENCE; //序列错
- return;
- }
- }
-
- //执行遥控指令,只需要添加指令即可
- if(nCtrlCode == DR_REMOTE_CTRL_C_EXEC)
- {
- //生成操作SOE
- //待改 soe_AddNewOperateSOE(ID_RUN_REMOTE_CONTROL);
-
- /////////////////////////////////////////
- //控制操作,返回指令检查结果
- nCheckResult=ControlProc_ByComm(nCommand, nType);
- *info=nCheckResult;
- if(nCheckResult!=CTRLCMD_CHECK_OK)
- {
- return;
- }
-
- yk_ctrlinfo.bComplete = TRUE; //指令添加正确
- yk_ctrlinfo.nCtrlResult = nCheckResult;
-
- //if(D_ControlObject_Define[nObject].bReCheck)//检查控制对象是否需要真返校
- if(1) //固定为需要返校
- {
- // 真返校 等待选择/执行指令完成,以及超时处理
- while (nOverTime>0)
- {
- nOverTime--;
- if(yk_ctrlinfo.bComplete)/*遥控执行完成*/
- {
- nResult = yk_ctrlinfo.nCtrlResult; //获取结果
- break;
- }
- }
-
- if(nResult == -1) //超时到,仍然没有结果返回
- {
- nResult = ID_CTRLRESULT_OVERTIME;
- }
- }
- else
- {
- // 假返校 不需要等执行完成,直接返回
- if(nCtrlCode == DR_REMOTE_CTRL_C_SELECT) //遥控选择
- {
- yk_ctrlinfo.nCtrlCode = 0; //ClearControlCode(); //不管怎样,先清指令
- yk_ctrlinfo.nCtrlResult = (ID_CTRLRESULT_SUCCESS); //成功,总是选择成功
- nResult = yk_ctrlinfo.nCtrlResult;
- }
- else if(nCtrlCode == DR_REMOTE_CTRL_C_EXEC) //遥控执行
- {
- while (nOverTime>0) //等待遥控执行完成或超时
- {
- nOverTime--;
- if(yk_ctrlinfo.bComplete)/*遥控执行完成*/
- {
- nResult = yk_ctrlinfo.nCtrlResult; //获取结果
- break;
- }
- }
-
- if(nResult == -1) //超时到,仍然没有结果返回
- {
- nResult = ID_CTRLRESULT_OVERTIME;
- }
- }
- }
- }//执行完毕
-
- //如果遥控校验失败或者在遥控执行下
- if(nResult!=ID_CTRLRESULT_SUCCESS || nCtrlCode == DR_REMOTE_CTRL_C_EXEC)
- {
- //清遥控信息
- memset(&yk_ctrlinfo, 0, sizeof(TCONTROL_INFO)); //ResetControlCode();
- }
-
- *info = nResult;
- return;
- }