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

📄 rs485_pc._c

📁 电梯楼层采集器代码
💻 _C
📖 第 1 页 / 共 2 页
字号:
//------------------------------------------------------------------------------
/*
15.	设电梯授权时间组 = CMD_SET_AUTH_TIME
命令码:		CMD_SET_AUTH_TIME
数据:		    内存位置                  2字节,高字节在前,值域 0 - 524	
      从指定位置开始的资料,不超过250字节
正常回应:	    [OK]
*/
void SET_AUTH_TIME(void)
{
 unsigned int point,count;
 struct StructOfProtocol *p_buf;
 p_buf = (struct StructOfProtocol *)Buffer485;
 *C51Buffer485 = *Buffer485;
 point = *(unsigned int *)p_buf->Data;
 if(point < sizeof(struct StructOfLiftSchedule))
 {
   count = sizeof(struct StructOfLiftSchedule) - point;
   p_buf->Length -= 3;
   if(p_buf->Length&&(p_buf->Length<=count))
   {
    point += LIFT_SCHEDULE_Address;
	I2C_Initial();
    AT24_Write((unsigned char *)&p_buf->Data[2],point,p_buf->Length);	
	I2C_Close();
    if (p_buf->Address!= 0xff) 
	{
	   Cyc_manage |= 0x04;//打开更新51控制板的数据
   	   CommandReply(RESP_CMD_OK);
	 }
   }
   else if(TEST && p_buf->Address != 0xff)
       CommandReply(RESP_INVALID_DATA);
 }
 else if(TEST && p_buf->Address != 0xff)
     CommandReply(RESP_INVALID_DATA);
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/*取系统配置参数*/
void GET_CONFIG(void)
{
 struct StructOfProtocol *p_buf;
 struct data *communication;
 p_buf = (struct StructOfProtocol *)Buffer485;
 if(p_buf->Address==Device_Address)
 {
   if (p_buf->Length == 1)  /*接收数据包长度确认*/
   {
     p_buf->Length = sizeof(SystemConfig) + 1;
	 I2C_Initial();
	 AT24_Read((unsigned char *)&p_buf->Data,SystemConfig_Address,p_buf->Length-1);
  	 communication->pc_txd = 1; 
   }
   else if(TEST) CommandReply(RESP_INVALID_DATA);          /*包长度异常*/
  }
}
//------------------------------------------------------------------------------
/*设置系统配置参数*/
void SET_CONFIG(void)
{
 unsigned int point,count;
 struct StructOfProtocol *p_buf;
 p_buf = (struct StructOfProtocol *)Buffer485;
 *C51Buffer485 = *Buffer485;
 if (p_buf->Length == sizeof(SystemConfig) + 1)                /*接收数据包长度确认*/
 {
  	I2C_Initial();
  	AT24_Write((unsigned char *)&p_buf->Data,SystemConfig_Address,sizeof(SystemConfig));
	I2C_Close();
    if (p_buf->Address != 0xff)     
	{
	   Cyc_manage |= 0x04;//打开更新51控制板的数据
       CommandReply(RESP_CMD_OK);
	}
  }
  else if (TEST && p_buf->Address != 0xff)    
  	   CommandReply(RESP_INVALID_DATA);
} 
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
 /*取产品标签代码*/
void GET_PRODUCT_CODE(void)
{
 struct StructOfProtocol *p_buf;
 struct data *communication;
 p_buf = (struct StructOfProtocol *)Buffer485;
 if (p_buf->Address == Device_Address)                                /*本机地址响应*/
 {
  if (p_buf->Length == 1)                                     /*接收数据包长度确认*/
  {
     p_buf->Length = sizeof(struct StructOfProductCode) + 1;
	 I2C_Initial();
	 AT24_Read((unsigned char *)&p_buf->Data,StructOfProductCode_Address,p_buf->Length-1);
  	 communication->pc_txd = 1; 
  }
  else if(TEST)     
  	  CommandReply(RESP_INVALID_DATA);          /*包长度异常*/
 }
}
//------------------------------------------------------------------------------
/*设置产品标签代码*/
void SET_PRODUCT_CODE(void)
{
 struct StructOfProtocol *p_buf;
 p_buf = (struct StructOfProtocol *)Buffer485;
 *C51Buffer485 = *Buffer485;
 if (p_buf->Length == sizeof(struct StructOfProductCode) + 1)  /*接收数据包长度确认*/
 {	
 	I2C_Initial();
	AT24_Write((unsigned char *)&p_buf->Data,StructOfProductCode_Address,sizeof(struct StructOfProductCode));	
	I2C_Close();	
    if (p_buf->Address != 0xff)  
    { 
	  Cyc_manage |= 0x04;//打开更新51控制板的数据
      CommandReply(RESP_CMD_OK);
    }
 }
 else if(TEST && p_buf->Address != 0xff)   
 	  CommandReply(RESP_INVALID_DATA);
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
 /*取控制器状态*/
void GET_UNIT_STATUS(void)
{
 struct StructOfProtocol *p_buf;
 struct data *communication;
 p_buf = (struct StructOfProtocol *)Buffer485;
 if (p_buf->Address == Device_Address)  /*本机地址响应*/
 {
  if (p_buf->Length == 1)   /*接收数据包长度确认*/
  {
    p_buf->Length = 4;
    p_buf->Data[0] = WorkingMode;        /*工作模式状态*/
    p_buf->Data[1] = StopSwitchStatus;   /*停止开关状态*/
    p_buf->Data[2] = FireSwitchStatus;   /*火警开关状态*/
  	communication->pc_txd = 1;
  }
 }
}
//------------------------------------------------------------------------------
 /*设置控制器状态*/
void SET_UNIT_STATUS(void)
{
/*
 struct StructOfProtocol *p_buf;
 struct Device51_StructOfProtocol *C51_buf;
 struct ControlStream *p_stream;
 p_buf = (struct StructOfProtocol *)Buffer485;
 C51_buf = (struct Device51_StructOfProtocol *)Buffer485;
 if (p_buf->Length == 3)                      //接收数据包长度确认
 {
   p_stream = (struct ControlStream *)p_buf->Data;
   if (!p_stream->Device_Address)             //复位控制器
   {
      if (!p_stream->Status)
      {
        b_reset = 1;
        EventRecord(MSG_WARM_RESET);
        if (p_buf->Address != 0xff)   
		   CommandReply(RESP_CMD_OK);
      }
      else if (p_stream->Status == 1)
      {
        CleanDatabase();
        EventRecord(MSG_COLD_RESET);
        b_reset = 1;
      }
   }
   else if (p_stream->Address == 1)         //设置工作模式
   {
     if (p_stream->Status == SLEEP_MODE ||
      p_stream->Status == UNLOCK_MODE || p_stream->Status == SAFETY_MODE)
     {
        tmp = WorkingMode & ~MANUAL;
        WorkingMode = p_stream->Status | MANUAL;
        if (!(tmp & MANUAL) || p_stream->Status != (tmp & 0x0f))
        {
          EventRecord(MSG_WORKING_MODE_CHANGED);
          if (p_stream->Status == UNLOCK_MODE)
          {
            if (SystemConfig.FirstKeyUnlock)    b_unlock = 0;
            else        b_unlock = 1;
          }
        }
      }
      else    WorkingMode = MANUAL;
      b_minute = 1;
      if (p_buf->Address != 0xff)    
	  	  CommandReply(RESP_CMD_OK);
   }
   else if (TEST && p_buf->Address != 0xff) 
   		CommandReply(RESP_INVALID_DATA);
  }
  else if (TEST && p_buf->Address != 0xff)    
  	CommandReply(RESP_INVALID_DATA);
	*/
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/*取控制器历史事件*/ 
void GET_EVENT(void)
{

/*

  	 		if (p_buf->Address == Address)
            {
            if (p_buf->Length == 3)                                     //接收数据包长度确认
              {
              tmp = p_buf->Data[0];                                     //取删除记录数
              if (tmp == 0xff)                                          //删除所有记录
                {
                Record.TopPoint = Record.BottomPoint = Record.Overflow = 0;
                SequentialWrite((unsigned char *)&Record,OFFSET_RECORD_POINT,sizeof(Record));
                }
              else if (p_buf->Data[1] == (unsigned char)Record.BottomPoint)//数据包标志比较
                {
                count = GetRecordNumber();                              //计算现有记录数
                if (tmp)                                                //删除部分记录
                  {
                  if (tmp <= count && tmp <= ((sizeof(Buffer485) - 10) / sizeof(struct StructOfRecord)))
                    {
                    count = tmp + Record.BottomPoint;
                    if (count < MAX_RECORD_NUMBER)    Record.BottomPoint = count;
                    else    Record.BottomPoint = count - MAX_RECORD_NUMBER;
                    Record.Overflow = 0;
                    SequentialWrite((unsigned char *)&Record,OFFSET_RECORD_POINT,sizeof(Record));
                    }
                  else if (TEST)                                        //删除记录数据异常
                    {
                    CommandReply(RESP_INVALID_DATA);
                    break;
                    }
                  }
                }
                count = GetRecordNumber();                                //计算删除后的记录数
                if (count)
                {
                if (count > ((sizeof(Buffer485) - 10) / sizeof(struct StructOfRecord)))
                  count = (sizeof(Buffer485) - 10) / sizeof(struct StructOfRecord);
                count *= sizeof(struct StructOfRecord);
                p_buf->Length = count + 2;
                p_buf->Data[0] = (unsigned char)Record.BottomPoint;     //回应包号
                point = OFFSET_EVENT_RECORD + Record.BottomPoint * sizeof(struct StructOfRecord);
                MemoryRead((unsigned char *)&p_buf->Data[1],point,count);
                b_rts = 1;                                              //置发送请求标志
                }
              else          CommandReply(RESP_NULL);                    //无记录数据
              }
            else if(TEST)     CommandReply(RESP_INVALID_DATA);          //包长度异常
            }

			*/
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void communication_with_pc(void)
{ 
  struct StructOfProtocol *p_buf;
  struct data *communication;
  p_buf = (struct StructOfProtocol *)Buffer485;
  if(communication->pc_txd)
  {//发送数据给PC
 	communication->pc_txd = 0; 
	p_buf->Address = Device_Address;
    UDR = BOOT_CODE;
  }
  if(communication->pc_rxd)
  {//pc发送给采集板的数据
    communication->pc_rxd = 0; 
	if((p_buf->Address==Device_Address)||(p_buf->Address == 0xff))
	{
 	  switch(p_buf->Command)
	  {
	    case CMD_GET_DCUID://取控制器名称和版本号
		 	 GET_NAME();
		 	 break;
	   	case CMD_GET_TIME://取系统时间
		 	 GET_TIME();
			 break;
	 	case CMD_SET_TIME://下载系统时间
			 SET_TIME();
			 break;
	    case CMD_GET_CARDSET://取系统卡注册表
		     GET_CARDSET();
			 break;
	    case CMD_SET_CARDSET://下载系统卡注册表
			 SET_CARDSET();
			 break;
	    case CMD_GET_USER://取用户楼层授权资料
			 GET_USER();
			 break;
		case CMD_SET_USER://下载门禁时间组(设用户楼层授权资料)
		 	 SET_USER();
			 break;
	    case CMD_GET_USER_TIME://取用户时间组授权资料  
			 GET_USER_TIME();
			 break;
		case CMD_SET_USER_TIME://设用户时间组授权资料 
		 	 SET_USER_TIME();
			 break;	 
		case CMD_GET_AUTH_TIME://取电梯授权时间组 
		 	 GET_AUTH_TIME();
			 break;
	    case CMD_SET_AUTH_TIME://设电梯授权时间组
		 	 SET_AUTH_TIME();
			 break;
	    case CMD_GET_CONFIG://取系统配置参数
			 GET_CONFIG();
			 break;
	    case CMD_SET_CONFIG: //设置系统配置参数
			 SET_CONFIG();
	  		 break;
		case CMD_GET_PRODUCT_CODE://取产品标签代码
		     GET_PRODUCT_CODE();
			 break;	 
		case CMD_SET_PRODUCT_CODE://设置产品标签代码
			 SET_PRODUCT_CODE();
			 break;
		case CTL_GET_UNIT_STATUS: /*取控制器状态*/
			 GET_UNIT_STATUS();
			 break;
		case CTL_SET_UNIT_STATUS: /*设置控制器状态*/	 
			 SET_UNIT_STATUS();
			 break;
		case CMD_GET_EVENT://取控制器历史事件
			 GET_EVENT();
			 break;	 
		default:
		 	if (TEST && p_buf->Address != 0xff)   
			   CommandReply(RESP_INVALID_INSTRUCT);
	 	    break;	 
	  }
	}
  }
}

⌨️ 快捷键说明

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