//using System; //using System.Text; //using System.Collections.Generic; //using System.Threading; //using Newtonsoft.Json; //using Shared; //using Shared.SimpleControl.Phone; //using Newtonsoft.Json.Linq; //using SmartHome; //namespace SuperGateWay //{ // class SuperGateway11111 : FrameLayout // { // class DeviceInfo{} // public static SuperGateway11111 mSuperGateway; // FrameLayout mFrameLayout; // List DevicesList = new List (); // List SceneList = new List (); // ///程序主入口 传入高级网关设备号,子网号; // //public void SuperGateway (byte subnet_id, byte device_id) // public void Show () // { // mSuperGateway = this; // iniView (); // } // /// // /// 解析设备信息 // /// // /// Json data. // void resolveDevice (string jsonData) // { // var o = JObject.Parse (jsonData); // if (o == null) { // return; // } // var type = o ["type"]; // if (type == null) { // return; // } // switch (type.ToString ()) { // case "light": // var light = JsonConvert.DeserializeObject (jsonData); // break; // case "curtain": // break; // case "air_conditioner": // break; // } // } // public override void RemoveFromParent () // { // base.RemoveFromParent (); // mSuperGateway = null; // } // void iniView () // { // AddChidren (new Button { // Height = Application.GetRealHeight (30), // BackgroundColor = 0xFF1B1B1B, // }); // var topFrameLayout = new FrameLayout { // Height = Application.GetRealHeight (100), // Y = Application.GetRealHeight (30), // BackgroundColor = 0xFF1F1F1F, // }; // AddChidren (topFrameLayout); // var devuidnnamelist = new Button { // //TextID = MyInternationalizationString.Musiclike, // Text = "设备列表" // }; // topFrameLayout.AddChidren (devuidnnamelist); // var back = new Button { // Width = Application.GetRealWidth (82), // Height = Application.GetRealHeight (89), // X = Application.GetRealWidth (10), // Gravity = Gravity.CenterVertical, // UnSelectedImagePath = "MusicIcon/HomepageBack.png", // }; // topFrameLayout.AddChidren (back); // back.MouseDownEventHandler += (sender, e) => { // RemoveFromParent (); // }; // VerticalScrolViewLayout middle = new VerticalScrolViewLayout { // Y = topFrameLayout.Bottom, // Height = Application.GetRealHeight (Application.DesignHeight - 130), // BackgroundColor = 0xff2F2F2F, // }; // AddChidren (middle); // foreach (var uidlist in DevicesList) { // var uidrow = new RowLayout { // Height = Application.GetRealHeight (100), // }; // middle.AddChidren (uidrow); // var btnuid = new Button { // Height = Application.GetRealHeight (100), // X = Application.GetRealWidth (60), // Gravity = Gravity.CenterLeft, // }; // uidrow.AddChidren (btnuid); // } // } // /// // /// 获取所有设备UID // /// // /// The devices uid list. // public static async System.Threading.Tasks.Task GetDevicesUidList () // { // var packetInfo = new PacketInfo () { // command = "devices_get", // messageType = "CON", // }; // var dd = await sendData (packetInfo); // return dd; // } // /// // /// 根据UID来获取设备信息 // /// // /// The device by uid. // /// Uid. // public static async System.Threading.Tasks.Task getDeviceByUID (string uid) // { // JObject jo = new JObject (); // jo.Add ("uid", uid); // var packetInfo = new PacketInfo () { // command = "device_get", // messageType = "CON", // buffer = System.Text.Encoding.UTF8.GetBytes (jo.ToString ()), // }; // var deviceuid = await sendData (packetInfo); // return deviceuid; // } // #region 场景 // /// // /// 添加场景 // /// // /// Scene name. // /// Action. // public static async void AppendScene (string sceneName, Action action) // { // var jo = new JObject (); // jo.Add ("name", sceneName); // //string sss = "{\"name\":\"home\",\"actions\":{}}"; // var packetInfo = new PacketInfo () { // command = "scene_append", // messageType = "CON", // buffer = System.Text.Encoding.UTF8.GetBytes (jo.ToString ()), // }; // var result = await sendData (packetInfo); // if (result == null) { // action (null); // } else { // var dd = Newtonsoft.Json.JsonConvert.DeserializeObject (result); // action (dd); // } // } // /// // /// 获取所有场景ID // /// // /// The devices uid list. // System.Threading.Tasks.Task getSceneList () // { // var packetInfo = new PacketInfo () { // command = "scenes_get", // messageType = "CON", // }; // return sendData (packetInfo); // } // /// // /// 根据UID来获取场景信息 // /// // /// The device by uid. // /// Uid. // System.Threading.Tasks.Task getSceneByUID (string uid) // { // var jo = new JObject (); // jo.Add ("uid", uid); // var packetInfo = new PacketInfo () { // command = "scene_get", // messageType = "CON", // buffer = System.Text.Encoding.UTF8.GetBytes (jo.ToString ()), // }; // return sendData (packetInfo); // } // #endregion // /// // /// 真正发送数据的地方 // /// // /// The data. // /// Send datas. // static async System.Threading.Tasks.Task sendData (PacketInfo sendDatas) // { // var startDateTime = DateTime.Now; // var haveSendCount = 0; // SendAndReceiveDatas.IsACK = false; // SendAndReceiveDatas.IsFinished = false; // //最多发送3次 // while (haveSendCount < 3 && !SendAndReceiveDatas.IsACK) { // switch (haveSendCount) { // case 0: // startDateTime = DateTime.Now; // haveSendCount++; // //SendAndReceiveDatas.Send (sendDatas); // break; // case 1: // if (500 <= (DateTime.Now - startDateTime).TotalMilliseconds) { // haveSendCount++; // //SendAndReceiveDatas.Send (sendDatas); // } // break; // case 2: // if (1000 <= (DateTime.Now - startDateTime).TotalMilliseconds) { // haveSendCount++; // //SendAndReceiveDatas.Send (sendDatas); // } // break; // } // Thread.Sleep (10); // } // while (true) { // System.Threading.Thread.Sleep (10); // if (SendAndReceiveDatas.IsFinished) { // System.Console.WriteLine ("数据接收完毕"); // var tempData = System.Text.Encoding.UTF8.GetString (SendAndReceiveDatas.SplicePacket ()); // return tempData; // } // if (3000 <= (DateTime.Now - startDateTime).TotalMilliseconds) { // //超时 // System.Console.WriteLine ("数据超时"); // return null; // } // } // } // } //}