using System;
|
using System.Collections.Generic;
|
using Newtonsoft.Json.Linq;
|
using Shared;
|
|
namespace SuperGateWay
|
{
|
[System.Serializable]
|
public class Sunrise
|
{
|
public int type = 0;
|
public string time="";
|
}
|
|
[System.Serializable]
|
public class Input
|
{
|
|
public string sid="";
|
public int value;
|
public int continueX;
|
public string compare="=";
|
|
// public Dictionary<string, object> param = new Dictionary<string, object> { };
|
|
//public void Add (string key, object value)
|
//{
|
// if (key == null) {
|
// return;
|
// }
|
// if (param.ContainsKey (key)) {
|
// param [key] = value;
|
// } else {
|
// param.Add (key, value);
|
// }
|
//}
|
|
//public int GetIntValueByKey (string key, int defaultValue)
|
//{
|
// try {
|
// object o;
|
// param.TryGetValue (key, out o);
|
// if (o == null) {
|
// return defaultValue;
|
// } else {
|
// return int.Parse (o.ToString ());
|
// }
|
|
// } catch {
|
// return defaultValue;
|
// }
|
//}
|
[Newtonsoft.Json.JsonIgnore]
|
public SuperGateWayCommon InputBySid
|
{
|
get{
|
try {
|
|
SuperGateWayCommon common = null;
|
if (string.IsNullOrEmpty (sid)) {
|
return null;
|
}
|
//判断SID是否有效的,如果不是有效的当前这个场景数据就不处理
|
Convert.ToUInt64 (sid, 16);
|
|
var sidUlong = Convert.ToUInt64 (sid, 16);
|
var subnetId = (byte)((sidUlong >> 40) & 0xFF);
|
var deviceId = (byte)((sidUlong >> 32) & 0xFF);
|
var targetType = (byte)((sidUlong >> 24) & 0xFF);
|
var property = (byte)((sidUlong >> 16) & 0xFF);
|
var targetNumber = (uint)((sidUlong >> 0) & 0xFFFF);
|
|
switch (targetType) {
|
case 0:
|
break;
|
case 1:
|
break;
|
//空调
|
case 2: {
|
common = new SuperGateWayCommon { Type = DeviceType.HVAC, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
if (property == 0) {
|
common.Add ("Power", value);
|
} else if (property == 1) {
|
common.Add ("Mode", value);
|
} else if (property == 2) {
|
common.Add ("Speed",value);
|
} else if (property == 3) {
|
common.Add ("Temperature",value);
|
} else if (property == 4) {
|
common.Add ("Scavenging", value);
|
} else if (property == 5) {
|
common.Add ("ambienTtemperature", value);
|
}
|
}
|
break;
|
//地热
|
case 3: {
|
common = new SuperGateWayCommon { Type = DeviceType.FoolHeat, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
if (property == 0) {
|
common.Add ("Power", value);
|
} else if (property == 1) {
|
common.Add ("Temperature", value);
|
}
|
}
|
break;
|
//新风
|
case 4: {
|
common = new SuperGateWayCommon { Type = DeviceType.FreshAir, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
|
if (property == 0) {
|
common.Add ("Power",value);
|
} else if (property == 1) {
|
common.Add ("Mode",value);
|
} else if (property == 2) {
|
common.Add ("Speed", value);
|
}
|
}
|
break;
|
//窗帘
|
case 5: {
|
if (property == 0) {
|
common = new SuperGateWayCommon { Type = DeviceType.CurtainModel, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
|
common.Add ("Power", value);
|
|
} else if (property == 1) {
|
common = new SuperGateWayCommon { Type = DeviceType.CurtainRoller, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
|
common.Add ("Brightness",value);
|
|
}
|
}
|
break;
|
//灯光,可能包含调光及开关
|
case 6: {
|
if (property == 0) {
|
common = new SuperGateWayCommon { Type = DeviceType.LightSwitch, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
|
common.Add ("Power", value.ToString() == "0" ? 0 : 1);
|
} else if (property == 1) {
|
common = new SuperGateWayCommon { Type = DeviceType.LightDimming, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
common.Add ("Brightness", value);
|
}
|
}
|
break;
|
//按键
|
case 7: {
|
if (property == 0) {
|
common = new SuperGateWayCommon { Type = DeviceType.MechanicalSwitch, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
common.Add ("Power", value.ToString() == "0" ? 0 : 1);
|
} else if (property == 1) {
|
common = new SuperGateWayCommon { Type = DeviceType.AutomaticSwitch, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
|
common.Add ("Power",value);
|
}
|
}
|
break;
|
case 8: {
|
common = new SuperGateWayCommon { Type = DeviceType.MusicModel, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
|
if (property == 0) {
|
common.Add ("Status", value);
|
} else if (property == 1) {
|
common.Add ("Volume", value);
|
} else if (property == 3) {
|
common.Add ("Source", value);
|
} else if (property == 5) {
|
common.Add ("Mode", value);
|
}
|
}
|
break;
|
//传感器
|
case 9: {
|
common = new SuperGateWayCommon { Type = DeviceType.Sensor, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
|
if (property == 0) {
|
common.Add ("Temperature",value);
|
} else if (property == 1) {
|
common.Add ("Brightness", value);
|
}
|
|
}
|
break;
|
//门锁
|
case 10: {
|
common = new SuperGateWayCommon { Type = DeviceType.DoorLock, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
common.Add ("Power", value.ToString() == "0" ? 0 : 1);
|
}
|
break;
|
case 11: {
|
|
}
|
break;
|
case 12:
|
break;
|
case 13:
|
break;
|
//干接点
|
case 14: {
|
common = new SuperGateWayCommon { Type = DeviceType.DryContact, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
common.Add ("Power", value.ToString() == "0" ? 0 : 1);
|
}
|
break;
|
case 15:
|
break;
|
case 16:
|
break;
|
}
|
return common;
|
} catch {
|
return null;
|
}
|
}
|
}
|
}
|
|
public class Output
|
{
|
public List<Dictionary<string, object>> objects = new List<Dictionary<string, object>> { };
|
|
//public void Add (string key, object value)
|
//{
|
// foreach (var o in objects) {
|
// if (key == null) {
|
// return;
|
// }
|
// if (o.ContainsKey (key)) {
|
// o [key] = value;
|
// } else {
|
// o.Add (key, value);
|
// }
|
// }
|
//}
|
|
//public int GetIntValueByKey (string key, int defaultValue)
|
//{
|
// try {
|
// object o;
|
// o.TryGetValue (key, out o);
|
// if (o == null) {
|
// return defaultValue;
|
// } else {
|
// return int.Parse (o.ToString ());
|
// }
|
|
// } catch {
|
// return defaultValue;
|
// }
|
//}
|
[Newtonsoft.Json.JsonIgnore]
|
public List<SuperGateWayCommon> OutputBySid {
|
get {
|
try {
|
List<SuperGateWayCommon> d = new List<SuperGateWayCommon> ();
|
SuperGateWayCommon common = new SuperGateWayCommon();
|
foreach (var o in objects) {
|
|
var sid = o ["sid"]?.ToString ();
|
if (sid == null) {
|
return null;
|
}
|
|
var value = o ["value"]?.ToString ();
|
if (value == null) {
|
value = "0";
|
}
|
|
var delay = o ["delay"]?.ToString ();
|
if (delay == null) {
|
delay = "0";
|
}
|
|
//if (string.IsNullOrEmpty (sid)) {
|
// return null;
|
//}
|
//判断SID是否有效的,如果不是有效的当前这个场景数据就不处理
|
Convert.ToUInt64 (sid, 16);
|
|
var sidUlong = Convert.ToUInt64 (sid, 16);
|
var subnetId = (byte)((sidUlong >> 40) & 0xFF);
|
var deviceId = (byte)((sidUlong >> 32) & 0xFF);
|
var targetType = (byte)((sidUlong >> 24) & 0xFF);
|
var property = (byte)((sidUlong >> 16) & 0xFF);
|
var targetNumber = (uint)((sidUlong >> 0) & 0xFFFF);
|
|
common.SubnetID = subnetId;
|
common.DeviceID = deviceId;
|
common.LoopID = (byte)targetNumber;
|
common.Add ("delay",delay);
|
switch (targetType) {
|
case 0:
|
break;
|
case 1:
|
break;
|
//空调
|
case 2: {
|
common.Type = DeviceType.HVAC;
|
if (property == 0) {
|
common.Add ("Power", value);
|
} else if (property == 1) {
|
common.Add ("Mode", value);
|
} else if (property == 2) {
|
common.Add ("Speed", value);
|
} else if (property == 3) {
|
common.Add ("Temperature", value);
|
} else if (property == 4) {
|
common.Add ("Scavenging", value);
|
} else if (property == 5) {
|
common.Add ("ambienTtemperature", value);
|
}
|
|
}
|
break;
|
//地热
|
case 3: {
|
common.Type = DeviceType.FoolHeat;
|
if (property == 0) {
|
common.Add ("Power", value);
|
} else if (property == 1) {
|
common.Add ("Temperature", value);
|
}
|
}
|
break;
|
//新风
|
case 4: {
|
common.Type = DeviceType.FreshAir;
|
if (property == 0) {
|
common.Add ("Power", value);
|
} else if (property == 1) {
|
common.Add ("Mode", value);
|
} else if (property == 2) {
|
common.Add ("Speed", value);
|
}
|
}
|
break;
|
//窗帘
|
case 5: {
|
if (property == 0) {
|
common.Type = DeviceType.CurtainModel;
|
common.Add ("Power", value);
|
} else if (property == 1) {
|
common.Type = DeviceType.CurtainRoller;
|
common.Add ("Brightness", value);
|
|
}
|
}
|
break;
|
//灯光,可能包含调光及开关
|
case 6: {
|
if (property == 0) {
|
common.Type = DeviceType.LightSwitch;
|
common.Add ("Power", value.ToString () == "0" ? 0 : 1);
|
} else if (property == 1) {
|
common.Type = DeviceType.LightDimming;
|
common.Add ("Brightness", value);
|
}
|
}
|
break;
|
//按键
|
case 7: {
|
if (property == 0) {
|
common.Type = DeviceType.MechanicalSwitch;
|
common.Add ("Power", value.ToString () == "0" ? 0 : 1);
|
} else if (property == 1) {
|
common.Type = DeviceType.AutomaticSwitch;
|
|
common.Add ("Power", value);
|
}
|
}
|
break;
|
case 8: {
|
common.Type = DeviceType.MusicModel;
|
|
if (property == 0) {
|
common.Add ("Status", value);
|
} else if (property == 1) {
|
common.Add ("Volume", value);
|
} else if (property == 3) {
|
common.Add ("Source", value);
|
} else if (property == 5) {
|
common.Add ("Mode", value);
|
}
|
}
|
break;
|
//传感器
|
case 9: {
|
common.Type = DeviceType.Sensor;
|
|
if (property == 0) {
|
common.Add ("Temperature", value);
|
} else if (property == 1) {
|
common.Add ("Brightness", value);
|
}
|
|
}
|
break;
|
//门锁
|
case 10: {
|
common.Type = DeviceType.DoorLock;
|
common.Add ("Power", value.ToString () == "0" ? 0 : 1);
|
}
|
break;
|
case 11: {
|
|
}
|
break;
|
case 12:
|
break;
|
case 13:
|
break;
|
//干接点
|
case 14: {
|
common.Type = DeviceType.DryContact;
|
common.Add ("Power", value.ToString () == "0" ? 0 : 1);
|
}
|
break;
|
case 15:
|
break;
|
case 16:
|
break;
|
}
|
d.Add (common);
|
}
|
return d;
|
} catch {
|
return null;
|
}
|
}
|
}
|
|
//public Dictionary<string, object> objects = new Dictionary<string, object> { };
|
//public List<Objects> objects = new List<Objects> { };
|
}
|
|
public class Objects
|
{
|
public string sid;
|
public int value;
|
public int delay;
|
}
|
|
public class Logic
|
{
|
|
/// <summary>
|
/// 接收逻辑状态回复数据
|
/// </summary>
|
[Newtonsoft.Json.JsonIgnore]
|
public byte [] ByteState;
|
|
[Newtonsoft.Json.JsonIgnore]
|
public string Tag = "false";
|
/// <summary>
|
/// 当前添加的逻辑模块
|
/// </summary>
|
public static Logic CurrentLogic;
|
public string module = "";
|
public string name = "";
|
public string sid = "";
|
public List<string> time = new List<string> ();
|
//public string sunrise = "none";
|
|
public Dictionary<string, object> param = new Dictionary<string, object> { };
|
public Dictionary<string, object> date = new Dictionary<string, object> { };
|
public Sunrise sunrise = new Sunrise ();
|
//public Dictionary<string, object> sunrise = new Dictionary<string, object> { };
|
public List<Input> input = new List<Input> { };
|
public List<Output> output = new List<Output> { };
|
|
[Newtonsoft.Json.JsonIgnore]
|
public uint uid {
|
get {
|
return (uint)(Convert.ToUInt64 (sid, 16) >> 32);
|
}
|
}
|
|
/// <summary>
|
/// 获取
|
/// </summary>
|
/// <value>The new uid.</value>
|
public static string NewSid {
|
get {
|
uint max = 0;
|
foreach (var logic in GateWay.Instance.Logics) {
|
var number = logic.uid & 0x0000FFFF;
|
if (max < number) {
|
max = number;
|
}
|
}
|
//if (max < 256) {
|
// //默认最小的区号为1 {256(16进制)=0100; 区号为01;逻辑号00;max=区号为01|逻辑号00}
|
// max += 256;
|
//}
|
//比当前最大的加1
|
max += 1;
|
//uid<<32|oid
|
return ((((ulong)(0x30000000 | 0x00010000 | max)) << 32) | 0x00000000).ToString ("X");
|
}
|
}
|
|
#region -----暂时隐藏-----
|
/*
|
///// <summary>
|
///// 逻辑条件对象的列表
|
///// </summary>
|
public List<SuperGateWayCommon> inputdeviceList = new List<SuperGateWayCommon> { };
|
///// <summary>
|
///// 逻辑执行事件对象的列表
|
///// </summary>
|
public List<SuperGateWayCommon> outputdeviceList = new List<SuperGateWayCommon> { };
|
|
/// <summary>
|
///逻辑条件对象的方法
|
/// </summary>
|
public void inputSidToDevice ()
|
{
|
try {
|
if (input == null) {
|
return;
|
}
|
foreach (var o in input) {
|
|
var tempSid = o.sid;
|
if (tempSid== null) {
|
continue;
|
}
|
var value = o.value.ToString ();
|
if (value == null) {
|
value = "0";
|
}
|
//判断SID是否有效的,如果不是有效的当前这个场景数据就不处理
|
Convert.ToUInt64 (tempSid, 16);
|
|
var sidUlong = Convert.ToUInt64 (tempSid, 16);
|
var subnetId = (byte)((sidUlong >> 40) & 0xFF);
|
var deviceId = (byte)((sidUlong >> 32) & 0xFF);
|
var targetType = (byte)((sidUlong >> 24) & 0xFF);
|
var property = (byte)((sidUlong >> 16) & 0xFF);
|
var targetNumber = (uint)((sidUlong >> 0) & 0xFFFF);
|
|
switch (targetType) {
|
case 0:
|
break;
|
case 1:
|
break;
|
//空调
|
case 2: {
|
var common = new SuperGateWayCommon { Type = DeviceType.HVAC, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = inputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
inputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
|
if (property == 0) {
|
common.Add ("Power", byte.Parse (value));
|
} else if (property == 1) {
|
common.Add ("Mode", byte.Parse (value));
|
} else if (property == 2) {
|
common.Add ("Speed", byte.Parse (value));
|
} else if (property == 3) {
|
common.Add ("Temperature", byte.Parse (value));
|
} else if (property == 4) {
|
common.Add ("Scavenging", byte.Parse (value));
|
} else if (property == 5) {
|
common.Add ("ambienTtemperature", byte.Parse (value));
|
}
|
|
}
|
break;
|
//地热
|
case 3: {
|
var common = new SuperGateWayCommon { Type = DeviceType.FoolHeat, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = inputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
inputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
if (property == 0) {
|
common.Add ("Power", byte.Parse (value));
|
} else if (property == 1) {
|
common.Add ("Temperature", byte.Parse (value));
|
}
|
}
|
break;
|
//新风
|
case 4: {
|
var common = new SuperGateWayCommon { Type = DeviceType.FreshAir, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = inputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
inputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
|
if (property == 0) {
|
common.Add ("Power", byte.Parse (value));
|
} else if (property == 1) {
|
common.Add ("Mode", byte.Parse (value));
|
} else if (property == 2) {
|
common.Add ("Speed", byte.Parse (value));
|
}
|
}
|
break;
|
//窗帘
|
case 5: {
|
if (property == 0) {
|
var common = new SuperGateWayCommon { Type = DeviceType.CurtainModel, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = inputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
inputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
common.Add ("Power", byte.Parse (value));
|
|
} else if (property == 1) {
|
var common = new SuperGateWayCommon { Type = DeviceType.CurtainRoller, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = inputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
inputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
common.Add ("Brightness", byte.Parse (value));
|
}
|
}
|
break;
|
//灯光,可能包含调光及开关
|
case 6: {
|
if (property == 0) {
|
var common = new SuperGateWayCommon { Type = DeviceType.LightSwitch, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = inputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
inputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
common.Add ("Power", value == "0" ? 0 : 1);
|
} else if (property == 1) {
|
var common = new SuperGateWayCommon { Type = DeviceType.LightDimming, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = inputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
inputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
common.Add ("Brightness", byte.Parse (value));
|
}
|
}
|
break;
|
//按键
|
case 7: {
|
if (property == 0) {
|
var common = new SuperGateWayCommon { Type = DeviceType.MechanicalSwitch, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = inputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
inputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
common.Add ("Power", value == "0" ? 0 : 1);
|
} else if (property == 1) {
|
var common = new SuperGateWayCommon { Type = DeviceType.AutomaticSwitch, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = inputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
inputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
common.Add ("Power", byte.Parse (value));
|
}
|
}
|
break;
|
case 8: {
|
var common = new SuperGateWayCommon { Type = DeviceType.MusicModel, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = inputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
inputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
if (property == 0) {
|
common.Add ("Status", byte.Parse (value));
|
} else if (property == 1) {
|
common.Add ("Volume", byte.Parse (value));
|
} else if (property == 3) {
|
common.Add ("Source", byte.Parse (value));
|
} else if (property == 5) {
|
common.Add ("Mode", byte.Parse (value));
|
}
|
}
|
break;
|
//传感器
|
case 9: {
|
var common = new SuperGateWayCommon { Type = DeviceType.Sensor, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = inputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
inputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
if (property == 0) {
|
common.Add ("Temperature", byte.Parse (value));
|
} else if (property == 1) {
|
common.Add ("Brightness", byte.Parse (value));
|
}
|
|
}
|
break;
|
//门锁
|
case 10: {
|
var common = new SuperGateWayCommon { Type = DeviceType.DoorLock, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = inputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
inputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
common.Add ("Power", value == "0" ? 0 : 1);
|
}
|
break;
|
case 11: {
|
|
}
|
break;
|
case 12:
|
break;
|
case 13:
|
break;
|
//干接点
|
case 14: {
|
var common = new SuperGateWayCommon { Type = DeviceType.DryContact, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = inputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
inputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
common.Add ("Power", value == "0" ? 0 : 1);
|
}
|
break;
|
case 15:
|
break;
|
case 16:
|
break;
|
}
|
}
|
} catch { }
|
}
|
|
/// <summary>
|
/// 逻辑执行事件对象的方法
|
/// </summary>
|
public void outputSidToDevice ()
|
{
|
try {
|
if (output == null) {
|
return;
|
}
|
|
foreach (var outputlist in output) {
|
if (outputlist.objects == null) {
|
continue;
|
}
|
var objectsList =outputlist.objects;
|
foreach (var o in objectsList) {
|
var tempSid = o ["sid"]?.ToString ();
|
if (tempSid == null) {
|
continue;
|
}
|
var value = o ["value"]?.ToString ();
|
if (value == null) {
|
value = "0";
|
}
|
|
//判断SID是否有效的,如果不是有效的当前这个场景数据就不处理
|
Convert.ToUInt64 (tempSid, 16);
|
|
var sidUlong = Convert.ToUInt64 (tempSid, 16);
|
var subnetId = (byte)((sidUlong >> 40) & 0xFF);
|
var deviceId = (byte)((sidUlong >> 32) & 0xFF);
|
var targetType = (byte)((sidUlong >> 24) & 0xFF);
|
var property = (byte)((sidUlong >> 16) & 0xFF);
|
var targetNumber = (uint)((sidUlong >> 0) & 0xFFFF);
|
|
switch (targetType) {
|
case 0:
|
break;
|
case 1:
|
break;
|
//空调
|
case 2: {
|
var common = new SuperGateWayCommon { Type = DeviceType.HVAC, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = outputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
outputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
|
if (property == 0) {
|
common.Add ("Power", byte.Parse (value));
|
} else if (property == 1) {
|
common.Add ("Mode", byte.Parse (value));
|
} else if (property == 2) {
|
common.Add ("Speed", byte.Parse (value));
|
} else if (property == 3) {
|
common.Add ("Temperature", byte.Parse (value));
|
} else if (property == 4) {
|
common.Add ("Scavenging", byte.Parse (value));
|
} else if (property == 5) {
|
common.Add ("ambienTtemperature", byte.Parse (value));
|
}
|
|
}
|
break;
|
//地热
|
case 3: {
|
var common = new SuperGateWayCommon { Type = DeviceType.FoolHeat, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = outputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
outputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
if (property == 0) {
|
common.Add ("Power", byte.Parse (value));
|
} else if (property == 1) {
|
common.Add ("Temperature", byte.Parse (value));
|
}
|
}
|
break;
|
//新风
|
case 4: {
|
var common = new SuperGateWayCommon { Type = DeviceType.FreshAir, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = outputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
outputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
|
if (property == 0) {
|
common.Add ("Power", byte.Parse (value));
|
} else if (property == 1) {
|
common.Add ("Mode", byte.Parse (value));
|
} else if (property == 2) {
|
common.Add ("Speed", byte.Parse (value));
|
}
|
}
|
break;
|
//窗帘
|
case 5: {
|
if (property == 0) {
|
var common = new SuperGateWayCommon { Type = DeviceType.CurtainModel, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = outputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
outputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
common.Add ("Power", byte.Parse (value));
|
|
} else if (property == 1) {
|
var common = new SuperGateWayCommon { Type = DeviceType.CurtainRoller, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = outputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
outputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
common.Add ("Brightness", byte.Parse (value));
|
}
|
}
|
break;
|
//灯光,可能包含调光及开关
|
case 6: {
|
if (property == 0) {
|
var common = new SuperGateWayCommon { Type = DeviceType.LightSwitch, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = outputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
outputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
common.Add ("Power", value == "0" ? 0 : 1);
|
} else if (property == 1) {
|
var common = new SuperGateWayCommon { Type = DeviceType.LightDimming, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = outputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
outputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
common.Add ("Brightness", byte.Parse (value));
|
}
|
}
|
break;
|
//按键
|
case 7: {
|
if (property == 0) {
|
var common = new SuperGateWayCommon { Type = DeviceType.MechanicalSwitch, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = outputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
outputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
common.Add ("Power", value == "0" ? 0 : 1);
|
} else if (property == 1) {
|
var common = new SuperGateWayCommon { Type = DeviceType.AutomaticSwitch, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = outputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
outputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
common.Add ("Power", byte.Parse (value));
|
}
|
}
|
break;
|
case 8: {
|
var common = new SuperGateWayCommon { Type = DeviceType.MusicModel, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = outputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
outputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
if (property == 0) {
|
common.Add ("Status", byte.Parse (value));
|
} else if (property == 1) {
|
common.Add ("Volume", byte.Parse (value));
|
} else if (property == 3) {
|
common.Add ("Source", byte.Parse (value));
|
} else if (property == 5) {
|
common.Add ("Mode", byte.Parse (value));
|
}
|
}
|
break;
|
//传感器
|
case 9: {
|
var common = new SuperGateWayCommon { Type = DeviceType.Sensor, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = outputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
outputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
if (property == 0) {
|
common.Add ("Temperature", byte.Parse (value));
|
} else if (property == 1) {
|
common.Add ("Brightness", byte.Parse (value));
|
}
|
|
}
|
break;
|
//门锁
|
case 10: {
|
var common = new SuperGateWayCommon { Type = DeviceType.DoorLock, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = outputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
outputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
common.Add ("Power", value == "0" ? 0 : 1);
|
}
|
break;
|
case 11: {
|
|
}
|
break;
|
case 12:
|
break;
|
case 13:
|
break;
|
//干接点
|
case 14: {
|
var common = new SuperGateWayCommon { Type = DeviceType.DryContact, SubnetID = subnetId, DeviceID = deviceId, LoopID = (byte)targetNumber };
|
var tempCommon = outputdeviceList.Find ((obj) => obj.Type == common.Type && obj.CommonLoopID == common.CommonLoopID);
|
if (tempCommon == null) {
|
outputdeviceList.Add (common);
|
} else {
|
common = tempCommon;
|
}
|
common.Add ("Power", value == "0" ? 0 : 1);
|
}
|
break;
|
case 15:
|
break;
|
case 16:
|
break;
|
}
|
}
|
}
|
} catch { }
|
}
|
*/
|
#endregion
|
|
|
public void InputRemoveByTag (SuperGateWayCommon common)
|
{
|
for (int i = 0; i < input.Count; i++) {
|
if (input [i].InputBySid.Type == common.Type && input [i].InputBySid.CommonLoopID == common.CommonLoopID) {
|
input.Remove (input [i]);
|
return;
|
}
|
|
}
|
//input.RemoveAll ((obj) => obj.InputBySid.Type == common.Type && obj.InputBySid.CommonLoopID == common.CommonLoopID);
|
}
|
/// <summary>
|
/// 添加目标的条件
|
/// </summary>
|
/// <param name="common">Common.</param>
|
/// <param name="deviceOutput">Device output.</param>
|
public void AddInput (Input deviceinput)
|
{
|
if (deviceinput.sid == null||deviceinput.sid == "") {
|
return;
|
}
|
var tempSid = deviceinput.sid;
|
//判断SID是否有效的,如果不是有效的当前这个场景数据就不处理
|
Convert.ToUInt64 (tempSid, 16);
|
var sidUlong = Convert.ToUInt64 (tempSid, 16);
|
///1:设备;2:场景;3:逻辑;
|
var type = (byte)((sidUlong >> 60) & 0xF);
|
|
switch (type) {
|
case 1: {
|
var subnetId = (byte)((sidUlong >> 40) & 0xFF);
|
var deviceId = (byte)((sidUlong >> 32) & 0xFF);
|
var targetType = (byte)((sidUlong >> 24) & 0xFF);
|
var property = (byte)((sidUlong >> 16) & 0xFF);
|
var targetNumber = (uint)((sidUlong >> 0) & 0xFFFF);
|
///用来判断为条件,查找当前设备;
|
var commonLoopID = subnetId + "_" + deviceId + "_" + targetNumber;
|
var Type = devicetype (targetType, property);
|
|
for (int i = 0; i < input.Count; i++) {
|
var devsid = input [i].sid;
|
Convert.ToUInt64 (devsid, 16);
|
var devsidUlong = Convert.ToUInt64 (devsid, 16);
|
var devsubnetId = (byte)((devsidUlong >> 40) & 0xFF);
|
var deviceId1 = (byte)((devsidUlong >> 32) & 0xFF);
|
var devtargetType = (byte)((devsidUlong >> 24) & 0xFF);
|
var devproperty = (byte)((devsidUlong >> 16) & 0xFF);
|
var devtargetNumber = (uint)((devsidUlong >> 0) & 0xFFFF);
|
///用来判断为条件,查找当前设备;
|
var devcommonLoopID = devsubnetId + "_" + deviceId1 + "_" + devtargetNumber;
|
var devType = devicetype (devtargetType, devproperty);
|
if (commonLoopID == devcommonLoopID && Type == devType && property == devproperty) {
|
input.RemoveAt (i);
|
input.Insert (i, deviceinput);
|
return;
|
}
|
}
|
input.Add (deviceinput);
|
}
|
break;
|
case 3: {
|
for (int i = 0; i < input.Count; i++) {
|
var devsid = input [i].sid;
|
if (tempSid == devsid) {
|
input.RemoveAt (i);
|
input.Insert (i, deviceinput);
|
return;
|
}
|
}
|
input.Add (deviceinput);
|
}
|
break;
|
}
|
|
}
|
/// <summary>
|
/// 添加执行目标
|
/// </summary>
|
/// <param name="common">Common.</param>
|
/// <param name="deviceOutput">Device output.</param>
|
public void AddOutput (Output objects)
|
{
|
var dictionary = new Dictionary<string, object> ();
|
foreach (var o in objects.objects) {
|
dictionary = o;
|
}
|
if (!dictionary.ContainsKey ("sid")) {
|
return;
|
}
|
var tempSid = dictionary ["sid"]?.ToString ();
|
if (tempSid == null||tempSid =="") {
|
return;
|
}
|
//判断SID是否有效的,如果不是有效的当前这个场景数据就不处理
|
Convert.ToUInt64 (tempSid, 16);
|
var sidUlong = Convert.ToUInt64 (tempSid, 16);
|
///1:设备;2:场景;3:逻辑;
|
var type = (byte)((sidUlong >> 60) & 0xF);
|
|
switch (type) {
|
case 1: {
|
var subnetId = (byte)((sidUlong >> 40) & 0xFF);
|
var deviceId = (byte)((sidUlong >> 32) & 0xFF);
|
var targetType = (byte)((sidUlong >> 24) & 0xFF);
|
var property = (byte)((sidUlong >> 16) & 0xFF);
|
var targetNumber = (uint)((sidUlong >> 0) & 0xFFFF);
|
///用来判断为条件,查找当前设备;
|
var commonLoopID = subnetId + "_" + deviceId + "_" + targetNumber;
|
var Type = devicetype (targetType, property);
|
|
for (int i = 0; i < output.Count; i++) {
|
var objectlist = output [i].objects;
|
for (int j = 0; j < objectlist.Count; j++) {
|
var temdevsid = objectlist [j] ["sid"]?.ToString ();
|
Convert.ToUInt64 (temdevsid, 16);
|
var devsidUlong = Convert.ToUInt64 (temdevsid, 16);
|
var devsubnetId = (byte)((devsidUlong >> 40) & 0xFF);
|
var deviceId1 = (byte)((devsidUlong >> 32) & 0xFF);
|
var devtargetType = (byte)((devsidUlong >> 24) & 0xFF);
|
var devproperty = (byte)((devsidUlong >> 16) & 0xFF);
|
var devtargetNumber = (uint)((devsidUlong >> 0) & 0xFFFF);
|
///用来判断为条件,查找当前设备;
|
var devcommonLoopID = devsubnetId + "_" + deviceId1 + "_" + devtargetNumber;
|
var devType = devicetype (devtargetType, devproperty);
|
if (commonLoopID == devcommonLoopID && Type == devType&&property == devproperty) {
|
objectlist.RemoveAt (j);
|
objectlist.Insert (j, dictionary);
|
return;
|
}
|
|
}
|
objectlist.Add (dictionary);
|
return;
|
}
|
output.Add (objects);
|
}
|
break;
|
case 2: {
|
for (int i = 0; i < output.Count; i++) {
|
var objectlist = output [i].objects;
|
for (int j = 0; j < objectlist.Count; j++) {
|
var temdevsid = objectlist [j] ["sid"]?.ToString ();
|
if (tempSid == temdevsid) {
|
objectlist.RemoveAt (j);
|
objectlist.Insert (j, dictionary);
|
return;
|
}
|
|
}
|
objectlist.Add (dictionary);
|
return;
|
}
|
output.Add (objects);
|
}
|
break;
|
case 3: {
|
for (int i = 0; i < output.Count; i++) {
|
var objectlist = output [i].objects;
|
for (int j = 0; j < objectlist.Count; j++) {
|
var temdevsid = objectlist [j] ["sid"]?.ToString ();
|
if (tempSid == temdevsid) {
|
objectlist.RemoveAt (j);
|
objectlist.Insert (j, dictionary);
|
return;
|
}
|
|
}
|
objectlist.Add (dictionary);
|
return;
|
}
|
output.Add (objects);
|
}
|
break;
|
}
|
|
}
|
/// <summary>
|
///返回设备类型;
|
/// </summary>
|
/// <returns>The devicetype.</returns>
|
/// <param name="targetType">Target type.</param>
|
/// <param name="property">Property.</param>
|
public static string devicetype (byte targetType, byte property)
|
{
|
var Type = "";
|
switch (targetType) {
|
case 0:
|
break;
|
case 1:
|
break;
|
//空调
|
case 2: {
|
Type = "HVAC";
|
}
|
break;
|
//地热
|
case 3: {
|
Type = "FoolHeat";
|
}
|
break;
|
//新风
|
case 4: {
|
Type = "FreshAir";
|
}
|
break;
|
//窗帘
|
case 5: {
|
if (property == 0) {
|
Type = "CurtainModel";
|
} else if (property == 1) {
|
Type = "CurtainRoller";
|
}
|
}
|
break;
|
//灯光,可能包含调光及开关
|
case 6: {
|
if (property == 0) {
|
Type = "LightSwitch";
|
} else if (property == 1) {
|
Type = "LightDimming";
|
}
|
}
|
break;
|
//按键
|
case 7: {
|
if (property == 0) {
|
Type = "MechanicalSwitch";
|
} else if (property == 1) {
|
Type = "AutomaticSwitch";
|
}
|
}
|
break;
|
case 8: {
|
Type = "MusicModel";
|
}
|
break;
|
//传感器
|
case 9: {
|
Type = "Sensor";
|
}
|
break;
|
//门锁
|
case 10: {
|
Type = "DoorLock";
|
}
|
break;
|
case 11: {
|
}
|
break;
|
case 12:
|
break;
|
case 13:
|
break;
|
//干接点
|
case 14: {
|
Type = "DryContact";
|
}
|
break;
|
case 15:
|
break;
|
case 16:
|
break;
|
}
|
|
return Type;
|
}
|
|
|
|
}
|
|
|
}
|