Search in sources :

Example 6 with SystemConnectionMemo

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

the class JmriSRCPSensorServer method parseStatus.

/*
     * for SRCP, we're doing the parsing elsewhere, so we just need to build
     * the correct string from the provided compoents.
     */
public void parseStatus(int bus, int address, int value) throws jmri.JmriException, java.io.IOException {
    log.debug("parse Status called with bus " + bus + " address " + address + " and value " + value);
    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;
    this.initSensor(sensorName);
    if (value == 0) {
        if (log.isDebugEnabled()) {
            log.debug("Setting Sensor INACTIVE");
        }
        setSensorInactive(sensorName);
    } else if (value == 1) {
        if (log.isDebugEnabled()) {
            log.debug("Setting Sensor ACTIVE");
        }
        setSensorActive(sensorName);
    }
//sendStatus(bus,address);
}
Also used : SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo)

Example 7 with SystemConnectionMemo

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

the class JmriSRCPSensorServer method sendStatus.

/*
     * Protocol Specific Abstract Functions
     */
@Override
public void sendStatus(String sensorName, int Status) throws IOException {
    int bus = 0;
    int address = 0;
    java.util.List<SystemConnectionMemo> list = jmri.InstanceManager.getList(SystemConnectionMemo.class);
    for (SystemConnectionMemo memo : list) {
        String prefix = memo.getSystemPrefix();
        if (sensorName.startsWith(prefix)) {
            try {
                address = Integer.parseInt(sensorName.substring(prefix.length() + 1));
                break;
            } catch (NumberFormatException ne) {
            // we expect this if the prefix doesn't match
            }
        }
        bus++;
    }
    if (bus > list.size()) {
        TimeStampedOutput.writeTimestamp(output, "499 ERROR unspecified error\n\r");
        return;
    }
    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");
    }
}
Also used : SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo)

Example 8 with SystemConnectionMemo

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

the class JsonUtilHttpService method getSystemConnections.

/**
     *
     * @param locale the client's Locale.
     * @return the JSON systemConnections message.
     */
public ArrayNode getSystemConnections(Locale locale) {
    ArrayNode root = mapper.createArrayNode();
    ArrayList<String> prefixes = new ArrayList<>();
    for (ConnectionConfig config : InstanceManager.getDefault(ConnectionConfigManager.class)) {
        if (!config.getDisabled()) {
            ObjectNode connection = mapper.createObjectNode().put(JSON.TYPE, JSON.SYSTEM_CONNECTION);
            ObjectNode data = connection.putObject(JSON.DATA);
            data.put(JSON.NAME, config.getConnectionName());
            data.put(JSON.MFG, config.getManufacturer());
            data.put(JSON.PREFIX, config.getAdapter().getSystemConnectionMemo().getSystemPrefix());
            data.put(JSON.DESCRIPTION, Bundle.getMessage(locale, "ConnectionSucceeded", config.getConnectionName(), config.name(), config.getInfo()));
            prefixes.add(config.getAdapter().getSystemConnectionMemo().getSystemPrefix());
            root.add(connection);
        }
    }
    InstanceManager.getList(SystemConnectionMemo.class).stream().map((instance) -> instance).filter((memo) -> (!memo.getDisabled() && !prefixes.contains(memo.getSystemPrefix()))).forEach((memo) -> {
        ObjectNode connection = mapper.createObjectNode().put(JSON.TYPE, JSON.SYSTEM_CONNECTION);
        ObjectNode data = connection.putObject(JSON.DATA);
        data.put(JSON.NAME, memo.getUserName());
        data.put(JSON.PREFIX, memo.getSystemPrefix());
        data.putNull(JSON.MFG);
        data.putNull(JSON.DESCRIPTION);
        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(JSON.TYPE, JSON.SYSTEM_CONNECTION);
        ObjectNode data = connection.putObject(JSON.DATA);
        data.put(JSON.NAME, ConnectionNameFromSystemName.getConnectionName(prefix));
        data.put(JSON.PREFIX, prefix);
        data.putNull(JSON.MFG);
        data.putNull(JSON.DESCRIPTION);
        root.add(connection);
    }
    return root;
}
Also used : ControlPanelEditor(jmri.jmrit.display.controlPanelEditor.ControlPanelEditor) Arrays(java.util.Arrays) Enumeration(java.util.Enumeration) ConnectionConfig(jmri.jmrix.ConnectionConfig) URL(jmri.server.json.JSON.URL) ProfileManager(jmri.profile.ProfileManager) DccLocoAddress(jmri.DccLocoAddress) JmriJFrame(jmri.util.JmriJFrame) PANEL(jmri.server.json.JSON.PANEL) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Editor(jmri.jmrit.display.Editor) JsonException(jmri.server.json.JsonException) SWITCHBOARD_PANEL(jmri.server.json.JSON.SWITCHBOARD_PANEL) ArrayList(java.util.ArrayList) TYPE(jmri.server.json.JSON.TYPE) JsonServerPreferences(jmri.jmris.json.JsonServerPreferences) ConnectionConfigManager(jmri.jmrix.ConnectionConfigManager) Locale(java.util.Locale) Profile(jmri.profile.Profile) SwitchboardEditor(jmri.jmrit.display.switchboardEditor.SwitchboardEditor) PanelEditor(jmri.jmrit.display.panelEditor.PanelEditor) JsonNode(com.fasterxml.jackson.databind.JsonNode) NAME(jmri.server.json.JSON.NAME) InstanceManager(jmri.InstanceManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) JsonHttpService(jmri.server.json.JsonHttpService) Metadata(jmri.Metadata) LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) WebServerPreferences(jmri.web.server.WebServerPreferences) SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo) CONTROL_PANEL(jmri.server.json.JSON.CONTROL_PANEL) ConnectionNameFromSystemName(jmri.util.ConnectionNameFromSystemName) DATA(jmri.server.json.JSON.DATA) USERNAME(jmri.server.json.JSON.USERNAME) JSON(jmri.server.json.JSON) NodeIdentity(jmri.util.node.NodeIdentity) ZeroConfService(jmri.util.zeroconf.ZeroConfService) LAYOUT_PANEL(jmri.server.json.JSON.LAYOUT_PANEL) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ConnectionConfig(jmri.jmrix.ConnectionConfig)

Example 9 with SystemConnectionMemo

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

the class JmriSRCPTurnoutServer method initTurnout.

/*
     * Initialize an SRCP server turnout. Constructs the system name 
     * string from the provided parameters.
     */
public void initTurnout(int bus, int address, String protocol) throws jmri.JmriException, java.io.IOException {
    log.debug("init Turnout called with bus {} address {} and protocol {}", bus, address, protocol);
    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 turnoutName = memo.getSystemPrefix() + "T" + address;
    // create turnout if it does not exist.
    this.initTurnout(turnoutName);
    TimeStampedOutput.writeTimestamp(output, "101 INFO " + bus + " GA " + address + " " + protocol + "\n\r");
}
Also used : SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo)

Example 10 with SystemConnectionMemo

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

the class JmriSRCPTurnoutServer method parseStatus.

/*
     * for SRCP, we're doing the parsing elsewhere, so we just need to build
     * the correct string from the provided compoents.
     */
public void parseStatus(int bus, int address, int value) throws jmri.JmriException, java.io.IOException {
    log.debug("parse Status called with bus {} address {} and value {}", bus, address, value);
    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 turnoutName = memo.getSystemPrefix() + "T" + address;
    //this.initTurnout(turnoutName);
    if (value == 1) {
        log.debug("Setting Turnout THROWN");
        throwTurnout(turnoutName);
    } else if (value == 0) {
        log.debug("Setting Turnout CLOSED");
        closeTurnout(turnoutName);
    }
    sendStatus(bus, address);
}
Also used : SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo)

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