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

📄 rs485_pc._c

📁 电梯楼层采集器代码
💻 _C
📖 第 1 页 / 共 2 页
字号:

#include"include.h"

void CommandReply(unsigned char command)
{//发送返回值给PC
  struct StructOfProtocol *p_buf;
  struct data *communication;
  p_buf = (struct StructOfProtocol *)Buffer485;
  p_buf->Length = 1;
  p_buf->Command = command;
  communication->pc_txd = 1; 
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/*
取控制器名称和版本号
命令码:	CMD_GET_DCUID
数据:		NONE
回应数据:
	[设备名称]	  10 byte(字符串形式)
	[软件版本号]  6 byte(字符串形式)
*/	
flash unsigned char UnitID[16] = { "LCU9040/1 V3.0  " }; /*设备标示代码*/
void GET_NAME(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(UnitID) + 1;
	 memcpy(p_buf->Data,UnitID,sizeof(UnitID));
  	 communication->pc_txd = 1;
   }
   else if(TEST) CommandReply(RESP_INVALID_DATA);
 }
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/*
取系统时间
命令码:CMD_GET_TIME
数据:		NONE		
正常回应数据:	
    日期表示: 2 bytes              
     时间表示:  2 bytes
*/
void GET_TIME(void)
{
 struct StructOfProtocol *p_buf;
 struct data *communication;
 p_buf = (struct StructOfProtocol *)Buffer485;
 *C51Buffer485 = *Buffer485;
 if(p_buf->Address == Device_Address) 
 {

   if(p_buf->Length==1)
   {//发送获取时间给51控制板
  	 communication->c51_txd = 1; 
   }
   else if(TEST) CommandReply(RESP_INVALID_DATA);   
 }
}
//------------------------------------------------------------------------------
/*
下载系统时间
命令码:CMD_SET_TIME
数据:	日期2字节,时间2字节
正常回应:[OK]
*/
void SET_TIME(void)
{
 struct StructOfProtocol *p_buf;
 p_buf = (struct StructOfProtocol *)Buffer485;
 *C51Buffer485 = *Buffer485;
 if(p_buf->Length ==5)
 {//发送设置时间给51控制板
  	DayOfTime = ((unsigned int)p_buf->Data[0] << 8) | p_buf->Data[1];
 	SecondOfTime = ((unsigned int)p_buf->Data[2] << 8) | p_buf->Data[3];
 	if (p_buf->Address  != 0xff) 
	{
	  	Cyc_manage |= 0x04;//打开更新51控制板的数据
        CommandReply(RESP_CMD_OK);
	}
 }
 else if(TEST && p_buf->Address != 0xff)
       CommandReply(RESP_INVALID_DATA);
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/*
取系统卡注册表
命令码:	CMD_GET_CARDSET 
数据:		NONE
正常回应数据:	
	卡注册表数据结构
*/
void GET_CARDSET(void)
{
  unsigned int point,count;
  struct StructOfProtocol *p_buf;
  struct data *communication;
  p_buf = (struct StructOfProtocol *)Buffer485;
  if(p_buf->Address==Device_Address)
  {
    if(p_buf->Length==3)
    {
	   point = *(unsigned int *)p_buf->Data;
	   if (point < sizeof(struct StructOfRegister))
       {//发送系统卡注册表给PC
	     count = sizeof(struct StructOfRegister) - point;
         if (count < 256 - 8) p_buf->Length = count + 1;
         else  p_buf->Length = 256 - 8;
         point += CARDSET_Address;
		 I2C_Initial();
	     AT24_Read((unsigned char *)&p_buf->Data,point,p_buf->Length-1);
  		 communication->pc_txd = 1; 
	   }
	   else if(TEST) CommandReply(RESP_INVALID_DATA);  
	}
	else if(TEST) CommandReply(RESP_INVALID_DATA);
  }
}
//------------------------------------------------------------------------------
/*
下载系统卡注册表
命令码:	CMD_SET_CARDSET
数据:  	卡注册表
正常回应:	[OK]
*/
void SET_CARDSET(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 StructOfRegister))
 {
   count = sizeof(struct StructOfRegister) - point;
   p_buf->Length -= 3;
   if (p_buf->Length && (p_buf->Length <= count))
   {//保存系统卡注册表
     point += CARDSET_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);
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/*
用户楼层授权资料(取控制器门禁时间组)
命令码:		CMD_GET_USER
数据:		NONE

正常回应数据:
    门禁时间组数据结构  
*/
void GET_USER(void)
{
  unsigned int point,count;
  struct StructOfProtocol *p_buf;
  struct data *communication;
  p_buf = (struct StructOfProtocol *)Buffer485;
  if(p_buf->Address==Device_Address)
  {
    if(p_buf->Length==3)
    {
       point = *(unsigned int *)p_buf->Data;
       if (point < sizeof(struct StructOfUserInformation))
       {
	     count = sizeof(struct StructOfUserInformation) - point;
	      if (count < 256 - 8)   p_buf->Length = count + 1;
          else  p_buf->Length = 256 - 8;
		  point += USER_INFORMATION_Address;
		  I2C_Initial();
	      AT24_Read((unsigned char *)&p_buf->Data,point,p_buf->Length-1);
  		  communication->pc_txd = 1; 
	   }
	   else if(TEST) CommandReply(RESP_INVALID_DATA);
  	}
	else if(TEST) CommandReply(RESP_INVALID_DATA);
  }
}
//------------------------------------------------------------------------------
/*
下载门禁时间组(设用户楼层授权资料)
命令码:CMD_SET_USER
数据:	门禁时间组
正常回应:	[OK]
*/
void SET_USER(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 StructOfUserInformation))
 {
  	count = sizeof(struct StructOfUserInformation) - point;
    p_buf->Length -= 3;
	if(p_buf->Length&&(p_buf->Length<=count))
	{
	  point += USER_INFORMATION_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);
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/*
取用户时间组授权资料
命令码:		CMD_GET_USER_TIME
数据:		    内存位置  2字节,高字节在前,值域 0 - 7499
正常回应数据:	
      从指定位置开始的资料,不超过255字节
*/
void GET_USER_TIME(void)
{
  unsigned int point,count;
  struct StructOfProtocol *p_buf;
  struct data *communication;
  p_buf = (struct StructOfProtocol *)Buffer485;
  if(p_buf->Address==Device_Address)
  {
    if(p_buf->Length==3)
    {
      point = *(unsigned int *)p_buf->Data;
      if (point < sizeof(struct StructOfUserTimezone))
      {
        count = sizeof(struct StructOfUserTimezone) - point;
        if (count < 256 - 8) p_buf->Length = count + 1;
        else    p_buf->Length = 256 - 8;
		point += USER_TIMEZONE_Address;
		I2C_Initial();
		AT24_Read((unsigned char *)&p_buf->Data,point,p_buf->Length-1);
  		communication->pc_txd = 1;
      }
	  else if(TEST) CommandReply(RESP_INVALID_DATA);
  	}
	else if(TEST) CommandReply(RESP_INVALID_DATA);
  }
}
//------------------------------------------------------------------------------
/*
设用户时间组授权资料 
命令码:CMD_SET_USER_TIME
数据:	内存位置  2字节,高字节在前,值域 0 - 7499	
      从指定位置开始的资料,不超过250字节
正常回应:	    [OK]
*/
void SET_USER_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 StructOfUserTimezone))
 {
   count = sizeof(struct StructOfUserTimezone) - point ;
   p_buf->Length -= 3;
   if(p_buf->Length&&(p_buf->Length<=count))
   {
     point += USER_TIMEZONE_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);
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/*
8.	取电梯授权时间组            
命令码:		CMD_GET_AUTH_TIME
数据:		    内存位置  2字节,高字节在前,值域 0 - 524
正常回应数据:	
   从指定位置开始的资料,不超过255字节
*/
void GET_AUTH_TIME(void)
{
 unsigned int point,count;
 struct StructOfProtocol *p_buf;
 struct data *communication;
 p_buf = (struct StructOfProtocol *)Buffer485;
 if(p_buf->Address==Device_Address)
 {
   if(p_buf->Length==3)
   {
     point = *(unsigned int *)p_buf->Data;
     if(point < sizeof(struct StructOfLiftSchedule))
	 {
	   count = sizeof(struct StructOfLiftSchedule) - point;
	   if(count< 256 - 8) p_buf->Length = count + 1;
	   else p_buf->Length = 256 - 8;
	   point += LIFT_SCHEDULE_Address;
	   I2C_Initial();
	   AT24_Read((unsigned char *)&p_buf->Data,point,p_buf->Length-1);
  	   communication->pc_txd = 1; 
	 }
	 else if(TEST) CommandReply(RESP_INVALID_DATA);
  	}
	else if(TEST) CommandReply(RESP_INVALID_DATA);
 }
}

⌨️ 快捷键说明

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