using System;
using System.Collections.Generic;
using System.Text;
//using Newtonsoft.Json.Linq;
////using service.hdlcontrol.com_WebServiceAirQuality;
using HDL_ON.DAL.Net;
using HDL_ON.UI;
using Shared;
using Shared.IOS;
using Shared.Net;
namespace HDL_ON.DAL
{
public static class CommonPage
{
public static bool IsRemote;
//public static AirQuality AirQuality;
public static Action RefreshAir;
public static bool FindGateway = false;
public static bool FindGatewayChilren = false;
public static string FindGatewayChilrenIPAddress = new NetWiFi ().BroadcastIpAddress.ToString ();
public static bool LocalPhoneFindDevice = false;
private static string ip = "0.0.0.0";
public static System.Net.IPEndPoint EndPoint {
get {
try {
if (FindGateway) {
return new System.Net.IPEndPoint (System.Net.IPAddress.Parse (new NetWiFi ().BroadcastIpAddress.ToString ()), 6000);
} else if (FindGatewayChilren) {
try {
return new System.Net.IPEndPoint (System.Net.IPAddress.Parse (FindGatewayChilrenIPAddress), 6000);
} catch {
return new System.Net.IPEndPoint (System.Net.IPAddress.Parse ("224.0.168.188"), 6000);
}
} else {
return new System.Net.IPEndPoint (System.Net.IPAddress.Parse (new NetWiFi ().BroadcastIpAddress.ToString ()), 6000);
}
} catch {
//防止异常导致程序退出
return new System.Net.IPEndPoint (System.Net.IPAddress.Parse ("127.0.0.1"), 6000);
}
}
}
///保存设备备注才用gb2312,其他情况用utf8
public static Encoding MyEncodingUTF8 = Encoding.UTF8;//Get
public static Encoding MyEncodingGB2312 {
get {
try {
if (System.Globalization.CultureInfo.InstalledUICulture.EnglishName.ToUpper().StartsWith("CZECH")) {
return System.Text.Encoding.GetEncoding (1250);
} else {
return Encoding.GetEncoding ("gb2312");
}
}catch (Exception ex) {
MainPage.Log ("MyEncodingGB2312 Erorr : "+ex.Message);
return Encoding.GetEncoding ("gb2312");
}
}
}
static bool isHttpListenerStart;
public static DateTime dt;
//public static byte currentSubnetID = 0;
public static void InitHttpListener ()
{
if (isHttpListenerStart) {
return;
}
HttpListener.Start (new NetWiFi ().IpAddress, 6001);
HttpListener.EventHandler -= httpListener_EventHandler;
HttpListener.EventHandler += httpListener_EventHandler;
isHttpListenerStart = true;
}
public static void CloseHttpListener ()
{
//isHttpListenerStart = false;
//return;
if (!isHttpListenerStart)
return;
HttpListener.Close ();
isHttpListenerStart = false;
}
///
/// 初始化处理socket接收的数据
///
public static void InitReceiveEvent ()
{
Packet.ReceiveEvent += Packet_ReceiveEvent;
}
public static float floatChange (byte b1, byte b2, byte b3, byte b4)
{
byte [] byteTemp = new byte [4] { b4, b3, b2, b1 };
return BitConverter.ToSingle (byteTemp, 0);
}
static void Packet_ReceiveEvent (byte subnetID, byte deviceID, Command command, byte [] usefullBytes, string revGatewayIP)
{
//try {
// List ButtonBkeyModelList = new List ();
// switch (command) {
// case Command.ReadAnalogACK:
// if (UserConfig.Instance.IsSetHomePageSensor) {
// DeviceType deviceType2 = (DeviceType)(usefullBytes [0] * 256 + usefullBytes [1]);
// switch (deviceType2) {
// case DeviceType.SensorPM25:
// if(UserConfig.Instance.pm25.SubnetID == subnetID&& UserConfig.Instance.pm25.DeviceID == deviceID && UserConfig.Instance.pm25.LoopID == usefullBytes[2]) {
// switch(usefullBytes [3]) {
// case 1://无符号整形
// UserConfig.Instance.pm25.values = usefullBytes [5] * 256 * 256 * 256 + usefullBytes [6] * 256 * 256 + usefullBytes [7] * 256 + usefullBytes [8];
// break;
// case 2://有符号整形
// if (usefullBytes [5] > 128) {
// UserConfig.Instance.pm25.values = (1 - (usefullBytes [5] - 128) * 256 * 256 * 256 + usefullBytes [6] * 256 * 256 + usefullBytes [7] * 256 + usefullBytes [8]);
// } else {
// UserConfig.Instance.pm25.values = usefullBytes [5] * 256 * 256 * 256 + usefullBytes [6] * 256 * 256 + usefullBytes [7] * 256 + usefullBytes [8];
// }
// break;
// case 3://Float
// UserConfig.Instance.pm25.values = (double) floatChange (usefullBytes [5], usefullBytes [6], usefullBytes [7], usefullBytes [8]);
// break;
// }
// }
// break;
// case DeviceType.SensorTemperature:
// if (UserConfig.Instance.temp.SubnetID == subnetID && UserConfig.Instance.temp.DeviceID == deviceID && UserConfig.Instance.temp.LoopID == usefullBytes [2]) {
// switch (usefullBytes [3]) {
// case 1://无符号整形
// UserConfig.Instance.temp.values = usefullBytes [5] * 256 * 256 * 256 + usefullBytes [6] * 256 * 256 + usefullBytes [7] * 256 + usefullBytes [8];
// break;
// case 2://有符号整形
// if (usefullBytes [5] > 128) {
// UserConfig.Instance.temp.values = (1 - (usefullBytes [5] - 128) * 256 * 256 * 256 + usefullBytes [6] * 256 * 256 + usefullBytes [7] * 256 + usefullBytes [8]);
// } else {
// UserConfig.Instance.temp.values = usefullBytes [5] * 256 * 256 * 256 + usefullBytes [6] * 256 * 256 + usefullBytes [7] * 256 + usefullBytes [8];
// }
// break;
// case 3://Float
// UserConfig.Instance.temp.values = (double)floatChange (usefullBytes [8], usefullBytes [7], usefullBytes [6], usefullBytes [5]);
// break;
// }
// }
// break;
// case DeviceType.SensorCO2:
// if (UserConfig.Instance.co2.SubnetID == subnetID && UserConfig.Instance.co2.DeviceID == deviceID && UserConfig.Instance.co2.LoopID == usefullBytes [2]) {
// switch (usefullBytes [3]) {
// case 1://无符号整形
// UserConfig.Instance.co2.values = usefullBytes [5] * 256 * 256 * 256 + usefullBytes [6] * 256 * 256 + usefullBytes [7] * 256 + usefullBytes [8];
// break;
// case 2://有符号整形
// if (usefullBytes [5] > 128) {
// UserConfig.Instance.co2.values = (1 - (usefullBytes [5] - 128) * 256 * 256 * 256 + usefullBytes [6] * 256 * 256 + usefullBytes [7] * 256 + usefullBytes [8]);
// } else {
// UserConfig.Instance.co2.values = usefullBytes [5] * 256 * 256 * 256 + usefullBytes [6] * 256 * 256 + usefullBytes [7] * 256 + usefullBytes [8];
// }
// break;
// case 3://Float
// UserConfig.Instance.co2.values = (double)floatChange (usefullBytes [8], usefullBytes [7], usefullBytes [6], usefullBytes [5]);
// break;
// }
// }
// break;
// case DeviceType.SensorHumidity:
// if (UserConfig.Instance.humidity.SubnetID == subnetID && UserConfig.Instance.humidity.DeviceID == deviceID && UserConfig.Instance.humidity.LoopID == usefullBytes [2]) {
// switch (usefullBytes [3]) {
// case 1://无符号整形
// UserConfig.Instance.humidity.values = usefullBytes [5] * 256 * 256 * 256 + usefullBytes [6] * 256 * 256 + usefullBytes [7] * 256 + usefullBytes [8];
// break;
// case 2://有符号整形
// if (usefullBytes [5] > 128) {
// UserConfig.Instance.humidity.values = (1 - (usefullBytes [5] - 128) * 256 * 256 * 256 + usefullBytes [6] * 256 * 256 + usefullBytes [7] * 256 + usefullBytes [8]);
// } else {
// UserConfig.Instance.humidity.values = usefullBytes [5] * 256 * 256 * 256 + usefullBytes [6] * 256 * 256 + usefullBytes [7] * 256 + usefullBytes [8];
// }
// break;
// case 3://Float
// UserConfig.Instance.humidity.values = (double)floatChange (usefullBytes [8], usefullBytes [7], usefullBytes [6], usefullBytes [5]);
// break;
// }
// }
// break;
// case DeviceType.SensorTVOC:
// if (UserConfig.Instance.tvoc.SubnetID == subnetID && UserConfig.Instance.tvoc.DeviceID == deviceID && UserConfig.Instance.tvoc.LoopID == usefullBytes [2]) {
// switch (usefullBytes [3]) {
// case 1://无符号整形
// UserConfig.Instance.tvoc.values = usefullBytes [5] * 256 * 256 * 256 + usefullBytes [6] * 256 * 256 + usefullBytes [7] * 256 + usefullBytes [8];
// break;
// case 2://有符号整形
// if (usefullBytes [5] > 128) {
// UserConfig.Instance.tvoc.values = (1 - (usefullBytes [5] - 128) * 256 * 256 * 256 + usefullBytes [6] * 256 * 256 + usefullBytes [7] * 256 + usefullBytes [8]);
// } else {
// UserConfig.Instance.tvoc.values = usefullBytes [5] * 256 * 256 * 256 + usefullBytes [6] * 256 * 256 + usefullBytes [7] * 256 + usefullBytes [8];
// }
// break;
// case 3://Float
// UserConfig.Instance.tvoc.values = (double)floatChange (usefullBytes [8], usefullBytes [7], usefullBytes [6], usefullBytes [5]);
// break;
// }
// }
// break;
// }
// }
// break;
// case Command.ReadThermostatExtensionACK:
// case Command.SetThermostatExtensionACK:
// foreach (var room in Room.Lists) {
// var commons = room.DeviceList.FindAll ((obj) => obj.SubnetID == subnetID && obj.DeviceID == deviceID && obj.Type == DeviceType.Thermostat);
// if (commons != null && commons.Count>0) {
// foreach (var common in commons) {
// var cac = common as Thermostat;
// if (cac.ExtensionID == usefullBytes [0]) {
// // 1 通道号 1-255
// // 2 温控器开/关机 0-关机,1-开机
// // 3 模拟量激活位 从低位开始 如bit0对应温控器环境温度值
// // 4-7 温控器环境温度值 浮点型数据 ℃ IEEE 754浮点数
// // 8-11 温控器设置温度值 浮点型数据 ℃ IEEE 754浮点数
// // 12-15 温控器环境湿度值 浮点型数据 % IEEE 754浮点数
// // 16-19 温控器设置湿度值 浮点型数据 % IEEE 754浮点数
// cac.Power = usefullBytes [1];
// cac.AnalogActivationByte = usefullBytes [2];
// cac.Indoor_Temperature_Values1 = usefullBytes [3];
// cac.Indoor_Temperature_Values2 = usefullBytes [4];
// cac.Indoor_Temperature_Values3 = usefullBytes [5];
// cac.Indoor_Temperature_Values4 = usefullBytes [6];
// cac.Setting_Temperature_Values1 = usefullBytes [7];
// cac.Setting_Temperature_Values2 = usefullBytes [8];
// cac.Setting_Temperature_Values3 = usefullBytes [9];
// cac.Setting_Temperature_Values4 = usefullBytes [10];
// cac.Indoor_Humidity_Values1 = usefullBytes [11];
// cac.Indoor_Humidity_Values2 = usefullBytes [12];
// cac.Indoor_Humidity_Values3 = usefullBytes [13];
// cac.Indoor_Humidity_Values4 = usefullBytes [14];
// cac.Setting_Humidity_Values1 = usefullBytes [15];
// cac.Setting_Humidity_Values2 = usefullBytes [16];
// cac.Setting_Humidity_Values3 = usefullBytes [17];
// cac.Setting_Humidity_Values4 = usefullBytes [18];
// MainPage.WriteLog ("ReadThermostatExtensionACK : 222");
// UserRoom.UpdateThermostatExtensionTempAndHumidityValues (cac);
// MainPage.WriteLog ("ReadThermostatExtensionACK : 333");
// ThermostatExtensionPage.UpdateStatus (cac);
// MainPage.WriteLog ("ReadThermostatExtensionACK : 444");
// ThermostatHostPage.UpdateExtensionStatus (cac);
// MainPage.WriteLog ("ReadThermostatExtensionACK : 555");
// IO.FileUtils.SaveEquipmentMessage (cac, cac.LoopID.ToString ());
// }
// }
// }
// }
// break;
// case Command.ReadThermostatHostACK:
// case Command.SetThermostatHostACK:
// foreach (var cac in Room.Thermostat_HostList) {
// if (cac.SubnetID == subnetID && cac.DeviceID == deviceID && cac.HostID == usefullBytes [0]) {
// // 1 通道号
// // 2 开/关机 0--关 1--开
// // 3 运行模式 1-制冷,2-制热,3-通风,4-除湿,5-制热除湿
// // 4 运行场景 1-在家,2-离家,3-睡眠
// // 5 湿度档位 1-低,2-中,3-高(只在制热模式下可以设置)
// // 6 滤网百分比 %
// // 7 温控器分机数量 1-32
// // 8-9 故障信息1
// // 10-11 故障信息2
// // 12-13 故障信息3
// // 14-15 故障信息4
// // 16-17 故障信息5
// // 18-19 故障信息6
// // 20-21 模拟量激活位 从低位开始,如enable[0] 的bit0--->室内温度
// // 22-25 模拟量1(bit0)室内温度 浮点型数据 IEEE 754浮点数
// // 26-29 模拟量2(bit1)室内湿度 浮点型数据 0-100 % IEEE 754浮点数
// // 30-33 模拟量3(bit2)室内CO2 浮点型数据 PPM IEEE 754浮点数
// // 34-37 模拟量4(bit3)室内TVOC 浮点型数据 级 IEEE 754浮点数
// // 38-41 模拟量5(bit4)室内PM2.5 浮点型数据 PPM IEEE 754浮点数
// // 42-45 模拟量6(bit5)室外温度 浮点型数据 IEEE 754浮点数
// // 46-49 模拟量7(bit6)室外湿度 浮点型数据 0-100 % IEEE 754浮点数
// // 50-53 模拟量8(bit7)室外PM2.5 浮点型数据 PPM IEEE 754浮点数
// cac.LoopID = 1;
// cac.Power = usefullBytes [1];
// cac.CurrentMode = usefullBytes [2];
// cac.CurrentScene = usefullBytes [3];
// cac.HumidityLevel = usefullBytes [4];
// cac.StrainerState = usefullBytes [5];
// cac.ExtensionCount = usefullBytes [6];
// cac.FaultInformation1 = usefullBytes [7] * 256 + usefullBytes [8];
// cac.FaultInformation1 = usefullBytes [9] * 256 + usefullBytes [10];
// cac.FaultInformation1 = usefullBytes [11] * 256 + usefullBytes [12];
// cac.FaultInformation1 = usefullBytes [13] * 256 + usefullBytes [14];
// cac.FaultInformation1 = usefullBytes [15] * 256 + usefullBytes [16];
// cac.FaultInformation1 = usefullBytes [17] * 256 + usefullBytes [18];
// cac.AnalogActivationByte = usefullBytes [19];
// cac.AnalogActivationByte2 = usefullBytes [20];
// var AnalogActivationIndexString = Convert.ToString (cac.AnalogActivationByte2,2).PadLeft(8,'0');
// if (AnalogActivationIndexString [7] == '1') {
// cac.Indoor_Temperature_Values1 = usefullBytes [21];
// cac.Indoor_Temperature_Values2 = usefullBytes [22];
// cac.Indoor_Temperature_Values3 = usefullBytes [23];
// cac.Indoor_Temperature_Values4 = usefullBytes [24];
// }
// if (AnalogActivationIndexString [6] == '1') {
// cac.Indoor_Humidity_Values1 = usefullBytes [25];
// cac.Indoor_Humidity_Values2 = usefullBytes [26];
// cac.Indoor_Humidity_Values3 = usefullBytes [27];
// cac.Indoor_Humidity_Values4 = usefullBytes [28];
// }
// if (AnalogActivationIndexString [5] == '1') {
// cac.Indoor_CO2_Values1 = usefullBytes [29];
// cac.Indoor_CO2_Values2 = usefullBytes [30];
// cac.Indoor_CO2_Values3 = usefullBytes [31];
// cac.Indoor_CO2_Values4 = usefullBytes [32];
// }
// if (AnalogActivationIndexString [4] == '1') {
// cac.Indoor_TVOC_Values1 = usefullBytes [33];
// cac.Indoor_TVOC_Values2 = usefullBytes [34];
// cac.Indoor_TVOC_Values3 = usefullBytes [35];
// cac.Indoor_TVOC_Values4 = usefullBytes [36];
// }
// if (AnalogActivationIndexString [3] == '1') {
// cac.Indoor_PM25_Values1 = usefullBytes [37];
// cac.Indoor_PM25_Values2 = usefullBytes [38];
// cac.Indoor_PM25_Values3 = usefullBytes [39];
// cac.Indoor_PM25_Values4 = usefullBytes [40];
// }
// if (AnalogActivationIndexString [2] == '1') {
// cac.Outdoor_Temperature_Values1 = usefullBytes [41];
// cac.Outdoor_Temperature_Values2 = usefullBytes [42];
// cac.Outdoor_Temperature_Values3 = usefullBytes [43];
// cac.Outdoor_Temperature_Values4 = usefullBytes [44];
// }
// if (AnalogActivationIndexString [1] == '1') {
// cac.Outdoor_Humidity_Values1 = usefullBytes [45];
// cac.Outdoor_Humidity_Values2 = usefullBytes [46];
// cac.Outdoor_Humidity_Values3 = usefullBytes [47];
// cac.Outdoor_Humidity_Values4 = usefullBytes [48];
// }
// if (AnalogActivationIndexString [0] == '1') {
// cac.Outdoor_PM25_Values1 = usefullBytes [49];
// cac.Outdoor_PM25_Values2 = usefullBytes [50];
// cac.Outdoor_PM25_Values3 = usefullBytes [51];
// cac.Outdoor_PM25_Values4 = usefullBytes [52];
// }
// ThermostatHostPage.UpdateStatus (cac);
// ThermostatExtensionPage.UptateMode (cac);
// foreach (var room in Room.Lists) {
// foreach (var device in room.DeviceList) {
// if (device.Type == DeviceType.Thermostat) {
// var cac1 = device as Thermostat;
// if (cac.SubnetID == cac1.SubnetID && cac.DeviceID == cac1.DeviceID && cac.HostID == cac1.HostID) {
// cac1.CurrentMode = cac.CurrentMode;
// UserRoom.UpdateThermostatModeStatus (cac1);
// IO.FileUtils.SaveEquipmentMessage (cac1, cac1.LoopID.ToString ());
// }
// }
// }
// }
// IO.FileUtils.SaveEquipmentMessage (cac);
// }
// }
// break;
// case Command.FreshAirReadACK:
// case Command.FreshAirControlACK:
// foreach (var room in Room.Lists) {
// var common = room.DeviceList.Find ((obj) => obj.SubnetID == subnetID && obj.DeviceID == deviceID && obj.LoopID == usefullBytes [0] && obj.Type == DeviceType.FreshAir);
// if (common != null) {
// var fresAirReceive = common as FreshAir;
// fresAirReceive.SwitchStatus = usefullBytes [1];
// fresAirReceive.WindSpeed = usefullBytes [2];
// fresAirReceive.SetPattern = usefullBytes [3];
// fresAirReceive.EnableValue1 = usefullBytes [4];
// fresAirReceive.EnableValue2 = usefullBytes [5];
// if (usefullBytes.Length > 6) {
// fresAirReceive.InTemp = floatChange (usefullBytes [6], usefullBytes [7], usefullBytes [8], usefullBytes [9]);
// fresAirReceive.OutTemp = floatChange (usefullBytes [10], usefullBytes [11], usefullBytes [12], usefullBytes [13]);
// fresAirReceive.Humidity = floatChange (usefullBytes [14], usefullBytes [15], usefullBytes [16], usefullBytes [17]);
// fresAirReceive.PM25 = floatChange (usefullBytes [18], usefullBytes [19], usefullBytes [20], usefullBytes [21]);
// fresAirReceive.TVOC = floatChange (usefullBytes [22], usefullBytes [23], usefullBytes [24], usefullBytes [25]);
// fresAirReceive.CO2 = floatChange (usefullBytes [26], usefullBytes [27], usefullBytes [28], usefullBytes [29]);
// }
// IO.FileUtils.SaveEquipmentMessage (fresAirReceive, fresAirReceive.LoopID.ToString ());
// UserFresAirList.UpdateStatus (fresAirReceive);
// UserRoom.UpdataDeviceStatus (fresAirReceive);
// UserFreshAirPage.UpdateStatus (fresAirReceive);
// }
// }
// break;
// case Command.SetArmACK:
// case Command.ReadArmACK:
// if (Application.IsPad) { } else {
// SecurityModul sm = new SecurityModul () {
// SubnetID = subnetID,
// DeviceID = subnetID,
// LoopID = usefullBytes [0],
// AreaType = usefullBytes [1],
// };
// UserSecurityAreaPage.UpdateStatus (sm);
// }
// break;
// case Command.ReadLightEquipmentAllLoopBrightnessACK://18145611909
// for (byte i = 1; i <= usefullBytes [0]; i++) {
// bool updateLightStatus = true;
// foreach (var room in Room.Lists) {
// Common common = null;
// var commons = room.DeviceList.FindAll ((obj) => obj.SubnetID == subnetID && obj.DeviceID == deviceID);
// if (commons.Count > 0) {
// foreach (var c in commons) {
// if (c.Type == DeviceType.LightMixDimming) {
// var rcuDimming = (c as LightMixDimming);
// if (rcuDimming.SubnetID == subnetID && rcuDimming.DeviceID == deviceID && rcuDimming.PhysicsLoopID == i) {
// if (rcuDimming.CurrentBrightness == usefullBytes [i]) {
// updateLightStatus = false;
// }
// rcuDimming.CurrentBrightness = usefullBytes [i];
// common = rcuDimming;
// }
// }
// if (c.Type == DeviceType.LightMixSwitch) {
// var rcuSwitch = (c as LightMixSwitch);
// if (rcuSwitch.SubnetID == subnetID && rcuSwitch.DeviceID == deviceID && rcuSwitch.PhysicsLoopID == i) {
// if (rcuSwitch.CurrentBrightness == usefullBytes [i]) {
// updateLightStatus = false;
// }
// rcuSwitch.CurrentBrightness = usefullBytes [i];
// common = rcuSwitch;
// }
// }
// }
// }
// if (common == null)
// common = room.DeviceList.Find ((obj) => obj.SubnetID == subnetID && obj.DeviceID == deviceID && obj.LoopID == i);
// if (common != null) {
// //foreach (var common in room.DeviceList) {
// //if (common.SubnetID != subnetID || common.DeviceID != deviceID || common.LoopID != i) {
// // continue;
// //}
// common.LastUpdateTime = DateTime.Now;
// if (common.Type == DeviceType.LightSwitch || common.Type == DeviceType.LightSwitchSocket || common.Type == DeviceType.LightEnergySwitch) {
// if ((common as LightSwitch).CurrentBrightness == usefullBytes [i]) {
// updateLightStatus = false;
// }
// (common as LightSwitch).CurrentBrightness = usefullBytes [i];
// } else if (common.Type == DeviceType.LightDimming) {
// if ((common as LightDimming).CurrentBrightness == usefullBytes [i]) {
// updateLightStatus = false;
// }
// (common as LightDimming).CurrentBrightness = usefullBytes [i];
// } else if (common.Type == DeviceType.FanModule) {
// if ((common as FanModule).Switch == usefullBytes [i]) {
// updateLightStatus = false;
// }
// (common as FanModule).Switch = usefullBytes [i];
// if (usefullBytes [i] != 0)
// (common as FanModule).WindSpeed = usefullBytes [i];
// } else if (common.Type == DeviceType.LightDALI) {
// if ((common as LightDALI).CurrentBrightness == usefullBytes [i]) {
// updateLightStatus = false;
// }
// (common as LightDALI).CurrentBrightness = usefullBytes [i];
// }
// string updateFlag = common.CommonLoopID;
// if (Application.IsPad) {
// //Pad.UserLightPage.UpdateStatus (updateFlag, usefullBytes [i]);
// //Pad.UserDeviceToLight.UpdateStatus ();
// //Pad.UserDeviceToLight.UpdateAllLightsStatus (updateFlag, usefullBytes [i]);
// //Pad.UserDeviceToSocket.UpdateStatus (updateFlag, usefullBytes [i]);
// //Pad.UserFan.UpdataFanView (updateFlag, usefullBytes [i]);
// } else {
// UserDeviceToLight.UpdateBrighingCount (updateFlag);
// if (updateLightStatus) {
// UserRoom.UpdataDeviceStatus (common);
// UserLightPage.UpdateStatus (updateFlag, usefullBytes [i]);
// UserDeviceToLight.UpdateStatus (updateFlag, usefullBytes [i]);
// UserFan.UpdataFanView (updateFlag, usefullBytes [i]);
// UserDeviceToFan.UpdataStatus (updateFlag, usefullBytes [i]);
// UserDeviceToSocket.UpdateStatus (updateFlag, usefullBytes [i]);
// }
// }
// }
// }
// }
// break;
// case Command.SetSingleLightACK:
// foreach (var room in Room.Lists) {
// var common = room.DeviceList.Find ((obj) => obj.CommonLoopID == subnetID.ToString () + "_" + deviceID.ToString () + "_" + usefullBytes [0].ToString ());
// if (common != null) {
// //foreach (var common in room.DeviceList) {
// if (common.CommonLoopID != subnetID.ToString () + "_" + deviceID.ToString () + "_" + usefullBytes [0].ToString ()) {
// continue;
// }
// string updateFlag = common.CommonLoopID;
// if (common.Type == DeviceType.LightRGB) {
// break;
// }
// common.LastUpdateTime = DateTime.Now;
// bool hadBeUpdate = true;
// if (common.Type == DeviceType.LightSwitch || common.Type == DeviceType.LightSwitchSocket || common.Type == DeviceType.LightSwitchSocket) {
// if ((common as LightSwitch).CurrentBrightness == usefullBytes [2])
// hadBeUpdate = false;
// (common as LightSwitch).CurrentBrightness = usefullBytes [2];
// } else if (common.Type == DeviceType.LightDimming) {
// if ((common as LightDimming).CurrentBrightness == usefullBytes [2])
// hadBeUpdate = false;
// (common as LightDimming).CurrentBrightness = usefullBytes [2];
// } else if (common.Type == DeviceType.FanModule) {
// if ((common as FanModule).Switch == usefullBytes [2])
// hadBeUpdate = false;
// (common as FanModule).Switch = usefullBytes [2];
// if (usefullBytes [2] != 0)
// (common as FanModule).WindSpeed = usefullBytes [2];
// } else if (common.Type == DeviceType.LightMixSwitch) {
// if ((common as LightMixSwitch).CurrentBrightness == usefullBytes [2])
// hadBeUpdate = false;
// (common as LightMixSwitch).CurrentBrightness = usefullBytes [2];
// } else if (common.Type == DeviceType.LightMixDimming) {
// if ((common as LightMixDimming).CurrentBrightness == usefullBytes [2])
// hadBeUpdate = false;
// (common as LightMixDimming).CurrentBrightness = usefullBytes [2];
// } else if (common.Type == DeviceType.LightDALI) {
// if ((common as LightDALI).CurrentBrightness == usefullBytes [2])
// hadBeUpdate = false;
// (common as LightDALI).CurrentBrightness = usefullBytes [2];
// }
// if (Application.IsPad) {
// //Pad.UserLightPage.UpdateStatus (updateFlag, usefullBytes [2]);
// //Pad.UserDeviceToLight.UpdateStatus ();
// //Pad.UserDeviceToLight.UpdateAllLightsStatus (updateFlag, usefullBytes [2]);
// //Pad.UserDeviceToSocket.UpdateStatus (updateFlag, usefullBytes [2]);
// //Pad.UserFan.UpdataFanView (updateFlag, usefullBytes [2]);
// //break;
// } else {
// UserDeviceToLight.UpdateBrighingCount (updateFlag);
// if (hadBeUpdate) {
// UserRoom.UpdataDeviceStatus (common);
// UserLightPage.UpdateStatus (updateFlag, usefullBytes [2]);
// UserDeviceToLight.UpdateStatus (updateFlag, usefullBytes [2]);
// UserFan.UpdataFanView (updateFlag, usefullBytes [2]);
// UserDeviceToFan.UpdataStatus (updateFlag, usefullBytes [2]);
// UserDeviceToSocket.UpdateStatus (updateFlag, usefullBytes [2]);
// }
// //break;
// }
// }
// }
// break;
// case Command.SetSceneACK:
// /// [0]// 区号1-n, 255表示所有区(用于广播场景) 1byte
// /// [1]// 场号0-x 1byte
// /// [2]// 回路总数n 1byte
// /// [3]// 回路状态:bit位 0关、1开,(byte:bit0-7对应1-8回路 ...n回路) ((n+7)/8) byte
// foreach (var room in Room.Lists) {
// var commonList = room.DeviceList.FindAll ((obj) => obj.CommonLoopID == subnetID.ToString () + "_" + deviceID.ToString () + "_" + usefullBytes [0].ToString ());
// if (commonList != null && commonList.Count > 0) {
// foreach (var common in commonList) {
// if (common.LoopID > usefullBytes [2]) {
// continue;
// }
// string updateFlag = common.CommonLoopID;
// int useIndex = common.LoopID / 8;
// int selfIndex = common.LoopID % 8;
// var binaryString = Convert.ToString (usefullBytes [2 + useIndex], 2).ToCharArray();
// byte ackSceneBrightness = 100;
// if (binaryString [selfIndex] == '0') {
// ackSceneBrightness = 0;
// }
// if (common.Type == DeviceType.LightRGB) {
// break;
// }
// common.LastUpdateTime = DateTime.Now;
// bool hadBeUpdate = true;
// if (common.Type == DeviceType.LightSwitch || common.Type == DeviceType.LightSwitchSocket || common.Type == DeviceType.LightSwitchSocket) {
// if ((common as LightSwitch).CurrentBrightness == ackSceneBrightness)
// hadBeUpdate = false;
// (common as LightSwitch).CurrentBrightness = ackSceneBrightness;
// } else if (common.Type == DeviceType.LightDimming) {
// if ((common as LightDimming).CurrentBrightness == ackSceneBrightness)
// hadBeUpdate = false;
// (common as LightDimming).CurrentBrightness = ackSceneBrightness;
// } else if (common.Type == DeviceType.FanModule) {
// if ((common as FanModule).Switch == ackSceneBrightness)
// hadBeUpdate = false;
// (common as FanModule).Switch = ackSceneBrightness;
// if (ackSceneBrightness != 0)
// (common as FanModule).WindSpeed = ackSceneBrightness;
// } else if (common.Type == DeviceType.LightMixSwitch) {
// if ((common as LightMixSwitch).CurrentBrightness == ackSceneBrightness)
// hadBeUpdate = false;
// (common as LightMixSwitch).CurrentBrightness = ackSceneBrightness;
// } else if (common.Type == DeviceType.LightMixDimming) {
// if ((common as LightMixDimming).CurrentBrightness == ackSceneBrightness)
// hadBeUpdate = false;
// (common as LightMixDimming).CurrentBrightness = ackSceneBrightness;
// } else if (common.Type == DeviceType.LightDALI) {
// if ((common as LightDALI).CurrentBrightness == ackSceneBrightness)
// hadBeUpdate = false;
// (common as LightDALI).CurrentBrightness = ackSceneBrightness;
// }
// if (Application.IsPad) {
// } else {
// UserDeviceToLight.UpdateBrighingCount (updateFlag);
// if (hadBeUpdate) {
// UserRoom.UpdataDeviceStatus (common);
// UserLightPage.UpdateStatus (updateFlag, ackSceneBrightness);
// UserDeviceToLight.UpdateStatus (updateFlag, ackSceneBrightness);
// UserFan.UpdataFanView (updateFlag, ackSceneBrightness);
// UserDeviceToFan.UpdataStatus (updateFlag, ackSceneBrightness);
// UserDeviceToSocket.UpdateStatus (updateFlag, ackSceneBrightness);
// }
// //break;
// }
// }
// }
// }
// break;
// case Command.ReadAnalogValueACK:
// foreach (var room in Room.Lists) {
// foreach (var common in room.DeviceList) {
// if (common.SubnetID != subnetID || common.DeviceID != deviceID || common.LoopID != usefullBytes [1]) {
// continue;
// }
// if (common.Type == DeviceType.LightEnergySwitch) {
// string updateFlag = common.CommonLoopID;
// if (!Application.IsPad) {
// UserDeviceToSocket.UpdataEnergy (updateFlag, usefullBytes [2] * 256 + usefullBytes [3]);
// UserRoom.UpdataEnergy (updateFlag, usefullBytes [2] * 256 + usefullBytes [3]);
// break;
// } else {
// //Pad.UserDeviceToSocket.UpdataEnergy (updateFlag, usefullBytes [2] + usefullBytes [3]);
// break;
// }
// }
// int dddd = usefullBytes [0] & 0x3F;
// // 0xXX:公司内部协议对应的序号
// // common.Type:对应的是编辑软件的序号(没有一一对应,是为了将相近的调整在一起,方便客户使用)
// if (dddd == 0x09 && common.Type == DeviceType.SensorPM25) {
// // PM2.5
// int value = (usefullBytes [2] & 0xFF) * 256 + (usefullBytes [3] & 0xFF);
// (common as SensorPM25).CurrentPM25 = value;
// //} else if (dddd == 0x13 && common.Type == 1) {
// // PM10
// //int value = (usefullBytes [2] & 0xFF) * 256 + (usefullBytes [3] & 0xFF);
// //common.value = value;
// //} else if (dddd == 0x0D && common.Type == DeviceType.SensorCH4) {
// //// 氧气
// //int value = (usefullBytes [2] & 0xFF) * 256 + (usefullBytes [3] & 0xFF);
// //common.value = value;
// } else if (dddd == 0x07 && common.Type == DeviceType.SensorCO2) {
// // CO2
// int value = (usefullBytes [2] & 0xFF) * 256 + (usefullBytes [3] & 0xFF);
// (common as SensorCO2).CurrentCO2 = value;
// //} else if (dddd == 0x10 && common.Type == DeviceType.co) {
// //// CO
// //int value = (usefullBytes [2] & 0xFF) * 256 + (usefullBytes [3] & 0xFF);
// //common.value = value;
// } else if (dddd == 0x05 && common.Type == DeviceType.SensorHumidity) {
// // 湿度
// int value = (usefullBytes [2] & 0xFF) * 256 + (usefullBytes [3] & 0xFF);
// (common as SensorHumidity).CurrentHumidity = value;
// } else if (dddd == 0x01 && common.Type == DeviceType.SensorTemperature) {
// // Temperature
// if (usefullBytes [2] >> 7 == 0) {// 温度
// int value = usefullBytes [3] & 0xFF;
// (common as SensorTemperature).CurrentTemperature = value;
// } else {
// int value = -(usefullBytes [3] & 0xFF);
// (common as SensorTemperature).CurrentTemperature = value;
// }
// } else if (dddd == 0x0C && common.Type == DeviceType.SensorTVOC) {
// // VOC
// int value = (usefullBytes [2] & 0xFF) * 256 + (usefullBytes [3] & 0xFF);
// (common as SensorTVOC).CurrentTVOC = value;
// //} else if (dddd == 0x04 && common.Type == DeviceType.SensorTVOC) {
// // // Air_ppressure 气压
// // int value = (usefullBytes [2] & 0xFF) * 256 + (usefullBytes [3] & 0xFF);
// // common.value = value;
// //} else if (dddd == 0x00 && common.Type == DeviceType.SensorIllumination) {
// // // 亮度
// // int value = (usefullBytes [2] & 0xFF) * 256 + (usefullBytes [3] & 0xFF);
// // (common as SensorIllumination).CurrentIllumination = value;
// //} else if (dddd == 0x02 && common.Type == DeviceType.SensorVoltage) {
// // // 电压
// // int value = (usefullBytes [2] & 0xFF) * 256 + (usefullBytes [3] & 0xFF);
// // (common as SensorVoltage).CurrentVoltage = value;
// //} else if (dddd == 0x03 && common.Type == DeviceType.SensorCurrent) {
// // // 电流
// // int value = (usefullBytes [2] & 0xFF) * 256 + (usefullBytes [3] & 0xFF);
// // (common as SensorCurrent).CurrentCurrent = value;
// //} else if (dddd == 0x04 && common.Type == DeviceType.SensorVoltage) {
// // // 压力
// // int value = (usefullBytes [2] & 0xFF) * 256 + (usefullBytes [3] & 0xFF);
// // (common as SensorVoltage).CurrentVoltage = value;
// //} else if (dddd == 0x06 && common.Type == DeviceType.SensorWindSpeed) {
// // // 风速
// // int value = (usefullBytes [2] & 0xFF) * 256 + (usefullBytes [3] & 0xFF);
// // (common as SensorWindSpeed).CurrentWindSpeed = value;
// //} else if (dddd == 0x0A && common.Type == DeviceType.SensorVoltage) {
// // // 功率
// // int value = (usefullBytes [2] & 0xFF) * 256 + (usefullBytes [3] & 0xFF);
// // (common as SensorVoltage).CurrentVoltage = value;
// //} else if (dddd == 0x0B && common.Type == DeviceType.SensorVoltage) {
// // // 电能
// // int value = (usefullBytes [2] & 0xFF) * 256 + (usefullBytes [3] & 0xFF);
// // (common as SensorVoltage).CurrentVoltage = value;
// //} else if (dddd == 0x0E && common.Type == DeviceType.SensorVoltage) {
// // // 烟雾
// // int value = (usefullBytes [2] & 0xFF) * 256 + (usefullBytes [3] & 0xFF);
// // (common as SensorVoltage).CurrentVoltage = value;
// //} else if (dddd == 0x0F && common.Type == DeviceType.SensorVoltage) {
// // // 甲醛
// // int value = (usefullBytes [2] & 0xFF) * 256 + (usefullBytes [3] & 0xFF);
// // (common as SensorVoltage).CurrentVoltage = value;
// //} else if (dddd == 0x11 && common.Type == DeviceType.SensorVoltage) {
// // // 甲烷
// // int value = (usefullBytes [2] & 0xFF) * 256 + (usefullBytes [3] & 0xFF);
// // (common as SensorVoltage).CurrentVoltage = value;
// //} else if (dddd == 0x12 && common.Type == DeviceType.SensorVoltage) {
// // // 噪音
// // int value = (usefullBytes [2] & 0xFF) * 256 + (usefullBytes [3] & 0xFF);
// // (common as SensorVoltage).CurrentVoltage = value;
// //} else if (dddd == 0x14 && common.Type == DeviceType.SensorVoltage) {
// //// 空气质量
// //int value = (usefullBytes [2] & 0xFF) * 256 + (usefullBytes [3] & 0xFF);
// //(common as SensorVoltage).CurrentVoltage = value;
// }
// }
// }
// break;
// case Command.SetLogicLoopColorACK:
// case Command.ReadLogicLoopColorACK:
// foreach (var room in Room.Lists) {
// foreach (var common in room.DeviceList) {
// if (common.SubnetID != subnetID || common.DeviceID != deviceID || common.LoopID != usefullBytes [0]) {
// continue;
// }
// common.LastUpdateTime = DateTime.Now;
// if (common.Type == DeviceType.LightRGB) {
// (common as LightLogic).CurrentBrightness = usefullBytes [1];
// string updateFlag = common.CommonLoopID + "RGB";
// if (Application.IsPad) {
// UserLightPage.UpdateStatus (updateFlag, usefullBytes [1]);
// UserDeviceToLight.UpdateStatus (updateFlag, usefullBytes [1]);
// } else {
// UserRoom.UpdataDeviceStatus (common);
// UserLightPage.UpdateStatus (updateFlag, usefullBytes [1]);
// UserDeviceToLight.UpdateStatus (updateFlag, usefullBytes [1]);
// }
// }
// }
// }
// break;
// case Command.SetFoolHeatACK:
// case Command.ReadFoolHeatACK:
// case Command.Serverx_FH_CMD_ACK:
// foreach (var room in Room.Lists) {
// var fhCommon = room.DeviceList.Find ((obj) => obj.SubnetID == subnetID && obj.DeviceID == deviceID && obj.LoopID == usefullBytes [0]);
// if (fhCommon != null) {
// (fhCommon as FoolHeat).Serverx_FH_CMD (FoolHeat.CommandType.Null, usefullBytes);
// }
// }
// break;
// case Command.BroadcastDryContactStatus://干接点广播出来的数据接受,不是回复数据
// if (Application.IsPad) { } else {
// UserDryContact.UpdataView (subnetID, deviceID, usefullBytes [0], usefullBytes [2]);
// }
// break;
// #region 门锁
// case Command.ReadDoorLockClockACK:
// //门锁111
// foreach (var room in Room.Lists) {
// foreach (var common in room.DeviceList) {
// if (common.SubnetID != subnetID || common.DeviceID != deviceID || common.LoopID != usefullBytes [0]) {
// continue;
// }
// if (common.Type == DeviceType.DoorLock) {
// common.LastUpdateTime = DateTime.Now;
// var doorLock = common as DoorLock;
// doorLock.DoorLockNum = usefullBytes [1];
// if (Application.IsPad) {
// //Pad.UserDoorLockPage.UpdateStatus (doorLock);
// } else {
// //PasswordList.UpdateStatus (doorLock);
// }
// }
// }
// }
// break;
// //广播门锁状态和报警,
// //门锁111,BroadcastDoorLockStateAndAlarm
// case Command.BroadcastDoorLockStateAndAlarm:
// if (Application.IsPad) { } else {
// UserDryContact.UpdataView (subnetID, deviceID, usefullBytes [0], usefullBytes [2]);
// }
// break;
// #endregion
// case Command.ReadCurtainStutasACK:
// case Command.UpdataCurtainModelStutasACK:
// #region 窗帘
// foreach (var room in Room.Lists) {
// foreach (var common in room.DeviceList) {
// if (common.SubnetID != subnetID || common.DeviceID != deviceID) {
// continue;
// }
// common.LastUpdateTime = DateTime.Now;
// if (common.Type == DeviceType.CurtainModel) {
// if (common.LoopID == usefullBytes [0]) {
// (common as CurtainModel).Status = (CurtainStatus)usefullBytes [1];
// if (Application.IsPad) {
// //Pad.UserCurtainPage.UpdateStatus (common);
// } else {
// UserCurtainPage.UpdateStatus (common);
// }
// }
// } else if (common.Type == DeviceType.CurtainRoller) {
// if (usefullBytes [0] == 17) {
// (common as CurtainRoller).CurtainProress = usefullBytes [1];
// } else {
// (common as CurtainRoller).Status = (CurtainStatus)usefullBytes [1];
// }
// if (Application.IsPad) {
// //Pad.UserCurtainPage.UpdateStatus (common);
// } else {
// UserCurtainPage.UpdateStatus (common);
// }
// } else if (common.Type == DeviceType.CurtainTrietex) {
// if (usefullBytes [0] == 17) {
// (common as CurtainTrietex).CurtainProress = usefullBytes [1];
// } else {
// (common as CurtainTrietex).Status = (CurtainStatus)usefullBytes [1];
// }
// if (Application.IsPad) {
// //Pad.UserCurtainPage.UpdateStatus (common);
// } else {
// UserCurtainPage.UpdateStatus (common);
// }
// }
// }
// }
// break;
// #endregion
// case Command.SonosControlACK: {
// #region Sonos音乐播放器
// var result = Encoding.UTF8.GetString (usefullBytes);
// if (result != null) {
// var jObject = JObject.Parse (result);
// if (jObject == null) {
// return;
// }
// var sid = jObject ["sid"]?.ToString ();
// if (sid == null) {
// return;
// }
// var sidUlong = Convert.ToUInt64 (sid, 16);
// var property = (byte)((sidUlong >> 16) & 0xFF);
// var subnetId = (byte)((sidUlong >> 40) & 0xFF);
// var deviceId = (byte)((sidUlong >> 32) & 0xFF);
// var targetNumber = (uint)((sidUlong >> 0) & 0xFFFF);
// string CommonLoopID = subnetId.ToString () + "_" + deviceId.ToString () + "_" + targetNumber.ToString ();
// foreach (var music in SonosMusic.SonosMusicList) {
// if (music.CommonLoopID == CommonLoopID && music.sidlist.Contains (sid)) {
// var Issuccess = Convert.ToBoolean (jObject ["event"] ["success"]);
// var job = jObject ["event"] ["data"];
// if (Issuccess) {
// if (property == 35) {
// //music.sonosPlayStatus.vol = job ["groupVolume"]?.ToString ();//组音量
// if (music.ServerClientType == -1) {
// //music.sonosPlayStatus.playbackState = job.Value ("playbackState");
// //if (music.sonosPlayStatus.playbackState != 4) {
// music.sonosPlayStatus.vol = job ["playerVolume"]?.ToString ();//音量
// //}
// } else {
// music.sonosPlayStatus.vol = job ["playerVolume"]?.ToString ();//音量
// music.sonosPlayStatus.positionMillis = job.Value ("positionMillis");
// music.sonosPlayStatus.durationMillis = job.Value ("durationMillis");
// music.sonosPlayStatus.playModes = job.Value ("playModes");
// music.sonosPlayStatus.playbackState = job.Value ("playbackState");
// music.sonosPlayStatus.mute = Convert.ToBoolean (job ["muted"]);
// music.sonosPlayStatus.DateTime = DateTime.Now;
// if (music.sonosPlayStatus.playbackState != 4) {
// music.sonosPlayStatus.songName = job ["songName"]?.ToString ();
// music.sonosPlayStatus.artist = job ["artist"]?.ToString ();
// music.sonosPlayStatus.album = job ["album"]?.ToString ();
// music.sonosPlayStatus.imageUrl = job ["imageUrl"]?.ToString ();
// }
// }
// }
// }
// //if(Issuccess){
// // if (property == 27) {
// // //music.sonosPlayStatus.vol = job ["playerVolume"]?.ToString ();
// // }
// // //
// //}else{
// // ////提示:控制失败
// //}
// }
// }
// }
// #endregion
// }
// break;
// case Command.ControlMusicModel1ACK:
// #region 音乐
// foreach (var m in Room.Lists) {
// var device = m.DeviceList.Find ((v) => {
// return v.Type == DeviceType.MusicModel && v.SubnetID == subnetID && v.DeviceID == deviceID;
// });
// if (device == null) {
// continue;
// }
// MusicModel music = device as MusicModel;
// //把接收到的数据转换为字符串
// string backAllString = CommonPage.MyEncodingGB2312.GetString (usefullBytes);
// //把当前字符串以,号分开
// string [] backResult = backAllString.Split (',');
// string commandString = backResult [0];
// if (commandString.StartsWith ("#Z")) {
// if (2 <= backResult.Length) {
// //music.PlayStatus = backResult [1] == "ON" ? MusicModel.Status.Play : MusicModel.Status.Stop;
// }
// if (backResult.Length > 3) {
// //设置音乐的区号,源号,音量值。
// if (backResult [0].StartsWith ("#Z") && backResult [1] == "ON" && backResult [2].StartsWith ("SRC") && backResult [3].StartsWith ("VOL")) {
// music.ZoneID = backResult [0].Replace ("#Z", "");
// music.SourceID = backResult [2].Replace ("SRC", "");
// music.CurVol = backResult [3].Replace ("VOL", "").TrimEnd (new char [] { '\r', '\n' });
// }
// }
// }
// if (commandString.Length > 3) {
// if (commandString.StartsWith ("#S")) {
// //music_SourceID=commandString.Substring (2, 1);
// }
// commandString = commandString.Substring (3, commandString.Length - 3);
// byte [] bytes = null;
// switch (commandString) {
// case "DISPLINE4":
// //当前播放歌曲名
// var len = 0;
// for (var i = 14; i < usefullBytes.Length; i += 2) {
// if (usefullBytes [i] == 0x00 && usefullBytes [i + 1] == 0x03) {
// break;
// }
// len += 2;
// }
// bytes = new byte [len];
// for (var j = 0; j < bytes.Length;) {
// bytes [j + 1] = usefullBytes [14 + j];
// bytes [j] = usefullBytes [14 + j + 1];
// j += 2;
// }
// music.curPlayMusicName = Encoding.Unicode.GetString (bytes);
// break;
// case "DISPLINE1":
// //列表号、列表总数,返回格式: L:1/2
// bytes = new byte [usefullBytes.Length - 4 - 14];
// for (int i = 14, j = 0; j < bytes.Length;) {
// bytes [j + 1] = usefullBytes [i++];
// bytes [j] = usefullBytes [i++];
// j += 2;
// }
// string curPlayListNumberAndCount = Encoding.Unicode.GetString (bytes);
// // mm1ACK.musicListNumber = "0";
// int number = 0;
// if (curPlayListNumberAndCount.StartsWith ("L:")) {
// curPlayListNumberAndCount = curPlayListNumberAndCount.Replace ("L:", "");
// if (curPlayListNumberAndCount.Contains ("/")) {
// number = int.Parse (curPlayListNumberAndCount.Split ('/') [0]);
// music.curListNumber = number < 10 ? "00" + number : (number < 100 ? "0" + number : number.ToString ());
// }
// }
// break;
// case "DISPLINE2":
// //当前列表名,返回格式: SOME.PLS
// bytes = new byte [usefullBytes.Length - 4 - 14];
// for (int i = 14, j = 0; j < bytes.Length;) {
// bytes [j + 1] = usefullBytes [i++];
// bytes [j] = usefullBytes [i++];
// j += 2;
// }
// string curPlayMusicListName = Encoding.Unicode.GetString (bytes);
// string curMusicListName = curPlayMusicListName;
// if (curPlayMusicListName.Contains (".PLS")) {
// curMusicListName = curPlayMusicListName.Split ('.') [0];
// }
// music.curMusicListName = curMusicListName;
// //MusicStatusFunction.updateMusicStatus_PlayListName (subnetID, deviceID, music_SourceID, curMusicListName, iPEndPoint.Address.ToString (), iPEndPoint.Port);
// break;
// case "DISPLINE3":
// //歌曲号、歌曲总数,返回格式: S:10/23
// bytes = new byte [usefullBytes.Length - 4 - 14];
// for (int i = 14, j = 0; j < bytes.Length;) {
// bytes [j + 1] = usefullBytes [i++];
// bytes [j] = usefullBytes [i++];
// j += 2;
// }
// string curPlayMusicNumberAndCount = System.Text.Encoding.Unicode.GetString (bytes);
// int musicFileNumber = 0;
// if (curPlayMusicNumberAndCount.StartsWith ("S:")) {
// curPlayMusicNumberAndCount = curPlayMusicNumberAndCount.Replace ("S:", "");
// if (curPlayMusicNumberAndCount.Contains ("/")) {
// musicFileNumber = int.Parse (curPlayMusicNumberAndCount.Split ('/') [0]);
// }
// }
// music.curSongNumber = musicFileNumber < 10 ? "00" + musicFileNumber : (musicFileNumber < 100 ? "0" + musicFileNumber : musicFileNumber.ToString ());
// //MusicStatusFunction.updateMusicStatus_PlayMusicFileNumber (subnetID, deviceID, music_SourceID, musicFileNumber, iPEndPoint.Address.ToString (), iPEndPoint.Port);
// break;
// case "DISPINFO":
// //当前播放歌曲的状态,返回格式: #SsDISPINFO,DUR1945,POS0,STATUS2
// //DUR后数值:为歌曲播放总时间 (秒×10,实际时间的10倍)
// //POS后数值:为歌曲已播放时间 (秒×10,实际时间的10倍)
// //STATUS后数值:为1表示stop,为2表示play,为3表示pause
// if (backResult [1].StartsWith ("DUR") && backResult [2].StartsWith ("POS") && backResult [3].StartsWith ("STATUS")) {
// music.SoundGenerator = backResult [0] [2].ToString ();
// music.musicTime = backResult [1].Replace ("DUR", "");
// music.musicPalyTime = backResult [2].Replace ("POS", "");
// music.musicCurPalyStatus = backResult [3] [6].ToString ();//.Replace ("STATUS", "")[0];
// music.PlayStatus = music.musicCurPalyStatus == "2" ? MusicModel.Status.Play : MusicModel.Status.Stop;
// music.LastDateTime = DateTime.Now;
// }
// // UserMusicModelRoom.UpdateControls(mm1ACK);
// //UserMusicModel.UpdateRoomMusicStatus(mm1ACK);
// break;
// //播放模式
// case "DISPMODE":
// if (7 <= backResult [1].Length) {
// music.playMode = int.Parse (backResult [1].Substring (6, 1));
// System.MainPage.WriteLog ("DISPMODE=====" + music.playMode);
// }
// break;
// }
// }
// }
// break;
// #endregion
// #region 空调
// case Command.ReadPanelTempTypeACK:
// foreach (var room in Room.Lists) {
// foreach (var common in room.DeviceList) {
// if (common.SubnetID != subnetID || common.DeviceID != deviceID || common.LoopID != usefullBytes [0]) {
// continue;
// }
// common.LastUpdateTime = DateTime.Now;
// if (common.Type == DeviceType.ACPanel ) {
// var ac = common as ACPanel;
// ac.TemperatureMode = usefullBytes [0];
// }
// }
// }
// break;
// case Command.ReadACModeACK:
// case Command.SetACModeACK:
// foreach (var room in Room.Lists) {
// foreach (var common in room.DeviceList) {
// if (common.SubnetID != subnetID || common.DeviceID != deviceID || common.LoopID != usefullBytes [0]) {
// continue;
// }
// common.LastUpdateTime = DateTime.Now;
// if (common.Type == DeviceType.HVAC || common.Type == DeviceType.ACPanel || common.Type == DeviceType.ACInfrared
// || common.Type == DeviceType.LongXiAC) {
// if (common.Type == DeviceType.LongXiAC) {
// var ac = common as LongXiAC;
// ac.TemperatureMode = usefullBytes [1];
// ac.IndoorTemperature = usefullBytes [2];
// ac.CoolTemperature = usefullBytes [3];
// ac.HeatTemperature = usefullBytes [4];
// ac.AutoTemperature = usefullBytes [5];
// ac.ChuShiTemperature = usefullBytes [6];
// ac.RealModeAndFanSpeed = usefullBytes [7];
// ac.Power = usefullBytes [8];
// ac.SetMode = usefullBytes [9];
// ac.SetFanSpeed = usefullBytes [10];
// ac.Wave = usefullBytes [12];
// if (usefullBytes.Length == 23) {//首城珑玺定制的新风空调固件是不一样的
// ac.ElectricHeating = usefullBytes [15];
// ac.Antifreeze = usefullBytes [16];
// ac.OutTemp = usefullBytes [17] > 50 ? (byte)(0 - (usefullBytes [17] - 50)) : usefullBytes [17];
// ac.Humidity = usefullBytes [18];
// ac.TVOC = usefullBytes [19] * 256 + usefullBytes [20];
// ac.PM25 = usefullBytes [21] * 256 + usefullBytes [22];
// }
// if (Application.IsPad) {
// //Pad.UserACPage.UpdateStatus (ac);
// } else {
// UserLongXiACPage.UpdateStatus (ac);
// UserDeviceToAC.UpdateStatus (ac);
// UserRoom.UpdataDeviceStatus (ac);
// }
// } else {
// var ac = common as AC;
// ac.TemperatureMode = usefullBytes [1];
// ac.IndoorTemperature = usefullBytes [2];
// ac.CoolTemperature = usefullBytes [3];
// ac.HeatTemperature = usefullBytes [4];
// ac.AutoTemperature = usefullBytes [5];
// ac.ChuShiTemperature = usefullBytes [6];
// ac.RealModeAndFanSpeed = usefullBytes [7];
// ac.Power = usefullBytes [8];
// ac.SetMode = usefullBytes [9];
// ac.SetFanSpeed = usefullBytes [10];
// //if (usefullBytes [11] < 16 || usefullBytes [11] == 0) {
// // ac.SetTemperature = (byte)16;
// //} else {
// // ac.SetTemperature = usefullBytes [11];
// //}
// ac.ShaoFanMode = usefullBytes [12];
// //IO.F
// if (Application.IsPad) {
// //Pad.UserACPage.UpdateStatus (ac);
// } else {
// UserACPage.UpdateStatus (ac);
// UserDeviceToAC.UpdateStatus (ac);
// UserRoom.UpdataDeviceStatus (ac);
// }
// }
// }
// }
// }
// break;
// case Command.ReadPanleTempACK:
// case Command.PanleBroadcastTemp:
// foreach (var room in Room.Lists) {
// foreach (var common in room.DeviceList) {
// if (common.CommonLoopID == subnetID + "_" + deviceID + "_" + usefullBytes [0]) {
// if (common.Type == DeviceType.ACPanel) {
// var tempAC = common as ACPanel;
// tempAC.IndoorTemperature = usefullBytes [1];
// UserACPage.UpdateIndoorTemp (tempAC.Type + "_" + tempAC.SubnetID + "_" + tempAC.DeviceID, usefullBytes [1]);
// } else if (common.Type == DeviceType.FoolHeatPanel) {
// var tempFH22 = common as FoolHeatPanel;
// tempFH22.IndoorTemperature = usefullBytes [1];
// UserFHPage.UpdateIndoorTemp (tempFH22.Type + "_" + tempFH22.SubnetID + "_" + tempFH22.DeviceID, usefullBytes [1]);
// }
// }
// }
// }
// break;
// case Command.InstructionPanelKeyACK:
// case Command.ReadInstructionPanelKeyACK:
// byte reACPanel = 0;
// if (usefullBytes.Length == 2) {
// reACPanel = 1;
// } else if (usefullBytes.Length == 3) {
// reACPanel = usefullBytes [2];
// } else {
// break;
// }
// foreach (var room in Room.Lists) {
// foreach (var common in room.DeviceList) {
// if (common.SubnetID != subnetID || common.DeviceID != deviceID || common.LoopID != reACPanel) {
// continue;
// }
// common.LastUpdateTime = DateTime.Now;
// if (common.Type == DeviceType.ACPanel) {
// var ac = common as ACPanel;
// switch (usefullBytes [0]) {
// case 3://
// ac.Power = usefullBytes [1];
// UserACPage.UpdatePower (ac.CommonLoopID, usefullBytes [1]);
// UserDeviceToAC.UpdatePower (ac.CommonLoopID, usefullBytes [1]);
// UserRoom.Update_ACPanel_Power (ac.Type.ToString () + "_" + ac.CommonLoopID, usefullBytes [1]);
// break;
// case 4:
// ac.CoolTemperature = usefullBytes [1];
// if (ac.SetMode == 0) {
// ac.SetTemperature = usefullBytes [1];
// UserACPage.UpdateWorkingTemp (ac.CommonLoopID, usefullBytes [1]);
// UserDeviceToAC.UpdateWorkingTemp (ac.CommonLoopID, usefullBytes [1]);
// UserRoom.Update_ACPanel_WorkingTemp (ac.Type.ToString () + "_" + ac.CommonLoopID, usefullBytes [1], ac.TemperatureMode);
// }
// break;
// case 5:
// ac.SetFanSpeed = usefullBytes [1];
// UserACPage.UpdateSetFanSpeed (ac.CommonLoopID, usefullBytes [1]);
// UserDeviceToAC.UpdateFanSpeed (ac.CommonLoopID, usefullBytes [1]);
// UserRoom.Update_ACPanel_FanIcon (ac.Type.ToString () + "_" + ac.CommonLoopID, usefullBytes [1]);
// break;
// case 6:
// ac.SetMode = usefullBytes [1];
// UserACPage.UpdateSetMode (ac.CommonLoopID, usefullBytes [1]);
// UserDeviceToAC.UpdateSetMode (ac.CommonLoopID, usefullBytes [1]);
// UserRoom.Update_ACPanel_ModeIcon (ac.Type.ToString () + "_" + ac.CommonLoopID, usefullBytes [1]);
// break;
// case 7:
// ac.HeatTemperature = usefullBytes [1];
// if (ac.SetMode == 1) {
// ac.SetTemperature = usefullBytes [1];
// UserACPage.UpdateWorkingTemp (ac.CommonLoopID, usefullBytes [1]);
// UserDeviceToAC.UpdateWorkingTemp (ac.CommonLoopID, usefullBytes [1]);
// UserRoom.Update_ACPanel_WorkingTemp (ac.Type.ToString () + "_" + ac.CommonLoopID, usefullBytes [1], ac.TemperatureMode);
// }
// break;
// case 8:
// ac.AutoTemperature = usefullBytes [1];
// if (ac.SetMode == 3) {
// ac.SetTemperature = usefullBytes [1];
// UserACPage.UpdateWorkingTemp (ac.CommonLoopID, usefullBytes [1]);
// UserDeviceToAC.UpdateWorkingTemp (ac.CommonLoopID, usefullBytes [1]);
// UserRoom.Update_ACPanel_WorkingTemp (ac.Type.ToString () + "_" + ac.CommonLoopID, usefullBytes [1], ac.TemperatureMode);
// }
// break;
// case 19:
// ac.ChuShiTemperature = usefullBytes [1];
// if (ac.SetMode == 4) {
// ac.SetTemperature = usefullBytes [1];
// UserACPage.UpdateWorkingTemp (ac.CommonLoopID, usefullBytes [1]);
// UserDeviceToAC.UpdateWorkingTemp (ac.CommonLoopID, usefullBytes [1]);
// UserRoom.Update_ACPanel_WorkingTemp (ac.Type.ToString () + "_" + ac.CommonLoopID, usefullBytes [1], ac.TemperatureMode);
// }
// break;
// }
// if (Application.IsPad) {
// //Pad.UserACPage.UpdateStatus (ac);
// } else {
// //UserACPage.UpdateStatus (ac);
// //UserDeviceToAC.UpdateStatus (ac);
// //UserRoom.UpdataDeviceStatus (ac);
// }
// } else if (common.Type == DeviceType.FoolHeatPanel) {
// var fh = common as FoolHeatPanel;
// switch (usefullBytes [0]) {
// case 20://
// fh.Status = usefullBytes [1];
// UserDeviceToFH.UpdatePower (fh.CommonLoopID, usefullBytes [1]);
// UserFHPage.UpdatePower (fh.CommonLoopID, usefullBytes [1]);
// UserRoom.Update_FoolHeatPanel_Power (fh.Type.ToString () + "_" + fh.CommonLoopID, usefullBytes [1]);
// break;
// case 21:
// fh.TemperatureType = usefullBytes [1];
// UserFHPage.UpdateWorkingMode (fh.CommonLoopID, usefullBytes [1]);
// if (usefullBytes [1] == 5) {
// if (fh.Timer == 0)//时间模式的时间段标志 (0:白天,1:夜晚) (1byte) //20110112加时间段标志
// Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 26, 2, fh.LoopID }, SendCount.Zero);
// else
// Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { 27, 3, fh.LoopID }, SendCount.Zero);
// } else
// Control.ControlBytesSend (Command.ReadInstructionPanelKey, fh.SubnetID, fh.DeviceID, new byte [] { (byte)(usefullBytes [1] + 24), fh.LoopID }, SendCount.Zero);
// break;
// case 25:
// fh.NormalTemperature = usefullBytes [1];
// if (fh.TemperatureType == 1) {
// fh.WorkingTemperature = usefullBytes [1];
// UserDeviceToFH.UpdateWorkingTemp (fh.CommonLoopID, usefullBytes [1]);
// UserFHPage.UpdateWorkingTemp (fh.CommonLoopID, usefullBytes [1]);
// UserRoom.Update_FoolHeatPanel_WorkingTemp (fh.Type.ToString () + "_" + fh.CommonLoopID, usefullBytes [1]);
// }
// break;
// case 26:
// fh.DayTemperature = usefullBytes [1];
// if (fh.TemperatureType == 2) {
// fh.WorkingTemperature = usefullBytes [1];
// UserDeviceToFH.UpdateWorkingTemp (fh.CommonLoopID, usefullBytes [1]);
// UserFHPage.UpdateWorkingTemp (fh.CommonLoopID, usefullBytes [1]);
// UserRoom.Update_FoolHeatPanel_WorkingTemp (fh.Type.ToString () + "_" + fh.CommonLoopID, usefullBytes [1]);
// }
// break;
// case 27:
// fh.NightTemperature = usefullBytes [1];
// if (fh.TemperatureType == 3) {
// fh.WorkingTemperature = usefullBytes [1];
// UserDeviceToFH.UpdateWorkingTemp (fh.CommonLoopID, usefullBytes [1]);
// UserFHPage.UpdateWorkingTemp (fh.CommonLoopID, usefullBytes [1]);
// UserRoom.Update_FoolHeatPanel_WorkingTemp (fh.Type.ToString () + "_" + fh.CommonLoopID, usefullBytes [1]);
// }
// break;
// case 28:
// fh.AwayTemperature = usefullBytes [1];
// if (fh.TemperatureType == 4) {
// fh.WorkingTemperature = usefullBytes [1];
// UserDeviceToFH.UpdateWorkingTemp (fh.CommonLoopID, usefullBytes [1]);
// UserFHPage.UpdateWorkingTemp (fh.CommonLoopID, usefullBytes [1]);
// UserRoom.Update_FoolHeatPanel_WorkingTemp (fh.Type + "_" + fh.CommonLoopID, usefullBytes [1]);
// }
// break;
// }
// if (Application.IsPad) {
// //SimpleControl.Pad.UserFHPage.UpdateStatus (fh);
// } else {
// //UserDeviceToFH.UpdateStatus (fh);
// //UserFHPage.UpdateStatus (fh);
// //UserRoom.UpdataDeviceStatus (fh);
// }
// }
// }
// }
// break;
// case Command.Read_Air_Condition_Set_ack:
// byte acpanelLoopId = 0;
// if (usefullBytes.Length == 10) {
// acpanelLoopId = 1;
// } else if (usefullBytes.Length == 11) {
// acpanelLoopId = usefullBytes [10];
// }
// foreach (var room in Room.Lists) {
// var common = room.DeviceList.Find ((obj) => obj.SubnetID == subnetID && obj.DeviceID == deviceID && obj.LoopID == usefullBytes [1] && obj.Type == DeviceType.ACPanel);
// if (common == null)
// continue;
// common.LastUpdateTime = DateTime.Now;
// var ac = common as ACPanel;
// ac.Power = usefullBytes [0];
// ac.CoolTemperature = usefullBytes [1];
// ac.SetMode = (byte)(usefullBytes [2] >> 4);//模式和风速
// ac.SetFanSpeed = (byte)(usefullBytes [2] & 0x0F);
// //空调锁
// ac.SetTemperature = usefullBytes [4];//当前温度
// ac.HeatTemperature = usefullBytes [5];//制热温度
// //空调实际运行模式和风速
// ac.AutoTemperature = usefullBytes [7];//自动温度
// ac.ChuShiTemperature = usefullBytes [8];//抽湿温度
// ac.ShaoFanMode = usefullBytes [9];//空调是否扫风(低四位)
// if (Application.IsPad) {
// } else {
// UserACPage.UpdateStatus (ac);
// UserDeviceToAC.UpdateStatus (ac);
// UserRoom.UpdataDeviceStatus (ac);
// }
// }
// break;
// case Command.Set_Air_State_New_ack:
// if (usefullBytes.Length == 15) {
// /// [0]//MODIFY_SUCCESS 1byte
// /// [1]//空调页号(0-8) 1byte
// /// [2]//空调开关(1开0关) 1byte
// /// [3]//制冷控制温度(摄氏0-30,华氏32-86) 1byte
// /// [4]//制热控制温度(摄氏0-30,华氏32-86) 1byte
// /// [5]//自动控制温度(摄氏0-30,华氏32-86) 1byte
// /// [6]//除湿控制温度(摄氏0-30,华氏32-86) 1byte
// /// [7]//设置模式(0制冷,1制热,2通风,3自动,4除湿) 1byte
// /// [8]//设置风速(0自动,1高风,2中风,3低风) 1byte //注意:当模式为除湿或模式为通风及风速为自动时,风速视为小风为准
// /// [9]//设置扫风(0不扫风,1扫风) 1byte
// /// [10]//温度模式(摄氏Celsius:0,华氏Fahrenheit:1) 1byte
// /// [11]//模式实际工作状态(0制冷,1制热,2通风,3自动,4除湿) 1byte
// /// [12]//风速实际工作状态(0关闭,1高风,2中风,3低风) 1byte
// /// [13]//扫风实际工作状态(0不扫风,1扫风) 1byte
// /// [14]//环境温度(摄氏0-40,华氏32-99) 1byte
// foreach (var room in Room.Lists) {
// //foreach (var common in room.DeviceList) {
// var common = room.DeviceList.Find ((obj) => obj.SubnetID == subnetID && obj.DeviceID == deviceID && obj.LoopID == usefullBytes [1] && obj.Type == DeviceType.ACPanel);
// if (common == null)
// continue;
// //if (common.SubnetID != subnetID || common.DeviceID != deviceID || common.LoopID != usefullBytes[1]) {
// // continue;
// //}
// common.LastUpdateTime = DateTime.Now;
// var ac = common as ACPanel;
// ac.Power = usefullBytes [2];
// ac.CoolTemperature = usefullBytes [3];
// ac.SetMode = usefullBytes [7];//模式和风速
// ac.SetFanSpeed = (byte)(usefullBytes [2] & 0x0F);
// //空调锁
// ac.SetTemperature = usefullBytes [4];//当前温度
// ac.HeatTemperature = usefullBytes [4];//制热温度
// //空调实际运行模式和风速
// ac.AutoTemperature = usefullBytes [5];//自动温度
// ac.ChuShiTemperature = usefullBytes [6];//抽湿温度
// ac.ShaoFanMode = usefullBytes [9];//空调是否扫风(低四位)
// ac.IndoorTemperature = usefullBytes [14];
// if (Application.IsPad) {
// } else {
// UserACPage.UpdateStatus (ac);
// UserDeviceToAC.UpdateStatus (ac);
// UserRoom.UpdataDeviceStatus (ac);
// }
// //}
// }
// }
// break;
// #endregion
// #region 地热
// case Command.Read_Floor_Heat_State_ack:
// foreach (var room in Room.Lists) {
// byte fhLoopId = 1;
// if (usefullBytes.Length == 11) {
// fhLoopId = usefullBytes [10];
// }
// var common = room.DeviceList.Find ((obj) => obj.SubnetID == subnetID && obj.DeviceID == deviceID && obj.LoopID == fhLoopId && obj.Type == DeviceType.FoolHeatPanel);
// if (common == null)
// continue;
// /// 1温度模式(摄氏Celsius:0,华氏Fahrenheit:1) (1byte)
// /// 2温度源温度(最高位0:正,1:负.后7bit为值) (1byte)
// /// 3地热地冷开关::0关、1开 (1byte)
// /// 4工作温度模式:1:普通,2:白天,3:夜晚,4:离开,5:时间 (1-5) (1byte)
// /// 5普通温度 (摄氏0-99,华氏32-210) (1byte)
// /// 6白天温度 (摄氏0-99,华氏32-210) (1byte)
// /// 7夜晚温度 (摄氏0-99,华氏32-210) (1byte)
// /// 8离开温度 (摄氏0-99,华氏32-210) (1byte)
// /// 9时间模式的时间段标志 (0:白天,1:夜晚) (1byte) //20110112加时间段标志
// /// 10模式:0地热模式、1地冷模式、2自动 (1byte) //20120802加//20140805加自动
// /// 11地热页号0-8 (1byte)//彩屏加入20150714
// var th = common as FoolHeatPanel;
// th.IndoorTemperature = usefullBytes [1] > 128 ? (byte)(0 - (usefullBytes [1] - 128)) : usefullBytes [1];
// th.Status = usefullBytes [2];
// th.TemperatureType = usefullBytes [3];
// th.NormalTemperature = usefullBytes [4];
// th.DayTemperature = usefullBytes [5];
// th.NightTemperature = usefullBytes [6];
// th.AwayTemperature = usefullBytes [7];
// switch (usefullBytes [3]) {
// case 1://普通
// th.WorkingTemperature = th.NormalTemperature;
// break;
// case 2://白天
// th.WorkingTemperature = th.DayTemperature;
// break;
// case 3://夜晚
// th.WorkingTemperature = th.NightTemperature;
// break;
// case 4://离开
// th.WorkingTemperature = th.AwayTemperature;
// break;
// case 5://时间模式
// th.Timer = usefullBytes [9];
// if (usefullBytes [9] == 1)//时间模式的时间段标志 (0:白天,1:夜晚) (1byte) //20110112加时间段标志
// th.WorkingTemperature = th.DayTemperature;
// else
// th.WorkingTemperature = th.NightTemperature;
// break;
// }
// UserDeviceToFH.UpdateStatus (th);
// UserFHPage.UpdateStatus (th,fhLoopId);
// UserRoom.UpdataDeviceStatus (th);
// }
// break;
// case Command.Set_Floor_Heat_State_ack:
// foreach (var room in Room.Lists) {
// byte fhLoopId = 1;
// if (usefullBytes.Length == 12) {
// fhLoopId = usefullBytes [11];
// }
// var common = room.DeviceList.Find ((obj) => obj.SubnetID == subnetID && obj.DeviceID == deviceID && obj.LoopID == fhLoopId && obj.Type == DeviceType.FoolHeatPanel);
// if (common == null)
// continue;
// /// 1 MODIFY_SUCCESS 1 byte
// /// 2温度模式(摄氏Celsius:0,华氏Fahrenheit:1) (1byte)
// /// 3地热地冷开关::0关、1开 (1byte)
// /// 4工作温度模式:1:普通,2:白天,3:夜晚,4:离开,5:时间 (1-5) (1byte)
// /// 5普通温度 (摄氏0-99,华氏32-210) (1byte)
// /// 6白天温度 (摄氏0-99,华氏32-210) (1byte)
// /// 7夜晚温度 (摄氏0-99,华氏32-210) (1byte)
// /// 8离开温度 (摄氏0-99,华氏32-210) (1byte)
// /// 9时间模式的时间段标志 (0:白天,1:夜晚) (1byte) //20120802加
// /// 10工作模式:0地热、1地冷、2自动 (1byte) //20120802加//20140805加自动
// var th = common as FoolHeatPanel;
// th.Status = usefullBytes [2];
// th.TemperatureType = usefullBytes [3];
// th.NormalTemperature = usefullBytes [4];
// th.DayTemperature = usefullBytes [5];
// th.NightTemperature = usefullBytes [6];
// th.AwayTemperature = usefullBytes [7];
// switch (usefullBytes [3]) {
// case 1://普通
// th.WorkingTemperature = th.NormalTemperature;
// break;
// case 2://白天
// th.WorkingTemperature = th.DayTemperature;
// break;
// case 3://夜晚
// th.WorkingTemperature = th.NightTemperature;
// break;
// case 4://离开
// th.WorkingTemperature = th.AwayTemperature;
// break;
// case 5://时间模式
// th.Timer = usefullBytes [9];
// if (usefullBytes [9] == 1)//时间模式的时间段标志 (0:白天,1:夜晚) (1byte) //20110112加时间段标志
// th.WorkingTemperature = th.DayTemperature;
// else
// th.WorkingTemperature = th.NightTemperature;
// break;
// }
// UserDeviceToFH.UpdateStatus (th);
// UserFHPage.UpdateStatus (th,fhLoopId);
// UserRoom.UpdataDeviceStatus (th);
// }
// break;
// #endregion
// //读取网关设备回复
// case Command.ReadGatewayACK:
// if (!LocalPhoneFindDevice) {//r如果不是本机在查找设备
// break;
// }
// if (usefullBytes [0] != RandomHigh | usefullBytes [1] != RandomLow) {
// return;
// }
// if (GateWayList.Find ((l) => { return l.SubnetID == subnetID && l.DeviceID == deviceID; }) != null) {
// return;
// }
// DeviceType deviceType = (DeviceType)(usefullBytes [2] * 256 + usefullBytes [3]);
// bool notHasRemake = false;
// for (int ki = 0; ki < 20; ki++) {
// if (usefullBytes [13 + ki] != 255) {
// break;
// } else {
// notHasRemake = true;
// }
// }
// if (notHasRemake) {
// byte [] ddd = CommonPage.MyEncodingGB2312.GetBytes ("Gateway " + subnetID.ToString ());
// //byte [] newddd = new byte [20];
// //Array.Copy (ddd, 0, newddd, 0, 20 < ddd.Length ? 20 : ddd.Length);
// Array.Copy (ddd, 0, usefullBytes, 13, 20 < ddd.Length ? 20 : ddd.Length);
// }
// switch (deviceType) {
// case DeviceType.SuperWireless:
// //string macstring = byteToHex16 (usefullBytes [5]) + byteToHex16 (usefullBytes [6]) + byteToHex16 (usefullBytes [7]) + byteToHex16 (usefullBytes [8]) + byteToHex16 (usefullBytes [9]) + byteToHex16 (usefullBytes [10]) + byteToHex16 (usefullBytes [11]) + byteToHex16 (usefullBytes [12]);
// //if (!UserConfig.Instance.GatewayMACList.Contains (macstring) && MainPage.LoginUser.AccountString != "464027401@qq.com") {
// // HasNotInListMAC = true;
// // break;
// //}
// #region
// SuperWireless superWireless = new SuperWireless ();
// string superWirelessPath = "Equipment_" + typeof (SuperWireless).Name + "_" + subnetID + "_" + deviceID;
// var superWirelessbytes = IO.FileUtils.ReadFile (superWirelessPath);
// if (superWirelessbytes.Length > 1) {
// superWireless = Newtonsoft.Json.JsonConvert.DeserializeObject (MyEncodingUTF8.GetString (superWirelessbytes));
// }
// superWireless.SubnetID = subnetID;
// superWireless.DeviceID = deviceID;
// superWireless.MAC = byteToHex16 (usefullBytes [5]) + "." + byteToHex16 (usefullBytes [6]) + "." + byteToHex16 (usefullBytes [7]) + "." + byteToHex16 (usefullBytes [8]) + "." + byteToHex16 (usefullBytes [9]) + "." + byteToHex16 (usefullBytes [10]) + "." + byteToHex16 (usefullBytes [11]) + "." + byteToHex16 (usefullBytes [12]);
// superWireless.Name = MyEncodingGB2312.GetString (usefullBytes, 13, 20).Trim ('\0');//=============
// superWireless.IPAddress = usefullBytes [33] + "." + usefullBytes [34] + "." + usefullBytes [35] + "." + usefullBytes [36];
// superWireless.RouteIPAddress = usefullBytes [37] + "." + usefullBytes [38] + "." + usefullBytes [39] + "." + usefullBytes [40];
// superWireless.IPMAC = (char)usefullBytes [41] + "." + (char)usefullBytes [42] + "." + (char)usefullBytes [43] + "." + usefullBytes [44] + "." + usefullBytes [45] + "." + usefullBytes [46];
// superWireless.SubnetMask = usefullBytes [47] + "." + usefullBytes [48] + "." + usefullBytes [49] + "." + usefullBytes [50];
// superWireless.DHCP = usefullBytes [51] == 0 ? false : true;
// if (usefullBytes.Length == 80) {
// superWireless.EncryptionFlag = usefullBytes [53];
// superWireless.Password = MyEncodingGB2312.GetString (usefullBytes, 54, 8).Trim ('\0');
// superWireless.WirelessBand = usefullBytes [62];
// superWireless.WirelessChannel = usefullBytes [63];
// superWireless.WirelessPassword = MyEncodingGB2312.GetString (usefullBytes, 64, 16).Trim ('\0');
// }
// GateWayList.Add (superWireless);
// //IO.FileUtils.SaveEquipmentMessage (superWireless);
// //System.Threading.Tasks.Task.Run (() => {
// // if (string.IsNullOrEmpty (UserConfig.Current.RemoteModeFile)) {
// // var gatewayBytes = Control.ControlBytesSendHasReturn (Command.ReadGateWayModelInfo, superWireless.SubnetID, superWireless.DeviceID, new byte [] { });
// // if (gatewayBytes!=null&&gatewayBytes [0] == 2) {
// // UserConfig.Current.RemoteModeFile = "Equipment_" + superWireless.Type.ToString () + "_" + superWireless.SubnetID.ToString () + "_" + superWireless.DeviceID.ToString ();
// // UserConfig.Current.SaveUserConfig ();
// // }
// // }
// //});
// #endregion
// break;
// case DeviceType.OnePortWirelessFR:
// #region
// OnePortWirelessFR onePortWirelessFR = new OnePortWirelessFR ();
// string wirelessPath = "Equipment_" + typeof (OnePortWirelessFR).Name + "_" + subnetID + "_" + deviceID;
// var bytes = IO.FileUtils.ReadFile (wirelessPath);
// if (bytes.Length > 1) {
// onePortWirelessFR = Newtonsoft.Json.JsonConvert.DeserializeObject (MyEncodingUTF8.GetString (bytes));
// }
// onePortWirelessFR.SubnetID = subnetID;
// onePortWirelessFR.DeviceID = deviceID;
// onePortWirelessFR.MAC = byteToHex16 (usefullBytes [5]) + "." + byteToHex16 (usefullBytes [6]) + "." + byteToHex16 (usefullBytes [7]) + "." + byteToHex16 (usefullBytes [8]) + "." + byteToHex16 (usefullBytes [9]) + "." + byteToHex16 (usefullBytes [10]) + "." + byteToHex16 (usefullBytes [11]) + "." + byteToHex16 (usefullBytes [12]);
// onePortWirelessFR.Name = MyEncodingGB2312.GetString (usefullBytes, 13, 20).Trim ('\0');//=============
// onePortWirelessFR.IPAddress = usefullBytes [33] + "." + usefullBytes [34] + "." + usefullBytes [35] + "." + usefullBytes [36];
// onePortWirelessFR.RouteIPAddress = usefullBytes [37] + "." + usefullBytes [38] + "." + usefullBytes [39] + "." + usefullBytes [40];
// onePortWirelessFR.IPMAC = (char)usefullBytes [41] + "." + (char)usefullBytes [42] + "." + (char)usefullBytes [43] + "." + usefullBytes [44] + "." + usefullBytes [45] + "." + usefullBytes [46];
// onePortWirelessFR.SubnetMask = usefullBytes [47] + "." + usefullBytes [48] + "." + usefullBytes [49] + "." + usefullBytes [50];
// onePortWirelessFR.DHCP = usefullBytes [51] == 0 ? false : true;
// if (usefullBytes.Length == 80) {
// onePortWirelessFR.EncryptionFlag = usefullBytes [53];
// onePortWirelessFR.Password = MyEncodingGB2312.GetString (usefullBytes, 54, 8).Trim ('\0');
// onePortWirelessFR.WirelessBand = usefullBytes [62];
// onePortWirelessFR.WirelessChannel = usefullBytes [63];
// onePortWirelessFR.WirelessPassword = MyEncodingGB2312.GetString (usefullBytes, 64, 16).Trim ('\0');
// }
// GateWayList.Add (onePortWirelessFR);
// if (onePortWirelessFR.Name == "") {
// onePortWirelessFR.Name = onePortWirelessFR.CommonLoopID.ToString ();
// }
// //IO.FileUtils.SaveEquipmentMessage (onePortWirelessFR);
// //System.Threading.Tasks.Task.Run (() => {
// // if (string.IsNullOrEmpty (UserConfig.Current.RemoteModeFile)) {
// // var gatewayBytes = Control.ControlBytesSendHasReturn (Command.ReadGateWayModelInfo, onePortWirelessFR.SubnetID, onePortWirelessFR.DeviceID, new byte [] { });
// // if (gatewayBytes!=null&&gatewayBytes [0] == 2) {
// // UserConfig.Current.RemoteModeFile = "Equipment_" + onePortWirelessFR.Type.ToString () + "_" + onePortWirelessFR.SubnetID.ToString () + "_" + onePortWirelessFR.DeviceID.ToString ();
// // UserConfig.Current.SaveUserConfig ();
// // }
// // }
// //});
// #endregion
// break;
// case DeviceType.OnePortBus:
// #region
// OnePortBus onePortBus = new OnePortBus ();
// string onePath = "Equipment_" + typeof (OnePortBus).Name + "_" + subnetID + "_" + deviceID;
// var bytesOne = IO.FileUtils.ReadFile (onePath);
// if (bytesOne.Length > 1) {
// onePortBus = Newtonsoft.Json.JsonConvert.DeserializeObject (MyEncodingUTF8.GetString (bytesOne));
// }
// onePortBus.SubnetID = subnetID;
// onePortBus.DeviceID = deviceID;
// //onePortBus.ChNumberCount = usefullBytes [4];
// onePortBus.MAC = byteToHex16 (usefullBytes [5]) + "." + byteToHex16 (usefullBytes [6]) + "." + byteToHex16 (usefullBytes [7]) + "." + byteToHex16 (usefullBytes [8]) + "." + byteToHex16 (usefullBytes [9]) + "." + byteToHex16 (usefullBytes [10]) + "." + byteToHex16 (usefullBytes [11]) + "." + byteToHex16 (usefullBytes [12]);
// onePortBus.Name = MyEncodingGB2312.GetString (usefullBytes, 13, 20).Trim ('\0'); ;
// onePortBus.IPAddress = usefullBytes [33] + "." + usefullBytes [34] + "." + usefullBytes [35] + "." + usefullBytes [36];
// onePortBus.RouteIPAddress = usefullBytes [37] + "." + usefullBytes [38] + "." + usefullBytes [39] + "." + usefullBytes [40];
// onePortBus.IPMAC = (char)usefullBytes [41] + "." + (char)usefullBytes [42] + "." + (char)usefullBytes [43] + "." + usefullBytes [44] + "." + usefullBytes [45] + "." + usefullBytes [46];
// onePortBus.SubnetMask = usefullBytes [47] + "." + usefullBytes [48] + "." + usefullBytes [49] + "." + usefullBytes [50];
// onePortBus.DHCP = usefullBytes [51] == 0 ? false : true;
// //onePortBus.SubnetID = usefullBytes [52];
// if (usefullBytes.Length == 53 + 1 + 8) {
// onePortBus.EncryptionFlag = usefullBytes [53];
// onePortBus.Password = MyEncodingGB2312.GetString (usefullBytes, 54, 8).Trim ('\0');
// }
// GateWayList.Add (onePortBus);
// if (onePortBus.Name == "") {
// onePortBus.Name = onePortBus.CommonLoopID.ToString ();
// }
// //IO.FileUtils.SaveEquipmentMessage (onePortBus);
// //System.Threading.Tasks.Task.Run (() => {
// // if (string.IsNullOrEmpty (UserConfig.Current.RemoteModeFile)) {
// // var gatewayBytes = Control.ControlBytesSendHasReturn (Command.ReadGateWayModelInfo, onePortBus.SubnetID, onePortBus.DeviceID, new byte [] { });
// // if (gatewayBytes!=null&&gatewayBytes [0] == 2) {
// // UserConfig.Current.RemoteModeFile = "Equipment_" + onePortBus.Type.ToString () + "_" + onePortBus.SubnetID.ToString () + "_" + onePortBus.DeviceID.ToString ();
// // UserConfig.Current.SaveUserConfig ();
// // }
// // }
// //});
// #endregion
// break;
// case DeviceType.RCU:
// RCU RCU_Device = new RCU ();
// string RCU_DevicePath = "Equipment_" + typeof (RCU).Name + "_" + subnetID + "_" + deviceID;
// var RCU_DeviceBytes = IO.FileUtils.ReadFile (RCU_DevicePath);
// if (RCU_DeviceBytes.Length > 1) {
// RCU_Device = Newtonsoft.Json.JsonConvert.DeserializeObject (MyEncodingUTF8.GetString (RCU_DeviceBytes));
// }
// RCU_Device.SubnetID = subnetID;
// RCU_Device.DeviceID = deviceID;
// RCU_Device.LoopID = usefullBytes [4];
// RCU_Device.MAC = byteToHex16 (usefullBytes [5]) + "." + byteToHex16 (usefullBytes [6]) + "." + byteToHex16 (usefullBytes [7]) + "." + byteToHex16 (usefullBytes [8]) + "." + byteToHex16 (usefullBytes [9]) + "." + byteToHex16 (usefullBytes [10]) + "." + byteToHex16 (usefullBytes [11]) + "." + byteToHex16 (usefullBytes [12]);
// RCU_Device.Name = MyEncodingGB2312.GetString (usefullBytes, 13, 20).Trim ('\0');//=============
// RCU_Device.IPAddress = usefullBytes [33] + "." + usefullBytes [34] + "." + usefullBytes [35] + "." + usefullBytes [36];
// RCU_Device.RouteIPAddress = usefullBytes [37] + "." + usefullBytes [38] + "." + usefullBytes [39] + "." + usefullBytes [40];
// RCU_Device.IPMAC = (char)usefullBytes [41] + "." + (char)usefullBytes [42] + "." + (char)usefullBytes [43] + "." + usefullBytes [44] + "." + usefullBytes [45] + "." + usefullBytes [46];
// RCU_Device.SubnetMask = usefullBytes [47] + "." + usefullBytes [48] + "." + usefullBytes [49] + "." + usefullBytes [50];
// RCU_Device.DHCP = usefullBytes [51] == 0 ? false : true;
// RCU_Device.LinkNetworkLine = true;
// GateWayList.Add (RCU_Device);
// if (RCU_Device.Name == "") {
// RCU_Device.Name = RCU_Device.CommonLoopID.ToString ();
// }
// //IO.FileUtils.SaveEquipmentMessage (RCU_Device);
// break;
// case DeviceType.MusicModel:
// MusicModel mm = new MusicModel ();
// GateWayList.Add (mm);
// mm.SubnetID = subnetID;
// mm.DeviceID = deviceID;
// mm.ChNumberCount = usefullBytes [4];
// mm.MAC = byteToHex16 (usefullBytes [5]) + "." + byteToHex16 (usefullBytes [6]) + "." + byteToHex16 (usefullBytes [7]) + "." + byteToHex16 (usefullBytes [8]) + "." + byteToHex16 (usefullBytes [9]) + "." + byteToHex16 (usefullBytes [10]) + "." + byteToHex16 (usefullBytes [11]) + "." + byteToHex16 (usefullBytes [12]);
// mm.Name = MyEncodingGB2312.GetString (usefullBytes, 13, 20).Trim ('\0');//=============
// mm.IPAddress = usefullBytes [33] + "." + usefullBytes [34] + "." + usefullBytes [35] + "." + usefullBytes [36];
// mm.RouteIPAddress = usefullBytes [37] + "." + usefullBytes [38] + "." + usefullBytes [39] + "." + usefullBytes [40];
// mm.IPMAC = (char)usefullBytes [41] + "." + (char)usefullBytes [42] + "." + (char)usefullBytes [43] + "." + usefullBytes [44] + "." + usefullBytes [45] + "." + usefullBytes [46];
// mm.SubnetMask = usefullBytes [47] + "." + usefullBytes [48] + "." + usefullBytes [49] + "." + usefullBytes [50];
// mm.DHCP = 0;
// if (mm.Name == "") {
// mm.Name = mm.CommonLoopID.ToString ();
// }
// IO.FileUtils.SaveEquipmentMessage (mm);
// IO.FileUtils.SaveEquipmentMessage (mm, "1");
// break;
// case DeviceType.MusicA31:
// MusicA31 mm31 = new MusicA31 ();
// GateWayList.Add (mm31);
// mm31.SubnetID = subnetID;
// mm31.DeviceID = deviceID;
// mm31.ChNumberCount = usefullBytes [4];
// mm31.MAC = byteToHex16 (usefullBytes [5]) + "." + byteToHex16 (usefullBytes [6]) + "." + byteToHex16 (usefullBytes [7]) + "." + byteToHex16 (usefullBytes [8]) + "." + byteToHex16 (usefullBytes [9]) + "." + byteToHex16 (usefullBytes [10]) + "." + byteToHex16 (usefullBytes [11]) + "." + byteToHex16 (usefullBytes [12]);
// mm31.Name = MyEncodingGB2312.GetString (usefullBytes, 13, 20).Trim ('\0');//=============
// mm31.IPAddress = usefullBytes [33] + "." + usefullBytes [34] + "." + usefullBytes [35] + "." + usefullBytes [36];
// mm31.RouteIPAddress = usefullBytes [37] + "." + usefullBytes [38] + "." + usefullBytes [39] + "." + usefullBytes [40];
// mm31.IPMAC = (char)usefullBytes [41] + "." + (char)usefullBytes [42] + "." + (char)usefullBytes [43] + "." + usefullBytes [44] + "." + usefullBytes [45] + "." + usefullBytes [46];
// mm31.SubnetMask = usefullBytes [47] + "." + usefullBytes [48] + "." + usefullBytes [49] + "." + usefullBytes [50];
// mm31.DHCP = usefullBytes [51];
// if (mm31.Name == "") {
// mm31.Name = mm31.CommonLoopID.ToString ();
// }
// //mm31.SubnetID
// IO.FileUtils.SaveEquipmentMessage (mm31);
// IO.FileUtils.SaveEquipmentMessage (mm31, "1");
// break;
// default:
// break;
// }
// break;
// //读取非网络设备回复
// case Command.ReadDeviceModulACK:
// if (!LocalPhoneFindDevice) {//r如果不是本机在查找设备
// break;
// }
// if (!string.IsNullOrEmpty (SystemMiddle.curGatewayIP) && SystemMiddle.curGatewayIP != revGatewayIP) {
// return;
// }
// if (usefullBytes [0] != RandomHigh || usefullBytes [1] != RandomLow) {
// return;
// }
// if (DeviceList.Find ((l) => { return l.SubnetID == subnetID && l.DeviceID == deviceID; }) != null) {
// return;
// }
// notHasRemake = false;
// for (int ki = 0; ki < 20; ki++) {
// if (usefullBytes [3 + ki] != 255) {
// break;
// } else {
// notHasRemake = true;
// }
// }
// if (usefullBytes [24] == 0) {
// } else {
// for (int i = 22; i < usefullBytes.Length; i += 3) {
// if (usefullBytes [i + 2] == 0) {
// continue;
// }
// deviceType = (DeviceType)(usefullBytes [i] * 256 + usefullBytes [i + 1]);
// //MainPage.WriteLog (deviceType.ToString ());
// //if (notHasRemake ) {
// // byte [] ddd = CommonPage.MyEncodingGB2312.GetBytes (deviceType.ToString () + "-" + subnetID.ToString () + "-" + deviceID.ToString ());
// // Array.Copy (ddd, 0, usefullBytes, 2, 20 < ddd.Length ? 20 : ddd.Length);
// //}
// if (deviceType.ToString () == (usefullBytes [i] * 256 + usefullBytes [i + 1]).ToString ()) {
// continue;
// }
// if (deviceType == DeviceType.MusicModel || deviceType == DeviceType.RCU || deviceType == DeviceType.MusicPanel) {//|| deviceType == DeviceType.LogicModule) {// || deviceType == DeviceType.FoolHeat){// ||deviceType == DeviceType.InfraredMode) {
// continue;
// }
// if (deviceType == DeviceType.Thermostat) {
// if (i > 24)
// continue;
// }
// Common common = new Common () {
// GatewayMAC = SystemMiddle.curGatewayMAC,
// SubnetID = subnetID, DeviceID = deviceID,
// Name = MyEncodingGB2312.GetString (usefullBytes, 2, 20).Trim ('\0'), Type = deviceType, LoopCount = usefullBytes [i + 2],
// };
// DeviceList.Add (common);
// if (i > 24) {
// common.isMixBox = true;
// common.MixType = (DeviceType)(usefullBytes [22] * 256 + usefullBytes [23]);
// }
// IO.FileUtils.SaveEquipmentMessage (common);
// }
// }
// break;
// //设备对应回路
// case Command.ReadDeviceLoopInfoACK:
// MainPage.WriteLog ("ReadDeviceLoopInfoACK : " + LocalPhoneFindDevice);
// if (!LocalPhoneFindDevice) {//r如果不是本机在查找设备
// if (usefullBytes [0] * 256 != 5)
// break;
// //Application.RunOnMainThread (() => {
// // try {
// // new Alert (Language.StringByID (R.MyInternationalizationString.Tip), "ReadDeviceLoopInfoACK fail", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
// // } catch {
// // }
// //});
// }
// DeviceType deviceType1 = (DeviceType)(usefullBytes [0] * 256 + usefullBytes [1]);
// bool notHasRemake2 = false;
// for (int ki = 0; ki < 20; ki++) {
// if (usefullBytes [3 + ki] != 255) {
// break;
// } else {
// notHasRemake2 = true;
// }
// }
// //处理特殊字符
// for (var remakeIndex = 22; remakeIndex >= 3; remakeIndex--) {
// if (usefullBytes [remakeIndex] == 0xFF) {
// usefullBytes [remakeIndex] = 0;
// } else {
// break;
// }
// }
// if (notHasRemake2 || MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0') == "") {
// byte [] ddd = CommonPage.MyEncodingGB2312.GetBytes (deviceType1.ToString () + "-" + subnetID.ToString () + "-" + deviceID.ToString () + "-" + usefullBytes [2].ToString ());
// Array.Copy (ddd, 0, usefullBytes, 3, 20 < ddd.Length ? 20 : ddd.Length);
// }
// if (null != DeviceLoopList.Find ((common) => {
// return common.Type == deviceType1 && common.SubnetID == subnetID & common.DeviceID == deviceID && common.LoopID == usefullBytes [2];
// })) {
// //存在当前设备就返回
// return;
// }
// //if (ModuleType.YIPanel == (ModuleType)(usefullBytes [0] * 256 + usefullBytes [1])){
// // var yIPanel = new YIPanel () {
// // SubnetID = subnetID, DeviceID = deviceID, Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0'),
// // };
// // IO.FileUtils.SaveEquipmentMessage (yIPanel);
// //}
// switch (deviceType1) {
// case DeviceType.Thermostat:
// var thermostat = new Thermostat () {
// SubnetID = subnetID, DeviceID = deviceID, LoopID = usefullBytes [2], Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0'),
// HostID = usefullBytes[23],ExtensionID = usefullBytes[24]
// };
// DeviceLoopList.Add (thermostat);
// IO.FileUtils.SaveEquipmentMessage (thermostat, thermostat.LoopID.ToString ());
// break;
// case DeviceType.FreshAir:
// //通道号(1 - 200) + 备注 + 开关(0,1) + 风速(0 关,1低,2中,3高) + 模式(0手动,1 自动) + 换气扇(0 关,1低,2中,3高) + 室内温度 + 室外温度 + 室内湿度+ PM2.5 + VOC +CO2
// FreshAir fresAir = new FreshAir () {
// SubnetID = subnetID, DeviceID = deviceID, LoopID = usefullBytes [2], Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0'),
// //SwitchStatus = usefullBytes[23], WindSpeed = usefullBytes [24], SetPattern= usefullBytes [25], InTemp = usefullBytes [26],
// //OutTemp =usefullBytes [27], InHumidity =usefullBytes [28], PM25 = usefullBytes [29], TVOC = usefullBytes [30], CO2 = usefullBytes [31]
// };
// DeviceLoopList.Add (fresAir);
// IO.FileUtils.SaveEquipmentMessage (fresAir, fresAir.LoopID.ToString ());
// break;
// case DeviceType.MusicPanel:
// MusicPanel mm = new MusicPanel ();
// mm.SubnetID = subnetID;
// mm.DeviceID = deviceID;
// mm.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// mm.Status = usefullBytes [23];
// mm.isMixBox = true;
// DeviceLoopList.Add (mm);
// IO.FileUtils.SaveEquipmentMessage (mm, "1");
// break;
// case DeviceType.DryContact:
// #region
// DryContact sdc = new DryContact ();
// sdc.SubnetID = subnetID;
// sdc.DeviceID = deviceID;
// sdc.LoopID = usefullBytes [2];//前两位为随机数
// sdc.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// sdc.Mode = usefullBytes [23];
// DeviceLoopList.Add (sdc);
// IO.FileUtils.SaveEquipmentMessage (sdc, sdc.LoopID.ToString ());
// #endregion
// break;
// case DeviceType.FoolHeat:
// #region
// var thRDD = new FoolHeat ();
// thRDD.SubnetID = subnetID;
// thRDD.DeviceID = deviceID;
// thRDD.LoopID = usefullBytes [2];
// thRDD.Name = Encoding.Unicode.GetString (usefullBytes, 3, 20).Trim ('\0');
// thRDD.Status = usefullBytes [23];
// thRDD.WorkingMode = usefullBytes [24];
// thRDD.WorkingTemperature = usefullBytes [25];
// thRDD.PIDSpeed = usefullBytes [26];
// thRDD.IndoorTemperature = usefullBytes [27];
// thRDD.FloorTemperature = usefullBytes [28];
// DeviceLoopList.Add (thRDD);
// IO.FileUtils.SaveEquipmentMessage (thRDD, thRDD.LoopID.ToString ());
// #endregion
// break;
// case DeviceType.FoolHeatPanel:
// #region
// var thp = new FoolHeatPanel ();
// thp.SubnetID = subnetID;
// thp.DeviceID = deviceID;
// thp.LoopID = usefullBytes [2];
// thp.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// thp.Status = usefullBytes [23];
// thp.WorkingMode = usefullBytes [24];
// thp.WorkingTemperature = usefullBytes [25];
// thp.PIDSpeed = usefullBytes [26];
// thp.IndoorTemperature = usefullBytes [27];
// thp.FloorTemperature = usefullBytes [28];
// DeviceLoopList.Add (thp);
// IO.FileUtils.SaveEquipmentMessage (thp, thp.LoopID.ToString ());
// #endregion
// break;
// case DeviceType.LightDimming:
// #region
// var lightDimming = new LightDimming ();
// lightDimming.SubnetID = subnetID;
// lightDimming.DeviceID = deviceID;
// lightDimming.LoopID = usefullBytes [2];
// lightDimming.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// lightDimming.Minimum = usefullBytes [23];
// lightDimming.MaxLevel = usefullBytes [24];
// lightDimming.CurrentBrightness = usefullBytes [25];
// DeviceLoopList.Add (lightDimming);
// IO.FileUtils.SaveEquipmentMessage (lightDimming, lightDimming.LoopID.ToString ());
// #endregion
// break;
// case DeviceType.LightDALI:
// #region
// /*
// 回路号,备注,低限,最大水平,当前亮度值, 24byte
// 回路在线(0x00不在,oxff在线),回路类型(全部有亮度,另8有色温), 2byte
// 色温物理最暖H + 最暖L,色温物理最冷H + 最冷L, 4byte
// 色温最暖H + 最暖L,色温最冷H + 最冷L, 4byte
// 当前色温H + L, 2byte
// */
// var lightDALI = new LightDALI ();
// lightDALI.Type = DeviceType.LightDALI;
// lightDALI.SubnetID = subnetID;
// lightDALI.DeviceID = deviceID;
// lightDALI.LoopID = usefullBytes [2];
// lightDALI.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// lightDALI.Minimum = usefullBytes [23];
// lightDALI.MaxLevel = usefullBytes [24];
// if (usefullBytes.Length > 27) {
// //lightDALI.LinkLightStatus = usefullBytes [24];
// lightDALI.CurrentBrightness = usefullBytes [25];
// lightDALI.DALIModule = true;
// lightDALI.Online = usefullBytes [26];
// lightDALI.LoopType = usefullBytes [27];
// lightDALI.WarmTones_High_Modular = usefullBytes [28];
// lightDALI.WarmTones_Low_Modular = usefullBytes [29];
// lightDALI.CoolTones_High_Modular = usefullBytes [30];
// lightDALI.CoolTones_Low_Modular = usefullBytes [31];
// lightDALI.WarmTones_High = usefullBytes [32];
// lightDALI.WarmTones_Low = usefullBytes [33];
// lightDALI.CoolTones_High = usefullBytes [34];
// lightDALI.CoolTones_Low = usefullBytes [35];
// lightDALI.CurTones_High = usefullBytes [36];
// lightDALI.CurTones_Low = usefullBytes [37];
// }
// //lightDALI.MinClass = 7;
// DeviceLoopList.Add (lightDALI);
// IO.FileUtils.SaveEquipmentMessage (lightDALI, lightDALI.LoopID.ToString ());
// #endregion
// break;
// case DeviceType.LightSwitch:
// #region
// var lightSwitch = new LightSwitch ();
// lightSwitch.SubnetID = subnetID;
// lightSwitch.DeviceID = deviceID;
// lightSwitch.LoopID = usefullBytes [2];
// lightSwitch.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// lightSwitch.CurrentBrightness = usefullBytes [23];
// if (UserConfig.Instance.SocketList.Contains (lightSwitch.CommonLoopID)) {
// lightSwitch.Type = DeviceType.LightSwitchSocket;
// lightSwitch.DeviceTextID = SimpleControl.R.MyInternationalizationString.ElectricalControl;
// }
// DeviceLoopList.Add (lightSwitch);
// IO.FileUtils.SaveEquipmentMessage (lightSwitch, lightSwitch.LoopID.ToString ());
// #endregion
// break;
// case DeviceType.LightEnergySwitch:
// #region
// var lightEnergySwitch = new LightEnergySwitch ();
// lightEnergySwitch.SubnetID = subnetID;
// lightEnergySwitch.DeviceID = deviceID;
// lightEnergySwitch.LoopID = usefullBytes [2];
// lightEnergySwitch.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// lightEnergySwitch.CurrentBrightness = usefullBytes [23];
// //if (UserConfig.Current.SocketList.Contains (lightEnergySwitch.CommonLoopID)) {
// // lightEnergySwitch.Type = DeviceType.LightSwitchSocket;
// // lightEnergySwitch.DeviceTextID = SimpleControl.R.MyInternationalizationString.ElectricalControl;
// //}
// DeviceLoopList.Add (lightEnergySwitch);
// IO.FileUtils.SaveEquipmentMessage (lightEnergySwitch, lightEnergySwitch.LoopID.ToString ());
// #endregion
// break;
// case DeviceType.LightMixDimming:
// #region
// var lightMixDimming = new LightMixDimming ();
// lightMixDimming.SubnetID = subnetID;
// lightMixDimming.DeviceID = deviceID;
// lightMixDimming.LoopID = usefullBytes [2];
// lightMixDimming.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// lightMixDimming.Minimum = usefullBytes [23];
// lightMixDimming.MaxLevel = usefullBytes [24];
// lightMixDimming.CurrentBrightness = usefullBytes [25];
// lightMixDimming.PhysicsLoopID = usefullBytes [26];
// DeviceLoopList.Add (lightMixDimming);
// IO.FileUtils.SaveEquipmentMessage (lightMixDimming, lightMixDimming.LoopID.ToString ());
// #endregion
// break;
// case DeviceType.LightMixSwitch:
// #region
// var lightMixSwitch = new LightMixSwitch ();
// lightMixSwitch.SubnetID = subnetID;
// lightMixSwitch.DeviceID = deviceID;
// lightMixSwitch.LoopID = usefullBytes [2];
// lightMixSwitch.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// lightMixSwitch.CurrentBrightness = usefullBytes [23];
// lightMixSwitch.PhysicsLoopID = usefullBytes [24];
// DeviceLoopList.Add (lightMixSwitch);
// IO.FileUtils.SaveEquipmentMessage (lightMixSwitch, lightMixSwitch.LoopID.ToString ());
// #endregion
// break;
// case DeviceType.LightRGB:
// var lightRGB = new LightLogic ();
// lightRGB.Type = DeviceType.LightRGB;
// lightRGB.SubnetID = subnetID;
// lightRGB.DeviceID = deviceID;
// lightRGB.LoopID = usefullBytes [2];
// lightRGB.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// lightRGB.RStatus = usefullBytes [23];
// lightRGB.GStatus = usefullBytes [24];
// lightRGB.BStatus = usefullBytes [25];
// DeviceLoopList.Add (lightRGB);
// IO.FileUtils.SaveEquipmentMessage (lightRGB, lightRGB.LoopID.ToString ());
// break;
// case DeviceType.LightRGBW:
// //var lightRGBW = new LightLogic ();
// //lightRGBW.Type = DeviceType.LightRGBW;
// //lightRGBW.SubnetID = subnetID;
// //lightRGBW.DeviceID = deviceID;
// //lightRGBW.LoopID = usefullBytes [2];
// //lightRGBW.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// //lightRGBW.RStatus = usefullBytes [23] /100 * 255;
// //lightRGBW.GStatus = usefullBytes [24] /100 * 255;
// //lightRGBW.BStatus = usefullBytes [25] /100 * 255;
// //lightRGBW.WStatus = usefullBytes [26] /100 * 255;
// //DeviceLoopList.Add (lightRGBW);
// //IO.FileUtils.SaveEquipmentMessage (lightRGBW, lightRGBW.LoopID.ToString ());
// break;
// case DeviceType.LightCCT:
// //var lightCCT = new LightLogic ();
// //lightCCT.Type = DeviceType.LightCCT;
// //lightCCT.SubnetID = subnetID;
// //lightCCT.DeviceID = deviceID;
// //lightCCT.LoopID = usefullBytes [2];
// //lightCCT.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// //lightCCT.CTHStatus = usefullBytes [23];
// //lightCCT.CTLStatus = usefullBytes [24];
// //DeviceLoopList.Add (lightCCT);
// //IO.FileUtils.SaveEquipmentMessage (lightCCT, lightCCT.LoopID.ToString ());
// break;
// case DeviceType.LightRGBandCCT:
// //var lightRGBandCCT = new LightLogic ();
// //lightRGBandCCT.Type = DeviceType.LightRGBandCCT;
// //lightRGBandCCT.SubnetID = subnetID;
// //lightRGBandCCT.DeviceID = deviceID;
// //lightRGBandCCT.LoopID = usefullBytes [2];
// //lightRGBandCCT.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// //lightRGBandCCT.RStatus = usefullBytes [23] /100 * 255;
// //lightRGBandCCT.GStatus = usefullBytes [24] /100 * 255;
// //lightRGBandCCT.BStatus = usefullBytes [25] /100 * 255;
// //lightRGBandCCT.CTHStatus = usefullBytes [26];
// //lightRGBandCCT.CTLStatus = usefullBytes [27];
// //DeviceLoopList.Add (lightRGBandCCT);
// //IO.FileUtils.SaveEquipmentMessage (lightRGBandCCT, lightRGBandCCT.LoopID.ToString ());
// break;
// case DeviceType.CurtainModel:
// #region
// var curtain = new CurtainModel ();
// curtain.SubnetID = subnetID;
// curtain.DeviceID = deviceID;
// curtain.LoopID = usefullBytes [2];
// curtain.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// curtain.RunTime = (usefullBytes [23] * 256 + usefullBytes [24])/10;
// curtain.Status = (CurtainStatus)(usefullBytes [25]);
// DeviceLoopList.Add (curtain);
// FileUtils.SaveEquipmentMessage (curtain, curtain.LoopID.ToString ());
// #endregion
// break;
// case DeviceType.CurtainTrietex:
// #region
// var curtaintrietex = new CurtainTrietex ();
// curtaintrietex.SubnetID = subnetID;
// curtaintrietex.DeviceID = deviceID;
// curtaintrietex.LoopID = usefullBytes [2];
// curtaintrietex.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// curtaintrietex.CurtainLength = usefullBytes [23] * 256 + usefullBytes [24];
// //curtaintrietex.Status = (CurtainStatus)(usefullBytes [24]);
// curtaintrietex.CurtainProress = usefullBytes [25];
// curtaintrietex.MotorRotation = usefullBytes [26];
// DeviceLoopList.Add (curtaintrietex);
// FileUtils.SaveEquipmentMessage (curtaintrietex, curtaintrietex.LoopID.ToString ());
// #endregion
// break;
// case DeviceType.CurtainRoller:
// #region
// var CurtainRoller = new CurtainRoller ();
// CurtainRoller.SubnetID = subnetID;
// CurtainRoller.DeviceID = deviceID;
// CurtainRoller.LoopID = usefullBytes [2];
// CurtainRoller.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// CurtainRoller.CurtainProress = usefullBytes [23];
// CurtainRoller.MotorRotation = usefullBytes [24];
// DeviceLoopList.Add (CurtainRoller);
// FileUtils.SaveEquipmentMessage (CurtainRoller, CurtainRoller.LoopID.ToString ());
// #endregion
// break;
// case DeviceType.HVAC:
// #region
// var acHost = new HVAC ();
// acHost.SubnetID = subnetID;
// acHost.DeviceID = deviceID;
// acHost.LoopID = usefullBytes [2];
// acHost.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// DeviceLoopList.Add (acHost);
// IO.FileUtils.SaveEquipmentMessage (acHost, acHost.LoopID.ToString ());
// #endregion
// break;
// case DeviceType.ACPanel:
// #region
// var acPanel = new ACPanel ();
// acPanel.SubnetID = subnetID;
// acPanel.DeviceID = deviceID;
// acPanel.LoopID = usefullBytes [2];
// acPanel.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// DeviceLoopList.Add (acPanel);
// IO.FileUtils.SaveEquipmentMessage (acPanel, acPanel.LoopID.ToString ());
// #endregion
// break;
// case DeviceType.ButtonPanel:
// #region MyRegion
// if (usefullBytes [23] == 255)
// break;
// ButtonPanel wirelessPanelButtonKey = new ButtonPanel ();
// DeviceLoopList.Add (wirelessPanelButtonKey);
// wirelessPanelButtonKey.SubnetID = subnetID;
// wirelessPanelButtonKey.DeviceID = deviceID;
// wirelessPanelButtonKey.LoopID = usefullBytes [2];
// wirelessPanelButtonKey.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// wirelessPanelButtonKey.Mode = usefullBytes [23];
// ButtonBkeyModelList.Add (wirelessPanelButtonKey.Mode);
// System.MainPage.WriteLog ("读取面板按键:回路号:" + wirelessPanelButtonKey.LoopID + " 模式:" + wirelessPanelButtonKey.Mode);
// IO.FileUtils.SaveEquipmentMessage (wirelessPanelButtonKey, wirelessPanelButtonKey.LoopID.ToString ());
// #endregion
// break;
// case DeviceType.InfraredMode:
// #region 红外模块
// InfraredMode infrared = new InfraredMode ();
// DeviceLoopList.Add (infrared);
// infrared.SubnetID = subnetID;
// infrared.DeviceID = deviceID;
// infrared.LoopID = usefullBytes [2];
// infrared.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// IO.FileUtils.SaveEquipmentMessage (infrared, infrared.LoopID.ToString ());
// SystemWirelessGateway.Waiting = true;
// try {
// Control.ControlBytesSendHasReturn (Command.DownloadInfrared, subnetID, deviceID, new byte [] { usefullBytes [2], 0, 0 });
// SystemWirelessGateway.Waiting = false;
// } catch {
// SystemWirelessGateway.Waiting = false;
// }
// #endregion
// break;
// case DeviceType.ACInfrared:
// #region
// var acInfrared = new ACInfrared ();
// acInfrared.SubnetID = subnetID;
// acInfrared.DeviceID = deviceID;
// acInfrared.LoopID = usefullBytes [2];
// acInfrared.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// DeviceLoopList.Add (acInfrared);
// IO.FileUtils.SaveEquipmentMessage (acInfrared, acInfrared.LoopID.ToString ());
// #endregion
// break;
// case DeviceType.SecurityModule:
// #region 安防模块
// var SecurityMould = new SecurityModul ();
// SecurityMould.SubnetID = subnetID;
// SecurityMould.DeviceID = deviceID;
// SecurityMould.LoopID = usefullBytes [2];
// SecurityMould.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// SecurityMould.AreaType = usefullBytes [23];
// DeviceLoopList.Add (SecurityMould);
// IO.FileUtils.SaveEquipmentMessage (SecurityMould, SecurityMould.LoopID.ToString ());
// #endregion
// break;
// case DeviceType.FanModule:
// #region 风扇模块
// var fanModule = new FanModule ();
// fanModule.SubnetID = subnetID;
// fanModule.DeviceID = deviceID;
// fanModule.LoopID = usefullBytes [2];
// fanModule.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// fanModule.WindSpeed = 1;
// //fanModule.WindSpeed = usefullBytes [23];
// IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
// #endregion
// break;
// case DeviceType.LogicModule:
// LogicModule logicModule = new LogicModule ();
// logicModule.SubnetID = subnetID;
// logicModule.DeviceID = deviceID;
// logicModule.LoopID = usefullBytes [2];
// logicModule.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// logicModule.AreaID = usefullBytes [23];
// logicModule.AreaSceneID = usefullBytes [24];
// IO.FileUtils.SaveEquipmentMessage (logicModule, logicModule.LoopID.ToString ());
// break;
// case DeviceType.DoorLock:
// var doorLock = new DoorLock ();//门锁111
// doorLock.SubnetID = subnetID;
// doorLock.DeviceID = deviceID;
// doorLock.LoopID = usefullBytes [2];
// doorLock.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// DeviceLoopList.Add (doorLock);
// IO.FileUtils.SaveEquipmentMessage (doorLock, doorLock.LoopID.ToString ());
// UserConfig.Instance.HideDeviceTypes.Remove (R.MyInternationalizationString.DoorLock);
// UserConfig.Instance.SaveUserConfig ();
// break;
// #region 传感器
// case DeviceType.SensorMobileDetection:
// //var sensor = new SensorMobileDetection ();
// //sensor.SubnetID = subnetID;
// //sensor.DeviceID = deviceID;
// //sensor.LoopID = usefullBytes [2];
// //sensor.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// //sensor.Enable = usefullBytes [23] == 1 ? true : false;
// //sensor.Sensitivity = usefullBytes [24];
// //sensor.Status = usefullBytes [25];
// //IO.FileUtils.SaveEquipmentMessage (sensor, sensor.LoopID.ToString ());
// break;
// ///
// /// 温度
// ///
// case DeviceType.SensorTemperature:
// var sensor1 = new SensorTemperature ();
// sensor1.SubnetID = subnetID;
// sensor1.DeviceID = deviceID;
// sensor1.LoopID = usefullBytes [2];
// sensor1.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// byte [] tempBytes = new byte [] { usefullBytes [24], usefullBytes [25], usefullBytes [26], usefullBytes [27] };
// sensor1.CurrentTemperature = Math.Round (BitConverter.ToSingle (tempBytes, 0), 1);
// bool inLocal1 = false;
// foreach (var room in Room.Lists) {
// var roomSensor = room.DeviceList.Find ((obj) => obj.MinClass == sensor1.MinClass && obj.SubnetID == sensor1.SubnetID && obj.DeviceID == sensor1.DeviceID && obj.LoopID == sensor1.LoopID);
// if (roomSensor != null) {
// (roomSensor as SensorTemperature).CurrentTemperature = sensor1.CurrentTemperature;
// inLocal1 = true;
// }
// }
// //if(!inLocal1){
// IO.FileUtils.SaveEquipmentMessage (sensor1, sensor1.LoopID.ToString ());
// //}
// break;
// ///
// /// 湿度
// ///
// case DeviceType.SensorHumidity:
// var sensor2 = new SensorHumidity ();
// sensor2.SubnetID = subnetID;
// sensor2.DeviceID = deviceID;
// sensor2.LoopID = usefullBytes [2];
// sensor2.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// sensor2.Enable = usefullBytes [23] == 1 ? true : false;
// sensor2.CurrentHumidity = Convert.ToDouble (usefullBytes [24] * 256 + usefullBytes [25]) / 10;
// bool inLocal2 = false;
// foreach (var room in Room.Lists) {
// var roomSensor = room.DeviceList.Find ((obj) => obj.MinClass == sensor2.MinClass && obj.SubnetID == sensor2.SubnetID && obj.DeviceID == sensor2.DeviceID && obj.LoopID == sensor2.LoopID);
// if (roomSensor != null) {
// (roomSensor as SensorHumidity).CurrentHumidity = sensor2.CurrentHumidity;
// inLocal2 = true;
// }
// }
// //if(!inLocal2){
// IO.FileUtils.SaveEquipmentMessage (sensor2, sensor2.LoopID.ToString ());
// //}
// break;
// /////
// ///// 光照
// /////
// case DeviceType.SensorIllumination:
// //var sensor3 = new SensorIllumination ();
// //sensor3.SubnetID = subnetID;
// //sensor3.DeviceID = deviceID;
// //sensor3.LoopID = usefullBytes [2];
// //sensor3.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// //sensor3.Enable = usefullBytes [23] == 1 ? true : false;
// //sensor3.CurrentIllumination = Convert.ToInt32(usefullBytes [24] * 256 + usefullBytes [25]);
// //IO.FileUtils.SaveEquipmentMessage (sensor3, sensor3.LoopID.ToString ());
// break;
// /////
// ///// TVOC(05)
// /////
// case DeviceType.SensorTVOC:
// var sensor4 = new SensorTVOC ();
// sensor4.SubnetID = subnetID;
// sensor4.DeviceID = deviceID;
// sensor4.LoopID = usefullBytes [2];
// sensor4.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// sensor4.Enable = usefullBytes [23] == 1 ? true : false;
// sensor4.CurrentTVOC = Convert.ToDouble (usefullBytes [24] * 256 + usefullBytes [25]) / 100;
// bool inLocal3 = false;
// foreach (var room in Room.Lists) {
// var roomSensor = room.DeviceList.Find ((obj) => obj.MinClass == sensor4.MinClass && obj.SubnetID == sensor4.SubnetID && obj.DeviceID == sensor4.DeviceID && obj.LoopID == sensor4.LoopID);
// if (roomSensor != null) {
// inLocal3 = true;
// (roomSensor as SensorTVOC).CurrentTVOC = sensor4.CurrentTVOC;
// }
// }
// //if (!inLocal3) {
// IO.FileUtils.SaveEquipmentMessage (sensor4, sensor4.LoopID.ToString ());
// //}
// break;
// /////
// ///// The sensor PM 25.
// /////
// case DeviceType.SensorPM25:
// var sensor5 = new SensorPM25 ();
// sensor5.SubnetID = subnetID;
// sensor5.DeviceID = deviceID;
// sensor5.LoopID = usefullBytes [2];
// sensor5.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// sensor5.Enable = usefullBytes [23] == 1 ? true : false;
// sensor5.CurrentPM25 = Convert.ToInt32 (usefullBytes [24] * 256 + usefullBytes [25]);
// bool inLocal4 = false;
// foreach (var room in Room.Lists) {
// var roomSensor = room.DeviceList.Find ((obj) => obj.MinClass == sensor5.MinClass && obj.SubnetID == sensor5.SubnetID && obj.DeviceID == sensor5.DeviceID && obj.LoopID == sensor5.LoopID);
// if (roomSensor != null) {
// (roomSensor as SensorPM25).CurrentPM25 = sensor5.CurrentPM25;
// inLocal4 = true;
// }
// }
// //if(!inLocal4){
// IO.FileUtils.SaveEquipmentMessage (sensor5, sensor5.LoopID.ToString ());
// //}
// break;
// /////
// ///// The sensor CO2.
// /////
// case DeviceType.SensorCO2:
// var sensor6 = new SensorCO2 ();
// sensor6.SubnetID = subnetID;
// sensor6.DeviceID = deviceID;
// sensor6.LoopID = usefullBytes [2];
// sensor6.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// sensor6.Enable = usefullBytes [23] == 1 ? true : false;
// sensor6.CurrentCO2 = Convert.ToInt32 (usefullBytes [24] * 256 + usefullBytes [25]);
// bool inLocal5 = false;
// foreach (var room in Room.Lists) {
// var roomSensor = room.DeviceList.Find ((obj) => obj.MinClass == sensor6.MinClass && obj.SubnetID == sensor6.SubnetID && obj.DeviceID == sensor6.DeviceID && obj.LoopID == sensor6.LoopID);
// if (roomSensor != null) {
// (roomSensor as SensorCO2).CurrentCO2 = sensor6.CurrentCO2;
// inLocal5 = true;
// }
// }
// //if(!inLocal5)
// //{
// IO.FileUtils.SaveEquipmentMessage (sensor6, sensor6.LoopID.ToString ());
// //}
// break;
// /////
// ///// 液化石油气(LPG)(08)
// /////
// //SensorLPG = 0x0508,
// case DeviceType.SensorLPG:
// //var sensor7 = new SensorLPG ();
// //sensor7.SubnetID = subnetID;
// //sensor7.DeviceID = deviceID;
// //sensor7.LoopID = usefullBytes [2];
// //sensor7.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// //sensor7.Enable = usefullBytes [23] == 1 ? true : false;
// //sensor7.CurrentLPG = Convert.ToInt32(usefullBytes [24] * 256 + usefullBytes [25]);
// //IO.FileUtils.SaveEquipmentMessage (sensor7, sensor7.LoopID.ToString ());
// break;
// /////
// ///// 人工煤气(CO,H2)(09)
// /////
// case DeviceType.SensorCOH2:
// //var sensor8 = new SensorCOH2 ();
// //sensor8.SubnetID = subnetID;
// //sensor8.DeviceID = deviceID;
// //sensor8.LoopID = usefullBytes [2];
// //sensor8.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// //sensor8.Enable = usefullBytes [23] == 1 ? true : false;
// //sensor8.CurrentCOH2 = Convert.ToInt32(usefullBytes [24] * 256 + usefullBytes [25]);
// //IO.FileUtils.SaveEquipmentMessage (sensor8, sensor8.LoopID.ToString ());
// break;
// /////
// ///// 天然气(CH4)(10)
// /////
// case DeviceType.SensorCH4:
// //var sensor9 = new SensorCH4 ();
// //sensor9.SubnetID = subnetID;
// //sensor9.DeviceID = deviceID;
// //sensor9.LoopID = usefullBytes [2];
// //sensor9.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// //sensor9.Enable = usefullBytes [23] == 1 ? true : false;
// //sensor9.CurrentCH4 = Convert.ToInt32(usefullBytes [24] * 256 + usefullBytes [25]);
// //IO.FileUtils.SaveEquipmentMessage (sensor9, sensor9.LoopID.ToString ());
// break;
// /////
// ///// 烟雾(11)
// /////
// case DeviceType.SensorSmoke:
// //var sensor10 = new SensorSmoke ();
// //sensor10.SubnetID = subnetID;
// //sensor10.DeviceID = deviceID;
// //sensor10.LoopID = usefullBytes [2];
// //sensor10.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// //sensor10.Enable = usefullBytes [23] == 1 ? true : false;
// //sensor10.CurrentStatus = Convert.ToInt32(usefullBytes [24] * 256 + usefullBytes [25]);
// //IO.FileUtils.SaveEquipmentMessage (sensor10, sensor10.LoopID.ToString ());
// break;
// /////
// ///// 风速(12)
// /////
// case DeviceType.SensorWindSpeed:
// //var sensor11 = new SensorWindSpeed ();
// //sensor11.SubnetID = subnetID;
// //sensor11.DeviceID = deviceID;
// //sensor11.LoopID = usefullBytes [2];
// //sensor11.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// //sensor11.Enable = usefullBytes [23] == 1 ? true : false;
// //sensor11.CurrentWindSpeed = Convert.ToInt32(usefullBytes [24] * 256 + usefullBytes [25]);
// //IO.FileUtils.SaveEquipmentMessage (sensor11, sensor11.LoopID.ToString ());
// break;
// /////
// ///// 风压(13)
// /////
// case DeviceType.SensorWindPressure:
// //var sensor12 = new SensorWindPressure ();
// //sensor12.SubnetID = subnetID;
// //sensor12.DeviceID = deviceID;
// //sensor12.LoopID = usefullBytes [2];
// //sensor12.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// //sensor12.Enable = usefullBytes [23] == 1 ? true : false;
// //sensor12.CurrentWindPressure = Convert.ToInt32(usefullBytes [24] * 256 + usefullBytes [25]);
// //IO.FileUtils.SaveEquipmentMessage (sensor12, sensor12.LoopID.ToString ());
// break;
// /////
// ///// 液体流量(14)
// /////
// case DeviceType.SensorLiquidFlow:
// //var sensor13 = new SensorLiquidFlow ();
// //sensor13.SubnetID = subnetID;
// //sensor13.DeviceID = deviceID;
// //sensor13.LoopID = usefullBytes [2];
// //sensor13.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// //sensor13.Enable = usefullBytes [23] == 1 ? true : false;
// //sensor13.CurrentLiquidFlow = Convert.ToInt32(usefullBytes [24] * 256 + usefullBytes [25]);
// //IO.FileUtils.SaveEquipmentMessage (sensor13, sensor13.LoopID.ToString ());
// break;
// /////
// ///// 液体压力(15)
// /////
// case DeviceType.SensorLiquidPressure:
// //var sensor14 = new SensorLiquidPressure ();
// //sensor14.SubnetID = subnetID;
// //sensor14.DeviceID = deviceID;
// //sensor14.LoopID = usefullBytes [2];
// //sensor14.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// //sensor14.Enable = usefullBytes [23] == 1 ? true : false;
// //sensor14.CurrentLiquidPressure = Convert.ToInt32(usefullBytes [24] * 256 + usefullBytes [25]);
// //IO.FileUtils.SaveEquipmentMessage (sensor14, sensor14.LoopID.ToString ());
// break;
// /////
// ///// 液体深度(16)
// /////
// case DeviceType.SensorLiquidDepth:
// //var sensor15 = new SensorLiquidDepth ();
// //sensor15.SubnetID = subnetID;
// //sensor15.DeviceID = deviceID;
// //sensor15.LoopID = usefullBytes [2];
// //sensor15.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// //sensor15.Enable = usefullBytes [23] == 1 ? true : false;
// //sensor15.CurrentLiquidDepth = Convert.ToInt32(usefullBytes [24] * 256 + usefullBytes [25]);
// //IO.FileUtils.SaveEquipmentMessage (sensor15, sensor15.LoopID.ToString ());
// break;
// /////
// ///// 雨量(17)
// /////
// //SensorRainfall = 0x0517,
// case DeviceType.SensorRainfall:
// //var sensor16 = new SensorRainfall ();
// //sensor16.SubnetID = subnetID;
// //sensor16.DeviceID = deviceID;
// //sensor16.LoopID = usefullBytes [2];
// //sensor16.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// //sensor16.Enable = usefullBytes [23] == 1 ? true : false;
// //sensor16.CurrentRainfall = Convert.ToInt32(usefullBytes [24] * 256 + usefullBytes [25]);
// //IO.FileUtils.SaveEquipmentMessage (sensor16, sensor16.LoopID.ToString ());
// break;
// /////
// ///// 重量
// /////
// case DeviceType.SensorWeight:
// //var sensor17 = new SensorWeight ();
// //sensor17.SubnetID = subnetID;
// //sensor17.DeviceID = deviceID;
// //sensor17.LoopID = usefullBytes [2];
// //sensor17.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// //sensor17.Enable = usefullBytes [23] == 1 ? true : false;
// //sensor17.CurrentWeight = Convert.ToInt32(usefullBytes [24] * 256 + usefullBytes [25]);
// //IO.FileUtils.SaveEquipmentMessage (sensor17, sensor17.LoopID.ToString ());
// break;
// /////
// ///// 高度/长度
// /////
// case DeviceType.SensorHeightLength:
// //var sensor18 = new SensorHeightLength ();
// //sensor18.SubnetID = subnetID;
// //sensor18.DeviceID = deviceID;
// //sensor18.LoopID = usefullBytes [2];
// //sensor18.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// //sensor18.Enable = usefullBytes [23] == 1 ? true : false;
// //sensor18.CurrentHeightLength = Convert.ToInt32(usefullBytes [24] * 256 + usefullBytes [25]);
// //IO.FileUtils.SaveEquipmentMessage (sensor18, sensor18.LoopID.ToString ());
// break;
// /////
// ///// 物体速度(20)
// /////
// case DeviceType.SensorVelocity:
// //var sensor19 = new SensorVelocity ();
// //sensor19.SubnetID = subnetID;
// //sensor19.DeviceID = deviceID;
// //sensor19.LoopID = usefullBytes [2];
// //sensor19.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// //sensor19.Enable = usefullBytes [23] == 1 ? true : false;
// //sensor19.CurrentVelocity = Convert.ToInt32(usefullBytes [24] * 256 + usefullBytes [25]);
// //IO.FileUtils.SaveEquipmentMessage (sensor19, sensor19.LoopID.ToString ());
// break;
// /////
// ///// 震动(21)
// /////
// case DeviceType.SensorVibration:
// //var sensor20 = new SensorVibration ();
// //sensor20.SubnetID = subnetID;
// //sensor20.DeviceID = deviceID;
// //sensor20.LoopID = usefullBytes [2];
// //sensor20.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// //sensor20.Enable = usefullBytes [23] == 1 ? true : false;
// //sensor20.CurrentVibration = Convert.ToInt32(usefullBytes [24] * 256 + usefullBytes [25]);
// //IO.FileUtils.SaveEquipmentMessage (sensor20, sensor20.LoopID.ToString ());
// break;
// /////
// ///// 电压
// /////
// case DeviceType.SensorVoltage:
// //var sensor21 = new SensorVoltage ();
// //sensor21.SubnetID = subnetID;
// //sensor21.DeviceID = deviceID;
// //sensor21.LoopID = usefullBytes [2];
// //sensor21.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// //sensor21.Enable = usefullBytes [23] == 1 ? true : false;
// //sensor21.CurrentVoltage = Convert.ToInt32(usefullBytes [24] * 256 + usefullBytes [25]);
// //IO.FileUtils.SaveEquipmentMessage (sensor21, sensor21.LoopID.ToString ());
// break;
// /////
// ///// 电流
// /////
// case DeviceType.SensorCurrent:
// //var sensor22 = new SensorCurrent ();
// //sensor22.SubnetID = subnetID;
// //sensor22.DeviceID = deviceID;
// //sensor22.LoopID = usefullBytes [2];
// //sensor22.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// //sensor22.Enable = usefullBytes [23] == 1 ? true : false;
// //sensor22.CurrentCurrent = Convert.ToInt32(usefullBytes [24] * 256 + usefullBytes [25]);
// //IO.FileUtils.SaveEquipmentMessage (sensor22, sensor22.LoopID.ToString ());
// break;
// /////
// ///// 功率
// /////
// case DeviceType.SensorPower:
// //var sensor23 = new SensorPower ();
// //sensor23.SubnetID = subnetID;
// //sensor23.DeviceID = deviceID;
// //sensor23.LoopID = usefullBytes [2];
// //sensor23.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0');
// //sensor23.Enable = usefullBytes [23] == 1 ? true : false;
// //sensor23.CurrentPower = Convert.ToInt32(usefullBytes [24] * 256 + usefullBytes [25]);
// //IO.FileUtils.SaveEquipmentMessage (sensor23, sensor23.LoopID.ToString ());
// break;
// #endregion
// default:
// //DeviceLoopList.Add (new Common () { SubnetID = subnetID, DeviceID = deviceID });
// break;
// }
// MainPage.WriteLog ("ReadDeviceLoopInfoACK " + deviceType1);
// break;
// case Command.WriteWirelessPanelButtonKey:
// //01 01 59(+30) 02 0D 03 64 00 01
// break;
// case Command.AssignedAddressACK:
// MainPage.WriteLog (usefullBytes [0].ToString ());
// if (usefullBytes [0] == 3) {
// dt = DateTime.Now;
// } else if (usefullBytes [0] == 4) {
// dt = System.DateTime.MinValue;
// }
// break;
// case Command.Remote3thACK:
// MainPage.WriteLog (usefullBytes [0]);
// break;
// case Command.DownloadInfraredACK:
// string loopID_IM = usefullBytes [0] < 10 ? "0" + usefullBytes [0].ToString () : usefullBytes [0].ToString ();
// if ((InfraredType)usefullBytes [2] != InfraredType.AC) {
// if ((InfraredType)usefullBytes [2] == InfraredType.NULL) {
// MainPage.WriteLog ("NULL-------------");
// }
// string filePath = "Equipment_InfraredMode_" + subnetID + "_" + deviceID + "_" + loopID_IM;
// InfraredMode im = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (filePath)));
// im.InfraredType = (InfraredType)usefullBytes [2];
// MainPage.WriteLog (im.InfraredType.ToString () + "----------------------------------------");
// IO.FileUtils.SaveEquipmentMessage (im, im.LoopID.ToString ());
// }
// break;
// }
//} catch (Exception ex) {
// MainPage.WriteLog ("Packet_ReceiveEvent:" + ex.ToString ());
//}
}
///
/// byte 变字符串
///
/// The to hex16.
/// The blue component.
public static string byteToHex16 (byte b)
{
string s = Convert.ToString (b, 16).ToUpper ();
if (s.Length <= 1) {
return "0" + s;
}
return s;//
}
static void httpListener_EventHandler (System.Collections.Specialized.NameValueCollection nameValueCollection, System.IO.Stream outputStream, System.IO.Stream inputStream)
{
try {
if (nameValueCollection ["Command"] != null && nameValueCollection ["Command"].StartsWith ("Get")) {
string tempFileName = nameValueCollection ["Command"].Replace ("Get", "");
if ("AllFiles" == tempFileName) {
byte [] bytes = System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (MyIO.FileUtils.ReadFiles ()));
outputStream.Write (bytes, 0, bytes.Length);
outputStream.Flush ();
} else {
byte [] bytes;
if (!MyIO.FileUtils.Exists (tempFileName)) {
bytes = System.Text.Encoding.UTF8.GetBytes ("文件名不存在!");
outputStream.Write (bytes, 0, bytes.Length);
outputStream.Flush ();
return;
}
System.IO.FileStream fs = new System.IO.FileStream (Application.RootPath + tempFileName, System.IO.FileMode.Open);
bytes = new byte [fs.Length];
fs.Read (bytes, 0, bytes.Length);
fs.Close ();
outputStream.Write (bytes, 0, bytes.Length);
outputStream.Flush ();
}
} else if (nameValueCollection ["Command"].StartsWith ("Upload")) {
string path = Application.RootPath + nameValueCollection ["Command"].Replace ("Upload", "");
string dePath = nameValueCollection ["Command"].Replace ("Upload", "");
//if (dePath.Contains ("Room_")) {
// new Room ().Add (dePath);
//}
//if (dePath.Split ('_').Length == 5) {
// if (dePath.Split ('_') [1] == (typeof (OnePortBus).Name) || dePath.Split ('_') [1] == (typeof (OnePortWirelessFR).Name)) {
// UserConfig.Instance.RemoteModeFile = dePath;
// UserConfig.Instance.SaveUserConfig ();
// }
// if (dePath.Split ('_') [1] == (typeof (SecurityModul).Name)) {
// if (UserConfig.Instance.HideDeviceTypes.Contains ((InternationalizationString.Security))) {
// UserConfig.Instance.HideDeviceTypes.Remove (InternationalizationString.Security);
// UserConfig.Instance.SaveUserConfig ();
// }
// }
//}
//if (dePath.Split ('_').Length == 2 && dePath.StartsWith ("GlobalScene")) {
// var sceneFileList = Newtonsoft.Json.JsonConvert.DeserializeObject> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (Scene.GlobalSceneFilePath)));
// if (!sceneFileList.Contains (dePath)) {
// sceneFileList.Add (dePath);
// IO.FileUtils.WriteFileByBytes (Scene.GlobalSceneFilePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (sceneFileList)));
// }
//}
//FileUtils.WriteFileByInputStream (path, inputStream);
//Common common = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (path)));
//if (common.DeviceTextID == R.MyInternationalizationString.ElectricalControl) {
// UserConfig.Instance.SocketList.Add (common.CommonLoopID);
//}
} else {
byte [] bytes = System.Text.Encoding.UTF8.GetBytes ("请求命令无效!");
outputStream.Write (bytes, 0, bytes.Length);
outputStream.Flush ();
}
} catch (Exception ex) {
MainPage.Log ("httpListener_EventHandler" + ex.ToString ());
}
}
///
/// 随机数高位
///
public static byte RandomHigh;
///
/// 随机数低位
///
public static byte RandomLow;
///
/// 设备列表
///
public static System.Collections.Generic.List DeviceList = new System.Collections.Generic.List ();
///
/// 网关设备列表
///
public static System.Collections.Generic.List GateWayList = new System.Collections.Generic.List ();
///
/// 设备对应回路列表
///
public static System.Collections.Generic.List DeviceLoopList = new System.Collections.Generic.List ();
///
/// Updates Device's remake.
///
public static void UpdateRemark (byte subnetID, byte deviceID, string remark)
{
byte [] updateBytes = new byte [20];
byte [] remakeBytes = MyEncodingGB2312.GetBytes (remark);
Array.Copy (remakeBytes, 0, updateBytes, 0, remakeBytes.Length < 20 ? remakeBytes.Length : 20);
Control.ControlBytesSend (Command.UpdataRemake, subnetID, deviceID, updateBytes);
}
///
/// 监听请求的Http端口
///
public static int Port = 5555;
static void httpListener_EventHandler (string rawUrl, System.IO.Stream outputStream, System.IO.Stream inputStream)
{
foreach (var musicInfo in MusicInfo.MusicInfoList) {
if ("audio-item-" + musicInfo.ID == rawUrl.TrimStart ('/')) {
var file = new System.IO.FileStream (musicInfo.Data, System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte [] bytes = new byte [1024];
try {
while (file.CanRead) {
int len = file.Read (bytes, 0, bytes.Length);
if (len == 0) {
break;
}
outputStream.Write (bytes, 0, len);
}
} catch { }
file.Close ();
break;
}
}
}
}
}