|
From: <jac...@us...> - 2012-05-06 05:05:56
|
Revision: 2179
http://openlcb.svn.sourceforge.net/openlcb/?rev=2179&view=rev
Author: jacobsen
Date: 2012-05-06 05:05:50 +0000 (Sun, 06 May 2012)
Log Message:
-----------
current code
Modified Paths:
--------------
trunk/prototypes/java/openlcb-demo.jar
trunk/prototypes/java/openlcb.jar
Modified: trunk/prototypes/java/openlcb-demo.jar
===================================================================
(Binary files differ)
Modified: trunk/prototypes/java/openlcb.jar
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-06 06:41:25
|
Revision: 2180
http://openlcb.svn.sourceforge.net/openlcb/?rev=2180&view=rev
Author: jacobsen
Date: 2012-05-06 06:41:18 +0000 (Sun, 06 May 2012)
Log Message:
-----------
handle startup of SNII much better
Modified Paths:
--------------
trunk/prototypes/java/openlcb-demo.jar
trunk/prototypes/java/openlcb.jar
trunk/prototypes/java/src/org/openlcb/MimicNodeStore.java
trunk/prototypes/java/src/org/openlcb/SimpleNodeIdent.java
trunk/prototypes/java/src/org/openlcb/SimpleNodeIdentInfoRequestMessage.java
trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java
trunk/prototypes/java/src/org/openlcb/swing/networktree/NodeTreeRep.java
trunk/prototypes/java/src/org/openlcb/swing/networktree/TreePane.java
trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java
trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentInfoRequestMessageTest.java
trunk/prototypes/java/test/org/openlcb/swing/networktree/TreePaneTest.java
Modified: trunk/prototypes/java/openlcb-demo.jar
===================================================================
(Binary files differ)
Modified: trunk/prototypes/java/openlcb.jar
===================================================================
(Binary files differ)
Modified: trunk/prototypes/java/src/org/openlcb/MimicNodeStore.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/MimicNodeStore.java 2012-05-06 05:05:50 UTC (rev 2179)
+++ trunk/prototypes/java/src/org/openlcb/MimicNodeStore.java 2012-05-06 06:41:18 UTC (rev 2180)
@@ -14,9 +14,14 @@
* @version $Revision$
*/
public class MimicNodeStore extends MessageDecoder implements Connection {
- public MimicNodeStore() {
+ public MimicNodeStore(Connection connection, NodeID node) {
+ this.connection = connection;
+ this.node = node;
}
+ Connection connection;
+ NodeID node;
+
public Collection<NodeMemo> getNodeMemos() {
return map.values();
}
@@ -32,6 +37,18 @@
memo.put(msg, sender);
}
+ public SimpleNodeIdent getSimpleNodeIdent(NodeID dest) {
+ NodeMemo memo = map.get(dest);
+ if (memo == null) {
+ return null;
+ } else if (memo.getSimpleNodeIdent() != null) {
+ return memo.getSimpleNodeIdent();
+ } else {
+ connection.put(new SimpleNodeIdentInfoRequestMessage(node, dest), null);
+ return null;
+ }
+ }
+
HashMap<NodeID, NodeMemo> map = new java.util.HashMap<NodeID, NodeMemo>();
java.beans.PropertyChangeSupport pcs = new java.beans.PropertyChangeSupport(this);
Modified: trunk/prototypes/java/src/org/openlcb/SimpleNodeIdent.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/SimpleNodeIdent.java 2012-05-06 05:05:50 UTC (rev 2179)
+++ trunk/prototypes/java/src/org/openlcb/SimpleNodeIdent.java 2012-05-06 06:41:18 UTC (rev 2180)
@@ -40,7 +40,9 @@
// skip mfg
for (; len < bytes.length; len++)
if (bytes[len] == 0) break;
- return new String(bytes,start, len-start);
+ String s = new String(bytes,start, len-start);
+ if (s == null) return "";
+ else return s;
}
public String getModelName() {
int len = 1;
@@ -51,7 +53,9 @@
start = ++len;
for (; len < bytes.length; len++)
if (bytes[len] == 0) break;
- return new String(bytes,start, len-start);
+ String s = new String(bytes,start, len-start);
+ if (s == null) return "";
+ else return s;
}
public String getVersion() {
int len = 1;
@@ -65,7 +69,9 @@
start = ++len;
for (; len < bytes.length; len++)
if (bytes[len] == 0) break;
- return new String(bytes,start, len-start);
+ String s = new String(bytes,start, len-start);
+ if (s == null) return "";
+ else return s;
}
}
Modified: trunk/prototypes/java/src/org/openlcb/SimpleNodeIdentInfoRequestMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/SimpleNodeIdentInfoRequestMessage.java 2012-05-06 05:05:50 UTC (rev 2179)
+++ trunk/prototypes/java/src/org/openlcb/SimpleNodeIdentInfoRequestMessage.java 2012-05-06 06:41:18 UTC (rev 2180)
@@ -12,10 +12,10 @@
*/
@Immutable
@ThreadSafe
-public class SimpleNodeIdentInfoRequestMessage extends Message {
+public class SimpleNodeIdentInfoRequestMessage extends AddressedMessage {
- public SimpleNodeIdentInfoRequestMessage(NodeID source) {
- super(source);
+ public SimpleNodeIdentInfoRequestMessage(NodeID source, NodeID dest) {
+ super(source, dest);
}
long value;
Modified: trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java 2012-05-06 05:05:50 UTC (rev 2179)
+++ trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java 2012-05-06 06:41:18 UTC (rev 2180)
@@ -194,6 +194,7 @@
List<Message> processFormat6(CanFrame f) {
List<Message> retlist = new java.util.ArrayList<Message>();
NodeID source = map.getNodeID(getSourceID(f));
+ NodeID dest = map.getNodeID( (f.getHeader() & 0x00FFF000) >> 12);
int type = f.getElement(0);
switch (type) {
case 0x2E:
@@ -203,7 +204,7 @@
retlist.add(new ProtocolIdentificationReplyMessage(source,f.bodyAsLong()));
return retlist;
case 0x52:
- retlist.add(new SimpleNodeIdentInfoRequestMessage(source));
+ retlist.add(new SimpleNodeIdentInfoRequestMessage(source, dest));
return retlist;
case 0x53:
byte[] content = f.getData();
@@ -341,6 +342,15 @@
defaultHandler(msg, sender);
}
/**
+ * Handle "Simple Node Ident Info Request" message
+ */
+ public void handleSimpleNodeIdentInfoRequest(SimpleNodeIdentInfoRequestMessage msg, Connection sender){
+ OpenLcbCanFrame f = new OpenLcbCanFrame(0x00);
+ f.setAddressedMessage(map.getAlias(msg.getDestNodeID()), (byte)0x52);
+ f.setSourceAlias(map.getAlias(msg.getSourceNodeID()));
+ retlist.add(f);
+ }
+ /**
* Handle "Datagram" message
*/
public void handleDatagram(DatagramMessage msg, Connection sender){
Modified: trunk/prototypes/java/src/org/openlcb/swing/networktree/NodeTreeRep.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/swing/networktree/NodeTreeRep.java 2012-05-06 05:05:50 UTC (rev 2179)
+++ trunk/prototypes/java/src/org/openlcb/swing/networktree/NodeTreeRep.java 2012-05-06 06:41:18 UTC (rev 2180)
@@ -43,27 +43,7 @@
}
if (e.getPropertyName().equals("updateSimpleNodeIdent")) {
System.out.println("simple ID property change");
- if (simpleInfoMfgNode == null) {
- simpleInfoMfgNode = new DefaultMutableTreeNode("Mfg: "+((SimpleNodeIdent)e.getNewValue()).getMfgName());
- getTreeModel().insertNodeInto(simpleInfoMfgNode, getThis(),
- getThis().getChildCount());
- } else {
- simpleInfoMfgNode.setUserObject("Mfg: "+((SimpleNodeIdent)e.getNewValue()).getMfgName());
- }
- if (simpleInfoModelNode == null) {
- simpleInfoModelNode = new DefaultMutableTreeNode("Mod: "+((SimpleNodeIdent)e.getNewValue()).getModelName());
- getTreeModel().insertNodeInto(simpleInfoModelNode, getThis(),
- getThis().getChildCount());
- } else {
- simpleInfoModelNode.setUserObject("Mod: "+((SimpleNodeIdent)e.getNewValue()).getModelName());
- }
- if (simpleInfoVersionNode == null) {
- simpleInfoVersionNode = new DefaultMutableTreeNode("Ver: "+((SimpleNodeIdent)e.getNewValue()).getVersion());
- getTreeModel().insertNodeInto(simpleInfoVersionNode, getThis(),
- getThis().getChildCount());
- } else {
- simpleInfoVersionNode.setUserObject("Ver: "+((SimpleNodeIdent)e.getNewValue()).getVersion());
- }
+ updateSimpleNodeIdent((SimpleNodeIdent)e.getNewValue());
}
if (e.getPropertyName().equals("updateConsumers")) {
getTreeModel().insertNodeInto(new DefaultMutableTreeNode("Supported Consumers"), getThis(),
@@ -77,8 +57,36 @@
}
}
});
+
+ // see if simple ID info already present
+ SimpleNodeIdent id = store.getSimpleNodeIdent(memo.getNodeID());
+ if (id != null) updateSimpleNodeIdent(id); // otherwise, will be notified later
}
+ void updateSimpleNodeIdent(SimpleNodeIdent e) {
+ if (simpleInfoMfgNode == null) {
+ simpleInfoMfgNode = new DefaultMutableTreeNode("Mfg: "+e.getMfgName());
+ getTreeModel().insertNodeInto(simpleInfoMfgNode, getThis(),
+ getThis().getChildCount());
+ } else {
+ simpleInfoMfgNode.setUserObject("Mfg: "+e.getMfgName());
+ }
+ if (simpleInfoModelNode == null) {
+ simpleInfoModelNode = new DefaultMutableTreeNode("Mod: "+e.getModelName());
+ getTreeModel().insertNodeInto(simpleInfoModelNode, getThis(),
+ getThis().getChildCount());
+ } else {
+ simpleInfoModelNode.setUserObject("Mod: "+e.getModelName());
+ }
+ if (simpleInfoVersionNode == null) {
+ simpleInfoVersionNode = new DefaultMutableTreeNode("Ver: "+e.getVersion());
+ getTreeModel().insertNodeInto(simpleInfoVersionNode, getThis(),
+ getThis().getChildCount());
+ } else {
+ simpleInfoVersionNode.setUserObject("Ver: "+e.getVersion());
+ }
+ }
+
DefaultMutableTreeNode simpleInfoMfgNode;
DefaultMutableTreeNode simpleInfoModelNode;
DefaultMutableTreeNode simpleInfoVersionNode;
Modified: trunk/prototypes/java/src/org/openlcb/swing/networktree/TreePane.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/swing/networktree/TreePane.java 2012-05-06 05:05:50 UTC (rev 2179)
+++ trunk/prototypes/java/src/org/openlcb/swing/networktree/TreePane.java 2012-05-06 06:41:18 UTC (rev 2180)
@@ -28,18 +28,14 @@
MimicNodeStore getStore() { return store; }
DefaultTreeModel getTreeModel() { return treeModel; }
- public void initComponents(MimicNodeStore store) {
+ public void initComponents(MimicNodeStore store, final Connection connection, final NodeID node) {
this.store = store;
-
+
nodes = new DefaultMutableTreeNode("OpenLCB Network");
- // add nodes that exist now
- for (MimicNodeStore.NodeMemo memo : store.getNodeMemos() ) {
- nodes.add(new NodeTreeRep(memo, store, treeModel));
- }
- // listen for more
+ // listen for newly arrived nodes
store.addPropertyChangeListener(
new PropertyChangeListener(){
public void propertyChange(java.beans.PropertyChangeEvent e) {
@@ -53,6 +49,20 @@
}
});
+ // add nodes that exist now
+ for (MimicNodeStore.NodeMemo memo : store.getNodeMemos() ) {
+ nodes.add(new NodeTreeRep(memo, store, treeModel));
+ }
+
+ // kick off a listen when connection ready
+ Connection.ConnectionListener cl = new Connection.ConnectionListener(){
+ public void connectionActive(Connection c) {
+ // load the alias field
+ connection.put(new VerifyNodeIDNumberMessage(node), null);
+ }
+ };
+ if (connection != null) connection.registerStartNotification(cl);
+
// build GUI
treeModel = new DefaultTreeModel(nodes);
JTree tree = new JTree(treeModel);
Modified: trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java 2012-05-06 05:05:50 UTC (rev 2179)
+++ trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java 2012-05-06 06:41:18 UTC (rev 2180)
@@ -26,9 +26,14 @@
PropertyChangeListener listener;
boolean listenerFired;
+ Connection connection = new AbstractConnection() {
+ public void put(Message msg, Connection sender) {}
+ };
+
+ NodeID node = new NodeID(new byte[]{1,2,3,4,5,6});
public void setUp() {
- store = new MimicNodeStore();
+ store = new MimicNodeStore(connection, node);
listener = new PropertyChangeListener(){
public void propertyChange(java.beans.PropertyChangeEvent e) { listenerFired = true; }
Modified: trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentInfoRequestMessageTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentInfoRequestMessageTest.java 2012-05-06 05:05:50 UTC (rev 2179)
+++ trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentInfoRequestMessageTest.java 2012-05-06 06:41:18 UTC (rev 2180)
@@ -17,21 +17,30 @@
public void testEqualsSame() {
Message m1 = new SimpleNodeIdentInfoRequestMessage(
- nodeID1);
+ nodeID1,nodeID2);
Message m2 = new SimpleNodeIdentInfoRequestMessage(
- nodeID1);
+ nodeID1,nodeID2);
Assert.assertTrue(m1.equals(m2));
}
- public void testNotEqualsDifferentNode() {
+ public void testNotEqualsDifferentSrcNode() {
Message m1 = new SimpleNodeIdentInfoRequestMessage(
- nodeID1);
+ nodeID1,nodeID2);
Message m2 = new SimpleNodeIdentInfoRequestMessage(
- nodeID2);
+ nodeID2,nodeID2);
Assert.assertTrue( ! m1.equals(m2));
}
+
+ public void testNotEqualsDifferentDstNode() {
+ Message m1 = new SimpleNodeIdentInfoRequestMessage(
+ nodeID1,nodeID2);
+ Message m2 = new SimpleNodeIdentInfoRequestMessage(
+ nodeID1,nodeID1);
+
+ Assert.assertTrue( ! m1.equals(m2));
+ }
public void testHandling() {
@@ -42,7 +51,7 @@
result = true;
}
};
- Message m = new SimpleNodeIdentInfoRequestMessage(nodeID1);
+ Message m = new SimpleNodeIdentInfoRequestMessage(nodeID1, nodeID2);
n.put(m, null);
Modified: trunk/prototypes/java/test/org/openlcb/swing/networktree/TreePaneTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/swing/networktree/TreePaneTest.java 2012-05-06 05:05:50 UTC (rev 2179)
+++ trunk/prototypes/java/test/org/openlcb/swing/networktree/TreePaneTest.java 2012-05-06 06:41:18 UTC (rev 2180)
@@ -39,10 +39,14 @@
JFrame frame;
TreePane pane;
+ Connection connection = new AbstractConnection() {
+ public void put(Message msg, Connection sender) {}
+ };
+
MimicNodeStore store;
public void setUp() throws Exception {
- store = new MimicNodeStore();
+ store = new MimicNodeStore(connection, nid1);
Message msg = new ProducerIdentifiedMessage(nid1, eventA);
store.put(msg, null);
@@ -51,7 +55,7 @@
frame.setTitle("TreePane Test");
TreePane pane = new TreePane();
frame.add( pane );
- pane.initComponents(store);
+ pane.initComponents(store, null, null);
frame.pack();
frame.setMinimumSize(new java.awt.Dimension(200,200));
frame.setVisible(true);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-07 01:20:26
|
Revision: 2182
http://openlcb.svn.sourceforge.net/openlcb/?rev=2182&view=rev
Author: jacobsen
Date: 2012-05-07 01:20:20 +0000 (Mon, 07 May 2012)
Log Message:
-----------
handling of read reply data
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/implementations/DatagramService.java
trunk/prototypes/java/src/org/openlcb/implementations/MemoryConfigurationService.java
trunk/prototypes/java/test/org/openlcb/implementations/MemoryConfigurationServiceTest.java
Modified: trunk/prototypes/java/src/org/openlcb/implementations/DatagramService.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/DatagramService.java 2012-05-07 01:19:40 UTC (rev 2181)
+++ trunk/prototypes/java/src/org/openlcb/implementations/DatagramService.java 2012-05-07 01:20:20 UTC (rev 2182)
@@ -68,6 +68,7 @@
* Handle positive datagram reply message from layout
*/
public void handleDatagramAcknowledged(DatagramAcknowledgedMessage msg, Connection sender){
+ System.out.println("received Datagram acknowledged");
if (xmtMemo != null) {
xmtMemo.handleReply(0);
}
Modified: trunk/prototypes/java/src/org/openlcb/implementations/MemoryConfigurationService.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/MemoryConfigurationService.java 2012-05-07 01:19:40 UTC (rev 2181)
+++ trunk/prototypes/java/src/org/openlcb/implementations/MemoryConfigurationService.java 2012-05-07 01:20:20 UTC (rev 2182)
@@ -18,12 +18,21 @@
*/
public class MemoryConfigurationService {
+ private static final int DATAGRAM_TYPE = 0x20;
/**
* @param downstream Connection in the direction of the layout
*/
public MemoryConfigurationService(NodeID here, DatagramService downstream) {
this.here = here;
this.downstream = downstream;
+
+ // connect to be notified of config service
+ downstream.registerForReceive(new DatagramService.DatagramServiceReceiveMemo(DATAGRAM_TYPE){
+ public int handleData(int[] data) {
+ System.out.println("Received datagram "+data);
+ return 0;
+ }
+ });
}
NodeID here;
@@ -34,10 +43,16 @@
WriteDatagramMemo dg = new WriteDatagramMemo(memo.dest, memo.space, memo.address, memo.data, memo);
downstream.sendData(dg);
}
+
+ public void request(McsReadMemo memo) {
+ // forward as read Datagram
+ ReadDatagramMemo dg = new ReadDatagramMemo(memo.dest, memo.space, memo.address, memo.count, memo);
+ downstream.sendData(dg);
+ }
@Immutable
@ThreadSafe
- static protected class McsReadMemo {
+ static public class McsReadMemo {
public McsReadMemo(NodeID dest, int space, long address, int count) {
this.count = count;
this.address = address;
@@ -83,15 +98,46 @@
@Immutable
@ThreadSafe
- static protected class McsWriteMemo {
- public McsWriteMemo(NodeID dest, int space, long address, int[] data) {
+ static public class ReadDatagramMemo extends DatagramService.DatagramServiceTransmitMemo {
+ ReadDatagramMemo(NodeID dest, int space, long address, int count, McsReadMemo memo) {
+ super(dest);
+ boolean spaceByte = false;
+ if (space<0xFD) spaceByte = true;
+ this.data = new int[6+(spaceByte ? 1 : 0)+1];
+ this.data[0] = DATAGRAM_TYPE;
+ this.data[1] = 0x40;
+ if (space >= 0xFD) this.data[1] |= space&0x3;
+
+ this.data[2] = (int)(address>>24)&0xFF;
+ this.data[3] = (int)(address>>16)&0xFF;
+ this.data[4] = (int)(address>>8 )&0xFF;
+ this.data[5] = (int)(address )&0xFF;
+
+ if (spaceByte) this.data[6] = space;
+
+ this.data[6+(spaceByte ? 1 : 0)] = count;
+
+ this.memo = memo;
+ }
+ McsReadMemo memo;
+ public void handleReply(int code) {
+ memo.handleWriteReply(code);
+ }
+
+
+ }
+
+ @Immutable
+ @ThreadSafe
+ static public class McsWriteMemo {
+ public McsWriteMemo(NodeID dest, int space, long address, byte[] data) {
this.data = data;
this.address = address;
this.space = space;
this.dest = dest;
}
- int[] data;
+ byte[] data;
long address;
int space;
NodeID dest;
@@ -126,13 +172,13 @@
@Immutable
@ThreadSafe
- protected class WriteDatagramMemo extends DatagramService.DatagramServiceTransmitMemo {
- WriteDatagramMemo(NodeID dest, int space, long address, int[] content, McsWriteMemo memo) {
+ static public class WriteDatagramMemo extends DatagramService.DatagramServiceTransmitMemo {
+ WriteDatagramMemo(NodeID dest, int space, long address, byte[] content, McsWriteMemo memo) {
super(dest);
boolean spaceByte = false;
if (space<0xFD) spaceByte = true;
this.data = new int[6+(spaceByte ? 1 : 0)+content.length];
- this.data[0] = 0x20;
+ this.data[0] = DATAGRAM_TYPE;
this.data[1] = 0x00;
if (space >= 0xFD) this.data[1] |= space&0x3;
Modified: trunk/prototypes/java/test/org/openlcb/implementations/MemoryConfigurationServiceTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/MemoryConfigurationServiceTest.java 2012-05-07 01:19:40 UTC (rev 2181)
+++ trunk/prototypes/java/test/org/openlcb/implementations/MemoryConfigurationServiceTest.java 2012-05-07 01:20:20 UTC (rev 2182)
@@ -67,21 +67,21 @@
public void testWriteMemoIsRealClass() {
MemoryConfigurationService.McsWriteMemo m20 =
- new MemoryConfigurationService.McsWriteMemo(farID,0xFD, 0x0000, new int[]{1,2});
+ new MemoryConfigurationService.McsWriteMemo(farID,0xFD, 0x0000, new byte[]{1,2});
MemoryConfigurationService.McsWriteMemo m20a =
- new MemoryConfigurationService.McsWriteMemo(farID,0xFD, 0x0000, new int[]{1,2});
+ new MemoryConfigurationService.McsWriteMemo(farID,0xFD, 0x0000, new byte[]{1,2});
MemoryConfigurationService.McsWriteMemo m21 =
- new MemoryConfigurationService.McsWriteMemo(hereID,0xFD, 0x0000, new int[]{1,2});
+ new MemoryConfigurationService.McsWriteMemo(hereID,0xFD, 0x0000, new byte[]{1,2});
MemoryConfigurationService.McsWriteMemo m22 =
- new MemoryConfigurationService.McsWriteMemo(farID,0xFE, 0x0000, new int[]{1,2});
+ new MemoryConfigurationService.McsWriteMemo(farID,0xFE, 0x0000, new byte[]{1,2});
MemoryConfigurationService.McsWriteMemo m23 =
- new MemoryConfigurationService.McsWriteMemo(farID,0xFD, 0x0001, new int[]{1,2});
+ new MemoryConfigurationService.McsWriteMemo(farID,0xFD, 0x0001, new byte[]{1,2});
MemoryConfigurationService.McsWriteMemo m24 =
- new MemoryConfigurationService.McsWriteMemo(farID,0xFD, 0x0000, new int[]{1});
+ new MemoryConfigurationService.McsWriteMemo(farID,0xFD, 0x0000, new byte[]{1});
MemoryConfigurationService.McsWriteMemo m25 =
- new MemoryConfigurationService.McsWriteMemo(farID,0xFD, 0x0000, new int[]{1,2,3});
+ new MemoryConfigurationService.McsWriteMemo(farID,0xFD, 0x0000, new byte[]{1,2,3});
MemoryConfigurationService.McsWriteMemo m26 =
- new MemoryConfigurationService.McsWriteMemo(farID,0xFD, 0x0000, new int[]{1,5,3});
+ new MemoryConfigurationService.McsWriteMemo(farID,0xFD, 0x0000, new byte[]{1,5,3});
Assert.assertTrue(m20.equals(m20));
Assert.assertTrue(m20.equals(m20a));
@@ -100,7 +100,7 @@
public void testSimpleWrite() {
int space = 0xFD;
long address = 0x12345678;
- int[] data = new int[]{1,2};
+ byte[] data = new byte[]{1,2};
MemoryConfigurationService.McsWriteMemo memo =
new MemoryConfigurationService.McsWriteMemo(farID, space, address, data) {
public void handleWriteReply(int code) {
@@ -211,7 +211,7 @@
//
//
// public void testSendOK() {
-// int[] data = new int[]{1,2,3,4,5};
+// int[] data = new byte[]{1,2,3,4,5};
// DatagramService.DatagramServiceTransmitMemo memo =
// new DatagramService.DatagramServiceTransmitMemo(farID,data) {
// public void handleReply(int code) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-07 01:21:45
|
Revision: 2184
http://openlcb.svn.sourceforge.net/openlcb/?rev=2184&view=rev
Author: jacobsen
Date: 2012-05-07 01:21:39 +0000 (Mon, 07 May 2012)
Log Message:
-----------
0.4.5
Modified Paths:
--------------
trunk/prototypes/java/manifest
trunk/prototypes/java/openlcb-demo.jar
trunk/prototypes/java/openlcb.jar
Modified: trunk/prototypes/java/manifest
===================================================================
--- trunk/prototypes/java/manifest 2012-05-07 01:20:50 UTC (rev 2183)
+++ trunk/prototypes/java/manifest 2012-05-07 01:21:39 UTC (rev 2184)
@@ -4,9 +4,9 @@
Name: org.openlcb
Specification-Title: \xD2OpenLCB\xD3
-Specification-Version: \xD20.4.1\xD3
+Specification-Version: \xD20.4.5\xD3
Specification-Vendor: \xD2OpenLCB group"
Package-Title: \xD2openlcb\xD3
-Package-Version: \xD20.4.4\xD3
+Package-Version: \xD20.4.5\xD3
Package-Vendor: \xD2OpenLCB group\xD3
Modified: trunk/prototypes/java/openlcb-demo.jar
===================================================================
(Binary files differ)
Modified: trunk/prototypes/java/openlcb.jar
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-07 07:09:38
|
Revision: 2186
http://openlcb.svn.sourceforge.net/openlcb/?rev=2186&view=rev
Author: jacobsen
Date: 2012-05-07 07:09:32 +0000 (Mon, 07 May 2012)
Log Message:
-----------
improved handling of read-reply datagrams from config service
Modified Paths:
--------------
trunk/prototypes/java/manifest
trunk/prototypes/java/openlcb-demo.jar
trunk/prototypes/java/openlcb.jar
trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java
trunk/prototypes/java/src/org/openlcb/implementations/DatagramService.java
trunk/prototypes/java/src/org/openlcb/implementations/MemoryConfigurationService.java
trunk/prototypes/java/test/org/openlcb/implementations/DatagramServiceTest.java
Modified: trunk/prototypes/java/manifest
===================================================================
--- trunk/prototypes/java/manifest 2012-05-07 02:41:46 UTC (rev 2185)
+++ trunk/prototypes/java/manifest 2012-05-07 07:09:32 UTC (rev 2186)
@@ -4,9 +4,9 @@
Name: org.openlcb
Specification-Title: \xD2OpenLCB\xD3
-Specification-Version: \xD20.4.5\xD3
+Specification-Version: \xD20.4.2\xD3
Specification-Vendor: \xD2OpenLCB group"
Package-Title: \xD2openlcb\xD3
-Package-Version: \xD20.4.5\xD3
+Package-Version: \xD20.4.6\xD3
Package-Vendor: \xD2OpenLCB group\xD3
Modified: trunk/prototypes/java/openlcb-demo.jar
===================================================================
(Binary files differ)
Modified: trunk/prototypes/java/openlcb.jar
===================================================================
(Binary files differ)
Modified: trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java 2012-05-07 02:41:46 UTC (rev 2185)
+++ trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java 2012-05-07 07:09:32 UTC (rev 2186)
@@ -203,6 +203,12 @@
case 0x2F:
retlist.add(new ProtocolIdentificationReplyMessage(source,f.bodyAsLong()));
return retlist;
+ case 0x4C:
+ retlist.add(new DatagramAcknowledgedMessage(source,dest));
+ return retlist;
+ case 0x4D:
+ retlist.add(new DatagramRejectedMessage(source,dest,(int)f.bodyAsLong()));
+ return retlist;
case 0x52:
retlist.add(new SimpleNodeIdentInfoRequestMessage(source, dest));
return retlist;
Modified: trunk/prototypes/java/src/org/openlcb/implementations/DatagramService.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/DatagramService.java 2012-05-07 02:41:46 UTC (rev 2185)
+++ trunk/prototypes/java/src/org/openlcb/implementations/DatagramService.java 2012-05-07 07:09:32 UTC (rev 2186)
@@ -51,7 +51,7 @@
// forward
int retval = DEFAULT_ERROR_CODE;
if (rcvMemo != null && rcvMemo.type == msg.getData()[0]) {
- retval = rcvMemo.handleData(msg.getData());
+ retval = rcvMemo.handleData(msg.getSourceNodeID(), msg.getData());
}
if (retval == 0) {
// accept
@@ -68,7 +68,6 @@
* Handle positive datagram reply message from layout
*/
public void handleDatagramAcknowledged(DatagramAcknowledgedMessage msg, Connection sender){
- System.out.println("received Datagram acknowledged");
if (xmtMemo != null) {
xmtMemo.handleReply(0);
}
@@ -111,7 +110,7 @@
* Overload this to for notification of data.
* @returns 0 for OK, non-zero for error reply
*/
- public int handleData(int[] data) {
+ public int handleData(NodeID n, int[] data) {
// default is error
return DEFAULT_ERROR_CODE;
}
Modified: trunk/prototypes/java/src/org/openlcb/implementations/MemoryConfigurationService.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/MemoryConfigurationService.java 2012-05-07 02:41:46 UTC (rev 2185)
+++ trunk/prototypes/java/src/org/openlcb/implementations/MemoryConfigurationService.java 2012-05-07 07:09:32 UTC (rev 2186)
@@ -28,8 +28,14 @@
// connect to be notified of config service
downstream.registerForReceive(new DatagramService.DatagramServiceReceiveMemo(DATAGRAM_TYPE){
- public int handleData(int[] data) {
- System.out.println("Received datagram "+data);
+ public int handleData(NodeID dest, int[] data) {
+ System.out.println("Received datagram of "+data.length+" from "+dest);
+ if (readMemo != null) {
+ byte[] content = new byte[data.length-6];
+ for (int i = 0; i<content.length; i++) content[i] = (byte)data[i+6];
+ readMemo.handleReadData(dest, readMemo.space, readMemo.address, content);
+ }
+ readMemo = null;
return 0;
}
});
@@ -38,14 +44,17 @@
NodeID here;
DatagramService downstream;
+
public void request(McsWriteMemo memo) {
// forward as write Datagram
WriteDatagramMemo dg = new WriteDatagramMemo(memo.dest, memo.space, memo.address, memo.data, memo);
downstream.sendData(dg);
}
+ McsReadMemo readMemo;
public void request(McsReadMemo memo) {
// forward as read Datagram
+ readMemo = memo;
ReadDatagramMemo dg = new ReadDatagramMemo(memo.dest, memo.space, memo.address, memo.count, memo);
downstream.sendData(dg);
}
@@ -91,7 +100,7 @@
/**
* Overload this for notification of data.
*/
- public void handleReadData(int[] data) {
+ public void handleReadData(NodeID dest, int space, long address, byte[] data) {
}
}
Modified: trunk/prototypes/java/test/org/openlcb/implementations/DatagramServiceTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/DatagramServiceTest.java 2012-05-07 02:41:46 UTC (rev 2185)
+++ trunk/prototypes/java/test/org/openlcb/implementations/DatagramServiceTest.java 2012-05-07 07:09:32 UTC (rev 2186)
@@ -99,7 +99,7 @@
public void testReceiveFirstDG() {
DatagramService.DatagramServiceReceiveMemo m20 =
new DatagramService.DatagramServiceReceiveMemo(0x20){
- public int handleData(int[] data) {
+ public int handleData( NodeID n, int[] data) {
flag = true;
return 0;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-09 04:25:40
|
Revision: 2188
http://openlcb.svn.sourceforge.net/openlcb/?rev=2188&view=rev
Author: jacobsen
Date: 2012-05-09 04:25:34 +0000 (Wed, 09 May 2012)
Log Message:
-----------
occasional startup NPE in TreePane
Modified Paths:
--------------
trunk/prototypes/java/openlcb-demo.jar
trunk/prototypes/java/openlcb.jar
trunk/prototypes/java/src/org/openlcb/swing/networktree/NodeTreeRep.java
trunk/prototypes/java/src/org/openlcb/swing/networktree/TreePane.java
Modified: trunk/prototypes/java/openlcb-demo.jar
===================================================================
(Binary files differ)
Modified: trunk/prototypes/java/openlcb.jar
===================================================================
(Binary files differ)
Modified: trunk/prototypes/java/src/org/openlcb/swing/networktree/NodeTreeRep.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/swing/networktree/NodeTreeRep.java 2012-05-08 18:09:23 UTC (rev 2187)
+++ trunk/prototypes/java/src/org/openlcb/swing/networktree/NodeTreeRep.java 2012-05-09 04:25:34 UTC (rev 2188)
@@ -29,7 +29,9 @@
this.memo = memo;
this.store = store;
this.treeModel = treeModel;
-
+ }
+
+ void initConnections() {
// listen for more info arriving
memo.addPropertyChangeListener(
new PropertyChangeListener(){
@@ -64,22 +66,25 @@
void updateSimpleNodeIdent(SimpleNodeIdent e) {
if (simpleInfoMfgNode == null) {
simpleInfoMfgNode = new DefaultMutableTreeNode("Mfg: "+e.getMfgName());
- getTreeModel().insertNodeInto(simpleInfoMfgNode, getThis(),
- getThis().getChildCount());
+ getTreeModel().insertNodeInto(simpleInfoMfgNode,
+ getThis(),
+ getThis().getChildCount());
} else {
simpleInfoMfgNode.setUserObject("Mfg: "+e.getMfgName());
}
if (simpleInfoModelNode == null) {
simpleInfoModelNode = new DefaultMutableTreeNode("Mod: "+e.getModelName());
- getTreeModel().insertNodeInto(simpleInfoModelNode, getThis(),
- getThis().getChildCount());
+ getTreeModel().insertNodeInto(simpleInfoModelNode,
+ getThis(),
+ getThis().getChildCount());
} else {
simpleInfoModelNode.setUserObject("Mod: "+e.getModelName());
}
if (simpleInfoVersionNode == null) {
simpleInfoVersionNode = new DefaultMutableTreeNode("Ver: "+e.getVersion());
- getTreeModel().insertNodeInto(simpleInfoVersionNode, getThis(),
- getThis().getChildCount());
+ getTreeModel().insertNodeInto(simpleInfoVersionNode,
+ getThis(),
+ getThis().getChildCount());
} else {
simpleInfoVersionNode.setUserObject("Ver: "+e.getVersion());
}
Modified: trunk/prototypes/java/src/org/openlcb/swing/networktree/TreePane.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/swing/networktree/TreePane.java 2012-05-08 18:09:23 UTC (rev 2187)
+++ trunk/prototypes/java/src/org/openlcb/swing/networktree/TreePane.java 2012-05-09 04:25:34 UTC (rev 2188)
@@ -34,6 +34,12 @@
nodes = new DefaultMutableTreeNode("OpenLCB Network");
+ // build GUI
+ treeModel = new DefaultTreeModel(nodes);
+ JTree tree = new JTree(treeModel);
+ tree.setEditable(true);
+ JScrollPane treeView = new JScrollPane(tree);
+ add(treeView);
// listen for newly arrived nodes
store.addPropertyChangeListener(
@@ -43,16 +49,23 @@
if (e.getPropertyName().equals("AddNode")) {
MimicNodeStore.NodeMemo memo = (MimicNodeStore.NodeMemo) e.getNewValue();
- treeModel.insertNodeInto(new NodeTreeRep(memo, getStore(), getTreeModel()), nodes,
+ NodeTreeRep n = new NodeTreeRep(memo, getStore(), getTreeModel());
+ treeModel.insertNodeInto(n, nodes,
nodes.getChildCount());
+ n.initConnections();
}
}
});
// add nodes that exist now
for (MimicNodeStore.NodeMemo memo : store.getNodeMemos() ) {
- nodes.add(new NodeTreeRep(memo, store, treeModel));
+ NodeTreeRep n = new NodeTreeRep(memo, store, treeModel);
+ nodes.add(n);
+ n.initConnections();
}
+
+ // start with top level expanded
+ tree.expandPath(new TreePath(nodes.getPath()));
// kick off a listen when connection ready
Connection.ConnectionListener cl = new Connection.ConnectionListener(){
@@ -63,12 +76,6 @@
};
if (connection != null) connection.registerStartNotification(cl);
- // build GUI
- treeModel = new DefaultTreeModel(nodes);
- JTree tree = new JTree(treeModel);
- tree.setEditable(true);
- JScrollPane treeView = new JScrollPane(tree);
- add(treeView);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-10 12:44:12
|
Revision: 2189
http://openlcb.svn.sourceforge.net/openlcb/?rev=2189&view=rev
Author: jacobsen
Date: 2012-05-10 12:44:05 +0000 (Thu, 10 May 2012)
Log Message:
-----------
new, allows selection from known nodes
Modified Paths:
--------------
trunk/prototypes/java/test/org/openlcb/swing/PackageTest.java
Added Paths:
-----------
trunk/prototypes/java/src/org/openlcb/swing/NodeSelector.java
trunk/prototypes/java/test/org/openlcb/swing/NodeSelectorTest.java
Copied: trunk/prototypes/java/src/org/openlcb/swing/NodeSelector.java (from rev 2188, trunk/prototypes/java/src/org/openlcb/swing/ConsumerPane.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/swing/NodeSelector.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/swing/NodeSelector.java 2012-05-10 12:44:05 UTC (rev 2189)
@@ -0,0 +1,50 @@
+// NodeSelector.java
+
+package org.openlcb.swing;
+
+import javax.swing.*;
+import javax.swing.text.*;
+import java.beans.PropertyChangeListener;
+
+import org.openlcb.*;
+import org.openlcb.implementations.*;
+
+/**
+ * Java Swing component to select a node, populated
+ * from a MimicNodeStore
+ *
+ * @author Bob Jacobsen Copyright (C) 2012
+ * @version $Revision$
+ */
+public class NodeSelector extends JPanel {
+
+ MimicNodeStore store;
+ JComboBox box;
+ public NodeSelector(MimicNodeStore store) {
+ this.store = store;
+
+ box = new JComboBox();
+ add(box);
+
+ // listen for newly arrived nodes
+ store.addPropertyChangeListener(
+ new PropertyChangeListener(){
+ public void propertyChange(java.beans.PropertyChangeEvent e) {
+
+ if (e.getPropertyName().equals("AddNode")) {
+ MimicNodeStore.NodeMemo memo = (MimicNodeStore.NodeMemo) e.getNewValue();
+ box.addItem(memo.getNodeID());
+ }
+ }
+ });
+
+ // add existing nodes
+ for (MimicNodeStore.NodeMemo memo : store.getNodeMemos() ) {
+ box.addItem(memo.getNodeID());
+ }
+
+ // set up to add more as they become available
+
+ }
+
+}
Added: trunk/prototypes/java/test/org/openlcb/swing/NodeSelectorTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/swing/NodeSelectorTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/swing/NodeSelectorTest.java 2012-05-10 12:44:05 UTC (rev 2189)
@@ -0,0 +1,81 @@
+package org.openlcb.swing;
+
+import org.openlcb.*;
+import org.openlcb.implementations.*;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import javax.swing.*;
+/**
+ *
+ * @author Bob Jacobsen Copyright 2009
+ * @version $Revision: 34 $
+ */
+public class NodeSelectorTest extends TestCase {
+
+ NodeID id1 = new NodeID(new byte[]{0,0,0,0,0,1});
+ NodeID id2 = new NodeID(new byte[]{0,0,0,0,0,2});
+ NodeID id3 = new NodeID(new byte[]{0,0,0,0,0,3});
+ NodeID id4 = new NodeID(new byte[]{0,0,0,0,0,4});
+ NodeID id5 = new NodeID(new byte[]{0,0,0,0,0,5});
+ NodeID id6 = new NodeID(new byte[]{0,0,0,0,0,6});
+ NodeID id7 = new NodeID(new byte[]{0,0,0,0,0,7});
+ NodeID id8 = new NodeID(new byte[]{0,0,0,0,0,8});
+ NodeID id9 = new NodeID(new byte[]{0,0,0,0,0,9});
+
+ NodeID thisNode = new NodeID(new byte[]{1,2,3,4,5,6});
+ MimicNodeStore store;
+
+ JFrame frame;
+
+ public void setUp() throws Exception {
+ store = new MimicNodeStore(null, thisNode);
+ store.addNode(id1);
+ store.addNode(id2);
+ store.addNode(id3);
+
+ // Test is really popping a window before doing all else
+ frame = new JFrame();
+ frame.setTitle("NodeSelector: expect 3");
+ NodeSelector m = new NodeSelector(store);
+ frame.add( m );
+ frame.pack();
+ frame.setVisible(true);
+
+ }
+
+ public void tearDown() {}
+
+ public void testCtor() {
+ // test is really in setUp()
+ }
+
+ public void testNodesArrivingLater() {
+ frame.setTitle("NodeSelector: expect 6");
+ frame.setLocation(0,100);
+ store.addNode(id4);
+ store.addNode(id5);
+ store.addNode(id6);
+ }
+
+ // from here down is testing infrastructure
+
+ public NodeSelectorTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {NodeSelectorTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(NodeSelectorTest.class);
+ return suite;
+ }
+}
Modified: trunk/prototypes/java/test/org/openlcb/swing/PackageTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/swing/PackageTest.java 2012-05-09 04:25:34 UTC (rev 2188)
+++ trunk/prototypes/java/test/org/openlcb/swing/PackageTest.java 2012-05-10 12:44:05 UTC (rev 2189)
@@ -34,6 +34,7 @@
public static Test suite() {
TestSuite suite = new TestSuite(PackageTest.class);
suite.addTest(MonPaneTest.suite());
+ suite.addTest(NodeSelectorTest.suite());
suite.addTest(org.openlcb.swing.networktree.PackageTest.suite());
return suite;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-13 18:38:13
|
Revision: 2201
http://openlcb.svn.sourceforge.net/openlcb/?rev=2201&view=rev
Author: jacobsen
Date: 2012-05-13 18:38:07 +0000 (Sun, 13 May 2012)
Log Message:
-----------
start new package
Modified Paths:
--------------
trunk/prototypes/java/test/org/openlcb/swing/PackageTest.java
Added Paths:
-----------
trunk/prototypes/java/src/org/openlcb/swing/memconfig/
trunk/prototypes/java/src/org/openlcb/swing/memconfig/package-info.java
trunk/prototypes/java/test/org/openlcb/swing/memconfig/
trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigDescriptionPaneTest.java
trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigReadWritePaneTest.java
trunk/prototypes/java/test/org/openlcb/swing/memconfig/PackageTest.java
Copied: trunk/prototypes/java/src/org/openlcb/swing/memconfig/package-info.java (from rev 2192, trunk/prototypes/java/src/org/openlcb/package-info.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/swing/memconfig/package-info.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/swing/memconfig/package-info.java 2012-05-13 18:38:07 UTC (rev 2201)
@@ -0,0 +1,13 @@
+
+/**
+Swing JPanels for doing direct manipulation via the Memory Configuration Protocol
+<p>
+This is not intended as a base for production implementations,
+but rather a convenient example of implementing
+of OpenLCB protocols.
+<p>
+The various "Pane" classes implement independent pieces that can be
+arranged as needed. For example, a simple configuration window doesn't
+need to show the description information pane.
+*/
+package org.openlcb.swing.memconfig;
Modified: trunk/prototypes/java/test/org/openlcb/swing/PackageTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/swing/PackageTest.java 2012-05-13 05:24:58 UTC (rev 2200)
+++ trunk/prototypes/java/test/org/openlcb/swing/PackageTest.java 2012-05-13 18:38:07 UTC (rev 2201)
@@ -36,6 +36,7 @@
suite.addTest(MonPaneTest.suite());
suite.addTest(NodeSelectorTest.suite());
suite.addTest(org.openlcb.swing.networktree.PackageTest.suite());
+ suite.addTest(org.openlcb.swing.memconfig.PackageTest.suite());
return suite;
}
Copied: trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigDescriptionPaneTest.java (from rev 2192, trunk/prototypes/java/test/org/openlcb/swing/networktree/TreePaneTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigDescriptionPaneTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigDescriptionPaneTest.java 2012-05-13 18:38:07 UTC (rev 2201)
@@ -0,0 +1,75 @@
+package org.openlcb.swing.memconfig;
+
+import org.openlcb.*;
+import org.openlcb.implementations.*;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import javax.swing.*;
+/**
+ * Simulate nine nodes interacting on a single gather/scatter
+ * "link", and feed them to monitor.
+ * <ul>
+ * <li>Nodes 1,2,3 send Event A to 8,9
+ * <li>Node 4 sends Event B to node 7
+ * <li>Node 5 sends Event C to node 6
+ * </ul>
+ *
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision: 34 $
+ */
+public class MemConfigDescriptionPaneTest extends TestCase {
+
+ NodeID nidHere = new NodeID(new byte[]{0,0,0,0,0,1});
+ NodeID nidThere = new NodeID(new byte[]{0,0,0,0,0,2});
+
+ JFrame frame;
+ Connection connection = new AbstractConnection() {
+ public void put(Message msg, Connection sender) {}
+ };
+
+ MimicNodeStore store;
+
+ public void setUp() throws Exception {
+ store = new MimicNodeStore(connection, nidHere);
+ store.addNode(nidThere);
+
+ // Test is really popping a window before doing all else
+ frame = new JFrame();
+ frame.setTitle("MemConfigDescriptionPane Test");
+
+ frame.pack();
+ frame.setMinimumSize(new java.awt.Dimension(200,200));
+ frame.setVisible(true);
+
+
+ }
+
+ public void tearDown() {
+ //frame.setVisible(false);
+ }
+
+ public void testSetup() {
+ }
+
+ // from here down is testing infrastructure
+
+ public MemConfigDescriptionPaneTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {MemConfigDescriptionPaneTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(MemConfigDescriptionPaneTest.class);
+ return suite;
+ }
+}
Copied: trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigReadWritePaneTest.java (from rev 2192, trunk/prototypes/java/test/org/openlcb/swing/networktree/TreePaneTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigReadWritePaneTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigReadWritePaneTest.java 2012-05-13 18:38:07 UTC (rev 2201)
@@ -0,0 +1,75 @@
+package org.openlcb.swing.memconfig;
+
+import org.openlcb.*;
+import org.openlcb.implementations.*;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import javax.swing.*;
+/**
+ * Simulate nine nodes interacting on a single gather/scatter
+ * "link", and feed them to monitor.
+ * <ul>
+ * <li>Nodes 1,2,3 send Event A to 8,9
+ * <li>Node 4 sends Event B to node 7
+ * <li>Node 5 sends Event C to node 6
+ * </ul>
+ *
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision: 34 $
+ */
+public class MemConfigReadWritePaneTest extends TestCase {
+
+ NodeID nidHere = new NodeID(new byte[]{0,0,0,0,0,1});
+ NodeID nidThere = new NodeID(new byte[]{0,0,0,0,0,2});
+
+ JFrame frame;
+ Connection connection = new AbstractConnection() {
+ public void put(Message msg, Connection sender) {}
+ };
+
+ MimicNodeStore store;
+
+ public void setUp() throws Exception {
+ store = new MimicNodeStore(connection, nidHere);
+ store.addNode(nidThere);
+
+ // Test is really popping a window before doing all else
+ frame = new JFrame();
+ frame.setTitle("MemConfigReadWritePane Test");
+
+ frame.pack();
+ frame.setMinimumSize(new java.awt.Dimension(200,200));
+ frame.setVisible(true);
+
+
+ }
+
+ public void tearDown() {
+ //frame.setVisible(false);
+ }
+
+ public void testSetup() {
+ }
+
+ // from here down is testing infrastructure
+
+ public MemConfigReadWritePaneTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {MemConfigReadWritePaneTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(MemConfigReadWritePaneTest.class);
+ return suite;
+ }
+}
Copied: trunk/prototypes/java/test/org/openlcb/swing/memconfig/PackageTest.java (from rev 2192, trunk/prototypes/java/test/org/openlcb/swing/PackageTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/swing/memconfig/PackageTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/swing/memconfig/PackageTest.java 2012-05-13 18:38:07 UTC (rev 2201)
@@ -0,0 +1,37 @@
+package org.openlcb.swing.memconfig;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision$
+ */
+public class PackageTest extends TestCase {
+ public void testStart() {
+ }
+
+
+ // from here down is testing infrastructure
+
+ public PackageTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {PackageTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(PackageTest.class);
+ suite.addTest(MemConfigDescriptionPaneTest.suite());
+ suite.addTest(MemConfigReadWritePaneTest.suite());
+
+ return suite;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-14 06:43:38
|
Revision: 2203
http://openlcb.svn.sourceforge.net/openlcb/?rev=2203&view=rev
Author: jacobsen
Date: 2012-05-14 06:43:32 +0000 (Mon, 14 May 2012)
Log Message:
-----------
install reader
Added Paths:
-----------
trunk/prototypes/java/src/org/openlcb/cdi/jdom/CdiMemConfigReader.java
trunk/prototypes/java/test/org/openlcb/cdi/jdom/CdiMemConfigReaderTest.java
Copied: trunk/prototypes/java/src/org/openlcb/cdi/jdom/CdiMemConfigReader.java (from rev 2192, trunk/prototypes/java/src/org/openlcb/swing/NodeSelector.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/cdi/jdom/CdiMemConfigReader.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/cdi/jdom/CdiMemConfigReader.java 2012-05-14 06:43:32 UTC (rev 2203)
@@ -0,0 +1,74 @@
+// CdiMemConfigReader.java
+
+package org.openlcb.cdi.jdom;
+
+import javax.swing.*;
+import javax.swing.text.*;
+import java.beans.PropertyChangeListener;
+
+import org.openlcb.*;
+import org.openlcb.Utilities;
+import org.openlcb.implementations.*;
+
+/**
+ * Provide a Reader to the OpenLCB CDI in a node.
+ *
+ * This first implementation reads the entire data before providing the Reader
+ * by call back.
+ *
+ * @author Bob Jacobsen Copyright (C) 2012
+ * @version $Revision$
+ */
+public class CdiMemConfigReader {
+
+ final static int LENGTH = 64;
+ final static int SPACE = 0xFF;
+
+ NodeID node;
+ MimicNodeStore store;
+ MemoryConfigurationService service;
+
+ public CdiMemConfigReader(NodeID node, MimicNodeStore store, MemoryConfigurationService service) {
+ this.node = node;
+ this.store = store;
+ this.service = service;
+ }
+
+ long nextAddress = 0;
+ StringBuffer buf;
+
+ ReaderAccess retval;
+ public void startLoadReader(ReaderAccess retval) {
+ this.retval = retval;
+ nextAddress = 0;
+ buf = new StringBuffer();
+ nextRequest();
+ }
+
+ void nextRequest() {
+ MemoryConfigurationService.McsReadMemo memo =
+ new MemoryConfigurationService.McsReadMemo(node, SPACE, nextAddress, LENGTH) {
+ public void handleReadData(NodeID dest, int space, long address, byte[] data) {
+ System.out.println("read "+data.length+" bytes");
+ // handle return data, checking for null in string
+ for (int i = 0; i<data.length; i++) {
+ if (data[i] == 0) {
+ // done, return
+ if (retval != null)
+ retval.provideReader(new java.io.StringReader(new String(buf)));
+ return;
+ }
+ buf.append((char)data[i]);
+ }
+ // repeat if not done
+ nextAddress = nextAddress + LENGTH;
+ nextRequest();
+ }
+ };
+ service.request(memo);
+ }
+
+ public interface ReaderAccess {
+ public void provideReader(java.io.Reader r);
+ }
+}
Copied: trunk/prototypes/java/test/org/openlcb/cdi/jdom/CdiMemConfigReaderTest.java (from rev 2201, trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigDescriptionPaneTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/cdi/jdom/CdiMemConfigReaderTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/cdi/jdom/CdiMemConfigReaderTest.java 2012-05-14 06:43:32 UTC (rev 2203)
@@ -0,0 +1,117 @@
+package org.openlcb.cdi.jdom;
+
+import org.openlcb.*;
+import org.openlcb.implementations.*;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import javax.swing.*;
+/**
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision: 34 $
+ */
+public class CdiMemConfigReaderTest extends TestCase {
+
+ NodeID nidHere = new NodeID(new byte[]{0,0,0,0,0,1});
+ NodeID nidThere = new NodeID(new byte[]{0,0,0,0,0,2});
+
+ Connection connection = new AbstractConnection() {
+ public void put(Message msg, Connection sender) {}
+ };
+
+ MimicNodeStore store;
+ MemoryConfigurationService service;
+ int spaceCount;
+
+ DatagramService dgs;
+ String testString = "string to be checked which involves more than 64 characters, so its three datagrams at least, because two originally worked and perhaps three did not ";
+ byte[] content;
+
+ public void setUp() throws Exception {
+ store = new MimicNodeStore(connection, nidHere);
+ dgs = new DatagramService(null, null);
+
+ store.addNode(nidThere);
+
+ spaceCount = 0; // number sent so far
+ content = testString.getBytes();
+ content[content.length-1] = 0;
+
+ service = new MemoryConfigurationService(nidHere, dgs) {
+ public void request(MemoryConfigurationService.McsWriteMemo memo) {
+ }
+
+ public void request(MemoryConfigurationService.McsReadMemo memo) {
+ if ( spaceCount*64 >= content.length) return; // done
+
+ int space = 0xFD;
+ long address = 0;
+ byte[] data = new byte[Math.min(CdiMemConfigReader.LENGTH, content.length - CdiMemConfigReader.LENGTH*spaceCount)];
+
+ for (int i = 0; (i<CdiMemConfigReader.LENGTH) && ((i+spaceCount*CdiMemConfigReader.LENGTH)<content.length); i++)
+ data[i] = content[i+spaceCount*CdiMemConfigReader.LENGTH];
+
+ spaceCount++;
+ memo.handleReadData(nidThere, space, address, data);
+ }
+
+ public void request(MemoryConfigurationService.McsConfigMemo memo) {
+ }
+
+ public void request(MemoryConfigurationService.McsAddrSpaceMemo memo) {
+ }
+ };
+
+ }
+
+ public void tearDown() {
+ }
+
+ public void testSetup() {
+ // just calls setup & teardown
+ }
+
+ public void testCtor() {
+ CdiMemConfigReader cmcr = new CdiMemConfigReader(nidHere, store, service);
+ }
+ java.io.Reader rdr;
+ public void testCycle() throws java.io.IOException {
+ CdiMemConfigReader cmcr = new CdiMemConfigReader(nidHere, store, service);
+ CdiMemConfigReader.ReaderAccess a = new CdiMemConfigReader.ReaderAccess() {
+ public void provideReader(java.io.Reader r) {
+ rdr = r;
+ }
+ };
+
+ rdr = null;
+ cmcr.startLoadReader(a);
+ Assert.assertTrue(rdr != null);
+ Assert.assertEquals("1", testString.getBytes()[0], rdr.read());
+ Assert.assertEquals("2", testString.getBytes()[1], rdr.read());
+ int count = 2;
+ while (rdr.read() > 0) count++;
+ Assert.assertEquals("length", testString.length()-1, count); // -1 for trailing zero on input
+ }
+
+
+ // from here down is testing infrastructure
+
+ public CdiMemConfigReaderTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {CdiMemConfigReaderTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(CdiMemConfigReaderTest.class);
+ return suite;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-14 06:44:38
|
Revision: 2205
http://openlcb.svn.sourceforge.net/openlcb/?rev=2205&view=rev
Author: jacobsen
Date: 2012-05-14 06:44:32 +0000 (Mon, 14 May 2012)
Log Message:
-----------
with tests
Modified Paths:
--------------
trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigDescriptionPaneTest.java
trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigReadWritePaneTest.java
Added Paths:
-----------
trunk/prototypes/java/src/org/openlcb/swing/memconfig/MemConfigDescriptionPane.java
trunk/prototypes/java/src/org/openlcb/swing/memconfig/MemConfigReadWritePane.java
Copied: trunk/prototypes/java/src/org/openlcb/swing/memconfig/MemConfigDescriptionPane.java (from rev 2192, trunk/prototypes/java/src/org/openlcb/swing/NodeSelector.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/swing/memconfig/MemConfigDescriptionPane.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/swing/memconfig/MemConfigDescriptionPane.java 2012-05-14 06:44:32 UTC (rev 2205)
@@ -0,0 +1,91 @@
+// MemConfigDescriptionPane.java
+
+package org.openlcb.swing.memconfig;
+
+import javax.swing.*;
+import javax.swing.text.*;
+import java.beans.PropertyChangeListener;
+
+import org.openlcb.*;
+import org.openlcb.Utilities;
+import org.openlcb.implementations.*;
+
+/**
+ * Display the node's memory configuration capabilities
+ *
+ * @author Bob Jacobsen Copyright (C) 2012
+ * @version $Revision$
+ */
+public class MemConfigDescriptionPane extends JPanel {
+
+ NodeID node;
+ MimicNodeStore store;
+ MemoryConfigurationService service;
+
+ JLabel commandLabel = new JLabel(" ");
+ JLabel highSpaceLabel = new JLabel(" ");
+ JLabel lowSpaceLabel = new JLabel(" ");
+
+ public MemConfigDescriptionPane(NodeID node, MimicNodeStore store, MemoryConfigurationService service) {
+ this.node = node;
+ this.store = store;
+ this.service = service;
+
+ setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
+
+ addLine(commandLabel, "Commands:");
+ addLine(highSpaceLabel,"High Address Space:");
+ addLine(lowSpaceLabel, "Low Address Space:");
+ add(new JSeparator());
+ }
+
+ void addLine(JComponent j, String name) {
+ JPanel p = new JPanel();
+ p.setLayout(new java.awt.FlowLayout());
+ p.add(new JLabel(name));
+ p.add(j);
+ add(p);
+ }
+
+ /**
+ * To be invoked after Swing component installation is complete,
+ * as it drives display changes.
+ */
+ public void initComponents() {
+ // start by asking for basic config
+ MemoryConfigurationService.McsConfigMemo memo =
+ new MemoryConfigurationService.McsConfigMemo(node) {
+ public void handleConfigData(NodeID dest, int commands, int lengths, int highSpace, int lowSpace, String name) {
+ // fill window from values
+ commandLabel.setText("0x"+Utilities.toHexPair(commands>>8)+Utilities.toHexPair(commands));
+
+ highSpaceLabel.setText("0x"+Utilities.toHexPair(highSpace));
+ lowSpaceLabel.setText("0x"+Utilities.toHexPair(lowSpace));
+
+ // and start address space read
+ readSpace(dest, highSpace, lowSpace);
+ }
+ };
+ service.request(memo);
+
+ }
+
+ void readSpace(NodeID dest, final int highSpace, final int lowSpace) {
+ if (highSpace < lowSpace) return;
+ MemoryConfigurationService.McsAddrSpaceMemo memo =
+ new MemoryConfigurationService.McsAddrSpaceMemo(node, highSpace) {
+ public void handleConfigData(NodeID dest, int space, long hiAddress, long lowAddress, int flags, String desc) {
+ // new line with values
+ JPanel p = new JPanel();
+ p.setLayout(new java.awt.FlowLayout());
+ MemConfigDescriptionPane.this.add(p);
+ p.add(new JLabel("Space "+space+": "));
+ p.add(new JLabel("High address: 0x"+Long.toHexString(hiAddress).toUpperCase()));
+ // and read next space
+ readSpace(dest, highSpace-1, lowSpace);
+ }
+ };
+ service.request(memo);
+ }
+
+}
Copied: trunk/prototypes/java/src/org/openlcb/swing/memconfig/MemConfigReadWritePane.java (from rev 2192, trunk/prototypes/java/src/org/openlcb/swing/NodeSelector.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/swing/memconfig/MemConfigReadWritePane.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/swing/memconfig/MemConfigReadWritePane.java 2012-05-14 06:44:32 UTC (rev 2205)
@@ -0,0 +1,25 @@
+// MemConfigReadWritePane.java
+
+package org.openlcb.swing.memconfig;
+
+import javax.swing.*;
+import javax.swing.text.*;
+import java.beans.PropertyChangeListener;
+
+import org.openlcb.*;
+import org.openlcb.implementations.*;
+
+/**
+ * Provide read/write access to a node
+ *
+ * @author Bob Jacobsen Copyright (C) 2012
+ * @version $Revision$
+ */
+public class MemConfigReadWritePane extends JPanel {
+
+ MimicNodeStore store;
+ public MemConfigReadWritePane(MimicNodeStore store) {
+ this.store = store;
+ }
+
+}
Modified: trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigDescriptionPaneTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigDescriptionPaneTest.java 2012-05-14 06:43:55 UTC (rev 2204)
+++ trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigDescriptionPaneTest.java 2012-05-14 06:44:32 UTC (rev 2205)
@@ -32,20 +32,49 @@
};
MimicNodeStore store;
+ MemoryConfigurationService service;
+ int spaceCount;
+ DatagramService dgs;
+
+ MemConfigDescriptionPane pane;
+
public void setUp() throws Exception {
store = new MimicNodeStore(connection, nidHere);
+ dgs = new DatagramService(null, null);
+
store.addNode(nidThere);
+ spaceCount = 3;
+ service = new MemoryConfigurationService(nidHere, dgs) {
+ public void request(MemoryConfigurationService.McsWriteMemo memo) {
+ }
+
+ public void request(MemoryConfigurationService.McsReadMemo memo) {
+ }
+
+ public void request(MemoryConfigurationService.McsConfigMemo memo) {
+ // for test, call back immediately
+ memo.handleConfigData(nidThere, 0xFFFF, 0xFF, 0xFF, 0, "");
+ }
+
+ public void request(MemoryConfigurationService.McsAddrSpaceMemo memo) {
+ if (spaceCount-- > 0) memo.handleConfigData(nidThere, spaceCount, spaceCount*256, 0, 0, "");
+ }
+ };
+
// Test is really popping a window before doing all else
frame = new JFrame();
frame.setTitle("MemConfigDescriptionPane Test");
+ pane = new MemConfigDescriptionPane(nidThere, store, service);
+ frame.add(pane);
+
+ pane.initComponents();
+
frame.pack();
frame.setMinimumSize(new java.awt.Dimension(200,200));
frame.setVisible(true);
-
-
}
public void tearDown() {
@@ -53,6 +82,7 @@
}
public void testSetup() {
+
}
// from here down is testing infrastructure
Modified: trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigReadWritePaneTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigReadWritePaneTest.java 2012-05-14 06:43:55 UTC (rev 2204)
+++ trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigReadWritePaneTest.java 2012-05-14 06:44:32 UTC (rev 2205)
@@ -32,7 +32,8 @@
};
MimicNodeStore store;
-
+ MemConfigReadWritePane pane;
+
public void setUp() throws Exception {
store = new MimicNodeStore(connection, nidHere);
store.addNode(nidThere);
@@ -41,7 +42,11 @@
frame = new JFrame();
frame.setTitle("MemConfigReadWritePane Test");
+ pane = new MemConfigReadWritePane(store);
+ frame.add(pane);
+
frame.pack();
+ frame.pack();
frame.setMinimumSize(new java.awt.Dimension(200,200));
frame.setVisible(true);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-14 06:45:17
|
Revision: 2206
http://openlcb.svn.sourceforge.net/openlcb/?rev=2206&view=rev
Author: jacobsen
Date: 2012-05-14 06:45:10 +0000 (Mon, 14 May 2012)
Log Message:
-----------
update service for JMRI access
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/implementations/MemoryConfigurationService.java
trunk/prototypes/java/test/org/openlcb/implementations/MemoryConfigurationServiceTest.java
Modified: trunk/prototypes/java/src/org/openlcb/implementations/MemoryConfigurationService.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/MemoryConfigurationService.java 2012-05-14 06:44:32 UTC (rev 2205)
+++ trunk/prototypes/java/src/org/openlcb/implementations/MemoryConfigurationService.java 2012-05-14 06:45:10 UTC (rev 2206)
@@ -28,14 +28,39 @@
// connect to be notified of config service
downstream.registerForReceive(new DatagramService.DatagramServiceReceiveMemo(DATAGRAM_TYPE){
+ // does not allow for overlapping operations, either to a single node nor or multiple types
+ // nor to multiple nodes
+ //
+ // doesn't check for match of reply to memo, but eventually should.
public int handleData(NodeID dest, int[] data) {
- System.out.println("Received datagram of "+data.length+" from "+dest);
if (readMemo != null) {
byte[] content = new byte[data.length-6];
for (int i = 0; i<content.length; i++) content[i] = (byte)data[i+6];
- readMemo.handleReadData(dest, readMemo.space, readMemo.address, content);
+ McsReadMemo memo = readMemo;
+ readMemo = null;
+ memo.handleReadData(dest, memo.space, memo.address, content);
}
- readMemo = null;
+ if (configMemo != null) {
+ // doesn't handle decode of name string, but should
+ int commands = (data[2]<<8)+data[3];
+ int options = data[4];
+ int highSpace = data[5];
+ int lowSpace = data[6];
+ McsConfigMemo memo = configMemo;
+ configMemo = null;
+ memo.handleConfigData(dest, commands, options, highSpace, lowSpace,"");
+ }
+ if (addrSpaceMemo != null) {
+ // doesn't handle decode of desc string, but should
+ int space = data[2];
+ long highAddress = (data[3]<<24)+(data[4]<<16)+(data[5]<<8)+data[6];
+ int flags = data[7];
+ long lowAddress = 0; // doesn't handle optional value
+
+ McsAddrSpaceMemo memo = addrSpaceMemo;
+ addrSpaceMemo = null;
+ memo.handleConfigData(dest, space, highAddress, lowAddress, flags, "");
+ }
return 0;
}
});
@@ -58,7 +83,23 @@
ReadDatagramMemo dg = new ReadDatagramMemo(memo.dest, memo.space, memo.address, memo.count, memo);
downstream.sendData(dg);
}
+
+ McsConfigMemo configMemo;
+ public void request(McsConfigMemo memo) {
+ // forward as read Datagram
+ configMemo = memo;
+ ConfigDatagramMemo dg = new ConfigDatagramMemo(memo.dest, memo);
+ downstream.sendData(dg);
+ }
+ McsAddrSpaceMemo addrSpaceMemo;
+ public void request(McsAddrSpaceMemo memo) {
+ // forward as read Datagram
+ addrSpaceMemo = memo;
+ AddrSpaceDatagramMemo dg = new AddrSpaceDatagramMemo(memo.dest, memo);
+ downstream.sendData(dg);
+ }
+
@Immutable
@ThreadSafe
static public class McsReadMemo {
@@ -132,8 +173,6 @@
public void handleReply(int code) {
memo.handleWriteReply(code);
}
-
-
}
@Immutable
@@ -211,4 +250,117 @@
}
+ @Immutable
+ @ThreadSafe
+ static public class McsConfigMemo {
+ public McsConfigMemo(NodeID dest) {
+ this.dest = dest;
+ }
+
+ NodeID dest;
+
+ public boolean equals(Object o) {
+ if (o == null) return false;
+ if (! (o instanceof McsConfigMemo)) return false;
+ McsConfigMemo m = (McsConfigMemo) o;
+ return this.dest == m.dest;
+ }
+
+ public String toString() {
+ return "McsConfigMemo";
+ }
+
+ public int hashCode() { return dest.hashCode(); }
+
+ /**
+ * Overload this for notification of failure reply
+ * @param code non-zero for error reply
+ */
+ public void handleWriteReply(int code) {
+ }
+
+ /**
+ * Overload this for notification of data.
+ */
+ public void handleConfigData(NodeID dest, int commands, int options, int highSpace, int lowSpace, String name) {
+ }
+
+ }
+
+ @Immutable
+ @ThreadSafe
+ static public class ConfigDatagramMemo extends DatagramService.DatagramServiceTransmitMemo {
+ ConfigDatagramMemo(NodeID dest, McsConfigMemo memo) {
+ super(dest);
+ this.data = new int[2];
+ this.data[0] = DATAGRAM_TYPE;
+ this.data[1] = 0x80;
+ this.memo = memo;
+ }
+ McsConfigMemo memo;
+ public void handleReply(int code) {
+ memo.handleWriteReply(code);
+ }
+
+
+ }
+
+ @Immutable
+ @ThreadSafe
+ static public class McsAddrSpaceMemo {
+ public McsAddrSpaceMemo(NodeID dest, int space) {
+ this.dest = dest;
+ this.space = space;
+ }
+
+ NodeID dest;
+ int space;
+
+ public boolean equals(Object o) {
+ if (o == null) return false;
+ if (! (o instanceof McsAddrSpaceMemo)) return false;
+ McsAddrSpaceMemo m = (McsAddrSpaceMemo) o;
+ if (this.space != m.space) return false;
+ return this.dest == m.dest;
+ }
+
+ public String toString() {
+ return "McsAddrSpaceMemo "+space;
+ }
+
+ public int hashCode() { return dest.hashCode()+space; }
+
+ /**
+ * Overload this for notification of failure reply
+ * @param code non-zero for error reply
+ */
+ public void handleWriteReply(int code) {
+ }
+
+ /**
+ * Overload this for notification of data.
+ */
+ public void handleConfigData(NodeID dest, int space, long hiAddress, long lowAddress, int flags, String desc) {
+ }
+
+ }
+
+ @Immutable
+ @ThreadSafe
+ static public class AddrSpaceDatagramMemo extends DatagramService.DatagramServiceTransmitMemo {
+ AddrSpaceDatagramMemo(NodeID dest, McsAddrSpaceMemo memo) {
+ super(dest);
+ this.data = new int[3];
+ this.data[0] = DATAGRAM_TYPE;
+ this.data[1] = 0x84;
+ this.data[2] = memo.space;
+ this.memo = memo;
+ }
+ McsAddrSpaceMemo memo;
+ public void handleReply(int code) {
+ memo.handleWriteReply(code);
+ }
+
+
+ }
}
Modified: trunk/prototypes/java/test/org/openlcb/implementations/MemoryConfigurationServiceTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/MemoryConfigurationServiceTest.java 2012-05-14 06:44:32 UTC (rev 2205)
+++ trunk/prototypes/java/test/org/openlcb/implementations/MemoryConfigurationServiceTest.java 2012-05-14 06:45:10 UTC (rev 2206)
@@ -146,98 +146,191 @@
}
-// public void testReceiveDGbeforeReg() {
-// DatagramService.DatagramServiceReceiveMemo m20 =
-// new DatagramService.DatagramServiceReceiveMemo(0x20){
-// public int handleData(int[] data) {
-// flag = true;
-// return 0;
-// }
-// };
-//
-// Message m = new DatagramMessage(farID, hereID, new int[]{0x020});
-//
-// Assert.assertEquals(0,messagesReceived.size());
-//
-// Assert.assertTrue(!flag);
-// service.put(m, null);
-// Assert.assertTrue(!flag);
-//
-// Assert.assertEquals(1,messagesReceived.size());
-// Assert.assertTrue(messagesReceived.get(0) instanceof DatagramRejectedMessage);
-// }
-//
-// public void testReceiveFirstDG() {
-// DatagramService.DatagramServiceReceiveMemo m20 =
-// new DatagramService.DatagramServiceReceiveMemo(0x20){
-// public int handleData(int[] data) {
-// flag = true;
-// return 0;
-// }
-// };
-//
-// service.registerForReceive(m20);
-//
-// Message m = new DatagramMessage(farID, hereID, new int[]{0x020});
-//
-// Assert.assertTrue(!flag);
-// service.put(m, null);
-// Assert.assertTrue(flag);
-//
-// Assert.assertEquals(1,messagesReceived.size());
-// Assert.assertTrue(messagesReceived.get(0) instanceof DatagramAcknowledgedMessage);
-// }
-//
-// public void testReceiveWrongDGType() {
-// DatagramService.DatagramServiceReceiveMemo m20 =
-// new DatagramService.DatagramServiceReceiveMemo(0x20){
-// public int handleData(int[] data) {
-// flag = true;
-// return 0;
-// }
-// };
-//
-// service.registerForReceive(m20);
-//
-// Message m = new DatagramMessage(farID, hereID, new int[]{0x21});
-//
-// Assert.assertTrue(!flag);
-// service.put(m, null);
-// Assert.assertTrue(!flag);
-//
-// Assert.assertEquals(1,messagesReceived.size());
-// Assert.assertTrue(messagesReceived.get(0) instanceof DatagramRejectedMessage);
-// }
-//
-//
-// public void testSendOK() {
-// int[] data = new byte[]{1,2,3,4,5};
-// DatagramService.DatagramServiceTransmitMemo memo =
-// new DatagramService.DatagramServiceTransmitMemo(farID,data) {
-// public void handleReply(int code) {
-// flag = true;
-// }
-// };
-//
-// service.sendData(memo);
-//
-// Assert.assertEquals("init messages", 1, messagesReceived.size());
-// Assert.assertTrue(messagesReceived.get(0)
-// .equals(new DatagramMessage(hereID, farID, data)));
-//
-// // Accepted
-// Message m = new DatagramAcknowledgedMessage(farID, hereID);
-// messagesReceived = new java.util.ArrayList<Message>();
-//
-// Assert.assertTrue(!flag);
-// service.put(m, null);
-// Assert.assertTrue(flag);
-//
-// Assert.assertEquals("1st messages", 0, messagesReceived.size());
-//
-// }
+ public void testSimpleRead() {
+ int space = 0xFD;
+ long address = 0x12345678;
+ int length = 4;
+ MemoryConfigurationService.McsReadMemo memo =
+ new MemoryConfigurationService.McsReadMemo(farID, space, address, length) {
+ public void handleWriteReply(int code) {
+ flag = true;
+ }
+ public void handleReadData(NodeID dest, int space, long address, byte[] data) {
+ flag = true;
+ }
+ };
+
+ // test executes the callbacks instantly; real connections might not
+ Assert.assertTrue(!flag);
+ service.request(memo);
+ Assert.assertTrue(!flag);
+
+ // should have sent datagram
+ Assert.assertEquals(1,messagesReceived.size());
+ Assert.assertTrue(messagesReceived.get(0) instanceof DatagramMessage);
+
+ // check format of datagram read
+ int[] content = ((DatagramMessage)messagesReceived.get(0)).getData();
+ Assert.assertTrue(content.length >= 6);
+ Assert.assertEquals("datagram type", 0x20, content[0]);
+ Assert.assertEquals("read command", 0x40, (content[1]&0xFC));
+
+ Assert.assertEquals("address", address, ((long)content[2]<<24)+((long)content[3]<<16)+((long)content[4]<<8)+(long)content[5] );
+
+ if (space >= 0xFD) {
+ Assert.assertEquals("space bits", space&0x3, content[1]&0x3);
+ Assert.assertEquals("data length", length, content[6]);
+ } else {
+ Assert.assertEquals("space byte", space, content[6]);
+ Assert.assertEquals("data length", length, content[7]);
+ }
+
+ // datagram reply comes back
+ Message m = new DatagramAcknowledgedMessage(farID, hereID);
+
+ Assert.assertTrue(!flag);
+ datagramService.put(m, null);
+ Assert.assertTrue(flag);
+
+ // now return data
+ flag = false;
+ content[1] = content[1]|0x01;
+ // needs to have pseudo-data added to end of array
+ m = new DatagramMessage(farID, hereID, content);
+
+ Assert.assertTrue(!flag);
+ datagramService.put(m, null);
+ Assert.assertTrue(flag);
+
+ }
-
+ public void testConfigMemoIsRealClass() {
+ MemoryConfigurationService.McsConfigMemo m20 =
+ new MemoryConfigurationService.McsConfigMemo(farID);
+ MemoryConfigurationService.McsConfigMemo m20a =
+ new MemoryConfigurationService.McsConfigMemo(farID);
+ MemoryConfigurationService.McsConfigMemo m21 =
+ new MemoryConfigurationService.McsConfigMemo(hereID);
+
+ Assert.assertTrue(m20.equals(m20));
+ Assert.assertTrue(m20.equals(m20a));
+
+ Assert.assertTrue(!m20.equals(null));
+
+ Assert.assertTrue(!m20.equals(m21));
+
+ }
+
+ public void testGetConfig() {
+ MemoryConfigurationService.McsConfigMemo memo =
+ new MemoryConfigurationService.McsConfigMemo(farID) {
+ public void handleWriteReply(int code) {
+ flag = true;
+ }
+ public void handleConfigData(NodeID dest, int commands, int lengths, int highSpace, int lowSpace, String name) {
+ flag = true;
+ }
+ };
+
+ // test executes the callbacks instantly; real connections might not
+ Assert.assertTrue(!flag);
+ service.request(memo);
+ Assert.assertTrue(!flag);
+
+ // should have sent datagram
+ Assert.assertEquals(1,messagesReceived.size());
+ Assert.assertTrue(messagesReceived.get(0) instanceof DatagramMessage);
+
+ // check format of datagram read
+ int[] content = ((DatagramMessage)messagesReceived.get(0)).getData();
+ Assert.assertTrue(content.length == 2);
+ Assert.assertEquals("datagram type", 0x20, content[0]);
+ Assert.assertEquals("read command", 0x80, (content[1]&0xFC));
+
+ // datagram reply comes back
+ Message m = new DatagramAcknowledgedMessage(farID, hereID);
+
+ Assert.assertTrue(!flag);
+ datagramService.put(m, null);
+ Assert.assertTrue(flag);
+
+ // now return data
+ flag = false;
+ content = new int[]{0x20, 0x81, 0x55, 0x55, 0xEE, 0xFF, 0x80, 'a', 'b', 'c'};
+ m = new DatagramMessage(farID, hereID, content);
+
+ Assert.assertTrue(!flag);
+ datagramService.put(m, null);
+ Assert.assertTrue(flag);
+
+ }
+
+ public void testAddrSpaceMemoIsRealClass() {
+ MemoryConfigurationService.McsAddrSpaceMemo m20 =
+ new MemoryConfigurationService.McsAddrSpaceMemo(farID,0xFD);
+ MemoryConfigurationService.McsAddrSpaceMemo m20a =
+ new MemoryConfigurationService.McsAddrSpaceMemo(farID,0xFD);
+ MemoryConfigurationService.McsAddrSpaceMemo m22 =
+ new MemoryConfigurationService.McsAddrSpaceMemo(farID,0xFE);
+ MemoryConfigurationService.McsAddrSpaceMemo m23 =
+ new MemoryConfigurationService.McsAddrSpaceMemo(hereID,0xFD);
+
+ Assert.assertTrue(m20.equals(m20));
+ Assert.assertTrue(m20.equals(m20a));
+
+ Assert.assertTrue(!m20.equals(null));
+
+ Assert.assertTrue(!m20.equals(m22));
+ Assert.assertTrue(!m20.equals(m23));
+
+ }
+
+ public void testGetAddrSpace() {
+ int space = 0xFD;
+ MemoryConfigurationService.McsAddrSpaceMemo memo =
+ new MemoryConfigurationService.McsAddrSpaceMemo(farID, space) {
+ public void handleWriteReply(int code) {
+ flag = true;
+ }
+ public void handleConfigData(NodeID dest, int space, long hiAddress, long lowAddress, int flags, String desc) {
+ flag = true;
+ }
+ };
+
+ // test executes the callbacks instantly; real connections might not
+ Assert.assertTrue(!flag);
+ service.request(memo);
+ Assert.assertTrue(!flag);
+
+ // should have sent datagram
+ Assert.assertEquals(1,messagesReceived.size());
+ Assert.assertTrue(messagesReceived.get(0) instanceof DatagramMessage);
+
+ // check format of datagram read
+ int[] content = ((DatagramMessage)messagesReceived.get(0)).getData();
+ Assert.assertTrue(content.length == 3);
+ Assert.assertEquals("datagram type", 0x20, content[0]);
+ Assert.assertEquals("addr space command", 0x84, (content[1]&0xFC));
+ Assert.assertEquals("space", space, (content[2]));
+
+ // datagram reply comes back
+ Message m = new DatagramAcknowledgedMessage(farID, hereID);
+
+ Assert.assertTrue(!flag);
+ datagramService.put(m, null);
+ Assert.assertTrue(flag);
+
+ // now return data
+ flag = false;
+ content = new int[]{0x20, 0x85, space, 0x12, 0x34, 0x56, 0x78, 0x55};
+ m = new DatagramMessage(farID, hereID, content);
+
+ Assert.assertTrue(!flag);
+ datagramService.put(m, null);
+ Assert.assertTrue(flag);
+
+ }
+
// from here down is testing infrastructure
public MemoryConfigurationServiceTest(String s) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-14 06:45:46
|
Revision: 2207
http://openlcb.svn.sourceforge.net/openlcb/?rev=2207&view=rev
Author: jacobsen
Date: 2012-05-14 06:45:37 +0000 (Mon, 14 May 2012)
Log Message:
-----------
0.4.7 implementation
Modified Paths:
--------------
trunk/prototypes/java/manifest
trunk/prototypes/java/openlcb-demo.jar
trunk/prototypes/java/openlcb.jar
Modified: trunk/prototypes/java/manifest
===================================================================
--- trunk/prototypes/java/manifest 2012-05-14 06:45:10 UTC (rev 2206)
+++ trunk/prototypes/java/manifest 2012-05-14 06:45:37 UTC (rev 2207)
@@ -7,6 +7,6 @@
Specification-Version: \xD20.4.2\xD3
Specification-Vendor: \xD2OpenLCB group"
Package-Title: \xD2openlcb\xD3
-Package-Version: \xD20.4.6\xD3
+Package-Version: \xD20.4.7\xD3
Package-Vendor: \xD2OpenLCB group\xD3
Modified: trunk/prototypes/java/openlcb-demo.jar
===================================================================
(Binary files differ)
Modified: trunk/prototypes/java/openlcb.jar
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-16 19:19:16
|
Revision: 2221
http://openlcb.svn.sourceforge.net/openlcb/?rev=2221&view=rev
Author: jacobsen
Date: 2012-05-16 19:19:10 +0000 (Wed, 16 May 2012)
Log Message:
-----------
FindBugs
Modified Paths:
--------------
trunk/prototypes/java/build.xml
trunk/prototypes/java/nbproject/project.xml
trunk/prototypes/java/test/simulations/NodeIDCollisions.java
Added Paths:
-----------
trunk/prototypes/java/nbproject/findbugs.settings
Modified: trunk/prototypes/java/build.xml
===================================================================
--- trunk/prototypes/java/build.xml 2012-05-16 00:27:08 UTC (rev 2220)
+++ trunk/prototypes/java/build.xml 2012-05-16 19:19:10 UTC (rev 2221)
@@ -66,22 +66,6 @@
<target name="compile" depends="init, copyfiles" description="compile source, omitting tests">
<!-- Compile the java code from ${source} into ${target} -->
<javac srcdir="${source}"
- destdir="${target}"
- source="${source_version}"
- target="${jre_version}"
- fork="true"
- includeantruntime="false"
- memoryinitialsize="256m"
- memorymaximumsize="256m"
- deprecation="${deprecation}"
- debug="no" >
- <classpath refid="project.class.path" />
- </javac>
- </target>
-
- <target name="debug" depends="init, copyfiles" description="compile source with debugging on, omitting tests">
- <!-- Compile the java code from ${source} into ${target} -->
- <javac srcdir="${source}"
destdir="${target}"
source="${source_version}"
target="${jre_version}"
@@ -97,7 +81,7 @@
</javac>
</target>
- <target name="tests" depends="debug" description="compile test classes">
+ <target name="tests" depends="compile" description="compile test classes">
<!-- Compile the test java code from ${source} into ${target} -->
<copy todir="${target}">
<fileset dir="test/" includes="**/*.properties" />
@@ -116,7 +100,7 @@
</javac>
</target>
- <target name="run" depends="debug, tests" description="build and run test suite">
+ <target name="run" depends="compile, tests" description="build and run test suite">
<java classname="AllTest"
dir=".."
fork="yes" >
@@ -126,7 +110,7 @@
</java>
</target>
- <target name="bg" depends="debug, tests" description="build and run Blue/Gold test">
+ <target name="bg" depends="compile, tests" description="build and run Blue/Gold test">
<java classname="scenarios.BlueGoldCheck"
dir=".."
fork="yes" >
Added: trunk/prototypes/java/nbproject/findbugs.settings
===================================================================
--- trunk/prototypes/java/nbproject/findbugs.settings (rev 0)
+++ trunk/prototypes/java/nbproject/findbugs.settings 2012-05-16 19:19:10 UTC (rev 2221)
@@ -0,0 +1,244 @@
+#FindBugs User Preferences
+#Wed May 16 11:55:54 PDT 2012
+detectorAbnormalFinallyBlockReturn=AbnormalFinallyBlockReturn|false
+detectorAbstractClassEmptyMethods=AbstractClassEmptyMethods|false
+detectorAbstractOverriddenMethod=AbstractOverriddenMethod|false
+detectorAppendingToAnObjectOutputStream=AppendingToAnObjectOutputStream|true
+detectorArrayBasedCollections=ArrayBasedCollections|false
+detectorArrayWrappedCallByReference=ArrayWrappedCallByReference|false
+detectorBCPMethodReturnCheck=BCPMethodReturnCheck|false
+detectorBadAppletConstructor=BadAppletConstructor|false
+detectorBadResultSetAccess=BadResultSetAccess|true
+detectorBadSyntaxForRegularExpression=BadSyntaxForRegularExpression|true
+detectorBadUseOfReturnValue=BadUseOfReturnValue|true
+detectorBadlyOverriddenAdapter=BadlyOverriddenAdapter|true
+detectorBloatedAssignmentScope=BloatedAssignmentScope|false
+detectorBloatedSynchronizedBlock=BloatedSynchronizedBlock|false
+detectorBogusExceptionDeclaration=BogusExceptionDeclaration|false
+detectorBooleanReturnNull=BooleanReturnNull|true
+detectorBuildInterproceduralCallGraph=BuildInterproceduralCallGraph|false
+detectorBuildObligationPolicyDatabase=BuildObligationPolicyDatabase|true
+detectorCallToUnsupportedMethod=CallToUnsupportedMethod|false
+detectorCalledMethods=CalledMethods|true
+detectorCheckCalls=CheckCalls|false
+detectorCheckExpectedWarnings=CheckExpectedWarnings|false
+detectorCheckImmutableAnnotation=CheckImmutableAnnotation|true
+detectorCheckTypeQualifiers=CheckTypeQualifiers|true
+detectorClassEnvy=ClassEnvy|false
+detectorCloneIdiom=CloneIdiom|true
+detectorCollectStatistics=CollectStatistics|false
+detectorComparatorIdiom=ComparatorIdiom|true
+detectorConfusedInheritance=ConfusedInheritance|true
+detectorConfusingAutoboxedOverloading=ConfusingAutoboxedOverloading|false
+detectorConfusingFunctionSemantics=ConfusingFunctionSemantics|false
+detectorConfusionBetweenInheritedAndOuterMethod=ConfusionBetweenInheritedAndOuterMethod|true
+detectorConstantListIndex=ConstantListIndex|false
+detectorCopiedOverriddenMethod=CopiedOverriddenMethod|false
+detectorCrossSiteScripting=CrossSiteScripting|true
+detectorCustomBuiltXML=CustomBuiltXML|false
+detectorCyclomaticComplexity=CyclomaticComplexity|false
+detectorDateComparison=DateComparison|false
+detectorDeclaredRuntimeException=DeclaredRuntimeException|false
+detectorDeletingWhileIterating=DeletingWhileIterating|false
+detectorDeprecatedTypesafeEnumPattern=DeprecatedTypesafeEnumPattern|false
+detectorDoInsideDoPrivileged=DoInsideDoPrivileged|true
+detectorDontCatchIllegalMonitorStateException=DontCatchIllegalMonitorStateException|true
+detectorDontIgnoreResultOfPutIfAbsent=DontIgnoreResultOfPutIfAbsent|true
+detectorDontUseEnum=DontUseEnum|true
+detectorDroppedException=DroppedException|true
+detectorDubiousListCollection=DubiousListCollection|false
+detectorDubiousSetOfCollections=DubiousSetOfCollections|false
+detectorDumbMethodInvocations=DumbMethodInvocations|true
+detectorDumbMethods=DumbMethods|true
+detectorDuplicateBranches=DuplicateBranches|true
+detectorEmptyZipFileEntry=EmptyZipFileEntry|true
+detectorEqStringTest=EqStringTest|false
+detectorEqualsOperandShouldHaveClassCompatibleWithThis=EqualsOperandShouldHaveClassCompatibleWithThis|true
+detectorExceptionSoftening=ExceptionSoftening|false
+detectorFieldCouldBeLocal=FieldCouldBeLocal|false
+detectorFieldItemSummary=FieldItemSummary|true
+detectorFinalParameters=FinalParameters|false
+detectorFinalizerNullsFields=FinalizerNullsFields|true
+detectorFindBadCast=FindBadCast|false
+detectorFindBadCast2=FindBadCast2|true
+detectorFindBadEqualsImplementation=FindBadEqualsImplementation|false
+detectorFindBadForLoop=FindBadForLoop|true
+detectorFindBugsSummaryStats=FindBugsSummaryStats|true
+detectorFindCircularDependencies=FindCircularDependencies|false
+detectorFindDeadLocalStores=FindDeadLocalStores|true
+detectorFindDoubleCheck=FindDoubleCheck|true
+detectorFindEmptySynchronizedBlock=FindEmptySynchronizedBlock|true
+detectorFindFieldSelfAssignment=FindFieldSelfAssignment|true
+detectorFindFinalizeInvocations=FindFinalizeInvocations|true
+detectorFindFloatEquality=FindFloatEquality|true
+detectorFindFloatMath=FindFloatMath|false
+detectorFindHEmismatch=FindHEmismatch|true
+detectorFindInconsistentSync2=FindInconsistentSync2|true
+detectorFindJSR166LockMonitorenter=FindJSR166LockMonitorenter|true
+detectorFindLocalSelfAssignment2=FindLocalSelfAssignment2|true
+detectorFindMaskedFields=FindMaskedFields|true
+detectorFindMismatchedWaitOrNotify=FindMismatchedWaitOrNotify|true
+detectorFindNakedNotify=FindNakedNotify|true
+detectorFindNonSerializableStoreIntoSession=FindNonSerializableStoreIntoSession|true
+detectorFindNonSerializableValuePassedToWriteObject=FindNonSerializableValuePassedToWriteObject|true
+detectorFindNonShortCircuit=FindNonShortCircuit|true
+detectorFindNullDeref=FindNullDeref|true
+detectorFindNullDerefsInvolvingNonShortCircuitEvaluation=FindNullDerefsInvolvingNonShortCircuitEvaluation|true
+detectorFindOpenStream=FindOpenStream|true
+detectorFindPuzzlers=FindPuzzlers|true
+detectorFindRefComparison=FindRefComparison|true
+detectorFindReturnRef=FindReturnRef|true
+detectorFindRunInvocations=FindRunInvocations|true
+detectorFindSelfComparison=FindSelfComparison|true
+detectorFindSelfComparison2=FindSelfComparison2|true
+detectorFindSleepWithLockHeld=FindSleepWithLockHeld|true
+detectorFindSpinLoop=FindSpinLoop|true
+detectorFindSqlInjection=FindSqlInjection|true
+detectorFindTwoLockWait=FindTwoLockWait|true
+detectorFindUncalledPrivateMethods=FindUncalledPrivateMethods|true
+detectorFindUnconditionalWait=FindUnconditionalWait|true
+detectorFindUninitializedGet=FindUninitializedGet|true
+detectorFindUnrelatedTypesInGenericContainer=FindUnrelatedTypesInGenericContainer|true
+detectorFindUnreleasedLock=FindUnreleasedLock|true
+detectorFindUnsatisfiedObligation=FindUnsatisfiedObligation|true
+detectorFindUnsyncGet=FindUnsyncGet|true
+detectorFindUselessControlFlow=FindUselessControlFlow|true
+detectorFloatingPointLoops=FloatingPointLoops|false
+detectorFormatStringChecker=FormatStringChecker|true
+detectorHugeSharedStringConstants=HugeSharedStringConstants|true
+detectorIDivResultCastToDouble=IDivResultCastToDouble|true
+detectorInappropriateToStringUse=InappropriateToStringUse|false
+detectorIncompatMask=IncompatMask|true
+detectorInconsistentAnnotations=InconsistentAnnotations|true
+detectorIncorrectInternalClassUse=IncorrectInternalClassUse|false
+detectorInefficientMemberAccess=InefficientMemberAccess|false
+detectorInefficientStringBuffering=InefficientStringBuffering|false
+detectorInefficientToArray=InefficientToArray|true
+detectorInfiniteLoop=InfiniteLoop|true
+detectorInfiniteRecursiveLoop=InfiniteRecursiveLoop|true
+detectorInfiniteRecursiveLoop2=InfiniteRecursiveLoop2|false
+detectorInheritanceTypeChecking=InheritanceTypeChecking|false
+detectorInheritanceUnsafeGetResource=InheritanceUnsafeGetResource|true
+detectorInitializationChain=InitializationChain|true
+detectorInstantiateStaticClass=InstantiateStaticClass|true
+detectorInvalidJUnitTest=InvalidJUnitTest|true
+detectorIteratorIdioms=IteratorIdioms|true
+detectorJDBCVendorReliance=JDBCVendorReliance|false
+detectorJUnitAssertionOddities=JUnitAssertionOddities|false
+detectorLazyInit=LazyInit|true
+detectorListIndexedIterating=ListIndexedIterating|false
+detectorLiteralStringComparison=LiteralStringComparison|false
+detectorLoadOfKnownNullValue=LoadOfKnownNullValue|true
+detectorLocalSynchronizedCollection=LocalSynchronizedCollection|false
+detectorLockedFields=LockedFields|false
+detectorLoggerOddities=LoggerOddities|false
+detectorLostExceptionStackTrace=LostExceptionStackTrace|false
+detectorLostLoggerDueToWeakReference=LostLoggerDueToWeakReference|true
+detectorManualArrayCopy=ManualArrayCopy|false
+detectorMethodReturnCheck=MethodReturnCheck|true
+detectorMethodReturnsConstant=MethodReturnsConstant|false
+detectorMethods=Methods|true
+detectorMisleadingOverloadModel=MisleadingOverloadModel|false
+detectorMultithreadedInstanceAccess=MultithreadedInstanceAccess|true
+detectorMutableLock=MutableLock|true
+detectorMutableStaticFields=MutableStaticFields|true
+detectorNaming=Naming|true
+detectorNeedlessAutoboxing=NeedlessAutoboxing|false
+detectorNeedlessCustomSerialization=NeedlessCustomSerialization|false
+detectorNeedlessInstanceRetrieval=NeedlessInstanceRetrieval|false
+detectorNeedlessMemberCollectionSynchronization=NeedlessMemberCollectionSynchronization|false
+detectorNoise=Noise|false
+detectorNoiseNullDeref=NoiseNullDeref|false
+detectorNonCollectionMethodUse=NonCollectionMethodUse|false
+detectorNonOwnedSynchronization=NonOwnedSynchronization|false
+detectorNonRecycleableTaglibs=NonRecycleableTaglibs|false
+detectorNoteAnnotationRetention=NoteAnnotationRetention|true
+detectorNoteCheckReturnValue=NoteCheckReturnValue|true
+detectorNoteCheckReturnValueAnnotations=NoteCheckReturnValueAnnotations|true
+detectorNoteDirectlyRelevantTypeQualifiers=NoteDirectlyRelevantTypeQualifiers|true
+detectorNoteJCIPAnnotation=NoteJCIPAnnotation|true
+detectorNoteNonNullAnnotations=NoteNonNullAnnotations|true
+detectorNoteNonnullReturnValues=NoteNonnullReturnValues|true
+detectorNoteSuppressedWarnings=NoteSuppressedWarnings|true
+detectorNoteUnconditionalParamDerefs=NoteUnconditionalParamDerefs|true
+detectorNumberConstructor=NumberConstructor|true
+detectorOrphanedDOMNode=OrphanedDOMNode|false
+detectorOverlyConcreteParameter=OverlyConcreteParameter|false
+detectorOverridingEqualsNotSymmetrical=OverridingEqualsNotSymmetrical|true
+detectorParallelLists=ParallelLists|false
+detectorPartiallyConstructedObjectAccess=PartiallyConstructedObjectAccess|false
+detectorPossibleIncompleteSerialization=PossibleIncompleteSerialization|false
+detectorPossibleMemoryBloat=PossibleMemoryBloat|false
+detectorPossiblyRedundantMethodCalls=PossiblyRedundantMethodCalls|false
+detectorPreferZeroLengthArrays=PreferZeroLengthArrays|true
+detectorPublicSemaphores=PublicSemaphores|false
+detectorQuestionableBooleanAssignment=QuestionableBooleanAssignment|true
+detectorReadOfInstanceFieldInMethodInvokedByConstructorInSuperclass=ReadOfInstanceFieldInMethodInvokedByConstructorInSuperclass|true
+detectorReadReturnShouldBeChecked=ReadReturnShouldBeChecked|true
+detectorRedundantInterfaces=RedundantInterfaces|true
+detectorReflectiveClasses=ReflectiveClasses|true
+detectorRepeatedConditionals=RepeatedConditionals|true
+detectorResolveAllReferences=ResolveAllReferences|false
+detectorRuntimeExceptionCapture=RuntimeExceptionCapture|true
+detectorSQLInLoop=SQLInLoop|false
+detectorSection508Compliance=Section508Compliance|false
+detectorSerializableIdiom=SerializableIdiom|true
+detectorSillynessPotPourri=SillynessPotPourri|false
+detectorSloppyClassReflection=SloppyClassReflection|false
+detectorSluggishGui=SluggishGui|false
+detectorSpoiledChildInterfaceImplementor=SpoiledChildInterfaceImplementor|false
+detectorSpuriousThreadStates=SpuriousThreadStates|false
+detectorStartInConstructor=StartInConstructor|true
+detectorStaticArrayCreatedInMethod=StaticArrayCreatedInMethod|false
+detectorStaticCalendarDetector=StaticCalendarDetector|true
+detectorStaticMethodInstanceInvocation=StaticMethodInstanceInvocation|false
+detectorStringConcatenation=StringConcatenation|true
+detectorStutteredMethodArguments=StutteredMethodArguments|false
+detectorSuperfluousInstanceOf=SuperfluousInstanceOf|true
+detectorSuspiciousCloneAlgorithm=SuspiciousCloneAlgorithm|false
+detectorSuspiciousClusteredSessionSupport=SuspiciousClusteredSessionSupport|false
+detectorSuspiciousComparatorReturnValues=SuspiciousComparatorReturnValues|false
+detectorSuspiciousJDKVersionUse=SuspiciousJDKVersionUse|false
+detectorSuspiciousThreadInterrupted=SuspiciousThreadInterrupted|true
+detectorSuspiciousUninitializedArray=SuspiciousUninitializedArray|false
+detectorSuspiciousWaitOnConcurrentObject=SuspiciousWaitOnConcurrentObject|false
+detectorSwitchFallthrough=SwitchFallthrough|true
+detectorSyncCollectionIterators=SyncCollectionIterators|false
+detectorSynchronizationOnSharedBuiltinConstant=SynchronizationOnSharedBuiltinConstant|true
+detectorSynchronizeAndNullCheckField=SynchronizeAndNullCheckField|true
+detectorSynchronizeOnClassLiteralNotGetClass=SynchronizeOnClassLiteralNotGetClass|true
+detectorSynchronizingOnContentsOfFieldToProtectField=SynchronizingOnContentsOfFieldToProtectField|true
+detectorTailRecursion=TailRecursion|false
+detectorTestASM=TestASM|false
+detectorTestDataflowAnalysis=TestDataflowAnalysis|false
+detectorTestingGround=TestingGround|false
+detectorTrainFieldStoreTypes=TrainFieldStoreTypes|true
+detectorTrainNonNullAnnotations=TrainNonNullAnnotations|true
+detectorTrainUnconditionalDerefParams=TrainUnconditionalDerefParams|true
+detectorTristateBooleanPattern=TristateBooleanPattern|false
+detectorURLProblems=URLProblems|true
+detectorUncallableMethodOfAnonymousClass=UncallableMethodOfAnonymousClass|true
+detectorUnnecessaryMath=UnnecessaryMath|true
+detectorUnnecessaryNewNullCheck=UnnecessaryNewNullCheck|false
+detectorUnnecessaryStoreBeforeReturn=UnnecessaryStoreBeforeReturn|false
+detectorUnreadFields=UnreadFields|true
+detectorUnrelatedCollectionContents=UnrelatedCollectionContents|false
+detectorUnrelatedReturnValues=UnrelatedReturnValues|false
+detectorUseAddAll=UseAddAll|false
+detectorUseCharacterParameterizedMethod=UseCharacterParameterizedMethod|false
+detectorUseEnumCollections=UseEnumCollections|false
+detectorUseObjectEquals=UseObjectEquals|false
+detectorUseSplit=UseSplit|false
+detectorUseToArray=UseToArray|false
+detectorUselessSubclassMethod=UselessSubclassMethod|false
+detectorVarArgsProblems=VarArgsProblems|true
+detectorVolatileUsage=VolatileUsage|true
+detectorWaitInLoop=WaitInLoop|true
+detectorWeakExceptionMessaging=WeakExceptionMessaging|false
+detectorWrongMapIterator=WrongMapIterator|true
+detectorXMLFactoryBypass=XMLFactoryBypass|true
+detector_threshold=2
+effort=default
+filter_settings=Medium|BAD_PRACTICE,CORRECTNESS,EXPERIMENTAL,I18N,MALICIOUS_CODE,MT_CORRECTNESS,PERFORMANCE,SECURITY,STYLE|false
+filter_settings_neg=NOISE|
+run_at_full_build=true
Modified: trunk/prototypes/java/nbproject/project.xml
===================================================================
--- trunk/prototypes/java/nbproject/project.xml 2012-05-16 00:27:08 UTC (rev 2220)
+++ trunk/prototypes/java/nbproject/project.xml 2012-05-16 19:19:10 UTC (rev 2221)
@@ -30,7 +30,7 @@
</folders>
<ide-actions>
<action name="build">
- <target>debug</target>
+ <target>compile</target>
</action>
<action name="clean">
<target>clean</target>
@@ -49,7 +49,7 @@
</action>
<action name="rebuild">
<target>clean</target>
- <target>tests</target>
+ <target>compile</target>
</action>
<action name="compile.single">
<script>nbproject/ide-file-targets.xml</script>
@@ -85,12 +85,12 @@
<export>
<type>folder</type>
<location>classes</location>
- <build-target>debug</build-target>
+ <build-target>compile</build-target>
</export>
<export>
<type>folder</type>
<location>classes</location>
- <build-target>debug</build-target>
+ <build-target>compile</build-target>
</export>
<view>
<items>
@@ -108,12 +108,12 @@
</items>
<context-menu>
<ide-action name="build"/>
+ <ide-action name="rebuild"/>
<ide-action name="clean"/>
<ide-action name="javadoc"/>
<ide-action name="run"/>
+ <ide-action name="test"/>
<ide-action name="profile"/>
- <ide-action name="test"/>
- <ide-action name="rebuild"/>
<ide-action name="debug"/>
<action>
<label>Make Jar File</label>
Modified: trunk/prototypes/java/test/simulations/NodeIDCollisions.java
===================================================================
--- trunk/prototypes/java/test/simulations/NodeIDCollisions.java 2012-05-16 00:27:08 UTC (rev 2220)
+++ trunk/prototypes/java/test/simulations/NodeIDCollisions.java 2012-05-16 19:19:10 UTC (rev 2221)
@@ -52,8 +52,9 @@
^ ((id[3]^id[4]^id[5])<<8);
// prototype v3: xor 3 16-bit quantities
- reg = (id[0]<<8 | id[1]) ^ (id[2]<<8 | id[3])
- ^ (id[4]<<8 | id[5]);
+ reg = ( ((id[0]<<8) & 0xFF) | (id[1] & 0xFF) )
+ ^ ( ((id[2]<<8) & 0xFF) | (id[3] & 0xFF) )
+ ^ ( ((id[4]<<8) & 0xFF) | (id[5] & 0xFF) );
// first step
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-16 19:19:52
|
Revision: 2222
http://openlcb.svn.sourceforge.net/openlcb/?rev=2222&view=rev
Author: jacobsen
Date: 2012-05-16 19:19:46 +0000 (Wed, 16 May 2012)
Log Message:
-----------
add string tool, tests
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/Utilities.java
Added Paths:
-----------
trunk/prototypes/java/test/org/openlcb/UtilitiesTest.java
Modified: trunk/prototypes/java/src/org/openlcb/Utilities.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/Utilities.java 2012-05-16 19:19:10 UTC (rev 2221)
+++ trunk/prototypes/java/src/org/openlcb/Utilities.java 2012-05-16 19:19:46 UTC (rev 2222)
@@ -22,4 +22,16 @@
String retval = "00"+Integer.toHexString(i).toUpperCase();
return retval.substring(retval.length()-2);
}
+
+ @CheckReturnValue
+ @NonNull
+ static public String toHexSpaceString(int[] array) {
+ StringBuffer buff = new StringBuffer();
+ for (int i = 0; i < array.length; i++) {
+ buff.append(" ");
+ buff.append(Utilities.toHexPair(array[i]));
+ }
+ String retval = new String(buff);
+ return retval.substring(1);
+ }
}
Copied: trunk/prototypes/java/test/org/openlcb/UtilitiesTest.java (from rev 2192, trunk/prototypes/java/test/org/openlcb/NodeIDTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/UtilitiesTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/UtilitiesTest.java 2012-05-16 19:19:46 UTC (rev 2222)
@@ -0,0 +1,47 @@
+package org.openlcb;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * @author Bob Jacobsen Copyright 2009
+ * @version $Revision$
+ */
+public class UtilitiesTest extends TestCase {
+
+ public void testZeroString() {
+ Assert.assertEquals("00", Utilities.toHexPair(0));
+ }
+
+ public void testHexAE() {
+ Assert.assertEquals("AE", Utilities.toHexPair(0xAE));
+ }
+
+ public void testHex0A() {
+ Assert.assertEquals("0A", Utilities.toHexPair(0xA));
+ }
+
+ public void testArray1() {
+ Assert.assertEquals("0A 0B 12", Utilities.toHexSpaceString(new int[]{0x0A, 0x0B, 0x12}));
+ }
+
+ // from here down is testing infrastructure
+
+ public UtilitiesTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {UtilitiesTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(UtilitiesTest.class);
+ return suite;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-17 06:05:25
|
Revision: 2226
http://openlcb.svn.sourceforge.net/openlcb/?rev=2226&view=rev
Author: jacobsen
Date: 2012-05-17 06:05:19 +0000 (Thu, 17 May 2012)
Log Message:
-----------
more netbeans/ant tuning
Modified Paths:
--------------
trunk/prototypes/java/build.xml
trunk/prototypes/java/nbproject/ide-file-targets.xml
Modified: trunk/prototypes/java/build.xml
===================================================================
--- trunk/prototypes/java/build.xml 2012-05-17 04:26:54 UTC (rev 2225)
+++ trunk/prototypes/java/build.xml 2012-05-17 06:05:19 UTC (rev 2226)
@@ -163,7 +163,7 @@
<target name="jars" description="create working jar files with current contents">
<antcall target="clean" />
- <antcall target="debug" />
+ <antcall target="compile" />
<jar jarfile="${jartarget}/openlcb.jar"
basedir="${target}"
manifest="manifest"
Modified: trunk/prototypes/java/nbproject/ide-file-targets.xml
===================================================================
--- trunk/prototypes/java/nbproject/ide-file-targets.xml 2012-05-17 04:26:54 UTC (rev 2225)
+++ trunk/prototypes/java/nbproject/ide-file-targets.xml 2012-05-17 06:05:19 UTC (rev 2226)
@@ -15,7 +15,7 @@
<target name="run-selected-file-in-test">
<fail unless="run.class">Must set property 'run.class'</fail>
<ant antfile="build.xml" inheritall="false">
- <target name="debug"/>
+ <target name="compile"/>
<target name="tests"/>
</ant>
<java classname="${run.class}" failonerror="true" fork="true">
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-17 07:17:28
|
Revision: 2231
http://openlcb.svn.sourceforge.net/openlcb/?rev=2231&view=rev
Author: jacobsen
Date: 2012-05-17 07:17:19 +0000 (Thu, 17 May 2012)
Log Message:
-----------
add from-string ctor
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/EventID.java
trunk/prototypes/java/test/org/openlcb/EventIDTest.java
Modified: trunk/prototypes/java/src/org/openlcb/EventID.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/EventID.java 2012-05-17 07:16:52 UTC (rev 2230)
+++ trunk/prototypes/java/src/org/openlcb/EventID.java 2012-05-17 07:17:19 UTC (rev 2231)
@@ -39,6 +39,18 @@
this.contents[i] = contents[i];
}
+ @CheckReturnValue
+ public EventID(@NonNull String value) {
+ if (value == null)
+ throw new java.lang.IllegalArgumentException("null argument invalid");
+ byte[] contents = org.openlcb.Utilities.bytesFromHexString(value);
+ if (contents.length != BYTECOUNT)
+ throw new java.lang.IllegalArgumentException("Wrong EventID length: "+contents.length);
+ this.contents = new byte[BYTECOUNT];
+ for (int i = 0; i < BYTECOUNT; i++)
+ this.contents[i] = contents[i];
+ }
+
byte[] contents;
@CheckReturnValue
Modified: trunk/prototypes/java/test/org/openlcb/EventIDTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/EventIDTest.java 2012-05-17 07:16:52 UTC (rev 2230)
+++ trunk/prototypes/java/test/org/openlcb/EventIDTest.java 2012-05-17 07:17:19 UTC (rev 2231)
@@ -41,6 +41,20 @@
Assert.assertTrue(e1.equals(e2));
}
+ public void testStringArgDotted() {
+ EventID e1 = new EventID("1.2.3.4.5.6.7.8");
+ EventID e2 = new EventID(new byte[]{1,2,3,4,5,6,7,8});
+ Assert.assertTrue(e1.equals(e2));
+
+ }
+
+ public void testStringArgSpaces() {
+ EventID e1 = new EventID("1 2 3 4 5 6 7 8");
+ EventID e2 = new EventID(new byte[]{1,2,3,4,5,6,7,8});
+ Assert.assertTrue(e1.equals(e2));
+
+ }
+
public void testAltCtor() {
EventID e1 = new EventID(new byte[]{1,2,3,4,5,6,7,8});
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-17 07:17:44
|
Revision: 2232
http://openlcb.svn.sourceforge.net/openlcb/?rev=2232&view=rev
Author: jacobsen
Date: 2012-05-17 07:17:37 +0000 (Thu, 17 May 2012)
Log Message:
-----------
more hex string utilities
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/Utilities.java
trunk/prototypes/java/test/org/openlcb/UtilitiesTest.java
Modified: trunk/prototypes/java/src/org/openlcb/Utilities.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/Utilities.java 2012-05-17 07:17:19 UTC (rev 2231)
+++ trunk/prototypes/java/src/org/openlcb/Utilities.java 2012-05-17 07:17:37 UTC (rev 2232)
@@ -34,4 +34,77 @@
String retval = new String(buff);
return retval.substring(1);
}
+
+ @CheckReturnValue
+ @NonNull
+ static public String toHexDotsString(int[] array) {
+ StringBuffer buff = new StringBuffer();
+ for (int i = 0; i < array.length; i++) {
+ buff.append(".");
+ buff.append(Utilities.toHexPair(array[i]));
+ }
+ String retval = new String(buff);
+ return retval.substring(1);
+ }
+
+ @CheckReturnValue
+ @NonNull
+ static public String toHexDotsString(byte[] array) {
+ StringBuffer buff = new StringBuffer();
+ for (int i = 0; i < array.length; i++) {
+ buff.append(".");
+ buff.append(Utilities.toHexPair(array[i]));
+ }
+ String retval = new String(buff);
+ return retval.substring(1);
+ }
+
+ /**
+ * Create a byte[] from a String containing hexadecimal values.
+ *
+ * @param s String of hex values, ala "01 02 0A B1 21". Either spaces or dots
+ * can be used as separators.
+ * @return byte array, with one byte for each pair. Can be zero length,
+ * but will not be null.
+ */
+ static public byte[] bytesFromHexString(String s) {
+ String ts = s.replace("."," ")+" "; // ensure blanks on end to make scan easier
+ int len = 0;
+ // scan for length
+ for (int i= 0; i< s.length(); i++) {
+ if (ts.charAt(i) != ' ') {
+ // need to process char for number. Is this a single digit?
+ if (ts.charAt(i+1) != ' ') {
+ // 2 char value
+ i++;
+ len++;
+ } else {
+ // 1 char value
+ len++;
+ }
+ }
+ }
+ byte[] b = new byte[len];
+ // scan for content
+ int saveAt = 0;
+ for (int i= 0; i< s.length(); i++) {
+ if (ts.charAt(i) != ' ') {
+ // need to process char for number. Is this a single digit?
+ if (ts.charAt(i+1) != ' ') {
+ // 2 char value
+ String v = ""+ts.charAt(i)+ts.charAt(i+1);
+ b[saveAt] = (byte)Integer.valueOf(v,16).intValue();
+ i++;
+ saveAt++;
+ } else {
+ // 1 char value
+ String v = ""+ts.charAt(i);
+ b[saveAt] = (byte)Integer.valueOf(v,16).intValue();
+ saveAt++;
+ }
+ }
+ }
+ return b;
+ }
+
}
Modified: trunk/prototypes/java/test/org/openlcb/UtilitiesTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/UtilitiesTest.java 2012-05-17 07:17:19 UTC (rev 2231)
+++ trunk/prototypes/java/test/org/openlcb/UtilitiesTest.java 2012-05-17 07:17:37 UTC (rev 2232)
@@ -27,8 +27,19 @@
Assert.assertEquals("0A 0B 12", Utilities.toHexSpaceString(new int[]{0x0A, 0x0B, 0x12}));
}
- // from here down is testing infrastructure
+ public void testToByteArray() {
+ Assert.assertTrue(compareArrays(new byte[]{0xA, 0xB, 0x12}, Utilities.bytesFromHexString("0A 0B 12")));
+ Assert.assertTrue(compareArrays(new byte[]{0xA, 0xB, 0x12}, Utilities.bytesFromHexString("0A.0B.12")));
+ }
+ boolean compareArrays(byte[] a, byte[]b) {
+ if (a == null && b == null) return true;
+ if (a.length != b.length) return false;
+ for (int i = 0; i <a.length; i++) if (a[i]!=b[i]) return false;
+ return true;
+ }
+ // from here down is testing infrastructure
+
public UtilitiesTest(String s) {
super(s);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-17 07:18:52
|
Revision: 2233
http://openlcb.svn.sourceforge.net/openlcb/?rev=2233&view=rev
Author: jacobsen
Date: 2012-05-17 07:18:45 +0000 (Thu, 17 May 2012)
Log Message:
-----------
work on read/write adapters; complete for EventID and String, Bit and Int still need work. Also add proper offset handing, include attribute on all items
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/cdi/CdiRep.java
trunk/prototypes/java/src/org/openlcb/cdi/jdom/JdomCdiRep.java
trunk/prototypes/java/src/org/openlcb/cdi/swing/CdiPanel.java
trunk/prototypes/java/test/scenarios/ConfigDemoApplet.java
Modified: trunk/prototypes/java/src/org/openlcb/cdi/CdiRep.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/cdi/CdiRep.java 2012-05-17 07:17:37 UTC (rev 2232)
+++ trunk/prototypes/java/src/org/openlcb/cdi/CdiRep.java 2012-05-17 07:18:45 UTC (rev 2233)
@@ -25,6 +25,7 @@
public static interface Segment {
public int getSpace();
+ public int getOrigin();
public java.util.List<Item> getItems();
public String getName();
@@ -36,6 +37,7 @@
public String getName();
public String getDescription();
public Map getMap();
+ public int getOffset();
}
public static interface Group extends Item {
@@ -51,19 +53,19 @@
public static interface EventID extends Item {
}
- public static interface Int extends Item {
+ public static interface IntegerRep extends Item {
public int getDefault();
public int getMin();
public int getMax();
public int getSize();
}
- public static interface Bit extends Item {
+ public static interface BitRep extends Item {
public boolean getDefault();
public int getSize();
}
- public static interface CdiString extends Item { // "String" causes too many name conflicts
+ public static interface StringRep extends Item { // "String" causes too many name conflicts
public int getSize();
}
Modified: trunk/prototypes/java/src/org/openlcb/cdi/jdom/JdomCdiRep.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/cdi/jdom/JdomCdiRep.java 2012-05-17 07:17:37 UTC (rev 2232)
+++ trunk/prototypes/java/src/org/openlcb/cdi/jdom/JdomCdiRep.java 2012-05-17 07:18:45 UTC (rev 2233)
@@ -90,10 +90,10 @@
// some elements aren't contained items
Element element = (Element)elements.get(i);
if ("group".equals(element.getName())) list.add(new Group(element));
- else if ("bit".equals(element.getName())) list.add(new Bit(element));
- else if ("int".equals(element.getName())) list.add(new Int(element));
+ else if ("bit".equals(element.getName())) list.add(new BitRep(element));
+ else if ("int".equals(element.getName())) list.add(new IntRep(element));
else if ("eventid".equals(element.getName())) list.add(new EventID(element));
- else if ("string".equals(element.getName())) list.add(new CdiString(element));
+ else if ("string".equals(element.getName())) list.add(new StringRep(element));
}
return list;
}
@@ -112,6 +112,13 @@
}
Segment(Element segment) { super(segment); }
+ public int getOrigin() {
+ Attribute a = e.getAttribute("origin");
+ try {
+ if (a == null) return 0;
+ else return a.getIntValue();
+ } catch (org.jdom.DataConversionException e) { return 0; }
+ }
}
public static class Map implements CdiRep.Map {
@@ -166,6 +173,13 @@
public Map getMap() {
return new Map(e.getChild("map"));
}
+ public int getOffset() {
+ Attribute a = e.getAttribute("offset");
+ try {
+ if (a == null) return 0;
+ else return a.getIntValue();
+ } catch (org.jdom.DataConversionException e) { return 0; }
+ }
Item(Element e) { this.e = e; }
Element e;
@@ -178,13 +192,21 @@
else return a.getIntValue();
} catch (org.jdom.DataConversionException e) { return 0; }
}
+ public int getOffset() {
+ Attribute a = e.getAttribute("offset");
+ try {
+ if (a == null) return 0;
+ else return a.getIntValue();
+ } catch (org.jdom.DataConversionException e) { return 0; }
+ }
Group(Element e) { super(e); }
}
+
public static class EventID extends Item implements CdiRep.EventID {
EventID(Element e) { super(e); }
}
- public static class Int extends Item implements CdiRep.Int {
+ public static class IntRep extends Item implements CdiRep.IntegerRep {
public int getDefault() { return 0; }
public int getMin() { return 0; }
public int getMax() { return 0; }
@@ -197,9 +219,9 @@
} catch (org.jdom.DataConversionException e) { return 0; }
}
- Int(Element e) { super(e); }
+ IntRep(Element e) { super(e); }
}
- public static class Bit extends Item implements CdiRep.Bit {
+ public static class BitRep extends Item implements CdiRep.BitRep {
public boolean getDefault() { return false; }
public int getSize() {
@@ -210,9 +232,9 @@
} catch (org.jdom.DataConversionException e) { return 0; }
}
- Bit(Element e) { super(e); }
+ BitRep(Element e) { super(e); }
}
- public static class CdiString extends Item implements CdiRep.CdiString {
+ public static class StringRep extends Item implements CdiRep.StringRep {
public int getSize() {
Attribute a = e.getAttribute("size");
@@ -222,7 +244,7 @@
} catch (org.jdom.DataConversionException e) { return 0; }
}
- CdiString(Element e) { super(e); }
+ StringRep(Element e) { super(e); }
}
Element root;
Modified: trunk/prototypes/java/src/org/openlcb/cdi/swing/CdiPanel.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/cdi/swing/CdiPanel.java 2012-05-17 07:17:37 UTC (rev 2232)
+++ trunk/prototypes/java/src/org/openlcb/cdi/swing/CdiPanel.java 2012-05-17 07:18:45 UTC (rev 2233)
@@ -17,10 +17,13 @@
public CdiPanel () { super(); }
- public void initComponents() {
+ public void initComponents(ReadWriteAccess accessor) {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
+ this.accessor = accessor;
}
+ ReadWriteAccess accessor;
+
public void loadCDI(CdiRep c) {
add(createIdentificationPane(c));
@@ -104,18 +107,38 @@
JPanel p2 = createPropertyPane(item.getMap());
if (p2!=null) p.add(p2);
+ long origin = item.getOrigin();
+ int space = item.getSpace();
+
// find and process items
java.util.List<CdiRep.Item> items = item.getItems();
if (items != null) {
- for (int i=0; i<items.size(); i++) {
+ DisplayPane pane = null;
+
+ for (int i=0; i<items.size(); i++) {
CdiRep.Item it = (CdiRep.Item) items.get(i);
- if (it instanceof CdiRep.Group) p.add(createGroupPane((CdiRep.Group)it));
- else if (it instanceof CdiRep.Bit) p.add(createBitPane((CdiRep.Bit)it));
- else if (it instanceof CdiRep.Int) p.add(createIntPane((CdiRep.Int)it));
- else if (it instanceof CdiRep.EventID) p.add(createEventIdPane((CdiRep.EventID)it));
- else if (it instanceof CdiRep.CdiString) p.add(createStringPane((CdiRep.CdiString)it));
- }
+
+ origin = origin +it.getOffset();
+
+ if (it instanceof CdiRep.Group) {
+ pane = createGroupPane((CdiRep.Group) it, origin, space);
+ } else if (it instanceof CdiRep.BitRep) {
+ pane = createBitPane((CdiRep.BitRep) it, origin, space);
+ } else if (it instanceof CdiRep.IntegerRep) {
+ pane = createIntPane((CdiRep.IntegerRep) it, origin, space);
+ } else if (it instanceof CdiRep.EventID) {
+ pane = createEventIdPane((CdiRep.EventID) it, origin, space);
+ } else if (it instanceof CdiRep.StringRep) {
+ pane = createStringPane((CdiRep.StringRep) it, origin, space);
+ }
+ if (pane != null) {
+ origin = pane.getOrigin() + pane.getVarSize();
+ p.add(pane);
+ } else {
+ System.out.println("could not process type of " + it);
+ }
}
+ }
JPanel ret = new util.CollapsiblePanel(name, p);
ret.setAlignmentY(Component.TOP_ALIGNMENT);
@@ -138,147 +161,326 @@
return p;
}
- JPanel createGroupPane(CdiRep.Group item) {
- JPanel p = new JPanel();
- p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
- p.setAlignmentX(Component.LEFT_ALIGNMENT);
- String name = "Group"+(item.getName()!=null?(": "+item.getName()):"");
- p.setBorder(BorderFactory.createTitledBorder(name));
+ abstract class DisplayPane extends JPanel {
+ DisplayPane(long origin, int space) {
+ this.origin = origin;
+ this.space = space;
+ }
+ int getVarSize() { return size; }
+ int size;
- String d = item.getDescription();
- if (d!=null) p.add(createDescriptionPane(d));
+ long getOrigin() { return origin; }
+ long origin;
- // include map if present
- JPanel p2 = createPropertyPane(item.getMap());
- if (p2!=null) p.add(p2);
+ int getVarSpace() { return space; }
+ int space;
+ }
- // find and process items as replicated
- int rep = item.getReplication();
- if (rep == 0) rep = 1; // default
-
- for (int i = 0; i < rep; i++) {
- java.util.List<CdiRep.Item> items = item.getItems();
- if (items != null) {
- for (int j=0; j<items.size(); j++) {
- CdiRep.Item it = (CdiRep.Item) items.get(j);
- if (it instanceof CdiRep.Group) p.add(createGroupPane((CdiRep.Group)it));
- else if (it instanceof CdiRep.Bit) p.add(createBitPane((CdiRep.Bit)it));
- else if (it instanceof CdiRep.Int) p.add(createIntPane((CdiRep.Int)it));
- else if (it instanceof CdiRep.EventID) p.add(createEventIdPane((CdiRep.EventID)it));
- else if (it instanceof CdiRep.CdiString) p.add(createStringPane((CdiRep.CdiString)it));
+ DisplayPane createGroupPane(CdiRep.Group item, long origin, int space) {
+ return new GroupPane(item, origin, space);
+ }
+
+ class GroupPane extends DisplayPane {
+ GroupPane(CdiRep.Group item, long origin, int space){
+ super(origin, space);
+ setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
+ setAlignmentX(Component.LEFT_ALIGNMENT);
+ String name = "Group" + (item.getName() != null ? (": " + item.getName()) : "");
+ setBorder(BorderFactory.createTitledBorder(name));
+
+ String d = item.getDescription();
+ if (d != null) {
+ add(createDescriptionPane(d));
+ }
+
+ // include map if present
+ JPanel p2 = createPropertyPane(item.getMap());
+ if (p2 != null) {
+ add(p2);
+ }
+
+ // find and process items as replicated
+ int rep = item.getReplication();
+ if (rep == 0) {
+ rep = 1; // default
+ }
+ for (int i = 0; i < rep; i++) {
+ java.util.List<CdiRep.Item> items = item.getItems();
+ if (items != null) {
+ for (int j = 0; j < items.size(); j++) {
+ CdiRep.Item it = (CdiRep.Item) items.get(j);
+ DisplayPane pane = null;
+
+ origin = origin +it.getOffset();
+ size = size + it.getOffset();
+
+ if (it instanceof CdiRep.Group) {
+ pane = createGroupPane((CdiRep.Group) it, origin, space);
+ } else if (it instanceof CdiRep.BitRep) {
+ pane = createBitPane((CdiRep.BitRep) it, origin, space);
+ } else if (it instanceof CdiRep.IntegerRep) {
+ pane = createIntPane((CdiRep.IntegerRep) it, origin, space);
+ } else if (it instanceof CdiRep.EventID) {
+ pane = createEventIdPane((CdiRep.EventID) it, origin, space);
+ } else if (it instanceof CdiRep.StringRep) {
+ pane = createStringPane((CdiRep.StringRep) it, origin,space);
+ }
+ if (pane != null) {
+ size = size + pane.getVarSize();
+ origin = pane.getOrigin() + pane.getVarSize();
+ add(pane);
+ } else {
+ System.out.println("could not process type of " + it);
+ }
+ }
}
}
+
}
- return p;
}
- JPanel createBitPane(CdiRep.Bit item) {
- JPanel p = new JPanel();
- p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
- p.setAlignmentX(Component.LEFT_ALIGNMENT);
- String name = "Bit"+(item.getName()!=null?(": "+item.getName()):"");
- p.setBorder(BorderFactory.createTitledBorder(name));
-
- String d = item.getDescription();
- if (d!=null) p.add(createDescriptionPane(d));
-
- // see if map is present
- String[] labels;
- CdiRep.Map map = item.getMap();
- if ((map != null) && (map.getKeys().size()>=2)) {
- // first two map values are labels, must be present
- java.util.List<String> keys = map.getKeys();
- labels = new String[]{map.getEntry(keys.get(0)),map.getEntry(keys.get(1))};
- } else {
- labels = new String[]{"On","Off"};
- }
+ DisplayPane createBitPane(CdiRep.BitRep item, long origin, int space) {
+ return new BitPane(item, origin, space);
+ }
- JPanel p3 = new JPanel();
- p3.setLayout(new FlowLayout());
- p.add(p3);
- p3.add(new JComboBox(labels));
- p3.add(new JButton("Read"));
- p3.add(new JButton("Write"));
+ class BitPane extends DisplayPane {
- return p;
- }
+ BitPane(CdiRep.BitRep item, long origin, int space) {
+ super(origin, space);
+ setAlignmentX(Component.LEFT_ALIGNMENT);
+ String name = "Bit" + (item.getName() != null ? (": " + item.getName()) : "");
+ setBorder(BorderFactory.createTitledBorder(name));
- JPanel createEventIdPane(CdiRep.EventID item) {
- JPanel p = new JPanel();
- p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
- p.setAlignmentX(Component.LEFT_ALIGNMENT);
- String name = "EventID"+(item.getName()!=null?(": "+item.getName()):"");
- p.setBorder(BorderFactory.createTitledBorder(name));
-
- String d = item.getDescription();
- if (d!=null) p.add(createDescriptionPane(d));
-
- JPanel p3 = new JPanel();
- p3.setAlignmentX(Component.LEFT_ALIGNMENT);
- p3.setLayout(new FlowLayout());
- p.add(p3);
+ String d = item.getDescription();
+ if (d != null) {
+ add(createDescriptionPane(d));
+ }
- p3.add(new JTextField(24));
-
- p3.add(new JButton("Read"));
- p3.add(new JButton("Write"));
+ size = item.getSize();
+
+ // see if map is present
+ String[] labels;
+ CdiRep.Map map = item.getMap();
+ if ((map != null) && (map.getKeys().size() >= 2)) {
+ // first two map values are labels, must be present
+ java.util.List<String> keys = map.getKeys();
+ labels = new String[]{map.getEntry(keys.get(0)), map.getEntry(keys.get(1))};
+ } else {
+ labels = new String[]{"On", "Off"};
+ }
- return p;
+ JPanel p3 = new JPanel();
+ p3.setLayout(new FlowLayout());
+ add(p3);
+ p3.add(new JComboBox(labels));
+
+ JButton b;
+ b = new JButton("Read");
+ final ReadReturn handler = new ReadReturn() {
+ public void returnData(byte[] data) {
+ //textField.setText(org.openlcb.Utilities.toHexDotsString(data));
+ }
+ };
+ b.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ accessor.doRead(getOrigin(), getVarSpace(), 8, handler);
+ }
+ });
+ p3.add(b);
+ b = new JButton("Write");
+ b.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ accessor.doWrite(getOrigin(), getVarSpace(), new byte[]{});
+ }
+ });
+ p3.add(b);
+ }
}
- JPanel createIntPane(CdiRep.Int item) {
- JPanel p = new JPanel();
- p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
- p.setAlignmentX(Component.LEFT_ALIGNMENT);
- String name = "Integer"+(item.getName()!=null?(": "+item.getName()):"");
- p.setBorder(BorderFactory.createTitledBorder(name));
+ DisplayPane createEventIdPane(CdiRep.EventID item, long start, int space) {
+ return new EventIdPane(item,start,space);
+ }
+
+ class EventIdPane extends DisplayPane {
+
+ JTextField textField;
- String d = item.getDescription();
- if (d!=null) p.add(createDescriptionPane(d));
-
- JPanel p3 = new JPanel();
- p3.setAlignmentX(Component.LEFT_ALIGNMENT);
- p3.setLayout(new FlowLayout());
- p.add(p3);
+ EventIdPane(CdiRep.EventID item, long origin, int space) {
+ super(origin, space);
+ setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
+ setAlignmentX(Component.LEFT_ALIGNMENT);
+ String name = "EventID" + (item.getName() != null ? (": " + item.getName()) : "");
+ setBorder(BorderFactory.createTitledBorder(name));
- // see if map is present
- String[] labels;
- CdiRep.Map map = item.getMap();
- if ((map != null) && (map.getKeys().size()>0)) {
- // map present, make selection box
- p3.add(new JComboBox(map.getValues().toArray(new String[]{""})));
- } else {
- // map not present, just an entry box
- p3.add(new JTextField(24));
+ String d = item.getDescription();
+ if (d != null) {
+ add(createDescriptionPane(d));
+ }
+
+ size = 8;
+
+ JPanel p3 = new JPanel();
+ p3.setAlignmentX(Component.LEFT_ALIGNMENT);
+ p3.setLayout(new FlowLayout());
+ add(p3);
+
+ textField = new JTextField(24);
+ p3.add(textField);
+ textField.setToolTipText("EventID as eight-byte dotted-hex string, e.g. 01.02.0A.AB.34.56.78.00");
+
+ JButton b;
+ b = new JButton("Read");
+ final ReadReturn handler = new ReadReturn() {
+ public void returnData(byte[] data) {
+ textField.setText(org.openlcb.Utilities.toHexDotsString(data));
+ }
+ };
+ b.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ accessor.doRead(getOrigin(), getVarSpace(), 8, handler);
+ }
+ });
+ p3.add(b);
+ b = new JButton("Write");
+ b.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ byte[] contents = org.openlcb.Utilities.bytesFromHexString(textField.getText());
+ accessor.doWrite(getOrigin(), getVarSpace(), contents);
+ }
+ });
+ p3.add(b);
+
}
+ }
+
+ DisplayPane createIntPane(CdiRep.IntegerRep item, long origin, int space) {
+ return new IntPane(item, origin, space);
+ }
- p3.add(new JButton("Read"));
- p3.add(new JButton("Write"));
+ class IntPane extends DisplayPane {
- return p;
+ IntPane(CdiRep.IntegerRep item, long origin, int space) {
+ super(origin, space);
+ setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
+ setAlignmentX(Component.LEFT_ALIGNMENT);
+ String name = "Integer" + (item.getName() != null ? (": " + item.getName()) : "");
+ setBorder(BorderFactory.createTitledBorder(name));
+
+ String d = item.getDescription();
+ if (d != null) {
+ add(createDescriptionPane(d));
+ }
+
+ size = item.getSize();
+
+ JPanel p3 = new JPanel();
+ p3.setAlignmentX(Component.LEFT_ALIGNMENT);
+ p3.setLayout(new FlowLayout());
+ add(p3);
+
+ // see if map is present
+ String[] labels;
+ CdiRep.Map map = item.getMap();
+ if ((map != null) && (map.getKeys().size() > 0)) {
+ // map present, make selection box
+ p3.add(new JComboBox(map.getValues().toArray(new String[]{""})));
+ } else {
+ // map not present, just an entry box
+ JTextField textField = new JTextField(24);
+ p3.add(textField);
+ textField.setToolTipText("Signed integer value of up to "+size+" bytes");
+ }
+
+ JButton b;
+ b = new JButton("Read");
+ final ReadReturn handler = new ReadReturn() {
+ public void returnData(byte[] data) {
+ //textField.setText(org.openlcb.Utilities.toHexDotsString(data));
+ }
+ };
+ b.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ accessor.doRead(getOrigin(), getVarSpace(), 8, handler);
+ }
+ });
+ p3.add(b);
+ b = new JButton("Write");
+ b.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ accessor.doWrite(getOrigin(), getVarSpace(), new byte[]{});
+ }
+ });
+ p3.add(b);
+ }
}
- JPanel createStringPane(CdiRep.CdiString item) {
- JPanel p = new JPanel();
- p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
- p.setAlignmentX(Component.LEFT_ALIGNMENT);
- String name = "String"+(item.getName()!=null?(": "+item.getName()):"");
- p.setBorder(BorderFactory.createTitledBorder(name));
+ DisplayPane createStringPane(CdiRep.StringRep item, long origin, int space) {
+ return new StringPane(item, origin, space);
+ }
+
+ class StringPane extends DisplayPane {
+ JTextField textField;
- String d = item.getDescription();
- if (d!=null) p.add(createDescriptionPane(d));
+ StringPane(CdiRep.StringRep item, long origin, int space) {
+ super(origin, space);
+ setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
+ setAlignmentX(Component.LEFT_ALIGNMENT);
+ String name = "String"+(item.getName()!=null?(": "+item.getName()):"");
+ setBorder(BorderFactory.createTitledBorder(name));
- JPanel p3 = new JPanel();
- p3.setAlignmentX(Component.LEFT_ALIGNMENT);
- p3.setLayout(new FlowLayout());
- p.add(p3);
+ String d = item.getDescription();
+ if (d!=null) add(createDescriptionPane(d));
+
+ size = item.getSize();
+
+ JPanel p3 = new JPanel();
+ p3.setAlignmentX(Component.LEFT_ALIGNMENT);
+ p3.setLayout(new FlowLayout());
+ add(p3);
- p3.add(new JTextField(24));
+ textField = new JTextField(size);
+
+ p3.add(textField);
+ textField.setToolTipText("String of up to "+size+" characters");
- p3.add(new JButton("Read"));
- p3.add(new JButton("Write"));
+ JButton b;
+ b = new JButton("Read");
+ final ReadReturn handler = new ReadReturn() {
+ public void returnData(byte[] data) {
+ textField.setText(new String(data));
+ }
+ };
+ b.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ accessor.doRead(getOrigin(), getVarSpace(), size, handler);
+ }
+ });
+ p3.add(b);
+ b = new JButton("Write");
+ b.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ byte[] content = textField.getText().getBytes();
+ accessor.doWrite(getOrigin(), getVarSpace(), content);
+ }
+ });
+ p3.add(b);
+ }
+ }
- return p;
- }
+ /**
+ * Memo class for adding access to e.g. a MemoryConfig service.
+ *
+ * Default just writes output for debug
+ */
+ abstract public static class ReadWriteAccess {
+ abstract public void doWrite(long address, int space, byte[] data);
+ abstract public void doRead(long address, int space, int length, final ReadReturn handler);
+ }
+ /**
+ * Memo class for handling read-return data
+ */
+ abstract public class ReadReturn {
+ abstract public void returnData(byte[] data);
+ }
}
Modified: trunk/prototypes/java/test/scenarios/ConfigDemoApplet.java
===================================================================
--- trunk/prototypes/java/test/scenarios/ConfigDemoApplet.java 2012-05-17 07:17:37 UTC (rev 2232)
+++ trunk/prototypes/java/test/scenarios/ConfigDemoApplet.java 2012-05-17 07:18:45 UTC (rev 2233)
@@ -49,7 +49,17 @@
JFrame f = new JFrame();
f.setTitle("Configuration Demonstration");
CdiPanel m = new CdiPanel();
- m.initComponents();
+
+ m.initComponents(new CdiPanel.ReadWriteAccess(){
+ public void doWrite(long address, int space, byte[] data) {
+ System.out.println(data.length);
+ System.out.println("write "+address+" "+space+": "+org.openlcb.Utilities.toHexDotsString(data));
+ }
+ public void doRead(long address, int space, int length, CdiPanel.ReadReturn handler) {
+ handler.returnData(new byte[]{1,2,3,4,5,6,7,8});
+ System.out.println("read "+address+" "+space);
+ }
+ });
m.loadCDI(
new org.openlcb.cdi.jdom.JdomCdiRep(
org.openlcb.cdi.jdom.SampleFactory.getBasicSample()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-17 07:19:33
|
Revision: 2234
http://openlcb.svn.sourceforge.net/openlcb/?rev=2234&view=rev
Author: jacobsen
Date: 2012-05-17 07:19:27 +0000 (Thu, 17 May 2012)
Log Message:
-----------
0.4.8
Modified Paths:
--------------
trunk/prototypes/java/manifest
trunk/prototypes/java/openlcb-demo.jar
trunk/prototypes/java/openlcb.jar
Modified: trunk/prototypes/java/manifest
===================================================================
--- trunk/prototypes/java/manifest 2012-05-17 07:18:45 UTC (rev 2233)
+++ trunk/prototypes/java/manifest 2012-05-17 07:19:27 UTC (rev 2234)
@@ -7,6 +7,6 @@
Specification-Version: \xD20.4.2\xD3
Specification-Vendor: \xD2OpenLCB group"
Package-Title: \xD2openlcb\xD3
-Package-Version: \xD20.4.7\xD3
+Package-Version: \xD20.4.8\xD3
Package-Vendor: \xD2OpenLCB group\xD3
Modified: trunk/prototypes/java/openlcb-demo.jar
===================================================================
(Binary files differ)
Modified: trunk/prototypes/java/openlcb.jar
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-18 04:14:26
|
Revision: 2238
http://openlcb.svn.sourceforge.net/openlcb/?rev=2238&view=rev
Author: jacobsen
Date: 2012-05-18 04:14:20 +0000 (Fri, 18 May 2012)
Log Message:
-----------
better handle SNII/ACDI user data
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/SimpleNodeIdent.java
trunk/prototypes/java/src/org/openlcb/swing/networktree/NodeTreeRep.java
trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentTest.java
Modified: trunk/prototypes/java/src/org/openlcb/SimpleNodeIdent.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/SimpleNodeIdent.java 2012-05-18 04:13:35 UTC (rev 2237)
+++ trunk/prototypes/java/src/org/openlcb/SimpleNodeIdent.java 2012-05-18 04:14:20 UTC (rev 2238)
@@ -57,16 +57,53 @@
if (s == null) return "";
else return s;
}
- public String getVersion() {
+ public String getHardwareVersion() {
int len = 1;
int start = 1;
// skip mfg, model
+ for (int i = 0; i<2; i++) {
+ for (; len < bytes.length; len++)
+ if (bytes[len] == 0) break;
+ start = ++len;
+ }
+
+ // find this string
for (; len < bytes.length; len++)
if (bytes[len] == 0) break;
- start = ++len;
+ String s = new String(bytes,start, len-start);
+ if (s == null) return "";
+ else return s;
+ }
+
+ public String getSoftwareVersion() {
+ int len = 1;
+ int start = 1;
+ // skip mfg, model, hardware_version
+ for (int i = 0; i<3; i++) {
+ for (; len < bytes.length; len++)
+ if (bytes[len] == 0) break;
+ start = ++len;
+ }
+
+ // find this string
for (; len < bytes.length; len++)
if (bytes[len] == 0) break;
- start = ++len;
+ String s = new String(bytes,start, len-start);
+ if (s == null) return "";
+ else return s;
+ }
+
+ public String getUserName() {
+ int len = 1;
+ int start = 1;
+ // skip mfg, model, hardware_version, software_version
+ for (int i = 0; i<4; i++) {
+ for (; len < bytes.length; len++)
+ if (bytes[len] == 0) break;
+ start = ++len;
+ }
+
+ // find this string
for (; len < bytes.length; len++)
if (bytes[len] == 0) break;
String s = new String(bytes,start, len-start);
@@ -74,4 +111,22 @@
else return s;
}
+ public String getUserDesc() {
+ int len = 1;
+ int start = 1;
+ // skip mfg, model, hardware_version, software_version, user_name
+ for (int i = 0; i<5; i++) {
+ for (; len < bytes.length; len++)
+ if (bytes[len] == 0) break;
+ start = ++len;
+ }
+
+ // find this string
+ for (; len < bytes.length; len++)
+ if (bytes[len] == 0) break;
+ String s = new String(bytes,start, len-start);
+ if (s == null) return "";
+ else return s;
+ }
+
}
Modified: trunk/prototypes/java/src/org/openlcb/swing/networktree/NodeTreeRep.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/swing/networktree/NodeTreeRep.java 2012-05-18 04:13:35 UTC (rev 2237)
+++ trunk/prototypes/java/src/org/openlcb/swing/networktree/NodeTreeRep.java 2012-05-18 04:14:20 UTC (rev 2238)
@@ -65,34 +65,73 @@
void updateSimpleNodeIdent(SimpleNodeIdent e) {
if (simpleInfoMfgNode == null) {
- simpleInfoMfgNode = new DefaultMutableTreeNode("Mfg: "+e.getMfgName());
- getTreeModel().insertNodeInto(simpleInfoMfgNode,
- getThis(),
- getThis().getChildCount());
+ if (e.getMfgName().replace(" ","").length()>0) {
+ simpleInfoMfgNode = new DefaultMutableTreeNode("Mfg: "+e.getMfgName());
+ getTreeModel().insertNodeInto(simpleInfoMfgNode,
+ getThis(),
+ getThis().getChildCount());
+ }
} else {
simpleInfoMfgNode.setUserObject("Mfg: "+e.getMfgName());
}
if (simpleInfoModelNode == null) {
- simpleInfoModelNode = new DefaultMutableTreeNode("Mod: "+e.getModelName());
- getTreeModel().insertNodeInto(simpleInfoModelNode,
- getThis(),
- getThis().getChildCount());
+ if (e.getModelName().replace(" ","").length()>0) {
+ simpleInfoModelNode = new DefaultMutableTreeNode("Mod: "+e.getModelName());
+ getTreeModel().insertNodeInto(simpleInfoModelNode,
+ getThis(),
+ getThis().getChildCount());
+ }
} else {
simpleInfoModelNode.setUserObject("Mod: "+e.getModelName());
}
- if (simpleInfoVersionNode == null) {
- simpleInfoVersionNode = new DefaultMutableTreeNode("Ver: "+e.getVersion());
- getTreeModel().insertNodeInto(simpleInfoVersionNode,
- getThis(),
- getThis().getChildCount());
+ if (simpleInfoHardwareVersionNode == null) {
+ if (e.getHardwareVersion().replace(" ","").length()>0) {
+ simpleInfoHardwareVersionNode = new DefaultMutableTreeNode("Hardware: "+e.getHardwareVersion());
+ getTreeModel().insertNodeInto(simpleInfoHardwareVersionNode,
+ getThis(),
+ getThis().getChildCount());
+ }
} else {
- simpleInfoVersionNode.setUserObject("Ver: "+e.getVersion());
+ simpleInfoHardwareVersionNode.setUserObject("Hardware: "+e.getHardwareVersion());
}
+ if (simpleInfoSoftwareVersionNode == null) {
+ if (e.getSoftwareVersion().replace(" ","").length()>0) {
+ simpleInfoSoftwareVersionNode = new DefaultMutableTreeNode("Software: "+e.getSoftwareVersion());
+ getTreeModel().insertNodeInto(simpleInfoSoftwareVersionNode,
+ getThis(),
+ getThis().getChildCount());
+ }
+ } else {
+ simpleInfoSoftwareVersionNode.setUserObject("Software: "+e.getSoftwareVersion());
+ }
+ if (simpleInfoUserNameNode == null) {
+ if (e.getUserName().replace(" ","").length()>0) {
+ simpleInfoUserNameNode = new DefaultMutableTreeNode("Name: "+e.getUserName());
+ getTreeModel().insertNodeInto(simpleInfoUserNameNode,
+ getThis(),
+ getThis().getChildCount());
+ }
+ } else {
+ simpleInfoUserNameNode.setUserObject("Name: "+e.getUserName());
+ }
+ if (simpleInfoUserDescNode == null ) {
+ if (e.getUserDesc().replace(" ","").length()>0) {
+ simpleInfoUserDescNode = new DefaultMutableTreeNode("Desc: "+e.getUserDesc());
+ getTreeModel().insertNodeInto(simpleInfoUserDescNode,
+ getThis(),
+ getThis().getChildCount());
+ }
+ } else {
+ simpleInfoUserDescNode.setUserObject("Desc: "+e.getUserDesc());
+ }
}
DefaultMutableTreeNode simpleInfoMfgNode;
DefaultMutableTreeNode simpleInfoModelNode;
- DefaultMutableTreeNode simpleInfoVersionNode;
+ DefaultMutableTreeNode simpleInfoHardwareVersionNode;
+ DefaultMutableTreeNode simpleInfoSoftwareVersionNode;
+ DefaultMutableTreeNode simpleInfoUserNameNode;
+ DefaultMutableTreeNode simpleInfoUserDescNode;
/**
* Provides the node label in the tree
Modified: trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentTest.java 2012-05-18 04:13:35 UTC (rev 2237)
+++ trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentTest.java 2012-05-18 04:14:20 UTC (rev 2238)
@@ -49,7 +49,7 @@
Assert.assertEquals("abcdefg", id.getMfgName());
Assert.assertEquals("AB", id.getModelName());
- Assert.assertEquals("Z", id.getVersion());
+ Assert.assertEquals("Z", id.getHardwareVersion());
}
// from here down is testing infrastructure
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-18 04:15:01
|
Revision: 2239
http://openlcb.svn.sourceforge.net/openlcb/?rev=2239&view=rev
Author: jacobsen
Date: 2012-05-18 04:14:55 +0000 (Fri, 18 May 2012)
Log Message:
-----------
0.4.9
Modified Paths:
--------------
trunk/prototypes/java/manifest
trunk/prototypes/java/openlcb-demo.jar
trunk/prototypes/java/openlcb.jar
Modified: trunk/prototypes/java/manifest
===================================================================
--- trunk/prototypes/java/manifest 2012-05-18 04:14:20 UTC (rev 2238)
+++ trunk/prototypes/java/manifest 2012-05-18 04:14:55 UTC (rev 2239)
@@ -7,6 +7,6 @@
Specification-Version: \xD20.4.2\xD3
Specification-Vendor: \xD2OpenLCB group"
Package-Title: \xD2openlcb\xD3
-Package-Version: \xD20.4.8\xD3
+Package-Version: \xD20.4.9\xD3
Package-Vendor: \xD2OpenLCB group\xD3
Modified: trunk/prototypes/java/openlcb-demo.jar
===================================================================
(Binary files differ)
Modified: trunk/prototypes/java/openlcb.jar
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-19 09:08:23
|
Revision: 2242
http://openlcb.svn.sourceforge.net/openlcb/?rev=2242&view=rev
Author: jacobsen
Date: 2012-05-19 09:08:17 +0000 (Sat, 19 May 2012)
Log Message:
-----------
JavaDoc improvements
Modified Paths:
--------------
trunk/prototypes/java/src/overview.html
trunk/prototypes/java/test/package.html
Modified: trunk/prototypes/java/src/overview.html
===================================================================
--- trunk/prototypes/java/src/overview.html 2012-05-19 07:22:06 UTC (rev 2241)
+++ trunk/prototypes/java/src/overview.html 2012-05-19 09:08:17 UTC (rev 2242)
@@ -1,6 +1,6 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<html>
<head>
+ <title>OpenLCB Java Implementation</title>
<!--
$Id$
@@ -11,6 +11,7 @@
Copyright 2009 Bob Jacobsen
-->
+
</head>
<body bgcolor="white">
@@ -26,4 +27,4 @@
<!-- Put @see and @since tags down here. -->
</body>
-</html>
+
Modified: trunk/prototypes/java/test/package.html
===================================================================
--- trunk/prototypes/java/test/package.html 2012-05-19 07:22:06 UTC (rev 2241)
+++ trunk/prototypes/java/test/package.html 2012-05-19 09:08:17 UTC (rev 2242)
@@ -1,6 +1,7 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
+ <title>OpenLCB Java Implementation</title>
<!--
$Id$
@@ -11,6 +12,7 @@
Copyright 2003
-->
+
</head>
<body bgcolor="white">
@@ -31,3 +33,4 @@
</body>
</html>
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-20 02:08:33
|
Revision: 2245
http://openlcb.svn.sourceforge.net/openlcb/?rev=2245&view=rev
Author: jacobsen
Date: 2012-05-20 02:08:26 +0000 (Sun, 20 May 2012)
Log Message:
-----------
new method for standard EVentID input
Modified Paths:
--------------
trunk/prototypes/java/test/org/openlcb/swing/PackageTest.java
Added Paths:
-----------
trunk/prototypes/java/src/org/openlcb/swing/EventIdTextField.java
trunk/prototypes/java/test/org/openlcb/swing/EventIdTextFieldTest.java
Copied: trunk/prototypes/java/src/org/openlcb/swing/EventIdTextField.java (from rev 2192, trunk/prototypes/java/src/org/openlcb/swing/MonPane.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/swing/EventIdTextField.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/swing/EventIdTextField.java 2012-05-20 02:08:26 UTC (rev 2245)
@@ -0,0 +1,39 @@
+// EventIdTextField.java
+
+package org.openlcb.swing;
+
+import javax.swing.*;
+import javax.swing.text.*;
+
+import org.openlcb.*;
+
+/**
+ * Text field for entry of forced-valid EventID string.
+ *
+ * Due to class loader issues, this is constructed in library form (as a
+ * static method you call to get the field) rather than a subclass.
+ *
+ * @author Bob Jacobsen Copyright (C) 2012
+ * @version $Revision$
+ */
+public class EventIdTextField extends JFormattedTextField {
+
+ static public JFormattedTextField getEventIdTextField() {
+ JFormattedTextField retval = new JFormattedTextField(createFormatter("HH.HH.HH.HH.HH.HH.HH.HH"));
+
+ retval.setValue("00.00.00.00.00.00.00.00");
+
+ return retval;
+ }
+
+ static private MaskFormatter createFormatter(String s) {
+ MaskFormatter formatter = null;
+ try {
+ formatter = new MaskFormatter(s);
+ } catch (java.text.ParseException exc) {
+ System.err.println("formatter is bad: " + exc.getMessage());
+ }
+ return formatter;
+ }
+
+}
Copied: trunk/prototypes/java/test/org/openlcb/swing/EventIdTextFieldTest.java (from rev 2192, trunk/prototypes/java/test/org/openlcb/swing/MonPaneTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/swing/EventIdTextFieldTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/swing/EventIdTextFieldTest.java 2012-05-20 02:08:26 UTC (rev 2245)
@@ -0,0 +1,62 @@
+package org.openlcb.swing;
+
+import org.openlcb.*;
+import org.openlcb.implementations.*;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import javax.swing.*;
+import javax.swing.text.*;
+
+/**
+ *
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision$
+ */
+public class EventIdTextFieldTest extends TestCase {
+
+ JFrame frame;
+
+ public void setUp() throws Exception {
+
+ frame = new JFrame();
+ frame.setTitle("EventIdTextField Test");
+
+ }
+
+ public void tearDown() {
+ }
+
+ public void testVisibleVersion() {
+ JFormattedTextField p = EventIdTextField.getEventIdTextField();
+
+ frame.add( p );
+
+ frame.pack();
+ frame.setVisible(true);
+
+ Assert.assertEquals("00.00.00.00.00.00.00.00", p.getValue());
+
+ }
+
+ // from here down is testing infrastructure
+
+ public EventIdTextFieldTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {EventIdTextFieldTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(EventIdTextFieldTest.class);
+ return suite;
+ }
+}
Modified: trunk/prototypes/java/test/org/openlcb/swing/PackageTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/swing/PackageTest.java 2012-05-19 15:51:26 UTC (rev 2244)
+++ trunk/prototypes/java/test/org/openlcb/swing/PackageTest.java 2012-05-20 02:08:26 UTC (rev 2245)
@@ -35,6 +35,8 @@
TestSuite suite = new TestSuite(PackageTest.class);
suite.addTest(MonPaneTest.suite());
suite.addTest(NodeSelectorTest.suite());
+ suite.addTest(EventIdTextFieldTest.suite());
+
suite.addTest(org.openlcb.swing.networktree.PackageTest.suite());
suite.addTest(org.openlcb.swing.memconfig.PackageTest.suite());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-20 20:23:02
|
Revision: 2252
http://openlcb.svn.sourceforge.net/openlcb/?rev=2252&view=rev
Author: jacobsen
Date: 2012-05-20 20:22:56 +0000 (Sun, 20 May 2012)
Log Message:
-----------
change default toString
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/NodeID.java
trunk/prototypes/java/test/org/openlcb/NodeIDTest.java
Modified: trunk/prototypes/java/src/org/openlcb/NodeID.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/NodeID.java 2012-05-20 20:22:18 UTC (rev 2251)
+++ trunk/prototypes/java/src/org/openlcb/NodeID.java 2012-05-20 20:22:56 UTC (rev 2252)
@@ -76,13 +76,7 @@
@CheckReturnValue
@NonNull
public String toString() {
- return "NodeID:"
- +Utilities.toHexPair(contents[0])+"."
- +Utilities.toHexPair(contents[1])+"."
- +Utilities.toHexPair(contents[2])+"."
- +Utilities.toHexPair(contents[3])+"."
- +Utilities.toHexPair(contents[4])+"."
- +Utilities.toHexPair(contents[5]);
+ return Utilities.toHexDotsString(contents);
}
}
Modified: trunk/prototypes/java/test/org/openlcb/NodeIDTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/NodeIDTest.java 2012-05-20 20:22:18 UTC (rev 2251)
+++ trunk/prototypes/java/test/org/openlcb/NodeIDTest.java 2012-05-20 20:22:56 UTC (rev 2252)
@@ -108,7 +108,7 @@
public void testOutputFormat() {
NodeID e1 = new NodeID(new byte[]{1,0x10,0x13,0x0D,(byte)0xD0,(byte)0xAB});
- Assert.assertEquals(e1.toString(), "NodeID:01.10.13.0D.D0.AB");
+ Assert.assertEquals("01.10.13.0D.D0.AB", e1.toString());
}
// from here down is testing infrastructure
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-20 20:25:51
|
Revision: 2256
http://openlcb.svn.sourceforge.net/openlcb/?rev=2256&view=rev
Author: jacobsen
Date: 2012-05-20 20:25:45 +0000 (Sun, 20 May 2012)
Log Message:
-----------
change interaction pattern from DatagramService to DatagramMeteringBuffer
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/implementations/DatagramMeteringBuffer.java
trunk/prototypes/java/src/org/openlcb/implementations/DatagramService.java
trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java
trunk/prototypes/java/test/org/openlcb/implementations/DatagramServiceTest.java
Modified: trunk/prototypes/java/src/org/openlcb/implementations/DatagramMeteringBuffer.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/DatagramMeteringBuffer.java 2012-05-20 20:24:43 UTC (rev 2255)
+++ trunk/prototypes/java/src/org/openlcb/implementations/DatagramMeteringBuffer.java 2012-05-20 20:25:45 UTC (rev 2256)
@@ -29,46 +29,68 @@
final static int TIMEOUT = 2000;
- public DatagramMeteringBuffer(Connection downstream) {
- this.downstream = downstream;
+ public DatagramMeteringBuffer(Connection toDownstream) {
+ this.toDownstream = toDownstream;
new Thread(new Consumer(queue)).start();
+
+ fromDownstream = new ReplyHandler();
}
- Connection downstream;
+ Connection toDownstream;
+ Connection fromDownstream;
+ MessageMemo currentMemo;
+ /**
+ * This is where e.g. replies from the OpenLCB
+ * network should be returned to.
+ */
+ public Connection connectionForRepliesFromDownstream() {
+ return fromDownstream;
+ }
+
BlockingQueue<MessageMemo> queue = new LinkedBlockingQueue<MessageMemo>();
/**
* Accept a datagram message to be sent
*/
-
- public void put(Message msg, Connection upstream) {
+ public void put(Message msg, Connection toUpstream) {
if (msg instanceof DatagramMessage)
- queue.add(new MessageMemo(msg, upstream, downstream));
+ queue.add(new MessageMemo(msg, toUpstream, toDownstream));
else
- downstream.put(msg, this);
+ toDownstream.put(msg, fromDownstream);
}
+ class ReplyHandler extends AbstractConnection {
+ /*
+ * Find the current handler and have it handle it
+ */
+ public void put(Message msg, Connection sender) {
+ if (currentMemo == null) return;
+ currentMemo.put(msg, sender);
+ }
+ }
+
class MessageMemo extends MessageDecoder {
Message message;
- Connection downstream;
- Connection upstream;
+ Connection toDownstream;
+ Connection toUpstream;
- MessageMemo(Message msg, Connection u, Connection d) {
+ MessageMemo(Message msg, Connection toUpstream, Connection toDownstream) {
message = msg;
- upstream = u;
- downstream = d;
+ this.toUpstream = toUpstream;
+ this.toDownstream = toDownstream;
}
public void sendIt() {
- downstream.put(message, this);
+ currentMemo = this;
+ toDownstream.put(message, fromDownstream);
}
/**
* Handle "Datagram Acknowledged" message
*/
public void handleDatagramAcknowledged(DatagramAcknowledgedMessage msg, Connection sender){
// forward message upstream
- upstream.put(msg, upstream);
+ toUpstream.put(msg, toUpstream);
// and allow sending another
new Thread(new Consumer(queue)).start();
@@ -80,8 +102,15 @@
public void handleDatagramRejected(DatagramRejectedMessage msg, Connection sender){
// need to check if this is from right source
- // resend
- downstream.put(message, this);
+ // check if resend permitted
+ if (msg.canResend()) {
+ toDownstream.put(message, fromDownstream);
+ } else {
+ // forward upstream to originator and let them sort it out
+ toUpstream.put(msg, toUpstream);
+ // and allow sending another
+ new Thread(new Consumer(queue)).start();
+ }
}
}
@@ -92,6 +121,7 @@
try {
consume(queue.take());
} catch (InterruptedException ex) {}
+ // and exits. Another has to be started with this item is done.
}
void consume(MessageMemo x) { x.sendIt(); }
}
Modified: trunk/prototypes/java/src/org/openlcb/implementations/DatagramService.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/DatagramService.java 2012-05-20 20:24:43 UTC (rev 2255)
+++ trunk/prototypes/java/src/org/openlcb/implementations/DatagramService.java 2012-05-20 20:25:45 UTC (rev 2256)
@@ -14,6 +14,7 @@
* <li>Register to be notified when data of a particular type arrives
* </ul>
*
+ * Does not handle retry of negative replies. For that, see {@link DatagramMeteringBuffer}.
*
* @author Bob Jacobsen Copyright 2012
* @version $Revision$
@@ -45,26 +46,38 @@
/**
* Handle "Datagram" message from layout
*/
+ @Override
public void handleDatagram(DatagramMessage msg, Connection sender){
// forward
int retval = DEFAULT_ERROR_CODE;
+ ReplyMemo replyMemo = new ReplyMemo(msg, downstream, here, this);
if (rcvMemo != null && rcvMemo.type == msg.getData()[0]) {
- retval = rcvMemo.handleData(msg.getSourceNodeID(), msg.getData());
- }
- if (retval == 0) {
- // accept
- Message m = new DatagramAcknowledgedMessage(here, msg.getSourceNodeID());
- downstream.put(m, this);
+ rcvMemo.handleData(msg.getSourceNodeID(), msg.getData(), replyMemo);
+ // check that a reply was sent
+ if (! replyMemo.hasReplied())
+ System.err.println("No internal reply received to datagram with contents "+Utilities.toHexDotsString(msg.getData()));
} else {
// reject
- Message m = new DatagramRejectedMessage(here, msg.getSourceNodeID(), retval);
- downstream.put(m, this);
+ replyMemo.acceptData(retval);
}
+
}
/**
* Handle positive datagram reply message from layout
*/
+ @Override
+ public void handleDatagramRejected(DatagramRejectedMessage msg, Connection sender){
+ if (xmtMemo != null) {
+ xmtMemo.handleReply(msg.getCode());
+ }
+ xmtMemo = null;
+ }
+
+ /**
+ * Handle negative datagram reply message from layout
+ */
+ @Override
public void handleDatagramAcknowledged(DatagramAcknowledgedMessage msg, Connection sender){
if (xmtMemo != null) {
xmtMemo.handleReply(0);
@@ -107,17 +120,58 @@
@Override
public int hashCode() { return type; }
+ public void acceptData(int resultCode) {
+
+ }
/**
- * Overload this to for notification of data.
+ * Overload this for notification of data.
+ *
+ * @param service Implementations must reply to the datagram by invoking
+ * reply.acceptData(int replycode)
+ * before returning. (This is done, instead of using the
+ * return value, to allow the receiving code to reply immediately
+ * and queue other activity afterwards)
+ *
* @return 0 for OK, non-zero for error reply
*/
- public int handleData(NodeID n, int[] data) {
+ public void handleData(NodeID n, int[] data, ReplyMemo service) {
// default is error
- return DEFAULT_ERROR_CODE;
+ service.acceptData(DEFAULT_ERROR_CODE);
}
}
+
+ @Immutable
+ static protected class ReplyMemo {
+ DatagramMessage msg;
+ Connection downstream;
+ NodeID here;
+ DatagramService service;
+ boolean replied = false;
+
+ protected ReplyMemo (DatagramMessage msg, Connection downstream, NodeID here, DatagramService service) {
+ this.msg = msg;
+ this.downstream = downstream;
+ this.here = here;
+ this.service = service;
+ }
+ public void acceptData(int resultCode) {
+ replied = true;
+ if (resultCode == 0) {
+ // accept
+ Message m = new DatagramAcknowledgedMessage(here, msg.getSourceNodeID());
+ downstream.put(m, service);
+ } else {
+ // reject
+ Message m = new DatagramRejectedMessage(here, msg.getSourceNodeID(), resultCode);
+ downstream.put(m, service);
+ }
+ }
+ boolean hasReplied() { return replied; }
+
+ }
+
/**
* Memo class to hold information about request while
* it's being processed.
Modified: trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java 2012-05-20 20:24:43 UTC (rev 2255)
+++ trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java 2012-05-20 20:25:45 UTC (rev 2256)
@@ -21,7 +21,7 @@
java.util.ArrayList<Message> repliesReturned1;
Connection replyConnection1;
- Connection testConnection;
+ Connection returnConnection;
java.util.ArrayList<Message> messagesForwarded;
Connection forwardConnection;
@@ -32,7 +32,7 @@
DatagramMessage datagram2;
DatagramAcknowledgedMessage replyOK;
- DatagramRejectedMessage replyNAK;
+ DatagramRejectedMessage replyNAKresend;
public void setUp() {
@@ -47,15 +47,15 @@
forwardConnection = new AbstractConnection(){
public void put(Message msg, Connection sender) {
messagesForwarded.add(msg);
- testConnection = sender;
+ Assert.assertEquals(returnConnection, sender);
}
};
- testConnection = null;
-
data = new int[32];
buffer = new DatagramMeteringBuffer(forwardConnection);
+
+ returnConnection = buffer.connectionForRepliesFromDownstream();
data[0] = 1;
datagram1 = new DatagramMessage(hereID, farID, data);
@@ -63,7 +63,7 @@
datagram2 = new DatagramMessage(hereID, farID, data);
replyOK = new DatagramAcknowledgedMessage(farID, hereID);
- replyNAK = new DatagramRejectedMessage(farID, hereID, 0x010);
+ replyNAKresend = new DatagramRejectedMessage(farID, hereID, 0x210);
}
public void testSend() throws InterruptedException {
@@ -79,7 +79,6 @@
Thread.currentThread().sleep(10);
Assert.assertEquals("forwarded messages", 1, messagesForwarded.size());
Assert.assertTrue(messagesForwarded.get(0).equals(m));
- Assert.assertTrue(testConnection != null);
}
public void testFirstDatagramSendGoesThrough() throws InterruptedException {
@@ -88,16 +87,14 @@
Thread.currentThread().sleep(10);
Assert.assertEquals("forwarded messages", 1, messagesForwarded.size());
Assert.assertTrue(messagesForwarded.get(0).equals(datagram1));
- Assert.assertTrue(testConnection != null);
}
public void testSendReplyOK() throws InterruptedException {
buffer.put(datagram1, replyConnection1);
Thread.currentThread().sleep(10);
- Assert.assertTrue(testConnection != null);
- testConnection.put(replyOK, null);
+ returnConnection.put(replyOK, null);
Assert.assertEquals("reply messages", 1, repliesReturned1.size());
Assert.assertTrue(repliesReturned1.get(0).equals(replyOK));
@@ -108,7 +105,7 @@
Thread.currentThread().sleep(10);
- testConnection.put(replyNAK, null);
+ returnConnection.put(replyNAKresend, null);
Assert.assertEquals("forwarded messages", 2, messagesForwarded.size());
Assert.assertTrue(messagesForwarded.get(1).equals(datagram1));
@@ -119,12 +116,12 @@
Thread.currentThread().sleep(10);
- testConnection.put(replyNAK, null);
+ returnConnection.put(replyNAKresend, null);
Assert.assertEquals("forwarded messages", 2, messagesForwarded.size());
Assert.assertTrue(messagesForwarded.get(1).equals(datagram1));
- testConnection.put(replyOK, null);
+ returnConnection.put(replyOK, null);
Assert.assertEquals("reply messages", 1, repliesReturned1.size());
Assert.assertTrue(repliesReturned1.get(0).equals(replyOK));
@@ -139,7 +136,6 @@
Assert.assertEquals("forwarded messages", 2, messagesForwarded.size());
Assert.assertTrue(messagesForwarded.get(0).equals(m));
Assert.assertTrue(messagesForwarded.get(1).equals(m));
- Assert.assertTrue(testConnection != null);
}
public void testSendTwoBeforeReply() throws InterruptedException {
@@ -150,11 +146,10 @@
Assert.assertEquals("forwarded messages", 1, messagesForwarded.size());
Assert.assertTrue(messagesForwarded.get(0).equals(datagram1));
- Assert.assertTrue(testConnection != null);
// now send the reply
- testConnection.put(replyOK, null);
+ returnConnection.put(replyOK, null);
Thread.currentThread().sleep(10);
Modified: trunk/prototypes/java/test/org/openlcb/implementations/DatagramServiceTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/DatagramServiceTest.java 2012-05-20 20:24:43 UTC (rev 2255)
+++ trunk/prototypes/java/test/org/openlcb/implementations/DatagramServiceTest.java 2012-05-20 20:25:45 UTC (rev 2256)
@@ -78,9 +78,10 @@
public void testReceiveDGbeforeReg() {
DatagramService.DatagramServiceReceiveMemo m20 =
new DatagramService.DatagramServiceReceiveMemo(0x20){
- public int handleData(int[] data) {
+ @Override
+ public void handleData(NodeID n, int[] data, DatagramService.ReplyMemo service) {
flag = true;
- return 0;
+ service.acceptData(0);
}
};
@@ -99,9 +100,10 @@
public void testReceiveFirstDG() {
DatagramService.DatagramServiceReceiveMemo m20 =
new DatagramService.DatagramServiceReceiveMemo(0x20){
- public int handleData( NodeID n, int[] data) {
+ @Override
+ public void handleData(NodeID n, int[] data, DatagramService.ReplyMemo service) {
flag = true;
- return 0;
+ service.acceptData(0);
}
};
@@ -120,9 +122,10 @@
public void testReceiveWrongDGType() {
DatagramService.DatagramServiceReceiveMemo m20 =
new DatagramService.DatagramServiceReceiveMemo(0x20){
- public int handleData(int[] data) {
+ @Override
+ public void handleData(NodeID n, int[] data, DatagramService.ReplyMemo service) {
flag = true;
- return 0;
+ service.acceptData(0);
}
};
@@ -143,6 +146,7 @@
int[] data = new int[]{1,2,3,4,5};
DatagramService.DatagramServiceTransmitMemo memo =
new DatagramService.DatagramServiceTransmitMemo(farID,data) {
+ @Override
public void handleReply(int code) {
flag = true;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|