using System;
|
using System.Collections.Generic;
|
using System.Threading.Tasks;
|
using Shared.Common;
|
using Shared.Phone.UserView;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.UserCenter.Device
|
{
|
/// <summary>
|
/// 编辑设备的信息(这里修改的是MAC名,这个画面会更改MAC的物理名字)
|
/// </summary>
|
public class DeviceMacInfoEditorForm : UserCenterCommonForm, ZigBee.Common.IStatus
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 画面正常关闭的回调函数
|
/// </summary>
|
public Action<string> ActionFormClose = null;
|
/// <summary>
|
/// 设备对象
|
/// </summary>
|
private List<CommonDevice> listNewDevice = null;
|
/// <summary>
|
/// 设置窗帘维修模式Btn
|
/// </summary>
|
private SwichControl switchBtn = null;
|
/// <summary>
|
/// 获取得到了镜像信息
|
/// </summary>
|
private bool receiveImageInfo = false;
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 构造方法
|
/// </summary>
|
public DeviceMacInfoEditorForm()
|
{
|
ZbGateway.StatusList.Add(this);
|
}
|
|
/// <summary>
|
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
/// </summary>
|
/// <param name="listdevices">设备列表</param>
|
public void ShowForm(List<CommonDevice> listdevices)
|
{
|
this.listNewDevice = listdevices;
|
|
//设置标题信息
|
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uDeviceInfo));
|
|
//初始化删除设备的界面(右上)
|
this.InitDeleteDeviceForm();
|
|
new System.Threading.Thread(() =>
|
{
|
//重新获取硬件信息
|
this.RefreshHardFirmwareInfo();
|
Application.RunOnMainThread(() =>
|
{
|
//初始化中部控件
|
this.InitMiddleFrame();
|
});
|
})
|
{ IsBackground = true }.Start();
|
}
|
|
/// <summary>
|
/// 初始化中部控件
|
/// </summary>
|
private void InitMiddleFrame()
|
{
|
this.bodyFrameLayout.RemoveAll();
|
|
//设备图片
|
var btnpictrue = new PicViewControl(510, 320);
|
btnpictrue.Gravity = Gravity.CenterHorizontal;
|
btnpictrue.Y = Application.GetRealHeight(100);
|
Common.LocalDevice.Current.SetRealDeviceIconToControl(btnpictrue, listNewDevice);
|
bodyFrameLayout.AddChidren(btnpictrue);
|
|
var listview = new VerticalScrolViewLayout();
|
listview.Y = btnpictrue.Bottom + Application.GetRealHeight(100);
|
listview.Height = bodyFrameLayout.Height - btnpictrue.Bottom - Application.GetRealHeight(100);
|
bodyFrameLayout.AddChidren(listview);
|
|
//生产商名称
|
var row = new RowLayout();
|
row.Height = ControlCommonResourse.ListViewRowHeight;
|
listview.AddChidren(row);
|
var btnManuView = new RowTopGrayView(false);
|
btnManuView.TextID = R.MyInternationalizationString.uManufacturerName;
|
row.AddChidren(btnManuView);
|
var btnManu = new RowBottomBlackView(false);
|
btnManu.Text = listNewDevice[0].ManufacturerName;
|
if (string.IsNullOrEmpty(btnManu.Text) == true)
|
{
|
if (listNewDevice[0].DriveCode > 0)
|
{
|
//虚拟设备固定使用HDL
|
listNewDevice[0].ManufacturerName = "HDL";
|
listNewDevice[0].ReSave();
|
btnManu.Text = "HDL";
|
}
|
}
|
row.AddChidren(btnManu);
|
|
//设备型号
|
row = new RowLayout();
|
row.Height = ControlCommonResourse.ListViewRowHeight;
|
listview.AddChidren(row);
|
var btnModelIdView = new RowTopGrayView(false);
|
btnModelIdView.TextID = R.MyInternationalizationString.uModelIdentifier;
|
row.AddChidren(btnModelIdView);
|
var btnModelId = new RowBottomBlackView(false);
|
btnModelId.Text = listNewDevice[0].ModelIdentifier;
|
row.AddChidren(btnModelId);
|
|
//序列号
|
row = new RowLayout();
|
row.Height = ControlCommonResourse.ListViewRowHeight;
|
listview.AddChidren(row);
|
var btnSerialView = new RowTopGrayView(false);
|
btnSerialView.TextID = R.MyInternationalizationString.uSerialNumber;
|
row.AddChidren(btnSerialView);
|
var btnSerial = new RowBottomBlackView(false);
|
btnSerial.Text = listNewDevice[0].SerialNumber;
|
if (string.IsNullOrEmpty(btnSerial.Text) == true)
|
{
|
btnSerial.Text = listNewDevice[0].DeviceAddr;
|
}
|
row.AddChidren(btnSerial);
|
|
//产品名称
|
string caption = Language.StringByID(R.MyInternationalizationString.uProductName);
|
string nameValue = Common.LocalDevice.Current.GetDeviceMacName(listNewDevice[0]);
|
var btnDeviceView = new EditorNameValueRow(caption, nameValue);
|
listview.AddChidren(btnDeviceView);
|
btnDeviceView.InitControl();
|
//请输入产品名称
|
btnDeviceView.SetEmptyNameTip(Language.StringByID(R.MyInternationalizationString.uProductNameMastInput));
|
//编辑产品名称
|
btnDeviceView.SetDialogTitle(Language.StringByID(R.MyInternationalizationString.uEditorProductName));
|
btnDeviceView.ActionNameChangedEvent += (deviceName) =>
|
{
|
//设备重命名然后打开新的画面
|
this.DeviceReName(deviceName);
|
};
|
|
//只有是河东的设备的时候
|
if (Common.LocalDevice.Current.IsHdlDevice(listNewDevice[0]) == true)
|
{
|
//添加【背光设置】行
|
this.AddBackLightRow(listview);
|
|
//添加 【方向与限位】行
|
this.AddDirectionLimitRow(listview);
|
|
//添加 【维护模式】行
|
this.AddMaintenanceModeRow(listview);
|
|
//添加【固件信息】行
|
this.AddFirmwareVersionRow(listview);
|
}
|
}
|
|
#endregion
|
|
#region ■ 硬件信息___________________________
|
|
/// <summary>
|
/// 重新获取硬件信息
|
/// </summary>
|
private void RefreshHardFirmwareInfo()
|
{
|
//打开进度条
|
this.ShowProgressBar();
|
|
bool isReceive = false;
|
//重新获取硬件信息
|
Common.LocalDevice.Current.SetAllHardFirmwareInfoToDevice(listNewDevice[0], true, (device, reportData) =>
|
{
|
for (int i = 1; i < listNewDevice.Count; i++)
|
{
|
//全部回路的信息都是一致的
|
DeviceAttributeLogic.Current.SetHardFirmwareInfo(device.DeviceStatusReport, listNewDevice[i]);
|
listNewDevice[i].ReSave();
|
}
|
isReceive = true;
|
});
|
int count = 20;
|
while (isReceive == false && count > 0)
|
{
|
//等待设备镜像的反馈
|
System.Threading.Thread.Sleep(100);
|
count--;
|
}
|
if (count <= 0)
|
{
|
//移除获取设备硬件信息的监听线程
|
Common.LocalDevice.Current.RemoveDeviceHardInfoThread(listNewDevice[0]);
|
}
|
//关闭进度条
|
this.CloseProgressBar();
|
}
|
|
#endregion
|
|
#region ■ 背光设置___________________________
|
|
/// <summary>
|
/// 添加【背光设置】行
|
/// </summary>
|
/// <param name="listview"></param>
|
private void AddBackLightRow(VerticalScrolViewLayout listview)
|
{
|
bool canAddRow = false;
|
foreach (var device in listNewDevice)
|
{
|
if (device.Type == DeviceType.OnOffSwitch)
|
{
|
canAddRow = true;
|
break;
|
}
|
}
|
if (canAddRow == false)
|
{
|
//必须有一路回路是OnOffSwitch才行
|
return;
|
}
|
|
//获取这一堆设备时属于什么类型的
|
var myDeviceType = Common.LocalDevice.Current.GetMyDeviceEnumInfo(listNewDevice);
|
//如果是控制面板
|
if (myDeviceType.BeloneType == DeviceBeloneType.A按键面板 || myDeviceType.BeloneType == DeviceBeloneType.A调光器)
|
{
|
//背光设置
|
var statuRowLight = new StatuRowLayout(listview);
|
|
var btnBackLight = new RowCenterView(false);
|
btnBackLight.TextID = R.MyInternationalizationString.uBackLightSettion;
|
statuRowLight.AddChidren(btnBackLight);
|
//背光设置向右的图标
|
statuRowLight.AddRightIconControl();
|
statuRowLight.MouseUpEvent += (sender, e) =>
|
{
|
var form = new DevicePanel.PanelBackLightSettionForm();
|
this.AddForm(form, listNewDevice);
|
};
|
}
|
}
|
|
#endregion
|
|
#region ■ 固件信息___________________________
|
|
/// <summary>
|
/// 添加【固件信息】行
|
/// </summary>
|
/// <param name="listview"></param>
|
private void AddFirmwareVersionRow(VerticalScrolViewLayout listview)
|
{
|
//拥有200端口这个东西的时候,才会显示这一行
|
var oTADevice = Common.LocalDevice.Current.GetOTADevice(listNewDevice[0].DeviceAddr);
|
if (oTADevice == null)
|
{
|
return;
|
}
|
|
var statuRow = new StatuRowLayout(listview);
|
//固件信息
|
var btnUpview = new RowCenterView(false);
|
btnUpview.TextID = R.MyInternationalizationString.uFirmwareInformation;
|
statuRow.AddChidren(btnUpview);
|
//提示有新版本
|
var btnNewVersion = new RowNewVersionTipView();
|
btnNewVersion.Visible = false;
|
statuRow.AddChidren(btnNewVersion);
|
|
statuRow.AddRightIconControl();
|
|
statuRow.MouseUpEvent += (sender, e) =>
|
{
|
btnNewVersion.Visible = false;
|
var form = new DeviceFirmwareInfoForm();
|
this.AddForm(form, listNewDevice);
|
};
|
|
//设置设备的版本信息
|
this.SetDeviceVersionInfo(btnNewVersion, oTADevice);
|
}
|
|
/// <summary>
|
/// 设置设备的版本信息
|
/// </summary>
|
/// <param name="btnNewVersion">有新版本的提示控件</param>
|
/// <param name="oTADevice">ota设备</param>
|
private void SetDeviceVersionInfo(RowNewVersionTipView btnNewVersion, OTADevice oTADevice)
|
{
|
new System.Threading.Thread(async () =>
|
{
|
//设置设备全部的镜像信息
|
Common.LocalDevice.Current.SetAllImageInfoToOtaDevice(oTADevice, this.OtaImageInfoActionBack);
|
int count = 5;
|
while (this.receiveImageInfo == false && count > 0)
|
{
|
//等待设备镜像的反馈
|
await Task.Delay(300);
|
count--;
|
}
|
//变量还原
|
this.receiveImageInfo = false;
|
|
oTADevice = Common.LocalDevice.Current.GetOTADevice(listNewDevice[0].DeviceAddr);
|
//添加升级固件信息(成不成功都无所谓)
|
var result = await FirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.ZigbeeDevice, oTADevice.HwVersion.ToString(), oTADevice.ImgTypeId.ToString());
|
|
//获取设备最新版本
|
var deviceFirmware = FirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.ZigbeeDevice,
|
oTADevice.HwVersion.ToString(),
|
oTADevice.ImgTypeId.ToString(),
|
oTADevice.ImgVersion);
|
|
if (deviceFirmware != null)
|
{
|
if (deviceFirmware.FirmwareVersion > oTADevice.ImgVersion)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
btnNewVersion.Visible = true;
|
});
|
}
|
}
|
})
|
{ IsBackground = true }.Start();
|
}
|
|
/// <summary>
|
/// 获取到了OTA镜像信息回调(100%特定回调)
|
/// </summary>
|
/// <param name="device"></param>
|
/// <param name="reportData"></param>
|
private void OtaImageInfoActionBack(CommonDevice device, CommonDevice.DeviceStatusReportData reportData)
|
{
|
this.receiveImageInfo = true;
|
}
|
|
#endregion
|
|
#region ■ 方向限位___________________________
|
|
/// <summary>
|
///添加 【方向限位】行
|
/// </summary>
|
/// <param name="listview">Listview.</param>
|
private void AddDirectionLimitRow(VerticalScrolViewLayout listview)
|
{
|
bool canAddRow = false;
|
foreach (var device in listNewDevice)
|
{
|
if (device.Type == DeviceType.WindowCoveringDevice)
|
{
|
canAddRow = true;
|
break;
|
}
|
}
|
if (canAddRow == false)
|
{
|
//必须有一路回路是WindowCoveringDevice才行
|
return;
|
}
|
|
//获取这一堆设备时属于什么类型的
|
var myDeviceType = Common.LocalDevice.Current.GetMyDeviceEnumInfo(listNewDevice);
|
//如果是窗帘
|
if (myDeviceType.BeloneType == DeviceBeloneType.A窗帘)
|
{
|
//方向与限位设置
|
var directionLimitRow = new StatuRowLayout(listview);
|
|
var directionLimitBtn = new RowCenterView(false);
|
directionLimitBtn.TextID = R.MyInternationalizationString.DirectionLimit;
|
directionLimitRow.AddChidren(directionLimitBtn);
|
//方向与限位设置向右的图标
|
var btnLightRight = new RowRightIconView();
|
directionLimitRow.AddChidren(btnLightRight);
|
directionLimitRow.MouseUpEvent += (sender, e) =>
|
{
|
var form = new RollerShadeDirectionLimitSettingForm();
|
this.AddForm(form, listNewDevice);
|
};
|
}
|
}
|
|
#endregion
|
|
#region ■ 维护模式___________________________
|
|
/// <summary>
|
/// 添加 【维护模式】行
|
/// </summary>
|
/// <param name="listview">Listview.</param>
|
/// <param name="statu">If set to <c>true</c> statu.</param>
|
private void AddMaintenanceModeRow(VerticalScrolViewLayout listview, bool statu = false)
|
{
|
bool canAddRow = false;
|
foreach (var device in listNewDevice)
|
{
|
if (device.Type == DeviceType.WindowCoveringDevice)
|
{
|
var rollershade = device as Rollershade;
|
canAddRow = true;
|
break;
|
}
|
}
|
if (canAddRow == false)
|
{
|
//必须有一路回路是WindowCoveringDevice才行
|
return;
|
}
|
//获取这一堆设备时属于什么类型的
|
var myDeviceType = Common.LocalDevice.Current.GetMyDeviceEnumInfo(listNewDevice);
|
//如果是窗帘
|
if (myDeviceType.BeloneType == DeviceBeloneType.A窗帘)
|
{
|
//窗帘取第一回路
|
var rollerShade = listNewDevice[0] as Rollershade;
|
//维护模式 设置
|
var maintenanceModeRow = new RowLayout
|
{
|
Height = ControlCommonResourse.ListViewRowHeight
|
};
|
listview.AddChidren(maintenanceModeRow);
|
|
//不上非远程
|
if (rollerShade.Gateway == null)
|
{
|
return;
|
}
|
//if (rollerShade.Gateway.IsVirtual)
|
//{
|
UserHomeView.ReadStatus(rollerShade, () =>
|
{
|
rollerShade.ReadCurtainDirectionAndMode();
|
},3);
|
//}
|
//else
|
//{
|
// //防止短时间内多次读取
|
// if ((DateTime.Now - rollerShade.LastDateTime).TotalSeconds > CommonPage.ReadDeviceStatuSpan)
|
// {
|
// rollerShade.ReadCurtainDirectionAndMode();
|
// }
|
//}
|
|
var maintenanceModeBtn = new RowTopGrayView(false);
|
maintenanceModeBtn.TextID = R.MyInternationalizationString.MaintenanceMode;
|
maintenanceModeRow.AddChidren(maintenanceModeBtn);
|
|
var Start_ban_switchBtn = new RowBottomBlackView(false);
|
Start_ban_switchBtn.TextID = R.MyInternationalizationString.Start_Forbid_Hand_Pull_Switch;
|
maintenanceModeRow.AddChidren(Start_ban_switchBtn);
|
|
switchBtn = new SwichControl();
|
switchBtn.Tag = rollerShade;
|
maintenanceModeRow.AddChidren(switchBtn);
|
switchBtn.IsSelected = rollerShade.WcdCurrentMaintenance;
|
switchBtn.MouseUpEventHandler += async (sender, e) =>
|
{
|
try
|
{
|
CommonPage.Loading.Start();
|
switchBtn.IsSelected = !switchBtn.IsSelected;
|
var setWritableValueResponAllData = await rollerShade.SetCurtianMaintenanceAsync(switchBtn.IsSelected);
|
|
await System.Threading.Tasks.Task.Delay(5000);
|
|
if (setWritableValueResponAllData == null || setWritableValueResponAllData.setWritableValueResponData == null)
|
{
|
Shared.Common.CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.ConnectGWFail);
|
switchBtn.IsSelected = false;
|
return;
|
}
|
var status = setWritableValueResponAllData.setWritableValueResponData.Status;
|
//以后补充提示
|
//0:配置成功(若配置成功,下面的AttributeId字段不存在)
|
//34:不支持该属性
|
//135:无效的属性值
|
//141:无效的数据类型
|
if (status == 0)
|
{
|
System.Console.WriteLine("切换维护模式成功");
|
//DeviceUI.ShowStatuTip(R.MyInternationalizationString.Success);
|
}
|
else
|
{
|
Shared.Common.CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.ChangeMaintenanceMode_Fail);
|
switchBtn.IsSelected = false;
|
}
|
}
|
catch(Exception ex)
|
{
|
System.Console.WriteLine("设置维护模式失败"+ex);
|
}
|
finally
|
{
|
CommonPage.Loading.Hide();
|
}
|
|
};
|
}
|
}
|
|
#endregion
|
|
#region ■ 修改名字___________________________
|
|
/// <summary>
|
/// 设备重命名
|
/// </summary>
|
/// <param name="i_deviceName">deviceName.</param>
|
private async void DeviceReName(string i_deviceName)
|
{
|
//修改MAC名
|
string deviceName = i_deviceName.Trim();
|
var result = await Common.LocalDevice.Current.ReMacName(this.listNewDevice, deviceName);
|
if (result == false)
|
{
|
return;
|
}
|
|
Application.RunOnMainThread(() =>
|
{
|
if (ActionFormClose != null)
|
{
|
this.ActionFormClose(deviceName);
|
}
|
});
|
}
|
|
#endregion
|
|
#region ■ 删除界面___________________________
|
|
/// <summary>
|
/// 初始化删除设备的界面
|
/// </summary>
|
private void InitDeleteDeviceForm()
|
{
|
var btnIcon = new TopLayoutMostRightView();
|
btnIcon.UnSelectedImagePath = "Item/More.png";
|
btnIcon.SelectedImagePath = "Item/MoreSelected.png";
|
topFrameLayout.AddChidren(btnIcon);
|
btnIcon.MouseUpEventHandler += ((sender, e) =>
|
{
|
//显示删除设备的弹窗界面
|
this.ShowDeleteDeviceDialogForm();
|
});
|
}
|
|
/// <summary>
|
/// 显示删除设备的弹窗界面
|
/// </summary>
|
private void ShowDeleteDeviceDialogForm()
|
{
|
var frame = new TopRightMenuControl(this, 1);
|
//删除设备
|
string deviceMenu = Language.StringByID(R.MyInternationalizationString.uDeleteDevice);
|
frame.AddRowMenu(deviceMenu, (obj) =>
|
{
|
//确认要删除该设备?{0}(删除设备后,绑定目标将消失)
|
string msg = Language.StringByID(R.MyInternationalizationString.uDeleteDeviceMsg);
|
if (msg.Contains("{0}") == true)
|
{
|
msg = string.Format(msg, "\r\n");
|
}
|
this.ShowConfirmMsg(msg, "DoDeleteDevice");
|
});
|
}
|
|
/// <summary>
|
/// 删除指定设备
|
/// </summary>
|
public async void DoDeleteDevice()
|
{
|
//开启进度条
|
this.ShowProgressBar();
|
//删除设备
|
bool result = await Common.LocalDevice.Current.DeleteDevice(listNewDevice);
|
|
this.CloseProgressBar();
|
|
if (result == false)
|
{
|
return;
|
}
|
|
Application.RunOnMainThread(() =>
|
{
|
//关闭界面
|
this.CloseForm();
|
//移除设备列表界面指定的设备
|
this.LoadFormMethodByName("DeviceManagementMainForm", "RemoveDeviceFromMemory", listNewDevice);
|
});
|
}
|
#endregion
|
|
#region ■ 关闭界面___________________________
|
|
/// <summary>
|
/// 画面关闭
|
/// </summary>
|
/// <param name="isCloseForm">是否关闭界面,false的时候,只会调用关闭函数里面的附加功能</param>
|
public override void CloseForm(bool isCloseForm = true)
|
{
|
ZbGateway.StatusList.Remove(this);
|
base.CloseForm(isCloseForm);
|
}
|
|
#endregion
|
|
#region ■ 设备接口___________________________
|
/// <summary>
|
/// Changed the specified common.
|
/// </summary>
|
/// <param name="common">Common.</param>
|
public void Changed(CommonDevice common)
|
{
|
}
|
/// <summary>
|
/// 设备状态更新接口
|
/// <para>type:如果为 DeviceInComingRespon:设备新上报</para>
|
/// <para>type:如果为 IASInfoReport:RemoveDeviceRespon</para>
|
/// <para>type:如果为 DeviceStatusReport:设备上报</para>
|
/// <para>type:如果为 IASInfoReport:IAS安防信息上报</para>
|
/// <para>type:如果为 OnlineStatusChange: 设备在线状态更新</para>
|
/// </summary>
|
/// <param name="common">Common.</param>
|
/// <param name="typeTag">Type tag.</param>
|
public void DeviceInfoChange(CommonDevice common, string typeTag)
|
{
|
if (typeTag == "DeviceStatusReport")
|
{
|
Application.RunOnMainThread(() =>
|
{
|
try
|
{
|
if (switchBtn == null)
|
{
|
return;
|
}
|
var device = switchBtn.Tag as CommonDevice;
|
|
//是否为当前设备
|
if (device.DeviceEpoint != common.DeviceEpoint || device.DeviceAddr != common.DeviceAddr)
|
{
|
return;
|
}
|
if ((common as Rollershade).DeviceStatusReport.CluterID != 258)
|
{
|
return;
|
}
|
var rollerShade = device as Rollershade;
|
rollerShade.DeviceStatusReport = (common as Rollershade).DeviceStatusReport;
|
|
var attriButeList = rollerShade.DeviceStatusReport.AttriBute;
|
if(attriButeList==null)
|
{
|
return;
|
}
|
foreach (var attriBute in attriButeList)
|
{
|
//维护模式
|
if (attriBute.AttributeId == 23)
|
{
|
if (0 < (attriBute.AttriButeData & 0x04))
|
{
|
switchBtn.IsSelected = rollerShade.WcdCurrentMaintenance = true;
|
}
|
else
|
{
|
switchBtn.IsSelected = rollerShade.WcdCurrentMaintenance = false;
|
}
|
rollerShade.LastDateTime = DateTime.Now;
|
}
|
}
|
|
}
|
catch (Exception ex)
|
{
|
System.Console.WriteLine($"Error:{ex.Message}");
|
}
|
});
|
}
|
}
|
/// <summary>
|
/// Changeds the IL ogic status.
|
/// </summary>
|
/// <param name="logic">Logic.</param>
|
public void ChangedILogicStatus(ZigBee.Device.Logic logic)
|
{
|
}
|
/// <summary>
|
/// Changeds the IS cene status.
|
/// </summary>
|
/// <param name="scene">Scene.</param>
|
public void ChangedISceneStatus(Scene scene)
|
{
|
}
|
#endregion
|
}
|
}
|