diff --git a/Config.cpp b/Config.cpp index bc143301..a724e8b7 100644 --- a/Config.cpp +++ b/Config.cpp @@ -3,9 +3,15 @@ TConfig Config; // 初始化,各字段为0 -TConfig::TConfig() +void TConfig::Init() { // 实际内存大小,减去头部大小 - Length = sizeof(this) - (int)&Length - (int)this; - memset(&Length, 0, Length); + uint len = sizeof(this) - (int)&Length - (int)this; + memset(&Length, 0, len); + Length = len; } + +void TConfig::LoadDefault() +{ + +} \ No newline at end of file diff --git a/Config.h b/Config.h index 56d5351e..c7d495c9 100644 --- a/Config.h +++ b/Config.h @@ -13,10 +13,20 @@ class TConfig { public: - int Length; // 数据长度 + ushort Length; // 数据长度 + + byte HardVer; // 硬件版本 + byte SoftVer; // 软件版本 + ushort Type; // 类型 + byte Address; // 分配得到的设备地址 + byte Server; // 网关ID + byte Channel; // 通道 + byte Speed; // 传输速度 + ByteArray ServerKey; // 服务端组网密码,退网时使用。一般6字节 // 初始化,各字段为0 - TConfig(); + void Init(); + void LoadDefault(); }; #pragma pack(pop) // 恢复对齐状态 diff --git a/TinyNet/TinyServer.cpp b/TinyNet/TinyServer.cpp index 84410afe..f5cc49af 100644 --- a/TinyNet/TinyServer.cpp +++ b/TinyNet/TinyServer.cpp @@ -116,12 +116,8 @@ bool TinyServer::OnJoin(TinyMessage& msg) if(!id) return false; Device* dv = FindDevice(dm.HardID); - //Device* dv = FindDevice(id); - //bool isNew = false; if(!dv) { - //isNew = true; - // 查找该ID是否存在,如果不同设备有相同ID,则从0x02开始主动分配 if(FindDevice(id) != NULL) { @@ -175,6 +171,7 @@ bool TinyServer::OnJoin(TinyMessage& msg) ulong now = Time.Current(); ByteArray bs((byte*)&now, 8); dv->Pass = MD5::Hash(bs); + dv->Pass.SetLength(8); // 小心不要超长 // 响应 TinyMessage rs; @@ -183,10 +180,12 @@ bool TinyServer::OnJoin(TinyMessage& msg) rs.Sequence = msg.Sequence; // 发现响应 - JoinMessage dm; + //JoinMessage dm; dm.Reply = true; dm.Address = dv->Address; dm.Password = dv->Pass; + dm.HardID.SetLength(6); // 小心不要超长 + dm.HardID = Sys.ID; dm.WriteMessage(rs); Reply(rs);