use of jmri.DccLocoAddress in project JMRI by JMRI.
the class LocoNetConsistManager method requestUpdateFromLayout.
/* request an update from the layout, loading
* Consists from the command station.
*
* On a LocoNet command station, the consists are stored in the
* slots in an array based tree. Each node in a consist contains
* a pointer to the "top" slot in the consist. A top slot is
* allowed to be a member of another consist. When this occurs,
* it is labeled as a "mid" locomotive.
*
* This function updates the list of consists by scanning the
* slots and adding new "top" slot addresses and removing address
* that are no longer "top" locomotives.
*/
@Override
public void requestUpdateFromLayout() {
if (!shouldRequestUpdateFromLayout()) {
return;
}
requestingUpdate = true;
SlotManager sm = memo.getSlotManager();
// command station slots.
for (int i = 0; i < 128; i++) {
LocoNetSlot s = sm.slot(i);
DccLocoAddress address = new DccLocoAddress(s.locoAddr(), LnThrottleManager.isLongAddress(s.locoAddr()));
if (log.isDebugEnabled()) {
log.debug(" Slot " + i + " Address " + address + " consist status " + LnConstants.CONSIST_STAT(s.consistStatus()));
}
if (s.consistStatus() == LnConstants.CONSIST_TOP || s.consistStatus() == LnConstants.CONSIST_MID) {
// already.
if (!consistTable.containsKey(address)) {
if (log.isDebugEnabled()) {
log.debug("Adding Consist with Address " + address + " due to command station read");
}
addConsist(address);
// add the address to the consist.
getConsist(address).add(address, true);
}
}
}
// make a second pass, this time looking for locomotives in a consist.
for (int i = 0; i < 128; i++) {
LocoNetSlot s = sm.slot(i);
DccLocoAddress address = new DccLocoAddress(s.locoAddr(), LnThrottleManager.isLongAddress(s.locoAddr()));
if (log.isDebugEnabled()) {
log.debug(" Slot " + i + " Address " + address + " consist status " + LnConstants.CONSIST_STAT(s.consistStatus()));
}
if (s.consistStatus() == LnConstants.CONSIST_SUB || s.consistStatus() == LnConstants.CONSIST_MID) {
// this is a consist member, add it to the consist in the
// slot which it has a pointer to (the slot pointer is stored in
// the slot's speed).
DccLocoAddress lead = new DccLocoAddress(sm.slot(s.speed()).locoAddr(), LnThrottleManager.isLongAddress(sm.slot(s.speed()).locoAddr()));
getConsist(lead).add(address, s.isForward() == sm.slot(s.speed()).isForward());
}
}
requestingUpdate = false;
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class LnPr2PowerManager method setPower.
@Override
public void setPower(int v) throws JmriException {
power = UNKNOWN;
// Instead of GPON/GPOFF, PR2 uses ops-mode writes to CV 128 for control
if (v == ON) {
// get current active address
DccLocoAddress activeAddress = ((LnPr2ThrottleManager) InstanceManager.throttleManagerInstance()).getActiveAddress();
if (activeAddress != null) {
pm = new LnOpsModeProgrammer(sm, memo, activeAddress.getNumber(), activeAddress.isLongAddress());
checkOpsProg();
// set bit 1 in CV 128
pm.writeCV(128, 1, null);
power = ON;
// NOI18N
firePropertyChange("Power", null, null);
// start making sure that the power is refreshed
if (timer == null) {
timer = new javax.swing.Timer(2 * 1000, new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
refresh();
}
});
timer.setInitialDelay(2 * 1000);
// in case we run by
timer.setRepeats(true);
}
timer.start();
}
} else if (v == OFF) {
if (timer != null) {
timer.stop();
}
// get current active address
DccLocoAddress activeAddress = ((LnPr2ThrottleManager) InstanceManager.throttleManagerInstance()).getActiveAddress();
if (activeAddress != null) {
pm = new LnOpsModeProgrammer(sm, memo, activeAddress.getNumber(), activeAddress.isLongAddress());
checkOpsProg();
// reset bit 1 in CV 128
pm.writeCV(128, 0, null);
power = OFF;
}
}
// notify of change
// NOI18N
firePropertyChange("Power", null, null);
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class SprogCommandStation method findAddressSpeedPacket.
private SprogSlot findAddressSpeedPacket(DccLocoAddress address) {
// SPROG doesn't use IDLE packets but sends speed commands to last address selected by "A" command.
// We may need to move these pseudo-idle packets to an unused long address so locos will not receive conflicting speed commands.
// Some short-address-only decoders may also respond to same-numbered long address so we avoid any number match irrespective of type
// We need to find a suitable free long address, save (currentSprogAddress) and use it for pseudo-idle packets
int lastSprogAddress = currentSprogAddress;
while (// initialisation || avoid address 0 for reason above
(currentSprogAddress <= 0) || // avoid this address (slot may not exist but we will be creating one)
((address.getNumber() == currentSprogAddress)) || (findAddress(new DccLocoAddress(currentSprogAddress, true)) != null) || // avoid in-use (both long or short versions of) address
(findAddress(new DccLocoAddress(currentSprogAddress, false)) != null)) {
currentSprogAddress++;
currentSprogAddress = currentSprogAddress % 10240;
}
if (currentSprogAddress != lastSprogAddress) {
log.info("Changing currentSprogAddress (for pseudo-idle packets) to " + currentSprogAddress + "(L)");
// lastSprogAddress = currentSprogAddress;
}
tc.sendSprogMessage(new SprogMessage("A " + currentSprogAddress + " 0"));
for (SprogSlot s : slots) {
if (s.isActiveAddressMatch(address) && s.isSpeedPacket()) {
return s;
}
}
if (getInUseCount() < SprogConstants.MAX_SLOTS) {
return findFree();
}
return (null);
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class SprogCSThrottleManager method requestThrottleSetup.
@Override
public void requestThrottleSetup(LocoAddress a, boolean control) {
// The SPROG protocol doesn't require an interaction with the command
// station for this, so immediately trigger the callback
DccLocoAddress address = (DccLocoAddress) a;
log.debug("new SprogThrottle for " + address);
notifyThrottleKnown(new SprogCSThrottle((SprogSystemConnectionMemo) adapterMemo, address), address);
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class SRCPThrottleManager method disposeThrottle.
@Override
public boolean disposeThrottle(jmri.DccThrottle t, jmri.ThrottleListener l) {
if (super.disposeThrottle(t, l)) {
// Form a message to release the loco
DccLocoAddress la = (DccLocoAddress) t.getLocoAddress();
String msg = "TERM " + bus + " GL " + (la.getNumber()) + "\n";
// and send it
((SRCPBusConnectionMemo) adapterMemo).getTrafficController().sendSRCPMessage(new SRCPMessage(msg), null);
return true;
}
return false;
//LocoNetSlot tSlot = lnt.getLocoNetSlot();
}
Aggregations