use of jmri.DccThrottle in project JMRI by JMRI.
the class Calibrater method makeExitPanel.
private JPanel makeExitPanel(boolean init) {
float spFactor = 0.0f;
float spSpeed = 0.0f;
DccThrottle throttle = _warrant.getThrottle();
float scale = jmri.InstanceManager.getDefault(SignalSpeedMap.class).getLayoutScale();
// prototype m/s
float scaleSpeed = _rawSpeed * scale;
if (!init) {
float speedSetting = throttle.getSpeedSetting();
int speedStep = 0;
switch(throttle.getSpeedStepMode()) {
case DccThrottle.SpeedStepMode14:
speedStep = java.lang.Math.round(speedSetting * 14);
break;
case DccThrottle.SpeedStepMode27:
speedStep = java.lang.Math.round(speedSetting * 27);
break;
case DccThrottle.SpeedStepMode28:
speedStep = java.lang.Math.round(speedSetting * 28);
break;
case DccThrottle.SpeedStepMode128:
default:
// 128 speed step mode is the default in the JMRI
// throttle code.
speedStep = java.lang.Math.round(speedSetting * 126);
break;
}
// actual speedSetting
speedSetting = throttle.getSpeedIncrement() * speedStep;
_factor = _rawSpeed / speedSetting;
// _factor = speedSetting*25.4f/(_rawSpeed*100);
_isForward = throttle.getIsForward();
if (_speedProfile != null) {
if (_isForward) {
spSpeed = _speedProfile.getForwardSpeed(speedSetting);
} else {
spSpeed = _speedProfile.getReverseSpeed(speedSetting);
}
spFactor = spSpeed / (speedSetting * 1000);
}
if (log.isDebugEnabled())
log.debug("Throttle speedSetting= " + speedSetting + ", Set from _maxSpeed= " + _maxSpeed + ", expected profile speed =" + spSpeed + ", actual _rawSpeed= " + (_rawSpeed * 1000) + "mm/sec, scale= " + scale);
// now is the actual setting
_maxSpeed = speedSetting;
}
String speedUnits;
if (jmri.InstanceManager.getDefault(SignalSpeedMap.class).getInterpretation() == SignalSpeedMap.SPEED_KMPH) {
speedUnits = "kmph";
scaleSpeed = 3.6f * scaleSpeed;
spSpeed = spSpeed * scale * 3.6f / 1000;
} else {
speedUnits = "mph";
scaleSpeed = scaleSpeed * 3.6f * 0.621371f;
spSpeed = spSpeed * scale * 3.6f * 0.621371f / 1000;
}
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout(10, 10));
JPanel p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));
p.add(new JLabel(Bundle.getMessage("trainInfo3", _maxSpeed, scaleSpeed, speedUnits)));
p.add(new JLabel(Bundle.getMessage("trainInfo4", _factor)));
if (_speedProfile != null) {
p.add(new JLabel(Bundle.getMessage("trainInfo5", spSpeed, speedUnits, spFactor)));
} else {
p.add(new JLabel(Bundle.getMessage("trainInfo6", _warrant.getTrainId())));
}
panel.add(p, BorderLayout.CENTER);
panel.add(Box.createRigidArea(new java.awt.Dimension(10, 100)), BorderLayout.WEST);
p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));
p.add(_addBox);
p.add(_ignoreBox);
p.add(_clearBox);
JPanel pp = new JPanel();
pp.setLayout(new BoxLayout(pp, BoxLayout.LINE_AXIS));
pp.add(Box.createRigidArea(new java.awt.Dimension(10, 100)));
pp.add(p);
panel.add(pp, BorderLayout.SOUTH);
return panel;
}
use of jmri.DccThrottle in project JMRI by JMRI.
the class AbstractAutomaton method getThrottle.
/**
* Obtains a DCC throttle, including waiting for the command station
* response.
*
* @param address Numeric address value
* @param longAddress true if this is a long address, false for a short
* address
* @param waitSecs number of seconds to wait for throttle to acquire
* before returning null
* @return A usable throttle, or null if error
*/
public DccThrottle getThrottle(int address, boolean longAddress, int waitSecs) {
log.debug("requesting DccThrottle for addr " + address);
if (!inThread) {
log.warn("getThrottle invoked from invalid context");
}
throttle = null;
ThrottleListener throttleListener = new ThrottleListener() {
@Override
public void notifyThrottleFound(DccThrottle t) {
throttle = t;
synchronized (self) {
// should be only one thread waiting, but just in case
self.notifyAll();
}
}
@Override
public void notifyFailedThrottleRequest(jmri.DccLocoAddress address, String reason) {
log.error("Throttle request failed for " + address + " because " + reason);
failedThrottleRequest = true;
synchronized (self) {
// should be only one thread waiting, but just in case
self.notifyAll();
}
}
};
boolean ok = InstanceManager.getDefault(ThrottleManager.class).requestThrottle(address, longAddress, throttleListener);
// check if reply is coming
if (!ok) {
log.info("Throttle for loco " + address + " not available");
//kill the pending request
InstanceManager.getDefault(ThrottleManager.class).cancelThrottleRequest(address, throttleListener);
return null;
}
// now wait for reply from identified throttle
int waited = 0;
while (throttle == null && failedThrottleRequest == false && waited <= waitSecs) {
log.debug("waiting for throttle");
// 1 seconds
wait(1000);
waited++;
if (throttle == null) {
log.warn("Still waiting for throttle " + address + "!");
}
}
if (throttle == null) {
log.debug("canceling request for Throttle " + address);
//kill the pending request
InstanceManager.getDefault(ThrottleManager.class).cancelThrottleRequest(address, throttleListener);
}
return throttle;
}
use of jmri.DccThrottle in project JMRI by JMRI.
the class RpsBlock method updateCurrentThrottles.
void updateCurrentThrottles() {
List<Integer> l = sensor.getContents();
if (l.size() == 0) {
return;
}
if (l.size() > 1) {
log.warn("More than one address present!");
}
for (int i = 0; i < l.size(); i++) {
Integer num = l.get(i);
DccThrottle t = throttleTable.get(num);
if (t != null) {
updateOneThrottle(t);
} else {
log.warn("Throttle not yet available for: " + num);
}
}
}
use of jmri.DccThrottle in project JMRI by JMRI.
the class AbstractAutomaton method getThrottle.
/**
* Obtains a DCC throttle, including waiting for the command station
* response.
*
* @param re specifies the desired locomotive
* @param waitSecs number of seconds to wait for throttle to acquire before
* returning null
* @return A usable throttle, or null if error
*/
public DccThrottle getThrottle(BasicRosterEntry re, int waitSecs) {
log.debug("requesting DccThrottle for rosterEntry " + re.getId());
if (!inThread) {
log.warn("getThrottle invoked from invalid context");
}
throttle = null;
ThrottleListener throttleListener = new ThrottleListener() {
@Override
public void notifyThrottleFound(DccThrottle t) {
throttle = t;
synchronized (self) {
// should be only one thread waiting, but just in case
self.notifyAll();
}
}
@Override
public void notifyFailedThrottleRequest(jmri.DccLocoAddress address, String reason) {
log.error("Throttle request failed for " + address + " because " + reason);
failedThrottleRequest = true;
synchronized (self) {
// should be only one thread waiting, but just in case
self.notifyAll();
}
}
};
boolean ok = InstanceManager.throttleManagerInstance().requestThrottle(re, throttleListener);
// check if reply is coming
if (!ok) {
log.info("Throttle for loco " + re.getId() + " not available");
//kill the pending request
InstanceManager.getDefault(ThrottleManager.class).cancelThrottleRequest(re, throttleListener);
return null;
}
// now wait for reply from identified throttle
int waited = 0;
while (throttle == null && failedThrottleRequest == false && waited <= waitSecs) {
log.debug("waiting for throttle");
// 1 seconds
wait(1000);
waited++;
if (throttle == null) {
log.warn("Still waiting for throttle " + re.getId() + "!");
}
}
if (throttle == null) {
log.debug("canceling request for Throttle " + re.getId());
//kill the pending request
InstanceManager.getDefault(ThrottleManager.class).cancelThrottleRequest(re, throttleListener);
}
return throttle;
}
use of jmri.DccThrottle in project JMRI by JMRI.
the class UhlenbrockLnThrottleManager method notifyChangedSlot.
/**
* SlotListener contract. Get notification that an address has changed slot.
* This method creates a throttle for all ThrottleListeners of that address
* and notifies them via the ThrottleListener.notifyThrottleFound method.
*/
@Override
public void notifyChangedSlot(LocoNetSlot s) {
DccThrottle throttle = new LocoNetThrottle((LocoNetSystemConnectionMemo) adapterMemo, s);
notifyThrottleKnown(throttle, new DccLocoAddress(s.locoAddr(), isLongAddress(s.locoAddr())));
if (waitingForNotification.containsKey(s.locoAddr())) {
Thread r = waitingForNotification.get(s.locoAddr());
synchronized (r) {
r.interrupt();
}
waitingForNotification.remove(s.locoAddr());
}
}
Aggregations