public UnconfirmedRequest(ServicesSupported services, ByteStream queue)
        {
            queue.ReadByte();
            byte choiceId = queue.ReadByte();

            Service = UnconfirmedRequestService.createUnconfirmedRequestService(services, choiceId, queue);
            if (Service == null)
            {
                throw new BACnetErrorException(ErrorClass.Device, ErrorCode.ServiceRequestDenied);
            }
        }
 public override void handle(LocalDevice localDevice, Address from, OctetString linkService)
 {
     try
     {
         ServicesSupported servicesSupported = (ServicesSupported)localDevice.Configuration.getProperty(
             PropertyIdentifier.ProtocolServicesSupported);
         if (servicesSupported.isUtcTimeSynchronization())
         {
             throw new NotImplementedException();
         }
         //localDevice.getEventHandler().synchronizeTime(time, true);
     }
     catch (BACnetServiceException e)
     {
         // no op
     }
 }
        public ConfirmedRequest(ServicesSupported servicesSupported, ByteStream queue)
        {
            byte b = queue.ReadByte();

            IsSegmentedMessage          = (b & 8) != 0;
            IsMoreFollows               = (b & 4) != 0;
            IsSegmentedResponseAccepted = (b & 2) != 0;

            b = queue.ReadByte();
            MaxSegmentsAccepted   = (MaxSegments)((byte)((b & 0x70) >> 4));
            MaxApduLengthAccepted = (MaxApduLength)((byte)(b & 0xf));
            InvokeId = queue.ReadByte();
            if (IsSegmentedMessage)
            {
                SequenceNumber     = queue.popU1B();
                ProposedWindowSize = queue.popU1B();
            }
            serviceChoice = queue.ReadByte();
            ServiceData   = new ByteStream(queue.ReadToEnd());

            ConfirmedRequestService.checkConfirmedRequestService(servicesSupported, serviceChoice);
        }
        internal static UnconfirmedRequestService createUnconfirmedRequestService(ServicesSupported services, byte type, ByteStream source)
        {
            if (type == IAmRequest.TYPE_ID)
            {
                if (services.isIAm())
                {
                    return(new IAmRequest(source));
                }
                return(null);
            }

            if (type == IHaveRequest.TYPE_ID)
            {
                if (services.isIHave())
                {
                    return(new IHaveRequest(source));
                }
                return(null);
            }

            /*
             * if (type == UnconfirmedCovNotificationRequest.TYPE_ID)
             * {
             *  if (services.isUnconfirmedCovNotification())
             *      return new UnconfirmedCovNotificationRequest(source);
             *  return null;
             * }
             *
             * if (type == UnconfirmedEventNotificationRequest.TYPE_ID)
             * {
             *  if (services.isUnconfirmedEventNotification())
             *      return new UnconfirmedEventNotificationRequest(source);
             *  return null;
             * }
             *
             * if (type == UnconfirmedPrivateTransferRequest.TYPE_ID)
             * {
             *  if (services.isUnconfirmedPrivateTransfer())
             *      return new UnconfirmedPrivateTransferRequest(source);
             *  return null;
             * }
             *
             * if (type == UnconfirmedTextMessageRequest.TYPE_ID)
             * {
             *  if (services.isUnconfirmedTextMessage())
             *      return new UnconfirmedTextMessageRequest(source);
             *  return null;
             * }
             *
             * if (type == TimeSynchronizationRequest.TYPE_ID)
             * {
             *  if (services.isTimeSynchronization())
             *      return new TimeSynchronizationRequest(source);
             *  return null;
             * }
             *
             * if (type == WhoHasRequest.TYPE_ID)
             * {
             *  if (services.isWhoHas())
             *      return new WhoHasRequest(source);
             *  return null;
             * }
             */

            if (type == WhoIsRequest.TYPE_ID)
            {
                if (services.isWhoIs())
                {
                    return(new WhoIsRequest(source));
                }
                return(null);
            }

            /*
             * if (type == UTCTimeSynchronizationRequest.TYPE_ID)
             * {
             *  if (services.isUtcTimeSynchronization())
             *      return new UTCTimeSynchronizationRequest(queue);
             *  return null;
             * }
             */

            throw new System.Exception("Unsupported unconfirmed service: " + (type & 0xff));
        }
 public static void checkConfirmedRequestService(ServicesSupported services, byte type)
 {/*
   * if (type == AcknowledgeAlarmRequest.TYPE_ID && services.isAcknowledgeAlarm()) // 0
   * return;
   * if (type == ConfirmedCovNotificationRequest.TYPE_ID && services.isConfirmedCovNotification()) // 1
   * return;
   * if (type == ConfirmedEventNotificationRequest.TYPE_ID && services.ConfirmedEventNotification()) // 2
   * return;
   * if (type == GetAlarmSummaryRequest.TYPE_ID && services.isGetAlarmSummary()) // 3
   * return;
   * if (type == GetEnrollmentSummaryRequest.TYPE_ID && services.isGetEnrollmentSummary()) // 4
   * return;
   * if (type == SubscribeCOVRequest.TYPE_ID && services.isSubscribeCov()) // 5
   * return;
   * if (type == AtomicReadFileRequest.TYPE_ID && services.isAtomicReadFile()) // 6
   * return;
   * if (type == AtomicWriteFileRequest.TYPE_ID && services.isAtomicWriteFile()) // 7
   * return;
   * if (type == AddListElementRequest.TYPE_ID && services.isAddListElement()) // 8
   * return;
   * if (type == RemoveListElementRequest.TYPE_ID && services.isRemoveListElement()) // 9
   * return;
   * if (type == CreateObjectRequest.TYPE_ID && services.isCreateObject()) // 10
   * return;
   * if (type == DeleteObjectRequest.TYPE_ID && services.isDeleteObject()) // 11
   * return;
   * if (type == ReadPropertyRequest.TYPE_ID && services.isReadProperty()) // 12
   * return;
   * if (type == ReadPropertyConditionalRequest.TYPE_ID && services.isReadPropertyConditional()) // 13
   * return;
   * if (type == ReadPropertyMultipleRequest.TYPE_ID && services.isReadPropertyMultiple()) // 14
   * return;
   * if (type == WritePropertyRequest.TYPE_ID && services.isWriteProperty()) // 15
   * return;
   * if (type == WritePropertyMultipleRequest.TYPE_ID && services.isWritePropertyMultiple()) // 16
   * return;
   * if (type == DeviceCommunicationControlRequest.TYPE_ID && services.isDeviceCommunicationControl()) // 17
   * return;
   * if (type == ConfirmedPrivateTransferRequest.TYPE_ID && services.isConfirmedPrivateTransfer()) // 18
   * return;
   * if (type == ConfirmedTextMessageRequest.TYPE_ID && services.isConfirmedTextMessage()) // 19
   * return;
   * if (type == ReinitializeDeviceRequest.TYPE_ID && services.isReinitializeDevice()) // 20
   * return;
   * if (type == VtOpenRequest.TYPE_ID && services.isVtOpen()) // 21
   * return;
   * if (type == VtCloseRequest.TYPE_ID && services.isVtClose()) // 22
   * return;
   * if (type == VtDataRequest.TYPE_ID && services.isVtData()) // 23
   * return;
   * if (type == AuthenticateRequest.TYPE_ID && services.isAuthenticate()) // 24
   * return;
   * if (type == RequestKeyRequest.TYPE_ID && services.isRequestKey()) // 25
   * return;
   * if (type == ReadRangeRequest.TYPE_ID && services.isReadRange()) // 26
   * return;
   * if (type == LifeSafetyOperationRequest.TYPE_ID && services.isLifeSafetyOperation()) // 27
   * return;
   * if (type == SubscribeCOVPropertyRequest.TYPE_ID && services.isSubscribeCovProperty()) // 28
   * return;
   * if (type == GetEventInformation.TYPE_ID && services.isGetEventInformation()) // 29
   * return;
   */
     throw new BACnetErrorException(ErrorClass.Device, ErrorCode.ServiceRequestDenied);
 }
Example #6
0
        // Event listeners
        //private readonly DeviceEventHandler eventHandler = new DeviceEventHandler();
        //private readonly DeviceEventHandler eventHandler = new DeviceEventAsyncHandler();

        public LocalDevice(uint deviceId, ApplicationLayer applicationLayer, string deviceName, string modelName)
        {
            this.applicationLayer   = applicationLayer;
            applicationLayer.Device = this;

            initEventHandlers();

            try
            {
                ObjectIdentifier deviceIdentifier = new ObjectIdentifier(ObjectType.Device, deviceId);

                configuration = new BACnetObject(this, deviceIdentifier);
                configuration.setProperty(PropertyIdentifier.MaxApduLengthAccepted, new UnsignedInteger(1476));
                configuration.setProperty(PropertyIdentifier.VendorIdentifier, new Unsigned16(VENDOR_ID));
                configuration.setProperty(PropertyIdentifier.VendorName, new CharacterString(VENDOR_STRING));
                configuration.setProperty(PropertyIdentifier.SegmentationSupported, Segmentation.SegmentedBoth);

                /*TODO SequenceOf<ObjectIdentifier> objectList = new SequenceOf<ObjectIdentifier>();
                 * objectList.add(deviceIdentifier);
                 * configuration.setProperty(PropertyIdentifier.objectList, objectList);*/

                // Set up the supported services indicators. Remove lines as services get implemented.
                ServicesSupported servicesSupported = new ServicesSupported();
                servicesSupported.SetAll(false);
                servicesSupported.AcknowledgeAlarm           = true;
                servicesSupported.ConfirmedCovNotification   = true;
                servicesSupported.ConfirmedEventNotification = true;
                servicesSupported.GetAlarmSummary            = true;
                servicesSupported.GetEnrollmentSummary       = true;
                servicesSupported.setGetEventInformation(true);
                servicesSupported.setIAm(true);
                servicesSupported.setIHave(true);
                servicesSupported.setReadProperty(true);
                servicesSupported.setReadPropertyMultiple(true);
                servicesSupported.setReinitializeDevice(true);
                servicesSupported.SubscribeCov = true;
                servicesSupported.setTimeSynchronization(true);
                servicesSupported.setUnconfirmedCovNotification(true);
                servicesSupported.setUnconfirmedEventNotification(true);
                servicesSupported.setWhoHas(true);
                servicesSupported.setWhoIs(true);
                servicesSupported.setWriteProperty(true);
                servicesSupported.setWritePropertyMultiple(true);
                servicesSupported.setDeviceCommunicationControl(true);

                //servicesSupported.setAll(true);
                //AdK
                //servicesSupported.setAcknowledgeAlarm(false);

                /*
                 * servicesSupported.setGetAlarmSummary(true);
                 * servicesSupported.setGetEnrollmentSummary(true);
                 * servicesSupported.setAtomicReadFile(false);
                 * servicesSupported.setAtomicWriteFile(false);
                 * servicesSupported.setAddListElement(false);
                 * servicesSupported.setRemoveListElement(false);
                 * servicesSupported.setReadPropertyConditional(false);
                 * servicesSupported.setDeviceCommunicationControl(false);
                 * servicesSupported.setReinitializeDevice(false);
                 * servicesSupported.setVtOpen(false);
                 * servicesSupported.setVtClose(false);
                 * servicesSupported.setVtData(false);
                 * servicesSupported.setAuthenticate(false);
                 * servicesSupported.setRequestKey(false);
                 * servicesSupported.setTimeSynchronization(true);
                 * servicesSupported.setReadRange(false);
                 * servicesSupported.setUtcTimeSynchronization(true);
                 * servicesSupported.setLifeSafetyOperation(false);
                 * //servicesSupported.setSubscribeCovProperty(true);
                 * //servicesSupported.setGetEventInformation(true);
                 */

                configuration.setProperty(PropertyIdentifier.ProtocolServicesSupported, servicesSupported);

                // Set up the object types supported.

                /* TODO ObjectTypesSupported objectTypesSupported = new ObjectTypesSupported();
                 * objectTypesSupported.setAll(false);
                 *
                 * objectTypesSupported.setDevice(true);
                 *
                 * objectTypesSupported.setAnalogInput(true);
                 * objectTypesSupported.setAnalogOutput(true);
                 * objectTypesSupported.setAnalogValue(true);
                 *
                 * objectTypesSupported.setBinaryInput(true);
                 * objectTypesSupported.setBinaryOutput(true);
                 * objectTypesSupported.setBinaryValue(true);
                 *
                 * objectTypesSupported.setMultiStateInput(true);
                 * objectTypesSupported.setMultiStateOutput(true);
                 * objectTypesSupported.setMultiStateValue(true);
                 *
                 * objectTypesSupported.setNotificationClass(true);
                 *
                 * configuration.setProperty(PropertyIdentifier.protocolObjectTypesSupported, objectTypesSupported);*/

                // Set some other required values to defaults
                configuration.setProperty(PropertyIdentifier.ObjectName, new CharacterString(deviceName));
                configuration.setProperty(PropertyIdentifier.SystemStatus, DeviceStatus.Operational);
                configuration.setProperty(PropertyIdentifier.ModelName, new CharacterString(modelName));
                configuration.setProperty(PropertyIdentifier.FirmwareRevision, new CharacterString(FIRMWARE_REVISION));
                configuration.setProperty(PropertyIdentifier.ApplicationSoftwareVersion, new CharacterString(APPLICATION_SOFTWARE_VERSION));
                configuration.setProperty(PropertyIdentifier.ProtocolVersion, new UnsignedInteger(1));
                configuration.setProperty(PropertyIdentifier.ProtocolRevision, new UnsignedInteger(0));
                configuration.setProperty(PropertyIdentifier.DatabaseRevision, new UnsignedInteger(0));
            }
            catch (BACnetServiceException e)
            {
                // Should never happen, but wrap in an unchecked just in case.
                throw new BACnetRuntimeException(e);
            }
        }