Search in sources :

Example 1 with CommandStation

use of jmri.CommandStation in project JMRI by JMRI.

the class DccSignalHeadTest method setUp.

// from here down is testing infrastructure
// The minimal setup for log4J
@Before
public void setUp() throws Exception {
    apps.tests.Log4JFixture.setUp();
    JUnitUtil.resetInstanceManager();
    JUnitUtil.initInternalTurnoutManager();
    CommandStation c = new CommandStation() {

        @Override
        public void sendPacket(byte[] packet, int repeats) {
            lastSentPacket = packet;
            sentPacketCount++;
        }

        @Override
        public String getUserName() {
            return null;
        }

        @Override
        public String getSystemPrefix() {
            return "I";
        }
    };
    InstanceManager.store(c, CommandStation.class);
    lastSentPacket = null;
    sentPacketCount = 0;
}
Also used : CommandStation(jmri.CommandStation) Before(org.junit.Before)

Example 2 with CommandStation

use of jmri.CommandStation in project JMRI by JMRI.

the class SendPacketFrame method initComponents.

@Override
public void initComponents() throws Exception {
    setTitle("Send DCC Packet");
    getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
    // handle single-packet part
    getContentPane().add(new JLabel("Send one packet:"));
    {
        JPanel pane1 = new JPanel();
        pane1.setLayout(new BoxLayout(pane1, BoxLayout.Y_AXIS));
        jLabel1.setText("Packet:");
        jLabel1.setVisible(true);
        sendButton.setText("Send");
        sendButton.setVisible(true);
        sendButton.setToolTipText("Send packet");
        packetTextField.setToolTipText("Enter packet as hex pairs, e.g. 82 7D");
        pane1.add(jLabel1);
        pane1.add(packetTextField);
        pane1.add(sendButton);
        pane1.add(Box.createVerticalGlue());
        sendButton.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent e) {
                sendButtonActionPerformed(e);
            }
        });
        getContentPane().add(pane1);
    }
    getContentPane().add(new JSeparator());
    // Configure the sequence
    getContentPane().add(new JLabel("Send sequence of packets:"));
    JPanel pane2 = new JPanel();
    pane2.setLayout(new GridLayout(MAXSEQUENCE + 2, 4));
    pane2.add(new JLabel(""));
    pane2.add(new JLabel("Send"));
    pane2.add(new JLabel("packet"));
    pane2.add(new JLabel("wait (msec)"));
    for (int i = 0; i < MAXSEQUENCE; i++) {
        pane2.add(new JLabel(Integer.toString(i + 1)));
        mUseField[i] = new JCheckBox();
        mPacketField[i] = new JTextField(10);
        mDelayField[i] = new JTextField(10);
        pane2.add(mUseField[i]);
        pane2.add(mPacketField[i]);
        pane2.add(mDelayField[i]);
    }
    // starts a new row in layout
    pane2.add(mRunButton);
    getContentPane().add(pane2);
    mRunButton.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {
            runButtonActionPerformed(e);
        }
    });
    // get the CommandStation reference
    cs = InstanceManager.getNullableDefault(CommandStation.class);
    if (cs == null) {
        log.error("No CommandStation object available");
    }
    // add help menu
    addHelpMenu("package.jmri.jmrit.sendpacket.SendPacketFrame", true);
    // pack to cause display
    pack();
}
Also used : JPanel(javax.swing.JPanel) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) JSeparator(javax.swing.JSeparator) JCheckBox(javax.swing.JCheckBox) GridLayout(java.awt.GridLayout) CommandStation(jmri.CommandStation)

Example 3 with CommandStation

use of jmri.CommandStation in project JMRI by JMRI.

the class AbstractThrottle method sendFunctionGroup5.

/**
     * Send the message to set the state of functions F21, F22, F23, F24, F25,
     * F26, F27, F28
     * <P>
     * This is used in the setFn implementations provided in this class, but a
     * real implementation needs to be provided.
     */
protected void sendFunctionGroup5() {
    DccLocoAddress a = (DccLocoAddress) getLocoAddress();
    byte[] result = jmri.NmraPacket.function21Through28Packet(a.getNumber(), a.isLongAddress(), getF21(), getF22(), getF23(), getF24(), getF25(), getF26(), getF27(), getF28());
    //if the result returns as null, we should quit.
    if (result == null) {
        return;
    }
    CommandStation c;
    if ((adapterMemo != null) && (adapterMemo.get(jmri.CommandStation.class) != null)) {
        c = adapterMemo.get(jmri.CommandStation.class);
    } else {
        c = InstanceManager.getNullableDefault(CommandStation.class);
    }
    // send it 3 times
    if (c != null) {
        c.sendPacket(result, 3);
    } else {
        log.error("Can't send F21-F28 since no command station defined");
    }
}
Also used : CommandStation(jmri.CommandStation) DccLocoAddress(jmri.DccLocoAddress)

Example 4 with CommandStation

use of jmri.CommandStation in project JMRI by JMRI.

the class AbstractThrottle method sendFunctionGroup4.

/**
     * Send the message to set the state of functions F13, F14, F15, F16, F17,
     * F18, F19, F20
     * <P>
     * This is used in the setFn implementations provided in this class, but a
     * real implementation needs to be provided.
     */
protected void sendFunctionGroup4() {
    DccLocoAddress a = (DccLocoAddress) getLocoAddress();
    byte[] result = jmri.NmraPacket.function13Through20Packet(a.getNumber(), a.isLongAddress(), getF13(), getF14(), getF15(), getF16(), getF17(), getF18(), getF19(), getF20());
    //if the result returns as null, we should quit.
    if (result == null) {
        return;
    }
    CommandStation c;
    if ((adapterMemo != null) && (adapterMemo.get(jmri.CommandStation.class) != null)) {
        c = adapterMemo.get(jmri.CommandStation.class);
    } else {
        c = InstanceManager.getNullableDefault(CommandStation.class);
    }
    // send it 3 times
    if (c != null) {
        c.sendPacket(result, 3);
    } else {
        log.error("Can't send F13-F20 since no command station defined");
    }
}
Also used : CommandStation(jmri.CommandStation) DccLocoAddress(jmri.DccLocoAddress)

Example 5 with CommandStation

use of jmri.CommandStation in project JMRI by JMRI.

the class DccSignalMastTest method setUp.

// from here down is testing infrastructure
// The minimal setup for log4J
@Before
public void setUp() throws Exception {
    apps.tests.Log4JFixture.setUp();
    JUnitUtil.resetInstanceManager();
    JUnitUtil.initInternalTurnoutManager();
    CommandStation c = new CommandStation() {

        @Override
        public void sendPacket(byte[] packet, int repeats) {
            lastSentPacket = packet;
            sentPacketCount++;
        }

        @Override
        public String getUserName() {
            return null;
        }

        @Override
        public String getSystemPrefix() {
            return "I";
        }
    };
    InstanceManager.store(c, CommandStation.class);
    lastSentPacket = null;
    sentPacketCount = 0;
}
Also used : CommandStation(jmri.CommandStation) Before(org.junit.Before)

Aggregations

CommandStation (jmri.CommandStation)5 DccLocoAddress (jmri.DccLocoAddress)2 Before (org.junit.Before)2 GridLayout (java.awt.GridLayout)1 BoxLayout (javax.swing.BoxLayout)1 JCheckBox (javax.swing.JCheckBox)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JSeparator (javax.swing.JSeparator)1 JTextField (javax.swing.JTextField)1