示例#1
0
        /// <summary>
        /// 运行时指令 160
        /// </summary>
        public override void initRuntimeCmd()
        {
            base.initRuntimeCmd();
            ///////////////r2////////////////////
            BaseCmd r1 = BaseCmd.getRuntimeCmd();

            byte[] send2 = new byte[6];
            send2[0] = Convert.ToByte(stationEntity.Address);
            send2[1] = 6;
            send2[2] = 0;
            send2[3] = 0;
            send2[4] = 0;
            send2[5] = 4;
            CRCData crcdata = CRCDataCaculate.CRCCaculate(send2);

            byte[] s2 = new byte[8];

            for (int i = 0; i < 6; i++)
            {
                s2[i] = send2[i];
            }

            s2[6] = crcdata.CRCHigh;
            s2[7] = crcdata.CRCLow;
            r1.SetData(s2);
            runtimeComand.Enqueue(r1);
        }
示例#2
0
        //取消操作,将done栈弹出,redo 栈压入
        public Boolean Undo()
        {
            if (mStackDone.Count <= 0)
            {
                return(false);
            }
            BaseCmd cmd = mStackDone.Pop();

            if (mStackReDo.Count >= MAXCMD)
            {
                mStackTmp.Clear();
                for (int i = 0; i < mStackReDo.Count - REMOVENUM; i++)
                {
                    mStackTmp.Push(mStackReDo.Pop());
                }
                mStackReDo.Clear();
                for (int i = 0; i < mStackTmp.Count; i++)
                {
                    mStackReDo.Push(mStackTmp.Pop());
                }
            }
            mStackReDo.Push(cmd);

            cmd.Undo();                       //执行操作

            return(true);
        }
示例#3
0
        /// <summary>
        /// 定时指令 170 180 190
        /// </summary>
        public override void initTimedCmd()
        {
            //170每2分钟执行一次
            TimedRule tr2 = new TimedRule(TimedType.MINUTE, new DateTime(2017, 8, 6, 15, 53, 12), 2, false);
            ///////////////////////////////p2///////
            BaseCmd p2 = BaseCmd.getRuntimeCmd();

            byte[]  send2   = new byte[] { Convert.ToByte(stationEntity.Address), 7, 0, 0, 0, 4 };
            CRCData crcdata = CRCDataCaculate.CRCCaculate(send2);

            byte[] s2 = new byte[8];
            for (int i = 0; i < 6; i++)
            {
                s2[i] = send2[i];
            }
            s2[6] = crcdata.CRCHigh;
            s2[7] = crcdata.CRCLow;
            p2.SetData(s2);
            tr2.cmdList.Add(p2);
            trList.Add(tr2);
            //180每1小时执行一次
            TimedRule tr3 = new TimedRule(TimedType.MINUTE, new DateTime(2017, 8, 6, 15, 10, 6), 1, false);
            /////////////////////////////p3///////
            BaseCmd p3 = BaseCmd.getRuntimeCmd();

            byte[] send3 = new byte[] { Convert.ToByte(stationEntity.Address), 8, 0, 0, 0, 4 };
            crcdata = CRCDataCaculate.CRCCaculate(send3);
            byte[] s3 = new byte[8];
            for (int i = 0; i < 6; i++)
            {
                s3[i] = send3[i];
            }
            s3[6] = crcdata.CRCHigh;
            s3[7] = crcdata.CRCLow;
            p3.SetData(s3);
            tr3.cmdList.Add(p3);
            trList.Add(tr3);

            //190每1天执行一次,上午10点
            TimedRule tr1 = new TimedRule(TimedType.MINUTE, new DateTime(2017, 8, 6, 10, 0, 0), 4, false);
            /////////////////////////////p1///////
            BaseCmd p1 = BaseCmd.getRuntimeCmd();

            byte[] send1 = new byte[] { Convert.ToByte(stationEntity.Address), 9, 0, 0, 0, 4 };
            crcdata = CRCDataCaculate.CRCCaculate(send1);
            byte[] s1 = new byte[8];
            for (int i = 0; i < 6; i++)
            {
                s1[i] = send1[i];
            }
            s1[6] = crcdata.CRCHigh;
            s1[7] = crcdata.CRCLow;
            p1.SetData(s1);
            tr1.cmdList.Add(p1);
            trList.Add(tr1);
        }
示例#4
0
        //重做操作 , 将redo 栈弹出,done 栈压入
        public Boolean Redo()
        {
            if (mStackReDo.Count <= 0)
            {
                return(false);
            }
            BaseCmd cmd = mStackReDo.Pop();

            PushCmd(cmd);
            cmd.Redo();
            return(true);
        }
示例#5
0
 public void OnCmd(BaseCmd cmd)
 {
     if (cmd.Cmd == 0)
     {
         if (cmd.Para == 1)
         {
             Msg_SC_Data msg_SC_Data = (Msg_SC_Data)cmd;
             Debug.LogFormat("Data Cmd:{0} Para:{1} ->>{2} ,{3}, {4}", cmd.Cmd, cmd.Para,
                             msg_SC_Data._dataUint, msg_SC_Data._dataInt, msg_SC_Data._dataString);
         }
     }
 }
示例#6
0
        /// <summary>
        /// 初始化Init指令   110 和120
        /// </summary>
        public override void initInitCmd()
        {
            ///////////////////////i1//////////////////////
            BaseCmd i1 = BaseCmd.getInitCmd();

            byte[] send1 = new byte[6];
            send1[0] = Convert.ToByte(stationEntity.Address);
            send1[1] = 1;
            send1[2] = 0;
            send1[3] = 0;
            send1[4] = 0;
            send1[5] = 4;
            CRCData crcdata = CRCDataCaculate.CRCCaculate(send1);

            byte[] s1 = new byte[8];

            for (int i = 0; i < 6; i++)
            {
                s1[i] = send1[i];
            }

            s1[6] = crcdata.CRCHigh;
            s1[7] = crcdata.CRCLow;
            i1.SetData(s1);
            initComand.Add(i1);
            ///////////////////////i2//////////////////////
            BaseCmd i2 = BaseCmd.getInitCmd();

            byte[] send2 = new byte[6];
            send2[0] = Convert.ToByte(stationEntity.Address);
            send2[1] = 2;
            send2[2] = 0;
            send2[3] = 0;
            send2[4] = 0;
            send2[5] = 4;
            crcdata  = CRCDataCaculate.CRCCaculate(send2);
            byte[] s2 = new byte[8];

            for (int i = 0; i < 6; i++)
            {
                s2[i] = send2[i];
            }

            s2[6] = crcdata.CRCHigh;
            s2[7] = crcdata.CRCLow;
            i2.SetData(s2);
            initComand.Add(i2);
        }
示例#7
0
 public void PushCmd(BaseCmd cmd)
 {
     if (mStackDone.Count >= MAXCMD)
     {
         mStackTmp.Clear();
         for (int i = 0; i < mStackDone.Count - REMOVENUM; i++)
         {
             mStackTmp.Push(mStackDone.Pop());
         }
         mStackDone.Clear();
         for (int i = 0; i < mStackTmp.Count; i++)
         {
             mStackDone.Push(mStackTmp.Pop());
         }
     }
     mStackDone.Push(cmd);
 }
示例#8
0
        /// <summary>
        /// 初始化Polling指令   130 和140 150
        /// </summary>
        public override void initPollingCmd()
        {
            /////////////////////////////p1///////
            BaseCmd p1 = BaseCmd.getPollingCmd();

            byte[]  send1   = new byte[] { Convert.ToByte(stationEntity.Address), 3, 0, 3, 0, 12 };
            CRCData crcdata = CRCDataCaculate.CRCCaculate(send1);

            byte[] s1 = new byte[8];
            for (int i = 0; i < 6; i++)
            {
                s1[i] = send1[i];
            }
            s1[6] = crcdata.CRCLow;
            s1[7] = crcdata.CRCHigh;
            p1.SetData(s1);
            pollingComand.Add(p1);
            /////////////////////////////p2///////
            BaseCmd p2 = BaseCmd.getPollingCmd();

            byte[] send2 = new byte[] { Convert.ToByte(stationEntity.Address), 4, 0, 3, 0, 12 };
            crcdata = CRCDataCaculate.CRCCaculate(send2);
            byte[] s2 = new byte[8];
            for (int i = 0; i < 6; i++)
            {
                s2[i] = send2[i];
            }
            s2[6] = crcdata.CRCLow;
            s2[7] = crcdata.CRCHigh;
            p2.SetData(s2);
            pollingComand.Add(p2);
            /////////////////////////////p3///////
            BaseCmd p3 = BaseCmd.getPollingCmd();

            byte[] send3 = new byte[] { Convert.ToByte(stationEntity.Address), 5, 0, 3, 0, 12 };
            crcdata = CRCDataCaculate.CRCCaculate(send3);
            byte[] s3 = new byte[8];
            for (int i = 0; i < 6; i++)
            {
                s3[i] = send3[i];
            }
            s3[6] = crcdata.CRCLow;
            s3[7] = crcdata.CRCHigh;
            p3.SetData(s3);
            pollingComand.Add(p3);
        }
示例#9
0
        public void SendData(int mainId, int subId, BaseCmd cmdObj, List <string> desireReceiver)
        {
            if (IsStarted() == false)
            {
                return;
            }

            MainCommand command = new MainCommand();

            command.mainCommandId = mainId;
            command.subCommandId  = subId;
            command.data          = cmdObj.getCommandString();

            string message = serializer.Serialize(command);

            _SessionMgr.SendMessage(message, desireReceiver);
        }
示例#10
0
        public void BroadcastMessage(int mainId, int subId, BaseCmd cmdObj)
        {
            if (IsStarted() == false)
            {
                return;
            }

            MainCommand command = new MainCommand();

            command.mainCommandId = mainId;
            command.subCommandId  = subId;
            command.data          = cmdObj.getCommandString();

            string message = serializer.Serialize(command);

            _SessionMgr.BroadcastMessage(message);
        }
示例#11
0
    //发送协议并加锁,防止连续多次发送协议,必须收到指定协议之后才可继续发送协议
    public bool sendCmd_And_Lock(BaseCmd _cmd, int _unLockKey)
    {
        if (_cmd.getSize() <= 0 || !m_isConnected || m_sendLock)
        {
            return(false);
        }

        int         _message_length = _cmd.getSize() + 4;
        BytesBuffer _sendBuf        = new BytesBuffer(_message_length);

        _sendBuf.writeInt32(_message_length - 4);

        System.Buffer.BlockCopy(_cmd.getBuffer.bytes, 0, _sendBuf.bytes, 4, _cmd.getSize());

        m_ClientSocket.Client.BeginSend(_sendBuf.bytes, 0, _sendBuf.bytes.Length, SocketFlags.None, new AsyncCallback(_onSendMsg), m_ClientSocket);

        m_sendUnLockKey = _unLockKey;
        m_sendLock      = true;

        return(true);
    }
示例#12
0
    //发送协议
    public bool sendCmd(BaseCmd _cmd)
    {
        if (!m_isConnected)
        {
            Debug.LogErrorFormat("当前未连接服务器! {0}", DateTime.Now);
        }

        if (_cmd.getSize() <= 0 || !m_isConnected || m_sendLock)
        {
            Debug.LogWarning("send field");
            return(false);
        }

        // Debug.Log("[SEND] cmd : " + _cmd.Cmd.ToString() + " para :" + _cmd.Para.ToString() + " msgLength : " + _cmd.getSize().ToString());

        int _message_length = _cmd.getSize();
        //BytesBuffer _sendBuf = new BytesBuffer (_message_length);
        BytesBuffer _sendBuf = _cmd.sendBuffer;

        _sendBuf.resetPosition();
        _sendBuf.writeInt32(_message_length - 4);

        //System.Buffer.BlockCopy (_cmd.getBuffer.bytes, 0, _sendBuf.bytes, 4, _cmd.getSize());

        if (_sendAsyncCallback == null)
        {
            _sendAsyncCallback = new AsyncCallback(_onSendMsg);
        }
        //m_ClientSocket.Client.BeginSend (_sendBuf.bytes, 0, _sendBuf.bytes.Length, SocketFlags.None, _sendAsyncCallback, m_ClientSocket);

        m_ClientSocket.Client.Send(_sendBuf.bytes, 0, _message_length, SocketFlags.None);

        /* 断包测试
         * int bl = 5;
         * m_ClientSocket.Client.Send (_sendBuf.bytes, 0, _sendBuf.bytes.Length - bl, SocketFlags.None);
         * System.Threading.Thread.Sleep (1000);
         * m_ClientSocket.Client.Send (_sendBuf.bytes, bl, bl, SocketFlags.None);
         * ///*/
        return(true);
    }
示例#13
0
    void OnPacket()
    {
        bytesBuffer.bytes = m_recvData;

        keyByteArr[0] = m_recvData[m_recvBufferIndex];
        keyByteArr[1] = m_recvData[m_recvBufferIndex + 1];

        if (keyByteArr [0] == 1 && keyByteArr [1] == 2)
        {
            CheckTimeDelayReturn();
        }

        m_cmdkey = BitConverter.ToUInt16(keyByteArr, 0);

        m_Cur_BaseCmd = null;
        m_Cmd_Dic.TryGetValue(m_cmdkey, out m_Cur_BaseCmd);

        if (m_Cur_BaseCmd != null)
        {
            bytesBuffer.position     = m_recvBufferIndex + 2;
            m_Cur_BaseCmd.sendBuffer = bytesBuffer;

            m_Cur_BaseCmd.unserialize();

            if (m_Cur_BaseCmd.Stackable)
            {
                m_BaseCmd_Queue.Enqueue(m_Cur_BaseCmd.Clone());
            }
            else if (_onCmd != null)
            {
                _onCmd(m_Cur_BaseCmd);
            }
            //Debug.LogWarningFormat ("recv cmd:{0} para:{1} Stackable:{2}",keyByteArr[0],keyByteArr[1],m_Cur_BaseCmd.Stackable);
        }
        //Debug.LogError(m_Cur_BaseCmd.ToString());
    }
示例#14
0
 public void Register(BaseCmd baseCmd)
 {
     m_Cmd_Dic.Add(baseCmd.getKey(), baseCmd);
 }