主数据区超过18字节 ,心跳不带硬件Crc
This commit is contained in:
parent
3f75afc218
commit
02a7815a3e
|
@ -55,10 +55,6 @@ void TinyClient::Open()
|
|||
|
||||
Password.Load(Cfg->Password, ArrayLength(Cfg->Password));
|
||||
}
|
||||
//算硬件ID的CRC
|
||||
HardCrc=Crc::Hash16(&Sys.ID,12);
|
||||
|
||||
debug_printf("ID :0x%08X ,计算得CRC 0x%08X \r\n",Sys.ID, HardCrc);
|
||||
|
||||
if(Sys.Version > 1) Encryption = true;
|
||||
|
||||
|
@ -330,13 +326,14 @@ void TinyClient::Report(Message& msg)
|
|||
msg.Length = ms.Position();
|
||||
}
|
||||
|
||||
void TinyClient::ReportPing(Message& msg)
|
||||
bool TinyClient::ReportPing(Message& msg)
|
||||
{
|
||||
// 没有服务端时不要上报
|
||||
if(!Server) return;
|
||||
if(!Server) return false;
|
||||
if(Store.Data.Length() > 18) return false;//主数据区长度超过18字节不带CRC校验
|
||||
|
||||
Stream ms = msg.ToStream();
|
||||
ms.Write((byte)0x01); // 子功能码
|
||||
ms.Write((byte)0x02); // 子功能码
|
||||
ms.Write(HardCrc); //硬件CRC
|
||||
ms.Write((byte)0x00); // 起始地址
|
||||
ms.Write((byte)Store.Data.Length()); // 长度
|
||||
|
@ -450,7 +447,8 @@ bool TinyClient::OnJoin(const TinyMessage& msg)
|
|||
Joining = false;
|
||||
|
||||
Cfg->SoftVer = dm.Version;
|
||||
if(Cfg->SoftVer > 1) Encryption=true;//大于1的版本加密
|
||||
if(Cfg->SoftVer < 2) Encryption=false;//小于2的版本加不加密
|
||||
|
||||
Cfg->Address = dm.Address;
|
||||
Control->Address = dm.Address;
|
||||
Password = dm.Password;
|
||||
|
@ -549,9 +547,11 @@ void TinyClient::Ping()
|
|||
|
||||
// 没事的时候,心跳指令承载0x01子功能码,作为数据上报
|
||||
if(Encryption)
|
||||
ReportPing(msg);
|
||||
if(!ReportPing(msg));
|
||||
Report(msg);
|
||||
else
|
||||
Report(msg);
|
||||
Report(msg);
|
||||
|
||||
Send(msg);
|
||||
|
||||
if(LastActive == 0) LastActive = Sys.Ms();
|
||||
|
|
|
@ -315,22 +315,21 @@ bool TinyServer::Disjoin(TinyMessage& msg,uint crc)
|
|||
// 心跳保持与对方的活动状态
|
||||
bool TinyServer::OnPing(const TinyMessage& msg)
|
||||
{
|
||||
Device* dv = FindDevice(msg.Src);
|
||||
// 网关内没有相关节点信息时不鸟他
|
||||
if(FindDevice(msg.Src) == NULL)return false;
|
||||
if(dv == NULL)return false;
|
||||
|
||||
// 准备一条响应指令
|
||||
TinyMessage rs;
|
||||
rs.Code = msg.Code;
|
||||
rs.Dest = msg.Src;
|
||||
rs.Sequence = msg.Sequence;
|
||||
|
||||
rs.Sequence = msg.Sequence;
|
||||
// 子操作码
|
||||
switch(msg.Data[0])
|
||||
{
|
||||
// 同步数据
|
||||
case 0x01:
|
||||
{
|
||||
Device* dv = FindDevice(msg.Src);
|
||||
{
|
||||
byte ver = 0;
|
||||
if(dv->Version > 1)
|
||||
{
|
||||
|
@ -365,9 +364,7 @@ bool TinyServer::OnPing(const TinyMessage& msg)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//todo。告诉客户端有多少待处理指令
|
||||
|
||||
Reply(rs);
|
||||
|
|
Loading…
Reference in New Issue