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 an
OpenemsComponent
.
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
FieldsModifier and TypeFieldDescriptionstatic final int
Holds the number of past values for this Channel that are kept in the 'pastValues' variable. -
Method Summary
Modifier and TypeMethodDescriptionvoid
_setNextValue
(T value) Deprecated.address()
Gets the address of this Channel.default Doc
Gets the ChannelDoc of this Channel.Gets the ChannelId of this Channel.void
Deactivates the Channel and makes sure all callbacks are released for garbe collection to avoid memory-leaks.Gets the OpenemsComponent this Channel belongs to.<META_INFO>
META_INFOGets the meta information object.Gets the 'next value'.Gets the past values for this Channel.getType()
Gets the type of this Channel, e.g.void
Switches to the next process image, i.e.BiConsumer<Value<T>,
Value<T>> Add an onChange callback.onSetNextValue
(Consumer<Value<T>> callback) Add an onSetNextValue callback.Add an onUpdate callback.void
removeOnChangeCallback
(BiConsumer<?, ?> callback) Removes an onChange callback.void
removeOnSetNextValueCallback
(Consumer<?> callback) Removes an onSetNextValue callback.void
removeOnUpdateCallback
(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
(Object value) Updates the 'next value' of Channel.value()
Gets the currently active value, wrapped in a @{link Value}.
-
Field Details
-
NO_OF_PAST_VALUES
static final int NO_OF_PAST_VALUESHolds the number of past values for this Channel that are kept in the 'pastValues' variable.- See Also:
-
-
Method Details
-
channelId
ChannelId channelId()Gets the ChannelId of this Channel.- Returns:
- the ChannelId
-
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
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
Gets the 'next value'.Note that usually you should prefer the value() method.
- Returns:
- the 'next value', never null
-
onSetNextValue
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:
-
removeOnSetNextValueCallback
Removes an onSetNextValue callback.- Parameters:
callback
- the callbackConsumer
- See Also:
-
_setNextValue
Deprecated.Internal method. Do not call directly.- Parameters:
value
- the 'next value'
-
value
Gets the currently active value, wrapped in a @{link Value}.- Returns:
- the active value, never null
- Throws:
IllegalArgumentException
- if value cannot be accessed, e.g. because the Channel is Write-Only.
-
getPastValues
CircularTreeMap<LocalDateTime,Value<T>> getPastValues()Gets the past values for this Channel.- Returns:
- a map of recording time and historic value at that time
-
onUpdate
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
Removes an onUpdate callback.- Parameters:
callback
- the callbackConsumer
- See Also:
-
onChange
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
Removes an onChange callback.- Parameters:
callback
- the callbackBiConsumer
- See Also:
-
deactivate
void deactivate()Deactivates the Channel and makes sure all callbacks are released for garbe collection to avoid memory-leaks. -
setMetaInfo
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:
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
-