Search in sources :

Example 51 with Turnout

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));
    }
}
Also used : JmriException(jmri.JmriException) Turnout(jmri.Turnout)

Example 52 with Turnout

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;
}
Also used : Turnout(jmri.Turnout)

Example 53 with Turnout

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")));
}
Also used : Turnout(jmri.Turnout)

Example 54 with Turnout

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;
        }
    }
}
Also used : Turnout(jmri.Turnout)

Example 55 with Turnout

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);
}
Also used : Turnout(jmri.Turnout)

Aggregations

Turnout (jmri.Turnout)221 Test (org.junit.Test)63 Sensor (jmri.Sensor)26 SignalHead (jmri.SignalHead)20 Element (org.jdom2.Element)20 TurnoutManager (jmri.TurnoutManager)17 JmriException (jmri.JmriException)11 Light (jmri.Light)10 SignalMast (jmri.SignalMast)10 ActionEvent (java.awt.event.ActionEvent)9 NamedBeanHandle (jmri.NamedBeanHandle)9 JsonException (jmri.server.json.JsonException)9 ActionListener (java.awt.event.ActionListener)8 Block (jmri.Block)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 NamedBean (jmri.NamedBean)6 Route (jmri.Route)6 AbstractTurnout (jmri.implementation.AbstractTurnout)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5