Search in sources :

Example 11 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class ConsistToolFrame method restoreButtonActionPerformed.

public void restoreButtonActionPerformed(ActionEvent e) {
    if (adrSelector.getAddress() == null) {
        JOptionPane.showMessageDialog(this, Bundle.getMessage("NoConsistSelectedError"));
        return;
    }
    // make sure any new locomotives are added to the consist.
    addLocoButtonActionPerformed(e);
    /*
         * get the array list of the locomotives in the consist
         */
    DccLocoAddress address = adrSelector.getAddress();
    Consist tempConsist = ConsistMan.getConsist(address);
    tempConsist.restore();
}
Also used : Consist(jmri.Consist) DccLocoAddress(jmri.DccLocoAddress)

Example 12 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class AbstractThrottleManager method notifyThrottleKnown.

/**
     * Handle throttle information when it's finally available, e.g. when a new
     * Throttle object has been created.
     * <P>
     * This method creates a throttle for all ThrottleListeners of that address
     * and notifies them via the ThrottleListener.notifyThrottleFound method.
     */
public void notifyThrottleKnown(DccThrottle throttle, LocoAddress addr, boolean suppressUseIncrements) {
    log.debug("notifyThrottleKnown for " + addr);
    DccLocoAddress dla = (DccLocoAddress) addr;
    Addresses ads = null;
    if (!addressThrottles.containsKey(dla)) {
        log.debug("Address " + addr + "doesn't already exists so will add");
        ads = new Addresses(throttle);
        addressThrottles.put(dla, ads);
    } else {
        addressThrottles.get(dla).setThrottle(throttle);
    }
    ArrayList<WaitingThrottle> a = throttleListeners.get(dla);
    if (a == null) {
        log.debug("notifyThrottleKnown with zero-length listeners: " + addr);
    } else {
        for (int i = 0; i < a.size(); i++) {
            ThrottleListener l = a.get(i).getListener();
            log.debug("Notify listener " + (i + 1) + " of " + a.size());
            l.notifyThrottleFound(throttle);
            if (suppressUseIncrements == false) {
                // this is a new throttle
                addressThrottles.get(dla).incrementUse();
            } else {
                // requestThrottle() found an existing throttle, we're re-using that one
                log.debug("incrementUse suppressed");
            }
            addressThrottles.get(dla).addListener(l);
            if (ads != null && a.get(i).getRosterEntry() != null && throttle.getRosterEntry() == null) {
                throttle.setRosterEntry(a.get(i).getRosterEntry());
            }
        }
        throttleListeners.remove(dla);
    }
    ArrayList<WaitingThrottle> p = listenerOnly.get(dla);
    if (p == null) {
        log.debug("notifyThrottleKnown with zero-length propertyChangeListeners: " + addr);
    } else {
        for (int i = 0; i < p.size(); i++) {
            PropertyChangeListener l = p.get(i).getPropertyChangeListener();
            log.debug("Notify propertyChangeListener");
            l.propertyChange(new PropertyChangeEvent(this, "throttleAssigned", null, dla));
            if (ads != null && p.get(i).getRosterEntry() != null && throttle.getRosterEntry() == null) {
                throttle.setRosterEntry(p.get(i).getRosterEntry());
            }
            throttle.addPropertyChangeListener(l);
        }
        listenerOnly.remove(dla);
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ThrottleListener(jmri.ThrottleListener) DccLocoAddress(jmri.DccLocoAddress)

Example 13 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class AbstractThrottleManager method disposeThrottle.

@Override
public boolean disposeThrottle(DccThrottle t, ThrottleListener l) {
    //        if (!active) log.error("Dispose called when not active");  <-- might need to control this in the sub class
    DccLocoAddress la = (DccLocoAddress) t.getLocoAddress();
    if (addressReleased(la, l)) {
        log.debug("Address " + t.getLocoAddress() + " still has active users");
        return false;
    }
    if (t.getListeners().size() > 0) {
        log.debug("Throttle " + t.getLocoAddress() + " still has active propertyChangeListeners registered to the throttle");
        return false;
    }
    if (addressThrottles.containsKey(la)) {
        addressThrottles.remove(la);
        log.debug("Loco Address removed from the stack " + la);
    } else {
        log.debug("Loco Address not found in the stack " + la);
    }
    return true;
}
Also used : DccLocoAddress(jmri.DccLocoAddress)

Example 14 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class EasyDccThrottleManager method disposeThrottle.

@Override
public boolean disposeThrottle(jmri.DccThrottle t, jmri.ThrottleListener l) {
    if (super.disposeThrottle(t, l)) {
        int value = 0;
        DccLocoAddress address = (DccLocoAddress) t.getLocoAddress();
        byte[] result = jmri.NmraPacket.speedStep128Packet(address.getNumber(), address.isLongAddress(), value, t.getIsForward());
        // KSL 20040409 - this is messy, as I only wanted
        // the address to be sent.
        EasyDccMessage m = new EasyDccMessage(7);
        // for EasyDCC, release the loco.
        // D = Dequeue
        // Cx xx (address)
        // message index counter
        int i = 0;
        m.setElement(i++, 'D');
        if (address.isLongAddress()) {
            m.setElement(i++, ' ');
            m.addIntAsTwoHex(result[0] & 0xFF, i);
            i = i + 2;
            m.setElement(i++, ' ');
            m.addIntAsTwoHex(result[1] & 0xFF, i);
            i = i + 2;
        } else {
            // short address
            m.setElement(i++, ' ');
            m.addIntAsTwoHex(0, i);
            i = i + 2;
            m.setElement(i++, ' ');
            m.addIntAsTwoHex(result[0] & 0xFF, i);
            i = i + 2;
        }
        EasyDccTrafficController.instance().sendEasyDccMessage(m, null);
        EasyDccThrottle lnt = (EasyDccThrottle) t;
        lnt.throttleDispose();
        return true;
    }
    return false;
}
Also used : DccLocoAddress(jmri.DccLocoAddress)

Example 15 with DccLocoAddress

use of jmri.DccLocoAddress in project JMRI by JMRI.

the class LnReporter method getLocoAddress.

// Parses out a (possibly old) LnReporter-generated report string to extract the address from the front.
// Assumes the LocoReporter format is "NNNN [enter|exit]"
@Override
public LocoAddress getLocoAddress(String rep) {
    // Extract the number from the head of the report string
    log.debug("report string: " + rep);
    Matcher m = this.parseReport(rep);
    if ((m != null) && m.find()) {
        log.debug("Parsed address: " + m.group(1));
        return (new DccLocoAddress(Integer.parseInt(m.group(1)), LocoAddress.Protocol.DCC));
    } else {
        return (null);
    }
}
Also used : Matcher(java.util.regex.Matcher) 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