From a3f51a59941dbe3138e71328baa8f6c7a3d0f9b0 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期三, 02 十二月 2020 17:50:43 +0800
Subject: [PATCH] 2020-12-02-3
---
HDL_ON/Entity/Function/Function.cs | 312 ++++++++++++++++++++++++++++++++++++---------------
1 files changed, 220 insertions(+), 92 deletions(-)
diff --git a/HDL_ON/Entity/Function/Function.cs b/HDL_ON/Entity/Function/Function.cs
index a602940..d5646d3 100644
--- a/HDL_ON/Entity/Function/Function.cs
+++ b/HDL_ON/Entity/Function/Function.cs
@@ -1,5 +1,6 @@
锘縰sing System;
using System.Collections.Generic;
+using HDL_ON.DriverLayer;
using Shared;
namespace HDL_ON.Entity
@@ -12,23 +13,12 @@
public Function()
{
}
- /// <summary>
- /// 鏁版嵁瀛樺偍鏂囦欢鍚�
- /// </summary>
- [Newtonsoft.Json.JsonIgnore]
- public string savePath
- {
- get
- {
- return "FunctionData_" + sid;
- }
- }
#region base info
/// <summary>
/// HDL缁熶竴鍗忚鏍煎紡锛�14bytes
/// 涓句緥锛� 鏉ユ簮 鍘傚晢浠g爜 閫氳鏂瑰紡 浜у搧鏃堕棿鎴� 浜у搧绫诲埆 鐗╂ā鍨嬬被 閫氶亾鍙� 澶у皬绫诲埆
- // 1byte 1byte 1byte 4byte 1byte 2byte 2byte 2byte
+ /// 1byte 1byte 1byte 4byte 1byte 2byte 2byte 2byte
/// 鏉ユ簮锛�00 榛樿鍘熺敓鎬佺郴缁熸暟鎹� 銆�01 缃戝叧鎴栬�呭叾浠朅璁惧銆�02 璋冭瘯杞欢銆�03 APP搴旂敤绋嬪簭銆�04 绗笁鏂圭綉鍏虫垨鑰呭钩鍙�
/// 鍘傚晢浠g爜锛�01 HDL
/// 閫氳鏂瑰紡锛�01 HDL Bus銆�02 Zigbee銆�03 KNX銆�04 Z-Wave
@@ -48,25 +38,75 @@
/// 灏忕被鍒� 1byte 锛堥鐣欙級
/// </summary>
public string sid = "0301011234567801012301230123";
+ /// <summary>
+ /// 澶囨敞
+ /// </summary>
+ public string name;
+ /// <summary>
+ /// 璁惧ID
+ /// 浜戠璐熻矗鐢熸垚
+ /// </summary>
+ public string deviceId = "0";
+ /// <summary>
+ /// 璁惧spk
+ /// </summary>
+ public string spk = "";
+ /// <summary>
+ /// 鍔熻兘绫诲埆
+ /// 濡傦細绌鸿皟绫汇�佺伅鍏夌被銆佺獥甯樼被
+ /// </summary>
+ public FunctionCategory functionCategory
+ {
+ get
+ {
+ try
+ {
+ var _functionCategoryString = sid.Substring(16, 2);
+ var _functionCategory = Convert.ToInt32(_functionCategoryString, 16);
+ return (FunctionCategory)Enum.ToObject(typeof(FunctionCategory), _functionCategory);
+ }
+ catch (Exception ex)
+ {
+ MainPage.Log($"get FunctionCategory error : {ex.Message}");
+ return FunctionCategory.UnKown;
+ }
+ }
+ }
+ /// <summary>
+ /// 鍔熻兘绫诲瀷
+ /// </summary>
+ public FunctionType functionType
+ {
+ get
+ {
+ var _functionTypeString = sid.Substring(16, 4);
+ return (FunctionType)Enum.ToObject(typeof(FunctionType), Convert.ToInt32(_functionTypeString, 16));
+ }
+ }
/// <summary>
/// A鍗忚鍔熻兘鐨勭壒鎬�
/// 濡傦細鏄疉C鍔熻兘锛氱壒鎬э細on_off,mode,fan,temperature
/// attri
/// </summary>
- public List<FunctionAttributes> function = new List<FunctionAttributes>();
+ public List<FunctionAttributes> attributes = new List<FunctionAttributes>();
/// <summary>
/// 鎴块棿ID鍒楄〃
/// 璇ュ姛鑳芥坊鍔犲埌鍒版埧闂村垪琛�
/// </summary>
- public List<string> roomIdList = new List<string>();
+ public List<string> roomIds = new List<string>();
/// <summary>
/// bus鍗忚鏁版嵁鏍煎紡
/// 浣跨敤A鍗忚鎺у埗鏃讹紝鏀瑰睘鎬т负绌�
/// </summary>
public BusData bus_Data;
+ /// <summary>
+ /// 鏄惁鏀惰棌
+ /// </summary>
+ public bool collect = false;
+ #endregion
/// <summary>
/// 寤舵椂
/// </summary>
@@ -101,43 +141,6 @@
return text;
}
}
- #endregion
-
- /// <summary>
- /// 鍔熻兘绫诲埆
- /// 濡傦細绌鸿皟绫汇�佺伅鍏夌被銆佺獥甯樼被
- /// </summary>
- public FunctionCategory functionCategory
- {
- get
- {
- try
- {
- var _functionCategoryString = sid.Substring(16, 2);
- var _functionCategory = Convert.ToInt32(_functionCategoryString, 16);
- return (FunctionCategory)Enum.ToObject(typeof(FunctionCategory), _functionCategory);
- }
- catch (Exception ex)
- {
- MainPage.Log($"get FunctionCategory error : {ex.Message}");
- return FunctionCategory.UnKown;
- }
- }
- }
-
- public FunctionType functionType
- {
- get
- {
- var _functionTypeString = sid.Substring(16, 4);
- return (FunctionType)Enum.ToObject(typeof(FunctionType), Convert.ToInt32(_functionTypeString, 16));
- }
- }
-
- /// <summary>
- /// 澶囨敞
- /// </summary>
- public string name;
/// <summary>
/// 鏈�鍚庢帶鍒剁殑涓�娆$姸鎬�
@@ -153,7 +156,7 @@
{
if (_trait_on_off == null)
{
- _trait_on_off = function.Find((obj) => obj.key == "on_off");
+ _trait_on_off = attributes.Find((obj) => obj.key == "on_off");
//鎵句笉鍒板睘鎬ч渶瑕佸0鏄庝竴涓紝闃叉鎶ラ敊闂��
if (_trait_on_off == null)
{
@@ -174,11 +177,6 @@
// _trait_on_off = value;
//}
}
-
- /// <summary>
- /// 鏄惁鏀惰棌
- /// </summary>
- public bool collection = false;
/// <summary>
/// 浣跨敤娆℃暟
@@ -203,7 +201,7 @@
string busId = "";
if (bus_Data != null)
{
- busId = bus_Data.SubnetID + "_" + bus_Data.DeviceID + "_" + bus_Data.LoopID;
+ busId = bus_Data.SubnetID + "_" + bus_Data.DeviceID + "_" + bus_Data.loopId;
}
return busId;
}
@@ -215,7 +213,7 @@
public string GetRoomListName()
{
string roomNameList = "";
- foreach(var roomId in roomIdList)
+ foreach(var roomId in roomIds)
{
var findRoom = DB_ResidenceData.rooms.Find(obj => obj.sid == roomId);
if (findRoom == null)
@@ -235,13 +233,38 @@
return roomNameList;
}
/// <summary>
+ /// 鏁版嵁瀛樺偍鏂囦欢鍚�
+ /// </summary>
+ [Newtonsoft.Json.JsonIgnore]
+ public string savePath
+ {
+ get
+ {
+ return "FunctionData_" + sid;
+ }
+ }
+ /// <summary>
/// 淇濆瓨鍔熻兘鏁版嵁
/// </summary>
public void SaveFunctionData()
{
var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
- FileUtils.WriteFileByBytes("FunctionData_" + this.sid, ssd);
+ FileUtils.WriteFileByBytes( savePath + this.sid, ssd);
MainPage.Log($"Save FunctionData {this.functionType} : {this.sid}");
+ }
+
+ /// <summary>
+ /// 杞崲鎴愬満鏅姛鑳藉璞�
+ /// </summary>
+ /// <returns></returns>
+ public SceneFunction ConvertSceneFunction()
+ {
+ var sFunc = new SceneFunction();
+ foreach (var attr in attributes)
+ {
+ sFunc.status.Add(new SceneFunctionStatus() { key = attr.key, value = attr.curValue.ToString() });
+ }
+ return sFunc;
}
/// <summary>
@@ -250,63 +273,106 @@
public DateTime refreshTime = DateTime.MinValue;
/// <summary>
- /// 鑾峰彇鎺у埗鍙戦�佹暟鎹�
+ /// 鑾峰彇鏈湴鎺у埗鏁版嵁
/// </summary>
- public AprotocolControlObj GetControlSendData(Dictionary<string, string> commandDictionary)
+ public GatewayAlinkControlObj GetGatewayAlinkControlData(Dictionary<string, string> commandDictionary)
{
- var sendDataObj = new AprotocolControlObj();
- sendDataObj.from_oid = "";
- sendDataObj.to_oid = "";
- sendDataObj.time_stamp = "";
- sendDataObj.type = "device_sid";
- sendDataObj.command = "write";
+ var sendDataObj = new GatewayAlinkControlObj();
+ sendDataObj.id = Control.Ins.msg_id.ToString();
+ sendDataObj.time_stamp = Control.Ins.Get_TimeStamp();
- var acoList = new AprotocolControlData();
- acoList.sid = sid;
- var aco = new AprotocolControlAttribute();
+
+ var acd = new AlinkControlData();
+ acd.sid = sid;
+#if DEBUG
+ acd.sid = "0001016FB925AB02020100010101";
+#endif
+ var aca = new AlinkControlAttributes();
foreach(var dic in commandDictionary)
{
- aco.name = dic.Key;
- aco.value = dic.Value;
- acoList.function.Add(aco);
+ aca.key = dic.Key;
+ aca.value = dic.Value;
+ acd.status.Add(aca);
}
- sendDataObj.objects.Add(acoList);
-
+ sendDataObj.objects.Add(acd);
return sendDataObj;
+ }
+ /// <summary>
+ /// 鑾峰彇Api鎺у埗鏁版嵁
+ /// </summary>
+ /// <returns></returns>
+ public ApiAlinkControlActionObj GetApiControlData(Dictionary<string,string> keyValues)
+ {
+ ApiAlinkControlActionObj aaao = new ApiAlinkControlActionObj();
+ aaao.deviceId = this.deviceId;
+ aaao.spk = this.spk;
+ foreach (var kv in keyValues)
+ {
+ aaao.attributes.Add(new AlinkControlAttributes()
+ {
+ key = kv.Key,
+ value = kv.Value,
+ });
+ }
+ return aaao;
}
}
/// <summary>
+ /// 杩滅▼鎺у埗
+ /// api a鍗忚鎺у埗鍔ㄤ綔瀵硅薄
+ /// </summary>
+ public class ApiAlinkControlActionObj
+ {
+ /// <summary>
+ /// 璁惧ID
+ /// </summary>
+ public string deviceId = "0";
+ /// <summary>
+ /// spk
+ /// 鍒�:light.switch
+ /// </summary>
+ public string spk = "";
+
+ public List<AlinkControlAttributes> attributes = new List<AlinkControlAttributes>();
+ }
+
+ /// <summary>
+ /// 鏈湴鎺у埗
/// A鍗忚鎺у埗鏁版嵁鐨勫璞�
/// </summary>
- public class AprotocolControlObj
+ public class GatewayAlinkControlObj
{
- public List<AprotocolControlData> objects = new List<AprotocolControlData>();
+ public List<AlinkControlData> objects = new List<AlinkControlData>();
- public string from_oid = "";
- public string to_oid = "";
public string time_stamp = "";
- public string type = "";
- public string command = "";
+ public string id = "";
}
/// <summary>
/// A鍗忚鎺у埗鏁版嵁
/// </summary>
- public class AprotocolControlData
+ public class AlinkControlData
{
-
public string sid = "";
- public List<AprotocolControlAttribute> function = new List<AprotocolControlAttribute>();
+ public List<AlinkControlAttributes> status = new List<AlinkControlAttributes>();
}
/// <summary>
- /// A鍗忚鎺у埗灞炴�у璞�
+ /// a鍗忚鎺у埗鍔ㄤ綔鏁版嵁
/// </summary>
- public class AprotocolControlAttribute
+ public class AlinkControlAttributes
{
- public string name;
- public string value;
+ /// <summary>
+ /// 灞炴�у悕
+ /// 鍒�:on_off
+ /// </summary>
+ public string key = "";
+ /// <summary>
+ /// 灞炴�у��
+ /// 鍒�:on
+ /// </summary>
+ public string value = "";
}
/// <summary>
@@ -331,17 +397,14 @@
/// 鏈�灏忓��
/// </summary>
public int min;
-
/// <summary>
/// 鏁版嵁绫诲瀷
/// </summary>
public string data_type = "";
-
/// <summary>
/// 褰撳墠鍊�
/// </summary>
public object curValue = new object();
-
//----app鑷畾涔�
/// <summary>
@@ -609,6 +672,48 @@
}
}
/// <summary>
+ /// 鍔熻兘灞炴�ч敭鍚嶅垪琛�
+ /// </summary>
+ public static class FunctionAttributeKey
+ {
+ /// <summary>
+ /// 寮�鍏�
+ /// </summary>
+ public const string OnOff = "on_off";
+ /// <summary>
+ /// 浜害
+ /// </summary>
+ public const string Brightness = "brightness";
+ /// <summary>
+ /// 棰滆壊
+ /// </summary>
+ public const string Color = "color";
+ /// <summary>
+ /// 妯″紡
+ /// </summary>
+ public const string Mode = "mode";
+ /// <summary>
+ /// 椋庨��
+ /// </summary>
+ public const string FanSpeed = "fan";
+ /// <summary>
+ /// 娓╁害
+ /// </summary>
+ public const string Temp = "temperature";
+ /// <summary>
+ /// 寤舵椂
+ /// </summary>
+ public const string Delay = "delay";
+ /// <summary>
+ /// 鑹叉俯
+ /// </summary>
+ public const string CCT = "cct";
+ /// <summary>
+ /// 鐧惧垎姣�
+ /// </summary>
+ public const string Percent = "percent";
+ }
+ /// <summary>
/// 璁惧鍔熻兘oid
/// </summary>
public class FunctionOid
@@ -621,4 +726,27 @@
public string channels;
}
+ /// <summary>
+ /// 鍏煎鏃у崗璁帶鍒�
+ /// </summary>
+ public class BusData
+ {
+ public string addresses = "FFFF";
+ public byte SubnetID
+ {
+ get
+ {
+ return Convert.ToByte(addresses.Substring(0, 2), 16);
+ }
+ }
+ public byte DeviceID
+ {
+ get
+ {
+ return Convert.ToByte(addresses.Substring(2, 2), 16);
+ }
+ }
+ public byte loopId;
+ }
+
}
--
Gitblit v1.8.0