|
From: <jac...@us...> - 2011-03-29 16:19:33
|
Revision: 1189
http://openlcb.svn.sourceforge.net/openlcb/?rev=1189&view=rev
Author: jacobsen
Date: 2011-03-29 16:19:27 +0000 (Tue, 29 Mar 2011)
Log Message:
-----------
allow annoations
Modified Paths:
--------------
trunk/prototypes/java/build.xml
trunk/prototypes/java/nbproject/project.xml
Modified: trunk/prototypes/java/build.xml
===================================================================
--- trunk/prototypes/java/build.xml 2011-03-29 16:01:43 UTC (rev 1188)
+++ trunk/prototypes/java/build.xml 2011-03-29 16:19:27 UTC (rev 1189)
@@ -36,6 +36,8 @@
<pathelement location="lib/junit.jar" />
<pathelement location="lib/jdom.jar" />
<pathelement location="lib/jlfgr-1_0.jar" />
+ <pathelement location="lib/annotations.jar" /> <!-- only needed for compile -->
+ <pathelement location="lib/jsr305.jar" /> <!-- only needed for compile -->
<pathelement location="/System/Library/Java" /> <!-- MacOS X -->
<pathelement location="${target}/" /> <!-- last to check for name collisions -->
</path>
Modified: trunk/prototypes/java/nbproject/project.xml
===================================================================
--- trunk/prototypes/java/nbproject/project.xml 2011-03-29 16:01:43 UTC (rev 1188)
+++ trunk/prototypes/java/nbproject/project.xml 2011-03-29 16:19:27 UTC (rev 1189)
@@ -111,6 +111,10 @@
<package-root>test</package-root>
<unit-tests/>
<classpath mode="compile">lib/junit.jar</classpath>
+ <classpath mode="compile">lib/jdom.jar</classpath>
+ <classpath mode="compile">lib/jlfgr-1_0.jar</classpath>
+ <classpath mode="compile">lib/annotations.jar</classpath>
+ <classpath mode="compile">lib/jsr305.jar</classpath>
<built-to>classes</built-to>
<source-level>1.5</source-level>
</compilation-unit>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2011-04-03 22:42:35
|
Revision: 1201
http://openlcb.svn.sourceforge.net/openlcb/?rev=1201&view=rev
Author: jacobsen
Date: 2011-04-03 22:42:29 +0000 (Sun, 03 Apr 2011)
Log Message:
-----------
add a simple demo selector to the demo jar file
Modified Paths:
--------------
trunk/prototypes/java/manifest
trunk/prototypes/java/openlcb-demo.jar
trunk/prototypes/java/openlcb.jar
trunk/prototypes/java/test/AllTest.java
Added Paths:
-----------
trunk/prototypes/java/test/scenarios/PackageTest.java
trunk/prototypes/java/test/scenarios/ScenarioRunner.java
Removed Paths:
-------------
trunk/prototypes/java/test/scenarios/Scenarios.java
Modified: trunk/prototypes/java/manifest
===================================================================
--- trunk/prototypes/java/manifest 2011-04-03 19:01:58 UTC (rev 1200)
+++ trunk/prototypes/java/manifest 2011-04-03 22:42:29 UTC (rev 1201)
@@ -1,5 +1,5 @@
Manifest-Version: 1.0
-Main-Class: scenarios.BlueGoldCheck
+Main-Class: scenarios.ScenarioRunner
Class-Path: lib/junit.jar lib/jdom.jar lib/jlfgr-1_0.jar
Name: org.openlcb
Modified: trunk/prototypes/java/openlcb-demo.jar
===================================================================
(Binary files differ)
Modified: trunk/prototypes/java/openlcb.jar
===================================================================
(Binary files differ)
Modified: trunk/prototypes/java/test/AllTest.java
===================================================================
--- trunk/prototypes/java/test/AllTest.java 2011-04-03 19:01:58 UTC (rev 1200)
+++ trunk/prototypes/java/test/AllTest.java 2011-04-03 22:42:29 UTC (rev 1201)
@@ -29,7 +29,7 @@
TestSuite suite = new TestSuite(AllTest.class);
suite.addTest(tools.ToolsTest.suite());
suite.addTest(org.openlcb.NetTest.suite());
- suite.addTest(scenarios.Scenarios.suite());
+ suite.addTest(scenarios.PackageTest.suite());
return suite;
}
}
Copied: trunk/prototypes/java/test/scenarios/PackageTest.java (from rev 1175, trunk/prototypes/java/test/scenarios/Scenarios.java)
===================================================================
--- trunk/prototypes/java/test/scenarios/PackageTest.java (rev 0)
+++ trunk/prototypes/java/test/scenarios/PackageTest.java 2011-04-03 22:42:29 UTC (rev 1201)
@@ -0,0 +1,55 @@
+package scenarios;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Primary test runner for this package.
+ *
+ * @author Bob Jacobsen Copyright 2009
+ * @version $Revision$
+ */
+public class PackageTest extends TestCase {
+ public void testStart() {
+ }
+
+ // BlueGoldCheck not JUnit so can run standalone
+ public void testBlueGold() throws Exception {
+ BlueGoldCheck.runTest();
+ }
+
+ // ConfigDemoApplet not JUnit so can run standalone
+ public void testConfigDemoApplet() throws Exception {
+ ConfigDemoApplet.runTest();
+ }
+
+ // 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(NineOnALink.suite());
+
+ suite.addTest(TwoBuses.suite());
+ suite.addTest(TwoBusesFiltered.suite());
+ suite.addTest(ThreeBuses.suite());
+
+ suite.addTest(scenarios.can.CanScenarios.suite());
+
+ // Applets done above
+
+ return suite;
+ }
+}
Copied: trunk/prototypes/java/test/scenarios/ScenarioRunner.java (from rev 1175, trunk/prototypes/java/test/scenarios/Scenarios.java)
===================================================================
--- trunk/prototypes/java/test/scenarios/ScenarioRunner.java (rev 0)
+++ trunk/prototypes/java/test/scenarios/ScenarioRunner.java 2011-04-03 22:42:29 UTC (rev 1201)
@@ -0,0 +1,50 @@
+package scenarios;
+
+import javax.swing.*;
+import java.awt.event.*;
+
+/**
+ * Simple interface to select which scenario to run
+ *
+ * @author Bob Jacobsen Copyright 2010
+ * @version $Revision$
+ */
+public class ScenarioRunner {
+
+ // Main entry point
+ static public void main(String[] args) {
+
+ JFrame f = new JFrame("OpenLCB Demo Selector");
+
+ JPanel p = new JPanel();
+ f.add(p);
+ p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
+
+ p.add(new JLabel("Click a button to start the"));
+ p.add(new JLabel("corresponding OpenLCB demo."));
+ p.add(new JLabel(""));
+ JButton b;
+ b = new JButton("Configuration Tool Demo");
+ b.addActionListener(new ActionListener(){
+ public void actionPerformed(ActionEvent e) {
+ try {
+ scenarios.ConfigDemoApplet.main((String[])null);
+ } catch (Exception ex) {ex.printStackTrace();}
+ }
+ });
+ p.add(b);
+ b = new JButton("Blue/Gold Configuration Demo");
+ b.addActionListener(new ActionListener(){
+ public void actionPerformed(ActionEvent e) {
+ try {
+ scenarios.BlueGoldCheck.main((String[])null);
+ } catch (Exception ex) {ex.printStackTrace();}
+ }
+ });
+ p.add(b);
+
+ f.pack();
+ f.setVisible(true);
+ }
+
+}
Deleted: trunk/prototypes/java/test/scenarios/Scenarios.java
===================================================================
--- trunk/prototypes/java/test/scenarios/Scenarios.java 2011-04-03 19:01:58 UTC (rev 1200)
+++ trunk/prototypes/java/test/scenarios/Scenarios.java 2011-04-03 22:42:29 UTC (rev 1201)
@@ -1,55 +0,0 @@
-package scenarios;
-
-import junit.framework.Assert;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Primary test runner for this package.
- *
- * @author Bob Jacobsen Copyright 2009
- * @version $Revision$
- */
-public class Scenarios extends TestCase {
- public void testStart() {
- }
-
- // BlueGoldCheck not JUnit so can run standalone
- public void testBlueGold() throws Exception {
- BlueGoldCheck.runTest();
- }
-
- // ConfigDemoApplet not JUnit so can run standalone
- public void testConfigDemoApplet() throws Exception {
- ConfigDemoApplet.runTest();
- }
-
- // from here down is testing infrastructure
-
- public Scenarios(String s) {
- super(s);
- }
-
- // Main entry point
- static public void main(String[] args) {
- String[] testCaseName = {Scenarios.class.getName()};
- junit.swingui.TestRunner.main(testCaseName);
- }
-
- // test suite from all defined tests
- public static Test suite() {
- TestSuite suite = new TestSuite(Scenarios.class);
- suite.addTest(NineOnALink.suite());
-
- suite.addTest(TwoBuses.suite());
- suite.addTest(TwoBusesFiltered.suite());
- suite.addTest(ThreeBuses.suite());
-
- suite.addTest(scenarios.can.CanScenarios.suite());
-
- // Applets done above
-
- return suite;
- }
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2011-07-24 01:43:00
|
Revision: 1404
http://openlcb.svn.sourceforge.net/openlcb/?rev=1404&view=rev
Author: jacobsen
Date: 2011-07-24 01:42:54 +0000 (Sun, 24 Jul 2011)
Log Message:
-----------
MTI bits updated; some restructure to localize change
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/OpenLcb.java
trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java
trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java
trunk/prototypes/java/test/org/openlcb/can/MessageBuilderTest.java
Removed Paths:
-------------
trunk/prototypes/java/src/org/openlcb/can/OpenLcbCan.java
Modified: trunk/prototypes/java/src/org/openlcb/OpenLcb.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/OpenLcb.java 2011-07-24 01:42:14 UTC (rev 1403)
+++ trunk/prototypes/java/src/org/openlcb/OpenLcb.java 2011-07-24 01:42:54 UTC (rev 1404)
@@ -10,20 +10,20 @@
static final int MTI_INITIALIZATION_COMPLETE = 0x3080;
static final int MTI_VERIFY_NID = 0x30A4;
- static final int MTI_VERIFIED_NID = 0x30B0; // also 30B2
+ static final int MTI_VERIFIED_NID = 0x30B0;
- static final int MTI_IDENTIFY_CONSUMERS = 0x3242;
+ static final int MTI_IDENTIFY_CONSUMERS = 0x1242;
static final int MTI_IDENTIFY_CONSUMERS_RANGE = 0x3252;
static final int MTI_CONSUMER_IDENTIFIED = 0x3263;
- static final int MTI_IDENTIFY_PRODUCERS = 0x3282;
+ static final int MTI_IDENTIFY_PRODUCERS = 0x1282;
static final int MTI_IDENTIFY_PRODUCERS_RANGE = 0x3292;
static final int MTI_PRODUCER_IDENTIFIED = 0x32A3;
- static final int MTI_IDENTIFY_EVENTS = 0x32B0; // also 32B2
+ static final int MTI_IDENTIFY_EVENTS = 0x32B4;
- static final int MTI_LEARN_EVENT = 0x32C2;
- static final int MTI_PC_EVENT_REPORT = 0x32D2;
+ static final int MTI_LEARN_EVENT = 0x12C2;
+ static final int MTI_PC_EVENT_REPORT = 0x12D2;
static final int MTI_DATAGRAM = 0x3404;
static final int MTI_DATAGRAM_RCV_OK = 0x34C4;
Modified: trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java 2011-07-24 01:42:14 UTC (rev 1403)
+++ trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java 2011-07-24 01:42:54 UTC (rev 1404)
@@ -85,18 +85,13 @@
break;
case OpenLcb.MTI_DATAGRAM:
- case OpenLcb.MTI_DATAGRAM_RCV_OK:
- case OpenLcb.MTI_DATAGRAM_REJECTED:
case OpenLcb.MTI_STREAM_INIT_REQUEST:
case OpenLcb.MTI_STREAM_INIT_REPLY:
case OpenLcb.MTI_STREAM_DATA_SEND:
case OpenLcb.MTI_STREAM_DATA_PROCEED:
case OpenLcb.MTI_STREAM_DATA_COMPLETE:
-
- //case OpenLcb.MTI_IDENTIFY_CONSUMERS_RANGE:
- //case OpenLcb.MTI_IDENTIFY_PRODUCERS_RANGE:
-
+
default:
// this is an error
}
Deleted: trunk/prototypes/java/src/org/openlcb/can/OpenLcbCan.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/OpenLcbCan.java 2011-07-24 01:42:14 UTC (rev 1403)
+++ trunk/prototypes/java/src/org/openlcb/can/OpenLcbCan.java 2011-07-24 01:42:54 UTC (rev 1404)
@@ -1,44 +0,0 @@
-package org.openlcb.can;
-
-public interface OpenLcbCan {
-
- /**
- * OpenLCB CAN MTI format bits
- */
- static final int MTI_FORMAT_SIMPLE_MTI = 0;
- static final int MTI_FORMAT_COMPLEX_MTI = 1;
- //
- //
- static final int MTI_FORMAT_ADDRESSED_DATAGRAM = 4;
- static final int MTI_FORMAT_ADDRESSED_DATAGRAM_LAST = 5;
- static final int MTI_FORMAT_ADDRESSED_NON_DATAGRAM = 6;
- static final int MTI_FORMAT_STREAM_CODE = 7;
-
-
- /**
- * Basic header MTI definitions for OpenLCB on CAN.
- * Low bits 0x00F on all of these automatically
- */
-
- static final int MTI_INITIALIZATION_COMPLETE = 0x08F;
-
- static final int MTI_VERIFY_NID = 0x0AF;
- static final int MTI_VERIFIED_NID = 0x0BF;
-
- static final int MTI_IDENTIFY_CONSUMERS = 0x24F;
- static final int MTI_IDENTIFY_CONSUMERS_RANGE = 0x25F;
- static final int MTI_CONSUMER_IDENTIFIED = 0x26F;
-
- static final int MTI_IDENTIFY_PRODUCERS = 0x28F;
- static final int MTI_IDENTIFY_PRODUCERS_RANGE = 0x29F;
- static final int MTI_PRODUCER_IDENTIFIED = 0x2AF;
-
- static final int MTI_IDENTIFY_EVENTS = 0x2BF;
-
- static final int MTI_LEARN_EVENT = 0x2CF;
- static final int MTI_PC_EVENT_REPORT = 0x2DF;
-
- static final int MTI_DATAGRAM_RCV_OK = 0x4CF;
- static final int MTI_DATAGRAM_REJECTED = 0x4DF;
-
-}
\ No newline at end of file
Modified: trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java 2011-07-24 01:42:14 UTC (rev 1403)
+++ trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java 2011-07-24 01:42:54 UTC (rev 1404)
@@ -15,7 +15,7 @@
*/
-public class OpenLcbCanFrame implements CanFrame, OpenLcbCan {
+public class OpenLcbCanFrame implements CanFrame {
public OpenLcbCanFrame(int nodeAlias) {
this.nodeAlias = nodeAlias;
@@ -343,4 +343,43 @@
}
return retval;
}
+
+ // the following constants really shouldn't leak out of this class
+
+ /**
+ * OpenLCB CAN MTI format bits
+ */
+ static final int MTI_FORMAT_SIMPLE_MTI = 0;
+ static final int MTI_FORMAT_COMPLEX_MTI = 1;
+ //
+ //
+ static final int MTI_FORMAT_ADDRESSED_DATAGRAM = 4;
+ static final int MTI_FORMAT_ADDRESSED_DATAGRAM_LAST = 5;
+ static final int MTI_FORMAT_ADDRESSED_NON_DATAGRAM = 6;
+ static final int MTI_FORMAT_STREAM_CODE = 7;
+
+
+ /**
+ * Basic header MTI definitions for OpenLCB on CAN.
+ */
+
+ static final int MTI_INITIALIZATION_COMPLETE = 0x087;
+
+ static final int MTI_VERIFY_NID = 0x0A7;
+ static final int MTI_VERIFIED_NID = 0x0B7;
+
+ static final int MTI_IDENTIFY_CONSUMERS = 0x24F;
+ static final int MTI_IDENTIFY_CONSUMERS_RANGE = 0x25F;
+ static final int MTI_CONSUMER_IDENTIFIED = 0x26B;
+
+ static final int MTI_IDENTIFY_PRODUCERS = 0x28F;
+ static final int MTI_IDENTIFY_PRODUCERS_RANGE = 0x29F;
+ static final int MTI_PRODUCER_IDENTIFIED = 0x2AB;
+
+ static final int MTI_IDENTIFY_EVENTS = 0x2B7;
+
+ static final int MTI_LEARN_EVENT = 0x2CF;
+ static final int MTI_PC_EVENT_REPORT = 0x2DF;
+
+
}
Modified: trunk/prototypes/java/test/org/openlcb/can/MessageBuilderTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/can/MessageBuilderTest.java 2011-07-24 01:42:14 UTC (rev 1403)
+++ trunk/prototypes/java/test/org/openlcb/can/MessageBuilderTest.java 2011-07-24 01:42:54 UTC (rev 1404)
@@ -29,7 +29,7 @@
Assert.assertEquals("count", 1, list.size());
CanFrame f0 = list.get(0);
- Assert.assertEquals("header", toHexString(0x1908f123), toHexString(f0.getHeader()));
+ Assert.assertEquals("header", toHexString(0x19087123), toHexString(f0.getHeader()));
compareContent(source.getContents(), f0);
}
public void testVerifyNodeIDNumberMessage() {
@@ -43,7 +43,7 @@
Assert.assertEquals("count", 1, list.size());
CanFrame f0 = list.get(0);
- Assert.assertEquals("header", toHexString(0x190af123), toHexString(f0.getHeader()));
+ Assert.assertEquals("header", toHexString(0x190a7123), toHexString(f0.getHeader()));
compareContent(null, f0);
}
public void testVerifiedNodeIDNumberMessage() {
@@ -57,7 +57,7 @@
Assert.assertEquals("count", 1, list.size());
CanFrame f0 = list.get(0);
- Assert.assertEquals("header", toHexString(0x190bf123), toHexString(f0.getHeader()));
+ Assert.assertEquals("header", toHexString(0x190b7123), toHexString(f0.getHeader()));
compareContent(source.getContents(), f0);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-01-27 03:45:17
|
Revision: 1679
http://openlcb.svn.sourceforge.net/openlcb/?rev=1679&view=rev
Author: jacobsen
Date: 2012-01-27 03:45:10 +0000 (Fri, 27 Jan 2012)
Log Message:
-----------
make links to sample XML file explicit
Modified Paths:
--------------
trunk/prototypes/java/ConfigDemoApplet.html
trunk/prototypes/java/index.html
Added Paths:
-----------
trunk/prototypes/java/sample.xml
trunk/prototypes/java/sample2.xml
Modified: trunk/prototypes/java/ConfigDemoApplet.html
===================================================================
--- trunk/prototypes/java/ConfigDemoApplet.html 2012-01-26 21:22:41 UTC (rev 1678)
+++ trunk/prototypes/java/ConfigDemoApplet.html 2012-01-27 03:45:10 UTC (rev 1679)
@@ -36,6 +36,11 @@
</ul>
<p>
+The CDI for this demo is in XML format, as shown in this
+<a href="sample2.xml">sample XML document</a> (depending on your browser, you
+may have to "view source" to see it after clicking)
+
+<p>
Note this that is just a demo. The read/write buttons don't work yet!
Also, we haven't done much work on the cosmetics, so some things will look odd,
the layout on the screen takes too much space, etc.
Modified: trunk/prototypes/java/index.html
===================================================================
--- trunk/prototypes/java/index.html 2012-01-26 21:22:41 UTC (rev 1678)
+++ trunk/prototypes/java/index.html 2012-01-27 03:45:10 UTC (rev 1679)
@@ -34,6 +34,9 @@
<P><A HREF="BlueGoldApplet.html">Applet demonstration</A> of
Blue/Gold configuration.
</P>
+<P><A HREF="ConfigDemoApplet.html">Applet demonstration</A> of
+configuration tool loading from <a href="sample2.xml">sample node XML</a>.
+</P>
<P>Major subdirectories:</P>
<DL>
<DT><A HREF="src">src</A>
Added: trunk/prototypes/java/sample.xml
===================================================================
--- trunk/prototypes/java/sample.xml (rev 0)
+++ trunk/prototypes/java/sample.xml 2012-01-27 03:45:10 UTC (rev 1679)
@@ -0,0 +1,51 @@
+<cdi>
+
+<identification>
+ <manufacturer>Spacely Sprokets</manufacturer>
+ <model>Model 123 Uniblab</model>
+ <hardwareVersion>EC 415</hardwareVersion>
+ <softwareVersion>1.2.3.4</softwareVersion>
+ <map>
+ <relation><property>Size</property><value>8 cm by 12 cm</value></relation>
+ </map>
+</identification>
+
+<segment origin="0" space="0">
+ <group offset="0" reps="2">
+ <name>Produced Events</name>
+ <description>The EventIDs for the producers</description>
+ <eventid/>
+ <eventid/>
+ </group>
+ <group reps="2">
+ <name>Consumed Events</name>
+ <description>The EventIDs for the consumers</description>
+ <eventid/>
+ <eventid/>
+ </group>
+ <bit>
+ <name>Sample bit variable</name>
+ <description>Doesn't do anything</description>
+ </bit>
+ <int size="2">
+ <name>Sample integer variable</name>
+ <description>Doesn't do anything</description>
+ <min>1</min>
+ <max>999</max>
+ <default>12</default>
+ </int>
+</segment>
+
+<segment origin="128" space="1">
+ <int size="1">
+ <name>Reset</name>
+ <description>Controls reloading and clearing node memory. Board must be restarted for this to take effect.</description>
+ <map>
+ <relation><property>85</property><value>(No reset)</value></relation>
+ <relation><property>0</property><value>Reset all to defaults</value></relation>
+ <relation><property>170</property><value>Reset just EventIDs to defaults</value></relation>
+ </map>
+ </int>
+</segment>
+
+</cdi>
Added: trunk/prototypes/java/sample2.xml
===================================================================
--- trunk/prototypes/java/sample2.xml (rev 0)
+++ trunk/prototypes/java/sample2.xml 2012-01-27 03:45:10 UTC (rev 1679)
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<cdi>
+ <identification>
+ <manufacturer>OpenLCB Prototype</manufacturer>
+ <model>Basic sketch</model>
+ <hardwareVersion>Arduino (any)</hardwareVersion>
+ <softwareVersion>0.4</softwareVersion>
+ <map>
+ <relation>
+ <property>size</property>
+ <value>8 cm by 12 cm</value>
+ </relation>
+ <relation>
+ <property>weight</property>
+ <value>220g</value>
+ </relation>
+ <relation>
+ <property>power</property>
+ <value>12V at 100mA</value>
+ </relation>
+ </map>
+ </identification>
+ <segment space="0" origin="0">
+ <name>Content</name>
+ <description>Variables for controlling general operation</description>
+ <group>
+ <name>Produced Events</name>
+ <description>The EventIDs for the producers</description>
+ <eventid />
+ <eventid />
+ </group>
+ <group>
+ <name>Consumed Events</name>
+ <description>The EventIDs for the consumers</description>
+ <eventid />
+ <eventid />
+ </group>
+ <bit>
+ <name>Regular bit variable</name>
+ <description>Demonstrate how a standard bit (boolean) variable can be shown</description>
+ </bit>
+ <bit>
+ <name>Bit variable with named states</name>
+ <description>Demonstrate how a map relabels the states of a bit (boolean) variable</description>
+ <map>
+ <relation>
+ <property>true</property>
+ <value>Lit</value>
+ </relation>
+ <relation>
+ <property>false</property>
+ <value>Not Lit</value>
+ </relation>
+ </map>
+ </bit>
+ </segment>
+ <segment space="1" origin="128">
+ <name>Resets</name>
+ <description>Memory locations controlling resets</description>
+ <int size="1">
+ <name>Reset</name>
+ <description>Controls reloading and clearing node memory. Board must be restarted for this to take effect.</description>
+ <map>
+ <relation>
+ <property>85</property>
+ <value>(No reset)</value>
+ </relation>
+ <relation>
+ <property>0</property>
+ <value>Reset all to defaults</value>
+ </relation>
+ <relation>
+ <property>170</property>
+ <value>Reset just EventIDs to defaults</value>
+ </relation>
+ </map>
+ </int>
+ </segment>
+ <segment space="3" origin="0">
+ <name>Demos</name>
+ <description>Demonstrations of various CDI capabilities</description>
+ <group replication="2">
+ <name>Outer Group</name>
+ <description>The contents of this group are replicated by 2</description>
+ <group replication="3">
+ <name>Inner Group</name>
+ <description>The contents of this group are replicated by 3</description>
+ <int size="1">
+ <name>Int inside groups</name>
+ <description>This is inside a 2x3 group</description>
+ </int>
+ </group>
+ </group>
+ </segment>
+</cdi>
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-01-29 07:35:59
|
Revision: 1688
http://openlcb.svn.sourceforge.net/openlcb/?rev=1688&view=rev
Author: jacobsen
Date: 2012-01-29 07:35:53 +0000 (Sun, 29 Jan 2012)
Log Message:
-----------
add ProtocolIdentificationProtocol decode
Modified Paths:
--------------
trunk/prototypes/java/test/org/openlcb/NetTest.java
Added Paths:
-----------
trunk/prototypes/java/src/org/openlcb/ProtocolIdentification.java
trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationTest.java
Added: trunk/prototypes/java/src/org/openlcb/ProtocolIdentification.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/ProtocolIdentification.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/ProtocolIdentification.java 2012-01-29 07:35:53 UTC (rev 1688)
@@ -0,0 +1,46 @@
+// ProtocolIdentification.java
+
+package org.openlcb;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Protocol Identification Protocol
+ *
+ * @see http://www.openlcb.org/trunk/specs/drafts/GenProtocolIdS.pdf
+ * @author Bob Jacobsen Copyright (C) 2010
+ * @version $Revision: 18542 $
+ *
+ */
+public class ProtocolIdentification {
+
+ public enum Protocols {
+ ProtocolIdentification( 0x800000000000L,"ProtocolIdentification"),
+ Datagram( 0x400000000000L,"Datagram"),
+ Stream( 0x200000000000L,"Stream"),
+ Configuration( 0x100000000000L,"Configuration"),
+ Reservation( 0x080000000000L,"Reservation"),
+ Display( 0x040000000000L,"Display"),
+ Identification( 0x020000000000L,"Identification"),
+ TeachingLearningConfiguration(0x010000000000L,"TeachingLearningConfiguration"),
+ RemoteButton( 0x008000000000L,"RemoteButton"),
+ AbbreviatedDefaultCDI( 0x004000000000L,"AbbreviatedDefaultCDI");
+
+ Protocols(long value, String name) {
+ this.value = value;
+ this.name = name;
+ }
+ long value;
+ String name;
+
+ static List<String> decode(long r) {
+ ArrayList<String> retval = new ArrayList<String>();
+ for (Protocols t : Protocols.values()) {
+ if ( (t.value & r) != 0 ) retval.add(t.name);
+ }
+ return retval;
+ }
+ }
+
+}
Modified: trunk/prototypes/java/test/org/openlcb/NetTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/NetTest.java 2012-01-27 23:21:42 UTC (rev 1687)
+++ trunk/prototypes/java/test/org/openlcb/NetTest.java 2012-01-29 07:35:53 UTC (rev 1688)
@@ -43,6 +43,7 @@
suite.addTest(IdentifyEventsMessageTest.suite());
suite.addTest(IdentifyProducersMessageTest.suite());
suite.addTest(InitializationCompleteMessageTest.suite());
+ suite.addTest(ProtocolIdentificationTest.suite());
suite.addTest(ProducerConsumerEventReportMessageTest.suite());
suite.addTest(ProducerIdentifiedMessageTest.suite());
suite.addTest(VerifiedNodeIDNumberMessageTest.suite());
Copied: trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationTest.java (from rev 1684, trunk/prototypes/java/test/org/openlcb/NodeTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationTest.java 2012-01-29 07:35:53 UTC (rev 1688)
@@ -0,0 +1,55 @@
+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 ProtocolIdentificationTest extends TestCase {
+ public void testCtor() {
+ new ProtocolIdentification();
+ }
+
+ public void testDecode0() {
+ java.util.List result = ProtocolIdentification.Protocols.decode(0x000000000000L);
+
+ Assert.assertEquals("length", 0, result.size());
+ }
+
+ public void testDecode1() {
+ java.util.List result = ProtocolIdentification.Protocols.decode(0x800000000000L);
+
+ Assert.assertEquals("length", 1, result.size());
+ Assert.assertEquals("result 1", "ProtocolIdentification", result.get(0));
+ }
+
+ public void testDecode2() {
+ java.util.List result = ProtocolIdentification.Protocols.decode(0x880000000000L);
+
+ Assert.assertEquals("length", 2, result.size());
+ Assert.assertEquals("result 1", "ProtocolIdentification", result.get(0));
+ Assert.assertEquals("result 2", "Reservation", result.get(1));
+ }
+
+ // from here down is testing infrastructure
+
+ public ProtocolIdentificationTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {ProtocolIdentificationTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(ProtocolIdentificationTest.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-01-29 08:42:52
|
Revision: 1689
http://openlcb.svn.sourceforge.net/openlcb/?rev=1689&view=rev
Author: jacobsen
Date: 2012-01-29 08:42:46 +0000 (Sun, 29 Jan 2012)
Log Message:
-----------
service method for support() check
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/ProtocolIdentification.java
trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationTest.java
Modified: trunk/prototypes/java/src/org/openlcb/ProtocolIdentification.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/ProtocolIdentification.java 2012-01-29 07:35:53 UTC (rev 1688)
+++ trunk/prototypes/java/src/org/openlcb/ProtocolIdentification.java 2012-01-29 08:42:46 UTC (rev 1689)
@@ -34,10 +34,14 @@
long value;
String name;
+ boolean supports(long r) {
+ return ( (this.value & r) != 0 );
+ }
+
static List<String> decode(long r) {
ArrayList<String> retval = new ArrayList<String>();
for (Protocols t : Protocols.values()) {
- if ( (t.value & r) != 0 ) retval.add(t.name);
+ if ( t.supports(r) ) retval.add(t.name);
}
return retval;
}
Modified: trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationTest.java 2012-01-29 07:35:53 UTC (rev 1688)
+++ trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationTest.java 2012-01-29 08:42:46 UTC (rev 1689)
@@ -35,6 +35,18 @@
Assert.assertEquals("result 2", "Reservation", result.get(1));
}
+ public void testSupports1() {
+ ProtocolIdentification.Protocols p = ProtocolIdentification.Protocols.Datagram;
+
+ Assert.assertTrue("supports", p.supports(~0));
+ }
+
+ public void testSupports2() {
+ ProtocolIdentification.Protocols p = ProtocolIdentification.Protocols.Datagram;
+
+ Assert.assertTrue("supports", !p.supports(0));
+ }
+
// from here down is testing infrastructure
public ProtocolIdentificationTest(String s) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-02-02 17:29:00
|
Revision: 1711
http://openlcb.svn.sourceforge.net/openlcb/?rev=1711&view=rev
Author: jacobsen
Date: 2012-02-02 17:28:49 +0000 (Thu, 02 Feb 2012)
Log Message:
-----------
new class for 0.4
Modified Paths:
--------------
trunk/prototypes/java/test/org/openlcb/NetTest.java
Added Paths:
-----------
trunk/prototypes/java/src/org/openlcb/MimicNodeStore.java
trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java
Copied: trunk/prototypes/java/src/org/openlcb/MimicNodeStore.java (from rev 1709, trunk/prototypes/java/src/org/openlcb/Node.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/MimicNodeStore.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/MimicNodeStore.java 2012-02-02 17:28:49 UTC (rev 1711)
@@ -0,0 +1,38 @@
+package org.openlcb;
+
+import java.util.HashMap;
+import java.util.Collection;
+
+/**
+ * Store containing mimic proxies for nodes on external connections
+ * <p>
+ * Provides a Connection for incoming Messages.
+ *
+ * @author Bob Jacobsen Copyright 2011
+ * @version $Revision$
+ */
+public class MimicNodeStore extends MessageDecoder implements Connection {
+ public MimicNodeStore() {
+ }
+
+ public Collection<NodeMemo> getNodeMemos() {
+ return map.values();
+ }
+
+ public void put(Message msg, Connection sender) {
+ if (map.get(msg.getSourceNodeID()) == null)
+ map.put(msg.getSourceNodeID(), new NodeMemo(msg.getSourceNodeID()));
+ }
+
+ HashMap<NodeID, NodeMemo> map = new java.util.HashMap<NodeID, NodeMemo>();
+
+ class NodeMemo {
+ NodeID id;
+
+ public NodeMemo(NodeID id) { this.id = id; }
+
+ public NodeID getNodeID() {
+ return id;
+ }
+ }
+}
Copied: trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java (from rev 1709, trunk/prototypes/java/test/org/openlcb/NodeTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java 2012-02-02 17:28:49 UTC (rev 1711)
@@ -0,0 +1,92 @@
+package org.openlcb;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import java.util.Collection;
+
+/**
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision$
+ */
+public class MimicNodeStoreTest extends TestCase {
+ MimicNodeStore store = null;
+
+ NodeID nid1 = new NodeID(new byte[]{1,3,3,4,5,6});
+ NodeID nid2 = new NodeID(new byte[]{2,3,3,4,5,6});
+
+ ProducerIdentifiedMessage pim1 = new ProducerIdentifiedMessage(nid1,
+ new EventID(new byte[]{1,0,0,0,0,0,1,0}));
+
+ ProducerIdentifiedMessage pim2 = new ProducerIdentifiedMessage(nid2,
+ new EventID(new byte[]{1,0,0,0,0,0,1,0}));
+
+ public void setUp() {
+ store = new MimicNodeStore();
+ }
+
+ public void testCtor() {
+ Assert.assertNotNull(store);
+ }
+
+ public void testListExists() {
+ Collection<MimicNodeStore.NodeMemo> list = store.getNodeMemos();
+ Assert.assertNotNull(list);
+ }
+
+ public void testListInitiallyEmpty() {
+ Collection<MimicNodeStore.NodeMemo> list = store.getNodeMemos();
+ Assert.assertTrue(list.size()==0);
+ }
+
+ public void testAcceptsMessage() {
+ store.put(pim1,null);
+ }
+
+ public void testMessageAddsToList() {
+ store.put(pim1,null);
+ Collection<MimicNodeStore.NodeMemo> list = store.getNodeMemos();
+ Assert.assertTrue(list.size()==1);
+ }
+
+ public void testMessageMemoKnowsNodeID() {
+ store.put(pim1,null);
+ Collection<MimicNodeStore.NodeMemo> list = store.getNodeMemos();
+ Assert.assertEquals(list.iterator().next().getNodeID(), nid1);
+ }
+
+ public void testHandleMultipleNodes() {
+ store.put(pim1,null);
+ store.put(pim2,null);
+ Collection<MimicNodeStore.NodeMemo> list = store.getNodeMemos();
+ Assert.assertTrue(list.size()==2);
+ }
+
+ public void testHandleMultipleMessagesFromNode() {
+ store.put(pim1,null);
+ store.put(pim1,null);
+ Collection<MimicNodeStore.NodeMemo> list = store.getNodeMemos();
+ Assert.assertTrue(list.size()==1);
+ }
+
+
+ // from here down is testing infrastructure
+
+ public MimicNodeStoreTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {MimicNodeStoreTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(MimicNodeStoreTest.class);
+ return suite;
+ }
+}
Modified: trunk/prototypes/java/test/org/openlcb/NetTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/NetTest.java 2012-02-02 17:28:13 UTC (rev 1710)
+++ trunk/prototypes/java/test/org/openlcb/NetTest.java 2012-02-02 17:28:49 UTC (rev 1711)
@@ -54,6 +54,8 @@
suite.addTest(GatewayTest.suite());
+ suite.addTest(MimicNodeStoreTest.suite());
+
// test implementation classes
suite.addTest(org.openlcb.implementations.ImplementationsTest.suite());
suite.addTest(org.openlcb.swing.SwingTest.suite());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-02-04 15:45:41
|
Revision: 1716
http://openlcb.svn.sourceforge.net/openlcb/?rev=1716&view=rev
Author: jacobsen
Date: 2012-02-04 15:45:34 +0000 (Sat, 04 Feb 2012)
Log Message:
-----------
structure update
Modified Paths:
--------------
trunk/prototypes/java/index.html
trunk/prototypes/java/openlcb-demo.jar
trunk/prototypes/java/openlcb.jar
trunk/prototypes/java/src/org/openlcb/MessageDecoder.java
trunk/prototypes/java/src/org/openlcb/OpenLcb.java
trunk/prototypes/java/test/AllTest.java
Added Paths:
-----------
trunk/prototypes/java/src/org/openlcb/ConfigurationPortal.java
trunk/prototypes/java/src/org/openlcb/ProtocolIdentificationReplyMessage.java
trunk/prototypes/java/src/org/openlcb/ProtocolIdentificationRequestMessage.java
trunk/prototypes/java/src/org/openlcb/implementations/DatagramMeteringBuffer.java
trunk/prototypes/java/src/org/openlcb/swing/networktree/
trunk/prototypes/java/src/org/openlcb/swing/networktree/package-info.java
trunk/prototypes/java/test/org/openlcb/ConfigurationPortalTest.java
trunk/prototypes/java/test/org/openlcb/PackageTest.java
trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationReplyMessageTest.java
trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationRequestMessageTest.java
trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java
trunk/prototypes/java/test/org/openlcb/implementations/PackageTest.java
trunk/prototypes/java/versions.html
Removed Paths:
-------------
trunk/prototypes/java/test/org/openlcb/NetTest.java
trunk/prototypes/java/test/org/openlcb/implementations/ImplementationsTest.java
Modified: trunk/prototypes/java/index.html
===================================================================
--- trunk/prototypes/java/index.html 2012-02-03 21:22:21 UTC (rev 1715)
+++ trunk/prototypes/java/index.html 2012-02-04 15:45:34 UTC (rev 1716)
@@ -3,10 +3,10 @@
<HEAD>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8">
<TITLE>OpenLCB: Java Prototypes Directory</TITLE>
- <META NAME="GENERATOR" CONTENT="OpenOffice.org 3.2 (Unix)">
+ <META NAME="GENERATOR" CONTENT="OpenOffice.org 3.3 (Unix)">
<META NAME="CREATED" CONTENT="0;0">
<META NAME="CHANGEDBY" CONTENT="Bob Jacobsen">
- <META NAME="CHANGED" CONTENT="20110308;17033600">
+ <META NAME="CHANGED" CONTENT="20120129;10374100">
<META NAME="Info 1" CONTENT="">
<META NAME="Info 2" CONTENT="">
<META NAME="Info 3" CONTENT="">
@@ -14,10 +14,13 @@
<META NAME="CHANGEDBY" CONTENT="Bob Jacobsen">
<META NAME="CHANGEDBY" CONTENT="Bob Jacobsen">
<META NAME="CHANGEDBY" CONTENT="Bob Jacobsen">
+ <META NAME="CHANGEDBY" CONTENT="Bob Jacobsen">
<!-- $Id$ -->
<STYLE TYPE="text/css">
<!--
+ H2.cjk { font-family: "SimSun" }
H2.ctl { font-family: "Lucida Sans" }
+ H3.cjk { font-family: "SimSun" }
H3.ctl { font-family: "Lucida Sans" }
-->
</STYLE>
@@ -26,7 +29,7 @@
<H1><IMG SRC="../../web/logo-ajs-dph.png" NAME="OpenLCB" ALIGN=RIGHT WIDTH=344 HEIGHT=142 BORDER=0>OpenLCB
Proposal Java Prototypes Directory</H1>
<P>This directory contains prototype implementation(s) in Java of the
-proposed OpenLCB™ specification.
+proposed OpenLCB™ specification.
</P>
<P>These are primarily intended for testing proposed algorithms, not
as a first implementation for use.
@@ -35,7 +38,8 @@
Blue/Gold configuration.
</P>
<P><A HREF="ConfigDemoApplet.html">Applet demonstration</A> of
-configuration tool loading from <a href="sample2.xml">sample node XML</a>.
+configuration tool loading from <A HREF="sample2.xml">sample node
+XML</A>.
</P>
<P>Major subdirectories:</P>
<DL>
@@ -81,6 +85,14 @@
<P>The main OpenLCB library has no pre-requisite libraries.</P>
<P>The test code uses JUnit and JDOM via lib/junit.jar and
lib/jdom.jar respectively.</P>
+<H3 CLASS="western">Packaging and Versioning</H3>
+<P>For use in applications, we provide versioned Jar files containing
+parts of this prototype:</P>
+<P>openlcb.jar – contains the org.openlcb service classes, does not
+include test or demo classes</P>
+<P>openlcb-demo.jar – contains the demo code, including applets</P>
+<P>Version summary information is kept in SVN and on a
+<a href="versions.html">separate page</a>.</P>
<H2 CLASS="western">License</H2>
<P>All of the software in this directory and linked from this page is
copyrighted by its authors. You many only use it subject to its
Modified: trunk/prototypes/java/openlcb-demo.jar
===================================================================
(Binary files differ)
Modified: trunk/prototypes/java/openlcb.jar
===================================================================
(Binary files differ)
Copied: trunk/prototypes/java/src/org/openlcb/ConfigurationPortal.java (from rev 1711, trunk/prototypes/java/src/org/openlcb/SingleLinkNode.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/ConfigurationPortal.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/ConfigurationPortal.java 2012-02-04 15:45:34 UTC (rev 1716)
@@ -0,0 +1,23 @@
+package org.openlcb;
+
+/**
+ * Manages configuration interactions with a node
+ *
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision$
+ */
+public class ConfigurationPortal {
+
+ /**
+ * @param node NodeID of node being configured
+ * @param connection Connection for sending messages to node
+ */
+ public ConfigurationPortal(NodeID node, Connection connection) {
+ if (connection == null)
+ throw new IllegalArgumentException("Connection must be provided");
+ this.connection = connection;
+ }
+
+ protected Connection connection;
+
+}
Modified: trunk/prototypes/java/src/org/openlcb/MessageDecoder.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/MessageDecoder.java 2012-02-03 21:22:21 UTC (rev 1715)
+++ trunk/prototypes/java/src/org/openlcb/MessageDecoder.java 2012-02-04 15:45:34 UTC (rev 1716)
@@ -146,5 +146,16 @@
public void handleStreamDataComplete(StreamDataCompleteMessage msg, Connection sender){
defaultHandler(msg, sender);
}
-
+ /**
+ * Handle "Protocol Identification Request" message
+ */
+ public void handleProtocolIdentificationRequest(ProtocolIdentificationRequestMessage msg, Connection sender){
+ defaultHandler(msg, sender);
+ }
+ /**
+ * Handle "Protocol Identification Reply" message
+ */
+ public void handleProtocolIdentificationReply(ProtocolIdentificationReplyMessage msg, Connection sender){
+ defaultHandler(msg, sender);
+ }
}
Modified: trunk/prototypes/java/src/org/openlcb/OpenLcb.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/OpenLcb.java 2012-02-03 21:22:21 UTC (rev 1715)
+++ trunk/prototypes/java/src/org/openlcb/OpenLcb.java 2012-02-04 15:45:34 UTC (rev 1716)
@@ -35,4 +35,7 @@
static final int MTI_STREAM_DATA_PROCEED = 0x36A4;
static final int MTI_STREAM_DATA_COMPLETE = 0x36B4;
+ static final int MTI_PROTOCOL_IDENT_REQUEST = 0x0;
+ static final int MTI_PROTOCOL_IDENT_REPLY = 0x0;
+
}
\ No newline at end of file
Copied: trunk/prototypes/java/src/org/openlcb/ProtocolIdentificationReplyMessage.java (from rev 1711, trunk/prototypes/java/src/org/openlcb/ProtocolIdentification.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/ProtocolIdentificationReplyMessage.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/ProtocolIdentificationReplyMessage.java 2012-02-04 15:45:34 UTC (rev 1716)
@@ -0,0 +1,32 @@
+package org.openlcb;
+
+/**
+ * Reply message for the Protocol Identification protocol
+ *
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision: 529 $
+ */
+public class ProtocolIdentificationReplyMessage extends Message {
+
+ public ProtocolIdentificationReplyMessage(NodeID source) {
+ super(source);
+ }
+
+ /**
+ * Implement message-type-specific
+ * processing when this message
+ * is received by a node.
+ *<p>
+ * Default is to do nothing.
+ */
+ @Override
+ public void applyTo(MessageDecoder decoder, Connection sender) {
+ decoder.handleProtocolIdentificationReply(this, sender);
+ }
+ public String toString() {
+ return getSourceNodeID().toString()
+ +" Protocol Identification Reply ";
+ }
+
+ public int getMTI() { return MTI_PROTOCOL_IDENT_REPLY; }
+}
Copied: trunk/prototypes/java/src/org/openlcb/ProtocolIdentificationRequestMessage.java (from rev 1711, trunk/prototypes/java/src/org/openlcb/ProtocolIdentification.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/ProtocolIdentificationRequestMessage.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/ProtocolIdentificationRequestMessage.java 2012-02-04 15:45:34 UTC (rev 1716)
@@ -0,0 +1,32 @@
+package org.openlcb;
+
+/**
+ * Request message for the Protocol Identification protocol
+ *
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision: 529 $
+ */
+public class ProtocolIdentificationRequestMessage extends Message {
+
+ public ProtocolIdentificationRequestMessage(NodeID source) {
+ super(source);
+ }
+
+ /**
+ * Implement message-type-specific
+ * processing when this message
+ * is received by a node.
+ *<p>
+ * Default is to do nothing.
+ */
+ @Override
+ public void applyTo(MessageDecoder decoder, Connection sender) {
+ decoder.handleProtocolIdentificationRequest(this, sender);
+ }
+ public String toString() {
+ return getSourceNodeID().toString()
+ +" Protocol Identification Request ";
+ }
+
+ public int getMTI() { return MTI_PROTOCOL_IDENT_REQUEST; }
+}
Copied: trunk/prototypes/java/src/org/openlcb/implementations/DatagramMeteringBuffer.java (from rev 1711, trunk/prototypes/java/src/org/openlcb/implementations/DatagramTransmitter.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/DatagramMeteringBuffer.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/implementations/DatagramMeteringBuffer.java 2012-02-04 15:45:34 UTC (rev 1716)
@@ -0,0 +1,85 @@
+package org.openlcb.implementations;
+
+import org.openlcb.*;
+
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+
+/**
+ * Accepts Datagrams from one or more sources, and meters them out
+ * to a downstream node (e.g. on CAN), one at a time.
+ *<p>
+ * Does not parallelize Datagrams to separate nodes, but could
+ *
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision$
+ */
+public class DatagramMeteringBuffer extends MessageDecoder {
+
+ final static int TIMEOUT = 2000;
+
+ public DatagramMeteringBuffer(Connection downstream) {
+ this.downstream = downstream;
+ new Thread(new Consumer(queue)).start();
+ }
+
+ Connection downstream;
+
+ BlockingQueue<MessageMemo> queue = new LinkedBlockingQueue<MessageMemo>();
+
+ /**
+ * Accept a datagram message to be sent
+ */
+
+ public void put(Message msg, Connection upstream) {
+ queue.add(new MessageMemo(msg, upstream, downstream));
+ }
+
+ class MessageMemo extends MessageDecoder {
+ Message message;
+ Connection downstream;
+ Connection upstream;
+
+ MessageMemo(Message msg, Connection u, Connection d) {
+ message = msg;
+ upstream = u;
+ downstream = d;
+ }
+
+ public void sendIt() {
+ downstream.put(message, this);
+ }
+ /**
+ * Handle "Datagram Acknowledged" message
+ */
+ public void handleDatagramAcknowledged(DatagramAcknowledgedMessage msg, Connection sender){
+ // forward message upstream
+ upstream.put(msg, upstream);
+
+ // and allow sending another
+ new Thread(new Consumer(queue)).start();
+ }
+
+ /**
+ * Handle "Datagram Rejected" message
+ */
+ public void handleDatagramRejected(DatagramRejectedMessage msg, Connection sender){
+ // need to check if this is from right source
+
+ // resend
+ downstream.put(message, this);
+ }
+ }
+
+ class Consumer implements Runnable {
+ private final BlockingQueue<MessageMemo> queue;
+ Consumer(BlockingQueue<MessageMemo> q) { queue = q; }
+ public void run() {
+ try {
+ consume(queue.take());
+ } catch (InterruptedException ex) {}
+ }
+ void consume(MessageMemo x) { x.sendIt(); }
+ }
+
+}
Copied: trunk/prototypes/java/src/org/openlcb/swing/networktree/package-info.java (from rev 1711, trunk/prototypes/java/src/org/openlcb/package-info.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/swing/networktree/package-info.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/swing/networktree/package-info.java 2012-02-04 15:45:34 UTC (rev 1716)
@@ -0,0 +1,5 @@
+
+/**
+Provides JTree access to OpenLCB node information from the MimicNodeStore
+*/
+package org.openlcb.swing.networktree;
Modified: trunk/prototypes/java/test/AllTest.java
===================================================================
--- trunk/prototypes/java/test/AllTest.java 2012-02-03 21:22:21 UTC (rev 1715)
+++ trunk/prototypes/java/test/AllTest.java 2012-02-04 15:45:34 UTC (rev 1716)
@@ -28,7 +28,7 @@
public static Test suite() {
TestSuite suite = new TestSuite(AllTest.class);
suite.addTest(tools.ToolsTest.suite());
- suite.addTest(org.openlcb.NetTest.suite());
+ suite.addTest(org.openlcb.PackageTest.suite());
suite.addTest(scenarios.PackageTest.suite());
return suite;
}
Copied: trunk/prototypes/java/test/org/openlcb/ConfigurationPortalTest.java (from rev 1711, trunk/prototypes/java/test/org/openlcb/ProducerIdentifiedMessageTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/ConfigurationPortalTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/ConfigurationPortalTest.java 2012-02-04 15:45:34 UTC (rev 1716)
@@ -0,0 +1,70 @@
+package org.openlcb;
+
+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 ConfigurationPortalTest extends TestCase {
+ boolean result;
+
+ NodeID nodeID1 = new NodeID(new byte[]{1,2,3,4,5,6});
+
+ Connection connection = new Connection(){
+ public void put(Message m, Connection node) {
+ msg = m;
+ }
+ };
+
+ Message msg = null;
+
+ ConfigurationPortal portal = new ConfigurationPortal(nodeID1, connection);
+
+ public void setup() {
+ msg = null;
+ }
+
+ public void testCtor() {
+
+ }
+
+ public void testRequestWrite() {
+ }
+
+ public void testHandling() {
+ result = false;
+ Node n = new Node(){
+ @Override
+ public void handleProtocolIdentificationRequest(ProtocolIdentificationRequestMessage msg, Connection sender){
+ result = true;
+ }
+ };
+ Message m = new ProtocolIdentificationRequestMessage(nodeID1);
+
+ n.put(m, null);
+
+ Assert.assertTrue(result);
+ }
+
+ // from here down is testing infrastructure
+
+ public ConfigurationPortalTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {ConfigurationPortalTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(ConfigurationPortalTest.class);
+ return suite;
+ }
+}
Deleted: trunk/prototypes/java/test/org/openlcb/NetTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/NetTest.java 2012-02-03 21:22:21 UTC (rev 1715)
+++ trunk/prototypes/java/test/org/openlcb/NetTest.java 2012-02-04 15:45:34 UTC (rev 1716)
@@ -1,69 +0,0 @@
-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 NetTest extends TestCase {
- public void testStart() {
- }
-
- // from here down is testing infrastructure
-
- public NetTest(String s) {
- super(s);
- }
-
- // Main entry point
- static public void main(String[] args) {
- String[] testCaseName = {NetTest.class.getName()};
- junit.swingui.TestRunner.main(testCaseName);
- }
-
- // test suite from all defined tests
- public static Test suite() {
- TestSuite suite = new TestSuite(NetTest.class);
-
- suite.addTest(EventIDTest.suite());
- suite.addTest(NodeIDTest.suite());
-
- suite.addTest(MessageTest.suite());
-
- suite.addTest(MessageDecoderTest.suite());
- suite.addTest(NodeTest.suite());
-
- // specific message types (uses Node, IDs)
- suite.addTest(ConsumerIdentifiedMessageTest.suite());
- suite.addTest(IdentifyConsumersMessageTest.suite());
- suite.addTest(IdentifyEventsMessageTest.suite());
- suite.addTest(IdentifyProducersMessageTest.suite());
- suite.addTest(InitializationCompleteMessageTest.suite());
- suite.addTest(ProtocolIdentificationTest.suite());
- suite.addTest(ProducerConsumerEventReportMessageTest.suite());
- suite.addTest(ProducerIdentifiedMessageTest.suite());
- suite.addTest(VerifiedNodeIDNumberMessageTest.suite());
- suite.addTest(VerifyNodeIDNumberMessageTest.suite());
- suite.addTest(LearnEventMessageTest.suite());
-
- suite.addTest(SingleLinkNodeTest.suite());
-
- suite.addTest(GatewayTest.suite());
-
- suite.addTest(MimicNodeStoreTest.suite());
-
- // test implementation classes
- suite.addTest(org.openlcb.implementations.ImplementationsTest.suite());
- suite.addTest(org.openlcb.swing.SwingTest.suite());
- suite.addTest(org.openlcb.cdi.PackageTest.suite());
-
- // test CAN classes
- suite.addTest(org.openlcb.can.CanTest.suite());
-
- return suite;
- }
-}
Copied: trunk/prototypes/java/test/org/openlcb/PackageTest.java (from rev 1711, trunk/prototypes/java/test/org/openlcb/NetTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/PackageTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/PackageTest.java 2012-02-04 15:45:34 UTC (rev 1716)
@@ -0,0 +1,73 @@
+package org.openlcb;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * @author Bob Jacobsen Copyright 2009, 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(EventIDTest.suite());
+ suite.addTest(NodeIDTest.suite());
+
+ suite.addTest(MessageTest.suite());
+
+ suite.addTest(MessageDecoderTest.suite());
+ suite.addTest(NodeTest.suite());
+
+ // specific message types (uses Node, IDs)
+ suite.addTest(ConsumerIdentifiedMessageTest.suite());
+ suite.addTest(IdentifyConsumersMessageTest.suite());
+ suite.addTest(IdentifyEventsMessageTest.suite());
+ suite.addTest(IdentifyProducersMessageTest.suite());
+ suite.addTest(InitializationCompleteMessageTest.suite());
+ suite.addTest(ProtocolIdentificationTest.suite());
+ suite.addTest(ProducerConsumerEventReportMessageTest.suite());
+ suite.addTest(ProducerIdentifiedMessageTest.suite());
+ suite.addTest(VerifiedNodeIDNumberMessageTest.suite());
+ suite.addTest(VerifyNodeIDNumberMessageTest.suite());
+ suite.addTest(LearnEventMessageTest.suite());
+ suite.addTest(ProtocolIdentificationRequestMessageTest.suite());
+ suite.addTest(ProtocolIdentificationReplyMessageTest.suite());
+
+ suite.addTest(ConfigurationPortalTest.suite());
+
+ suite.addTest(SingleLinkNodeTest.suite());
+
+ suite.addTest(GatewayTest.suite());
+
+ suite.addTest(MimicNodeStoreTest.suite());
+
+ // test implementation classes
+ suite.addTest(org.openlcb.implementations.PackageTest.suite());
+ suite.addTest(org.openlcb.swing.SwingTest.suite());
+ suite.addTest(org.openlcb.cdi.PackageTest.suite());
+
+ // test CAN classes
+ suite.addTest(org.openlcb.can.CanTest.suite());
+
+ return suite;
+ }
+}
Copied: trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationReplyMessageTest.java (from rev 1711, trunk/prototypes/java/test/org/openlcb/ProducerIdentifiedMessageTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationReplyMessageTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationReplyMessageTest.java 2012-02-04 15:45:34 UTC (rev 1716)
@@ -0,0 +1,69 @@
+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 ProtocolIdentificationReplyMessageTest extends TestCase {
+ boolean result;
+
+ NodeID nodeID1 = new NodeID(new byte[]{1,2,3,4,5,6});
+ NodeID nodeID2 = new NodeID(new byte[]{0,0,0,0,0,0});
+
+ public void testEqualsSame() {
+ Message m1 = new ProtocolIdentificationReplyMessage(
+ nodeID1);
+ Message m2 = new ProtocolIdentificationReplyMessage(
+ nodeID1);
+
+ Assert.assertTrue(m1.equals(m2));
+ }
+
+ public void testNotEqualsDifferentNode() {
+ Message m1 = new ProtocolIdentificationReplyMessage(
+ nodeID1);
+ Message m2 = new ProtocolIdentificationReplyMessage(
+ nodeID2);
+
+ Assert.assertTrue( ! m1.equals(m2));
+ }
+
+
+ public void testHandling() {
+ result = false;
+ Node n = new Node(){
+ @Override
+ public void handleProtocolIdentificationReply(ProtocolIdentificationReplyMessage msg, Connection sender){
+ result = true;
+ }
+ };
+ Message m = new ProtocolIdentificationReplyMessage(nodeID1);
+
+ n.put(m, null);
+
+ Assert.assertTrue(result);
+ }
+
+ // from here down is testing infrastructure
+
+ public ProtocolIdentificationReplyMessageTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {ProtocolIdentificationReplyMessageTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(ProtocolIdentificationReplyMessageTest.class);
+ return suite;
+ }
+}
Copied: trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationRequestMessageTest.java (from rev 1711, trunk/prototypes/java/test/org/openlcb/ProducerIdentifiedMessageTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationRequestMessageTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationRequestMessageTest.java 2012-02-04 15:45:34 UTC (rev 1716)
@@ -0,0 +1,69 @@
+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 ProtocolIdentificationRequestMessageTest extends TestCase {
+ boolean result;
+
+ NodeID nodeID1 = new NodeID(new byte[]{1,2,3,4,5,6});
+ NodeID nodeID2 = new NodeID(new byte[]{0,0,0,0,0,0});
+
+ public void testEqualsSame() {
+ Message m1 = new ProtocolIdentificationRequestMessage(
+ nodeID1 );
+ Message m2 = new ProtocolIdentificationRequestMessage(
+ nodeID1 );
+
+ Assert.assertTrue(m1.equals(m2));
+ }
+
+ public void testNotEqualsDifferentNode() {
+ Message m1 = new ProtocolIdentificationRequestMessage(
+ nodeID1 );
+ Message m2 = new ProtocolIdentificationRequestMessage(
+ nodeID2 );
+
+ Assert.assertTrue( ! m1.equals(m2));
+ }
+
+
+ public void testHandling() {
+ result = false;
+ Node n = new Node(){
+ @Override
+ public void handleProtocolIdentificationRequest(ProtocolIdentificationRequestMessage msg, Connection sender){
+ result = true;
+ }
+ };
+ Message m = new ProtocolIdentificationRequestMessage(nodeID1);
+
+ n.put(m, null);
+
+ Assert.assertTrue(result);
+ }
+
+ // from here down is testing infrastructure
+
+ public ProtocolIdentificationRequestMessageTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {ProtocolIdentificationRequestMessageTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(ProtocolIdentificationRequestMessageTest.class);
+ return suite;
+ }
+}
Copied: trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java (from rev 1711, trunk/prototypes/java/test/org/openlcb/implementations/DatagramTransmitterTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java 2012-02-04 15:45:34 UTC (rev 1716)
@@ -0,0 +1,161 @@
+package org.openlcb.implementations;
+
+import org.openlcb.*;
+
+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 DatagramMeteringBufferTest extends TestCase {
+
+ NodeID hereID = new NodeID(new byte[]{1,2,3,4,5,6});
+ NodeID farID = new NodeID(new byte[]{1,1,1,1,1,1});
+
+ int[] data;
+
+ java.util.ArrayList<Message> repliesReturned1;
+ Connection replyConnection1;
+
+ Connection testConnection;
+
+ java.util.ArrayList<Message> messagesForwarded;
+ Connection forwardConnection;
+
+ DatagramMeteringBuffer buffer;
+
+ DatagramMessage datagram1;
+ DatagramMessage datagram2;
+
+ DatagramAcknowledgedMessage replyOK;
+ DatagramRejectedMessage replyNAK;
+
+ public void setUp() {
+
+ repliesReturned1 = new java.util.ArrayList<Message>();
+ replyConnection1 = new Connection(){
+ public void put(Message msg, Connection sender) {
+ repliesReturned1.add(msg);
+ }
+ };
+
+ messagesForwarded = new java.util.ArrayList<Message>();
+ forwardConnection = new Connection(){
+ public void put(Message msg, Connection sender) {
+ messagesForwarded.add(msg);
+ testConnection = sender;
+ }
+ };
+
+ testConnection = null;
+
+ data = new int[32];
+
+ buffer = new DatagramMeteringBuffer(forwardConnection);
+
+ data[0] = 1;
+ datagram1 = new DatagramMessage(hereID, farID, data);
+ data[0] = 2;
+ datagram2 = new DatagramMessage(hereID, farID, data);
+
+ replyOK = new DatagramAcknowledgedMessage(farID, hereID);
+ replyNAK = new DatagramRejectedMessage(farID, hereID);
+ }
+
+ public void testSend() throws InterruptedException {
+ buffer.put(datagram1, replyConnection1);
+
+ Thread.currentThread().sleep(10);
+ }
+
+ public void testSendGoesThrough() throws InterruptedException {
+ buffer.put(datagram1, replyConnection1);
+
+ Thread.currentThread().sleep(10);
+ Assert.assertEquals("forwarded messages", 1, messagesForwarded.size());
+ Assert.ass...
[truncated message content] |
|
From: <jac...@us...> - 2012-02-04 16:39:30
|
Revision: 1717
http://openlcb.svn.sourceforge.net/openlcb/?rev=1717&view=rev
Author: jacobsen
Date: 2012-02-04 16:39:24 +0000 (Sat, 04 Feb 2012)
Log Message:
-----------
datagram immutable
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/DatagramMessage.java
trunk/prototypes/java/src/org/openlcb/implementations/DatagramMeteringBuffer.java
trunk/prototypes/java/test/org/openlcb/PackageTest.java
trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java
Added Paths:
-----------
trunk/prototypes/java/test/org/openlcb/DatagramMessageTest.java
Modified: trunk/prototypes/java/src/org/openlcb/DatagramMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/DatagramMessage.java 2012-02-04 15:45:34 UTC (rev 1716)
+++ trunk/prototypes/java/src/org/openlcb/DatagramMessage.java 2012-02-04 16:39:24 UTC (rev 1717)
@@ -8,13 +8,34 @@
*/
public class DatagramMessage extends AddressedMessage {
- public DatagramMessage(NodeID source, NodeID dest, int[] data) {
+ public DatagramMessage(NodeID source, NodeID dest, int[] dataIn) {
super(source, dest);
- this.data = data;
+ this.data = new int[dataIn.length];
+ System.arraycopy(dataIn, 0, this.data, 0, dataIn.length);
}
int[] data;
+ /**
+ * To be equal, messages have to have the
+ * same type and content
+ */
+ public boolean equals(Object o) {
+ if (o == null) return false;
+ if (! (o instanceof DatagramMessage))
+ return false;
+ DatagramMessage msg = (DatagramMessage) o;
+ if (this.getData().length != msg.getData().length)
+ return false;
+ int n = this.getData().length;
+ int[] d1 = this.getData();
+ int[] d2 = msg.getData();
+ for (int i = 0; i<n; i++) {
+ if (d1[i]!= d2[i]) return false;
+ }
+ return super.equals(o);
+ }
+
/**
* Implement message-type-specific
* processing when this message
Modified: trunk/prototypes/java/src/org/openlcb/implementations/DatagramMeteringBuffer.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/DatagramMeteringBuffer.java 2012-02-04 15:45:34 UTC (rev 1716)
+++ trunk/prototypes/java/src/org/openlcb/implementations/DatagramMeteringBuffer.java 2012-02-04 16:39:24 UTC (rev 1717)
@@ -6,10 +6,22 @@
import java.util.concurrent.BlockingQueue;
/**
- * Accepts Datagrams from one or more sources, and meters them out
- * to a downstream node (e.g. on CAN), one at a time.
+ * Accepts Datagrams over a Connection from "upstream", and meters them out
+ * to "downstream" nodes (e.g. on a CAN network), one at a time.
+ * This is to ensure that e.g. simple CAN nodes that can't accept more
+ * than one datagram at a time get a chance to reply before the next one
+ * arrives.
*<p>
- * Does not parallelize Datagrams to separate nodes, but could
+ * Datagram negative replies cause a local retransmission. Positive
+ * replies are reflected upstream to original source of the datagram.
+ *<p>
+ *<ul>
+ *<li>Does not parallelize Datagrams to separate nodes
+ *<li>Does not yet check NAK for transient vs permanent
+ *<li>Needs to timeout and resume operation is no reply received
+ *<li>Should just pass non-datagram messages through unchanged.
+ *</ul>
+ *<p>
*
* @author Bob Jacobsen Copyright 2012
* @version $Revision$
Added: trunk/prototypes/java/test/org/openlcb/DatagramMessageTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/DatagramMessageTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/DatagramMessageTest.java 2012-02-04 16:39:24 UTC (rev 1717)
@@ -0,0 +1,106 @@
+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: 155 $
+ */
+public class DatagramMessageTest extends TestCase {
+ boolean result;
+
+ NodeID nodeID1 = new NodeID(new byte[]{1,2,3,4,5,6});
+ NodeID nodeID2 = new NodeID(new byte[]{0,0,0,0,0,0});
+ NodeID nodeID3 = new NodeID(new byte[]{0,0,0,0,0,3});
+
+ int data1[] = new int[]{1,1};
+ int data2[] = new int[]{1,2};
+ int data3[] = new int[]{1};
+
+ public void testEqualsSame() {
+ Message m1 = new DatagramMessage(nodeID1, nodeID2, data1);
+ Message m2 = new DatagramMessage(nodeID1, nodeID2, data1);
+
+ Assert.assertTrue(m1.equals(m2));
+ }
+
+ public void testNotEqualsDifferentNodeFrom() {
+ Message m1 = new DatagramMessage(nodeID1, nodeID2, data1);
+ Message m2 = new DatagramMessage(nodeID3, nodeID2, data1);
+
+ Assert.assertTrue( ! m1.equals(m2));
+ }
+
+ public void testNotEqualsDifferentNodeTo() {
+ Message m1 = new DatagramMessage(nodeID1, nodeID2, data1);
+ Message m2 = new DatagramMessage(nodeID1, nodeID3, data1);
+
+ Assert.assertTrue( ! m1.equals(m2));
+ }
+
+ public void testNotEqualsDifferentDataLength1() {
+ Message m1 = new DatagramMessage(nodeID1, nodeID2, data1);
+ Message m2 = new DatagramMessage(nodeID1, nodeID2, data3);
+
+ Assert.assertTrue( ! m1.equals(m2));
+ }
+
+ public void testNotEqualsDifferentDataLength2() {
+ Message m1 = new DatagramMessage(nodeID1, nodeID2, data3);
+ Message m2 = new DatagramMessage(nodeID1, nodeID2, data1);
+
+ Assert.assertTrue( ! m1.equals(m2));
+ }
+
+ public void testNotEqualsDifferentDataContent() {
+ Message m1 = new DatagramMessage(nodeID1, nodeID2, data1);
+ Message m2 = new DatagramMessage(nodeID1, nodeID2, data2);
+
+ Assert.assertTrue( ! m1.equals(m2));
+ }
+
+ public void testMessageImmutable() {
+ int data[] = new int[]{1,2,3};
+ Message m1 = new DatagramMessage(nodeID1, nodeID2, data);
+ data[1]=12;
+ Message m2 = new DatagramMessage(nodeID1, nodeID2, data);
+
+ Assert.assertTrue( ! m1.equals(m2));
+ }
+
+ public void testHandling() {
+ result = false;
+ Node n = new Node(){
+ @Override
+ public void handleDatagram(DatagramMessage msg, Connection sender){
+ result = true;
+ }
+ };
+ Message m = new DatagramMessage(nodeID1, nodeID2, data1);
+
+ n.put(m, null);
+
+ Assert.assertTrue(result);
+ }
+
+ // from here down is testing infrastructure
+
+ public DatagramMessageTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {DatagramMessageTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(DatagramMessageTest.class);
+ return suite;
+ }
+}
Modified: trunk/prototypes/java/test/org/openlcb/PackageTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/PackageTest.java 2012-02-04 15:45:34 UTC (rev 1716)
+++ trunk/prototypes/java/test/org/openlcb/PackageTest.java 2012-02-04 16:39:24 UTC (rev 1717)
@@ -38,19 +38,25 @@
suite.addTest(NodeTest.suite());
// specific message types (uses Node, IDs)
+ suite.addTest(InitializationCompleteMessageTest.suite());
+
+ suite.addTest(VerifiedNodeIDNumberMessageTest.suite());
+ suite.addTest(VerifyNodeIDNumberMessageTest.suite());
+
+ suite.addTest(IdentifyProducersMessageTest.suite());
+ suite.addTest(ProducerIdentifiedMessageTest.suite());
+ suite.addTest(IdentifyConsumersMessageTest.suite());
suite.addTest(ConsumerIdentifiedMessageTest.suite());
- suite.addTest(IdentifyConsumersMessageTest.suite());
suite.addTest(IdentifyEventsMessageTest.suite());
- suite.addTest(IdentifyProducersMessageTest.suite());
- suite.addTest(InitializationCompleteMessageTest.suite());
- suite.addTest(ProtocolIdentificationTest.suite());
suite.addTest(ProducerConsumerEventReportMessageTest.suite());
- suite.addTest(ProducerIdentifiedMessageTest.suite());
- suite.addTest(VerifiedNodeIDNumberMessageTest.suite());
- suite.addTest(VerifyNodeIDNumberMessageTest.suite());
+
suite.addTest(LearnEventMessageTest.suite());
+
+ suite.addTest(DatagramMessageTest.suite());
+
suite.addTest(ProtocolIdentificationRequestMessageTest.suite());
suite.addTest(ProtocolIdentificationReplyMessageTest.suite());
+ suite.addTest(ProtocolIdentificationTest.suite());
suite.addTest(ConfigurationPortalTest.suite());
Modified: trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java 2012-02-04 15:45:34 UTC (rev 1716)
+++ trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java 2012-02-04 16:39:24 UTC (rev 1717)
@@ -127,7 +127,7 @@
Thread.currentThread().sleep(10);
Assert.assertEquals("forwarded messages", 1, messagesForwarded.size());
- Assert.assertTrue(messagesForwarded.get(0).equals(datagram2));
+ Assert.assertTrue(messagesForwarded.get(0).equals(datagram1));
Assert.assertTrue(testConnection != null);
// now send the reply
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-02-04 20:37:38
|
Revision: 1729
http://openlcb.svn.sourceforge.net/openlcb/?rev=1729&view=rev
Author: jacobsen
Date: 2012-02-04 20:37:32 +0000 (Sat, 04 Feb 2012)
Log Message:
-----------
first commit, believed to be consistent
Added Paths:
-----------
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/swing/networktree/
trunk/prototypes/java/test/org/openlcb/swing/networktree/PackageTest.java
trunk/prototypes/java/test/org/openlcb/swing/networktree/TreePaneTest.java
Copied: trunk/prototypes/java/src/org/openlcb/swing/networktree/NodeTreeRep.java (from rev 1715, trunk/prototypes/java/src/org/openlcb/swing/MonPane.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/swing/networktree/NodeTreeRep.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/swing/networktree/NodeTreeRep.java 2012-02-04 20:37:32 UTC (rev 1729)
@@ -0,0 +1,64 @@
+// NodeTreeRep.java
+
+package org.openlcb.swing.networktree;
+
+import javax.swing.*;
+import javax.swing.tree.*;
+import java.beans.PropertyChangeListener;
+
+import org.openlcb.*;
+
+/**
+ * Represent a single node for the tree display
+ *<p>
+ *
+ * @author Bob Jacobsen Copyright (C) 2010, 2012
+ * @version $Revision$
+ */
+public class NodeTreeRep extends DefaultMutableTreeNode {
+
+ MimicNodeStore.NodeMemo memo;
+ MimicNodeStore store;
+ DefaultTreeModel treeModel;
+
+ DefaultMutableTreeNode getThis() { return this; }
+ DefaultTreeModel getTreeModel() { return treeModel; }
+
+ public NodeTreeRep(MimicNodeStore.NodeMemo memo, MimicNodeStore store, DefaultTreeModel treeModel) {
+ super("Node");
+ this.memo = memo;
+ this.store = store;
+ this.treeModel = treeModel;
+
+ // listen for more info arriving
+ memo.addPropertyChangeListener(
+ new PropertyChangeListener(){
+ public void propertyChange(java.beans.PropertyChangeEvent e) {
+
+ if (e.getPropertyName().equals("updateProtocol")) {
+ getTreeModel().insertNodeInto(new DefaultMutableTreeNode("Supported Protocols"), getThis(),
+ getThis().getChildCount());
+
+ }
+ if (e.getPropertyName().equals("updateConsumers")) {
+ getTreeModel().insertNodeInto(new DefaultMutableTreeNode("Supported Consumers"), getThis(),
+ getThis().getChildCount());
+
+ }
+ if (e.getPropertyName().equals("updateProducers")) {
+ getTreeModel().insertNodeInto(new DefaultMutableTreeNode("Supported Producers"), getThis(),
+ getThis().getChildCount());
+
+ }
+ }
+ });
+ }
+
+ /**
+ * Provides the node label in the tree
+ */
+ public String toString() {
+ return memo.getNodeID().toString();
+ }
+
+}
Copied: trunk/prototypes/java/src/org/openlcb/swing/networktree/TreePane.java (from rev 1715, trunk/prototypes/java/src/org/openlcb/swing/MonPane.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/swing/networktree/TreePane.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/swing/networktree/TreePane.java 2012-02-04 20:37:32 UTC (rev 1729)
@@ -0,0 +1,65 @@
+// TreePane.java
+
+package org.openlcb.swing.networktree;
+
+import javax.swing.*;
+import javax.swing.tree.*;
+import java.beans.PropertyChangeListener;
+
+import org.openlcb.*;
+
+/**
+ * Pane for monitoring an entire OpenLCB network as a logical tree
+ *<p>
+ *
+ * @author Bob Jacobsen Copyright (C) 2010, 2012
+ * @version $Revision$
+ */
+public class TreePane extends JPanel {
+
+ public TreePane() {
+ super();
+ }
+
+ MimicNodeStore store;
+ DefaultMutableTreeNode nodes;
+ DefaultTreeModel treeModel;
+
+ MimicNodeStore getStore() { return store; }
+ DefaultTreeModel getTreeModel() { return treeModel; }
+
+ public void initComponents(MimicNodeStore store) {
+
+ 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
+ store.addPropertyChangeListener(
+ new PropertyChangeListener(){
+ public void propertyChange(java.beans.PropertyChangeEvent e) {
+
+ if (e.getPropertyName().equals("AddNode")) {
+ MimicNodeStore.NodeMemo memo = (MimicNodeStore.NodeMemo) e.getNewValue();
+
+ treeModel.insertNodeInto(new NodeTreeRep(memo, getStore(), getTreeModel()), nodes,
+ nodes.getChildCount());
+ }
+ }
+ });
+
+ // build GUI
+ treeModel = new DefaultTreeModel(nodes);
+ JTree tree = new JTree(treeModel);
+ tree.setEditable(true);
+ JScrollPane treeView = new JScrollPane(tree);
+ add(treeView);
+
+ }
+
+}
Copied: trunk/prototypes/java/test/org/openlcb/swing/networktree/PackageTest.java (from rev 1715, trunk/prototypes/java/test/org/openlcb/swing/SwingTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/swing/networktree/PackageTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/swing/networktree/PackageTest.java 2012-02-04 20:37:32 UTC (rev 1729)
@@ -0,0 +1,40 @@
+package org.openlcb.swing.networktree;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import javax.swing.*;
+
+import org.openlcb.swing.*;
+
+/**
+ * @author Bob Jacobsen Copyright 2009
+ * @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(TreePaneTest.suite());
+
+ return suite;
+ }
+}
Added: trunk/prototypes/java/test/org/openlcb/swing/networktree/TreePaneTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/swing/networktree/TreePaneTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/swing/networktree/TreePaneTest.java 2012-02-04 20:37:32 UTC (rev 1729)
@@ -0,0 +1,103 @@
+package org.openlcb.swing.networktree;
+
+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 2009
+ * @version $Revision: 34 $
+ */
+public class TreePaneTest extends TestCase {
+
+ NodeID nid1 = new NodeID(new byte[]{0,0,0,0,0,1});
+ NodeID nid2 = new NodeID(new byte[]{0,0,0,0,0,2});
+ NodeID nid3 = new NodeID(new byte[]{0,0,0,0,0,3});
+ NodeID nid4 = new NodeID(new byte[]{0,0,0,0,0,4});
+ NodeID nid5 = new NodeID(new byte[]{0,0,0,0,0,5});
+ NodeID nid6 = new NodeID(new byte[]{0,0,0,0,0,6});
+ NodeID nid7 = new NodeID(new byte[]{0,0,0,0,0,7});
+ NodeID nid8 = new NodeID(new byte[]{0,0,0,0,0,8});
+ NodeID nid9 = new NodeID(new byte[]{0,0,0,0,0,9});
+
+ EventID eventA = new EventID(new byte[]{1,0,0,0,0,0,1,0});
+ EventID eventB = new EventID(new byte[]{1,0,0,0,0,0,2,0});
+ EventID eventC = new EventID(new byte[]{1,0,0,0,0,0,3,0});
+
+ JFrame frame;
+ TreePane pane;
+ MimicNodeStore store;
+
+ public void setUp() throws Exception {
+ store = new MimicNodeStore();
+ Message msg = new ProducerIdentifiedMessage(nid1, eventA);
+ store.put(msg, null);
+
+ // Test is really popping a window before doing all else
+ frame = new JFrame();
+ frame.setTitle("TreePane Test");
+ TreePane pane = new TreePane();
+ frame.add( pane );
+ pane.initComponents(store);
+ frame.pack();
+ frame.setMinimumSize(new java.awt.Dimension(200,200));
+ frame.setVisible(true);
+
+
+ }
+
+ public void tearDown() {
+ //frame.setVisible(false);
+ }
+
+ public void testPriorMessage() {
+ frame.setTitle("Prior Message");
+ }
+
+ public void testAfterMessage() {
+ frame.setTitle("After Message");
+ Message msg = new ProducerIdentifiedMessage(nid2, eventA);
+ store.put(msg, null);
+ }
+
+ public void testWithProtocolID() {
+ frame.setTitle("2nd has protocol id");
+ Message msg;
+ msg = new ProducerIdentifiedMessage(nid2, eventA);
+ store.put(msg, null);
+ msg = new ProtocolIdentificationReplyMessage(nid2, 0x03);
+ store.put(msg, null);
+ }
+
+
+ // from here down is testing infrastructure
+
+ public TreePaneTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {TreePaneTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(TreePaneTest.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-02-04 20:38:09
|
Revision: 1730
http://openlcb.svn.sourceforge.net/openlcb/?rev=1730&view=rev
Author: jacobsen
Date: 2012-02-04 20:38:03 +0000 (Sat, 04 Feb 2012)
Log Message:
-----------
notifications update
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/MimicNodeStore.java
trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java
Modified: trunk/prototypes/java/src/org/openlcb/MimicNodeStore.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/MimicNodeStore.java 2012-02-04 20:37:32 UTC (rev 1729)
+++ trunk/prototypes/java/src/org/openlcb/MimicNodeStore.java 2012-02-04 20:38:03 UTC (rev 1730)
@@ -3,6 +3,8 @@
import java.util.HashMap;
import java.util.Collection;
+import java.beans.PropertyChangeListener;
+
/**
* Store containing mimic proxies for nodes on external connections
* <p>
@@ -20,13 +22,23 @@
}
public void put(Message msg, Connection sender) {
- if (map.get(msg.getSourceNodeID()) == null)
- map.put(msg.getSourceNodeID(), new NodeMemo(msg.getSourceNodeID()));
+ NodeMemo memo = map.get(msg.getSourceNodeID());
+ if (memo == null) {
+ memo = new NodeMemo(msg.getSourceNodeID());
+ map.put(msg.getSourceNodeID(), memo);
+ pcs.firePropertyChange("AddNode", null, memo);
+ }
+ // check for necessary updates in specific node
+ memo.put(msg, sender);
}
HashMap<NodeID, NodeMemo> map = new java.util.HashMap<NodeID, NodeMemo>();
-
- class NodeMemo {
+
+ java.beans.PropertyChangeSupport pcs = new java.beans.PropertyChangeSupport(this);
+ public synchronized void addPropertyChangeListener(java.beans.PropertyChangeListener l) {pcs.addPropertyChangeListener(l);}
+ public synchronized void removePropertyChangeListener(java.beans.PropertyChangeListener l) {pcs.removePropertyChangeListener(l);}
+
+ public class NodeMemo extends MessageDecoder {
NodeID id;
public NodeMemo(NodeID id) { this.id = id; }
@@ -34,5 +46,19 @@
public NodeID getNodeID() {
return id;
}
+
+ ProtocolIdentification pIdent = null;
+ public void handleProtocolIdentificationReply(ProtocolIdentificationReplyMessage msg, Connection sender){
+ // accept assumes from mimic'd node
+ pIdent = new ProtocolIdentification(msg);
+ pcs.firePropertyChange("updateProtocol", null, pIdent);
+ }
+ public ProtocolIdentification getProtocolIdentification() {
+ return pIdent;
+ }
+
+ java.beans.PropertyChangeSupport pcs = new java.beans.PropertyChangeSupport(this);
+ public synchronized void addPropertyChangeListener(java.beans.PropertyChangeListener l) {pcs.addPropertyChangeListener(l);}
+ public synchronized void removePropertyChangeListener(java.beans.PropertyChangeListener l) {pcs.removePropertyChangeListener(l);}
}
}
Modified: trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java 2012-02-04 20:37:32 UTC (rev 1729)
+++ trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java 2012-02-04 20:38:03 UTC (rev 1730)
@@ -6,6 +6,7 @@
import junit.framework.TestSuite;
import java.util.Collection;
+import java.beans.PropertyChangeListener;
/**
* @author Bob Jacobsen Copyright 2012
@@ -22,9 +23,17 @@
ProducerIdentifiedMessage pim2 = new ProducerIdentifiedMessage(nid2,
new EventID(new byte[]{1,0,0,0,0,0,1,0}));
-
+
+ PropertyChangeListener listener;
+ boolean listenerFired;
+
public void setUp() {
store = new MimicNodeStore();
+
+ listener = new PropertyChangeListener(){
+ public void propertyChange(java.beans.PropertyChangeEvent e) { listenerFired = true; }
+ };
+ listenerFired = false;
}
public void testCtor() {
@@ -71,7 +80,66 @@
Assert.assertTrue(list.size()==1);
}
+ public void testNoDefaultProtocolInfo() {
+ store.put(pim1,null);
+ Collection<MimicNodeStore.NodeMemo> list = store.getNodeMemos();
+ MimicNodeStore.NodeMemo memo = list.iterator().next();
+
+ Assert.assertNull(memo.getProtocolIdentification());
+ }
+
+ public void testProtocolInfoAvailableFromNode() {
+ store.put(pim1,null);
+ Collection<MimicNodeStore.NodeMemo> list = store.getNodeMemos();
+ MimicNodeStore.NodeMemo memo = list.iterator().next();
+ store.put(new ProtocolIdentificationReplyMessage(nid1, 0x03), null);
+
+ Assert.assertNotNull(memo.getProtocolIdentification());
+ }
+ public void testForNotificationOfNode() {
+ store.addPropertyChangeListener(
+ new PropertyChangeListener(){
+ public void propertyChange(java.beans.PropertyChangeEvent e) {
+ MimicNodeStore.NodeMemo memo = (MimicNodeStore.NodeMemo) e.getNewValue();
+ memo.addPropertyChangeListener(listener);
+ }
+ });
+ store.put(pim1,null);
+ Assert.assertFalse(listenerFired);
+
+ store.put(new ProtocolIdentificationReplyMessage(nid1, 0x03), null);
+ Assert.assertTrue(listenerFired);
+
+ }
+
+ public void testForNotificationOfOnlyOneNode() {
+ store.put(pim1,null);
+
+ store.addPropertyChangeListener(
+ new PropertyChangeListener(){
+ public void propertyChange(java.beans.PropertyChangeEvent e) {
+ MimicNodeStore.NodeMemo memo = (MimicNodeStore.NodeMemo) e.getNewValue();
+ memo.addPropertyChangeListener(listener);
+ }
+ });
+ store.put(pim2,null);
+ Assert.assertFalse(listenerFired);
+
+ store.put(new ProtocolIdentificationReplyMessage(nid1, 0x03), null);
+ Assert.assertFalse(listenerFired);
+
+ store.put(new ProtocolIdentificationReplyMessage(nid2, 0x03), null);
+ Assert.assertTrue(listenerFired);
+
+ }
+
+ public void testForNotificationOfProtocolIdent() {
+ store.addPropertyChangeListener(listener);
+ store.put(pim1,null);
+
+ Assert.assertTrue(listenerFired);
+ }
// from here down is testing infrastructure
public MimicNodeStoreTest(String s) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-02-04 20:38:54
|
Revision: 1732
http://openlcb.svn.sourceforge.net/openlcb/?rev=1732&view=rev
Author: jacobsen
Date: 2012-02-04 20:38:48 +0000 (Sat, 04 Feb 2012)
Log Message:
-----------
multiple message handling, found in JMRI test
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/implementations/DatagramMeteringBuffer.java
trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java
Modified: trunk/prototypes/java/src/org/openlcb/implementations/DatagramMeteringBuffer.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/DatagramMeteringBuffer.java 2012-02-04 20:38:17 UTC (rev 1731)
+++ trunk/prototypes/java/src/org/openlcb/implementations/DatagramMeteringBuffer.java 2012-02-04 20:38:48 UTC (rev 1732)
@@ -19,7 +19,6 @@
*<li>Does not parallelize Datagrams to separate nodes
*<li>Does not yet check NAK for transient vs permanent
*<li>Needs to timeout and resume operation is no reply received
- *<li>Should just pass non-datagram messages through unchanged.
*</ul>
*<p>
*
@@ -44,7 +43,10 @@
*/
public void put(Message msg, Connection upstream) {
- queue.add(new MessageMemo(msg, upstream, downstream));
+ if (msg instanceof DatagramMessage)
+ queue.add(new MessageMemo(msg, upstream, downstream));
+ else
+ downstream.put(msg, this);
}
class MessageMemo extends MessageDecoder {
Modified: trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java 2012-02-04 20:38:17 UTC (rev 1731)
+++ trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java 2012-02-04 20:38:48 UTC (rev 1732)
@@ -72,7 +72,17 @@
Thread.currentThread().sleep(10);
}
- public void testSendGoesThrough() throws InterruptedException {
+ public void testSendNonDatagramGoesThrough() throws InterruptedException {
+ Message m = new InitializationCompleteMessage(hereID);
+ buffer.put(m, replyConnection1);
+
+ 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 {
buffer.put(datagram1, replyConnection1);
Thread.currentThread().sleep(10);
@@ -120,6 +130,18 @@
Assert.assertTrue(repliesReturned1.get(0).equals(replyOK));
}
+ public void testSendTwoNonDatagramGoesThrough() throws InterruptedException {
+ Message m = new InitializationCompleteMessage(hereID);
+ buffer.put(m, replyConnection1);
+ buffer.put(m, replyConnection1);
+
+ Thread.currentThread().sleep(10);
+ 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 {
buffer.put(datagram1, replyConnection1);
buffer.put(datagram2, replyConnection1);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-02-07 05:59:23
|
Revision: 1745
http://openlcb.svn.sourceforge.net/openlcb/?rev=1745&view=rev
Author: jacobsen
Date: 2012-02-07 05:59:17 +0000 (Tue, 07 Feb 2012)
Log Message:
-----------
CAN frame install
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/can/AliasMap.java
trunk/prototypes/java/src/org/openlcb/can/CanFrame.java
trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java
trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java
trunk/prototypes/java/test/org/openlcb/PackageTest.java
trunk/prototypes/java/test/org/openlcb/can/AliasMapTest.java
trunk/prototypes/java/test/org/openlcb/can/MessageBuilderTest.java
Added Paths:
-----------
trunk/prototypes/java/test/org/openlcb/can/PackageTest.java
Removed Paths:
-------------
trunk/prototypes/java/test/org/openlcb/can/CanTest.java
Modified: trunk/prototypes/java/src/org/openlcb/can/AliasMap.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/AliasMap.java 2012-02-07 05:19:06 UTC (rev 1744)
+++ trunk/prototypes/java/src/org/openlcb/can/AliasMap.java 2012-02-07 05:59:17 UTC (rev 1745)
@@ -32,7 +32,9 @@
}
public NodeID getNodeID(int alias) {
- return nMap.get(new Integer(alias));
+ NodeID retVal = nMap.get(new Integer(alias));
+ if (retVal != null) return retVal;
+ else return new NodeID();
}
public int getAlias(NodeID nid) {
Integer r = iMap.get(nid);
Modified: trunk/prototypes/java/src/org/openlcb/can/CanFrame.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/CanFrame.java 2012-02-07 05:19:06 UTC (rev 1744)
+++ trunk/prototypes/java/src/org/openlcb/can/CanFrame.java 2012-02-07 05:59:17 UTC (rev 1745)
@@ -21,5 +21,7 @@
public int getNumDataElements();
public int getElement(int n);
+
+ public byte[] getData();
}
Modified: trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java 2012-02-07 05:19:06 UTC (rev 1744)
+++ trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java 2012-02-07 05:59:17 UTC (rev 1745)
@@ -3,6 +3,8 @@
import org.openlcb.*;
import java.util.List;
+import java.util.ArrayList;
+import java.util.HashMap;
/**
* Converts CAN frame messages to regular messages
@@ -37,66 +39,142 @@
*
* The List is always returned, even if empty.
*/
- public List<Message> processFrame(OpenLcbCanFrame f) {
- List<Message> retlist = new java.util.ArrayList<Message>();
- NodeID source = map.getNodeID(f.getSourceAlias());
-
+ public List<Message> processFrame(CanFrame f) {
// check for special cases first
+ if ( (f.getHeader() & 0x08000000) != 0x08000000 ) return null; // not OpenLCB frame
- // then decode standard MTIs
- switch(1) {
+ // break into types
+ int format = ( f.getHeader() & 0x07000000 ) >> 24;
- case OpenLcb.MTI_INITIALIZATION_COMPLETE:
- retlist.add(new InitializationCompleteMessage(source));
- break;
+ switch (format) {
+ case 0:
+ return processFormat0(f);
+ case 1:
+ return processFormat1(f);
+ case 2:
+ return processFormat2(f);
+ case 3:
+ return processFormat3(f);
+ case 4:
+ return processFormat4(f);
+ case 5:
+ return processFormat5(f);
+ case 6:
+ return processFormat6(f);
+ case 7:
+ return processFormat7(f);
+ default: // should not happen
+ return null;
+ }
+ }
+
+ HashMap<NodeID, List<Integer>> datagramData = new HashMap<NodeID, List<Integer>>();
+
+ int getSourceID(CanFrame f) { return f.getHeader()&0x00000FFF; }
+ int getType(CanFrame f) { return ( f.getHeader() & 0x00FF0000 ) >> 16; }
+ EventID getEventID(CanFrame f) { return new EventID(f.getData()); }
+
+ public List<Message> processFormat0(CanFrame f) {
+ // simple MTI
+ List<Message> retlist = new java.util.ArrayList<Message>();
+ NodeID source = map.getNodeID(getSourceID(f));
- case OpenLcb.MTI_VERIFY_NID:
- retlist.add(new VerifyNodeIDNumberMessage(source));
- break;
- case OpenLcb.MTI_VERIFIED_NID: // also 30B2
- retlist.add(new VerifiedNodeIDNumberMessage(source));
- break;
+ int type = getType(f);
+ switch (type) {
+ case 0x0A:
+ retlist.add(new VerifyNodeIDNumberMessage(source));
+ return retlist;
+ case 0x24:
+ retlist.add(new IdentifyConsumersMessage(source, getEventID(f)));
+ return retlist;
+ case 0x28:
+ retlist.add(new IdentifyProducersMessage(source, getEventID(f)));
+ return retlist;
+ case 0x2B:
+ retlist.add(new IdentifyEventsMessage(source));
+ return retlist;
+ case 0x2C:
+ retlist.add(new LearnEventMessage(source, getEventID(f)));
+ return retlist;
+ case 0x2D:
+ retlist.add(new ProducerConsumerEventReportMessage(source, getEventID(f)));
+ return retlist;
+ default: return null;
+ }
+ }
+ public List<Message> processFormat1(CanFrame f) {
+ // complex MTI
+ List<Message> retlist = new java.util.ArrayList<Message>();
+ NodeID source = map.getNodeID(getSourceID(f));
+ int type = getType(f);
+ switch (type) {
+ case 0x08:
+ retlist.add(new InitializationCompleteMessage(source));
+ return retlist;
+ case 0x0B:
+ retlist.add(new VerifiedNodeIDNumberMessage(source));
+ return retlist;
+ case 0x26:
+ retlist.add(new ConsumerIdentifiedMessage(source, getEventID(f)));
+ return retlist;
+ case 0x2A:
+ retlist.add(new ProducerIdentifiedMessage(source, getEventID(f)));
+ return retlist;
+ default: return null;
+ }
+ }
+ public List<Message> processFormat2(CanFrame f) {
+ // reserved
+ return null;
+ }
+ public List<Message> processFormat3(CanFrame f) {
+ // reserved
+ return null;
+ }
+ public List<Message> processFormat4(CanFrame f) {
+ // datagram not-last
+ NodeID source = map.getNodeID(getSourceID(f));
+ List<Integer> list = datagramData.get(source);
+ if (list == null) {
+ list = new ArrayList<Integer>();
+ datagramData.put(source, list);
+ }
+ for (int i = 0; i < f.getNumDataElements(); i++) {
+ list.add(f.getElement(i));
+ }
+ return null;
+ }
+ public List<Message> processFormat5(CanFrame f) {
+ // datagram last
+ NodeID source = map.getNodeID(getSourceID(f));
+ List<Integer> list = datagramData.get(source);
+ if (list == null) {
+ list = new ArrayList<Integer>();
+ }
+ for (int i = 0; i < f.getNumDataElements(); i++) {
+ list.add(f.getElement(i));
+ }
- case OpenLcb.MTI_IDENTIFY_CONSUMERS:
- retlist.add(new IdentifyConsumersMessage(source, f.getEventID()));
- break;
-
- case OpenLcb.MTI_CONSUMER_IDENTIFIED:
- retlist.add(new ConsumerIdentifiedMessage(source, f.getEventID()));
- break;
+ datagramData.put(source, null);
- case OpenLcb.MTI_IDENTIFY_PRODUCERS:
- retlist.add(new IdentifyProducersMessage(source, f.getEventID()));
- break;
-
- case OpenLcb.MTI_PRODUCER_IDENTIFIED:
- retlist.add(new ProducerIdentifiedMessage(source, f.getEventID()));
- break;
-
- case OpenLcb.MTI_IDENTIFY_EVENTS: // also 32B2
- retlist.add(new IdentifyEventsMessage(source));
- break;
-
- case OpenLcb.MTI_LEARN_EVENT:
- retlist.add(new LearnEventMessage(source, f.getEventID()));
- break;
- case OpenLcb.MTI_PC_EVENT_REPORT:
- retlist.add(new ProducerConsumerEventReportMessage(source, f.getEventID()));
- break;
-
- case OpenLcb.MTI_DATAGRAM:
-
- case OpenLcb.MTI_STREAM_INIT_REQUEST:
- case OpenLcb.MTI_STREAM_INIT_REPLY:
- case OpenLcb.MTI_STREAM_DATA_SEND:
- case OpenLcb.MTI_STREAM_DATA_PROCEED:
- case OpenLcb.MTI_STREAM_DATA_COMPLETE:
-
- default:
- // this is an error
+ int[] data = new int[list.size()];
+ for (int i=0; i<list.size(); i++) {
+ data[i] = list.get(i);
}
+ List<Message> retlist = new java.util.ArrayList<Message>();
+ NodeID dest = map.getNodeID( (f.getHeader() & 0x00FFF000) >> 12);
+ retlist.add(new DatagramMessage(source, dest, data));
return retlist;
}
+ public List<Message> processFormat6(CanFrame f) {
+ // addressed
+ return null;
+ }
+ public List<Message> processFormat7(CanFrame f) {
+ // stream data
+ return null;
+ }
+
/**
* Accept an OpenLCB Message, and convert to
Modified: trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java 2012-02-07 05:19:06 UTC (rev 1744)
+++ trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java 2012-02-07 05:59:17 UTC (rev 1745)
@@ -32,7 +32,11 @@
int nodeAlias;
public int getHeader() { return id; }
+ public void setHeader(int id) { this.id = id; }
+ public byte[] getData() { return data; }
+ public void setData(byte[] b) { data = b; length = b.length;}
+
public boolean isExtended() { return true; }
public boolean isRtr() { return false; }
@@ -337,7 +341,7 @@
}
public String toString() {
- String retval = "["+id+"(d)]";
+ String retval = "[0x"+Integer.toHexString(id)+"]";
for (int i = 0; i<length; i++) {
retval += " "+data[i];
}
@@ -363,7 +367,7 @@
* Basic header MTI definitions for OpenLCB on CAN.
*/
- static final int MTI_INITIALIZATION_COMPLETE = 0x087;
+ static final int MTI_INITIALIZATION_COMPLETE = 0x08F;
static final int MTI_VERIFY_NID = 0x0A7;
static final int MTI_VERIFIED_NID = 0x0B7;
Modified: trunk/prototypes/java/test/org/openlcb/PackageTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/PackageTest.java 2012-02-07 05:19:06 UTC (rev 1744)
+++ trunk/prototypes/java/test/org/openlcb/PackageTest.java 2012-02-07 05:59:17 UTC (rev 1745)
@@ -72,7 +72,7 @@
suite.addTest(org.openlcb.cdi.PackageTest.suite());
// test CAN classes
- suite.addTest(org.openlcb.can.CanTest.suite());
+ suite.addTest(org.openlcb.can.PackageTest.suite());
return suite;
}
Modified: trunk/prototypes/java/test/org/openlcb/can/AliasMapTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/can/AliasMapTest.java 2012-02-07 05:19:06 UTC (rev 1744)
+++ trunk/prototypes/java/test/org/openlcb/can/AliasMapTest.java 2012-02-07 05:59:17 UTC (rev 1745)
@@ -18,7 +18,7 @@
Assert.assertEquals("get Alias", -1, map.getAlias(new NodeID(new byte[]{0,1,2,3,4,5})));
- Assert.assertEquals("get NodeID", null, map.getNodeID(0));
+ Assert.assertEquals("get NodeID", new NodeID(), map.getNodeID(0));
}
public void testAfterFrame() {
Deleted: trunk/prototypes/java/test/org/openlcb/can/CanTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/can/CanTest.java 2012-02-07 05:19:06 UTC (rev 1744)
+++ trunk/prototypes/java/test/org/openlcb/can/CanTest.java 2012-02-07 05:59:17 UTC (rev 1745)
@@ -1,40 +0,0 @@
-package org.openlcb.can;
-
-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 CanTest extends TestCase {
- public void testStart() {
- }
-
- // from here down is testing infrastructure
-
- public CanTest(String s) {
- super(s);
- }
-
- // Main entry point
- static public void main(String[] args) {
- String[] testCaseName = {CanTest.class.getName()};
- junit.swingui.TestRunner.main(testCaseName);
- }
-
- // test suite from all defined tests
- public static Test suite() {
- TestSuite suite = new TestSuite(CanTest.class);
-
- suite.addTest(OpenLcbCanFrameTest.suite());
- suite.addTest(MessageBuilderTest.suite());
- suite.addTest(NIDaTest.suite());
- suite.addTest(NIDaAlgorithmTest.suite());
- suite.addTest(AliasMapTest.suite());
-
- return suite;
- }
-}
Modified: trunk/prototypes/java/test/org/openlcb/can/MessageBuilderTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/can/MessageBuilderTest.java 2012-02-07 05:19:06 UTC (rev 1744)
+++ trunk/prototypes/java/test/org/openlcb/can/MessageBuilderTest.java 2012-02-07 05:59:17 UTC (rev 1745)
@@ -29,7 +29,7 @@
Assert.assertEquals("count", 1, list.size());
CanFrame f0 = list.get(0);
- Assert.assertEquals("header", toHexString(0x19087123), toHexString(f0.getHeader()));
+ Assert.assertEquals("header", toHexString(0x1908F123), toHexString(f0.getHeader()));
compareContent(source.getContents(), f0);
}
public void testVerifyNodeIDNumberMessage() {
@@ -146,6 +146,63 @@
compareContent(new byte[]{31}, f1);
}
+ public void testInitializationCompleteFrame() {
+ OpenLcbCanFrame frame = new OpenLcbCanFrame(0x123);
+ frame.setHeader(0x19087123);
+
+ MessageBuilder b = new MessageBuilder(map);
+
+ List<Message> list = b.processFrame(frame);
+
+ Assert.assertEquals("count", 1, list.size());
+ Message msg = list.get(0);
+
+ Assert.assertTrue(msg instanceof InitializationCompleteMessage);
+ }
+
+ public void testSingleFrameDatagram() {
+ OpenLcbCanFrame frame = new OpenLcbCanFrame(0x123);
+ frame.setHeader(0x1D321123);
+
+ MessageBuilder b = new MessageBuilder(map);
+
+ List<Message> list = b.processFrame(frame);
+
+ Assert.assertEquals("count", 1, list.size());
+ Message msg = list.get(0);
+
+ Assert.assertTrue(msg instanceof DatagramMessage);
+ }
+
+ public void testTwoFrameDatagram() {
+ OpenLcbCanFrame frame = new OpenLcbCanFrame(0x123);
+ frame.setHeader(0x1C321123);
+ frame.setData(new byte[]{1,2});
+
+ MessageBuilder b = new MessageBuilder(map);
+
+ List<Message> list = b.processFrame(frame);
+
+ Assert.assertNull(list);
+
+ frame = new OpenLcbCanFrame(0x123);
+ frame.setHeader(0x1D321123);
+ frame.setData(new byte[]{11,12,13});
+
+ list = b.processFrame(frame);
+
+ Assert.assertEquals("count", 1, list.size());
+ Message msg = list.get(0);
+ Assert.assertTrue(msg instanceof DatagramMessage);
+ int[] data = ((DatagramMessage)msg).getData();
+ Assert.assertEquals(5, data.length);
+ Assert.assertEquals(1,data[0]);
+ Assert.assertEquals(2,data[1]);
+ Assert.assertEquals(11,data[2]);
+ Assert.assertEquals(12,data[3]);
+ Assert.assertEquals(13,data[4]);
+ }
+
// from here down is testing infrastructure
public MessageBuilderTest(String s) {
Copied: trunk/prototypes/java/test/org/openlcb/can/PackageTest.java (from rev 1715, trunk/prototypes/java/test/org/openlcb/can/CanTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/can/PackageTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/can/PackageTest.java 2012-02-07 05:59:17 UTC (rev 1745)
@@ -0,0 +1,40 @@
+package org.openlcb.can;
+
+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 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(OpenLcbCanFrameTest.suite());
+ suite.addTest(MessageBuilderTest.suite());
+ suite.addTest(NIDaTest.suite());
+ suite.addTest(NIDaAlgorithmTest.suite());
+ suite.addTest(AliasMapTest.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-02-19 21:30:45
|
Revision: 1874
http://openlcb.svn.sourceforge.net/openlcb/?rev=1874&view=rev
Author: jacobsen
Date: 2012-02-19 21:30:38 +0000 (Sun, 19 Feb 2012)
Log Message:
-----------
new message type
Added Paths:
-----------
trunk/prototypes/java/src/org/openlcb/SimpleNodeIdentInfoReplyMessage.java
trunk/prototypes/java/src/org/openlcb/SimpleNodeIdentInfoRequestMessage.java
trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentInfoReplyMessageTest.java
trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentInfoRequestMessageTest.java
Copied: trunk/prototypes/java/src/org/openlcb/SimpleNodeIdentInfoReplyMessage.java (from rev 1849, trunk/prototypes/java/src/org/openlcb/ProtocolIdentificationReplyMessage.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/SimpleNodeIdentInfoReplyMessage.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/SimpleNodeIdentInfoReplyMessage.java 2012-02-19 21:30:38 UTC (rev 1874)
@@ -0,0 +1,67 @@
+package org.openlcb;
+
+// For annotations
+import net.jcip.annotations.*;
+import edu.umd.cs.findbugs.annotations.*;
+
+/**
+ * Reply message for the Simple Node Ident Info protocol
+ *
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision: 529 $
+ */
+@Immutable
+@ThreadSafe
+public class SimpleNodeIdentInfoReplyMessage extends Message {
+
+ public SimpleNodeIdentInfoReplyMessage(NodeID source, byte[] dataIn) {
+ super(source);
+ this.data = new byte[dataIn.length];
+ System.arraycopy(dataIn, 0, this.data, 0, dataIn.length);
+ }
+
+ byte[] data;
+
+ /**
+ * To be equal, messages have to have the
+ * same type and content
+ */
+ public boolean equals(Object o) {
+ if (o == null) return false;
+ if (! (o instanceof SimpleNodeIdentInfoReplyMessage))
+ return false;
+ SimpleNodeIdentInfoReplyMessage msg = (SimpleNodeIdentInfoReplyMessage) o;
+ if (this.getData().length != msg.getData().length)
+ return false;
+ int n = this.getData().length;
+ byte[] d1 = this.getData();
+ byte[] d2 = msg.getData();
+ for (int i = 0; i<n; i++) {
+ if (d1[i]!= d2[i]) return false;
+ }
+ return super.equals(o);
+ }
+
+ public byte[] getData() {
+ return data;
+ }
+
+ /**
+ * Implement message-type-specific
+ * processing when this message
+ * is received by a node.
+ *<p>
+ * Default is to do nothing.
+ */
+ @Override
+ public void applyTo(MessageDecoder decoder, Connection sender) {
+ decoder.handleSimpleNodeIdentInfoReply(this, sender);
+ }
+
+ public String toString() {
+ return getSourceNodeID().toString()
+ +" Simple Node Ident Info with content "+getData();
+ }
+
+ public int getMTI() { return MTI_SIMPLE_NODE_IDENT_REPLY; }
+}
Copied: trunk/prototypes/java/src/org/openlcb/SimpleNodeIdentInfoRequestMessage.java (from rev 1849, trunk/prototypes/java/src/org/openlcb/ProtocolIdentificationReplyMessage.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/SimpleNodeIdentInfoRequestMessage.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/SimpleNodeIdentInfoRequestMessage.java 2012-02-19 21:30:38 UTC (rev 1874)
@@ -0,0 +1,54 @@
+package org.openlcb;
+
+// For annotations
+import net.jcip.annotations.*;
+import edu.umd.cs.findbugs.annotations.*;
+
+/**
+ * Request message for the Simple Node Ident Info protocol
+ *
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision: 529 $
+ */
+@Immutable
+@ThreadSafe
+public class SimpleNodeIdentInfoRequestMessage extends Message {
+
+ public SimpleNodeIdentInfoRequestMessage(NodeID source) {
+ super(source);
+ }
+
+ long value;
+
+ public long getValue() { return value; }
+
+ /**
+ * To be equal, messages have to have the
+ * same type and content
+ */
+ public boolean equals(Object o) {
+ if (o == null) return false;
+ if (! (o instanceof SimpleNodeIdentInfoRequestMessage))
+ return false;
+ return super.equals(o);
+ }
+
+ /**
+ * Implement message-type-specific
+ * processing when this message
+ * is received by a node.
+ *<p>
+ * Default is to do nothing.
+ */
+ @Override
+ public void applyTo(MessageDecoder decoder, Connection sender) {
+ decoder.handleSimpleNodeIdentInfoRequest(this, sender);
+ }
+
+ public String toString() {
+ return getSourceNodeID().toString()
+ +" Simple Node Ident Info Request";
+ }
+
+ public int getMTI() { return MTI_SIMPLE_NODE_IDENT_REQUEST; }
+}
Copied: trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentInfoReplyMessageTest.java (from rev 1872, trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationReplyMessageTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentInfoReplyMessageTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentInfoReplyMessageTest.java 2012-02-19 21:30:38 UTC (rev 1874)
@@ -0,0 +1,96 @@
+package org.openlcb;
+
+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 SimpleNodeIdentInfoReplyMessageTest extends TestCase {
+ boolean result;
+
+ NodeID nodeID1 = new NodeID(new byte[]{1,2,3,4,5,6});
+ NodeID nodeID2 = new NodeID(new byte[]{0,0,0,0,0,0});
+
+ public void testEqualsSame() {
+ Message m1 = new SimpleNodeIdentInfoReplyMessage(
+ nodeID1, new byte[]{1,2});
+ Message m2 = new SimpleNodeIdentInfoReplyMessage(
+ nodeID1, new byte[]{1,2});
+
+ Assert.assertTrue(m1.equals(m2));
+ }
+
+ public void testNotEqualsDifferentNode() {
+ Message m1 = new SimpleNodeIdentInfoReplyMessage(
+ nodeID1, new byte[]{1,2});
+ Message m2 = new SimpleNodeIdentInfoReplyMessage(
+ nodeID2, new byte[]{1,2});
+
+ Assert.assertTrue( ! m1.equals(m2));
+ }
+
+
+ public void testNotEqualsDifferentValue() {
+ Message m1 = new SimpleNodeIdentInfoReplyMessage(
+ nodeID1, new byte[]{1,2});
+ Message m2 = new SimpleNodeIdentInfoReplyMessage(
+ nodeID1, new byte[]{3,1});
+
+ Assert.assertTrue( ! m1.equals(m2));
+ }
+
+ public void testNotEqualsDifferentValueLength() {
+ Message m1 = new SimpleNodeIdentInfoReplyMessage(
+ nodeID1, new byte[]{1,2});
+ Message m2 = new SimpleNodeIdentInfoReplyMessage(
+ nodeID1, new byte[]{1,2,3});
+
+ Assert.assertTrue( ! m1.equals(m2));
+ }
+ public void testNotEqualsDifferentValueLengthBis() {
+ Message m1 = new SimpleNodeIdentInfoReplyMessage(
+ nodeID1, new byte[]{1,2,3});
+ Message m2 = new SimpleNodeIdentInfoReplyMessage(
+ nodeID1, new byte[]{1,2});
+
+ Assert.assertTrue( ! m1.equals(m2));
+ }
+
+
+ public void testHandling() {
+ result = false;
+ Node n = new Node(){
+ @Override
+ public void handleSimpleNodeIdentInfoReply(SimpleNodeIdentInfoReplyMessage msg, Connection sender){
+ result = true;
+ }
+ };
+ Message m = new SimpleNodeIdentInfoReplyMessage(nodeID1, new byte[]{1,2});
+
+ n.put(m, null);
+
+ Assert.assertTrue(result);
+ }
+
+ // from here down is testing infrastructure
+
+ public SimpleNodeIdentInfoReplyMessageTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {SimpleNodeIdentInfoReplyMessageTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(SimpleNodeIdentInfoReplyMessageTest.class);
+ return suite;
+ }
+}
Copied: trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentInfoRequestMessageTest.java (from rev 1872, trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationReplyMessageTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentInfoRequestMessageTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentInfoRequestMessageTest.java 2012-02-19 21:30:38 UTC (rev 1874)
@@ -0,0 +1,69 @@
+package org.openlcb;
+
+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 SimpleNodeIdentInfoRequestMessageTest extends TestCase {
+ boolean result;
+
+ NodeID nodeID1 = new NodeID(new byte[]{1,2,3,4,5,6});
+ NodeID nodeID2 = new NodeID(new byte[]{0,0,0,0,0,0});
+
+ public void testEqualsSame() {
+ Message m1 = new SimpleNodeIdentInfoRequestMessage(
+ nodeID1);
+ Message m2 = new SimpleNodeIdentInfoRequestMessage(
+ nodeID1);
+
+ Assert.assertTrue(m1.equals(m2));
+ }
+
+ public void testNotEqualsDifferentNode() {
+ Message m1 = new SimpleNodeIdentInfoRequestMessage(
+ nodeID1);
+ Message m2 = new SimpleNodeIdentInfoRequestMessage(
+ nodeID2);
+
+ Assert.assertTrue( ! m1.equals(m2));
+ }
+
+
+ public void testHandling() {
+ result = false;
+ Node n = new Node(){
+ @Override
+ public void handleSimpleNodeIdentInfoRequest(SimpleNodeIdentInfoRequestMessage msg, Connection sender){
+ result = true;
+ }
+ };
+ Message m = new SimpleNodeIdentInfoRequestMessage(nodeID1);
+
+ n.put(m, null);
+
+ Assert.assertTrue(result);
+ }
+
+ // from here down is testing infrastructure
+
+ public SimpleNodeIdentInfoRequestMessageTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {SimpleNodeIdentInfoRequestMessageTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(SimpleNodeIdentInfoRequestMessageTest.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-02-19 21:31:37
|
Revision: 1875
http://openlcb.svn.sourceforge.net/openlcb/?rev=1875&view=rev
Author: jacobsen
Date: 2012-02-19 21:31:31 +0000 (Sun, 19 Feb 2012)
Log Message:
-----------
new message type
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/MessageDecoder.java
trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java
Added Paths:
-----------
trunk/prototypes/java/src/org/openlcb/SimpleNodeIdent.java
trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentTest.java
Modified: trunk/prototypes/java/src/org/openlcb/MessageDecoder.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/MessageDecoder.java 2012-02-19 21:30:38 UTC (rev 1874)
+++ trunk/prototypes/java/src/org/openlcb/MessageDecoder.java 2012-02-19 21:31:31 UTC (rev 1875)
@@ -158,4 +158,16 @@
public void handleProtocolIdentificationReply(ProtocolIdentificationReplyMessage msg, Connection sender){
defaultHandler(msg, sender);
}
+ /**
+ * Handle "Simple Node Ident Info Request" message
+ */
+ public void handleSimpleNodeIdentInfoRequest(SimpleNodeIdentInfoRequestMessage msg, Connection sender){
+ defaultHandler(msg, sender);
+ }
+ /**
+ * Handle "Simple Node Ident Info Reply" message
+ */
+ public void handleSimpleNodeIdentInfoReply(SimpleNodeIdentInfoReplyMessage msg, Connection sender){
+ defaultHandler(msg, sender);
+ }
}
Copied: trunk/prototypes/java/src/org/openlcb/SimpleNodeIdent.java (from rev 1849, trunk/prototypes/java/src/org/openlcb/ProtocolIdentification.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/SimpleNodeIdent.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/SimpleNodeIdent.java 2012-02-19 21:31:31 UTC (rev 1875)
@@ -0,0 +1,71 @@
+// SimpleNodeIdent.java
+
+package org.openlcb;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Simple Node Ident Protocol
+ *
+ * @see http://www.openlcb.org/trunk/specs/drafts/GenProtocolIdS.pdf
+ * @author Bob Jacobsen Copyright (C) 2012
+ * @version $Revision: 18542 $
+ *
+ */
+public class SimpleNodeIdent {
+
+ public SimpleNodeIdent( SimpleNodeIdentInfoReplyMessage msg) {
+ byte data[] = msg.getData();
+ for (int i = 0; i < data.length ; i++ ) {
+ bytes[next++] = (byte)data[i];
+ }
+ }
+ public SimpleNodeIdent() {
+ }
+
+ byte[] bytes = new byte[128];
+ int next = 0;
+
+ public void addMsg(SimpleNodeIdentInfoReplyMessage msg) {
+ byte data[] = msg.getData();
+ for (int i = 0; i < data.length ; i++ ) {
+ bytes[next++] = (byte)data[i];
+ }
+ }
+
+ public String getMfgName() {
+ int len = 1;
+ int start = 1;
+ // skip mfg
+ for (; len < bytes.length; len++)
+ if (bytes[len] == 0) break;
+ return new String(bytes,start, len-start);
+ }
+ public String getModelName() {
+ int len = 1;
+ int start = 1;
+ // skip mfg
+ for (; len < bytes.length; len++)
+ if (bytes[len] == 0) break;
+ start = ++len;
+ for (; len < bytes.length; len++)
+ if (bytes[len] == 0) break;
+ return new String(bytes,start, len-start);
+ }
+ public String getVersion() {
+ int len = 1;
+ int start = 1;
+ // skip mfg, model
+ for (; len < bytes.length; len++)
+ if (bytes[len] == 0) break;
+ start = ++len;
+ for (; len < bytes.length; len++)
+ if (bytes[len] == 0) break;
+ start = ++len;
+ for (; len < bytes.length; len++)
+ if (bytes[len] == 0) break;
+ return new String(bytes,start, len-start);
+ }
+
+}
Modified: trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java 2012-02-19 21:30:38 UTC (rev 1874)
+++ trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java 2012-02-19 21:31:31 UTC (rev 1875)
@@ -78,12 +78,15 @@
// simple MTI
List<Message> retlist = new java.util.ArrayList<Message>();
NodeID source = map.getNodeID(getSourceID(f));
-
+
int type = getType(f);
switch (type) {
case 0x0A:
retlist.add(new VerifyNodeIDNumberMessage(source));
return retlist;
+ case 0x0B:
+ retlist.add(new VerifiedNodeIDNumberMessage(source));
+ return retlist;
case 0x24:
retlist.add(new IdentifyConsumersMessage(source, getEventID(f)));
return retlist;
@@ -111,9 +114,6 @@
case 0x08:
retlist.add(new InitializationCompleteMessage(source));
return retlist;
- case 0x0B:
- retlist.add(new VerifiedNodeIDNumberMessage(source));
- return retlist;
case 0x26:
retlist.add(new ConsumerIdentifiedMessage(source, getEventID(f)));
return retlist;
@@ -167,8 +167,28 @@
return retlist;
}
public List<Message> processFormat6(CanFrame f) {
- // addressed
- return null;
+ List<Message> retlist = new java.util.ArrayList<Message>();
+ NodeID source = map.getNodeID(getSourceID(f));
+ int type = f.getElement(0);
+ switch (type) {
+ case 0x2E:
+ retlist.add(new ProtocolIdentificationRequestMessage(source));
+ return retlist;
+ case 0x2F:
+ retlist.add(new ProtocolIdentificationReplyMessage(source,f.bodyAsLong()));
+ return retlist;
+ case 0x52:
+ retlist.add(new SimpleNodeIdentInfoRequestMessage(source));
+ return retlist;
+ case 0x53:
+ byte[] content = f.getData();
+ byte[] data = new byte[content.length-1];
+ System.arraycopy(content, 1, data, 0, data.length);
+
+ retlist.add(new SimpleNodeIdentInfoReplyMessage(source,data));
+ return retlist;
+ default: return null;
+ }
}
public List<Message> processFormat7(CanFrame f) {
// stream data
Copied: trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentTest.java (from rev 1849, trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentTest.java 2012-02-19 21:31:31 UTC (rev 1875)
@@ -0,0 +1,72 @@
+package org.openlcb;
+
+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 SimpleNodeIdentTest extends TestCase {
+ public void testCtor() {
+ new SimpleNodeIdent();
+ }
+
+ public void testCreationFromMessage() {
+ SimpleNodeIdent id = new SimpleNodeIdent(
+ new SimpleNodeIdentInfoReplyMessage(
+ new NodeID(new byte[]{1,3,3,4,5,6}),
+ new byte[]{1,'a','b','c',0,'z','y','x'}));
+
+ Assert.assertEquals("abc", id.getMfgName());
+ }
+
+ public void testCreationFromTwoMessages() {
+ SimpleNodeIdent id = new SimpleNodeIdent(
+ new SimpleNodeIdentInfoReplyMessage(
+ new NodeID(new byte[]{1,2,3,4,5,6}),
+ new byte[]{1,'a','b','c',0,'z','y','x'}));
+ id.addMsg(
+ new SimpleNodeIdentInfoReplyMessage(
+ new NodeID(new byte[]{1,2,3,4,5,6}),
+ new byte[]{0,'A','B','C',0,'Z',0}));
+
+ Assert.assertEquals("abc", id.getMfgName());
+ Assert.assertEquals("zyx", id.getModelName());
+ }
+
+ public void testSpannedCreationFromTwoMessages() {
+ SimpleNodeIdent id = new SimpleNodeIdent(
+ new SimpleNodeIdentInfoReplyMessage(
+ new NodeID(new byte[]{1,2,3,4,5,6}),
+ new byte[]{1,'a','b','c','d','e','f'}));
+ id.addMsg(
+ new SimpleNodeIdentInfoReplyMessage(
+ new NodeID(new byte[]{1,2,3,4,5,6}),
+ new byte[]{'g',0,'A','B',0,'Z',0}));
+
+ Assert.assertEquals("abcdefg", id.getMfgName());
+ Assert.assertEquals("AB", id.getModelName());
+ Assert.assertEquals("Z", id.getVersion());
+ }
+
+ // from here down is testing infrastructure
+
+ public SimpleNodeIdentTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {SimpleNodeIdentTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(SimpleNodeIdentTest.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-02-19 21:34:16
|
Revision: 1881
http://openlcb.svn.sourceforge.net/openlcb/?rev=1881&view=rev
Author: jacobsen
Date: 2012-02-19 21:34:10 +0000 (Sun, 19 Feb 2012)
Log Message:
-----------
and that completes 0.4.1, which goes into JMRI 2.99.3
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-02-19 21:33:33 UTC (rev 1880)
+++ trunk/prototypes/java/manifest 2012-02-19 21:34:10 UTC (rev 1881)
@@ -4,9 +4,9 @@
Name: org.openlcb
Specification-Title: \xD2OpenLCB\xD3
-Specification-Version: \xD20.4\xD3
+Specification-Version: \xD20.4.0\xD3
Specification-Vendor: \xD2OpenLCB group"
Package-Title: \xD2openlcb\xD3
-Package-Version: \xD20.4\xD3
+Package-Version: \xD20.4.0\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-03-14 19:43:25
|
Revision: 2017
http://openlcb.svn.sourceforge.net/openlcb/?rev=2017&view=rev
Author: jacobsen
Date: 2012-03-14 19:43:19 +0000 (Wed, 14 Mar 2012)
Log Message:
-----------
complete 1st pass
Added Paths:
-----------
trunk/prototypes/java/src/org/openlcb/implementations/DatagramService.java
trunk/prototypes/java/test/org/openlcb/implementations/DatagramServiceTest.java
Copied: trunk/prototypes/java/src/org/openlcb/implementations/DatagramService.java (from rev 1998, trunk/prototypes/java/src/org/openlcb/implementations/DatagramTransmitter.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/DatagramService.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/implementations/DatagramService.java 2012-03-14 19:43:19 UTC (rev 2017)
@@ -0,0 +1,162 @@
+package org.openlcb.implementations;
+
+import org.openlcb.*;
+
+// For annotations
+import net.jcip.annotations.*;
+import edu.umd.cs.findbugs.annotations.*;
+
+/**
+ * Service for sending and receiving data via datagrams.
+ *
+ * Meant to shield the using code from all the details of that
+ * process via some primitives:
+ * <ul>
+ * <li>Send data via a memo that gets notified on success
+ * <li>Register to be notified when data of a particular type arrives
+ * </ul>
+ *
+ *
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision$
+ */
+public class DatagramService extends MessageDecoder {
+
+ /**
+ * @param downstream Connection in the direction of the layout
+ */
+ public DatagramService(NodeID here, Connection downstream) {
+ this.here = here;
+ this.downstream = downstream;
+
+ }
+
+ static final int DEFAULT_ERROR_CODE = 0x1000;
+ NodeID here;
+ Connection downstream;
+
+ /**
+ * Send data to layout
+ */
+ public void sendData(DatagramServiceTransmitMemo memo){
+ xmtMemo = memo;
+ Message m = new DatagramMessage(here, memo.dest, memo.data);
+ downstream.put(m, this);
+ }
+
+ /**
+ * Handle "Datagram" message from layout
+ */
+ public void handleDatagram(DatagramMessage msg, Connection sender){
+ // forward
+ int retval = DEFAULT_ERROR_CODE;
+ if (rcvMemo != null && rcvMemo.type == msg.getData()[0]) {
+ retval = rcvMemo.handleData(msg.getData());
+ }
+ if (retval == 0) {
+ // accept
+ Message m = new DatagramAcknowledgedMessage(here, msg.getSourceNodeID());
+ downstream.put(m, this);
+ } else {
+ // reject
+ Message m = new DatagramRejectedMessage(here, msg.getSourceNodeID(), retval);
+ downstream.put(m, this);
+ }
+ }
+
+ /**
+ * Handle positive datagram reply message from layout
+ */
+ public void handleDatagramAcknowledged(DatagramAcknowledgedMessage msg, Connection sender){
+ if (xmtMemo != null) {
+ xmtMemo.handleReply(0);
+ }
+ xmtMemo = null;
+ }
+
+ DatagramServiceReceiveMemo rcvMemo;
+ DatagramServiceTransmitMemo xmtMemo;
+
+ /**
+ * Accept request to notify for a particular
+ * type of datagram
+ */
+ public void registerForReceive(DatagramServiceReceiveMemo memo) {
+ this.rcvMemo = memo;
+ }
+
+ @Immutable
+ @ThreadSafe
+ static protected class DatagramServiceReceiveMemo {
+ public DatagramServiceReceiveMemo(int type) {
+ this.type = type;
+ }
+
+ int type;
+
+ public boolean equals(Object o) {
+ if (o == null) return false;
+ if (! (o instanceof DatagramServiceReceiveMemo)) return false;
+ return this.type == ((DatagramServiceReceiveMemo)o).type;
+ }
+
+ public String toString() {
+ return "DatagramServiceReceiveMemo: "+type;
+ }
+
+ public int hashCode() { return type; }
+
+ /**
+ * Overload this to for notification of data.
+ * @returns 0 for OK, non-zero for error reply
+ */
+ public int handleData(int[] data) {
+ // default is error
+ return DEFAULT_ERROR_CODE;
+ }
+
+ }
+
+ @Immutable
+ @ThreadSafe
+ static protected class DatagramServiceTransmitMemo {
+ public DatagramServiceTransmitMemo(NodeID dest, int[] data) {
+ this.data = data;
+ this.dest = dest;
+ }
+
+ protected DatagramServiceTransmitMemo(NodeID dest) {
+ this.data = data;
+ this.dest = dest;
+ }
+
+ protected int[] data;
+ NodeID dest;
+
+ public boolean equals(Object o) {
+ if (o == null) return false;
+ if (! (o instanceof DatagramServiceTransmitMemo)) return false;
+ DatagramServiceTransmitMemo m = (DatagramServiceTransmitMemo) o;
+ if (this.data.length != m.data.length) return false;
+ if (this.dest != m.dest) return false;
+ for (int i = 0; i < this.data.length; i++)
+ if (this.data[i] != m.data[i]) return false;
+ return true;
+ }
+
+ public String toString() {
+ return "DatagramServiceTransmitMemo: "+data;
+ }
+
+ public int hashCode() { return this.data.length+this.data[0]+dest.hashCode(); }
+
+ /**
+ * Overload this to for notification of response
+ * @param code 0 for OK, non-zero for error reply
+ */
+ public void handleReply(int code) {
+ }
+
+ }
+
+}
Copied: trunk/prototypes/java/test/org/openlcb/implementations/DatagramServiceTest.java (from rev 1998, trunk/prototypes/java/test/org/openlcb/implementations/DatagramTransmitterTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/DatagramServiceTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/implementations/DatagramServiceTest.java 2012-03-14 19:43:19 UTC (rev 2017)
@@ -0,0 +1,187 @@
+package org.openlcb.implementations;
+
+import org.openlcb.*;
+
+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 DatagramServiceTest extends TestCase {
+
+ NodeID hereID = new NodeID(new byte[]{1,2,3,4,5,6});
+ NodeID farID = new NodeID(new byte[]{1,2,3,4,5,7});
+ Connection testConnection;
+ java.util.ArrayList<Message> messagesReceived;
+ boolean flag;
+ DatagramService service;
+
+ public void setUp() {
+ messagesReceived = new java.util.ArrayList<Message>();
+ testConnection = new Connection(){
+ public void put(Message msg, Connection sender) {
+ messagesReceived.add(msg);
+ }
+ };
+ service = new DatagramService(hereID, testConnection);
+ flag = false;
+ }
+
+
+
+ public void testCtorViaSetup() {
+ }
+
+ public void testRcvMemoIsRealClass() {
+ DatagramService.DatagramServiceReceiveMemo m20 =
+ new DatagramService.DatagramServiceReceiveMemo(0x20);
+ DatagramService.DatagramServiceReceiveMemo m21 =
+ new DatagramService.DatagramServiceReceiveMemo(0x21);
+
+ Assert.assertTrue(m20.equals(m20));
+ Assert.assertTrue(!m20.equals(null));
+ Assert.assertTrue(!m20.equals(m21));
+
+ }
+
+ public void testXmtMemoIsRealClass() {
+ DatagramService.DatagramServiceTransmitMemo m20 =
+ new DatagramService.DatagramServiceTransmitMemo(farID,new int[]{1});
+ DatagramService.DatagramServiceTransmitMemo m21 =
+ new DatagramService.DatagramServiceTransmitMemo(farID,new int[]{1});
+ DatagramService.DatagramServiceTransmitMemo m22 =
+ new DatagramService.DatagramServiceTransmitMemo(farID,new int[]{2});
+ DatagramService.DatagramServiceTransmitMemo m23 =
+ new DatagramService.DatagramServiceTransmitMemo(farID,new int[]{1,2});
+
+ Assert.assertTrue(m20.equals(m20));
+ Assert.assertTrue(m20.equals(m21));
+ Assert.assertTrue(!m20.equals(null));
+ Assert.assertTrue(!m20.equals(m22));
+ Assert.assertTrue(!m20.equals(m23));
+ Assert.assertTrue(!m22.equals(m20));
+ Assert.assertTrue(!m23.equals(m20));
+
+ }
+
+ public void testRegisterForData() {
+ DatagramService.DatagramServiceReceiveMemo m20 =
+ new DatagramService.DatagramServiceReceiveMemo(0x20);
+
+ service.registerForReceive(m20);
+ }
+
+ 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 int[]{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());
+
+ }
+
+
+ // from here down is testing infrastructure
+
+ public DatagramServiceTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {DatagramServiceTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(DatagramServiceTest.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-03-14 19:44:00
|
Revision: 2018
http://openlcb.svn.sourceforge.net/openlcb/?rev=2018&view=rev
Author: jacobsen
Date: 2012-03-14 19:43:53 +0000 (Wed, 14 Mar 2012)
Log Message:
-----------
complete first pass
Added Paths:
-----------
trunk/prototypes/java/src/org/openlcb/implementations/MemoryConfigurationService.java
trunk/prototypes/java/test/org/openlcb/implementations/MemoryConfigurationServiceTest.java
Added: trunk/prototypes/java/src/org/openlcb/implementations/MemoryConfigurationService.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/MemoryConfigurationService.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/implementations/MemoryConfigurationService.java 2012-03-14 19:43:53 UTC (rev 2018)
@@ -0,0 +1,159 @@
+package org.openlcb.implementations;
+
+import org.openlcb.*;
+
+// For annotations
+import net.jcip.annotations.*;
+import edu.umd.cs.findbugs.annotations.*;
+
+/**
+ * Service for reading and writing via the Memory Configuration protocol
+ *
+ * Meant to shield the using code from all the details of that
+ * process via read and write primitives.
+ *
+ *
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision: -1 $
+ */
+public class MemoryConfigurationService {
+
+ /**
+ * @param downstream Connection in the direction of the layout
+ */
+ public MemoryConfigurationService(NodeID here, DatagramService downstream) {
+ this.here = here;
+ this.downstream = downstream;
+ }
+
+ 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);
+ }
+
+ @Immutable
+ @ThreadSafe
+ static protected class McsReadMemo {
+ public McsReadMemo(NodeID dest, int space, long address, int count) {
+ this.count = count;
+ this.address = address;
+ this.space = space;
+ this.dest = dest;
+ }
+
+ int count;
+ long address;
+ int space;
+ NodeID dest;
+
+ public boolean equals(Object o) {
+ if (o == null) return false;
+ if (! (o instanceof McsReadMemo)) return false;
+ McsReadMemo m = (McsReadMemo) o;
+ if (this.dest != m.dest) return false;
+ if (this.space != m.space) return false;
+ if (this.address != m.address) return false;
+ return this.count == m.count;
+ }
+
+ public String toString() {
+ return "McsReadMemo: "+address;
+ }
+
+ public int hashCode() { return dest.hashCode()+space+((int)address)+count; }
+
+ /**
+ * Overload this for notification of failure reply
+ * @param non-zero for error reply
+ */
+ public void handleWriteReply(int code) {
+ }
+
+ /**
+ * Overload this for notification of data.
+ */
+ public void handleReadData(int[] data) {
+ }
+
+ }
+
+ @Immutable
+ @ThreadSafe
+ static protected class McsWriteMemo {
+ public McsWriteMemo(NodeID dest, int space, long address, int[] data) {
+ this.data = data;
+ this.address = address;
+ this.space = space;
+ this.dest = dest;
+ }
+
+ int[] data;
+ long address;
+ int space;
+ NodeID dest;
+
+ public boolean equals(Object o) {
+ if (o == null) return false;
+ if (! (o instanceof McsWriteMemo)) return false;
+ McsWriteMemo m = (McsWriteMemo) o;
+ if (this.dest != m.dest) return false;
+ if (this.space != m.space) return false;
+ if (this.address != m.address) return false;
+ if (this.data.length != m.data.length) return false;
+ for (int i = 0; i < this.data.length; i++)
+ if (this.data[i] != m.data[i]) return false;
+ return true;
+ }
+
+ public String toString() {
+ return "McsWriteMemo: "+address;
+ }
+
+ public int hashCode() { return this.data.length+this.data[0]+dest.hashCode()+((int)address)+space; }
+
+ /**
+ * Overload this for notification of response
+ * @param code 0 for OK, non-zero for error reply
+ */
+ public void handleWriteReply(int code) {
+ }
+
+ }
+
+ @Immutable
+ @ThreadSafe
+ protected class WriteDatagramMemo extends DatagramService.DatagramServiceTransmitMemo {
+ WriteDatagramMemo(NodeID dest, int space, long address, int[] 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[1] = 0x00;
+ 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;
+
+ for (int i = 0; i < content.length; i++)
+ this.data[6+(spaceByte ? 1 : 0)+i] = content[i];
+
+ this.memo = memo;
+ }
+ McsWriteMemo memo;
+ public void handleReply(int code) {
+ memo.handleWriteReply(code);
+ }
+
+
+ }
+
+}
Added: trunk/prototypes/java/test/org/openlcb/implementations/MemoryConfigurationServiceTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/MemoryConfigurationServiceTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/implementations/MemoryConfigurationServiceTest.java 2012-03-14 19:43:53 UTC (rev 2018)
@@ -0,0 +1,258 @@
+package org.openlcb.implementations;
+
+import org.openlcb.*;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision: -1 $
+ */
+public class MemoryConfigurationServiceTest extends TestCase {
+
+ NodeID hereID = new NodeID(new byte[]{1,2,3,4,5,6});
+ NodeID farID = new NodeID(new byte[]{1,2,3,4,5,7});
+ Connection testConnection;
+ java.util.ArrayList<Message> messagesReceived;
+ boolean flag;
+ DatagramService datagramService;
+ MemoryConfigurationService service;
+
+ public void setUp() {
+ messagesReceived = new java.util.ArrayList<Message>();
+ flag = false;
+ testConnection = new Connection(){
+ public void put(Message msg, Connection sender) {
+ messagesReceived.add(msg);
+ }
+ };
+ datagramService = new DatagramService(hereID, testConnection);
+
+ service = new MemoryConfigurationService(hereID, datagramService);
+ }
+
+
+
+ public void testCtorViaSetup() {
+ }
+
+ public void testReadMemoIsRealClass() {
+ MemoryConfigurationService.McsReadMemo m20 =
+ new MemoryConfigurationService.McsReadMemo(farID,0xFD, 0x0000, 2);
+ MemoryConfigurationService.McsReadMemo m20a =
+ new MemoryConfigurationService.McsReadMemo(farID,0xFD, 0x0000, 2);
+ MemoryConfigurationService.McsReadMemo m21 =
+ new MemoryConfigurationService.McsReadMemo(hereID,0xFD, 0x0000, 2);
+ MemoryConfigurationService.McsReadMemo m22 =
+ new MemoryConfigurationService.McsReadMemo(farID,0xFE, 0x0000, 2);
+ MemoryConfigurationService.McsReadMemo m23 =
+ new MemoryConfigurationService.McsReadMemo(farID,0xFD, 0x0001, 2);
+ MemoryConfigurationService.McsReadMemo m24 =
+ new MemoryConfigurationService.McsReadMemo(farID,0xFD, 0x0000, 3);
+
+ Assert.assertTrue(m20.equals(m20));
+ Assert.assertTrue(m20.equals(m20a));
+
+ Assert.assertTrue(!m20.equals(null));
+
+ Assert.assertTrue(!m20.equals(m21));
+ Assert.assertTrue(!m20.equals(m22));
+ Assert.assertTrue(!m20.equals(m23));
+ Assert.assertTrue(!m20.equals(m24));
+
+ }
+
+ public void testWriteMemoIsRealClass() {
+ MemoryConfigurationService.McsWriteMemo m20 =
+ new MemoryConfigurationService.McsWriteMemo(farID,0xFD, 0x0000, new int[]{1,2});
+ MemoryConfigurationService.McsWriteMemo m20a =
+ new MemoryConfigurationService.McsWriteMemo(farID,0xFD, 0x0000, new int[]{1,2});
+ MemoryConfigurationService.McsWriteMemo m21 =
+ new MemoryConfigurationService.McsWriteMemo(hereID,0xFD, 0x0000, new int[]{1,2});
+ MemoryConfigurationService.McsWriteMemo m22 =
+ new MemoryConfigurationService.McsWriteMemo(farID,0xFE, 0x0000, new int[]{1,2});
+ MemoryConfigurationService.McsWriteMemo m23 =
+ new MemoryConfigurationService.McsWriteMemo(farID,0xFD, 0x0001, new int[]{1,2});
+ MemoryConfigurationService.McsWriteMemo m24 =
+ new MemoryConfigurationService.McsWriteMemo(farID,0xFD, 0x0000, new int[]{1});
+ MemoryConfigurationService.McsWriteMemo m25 =
+ new MemoryConfigurationService.McsWriteMemo(farID,0xFD, 0x0000, new int[]{1,2,3});
+ MemoryConfigurationService.McsWriteMemo m26 =
+ new MemoryConfigurationService.McsWriteMemo(farID,0xFD, 0x0000, new int[]{1,5,3});
+
+ Assert.assertTrue(m20.equals(m20));
+ Assert.assertTrue(m20.equals(m20a));
+
+ Assert.assertTrue(!m20.equals(null));
+
+ Assert.assertTrue(!m20.equals(m21));
+ Assert.assertTrue(!m20.equals(m22));
+ Assert.assertTrue(!m20.equals(m23));
+ Assert.assertTrue(!m20.equals(m24));
+ Assert.assertTrue(!m20.equals(m25));
+ Assert.assertTrue(!m20.equals(m26));
+
+ }
+
+ public void testSimpleWrite() {
+ int space = 0xFD;
+ long address = 0x12345678;
+ int[] data = new int[]{1,2};
+ MemoryConfigurationService.McsWriteMemo memo =
+ new MemoryConfigurationService.McsWriteMemo(farID, space, address, data) {
+ public void handleWriteReply(int code) {
+ 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 write
+ int[] content = ((DatagramMessage)messagesReceived.get(0)).getData();
+ Assert.assertTrue(content.length >= 6);
+ Assert.assertEquals("datagram type", 0x20, content[0]);
+ Assert.assertEquals("write command", 0x00, (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", content.length-6, data.length);
+ for (int i = 0; i<data.length; i++)
+ Assert.assertEquals("data byte "+i, content[i+6], data[i]);
+ } else {
+ Assert.assertEquals("space byte", space, content[6]);
+ Assert.assertEquals("data length", content.length-7, data.length);
+ for (int i = 0; i<data.length; i++)
+ Assert.assertEquals("data byte "+i, content[i+7], data[i]);
+ }
+
+ // datagram reply comes back
+ Message m = new DatagramAcknowledgedMessage(farID, hereID);
+
+ Assert.assertTrue(!flag);
+ datagramService.put(m, null);
+ Assert.assertTrue(flag);
+
+ }
+
+// 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 int[]{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());
+//
+// }
+
+
+ // from here down is testing infrastructure
+
+ public MemoryConfigurationServiceTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {MemoryConfigurationServiceTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(MemoryConfigurationServiceTest.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-03-14 19:44:43
|
Revision: 2019
http://openlcb.svn.sourceforge.net/openlcb/?rev=2019&view=rev
Author: jacobsen
Date: 2012-03-14 19:44:37 +0000 (Wed, 14 Mar 2012)
Log Message:
-----------
datagram Nak reply code
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/implementations/DatagramMeteringBuffer.java
trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java
trunk/prototypes/java/test/org/openlcb/implementations/DatagramTransmitterTest.java
Modified: trunk/prototypes/java/src/org/openlcb/implementations/DatagramMeteringBuffer.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/DatagramMeteringBuffer.java 2012-03-14 19:43:53 UTC (rev 2018)
+++ trunk/prototypes/java/src/org/openlcb/implementations/DatagramMeteringBuffer.java 2012-03-14 19:44:37 UTC (rev 2019)
@@ -18,7 +18,7 @@
*<ul>
*<li>Does not parallelize Datagrams to separate nodes
*<li>Does not yet check NAK for transient vs permanent
- *<li>Needs to timeout and resume operation is no reply received
+ *<li>Needs to timeout and resume operation if no reply received
*</ul>
*<p>
*
Modified: trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java 2012-03-14 19:43:53 UTC (rev 2018)
+++ trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java 2012-03-14 19:44:37 UTC (rev 2019)
@@ -63,7 +63,7 @@
datagram2 = new DatagramMessage(hereID, farID, data);
replyOK = new DatagramAcknowledgedMessage(farID, hereID);
- replyNAK = new DatagramRejectedMessage(farID, hereID);
+ replyNAK = new DatagramRejectedMessage(farID, hereID, 0x010);
}
public void testSend() throws InterruptedException {
Modified: trunk/prototypes/java/test/org/openlcb/implementations/DatagramTransmitterTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/DatagramTransmitterTest.java 2012-03-14 19:43:53 UTC (rev 2018)
+++ trunk/prototypes/java/test/org/openlcb/implementations/DatagramTransmitterTest.java 2012-03-14 19:44:37 UTC (rev 2019)
@@ -69,7 +69,7 @@
.equals(new DatagramMessage(hereID, farID, data)));
// Reject once
- Message m = new DatagramRejectedMessage(farID, hereID);
+ Message m = new DatagramRejectedMessage(farID, hereID,0x021);
messagesReceived = new java.util.ArrayList<Message>();
xmt.put(m, null);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-04-29 04:59:56
|
Revision: 2150
http://openlcb.svn.sourceforge.net/openlcb/?rev=2150&view=rev
Author: jacobsen
Date: 2012-04-29 04:59:50 +0000 (Sun, 29 Apr 2012)
Log Message:
-----------
format is dotted hex pairs
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/EventID.java
trunk/prototypes/java/src/org/openlcb/NodeID.java
trunk/prototypes/java/test/org/openlcb/EventIDTest.java
trunk/prototypes/java/test/org/openlcb/NodeIDTest.java
Added Paths:
-----------
trunk/prototypes/java/src/org/openlcb/Utilities.java
Modified: trunk/prototypes/java/src/org/openlcb/EventID.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/EventID.java 2012-04-28 21:53:26 UTC (rev 2149)
+++ trunk/prototypes/java/src/org/openlcb/EventID.java 2012-04-29 04:59:50 UTC (rev 2150)
@@ -79,14 +79,14 @@
@CheckReturnValue
@NonNull
public String toString() {
- return "Event:"
- +contents[0]+","
- +contents[1]+","
- +contents[2]+","
- +contents[3]+","
- +contents[4]+","
- +contents[5]+","
- +contents[6]+","
- +contents[7];
+ return "EventID:"
+ +Utilities.toHexPair(contents[0])+"."
+ +Utilities.toHexPair(contents[1])+"."
+ +Utilities.toHexPair(contents[2])+"."
+ +Utilities.toHexPair(contents[3])+"."
+ +Utilities.toHexPair(contents[4])+"."
+ +Utilities.toHexPair(contents[5])+"."
+ +Utilities.toHexPair(contents[6])+"."
+ +Utilities.toHexPair(contents[7]);
}
}
Modified: trunk/prototypes/java/src/org/openlcb/NodeID.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/NodeID.java 2012-04-28 21:53:26 UTC (rev 2149)
+++ trunk/prototypes/java/src/org/openlcb/NodeID.java 2012-04-29 04:59:50 UTC (rev 2150)
@@ -77,11 +77,12 @@
@NonNull
public String toString() {
return "NodeID:"
- +contents[0]+","
- +contents[1]+","
- +contents[2]+","
- +contents[3]+","
- +contents[4]+","
- +contents[5];
+ +Utilities.toHexPair(contents[0])+"."
+ +Utilities.toHexPair(contents[1])+"."
+ +Utilities.toHexPair(contents[2])+"."
+ +Utilities.toHexPair(contents[3])+"."
+ +Utilities.toHexPair(contents[4])+"."
+ +Utilities.toHexPair(contents[5]);
}
+
}
Copied: trunk/prototypes/java/src/org/openlcb/Utilities.java (from rev 2141, trunk/prototypes/java/src/org/openlcb/NodeID.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/Utilities.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/Utilities.java 2012-04-29 04:59:50 UTC (rev 2150)
@@ -0,0 +1,25 @@
+package org.openlcb;
+
+// For annotations
+import net.jcip.annotations.*;
+import edu.umd.cs.findbugs.annotations.*;
+
+/**
+ * Common service methods (a library, not a class)
+ * <p>
+ * NodeID objects are immutable once created.
+ *
+ * @author Bob Jacobsen Copyright 2009, 2010, 2011 2012
+ * @version $Revision$
+ */
+@Immutable
+@ThreadSafe
+public class Utilities {
+
+ @CheckReturnValue
+ @NonNull
+ static public String toHexPair(int i) {
+ String retval = "00"+Integer.toHexString(i).toUpperCase();
+ return retval.substring(retval.length()-2);
+ }
+}
Modified: trunk/prototypes/java/test/org/openlcb/EventIDTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/EventIDTest.java 2012-04-28 21:53:26 UTC (rev 2149)
+++ trunk/prototypes/java/test/org/openlcb/EventIDTest.java 2012-04-29 04:59:50 UTC (rev 2150)
@@ -85,6 +85,11 @@
Assert.assertTrue(!e1.equals(e2));
}
+ public void testOutputFormat() {
+ EventID e1 = new EventID(new byte[]{0,0,1,0x10,0x13,0x0D,(byte)0xD0,(byte)0xAB});
+ Assert.assertEquals(e1.toString(), "EventID:00.00.01.10.13.0D.D0.AB");
+ }
+
// from here down is testing infrastructure
public EventIDTest(String s) {
Modified: trunk/prototypes/java/test/org/openlcb/NodeIDTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/NodeIDTest.java 2012-04-28 21:53:26 UTC (rev 2149)
+++ trunk/prototypes/java/test/org/openlcb/NodeIDTest.java 2012-04-29 04:59:50 UTC (rev 2150)
@@ -106,6 +106,11 @@
Assert.assertTrue(contents[5] == 6);
}
+ 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");
+ }
+
// from here down is testing infrastructure
public NodeIDTest(String s) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-04-29 05:31:52
|
Revision: 2151
http://openlcb.svn.sourceforge.net/openlcb/?rev=2151&view=rev
Author: jacobsen
Date: 2012-04-29 05:31:45 +0000 (Sun, 29 Apr 2012)
Log Message:
-----------
new class
Modified Paths:
--------------
trunk/prototypes/java/test/org/openlcb/PackageTest.java
Added Paths:
-----------
trunk/prototypes/java/src/org/openlcb/MessageTypeIdentifier.java
trunk/prototypes/java/test/org/openlcb/MessageTypeIdentifierTest.java
Copied: trunk/prototypes/java/src/org/openlcb/MessageTypeIdentifier.java (from rev 2091, trunk/prototypes/java/src/org/openlcb/ProtocolIdentification.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/MessageTypeIdentifier.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/MessageTypeIdentifier.java 2012-04-29 05:31:45 UTC (rev 2151)
@@ -0,0 +1,52 @@
+// MessageTypeIdentifier.java
+
+package org.openlcb;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Message Type Identifiers
+ *
+ * Central place to carry the (only) numerical values for
+ * Message Type Identifiers
+ *
+ * @see http://www.openlcb.org/trunk/specs/drafts/
+ * @author Bob Jacobsen Copyright (C) 2012
+ * @version $Revision: 18542 $
+ *
+ */
+public enum MessageTypeIdentifier {
+
+ ProtocolIdentification( 0x800000000000L,"ProtocolIdentification"),
+ Datagram( 0x400000000000L,"Datagram"),
+ Stream( 0x200000000000L,"Stream"),
+ Configuration( 0x100000000000L,"Configuration"),
+ Reservation( 0x080000000000L,"Reservation"),
+ ProducerConsumer( 0x040000000000L,"ProducerConsumer"),
+ Identification( 0x020000000000L,"Identification"),
+ TeachingLearningConfiguration(0x010000000000L,"TeachingLearningConfiguration"),
+ RemoteButton( 0x008000000000L,"RemoteButton"),
+ AbbreviatedDefaultCDI( 0x004000000000L,"AbbreviatedDefaultCDI"),
+ Display( 0x002000000000L,"Display");
+
+ MessageTypeIdentifier(long value, String name) {
+ this.value = value;
+ this.name = name;
+ }
+ long value;
+ String name;
+
+ boolean supports(long r) {
+ return ( (this.value & r) != 0 );
+ }
+
+ static List<String> decode(long r) {
+ ArrayList<String> retval = new ArrayList<String>();
+ for (MessageTypeIdentifier t : MessageTypeIdentifier.values()) {
+ if ( t.supports(r) ) retval.add(t.name);
+ }
+ return retval;
+ }
+
+}
Copied: trunk/prototypes/java/test/org/openlcb/MessageTypeIdentifierTest.java (from rev 2091, trunk/prototypes/java/test/org/openlcb/MessageTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/MessageTypeIdentifierTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/MessageTypeIdentifierTest.java 2012-04-29 05:31:45 UTC (rev 2151)
@@ -0,0 +1,49 @@
+package org.openlcb;
+
+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 MessageTypeIdentifierTest extends TestCase {
+
+ public void testEqualsSame() {
+ Message m1 = new Message(new NodeID(new byte[]{1,2,3,4,5,6}) )
+ {public int getMTI() {return 0; }};
+ Message m2 = new Message(new NodeID(new byte[]{1,2,3,4,5,6}) )
+ {public int getMTI() {return 0; }};
+
+ Assert.assertTrue(m1.equals(m2));
+ }
+
+ public void testNotEqualsDifferent() {
+ Message m1 = new Message(new NodeID(new byte[]{1,2,3,4,5,6}) )
+ {public int getMTI() {return 0; }};
+ Message m2 = new Message(new NodeID(new byte[]{1,3,3,4,5,6}) )
+ {public int getMTI() {return 0; }};
+
+ Assert.assertTrue( ! m1.equals(m2));
+ }
+
+ // from here down is testing infrastructure
+
+ public MessageTypeIdentifierTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {MessageTypeIdentifierTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(MessageTypeIdentifierTest.class);
+ return suite;
+ }
+}
Modified: trunk/prototypes/java/test/org/openlcb/PackageTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/PackageTest.java 2012-04-29 04:59:50 UTC (rev 2150)
+++ trunk/prototypes/java/test/org/openlcb/PackageTest.java 2012-04-29 05:31:45 UTC (rev 2151)
@@ -32,6 +32,8 @@
suite.addTest(EventIDTest.suite());
suite.addTest(NodeIDTest.suite());
+ suite.addTest(MessageTypeIdentifierTest.suite());
+
suite.addTest(MessageTest.suite());
suite.addTest(MessageDecoderTest.suite());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-04-29 05:55:55
|
Revision: 2152
http://openlcb.svn.sourceforge.net/openlcb/?rev=2152&view=rev
Author: jacobsen
Date: 2012-04-29 05:55:49 +0000 (Sun, 29 Apr 2012)
Log Message:
-----------
basic tests
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/MessageTypeIdentifier.java
trunk/prototypes/java/test/org/openlcb/MessageTypeIdentifierTest.java
Modified: trunk/prototypes/java/src/org/openlcb/MessageTypeIdentifier.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/MessageTypeIdentifier.java 2012-04-29 05:31:45 UTC (rev 2151)
+++ trunk/prototypes/java/src/org/openlcb/MessageTypeIdentifier.java 2012-04-29 05:55:49 UTC (rev 2152)
@@ -18,35 +18,22 @@
*/
public enum MessageTypeIdentifier {
- ProtocolIdentification( 0x800000000000L,"ProtocolIdentification"),
- Datagram( 0x400000000000L,"Datagram"),
- Stream( 0x200000000000L,"Stream"),
- Configuration( 0x100000000000L,"Configuration"),
- Reservation( 0x080000000000L,"Reservation"),
- ProducerConsumer( 0x040000000000L,"ProducerConsumer"),
- Identification( 0x020000000000L,"Identification"),
- TeachingLearningConfiguration(0x010000000000L,"TeachingLearningConfiguration"),
- RemoteButton( 0x008000000000L,"RemoteButton"),
- AbbreviatedDefaultCDI( 0x004000000000L,"AbbreviatedDefaultCDI"),
- Display( 0x002000000000L,"Display");
+ // Arguments are addressed,
+ InitializationComplete( false, 0x1080, 0x18017, 0x00, "InitializationComplete"),
+ VerifyNodeIdAddressed ( true, 0x1080, 0x18017, 0x00, "VerifyNodeIdAddressed"),
+ VerifyNodeIdGlobal ( false, 0x1080, 0x18017, 0x00, "VerifyNodeIdGlobal"),
+ VerifiedNodeId ( false, 0x1080, 0x18017, 0x00, "VerifyNodeIdGlobal"),
+ OptionalIntRejected ( false, 0x1080, 0x18017, 0x00, "VerifyNodeIdGlobal"),
+ TerminateDueToError ( false, 0x1080, 0x18017, 0x00, "VerifyNodeIdGlobal");
- MessageTypeIdentifier(long value, String name) {
- this.value = value;
+ MessageTypeIdentifier(boolean addressed, long genMTI, int a, int b, String name) {
+ this.genMTI = genMTI;
this.name = name;
}
- long value;
+ long genMTI;
String name;
- boolean supports(long r) {
- return ( (this.value & r) != 0 );
+ public String toString() {
+ return name;
}
-
- static List<String> decode(long r) {
- ArrayList<String> retval = new ArrayList<String>();
- for (MessageTypeIdentifier t : MessageTypeIdentifier.values()) {
- if ( t.supports(r) ) retval.add(t.name);
- }
- return retval;
- }
-
}
Modified: trunk/prototypes/java/test/org/openlcb/MessageTypeIdentifierTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/MessageTypeIdentifierTest.java 2012-04-29 05:31:45 UTC (rev 2151)
+++ trunk/prototypes/java/test/org/openlcb/MessageTypeIdentifierTest.java 2012-04-29 05:55:49 UTC (rev 2152)
@@ -11,24 +11,28 @@
*/
public class MessageTypeIdentifierTest extends TestCase {
- public void testEqualsSame() {
- Message m1 = new Message(new NodeID(new byte[]{1,2,3,4,5,6}) )
- {public int getMTI() {return 0; }};
- Message m2 = new Message(new NodeID(new byte[]{1,2,3,4,5,6}) )
- {public int getMTI() {return 0; }};
-
- Assert.assertTrue(m1.equals(m2));
+ public void testCtor() {
+ MessageTypeIdentifier mti1 = MessageTypeIdentifier.InitializationComplete;
}
- public void testNotEqualsDifferent() {
- Message m1 = new Message(new NodeID(new byte[]{1,2,3,4,5,6}) )
- {public int getMTI() {return 0; }};
- Message m2 = new Message(new NodeID(new byte[]{1,3,3,4,5,6}) )
- {public int getMTI() {return 0; }};
-
- Assert.assertTrue( ! m1.equals(m2));
+ public void testEquals() {
+ MessageTypeIdentifier mti1 = MessageTypeIdentifier.InitializationComplete;
+ MessageTypeIdentifier mti2 = MessageTypeIdentifier.InitializationComplete;
+ Assert.assertEquals(mti1, mti2);
}
+ public void testNotEquals() {
+ MessageTypeIdentifier mti1 = MessageTypeIdentifier.InitializationComplete;
+ MessageTypeIdentifier mti2 = MessageTypeIdentifier.VerifyNodeIdAddressed;
+ Assert.assertTrue(!mti1.equals(mti2));
+ }
+
+ public void testToString() {
+ MessageTypeIdentifier mti1 = MessageTypeIdentifier.InitializationComplete;
+ Assert.assertEquals(mti1.toString(), "InitializationComplete");
+
+ }
+
// from here down is testing infrastructure
public MessageTypeIdentifierTest(String s) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-04-30 06:23:45
|
Revision: 2163
http://openlcb.svn.sourceforge.net/openlcb/?rev=2163&view=rev
Author: jacobsen
Date: 2012-04-30 06:23:38 +0000 (Mon, 30 Apr 2012)
Log Message:
-----------
implementation (not complete) of Great MTI Migration
Modified Paths:
--------------
trunk/prototypes/java/openlcb-demo.jar
trunk/prototypes/java/openlcb.jar
trunk/prototypes/java/src/org/openlcb/MessageTypeIdentifier.java
trunk/prototypes/java/src/org/openlcb/OpenLcb.java
trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java
trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java
trunk/prototypes/java/test/org/openlcb/MessageTypeIdentifierTest.java
trunk/prototypes/java/test/org/openlcb/can/MessageBuilderTest.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/MessageTypeIdentifier.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/MessageTypeIdentifier.java 2012-04-30 06:23:01 UTC (rev 2162)
+++ trunk/prototypes/java/src/org/openlcb/MessageTypeIdentifier.java 2012-04-30 06:23:38 UTC (rev 2163)
@@ -18,22 +18,85 @@
*/
public enum MessageTypeIdentifier {
- // Arguments are addressed,
- InitializationComplete( false, 0x1080, 0x18017, 0x00, "InitializationComplete"),
- VerifyNodeIdAddressed ( true, 0x1080, 0x18017, 0x00, "VerifyNodeIdAddressed"),
- VerifyNodeIdGlobal ( false, 0x1080, 0x18017, 0x00, "VerifyNodeIdGlobal"),
- VerifiedNodeId ( false, 0x1080, 0x18017, 0x00, "VerifyNodeIdGlobal"),
- OptionalIntRejected ( false, 0x1080, 0x18017, 0x00, "VerifyNodeIdGlobal"),
- TerminateDueToError ( false, 0x1080, 0x18017, 0x00, "VerifyNodeIdGlobal");
+ // Arguments are
+ // addressed?
+ // contains Event ID?
+ // Flags in Header?
+ // Simple node message?
+ // Priority Group
+ // Type number
+
+ InitializationComplete ( false, false, false, false, 0x0, 0x08, "InitializationComplete"),
+ VerifyNodeIdAddressed ( true, false, false, false, 0x0, 0x0A, "VerifyNodeIdAddressed"),
+ VerifyNodeIdGlobal ( false, false, false, true, 0x0, 0x0A, "VerifyNodeIdGlobal"),
+ VerifiedNodeId ( false, false, false, true, 0x0, 0x0B, "VerifiedNodeId"),
+ OptionalInteractionRejected ( true, false, false, false, 0x0, 0x0C, "OptionalInteractionRejected"),
+ TerminateDueToError ( true, false, false, false, 0x0, 0x0D, "TerminateDueToError"),
+
+ ProtocolSupportInquiry ( true, false, false, false, 0x1, 0x0E, "ProtocolSupportInquiry"),
+ ProtocolSupportReply ( true, false, false, false, 0x1, 0x0F, "ProtocolSupportReply"),
+
+ IdentifyConsumer ( false, true, false, true, 0x1, 0x04, "IdentifyConsumer"),
+ ConsumerIdentifyRange ( false, true, false, false, 0x1, 0x05, "ConsumerIdentifyRange"),
+ ConsumerIdentified ( false, true, true, false, 0x1, 0x06, "ConsumerIdentified"),
+
+ IdentifyProducer ( false, true, false, true, 0x1, 0x08, "IdentifyProducer"),
+ ProducerIdentifyRange ( false, true, false, false, 0x1, 0x09, "ProducerIdentifyRange"),
+ ProducerIdentified ( false, true, true, false, 0x1, 0x0A, "ProducerIdentified"),
+
+ IdentifyEventsAddressed ( true, false, false, false, 0x1, 0x0B, "IdentifyEventsAddressed"),
+ IdentifyEventsGlobal ( false, false, false, true, 0x1, 0x0B, "IdentifyEventsGlobal"),
+
+ LearnEvent ( false, true, false, true, 0x1, 0x0C, "LearnEvent"),
+ ProducerConsumerEventReport ( false, true, false, true, 0x1, 0x0D, "ProducerConsumerEventReport"),
+
+ SimpleNodeIdentInfoRequest ( true, false, false, false, 0x2, 0x12, "SimpleNodeIdentInfoRequest"),
+ SimpleNodeIdentInfoReply ( true, false, false, false, 0x2, 0x13, "SimpleNodeIdentInfoReply"),
+
+ Datagram ( true, false, false, false, 0x2, 0x00, "Datagram"),
+ DatagramReceivedOK ( true, false, false, false, 0x2, 0x0C, "DatagramReceivedOK"),
+ DatagramRejected ( true, false, false, false, 0x2, 0x0D, "DatagramRejected"),
+
+ StreamInitiateRequest ( true, false, false, false, 0x2, 0x0E, "StreamInitiateRequest"),
+ StreamInitiateReply ( true, false, false, false, 0x2, 0x0F, "StreamDataSend"),
+ StreamDataSend ( true, false, false, false, 0x3, 0x09, "StreamDataSend"),
+ StreamDataProceed ( true, false, false, false, 0x3, 0x0A, "StreamDataProceed"),
+ StreamDataComplete ( true, false, false, false, 0x3, 0x0B, "StreamDataComplete");
- MessageTypeIdentifier(boolean addressed, long genMTI, int a, int b, String name) {
- this.genMTI = genMTI;
+ MessageTypeIdentifier(boolean addressed, boolean hasEventID, boolean hasFlagsInHeader,
+ boolean isSimpleModeMessage, int priorityGroup, int typeNumber, String name) {
+ this.addressed = addressed;
+ this.hasEventID = hasEventID;
+ this.hasFlagsInHeader = hasFlagsInHeader;
+ this.isSimpleModeMessage = isSimpleModeMessage;
+ this.priorityGroup = priorityGroup;
+ this.typeNumber = typeNumber;
this.name = name;
}
- long genMTI;
+
+ boolean addressed;
+ boolean hasEventID;
+ boolean hasFlagsInHeader;
+ boolean isSimpleModeMessage;
+ int priorityGroup;
+ int typeNumber;
+
String name;
public String toString() {
return name;
}
+
+ public long mti() {
+ long retval = 0x1000;
+ if (addressed) retval = retval | 0x0004;
+ if (hasEventID) retval = retval | 0x0002;
+ if (hasFlagsInHeader) retval = retval | 0x0001;
+ if (isSimpleModeMessage) retval = retval | 0x0800;
+
+ retval = retval | (priorityGroup << 4+5);
+ retval = retval | (typeNumber << 4);
+
+ return retval;
+ }
}
Modified: trunk/prototypes/java/src/org/openlcb/OpenLcb.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/OpenLcb.java 2012-04-30 06:23:01 UTC (rev 2162)
+++ trunk/prototypes/java/src/org/openlcb/OpenLcb.java 2012-04-30 06:23:38 UTC (rev 2163)
@@ -1,5 +1,9 @@
package org.openlcb;
+//
+// Eventually, these should go away
+//
+
public interface OpenLcb {
@@ -7,7 +11,7 @@
* MTI definitions for OpenLCB.
*/
- static final int MTI_INITIALIZATION_COMPLETE = 0x3080;
+ static final int MTI_INITIALIZATION_COMPLETE = (int)MessageTypeIdentifier.InitializationComplete.mti();
static final int MTI_VERIFY_NID = 0x10A4;
static final int MTI_VERIFIED_NID = 0x10B0;
Modified: trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java 2012-04-30 06:23:01 UTC (rev 2162)
+++ trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java 2012-04-30 06:23:38 UTC (rev 2163)
@@ -74,43 +74,31 @@
int getType(CanFrame f) { return ( f.getHeader() & 0x00FF0000 ) >> 16; }
EventID getEventID(CanFrame f) { return new EventID(f.getData()); }
- public List<Message> processFormat0(CanFrame f) {
+ List<Message> processFormat0(CanFrame f) {
// simple MTI
List<Message> retlist = new java.util.ArrayList<Message>();
NodeID source = map.getNodeID(getSourceID(f));
int type = getType(f);
switch (type) {
- case 0x0A:
+ case 0x8A:
retlist.add(new VerifyNodeIDNumberMessage(source));
return retlist;
- case 0x0B:
+ case 0x8B:
retlist.add(new VerifiedNodeIDNumberMessage(source));
return retlist;
- case 0x24:
+ case 0xA4:
retlist.add(new IdentifyConsumersMessage(source, getEventID(f)));
return retlist;
- case 0x28:
+ case 0xA8:
retlist.add(new IdentifyProducersMessage(source, getEventID(f)));
return retlist;
- case 0x2B:
- retlist.add(new IdentifyEventsMessage(source));
- return retlist;
- case 0x2C:
+ case 0xAC:
retlist.add(new LearnEventMessage(source, getEventID(f)));
return retlist;
- case 0x2D:
+ case 0xAD:
retlist.add(new ProducerConsumerEventReportMessage(source, getEventID(f)));
return retlist;
- default: return null;
- }
- }
- public List<Message> processFormat1(CanFrame f) {
- // complex MTI
- List<Message> retlist = new java.util.ArrayList<Message>();
- NodeID source = map.getNodeID(getSourceID(f));
- int type = getType(f);
- switch (type) {
case 0x08:
retlist.add(new InitializationCompleteMessage(source));
return retlist;
@@ -123,19 +111,56 @@
default: return null;
}
}
- public List<Message> processFormat2(CanFrame f) {
+ List<Message> processFormat1(CanFrame f) {
// reserved
return null;
}
- public List<Message> processFormat3(CanFrame f) {
- // reserved
+ List<Message> processFormat2(CanFrame f) {
+ // datagram only-segment
+ NodeID source = map.getNodeID(getSourceID(f));
+ List<Integer> list = datagramData.get(source);
+ if (list == null) {
+ list = new ArrayList<Integer>();
+ // don't need to put it back, as we're doing just one
+ } else {
+ // this is actually an error, datagram already in process for only-segment
+ }
+ for (int i = 0; i < f.getNumDataElements(); i++) {
+ list.add(f.getElement(i));
+ }
+
+ // done, forward
+
+ int[] data = new int[list.size()];
+ for (int i=0; i<list.size(); i++) {
+ data[i] = list.get(i);
+ }
+ List<Message> retlist = new java.util.ArrayList<Message>();
+ NodeID dest = map.getNodeID( (f.getHeader() & 0x00FFF000) >> 12);
+ retlist.add(new DatagramMessage(source, dest, data));
+ return retlist;
+ }
+ List<Message> processFormat3(CanFrame f) {
+ // datagram first-segment
+ NodeID source = map.getNodeID(getSourceID(f));
+ List<Integer> list = datagramData.get(source);
+ if (list == null) {
+ list = new ArrayList<Integer>();
+ datagramData.put(source, list);
+ } else {
+ // this is actually an error, datagram already in process for only-segment
+ }
+ for (int i = 0; i < f.getNumDataElements(); i++) {
+ list.add(f.getElement(i));
+ }
return null;
}
- public List<Message> processFormat4(CanFrame f) {
- // datagram not-last
+ List<Message> processFormat4(CanFrame f) {
+ // datagram middle-segment
NodeID source = map.getNodeID(getSourceID(f));
List<Integer> list = datagramData.get(source);
if (list == null) {
+ // this is actually an error, should be already started
list = new ArrayList<Integer>();
datagramData.put(source, list);
}
@@ -144,7 +169,7 @@
}
return null;
}
- public List<Message> processFormat5(CanFrame f) {
+ List<Message> processFormat5(CanFrame f) {
// datagram last
NodeID source = map.getNodeID(getSourceID(f));
List<Integer> list = datagramData.get(source);
@@ -155,7 +180,7 @@
list.add(f.getElement(i));
}
- datagramData.put(source, null);
+ datagramData.put(source, null); // not accumulating any more
int[] data = new int[list.size()];
for (int i=0; i<list.size(); i++) {
@@ -166,7 +191,7 @@
retlist.add(new DatagramMessage(source, dest, data));
return retlist;
}
- public List<Message> processFormat6(CanFrame f) {
+ List<Message> processFormat6(CanFrame f) {
List<Message> retlist = new java.util.ArrayList<Message>();
NodeID source = map.getNodeID(getSourceID(f));
int type = f.getElement(0);
@@ -190,7 +215,7 @@
default: return null;
}
}
- public List<Message> processFormat7(CanFrame f) {
+ List<Message> processFormat7(CanFrame f) {
// stream data
return null;
}
Modified: trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java 2012-04-30 06:23:01 UTC (rev 2162)
+++ trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java 2012-04-30 06:23:38 UTC (rev 2163)
@@ -182,30 +182,30 @@
void setPCEventReport(EventID eid) {
init(nodeAlias);
- setOpenLcbMTI(MTI_FORMAT_SIMPLE_MTI,MTI_PC_EVENT_REPORT);
+ setOpenLcbMTI(MTI_FORMAT_UNADDRESSED_MTI,MTI_PC_EVENT_REPORT);
length=8;
loadFromEid(eid);
}
boolean isPCEventReport() {
- return isOpenLcbMTI(MTI_FORMAT_SIMPLE_MTI, MTI_PC_EVENT_REPORT);
+ return isOpenLcbMTI(MTI_FORMAT_UNADDRESSED_MTI, MTI_PC_EVENT_REPORT);
}
void setLearnEvent(EventID eid) {
init(nodeAlias);
- setOpenLcbMTI(MTI_FORMAT_SIMPLE_MTI,MTI_LEARN_EVENT);
+ setOpenLcbMTI(MTI_FORMAT_UNADDRESSED_MTI,MTI_LEARN_EVENT);
length=8;
loadFromEid(eid);
}
boolean isLearnEvent() {
- return isOpenLcbMTI(MTI_FORMAT_SIMPLE_MTI, MTI_LEARN_EVENT);
+ return isOpenLcbMTI(MTI_FORMAT_UNADDRESSED_MTI, MTI_LEARN_EVENT);
}
void setInitializationComplete(int alias, NodeID nid) {
nodeAlias = alias;
init(nodeAlias);
- setOpenLcbMTI(MTI_FORMAT_COMPLEX_MTI,MTI_INITIALIZATION_COMPLETE);
+ setOpenLcbMTI(MTI_FORMAT_UNADDRESSED_MTI,MTI_INITIALIZATION_COMPLETE);
length=6;
byte[] val = nid.getContents();
data[0] = val[0];
@@ -217,7 +217,7 @@
}
boolean isInitializationComplete() {
- return isOpenLcbMTI(MTI_FORMAT_COMPLEX_MTI, MTI_INITIALIZATION_COMPLETE);
+ return isOpenLcbMTI(MTI_FORMAT_UNADDRESSED_MTI, MTI_INITIALIZATION_COMPLETE);
}
EventID getEventID() {
@@ -229,22 +229,22 @@
}
boolean isVerifyNID() {
- return isOpenLcbMTI(MTI_FORMAT_SIMPLE_MTI, MTI_VERIFY_NID);
+ return isOpenLcbMTI(MTI_FORMAT_UNADDRESSED_MTI, MTI_VERIFY_NID);
}
void setVerifyNID(NodeID nid) {
init(nodeAlias);
- setOpenLcbMTI(MTI_FORMAT_COMPLEX_MTI,MTI_VERIFY_NID);
+ setOpenLcbMTI(MTI_FORMAT_UNADDRESSED_MTI,MTI_VERIFY_NID);
length=0;
}
boolean isVerifiedNID() {
- return isOpenLcbMTI(MTI_FORMAT_SIMPLE_MTI, MTI_VERIFIED_NID);
+ return isOpenLcbMTI(MTI_FORMAT_UNADDRESSED_MTI, MTI_VERIFIED_NID);
}
void setVerifiedNID(NodeID nid) {
init(nodeAlias);
- setOpenLcbMTI(MTI_FORMAT_COMPLEX_MTI,MTI_VERIFIED_NID);
+ setOpenLcbMTI(MTI_FORMAT_UNADDRESSED_MTI,MTI_VERIFIED_NID);
length=6;
byte[] val = nid.getContents();
data[0] = val[0];
@@ -256,12 +256,12 @@
}
boolean isIdentifyConsumers() {
- return isOpenLcbMTI(MTI_FORMAT_SIMPLE_MTI, MTI_IDENTIFY_CONSUMERS);
+ return isOpenLcbMTI(MTI_FORMAT_UNADDRESSED_MTI, MTI_IDENTIFY_CONSUMERS);
}
void setConsumerIdentified(EventID eid) {
init(nodeAlias);
- setOpenLcbMTI(MTI_FORMAT_COMPLEX_MTI,MTI_CONSUMER_IDENTIFIED);
+ setOpenLcbMTI(MTI_FORMAT_UNADDRESSED_MTI,MTI_CONSUMER_IDENTIFIED);
length=8;
loadFromEid(eid);
}
@@ -269,18 +269,18 @@
void setConsumerIdentifyRange(EventID eid, EventID mask) {
// does send a message, but not complete yet - RGJ 2009-06-14
init(nodeAlias);
- setOpenLcbMTI(MTI_FORMAT_COMPLEX_MTI,MTI_IDENTIFY_CONSUMERS_RANGE);
+ setOpenLcbMTI(MTI_FORMAT_UNADDRESSED_MTI,MTI_IDENTIFY_CONSUMERS_RANGE);
length=8;
loadFromEid(eid);
}
boolean isIdentifyProducers() {
- return isOpenLcbMTI(MTI_FORMAT_SIMPLE_MTI, MTI_IDENTIFY_PRODUCERS);
+ return isOpenLcbMTI(MTI_FORMAT_UNADDRESSED_MTI, MTI_IDENTIFY_PRODUCERS);
}
void setProducerIdentified(EventID eid) {
init(nodeAlias);
- setOpenLcbMTI(MTI_FORMAT_COMPLEX_MTI,MTI_PRODUCER_IDENTIFIED);
+ setOpenLcbMTI(MTI_FORMAT_UNADDRESSED_MTI,MTI_PRODUCER_IDENTIFIED);
length=8;
loadFromEid(eid);
}
@@ -288,13 +288,13 @@
void setProducerIdentifyRange(EventID eid, EventID mask) {
// does send a message, but not complete yet - RGJ 2009-06-14
init(nodeAlias);
- setOpenLcbMTI(MTI_FORMAT_COMPLEX_MTI,MTI_IDENTIFY_PRODUCERS_RANGE);
+ setOpenLcbMTI(MTI_FORMAT_UNADDRESSED_MTI,MTI_IDENTIFY_PRODUCERS_RANGE);
length=8;
loadFromEid(eid);
}
boolean isIdentifyEvents() {
- return isOpenLcbMTI(MTI_FORMAT_SIMPLE_MTI, MTI_IDENTIFY_EVENTS);
+ return isOpenLcbMTI(MTI_FORMAT_UNADDRESSED_MTI, MTI_IDENTIFY_EVENTS);
}
void loadFromEid(EventID eid) {
@@ -368,8 +368,7 @@
/**
* OpenLCB CAN MTI format bits
*/
- static final int MTI_FORMAT_SIMPLE_MTI = 0;
- static final int MTI_FORMAT_COMPLEX_MTI = 1;
+ static final int MTI_FORMAT_UNADDRESSED_MTI = 0;
//
//
static final int MTI_FORMAT_ADDRESSED_DATAGRAM = 4;
@@ -382,23 +381,23 @@
* Basic header MTI definitions for OpenLCB on CAN.
*/
- static final int MTI_INITIALIZATION_COMPLETE = 0x08F;
+ static final int MTI_INITIALIZATION_COMPLETE = 0x087;
- static final int MTI_VERIFY_NID = 0x0A7;
- static final int MTI_VERIFIED_NID = 0x0B7;
+ static final int MTI_VERIFY_NID = 0x8A7;
+ static final int MTI_VERIFIED_NID = 0x8B7;
- static final int MTI_IDENTIFY_CONSUMERS = 0x24F;
+ static final int MTI_IDENTIFY_CONSUMERS = 0xA4F;
static final int MTI_IDENTIFY_CONSUMERS_RANGE = 0x25F;
static final int MTI_CONSUMER_IDENTIFIED = 0x26B;
- static final int MTI_IDENTIFY_PRODUCERS = 0x28F;
+ static final int MTI_IDENTIFY_PRODUCERS = 0xA8F;
static final int MTI_IDENTIFY_PRODUCERS_RANGE = 0x29F;
static final int MTI_PRODUCER_IDENTIFIED = 0x2AB;
- static final int MTI_IDENTIFY_EVENTS = 0x2B7;
+ static final int MTI_IDENTIFY_EVENTS = 0xAB7;
- static final int MTI_LEARN_EVENT = 0x2CF;
- static final int MTI_PC_EVENT_REPORT = 0x2DF;
+ static final int MTI_LEARN_EVENT = 0xACF;
+ static final int MTI_PC_EVENT_REPORT = 0xADF;
}
Modified: trunk/prototypes/java/test/org/openlcb/MessageTypeIdentifierTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/MessageTypeIdentifierTest.java 2012-04-30 06:23:01 UTC (rev 2162)
+++ trunk/prototypes/java/test/org/openlcb/MessageTypeIdentifierTest.java 2012-04-30 06:23:38 UTC (rev 2163)
@@ -5,6 +5,8 @@
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import java.util.*;
+
/**
* @author Bob Jacobsen Copyright 2012
* @version $Revision$
@@ -29,10 +31,61 @@
public void testToString() {
MessageTypeIdentifier mti1 = MessageTypeIdentifier.InitializationComplete;
- Assert.assertEquals(mti1.toString(), "InitializationComplete");
+ Assert.assertEquals("InitializationComplete", mti1.toString());
}
+ public void testMtiValues() {
+ MessageTypeIdentifier mti;
+
+ Assert.assertEquals(0x1080, MessageTypeIdentifier.InitializationComplete.mti());
+ Assert.assertEquals(0x10A4, MessageTypeIdentifier.VerifyNodeIdAddressed.mti());
+ Assert.assertEquals(0x18A0, MessageTypeIdentifier.VerifyNodeIdGlobal.mti());
+ Assert.assertEquals(0x18B0, MessageTypeIdentifier.VerifiedNodeId.mti());
+ Assert.assertEquals(0x10C4, MessageTypeIdentifier.OptionalInteractionRejected.mti());
+ Assert.assertEquals(0x10D4, MessageTypeIdentifier.TerminateDueToError.mti());
+
+ Assert.assertEquals(0x12E4, MessageTypeIdentifier.ProtocolSupportInquiry.mti());
+ Assert.assertEquals(0x12F4, MessageTypeIdentifier.ProtocolSupportReply.mti());
+
+ Assert.assertEquals(0x1A42, MessageTypeIdentifier.IdentifyConsumer.mti());
+ Assert.assertEquals(0x1252, MessageTypeIdentifier.ConsumerIdentifyRange.mti());
+ Assert.assertEquals(0x1263, MessageTypeIdentifier.ConsumerIdentified.mti());
+
+ Assert.assertEquals(0x1A82, MessageTypeIdentifier.IdentifyProducer.mti());
+ Assert.assertEquals(0x1292, MessageTypeIdentifier.ProducerIdentifyRange.mti());
+ Assert.assertEquals(0x12A3, MessageTypeIdentifier.ProducerIdentified.mti());
+
+ Assert.assertEquals(0x12B4, MessageTypeIdentifier.IdentifyEventsAddressed.mti());
+ Assert.assertEquals(0x1AB0, MessageTypeIdentifier.IdentifyEventsGlobal.mti());
+
+ Assert.assertEquals(0x1AC2, MessageTypeIdentifier.LearnEvent.mti());
+ Assert.assertEquals(0x1AD2, MessageTypeIdentifier.ProducerConsumerEventReport.mti());
+
+ Assert.assertEquals(0x1524, MessageTypeIdentifier.SimpleNodeIdentInfoRequest.mti());
+ Assert.assertEquals(0x1534, MessageTypeIdentifier.SimpleNodeIdentInfoReply.mti());
+
+ Assert.assertEquals(0x1404, MessageTypeIdentifier.Datagram.mti());
+ Assert.assertEquals(0x14C4, MessageTypeIdentifier.DatagramReceivedOK.mti());
+ Assert.assertEquals(0x14D4, MessageTypeIdentifier.DatagramRejected.mti());
+
+ Assert.assertEquals(0x14E4, MessageTypeIdentifier.StreamInitiateRequest.mti());
+ Assert.assertEquals(0x14F4, MessageTypeIdentifier.StreamInitiateReply.mti());
+ Assert.assertEquals(0x1694, MessageTypeIdentifier.StreamDataSend.mti());
+ Assert.assertEquals(0x16A4, MessageTypeIdentifier.StreamDataProceed.mti());
+ Assert.assertEquals(0x16B4, MessageTypeIdentifier.StreamDataComplete.mti());
+ }
+
+ public void testForOverlaps() {
+ ArrayList<Long> mtis = new ArrayList<Long>();
+ for (MessageTypeIdentifier item : MessageTypeIdentifier.values()) {
+ if (mtis.contains(item.mti())) {
+ Assert.fail("MTI "+item.mti()+" is a duplicate, 2nd is "+item.toString());
+ }
+ mtis.add(item.mti());
+ }
+ }
+
// from here down is testing infrastructure
public MessageTypeIdentifierTest(String s) {
Modified: trunk/prototypes/java/test/org/openlcb/can/MessageBuilderTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/can/MessageBuilderTest.java 2012-04-30 06:23:01 UTC (rev 2162)
+++ trunk/prototypes/java/test/org/openlcb/can/MessageBuilderTest.java 2012-04-30 06:23:38 UTC (rev 2163)
@@ -25,11 +25,11 @@
List<OpenLcbCanFrame> list = b.processMessage(m);
- // looking for [1908f123] 01 02 03 04 05 06
+ // looking for [18017123] 01 02 03 04 05 06
Assert.assertEquals("count", 1, list.size());
CanFrame f0 = list.get(0);
- Assert.assertEquals("header", toHexString(0x1908F123), toHexString(f0.getHeader()));
+ Assert.assertEquals("header", toHexString(0x18017123), toHexString(f0.getHeader()));
compareContent(source.getContents(), f0);
}
public void testVerifyNodeIDNumberMessage() {
@@ -39,11 +39,11 @@
List<OpenLcbCanFrame> list = b.processMessage(m);
- // looking for [190AF123]
+ // looking for [188AF123]
Assert.assertEquals("count", 1, list.size());
CanFrame f0 = list.get(0);
- Assert.assertEquals("header", toHexString(0x190a7123), toHexString(f0.getHeader()));
+ Assert.assertEquals("header", toHexString(0x188a7123), toHexString(f0.getHeader()));
compareContent(null, f0);
}
public void testVerifiedNodeIDNumberMessage() {
@@ -53,11 +53,11 @@
List<OpenLcbCanFrame> list = b.processMessage(m);
- // looking for [190BF123] 01 02 03 04 05 06
+ // looking for [188BF123] 01 02 03 04 05 06
Assert.assertEquals("count", 1, list.size());
CanFrame f0 = list.get(0);
- Assert.assertEquals("header", toHexString(0x190b7123), toHexString(f0.getHeader()));
+ Assert.assertEquals("header", toHexString(0x188b7123), toHexString(f0.getHeader()));
compareContent(source.getContents(), f0);
}
@@ -68,11 +68,11 @@
List<OpenLcbCanFrame> list = b.processMessage(m);
- // looking for [182df123] 11 12 13 14 15 16 17 18
+ // looking for [18adf123] 11 12 13 14 15 16 17 18
Assert.assertEquals("count", 1, list.size());
CanFrame f0 = list.get(0);
- Assert.assertEquals("header", toHexString(0x182Df123), toHexString(f0.getHeader()));
+ Assert.assertEquals("header", toHexString(0x18ADf123), toHexString(f0.getHeader()));
compareContent(event.getContents(), f0);
}
@@ -86,7 +86,7 @@
Assert.assertEquals("count", 1, list.size());
CanFrame f0 = list.get(0);
- Assert.assertEquals("header", toHexString(0x1D321123), toHexString(f0.getHeader()));
+ Assert.assertEquals("header", toHexString(0x1A321123), toHexString(f0.getHeader()));
compareContent(new byte[]{21,22,23}, f0);
}
@@ -100,7 +100,7 @@
Assert.assertEquals("count", 1, list.size());
CanFrame f0 = list.get(0);
- Assert.assertEquals("header", toHexString(0x1D321123), toHexString(f0.getHeader()));
+ Assert.assertEquals("header", toHexString(0x1A321123), toHexString(f0.getHeader()));
compareContent(new byte[]{21,22,23,24,25,26,27,28}, f0);
}
@@ -117,7 +117,7 @@
Assert.assertEquals("count", 2, list.size());
CanFrame f0 = list.get(0);
- Assert.assertEquals("f0 header", toHexString(0x1C321123), toHexString(f0.getHeader()));
+ Assert.assertEquals("f0 header", toHexString(0x1B321123), toHexString(f0.getHeader()));
compareContent(new byte[]{21,22,23,24,25,26,27,28}, f0);
CanFrame f1 = list.get(1);
@@ -138,7 +138,7 @@
Assert.assertEquals("count", 2, list.size());
CanFrame f0 = list.get(0);
- Assert.assertEquals("f0 header", toHexString(0x1C321123), toHexString(f0.getHeader()));
+ Assert.assertEquals("f0 header", toHexString(0x1B321123), toHexString(f0.getHeader()));
compareContent(new byte[]{21,22,23,24,25,26,27,28}, f0);
CanFrame f1 = list.get(1);
@@ -148,7 +148,7 @@
public void testInitializationCompleteFrame() {
OpenLcbCanFrame frame = new OpenLcbCanFrame(0x123);
- frame.setHeader(0x19087123);
+ frame.setHeader(0x18087123);
MessageBuilder b = new MessageBuilder(map);
@@ -162,7 +162,7 @@
public void testSingleFrameDatagram() {
OpenLcbCanFrame frame = new OpenLcbCanFrame(0x123);
- frame.setHeader(0x1D321123);
+ frame.setHeader(0x1A321123);
MessageBuilder b = new MessageBuilder(map);
@@ -176,7 +176,7 @@
public void testTwoFrameDatagram() {
OpenLcbCanFrame frame = new OpenLcbCanFrame(0x123);
- frame.setHeader(0x1C321123);
+ frame.setHeader(0x1B321123);
frame.setData(new byte[]{1,2});
MessageBuilder b = new MessageBuilder(map);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-05 18:45:44
|
Revision: 2173
http://openlcb.svn.sourceforge.net/openlcb/?rev=2173&view=rev
Author: jacobsen
Date: 2012-05-05 18:45:38 +0000 (Sat, 05 May 2012)
Log Message:
-----------
new MTI tests, refactoring of datagram creation
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java
trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java
trunk/prototypes/java/test/org/openlcb/can/MessageBuilderTest.java
Modified: trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java 2012-05-05 18:00:00 UTC (rev 2172)
+++ trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java 2012-05-05 18:45:38 UTC (rev 2173)
@@ -336,6 +336,7 @@
// must loop over data to send 8 byte chunks
int remains = msg.getData().length;
int j = 0;
+ boolean first = true;
// always sends at least one datagram, even with zero bytes
do {
int size = Math.min(8, remains);
@@ -345,11 +346,12 @@
}
OpenLcbCanFrame f = new OpenLcbCanFrame(0x00);
- f.setDatagram(data, map.getAlias(msg.getDestNodeID()), remains <= 8);
+ f.setDatagram(data, map.getAlias(msg.getDestNodeID()), first, remains <= 8);
f.setSourceAlias(map.getAlias(msg.getSourceNodeID()));
retlist.add(f);
remains = remains - size;
+ first = false;
} while (remains > 0);
}
Modified: trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java 2012-05-05 18:00:00 UTC (rev 2172)
+++ trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java 2012-05-05 18:45:38 UTC (rev 2173)
@@ -312,8 +312,10 @@
// general, but not efficient
boolean isDatagram() {
return isFrameTypeOpenLcb()
- && ( (getOpenLcbFormat() == MTI_FORMAT_ADDRESSED_DATAGRAM)
- || (getOpenLcbFormat() == MTI_FORMAT_ADDRESSED_DATAGRAM_LAST))
+ && ( (getOpenLcbFormat() == MTI_FORMAT_ADDRESSED_DATAGRAM_ALL)
+ || (getOpenLcbFormat() == MTI_FORMAT_ADDRESSED_DATAGRAM_FIRST)
+ || (getOpenLcbFormat() == MTI_FORMAT_ADDRESSED_DATAGRAM_MID)
+ || (getOpenLcbFormat() == MTI_FORMAT_ADDRESSED_DATAGRAM_LAST) )
&& (nodeAlias == getVariableField() );
}
// just checks 1st, assumes datagram already checked.
@@ -324,12 +326,18 @@
/**
* create a single datagram frame
*/
- void setDatagram(int[] content, int destAlias, boolean last) {
+ void setDatagram(int[] content, int destAlias, boolean first, boolean last) {
init(nodeAlias);
- if (!last) {
- setOpenLcbMTI(MTI_FORMAT_ADDRESSED_DATAGRAM,destAlias);
+ if (last) {
+ if (first)
+ setOpenLcbMTI(MTI_FORMAT_ADDRESSED_DATAGRAM_ALL,destAlias);
+ else
+ setOpenLcbMTI(MTI_FORMAT_ADDRESSED_DATAGRAM_LAST,destAlias);
} else {
- setOpenLcbMTI(MTI_FORMAT_ADDRESSED_DATAGRAM_LAST,destAlias);
+ if (first)
+ setOpenLcbMTI(MTI_FORMAT_ADDRESSED_DATAGRAM_FIRST,destAlias);
+ else
+ setOpenLcbMTI(MTI_FORMAT_ADDRESSED_DATAGRAM_MID,destAlias);
}
length=content.length;
for (int i = 0; i< content.length; i++) {
@@ -371,7 +379,9 @@
static final int MTI_FORMAT_UNADDRESSED_MTI = 0;
//
//
- static final int MTI_FORMAT_ADDRESSED_DATAGRAM = 4;
+ static final int MTI_FORMAT_ADDRESSED_DATAGRAM_ALL = 2;
+ static final int MTI_FORMAT_ADDRESSED_DATAGRAM_FIRST = 3;
+ static final int MTI_FORMAT_ADDRESSED_DATAGRAM_MID = 4;
static final int MTI_FORMAT_ADDRESSED_DATAGRAM_LAST = 5;
static final int MTI_FORMAT_ADDRESSED_NON_DATAGRAM = 6;
static final int MTI_FORMAT_STREAM_CODE = 7;
Modified: trunk/prototypes/java/test/org/openlcb/can/MessageBuilderTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/can/MessageBuilderTest.java 2012-05-05 18:00:00 UTC (rev 2172)
+++ trunk/prototypes/java/test/org/openlcb/can/MessageBuilderTest.java 2012-05-05 18:45:38 UTC (rev 2173)
@@ -29,7 +29,7 @@
Assert.assertEquals("count", 1, list.size());
CanFrame f0 = list.get(0);
- Assert.assertEquals("header", toHexString(0x18017123), toHexString(f0.getHeader()));
+ Assert.assertEquals("header", toHexString(0x18087123), toHexString(f0.getHeader()));
compareContent(source.getContents(), f0);
}
public void testVerifyNodeIDNumberMessage() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-05-06 03:08:22
|
Revision: 2175
http://openlcb.svn.sourceforge.net/openlcb/?rev=2175&view=rev
Author: jacobsen
Date: 2012-05-06 03:08:15 +0000 (Sun, 06 May 2012)
Log Message:
-----------
refactor to use AbstractConnection; better control of mti fragments
Modified Paths:
--------------
trunk/prototypes/java/openlcb-demo.jar
trunk/prototypes/java/openlcb.jar
trunk/prototypes/java/src/org/openlcb/AddressedMessage.java
trunk/prototypes/java/src/org/openlcb/Connection.java
trunk/prototypes/java/src/org/openlcb/DatagramAcknowledgedMessage.java
trunk/prototypes/java/src/org/openlcb/DatagramMessage.java
trunk/prototypes/java/src/org/openlcb/DatagramRejectedMessage.java
trunk/prototypes/java/src/org/openlcb/Gateway.java
trunk/prototypes/java/src/org/openlcb/IdentifyConsumersMessage.java
trunk/prototypes/java/src/org/openlcb/IdentifyEventsMessage.java
trunk/prototypes/java/src/org/openlcb/IdentifyProducersMessage.java
trunk/prototypes/java/src/org/openlcb/MessageDecoder.java
trunk/prototypes/java/src/org/openlcb/Node.java
trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java
trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java
trunk/prototypes/java/src/org/openlcb/implementations/ScatterGather.java
trunk/prototypes/java/src/org/openlcb/swing/MonPane.java
trunk/prototypes/java/src/org/openlcb/swing/ProducerPane.java
trunk/prototypes/java/test/org/openlcb/ConfigurationPortalTest.java
trunk/prototypes/java/test/org/openlcb/GatewayTest.java
trunk/prototypes/java/test/org/openlcb/IdentifyEventsMessageTest.java
trunk/prototypes/java/test/org/openlcb/SingleLinkNodeTest.java
trunk/prototypes/java/test/org/openlcb/can/OpenLcbCanFrameTest.java
trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java
trunk/prototypes/java/test/org/openlcb/implementations/DatagramReceiverTest.java
trunk/prototypes/java/test/org/openlcb/implementations/DatagramServiceTest.java
trunk/prototypes/java/test/org/openlcb/implementations/DatagramTransmitterTest.java
trunk/prototypes/java/test/org/openlcb/implementations/MemoryConfigurationServiceTest.java
trunk/prototypes/java/test/org/openlcb/implementations/ScatterGatherTest.java
trunk/prototypes/java/test/org/openlcb/implementations/SingleConsumerNodeTest.java
trunk/prototypes/java/test/org/openlcb/implementations/SingleProducerNodeTest.java
trunk/prototypes/java/test/org/openlcb/implementations/StreamReceiverTest.java
trunk/prototypes/java/test/org/openlcb/implementations/StreamTransmitterTest.java
Added Paths:
-----------
trunk/prototypes/java/src/org/openlcb/AbstractConnection.java
Modified: trunk/prototypes/java/openlcb-demo.jar
===================================================================
(Binary files differ)
Modified: trunk/prototypes/java/openlcb.jar
===================================================================
(Binary files differ)
Copied: trunk/prototypes/java/src/org/openlcb/AbstractConnection.java (from rev 2173, trunk/prototypes/java/src/org/openlcb/Connection.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/AbstractConnection.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/AbstractConnection.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -0,0 +1,28 @@
+package org.openlcb;
+
+/**
+ * Partial implementation of Connection with null startup behavior
+ *
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision$
+ */
+abstract public class AbstractConnection implements Connection {
+
+ /**
+ * Put a message to this connection.
+ * @param sender Node that is sending the message, used
+ * for tracking, logging, etc.
+ * (This models a two-ended connection to whatever
+ * communications link is used)
+ */
+ abstract public void put(Message msg, Connection sender);
+
+ /**
+ * Default registration behavior is an immediate call-back
+ * with news that the connection is up.
+ */
+ public void registerStartNotification(ConnectionListener c) {
+ c.connectionActive(this);
+ }
+
+}
Modified: trunk/prototypes/java/src/org/openlcb/AddressedMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/AddressedMessage.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/src/org/openlcb/AddressedMessage.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -41,7 +41,7 @@
if (! (o instanceof AddressedMessage))
return false;
AddressedMessage msg = (AddressedMessage) o;
- if (this.getDestNodeID() != msg.getDestNodeID())
+ if (!this.getDestNodeID().equals(msg.getDestNodeID()))
return false;
else return super.equals(o);
}
Modified: trunk/prototypes/java/src/org/openlcb/Connection.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/Connection.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/src/org/openlcb/Connection.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -18,5 +18,21 @@
* communications link is used)
*/
public void put(Message msg, Connection sender);
+
+ /**
+ * Register to be informed when this connection is ready
+ * to accept messages. Unless you know via some other
+ * mechanism that the connection is ready to go, you
+ * must register a listener and get the call-back before
+ * sending messages through the connection.
+ */
+ public void registerStartNotification(ConnectionListener c);
+ /**
+ * Internal listener class definition
+ */
+ public class ConnectionListener {
+ public void connectionActive(Connection c) {
+ }
+ }
}
Modified: trunk/prototypes/java/src/org/openlcb/DatagramAcknowledgedMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/DatagramAcknowledgedMessage.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/src/org/openlcb/DatagramAcknowledgedMessage.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -12,10 +12,10 @@
*/
@Immutable
@ThreadSafe
-public class DatagramAcknowledgedMessage extends Message {
+public class DatagramAcknowledgedMessage extends AddressedMessage {
public DatagramAcknowledgedMessage(NodeID source, NodeID dest) {
- super(source);
+ super(source, dest);
}
/**
Modified: trunk/prototypes/java/src/org/openlcb/DatagramMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/DatagramMessage.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/src/org/openlcb/DatagramMessage.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -20,6 +20,13 @@
System.arraycopy(dataIn, 0, this.data, 0, dataIn.length);
}
+ public DatagramMessage(NodeID source, NodeID dest, byte[] dataIn) {
+ super(source, dest);
+ this.data = new int[dataIn.length];
+ for (int i = 0; i<dataIn.length; i++)
+ this.data[i] = dataIn[i]&0xFF;
+ }
+
/**
* Intended for use by subclasses only
* to ensure immutable objects
Modified: trunk/prototypes/java/src/org/openlcb/DatagramRejectedMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/DatagramRejectedMessage.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/src/org/openlcb/DatagramRejectedMessage.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -12,10 +12,10 @@
*/
@Immutable
@ThreadSafe
-public class DatagramRejectedMessage extends Message {
+public class DatagramRejectedMessage extends AddressedMessage {
public DatagramRejectedMessage(NodeID source, NodeID dest, int code) {
- super(source);
+ super(source, dest);
this.code = code;
}
Modified: trunk/prototypes/java/src/org/openlcb/Gateway.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/Gateway.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/src/org/openlcb/Gateway.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -17,7 +17,7 @@
* the East node.
*/
public Connection getEastConnection() {
- eastInputConnection = new Connection() {
+ eastInputConnection = new AbstractConnection() {
public void put(Message msg, Connection sender) {
sendMessageToWest(msg, sender);
}
@@ -46,7 +46,7 @@
* the West node.
*/
public Connection getWestConnection() {
- westInputConnection = new Connection() {
+ westInputConnection = new AbstractConnection() {
public void put(Message msg, Connection sender) {
sendMessageToEast(msg, sender);
}
Modified: trunk/prototypes/java/src/org/openlcb/IdentifyConsumersMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/IdentifyConsumersMessage.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/src/org/openlcb/IdentifyConsumersMessage.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -20,6 +20,8 @@
}
EventID eventID = null;
+ public EventID getEventID() { return eventID; }
+
/**
* Implement message-type-specific
* processing when this message
Modified: trunk/prototypes/java/src/org/openlcb/IdentifyEventsMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/IdentifyEventsMessage.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/src/org/openlcb/IdentifyEventsMessage.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -12,10 +12,10 @@
*/
@Immutable
@ThreadSafe
-public class IdentifyEventsMessage extends Message {
+public class IdentifyEventsMessage extends AddressedMessage {
- public IdentifyEventsMessage(NodeID source) {
- super(source);
+ public IdentifyEventsMessage(NodeID source, NodeID dest) {
+ super(source, dest);
}
/**
Modified: trunk/prototypes/java/src/org/openlcb/IdentifyProducersMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/IdentifyProducersMessage.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/src/org/openlcb/IdentifyProducersMessage.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -20,6 +20,8 @@
}
EventID eventID;
+ public EventID getEventID() { return eventID; }
+
/**
* Implement message-type-specific
* processing when this message
Modified: trunk/prototypes/java/src/org/openlcb/MessageDecoder.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/MessageDecoder.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/src/org/openlcb/MessageDecoder.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -10,10 +10,10 @@
* Using this, a subclass need not use e.g. a switch statement
* or tentative casting to determine the type of message received.
*
- * @author Bob Jacobsen Copyright 2009
+ * @author Bob Jacobsen Copyright 2009, 2012
* @version $Revision$
*/
-public class MessageDecoder implements Connection {
+public class MessageDecoder extends AbstractConnection {
/**
* Process message.
Modified: trunk/prototypes/java/src/org/openlcb/Node.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/Node.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/src/org/openlcb/Node.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -9,7 +9,7 @@
* @author Bob Jacobsen Copyright 2009
* @version $Revision$
*/
-public class Node extends MessageDecoder implements Connection {
+public class Node extends MessageDecoder {
public Node(NodeID nodeID) {
this.nodeID = nodeID;
}
Modified: trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -297,7 +297,11 @@
* Handle "Identify Consumers" message
*/
public void handleIdentifyConsumers(IdentifyConsumersMessage msg, Connection sender){
- defaultHandler(msg, sender);
+ OpenLcbCanFrame f = new OpenLcbCanFrame(0x00);
+ f.setGlobalMessage(0xA4F);
+ f.setSourceAlias(map.getAlias(msg.getSourceNodeID()));
+ f.loadFromEid(msg.getEventID());
+ retlist.add(f);
}
/**
* Handle "Consumer Identified" message
@@ -309,7 +313,11 @@
* Handle "Identify Producers" message
*/
public void handleIdentifyProducers(IdentifyProducersMessage msg, Connection sender){
- defaultHandler(msg, sender);
+ OpenLcbCanFrame f = new OpenLcbCanFrame(0x00);
+ f.setGlobalMessage(0xA8F);
+ f.setSourceAlias(map.getAlias(msg.getSourceNodeID()));
+ f.loadFromEid(msg.getEventID());
+ retlist.add(f);
}
/**
* Handle "Producer Identified" message
@@ -321,7 +329,10 @@
* Handle "Identify Event" message
*/
public void handleIdentifyEvents(IdentifyEventsMessage msg, Connection sender){
- defaultHandler(msg, sender);
+ OpenLcbCanFrame f = new OpenLcbCanFrame(0x00);
+ f.setAddressedMessage(map.getAlias(msg.getDestNodeID()), (byte)0x2B);
+ f.setSourceAlias(map.getAlias(msg.getSourceNodeID()));
+ retlist.add(f);
}
/**
* Handle "Learn Event" message
@@ -359,13 +370,19 @@
* Handle "Datagram Rejected" message
*/
public void handleDatagramRejected(DatagramRejectedMessage msg, Connection sender){
- defaultHandler(msg, sender);
+ OpenLcbCanFrame f = new OpenLcbCanFrame(0x00);
+ f.setAddressedMessage(map.getAlias(msg.getDestNodeID()), (byte)0x4D);
+ f.setSourceAlias(map.getAlias(msg.getSourceNodeID()));
+ retlist.add(f);
}
/**
* Handle "Datagram Acknowledged" message
*/
public void handleDatagramAcknowledged(DatagramAcknowledgedMessage msg, Connection sender){
- defaultHandler(msg, sender);
+ OpenLcbCanFrame f = new OpenLcbCanFrame(0x00);
+ f.setAddressedMessage(map.getAlias(msg.getDestNodeID()), (byte)0x4C);
+ f.setSourceAlias(map.getAlias(msg.getSourceNodeID()));
+ retlist.add(f);
}
/**
* Handle "Stream Init Request" message
Modified: trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -34,7 +34,12 @@
public int getHeader() { return id; }
public void setHeader(int id) { this.id = id; }
- public byte[] getData() { return data; }
+ public byte[] getData() {
+ // return a copy of appropriate length
+ byte[] copy = new byte[length];
+ System.arraycopy(data,0,copy,0,length);
+ return copy;
+ }
public void setData(byte[] b) { data = b; length = b.length;}
public long bodyAsLong() {
long retval = 0;
@@ -293,11 +298,30 @@
loadFromEid(eid);
}
- boolean isIdentifyEvents() {
+ boolean isIdentifyEventsGlobal() {
return isOpenLcbMTI(MTI_FORMAT_UNADDRESSED_MTI, MTI_IDENTIFY_EVENTS);
}
+ void setIdentifyEventsGlobal() {
+ init(nodeAlias);
+ setOpenLcbMTI(MTI_FORMAT_UNADDRESSED_MTI,MTI_IDENTIFY_EVENTS);
+ length=0;
+ }
+
+ void setGlobalMessage(int mti) {
+ init(nodeAlias);
+ setOpenLcbMTI(MTI_FORMAT_UNADDRESSED_MTI,mti);
+ length=0;
+ }
+ void setAddressedMessage(int destAlias, byte mti) {
+ init(nodeAlias);
+ setOpenLcbMTI(MTI_FORMAT_ADDRESSED_NON_DATAGRAM,destAlias);
+ length=1;
+ data[0] = mti;
+ }
+
void loadFromEid(EventID eid) {
+ length = 8;
byte[] val = eid.getContents();
data[0] = val[0];
data[1] = val[1];
@@ -388,7 +412,7 @@
/**
- * Basic header MTI definitions for OpenLCB on CAN.
+ * Basic 12-bit header MTI definitions for OpenLCB on CAN.
*/
static final int MTI_INITIALIZATION_COMPLETE = 0x087;
@@ -403,11 +427,15 @@
static final int MTI_IDENTIFY_PRODUCERS = 0xA8F;
static final int MTI_IDENTIFY_PRODUCERS_RANGE = 0x29F;
static final int MTI_PRODUCER_IDENTIFIED = 0x2AB;
-
- static final int MTI_IDENTIFY_EVENTS = 0xAB7;
-
+
+ static final int MTI_IDENTIFY_EVENTS = 0xAB7; // global form
+
static final int MTI_LEARN_EVENT = 0xACF;
static final int MTI_PC_EVENT_REPORT = 0xADF;
+ /**
+ * Basic 8-bit header MTI definitions for OpenLCB on CAN, go in data[0]
+ */
+
}
Modified: trunk/prototypes/java/src/org/openlcb/implementations/ScatterGather.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/ScatterGather.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/src/org/openlcb/implementations/ScatterGather.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -31,7 +31,7 @@
return c;
}
- class SingleConnection implements Connection {
+ class SingleConnection extends AbstractConnection {
public void put(Message msg, Connection sender) {
// forward to all but the sender
boolean match = false;
Modified: trunk/prototypes/java/src/org/openlcb/swing/MonPane.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/swing/MonPane.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/src/org/openlcb/swing/MonPane.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -320,7 +320,7 @@
* <p>
* This implementation doesn't distinguish the source of a message, but it could.
*/
- class InputLink implements Connection {
+ class InputLink extends AbstractConnection {
public InputLink() {
}
Modified: trunk/prototypes/java/src/org/openlcb/swing/ProducerPane.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/swing/ProducerPane.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/src/org/openlcb/swing/ProducerPane.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -65,7 +65,7 @@
* <p>
* This implementation doesn't distinguish the source of a message, but it could.
*/
- class InputLink implements Connection {
+ class InputLink extends AbstractConnection {
public InputLink() {
}
Modified: trunk/prototypes/java/test/org/openlcb/ConfigurationPortalTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/ConfigurationPortalTest.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/test/org/openlcb/ConfigurationPortalTest.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -14,7 +14,7 @@
NodeID nodeID1 = new NodeID(new byte[]{1,2,3,4,5,6});
- Connection connection = new Connection(){
+ Connection connection = new AbstractConnection(){
public void put(Message m, Connection node) {
msg = m;
}
Modified: trunk/prototypes/java/test/org/openlcb/GatewayTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/GatewayTest.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/test/org/openlcb/GatewayTest.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -32,7 +32,7 @@
protected Connection cE;
protected Connection cW;
- abstract class TestListener implements Connection {
+ abstract class TestListener extends AbstractConnection {
public void put(Message m, Connection n) {
setResult();
}
Modified: trunk/prototypes/java/test/org/openlcb/IdentifyEventsMessageTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/IdentifyEventsMessageTest.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/test/org/openlcb/IdentifyEventsMessageTest.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -14,21 +14,43 @@
public void testEqualsSame() {
Message m1 = new IdentifyEventsMessage(
- new NodeID(new byte[]{1,2,3,4,5,6}) );
+ new NodeID(new byte[]{1,2,3,4,5,6}),
+ new NodeID(new byte[]{7,8,9,10,11,12}) );
Message m2 = new IdentifyEventsMessage(
- new NodeID(new byte[]{1,2,3,4,5,6}) );
+ new NodeID(new byte[]{1,2,3,4,5,6}),
+ new NodeID(new byte[]{7,8,9,10,11,12}) );
Assert.assertTrue(m1.equals(m2));
}
- public void testNotEqualsDifferent() {
+ public void testEqualsSelf() {
Message m1 = new IdentifyEventsMessage(
- new NodeID(new byte[]{1,2,3,4,5,6}) );
+ new NodeID(new byte[]{1,2,3,4,5,6}),
+ new NodeID(new byte[]{7,8,9,10,11,12}) );
+
+ Assert.assertTrue(m1.equals(m1));
+ }
+
+ public void testNotEqualsDifferentSrc() {
+ Message m1 = new IdentifyEventsMessage(
+ new NodeID(new byte[]{1,2,3,4,5,6}),
+ new NodeID(new byte[]{7,8,9,10,11,12}) );
Message m2 = new IdentifyEventsMessage(
- new NodeID(new byte[]{1,3,3,4,5,6}) );
+ new NodeID(new byte[]{1,3,3,4,5,6}),
+ new NodeID(new byte[]{7,8,9,10,11,12}) );
Assert.assertTrue( ! m1.equals(m2));
}
+ public void testNotEqualsDifferentDest() {
+ Message m1 = new IdentifyEventsMessage(
+ new NodeID(new byte[]{1,2,3,4,5,6}),
+ new NodeID(new byte[]{7,8,9,10,11,12}) );
+ Message m2 = new IdentifyEventsMessage(
+ new NodeID(new byte[]{1,2,3,4,5,6}),
+ new NodeID(new byte[]{7,10,9,10,11,12}) );
+
+ Assert.assertTrue( ! m1.equals(m2));
+ }
public void testHandling() {
result = false;
@@ -39,7 +61,8 @@
}
};
Message m = new IdentifyEventsMessage(
- new NodeID(new byte[]{1,2,3,4,5,6}) );
+ new NodeID(new byte[]{1,2,3,4,5,6}),
+ new NodeID(new byte[]{7,8,9,10,11,12}) );
n.put(m, null);
Modified: trunk/prototypes/java/test/org/openlcb/SingleLinkNodeTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/SingleLinkNodeTest.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/test/org/openlcb/SingleLinkNodeTest.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -17,7 +17,7 @@
public void testInitialization() {
result = false;
- Connection testConnection = new Connection(){
+ Connection testConnection = new AbstractConnection(){
public void put(Message msg, Connection node) {
if (msg.equals(new InitializationCompleteMessage(nodeID)))
result = true;
Modified: trunk/prototypes/java/test/org/openlcb/can/OpenLcbCanFrameTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/can/OpenLcbCanFrameTest.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/test/org/openlcb/can/OpenLcbCanFrameTest.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -25,6 +25,17 @@
Assert.assertTrue("12a not equals 13", !cf12a.equals(cf13));
}
+ public void testArrayGet() {
+ OpenLcbCanFrame cf12a = new OpenLcbCanFrame(12);
+ cf12a.setData(new byte[]{10,20,30});
+
+ byte[] b = cf12a.getData();
+ Assert.assertEquals(3, b.length);
+ Assert.assertEquals(10, b[0]);
+ Assert.assertEquals(20, b[1]);
+ Assert.assertEquals(30, b[2]);
+ }
+
public void testSimpleEqualObject() {
Object cf12a = new OpenLcbCanFrame(12);
Object cf12b = new OpenLcbCanFrame(12);
Modified: trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/test/org/openlcb/implementations/DatagramMeteringBufferTest.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -37,14 +37,14 @@
public void setUp() {
repliesReturned1 = new java.util.ArrayList<Message>();
- replyConnection1 = new Connection(){
+ replyConnection1 = new AbstractConnection(){
public void put(Message msg, Connection sender) {
repliesReturned1.add(msg);
}
};
messagesForwarded = new java.util.ArrayList<Message>();
- forwardConnection = new Connection(){
+ forwardConnection = new AbstractConnection(){
public void put(Message msg, Connection sender) {
messagesForwarded.add(msg);
testConnection = sender;
Modified: trunk/prototypes/java/test/org/openlcb/implementations/DatagramReceiverTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/DatagramReceiverTest.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/test/org/openlcb/implementations/DatagramReceiverTest.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -22,7 +22,7 @@
public void testTransfer() {
messagesReceived = new java.util.ArrayList<Message>();
- Connection testConnection = new Connection(){
+ Connection testConnection = new AbstractConnection(){
public void put(Message msg, Connection sender) {
messagesReceived.add(msg);
}
Modified: trunk/prototypes/java/test/org/openlcb/implementations/DatagramServiceTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/DatagramServiceTest.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/test/org/openlcb/implementations/DatagramServiceTest.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -22,7 +22,7 @@
public void setUp() {
messagesReceived = new java.util.ArrayList<Message>();
- testConnection = new Connection(){
+ testConnection = new AbstractConnection(){
public void put(Message msg, Connection sender) {
messagesReceived.add(msg);
}
Modified: trunk/prototypes/java/test/org/openlcb/implementations/DatagramTransmitterTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/DatagramTransmitterTest.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/test/org/openlcb/implementations/DatagramTransmitterTest.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -22,7 +22,7 @@
public void testSendOK() {
messagesReceived = new java.util.ArrayList<Message>();
- Connection testConnection = new Connection(){
+ Connection testConnection = new AbstractConnection(){
public void put(Message msg, Connection sender) {
messagesReceived.add(msg);
}
@@ -51,7 +51,7 @@
public void testOneResendNeeded() {
messagesReceived = new java.util.ArrayList<Message>();
- Connection testConnection = new Connection(){
+ Connection testConnection = new AbstractConnection(){
public void put(Message msg, Connection sender) {
messagesReceived.add(msg);
}
Modified: trunk/prototypes/java/test/org/openlcb/implementations/MemoryConfigurationServiceTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/MemoryConfigurationServiceTest.java 2012-05-05 22:08:29 UTC (rev 2174)
+++ trunk/prototypes/java/test/org/openlcb/implementations/MemoryConfigurationServiceTest.java 2012-05-06 03:08:15 UTC (rev 2175)
@@ -24,7 +24,7 @@
public void setUp() {
messagesReceived = new java.util.ArrayList<Message>();
flag = false;
- testConnection = new Connection(){
+ testConnection = new AbstractConnection(){
public void put(Message msg, Connection sender) {
messagesReceived.add(msg);
}
Modified: trunk/prototypes/java/test/org/openlcb/implementations/ScatterGatherTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/ScatterGatherTest.java 20...
[truncated message content] |