Skip to content

Commit

Permalink
Merge pull request #264 from bobjacobsen/IC_Simple_via_state
Browse files Browse the repository at this point in the history
Add Simple property to InitComplete and VerifiedNode msgs
  • Loading branch information
dpharris authored May 23, 2024
2 parents dd68d12 + 494884a commit 52e9473
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 18 deletions.
16 changes: 13 additions & 3 deletions src/org/openlcb/InitializationCompleteMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,26 @@
/**
* Initialization Complete message implementation
*
* @author Bob Jacobsen Copyright 2009
* @version $Revision$
* @author Bob Jacobsen Copyright 2009, 2024
*/
@Immutable
@ThreadSafe
public class InitializationCompleteMessage extends Message {

public InitializationCompleteMessage(NodeID source) {
super(source);
this.hasSimpleProtocol = false;
}

public InitializationCompleteMessage(NodeID source, boolean hasSimpleProtocol) {
super(source);
this.hasSimpleProtocol = hasSimpleProtocol;
}

final boolean hasSimpleProtocol;

public boolean hasSimpleProtocol() { return hasSimpleProtocol; }

/**
* Implement message-type-specific
* processing when this message
Expand All @@ -31,7 +40,8 @@ public void applyTo(MessageDecoder decoder, Connection sender) {
}
public String toString() {
return super.toString()
+" Initialization Complete";
+" Initialization Complete"
+(hasSimpleProtocol() ? " with Simple Protocol" : "");
}

public int getMTI() { return MTI_INITIALIZATION_COMPLETE; }
Expand Down
3 changes: 3 additions & 0 deletions src/org/openlcb/MessageTypeIdentifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ public enum MessageTypeIdentifier {
// addr, event, simpl, S, P, Ty, M, Name

InitializationComplete ( false, false, false, 0, 0, 8, 0, "InitializationComplete"),
InitializationCompleteSimple( false, false, false, 0, 0, 8, 1, "InitializationCompleteSimple"),

VerifyNodeIdAddressed ( true, false, false, 0, 1, 4, 0, "VerifyNodeIdAddressed"),
VerifyNodeIdGlobal ( false, false, true, 0, 1, 4, 0, "VerifyNodeIdGlobal"),
VerifiedNodeId ( false, false, true, 0, 0, 11, 0, "VerifiedNodeId"),
VerifiedNodeIdSimple ( false, false, true, 0, 0, 11, 1, "VerifiedNodeIdSimple"),
OptionalInteractionRejected ( true, false, false, 0, 0, 3, 0, "OptionalInteractionRejected"),
TerminateDueToError ( true, false, false, 0, 0, 5, 0, "TerminateDueToError"),

Expand Down
2 changes: 1 addition & 1 deletion src/org/openlcb/OpenLcb.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface OpenLcb {
static final int MTI_INITIALIZATION_COMPLETE = (int)MessageTypeIdentifier.InitializationComplete.mti();

static final int MTI_VERIFY_NID = 0x10A4;
static final int MTI_VERIFIED_NID = 0x10B0;
static final int MTI_VERIFIED_NID = (int)MessageTypeIdentifier.VerifiedNodeId.mti();

static final int MTI_OPT_INT_REJECTED = 0x30C0;

Expand Down
18 changes: 14 additions & 4 deletions src/org/openlcb/VerifiedNodeIDNumberMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,26 @@
/**
* Verified Node ID Number message implementation
*
* @author Bob Jacobsen Copyright 2009
* @version $Revision$
* @author Bob Jacobsen Copyright 2009, 2024
*/
@Immutable
@ThreadSafe
public class VerifiedNodeIDNumberMessage extends Message {

public VerifiedNodeIDNumberMessage(NodeID source) {
super(source);
this.hasSimpleProtocol = false;
}


public VerifiedNodeIDNumberMessage(NodeID source, boolean hasSimpleProtocol) {
super(source);
this.hasSimpleProtocol = hasSimpleProtocol;
}

final boolean hasSimpleProtocol;

public boolean hasSimpleProtocol() { return hasSimpleProtocol; }

/**
* Implement message-type-specific
* processing when this message
Expand All @@ -31,7 +40,8 @@ public void applyTo(MessageDecoder decoder, Connection sender) {
}
public String toString() {
return super.toString()
+" Verified Node ID Number";
+" Verified Node ID Number"
+(hasSimpleProtocol() ? " with Simple Protocol" : "");
}

public int getMTI() { return MTI_VERIFIED_NID; }
Expand Down
15 changes: 13 additions & 2 deletions src/org/openlcb/can/MessageBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ List<Message> processFormat1(CanFrame f) {
case InitializationComplete:
retlist.add(new InitializationCompleteMessage(source));
return retlist;

case InitializationCompleteSimple:
retlist.add(new InitializationCompleteMessage(source, true));
return retlist;

case VerifyNodeIdAddressed:
// check for content
if (data.length >= 6) {
Expand All @@ -263,6 +268,10 @@ List<Message> processFormat1(CanFrame f) {
retlist.add(new VerifiedNodeIDNumberMessage(source));
return retlist;

case VerifiedNodeIdSimple:
retlist.add(new VerifiedNodeIDNumberMessage(source, true));
return retlist;

case OptionalInteractionRejected: {
int d2 = data.length >= 3 ? f.getElement(2) : 0;
int d3 = data.length >= 4 ? f.getElement(3) : 0;
Expand Down Expand Up @@ -709,7 +718,9 @@ private void handleAddressedPayloadMessage(AddressedPayloadMessage msg, Connecti
@Override
public void handleInitializationComplete(InitializationCompleteMessage msg, Connection sender){
OpenLcbCanFrame f = new OpenLcbCanFrame(0x00);
f.setInitializationComplete(map.getAlias(msg.getSourceNodeID()), msg.getSourceNodeID());
f.setInitializationComplete(map.getAlias(msg.getSourceNodeID()),
msg.getSourceNodeID(),
msg.hasSimpleProtocol());
f.setSourceAlias(map.getAlias(msg.getSourceNodeID()));
retlist.add(f);
}
Expand All @@ -718,7 +729,7 @@ public void handleInitializationComplete(InitializationCompleteMessage msg, Conn
*/
public void handleVerifiedNodeIDNumber(VerifiedNodeIDNumberMessage msg, Connection sender){
OpenLcbCanFrame f = new OpenLcbCanFrame(0x00);
f.setVerifiedNID(msg.getSourceNodeID());
f.setVerifiedNID(msg.getSourceNodeID(), msg.hasSimpleProtocol());
f.setSourceAlias(map.getAlias(msg.getSourceNodeID()));
retlist.add(f);
}
Expand Down
16 changes: 12 additions & 4 deletions src/org/openlcb/can/OpenLcbCanFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,14 @@ boolean isLearnEvent() {
return isOpenLcbMTI(MessageTypeIdentifier.LearnEvent.mti());
}

void setInitializationComplete(int alias, NodeID nid) {
void setInitializationComplete(int alias, NodeID nid, boolean simple) {
nodeAlias = alias;
init(nodeAlias);
setOpenLcbMTI(MessageTypeIdentifier.InitializationComplete.mti());
if (simple) {
setOpenLcbMTI(MessageTypeIdentifier.InitializationCompleteSimple.mti());
} else {
setOpenLcbMTI(MessageTypeIdentifier.InitializationComplete.mti());
}
length=6;
byte[] val = nid.getContents();
data[0] = val[0];
Expand Down Expand Up @@ -335,9 +339,13 @@ boolean isVerifiedNID() {
return isOpenLcbMTI(MessageTypeIdentifier.VerifiedNodeId.mti());
}

void setVerifiedNID(NodeID nid) {
void setVerifiedNID(NodeID nid, boolean simple) {
init(nodeAlias);
setOpenLcbMTI(MessageTypeIdentifier.VerifiedNodeId.mti());
if (simple) {
setOpenLcbMTI(MessageTypeIdentifier.VerifiedNodeIdSimple.mti());
} else {
setOpenLcbMTI(MessageTypeIdentifier.VerifiedNodeId.mti());
}
length=6;
byte[] val = nid.getContents();
data[0] = val[0];
Expand Down
4 changes: 2 additions & 2 deletions test/org/openlcb/can/AliasMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void testAfterFrame() {
AliasMap map = new AliasMap();

OpenLcbCanFrame f = new OpenLcbCanFrame(0x123);
f.setInitializationComplete(0x123, new NodeID(new byte[]{0,1,2,3,4,5}));
f.setInitializationComplete(0x123, new NodeID(new byte[]{0,1,2,3,4,5}), false);
map.processFrame(f);
Assert.assertEquals("check NodeID", new NodeID(new byte[]{0,1,2,3,4,5}), map.getNodeID(0x123));
Assert.assertEquals("check alias", 0x123, map.getAlias(new NodeID(new byte[]{0,1,2,3,4,5})));
Expand Down Expand Up @@ -75,7 +75,7 @@ public void aliasAdded(NodeID id, int alias) {
found[0] = false;

OpenLcbCanFrame f = new OpenLcbCanFrame(a);
f.setInitializationComplete(a, nid);
f.setInitializationComplete(a, nid, false);
map.processFrame(f);

Assert.assertTrue(found[0]);
Expand Down
85 changes: 84 additions & 1 deletion test/org/openlcb/can/MessageBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ public void testInitializationCompleteMessage() {
testDecoding(m, list);
}

@Test
public void testInitializationCompleteSimpleMessage() {
Message m = new InitializationCompleteMessage(source, true);
MessageBuilder b = new MessageBuilder(map);

List<OpenLcbCanFrame> list = b.processMessage(m);

// looking for [19101123] 01 02 03 04 05 06

Assert.assertEquals("count", 1, list.size());
CanFrame f0 = list.get(0);
Assert.assertEquals("header", toHexString(0x19101123), toHexString(f0.getHeader()));
compareContent(source.getContents(), f0);

testDecoding(m, list);
}

@Test
public void testVerifyNodeIDNumberMessageEmpty() {
Message m = new VerifyNodeIDNumberGlobalMessage(source);
Expand Down Expand Up @@ -189,6 +206,23 @@ public void testVerifiedNodeIDNumberMessage() {
testDecoding(m, list);
}

@Test
public void testVerifiedNodeIDNumberSimpleMessage() {
Message m = new VerifiedNodeIDNumberMessage(source, true);
MessageBuilder b = new MessageBuilder(map);

List<OpenLcbCanFrame> list = b.processMessage(m);

// looking for [19171123] 01 02 03 04 05 06

Assert.assertEquals("count", 1, list.size());
CanFrame f0 = list.get(0);
Assert.assertEquals("header", toHexString(0x19171123), toHexString(f0.getHeader()));
compareContent(source.getContents(), f0);

testDecoding(m, list);
}

@Test
public void testProducerConsumerEventReportMessage() {
Message m = new ProducerConsumerEventReportMessage(source, event);
Expand Down Expand Up @@ -483,7 +517,7 @@ public void testDelayedMessage() {

// Now the verify node id comes back.
OpenLcbCanFrame frame = new OpenLcbCanFrame(0x555);
frame.setInitializationComplete(0x575, unknownDst);
frame.setInitializationComplete(0x575, unknownDst, false);

b.processFrame(frame);
map.processFrame(frame);
Expand Down Expand Up @@ -523,6 +557,23 @@ public void testInitializationCompleteFrame() {
Message msg = list.get(0);

Assert.assertTrue(msg instanceof InitializationCompleteMessage);
Assert.assertTrue(!((InitializationCompleteMessage)msg).hasSimpleProtocol() );
}

@Test
public void testInitializationCompleteSimpleFrame() {
OpenLcbCanFrame frame = new OpenLcbCanFrame(0x123);
frame.setHeader(0x19101123);

MessageBuilder b = new MessageBuilder(map);

List<Message> list = b.processFrame(frame);

Assert.assertEquals("count", 1, list.size());
Message msg = list.get(0);

Assert.assertTrue(msg instanceof InitializationCompleteMessage);
Assert.assertTrue(((InitializationCompleteMessage)msg).hasSimpleProtocol() );
}

@Test
Expand Down Expand Up @@ -573,6 +624,38 @@ public void testVerifyNodeContentFrame() {
Assert.assertEquals(new VerifyNodeIDNumberGlobalMessage(source, source), msg);
}

@Test
public void testVerifiedNodeFrame() {
OpenLcbCanFrame frame = new OpenLcbCanFrame(0x123);
frame.setHeader(0x19170123);

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 VerifiedNodeIDNumberMessage);
Assert.assertTrue(!((VerifiedNodeIDNumberMessage)msg).hasSimpleProtocol() );
}

@Test
public void testVerifiedNodeSimpleFrame() {
OpenLcbCanFrame frame = new OpenLcbCanFrame(0x123);
frame.setHeader(0x19171123);

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 VerifiedNodeIDNumberMessage);
Assert.assertTrue(((VerifiedNodeIDNumberMessage)msg).hasSimpleProtocol() );
}

@Test
public void testSingleFrameDatagram() {
OpenLcbCanFrame frame = new OpenLcbCanFrame(0x123);
Expand Down
2 changes: 1 addition & 1 deletion test/org/openlcb/can/OpenLcbCanFrameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void testGetTypeField(){
@Test
public void testInitializationComplete(){
OpenLcbCanFrame f = new OpenLcbCanFrame(0x123);
f.setInitializationComplete(0x123, new NodeID(new byte[]{0,1,2,3,4,5}));
f.setInitializationComplete(0x123, new NodeID(new byte[]{0,1,2,3,4,5}), false);
Assert.assertTrue("isIC", f.isInitializationComplete());
}

Expand Down

0 comments on commit 52e9473

Please sign in to comment.