Search in sources :

Example 56 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class ConsistController method setConsistCVs.

/**
     * set CV 21&22 for consist functions send each CV individually
     *
     * @param message RCF<;> locoAddress <:> CV# <;> value
     */
private void setConsistCVs(String message) {
    DccLocoAddress loco;
    List<String> headerAndCVs = Arrays.asList(message.split("<:>"));
    if (log.isDebugEnabled()) {
        log.debug("setConsistCVs string: " + message);
    }
    try {
        List<String> headerData = Arrays.asList(headerAndCVs.get(0).split("<;>"));
        loco = stringToDcc(headerData.get(1));
        if (checkForBroadcastAddress(loco)) {
            return;
        }
    } catch (NullPointerException e) {
        log.warn("setConsistCVs error for message: " + message);
        return;
    }
    AddressedProgrammer pom = jmri.InstanceManager.getDefault(jmri.ProgrammerManager.class).getAddressedProgrammer(loco.isLongAddress(), loco.getNumber());
    // loco done, now get CVs
    for (int i = 1; i < headerAndCVs.size(); i++) {
        List<String> CVData = Arrays.asList(headerAndCVs.get(i).split("<;>"));
        try {
            int CVNum = Integer.parseInt(CVData.get(0));
            int CVValue = Integer.parseInt(CVData.get(1));
            try {
                pom.writeCV(CVNum, CVValue, this);
            } catch (ProgrammerException e) {
            }
        } catch (NumberFormatException nfe) {
            log.warn("Error in setting CVs: " + nfe);
        }
    }
    jmri.InstanceManager.getDefault(jmri.ProgrammerManager.class).releaseAddressedProgrammer(pom);
}
Also used : ProgrammerException(jmri.ProgrammerException) AddressedProgrammer(jmri.AddressedProgrammer) DccLocoAddress(jmri.DccLocoAddress)

Example 57 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class ConsistController method stringToDcc.

public DccLocoAddress stringToDcc(String s) {
    int num = Integer.parseInt(s.substring(1));
    boolean isLong = (s.charAt(0) == 'L');
    return (new DccLocoAddress(num, isLong));
}
Also used : DccLocoAddress(jmri.DccLocoAddress)

Example 58 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class ConsistController method reorderConsist.

/**
     * Change the sequence of locos in this consist. Reorders the consistList,
     * instead of setting the 'position' value. Lead and Trail are set on first
     * and last locos by DccConsist.
     *
     * @param message RCP<;>consistAddress<:>leadLoco<;>nextLoco<;>...
     * ...<;>nextLoco<;>trailLoco
     */
private void reorderConsist(String message) {
    Consist consist;
    List<String> headerAndLocos = Arrays.asList(message.split("<:>"));
    if (headerAndLocos.size() < 2) {
        log.warn("reorderConsist missing data in message: " + message);
        return;
    }
    try {
        List<String> headerData = Arrays.asList(headerAndLocos.get(0).split("<;>"));
        //  
        consist = manager.getConsist(stringToDcc(headerData.get(1)));
        List<String> locoData = Arrays.asList(headerAndLocos.get(1).split("<;>"));
        /*
             * Reorder the consistList:
             * For each loco sent, remove it from the consistList
             * and reinsert it at the front of the list.
             */
        for (String loco : locoData) {
            ArrayList<DccLocoAddress> conList = consist.getConsistList();
            int index = conList.indexOf(stringToDcc(loco));
            if (index != -1) {
                conList.add(conList.remove(index));
            }
        }
    } catch (NullPointerException e) {
        log.warn("reorderConsist error for message: " + message);
        return;
    }
    writeFile();
}
Also used : Consist(jmri.Consist) DccLocoAddress(jmri.DccLocoAddress)

Example 59 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class ConsistController method removeLoco.

/**
     * remove a loco if it exist in this consist.
     *
     * @param message RC-<;>consistAddress<:>locoAddress
     */
private void removeLoco(String message) {
    Consist consist;
    List<String> headerAndLoco = Arrays.asList(message.split("<:>"));
    if (log.isDebugEnabled()) {
        log.debug("remove loco string: " + message);
    }
    try {
        List<String> headerData = Arrays.asList(headerAndLoco.get(0).split("<;>"));
        consist = manager.getConsist(stringToDcc(headerData.get(1)));
        List<String> locoData = Arrays.asList(headerAndLoco.get(1).split("<;>"));
        DccLocoAddress loco = stringToDcc(locoData.get(0));
        if (checkForBroadcastAddress(loco)) {
            return;
        }
        if (consist.contains(loco)) {
            consist.remove(loco);
            if (log.isDebugEnabled()) {
                log.debug("Remove loco: " + loco + ", from consist: " + headerData.get(1));
            }
        }
    } catch (NullPointerException e) {
        log.warn("removeLoco error for message: " + message);
        return;
    }
    writeFile();
}
Also used : Consist(jmri.Consist) DccLocoAddress(jmri.DccLocoAddress)

Example 60 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class WiFiConsistManager method stringToDcc.

public DccLocoAddress stringToDcc(String s) {
    int num = Integer.parseInt(s.substring(1));
    boolean isLong = (s.charAt(0) == 'L');
    return (new DccLocoAddress(num, isLong));
}
Also used : 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