// SimpleNodeIdent.java package org.openlcb; import java.util.ArrayList; import java.util.List; import java.nio.charset.Charset; /** * Accumulates data from Simple Node Ident Protocol replies and * provides access to the resulting data to represent a single node. * * @see "http://www.openlcb.org/trunk/specs/drafts/GenSimpleNodeInfoS.pdf" * @see "http://www.openlcb.org/trunk/specs/drafts/GenSimpleNodeInfoTN.pdf" * @author Bob Jacobsen Copyright (C) 2012 * @version $Revision: 18542 $ * */ public class SimpleNodeIdent { /* * @param msg Message, already known to be from proper node. */ public SimpleNodeIdent( SimpleNodeIdentInfoReplyMessage msg) { addMsg(msg); } public SimpleNodeIdent(NodeID source, NodeID dest) { this.source = source; this.dest = dest; } NodeID source; NodeID dest; void start(Connection connection) { next = 0; connection.put(new SimpleNodeIdentInfoRequestMessage(source, dest), null); } static final Charset UTF8 = Charset.forName("UTF8"); static final int MAX_REPLY_LENGTH = 256; // TODO from standard byte[] bytes = new byte[MAX_REPLY_LENGTH]; int next = 0; public void addMsg(SimpleNodeIdentInfoReplyMessage msg) { // if complete, restart with handling this message if (contentComplete()) { bytes = new byte[MAX_REPLY_LENGTH]; next = 0; } byte data[] = msg.getData(); for (int i = 0; i < data.length ; i++ ) { bytes[next++] = (byte)data[i]; } } /** * Check whether enough messages have arrived to * completely fill content. */ public boolean contentComplete() { // this is for the version 1 case only int strings = 0; for (int i=0; i