Search in sources :

Example 71 with LocoNetMessage

use of jmri.jmrix.loconet.LocoNetMessage in project JMRI by JMRI.

the class LocoIO method programLocoIOAddress.

public static void programLocoIOAddress(int address, int subAddress, LnTrafficController ln) {
    LocoNetMessage msg;
    msg = LocoIO.writeCV(0x0100, 0, 1, address & 0xFF);
    ln.sendLocoNetMessage(msg);
    if (subAddress != 0) {
        msg = LocoIO.writeCV(0x0100, 0, 2, subAddress);
        ln.sendLocoNetMessage(msg);
    }
}
Also used : LocoNetMessage(jmri.jmrix.loconet.LocoNetMessage)

Example 72 with LocoNetMessage

use of jmri.jmrix.loconet.LocoNetMessage in project JMRI by JMRI.

the class LnPr2PowerManager method refresh.

void refresh() {
    // send inquiry message to keep power alive
    LocoNetMessage msg = new LocoNetMessage(2);
    msg.setOpCode(LnConstants.OPC_GPBUSY);
    tc.sendLocoNetMessage(msg);
}
Also used : LocoNetMessage(jmri.jmrix.loconet.LocoNetMessage)

Example 73 with LocoNetMessage

use of jmri.jmrix.loconet.LocoNetMessage in project JMRI by JMRI.

the class Pr3SelectPane method selectPR2mode.

void selectPR2mode() {
    // set to PR2 mode
    status.setText(Bundle.getMessage("StatusPr2"));
    LocoNetMessage msg = new LocoNetMessage(6);
    msg.setOpCode(0xD3);
    msg.setElement(1, 0x10);
    // set PR2
    msg.setElement(2, 1);
    msg.setElement(3, 0);
    msg.setElement(4, 0);
    memo.getLnTrafficController().sendLocoNetMessage(msg);
}
Also used : LocoNetMessage(jmri.jmrix.loconet.LocoNetMessage)

Example 74 with LocoNetMessage

use of jmri.jmrix.loconet.LocoNetMessage in project JMRI by JMRI.

the class ClientRxHandler method run.

@SuppressWarnings("null")
@Override
public void run() {
    try {
        inStream = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        outStream = clientSocket.getOutputStream();
        LnTrafficController.instance().addLocoNetListener(~0, this);
        txThread = new Thread(new ClientTxHandler(this));
        txThread.setDaemon(true);
        txThread.setPriority(Thread.MAX_PRIORITY);
        txThread.setName("ClientTxHandler:" + remoteAddress);
        txThread.start();
        while (!isInterrupted()) {
            inString = inStream.readLine();
            if (inString == null) {
                log.debug("ClientRxHandler: Remote Connection Closed");
                interrupt();
            } else {
                log.debug("ClientRxHandler: Received: " + inString);
                StringTokenizer st = new StringTokenizer(inString);
                if (st.nextToken().equals("SEND")) {
                    LocoNetMessage msg = null;
                    int opCode = Integer.parseInt(st.nextToken(), 16);
                    int byte2 = Integer.parseInt(st.nextToken(), 16);
                    // Decide length
                    switch((opCode & 0x60) >> 5) {
                        case // 2 byte message
                        0:
                            msg = new LocoNetMessage(2);
                            break;
                        case // 4 byte message
                        1:
                            msg = new LocoNetMessage(4);
                            break;
                        case // 6 byte message
                        2:
                            msg = new LocoNetMessage(6);
                            break;
                        case // N byte message
                        3:
                            if (byte2 < 2) {
                                log.error("ClientRxHandler: LocoNet message length invalid: " + byte2 + " opcode: " + Integer.toHexString(opCode));
                            }
                            msg = new LocoNetMessage(byte2);
                            break;
                        default:
                            log.warn("Unhandled msg length: {}", (opCode & 0x60) >> 5);
                            break;
                    }
                    if (msg == null) {
                        log.error("msg is null!");
                        return;
                    }
                    // message exists, now fill it
                    msg.setOpCode(opCode);
                    msg.setElement(1, byte2);
                    int len = msg.getNumDataElements();
                    for (int i = 2; i < len; i++) {
                        int b = Integer.parseInt(st.nextToken(), 16);
                        msg.setElement(i, b);
                    }
                    LnTrafficController.instance().sendLocoNetMessage(msg);
                    // Keep the message we just sent so we can ACK it when we hear
                    // the echo from the LocoBuffer
                    lastSentMessage = msg;
                }
            }
        }
    } catch (IOException ex) {
        log.debug("ClientRxHandler: IO Exception: ", ex);
    }
    LnTrafficController.instance().removeLocoNetListener(~0, this);
    txThread.interrupt();
    txThread = null;
    inStream = null;
    outStream = null;
    msgQueue.clear();
    try {
        clientSocket.close();
    } catch (IOException ex1) {
    }
    LnTcpServer.getDefault().removeClient(this);
    log.info("ClientRxHandler: Exiting");
}
Also used : StringTokenizer(java.util.StringTokenizer) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) LocoNetMessage(jmri.jmrix.loconet.LocoNetMessage) IOException(java.io.IOException)

Example 75 with LocoNetMessage

use of jmri.jmrix.loconet.LocoNetMessage in project JMRI by JMRI.

the class LocoGenTest method testPacketNull.

public void testPacketNull() {
    LocoGenPanel t = new LocoGenPanel();
    LocoNetMessage m = t.createPacket("");
    Assert.assertEquals("null pointer", null, m);
}
Also used : LocoNetMessage(jmri.jmrix.loconet.LocoNetMessage)

Aggregations

LocoNetMessage (jmri.jmrix.loconet.LocoNetMessage)103 Test (org.junit.Test)8 JFrame (javax.swing.JFrame)3 LocoNetInterfaceScaffold (jmri.jmrix.loconet.LocoNetInterfaceScaffold)3 LocoNetSystemConnectionMemo (jmri.jmrix.loconet.LocoNetSystemConnectionMemo)3 LocoStatsPanel (jmri.jmrix.loconet.locostats.swing.LocoStatsPanel)3 JmriJFrame (jmri.util.JmriJFrame)3 LocoNetSlot (jmri.jmrix.loconet.LocoNetSlot)2 SpjFile (jmri.jmrix.loconet.spjfile.SpjFile)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 StringTokenizer (java.util.StringTokenizer)1 LnPacketizer (jmri.jmrix.loconet.LnPacketizer)1 LnReporter (jmri.jmrix.loconet.LnReporter)1 LnTrafficController (jmri.jmrix.loconet.LnTrafficController)1 LnTurnout (jmri.jmrix.loconet.LnTurnout)1