Exemple #1
0
        private void HandleCommand(List <byte> hexBuffer, AsyncClient client = null)
        {
            if (hexBuffer != null && hexBuffer.Count >= 6)
            {
                if (hexBuffer[0] == 0x00 && hexBuffer[1] == 0x02 && hexBuffer[3] == 0x03)//应该是泵类型命令
                {
                    #region
                    //m_Client.s
                    CmdSendPumpType cmdPump = new CmdSendPumpType();
                    cmdPump.Direction = 1;
                    //cmdPump.PumpState = PumpStatus.Run;
                    List <byte> debugBytes = cmdPump.GetBytesDebug();
                    int         iCount     = debugBytes.Count - 4;
                    if (pumpTypeResponseFlag == 1)//全部启动
                    {
                        debugBytes[iCount - 1] = 0x02;
                        debugBytes[iCount - 2] = 0x02;
                        debugBytes[iCount - 3] = 0x02;
                        debugBytes[iCount - 4] = 0x02;
                        debugBytes[iCount - 5] = 0x02;
                        debugBytes[iCount - 6] = 0x02;
                    }
                    else if (pumpTypeResponseFlag == 2)//全部停止
                    {
                        debugBytes[iCount - 1] = 0x01;
                        debugBytes[iCount - 2] = 0x01;
                        debugBytes[iCount - 3] = 0x01;
                        debugBytes[iCount - 4] = 0x01;
                        debugBytes[iCount - 5] = 0x01;
                        debugBytes[iCount - 6] = 0x01;
                    }

                    client.Send(Common.Hex2Char(debugBytes.ToArray()));
                    #endregion
                }
                else if (hexBuffer[0] == 0x00 && hexBuffer[1] == 0x03 && hexBuffer[3] == 0x09)//应该是老化开始命令
                {
                    //m_Client.s
                    CmdCharge cmdcharge = new CmdCharge();
                    cmdcharge.Direction = 1;
                    List <byte> debugBytes = cmdcharge.GetBytesDebug();
                    client.Send(Common.Hex2Char(debugBytes.ToArray()));
                }
                else if (hexBuffer[0] == 0x00 && hexBuffer[1] == 0x04) //放电命令
                {
                    CmdDischarge cmd = new CmdDischarge();
                    cmd.Direction = 1;
                    List <byte> debugBytes = cmd.GetBytesDebug();
                    client.Send(Common.Hex2Char(debugBytes.ToArray()));
                }
                else if (hexBuffer[0] == 0x00 && hexBuffer[1] == 0x05) //补电命令
                {
                    CmdRecharge cmd = new CmdRecharge();
                    cmd.Direction = 1;
                    List <byte> debugBytes = cmd.GetBytesEx();
                    client.Send(Common.Hex2Char(debugBytes.ToArray()));
                }
            }
        }
        /// <summary>
        /// 发送放电命令
        /// </summary>
        /// <param name="handle">回调函数对象</param>
        public void SendCmdDischarge(AsyncSocketUserToken remoteSocket, EventHandler <EventArgs> func, EventHandler <EventArgs> timeoutFunc, byte channel = 0xFF)
        {
            if (remoteSocket == null)
            {
                Logger.Instance().ErrorFormat("CommandManage::SendCmdDischarge()->参数remoteSocket为null");
                return;
            }
            CmdDischarge cmd = new CmdDischarge();

            cmd.Channel      = channel;
            cmd.RemoteSocket = remoteSocket;
            long ip = ControllerManager.GetLongIPFromSocket(remoteSocket);

            AddCommand(ip, cmd, func, timeoutFunc);
        }