Search in sources :

Example 76 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class AbstractThrottle method sendFunctionGroup5.

/**
     * Send the message to set the state of functions F21, F22, F23, F24, F25,
     * F26, F27, F28
     * <P>
     * This is used in the setFn implementations provided in this class, but a
     * real implementation needs to be provided.
     */
protected void sendFunctionGroup5() {
    DccLocoAddress a = (DccLocoAddress) getLocoAddress();
    byte[] result = jmri.NmraPacket.function21Through28Packet(a.getNumber(), a.isLongAddress(), getF21(), getF22(), getF23(), getF24(), getF25(), getF26(), getF27(), getF28());
    //if the result returns as null, we should quit.
    if (result == null) {
        return;
    }
    CommandStation c;
    if ((adapterMemo != null) && (adapterMemo.get(jmri.CommandStation.class) != null)) {
        c = adapterMemo.get(jmri.CommandStation.class);
    } else {
        c = InstanceManager.getNullableDefault(CommandStation.class);
    }
    // send it 3 times
    if (c != null) {
        c.sendPacket(result, 3);
    } else {
        log.error("Can't send F21-F28 since no command station defined");
    }
}
Also used : CommandStation(jmri.CommandStation) DccLocoAddress(jmri.DccLocoAddress)

Example 77 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class AbstractThrottle method sendFunctionGroup4.

/**
     * Send the message to set the state of functions F13, F14, F15, F16, F17,
     * F18, F19, F20
     * <P>
     * This is used in the setFn implementations provided in this class, but a
     * real implementation needs to be provided.
     */
protected void sendFunctionGroup4() {
    DccLocoAddress a = (DccLocoAddress) getLocoAddress();
    byte[] result = jmri.NmraPacket.function13Through20Packet(a.getNumber(), a.isLongAddress(), getF13(), getF14(), getF15(), getF16(), getF17(), getF18(), getF19(), getF20());
    //if the result returns as null, we should quit.
    if (result == null) {
        return;
    }
    CommandStation c;
    if ((adapterMemo != null) && (adapterMemo.get(jmri.CommandStation.class) != null)) {
        c = adapterMemo.get(jmri.CommandStation.class);
    } else {
        c = InstanceManager.getNullableDefault(CommandStation.class);
    }
    // send it 3 times
    if (c != null) {
        c.sendPacket(result, 3);
    } else {
        log.error("Can't send F13-F20 since no command station defined");
    }
}
Also used : CommandStation(jmri.CommandStation) DccLocoAddress(jmri.DccLocoAddress)

Example 78 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class SpeedoConsoleFrame method programmingOpReply.

@Override
public void programmingOpReply(int value, int status) {
    if (status == 0) {
        switch(readState) {
            case IDLE:
                log.debug("unexpected reply in IDLE state");
                break;
            case WAIT29:
                // Check extended address bit
                if ((value & 0x20) == 0) {
                    readState = ProgState.WAIT1;
                    statusLabel.setText(rb.getString("ProgRdShort"));
                    startRead(1);
                } else {
                    readState = ProgState.WAIT17;
                    statusLabel.setText(rb.getString("ProgRdExtended"));
                    startRead(17);
                }
                break;
            case WAIT1:
                readAddress = value;
                //profileAddressField.setText(Integer.toString(profileAddress));
                //profileAddressField.setBackground(Color.WHITE);
                addrSelector.setAddress(new DccLocoAddress(readAddress, false));
                changeOfAddress();
                readState = ProgState.IDLE;
                break;
            case WAIT17:
                readAddress = value;
                readState = ProgState.WAIT18;
                startRead(18);
                break;
            case WAIT18:
                readAddress = (readAddress & 0x3f) * 256 + value;
                //profileAddressField.setText(Integer.toString(profileAddress));
                //profileAddressField.setBackground(Color.WHITE);
                addrSelector.setAddress(new DccLocoAddress(readAddress, true));
                changeOfAddress();
                statusLabel.setText(rb.getString("ProgRdComplete"));
                readState = ProgState.IDLE;
                break;
            default:
                log.warn("Unhandled read state: {}", readState);
                break;
        }
    } else {
        // Error during programming
        log.error("Status not OK during read: " + status);
        //profileAddressField.setText("Error");
        statusLabel.setText(rb.getString("ProgRdError"));
        readState = ProgState.IDLE;
    }
}
Also used : DccLocoAddress(jmri.DccLocoAddress)

Example 79 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class CbusThrottleManager method requestThrottleSetup.

/**
     * Request a new throttle object be created for the address
     *
     */
@Override
public synchronized void requestThrottleSetup(LocoAddress address, boolean control) {
    _dccAddr = (DccLocoAddress) address;
    _intAddr = _dccAddr.getNumber();
    // The CBUS protocol requires that we request a session from the command
    // station. Throttle object will be notified by Command Station
    log.debug("Requesting session for throttle");
    CanMessage msg = new CanMessage(3, tc.getCanid());
    // Request a session for this throttle
    msg.setOpCode(CbusConstants.CBUS_RLOC);
    if (((DccLocoAddress) address).isLongAddress()) {
        _intAddr = _intAddr | 0xC000;
    }
    msg.setElement(1, (_intAddr / 256));
    msg.setElement(2, _intAddr & 0xff);
    tc.sendCanMessage(msg, this);
    _handleExpected = true;
    startThrottleRequestTimer();
}
Also used : CanMessage(jmri.jmrix.can.CanMessage) DccLocoAddress(jmri.DccLocoAddress)

Example 80 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class DebugThrottleManager method requestThrottleSetup.

@Override
public void requestThrottleSetup(LocoAddress a, boolean control) {
    // Immediately trigger the callback.
    DccLocoAddress address = (DccLocoAddress) a;
    log.debug("new debug throttle for " + address);
    notifyThrottleKnown(new DebugThrottle(address, adapterMemo), a);
}
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