using System;
using System.Collections.Generic;
using System.Threading;
namespace Shared.SimpleControl.Phone
{
///
/// 无线网关数据设置界面
///
public class SystemWirelessGateway : FrameLayout
{
public override void RemoveFromParent ()
{
SystemMiddle.curGatewayMAC = "";
SystemMiddle.curGatewayIP = "";
base.RemoveFromParent ();
}
///
/// 更新无线网关数据
///
void UpdateOnePorWirelessFR (OnePortWirelessFR onePortWirelessFR)
{
System.Threading.Tasks.Task.Run (() => {
try {
Application.RunOnMainThread (() => {
MainPage.Loading.Start ("Sending...");
});
byte [] bytes = new byte [78];
bytes [0] = onePortWirelessFR.BigClass;
bytes [1] = onePortWirelessFR.MinClass;
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)
{
RemoveAll ();
MainPage.Loading.Start ();
try {
CommonPage.FindGatewayChilrenIPAddress = gatewayDevice.IPAddress;
System.Threading.Tasks.Task.Run (() => {
CommonPage.RandomHigh = (byte)new Random ().Next (255);
CommonPage.RandomLow = (byte)new Random ().Next (255);
var gatewayInfo = Control.ControlBytesSendHasReturn (Command.ReadGateway, gatewayDevice.SubnetID, gatewayDevice.DeviceID, new byte [] { CommonPage.RandomHigh, CommonPage.RandomLow });
Application.RunOnMainThread (() => {
VerticalScrolViewLayout sView = new VerticalScrolViewLayout () {
Height = Application.GetRealHeight (844),
};
AddChidren (sView);
if (gatewayInfo == null) {
new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline),
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
return;
}
//var one = IO.FileUtils.ReadEquipmentMessage (gatewayDevice);
//gatewayDevice = Newtonsoft.Json.JsonConvert.DeserializeObject (one);
SystemMiddle.curGatewayMAC = gatewayDevice.MAC;
SystemMiddle.curGatewayIP = gatewayDevice.IPAddress;
#region ---top---
RowLayout flTitleRow = new RowLayout () {
Height = Application.GetRealHeight (98),
Width = LayoutParams.MatchParent,
BackgroundColor = SkinStyle.Current.MainColor,
};
sView.AddChidren (flTitleRow);
Button backButton = new Button () {
Height = Application.GetRealHeight (90),
Width = Application.GetRealWidth (85),
UnSelectedImagePath = "Item/Back.png",
SelectedImagePath = "Item/BackSelected.png",
Gravity = Gravity.CenterVertical,
};
backButton.MouseUpEventHandler += (sender, e) => {
(Parent as PageLayout).PageIndex -= 1;
new SystemMiddle ().ShowGateWayView ();
SystemMiddle.curGatewayMAC = "";
SystemMiddle.curGatewayIP = "";
};
flTitleRow.AddChidren (backButton);
string strOnePortWirelessFRRemark = gatewayDevice.Name.ToString ();
EditText textButton = new EditText () {
X = Application.GetRealWidth (95),
Height = Application.GetRealHeight (50),
Width = Application.GetRealWidth (380),
Gravity = Gravity.CenterVertical,
Text = strOnePortWirelessFRRemark,
BackgroundColor = SkinStyle.Current.Transparent,
SelectedBackgroundColor = SkinStyle.Current.SysEditBox,
Enable = false,
TextColor = SkinStyle.Current.TextColor1,
BorderColor = SkinStyle.Current.Transparent,
BorderWidth = 0,
Radius = 5,
};
flTitleRow.AddChidren (textButton);
Button editor = new Button () {
X = Application.GetRealWidth (640 - 70 - 30),
Height = Application.GetRealHeight (90),
Width = Application.GetRealWidth (70),
UnSelectedImagePath = "Item/Editor.png",
SelectedImagePath = "Item/EditorSelected.png",
Gravity = Gravity.CenterVertical,
};
flTitleRow.AddChidren (editor);
editor.MouseUpEventHandler += (sender, e) => {
if (editor.IsSelected) {
MainPage.Loading.Start ();
gatewayDevice.Name = textButton.Text.Trim ();
editor.IsSelected = textButton.IsSelected = textButton.Enable = false;
//textButton.BackgroundColor = SkinStyle.Current.Transparent;
CommonPage.UpdateRemark (gatewayDevice.SubnetID, gatewayDevice.DeviceID, gatewayDevice.Name);
IO.FileUtils.SaveEquipmentMessage (gatewayDevice);
editor.IsSelected = false;
textButton.Enable = false;
textButton.IsSelected = false;
MainPage.Loading.Hide ();
} else {
textButton.Enable = true;
textButton.IsSelected = true;
editor.IsSelected = true;
//textButton.BackgroundColor = 0xFF494949;
}
};
Button gatewayInfoSwitch = new Button () {
Height = Application.GetRealHeight (90),
Width = Application.GetRealWidth (90),
UnSelectedImagePath = "Item/GatwayInfoHide.png",
SelectedImagePath = "Item/GatwayInfoShow.png",
Gravity = Gravity.CenterVertical,
X = editor.Right + Application.GetRealWidth (5),
TextColor = SkinStyle.Current.TextColor1
};
flTitleRow.AddChidren (gatewayInfoSwitch);
#endregion
#region GatewayID
RowLayout frameLayoutGatewayID = new RowLayout () {
Height = Application.GetRealHeight (98),
Width = LayoutParams.MatchParent,
BackgroundColor = SkinStyle.Current.MainColor,
};
sView.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,
TextColor = SkinStyle.Current.TextColor1,
};
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,
TextColor = SkinStyle.Current.TextColor1
};
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 = SkinStyle.Current.SysEditBox,
BackgroundColor = SkinStyle.Current.Transparent,
Enable = false,
TextColor = SkinStyle.Current.TextColor1,
BorderColor = SkinStyle.Current.Transparent,
BorderWidth = 1,
Radius = 5,
};
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,
TextColor = SkinStyle.Current.TextColor1
};
gatewayIDEdit.X = flTitleRow.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;
etGatewayID.BackgroundColor = SkinStyle.Current.Transparent;
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);
#endregion
#region--------------NetWork----------------------
RowLayout flNetWorkTop = new RowLayout () {
Height = Application.GetRealHeight (98),
Width = LayoutParams.MatchParent,
BackgroundColor = SkinStyle.Current.MainColor,
};
sView.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,
TextColor = SkinStyle.Current.TextColor1
};
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 = flTitleRow.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);
//-----------------------------------------------------------------------------------
FrameLayout frameLayout2 = new FrameLayout () {
Height = Application.GetRealHeight (798),
Width = LayoutParams.MatchParent,
};
sView.AddChidren (frameLayout2);
Button dhcp = new Button () {
X = gatewayIDName.X,
TextAlignment = TextAlignment.CenterLeft,
Height = Application.GetRealHeight (60),
Width = Application.GetRealWidth (360),
Text = "DHCP:",
Y = Application.GetRealHeight (10),
TextColor = SkinStyle.Current.TextColor1
};
frameLayout2.AddChidren (dhcp);
Button btnDHCPcheck = new Button () {
Height = Application.GetMinRealAverage (98),
Width = Application.GetMinRealAverage (76),
UnSelectedImagePath = "Item/Check.png",
SelectedImagePath = "Item/CheckSelected.png",
IsSelected = gatewayDevice.DHCP,
TextColor = SkinStyle.Current.TextColor1
};
btnDHCPcheck.X = flTitleRow.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),
TextColor = SkinStyle.Current.TextColor1
};
frameLayout2.AddChidren (lblIPAddresses);
EditText etIPAddresses = new EditText () {
X = dhcp.X,
TextAlignment = TextAlignment.CenterLeft,
Height = Application.GetRealHeight (55),
Width = Application.GetRealWidth (440),
Text = " " + gatewayDevice.IPAddress,
//UnSelectedImagePath = "Item/TextBox.png",
//BackgroundColor = SkinStyle.Current.SysEditBox,
Y = lblIPAddresses.Bottom + Application.GetRealHeight (2),
TextColor = SkinStyle.Current.TextColor1,
BorderColor = SkinStyle.Current.BorderColor,
BorderWidth = 1,
Radius = 5,
};
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),
TextColor = SkinStyle.Current.TextColor1
};
frameLayout2.AddChidren (lblSubnetMask);
EditText etSubnetMask = new EditText () {
X = dhcp.X,
TextAlignment = TextAlignment.CenterLeft,
Height = Application.GetRealHeight (55),
Width = Application.GetRealWidth (440),
Text = " " + gatewayDevice.SubnetMask,
//UnSelectedImagePath = "Item/TextBox.png",
//BackgroundColor = SkinStyle.Current.SysEditBox,
BorderColor = SkinStyle.Current.BorderColor,
BorderWidth = 1,
Radius = 5,
Y = lblSubnetMask.Bottom + Application.GetRealHeight (2),
TextColor = SkinStyle.Current.TextColor1,
};
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),
TextColor = SkinStyle.Current.TextColor1
};
frameLayout2.AddChidren (lblRoutingIP);
EditText etRoutingIP = new EditText () {
X = dhcp.X,
TextAlignment = TextAlignment.CenterLeft,
Height = Application.GetRealHeight (55),
Width = Application.GetRealWidth (440),
Text = " " + gatewayDevice.RouteIPAddress,
//UnSelectedImagePath = "Item/TextBox.png",
//BackgroundColor = SkinStyle.Current.SysEditBox,
BorderColor = SkinStyle.Current.BorderColor,
BorderWidth = 1,
Radius = 5,
Y = lblRoutingIP.Bottom + Application.GetRealHeight (2),
TextColor = SkinStyle.Current.TextColor1,
};
frameLayout2.AddChidren (etRoutingIP);
Button btnDHCPSave = new Button () {
X = (Application.CurrentWidth / 2 - 30),
Height = Application.GetRealHeight (55),
Width = Application.GetRealWidth (98),
BackgroundColor = SkinStyle.Current.ButtonColor,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
BorderWidth = 1,
Radius = 5,
BorderColor = SkinStyle.Current.Transparent,
TextID = R.MyInternationalizationString.SAVE,
Y = etRoutingIP.Bottom + Application.GetRealHeight (12),
TextColor = SkinStyle.Current.TextColor1
};
frameLayout2.AddChidren (btnDHCPSave);
frameLayout2.Height = btnDHCPSave.Bottom + Application.GetRealHeight (20);
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 ();
}
string [] ipMac = gatewayDevice.IPMAC.Split ('.');
//ipMAC前三位HDL 需要特殊处理
bytes [0 + 8] = (byte)(ipMac [0].ToCharArray () [0]);
bytes [1 + 8] = (byte)(ipMac [1].ToCharArray () [0]);
bytes [2 + 8] = (byte)(ipMac [2].ToCharArray () [0]);
bytes [3 + 8] = byte.Parse (ipMac [3]);
bytes [4 + 8] = byte.Parse (ipMac [4]);
bytes [5 + 8] = byte.Parse (ipMac [5]);
string [] subnetMask = gatewayDevice.SubnetMask.Split ('.');
bytes [14] = 0x17;
bytes [15] = 0x70;
for (int i = 0; i < subnetMask.Length; i++) {
bytes [i + 16] = byte.Parse (subnetMask [i]);
}
if (Control.ControlBytesSendHasReturn (Command.UpdateGatewayIp,
gatewayDevice.SubnetID, gatewayDevice.DeviceID, bytes) != null) {
IO.FileUtils.SaveEquipmentMessage (gatewayDevice);
}
//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 ();
}
string [] ipMac = gatewayDevice.IPMAC.Split ('.');
//ipMAC前三位HDL 需要特殊处理
bytes [0 + 8] = (byte)(ipMac [0].ToCharArray () [0]);
bytes [1 + 8] = (byte)(ipMac [1].ToCharArray () [0]);
bytes [2 + 8] = (byte)(ipMac [2].ToCharArray () [0]);
bytes [3 + 8] = byte.Parse (ipMac [3]);
bytes [4 + 8] = byte.Parse (ipMac [4]);
bytes [5 + 8] = byte.Parse (ipMac [5]);
string [] subnetMask = gatewayDevice.SubnetMask.Split ('.');
bytes [14] = 0x17;
bytes [15] = 0x70;
for (int i = 0; i < subnetMask.Length; i++) {
bytes [i + 16] = byte.Parse (subnetMask [i]);
}
if (Control.ControlBytesSendHasReturn (Command.UpdateGatewayIp,
gatewayDevice.SubnetID, gatewayDevice.DeviceID, bytes) != null) {
IO.FileUtils.SaveEquipmentMessage (gatewayDevice);
}
//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;
}
#endregion
#region--------------RemoteAccess---------------------
RowLayout flRemoteAccessTop = new RowLayout () {
Height = Application.GetRealHeight (100),
Width = LayoutParams.MatchParent,
BackgroundColor = SkinStyle.Current.MainColor
};
sView.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,
TextColor = SkinStyle.Current.TextColor1
};
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);
flRemoteAccessTop.AddChidren (btnRemoteAccessHelp);
Button btnRemoteAccessCheck = new Button () {
Height = Application.GetMinRealAverage (98),
Width = Application.GetMinRealAverage (76),
UnSelectedImagePath = "Item/Check.png",
SelectedImagePath = "Item/CheckSelected.png",
Y = btnRemoteAccessHelp.Y,
};
btnRemoteAccessCheck.X = flRemoteAccessTop.Width - btnRemoteAccessCheck.Width - Application.GetRealWidth (100);
btnRemoteAccessHelp.MouseUpEventHandler += (sender, e) => {
new Tip () { MaxWidth = 150, Text = Language.StringByID (R.MyInternationalizationString.HelpRemoteAccess), Direction = AMPopTipDirection.Down, CloseTime = 4 }.Show ((View)sender);
};
flRemoteAccessTop.AddChidren (btnRemoteAccessCheck);
FrameLayout flRemoteAccessBody = new FrameLayout () {
Height = Application.GetRealHeight (0),
Width = LayoutParams.MatchParent,
};
sView.AddChidren (flRemoteAccessBody);
FrameLayout flRemoteAutoSetting = new FrameLayout () {
Height = Application.GetRealHeight (90),
};
flRemoteAccessBody.AddChidren (flRemoteAutoSetting);
Button btnRemoteAutoCheck = new Button () {
Gravity = Gravity.Center,
Width = Application.GetRealWidth (300),
Height = Application.GetRealHeight (60),
BorderColor = SkinStyle.Current.BorderColor,
BorderWidth = 1,
Radius = 5,
TextColor = SkinStyle.Current.TextColor1,
SelectedTextColor = SkinStyle.Current.TextColor1,
TextID = R.MyInternationalizationString.AutomaticSetting,
TextAlignment = TextAlignment.Center,
//Text = "YES"
};
flRemoteAutoSetting.AddChidren (btnRemoteAutoCheck);
Button btnGroupName = new Button () {
X = gatewayIDName.X,
Y = flRemoteAutoSetting.Bottom + Application.GetRealHeight (20),
TextAlignment = TextAlignment.CenterLeft,
Height = Application.GetRealHeight (49),
Width = Application.GetRealWidth (360),
TextID = R.MyInternationalizationString.GroupName,
TextColor = SkinStyle.Current.TextColor1
};
flRemoteAccessBody.AddChidren (btnGroupName);
EditText etGroupName = new EditText () {
X = gatewayIDName.X,
TextAlignment = TextAlignment.CenterLeft,
Height = Application.GetRealHeight (55),
Width = Application.GetRealWidth (440),
Y = btnGroupName.Bottom + Application.GetRealHeight (2),
//BackgroundColor = SkinStyle.Current.SysEditBox,
BorderColor = SkinStyle.Current.BorderColor,
BorderWidth = 1,
Radius = 5,
TextColor = SkinStyle.Current.TextColor1
};
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),
TextColor = SkinStyle.Current.TextColor1
};
flRemoteAccessBody.AddChidren (lblProjectName);
EditText etProjectName = new EditText () {
X = gatewayIDName.X,
TextAlignment = TextAlignment.CenterLeft,
Height = Application.GetRealHeight (55),
Width = Application.GetRealWidth (440),
Y = lblProjectName.Bottom + Application.GetRealHeight (2),
//BackgroundColor = SkinStyle.Current.SysEditBox,
BorderColor = SkinStyle.Current.BorderColor,
BorderWidth = 1,
Radius = 5,
TextColor = SkinStyle.Current.TextColor1
};
flRemoteAccessBody.AddChidren (etProjectName);
Button lblUsername = new Button () {
X = lblProjectName.X,
TextAlignment = TextAlignment.CenterLeft,
Height = Application.GetRealHeight (55),
Width = Application.GetRealWidth (440),
TextID = R.MyInternationalizationString.UserName,
Y = etProjectName.Bottom + Application.GetRealHeight (2),
TextColor = SkinStyle.Current.TextColor1
};
flRemoteAccessBody.AddChidren (lblUsername);
EditText etUserName = new EditText () {
X = lblProjectName.X,
TextAlignment = TextAlignment.CenterLeft,
Height = Application.GetRealHeight (55),
Width = Application.GetRealWidth (440),
//BackgroundColor = SkinStyle.Current.SysEditBox,
BorderColor = SkinStyle.Current.BorderColor,
BorderWidth = 1,
Radius = 5,
Y = lblUsername.Bottom + Application.GetRealHeight (2),
TextColor = SkinStyle.Current.TextColor1
};
flRemoteAccessBody.AddChidren (etUserName);
Button btnGatewayPassword = new Button () {
X = lblProjectName.X,
Y = etUserName.Bottom + Application.GetRealHeight (2),
Height = Application.GetRealHeight (55),
Width = Application.GetRealWidth (440),
TextID = R.MyInternationalizationString.PassWrod,
TextAlignment = TextAlignment.CenterLeft,
TextColor = SkinStyle.Current.TextColor1
};
flRemoteAccessBody.AddChidren (btnGatewayPassword);
EditText etGatewayPassWrod = new EditText () {
X = lblProjectName.X,
Y = btnGatewayPassword.Bottom + Application.GetRealHeight (2),
TextAlignment = TextAlignment.CenterLeft,
Height = Application.GetRealHeight (55),
Width = Application.GetRealWidth (440),
Text = gatewayDevice.Password,
//BackgroundColor = SkinStyle.Current.SysEditBox,
BorderColor = SkinStyle.Current.BorderColor,
BorderWidth = 1,
Radius = 5,
TextColor = SkinStyle.Current.TextColor1
};
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,
TextColor = SkinStyle.Current.TextColor1
};
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),
//BackgroundColor = SkinStyle.Current.SysEditBox,
BorderColor = SkinStyle.Current.BorderColor,
BorderWidth = 1,
Radius = 5,
TextColor = SkinStyle.Current.TextColor1
};
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 = SkinStyle.Current.SysEditBox,
BorderColor = SkinStyle.Current.BorderColor,
BorderWidth = 1,
Radius = 5,
TextColor = SkinStyle.Current.TextColor1
};
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,
TextColor = SkinStyle.Current.TextColor1
};
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 = SkinStyle.Current.SysEditBox,
BorderColor = SkinStyle.Current.BorderColor,
BorderWidth = 1,
Radius = 5,
TextColor = SkinStyle.Current.TextColor1
};
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 = SkinStyle.Current.SysEditBox,
BorderColor = SkinStyle.Current.BorderColor,
BorderWidth = 1,
Radius = 5,
TextColor = SkinStyle.Current.TextColor1
};
flRemoteAccessBody.AddChidren (etAlternativeServerIPPoint);
Button btnGatewaySave = new Button () {
X = (Application.CurrentWidth / 2 - 30),
Height = Application.GetRealHeight (55),
Width = Application.GetRealWidth (100),
BackgroundColor = SkinStyle.Current.ButtonColor,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
BorderWidth = 1,
Radius = 5,
BorderColor = SkinStyle.Current.Transparent,
TextID = R.MyInternationalizationString.SAVE,
Y = etAlternativeServerIP.Bottom + Application.GetRealHeight (20),
TextColor = SkinStyle.Current.TextColor1
};
flRemoteAccessBody.AddChidren (btnGatewaySave);
flRemoteAccessBody.Height = btnGatewaySave.Bottom + Application.GetRealHeight (20);
byte [] gatewayBytes = null;
byte [] serverIPBytes = null;
System.Threading.Tasks.Task.Run (() => {
gatewayBytes = Control.ControlBytesSendHasReturn (Command.ReadGateWayModelInfo, gatewayDevice.SubnetID, gatewayDevice.DeviceID, new byte [] { });
serverIPBytes = Control.ControlBytesSendHasReturn (Command.ReadGatewayServerIP, gatewayDevice.SubnetID, gatewayDevice.DeviceID, new byte [] { });
IO.FileUtils.WriteFileByBytes ("Remote_GatewayBytes_" + gatewayDevice.Name + "_" + gatewayDevice.SubnetID, gatewayBytes);
if (gatewayBytes != null && serverIPBytes != null) {
Application.RunOnMainThread (() => {
#region ---读取、设置组名工程名---
int model = gatewayBytes [0];
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');
IO.FileUtils.SaveEquipmentMessage (gatewayDevice);
etGroupName.Text = gatewayDevice.Remote_GroupName;
etProjectName.Text = gatewayDevice.Remote_ProjectName;
etUserName.Text = gatewayDevice.Remote_UserName;
etGatewayPassWrod.Text = gatewayDevice.Remote_Password;
btnRemoteAccessCheck.MouseUpEventHandler += (sender, e) => {
if (!btnRemoteAccessCheck.IsSelected) {
flRemoteAccessBody.Height = btnGatewaySave.Bottom + Application.GetRealHeight (20);
btnRemoteAccessCheck.IsSelected = true;
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;
gatewayDevice.RometoMode = gatewayBytes [0] = 0;
Control.ControlBytesSend (Command.SetGateWayModelInfo, gatewayDevice.SubnetID, gatewayDevice.DeviceID, gatewayBytes);
UserConfig.Instance.RemoteModeFile = "";
UserConfig.Instance.SaveUserConfig ();
}
IO.FileUtils.SaveEquipmentMessage (gatewayDevice);
};
#endregion
#region ---读取、设置 网关IP地址参数---
string serverIP1 = serverIPBytes [0].ToString () + "." + serverIPBytes [1].ToString () + "." +
serverIPBytes [2].ToString () + "." + serverIPBytes [3].ToString ();
string serverIP1Point = ((serverIPBytes [4] * 256) + serverIPBytes [5]).ToString ();
string serverIP2 = serverIPBytes [6].ToString () + "." + serverIPBytes [7].ToString () + "." +
serverIPBytes [8].ToString () + "." + serverIPBytes [9].ToString ();
string serverIP2Point = ((serverIPBytes [10] * 256) + serverIPBytes [11]).ToString ();
etServerIP.Text = serverIP1;
etServerIPPoint.Text = serverIP1Point == "0" ? "9999" : serverIP1Point;
serverIP1Point = etServerIPPoint.Text;
etAlternativeServerIP.Text = serverIP2;
etAlternativeServerIPPoint.Text = serverIP2Point == "0" ? "9999" : serverIP2Point;
serverIP2Point = etAlternativeServerIPPoint.Text;
btnGatewaySave.MouseUpEventHandler += (sender, e) => {
gatewayDevice.Remote_GroupName = etGroupName.Text.Trim ();// "james";//gatewayGroupName;
gatewayDevice.Remote_ProjectName = etProjectName.Text.Trim ();//"myhome";//gatewayProjectName;
gatewayDevice.Remote_UserName = etUserName.Text.Trim ();//"james";//gatewayUserName;
gatewayDevice.Remote_Password = etGatewayPassWrod.Text.Trim ();//"chy1125";//gatewayPassWord;
string [] strServerIP = etServerIP.Text.Split ('.');
string [] strServerIP1 = etAlternativeServerIP.Text.Split ('.');
IO.FileUtils.SaveEquipmentMessage (gatewayDevice);
System.Threading.Tasks.Task.Run (() => {
try {
Application.RunOnMainThread (() => {
MainPage.Loading.Start ("Sending...");
});
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);
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 = 251,
DeviceID = 251,
AddData = sendServerBytes,
}, 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 ();
});
//} 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 ();
//});
} else {
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);
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 (serverIP1Point, 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 (serverIP2Point, 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 ();
});
} else {
Application.RunOnMainThread (() => {
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.ThePerationWasSuccessful), Language.StringByID (R.MyInternationalizationString.Confrim)).Show ();
});
}
}
} catch {
Application.RunOnMainThread (() => {
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipPleaseEnterTheCorrectData), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
});
} finally {
Application.RunOnMainThread (() => {
MainPage.Loading.Hide ();
});
}
});
};
#endregion
if (model == 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 ();
gatewayBytes [0] = 2;
}
});
}
});
btnRemoteAutoCheck.MouseUpEventHandler += (sender, e) => {
Dialog dialogRemoteAuto = new Dialog ();
FrameLayout remoteAutoView = new FrameLayout () {
Width = Application.GetRealWidth (400),
Height = Application.GetRealHeight (270 + 100),
Gravity = Gravity.Center,
Radius = 5,
BorderColor = SkinStyle.Current.Transparent,
BorderWidth = 0,
BackgroundColor = SkinStyle.Current.DialogColor,
};
dialogRemoteAuto.AddChidren (remoteAutoView);
Button remoteAutoTitle = new Button () {
Height = Application.GetRealHeight (80),
BackgroundColor = SkinStyle.Current.DialogTitle,
TextID = R.MyInternationalizationString.RemotePassword,
TextColor = SkinStyle.Current.DialogTextColor,
TextAlignment = TextAlignment.Center,
};
remoteAutoView.AddChidren (remoteAutoTitle);
EditText etRemoteAutoPW = new EditText () {
Gravity = Gravity.Center,
Height = Application.GetRealHeight (55),
Width = Application.GetRealWidth (300),
//BackgroundColor = SkinStyle.Current.SysEditBox,
BorderColor = SkinStyle.Current.BorderColor,
TextAlignment = TextAlignment.Center,
BorderWidth = 1,
Radius = 5,
TextColor = SkinStyle.Current.TextColor
};
remoteAutoView.AddChidren (etRemoteAutoPW);
FrameLayout remoteAutoBottom = new FrameLayout () {
Y = Application.GetRealHeight (270 + 20),
Height = Application.GetRealHeight (83),
BackgroundColor = SkinStyle.Current.LineColor,
};
remoteAutoView.AddChidren (remoteAutoBottom);
Button btnCancel = new Button () {
Width = Application.GetRealWidth (200),
BackgroundColor = SkinStyle.Current.DialogTitle,
TextID = R.MyInternationalizationString.cancel,
TextAlignment = TextAlignment.Center,
};
remoteAutoBottom.AddChidren (btnCancel);
btnCancel.MouseUpEventHandler += (ssd, de) => {
dialogRemoteAuto.Close ();
};
Button btnConfrim = new Button () {
X = btnCancel.Right + 1,
Width = Application.GetRealWidth (200),
BackgroundColor = SkinStyle.Current.DialogTitle,
TextID = R.MyInternationalizationString.Confrim,
TextAlignment = TextAlignment.Center,
};
remoteAutoBottom.AddChidren (btnConfrim);
btnConfrim.MouseUpEventHandler += (ssd, de) => {
if (etRemoteAutoPW.Text.Trim ().Length < 6) {
new Tip () { MaxWidth = 250, Text = Language.StringByID (R.MyInternationalizationString.PasswordLenghtTip), Direction = AMPopTipDirection.Down, CloseTime = 3 }.Show (etRemoteAutoPW);
return;
}
gatewayDevice.Remote_GroupName = etGroupName.Text = UserConfig.Instance.CurrentRegion.RegionName;
gatewayDevice.Remote_ProjectName = etProjectName.Text = UserConfig.Instance.CurrentRegion.RegionName;
gatewayDevice.Remote_UserName = etUserName.Text = "Admin";
gatewayDevice.Remote_Password = etGatewayPassWrod.Text = etRemoteAutoPW.Text.Trim ();
string [] strServerIP = (MainPage.SeviceIP).Split ('.');
string [] strServerIP1 = (MainPage.SeviceIP).Split ('.');
etServerIP.Text = btnAlternativeServerIP.Text = MainPage.SeviceIP;
etServerIPPoint.Text = etAlternativeServerIPPoint.Text = "9999";
System.Threading.Tasks.Task.Run (() => {
try {
Application.RunOnMainThread (() => {
MainPage.Loading.Start ("Sending...");
});
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);
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 = 251,
DeviceID = 251,
AddData = sendServerBytes,
}, 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 ();
});
} else {
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);
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;
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;
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 ();
});
} else {
Application.RunOnMainThread (() => {
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.ThePerationWasSuccessful), Language.StringByID (R.MyInternationalizationString.Confrim)).Show ();
IO.FileUtils.SaveEquipmentMessage (gatewayDevice);
dialogRemoteAuto.Close ();
});
}
}
} catch {
Application.RunOnMainThread (() => {
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipPleaseEnterTheCorrectData), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
});
} finally {
Application.RunOnMainThread (() => {
MainPage.Loading.Hide ();
});
}
});
};
dialogRemoteAuto.Show ();
};
#endregion
#region--------------广播参数--------------------------
RowLayout flRadioParameterTop = new RowLayout () {
Height = Application.GetRealHeight (98),
Width = LayoutParams.MatchParent,
BackgroundColor = SkinStyle.Current.MainColor,
};
sView.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,
TextColor = SkinStyle.Current.TextColor1
};
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,
TextColor = SkinStyle.Current.TextColor1
};
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);
//-------------------------
FrameLayout flRadioParameterBody = new FrameLayout () {
Height = Application.GetRealHeight (598),
Width = LayoutParams.MatchParent,
};
//if (usefulBytesOther != null)
sView.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 (20),
TextColor = SkinStyle.Current.TextColor1
};
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 (30),
};
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 (12),
TextColor = SkinStyle.Current.TextColor1
};
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 (5),
};
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 (22),
TextColor = SkinStyle.Current.TextColor1
};
flRadioParameterBody.AddChidren (lblPasswordG);
channelText = gatewayDevice.WirelessPassword;
EditText etRadioParameterPassWrod = new EditText () {
X = spinnerband.X,
Y = spinnerChannel.Bottom + Application.GetRealHeight (12),
Text = channelText,
TextAlignment = TextAlignment.CenterLeft,
Height = Application.GetRealHeight (55),
Width = Application.GetRealWidth (310),
//UnSelectedImagePath = "Item/TextBox.png",
//BackgroundColor = SkinStyle.Current.SysEditBox,
BorderColor = SkinStyle.Current.BorderColor,
BorderWidth = 1,
Radius = 5,
TextColor = SkinStyle.Current.TextColor1,
};
flRadioParameterBody.AddChidren (etRadioParameterPassWrod);
//--------------------------------------------------------------------------------------
Button btnRadioParameterSave = new Button () {
X = (Application.CurrentWidth / 2 - 30),
Height = Application.GetRealHeight (55),
Width = Application.GetRealWidth (98),
BackgroundColor = SkinStyle.Current.ButtonColor,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
BorderWidth = 1,
Radius = 5,
BorderColor = SkinStyle.Current.Transparent,
TextID = R.MyInternationalizationString.SAVE,
Y = etRadioParameterPassWrod.Bottom + Application.GetRealHeight (20),
TextColor = SkinStyle.Current.TextColor1
};
flRadioParameterBody.AddChidren (btnRadioParameterSave);
flRadioParameterBody.Height = btnRadioParameterSave.Bottom + Application.GetRealHeight (20);
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.");
};
#endregion
#region--------------无线频率配对--------------------------
RowLayout flGatewayMapping = new RowLayout () {
Height = Application.GetRealHeight (98),
Width = LayoutParams.MatchParent,
BackgroundColor = SkinStyle.Current.MainColor,
};
sView.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,
TextColor = SkinStyle.Current.TextColor1
};
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,
TextColor = SkinStyle.Current.TextColor1
};
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);
};
#endregion
#region --------------分配地址-----------------
RowLayout flDistributionMACTop = new RowLayout () {
Height = Application.GetRealHeight (98),
Width = LayoutParams.MatchParent,
BackgroundColor = SkinStyle.Current.MainColor,
};
sView.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,
TextColor = SkinStyle.Current.TextColor1
};
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,
TextColor = SkinStyle.Current.TextColor1
};
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,
TextColor = SkinStyle.Current.TextColor1
};
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);
};
#endregion
gatewayInfoSwitch.MouseUpEventHandler += (sender, e) => {
gatewayInfoSwitch.IsSelected = !gatewayInfoSwitch.IsSelected;
if (gatewayInfoSwitch.IsSelected) {
sView.Height = flRadioParameterBody.Bottom - frameLayoutGatewayID.X;
} else {
sView.Height = 0;
}
};
#region -----搜索设备----
RowLayout flSearchEquipmentTop = new RowLayout () {
Height = Application.GetRealHeight (98),
Width = LayoutParams.MatchParent,
BackgroundColor = SkinStyle.Current.MainColor,
};
sView.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,
TextColor = SkinStyle.Current.TextColor1
};
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,
TextColor = SkinStyle.Current.TextColor1
};
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,
TextColor = SkinStyle.Current.TextColor1
};
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);
};
FrameLayout flSearchEquipmentBody = new FrameLayout () {
Height = Application.GetRealHeight (60),
Width = LayoutParams.MatchParent,
};
btnGatewayMappingText.MouseUpEventHandler += (sender, e) => {
UpdataGatewayList (btnSearchEquipmentHelp.X, flSearchEquipmentBody, gatewayDevice.MAC);
};
btnGatewayMappingIcon.MouseUpEventHandler += (sender, e) => {
UpdataGatewayList (btnSearchEquipmentHelp.X, flSearchEquipmentBody, gatewayDevice.MAC);
};
flGatewayMapping.MouseUpEventHandler += (sender, e) => {
UpdataGatewayList (btnSearchEquipmentHelp.X, flSearchEquipmentBody, gatewayDevice.MAC);
};
sView.AddChidren (flSearchEquipmentBody);
#endregion
#region --------------bottom--------------
var sysBottomView = new FrameLayout () {
Height = Application.GetRealHeight (90),
Y = Application.GetRealHeight (844)
};
AddChidren (sysBottomView);
Button AddSystemEquipmentButton = new Button () {
Width = LayoutParams.MatchParent,
Height = LayoutParams.MatchParent,
TextID = R.MyInternationalizationString.ReFresh,
TextAlignment = TextAlignment.Center,
TextColor = SkinStyle.Current.TextColor1,
BackgroundColor = SkinStyle.Current.MainColor
};
sysBottomView.AddChidren (AddSystemEquipmentButton);
AddSystemEquipmentButton.MouseUpEventHandler += (sender, 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 deviceBytes = IO.FileUtils.ReadEquipmentMessage (gatewayDevice);
var tempGatewayDevice = Newtonsoft.Json.JsonConvert.DeserializeObject (deviceBytes);
if (tempGatewayDevice != null) {
Application.RunOnMainThread (() => {
this.ShowWirelessGateway (tempGatewayDevice);
});
}
});
};
sysBottomView.AddChidren (new Button () { Height = 1, BackgroundColor = SkinStyle.Current.White20Transparent });
#endregion
MainPage.Loading.Hide ();
});
});
} finally {
}
}
///
/// 开关无线配置弹窗
///
static void ShowWirelessConfigDialog (byte subnetID, byte deviceID)
{
Dialog dialog = new Dialog ();
FrameLayout dialogBody = new FrameLayout () {
BackgroundColor = SkinStyle.Current.DialogColor,
Width = Application.GetRealWidth (480),
Height = Application.GetRealHeight (480),
Gravity = Gravity.Center,
Radius = 5,
BorderColor = SkinStyle.Current.Transparent,
BorderWidth = 0,
};
dialog.AddChidren (dialogBody);
Button btnEquipmentTitle = new Button () {
Height = Application.GetRealHeight (85),
BackgroundColor = SkinStyle.Current.DialogTitle,
TextID = R.MyInternationalizationString.WirelessConfiguration,
TextAlignment = TextAlignment.Center,
Enable = false,
TextColor = SkinStyle.Current.TextColor1
};
dialogBody.AddChidren (btnEquipmentTitle);
Button btnOpenConfig = new Button () {
X = Application.GetRealWidth (30),
Y = Application.GetRealHeight (205),
Width = Application.GetRealWidth (420),
Height = Application.GetRealHeight (65),
TextID = R.MyInternationalizationString.Close,
TextAlignment = TextAlignment.Center,
BackgroundColor = SkinStyle.Current.ButtonColor,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
Radius = 5,
TextColor = SkinStyle.Current.TextColor1
};
dialogBody.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;
}
};
//---bottom--
Button btnBack = new Button () {
Width = Application.GetRealWidth (480),
Height = Application.GetRealHeight (85),
BackgroundColor = SkinStyle.Current.ButtonColor,
Y = Application.GetRealHeight (480) - Application.GetRealHeight (85),
TextID = R.MyInternationalizationString.Confrim,
TextAlignment = TextAlignment.Center,
Radius = 1,
TextColor = SkinStyle.Current.TextColor1
};
dialogBody.AddChidren (btnBack);
btnBack.MouseUpEventHandler += (s, e1) => {
dialog.Close ();
};
dialog.Show ();
}
///
/// 弹出确认分配设备地址的窗口
///
/// Subnet I.
/// Device I.
public static void ShowAssignedAddressDialog (byte subnetID, byte deviceID)
{
byte [] sendByte = new byte [] { 1, 0, 0, 0, 0 };
Dialog dialog = new Dialog ();
FrameLayout dialogBodyView = new FrameLayout () {
Gravity = Gravity.Center,
Width = Application.GetRealWidth (480),
Height = Application.GetRealHeight (480),
BackgroundColor = SkinStyle.Current.DialogColor,
Radius = 5,
BorderWidth = 0,
BorderColor = SkinStyle.Current.Transparent
};
dialog.AddChidren (dialogBodyView);
Button btnEquipmentTitle = new Button () {
Height = Application.GetRealHeight (85),
BackgroundColor = SkinStyle.Current.DialogTitle,
TextID = R.MyInternationalizationString.DistributionOfDeviceAddress,
TextAlignment = TextAlignment.Center,
Radius = 1,
TextColor = SkinStyle.Current.TextColor1
};
dialogBodyView.AddChidren (btnEquipmentTitle);
Button btnAssignedAll = new Button () {
X = Application.GetRealWidth (30),
Y = Application.GetRealHeight (125),
Width = Application.GetRealWidth (420),
Height = Application.GetRealHeight (80),
TextID = R.MyInternationalizationString.AssignedAddressAll,
TextAlignment = TextAlignment.Center,
BackgroundColor = SkinStyle.Current.ButtonColor,
TextColor = SkinStyle.Current.TextColor1
};
dialogBodyView.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 = Application.GetRealWidth (420),
Height = Application.GetRealHeight (80),
TextID = R.MyInternationalizationString.AssignedAddressAdditional,
TextAlignment = TextAlignment.Center,
BackgroundColor = SkinStyle.Current.ButtonColor,
TextColor = SkinStyle.Current.TextColor1
};
dialogBodyView.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.ButtonColor,
Y = Application.GetRealHeight (480) - Application.GetRealHeight (85),
TextID = R.MyInternationalizationString.Cancel,
TextAlignment = TextAlignment.Center,
Radius = 1,
TextColor = SkinStyle.Current.TextColor1
};
dialogBodyView.AddChidren (btnBack);
btnBack.MouseUpEventHandler += (s, e1) => {
dialog.Close ();
};
dialog.Show ();
}
///
/// 为设备分配地址
///
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 += ( sender2, 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.DialogColor,
};
int btnX = Application.GetRealWidth (420);
Button btnEquipmentTitle = new Button () {
Width = dialog.Width,
Height = Application.GetRealHeight (85),
BackgroundColor = SkinStyle.Current.DialogTitle,
TextID = R.MyInternationalizationString.AssignedAddressAdditional,
TextAlignment = TextAlignment.Center,
Radius = 1,
TextColor = SkinStyle.Current.DialogTextColor
};
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 = SkinStyle.Current.ButtonColor,
SelectedBackgroundColor = SkinStyle.Current.Transparent,
TextColor = SkinStyle.Current.TextColor1,
SelectedTextColor = SkinStyle.Current.TextColor1
};
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 = SkinStyle.Current.ButtonColor,
SelectedBackgroundColor = SkinStyle.Current.Transparent,
TextColor = SkinStyle.Current.TextColor1,
SelectedTextColor = SkinStyle.Current.TextColor1
};
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 = SkinStyle.Current.ButtonColor,
SelectedBackgroundColor = SkinStyle.Current.Transparent,
TextColor = SkinStyle.Current.TextColor1,
SelectedTextColor = SkinStyle.Current.TextColor1
};
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 = SkinStyle.Current.ButtonColor,
SelectedBackgroundColor = SkinStyle.Current.Transparent,
TextColor = SkinStyle.Current.TextColor1,
SelectedTextColor = SkinStyle.Current.TextColor1
};
dialog.AddChidren (btnAssigned4);
btnAssigned.MouseUpEventHandler += (sender, e) => {
btnAssigned.Enable = false;
btnAssigned.IsSelected = true;
btnAssigned.Text += " √";
btnAssigned1.Visible = true;
};
btnAssigned1.MouseUpEventHandler += (sender, e) => {
System.Threading.Tasks.Task.Run (() => {
try {
Application.RunOnMainThread (() => {
MainPage.Loading.Start (Language.StringByID(R.MyInternationalizationString.load));
});
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;
btnAssigned3.Text += " √";
});
} 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.Text += " √";
};
btnAssigned4.MouseUpEventHandler += (sender, e) => {
Application.RunOnMainThread (() => {
System.Threading.Tasks.Task.Run (() => {
try {
Application.RunOnMainThread (() => {
dialog.Close ();
MainPage.Loading.Start (Language.StringByID(R.MyInternationalizationString.load));
});
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.DialogTitle,
Y = Application.GetRealHeight (680) - Application.GetRealHeight (85),
TextID = R.MyInternationalizationString.Cancel,
TextAlignment = TextAlignment.Center,
Radius = 1,
TextColor = SkinStyle.Current.DialogTextColor
};
btnBack.MouseUpEventHandler += (s, e1) => {
dialog.Close ();
};
dialog.AddChidren (btnBack);
dialog.Show ();
}
public static void UpdataGatewayList (int x, FrameLayout flGatewayMapping4, string gateWayMAC)
{
flGatewayMapping4.RemoveAll ();
MainPage.Loading.Start ();
Button title = new Button () {
X = Application.GetRealWidth (50),
TextAlignment = TextAlignment.TopLeft,
Height = Application.GetRealHeight (70),
Width = Application.GetRealWidth (400),
TextID = R.MyInternationalizationString.DeviceList,
Y = Application.GetRealHeight (20),
TextColor = SkinStyle.Current.TextColor1
};
flGatewayMapping4.AddChidren (title);
FrameLayout tipView = new FrameLayout () {
Y = title.Bottom,
Height = Application.GetRealHeight (50),
};
flGatewayMapping4.AddChidren (tipView);
Button btnNormal = new Button () {
Width = Application.GetRealWidth (30),
Height = Application.GetRealHeight (30),
X = Application.GetRealWidth (55),
Y = Application.GetRealHeight (10),
BackgroundColor = SkinStyle.Current.TextColor1,
Radius = 2,
Enable = false,
TextColor = SkinStyle.Current.TextColor1
};
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,
TextColor = SkinStyle.Current.TextColor1
};
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,
TextColor = SkinStyle.Current.TextColor1,
};
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,
TextColor = SkinStyle.Current.TextColor1
};
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),
TextColor = SkinStyle.Current.TextColor1,
Enable = false
};
tipView.AddChidren (btnLostText);
int countDevcie = 0;
CommonPage.FindGatewayChilren = true;
CommonPage.LocalPhoneFindDevice = true;
var oldFilesList = IO.FileUtils.ReadFiles ().FindAll ((obj) => obj.Split ('_') [0] == "Equipment"&& obj.Split ('_').Length == 4 && obj.Split('_')[3] != "0");
//全部重新更新设备下面所有的回路信息
if (th != null) {
th.Abort ();
th = null;
}
ReadDevices (() => {
var oldCommon = new List ();
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 (equipmentString);
if (common == null) {
continue;
}
if (common.isMixBox) {
continue;
}if(common.GatewayMAC != gateWayMAC){
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;
//Console.WriteLine(common.DeviceID);
if (common.GatewayMAC == gateWayMAC && common.DeviceID != 0) {
int btnY = tipView.Y + (countDevcie + 1) * Application.GetRealHeight (80);
countDevcie++;
if (common.isMixBox) {
Console.WriteLine ("IsMixBox");
countDevcie--;
continue;
}
#region Show Device
Button btn = new Button () {
X = Application.GetRealWidth (50),
Y = btnY,
Height = Application.GetRealHeight (42),
Width = Application.GetRealWidth (42),
TextColor = SkinStyle.Current.TextColor1,
};
string strDeviceType = "";
if (common.Type == DeviceType.LightSwitch || common.Type == DeviceType.LightDimming
|| common.Type == DeviceType.LightDALI || common.Type == DeviceType.LightLogic
|| common.Type == DeviceType.LightMixSwitch || common.Type == DeviceType.LightMixDimming
|| common.Type == DeviceType.LightEnergySwitch) {
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 || common.Type == DeviceType.DeviceCommon) {
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.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);
} else if (common.Type == DeviceType.DoorLock) {
btn.UnSelectedImagePath = "DoorLockPic/door_lock.png";//门锁111
strDeviceType = Language.StringByID (R.MyInternationalizationString.DoorLock);
} else if (common.Type == DeviceType.SensorLPG || common.Type == DeviceType.SensorCH4 || common.Type == DeviceType.SensorCOH2
|| common.Type == DeviceType.SensorWater || common.Type == DeviceType.SensorSmoke || common.Type == DeviceType.SensorMobileDetection
|| common.Type == DeviceType.SensorTemperature || common.Type == DeviceType.SensorHumidity || common.Type == DeviceType.SensorIllumination
|| common.Type == DeviceType.SensorTVOC || common.Type == DeviceType.SensorPM25 || common.Type == DeviceType.SensorCO2
|| common.Type == DeviceType.SensorWindSpeed || common.Type == DeviceType.SensorWindPressure || common.Type == DeviceType.SensorLiquidFlow
|| common.Type == DeviceType.SensorLiquidPressure || common.Type == DeviceType.SensorLiquidDepth || common.Type == DeviceType.SensorRainfall
|| common.Type == DeviceType.SensorWeight || common.Type == DeviceType.SensorHeightLength || common.Type == DeviceType.SensorVelocity
|| common.Type == DeviceType.SensorVibration || common.Type == DeviceType.SensorVoltage || common.Type == DeviceType.SensorCurrent || common.Type == DeviceType.SensorPower
|| common.Type == DeviceType.SensorMenciAndwindowMagnetic) {
strDeviceType = Language.StringByID (R.MyInternationalizationString.Sensor);
btn.UnSelectedImagePath = "Sensor/Sensor.png";
} else if (common.Type == DeviceType.RCU || common.Type == DeviceType.ZBConverter) {
btn.UnSelectedImagePath = "Item/OnePort.png";
} else if (common.Type == DeviceType.FreshAir) {
btn.UnSelectedImagePath = "FreshAir/FreshAir.png";
} else if (common.Type == DeviceType.Thermostat) {
btn.UnSelectedImagePath = "CapillaryAC/CapillaryACIcon.png";
} else {
continue;
}
Button btn1 = new Button () {
X = Application.GetRealWidth (144),
Y = btnY,
Text = common.Name,
TextAlignment = TextAlignment.CenterLeft,
Height = Application.GetRealHeight (42),
Width = Application.GetRealWidth (342),
TextColor = SkinStyle.Current.TextColor1,
};
Button btn2 = new Button () {
X = x,
Y = btnY + Application.GetRealHeight (10),
UnSelectedImagePath = "Item/More2.png",
SelectedImagePath = "Item/More2Selected.png",
Height = Application.GetRealHeight (42),
Width = Application.GetRealWidth (40),
TextColor = SkinStyle.Current.TextColor1,
};
EventHandler eHandlerC = new EventHandler (delegate (object sender, MouseEventArgs e) {
btn2.IsSelected = true;
Dialog dialog = new Dialog ();
FrameLayout dialogBodyView = new FrameLayout () {
BackgroundColor = SkinStyle.Current.DialogColor,
Width = Application.GetRealWidth (494),
Height = Application.GetRealHeight (488),
Radius = 5,
BorderColor = SkinStyle.Current.Transparent,
BorderWidth = 0,
Gravity = Gravity.Center
};
dialog.AddChidren (dialogBodyView);
Button btnEquipmentTitle = new Button () {
Height = Application.GetRealHeight (70),
TextAlignment = TextAlignment.Center,
Text = strDeviceType,
BackgroundColor = SkinStyle.Current.DialogTitle,
TextColor = SkinStyle.Current.TextColor1,
};
dialogBodyView.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.TextColor
};
dialogBodyView.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,
//BackgroundColor = SkinStyle.Current.SysEditBox,
BorderColor = SkinStyle.Current.BorderColor,
BorderWidth = 1,
Radius = 5,
TextColor = SkinStyle.Current.TextColor,
};
dialogBodyView.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 = SkinStyle.Current.DialogTitle,
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
TextColor = SkinStyle.Current.TextColor1
};
dialogBodyView.AddChidren (btnFindDevcie);
btnFindDevcie.MouseDownEventHandler += (sender1, e1) => {
btnFindDevcie.IsSelected = true;
};
btnFindDevcie.MouseUpEventHandler += (sender1, e1) => {
btnFindDevcie.IsSelected = false;
//查找设备,发送命令让设备闪烁,面板设备与其他设备发送的数据不一样,多了一个byte,固定为:0(相当于多余)
//if (strDeviceType != Language.StringByID (R.MyInternationalizationString.PanelDevice)) {
Control.ControlBytesSend (Command.PositioningEquipment, common.SubnetID, common.DeviceID, new byte [] { 3 });
//} else {
// Control.ControlBytesSend (Command.PositioningPanel, common.SubnetID, common.DeviceID, new byte [] { 0, 3 });
//}
};
//---bottom--
Button btnBack = new Button () {
Width = Application.GetRealWidth (250),
Height = Application.GetRealHeight (85),
Y = Application.GetRealHeight (490 - 85),
BackgroundColor = SkinStyle.Current.DialogTitle,
TextID = R.MyInternationalizationString.Close,
TextColor = SkinStyle.Current.TextColor1
};
btnBack.MouseUpEventHandler += (s, e1) => {
dialog.Close ();
btn2.IsSelected = false;
};
dialogBodyView.AddChidren (btnBack);
Button btnLineV = new Button () {
Width = 1,
Height = btnBack.Height,
BackgroundColor = SkinStyle.Current.White20Transparent,
X = btnBack.Right,
Y = btnBack.Y,
TextColor = SkinStyle.Current.TextColor1,
};
dialogBodyView.AddChidren (btnLineV);
Button btnSave = new Button () {
Width = Application.GetRealWidth (250),
Height = Application.GetRealHeight (85),
X = btnLineV.Right,
Y = btnBack.Y,
TextID = R.MyInternationalizationString.SAVE,
TextColor = SkinStyle.Current.TextColor1,
BackgroundColor = SkinStyle.Current.DialogTitle,
};
dialogBodyView.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;
flGatewayMapping4.AddChidren (btn);
flGatewayMapping4.AddChidren (btn1);
flGatewayMapping4.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 () {
Width = btn.Width,
Height = btn.Height,
X = btn.X,
Y = btn.Y,
Radius = 3,
BackgroundColor = SkinStyle.Current.newDeviceBG
};
flGatewayMapping4.AddChidren (btnBG);
} else {
oldCommon.Remove (oldC);
}
#endregion
}
}
for (int i = 0; i < oldCommon.Count; i++) {
Common common = oldCommon [i];
if (common.DeviceID != 0) {
int btnY = tipView.Y + (countDevcie + 1) * Application.GetRealHeight (80);
countDevcie++;
if (common.isMixBox) {
Console.WriteLine ("IsMixBox");
countDevcie--;
continue;
}
Button btn = new Button () {
X = Application.GetRealWidth (50),
Y = btnY,
Height = Application.GetRealHeight (42),
Width = Application.GetRealWidth (42),
};
if (common.Type == DeviceType.LightSwitch || common.Type == DeviceType.LightDimming
|| common.Type == DeviceType.LightDALI || common.Type == DeviceType.LightLogic
|| common.Type == DeviceType.LightMixSwitch || common.Type == DeviceType.LightMixDimming
|| common.Type == DeviceType.LightEnergySwitch) {
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.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.Thermostat) {
btn.UnSelectedImagePath = "CapillaryAC/CapillaryACIcon.png";
} else if (common.Type == DeviceType.MusicModel) {
continue;
btn.UnSelectedImagePath = "Item/Music.png";
} else if (common.Type == DeviceType.LogicModule) {
btn.UnSelectedImagePath = "Item/LogicModule.png";
} else if (common.Type == DeviceType.RCU) {
btn.UnSelectedImagePath = "Item/LogicModule.png";
} else if (common.Type == DeviceType.DoorLock) {
btn.UnSelectedImagePath = "DoorLockPic/door_lock.png";//门锁111
} else if (common.Type == DeviceType.SensorLPG || common.Type == DeviceType.SensorCH4 || common.Type == DeviceType.SensorCOH2
|| common.Type == DeviceType.SensorWater || common.Type == DeviceType.SensorSmoke || common.Type == DeviceType.SensorMobileDetection
|| common.Type == DeviceType.SensorTemperature || common.Type == DeviceType.SensorHumidity || common.Type == DeviceType.SensorIllumination
|| common.Type == DeviceType.SensorTVOC || common.Type == DeviceType.SensorPM25 || common.Type == DeviceType.SensorCO2
|| common.Type == DeviceType.SensorWindSpeed || common.Type == DeviceType.SensorWindPressure || common.Type == DeviceType.SensorLiquidFlow
|| common.Type == DeviceType.SensorLiquidPressure || common.Type == DeviceType.SensorLiquidDepth || common.Type == DeviceType.SensorRainfall
|| common.Type == DeviceType.SensorWeight || common.Type == DeviceType.SensorHeightLength || common.Type == DeviceType.SensorVelocity
|| common.Type == DeviceType.SensorVibration || common.Type == DeviceType.SensorVoltage || common.Type == DeviceType.SensorCurrent || common.Type == DeviceType.SensorPower
|| common.Type == DeviceType.SensorMenciAndwindowMagnetic) {
btn.UnSelectedImagePath = "Sensor/Sensor.png";
} else if (common.Type == DeviceType.RCU || common.Type == DeviceType.ZBConverter) {
btn.UnSelectedImagePath = "Item/OnePort.png";
} else if (common.Type == DeviceType.FreshAir) {
btn.UnSelectedImagePath = "FreshAir/FreshAir.png";
} else {
continue;
}
Button btn1 = new Button () {
X = Application.GetRealWidth (144),
Y = btnY,
Text = common.Name,
TextAlignment = TextAlignment.CenterLeft,
Height = Application.GetRealHeight (42),
Width = Application.GetRealWidth (342),
TextColor = SkinStyle.Current.TextColor1,
};
flGatewayMapping4.AddChidren (btn);
flGatewayMapping4.AddChidren (btn1);
Button btnBG = new Button () {
Width = btn.Width,
Height = btn.Height,
X = btn.X,
Y = btn.Y,
Radius = 3,
BackgroundColor = SkinStyle.Current.LostDeviceBG
};
flGatewayMapping4.AddChidren (btnBG);
}
}
flGatewayMapping4.Height = Application.GetRealHeight (98 + 50 + 80 * countDevcie);
th = new Thread ((obj) => {
//CommonPage.FindGatewayChilren = true;
Waiting = false;
CommonPage.DeviceLoopList.Clear ();
var listCommonEquipment = CommonPage.DeviceList;
for (int i = 0; i < listCommonEquipment.Count; i++) {
var common = listCommonEquipment [i];
if (common.Type == DeviceType.ZBConverter) {
continue;
}
if (common == null)
continue;
Console.WriteLine ("读取设备各个回路的具体信息,当前设备名称:" + common.Name + " 回路总数:" + common.LoopCount);
byte bigClass = common.BigClass;
byte minClass = common.MinClass;
if(bigClass == 19){
}
if(common.DeviceID == 112){
}
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;
}
}
}
th = null;
});
th.Start ();
}, gateWayMAC);
}
static Thread th;
//等待红外读取红外类型
public static bool Waiting;
public static void ReadDevices (Action action, string gateWayMAC)
{
System.Threading.Tasks.Task.Run (() => {
try {
//这里搜索设备,直到完成就退出
readDevice (gateWayMAC);
CommonPage.LocalPhoneFindDevice = false;
if (action != null) {
Application.RunOnMainThread (
action
);
}
} catch (Exception ex) {
Console.WriteLine (ex.ToString ());
} finally {
Application.RunOnMainThread (() => {
MainPage.Loading.Hide ();
Room.ReadThermostatHostList ();
});
}
});
}
///
/// 读取设备
///
static void readDevice (string gateWayMAC)
{
CommonPage.LocalPhoneFindDevice = true;
CommonPage.RandomHigh = (byte)new Random ().Next (255);
CommonPage.RandomLow = (byte)new Random ().Next (255);
CommonPage.DeviceList.Clear ();
//如果两次都没有数据反馈,就不读取
int readCount = 4;
while (0 < readCount) {
readCount--;
System.IO.MemoryStream ms = new System.IO.MemoryStream ();
ms.WriteByte (CommonPage.RandomHigh);
ms.WriteByte (CommonPage.RandomLow);
List list = CommonPage.DeviceList;
int tempCount = list.Count;
string s = ";";
for (int i = 0; i < list.Count; i++) {
Common common = list [i];
if (common.GatewayMAC != gateWayMAC)
continue;
if (s.Contains (";" + common.SubnetID.ToString () + ":" + common.DeviceID.ToString ()))
continue;
s += common.SubnetID.ToString () + ":" + common.DeviceID.ToString () + ";";
ms.WriteByte (common.SubnetID);
ms.WriteByte (common.DeviceID);
}
Console.WriteLine ("搜索非网关设备,网络地址是:" + CommonPage.EndPoint.ToString ());
Control control = new Control ();
control.Send (new Target () {
IPEndPoint = CommonPage.EndPoint,
Command = Command.ReadDeviceModul,
SubnetID = 0xFF,
DeviceID = 0xFF,
AddData = ms.ToArray ()
}, SendCount.Zero, false);
ms.Close ();
System.Threading.Thread.Sleep (1000);
//如果数量不相等,就重置次数
if (tempCount != CommonPage.DeviceList.Count) {
readCount = 4;
}
}
CommonPage.DeviceList = CommonPage.DeviceList.FindAll ((obj) => { return obj != null && obj.GatewayMAC == gateWayMAC; });
CommonPage.LocalPhoneFindDevice = false;
}
}
}