wxr
2020-08-13 6a9ad7ec93218913a2ce3b898bb036f18f8f0da4
HDL_ON/Entity/Function/Function.cs
@@ -17,6 +17,10 @@
        /// </summary>
        public string attri;
        /// <summary>
        /// 属性名称
        /// </summary>
        public string name;
        /// <summary>
        /// 属性的值
        /// </summary>
        public List<string> value;
@@ -28,58 +32,69 @@
        /// 最小值
        /// </summary>
        public int min;
        /// <summary>
        /// 数据类型
        /// </summary>
        public string data_type = "";
        /// <summary>
        /// 当前值
        /// app软件自定义属性
        /// 用来记录当前状态
        /// </summary>
        public object curValues = new object();
    }
    /// <summary>
    /// 设备功能oid
    /// </summary>
    public class FunctionOid
    {
        public string oid;
        public string name;
        public string machine_id;
        public string net_id;
        public string dev_id;
        public string channels;
    }
    public class Function
    {
        /*
        HDL统一协议格式:16bytes
        厂商代号:2bytes
        通讯方式:有线/无线/ZIGBEE等1bytes
        产品识别码:以添加设备的年月日时分秒 + 随机数  8bytes  Category
        功能类别:1bytes
        数据表索引地址:2bytes
        回路:2bytes
        举例: 0001-00-2019101209001234-01-0001-0001
        */
        public Function()
        {
            dicPropert = new Dictionary<string, string>();
            if (trait == null || trait.Count == 0)
            {
                foreach (var t in trait)
                {
                    dicPropert.TryAdd(t.attri,t.min.ToString());
                }
            }
        }
        #region base info
        /// <summary>
        /// 功能ID
        /// 厂商代码   2bytes;     01   HDL
        /// 通讯方式   1byte ;     01   HDL Bus; 02   Zigbee;03   KNX;04   Z-Wave
        /// 产品GUID   8bytes
        /// 产品类别   1byte ;     01  调光器;02继电器;03干接点模块;04传感器;05面板
        /// 物模型类型2bytes      01 开关类    --01开关;02插座
        ///                      02   照明     --01开关类;02调光类;03色温;04LED
        ///                      03   遮阳     --01窗帘电机;02百叶窗;03开合帘;04卷帘
        ///                      04   恒温器    --01空调;02地暖;03毛细空调
        ///                   05   新风
        ///                   06   影音
        ///                   07   音乐
        ///                      08   能源
        ///                      09   安防
        /// 通道号   2bytes
        /// Key_id  2bytes
        /// HDL统一协议格式:14bytes
        /// 举例: 来源   厂商代码 通讯方式  产品时间戳   产品类别 物模型类  通道号   大小类别
        //       1byte   1byte   1byte     4byte       1byte   2byte   2byte   2byte
        /// 来源:00   默认原生态系统数据 、01   网关或者其他A设备、02   调试软件、03   APP应用程序、04   第三方网关或者平台
        /// 厂商代码: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 卷帘
      ///     04   恒温器:01 空调、02 地暖、03 毛细空调
        ///     05   新风
        ///     06   影音
        ///     07   音乐
        ///     08   能源
        ///     09   安防
        /// 大类别   1bytes   (预留)
        /// 小类别   1byte   (预留)
        /// </summary>
        public string sid = "00010112345678901234560101230123AABB";
        public string sid = "03010112345678010123012301230101";
        /// <summary>
        /// A协议功能的通行
        /// A协议功能的特性
        /// 如:是AC功能:特性:on_off,mode,fan,temperature
        /// attri
        /// </summary>
        public List<Trait> trait = new List<Trait>();
        public List<Trait> function = new List<Trait>();
        /// <summary>
        /// 房间ID列表
@@ -94,12 +109,6 @@
        public BusData bus_Data;
        #endregion
        /// <summary>
        /// 功能附带的属性与值的列表
        /// </summary>
        public Dictionary<string, string> dicPropert;
        /// <summary>
        /// 功能类别
        /// 如:空调类、灯光类、窗帘类
@@ -110,8 +119,9 @@
            {
                try
                {
                    var _functionCategoryString = sid.Substring(24, 2);
                    return (FunctionCategory)Enum.ToObject(typeof(FunctionCategory), Convert.ToInt32(_functionCategoryString));
                    var _functionCategoryString = sid.Substring(16, 2);
                    var _functionCategory = Convert.ToInt32(_functionCategoryString, 16);
                    return (FunctionCategory)Enum.ToObject(typeof(FunctionCategory), _functionCategory);
                }
                catch (Exception ex)
                {
@@ -125,7 +135,7 @@
        {
            get
            {
                var _functionTypeString = sid.Substring(24, 4);
                var _functionTypeString = sid.Substring(16, 4);
                return (FunctionType)Enum.ToObject(typeof(FunctionType), Convert.ToInt32(_functionTypeString, 16));
            }
        }
@@ -152,9 +162,11 @@
        /// <summary>
        /// 最后控制的一次状态
        /// </summary>
        [Newtonsoft.Json.JsonIgnore]
        public string lastState = "";
        [Newtonsoft.Json.JsonIgnore]
        public Trait trait_on_off;
        /// <summary>
        /// 开关状态
        /// 0:关
@@ -167,14 +179,34 @@
            {
                try
                {
                    string o = "off";
                    dicPropert.TryGetValue("on_off", out o);
                    return o == "" ? "off" : o;
                    if (trait_on_off == null)
                    {
                        trait_on_off = function.Find((obj) => obj.attri == "on_off");
                        //找不到属性需要声明一个,防止报错闪退
                        if (trait_on_off == null)
                        {
                            trait_on_off = new Trait()
                            {
                                attri = "on_off",
                                value = new List<string> { "on", "off" },
                                max = 1,
                                min = 0,
                            };
                        }
                        trait_on_off.curValues = trait_on_off.value[trait_on_off.min];
                    }
                    return trait_on_off.curValues.ToString();
                }
                catch
                {
                    MainPage.Log("on_off 数据获取失败.");
                    dicPropert.TryAdd("on_off", "0");
                    function.Add( new Trait()
                    {
                        attri = "on_off",
                        value = new List<string> { "on", "off" },
                        max = 1,
                        min = 0,
                    });
                    return "off";
                }
            }
@@ -182,12 +214,34 @@
            {
                try
                {
                    dicPropert["on_off"] = value.ToString();
                    if (trait_on_off == null)
                    {
                        trait_on_off = function.Find((obj) => obj.attri == "on_off");
                        //找不到属性需要声明一个,防止报错闪退
                        if (trait_on_off == null)
                        {
                            trait_on_off = new Trait()
                            {
                                attri = "on_off",
                                value = new List<string> { "on", "off" },
                                max = 1,
                                min = 0,
                            };
                        }
                        trait_on_off.curValues = trait_on_off.min;
                    }
                    trait_on_off.curValues = value;
                }
                catch
                catch (Exception ex)
                {
                    MainPage.Log("on_off 数据刷新失败.");
                    dicPropert.TryAdd("on_off", value.ToString());
                    MainPage.Log($"on_off 数据刷新失败: {ex.Message}");
                    function.Add(new Trait()
                    {
                        attri = "on_off",
                        value = new List<string> { "on", "off" },
                        max = 1,
                        min = 0,
                    });
                }
            }
        }
@@ -214,39 +268,6 @@
        /// 固定的序号
        /// </summary>
        public int fixedSerialNumber = int.MaxValue;
        /// <summary>
        /// A协议数据
        /// </summary>
        public List<string> PropertyArray
        {
            get
            {
                try
                {
                    if (trait == null)
                        return new List<string>();
                    var proArr = new List<string>();
                    foreach (var pro in trait)
                    {
                        if (!dicPropert.ContainsKey(pro.attri))
                        {
                            dicPropert.TryAdd(pro.attri, "0");
                        }
                        if (!proArr.Contains(pro.attri))
                        {
                            proArr.Add(pro.attri);
                        }
                    }
                    return proArr;
                }
                catch (Exception ex)
                {
                    MainPage.Log($"Get PropertyArray error : {ex.Message}");
                    return new List<string>();
                }
            }
        }
        /// <summary>
        /// 获取A协议控制字符串
@@ -291,7 +312,6 @@
            }
            return roomNameList;
        }
        /// <summary>
        /// 更新时间