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);
}
}
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);
}
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);
}
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");
}
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);
}
Aggregations