Skip to content

Commit

Permalink
Send AMD at end of alias sequence (#224)
Browse files Browse the repository at this point in the history
Fix for #121.

===

* Send AMD at end of alias sequence

* fix complete, AMD sending in timeout

* test for complete state updated
  • Loading branch information
bobjacobsen authored Aug 22, 2023
1 parent 09ccef4 commit 0e32ff1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/org/openlcb/can/NIDaAlgorithm.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* to and from the actual interface.
* It also requires subclassing to provide a timer function.
*
* @author Bob Jacobsen Copyright 2009, 2010
* @author Bob Jacobsen Copyright 2009, 2010, 2023
*/
public class NIDaAlgorithm implements CanFrameListener {
/// Callback to invoke when the alias was successfully reserved.
Expand Down Expand Up @@ -70,6 +70,9 @@ public OpenLcbCanFrame nextFrame() {
} else if (index == 4) {
f = new OpenLcbCanFrame(nida.getNIDa());
f.setRIM(nida.getNIDa());
} else if (index == 5) {
f = new OpenLcbCanFrame(nida.getNIDa());
f.setAMD(nida.getNIDa(), nid);
complete = true;
} else {
// send nothing
Expand Down Expand Up @@ -148,6 +151,7 @@ protected void timerExpired() {
}
scheduleTimer(200);
} else if (index == 4) {
sendInterface.send(nextFrame());
sendInterface.send(nextFrame());
if (done != null) {
done.run();
Expand Down
17 changes: 14 additions & 3 deletions test/org/openlcb/can/NIDaAlgorithmTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,18 @@ public void testFirst() {
}

@Test
public void testFifth() {
public void testSixth() {
Assert.assertTrue("not complete", !alg.isComplete());

// seventh frame is RIM
// fifth frame is RIM
Assert.assertTrue(alg.nextFrame().isCIM());
Assert.assertTrue(alg.nextFrame().isCIM());
Assert.assertTrue(alg.nextFrame().isCIM());
Assert.assertTrue(alg.nextFrame().isCIM());
Assert.assertTrue(alg.nextFrame().isRIM());

Assert.assertNotEquals(alg.nextFrame(), null); // AMD frame

Assert.assertTrue("complete", alg.isComplete());

Assert.assertEquals(alg.nextFrame(), null);
Expand Down Expand Up @@ -94,6 +96,9 @@ public void testNotAConflict() {
alg.processFrame(t);
Assert.assertTrue(alg.nextFrame().isRIM());

// sixth is AMD
Assert.assertNotEquals((alg.nextFrame()), null);

Assert.assertTrue("complete", alg.isComplete());

Assert.assertEquals(alg.nextFrame(), null);
Expand Down Expand Up @@ -130,6 +135,9 @@ public void testConflictAfterOne() {
f = alg.nextFrame();
Assert.assertTrue(f.isRIM());

// sixth is AMD
Assert.assertNotEquals((f = alg.nextFrame()), null);

Assert.assertTrue("complete", alg.isComplete());

Assert.assertEquals((f = alg.nextFrame()), null);
Expand Down Expand Up @@ -157,6 +165,9 @@ public void testLatecomerConflict() {
f = alg.nextFrame();
Assert.assertTrue(f.isRIM());

// sixth is AMD
Assert.assertNotEquals((f = alg.nextFrame()), null);

int nida = f.getSourceAlias();
Assert.assertTrue("complete", alg.isComplete());

Expand Down Expand Up @@ -188,7 +199,7 @@ public void testSequentialStart2() {
alg1.nextFrame();
alg1.nextFrame();

int expectedCount = 5;
int expectedCount = 6;
int count = sequentialRunner(new NIDaAlgorithm[]{alg1, alg2}, expectedCount);

debug("tSS2 converges " + count);
Expand Down

0 comments on commit 0e32ff1

Please sign in to comment.