Class OlcbSensorManager

    • Method Detail

      • createNewSensor

        @Nonnull
        protected Sensor createNewSensor​(@Nonnull
                                         java.lang.String systemName,
                                         java.lang.String userName)
                                  throws java.lang.IllegalArgumentException
        Internal method to invoke the factory and create a new Sensor. Called after all the logic for returning an existing Sensor has been invoked. An existing SystemName is not found, existing UserName not found. Implementing classes should base Sensor on the system name, then add user name.
        Specified by:
        createNewSensor in class AbstractSensorManager
        Parameters:
        systemName - the system name to use for the new Sensor
        userName - the optional user name to use for the new Sensor
        Returns:
        the new Sensor
        Throws:
        java.lang.IllegalArgumentException - when SystemName can't be converted
      • startLoad

        public void startLoad()
        This function is invoked before an XML load is started. We defer initialization of the newly created Sensors until finishLoad because the feedback type might be changing as we are parsing the XML.
      • finishLoad

        public void finishLoad()
        This function is invoked after the XML load is complete and all Sensors are instantiated and their feedback type is read in. We use this hook to finalize the construction of the OpenLCB objects whose instantiation was deferred until the feedback type was known.
      • allowMultipleAdditions

        public boolean allowMultipleAdditions​(@Nonnull
                                              java.lang.String systemName)
        Description copied from interface: NameIncrementingManager
        Determines if it is possible to add a range of NamedBeans in numerical order for a particular system implementation.

        Default is not providing this service. Systems should override this method if they do provide the service.

        Specified by:
        allowMultipleAdditions in interface NameIncrementingManager
        Parameters:
        systemName - the system name to check against; appears to be ignored in all implementations
        Returns:
        true if possible; false otherwise
      • createSystemName

        @Nonnull
        public java.lang.String createSystemName​(@Nonnull
                                                 java.lang.String curAddress,
                                                 @Nonnull
                                                 java.lang.String prefix)
                                          throws JmriException
        Description copied from class: AbstractSensorManager
        Default Sensor ensures a numeric only system name. Create a System Name from hardware address and system letter prefix. AbstractManager performs no validation.
        Specified by:
        createSystemName in interface SensorManager
        Overrides:
        createSystemName in class AbstractSensorManager
        Parameters:
        curAddress - hardware address, no system prefix or type letter.
        prefix - - just system prefix, not including Type Letter.
        Returns:
        full system name with system prefix, type letter and hardware address.
        Throws:
        JmriException - if unable to create a system name.
      • getNextValidSystemName

        @Nonnull
        @CheckReturnValue
        public java.lang.String getNextValidSystemName​(@Nonnull
                                                       NamedBean currentBean)
                                                throws JmriException
        Description copied from interface: NameIncrementingManager
        Get the next valid NamedBean system name.

        For example, if the system name of the provided NamedBean is IS10, the next valid name is IS11.

        This should not be called if NameIncrementingManager.allowMultipleAdditions(java.lang.String) returns false.

        Pays no attention to whether the next NamedBean already exists or not, just works out the name. Nor is there any guarantee that the return value can actually be created: a provide() call on the return value can still perhaps fail in some circumstances.

        In some cases, there is no clear next address. In that case, a JmriException is thrown. For example, some systems have no concept of a "next" address; Internal sensors don't necessarily have numeric suffixes; etc.

        Default implementation works for names of the form (prefix)(type letter)(numeric string) by incrementing the numeric string as needed.

        Specified by:
        getNextValidSystemName in interface NameIncrementingManager
        Parameters:
        currentBean - The NamedBean who's system name that provides the base for "next"
        Returns:
        The next valid system name
        Throws:
        JmriException - If unable to create a valid next address
      • reply

        public void reply​(CanReply l)
        Description copied from interface: CanListener
        Called when an incoming CanFrame is received from the CAN Network.
        Specified by:
        reply in interface CanListener
        Parameters:
        l - the CanReply being received.
      • message

        public void message​(CanMessage l)
        Description copied from interface: CanListener
        Called when an outgoing message is sent to the CAN Network.
        Specified by:
        message in interface CanListener
        Parameters:
        l - the CanMessage being sent.
      • validateSystemNameFormat

        @Nonnull
        public java.lang.String validateSystemNameFormat​(@Nonnull
                                                         java.lang.String name,
                                                         @Nonnull
                                                         java.util.Locale locale)
                                                  throws NamedBean.BadSystemNameException
        Validates to OpenLCB format. Validate the format of name, returning it unchanged if valid.

        Although further restrictions may be added by system-specific implementations, at a minimum, the implementation must consider a name that does not start with the System Name prefix for this manager to be invalid, and must consider a name that is the same as the System Name prefix to be invalid.

        Overriding implementations may rely on Manager.validSystemNameFormat(java.lang.String), however they must provide an actionable message in the thrown exception if that method does not return Manager.NameValidity.VALID. When overriding implementations of this method rely on validSystemNameFormat(), implementations of that method must not throw an exception, log an error, or otherwise disrupt the user.

        Specified by:
        validateSystemNameFormat in interface Manager<Sensor>
        Parameters:
        name - the system name to validate
        locale - the locale for a localized exception; this is needed for the JMRI web server, which supports multiple locales
        Returns:
        the unchanged value of the name parameter
        Throws:
        NamedBean.BadSystemNameException - if provided name is an invalid format