From c0379d078e7919c9934085da038e8e3c20dee85a Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期四, 25 二月 2021 19:26:06 +0800 Subject: [PATCH] 2021-02-25 1.增加语音设备选择。2.增加场景全量更新上传。 --- Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs | 133 +++++++++++++++++++++++++++++++++++++------- 1 files changed, 111 insertions(+), 22 deletions(-) diff --git a/Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs b/Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs index 996ecc4..ca01b81 100644 --- a/Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs +++ b/Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs @@ -11,6 +11,40 @@ public class HDLLinkUtlis { /// <summary> + /// 鐢熸垚閫昏緫sid鏂规硶 + /// </summary> + public static string NewSceneSid () + { + string sceneId = ""; + try { + string sOidBeginsWith = "000101";//鍘傚晢 + 閫氳鏂瑰紡 + + string sTimeSpan = "00000000"; + long sTimeSp = ConvertDateTimeLong (); //浠�2020骞�1鏈�1鏃ョ畻鍑虹殑鏃堕棿鎴�0.1s涓哄崟浣� + ConvertIntToByteArray (sTimeSp, ref sTimeSpan); + + if (sTimeSpan.Length > 8) { + sTimeSpan = sTimeSpan.Substring (0, 8); + } + + sceneId = sOidBeginsWith + sTimeSpan; + + sceneId += "0A"; + sceneId += "0A01"; + int maxId = 1; + + Random random = new Random (Guid.NewGuid ().GetHashCode ()); + maxId = random.Next (65535); + + sceneId += (maxId).ToString ("X4"); + sceneId += "0000"; + } catch { + return sceneId; + } + return sceneId; + } + + /// <summary> /// /// </summary> /// <param name="curtainStatus"></param> @@ -38,7 +72,7 @@ public static long ConvertDateTimeLong () { System.DateTime startTime = TimeZoneInfo.ConvertTimeToUtc (new System.DateTime (2020, 1, 1)); - long l = (long)(Math.Round ((DateTime.Now - startTime).TotalSeconds, 1) * 10); + long l = (long)(Math.Round ((DateTime.Now - startTime).TotalMilliseconds, 1) / 10); if (l <= LastTime) l = LastTime + 1; LastTime = l; return l; @@ -100,8 +134,10 @@ hdlLinkSceneList.Add (mHDLLinkScene); } } - //2.涓婁紶鍦烘櫙 + + //鍏ㄩ噺鍚屾鍦烘櫙 res = UploadSceneList (hdlLinkSceneList); + } catch (Exception ex){ Utlis.WriteLine ("catch :" + ex.ToString ()); @@ -134,16 +170,29 @@ } } - foreach (var list in globalSceneFileList) { - var tempScene = Scene.GetSceneByFilePath (list); + foreach (var sceneFilePath in globalSceneFileList) { + var tempScene = Scene.GetSceneByFilePath (sceneFilePath); if (tempScene != null) { + if (string.IsNullOrEmpty (tempScene.Sid)) { + //濡傛灉Sid涓虹┖锛岄噸鏂扮敓鎴愬苟淇濆瓨 + tempScene.Sid = NewSceneSid (); + tempScene.Save (sceneFilePath); + Utlis.WriteLine ("鐢熸垚鏂扮殑鍦烘櫙id锛� " + tempScene.Sid); + + } targetSceneList.Add (tempScene); } } - foreach (var list in RoomsSceneFileList) { - var tempScene = Scene.GetSceneByFilePath (list); + foreach (var roomSceneFilePath in RoomsSceneFileList) { + var tempScene = Scene.GetSceneByFilePath (roomSceneFilePath); if (tempScene != null) { + if (string.IsNullOrEmpty (tempScene.Sid)) { + //濡傛灉Sid涓虹┖锛岄噸鏂扮敓鎴愬苟淇濆瓨 + tempScene.Sid = NewSceneSid (); + tempScene.Save (roomSceneFilePath); + Utlis.WriteLine ("鐢熸垚鏂扮殑鍦烘櫙id锛� " + tempScene.Sid); + } targetSceneList.Add (tempScene); } } @@ -152,14 +201,34 @@ } /// <summary> - /// + /// 鍏ㄩ噺鍚屾鍦烘櫙 /// </summary> /// <param name="mScene"></param> bool UploadSceneList (List<HDLLinkScene> hdlLinkSceneList) { var res = false; try { - var revertObj = HttpServerRequest.Current.AddScene (hdlLinkSceneList); + var revertObj = HttpServerRequest.Current.SecneSyncList (hdlLinkSceneList); + if (revertObj.Code == StateCode.SUCCESS) { + res = true; + } else { + IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code); + } + } catch { + + } + return res; + } + + /// <summary> + /// + /// </summary> + /// <param name="mScene"></param> + bool UpdateSceneList (List<HDLLinkScene> updateLinkSceneList) + { + var res = false; + try { + var revertObj = HttpServerRequest.Current.EditScene (updateLinkSceneList); if (revertObj.Code == StateCode.SUCCESS) { res = true; } else { @@ -179,8 +248,7 @@ HDLLinkScene GetHDLLinkScene (Scene mScene) { var mHDLLinkScene = new HDLLinkScene (); - //mHDLLinkScene.sid = mHDLLinkScene.NewSid(); - mHDLLinkScene.sid = mScene.SceneID; + mHDLLinkScene.sid = mScene.Sid; mHDLLinkScene.name = mScene.Name; if (UserConfig.Instance.CheckWhetherGatewayIdNotNull ()) { mHDLLinkScene.gatewayId = UserConfig.Instance.HomeGateway.gatewayId; @@ -653,7 +721,7 @@ Oid tmpOid = new Oid (); tmpOid.protocolType = "bus"; tmpOid.device_name = tmp.Type.ToString (); - tmpOid.oid = FormingNewOid (tmp.Type); + tmpOid.oid = FormingNewOid (tmp); tmpOid.addresses = addresses; tmpOid.device_model = tmp.Type.ToString (); tmpOid.fw_version = ""; @@ -664,11 +732,11 @@ functionLists.AddRange (ConvertToSidListToIotCloud (tmpOid.oid, tmp)); - Utlis.WriteLine ("鏂扮殑妯″潡锛屾柊鐨勭殑OID锛�" + tmpOid.addresses + " deviceType:" + tmpOid.deviceType); + //Utlis.WriteLine ("鏂扮殑妯″潡锛屾柊鐨勭殑OID锛�" + tmpOid.addresses + " deviceType:" + tmpOid.deviceType); } else { //3.2瀛樺湪鍒欏彇涔嬪墠鐨刼id functionLists.AddRange (ConvertToSidListToIotCloud (deviceOid.oid, tmp)); - Utlis.WriteLine ("鐩稿悓鐨勬ā鍧楋紝鍙栦箣鍓嶇殑OID锛�" + deviceOid.addresses + " deviceType:" + deviceOid.deviceType); + //Utlis.WriteLine ("鐩稿悓鐨勬ā鍧楋紝鍙栦箣鍓嶇殑OID锛�" + deviceOid.addresses + " deviceType:" + deviceOid.deviceType); } } @@ -727,23 +795,30 @@ /// <summary> /// 鐢熸垚璁惧Oid /// </summary> - /// <param name="iDeviceType"></param> + /// <param name="common"></param> /// <returns></returns> - public string FormingNewOid (DeviceType deviceType) + public string FormingNewOid (Common common) { string sOid = ""; try { //1.鐢熸垚 鍘傚晢 + 閫氳鏂瑰紡 string sOidBeginsWith = "000101";//鍘傚晢 + 閫氳鏂瑰紡 - //2.鐢熸垚浜у搧鏃堕棿鎴� - long sTimeSp = ConvertDateTimeLong (); //浠�2020骞�1鏈�1鏃ョ畻鍑虹殑鏃堕棿鎴�0.1s涓哄崟浣� + + //**************************** + ////2.鐢熸垚浜у搧鏃堕棿鎴� + //long sTimeSp = ConvertDateTimeLong (); //浠�2020骞�1鏈�1鏃ョ畻鍑虹殑鏃堕棿鎴�0.1s涓哄崟浣� + //string sTimeSpan = ""; + //ConvertIntToByteArray (sTimeSp, ref sTimeSpan); + //if (sTimeSpan.Length != 8) return sOid; + ////寤惰繜10ms + + //2.鏂规浜岋細鐢熸垚浜у搧鏃堕棿鎴筹紙浜戠涓嶈В鏋愶級鍗板害APP鎶婂綋鍓嶄綅缃敼涓�(瀛愮綉鍙枫�佽澶囧彿銆佸ぇ绫诲皬绫�)琛ㄧず锛屼繚璇佽澶囧湪瀛愮綉鍙疯澶囧彿涓嶅彉鐨勬儏鍐典笅 oid鐢熸垚涔熶笉鍙� string sTimeSpan = ""; - ConvertIntToByteArray (sTimeSp, ref sTimeSpan); - if (sTimeSpan.Length != 8) return sOid; - //寤惰繜10ms + sTimeSpan = common.SubnetID.ToString ("X2") + common.DeviceID.ToString ("X2") + common.DeviceTypeString; + //**************************** //3.鐢熸垚浜у搧绫诲埆 - var productType = GetProductType (deviceType); + var productType = GetProductType (common.Type); sOid = sOidBeginsWith + sTimeSpan + productType; return sOid; @@ -938,7 +1013,7 @@ //2.閫氶亾鍙� string loopIDStr = loopCommon.LoopID.ToString ("X4"); //3.澶у皬绫诲埆 - string bigMinStr = loopCommon.BigClass.ToString ("X2") + loopCommon.MinClass.ToString ("X2"); + string bigMinStr = loopCommon.DeviceTypeString; //4.鎷兼帴 sSid = sOid + mPhysicalModelType + loopIDStr + bigMinStr; return sSid; @@ -2216,6 +2291,20 @@ /// 鍥哄畾鐨勫簭鍙� /// </summary> public int fixedSerialNumber = int.MaxValue; + + /// <summary> + /// 澶х被灏忕被 + /// </summary> + [Newtonsoft.Json.JsonIgnore] + public string DeviceTypeString { + get { + if (!string.IsNullOrEmpty (sid) && sid.Length >= 28) { + return sid.Substring (sid.Length - 4, 4); + } else { + return "0000"; + } + } + } } -- Gitblit v1.8.0