All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bidib.wizard.api.model.connection.BidibConnection Maven / Gradle / Ivy

There is a newer version: 2.0.25
Show newest version
package org.bidib.wizard.api.model.connection;

import java.time.LocalDateTime;
import java.util.List;

import org.bidib.api.json.types.action.UserInteractionAction;
import org.bidib.jbidibc.core.InbandProtocolHandler;
import org.bidib.jbidibc.core.node.ConfigurationVariable;
import org.bidib.jbidibc.messages.Feature;
import org.bidib.jbidibc.messages.FirmwareUpdateStat;
import org.bidib.jbidibc.messages.NodeEnableData;
import org.bidib.jbidibc.messages.ProtocolVersion;
import org.bidib.jbidibc.messages.SoftwareVersion;
import org.bidib.jbidibc.messages.VendorData;
import org.bidib.jbidibc.messages.enums.FirmwareUpdateOperation;
import org.bidib.jbidibc.messages.enums.IdentifyState;
import org.bidib.jbidibc.messages.helpers.Context;
import org.bidib.jbidibc.messages.message.netbidib.NetBidibLinkData.PairingStatus;
import org.bidib.wizard.api.model.NodeInterface;
import org.bidib.wizard.api.model.NodeProvider;
import org.bidib.wizard.api.model.connection.event.GenericEvent;
import org.bidib.wizard.api.model.event.NodeEvent;
import org.bidib.wizard.api.notification.ConnectionLoadStatus;
import org.bidib.wizard.api.notification.ConnectionLoadStatus.ConnectionLoadStatusEnum;
import org.bidib.wizard.api.notification.NodeStatusInfo;
import org.bidib.wizard.api.notification.TimeEvent;
import org.bidib.wizard.model.ports.event.PortEvent;
import org.bidib.wizard.model.ports.event.StatusEvent;
import org.bidib.wizard.model.status.BoosterStatus;
import org.bidib.wizard.model.stringdata.StoredStrings;

import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Action;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.functions.Predicate;
import io.reactivex.rxjava3.subjects.Subject;

public interface BidibConnection {

    /**
     * Get the connection id of the connection.
     * 
     * @return the connection id
     */
    String getConnectionId();

    /**
     * Get the connection uri.
     * 
     * @return the uri
     */
    String getUri();

    /**
     * Set the connection uri. This could be the COM port (e.g. COM24 on Windows OS or '/dev/ttyUSB0' on linux).
     * 
     * @param uri
     *            the connection uri
     */
    void setUri(String uri);

    /**
     * Get the subject for received bidib messages.
     * 
     * @return the subjectMessages
     */
    Subject getSubjectMessages();

    /**
     * Get the subject for port events.
     * 
     * @return the port events subject
     */
    Subject getSubjectPortEvents();

    /**
     * Get the subject for node events.
     * 
     * @return the node events subject
     */
    Subject getSubjectNodeEvents();

    /**
     * Get the subject for status events.
     * 
     * @return the status events subject
     */
    Subject getSubjectStatusEvents();

    /**
     * @return the subject that emits the connection actions.
     */
    Subject getSubjectConnectionActions();

    /**
     * Subscribe to bidib messages.
     * 
     * @param onNext
     *            the data handler
     * @param onError
     *            the error handler
     * @param onComplete
     *            the complete action
     * @return the disposable
     */
    Disposable subscribeMessages(
        final Consumer onNext, final Consumer onError, final Action onComplete);

    /**
     * Subscribe to generic events.
     * 
     * @param onNext
     *            the data handler
     * @param onError
     *            the error handler
     * @param onComplete
     *            the complete action
     * @return the disposable
     */
    Disposable subscribeGenericEvents(Consumer onNext, Consumer onError, Action onComplete);

    /**
     * Subscribe to port events.
     * 
     * @param onNext
     *            the data handler
     * @param onError
     *            the error handler
     * @param onComplete
     *            the complete action
     * @return the disposable
     */
    Disposable subscribePortEvents(
        Consumer onNext, Consumer onError, Action onComplete,
        final Predicate predicate);

    /**
     * Subscribe to node events.
     * 
     * @param onNext
     *            the data handler
     * @param onError
     *            the error handler
     * @param onComplete
     *            the complete action
     * @return the disposable
     */
    Disposable subscribeNodeEvents(Consumer onNext, Consumer onError, Action onComplete);

    /**
     * Subscribe to time events.
     * 
     * @param onNext
     *            the data handler
     * @param onError
     *            the error handler
     * @param onComplete
     *            the complete action
     * @return the disposable
     */
    Disposable subscribeTimeEvents(Consumer onNext, Consumer onError, Action onComplete);

    /**
     * Subscribe to status events.
     * 
     * @param onNext
     *            the data handler
     * @param onError
     *            the error handler
     * @param onComplete
     *            the complete action
     * @return the disposable
     */
    Disposable subscribeStatusEvents(Consumer onNext, Consumer onError, Action onComplete);

    /**
     * Subscribe to node status info.
     * 
     * @param onNext
     *            the data handler
     * @param onError
     *            the error handler
     * @param onComplete
     *            the complete action
     * @return the disposable
     */
    Disposable subscribeNodeStatusInfo(Consumer onNext, Consumer onError, Action onComplete);

    /**
     * Subscribe to connection load status.
     * 
     * @param onNext
     *            the data handler
     * @param onError
     *            the error handler
     * @param onComplete
     *            the complete action
     * @return the disposable
     */
    Disposable subscribeConnectionLoadStatus(
        Consumer onNext, Consumer onError, Action onComplete);

    /**
     * Get the current connection state.
     * 
     * @return the current connection state
     */
    ConnectionState getConnectionState();

    /**
     * Connect the connection to the configured uri.
     * 
     * @param context
     *            the context to provide additional params
     */
    void connect(final Context context);

    /**
     * Disconnect the connection if connected.
     */
    void disconnect();

    /**
     * @return the connection is connected
     */
    boolean isConnected();

    /**
     * @return the connection is a simulation
     */
    boolean isSimulation();

    /**
     * @return the connection is a netBidib client connection
     */
    boolean isNetBidib();

    /**
     * A proxied connection uses a proxy to communicate to the master. These proxy do not want to have some message
     * types sent, e.g. initialize the loco decoders.
     * 
     * @return {@code true}: the connection is a proxied connection, {@code false} otherwise
     */
    boolean isProxiedConnection();

    /**
     * Load the nodes initially.
     */
    void loadInitialNodes();

    /**
     * Release and reload the root node, e.g. after firmware update of root node.
     * 
     * @param node
     *            the node
     */
    void releaseAndReloadRootNode(final NodeInterface node);

    /**
     * Load the subnodes of the provided node from the system.
     * 
     * @param node
     *            the node
     * @return the collection of subnodes of the provided node
     */
    List loadSubNodes(final NodeInterface node);

    /**
     * @return the node provider
     */
    NodeProvider getNodeProvider();

    /**
     * Deny the node to send spontaneous messages.
     * 
     * @param node
     *            the node
     */
    void disable(final NodeInterface node);

    /**
     * Allow the node to send spontaneous messages.
     * 
     * @param node
     *            the node
     * @param nodeEnableData
     *            the nodeEnbleData
     */
    void enable(final NodeInterface node, final NodeEnableData nodeEnableData);

    /**
     * Send the model time message.
     * 
     * @param node
     *            the node
     * @param time
     *            the current model time
     * @param acceleration
     *            the acceleration value
     */
    void clock(final NodeInterface node, final LocalDateTime time, int acceleration);

    /**
     * Get the magic from the node. If the node does not respond correctly in the configured timespan a
     * NoAnswerException is thrown.
     * 
     * @param node
     *            the node
     * @return the magic value
     */
    Integer getMagic(final NodeInterface node);

    /**
     * Get the software version of the node
     * 
     * @param node
     *            the node
     * @return the current software version
     */
    SoftwareVersion getSoftwareVersion(final NodeInterface node);

    /**
     * Get the protocol version of the node.
     * 
     * @param node
     *            the node
     * @return the current protocol version of the node
     */
    ProtocolVersion getProtocolVersion(final NodeInterface node);

    /**
     * Returns the list of features of the specified node
     * 
     * @param node
     *            the node
     * @param discardCache
     *            discard cached values and read features from node
     * @return list of features
     */
    List getFeatures(final NodeInterface node, boolean discardCache);

    /**
     * Write a single feature to the specified node.
     * 
     * @param node
     *            the node
     * @param feature
     *            the feature
     */
    void setFeature(final NodeInterface node, Feature feature);

    /**
     * Get a string value from the node
     * 
     * @param node
     *            the node
     * @param namespace
     *            the namespace (default: 0)
     * @param index
     *            the index
     * @return the string value
     */
    String getString(final NodeInterface node, int namespace, int index);

    /**
     * Set a string value on the node.
     * 
     * @param node
     *            the node
     * @param namespace
     *            the namespace (default: 1)
     * @param index
     *            the index
     * @param value
     *            the string value
     */
    String setString(final NodeInterface node, int namespace, int index, String value);

    /**
     * Get all string of the selected namespace from the node.
     * 
     * @param connectionId
     *            the connection id
     * @param node
     *            the node
     * @param namespace
     *            the namespace
     * @return the map with the index and string pairs
     */
    StoredStrings getStrings(final NodeInterface node, int namespace);

    /**
     * Check if the node supports FW update
     * 
     * @param node
     *            the node
     * @return the node supports FW update
     */
    boolean isUpdatable(final NodeInterface node);

    /**
     * Check if the node is registered in the node registry of the core.
     * 
     * @param node
     * @return valid node
     */
    boolean isValidCoreNode(final NodeInterface node);

    /**
     * Send the FW update operation to the node.
     * 
     * @param node
     *            the node
     * @param operation
     *            the operation
     * @param data
     *            the data
     * @return the status
     */
    FirmwareUpdateStat sendFirmwareUpdateOperation(
        final NodeInterface node, FirmwareUpdateOperation operation, byte... data);

    /**
     * Shutdown the connection and release all resources.
     */
    void shutdown();

    /**
     * Returns the list of configuration variables (CV) of the specified node. The variables are fetched from a cache if
     * already availble.
     * 
     * @param node
     *            the node
     * @param configVariables
     *            the list of config variables to load
     * @return list of configuration variables (CV)
     */
    List getConfigurationVariables(
        final NodeInterface node, final List configVariables);

    /**
     * Returns the list of configuration variables (CV) of the specified node. The variables are fetched from a cache if
     * already availble.
     *
     * @param node
     *            the node
     * @param configVariables
     *            the list of config variables to load
     * @param handler
     *            the inband protocol handler
     * @return list of configuration variables (CV)
     */
    List getConfigurationVariables(
        final NodeInterface node, final List configVariables,
        final InbandProtocolHandler handler);

    /**
     * Writes the CV values of the provided list to the node.
     * 
     * @param node
     *            the node
     * @param configVariables
     *            the list of configuration variables (CV)
     * @return the list with the changed values
     */
    List writeConfigurationVariables(
        final NodeInterface node, final List configVariables);

    /**
     * Writes the CV values of the provided list to the node.
     *
     * @param node
     *            the node
     * @param configVariables
     *            the list of configuration variables (CV)
     * @param handler
     *            the inband protocol handler
     * @return the list with the changed values
     */
    List writeConfigurationVariables(
        final NodeInterface node, final List configVariables,
        final InbandProtocolHandler handler);

    /**
     * Reset the node.
     * 
     * @param node
     *            the node, if null the root node is reset
     */
    void reset(final NodeInterface node);

    /**
     * Set the identify mode.
     * 
     * @param node
     *            the node
     * @param state
     *            the identify state to set
     */
    void identify(final NodeInterface node, IdentifyState state);

    /**
     * Set the secure ack enabled flag in the node. If this flag is disabled, the application will not send the secure
     * ack to the node.
     * 
     * @param node
     *            the node
     * @param enabled
     *            the enabled flag
     */
    void setSecureAckEnabled(final NodeInterface node, boolean enabled);

    /**
     * Ping the node.
     * 
     * @param node
     *            the node
     * @param data
     *            the data byte
     */
    void ping(final NodeInterface node, byte[] data, int additionalTotalBytesCount);

    /**
     * Read the uniqueId from the node.
     * 
     * @param node
     *            the node
     * @return the uniqueId
     */
    Long readUniqueId(final NodeInterface node);

    /**
     * Start or stop the model time for the system.
     * 
     * @param enable
     *            enable or disable send time
     * @param startTime
     *            the start time to use
     * @param accelerationFactor
     *            the acceleration factor
     */
    void setModelTime(boolean enable, LocalDateTime startTime, Integer accelerationFactor);

    /**
     * Send local logon rejected to the node.
     * 
     * @param node
     *            the node
     * @param uniqueId
     *            the uniqueId of the node to reject
     */
    void sendLocalLogonRejected(final NodeInterface node, long uniqueId);

    /**
     * Attach to interface.
     * 
     * @param node
     *            the node
     * @param uniqueId
     *            the uniqueId
     */
    void attach(final NodeInterface node, Long uniqueId);

    /**
     * Detach from interface.
     * 
     * @param node
     *            the node
     * @param uniqueId
     *            the uniqueId
     */
    void detach(final NodeInterface node, Long uniqueId);

    /**
     * Signal the pairing status.
     * 
     * @param uniqueId
     *            the uniqueId of the remote partner
     * @param pairingStatus
     *            the pairing status
     */
    void signalPairingStatus(Long uniqueId, final PairingStatus pairingStatus);

    /**
     * Signal the pairing request.
     */
    void signalPairingRequest();

    /**
     * Start the local ping worker on the root node.
     */
    void startLocalPingWorker();

    /**
     * Set the localhost enabled flag. This flag signals that a localhost is enabled on the connection.
     * 
     * @param localHostEnabled
     *            {@code true}: localhost is enabled, {@code false}: no locolhost enabled
     */
    void setLocalHostEnabled(boolean localHostEnabled);

    /**
     * @return the localhost enabled flag
     */
    boolean isLocalHostEnabled();

    /**
     * Reload the node.
     *
     * @param node
     *            the node, if null the root node is reset
     */
    void reloadNode(final NodeInterface node);

    /**
     * Load the node configuration of a partially loaded node (only features and version are loaded).
     *
     * @param node
     *            the node
     */
    void loadNodeConfiguration(final NodeInterface node);

    /**
     * Broadcast the booster state.
     * 
     * @param boosterState
     *            the new booster state
     */
    void broadcastBoosterState(final BoosterStatus boosterState);

    /**
     * Publish the connection load status.
     * 
     * @param connectionLoadStatusEnum
     *            the current connection load status
     */
    void publishConnectionLoadStatus(final ConnectionLoadStatusEnum connectionLoadStatusEnum);

    /**
     * Send the system time to the root node.
     * 
     * @param systemTime
     *            the current system time
     */
    void sendSystemTime(final int systemTime);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy