Exemple #1
0
        private Choice read(ByteStream queue, IList types)
        {
            int       tContextId = peekTagNumber(queue);
            Encodable tDatum     = read(queue, (Type)types[tContextId], tContextId);

            return(new Choice(tContextId, tDatum));
        }
Exemple #2
0
        private void setPropertyImpl(PropertyIdentifier pid, Encodable value)
        {
            Encodable oldValue = (Encodable)properties[pid];

            properties[pid] = value;

            if (!value.Equals(oldValue))
            {
                // Check for subscriptions.
                if (ObjectCovSubscription.SendCovNotification(Id.ObjectType, pid, this.getCovIncrement()))
                {
                    //synchronized(covSubscriptions) {
                    long now = System.DateTime.Now.Ticks;
                    ObjectCovSubscription sub;
                    for (int i = covSubscriptions.Count - 1; i >= 0; i--)
                    {
                        sub = (ObjectCovSubscription)covSubscriptions[i];
                        if (sub.HasExpired(now))
                        {
                            covSubscriptions.RemoveAt(i);
                        }
                        else if (sub.IsNotificationRequired(pid, value))
                        {
                            sendCovNotification(sub, now);
                        }
                    }
                    //}
                }
            }
        }
Exemple #3
0
        public Choice(ByteStream queue, IList types)
        {
            Choice c = read(queue, types);

            ContextId = c.ContextId;
            Data      = c.Data;
        }
 internal ReadPropertyAck(ByteStream queue)
 {
     EventObjectIdentifier = (ObjectIdentifier)read(queue, typeof(ObjectIdentifier), 0);
     PropertyIdentifier    = (PropertyIdentifier)read(queue, typeof(PropertyIdentifier), 1);
     PropertyArrayIndex    = (UnsignedInteger)readOptional(queue, typeof(UnsignedInteger), 2);
     Value = readEncodable(queue, EventObjectIdentifier.ObjectType, PropertyIdentifier, PropertyArrayIndex, 3);
 }
Exemple #5
0
        /**
         * Determine if the newValue has surpassed the threshold value compared with the original value.
         * <p>
         * When the originalValue is null, it is automatically assumed to be outside the threshold, because it means the
         * property hasn't been seen before.
         * <p>
         * If any of the parameters cannot be converted to a {@link Float}, then this method returns true when the
         * original and new value are not equal and false otherwise.
         *
         * @param threshold
         *            The threshold value
         * @param originalValue
         *            The original or last sent value
         * @param newValue
         *            The new value to check
         * @return true if the new value is outside the threshold or false otherwise.
         */

        public static bool IsValueOutsideOfThreshold(Real threshold, Encodable originalValue, Encodable newValue)
        {
            float floatThreshold = ConvertEncodableToFloat(threshold);
            float floatOriginal  = ConvertEncodableToFloat(originalValue);
            float floatNewValue  = ConvertEncodableToFloat(newValue);

            // This property hasn't been seen before, so a notification is required
            if (originalValue == null)
            {
                return(true);
            }
            // Handle types that can't do threshold comparisons
            else if (floatThreshold == float.MinValue || floatOriginal == float.MinValue ||
                     floatNewValue == float.MinValue)
            {
                return(!originalValue.Equals(newValue));
            }
            else
            {
                // Due to floating point maths, it's possible that where the difference should be equal to the threshold
                // and not be outside the threshold actually evaluates to true due to precision errors.  However since
                // this threshold is calculated only for use in deciding whether to trigger a COV notification, small
                // margins of error on boundary cases are acceptable.
                return(Math.Abs(floatNewValue - floatOriginal) > floatThreshold);
            }
        }
Exemple #6
0
 public ConfirmedPrivateTransferError(byte choice, BACnetError error, UnsignedInteger vendorId,
                                      UnsignedInteger serviceNumber, BaseType errorParameters) : base(choice, error)
 {
     this.vendorId        = vendorId;
     this.serviceNumber   = serviceNumber;
     this.errorParameters = errorParameters;
 }
Exemple #7
0
        public Encodable getProperty(PropertyIdentifier pid, UnsignedInteger propertyArrayIndex)
        {
            Encodable result = getProperty(pid);

            if (propertyArrayIndex == null)
            {
                return(result);
            }

            if (!(result is SequenceOf))
            {
                throw new BACnetServiceException(ErrorClass.Property, ErrorCode.PropertyIsNotAnArray);
            }

            SequenceOf array = (SequenceOf )result;
            uint       index = propertyArrayIndex.Value;

            if (index == 0)
            {
                return(new UnsignedInteger((uint)array.Count));
            }

            if (index > array.getCount())
            {
                throw new BACnetServiceException(ErrorClass.Property, ErrorCode.InvalidArrayIndex);
            }

            return(array.Get((int)index));
        }
Exemple #8
0
 public UnconfirmedPrivateTransferRequest(UnsignedInteger vendorId, UnsignedInteger serviceNumber,
                                          Encodable serviceParameters)
 {
     this.vendorId          = vendorId;
     this.serviceNumber     = serviceNumber;
     this.serviceParameters = serviceParameters;
 }
 public PropertyValue(PropertyIdentifier propertyIdentifier, UnsignedInteger propertyArrayIndex, Encodable value,
                      UnsignedInteger priority)
 {
     this.PropertyIdentifier = propertyIdentifier;
     this.PropertyArrayIndex = propertyArrayIndex;
     this.Value    = value;
     this.Priority = priority;
 }
 public ReadPropertyAck(ObjectIdentifier eventObjectIdentifier, PropertyIdentifier propertyIdentifier,
                        UnsignedInteger propertyArrayIndex, Encodable value)
 {
     EventObjectIdentifier = eventObjectIdentifier;
     PropertyIdentifier    = propertyIdentifier;
     PropertyArrayIndex    = propertyArrayIndex;
     Value = value;
 }
Exemple #11
0
        public Choice(ByteStream queue, IList types, int contextId)
        {
            popStart(queue, contextId);
            Choice c = read(queue, types);

            popEnd(queue, contextId);
            ContextId = c.ContextId;
            Data      = c.Data;
        }
Exemple #12
0
 public SequenceOf(ByteStream queue, Type type, int contextId)
 {
     Values = new ArrayList();
     while (readEnd(queue) != contextId)
     {
         Encodable obj = read(queue, type);
         Values.Add(obj);
     }
 }
Exemple #13
0
 internal PropertyTypeDefinition(ObjectType objectType, PropertyIdentifier propertyIdentifier, Type type, bool sequence, bool required, Encodable defaultValue)
 {
     ObjectType         = objectType;
     PropertyIdentifier = propertyIdentifier;
     Type         = type;
     IsSequence   = sequence;
     IsRequired   = required;
     DefaultValue = defaultValue;
 }
Exemple #14
0
 public void removeAll(Encodable value)
 {
     /*for (IEnumerator it = values.GetEnumerator(); it.MoveNext();)
      * {
      * // TODO
      *  Encodable e = (Encodable) it.Current;
      *  if (ObjectUtils.equals(e, value))
      *      it.remove();
      * }*/
 }
Exemple #15
0
        public Encodable getPropertyRequired(PropertyIdentifier pid, UnsignedInteger propertyArrayIndex)
        {
            Encodable p = getProperty(pid, propertyArrayIndex);

            if (p == null)
            {
                throw new BACnetServiceException(ErrorClass.Property, ErrorCode.UnknownProperty);
            }
            return(p);
        }
Exemple #16
0
        public void set(int indexBase1, Encodable value)
        {
            int index = indexBase1 - 1;

            while (Values.Count <= index)
            {
                Values.Add(null);
            }
            Values[index] = value;
        }
Exemple #17
0
        //
        //
        // Set property
        //
        public void setProperty(PropertyIdentifier pid, Encodable value)
        {
            ObjectProperties.validateValue(Id.ObjectType, pid, value);
            setPropertyImpl(pid, value);

            // If the relinquish default was set, make sure the present value gets updated as necessary.
            if (pid.Equals(PropertyIdentifier.RelinquishDefault))
            {
                setCommandableImpl((PriorityArray)getProperty(PropertyIdentifier.PriorityArray));
            }
        }
Exemple #18
0
 protected EncoderOpCodeHandler(Code code, uint opCode, int groupIndex, Encodable encodable, OperandSize opSize, AddressSize addrSize, TryConvertToDisp8N tryConvertToDisp8N, Op[] operands)
 {
     TEST_Code          = code;
     OpCode             = opCode;
     GroupIndex         = groupIndex;
     Encodable          = encodable;
     OpSize             = opSize;
     AddrSize           = addrSize;
     TryConvertToDisp8N = tryConvertToDisp8N;
     Operands           = operands;
 }
Exemple #19
0
 public bool contains(Encodable value)
 {
     foreach (Encodable e in Values)
     {
         if (value.Equals(e))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #20
0
 protected OpCodeHandler(uint opCode, int groupIndex, OpCodeHandlerFlags flags, Encodable encodable, OperandSize opSize, AddressSize addrSize, TryConvertToDisp8N?tryConvertToDisp8N, Op[] operands)
 {
     OpCode             = opCode;
     GroupIndex         = groupIndex;
     Flags              = flags;
     Encodable          = encodable;
     OpSize             = opSize;
     AddrSize           = addrSize;
     TryConvertToDisp8N = tryConvertToDisp8N;
     Operands           = operands;
 }
Exemple #21
0
        /**
         * Convert the given encodable value to a {@link Float} if possible.
         *
         * @param value
         *            The value to attempt to convert to a {@link Float}.
         * @return A {@link Float} value if the {@link Encodable} can be converted, otherwise null.
         */

        private static float ConvertEncodableToFloat(Encodable value)
        {
            float floatValue = float.MinValue; // TODO

            if (value is Real)
            {
                floatValue = ((Real)value).Value;
            }

            return(floatValue);
        }
Exemple #22
0
 public void add(Encodable value)
 {
     for (int i = 0; i < Values.Count; i++)
     {
         if (Values[i] == null)
         {
             Values[i] = value;
             return;
         }
     }
     Values.Add(value);
 }
Exemple #23
0
        public void setProperty(PropertyIdentifier pid, uint indexBase1, Encodable value)
        {
            ObjectProperties.validateSequenceValue(Id.ObjectType, pid, value);
            SequenceOf list = (SequenceOf)properties[pid];

            if (list == null)
            {
                list = new SequenceOf();
                setPropertyImpl(pid, list);
            }
            list.set((int)indexBase1, value);
        }
 public ActionCommand(ObjectIdentifier deviceIdentifier, ObjectIdentifier objectIdentifier,
                      PropertyIdentifier propertyIdentifier, UnsignedInteger propertyArrayIndex, Encodable propertyValue,
                      UnsignedInteger priority, UnsignedInteger postDelay, BBoolean quitOnFailure, BBoolean writeSuccessful)
 {
     DeviceIdentifier   = deviceIdentifier;
     ObjectIdentifier   = objectIdentifier;
     PropertyIdentifier = propertyIdentifier;
     PropertyArrayIndex = propertyArrayIndex;
     PropertyValue      = propertyValue;
     Priority           = priority;
     PostDelay          = postDelay;
     QuitOnFailure      = quitOnFailure;
     WriteSuccessful    = writeSuccessful;
 }
Exemple #25
0
        public void setCommandable(Encodable value, UnsignedInteger priority)
        {
            uint pri = 16;

            if (priority != null)
            {
                pri = priority.Value;
            }

            PriorityArray priorityArray = (PriorityArray)getProperty(PropertyIdentifier.PriorityArray);

            priorityArray.set((int)pri, createCommandValue(value));
            setCommandableImpl(priorityArray);
        }
Exemple #26
0
        /**
         * Determine if a notification needs to be sent out based on the Threshold if relevant.
         *
         * @param pid
         *            The {@link PropertyIdentifier} being updated
         * @param value
         *            The new value
         * @return true if a COV notification should be sent out, false otherwise.
         */

        public bool IsNotificationRequired(PropertyIdentifier pid, Encodable value)
        {
            Encodable lastSentValue = (Encodable)lastSentValues[pid];

            bool notificationRequired = ThresholdCalculator.IsValueOutsideOfThreshold(this.covIncrement,
                                                                                      lastSentValue,
                                                                                      value);

            if (notificationRequired)
            {
                lastSentValues[pid] = value;
            }

            return(notificationRequired);
        }
Exemple #27
0
        public void remove(Encodable value)
        {
            if (value == null)
            {
                return;
            }

            for (int i = 0; i < Values.Count; i++)
            {
                if (value.Equals(Values[i]))
                {
                    remove(i + 1);
                    break;
                }
            }
        }
Exemple #28
0
 private static void AddValue(BACnetObject obj, IList values, PropertyIdentifier pid)
 {
     try
     {
         // Ensure that the obj has the given property. The addition of doorAlarmState requires this.
         if (ObjectProperties.getPropertyTypeDefinition(obj.Id.ObjectType, pid) != null)
         {
             Encodable value = obj.getProperty(pid);
             if (value != null)
             {
                 values.Add(new PropertyValue(pid, value));
             }
         }
     }
     catch (BACnetServiceException e)
     {
         // Should never happen, so wrap in a RuntimeException
         throw e;
     }
 }
Exemple #29
0
        private void setCommandableImpl(PriorityArray priorityArray)
        {
            PriorityValue priorityValue = null;

            foreach (PriorityValue priv in priorityArray)
            {
                if (!priv.IsNull)
                {
                    priorityValue = priv;
                    break;
                }
            }

            Encodable newValue = getProperty(PropertyIdentifier.RelinquishDefault);

            if (priorityValue != null)
            {
                newValue = priorityValue.Value;
            }

            setPropertyImpl(PropertyIdentifier.PresentValue, newValue);
        }
Exemple #30
0
        private PriorityValue createCommandValue(Encodable value)
        {
            if (value is Null)
            {
                return(new PriorityValue((Null)value));
            }

            ObjectType type = (ObjectType)getProperty(PropertyIdentifier.ObjectType);

            if (type.Equals(ObjectType.AccessDoor))
            {
                return(new PriorityValue((BaseType)value));
            }
            if (type.Equals(ObjectType.AnalogOutput) || type.Equals(ObjectType.AnalogValue))
            {
                return(new PriorityValue((Real)value));
            }
            if (type.Equals(ObjectType.BinaryOutput) || type.Equals(ObjectType.BinaryValue))
            {
                return(new PriorityValue((BinaryPV)value));
            }
            return(new PriorityValue((UnsignedInteger)value));
        }