public void Decode(byte[] buffer, ref int pos)
        {
            networkNumber  = (uint)buffer[pos++] << 8;
            networkNumber |= buffer[pos++];

            MACaddress.length = buffer[pos++];

            switch (MACaddress.length)
            {
            case 0:
                // indicates a broadcast, perfectly legal.
                break;

            case 1:
                MACaddress.uintMACaddress = buffer[pos++];
                break;

            case 6:
                // extract the IP address
                myIPEndPoint ipep = new myIPEndPoint();
                ipep.Decode(buffer, pos);
                MACaddress.ipMACaddress = ipep;
                pos += 6;
                break;

            default:
                BACnetLibraryCL.Panic("Illegal MAC address length??");
                break;
            }
        }
Exemple #2
0
        public void Decode(byte[] buffer, ref int pos)
        {
            networkNumber = BACnetUtil.ExtractUInt16(buffer, ref pos);

            if (networkNumber == 0)
            {
                throw new Exception("m0205-Illegal network number of 0 in decode");
            }

            switch (buffer[pos++])
            {
            case 0:
                // indicates a remote, or possibly a global, broadcast, perfectly legal.
                isBroadcast      = true;
                isLocalBroadcast = false;
                if (networkNumber != 0xffff)
                {
                    isRemoteBroadcast = true;
                }
                else
                {
                    // a remote b'cast with a dest network number is a global broadcast
                    isRemoteBroadcast = false;
                }
                break;

            case 1:
                MACaddress = new BACnetMACaddress(buffer[pos++]);
                //MACaddress.length = buffer[pos++];
                //MACaddress.uintMACaddress = buffer[pos++];
                break;

            case 6:
                // extract the IP address
                myIPEndPoint ipep = new myIPEndPoint();
                ipep.Decode(buffer, ref pos);
                MACaddress = new BACnetMACaddress(ipep);
                //MACaddress.ipMACaddress = ipep;
                // pos += 6;
                break;

            default:
                throw new Exception("m0178-Illegal MAC address length??");
                //break;
            }
        }
Exemple #3
0
        public virtual void Decode(byte[] buffer, ref int pos, bool tolerate0NN)
        {
            networkNumber = BACnetUtil.ExtractUInt16(buffer, ref pos);

            if (!tolerate0NN && networkNumber == 0)
            {
                throw new Exception("m0161-Illegal network number of 0 in decode");

                // So there is at least one router out there that includes a 0 in the NN part of the SADR when sending a who-is-router. This is benign, because routers
                // broadcast their i-am routers. In any event FOR NOW, tolerate this transgression or else comms will not happen on these networks.
                // but we do need to find a cleaner way of dealing with this!!
            }


            switch (buffer[pos++])
            {
            case 0:
                // illegal for sadr
                throw new Exception("m0506-MAC length of 0 illegal for SADR");

            // break;
            case 1:
                MACaddress = new BACnetMACaddress(buffer[pos++]);
                break;

            case 6:
                // extract the IP address
                myIPEndPoint ipep = new myIPEndPoint();
                ipep.Decode(buffer, ref pos);
                MACaddress = new BACnetMACaddress(ipep);
                //MACaddress.ipMACaddress = ipep;
                break;

            default:
                throw new Exception("m0178-Illegal MAC address length??");
            }
        }