using System;
|
using System.Collections.Generic;
|
using System.Threading;
|
using Shared.SimpleControl.Phone;
|
|
namespace Shared.SimpleControl.Pad
|
{
|
/// <summary>
|
/// 无线网关数据设置界面
|
/// </summary>
|
public class SystemWirelessGateway
|
{
|
/// <summary>
|
/// 更新无线网关数据
|
/// </summary>
|
void UpdateOnePorWirelessFR (OnePortWirelessFR onePortWirelessFR)
|
{
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
Application.RunOnMainThread (() => {
|
System.Console.WriteLine (System.Threading.Thread.CurrentThread.ManagedThreadId);
|
MainPage.Loading.Start ("Sending...");
|
});
|
System.Console.WriteLine ("0000" + System.Threading.Thread.CurrentThread.ManagedThreadId);
|
byte [] bytes = new byte [78];
|
bytes [0] = onePortWirelessFR.BigClass;
|
bytes [1] = onePortWirelessFR.MinClass;
|
bytes [2] = onePortWirelessFR.ChNumberCount;
|
string [] mac = onePortWirelessFR.MAC.Split ('.');
|
for (int i = 0; i < mac.Length; i++)
|
bytes [i + 3] = Convert.ToByte (mac [i], 16);
|
//Remark需要解码
|
byte [] ddd = new byte [20];
|
byte [] ddd2 = CommonPage.MyEncodingGB2312.GetBytes (onePortWirelessFR.Name);
|
Array.Copy (ddd2, 0, ddd, 0, 20 < ddd2.Length ? 20 : ddd2.Length);
|
Array.Copy (ddd, 0, bytes, 11, 20);
|
string [] ipAddress = onePortWirelessFR.IPAddress.Split ('.');
|
for (int i = 0; i < ipAddress.Length; i++)
|
bytes [i + 31] = byte.Parse (ipAddress [i]);
|
string [] r = onePortWirelessFR.RouteIPAddress.Split ('.');
|
for (int i = 0; i < r.Length; i++)
|
bytes [i + 35] = byte.Parse (r [i]);
|
string [] ipMac = onePortWirelessFR.IPMAC.Split ('.');
|
//ipMAC前三位HDL 需要特殊处理
|
bytes [0 + 39] = (byte)(ipMac [0].ToCharArray () [0]);
|
bytes [1 + 39] = (byte)(ipMac [1].ToCharArray () [0]);
|
bytes [2 + 39] = (byte)(ipMac [2].ToCharArray () [0]);
|
bytes [3 + 39] = byte.Parse (ipMac [3]);
|
bytes [4 + 39] = byte.Parse (ipMac [4]);
|
bytes [5 + 39] = byte.Parse (ipMac [5]);
|
string [] subnetMask = onePortWirelessFR.SubnetMask.Split ('.');
|
for (int i = 0; i < subnetMask.Length; i++)
|
bytes [i + 45] = byte.Parse (subnetMask [i]);
|
bytes [49] = onePortWirelessFR.DHCP == true ? (byte)1 : (byte)0;
|
bytes [50] = onePortWirelessFR.SubnetID;
|
bytes [51] = onePortWirelessFR.EncryptionFlag;
|
byte [] pbyte = new byte [8];
|
byte [] pddd = CommonPage.MyEncodingGB2312.GetBytes (onePortWirelessFR.Password);
|
Array.Copy (pddd, 0, ddd, 0, 8 < pddd.Length ? 8 : pddd.Length);
|
Array.Copy (pbyte, 0, bytes, 52, 8);
|
bytes [60] = onePortWirelessFR.WirelessBand;
|
bytes [61] = onePortWirelessFR.WirelessChannel;
|
byte [] wbyte = new byte [16];
|
byte [] w2 = CommonPage.MyEncodingGB2312.GetBytes (onePortWirelessFR.WirelessPassword);
|
Array.Copy (w2, 0, wbyte, 0, 16 < w2.Length ? 16 : w2.Length);
|
Array.Copy (wbyte, 0, bytes, 62, 16);
|
|
var datass = Control.ControlBytesSendHasReturn (Command.SetGateway,
|
onePortWirelessFR.SubnetID,
|
onePortWirelessFR.DeviceID,
|
bytes);
|
if (datass == null) {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
|
Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
} else {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
IO.FileUtils.SaveEquipmentMessage (onePortWirelessFR);
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
|
Language.StringByID (R.MyInternationalizationString.ThePerationWasSuccessful),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
}
|
} catch {
|
} finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
}
|
|
public void ShowWirelessGateway (OnePortWirelessFR gatewayDevice)
|
{
|
MainPage.Loading.Start ();
|
try {
|
if (!CommonPage.IsRemote) {//判断是否为远程连接
|
CommonPage.FindGatewayChilrenIPAddress = gatewayDevice.IPAddress;
|
}
|
|
System.Threading.Tasks.Task.Run (() => {
|
Application.RunOnMainThread (() => {
|
#region ---top---
|
SystemMiddle.SecondScrolView.RemoveAll ();
|
SystemMiddle.ThirdScrolView.RemoveAll ();
|
Button backButton = new Button () {
|
Height = Application.GetRealHeight (98),
|
Width = Application.GetRealWidth (85),
|
UnSelectedImagePath = "Item/Wireless.png",
|
SelectedImagePath = "Item/WirelessSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
SystemMiddle.SecondScrolView.TitleView.AddChidren (backButton);
|
string deviceRemark = gatewayDevice.Name.ToString ();
|
EditText textButton = new EditText () {
|
X = Application.GetRealWidth (95),
|
Height = Application.GetRealHeight (50),
|
Width = Application.GetRealWidth (380),
|
Gravity = Gravity.CenterVertical,
|
Text = deviceRemark,
|
SelectedBackgroundColor = 0xFF000000,
|
UnSelectedImagePath = "Item/Transparent.png",
|
Enable = false,
|
};
|
SystemMiddle.SecondScrolView.TitleView.AddChidren (textButton);
|
|
Button editor = new Button () {
|
Height = Application.GetRealHeight (90),
|
Width = Application.GetRealWidth (70),
|
UnSelectedImagePath = "Item/Editor.png",
|
SelectedImagePath = "Item/EditorSelected.png",
|
Gravity = Gravity.CenterVertical,
|
X = textButton.Right + Application.GetRealWidth (10),
|
};
|
SystemMiddle.SecondScrolView.TitleView.AddChidren (editor);
|
editor.MouseUpEventHandler += (sender, e) => {//---------------修改Remark----------------
|
if (editor.IsSelected == true) {
|
MainPage.Loading.Start ();
|
gatewayDevice.Name = textButton.Text.Trim ();
|
editor.IsSelected = textButton.IsSelected = textButton.Enable = false;
|
|
CommonPage.UpdateRemark (gatewayDevice.SubnetID, gatewayDevice.DeviceID, gatewayDevice.Name);
|
IO.FileUtils.SaveEquipmentMessage (gatewayDevice);
|
editor.IsSelected = false;
|
textButton.Enable = false;
|
textButton.IsSelected = false;
|
MainPage.Loading.Hide ();
|
System.Console.WriteLine ("OnePortWirelessFR Remark Update");
|
} else {
|
textButton.Enable = true;
|
textButton.IsSelected = true;
|
editor.IsSelected = true;
|
}
|
};
|
|
Button btnRefresh = new Button () {
|
X = editor.Right + Application.GetRealWidth (10),
|
Height = Application.GetMinRealAverage (66),
|
Width = Application.GetMinRealAverage (66),
|
UnSelectedImagePath = "Item/Refresh.png",
|
SelectedImagePath = "Item/RefreshOn.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
SystemMiddle.SecondScrolView.TitleView.AddChidren (btnRefresh);
|
#endregion
|
|
#region GatewayID
|
FrameLayout frameLayoutGatewayID = new FrameLayout () {
|
Height = Application.GetRealHeight (131),
|
Width = LayoutParams.MatchParent,
|
};
|
SystemMiddle.SecondScrolView.AddChidren (frameLayoutGatewayID);
|
|
Button gatewayIDText = new Button () {
|
X = Application.GetRealWidth (15),
|
Height = Application.GetRealHeight (66),
|
Width = Application.GetRealWidth (66),
|
UnSelectedImagePath = "Item/Wireless.png",
|
SelectedImagePath = "Item/WirelessSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
frameLayoutGatewayID.AddChidren (gatewayIDText);
|
Button gatewayIDName = new Button () {
|
X = Application.GetRealWidth (11) + gatewayIDText.Right,
|
Height = Application.GetRealHeight (41),
|
Width = Application.GetRealWidth (150),
|
TextID = R.MyInternationalizationString.GatewayID,
|
Gravity = Gravity.CenterVertical,
|
TextAlignment = TextAlignment.CenterLeft,
|
};
|
frameLayoutGatewayID.AddChidren (gatewayIDName);
|
EditText etGatewayID = new EditText () {
|
Height = Application.GetRealHeight (42),
|
Width = Application.GetRealWidth (62),
|
X = gatewayIDName.Right,
|
Gravity = Gravity.CenterVertical,
|
TextAlignment = TextAlignment.Center,
|
Text = gatewayDevice.SubnetID.ToString (),
|
SelectedBackgroundColor = 0xFF000000,
|
UnSelectedImagePath = "Item/Transparent.png",
|
Enable = false,
|
};
|
frameLayoutGatewayID.AddChidren (etGatewayID);
|
|
Button gatewayIDEdit = new Button () {
|
Height = Application.GetRealHeight (90),
|
Width = Application.GetRealWidth (70),
|
UnSelectedImagePath = "Item/Editor.png",
|
SelectedImagePath = "Item/EditorSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
gatewayIDEdit.X = SystemMiddle.SecondScrolView.TitleView.Width - gatewayIDEdit.Width - Application.GetRealWidth (30);
|
#region 更改网关设备号
|
//byte[] macAddress = Control.ControlBytesSendHasReturn(Command.ReadDeviceMac,onePortWirelessFR.SubnetID,onePortWirelessFR.DeviceID,new byte[]{});
|
gatewayIDEdit.MouseUpEventHandler += (sender, e) => {
|
string [] macAddress = gatewayDevice.MAC.Split ('.');
|
if (etGatewayID.Enable) {
|
etGatewayID.Enable = etGatewayID.IsSelected = false;
|
byte [] Musics = new byte [10];
|
for (int i = 0; i < macAddress.Length; i++) {
|
Musics [i] = Convert.ToByte (macAddress [i], 16);
|
}
|
try {
|
Musics [8] = Convert.ToByte (Convert.ToInt32 (etGatewayID.Text.Trim ()));
|
if (Musics [8] < 0 || Musics [8] > 255) {
|
throw new Exception ();
|
}
|
} catch {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipPleaseEnterTheCorrectData), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
return;
|
}
|
Control.ControlBytesSend (Command.SetDeviceSubnetID, gatewayDevice.SubnetID, gatewayDevice.DeviceID, Musics);
|
foreach (string ss in IO.FileUtils.ReadFiles ()) {
|
if (ss.Contains ("Equipment_")) {
|
if (ss.Contains ("_" + Musics [8].ToString () + "_") || ss.Contains ("_" + gatewayDevice.SubnetID.ToString () + "_")) {
|
IO.FileUtils.DeleteFile (ss);
|
}
|
}
|
}
|
gatewayDevice.SubnetID = Musics [8];
|
UpdateOnePorWirelessFR (gatewayDevice);
|
} else {
|
etGatewayID.IsSelected = etGatewayID.Enable = true;
|
}
|
};
|
#endregion
|
frameLayoutGatewayID.AddChidren (gatewayIDEdit);
|
|
Button btnNul = new Button () {
|
Y = Application.GetRealHeight (131) - 2,
|
Height = 1,
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
frameLayoutGatewayID.AddChidren (btnNul);
|
Button btnNull = new Button () {
|
Y = Application.GetRealHeight (131) - 1,
|
Height = 1,
|
BackgroundColor = 0xFF2f2f2f,
|
};
|
frameLayoutGatewayID.AddChidren (btnNull);
|
#endregion
|
|
#region--------------NetWork----------------------
|
FrameLayout flNetWorkTop = new FrameLayout () {
|
Height = Application.GetRealHeight (131),
|
Width = LayoutParams.MatchParent,
|
};
|
SystemMiddle.SecondScrolView.AddChidren (flNetWorkTop);
|
|
Button netParameterSeleted = new Button () {
|
X = Application.GetRealWidth (15),
|
Height = Application.GetRealHeight (66),
|
Width = Application.GetRealWidth (66),
|
UnSelectedImagePath = "Item/NetParameter.png",
|
SelectedImagePath = "Item/NetParameterSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
flNetWorkTop.AddChidren (netParameterSeleted);
|
Button textButton1 = new Button () {
|
X = Application.GetRealWidth (11) + netParameterSeleted.Right,
|
Height = Application.GetRealHeight (41),
|
Width = Application.GetRealWidth (300),
|
TextID = R.MyInternationalizationString.NetwordParameters,
|
Gravity = Gravity.CenterVertical,
|
TextAlignment = TextAlignment.CenterLeft,
|
};
|
flNetWorkTop.AddChidren (textButton1);
|
Button btnNetWorkHelp = new Button () {
|
Height = Application.GetMinRealAverage (98),
|
Width = Application.GetMinRealAverage (76),
|
UnSelectedImagePath = "Item/Help.png",
|
SelectedImagePath = "Item/HelpSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
btnNetWorkHelp.X = SystemMiddle.SecondScrolView.TitleView.Width - btnNetWorkHelp.Width - Application.GetRealWidth (30);
|
btnNetWorkHelp.MouseUpEventHandler += (sender, e) => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.HelpNetWork), Direction = AMPopTipDirection.Down, CloseTime = 4 }.Show ((View)sender);
|
};
|
flNetWorkTop.AddChidren (btnNetWorkHelp);
|
|
|
Button btnNul2 = new Button () {
|
Y = Application.GetRealHeight (131) - 2,
|
Height = 1,
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
flNetWorkTop.AddChidren (btnNul2);
|
Button btnNull2 = new Button () {
|
Y = Application.GetRealHeight (131) - 1,
|
Height = 1,
|
BackgroundColor = 0xFF2f2f2f,
|
};
|
flNetWorkTop.AddChidren (btnNull2);
|
|
//---------------------------------------------------------------------------------------------------------------------------------
|
EventHandler<MouseEventArgs> networkEHandler = new EventHandler<MouseEventArgs> (delegate (object senderea, MouseEventArgs eae) {
|
SystemMiddle.ThirdScrolView.RemoveAll ();
|
|
Button textButton12 = new Button () {
|
TextID = R.MyInternationalizationString.NetwordParameters,
|
TextAlignment = TextAlignment.Center
|
};
|
SystemMiddle.ThirdScrolView.TitleView.AddChidren (textButton12);
|
|
FrameLayout frameLayout2 = new FrameLayout ();
|
SystemMiddle.ThirdScrolView.AddChidren (frameLayout2);
|
Button dhcp = new Button () {
|
X = gatewayIDName.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (40),
|
Width = Application.GetRealWidth (360),
|
Text = "DHCP:",
|
Y = Application.GetRealHeight (10),
|
};
|
frameLayout2.AddChidren (dhcp);
|
Button btnDHCPcheck = new Button () {
|
Height = Application.GetMinRealAverage (98),
|
Width = Application.GetMinRealAverage (76),
|
UnSelectedImagePath = "Item/Check.png",
|
SelectedImagePath = "Item/CheckSelected.png",
|
Y = Application.GetRealHeight (10),
|
IsSelected = gatewayDevice.DHCP,
|
};
|
btnDHCPcheck.X = SystemMiddle.SecondScrolView.TitleView.Width - btnDHCPcheck.Width - Application.GetRealWidth (98);
|
|
frameLayout2.AddChidren (btnDHCPcheck);
|
|
Button lblIPAddresses = new Button () {
|
X = gatewayIDName.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (239),
|
TextID = R.MyInternationalizationString.IPAddresses,
|
Y = dhcp.Bottom + Application.GetRealHeight (2),
|
};
|
frameLayout2.AddChidren (lblIPAddresses);
|
|
EditText etIPAddresses = new EditText () {
|
X = dhcp.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
Text = " " + gatewayDevice.IPAddress,
|
BackgroundColor = 0xFF000000,
|
Y = lblIPAddresses.Bottom + Application.GetRealHeight (2),
|
};
|
frameLayout2.AddChidren (etIPAddresses);
|
CommonPage.FindGatewayChilrenIPAddress = gatewayDevice.IPAddress;
|
|
Button lblSubnetMask = new Button () {
|
X = dhcp.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
TextID = R.MyInternationalizationString.SubnetMask,
|
Y = etIPAddresses.Bottom + Application.GetRealHeight (2),
|
};
|
frameLayout2.AddChidren (lblSubnetMask);
|
|
EditText etSubnetMask = new EditText () {
|
X = dhcp.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
Text = " " + gatewayDevice.SubnetMask,
|
BackgroundColor = 0xFF000000,
|
Y = lblSubnetMask.Bottom + Application.GetRealHeight (2),
|
};
|
frameLayout2.AddChidren (etSubnetMask);
|
|
Button lblRoutingIP = new Button () {
|
X = dhcp.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
TextID = R.MyInternationalizationString.RoutingIP,
|
Y = etSubnetMask.Bottom + Application.GetRealHeight (2),
|
};
|
frameLayout2.AddChidren (lblRoutingIP);
|
|
EditText etRoutingIP = new EditText () {
|
X = dhcp.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
Text = " " + gatewayDevice.RouteIPAddress,
|
BackgroundColor = 0xFF000000,
|
Y = lblRoutingIP.Bottom + Application.GetRealHeight (2),
|
};
|
frameLayout2.AddChidren (etRoutingIP);
|
|
Button btnDHCPSave = new Button () {
|
Gravity = Gravity.CenterHorizontal,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (98),
|
BackgroundColor = 0xFF333333,
|
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
|
BorderWidth = 1,
|
Radius = 5,
|
BorderColor = SkinStyle.Current.Transparent,
|
TextID = R.MyInternationalizationString.SAVE,
|
Y = etRoutingIP.Bottom + Application.GetRealHeight (50),
|
};
|
frameLayout2.AddChidren (btnDHCPSave);
|
|
btnDHCPcheck.MouseUpEventHandler += (sender, e) => {
|
if (btnDHCPcheck.IsSelected) {
|
btnDHCPcheck.IsSelected = false;
|
etIPAddresses.Enable = etSubnetMask.Enable = etRoutingIP.Enable = true;
|
btnDHCPSave.Visible = true;
|
} else {
|
btnDHCPcheck.IsSelected = true;
|
etIPAddresses.Enable = etSubnetMask.Enable = etRoutingIP.Enable = false;
|
btnDHCPSave.Visible = false;
|
}
|
gatewayDevice.IPAddress = etIPAddresses.Text.Trim ();
|
gatewayDevice.SubnetMask = etSubnetMask.Text.Trim ();
|
gatewayDevice.RouteIPAddress = etRoutingIP.Text.Trim ();
|
gatewayDevice.DHCP = btnDHCPcheck.IsSelected;
|
try {
|
byte [] bytes = new byte [21];
|
bytes [20] = gatewayDevice.DHCP == true ? (byte)1 : (byte)0;
|
System.Net.IPAddress address;
|
if (System.Net.IPAddress.TryParse (gatewayDevice.IPAddress, out address)) {
|
string [] ipAddress = gatewayDevice.IPAddress.Split ('.');
|
for (int i = 0; i < ipAddress.Length; i++) {
|
bytes [i] = byte.Parse (ipAddress [i]);
|
}
|
} else {
|
throw new Exception ();
|
}
|
if (System.Net.IPAddress.TryParse (gatewayDevice.RouteIPAddress, out address)) {
|
string [] r = gatewayDevice.RouteIPAddress.Split ('.');
|
for (int i = 0; i < r.Length; i++) {
|
bytes [i + 4] = byte.Parse (r [i]);
|
}
|
} else {
|
throw new Exception ();
|
}
|
UpdateOnePorWirelessFR (gatewayDevice);
|
|
} catch {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipPleaseEnterTheCorrectData), Language.StringByID (R.MyInternationalizationString.Confrim)).Show ();
|
}
|
};
|
|
btnDHCPSave.MouseUpEventHandler += (sender, e) => {
|
gatewayDevice.IPAddress = etIPAddresses.Text.Trim ();
|
gatewayDevice.SubnetMask = etSubnetMask.Text.Trim ();
|
gatewayDevice.RouteIPAddress = etRoutingIP.Text.Trim ();
|
gatewayDevice.DHCP = btnDHCPcheck.IsSelected;
|
try {
|
byte [] bytes = new byte [21];
|
bytes [20] = gatewayDevice.DHCP == true ? (byte)1 : (byte)0;
|
System.Net.IPAddress address;
|
if (System.Net.IPAddress.TryParse (gatewayDevice.IPAddress, out address)) {
|
string [] ipAddress = gatewayDevice.IPAddress.Split ('.');
|
for (int i = 0; i < ipAddress.Length; i++) {
|
bytes [i] = byte.Parse (ipAddress [i]);
|
}
|
} else {
|
throw new Exception ();
|
}
|
if (System.Net.IPAddress.TryParse (gatewayDevice.RouteIPAddress, out address)) {
|
string [] r = gatewayDevice.RouteIPAddress.Split ('.');
|
for (int i = 0; i < r.Length; i++) {
|
bytes [i + 4] = byte.Parse (r [i]);
|
}
|
} else {
|
throw new Exception ();
|
}
|
UpdateOnePorWirelessFR (gatewayDevice);
|
} catch {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipPleaseEnterTheCorrectData), Language.StringByID (R.MyInternationalizationString.Confrim)).Show ();
|
}
|
};
|
if (gatewayDevice.DHCP) {
|
btnDHCPcheck.IsSelected = true;
|
etIPAddresses.Enable = etSubnetMask.Enable = etRoutingIP.Enable = false;
|
btnDHCPSave.Visible = false;
|
|
} else {
|
btnDHCPcheck.IsSelected = false;
|
etIPAddresses.Enable = etSubnetMask.Enable = etRoutingIP.Enable = true;
|
btnDHCPSave.Visible = true;
|
}
|
});
|
textButton1.MouseUpEventHandler += networkEHandler;
|
flNetWorkTop.MouseUpEventHandler += networkEHandler;
|
#endregion
|
|
#region--------------RemoteAccess--------------------------
|
FrameLayout flRemoteAccessTop = new FrameLayout () {
|
Height = Application.GetRealHeight (131),
|
Width = LayoutParams.MatchParent,
|
};
|
SystemMiddle.SecondScrolView.AddChidren (flRemoteAccessTop);
|
|
Button RemoteAccessSeleted = new Button () {
|
X = Application.GetRealWidth (15),
|
Height = Application.GetRealHeight (66),
|
Width = Application.GetRealWidth (66),
|
UnSelectedImagePath = "Item/RemoteAccess.png",
|
SelectedImagePath = "Item/RemoteAccessSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
flRemoteAccessTop.AddChidren (RemoteAccessSeleted);
|
Button lblRemoteAccesss = new Button () {
|
X = Application.GetRealWidth (11) + RemoteAccessSeleted.Right,
|
Height = Application.GetRealHeight (41),
|
Width = Application.GetRealWidth (200),
|
TextID = R.MyInternationalizationString.RemoteAccess,
|
Gravity = Gravity.CenterVertical,
|
TextAlignment = TextAlignment.CenterLeft,
|
};
|
flRemoteAccessTop.AddChidren (lblRemoteAccesss);
|
Button btnRemoteAccessHelp = new Button () {
|
Height = Application.GetMinRealAverage (98),
|
Width = Application.GetMinRealAverage (76),
|
UnSelectedImagePath = "Item/Help.png",
|
SelectedImagePath = "Item/HelpSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
btnRemoteAccessHelp.X = flRemoteAccessTop.Width - btnRemoteAccessHelp.Width - Application.GetRealWidth (30);
|
btnRemoteAccessHelp.MouseUpEventHandler += (sender, e) => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.HelpRemoteAccess), Direction = AMPopTipDirection.Down, CloseTime = 4 }.Show ((View)sender);
|
};
|
flRemoteAccessTop.AddChidren (btnRemoteAccessHelp);
|
|
Button btnNul3 = new Button () {
|
Y = Application.GetRealHeight (131) - 2,
|
Height = 1,
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
flRemoteAccessTop.AddChidren (btnNul3);
|
Button btnNull3 = new Button () {
|
Y = Application.GetRealHeight (131) - 1,
|
Height = 1,
|
BackgroundColor = 0xFF2f2f2f,
|
};
|
flRemoteAccessTop.AddChidren (btnNull3);
|
|
//---------------------------------------------------------------------------------------------------------------------------------
|
|
EventHandler<MouseEventArgs> RemoteAccessBodyEHandler = new EventHandler<MouseEventArgs> (delegate (object senderea, MouseEventArgs eae) {
|
SystemMiddle.ThirdScrolView.RemoveAll ();
|
|
Button lblRemoteAccesss2 = new Button () {
|
TextID = R.MyInternationalizationString.RemoteAccess,
|
TextAlignment = TextAlignment.Center,
|
};
|
SystemMiddle.ThirdScrolView.TitleView.AddChidren (lblRemoteAccesss2);
|
|
Button btnRemoteAccessCheck = new Button () {
|
X = Application.GetRealWidth (550),
|
Height = Application.GetMinRealAverage (98),
|
Width = Application.GetMinRealAverage (76),
|
UnSelectedImagePath = "Item/Check.png",
|
SelectedImagePath = "Item/CheckSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
SystemMiddle.ThirdScrolView.TitleView.AddChidren (btnRemoteAccessCheck);
|
|
|
|
FrameLayout flRemoteAccessBody = new FrameLayout ();
|
SystemMiddle.ThirdScrolView.AddChidren (flRemoteAccessBody);
|
Button btnRemoteGroupName = new Button () {
|
X = gatewayIDName.X,
|
Y = Application.GetRealHeight (20),
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (40),
|
Width = Application.GetRealWidth (360),
|
TextID = R.MyInternationalizationString.GroupName,
|
};
|
flRemoteAccessBody.AddChidren (btnRemoteGroupName);
|
|
EditText etGroupName = new EditText () {
|
X = gatewayIDName.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
Y = btnRemoteGroupName.Bottom + Application.GetRealHeight (2),
|
BackgroundColor = 0xFF000000,
|
};
|
flRemoteAccessBody.AddChidren (etGroupName);
|
|
Button lblProjectName = new Button () {
|
X = gatewayIDName.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (40),
|
Width = Application.GetRealWidth (360),
|
TextID = R.MyInternationalizationString.ProjectName,
|
Y = etGroupName.Bottom + Application.GetRealHeight (2),
|
};
|
flRemoteAccessBody.AddChidren (lblProjectName);
|
|
EditText etRemoteProjectName = new EditText () {
|
X = gatewayIDName.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
Y = lblProjectName.Bottom + Application.GetRealHeight (2),
|
BackgroundColor = 0xFF000000,
|
};
|
flRemoteAccessBody.AddChidren (etRemoteProjectName);
|
|
Button lblUsername = new Button () {
|
X = lblProjectName.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
TextID = R.MyInternationalizationString.UserName,
|
Y = etRemoteProjectName.Bottom + Application.GetRealHeight (2),
|
};
|
flRemoteAccessBody.AddChidren (lblUsername);
|
//----------------------------------------------------------------------------------------
|
|
EditText etRemoteUserName = new EditText () {
|
X = lblProjectName.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
BackgroundColor = 0xFF000000,
|
Y = lblUsername.Bottom + Application.GetRealHeight (2),
|
};
|
flRemoteAccessBody.AddChidren (etRemoteUserName);
|
|
Button btnRemotePassword = new Button () {
|
X = lblProjectName.X,
|
Y = etRemoteUserName.Bottom + Application.GetRealHeight (2),
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
TextID = R.MyInternationalizationString.PassWrod,
|
TextAlignment = TextAlignment.CenterLeft,
|
};
|
flRemoteAccessBody.AddChidren (btnRemotePassword);
|
|
EditText etGatewayPassWrod = new EditText () {
|
X = lblProjectName.X,
|
Y = btnRemotePassword.Bottom + Application.GetRealHeight (2),
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
Text = gatewayDevice.Password,
|
BackgroundColor = 0xFF000000,
|
};
|
flRemoteAccessBody.AddChidren (etGatewayPassWrod);
|
|
Button btnServerIP = new Button () {
|
X = lblProjectName.X,
|
Y = etGatewayPassWrod.Bottom + Application.GetRealHeight (2),
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
TextID = R.MyInternationalizationString.ServerIP,
|
TextAlignment = TextAlignment.CenterLeft,
|
};
|
flRemoteAccessBody.AddChidren (btnServerIP);
|
|
EditText etServerIP = new EditText () {
|
X = lblProjectName.X,
|
Y = btnServerIP.Bottom + Application.GetRealHeight (2),
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (300),
|
SelectedBackgroundColor = 0xFF000000,
|
SelectedImagePath = "Item/TextBoxSelected.png",
|
};
|
flRemoteAccessBody.AddChidren (etServerIP);
|
|
EditText etServerIPPoint = new EditText () {
|
X = etServerIP.Right + 2,
|
Y = etServerIP.Y,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (140) - 2,
|
BackgroundColor = 0xFF000000,
|
};
|
flRemoteAccessBody.AddChidren (etServerIPPoint);
|
|
|
Button btnAlternativeServerIP = new Button () {
|
X = lblProjectName.X,
|
Y = etServerIP.Bottom + Application.GetRealHeight (2),
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (440),
|
TextID = R.MyInternationalizationString.AlternativeServerIP,
|
TextAlignment = TextAlignment.CenterLeft,
|
};
|
flRemoteAccessBody.AddChidren (btnAlternativeServerIP);
|
|
|
EditText etAlternativeServerIP = new EditText () {
|
X = lblProjectName.X,
|
Y = btnAlternativeServerIP.Bottom + Application.GetRealHeight (2),
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (300),
|
BackgroundColor = 0xFF000000,
|
};
|
flRemoteAccessBody.AddChidren (etAlternativeServerIP);
|
EditText etAlternativeServerIPPoint = new EditText () {
|
X = etAlternativeServerIP.Right + 2,
|
Y = etAlternativeServerIP.Y,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (140) - 2,
|
BackgroundColor = 0xFF000000,
|
};
|
flRemoteAccessBody.AddChidren (etAlternativeServerIPPoint);
|
|
//-----------------------------------------------------------------------------
|
Button btnGatewaySave = new Button () {
|
Gravity = Gravity.CenterHorizontal,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (98),
|
BackgroundColor = 0xFF333333,
|
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
|
BorderWidth = 1,
|
Radius = 5,
|
BorderColor = SkinStyle.Current.Transparent,
|
TextID = R.MyInternationalizationString.SAVE,
|
Y = etAlternativeServerIP.Bottom + Application.GetRealHeight (50),
|
};
|
flRemoteAccessBody.AddChidren (btnGatewaySave);
|
|
byte [] gatewayBytes = Control.ControlBytesSendHasReturn (Command.ReadGateWayModelInfo, gatewayDevice.SubnetID, gatewayDevice.DeviceID, new byte [] { });
|
|
if (gatewayBytes != null && gatewayBytes.Length > 58) {
|
gatewayDevice.Remote_GroupName = CommonPage.MyEncodingGB2312.GetString (gatewayBytes, 1, 20).Trim ('\0');
|
gatewayDevice.Remote_ProjectName = CommonPage.MyEncodingGB2312.GetString (gatewayBytes, 21, 20).Trim ('\0');
|
gatewayDevice.Remote_UserName = CommonPage.MyEncodingGB2312.GetString (gatewayBytes, 41, 8).Trim ('\0');
|
gatewayDevice.Remote_Password = CommonPage.MyEncodingGB2312.GetString (gatewayBytes, 49, 8).Trim ('\0');
|
gatewayDevice.RometoMode = gatewayBytes [0];
|
IO.FileUtils.SaveEquipmentMessage (gatewayDevice);
|
}
|
|
btnRemoteAccessCheck.MouseUpEventHandler += (sender, e) => {
|
if (!btnRemoteAccessCheck.IsSelected) {
|
flRemoteAccessBody.Height = btnGatewaySave.Bottom + Application.GetRealHeight (20);
|
btnRemoteAccessCheck.IsSelected = true;
|
if (gatewayBytes != null) {
|
gatewayDevice.RometoMode = gatewayBytes [0] = 2;
|
Control.ControlBytesSend (Command.SetGateWayModelInfo, gatewayDevice.SubnetID, gatewayDevice.DeviceID, gatewayBytes);
|
UserConfig.Instance.RemoteModeFile = "Equipment_" + gatewayDevice.Type.ToString () + "_" + gatewayDevice.SubnetID.ToString () + "_" + gatewayDevice.DeviceID.ToString ();
|
UserConfig.Instance.SaveUserConfig ();
|
}
|
} else {
|
flRemoteAccessBody.Height = Application.GetRealHeight (0);
|
btnRemoteAccessCheck.IsSelected = false;
|
if (gatewayBytes != null) {
|
gatewayDevice.RometoMode = gatewayBytes [0] = 0;
|
var returnByte = Control.ControlBytesSendHasReturn (Command.SetGateWayModelInfo, gatewayDevice.SubnetID, gatewayDevice.DeviceID, gatewayBytes);
|
UserConfig.Instance.RemoteModeFile = string.Empty;
|
UserConfig.Instance.SaveUserConfig ();
|
}
|
}
|
IO.FileUtils.SaveEquipmentMessage (gatewayDevice);
|
};
|
|
byte [] serverIPBytes = Control.ControlBytesSendHasReturn (Command.ReadGatewayServerIP, gatewayDevice.SubnetID, gatewayDevice.DeviceID, new byte [] { });
|
if (serverIPBytes != null && serverIPBytes.Length > 12) {
|
string serverIP1 = serverIPBytes [0].ToString () + "." + serverIPBytes [1].ToString () + "." +
|
serverIPBytes [2].ToString () + "." + serverIPBytes [3].ToString ();
|
string serverIP2 = serverIPBytes [6].ToString () + "." + serverIPBytes [7].ToString () + "." +
|
serverIPBytes [8].ToString () + "." + serverIPBytes [9].ToString ();
|
|
|
string serverIP1Point = ((serverIPBytes [4] * 256) + serverIPBytes [5]).ToString ();
|
string serverIP2Point = ((serverIPBytes [10] * 256) + serverIPBytes [11]).ToString ();
|
etServerIPPoint.Text = serverIP1Point == "0" ? "9999" : serverIP1Point;
|
etAlternativeServerIPPoint.Text = serverIP2Point == "0" ? "9999" : serverIP2Point;
|
|
gatewayDevice.Remote_IP1 = serverIP1;
|
gatewayDevice.Remote_IP2 = serverIP2;
|
gatewayDevice.Remote_IP1_Prot = serverIP1Point;
|
gatewayDevice.Remote_IP2_Prot = serverIP2Point;
|
}
|
etServerIP.Text = gatewayDevice.Remote_IP1;
|
etAlternativeServerIP.Text = gatewayDevice.Remote_IP2;
|
etGroupName.Text = gatewayDevice.Remote_GroupName;
|
etRemoteProjectName.Text = gatewayDevice.Remote_ProjectName;
|
etRemoteUserName.Text = gatewayDevice.Remote_UserName;
|
etGatewayPassWrod.Text = gatewayDevice.Remote_Password;
|
|
btnGatewaySave.MouseUpEventHandler += (sender, e) => {
|
gatewayDevice.Remote_GroupName = etGroupName.Text.Trim ();// "james";//gatewayGroupName;
|
gatewayDevice.Remote_ProjectName = etRemoteProjectName.Text.Trim ();//"myhome";//gatewayProjectName;
|
gatewayDevice.Remote_UserName = etRemoteUserName.Text.Trim ();//"james";//gatewayUserName;
|
gatewayDevice.Remote_Password = etGatewayPassWrod.Text.Trim ();//"chy1125";//gatewayPassWord;
|
|
IO.FileUtils.SaveEquipmentMessage (gatewayDevice);
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.ThePerationWasSuccessful), Language.StringByID (R.MyInternationalizationString.Confrim)).Show ();
|
try {
|
byte [] ggn = new byte [20];
|
byte [] b1 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDevice.Remote_GroupName);
|
Array.Copy (b1, 0, ggn, 0, 20 < b1.Length ? 20 : b1.Length);
|
|
byte [] gpn = new byte [20];
|
byte [] b2 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDevice.Remote_ProjectName);
|
Array.Copy (b2, 0, gpn, 0, 20 < b2.Length ? 20 : b2.Length);
|
|
byte [] gun = new byte [8];
|
byte [] b3 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDevice.Remote_UserName);
|
Array.Copy (b3, 0, gun, 0, 8 < b3.Length ? 8 : b3.Length);
|
|
byte [] gpw = new byte [8];
|
byte [] b4 = CommonPage.MyEncodingGB2312.GetBytes (gatewayDevice.Remote_Password);
|
Array.Copy (b4, 0, gpw, 0, 8 < b4.Length ? 8 : b4.Length);
|
|
System.Threading.Tasks.Task.Run (() => {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Start ("Sending...");
|
});
|
byte [] macAddress = Control.ControlBytesSendHasReturn (Command.ReadDeviceMac, gatewayDevice.SubnetID, gatewayDevice.DeviceID, new byte [] { });
|
byte [] sendServerBytes = new byte [56];
|
Array.Copy (gpn, 0, sendServerBytes, 0, 20 < gpn.Length ? 20 : gpn.Length);
|
Array.Copy (ggn, 0, sendServerBytes, 20, 20 < ggn.Length ? 20 : ggn.Length);
|
Array.Copy (gun, 0, sendServerBytes, 40, 8 < gun.Length ? 8 : gun.Length);
|
Array.Copy (macAddress, 0, sendServerBytes, 48, 8 < macAddress.Length ? 8 : macAddress.Length);
|
Control control = new Control ();
|
control.Send (new Target () {
|
IPEndPoint = new System.Net.IPEndPoint (System.Net.IPAddress.Parse (MainPage.SeviceIP), 9999),
|
Command = Command.SendRemoteInfoToServer,
|
SubnetID = 255,
|
DeviceID = 255,
|
AddData = gatewayBytes,
|
}, SendCount.Three, true);
|
var serverResult = control.UsefulBytes;
|
if (serverResult == null || serverResult [0] == 0) {
|
Application.RunOnMainThread (() => {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
|
Language.StringByID (R.MyInternationalizationString.OperationFailed),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
return;
|
});
|
} else if (serverResult [0] == 2) {
|
Application.RunOnMainThread (() => {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
|
Language.StringByID (R.MyInternationalizationString.HaveTheSame),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
return;
|
});
|
}
|
Array.Copy (ggn, 0, gatewayBytes, 1, 20 < ggn.Length ? 20 : ggn.Length);
|
Array.Copy (gpn, 0, gatewayBytes, 21, 20 < gpn.Length ? 20 : gpn.Length);
|
Array.Copy (gun, 0, gatewayBytes, 41, 8 < gun.Length ? 8 : gun.Length);
|
Array.Copy (gpw, 0, gatewayBytes, 49, 8 < gpw.Length ? 8 : gpw.Length);
|
|
Control.ControlBytesSend (Command.SetGateWayModelInfo, gatewayDevice.SubnetID, gatewayDevice.DeviceID, gatewayBytes);
|
|
string [] strServerIP = etServerIP.Text.Split ('.');
|
string [] strServerIP1 = etAlternativeServerIP.Text.Split ('.');
|
if (strServerIP.Length != 4 || strServerIP1.Length != 4) {
|
throw new Exception ();
|
} else {
|
serverIPBytes [0] = Convert.ToByte (strServerIP [0]);
|
serverIPBytes [1] = Convert.ToByte (strServerIP [1]);
|
serverIPBytes [2] = Convert.ToByte (strServerIP [2]);
|
serverIPBytes [3] = Convert.ToByte (strServerIP [3]);
|
int point1 = 9999;
|
if (!int.TryParse (etServerIPPoint.Text, out point1)) {
|
point1 = 9999;
|
}
|
serverIPBytes [4] = Convert.ToByte (point1 / 256);
|
serverIPBytes [5] = Convert.ToByte (point1 % 256);
|
|
serverIPBytes [6] = Convert.ToByte (strServerIP1 [0]);
|
serverIPBytes [7] = Convert.ToByte (strServerIP1 [1]);
|
serverIPBytes [8] = Convert.ToByte (strServerIP1 [2]);
|
serverIPBytes [9] = Convert.ToByte (strServerIP1 [3]); int point2 = 9999;
|
if (!int.TryParse (etAlternativeServerIPPoint.Text, out point2)) {
|
point2 = 9999;
|
}
|
serverIPBytes [10] = Convert.ToByte (point2 / 256);
|
serverIPBytes [11] = Convert.ToByte (point2 % 256);
|
}
|
|
});
|
//远程ip地址的设置
|
var mobytes = Control.ControlBytesSendHasReturn (Command.SetGateWayModelInternetInfo, gatewayDevice.SubnetID, gatewayDevice.DeviceID, serverIPBytes);
|
if (mobytes == null || mobytes [0] == 0xF5) {
|
Application.RunOnMainThread (() => {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
|
Language.StringByID (R.MyInternationalizationString.OperationFailed),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
return;
|
});
|
}
|
} catch {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipPleaseEnterTheCorrectData), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
return;
|
} finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
};
|
|
if (gatewayDevice.RometoMode == 0) {
|
flRemoteAccessBody.Height = Application.GetRealHeight (0);
|
btnRemoteAccessCheck.IsSelected = false;
|
} else {
|
flRemoteAccessBody.Height = btnGatewaySave.Bottom + Application.GetRealHeight (20);
|
btnRemoteAccessCheck.IsSelected = true;
|
UserConfig.Instance.RemoteModeFile = "Equipment_" + gatewayDevice.Type.ToString () + "_" + gatewayDevice.SubnetID.ToString () + "_" + gatewayDevice.DeviceID.ToString ();
|
UserConfig.Instance.SaveUserConfig ();
|
}
|
});
|
lblRemoteAccesss.MouseUpEventHandler += RemoteAccessBodyEHandler;
|
flRemoteAccessTop.MouseUpEventHandler += RemoteAccessBodyEHandler;
|
#endregion
|
#region--------------广播参数--------------------------
|
RowLayout flRadioParameterTop = new RowLayout () {
|
Height = Application.GetRealHeight (131),
|
Width = LayoutParams.MatchParent,
|
};
|
SystemMiddle.SecondScrolView.AddChidren (flRadioParameterTop);
|
|
Button btnRadioParameterIcon = new Button () {
|
X = Application.GetRealWidth (15),
|
Height = Application.GetRealHeight (66),
|
Width = Application.GetRealWidth (66),
|
UnSelectedImagePath = "Item/Wireless.png",
|
SelectedImagePath = "Item/WirelessSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
flRadioParameterTop.AddChidren (btnRadioParameterIcon);
|
Button btnRadioParameterTitel = new Button () {
|
X = Application.GetRealWidth (11) + btnRadioParameterIcon.Right,
|
Height = Application.GetRealHeight (41),
|
Width = Application.GetRealWidth (500),
|
TextID = R.MyInternationalizationString.RadioParameters,
|
Gravity = Gravity.CenterVertical,
|
TextAlignment = TextAlignment.CenterLeft,
|
};
|
flRadioParameterTop.AddChidren (btnRadioParameterTitel);
|
Button btnRadioParameterHelp = new Button () {
|
Height = Application.GetMinRealAverage (98),
|
Width = Application.GetMinRealAverage (76),
|
UnSelectedImagePath = "Item/Help.png",
|
SelectedImagePath = "Item/HelpSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
btnRadioParameterHelp.X = flRadioParameterTop.Width - btnRadioParameterHelp.Width - Application.GetRealWidth (30);
|
btnRadioParameterHelp.MouseUpEventHandler += (sender, e) => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.GatewayConfigHelp), Direction = AMPopTipDirection.Down, CloseTime = 4 }.Show ((View)sender);
|
};
|
flRadioParameterTop.AddChidren (btnRadioParameterHelp);
|
|
Button btnNul4 = new Button () {
|
Y = Application.GetRealHeight (131) - 2,
|
Height = 1,
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
flRadioParameterTop.AddChidren (btnNul4);
|
Button btnNull4 = new Button () {
|
Y = Application.GetRealHeight (131) - 1,
|
Height = 1,
|
BackgroundColor = 0xFF2f2f2f,
|
};
|
flRadioParameterTop.AddChidren (btnNull4);
|
//-------------------------
|
|
EventHandler<MouseEventArgs> RadioParameterBody = new EventHandler<MouseEventArgs> (delegate (object senderea, MouseEventArgs eae) {
|
SystemMiddle.ThirdScrolView.RemoveAll ();
|
|
|
Button btnRadioParameterTitel2 = new Button () {
|
TextID = R.MyInternationalizationString.RadioParameters,
|
TextAlignment = TextAlignment.Center,
|
};
|
SystemMiddle.ThirdScrolView.TitleView.AddChidren (btnRadioParameterTitel2);
|
|
FrameLayout flRadioParameterBody = new FrameLayout ();
|
SystemMiddle.ThirdScrolView.AddChidren (flRadioParameterBody);
|
Button lblBand = new Button () {
|
X = gatewayIDName.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (60),
|
Width = Application.GetRealWidth (130),
|
TextID = R.MyInternationalizationString.Band,
|
Y = Application.GetRealHeight (50),
|
};
|
flRadioParameterBody.AddChidren (lblBand);
|
|
string [] bandText = new string [3];
|
if (Language.CurrentLanguage == "English") {
|
bandText [0] = "WPAN (China)";
|
bandText [1] = "SRD (European)";
|
bandText [2] = "ISM (North_American)";
|
} else if (Language.CurrentLanguage == "Chinese") {
|
bandText [0] = "WPAN(中国)";
|
bandText [1] = "SRD(欧洲)";
|
bandText [2] = "ISM(美国)";
|
}
|
Spinner spinnerband = new Spinner () {
|
X = lblBand.Right + Application.GetRealWidth (5),
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (310),
|
Y = Application.GetRealHeight (60),
|
};
|
spinnerband.AdapterStr = bandText;//.AddAdapter(bandText);
|
spinnerband.SelectedItemChanged += (sender, e) => {
|
System.Console.WriteLine (e);
|
gatewayDevice.WirelessBand = (byte)e;
|
};
|
flRadioParameterBody.AddChidren (spinnerband);
|
try {
|
spinnerband.CurrentRow = Convert.ToInt32 (gatewayDevice.WirelessBand);
|
} catch { }
|
Button btnChannel = new Button () {
|
X = lblBand.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (130),
|
TextID = R.MyInternationalizationString.Channel,
|
Y = lblBand.Bottom + Application.GetRealHeight (42),
|
};
|
btnChannel.Text += ":";
|
flRadioParameterBody.AddChidren (btnChannel);
|
|
#region channelText
|
string channelText = "";
|
string [] channelTextSpinner = new string [13];
|
if (gatewayDevice.WirelessBand == 0) {
|
channelTextSpinner [0] = "780MHz";
|
channelTextSpinner [1] = "782MHz";
|
channelTextSpinner [2] = "784MHz";
|
channelTextSpinner [3] = "786MHz";
|
channelTextSpinner [4] = "770MHz";
|
channelTextSpinner [5] = "772MHz";
|
channelTextSpinner [6] = "774MHz";
|
channelTextSpinner [7] = "776MHz";
|
channelTextSpinner [8] = "778MHz";
|
channelTextSpinner [9] = "788MHz";
|
channelTextSpinner [10] = "790MHz";
|
channelTextSpinner [11] = "792MHz";
|
channelTextSpinner [12] = "794MHz";
|
} else if (gatewayDevice.WirelessBand == 1) {
|
channelTextSpinner [0] = "864MHz";
|
channelTextSpinner [1] = "866MHz";
|
channelTextSpinner [2] = "868MHz";
|
channelTextSpinner [3] = "870MHz";
|
channelTextSpinner [4] = "858MHz";
|
channelTextSpinner [5] = "860MHz";
|
channelTextSpinner [6] = "862MHz";
|
channelTextSpinner [7] = "872MHz";
|
channelTextSpinner [8] = "874MHz";
|
channelTextSpinner [9] = "876MHz";
|
channelTextSpinner [10] = "878MHz";
|
channelTextSpinner [11] = "880MHz";
|
channelTextSpinner [12] = "882MHz";
|
|
} else if (gatewayDevice.WirelessBand == 2) {
|
channelTextSpinner [0] = "904MHz";
|
channelTextSpinner [1] = "906MHz";
|
channelTextSpinner [2] = "908MHz";
|
channelTextSpinner [3] = "910MHz";
|
channelTextSpinner [4] = "912MHz";
|
channelTextSpinner [5] = "914MHz";
|
channelTextSpinner [6] = "916MHz";
|
channelTextSpinner [7] = "918MHz";
|
channelTextSpinner [8] = "920MHz";
|
channelTextSpinner [9] = "922MHz";
|
channelTextSpinner [10] = "924MHz";
|
channelTextSpinner [11] = "926MHz";
|
channelTextSpinner [12] = "928MHz";
|
}
|
#endregion
|
|
Spinner spinnerChannel = new Spinner () {
|
X = spinnerband.X,
|
Height = Application.GetRealHeight (60),
|
Width = Application.GetRealWidth (310),
|
Y = btnChannel.Y + Application.GetRealHeight (35),
|
};
|
spinnerChannel.AdapterStr = channelTextSpinner;//.AddAdapter(channelTextSpinner);
|
spinnerChannel.SelectedItemChanged += (sender, e) => {
|
System.Console.WriteLine (e);
|
gatewayDevice.WirelessChannel = (byte)e;
|
};
|
flRadioParameterBody.AddChidren (spinnerChannel);
|
try {
|
spinnerChannel.CurrentRow = Convert.ToInt32 (gatewayDevice.WirelessChannel);
|
} catch { }
|
Button lblPasswordG = new Button () {
|
X = lblBand.X,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (130),
|
TextID = R.MyInternationalizationString.PassWrod,
|
Y = btnChannel.Bottom + Application.GetRealHeight (42),
|
};
|
flRadioParameterBody.AddChidren (lblPasswordG);
|
|
channelText = gatewayDevice.WirelessPassword;
|
EditText etRadioParameterPassWrod = new EditText () {
|
X = spinnerband.X,
|
Y = spinnerChannel.Bottom + Application.GetRealHeight (32),
|
Text = channelText,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (310),
|
BackgroundColor = 0xFF000000,
|
};
|
flRadioParameterBody.AddChidren (etRadioParameterPassWrod);
|
|
//--------------------------------------------------------------------------------------
|
Button btnRadioParameterSave = new Button () {
|
Gravity = Gravity.CenterHorizontal,
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (98),
|
BackgroundColor = 0xFF333333,
|
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
|
BorderWidth = 1,
|
Radius = 5,
|
BorderColor = SkinStyle.Current.Transparent,
|
TextID = R.MyInternationalizationString.SAVE,
|
Y = etRadioParameterPassWrod.Bottom + Application.GetRealHeight (50),
|
};
|
flRadioParameterBody.AddChidren (btnRadioParameterSave);
|
|
btnRadioParameterSave.MouseUpEventHandler += (sender, e) => {
|
|
UpdateOnePorWirelessFR (gatewayDevice);
|
//byte [] pw = CommonPage.MyEncodingGB2312.GetBytes (etRadioParameterPassWrod.Text.Trim ());
|
//byte [] pws = new byte [16];
|
//Array.Copy (pw, 0, pws, 0, 16 < pw.Length ? 16 : pw.Length);
|
//Array.Copy (pws, 0, usefulBytesOther, 8, pws.Length);
|
//byte [] meshGateway = new byte [23];
|
//Array.Copy (usefulBytesOther, 1, meshGateway, 0, 23);
|
//var suful = Control.ControlBytesSendHasReturn (Command.TestWriteManageWirelessNet, onePortWirelessFR.SubnetID, onePortWirelessFR.DeviceID, new byte [] { 0 });
|
//if (suful != null) {
|
// if (suful [0] == 0xF8) {
|
// Control.ControlBytesSend (Command.WriteManageWirelessNet, onePortWirelessFR.SubnetID, onePortWirelessFR.DeviceID, meshGateway);
|
// }
|
//}
|
//MainPage.Loading.Hide ();
|
//System.Console.WriteLine ("UpdateWirelessManage send.");
|
};
|
});
|
btnRadioParameterTitel.MouseUpEventHandler += RadioParameterBody;
|
flRadioParameterTop.MouseUpEventHandler += RadioParameterBody;
|
#endregion
|
|
#region--------------无线频率配对--------------------------
|
RowLayout flGatewayMapping = new RowLayout () {
|
Height = Application.GetRealHeight (131),
|
Width = LayoutParams.MatchParent,
|
};
|
SystemMiddle.SecondScrolView.AddChidren (flGatewayMapping);
|
|
Button btnWirelessConfigIcon = new Button () {
|
X = Application.GetRealWidth (15),
|
Height = Application.GetRealHeight (66),
|
Width = Application.GetRealWidth (66),
|
UnSelectedImagePath = "Item/GatewayMapping.png",
|
SelectedImagePath = "Item/GatewayMappingSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
btnWirelessConfigIcon.MouseUpEventHandler += (sender, e) => {
|
ShowWirelessConfigDialog (gatewayDevice.SubnetID, gatewayDevice.DeviceID);
|
};
|
flGatewayMapping.AddChidren (btnWirelessConfigIcon);
|
Button btnWirelessConfigText = new Button () {
|
X = Application.GetRealWidth (11) + btnWirelessConfigIcon.Right,
|
Height = Application.GetRealHeight (41),
|
Width = Application.GetRealWidth (400),
|
TextID = R.MyInternationalizationString.PairingOfWirelessDevices,
|
Gravity = Gravity.CenterVertical,
|
TextAlignment = TextAlignment.CenterLeft,
|
};
|
flGatewayMapping.AddChidren (btnWirelessConfigText);
|
btnWirelessConfigText.MouseUpEventHandler += (sender, e) => {
|
ShowWirelessConfigDialog (gatewayDevice.SubnetID, gatewayDevice.DeviceID);
|
};
|
Button btnGatewayMappingHelp = new Button () {
|
Height = Application.GetMinRealAverage (98),
|
Width = Application.GetMinRealAverage (76),
|
UnSelectedImagePath = "Item/Help.png",
|
SelectedImagePath = "Item/HelpSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
btnGatewayMappingHelp.X = flRadioParameterTop.Width - btnGatewayMappingHelp.Width - Application.GetRealWidth (30);
|
flGatewayMapping.AddChidren (btnGatewayMappingHelp);
|
btnGatewayMappingHelp.MouseUpEventHandler += (sender, e) => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.GatewayConfigHelp), Direction = AMPopTipDirection.Down, CloseTime = 4 }.Show ((View)sender);
|
};
|
|
Button btnNul5 = new Button () {
|
Y = Application.GetRealHeight (131) - 2,
|
Height = 1,
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
flGatewayMapping.AddChidren (btnNul5);
|
Button btnNull5 = new Button () {
|
Y = Application.GetRealHeight (131) - 1,
|
Height = 1,
|
BackgroundColor = 0xFF2f2f2f,
|
};
|
flGatewayMapping.AddChidren (btnNull5);
|
|
#endregion
|
|
#region --------------分配地址-----------------
|
RowLayout flDistributionMACTop = new RowLayout () {
|
Height = Application.GetRealHeight (131),
|
Width = LayoutParams.MatchParent,
|
};
|
SystemMiddle.SecondScrolView.AddChidren (flDistributionMACTop);
|
Button btnDistributionMACIcon = new Button () {
|
X = Application.GetRealWidth (15),
|
Height = Application.GetMinRealAverage (66),
|
Width = Application.GetMinRealAverage (66),
|
UnSelectedImagePath = "Item/RedistributionAddress.png",
|
SelectedImagePath = "Item/RedistributionAddressSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
flDistributionMACTop.AddChidren (btnDistributionMACIcon);
|
Button btnDistributionMACText = new Button () {
|
X = Application.GetRealWidth (11) + btnDistributionMACIcon.Right,
|
Height = Application.GetRealHeight (41),
|
Width = Application.GetRealWidth (400),
|
TextID = R.MyInternationalizationString.DistributionOfDeviceAddress,// = "Distribution of device address",
|
Gravity = Gravity.CenterVertical,
|
TextAlignment = TextAlignment.CenterLeft,
|
};
|
flDistributionMACTop.AddChidren (btnDistributionMACText);
|
btnDistributionMACIcon.MouseUpEventHandler += (sender, e) => {
|
ShowAssignedAddressDialog (gatewayDevice.SubnetID, gatewayDevice.DeviceID);
|
};
|
btnDistributionMACText.MouseUpEventHandler += (sender, e) => {
|
ShowAssignedAddressDialog (gatewayDevice.SubnetID, gatewayDevice.DeviceID);
|
};
|
|
Button btnDistributionMACHelp = new Button () {
|
Height = Application.GetMinRealAverage (98),
|
Width = Application.GetMinRealAverage (76),
|
UnSelectedImagePath = "Item/Help.png",
|
SelectedImagePath = "Item/HelpSelected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
btnDistributionMACHelp.X = flRadioParameterTop.Width - btnDistributionMACHelp.Width - Application.GetRealWidth (30);
|
flDistributionMACTop.AddChidren (btnDistributionMACHelp);
|
btnDistributionMACHelp.MouseUpEventHandler += (sender, e) => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.SearchEquipmentHelp), Direction = AMPopTipDirection.Down, CloseTime = 4 }.Show ((View)sender);
|
};
|
Button btnNul41 = new Button () {
|
Y = Application.GetRealHeight (131) - 2,
|
Height = 1,
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
flDistributionMACTop.AddChidren (btnNul41);
|
Button btnNull41 = new Button () {
|
Y = Application.GetRealHeight (131) - 1,
|
Height = 1,
|
BackgroundColor = 0xFF2f2f2f,
|
};
|
flDistributionMACTop.AddChidren (btnNull41);
|
|
#endregion
|
|
#region -----搜索设备----
|
RowLayout flSearchEquipmentTop = new RowLayout () {
|
Height = Application.GetRealHeight (131),
|
Width = LayoutParams.MatchParent,
|
};
|
SystemMiddle.SecondScrolView.AddChidren (flSearchEquipmentTop);
|
Button btnGatewayMappingIcon = new Button () {
|
X = Application.GetRealWidth (17),
|
Height = Application.GetRealHeight (55),
|
Width = Application.GetRealWidth (55),
|
UnSelectedImagePath = "Item/+.png",
|
SelectedImagePath = "Item/+Selected.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
flSearchEquipmentTop.AddChidren (btnGatewayMappingIcon);
|
|
Button btnGatewayMappingText = new Button () {
|
X = Application.GetRealWidth (11) + btnGatewayMappingIcon.Right,
|
Height = Application.GetRealHeight (41),
|
Width = Application.GetRealWidth (400),
|
TextID = R.MyInternationalizationString.GatewayList,
|
Gravity = Gravity.CenterVertical,
|
TextAlignment = TextAlignment.CenterLeft,
|
};
|
|
flSearchEquipmentTop.AddChidren (btnGatewayMappingText);
|
Button btnSearchEquipmentHelp = new Button () {
|
Height = Application.GetMinRealAverage (98),
|
Width = Application.GetMinRealAverage (76),
|
UnSelectedImagePath = "Item/Help.png",
|
SelectedImagePath = "Item/HelpSelected.png",
|
Gravity = Gravity.CenterVertical,
|
X = btnNetWorkHelp.X
|
};
|
flSearchEquipmentTop.AddChidren (btnSearchEquipmentHelp);
|
btnSearchEquipmentHelp.MouseUpEventHandler += (sender, e) => {
|
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.DistributionMACHelp), Direction = AMPopTipDirection.Down, CloseTime = 4 }.Show ((View)sender);
|
};
|
Button btnNul42 = new Button () {
|
Y = Application.GetRealHeight (131) - 2,
|
Height = 1,
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
flSearchEquipmentTop.AddChidren (btnNul42);
|
Button btnNull42 = new Button () {
|
Y = Application.GetRealHeight (131) - 1,
|
Height = 1,
|
BackgroundColor = 0xFF2f2f2f,
|
};
|
flSearchEquipmentTop.AddChidren (btnNull42);
|
|
btnGatewayMappingText.MouseUpEventHandler += (sender, e) => {
|
UpdataGatewayList (gatewayDevice.SubnetID);
|
};
|
btnGatewayMappingIcon.MouseUpEventHandler += (sender, e) => {
|
UpdataGatewayList (gatewayDevice.SubnetID);
|
};
|
#endregion
|
|
#region --------------bottom--------------
|
EventHandler<MouseEventArgs> eHandler = new EventHandler<MouseEventArgs> (delegate (object sender, MouseEventArgs e) {
|
MainPage.Loading.Start ();
|
System.Threading.Tasks.Task.Run (() => {
|
CommonPage.GateWayList.Clear ();
|
CommonPage.RandomHigh = (byte)new Random ().Next (255);
|
CommonPage.RandomLow = (byte)new Random ().Next (255);
|
Control.ControlBytesSendHasReturn (Command.ReadGateway, gatewayDevice.SubnetID, gatewayDevice.DeviceID, new byte [] { CommonPage.RandomHigh, CommonPage.RandomLow });
|
var one = IO.FileUtils.ReadEquipmentMessage (gatewayDevice);
|
gatewayDevice = Newtonsoft.Json.JsonConvert.DeserializeObject<OnePortWirelessFR> (one);
|
Application.RunOnMainThread (() => {
|
this.ShowWirelessGateway (gatewayDevice);
|
});
|
});
|
});
|
btnRefresh.MouseUpEventHandler += eHandler;
|
#endregion
|
MainPage.Loading.Hide ();
|
});
|
});
|
} finally {
|
}
|
}
|
/// <summary>
|
/// 开关无线配置弹窗
|
/// </summary>
|
static void ShowWirelessConfigDialog (byte subnetID, byte deviceID)
|
{
|
Dialog dialog = new Dialog () {
|
BackgroundColor = SkinStyle.Current.TextColor1,
|
Width = Application.GetRealWidth (480),
|
Height = Application.GetRealHeight (480),
|
};
|
int btnW = Application.GetRealWidth (420);
|
Button btnEquipmentTitle = new Button () {
|
Width = dialog.Width,
|
Height = Application.GetRealHeight (85),
|
BackgroundColor = 0xFF333333,
|
TextID = R.MyInternationalizationString.WirelessConfiguration,
|
TextAlignment = TextAlignment.Center,
|
Enable = false,
|
};
|
dialog.AddChidren (btnEquipmentTitle);
|
Button btnOpenConfig = new Button () {
|
X = Application.GetRealWidth (30),
|
Y = Application.GetRealHeight (205),
|
Width = btnW,
|
Height = Application.GetRealHeight (65),
|
TextID = R.MyInternationalizationString.Close,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = 0xFF333333,
|
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
|
Radius = 5,
|
};
|
dialog.AddChidren (btnOpenConfig);
|
btnOpenConfig.MouseUpEventHandler += (sender, e) => {
|
btnOpenConfig.IsSelected = !btnOpenConfig.IsSelected;
|
if (btnOpenConfig.IsSelected) {
|
Control.ControlBytesSend (Command.GotoConfigMode, subnetID, deviceID, new byte [] { });
|
btnOpenConfig.TextID = R.MyInternationalizationString.ON;
|
} else {
|
Control.ControlBytesSend (Command.CheckConfigSuccess, subnetID, deviceID, new byte [] { 1 });
|
btnOpenConfig.TextID = R.MyInternationalizationString.OFF;
|
}
|
};
|
//Button btnCloseConfig = new Button () {
|
// X = Application.GetRealWidth (30),
|
// Y = btnOpenConfig.Y + btnOpenConfig.Height + Application.GetRealHeight (50),
|
// Width = btnW,
|
// Height = Application.GetRealHeight (65),
|
// TextID = R.MyInternationalizationString.Close,
|
// TextAlignment = TextAlignment.Center,
|
// BackgroundColor = SkinStyle.Current.MusicEditTextBackgroundColor,
|
// SelectedBackgroundColor = SkinStyle.Current.SelectedTextColor,
|
//};
|
//dialog.AddChidren (btnCloseConfig);
|
//btnCloseConfig.MouseUpEventHandler += (sender, e) => {
|
//Control.ControlBytesSend (Command.CheckConfigSuccess, subnetID, deviceID, new byte [] { 1 });
|
//};
|
//---bottom--
|
Button btnBack = new Button () {
|
Width = Application.GetRealWidth (480),
|
Height = Application.GetRealHeight (85),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
Y = Application.GetRealHeight (480) - Application.GetRealHeight (85),
|
TextID = R.MyInternationalizationString.Confrim,
|
TextAlignment = TextAlignment.Center,
|
Radius = 1,
|
};
|
btnBack.MouseUpEventHandler += (s, e1) => {
|
dialog.Close ();
|
};
|
dialog.AddChidren (btnBack);
|
dialog.Show ();
|
}
|
|
/// <summary>
|
/// 弹出确认分配设备地址的窗口
|
/// </summary>
|
/// <param name="subnetID">Subnet I.</param>
|
/// <param name="deviceID">Device I.</param>
|
public static void ShowAssignedAddressDialog (byte subnetID, byte deviceID)
|
{
|
byte [] sendByte = new byte [] { 1, 0, 0, 0, 0 };
|
Dialog dialog = new Dialog () {
|
Width = Application.GetRealWidth (480),
|
Height = Application.GetRealHeight (480),
|
BackgroundColor = SkinStyle.Current.TextColor1,
|
};
|
int btnX = Application.GetRealWidth (420);
|
Button btnEquipmentTitle = new Button () {
|
Width = dialog.Width,
|
Height = Application.GetRealHeight (85),
|
BackgroundColor = 0xFF333333,
|
TextID = R.MyInternationalizationString.DistributionOfDeviceAddress,
|
TextAlignment = TextAlignment.Center,
|
Radius = 1,
|
};
|
dialog.AddChidren (btnEquipmentTitle);
|
Button btnAssignedAll = new Button () {
|
X = Application.GetRealWidth (30),
|
Y = Application.GetRealHeight (125),
|
Width = btnX,
|
Height = Application.GetRealHeight (65),
|
TextID = R.MyInternationalizationString.AssignedAddressAll,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = 0xFF333333,
|
};
|
dialog.AddChidren (btnAssignedAll);
|
btnAssignedAll.MouseUpEventHandler += (sender, e) => {
|
dialog.Close ();
|
sendByte [0] = 0x81;
|
AssignedAddressM (subnetID, deviceID, sendByte);
|
};
|
Button btnAssignedNew = new Button () {
|
X = Application.GetRealWidth (30),
|
Y = btnAssignedAll.Y + btnAssignedAll.Height + Application.GetRealHeight (50),
|
Width = btnX,
|
Height = Application.GetRealHeight (65),
|
TextID = R.MyInternationalizationString.AssignedAddressAdditional,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = 0xFF333333,
|
};
|
dialog.AddChidren (btnAssignedNew);
|
btnAssignedNew.MouseUpEventHandler += (sender, e) => {
|
sendByte [0] = 0x1;
|
dialog.Close ();
|
AssignedAddressM (subnetID, deviceID, sendByte);
|
};
|
//---bottom---
|
Button btnBack = new Button () {
|
Width = Application.GetRealWidth (480),
|
Height = Application.GetRealHeight (85),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
Y = Application.GetRealHeight (480) - Application.GetRealHeight (85),
|
TextID = R.MyInternationalizationString.Cancel,
|
TextAlignment = TextAlignment.Center,
|
Radius = 1,
|
};
|
btnBack.MouseUpEventHandler += (s, e1) => {
|
dialog.Close ();
|
};
|
dialog.AddChidren (btnBack);
|
dialog.Show ();
|
}
|
|
/// <summary>
|
/// 为设备分配地址
|
/// </summary>
|
public static void AssignedAddressM (byte subnetID, byte deviceID, byte [] sendByte)
|
{
|
string tipString = Language.StringByID (R.MyInternationalizationString.NewEquipmentNotConnected);
|
if (sendByte [0] == 0x1) {//追加设备
|
AssignedAddressAdditional (subnetID, deviceID, sendByte);
|
} else {
|
System.Threading.Tasks.Task.Run (() => {
|
Application.RunOnMainThread (() => {
|
Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
|
Language.StringByID (R.MyInternationalizationString.TipAssignedAddress),
|
Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim));
|
alert.ResultEventHandler += (object sender2, bool e2) => {
|
if (e2) {
|
MainPage.Loading.Start ();
|
foreach (string file in IO.FileUtils.ReadFiles ()) {
|
string [] fileStr = file.Split ('_');
|
if (fileStr.Length == 4 || fileStr.Length == 5) {
|
if (fileStr [0] == "Equipment" && fileStr [1] != typeof (OnePortBus).Name && fileStr [1] != typeof (OnePortWirelessFR).Name && fileStr [2] == subnetID.ToString ()) {
|
IO.FileUtils.DeleteFile (file);
|
}
|
}
|
}
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
byte [] usefulBytes = Control.ControlBytesSendHasReturn (Command.AssignedAddress, subnetID, deviceID, new byte [] { sendByte [0] });
|
if (usefulBytes != null) {
|
sendByte [0]++;
|
Array.Copy (usefulBytes, 1, sendByte, 1, 4);
|
usefulBytes = Control.ControlBytesSendHasReturn (Command.AssignedAddress, subnetID, deviceID, sendByte);
|
if (usefulBytes == null) {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
|
Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
}
|
usefulBytes = Control.ControlBytesSendHasReturn (Command.AssignedAddress, subnetID, deviceID, new byte [] { 0x1 });
|
Array.Copy (usefulBytes, 1, sendByte, 1, 4);
|
sendByte [0] = 2;
|
usefulBytes = Control.ControlBytesSendHasReturn (Command.AssignedAddress, subnetID, deviceID, sendByte);
|
if (usefulBytes != null) {
|
CommonPage.dt = System.DateTime.Now;
|
while (true) {
|
if ((DateTime.Now - CommonPage.dt).TotalSeconds > 9)
|
break;
|
System.Threading.Thread.Sleep (98);
|
}
|
}
|
} else {
|
Application.RunOnMainThread (() => {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
|
Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
}
|
} catch { } finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
}
|
};
|
alert.Show ();
|
});
|
});
|
}
|
}
|
|
public static void AssignedAddressAdditional (byte subnetID, byte deviceID, byte [] sendByte)
|
{
|
Dialog dialog = new Dialog () {
|
Width = Application.GetRealWidth (480),
|
Height = Application.GetRealHeight (680),
|
BackgroundColor = SkinStyle.Current.TextColor1,
|
};
|
int btnX = Application.GetRealWidth (420);
|
Button btnEquipmentTitle = new Button () {
|
Width = dialog.Width,
|
Height = Application.GetRealHeight (85),
|
BackgroundColor = 0xFF333333,
|
TextID = R.MyInternationalizationString.AssignedAddressAdditional,
|
TextAlignment = TextAlignment.Center,
|
Radius = 1,
|
};
|
dialog.AddChidren (btnEquipmentTitle);
|
|
|
Button btnAssigned = new Button () {
|
Y = Application.GetRealHeight (95),
|
X = Application.GetRealWidth (40),
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (100),
|
TextID = R.MyInternationalizationString.NewEquipmentNotConnected,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = 0xFF333333,
|
SelectedBackgroundColor = 0xFFDBDDDF,
|
};
|
dialog.AddChidren (btnAssigned);
|
Button btnAssigned1 = new Button () {
|
Y = btnAssigned.Bottom + Application.GetRealHeight (10),
|
X = Application.GetRealWidth (40),
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (100),
|
TextID = R.MyInternationalizationString.RefreshDeviceList,
|
Visible = false,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = 0xFF333333,
|
SelectedBackgroundColor = 0xFFDBDDDF,
|
};
|
dialog.AddChidren (btnAssigned1);
|
|
Button btnAssigned3 = new Button () {
|
Y = btnAssigned1.Bottom + Application.GetRealHeight (10),
|
X = Application.GetRealWidth (40),
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (120),
|
Visible = false,
|
TextID = R.MyInternationalizationString.PleaseAccessNeedToAddEquipment,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = 0xFF333333,
|
SelectedBackgroundColor = 0xFFDBDDDF,
|
};
|
dialog.AddChidren (btnAssigned3);
|
Button btnAssigned4 = new Button () {
|
Y = btnAssigned3.Bottom + Application.GetRealHeight (10),
|
X = Application.GetRealWidth (40),
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (120),
|
Visible = false,
|
TextID = R.MyInternationalizationString.StartAllocatingAddresses,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = 0xFF333333,
|
SelectedBackgroundColor = 0xFFDBDDDF,
|
};
|
dialog.AddChidren (btnAssigned4);
|
btnAssigned.MouseUpEventHandler += (sender, e) => {
|
btnAssigned.Enable = false;
|
btnAssigned.IsSelected = true;
|
btnAssigned1.Visible = true;
|
};
|
btnAssigned1.MouseUpEventHandler += (sender, e) => {
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Start ("Loading...");
|
});
|
byte [] usefulBytes = Control.ControlBytesSendHasReturn (Command.AssignedAddress, subnetID, deviceID, new byte [] { 0x11 });
|
if (usefulBytes != null) {
|
usefulBytes = Control.ControlBytesSendHasReturn (Command.AssignedAddress, subnetID, deviceID, new byte [] { 0x12, usefulBytes [1], usefulBytes [2], usefulBytes [3], usefulBytes [4] });
|
if (usefulBytes != null) {
|
if (usefulBytes [0] == 0x12) {
|
CommonPage.dt = System.DateTime.Now;
|
while (true) {
|
if ((DateTime.Now - CommonPage.dt).TotalSeconds > 9)
|
break;
|
System.Threading.Thread.Sleep (98);
|
}
|
}
|
Application.RunOnMainThread (() => {
|
btnAssigned1.Enable = false;
|
btnAssigned1.IsSelected = true;
|
btnAssigned3.Visible = true;
|
});
|
} else {
|
Application.RunOnMainThread (() => {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
|
Language.StringByID (R.MyInternationalizationString.TheGatewayAssignmentAddressFailed),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
}
|
} else {
|
Application.RunOnMainThread (() => {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
|
Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
}
|
} catch (Exception ex) {
|
Console.WriteLine (ex.Message);
|
} finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
};
|
btnAssigned3.MouseUpEventHandler += (sender, e) => {
|
btnAssigned3.Enable = false;
|
btnAssigned3.IsSelected = true;
|
btnAssigned4.Visible = true;
|
};
|
btnAssigned4.MouseUpEventHandler += (sender, e) => {
|
Application.RunOnMainThread (() => {
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
Application.RunOnMainThread (() => {
|
dialog.Close ();
|
MainPage.Loading.Start ("Loading...");
|
});
|
byte [] usefulBytes1 = Control.ControlBytesSendHasReturn (Command.AssignedAddress, subnetID, deviceID, new byte [] { 0x1 });
|
if (usefulBytes1 != null && usefulBytes1 [0] == 1) {
|
sendByte [0]++;
|
Array.Copy (usefulBytes1, 1, sendByte, 1, 4);
|
usefulBytes1 = Control.ControlBytesSendHasReturn (Command.AssignedAddress, subnetID, deviceID, sendByte);
|
if (usefulBytes1 [0] == 2) {
|
CommonPage.dt = System.DateTime.Now;
|
while (true) {
|
if ((DateTime.Now - CommonPage.dt).TotalSeconds > 9)
|
break;
|
System.Threading.Thread.Sleep (98);
|
}
|
}
|
}
|
} catch { } finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
});
|
};
|
Button btnBack = new Button () {
|
Width = Application.GetRealWidth (480),
|
Height = Application.GetRealHeight (85),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
Y = Application.GetRealHeight (680) - Application.GetRealHeight (85),
|
TextID = R.MyInternationalizationString.Cancel,
|
TextAlignment = TextAlignment.Center,
|
Radius = 1,
|
};
|
btnBack.MouseUpEventHandler += (s, e1) => {
|
dialog.Close ();
|
};
|
dialog.AddChidren (btnBack);
|
dialog.Show ();
|
}
|
|
public static void UpdataGatewayList (byte subnetID)
|
{
|
MainPage.Loading.Start ();
|
SystemMiddle.ThirdScrolView.RemoveAll ();
|
|
Button btnTitle = new Button () {
|
Height = Application.GetRealHeight (140),
|
Text = Language.StringByID (R.MyInternationalizationString.EquipmentList).Replace (":", ""),
|
TextAlignment = TextAlignment.Center,
|
TextSize = 16
|
};
|
SystemMiddle.ThirdScrolView.TitleView.AddChidren (btnTitle);
|
|
|
FrameLayout tipView = new FrameLayout () {
|
Height = Application.GetRealHeight (100),
|
};
|
SystemMiddle.ThirdScrolView.AddChidren (tipView);
|
|
Button btnNormal = new Button () {
|
Width = Application.GetRealWidth (30),
|
Height = Application.GetRealHeight (30),
|
X = Application.GetRealWidth (55),
|
Gravity = Gravity.CenterVertical,
|
BackgroundColor = SkinStyle.Current.TextColor1,
|
Radius = 2,
|
Enable = false
|
};
|
tipView.AddChidren (btnNormal);
|
Button btnNormalText = new Button () {
|
Width = Application.GetRealWidth (120),
|
TextID = R.MyInternationalizationString.Normal,
|
TextAlignment = TextAlignment.CenterLeft,
|
X = btnNormal.Right + Application.GetRealWidth (5),
|
Enable = false
|
};
|
tipView.AddChidren (btnNormalText);
|
Button btnNewDiscovery = new Button () {
|
Width = Application.GetRealWidth (30),
|
Height = Application.GetRealHeight (30),
|
Radius = 2,
|
BackgroundColor = SkinStyle.Current.newDeviceBG,
|
X = btnNormalText.Right + Application.GetRealWidth (20),
|
Y = btnNormal.Y,
|
Enable = false
|
};
|
tipView.AddChidren (btnNewDiscovery);
|
Button btnNewDiscoveryText = new Button () {
|
Width = Application.GetRealWidth (200),
|
TextID = R.MyInternationalizationString.NewDiscovery,
|
TextAlignment = TextAlignment.CenterLeft,
|
X = btnNewDiscovery.Right + Application.GetRealWidth (5),
|
Enable = false
|
};
|
tipView.AddChidren (btnNewDiscoveryText);
|
Button btnLost = new Button () {
|
Width = Application.GetRealWidth (30),
|
Height = Application.GetRealHeight (30),
|
Radius = 2,
|
BackgroundColor = SkinStyle.Current.LostDeviceBG,
|
X = btnNewDiscoveryText.Right + Application.GetRealWidth (20),
|
Y = btnNormal.Y,
|
Enable = false
|
};
|
tipView.AddChidren (btnLost);
|
Button btnLostText = new Button () {
|
Width = Application.GetRealWidth (120),
|
TextID = R.MyInternationalizationString.Lost,
|
TextAlignment = TextAlignment.CenterLeft,
|
X = btnLost.Right + Application.GetRealWidth (5),
|
Enable = false
|
};
|
tipView.AddChidren (btnLostText);
|
|
CommonPage.FindGatewayChilren = true;
|
CommonPage.LocalPhoneFindDevice = true;
|
var oldFilesList = IO.FileUtils.ReadFiles ().FindAll ((obj) => obj.Split ('_') [0] == "Equipment"
|
&& obj.Split ('_').Length == 4 && obj.Split ('_') [2] == subnetID.ToString ());
|
//全部重新更新设备下面所有的回路信息
|
if (th != null) {
|
th.Abort ();
|
th = null;
|
}
|
SystemMiddle.readOnePort (() => {
|
List<Common> oldCommon = new List<Common> ();
|
foreach (var deviceFile in oldFilesList) {
|
byte [] equipmentUsefullBytes = IO.FileUtils.ReadFile (deviceFile);
|
string equipmentString;
|
Common common = null;
|
equipmentString = CommonPage.MyEncodingUTF8.GetString (equipmentUsefullBytes);
|
common = Newtonsoft.Json.JsonConvert.DeserializeObject<Common> (equipmentString);
|
if (common == null) {
|
continue;
|
}
|
if (common.isMixBox) {
|
continue;
|
}
|
oldCommon.Add (common);
|
}
|
CommonPage.FindGatewayChilren = false;
|
MainPage.Loading.Hide ();
|
for (int i = 0; i < CommonPage.DeviceList.Count; i++) {
|
Common common = CommonPage.DeviceList [i];
|
if (common.Type == DeviceType.MusicModel)
|
continue;
|
if (common.SubnetID == subnetID && common.DeviceID != 0) {
|
if (common.isMixBox) {
|
Console.WriteLine ("IsMixBox");
|
continue;
|
}
|
FrameLayout commonView = new FrameLayout () {
|
Height = Application.GetRealHeight (100),
|
};
|
SystemMiddle.ThirdScrolView.AddChidren (commonView);
|
#region Show Device
|
Button btn = new Button () {
|
X = Application.GetRealWidth (50),
|
Gravity = Gravity.CenterVertical,
|
Height = Application.GetRealHeight (60),
|
Width = Application.GetRealWidth (60),
|
};
|
|
string strDeviceType = "";
|
if (common.Type == DeviceType.LightSwitch || common.Type == DeviceType.LightDimming ||
|
common.Type == DeviceType.LightMixSwitch || common.Type == DeviceType.LightMixDimming
|
|| common.Type == DeviceType.LightEnergySwitch
|
|| common.Type == DeviceType.LightDALI || common.Type == DeviceType.LightLogic) {
|
strDeviceType = Language.StringByID (R.MyInternationalizationString.Lights);
|
btn.UnSelectedImagePath = "Item/Light.png";
|
} else if (common.Type == DeviceType.HVAC || common.Type == DeviceType.ACInfrared || common.Type == DeviceType.ACPanel) {
|
btn.UnSelectedImagePath = "AC/AC.png";
|
strDeviceType = Language.StringByID (R.MyInternationalizationString.ACHost);
|
} else if (common.Type == DeviceType.CurtainModel || common.Type == DeviceType.CurtainTrietex || common.Type == DeviceType.CurtainRoller) {
|
btn.UnSelectedImagePath = "Curtain/Curtain.png";
|
strDeviceType = Language.StringByID (R.MyInternationalizationString.Curtains);
|
} else if (common.Type == DeviceType.ButtonPanel) {
|
btn.UnSelectedImagePath = "Item/Panel.png";
|
strDeviceType = Language.StringByID (R.MyInternationalizationString.PanelDevice);
|
} else if (common.Type == DeviceType.FoolHeat || common.Type == DeviceType.FoolHeatPanel) {
|
btn.UnSelectedImagePath = "Item/FloorHeating.png";
|
strDeviceType = Language.StringByID (R.MyInternationalizationString.FoolHeat);
|
} else if (common.Type == DeviceType.DryContact) {
|
btn.X = Application.GetRealWidth (65);
|
btn.Width = Application.GetRealWidth (30);
|
btn.Height = Application.GetRealHeight (30);
|
btn.UnSelectedImagePath = "Item/DryContact.png";
|
strDeviceType = Language.StringByID (R.MyInternationalizationString.DryContactPanel);
|
} else if (common.Type == DeviceType.InfraredMode) {
|
btn.UnSelectedImagePath = "Item/InfraredModel.png";
|
strDeviceType = Language.StringByID (R.MyInternationalizationString.InfraredCoding);
|
} else if (common.Type == DeviceType.ACInfrared) {
|
btn.UnSelectedImagePath = "AC/AC.png";
|
strDeviceType = Language.StringByID (R.MyInternationalizationString.InfraredCoding);
|
} else if (common.Type == DeviceType.MusicModel) {
|
btn.UnSelectedImagePath = "Item/Music.png";
|
strDeviceType = Language.StringByID (R.MyInternationalizationString.MusicModel);
|
} else if (common.Type == DeviceType.FanModule) {
|
btn.UnSelectedImagePath = "Fan/Fan.png";
|
strDeviceType = Language.StringByID (R.MyInternationalizationString.Fan);
|
} else if (common.Type == DeviceType.LogicModule) {
|
btn.UnSelectedImagePath = "Item/LogicModule.png";
|
strDeviceType = Language.StringByID (R.MyInternationalizationString.LogicModule);
|
}
|
Button btn1 = new Button () {
|
X = btn.Right + Application.GetRealWidth (20),
|
Gravity = Gravity.CenterVertical,
|
Text = common.Name,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (42),
|
Width = Application.GetRealWidth (342),
|
};
|
Button btn2 = new Button () {
|
X = Application.GetRealWidth (550),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "Item/More2.png",
|
SelectedImagePath = "Item/More2Selected.png",
|
Height = Application.GetRealHeight (42),
|
Width = Application.GetRealWidth (40),
|
};
|
|
EventHandler<MouseEventArgs> eHandlerC = new EventHandler<MouseEventArgs> (delegate (object sender, MouseEventArgs e) {
|
btn2.IsSelected = true;
|
Dialog dialog = new Dialog () {
|
Width = Application.GetRealWidth (494),
|
Height = Application.GetRealHeight (488),
|
};
|
FrameLayout dialogBodyView = new FrameLayout () {
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
Radius = 5,
|
BorderColor = SkinStyle.Current.Transparent,
|
BorderWidth = 0,
|
};
|
dialog.AddChidren (dialogBodyView);
|
|
|
Button btnEquipmentTitle = new Button () {
|
Width = Application.GetRealWidth (482),
|
Height = Application.GetRealHeight (70),
|
TextAlignment = TextAlignment.Center,
|
Text = strDeviceType,
|
BackgroundColor = 0xFF333333,
|
Radius = 2,
|
};
|
dialog.AddChidren (btnEquipmentTitle);
|
Button lblChangeName = new Button () {
|
X = Application.GetRealWidth (40),
|
Y = btnEquipmentTitle.Bottom + Application.GetRealHeight (10),
|
Width = dialog.Width - 2 * btnEquipmentTitle.X,
|
Height = btnEquipmentTitle.Height,
|
TextID = R.MyInternationalizationString.EquipmentName,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = SkinStyle.Current.MainColor
|
};
|
dialog.AddChidren (lblChangeName);
|
EditText btnChangeName = new EditText () {
|
X = lblChangeName.X,
|
Y = lblChangeName.Bottom + Application.GetRealHeight (10),
|
Width = Application.GetRealWidth (425),
|
Height = Application.GetRealHeight (50),
|
TextAlignment = TextAlignment.CenterLeft,
|
Text = " " + common.Name,
|
TextColor = 0xFF000000,
|
BackgroundColor = 0xFF000000,
|
};
|
dialog.AddChidren (btnChangeName);
|
|
Button btnFindDevcie = new Button () {
|
Y = btnChangeName.Bottom + Application.GetRealHeight (50),
|
Gravity = Gravity.CenterHorizontal,
|
Width = Application.GetRealWidth (300),
|
Height = Application.GetRealHeight (70),
|
TextID = R.MyInternationalizationString.PositioningEquipment,
|
TextAlignment = TextAlignment.Center,
|
Radius = (uint)Application.GetRealHeight (5),
|
BackgroundColor = 0xFF333333,
|
SelectedBackgroundColor = SkinStyle.Current.SelectedColor
|
//UnSelectedImagePath = "Item/PositioningDialogButton.png",
|
};
|
dialog.AddChidren (btnFindDevcie);
|
btnFindDevcie.MouseDownEventHandler += (sender1, e1) => {
|
btnFindDevcie.IsSelected = true;
|
};
|
btnFindDevcie.MouseUpEventHandler += (sender1, e1) => {
|
btnFindDevcie.IsSelected = false;
|
//查找设备,发送命令让设备闪烁,面板设备与其他设备发送的数据不一样,多了一个byte,固定为:0(相当于多余的,做硬件的不想改命令)
|
Control.ControlBytesSend (Command.PositioningEquipment, common.SubnetID, common.DeviceID, new byte [] { 3 });
|
};
|
//---bottom--
|
Button btnBack = new Button () {
|
UnSelectedImagePath = "Item/PositioningDialogBack.png",
|
Width = Application.GetRealWidth (119),
|
Height = Application.GetRealHeight (85),
|
Y = Application.GetRealHeight (490 - 85),
|
BackgroundColor = 0xFF333333,
|
};
|
btnBack.MouseUpEventHandler += (s, e1) => {
|
dialog.Close ();
|
btn2.IsSelected = false;
|
};
|
dialog.AddChidren (btnBack);
|
Button btnLineV = new Button () {
|
Width = 1,
|
Height = btnBack.Height,
|
BackgroundColor = 0xFF333333,
|
X = btnBack.Right,
|
Y = btnBack.Y
|
};
|
dialog.AddChidren (btnLineV);
|
Button btnSave = new Button () {
|
Width = Application.GetRealWidth (494 - 119),
|
Height = Application.GetRealHeight (85),
|
X = btnLineV.Right,
|
Y = btnBack.Y,
|
TextID = R.MyInternationalizationString.SAVE,
|
TextColor = SkinStyle.Current.TextColor1,
|
BackgroundColor = 0xFF333333,
|
};
|
dialog.AddChidren (btnSave);
|
btnSave.MouseUpEventHandler += (sender2, e2) => {
|
CommonPage.UpdateRemark (common.SubnetID, common.DeviceID, btnChangeName.Text.Trim ());
|
btn1.Text = btnChangeName.Text;
|
dialog.Close ();
|
common.Name = btnChangeName.Text.Trim ();
|
IO.FileUtils.SaveEquipmentMessage (common);
|
btn2.IsSelected = false;
|
};
|
dialog.Show ();
|
|
});
|
btn1.MouseUpEventHandler += eHandlerC;
|
btn2.MouseUpEventHandler += eHandlerC;
|
commonView.AddChidren (btn);
|
commonView.AddChidren (btn1);
|
commonView.AddChidren (btn2);
|
//新增
|
var oldC = oldCommon.Find ((obj) => obj.SubnetID == common.SubnetID && obj.DeviceID == common.DeviceID && obj.LoopID == common.LoopID);
|
if (oldC == null) {
|
Button btnBG = new Button () {
|
Height = Application.GetRealHeight (60),
|
Width = Application.GetRealWidth (60),
|
X = Application.GetRealWidth (50),
|
Gravity = Gravity.CenterVertical,
|
Radius = 3,
|
BackgroundColor = SkinStyle.Current.newDeviceBG
|
};
|
commonView.AddChidren (btnBG);
|
} else {
|
oldCommon.Remove (oldC);
|
}
|
|
Button btnNul = new Button () {
|
Y = Application.GetRealHeight (100) - 2,
|
Height = 1,
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
commonView.AddChidren (btnNul);
|
Button btnNull = new Button () {
|
Y = Application.GetRealHeight (100) - 1,
|
Height = 1,
|
BackgroundColor = 0xFF2f2f2f,
|
};
|
commonView.AddChidren (btnNull);
|
#endregion
|
}
|
}
|
|
for (int i = 0; i < oldCommon.Count; i++) {
|
Common common = oldCommon [i];
|
if (common.SubnetID == subnetID && common.DeviceID != 0) {
|
if (common.isMixBox) {
|
Console.WriteLine ("IsMixBox");
|
continue;
|
}
|
FrameLayout commonView = new FrameLayout () {
|
Height = Application.GetRealHeight (100),
|
};
|
SystemMiddle.ThirdScrolView.AddChidren (commonView);
|
Button btn = new Button () {
|
X = Application.GetRealWidth (50),
|
Gravity = Gravity.CenterVertical,
|
Height = Application.GetRealHeight (60),
|
Width = Application.GetRealWidth (60),
|
};
|
|
if (common.Type == DeviceType.LightSwitch || common.Type == DeviceType.LightDimming ||
|
common.Type == DeviceType.LightMixSwitch || common.Type == DeviceType.LightMixDimming
|
|| common.Type == DeviceType.LightEnergySwitch
|
|| common.Type == DeviceType.LightDALI || common.Type == DeviceType.LightLogic) {
|
btn.UnSelectedImagePath = "Item/Light.png";
|
} else if (common.Type == DeviceType.HVAC || common.Type == DeviceType.ACInfrared || common.Type == DeviceType.ACPanel) {
|
btn.UnSelectedImagePath = "AC/AC.png";
|
} else if (common.Type == DeviceType.CurtainModel || common.Type == DeviceType.CurtainTrietex || common.Type == DeviceType.CurtainRoller) {
|
btn.UnSelectedImagePath = "Curtain/Curtain.png";
|
} else if (common.Type == DeviceType.ButtonPanel) {
|
btn.UnSelectedImagePath = "Item/Panel.png";
|
} else if (common.Type == DeviceType.FoolHeat || common.Type == DeviceType.FoolHeatPanel) {
|
btn.UnSelectedImagePath = "Item/FloorHeating.png";
|
} else if (common.Type == DeviceType.DryContact) {
|
btn.X = Application.GetRealWidth (65);
|
btn.Width = Application.GetRealWidth (30);
|
btn.Height = Application.GetRealHeight (30);
|
btn.UnSelectedImagePath = "Item/DryContact.png";
|
} else if (common.Type == DeviceType.InfraredMode) {
|
btn.UnSelectedImagePath = "Item/InfraredModel.png";
|
} else if (common.Type == DeviceType.ACInfrared) {
|
btn.UnSelectedImagePath = "AC/AC.png";
|
} else if (common.Type == DeviceType.MusicModel) {
|
return;
|
btn.UnSelectedImagePath = "Item/Music.png";
|
} else if (common.Type == DeviceType.LogicModule) {
|
btn.UnSelectedImagePath = "Item/LogicModule.png";
|
} else if (common.Type == DeviceType.FanModule) {
|
btn.UnSelectedImagePath = "Fan/Fan.png";
|
}
|
Button btn1 = new Button () {
|
X = Application.GetRealWidth (144),
|
Gravity = Gravity.CenterVertical,
|
Text = common.Name,
|
TextAlignment = TextAlignment.CenterLeft,
|
Height = Application.GetRealHeight (42),
|
Width = Application.GetRealWidth (342),
|
};
|
|
commonView.AddChidren (btn);
|
commonView.AddChidren (btn1);
|
Button btnBG = new Button () {
|
Height = Application.GetRealHeight (60),
|
Width = Application.GetRealWidth (60),
|
X = Application.GetRealWidth (50),
|
Gravity = Gravity.CenterVertical,
|
Radius = 3,
|
BackgroundColor = 0xFFDBDDDF
|
};
|
commonView.AddChidren (btnBG);
|
|
Button btnNul = new Button () {
|
Y = Application.GetRealHeight (100) - 2,
|
Height = 1,
|
BackgroundColor = SkinStyle.Current.LostDeviceBG,
|
};
|
commonView.AddChidren (btnNul);
|
Button btnNull = new Button () {
|
Y = Application.GetRealHeight (100) - 1,
|
Height = 1,
|
BackgroundColor = 0xFF2f2f2f,
|
};
|
commonView.AddChidren (btnNull);
|
}
|
}
|
|
th = new Thread ((obj) => {
|
Waiting = false;
|
CommonPage.DeviceLoopList.Clear ();
|
var listCommonEquipment = CommonPage.DeviceList;
|
for (int i = 0; i < listCommonEquipment.Count; i++) {
|
var common = listCommonEquipment [i];
|
if (common == null)
|
continue;
|
Console.WriteLine ("读取设备各个回路的具体信息,当前设备名称:" + common.Name + " 回路总数:" + common.LoopCount);
|
byte bigClass = common.BigClass;
|
byte minClass = common.MinClass;
|
int count = common.LoopCount;
|
for (int k = 1, j = 0; k <= count; k++) {
|
while (Waiting) {
|
Thread.Sleep (100);
|
}
|
if (Control.ControlBytesSendHasReturn (Command.ReadDeviceLoopInfo, common.SubnetID, common.DeviceID,
|
new byte [] { bigClass, minClass, (byte)k }) == null) {
|
j++;
|
//连续两次读取不到数据则跳出该循环
|
if (j == 2 && k == 2)
|
break;
|
}
|
}
|
}
|
CommonPage.LocalPhoneFindDevice = false;
|
th = null;
|
});
|
th.Start ();
|
}, subnetID);
|
}
|
|
static Thread th;
|
//等待红外读取红外类型
|
public static bool Waiting;
|
}
|
}
|