public BACnetPacket waitForPacket(int timeout, BACnetEnums.BACNET_UNCONFIRMED_SERVICE bus)
 {
     do
     {
         BACnetPacket pkt = waitForPacket(timeout);
         if (pkt.messageType == BACnetPacket.MESSAGE_TYPE.APPLICATION &&
             pkt.pduType == BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST &&
             pkt.unconfirmedServiceChoice == bus)
         {
             return(pkt);
         }
     } while (true);
 }
Exemple #2
0
        private bool DecodeUnconfirmedService(byte[] apdu_buf, int apduLen)
        {
            // todo, this code assumes that the service is encoded in postion number one. This is not always the case. Resolve

            if ((apdu_buf[0] & 0x0f) != 0)
            {
                _apm.MessageProtocolError("m0025 this nibble should be zero for Unconfirmed services");
                return(false);
            }

            if (apdu_buf[1] == (byte)BACnetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_WHO_IS)
            {
                // http://www.bacnetwiki.com/wiki/index.php?title=Who-Is

                apduUnconfirmedServiceFlag = true;
                unconfirmedServiceChoice   = BACnetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_WHO_IS;

                if (apduLen != 2)
                {
                    int offset = 2;

                    // means we must have a low and high range..
                    lowRange  = BACnetEncoding.DecodeTagContextUint(apdu_buf, ref offset, 0);
                    highRange = BACnetEncoding.DecodeTagContextUint(apdu_buf, ref offset, 1);
                }

                // and for now, we will assume only workstations issue who-is messages.
                this.srcDevice.type = BACnetEnums.DEVICE_TYPE.Workstation;
            }
            else if (apdu_buf[1] == (byte)BACnetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_I_AM)
            {
                apduUnconfirmedServiceFlag = true;
                unconfirmedServiceChoice   = BACnetEnums.BACNET_UNCONFIRMED_SERVICE.SERVICE_UNCONFIRMED_I_AM;

                // I-Am described right here: http://www.bacnetwiki.com/wiki/index.php?title=I-Am

                // first encoded entity is the Device Identifier...
                // Encoding described here: http://www.bacnetwiki.com/wiki/index.php?title=Encoding

                // Decode Device Identifier

                int offset = 2;

                srcDevice.deviceObjectID.DecodeApplicationTag(apdu_buf, ref offset);
                Console.WriteLine("This is device: " + srcDevice.deviceObjectID);

                // todo, for now, we will ignore device insance xxx if received
                // and we are the client (bacnet browser )

                srcDevice.packet = this;

                uint maxAPDULen;

                offset += BACnetEncoding.BACnetDecode_uint(apdu_buf, offset, out maxAPDULen);

                Console.WriteLine("Max APDU length accepted: " + maxAPDULen);

                uint segmentation_supported;

                offset += BACnetEncoding.BACnetDecode_uint(apdu_buf, offset, out segmentation_supported);

                Console.WriteLine("Segmentation Supported: " + segmentation_supported);

                srcDevice.SegmentationSupported = (BACnetEnums.BACNET_SEGMENTATION)segmentation_supported;



                uint vendorId;

                offset += BACnetEncoding.BACnetDecode_uint(apdu_buf, offset, out vendorId);

                Console.WriteLine("VendorId: " + vendorId);

                srcDevice.VendorId = vendorId;
            }
            return(true);
        }