服务端心跳和退网处理,设备ID共用处理
This commit is contained in:
parent
8a11a5f210
commit
d7faacab39
|
@ -32,7 +32,7 @@ struct TinyConfig
|
||||||
byte ServerKey[16]; // 服务端组网密码,退网时使用。一般6字节
|
byte ServerKey[16]; // 服务端组网密码,退网时使用。一般6字节
|
||||||
|
|
||||||
|
|
||||||
// 初始化,各字段为0
|
//初始化,各字段为0
|
||||||
//TinyConfig();
|
//TinyConfig();
|
||||||
//const TinyConfig& Default();
|
//const TinyConfig& Default();
|
||||||
byte StartSet;
|
byte StartSet;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "Flash.h"
|
#include "Flash.h"
|
||||||
#include "TinyServer.h"
|
#include "TinyServer.h"
|
||||||
|
#include "Security\Crc.h"
|
||||||
|
|
||||||
#include "JoinMessage.h"
|
#include "JoinMessage.h"
|
||||||
|
|
||||||
|
@ -300,12 +301,29 @@ bool TinyServer::OnDisjoin(const TinyMessage& msg)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TinyServer::Disjoin(TinyMessage& msg,uint crc)
|
||||||
|
{
|
||||||
|
msg.Code = 0x02;
|
||||||
|
Stream ms = msg.ToStream();
|
||||||
|
ms.Write(crc);
|
||||||
|
msg.Length = ms.Position();
|
||||||
|
|
||||||
|
Reply(msg);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
// 心跳保持与对方的活动状态
|
// 心跳保持与对方的活动状态
|
||||||
bool TinyServer::OnPing(const TinyMessage& msg)
|
bool TinyServer::OnPing(const TinyMessage& msg)
|
||||||
{
|
{
|
||||||
// 网关内没有相关节点信息时不鸟他
|
// 网关内没有相关节点信息时不鸟他
|
||||||
if(FindDevice(msg.Src) == NULL)return false;
|
if(FindDevice(msg.Src) == NULL)return false;
|
||||||
|
|
||||||
|
// 准备一条响应指令
|
||||||
|
TinyMessage rs;
|
||||||
|
rs.Code = msg.Code;
|
||||||
|
rs.Dest = msg.Src;
|
||||||
|
rs.Sequence = msg.Sequence;
|
||||||
|
|
||||||
// 子操作码
|
// 子操作码
|
||||||
switch(msg.Data[0])
|
switch(msg.Data[0])
|
||||||
{
|
{
|
||||||
|
@ -313,10 +331,26 @@ bool TinyServer::OnPing(const TinyMessage& msg)
|
||||||
case 0x01:
|
case 0x01:
|
||||||
{
|
{
|
||||||
Device* dv = Current;
|
Device* dv = Current;
|
||||||
if(dv && msg.Length >= 4)
|
byte ver = 0;
|
||||||
|
if(dv->Version > 1)
|
||||||
{
|
{
|
||||||
byte offset = msg.Data[1];
|
Stream ms(msg.Data, msg.Length);
|
||||||
byte len = msg.Data[2];
|
ushort crc = ms.ReadUInt16();
|
||||||
|
ushort crc1 = Crc::Hash16(&dv->HardID, dv->HardID.Length());
|
||||||
|
if(crc ==crc1) ver = 2;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
debug_printf("设备硬件Crc:%0x%08X,对比Crc:%0x%08X \r\n",crc,crc1);
|
||||||
|
debug_printf("设备硬件ID");
|
||||||
|
dv->HardID.Show();
|
||||||
|
Disjoin(rs,crc);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(dv && msg.Length >= ver + 4)
|
||||||
|
{
|
||||||
|
byte offset = msg.Data[ver + 1];
|
||||||
|
byte len = msg.Data[ver + 2];
|
||||||
debug_printf("设备 0x%02X 同步数据(%d, %d)到网关缓存 \r\n", dv->Address, offset, len);
|
debug_printf("设备 0x%02X 同步数据(%d, %d)到网关缓存 \r\n", dv->Address, offset, len);
|
||||||
|
|
||||||
int remain = dv->Store.Capacity() - offset;
|
int remain = dv->Store.Capacity() - offset;
|
||||||
|
@ -330,11 +364,6 @@ bool TinyServer::OnPing(const TinyMessage& msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 响应 Ping 指令,告诉客户端有多少指令需要等待执行
|
|
||||||
TinyMessage rs;
|
|
||||||
rs.Code = msg.Code;
|
|
||||||
rs.Dest = msg.Src;
|
|
||||||
rs.Sequence = msg.Sequence;
|
|
||||||
|
|
||||||
//todo。告诉客户端有多少待处理指令
|
//todo。告诉客户端有多少待处理指令
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,7 @@ public:
|
||||||
|
|
||||||
bool ResetPassword(byte id);
|
bool ResetPassword(byte id);
|
||||||
|
|
||||||
|
bool Disjoin(TinyMessage& msg,uint crc);
|
||||||
bool OnDisjoin(const TinyMessage& msg);
|
bool OnDisjoin(const TinyMessage& msg);
|
||||||
|
|
||||||
// 心跳
|
// 心跳
|
||||||
|
|
Loading…
Reference in New Issue