using System; using Shared.Net; using Shared.IO; using System.Text; using System.Collections.Generic; using Shared.SimpleControl.Phone; using service.hdlcontrol.com_WebServiceAirQuality; namespace Shared.SimpleControl { public static class CommonPage { public static AirQuality AirQuality; public static Action RefreshAir; public static bool IsRemote = false; public static bool FindGateway = false; public static bool FindGatewayChilren = false; public static string FindGatewayChilrenIPAddress = new Net.NetWiFi ().BroadcastIpAddress.ToString (); public static bool LocalPhoneFindDevice = false; public static int searchTotal = 0; public static int newDevice = 0; private static string ip="0.0.0.0"; public static System.Net.IPEndPoint EndPoint { get { try { if (IsRemote) { //127.0.0.1 if (ip == "0.0.0.0") { try { ip = System.Net.Dns.GetHostEntry ("homeautomation.havells.com").AddressList [0].ToString (); } catch { } } return new System.Net.IPEndPoint (System.Net.IPAddress.Parse (ip), 9999); } else { if (FindGateway) { //return new System.Net.IPEndPoint (System.Net.IPAddress.Parse (new Net.NetWiFi ().BroadcastIpAddress.ToString ()), 6000); return new System.Net.IPEndPoint (System.Net.IPAddress.Parse ("224.0.168.188"), 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 Net.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 = 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; } 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 object lockobj = new object (); static void Packet_ReceiveEvent (byte subnetID, byte deviceID, Command command, byte [] usefullBytes) { try { List ButtonBkeyModelList = new List (); switch (command) { case Command.PushtoServer_DevMsg: #if DEBUG string pushBytesString = "PushtoServer_DevMsg : " + subnetID + "," + deviceID + ","; foreach (var bin in usefullBytes) { pushBytesString += bin + ","; } Console.WriteLine (pushBytesString); #endif if (DeviceList.Find ((l) => { return l.SubnetID == subnetID && l.DeviceID == deviceID; }) != null) { return; } bool noRemake = false; for (int ki = 0; ki < 20; ki++) { if (usefullBytes [10 + ki] != 255) { break; } else { noRemake = true; } } for (int i = 30; i < usefullBytes.Length; i += 3) { if (usefullBytes [i + 2] == 0) { continue; } DeviceType deviceType_wireless = (DeviceType)(usefullBytes [i] * 256 + usefullBytes [i + 1]); Console.WriteLine (deviceType_wireless.ToString ()); if (noRemake || MyEncodingGB2312.GetString (usefullBytes, 2, 20).Trim ('\0') == "") { byte [] ddd = CommonPage.MyEncodingGB2312.GetBytes (deviceType_wireless.ToString () + "-" + subnetID.ToString () + "-" + deviceID.ToString ()); byte [] newddd = new byte [20]; Array.Copy (ddd, 0, newddd, 0, 20 < ddd.Length ? 20 : ddd.Length); Array.Copy (newddd, 0, usefullBytes, 3, 20 < newddd.Length ? 20 : newddd.Length); } if (deviceType_wireless.ToString () == (usefullBytes [i] * 256 + usefullBytes [i + 1]).ToString ()) { continue; } if (deviceType_wireless == DeviceType.MusicModel || deviceType_wireless == DeviceType.MusicPanel) { continue; } Common common = new Common () { SubnetID = subnetID, DeviceID = deviceID, Name = MyEncodingGB2312.GetString (usefullBytes, 10, 20).Trim ('\0'), Type = deviceType_wireless, LoopCount = usefullBytes [i + 2], }; common.MAC = byteToHex16 (usefullBytes [2]) + "." + byteToHex16 (usefullBytes [3]) + "." + byteToHex16 (usefullBytes [4]) + "." + byteToHex16 (usefullBytes [5]) + "." + byteToHex16 (usefullBytes [6]) + "." + byteToHex16 (usefullBytes [7]) + "." + byteToHex16 (usefullBytes [8]) + "." + byteToHex16 (usefullBytes [9]); DeviceList.Add (common); if (i > 33) { common.isMixBox = true; } else { Application.RunOnMainThread (() => { GuideSettingGateway.InitSearchDeviceList (common, true); }); } IO.FileUtils.SaveEquipmentMessage (common); } 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]; 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: for (byte i = 1; i <= usefullBytes [0]; i++) { foreach (var room in Room.Lists) { var 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; bool updateLightStatus = true; if (common.Type == DeviceType.LightSwitch || common.Type == DeviceType.LightEnergySwitch || common.Type == DeviceType.LightSwitchSocket || common.Type == DeviceType.LightEnergySocket) { 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.LightMixSwitch) { if ((common as LightMixSwitch).CurrentBrightness == usefullBytes [i]) { updateLightStatus = false; } (common as LightMixSwitch).CurrentBrightness = usefullBytes [i]; } else if (common.Type == DeviceType.LightMixDimming) { if ((common as LightMixDimming).CurrentBrightness == usefullBytes [i]) { updateLightStatus = false; } (common as LightMixDimming).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: Console.WriteLine ("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) { 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) { (common as FanModule).Switch = 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]; } else if (common.Type == DeviceType.LightEnergySwitch) { if ((common as LightEnergySwitch).CurrentBrightness == usefullBytes [2]) hadBeUpdate = false; (common as LightEnergySwitch).CurrentBrightness = usefullBytes [2]; } else if (common.Type == DeviceType.LightEnergySocket) { if ((common as LightEnergySocket).CurrentBrightness == usefullBytes [2]) hadBeUpdate = false; (common as LightEnergySocket).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 { if (!string.IsNullOrEmpty (room.Name)) UserDeviceToLight.UpdateBrighingCount (updateFlag); if (hadBeUpdate) { UserRoom.UpdataDeviceStatus (common); UserLightPage.UpdateStatus (updateFlag, usefullBytes [2]); UserDeviceToLight.UpdateStatus (updateFlag, usefullBytes [2]); UserDeviceToFan.UpdataStatus (updateFlag, usefullBytes [2]); UserDeviceToSocket.UpdateStatus (updateFlag, usefullBytes [2]); } if (common.Type == DeviceType.FanModule) { UserRoom.UpdataDeviceStatus (common); UserFan.UpdataFanView (updateFlag, usefullBytes [2]); } } } } 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.LightEnergySocket || common.Type == DeviceType.LightEnergySwitch) { string updateFlag = common.CommonLoopID; if (usefullBytes [0] == 10) { UserDeviceToSocket.UpdataEnergy (usefullBytes [0], updateFlag, usefullBytes [2] * 256 + usefullBytes [3]); UserDeviceToLight.UpdataEnergy (usefullBytes [0], updateFlag, usefullBytes [2] * 256 + usefullBytes [3]); UserRoom.UpdataEnergy (usefullBytes [0], common.Type + "_" + updateFlag, usefullBytes [2] * 256 + usefullBytes [3]); break; } else if (usefullBytes [0] == 11) { UserDeviceToSocket.UpdataEnergy (usefullBytes [0], updateFlag, usefullBytes [2] * 256 * 256 * 256 + usefullBytes [3] * 256 * 256 + usefullBytes [4] * 256 + usefullBytes [5]); UserDeviceToLight.UpdataEnergy (usefullBytes [0], updateFlag, usefullBytes [2] * 256 * 256 * 256 + usefullBytes [3] * 256 * 256 + usefullBytes [4] * 256 + usefullBytes [5]); UserRoom.UpdataEnergy (usefullBytes [0], common.Type + "_" + updateFlag, usefullBytes [2] * 256 * 256 * 256 + usefullBytes [3] * 256 * 256 + usefullBytes [4] * 256 + usefullBytes [5]); 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.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 (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": //当前播放歌曲名 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; } 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.Console.WriteLine ("DISPMODE=====" + music.playMode); } break; } } } break; #endregion #region 空调 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 ) { 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.UpdateStatus (tempAC); } else if (common.Type == DeviceType.FoolHeatPanel) { var tempFH22 = common as FoolHeatPanel; tempFH22.IndoorTemperature = usefullBytes [1]; UserFHPage.UpdateStatus (tempFH22); } } } } 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]; break; case 4: ac.SetTemperature = usefullBytes [1]; ac.CoolTemperature = usefullBytes [1]; break; case 5: ac.SetFanSpeed = usefullBytes [1]; break; case 6: ac.SetMode = usefullBytes [1]; break; case 7: ac.SetTemperature = usefullBytes [1]; ac.HeatTemperature = usefullBytes [1]; break; case 8: ac.SetTemperature = usefullBytes [1]; ac.AutoTemperature = usefullBytes [1]; break; case 19: ac.SetTemperature = usefullBytes [1]; ac.ChuShiTemperature = usefullBytes [1]; 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]; break; case 21: fh.TemperatureType = usefullBytes [1]; break; case 25: fh.NormalTemperature = usefullBytes [1]; fh.WorkingTemperature = usefullBytes [1]; break; case 26: fh.DayTemperature = usefullBytes [1]; fh.WorkingTemperature = usefullBytes [1]; break; case 27: fh.NightTemperature = usefullBytes [1]; fh.WorkingTemperature = usefullBytes [1]; break; case 28: fh.AwayTemperature = usefullBytes [1]; fh.WorkingTemperature = usefullBytes [1]; break; } if (Application.IsPad) { //SimpleControl.Pad.UserFHPage.UpdateStatus (fh); } else { UserDeviceToFH.UpdateStatus (fh); UserFHPage.UpdateStatus (fh); UserRoom.UpdataDeviceStatus (fh); } } } } break; //case Command.ReadACPanelStatusACK: //byte acpanelLoopId = 0; // if (usefullBytes.Length == 10) { // acpanelLoopId = 1; //} else if (usefullBytes.Length == 11) { // acpanelLoopId = usefullBytes [10]; //} //foreach (var room in Room.Lists) { // foreach (var common in room.DeviceList) { // if (common.SubnetID != subnetID || common.DeviceID != deviceID || common.LoopID != acpanelLoopId) { // 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) { // Pad.UserACPage.UpdateStatus (ac); // } else { // UserACPage.UpdateStatus (ac); // UserDeviceToAC.UpdateStatus (ac); // UserRoom.UpdataDeviceStatus (ac); // } // } //} //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 (newddd, 0, usefullBytes, 13, 20 < newddd.Length ? 20 : newddd.Length); } switch (deviceType) { case DeviceType.SuperWireless: #region SuperWireless superWireless = new SuperWireless (); string superWirelessPath = "Equipment_" + typeof (OnePortWirelessFR).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.ChNumberCount = usefullBytes [4]; 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 = usefullBytes [41] + "." + usefullBytes [42] + "." + 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.ChNumberCount = usefullBytes [4]; 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 = usefullBytes [41] + "." + usefullBytes [42] + "." + 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 (); } Application.RunOnMainThread (() => { GuideAddGateway.InitGatewayRowView (onePortWirelessFR); }); //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 = usefullBytes [41] + "." + usefullBytes [42] + "." + 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 (); } Application.RunOnMainThread (() => { GuideAddGateway.InitGatewayRowView (onePortBus); }); //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 = usefullBytes [41] + "." + usefullBytes [42] + "." + 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 = usefullBytes [41] + "." + usefullBytes [42] + "." + 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; } //GuideAddGateway.InitGatewayRowView (new Common () { // SubnetID = subnetID, DeviceID = deviceID, Name = MyEncodingGB2312.GetString (usefullBytes, 13, 20).Trim ('\0') //}); break; //读取非网络设备回复 case Command.ReadDeviceModulACK: if (!LocalPhoneFindDevice) {//r如果不是本机在查找设备 break; } 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; } } int iReadDeviceModulACK = 22; for (; iReadDeviceModulACK < usefullBytes.Length; iReadDeviceModulACK += 3) { if (usefullBytes.Length < iReadDeviceModulACK + 2 || usefullBytes [iReadDeviceModulACK + 2] == 0) { continue; } deviceType = (DeviceType)(usefullBytes [iReadDeviceModulACK] * 256 + usefullBytes [iReadDeviceModulACK + 1]); Console.WriteLine (deviceType.ToString ()); string devcieTempName = MyEncodingGB2312.GetString (usefullBytes, 2, 20).Trim ('\0'); if (notHasRemake || MyEncodingGB2312.GetString (usefullBytes, 2, 20).Trim ('\0') == "") { devcieTempName = deviceType.ToString ().Replace (DeviceType.Sensor.ToString (), "") + "-" + deviceID.ToString (); byte [] ddd = CommonPage.MyEncodingGB2312.GetBytes (devcieTempName); //Array.Copy (ddd, 0, usefullBytes, 2, 20 < ddd.Length ? 20 : ddd.Length); //byte [] ddd = CommonPage.MyEncodingGB2312.GetBytes (deviceType_wireless.ToString () + "-" + subnetID.ToString () + "-" + deviceID.ToString ()); byte [] newddd = new byte [20]; Array.Copy (ddd, 0, newddd, 0, 20 < ddd.Length ? 20 : ddd.Length); Array.Copy (newddd, 0, usefullBytes, 3, 20 < newddd.Length ? 20 : newddd.Length); } if (deviceType.ToString () == (usefullBytes [iReadDeviceModulACK] * 256 + usefullBytes [iReadDeviceModulACK + 1]).ToString ()) { continue; } //if (deviceType == DeviceType.MusicModel || deviceType == DeviceType.MusicPanel) {//|| deviceType == DeviceType.LogicModule) {// || deviceType == DeviceType.FoolHeat){// ||deviceType == DeviceType.InfraredMode) { // continue; //} Common common = new Common () { SubnetID = subnetID, DeviceID = deviceID, Name = MyEncodingGB2312.GetString (usefullBytes, 2, 20).Trim ('\0'), Type = deviceType, LoopCount = usefullBytes [iReadDeviceModulACK + 2], }; if (1 == (usefullBytes.Length - 22) % 3) { common.Online = usefullBytes [usefullBytes.Length - 1] == 1; } DeviceList.Add (common); if (iReadDeviceModulACK > 24) { common.isMixBox = true; } else { Application.RunOnMainThread (() => { MainPage.Loading.Start ("Search for device:" + devcieTempName); ++searchTotal; GuideSettingGateway.InitSearchDeviceList (common); for (int k = 1; k <= common.LoopCount; k++) { Control.ControlBytesSend (Command.ReadDeviceLoopInfo, common.SubnetID, common.DeviceID, new byte [] { common.BigClass, common.MinClass, (byte)k }); } }); } IO.FileUtils.SaveEquipmentMessage (common); } break; //设备对应回路 case Command.ReadDeviceLoopInfoACK: if (!LocalPhoneFindDevice) {//r如果不是本机在查找设备 break; } 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; } } if (notHasRemake2 || MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0') == "") { var devcieLoopName = deviceType1.ToString () + "-" + subnetID.ToString () + "-" + deviceID.ToString () + "-" + usefullBytes [2].ToString (); //if (deviceType1.ToString ().Contains ("Dimming")) { // devcieLoopName = "Dimmer SW" + usefullBytes [2].ToString (); //} else if (deviceType1.ToString ().Contains ("Switch")) { // devcieLoopName = "Relay SW" + usefullBytes [2].ToString (); //} byte [] ddd = CommonPage.MyEncodingGB2312.GetBytes (devcieLoopName); byte [] newddd = new byte [20]; Array.Copy (ddd, 0, newddd, 0, 20 < ddd.Length ? 20 : ddd.Length); Array.Copy (newddd, 0, usefullBytes, 3, 20 < newddd.Length ? 20 : newddd.Length); } if (null != DeviceLoopList.Find ((common) => { return common.Type == deviceType1 && common.SubnetID == subnetID & common.DeviceID == deviceID && common.LoopID == usefullBytes [2]; })) { //存在当前设备就返回 return; } switch (deviceType1) { 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 = MyEncodingGB2312.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 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]; lightDALI.LinkLightStatus = usefullBytes [25]; lightDALI.CurrentBrightness = usefullBytes [26]; lightDALI.DALIModule = true; //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.LightEnergySocket: #region var lightEnergySocket = new LightEnergySocket (); lightEnergySocket.SubnetID = subnetID; lightEnergySocket.DeviceID = deviceID; lightEnergySocket.LoopID = usefullBytes [2]; lightEnergySocket.Name = MyEncodingGB2312.GetString (usefullBytes, 3, 20).Trim ('\0'); lightEnergySocket.CurrentBrightness = usefullBytes [23]; //if (UserConfig.Current.SocketList.Contains (lightEnergySwitch.CommonLoopID)) { // lightEnergySwitch.Type = DeviceType.LightSwitchSocket; // lightEnergySwitch.DeviceTextID = SimpleControl.R.MyInternationalizationString.ElectricalControl; //} DeviceLoopList.Add (lightEnergySocket); IO.FileUtils.SaveEquipmentMessage (lightEnergySocket, lightEnergySocket.LoopID.ToString ()); #endregion break; case DeviceType.LightEnergySwitch: 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 ()); 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]; 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.Console.WriteLine ("读取面板按键:回路号:" + 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.InfraredType = InfraredType.TV; 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; } break; //case Command.ReadFoolHeatACK: //1地热号,2工作模式,3温度模式,4模式,5正常模式温度点,6白天模式温度点,7夜晚模式温度,8离开模式温度,9时间轴(0白天、1夜晚) //10开关,11PWD值,12冲洗标志,13冲洗时间 //string equipment = "Equipment_" + DeviceType.FoolHeat.ToString () + "_" + subnetID.ToString () + "_" + deviceID.ToString () + "_" + usefullBytes [0].ToString (); //byte [] usefullBytes1 = IO.FileUtils.ReadFile (equipment); //var localFileForClick = CommonPage.MyEncodingUTF8.GetString (usefullBytes1); //FoolHeat th = Newtonsoft.Json.JsonConvert.DeserializeObject (localFileForClick); //th.SubnetID = subnetID; //th.DeviceID = deviceID; //th.LoopID = usefullBytes [0]; //th.WorkingModel = usefullBytes [1]; //th.WorkingModelTemperature = usefullBytes [2]; //th.Mode = usefullBytes [3]; //th.NightTemperature = usefullBytes [4]; //th.DayTemperature = usefullBytes [5]; //th.NightTemperature = usefullBytes [6]; //th.AwayTemperature = usefullBytes [7]; //th.Timer = usefullBytes [8]; //th.VavleStatus = usefullBytes [9]; //th.PWDValue = usefullBytes [10]; //th.WateringFlag = usefullBytes [11]; //th.WateringTime = usefullBytes [12]; //IO.FileUtils.SaveEquipmentMessage (th, th.LoopID.ToString ()); //break; case Command.WriteWirelessPanelButtonKey: //01 01 59(+30) 02 0D 03 64 00 01 break; case Command.AssignedAddressACK: Console.WriteLine (usefullBytes [0].ToString ()); if (usefullBytes [0] == 3) { dt = DateTime.Now; } else if (usefullBytes [0] == 4) { dt = System.DateTime.MinValue; } break; case Command.Remote3thACK: Console.WriteLine (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) { Console.WriteLine ("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]; Console.WriteLine (im.InfraredType.ToString () + "------------------------------------------------------"); IO.FileUtils.SaveEquipmentMessage (im, im.LoopID.ToString ()); } break; } } catch (Exception ex) { Console.WriteLine ("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) { //if (!isHttpListenerStart) { // return; //} try { //System.Net.WebClient webClient = new System.Net.WebClient (); //byte []bytes= webClient.DownloadData("http://ip:6001/GetAllFiles"); // System.Text.Encoding.UTF8.GetString (bytes); //List list = new List (); //foreach(string s in list) { // byte [] bytes = webClient.DownloadData ("http://ip:6001/Get"+s); // FileUtils.WriteFileByBytes (s, bytes); //} 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 (IO.FileUtils.ReadFiles ())); outputStream.Write (bytes, 0, bytes.Length); outputStream.Flush (); } else { byte [] bytes; if (!IO.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.StartsWith ("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 ((R.MyInternationalizationString.Security))) { UserConfig.Instance.HideDeviceTypes.Remove (R.MyInternationalizationString.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) { Console.WriteLine ("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; } } } } }