示例#1
0
        public List <byte> Encode(XElement xElem)
        {
            packet = new List <byte>(0);
            packet.Add(0x81);
            var field = xElem.Element("Function").Value;

            function = (BVLL_IP_Fnct)System.Enum.Parse(typeof(BVLL_IP_Fnct), field, true);
            packet.Add((byte)function);
            packet.Add(0); // Lenght bytes
            packet.Add(0); // Lenght bytes
            switch (function)
            {
            case BVLL_IP_Fnct.ORIGINAL_UNICAST_NPDU:
                NPCI pic = new NPCI();
                packet.AddRange(pic.Encode(xElem));
                break;

            case BVLL_IP_Fnct.ORIGINAL_BROADCAST_NPDU:
                //NPCI pic1 = new NPCI();
                //pic1.Decode(cm);
                break;

            default:
                break;
            }
            packet[2] = (byte)(packet.Count >> 16);
            packet[3] = (byte)packet.Count;

            packet.Add(0); // Lenght bytes
            return(packet);
        }
示例#2
0
        public Boolean Decode(BACPacket cm)
        {
            if (0 == cm.getNextByte().CompareTo(0x81))
            {
                function = (BVLL_IP_Fnct)cm.getNextByte();
                length   = cm.getNextByte();
                length   = (UInt16)(length << 4);
                length  += cm.getNextByte();
                cm.setLength(length);

                switch (function)
                {
                case BVLL_IP_Fnct.ORIGINAL_UNICAST_NPDU:
                    NPCI pic = new NPCI();
                    pic.Decode(cm);
                    inner = pic.ToString();
                    System.Console.WriteLine(ToString());
                    break;

                case BVLL_IP_Fnct.ORIGINAL_BROADCAST_NPDU:
                    NPCI pic1 = new NPCI();
                    pic1.Decode(cm);
                    inner = pic1.ToString();
                    System.Console.WriteLine(ToString());
                    break;

                default:
                    break;
                }
                return(true);
            }

            return(false);
        }