using IStation.DataDockingSocket.MsgHandle;
|
using IStation.Untity;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace IStation.DataDockingSocket
|
{
|
internal class ShunDownMsgHelper
|
{
|
public static eShutDownInstructionStatus InstructionStatus = eShutDownInstructionStatus.未发送;
|
public static DateTime sendTime ;
|
/// <summary>
|
/// 开始关机
|
/// </summary>
|
/// <param name="session"></param>
|
/// <returns></returns>
|
public static bool StartJob(Model.IMonitorDataDockingSession session)
|
{
|
if (session != null)
|
{
|
NtLogHelper.Error($"关机 session:Close");
|
return false;
|
}
|
|
if (session.IsConnected)
|
{
|
byte[] bts = GetControlMsg();
|
|
session.Send(bts, 0, bts.Length);
|
InstructionStatus = eShutDownInstructionStatus.关机机指令发送;
|
sendTime = DateTime.Now;
|
NtLogHelper.Debug("关机指令发送:" + session.SessionName + ":" + BitTransfer.ToString(bts) + ", 发送一条请求控制指令");
|
|
return true;
|
}
|
else
|
{
|
NtLogHelper.Error($"关机时 session:Not connected");
|
return false;
|
}
|
|
}
|
|
|
/// <summary>
|
/// 是否是控制指令
|
/// </summary>
|
/// <param name="byteMessage"></param>
|
/// <returns></returns>
|
public static bool IsControlMsg(byte[] byteMessage)
|
{
|
|
|
return false;
|
}
|
|
/// <summary>
|
/// 获取控制指令(开机)
|
/// </summary>
|
/// <returns></returns>
|
public static byte[] GetControlMsg ()
|
{
|
// var appParas = AppParasHelper.GetInstance();
|
// if (appParas == null || appParas.InstructionStartUp == null || appParas.InstructionStartUp.Content == null)
|
{
|
return BitTransfer.FromString("01-06-00-10-00-01-49-CF");
|
}
|
// return BitTransfer.FromString(appParas.InstructionStartUp.Content);
|
}
|
|
/// <summary>
|
/// 读取返回消息
|
/// </summary>
|
/// <param name="byteMessage"></param>
|
public static void HandleReceive(Model.IMonitorDataDockingSession session,byte[] byteMessage)
|
{
|
if (InstructionStatus == eShutDownInstructionStatus.未发送)
|
return;
|
if (InstructionStatus == eShutDownInstructionStatus.关机机指令发送)
|
{
|
if (byteMessage.Length == 8)
|
{
|
if (byteMessage[0] == 0x01 && byteMessage[1] == 0x06 && byteMessage[2] == 0x00
|
&& byteMessage[3] == 0x10 && byteMessage[4] == 0x00 && byteMessage[5] == 0x01
|
&& byteMessage[6] == 0x49 && byteMessage[7] == 0xCF)
|
{//01-06-00-0F-00-01-78-09
|
InstructionStatus = eShutDownInstructionStatus.未发送;
|
|
NtLogHelper.Debug("关机指令返回:" + BitTransfer.ToString(byteMessage) );
|
|
return;
|
}
|
}
|
//返回失败, 再发送一次再确认一下
|
if((DateTime.Now- sendTime).TotalSeconds > 3)
|
{
|
StartJob(session);
|
}
|
|
}
|
|
|
}
|
|
}
|
}
|