Beispiel #1
0
        public Deliver(byte[] bytes)
        {
            int i = 0;

            byte[] buffer = new byte[MessageHeader.Length];
            Buffer.BlockCopy(bytes, 0, buffer, 0, MessageHeader.Length);
            this._Header = new MessageHeader(buffer);

            string s = null;

            //MsgId 10
            //i += MessageHeader.Length;
            //buffer = new byte[10];
            //Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
            //s = Encoding.ASCII.GetString(buffer).Trim();
            //s = s.Substring(0, s.IndexOf('\0'));
            //this._MsgID = s;

            i     += MessageHeader.Length;
            buffer = new byte[10];
            Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
            Array.Reverse(buffer);
            this._MsgID = BitConverter.ToUInt32(buffer, 0);

            //IsReport 1
            i += 10;
            this._IsReport  = (uint)bytes[i++];
            this._MsgFormat = (uint)bytes[i++];

            //RecvTime 14
            buffer = new byte[14];
            Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
            s = Encoding.ASCII.GetString(buffer).Trim();
            if (s.IndexOf('\0') > 0)
            {
                s = s.Substring(0, s.IndexOf('\0'));
            }
            this._RecvTime = s;

            //SrcTermID 21
            i     += 14;
            buffer = new byte[21];
            Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
            s = Encoding.ASCII.GetString(buffer).Trim();
            if (s.IndexOf('\0') > 0)
            {
                s = s.Substring(0, s.IndexOf('\0'));
            }
            this._SrcTermID = s;

            // DestTermID 21
            i     += 21;
            buffer = new byte[21];
            Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
            s = Encoding.ASCII.GetString(buffer).Trim();
            if (s.IndexOf('\0') > 0)
            {
                s = s.Substring(0, s.IndexOf('\0'));
            }
            this._DestTermID = s;

            // MsgLength 1
            i += 21;
            this._MsgLength = (uint)bytes[i++];


            // MsgContent
            buffer = new byte[this._MsgLength];
            Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);

            if (this._IsReport == 1)
            {
                // 状态报告 保存至Report
                this._MsgContent = "";
                this._Report     = new byte[_MsgLength];
                Buffer.BlockCopy(buffer, 0, _Report, 0, _Report.Length);
            }
            else
            {
                // 短信 保存至Msg_Content
                switch (this._MsgFormat)
                {
                case 8:
                    this._MsgContent = Encoding.BigEndianUnicode.GetString(buffer).Trim();
                    break;

                case 15:     // gb2312
                    this._MsgContent = Encoding.GetEncoding("gb2312").GetString(buffer).Trim();
                    break;

                case 0:     // ascii
                case 3:     // 短信写卡操作
                case 4:     // 二进制信息
                default:
                    this._MsgContent = Encoding.ASCII.GetString(buffer).ToString();
                    break;
                }
            }
            // Reserve 8
            i     += (int)this._MsgLength;
            buffer = new byte[8];
            Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
            s = Encoding.ASCII.GetString(buffer).Trim();
            if (s.IndexOf('\0') > 0)
            {
                s = s.Substring(0, s.IndexOf('\0'));
            }
            this._Reserve = s;

            // tlv  --剩余全部
            i += 8;
            //  buffer = new byte[bytes.Length - i];
            //  Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
            ArrayList tmptlv = new ArrayList();

            for (; i < bytes.Length;)
            {
                // Tag 2
                buffer = new byte[2];
                Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
                Array.Reverse(buffer);
                short tlv_Tag = BitConverter.ToInt16(buffer, 0);

                // Length 2
                i     += 2;
                buffer = new byte[2];
                Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
                Array.Reverse(buffer);
                short tlv_Length = BitConverter.ToInt16(buffer, 0);
                i += 2;

                String tlv_Value = "";
                if (tlv_Tag == TlvId.Mserviceid || tlv_Tag == TlvId.SrcTermPseudo ||
                    tlv_Tag == TlvId.DestTermPseudo ||
                    tlv_Tag == TlvId.ChargeTermPseudo ||
                    tlv_Tag == TlvId.LinkID)
                {
                    buffer = new byte[tlv_Length];
                    Buffer.BlockCopy(bytes, i, buffer, 0, buffer.Length);
                    s = Encoding.ASCII.GetString(buffer).Trim();
                    if (s.IndexOf('\0') > 0)
                    {
                        s = s.Substring(0, s.IndexOf('\0'));
                    }
                    tlv_Value = s;
                    i        += tlv_Length;
                }
                else
                {
                    tlv_Value = ((uint)bytes[i++]).ToString();
                }

                if (tlv_Tag == (short)TlvId.TP_udhi)
                {
                    this._TP_udhi = uint.Parse(tlv_Value);
                }
                else if (tlv_Tag == (short)TlvId.LinkID)
                {
                    this._LinkID = tlv_Value;
                }
                else
                {
                    tmptlv.Add(new Tlv(tlv_Tag, tlv_Value));
                }

                if (tmptlv.Count > 0)
                {
                    this._OtherTlv = new Tlv[tmptlv.Count];
                    int j = 0;
                    foreach (Object tmp in tmptlv)
                    {
                        this.OtherTlv[j++] = (Tlv)tmp;
                    }
                }
                break;
            }
        }
Beispiel #2
0
 public Active_Test(uint Sequence_Id)
 {
     this._Header = new MessageHeader(MessageHeader.Length, SMGP3_COMMAND.Active_Test, Sequence_Id);
 }