Class SGrDeviceBase<D extends com.smartgridready.ns.v0.DeviceFrame,F extends com.smartgridready.ns.v0.FunctionalProfileBase,P extends com.smartgridready.ns.v0.DataPointBase>
- java.lang.Object
-
- com.smartgridready.communicator.common.impl.SGrDeviceBase<D,F,P>
-
- 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSGrDeviceBase.ComparatorComparators.static classSGrDeviceBase.RwpDirectionsCollection of access permissions.
-
Constructor Summary
Constructors Modifier Constructor Description protectedSGrDeviceBase(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>
ValueapplyUnitConversion(P dataPoint, Value value, java.util.function.DoubleBinaryOperator conversionFunction)Performs conversion of units of measurements on a data point.booleancanSubscribe()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.voidcheckOutOfRange(Value[] values, com.smartgridready.ns.v0.DataPointBase dataPoint)Tests an array of SGr values against upper and lower bounds of a given data point.voidcheckReadWritePermission(com.smartgridready.ns.v0.DataPointBase dataPoint, SGrDeviceBase.RwpDirections direction)Tests a given data point's read or write permissions.protected static doubledivide(double dividend, double divisor)Divides two numbers.protected PfindDataPoint(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.DataPointgetDataPoint(java.lang.String functionalProfileName, java.lang.String dataPointName)Get a data pointjava.util.List<DataPoint>getDataPoints(java.lang.String functionalProfileName)Get all data points of a functional profilejava.util.List<ConfigurationValue>getDeviceConfigurationInfo()Get the device interface configuration parametersDeviceInfogetDeviceInfo()Get device informationFunctionalProfilegetFunctionalProfile(java.lang.String functionalProfileName)Get a functional profilejava.util.List<FunctionalProfile>getFunctionalProfiles()Get all functional profilesjava.util.List<DataPointValue>getValues()Get value of all data points in one goprotected static booleanisNumeric(Value value)Tells if a value contains a number.protected static doublemultiply(double factor1, double factor2)Multiplies two numbers.voidsubscribe(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 pointvoidunsubscribe(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
-
Methods inherited from interface com.smartgridready.communicator.common.api.GenDeviceApi
connect, disconnect, getVal, getVal, isConnected, setVal
-
-
-
-
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 profiledataPointName- 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 namedataPointName- 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 testdataPoint- 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.GenDriverExceptionTests a given data point's read or write permissions.- Parameters:
dataPoint- the data point to testdirection- 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 testlimit- the boundscomparator- 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:GenDeviceApiGet device information- Specified by:
getDeviceInfoin interfaceGenDeviceApi- Returns:
- The device information
- Throws:
com.smartgridready.driver.api.common.GenDriverException- Generic error while reading from the device
-
getDeviceConfigurationInfo
public java.util.List<ConfigurationValue> getDeviceConfigurationInfo()
Description copied from interface:GenDeviceApiGet the device interface configuration parameters- Specified by:
getDeviceConfigurationInfoin interfaceGenDeviceApi- Returns:
- The configuration parameter list
-
getFunctionalProfiles
public java.util.List<FunctionalProfile> getFunctionalProfiles() throws com.smartgridready.driver.api.common.GenDriverException
Description copied from interface:GenDeviceApiGet all functional profiles- Specified by:
getFunctionalProfilesin interfaceGenDeviceApi- 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:GenDeviceApiGet a functional profile- Specified by:
getFunctionalProfilein interfaceGenDeviceApi- 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:GenDeviceApiGet all data points of a functional profile- Specified by:
getDataPointsin interfaceGenDeviceApi- 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:GenDeviceApiGet a data point- Specified by:
getDataPointin interfaceGenDeviceApi- Parameters:
functionalProfileName- The name of the functional profiledataPointName- 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:GenDeviceApiGet value of all data points in one go- Specified by:
getValuesin interfaceGenDeviceApi- 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:GenDeviceApiChecks whether the device can subscribe to data points.- Specified by:
canSubscribein interfaceGenDeviceApi- 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.GenDriverExceptionDescription copied from interface:GenDeviceApiSubscribes to messages that are related to the given data point- Specified by:
subscribein interfaceGenDeviceApi- Parameters:
profileName- The functional profile namedataPointName- The data point namecallbackFunction- 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.GenDriverExceptionDescription copied from interface:GenDeviceApiUnsubscribes from messages that are related to a given data point- Specified by:
unsubscribein interfaceGenDeviceApi- Parameters:
profileName- The functional profile namedataPointName- 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 instancevalue- the value to convertconversionFunction- 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 dividenddivisor- the divisor- Returns:
- the division result
-
multiply
protected static double multiply(double factor1, double factor2)Multiplies two numbers.- Parameters:
factor1- the first factorfactor2- the second factor- Returns:
- the multiplication result
-
-