Search in sources :

Example 16 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class NceConsist method getLocoAddressByPosition.

public DccLocoAddress getLocoAddressByPosition(int position) {
    DccLocoAddress locoAddress;
    ArrayList<DccLocoAddress> list = getConsistList();
    for (int i = 0; i < list.size(); i++) {
        locoAddress = list.get(i);
        if (getPosition(locoAddress) == position) {
            return locoAddress;
        }
    }
    return null;
}
Also used : DccLocoAddress(jmri.DccLocoAddress)

Example 17 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class NceConsist method dispose.

// Clean Up local storage
@Override
public void dispose() {
    if (ConsistList.size() > 0) {
        // kill this consist
        DccLocoAddress locoAddress = ConsistList.get(0);
        killConsist(locoAddress.getNumber(), locoAddress.isLongAddress());
    }
    stopReadNCEconsistThread();
    super.dispose();
}
Also used : DccLocoAddress(jmri.DccLocoAddress)

Example 18 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class NceConsist method setConsistType.

// Set the Consist Type
@Override
public void setConsistType(int consist_type) {
    if (consist_type == Consist.ADVANCED_CONSIST) {
        ConsistType = consist_type;
    } else {
        log.error("Consist Type Not Supported");
        notifyConsistListeners(new DccLocoAddress(0, false), ConsistListener.NotImplemented);
    }
}
Also used : DccLocoAddress(jmri.DccLocoAddress)

Example 19 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class DccLocoAddressXml method store.

/**
     * Default implementation for storing the contents of a DccLocoAddress
     *
     * @param o Object to store, of type DccLocoAddress
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    DccLocoAddress p = (DccLocoAddress) o;
    Element element = new Element("dcclocoaddress");
    // include contents
    if (p != null) {
        element.setAttribute("number", "" + p.getNumber());
        if (p.isLongAddress()) {
            element.setAttribute("longaddress", "yes");
        } else {
            element.setAttribute("longaddress", "no");
        }
    } else {
        element.setAttribute("number", "");
        element.setAttribute("longaddress", "no");
    }
    return element;
}
Also used : Element(org.jdom2.Element) DccLocoAddress(jmri.DccLocoAddress)

Example 20 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class JsonConsistServer method parseRequest.

public void parseRequest(Locale locale, JsonNode data) throws IOException, JsonException {
    DccLocoAddress address;
    if (data.path(ADDRESS).canConvertToInt()) {
        address = new DccLocoAddress(data.path(ADDRESS).asInt(), data.path(IS_LONG_ADDRESS).asBoolean(false));
    } else {
        address = JsonUtil.addressForString(data.path(ADDRESS).asText());
    }
    if (data.path(METHOD).asText().equals(PUT)) {
        JsonUtil.putConsist(locale, address, data);
    } else if (data.path(METHOD).asText().equals(DELETE)) {
        JsonUtil.delConsist(locale, address);
    } else {
        JsonUtil.setConsist(locale, address, data);
    }
    this.connection.sendMessage(this.mapper.writeValueAsString(JsonUtil.getConsist(locale, address)));
    InstanceManager.getDefault(jmri.ConsistManager.class).getConsist(address).addConsistListener(new JsonConsistListener(address));
}
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