diff --git a/Config.cpp b/Config.cpp index 1fd287be..d70071f6 100644 --- a/Config.cpp +++ b/Config.cpp @@ -218,31 +218,3 @@ HotConfig& HotConfig::Current() return *(HotConfig*)dat; } - -// 初始化 -TConfig::TConfig() -{ - // 实际内存大小,减去头部大小 - uint len = sizeof(this) - ((int)&Length - (int)this); - //memset(&Length, 0, len); - Length = len; -} - -void TConfig::LoadDefault() -{ - Kind = Sys.Code; - //Server = 0x01; - - PingTime = 15; - OfflineTime = 60; -} - -void TConfig::Write(Stream& ms)const -{ - ms.Write((byte *)this, 0, sizeof(this[0])); -} - -void TConfig::Read(Stream& ms) -{ - memcpy((byte *)this, ms.GetBuffer(), sizeof(this[0])); -} diff --git a/Config.h b/Config.h index a58738a6..5ebd419b 100644 --- a/Config.h +++ b/Config.h @@ -59,39 +59,8 @@ public: }; -// 配置信息 -class TConfig -{ -public: - ushort Length; // 数据长度 - - byte HardVer; // 硬件版本 - byte SoftVer; // 软件版本 - ushort Kind; // 类型 - byte Address; // 分配得到的设备地址 - byte Password[16]; // 通信密码 - byte Server; // 网关ID - byte Channel; // 通道 - ushort Speed; // 传输速度 - byte ServerKey[16]; // 服务端组网密码,退网时使用。一般6字节 - - ushort PingTime; // 心跳时间。秒 - ushort OfflineTime; // 离线阀值时间。秒 - ushort SleepTime; // 睡眠时间。秒 - - // 初始化,各字段为0 - TConfig(); - void LoadDefault(); - - // 序列化到消息数据流 - void Write(Stream& ms) const; - void Read(Stream& ms); -}; - #pragma pack(pop) // 恢复对齐状态 -//extern TConfig Config; - /* 配置子系统,链式保存管理多配置段。 1,每个配置段都有固定长度的头部,包括签名、校验、名称等,数据紧跟其后 diff --git a/TinyNet/TinyClient.cpp b/TinyNet/TinyClient.cpp index 416f3c94..039b258b 100644 --- a/TinyNet/TinyClient.cpp +++ b/TinyNet/TinyClient.cpp @@ -1,6 +1,5 @@ #include "Time.h" #include "Task.h" -#include "Config.h" #include "TinyClient.h" @@ -26,7 +25,7 @@ TinyClient::TinyClient(TinyController* control) Received = NULL; Param = NULL; - Config = NULL; + Cfg = NULL; _TaskID = 0; @@ -45,12 +44,12 @@ void TinyClient::Open() _TaskID = Sys.AddTask(TinyClientTask, this, 0, 5000, "客户端服务"); - if(Config->Address > 0 && Config->Server > 0) + if(Cfg->Address > 0 && Cfg->Server > 0) { - Control->Address = Config->Address; - Server = Config->Server; + Control->Address = Cfg->Address; + Server = Cfg->Server; - Password.Load(Config->Password, ArrayLength(Config->Password)); + Password.Load(Cfg->Password, ArrayLength(Cfg->Password)); } } @@ -332,23 +331,23 @@ bool TinyClient::OnJoin(const TinyMessage& msg) Control->Address = dm.Address; Password = dm.Password; - Password.Save(Config->Password, ArrayLength(Config->Password)); + Password.Save(Cfg->Password, ArrayLength(Cfg->Password)); // 记住服务端地址 Server = dm.Server; - Config->Channel = dm.Channel; - Config->Speed = dm.Speed == 0 ? 250 : (dm.Speed == 1 ? 1000 : 2000); + Cfg->Channel = dm.Channel; + Cfg->Speed = dm.Speed == 0 ? 250 : (dm.Speed == 1 ? 1000 : 2000); // 服务端组网密码,退网使用 - Config->ServerKey[0] = dm.HardID.Length(); - dm.HardID.Save(Config->ServerKey, ArrayLength(Config->ServerKey)); + Cfg->ServerKey[0] = dm.HardID.Length(); + dm.HardID.Save(Cfg->ServerKey, ArrayLength(Cfg->ServerKey)); debug_printf("组网成功!\r\n"); - //debug_printf("组网成功!由网关 0x%02X 分配得到节点地址 0x%02X ,频道:%d,传输速率:%dkbps,密码:", Server, dm.Address, dm.Channel, Config->Speed); + //debug_printf("组网成功!由网关 0x%02X 分配得到节点地址 0x%02X ,频道:%d,传输速率:%dkbps,密码:", Server, dm.Address, dm.Channel, Cfg->Speed); //Password.Show(true); // 这里出错 问题未知 // 取消Join任务,启动Ping任务 - ushort time = Config->PingTime; + ushort time = Cfg->PingTime; if(time < 5) time = 5; if(time > 60) time = 60; Sys.SetTaskPeriod(_TaskID, time * 1000); @@ -368,7 +367,7 @@ bool TinyClient::OnDisjoin(const TinyMessage& msg) // 心跳 void TinyClient::Ping() { - ushort off = Config->OfflineTime; + ushort off = Cfg->OfflineTime; if(off < 10) off = 10; if(LastActive > 0 && LastActive + off * 1000 < Time.Current()) { diff --git a/TinyNet/TinyClient.h b/TinyNet/TinyClient.h index 790d655a..acaf3ce1 100644 --- a/TinyNet/TinyClient.h +++ b/TinyNet/TinyClient.h @@ -2,8 +2,9 @@ #define __TinyClient_H__ #include "Sys.h" -#include "Config.h" + #include "TinyMessage.h" +#include "TinyConfig.h" #include "Message\DataStore.h" @@ -15,7 +16,7 @@ private: public: TinyController* Control; - TConfig* Config; + TinyConfig* Cfg; byte Server; // 服务端地址 ushort Type; // 设备类型。两个字节可做二级分类 diff --git a/TinyNet/TinyServer.h b/TinyNet/TinyServer.h index c21304ec..446a56b4 100644 --- a/TinyNet/TinyServer.h +++ b/TinyNet/TinyServer.h @@ -4,9 +4,9 @@ #include "Sys.h" #include "TinyMessage.h" +#include "TinyConfig.h" #include "TinyNet\Device.h" -#include "TinyNet\TinyConfig.h" /******************************** TinyServer ********************************/