Package io.openems.edge.common.channel
Interface Channel<T>
-
- Type Parameters:
T
- the type of the Channel. One out ofOpenemsType
.
- All Known Subinterfaces:
WriteChannel<T>
- All Known Implementing Classes:
AbstractReadChannel
,BooleanReadChannel
,BooleanWriteChannel
,DoubleReadChannel
,DoubleWriteChannel
,EnumReadChannel
,EnumWriteChannel
,FloatReadChannel
,FloatWriteChannel
,IntegerReadChannel
,IntegerWriteChannel
,LongReadChannel
,LongWriteChannel
,ShortReadChannel
,ShortWriteChannel
,StateChannel
,StateCollectorChannel
,StringReadChannel
,StringWriteChannel
public interface Channel<T>
An OpenEMS Channel holds one specific piece of information of anOpenemsComponent
.A Channel has
- a Channel-ID which is unique among the OpenemsComponent. (see
ChannelId
) - a
Doc
as static meta information. (viachannelDoc()
) - a system-wide unique
ChannelAddress
built from Component-ID and Channel-ID. (viaaddress()
- a
OpenemsType
which needs to map to the generic parameter <T>. (viagetType()
) - an (active)
Value
. (viavalue()
) - callback methods to listen on value updates and changes. (see
Channel#onChange(Consumer)
,onUpdate(Consumer)
andonSetNextValue(Consumer)
)
Channels implement a 'Process Image' pattern. They provide an 'active' value which should be used for any operations on the channel value. The 'next' value is filled by asynchronous workers in the background. At the 'Process Image Switch' the 'next' value is copied to the 'current' value.
The recommended implementation of an OpenEMS Channel is via
AbstractReadChannel
.
-
-
Field Summary
Fields Modifier and Type Field Description static int
NO_OF_PAST_VALUES
Holds the number of past values for this Channel that are kept in the 'pastValues' variable.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description void
_setNextValue(T value)
Deprecated.ChannelAddress
address()
Gets the address of this Channel.default Doc
channelDoc()
Gets the ChannelDoc of this Channel.ChannelId
channelId()
Gets the ChannelId of this Channel.void
deactivate()
Deactivates the Channel and makes sure all callbacks are released for garbe collection to avoid memory-leaks.OpenemsComponent
getComponent()
Gets the OpenemsComponent this Channel belongs to.<META_INFO>
META_INFOgetMetaInfo()
Gets the meta information object.Value<T>
getNextValue()
Gets the 'next value'.CircularTreeMap<java.time.LocalDateTime,Value<T>>
getPastValues()
Gets the past values for this Channel.OpenemsType
getType()
Gets the type of this Channel, e.g.void
nextProcessImage()
Switches to the next process image, i.e.java.util.function.BiConsumer<Value<T>,Value<T>>
onChange(java.util.function.BiConsumer<Value<T>,Value<T>> callback)
Add an onChange callback.java.util.function.Consumer<Value<T>>
onSetNextValue(java.util.function.Consumer<Value<T>> callback)
Add an onSetNextValue callback.java.util.function.Consumer<Value<T>>
onUpdate(java.util.function.Consumer<Value<T>> callback)
Add an onUpdate callback.void
removeOnChangeCallback(java.util.function.BiConsumer<?,?> callback)
Removes an onChange callback.void
removeOnSetNextValueCallback(java.util.function.Consumer<?> callback)
Removes an onSetNextValue callback.void
removeOnUpdateCallback(java.util.function.Consumer<Value<?>> callback)
Removes an onUpdate callback.<META_INFO>
voidsetMetaInfo(META_INFO metaInfo)
Sets an object that holds meta information about the Channel, e.g.default void
setNextValue(java.lang.Object value)
Updates the 'next value' of Channel.Value<T>
value()
Gets the currently active value, wrapped in a @{link Value}.
-
-
-
Field Detail
-
NO_OF_PAST_VALUES
static final int NO_OF_PAST_VALUES
Holds the number of past values for this Channel that are kept in the 'pastValues' variable.- See Also:
- Constant Field Values
-
-
Method Detail
-
channelId
ChannelId channelId()
Gets the ChannelId of this Channel.- Returns:
- the ChannelId
-
channelDoc
default Doc channelDoc()
Gets the ChannelDoc of this Channel.- Returns:
- the ChannelDoc
-
getComponent
OpenemsComponent getComponent()
Gets the OpenemsComponent this Channel belongs to.- Returns:
- the OpenemsComponent
-
address
ChannelAddress address()
Gets the address of this Channel.- Returns:
- the
ChannelAddress
-
nextProcessImage
void nextProcessImage()
Switches to the next process image, i.e. copies the "next"-value into "current"-value.
-
getType
OpenemsType getType()
Gets the type of this Channel, e.g. INTEGER, BOOLEAN,..- Returns:
- the
OpenemsType
-
setNextValue
default void setNextValue(java.lang.Object value)
Updates the 'next value' of Channel.- Parameters:
value
- the 'next value'. It is going to be the 'value' after the next ProcessImage gets activated.
-
getNextValue
Value<T> getNextValue()
Gets the 'next value'.Note that usually you should prefer the value() method.
- Returns:
- the 'next value'
-
onSetNextValue
java.util.function.Consumer<Value<T>> onSetNextValue(java.util.function.Consumer<Value<T>> callback)
Add an onSetNextValue callback. It is called, after a new NextValue was set. Note that usually you should prefer the onUpdate() callback.Remember to remove the callback using
removeOnSetNextValueCallback(Consumer)
once it is not needed anymore, e.g. on deactivate().- Parameters:
callback
- the callbackConsumer
- Returns:
- the callback to enable fluent programming
- See Also:
onUpdate(java.util.function.Consumer<io.openems.edge.common.channel.value.Value<T>>)
-
removeOnSetNextValueCallback
void removeOnSetNextValueCallback(java.util.function.Consumer<?> callback)
Removes an onSetNextValue callback.- Parameters:
callback
- the callbackConsumer
- See Also:
onSetNextValue(Consumer)
-
_setNextValue
@Deprecated void _setNextValue(T value)
Deprecated.Internal method. Do not call directly.- Parameters:
value
- the 'next value'
-
value
Value<T> value() throws java.lang.IllegalArgumentException
Gets the currently active value, wrapped in a @{link Value}.- Returns:
- the active value
- Throws:
java.lang.IllegalArgumentException
- if value cannot be access, e.g. because the Channel is Write-Only.
-
getPastValues
CircularTreeMap<java.time.LocalDateTime,Value<T>> getPastValues()
Gets the past values for this Channel.- Returns:
- a map of recording time and historic value at that time
-
onUpdate
java.util.function.Consumer<Value<T>> onUpdate(java.util.function.Consumer<Value<T>> callback)
Add an onUpdate callback. It is called, after the active value was updated by nextProcessImage().- Parameters:
callback
- the callback- Returns:
- the same callback for fluent coding
-
removeOnUpdateCallback
void removeOnUpdateCallback(java.util.function.Consumer<Value<?>> callback)
Removes an onUpdate callback.- Parameters:
callback
- the callbackConsumer
- See Also:
onUpdate(Consumer)
-
onChange
java.util.function.BiConsumer<Value<T>,Value<T>> onChange(java.util.function.BiConsumer<Value<T>,Value<T>> callback)
Add an onChange callback. It is called, after a new, different active value was set by nextProcessImage().- Parameters:
callback
- old value and new value- Returns:
- the same callback for fluent coding
-
removeOnChangeCallback
void removeOnChangeCallback(java.util.function.BiConsumer<?,?> callback)
Removes an onChange callback.- Parameters:
callback
- the callbackBiConsumer
- See Also:
onChange(BiConsumer)
-
deactivate
void deactivate()
Deactivates the Channel and makes sure all callbacks are released for garbe collection to avoid memory-leaks.
-
setMetaInfo
<META_INFO> void setMetaInfo(META_INFO metaInfo) throws java.lang.IllegalArgumentException
Sets an object that holds meta information about the Channel, e.g. a read source or write target of this Channel, like a Modbus Register or REST-Api endpoint address. Defaults to null.- Type Parameters:
META_INFO
- the type of the meta info- Parameters:
metaInfo
- the meta info object- Throws:
java.lang.IllegalArgumentException
- if there is already a different meta-info registered with the Channel
-
getMetaInfo
<META_INFO> META_INFO getMetaInfo()
Gets the meta information object. Defaults to null.- Type Parameters:
META_INFO
- the type of the meta info attachment- Returns:
- the meta info object
-
-