コード例 #1
0
ファイル: Router.cs プロジェクト: kyanha/bacnet-browser
 public bool Decode(byte[] buf, ref int iptr)
 {
     networkNumber = BACnetUtil.ExtractUInt16(buf, ref iptr);
     portID        = buf[iptr++];
     portInfoLen   = buf[iptr++];
     if (portInfoLen != 0)
     {
         // we are not ready to handle this.
         throw new Exception("m0154-Cannot deal with portInfoLen > 0");
     }
     iptr += (int)portInfoLen;
     return(true);
 }
コード例 #2
0
ファイル: ADR.cs プロジェクト: kyanha/bacnet-browser
        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;
            }
        }
コード例 #3
0
ファイル: ADR.cs プロジェクト: kyanha/bacnet-browser
        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??");
            }
        }
コード例 #4
0
 public void Encode(byte[] buffer, ref int pos)
 {
     BACnetUtil.EncodeContextTag(buffer, ref pos, 0, (int)(((UInt32)objectType << 22) | objectInstance), 4);
 }
コード例 #5
0
        public void EncodeApplicationTag(byte[] buffer, ref int pos)
        {
            UInt32 objid = ((UInt32)objectType << 22) | (objectInstance & 0x3ffffff);

            BACnetUtil.InsertApplicationTag(buffer, ref pos, BACnetEnums.BACNET_APPLICATION_TAG.BACNET_APPLICATION_TAG_OBJECT_ID, objid);
        }
コード例 #6
0
        // the better method is to populate the pkt structure, then call encode...
        public static void ReadPropertyObjectList_deprecated(BACnetManager bnm, Device device)
        {
            byte[] data = new byte[1024];
            int    optr = 0;

            // BVLC Part
            // http://www.bacnetwiki.com/wiki/index.php?title=BACnet_Virtual_Link_Control

            data[optr++] = BACnetEnums.BACNET_BVLC_TYPE_BIP;                                  // 81
            data[optr++] = (byte)BACnetEnums.BACNET_BVLC_FUNCTION.BVLC_ORIGINAL_UNICAST_NPDU; //0a

            int store_length_here = optr;

            optr += 2;

            // Start of NPDU
            // http://www.bacnetwiki.com/wiki/index.php?title=NPDU

            data[optr++] = 0x01;            //  Version
            data[optr++] = 0x24;            //  NCPI - Dest present, expecting reply

            if (device.adr != null)
            {
                device.adr.Encode(data, ref optr);
            }
            else
            {
                // this means we have an ethernet/IP address for a MAC address. At present
                // we then dont know the network number
                // todo - resolve the network number issue
                ADR tempAdr = new ADR(0, device.directlyConnectedIPEndPointOfDevice);
                tempAdr.Encode(data, ref optr);
            }

            data[optr++] = 0xff;            // Hopcount


            // APDU start
            // http://www.bacnetwiki.com/wiki/index.php?title=APDU


            // Unconfirmed Request
            // Structure described here http://www.bacnetwiki.com/wiki/index.php?title=BACnet-Confirmed-Request-PDU

            data[optr++] = 0x02;            //  PDU Type=0 and SA=1
            data[optr++] = 0x04;            //  Max Resp (Encoded)

            data[optr++] = 0x01;            //  Invoke ID

            data[optr++] = 0x0c;            //  Service Choice 12 = ReadProperty

            // Service Request

            // Object type, instance (Device Object)
            device.deviceObjectID.Encode(data, ref optr);

            // Property Identifier (Object List)

            data[optr++] = 0x19;            //  19  Context Tag: 1, Length/Value/Type: 1
            data[optr++] = 0x4c;            //  4c  Property Identifier: object-list (76)

            BACnetUtil.InsertInt16(data, ref store_length_here, optr);

            bnm.insideSocket.OurSendTo(data, optr, device.packet.directlyConnectedIPEndPointOfDevice);
        }