using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using Newtonsoft.Json.Linq;
|
using Shared.IO;
|
using Shared.Net;
|
using Shared.SimpleControl.Phone;
|
|
namespace Shared.SimpleControl
|
{
|
public static class CommonPage
|
{
|
public static bool IsRemote;
|
public static Action RefreshAir;
|
public static bool FindGateway = false;
|
public static bool FindGatewayChilren = false;
|
public static string FindGatewayChilrenIPAddress = new Net.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 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 {
|
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) {
|
Console.WriteLine ("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;
|
}
|
/// <summary>
|
/// 初始化处理socket接收的数据
|
/// </summary>
|
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<byte> ButtonBkeyModelList = new List<byte> ();
|
switch (command) {
|
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.ReadLightSingleLoopBrightnessACK:
|
case Command.SetSingleLightACK:
|
Console.WriteLine ($"SetSingleLightACK {usefullBytes [2]}");
|
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.SubnetID == subnetID&& obj.DeviceID == deviceID);
|
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 -1) % 8;
|
var binaryString = Convert.ToString (usefullBytes [3 + useIndex], 2).PadLeft(8,'0').ToCharArray();
|
byte ackSceneBrightness = 100;
|
if (binaryString [7-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.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.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]) {
|
if (usefullBytes [1] != 0) {
|
(common as CurtainModel).Status = (CurtainStatus)usefullBytes [1];
|
common.obj5 = usefullBytes [1];
|
UserCurtainPage.UpdateStatus (common);
|
UserDeviceToCurtains.UpdateStata (common);
|
}
|
}
|
} else if (common.Type == DeviceType.CurtainRoller) {
|
if (usefullBytes [0] == 17) {
|
(common as CurtainRoller).CurtainProress = usefullBytes [1];
|
if (usefullBytes [1] > 0) {
|
(common as CurtainRoller).Status = CurtainStatus.Open;
|
} else {
|
(common as CurtainRoller).Status = CurtainStatus.Close;
|
}
|
} else {
|
if (usefullBytes [1] != 0) {
|
common.obj5 = usefullBytes [1];
|
(common as CurtainRoller).Status = (CurtainStatus)usefullBytes [1];
|
}
|
}
|
UserCurtainPage.UpdateStatus (common);
|
UserDeviceToCurtains.UpdateStata (common);
|
} else if (common.Type == DeviceType.CurtainTrietex) {
|
if (usefullBytes [0] == 17) {
|
(common as CurtainTrietex).CurtainProress = usefullBytes [1];
|
if (usefullBytes [1] > 0) {
|
(common as CurtainTrietex).Status = CurtainStatus.Open;
|
} else {
|
(common as CurtainTrietex).Status = CurtainStatus.Close;
|
}
|
} else {
|
if (usefullBytes [1] != 0) {
|
common.obj5 = usefullBytes [1];
|
(common as CurtainTrietex).Status = (CurtainStatus)usefullBytes [1];
|
}
|
}
|
UserCurtainPage.UpdateStatus (common);
|
UserDeviceToCurtains.UpdateStata (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 (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.Console.WriteLine ("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)
|
{
|
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.Type == DeviceType.ACPanel) {
|
var tempAC = common as ACPanel;
|
tempAC.IndoorTemperature = usefullBytes [1];
|
UserACPage.UpdateIndoorTemp (common.CommonLoopID, usefullBytes [1]);
|
} else if (common.Type == DeviceType.FoolHeatPanel) {
|
var tempFH22 = common as FoolHeatPanel;
|
tempFH22.IndoorTemperature = usefullBytes [1];
|
UserFHPage.UpdateIndoorTemp (tempFH22.CommonLoopID, 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
|
}
|
} catch (Exception ex) {
|
Console.WriteLine ("Packet_ReceiveEvent:" + ex.ToString ());
|
}
|
|
}
|
/// <summary>
|
/// byte 变字符串
|
/// </summary>
|
/// <returns>The to hex16.</returns>
|
/// <param name="b">The blue component.</param>
|
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<string> list = new List<string> ();
|
//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.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 ((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<List<string>> (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<Common> (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 ());
|
}
|
}
|
|
/// <summary>
|
/// 随机数高位
|
/// </summary>
|
public static byte RandomHigh;
|
/// <summary>
|
/// 随机数低位
|
/// </summary>
|
public static byte RandomLow;
|
|
/// <summary>
|
/// 设备列表
|
/// </summary>
|
public static System.Collections.Generic.List<Common> DeviceList = new System.Collections.Generic.List<Common> ();
|
/// <summary>
|
/// 网关设备列表
|
/// </summary>
|
public static System.Collections.Generic.List<Common> GateWayList = new System.Collections.Generic.List<Common> ();
|
/// <summary>
|
/// 设备对应回路列表
|
/// </summary>
|
public static System.Collections.Generic.List<Common> DeviceLoopList = new System.Collections.Generic.List<Common> ();
|
|
/// <summary>
|
/// Updates Device's remake.
|
/// </summary>
|
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);
|
}
|
|
/// <summary>
|
/// 监听请求的Http端口
|
/// </summary>
|
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;
|
}
|
}
|
}
|
}
|
}
|