Ejemplo n.º 1
0
        /// <summary>
        /// 向客户端发送应答
        /// </summary>
        /// <param name="context"></param>
        /// <param name="resp"></param>
        private void DoResponse(IChannelHandlerContext context, PlatformResp resp)
        {
            // 构建消息体属性对象
            JT808MessageBodyAttr attr = new JT808MessageBodyAttr();

            attr.EncryptionType = 0;
            byte[] body = resp.Encode();
            attr.MsgBodyLength = body.Length;
            attr.IsSplit       = false;

            JT808MessageHead head = new JT808MessageHead();

            head.MessageId     = resp.GetMessageId();
            head.MessageSerial = GetFlowId(context.Channel);
            head.TerminalId    = resp.TerminalId;
            head.MsgBodyAttr   = attr;

            // 构建JT/T808协议消息对象
            JT808Message message = new JT808Message();

            message.MsgHeader = head;
            message.MsgBody   = body;

            byte[] reply = message.Encode();
            context.WriteAndFlushAsync(Unpooled.CopiedBuffer(reply));


            //ResponseData response = new ResponseData();
            //response.CmdID = message.MsgHeader.MessageId;
            //response.CmdSerialNo = message.MsgHeader.MessageSerial;
            //response.MsgBody = reply;
            //response.TerminalID = resp.TerminalId;
            //response.Time = response.GetTimeStamp();
            //context.WriteAndFlushAsync(response);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 解码为对象
        /// </summary>
        /// <param name="_2Bytes"></param>
        /// <returns></returns>
        public static JT808MessageBodyAttr Decode(short _2Bytes)
        {
            JT808MessageBodyAttr attr = new JT808MessageBodyAttr();

            // isSpilt ?
            int isSplit = _2Bytes >> 13 & 0x1;

            if (isSplit == 1)
            {
                attr.IsSplit = true;
            }

            // Encrypt type
            int encryptTypeVal = _2Bytes >> 10 & 0x1;

            if (encryptTypeVal == 1)
            {
                attr.EncryptionType = 1;
            }
            else
            {
                attr.EncryptionType = 0;
            }

            // Body length
            int bodyLen = _2Bytes & 0x3ff;

            attr.MsgBodyLength = bodyLen;

            return(attr);
        }