Class AbstractOpenemsSunSpecComponent

    • 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 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,
                                   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
      • 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 from
        model - the SunSpecModel
        priority - 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 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.