From cb888f2e82515d0b9cad1a9a7c417eb4afb64e3b Mon Sep 17 00:00:00 2001 From: nnhy Date: Fri, 4 Sep 2015 09:59:36 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BB=A5=E7=BD=91=E5=85=B3=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E4=B8=BA=E5=9F=BA=E5=87=86=EF=BC=8C=E8=BF=9B=E8=A1=8C=E9=80=92?= =?UTF-8?q?=E5=A2=9E=E5=88=86=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Config.cpp | 2 +- Config.h | 2 +- TinyNet/Device.cpp | 8 ++++---- TinyNet/Device.h | 2 +- TinyNet/TinyServer.cpp | 18 ++++-------------- TokenNet/Gateway.cpp | 2 +- 6 files changed, 12 insertions(+), 22 deletions(-) diff --git a/Config.cpp b/Config.cpp index 8e5a489d..3c6b6632 100644 --- a/Config.cpp +++ b/Config.cpp @@ -13,7 +13,7 @@ void TConfig::Init() void TConfig::LoadDefault() { - Type = Sys.Code; + Kind = Sys.Code; //Server = 0x01; PingTime = 15; diff --git a/Config.h b/Config.h index 08a6101b..cb850e45 100644 --- a/Config.h +++ b/Config.h @@ -17,7 +17,7 @@ public: byte HardVer; // 硬件版本 byte SoftVer; // 软件版本 - ushort Type; // 类型 + ushort Kind; // 类型 byte Address; // 分配得到的设备地址 byte Password[16]; // 通信密码 byte Server; // 网关ID diff --git a/TinyNet/Device.cpp b/TinyNet/Device.cpp index 6cc738f6..f6f04c6f 100644 --- a/TinyNet/Device.cpp +++ b/TinyNet/Device.cpp @@ -6,7 +6,7 @@ Device::Device() : HardID(0), Name(0), Pass(0) { Address = 0; - Type = 0; + Kind = 0; LastTime = 0; DataSize = 0; ConfigSize = 0; @@ -22,7 +22,7 @@ Device::Device() : HardID(0), Name(0), Pass(0) void Device::Write(Stream& ms) const { ms.Write(Address); - ms.Write(Type); + ms.Write(Kind); ms.WriteArray(HardID); ms.Write(LastTime); ms.Write(DataSize); @@ -33,7 +33,7 @@ void Device::Write(Stream& ms) const void Device::Read(Stream& ms) { Address = ms.Read(); - Type = ms.Read(); + Kind = ms.Read(); //ms.ReadArray(HardID); HardID = ms.ReadArray(); LastTime= ms.Read(); @@ -46,7 +46,7 @@ void Device::Read(Stream& ms) String& Device::ToStr(String& str) const { str = str + "Address=0x" + Address; - str = str + " Type=" + (byte)(Type >> 8) + (byte)(Type & 0xFF); + str = str + " Kind=" + (byte)(Kind >> 8) + (byte)(Kind & 0xFF); str = str + " Name=" + Name; str = str + " HardID=" + HardID; diff --git a/TinyNet/Device.h b/TinyNet/Device.h index 20d24d7b..fc3c7a7e 100644 --- a/TinyNet/Device.h +++ b/TinyNet/Device.h @@ -11,7 +11,7 @@ class Device : public Object { public: byte Address; // 节点地址 - ushort Type; // 类型 + ushort Kind; // 类型 ByteArray HardID; // 硬件编码 ulong LastTime; // 活跃时间 ushort Version; // 版本 diff --git a/TinyNet/TinyServer.cpp b/TinyNet/TinyServer.cpp index 3c4cd1ba..e47268a0 100644 --- a/TinyNet/TinyServer.cpp +++ b/TinyNet/TinyServer.cpp @@ -145,29 +145,21 @@ bool TinyServer::OnJoin(const TinyMessage& msg) byte id = msg.Src; if(!id) return false; + // 根据硬件编码找设备 Device* dv = FindDevice(dm.HardID); if(!dv) { // 以网关地址为基准,进行递增分配 byte addr = Config->Address; - // 查找该ID是否存在,如果不同设备有相同ID,则从0x02开始主动分配 - if(FindDevice(id) != NULL) { id = addr; while(FindDevice(++id) != NULL && id < 0xFF); - debug_printf("发现ID=0x%02X已分配,为当前节点分配 0x%02X\r\n", msg.Src, id); - } - else - { - id = Devices.Count() + addr; - // 注意,网关可能来不及添加 - if(id <= addr) id = addr + 1; - debug_printf("发现节点设备 0x%02X ,为其分配 0x%02X\r\n", msg.Src, id); + debug_printf("发现节点设备 0x%02X ,为其分配 0x%02X\r\n", dm.Kind, id); } dv = new Device(); - dv->Address = id; + dv->Address = id; Devices.Add(dv); @@ -179,11 +171,9 @@ bool TinyServer::OnJoin(const TinyMessage& msg) { Current = dv; - dv->Type = dm.Kind; + dv->Kind = dm.Kind; dv->HardID = dm.HardID; dv->Version = dm.Version; - //dv->Switchs = dm.Switchs; - //dv->Analogs = dm.Analogs; // 如果最后活跃时间超过60秒,则认为是设备上线 if(dv->LastTime == 5 || dv->LastTime + 6000000 < Time.Current()) diff --git a/TokenNet/Gateway.cpp b/TokenNet/Gateway.cpp index 992c88cf..287b0739 100644 --- a/TokenNet/Gateway.cpp +++ b/TokenNet/Gateway.cpp @@ -51,7 +51,7 @@ void Gateway::Start() { Device* dv = new Device(); dv->Address = Server->Config->Address; - dv->Type = Sys.Code; + dv->Kind = Sys.Code; dv->HardID.SetLength(16); dv->HardID = Sys.ID; dv->LastTime = Time.Current();