Class AbstractOpenemsSunSpecComponent
- java.lang.Object
-
- io.openems.edge.common.component.AbstractOpenemsComponent
-
- io.openems.edge.bridge.modbus.api.AbstractOpenemsModbusComponent
-
- io.openems.edge.bridge.modbus.sunspec.AbstractOpenemsSunSpecComponent
-
- All Implemented Interfaces:
ModbusComponent
,OpenemsComponent
- Direct Known Subclasses:
AbstractSunSpecBatteryInverter
,AbstractSunSpecMeter
,AbstractSunSpecPvInverter
public abstract class AbstractOpenemsSunSpecComponent extends AbstractOpenemsModbusComponent
This class provides a generic implementation of SunSpec ModBus protocols.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.openems.edge.bridge.modbus.api.AbstractOpenemsModbusComponent
AbstractOpenemsModbusComponent.BitConverter, AbstractOpenemsModbusComponent.ChannelMapper<T extends AbstractModbusElement<?>>
-
Nested classes/interfaces inherited from interface io.openems.edge.bridge.modbus.api.ModbusComponent
ModbusComponent.ChannelId
-
Nested classes/interfaces inherited from interface io.openems.edge.common.component.OpenemsComponent
OpenemsComponent.ChannelId
-
-
Constructor Summary
Constructors Constructor Description AbstractOpenemsSunSpecComponent(java.util.Map<SunSpecModel,Priority> activeModels, ChannelId[] firstInitialChannelIds, ChannelId[]... furtherInitialChannelIds)
Constructs a AbstractOpenemsSunSpecComponent.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected boolean
activate(org.osgi.service.component.ComponentContext context, java.lang.String id, java.lang.String alias, boolean enabled, int unitId, org.osgi.service.cm.ConfigurationAdmin cm, java.lang.String modbusReference, java.lang.String modbusId)
Call this method from Component implementations activate().protected boolean
activate(org.osgi.service.component.ComponentContext context, java.lang.String id, java.lang.String alias, boolean enabled, int unitId, org.osgi.service.cm.ConfigurationAdmin cm, java.lang.String modbusReference, java.lang.String modbusId, int readFromCommonBlockNo)
protected void
addBlock(int startAddress, SunSpecModel model, Priority priority)
Adds the block starting from startAddress.protected ModbusProtocol
defineModbusProtocol()
Defines the Modbus protocol.protected <T extends Channel<?>>
java.util.Optional<T>getSunSpecChannel(SunSpecPoint point)
Get the Channel for the given Point.protected <T extends Channel<?>>
TgetSunSpecChannelOrError(SunSpecPoint point)
Get the Channel for the given Point or throw an error if it is not available.protected SunSpecModel
getSunSpecModel(int blockId)
Overwrite to provide custom SunSpecModel.boolean
isSunSpecInitializationCompleted()
Is the SunSpec initialization completed?.protected void
mapFirstPointToChannel(ChannelId targetChannel, ElementToChannelConverter converter, SunSpecPoint... points)
Maps the first available SunSpecSunSpecPoint
to the targetChannel.protected abstract void
onSunSpecInitializationCompleted()
This method is called after the SunSpec initialization was completed.-
Methods inherited from class io.openems.edge.bridge.modbus.api.AbstractOpenemsModbusComponent
activate, activate, deactivate, getBridgeModbus, getModbusProtocol, getUnitId, m, m, m, m, m, m, modified, modified, setModbus, unsetModbus
-
Methods inherited from class io.openems.edge.common.component.AbstractOpenemsComponent
_channel, addChannel, addChannels, addChannels, alias, channels, getComponentContext, id, isEnabled, logDebug, logError, logInfo, logWarn, removeChannel
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.openems.edge.bridge.modbus.api.ModbusComponent
_setModbusCommunicationFailed, getModbusCommunicationFailed, getModbusCommunicationFailedChannel
-
Methods inherited from interface io.openems.edge.common.component.OpenemsComponent
_channel, _getChannelAs, alias, channel, channel, channels, debugLog, getComponentContext, getState, getStateChannel, hasFaults, id, isEnabled, serviceFactoryPid, servicePid
-
-
-
-
Constructor Detail
-
AbstractOpenemsSunSpecComponent
public AbstractOpenemsSunSpecComponent(java.util.Map<SunSpecModel,Priority> activeModels, ChannelId[] firstInitialChannelIds, ChannelId[]... furtherInitialChannelIds) throws OpenemsException
Constructs a AbstractOpenemsSunSpecComponent.- Parameters:
activeModels
- the active SunSpec Models (i.e.SunSpecModel
) that should be considered and their reading-priorityfirstInitialChannelIds
- forwarded toAbstractOpenemsModbusComponent
furtherInitialChannelIds
- forwarded toAbstractOpenemsModbusComponent
- Throws:
OpenemsException
- on error
-
-
Method Detail
-
activate
protected boolean activate(org.osgi.service.component.ComponentContext context, java.lang.String id, java.lang.String alias, boolean enabled, int unitId, org.osgi.service.cm.ConfigurationAdmin cm, java.lang.String modbusReference, java.lang.String modbusId)
Description copied from class:AbstractOpenemsModbusComponent
Call this method from Component implementations activate().- Overrides:
activate
in classAbstractOpenemsModbusComponent
- Parameters:
context
- ComponentContext of this component. Receive it from parameter for @Activateid
- ID of this component. Typically 'config.id()'alias
- Human-readable name of this Component. Typically 'config.alias()'. Defaults to 'id' if emptyenabled
- Whether the component should be enabled. Typically 'config.enabled()'unitId
- Unit-ID of the Modbus targetcm
- An instance of ConfigurationAdmin. Receive it using @ReferencemodbusReference
- The name of the @Reference setter method for the Modbus bridge - e.g. 'Modbus' if you have a setModbus()-methodmodbusId
- The ID of the Modbus bridge. Typically 'config.modbus_id()'- Returns:
- true if the target filter was updated. You may use it to abort the activate() method.
-
activate
protected boolean activate(org.osgi.service.component.ComponentContext context, java.lang.String id, java.lang.String alias, boolean enabled, int unitId, org.osgi.service.cm.ConfigurationAdmin cm, java.lang.String modbusReference, java.lang.String modbusId, int readFromCommonBlockNo) throws OpenemsException
- Throws:
OpenemsException
-
defineModbusProtocol
protected final ModbusProtocol defineModbusProtocol()
Description copied from class:AbstractOpenemsModbusComponent
Defines the Modbus protocol.- Specified by:
defineModbusProtocol
in classAbstractOpenemsModbusComponent
- Returns:
- the ModbusProtocol
-
getSunSpecModel
protected SunSpecModel getSunSpecModel(int blockId) throws java.lang.IllegalArgumentException
Overwrite to provide custom SunSpecModel.- Parameters:
blockId
- the Block-Id- Returns:
- the
SunSpecModel
- Throws:
java.lang.IllegalArgumentException
- on error
-
isSunSpecInitializationCompleted
public boolean isSunSpecInitializationCompleted()
Is the SunSpec initialization completed?.If this returns true, all Channels are available.
- Returns:
- true if initialization is completed
-
onSunSpecInitializationCompleted
protected abstract void onSunSpecInitializationCompleted()
This method is called after the SunSpec initialization was completed.The purpose of this method is to add mappings between SunSpec Channel-Points to OpenEMS Nature Channels.
-
addBlock
protected void addBlock(int startAddress, SunSpecModel model, Priority priority) throws OpenemsException
Adds the block starting from startAddress.- Parameters:
startAddress
- the address to start reading frommodel
- the SunSpecModelpriority
- the reading priority- Throws:
OpenemsException
- on error
-
getSunSpecChannel
protected <T extends Channel<?>> java.util.Optional<T> getSunSpecChannel(SunSpecPoint point)
Get the Channel for the given Point.- Type Parameters:
T
- the Channel type- Parameters:
point
- the SunSpec Point- Returns:
- the optional Channel
-
getSunSpecChannelOrError
protected <T extends Channel<?>> T getSunSpecChannelOrError(SunSpecPoint point) throws OpenemsException
Get the Channel for the given Point or throw an error if it is not available.- Type Parameters:
T
- the Channel type- Parameters:
point
- the SunSpec Point- Returns:
- the optional Channel
- Throws:
OpenemsException
- if Channel is not available
-
mapFirstPointToChannel
protected void mapFirstPointToChannel(ChannelId targetChannel, ElementToChannelConverter converter, SunSpecPoint... points)
Maps the first available SunSpecSunSpecPoint
to the targetChannel.The logic checks in order if a point is defined and uses that point.
Call this method only after all SunSpec models were completely read - i.e. onSunSpecInitializationCompleted()
- Parameters:
targetChannel
- the targetChannelconverter
- convert from Point value to the Unit of the Channelpoints
- the points.
-
-