using System;
|
using System.Collections.Generic;
|
using Shared;
|
|
namespace HDL_ON.UI.UI2.Intelligence.Automation
|
{
|
|
public class LogicMethod
|
{
|
/// <summary>
|
/// 表示是条件
|
/// </summary>
|
public const string condition_if = "条件";
|
/// <summary>
|
/// 表示是目标
|
/// </summary>
|
public const string target_if = "目标";
|
/// <summary>
|
/// 移除所有"Logic"界面
|
/// </summary>
|
public static void RemoveAllView()
|
{
|
MainPage.BasePageView.RemoveViewByTag("Logic");
|
}
|
/// <summary>
|
/// 生成逻辑sid方法
|
/// </summary>
|
public static 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 = "00000000";
|
|
byte[] arry = new byte[4];
|
arry[0] = (byte)(m & 0xFF);
|
arry[1] = (byte)((m & 0xFF00) >> 8);
|
arry[2] = (byte)((m & 0xFF0000) >> 16);
|
arry[3] = (byte)((m >> 24) & 0xFF);
|
sTimeSpan = arry[0].ToString("X2") + arry[1].ToString("X2") + arry[2].ToString("X2") + arry[3].ToString("X2");
|
|
|
if (sTimeSpan.Length > 8)
|
{
|
sTimeSpan = sTimeSpan.Substring(0, 8);
|
}
|
else
|
{
|
sTimeSpan = "00000000";
|
}
|
|
logicId = sOidBeginsWith + sTimeSpan;
|
|
logicId += "0A";
|
logicId += "0A01";
|
//0A01 物模型为逻辑, 0001 表示 1 号逻辑功能
|
int iTopLogicId = 1;
|
|
Random random = new Random();
|
iTopLogicId = random.Next(0, 255);
|
iTopLogicId += random.Next(0, 255);
|
|
logicId += iTopLogicId.ToString("X4");//逻辑号 两个byte
|
logicId += "1100";
|
}
|
catch
|
{
|
return logicId;
|
}
|
return logicId;
|
}
|
|
/// <summary>
|
/// 生成逻辑sid方法
|
/// </summary>
|
//public static string NewSid()
|
//{
|
// String sLogicid = "";
|
// try
|
// {
|
// String sOidBeginsWith = "000101";//厂商 + 通讯方式
|
// //生成4个byte时间戳
|
// DateTime dt = DateTime.Now;
|
// long sTimeSp = GateWay.ConvertDateTimeLong(dt);
|
// string sTimeSpan = "";
|
// GateWay.ConvertIntToByteArray(sTimeSp, ref sTimeSpan);
|
// if (sTimeSpan.Length != 8) return sLogicid;
|
// //间隔10毫秒 错开时间戳
|
// HDLUDP.TimeBetwnNext(10);
|
// sLogicid = sOidBeginsWith + sTimeSpan;
|
// //1501 物模型为自动化, 0001 表示 1 号自动化功能
|
// sLogicid += "15";
|
// sLogicid += "1501";
|
// //自动化号自增
|
// int iTopSceneId = 1;
|
// if (myGateway.LogicResponse != null)
|
// {
|
// if (myGateway.LogicResponse.objects != null)
|
// {
|
// for (int i = 0; i < myGateway.LogicResponse.objects.Count; i++)
|
// {
|
// string ccc = myGateway.LogicResponse.objects[i].sid.Substring(myGateway.LogicResponse.objects[i].sid.Length - 8, 4);
|
// int iThisSceneId = Convert.ToInt16(myGateway.LogicResponse.objects[i].sid.Substring(myGateway.LogicResponse.objects[i].sid.Length - 8, 4), 16);
|
// if (iThisSceneId >= iTopSceneId)
|
// iTopSceneId = iThisSceneId + 1;
|
// }
|
// }
|
// }
|
// sLogicid += iTopSceneId.ToString("X4");//场景号 两个byte
|
// //大类小类没有用到 固定为0
|
// sLogicid += "0000";
|
// return sLogicid;
|
// }
|
// catch
|
// {
|
// return sLogicid;
|
// }
|
//}
|
|
/// <summary>
|
/// 封装Dictionary对象
|
/// </summary>
|
/// <param name="dic">Dictionary类</param>
|
/// <param name="key">健</param>
|
/// <param name="value">值</param>
|
public static 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 static List<HDL_ON.Entity.Room> GetGatewayRoomList()
|
{
|
return HDL_ON.Entity.DB_ResidenceData.residenceData.Rooms;
|
}
|
/// <summary>
|
/// 获取网关房间列表
|
/// </summary>
|
/// <returns></returns>
|
public static 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;//默认一个房间名为:全部区域
|
room1.uid = "全部区域";//默认sid用识别该房间
|
roomList.Add(room1);//默认添加到房间列表里
|
var roomLists = GetGatewayRoomList();
|
foreach (var room in roomLists)
|
{
|
roomList.Add(room);
|
}
|
|
return roomList;
|
}
|
/// <summary>
|
/// 获取网关设备列表
|
/// </summary>
|
/// <returns></returns>
|
public static List<HDL_ON.Entity.Function> GetGatewayDeviceList()
|
{
|
List<HDL_ON.Entity.Function> list = new List<Entity.Function>();
|
for (int i=0;i<10;i++) {
|
HDL_ON.Entity.Function function = new Entity.Function();
|
switch (i) {
|
case 0: {
|
function.sid = "1234560001212121020182";
|
function.name ="灯光";
|
list.Add(function);
|
}
|
break;
|
case 1: {
|
|
function.sid = "1234560001212121030182";
|
function.name = "窗帘";
|
list.Add(function);
|
} break;
|
case 2: {
|
function.sid = "1234560001212121040182";
|
function.name = "空调";
|
list.Add(function);
|
} break;
|
case 3:
|
{
|
function.sid = "1234560001212121010282";
|
function.name = "RGBW";
|
list.Add(function);
|
}
|
break;
|
case 4:
|
{
|
|
function.sid = "1234560001212121010382";
|
function.name = "CCT灯";
|
list.Add(function);
|
}
|
break;
|
case 5:
|
{
|
function.sid = "1234560001212121010482";
|
function.name = "开合帘";
|
list.Add(function);
|
}
|
break;
|
case 6:
|
{
|
function.sid = "1234560001212121010582";
|
function.name = "卷帘";
|
list.Add(function);
|
}
|
break;
|
case 7:
|
{
|
function.sid = "1234560001212121040282";
|
function.name = "地热";
|
list.Add(function);
|
}
|
break;
|
case 8:
|
{
|
function.sid = "1234560001212121020282";
|
function.name = "调关";
|
list.Add(function);
|
}
|
break;
|
case 9:
|
{
|
function.sid = "1234560001212121020482";
|
function.name = "RGB";
|
list.Add(function);
|
}
|
break;
|
}
|
}
|
return list;
|
//return HDL_ON.Entity.DB_ResidenceData.functionList.GetAllFunction();
|
}
|
/// <summary>
|
/// 获取网关场景列表
|
/// </summary>
|
/// <returns></returns>
|
public static List<HDL_ON.Entity.Scene> GetSceneList()
|
{
|
return HDL_ON.Entity.DB_ResidenceData.functionList.scenes;
|
}
|
/// <summary>
|
/// 获取房间的设备列表
|
/// </summary>
|
/// <param name="room">当前房间</param>
|
/// <returns></returns>
|
public static 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();
|
foreach (var dev in lists)
|
{
|
if (dev.roomIds.Find((id) => id == room.uid) != null)
|
{
|
deviceLists.Add(dev);
|
}
|
if (room.uid == "全部区域")
|
{
|
//房间名为全部区域时,显示网关全部设备
|
deviceLists = lists;
|
}
|
|
}
|
return deviceLists;
|
}
|
/// <summary>
|
/// 获取当个设备
|
/// </summary>
|
/// <param name="sid">设备唯一标识</param>
|
/// <returns></returns>
|
public static HDL_ON.Entity.Function GetDevice(string sid)
|
{
|
HDL_ON.Entity.Function device = new Entity.Function() { name= "Unknown",sid="设备不存在"};
|
List<HDL_ON.Entity.Function> deviceLists = GetGatewayDeviceList();
|
foreach (var dev in deviceLists)
|
{
|
if (dev.sid == sid)
|
{
|
device = dev;
|
break;
|
}
|
}
|
return device;
|
}
|
|
/// <summary>
|
/// 获取当个场景
|
/// </summary>
|
/// <param name="sid">场景唯一标识</param>
|
/// <returns></returns>
|
public static HDL_ON.Entity.Scene GetSecne(string sid)
|
{
|
HDL_ON.Entity.Scene scene = new Entity.Scene() { name = "Unknown", sid = "场景不存在" };
|
List<HDL_ON.Entity.Scene> sceneLists = GetSceneList();
|
foreach (var sce in sceneLists)
|
{
|
if (sce.sid == sid)
|
{
|
scene = sce;
|
break;
|
}
|
}
|
return scene;
|
}
|
/// <summary>
|
/// 获取房间名(即是=区域名称)
|
/// </summary>
|
/// <param name="device">设备</param>
|
/// <returns></returns>
|
public static string GetGetRoomName(HDL_ON.Entity.Function device)
|
{
|
string roomName = "";
|
List<HDL_ON.Entity.Room> roomLists = GetGatewayRoomList();
|
|
foreach (var dev in device.roomIds)
|
{
|
var room = roomLists.Find((c) => c.uid == dev);
|
if (room != null)
|
{
|
roomName += room.floorName + "." + room.roomName + ",";
|
}
|
}
|
|
return roomName.TrimEnd(',');
|
}
|
/// <summary>
|
/// 获取设备类型图标
|
/// </summary>
|
/// <param name="functionType">设备类型</param>
|
/// <returns></returns>
|
public static string GetIconPath(FunctionType functionType)
|
{
|
string strPath = "";
|
switch (functionType)
|
{
|
case FunctionType.Relay:
|
case FunctionType.RGB:
|
case FunctionType.RGBW:
|
case FunctionType.CCT:
|
case FunctionType.Dimmer:
|
{
|
strPath = "LogicIcon/lightloguc.png";
|
}
|
break;
|
case FunctionType.Curtain:
|
case FunctionType.RollerCurtain:
|
case FunctionType.TrietexCurtain:
|
{
|
strPath = "LogicIcon/curtainlogic.png";
|
}
|
break;
|
case FunctionType.AC:
|
{
|
strPath = "LogicIcon/airconditionerlogic.png";
|
}
|
break;
|
case FunctionType.FloorHeating:
|
{
|
strPath = "LogicIcon/heatlogic.png";
|
}
|
break;
|
|
}
|
return strPath;
|
}
|
/// <summary>
|
/// 设备类型的列表(灯光类,窗帘类。。。)
|
/// </summary>
|
/// <param name="deviceList">设备列表</param>
|
/// <returns></returns>
|
public static List<string> GetDeviceTypeList(List<HDL_ON.Entity.Function> deviceList)
|
{
|
List<string> deviceStrTypeList = new List<string>();
|
deviceStrTypeList.Clear();
|
var lightjosn = deviceList.Find((device) => device.functionType == FunctionType.Relay || device.functionType == FunctionType.Dimmer|| device.functionType == FunctionType.CCT || device.functionType == FunctionType.RGB|| device.functionType == FunctionType.RGBW);
|
if (lightjosn != null)
|
{
|
deviceStrTypeList.Add(Language.StringByID(StringId.Lights));
|
}
|
|
var curtainjosn = deviceList.Find((device) => device.functionType ==FunctionType.Curtain|| device.functionType == FunctionType.TrietexCurtain|| device.functionType == FunctionType.RollerCurtain);
|
if (curtainjosn != null)
|
{
|
deviceStrTypeList.Add(Language.StringByID(StringId.Curtain));
|
}
|
|
var ac = deviceList.Find((device) => device.functionType == FunctionType.AC);
|
if (ac != null)
|
{
|
deviceStrTypeList.Add(Language.StringByID(StringId.AC));
|
}
|
var floorHeating = deviceList.Find((device) => device.functionType == FunctionType.FloorHeating);
|
if (ac != null)
|
{
|
deviceStrTypeList.Add(Language.StringByID(StringId.FloorHeating));
|
}
|
return deviceStrTypeList;
|
|
}
|
/// <summary>
|
/// 设备类型FunctionType列表
|
/// </summary>
|
/// <param name="deviceType">设备类型(灯光类,窗帘类。)</param>
|
/// <returns></returns>
|
public static List<FunctionType> GetDeviceTypeFunctionList(string deviceType)
|
{
|
List<FunctionType> functionTypeList = new List<FunctionType>();
|
if (deviceType == Language.StringByID(StringId.Lights))
|
{
|
functionTypeList.Add(FunctionType.Relay);
|
functionTypeList.Add(FunctionType.Dimmer);
|
functionTypeList.Add(FunctionType.RGB);
|
functionTypeList.Add(FunctionType.RGBW);
|
functionTypeList.Add(FunctionType.CCT);
|
}
|
else if (deviceType == Language.StringByID(StringId.Curtain))
|
{
|
functionTypeList.Add(FunctionType.Curtain);
|
functionTypeList.Add(FunctionType.RollerCurtain);
|
functionTypeList.Add(FunctionType.TrietexCurtain);
|
}
|
else if (deviceType == Language.StringByID(StringId.AC))
|
{
|
functionTypeList.Add(FunctionType.AC);
|
}
|
else if (deviceType == Language.StringByID(StringId.FloorHeating))
|
{
|
functionTypeList.Add(FunctionType.FloorHeating);
|
}
|
return functionTypeList;
|
|
}
|
/// <summary>
|
/// 条件/目标支持设备
|
/// </summary>
|
/// <returns></returns>
|
public static List<FunctionType> GetSupportEquipment(string if_type)
|
{
|
List<FunctionType> deviceTypeList = new List<FunctionType>();
|
switch (if_type) {
|
case condition_if: {
|
deviceTypeList.Add(FunctionType.Relay);
|
deviceTypeList.Add(FunctionType.RGB);
|
deviceTypeList.Add(FunctionType.RGBW);
|
deviceTypeList.Add(FunctionType.Dimmer);
|
deviceTypeList.Add(FunctionType.CCT);
|
deviceTypeList.Add(FunctionType.Curtain);
|
deviceTypeList.Add(FunctionType.RollerCurtain);
|
deviceTypeList.Add(FunctionType.TrietexCurtain);
|
deviceTypeList.Add(FunctionType.AC);
|
deviceTypeList.Add(FunctionType.FloorHeating);
|
}
|
break;
|
case target_if:
|
{
|
deviceTypeList.Add(FunctionType.Relay);
|
deviceTypeList.Add(FunctionType.RGB);
|
deviceTypeList.Add(FunctionType.RGBW);
|
deviceTypeList.Add(FunctionType.Dimmer);
|
deviceTypeList.Add(FunctionType.CCT);
|
deviceTypeList.Add(FunctionType.Curtain);
|
deviceTypeList.Add(FunctionType.RollerCurtain);
|
deviceTypeList.Add(FunctionType.TrietexCurtain);
|
deviceTypeList.Add(FunctionType.AC);
|
deviceTypeList.Add(FunctionType.FloorHeating);
|
}
|
break;
|
}
|
return deviceTypeList;
|
}
|
/// <summary>
|
/// 显示的设备列表
|
/// </summary>
|
/// <param name="functionType">源数据列表1</param>
|
/// <param name="deviceList">源数据列表2</param>
|
/// <returns></returns>
|
public static List<Entity.Function> GetShowDeviceList(List<FunctionType> functionType, List<HDL_ON.Entity.Function> deviceList)
|
{
|
List<HDL_ON.Entity.Function> devList = new List<Entity.Function>();
|
foreach (var dev in deviceList)
|
{
|
if (functionType.Contains(dev.functionType))
|
{
|
///过滤掉不需要显示的设备
|
devList.Add(dev);
|
}
|
}
|
return devList;
|
}
|
/// <summary>
|
/// 返回最终支持显示出来的设备列表
|
/// </summary>
|
/// <param name="room">当前房间</param>
|
/// <param name="str">判断符(表示=输入设备和输出设备)</param>
|
/// <returns></returns>
|
public static List<Entity.Function> GetFunctionDeviceList(Entity.Room room, string str)
|
{
|
List<FunctionType> functionTypeList = GetSupportEquipment(str);
|
//返回房间设备列表
|
var roomDeviceList = GetRoomDevice(room);
|
//返回最终支持显示出来的设备列表
|
var list = GetShowDeviceList(functionTypeList, roomDeviceList);
|
return list;
|
}
|
}
|
}
|