use of jmri.jmrix.can.adapters.gridconnect.GridConnectReply in project JMRI by JMRI.
the class HubPane method startHubThread.
void startHubThread(int port) {
t = new Thread() {
@Override
public void run() {
hub.start();
}
};
t.setDaemon(true);
// add forwarder for internal JMRI traffic
hub.addForwarder(new Hub.Forwarding() {
@Override
public void forward(Hub.Memo m) {
if (m.source == null) {
// was from this
return;
}
// process and forward m.line;
GridConnectReply msg = new GridConnectReply();
byte[] bytes;
try {
// GC adapters use ASCII // NOI18N
bytes = m.line.getBytes("US-ASCII");
} catch (java.io.UnsupportedEncodingException e) {
log.error("Cannot proceed with GC input message since US-ASCII not supported");
return;
}
for (int i = 0; i < m.line.length(); i++) {
msg.setElement(i, bytes[i]);
}
workingReply = msg.createReply();
CanMessage result = new CanMessage(workingReply.getNumDataElements(), workingReply.getHeader());
for (int i = 0; i < workingReply.getNumDataElements(); i++) {
result.setElement(i, workingReply.getElement(i));
}
result.setExtended(workingReply.isExtended());
// Send over outbound link
memo.getTrafficController().sendCanMessage(result, HubPane.this);
// And send into JMRI
memo.getTrafficController().distributeOneReply(workingReply, HubPane.this);
}
});
t.start();
advertise(port);
}
Aggregations