tangxu
2022-10-31 2f30d9dfe474db862e1b409065a7ba5280bed92b
Socket/IStation.DataDockingSocket4NT/MsgHandle/StartUpMsgHelper.cs
@@ -1,5 +1,4 @@
using IStation.DataDockingSocket.MsgHandle;
using IStation.Model;
using IStation.Model;
using IStation.Untity;
using System;
using System.Collections.Generic;
@@ -24,7 +23,7 @@
        /// <returns></returns>
        public static bool StartJob(Model.IMonitorDataDockingSession session, MonitorTestControlParas.StartContext paras)
        {
            if (session != null)
            if (session == null)
            {
                NtLogHelper.Error($"开机 session:Close");
                return false;
@@ -82,7 +81,7 @@
                return false;
        }
        /// <summary>
        /// 关机指令
        /// 开机指令
        /// </summary>
        static string ControlMsgOpen = "01-06-00-0F-00-01-78-09";
        /// <summary>
@@ -92,30 +91,56 @@
        public static bool HandleReceive(Model.IMonitorDataDockingSession session, byte[] byteMessage)
        {
            if (InstructionStatus == eStartUpInstructionStatus.未发送)
            {
                NtLogHelper.Info("InstructionStatus==eStartUpInstructionStatus.未发送");
                return false;
            }
            if (InstructionStatus == eStartUpInstructionStatus.开机指令发送)
            {
                if (byteMessage.Length >= ControlMsgOpen.Length)
                NtLogHelper.Info("InstructionStatus==eStartUpInstructionStatus.开机指令发送");
                var byteMsgOpen = Encoding.Unicode.GetBytes(ControlMsgOpen);
                //if (byteMessage.Length >= byteMsgOpen.Length)
                //{
                string strMessage = BitConverter.ToString(byteMessage, 0, byteMessage.Length);
                if (strMessage == ControlMsgOpen)
                {
                    string strMessage = BitConverter.ToString(byteMessage, 0, byteMessage.Length);
                    if (strMessage == ControlMsgOpen)
                    {//01-06-00-0F-00-01-78-09
                        InstructionStatus = eStartUpInstructionStatus.未发送;
                    NtLogHelper.Info($"strMessage ({strMessage})== ControlMsgOpen ({ControlMsgOpen})");
                    //01-06-00-0F-00-01-78-09
                    InstructionStatus = eStartUpInstructionStatus.未发送;
                        NtLogHelper.Debug("开机指令返回:" + BitTransfer.ToString(byteMessage));
                    NtLogHelper.Info("开机指令返回:" + BitTransfer.ToString(byteMessage));
                    if (_lastParas.OperatingValue > 0)
                    {
                        //开启自动关闭
                        ShutDownMsgHelper.StartAutoClose(_lastParas.OperatingValue);
                        return true;
                    }
                    else
                    {
                        NtLogHelper.Info("时间小于等于0,不开启自动关闭");
                    }
                    return true;
                }
                else
                {
                    NtLogHelper.Info($"strMessage ({strMessage})!= ControlMsgOpen ({ControlMsgOpen})");
                }
                //}
                //else
                //{
                //    NtLogHelper.Info($"byteMessage.Length ({byteMessage.Length}) <= ControlMsgOpen.Length ({ControlMsgOpen.Length})");
                //}
                //返回失败, 再发送一次再确认一下
                if ((DateTime.Now - _lastOpenSendTime).TotalSeconds > 5)
                {
                    NtLogHelper.Info($"返回失败, 再发送一次再确认一下");
                    SendOpenMsg(session);
                }
            }
            if (InstructionStatus == eStartUpInstructionStatus.调频指令发送)
            {
                NtLogHelper.Info($"InstructionStatus == eStartUpInstructionStatus.调频指令发送");
                //需要判断是否是调频指令:以后再补充
                {
                    SendOpenMsg(session);
@@ -125,6 +150,7 @@
                //返回失败, 再发送一次再确认一下
                if ((DateTime.Now - _lastHzSendTime).TotalSeconds > 5)
                {
                    NtLogHelper.Info($"返回失败, 再发送一次再确认一下");
                    StartJob(session, _lastParas);
                }
            }
@@ -132,10 +158,9 @@
            return false;
        }
        private static  void SendOpenMsg(Model.IMonitorDataDockingSession session)
        private static void SendOpenMsg(Model.IMonitorDataDockingSession session)
        {
            byte[] bts = GetControlMsg开机();
            session.Send(bts, 0, bts.Length);
            InstructionStatus = eStartUpInstructionStatus.开机指令发送;
@@ -166,9 +191,7 @@
        public static byte[] GetControlMsg调频(double frequece)
        {
            var iFrequece = (int)(frequece * 10);
            byte[] commandSend = null;
            ModBusRtuHelper.BuildSendMessage06(0x01, 20, 2,
                iFrequece, ref commandSend);