From 2812489c4b0a0b440d2e2acb4b3447ee9d343059 Mon Sep 17 00:00:00 2001 From: nnhy Date: Sat, 22 Aug 2015 01:51:51 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=B6=88=E6=81=AF=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E4=BC=A0=E8=BE=93=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Config.h | 2 +- TinyNet/TinyClient.cpp | 14 ++++++++++---- TinyNet/TinyServer.cpp | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Config.h b/Config.h index 206bf102..fb591cb8 100644 --- a/Config.h +++ b/Config.h @@ -21,7 +21,7 @@ public: byte Address; // 分配得到的设备地址 byte Server; // 网关ID byte Channel; // 通道 - byte Speed; // 传输速度 + ushort Speed; // 传输速度 byte ServerKey[16]; // 服务端组网密码,退网时使用。一般6字节 ushort PingTime; // 心跳时间。秒 diff --git a/TinyNet/TinyClient.cpp b/TinyNet/TinyClient.cpp index bae6de93..16313f97 100644 --- a/TinyNet/TinyClient.cpp +++ b/TinyNet/TinyClient.cpp @@ -258,13 +258,17 @@ bool TinyClient::OnJoin(TinyMessage& msg) // 记住服务端地址 Server = dm.Server; + Config.Channel = dm.Channel; + Config.Speed = dm.Speed == 0 ? 250 : (dm.Speed == 1 ? 1000 : 2000);; - debug_printf("组网成功!由网关 0x%02X 分配得到节点地址 0x%02X ,频道:%d,密码:", Server, dm.Address, dm.Channel); + debug_printf("组网成功!由网关 0x%02X 分配得到节点地址 0x%02X ,频道:%d,传输速率:%dkbps,密码:", Server, dm.Address, dm.Channel, Config.Speed); Password.Show(true); // 取消Join任务,启动Ping任务 Task* task = Scheduler[_TaskID]; - task->Period = Config.PingTime; + ushort time = Config.PingTime; + if(time < 5) time = 5; + task->Period = time * 1000000; // 组网成功更新一次最后活跃时间 LastActive = Time.Current(); @@ -281,11 +285,13 @@ bool TinyClient::OnDisjoin(TinyMessage& msg) // 心跳 void TinyClient::Ping() { - if(LastActive > 0 && LastActive + Config.OfflineTime * 1000000 < Time.Current()) + ushort off = Config.OfflineTime; + if(off < 10) off = 10; + if(LastActive > 0 && LastActive + off * 1000000 < Time.Current()) { if(Server == 0) return; - debug_printf("%d 秒无法联系,服务端可能已经掉线,重启Join任务,关闭Ping任务\r\n", Config.OfflineTime); + debug_printf("%d 秒无法联系,服务端可能已经掉线,重启Join任务,关闭Ping任务\r\n", off); Task* task = Scheduler[_TaskID]; task->Period = 5000000; diff --git a/TinyNet/TinyServer.cpp b/TinyNet/TinyServer.cpp index b33cfc9f..b6287008 100644 --- a/TinyNet/TinyServer.cpp +++ b/TinyNet/TinyServer.cpp @@ -191,7 +191,7 @@ bool TinyServer::OnJoin(TinyMessage& msg) dm.Server = Config.Address; dm.Channel = Config.Channel; - dm.Speed = Config.Speed; + dm.Speed = Config.Speed == 250 ? 0 : (Config.Speed == 1000 ? 1 : 2);; dm.Address = dv->Address; dm.Password = dv->Pass;