解决组网响应指令超长问题

This commit is contained in:
nnhy 2015-08-21 08:50:08 +00:00
parent 1692163fd4
commit 8dfd360f8b
3 changed files with 25 additions and 10 deletions

View File

@ -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()
{
}

View File

@ -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) // 恢复对齐状态

View File

@ -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);