use of jmri.Turnout in project JMRI by JMRI.
the class SerialTurnoutManager method getNextValidAddress.
/**
* A method that returns the next valid free turnout hardware address
*/
@Override
public String getNextValidAddress(String curAddress, String prefix) throws JmriException {
String tmpSName = "";
try {
tmpSName = createSystemName(curAddress, prefix);
} catch (JmriException ex) {
throw ex;
}
//If the hardware address past does not already exist then this can
//be considered the next valid address.
Turnout t = getBySystemName(tmpSName);
if (t == null) {
return Integer.toString(nNode) + Integer.toString((nCard + bitNum));
//return ""+nNode+(nCard+bitNum);
}
//The Number of Output Bits of the previous turnout will help determine the next
//valid address.
bitNum = bitNum + t.getNumberOutputBits();
//Check to determine if the systemName is in use, return null if it is,
//otherwise return the next valid address.
tmpSName = prefix + "T" + nNode + (nCard + bitNum);
t = getBySystemName(tmpSName);
if (t != null) {
for (int x = 1; x < 10; x++) {
bitNum = bitNum + t.getNumberOutputBits();
tmpSName = prefix + "T" + nNode + (nCard + bitNum);
t = getBySystemName(tmpSName);
if (t == null) {
return Integer.toString(nNode) + Integer.toString((nCard + bitNum));
}
//return ""+nNode+(nCard+bitNum);
}
return null;
} else {
return Integer.toString(nNode) + Integer.toString((nCard + bitNum));
}
}
use of jmri.Turnout in project JMRI by JMRI.
the class JMRIClientTurnoutManager method createNewTurnout.
@Override
public Turnout createNewTurnout(String systemName, String userName) {
Turnout t;
int addr = Integer.valueOf(systemName.substring(prefix.length() + 1)).intValue();
t = new JMRIClientTurnout(addr, memo);
t.setUserName(userName);
return t;
}
use of jmri.Turnout in project JMRI by JMRI.
the class Llnmon method interpretOpcSwRep.
private String interpretOpcSwRep(LocoNetMessage l) {
int sn1 = l.getElement(1);
int sn2 = l.getElement(2);
// get system and user names
String turnoutSystemName;
String turnoutUserName = "";
turnoutSystemName = locoNetTurnoutPrefix + SENSOR_ADR(sn1, sn2);
Turnout turnout = turnoutManager.provideTurnout(turnoutSystemName);
String uname = turnout.getUserName();
if ((uname != null) && (!uname.isEmpty())) {
turnoutUserName = uname;
} else {
turnoutUserName = "";
}
if ((sn2 & LnConstants.OPC_SW_REP_INPUTS) != 0) {
return Bundle.getMessage("LN_MSG_OPC_SW_REP_INPUTS_STATE", turnoutSystemName, turnoutUserName, Bundle.getMessage(((sn2 & LnConstants.OPC_SW_REP_SW) != 0 ? "LN_MSG_SENSOR_SW_INPUT_TYPE_HI" : "LN_MSG_SENSOR_SW_INPUT_TYPE_LO")), Bundle.getMessage((((sn2 & LnConstants.OPC_SW_REP_HI) != 0) ? "LN_MSG_SENSOR_SW_INPUT_STATE_HI" : "LN_MSG_SENSOR_SW_INPUT_STATE_LO")));
}
return Bundle.getMessage("LN_MSG_OPC_SW_REP_OUTPUT_STATE", turnoutSystemName, turnoutUserName, Bundle.getMessage((((sn2 & LnConstants.OPC_SW_REP_CLOSED) != 0) ? "LN_MSG_SENSOR_SW_OUTPUT_STATE_ON" : "LN_MSG_SENSOR_SW_OUTPUT_STATE_OFF")), Bundle.getMessage((((sn2 & LnConstants.OPC_SW_REP_THROWN) != 0) ? "LN_MSG_SENSOR_SW_OUTPUT_STATE_ON" : "LN_MSG_SENSOR_SW_OUTPUT_STATE_OFF")));
}
use of jmri.Turnout in project JMRI by JMRI.
the class NceTurnoutMonitor method pollMessage.
public NceMessage pollMessage() {
if (tc.getCommandOptions() < NceTrafficController.OPTION_2006) {
//Only 2007 CS EPROMs support polling
return null;
}
if (tc.getUsbSystem() != NceTrafficController.USB_SYSTEM_NONE) {
//Can't poll USB!
return null;
}
if (NceTurnout.getNumNtTurnouts() == 0) {
//No work!
return null;
}
long currentTime = java.util.Calendar.getInstance().getTimeInMillis();
if (currentTime - lastPollTime < 2 * POLL_TIME) {
return null;
} else {
lastPollTime = currentTime;
}
// also see if the number of turnouts now differs from the last scan
if (FeedbackChange || numTurnouts != NceTurnout.getNumNtTurnouts()) {
FeedbackChange = false;
numTurnouts = NceTurnout.getNumNtTurnouts();
// Determine what turnouts have been defined and what blocks have active turnouts
for (int block = 0; block < NUM_BLOCK; block++) {
// Block may be active, but new turnouts may have been loaded
newTurnouts[block] = true;
if (activeBlock[block] == false) {
for (int i = 0; i < 128; i++) {
// Check 128 turnouts per block
int NTnum = 1 + i + (block * 128);
Turnout mControlTurnout = tc.getAdapterMemo().getTurnoutManager().getBySystemName(tc.getAdapterMemo().getSystemPrefix() + "T" + NTnum);
if (mControlTurnout != null) {
// remove listener in case we're already listening
mControlTurnout.removePropertyChangeListener(this);
if (mControlTurnout.getFeedbackMode() == Turnout.MONITORING) {
// turnout found, block is active forever
activeBlock[block] = true;
numActiveBlocks++;
// don't check rest of block
break;
} else {
// turnout feedback isn't monitoring, but listen in case it changes
mControlTurnout.addPropertyChangeListener(this);
if (debugTurnoutMonitor) {
if (log.isDebugEnabled()) {
log.debug("add turnout to listener NT" + NTnum + " Feed back mode: " + mControlTurnout.getFeedbackMode());
}
}
}
}
}
}
}
}
// See if there's any poll messages needed
if (numActiveBlocks <= 0) {
// to avoid immediate infinite loop
return null;
}
// This protects pollMessage (xmt) and reply threads if there's lockup!
if (NceTurnoutMonitorThread == null) {
NceTurnoutMonitorThread = new Thread(new Runnable() {
@Override
public void run() {
turnoutUpdate();
}
});
NceTurnoutMonitorThread.setName("NCE Turnout Monitor");
NceTurnoutMonitorThread.setPriority(Thread.MIN_PRIORITY);
NceTurnoutMonitorThread.start();
}
// now try to build a poll message if there are any defined turnouts to scan
while (true) {
// will break out when next block to poll is found
currentBlock++;
if (currentBlock >= NUM_BLOCK) {
currentBlock = 0;
}
if (activeBlock[currentBlock]) {
if (debugTurnoutMonitor) {
if (log.isDebugEnabled()) {
log.debug("found turnouts block " + currentBlock);
}
}
// Read NCE CS memory
int nceAccAddress = CS_ACCY_MEMORY + currentBlock * BLOCK_LEN;
byte[] bl = NceBinaryCommand.accMemoryRead(nceAccAddress);
NceMessage m = NceMessage.createBinaryMessage(tc, bl, REPLY_LEN);
return m;
}
}
}
use of jmri.Turnout in project JMRI by JMRI.
the class TurnoutSignalMast method setAspect.
@Override
public void setAspect(String aspect) {
// check it's a choice
if (!map.checkAspect(aspect)) {
// not a valid aspect
log.warn("attempting to set invalid aspect: " + aspect + " on mast: " + getDisplayName());
throw new IllegalArgumentException("attempting to set invalid aspect: " + aspect + " on mast: " + getDisplayName());
} else if (disabledAspects.contains(aspect)) {
log.warn("attempting to set an aspect that has been disabled: " + aspect + " on mast: " + getDisplayName());
throw new IllegalArgumentException("attempting to set an aspect that has been disabled: " + aspect + " on mast: " + getDisplayName());
}
if (getLit()) {
//If the signalmast is lit, then send the commands to change the aspect.
if (resetPreviousStates) {
//Clear all the current states, this will result in the signalmast going blank for a very short time.
for (String appearances : turnouts.keySet()) {
if (!isAspectDisabled(appearances)) {
int setState = Turnout.CLOSED;
if (turnouts.get(appearances).getTurnoutState() == Turnout.CLOSED) {
setState = Turnout.THROWN;
}
if (turnouts.get(appearances).getTurnout().getKnownState() != setState) {
turnouts.get(appearances).getTurnout().setCommandedState(setState);
}
}
}
}
Turnout turnToSet = turnouts.get(aspect).getTurnout();
int stateToSet = turnouts.get(aspect).getTurnoutState();
//Set the new signal mast state
if (turnToSet != null) {
turnToSet.setCommandedState(stateToSet);
} else {
log.error("Trying to set a state " + aspect + " on signal mast " + getDisplayName() + " which has not been configured");
}
} else if (log.isDebugEnabled()) {
log.debug("Mast set to unlit, will not send aspect change to hardware");
}
super.setAspect(aspect);
}
Aggregations