using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using Newtonsoft.Json.Linq;
using Shared.Common;
using Shared.Phone.UserCenter.Device.Bind;
using Shared.Phone.UserCenter.Safety;
using ZigBee.Device;
using static ZigBee.Device.BindObj;
using static ZigBee.Device.Panel;
namespace Shared.Phone.UserCenter.DeviceBind
{
///
/// 简约多功能面板
/// 当前界面默认选择第一个楼层,第一个类型
///
public class PanelSimpleMutilfunctionTargetsForm : BindCommonLayout
{
#region 构造函数
///
/// 构造函数
///
/// 简约多功能面板Mac
public PanelSimpleMutilfunctionTargetsForm(string deviceMac)
{
curControlDev = new Panel();
var dev = Common.LocalDevice.Current.GetDevice(deviceMac, 62);//简约面板随便一个回路来获取设备
if (dev != null)
{
curControlDev.CurrentGateWayId = dev.CurrentGateWayId;
}
curControlDev.Type = DeviceType.OnOffSwitch;
curControlDev.DeviceAddr = deviceMac;
}
#endregion
#region 变量申明
///
/// 控制设备
///
Panel curControlDev;
///
/// 显示被绑定设备或场景的view
///
VerticalFrameRefreshControl midVerticalScrolViewLayout;
///
/// 显示绑定类型
///
FrameLayout typeFrameLayout;
///
/// 绑定类型提示文本
///
Button btnTipText;
///
/// 保存完成按钮
///
Button btnFinifh;
///
/// 本地设备列表
///
private System.Collections.Generic.List localDeviceList = new System.Collections.Generic.List();
///
/// 本地场景列表
///
private System.Collections.Generic.List scList = new System.Collections.Generic.List { };
///
/// 当前类型的绑定表
///
public List curBindTypeList = new List();
///
/// 当前类型
/// 0:场景 1:开关 2:插座 3:灯光 4:遮阳 5:空调 6:新风
///
int curBindType = 0;
///
/// 是否支持读取
///
bool IsRead = false;
///
/// 是否支持再次读取【当目标读取不全情况下重新读取】
///
bool IsAgain = false;
///
/// 上一次读取端点
///
private int oldReadEpoint = 2;
///
/// 特殊类型的个数【开关/插座/灯光】需要计算显示的个数
///
int specialTypeCount = 0;
private Action bindReceiveAction = null;
///
/// 回调绑定目标页面刷新
///
public Action> action;
#endregion
#region UI设计
///
/// 目标页显示
///
public void Show()
{
//标题栏
TitleUI();
//中部UI【标题栏下的UI】
MidFrameLayouUI();
//类型栏UI
BindTypeUI();
CommonPage.Loading.Start("");
InitLocalDeviceList();
if (MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.Count == 0)
{
IsRead = true;
}
else
{
IsRead = false;
}
InitData();
}
///
/// 标题栏
///
void TitleUI()
{
string titleText = "";
titleText = Language.StringByID(R.MyInternationalizationString.uBindTargets);
this.TopFrameLayout(this, titleText);
EventHandler eHandlerBack = (sender, e) =>
{
RemoveFromParent();
};
this.btnTitle.Width = Application.GetRealWidth(1080 - 161 - 300);
this.btnBack.MouseUpEventHandler += eHandlerBack;
this.btnBackFrameLayout.MouseUpEventHandler += eHandlerBack;
this.MidFrameLayout(this);
var btnAddFrameLayout = new FrameLayout()
{
X = Application.GetRealWidth(772 - 58),
Width = Application.GetRealWidth(192),
};
this.titleFrameLayout.AddChidren(btnAddFrameLayout);
var btnBindAdd = new Button
{
X = Application.GetRealWidth(62),
Height = Application.GetMinReal(72),
Width = Application.GetMinReal(72),
UnSelectedImagePath = "BindPic/BindAdd.png",
};
btnAddFrameLayout.AddChidren(btnBindAdd);
EventHandler eHandlerAdd = (sender, e) =>
{
var simpleMutilfunctionBindTargetsForm = new Shared.Phone.UserCenter.DeviceBind.PanelSimpleMutilfunctionAddTargetsForm(curControlDev.DeviceAddr, curBindType);
Shared.Phone.UserView.HomePage.Instance.AddChidren(simpleMutilfunctionBindTargetsForm);
Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
simpleMutilfunctionBindTargetsForm.Show();
Action action = () =>
{
RefreshBindListUI();
};
simpleMutilfunctionBindTargetsForm.actionRefreshBindList += action;
};
btnBindAdd.MouseDownEventHandler += eHandlerAdd;
btnAddFrameLayout.MouseDownEventHandler += eHandlerAdd;
}
///
/// 中部UI【标题栏下的UI】
///
void MidFrameLayouUI()
{
//类型栏1
typeFrameLayout = new FrameLayout
{
X = Application.GetRealWidth(58 / 2),
Height = Application.GetRealHeight(323),
};
this.midFrameLayout.AddChidren(typeFrameLayout);
//设备栏
midVerticalScrolViewLayout = new VerticalFrameRefreshControl()
{
Y = Application.GetRealHeight(323),
Height = Application.GetRealHeight(1065),
};
this.midFrameLayout.AddChidren(midVerticalScrolViewLayout);
midVerticalScrolViewLayout.BeginHeaderRefreshingAction += () =>
{
midVerticalScrolViewLayout.BeginHeaderRefreshing();
IsRead = true;
InitData();
};
//底部保存栏
var bottomFrameLayout = new FrameLayout()
{
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight(84 * 2 + 127),
Y = Application.GetRealHeight(1388),
};
this.midFrameLayout.AddChidren(bottomFrameLayout);
btnTipText = new Button()
{
Height = Application.GetRealHeight(84),
TextID = R.MyInternationalizationString.Tip,
TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
TextSize = 12,
Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType),
TextAlignment = TextAlignment.Center,
};
bottomFrameLayout.AddChidren(btnTipText);
btnFinifh = new Button()
{
Width = Application.GetRealWidth(907),
Height = Application.GetRealHeight(127),
Y = Application.GetRealHeight(49 + 35),
Gravity = Gravity.CenterHorizontal,
Radius = (uint)Application.GetRealHeight(127) / 2,
TextID = R.MyInternationalizationString.Save,
BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack,
TextColor = Shared.Common.ZigbeeColor.Current.XMWhite,
IsBold = true,
TextSize = 16,
};
bottomFrameLayout.AddChidren(btnFinifh);
btnFinifh.MouseUpEventHandler += (sender, e) =>
{
SaveTarget();
};
}
///
/// 类型栏UI
///
void BindTypeUI()
{
//匹配的类型列表
var typeList = GetTypeList();
int index = 0;
Button curentOldType = null;
FrameLayout curentOldTypeLayout = null;
foreach (var typeText in typeList)
{
var btnTypeLayout = new FrameLayout
{
Height = Application.GetMinRealAverage(159),
Width = Application.GetMinRealAverage(255),
Y = Application.GetRealHeight(23),
BackgroundImagePath = "Item/RoomIconBackground.png",
BorderWidth = 1,
};
typeFrameLayout.AddChidren(btnTypeLayout);
var btnType = new Button
{
Height = Application.GetRealHeight(58),
Width = Application.GetRealWidth(127),
Y = Application.GetRealHeight(58),
X = Application.GetRealWidth(14),
Text = typeText,
TextSize = 12,
TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
Gravity = Gravity.Center,
};
btnTypeLayout.AddChidren(btnType);
btnType.IsSelected = false;
if (index == 0)
{
btnTypeLayout.Y = Application.GetRealHeight(0);
btnTypeLayout.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
btnType.TextColor = Shared.Common.ZigbeeColor.Current.XMWhite;
curentOldType = btnType;
curentOldTypeLayout = btnTypeLayout;
}
else
{
btnTypeLayout.Y = Application.GetRealHeight(0);
btnTypeLayout.X = index * Application.GetRealWidth(260);
if (index > 3)
{
btnTypeLayout.Y = Application.GetRealHeight(58 + 78);
if (index == 4)
{
btnTypeLayout.X = Application.GetRealWidth(0);
}
else
{
btnTypeLayout.X = (index - 4) * Application.GetRealWidth(260);
}
}
}
EventHandler eHandlerRoom = (sender, e) =>
{
if (!curentOldType.IsSelected)
{
if (curentOldType != null)
{
curentOldType.TextColor = Shared.Common.ZigbeeColor.Current.XMGray3;
}
curentOldType = btnType;
curentOldType.TextColor = Shared.Common.ZigbeeColor.Current.XMWhite;
}
if (btnTypeLayout.BorderWidth == 1)
{
if (curentOldTypeLayout != null)
{
curentOldTypeLayout.BorderWidth = 1;
curentOldTypeLayout.BorderColor = Shared.Common.ZigbeeColor.Current.XMOrange;
curentOldTypeLayout.BackgroundImagePath = "Item/RoomIconBackground.png";
}
curentOldTypeLayout = btnTypeLayout;
curentOldTypeLayout.BorderWidth = 0;
curentOldTypeLayout.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
}
if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.scene))
{
curBindType = 0;
RefreshBindListUI();
}
else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId13))
{
curBindType = 1;
RefreshBindListUI();
}
else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId14))
{
curBindType = 2;
RefreshBindListUI();
}
else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId15))
{
curBindType = 3;
RefreshBindListUI();
}
else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId100))
{
curBindType = 4;
RefreshBindListUI();
}
else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId3600))
{
curBindType = 5;
RefreshBindListUI();
}
else if (curentOldType.Text == Language.StringByID(R.MyInternationalizationString.uDeviceBelongId2310))
{
curBindType = 6;
RefreshBindListUI();
}
};
btnType.MouseUpEventHandler += eHandlerRoom;
btnTypeLayout.MouseUpEventHandler += eHandlerRoom;
index++;
}
}
///
/// 绑定表显示
///
void RefreshBindListUI()
{
midVerticalScrolViewLayout.RemoveAll();
curBindTypeList = MutilfunctionPanelMethod.GetMatchBindList(curBindType);
int curIndex = 0;
for (int i = 0; i < curBindTypeList.Count; i++)
{
curIndex = i;
var bindObj = curBindTypeList[i];
SceneUI curSceneUI = null;
var rowLayout = new RowLayoutControl(midVerticalScrolViewLayout.rowSpace / 2);
rowLayout.BackgroundColor = ZigbeeColor.Current.XMWhite;
midVerticalScrolViewLayout.AddChidren(rowLayout);
rowLayout.frameTable.UseClickStatu = false;
var devicePic = rowLayout.frameTable.AddLeftIcon();
devicePic.Y = Application.GetRealHeight(25);//49
devicePic.UnSelectedImagePath = "DoorLock/DoorLockUserPic.png";
#region 绑定数据处理
int currentIndex = i;
var btnBindNameText = "";
var btnFloorRoomNameText = "";
if (currentIndex == curBindTypeList.Count - 1)
{
rowLayout.LineColor = Shared.Common.ZigbeeColor.Current.XMWhite;
}
if (curBindType == 0)
{
//Scene
curSceneUI = HdlSceneLogic.Current.GetSceneUIBySceneId(bindObj.BindScenesId);
devicePic.UnSelectedImagePath = "Scene/SceneIcon.png";
if (curSceneUI == null)
{
if (string.IsNullOrEmpty(bindObj.ESName))
{
btnBindNameText = Language.StringByID(R.MyInternationalizationString.OffLineScene) + "_" + "ID" + "_" + bindObj.BindScenesId.ToString();
}
else
{
btnBindNameText = Language.StringByID(R.MyInternationalizationString.OffLineScene) + "_" + bindObj.ESName;
}
btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed);
}
else
{
btnBindNameText = curSceneUI.Name;
string myName = HdlSceneLogic.Current.GetZoneById(curSceneUI.Id);
if (myName != null)
{
btnFloorRoomNameText = myName;
}
else
{
btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed);
}
}
}
else
{
//被绑定设备图片【可能和外面设备等图片不同,因为这里是以功能来绑定的】
//devicePic.UnSelectedImagePath = tempDev.IconPath;
var device = LocalDevice.Current.GetDevice(bindObj.BindMacAddr, bindObj.BindEpoint);
switch (curBindType)
{
case 1:
devicePic.UnSelectedImagePath = "BindPic/Switch.png";
break;
case 2:
devicePic.UnSelectedImagePath = "Device/Socket1.png";
break;
case 3:
devicePic.UnSelectedImagePath = "Device/Light.png";
break;
case 4:
if (device != null)
{
if (device.Type == DeviceType.WindowCoveringDevice)
{
var tempCur = device as Rollershade;
if (tempCur.WcdType == 4)
{
devicePic.UnSelectedImagePath = "BindPic/Curtain.png";
}
else
{
devicePic.UnSelectedImagePath = "BindPic/Roller.png";
}
}
}
break;
case 5:
devicePic.UnSelectedImagePath = "Device/AirConditionerEpoint.png";
break;
case 6:
devicePic.UnSelectedImagePath = "Device/FreshAirEpoint.png";
break;
}
if (device != null)
{
//设备名字
btnBindNameText = Common.LocalDevice.Current.GetDeviceEpointName(device);
//获取设备所属房间
var tempDevRoom = HdlRoomLogic.Current.GetRoomByDevice(device);
if (tempDevRoom != null)
{
var tempDevFloorId = tempDevRoom.FloorId;
//获取房间的名字
var tempDevRoomName = tempDevRoom.Name;
//获取楼层的名字
var tempDevFloorName = HdlResidenceLogic.Current.GetFloorNameById(tempDevFloorId);
if (string.IsNullOrEmpty(tempDevFloorName))
{
if (string.IsNullOrEmpty(tempDevRoomName))
{
btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed);
}
else
{
btnFloorRoomNameText = tempDevRoomName;
}
}
else
{
if (string.IsNullOrEmpty(tempDevRoomName))
{
btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed);
}
else
{
btnFloorRoomNameText = tempDevFloorName + "," + tempDevRoomName;
}
}
}
else
{
btnFloorRoomNameText = Language.StringByID(R.MyInternationalizationString.Undistributed);
}
}
else
{
devicePic.TextAlignment = TextAlignment.CenterLeft;
devicePic.TextColor = UserCenterColor.Current.Gray;
devicePic.Text = Language.StringByID(R.MyInternationalizationString.uOffLine);
}
}
var btnBindName = rowLayout.frameTable.AddTopView(btnBindNameText, 800);
var btnFloorRoomName = rowLayout.frameTable.AddBottomView(btnFloorRoomNameText, 800);
rowLayout.frameTable.AddBottomLine();
var btnDel = rowLayout.AddDeleteControl();
btnDel.ButtonClickEvent += (sender, e) =>
{
RemoveTargets(bindObj, btnDel);
};
#endregion
}
switch (curBindType)
{
case 1:
btnTipText.Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType, MutilfunctionPanelMethod.curSwitchCount + MutilfunctionPanelMethod.curSocketCount + MutilfunctionPanelMethod.curLightFromRelayCount);
break;
case 2:
btnTipText.Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType, MutilfunctionPanelMethod.curSwitchCount + MutilfunctionPanelMethod.curSocketCount + MutilfunctionPanelMethod.curLightFromRelayCount);
break;
case 3:
btnTipText.Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType, MutilfunctionPanelMethod.curSwitchCount + MutilfunctionPanelMethod.curSocketCount + MutilfunctionPanelMethod.curLightFromRelayCount + MutilfunctionPanelMethod.curLightCount);
break;
default:
btnTipText.Text = MutilfunctionPanelMethod.MatchTypeBindTextTip(curBindType, curBindTypeList.Count);
break;
}
midVerticalScrolViewLayout.AdjustTableHeight(Application.GetRealHeight(23));
}
#endregion
#region 数据处理
///
/// 获取本地列表
///
void InitLocalDeviceList()
{
localDeviceList.Clear();
scList.Clear();
//设备
foreach (var dev in Shared.Common.LocalDevice.Current.listAllDevice)
{
localDeviceList.Add(dev);
}
//场景
scList = HdlSceneLogic.Current.GetAllRoomSceneList();
}
///
/// 初始化设备数据
///
void InitData()
{
System.Threading.Tasks.Task.Run(async () =>
{
try
{
//读取按键当前绑定目标 多功能面板目标总共需要读取本页的目标60个,3秒左右(3秒+200毫秒)
GetDeviceBindResponseAllData getBindList = null;
if (IsRead)
{
MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.Clear();
var epointList = new List();
for (int i = 2; i < 62; i++)
{
epointList.Add(i);
}
//读取上次没读全读目标
if (IsAgain)
{
epointList.Clear();
for (int i = oldReadEpoint; i < 62; i++)
{
epointList.Add(i);
}
}
foreach (var epoint in epointList)
{
curControlDev.DeviceEpoint = epoint;
getBindList = HdlDeviceBindLogic.Current.GetDeviceBindAsync(curControlDev);
if (getBindList != null && getBindList.getAllBindResponseData != null)
{
var bList = new List();
foreach (var dev in getBindList.getAllBindResponseData.BindList)
{
var curD = new BindListAllInfo();
curD.KeyMacAddr = curControlDev.DeviceAddr;
curD.KeyEpoint = epoint;
curD.BindCluster = dev.BindCluster;
curD.BindScenesId = dev.BindScenesId;
curD.BindMacAddr = dev.BindMacAddr;
curD.BindEpoint = dev.BindEpoint;
curD.ESName = dev.ESName;
curD.BindType = dev.BindType;
bList.Add(curD);
}
MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.Add(curControlDev.DeviceAddr + curControlDev.DeviceEpoint, bList);
oldReadEpoint++;
}
else
{
if (oldReadEpoint < 62)
{
IsAgain = true;
}
Application.RunOnMainThread(() =>
{
RefreshBindListUI();
midVerticalScrolViewLayout.EndHeaderRefreshing();
CommonPage.Loading.Hide();
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
});
break;
}
}
if (oldReadEpoint >= 61)
{
IsAgain = false;
oldReadEpoint = 2;
}
//获取所有类型的绑定目标个数
for (int i = 0; i < 7; i++)
{
curBindTypeList = MutilfunctionPanelMethod.GetMatchBindList(i);
}
Application.RunOnMainThread(() =>
{
RefreshBindListUI();
midVerticalScrolViewLayout.EndHeaderRefreshing();
CommonPage.Loading.Hide();
});
}
else
{
Application.RunOnMainThread(() =>
{
RefreshBindListUI();
CommonPage.Loading.Hide();
});
}
}
catch (Exception ex)
{
var mess = ex.Message;
}
});
}
///
/// 保存目标
///
///
void SaveTarget()
{
RemoveFromParent();
}
///
/// 删除多功能面板的目标
///
///
///
///
private void RemoveTargets(BindListAllInfo bindDevice, Button btnDel)
{
var delDevice = new DelDeviceBindData();
delDevice.DeviceAddr = bindDevice.KeyMacAddr;
delDevice.Epoint = bindDevice.KeyEpoint;
if (bindDevice.BindType == 0 || bindDevice.BindType == 1)
{
var removeDevice = new RemoveBindListObj();
removeDevice.BindCluster = bindDevice.BindCluster;
removeDevice.BindType = 0;
removeDevice.BindMacAddr = bindDevice.BindMacAddr;
removeDevice.BindEpoint = bindDevice.BindEpoint;
delDevice.RemoveBindList.Add(removeDevice);
//部分目标需要二次绑定第二种功能
switch (curBindType)
{
case 3:
var device = LocalDevice.Current.GetDevice(bindDevice.BindMacAddr, bindDevice.BindEpoint);
if (device != null)
{
if (device.Type == DeviceType.DimmableLight)
{
//灯光为调光时需要移除6,8
var removeDevice2 = new RemoveBindListObj();
removeDevice2.BindCluster = 6;
removeDevice2.BindType = 0;
removeDevice2.BindMacAddr = bindDevice.BindMacAddr;
removeDevice2.BindEpoint = bindDevice.BindEpoint;
delDevice.RemoveBindList.Add(removeDevice2);
}
}
break;
case 5:
//要移除空调:需要移除513,514
var removeDevice3 = new RemoveBindListObj();
removeDevice3.BindCluster = 514;
removeDevice3.BindType = 0;
removeDevice3.BindMacAddr = bindDevice.BindMacAddr;
removeDevice3.BindEpoint = bindDevice.BindEpoint;
delDevice.RemoveBindList.Add(removeDevice3);
break;
}
}
else if (bindDevice.BindType == 2)
{
var removeDevice = new RemoveBindListObj();
removeDevice.BindCluster = bindDevice.BindCluster;
removeDevice.BindType = 1;
removeDevice.BindScenesId = bindDevice.BindScenesId;
delDevice.RemoveBindList.Add(removeDevice);
}
System.Threading.Tasks.Task.Run(() =>
{
try
{
Application.RunOnMainThread(() =>
{
CommonPage.Loading.Start("");
});
var delResult = new DelDeviceBindResponseAllData();
delResult = HdlDeviceBindLogic.Current.DelDeviceBindAsync(delDevice);
if (delResult == null)
{
Application.RunOnMainThread(() =>
{
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 2 }.Show(CommonPage.Instance);
CommonPage.Loading.Hide();
});
return;
}
else
{
if (delResult.removeBindResultResponseData == null)
{
if (delResult.delDeviceBindResponseData != null)
{
foreach (var d in delResult.delDeviceBindResponseData.RemoveBindList)
{
if (d.Result == 0 || d.Result == 1)
{
if (MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.ContainsKey(bindDevice.KeyMacAddr + bindDevice.KeyEpoint))
{
MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.Remove(bindDevice.KeyMacAddr + bindDevice.KeyEpoint);
}
Application.RunOnMainThread(() =>
{
RefreshBindListUI();
CommonPage.Loading.Hide();
});
}
else
{
Application.RunOnMainThread(() =>
{
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 2 }.Show(CommonPage.Instance);
CommonPage.Loading.Hide();
});
return;
}
}
}
else
{
Application.RunOnMainThread(() =>
{
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 2 }.Show(CommonPage.Instance);
CommonPage.Loading.Hide();
});
return;
}
}
else
{
if (delResult.removeBindResultResponseData.Result == 0)
{
if (MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.ContainsKey(bindDevice.KeyMacAddr + bindDevice.KeyEpoint))
{
MutilfunctionPanelMethod.bindTargetsFromMutilfunctionPanelList.Remove(bindDevice.KeyMacAddr + bindDevice.KeyEpoint);
}
Application.RunOnMainThread(() =>
{
RefreshBindListUI();
CommonPage.Loading.Hide();
});
}
else
{
Application.RunOnMainThread(() =>
{
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(CommonPage.Instance);
CommonPage.Loading.Hide();
});
return;
}
}
}
}
catch { }
finally
{
Application.RunOnMainThread(() =>
{
CommonPage.Loading.Hide();
});
}
});
}
///
/// 匹配的类型列表
///
///
private List GetTypeList()
{
List textTypelist = new List { };
textTypelist.Add(Language.StringByID(R.MyInternationalizationString.scene));
textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId13));
textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId14));
textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId15));
textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId100));
textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId3600));
textTypelist.Add(Language.StringByID(R.MyInternationalizationString.uDeviceBelongId2310));
return textTypelist;
}
#endregion
#region 其他方法
///
/// 显示绑定设备线程是否已经开启
///
private bool isDeviceThreadStart = false;
///
/// 主题超时的线程是否开启
///
private bool isTopicTimeOutThreadStart = false;
///
/// 等待设备的回馈的超时时间(单位:百毫秒)
///
private int waitDeviceTimeOut = 20;
///
/// 网关ID
///
private string gatewayId = string.Empty;
///
/// 接收个数
///
private int countBind = 0;
///
/// 新上报的设备
///
private Dictionary dicPanelResInfo = new Dictionary();
///
/// 发送获取面板命令[通过DeviceAddr获取]
///
private void SendPanelCommand()
{
var jObject = new JObject { { "DeviceAddr", curControlDev.DeviceAddr }, { "Cluster_ID", 0 }, { "Command", 5009 } };
curControlDev.Gateway.Send(("SearchNewDevice"), jObject.ToString());
}
///
/// 检测设备绑定的主题
///
///
///
///
public bool CheckIsDeviceBindTopic(string topic)
{
if (topic == gatewayId + "Bind/GetDeviceLocalBind_Respon")
{
return true;
}
return false;
}
///
/// 处理面板绑定的设备,和端点没有关系
///
/// 主题
/// 上报数据
private void AdjustGatewayResultData(string topic, string resultData)
{
//接收绑定设备,开启接收绑定设备信息的线程(里面会等待三秒这样)
this.ReceiveSuccessFormThread();
var result = this.CheckIsDeviceBindTopic(topic);
if (result)
{
lock (dicPanelResInfo)
{
var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
var info = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
countBind = info.MaxNumItems;
if (info != null)
{
foreach (var bDev in info.BindList)
{
if (this.dicPanelResInfo.ContainsKey(bDev.ControllerEpoint) == false)
{
this.dicPanelResInfo[bDev.ControllerEpoint] = info;
}
}
}
if (this.dicPanelResInfo.Count == countBind)
{
//停止接收
curControlDev.Gateway.GwResDataAction -= this.AdjustGatewayResultData;
//刷新超时时间
this.waitDeviceTimeOut = -1;
}
else
{
//刷新超时时间
this.waitDeviceTimeOut = 20;
}
}
}
}
///
/// 开启接收绑定设备的超时线程
///
private void ReceiveSuccessFormThread()
{
if (this.isDeviceThreadStart == true)
{
//线程已经开启
return;
}
this.isDeviceThreadStart = true;
HdlThreadLogic.Current.RunThread(() =>
{
System.Console.WriteLine($"1AAAAA");
while (this.waitDeviceTimeOut >= 0)
{
//等待下一个回路
System.Threading.Thread.Sleep(100);
this.waitDeviceTimeOut--;
System.Console.WriteLine($"2AAAAA");
}
System.Console.WriteLine($"3AAAAA");
//停止接收
bindReceiveAction.Invoke();
curControlDev.Gateway.GwResDataAction -= this.AdjustGatewayResultData;
System.Console.WriteLine($"4AAAAA");
System.Threading.Thread.Sleep(200);
System.Console.WriteLine($"5AAAAA");
//目前就弄一个
Application.RunOnMainThread(() =>
{
if (this.dicPanelResInfo.Count < countBind)
{
//响应超时,请重新下拉刷新获取绑定信息
new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndReAccessNetwork), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
//停止接收
curControlDev.Gateway.GwResDataAction -= this.AdjustGatewayResultData;
}
System.Console.WriteLine($"6AAAAA");
});
});
}
#endregion
}
}