Beispiel #1
0
        /// <summary>
        /// 读取头信息的总长度 命令id 和序列号
        /// </summary>
        /// <param name="argSocket"></param>
        public void ReadHead(Socket argSocket)
        {
            byte[] vTempBytes = new byte[4];
            argSocket.Receive(vTempBytes);
            TotalMsgLen = SGIPCommand.Bytes4ToInt(vTempBytes); // 长度

            byte[] vCommandIdByte = new byte[4];
            argSocket.Receive(vCommandIdByte);
            CommandId = (uint)SGIPCommand.Bytes4ToInt(vCommandIdByte); // 命令id
            UnicomSN  = new byte[12];
            argSocket.Receive(vTempBytes);
            byte[] vSrcnodeByte = new byte[5];
            Buffer.BlockCopy(vTempBytes, 0, vSrcnodeByte, 1, 4);
            long vSrcNode = SGIPCommand.Bytes4ToLong(vSrcnodeByte);

            Buffer.BlockCopy(vTempBytes, 0, UnicomSN, 0, 4);
            argSocket.Receive(vTempBytes);
            string vDate = SGIPCommand.Bytes4ToInt(vTempBytes) + "";

            Buffer.BlockCopy(vTempBytes, 0, UnicomSN, 4, 4);
            argSocket.Receive(vTempBytes);
            string vSeqNum = SGIPCommand.Bytes4ToInt(vTempBytes) + "";

            SequenceNumber = vSrcNode + vDate + vSeqNum;
            Buffer.BlockCopy(vTempBytes, 0, UnicomSN, 8, 4);
        }
Beispiel #2
0
 /// <summary>
 /// 获取头字节
 /// </summary>
 /// <param name="argSrcNode"></param>
 /// <returns></returns>
 public byte[] GetCommandHeadBytes()
 {
     byte[] vSrcNode   = SGIPCommand.LongToBytesReverse(SocketConfig.SourceNode);
     byte[] vDateCmd   = SGIPCommand.IntToBytesReverse(GetDateCmd());   // 命令产生日期
     byte[] vSeqNum    = SGIPCommand.IntToBytesReverse(GetSeqNumber()); // 序列号
     byte[] vMsgLen    = SGIPCommand.IntToBytesReverse(TotalMsgLen);    // 命令体总长度
     byte[] vCommandId = BitConverter.GetBytes(CommandId);
     Array.Reverse(vCommandId);
     SequenceNumber = SocketConfig.SourceNode.ToString() + SGIPCommand.Bytes4ToInt(vDateCmd) + SGIPCommand.Bytes4ToInt(vSeqNum);
     byte[] vCommandHeadbytes = new byte[(int)SGIPCommandDefine.LEN_SGIP_HEADER];
     byte[] vCmdseq           = new byte[12]; // 总序列号(MessageLength + Commandid + sequenceNumber)
     Buffer.BlockCopy(vMsgLen, 0, vCommandHeadbytes, 0, 4);
     Buffer.BlockCopy(vCommandId, 0, vCommandHeadbytes, 4, 4);
     if (UnicomSN != null)
     {
         Buffer.BlockCopy(UnicomSN, 0, vCmdseq, 0, 12);
         byte[] vTempBytes = new byte[4];
         Buffer.BlockCopy(UnicomSN, 0, vTempBytes, 0, 4);
         byte[] vSrcNodeByte = new byte[5];
         Buffer.BlockCopy(vTempBytes, 0, vSrcNodeByte, 1, 4);
         uint vSrc = BitConverter.ToUInt32(vSrcNodeByte, 0);
         Buffer.BlockCopy(UnicomSN, 4, vTempBytes, 0, 4);
         string vDate = SGIPCommand.Bytes4ToInt(vTempBytes) + "";
         Buffer.BlockCopy(UnicomSN, 8, vTempBytes, 0, 4);
         string vNum = SGIPCommand.Bytes4ToInt(vTempBytes) + "";
         SequenceNumber = vSrc + vDate + vNum;
     }
     else
     {
         Buffer.BlockCopy(vSrcNode, 0, vCmdseq, 0, 4);
         Buffer.BlockCopy(vDateCmd, 0, vCmdseq, 4, 4);
         Buffer.BlockCopy(vSeqNum, 0, vCmdseq, 8, 4);
     }
     Buffer.BlockCopy(vCmdseq, 0, vCommandHeadbytes, 8, 12);
     return(vCommandHeadbytes);
 }