using System;
|
using System.Collections.Generic;
|
using System.Net.Sockets;
|
using System.Text;
|
using HDL_ON.DAL;
|
using HDL_ON.DAL.Net;
|
using HDL_ON.Entity;
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using Shared;
|
using Shared.Net;
|
|
namespace HDL_ON
|
{
|
public partial class Control
|
{
|
public DateTime LatestDateTime = DateTime.Now;
|
/// <summary>
|
/// 控制失败次数
|
/// </summary>
|
public static int controlLostCount = 0;
|
|
/// <summary>
|
/// 所有微信对一端口的控制都会放到这个集合里
|
/// </summary>
|
private static List<Control> controlList = new List<Control>(50);
|
|
/// <summary>
|
/// 发送数据,不需要等待回复
|
/// </summary>
|
public static void ControlBytesSend(Command command, byte subnetID, byte deviceID, byte[] gatewayBytes, int sendCount = 3, System.Net.IPEndPoint ipEndpoint = null)
|
{
|
Control control = new Control();
|
control.Send(new Target()
|
{
|
IPEndPoint = ipEndpoint == null ? CommonPage.EndPoint : ipEndpoint,
|
Command = command,
|
SubnetID = subnetID,
|
DeviceID = deviceID,
|
AddData = gatewayBytes,
|
}, sendCount, false);
|
MainPage.Log(command.ToString() + "::" + CommonPage.EndPoint.ToString());
|
}
|
|
public static byte[] ReadGatewayIPAddress()
|
{
|
Control control = new Control();
|
control.ReadGatewayIP();
|
return control.UsefulBytes;
|
}
|
|
static DAL.Net.TcpListener tcpListener;
|
|
/// <summary>
|
/// 000E 搜索回复
|
/// </summary>
|
/// <param name="usefullBytes"></param>
|
static void ReceiveReadRemark(byte[] usefullBytes)
|
{
|
try
|
{
|
//账号没登录不回复
|
if (MainPage.LoginUser == null || !MainPage.LoginUser.IsLogin)
|
{
|
return;
|
}
|
|
if (tcpListener == null)
|
{
|
tcpListener = new DAL.Net.TcpListener();
|
tcpListener.OpenServer(8586);
|
}
|
|
//if (!CommonPage.isHttpListenerStart)
|
//{
|
// //数据接收端口没打开,不回复
|
// CommonPage.InitHttpListener();
|
//}
|
var sendStr = MainPage.LoginUser.accountString;
|
if (usefullBytes.Length == 0)
|
{
|
SenRemark(sendStr);
|
}
|
else
|
{
|
bool isExit = false;
|
|
for (int i = 0, len = usefullBytes.Length; i < len; i++)
|
{
|
if (i % 2 == 0)
|
{
|
if ((usefullBytes[i] & 0xFF) == 252
|
&& (usefullBytes[i + 1] & 0xFF) == 252)
|
{
|
isExit = true;
|
break;
|
}
|
}
|
}
|
|
if (!isExit)
|
{
|
//不存在,代表没收到本机的发送,继续回复
|
SenRemark(sendStr);
|
}
|
|
}
|
|
}
|
catch { }
|
}
|
|
/// <summary>
|
/// 000F回复备注
|
/// </summary>
|
/// <param name="sendStr"></param>
|
static void SenRemark(string sendStr)
|
{
|
byte[] sendBytes = new byte[20];
|
byte[] b1 = CommonPage.MyEncodingGB2312.GetBytes(sendStr);
|
//Remote_GroupName = CommonPage.MyEncodingGB2312.GetString (b1);
|
Array.Copy(b1, 0, sendBytes, 0, 20 < b1.Length ? 20 : b1.Length);
|
|
var control = new Control();
|
control.Send(new Target()
|
{
|
IPEndPoint = CommonPage.EndPoint,
|
Command = Command.ReadRemarkACK,
|
SubnetID = 0xFF,
|
DeviceID = 0xFF,
|
AddData = sendBytes,
|
}, 0, false); //设置当前发送指令方式为:任何情况下本地发送、不限制、不加密明文发送
|
}
|
/// <summary>
|
/// 处理接收回来的数据
|
/// </summary>
|
/// <param name="subnetID">源子网号</param>
|
/// <param name="deviceID">源设备号</param>
|
/// <param name="command">操作码</param>
|
/// <param name="usefulBytes">有用的数据</param>
|
/// <param name="remoteEndPoint">源网络套接字</param>
|
public static void ManagerReceive(byte subnetID, byte deviceID, Command command, byte targetSubnetID, byte targetDeviceID, byte[] usefulBytes, System.Net.EndPoint remoteEndPoint)
|
{
|
if (((System.Net.IPEndPoint)remoteEndPoint).Port == 6688)
|
{
|
|
for (int i = 0; i < controlList.Count; i++)
|
{
|
try
|
{
|
var control = controlList[i];
|
control.LatestDateTime = DateTime.Now;
|
control.UsefulBytes = usefulBytes;//
|
control.run();
|
}
|
catch (Exception ex)
|
{
|
Console.WriteLine($"control error : {ex.Message}");
|
}
|
}
|
}
|
|
try
|
{
|
string receiveFlag = string.Format("{0},{1},{2},", subnetID, deviceID, (int)command);
|
|
switch (command)
|
{
|
case Command.SetSingleLightACK:
|
receiveFlag += string.Format("{0}", usefulBytes[0]);
|
break;
|
case Command.SetLogicLoopColorACK:
|
receiveFlag += string.Format("{0},{1},{2}", usefulBytes[0], usefulBytes[1], usefulBytes[2]);
|
break;
|
case Command.ReadLogicLoopColorACK:
|
case Command.ReadACModeACK:
|
case Command.SetACModeACK:
|
case Command.ReadFloorHeatACK:
|
case Command.SetFloorHeatACK:
|
receiveFlag += string.Format("{0}", usefulBytes[0]);
|
break;
|
case Command.ReadRemark:
|
//buspro 读备注回复
|
Console.WriteLine("buspro 读备注回复");
|
ReceiveReadRemark(usefulBytes);
|
break;
|
case Command.ReadLightAllLoopBrightnessACK:
|
receiveFlag += "";
|
break;
|
//case Command.YIPanelDeviceInofACK:
|
// for (int i = 0; i < 4; i++)
|
// {
|
// receiveFlag += string.Format("{0}", usefulBytes[i]);
|
// }
|
// break;
|
//case Command.ReadDoorLockSceneObjACK:
|
// receiveFlag += string.Format("{0},{1},{2},{3},{4}", usefulBytes[0], usefulBytes[1], usefulBytes[2], usefulBytes[3], usefulBytes[4]);
|
// break;
|
//case Command.ReadDoorLockClockACK:
|
//case Command.CreatConnectionACK:
|
// receiveFlag += string.Format("{0}", usefulBytes[0]);
|
// break;
|
////门锁,BroadcastDoorLockStateAndAlarm
|
////广播门锁状态和报警,
|
//case Command.BroadcastDoorLockStateAndAlarm://广播门锁状态和报警
|
// receiveFlag += string.Format("{0},{1}", usefulBytes[0], usefulBytes[1]);
|
// break;
|
//case Command.ReadDoorLockUseRemarkACK:
|
//case Command.ReadSensorPushMessageACK:
|
//case Command.SetSensorPushMessageACK:
|
//case Command.ReadSensorScenceACK:
|
//case Command.ReadAnalogACK:
|
// receiveFlag += string.Format("{0},{1},{2}", usefulBytes[0], usefulBytes[1], usefulBytes[2]);
|
// break;
|
//case Command.SetSensorScenceACK:
|
// receiveFlag += string.Format("{0},{1},{2}", usefulBytes[1], usefulBytes[2], usefulBytes[3]);
|
// break;
|
//case Command.SendRemoteInfoToServerACK:
|
// for (int i = 1; i < 9; i++)
|
// {
|
// receiveFlag += string.Format("{0}", usefulBytes[i]);
|
// }
|
// break;
|
//case Command.BroadcastDryContactStatus://由干接点广播出来的数据,程序不做回复。
|
// receiveFlag += string.Format("{0}", usefulBytes[0]);
|
// break;
|
//case Command.SetSceneACK:
|
// receiveFlag += string.Format("{0},{1}", usefulBytes[0], usefulBytes[1]);
|
// break;
|
//case Command.SetSeriesACK:
|
// receiveFlag += string.Format("{0},{1}", usefulBytes[0], usefulBytes[1]);
|
// break;
|
//case Command.SetCurtainModelStutasACK:
|
//case Command.SetHotelCurtainACK:
|
//case Command.DownloadInfraredACK:
|
//case Command.SetSensorPushValuesACK:
|
//case Command.ReadSensorPushValuesACK:
|
// receiveFlag += string.Format("{0},{1}", usefulBytes[0], usefulBytes[1]);
|
// break;
|
//case Command.UpLoadInfraredACK:
|
// receiveFlag += string.Format("{0},{1}", usefulBytes[0], usefulBytes[1]);
|
// break;
|
//case Command.SetCommonACK:
|
//case Command.InfraredChannelControlACK:
|
//case Command.Serverx_FH_CMD_ACK:
|
//case Command.ReadSensorHistoryACK:
|
//case Command.SetSensorAutomationTargetLevelEnableACK:
|
//case Command.ReadSensorAutomationLevelTargetEnableACK:
|
// receiveFlag += string.Format("{0}", usefulBytes[0]);
|
// break;
|
//case Command.ReadFoolHeatACK:
|
//case Command.SetFoolHeatACK:
|
//case Command.SetArmACK:
|
//case Command.ReadArmACK:
|
// receiveFlag += string.Format("{0}", usefulBytes[0]);
|
// break;
|
//case Command.ReadDeviceModulACK:
|
//case Command.ReadGatewayACK:
|
//case Command.ReadSecurityStatusACK:
|
// receiveFlag = string.Format("{0},{1}", usefulBytes[0], usefulBytes[1]);
|
// break;
|
//case Command.UpdataLightDimmingTheLargestLevelACK:
|
//case Command.UpdataLightDimmingMaximumOrMinimumACK:
|
//case Command.WriteManageWirelessNetACK:
|
//case Command.ReadGateWayModelInfoACK:
|
//case Command.ReadGatewayServerIPACK:
|
//case Command.SetGateWayModelInfoACK:
|
//case Command.SetGateWayModelInternetInfoACK:
|
//case Command.ReadDeviceMacACK:
|
//case Command.SetDeviceSubnetIDACK:
|
//case Command.PositioningEquipmentACK:
|
//case Command.PositioningPanelACK:
|
//case Command.GotoConfigModeACK:
|
//case Command.CheckConfigSuccessACK:
|
//case Command.SetACPanelACK:
|
//case Command.ReadACPanelACK:
|
//case Command.ReadTerrestriaHeatRemarkACK:
|
//case Command.UpdateGatewayIpACK:
|
//case Command.ReadWirelessPanelModeACK:
|
//case Command.ReadDrycontactModeACK:
|
//case Command.ReadACFloorHeatingSettingEquipmentACK:
|
//case Command.SetACFloorHeatingSettingEquipmentACK:
|
//case Command.Read43FloorHeatingSettingEquipmentACK:
|
//case Command.Set43FloorHeatingSettingEquipmentACK:
|
//case Command.READ_AIR_ALL_Parameter_ack:
|
//case Command.Set_AIR_ALL_Parameter_ack:
|
//case Command.ReadFloorHeatProbeACK:
|
//case Command.ReadButtonKeyEnableACK:
|
//case Command.UpdateLightDimmingLoopRemakeACK:
|
//case Command.ReadMusicPanelSettingACK:
|
//case Command.ReadMusicPanelEnableACK:
|
//case Command.SetMusicPanelEnableACK:
|
//case Command.SetMusicPanelSettingACK:
|
//case Command.SetGatewayACK:
|
//case Command.ReadGatewayProgrammingModeACK:
|
//case Command.RED_HSFH_TOTAL_ACK:
|
//case Command.RED_HSFH_INFORMATION_ACK:
|
//case Command.RED_HSRM_TOTAL_ACK:
|
//case Command.RED_HSRM_INFORMATION_ACK:
|
//case Command.CLEAR_SYSTEM_HISTORY_ACK:
|
//case Command.SetSensorTargetRemarkACK:
|
//case Command.ReadSensorAutomationEnableListACK:
|
//case Command.SetSensorAutomationEnableListACK:
|
//case Command.SetSensorAutomationListIDACK:
|
//case Command.ReadSensorAutomationListIDACK:
|
//case Command.ReadSensorAutomationNameACK:
|
//case Command.SetSensorAutomationNameACK:
|
//case Command.Set_Floor_Heat_State_ack:
|
//case Command.Read_Floor_Heat_State_ack:
|
//case Command.Read_Air_Condition_Set_ack:
|
//case Command.HornAlarmBroadcast:
|
//case Command.ReadHornLoopCountACK:
|
//case Command.UpdateHornLoopRemakeACK:
|
//case Command.ReadPanelTempTypeACK:
|
// receiveFlag += "";
|
// break;
|
//case Command.ControlMusicModel1ACK:
|
// receiveFlag += "";
|
// break;
|
//case Command.ControlMusicModel2ACK:
|
// for (int i = 1; i < usefulBytes.Length; i++)
|
// {
|
// if (usefulBytes[i + 1] == 44)
|
// {
|
// break;
|
// }
|
// receiveFlag += string.Format("{0},", usefulBytes[i]);
|
// }
|
// break;
|
|
//case Command.Remote3thACK:
|
// receiveFlag = string.Format("{0},", (int)command);
|
// break;
|
case Command.ReadDeviceLoopInfoACK:
|
if (usefulBytes[0] == 1)
|
{
|
receiveFlag += string.Format("{0},{1}", usefulBytes[0], usefulBytes[2]); ;
|
}
|
else
|
receiveFlag += string.Format("{0},{1},{2}", usefulBytes[0], usefulBytes[1], usefulBytes[2]);
|
break;
|
//case Command.SetDeviceLoopInfoACK:
|
//case Command.InfraredControlACK:
|
//case Command.SetSecurityByPassACK:
|
//case Command.SetSensorAutomationDateTimeCycleACK:
|
//case Command.ReadSensorAutomationDateTimeCycleACK:
|
// receiveFlag += string.Format("{0},{1},{2}", usefulBytes[0], usefulBytes[1], usefulBytes[2]);
|
// break;
|
//case Command.UpdataRemakeACK:
|
// break;
|
//case Command.ReadWirelessPanelButtonKeyACK:
|
//case Command.WriteWirelessPanelButtonKeyACK:
|
//case Command.ReadDryContactStatusACK:
|
case Command.InstructionPanelKeyACK:
|
case Command.ReadInstructionPanelKeyACK:
|
//case Command.ReadAnalogValueACK:
|
//case Command.ReadSensorTargetRemarkACK:
|
//case Command.SetHornTargetStateACK:
|
//case Command.ReadHornTargetStateACK:
|
receiveFlag += string.Format("{0},{1}", usefulBytes[0], usefulBytes[1]);
|
break;
|
//case Command.AssignedAddressACK:
|
//case Command.UpdataCurtainModelRunTimeACK:
|
//case Command.ReadCurtainStutasACK:
|
//case Command.ReadPanleTempACK:
|
//case Command.FreshAirReadACK:
|
//case Command.FreshAirControlACK:
|
//case Command.Set_Air_State_New_ack:
|
//case Command.ReadHornHistoryACK:
|
//case Command.ReadHornLoopsStatusACK:
|
//case Command.ReadHornPushACK:
|
//case Command.SetHornPushACK:
|
//case Command.ReadHornLoopAlarmACK:
|
//case Command.SetHornTargetEnableACK:
|
//case Command.ReadHornTargetEnableACK:
|
// receiveFlag += string.Format("{0}", usefulBytes[0]);
|
// break;
|
//case Command.RemoteFirstACK:
|
// for (int i = 1; i < 1 + 28; i++)
|
// {
|
// receiveFlag += string.Format("{0}", usefulBytes[i]);
|
// }
|
// break;
|
//case Command.RemoteSecoudACK:
|
// for (int i = 0; i < 7; i++)
|
// {
|
// receiveFlag += string.Format("{0}", usefulBytes[i]);
|
// }
|
// break;
|
default:
|
break;
|
}
|
//System.MainPage.WriteLog ("接收到数据:" + receiveFlag);
|
|
for (int i = 0; i < controlList.Count; i++)
|
{
|
try
|
{
|
var control = controlList[i];
|
if (control.SendFlag == receiveFlag)
|
{
|
control.LatestDateTime = System.DateTime.Now;
|
control.UsefulBytes = usefulBytes;//
|
control.run();
|
}
|
}
|
catch (Exception ex)
|
{
|
Console.WriteLine($"control error : {ex.Message}");
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
MainPage.Log("ManagerReceive抛出异常:" + ex.ToString());
|
}
|
}
|
|
/// <summary>
|
/// 添加到内存数组里面
|
/// </summary>
|
void add()
|
{
|
/// <summary>
|
/// 达到50条数据后就清理一下
|
/// </summary>
|
if (50 < controlList.Count)
|
{
|
lock (controlList)
|
{
|
for (int i = 0; i < controlList.Count;)
|
{
|
if (controlList[i] == null || 3 <= controlList[i].Packet.HaveSendCount)
|
{
|
controlList.RemoveAt(i);
|
}
|
else
|
{
|
i++;
|
}
|
}
|
|
}
|
//System.MainPage.WriteLog ("++++++++"+controlList.Count.ToString ());
|
}
|
controlList.Add(this);
|
}
|
|
//当前数据的关键数据
|
string sendFlag = string.Empty;
|
protected string SendFlag
|
{
|
get
|
{
|
return sendFlag;
|
}
|
set
|
{
|
sendFlag = value;
|
usefulBytes = null;
|
}
|
}
|
|
private byte[] usefulBytes;
|
/// <summary>
|
/// 获取回来的有用信息,如果获取回来的数据为null,就会抛出异常信息
|
/// </summary>
|
public byte[] UsefulBytes
|
{
|
get
|
{
|
if (null == usefulBytes)
|
{
|
// throw new Exception("不好意思,网络不稳定或者远程设备不在线,请稍候再试!");
|
}
|
|
return this.usefulBytes;
|
}
|
set
|
{
|
usefulBytes = value;
|
}
|
}
|
|
//发送数据了之后当前线程等待或者运行的信号
|
System.Threading.ManualResetEvent allDone = new System.Threading.ManualResetEvent(false);
|
|
/// <summary>
|
/// 发送了数据后,线程就是等待状态,直到接收到反馈或者超时后退出
|
/// </summary>
|
void wait()
|
{
|
allDone.Reset();
|
allDone.WaitOne();
|
}
|
|
|
/// <summary>
|
/// 让当前线程继续执行
|
/// </summary>
|
void run()
|
{
|
allDone.Set();
|
Packet.HaveSendCount = 4;
|
}
|
|
|
//数据重发处理
|
void managerSendCount(object o)
|
{
|
add();
|
if (CommonPage.IsRemote)
|
{
|
}
|
else
|
{
|
//Bus socket无法控制,重启机制
|
if (controlLostCount > 10)
|
{
|
BusSocket.Stop();
|
new System.Threading.Thread(() =>
|
{
|
System.Threading.Thread.Sleep(1000);
|
BusSocket.Start(6000);
|
controlLostCount = 0;
|
})
|
{ IsBackground = true }.Start();
|
}
|
|
try
|
{
|
MainPage.Log("发送数据:" + SendFlag);
|
BusSocket.AsyncBeginSend(Packet);
|
Packet.HaveSendCount--;
|
|
//这里是重发两次
|
while (Packet.HaveSendCount < 3)
|
{
|
if (Packet.FlagDateTime.AddMilliseconds(1000).Ticks <= DateTime.Now.Ticks)
|
{
|
MainPage.Log("重发数据:" + SendFlag);
|
BusSocket.AsyncBeginSend(Packet);
|
controlLostCount++;
|
}
|
System.Threading.Thread.Sleep(100);
|
}
|
}
|
catch (Exception ex)
|
{
|
MainPage.Log("managerSendCount:" + ex.ToString());
|
}
|
finally
|
{
|
allDone.Set();
|
}
|
}
|
}
|
|
/// <summary>
|
/// 当前数据包
|
/// </summary>
|
Packet Packet;
|
|
private void ini(Target target)
|
{
|
this.SendFlag = string.Format("{0},{1},{2},", target.SubnetID, target.DeviceID, (int)target.Command + 1);
|
|
switch (target.Command)
|
{
|
case Command.SetSingleLight:
|
case Command.ReadLogicLoopColor:
|
case Command.ReadACMode:
|
case Command.SetACMode:
|
case Command.ReadFloorHeat:
|
case Command.SetFloorHeat:
|
this.sendFlag += string.Format("{0}", target.AddData[0]);
|
break;
|
case Command.SetLogicLoopColor:
|
this.sendFlag += string.Format("{0},{1},{2}", target.AddData[0], target.AddData[1], target.AddData[2]);
|
break;
|
case Command.ReadLightAllLoopBrightness:
|
this.SendFlag += "";
|
break;
|
//case Command.YIPanelDeviceInof:
|
// for (int i = 0; i < 4; i++)
|
// {
|
// this.sendFlag += string.Format("{0}", target.AddData[i]);
|
// }
|
// break;
|
//case Command.ReadDoorLockSceneObj:
|
// this.SendFlag += string.Format("{0},{1},{2},{3},{4}", target.AddData[0], target.AddData[1], target.AddData[2], target.AddData[3], target.AddData[4]);
|
// break;
|
//case Command.ReadDoorLockClock:
|
//case Command.CreatConnection:
|
// this.SendFlag += string.Format("{0}", target.AddData[0]);
|
// break;
|
//case Command.ReadDoorLockUseRemark:
|
//case Command.ReadSensorPushMessage:
|
//case Command.SetSensorPushMessage:
|
//case Command.SetSensorScence:
|
//case Command.ReadAnalog:
|
// this.sendFlag += string.Format("{0},{1},{2}", target.AddData[0], target.AddData[1], target.AddData[2]);
|
// break;
|
//case Command.ReadSensorScence:
|
// this.sendFlag += string.Format("{0},{1},{2}", target.AddData[0], target.AddData[1], target.AddData[2]);
|
// break;
|
//case Command.SendRemoteInfoToServer:
|
// for (int i = 40; i < 48; i++)
|
// {
|
// this.sendFlag += string.Format("{0}", target.AddData[i]);
|
// }
|
// break;
|
//case Command.SetCommonSwitch:
|
//case Command.InfraredChannelControl:
|
//case Command.ReadFoolHeat:
|
//case Command.SetFoolHeat:
|
//case Command.Serverx_FH_CMD:
|
//case Command.SetArm:
|
//case Command.ReadArm:
|
//case Command.ReadSensorHistory:
|
//case Command.SetSensorAutomationTargetLevelEnable:
|
//case Command.ReadSensorAutomationLevelTargetEnable:
|
// this.SendFlag += string.Format("{0}", target.AddData[0]);
|
// break;
|
//case Command.ReadDeviceModul:
|
//case Command.ReadGateway:
|
//case Command.ReadSecurityStatus:
|
//case Command.ReadHornTargetState:
|
// this.SendFlag = string.Format("{0},{1}", target.AddData[0], target.AddData[1]);
|
// break;
|
//case Command.SetScene:
|
//case Command.SetSeries:
|
//case Command.SetHotelCurtain:
|
//case Command.ReadAnalogValue:
|
//case Command.SetSensorPushValues:
|
//case Command.ReadSensorPushValues:
|
// this.SendFlag += string.Format("{0},{1}", target.AddData[0], target.AddData[1]);
|
// break;
|
////case Command.ReadOnePortWirelessFROtherInfo:
|
//case Command.UpdataRemake:
|
//case Command.WriteManageWirelessNet:
|
//case Command.UpdataLightDimmingTheLargestLevel:
|
//case Command.UpdataLightDimmingMaximumOrMinimum:
|
//case Command.ReadGateWayModelInfo:
|
//case Command.ReadGatewayServerIP:
|
//case Command.SetGateWayModelInfo:
|
//case Command.SetGateWayModelInternetInfo:
|
//case Command.ReadDeviceMac:
|
//case Command.SetDeviceSubnetID:
|
//case Command.PositioningEquipment:
|
//case Command.PositioningPanel:
|
//case Command.CheckConfigSuccess:
|
//case Command.GotoConfigMode:
|
//case Command.ReadACPanel:
|
//case Command.SetACPanel:
|
//case Command.ReadTerrestriaHeatRemark:
|
//case Command.UpdateGatewayIp:
|
//case Command.ReadWirelessPanelMode:
|
//case Command.ReadDrycontactMode:
|
//case Command.ReadACFloorHeatingSettingEquipment:
|
//case Command.SetACFloorHeatingSettingEquipment:
|
//case Command.Read43FloorHeatingSettingEquipment:
|
//case Command.Set43FloorHeatingSettingEquipment:
|
//case Command.READ_AIR_ALL_Parameter:
|
//case Command.Set_AIR_ALL_Parameter:
|
//case Command.ReadFloorHeatProbe:
|
//case Command.ControlMusicModel:
|
//case Command.ReadButtonKeyEnable:
|
//case Command.UpdateEquipmentLoopRemake:
|
//case Command.SetGateway:
|
//case Command.ReadMusicPanelSetting:
|
//case Command.ReadMusicPanelEnable:
|
//case Command.SetMusicPanelEnable:
|
//case Command.SetMusicPanelSetting:
|
//case Command.ReadGatewayProgrammingMode:
|
//case Command.RED_HSFH_TOTAL:
|
//case Command.RED_HSFH_INFORMATION:
|
//case Command.RED_HSRM_TOTAL:
|
//case Command.RED_HSRM_INFORMATION:
|
//case Command.CLEAR_SYSTEM_HISTORY:
|
//case Command.SetSensorTargetRemark:
|
//case Command.ReadSensorAutomationEnableList:
|
//case Command.SetSensorAutomationEnableList:
|
//case Command.SetSensorAutomationListID:
|
//case Command.ReadSensorAutomationListID:
|
//case Command.SetSensorAutomationName:
|
//case Command.ReadSensorAutomationName:
|
//case Command.Set_Floor_Heat_State:
|
//case Command.Read_Floor_Heat_State:
|
//case Command.Read_Air_Condition_Set:
|
//case Command.UpdateHornLoopRemake:
|
//case Command.ReadHornLoopCount:
|
//case Command.ReadPanelTempType:
|
// this.SendFlag += "";
|
// break;
|
//case Command.ControlMusicModel2:
|
// for (int i = 1; i < target.AddData.Length; i++)
|
// {
|
// if (target.AddData[i + 1] == 0x0D)
|
// {
|
// break;
|
// }
|
// this.sendFlag += string.Format("{0},", target.AddData[i]);
|
// }
|
// break;
|
//case Command.Remote3th:
|
// this.SendFlag = string.Format("{0},", (int)target.Command + 1);
|
// break;
|
case Command.ReadDeviceLoopInfo:
|
if (target.AddData[0] == 1)//特殊处理灯光类,DMX模块每一个回路不固定小类,根据具体设置来回复
|
this.sendFlag += string.Format("{0},{1}", target.AddData[0], target.AddData[2]);
|
else
|
this.sendFlag += string.Format("{0},{1},{2}", target.AddData[0], target.AddData[1], target.AddData[2]);
|
break;
|
//case Command.SetDeviceLoopInfo:
|
//case Command.InfraredControl:
|
//case Command.SetSecurityByPass:
|
//case Command.SetSensorAutomationDateTimeCycle:
|
//case Command.ReadSensorAutomationDateTimeCycle:
|
// this.sendFlag += string.Format("{0},{1},{2}", target.AddData[0], target.AddData[1], target.AddData[2]);
|
// break;
|
//case Command.ReadWirelessPanelButtonKey:
|
//case Command.WriteWirelessPanelButtonKey:
|
//case Command.ReadDryContactStatus:
|
//case Command.SetCurtainModelStutas:
|
//case Command.DownloadInfrared:
|
//case Command.UpLoadInfrared:
|
case Command.InstructionPanelKey:
|
case Command.ReadInstructionPanelKey:
|
//case Command.ReadSensorTargetRemark:
|
//case Command.SetHornTargetState:
|
this.sendFlag += string.Format("{0},{1}", target.AddData[0], target.AddData[1]);
|
break;
|
//case Command.AssignedAddress:
|
//case Command.UpdataCurtainModelRunTime:
|
//case Command.ReadCurtainStatus:
|
//case Command.ReadPanleTemp:
|
//case Command.FreshAirRead:
|
//case Command.FreshAirControl:
|
//case Command.Set_Air_State_New:
|
//case Command.ReadHornTargetEnable:
|
//case Command.SetHornTargetEnable:
|
//case Command.ReadHornLoopAlarm:
|
//case Command.SetHornPush:
|
//case Command.ReadHornPush:
|
//case Command.ReadHornHistory:
|
//case Command.ReadHornLoopsStatus:
|
// this.sendFlag += string.Format("{0}", target.AddData[0]);
|
// break;
|
//case Command.RemoteFirst:
|
// for (int i = 0; i < 28; i++)
|
// {
|
// this.sendFlag += string.Format("{0}", target.AddData[i]);
|
// }
|
// break;
|
//case Command.RemoteSecoud:
|
// for (int i = 0; i < 7; i++)
|
// {
|
// this.sendFlag += string.Format("{0}", target.AddData[i]);
|
// }
|
// break;
|
default:
|
//return;
|
break;
|
}
|
|
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(managerSendCount));
|
thread.IsBackground = true;
|
thread.Start(Packet);
|
}
|
|
/// <summary>
|
/// 发送Bus数据,发送了不需要等待
|
/// </summary>
|
/// <param name="target">发送对象</param>
|
/// <param name="sendCount">重发次数</param>
|
void Send(Target target, int sendCount, bool isWait)
|
{
|
try
|
{
|
Packet = new Packet(target.SendBytes, target.IPEndPoint);
|
Packet.HaveSendCount = 3 - sendCount;
|
|
ini(target);
|
|
if (isWait)
|
{
|
this.wait();
|
}
|
}
|
catch(Exception ex)
|
{
|
MainPage.Log($"Send bus data error {ex.Message}");
|
}
|
}
|
|
/// <summary>
|
/// 读取网关IP
|
/// </summary>
|
void ReadGatewayIP()
|
{
|
try
|
{
|
var sendJob = new JObject { { "vendor_code", "HDL" }, { "command", "search" } };
|
var SearchGateway = JsonConvert.SerializeObject(sendJob);
|
var SearchGatewayPayload = Encoding.ASCII.GetBytes(SearchGateway);
|
Packet = new Packet(SearchGatewayPayload, CommonPage.GetGatewayIP_EndPoint);
|
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(managerSendCount));
|
thread.IsBackground = true;
|
thread.Start(Packet);
|
|
wait();
|
}
|
catch (Exception ex)
|
{
|
MainPage.Log($"Send bus data error {ex.Message}");
|
}
|
}
|
|
|
}
|
}
|