Class 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.
  • Constructor Details

  • Method Details

    • activate

      protected boolean activate(org.osgi.service.component.ComponentContext context, String id, String alias, boolean enabled, int unitId, org.osgi.service.cm.ConfigurationAdmin cm, String modbusReference, String modbusId)
      Description copied from class: AbstractOpenemsModbusComponent
      Call this method from Component implementations activate().
      Overrides:
      activate in class AbstractOpenemsModbusComponent
      Parameters:
      context - ComponentContext of this component. Receive it from parameter for @Activate
      id - ID of this component. Typically 'config.id()'
      alias - Human-readable name of this Component. Typically 'config.alias()'. Defaults to 'id' if empty
      enabled - Whether the component should be enabled. Typically 'config.enabled()'
      unitId - Unit-ID of the Modbus target
      cm - An instance of ConfigurationAdmin. Receive it using @Reference
      modbusReference - The name of the @Reference setter method for the Modbus bridge - e.g. 'Modbus' if you have a setModbus()-method
      modbusId - 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, String id, String alias, boolean enabled, int unitId, org.osgi.service.cm.ConfigurationAdmin cm, String modbusReference, 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 class AbstractOpenemsModbusComponent
      Returns:
      the ModbusProtocol
    • getSunSpecModel

      protected SunSpecModel getSunSpecModel(int blockId) throws IllegalArgumentException
      Overwrite to provide custom SunSpecModel.
      Parameters:
      blockId - the Block-Id
      Returns:
      the SunSpecModel
      Throws:
      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 from
      model - the SunSpecModel
      priority - the reading priority
      Throws:
      OpenemsException - on error
    • preprocessModbusElements

      protected static List<List<ModbusElement>> preprocessModbusElements(List<ModbusElement> elements)
      Converts a list of ModbusElements to sublists, prepared for Modbus AbstractTasks.
      • Sublists are without holes (i.e. nextStartAddress = currentStartAddress + Length + 1)
      • Length of sublist invalid input: '<'= MAXIMUM_TASK_LENGTH
      Parameters:
      elements - the source elements
      Returns:
      list of ModbusElement lists
    • generateElementToChannelConverter

      protected ElementToChannelConverter generateElementToChannelConverter(SunSpecModel model, SunSpecPoint point)
      Generates a ElementToChannelConverter for a Point.
      • Check for UNDEFINED value as defined in SunSpec per Type specification
      • If a Scale-Factor is defined, try to add it - either as other point of model (e.g. "W_SF") or as static value converter
      Parameters:
      model - the SunSpecModel
      point - the SunSpecPoint
      Returns:
      an ElementToChannelConverter, never null
    • getSunSpecChannel

      protected <T extends Channel<?>> 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 SunSpec SunSpecPoint 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 targetChannel
      converter - convert from Point value to the Unit of the Channel
      points - the points.