组网成功更新一次最后活跃时间
This commit is contained in:
parent
19a14bc5dc
commit
692ca31fed
|
@ -15,4 +15,7 @@ void TConfig::LoadDefault()
|
|||
{
|
||||
Type = Sys.Code;
|
||||
//Server = 0x01;
|
||||
|
||||
PingTime = 15;
|
||||
OfflineTime = 60;
|
||||
}
|
||||
|
|
6
Config.h
6
Config.h
|
@ -22,7 +22,11 @@ public:
|
|||
byte Server; // 网关ID
|
||||
byte Channel; // 通道
|
||||
byte Speed; // 传输速度
|
||||
ByteArray ServerKey; // 服务端组网密码,退网时使用。一般6字节
|
||||
byte ServerKey[16]; // 服务端组网密码,退网时使用。一般6字节
|
||||
|
||||
ushort PingTime; // 心跳时间。秒
|
||||
ushort OfflineTime; // 离线阀值时间。秒
|
||||
ushort SleepTime; // 睡眠时间。秒
|
||||
|
||||
// 初始化,各字段为0
|
||||
void Init();
|
||||
|
|
|
@ -241,30 +241,33 @@ bool TinyClient::OnJoin(TinyMessage& msg)
|
|||
// 客户端只处理Discover响应
|
||||
if(!msg.Reply || msg.Error) return true;
|
||||
|
||||
// 校验不对
|
||||
if(TranID != msg.Sequence)
|
||||
{
|
||||
debug_printf("发现响应序列号 %d 不等于内部序列号 %d \r\n", msg.Sequence, TranID);
|
||||
//return true;
|
||||
}
|
||||
|
||||
// 解析数据
|
||||
JoinMessage dm;
|
||||
dm.ReadMessage(msg);
|
||||
dm.Show(true);
|
||||
|
||||
// 校验不对
|
||||
if(TranID != dm.TranID)
|
||||
{
|
||||
debug_printf("发现响应序列号 0x%08X 不等于内部序列号 0x%08X \r\n", dm.TranID, TranID);
|
||||
//return true;
|
||||
}
|
||||
|
||||
Control->Address = dm.Address;
|
||||
Password = dm.Password;
|
||||
|
||||
// 记住服务端地址
|
||||
Server = dm.Server;
|
||||
|
||||
debug_printf("组网成功!由网关 0x%02X 分配得到节点地址 0x%02X ,频道:%d,密码:", Server, dm.Address, 0);
|
||||
debug_printf("组网成功!由网关 0x%02X 分配得到节点地址 0x%02X ,频道:%d,密码:", Server, dm.Address, dm.Channel);
|
||||
Password.Show(true);
|
||||
|
||||
// 取消Join任务,启动Ping任务
|
||||
Task* task = Scheduler[_TaskID];
|
||||
task->Period = 15000000;
|
||||
task->Period = Config.PingTime;
|
||||
|
||||
// 组网成功更新一次最后活跃时间
|
||||
LastActive = Time.Current();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -278,11 +281,11 @@ bool TinyClient::OnDisjoin(TinyMessage& msg)
|
|||
// 心跳
|
||||
void TinyClient::Ping()
|
||||
{
|
||||
if(LastActive > 0 && LastActive + 60000000 < Time.Current())
|
||||
if(LastActive > 0 && LastActive + Config.OfflineTime * 1000000 < Time.Current())
|
||||
{
|
||||
if(Server == 0) return;
|
||||
|
||||
debug_printf("30秒无法联系,服务端可能已经掉线,重启Join任务,关闭Ping任务\r\n");
|
||||
debug_printf("%d 秒无法联系,服务端可能已经掉线,重启Join任务,关闭Ping任务\r\n", Config.OfflineTime);
|
||||
|
||||
Task* task = Scheduler[_TaskID];
|
||||
task->Period = 5000000;
|
||||
|
|
|
@ -167,7 +167,7 @@ bool TinyServer::OnJoin(TinyMessage& msg)
|
|||
}
|
||||
dv->LastTime = Time.Current();
|
||||
|
||||
debug_printf("\r\nTinyServer::新设备 ");
|
||||
debug_printf("\r\nTinyServer::新设备组网 0x%08X \r\n", dm.TranID);
|
||||
dv->Show(true);
|
||||
|
||||
// 对于已注册的设备,再来发现消息不做处理
|
||||
|
|
Loading…
Reference in New Issue