Search in sources :

Example 16 with SystemConnectionMemo

use of jmri.jmrix.SystemConnectionMemo in project JMRI by JMRI.

the class JmriSRCPSensorServer method sendStatus.

public void sendStatus(int bus, int address) throws IOException {
    log.debug("send Status called with bus " + bus + " and address " + address);
    java.util.List<SystemConnectionMemo> list = jmri.InstanceManager.getList(SystemConnectionMemo.class);
    SystemConnectionMemo memo;
    try {
        memo = list.get(bus - 1);
    } catch (java.lang.IndexOutOfBoundsException obe) {
        TimeStampedOutput.writeTimestamp(output, "412 ERROR wrong value\n\r");
        return;
    }
    String sensorName = memo.getSystemPrefix() + "S" + address;
    try {
        int Status = InstanceManager.sensorManagerInstance().provideSensor(sensorName).getKnownState();
        if (Status == Sensor.ACTIVE) {
            TimeStampedOutput.writeTimestamp(output, "100 INFO " + bus + " FB " + address + " 1\n\r");
        } else if (Status == Sensor.INACTIVE) {
            TimeStampedOutput.writeTimestamp(output, "100 INFO " + bus + " FB " + address + " 0\n\r");
        } else {
            //  unknown state
            TimeStampedOutput.writeTimestamp(output, "411 ERROR unknown value\n\r");
        }
    } catch (IllegalArgumentException ex) {
        log.warn("Failed to provide Sensor \"{}\" in sendStatus", sensorName);
    }
}
Also used : SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo)

Example 17 with SystemConnectionMemo

use of jmri.jmrix.SystemConnectionMemo in project JMRI by JMRI.

the class SerialDriverAdapter method validOption1.

/**
     * Option 1 controls the connection used for programming
     */
public String[] validOption1() {
    List<SystemConnectionMemo> connList = jmri.InstanceManager.getList(SystemConnectionMemo.class);
    if (!connList.isEmpty()) {
        ArrayList<String> progConn = new ArrayList<>();
        progConn.add("");
        String userName = "Dcc4Pc";
        if (this.getSystemConnectionMemo() != null) {
            userName = this.getSystemConnectionMemo().getUserName();
        }
        for (int i = 0; i < connList.size(); i++) {
            SystemConnectionMemo scm = connList.get(i);
            if (scm.provides(jmri.ProgrammerManager.class) && (!scm.getUserName().equals(userName))) {
                progConn.add(scm.getUserName());
            }
        }
        return progConn.toArray(new String[progConn.size()]);
    } else {
        return new String[] { "" };
    }
}
Also used : SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo) Dcc4PcSystemConnectionMemo(jmri.jmrix.dcc4pc.Dcc4PcSystemConnectionMemo) ArrayList(java.util.ArrayList)

Example 18 with SystemConnectionMemo

use of jmri.jmrix.SystemConnectionMemo in project JMRI by JMRI.

the class ManagerDefaultSelector method configure.

/**
     * Load into InstanceManager
     *
     * @return an exception that can be passed to the user or null if no errors
     *         occur
     */
@CheckForNull
public InitializationException configure() {
    InitializationException error = null;
    List<SystemConnectionMemo> connList = InstanceManager.getList(SystemConnectionMemo.class);
    log.debug("configure defaults into InstanceManager from {} memos, {} defaults", connList.size(), defaults.keySet().size());
    for (Class<?> c : defaults.keySet()) {
        // 'c' is the class to load
        String connectionName = this.defaults.get(c);
        // have to find object of that type from proper connection
        boolean found = false;
        for (SystemConnectionMemo memo : connList) {
            String testName = memo.getUserName();
            if (testName.equals(connectionName)) {
                found = true;
                // match, store
                try {
                    if (memo.provides(c)) {
                        log.debug("   setting default for \"{}\" to \"{}\" in configure", c, memo.get(c));
                        InstanceManager.setDefault(c, memo.get(c));
                    }
                } catch (NullPointerException ex) {
                    // NOI18N
                    String englishMsg = Bundle.getMessage(Locale.ENGLISH, "ErrorNullDefault", memo.getUserName(), c);
                    // NOI18N
                    String localizedMsg = Bundle.getMessage("ErrorNullDefault", memo.getUserName(), c);
                    error = new InitializationException(englishMsg, localizedMsg);
                    log.warn("SystemConnectionMemo for {} ({}) provides a null {} instance", memo.getUserName(), memo.getClass(), c);
                }
                break;
            } else {
                log.debug("   memo name didn't match: {} vs {}", testName, connectionName);
            }
        }
        /*
             * If the set connection can not be found then we shall set the manager default to use what
             * has currently been set.
             */
        if (!found) {
            log.debug("!found, so resetting");
            String currentName = null;
            if (c == ThrottleManager.class && InstanceManager.getNullableDefault(ThrottleManager.class) != null) {
                currentName = InstanceManager.throttleManagerInstance().getUserName();
            } else if (c == PowerManager.class && InstanceManager.getNullableDefault(PowerManager.class) != null) {
                currentName = InstanceManager.getDefault(PowerManager.class).getUserName();
            } else if (c == ProgrammerManager.class && InstanceManager.getNullableDefault(ProgrammerManager.class) != null) {
                currentName = InstanceManager.getDefault(ProgrammerManager.class).getUserName();
            }
            if (currentName != null) {
                log.warn("The configured " + connectionName + " for " + c + " can not be found so will use the default " + currentName);
                this.defaults.put(c, currentName);
            }
        }
    }
    return error;
}
Also used : PowerManager(jmri.PowerManager) InternalSystemConnectionMemo(jmri.jmrix.internal.InternalSystemConnectionMemo) SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo) ThrottleManager(jmri.ThrottleManager) ProgrammerManager(jmri.ProgrammerManager) AddressedProgrammerManager(jmri.AddressedProgrammerManager) GlobalProgrammerManager(jmri.GlobalProgrammerManager) InitializationException(jmri.util.prefs.InitializationException) CheckForNull(javax.annotation.CheckForNull)

Aggregations

SystemConnectionMemo (jmri.jmrix.SystemConnectionMemo)18 DccLocoAddress (jmri.DccLocoAddress)6 ThrottleManager (jmri.ThrottleManager)6 ArrayList (java.util.ArrayList)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 IOException (java.io.IOException)2 JLabel (javax.swing.JLabel)2 DccThrottle (jmri.DccThrottle)2 Throttle (jmri.Throttle)2 ConnectionConfig (jmri.jmrix.ConnectionConfig)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Arrays (java.util.Arrays)1 Enumeration (java.util.Enumeration)1 Locale (java.util.Locale)1 CheckForNull (javax.annotation.CheckForNull)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Action (javax.swing.Action)1 ButtonGroup (javax.swing.ButtonGroup)1