This commit is contained in:
cdyong 2015-11-11 01:36:11 +00:00
parent 1ebdc7026a
commit 2fa6f30d68
2 changed files with 41 additions and 9 deletions

View File

@ -326,12 +326,22 @@ void TinyClient::Report(Message& msg)
msg.Length = ms.Position();
}
bool TinyClient::ReportPing(Message& msg)
void TinyClient::ReportPing0x01(Message& msg)
{
if(!Server) return ;
Stream ms = msg.ToStream();
ms.Write((byte)0x01); // 子功能码
ms.Write(HardCrc); //硬件CRC
ms.Write((byte)0x00); // 起始地址
ms.Write((byte)Store.Data.Length()); // 长度
ms.Write(Store.Data);
msg.Length = ms.Position();
}
void TinyClient::ReportPing0x02(Message& msg)
{
// 没有服务端时不要上报
if(!Server) return false;
if(Store.Data.Length() > 18) return false;//主数据区长度超过18字节不带CRC校验
if(!Server) return ;
//主数据区长度超过18字节不带CRC校验
Stream ms = msg.ToStream();
ms.Write((byte)0x02); // 子功能码
ms.Write(HardCrc); //硬件CRC
@ -339,9 +349,17 @@ bool TinyClient::ReportPing(Message& msg)
ms.Write((byte)Store.Data.Length()); // 长度
ms.Write(Store.Data);
msg.Length = ms.Position();
return true;
}
void TinyClient::ReportPing0x03(Message& msg)
{
Stream ms = msg.ToStream();
ms.Write((byte)0x03); // 子功能码
ms.Write((byte)0x00); // 起始地址
ms.Write((byte)Store.Data.Length()); // 长度
ms.Write(Store.Data);
msg.Length = ms.Position();
}
bool TinyClient::Report(uint offset, byte dat)
{
TinyMessage msg;
@ -548,8 +566,19 @@ void TinyClient::Ping()
// 没事的时候心跳指令承载0x01子功能码作为数据上报
if(Encryption)
if(!ReportPing(msg))
Report(msg);
{
if(Store.Data.Length()<18)
{
ReportPing0x01(msg);
}
else
{
if(Store.Data.Length()<20)
ReportPing0x02(msg);
else
ReportPing0x03(msg);
}
}
else
Report(msg);

View File

@ -48,7 +48,10 @@ public:
void Report(Message& msg);
bool Report(uint offset, byte dat);
bool Report(uint offset, const ByteArray& bs);
bool ReportPing(Message& msg);
//特色心跳上报
void ReportPing0x01(Message& msg);
void ReportPing0x02(Message& msg);
void ReportPing0x03(Message& msg);
uint NextReport; // 下次上报偏移0不动
void ReportAsync(uint offset);