//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<DeviceInfo> DevicesList = new List<DeviceInfo> ();
|
// List<Scene> SceneList = new List<Scene> ();
|
|
// ///程序主入口 传入高级网关设备号,子网号;
|
// //public void SuperGateway (byte subnet_id, byte device_id)
|
// public void Show ()
|
// {
|
// mSuperGateway = this;
|
|
// iniView ();
|
// }
|
|
|
// /// <summary>
|
// /// 解析设备信息
|
// /// </summary>
|
// /// <param name="jsonData">Json data.</param>
|
// 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<Light> (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);
|
// }
|
|
// }
|
|
|
// /// <summary>
|
// /// 获取所有设备UID
|
// /// </summary>
|
// /// <returns>The devices uid list.</returns>
|
// public static async System.Threading.Tasks.Task<string> GetDevicesUidList ()
|
// {
|
// var packetInfo = new PacketInfo () {
|
// command = "devices_get",
|
// messageType = "CON",
|
// };
|
// var dd = await sendData (packetInfo);
|
// return dd;
|
|
// }
|
// /// <summary>
|
// /// 根据UID来获取设备信息
|
// /// </summary>
|
// /// <returns>The device by uid.</returns>
|
// /// <param name="uid">Uid.</param>
|
// public static async System.Threading.Tasks.Task<string> 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 场景
|
// /// <summary>
|
// /// 添加场景
|
// /// </summary>
|
// /// <param name="sceneName">Scene name.</param>
|
// /// <param name="action">Action.</param>
|
// public static async void AppendScene (string sceneName, Action<SuperGateWay.Scene> 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<SuperGateWay.Scene> (result);
|
// action (dd);
|
// }
|
// }
|
|
// /// <summary>
|
// /// 获取所有场景ID
|
// /// </summary>
|
// /// <returns>The devices uid list.</returns>
|
// System.Threading.Tasks.Task<string> getSceneList ()
|
// {
|
// var packetInfo = new PacketInfo () {
|
// command = "scenes_get",
|
// messageType = "CON",
|
// };
|
// return sendData (packetInfo);
|
// }
|
// /// <summary>
|
// /// 根据UID来获取场景信息
|
// /// </summary>
|
// /// <returns>The device by uid.</returns>
|
// /// <param name="uid">Uid.</param>
|
// System.Threading.Tasks.Task<string> 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
|
|
// /// <summary>
|
// /// 真正发送数据的地方
|
// /// </summary>
|
// /// <returns>The data.</returns>
|
// /// <param name="sendDatas">Send datas.</param>
|
// static async System.Threading.Tasks.Task<string> 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;
|
// }
|
// }
|
// }
|
// }
|
//}
|