设备list命令未做
This commit is contained in:
parent
efbb0b794e
commit
dfd2f9ce89
|
@ -267,24 +267,26 @@ bool DevicesManagement::DeviceProcess(const Message& msg)
|
|||
|
||||
TS("DevicesManagement::DeviceProcess");
|
||||
|
||||
auto act = (DeviceAtions)msg.Data[0];
|
||||
byte id = msg.Data[1];
|
||||
auto ms = msg.ToStream();
|
||||
|
||||
DeviceMessage dm;
|
||||
if (!dm.GetBaseInfo(ms))return false;
|
||||
auto dv = FindDev(dm.Id);
|
||||
|
||||
TokenMessage rs;
|
||||
rs.Code = 0x21;
|
||||
rs.Length = 2;
|
||||
rs.Data[0] = (byte)act;
|
||||
rs.Data[1] = id;
|
||||
|
||||
auto dv = FindDev(id);
|
||||
// 外部处理
|
||||
if (_DevProcess)_DevProcess(act, dv, _ClbkParam);
|
||||
if (dv)
|
||||
{
|
||||
// 外部处理
|
||||
if (_DevProcess)_DevProcess(dm.Action, dv, _ClbkParam);
|
||||
|
||||
switch (act)
|
||||
}
|
||||
switch (dm.Action)
|
||||
{
|
||||
case DeviceAtions::List:
|
||||
{
|
||||
SendDevices(act, nullptr);
|
||||
SendDevices(dm.Action, nullptr);
|
||||
return true;
|
||||
}
|
||||
case DeviceAtions::Update:
|
||||
|
@ -296,13 +298,16 @@ bool DevicesManagement::DeviceProcess(const Message& msg)
|
|||
}
|
||||
else
|
||||
{
|
||||
auto ms = msg.ToStream();
|
||||
ms.Seek(2);
|
||||
|
||||
dv->ReadMessage(ms);
|
||||
// 获取信息
|
||||
dm.GetMsgInfo(ms, dv);
|
||||
SaveDev();
|
||||
// 拿到写后的信息
|
||||
DeviceMessage dmrs;
|
||||
dmrs.pDev = dv;
|
||||
dmrs.Action = dm.Action;
|
||||
dmrs.WriteMessage(rs);
|
||||
}
|
||||
|
||||
// 发送
|
||||
if (Port)Port->Reply(rs);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
|
||||
#include "Sys.h"
|
||||
#include "Stream.h"
|
||||
#include "Device.h"
|
||||
#include "TokenNet\Device.h"
|
||||
#include "TokenNet\DeviceMessage.h"
|
||||
|
||||
#include "Flash.h"
|
||||
#include "TinyConfig.h"
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define __PingMessage_H__
|
||||
|
||||
#include "Message\MessageBase.h"
|
||||
#include "Device.h"
|
||||
#include "TokenNet\Device.h"
|
||||
|
||||
// 心跳消息
|
||||
class PingMessage : public MessageBase
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "Sys.h"
|
||||
#include "Net\ITransport.h"
|
||||
#include "Stream.h"
|
||||
#include "Device.h"
|
||||
#include "TokenNet\Device.h"
|
||||
|
||||
#include "Message\Controller.h"
|
||||
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
#include "Stream.h"
|
||||
|
||||
#include "Flash.h"
|
||||
|
||||
#include "TinyConfig.h"
|
||||
#include "TinyNet\TinyConfig.h"
|
||||
|
||||
/******************************** Device ********************************/
|
||||
|
|
@ -1,49 +1,110 @@
|
|||
#include "DeviceMessage.h"
|
||||
|
||||
#include "Security\MD5.h"
|
||||
#include "Message\BinaryPair.h"
|
||||
|
||||
// 初始化消息,各字段为0
|
||||
DeviceMessage::DeviceMessage() : HardID(16), Key(6)
|
||||
DeviceMessage::DeviceMessage()
|
||||
{
|
||||
}
|
||||
|
||||
// 初始化消息,各字段为0
|
||||
DeviceMessage::DeviceMessage(Device* dv)
|
||||
{
|
||||
pDev = dv;
|
||||
}
|
||||
|
||||
// 拿ID 不修改ms
|
||||
bool DeviceMessage::GetBaseInfo(Stream& ms)
|
||||
{
|
||||
BinaryPair bp(ms);
|
||||
byte act;
|
||||
if (!bp.Get("Action",act))return false;
|
||||
Action = (DeviceAtions)act;
|
||||
if (!bp.Get("ID", Id))return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeviceMessage::GetMsgInfo(Stream&ms, Device* dv)
|
||||
{
|
||||
pDev = dv;
|
||||
byte id = 0;
|
||||
|
||||
BinaryPair bp(ms);
|
||||
bp.Get("ID", id);
|
||||
if (pDev->Address == 0)pDev->Address = id;
|
||||
if (id != pDev->Address)
|
||||
{
|
||||
debug_printf("ERROR");
|
||||
return false;
|
||||
}
|
||||
byte login = 0;
|
||||
if (bp.Get("Online", login))
|
||||
pDev->Logined = login;
|
||||
bp.Get("Kind", pDev->Kind);
|
||||
bp.Get("LastActive", pDev->LastTime);
|
||||
bp.Get("RegisterTime", pDev->RegTime);
|
||||
bp.Get("LoginTime", pDev->LoginTime);
|
||||
// bp.Get("HardID", pDev->Logins);
|
||||
|
||||
bp.Get("Version", pDev->Version);
|
||||
bp.Get("DataSize", pDev->DataSize);
|
||||
bp.Get("ConfigSize", pDev->ConfigSize);
|
||||
|
||||
bp.Get("SleepTime", pDev->SleepTime);
|
||||
bp.Get("Offline", pDev->OfflineTime);
|
||||
bp.Get("PingTime", pDev->PingTime);
|
||||
|
||||
bp.Get("HardID", pDev->HardID);
|
||||
bp.Get("Name", pDev->Name);
|
||||
|
||||
bp.Get("Password", pDev->Pass);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 从数据流中读取消息
|
||||
bool DeviceMessage::Read(Stream& ms)
|
||||
{
|
||||
ms.ReadArray(HardID);
|
||||
ms.ReadArray(Key);
|
||||
ms.ReadArray(Salt);
|
||||
|
||||
Local.Address = ms.ReadBytes(4);
|
||||
Local.Port = ms.ReadUInt16();
|
||||
|
||||
return false;
|
||||
GetBaseInfo(ms);
|
||||
if (pDev == 0)return false;
|
||||
return GetMsgInfo(ms, pDev);
|
||||
}
|
||||
|
||||
// 把消息写入数据流中
|
||||
void DeviceMessage::Write(Stream& ms) const
|
||||
{
|
||||
ms.WriteArray(HardID);
|
||||
BinaryPair bp(ms);
|
||||
byte act = (byte)Action;
|
||||
bp.Set("Action", act);
|
||||
bp.Set("ID", pDev->Address);
|
||||
|
||||
// 密码取MD5后传输
|
||||
ms.WriteArray(MD5::Hash(Key));
|
||||
byte login = pDev->Logined ? 1 : 0;
|
||||
bp.Set("Online", login);
|
||||
bp.Set("Kind", pDev->Kind);
|
||||
bp.Set("LastActive", pDev->LastTime);
|
||||
bp.Set("RegisterTime", pDev->RegTime);
|
||||
bp.Set("LoginTime", pDev->LoginTime);
|
||||
// bp.Set("HardID", pDev->Logins);
|
||||
|
||||
UInt64 now = Sys.Ms();
|
||||
//Salt.Set((byte*)&now, 8);
|
||||
//ms.WriteArray(Salt);
|
||||
ms.WriteArray(Buffer(&now, 8));
|
||||
bp.Set("Version", pDev->Version);
|
||||
bp.Set("DataSize", pDev->DataSize);
|
||||
bp.Set("ConfigSize", pDev->ConfigSize);
|
||||
|
||||
ms.Write(Local.Address.ToArray());
|
||||
ms.Write((ushort)Local.Port);
|
||||
bp.Set("SleepTime", pDev->SleepTime);
|
||||
bp.Set("Offline", pDev->OfflineTime);
|
||||
bp.Set("PingTime", pDev->PingTime);
|
||||
|
||||
bp.Set("HardID", pDev->HardID);
|
||||
bp.Set("Name", pDev->Name);
|
||||
|
||||
bp.Set("Password", pDev->Pass);
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
// 显示消息内容
|
||||
String& DeviceMessage::ToStr(String& str) const
|
||||
{
|
||||
str += "登录";
|
||||
if(Reply) str += "#";
|
||||
str = str + " HardID=" + HardID + " Key=" + Key + " Salt=" + Salt + " " + Local;
|
||||
str += "DeviceMessage";
|
||||
|
||||
return str;
|
||||
}
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
|
||||
#include "Message\MessageBase.h"
|
||||
#include "Net\Net.h"
|
||||
#include "TokenNet\Device.h"
|
||||
|
||||
enum class DeviceAtions
|
||||
enum class DeviceAtions : byte
|
||||
{
|
||||
// <summary>信息列表。请求ID列表,响应设备信息列表</summary>
|
||||
List,
|
||||
|
@ -31,16 +32,16 @@ enum class DeviceAtions
|
|||
class DeviceMessage : public MessageBase
|
||||
{
|
||||
public:
|
||||
ByteArray HardID; // 硬件ID
|
||||
ByteArray Key; // 登录密码
|
||||
ByteArray Salt; // 加盐
|
||||
IPEndPoint Local; // 内网地址
|
||||
|
||||
bool Reply; // 是否响应
|
||||
DeviceAtions Action;
|
||||
byte Id = 0;
|
||||
Device * pDev = nullptr;
|
||||
|
||||
// 初始化消息,各字段为0
|
||||
DeviceMessage();
|
||||
|
||||
DeviceMessage(Device *dv);
|
||||
// 拿ID 不修改ms
|
||||
bool GetBaseInfo(Stream& ms);
|
||||
bool GetMsgInfo(Stream&ms, Device* dv);
|
||||
// 从数据流中读取消息
|
||||
virtual bool Read(Stream& ms);
|
||||
// 把消息写入数据流中
|
||||
|
|
Loading…
Reference in New Issue