|
From: <jac...@us...> - 2012-02-04 20:35:48
|
Revision: 1727
http://openlcb.svn.sourceforge.net/openlcb/?rev=1727&view=rev
Author: jacobsen
Date: 2012-02-04 20:35:42 +0000 (Sat, 04 Feb 2012)
Log Message:
-----------
carries value as long
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/ProtocolIdentification.java
trunk/prototypes/java/src/org/openlcb/ProtocolIdentificationReplyMessage.java
trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationReplyMessageTest.java
Modified: trunk/prototypes/java/src/org/openlcb/ProtocolIdentification.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/ProtocolIdentification.java 2012-02-04 20:34:53 UTC (rev 1726)
+++ trunk/prototypes/java/src/org/openlcb/ProtocolIdentification.java 2012-02-04 20:35:42 UTC (rev 1727)
@@ -46,5 +46,14 @@
return retval;
}
}
-
+
+ long value = 0; // multiple bits, e.g. from a node
+
+ public ProtocolIdentification( ProtocolIdentificationReplyMessage msg) {
+ value = msg.getValue();
+ }
+ public ProtocolIdentification() {
+ value = 0;
+ }
+
}
Modified: trunk/prototypes/java/src/org/openlcb/ProtocolIdentificationReplyMessage.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/ProtocolIdentificationReplyMessage.java 2012-02-04 20:34:53 UTC (rev 1726)
+++ trunk/prototypes/java/src/org/openlcb/ProtocolIdentificationReplyMessage.java 2012-02-04 20:35:42 UTC (rev 1727)
@@ -14,10 +14,29 @@
@ThreadSafe
public class ProtocolIdentificationReplyMessage extends Message {
- public ProtocolIdentificationReplyMessage(NodeID source) {
+ public ProtocolIdentificationReplyMessage(NodeID source, long value) {
super(source);
+ this.value = value;
}
+ long value;
+
+ public long getValue() { return value; }
+
+ /**
+ * To be equal, messages have to have the
+ * same type and content
+ */
+ public boolean equals(Object o) {
+ if (o == null) return false;
+ if (! (o instanceof ProtocolIdentificationReplyMessage))
+ return false;
+ ProtocolIdentificationReplyMessage msg = (ProtocolIdentificationReplyMessage) o;
+ if (this.value != msg.getValue())
+ return false;
+ return super.equals(o);
+ }
+
/**
* Implement message-type-specific
* processing when this message
@@ -29,9 +48,10 @@
public void applyTo(MessageDecoder decoder, Connection sender) {
decoder.handleProtocolIdentificationReply(this, sender);
}
+
public String toString() {
return getSourceNodeID().toString()
- +" Protocol Identification Reply ";
+ +" Protocol Identification Reply with value "+value;
}
public int getMTI() { return MTI_PROTOCOL_IDENT_REPLY; }
Modified: trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationReplyMessageTest.java
===================================================================
--- trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationReplyMessageTest.java 2012-02-04 20:34:53 UTC (rev 1726)
+++ trunk/prototypes/java/test/org/openlcb/ProtocolIdentificationReplyMessageTest.java 2012-02-04 20:35:42 UTC (rev 1727)
@@ -17,23 +17,33 @@
public void testEqualsSame() {
Message m1 = new ProtocolIdentificationReplyMessage(
- nodeID1);
+ nodeID1, 12);
Message m2 = new ProtocolIdentificationReplyMessage(
- nodeID1);
+ nodeID1, 12);
Assert.assertTrue(m1.equals(m2));
}
public void testNotEqualsDifferentNode() {
Message m1 = new ProtocolIdentificationReplyMessage(
- nodeID1);
+ nodeID1, 12);
Message m2 = new ProtocolIdentificationReplyMessage(
- nodeID2);
+ nodeID2, 12);
Assert.assertTrue( ! m1.equals(m2));
}
+ public void testNotEqualsDifferentValue() {
+ Message m1 = new ProtocolIdentificationReplyMessage(
+ nodeID1, 12);
+ Message m2 = new ProtocolIdentificationReplyMessage(
+ nodeID1, 13);
+
+ Assert.assertTrue( ! m1.equals(m2));
+ }
+
+
public void testHandling() {
result = false;
Node n = new Node(){
@@ -42,7 +52,7 @@
result = true;
}
};
- Message m = new ProtocolIdentificationReplyMessage(nodeID1);
+ Message m = new ProtocolIdentificationReplyMessage(nodeID1, 21);
n.put(m, null);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|