예제 #1
0
        public virtual List <byte> Encode(XElement xParentElem)
        {
            packet = new List <byte>(0);
            PDU      pdu   = this;
            XElement xElem = (XElement)xParentElem.Elements().First(x => ((XElement)x).Name.ToString().StartsWith("PDU") == true);

            pdu = (PDU)System.Activator.CreateInstance(Type.GetType(this.GetType().Namespace.ToString() + "." + xElem.Name.ToString()));
            //If not the base class
            if (pdu.GetType().IsSubclassOf(this.GetType()))
            {
                packet.AddRange(pdu.Encode(xElem));
            }
            // Working here
            return(packet);
        }
예제 #2
0
        public Boolean Decode(BACPacket cm)
        {
            pciVersion = cm.getNextByte(); // PIC Version is allways 0x01

            if (pciVersion != 0x01)
            {
                return(false);
            }

            byte picByt = cm.getNextByte();

            messageType    = this.DecodeMType(picByt);
            destPresent    = this.DecodeDestonation(picByt);
            srcPresent     = this.DecodeSource(picByt);
            expectingReply = this.DecodeExpectingReply(picByt);
            priority       = this.DecodePriority(picByt);

            //IF it contains the destonation addr get it
            if (destPresent == PRESENCES.EXIST)
            {
                destAddr.Decode(cm);
            }

            //IF it contains the source addr get it
            if (srcPresent == PRESENCES.EXIST)
            {
                srcAddr.Decode(cm);
            }

            //IF it contains the destonation don't forget the hop count
            if (destPresent == PRESENCES.EXIST)
            {
                hopCnt = cm.getNextByte();
            }

            if (messageType == MTYPE.APPICATION)
            {
                pdu = pdu.Decode(cm);
            }
            else
            {
                nsdu = nsdu.Decode(cm);
            }

            return(true);
        }