Search in sources :

Example 31 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class JsonConsistHttpService method doPut.

@Override
public JsonNode doPut(String type, String name, JsonNode data, Locale locale) throws JsonException {
    if (!this.manager.isConsistManager()) {
        // NOI18N
        throw new JsonException(503, Bundle.getMessage(locale, "ErrorNoConsistManager"));
    }
    DccLocoAddress address;
    if (data.path(ADDRESS).canConvertToInt()) {
        address = new DccLocoAddress(data.path(ADDRESS).asInt(), data.path(IS_LONG_ADDRESS).asBoolean(false));
    } else {
        address = JsonUtilHttpService.addressForString(data.path(ADDRESS).asText());
    }
    this.manager.getConsist(address);
    return this.doPost(type, name, data, locale);
}
Also used : JsonException(jmri.server.json.JsonException) DccLocoAddress(jmri.DccLocoAddress)

Example 32 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class DccConsistTest method testCtor.

@Test
public void testCtor() {
    // NmraLocoAddress constructor test.
    DccConsist c = new DccConsist(new DccLocoAddress(12, true));
    Assert.assertNotNull(c);
}
Also used : DccLocoAddress(jmri.DccLocoAddress) Test(org.junit.Test)

Example 33 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class DccLocoAddressSelectorTest method testSetNumByField1.

// try setting the address after creation
public void testSetNumByField1() {
    setThrottleManager();
    DccLocoAddressSelector sel = new DccLocoAddressSelector();
    JTextField f = sel.getTextField();
    f.setText("123");
    Assert.assertEquals("check initial number ", 123, sel.getAddress().getNumber());
    sel.setAddress(new DccLocoAddress(2000, true));
    Assert.assertEquals("check updated number ", 2000, sel.getAddress().getNumber());
    Assert.assertEquals("check updated type ", true, sel.getAddress().isLongAddress());
}
Also used : JTextField(javax.swing.JTextField) DccLocoAddress(jmri.DccLocoAddress)

Example 34 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class AbstractThrottleServer method releaseThrottle.

/*
     * Release a throttle for the specified address from the default
     * Throttle Manager.
     *
     * @param l LocoAddress of the locomotive to request.
     */
public void releaseThrottle(LocoAddress l) {
    ThrottleManager t = InstanceManager.throttleManagerInstance();
    t.cancelThrottleRequest(l.getNumber(), this);
    if (l instanceof DccLocoAddress) {
        throttleList.forEach(throttle -> {
            if (throttle.getLocoAddress() == l) {
                t.releaseThrottle((DccThrottle) throttle, this);
                throttleList.remove(throttle);
                try {
                    sendThrottleReleased(l);
                } catch (IOException ioe) {
                    log.error("Error writing to network port");
                }
            }
        });
    }
}
Also used : ThrottleManager(jmri.ThrottleManager) IOException(java.io.IOException) DccLocoAddress(jmri.DccLocoAddress)

Example 35 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class AbstractThrottleServer method requestThrottle.

/*
     * Request a throttle for the specified address from the default
     * Throttle Manager.
     *
     * @param l LocoAddress of the locomotive to request.
     */
public void requestThrottle(LocoAddress l) {
    ThrottleManager t = InstanceManager.throttleManagerInstance();
    boolean result;
    if (l instanceof DccLocoAddress) {
        result = t.requestThrottle(((DccLocoAddress) l), this);
    } else {
        result = t.requestThrottle(l.getNumber(), t.canBeLongAddress(l.getNumber()), this);
    }
    if (!result) {
        try {
            sendErrorStatus();
        } catch (IOException ioe) {
            log.error("Error writing to network port");
        }
    }
}
Also used : ThrottleManager(jmri.ThrottleManager) IOException(java.io.IOException) 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