parent
d74e402eea
commit
cb73ba8580
|
@ -305,6 +305,7 @@ bool DevicesManagement::DeviceProcess(DeviceAtions act, const Pair& args, Stream
|
|||
ByteArray ids;
|
||||
args.Get("ids", ids);
|
||||
|
||||
// result.Write(ids.Length());
|
||||
for (int i = 0; i < ids.Length(); i++) // 判定依据需要修改
|
||||
{
|
||||
// 获取数据ms
|
||||
|
@ -314,17 +315,16 @@ bool DevicesManagement::DeviceProcess(DeviceAtions act, const Pair& args, Stream
|
|||
if (!GetDevInfo(ids[i], dvms))continue;
|
||||
// 转换为ByteArray
|
||||
ByteArray dvbs(dvms.GetBuffer(), dvms.Position());
|
||||
// 写入DevInfo
|
||||
// result.Write(String((byte)i)); // 数组格式 "idx" + Data
|
||||
result.Write((byte)1);
|
||||
result.Write((byte)i);
|
||||
result.WriteEncodeInt(dvbs.Length());
|
||||
result.Write(dvbs);
|
||||
|
||||
debug_printf("\r\n");
|
||||
ByteArray bs(result.GetBuffer(), result.Position());
|
||||
bs.Show(true);
|
||||
// 写入DevInfo
|
||||
result.WriteArray(String(i));
|
||||
|
||||
//result.Write((byte)1); // idxlen 这里打死不会超过127
|
||||
//result.Write((byte)i); // idx 这里长度不会大于127 所以简便写法 不使用压缩编码
|
||||
result.WriteEncodeInt(dvbs.Length()); // data[x]len
|
||||
result.Write(dvbs); // data[x]
|
||||
}
|
||||
// ByteArray(result.GetBuffer(), result.Position()).Show(true);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -427,10 +427,8 @@ bool DevicesManagement::GetDevInfo(Device *dv, MemoryStream &ms)
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
/******************************** 发送Invoke ********************************/
|
||||
|
||||
|
||||
void DevicesManagement::SendDevicesIDs()
|
||||
{
|
||||
// 获取IDList
|
||||
|
@ -540,7 +538,6 @@ void DevicesManagement::MaintainState()
|
|||
if (Port->Status < 2) return;
|
||||
SendDevicesIDs();
|
||||
|
||||
//auto now = Sys.Seconds();
|
||||
auto now = DateTime::Now().TotalSeconds();
|
||||
|
||||
// 处理持久在线设备
|
||||
|
@ -558,9 +555,6 @@ void DevicesManagement::MaintainState()
|
|||
|
||||
ushort time = dv->OfflineTime ? dv->OfflineTime : 60;
|
||||
|
||||
// 特殊处理网关自身
|
||||
// if (dv->Address == gw->Server->Cfg->Address) dv->LastTime = now;
|
||||
|
||||
if (dv->LastTime + time < now)
|
||||
{ // 下线
|
||||
if (dv->Logined)
|
||||
|
|
|
@ -83,6 +83,8 @@ void Gateway::Start()
|
|||
_task = Sys.AddTask(Loop, this, 10000, LOOP_Interval, "设备任务");
|
||||
|
||||
Running = true;
|
||||
|
||||
Client->Register("Gateway/Study", &Gateway::InvokeStudy, this);
|
||||
}
|
||||
|
||||
// 停止网关。取消本地和远程的消息挂载
|
||||
|
@ -298,6 +300,19 @@ Gateway* Gateway::CreateGateway(TokenClient* client, TinyServer* server)
|
|||
|
||||
return gw;
|
||||
}
|
||||
/******************************** invoke 调用********************************/
|
||||
|
||||
// 调用学习模式
|
||||
bool Gateway::InvokeStudy(const Pair& args, Stream& result)
|
||||
{
|
||||
uint time;
|
||||
args.Get("time", time);
|
||||
SetMode(time);
|
||||
result.Write((byte)true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 设备上线下线报备
|
||||
void Gateway::Loop(void* param)
|
||||
{
|
||||
|
@ -316,16 +331,6 @@ void Gateway::Loop(void* param)
|
|||
gw->SetMode(0);
|
||||
}
|
||||
}
|
||||
gw->pDevMgmt->MaintainState();
|
||||
}
|
||||
/******************************** invoke 调用********************************/
|
||||
// 调用学习模式
|
||||
bool Gateway::InvokeStudy(void * param, const Pair& args, Stream& result)
|
||||
{
|
||||
uint time;
|
||||
args.Get("time", time);
|
||||
auto gw = (Gateway*)param;
|
||||
gw->SetMode(time)
|
||||
;
|
||||
return true;
|
||||
// gw->pDevMgmt->MaintainState();
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
static Gateway* CreateGateway(TokenClient* client, TinyServer* server);
|
||||
|
||||
// 学习模式
|
||||
static bool InvokeStudy(void * param, const Pair& args, Stream& result);
|
||||
bool InvokeStudy(const Pair& args, Stream& result);
|
||||
|
||||
public:
|
||||
uint _task = 0; // 定时任务,10秒
|
||||
|
|
Loading…
Reference in New Issue