⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cdt.c

📁 力导保护35kv保护装置对接南自系统的CDT源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
        {
          t_event.e_date.msec = MAKEWORD(body_e[1],body_e[2])+body_e[3]*1000;
          t_event.e_date.minute =body_e[4];
        }  
        if(body_e[0]==0x81) 
        {
                   SYS_Get_Clock(&t_date);
                   temp=MAKEWORD(body_e[3],body_e[4]&0x7f);
                   id=1+temp/8;
                  
                  t_event.e_state =(body_e[4]&0x80)>>7;              
                  t_event.e_date.hour =body_e[1];
                  t_event.e_date.day =body_e[2];
                  t_event.e_date.month =t_date.month;
                  t_event.e_date.year =t_date.year;    
                  t_list.l_type =LIST_T_EVENT;
                  code=MAKEWORD(body_e[3],body_e[4]&0x7f);
                  if(code<7)//管理机LD_301
                  {
                    t_event.dev_id=1;
                    p_ied->dev_type=5;
                    code=code+1	;
                  }
                  if((code>299)&&(code<312))//331
                  {
                    t_event.dev_id=2;
                    p_ied->dev_type=2;
                  }
                  if((code>311)&&(code<322))//315
                  {
                    t_event.dev_id=3;
                    p_ied->dev_type=3;
                  }
                   if((code>321)&&(code<722))//管理机311  16个事件
                  {
                    //code=code-322;
                    t_event.dev_id=(code-322)/16+4;
                    p_ied->dev_type=1;
                    code=code-(t_event.dev_id-4)*16-321;
                  }
                  if(code>729)//313  20
                  {
                    //code=code-730;
                    t_event.dev_id=(code-730)/20+29;
                    p_ied->dev_type=4;
                    code=code-(t_event.dev_id-29)*20-729;	
                  }
                  t_event.e_code =C103_Get_Code(p_ied, &t_list, code);
                  if(t_event.e_code!=0)
                     INF_Record_Event(&t_event);
                    
        }
        body_e+=6;
   }//end  for  for (i =0; i < nSize; i++)
  // break;
}

#define	FRAME_A  0x61
#define	FRAME_B  0xC2
#define	FRAME_C  0xB3
#define	FRAME_D  0xF4	
#define	FRAME_E  0x26	
static void  DC_Interpret(const BYTE *pFrame)
{
	//check control word here
	/*if (calc_crc_8(&pFrame[6], 5) != pFrame[11])
	{
		return;
	}*/
	switch( pFrame[7] ) /* 帧类型 */
	{
	case FRAME_A:
		Frame_A_Interpret(&pFrame[12], pFrame[8]);
		break;
	case FRAME_B:
		Frame_B_Interpret(&pFrame[12], pFrame[8]);
		break;
	case FRAME_C:
		Frame_C_Interpret(&pFrame[12], pFrame[8]);
		break;
	case FRAME_D:
		Frame_D_Interpret(&pFrame[12], pFrame[8]);
		break;
	case FRAME_E:
		Frame_E_Interpret(&pFrame[12], pFrame[8]);
		break;
		default:
                break;
	}
}

static void EVENT_Interpret (const BYTE *Frame)
{  
         Frame_E_Interpret(&Frame[12], Frame[8]);                  
}

static void DI_Interpret (const BYTE *diFrame)
{  
         get_change_di(&diFrame[12], diFrame[8])  ;               
}

static void get_change_di(const BYTE *body_di, WORD wSize)
{
  int      m;
  int      a;
  WORD   cpu;
  
  for (m =0; m < wSize; m++)
  {
    if((body_di[0]&0x80)!=0)
    {
      cpu=(body_di[0]-0xf0)*4+1;
      for(a=0;a<4;a++)
      {
	m_di.di_val[0]=MAKEDWORD(MAKEWORD(body_di[1+a],0),0);	       	
	INF_Set_Di(cpu+a, &m_di);
      }
      body_di+=6;
    }
  }
        	
}
/* module's task */
static  VOID task_232(UNSIGNED argc, VOID *argv)
{			
	T_IED *p_ied;
	p_ied =DEV_Search_IED(m_dev_id);
	m_di.di_num =8;
	m_ms.ms_num =20;
Loop:
          memset(&m_rx_buf,0,300);
          DEV_LOCK_COM();
          UART_Read(m_dev_port,m_rx_buf,2000);
	  DC_Interpret(m_rx_buf);
	  NU_Sleep(200);
	  DEV_UNLOCK_COM();	
	  goto Loop;
}

/*static  VOID task_232x(UNSIGNED argc, VOID *argv)
{
 // T_IED *p_ied;
Loopevent:
          if(m_rx_buf[7]==0x26)
          {
            EVENT_Interpret(m_rx_buf);	
          }	
          goto Loopevent;		
}*/

/*static  VOID task_232di(UNSIGNED argc, VOID *argv)
{
  int y;
  m_di.di_num =8;
  Loopdi:
         if(m_rx_buf[7]==0x61)
	{
          for(y=0;y<m_rx_buf[8];y++)
	  {
	    if((m_rx_buf[y*8+12]&0x80)!=0)
	    {
	    	DI_Interpret(m_rx_buf);
	    }
	  }
	}
	NU_Sleep(30);		
	goto Loopdi;
}*/

/*static  VOID task_232x(UNSIGNED argc, VOID *argv)
{
	T_IED *p_ied;
	p_ied =DEV_Search_IED(m_dev_id);
	m_di.di_num =8;
	m_ms.ms_num =20;
Loop:
	  DC_Interpret(m_rx_buf);
	  NU_Sleep(50);	
	goto Loop;
}*/

BOOL c103_get_List(T_IED *p_ied, T_LIST* p_list)
{	
  int i;
  for(i=0;i<g_c103_code_size;i++)
  {
    if(p_ied->dev_type==g_c103_code[i].dev_type)
    {
      switch(p_list->l_type)
      {				
      
      case LIST_T_EVENT:
        {
          p_list->l_ptr = g_c103_code[i].p_event;
          p_list->l_size = g_c103_code[i].w_even;
          return true;
        }
      case LIST_T_SET:
        {
          p_list->l_ptr = g_c103_code[i].p_setting;
          p_list->l_size = g_c103_code[i].w_setting;
          return true;
        }
        return false;
      }
    }  
  }
  return false; //hu?
}

static WORD C103_Get_Code(T_IED* p_ied, T_LIST* p_list, WORD code)
{
  if(c103_get_List(p_ied,p_list))
  {	
    switch(p_list->l_type)
    {
    case  LIST_T_EVENT:
      {
        int i;
        T_EVENT_ENTRY* p_event = (T_EVENT_ENTRY*) p_list->l_ptr;
        for(i = 0; i< p_list->l_size; i++)
        {
          if(p_event[i].e_key == code)
            return i+1;
        }		
      }
    case LIST_T_ALARM:
      {
        int i;
        T_ALARM_ENTRY* p_alarm = (T_ALARM_ENTRY*) p_list->l_ptr;
        for(i = 0; i< p_list->l_size; i++)
        {
          if(p_alarm[i].e_key  == code)
            return i+1;
        }
      }
    case LIST_T_SET:
      {
        int i;
        T_SET_ENTRY* p_set = (T_SET_ENTRY*) p_list->l_ptr;
        for(i = 0; i< p_list->l_size; i++)
        {
          if(p_set[i].e_key  == code)
            return i+1;
        }	
      }
    }
  }
  return 0;
}
BOOL cdt_remote_control(T_IED *p_ied, WORD ctrl_no)
{
  WORD  crc=0;
 
  
  m_tx_buf[0]=0xeb;
  m_tx_buf[1]=0x90;
  m_tx_buf[2]=0xeb;
  m_tx_buf[3]=0x90;
  m_tx_buf[4]=0xeb;
  m_tx_buf[5]=0x90;
  m_tx_buf[6]=0x71;
  m_tx_buf[7]=0xc2;
  m_tx_buf[8]=0x03;
  m_tx_buf[9]=0;
  m_tx_buf[10]=0;
  crc=calc_crc_8(&m_tx_buf[6],5);
  m_tx_buf[11]=crc;
  m_tx_buf[12]=0xe2;
  m_tx_buf[13]=0xaa;
  m_tx_buf[14]=2+p_ied->dev_id;
  m_tx_buf[15]=m_tx_buf[13];
  m_tx_buf[16]=m_tx_buf[14];
  crc=calc_crc_8(&m_tx_buf[12],5);
  m_tx_buf[17]=crc;
  
  m_tx_buf[18]=0xe2;
  m_tx_buf[19]=m_tx_buf[13];
  m_tx_buf[20]=m_tx_buf[14];
  m_tx_buf[21]=m_tx_buf[15];
  m_tx_buf[22]=m_tx_buf[16];
  crc=calc_crc_8(&m_tx_buf[18],5);
  m_tx_buf[23]=crc;
  
  m_tx_buf[24]=0xe2;
  m_tx_buf[25]=m_tx_buf[13];
  m_tx_buf[26]=m_tx_buf[14];
  m_tx_buf[27]=m_tx_buf[15];
  m_tx_buf[28]=m_tx_buf[16];
  crc=calc_crc_8(&m_tx_buf[24],5);
  m_tx_buf[29]=crc;
  
  UART_Write(m_dev_port, m_tx_buf, 30);
  NU_Sleep(100);
  return true;
  	
}

BOOL cdt_check_control(T_IED *p_ied, WORD ctrl_no)
{
  WORD  crc=0;
   WORD  len=0;
  
  m_tx_buf[0]=0xeb;
  m_tx_buf[1]=0x90;
  m_tx_buf[2]=0xeb;
  m_tx_buf[3]=0x90;
  m_tx_buf[4]=0xeb;
  m_tx_buf[5]=0x90;
  m_tx_buf[6]=0x71;
  m_tx_buf[7]=0x61;
  m_tx_buf[8]=0x03;
  m_tx_buf[9]=0;
  m_tx_buf[10]=0;
  crc=calc_crc_8(&m_tx_buf[6],5);
  m_tx_buf[11]=crc;
  m_tx_buf[12]=0xe0;
  //1分 2合
  if(ctrl_no%2==1)
  {
    m_tx_buf[13]=0x33;//fen 
  }
  else
  {
    m_tx_buf[13]=0xcc;	//he 
  }
  m_tx_buf[14]=2+p_ied->dev_id;
  m_tx_buf[15]=m_tx_buf[13];
  m_tx_buf[16]=m_tx_buf[14];
  crc=calc_crc_8(&m_tx_buf[12],5);
  m_tx_buf[17]=crc;
  
  m_tx_buf[18]=0xe0;
  m_tx_buf[19]=m_tx_buf[13];
  m_tx_buf[20]=m_tx_buf[14];
  m_tx_buf[21]=m_tx_buf[15];
  m_tx_buf[22]=m_tx_buf[16];
  crc=calc_crc_8(&m_tx_buf[18],5);
  m_tx_buf[23]=crc;
  
  m_tx_buf[24]=0xe0;
  m_tx_buf[25]=m_tx_buf[13];
  m_tx_buf[26]=m_tx_buf[14];
  m_tx_buf[27]=m_tx_buf[15];
  m_tx_buf[28]=m_tx_buf[16];
  crc=calc_crc_8(&m_tx_buf[24],5);
  m_tx_buf[29]=crc;
  
 
  
  UART_Write(m_dev_port, m_tx_buf, 30);

  UART_Read(m_dev_port, m_rx_buf, 2000);
  NU_Sleep(100);
  return true;
  
}                          
                           
BOOL cdt_set_clock(T_IED *p_ied, const T_DATE *p_date)
{
  T_DATE        t_date;
  WORD          crc;
  
  SYS_Get_Clock(&t_date);
  m_tx_buf[0]=0xeb;
  m_tx_buf[1]=0x90;
  m_tx_buf[2]=0xeb;
  m_tx_buf[3]=0x90;
  m_tx_buf[4]=0xeb;
  m_tx_buf[5]=0x90;
  m_tx_buf[6]=0x71;
  m_tx_buf[7]=0x7a;
  m_tx_buf[8]=0x02;
  m_tx_buf[9]=0;
  m_tx_buf[10]=0;
  crc=calc_crc_8(&m_tx_buf[6],5);
  m_tx_buf[11]=crc;
  m_tx_buf[12]=0xee;
  m_tx_buf[13]=t_date.msec&0xff;
  m_tx_buf[14]=t_date.msec>>8;
  m_tx_buf[15]=t_date.msec/1000;
  m_tx_buf[16]=t_date.minute;
  crc=calc_crc_8(&m_tx_buf[12],5);
  m_tx_buf[17]=crc;
  
  m_tx_buf[18]=0xef;
  m_tx_buf[19]=t_date.hour;
  m_tx_buf[20]=t_date.day;
  m_tx_buf[21]=t_date.month;
  m_tx_buf[22]=t_date.year-2000;
  crc=calc_crc_8(&m_tx_buf[18],5);
  m_tx_buf[23]=crc;
  UART_Write(m_dev_port, m_tx_buf, 24);
  return true;	
}

BOOL cdt_get_setting(T_IED *p_ied, T_SET *p_set)
{
   WORD crc1=0,crc2=0; 
   BYTE len=0;
   int i=0,j=0,n=0;
   BYTE set_num=0;
   WORD set=0;

   memset(&set_temp,0,300);  
  
   m_tx_buf[0]=0xeb;
   m_tx_buf[1]=0x90;
   m_tx_buf[2]=0xeb;
   m_tx_buf[3]=0x90;
   m_tx_buf[4]=0xeb;
   m_tx_buf[5]=0x90;
   m_tx_buf[6]=0x71;
   m_tx_buf[7]=0xfc;//功能码,召唤定值
   m_tx_buf[8]=0x02;
   m_tx_buf[9]=0;
   m_tx_buf[10]=0;
   m_tx_buf[11]=0x3e;
   
   m_tx_buf[12]=0x00;
   m_tx_buf[13]=0x01;//柜号,默认为1
   m_tx_buf[14]=0x53;
   m_tx_buf[15]=0x03;
   m_tx_buf[16]=p_ied->dev_data[0];
   crc1=calc_crc_8(&m_tx_buf[12],5);
   m_tx_buf[17]=crc1;
   
   m_tx_buf[18]=0x01;
   crc2=(m_tx_buf[14] + m_tx_buf[15] + m_tx_buf[16]);
   m_tx_buf[19]=crc2&0xff;
   m_tx_buf[20]=(crc2>>8)&0xff;
   m_tx_buf[21]=0;
   m_tx_buf[22]=0;
   crc1=calc_crc_8(&m_tx_buf[18],5);
   m_tx_buf[23]=crc1;
   
   UART_Write(m_dev_port, m_tx_buf, 24);
   NU_Sleep(100);
   len=UART_Read(m_dev_port, m_rx_buf, 3000);
   if(len==0)
   {
     return false;	
   }	
   if(m_rx_buf[7]!=0xfc)
   {
     UART_Read(m_dev_port, m_rx_buf, 3000);	
   }
   if(m_rx_buf[7]!=0xfc)
   {
     UART_Read(m_dev_port, m_rx_buf, 3000);	
   }
   if(m_rx_buf[7]!=0xfc)
   {
     UART_Read(m_dev_port, m_rx_buf, 3000);	
   }
   if(m_rx_buf[7]!=0xfc)
   {
     UART_Read(m_dev_port, m_rx_buf, 3000);	
   }
   if(m_rx_buf[7]!=0xfc)
   {
     UART_Read(m_dev_port, m_rx_buf, 3000);	
   }
   if(m_rx_buf[7]!=0xfc)
   {
     return false;	
   }
   for(i=1;i<(m_rx_buf[8]-1);i++)//将CDT报文中的定值信息解包放入缓冲区
   {
     for(j=0;j<5;j++)
     {
       if((i*6+12+j)%6!=0)
       {
         set_temp[i+j+n]=m_rx_buf[i*6+12+j];
         set_num=(i+j+n)/3;
         if(j==4)
         {
           n=n+3;	
         }	
       }	
     }	
   }
   p_set->set_num=set_num;
   for(i=0;i<set_num;i++)
   {
     set=MAKEWORD(set_temp[i*3+3],set_temp[i*3+4]);
     
     if(set==0xffff)
     {
       p_set->set_val[i].type =SET_T_FLOAT;
       p_set->set_val[i].un_val.f_val =1;		
     }
     else
     {
       p_set->set_val[i].type =SET_T_FLOAT;
       p_set->set_val[i].un_val.f_val =(float)set/100.0;
     }	
   }
   return true;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -