Search in sources :

Example 21 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class JmriSRCPThrottleServer method initThrottle.

public void initThrottle(int bus, int address, boolean isLong, int speedsteps, int functions) throws IOException {
    log.debug("initThrottle 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, isLong);
        busList.add(Integer.valueOf(bus));
        addressList.add(addr);
        t.requestThrottle(addr, this);
    }
}
Also used : SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo) ThrottleManager(jmri.ThrottleManager) DccLocoAddress(jmri.DccLocoAddress)

Example 22 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class JmriSRCPThrottleServer method setThrottleFunctions.

/*
     * Set Throttle Functions on/off
     *
     * @param bus, bus the throttle is on.
     * @param l address of the locomotive to change speed of.
     * @param fList an ArrayList of boolean values indicating whether the
     *         function is active or not.
     */
public void setThrottleFunctions(int bus, int address, ArrayList<Boolean> fList) {
    log.debug("Setting Functions for address {} bus {}", address, bus);
    java.util.List<SystemConnectionMemo> list = jmri.InstanceManager.getList(SystemConnectionMemo.class);
    SystemConnectionMemo memo = null;
    try {
        memo = list.get(bus - 1);
    } catch (java.lang.IndexOutOfBoundsException obe) {
        try {
            TimeStampedOutput.writeTimestamp(output, Bundle.getMessage("Error412"));
        } catch (IOException ioe) {
            log.error("Error writing to network port");
        }
        return;
    }
    /* request the throttle for this particular locomotive address */
    if (memo.provides(jmri.ThrottleManager.class)) {
        ThrottleManager tm = 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, tm.canBeLongAddress(address));
        // get the throttle for the address.
        if (addressList.contains(addr)) {
            log.debug("Throttle in throttle list");
            Throttle t = throttleList.get(addressList.indexOf(addr));
            for (int i = 0; i < fList.size(); i++) {
                try {
                    java.lang.reflect.Method setter = t.getClass().getMethod("setF" + i, boolean.class);
                    setter.invoke(t, fList.get(i));
                } catch (java.lang.NoSuchMethodException | java.lang.IllegalAccessException | java.lang.reflect.InvocationTargetException ex1) {
                    ex1.printStackTrace();
                    try {
                        sendErrorStatus();
                    } catch (IOException ioe) {
                        log.error("Error writing to network port");
                    }
                }
            }
        }
    }
}
Also used : IOException(java.io.IOException) DccLocoAddress(jmri.DccLocoAddress) Throttle(jmri.Throttle) DccThrottle(jmri.DccThrottle) SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo) ThrottleManager(jmri.ThrottleManager)

Example 23 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class JmriSRCPThrottleServer method setThrottleSpeedAndDirection.

/*
     * Set Throttle Speed and Direction
     *
     * @param bus, bus the throttle is on.
     * @param l address of the locomotive to change speed of.
     * @param speed float representing the speed, -1 for emergency stop.
     * @param isForward boolean, true if forward, false if reverse or
     * undefined.
     */
public void setThrottleSpeedAndDirection(int bus, int address, float speed, boolean isForward) {
    log.debug("Setting Speed for address {} bus {} to {} with direction {}", address, bus, speed, isForward ? "forward" : "reverse");
    java.util.List<SystemConnectionMemo> list = jmri.InstanceManager.getList(SystemConnectionMemo.class);
    SystemConnectionMemo memo = null;
    try {
        memo = list.get(bus - 1);
    } catch (java.lang.IndexOutOfBoundsException obe) {
        try {
            TimeStampedOutput.writeTimestamp(output, Bundle.getMessage("Error412"));
        } catch (IOException ioe) {
            log.error("Error writing to network port");
        }
        return;
    }
    /* request the throttle for this particular locomotive address */
    if (memo.provides(jmri.ThrottleManager.class)) {
        ThrottleManager tm = 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, tm.canBeLongAddress(address));
        // get the throttle for the address.
        if (addressList.contains(addr)) {
            log.debug("Throttle in throttle list");
            Throttle t = throttleList.get(addressList.indexOf(addr));
            // set the speed and direction.
            t.setSpeedSetting(speed);
            t.setIsForward(isForward);
        }
    }
}
Also used : SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo) ThrottleManager(jmri.ThrottleManager) IOException(java.io.IOException) DccLocoAddress(jmri.DccLocoAddress) Throttle(jmri.Throttle) DccThrottle(jmri.DccThrottle)

Example 24 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class WarrantManagerXml method storeTrain.

static Element storeTrain(Warrant warrant, String type) {
    Element elem = new Element(type);
    String str = warrant.getTrainId();
    if (str == null)
        str = "";
    elem.setAttribute("trainId", str);
    DccLocoAddress addr = warrant.getDccAddress();
    if (addr != null) {
        elem.setAttribute("dccAddress", "" + addr.getNumber());
        elem.setAttribute("dccType", "" + (addr.isLongAddress() ? "L" : "S"));
    }
    elem.setAttribute("runBlind", warrant.getRunBlind() ? "true" : "false");
    elem.setAttribute("shareRoute", warrant.getShareRoute() ? "true" : "false");
    elem.setAttribute("noRamp", warrant.getNoRamp() ? "true" : "false");
    str = warrant.getTrainName();
    if (str == null)
        str = "";
    elem.setAttribute("trainName", str);
    return elem;
}
Also used : Element(org.jdom2.Element) DccLocoAddress(jmri.DccLocoAddress)

Example 25 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class ConsistController method removeConsist.

/**
     * remove a consist by it's Dcc address. Wiil remove all locos in the
     * process.
     *
     * @param message RCR<;>consistAddress
     */
private void removeConsist(String message) {
    List<String> header = Arrays.asList(message.split("<;>"));
    Consist consist = null;
    try {
        consist = manager.getConsist(stringToDcc(header.get(1)));
        while (!consist.getConsistList().isEmpty()) {
            DccLocoAddress loco = consist.getConsistList().get(0);
            if (log.isDebugEnabled()) {
                log.debug("Remove loco: " + loco + ", from consist: " + consist.getConsistAddress().toString());
            }
            consist.remove(loco);
        }
    } catch (NullPointerException noCon) {
        log.warn("Consist: " + header.get(1) + " not found. Cannot delete.");
        return;
    }
    try {
        manager.delConsist(stringToDcc(header.get(1)));
    } catch (NullPointerException noCon) {
        log.warn("Consist: " + header.get(1) + " not found. Cannot delete.");
        return;
    }
    writeFile();
}
Also used : Consist(jmri.Consist) DccLocoAddress(jmri.DccLocoAddress)

Aggregations

DccLocoAddress (jmri.DccLocoAddress)96 Consist (jmri.Consist)12 ThrottleManager (jmri.ThrottleManager)7 IOException (java.io.IOException)6 Element (org.jdom2.Element)6 Test (org.junit.Test)6 Matcher (java.util.regex.Matcher)5 DccThrottle (jmri.DccThrottle)5 SystemConnectionMemo (jmri.jmrix.SystemConnectionMemo)5 JsonException (jmri.server.json.JsonException)5 Pattern (java.util.regex.Pattern)4 IdTag (jmri.IdTag)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 JTextField (javax.swing.JTextField)2 CommandStation (jmri.CommandStation)2 ProgrammerException (jmri.ProgrammerException)2