using System;
|
using System.Collections.Generic;
|
using System.Threading;
|
using System.Net.NetworkInformation;
|
using System.Net;
|
using System.Text;
|
|
namespace Shared.SimpleControl.Phone
|
{
|
/// <summary>
|
/// 美林空调系统
|
/// 1.总控 在家 离家 ==> 通用开关指令(控制:E01C,读状态:E018) 开关号:1,开关状态: 0在家、1离家
|
/// 2.总控 全关 全开 ==> 通用开关指令(控制:E01C,读状态:E018) 开关号:2,开关状态: 0全关、1全开
|
/// 3.总控 模式 ==> 通用开关指令(控制:E01C,读状态:E018) 开关号:3,开关状态: 0制冷、1制热、2通风
|
///
|
/// 空调室内湿度
|
/// 1.读1938 回1939,扫风状态位替换位湿度状态位
|
///
|
/// 读模拟量 E50A
|
/// 日功耗 小类:25, 月功耗 小类:26, 功率 小类 24;
|
///
|
/// </summary>
|
public class ACMerrillHomePage : FrameLayout
|
{
|
|
uint MLTextColor = 0xFFEB5C19;
|
Button tempSwitch;
|
Button todayValueBtn;
|
Button monthValueBtn;
|
Button kwValueBtn;
|
Button btnLine3;
|
|
Button atHomeBtn;
|
Button outHomeBtn;
|
Button strokeBtn;
|
Button heatingBtn;
|
Button coolingBtn;
|
|
//List<EmqServerInfoRes> mEmqServerList;
|
VerticalScrolViewLayout bodyScrolView;
|
|
VerticalScrolViewLayout mACListScrolView;
|
//Thread readSpeedThead;
|
|
/// <summary>
|
/// 当前视图
|
/// </summary>
|
static ACMerrillHomePage curView;
|
ACMerrill mACMerrill;
|
|
public ACMerrillHomePage (ACMerrill mmACMerrill)
|
{
|
//BackgroundColor = SkinStyle.Current.MainColor;
|
this.mACMerrill = mmACMerrill;
|
curView = this;
|
}
|
|
public override void RemoveFromParent ()
|
{
|
SaveMerrilEquipmentMessage ();
|
MainPage.Loading.Hide ();
|
base.RemoveFromParent ();
|
curView = null;
|
}
|
|
public void ShowView ()
|
{
|
#region 标题
|
var topView = new FrameLayout () {
|
Y = Application.GetRealHeight (36),
|
Height = Application.GetRealHeight (90),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
AddChidren (topView);
|
|
var title = new Button () {
|
Width = Application.GetRealWidth (400),
|
TextAlignment = TextAlignment.Center,
|
Text = Language.StringByID (R.MyInternationalizationString.ACMerrill),
|
TextSize = 19,
|
TextColor = SkinStyle.Current.TextColor1,
|
Height = Application.GetMinReal (90),
|
Gravity = Gravity.CenterHorizontal,
|
};
|
topView.AddChidren (title);
|
|
//var logo = new Button () {
|
// Width = Application.GetRealWidth (154),
|
// Height = Application.GetRealHeight (90),
|
// X = Application.GetRealWidth (486),
|
// UnSelectedImagePath = MainPage.LogoString,
|
// Gravity = Gravity.CenterVertical,
|
//};
|
//topView.AddChidren (logo);
|
var back = new Button () {
|
Height = Application.GetRealHeight (90),
|
Width = Application.GetRealWidth (85),
|
UnSelectedImagePath = "Item/Back.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
topView.AddChidren (back);
|
back.MouseUpEventHandler += (sender, e) => {
|
(Parent as PageLayout).PageIndex -= 1;
|
curView = null;
|
};
|
#endregion
|
|
bodyScrolView = new VerticalScrolViewLayout () {
|
Height = Application.GetRealHeight (Application.DesignHeight - 126),
|
Y = topView.Bottom,
|
//BackgroundColor = SkinStyle.Current.ViewColor,
|
};
|
AddChidren (bodyScrolView);
|
|
|
#region HomeView 系统总控View
|
|
var HomeView = new FrameLayout () {
|
Width = LayoutParams.MatchParent,
|
Height = Application.GetRealHeight (298),
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
};
|
bodyScrolView.AddChidren (HomeView);
|
|
var homeTitle = new Button () {
|
Width = Application.GetRealWidth (200),
|
Height = Application.GetRealHeight (38),
|
X = Application.GetRealWidth (33),
|
Y = Application.GetRealHeight (32),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextID = R.MyInternationalizationString.MyHome,
|
TextSize = 20,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
HomeView.AddChidren (homeTitle);
|
|
//开关按键
|
tempSwitch = new Button () {
|
Width = Application.GetMinRealAverage (89),
|
Height = Application.GetMinRealAverage (54),
|
X = Application.GetRealWidth (640 - 89 - 32),
|
Y = Application.GetRealHeight (24),
|
UnSelectedImagePath = "Item/SwitchClose.png",
|
SelectedImagePath = "Item/SwitchOpen.png",
|
};
|
HomeView.AddChidren (tempSwitch);
|
|
tempSwitch.MouseUpEventHandler += (sender3, e3) => {
|
//弹窗询问
|
ShowAllAcOpenAlter ();
|
};
|
|
//空调总能耗
|
var statusTitle = new Button () {
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (27),
|
X = Application.GetRealWidth (34),
|
Y = Application.GetRealHeight (109),
|
TextAlignment = TextAlignment.CenterLeft,
|
//Text = "空调总能耗",
|
TextID = R.MyInternationalizationString.TotalEnergyConsumption,
|
TextSize = 14,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
HomeView.AddChidren (statusTitle);
|
|
//屏幕1/3宽
|
var MenuWidth = Application.GetRealWidth (640 / 3);
|
|
//今日耗电量
|
todayValueBtn = new Button () {
|
Width = MenuWidth,
|
Height = Application.GetRealHeight (27),
|
//X = Application.GetRealWidth (0),
|
Y = Application.GetRealHeight (183),
|
TextAlignment = TextAlignment.Center,
|
//Text = mACMerrill.DailyPowerConsumption.ToString ("F2") + "KWH",
|
TextSize = 14,
|
TextColor = 0xFFEB5C19,
|
};
|
HomeView.AddChidren (todayValueBtn);
|
|
var todayTitle = new Button () {
|
Width = MenuWidth,
|
Height = Application.GetRealHeight (27),
|
//X = Application.GetRealWidth (0),
|
Y = Application.GetRealHeight (228),
|
TextAlignment = TextAlignment.Center,
|
//Text = "今日耗电量",
|
TextID = R.MyInternationalizationString.DailyPowerConsumption,
|
TextSize = 12,
|
TextColor = 0x90FFFFFF,
|
};
|
HomeView.AddChidren (todayTitle);
|
|
//本月耗电量
|
monthValueBtn = new Button () {
|
Width = MenuWidth,
|
Height = Application.GetRealHeight (27),
|
X = todayValueBtn.Right,
|
Y = Application.GetRealHeight (183),
|
TextAlignment = TextAlignment.Center,
|
//Text = mACMerrill.MonthlyPowerConsumption.ToString ("F2") + "KWH",
|
TextSize = 14,
|
TextColor = 0xFFEB5C19,
|
};
|
HomeView.AddChidren (monthValueBtn);
|
|
|
|
var monthTitle = new Button () {
|
Width = MenuWidth,
|
Height = Application.GetRealHeight (27),
|
X = todayValueBtn.Right,
|
Y = Application.GetRealHeight (228),
|
TextAlignment = TextAlignment.Center,
|
//Text = "本月耗电量",
|
TextID = R.MyInternationalizationString.MonthlyPowerConsumption,
|
TextSize = 12,
|
TextColor = 0x90FFFFFF,
|
};
|
HomeView.AddChidren (monthTitle);
|
|
//用电功率
|
kwValueBtn = new Button () {
|
Width = MenuWidth,
|
Height = Application.GetRealHeight (27),
|
X = monthValueBtn.Right,
|
Y = Application.GetRealHeight (183),
|
TextAlignment = TextAlignment.Center,
|
//Text = mACMerrill.CurrentPower.ToString ("F2") + "KW",
|
TextSize = 14,
|
TextColor = 0xFFEB5C19,
|
};
|
HomeView.AddChidren (kwValueBtn);
|
|
|
var kwTitle = new Button () {
|
Width = MenuWidth,
|
Height = Application.GetRealHeight (27),
|
X = monthValueBtn.Right,
|
Y = Application.GetRealHeight (228),
|
TextAlignment = TextAlignment.Center,
|
//Text = "用电功率",
|
TextID = R.MyInternationalizationString.ElectricPower,
|
TextSize = 12,
|
TextColor = 0x90FFFFFF,
|
};
|
HomeView.AddChidren (kwTitle);
|
|
try {
|
todayValueBtn.Text = mACMerrill.DailyPowerConsumption.ToString ("F2") + "KWH";
|
monthValueBtn.Text = mACMerrill.MonthlyPowerConsumption.ToString ("F2") + "KWH";
|
kwValueBtn.Text = mACMerrill.CurrentPower.ToString ("F2") + "KW";
|
} catch {
|
|
}
|
|
#endregion
|
|
var btnLine1 = new Button () {
|
Height = 1,
|
BackgroundColor = SkinStyle.Current.LineColor,
|
};
|
bodyScrolView.AddChidren (btnLine1);
|
|
#region 离家 在家 View
|
var ScenesView = new FrameLayout () {
|
Width = LayoutParams.MatchParent,
|
Height = Application.GetRealHeight (175),
|
Y = HomeView.Bottom,
|
//BackgroundColor = SkinStyle.Current.ViewColor,
|
};
|
bodyScrolView.AddChidren (ScenesView);
|
|
var atHomeTitle = new Button () {
|
Width = MenuWidth,
|
Height = Application.GetRealHeight (27),
|
//X = Application.GetRealWidth (65),
|
Y = Application.GetRealHeight (117),
|
TextAlignment = TextAlignment.Center,
|
//Text = "在家",
|
TextID = R.MyInternationalizationString.AtHome,
|
TextSize = 14,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
ScenesView.AddChidren (atHomeTitle);
|
|
var width94X = (MenuWidth - Application.GetMinRealAverage (94)) / 2;
|
|
atHomeBtn = new Button () {
|
Width = Application.GetMinRealAverage (94),
|
Height = Application.GetMinRealAverage (94),
|
X = width94X,
|
Y = Application.GetRealHeight (16),
|
UnSelectedImagePath = "ACMerrill/ACAtHome.png",
|
SelectedImagePath = "ACMerrill/ACAtHomeSelected.png",
|
};
|
ScenesView.AddChidren (atHomeBtn);
|
|
|
|
var outHomeTitle = new Button () {
|
Width = MenuWidth,
|
Height = Application.GetRealHeight (27),
|
X = MenuWidth*2,
|
Y = Application.GetRealHeight (117),
|
TextAlignment = TextAlignment.Center,
|
//Text = "离家",
|
TextID = R.MyInternationalizationString.OutHome,
|
TextSize = 14,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
ScenesView.AddChidren (outHomeTitle);
|
|
outHomeBtn = new Button () {
|
Width = Application.GetMinRealAverage (94),
|
Height = Application.GetMinRealAverage (94),
|
X = width94X + MenuWidth*2,
|
Y = Application.GetRealHeight (16),
|
UnSelectedImagePath = "ACMerrill/ACOutHome.png",
|
SelectedImagePath = "ACMerrill/ACOutHomeSelected.png",
|
};
|
ScenesView.AddChidren (outHomeBtn);
|
|
|
EventHandler<MouseEventArgs> atHomeEventHandler = (button, mouseEventArgs) => {
|
Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
|
Language.StringByID (R.MyInternationalizationString.IfSetToAtHomeMode),
|
Language.StringByID (R.MyInternationalizationString.Cancel),
|
Language.StringByID (R.MyInternationalizationString.Confrim));
|
alert.Show ();
|
alert.ResultEventHandler += (sender2, e2) => {
|
if (e2) {
|
atHomeBtn.IsSelected = true;
|
outHomeBtn.IsSelected = false;
|
SetSceneModeIsAtHome (true);
|
}
|
};
|
|
|
};
|
|
EventHandler<MouseEventArgs> outHomeEventHandler = (button, mouseEventArgs) => {
|
Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
|
Language.StringByID (R.MyInternationalizationString.IfSetToOutHomeMode),
|
Language.StringByID (R.MyInternationalizationString.Cancel),
|
Language.StringByID (R.MyInternationalizationString.Confrim));
|
alert.Show ();
|
alert.ResultEventHandler += (sender2, e2) => {
|
if (e2) {
|
atHomeBtn.IsSelected = false;
|
outHomeBtn.IsSelected = true;
|
SetSceneModeIsAtHome (false);
|
}
|
};
|
|
};
|
|
atHomeBtn.MouseUpEventHandler = atHomeEventHandler;
|
atHomeTitle.MouseUpEventHandler = atHomeEventHandler;
|
outHomeTitle.MouseUpEventHandler = outHomeEventHandler;
|
outHomeBtn.MouseUpEventHandler = outHomeEventHandler;
|
|
#endregion
|
|
var btnLine2 = new Button () {
|
Height = 1,
|
BackgroundColor = SkinStyle.Current.LineColor,
|
};
|
bodyScrolView.AddChidren (btnLine2);
|
|
#region 模式 View
|
var ModeView = new FrameLayout () {
|
Width = LayoutParams.MatchParent,
|
Height = Application.GetRealHeight (181),
|
Y = HomeView.Bottom,
|
//BackgroundColor = SkinStyle.Current.ViewColor,
|
};
|
bodyScrolView.AddChidren (ModeView);
|
|
//通风
|
var strokeTitle = new Button () {
|
Width = MenuWidth,
|
Height = Application.GetRealHeight (27),
|
//X = Application.GetRealWidth (65),
|
Y = Application.GetRealHeight (117),
|
TextAlignment = TextAlignment.Center,
|
TextID = R.MyInternationalizationString.Ventila,
|
TextSize = 14,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
ModeView.AddChidren (strokeTitle);
|
|
|
strokeBtn = new Button () {
|
Width = Application.GetMinRealAverage (94),
|
Height = Application.GetMinRealAverage (94),
|
X = width94X,
|
Y = Application.GetRealHeight (16),
|
UnSelectedImagePath = "ACMerrill/ACStroke.png",
|
SelectedImagePath = "ACMerrill/ACStrokeSelected.png",
|
};
|
ModeView.AddChidren (strokeBtn);
|
|
//制热
|
var heatingTitle = new Button () {
|
Width = MenuWidth,
|
Height = Application.GetRealHeight (27),
|
X = MenuWidth,
|
Y = Application.GetRealHeight (117),
|
TextAlignment = TextAlignment.Center,
|
//Text = "制热",
|
TextID = R.MyInternationalizationString.Heating,
|
TextSize = 14,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
ModeView.AddChidren (heatingTitle);
|
|
|
heatingBtn = new Button () {
|
Width = Application.GetMinRealAverage (94),
|
Height = Application.GetMinRealAverage (94),
|
X = width94X+MenuWidth,
|
Y = Application.GetRealHeight (16),
|
UnSelectedImagePath = "ACMerrill/ACHeating.png",
|
SelectedImagePath = "ACMerrill/ACHeatingSelected.png",
|
};
|
ModeView.AddChidren (heatingBtn);
|
|
|
//制冷
|
var coolingTitle = new Button () {
|
Width = MenuWidth,
|
Height = Application.GetRealHeight (27),
|
X = MenuWidth * 2,
|
Y = Application.GetRealHeight (117),
|
TextAlignment = TextAlignment.Center,
|
//Text = "制冷",
|
TextID = R.MyInternationalizationString.Cool,
|
TextSize = 14,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
ModeView.AddChidren (coolingTitle);
|
|
coolingBtn = new Button () {
|
Width = Application.GetMinRealAverage (94),
|
Height = Application.GetMinRealAverage (94),
|
X = width94X + MenuWidth*2,
|
Y = Application.GetRealHeight (16),
|
UnSelectedImagePath = "ACMerrill/ACCooling.png",
|
SelectedImagePath = "ACMerrill/ACCoolingSelected.png",
|
};
|
ModeView.AddChidren (coolingBtn);
|
|
//制冷按钮
|
EventHandler<MouseEventArgs> coolingModeEventHandler = (button, mouseEventArgs) => {
|
|
Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
|
Language.StringByID (R.MyInternationalizationString.IfSetToCoolingMode),
|
Language.StringByID (R.MyInternationalizationString.Cancel),
|
Language.StringByID (R.MyInternationalizationString.Confrim));
|
alert.Show ();
|
alert.ResultEventHandler += (sender2, e2) => {
|
if (e2) {
|
coolingBtn.IsSelected = true;
|
heatingBtn.IsSelected = false;
|
strokeBtn.IsSelected = false;
|
SetWorkMode ((byte)0);
|
}
|
};
|
|
};
|
|
//制热按钮
|
EventHandler<MouseEventArgs> heatingModeEventHandler = (button, mouseEventArgs) => {
|
Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
|
Language.StringByID (R.MyInternationalizationString.IfSetToHeatingMode),
|
Language.StringByID (R.MyInternationalizationString.Cancel),
|
Language.StringByID (R.MyInternationalizationString.Confrim));
|
alert.Show ();
|
alert.ResultEventHandler += (sender2, e2) => {
|
if (e2) {
|
coolingBtn.IsSelected = false;
|
heatingBtn.IsSelected = true;
|
strokeBtn.IsSelected = false;
|
SetWorkMode ((byte)1);
|
}
|
};
|
|
};
|
|
//通风按钮
|
EventHandler<MouseEventArgs> strokeModeEventHandler = (button, mouseEventArgs) => {
|
Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
|
Language.StringByID (R.MyInternationalizationString.IfSetToVentilationMode),
|
Language.StringByID (R.MyInternationalizationString.Cancel),
|
Language.StringByID (R.MyInternationalizationString.Confrim));
|
alert.Show ();
|
alert.ResultEventHandler += (sender2, e2) => {
|
if (e2) {
|
coolingBtn.IsSelected = false;
|
heatingBtn.IsSelected = false;
|
strokeBtn.IsSelected = true;
|
SetWorkMode ((byte)2);
|
}
|
};
|
|
};
|
|
coolingBtn.MouseUpEventHandler = coolingModeEventHandler;
|
coolingTitle.MouseUpEventHandler = coolingModeEventHandler;
|
|
heatingBtn.MouseUpEventHandler = heatingModeEventHandler;
|
heatingTitle.MouseUpEventHandler = heatingModeEventHandler;
|
|
|
strokeBtn.MouseUpEventHandler = strokeModeEventHandler;
|
strokeTitle.MouseUpEventHandler = strokeModeEventHandler;
|
|
#endregion
|
|
btnLine3 = new Button () {
|
Height = Application.GetRealHeight (16),
|
BackgroundColor = SkinStyle.Current.LineColor,
|
};
|
bodyScrolView.AddChidren (btnLine3);
|
|
//mVerticalScrolViewLayout = new VerticalScrolViewLayout ();
|
//BodyView.AddChidren (mVerticalScrolViewLayout);
|
|
UpdateACHomeView ();
|
|
#region 空调列表View
|
//显示出所有的空调
|
mACListScrolView = new VerticalScrolViewLayout () {
|
Height = bodyScrolView.Height - btnLine3.Bottom,
|
//BackgroundColor = 0xff33ff33
|
};
|
bodyScrolView.AddChidren (mACListScrolView);
|
|
#endregion
|
LoadACList ();
|
|
ReadAllStatus ();
|
}
|
|
|
/// <summary>
|
/// 刷新View
|
/// </summary>
|
void UpdateACHomeView () {
|
tempSwitch.IsSelected = mACMerrill.Power > 0;
|
atHomeBtn.IsSelected = mACMerrill.ScenesMode == 0;
|
outHomeBtn.IsSelected = mACMerrill.ScenesMode > 0;
|
curView.coolingBtn.IsSelected = mACMerrill.WorkMode == 0;
|
curView.heatingBtn.IsSelected = mACMerrill.WorkMode == 1;
|
curView.strokeBtn.IsSelected = mACMerrill.WorkMode == 2;
|
|
}
|
|
/// <summary>
|
/// 加载所有子空调View
|
/// </summary>
|
void LoadACList ()
|
{
|
try {
|
mACListScrolView.RemoveAll ();
|
foreach (ACMerrillLoop ac in mACMerrill.mACMerrillLoopList) {
|
|
AddAcView (ac, mACListScrolView);
|
|
}
|
|
var nowHeight = bodyScrolView.Height - btnLine3.Bottom;
|
var allHeight = Application.GetRealHeight (158) * mACMerrill.mACMerrillLoopList.Count;
|
if (allHeight > nowHeight) {
|
mACListScrolView.Height = allHeight;
|
} else {
|
mACListScrolView.Height = nowHeight;
|
}
|
|
#if __IOS__
|
//bodyScrolView.ReLocation ();
|
#endif
|
} catch {
|
|
}
|
}
|
|
/// <summary>
|
/// 添加单个空调回路View
|
/// </summary>
|
/// <param name="mACMerrillLoop"></param>
|
/// <param name="VerticalScrolViewMiddle"></param>
|
void AddAcView (ACMerrillLoop mACMerrillLoop, VerticalScrolViewLayout VerticalScrolViewMiddle)
|
{
|
EventHandler<MouseEventArgs> openACMerrillDevicePage = (button, mouseEventArgs) => {
|
|
ACMerrillDevicePage mACMerrillDevicePage = new ACMerrillDevicePage (mACMerrillLoop);
|
(Parent as PageLayout).AddChidren (mACMerrillDevicePage);
|
mACMerrillDevicePage.ShowView ();
|
(Parent as PageLayout).PageIndex = (Parent as PageLayout).ChildrenCount - 1;
|
|
};
|
|
var acRowView = new ACMerrillRowView (mACMerrillLoop, openACMerrillDevicePage) {
|
Height = Application.GetRealHeight (158),
|
};
|
VerticalScrolViewMiddle.AddChidren (acRowView);
|
|
}
|
|
|
void ShowAllAcOpenAlter () {
|
|
var mes = tempSwitch.IsSelected ? Language.StringByID (R.MyInternationalizationString.AllACOff) : Language.StringByID (R.MyInternationalizationString.AllACOpen);
|
Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip),
|
mes,
|
Language.StringByID (R.MyInternationalizationString.Cancel),
|
Language.StringByID (R.MyInternationalizationString.Confrim));
|
alert.Show ();
|
alert.ResultEventHandler += (sender2, e2) => {
|
if (e2) {
|
//状态取反
|
tempSwitch.IsSelected = !tempSwitch.IsSelected;
|
SetAllAcOpen (tempSwitch.IsSelected);
|
}
|
};
|
|
}
|
|
/// <summary>
|
/// 全开全关
|
/// </summary>
|
/// <param name="isOn"></param>
|
void SetAllAcOpen (bool isOn)
|
{
|
try {
|
mACMerrill.Power = isOn ? (byte)1 : (byte)0;
|
Control.ControlBytesSend (Command.SetCommonSwitch, mACMerrill.SubnetID, mACMerrill.DeviceID, new byte [] { (byte)MerrillMasterMode.AllOnAndOffMode, mACMerrill.Power });
|
} catch { }
|
}
|
|
/// <summary>
|
/// 设置场景模式
|
/// </summary>
|
/// <param name="isAtHome"></param>
|
void SetSceneModeIsAtHome (bool isAtHome)
|
{
|
try {
|
mACMerrill.ScenesMode = isAtHome ? (byte)0 : (byte)1;
|
Control.ControlBytesSend (Command.SetCommonSwitch, mACMerrill.SubnetID, mACMerrill.DeviceID, new byte [] { (byte)MerrillMasterMode.SceneMode, mACMerrill.ScenesMode });
|
} catch { }
|
}
|
|
/// <summary>
|
/// 设置工作模式
|
/// 0制热、1制冷、2通风
|
/// </summary>
|
/// <param name="mWorkMode"> 0制热、1制冷、2通风</param>
|
void SetWorkMode (byte mWorkMode)
|
{
|
try {
|
mACMerrill.WorkMode = mWorkMode;
|
//byte sendByte = isAtHome ? (byte)1 : (byte)0;
|
Control.ControlBytesSend (Command.SetCommonSwitch, mACMerrill.SubnetID, mACMerrill.DeviceID, new byte [] { (byte)MerrillMasterMode.WorkMode, mWorkMode });
|
} catch { }
|
}
|
|
/// <summary>
|
/// 通用开关模式ID
|
/// </summary>
|
private enum MerrillMasterMode
|
{
|
/// <summary>
|
/// 离家 在家
|
/// </summary>
|
SceneMode = 1,
|
/// <summary>
|
/// 全开全开
|
/// </summary>
|
AllOnAndOffMode = 2,
|
/// <summary>
|
/// 工作模式
|
/// </summary>
|
WorkMode = 3,
|
}
|
|
/// <summary>
|
/// 模拟量ID
|
/// </summary>
|
private enum AnalogID
|
{
|
/// <summary>
|
/// 功率
|
/// </summary>
|
KW = 24,
|
/// <summary>
|
/// 日功耗
|
/// </summary>
|
DayPowerConsumption = 25,
|
/// <summary>
|
/// 月功耗
|
/// </summary>
|
MonthlyPowerConsumption = 26,
|
}
|
|
|
|
/// <summary>
|
/// 读功耗
|
/// </summary>
|
/// <param name="mAC"></param>
|
void ReadMerrillAnalogStatus (AnalogID readId)
|
{
|
try {
|
Control.ControlBytesSend (Command.ReadAnalog, mACMerrill.SubnetID, mACMerrill.DeviceID, new byte [] { 5, (byte)readId, 1 });
|
} catch { }
|
}
|
|
/// <summary>
|
/// 读美林系统状态
|
/// </summary>
|
/// <param name="mAC"></param>
|
void ReadMerrillStatus (MerrillMasterMode readId)
|
{
|
try {
|
Control.ControlBytesSend (Command.ReadHornLoopAlarm, mACMerrill.SubnetID, mACMerrill.DeviceID, new byte [] { (byte)readId });
|
} catch { }
|
}
|
|
|
/// <summary>
|
/// 读空调状态
|
/// </summary>
|
/// <param name="mAC"></param>
|
void ReadACStatus (ACMerrillLoop mAC)
|
{
|
Control.ControlBytesSend (Command.ReadACMode, mAC.SubnetID, mAC.DeviceID, new byte [] { mAC.LoopID });
|
}
|
|
System.Threading.Thread thread;
|
|
/// <summary>
|
/// 读取系统状态
|
/// </summary>
|
void ReadAllStatus ()
|
{
|
if (thread != null) {
|
thread.Abort ();
|
}
|
thread = new Thread (() => {
|
try {
|
ReadMerrillAnalogStatus (AnalogID.DayPowerConsumption);
|
Thread.Sleep (200);
|
ReadMerrillAnalogStatus (AnalogID.MonthlyPowerConsumption);
|
Thread.Sleep (200);
|
ReadMerrillAnalogStatus (AnalogID.KW);
|
Thread.Sleep (200);
|
ReadMerrillStatus (MerrillMasterMode.AllOnAndOffMode);
|
Thread.Sleep (200);
|
ReadMerrillStatus (MerrillMasterMode.SceneMode);
|
Thread.Sleep (200);
|
ReadMerrillStatus (MerrillMasterMode.WorkMode);
|
//读功率
|
|
//ReadACStatus (mACMerrill.mACMerrillLoopList[0]);
|
|
var list = mACMerrill.mACMerrillLoopList.FindAll ((obj) => {
|
return obj.LastUpdateTime.AddMinutes (Common.Time) <= DateTime.Now;
|
});
|
//System.Collections.Generic.List<string> readList = new System.Collections.Generic.List<string> ();
|
foreach (ACMerrillLoop mACMerrillLoop in list) {
|
if (mACMerrillLoop == null) {
|
continue;
|
}
|
Thread.Sleep (200);
|
ReadACStatus (mACMerrillLoop);
|
|
}
|
|
|
} catch (Exception xe) {
|
Console.WriteLine (xe.Message);
|
} finally {
|
thread = null;
|
}
|
});
|
thread.Start ();
|
|
|
}
|
|
|
///// <summary>
|
///// 接受数据之后更新UI
|
///// </summary>
|
///// <returns>The user lights.</returns>
|
//public static void UpdateStatus (byte subnetID, byte deviceID, byte loopID, byte status)
|
//{
|
// Application.RunOnMainThread (() => {
|
// if (curView == null) return;
|
|
// if (curView.mLightDoorLock.ReadStatusSubnetID != subnetID
|
// || curView.mLightDoorLock.ReadStatusDeviceID != deviceID
|
// || curView.mLightDoorLock.ReadStatusLoopID != loopID) {
|
// return;
|
// }
|
|
// curView.mLightDoorLock.CurrentStatus = status;
|
// curView.RefreshButtonStatus ();
|
// });
|
//}
|
|
/// <summary>
|
/// 更新美林系统状态
|
/// </summary>
|
/// <param name="subnetID"></param>
|
/// <param name="deviceID"></param>
|
/// <param name="SwitchID"></param>
|
/// <param name="StatusID"></param>
|
public static void UpdateMerrillModeStatus (byte SwitchID, byte StatusID)
|
{
|
Application.RunOnMainThread (() => {
|
if (curView == null) {
|
return;
|
}
|
|
if (curView.mACMerrill == null) {
|
return;
|
}
|
|
//if (curView.mACMerrill.SubnetID != subnetID || curView.mACMerrill.DeviceID != deviceID) {
|
// return;
|
//}
|
|
if (SwitchID == (byte)MerrillMasterMode.AllOnAndOffMode) {
|
|
curView.tempSwitch.IsSelected = StatusID > 0;
|
curView.mACMerrill.Power = StatusID;
|
|
} else if (SwitchID == (byte)MerrillMasterMode.SceneMode) {
|
curView.mACMerrill.ScenesMode = StatusID;
|
|
curView.atHomeBtn.IsSelected = !(StatusID > 0);
|
curView.outHomeBtn.IsSelected = StatusID > 0;
|
} else if (SwitchID == (byte)MerrillMasterMode.WorkMode) {
|
curView.coolingBtn.IsSelected = StatusID == 0;
|
curView.heatingBtn.IsSelected = StatusID == 1;
|
curView.strokeBtn.IsSelected = StatusID == 2;
|
curView.mACMerrill.WorkMode = StatusID;
|
}
|
|
|
});
|
}
|
|
/// <summary>
|
/// 更新美林系统 功耗状态
|
/// </summary>
|
/// <param name="subnetID"></param>
|
/// <param name="deviceID"></param>
|
/// <param name="SwitchID"></param>
|
/// <param name="StatusID"></param>
|
public static void UpdateMerrillAnalogStatus (byte [] usefullBytes)
|
{
|
Application.RunOnMainThread (() => {
|
if (curView == null) {
|
return;
|
}
|
|
if (curView.mACMerrill == null) {
|
return;
|
}
|
|
if (usefullBytes.Length < 9) {
|
return;
|
}
|
|
if (usefullBytes [0] != 5) {
|
return;
|
}
|
|
//var SwitchID = usefullBytes [1];
|
//var values = usefullBytes [5] * 256 * 256 * 256 + usefullBytes [6] * 256 * 256 + usefullBytes [7] * 256 + usefullBytes [8];
|
|
////var SwitchID =
|
|
//if (SwitchID == (byte)AnalogID.DayPowerConsumption) {
|
// curView.mACMerrill.DailyPowerConsumption = values;
|
// curView.todayValueBtn.Text = values + "KWH";
|
|
//} else if (SwitchID == (byte)AnalogID.MonthlyPowerConsumption) {
|
// curView.mACMerrill.MonthlyPowerConsumption = values;
|
// curView.monthValueBtn.Text = values + "KWH";
|
|
|
//} else if (SwitchID == (byte)AnalogID.KW) {
|
// curView.mACMerrill.CurrentPower = values;
|
// curView.kwValueBtn.Text = values + "KW";
|
//}
|
|
try {
|
//2020-05-28 修改为float类型
|
var SwitchID = usefullBytes [1];
|
var values = floatChange (usefullBytes [8], usefullBytes [7], usefullBytes [6], usefullBytes [5]);
|
var valuesStr = values.ToString ("F2");
|
|
//var SwitchID =
|
|
if (SwitchID == (byte)AnalogID.DayPowerConsumption) {
|
curView.mACMerrill.DailyPowerConsumption = values;
|
curView.todayValueBtn.Text = valuesStr + "KWH";
|
|
} else if (SwitchID == (byte)AnalogID.MonthlyPowerConsumption) {
|
curView.mACMerrill.MonthlyPowerConsumption = values;
|
curView.monthValueBtn.Text = valuesStr + "KWH";
|
|
|
} else if (SwitchID == (byte)AnalogID.KW) {
|
curView.mACMerrill.CurrentPower = values;
|
curView.kwValueBtn.Text = valuesStr + "KW";
|
}
|
} catch { }
|
|
});
|
}
|
|
public static float floatChange (byte b1, byte b2, byte b3, byte b4)
|
{
|
try {
|
byte [] byteTemp = new byte [4] { b4, b3, b2, b1 };
|
return BitConverter.ToSingle (byteTemp, 0);
|
} catch {
|
return 0.0f;
|
}
|
}
|
|
public static void SaveMerrilEquipmentMessage ()
|
{
|
if (curView == null) {
|
return;
|
}
|
|
if (curView.mACMerrill == null) {
|
return;
|
}
|
|
IO.FileUtils.SaveEquipmentMessage (curView.mACMerrill, curView.mACMerrill.LoopID.ToString ());
|
//IO.FileUtils.SaveEquipmentMessage (curView.mACMerrill);
|
|
|
}
|
|
|
|
/// <summary>
|
/// 更新空调
|
/// </summary>
|
public static void UpdateACStatus (ACMerrillLoop ac, bool selfUpdate = false)
|
{
|
Application.RunOnMainThread (() => {
|
try {
|
if (curView == null) {
|
return;
|
}
|
|
if (curView.bodyScrolView.Decelerating) {
|
return;
|
}
|
|
for (int i = 0; i < curView.mACListScrolView.ChildrenCount; i++) {
|
if (curView.mACListScrolView.GetChildren (i).GetType () == typeof (ACMerrillRowView)) {
|
var acRow = (ACMerrillRowView)curView.mACListScrolView.GetChildren (i);
|
var o = acRow.Tag;
|
if (o != null && o.ToString () == ac.CommonLoopID) {
|
acRow.UpdateButton (ac);
|
}
|
}
|
}
|
} catch {
|
|
}
|
|
});
|
}
|
|
/// <summary>
|
/// 刷新
|
/// </summary>
|
public static void UpdateACRowView () {
|
if (curView == null) {
|
return;
|
}
|
|
curView.LoadACList ();
|
|
}
|
}
|
}
|