Search in sources :

Example 36 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class Warrant method setDccAddress.

/**
     * Sets dccAddress and fetches RosterEntry
     * @param id address as a String
     * @return true if address found for id
     */
public boolean setDccAddress(String id) {
    _train = Roster.getDefault().entryFromTitle(id);
    if (_train == null) {
        int index = id.indexOf('(');
        String numId;
        if (index >= 0) {
            numId = id.substring(0, index);
        } else {
            numId = id;
        }
        try {
            List<RosterEntry> l = Roster.getDefault().matchingList(null, null, numId, null, null, null, null);
            if (l.size() > 0) {
                _train = l.get(0);
                if (_trainId == null) {
                    // In some systems, such as Maerklin MFX or ESU ECOS M4, the DCC address is always 0.
                    // That should not make us overwrite the _trainId.
                    _trainId = _train.getId();
                }
            } else {
                _train = null;
                _trainId = null;
                boolean isLong = true;
                if ((index + 1) < id.length() && (id.charAt(index + 1) == 'S' || id.charAt(index + 1) == 's')) {
                    isLong = false;
                }
                int num = Integer.parseInt(numId);
                _dccAddress = new DccLocoAddress(num, isLong);
                _trainId = _dccAddress.toString();
            }
        } catch (NumberFormatException e) {
            _dccAddress = null;
            return false;
        }
    } else {
        _trainId = id;
        _dccAddress = _train.getDccLocoAddress();
    }
    return true;
}
Also used : RosterEntry(jmri.jmrit.roster.RosterEntry) DccLocoAddress(jmri.DccLocoAddress)

Example 37 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class DccConsist method setConsistType.

// Set the Consist Type
@Override
public void setConsistType(int consist_type) {
    if (consist_type == 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 38 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class DccConsist method dispose.

// Clean Up local Storage.
@Override
public void dispose() {
    for (int i = (ConsistList.size() - 1); i >= 0; i--) {
        DccLocoAddress loco = ConsistList.get(i);
        if (log.isDebugEnabled()) {
            log.debug("Deleting Locomotive: " + loco.toString());
        }
        try {
            remove(loco);
        } catch (Exception ex) {
            log.error("Error removing loco: " + loco.toString() + " from consist: " + ConsistAddress.toString());
        }
    }
    ConsistList = null;
    ConsistDir = null;
    ConsistPosition = null;
    ConsistRoster = null;
}
Also used : ProgrammerException(jmri.ProgrammerException) DccLocoAddress(jmri.DccLocoAddress)

Example 39 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class JmriSRCPThrottleServer method sendStatus.

/*
     * send the status of the specified throttle address on the specified bus
     * @param bus bus number.
     * @param address locomoitve address.
     */
public void sendStatus(int bus, int address) throws IOException {
    log.debug("send Status 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, t.canBeLongAddress(address));
        Boolean isForward = (Boolean) t.getThrottleInfo(addr, "IsForward");
        Float speedSetting = (Float) t.getThrottleInfo(addr, "SpeedSetting");
        Integer speedStepMode = (Integer) t.getThrottleInfo(addr, "SpeedStepMode");
        Boolean f0 = (Boolean) t.getThrottleInfo(addr, "F0");
        Boolean f1 = (Boolean) t.getThrottleInfo(addr, "F1");
        Boolean f2 = (Boolean) t.getThrottleInfo(addr, "F2");
        Boolean f3 = (Boolean) t.getThrottleInfo(addr, "F3");
        Boolean f4 = (Boolean) t.getThrottleInfo(addr, "F4");
        Boolean f5 = (Boolean) t.getThrottleInfo(addr, "F5");
        Boolean f6 = (Boolean) t.getThrottleInfo(addr, "F6");
        Boolean f7 = (Boolean) t.getThrottleInfo(addr, "F7");
        Boolean f8 = (Boolean) t.getThrottleInfo(addr, "F8");
        Boolean f9 = (Boolean) t.getThrottleInfo(addr, "F9");
        Boolean f10 = (Boolean) t.getThrottleInfo(addr, "F10");
        Boolean f11 = (Boolean) t.getThrottleInfo(addr, "F11");
        Boolean f12 = (Boolean) t.getThrottleInfo(addr, "F12");
        Boolean f13 = (Boolean) t.getThrottleInfo(addr, "F13");
        Boolean f14 = (Boolean) t.getThrottleInfo(addr, "F14");
        Boolean f15 = (Boolean) t.getThrottleInfo(addr, "F15");
        Boolean f16 = (Boolean) t.getThrottleInfo(addr, "F16");
        Boolean f17 = (Boolean) t.getThrottleInfo(addr, "F17");
        Boolean f18 = (Boolean) t.getThrottleInfo(addr, "F18");
        Boolean f19 = (Boolean) t.getThrottleInfo(addr, "F19");
        Boolean f20 = (Boolean) t.getThrottleInfo(addr, "F20");
        Boolean f21 = (Boolean) t.getThrottleInfo(addr, "F21");
        Boolean f22 = (Boolean) t.getThrottleInfo(addr, "F22");
        Boolean f23 = (Boolean) t.getThrottleInfo(addr, "F23");
        Boolean f24 = (Boolean) t.getThrottleInfo(addr, "F24");
        Boolean f25 = (Boolean) t.getThrottleInfo(addr, "F25");
        Boolean f26 = (Boolean) t.getThrottleInfo(addr, "F26");
        Boolean f27 = (Boolean) t.getThrottleInfo(addr, "F27");
        Boolean f28 = (Boolean) t.getThrottleInfo(addr, "F28");
        // and now build the output string to send
        String StatusString = "100 INFO " + bus + " GL " + address + " ";
        StatusString += isForward ? "1 " : "0 ";
        switch(speedStepMode) {
            case DccThrottle.SpeedStepMode14:
                StatusString += (int) java.lang.Math.ceil(speedSetting * 14) + " " + 14;
                break;
            case DccThrottle.SpeedStepMode27:
                StatusString += (int) java.lang.Math.ceil(speedSetting * 27) + " " + 27;
                break;
            case DccThrottle.SpeedStepMode28:
                StatusString += (int) java.lang.Math.ceil(speedSetting * 28) + " " + 28;
                break;
            case DccThrottle.SpeedStepMode128:
                StatusString += (int) java.lang.Math.ceil(speedSetting * 126) + " " + 126;
                break;
            default:
                StatusString += (int) java.lang.Math.ceil(speedSetting * 100) + " " + 100;
        }
        StatusString += f0 ? " 1" : " 0";
        StatusString += f1 ? " 1" : " 0";
        StatusString += f2 ? " 1" : " 0";
        StatusString += f3 ? " 1" : " 0";
        StatusString += f4 ? " 1" : " 0";
        StatusString += f5 ? " 1" : " 0";
        StatusString += f6 ? " 1" : " 0";
        StatusString += f7 ? " 1" : " 0";
        StatusString += f8 ? " 1" : " 0";
        StatusString += f9 ? " 1" : " 0";
        StatusString += f10 ? " 1" : " 0";
        StatusString += f11 ? " 1" : " 0";
        StatusString += f12 ? " 1" : " 0";
        StatusString += f13 ? " 1" : " 0";
        StatusString += f14 ? " 1" : " 0";
        StatusString += f15 ? " 1" : " 0";
        StatusString += f16 ? " 1" : " 0";
        StatusString += f17 ? " 1" : " 0";
        StatusString += f18 ? " 1" : " 0";
        StatusString += f19 ? " 1" : " 0";
        StatusString += f20 ? " 1" : " 0";
        StatusString += f21 ? " 1" : " 0";
        StatusString += f22 ? " 1" : " 0";
        StatusString += f23 ? " 1" : " 0";
        StatusString += f24 ? " 1" : " 0";
        StatusString += f25 ? " 1" : " 0";
        StatusString += f26 ? " 1" : " 0";
        StatusString += f27 ? " 1" : " 0";
        StatusString += f28 ? " 1" : " 0";
        StatusString += "\n\r";
        TimeStampedOutput.writeTimestamp(output, StatusString);
    } else {
        TimeStampedOutput.writeTimestamp(output, Bundle.getMessage("Error412"));
        return;
    }
}
Also used : SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo) ThrottleManager(jmri.ThrottleManager) DccLocoAddress(jmri.DccLocoAddress)

Example 40 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class JmriSRCPThrottleServer method releaseThrottle.

public void releaseThrottle(int bus, int address) throws IOException {
    log.debug("releaseThrottle 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;
    }
    /* release the throttle for this particular locomotive address */
    if (memo.provides(jmri.ThrottleManager.class)) {
        ThrottleManager t = memo.get(jmri.ThrottleManager.class);
        DccLocoAddress addr = new DccLocoAddress(address, t.canBeLongAddress(address));
        t.releaseThrottle((DccThrottle) throttleList.get(addressList.indexOf(addr)), this);
        throttleList.remove(addressList.indexOf(addr));
        sendThrottleReleased(addr);
        busList.remove(addressList.indexOf(addr));
        addressList.remove(addr);
    }
}
Also used : SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo) ThrottleManager(jmri.ThrottleManager) 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