using System;
using System.Collections.Generic;
using ZigBee.Common;
using Shared;
using System.Linq;
using System.Text;
using System.Threading;
using System.Net.Sockets;
using System.Net;
using Newtonsoft.Json.Linq;
using MQTTnet;
using Shared.Common;
using Shared.Phone.UserView;
using MQTTnet.Client;
using System.Threading.Tasks;
namespace ZigBee.Device
{
/// ƒ
/// ZigBee网关对象
///
[System.Serializable]
public class ZbGateway : ZbGatewayData
{
public ZbGateway()
{
this.Type = DeviceType.ZbGateway;
}
#region 网关特殊信息处理
///
/// 主网关
///
/// The main gate way.
public static ZbGateway MainGateWay
{
get
{
return GateWayList.Find((obj) => { return obj.getGatewayBaseInfo.HomeId == Shared.Common.Config.Instance.HomeId && obj.getGatewayBaseInfo.IsMainGateWay; });
}
}
///
/// 主网关
///
[Newtonsoft.Json.JsonIgnore]
public bool IsMainGateWay
{
get
{
return getGatewayBaseInfo != null && getGatewayBaseInfo.IsMainGateWay;
}
}
///
/// 是否使用远程连接模式
///
/// true if is remote; otherwise, false.
public static bool IsRemote;
///
/// 是否拥有远程连接的权限
///
[Newtonsoft.Json.JsonIgnore]
public static bool AllowRemoteCtrl = true;
///
/// 网关保存路径
///
/// The file path.
[Newtonsoft.Json.JsonIgnore]
public override string FilePath
{
get
{
var deviceType = Type.ToString();
var fileName = "Gateway_" + deviceType + "_" + this.getGatewayBaseInfo?.gwID;
return fileName;
}
}
///
/// 局域网加密密码
///
string password;
///
/// 局域网加密密钥
///
[Newtonsoft.Json.JsonIgnore]
public string Password
{
get
{
if (password == null)
{
password = Guid.NewGuid().ToString().Substring(0, 16);
}
return password;
}
}
#region variable
///
/// 远程连接成功时的时间
///
public static DateTime LoginRemoteDateTime = DateTime.Now;
///
/// 同步到远程的当前时间戳
/// Re
public static ulong CurrentTimeStamp
{
get
{
return RemoteTimeStamp + (ulong)(DateTime.Now - LoginRemoteDateTime).TotalSeconds;
}
}
///
/// 远程连接成功时的时间戳
///
public static ulong RemoteTimeStamp;
///
/// 网关是否加密
///
[Newtonsoft.Json.JsonIgnore]
public bool IsEncry;
///
/// 网关当前公钥
///
[Newtonsoft.Json.JsonIgnore]
public string PubKey;
///
/// 所有的网关列表
///
[Newtonsoft.Json.JsonIgnore]
public static List GateWayList = new List();
//当前网关中的设备列表
[Newtonsoft.Json.JsonIgnore]
public List DeviceList = new List();
///
/// 网关中场景列表
/// 一个场景中包含所有信息,包括场景设备信息
///
[Newtonsoft.Json.JsonIgnore]
public static List AllSceneList = new List();
///
/// 网关中场景的设备列表
///
[Newtonsoft.Json.JsonIgnore]
public List SceneDeviceList = new List();
#region action variable
///
/// 接收数据后回调
///
[Newtonsoft.Json.JsonIgnore]
Action