using System;
|
using System.Collections.Generic;
|
using HDL_ON.Entity;
|
using Shared;
|
|
namespace HDL_ON.UI.UI2.Intelligence.Automation
|
{
|
|
public class LogicMethod
|
{
|
/// <summary>
|
/// 定义一个静态对象
|
/// </summary>
|
private static LogicMethod logicMethod = null;
|
/// <summary>
|
/// 获取静态对象
|
/// </summary>
|
public static LogicMethod CurrLogicMethod
|
{
|
get
|
{
|
if (logicMethod == null)
|
{
|
return new LogicMethod();
|
}
|
return logicMethod;
|
}
|
|
}
|
|
/// <summary>
|
/// 表示是条件
|
/// </summary>
|
public const string condition_if = "条件";
|
/// <summary>
|
/// 表示是目标
|
/// </summary>
|
public const string target_if = "目标";
|
/// <summary>
|
/// 移除所有"Logic"界面
|
/// </summary>
|
public void RemoveAllView()
|
{
|
MainPage.BasePageView.RemoveViewByTag("Logic");
|
}
|
|
/// <summary> Converts an array of bytes into a formatted string of hex digits (ex: E4 CA B2)</summary>
|
/// <param name="data"> The array of bytes to be translated into a string of hex digits. </param>
|
/// <returns> Returns a well formatted string of hex digits with spacing. </returns>
|
public string byteArrayToHexString(byte[] data)
|
{
|
System.Text.StringBuilder sb = new System.Text.StringBuilder();
|
foreach (byte b in data)
|
{
|
sb.Append(Convert.ToString(b, 16).PadLeft(2, '0'));
|
}
|
|
return sb.ToString().ToUpper();
|
}
|
|
/**
|
* int转byte[]
|
* 该方法将一个int类型的数据转换为byte[]形式,因为int为32bit,而byte为8bit所以在进行类型转换时,知会获取低8位,
|
* 丢弃高24位。通过位移的方式,将32bit的数据转换成4个8bit的数据。注意 &0xff,在这当中,&0xff简单理解为一把剪刀,
|
* 将想要获取的8位数据截取出来。
|
* @param i 一个int数字
|
* @return byte[]
|
*/
|
public byte[] int2ByteArray(int i)
|
{
|
byte[] result = new byte[4];
|
result[0] = (byte)((i >> 24) & 0xFF);
|
result[1] = (byte)((i >> 16) & 0xFF);
|
result[2] = (byte)((i >> 8) & 0xFF);
|
result[3] = (byte)(i & 0xFF);
|
return result;
|
}
|
/// <summary>
|
/// 获取时间戳
|
/// </summary>
|
/// <returns></returns>
|
public int getTimeStamp()
|
{
|
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
|
return (int)ts.TotalSeconds;
|
}
|
/// <summary>
|
/// 生成逻辑sid方法
|
/// </summary>
|
public string NewSid()
|
{
|
string logicId = "";
|
try
|
{
|
string sOidBeginsWith = "000101";//厂商 + 通讯方式
|
DateTime dt = DateTime.Now;
|
DateTime startTime = TimeZoneInfo.ConvertTimeToUtc(new DateTime(2020, 1, 1));
|
long m = (long)((dt - startTime).TotalMilliseconds / 10);
|
string sTimeSpan = byteArrayToHexString(int2ByteArray(getTimeStamp()));
|
|
|
|
logicId = sOidBeginsWith + sTimeSpan;
|
|
logicId += "15";
|
logicId += "1501";
|
//1501 物模型为逻辑, 0001 表示 1 号逻辑功能
|
int maxId = 1;
|
|
|
for (int i = 0; i < Logic.LogicList.Count; i++)
|
{
|
string s = Logic.LogicList[i].sid.Substring(20, 4);
|
int iThisSceneId = Convert.ToInt16(s, 16);
|
if (iThisSceneId > maxId)
|
maxId = iThisSceneId;
|
}
|
|
logicId += (maxId + 1).ToString("X4");//逻辑号 两个byte
|
logicId += "0000";
|
}
|
catch
|
{
|
return logicId;
|
}
|
return logicId;
|
}
|
/// <summary>
|
/// 封装Dictionary对象
|
/// </summary>
|
/// <param name="dic">Dictionary类</param>
|
/// <param name="key">健</param>
|
/// <param name="value">值</param>
|
public void dictionary(Dictionary<string, string> dic, string key, string value)
|
{
|
if (dic.ContainsKey(key)) //判断是否存在键值
|
{
|
//键存在移除
|
dic.Remove(key);
|
}
|
//添加键值
|
dic.Add(key, value);
|
}
|
/// <summary>
|
/// 获取网关房间列表
|
/// </summary>
|
/// <returns></returns>
|
public List<HDL_ON.Entity.Room> GetGatewayRoomList()
|
{
|
return HDL_ON.Entity.SpatialInfo.CurrentSpatial.RoomList;
|
}
|
/// <summary>
|
/// 获取网关房间列表
|
/// </summary>
|
/// <returns></returns>
|
public List<HDL_ON.Entity.Room> GetGatewayRoomList(string name)
|
{
|
List<Entity.Room> roomList = new List<Entity.Room>();
|
Entity.Room room1 = new Entity.Room();
|
room1.roomName = name;//自定义默认一个房间名为:6688
|
room1.roomId = "6688";//自定义默认id用识别该房间
|
roomList.Add(room1);//默认添加到房间列表里
|
var roomLists = GetGatewayRoomList();
|
for (int i = 0; i < roomLists.Count; i++)
|
{
|
var room = roomLists[i];
|
var devlist = GetRoomDevice(room);
|
if (devlist.Count == 0)
|
{
|
//过滤掉没有设备的房间;
|
continue;
|
}
|
roomList.Add(room);
|
}
|
return roomList;
|
}
|
/// <summary>
|
/// 获取网关设备列表
|
/// </summary>
|
/// <returns></returns>
|
public List<HDL_ON.Entity.Function> GetGatewayDeviceList()
|
{
|
return Entity.FunctionList.List.GetDeviceFunctionList();
|
}
|
/// <summary>
|
/// 获取场景列表
|
/// </summary>
|
/// <returns></returns>
|
public List<HDL_ON.Entity.Scene> GetSceneList()
|
{
|
return HDL_ON.Entity.FunctionList.List.scenes;
|
}
|
|
/// <summary>
|
/// 获取安防列表
|
/// </summary>
|
/// <returns></returns>
|
public List<HDL_ON.Entity.SecurityAlarm> GetSecurityList()
|
{
|
return FunctionList.List.securities;
|
}
|
/// <summary>
|
/// 获取房间的设备列表
|
/// </summary>
|
/// <param name="room">当前房间</param>
|
/// <returns></returns>
|
public List<HDL_ON.Entity.Function> GetRoomDevice(HDL_ON.Entity.Room room)
|
{
|
List<HDL_ON.Entity.Function> deviceLists = new List<Entity.Function>();
|
List<HDL_ON.Entity.Function> lists = GetGatewayDeviceList();
|
if (room.roomId == "6688")
|
{
|
//默认一个房间名:6688
|
//显示网关全部设备
|
deviceLists = lists;
|
}
|
else
|
{
|
for (int i = 0; i < lists.Count; i++)
|
{
|
var dev = lists[i];
|
if (dev.roomIds.Find((id) => id == room.roomId) != null)
|
{
|
//添加属于这个房间的设备;
|
deviceLists.Add(dev);
|
}
|
|
}
|
}
|
return deviceLists;
|
}
|
/// <summary>
|
/// 获取设备(功能)对象
|
/// </summary>
|
/// <param name="sid">设备唯一标识</param>
|
/// <returns></returns>
|
public HDL_ON.Entity.Function GetDevice(string sid)
|
{
|
HDL_ON.Entity.Function device = new Entity.Function() { name = "Unknown" };
|
List<HDL_ON.Entity.Function> deviceLists = GetGatewayDeviceList();
|
for (int i = 0; i < deviceLists.Count; i++)
|
{
|
var dev = deviceLists[i];
|
if (dev.sid == sid)
|
{
|
device = dev;
|
break;
|
}
|
}
|
return device;
|
}
|
|
/// <summary>
|
/// 获取场景对象
|
/// </summary>
|
/// <param name="sid">场景唯一标识</param>
|
/// <returns></returns>
|
public HDL_ON.Entity.Scene GetSecne(string sid)
|
{
|
HDL_ON.Entity.Scene scene = new Entity.Scene() { name = "Unknown" };
|
List<HDL_ON.Entity.Scene> sceneLists = GetSceneList();
|
for (int i = 0; i < sceneLists.Count; i++)
|
{
|
var sce = sceneLists[i];
|
if (sce.sid == sid)
|
{
|
scene = sce;
|
break;
|
}
|
}
|
return scene;
|
}
|
/// <summary>
|
/// 获取安防对象
|
/// </summary>
|
/// <param name="sid">安防唯一标识</param>
|
/// <returns></returns>
|
public HDL_ON.Entity.SecurityAlarm GetSecurity(string sid)
|
{
|
HDL_ON.Entity.SecurityAlarm security = new Entity.SecurityAlarm() { name = "Unknown" };
|
List<HDL_ON.Entity.SecurityAlarm> SecurityLists = GetSecurityList();
|
for (int i = 0; i < SecurityLists.Count; i++)
|
{
|
var sce = SecurityLists[i];
|
if (sce.sid == sid)
|
{
|
security = sce;
|
break;
|
}
|
}
|
return security;
|
}
|
/// <summary>
|
/// 获取房间名(即是=区域名称)
|
/// </summary>
|
/// <param name="device">设备</param>
|
/// <returns></returns>
|
public string GetGetRoomName(HDL_ON.Entity.Function device)
|
{
|
string roomName = "";
|
List<HDL_ON.Entity.Room> roomLists = GetGatewayRoomList();
|
for (int i = 0; i < device.roomIds.Count; i++)
|
{
|
var dev = device.roomIds[i];
|
var room = roomLists.Find((c) => c.roomId == dev);
|
if (room != null)
|
{
|
roomName += room.floorName + "." + room.roomName + ",";
|
}
|
}
|
|
return roomName.TrimEnd(',');
|
}
|
#region 动一改四
|
/// <summary>
|
/// 获取设备类型图标
|
/// </summary>
|
/// <param name="functionType">设备类型</param>
|
/// <returns></returns>
|
public string GetIconPath(string functionType)
|
{
|
string strPath = "";
|
switch (functionType)
|
{
|
|
case SPK.AirSwitch:
|
{
|
strPath = "FunctionIcon/Icon/electricalbreaker.png";
|
}
|
break;
|
case SPK.PanelSocket:
|
case SPK.ElectricSocket:
|
{
|
strPath = "FunctionIcon/Icon/electricalsocket.png";
|
}
|
break;
|
case SPK.LightSwitch:
|
case SPK.LightRGB:
|
case SPK.LightRGBW:
|
case SPK.LightCCT:
|
case SPK.LightDimming:
|
{
|
strPath = "LogicIcon/lightloguc.png";
|
}
|
break;
|
case SPK.CurtainSwitch:
|
case SPK.CurtainRoller:
|
case SPK.CurtainTrietex:
|
{
|
strPath = "LogicIcon/curtainlogic.png";
|
}
|
break;
|
case SPK.AcStandard:
|
case SPK.HvacAC:
|
{
|
strPath = "LogicIcon/airconditionerlogic.png";
|
}
|
break;
|
case SPK.FloorHeatStandard:
|
case SPK.HvacFloorHeat:
|
{
|
strPath = "LogicIcon/heatlogic.png";
|
}
|
break;
|
case SPK.AirFreshStandard:
|
case SPK.HvacAirFresh:
|
{
|
strPath = "LogicIcon/heatlogic.png";
|
}
|
break;
|
case SPK.SensorSmoke:
|
case SPK.SensorWater:
|
case SPK.SensorGas:
|
case SPK.SensorDryContact:
|
case SPK.SensorDryContact2:
|
case SPK.SensorShanLan:
|
case SPK.SensorDuiShe:
|
case SPK.SensorPir:
|
case SPK.SensorDoorWindow:
|
case SPK.SensorUtrasonic:
|
case SPK.SenesorMegahealth:
|
case SPK.SenesorMegahealth2:
|
case SPK.SensorEnvironment:
|
case SPK.SensorEnvironment2:
|
case SPK.SensorEnvironment3:
|
case SPK.SensorTemperature:
|
case SPK.SensorHumidity:
|
case SPK.SensorCO2:
|
case SPK.SensorPm25:
|
case SPK.SensorTVOC:
|
case SPK.SensorHcho:
|
{
|
strPath = "LogicIcon/sensor.png";
|
}
|
break;
|
|
}
|
return strPath;
|
}
|
/// <summary>
|
/// 设备类型的列表(灯光类,窗帘类。。。)
|
/// </summary>
|
/// <param name="deviceList">设备列表</param>
|
/// <returns></returns>
|
public List<string> GetDeviceTypeList(List<HDL_ON.Entity.Function> deviceList)
|
{
|
List<string> deviceStrTypeList = new List<string>();
|
deviceStrTypeList.Clear();
|
///灯光类
|
var lightjosn = deviceList.Find((device) =>
|
device.spk == SPK.LightSwitch
|
|| device.spk == SPK.LightDimming
|
|| device.spk == SPK.LightCCT
|
|| device.spk == SPK.LightRGB
|
|| device.spk == SPK.LightRGBW
|
);
|
if (lightjosn != null)
|
{
|
deviceStrTypeList.Add(Language.StringByID(StringId.Lights));
|
}
|
|
///窗帘类
|
var curtainjosn = deviceList.Find((device) =>
|
device.spk == SPK.CurtainSwitch
|
|| device.spk == SPK.CurtainTrietex
|
|| device.spk == SPK.CurtainRoller);
|
if (curtainjosn != null)
|
{
|
deviceStrTypeList.Add(Language.StringByID(StringId.Curtain));
|
}
|
///空调类
|
var ac = deviceList.Find((device) => device.spk == SPK.AcStandard || device.spk == SPK.HvacAC);
|
if (ac != null)
|
{
|
deviceStrTypeList.Add(Language.StringByID(StringId.AC));
|
}
|
///地暖类
|
var floorHeating = deviceList.Find((device) => device.spk == SPK.FloorHeatStandard || device.spk == SPK.HvacFloorHeat);
|
if (floorHeating != null)
|
{
|
deviceStrTypeList.Add(Language.StringByID(StringId.FloorHeating));
|
}
|
///新风类
|
var airFresh = deviceList.Find((device) => device.spk == SPK.AirFreshStandard || device.spk == SPK.HvacAirFresh);
|
if (airFresh != null)
|
{
|
deviceStrTypeList.Add(Language.StringByID(StringId.AirFresh));
|
}
|
///传感器类
|
var sensor = deviceList.Find((device) =>
|
device.spk == SPK.SensorWater
|
|| device.spk == SPK.SensorGas
|
|| device.spk == SPK.SensorSmoke
|
|| device.spk == SPK.SensorDryContact || device.spk == SPK.SensorDryContact2
|
|| device.spk == SPK.SensorShanLan
|
|| device.spk == SPK.SensorDuiShe
|
|| device.spk == SPK.SensorPir
|
|| device.spk == SPK.SensorDoorWindow
|
|| device.spk == SPK.SensorUtrasonic
|
|| device.spk == SPK.SenesorMegahealth
|
|| device.spk == SPK.SenesorMegahealth2
|
|| device.spk == SPK.SensorEnvironment
|
|| device.spk == SPK.SensorEnvironment2
|
|| device.spk == SPK.SensorEnvironment3
|
|| device.spk == SPK.SensorTemperature
|
|| device.spk == SPK.SensorHumidity
|
|| device.spk == SPK.SensorCO2
|
|| device.spk == SPK.SensorPm25
|
|| device.spk == SPK.SensorTVOC
|
|| device.spk == SPK.SensorHcho
|
);
|
if (sensor != null)
|
{
|
deviceStrTypeList.Add(Language.StringByID(StringId.Sensor));
|
}
|
///家电类
|
var electric = deviceList.Find((device) =>
|
device.spk == SPK.AirSwitch
|
|| device.spk == SPK.PanelSocket
|
|| device.spk == SPK.ElectricSocket
|
);
|
if (electric != null)
|
{
|
deviceStrTypeList.Add(Language.StringByID(StringId.Electric));
|
}
|
return deviceStrTypeList;
|
|
}
|
/// <summary>
|
/// 设备类型FunctionType列表
|
/// </summary>
|
/// <param name="deviceType">设备类型(灯光类,窗帘类。)</param>
|
/// <returns></returns>
|
public List<string> GetDeviceTypeFunctionList(string deviceType)
|
{
|
List<string> functionTypeList = new List<string>();
|
///灯光类
|
if (deviceType == Language.StringByID(StringId.Lights))
|
{
|
functionTypeList.Add(SPK.LightSwitch);
|
functionTypeList.Add(SPK.LightDimming);
|
functionTypeList.Add(SPK.LightRGB);
|
functionTypeList.Add(SPK.LightRGBW);
|
functionTypeList.Add(SPK.LightCCT);
|
functionTypeList.Add(SPK.AirSwitch);
|
functionTypeList.Add(SPK.PanelSocket);
|
functionTypeList.Add(SPK.ElectricSocket);
|
}
|
///窗帘类
|
else if (deviceType == Language.StringByID(StringId.Curtain))
|
{
|
functionTypeList.Add(SPK.CurtainSwitch);
|
functionTypeList.Add(SPK.CurtainRoller);
|
functionTypeList.Add(SPK.CurtainTrietex);
|
}
|
///空调类
|
else if (deviceType == Language.StringByID(StringId.AC))
|
{
|
functionTypeList.Add(SPK.AcStandard);
|
functionTypeList.Add(SPK.HvacAC);
|
}
|
///地暖类
|
else if (deviceType == Language.StringByID(StringId.FloorHeating))
|
{
|
functionTypeList.Add(SPK.FloorHeatStandard); functionTypeList.Add(SPK.HvacFloorHeat);
|
}
|
///新风类
|
else if (deviceType == Language.StringByID(StringId.AirFresh))
|
{
|
functionTypeList.Add(SPK.AirFreshStandard); functionTypeList.Add(SPK.HvacAirFresh);
|
}
|
///传感器类
|
else if (deviceType == Language.StringByID(StringId.Sensor))
|
{
|
functionTypeList.Add(SPK.SensorSmoke);
|
functionTypeList.Add(SPK.SensorWater);
|
functionTypeList.Add(SPK.SensorGas);
|
functionTypeList.Add(SPK.SensorDryContact); functionTypeList.Add(SPK.SensorDryContact2);
|
functionTypeList.Add(SPK.SensorShanLan);
|
functionTypeList.Add(SPK.SensorDuiShe);
|
functionTypeList.Add(SPK.SensorPir);
|
functionTypeList.Add(SPK.SensorDoorWindow);
|
functionTypeList.Add(SPK.SensorUtrasonic);
|
functionTypeList.Add(SPK.SenesorMegahealth);
|
functionTypeList.Add(SPK.SenesorMegahealth2);
|
functionTypeList.Add(SPK.SensorEnvironment);
|
functionTypeList.Add(SPK.SensorEnvironment2);
|
functionTypeList.Add(SPK.SensorEnvironment3);
|
functionTypeList.Add(SPK.SensorTemperature);
|
functionTypeList.Add(SPK.SensorHumidity);
|
functionTypeList.Add(SPK.SensorCO2);
|
functionTypeList.Add(SPK.SensorPm25);
|
functionTypeList.Add(SPK.SensorTVOC);
|
functionTypeList.Add(SPK.SensorHcho);
|
|
|
}
|
///家电类
|
else if (deviceType == Language.StringByID(StringId.Electric))
|
{
|
functionTypeList.Add(SPK.AirSwitch);
|
functionTypeList.Add(SPK.PanelSocket);
|
functionTypeList.Add(SPK.ElectricSocket);
|
}
|
|
|
return functionTypeList;
|
|
}
|
/// <summary>
|
/// 条件/目标支持设备
|
/// </summary>
|
/// <returns></returns>
|
public List<string> GetSupportEquipment(string if_type)
|
{
|
List<string> deviceTypeList = new List<string>();
|
switch (if_type)
|
{
|
case condition_if:
|
{
|
deviceTypeList.Add(SPK.LightSwitch);
|
deviceTypeList.Add(SPK.LightRGB);
|
deviceTypeList.Add(SPK.LightRGBW);
|
deviceTypeList.Add(SPK.LightDimming);
|
deviceTypeList.Add(SPK.LightCCT);
|
deviceTypeList.Add(SPK.CurtainSwitch);
|
deviceTypeList.Add(SPK.CurtainRoller);
|
deviceTypeList.Add(SPK.CurtainTrietex);
|
deviceTypeList.Add(SPK.AcStandard); deviceTypeList.Add(SPK.HvacAC);
|
deviceTypeList.Add(SPK.AirFreshStandard); deviceTypeList.Add(SPK.HvacAirFresh);
|
deviceTypeList.Add(SPK.FloorHeatStandard); deviceTypeList.Add(SPK.HvacFloorHeat);
|
deviceTypeList.Add(SPK.SensorSmoke);
|
deviceTypeList.Add(SPK.SensorWater);
|
deviceTypeList.Add(SPK.SensorGas);
|
deviceTypeList.Add(SPK.SensorDryContact); deviceTypeList.Add(SPK.SensorDryContact2);
|
deviceTypeList.Add(SPK.SensorShanLan);
|
deviceTypeList.Add(SPK.SensorDuiShe);
|
deviceTypeList.Add(SPK.SensorPir);
|
deviceTypeList.Add(SPK.SensorDoorWindow);
|
deviceTypeList.Add(SPK.SensorUtrasonic);
|
deviceTypeList.Add(SPK.SenesorMegahealth);
|
deviceTypeList.Add(SPK.SenesorMegahealth2);
|
deviceTypeList.Add(SPK.SensorEnvironment);
|
deviceTypeList.Add(SPK.SensorEnvironment2);
|
deviceTypeList.Add(SPK.SensorEnvironment3);
|
deviceTypeList.Add(SPK.SensorTemperature);
|
deviceTypeList.Add(SPK.SensorHumidity);
|
deviceTypeList.Add(SPK.SensorCO2);
|
deviceTypeList.Add(SPK.SensorPm25);
|
deviceTypeList.Add(SPK.SensorTVOC);
|
deviceTypeList.Add(SPK.SensorHcho);
|
deviceTypeList.Add(SPK.AirSwitch);
|
deviceTypeList.Add(SPK.PanelSocket);
|
deviceTypeList.Add(SPK.ElectricSocket);
|
|
}
|
break;
|
case target_if:
|
{
|
deviceTypeList.Add(SPK.LightSwitch);
|
deviceTypeList.Add(SPK.LightRGB);
|
deviceTypeList.Add(SPK.LightRGBW);
|
deviceTypeList.Add(SPK.LightDimming);
|
deviceTypeList.Add(SPK.LightCCT);
|
deviceTypeList.Add(SPK.CurtainSwitch);
|
deviceTypeList.Add(SPK.CurtainRoller);
|
deviceTypeList.Add(SPK.CurtainTrietex);
|
deviceTypeList.Add(SPK.AcStandard); deviceTypeList.Add(SPK.HvacAC);
|
deviceTypeList.Add(SPK.FloorHeatStandard); deviceTypeList.Add(SPK.HvacFloorHeat);
|
deviceTypeList.Add(SPK.AirFreshStandard); deviceTypeList.Add(SPK.HvacAirFresh);
|
deviceTypeList.Add(SPK.AirSwitch);
|
deviceTypeList.Add(SPK.PanelSocket);
|
deviceTypeList.Add(SPK.ElectricSocket);
|
}
|
break;
|
}
|
return deviceTypeList;
|
}
|
#endregion
|
/// <summary>
|
/// 显示的设备列表
|
/// </summary>
|
/// <param name="functionType">源数据列表1</param>
|
/// <param name="deviceList">源数据列表2</param>
|
/// <returns></returns>
|
public List<Entity.Function> GetShowDeviceList(List<string> functionType, List<HDL_ON.Entity.Function> deviceList)
|
{
|
List<HDL_ON.Entity.Function> devList = new List<Entity.Function>();
|
for (int i = 0; i < deviceList.Count; i++)
|
{
|
var dev = deviceList[i];
|
//过滤掉不需要显示的设备
|
if (functionType.Contains(dev.spk))
|
{
|
devList.Add(dev);
|
}
|
|
}
|
|
return devList;
|
}
|
/// <summary>
|
/// 返回最终支持显示出来的设备列表
|
/// </summary>
|
/// <param name="room">当前房间</param>
|
/// <param name="str">判断符(表示=输入设备和输出设备)</param>
|
/// <returns></returns>
|
public List<Entity.Function> GetFunctionDeviceList(Entity.Room room, string str)
|
{
|
List<string> functionTypeList = GetSupportEquipment(str);
|
//返回房间设备列表
|
var roomDeviceList = GetRoomDevice(room);
|
//返回最终支持显示出来的设备列表
|
var list = GetShowDeviceList(functionTypeList, roomDeviceList);
|
return list;
|
}
|
/// <summary>
|
/// 网关ID(获取嘉乐网关ID)
|
/// </summary>
|
public string GatewayId
|
{
|
get
|
{
|
if (Entity.DB_ResidenceData.Instance.HomeGateway == null)
|
{
|
return DriverLayer.Control.Ins.GatewayId;
|
}
|
return Entity.DB_ResidenceData.Instance.HomeGateway.gatewayId;
|
}
|
}
|
/// <summary>
|
/// 住宅ID
|
/// </summary>
|
public string HomeId
|
{
|
get
|
{
|
return Entity.DB_ResidenceData.Instance.CurrentRegion.id;
|
}
|
}
|
/// <summary>
|
/// 是否为其他主用户分享过来的住宅
|
/// </summary>
|
public bool IsOthreShare
|
{
|
get
|
{
|
return Entity.DB_ResidenceData.Instance.CurrentRegion.isOtherShare;
|
}
|
}
|
|
#region 高德坐标转WGS84坐标
|
/// <summary>
|
/// 高德坐标转WGS84坐标
|
/// </summary>
|
/// <param name="in_lng"></param>
|
/// <param name="in_lat"></param>
|
/// <param name="out_lng"></param>
|
/// <param name="out_lat"></param>
|
public void GCJ02_to_WGS84(double in_lng, double in_lat, out double out_lng, out double out_lat)
|
{
|
if (OutOfChina(in_lat, in_lng))
|
{
|
out_lng = in_lng;
|
out_lat = in_lat;
|
return;
|
}
|
|
CalculateDev(in_lng, in_lat, out out_lng, out out_lat);
|
out_lng = in_lng - out_lng;
|
out_lat = in_lat - out_lat;
|
}
|
#endregion
|
|
#region WGS84坐标转高德坐标
|
/// <summary>
|
/// WGS84坐标转高德坐标
|
/// </summary>
|
/// <param name="in_lng">经度</param>
|
/// <param name="in_lat">纬度</param>
|
/// <param name="out_lng"></param>
|
/// <param name="out_lat"></param>
|
public void WGS84_to_GCJ02(double in_lng, double in_lat, out double out_lng, out double out_lat)
|
{
|
if (OutOfChina(in_lat, in_lng))
|
{
|
out_lng = in_lng;
|
out_lat = in_lat;
|
return;
|
}
|
|
CalculateDev(in_lng, in_lat, out out_lng, out out_lat);
|
out_lng = in_lng + out_lng;
|
out_lat = in_lat + out_lat;
|
}
|
#endregion
|
|
/// <summary>
|
/// 坐标是否在中国境内
|
/// </summary>
|
/// <param name="lat"></param>
|
/// <param name="lng"></param>
|
/// <returns></returns>
|
public bool OutOfChina(double lat, double lng)
|
{
|
if (lng < 72.004 || lng > 137.8347)
|
return true;
|
if (lat < 0.8293 || lat > 55.8271)
|
return true;
|
return false;
|
}
|
/// <summary>
|
/// 计算偏差
|
/// </summary>
|
/// <param name="in_lng"></param>
|
/// <param name="in_lat"></param>
|
/// <param name="dLng"></param>
|
/// <param name="dLat"></param>
|
private void CalculateDev(double in_lng, double in_lat, out double dLng, out double dLat)
|
{
|
dLat = TransformLat(in_lng - 105.0, in_lat - 35.0);
|
dLng = TransformLng(in_lng - 105.0, in_lat - 35.0);
|
|
double radLat = in_lat / 180.0 * pi;
|
double magic = Math.Sin(radLat);
|
magic = 1 - ee * magic * magic;
|
double sqrtMagic = Math.Sqrt(magic);
|
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);
|
dLng = (dLng * 180.0) / (a / sqrtMagic * Math.Cos(radLat) * pi);
|
}
|
|
private double TransformLat(double x, double y)
|
{
|
double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.Sqrt(Math.Abs(x));
|
ret += (20.0 * Math.Sin(6.0 * x * pi) + 20.0 * Math.Sin(2.0 * x * pi)) * 2.0 / 3.0;
|
ret += (20.0 * Math.Sin(y * pi) + 40.0 * Math.Sin(y / 3.0 * pi)) * 2.0 / 3.0;
|
ret += (160.0 * Math.Sin(y / 12.0 * pi) + 320 * Math.Sin(y * pi / 30.0)) * 2.0 / 3.0;
|
return ret;
|
}
|
private double TransformLng(double x, double y)
|
{
|
double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.Sqrt(Math.Abs(x));
|
ret += (20.0 * Math.Sin(6.0 * x * pi) + 20.0 * Math.Sin(2.0 * x * pi)) * 2.0 / 3.0;
|
ret += (20.0 * Math.Sin(x * pi) + 40.0 * Math.Sin(x / 3.0 * pi)) * 2.0 / 3.0;
|
ret += (150.0 * Math.Sin(x / 12.0 * pi) + 300.0 * Math.Sin(x / 30.0 * pi)) * 2.0 / 3.0;
|
return ret;
|
}
|
// 椭球参数-圆周率
|
private const double pi = 3.14159265358979324;
|
|
// (北京54)椭球长半轴,卫星椭球坐标投影到平面地图坐标系的投影因子
|
private const double a = 6378245.0;
|
/*
|
* Krasovsky 1940 (北京54)椭球长半轴第一偏心率平方
|
* 计算方式:
|
* 长半轴:
|
* a = 6378245.0
|
* 扁率:
|
* 1/f = 298.3(变量相关计算为:(a-b)/a)
|
* 短半轴:
|
* b = 6356863.0188 (变量相关计算方法为:b = a * (1 - f))
|
* 第一偏心率平方:
|
* e2 = (a^2 - b^2) / a^2;
|
*/
|
private const double ee = 0.00669342162296594323;
|
|
/// <summary>
|
/// APP上报GPS经纬度
|
/// </summary>
|
/// <param name="lon">APP GPS经度</param>
|
/// <param name="lat">APP GPS纬度</param>
|
public void AppLatAndLonEvent(double lon, double lat)
|
{
|
Console.WriteLine($"GPS经度===={lon} \nGPS纬度===={lat}");
|
//Application.LocationAction += (lon, lat) =>
|
//{
|
// Console.WriteLine($"GPS经度===={lon}");
|
// Console.WriteLine($"GPS纬度===={lat}");
|
// ////GPS坐标转成高德坐标
|
// //double out_lng, out_lat;
|
// //this.WGS84_to_GCJ02(lon, lat, out out_lng, out out_lat);
|
// //上报经纬度
|
// this.AutomatedGeofenceStatusReporting(lon, lat);
|
//};
|
//上报经纬度<gps 上报条件大于30秒且移动距离大于100米,上报经纬度>
|
this.AutomatedGeofenceStatusReporting(lon, lat);
|
}
|
|
/// <summary>
|
/// 自动化地理围栏状态上报云端
|
/// </summary>
|
/// <param name="out_lng">APP GPS经度</param>
|
/// <param name="out_lat">APP GPS纬度</param>
|
private void AutomatedGeofenceStatusReporting(double out_lng, double out_lat)
|
{
|
if (IsOthreShare)
|
{
|
//不是主账号直接返回
|
return;
|
}
|
List<LogicData> logicDataList = new List<LogicData>();
|
logicDataList.Clear();
|
System.Threading.Tasks.Task.Run(() =>
|
{
|
try
|
{
|
//获取逻辑ID列表,目前针对所有<备注:如果只针对当前手机的话,可以直接拿缓存数据自动化列表遍历>
|
var idStr = Send.GetLogicIdList();
|
if (idStr.Code == "0" && idStr.Data != null && idStr.Data.ToString() != "")
|
{
|
var date = Newtonsoft.Json.JsonConvert.SerializeObject(idStr.Data);
|
logicDataList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<LogicData>>(date);
|
}
|
///有自动列表才处理
|
if (logicDataList.Count > 0)
|
{
|
///遍历所有列表
|
for (int i = 0; i < logicDataList.Count; i++)
|
{
|
var logicDate = logicDataList[i];
|
///自动化没有配置地理围栏不处理
|
if (string.IsNullOrEmpty(logicDate.geo_fence.latitude) || string.IsNullOrEmpty(logicDate.geo_fence.longitude))
|
{
|
//经纬度为空,认为自动化没有配置地理围栏,不处理;
|
continue;
|
}
|
//自动化配置输入条件纬度
|
double lat = Convert.ToDouble(logicDate.geo_fence.latitude);
|
//自动化配置输入条件经度
|
double lon = Convert.ToDouble(logicDate.geo_fence.longitude);
|
//自动化配置输入条件<地理围栏半径><单位,公里、千米.米>
|
int radius = int.Parse(logicDate.geo_fence.radius);
|
//计算2个经纬度之间的距离
|
int r = Infrastructure.Service.Helper.CalculatedDistance.Distance(out_lat, out_lng, lat, lon);
|
//定义一个局部变量
|
string direction = string.Empty;
|
//两点距离小于配置距离<既自动化配置输入条件地理围栏半径>,说明进入区域
|
if (r < radius)
|
{
|
//到达某地
|
direction = "arrive";
|
}
|
else
|
{
|
//离开
|
direction = "leave";
|
}
|
///遍历缓存列表<不为空说明数据已经推送过,不再推送>
|
var isPush = pushList.Find((o) => o.homeId == HomeId && o.userId == UserInfo.Current.ID && o.userLogicId == logicDate.userLogicId && o.arriveOnLeave == direction);
|
if (isPush == null)
|
{
|
//推送给云端是否成功
|
bool push = Send.GeoFenceStateReport(logicDate.userLogicId, logicDate.sid, direction);
|
if (push)
|
{
|
///添加到推送列表
|
pushList.Add(new Push
|
{
|
homeId = HomeId,
|
userId = UserInfo.Current.ID,
|
userLogicId = logicDate.userLogicId,
|
sid = logicDate.sid,
|
arriveOnLeave = direction,
|
});
|
}
|
}
|
}
|
|
}
|
}
|
catch { }
|
});
|
}
|
/// <summary>
|
/// 推送列表<这里数据已经推送过>
|
/// </summary>
|
private static List<Push> pushList = new List<Push>();
|
|
}
|
public class Push
|
{
|
/// <summary>
|
/// 云端唯一id
|
/// </summary>
|
public string userLogicId = "";
|
/// <summary>
|
/// 网关id
|
/// </summary>
|
public string gatewayId = "";
|
/// <summary>
|
/// 逻辑唯一标识
|
/// </summary>
|
public string sid = "";
|
/// <summary>
|
/// 住宅id
|
/// </summary>
|
public string homeId = "";
|
/// <summary>
|
/// 到达某地 离开
|
/// </summary>
|
public string arriveOnLeave = "";
|
/// <summary>
|
/// 用户id
|
/// </summary>
|
public string userId = "";
|
|
}
|
}
|