FDJ_HB_P103.C
上传用户:jndfzc
上传日期:2014-06-02
资源大小:325k
文件大小:91k
源码类别:

单片机开发

开发平台:

Others

  1. //++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. //         GCA-150A通信程序
  3. //    创建日期:2004年12月13日
  4. //    修改日期:2005年08月29日
  5. //++++++++++++++++++++++++++++++++++++++++++++++++++++
  6. #include "define.h"
  7. #include  "P103_mmi2dsp.h"
  8. #define  DELAYACK      200     //通信间隔计时器
  9. #define  DELAYACK1     200     //通信间隔计时器
  10. #define  RECALLCOUNT    600    //重复发送计数器
  11. #define  COMMANDDELAY 1500
  12. #define  FUNTYPE          0x01
  13. #define  Setting_Total    42
  14. #define  Sys_Cfg_Total    13
  15. #define  YC_Total         26
  16. #define  YC1_Total        26
  17. #define  CHANNEL_NUM      32
  18. extern struct  comm_buf_fm  PortA;
  19. extern struct  comm_buf_fm  Comm0;
  20. extern unsigned int YC_Value[YC_NUM];       /*数组存所有YC数据*/     
  21. extern unsigned int YC_Value1[YC_NUM];       /*数组存所有YC数据*/     
  22. extern struct  System_Info_fm  System_Info; //实时信息
  23. extern unsigned int   System_config[CONFIG_NUM];    //系统配置
  24. extern unsigned int   System_setting[SETTING_NUM];   //定值
  25. extern struct  Time_buf  realtime;          //实时时钟
  26. extern struct  Time_buf  realtime1;         //实时时钟
  27. extern unsigned char TargetArea;            //目标区(用于复制定值)
  28. extern unsigned char SourceArea;            //原始区(用于复制定值)
  29. extern struct  SOE_Buf_Show_fm      SOE_Buf_Show0;          //存放SOE的缓冲区
  30. extern struct  Report_Buf_Show_fm   Report_Buf_Show0;
  31. extern struct SoftInformation_fm  SoftInformation;
  32. extern struct Setting_Copy_fm    Setting_Copy;
  33. extern struct Setting_Switch_fm  Setting_Switch;
  34. extern struct Output_Test_YK_fm  Output_Test_YK;
  35. extern struct  Channel_Ration_Flag_fm  Channel_Ration_Flag;
  36. extern struct  YYB_Modify_Flag_fm   YYB_Modify_Flag;
  37. extern struct  Fault_Recode_Flag_fm   Fault_Recode_Flag;    //召唤故障报告/SOE缓冲区
  38. extern struct Harmonic_Value_fm Harmonic_Value;
  39. extern unsigned char New_Information_Flag,PC_Comm_Flag;
  40. struct  comm_buf_flag_fm
  41. {
  42.   UC      RecvBuf[270];     //接收缓冲区
  43.   UI      ReceivePoint;     //接收到的字节计数器
  44.   UC      synchro;          //同步标志
  45.   UC      Type;             //固定帧还是可变帧
  46.   UC      FrameRecv;        //收到完整的数据帧,固定帧0x15;可变帧0x1a
  47.                             
  48.   UC      DeviceAddr;       //DSP插件地址
  49.   US      Timing;           //发送时间间隔计数器
  50.   UC      Sendbuf[270];     //发送缓冲区
  51.   US      SendSeq;          //发送次序
  52.   UC      Length;           //发送长度计数
  53.   UC      Counter;          //重复发送计数器
  54.   
  55.   UC      CommError;         //装置通信故障标志,0x22复位CU   0x11复位FCB
  56.   
  57.   UC      Flag_CallAll;      //总召唤标志
  58.   UI      Timer_CallAll;     //总召唤计时
  59.   
  60.   UC      Flag_CheckTime;    //对时标志
  61.   UC      Modify_Time_Flag;  //修改时间标志
  62.   UI      Timer_CheckTime;   //定时对时计时器
  63.   UC      Init_System_Flag;  //上电初始化标志
  64.   UC      Asdu10_10;
  65.   UC      Asdu10_12;
  66.   UC      Asdu10_13;
  67.   
  68.   UC      TempBuf[260];     //发送临时缓冲区
  69.                             
  70.   UC      FCB;          
  71.   UC      FCV;
  72.   UC      FUN;              //哪种类型的保护
  73.   UC      ACD;
  74. //---------YK------------
  75.   UC      YkCommand;        //遥控命令
  76.   UC      YkDataNo1;        //遥控点号1
  77.   UC      YkDataNo2;        //遥控点号2
  78.   UC      YkSelect;         //选择标志
  79.   UC      YkError;          //遥控出错
  80. //---------Setting-------  
  81.   UC      DzCommand;        //定值操作,
  82.   UC      DzAreaNo;         //定值区号
  83.   UC      DzDataNum;        //定值个数
  84.   UC      DzSwitchSele;     //定值切换选择标志
  85.   UC      DzCopySele;       //定值复制选择标志
  86.   UC      DzData[256];
  87.   UC      DzSelect;         //定值选择标志
  88.   UC      DzError;          //远方修改定值出错
  89.   UC      FunctionCode;     //功能码
  90.   UC      LPDU_Command;
  91.   UC      ASDU_Length;
  92.   struct  comm_buf_fm      *com_103;
  93. };
  94. struct  comm_buf_flag_fm *comm_buf_flag;
  95. struct  comm_buf_flag_fm  ComDsp_buf_flag;
  96. struct Order_Array_fm
  97. {
  98.   unsigned char  Set;
  99.   unsigned char  Get;
  100.   unsigned short Order[10];
  101. };
  102. struct Order_Array_fm Order_Array;
  103. struct  command_statue_fm
  104. {
  105.      int   Check_Time_Flag;                  //修改时间
  106.      int   Check_Time_Count;
  107.      int   Config_Operation_Flag;            //系统参数操作标志
  108.      int   Config_Operation_Count;
  109.      int   Setting_Operation_Flag;           //定值操作标志
  110.      int   Setting_Operation_Count;
  111.      int   Channel_Ration_Flag;              //通道系数操作标志
  112.      int   Channel_Ration_Count;
  113.      int   YYB_Opreation_Flag;               //软压板操作
  114.      int   YYB_Opreation_Count;
  115.      int   Password_Modified_Flag;           //修改密码
  116.      int   Password_Modified_Count;
  117.      int   YK_Output_Command_Flag;           //遥控/开出传动选择
  118.      int   YK_Output_Command_Count;
  119.      int   Demand_Soe_Report_Flag;           //查询SOE及故障报告
  120.      int   Demand_Soe_Report_Count;
  121.      int   Device_FUGUI_Flag;                //装置复归
  122.      int   Device_FUGUI_Count;
  123. };
  124. struct command_statue_fm command_statue;
  125. //---------------------------------------------
  126. //     以下为函数声明
  127. //---------------------------------------------
  128. void   Init_Unit(void);        //初始化
  129. void   Check_Time(void);       //对时
  130. void   Call_WholeData(void);   //总召唤
  131. void   Com_Patrol(void);       //轮询
  132. void   ComSend(void);
  133. void   ComResend(void);
  134. void   Comm_RecvProcess(void);
  135. void   CommDspTimeUpdate(void);
  136. void   YK_Command_Style(unsigned int Addr,unsigned int Style,unsigned int Seq);
  137. //int    MMI_DSP_Instruction(unsigned int Command,unsigned int per1,unsigned int per2);
  138. void   Command_Timer_Update(void);
  139. void   Command_Timer_Check(void);
  140. int    Check_Instruction_Statue(unsigned int Command);
  141. void   SendFixFrm(UC SFunCode);
  142. void   SendValFrm(UC SFunCode, UC len );
  143. void   ProcessMMI_DSP(void);
  144. void   Init_Unit(void);
  145. void   Call_WholeData(void);
  146. void   Check_Time(void);
  147. void   Com_Patrol(void);
  148. void   Read_SystemConfig(void);
  149. void   Read_SystemSetting(void);
  150. void   Auto_Adjust_Ration(void);
  151. void   Modify_Channel_Ration(void);
  152. void   Setting_PreModify(void);
  153. void   Setting_Modified_Exe(void);
  154. void   Setting_Area_Switch(void);
  155. void   YYB_Opreation(void);
  156. void   Setting_Area_Copy(void);
  157. void   Config_PreModify(void);
  158. void   Config_Modified_Exe(void);
  159. void   Password_Modified_Exe(void);
  160. void   Demand_Soe_Report(void);
  161. void   YK_Output_Command(void);
  162. void   Device_FUGUI(void);
  163. void   ADSU_01_Analyze(void);
  164. void   ASDU_05_Send0(void);
  165. void   ASDU_05_Send1(void);
  166. void   ASDU_05_Send2(void);
  167. void   ASDU_05_Analyze(void);
  168. void   ASDU_06_Send0(void);
  169. void   ASDU_06_Send1(void);
  170. void   ASDU_06_Analyze(void);
  171. void   ASDU_07_Send(void);
  172. void   ASDU_10_Send2(unsigned char Type);
  173. void   ASDU_10_Send3(unsigned char Type);
  174. void   ASDU_10_Analyze(void);
  175. void   ASDU_20_Send0(void);
  176. void   ASDU_20_Send1(void);
  177. void   ASDU_20_Send2(void);
  178. void   ASDU_20_Send3(void);
  179. void   ASDU_20_Send4(void);
  180. void   ASDU_20_Send5(void);
  181. void   ASDU_20_Send7(void);
  182. void   ASDU_20_Send8(void);
  183. void   ASDU_20_Analyze(void);
  184. void   ASDU_21_Send0(unsigned char Segment);
  185. void   ASDU_40_Analyze(void);
  186. void   ASDU_50_Analyze(void);
  187. void   ASDU_64_Send0(void);
  188. void   ASDU_64_Analyze(void);
  189. void   ASDU_Analyze(void);
  190. //---------------------------------------------
  191. //     初始化通信标志及缓冲区
  192. //---------------------------------------------
  193. void  ComMMI2DSP_init(void)
  194. {
  195.  
  196.   ComDsp_buf_flag.synchro = 0;           
  197.   ComDsp_buf_flag.Type = 0xff;                 //固定帧还是可变帧
  198.   ComDsp_buf_flag.FrameRecv = 0;         
  199.   Order_Array.Set = Order_Array.Get = 0;
  200.   ComDsp_buf_flag.CommError = 0x11;
  201.   ComDsp_buf_flag.DeviceAddr = 0x03;     
  202.   ComDsp_buf_flag.ReceivePoint = 0;      // 
  203.   
  204.   ComDsp_buf_flag.SendSeq = 0x000;
  205.   ComDsp_buf_flag.FUN = 160;                  //哪种类型的保护
  206.   ComDsp_buf_flag.Flag_CallAll = 0x01;        //上电允许总召唤
  207.   ComDsp_buf_flag.Timer_CallAll = 0;          //总召唤计时器回零
  208.   ComDsp_buf_flag.Flag_CheckTime = 0x01;      //上电允许对时
  209.   ComDsp_buf_flag.Modify_Time_Flag = 0x00;
  210.   ComDsp_buf_flag.Timer_CheckTime = 0;        //对时间隔计时器回零
  211.   ComDsp_buf_flag.Init_System_Flag = 0x01;   //上电初始化标志
  212. //---------YK------------
  213.   ComDsp_buf_flag.YkCommand = 0;         //遥控命令
  214.   ComDsp_buf_flag.YkDataNo1 = 0;          //遥控点号
  215.   ComDsp_buf_flag.YkDataNo2 = 0;          //遥控点号
  216.   ComDsp_buf_flag.YkSelect = 0;          //选择标志
  217.   ComDsp_buf_flag.YkError = 0;           //遥控出错
  218. //---------Setting-------  
  219.   ComDsp_buf_flag.DzCommand = 0;         //定值操作,
  220.   ComDsp_buf_flag.DzAreaNo = 0;          //定值区号
  221.   ComDsp_buf_flag.DzDataNum = 0;         //定值个数
  222.   ComDsp_buf_flag.DzSelect = 0;          //定值选择标志
  223.   ComDsp_buf_flag.DzError = 0;           //远方修改定值出错
  224.   ComDsp_buf_flag.FunctionCode = 0;     //功能码
  225.   ComDsp_buf_flag.LPDU_Command = 0;
  226.   ComDsp_buf_flag.ASDU_Length = 0;
  227.         Order_Array.Order[ Order_Array.Set ] = 0x0200;
  228.         Order_Array.Set = (Order_Array.Set+1)%10;
  229.         Order_Array.Order[ Order_Array.Set ] = 0x0100;
  230.         Order_Array.Set = (Order_Array.Set+1)%10;
  231.   ComDsp_buf_flag.com_103 =&PortA;// &Comm0;//
  232.   comm_buf_flag = &ComDsp_buf_flag;
  233. }
  234. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
  235. //        发送处理
  236. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
  237. void  ComSend(void)
  238. {
  239.   UI  i;
  240.   for( i = 0 ; i < comm_buf_flag->Length ; i++)
  241.     {
  242.          comm_buf_flag->com_103->SendBuf[comm_buf_flag->com_103->SendSet] = comm_buf_flag->Sendbuf[i];
  243.          if((comm_buf_flag->com_103->SendSet++) >= SENDNUM)
  244.               comm_buf_flag->com_103->SendSet=0;
  245.          if(PC_Comm_Flag == 0x00)
  246.            {
  247.                  Comm0.SendBuf[Comm0.SendSet] =  comm_buf_flag->Sendbuf[i];
  248.                  Comm0.SendSet = (Comm0.SendSet+1)%SENDNUM;
  249.            }
  250.               
  251.     }
  252. }
  253. void  ComResend(void)
  254. {
  255.   UI i,Length;
  256.   if( comm_buf_flag->TempBuf[0] == 0x10 )
  257.     Length = 0x05;
  258.   else if(( comm_buf_flag->TempBuf[0] == 0x68 )&&( comm_buf_flag->TempBuf[3] == 0x68 )
  259.            &&(comm_buf_flag->TempBuf[1] == comm_buf_flag->TempBuf[2]))
  260.     {
  261.        if( (comm_buf_flag->TempBuf[1]+5)== 0x16 )  Length = comm_buf_flag->TempBuf[1]+6;
  262.     }
  263.   else   return;
  264.   
  265.   for( i = 0 ; i < Length ; i++)
  266.     {
  267.          comm_buf_flag->com_103->SendBuf[comm_buf_flag->com_103->SendSet] = comm_buf_flag->TempBuf[i];
  268.          if((comm_buf_flag->com_103->SendSet++) >= SENDNUM)
  269.               comm_buf_flag->com_103->SendSet=0;
  270.          if(PC_Comm_Flag == 0x00)
  271.            {
  272.                  Comm0.SendBuf[Comm0.SendSet] =  comm_buf_flag->TempBuf[i];
  273.                  Comm0.SendSet = (Comm0.SendSet+1)%SENDNUM;
  274.            }
  275.     }
  276. }
  277.   
  278. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
  279. //       接收处理
  280. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
  281. void   Comm_RecvProcess(void)
  282. {
  283.   unsigned char temp,i;
  284.   
  285.   switch(comm_buf_flag->synchro)
  286.     {
  287.       case    0:
  288.  
  289.               while( comm_buf_flag->com_103->RecvSet != comm_buf_flag->com_103->RecvGet )
  290.                {
  291.                  if(comm_buf_flag->com_103->RecvBuf[comm_buf_flag->com_103->RecvGet]==0x10)
  292.                    {
  293.                       comm_buf_flag->synchro=1;
  294.                       comm_buf_flag->Type = 0;
  295.                       break;  
  296.                    }
  297.                  else if(comm_buf_flag->com_103->RecvBuf[comm_buf_flag->com_103->RecvGet]==0x68)
  298.                    {
  299.                       comm_buf_flag->synchro=1;
  300.                       comm_buf_flag->Type = 1;
  301.                       break;  
  302.                    }
  303.                  else
  304.                    {
  305.                       comm_buf_flag->com_103->RecvGet++;
  306.                   if(comm_buf_flag->com_103->RecvGet >= RECVNUM) comm_buf_flag->com_103->RecvGet = 0; 
  307.                       continue;
  308.                    }
  309.                  }
  310.                break;
  311.        case   1:
  312.    
  313.               while( comm_buf_flag->com_103->RecvSet != comm_buf_flag->com_103->RecvGet )
  314.                 {
  315.                    comm_buf_flag->RecvBuf[comm_buf_flag->ReceivePoint] = comm_buf_flag->com_103->RecvBuf[comm_buf_flag->com_103->RecvGet];
  316.                    comm_buf_flag->ReceivePoint++;
  317.                comm_buf_flag->com_103->RecvGet++;
  318.                 if(comm_buf_flag->com_103->RecvGet >= RECVNUM) comm_buf_flag->com_103->RecvGet = 0; 
  319.                    if(comm_buf_flag->Type == 0)
  320.                      {
  321.                         if(comm_buf_flag->ReceivePoint>=5)  
  322.                          {
  323.                             temp = comm_buf_flag->RecvBuf[1]+comm_buf_flag->RecvBuf[2];
  324.                             
  325.                         if ((comm_buf_flag->RecvBuf[2]==comm_buf_flag->DeviceAddr)||(comm_buf_flag->RecvBuf[2]==0xFF))
  326.                            
  327.                               {
  328.                                  comm_buf_flag->FrameRecv = 0x15;
  329.                                  comm_buf_flag->Type = 0xff;
  330.                                  comm_buf_flag->synchro = 0; 
  331.                                  comm_buf_flag->ReceivePoint = 0;
  332.                                }
  333.                             else
  334.                                {
  335.                                  comm_buf_flag->FrameRecv = 0;
  336.                                  comm_buf_flag->Type = 0xff;
  337.                                  comm_buf_flag->synchro = 0; 
  338.                                  comm_buf_flag->ReceivePoint = 0;
  339.                                }
  340.                           
  341.                            break;
  342.                          }
  343.                      }
  344.                    else if(comm_buf_flag->Type == 1)
  345.                      {
  346.                        if((comm_buf_flag->ReceivePoint>=4))
  347.                          {
  348.                            if((comm_buf_flag->RecvBuf[0]!=0x68)||(comm_buf_flag->RecvBuf[3]!=0x68)||
  349.                               (comm_buf_flag->RecvBuf[1]!=comm_buf_flag->RecvBuf[2]))
  350.                               {
  351.                                  comm_buf_flag->Type = 0xff;
  352.                                  comm_buf_flag->synchro = 0; 
  353.                                  comm_buf_flag->ReceivePoint = 0;
  354.                                  break;
  355.                               }
  356.                            if(comm_buf_flag->ReceivePoint >= (comm_buf_flag->RecvBuf[1]+6))
  357.                               {
  358.                                temp = 0;
  359.                                for(i=0;i< comm_buf_flag->RecvBuf[1];i++)
  360.                                 temp = temp + comm_buf_flag->RecvBuf[4+i];
  361.                                 
  362.                            if (((comm_buf_flag->RecvBuf[5]==comm_buf_flag->DeviceAddr)||(comm_buf_flag->RecvBuf[5]==0xFF))
  363.                                    &&(temp==(comm_buf_flag->RecvBuf[comm_buf_flag->RecvBuf[1]+4])))
  364.                                  {
  365.                            comm_buf_flag->FrameRecv = 0x1A;
  366.                                    comm_buf_flag->Type = 0xff;
  367.                                    comm_buf_flag->synchro = 0; 
  368.                                    comm_buf_flag->ReceivePoint = 0;
  369.                                  }
  370.                                else
  371.                                  {
  372.                                    comm_buf_flag->FrameRecv = 0x0;
  373.                                    comm_buf_flag->Type = 0xff;
  374.                                    comm_buf_flag->synchro = 0; 
  375.                                    comm_buf_flag->ReceivePoint = 0;
  376.                                  }
  377.                                  break;
  378.                               }
  379.                          }
  380.                      }
  381.                    else
  382.                      {
  383.                         comm_buf_flag->Type = 0xff;
  384.                         comm_buf_flag->synchro = 0; 
  385.                         comm_buf_flag->ReceivePoint = 0;
  386.                         break;
  387.                      }
  388.                  }
  389.               break;   
  390.       default :
  391.               comm_buf_flag->Type = 0xff;
  392.               comm_buf_flag->synchro = 0; 
  393.               comm_buf_flag->ReceivePoint = 0;
  394.               break;
  395.     }
  396. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
  397. //     通信时间间隔计数
  398. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
  399. void   CommDspTimeUpdate(void)
  400. {
  401.     comm_buf_flag->Timing++;
  402. /*    comm_buf_flag->Timer_CallAll++;
  403.     if( comm_buf_flag->Timer_CallAll >= 900000 )
  404.       {
  405.         comm_buf_flag->Flag_CallAll = 0x01;     //上电允许总召唤
  406.         Order_Array.Order[ Order_Array.Set ] = 0x0100;
  407.         Order_Array.Set = (Order_Array.Set+1)%10;
  408.         comm_buf_flag->Timer_CallAll = 0;       //总召唤计时器回零
  409.       }
  410.  */  
  411.     if( ComDsp_buf_flag.CommError!=0x11 )
  412.      {
  413.         comm_buf_flag->Timer_CheckTime++;
  414.         if( comm_buf_flag->Timer_CheckTime >= 6000 ) //_CheckTime
  415.          {
  416.            comm_buf_flag->Flag_CheckTime = 0x01;     //置对时标志
  417.            Order_Array.Order[ Order_Array.Set ] = 0x0200;
  418.            Order_Array.Set = (Order_Array.Set+1)%10;
  419.            comm_buf_flag->Timer_CheckTime = 0;       //计数器归零
  420.          }
  421.       }
  422.     Command_Timer_Update();
  423.                                               
  424. }
  425. //---------------------------------------------------------------------
  426. //        遥控命令解析
  427. //---------------------------------------------------------------------
  428. void   YK_Command_Style(unsigned int Addr,unsigned int Style,unsigned int Seq)
  429. {
  430.     Output_Test_YK.YkDataNo1 = Addr;
  431.     if(Style == 0x11)   //合
  432.       {
  433.          if(Seq == 0x55)         Output_Test_YK.YkCommand = 0x82; //预合
  434.          else if(Seq == 0xAA)    Output_Test_YK.YkCommand = 0x02; //合执行
  435.          else if(Seq == 0xcc)    Output_Test_YK.YkCommand = 0xC2; //合命令撤销
  436.          else                    Output_Test_YK.YkCommand = 0x00; //未知
  437.       }
  438.     else if(Style == 0x22)   //分
  439.       {
  440.          if(Seq == 0x55)         Output_Test_YK.YkCommand = 0x81; //预分
  441.          else if(Seq == 0xAA)    Output_Test_YK.YkCommand = 0x01; //分执行
  442.          else if(Seq == 0xcc)    Output_Test_YK.YkCommand = 0xC1; //分命令撤销
  443.          else                    Output_Test_YK.YkCommand = 0x00; //未知
  444.       }
  445. }
  446. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
  447. //        通信命令处理
  448. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
  449. int   MMI_DSP_Instruction(unsigned int Command,unsigned int per1,unsigned int per2)
  450. {
  451.    int Res;
  452.    
  453.    Res = 1;
  454.    switch( Command )
  455.     {
  456.       case  0x0000:  //复位CU/FCB
  457.                    Order_Array.Order[ Order_Array.Set ] = 0x0000;
  458.                    Order_Array.Set = (Order_Array.Set+1)%10;
  459.                  break;
  460.       case  0x0100:  //总召唤
  461.                    Order_Array.Order[ Order_Array.Set ] = 0x0100;
  462.                    Order_Array.Set = (Order_Array.Set+1)%10;
  463.                  break;
  464.       case  0x0200:  //对时
  465.                    Order_Array.Order[ Order_Array.Set ] = 0x0200;
  466.                    Order_Array.Set = (Order_Array.Set+1)%10;
  467.                  break;
  468.       case  0x0210:  //修改时间
  469.                    Order_Array.Order[ Order_Array.Set ] = 0x0210;
  470.                    Order_Array.Set = (Order_Array.Set+1)%10;
  471.                    command_statue.Check_Time_Flag = 0xAA;
  472.                    command_statue.Check_Time_Count = 0;
  473.                  break;
  474.       case  0x0500:  //读系统参数
  475.                    Order_Array.Order[ Order_Array.Set ] = 0x0500;
  476.                    Order_Array.Set = (Order_Array.Set+1)%10;
  477.                    command_statue.Config_Operation_Flag = 0xaa;
  478.                    command_statue.Config_Operation_Count = 0;
  479.                  break;
  480.         case  0x0600:   //读定值
  481.                    comm_buf_flag->DzAreaNo = per1 + 0x17;
  482.                    Order_Array.Order[ Order_Array.Set ] = 0x0600;
  483.                    Order_Array.Set = (Order_Array.Set+1)%10;
  484.                    command_statue.Setting_Operation_Flag = 0xaa;
  485.                    command_statue.Setting_Operation_Count = 0;
  486.                    break;
  487.         case  0x0700:   //自动调整通道系数
  488.                    Channel_Ration_Flag.Command = per1&0xff;
  489.                    Order_Array.Order[ Order_Array.Set ] = 0x0700;
  490.                    Order_Array.Set = (Order_Array.Set+1)%10;
  491.                    command_statue.Channel_Ration_Flag = 0xaa;
  492.                    command_statue.Channel_Ration_Count = 0x00;
  493.                    break;
  494.         case  0x0800:   //定值预修改
  495.                    comm_buf_flag->DzSelect = 0x00;
  496.                    comm_buf_flag->DzAreaNo = per1+0x17;
  497.                    Order_Array.Order[ Order_Array.Set ] = 0x0800;
  498.                    Order_Array.Set = (Order_Array.Set+1)%10;
  499.                    command_statue.Setting_Operation_Flag = 0xaa;
  500.                    command_statue.Setting_Operation_Count = 0;
  501.                    break;
  502.         case  0x0900:   //定值修改执行
  503.                    if(comm_buf_flag->DzSelect == 0x11)
  504.                     {
  505.                       comm_buf_flag->DzAreaNo = per1+0x17;
  506.                       Order_Array.Order[ Order_Array.Set ] = 0x0900;
  507.                       Order_Array.Set = (Order_Array.Set+1)%10;
  508.                       command_statue.Setting_Operation_Flag = 0xaa;
  509.                       command_statue.Setting_Operation_Count = 0;
  510.                     }
  511.                    else
  512.                     Res = 0;
  513.                    break;
  514.         case  0x0a00:   //定值区号切换选择
  515.                    Setting_Switch.DzSelect = 0x00;
  516.                    Setting_Switch.DzCommand = 0x82;
  517.                    Setting_Switch.DzTarget = per1+0x17;
  518.                    Order_Array.Order[ Order_Array.Set ] = 0x0a00;
  519.                    Order_Array.Set = (Order_Array.Set+1)%10;
  520.                    command_statue.Setting_Operation_Flag = 0xaa;
  521.                    command_statue.Setting_Operation_Count = 0;
  522.                    break;
  523.         case  0x0a01:   //定值区号切换执行
  524.                    if(Setting_Switch.DzSelect == 0x11)
  525.                      {
  526.                         Setting_Switch.DzCommand = 0x02;
  527.                         Setting_Switch.DzTarget = per1+0x17;
  528.                         Order_Array.Order[ Order_Array.Set ] = 0x0a00;
  529.                         Order_Array.Set = (Order_Array.Set+1)%10;
  530.                         command_statue.Setting_Operation_Flag = 0xaa;
  531.                         command_statue.Setting_Operation_Count = 0;
  532.                      }
  533.                    else
  534.                      Res = 0;
  535.                    break;
  536.         case  0x0a02:   //定值区号切换撤销
  537.                    if(Setting_Switch.DzSelect == 0x11)
  538.                      {
  539.                        Setting_Switch.DzCommand = 0xc2;
  540.                        Setting_Switch.DzTarget = per1+0x17;
  541.                        Order_Array.Order[ Order_Array.Set ] = 0x0a00;
  542.                        Order_Array.Set = (Order_Array.Set+1)%10;
  543.                        command_statue.Setting_Operation_Flag = 0xaa;
  544.                        command_statue.Setting_Operation_Count = 0;
  545.                      }
  546.                    else
  547.                      Res = 0;
  548.                    break;
  549.         case  0x0b00:   //定值区复制选择
  550.                    Setting_Copy.DzSelect = 0x00;
  551.                    Setting_Copy.DzSource = per2+0x17;
  552.                    Setting_Copy.DzTarget = per1+0x17;
  553.                    Setting_Copy.DzCommand = 0x82;
  554.                    Order_Array.Order[ Order_Array.Set ] = 0x0b00;
  555.                    Order_Array.Set = (Order_Array.Set+1)%10;
  556.                    command_statue.Setting_Operation_Flag = 0xaa;
  557.                    command_statue.Setting_Operation_Count = 0;
  558.                    break;
  559.         case  0x0b01:   //定值区复制执行
  560.                    if(Setting_Copy.DzSelect == 0x11)
  561.                      {
  562.                        Setting_Copy.DzSource = per2+0x17;
  563.                        Setting_Copy.DzTarget = per1+0x17;
  564.                        Setting_Copy.DzCommand = 0x02;
  565.                        Order_Array.Order[ Order_Array.Set ] = 0x0b00;
  566.                        Order_Array.Set = (Order_Array.Set+1)%10;
  567.                        command_statue.Setting_Operation_Flag = 0xaa;
  568.                        command_statue.Setting_Operation_Count = 0;
  569.                      }
  570.                    else
  571.                      Res = 0;
  572.                    break;
  573.         case  0x0b02:   //定值区复制撤销
  574.                    if(Setting_Copy.DzSelect == 0x11)
  575.                      {
  576.                        Setting_Copy.DzSource = per2+0x17;
  577.                        Setting_Copy.DzTarget = per1+0x17;
  578.                        Setting_Copy.DzCommand = 0xc2;
  579.                        Order_Array.Order[ Order_Array.Set ] = 0x0b00;
  580.                        Order_Array.Set = (Order_Array.Set+1)%10;
  581.                        command_statue.Setting_Operation_Flag = 0xaa;
  582.                        command_statue.Setting_Operation_Count = 0;
  583.                      }
  584.                    else
  585.                      Res = 0;
  586.                    break;
  587.         case  0x0c00:   //系统配置修改选择
  588.                    Order_Array.Order[ Order_Array.Set ] = 0x0c00;
  589.                    Order_Array.Set = (Order_Array.Set+1)%10;
  590.                    command_statue.Config_Operation_Flag = 0xaa;
  591.                    command_statue.Config_Operation_Count = 0;
  592.                    break;
  593.         case  0x0d00:   //系统配置修改执行
  594.                    Order_Array.Order[ Order_Array.Set ] = 0x0d00;
  595.                    Order_Array.Set = (Order_Array.Set+1)%10;
  596.                    command_statue.Config_Operation_Flag = 0xaa;
  597.                    command_statue.Config_Operation_Count = 0;
  598.                    break;
  599.         case  0x0e00:   //通道系数调整选择
  600.                    Channel_Ration_Flag.Select = 0x00;
  601.                    Channel_Ration_Flag.Command = per1&0xff;
  602.                    Order_Array.Order[ Order_Array.Set ] = 0x0e00;
  603.                    Order_Array.Set = (Order_Array.Set+1)%10;
  604.                    command_statue.Channel_Ration_Flag = 0xaa;
  605.                    command_statue.Channel_Ration_Count = 0x00;
  606.                    break;
  607.         case  0x0e01:   //通道系数调整执行
  608.                    if(Channel_Ration_Flag.Select == 0x11)
  609.                      {
  610.                        Channel_Ration_Flag.Command = per1&0xff;
  611.                        Order_Array.Order[ Order_Array.Set ] = 0x0e00;
  612.                        Order_Array.Set = (Order_Array.Set+1)%10;
  613.                        command_statue.Channel_Ration_Flag = 0xaa;
  614.                        command_statue.Channel_Ration_Count = 0x00;
  615.                      }
  616.                    else
  617.                      Res = 0;
  618.                    break;
  619.         case  0x0e02:   //通道系数调整撤销
  620.                    if(Channel_Ration_Flag.Select == 0x11)
  621.                      {
  622.                        Channel_Ration_Flag.Command = per1&0xff;
  623.                        Order_Array.Order[ Order_Array.Set ] = 0x0e00;
  624.                        Order_Array.Set = (Order_Array.Set+1)%10;
  625.                        command_statue.Channel_Ration_Flag = 0xaa;
  626.                        command_statue.Channel_Ration_Count = 0x00;
  627.                      }
  628.                    else
  629.                      Res = 0;
  630.                    break;
  631.         case  0x0f00:   //软压板操作选择
  632.                    YYB_Modify_Flag.Select = 0x00;
  633.                    YYB_Modify_Flag.Command = 0x82;
  634.                    YYB_Modify_Flag.YYB_temp = per1&0xffffffff;
  635.                    Order_Array.Order[ Order_Array.Set ] = 0x0f00;
  636.                    Order_Array.Set = (Order_Array.Set+1)%10;
  637.                    command_statue.YYB_Opreation_Flag = 0xaa;
  638.                    command_statue.YYB_Opreation_Count = 0x00;
  639.                    break;
  640.         case  0x0f01:   //软压板操作执行
  641.                    if(YYB_Modify_Flag.Select == 0x11)
  642.                      {
  643.                        YYB_Modify_Flag.Command = 0x02;
  644.                        YYB_Modify_Flag.YYB_temp = per1&0xffffffff;
  645.                        Order_Array.Order[ Order_Array.Set ] = 0x0f00;
  646.                        Order_Array.Set = (Order_Array.Set+1)%10;
  647.                        command_statue.YYB_Opreation_Flag = 0xaa;
  648.                        command_statue.YYB_Opreation_Count = 0x00;
  649.                      }
  650.                    else
  651.                      Res = 0;
  652.                    break;
  653.         case  0x0f02:   //软压板操作撤销
  654.                    if(YYB_Modify_Flag.Select == 0x11)
  655.                      {
  656.                        YYB_Modify_Flag.Command = 0xc2;
  657.                        YYB_Modify_Flag.YYB_temp = per1&0xffffffff;
  658.                        Order_Array.Order[ Order_Array.Set ] = 0x0f00;
  659.                        Order_Array.Set = (Order_Array.Set+1)%10;
  660.                        command_statue.YYB_Opreation_Flag = 0xaa;
  661.                        command_statue.YYB_Opreation_Count = 0x00;
  662.                      }
  663.                    else
  664.                      Res = 0;
  665.                    break;
  666.         case  0x1000:   //修改密码
  667.                    Order_Array.Order[ Order_Array.Set ] = 0x1000;
  668.                    Order_Array.Set = (Order_Array.Set+1)%10;
  669.                    command_statue.Password_Modified_Flag = 0xaa;
  670.                    command_statue.Password_Modified_Count = 0;
  671.                    break;
  672.         case  0x1100:   //开出传动选择
  673.                    YK_Command_Style(per1,0x11,0x55);
  674.                    Output_Test_YK.YkSelect = 0;
  675.                    Order_Array.Order[ Order_Array.Set ] = 0x1100;
  676.                    Order_Array.Set = (Order_Array.Set+1)%10;
  677.                    command_statue.YK_Output_Command_Flag = 0xaa;
  678.                    command_statue.YK_Output_Command_Count = 0;
  679.                    break;
  680.         case  0x1101:   //开出传动执行
  681.                    if(Output_Test_YK.YkSelect == 0x11)
  682.                      {
  683.                        YK_Command_Style(per1,0x11,0xAA);
  684.                        Output_Test_YK.YkSelect = 0;
  685.                        Order_Array.Order[ Order_Array.Set ] = 0x1100;
  686.                        Order_Array.Set = (Order_Array.Set+1)%10;
  687.                        command_statue.YK_Output_Command_Flag = 0xaa;
  688.                        command_statue.YK_Output_Command_Count = 0;
  689.                      }
  690.                    else
  691.                      Res = 0;
  692.                    break;
  693.         case  0x1102:   //开出传动撤销
  694.                    if(Output_Test_YK.YkSelect == 0x11)
  695.                      {
  696.                        YK_Command_Style(per1,0x11,0xcc);
  697.                        Output_Test_YK.YkSelect = 0;
  698.                        Order_Array.Order[ Order_Array.Set ] = 0x1100;
  699.                        Order_Array.Set = (Order_Array.Set+1)%10;
  700.                        command_statue.YK_Output_Command_Flag = 0xaa;
  701.                        command_statue.YK_Output_Command_Count = 0;
  702.                      }
  703.                    else
  704.                      Res = 0;
  705.                    break;
  706.         case  0x1110:   //遥控合选择
  707.                    YK_Command_Style(per1,0x11,0x55);
  708.                    Output_Test_YK.YkSelect = 0;
  709.                    Order_Array.Order[ Order_Array.Set ] = 0x1100;
  710.                    Order_Array.Set = (Order_Array.Set+1)%10;
  711.                    command_statue.YK_Output_Command_Flag = 0xaa;
  712.                    command_statue.YK_Output_Command_Count = 0;
  713.                    break;
  714.         case  0x1111:   //遥控合执行
  715.                    if(Output_Test_YK.YkSelect == 0x11)
  716.                      {
  717.                        YK_Command_Style(per1,0x11,0xaa);
  718.                        Output_Test_YK.YkSelect = 0;
  719.                        Order_Array.Order[ Order_Array.Set ] = 0x1100;
  720.                        Order_Array.Set = (Order_Array.Set+1)%10;
  721.                        command_statue.YK_Output_Command_Flag = 0xaa;
  722.                        command_statue.YK_Output_Command_Count = 0;
  723.                      }
  724.                    else
  725.                      Res = 0;
  726.                    break;
  727.         case  0x1112:   //遥控合撤销
  728.                    if(Output_Test_YK.YkSelect == 0x11)
  729.                      {
  730.                        YK_Command_Style(per1,0x11,0xcc);
  731.                        Output_Test_YK.YkSelect = 0;
  732.                        Order_Array.Order[ Order_Array.Set ] = 0x1100;
  733.                        Order_Array.Set = (Order_Array.Set+1)%10;
  734.                        command_statue.YK_Output_Command_Flag = 0xaa;
  735.                        command_statue.YK_Output_Command_Count = 0;
  736.                      }
  737.                    else
  738.                      Res = 0;
  739.                    break;
  740.         case  0x1120:   //遥控分选择
  741.                    YK_Command_Style(per1,0x22,0x55);
  742.                    Output_Test_YK.YkSelect = 0;
  743.                    Order_Array.Order[ Order_Array.Set ] = 0x1100;
  744.                    Order_Array.Set = (Order_Array.Set+1)%10;
  745.                    command_statue.YK_Output_Command_Flag = 0xaa;
  746.                    command_statue.YK_Output_Command_Count = 0;
  747.                    break;
  748.         case  0x1121:   //遥控分执行
  749.                    if(Output_Test_YK.YkSelect == 0x11)
  750.                      {
  751.                        YK_Command_Style(per1,0x22,0xaa);
  752.                        Output_Test_YK.YkSelect = 0;
  753.                        Order_Array.Order[ Order_Array.Set ] = 0x1100;
  754.                        Order_Array.Set = (Order_Array.Set+1)%10;
  755.                        command_statue.YK_Output_Command_Flag = 0xaa;
  756.                        command_statue.YK_Output_Command_Count = 0;
  757.                      }
  758.                    else
  759.                      Res = 0;
  760.                    break;
  761.         case  0x1122:   //遥控分撤销
  762.                    if(Output_Test_YK.YkSelect == 0x11)
  763.                      {
  764.                        YK_Command_Style(per1,0x22,0xcc);
  765.                        Output_Test_YK.YkSelect = 0;
  766.                        Order_Array.Order[ Order_Array.Set ] = 0x1100;
  767.                        Order_Array.Set = (Order_Array.Set+1)%10;
  768.                        command_statue.YK_Output_Command_Flag = 0xaa;
  769.                        command_statue.YK_Output_Command_Count = 0;
  770.                      }
  771.                    else
  772.                      Res = 0;
  773.                    break;
  774.         case  0x1200:   //查询SOE及故障报告
  775.                    Fault_Recode_Flag.Number = per1; 
  776.                    Fault_Recode_Flag.Type = per2;
  777.                    Order_Array.Order[ Order_Array.Set ] = 0x1200;
  778.                    Order_Array.Set = (Order_Array.Set+1)%10;
  779.                    command_statue.Demand_Soe_Report_Flag = 0xaa;
  780.                    command_statue.Demand_Soe_Report_Count = 0x00;
  781.                    break;
  782.         case  0x1300:   //装置复归
  783.                    Order_Array.Order[ Order_Array.Set ] = 0x1300;
  784.                    Order_Array.Set = (Order_Array.Set+1)%10;
  785.                    command_statue.Device_FUGUI_Flag = 0xaa;
  786.                    command_statue.Device_FUGUI_Count = 0x00;
  787.                    break;
  788.         case  0x1500:   //装置复归
  789.                    Order_Array.Order[ Order_Array.Set ] = 0x1500;
  790.                    Order_Array.Set = (Order_Array.Set+1)%10;
  791.                    break;
  792.        default:
  793.                    break;
  794.      }
  795.    return(Res);
  796. }
  797. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
  798. //     组装并发送固定帧
  799. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
  800. void SendFixFrm(UC SFunCode)
  801. {
  802.   int   i;
  803.   comm_buf_flag->Sendbuf[0] = 0x10;
  804.   comm_buf_flag->Sendbuf[1] = (SFunCode & 0x0F) + (comm_buf_flag->FCB& 0x20) 
  805.                             + (comm_buf_flag->FCV& 0x10) + 0x40;
  806.   comm_buf_flag->Sendbuf[2] = comm_buf_flag->DeviceAddr;
  807.   comm_buf_flag->Sendbuf[3] = comm_buf_flag->Sendbuf[1] + comm_buf_flag->Sendbuf[2];
  808.   comm_buf_flag->Sendbuf[4] = 0x16;
  809.   
  810.   comm_buf_flag->Length = 5;
  811.   ComSend();
  812.   
  813.   for(i=0;i<comm_buf_flag->Length;i++)
  814.    comm_buf_flag->TempBuf[i] = comm_buf_flag->Sendbuf[i];
  815.    
  816.   comm_buf_flag->FCB = comm_buf_flag->FCB^0x20;
  817. }
  818. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
  819. //     组装并发送可变帧
  820. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
  821. void  SendValFrm(UC SFunCode, UC len )
  822. {
  823.   int i;
  824.   comm_buf_flag->Sendbuf[0] = comm_buf_flag->Sendbuf[3] = 0x68;
  825.   comm_buf_flag->Sendbuf[1] = len+2;
  826.   comm_buf_flag->Sendbuf[2] = comm_buf_flag->Sendbuf[1];
  827.   comm_buf_flag->Sendbuf[4] = (SFunCode & 0x0F) + (comm_buf_flag->FCB& 0x20) 
  828.                             + (comm_buf_flag->FCV& 0x10) + 0x40;
  829.                             
  830.   comm_buf_flag->Sendbuf[5] =  comm_buf_flag->DeviceAddr;
  831.   comm_buf_flag->Sendbuf[6+len] = comm_buf_flag->Sendbuf[4] + comm_buf_flag->Sendbuf[5] ;
  832.   for(i=0; i<len; i++)
  833.     {
  834.       comm_buf_flag->Sendbuf[6+len] =  comm_buf_flag->Sendbuf[6+len] + comm_buf_flag->Sendbuf[6+i];
  835.     }
  836.    comm_buf_flag->Sendbuf[7+len] = 0x16;
  837.   comm_buf_flag->Length = 8+len;
  838.   ComSend(); 
  839.   
  840.   for(i=0;i<comm_buf_flag->Length;i++)
  841.    comm_buf_flag->TempBuf[i] = comm_buf_flag->Sendbuf[i];
  842.    
  843.   comm_buf_flag->FCB = comm_buf_flag->FCB^0x20;
  844. }
  845. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
  846. //     链路层通信处理
  847. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
  848. void   LPDU_MMI_DSP_Send(void)
  849. {
  850.    if(comm_buf_flag->Timing >= DELAYACK)
  851.      {
  852.         comm_buf_flag->Timing = 0;
  853.         if(comm_buf_flag->Counter>=6)
  854.          {
  855.            comm_buf_flag->Counter = 6;
  856.            comm_buf_flag->LPDU_Command = 0x09;
  857.            ComDsp_buf_flag.CommError = 0x11;
  858.          }
  859.         else if( comm_buf_flag->ACD == 0x20 )
  860.            comm_buf_flag->LPDU_Command = 0x0a;
  861.         else if( comm_buf_flag->LPDU_Command == 0x0b )
  862.          {
  863.              if( Order_Array.Set != Order_Array.Get)  //有其他命令
  864.                {
  865.                  comm_buf_flag->SendSeq = Order_Array.Order[Order_Array.Get];
  866.                  Order_Array.Order[Order_Array.Get] = 0xFF00;
  867.                  Order_Array.Get=(Order_Array.Get+1)%10;
  868.                  ProcessMMI_DSP();
  869.                }
  870.          }
  871.         switch( comm_buf_flag->LPDU_Command )
  872.            {
  873.               case  0x00:    comm_buf_flag->FCV = 0;
  874.                              SendFixFrm( 0x00 );
  875.                              break;
  876.               case  0x03:    comm_buf_flag->FCV = 1;
  877.                              SendValFrm( 0x03,comm_buf_flag->ASDU_Length );
  878.                              break;
  879.               case  0x04:    comm_buf_flag->FCV = 0;
  880.                              SendValFrm( 0x04,comm_buf_flag->ASDU_Length );
  881.                              break;
  882.               case  0x07:    comm_buf_flag->FCV = 0;
  883.                              SendFixFrm( 0x07 );
  884.                              break;
  885.               case  0x09:    comm_buf_flag->FCV = 0;
  886.                              SendFixFrm( 0x09 );
  887.                              break;
  888.               case  0x0a:    comm_buf_flag->FCV = 1;
  889.                              SendFixFrm( 0x0a );
  890.                              comm_buf_flag->LPDU_Command = 0x0b;
  891.                              break;
  892.               case  0x0b:    comm_buf_flag->FCV = 1;
  893.                              SendFixFrm( 0x0b );
  894.                              break;
  895.               default:       comm_buf_flag->LPDU_Command = 9;
  896.                              break;
  897.            }
  898.          comm_buf_flag->Timing = 0;
  899.          comm_buf_flag->Counter++;
  900.       }
  901. }
  902. void   LPDU_MMI_DSP_Recv(void)
  903. {
  904. int i;
  905.     if( comm_buf_flag->FrameRecv == 0x15)
  906.       {
  907.         comm_buf_flag->FrameRecv = 0;
  908.         ComDsp_buf_flag.CommError = 0x00;
  909.         comm_buf_flag->Counter = 0;
  910.         comm_buf_flag->ACD = (comm_buf_flag->RecvBuf[1]&0x20);
  911.         switch( comm_buf_flag->RecvBuf[1]&0x0f)
  912.           {
  913.              case 0x00:
  914.                         if( comm_buf_flag->LPDU_Command == 0x03)
  915.                          {
  916.                           comm_buf_flag->LPDU_Command = 0x0b;
  917.                           comm_buf_flag->Counter = 0;
  918.                          }
  919.                         break;
  920.              case 0x01:
  921.                         break;
  922.              case 0x09: comm_buf_flag->LPDU_Command = 0x0b;
  923.                         break;
  924.              case 0x0b:
  925.                         break;
  926.              default:
  927.                         break;
  928.           }
  929.          if(PC_Comm_Flag == 0x00)
  930.            {
  931.                  Comm0.SendBuf[Comm0.SendSet] =  comm_buf_flag->Sendbuf[i];
  932.                  Comm0.SendSet = (Comm0.SendSet+1)%SENDNUM;
  933.            }
  934.       }
  935.     else  if( comm_buf_flag->FrameRecv == 0x1a)
  936.       {
  937.         comm_buf_flag->FrameRecv = 0;
  938.         ComDsp_buf_flag.CommError = 0x00;
  939.         comm_buf_flag->Counter = 0;
  940.         comm_buf_flag->ACD = (comm_buf_flag->RecvBuf[4]&0x20);
  941.         switch( comm_buf_flag->RecvBuf[4]&0x0f)
  942.           {
  943.               case 0x08: ASDU_Analyze();
  944.                          break;
  945.               default:
  946.                          break;
  947.           }
  948.       }
  949. }
  950.    
  951. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
  952. //     MMI和DSP通信处理
  953. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++
  954. void   ProcessMMI_DSP(void)
  955. {
  956.    switch(comm_buf_flag->SendSeq>>8)               //发送处理
  957.      {
  958.       case  0x01:  //总召唤
  959.                    Call_WholeData();
  960.                  break;
  961.       case  0x02:  //对时
  962.                  Check_Time();
  963.                  break;
  964.       case  0x05:  //读系统参数
  965.                    Read_SystemConfig();
  966.                    break;
  967.         case  0x06:   //读定值
  968.                    Read_SystemSetting();
  969.                    break;
  970.         case  0x07:   //自动调整通道系数
  971.                    Auto_Adjust_Ration();
  972.                    break;
  973.         case  0x08:   //定值预修改
  974.                    Setting_PreModify();
  975.                    break;
  976.         case  0x09:   //定值修改执行
  977.                    Setting_Modified_Exe();
  978.                    break;
  979.         case  0x0a:   //定值区号切换
  980.                    Setting_Area_Switch();
  981.                    break;
  982.         case  0x0b:   //定值区复制
  983.                    Setting_Area_Copy();
  984.                    break;
  985.         case  0x0c:   //系统配置修改选择
  986.                    Config_PreModify();
  987.                    break;
  988.         case  0x0d:   //系统配置修改执行
  989.                    Config_Modified_Exe();
  990.                    break;
  991.         case  0x0e:   //通道系数调整
  992.                    Modify_Channel_Ration();
  993.                    break;
  994.         case  0x0f:   //软压板操作
  995.                    YYB_Opreation();
  996.                    break;
  997.         case  0x10:   //修改密码
  998.                    Password_Modified_Exe();
  999.                    break;
  1000.         case  0x11:   //遥控及开出传动
  1001.                    YK_Output_Command();
  1002.                    break;
  1003.         case  0x12:   //查询SOE及故障报告
  1004.                    Demand_Soe_Report();
  1005.                    break;
  1006.         case  0x13:   //装置复归
  1007.                    Device_FUGUI();
  1008.                    break;
  1009.       default:
  1010.                    comm_buf_flag->SendSeq = 0x0300;
  1011.                  break;
  1012.       }
  1013. }
  1014. //-------------------------------------------------------
  1015. //                   总召唤
  1016. //-------------------------------------------------------              
  1017. void   Call_WholeData(void)
  1018. {
  1019.      ASDU_07_Send();
  1020. }
  1021. //-------------------------------------------------------
  1022. //                   对时命令
  1023. //-------------------------------------------------------              
  1024. void   Check_Time(void)
  1025. {
  1026.     if(comm_buf_flag->SendSeq==0x0200)
  1027.     ASDU_06_Send0();
  1028.     else   
  1029.         ASDU_06_Send1();
  1030. }
  1031. //-----------------------------------------------------------
  1032. //                   读系统配置
  1033. //-----------------------------------------------------------
  1034. void   Read_SystemConfig(void)
  1035. {
  1036.     ASDU_21_Send0(0x16);  //ASDU_10_Send0();
  1037. }
  1038. //-----------------------------------------------------------
  1039. //                   读定值
  1040. //-----------------------------------------------------------
  1041. void   Read_SystemSetting(void)
  1042. {
  1043.    ASDU_21_Send0(comm_buf_flag->DzAreaNo);
  1044. }
  1045. //-----------------------------------------------------------
  1046. //                   自动调整通道系数
  1047. //-----------------------------------------------------------
  1048. void   Auto_Adjust_Ration(void)
  1049. {
  1050.    ASDU_20_Send7();
  1051. }
  1052. //-----------------------------------------------------------
  1053. //                   通道系数调整
  1054. //-----------------------------------------------------------
  1055. void   Modify_Channel_Ration(void)
  1056. {
  1057.     ASDU_20_Send8();
  1058. }
  1059. //-----------------------------------------------------------
  1060. //                   定值预修改
  1061. //-----------------------------------------------------------
  1062. void   Setting_PreModify(void)
  1063. {
  1064.     ASDU_10_Send2(0x11);
  1065. }
  1066. //-----------------------------------------------------------
  1067. //                   定值修改执行
  1068. //-----------------------------------------------------------
  1069. void   Setting_Modified_Exe(void)
  1070. {
  1071.     ASDU_10_Send2(0x22);
  1072. }
  1073. //-----------------------------------------------------------
  1074. //                   定值区号切换
  1075. //-----------------------------------------------------------
  1076. void   Setting_Area_Switch(void)
  1077. {
  1078.     ASDU_20_Send0();
  1079. }
  1080. //-----------------------------------------------------------
  1081. //                   软压板操作
  1082. //-----------------------------------------------------------
  1083. void   YYB_Opreation(void)
  1084. {
  1085.     ASDU_20_Send4();
  1086. }
  1087. //-----------------------------------------------------------
  1088. //                   定值区复制
  1089. //-----------------------------------------------------------
  1090. void   Setting_Area_Copy(void)
  1091. {
  1092.    ASDU_20_Send1();
  1093. }
  1094. //-----------------------------------------------------------
  1095. //                   系统配置预修改
  1096. //-----------------------------------------------------------
  1097. void   Config_PreModify(void)
  1098. {
  1099.    ASDU_10_Send3(0x11);
  1100. }
  1101. //-----------------------------------------------------------
  1102. //                   系统配置修改执行
  1103. //-----------------------------------------------------------
  1104. void   Config_Modified_Exe(void)
  1105. {
  1106.     ASDU_10_Send3(0x22);
  1107. }
  1108. //-----------------------------------------------------------
  1109. //                   修改密码
  1110. //-----------------------------------------------------------
  1111. void   Password_Modified_Exe(void)
  1112. {
  1113.      ASDU_05_Send1();
  1114. }
  1115. //-----------------------------------------------------------
  1116. //             遥控/开出传动
  1117. //-----------------------------------------------------------
  1118. void   YK_Output_Command(void)
  1119. {
  1120.    ASDU_64_Send0();  //ASDU_20_Send2();
  1121. }
  1122. //-----------------------------------------------------------
  1123. //             查询SOE及故障报告
  1124. //-----------------------------------------------------------
  1125. void   Demand_Soe_Report(void)
  1126. {
  1127.   ASDU_20_Send5();
  1128. }
  1129. //-----------------------------------------------------------
  1130. //                  装置复归
  1131. //-----------------------------------------------------------
  1132. void   Device_FUGUI(void)
  1133. {
  1134.   ASDU_20_Send3();
  1135. }
  1136. //-----------------------------------------------------------
  1137. //                      ASDU1(SOE)
  1138. //-----------------------------------------------------------
  1139. void   ADSU_01_Analyze(void)
  1140. {
  1141.       switch(comm_buf_flag->RecvBuf[11])
  1142.            {
  1143.              case 0x17:
  1144.              case 0x18:
  1145.              case 0x19:
  1146.              case 0x1a:
  1147.                   if(comm_buf_flag->RecvBuf[11]==Setting_Switch.DzTarget )
  1148.                     {
  1149.                       if( comm_buf_flag->RecvBuf[12]==0x82)  //定值预切换
  1150.                         {
  1151.                          //Memo1->Lines->Add("================定值预切换================");
  1152.                          Setting_Switch.DzSelect = 0x11;
  1153.                          command_statue.Setting_Operation_Flag = 0x00;
  1154.                         }
  1155.                       if( comm_buf_flag->RecvBuf[12]==0xc2)  //定值切换
  1156.                         {
  1157.                          // Memo1->Lines->Add("===============定值切换撤销===============");
  1158.                           command_statue.Setting_Operation_Flag = 0x00;
  1159.                         }
  1160.                       if( comm_buf_flag->RecvBuf[12]==0x02)  //定值切换
  1161.                         {
  1162.                           command_statue.Setting_Operation_Flag = 0x00;
  1163.                          // Memo1->Lines->Add("===============定值切换成功===============");
  1164.                         }
  1165.                     }
  1166.                   break;
  1167.              case 0x16:
  1168.                   if(( comm_buf_flag->RecvBuf[18]==Setting_Copy.DzSource) && (comm_buf_flag->RecvBuf[19]==Setting_Copy.DzTarget ))
  1169.                     {
  1170.                        if( comm_buf_flag->RecvBuf[12]==0x82 )  //定值预复制成功
  1171.                         {
  1172.                          //Memo1->Lines->Add("================定值预复制================");
  1173.                          Setting_Copy.DzSelect = 0x11;
  1174.                          command_statue.Setting_Operation_Flag = 0x00;
  1175.                         }
  1176.                        if( comm_buf_flag->RecvBuf[12]==0xc2 )  //定值复制撤销
  1177.                         {
  1178.                          command_statue.Setting_Operation_Flag = 0x00;
  1179.                         // Memo1->Lines->Add("================定值复制撤销================");
  1180.                         }
  1181.                        if( comm_buf_flag->RecvBuf[12]==0x02 )  //定值复制成功
  1182.                         {
  1183.                          command_statue.Setting_Operation_Flag = 0x00;
  1184.                         // Memo1->Lines->Add("================定值复制成功================");
  1185.                         }
  1186.                     }
  1187.                   break;
  1188.              default://故障报告
  1189.                   break;
  1190.            }
  1191.          SOE_Buf_Show0.msec = (comm_buf_flag->RecvBuf[14]*256 + comm_buf_flag->RecvBuf[13])%1000;
  1192.          SOE_Buf_Show0.sec  = (US)((comm_buf_flag->RecvBuf[14]*256 + comm_buf_flag->RecvBuf[13])/1000);
  1193.          SOE_Buf_Show0.min  = comm_buf_flag->RecvBuf[15]; //min
  1194.          SOE_Buf_Show0.hour = comm_buf_flag->RecvBuf[16]; //hour
  1195.          SOE_Buf_Show0.day  = comm_buf_flag->RecvBuf[17]; //day
  1196.          SOE_Buf_Show0.mon  = comm_buf_flag->RecvBuf[18]; //mon
  1197.          SOE_Buf_Show0.year = comm_buf_flag->RecvBuf[19]; //year
  1198.          SOE_Buf_Show0.num  = comm_buf_flag->RecvBuf[11]; //NO.
  1199.          SOE_Buf_Show0.stu  = comm_buf_flag->RecvBuf[12];
  1200.          
  1201.          if(comm_buf_flag->RecvBuf[8]==0x01)
  1202.             New_Information_Flag = 1;        //20r1
  1203.             
  1204.          command_statue.Demand_Soe_Report_Flag = 0x00;
  1205.   
  1206. }
  1207. //-----------------------------------------------------------
  1208. //                      ASDU5
  1209. //-----------------------------------------------------------
  1210. void   ASDU_05_Send1(void)    //修改密码
  1211. {
  1212.        comm_buf_flag->Sendbuf[6]=0x05;
  1213.        comm_buf_flag->Sendbuf[7]=0x81;
  1214.        comm_buf_flag->Sendbuf[8]=0x66;
  1215.        comm_buf_flag->Sendbuf[9]=comm_buf_flag->DeviceAddr;
  1216.        comm_buf_flag->Sendbuf[10]=FUNTYPE;
  1217.        comm_buf_flag->Sendbuf[11]=0xff;
  1218.        comm_buf_flag->Sendbuf[12]=0x66;
  1219.        comm_buf_flag->Sendbuf[13]=(unsigned char )(System_Info.Password10&0xff);
  1220.        comm_buf_flag->Sendbuf[14]=(unsigned char )((System_Info.Password10>>8)&0xff);
  1221.        comm_buf_flag->Sendbuf[15]=(unsigned char )((System_Info.Password10>>16)&0xff);
  1222.        comm_buf_flag->Sendbuf[16]=(unsigned char )(System_Info.Password20&0xff);
  1223.        comm_buf_flag->Sendbuf[17]=(unsigned char )((System_Info.Password20>>8)&0xff);
  1224.        comm_buf_flag->Sendbuf[18]=(unsigned char )((System_Info.Password20>>16)&0xff);
  1225.        comm_buf_flag->Sendbuf[19]=0xfe;
  1226.        comm_buf_flag->FunctionCode = 3;     //功能码
  1227.        comm_buf_flag->LPDU_Command = 3;
  1228.        comm_buf_flag->ASDU_Length = 14;
  1229. }
  1230. void   ASDU_05_Analyze(void)
  1231. {
  1232.         switch(comm_buf_flag->Sendbuf[12])
  1233.            {
  1234.                 case 0x66: //密码修改成功
  1235.                           command_statue.Password_Modified_Flag = 0x00;
  1236.                           break;
  1237.                 default:
  1238.                           SoftInformation.Model[0] = comm_buf_flag->RecvBuf[13];
  1239.                           SoftInformation.Model[1] = comm_buf_flag->RecvBuf[14];
  1240.                           SoftInformation.Model[2] = comm_buf_flag->RecvBuf[15];
  1241.                           SoftInformation.Model[3] = comm_buf_flag->RecvBuf[16];
  1242.                           SoftInformation.Model[4] = comm_buf_flag->RecvBuf[17];
  1243.                           SoftInformation.Model[5] = comm_buf_flag->RecvBuf[18];
  1244.                           SoftInformation.Model[6] = comm_buf_flag->RecvBuf[19];
  1245.                           SoftInformation.Year =  comm_buf_flag->RecvBuf[20];
  1246.                           SoftInformation.Month=  comm_buf_flag->RecvBuf[21];
  1247.                           SoftInformation.Day  =  comm_buf_flag->RecvBuf[22];
  1248.                           SoftInformation.Ver[0] =  comm_buf_flag->RecvBuf[23]+0x30;
  1249.                           SoftInformation.Ver[1] =  0x2e;
  1250.                           SoftInformation.Ver[2] =  comm_buf_flag->RecvBuf[25]+0x30;
  1251.                           
  1252.                           break;
  1253.           }
  1254. }
  1255. //-----------------------------------------------------------
  1256. //                      ASDU6(对时)
  1257. //-----------------------------------------------------------
  1258. void   ASDU_06_Send0(void)
  1259. {
  1260.          comm_buf_flag->Sendbuf[6] = 0x06;
  1261.          comm_buf_flag->Sendbuf[7] = 0x81;
  1262.          comm_buf_flag->Sendbuf[8] = 0x88;        //传输原因 08-对时 88-修改
  1263.          comm_buf_flag->Sendbuf[9] = comm_buf_flag->DeviceAddr;
  1264.          comm_buf_flag->Sendbuf[10]= FUNTYPE;
  1265.          comm_buf_flag->Sendbuf[11]= 0x00;
  1266.          comm_buf_flag->Sendbuf[12]= realtime.msecond & 0xff;         //msl
  1267.          comm_buf_flag->Sendbuf[13]= (realtime.msecond & 0xff00)>>8; //msh
  1268.          comm_buf_flag->Sendbuf[14]= realtime.minute;         //minutes
  1269.          comm_buf_flag->Sendbuf[15]= realtime.hour;         //hours
  1270.          comm_buf_flag->Sendbuf[16]= realtime.day;         //date
  1271.          comm_buf_flag->Sendbuf[17]= realtime.month;         //months
  1272.          comm_buf_flag->Sendbuf[18]= realtime.year;         //years
  1273.          comm_buf_flag->FunctionCode = 3;     //功能码
  1274.          comm_buf_flag->LPDU_Command = 3;
  1275.          comm_buf_flag->ASDU_Length = 13;
  1276.          comm_buf_flag->Flag_CheckTime = 0x00;
  1277. }
  1278. void   ASDU_06_Send1(void)
  1279. {
  1280.          comm_buf_flag->Sendbuf[6] = 0x06;
  1281.          comm_buf_flag->Sendbuf[7] = 0x81;
  1282.          comm_buf_flag->Sendbuf[8] = 0x08;        //传输原因 08-对时 88-修改
  1283.          comm_buf_flag->Sendbuf[9] = comm_buf_flag->DeviceAddr;
  1284.          comm_buf_flag->Sendbuf[10]= 0xff;
  1285.          comm_buf_flag->Sendbuf[11]= 0x00;
  1286.          comm_buf_flag->Sendbuf[12]= realtime1.msecond & 0xff;         //msl
  1287.          comm_buf_flag->Sendbuf[13]= (realtime1.msecond & 0xff00)>>8; //msh
  1288.          comm_buf_flag->Sendbuf[14]= realtime1.minute;         //minutes
  1289.          comm_buf_flag->Sendbuf[15]= realtime1.hour;         //hours
  1290.          comm_buf_flag->Sendbuf[16]= realtime1.day;         //date
  1291.          comm_buf_flag->Sendbuf[17]= realtime1.month;         //months
  1292.          comm_buf_flag->Sendbuf[18]= realtime1.year;         //years
  1293.          comm_buf_flag->FunctionCode = 3;     //功能码
  1294.          comm_buf_flag->LPDU_Command = 3;
  1295.          comm_buf_flag->ASDU_Length = 13;
  1296.          //SendValFrm( 0x03, 13 );
  1297. }
  1298. void   ASDU_06_Analyze(void)
  1299. {
  1300.       realtime.year    = comm_buf_flag->RecvBuf[18]; //YEAR
  1301.       realtime.month   = comm_buf_flag->RecvBuf[17]; //MONTH
  1302.       realtime.day     = comm_buf_flag->RecvBuf[16]; //DATE
  1303.       realtime.hour    = comm_buf_flag->RecvBuf[15]; //HOUR
  1304.       realtime.minute  = comm_buf_flag->RecvBuf[14]; //MIN
  1305.       realtime.msecond = (comm_buf_flag->RecvBuf[13]<<8) + comm_buf_flag->RecvBuf[12];
  1306.       command_statue.Check_Time_Flag = 0x00;
  1307. }
  1308. //------------------------------------------------------------
  1309. //                    ASDU7(总查询发送)
  1310. //------------------------------------------------------------
  1311. void   ASDU_07_Send(void)
  1312. {
  1313.       comm_buf_flag->Sendbuf[6]=0x07;
  1314.       comm_buf_flag->Sendbuf[7]=0x81;
  1315.       comm_buf_flag->Sendbuf[8]=0x09;
  1316.       comm_buf_flag->Sendbuf[9]=comm_buf_flag->DeviceAddr;
  1317.       comm_buf_flag->Sendbuf[10]=0xff;
  1318.       comm_buf_flag->Sendbuf[11]=0x00;
  1319.       comm_buf_flag->Sendbuf[12]=0x00;
  1320.       
  1321.        comm_buf_flag->FunctionCode = 3;     //功能码
  1322.        comm_buf_flag->LPDU_Command = 3;
  1323.        comm_buf_flag->ASDU_Length = 7;
  1324.       //SendValFrm( 0x03, 7 );
  1325.       comm_buf_flag->Flag_CallAll = 0;
  1326. }
  1327. //-----------------------------------------------------------
  1328. //                      定值操作
  1329. //-----------------------------------------------------------
  1330. ////////////////////////////////////////////////////////////////////////////////
  1331. void   ASDU_10_Send2(unsigned char Type)           //下传定值
  1332. {
  1333.   unsigned int i,j=0;
  1334.        comm_buf_flag->Sendbuf[6] = 0x0a;
  1335.        comm_buf_flag->Sendbuf[7] = 0x81;
  1336.        comm_buf_flag->Sendbuf[8] = 40;
  1337.        comm_buf_flag->Sendbuf[9] = comm_buf_flag->DeviceAddr;;
  1338.        comm_buf_flag->Sendbuf[10]= 254;
  1339.        comm_buf_flag->Sendbuf[12]= 0x00;   //
  1340.        comm_buf_flag->Sendbuf[13]= 0x01;
  1341.        comm_buf_flag->Sendbuf[14]= comm_buf_flag->DzAreaNo;
  1342.        comm_buf_flag->Sendbuf[15]= 0x00;
  1343.        comm_buf_flag->Sendbuf[16]= 0x01;
  1344.        comm_buf_flag->Sendbuf[17]= 0x03;
  1345.        comm_buf_flag->Sendbuf[18]= 0x02;
  1346.        comm_buf_flag->Sendbuf[19]= Setting_Total+1;
  1347.        if(Type == 0x11)
  1348.          {
  1349.            comm_buf_flag->Sendbuf[11]= 249;  //预修改
  1350.            for(i=0;i<Setting_Total;i++)
  1351.             {
  1352.               comm_buf_flag->Sendbuf[j + 20] = (unsigned char)(~System_setting[ i ]&0xff);
  1353.               comm_buf_flag->Sendbuf[j + 21] = (unsigned char)((~System_setting[ i ]>>8)&0xff);
  1354.               j++;
  1355.               j++;
  1356.             }
  1357.            comm_buf_flag->Sendbuf[j+20]= (unsigned char)(~(System_Info.DZ_Area+0x17));
  1358.            comm_buf_flag->Sendbuf[j+21]= 0xff;
  1359.          }
  1360.        else 
  1361.          {
  1362.            if(Type == 0x22)
  1363.              comm_buf_flag->Sendbuf[11]= 250;  //修改
  1364.            else
  1365.              comm_buf_flag->Sendbuf[11]= 251;  //未知
  1366.            for(i=0;i<Setting_Total;i++)
  1367.             {
  1368.               comm_buf_flag->Sendbuf[j + 20] = (unsigned char)(System_setting[ i ]&0xff);
  1369.               comm_buf_flag->Sendbuf[j + 21] = (unsigned char)((System_setting[ i ]>>8)&0xff);
  1370.               j++;
  1371.               j++;
  1372.             }
  1373.            comm_buf_flag->Sendbuf[j+20]= (unsigned char)(System_Info.DZ_Area+0x17);
  1374.            comm_buf_flag->Sendbuf[j+21]= 0x00;
  1375.          }
  1376.        comm_buf_flag->FunctionCode = 3;     //功能码
  1377.        comm_buf_flag->LPDU_Command = 3;
  1378.        comm_buf_flag->ASDU_Length = j + 16;
  1379.        //SendValFrm( 0x03, 80 );
  1380. }
  1381. void   ASDU_10_Send3(unsigned char Type)           //下传配置
  1382. {
  1383.   unsigned int i,j=0;
  1384.        comm_buf_flag->Sendbuf[6] = 0x0a;
  1385.        comm_buf_flag->Sendbuf[7] = 0x81;
  1386.        comm_buf_flag->Sendbuf[8] = 40;
  1387.        comm_buf_flag->Sendbuf[9] = comm_buf_flag->DeviceAddr;;
  1388.        comm_buf_flag->Sendbuf[10]= 254;
  1389.        comm_buf_flag->Sendbuf[12]= 0x00;   //
  1390.        comm_buf_flag->Sendbuf[13]= 0x01;
  1391.        comm_buf_flag->Sendbuf[14]= 0x16;
  1392.        comm_buf_flag->Sendbuf[15]= 0x00;
  1393.        comm_buf_flag->Sendbuf[16]= 0x01;
  1394.        comm_buf_flag->Sendbuf[17]= 0x03;
  1395.        comm_buf_flag->Sendbuf[18]= 0x02;
  1396.        comm_buf_flag->Sendbuf[19]= Sys_Cfg_Total+1;
  1397.        if(Type == 0x11)
  1398.          {
  1399.            comm_buf_flag->Sendbuf[11]= 249;  //预修改
  1400.            for(i=0;i<Sys_Cfg_Total;i++)
  1401.             {
  1402.               comm_buf_flag->Sendbuf[j + 20] = (unsigned char)(~System_config[ i ]&0xff);
  1403.               comm_buf_flag->Sendbuf[j + 21] = (unsigned char)((~System_config[ i ]>>8)&0xff);
  1404.               j++;
  1405.               j++;
  1406.             }
  1407.            comm_buf_flag->Sendbuf[j+20]= 0xe9;
  1408.            comm_buf_flag->Sendbuf[j+21]= 0xff;
  1409.          }
  1410.        else
  1411.          {
  1412.             if(Type == 0x22)
  1413.                comm_buf_flag->Sendbuf[11]= 250;  //修改
  1414.             else
  1415.                comm_buf_flag->Sendbuf[11]= 251;  //未知
  1416.            for(i=0;i<Sys_Cfg_Total;i++)
  1417.             {
  1418.               comm_buf_flag->Sendbuf[j + 20] = (unsigned char)(System_config[ i ]&0xff);
  1419.               comm_buf_flag->Sendbuf[j + 21] = (unsigned char)((System_config[ i ]>>8)&0xff);
  1420.               j++;
  1421.               j++;
  1422.             }
  1423.            comm_buf_flag->Sendbuf[j+20]= 0x16;
  1424.            comm_buf_flag->Sendbuf[j+21]= 0x00;
  1425.         }
  1426.        comm_buf_flag->FunctionCode = 3;     //功能码
  1427.        comm_buf_flag->LPDU_Command = 3;
  1428.        comm_buf_flag->ASDU_Length = j + 16;
  1429.        //SendValFrm( 0x03, 102 );
  1430. }
  1431. void   ASDU_10_Analyze(void)
  1432. {
  1433.    unsigned int i;
  1434.           if(comm_buf_flag->RecvBuf[14]==0x16 && comm_buf_flag->RecvBuf[11]==241 && comm_buf_flag->RecvBuf[8]==42) //读系统参数
  1435.             {
  1436.                 for(i=0;i<Sys_Cfg_Total;i++)
  1437.                   System_config[i] = comm_buf_flag->RecvBuf[20+2*i]+(comm_buf_flag->RecvBuf[21+2*i]<<8);
  1438.                 command_statue.Config_Operation_Flag = 0x00;
  1439.             }
  1440.           else  if(comm_buf_flag->RecvBuf[14]==comm_buf_flag->DzAreaNo && comm_buf_flag->RecvBuf[11]==241 && comm_buf_flag->RecvBuf[8]==42)
  1441.             {
  1442.                 for(i=0;i<Setting_Total;i++)
  1443.                   System_setting[i] = comm_buf_flag->RecvBuf[20+2*i]+(comm_buf_flag->RecvBuf[21+2*i]<<8);
  1444.                  command_statue.Setting_Operation_Flag = 0x00;
  1445.             }
  1446.           else if(comm_buf_flag->RecvBuf[14]==comm_buf_flag->DzAreaNo && comm_buf_flag->RecvBuf[11]==249 && comm_buf_flag->RecvBuf[8]==40)
  1447.             {
  1448.                 comm_buf_flag->DzSelect = 0x11;
  1449.                 command_statue.Setting_Operation_Flag = 0x00;
  1450.                        //预改定值成功
  1451.             }
  1452.           else if(comm_buf_flag->RecvBuf[14]==comm_buf_flag->DzAreaNo && comm_buf_flag->RecvBuf[11]==250 && comm_buf_flag->RecvBuf[8]==40)
  1453.             {
  1454.                     comm_buf_flag->DzSelect = 0x00;   //改定值成功
  1455.                     command_statue.Setting_Operation_Flag = 0x00;
  1456.              }
  1457.           else if(comm_buf_flag->RecvBuf[14]==comm_buf_flag->DzAreaNo && comm_buf_flag->RecvBuf[11]==250 && comm_buf_flag->RecvBuf[8]==41)
  1458.              {
  1459.                      comm_buf_flag->DzSelect = 0x00; 
  1460.                      command_statue.Setting_Operation_Flag = 0x55;  
  1461.               //break;
  1462.              }
  1463.           else if(comm_buf_flag->RecvBuf[14]==0x16 && comm_buf_flag->RecvBuf[11]==249 && comm_buf_flag->RecvBuf[8]==40)
  1464.             {
  1465.                 comm_buf_flag->DzSelect = 0x11;
  1466.                 command_statue.Config_Operation_Flag = 0x00;
  1467.             }
  1468.          else if(comm_buf_flag->RecvBuf[14]==0x16 && comm_buf_flag->RecvBuf[11]==250 && comm_buf_flag->RecvBuf[8]==40)
  1469.             {
  1470.                     comm_buf_flag->DzSelect = 0x00;   //改系统配置成功
  1471.                     command_statue.Config_Operation_Flag = 0x00;
  1472.               //break;
  1473.              }
  1474.           else if(comm_buf_flag->RecvBuf[14]==0x16 && comm_buf_flag->RecvBuf[11]==250 && comm_buf_flag->RecvBuf[8]==41)
  1475.              {
  1476.                      comm_buf_flag->DzSelect = 0x00; 
  1477.                      command_statue.Config_Operation_Flag = 0x55;  
  1478.               //break;
  1479.              }
  1480. }
  1481. //-----------------------------------------------------------
  1482. //                     遥控操作&通道系数
  1483. //-----------------------------------------------------------
  1484. void   ASDU_20_Send0(void)     //定值区号切换
  1485. {
  1486.     comm_buf_flag->Sendbuf[6]=0x14;
  1487.     comm_buf_flag->Sendbuf[7]=0x81;
  1488.     comm_buf_flag->Sendbuf[8]=0x11;
  1489.     comm_buf_flag->Sendbuf[9]=comm_buf_flag->DeviceAddr;
  1490.     comm_buf_flag->Sendbuf[10]=FUNTYPE;
  1491.     comm_buf_flag->Sendbuf[11]=Setting_Switch.DzTarget;
  1492.     comm_buf_flag->Sendbuf[12]=Setting_Switch.DzCommand;
  1493.     comm_buf_flag->Sendbuf[13]=0xa0;
  1494.        comm_buf_flag->FunctionCode = 3;     //功能码
  1495.        comm_buf_flag->LPDU_Command = 3;
  1496.        comm_buf_flag->ASDU_Length = 8;
  1497. }
  1498. void   ASDU_20_Send1(void)     //定制区复制
  1499. {
  1500.     comm_buf_flag->Sendbuf[6]=0x14;
  1501.     comm_buf_flag->Sendbuf[7]=0x81;
  1502.     comm_buf_flag->Sendbuf[8]=0x11;
  1503.     comm_buf_flag->Sendbuf[9]=comm_buf_flag->DeviceAddr;
  1504.     comm_buf_flag->Sendbuf[10]=FUNTYPE;
  1505.     comm_buf_flag->Sendbuf[11]=0x16;
  1506.     comm_buf_flag->Sendbuf[12]=Setting_Copy.DzCommand;
  1507.     comm_buf_flag->Sendbuf[13]=0xb0;
  1508.     comm_buf_flag->Sendbuf[14]=Setting_Copy.DzSource;
  1509.     comm_buf_flag->Sendbuf[15]=Setting_Copy.DzTarget;
  1510.        comm_buf_flag->FunctionCode = 3;     //功能码
  1511.        comm_buf_flag->LPDU_Command = 3;
  1512.        comm_buf_flag->ASDU_Length = 10;
  1513. }
  1514. void   ASDU_20_Send3(void)     //装置复归
  1515. {
  1516.     comm_buf_flag->Sendbuf[6 ] = 0x14;
  1517.     comm_buf_flag->Sendbuf[7 ] = 0x81;
  1518.     comm_buf_flag->Sendbuf[8 ] = 0x14;
  1519.     comm_buf_flag->Sendbuf[9 ] = comm_buf_flag->DeviceAddr;
  1520.     comm_buf_flag->Sendbuf[10] = 0xe0;
  1521.     comm_buf_flag->Sendbuf[11] = 0x13;
  1522.     comm_buf_flag->Sendbuf[12] = 0x02;
  1523.     comm_buf_flag->Sendbuf[13] = 0xee;
  1524.        comm_buf_flag->FunctionCode = 3;     //功能码
  1525.        comm_buf_flag->LPDU_Command = 3;
  1526.        comm_buf_flag->ASDU_Length = 8;
  1527.     //SendValFrm( 0x03, 8 );
  1528. }
  1529. void   ASDU_20_Send4(void)     //软压板投退
  1530. {
  1531.     comm_buf_flag->Sendbuf[6 ] = 0x14;
  1532.     comm_buf_flag->Sendbuf[7 ] = 0x81;
  1533.     comm_buf_flag->Sendbuf[8 ] = 0x11;
  1534.     comm_buf_flag->Sendbuf[9 ] = comm_buf_flag->DeviceAddr;
  1535.     comm_buf_flag->Sendbuf[10] = FUNTYPE;
  1536.     comm_buf_flag->Sendbuf[11] = 0x15;
  1537.     comm_buf_flag->Sendbuf[12] = YYB_Modify_Flag.Command;
  1538.     comm_buf_flag->Sendbuf[13] = 0xef;
  1539.     comm_buf_flag->Sendbuf[14] = (unsigned char)((YYB_Modify_Flag.YYB_temp&0xff));
  1540.     comm_buf_flag->Sendbuf[15] = (unsigned char)((YYB_Modify_Flag.YYB_temp>>8)&0xff);
  1541.     comm_buf_flag->Sendbuf[16] = (unsigned char)((YYB_Modify_Flag.YYB_temp>>16)&0xff);
  1542.     comm_buf_flag->Sendbuf[17] = 0;
  1543.     comm_buf_flag->FunctionCode = 3;     //功能码
  1544.     comm_buf_flag->LPDU_Command = 3;
  1545.     comm_buf_flag->ASDU_Length = 12;
  1546. }
  1547. void   ASDU_20_Send5(void)     //查询SOE及故障报告
  1548. {
  1549.     comm_buf_flag->Sendbuf[6 ] = 0x14;
  1550.     comm_buf_flag->Sendbuf[7 ] = 0x81;
  1551.     comm_buf_flag->Sendbuf[8 ] = 0x11;
  1552.     comm_buf_flag->Sendbuf[9 ] = comm_buf_flag->DeviceAddr;
  1553.     comm_buf_flag->Sendbuf[10] = FUNTYPE;
  1554.     comm_buf_flag->Sendbuf[11] = 0x20;
  1555.     comm_buf_flag->Sendbuf[12] = 0x02;
  1556.     comm_buf_flag->Sendbuf[13] = Fault_Recode_Flag.Type;
  1557.     comm_buf_flag->Sendbuf[14] = Fault_Recode_Flag.Number;
  1558.        comm_buf_flag->FunctionCode = 3;     //功能码
  1559.        comm_buf_flag->LPDU_Command = 3;
  1560.        comm_buf_flag->ASDU_Length = 9;
  1561. }
  1562. void   ASDU_20_Send7(void)    //自动调整系数
  1563. {
  1564.        comm_buf_flag->Sendbuf[6]=0x14;
  1565.        comm_buf_flag->Sendbuf[7]=0x81;
  1566.        comm_buf_flag->Sendbuf[8]=0x11;
  1567.        comm_buf_flag->Sendbuf[9]=comm_buf_flag->DeviceAddr;
  1568.        comm_buf_flag->Sendbuf[10]=FUNTYPE;
  1569.        comm_buf_flag->Sendbuf[11]=0x14;
  1570.        comm_buf_flag->Sendbuf[12]=Channel_Ration_Flag.Command;
  1571.        comm_buf_flag->Sendbuf[13]=0xfe;
  1572.        comm_buf_flag->FunctionCode = 3;     //功能码
  1573.        comm_buf_flag->LPDU_Command = 3;
  1574.        comm_buf_flag->ASDU_Length = 8;
  1575. }
  1576. void   ASDU_20_Send8(void)    //通道系数修改
  1577. {
  1578.        int i;
  1579.        comm_buf_flag->Sendbuf[6]=0x14;
  1580.        comm_buf_flag->Sendbuf[7]=0x81;
  1581.        comm_buf_flag->Sendbuf[8]=0x22;
  1582.        comm_buf_flag->Sendbuf[9]=comm_buf_flag->DeviceAddr;
  1583.        comm_buf_flag->Sendbuf[10]=FUNTYPE;
  1584.        comm_buf_flag->Sendbuf[11]=0x14;
  1585.        comm_buf_flag->Sendbuf[13]=0xfe;
  1586.        switch(Channel_Ration_Flag.Command)
  1587.          {
  1588.            case 0x81:  //读取并选择
  1589.            case 0x82:
  1590.                     comm_buf_flag->Sendbuf[12]=Channel_Ration_Flag.Command;
  1591.                     comm_buf_flag->FunctionCode = 3;     //功能码
  1592.                     comm_buf_flag->LPDU_Command = 3;
  1593.                     comm_buf_flag->ASDU_Length = 8;
  1594.                     break;
  1595.            case 0x01:  //修改执行
  1596.            case 0x02:
  1597.                     comm_buf_flag->Sendbuf[12]=Channel_Ration_Flag.Command;
  1598.                     for(i=0;i<CHANNEL_NUM;i++)
  1599.                      {
  1600.                        comm_buf_flag->Sendbuf[14+2*i] = (unsigned char)(Channel_Ration_Flag.Temp[i]&0xff);
  1601.                        comm_buf_flag->Sendbuf[15+2*i] = (unsigned char)((Channel_Ration_Flag.Temp[i]>>8)&0xff);
  1602.                       }
  1603.                     comm_buf_flag->FunctionCode = 3;     //功能码
  1604.                     comm_buf_flag->LPDU_Command = 3;
  1605.                     comm_buf_flag->ASDU_Length = 8+2*CHANNEL_NUM;
  1606.                     break;
  1607.            case 0xc1:   //修改撤销
  1608.            case 0xc2:
  1609.                     comm_buf_flag->Sendbuf[12]=Channel_Ration_Flag.Command;
  1610.                     comm_buf_flag->FunctionCode = 3;     //功能码
  1611.                     comm_buf_flag->LPDU_Command = 3;
  1612.                     comm_buf_flag->ASDU_Length = 8;
  1613.                     break;
  1614.          };
  1615. }
  1616. void   ASDU_20_Analyze(void)
  1617. {
  1618.   unsigned int i;
  1619.         switch(comm_buf_flag->RecvBuf[11])
  1620.            {
  1621.               case 0x14:
  1622.                  switch(comm_buf_flag->RecvBuf[12])
  1623.                   {
  1624.               case 0x81:
  1625.                      case 0x82:
  1626.                           for(i = 0;i < CHANNEL_NUM; i++)
  1627.                             Channel_Ration_Flag.Value[i] = comm_buf_flag->RecvBuf[14 + 2*i] +
  1628.                                                        (comm_buf_flag->RecvBuf[15 + 2*i]<<8) ;
  1629.                           Channel_Ration_Flag.Select = 0x11;
  1630.                           command_statue.Channel_Ration_Flag = 0x00;
  1631.                          
  1632.                           break;
  1633.                      case 0x01:
  1634.                      case 0x02:
  1635.                           //Memo1->Lines->Add("*****************通道系数修改完成********************");
  1636.                           for(i=0;i<CHANNEL_NUM;i++)
  1637.                              Channel_Ration_Flag.Value[i] = comm_buf_flag->RecvBuf[14 + 2*i] +
  1638.                                                        (comm_buf_flag->RecvBuf[15 + 2*i]<<8) ;
  1639.                           Channel_Ration_Flag.Select = 0x00;
  1640.                           command_statue.Channel_Ration_Flag = 0x00;
  1641.                          
  1642.                           break;
  1643.                      case 0xc1:
  1644.                      case 0xc2:
  1645.                           //Memo1->Lines->Add("*****************通道系数修改撤销********************");
  1646.                           for(i=0;i<CHANNEL_NUM;i++)
  1647.                             Channel_Ration_Flag.Temp[i] = Channel_Ration_Flag.Value[i];
  1648.                           Channel_Ration_Flag.Select = 0x00;
  1649.                           command_statue.Channel_Ration_Flag = 0x00;
  1650.                         
  1651.                           break;
  1652.                      case 0x21:
  1653.                      case 0x22: //自动调整系数
  1654.                           //Memo1->Lines->Add("*****************自动调整通道系数********************");
  1655.                           command_statue.Channel_Ration_Flag = 0x00;
  1656.                           break;
  1657.                      default:
  1658.                           break;
  1659.                     }
  1660.                    break;
  1661.               case 0x15:
  1662.                      if( comm_buf_flag->RecvBuf[12]==0x82 )
  1663.                        {
  1664.                          command_statue.YYB_Opreation_Flag = 0x00;
  1665.                          //Memo1->Lines->Add("===========软压板预修改===========");
  1666.                          YYB_Modify_Flag.Select = 0x11;
  1667.                        }
  1668.                      else if( comm_buf_flag->RecvBuf[12]==0x02 )
  1669.                        {
  1670.                           command_statue.YYB_Opreation_Flag = 0x00;
  1671.                           //Memo1->Lines->Add("========软压板修改执行成功=========");
  1672.                        }
  1673.                      else if( comm_buf_flag->RecvBuf[12]==0xc2 )
  1674.                        {
  1675.                           command_statue.YYB_Opreation_Flag = 0x00;
  1676.                           //Memo1->Lines->Add("===========软压板修改撤销===========");
  1677.                        }
  1678.                      break;
  1679.                 default:
  1680.                      break;
  1681.        }
  1682. }
  1683. //-----------------------------------------------------------
  1684. //                      定值操作
  1685. //-----------------------------------------------------------
  1686. void   ASDU_21_Send0(unsigned char Segment)                           //召唤系统配置/定值
  1687. {
  1688.        comm_buf_flag->Sendbuf[6] = 0x15;
  1689.        comm_buf_flag->Sendbuf[7] = 0x81;
  1690.        comm_buf_flag->Sendbuf[8] = 42;
  1691.        comm_buf_flag->Sendbuf[9] = comm_buf_flag->DeviceAddr;;
  1692.        comm_buf_flag->Sendbuf[10]= 254;
  1693.        comm_buf_flag->Sendbuf[11]= 241;
  1694.        comm_buf_flag->Sendbuf[12]= 0;
  1695.        comm_buf_flag->Sendbuf[13]= 0x01;
  1696.        comm_buf_flag->Sendbuf[14]= Segment;
  1697.        comm_buf_flag->Sendbuf[15]= 0x00;
  1698.        comm_buf_flag->Sendbuf[16]= 0x01;
  1699.        comm_buf_flag->FunctionCode = 3;     //功能码
  1700.        comm_buf_flag->LPDU_Command = 3;
  1701.        comm_buf_flag->ASDU_Length = 11;
  1702.        //SendValFrm( 0x03, 11 );
  1703. }
  1704. //-----------------------------------------------------------
  1705. //                        ASDU40(总查询)
  1706. //-----------------------------------------------------------
  1707. void   ASDU_40_Analyze(void)
  1708. {
  1709.       System_Info.LED_Statue = comm_buf_flag->RecvBuf[12]&0x7f;                                 //信号灯
  1710.       System_Info.YB_Soft    = comm_buf_flag->RecvBuf[14]*256+comm_buf_flag->RecvBuf[13];  //压板
  1711.       System_Info.YX[0]         = comm_buf_flag->RecvBuf[16]*256+comm_buf_flag->RecvBuf[15];  //遥信
  1712.       System_Info.DZ_Area    = comm_buf_flag->RecvBuf[17]-0x17;                                 //定值区号
  1713.       System_Info.Password1  = ( comm_buf_flag->RecvBuf[18] + (comm_buf_flag->RecvBuf[19]<<8)
  1714.                                + (comm_buf_flag->RecvBuf[20]<<16) );//1级密码
  1715.       System_Info.Password2  = ( comm_buf_flag->RecvBuf[21] + (comm_buf_flag->RecvBuf[22]<<8)
  1716.                                + (comm_buf_flag->RecvBuf[23]<<16) );//2级密码
  1717. }
  1718. //-----------------------------------------------------------
  1719. //                        ASDU50
  1720. //-----------------------------------------------------------
  1721. void   ASDU_50_Analyze(void)
  1722. {
  1723.    int i;
  1724.    
  1725.   
  1726.      {
  1727.           System_Info.YX[0]        = ( comm_buf_flag->RecvBuf[13]<<8 ) + comm_buf_flag->RecvBuf[12];
  1728.           System_Info.YX[1]        = ( comm_buf_flag->RecvBuf[15]<<8 ) + comm_buf_flag->RecvBuf[14];
  1729.           System_Info.YB_Soft      = ( comm_buf_flag->RecvBuf[17]<<8 ) + comm_buf_flag->RecvBuf[16]
  1730.                                    + ( comm_buf_flag->RecvBuf[19]<<24 ) + ( comm_buf_flag->RecvBuf[18]<<16);
  1731.           switch(comm_buf_flag->RecvBuf[10])
  1732.             {
  1733.                case  0x01:
  1734.                      for( i = 0; i < YC_Total; i++)
  1735.                   YC_Value[ i ] = ((comm_buf_flag->RecvBuf[21 + 2*i]<<8)+comm_buf_flag->RecvBuf[20 + 2*i]);
  1736.                      System_Info.LED_Statue =  comm_buf_flag->RecvBuf[20 + 2*YC_Total];                           //state
  1737.                      System_Info.SYS_Statue =  comm_buf_flag->RecvBuf[21 + 2*YC_Total];                           //state
  1738.                      System_Info.DZ_Area    =  comm_buf_flag->RecvBuf[22 + 2*YC_Total];                           //state
  1739.                      break;
  1740.                case  0x02:
  1741.                      for( i = 0; i < YC1_Total; i++)
  1742.                   YC_Value1[ i ] = ((comm_buf_flag->RecvBuf[21 + 2*i]<<8)+comm_buf_flag->RecvBuf[20 + 2*i]);
  1743.                      System_Info.LED_Statue =  comm_buf_flag->RecvBuf[20 + 2*YC1_Total];                           //state
  1744.                      System_Info.SYS_Statue =  comm_buf_flag->RecvBuf[21 + 2*YC1_Total];                           //state
  1745.                      System_Info.DZ_Area    =  comm_buf_flag->RecvBuf[22 + 2*YC1_Total];                           //state
  1746.                      break;
  1747.             }
  1748.      }
  1749. }
  1750. //-----------------------------------------------------------
  1751. //                        ASDU64
  1752. //-----------------------------------------------------------
  1753. void   ASDU_64_Send0(void)     //遥控命令
  1754. {
  1755.     comm_buf_flag->Sendbuf[6 ] = 0x40;
  1756.     comm_buf_flag->Sendbuf[7 ] = 0x81;
  1757.     comm_buf_flag->Sendbuf[8 ] = 0x12;
  1758.     comm_buf_flag->Sendbuf[9 ] = comm_buf_flag->DeviceAddr;
  1759.     comm_buf_flag->Sendbuf[10] = 0x01;
  1760.     comm_buf_flag->Sendbuf[11] = Output_Test_YK.YkDataNo1;
  1761.     comm_buf_flag->Sendbuf[12] = Output_Test_YK.YkCommand;
  1762.     comm_buf_flag->Sendbuf[13] = 0xee;
  1763.        comm_buf_flag->FunctionCode = 3;     //功能码
  1764.        comm_buf_flag->LPDU_Command = 3;
  1765.        comm_buf_flag->ASDU_Length = 8;
  1766.     //SendValFrm( 0x03, 8 );
  1767. }
  1768. void   ASDU_64_Analyze(void)
  1769. {
  1770.             
  1771.               if (comm_buf_flag->RecvBuf[11]==48)
  1772.                  {
  1773.                          switch(comm_buf_flag->RecvBuf[12])  //与主站下发的相同
  1774.                          {
  1775.                                  case 0x81:  // 分/退选择信息
  1776.                                          Output_Test_YK.YkSelect = 0x11;
  1777.                                          command_statue.YK_Output_Command_Flag = 0x00;
  1778.                                          //Memo1->Lines->Add("===========断路器遥控(分)选择==========");
  1779.                                          break;
  1780.                                  case 0x01:  // 分/退执行信息
  1781.                                          Output_Test_YK.YkSelect = 0x00;
  1782.                                          command_statue.YK_Output_Command_Flag = 0x00;
  1783.                                          //Memo1->Lines->Add("===========断路器遥控(分)执行==========");
  1784.                                          break;
  1785.                                  case 0xC1:  // 分/退撤销信息
  1786.                                          Output_Test_YK.YkSelect = 0x00;
  1787.                                          command_statue.YK_Output_Command_Flag = 0x00;
  1788.                                          //Memo1->Lines->Add("===========断路器遥控(分)撤销==========");
  1789.                                          break;
  1790.                                  case 0x82:  // 合/投选择信息
  1791.                                          Output_Test_YK.YkSelect = 0x11;
  1792.                                          command_statue.YK_Output_Command_Flag = 0x00;
  1793.                                          //Memo1->Lines->Add("===========断路器遥控(合)选择===========");
  1794.                                          break;
  1795.                                  case 0x02:  // 合/投执行信息
  1796.                                          Output_Test_YK.YkSelect = 0x00;
  1797.                                          command_statue.YK_Output_Command_Flag = 0x00;
  1798.                                          //Memo1->Lines->Add("===========断路器遥控(合)执行===========");
  1799.                                          break;
  1800.                                  case 0xc2:  // 合/投撤销信息
  1801.                                          command_statue.YK_Output_Command_Flag = 0x00;
  1802.                                          //Memo1->Lines->Add("===========断路器遥控(合)撤销===========");
  1803.                                          Output_Test_YK.YkSelect = 0x00;
  1804.                                          break;
  1805.                                  default:
  1806.                                          break;
  1807.                       }
  1808.                  }
  1809.                else
  1810.                  {
  1811.                       switch(comm_buf_flag->RecvBuf[12])
  1812.                        {
  1813.                              case 0x82:  // 合/投选择信息
  1814.                                          Output_Test_YK.YkSelect = 0x11;
  1815.                                          command_statue.YK_Output_Command_Flag = 0x00;
  1816.                                          //Memo1->Lines->Add("===========开出传动(合)选择===========");
  1817.                                          break;
  1818.                              case 0x02:  // 合/投执行信息
  1819.                                          Output_Test_YK.YkSelect = 0x00;
  1820.                                          command_statue.YK_Output_Command_Flag = 0x00;
  1821.                                          //Memo1->Lines->Add("===========开出传动(合)执行===========");
  1822.                                          break;
  1823.                              case 0xC2:  // 合/投撤销信息
  1824.                                          command_statue.YK_Output_Command_Flag = 0x00;
  1825.                                          //Memo1->Lines->Add("===========开出传动(合)撤销===========");
  1826.                                          Output_Test_YK.YkSelect = 0x00;
  1827.                                          break;
  1828.                        }
  1829.                    }
  1830. }
  1831. void   ASDU_70_Analyze(void)
  1832. {
  1833.    int i;
  1834.    
  1835.    Report_Buf_Show0.num  = comm_buf_flag->RecvBuf[11]; //NO.
  1836.    Report_Buf_Show0.stu  = comm_buf_flag->RecvBuf[12]; //20r1
  1837.    Report_Buf_Show0.msec = (comm_buf_flag->RecvBuf[18]*256 + comm_buf_flag->RecvBuf[17])%1000;       //msec
  1838.    Report_Buf_Show0.sec  = (US)((comm_buf_flag->RecvBuf[18]*256 + comm_buf_flag->RecvBuf[17])/1000); //sec
  1839.    Report_Buf_Show0.min  = comm_buf_flag->RecvBuf[19]; //min
  1840.    Report_Buf_Show0.hour = comm_buf_flag->RecvBuf[20]; //hour
  1841.    for(i=0;i<20;i++)
  1842.     {
  1843.       Report_Buf_Show0.Value[i] = ((comm_buf_flag->RecvBuf[24+2*i]&0x3f)*256+comm_buf_flag->RecvBuf[23+2*i]);
  1844.     }
  1845.                     
  1846.    Report_Buf_Show0.day   = comm_buf_flag->RecvBuf[64];
  1847.    Report_Buf_Show0.mon   = comm_buf_flag->RecvBuf[65];
  1848.    Report_Buf_Show0.year  = comm_buf_flag->RecvBuf[66];
  1849.    command_statue.Demand_Soe_Report_Flag = 0x00;
  1850. }
  1851. //-------------------------------------------------------
  1852. //                ASDU解析函数
  1853. //-------------------------------------------------------
  1854. void  ASDU_Analyze(void)
  1855. {
  1856.   int i;
  1857.    switch(comm_buf_flag->RecvBuf[6])
  1858.      {
  1859.         case  0x01:
  1860.               ADSU_01_Analyze();
  1861.               break;
  1862.         case  0x05:
  1863.               ASDU_05_Analyze();
  1864.               break;
  1865.         case  0x06:
  1866.               ASDU_06_Analyze();
  1867.               break;
  1868.         case  0x0a:
  1869.               ASDU_10_Analyze();
  1870.               break;
  1871.         case  0x14:
  1872.               ASDU_20_Analyze();
  1873.               break;
  1874.         case  0x28:
  1875.               ASDU_40_Analyze();
  1876.               break;
  1877.         case  0x32:
  1878.              ASDU_50_Analyze();
  1879.              break;
  1880.         case  0x40:
  1881.              ASDU_64_Analyze();
  1882.              break;
  1883.         case  0x46:
  1884.              ASDU_70_Analyze();
  1885.              break;
  1886.         default:
  1887.               break;
  1888.      }
  1889.          if(PC_Comm_Flag == 0x00)
  1890.            {
  1891.                for(i=0;i< (comm_buf_flag->RecvBuf[2]+6);i++)
  1892.                 { 
  1893.                   Comm0.SendBuf[Comm0.SendSet] =  comm_buf_flag->RecvBuf[i];
  1894.                   Comm0.SendSet++;
  1895.                   if(Comm0.SendSet>=SENDNUM)
  1896.                     Comm0.SendSet = 0;
  1897.                 }
  1898.            }
  1899. }
  1900. //---------------------------------------------------------------------------              
  1901. int  Check_Instruction_Statue(unsigned int Command)
  1902. {
  1903.    int  temp;
  1904.    switch( Command )
  1905.     {
  1906.       case  0x0210:  //修改时间
  1907.                    if(command_statue.Check_Time_Flag == 0xAA)
  1908.                     {
  1909.                        if( command_statue.Check_Time_Count >= COMMANDDELAY)
  1910.                          temp = 0x22;
  1911.                        else
  1912.                          temp = 0x11;
  1913.                     }
  1914.                    else
  1915.                     {
  1916.                       temp = 0x00;
  1917.                     }
  1918.                  break;
  1919.       case  0x0500:   //读系统参数
  1920.         case  0x0c00:   //系统配置修改选择
  1921.         case  0x0d00:   //系统配置修改执行
  1922.                    if(command_statue.Config_Operation_Flag == 0xAA)
  1923.                     {
  1924.                        if( command_statue.Config_Operation_Count >= COMMANDDELAY)
  1925.                          temp = 0x22;
  1926.                        else
  1927.                          temp = 0x11;
  1928.                     }
  1929.                    else if(command_statue.Config_Operation_Flag == 0x55)
  1930.                     {
  1931.                       temp = 0x22;
  1932.                     }
  1933.                    else
  1934.                     {
  1935.                       temp = 0x00;
  1936.                     }
  1937.                    break;
  1938.         case  0x0600:   //读定值
  1939.         case  0x0800:   //定值预修改
  1940.         case  0x0900:   //定值修改执行
  1941.         case  0x0a00:   //定值区号切换选择
  1942.         case  0x0a01:   //定值区号切换执行
  1943.         case  0x0a02:   //定值区号切换撤销
  1944.         case  0x0b00:   //定值区复制选择
  1945.         case  0x0b01:   //定值区复制执行
  1946.         case  0x0b02:   //定值区复制撤销
  1947.                    if(command_statue.Setting_Operation_Flag == 0xAA)
  1948.                     {
  1949.                        if( command_statue.Setting_Operation_Count >= COMMANDDELAY)
  1950.                          temp = 0x22;
  1951.                        else
  1952.                          temp = 0x11;
  1953.                     }
  1954.                    else if(command_statue.Setting_Operation_Flag == 0x55)
  1955.                     {
  1956.                       temp = 0x22;
  1957.                     }
  1958.                    else
  1959.                     {
  1960.                       temp = 0x00;
  1961.                     }
  1962.                   break;
  1963.         case  0x0700:   //自动调整通道系数
  1964.         case  0x0e00:   //通道系数调整选择
  1965.         case  0x0e01:   //通道系数调整执行
  1966.         case  0x0e02:   //通道系数调整撤销
  1967.                    if(command_statue.Channel_Ration_Flag == 0xAA)
  1968.                     {
  1969.                        if( command_statue.Channel_Ration_Count >= COMMANDDELAY)
  1970.                          temp = 0x22;
  1971.                        else
  1972.                          temp = 0x11;
  1973.                     }
  1974.                    else
  1975.                     {
  1976.                       temp = 0x00;
  1977.                     }
  1978.                    break;
  1979.         case  0x0f00:   //软压板操作选择
  1980.         case  0x0f01:   //软压板操作执行
  1981.         case  0x0f02:   //软压板操作撤销
  1982.                    if(command_statue.YYB_Opreation_Flag == 0xAA)
  1983.                     {
  1984.                        if( command_statue.YYB_Opreation_Count >= COMMANDDELAY)
  1985.                          temp = 0x22;
  1986.                        else
  1987.                          temp = 0x11;
  1988.                     }
  1989.                    else
  1990.                     {
  1991.                       temp = 0x00;
  1992.                     }
  1993.                    break;
  1994.         case  0x1000:   //修改密码
  1995.                    if(command_statue.Password_Modified_Flag == 0xAA)
  1996.                     {
  1997.                        if( command_statue.Password_Modified_Count >= COMMANDDELAY)
  1998.                          temp = 0x22;
  1999.                        else
  2000.                          temp = 0x11;
  2001.                     }
  2002.                    else
  2003.                     {
  2004.                       temp = 0x00;
  2005.                     }
  2006.                    break;
  2007.         case  0x1100:   //开出传动选择
  2008.         case  0x1101:   //开出传动执行
  2009.         case  0x1102:   //开出传动撤销
  2010.         case  0x1110:   //遥控合选择
  2011.         case  0x1111:   //遥控合执行
  2012.         case  0x1112:   //遥控合撤销
  2013.         case  0x1120:   //遥控分选择
  2014.         case  0x1121:   //遥控分执行
  2015.         case  0x1122:   //遥控分撤销
  2016.                    if(command_statue.YK_Output_Command_Flag == 0xAA)
  2017.                     {
  2018.                        if( command_statue.YK_Output_Command_Count >= COMMANDDELAY)
  2019.                          temp = 0x22;
  2020.                        else
  2021.                          temp = 0x11;
  2022.                     }
  2023.                    else
  2024.                     {
  2025.                       temp = 0x00;
  2026.                     }
  2027.                    break;
  2028.         case  0x1200:   //查询SOE及故障报告
  2029.                    if(command_statue.Demand_Soe_Report_Flag == 0xAA)
  2030.                     {
  2031.                        if( command_statue.Demand_Soe_Report_Count >= COMMANDDELAY)
  2032.                          temp = 0x22;
  2033.                        else
  2034.                          temp = 0x11;
  2035.                     }
  2036.                    else
  2037.                     {
  2038.                       temp = 0x00;
  2039.                     }
  2040.                    break;
  2041.         case  0x1300:   //装置复归
  2042.                    if(command_statue.Device_FUGUI_Flag == 0xAA)
  2043.                     {
  2044.                        if( command_statue.Device_FUGUI_Count >= COMMANDDELAY)
  2045.                          temp = 0x22;
  2046.                        else
  2047.                          temp = 0x11;
  2048.                     }
  2049.                    else
  2050.                     {
  2051.                       temp = 0x00;
  2052.                     }
  2053.                    break;
  2054.      }
  2055.    return temp;
  2056. }
  2057. //---------------------------------------------------------------------------
  2058. void    Command_Timer_Update(void)
  2059. {
  2060.      command_statue.Check_Time_Count++;                 //修改时间
  2061.      command_statue.Config_Operation_Count++;           //系统参数操作标志
  2062.      command_statue.Setting_Operation_Count++;          //定值操作标志
  2063.      command_statue.Channel_Ration_Count++;             //通道系数操作标志
  2064.      command_statue.YYB_Opreation_Count++;              //软压板操作
  2065.      command_statue.Password_Modified_Count++;          //修改密码
  2066.      command_statue.YK_Output_Command_Count++;          //遥控/开出传动选择
  2067.      command_statue.Demand_Soe_Report_Count++;          //查询SOE及故障报告
  2068.      command_statue.Device_FUGUI_Count++;               //装置复归
  2069. }
  2070. //---------------------------------------------------------------------------
  2071. void    Command_Timer_Check(void)
  2072. {
  2073.      if( command_statue.Check_Time_Count >= COMMANDDELAY)                 //修改时间
  2074.         command_statue.Check_Time_Count =  COMMANDDELAY;
  2075.      if( command_statue.Config_Operation_Count >= COMMANDDELAY)           //系统参数操作标志
  2076.          command_statue.Config_Operation_Count =  COMMANDDELAY;
  2077.      if( command_statue.Setting_Operation_Count >= COMMANDDELAY)          //定值操作标志
  2078.          command_statue.Setting_Operation_Count =  COMMANDDELAY;
  2079.      if( command_statue.Channel_Ration_Count >= COMMANDDELAY)             //通道系数操作标志
  2080.          command_statue.Channel_Ration_Count =  COMMANDDELAY;
  2081.      if( command_statue.YYB_Opreation_Count >= COMMANDDELAY)              //软压板操作
  2082.          command_statue.YYB_Opreation_Count =  COMMANDDELAY;
  2083.      if( command_statue.Password_Modified_Count >= COMMANDDELAY)          //修改密码
  2084.          command_statue.Password_Modified_Count =  COMMANDDELAY;
  2085.      if( command_statue.YK_Output_Command_Count >= COMMANDDELAY)          //遥控/开出传动选择
  2086.          command_statue.YK_Output_Command_Count =  COMMANDDELAY;
  2087.      if( command_statue.Demand_Soe_Report_Count >= COMMANDDELAY)          //查询SOE及故障报告
  2088.          command_statue.Demand_Soe_Report_Count =  COMMANDDELAY;
  2089.      if( command_statue.Device_FUGUI_Count >= COMMANDDELAY)               //装置复归
  2090.          command_statue.Device_FUGUI_Count =  COMMANDDELAY;
  2091. }
  2092. //---------------------------------------------------------------------------
  2093. void   Comm_103_Run(void)
  2094. {
  2095.   if(PC_Comm_Flag == 0x00)
  2096.    {
  2097.       LPDU_MMI_DSP_Send();
  2098.       Comm_RecvProcess();
  2099.       LPDU_MMI_DSP_Recv();
  2100.       
  2101.       Comm0.RecvSet = 0;
  2102.       Comm0.RecvGet = 0;
  2103.    }
  2104.   else
  2105.    {
  2106.      if( Comm0.RecvSet != Comm0.RecvGet )
  2107.         {
  2108.            PortA.SendBuf[PortA.SendSet] = Comm0.RecvBuf[Comm0.RecvGet];
  2109.            
  2110.            PortA.SendSet = (PortA.SendSet+1)%SENDNUM;
  2111.            Comm0.RecvGet = (Comm0.RecvGet+1)%RECVNUM;
  2112.         }
  2113.       if( PortA.RecvSet != PortA.RecvGet )
  2114.         {
  2115.            Comm0.SendBuf[Comm0.SendSet] = PortA.RecvBuf[PortA.RecvGet];
  2116.            
  2117.            Comm0.SendSet = (Comm0.SendSet+1)%SENDNUM;
  2118.            PortA.RecvGet = (PortA.RecvGet+1)%RECVNUM;
  2119.         }
  2120.    }                             
  2121. }
  2122. //---------------------------------------------------------------------------