FDJ_HB_P103.C
资源名称:gca-150A.rar [点击查看]
上传用户:jndfzc
上传日期:2014-06-02
资源大小:325k
文件大小:91k
源码类别:
单片机开发
开发平台:
Others
- //++++++++++++++++++++++++++++++++++++++++++++++++++++
- // GCA-150A通信程序
- // 创建日期:2004年12月13日
- // 修改日期:2005年08月29日
- //++++++++++++++++++++++++++++++++++++++++++++++++++++
- #include "define.h"
- #include "P103_mmi2dsp.h"
- #define DELAYACK 200 //通信间隔计时器
- #define DELAYACK1 200 //通信间隔计时器
- #define RECALLCOUNT 600 //重复发送计数器
- #define COMMANDDELAY 1500
- #define FUNTYPE 0x01
- #define Setting_Total 42
- #define Sys_Cfg_Total 13
- #define YC_Total 26
- #define YC1_Total 26
- #define CHANNEL_NUM 32
- extern struct comm_buf_fm PortA;
- extern struct comm_buf_fm Comm0;
- extern unsigned int YC_Value[YC_NUM]; /*数组存所有YC数据*/
- extern unsigned int YC_Value1[YC_NUM]; /*数组存所有YC数据*/
- extern struct System_Info_fm System_Info; //实时信息
- extern unsigned int System_config[CONFIG_NUM]; //系统配置
- extern unsigned int System_setting[SETTING_NUM]; //定值
- extern struct Time_buf realtime; //实时时钟
- extern struct Time_buf realtime1; //实时时钟
- extern unsigned char TargetArea; //目标区(用于复制定值)
- extern unsigned char SourceArea; //原始区(用于复制定值)
- extern struct SOE_Buf_Show_fm SOE_Buf_Show0; //存放SOE的缓冲区
- extern struct Report_Buf_Show_fm Report_Buf_Show0;
- extern struct SoftInformation_fm SoftInformation;
- extern struct Setting_Copy_fm Setting_Copy;
- extern struct Setting_Switch_fm Setting_Switch;
- extern struct Output_Test_YK_fm Output_Test_YK;
- extern struct Channel_Ration_Flag_fm Channel_Ration_Flag;
- extern struct YYB_Modify_Flag_fm YYB_Modify_Flag;
- extern struct Fault_Recode_Flag_fm Fault_Recode_Flag; //召唤故障报告/SOE缓冲区
- extern struct Harmonic_Value_fm Harmonic_Value;
- extern unsigned char New_Information_Flag,PC_Comm_Flag;
- struct comm_buf_flag_fm
- {
- UC RecvBuf[270]; //接收缓冲区
- UI ReceivePoint; //接收到的字节计数器
- UC synchro; //同步标志
- UC Type; //固定帧还是可变帧
- UC FrameRecv; //收到完整的数据帧,固定帧0x15;可变帧0x1a
- UC DeviceAddr; //DSP插件地址
- US Timing; //发送时间间隔计数器
- UC Sendbuf[270]; //发送缓冲区
- US SendSeq; //发送次序
- UC Length; //发送长度计数
- UC Counter; //重复发送计数器
- UC CommError; //装置通信故障标志,0x22复位CU 0x11复位FCB
- UC Flag_CallAll; //总召唤标志
- UI Timer_CallAll; //总召唤计时
- UC Flag_CheckTime; //对时标志
- UC Modify_Time_Flag; //修改时间标志
- UI Timer_CheckTime; //定时对时计时器
- UC Init_System_Flag; //上电初始化标志
- UC Asdu10_10;
- UC Asdu10_12;
- UC Asdu10_13;
- UC TempBuf[260]; //发送临时缓冲区
- UC FCB;
- UC FCV;
- UC FUN; //哪种类型的保护
- UC ACD;
- //---------YK------------
- UC YkCommand; //遥控命令
- UC YkDataNo1; //遥控点号1
- UC YkDataNo2; //遥控点号2
- UC YkSelect; //选择标志
- UC YkError; //遥控出错
- //---------Setting-------
- UC DzCommand; //定值操作,
- UC DzAreaNo; //定值区号
- UC DzDataNum; //定值个数
- UC DzSwitchSele; //定值切换选择标志
- UC DzCopySele; //定值复制选择标志
- UC DzData[256];
- UC DzSelect; //定值选择标志
- UC DzError; //远方修改定值出错
- UC FunctionCode; //功能码
- UC LPDU_Command;
- UC ASDU_Length;
- struct comm_buf_fm *com_103;
- };
- struct comm_buf_flag_fm *comm_buf_flag;
- struct comm_buf_flag_fm ComDsp_buf_flag;
- struct Order_Array_fm
- {
- unsigned char Set;
- unsigned char Get;
- unsigned short Order[10];
- };
- struct Order_Array_fm Order_Array;
- struct command_statue_fm
- {
- int Check_Time_Flag; //修改时间
- int Check_Time_Count;
- int Config_Operation_Flag; //系统参数操作标志
- int Config_Operation_Count;
- int Setting_Operation_Flag; //定值操作标志
- int Setting_Operation_Count;
- int Channel_Ration_Flag; //通道系数操作标志
- int Channel_Ration_Count;
- int YYB_Opreation_Flag; //软压板操作
- int YYB_Opreation_Count;
- int Password_Modified_Flag; //修改密码
- int Password_Modified_Count;
- int YK_Output_Command_Flag; //遥控/开出传动选择
- int YK_Output_Command_Count;
- int Demand_Soe_Report_Flag; //查询SOE及故障报告
- int Demand_Soe_Report_Count;
- int Device_FUGUI_Flag; //装置复归
- int Device_FUGUI_Count;
- };
- struct command_statue_fm command_statue;
- //---------------------------------------------
- // 以下为函数声明
- //---------------------------------------------
- void Init_Unit(void); //初始化
- void Check_Time(void); //对时
- void Call_WholeData(void); //总召唤
- void Com_Patrol(void); //轮询
- void ComSend(void);
- void ComResend(void);
- void Comm_RecvProcess(void);
- void CommDspTimeUpdate(void);
- void YK_Command_Style(unsigned int Addr,unsigned int Style,unsigned int Seq);
- //int MMI_DSP_Instruction(unsigned int Command,unsigned int per1,unsigned int per2);
- void Command_Timer_Update(void);
- void Command_Timer_Check(void);
- int Check_Instruction_Statue(unsigned int Command);
- void SendFixFrm(UC SFunCode);
- void SendValFrm(UC SFunCode, UC len );
- void ProcessMMI_DSP(void);
- void Init_Unit(void);
- void Call_WholeData(void);
- void Check_Time(void);
- void Com_Patrol(void);
- void Read_SystemConfig(void);
- void Read_SystemSetting(void);
- void Auto_Adjust_Ration(void);
- void Modify_Channel_Ration(void);
- void Setting_PreModify(void);
- void Setting_Modified_Exe(void);
- void Setting_Area_Switch(void);
- void YYB_Opreation(void);
- void Setting_Area_Copy(void);
- void Config_PreModify(void);
- void Config_Modified_Exe(void);
- void Password_Modified_Exe(void);
- void Demand_Soe_Report(void);
- void YK_Output_Command(void);
- void Device_FUGUI(void);
- void ADSU_01_Analyze(void);
- void ASDU_05_Send0(void);
- void ASDU_05_Send1(void);
- void ASDU_05_Send2(void);
- void ASDU_05_Analyze(void);
- void ASDU_06_Send0(void);
- void ASDU_06_Send1(void);
- void ASDU_06_Analyze(void);
- void ASDU_07_Send(void);
- void ASDU_10_Send2(unsigned char Type);
- void ASDU_10_Send3(unsigned char Type);
- void ASDU_10_Analyze(void);
- void ASDU_20_Send0(void);
- void ASDU_20_Send1(void);
- void ASDU_20_Send2(void);
- void ASDU_20_Send3(void);
- void ASDU_20_Send4(void);
- void ASDU_20_Send5(void);
- void ASDU_20_Send7(void);
- void ASDU_20_Send8(void);
- void ASDU_20_Analyze(void);
- void ASDU_21_Send0(unsigned char Segment);
- void ASDU_40_Analyze(void);
- void ASDU_50_Analyze(void);
- void ASDU_64_Send0(void);
- void ASDU_64_Analyze(void);
- void ASDU_Analyze(void);
- //---------------------------------------------
- // 初始化通信标志及缓冲区
- //---------------------------------------------
- void ComMMI2DSP_init(void)
- {
- ComDsp_buf_flag.synchro = 0;
- ComDsp_buf_flag.Type = 0xff; //固定帧还是可变帧
- ComDsp_buf_flag.FrameRecv = 0;
- Order_Array.Set = Order_Array.Get = 0;
- ComDsp_buf_flag.CommError = 0x11;
- ComDsp_buf_flag.DeviceAddr = 0x03;
- ComDsp_buf_flag.ReceivePoint = 0; //
- ComDsp_buf_flag.SendSeq = 0x000;
- ComDsp_buf_flag.FUN = 160; //哪种类型的保护
- ComDsp_buf_flag.Flag_CallAll = 0x01; //上电允许总召唤
- ComDsp_buf_flag.Timer_CallAll = 0; //总召唤计时器回零
- ComDsp_buf_flag.Flag_CheckTime = 0x01; //上电允许对时
- ComDsp_buf_flag.Modify_Time_Flag = 0x00;
- ComDsp_buf_flag.Timer_CheckTime = 0; //对时间隔计时器回零
- ComDsp_buf_flag.Init_System_Flag = 0x01; //上电初始化标志
- //---------YK------------
- ComDsp_buf_flag.YkCommand = 0; //遥控命令
- ComDsp_buf_flag.YkDataNo1 = 0; //遥控点号
- ComDsp_buf_flag.YkDataNo2 = 0; //遥控点号
- ComDsp_buf_flag.YkSelect = 0; //选择标志
- ComDsp_buf_flag.YkError = 0; //遥控出错
- //---------Setting-------
- ComDsp_buf_flag.DzCommand = 0; //定值操作,
- ComDsp_buf_flag.DzAreaNo = 0; //定值区号
- ComDsp_buf_flag.DzDataNum = 0; //定值个数
- ComDsp_buf_flag.DzSelect = 0; //定值选择标志
- ComDsp_buf_flag.DzError = 0; //远方修改定值出错
- ComDsp_buf_flag.FunctionCode = 0; //功能码
- ComDsp_buf_flag.LPDU_Command = 0;
- ComDsp_buf_flag.ASDU_Length = 0;
- Order_Array.Order[ Order_Array.Set ] = 0x0200;
- Order_Array.Set = (Order_Array.Set+1)%10;
- Order_Array.Order[ Order_Array.Set ] = 0x0100;
- Order_Array.Set = (Order_Array.Set+1)%10;
- ComDsp_buf_flag.com_103 =&PortA;// &Comm0;//
- comm_buf_flag = &ComDsp_buf_flag;
- }
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
- // 发送处理
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
- void ComSend(void)
- {
- UI i;
- for( i = 0 ; i < comm_buf_flag->Length ; i++)
- {
- comm_buf_flag->com_103->SendBuf[comm_buf_flag->com_103->SendSet] = comm_buf_flag->Sendbuf[i];
- if((comm_buf_flag->com_103->SendSet++) >= SENDNUM)
- comm_buf_flag->com_103->SendSet=0;
- if(PC_Comm_Flag == 0x00)
- {
- Comm0.SendBuf[Comm0.SendSet] = comm_buf_flag->Sendbuf[i];
- Comm0.SendSet = (Comm0.SendSet+1)%SENDNUM;
- }
- }
- }
- void ComResend(void)
- {
- UI i,Length;
- if( comm_buf_flag->TempBuf[0] == 0x10 )
- Length = 0x05;
- else if(( comm_buf_flag->TempBuf[0] == 0x68 )&&( comm_buf_flag->TempBuf[3] == 0x68 )
- &&(comm_buf_flag->TempBuf[1] == comm_buf_flag->TempBuf[2]))
- {
- if( (comm_buf_flag->TempBuf[1]+5)== 0x16 ) Length = comm_buf_flag->TempBuf[1]+6;
- }
- else return;
- for( i = 0 ; i < Length ; i++)
- {
- comm_buf_flag->com_103->SendBuf[comm_buf_flag->com_103->SendSet] = comm_buf_flag->TempBuf[i];
- if((comm_buf_flag->com_103->SendSet++) >= SENDNUM)
- comm_buf_flag->com_103->SendSet=0;
- if(PC_Comm_Flag == 0x00)
- {
- Comm0.SendBuf[Comm0.SendSet] = comm_buf_flag->TempBuf[i];
- Comm0.SendSet = (Comm0.SendSet+1)%SENDNUM;
- }
- }
- }
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
- // 接收处理
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
- void Comm_RecvProcess(void)
- {
- unsigned char temp,i;
- switch(comm_buf_flag->synchro)
- {
- case 0:
- while( comm_buf_flag->com_103->RecvSet != comm_buf_flag->com_103->RecvGet )
- {
- if(comm_buf_flag->com_103->RecvBuf[comm_buf_flag->com_103->RecvGet]==0x10)
- {
- comm_buf_flag->synchro=1;
- comm_buf_flag->Type = 0;
- break;
- }
- else if(comm_buf_flag->com_103->RecvBuf[comm_buf_flag->com_103->RecvGet]==0x68)
- {
- comm_buf_flag->synchro=1;
- comm_buf_flag->Type = 1;
- break;
- }
- else
- {
- comm_buf_flag->com_103->RecvGet++;
- if(comm_buf_flag->com_103->RecvGet >= RECVNUM) comm_buf_flag->com_103->RecvGet = 0;
- continue;
- }
- }
- break;
- case 1:
- while( comm_buf_flag->com_103->RecvSet != comm_buf_flag->com_103->RecvGet )
- {
- comm_buf_flag->RecvBuf[comm_buf_flag->ReceivePoint] = comm_buf_flag->com_103->RecvBuf[comm_buf_flag->com_103->RecvGet];
- comm_buf_flag->ReceivePoint++;
- comm_buf_flag->com_103->RecvGet++;
- if(comm_buf_flag->com_103->RecvGet >= RECVNUM) comm_buf_flag->com_103->RecvGet = 0;
- if(comm_buf_flag->Type == 0)
- {
- if(comm_buf_flag->ReceivePoint>=5)
- {
- temp = comm_buf_flag->RecvBuf[1]+comm_buf_flag->RecvBuf[2];
- if ((comm_buf_flag->RecvBuf[2]==comm_buf_flag->DeviceAddr)||(comm_buf_flag->RecvBuf[2]==0xFF))
- {
- comm_buf_flag->FrameRecv = 0x15;
- comm_buf_flag->Type = 0xff;
- comm_buf_flag->synchro = 0;
- comm_buf_flag->ReceivePoint = 0;
- }
- else
- {
- comm_buf_flag->FrameRecv = 0;
- comm_buf_flag->Type = 0xff;
- comm_buf_flag->synchro = 0;
- comm_buf_flag->ReceivePoint = 0;
- }
- break;
- }
- }
- else if(comm_buf_flag->Type == 1)
- {
- if((comm_buf_flag->ReceivePoint>=4))
- {
- if((comm_buf_flag->RecvBuf[0]!=0x68)||(comm_buf_flag->RecvBuf[3]!=0x68)||
- (comm_buf_flag->RecvBuf[1]!=comm_buf_flag->RecvBuf[2]))
- {
- comm_buf_flag->Type = 0xff;
- comm_buf_flag->synchro = 0;
- comm_buf_flag->ReceivePoint = 0;
- break;
- }
- if(comm_buf_flag->ReceivePoint >= (comm_buf_flag->RecvBuf[1]+6))
- {
- temp = 0;
- for(i=0;i< comm_buf_flag->RecvBuf[1];i++)
- temp = temp + comm_buf_flag->RecvBuf[4+i];
- if (((comm_buf_flag->RecvBuf[5]==comm_buf_flag->DeviceAddr)||(comm_buf_flag->RecvBuf[5]==0xFF))
- &&(temp==(comm_buf_flag->RecvBuf[comm_buf_flag->RecvBuf[1]+4])))
- {
- comm_buf_flag->FrameRecv = 0x1A;
- comm_buf_flag->Type = 0xff;
- comm_buf_flag->synchro = 0;
- comm_buf_flag->ReceivePoint = 0;
- }
- else
- {
- comm_buf_flag->FrameRecv = 0x0;
- comm_buf_flag->Type = 0xff;
- comm_buf_flag->synchro = 0;
- comm_buf_flag->ReceivePoint = 0;
- }
- break;
- }
- }
- }
- else
- {
- comm_buf_flag->Type = 0xff;
- comm_buf_flag->synchro = 0;
- comm_buf_flag->ReceivePoint = 0;
- break;
- }
- }
- break;
- default :
- comm_buf_flag->Type = 0xff;
- comm_buf_flag->synchro = 0;
- comm_buf_flag->ReceivePoint = 0;
- break;
- }
- }
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
- // 通信时间间隔计数
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
- void CommDspTimeUpdate(void)
- {
- comm_buf_flag->Timing++;
- /* comm_buf_flag->Timer_CallAll++;
- if( comm_buf_flag->Timer_CallAll >= 900000 )
- {
- comm_buf_flag->Flag_CallAll = 0x01; //上电允许总召唤
- Order_Array.Order[ Order_Array.Set ] = 0x0100;
- Order_Array.Set = (Order_Array.Set+1)%10;
- comm_buf_flag->Timer_CallAll = 0; //总召唤计时器回零
- }
- */
- if( ComDsp_buf_flag.CommError!=0x11 )
- {
- comm_buf_flag->Timer_CheckTime++;
- if( comm_buf_flag->Timer_CheckTime >= 6000 ) //_CheckTime
- {
- comm_buf_flag->Flag_CheckTime = 0x01; //置对时标志
- Order_Array.Order[ Order_Array.Set ] = 0x0200;
- Order_Array.Set = (Order_Array.Set+1)%10;
- comm_buf_flag->Timer_CheckTime = 0; //计数器归零
- }
- }
- Command_Timer_Update();
- }
- //---------------------------------------------------------------------
- // 遥控命令解析
- //---------------------------------------------------------------------
- void YK_Command_Style(unsigned int Addr,unsigned int Style,unsigned int Seq)
- {
- Output_Test_YK.YkDataNo1 = Addr;
- if(Style == 0x11) //合
- {
- if(Seq == 0x55) Output_Test_YK.YkCommand = 0x82; //预合
- else if(Seq == 0xAA) Output_Test_YK.YkCommand = 0x02; //合执行
- else if(Seq == 0xcc) Output_Test_YK.YkCommand = 0xC2; //合命令撤销
- else Output_Test_YK.YkCommand = 0x00; //未知
- }
- else if(Style == 0x22) //分
- {
- if(Seq == 0x55) Output_Test_YK.YkCommand = 0x81; //预分
- else if(Seq == 0xAA) Output_Test_YK.YkCommand = 0x01; //分执行
- else if(Seq == 0xcc) Output_Test_YK.YkCommand = 0xC1; //分命令撤销
- else Output_Test_YK.YkCommand = 0x00; //未知
- }
- }
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
- // 通信命令处理
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
- int MMI_DSP_Instruction(unsigned int Command,unsigned int per1,unsigned int per2)
- {
- int Res;
- Res = 1;
- switch( Command )
- {
- case 0x0000: //复位CU/FCB
- Order_Array.Order[ Order_Array.Set ] = 0x0000;
- Order_Array.Set = (Order_Array.Set+1)%10;
- break;
- case 0x0100: //总召唤
- Order_Array.Order[ Order_Array.Set ] = 0x0100;
- Order_Array.Set = (Order_Array.Set+1)%10;
- break;
- case 0x0200: //对时
- Order_Array.Order[ Order_Array.Set ] = 0x0200;
- Order_Array.Set = (Order_Array.Set+1)%10;
- break;
- case 0x0210: //修改时间
- Order_Array.Order[ Order_Array.Set ] = 0x0210;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.Check_Time_Flag = 0xAA;
- command_statue.Check_Time_Count = 0;
- break;
- case 0x0500: //读系统参数
- Order_Array.Order[ Order_Array.Set ] = 0x0500;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.Config_Operation_Flag = 0xaa;
- command_statue.Config_Operation_Count = 0;
- break;
- case 0x0600: //读定值
- comm_buf_flag->DzAreaNo = per1 + 0x17;
- Order_Array.Order[ Order_Array.Set ] = 0x0600;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.Setting_Operation_Flag = 0xaa;
- command_statue.Setting_Operation_Count = 0;
- break;
- case 0x0700: //自动调整通道系数
- Channel_Ration_Flag.Command = per1&0xff;
- Order_Array.Order[ Order_Array.Set ] = 0x0700;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.Channel_Ration_Flag = 0xaa;
- command_statue.Channel_Ration_Count = 0x00;
- break;
- case 0x0800: //定值预修改
- comm_buf_flag->DzSelect = 0x00;
- comm_buf_flag->DzAreaNo = per1+0x17;
- Order_Array.Order[ Order_Array.Set ] = 0x0800;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.Setting_Operation_Flag = 0xaa;
- command_statue.Setting_Operation_Count = 0;
- break;
- case 0x0900: //定值修改执行
- if(comm_buf_flag->DzSelect == 0x11)
- {
- comm_buf_flag->DzAreaNo = per1+0x17;
- Order_Array.Order[ Order_Array.Set ] = 0x0900;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.Setting_Operation_Flag = 0xaa;
- command_statue.Setting_Operation_Count = 0;
- }
- else
- Res = 0;
- break;
- case 0x0a00: //定值区号切换选择
- Setting_Switch.DzSelect = 0x00;
- Setting_Switch.DzCommand = 0x82;
- Setting_Switch.DzTarget = per1+0x17;
- Order_Array.Order[ Order_Array.Set ] = 0x0a00;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.Setting_Operation_Flag = 0xaa;
- command_statue.Setting_Operation_Count = 0;
- break;
- case 0x0a01: //定值区号切换执行
- if(Setting_Switch.DzSelect == 0x11)
- {
- Setting_Switch.DzCommand = 0x02;
- Setting_Switch.DzTarget = per1+0x17;
- Order_Array.Order[ Order_Array.Set ] = 0x0a00;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.Setting_Operation_Flag = 0xaa;
- command_statue.Setting_Operation_Count = 0;
- }
- else
- Res = 0;
- break;
- case 0x0a02: //定值区号切换撤销
- if(Setting_Switch.DzSelect == 0x11)
- {
- Setting_Switch.DzCommand = 0xc2;
- Setting_Switch.DzTarget = per1+0x17;
- Order_Array.Order[ Order_Array.Set ] = 0x0a00;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.Setting_Operation_Flag = 0xaa;
- command_statue.Setting_Operation_Count = 0;
- }
- else
- Res = 0;
- break;
- case 0x0b00: //定值区复制选择
- Setting_Copy.DzSelect = 0x00;
- Setting_Copy.DzSource = per2+0x17;
- Setting_Copy.DzTarget = per1+0x17;
- Setting_Copy.DzCommand = 0x82;
- Order_Array.Order[ Order_Array.Set ] = 0x0b00;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.Setting_Operation_Flag = 0xaa;
- command_statue.Setting_Operation_Count = 0;
- break;
- case 0x0b01: //定值区复制执行
- if(Setting_Copy.DzSelect == 0x11)
- {
- Setting_Copy.DzSource = per2+0x17;
- Setting_Copy.DzTarget = per1+0x17;
- Setting_Copy.DzCommand = 0x02;
- Order_Array.Order[ Order_Array.Set ] = 0x0b00;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.Setting_Operation_Flag = 0xaa;
- command_statue.Setting_Operation_Count = 0;
- }
- else
- Res = 0;
- break;
- case 0x0b02: //定值区复制撤销
- if(Setting_Copy.DzSelect == 0x11)
- {
- Setting_Copy.DzSource = per2+0x17;
- Setting_Copy.DzTarget = per1+0x17;
- Setting_Copy.DzCommand = 0xc2;
- Order_Array.Order[ Order_Array.Set ] = 0x0b00;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.Setting_Operation_Flag = 0xaa;
- command_statue.Setting_Operation_Count = 0;
- }
- else
- Res = 0;
- break;
- case 0x0c00: //系统配置修改选择
- Order_Array.Order[ Order_Array.Set ] = 0x0c00;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.Config_Operation_Flag = 0xaa;
- command_statue.Config_Operation_Count = 0;
- break;
- case 0x0d00: //系统配置修改执行
- Order_Array.Order[ Order_Array.Set ] = 0x0d00;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.Config_Operation_Flag = 0xaa;
- command_statue.Config_Operation_Count = 0;
- break;
- case 0x0e00: //通道系数调整选择
- Channel_Ration_Flag.Select = 0x00;
- Channel_Ration_Flag.Command = per1&0xff;
- Order_Array.Order[ Order_Array.Set ] = 0x0e00;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.Channel_Ration_Flag = 0xaa;
- command_statue.Channel_Ration_Count = 0x00;
- break;
- case 0x0e01: //通道系数调整执行
- if(Channel_Ration_Flag.Select == 0x11)
- {
- Channel_Ration_Flag.Command = per1&0xff;
- Order_Array.Order[ Order_Array.Set ] = 0x0e00;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.Channel_Ration_Flag = 0xaa;
- command_statue.Channel_Ration_Count = 0x00;
- }
- else
- Res = 0;
- break;
- case 0x0e02: //通道系数调整撤销
- if(Channel_Ration_Flag.Select == 0x11)
- {
- Channel_Ration_Flag.Command = per1&0xff;
- Order_Array.Order[ Order_Array.Set ] = 0x0e00;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.Channel_Ration_Flag = 0xaa;
- command_statue.Channel_Ration_Count = 0x00;
- }
- else
- Res = 0;
- break;
- case 0x0f00: //软压板操作选择
- YYB_Modify_Flag.Select = 0x00;
- YYB_Modify_Flag.Command = 0x82;
- YYB_Modify_Flag.YYB_temp = per1&0xffffffff;
- Order_Array.Order[ Order_Array.Set ] = 0x0f00;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.YYB_Opreation_Flag = 0xaa;
- command_statue.YYB_Opreation_Count = 0x00;
- break;
- case 0x0f01: //软压板操作执行
- if(YYB_Modify_Flag.Select == 0x11)
- {
- YYB_Modify_Flag.Command = 0x02;
- YYB_Modify_Flag.YYB_temp = per1&0xffffffff;
- Order_Array.Order[ Order_Array.Set ] = 0x0f00;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.YYB_Opreation_Flag = 0xaa;
- command_statue.YYB_Opreation_Count = 0x00;
- }
- else
- Res = 0;
- break;
- case 0x0f02: //软压板操作撤销
- if(YYB_Modify_Flag.Select == 0x11)
- {
- YYB_Modify_Flag.Command = 0xc2;
- YYB_Modify_Flag.YYB_temp = per1&0xffffffff;
- Order_Array.Order[ Order_Array.Set ] = 0x0f00;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.YYB_Opreation_Flag = 0xaa;
- command_statue.YYB_Opreation_Count = 0x00;
- }
- else
- Res = 0;
- break;
- case 0x1000: //修改密码
- Order_Array.Order[ Order_Array.Set ] = 0x1000;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.Password_Modified_Flag = 0xaa;
- command_statue.Password_Modified_Count = 0;
- break;
- case 0x1100: //开出传动选择
- YK_Command_Style(per1,0x11,0x55);
- Output_Test_YK.YkSelect = 0;
- Order_Array.Order[ Order_Array.Set ] = 0x1100;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.YK_Output_Command_Flag = 0xaa;
- command_statue.YK_Output_Command_Count = 0;
- break;
- case 0x1101: //开出传动执行
- if(Output_Test_YK.YkSelect == 0x11)
- {
- YK_Command_Style(per1,0x11,0xAA);
- Output_Test_YK.YkSelect = 0;
- Order_Array.Order[ Order_Array.Set ] = 0x1100;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.YK_Output_Command_Flag = 0xaa;
- command_statue.YK_Output_Command_Count = 0;
- }
- else
- Res = 0;
- break;
- case 0x1102: //开出传动撤销
- if(Output_Test_YK.YkSelect == 0x11)
- {
- YK_Command_Style(per1,0x11,0xcc);
- Output_Test_YK.YkSelect = 0;
- Order_Array.Order[ Order_Array.Set ] = 0x1100;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.YK_Output_Command_Flag = 0xaa;
- command_statue.YK_Output_Command_Count = 0;
- }
- else
- Res = 0;
- break;
- case 0x1110: //遥控合选择
- YK_Command_Style(per1,0x11,0x55);
- Output_Test_YK.YkSelect = 0;
- Order_Array.Order[ Order_Array.Set ] = 0x1100;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.YK_Output_Command_Flag = 0xaa;
- command_statue.YK_Output_Command_Count = 0;
- break;
- case 0x1111: //遥控合执行
- if(Output_Test_YK.YkSelect == 0x11)
- {
- YK_Command_Style(per1,0x11,0xaa);
- Output_Test_YK.YkSelect = 0;
- Order_Array.Order[ Order_Array.Set ] = 0x1100;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.YK_Output_Command_Flag = 0xaa;
- command_statue.YK_Output_Command_Count = 0;
- }
- else
- Res = 0;
- break;
- case 0x1112: //遥控合撤销
- if(Output_Test_YK.YkSelect == 0x11)
- {
- YK_Command_Style(per1,0x11,0xcc);
- Output_Test_YK.YkSelect = 0;
- Order_Array.Order[ Order_Array.Set ] = 0x1100;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.YK_Output_Command_Flag = 0xaa;
- command_statue.YK_Output_Command_Count = 0;
- }
- else
- Res = 0;
- break;
- case 0x1120: //遥控分选择
- YK_Command_Style(per1,0x22,0x55);
- Output_Test_YK.YkSelect = 0;
- Order_Array.Order[ Order_Array.Set ] = 0x1100;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.YK_Output_Command_Flag = 0xaa;
- command_statue.YK_Output_Command_Count = 0;
- break;
- case 0x1121: //遥控分执行
- if(Output_Test_YK.YkSelect == 0x11)
- {
- YK_Command_Style(per1,0x22,0xaa);
- Output_Test_YK.YkSelect = 0;
- Order_Array.Order[ Order_Array.Set ] = 0x1100;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.YK_Output_Command_Flag = 0xaa;
- command_statue.YK_Output_Command_Count = 0;
- }
- else
- Res = 0;
- break;
- case 0x1122: //遥控分撤销
- if(Output_Test_YK.YkSelect == 0x11)
- {
- YK_Command_Style(per1,0x22,0xcc);
- Output_Test_YK.YkSelect = 0;
- Order_Array.Order[ Order_Array.Set ] = 0x1100;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.YK_Output_Command_Flag = 0xaa;
- command_statue.YK_Output_Command_Count = 0;
- }
- else
- Res = 0;
- break;
- case 0x1200: //查询SOE及故障报告
- Fault_Recode_Flag.Number = per1;
- Fault_Recode_Flag.Type = per2;
- Order_Array.Order[ Order_Array.Set ] = 0x1200;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.Demand_Soe_Report_Flag = 0xaa;
- command_statue.Demand_Soe_Report_Count = 0x00;
- break;
- case 0x1300: //装置复归
- Order_Array.Order[ Order_Array.Set ] = 0x1300;
- Order_Array.Set = (Order_Array.Set+1)%10;
- command_statue.Device_FUGUI_Flag = 0xaa;
- command_statue.Device_FUGUI_Count = 0x00;
- break;
- case 0x1500: //装置复归
- Order_Array.Order[ Order_Array.Set ] = 0x1500;
- Order_Array.Set = (Order_Array.Set+1)%10;
- break;
- default:
- break;
- }
- return(Res);
- }
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
- // 组装并发送固定帧
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
- void SendFixFrm(UC SFunCode)
- {
- int i;
- comm_buf_flag->Sendbuf[0] = 0x10;
- comm_buf_flag->Sendbuf[1] = (SFunCode & 0x0F) + (comm_buf_flag->FCB& 0x20)
- + (comm_buf_flag->FCV& 0x10) + 0x40;
- comm_buf_flag->Sendbuf[2] = comm_buf_flag->DeviceAddr;
- comm_buf_flag->Sendbuf[3] = comm_buf_flag->Sendbuf[1] + comm_buf_flag->Sendbuf[2];
- comm_buf_flag->Sendbuf[4] = 0x16;
- comm_buf_flag->Length = 5;
- ComSend();
- for(i=0;i<comm_buf_flag->Length;i++)
- comm_buf_flag->TempBuf[i] = comm_buf_flag->Sendbuf[i];
- comm_buf_flag->FCB = comm_buf_flag->FCB^0x20;
- }
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
- // 组装并发送可变帧
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
- void SendValFrm(UC SFunCode, UC len )
- {
- int i;
- comm_buf_flag->Sendbuf[0] = comm_buf_flag->Sendbuf[3] = 0x68;
- comm_buf_flag->Sendbuf[1] = len+2;
- comm_buf_flag->Sendbuf[2] = comm_buf_flag->Sendbuf[1];
- comm_buf_flag->Sendbuf[4] = (SFunCode & 0x0F) + (comm_buf_flag->FCB& 0x20)
- + (comm_buf_flag->FCV& 0x10) + 0x40;
- comm_buf_flag->Sendbuf[5] = comm_buf_flag->DeviceAddr;
- comm_buf_flag->Sendbuf[6+len] = comm_buf_flag->Sendbuf[4] + comm_buf_flag->Sendbuf[5] ;
- for(i=0; i<len; i++)
- {
- comm_buf_flag->Sendbuf[6+len] = comm_buf_flag->Sendbuf[6+len] + comm_buf_flag->Sendbuf[6+i];
- }
- comm_buf_flag->Sendbuf[7+len] = 0x16;
- comm_buf_flag->Length = 8+len;
- ComSend();
- for(i=0;i<comm_buf_flag->Length;i++)
- comm_buf_flag->TempBuf[i] = comm_buf_flag->Sendbuf[i];
- comm_buf_flag->FCB = comm_buf_flag->FCB^0x20;
- }
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
- // 链路层通信处理
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
- void LPDU_MMI_DSP_Send(void)
- {
- if(comm_buf_flag->Timing >= DELAYACK)
- {
- comm_buf_flag->Timing = 0;
- if(comm_buf_flag->Counter>=6)
- {
- comm_buf_flag->Counter = 6;
- comm_buf_flag->LPDU_Command = 0x09;
- ComDsp_buf_flag.CommError = 0x11;
- }
- else if( comm_buf_flag->ACD == 0x20 )
- comm_buf_flag->LPDU_Command = 0x0a;
- else if( comm_buf_flag->LPDU_Command == 0x0b )
- {
- if( Order_Array.Set != Order_Array.Get) //有其他命令
- {
- comm_buf_flag->SendSeq = Order_Array.Order[Order_Array.Get];
- Order_Array.Order[Order_Array.Get] = 0xFF00;
- Order_Array.Get=(Order_Array.Get+1)%10;
- ProcessMMI_DSP();
- }
- }
- switch( comm_buf_flag->LPDU_Command )
- {
- case 0x00: comm_buf_flag->FCV = 0;
- SendFixFrm( 0x00 );
- break;
- case 0x03: comm_buf_flag->FCV = 1;
- SendValFrm( 0x03,comm_buf_flag->ASDU_Length );
- break;
- case 0x04: comm_buf_flag->FCV = 0;
- SendValFrm( 0x04,comm_buf_flag->ASDU_Length );
- break;
- case 0x07: comm_buf_flag->FCV = 0;
- SendFixFrm( 0x07 );
- break;
- case 0x09: comm_buf_flag->FCV = 0;
- SendFixFrm( 0x09 );
- break;
- case 0x0a: comm_buf_flag->FCV = 1;
- SendFixFrm( 0x0a );
- comm_buf_flag->LPDU_Command = 0x0b;
- break;
- case 0x0b: comm_buf_flag->FCV = 1;
- SendFixFrm( 0x0b );
- break;
- default: comm_buf_flag->LPDU_Command = 9;
- break;
- }
- comm_buf_flag->Timing = 0;
- comm_buf_flag->Counter++;
- }
- }
- void LPDU_MMI_DSP_Recv(void)
- {
- int i;
- if( comm_buf_flag->FrameRecv == 0x15)
- {
- comm_buf_flag->FrameRecv = 0;
- ComDsp_buf_flag.CommError = 0x00;
- comm_buf_flag->Counter = 0;
- comm_buf_flag->ACD = (comm_buf_flag->RecvBuf[1]&0x20);
- switch( comm_buf_flag->RecvBuf[1]&0x0f)
- {
- case 0x00:
- if( comm_buf_flag->LPDU_Command == 0x03)
- {
- comm_buf_flag->LPDU_Command = 0x0b;
- comm_buf_flag->Counter = 0;
- }
- break;
- case 0x01:
- break;
- case 0x09: comm_buf_flag->LPDU_Command = 0x0b;
- break;
- case 0x0b:
- break;
- default:
- break;
- }
- if(PC_Comm_Flag == 0x00)
- {
- Comm0.SendBuf[Comm0.SendSet] = comm_buf_flag->Sendbuf[i];
- Comm0.SendSet = (Comm0.SendSet+1)%SENDNUM;
- }
- }
- else if( comm_buf_flag->FrameRecv == 0x1a)
- {
- comm_buf_flag->FrameRecv = 0;
- ComDsp_buf_flag.CommError = 0x00;
- comm_buf_flag->Counter = 0;
- comm_buf_flag->ACD = (comm_buf_flag->RecvBuf[4]&0x20);
- switch( comm_buf_flag->RecvBuf[4]&0x0f)
- {
- case 0x08: ASDU_Analyze();
- break;
- default:
- break;
- }
- }
- }
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
- // MMI和DSP通信处理
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
- void ProcessMMI_DSP(void)
- {
- switch(comm_buf_flag->SendSeq>>8) //发送处理
- {
- case 0x01: //总召唤
- Call_WholeData();
- break;
- case 0x02: //对时
- Check_Time();
- break;
- case 0x05: //读系统参数
- Read_SystemConfig();
- break;
- case 0x06: //读定值
- Read_SystemSetting();
- break;
- case 0x07: //自动调整通道系数
- Auto_Adjust_Ration();
- break;
- case 0x08: //定值预修改
- Setting_PreModify();
- break;
- case 0x09: //定值修改执行
- Setting_Modified_Exe();
- break;
- case 0x0a: //定值区号切换
- Setting_Area_Switch();
- break;
- case 0x0b: //定值区复制
- Setting_Area_Copy();
- break;
- case 0x0c: //系统配置修改选择
- Config_PreModify();
- break;
- case 0x0d: //系统配置修改执行
- Config_Modified_Exe();
- break;
- case 0x0e: //通道系数调整
- Modify_Channel_Ration();
- break;
- case 0x0f: //软压板操作
- YYB_Opreation();
- break;
- case 0x10: //修改密码
- Password_Modified_Exe();
- break;
- case 0x11: //遥控及开出传动
- YK_Output_Command();
- break;
- case 0x12: //查询SOE及故障报告
- Demand_Soe_Report();
- break;
- case 0x13: //装置复归
- Device_FUGUI();
- break;
- default:
- comm_buf_flag->SendSeq = 0x0300;
- break;
- }
- }
- //-------------------------------------------------------
- // 总召唤
- //-------------------------------------------------------
- void Call_WholeData(void)
- {
- ASDU_07_Send();
- }
- //-------------------------------------------------------
- // 对时命令
- //-------------------------------------------------------
- void Check_Time(void)
- {
- if(comm_buf_flag->SendSeq==0x0200)
- ASDU_06_Send0();
- else
- ASDU_06_Send1();
- }
- //-----------------------------------------------------------
- // 读系统配置
- //-----------------------------------------------------------
- void Read_SystemConfig(void)
- {
- ASDU_21_Send0(0x16); //ASDU_10_Send0();
- }
- //-----------------------------------------------------------
- // 读定值
- //-----------------------------------------------------------
- void Read_SystemSetting(void)
- {
- ASDU_21_Send0(comm_buf_flag->DzAreaNo);
- }
- //-----------------------------------------------------------
- // 自动调整通道系数
- //-----------------------------------------------------------
- void Auto_Adjust_Ration(void)
- {
- ASDU_20_Send7();
- }
- //-----------------------------------------------------------
- // 通道系数调整
- //-----------------------------------------------------------
- void Modify_Channel_Ration(void)
- {
- ASDU_20_Send8();
- }
- //-----------------------------------------------------------
- // 定值预修改
- //-----------------------------------------------------------
- void Setting_PreModify(void)
- {
- ASDU_10_Send2(0x11);
- }
- //-----------------------------------------------------------
- // 定值修改执行
- //-----------------------------------------------------------
- void Setting_Modified_Exe(void)
- {
- ASDU_10_Send2(0x22);
- }
- //-----------------------------------------------------------
- // 定值区号切换
- //-----------------------------------------------------------
- void Setting_Area_Switch(void)
- {
- ASDU_20_Send0();
- }
- //-----------------------------------------------------------
- // 软压板操作
- //-----------------------------------------------------------
- void YYB_Opreation(void)
- {
- ASDU_20_Send4();
- }
- //-----------------------------------------------------------
- // 定值区复制
- //-----------------------------------------------------------
- void Setting_Area_Copy(void)
- {
- ASDU_20_Send1();
- }
- //-----------------------------------------------------------
- // 系统配置预修改
- //-----------------------------------------------------------
- void Config_PreModify(void)
- {
- ASDU_10_Send3(0x11);
- }
- //-----------------------------------------------------------
- // 系统配置修改执行
- //-----------------------------------------------------------
- void Config_Modified_Exe(void)
- {
- ASDU_10_Send3(0x22);
- }
- //-----------------------------------------------------------
- // 修改密码
- //-----------------------------------------------------------
- void Password_Modified_Exe(void)
- {
- ASDU_05_Send1();
- }
- //-----------------------------------------------------------
- // 遥控/开出传动
- //-----------------------------------------------------------
- void YK_Output_Command(void)
- {
- ASDU_64_Send0(); //ASDU_20_Send2();
- }
- //-----------------------------------------------------------
- // 查询SOE及故障报告
- //-----------------------------------------------------------
- void Demand_Soe_Report(void)
- {
- ASDU_20_Send5();
- }
- //-----------------------------------------------------------
- // 装置复归
- //-----------------------------------------------------------
- void Device_FUGUI(void)
- {
- ASDU_20_Send3();
- }
- //-----------------------------------------------------------
- // ASDU1(SOE)
- //-----------------------------------------------------------
- void ADSU_01_Analyze(void)
- {
- switch(comm_buf_flag->RecvBuf[11])
- {
- case 0x17:
- case 0x18:
- case 0x19:
- case 0x1a:
- if(comm_buf_flag->RecvBuf[11]==Setting_Switch.DzTarget )
- {
- if( comm_buf_flag->RecvBuf[12]==0x82) //定值预切换
- {
- //Memo1->Lines->Add("================定值预切换================");
- Setting_Switch.DzSelect = 0x11;
- command_statue.Setting_Operation_Flag = 0x00;
- }
- if( comm_buf_flag->RecvBuf[12]==0xc2) //定值切换
- {
- // Memo1->Lines->Add("===============定值切换撤销===============");
- command_statue.Setting_Operation_Flag = 0x00;
- }
- if( comm_buf_flag->RecvBuf[12]==0x02) //定值切换
- {
- command_statue.Setting_Operation_Flag = 0x00;
- // Memo1->Lines->Add("===============定值切换成功===============");
- }
- }
- break;
- case 0x16:
- if(( comm_buf_flag->RecvBuf[18]==Setting_Copy.DzSource) && (comm_buf_flag->RecvBuf[19]==Setting_Copy.DzTarget ))
- {
- if( comm_buf_flag->RecvBuf[12]==0x82 ) //定值预复制成功
- {
- //Memo1->Lines->Add("================定值预复制================");
- Setting_Copy.DzSelect = 0x11;
- command_statue.Setting_Operation_Flag = 0x00;
- }
- if( comm_buf_flag->RecvBuf[12]==0xc2 ) //定值复制撤销
- {
- command_statue.Setting_Operation_Flag = 0x00;
- // Memo1->Lines->Add("================定值复制撤销================");
- }
- if( comm_buf_flag->RecvBuf[12]==0x02 ) //定值复制成功
- {
- command_statue.Setting_Operation_Flag = 0x00;
- // Memo1->Lines->Add("================定值复制成功================");
- }
- }
- break;
- default://故障报告
- break;
- }
- SOE_Buf_Show0.msec = (comm_buf_flag->RecvBuf[14]*256 + comm_buf_flag->RecvBuf[13])%1000;
- SOE_Buf_Show0.sec = (US)((comm_buf_flag->RecvBuf[14]*256 + comm_buf_flag->RecvBuf[13])/1000);
- SOE_Buf_Show0.min = comm_buf_flag->RecvBuf[15]; //min
- SOE_Buf_Show0.hour = comm_buf_flag->RecvBuf[16]; //hour
- SOE_Buf_Show0.day = comm_buf_flag->RecvBuf[17]; //day
- SOE_Buf_Show0.mon = comm_buf_flag->RecvBuf[18]; //mon
- SOE_Buf_Show0.year = comm_buf_flag->RecvBuf[19]; //year
- SOE_Buf_Show0.num = comm_buf_flag->RecvBuf[11]; //NO.
- SOE_Buf_Show0.stu = comm_buf_flag->RecvBuf[12];
- if(comm_buf_flag->RecvBuf[8]==0x01)
- New_Information_Flag = 1; //20r1
- command_statue.Demand_Soe_Report_Flag = 0x00;
- }
- //-----------------------------------------------------------
- // ASDU5
- //-----------------------------------------------------------
- void ASDU_05_Send1(void) //修改密码
- {
- comm_buf_flag->Sendbuf[6]=0x05;
- comm_buf_flag->Sendbuf[7]=0x81;
- comm_buf_flag->Sendbuf[8]=0x66;
- comm_buf_flag->Sendbuf[9]=comm_buf_flag->DeviceAddr;
- comm_buf_flag->Sendbuf[10]=FUNTYPE;
- comm_buf_flag->Sendbuf[11]=0xff;
- comm_buf_flag->Sendbuf[12]=0x66;
- comm_buf_flag->Sendbuf[13]=(unsigned char )(System_Info.Password10&0xff);
- comm_buf_flag->Sendbuf[14]=(unsigned char )((System_Info.Password10>>8)&0xff);
- comm_buf_flag->Sendbuf[15]=(unsigned char )((System_Info.Password10>>16)&0xff);
- comm_buf_flag->Sendbuf[16]=(unsigned char )(System_Info.Password20&0xff);
- comm_buf_flag->Sendbuf[17]=(unsigned char )((System_Info.Password20>>8)&0xff);
- comm_buf_flag->Sendbuf[18]=(unsigned char )((System_Info.Password20>>16)&0xff);
- comm_buf_flag->Sendbuf[19]=0xfe;
- comm_buf_flag->FunctionCode = 3; //功能码
- comm_buf_flag->LPDU_Command = 3;
- comm_buf_flag->ASDU_Length = 14;
- }
- void ASDU_05_Analyze(void)
- {
- switch(comm_buf_flag->Sendbuf[12])
- {
- case 0x66: //密码修改成功
- command_statue.Password_Modified_Flag = 0x00;
- break;
- default:
- SoftInformation.Model[0] = comm_buf_flag->RecvBuf[13];
- SoftInformation.Model[1] = comm_buf_flag->RecvBuf[14];
- SoftInformation.Model[2] = comm_buf_flag->RecvBuf[15];
- SoftInformation.Model[3] = comm_buf_flag->RecvBuf[16];
- SoftInformation.Model[4] = comm_buf_flag->RecvBuf[17];
- SoftInformation.Model[5] = comm_buf_flag->RecvBuf[18];
- SoftInformation.Model[6] = comm_buf_flag->RecvBuf[19];
- SoftInformation.Year = comm_buf_flag->RecvBuf[20];
- SoftInformation.Month= comm_buf_flag->RecvBuf[21];
- SoftInformation.Day = comm_buf_flag->RecvBuf[22];
- SoftInformation.Ver[0] = comm_buf_flag->RecvBuf[23]+0x30;
- SoftInformation.Ver[1] = 0x2e;
- SoftInformation.Ver[2] = comm_buf_flag->RecvBuf[25]+0x30;
- break;
- }
- }
- //-----------------------------------------------------------
- // ASDU6(对时)
- //-----------------------------------------------------------
- void ASDU_06_Send0(void)
- {
- comm_buf_flag->Sendbuf[6] = 0x06;
- comm_buf_flag->Sendbuf[7] = 0x81;
- comm_buf_flag->Sendbuf[8] = 0x88; //传输原因 08-对时 88-修改
- comm_buf_flag->Sendbuf[9] = comm_buf_flag->DeviceAddr;
- comm_buf_flag->Sendbuf[10]= FUNTYPE;
- comm_buf_flag->Sendbuf[11]= 0x00;
- comm_buf_flag->Sendbuf[12]= realtime.msecond & 0xff; //msl
- comm_buf_flag->Sendbuf[13]= (realtime.msecond & 0xff00)>>8; //msh
- comm_buf_flag->Sendbuf[14]= realtime.minute; //minutes
- comm_buf_flag->Sendbuf[15]= realtime.hour; //hours
- comm_buf_flag->Sendbuf[16]= realtime.day; //date
- comm_buf_flag->Sendbuf[17]= realtime.month; //months
- comm_buf_flag->Sendbuf[18]= realtime.year; //years
- comm_buf_flag->FunctionCode = 3; //功能码
- comm_buf_flag->LPDU_Command = 3;
- comm_buf_flag->ASDU_Length = 13;
- comm_buf_flag->Flag_CheckTime = 0x00;
- }
- void ASDU_06_Send1(void)
- {
- comm_buf_flag->Sendbuf[6] = 0x06;
- comm_buf_flag->Sendbuf[7] = 0x81;
- comm_buf_flag->Sendbuf[8] = 0x08; //传输原因 08-对时 88-修改
- comm_buf_flag->Sendbuf[9] = comm_buf_flag->DeviceAddr;
- comm_buf_flag->Sendbuf[10]= 0xff;
- comm_buf_flag->Sendbuf[11]= 0x00;
- comm_buf_flag->Sendbuf[12]= realtime1.msecond & 0xff; //msl
- comm_buf_flag->Sendbuf[13]= (realtime1.msecond & 0xff00)>>8; //msh
- comm_buf_flag->Sendbuf[14]= realtime1.minute; //minutes
- comm_buf_flag->Sendbuf[15]= realtime1.hour; //hours
- comm_buf_flag->Sendbuf[16]= realtime1.day; //date
- comm_buf_flag->Sendbuf[17]= realtime1.month; //months
- comm_buf_flag->Sendbuf[18]= realtime1.year; //years
- comm_buf_flag->FunctionCode = 3; //功能码
- comm_buf_flag->LPDU_Command = 3;
- comm_buf_flag->ASDU_Length = 13;
- //SendValFrm( 0x03, 13 );
- }
- void ASDU_06_Analyze(void)
- {
- realtime.year = comm_buf_flag->RecvBuf[18]; //YEAR
- realtime.month = comm_buf_flag->RecvBuf[17]; //MONTH
- realtime.day = comm_buf_flag->RecvBuf[16]; //DATE
- realtime.hour = comm_buf_flag->RecvBuf[15]; //HOUR
- realtime.minute = comm_buf_flag->RecvBuf[14]; //MIN
- realtime.msecond = (comm_buf_flag->RecvBuf[13]<<8) + comm_buf_flag->RecvBuf[12];
- command_statue.Check_Time_Flag = 0x00;
- }
- //------------------------------------------------------------
- // ASDU7(总查询发送)
- //------------------------------------------------------------
- void ASDU_07_Send(void)
- {
- comm_buf_flag->Sendbuf[6]=0x07;
- comm_buf_flag->Sendbuf[7]=0x81;
- comm_buf_flag->Sendbuf[8]=0x09;
- comm_buf_flag->Sendbuf[9]=comm_buf_flag->DeviceAddr;
- comm_buf_flag->Sendbuf[10]=0xff;
- comm_buf_flag->Sendbuf[11]=0x00;
- comm_buf_flag->Sendbuf[12]=0x00;
- comm_buf_flag->FunctionCode = 3; //功能码
- comm_buf_flag->LPDU_Command = 3;
- comm_buf_flag->ASDU_Length = 7;
- //SendValFrm( 0x03, 7 );
- comm_buf_flag->Flag_CallAll = 0;
- }
- //-----------------------------------------------------------
- // 定值操作
- //-----------------------------------------------------------
- ////////////////////////////////////////////////////////////////////////////////
- void ASDU_10_Send2(unsigned char Type) //下传定值
- {
- unsigned int i,j=0;
- comm_buf_flag->Sendbuf[6] = 0x0a;
- comm_buf_flag->Sendbuf[7] = 0x81;
- comm_buf_flag->Sendbuf[8] = 40;
- comm_buf_flag->Sendbuf[9] = comm_buf_flag->DeviceAddr;;
- comm_buf_flag->Sendbuf[10]= 254;
- comm_buf_flag->Sendbuf[12]= 0x00; //
- comm_buf_flag->Sendbuf[13]= 0x01;
- comm_buf_flag->Sendbuf[14]= comm_buf_flag->DzAreaNo;
- comm_buf_flag->Sendbuf[15]= 0x00;
- comm_buf_flag->Sendbuf[16]= 0x01;
- comm_buf_flag->Sendbuf[17]= 0x03;
- comm_buf_flag->Sendbuf[18]= 0x02;
- comm_buf_flag->Sendbuf[19]= Setting_Total+1;
- if(Type == 0x11)
- {
- comm_buf_flag->Sendbuf[11]= 249; //预修改
- for(i=0;i<Setting_Total;i++)
- {
- comm_buf_flag->Sendbuf[j + 20] = (unsigned char)(~System_setting[ i ]&0xff);
- comm_buf_flag->Sendbuf[j + 21] = (unsigned char)((~System_setting[ i ]>>8)&0xff);
- j++;
- j++;
- }
- comm_buf_flag->Sendbuf[j+20]= (unsigned char)(~(System_Info.DZ_Area+0x17));
- comm_buf_flag->Sendbuf[j+21]= 0xff;
- }
- else
- {
- if(Type == 0x22)
- comm_buf_flag->Sendbuf[11]= 250; //修改
- else
- comm_buf_flag->Sendbuf[11]= 251; //未知
- for(i=0;i<Setting_Total;i++)
- {
- comm_buf_flag->Sendbuf[j + 20] = (unsigned char)(System_setting[ i ]&0xff);
- comm_buf_flag->Sendbuf[j + 21] = (unsigned char)((System_setting[ i ]>>8)&0xff);
- j++;
- j++;
- }
- comm_buf_flag->Sendbuf[j+20]= (unsigned char)(System_Info.DZ_Area+0x17);
- comm_buf_flag->Sendbuf[j+21]= 0x00;
- }
- comm_buf_flag->FunctionCode = 3; //功能码
- comm_buf_flag->LPDU_Command = 3;
- comm_buf_flag->ASDU_Length = j + 16;
- //SendValFrm( 0x03, 80 );
- }
- void ASDU_10_Send3(unsigned char Type) //下传配置
- {
- unsigned int i,j=0;
- comm_buf_flag->Sendbuf[6] = 0x0a;
- comm_buf_flag->Sendbuf[7] = 0x81;
- comm_buf_flag->Sendbuf[8] = 40;
- comm_buf_flag->Sendbuf[9] = comm_buf_flag->DeviceAddr;;
- comm_buf_flag->Sendbuf[10]= 254;
- comm_buf_flag->Sendbuf[12]= 0x00; //
- comm_buf_flag->Sendbuf[13]= 0x01;
- comm_buf_flag->Sendbuf[14]= 0x16;
- comm_buf_flag->Sendbuf[15]= 0x00;
- comm_buf_flag->Sendbuf[16]= 0x01;
- comm_buf_flag->Sendbuf[17]= 0x03;
- comm_buf_flag->Sendbuf[18]= 0x02;
- comm_buf_flag->Sendbuf[19]= Sys_Cfg_Total+1;
- if(Type == 0x11)
- {
- comm_buf_flag->Sendbuf[11]= 249; //预修改
- for(i=0;i<Sys_Cfg_Total;i++)
- {
- comm_buf_flag->Sendbuf[j + 20] = (unsigned char)(~System_config[ i ]&0xff);
- comm_buf_flag->Sendbuf[j + 21] = (unsigned char)((~System_config[ i ]>>8)&0xff);
- j++;
- j++;
- }
- comm_buf_flag->Sendbuf[j+20]= 0xe9;
- comm_buf_flag->Sendbuf[j+21]= 0xff;
- }
- else
- {
- if(Type == 0x22)
- comm_buf_flag->Sendbuf[11]= 250; //修改
- else
- comm_buf_flag->Sendbuf[11]= 251; //未知
- for(i=0;i<Sys_Cfg_Total;i++)
- {
- comm_buf_flag->Sendbuf[j + 20] = (unsigned char)(System_config[ i ]&0xff);
- comm_buf_flag->Sendbuf[j + 21] = (unsigned char)((System_config[ i ]>>8)&0xff);
- j++;
- j++;
- }
- comm_buf_flag->Sendbuf[j+20]= 0x16;
- comm_buf_flag->Sendbuf[j+21]= 0x00;
- }
- comm_buf_flag->FunctionCode = 3; //功能码
- comm_buf_flag->LPDU_Command = 3;
- comm_buf_flag->ASDU_Length = j + 16;
- //SendValFrm( 0x03, 102 );
- }
- void ASDU_10_Analyze(void)
- {
- unsigned int i;
- if(comm_buf_flag->RecvBuf[14]==0x16 && comm_buf_flag->RecvBuf[11]==241 && comm_buf_flag->RecvBuf[8]==42) //读系统参数
- {
- for(i=0;i<Sys_Cfg_Total;i++)
- System_config[i] = comm_buf_flag->RecvBuf[20+2*i]+(comm_buf_flag->RecvBuf[21+2*i]<<8);
- command_statue.Config_Operation_Flag = 0x00;
- }
- else if(comm_buf_flag->RecvBuf[14]==comm_buf_flag->DzAreaNo && comm_buf_flag->RecvBuf[11]==241 && comm_buf_flag->RecvBuf[8]==42)
- {
- for(i=0;i<Setting_Total;i++)
- System_setting[i] = comm_buf_flag->RecvBuf[20+2*i]+(comm_buf_flag->RecvBuf[21+2*i]<<8);
- command_statue.Setting_Operation_Flag = 0x00;
- }
- else if(comm_buf_flag->RecvBuf[14]==comm_buf_flag->DzAreaNo && comm_buf_flag->RecvBuf[11]==249 && comm_buf_flag->RecvBuf[8]==40)
- {
- comm_buf_flag->DzSelect = 0x11;
- command_statue.Setting_Operation_Flag = 0x00;
- //预改定值成功
- }
- else if(comm_buf_flag->RecvBuf[14]==comm_buf_flag->DzAreaNo && comm_buf_flag->RecvBuf[11]==250 && comm_buf_flag->RecvBuf[8]==40)
- {
- comm_buf_flag->DzSelect = 0x00; //改定值成功
- command_statue.Setting_Operation_Flag = 0x00;
- }
- else if(comm_buf_flag->RecvBuf[14]==comm_buf_flag->DzAreaNo && comm_buf_flag->RecvBuf[11]==250 && comm_buf_flag->RecvBuf[8]==41)
- {
- comm_buf_flag->DzSelect = 0x00;
- command_statue.Setting_Operation_Flag = 0x55;
- //break;
- }
- else if(comm_buf_flag->RecvBuf[14]==0x16 && comm_buf_flag->RecvBuf[11]==249 && comm_buf_flag->RecvBuf[8]==40)
- {
- comm_buf_flag->DzSelect = 0x11;
- command_statue.Config_Operation_Flag = 0x00;
- }
- else if(comm_buf_flag->RecvBuf[14]==0x16 && comm_buf_flag->RecvBuf[11]==250 && comm_buf_flag->RecvBuf[8]==40)
- {
- comm_buf_flag->DzSelect = 0x00; //改系统配置成功
- command_statue.Config_Operation_Flag = 0x00;
- //break;
- }
- else if(comm_buf_flag->RecvBuf[14]==0x16 && comm_buf_flag->RecvBuf[11]==250 && comm_buf_flag->RecvBuf[8]==41)
- {
- comm_buf_flag->DzSelect = 0x00;
- command_statue.Config_Operation_Flag = 0x55;
- //break;
- }
- }
- //-----------------------------------------------------------
- // 遥控操作&通道系数
- //-----------------------------------------------------------
- void ASDU_20_Send0(void) //定值区号切换
- {
- comm_buf_flag->Sendbuf[6]=0x14;
- comm_buf_flag->Sendbuf[7]=0x81;
- comm_buf_flag->Sendbuf[8]=0x11;
- comm_buf_flag->Sendbuf[9]=comm_buf_flag->DeviceAddr;
- comm_buf_flag->Sendbuf[10]=FUNTYPE;
- comm_buf_flag->Sendbuf[11]=Setting_Switch.DzTarget;
- comm_buf_flag->Sendbuf[12]=Setting_Switch.DzCommand;
- comm_buf_flag->Sendbuf[13]=0xa0;
- comm_buf_flag->FunctionCode = 3; //功能码
- comm_buf_flag->LPDU_Command = 3;
- comm_buf_flag->ASDU_Length = 8;
- }
- void ASDU_20_Send1(void) //定制区复制
- {
- comm_buf_flag->Sendbuf[6]=0x14;
- comm_buf_flag->Sendbuf[7]=0x81;
- comm_buf_flag->Sendbuf[8]=0x11;
- comm_buf_flag->Sendbuf[9]=comm_buf_flag->DeviceAddr;
- comm_buf_flag->Sendbuf[10]=FUNTYPE;
- comm_buf_flag->Sendbuf[11]=0x16;
- comm_buf_flag->Sendbuf[12]=Setting_Copy.DzCommand;
- comm_buf_flag->Sendbuf[13]=0xb0;
- comm_buf_flag->Sendbuf[14]=Setting_Copy.DzSource;
- comm_buf_flag->Sendbuf[15]=Setting_Copy.DzTarget;
- comm_buf_flag->FunctionCode = 3; //功能码
- comm_buf_flag->LPDU_Command = 3;
- comm_buf_flag->ASDU_Length = 10;
- }
- void ASDU_20_Send3(void) //装置复归
- {
- comm_buf_flag->Sendbuf[6 ] = 0x14;
- comm_buf_flag->Sendbuf[7 ] = 0x81;
- comm_buf_flag->Sendbuf[8 ] = 0x14;
- comm_buf_flag->Sendbuf[9 ] = comm_buf_flag->DeviceAddr;
- comm_buf_flag->Sendbuf[10] = 0xe0;
- comm_buf_flag->Sendbuf[11] = 0x13;
- comm_buf_flag->Sendbuf[12] = 0x02;
- comm_buf_flag->Sendbuf[13] = 0xee;
- comm_buf_flag->FunctionCode = 3; //功能码
- comm_buf_flag->LPDU_Command = 3;
- comm_buf_flag->ASDU_Length = 8;
- //SendValFrm( 0x03, 8 );
- }
- void ASDU_20_Send4(void) //软压板投退
- {
- comm_buf_flag->Sendbuf[6 ] = 0x14;
- comm_buf_flag->Sendbuf[7 ] = 0x81;
- comm_buf_flag->Sendbuf[8 ] = 0x11;
- comm_buf_flag->Sendbuf[9 ] = comm_buf_flag->DeviceAddr;
- comm_buf_flag->Sendbuf[10] = FUNTYPE;
- comm_buf_flag->Sendbuf[11] = 0x15;
- comm_buf_flag->Sendbuf[12] = YYB_Modify_Flag.Command;
- comm_buf_flag->Sendbuf[13] = 0xef;
- comm_buf_flag->Sendbuf[14] = (unsigned char)((YYB_Modify_Flag.YYB_temp&0xff));
- comm_buf_flag->Sendbuf[15] = (unsigned char)((YYB_Modify_Flag.YYB_temp>>8)&0xff);
- comm_buf_flag->Sendbuf[16] = (unsigned char)((YYB_Modify_Flag.YYB_temp>>16)&0xff);
- comm_buf_flag->Sendbuf[17] = 0;
- comm_buf_flag->FunctionCode = 3; //功能码
- comm_buf_flag->LPDU_Command = 3;
- comm_buf_flag->ASDU_Length = 12;
- }
- void ASDU_20_Send5(void) //查询SOE及故障报告
- {
- comm_buf_flag->Sendbuf[6 ] = 0x14;
- comm_buf_flag->Sendbuf[7 ] = 0x81;
- comm_buf_flag->Sendbuf[8 ] = 0x11;
- comm_buf_flag->Sendbuf[9 ] = comm_buf_flag->DeviceAddr;
- comm_buf_flag->Sendbuf[10] = FUNTYPE;
- comm_buf_flag->Sendbuf[11] = 0x20;
- comm_buf_flag->Sendbuf[12] = 0x02;
- comm_buf_flag->Sendbuf[13] = Fault_Recode_Flag.Type;
- comm_buf_flag->Sendbuf[14] = Fault_Recode_Flag.Number;
- comm_buf_flag->FunctionCode = 3; //功能码
- comm_buf_flag->LPDU_Command = 3;
- comm_buf_flag->ASDU_Length = 9;
- }
- void ASDU_20_Send7(void) //自动调整系数
- {
- comm_buf_flag->Sendbuf[6]=0x14;
- comm_buf_flag->Sendbuf[7]=0x81;
- comm_buf_flag->Sendbuf[8]=0x11;
- comm_buf_flag->Sendbuf[9]=comm_buf_flag->DeviceAddr;
- comm_buf_flag->Sendbuf[10]=FUNTYPE;
- comm_buf_flag->Sendbuf[11]=0x14;
- comm_buf_flag->Sendbuf[12]=Channel_Ration_Flag.Command;
- comm_buf_flag->Sendbuf[13]=0xfe;
- comm_buf_flag->FunctionCode = 3; //功能码
- comm_buf_flag->LPDU_Command = 3;
- comm_buf_flag->ASDU_Length = 8;
- }
- void ASDU_20_Send8(void) //通道系数修改
- {
- int i;
- comm_buf_flag->Sendbuf[6]=0x14;
- comm_buf_flag->Sendbuf[7]=0x81;
- comm_buf_flag->Sendbuf[8]=0x22;
- comm_buf_flag->Sendbuf[9]=comm_buf_flag->DeviceAddr;
- comm_buf_flag->Sendbuf[10]=FUNTYPE;
- comm_buf_flag->Sendbuf[11]=0x14;
- comm_buf_flag->Sendbuf[13]=0xfe;
- switch(Channel_Ration_Flag.Command)
- {
- case 0x81: //读取并选择
- case 0x82:
- comm_buf_flag->Sendbuf[12]=Channel_Ration_Flag.Command;
- comm_buf_flag->FunctionCode = 3; //功能码
- comm_buf_flag->LPDU_Command = 3;
- comm_buf_flag->ASDU_Length = 8;
- break;
- case 0x01: //修改执行
- case 0x02:
- comm_buf_flag->Sendbuf[12]=Channel_Ration_Flag.Command;
- for(i=0;i<CHANNEL_NUM;i++)
- {
- comm_buf_flag->Sendbuf[14+2*i] = (unsigned char)(Channel_Ration_Flag.Temp[i]&0xff);
- comm_buf_flag->Sendbuf[15+2*i] = (unsigned char)((Channel_Ration_Flag.Temp[i]>>8)&0xff);
- }
- comm_buf_flag->FunctionCode = 3; //功能码
- comm_buf_flag->LPDU_Command = 3;
- comm_buf_flag->ASDU_Length = 8+2*CHANNEL_NUM;
- break;
- case 0xc1: //修改撤销
- case 0xc2:
- comm_buf_flag->Sendbuf[12]=Channel_Ration_Flag.Command;
- comm_buf_flag->FunctionCode = 3; //功能码
- comm_buf_flag->LPDU_Command = 3;
- comm_buf_flag->ASDU_Length = 8;
- break;
- };
- }
- void ASDU_20_Analyze(void)
- {
- unsigned int i;
- switch(comm_buf_flag->RecvBuf[11])
- {
- case 0x14:
- switch(comm_buf_flag->RecvBuf[12])
- {
- case 0x81:
- case 0x82:
- for(i = 0;i < CHANNEL_NUM; i++)
- Channel_Ration_Flag.Value[i] = comm_buf_flag->RecvBuf[14 + 2*i] +
- (comm_buf_flag->RecvBuf[15 + 2*i]<<8) ;
- Channel_Ration_Flag.Select = 0x11;
- command_statue.Channel_Ration_Flag = 0x00;
- break;
- case 0x01:
- case 0x02:
- //Memo1->Lines->Add("*****************通道系数修改完成********************");
- for(i=0;i<CHANNEL_NUM;i++)
- Channel_Ration_Flag.Value[i] = comm_buf_flag->RecvBuf[14 + 2*i] +
- (comm_buf_flag->RecvBuf[15 + 2*i]<<8) ;
- Channel_Ration_Flag.Select = 0x00;
- command_statue.Channel_Ration_Flag = 0x00;
- break;
- case 0xc1:
- case 0xc2:
- //Memo1->Lines->Add("*****************通道系数修改撤销********************");
- for(i=0;i<CHANNEL_NUM;i++)
- Channel_Ration_Flag.Temp[i] = Channel_Ration_Flag.Value[i];
- Channel_Ration_Flag.Select = 0x00;
- command_statue.Channel_Ration_Flag = 0x00;
- break;
- case 0x21:
- case 0x22: //自动调整系数
- //Memo1->Lines->Add("*****************自动调整通道系数********************");
- command_statue.Channel_Ration_Flag = 0x00;
- break;
- default:
- break;
- }
- break;
- case 0x15:
- if( comm_buf_flag->RecvBuf[12]==0x82 )
- {
- command_statue.YYB_Opreation_Flag = 0x00;
- //Memo1->Lines->Add("===========软压板预修改===========");
- YYB_Modify_Flag.Select = 0x11;
- }
- else if( comm_buf_flag->RecvBuf[12]==0x02 )
- {
- command_statue.YYB_Opreation_Flag = 0x00;
- //Memo1->Lines->Add("========软压板修改执行成功=========");
- }
- else if( comm_buf_flag->RecvBuf[12]==0xc2 )
- {
- command_statue.YYB_Opreation_Flag = 0x00;
- //Memo1->Lines->Add("===========软压板修改撤销===========");
- }
- break;
- default:
- break;
- }
- }
- //-----------------------------------------------------------
- // 定值操作
- //-----------------------------------------------------------
- void ASDU_21_Send0(unsigned char Segment) //召唤系统配置/定值
- {
- comm_buf_flag->Sendbuf[6] = 0x15;
- comm_buf_flag->Sendbuf[7] = 0x81;
- comm_buf_flag->Sendbuf[8] = 42;
- comm_buf_flag->Sendbuf[9] = comm_buf_flag->DeviceAddr;;
- comm_buf_flag->Sendbuf[10]= 254;
- comm_buf_flag->Sendbuf[11]= 241;
- comm_buf_flag->Sendbuf[12]= 0;
- comm_buf_flag->Sendbuf[13]= 0x01;
- comm_buf_flag->Sendbuf[14]= Segment;
- comm_buf_flag->Sendbuf[15]= 0x00;
- comm_buf_flag->Sendbuf[16]= 0x01;
- comm_buf_flag->FunctionCode = 3; //功能码
- comm_buf_flag->LPDU_Command = 3;
- comm_buf_flag->ASDU_Length = 11;
- //SendValFrm( 0x03, 11 );
- }
- //-----------------------------------------------------------
- // ASDU40(总查询)
- //-----------------------------------------------------------
- void ASDU_40_Analyze(void)
- {
- System_Info.LED_Statue = comm_buf_flag->RecvBuf[12]&0x7f; //信号灯
- System_Info.YB_Soft = comm_buf_flag->RecvBuf[14]*256+comm_buf_flag->RecvBuf[13]; //压板
- System_Info.YX[0] = comm_buf_flag->RecvBuf[16]*256+comm_buf_flag->RecvBuf[15]; //遥信
- System_Info.DZ_Area = comm_buf_flag->RecvBuf[17]-0x17; //定值区号
- System_Info.Password1 = ( comm_buf_flag->RecvBuf[18] + (comm_buf_flag->RecvBuf[19]<<8)
- + (comm_buf_flag->RecvBuf[20]<<16) );//1级密码
- System_Info.Password2 = ( comm_buf_flag->RecvBuf[21] + (comm_buf_flag->RecvBuf[22]<<8)
- + (comm_buf_flag->RecvBuf[23]<<16) );//2级密码
- }
- //-----------------------------------------------------------
- // ASDU50
- //-----------------------------------------------------------
- void ASDU_50_Analyze(void)
- {
- int i;
- {
- System_Info.YX[0] = ( comm_buf_flag->RecvBuf[13]<<8 ) + comm_buf_flag->RecvBuf[12];
- System_Info.YX[1] = ( comm_buf_flag->RecvBuf[15]<<8 ) + comm_buf_flag->RecvBuf[14];
- System_Info.YB_Soft = ( comm_buf_flag->RecvBuf[17]<<8 ) + comm_buf_flag->RecvBuf[16]
- + ( comm_buf_flag->RecvBuf[19]<<24 ) + ( comm_buf_flag->RecvBuf[18]<<16);
- switch(comm_buf_flag->RecvBuf[10])
- {
- case 0x01:
- for( i = 0; i < YC_Total; i++)
- YC_Value[ i ] = ((comm_buf_flag->RecvBuf[21 + 2*i]<<8)+comm_buf_flag->RecvBuf[20 + 2*i]);
- System_Info.LED_Statue = comm_buf_flag->RecvBuf[20 + 2*YC_Total]; //state
- System_Info.SYS_Statue = comm_buf_flag->RecvBuf[21 + 2*YC_Total]; //state
- System_Info.DZ_Area = comm_buf_flag->RecvBuf[22 + 2*YC_Total]; //state
- break;
- case 0x02:
- for( i = 0; i < YC1_Total; i++)
- YC_Value1[ i ] = ((comm_buf_flag->RecvBuf[21 + 2*i]<<8)+comm_buf_flag->RecvBuf[20 + 2*i]);
- System_Info.LED_Statue = comm_buf_flag->RecvBuf[20 + 2*YC1_Total]; //state
- System_Info.SYS_Statue = comm_buf_flag->RecvBuf[21 + 2*YC1_Total]; //state
- System_Info.DZ_Area = comm_buf_flag->RecvBuf[22 + 2*YC1_Total]; //state
- break;
- }
- }
- }
- //-----------------------------------------------------------
- // ASDU64
- //-----------------------------------------------------------
- void ASDU_64_Send0(void) //遥控命令
- {
- comm_buf_flag->Sendbuf[6 ] = 0x40;
- comm_buf_flag->Sendbuf[7 ] = 0x81;
- comm_buf_flag->Sendbuf[8 ] = 0x12;
- comm_buf_flag->Sendbuf[9 ] = comm_buf_flag->DeviceAddr;
- comm_buf_flag->Sendbuf[10] = 0x01;
- comm_buf_flag->Sendbuf[11] = Output_Test_YK.YkDataNo1;
- comm_buf_flag->Sendbuf[12] = Output_Test_YK.YkCommand;
- comm_buf_flag->Sendbuf[13] = 0xee;
- comm_buf_flag->FunctionCode = 3; //功能码
- comm_buf_flag->LPDU_Command = 3;
- comm_buf_flag->ASDU_Length = 8;
- //SendValFrm( 0x03, 8 );
- }
- void ASDU_64_Analyze(void)
- {
- if (comm_buf_flag->RecvBuf[11]==48)
- {
- switch(comm_buf_flag->RecvBuf[12]) //与主站下发的相同
- {
- case 0x81: // 分/退选择信息
- Output_Test_YK.YkSelect = 0x11;
- command_statue.YK_Output_Command_Flag = 0x00;
- //Memo1->Lines->Add("===========断路器遥控(分)选择==========");
- break;
- case 0x01: // 分/退执行信息
- Output_Test_YK.YkSelect = 0x00;
- command_statue.YK_Output_Command_Flag = 0x00;
- //Memo1->Lines->Add("===========断路器遥控(分)执行==========");
- break;
- case 0xC1: // 分/退撤销信息
- Output_Test_YK.YkSelect = 0x00;
- command_statue.YK_Output_Command_Flag = 0x00;
- //Memo1->Lines->Add("===========断路器遥控(分)撤销==========");
- break;
- case 0x82: // 合/投选择信息
- Output_Test_YK.YkSelect = 0x11;
- command_statue.YK_Output_Command_Flag = 0x00;
- //Memo1->Lines->Add("===========断路器遥控(合)选择===========");
- break;
- case 0x02: // 合/投执行信息
- Output_Test_YK.YkSelect = 0x00;
- command_statue.YK_Output_Command_Flag = 0x00;
- //Memo1->Lines->Add("===========断路器遥控(合)执行===========");
- break;
- case 0xc2: // 合/投撤销信息
- command_statue.YK_Output_Command_Flag = 0x00;
- //Memo1->Lines->Add("===========断路器遥控(合)撤销===========");
- Output_Test_YK.YkSelect = 0x00;
- break;
- default:
- break;
- }
- }
- else
- {
- switch(comm_buf_flag->RecvBuf[12])
- {
- case 0x82: // 合/投选择信息
- Output_Test_YK.YkSelect = 0x11;
- command_statue.YK_Output_Command_Flag = 0x00;
- //Memo1->Lines->Add("===========开出传动(合)选择===========");
- break;
- case 0x02: // 合/投执行信息
- Output_Test_YK.YkSelect = 0x00;
- command_statue.YK_Output_Command_Flag = 0x00;
- //Memo1->Lines->Add("===========开出传动(合)执行===========");
- break;
- case 0xC2: // 合/投撤销信息
- command_statue.YK_Output_Command_Flag = 0x00;
- //Memo1->Lines->Add("===========开出传动(合)撤销===========");
- Output_Test_YK.YkSelect = 0x00;
- break;
- }
- }
- }
- void ASDU_70_Analyze(void)
- {
- int i;
- Report_Buf_Show0.num = comm_buf_flag->RecvBuf[11]; //NO.
- Report_Buf_Show0.stu = comm_buf_flag->RecvBuf[12]; //20r1
- Report_Buf_Show0.msec = (comm_buf_flag->RecvBuf[18]*256 + comm_buf_flag->RecvBuf[17])%1000; //msec
- Report_Buf_Show0.sec = (US)((comm_buf_flag->RecvBuf[18]*256 + comm_buf_flag->RecvBuf[17])/1000); //sec
- Report_Buf_Show0.min = comm_buf_flag->RecvBuf[19]; //min
- Report_Buf_Show0.hour = comm_buf_flag->RecvBuf[20]; //hour
- for(i=0;i<20;i++)
- {
- Report_Buf_Show0.Value[i] = ((comm_buf_flag->RecvBuf[24+2*i]&0x3f)*256+comm_buf_flag->RecvBuf[23+2*i]);
- }
- Report_Buf_Show0.day = comm_buf_flag->RecvBuf[64];
- Report_Buf_Show0.mon = comm_buf_flag->RecvBuf[65];
- Report_Buf_Show0.year = comm_buf_flag->RecvBuf[66];
- command_statue.Demand_Soe_Report_Flag = 0x00;
- }
- //-------------------------------------------------------
- // ASDU解析函数
- //-------------------------------------------------------
- void ASDU_Analyze(void)
- {
- int i;
- switch(comm_buf_flag->RecvBuf[6])
- {
- case 0x01:
- ADSU_01_Analyze();
- break;
- case 0x05:
- ASDU_05_Analyze();
- break;
- case 0x06:
- ASDU_06_Analyze();
- break;
- case 0x0a:
- ASDU_10_Analyze();
- break;
- case 0x14:
- ASDU_20_Analyze();
- break;
- case 0x28:
- ASDU_40_Analyze();
- break;
- case 0x32:
- ASDU_50_Analyze();
- break;
- case 0x40:
- ASDU_64_Analyze();
- break;
- case 0x46:
- ASDU_70_Analyze();
- break;
- default:
- break;
- }
- if(PC_Comm_Flag == 0x00)
- {
- for(i=0;i< (comm_buf_flag->RecvBuf[2]+6);i++)
- {
- Comm0.SendBuf[Comm0.SendSet] = comm_buf_flag->RecvBuf[i];
- Comm0.SendSet++;
- if(Comm0.SendSet>=SENDNUM)
- Comm0.SendSet = 0;
- }
- }
- }
- //---------------------------------------------------------------------------
- int Check_Instruction_Statue(unsigned int Command)
- {
- int temp;
- switch( Command )
- {
- case 0x0210: //修改时间
- if(command_statue.Check_Time_Flag == 0xAA)
- {
- if( command_statue.Check_Time_Count >= COMMANDDELAY)
- temp = 0x22;
- else
- temp = 0x11;
- }
- else
- {
- temp = 0x00;
- }
- break;
- case 0x0500: //读系统参数
- case 0x0c00: //系统配置修改选择
- case 0x0d00: //系统配置修改执行
- if(command_statue.Config_Operation_Flag == 0xAA)
- {
- if( command_statue.Config_Operation_Count >= COMMANDDELAY)
- temp = 0x22;
- else
- temp = 0x11;
- }
- else if(command_statue.Config_Operation_Flag == 0x55)
- {
- temp = 0x22;
- }
- else
- {
- temp = 0x00;
- }
- break;
- case 0x0600: //读定值
- case 0x0800: //定值预修改
- case 0x0900: //定值修改执行
- case 0x0a00: //定值区号切换选择
- case 0x0a01: //定值区号切换执行
- case 0x0a02: //定值区号切换撤销
- case 0x0b00: //定值区复制选择
- case 0x0b01: //定值区复制执行
- case 0x0b02: //定值区复制撤销
- if(command_statue.Setting_Operation_Flag == 0xAA)
- {
- if( command_statue.Setting_Operation_Count >= COMMANDDELAY)
- temp = 0x22;
- else
- temp = 0x11;
- }
- else if(command_statue.Setting_Operation_Flag == 0x55)
- {
- temp = 0x22;
- }
- else
- {
- temp = 0x00;
- }
- break;
- case 0x0700: //自动调整通道系数
- case 0x0e00: //通道系数调整选择
- case 0x0e01: //通道系数调整执行
- case 0x0e02: //通道系数调整撤销
- if(command_statue.Channel_Ration_Flag == 0xAA)
- {
- if( command_statue.Channel_Ration_Count >= COMMANDDELAY)
- temp = 0x22;
- else
- temp = 0x11;
- }
- else
- {
- temp = 0x00;
- }
- break;
- case 0x0f00: //软压板操作选择
- case 0x0f01: //软压板操作执行
- case 0x0f02: //软压板操作撤销
- if(command_statue.YYB_Opreation_Flag == 0xAA)
- {
- if( command_statue.YYB_Opreation_Count >= COMMANDDELAY)
- temp = 0x22;
- else
- temp = 0x11;
- }
- else
- {
- temp = 0x00;
- }
- break;
- case 0x1000: //修改密码
- if(command_statue.Password_Modified_Flag == 0xAA)
- {
- if( command_statue.Password_Modified_Count >= COMMANDDELAY)
- temp = 0x22;
- else
- temp = 0x11;
- }
- else
- {
- temp = 0x00;
- }
- break;
- case 0x1100: //开出传动选择
- case 0x1101: //开出传动执行
- case 0x1102: //开出传动撤销
- case 0x1110: //遥控合选择
- case 0x1111: //遥控合执行
- case 0x1112: //遥控合撤销
- case 0x1120: //遥控分选择
- case 0x1121: //遥控分执行
- case 0x1122: //遥控分撤销
- if(command_statue.YK_Output_Command_Flag == 0xAA)
- {
- if( command_statue.YK_Output_Command_Count >= COMMANDDELAY)
- temp = 0x22;
- else
- temp = 0x11;
- }
- else
- {
- temp = 0x00;
- }
- break;
- case 0x1200: //查询SOE及故障报告
- if(command_statue.Demand_Soe_Report_Flag == 0xAA)
- {
- if( command_statue.Demand_Soe_Report_Count >= COMMANDDELAY)
- temp = 0x22;
- else
- temp = 0x11;
- }
- else
- {
- temp = 0x00;
- }
- break;
- case 0x1300: //装置复归
- if(command_statue.Device_FUGUI_Flag == 0xAA)
- {
- if( command_statue.Device_FUGUI_Count >= COMMANDDELAY)
- temp = 0x22;
- else
- temp = 0x11;
- }
- else
- {
- temp = 0x00;
- }
- break;
- }
- return temp;
- }
- //---------------------------------------------------------------------------
- void Command_Timer_Update(void)
- {
- command_statue.Check_Time_Count++; //修改时间
- command_statue.Config_Operation_Count++; //系统参数操作标志
- command_statue.Setting_Operation_Count++; //定值操作标志
- command_statue.Channel_Ration_Count++; //通道系数操作标志
- command_statue.YYB_Opreation_Count++; //软压板操作
- command_statue.Password_Modified_Count++; //修改密码
- command_statue.YK_Output_Command_Count++; //遥控/开出传动选择
- command_statue.Demand_Soe_Report_Count++; //查询SOE及故障报告
- command_statue.Device_FUGUI_Count++; //装置复归
- }
- //---------------------------------------------------------------------------
- void Command_Timer_Check(void)
- {
- if( command_statue.Check_Time_Count >= COMMANDDELAY) //修改时间
- command_statue.Check_Time_Count = COMMANDDELAY;
- if( command_statue.Config_Operation_Count >= COMMANDDELAY) //系统参数操作标志
- command_statue.Config_Operation_Count = COMMANDDELAY;
- if( command_statue.Setting_Operation_Count >= COMMANDDELAY) //定值操作标志
- command_statue.Setting_Operation_Count = COMMANDDELAY;
- if( command_statue.Channel_Ration_Count >= COMMANDDELAY) //通道系数操作标志
- command_statue.Channel_Ration_Count = COMMANDDELAY;
- if( command_statue.YYB_Opreation_Count >= COMMANDDELAY) //软压板操作
- command_statue.YYB_Opreation_Count = COMMANDDELAY;
- if( command_statue.Password_Modified_Count >= COMMANDDELAY) //修改密码
- command_statue.Password_Modified_Count = COMMANDDELAY;
- if( command_statue.YK_Output_Command_Count >= COMMANDDELAY) //遥控/开出传动选择
- command_statue.YK_Output_Command_Count = COMMANDDELAY;
- if( command_statue.Demand_Soe_Report_Count >= COMMANDDELAY) //查询SOE及故障报告
- command_statue.Demand_Soe_Report_Count = COMMANDDELAY;
- if( command_statue.Device_FUGUI_Count >= COMMANDDELAY) //装置复归
- command_statue.Device_FUGUI_Count = COMMANDDELAY;
- }
- //---------------------------------------------------------------------------
- void Comm_103_Run(void)
- {
- if(PC_Comm_Flag == 0x00)
- {
- LPDU_MMI_DSP_Send();
- Comm_RecvProcess();
- LPDU_MMI_DSP_Recv();
- Comm0.RecvSet = 0;
- Comm0.RecvGet = 0;
- }
- else
- {
- if( Comm0.RecvSet != Comm0.RecvGet )
- {
- PortA.SendBuf[PortA.SendSet] = Comm0.RecvBuf[Comm0.RecvGet];
- PortA.SendSet = (PortA.SendSet+1)%SENDNUM;
- Comm0.RecvGet = (Comm0.RecvGet+1)%RECVNUM;
- }
- if( PortA.RecvSet != PortA.RecvGet )
- {
- Comm0.SendBuf[Comm0.SendSet] = PortA.RecvBuf[PortA.RecvGet];
- Comm0.SendSet = (Comm0.SendSet+1)%SENDNUM;
- PortA.RecvGet = (PortA.RecvGet+1)%RECVNUM;
- }
- }
- }
- //---------------------------------------------------------------------------