Search in sources :

Example 11 with SystemConnectionMemo

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

the class JmriSRCPTurnoutServer method sendStatus.

public void sendStatus(int bus, int address) throws IOException {
    log.debug("send Status called with bus {} and address {}", bus, address);
    java.util.List<SystemConnectionMemo> list = jmri.InstanceManager.getList(SystemConnectionMemo.class);
    SystemConnectionMemo memo = null;
    try {
        memo = list.get(bus - 1);
    } catch (java.lang.IndexOutOfBoundsException obe) {
        TimeStampedOutput.writeTimestamp(output, "412 ERROR wrong value\n\r");
        return;
    }
    String turnoutName = memo.getSystemPrefix() + "T" + address;
    try {
        // busy loop, wait for turnout to settle before continuing.
        while (InstanceManager.turnoutManagerInstance().provideTurnout(turnoutName).getKnownState() != InstanceManager.turnoutManagerInstance().provideTurnout(turnoutName).getCommandedState()) {
        }
        int Status = InstanceManager.turnoutManagerInstance().provideTurnout(turnoutName).getKnownState();
        if (Status == Turnout.THROWN) {
            TimeStampedOutput.writeTimestamp(output, "100 INFO " + bus + " GA " + address + " 1 0\n\r");
        } else if (Status == Turnout.CLOSED) {
            TimeStampedOutput.writeTimestamp(output, "100 INFO " + bus + " GA " + address + " 0 0\n\r");
        } else {
            //  unknown state
            TimeStampedOutput.writeTimestamp(output, "411 ERROR unknown value\n\r");
        }
    } catch (IllegalArgumentException ex) {
        log.warn("Failed to provide Turnout \"{}\" in sendStatus", turnoutName);
    }
}
Also used : SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo)

Example 12 with SystemConnectionMemo

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

the class AbstractActionModel method performAction.

@Override
public void performAction() throws JmriException {
    log.debug("Invoke Action from {}", className);
    try {
        Action action = (Action) Class.forName(className).newInstance();
        if (SystemConnectionAction.class.isAssignableFrom(action.getClass())) {
            SystemConnectionMemo memo = ConnectionNameFromSystemName.getSystemConnectionMemoFromSystemPrefix(this.getSystemPrefix());
            if (memo != null) {
                ((SystemConnectionAction) action).setSystemConnectionMemo(memo);
            } else {
                log.warn("Connection \"{}\" does not exist and cannot be assigned to action {}\nThis warning can be silenced by configuring the connection associated with the startup action.", this.getSystemPrefix(), className);
            }
        }
        this.performAction(action);
    } catch (ClassNotFoundException ex) {
        log.error("Could not find specified class: {}", className);
    } catch (IllegalAccessException ex) {
        log.error("Unexpected access exception for class: {}", className, ex);
        throw new JmriException(ex);
    } catch (InstantiationException ex) {
        log.error("Could not instantiate specified class: {}", className, ex);
        throw new JmriException(ex);
    } catch (Exception ex) {
        log.error("Error while performing startup action for class: {}", className, ex);
        throw new JmriException(ex);
    }
}
Also used : SystemConnectionAction(jmri.jmrix.swing.SystemConnectionAction) Action(javax.swing.Action) SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo) JmriException(jmri.JmriException) SystemConnectionAction(jmri.jmrix.swing.SystemConnectionAction) JmriException(jmri.JmriException)

Example 13 with SystemConnectionMemo

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

the class JsonUtil method getSystemConnections.

/**
     *
     * @param locale the client's Locale.
     * @return the JSON networkServices message.
     * @deprecated since 4.5.2; use
     * {@link jmri.server.json.util.JsonUtilHttpService#getSystemConnections(java.util.Locale)}.
     */
@Deprecated
public static JsonNode getSystemConnections(Locale locale) {
    ArrayNode root = mapper.createArrayNode();
    ArrayList<String> prefixes = new ArrayList<String>();
    for (ConnectionConfig config : InstanceManager.getDefault(ConnectionConfigManager.class)) {
        if (!config.getDisabled()) {
            ObjectNode connection = mapper.createObjectNode().put(TYPE, SYSTEM_CONNECTION);
            ObjectNode data = connection.putObject(DATA);
            data.put(NAME, config.getConnectionName());
            data.put(MFG, config.getManufacturer());
            data.put(PREFIX, config.getAdapter().getSystemConnectionMemo().getSystemPrefix());
            prefixes.add(config.getAdapter().getSystemConnectionMemo().getSystemPrefix());
            root.add(connection);
        }
    }
    for (Object instance : InstanceManager.getList(SystemConnectionMemo.class)) {
        SystemConnectionMemo memo = (SystemConnectionMemo) instance;
        if (!memo.getDisabled() && !prefixes.contains(memo.getSystemPrefix())) {
            ObjectNode connection = mapper.createObjectNode().put(TYPE, SYSTEM_CONNECTION);
            ObjectNode data = connection.putObject(DATA);
            data.put(NAME, memo.getUserName());
            data.put(PREFIX, memo.getSystemPrefix());
            data.putNull(MFG);
            prefixes.add(memo.getSystemPrefix());
            root.add(connection);
        }
    }
    // Following is required because despite there being a SystemConnectionMemo
    // for the default internal connection, it is not used for the default internal
    // connection. This allows a client to map the server's internal objects.
    String prefix = "I";
    if (!prefixes.contains(prefix)) {
        ObjectNode connection = mapper.createObjectNode().put(TYPE, SYSTEM_CONNECTION);
        ObjectNode data = connection.putObject(DATA);
        data.put(NAME, ConnectionNameFromSystemName.getConnectionName(prefix));
        data.put(PREFIX, prefix);
        data.putNull(MFG);
        root.add(connection);
    }
    return root;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo) ArrayList(java.util.ArrayList) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) TrainCommon.splitString(jmri.jmrit.operations.trains.TrainCommon.splitString) ConnectionConfig(jmri.jmrix.ConnectionConfig)

Example 14 with SystemConnectionMemo

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

the class JmriSRCPThrottleServer method sendStatus.

/*
     * send the status of the specified throttle address on the specified bus
     * @param bus bus number.
     * @param address locomoitve address.
     */
public void sendStatus(int bus, int address) throws IOException {
    log.debug("send Status called with bus {} and address {}", bus, address);
    /* translate the bus into a system connection memo */
    java.util.List<SystemConnectionMemo> list = jmri.InstanceManager.getList(SystemConnectionMemo.class);
    SystemConnectionMemo memo = null;
    try {
        memo = list.get(bus - 1);
    } catch (java.lang.IndexOutOfBoundsException obe) {
        TimeStampedOutput.writeTimestamp(output, Bundle.getMessage("Error412"));
        return;
    }
    /* request the throttle for this particular locomotive address */
    if (memo.provides(jmri.ThrottleManager.class)) {
        ThrottleManager t = memo.get(jmri.ThrottleManager.class);
        // we will use getThrottleInfo to request information about the
        // address, so we need to convert the address to a DccLocoAddress
        // object first.
        DccLocoAddress addr = new DccLocoAddress(address, t.canBeLongAddress(address));
        Boolean isForward = (Boolean) t.getThrottleInfo(addr, "IsForward");
        Float speedSetting = (Float) t.getThrottleInfo(addr, "SpeedSetting");
        Integer speedStepMode = (Integer) t.getThrottleInfo(addr, "SpeedStepMode");
        Boolean f0 = (Boolean) t.getThrottleInfo(addr, "F0");
        Boolean f1 = (Boolean) t.getThrottleInfo(addr, "F1");
        Boolean f2 = (Boolean) t.getThrottleInfo(addr, "F2");
        Boolean f3 = (Boolean) t.getThrottleInfo(addr, "F3");
        Boolean f4 = (Boolean) t.getThrottleInfo(addr, "F4");
        Boolean f5 = (Boolean) t.getThrottleInfo(addr, "F5");
        Boolean f6 = (Boolean) t.getThrottleInfo(addr, "F6");
        Boolean f7 = (Boolean) t.getThrottleInfo(addr, "F7");
        Boolean f8 = (Boolean) t.getThrottleInfo(addr, "F8");
        Boolean f9 = (Boolean) t.getThrottleInfo(addr, "F9");
        Boolean f10 = (Boolean) t.getThrottleInfo(addr, "F10");
        Boolean f11 = (Boolean) t.getThrottleInfo(addr, "F11");
        Boolean f12 = (Boolean) t.getThrottleInfo(addr, "F12");
        Boolean f13 = (Boolean) t.getThrottleInfo(addr, "F13");
        Boolean f14 = (Boolean) t.getThrottleInfo(addr, "F14");
        Boolean f15 = (Boolean) t.getThrottleInfo(addr, "F15");
        Boolean f16 = (Boolean) t.getThrottleInfo(addr, "F16");
        Boolean f17 = (Boolean) t.getThrottleInfo(addr, "F17");
        Boolean f18 = (Boolean) t.getThrottleInfo(addr, "F18");
        Boolean f19 = (Boolean) t.getThrottleInfo(addr, "F19");
        Boolean f20 = (Boolean) t.getThrottleInfo(addr, "F20");
        Boolean f21 = (Boolean) t.getThrottleInfo(addr, "F21");
        Boolean f22 = (Boolean) t.getThrottleInfo(addr, "F22");
        Boolean f23 = (Boolean) t.getThrottleInfo(addr, "F23");
        Boolean f24 = (Boolean) t.getThrottleInfo(addr, "F24");
        Boolean f25 = (Boolean) t.getThrottleInfo(addr, "F25");
        Boolean f26 = (Boolean) t.getThrottleInfo(addr, "F26");
        Boolean f27 = (Boolean) t.getThrottleInfo(addr, "F27");
        Boolean f28 = (Boolean) t.getThrottleInfo(addr, "F28");
        // and now build the output string to send
        String StatusString = "100 INFO " + bus + " GL " + address + " ";
        StatusString += isForward ? "1 " : "0 ";
        switch(speedStepMode) {
            case DccThrottle.SpeedStepMode14:
                StatusString += (int) java.lang.Math.ceil(speedSetting * 14) + " " + 14;
                break;
            case DccThrottle.SpeedStepMode27:
                StatusString += (int) java.lang.Math.ceil(speedSetting * 27) + " " + 27;
                break;
            case DccThrottle.SpeedStepMode28:
                StatusString += (int) java.lang.Math.ceil(speedSetting * 28) + " " + 28;
                break;
            case DccThrottle.SpeedStepMode128:
                StatusString += (int) java.lang.Math.ceil(speedSetting * 126) + " " + 126;
                break;
            default:
                StatusString += (int) java.lang.Math.ceil(speedSetting * 100) + " " + 100;
        }
        StatusString += f0 ? " 1" : " 0";
        StatusString += f1 ? " 1" : " 0";
        StatusString += f2 ? " 1" : " 0";
        StatusString += f3 ? " 1" : " 0";
        StatusString += f4 ? " 1" : " 0";
        StatusString += f5 ? " 1" : " 0";
        StatusString += f6 ? " 1" : " 0";
        StatusString += f7 ? " 1" : " 0";
        StatusString += f8 ? " 1" : " 0";
        StatusString += f9 ? " 1" : " 0";
        StatusString += f10 ? " 1" : " 0";
        StatusString += f11 ? " 1" : " 0";
        StatusString += f12 ? " 1" : " 0";
        StatusString += f13 ? " 1" : " 0";
        StatusString += f14 ? " 1" : " 0";
        StatusString += f15 ? " 1" : " 0";
        StatusString += f16 ? " 1" : " 0";
        StatusString += f17 ? " 1" : " 0";
        StatusString += f18 ? " 1" : " 0";
        StatusString += f19 ? " 1" : " 0";
        StatusString += f20 ? " 1" : " 0";
        StatusString += f21 ? " 1" : " 0";
        StatusString += f22 ? " 1" : " 0";
        StatusString += f23 ? " 1" : " 0";
        StatusString += f24 ? " 1" : " 0";
        StatusString += f25 ? " 1" : " 0";
        StatusString += f26 ? " 1" : " 0";
        StatusString += f27 ? " 1" : " 0";
        StatusString += f28 ? " 1" : " 0";
        StatusString += "\n\r";
        TimeStampedOutput.writeTimestamp(output, StatusString);
    } else {
        TimeStampedOutput.writeTimestamp(output, Bundle.getMessage("Error412"));
        return;
    }
}
Also used : SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo) ThrottleManager(jmri.ThrottleManager) DccLocoAddress(jmri.DccLocoAddress)

Example 15 with SystemConnectionMemo

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

the class JmriSRCPThrottleServer method releaseThrottle.

public void releaseThrottle(int bus, int address) throws IOException {
    log.debug("releaseThrottle called with bus {} and address {}", bus, address);
    /* translate the bus into a system connection memo */
    java.util.List<SystemConnectionMemo> list = jmri.InstanceManager.getList(SystemConnectionMemo.class);
    SystemConnectionMemo memo = null;
    try {
        memo = list.get(bus - 1);
    } catch (java.lang.IndexOutOfBoundsException obe) {
        TimeStampedOutput.writeTimestamp(output, Bundle.getMessage("Error412"));
        return;
    }
    /* release the throttle for this particular locomotive address */
    if (memo.provides(jmri.ThrottleManager.class)) {
        ThrottleManager t = memo.get(jmri.ThrottleManager.class);
        DccLocoAddress addr = new DccLocoAddress(address, t.canBeLongAddress(address));
        t.releaseThrottle((DccThrottle) throttleList.get(addressList.indexOf(addr)), this);
        throttleList.remove(addressList.indexOf(addr));
        sendThrottleReleased(addr);
        busList.remove(addressList.indexOf(addr));
        addressList.remove(addr);
    }
}
Also used : SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo) ThrottleManager(jmri.ThrottleManager) DccLocoAddress(jmri.DccLocoAddress)

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