From b8a2e60af419b1710d8b727f3067fbf166887f85 Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期四, 24 十二月 2020 16:20:16 +0800
Subject: [PATCH] 远程控制一端口场景
---
HDL_ON/Entity/Function/Function.cs | 276 +++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 226 insertions(+), 50 deletions(-)
diff --git a/HDL_ON/Entity/Function/Function.cs b/HDL_ON/Entity/Function/Function.cs
index 5fd7886..58b7d98 100644
--- a/HDL_ON/Entity/Function/Function.cs
+++ b/HDL_ON/Entity/Function/Function.cs
@@ -1,5 +1,7 @@
-锘縰sing System;
+using System;
using System.Collections.Generic;
+using HDL_ON.Common;
+using HDL_ON.DAL.Server;
using HDL_ON.DriverLayer;
using Shared;
@@ -33,25 +35,25 @@
#region base info
/// <summary>
- /// HDL缁熶竴鍗忚鏍煎紡锛�14bytes
- /// 涓句緥锛� 鏉ユ簮 鍘傚晢浠g爜 閫氳鏂瑰紡 浜у搧鏃堕棿鎴� 浜у搧绫诲埆 鐗╂ā鍨嬬被 閫氶亾鍙� 澶у皬绫诲埆
+ /// HDL缁熶竴鍗忚鏍煎紡锛�14bytes
+ /// 涓句緥锛� 鏉ユ簮 鍘傚晢浠g爜 閫氳鏂瑰紡 浜у搧鏃堕棿鎴� 浜у搧绫诲埆 鐗╂ā鍨嬬被 閫氶亾鍙� 澶у皬绫诲埆
/// 1byte 1byte 1byte 4byte 1byte 2byte 2byte 2byte
- /// 鏉ユ簮锛�00 榛樿鍘熺敓鎬佺郴缁熸暟鎹� 銆�01 缃戝叧鎴栬�呭叾浠朅璁惧銆�02 璋冭瘯杞欢銆�03 APP搴旂敤绋嬪簭銆�04 绗笁鏂圭綉鍏虫垨鑰呭钩鍙�
- /// 鍘傚晢浠g爜锛�01 HDL
+ /// 鏉ユ簮锛�00 榛樿鍘熺敓鎬佺郴缁熸暟鎹� 銆�01 缃戝叧鎴栬�呭叾浠朅璁惧銆�02 璋冭瘯杞欢銆�03 APP搴旂敤绋嬪簭銆�04 绗笁鏂圭綉鍏虫垨鑰呭钩鍙�
+ /// 鍘傚晢浠g爜锛�01 HDL
/// 閫氳鏂瑰紡锛�01 HDL Bus銆�02 Zigbee銆�03 KNX銆�04 Z-Wave
- /// 浜у搧鏃堕棿鎴筹細4bytes 浠�2020骞�1鏈�1鏃ョ畻鍑虹殑鏃堕棿鎴�0.1s涓哄崟浣�
- /// 浜у搧绫诲埆锛�01 璋冨厜鍣ㄣ��02 缁х數鍣ㄣ��03 骞叉帴鐐规ā鍧椼��04 浼犳劅鍣ㄣ��05 闈㈡澘
- /// 鐗╂ā鍨嬬被鍨嬶細
- /// 01 寮�鍏崇被锛�01 寮�鍏炽��02 鎻掑骇銆�03
- /// 02 鐓ф槑锛� 01 寮�鍏炽��02 璋冨厜銆�03 鑹叉俯銆�04 LED
- /// 03 閬槼锛� 01 绐楀笜鐢垫満銆�02 鐧惧彾绐椼��03 寮�鍚堝笜銆�04 鍗峰笜
+ /// 浜у搧鏃堕棿鎴筹細4bytes 浠�2020骞�1鏈�1鏃ョ畻鍑虹殑鏃堕棿鎴�0.1s涓哄崟浣�
+ /// 浜у搧绫诲埆锛�01 璋冨厜鍣ㄣ��02 缁х數鍣ㄣ��03 骞叉帴鐐规ā鍧椼��04 浼犳劅鍣ㄣ��05 闈㈡澘
+ /// 鐗╂ā鍨嬬被鍨嬶細
+ /// 01 寮�鍏崇被锛�01 寮�鍏炽��02 鎻掑骇銆�03
+ /// 02 鐓ф槑锛� 01 寮�鍏炽��02 璋冨厜銆�03 鑹叉俯銆�04 LED
+ /// 03 閬槼锛� 01 绐楀笜鐢垫満銆�02 鐧惧彾绐椼��03 寮�鍚堝笜銆�04 鍗峰笜
/// 04 鎭掓俯鍣細01 绌鸿皟銆�02 鍦版殩銆�03 姣涚粏绌鸿皟
/// 05 鏂伴
/// 06 褰遍煶
/// 07 闊充箰
/// 08 鑳芥簮
/// 09 瀹夐槻
- /// 澶х被鍒� 1bytes 锛堥鐣欙級
+ /// 澶х被鍒� 1bytes 锛堥鐣欙級
/// 灏忕被鍒� 1byte 锛堥鐣欙級
/// </summary>
public string sid = "0301011234567801012301230123";
@@ -162,7 +164,7 @@
{
if (_trait_on_off == null)
{
- _trait_on_off = attributes.Find((obj) => obj.key == "on_off");
+ _trait_on_off = attributes.Find((obj) => obj.key == FunctionAttributeKey.OnOff);
//鎵句笉鍒板睘鎬ч渶瑕佸0鏄庝竴涓紝闃叉鎶ラ敊闂��
if (_trait_on_off == null)
{
@@ -173,8 +175,12 @@
max = 1,
min = 0,
};
+ _trait_on_off.curValue = "off";
}
- _trait_on_off.curValue = "on";
+ }
+ if(_trait_on_off.curValue.ToString() != "on"&& _trait_on_off.curValue.ToString() != "off")
+ {
+ _trait_on_off.curValue = "off";
}
return _trait_on_off;
}
@@ -187,7 +193,7 @@
/// <summary>
/// 浣跨敤娆℃暟
/// </summary>
- public double usageCount = 0;
+ public double controlCounter = 0;
/// <summary>
/// 浣跨敤棰戠巼
/// </summary>
@@ -195,7 +201,7 @@
{
get
{
- return usageCount / 7;
+ return controlCounter / 7;
}
}
/// <summary>
@@ -203,12 +209,72 @@
/// </summary>
public int fixedSerialNumber = int.MaxValue;
+ /// <summary>
+ /// 鏀惰棌鍔熻兘
+ /// </summary>
+ public void CollectFunction()
+ {
+ var result = "";
+ //var waitPage = new Loading();
+
+ new System.Threading.Thread(() =>
+ {
+ if (collect)
+ {
+ result = ApiUtlis.Ins.HttpRequest.CollectDevice(deviceId).Code;
+ }
+ else
+ {
+ result = ApiUtlis.Ins.HttpRequest.CancelCollectDevice(deviceId).Code;
+ }
+ //鎻愮ず閿欒
+ if (result != StateCode.SUCCESS)
+ {
+ Application.RunOnMainThread(() =>
+ {
+ collect = !collect;
+ IMessageCommon.Current.ShowErrorInfoAlter(result);
+ });
+ }
+ })
+ { IsBackground = true }.Start();
+ }
+ /// <summary>
+ /// 缂栬緫鍔熻兘缁戝畾鎴块棿淇℃伅
+ /// </summary>
+ public void EditBindRoomInfo(string roomId)
+ {
+ var result = "";
+
+ new System.Threading.Thread(() =>
+ {
+ if (collect)
+ {
+ result = ApiUtlis.Ins.HttpRequest.BindDeviceToRoom(new List<string>() { deviceId }, new List<string>() { roomId }).Code;
+ }
+ else
+ {
+ result = ApiUtlis.Ins.HttpRequest.UnbindDeviceToRoom(deviceId,roomId);
+ }
+ //鎻愮ず閿欒
+ if (result != StateCode.SUCCESS)
+ {
+ Application.RunOnMainThread(() =>
+ {
+ collect = !collect;
+ IMessageCommon.Current.ShowErrorInfoAlter(result);
+ });
+ }
+ })
+ { IsBackground = true }.Start();
+ }
+
public string GetBusId()
{
string busId = "";
if (bus != null)
{
- busId = bus.SubnetID + "_" + bus.DeviceID + "_" + bus.loopId;
+ busId = bus.SubnetID + "_" + bus.DeviceID + "_" + bus.LoopId;
}
return busId;
}
@@ -231,11 +297,11 @@
{
roomNameList += ",";
}
- roomNameList += findRoom.floorName + findRoom.roomName;
+ roomNameList += findRoom.floorName +"-"+ findRoom.roomName;
}
if (roomNameList == "" && functionType == FunctionType.Scene)
{
- roomNameList = Language.StringByID(StringId.WholeHouseScene);
+ roomNameList = Language.StringByID(StringId.WholeZone);
}
return roomNameList;
}
@@ -250,31 +316,104 @@
return "FunctionData_" + sid;
}
}
+
/// <summary>
- /// 淇濆瓨鍔熻兘鏁版嵁
+ /// 淇濆瓨鍔熻兘鏂囦欢
/// </summary>
- public void SaveFunctionData(bool upSevser)
+ public void SaveFunctionFile()
{
- if (upSevser)
+ var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
+ FileUtlis.Files.WriteFileByBytes(savePath, ssd);
+ }
+ /// <summary>
+ /// 淇濆瓨鎴块棿缁戝畾淇℃伅
+ /// </summary>
+ public void UpdataRoomIds()
+ {
+ new System.Threading.Thread(() =>
{
- var pm = new DAL.Server.HttpServerRequest();
- var pack = pm.UpdataDevcieInfo(this);
- if (pack.Code == DAL.Server.StateCode.SUCCESS)
+ var pack = ApiUtlis.Ins.HttpRequest.UpdataDevcieBindRoomInfo(this);
+ //鐩存帴淇濆瓨鏈湴锛�
+ SaveFunctionFile();
+ if (pack.Code == StateCode.SUCCESS)
{
- var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
- Common.FileUtlis.Files.WriteFileByBytes(savePath, ssd);
}
else
{
- Utlis.ShowTip(Language.StringByID(StringId.EditFunctionInfoFail) + "\r\nCode:" + pack.Code);
+ IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
}
- }
- else
- {
- var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
- Common.FileUtlis.Files.WriteFileByBytes(savePath, ssd);
- }
+ })
+ { IsBackground = true }.Start();
}
+ /// <summary>
+ /// 鏇存柊鍔熻兘淇℃伅
+ /// </summary>
+ public void UpdataFuncitonInfo()
+ {
+ new System.Threading.Thread(() =>
+ {
+ var pm = new HttpServerRequest();
+ var pack = pm.UpdataDevcieInfo(this);
+ SaveFunctionFile();
+ if (pack.Code == StateCode.SUCCESS)
+ {
+ }
+ else
+ {
+ IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
+ }
+ })
+ { IsBackground = true }.Start();
+ }
+ /// <summary>
+ /// 鏇存柊鍔熻兘鍚嶇О
+ /// </summary>
+ public void UpdataFunctionName()
+ {
+ new System.Threading.Thread(() =>
+ {
+ var pm = new HttpServerRequest();
+ var pack = pm.UpdataDevcieInfo(this);
+ SaveFunctionFile();
+ if (pack.Code == StateCode.SUCCESS)
+ {
+ }
+ else
+ {
+ IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
+ }
+ })
+ { IsBackground = true }.Start();
+ }
+ /// <summary>
+ /// 淇濆瓨鍔熻兘鏁版嵁
+ /// </summary>
+ //public void SaveFunctionData(bool upSevser)
+ //{
+ // if (upSevser)
+ // {
+ // new System.Threading.Thread(() =>
+ // {
+ // var pm = new HttpServerRequest();
+ // var pack = pm.UpdataDevcieInfo(this);
+ // if (pack.Code == StateCode.SUCCESS)
+ // {
+ // var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
+ // FileUtlis.Files.WriteFileByBytes(savePath, ssd);
+ // }
+ // else
+ // {
+ // IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
+ // }
+ // })
+ // { IsBackground = true }.Start();
+ // }
+ // else
+ // {
+ // var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
+ // FileUtlis.Files.WriteFileByBytes(savePath, ssd);
+ // }
+ //}
/// <summary>
@@ -286,14 +425,37 @@
var sFunc = new SceneFunction();
foreach (var attr in attributes)
{
- if (attr.key == FunctionAttributeKey.SetTemp)
+ switch (attr.key)
{
- var vv = Convert.ToDouble(attr.value);
- sFunc.status.Add(new SceneFunctionStatus() { key = attr.key, value = Convert.ToInt32(vv).ToString() });
- }
- else
- {
- sFunc.status.Add(new SceneFunctionStatus() { key = attr.key, value = attr.curValue.ToString() });
+ case FunctionAttributeKey.OnOff:
+ case FunctionAttributeKey.Brightness:
+ case FunctionAttributeKey.Mode:
+ case FunctionAttributeKey.SetTemp:
+ case FunctionAttributeKey.FanSpeed:
+ case FunctionAttributeKey.Percent:
+ //case FunctionAttributeKey.FadeTime:
+ if (attr.curValue.ToString() == "{}")
+ {
+ if (attr.key == FunctionAttributeKey.OnOff)
+ {
+ attr.curValue = "off";
+ }
+ else
+ {
+ attr.curValue = "0";
+ }
+ }
+ if (attr.key == FunctionAttributeKey.SetTemp)
+ {
+ double vv = 16;
+ Double.TryParse(attr.curValue.ToString(), out vv);
+ sFunc.status.Add(new SceneFunctionStatus() { key = attr.key, value = Convert.ToInt32(vv).ToString() });
+ }
+ else
+ {
+ sFunc.status.Add(new SceneFunctionStatus() { key = attr.key, value = attr.curValue.ToString() });
+ }
+ break;
}
}
sFunc.sid = this.sid;
@@ -317,9 +479,9 @@
var acd = new AlinkControlData();
acd.sid = sid;
- var aca = new AlinkControlAttributes();
foreach (var dic in commandDictionary)
{
+ var aca = new AlinkControlAttributes();
aca.key = dic.Key;
aca.value = dic.Value;
acd.status.Add(aca);
@@ -338,6 +500,7 @@
ApiAlinkControlActionObj aaao = new ApiAlinkControlActionObj();
aaao.deviceId = this.deviceId;
aaao.spk = this.spk;
+ aaao.bus = this.bus;
foreach (var kv in keyValues)
{
aaao.attributes.Add(new AlinkControlAttributes()
@@ -420,6 +583,7 @@
/// 鍔熻兘灞炴��
/// 灞炴�у瓧娈佃В鏋愶細attri :灞炴�у唴瀹癸紝value 灞炴�х殑鍊硷紝max 鏈�澶у�� min 鏈�灏忓��
/// </summary>
+ [System.Serializable]
public class FunctionAttributes
{
/// <summary>
@@ -497,6 +661,10 @@
/// 瀹ゅ唴娓╁害
/// </summary>
public const string IndoorTemp = "room_temp";
+ /// <summary>
+ /// value
+ /// </summary>
+ public const string Value = "value";
}
/// <summary>
/// 璁惧鍔熻兘oid
@@ -533,7 +701,15 @@
return Convert.ToByte(addresses.Substring(2, 2), 16);
}
}
- public byte loopId;
+ public byte LoopId
+ {
+ get
+ {
+ return Convert.ToByte(loopId, 16);
+ }
+ }
+
+ public string loopId;
}
public static class SPK
@@ -604,11 +780,11 @@
public const string SensorPir = "sensor.pir";
/// <summary>
/// 锛堥棬绐椾紶鎰熷櫒锛�
- /// </summary>
+ /// </summary>
public const string SensorDoorWindow = "sensor.doorwindow";
/// <summary>
/// 锛圥M2.5浼犳劅鍣級
- /// </summary>
+ /// </summary>
public const string SensorPm25 = "sensor.pm25";
/// <summary>
/// co2浼犳劅鍣�
@@ -624,20 +800,20 @@
public const string SensorHumidity = "sensor.humidity";
/// <summary>
/// 锛堝共鎺ョ偣锛�
- /// </summary>
- public const string DryContact = "dryContact.standard";
+ /// </summary>
+ public const string DryContact = "dryContact.standard";
/// <summary>
/// 瀹剁數銆佹彃搴�
/// </summary>
- public const string ElectricSocket = "electrical.socket";
+ public const string ElectricSocket = "electrical.socket";
/// <summary>
/// 瀹剁數銆佺數瑙�
/// </summary>
- public const string ElectricTV = "electrical.tv";
+ public const string ElectricTV = "electrical.tv";
/// <summary>
/// 瀹剁數銆侀鎵�
/// </summary>
public const string ElectricFan = "electrical.fan";
}
-}
\ No newline at end of file
+}
--
Gitblit v1.8.0