|
From: <jac...@us...> - 2012-09-04 20:39:10
|
Revision: 2707
http://openlcb.svn.sourceforge.net/openlcb/?rev=2707&view=rev
Author: jacobsen
Date: 2012-09-04 20:39:04 +0000 (Tue, 04 Sep 2012)
Log Message:
-----------
modifier handling for identifiedp/c
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/MessageTypeIdentifier.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
Modified: trunk/prototypes/java/src/org/openlcb/MessageTypeIdentifier.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/MessageTypeIdentifier.java 2012-09-04 20:38:16 UTC (rev 2706)
+++ trunk/prototypes/java/src/org/openlcb/MessageTypeIdentifier.java 2012-09-04 20:39:04 UTC (rev 2707)
@@ -40,11 +40,15 @@
IdentifyConsumer ( false, true, true, 0, 2, 7, 0, "IdentifyConsumer"),
ConsumerIdentifyRange ( false, true, false, 0, 1, 5, 0, "ConsumerIdentifyRange"),
- ConsumerIdentified ( false, true, false, 0, 1, 6, 0, "ConsumerIdentified"),
+ ConsumerIdentifiedUnknown ( false, true, false, 0, 1, 6, 3, "ConsumerIdentifiedUnknown"),
+ ConsumerIdentifiedValid ( false, true, false, 0, 1, 6, 0, "ConsumerIdentifiedValid"),
+ ConsumerIdentifiedInvalid ( false, true, false, 0, 1, 6, 1, "ConsumerIdentifiedInvalid"),
IdentifyProducer ( false, true, true, 0, 2, 8, 0, "IdentifyProducer"),
ProducerIdentifyRange ( false, true, false, 0, 1, 9, 0, "ProducerIdentifyRange"),
- ProducerIdentified ( false, true, false, 0, 1, 10, 0, "ProducerIdentified"),
+ ProducerIdentifiedUnknown ( false, true, false, 0, 1, 10, 3, "ProducerIdentifiedUnknown"),
+ ProducerIdentifiedValid ( false, true, false, 0, 1, 10, 0, "ProducerIdentifiedValid"),
+ ProducerIdentifiedInvalid ( false, true, false, 0, 1, 10, 1, "ProducerIdentifiedInvalid"),
IdentifyEventsAddressed ( true, false, false, 0, 2, 11, 0, "IdentifyEventsAddressed"),
IdentifyEventsGlobal ( false, false, true, 0, 2, 11, 0, "IdentifyEventsGlobal"),
@@ -106,10 +110,10 @@
retval = retval | (upper << 12);
retval = retval | (priorityGroup << 10);
retval = retval | (typeNumber << 5);
+ retval = retval | (modifier & 0x03);
if (addressed) retval = retval | 0x0008;
if (hasEventID) retval = retval | 0x0004;
- if (modifier != 0) retval = retval | modifier;
if (isSimpleModeMessage) retval = retval | 0x0010;
return retval;
Modified: trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java 2012-09-04 20:38:16 UTC (rev 2706)
+++ trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java 2012-09-04 20:39:04 UTC (rev 2707)
@@ -186,13 +186,17 @@
case IdentifyConsumer:
retlist.add(new IdentifyConsumersMessage(source, getEventID(f)));
return retlist;
- case ConsumerIdentified:
+ case ConsumerIdentifiedUnknown:
+ case ConsumerIdentifiedValid:
+ case ConsumerIdentifiedInvalid:
retlist.add(new ConsumerIdentifiedMessage(source, getEventID(f)));
return retlist;
case IdentifyProducer:
retlist.add(new IdentifyProducersMessage(source, getEventID(f)));
return retlist;
- case ProducerIdentified:
+ case ProducerIdentifiedUnknown:
+ case ProducerIdentifiedValid:
+ case ProducerIdentifiedInvalid:
retlist.add(new ProducerIdentifiedMessage(source, getEventID(f)));
return retlist;
case ProducerConsumerEventReport:
Modified: trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java 2012-09-04 20:38:16 UTC (rev 2706)
+++ trunk/prototypes/java/src/org/openlcb/can/OpenLcbCanFrame.java 2012-09-04 20:39:04 UTC (rev 2707)
@@ -286,7 +286,7 @@
void setProducerIdentified(EventID eid) {
init(nodeAlias);
- setOpenLcbMTI(MessageTypeIdentifier.ProducerIdentified.mti());
+ setOpenLcbMTI(MessageTypeIdentifier.ProducerIdentifiedUnknown.mti());
length=8;
loadFromEid(eid);
}
Modified: trunk/prototypes/java/test/org/openlcb/MessageTypeIdentifierTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/MessageTypeIdentifierTest.java 2012-09-04 20:38:16 UTC (rev 2706)
+++ trunk/prototypes/java/test/org/openlcb/MessageTypeIdentifierTest.java 2012-09-04 20:39:04 UTC (rev 2707)
@@ -50,11 +50,15 @@
Assert.assertEquals(0x08F4, MessageTypeIdentifier.IdentifyConsumer.mti());
Assert.assertEquals(0x04A4, MessageTypeIdentifier.ConsumerIdentifyRange.mti());
- Assert.assertEquals(0x04C4, MessageTypeIdentifier.ConsumerIdentified.mti());
+ Assert.assertEquals(0x04C7, MessageTypeIdentifier.ConsumerIdentifiedUnknown.mti());
+ Assert.assertEquals(0x04C4, MessageTypeIdentifier.ConsumerIdentifiedValid.mti());
+ Assert.assertEquals(0x04C5, MessageTypeIdentifier.ConsumerIdentifiedInvalid.mti());
Assert.assertEquals(0x0914, MessageTypeIdentifier.IdentifyProducer.mti());
Assert.assertEquals(0x0524, MessageTypeIdentifier.ProducerIdentifyRange.mti());
- Assert.assertEquals(0x0544, MessageTypeIdentifier.ProducerIdentified.mti());
+ Assert.assertEquals(0x0547, MessageTypeIdentifier.ProducerIdentifiedUnknown.mti());
+ Assert.assertEquals(0x0544, MessageTypeIdentifier.ProducerIdentifiedValid.mti());
+ Assert.assertEquals(0x0545, MessageTypeIdentifier.ProducerIdentifiedInvalid.mti());
Assert.assertEquals(0x0968, MessageTypeIdentifier.IdentifyEventsAddressed.mti());
Assert.assertEquals(0x0970, MessageTypeIdentifier.IdentifyEventsGlobal.mti());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-09-04 20:51:25
|
Revision: 2708
http://openlcb.svn.sourceforge.net/openlcb/?rev=2708&view=rev
Author: jacobsen
Date: 2012-09-04 20:51:18 +0000 (Tue, 04 Sep 2012)
Log Message:
-----------
working!
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/swing/memconfig/MemConfigReadWritePane.java
trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigReadWritePaneTest.java
Modified: trunk/prototypes/java/src/org/openlcb/swing/memconfig/MemConfigReadWritePane.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/swing/memconfig/MemConfigReadWritePane.java 2012-09-04 20:39:04 UTC (rev 2707)
+++ trunk/prototypes/java/src/org/openlcb/swing/memconfig/MemConfigReadWritePane.java 2012-09-04 20:51:18 UTC (rev 2708)
@@ -5,6 +5,7 @@
import javax.swing.*;
import javax.swing.text.*;
import java.beans.PropertyChangeListener;
+import java.awt.FlowLayout;
import org.openlcb.*;
import org.openlcb.implementations.*;
@@ -17,9 +18,80 @@
*/
public class MemConfigReadWritePane extends JPanel {
+ NodeID node;
MimicNodeStore store;
- public MemConfigReadWritePane(MimicNodeStore store) {
- this.store = store;
+ MemoryConfigurationService service;
+
+ public MemConfigReadWritePane(NodeID node, MimicNodeStore store, MemoryConfigurationService service) {
+ this.node = node;
+ this.store = store;
+ this.service = service;
+
+ setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
}
+ void addLine(JComponent j, String name) {
+ JPanel p = new JPanel();
+ p.setLayout(new java.awt.FlowLayout());
+ p.add(new JLabel(name));
+ p.add(j);
+ add(p);
+ }
+
+ JTextField readDataField = new JTextField(80);
+ JTextField writeDataField = new JTextField(80);
+ JTextField configNumberField = new JTextField("40");
+ JTextField configAddressField = new JTextField("000000");
+ JComboBox addrSpace = new JComboBox(new String[]{"CDI", "All", "Config", "None"});
+
+ /**
+ * To be invoked after Swing component installation is complete,
+ * as it drives display changes.
+ */
+ public void initComponents() {
+ addLine(readDataField, "Read: ");
+ addLine(writeDataField, "Write: ");
+ addLine(configNumberField, "Count: ");
+ addLine(configAddressField, "Address: ");
+ addLine(addrSpace, "Space: ");
+
+ JPanel p = new JPanel();
+ p.setLayout(new FlowLayout());
+
+ JButton b = new JButton("Read");
+ b.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ readPerformed();
+ }
+ });
+ p.add(b);
+ b = new JButton("Write");
+ b.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ writePerformed();
+ }
+ });
+ p.add(b);
+ add(p);
+
+ }
+
+ public void readPerformed() {
+ int space = 0xFF - addrSpace.getSelectedIndex();
+ long addr = Integer.parseInt(configAddressField.getText(), 16);
+ int length = Integer.parseInt(configNumberField.getText());
+ service.request(new MemoryConfigurationService.McsReadMemo(node,space,addr,length){
+ public void handleReadData(NodeID dest, int space, long address, byte[] data) {
+ readDataField.setText(org.openlcb.Utilities.toHexSpaceString(data));
+ }
+ });
+ }
+
+ public void writePerformed() {
+ int space = 0xFF - addrSpace.getSelectedIndex();
+ long addr = Integer.parseInt(configAddressField.getText(), 16);
+ byte[] content = org.openlcb.Utilities.bytesFromHexString(writeDataField.getText());
+ service.request(new MemoryConfigurationService.McsWriteMemo(node,space,addr,content));
+ }
+
}
Modified: trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigReadWritePaneTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigReadWritePaneTest.java 2012-09-04 20:39:04 UTC (rev 2707)
+++ trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigReadWritePaneTest.java 2012-09-04 20:51:18 UTC (rev 2708)
@@ -32,17 +32,36 @@
};
MimicNodeStore store;
+ MemoryConfigurationService service;
+ DatagramService dgs;
+
MemConfigReadWritePane pane;
public void setUp() throws Exception {
store = new MimicNodeStore(connection, nidHere);
store.addNode(nidThere);
+ dgs = new DatagramService(null, null);
+ service = new MemoryConfigurationService(nidHere, dgs) {
+ public void request(MemoryConfigurationService.McsWriteMemo memo) {
+ }
+
+ public void request(MemoryConfigurationService.McsReadMemo memo) {
+ }
+
+ public void request(MemoryConfigurationService.McsConfigMemo memo) {
+ }
+
+ public void request(MemoryConfigurationService.McsAddrSpaceMemo memo) {
+ }
+ };
+
// Test is really popping a window before doing all else
frame = new JFrame();
frame.setTitle("MemConfigReadWritePane Test");
- pane = new MemConfigReadWritePane(store);
+ pane = new MemConfigReadWritePane(nidThere, store, service);
+ pane.initComponents();
frame.add(pane);
frame.pack();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-09-04 20:51:56
|
Revision: 2709
http://openlcb.svn.sourceforge.net/openlcb/?rev=2709&view=rev
Author: jacobsen
Date: 2012-09-04 20:51:50 +0000 (Tue, 04 Sep 2012)
Log Message:
-----------
minor non-functional cleanup
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/swing/memconfig/MemConfigDescriptionPane.java
trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigDescriptionPaneTest.java
Modified: trunk/prototypes/java/src/org/openlcb/swing/memconfig/MemConfigDescriptionPane.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/swing/memconfig/MemConfigDescriptionPane.java 2012-09-04 20:51:18 UTC (rev 2708)
+++ trunk/prototypes/java/src/org/openlcb/swing/memconfig/MemConfigDescriptionPane.java 2012-09-04 20:51:50 UTC (rev 2709)
@@ -71,15 +71,21 @@
}
void readSpace(NodeID dest, final int highSpace, final int lowSpace) {
- if (highSpace < lowSpace) return;
+ if (highSpace < lowSpace) {
+ // done, no further reads
+ // force a layout
+ revalidate();
+ if (getTopLevelAncestor() instanceof JFrame) ((JFrame)getTopLevelAncestor()).pack();
+ return;
+ }
MemoryConfigurationService.McsAddrSpaceMemo memo =
new MemoryConfigurationService.McsAddrSpaceMemo(node, highSpace) {
- public void handleConfigData(NodeID dest, int space, long hiAddress, long lowAddress, int flags, String desc) {
+ public void handleAddrSpaceData(NodeID dest, int space, long hiAddress, long lowAddress, int flags, String desc) {
// new line with values
JPanel p = new JPanel();
p.setLayout(new java.awt.FlowLayout());
MemConfigDescriptionPane.this.add(p);
- p.add(new JLabel("Space "+space+": "));
+ p.add(new JLabel("Space: 0x"+Utilities.toHexPair(space)));
p.add(new JLabel("High address: 0x"+Long.toHexString(hiAddress).toUpperCase()));
// and read next space
readSpace(dest, highSpace-1, lowSpace);
Modified: trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigDescriptionPaneTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigDescriptionPaneTest.java 2012-09-04 20:51:18 UTC (rev 2708)
+++ trunk/prototypes/java/test/org/openlcb/swing/memconfig/MemConfigDescriptionPaneTest.java 2012-09-04 20:51:50 UTC (rev 2709)
@@ -41,10 +41,9 @@
public void setUp() throws Exception {
store = new MimicNodeStore(connection, nidHere);
+ store.addNode(nidThere);
dgs = new DatagramService(null, null);
- store.addNode(nidThere);
-
spaceCount = 3;
service = new MemoryConfigurationService(nidHere, dgs) {
public void request(MemoryConfigurationService.McsWriteMemo memo) {
@@ -59,7 +58,7 @@
}
public void request(MemoryConfigurationService.McsAddrSpaceMemo memo) {
- if (spaceCount-- > 0) memo.handleConfigData(nidThere, spaceCount, spaceCount*256, 0, 0, "");
+ if (spaceCount-- > 0) memo.handleAddrSpaceData(nidThere, spaceCount, spaceCount*256, 0, 0, "");
}
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-09-13 04:29:28
|
Revision: 2721
http://openlcb.svn.sourceforge.net/openlcb/?rev=2721&view=rev
Author: jacobsen
Date: 2012-09-13 04:29:22 +0000 (Thu, 13 Sep 2012)
Log Message:
-----------
package infrastructure for throttle implementation
Modified Paths:
--------------
trunk/prototypes/java/test/org/openlcb/implementations/PackageTest.java
Added Paths:
-----------
trunk/prototypes/java/src/org/openlcb/implementations/throttle/
trunk/prototypes/java/test/org/openlcb/implementations/throttle/
trunk/prototypes/java/test/org/openlcb/implementations/throttle/PackageTest.java
Modified: trunk/prototypes/java/test/org/openlcb/implementations/PackageTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/PackageTest.java 2012-09-10 11:25:38 UTC (rev 2720)
+++ trunk/prototypes/java/test/org/openlcb/implementations/PackageTest.java 2012-09-13 04:29:22 UTC (rev 2721)
@@ -49,6 +49,8 @@
suite.addTest(MemoryConfigurationServiceTest.suite());
+ suite.addTest(org.openlcb.implementations.throttle.PackageTest.suite());
+
return suite;
}
}
Copied: trunk/prototypes/java/test/org/openlcb/implementations/throttle/PackageTest.java (from rev 2720, trunk/prototypes/java/test/org/openlcb/implementations/PackageTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/throttle/PackageTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/implementations/throttle/PackageTest.java 2012-09-13 04:29:22 UTC (rev 2721)
@@ -0,0 +1,34 @@
+package org.openlcb.implementations.throttle;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision$
+ */
+public class PackageTest extends TestCase {
+ public void testStart() {
+ }
+
+ // from here down is testing infrastructure
+
+ public PackageTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {PackageTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(PackageTest.class);
+
+ return suite;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-09-13 04:41:04
|
Revision: 2722
http://openlcb.svn.sourceforge.net/openlcb/?rev=2722&view=rev
Author: jacobsen
Date: 2012-09-13 04:40:57 +0000 (Thu, 13 Sep 2012)
Log Message:
-----------
initial class structure
Modified Paths:
--------------
trunk/prototypes/java/test/org/openlcb/implementations/throttle/PackageTest.java
Added Paths:
-----------
trunk/prototypes/java/src/org/openlcb/implementations/throttle/Float16.java
trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleSpeedDatagram.java
trunk/prototypes/java/test/org/openlcb/implementations/throttle/Float16Test.java
trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleSpeedDatagramTest.java
Copied: trunk/prototypes/java/src/org/openlcb/implementations/throttle/Float16.java (from rev 2720, trunk/prototypes/java/src/org/openlcb/implementations/DatagramService.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/throttle/Float16.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/implementations/throttle/Float16.java 2012-09-13 04:40:57 UTC (rev 2722)
@@ -0,0 +1,16 @@
+package org.openlcb.implementations.throttle;
+
+import net.jcip.annotations.Immutable;
+import net.jcip.annotations.ThreadSafe;
+import org.openlcb.*;
+
+/**
+ * Represents a 16-bit IEEE float.
+ *
+ *
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision$
+ */
+public class Float16 {
+
+}
Copied: trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleSpeedDatagram.java (from rev 2720, trunk/prototypes/java/src/org/openlcb/implementations/DatagramService.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleSpeedDatagram.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleSpeedDatagram.java 2012-09-13 04:40:57 UTC (rev 2722)
@@ -0,0 +1,23 @@
+package org.openlcb.implementations.throttle;
+
+import net.jcip.annotations.Immutable;
+import net.jcip.annotations.ThreadSafe;
+import org.openlcb.*;
+
+/**
+ * Speed control datagram from throttle to command station.
+ *
+ * Meant to shield the using code from all the details of that
+ * process via some primitives:
+ * <ul>
+ * <li>
+ * <li>
+ * </ul>
+ *
+ *
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision$
+ */
+public class ThrottleSpeedDatagram {
+
+}
Copied: trunk/prototypes/java/test/org/openlcb/implementations/throttle/Float16Test.java (from rev 2720, trunk/prototypes/java/test/org/openlcb/implementations/StreamReceiverTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/throttle/Float16Test.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/implementations/throttle/Float16Test.java 2012-09-13 04:40:57 UTC (rev 2722)
@@ -0,0 +1,36 @@
+package org.openlcb.implementations.throttle;
+
+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 Float16Test extends TestCase {
+
+ public void testStart() {
+ }
+
+ // from here down is testing infrastructure
+
+ public Float16Test(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {Float16Test.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(Float16Test.class);
+ return suite;
+ }
+}
Modified: trunk/prototypes/java/test/org/openlcb/implementations/throttle/PackageTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/throttle/PackageTest.java 2012-09-13 04:29:22 UTC (rev 2721)
+++ trunk/prototypes/java/test/org/openlcb/implementations/throttle/PackageTest.java 2012-09-13 04:40:57 UTC (rev 2722)
@@ -29,6 +29,9 @@
public static Test suite() {
TestSuite suite = new TestSuite(PackageTest.class);
+ suite.addTest(Float16Test.suite());
+ suite.addTest(ThrottleSpeedDatagramTest.suite());
+
return suite;
}
}
Copied: trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleSpeedDatagramTest.java (from rev 2720, trunk/prototypes/java/test/org/openlcb/implementations/StreamReceiverTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleSpeedDatagramTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleSpeedDatagramTest.java 2012-09-13 04:40:57 UTC (rev 2722)
@@ -0,0 +1,36 @@
+package org.openlcb.implementations.throttle;
+
+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 ThrottleSpeedDatagramTest extends TestCase {
+
+ public void testStart() {
+ }
+
+ // from here down is testing infrastructure
+
+ public ThrottleSpeedDatagramTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {ThrottleSpeedDatagramTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(ThrottleSpeedDatagramTest.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-09-13 06:07:07
|
Revision: 2723
http://openlcb.svn.sourceforge.net/openlcb/?rev=2723&view=rev
Author: jacobsen
Date: 2012-09-13 06:07:00 +0000 (Thu, 13 Sep 2012)
Log Message:
-----------
initial test cases
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/implementations/throttle/Float16.java
trunk/prototypes/java/test/org/openlcb/implementations/throttle/Float16Test.java
Modified: trunk/prototypes/java/src/org/openlcb/implementations/throttle/Float16.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/throttle/Float16.java 2012-09-13 04:40:57 UTC (rev 2722)
+++ trunk/prototypes/java/src/org/openlcb/implementations/throttle/Float16.java 2012-09-13 06:07:00 UTC (rev 2723)
@@ -11,6 +11,63 @@
* @author Bob Jacobsen Copyright 2012
* @version $Revision$
*/
+@Immutable
+@ThreadSafe
public class Float16 {
+ public Float16(float f) {
+ double d = f;
+ if (d == 0.0) {
+ byte1 = 0;
+ byte2 = 0;
+ return;
+ }
+
+ boolean sign = false;
+
+ if (d < 0) {
+ sign = true;
+ d = -1 * d;
+ }
+ int exp = 15;
+ if (d < 1.0) {
+ while (d < 1.0) {
+ d = 2*d;
+ exp--;
+ }
+ } else {
+ while (d >= 2.0) {
+ d = d/2;
+ exp++;
+ }
+ }
+
+ int ch = ((int)(d*1024.))&0x3FF;
+ if ((((int)(d*1024.))&0x400) != 0x400) System.out.println("normalization failed for "+f+" with d="+d+" exp="+exp);
+ int bits = ch | (exp<<10);
+ if (sign) bits = bits | 0x8000;
+
+ byte1 = (byte)((bits >> 8)&0xFF);
+ byte2 = (byte)(bits&0xFF);
+ }
+
+ public Float16(int i) {
+ byte1 = (byte)((i>>8)&0xFF);
+ byte2 = (byte)(i&0xFF);
+ }
+
+ byte byte1, byte2;
+
+ public int getInt() {
+ return ((byte1&0xFF)<<8)|(byte2&0xFF);
+ }
+
+ public float getFloat() {
+ if (byte1 == 0 && byte2 == 0) return 0.0f;
+ int ch = (byte2&0xFF) | ((byte1&0x3)<<8) | 0x400;
+ int exp = (( ((int)byte1)&0x7C)>>2)-15;
+ int sign = ( (byte1 & 0x80) !=0 ) ? -1 : +1;
+ return (float)(((double)ch)/1024.0*((double)(1<<exp)))*sign;
+ }
+
}
Modified: trunk/prototypes/java/test/org/openlcb/implementations/throttle/Float16Test.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/throttle/Float16Test.java 2012-09-13 04:40:57 UTC (rev 2722)
+++ trunk/prototypes/java/test/org/openlcb/implementations/throttle/Float16Test.java 2012-09-13 06:07:00 UTC (rev 2723)
@@ -8,14 +8,73 @@
import junit.framework.TestSuite;
/**
+ * See http://en.wikipedia.org/wiki/Half-precision_floating-point_format
+ * http://www.mathworks.com/matlabcentral/fileexchange/23173
+ *
+ * 0 01111 0000000000 = 1
+ * 1 10000 0000000000 = −2
+ * 0 11110 1111111111 = 65504
+ * 0 00000 0000000000 = 0
+ * 1 00000 0000000000 = −0
+ * 0 01101 0101010101 ≈ 0.33325... ≈ 1/3
+ *
+ *
* @author Bob Jacobsen Copyright 2012
* @version $Revision$
*/
public class Float16Test extends TestCase {
+ Float16 f;
- public void testStart() {
+ public void testZeroAsBits() {
+ f = new Float16(0.0f);
+ Assert.assertEquals("zero", 0, f.getInt());
}
+ public void testOneAsBits() {
+ f = new Float16(1.0f);
+ Assert.assertEquals("one", 0x3C00, f.getInt());
+ }
+
+ public void testTwoAsBits() {
+ f = new Float16(2.0f);
+ Assert.assertEquals("two", 0x4000, f.getInt());
+ }
+
+ public void testNegTwoAsBits() {
+ f = new Float16(-2.0f);
+ Assert.assertEquals("-two", 0xC000, f.getInt());
+ }
+
+ public void testMaxAsBits() {
+ f = new Float16(65504.0f);
+ Assert.assertEquals("65504", 0x7BFF, f.getInt());
+ }
+
+ public void testZeroAsFloat() {
+ f = new Float16(0);
+ Assert.assertEquals("zero", 0.0f, f.getFloat());
+ }
+
+ public void testOneAsFloat() {
+ f = new Float16(0x3C00);
+ Assert.assertEquals("one", 1.0f, f.getFloat());
+ }
+
+ public void testTwoAsFloat() {
+ f = new Float16(0x4000);
+ Assert.assertEquals("two", 2.0f, f.getFloat());
+ }
+
+ public void testNegTwoAsFloat() {
+ f = new Float16(0xC000);
+ Assert.assertEquals("-two", -2.0f, f.getFloat());
+ }
+
+ public void testMaxAsFloat() {
+ f = new Float16(0x7BFF);
+ Assert.assertEquals("65504", 65504.0f, f.getFloat());
+ }
+
// from here down is testing infrastructure
public Float16Test(String s) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-09-14 08:06:45
|
Revision: 2726
http://openlcb.svn.sourceforge.net/openlcb/?rev=2726&view=rev
Author: jacobsen
Date: 2012-09-14 08:06:34 +0000 (Fri, 14 Sep 2012)
Log Message:
-----------
support for VerifyNodeID with content
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/VerifyNodeIDNumberMessage.java
trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java
trunk/prototypes/java/test/org/openlcb/VerifyNodeIDNumberMessageTest.java
trunk/prototypes/java/test/org/openlcb/can/MessageBuilderTest.java
Modified: trunk/prototypes/java/src/org/openlcb/VerifyNodeIDNumberMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/VerifyNodeIDNumberMessage.java 2012-09-14 00:32:31 UTC (rev 2725)
+++ trunk/prototypes/java/src/org/openlcb/VerifyNodeIDNumberMessage.java 2012-09-14 08:06:34 UTC (rev 2726)
@@ -5,7 +5,10 @@
import edu.umd.cs.findbugs.annotations.*;
/**
- * Verify Node ID Number message implementation
+ * Verify Node ID Number message implementation.
+ *
+ * Two forms: Global, with and without
+ * target NodeID in data
*
* @author Bob Jacobsen Copyright 2009, 2010
* @version $Revision$
@@ -16,8 +19,35 @@
public VerifyNodeIDNumberMessage(NodeID source) {
super(source);
+ this. content = null;
}
-
+
+ public VerifyNodeIDNumberMessage(NodeID source, NodeID content) {
+ this(source);
+ this.content = content;
+ }
+
+ NodeID content;
+
+ public NodeID getContent() { return content; }
+
+ /**
+ * To be equal, messages have to have the
+ * same type and content
+ */
+ public boolean equals(Object o) {
+ if (! (o instanceof VerifyNodeIDNumberMessage))
+ return false;
+ VerifyNodeIDNumberMessage msg = (VerifyNodeIDNumberMessage) o;
+ if (this.content != null) {
+ if (msg.content == null || (! this.content.equals(msg.content)))
+ return false;
+ } else {
+ if (msg.content != null) return false;
+ }
+ return super.equals(o);
+ }
+
/**
* Implement message-type-specific
* processing when this message
@@ -32,7 +62,8 @@
public String toString() {
return getSourceNodeID().toString()
- +" Verify Node ID number";
+ +" Verify Node ID number"
+ + ((content != null) ? (" for "+content) : (" for all nodes"));
}
public int getMTI() { return MTI_VERIFY_NID; }
Modified: trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java 2012-09-14 00:32:31 UTC (rev 2725)
+++ trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java 2012-09-14 08:06:34 UTC (rev 2726)
@@ -159,8 +159,14 @@
case InitializationComplete:
retlist.add(new InitializationCompleteMessage(source));
return retlist;
- case VerifyNodeIdGlobal:
- retlist.add(new VerifyNodeIDNumberMessage(source));
+ case VerifyNodeIdGlobal:
+ // check for content
+ if (data.length >= 6) {
+ NodeID node = new NodeID(data);
+ retlist.add(new VerifyNodeIDNumberMessage(source, node));
+ } else {
+ retlist.add(new VerifyNodeIDNumberMessage(source));
+ }
return retlist;
case VerifiedNodeId:
retlist.add(new VerifiedNodeIDNumberMessage(source));
@@ -376,6 +382,8 @@
OpenLcbCanFrame f = new OpenLcbCanFrame(0x00);
f.setVerifyNID(msg.getSourceNodeID());
f.setSourceAlias(map.getAlias(msg.getSourceNodeID()));
+ if (msg.getContent() != null)
+ f.setData(msg.getContent().getContents());
retlist.add(f);
}
Modified: trunk/prototypes/java/test/org/openlcb/VerifyNodeIDNumberMessageTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/VerifyNodeIDNumberMessageTest.java 2012-09-14 00:32:31 UTC (rev 2725)
+++ trunk/prototypes/java/test/org/openlcb/VerifyNodeIDNumberMessageTest.java 2012-09-14 08:06:34 UTC (rev 2726)
@@ -21,6 +21,15 @@
Assert.assertTrue(m1.equals(m2));
}
+ public void testEqualsSameWithContent() {
+ Message m1 = new VerifyNodeIDNumberMessage(
+ new NodeID(new byte[]{1,2,3,4,5,6}), new NodeID(new byte[]{1,2,3,4,5,6}));
+ Message m2 = new VerifyNodeIDNumberMessage(
+ new NodeID(new byte[]{1,2,3,4,5,6}), new NodeID(new byte[]{1,2,3,4,5,6}) );
+
+ Assert.assertTrue(m1.equals(m2));
+ }
+
public void testNotEqualsDifferent() {
Message m1 = new VerifyNodeIDNumberMessage(
new NodeID(new byte[]{1,2,3,4,5,6}) );
@@ -30,6 +39,15 @@
Assert.assertTrue( ! m1.equals(m2));
}
+ public void testEqualsContentMatters() {
+ Message m1 = new VerifyNodeIDNumberMessage(
+ new NodeID(new byte[]{1,2,3,4,5,6}), new NodeID(new byte[]{1,2,3,4,5,6}) );
+ Message m2 = new VerifyNodeIDNumberMessage(
+ new NodeID(new byte[]{1,2,3,4,5,6}), new NodeID(new byte[]{1,2,3,4,5,0}) );
+
+ Assert.assertTrue( ! m1.equals(m2));
+ }
+
public void testHandling() {
result = false;
Node n = new Node(){
Modified: trunk/prototypes/java/test/org/openlcb/can/MessageBuilderTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/can/MessageBuilderTest.java 2012-09-14 00:32:31 UTC (rev 2725)
+++ trunk/prototypes/java/test/org/openlcb/can/MessageBuilderTest.java 2012-09-14 08:06:34 UTC (rev 2726)
@@ -18,6 +18,10 @@
public void testCtor() {
}
+ /** ****************************************************
+ * Tests of messages into frames
+ ***************************************************** */
+
public void testInitializationCompleteMessage() {
Message m = new InitializationCompleteMessage(source);
@@ -32,7 +36,7 @@
Assert.assertEquals("header", toHexString(0x19100123), toHexString(f0.getHeader()));
compareContent(source.getContents(), f0);
}
- public void testVerifyNodeIDNumberMessage() {
+ public void testVerifyNodeIDNumberMessageEmpty() {
Message m = new VerifyNodeIDNumberMessage(source);
MessageBuilder b = new MessageBuilder(map);
@@ -46,6 +50,21 @@
Assert.assertEquals("header", toHexString(0x19490123), toHexString(f0.getHeader()));
compareContent(null, f0);
}
+ public void testVerifyNodeIDNumberMessageWithContent() {
+
+ Message m = new VerifyNodeIDNumberMessage(source, source);
+ MessageBuilder b = new MessageBuilder(map);
+
+ List<OpenLcbCanFrame> list = b.processMessage(m);
+
+ // looking for [19490123]
+
+ Assert.assertEquals("count", 1, list.size());
+ CanFrame f0 = list.get(0);
+ Assert.assertEquals("header", toHexString(0x19490123), toHexString(f0.getHeader()));
+ compareContent(source.getContents(), f0);
+ }
+
public void testVerifiedNodeIDNumberMessage() {
Message m = new VerifiedNodeIDNumberMessage(source);
@@ -146,6 +165,11 @@
compareContent(new byte[]{31}, f1);
}
+
+ /** ****************************************************
+ * Tests of messages into frames
+ ***************************************************** */
+
public void testInitializationCompleteFrame() {
OpenLcbCanFrame frame = new OpenLcbCanFrame(0x123);
frame.setHeader(0x19100123);
@@ -160,6 +184,36 @@
Assert.assertTrue(msg instanceof InitializationCompleteMessage);
}
+ public void testVerifyNodeEmptyFrame() {
+ OpenLcbCanFrame frame = new OpenLcbCanFrame(0x123);
+ frame.setHeader(0x19490123);
+
+ 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 VerifyNodeIDNumberMessage);
+ Assert.assertEquals(new VerifyNodeIDNumberMessage(source), msg);
+ }
+ public void testVerifyNodeContentFrame() {
+ OpenLcbCanFrame frame = new OpenLcbCanFrame(0x123);
+ frame.setHeader(0x19490123);
+ frame.setData(new byte[]{1,2,3,4,5,6});
+
+ 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 VerifyNodeIDNumberMessage);
+ Assert.assertEquals(new VerifyNodeIDNumberMessage(source, source), msg);
+ }
+
public void testSingleFrameDatagram() {
OpenLcbCanFrame frame = new OpenLcbCanFrame(0x123);
frame.setHeader(0x1A321123);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-09-14 08:07:40
|
Revision: 2727
http://openlcb.svn.sourceforge.net/openlcb/?rev=2727&view=rev
Author: jacobsen
Date: 2012-09-14 08:07:31 +0000 (Fri, 14 Sep 2012)
Log Message:
-----------
support for requesting a not-yet-seen node
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-09-14 08:06:34 UTC (rev 2726)
+++ trunk/prototypes/java/src/org/openlcb/MimicNodeStore.java 2012-09-14 08:07:31 UTC (rev 2727)
@@ -42,6 +42,20 @@
return memo;
}
+ /**
+ * If node not present, initiate process to find it.
+ * @return NodeMemo already known, but note you have to
+ * register listeners before calling in any case
+ */
+ public NodeMemo findNode(NodeID id) {
+ NodeMemo memo = map.get(id);
+ if (memo != null) return memo;
+
+ // create and send targeted request
+ connection.put(new VerifyNodeIDNumberMessage(id, id), null);
+ return null;
+ }
+
public SimpleNodeIdent getSimpleNodeIdent(NodeID dest) {
NodeMemo memo = map.get(dest);
if (memo == null) {
Modified: trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java 2012-09-14 08:06:34 UTC (rev 2726)
+++ trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java 2012-09-14 08:07:31 UTC (rev 2727)
@@ -184,6 +184,25 @@
Assert.assertEquals(lastMessage, new SimpleNodeIdentInfoRequestMessage(nid1, nid1) );
}
+ public void testFindNodeNotPresent() {
+ MimicNodeStore.NodeMemo retval = store.findNode(nid1);
+
+ Assert.assertTrue(retval == null);
+ Assert.assertTrue(lastMessage.equals(new VerifyNodeIDNumberMessage(nid1, nid1)));
+
+ }
+
+ public void testFindNodePresent() {
+ store.put(pim1,null);
+
+ MimicNodeStore.NodeMemo retval = store.findNode(nid1);
+
+ Assert.assertTrue(retval != null);
+ Assert.assertTrue(lastMessage == null);
+
+ }
+
+
// 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-09-14 10:28:18
|
Revision: 2728
http://openlcb.svn.sourceforge.net/openlcb/?rev=2728&view=rev
Author: jacobsen
Date: 2012-09-14 10:28:07 +0000 (Fri, 14 Sep 2012)
Log Message:
-----------
complete 1st implementation
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/implementations/throttle/Float16.java
trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleSpeedDatagram.java
trunk/prototypes/java/test/org/openlcb/implementations/throttle/PackageTest.java
trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleSpeedDatagramTest.java
Added Paths:
-----------
trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleImplementation.java
trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleImplementationTest.java
Modified: trunk/prototypes/java/src/org/openlcb/implementations/throttle/Float16.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/throttle/Float16.java 2012-09-14 08:07:31 UTC (rev 2727)
+++ trunk/prototypes/java/src/org/openlcb/implementations/throttle/Float16.java 2012-09-14 10:28:07 UTC (rev 2728)
@@ -16,7 +16,10 @@
public class Float16 {
public Float16(float f) {
- double d = f;
+ this((double)f);
+ }
+
+ public Float16(double d) {
if (d == 0.0) {
byte1 = 0;
byte2 = 0;
@@ -43,7 +46,7 @@
}
int ch = ((int)(d*1024.))&0x3FF;
- if ((((int)(d*1024.))&0x400) != 0x400) System.out.println("normalization failed for "+f+" with d="+d+" exp="+exp);
+ if ((((int)(d*1024.))&0x400) != 0x400) System.out.println("normalization failed with d="+d+" exp="+exp);
int bits = ch | (exp<<10);
if (sign) bits = bits | 0x8000;
Copied: trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleImplementation.java (from rev 2724, trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleSpeedDatagram.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleImplementation.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleImplementation.java 2012-09-14 10:28:07 UTC (rev 2728)
@@ -0,0 +1,53 @@
+package org.openlcb.implementations.throttle;
+
+import org.openlcb.*;
+import org.openlcb.implementations.DatagramService;
+
+/**
+ * Basic Throttle implementation, a class
+ * that uses the Motive Power protocol(s)
+ * to interface with e.g. a train.
+ *
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision$
+ */
+public class ThrottleImplementation {
+
+ public ThrottleImplementation(int dccAddress, boolean dccLongAddress,
+ MimicNodeStore store, DatagramService service) {
+ this.dccAddress = dccAddress;
+ this.dccLongAddress = dccLongAddress;
+ this.store = store;
+ this.service = service;
+
+ dest = createNodeIdFromDcc(dccAddress, dccLongAddress);
+ }
+
+ int dccAddress;
+ boolean dccLongAddress;
+ MimicNodeStore store;
+ DatagramService service;
+
+ NodeID dest;
+
+ NodeID createNodeIdFromDcc(int dccAddress, boolean dccLongAddress) {
+ if (dccLongAddress)
+ return new NodeID(new byte[]{6,0,0,0,(byte)((dccAddress>>8) & 0xFF), (byte)(dccAddress & 0xFF)});
+ else
+ return new NodeID(new byte[]{6,0,0,0,0, (byte)(dccAddress & 0xFF)});
+ }
+
+ public void start() {
+ store.findNode(dest);
+ }
+
+ /**
+ * @param speed Desired speed in scale meters/second. By convention, 100 m/sec is full speed
+ * for DCC locomotives.
+ */
+ public void setSpeed(double speed) {
+ ThrottleSpeedDatagram tsd = new ThrottleSpeedDatagram(speed);
+ service.sendData(dest, tsd.getData());
+ }
+
+}
Modified: trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleSpeedDatagram.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleSpeedDatagram.java 2012-09-14 08:07:31 UTC (rev 2727)
+++ trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleSpeedDatagram.java 2012-09-14 10:28:07 UTC (rev 2728)
@@ -2,7 +2,9 @@
import net.jcip.annotations.Immutable;
import net.jcip.annotations.ThreadSafe;
+
import org.openlcb.*;
+import org.openlcb.implementations.DatagramService;
/**
* Speed control datagram from throttle to command station.
@@ -14,10 +16,34 @@
* <li>
* </ul>
*
+ * Content:
+ * Datagram type byte 0x30
+ * Subtype: set speed 0x01
+ * Speed as float16 (2 bytes)
+ * 100.0 is full DCC speed (notionally meters per second)
*
* @author Bob Jacobsen Copyright 2012
* @version $Revision$
*/
+@Immutable
+@ThreadSafe
public class ThrottleSpeedDatagram {
+ /**
+ * @param speed Desired speed in scale meters/second. By convention, 100 m/sec is full speed
+ * for DCC locomotives.
+ */
+ public ThrottleSpeedDatagram(double speed) {
+ this.speed = speed;
+ }
+
+ NodeID dest;
+ double speed;
+
+ public int[] getData() {
+ Float16 fs = new Float16(speed);
+ int fsi = fs.getInt();
+ int[] data = new int[]{0x30,0x01,(fsi>>8)&0xFF, fsi&0xFF};
+ return data;
+ }
}
Modified: trunk/prototypes/java/test/org/openlcb/implementations/throttle/PackageTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/throttle/PackageTest.java 2012-09-14 08:07:31 UTC (rev 2727)
+++ trunk/prototypes/java/test/org/openlcb/implementations/throttle/PackageTest.java 2012-09-14 10:28:07 UTC (rev 2728)
@@ -31,6 +31,7 @@
suite.addTest(Float16Test.suite());
suite.addTest(ThrottleSpeedDatagramTest.suite());
+ suite.addTest(ThrottleImplementationTest.suite());
return suite;
}
Copied: trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleImplementationTest.java (from rev 2724, trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleSpeedDatagramTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleImplementationTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleImplementationTest.java 2012-09-14 10:28:07 UTC (rev 2728)
@@ -0,0 +1,88 @@
+package org.openlcb.implementations.throttle;
+
+import org.openlcb.*;
+import org.openlcb.implementations.DatagramService;
+
+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 ThrottleImplementationTest 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;
+ MimicNodeStore store;
+
+ @Override
+ public void setUp() {
+ messagesReceived = new java.util.ArrayList<Message>();
+ flag = false;
+ testConnection = new AbstractConnection(){
+ @Override
+ public void put(Message msg, Connection sender) {
+ messagesReceived.add(msg);
+ }
+ };
+ service = new DatagramService(hereID, testConnection);
+ store = new MimicNodeStore(testConnection, hereID);
+ }
+
+ public void testCtors() {
+ new ThrottleImplementation(1234, true, store, service);
+ new ThrottleImplementation(3, true, store, service);
+ new ThrottleImplementation(3, false, store, service);
+ }
+
+ public void testStartUnknownNode() {
+ ThrottleImplementation t = new ThrottleImplementation(1234, true, store, service);
+ t.start();
+
+ Assert.assertEquals(messagesReceived.size(), 1);
+ Assert.assertTrue(messagesReceived.get(0) instanceof VerifyNodeIDNumberMessage);
+
+ }
+
+ public void testSetSpeed() {
+ ThrottleImplementation t = new ThrottleImplementation(1234, true, store, service);
+ t.start();
+ messagesReceived = new java.util.ArrayList<Message>();
+
+ t.setSpeed(0.0);
+ Assert.assertEquals(messagesReceived.size(), 1);
+ Assert.assertTrue(messagesReceived.get(0) instanceof DatagramMessage);
+
+ int[] content = ((DatagramMessage)messagesReceived.get(0)).getData();
+ Assert.assertEquals(4, content.length);
+ Assert.assertEquals(0x30, content[0]);
+ Assert.assertEquals(0x01, content[1]);
+ Assert.assertEquals(0x00, content[2]);
+ Assert.assertEquals(0x00, content[3]);
+ }
+
+ // from here down is testing infrastructure
+
+ public ThrottleImplementationTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {ThrottleImplementationTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(ThrottleImplementationTest.class);
+ return suite;
+ }
+}
Modified: trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleSpeedDatagramTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleSpeedDatagramTest.java 2012-09-14 08:07:31 UTC (rev 2727)
+++ trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleSpeedDatagramTest.java 2012-09-14 10:28:07 UTC (rev 2728)
@@ -13,9 +13,45 @@
*/
public class ThrottleSpeedDatagramTest extends TestCase {
- public void testStart() {
+ public void testZeroSpeed() {
+ ThrottleSpeedDatagram t = new ThrottleSpeedDatagram(0.0);
+
+ int[] content = t.getData();
+
+ Assert.assertEquals(4, content.length);
+ Assert.assertEquals(0x30, content[0]);
+ Assert.assertEquals(0x01, content[1]);
+ Assert.assertEquals(0x00, content[2]);
+ Assert.assertEquals(0x00, content[3]);
+
}
+ public void test100Speed() {
+ ThrottleSpeedDatagram t = new ThrottleSpeedDatagram(100.0);
+
+ int[] content = t.getData();
+
+ Assert.assertEquals(4, content.length);
+ Assert.assertEquals(0x30, content[0]);
+ Assert.assertEquals(0x01, content[1]);
+ Assert.assertEquals(0x56, content[2]);
+ Assert.assertEquals(0x40, content[3]);
+
+ }
+
+ public void testNeg100Speed() {
+ ThrottleSpeedDatagram t = new ThrottleSpeedDatagram(-100.0);
+
+ int[] content = t.getData();
+
+ Assert.assertEquals(4, content.length);
+ Assert.assertEquals(0x30, content[0]);
+ Assert.assertEquals(0x01, content[1]);
+ Assert.assertEquals(0xD6, content[2]);
+ Assert.assertEquals(0x40, content[3]);
+
+ }
+
// from here down is testing infrastructure
public ThrottleSpeedDatagramTest(String s) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-09-14 10:28:30
|
Revision: 2729
http://openlcb.svn.sourceforge.net/openlcb/?rev=2729&view=rev
Author: jacobsen
Date: 2012-09-14 10:28:20 +0000 (Fri, 14 Sep 2012)
Log Message:
-----------
with throttle implementation
Modified Paths:
--------------
trunk/prototypes/java/openlcb-demo.jar
trunk/prototypes/java/openlcb.jar
Modified: trunk/prototypes/java/openlcb-demo.jar
===================================================================
(Binary files differ)
Modified: trunk/prototypes/java/openlcb.jar
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-09-14 16:41:08
|
Revision: 2731
http://openlcb.svn.sourceforge.net/openlcb/?rev=2731&view=rev
Author: jacobsen
Date: 2012-09-14 16:40:59 +0000 (Fri, 14 Sep 2012)
Log Message:
-----------
addressing for DCC
Modified Paths:
--------------
trunk/prototypes/java/openlcb-demo.jar
trunk/prototypes/java/openlcb.jar
trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleImplementation.java
trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleImplementationTest.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/implementations/throttle/ThrottleImplementation.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleImplementation.java 2012-09-14 10:28:51 UTC (rev 2730)
+++ trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleImplementation.java 2012-09-14 16:40:59 UTC (rev 2731)
@@ -32,9 +32,9 @@
NodeID createNodeIdFromDcc(int dccAddress, boolean dccLongAddress) {
if (dccLongAddress)
- return new NodeID(new byte[]{6,0,0,0,(byte)((dccAddress>>8) & 0xFF), (byte)(dccAddress & 0xFF)});
+ return new NodeID(new byte[]{6,1,0,0,(byte)((dccAddress>>8) & 0xFF), (byte)(dccAddress & 0xFF)});
else
- return new NodeID(new byte[]{6,0,0,0,0, (byte)(dccAddress & 0xFF)});
+ return new NodeID(new byte[]{6,1,0,0,0, (byte)(dccAddress & 0xFF)});
}
public void start() {
Modified: trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleImplementationTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleImplementationTest.java 2012-09-14 10:28:51 UTC (rev 2730)
+++ trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleImplementationTest.java 2012-09-14 16:40:59 UTC (rev 2731)
@@ -48,7 +48,10 @@
Assert.assertEquals(messagesReceived.size(), 1);
Assert.assertTrue(messagesReceived.get(0) instanceof VerifyNodeIDNumberMessage);
+ VerifyNodeIDNumberMessage v = (VerifyNodeIDNumberMessage)messagesReceived.get(0);
+ Assert.assertEquals(new NodeID(new byte[]{0x06, 0x01, 0,0, 1234/256, (byte)(1234&0xFF)}), v.getContent());
+
}
public void testSetSpeed() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-09-24 18:10:39
|
Revision: 2757
http://openlcb.svn.sourceforge.net/openlcb/?rev=2757&view=rev
Author: jacobsen
Date: 2012-09-24 18:10:33 +0000 (Mon, 24 Sep 2012)
Log Message:
-----------
useful string ctor for JMRI throttle
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/NodeID.java
trunk/prototypes/java/test/org/openlcb/NodeIDTest.java
Modified: trunk/prototypes/java/src/org/openlcb/NodeID.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/NodeID.java 2012-09-24 17:45:48 UTC (rev 2756)
+++ trunk/prototypes/java/src/org/openlcb/NodeID.java 2012-09-24 18:10:33 UTC (rev 2757)
@@ -38,6 +38,18 @@
this.contents[i] = contents[i];
}
+ @CheckReturnValue
+ public NodeID(@NonNull String value) {
+ if (value == null)
+ throw new java.lang.IllegalArgumentException("null argument invalid");
+ byte[] contents = org.openlcb.Utilities.bytesFromHexString(value);
+ if (contents.length < BYTECOUNT)
+ throw new java.lang.IllegalArgumentException("Wrong NodeID length: "+contents.length);
+ this.contents = new byte[BYTECOUNT];
+ for (int i = 0; i < BYTECOUNT; i++)
+ this.contents[i] = contents[i];
+ }
+
byte[] contents;
@CheckReturnValue
Modified: trunk/prototypes/java/test/org/openlcb/NodeIDTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/NodeIDTest.java 2012-09-24 17:45:48 UTC (rev 2756)
+++ trunk/prototypes/java/test/org/openlcb/NodeIDTest.java 2012-09-24 18:10:33 UTC (rev 2757)
@@ -29,16 +29,45 @@
Assert.fail("Should have thrown exception");
}
- public void testNOKArg() {
+ public void testOKArg() {
new NodeID(new byte[]{1,2,3,4,5,6});
}
+ public void testNullStringArg() {
+ try {
+ new NodeID((String)null);
+ } catch (IllegalArgumentException e) { return; }
+ Assert.fail("Should have thrown exception");
+ }
+
+ public void testTooLongStringArg() {
+ // shouldn't throw, just takes 1st part
+ new NodeID("1.2.3.4.5.6.7");
+ }
+
+ public void testTooShortStringArg() {
+ try {
+ new NodeID("1.2.3.4.5");
+ } catch (IllegalArgumentException e) { return; }
+ Assert.fail("Should have thrown exception");
+ }
+
+ public void testOKStringArg() {
+ new NodeID("1.2.3.4.5.6");
+ }
+
public void testEqualsSame() {
NodeID e1 = new NodeID(new byte[]{1,2,3,4,5,6});
NodeID e2 = new NodeID(new byte[]{1,2,3,4,5,6});
Assert.assertTrue(e1.equals(e2));
}
+ public void testEqualsSameString() {
+ NodeID e1 = new NodeID(new byte[]{1,2,3,4,5,6});
+ NodeID e2 = new NodeID("1.2.3.4.5.6");
+ Assert.assertTrue(e1.equals(e2));
+ }
+
public void testEqualsCastSame() {
Object e1 = new NodeID(new byte[]{1,2,3,4,5,6});
NodeID e2 = new NodeID(new byte[]{1,2,3,4,5,6});
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-09-27 03:58:36
|
Revision: 2758
http://openlcb.svn.sourceforge.net/openlcb/?rev=2758&view=rev
Author: jacobsen
Date: 2012-09-27 03:58:29 +0000 (Thu, 27 Sep 2012)
Log Message:
-----------
tweak function datagram
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleFunctionDatagram.java
trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleImplementationTest.java
Modified: trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleFunctionDatagram.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleFunctionDatagram.java 2012-09-24 18:10:33 UTC (rev 2757)
+++ trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleFunctionDatagram.java 2012-09-27 03:58:29 UTC (rev 2758)
@@ -29,7 +29,11 @@
int state;
public int[] getData() {
- int[] data = new int[]{0x30,0x11, number>>8, number&0xFF, state>>8, state&0xFF};
+ int[] data = new int[]{0x20, // mem config
+ 0x00, // mem write
+ 0x00,0x00,0x00, 0x00+number*2, // address
+ 0xF9, // space
+ (state>>8)&0xFF, state&0xFF}; // value
return data;
}
}
Modified: trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleImplementationTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleImplementationTest.java 2012-09-24 18:10:33 UTC (rev 2757)
+++ trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleImplementationTest.java 2012-09-27 03:58:29 UTC (rev 2758)
@@ -21,7 +21,7 @@
boolean flag;
DatagramService service;
MimicNodeStore store;
-
+
@Override
public void setUp() {
messagesReceived = new java.util.ArrayList<Message>();
@@ -71,6 +71,30 @@
Assert.assertEquals(0x00, content[3]);
}
+ public void testSetF0On() {
+ ThrottleImplementation t = new ThrottleImplementation(1234, true, store, service);
+ t.start();
+ messagesReceived = new java.util.ArrayList<Message>();
+
+ t.setFunction(0, 1); // F0 is on
+
+ Assert.assertEquals(messagesReceived.size(), 1);
+ Assert.assertTrue(messagesReceived.get(0) instanceof DatagramMessage);
+
+ int[] content = ((DatagramMessage)messagesReceived.get(0)).getData();
+ Assert.assertEquals(9, content.length);
+ Assert.assertEquals(0x20, content[0]);
+ Assert.assertEquals(0x00, content[1]); // command
+ Assert.assertEquals(0x00, content[2]);
+ Assert.assertEquals(0x00, content[3]);
+ Assert.assertEquals(0x00, content[4]);
+ Assert.assertEquals(2*0+0x00, content[5]); // address
+ Assert.assertEquals(0xF9, content[6]); // address space
+ Assert.assertEquals(0x00, content[7]); // data MSB
+ Assert.assertEquals(0x01, content[8]); // data LSB
+
+ }
+
// from here down is testing infrastructure
public ThrottleImplementationTest(String s) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-09-28 03:32:49
|
Revision: 2764
http://openlcb.svn.sourceforge.net/openlcb/?rev=2764&view=rev
Author: jacobsen
Date: 2012-09-28 03:32:43 +0000 (Fri, 28 Sep 2012)
Log Message:
-----------
use single byte values for DCC default functions
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleFunctionDatagram.java
trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleImplementation.java
trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleImplementationTest.java
Modified: trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleFunctionDatagram.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleFunctionDatagram.java 2012-09-27 18:03:33 UTC (rev 2763)
+++ trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleFunctionDatagram.java 2012-09-28 03:32:43 UTC (rev 2764)
@@ -9,10 +9,10 @@
/**
* Function control datagram from throttle to command station.
*
- * Content:
- * Datagram type byte 0x30
- * Subtype: set function 0x11
+ * Direct use of memory config protocol.
*
+ * DCC functions are defined as
+ *
* @author Bob Jacobsen Copyright 2012
* @version $Revision$
*/
@@ -31,9 +31,9 @@
public int[] getData() {
int[] data = new int[]{0x20, // mem config
0x00, // mem write
- 0x00,0x00,0x00, 0x00+number*2, // address
+ 0x00,0x00,0x00, number, // address
0xF9, // space
- (state>>8)&0xFF, state&0xFF}; // value
+ state&0xFF}; // value
return data;
}
}
Modified: trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleImplementation.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleImplementation.java 2012-09-27 18:03:33 UTC (rev 2763)
+++ trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleImplementation.java 2012-09-28 03:32:43 UTC (rev 2764)
@@ -13,24 +13,23 @@
*/
public class ThrottleImplementation {
- public ThrottleImplementation(int dccAddress, boolean dccLongAddress,
+ public ThrottleImplementation(NodeID node,
MimicNodeStore store, DatagramService service) {
- this.dccAddress = dccAddress;
- this.dccLongAddress = dccLongAddress;
+ this.dest = node;
this.store = store;
this.service = service;
-
- dest = createNodeIdFromDcc(dccAddress, dccLongAddress);
}
- int dccAddress;
- boolean dccLongAddress;
+ public ThrottleImplementation(int dccAddress, boolean dccLongAddress,
+ MimicNodeStore store, DatagramService service) {
+ this(createNodeIdFromDcc(dccAddress, dccLongAddress), store, service);
+ }
+
MimicNodeStore store;
DatagramService service;
-
NodeID dest;
- NodeID createNodeIdFromDcc(int dccAddress, boolean dccLongAddress) {
+ static NodeID createNodeIdFromDcc(int dccAddress, boolean dccLongAddress) {
if (dccLongAddress)
return new NodeID(new byte[]{6,1,0,0,(byte)((dccAddress>>8) & 0xFF), (byte)(dccAddress & 0xFF)});
else
Modified: trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleImplementationTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleImplementationTest.java 2012-09-27 18:03:33 UTC (rev 2763)
+++ trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleImplementationTest.java 2012-09-28 03:32:43 UTC (rev 2764)
@@ -71,30 +71,52 @@
Assert.assertEquals(0x00, content[3]);
}
- public void testSetF0On() {
+ public void testSetF1On() {
ThrottleImplementation t = new ThrottleImplementation(1234, true, store, service);
t.start();
messagesReceived = new java.util.ArrayList<Message>();
- t.setFunction(0, 1); // F0 is on
+ t.setFunction(1, 1); // F0 is on
Assert.assertEquals(messagesReceived.size(), 1);
Assert.assertTrue(messagesReceived.get(0) instanceof DatagramMessage);
int[] content = ((DatagramMessage)messagesReceived.get(0)).getData();
- Assert.assertEquals(9, content.length);
+ Assert.assertEquals(8, content.length);
Assert.assertEquals(0x20, content[0]);
Assert.assertEquals(0x00, content[1]); // command
Assert.assertEquals(0x00, content[2]);
Assert.assertEquals(0x00, content[3]);
Assert.assertEquals(0x00, content[4]);
- Assert.assertEquals(2*0+0x00, content[5]); // address
+ Assert.assertEquals(1, content[5]); // address
Assert.assertEquals(0xF9, content[6]); // address space
- Assert.assertEquals(0x00, content[7]); // data MSB
- Assert.assertEquals(0x01, content[8]); // data LSB
+ Assert.assertEquals(0x01, content[7]); // data
}
+ public void testSetF2Off() {
+ ThrottleImplementation t = new ThrottleImplementation(1234, true, store, service);
+ t.start();
+ messagesReceived = new java.util.ArrayList<Message>();
+
+ t.setFunction(2, 0); // F0 is on
+
+ Assert.assertEquals(messagesReceived.size(), 1);
+ Assert.assertTrue(messagesReceived.get(0) instanceof DatagramMessage);
+
+ int[] content = ((DatagramMessage)messagesReceived.get(0)).getData();
+ Assert.assertEquals(8, content.length);
+ Assert.assertEquals(0x20, content[0]);
+ Assert.assertEquals(0x00, content[1]); // command
+ Assert.assertEquals(0x00, content[2]);
+ Assert.assertEquals(0x00, content[3]);
+ Assert.assertEquals(0x00, content[4]);
+ Assert.assertEquals(2, content[5]); // address
+ Assert.assertEquals(0xF9, content[6]); // address space
+ Assert.assertEquals(0x00, content[7]); // data
+
+ }
+
// from here down is testing infrastructure
public ThrottleImplementationTest(String s) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-10-05 16:07:26
|
Revision: 2775
http://openlcb.svn.sourceforge.net/openlcb/?rev=2775&view=rev
Author: jacobsen
Date: 2012-10-05 16:07:17 +0000 (Fri, 05 Oct 2012)
Log Message:
-----------
fix repeated reply overrun?
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/SimpleNodeIdent.java
trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentTest.java
Modified: trunk/prototypes/java/src/org/openlcb/SimpleNodeIdent.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/SimpleNodeIdent.java 2012-10-02 03:28:12 UTC (rev 2774)
+++ trunk/prototypes/java/src/org/openlcb/SimpleNodeIdent.java 2012-10-05 16:07:17 UTC (rev 2775)
@@ -11,7 +11,8 @@
* Accumulates data from Simple Node Ident Protocol replies and
* provides access to the resulting data to represent a single node.
*
- * @see "http://www.openlcb.org/trunk/specs/drafts/GenProtocolIdS.pdf"
+ * @see "http://www.openlcb.org/trunk/specs/drafts/GenSimpleNodeInfoS.pdf"
+ * @see "http://www.openlcb.org/trunk/specs/drafts/GenSimpleNodeInfoTN.pdf"
* @author Bob Jacobsen Copyright (C) 2012
* @version $Revision: 18542 $
*
@@ -22,10 +23,7 @@
* @param msg Message, already known to be from proper node.
*/
public SimpleNodeIdent( SimpleNodeIdentInfoReplyMessage msg) {
- byte data[] = msg.getData();
- for (int i = 0; i < data.length ; i++ ) {
- bytes[next++] = (byte)data[i];
- }
+ addMsg(msg);
}
public SimpleNodeIdent(NodeID source, NodeID dest) {
this.source = source;
@@ -47,12 +45,31 @@
int next = 0;
public void addMsg(SimpleNodeIdentInfoReplyMessage msg) {
+ // if complete, restart with handling this message
+ if (contentComplete()) {
+ bytes = new byte[MAX_REPLY_LENGTH];
+ next = 0;
+ }
byte data[] = msg.getData();
+ System.out.println("add "+next+" "+data.length);
for (int i = 0; i < data.length ; i++ ) {
bytes[next++] = (byte)data[i];
}
}
-
+
+ /**
+ * Check whether enough messages have arrived to
+ * completely fill content.
+ */
+ public boolean contentComplete() {
+ // this is for the version 1 case only
+ int strings = 0;
+ for (int i=0; i<next; i++) {
+ if (bytes[i] == 0) strings++;
+ }
+ return strings == 6;
+ }
+
public String getMfgName() {
int len = 1;
int start = 1;
@@ -60,6 +77,7 @@
for (; len < bytes.length; len++)
if (bytes[len] == 0) break;
String s = new String(bytes,start, len-start, UTF8);
+ System.out.println("now "+next+" "+start+" "+len);
if (s == null) return "";
else return s;
}
Modified: trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentTest.java 2012-10-02 03:28:12 UTC (rev 2774)
+++ trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentTest.java 2012-10-05 16:07:17 UTC (rev 2775)
@@ -22,6 +22,7 @@
new byte[]{1,'a','b','c',0,'z','y','x'}));
Assert.assertEquals("abc", id.getMfgName());
+ Assert.assertFalse("not complete", id.contentComplete());
}
public void testCreationFromTwoMessages() {
@@ -36,6 +37,7 @@
Assert.assertEquals("abc", id.getMfgName());
Assert.assertEquals("zyx", id.getModelName());
+ Assert.assertFalse("not complete", id.contentComplete());
}
public void testSpannedCreationFromTwoMessages() {
@@ -51,6 +53,7 @@
Assert.assertEquals("abcdefg", id.getMfgName());
Assert.assertEquals("AB", id.getModelName());
Assert.assertEquals("Z", id.getHardwareVersion());
+ Assert.assertFalse("not complete", id.contentComplete());
}
public void testCreationWithUserPart() {
@@ -65,9 +68,31 @@
Assert.assertEquals("A", id.getSoftwareVersion());
Assert.assertEquals("us", id.getUserName());
Assert.assertEquals("34", id.getUserDesc());
+ Assert.assertTrue("complete", id.contentComplete());
}
+ public void testOverrunMessage() {
+ SimpleNodeIdent id = new SimpleNodeIdent(
+ new SimpleNodeIdentInfoReplyMessage(
+ new NodeID(new byte[]{1,2,3,4,5,6}),
+ new byte[]{1,'a','b',0,'1',0,'2',0,'A',0,1,'u','s',0,'3','4',0}));
+ Assert.assertEquals("ab", id.getMfgName());
+ Assert.assertEquals("1", id.getModelName());
+ Assert.assertEquals("2", id.getHardwareVersion());
+ Assert.assertEquals("A", id.getSoftwareVersion());
+ Assert.assertEquals("us", id.getUserName());
+ Assert.assertEquals("34", id.getUserDesc());
+ Assert.assertTrue("complete", id.contentComplete());
+
+ id.addMsg(
+ new SimpleNodeIdentInfoReplyMessage(
+ new NodeID(new byte[]{1,2,3,4,5,6}),
+ new byte[]{1,'s','t','a','r','t','s',0}));
+ Assert.assertEquals("starts", id.getMfgName());
+ }
+
+
// from here down is testing infrastructure
public SimpleNodeIdentTest(String s) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-10-11 04:19:15
|
Revision: 2785
http://openlcb.svn.sourceforge.net/openlcb/?rev=2785&view=rev
Author: jacobsen
Date: 2012-10-11 04:19:09 +0000 (Thu, 11 Oct 2012)
Log Message:
-----------
handle -0.0
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/implementations/throttle/Float16.java
trunk/prototypes/java/test/org/openlcb/implementations/throttle/Float16Test.java
Modified: trunk/prototypes/java/src/org/openlcb/implementations/throttle/Float16.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/throttle/Float16.java 2012-10-10 21:31:52 UTC (rev 2784)
+++ trunk/prototypes/java/src/org/openlcb/implementations/throttle/Float16.java 2012-10-11 04:19:09 UTC (rev 2785)
@@ -16,20 +16,26 @@
public class Float16 {
public Float16(float f) {
- this((double)f);
+ this((double)f, (f>=0.0f));
}
public Float16(double d) {
+ this(d, (d>=0.0f));
+ }
+
+ /**
+ * This allows the use of the -0.0 value if needed. That's not handled
+ * by the other constructors
+ */
+ Float16(double d, boolean positive) {
if (d == 0.0) {
byte1 = 0;
+ if (!positive) byte1 = (byte)0x80;
byte2 = 0;
return;
}
- boolean sign = false;
-
- if (d < 0) {
- sign = true;
+ if (d<0) {
d = -1 * d;
}
int exp = 15;
@@ -48,7 +54,7 @@
int ch = ((int)(d*1024.))&0x3FF;
if ((((int)(d*1024.))&0x400) != 0x400) System.out.println("normalization failed with d="+d+" exp="+exp);
int bits = ch | (exp<<10);
- if (sign) bits = bits | 0x8000;
+ if (!positive) bits = bits | 0x8000;
byte1 = (byte)((bits >> 8)&0xFF);
byte2 = (byte)(bits&0xFF);
Modified: trunk/prototypes/java/test/org/openlcb/implementations/throttle/Float16Test.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/throttle/Float16Test.java 2012-10-10 21:31:52 UTC (rev 2784)
+++ trunk/prototypes/java/test/org/openlcb/implementations/throttle/Float16Test.java 2012-10-11 04:19:09 UTC (rev 2785)
@@ -30,6 +30,11 @@
Assert.assertEquals("zero", 0, f.getInt());
}
+ public void testNegZeroAsBits() {
+ f = new Float16(0.0, false);
+ Assert.assertEquals("neg zero", 0x8000, f.getInt());
+ }
+
public void testOneAsBits() {
f = new Float16(1.0f);
Assert.assertEquals("one", 0x3C00, f.getInt());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-10-11 04:20:57
|
Revision: 2787
http://openlcb.svn.sourceforge.net/openlcb/?rev=2787&view=rev
Author: jacobsen
Date: 2012-10-11 04:20:51 +0000 (Thu, 11 Oct 2012)
Log Message:
-----------
handle e-stop, -0 for reverse stop
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleImplementation.java
trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleSpeedDatagram.java
trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleImplementationTest.java
trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleSpeedDatagramTest.java
Modified: trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleImplementation.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleImplementation.java 2012-10-11 04:19:23 UTC (rev 2786)
+++ trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleImplementation.java 2012-10-11 04:20:51 UTC (rev 2787)
@@ -31,7 +31,7 @@
static NodeID createNodeIdFromDcc(int dccAddress, boolean dccLongAddress) {
if (dccLongAddress)
- return new NodeID(new byte[]{6,1,0,0,(byte)((dccAddress>>8) & 0xFF), (byte)(dccAddress & 0xFF)});
+ return new NodeID(new byte[]{6,1,0,0,(byte)(((dccAddress>>8) & 0xFF) | 0xC0), (byte)(dccAddress & 0xFF)});
else
return new NodeID(new byte[]{6,1,0,0,0, (byte)(dccAddress & 0xFF)});
}
@@ -42,14 +42,22 @@
/**
* @param speed Desired speed in scale meters/second. By convention, 100 m/sec is full speed
- * for DCC locomotives. Negative is reverse motion.
+ * for DCC locomotives.
*/
- public void setSpeed(double speed) {
- ThrottleSpeedDatagram tsd = new ThrottleSpeedDatagram(speed);
+ public void setSpeed(double speed, boolean forward) {
+ ThrottleSpeedDatagram tsd = new ThrottleSpeedDatagram(speed, forward);
service.sendData(dest, tsd.getData());
}
/**
+ * Set emergency stop; unset by any following setSpeed command
+ */
+ public void doEmergencyStop() {
+ ThrottleSpeedDatagram tsd = new ThrottleSpeedDatagram();
+ service.sendData(dest, tsd.getData());
+ }
+
+ /**
* @param number 0 - ?? number of DCC function (0-28 space)
* @param value 0 for off, non-zero for on
*/
Modified: trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleSpeedDatagram.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleSpeedDatagram.java 2012-10-11 04:19:23 UTC (rev 2786)
+++ trunk/prototypes/java/src/org/openlcb/implementations/throttle/ThrottleSpeedDatagram.java 2012-10-11 04:20:51 UTC (rev 2787)
@@ -33,17 +33,32 @@
* @param speed Desired speed in scale meters/second. By convention, 100 m/sec is full speed
* for DCC locomotives.
*/
- public ThrottleSpeedDatagram(double speed) {
+ public ThrottleSpeedDatagram(double speed, boolean forward) {
this.speed = speed;
+ this.forward = forward;
}
+ /**
+ * Create datagram for emergency stop
+ */
+ public ThrottleSpeedDatagram() {
+ this.estop = true;
+ }
+
NodeID dest;
double speed;
+ boolean forward;
+ boolean estop = false;
public int[] getData() {
- Float16 fs = new Float16(speed);
- int fsi = fs.getInt();
- int[] data = new int[]{0x30,0x01,(fsi>>8)&0xFF, fsi&0xFF};
- return data;
+ if (estop) {
+ int[] data = new int[]{0x30,0x00};
+ return data;
+ } else {
+ Float16 fs = new Float16(speed, forward);
+ int fsi = fs.getInt();
+ int[] data = new int[]{0x30,0x01,(fsi>>8)&0xFF, fsi&0xFF};
+ return data;
+ }
}
}
Modified: trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleImplementationTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleImplementationTest.java 2012-10-11 04:19:23 UTC (rev 2786)
+++ trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleImplementationTest.java 2012-10-11 04:20:51 UTC (rev 2787)
@@ -50,16 +50,16 @@
Assert.assertTrue(messagesReceived.get(0) instanceof VerifyNodeIDNumberMessage);
VerifyNodeIDNumberMessage v = (VerifyNodeIDNumberMessage)messagesReceived.get(0);
- Assert.assertEquals(new NodeID(new byte[]{0x06, 0x01, 0,0, 1234/256, (byte)(1234&0xFF)}), v.getContent());
+ Assert.assertEquals(new NodeID(new byte[]{0x06, 0x01, 0,0, (byte)(1234/256 | 0xC0), (byte)(1234&0xFF)}), v.getContent());
}
- public void testSetSpeed() {
+ public void testSetSpeed100() {
ThrottleImplementation t = new ThrottleImplementation(1234, true, store, service);
t.start();
messagesReceived = new java.util.ArrayList<Message>();
- t.setSpeed(0.0);
+ t.setSpeed(100.0, true);
Assert.assertEquals(messagesReceived.size(), 1);
Assert.assertTrue(messagesReceived.get(0) instanceof DatagramMessage);
@@ -67,10 +67,44 @@
Assert.assertEquals(4, content.length);
Assert.assertEquals(0x30, content[0]);
Assert.assertEquals(0x01, content[1]);
+ Assert.assertEquals(0x56, content[2]);
+ Assert.assertEquals(0x40, content[3]);
+ }
+
+ public void testSetSpeedZero() {
+ ThrottleImplementation t = new ThrottleImplementation(1234, true, store, service);
+ t.start();
+ messagesReceived = new java.util.ArrayList<Message>();
+
+ t.setSpeed(0.0, true);
+ Assert.assertEquals(messagesReceived.size(), 1);
+ Assert.assertTrue(messagesReceived.get(0) instanceof DatagramMessage);
+
+ int[] content = ((DatagramMessage)messagesReceived.get(0)).getData();
+ Assert.assertEquals(4, content.length);
+ Assert.assertEquals(0x30, content[0]);
+ Assert.assertEquals(0x01, content[1]);
Assert.assertEquals(0x00, content[2]);
Assert.assertEquals(0x00, content[3]);
}
+ public void testSetSpeedReverseZero() {
+ ThrottleImplementation t = new ThrottleImplementation(1234, true, store, service);
+ t.start();
+ messagesReceived = new java.util.ArrayList<Message>();
+
+ t.setSpeed(0.0, false);
+ Assert.assertEquals(messagesReceived.size(), 1);
+ Assert.assertTrue(messagesReceived.get(0) instanceof DatagramMessage);
+
+ int[] content = ((DatagramMessage)messagesReceived.get(0)).getData();
+ Assert.assertEquals(4, content.length);
+ Assert.assertEquals(0x30, content[0]);
+ Assert.assertEquals(0x01, content[1]);
+ Assert.assertEquals(0x80, content[2]);
+ Assert.assertEquals(0x00, content[3]);
+ }
+
public void testSetF1On() {
ThrottleImplementation t = new ThrottleImplementation(1234, true, store, service);
t.start();
Modified: trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleSpeedDatagramTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleSpeedDatagramTest.java 2012-10-11 04:19:23 UTC (rev 2786)
+++ trunk/prototypes/java/test/org/openlcb/implementations/throttle/ThrottleSpeedDatagramTest.java 2012-10-11 04:20:51 UTC (rev 2787)
@@ -14,7 +14,7 @@
public class ThrottleSpeedDatagramTest extends TestCase {
public void testZeroSpeed() {
- ThrottleSpeedDatagram t = new ThrottleSpeedDatagram(0.0);
+ ThrottleSpeedDatagram t = new ThrottleSpeedDatagram(0.0, true);
int[] content = t.getData();
@@ -26,8 +26,21 @@
}
+ public void testNegZeroSpeed() {
+ ThrottleSpeedDatagram t = new ThrottleSpeedDatagram(0.0f, false);
+
+ int[] content = t.getData();
+
+ Assert.assertEquals(4, content.length);
+ Assert.assertEquals(0x30, content[0]);
+ Assert.assertEquals(0x01, content[1]);
+ Assert.assertEquals(0x80, content[2]);
+ Assert.assertEquals(0x00, content[3]);
+
+ }
+
public void test100Speed() {
- ThrottleSpeedDatagram t = new ThrottleSpeedDatagram(100.0);
+ ThrottleSpeedDatagram t = new ThrottleSpeedDatagram(100.0, true);
int[] content = t.getData();
@@ -40,7 +53,7 @@
}
public void testNeg100Speed() {
- ThrottleSpeedDatagram t = new ThrottleSpeedDatagram(-100.0);
+ ThrottleSpeedDatagram t = new ThrottleSpeedDatagram(100.0, false);
int[] content = t.getData();
@@ -51,6 +64,15 @@
Assert.assertEquals(0x40, content[3]);
}
+ public void testEStop() {
+ ThrottleSpeedDatagram t = new ThrottleSpeedDatagram();
+
+ int[] content = t.getData();
+
+ Assert.assertEquals(2, content.length);
+ Assert.assertEquals(0x30, content[0]);
+ Assert.assertEquals(0x00, content[1]);
+ }
// from here down is testing infrastructure
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-10-13 03:58:37
|
Revision: 2791
http://openlcb.svn.sourceforge.net/openlcb/?rev=2791&view=rev
Author: jacobsen
Date: 2012-10-13 03:58:31 +0000 (Sat, 13 Oct 2012)
Log Message:
-----------
handle source alias better
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-10-13 03:47:16 UTC (rev 2790)
+++ trunk/prototypes/java/src/org/openlcb/MimicNodeStore.java 2012-10-13 03:58:31 UTC (rev 2791)
@@ -52,7 +52,7 @@
if (memo != null) return memo;
// create and send targeted request
- connection.put(new VerifyNodeIDNumberMessage(id, id), null);
+ connection.put(new VerifyNodeIDNumberMessage(node, id), null);
return null;
}
@@ -124,7 +124,7 @@
if (msg.getMti() == MessageTypeIdentifier.SimpleNodeIdentInfoRequest.mti()) {
// check for temporary error
// have to resend the SNII request
- connection.put(new SimpleNodeIdentInfoRequestMessage(id, msg.getSourceNodeID()), null);
+ connection.put(new SimpleNodeIdentInfoRequestMessage(node, msg.getSourceNodeID()), null);
}
}
Modified: trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java 2012-10-13 03:47:16 UTC (rev 2790)
+++ trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java 2012-10-13 03:58:31 UTC (rev 2791)
@@ -36,10 +36,10 @@
}
};
- NodeID node = new NodeID(new byte[]{1,2,3,4,5,6});
+ NodeID src = new NodeID(new byte[]{1,2,3,4,5,6});
public void setUp() {
- store = new MimicNodeStore(connection, node);
+ store = new MimicNodeStore(connection, src);
lastMessage = null;
listener = new PropertyChangeListener(){
@@ -178,17 +178,17 @@
MimicNodeStore.NodeMemo memo = list.iterator().next();
Assert.assertNull(lastMessage);
- store.put(new OptionalIntRejectedMessage(nid1,nid1,0x0DE8,1), null);
+ store.put(new OptionalIntRejectedMessage(nid1,src,0x0DE8,1), null);
Assert.assertNotNull(lastMessage);
- Assert.assertEquals(lastMessage, new SimpleNodeIdentInfoRequestMessage(nid1, nid1) );
+ Assert.assertEquals(lastMessage, new SimpleNodeIdentInfoRequestMessage(src, nid1) );
}
public void testFindNodeNotPresent() {
MimicNodeStore.NodeMemo retval = store.findNode(nid1);
Assert.assertTrue(retval == null);
- Assert.assertTrue(lastMessage.equals(new VerifyNodeIDNumberMessage(nid1, nid1)));
+ Assert.assertTrue(lastMessage.equals(new VerifyNodeIDNumberMessage(src, nid1)));
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-10-13 16:03:51
|
Revision: 2792
http://openlcb.svn.sourceforge.net/openlcb/?rev=2792&view=rev
Author: jacobsen
Date: 2012-10-13 16:03:45 +0000 (Sat, 13 Oct 2012)
Log Message:
-----------
add TractionControl, FDI, DCC
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-10-13 03:58:31 UTC (rev 2791)
+++ trunk/prototypes/java/src/org/openlcb/ProtocolIdentification.java 2012-10-13 16:03:45 UTC (rev 2792)
@@ -28,7 +28,10 @@
AbbreviatedDefaultCDI( 0x004000000000L,"AbbreviatedDefaultCDI"),
Display( 0x002000000000L,"Display"),
SimpleNodeID( 0x001000000000L,"SNII"),
- ConfigurationDescription(0x000800000000L,"CDI");
+ ConfigurationDescription(0x000800000000L,"CDI"),
+ TractionControl( 0x000400000000L,"Train"),
+ FunctionDescription( 0x000200000000L,"FDI"),
+ DccCommandStation( 0x000100000000L,"DccCS");
Protocol(long value, String name) {
this.value = value;
Modified: trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationTest.java 2012-10-13 03:58:31 UTC (rev 2791)
+++ trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationTest.java 2012-10-13 16:03:45 UTC (rev 2792)
@@ -47,6 +47,16 @@
Assert.assertEquals("result 6", "CDI", result.get(5));
}
+ public void testDecode4() {
+ java.util.List result = ProtocolIdentification.Protocol.decodeNames(0x000F00000000L);
+
+ Assert.assertEquals("length", 4, result.size());
+ Assert.assertEquals("result 1", "CDI", result.get(0));
+ Assert.assertEquals("result 2", "Train", result.get(1));
+ Assert.assertEquals("result 3", "FDI", result.get(2));
+ Assert.assertEquals("result 4", "DccCS", result.get(3));
+ }
+
public void testSupports1() {
ProtocolIdentification.Protocol p = ProtocolIdentification.Protocol.Datagram;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-10-13 17:53:07
|
Revision: 2793
http://openlcb.svn.sourceforge.net/openlcb/?rev=2793&view=rev
Author: jacobsen
Date: 2012-10-13 17:53:00 +0000 (Sat, 13 Oct 2012)
Log Message:
-----------
handle missing error code value
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-10-13 16:03:45 UTC (rev 2792)
+++ trunk/prototypes/java/src/org/openlcb/MimicNodeStore.java 2012-10-13 17:53:00 UTC (rev 2793)
@@ -123,6 +123,11 @@
public void handleOptionalIntRejected(OptionalIntRejectedMessage msg, Connection sender){
if (msg.getMti() == MessageTypeIdentifier.SimpleNodeIdentInfoRequest.mti()) {
// check for temporary error
+ if ( (msg.getCode() & 0x1000 ) == 0) {
+ // not a temporary error, assume a permanent error
+ System.out.println("Permanent error geting Simple Node Info for node "+msg.getSourceNodeID()+" code 0x"+Integer.toHexString(msg.getCode()).toUpperCase());
+ return;
+ }
// have to resend the SNII request
connection.put(new SimpleNodeIdentInfoRequestMessage(node, msg.getSourceNodeID()), null);
}
Modified: trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java 2012-10-13 16:03:45 UTC (rev 2792)
+++ trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java 2012-10-13 17:53:00 UTC (rev 2793)
@@ -178,7 +178,7 @@
MimicNodeStore.NodeMemo memo = list.iterator().next();
Assert.assertNull(lastMessage);
- store.put(new OptionalIntRejectedMessage(nid1,src,0x0DE8,1), null);
+ store.put(new OptionalIntRejectedMessage(nid1,src,0x0DE8,0x1000), null);
Assert.assertNotNull(lastMessage);
Assert.assertEquals(lastMessage, new SimpleNodeIdentInfoRequestMessage(src, nid1) );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-10-14 23:16:52
|
Revision: 2795
http://openlcb.svn.sourceforge.net/openlcb/?rev=2795&view=rev
Author: jacobsen
Date: 2012-10-14 23:16:46 +0000 (Sun, 14 Oct 2012)
Log Message:
-----------
handle zero-lenght input
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/Utilities.java
trunk/prototypes/java/test/org/openlcb/UtilitiesTest.java
Modified: trunk/prototypes/java/src/org/openlcb/Utilities.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/Utilities.java 2012-10-13 19:25:49 UTC (rev 2794)
+++ trunk/prototypes/java/src/org/openlcb/Utilities.java 2012-10-14 23:16:46 UTC (rev 2795)
@@ -27,48 +27,56 @@
@NonNull
static public String toHexSpaceString(int[] array) {
StringBuffer buff = new StringBuffer();
+ boolean first = true;
for (int i = 0; i < array.length; i++) {
- buff.append(" ");
+ if (!first) buff.append(" ");
+ first = false;
buff.append(Utilities.toHexPair(array[i]));
}
String retval = new String(buff);
- return retval.substring(1);
+ return retval;
}
@CheckReturnValue
@NonNull
static public String toHexSpaceString(byte[] array) {
StringBuffer buff = new StringBuffer();
+ boolean first = true;
for (int i = 0; i < array.length; i++) {
- buff.append(" ");
+ if (!first) buff.append(" ");
+ first = false;
buff.append(Utilities.toHexPair(array[i]));
}
String retval = new String(buff);
- return retval.substring(1);
+ return retval;
}
@CheckReturnValue
@NonNull
static public String toHexDotsString(int[] array) {
StringBuffer buff = new StringBuffer();
+ boolean first = true;
for (int i = 0; i < array.length; i++) {
- buff.append(".");
+ if (!first) buff.append(".");
+ first = false;
buff.append(Utilities.toHexPair(array[i]));
}
String retval = new String(buff);
- return retval.substring(1);
+ return retval;
}
@CheckReturnValue
@NonNull
static public String toHexDotsString(byte[] array) {
StringBuffer buff = new StringBuffer();
+ boolean first = true;
for (int i = 0; i < array.length; i++) {
- buff.append(".");
+ if (!first) buff.append(".");
+ first = false;
buff.append(Utilities.toHexPair(array[i]));
}
String retval = new String(buff);
- return retval.substring(1);
+ return retval;
}
/**
Modified: trunk/prototypes/java/test/org/openlcb/UtilitiesTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/UtilitiesTest.java 2012-10-13 19:25:49 UTC (rev 2794)
+++ trunk/prototypes/java/test/org/openlcb/UtilitiesTest.java 2012-10-14 23:16:46 UTC (rev 2795)
@@ -31,6 +31,20 @@
Assert.assertEquals("0A.0B.12", Utilities.toHexDotsString(new int[]{0x0A, 0x0B, 0x12}));
}
+ public void testSpaceByteArrayZeroLen() {
+ Assert.assertEquals("", Utilities.toHexSpaceString(new int[]{}));
+ }
+ public void testSpaceIntArrayZeroLen() {
+ Assert.assertEquals("", Utilities.toHexSpaceString(new byte[]{}));
+ }
+
+ public void testDotByteArrayZeroLen() {
+ Assert.assertEquals("", Utilities.toHexDotsString(new int[]{}));
+ }
+ public void testDotIntArrayZeroLen() {
+ Assert.assertEquals("", Utilities.toHexDotsString(new byte[]{}));
+ }
+
public void testToByteArray() {
Assert.assertTrue(compareArrays(new byte[]{0xA, 0xB, 0x12}, Utilities.bytesFromHexString("0A 0B 12")));
Assert.assertTrue(compareArrays(new byte[]{0xA, 0xB, 0x12}, Utilities.bytesFromHexString("0A.0B.12")));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2012-10-17 03:09:46
|
Revision: 2798
http://openlcb.svn.sourceforge.net/openlcb/?rev=2798&view=rev
Author: jacobsen
Date: 2012-10-17 03:09:39 +0000 (Wed, 17 Oct 2012)
Log Message:
-----------
better output formatting
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/AddressedMessage.java
trunk/prototypes/java/src/org/openlcb/ConsumerIdentifiedMessage.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/IdentifyConsumersMessage.java
trunk/prototypes/java/src/org/openlcb/IdentifyEventsMessage.java
trunk/prototypes/java/src/org/openlcb/IdentifyProducersMessage.java
trunk/prototypes/java/src/org/openlcb/InitializationCompleteMessage.java
trunk/prototypes/java/src/org/openlcb/LearnEventMessage.java
trunk/prototypes/java/src/org/openlcb/Message.java
trunk/prototypes/java/src/org/openlcb/OptionalIntRejectedMessage.java
trunk/prototypes/java/src/org/openlcb/ProducerConsumerEventReportMessage.java
trunk/prototypes/java/src/org/openlcb/ProducerIdentifiedMessage.java
trunk/prototypes/java/src/org/openlcb/ProtocolIdentificationReplyMessage.java
trunk/prototypes/java/src/org/openlcb/ProtocolIdentificationRequestMessage.java
trunk/prototypes/java/src/org/openlcb/SimpleNodeIdentInfoReplyMessage.java
trunk/prototypes/java/src/org/openlcb/SimpleNodeIdentInfoRequestMessage.java
trunk/prototypes/java/src/org/openlcb/StreamDataCompleteMessage.java
trunk/prototypes/java/src/org/openlcb/StreamDataProceedMessage.java
trunk/prototypes/java/src/org/openlcb/StreamDataSendMessage.java
trunk/prototypes/java/src/org/openlcb/StreamInitReplyMessage.java
trunk/prototypes/java/src/org/openlcb/StreamInitRequestMessage.java
trunk/prototypes/java/src/org/openlcb/VerifiedNodeIDNumberMessage.java
trunk/prototypes/java/src/org/openlcb/VerifyNodeIDNumberMessage.java
trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java
trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java
trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationReplyMessageTest.java
trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationTest.java
trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentInfoReplyMessageTest.java
trunk/prototypes/java/test/org/openlcb/SimpleNodeIdentTest.java
trunk/prototypes/java/test/org/openlcb/swing/networktree/TreePaneTest.java
Modified: trunk/prototypes/java/src/org/openlcb/AddressedMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/AddressedMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/AddressedMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -52,4 +52,8 @@
@Override
public int hashCode() { return super.hashCode()+getDestNodeID().hashCode(); }
+ @Override
+ public String toString() {
+ return getSourceNodeID().toString()+" - "+getDestNodeID();
+ }
}
Modified: trunk/prototypes/java/src/org/openlcb/ConsumerIdentifiedMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/ConsumerIdentifiedMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/ConsumerIdentifiedMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -58,7 +58,7 @@
@Override
public String toString() {
- return getSourceNodeID().toString()
+ return super.toString()
+" Consumer identified for "+eventID.toString();
}
Modified: trunk/prototypes/java/src/org/openlcb/DatagramAcknowledgedMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/DatagramAcknowledgedMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/DatagramAcknowledgedMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -48,6 +48,6 @@
@Override
public String toString() {
- return getSourceNodeID().toString()+" Datagram Acknowledged";
+ return super.toString()+" Datagram Acknowledged";
}
}
Modified: trunk/prototypes/java/src/org/openlcb/DatagramMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/DatagramMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/DatagramMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -84,7 +84,7 @@
@Override
public String toString() {
- StringBuilder value = new StringBuilder(getSourceNodeID().toString());
+ StringBuilder value = new StringBuilder(super.toString());
value.append(" Datagram: ");
int n = getData().length;
Modified: trunk/prototypes/java/src/org/openlcb/DatagramRejectedMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/DatagramRejectedMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/DatagramRejectedMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -70,4 +70,10 @@
public boolean canResend() {
return (code & DATAGRAM_REJECTED_RESEND_MASK) == DATAGRAM_REJECTED_RESEND_MASK;
}
+
+ @Override
+ public String toString() {
+ return super.toString()+" Datagram Rejected";
+ }
+
}
Modified: trunk/prototypes/java/src/org/openlcb/IdentifyConsumersMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/IdentifyConsumersMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/IdentifyConsumersMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -48,7 +48,7 @@
}
public String toString() {
- return getSourceNodeID().toString()
+ return super.toString()
+" Identify Consumers with "+eventID.toString();
}
Modified: trunk/prototypes/java/src/org/openlcb/IdentifyEventsMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/IdentifyEventsMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/IdentifyEventsMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -30,7 +30,7 @@
decoder.handleIdentifyEvents(this, sender);
}
public String toString() {
- return getSourceNodeID().toString()
+ return super.toString()
+" Identify Events ";
}
Modified: trunk/prototypes/java/src/org/openlcb/IdentifyProducersMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/IdentifyProducersMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/IdentifyProducersMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -48,7 +48,7 @@
}
public String toString() {
- return getSourceNodeID().toString()
+ return super.toString()
+" Identify Producers with "+eventID.toString();
}
Modified: trunk/prototypes/java/src/org/openlcb/InitializationCompleteMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/InitializationCompleteMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/InitializationCompleteMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -30,7 +30,7 @@
decoder.handleInitializationComplete(this, sender);
}
public String toString() {
- return getSourceNodeID().toString()
+ return super.toString()
+" Initialization Complete";
}
Modified: trunk/prototypes/java/src/org/openlcb/LearnEventMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/LearnEventMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/LearnEventMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -45,7 +45,7 @@
}
public String toString() {
- return getSourceNodeID().toString()
+ return super.toString()
+" LearnEvent "+eventID.toString();
}
Modified: trunk/prototypes/java/src/org/openlcb/Message.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/Message.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/Message.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -60,5 +60,10 @@
@Override
public int hashCode() { return getSourceNodeID().hashCode(); }
+ @Override
+ public String toString() {
+ return getSourceNodeID().toString()+" ";
+ }
+
abstract public int getMTI();
}
Modified: trunk/prototypes/java/src/org/openlcb/OptionalIntRejectedMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/OptionalIntRejectedMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/OptionalIntRejectedMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -56,7 +56,7 @@
@Override
public String toString() {
- StringBuilder value = new StringBuilder(getSourceNodeID().toString());
+ StringBuilder value = new StringBuilder(super.toString());
value.append(" Optional Interaction Rejected for MTI 0x");
value.append(Integer.toHexString((int)(getMti()&0xFFF)).toUpperCase());
value.append(" code 0x");
Modified: trunk/prototypes/java/src/org/openlcb/ProducerConsumerEventReportMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/ProducerConsumerEventReportMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/ProducerConsumerEventReportMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -45,7 +45,7 @@
}
public String toString() {
- return getSourceNodeID().toString()
+ return super.toString()
+" Producer/Consumer Event Report with "+eventID.toString();
}
Modified: trunk/prototypes/java/src/org/openlcb/ProducerIdentifiedMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/ProducerIdentifiedMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/ProducerIdentifiedMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -47,7 +47,7 @@
}
public String toString() {
- return getSourceNodeID().toString()
+ return super.toString()
+" Producer identified for "+eventID.toString();
}
Modified: trunk/prototypes/java/src/org/openlcb/ProtocolIdentificationReplyMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/ProtocolIdentificationReplyMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/ProtocolIdentificationReplyMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -12,10 +12,10 @@
*/
@Immutable
@ThreadSafe
-public class ProtocolIdentificationReplyMessage extends Message {
+public class ProtocolIdentificationReplyMessage extends AddressedMessage {
- public ProtocolIdentificationReplyMessage(NodeID source, long value) {
- super(source);
+ public ProtocolIdentificationReplyMessage(NodeID source, NodeID dest, long value) {
+ super(source, dest);
this.value = value;
}
@@ -49,8 +49,9 @@
decoder.handleProtocolIdentificationReply(this, sender);
}
+ @Override
public String toString() {
- return getSourceNodeID().toString()
+ return super.toString()
+" Protocol Identification Reply with value "+value;
}
Modified: trunk/prototypes/java/src/org/openlcb/ProtocolIdentificationRequestMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/ProtocolIdentificationRequestMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/ProtocolIdentificationRequestMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -30,7 +30,7 @@
decoder.handleProtocolIdentificationRequest(this, sender);
}
public String toString() {
- return getSourceNodeID().toString()
+ return super.toString()
+" Protocol Identification Request ";
}
Modified: trunk/prototypes/java/src/org/openlcb/SimpleNodeIdentInfoReplyMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/SimpleNodeIdentInfoReplyMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/SimpleNodeIdentInfoReplyMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -12,13 +12,13 @@
*/
@Immutable
@ThreadSafe
-public class SimpleNodeIdentInfoReplyMessage extends Message {
+public class SimpleNodeIdentInfoReplyMessage extends AddressedMessage {
/**
* @param dataIn the data content without extra wire-protocol bytes
*/
- public SimpleNodeIdentInfoReplyMessage(NodeID source, byte[] dataIn) {
- super(source);
+ public SimpleNodeIdentInfoReplyMessage(NodeID source, NodeID dest, byte[] dataIn) {
+ super(source, dest);
this.data = new byte[dataIn.length];
System.arraycopy(dataIn, 0, this.data, 0, dataIn.length);
}
@@ -29,6 +29,7 @@
* To be equal, messages have to have the
* same type and content
*/
+ @Override
public boolean equals(Object o) {
if (o == null) return false;
if (! (o instanceof SimpleNodeIdentInfoReplyMessage))
@@ -61,8 +62,9 @@
decoder.handleSimpleNodeIdentInfoReply(this, sender);
}
+ @Override
public String toString() {
- return getSourceNodeID().toString()
+ return super.toString()
+" Simple Node Ident Info with content "+getData();
}
Modified: trunk/prototypes/java/src/org/openlcb/SimpleNodeIdentInfoRequestMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/SimpleNodeIdentInfoRequestMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/SimpleNodeIdentInfoRequestMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -46,7 +46,7 @@
}
public String toString() {
- return getSourceNodeID().toString()
+ return super.toString()
+" Simple Node Ident Info Request";
}
Modified: trunk/prototypes/java/src/org/openlcb/StreamDataCompleteMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/StreamDataCompleteMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/StreamDataCompleteMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -12,15 +12,13 @@
*/
@Immutable
@ThreadSafe
-public class StreamDataCompleteMessage extends Message {
+public class StreamDataCompleteMessage extends AddressedMessage {
public StreamDataCompleteMessage(NodeID source, NodeID dest,
int sourceStreamID, int destStreamID) {
- super(source);
- this.dest = dest;
+ super(source, dest);
}
- NodeID dest;
int sourceStreamID;
int destStreamID;
@@ -39,15 +37,14 @@
public boolean equals(Object o) {
if (!super.equals(o)) return false;
StreamDataCompleteMessage p = (StreamDataCompleteMessage) o;
- if (!dest.equals(p.dest)) return false;
if (sourceStreamID != p.sourceStreamID) return false;
if (destStreamID != p.destStreamID) return false;
return true;
}
public String toString() {
- return getSourceNodeID().toString()
- +" StreamDataComplete "+dest.toString();
+ return super.toString()
+ +" StreamDataComplete";
}
public int getMTI() { return MTI_STREAM_DATA_COMPLETE; }
Modified: trunk/prototypes/java/src/org/openlcb/StreamDataProceedMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/StreamDataProceedMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/StreamDataProceedMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -12,17 +12,15 @@
*/
@Immutable
@ThreadSafe
-public class StreamDataProceedMessage extends Message {
+public class StreamDataProceedMessage extends AddressedMessage {
public StreamDataProceedMessage(NodeID source, NodeID dest,
int sourceStreamID, int destStreamID) {
- super(source);
- this.dest = dest;
+ super(source, dest);
this.sourceStreamID = sourceStreamID;
this.destStreamID = destStreamID;
}
- NodeID dest;
int sourceStreamID;
int destStreamID;
@@ -41,15 +39,14 @@
public boolean equals(Object o) {
if (!super.equals(o)) return false;
StreamDataProceedMessage p = (StreamDataProceedMessage) o;
- if (!dest.equals(p.dest)) return false;
if (sourceStreamID != p.sourceStreamID) return false;
if (destStreamID != p.destStreamID) return false;
- return true;
+ return super.equals(o);
}
public String toString() {
- return getSourceNodeID().toString()
- +" StreamDataProceed "+dest.toString();
+ return super.toString()
+ +" StreamDataProceed";
}
public int getMTI() { return MTI_STREAM_DATA_PROCEED; }
Modified: trunk/prototypes/java/src/org/openlcb/StreamDataSendMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/StreamDataSendMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/StreamDataSendMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -12,17 +12,15 @@
*/
@Immutable
@ThreadSafe
-public class StreamDataSendMessage extends Message {
+public class StreamDataSendMessage extends AddressedMessage {
public StreamDataSendMessage(NodeID source, NodeID dest, int[] data,
int destStreamID) {
- super(source);
- this.dest = dest;
+ super(source, dest);
this.data = data;
this.destStreamID = destStreamID;
}
- NodeID dest;
int[] data;
int destStreamID;
@@ -41,16 +39,15 @@
public boolean equals(Object o) {
if (!super.equals(o)) return false;
StreamDataSendMessage p = (StreamDataSendMessage) o;
- if (!dest.equals(p.dest)) return false;
if (data.length != p.data.length) return false;
// should also check data length
if (destStreamID != p.destStreamID) return false;
- return true;
+ return super.equals(o);
}
public String toString() {
- return getSourceNodeID().toString()
- +" StreamDataSend "+dest.toString();
+ return super.toString()
+ +" StreamDataSend "+data;
}
public int getMTI() { return MTI_STREAM_DATA_SEND; }
Modified: trunk/prototypes/java/src/org/openlcb/StreamInitReplyMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/StreamInitReplyMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/StreamInitReplyMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -12,18 +12,16 @@
*/
@Immutable
@ThreadSafe
-public class StreamInitReplyMessage extends Message {
+public class StreamInitReplyMessage extends AddressedMessage {
public StreamInitReplyMessage(NodeID source, NodeID dest,
int bufferSize, int sourceStreamID, int destStreamID) {
- super(source);
- this.dest = dest;
+ super(source, dest);
this.bufferSize = bufferSize;
this.sourceStreamID = sourceStreamID;
this.destStreamID = destStreamID;
}
- NodeID dest;
int bufferSize;
int sourceStreamID;
int destStreamID;
@@ -46,16 +44,15 @@
public boolean equals(Object o) {
if (!super.equals(o)) return false;
StreamInitReplyMessage p = (StreamInitReplyMessage) o;
- if (!dest.equals(p.dest)) return false;
if (bufferSize != p.bufferSize) return false;
if (sourceStreamID != p.sourceStreamID) return false;
if (destStreamID != p.destStreamID) return false;
- return true;
+ return super.equals(o);
}
public String toString() {
- return getSourceNodeID().toString()
- +" StreamInitReply "+dest.toString()
+ return super.toString()
+ +" StreamInitReply"
+" SSID "+sourceStreamID
+" DSID "+destStreamID
+" bsize "+bufferSize;
Modified: trunk/prototypes/java/src/org/openlcb/StreamInitRequestMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/StreamInitRequestMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/StreamInitRequestMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -12,17 +12,15 @@
*/
@Immutable
@ThreadSafe
-public class StreamInitRequestMessage extends Message {
+public class StreamInitRequestMessage extends AddressedMessage {
public StreamInitRequestMessage(NodeID source, NodeID dest,
int bufferSize, int sourceStreamID) {
- super(source);
- this.dest = dest;
+ super(source, dest);
this.bufferSize = bufferSize;
this.sourceStreamID = sourceStreamID;
}
- NodeID dest;
int bufferSize;
int sourceStreamID;
@@ -44,15 +42,14 @@
public boolean equals(Object o) {
if (!super.equals(o)) return false;
StreamInitRequestMessage p = (StreamInitRequestMessage) o;
- if (!dest.equals(p.dest)) return false;
if (bufferSize != p.bufferSize) return false;
if (sourceStreamID != p.sourceStreamID) return false;
- return true;
+ return super.equals(o);
}
public String toString() {
- return getSourceNodeID().toString()
- +" StreamInitRequest "+dest.toString()
+ return super.toString()
+ +" StreamInitRequest "
+" SSID "+sourceStreamID
+" bsize "+bufferSize;
}
Modified: trunk/prototypes/java/src/org/openlcb/VerifiedNodeIDNumberMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/VerifiedNodeIDNumberMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/VerifiedNodeIDNumberMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -30,7 +30,7 @@
decoder.handleVerifiedNodeIDNumber(this, sender);
}
public String toString() {
- return getSourceNodeID().toString()
+ return super.toString()
+" Verified Node ID Number";
}
Modified: trunk/prototypes/java/src/org/openlcb/VerifyNodeIDNumberMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/VerifyNodeIDNumberMessage.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/VerifyNodeIDNumberMessage.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -61,7 +61,7 @@
}
public String toString() {
- return getSourceNodeID().toString()
+ return super.toString()
+" Verify Node ID Number: "
+ ((content != null) ? (content+" only") : ("all nodes"));
}
Modified: trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/src/org/openlcb/can/MessageBuilder.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -186,7 +186,7 @@
retlist.add(new ProtocolIdentificationRequestMessage(source, dest));
return retlist;
case ProtocolSupportReply:
- retlist.add(new ProtocolIdentificationReplyMessage(source,f.dataAsLong()));
+ retlist.add(new ProtocolIdentificationReplyMessage(source, dest, f.dataAsLong()));
return retlist;
case IdentifyConsumer:
@@ -220,7 +220,7 @@
byte[] content = new byte[data.length-2];
System.arraycopy(data, 2, content, 0, content.length);
- retlist.add(new SimpleNodeIdentInfoReplyMessage(source,content));
+ retlist.add(new SimpleNodeIdentInfoReplyMessage(source, dest, content));
return retlist;
case DatagramReceivedOK:
Modified: trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/test/org/openlcb/MimicNodeStoreTest.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -24,7 +24,7 @@
ProducerIdentifiedMessage pim2 = new ProducerIdentifiedMessage(nid2,
new EventID(new byte[]{1,0,0,0,0,0,1,0}));
- SimpleNodeIdentInfoReplyMessage snii1 = new SimpleNodeIdentInfoReplyMessage(nid1,
+ SimpleNodeIdentInfoReplyMessage snii1 = new SimpleNodeIdentInfoReplyMessage(nid1, nid2,
new byte[]{1,'a','b','c'});
PropertyChangeListener listener;
@@ -104,7 +104,7 @@
store.put(pim1,null);
Collection<MimicNodeStore.NodeMemo> list = store.getNodeMemos();
MimicNodeStore.NodeMemo memo = list.iterator().next();
- store.put(new ProtocolIdentificationReplyMessage(nid1, 0xF00000000000L), null);
+ store.put(new ProtocolIdentificationReplyMessage(nid1, nid2, 0xF00000000000L), null);
Assert.assertNotNull(memo.getProtocolIdentification());
}
@@ -120,7 +120,7 @@
store.put(pim1,null);
Assert.assertFalse(listenerFired);
- store.put(new ProtocolIdentificationReplyMessage(nid1, 0xF00000000000L), null);
+ store.put(new ProtocolIdentificationReplyMessage(nid1, nid2, 0xF00000000000L), null);
Assert.assertTrue(listenerFired);
}
@@ -138,10 +138,10 @@
store.put(pim2,null);
Assert.assertFalse(listenerFired);
- store.put(new ProtocolIdentificationReplyMessage(nid1, 0xF00000000000L), null);
+ store.put(new ProtocolIdentificationReplyMessage(nid1, nid2, 0xF00000000000L), null);
Assert.assertFalse(listenerFired);
- store.put(new ProtocolIdentificationReplyMessage(nid2, 0xF00000000000L), null);
+ store.put(new ProtocolIdentificationReplyMessage(nid2, nid2, 0xF00000000000L), null);
Assert.assertTrue(listenerFired);
}
Modified: trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationReplyMessageTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationReplyMessageTest.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationReplyMessageTest.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -17,18 +17,18 @@
public void testEqualsSame() {
Message m1 = new ProtocolIdentificationReplyMessage(
- nodeID1, 12);
+ nodeID1, nodeID2,12);
Message m2 = new ProtocolIdentificationReplyMessage(
- nodeID1, 12);
+ nodeID1, nodeID2, 12);
Assert.assertTrue(m1.equals(m2));
}
public void testNotEqualsDifferentNode() {
Message m1 = new ProtocolIdentificationReplyMessage(
- nodeID1, 12);
+ nodeID1, nodeID2, 12);
Message m2 = new ProtocolIdentificationReplyMessage(
- nodeID2, 12);
+ nodeID2, nodeID2, 12);
Assert.assertTrue( ! m1.equals(m2));
}
@@ -36,9 +36,9 @@
public void testNotEqualsDifferentValue() {
Message m1 = new ProtocolIdentificationReplyMessage(
- nodeID1, 12);
+ nodeID1, nodeID2, 12);
Message m2 = new ProtocolIdentificationReplyMessage(
- nodeID1, 13);
+ nodeID1, nodeID2, 13);
Assert.assertTrue( ! m1.equals(m2));
}
@@ -52,7 +52,7 @@
result = true;
}
};
- Message m = new ProtocolIdentificationReplyMessage(nodeID1, 21);
+ Message m = new ProtocolIdentificationReplyMessage(nodeID1, nodeID2, 21);
n.put(m, null);
Modified: trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationTest.java 2012-10-16 16:48:35 UTC (rev 2797)
+++ trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationTest.java 2012-10-17 03:09:39 UTC (rev 2798)
@@ -72,7 +72,7 @@
public void testCreationFromMessage() {
ProtocolIdentification pi = new ProtocolIdenti...
[truncated message content] |
|
From: <jac...@us...> - 2013-01-28 05:43:14
|
Revision: 2946
http://openlcb.svn.sourceforge.net/openlcb/?rev=2946&view=rev
Author: jacobsen
Date: 2013-01-28 05:43:07 +0000 (Mon, 28 Jan 2013)
Log Message:
-----------
train node support
Modified Paths:
--------------
trunk/prototypes/java/openlcb-demo.jar
trunk/prototypes/java/openlcb.jar
trunk/prototypes/java/test/org/openlcb/implementations/throttle/PackageTest.java
Added Paths:
-----------
trunk/prototypes/java/src/org/openlcb/implementations/throttle/AbstractNodeCache.java
trunk/prototypes/java/src/org/openlcb/implementations/throttle/TrainNode.java
trunk/prototypes/java/src/org/openlcb/implementations/throttle/TrainNodeCache.java
trunk/prototypes/java/src/org/openlcb/implementations/throttle/dcc/
trunk/prototypes/java/src/org/openlcb/implementations/throttle/dcc/DccProxyCache.java
trunk/prototypes/java/test/org/openlcb/implementations/throttle/TrainNodeCacheTest.java
trunk/prototypes/java/test/org/openlcb/implementations/throttle/TrainNodeTest.java
trunk/prototypes/java/test/org/openlcb/implementations/throttle/dcc/
trunk/prototypes/java/test/org/openlcb/implementations/throttle/dcc/DccProxyCacheTest.java
trunk/prototypes/java/test/org/openlcb/implementations/throttle/dcc/PackageTest.java
Modified: trunk/prototypes/java/openlcb-demo.jar
===================================================================
(Binary files differ)
Modified: trunk/prototypes/java/openlcb.jar
===================================================================
(Binary files differ)
Added: trunk/prototypes/java/src/org/openlcb/implementations/throttle/AbstractNodeCache.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/throttle/AbstractNodeCache.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/implementations/throttle/AbstractNodeCache.java 2013-01-28 05:43:07 UTC (rev 2946)
@@ -0,0 +1,44 @@
+package org.openlcb.implementations.throttle;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.openlcb.Connection;
+import org.openlcb.EventID;
+import org.openlcb.MessageDecoder;
+import org.openlcb.ProducerConsumerEventReportMessage;
+
+/**
+ *
+ * @author Bob Jacobsen Copyright 2012
+ */
+public class AbstractNodeCache extends MessageDecoder {
+
+ public AbstractNodeCache(EventID indicator) {
+ this.indicator = indicator;
+ }
+ ArrayList<TrainNode> list = new ArrayList<TrainNode>();
+ EventID indicator;
+
+ public List<TrainNode> getList() {
+ return list;
+ }
+
+ public void handleProducerConsumerEventReport(ProducerConsumerEventReportMessage msg, Connection sender) {
+ EventID evt = msg.getEventID();
+ if (evt.equals(indicator)) {
+ // get source as Node ID for train node
+ TrainNode tn = new TrainNode(msg.getSourceNodeID());
+ list.add(tn);
+ firePropertyChange("TrainNode", null, tn);
+ }
+ }
+
+ 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);
+ }
+ protected void firePropertyChange(String p, Object old, Object n) { pcs.firePropertyChange(p,old,n);}
+}
Copied: trunk/prototypes/java/src/org/openlcb/implementations/throttle/TrainNode.java (from rev 2815, trunk/prototypes/java/src/org/openlcb/implementations/throttle/Float16.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/throttle/TrainNode.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/implementations/throttle/TrainNode.java 2013-01-28 05:43:07 UTC (rev 2946)
@@ -0,0 +1,24 @@
+package org.openlcb.implementations.throttle;
+
+import net.jcip.annotations.Immutable;
+import net.jcip.annotations.ThreadSafe;
+import org.openlcb.*;
+
+/**
+ * Represents a TrainNode, a node that implements the Train protocol.
+ *
+ *
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision$
+ */
+@Immutable
+@ThreadSafe
+public class TrainNode {
+
+ public TrainNode(NodeID node) {
+ this.node = node;
+ }
+ NodeID node;
+
+ public NodeID getNode() { return node; }
+}
Copied: trunk/prototypes/java/src/org/openlcb/implementations/throttle/TrainNodeCache.java (from rev 2815, trunk/prototypes/java/src/org/openlcb/implementations/throttle/Float16.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/throttle/TrainNodeCache.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/implementations/throttle/TrainNodeCache.java 2013-01-28 05:43:07 UTC (rev 2946)
@@ -0,0 +1,19 @@
+package org.openlcb.implementations.throttle;
+
+import net.jcip.annotations.Immutable;
+import net.jcip.annotations.ThreadSafe;
+import org.openlcb.*;
+
+/**
+ * Maintain a cache of Train objects on OpenLCB network
+ *
+ *
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision$
+ */
+public class TrainNodeCache extends AbstractNodeCache {
+
+ public TrainNodeCache() {
+ super(new EventID("01.01.00.00.00.00.03.01"));
+ }
+}
Copied: trunk/prototypes/java/src/org/openlcb/implementations/throttle/dcc/DccProxyCache.java (from rev 2815, trunk/prototypes/java/src/org/openlcb/implementations/throttle/Float16.java)
===================================================================
--- trunk/prototypes/java/src/org/openlcb/implementations/throttle/dcc/DccProxyCache.java (rev 0)
+++ trunk/prototypes/java/src/org/openlcb/implementations/throttle/dcc/DccProxyCache.java 2013-01-28 05:43:07 UTC (rev 2946)
@@ -0,0 +1,21 @@
+package org.openlcb.implementations.throttle.dcc;
+
+import net.jcip.annotations.Immutable;
+import net.jcip.annotations.ThreadSafe;
+import org.openlcb.*;
+
+import org.openlcb.implementations.throttle.AbstractNodeCache;
+
+/**
+ * Maintain a cache of Train objects on OpenLCB network
+ *
+ *
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision$
+ */
+public class DccProxyCache extends AbstractNodeCache {
+
+ public DccProxyCache() {
+ super(new EventID("01.01.00.00.00.00.04.01"));
+ }
+}
Modified: trunk/prototypes/java/test/org/openlcb/implementations/throttle/PackageTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/throttle/PackageTest.java 2013-01-28 05:23:12 UTC (rev 2945)
+++ trunk/prototypes/java/test/org/openlcb/implementations/throttle/PackageTest.java 2013-01-28 05:43:07 UTC (rev 2946)
@@ -32,7 +32,11 @@
suite.addTest(Float16Test.suite());
suite.addTest(ThrottleSpeedDatagramTest.suite());
suite.addTest(ThrottleImplementationTest.suite());
+ suite.addTest(TrainNodeTest.suite());
+ suite.addTest(TrainNodeCacheTest.suite());
+ suite.addTest(org.openlcb.implementations.throttle.dcc.PackageTest.suite());
+
return suite;
}
}
Copied: trunk/prototypes/java/test/org/openlcb/implementations/throttle/TrainNodeCacheTest.java (from rev 2815, trunk/prototypes/java/test/org/openlcb/implementations/throttle/Float16Test.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/throttle/TrainNodeCacheTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/implementations/throttle/TrainNodeCacheTest.java 2013-01-28 05:43:07 UTC (rev 2946)
@@ -0,0 +1,80 @@
+package org.openlcb.implementations.throttle;
+
+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 TrainNodeCacheTest extends TestCase {
+ TrainNodeCache cache;
+
+ public void testSetup() {
+ Assert.assertTrue(cache != null);
+ }
+
+ public void testEmpty() {
+ Assert.assertTrue(cache.getList() != null);
+ Assert.assertEquals(0, cache.getList().size());
+ }
+
+ public void testIgnoresMessage() {
+
+ Message m = new OptionalIntRejectedMessage(null, null, 0, 0);
+
+ cache.put(m, null);
+ Assert.assertTrue(cache.getList() != null);
+ Assert.assertEquals(0, cache.getList().size());
+ }
+
+ public void testIgnoresEvent() {
+
+ Message m = new ProducerConsumerEventReportMessage(null, new EventID("01.02.03.04.05.06.07.08"));
+
+ cache.put(m, null);
+ Assert.assertTrue(cache.getList() != null);
+ Assert.assertEquals(0, cache.getList().size());
+ }
+
+ public void testSeesIsTrainEvent() {
+
+ Message m = new ProducerConsumerEventReportMessage(new NodeID(new byte[]{1,1,0,0,4,4}), new EventID("01.01.00.00.00.00.03.01"));
+
+ cache.put(m, null);
+ Assert.assertTrue(cache.getList() != null);
+ Assert.assertEquals(1, cache.getList().size());
+
+ TrainNode tn = cache.getList().get(0);
+
+ Assert.assertTrue(tn.getNode().equals(new NodeID(new byte[]{1,1,0,0,4,4})));
+
+ }
+
+ public void setUp() {
+ cache = new TrainNodeCache();
+ }
+
+ // from here down is testing infrastructure
+
+ public TrainNodeCacheTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {TrainNodeCacheTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(TrainNodeCacheTest.class);
+ return suite;
+ }
+}
Copied: trunk/prototypes/java/test/org/openlcb/implementations/throttle/TrainNodeTest.java (from rev 2815, trunk/prototypes/java/test/org/openlcb/implementations/throttle/Float16Test.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/throttle/TrainNodeTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/implementations/throttle/TrainNodeTest.java 2013-01-28 05:43:07 UTC (rev 2946)
@@ -0,0 +1,43 @@
+package org.openlcb.implementations.throttle;
+
+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 TrainNodeTest extends TestCase {
+
+ public void testCtor() {
+ new TrainNode(new NodeID(new byte[]{1,2,3,4,5,6}));
+ }
+
+ public void testNodeMemory() {
+ TrainNode node = new TrainNode(new NodeID(new byte[]{1,2,3,4,5,6}));
+ Assert.assertTrue(new NodeID(new byte[]{1,2,3,4,5,6}).equals(node.getNode()));
+ }
+
+ // from here down is testing infrastructure
+
+ public TrainNodeTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {TrainNodeTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(TrainNodeTest.class);
+ return suite;
+ }
+}
Copied: trunk/prototypes/java/test/org/openlcb/implementations/throttle/dcc/DccProxyCacheTest.java (from rev 2815, trunk/prototypes/java/test/org/openlcb/implementations/throttle/Float16Test.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/throttle/dcc/DccProxyCacheTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/implementations/throttle/dcc/DccProxyCacheTest.java 2013-01-28 05:43:07 UTC (rev 2946)
@@ -0,0 +1,82 @@
+package org.openlcb.implementations.throttle.dcc;
+
+import org.openlcb.*;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.openlcb.implementations.throttle.*;
+
+/**
+ *
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision$
+ */
+public class DccProxyCacheTest extends TestCase {
+ DccProxyCache cache;
+
+ public void testSetup() {
+ Assert.assertTrue(cache != null);
+ }
+
+ public void testEmpty() {
+ Assert.assertTrue(cache.getList() != null);
+ Assert.assertEquals(0, cache.getList().size());
+ }
+
+ public void testIgnoresMessage() {
+
+ Message m = new OptionalIntRejectedMessage(null, null, 0, 0);
+
+ cache.put(m, null);
+ Assert.assertTrue(cache.getList() != null);
+ Assert.assertEquals(0, cache.getList().size());
+ }
+
+ public void testIgnoresEvent() {
+
+ Message m = new ProducerConsumerEventReportMessage(null, new EventID("01.02.03.04.05.06.07.08"));
+
+ cache.put(m, null);
+ Assert.assertTrue(cache.getList() != null);
+ Assert.assertEquals(0, cache.getList().size());
+ }
+
+ public void testSeesIsTrainEvent() {
+
+ Message m = new ProducerConsumerEventReportMessage(new NodeID(new byte[]{1,1,0,0,4,4}), new EventID("01.01.00.00.00.00.04.01"));
+
+ cache.put(m, null);
+ Assert.assertTrue(cache.getList() != null);
+ Assert.assertEquals(1, cache.getList().size());
+
+ TrainNode tn = cache.getList().get(0);
+
+ Assert.assertTrue(tn.getNode().equals(new NodeID(new byte[]{1,1,0,0,4,4})));
+
+ }
+
+ public void setUp() {
+ cache = new DccProxyCache();
+ }
+
+ // from here down is testing infrastructure
+
+ public DccProxyCacheTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {DccProxyCacheTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(DccProxyCacheTest.class);
+ return suite;
+ }
+}
Copied: trunk/prototypes/java/test/org/openlcb/implementations/throttle/dcc/PackageTest.java (from rev 2815, trunk/prototypes/java/test/org/openlcb/implementations/throttle/PackageTest.java)
===================================================================
--- trunk/prototypes/java/test/org/openlcb/implementations/throttle/dcc/PackageTest.java (rev 0)
+++ trunk/prototypes/java/test/org/openlcb/implementations/throttle/dcc/PackageTest.java 2013-01-28 05:43:07 UTC (rev 2946)
@@ -0,0 +1,36 @@
+package org.openlcb.implementations.throttle.dcc;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * @author Bob Jacobsen Copyright 2012
+ * @version $Revision$
+ */
+public class PackageTest extends TestCase {
+ public void testStart() {
+ }
+
+ // from here down is testing infrastructure
+
+ public PackageTest(String s) {
+ super(s);
+ }
+
+ // Main entry point
+ static public void main(String[] args) {
+ String[] testCaseName = {PackageTest.class.getName()};
+ junit.swingui.TestRunner.main(testCaseName);
+ }
+
+ // test suite from all defined tests
+ public static Test suite() {
+ TestSuite suite = new TestSuite(PackageTest.class);
+
+ suite.addTest(DccProxyCacheTest.suite());
+
+ return suite;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2013-02-24 17:58:46
|
Revision: 3028
http://openlcb.svn.sourceforge.net/openlcb/?rev=3028&view=rev
Author: jacobsen
Date: 2013-02-24 17:58:38 +0000 (Sun, 24 Feb 2013)
Log Message:
-----------
new lib for reading files during tests
Modified Paths:
--------------
trunk/prototypes/java/build.xml
trunk/prototypes/java/runtest.csh
Modified: trunk/prototypes/java/build.xml
===================================================================
--- trunk/prototypes/java/build.xml 2013-02-24 17:57:22 UTC (rev 3027)
+++ trunk/prototypes/java/build.xml 2013-02-24 17:58:38 UTC (rev 3028)
@@ -34,6 +34,7 @@
<path id="project.class.path">
<pathelement location="." />
<pathelement location="lib/junit.jar" />
+ <pathelement location="lib/xercesImpl.jar" /> <!-- only needed for tests compile and run -->
<pathelement location="lib/jdom.jar" />
<pathelement location="lib/jlfgr-1_0.jar" />
<pathelement location="lib/annotations.jar" /> <!-- only needed for compile -->
Modified: trunk/prototypes/java/runtest.csh
===================================================================
--- trunk/prototypes/java/runtest.csh 2013-02-24 17:57:22 UTC (rev 3027)
+++ trunk/prototypes/java/runtest.csh 2013-02-24 17:58:38 UTC (rev 3028)
@@ -12,5 +12,5 @@
-Dapple.laf.useScreenMenuBar=true \
-Dlog4j.ignoreTCL=true \
-Djava.library.path=.:lib/ \
- -cp .:classes:lib/junit.jar:lib/jdom.jar:lib/jlfgr-1_0.jar \
+ -cp .:classes:lib/junit.jar:lib/xercesImpl.jar:lib/jdom.jar:lib/jlfgr-1_0.jar \
$1 $2 $3
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jac...@us...> - 2013-07-06 06:32:48
|
Revision: 3239
http://sourceforge.net/p/openlcb/svn/3239
Author: jacobsen
Date: 2013-07-06 06:32:45 +0000 (Sat, 06 Jul 2013)
Log Message:
-----------
hub changes
Modified Paths:
--------------
trunk/prototypes/java/openlcb-demo.jar
trunk/prototypes/java/openlcb.jar
Modified: trunk/prototypes/java/openlcb-demo.jar
===================================================================
(Binary files differ)
Modified: trunk/prototypes/java/openlcb.jar
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|