Class SGrDeviceBase<D extends com.smartgridready.ns.v0.DeviceFrame,​F extends com.smartgridready.ns.v0.FunctionalProfileBase,​P extends com.smartgridready.ns.v0.DataPointBase>

  • Type Parameters:
    D - The type of device specification.
    F - The type of functional profile.
    P - The type of data point.
    All Implemented Interfaces:
    GenDeviceApi
    Direct Known Subclasses:
    SGrContactsDevice, SGrGenericDevice, SGrMessagingDevice, SGrModbusDevice, SGrRestApiDevice

    public abstract class SGrDeviceBase<D extends com.smartgridready.ns.v0.DeviceFrame,​F extends com.smartgridready.ns.v0.FunctionalProfileBase,​P extends com.smartgridready.ns.v0.DataPointBase>
    extends java.lang.Object
    implements GenDeviceApi
    Base class for all kinds of device communication interfaces.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected D device
      The interface-specific device specification.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected SGrDeviceBase​(D device)
      Constructs a new instance.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected static <P extends com.smartgridready.ns.v0.DataPointBase>
      Value
      applyUnitConversion​(P dataPoint, Value value, java.util.function.DoubleBinaryOperator conversionFunction)
      Performs conversion of units of measurements on a data point.
      boolean canSubscribe()
      Checks whether the device can subscribe to data points.
      protected java.util.Optional<java.lang.String> checkOutOfRange​(Value[] values, double limit, SGrDeviceBase.Comparator comparator)
      Checks if a value is beyond its valid range.
      void checkOutOfRange​(Value[] values, com.smartgridready.ns.v0.DataPointBase dataPoint)
      Tests an array of SGr values against upper and lower bounds of a given data point.
      void checkReadWritePermission​(com.smartgridready.ns.v0.DataPointBase dataPoint, SGrDeviceBase.RwpDirections direction)
      Tests a given data point's read or write permissions.
      protected static double divide​(double dividend, double divisor)
      Divides two numbers.
      protected P findDataPoint​(java.lang.String profileName, java.lang.String dataPointName)
      Finds a data point by functional profile and data point name.
      protected abstract java.util.Optional<P> findDataPointForProfile​(F functionalProfile, java.lang.String dataPointName)
      Finds a data point of a given functional profile by name.
      protected abstract java.util.Optional<F> findProfile​(java.lang.String profileName)
      Finds a functional profile by name.
      DataPoint getDataPoint​(java.lang.String functionalProfileName, java.lang.String dataPointName)
      Get a data point
      java.util.List<DataPoint> getDataPoints​(java.lang.String functionalProfileName)
      Get all data points of a functional profile
      java.util.List<ConfigurationValue> getDeviceConfigurationInfo()
      Get the device interface configuration parameters
      DeviceInfo getDeviceInfo()
      Get device information
      FunctionalProfile getFunctionalProfile​(java.lang.String functionalProfileName)
      Get a functional profile
      java.util.List<FunctionalProfile> getFunctionalProfiles()
      Get all functional profiles
      java.util.List<DataPointValue> getValues()
      Get value of all data points in one go
      protected static boolean isNumeric​(Value value)
      Tells if a value contains a number.
      protected static double multiply​(double factor1, double factor2)
      Multiplies two numbers.
      void subscribe​(java.lang.String profileName, java.lang.String dataPointName, java.util.function.Consumer<io.vavr.control.Either<java.lang.Throwable,​Value>> callbackFunction)
      Subscribes to messages that are related to the given data point
      void unsubscribe​(java.lang.String profileName, java.lang.String dataPointName)
      Unsubscribes from messages that are related to a given data point
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • device

        protected final D extends com.smartgridready.ns.v0.DeviceFrame device
        The interface-specific device specification.
    • Constructor Detail

      • SGrDeviceBase

        protected SGrDeviceBase​(D device)
        Constructs a new instance.
        Parameters:
        device - the generic device specification
    • Method Detail

      • findProfile

        protected abstract java.util.Optional<F> findProfile​(java.lang.String profileName)
        Finds a functional profile by name.
        Parameters:
        profileName - the name of the functional profile
        Returns:
        an optional functional profile
      • findDataPointForProfile

        protected abstract java.util.Optional<P> findDataPointForProfile​(F functionalProfile,
                                                                         java.lang.String dataPointName)
        Finds a data point of a given functional profile by name.
        Parameters:
        functionalProfile - the functional profile
        dataPointName - the name of the data point to find
        Returns:
        an optional data point
      • findDataPoint

        protected P findDataPoint​(java.lang.String profileName,
                                  java.lang.String dataPointName)
                           throws com.smartgridready.driver.api.common.GenDriverException
        Finds a data point by functional profile and data point name.
        Parameters:
        profileName - the functional profile name
        dataPointName - the data point name
        Returns:
        a generic data point
        Throws:
        com.smartgridready.driver.api.common.GenDriverException - if the device specification contains errors
      • checkOutOfRange

        public void checkOutOfRange​(Value[] values,
                                    com.smartgridready.ns.v0.DataPointBase dataPoint)
                             throws com.smartgridready.driver.api.common.GenDriverException
        Tests an array of SGr values against upper and lower bounds of a given data point.
        Parameters:
        values - the values to test
        dataPoint - the data point to test against
        Throws:
        com.smartgridready.driver.api.common.GenDriverException - when one or more values are out of bounds
      • checkReadWritePermission

        public void checkReadWritePermission​(com.smartgridready.ns.v0.DataPointBase dataPoint,
                                             SGrDeviceBase.RwpDirections direction)
                                      throws com.smartgridready.driver.api.common.GenDriverException
        Tests a given data point's read or write permissions.
        Parameters:
        dataPoint - the data point to test
        direction - the permission to test against
        Throws:
        com.smartgridready.driver.api.common.GenDriverException - on generic error
      • checkOutOfRange

        protected java.util.Optional<java.lang.String> checkOutOfRange​(Value[] values,
                                                                       double limit,
                                                                       SGrDeviceBase.Comparator comparator)
                                                                throws com.smartgridready.driver.api.common.GenDriverException
        Checks if a value is beyond its valid range.
        Parameters:
        values - the values to test
        limit - the bounds
        comparator - the comparator function
        Returns:
        an empty instance
        Throws:
        com.smartgridready.driver.api.common.GenDriverException - if at least one value is out of range
      • getDeviceInfo

        public DeviceInfo getDeviceInfo()
                                 throws com.smartgridready.driver.api.common.GenDriverException
        Description copied from interface: GenDeviceApi
        Get device information
        Specified by:
        getDeviceInfo in interface GenDeviceApi
        Returns:
        The device information
        Throws:
        com.smartgridready.driver.api.common.GenDriverException - Generic error while reading from the device
      • getFunctionalProfiles

        public java.util.List<FunctionalProfile> getFunctionalProfiles()
                                                                throws com.smartgridready.driver.api.common.GenDriverException
        Description copied from interface: GenDeviceApi
        Get all functional profiles
        Specified by:
        getFunctionalProfiles in interface GenDeviceApi
        Returns:
        The functional profiles
        Throws:
        com.smartgridready.driver.api.common.GenDriverException - Generic error while reading from the device
      • getFunctionalProfile

        public FunctionalProfile getFunctionalProfile​(java.lang.String functionalProfileName)
                                               throws com.smartgridready.driver.api.common.GenDriverException
        Description copied from interface: GenDeviceApi
        Get a functional profile
        Specified by:
        getFunctionalProfile in interface GenDeviceApi
        Parameters:
        functionalProfileName - The name of the functional profile
        Returns:
        The functional profile
        Throws:
        com.smartgridready.driver.api.common.GenDriverException - Generic error while reading from the device
      • getDataPoints

        public java.util.List<DataPoint> getDataPoints​(java.lang.String functionalProfileName)
                                                throws com.smartgridready.driver.api.common.GenDriverException
        Description copied from interface: GenDeviceApi
        Get all data points of a functional profile
        Specified by:
        getDataPoints in interface GenDeviceApi
        Parameters:
        functionalProfileName - The name of the functional profile
        Returns:
        The data points
        Throws:
        com.smartgridready.driver.api.common.GenDriverException - Generic error while reading from the device
      • getDataPoint

        public DataPoint getDataPoint​(java.lang.String functionalProfileName,
                                      java.lang.String dataPointName)
                               throws com.smartgridready.driver.api.common.GenDriverException
        Description copied from interface: GenDeviceApi
        Get a data point
        Specified by:
        getDataPoint in interface GenDeviceApi
        Parameters:
        functionalProfileName - The name of the functional profile
        dataPointName - The name of the data point
        Returns:
        The data point
        Throws:
        com.smartgridready.driver.api.common.GenDriverException - Generic error while reading from the device
      • getValues

        public java.util.List<DataPointValue> getValues()
                                                 throws com.smartgridready.driver.api.common.GenDriverException
        Description copied from interface: GenDeviceApi
        Get value of all data points in one go
        Specified by:
        getValues in interface GenDeviceApi
        Returns:
        The values read from the device, by data point
        Throws:
        com.smartgridready.driver.api.common.GenDriverException - Generic error while reading from the device
      • canSubscribe

        public boolean canSubscribe()
        Description copied from interface: GenDeviceApi
        Checks whether the device can subscribe to data points.
        Specified by:
        canSubscribe in interface GenDeviceApi
        Returns:
        true if subscribe possible, false otherwise
      • subscribe

        public void subscribe​(java.lang.String profileName,
                              java.lang.String dataPointName,
                              java.util.function.Consumer<io.vavr.control.Either<java.lang.Throwable,​Value>> callbackFunction)
                       throws com.smartgridready.driver.api.common.GenDriverException
        Description copied from interface: GenDeviceApi
        Subscribes to messages that are related to the given data point
        Specified by:
        subscribe in interface GenDeviceApi
        Parameters:
        profileName - The functional profile name
        dataPointName - The data point name
        callbackFunction - A callback function that provides the received value
        Throws:
        com.smartgridready.driver.api.common.GenDriverException - if an error occurs
      • unsubscribe

        public void unsubscribe​(java.lang.String profileName,
                                java.lang.String dataPointName)
                         throws com.smartgridready.driver.api.common.GenDriverException
        Description copied from interface: GenDeviceApi
        Unsubscribes from messages that are related to a given data point
        Specified by:
        unsubscribe in interface GenDeviceApi
        Parameters:
        profileName - The functional profile name
        dataPointName - The data point name
        Throws:
        com.smartgridready.driver.api.common.GenDriverException - if an error occurs
      • applyUnitConversion

        protected static <P extends com.smartgridready.ns.v0.DataPointBase> Value applyUnitConversion​(P dataPoint,
                                                                                                      Value value,
                                                                                                      java.util.function.DoubleBinaryOperator conversionFunction)
        Performs conversion of units of measurements on a data point.
        Type Parameters:
        P - the generic type of data point
        Parameters:
        dataPoint - the data point instance
        value - the value to convert
        conversionFunction - the converter function
        Returns:
        the converted value
      • isNumeric

        protected static boolean isNumeric​(Value value)
        Tells if a value contains a number.
        Parameters:
        value - the SGr value to test
        Returns:
        a boolean
      • divide

        protected static double divide​(double dividend,
                                       double divisor)
        Divides two numbers.
        Parameters:
        dividend - the dividend
        divisor - the divisor
        Returns:
        the division result
      • multiply

        protected static double multiply​(double factor1,
                                         double factor2)
        Multiplies two numbers.
        Parameters:
        factor1 - the first factor
        factor2 - the second factor
        Returns:
        the multiplication result