-
Notifications
You must be signed in to change notification settings - Fork 331
/
SlotManagerTest.java
1308 lines (1125 loc) · 60.3 KB
/
SlotManagerTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package jmri.jmrix.loconet;
import jmri.ProgListener;
import jmri.ProgrammingMode;
import jmri.util.JUnitUtil;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.List;
/**
* @author B. Milhaupt, Copyright (C) 2018
*/
public class SlotManagerTest {
/**
* Local member to recall when a SlotListener has been invoked.
*/
private LocoNetSlot testSlot;
@Test
public void testGetDirectFunctionAddressOK() {
LocoNetMessage m1;
m1 = new LocoNetMessage(11);
m1.setElement(0, 0xED); // short 03 sets F9
m1.setElement(1, 0x0B);
m1.setElement(2, 0x7F);
m1.setElement(3, 0x24);
m1.setElement(4, 0x02);
m1.setElement(5, 0x03);
m1.setElement(6, 0x21);
m1.setElement(7, 0x00);
m1.setElement(8, 0x00);
m1.setElement(9, 0x00);
m1.setElement(10, 0x62);
Assert.assertEquals("short 3 sets F9", 3,
slotmanager.getDirectFunctionAddress(m1));
// test top half of short 65
m1 = new LocoNetMessage(new int[] {0xED, 0x0B, 0x7F, 0x24, 0x02, 0x42, 0x21, 0x00, 0x00, 0x23});
Assert.assertEquals("long 65 sets F9", 66,
slotmanager.getDirectFunctionAddress(m1));
m1 = new LocoNetMessage(11);
m1.setElement(0, 0xED); // long 513 sets F9
m1.setElement(1, 0x0B);
m1.setElement(2, 0x7F);
m1.setElement(3, 0x34);
m1.setElement(4, 0x05);
m1.setElement(5, 0x42);
m1.setElement(6, 0x01);
m1.setElement(7, 0x21);
m1.setElement(8, 0x00);
m1.setElement(9, 0x00);
m1.setElement(10, 0x35);
Assert.assertEquals("long 513 sets F9", 513,
slotmanager.getDirectFunctionAddress(m1));
//test mid high address 4097
m1 = new LocoNetMessage(new int[] {0xED, 0x0B, 0x7F, 0x34, 0x05, 0x50, 0x01, 0x21, 0x00, 0x00, 0x27});
Assert.assertEquals("long 4097 sets F9", 4097,
slotmanager.getDirectFunctionAddress(m1));
// test high high address 9983
m1 = new LocoNetMessage(new int[] {0xED, 0x0B, 0x7F, 0x34, 0x07, 0x66, 0x7F, 0x21, 0x00, 0x00, 0x6D});
Assert.assertEquals("long 9983 sets F9", 9983,
slotmanager.getDirectFunctionAddress(m1));
}
@Test
public void testGetDirectDccPacketOK() {
LocoNetMessage m1;
m1 = new LocoNetMessage(11);
m1.setElement(0, 0xED); // short 03 sets F9
m1.setElement(1, 0x0B);
m1.setElement(2, 0x7F);
m1.setElement(3, 0x24);
m1.setElement(4, 0x02);
m1.setElement(5, 0x03);
m1.setElement(6, 0x21);
m1.setElement(7, 0x00);
m1.setElement(8, 0x00);
m1.setElement(9, 0x00);
m1.setElement(10, 0x62);
Assert.assertEquals("short 3 sets F9", 0xA1,
slotmanager.getDirectDccPacket(m1));
// test top half of short 65
m1 = new LocoNetMessage(new int[] {0xED, 0x0B, 0x7F, 0x24, 0x02, 0x42, 0x21, 0x00, 0x00, 0x23});
Assert.assertEquals("long 65 sets F9", 0xA1,
slotmanager.getDirectDccPacket(m1));
m1 = new LocoNetMessage(11);
m1.setElement(0, 0xED); // long 513 sets F9
m1.setElement(1, 0x0B);
m1.setElement(2, 0x7F);
m1.setElement(3, 0x34);
m1.setElement(4, 0x05);
m1.setElement(5, 0x42);
m1.setElement(6, 0x01);
m1.setElement(7, 0x21);
m1.setElement(8, 0x00);
m1.setElement(9, 0x00);
m1.setElement(10, 0x35);
Assert.assertEquals("long 513 sets F9", 0xA1,
slotmanager.getDirectDccPacket(m1));
//test mid high address 4097
m1 = new LocoNetMessage(new int[] {0xED, 0x0B, 0x7F, 0x34, 0x05, 0x50, 0x01, 0x21, 0x00, 0x00, 0x27});
Assert.assertEquals("long 4097 sets F9", 0xA1,
slotmanager.getDirectDccPacket(m1));
// test high high address 9983
m1 = new LocoNetMessage(new int[] {0xED, 0x0B, 0x7F, 0x34, 0x07, 0x66, 0x7F, 0x21, 0x00, 0x00, 0x6D});
Assert.assertEquals("long 9983 sets F9", 0xA1,
slotmanager.getDirectDccPacket(m1));
}
@Test
public void testGetDirectFunctionAddressOK_F21_F28() {
LocoNetMessage m1;
m1 = new LocoNetMessage(new int[] {0xED, 0x0B, 0x7F, 0x34, 0x06, 0x03, 0x5F, 0x00, 0x00, 0x00, 0x08});
Assert.assertEquals("short 3 sets F28", 3,
slotmanager.getDirectFunctionAddress(m1));
// test top half of short 66
m1 = new LocoNetMessage(new int[] {0xED, 0x0B, 0x7F, 0x24, 0x02, 0x42, 0x21, 0x00, 0x00, 0x23});
Assert.assertEquals("long 66 sets F28", 66,
slotmanager.getDirectFunctionAddress(m1));
// address 3
m1 = new LocoNetMessage(new int[] {0xED, 0x0B, 0x7F, 0x44, 0x0D, 0x42, 0x01, 0x5F, 0x00, 0x00, 0x33});
Assert.assertEquals("long 513 sets F28", 513,
slotmanager.getDirectFunctionAddress(m1));
//test mid high address 4097
m1 = new LocoNetMessage(new int[] {0xED, 0x0B, 0x7F, 0x44, 0x0D, 0x50, 0x01, 0x5F, 0x00, 0x00, 0x21});
Assert.assertEquals("long 4097 sets F28", 4097,
slotmanager.getDirectFunctionAddress(m1));
// test high high address 9983
m1 = new LocoNetMessage(new int[] {0xED, 0x0B, 0x7F, 0x44, 0x0F, 0x66, 0x7F, 0x5F, 0x00, 0x00, 0x6B});
Assert.assertEquals("long 9983 sets F9", 9983,
slotmanager.getDirectFunctionAddress(m1));
}
@Test
public void testisExtFunctionMessage_F21_F28() {
LocoNetMessage m1;
m1 = new LocoNetMessage(new int[] {0xED, 0x0B, 0x7F, 0x34, 0x06, 0x03, 0x5F, 0x00, 0x00, 0x00, 0x08});
Assert.assertTrue("short 3 sets F28",slotmanager.isExtFunctionMessage(m1));
// test top half of short 66
m1 = new LocoNetMessage(new int[] {0xED, 0x0B, 0x7F, 0x24, 0x02, 0x42, 0x21, 0x00, 0x00, 0x23});
Assert.assertTrue("short 66 sets F28",slotmanager.isExtFunctionMessage(m1));
// address 3
m1 = new LocoNetMessage(new int[] {0xED, 0x0B, 0x7F, 0x44, 0x0D, 0x42, 0x01, 0x5F, 0x00, 0x00, 0x33});
Assert.assertTrue("short 513 sets F28",slotmanager.isExtFunctionMessage(m1));
//test mid high address 4097
m1 = new LocoNetMessage(new int[] {0xED, 0x0B, 0x7F, 0x44, 0x0D, 0x50, 0x01, 0x5F, 0x00, 0x00, 0x21});
Assert.assertTrue("short 4097 sets F28",slotmanager.isExtFunctionMessage(m1));
// test high high address 9983
m1 = new LocoNetMessage(new int[] {0xED, 0x0B, 0x7F, 0x44, 0x0F, 0x66, 0x7F, 0x5F, 0x7F, 0x00, 0x14});
Assert.assertTrue("short 9983 sets F28",slotmanager.isExtFunctionMessage(m1));
}
@Test
public void testGetSlotSend() {
testSlot = null;
SlotListener p2 = new SlotListener() {
@Override
public void notifyChangedSlot(LocoNetSlot l) {
testSlot = l;
}
};
slotmanager.slotFromLocoAddress(0x2134, p2);
Assert.assertEquals("slot request message",
"BF 42 34 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
Assert.assertEquals("hash length", 1, slotmanager.mLocoAddrHash.size());
Assert.assertEquals("key present", true,
slotmanager.mLocoAddrHash.containsKey(Integer.valueOf(0x2134)));
Assert.assertEquals("value present", true,
slotmanager.mLocoAddrHash.contains(p2));
}
@Test
public void testGetSlotRcv() {
testSlot = null;
SlotListener p2 = new SlotListener() {
@Override
public void notifyChangedSlot(LocoNetSlot l) {
testSlot = l;
}
};
slotmanager.slotFromLocoAddress(0x2134, p2);
// echo of the original message
LocoNetMessage m1 = new LocoNetMessage(4);
m1.setOpCode(0xBF);
m1.setElement(1, 0x42);
m1.setElement(2, 0x34);
slotmanager.message(m1);
// reply says its in slot 4
LocoNetMessage m2 = new LocoNetMessage(14);
m2.setElement(0, 0xE7);
m2.setElement(1, 0xE);
m2.setElement(2, 0xB);
m2.setElement(3, 3);
m2.setElement(4, 0x34);
m2.setElement(5, 0);
m2.setElement(6, 0);
m2.setElement(7, 4);
m2.setElement(8, 0);
m2.setElement(9, 0x42);
m2.setElement(10, 0);
m2.setElement(11, 0);
m2.setElement(12, 0);
m2.setElement(13, 0x6c);
slotmanager.message(m2);
Assert.assertEquals("returned slot", slotmanager.slot(11), testSlot);
// and make sure it forgets
testSlot = null;
slotmanager.message(m1);
slotmanager.message(m2);
Assert.assertEquals("returned slot", null, testSlot);
}
@Test
public void testReadCVPaged() throws jmri.ProgrammerException {
String CV1 = "12";
ProgListener p2 = null;
slotmanager.setMode(ProgrammingMode.PAGEMODE);
slotmanager.readCV(CV1, p2);
Assert.assertEquals("read message",
"EF 0E 7C 23 00 00 00 00 00 0B 00 7F 7F 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
}
@Test
public void testReadCVRegister() throws jmri.ProgrammerException {
String CV1 = "2";
ProgListener p2 = null;
slotmanager.setMode(ProgrammingMode.REGISTERMODE);
slotmanager.readCV(CV1, p2);
Assert.assertEquals("read message",
"EF 0E 7C 13 00 00 00 00 00 01 00 7F 7F 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
}
@Test
public void testReadCVDirect() throws jmri.ProgrammerException {
log.debug(".... start testReadCVDirect ...");
String CV1 = "29";
slotmanager.setMode(ProgrammingMode.DIRECTBYTEMODE);
slotmanager.readCV(CV1, lstn);
Assert.assertEquals("read message",
"EF 0E 7C 2B 00 00 00 00 00 1C 00 7F 7F 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
Assert.assertEquals("one message sent", 1, lnis.outbound.size());
Assert.assertEquals("initial status", -999, status);
// LACK received back (DCS240 sequence)
log.debug("send LACK back");
startedShortTimer = false;
startedLongTimer = false;
slotmanager.message(new LocoNetMessage(new int[]{0xB4, 0x6F, 0x01, 0x25}));
JUnitUtil.waitFor(()->{return startedLongTimer;},"startedLongTimer not set");
Assert.assertEquals("post-LACK status", -999, status);
Assert.assertTrue("started long timer", startedLongTimer);
Assert.assertFalse("didn't start short timer", startedShortTimer);
// read received back (DCS240 sequence)
value = 0;
log.debug("send E7 reply back");
slotmanager.message(new LocoNetMessage(new int[]{0xE7, 0x0E, 0x7C, 0x2B, 0x00, 0x00, 0x02, 0x47, 0x00, 0x1C, 0x23, 0x7F, 0x7F, 0x3B}));
JUnitUtil.waitFor(()->{return value == 35;},"value == 35 not set");
log.debug("checking..");
Assert.assertEquals("reply status", 0, status);
Assert.assertEquals("reply value", 35, value);
log.debug(".... end testReadCVDirect ...");
}
@Test
public void testReadCVOpsModeLong() throws jmri.ProgrammerException {
String CV1 = "12";
ProgListener p2 = null;
slotmanager.readCVOpsMode(CV1, p2, 4 * 128 + 0x23, true);
Assert.assertEquals("read message",
"EF 0E 7C 2F 00 04 23 00 00 0B 00 7F 7F 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
}
@Test
public void testReadCVOpsModeShort() throws jmri.ProgrammerException {
String CV1 = "12";
ProgListener p2 = null;
slotmanager.readCVOpsMode(CV1, p2, 22, false);
Assert.assertEquals("read message",
"EF 0E 7C 2F 00 00 16 00 00 0B 00 7F 7F 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
}
@Test
public void testWriteCVPaged() throws jmri.ProgrammerException {
String CV1 = "12";
int val2 = 34;
ProgListener p3 = null;
slotmanager.setMode(ProgrammingMode.PAGEMODE);
slotmanager.writeCV(CV1, val2, p3);
Assert.assertEquals("write message",
"EF 0E 7C 63 00 00 00 00 00 0B 22 7F 7F 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
}
@Test
public void testWriteCVRegister() throws jmri.ProgrammerException {
String CV1 = "2";
int val2 = 34;
ProgListener p3 = null;
slotmanager.setMode(ProgrammingMode.REGISTERMODE);
slotmanager.writeCV(CV1, val2, p3);
Assert.assertEquals("write message",
"EF 0E 7C 53 00 00 00 00 00 01 22 7F 7F 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
}
@Test
public void testWriteCVDirect() throws jmri.ProgrammerException {
String CV1 = "12";
int val2 = 34;
ProgListener p3 = null;
slotmanager.setMode(ProgrammingMode.DIRECTBYTEMODE);
slotmanager.writeCV(CV1, val2, p3);
Assert.assertEquals("write message",
"EF 0E 7C 6B 00 00 00 00 00 0B 22 7F 7F 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
}
@Test
public void testWriteCVDirectStringDCS240() throws jmri.ProgrammerException {
log.debug(".... start testWriteCVDirectStringDCS240 ...");
String CV1 = "31";
int val2 = 16;
slotmanager.setMode(ProgrammingMode.DIRECTBYTEMODE);
slotmanager.writeCV(CV1, val2, lstn);
Assert.assertEquals("one message sent", 1, lnis.outbound.size());
Assert.assertEquals("initial status", -999, status);
Assert.assertEquals("write message",
"EF 0E 7C 6B 00 00 00 00 00 1E 10 7F 7F 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
Assert.assertEquals("one message sent", 1, lnis.outbound.size());
Assert.assertEquals("initial status", -999, status);
// LACK received back (DCS240 sequence)
log.debug("send LACK back");
startedShortTimer = false;
startedLongTimer = false;
slotmanager.message(new LocoNetMessage(new int[]{0xB4, 0x6F, 0x01, 0x25}));
JUnitUtil.waitFor(()->{return startedShortTimer;},"startedShortTimer not set");
Assert.assertEquals("post-LACK status", -999, status);
Assert.assertTrue("started short timer", startedShortTimer);
Assert.assertFalse("didn't start long timer", startedLongTimer);
// read received back (DCS240 sequence)
value = -15;
log.debug("send E7 reply back");
slotmanager.message(new LocoNetMessage(new int[]{0xE7, 0x0E, 0x7C, 0x6B, 0x00, 0x00, 0x02, 0x47, 0x00, 0x1E, 0x10, 0x7F, 0x7F, 0x4A}));
Assert.assertEquals("no immediate reply", -999, status);
JUnitUtil.waitFor(()->{return value == -1;},"value == -1 not set");
log.debug("checking..");
Assert.assertEquals("reply status", 0, status);
Assert.assertEquals("reply value", -1, value);
log.debug(".... end testWriteCVDirectStringDCS240 ...");
}
@Test
public void testLackLogic() {
LocoNetMessage m = new LocoNetMessage(new int[]{0xB4, 0x6F, 0x01, 0x25});
Assert.assertTrue("checkLackTaskAccepted(m.getElement(2))", slotmanager.checkLackTaskAccepted(m.getElement(2)));
Assert.assertFalse("checkLackProgrammerBusy(m.getElement(2))", slotmanager.checkLackProgrammerBusy(m.getElement(2)));
Assert.assertFalse("checkLackAcceptedBlind(m.getElement(2))", slotmanager.checkLackAcceptedBlind(m.getElement(2)));
}
@Test
public void testWriteCVDirectStringDCS240Interrupted() throws jmri.ProgrammerException {
log.debug(".... start testWriteCVDirectStringDCS240 ...");
String CV1 = "31";
int val2 = 16;
slotmanager.setMode(ProgrammingMode.DIRECTBYTEMODE);
slotmanager.writeCV(CV1, val2, lstn);
Assert.assertEquals("one message sent", 1, lnis.outbound.size());
Assert.assertEquals("initial status", -999, status);
Assert.assertEquals("write message",
"EF 0E 7C 6B 00 00 00 00 00 1E 10 7F 7F 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
Assert.assertEquals("one message sent", 1, lnis.outbound.size());
Assert.assertEquals("initial status", -999, status);
// LACK received back (DCS240 sequence)
log.debug("send LACK back");
startedShortTimer = false;
startedLongTimer = false;
slotmanager.message(new LocoNetMessage(new int[]{0xB4, 0x6F, 0x01, 0x25}));
JUnitUtil.waitFor(()->{return startedShortTimer;},"startedShortTimer not set");
Assert.assertEquals("post-LACK status", -999, status);
Assert.assertTrue("started short timer", startedShortTimer);
Assert.assertFalse("didn't start long timer", startedLongTimer);
// CS check received back (DCS240 sequence)
log.debug("send CS check back");
slotmanager.message(new LocoNetMessage(new int[]{0xBB, 0x7F, 0x00, 0x3B}));
// not clear what to wait for here; status doesn't change
jmri.util.JUnitUtil.releaseThread(this, releaseTestDelay);
Assert.assertEquals("post-CS-check status", -999, status);
// read received back (DCS240 sequence)
log.debug("send E7 reply back");
slotmanager.message(new LocoNetMessage(new int[]{0xE7, 0x0E, 0x7C, 0x6B, 0x00, 0x00, 0x02, 0x47, 0x00, 0x1E, 0x10, 0x7F, 0x7F, 0x4A}));
Assert.assertEquals("no immediate reply", -999, status);
// not clear what to wait for here; content doesn't change
jmri.util.JUnitUtil.releaseThread(this, releaseTestDelay);
log.debug("checking..");
Assert.assertEquals("reply status", 0, status);
Assert.assertEquals("reply value", -1, value);
log.debug(".... end testWriteCVDirectStringDCS240 ...");
}
@Test
public void testWriteCVOpsLongAddr() throws jmri.ProgrammerException {
String CV1 = "12";
int val2 = 34;
ProgListener p3 = null;
slotmanager.writeCVOpsMode(CV1, val2, p3, 4 * 128 + 0x23, true);
Assert.assertEquals("one message sent", 1, lnis.outbound.size());
Assert.assertEquals("initial status", -999, status);
Assert.assertEquals("write message",
"EF 0E 7C 67 00 04 23 00 00 0B 22 7F 7F 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
}
@Test
public void testWriteCVOpsShortAddr() throws jmri.ProgrammerException {
String CV1 = "12";
int val2 = 34;
ProgListener p3 = null;
slotmanager.writeCVOpsMode(CV1, val2, p3, 22, false);
Assert.assertEquals("write message",
"EF 0E 7C 67 00 00 16 00 00 0B 22 7F 7F 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
}
@Test
public void testWriteThroughFacade() throws jmri.ProgrammerException {
log.debug(".... start testWriteThroughFacade ...");
slotmanager.setMode(ProgrammingMode.DIRECTBYTEMODE);
// install Facades from ESU_LokSoundV4_0.xml
// <name>High Access via Double Index</name>
String top = "256";
String addrCVhigh = "96";
String addrCVlow = "97";
String valueCV = "99";
String modulo = "100";
jmri.implementation.AddressedHighCvProgrammerFacade pf1
= new jmri.implementation.AddressedHighCvProgrammerFacade(slotmanager, top, addrCVhigh, addrCVlow, valueCV, modulo);
// <name>Indexed CV access</name>
String PI = "31";
String SI = "16";
boolean cvFirst = false;
jmri.implementation.MultiIndexProgrammerFacade pf2
= new jmri.implementation.MultiIndexProgrammerFacade(pf1, PI, SI, cvFirst, false);
String CV1 = "16.2.257";
int val2 = 55;
// Start overall sequence
pf2.writeCV(CV1, val2, lstn);
// Check for PI write
Assert.assertEquals("one message sent", 1, lnis.outbound.size());
Assert.assertEquals("initial status", -999, status);
Assert.assertEquals("write PI message",
"EF 0E 7C 6B 00 00 00 00 00 1E 10 7F 7F 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
Assert.assertEquals("one message sent", 1, lnis.outbound.size());
Assert.assertEquals("initial status", -999, status);
// LACK received back (DCS240 sequence) to PI write
log.debug("send LACK back");
startedShortTimer = false;
startedLongTimer = false;
slotmanager.message(new LocoNetMessage(new int[]{0xB4, 0x6F, 0x01, 0x25}));
JUnitUtil.waitFor(()->{return startedShortTimer;},"startedShortTimer not set");
Assert.assertEquals("post-LACK status", -999, status);
Assert.assertTrue("started short timer", startedShortTimer);
Assert.assertFalse("didn't start long timer", startedLongTimer);
jmri.util.JUnitUtil.releaseThread(this, releaseTestDelay); // wait for slow reply
Assert.assertEquals("still one message sent", 1, lnis.outbound.size());
Assert.assertEquals("initial status", -999, status);
// completion received back (DCS240 sequence) to PI write
log.debug("send E7 reply back");
slotmanager.message(new LocoNetMessage(new int[]{0xE7, 0x0E, 0x7C, 0x6B, 0x00, 0x00, 0x02, 0x47, 0x00, 0x1E, 0x10, 0x7F, 0x7F, 0x4A}));
Assert.assertEquals("no immediate reply", -999, status);
jmri.util.JUnitUtil.releaseThread(this, releaseTestDelay);
Assert.assertEquals("initial status", -999, status);
// check that SI write happened
Assert.assertEquals("two messages sent", 2, lnis.outbound.size());
Assert.assertEquals("write SI message",
"EF 0E 7C 6B 00 00 00 00 00 0F 02 7F 7F 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
Assert.assertEquals("initial status", -999, status);
// LACK received back (DCS240 sequence) to SI write
log.debug("send LACK back");
startedShortTimer = false;
startedLongTimer = false;
slotmanager.message(new LocoNetMessage(new int[]{0xB4, 0x6F, 0x01, 0x25}));
JUnitUtil.waitFor(()->{return startedShortTimer;},"startedShortTimer not set");
Assert.assertEquals("post-LACK status", -999, status);
Assert.assertTrue("started short timer", startedShortTimer);
Assert.assertFalse("didn't start long timer", startedLongTimer);
jmri.util.JUnitUtil.releaseThread(this, releaseTestDelay); // wait for slow reply
Assert.assertEquals("still two messages sent", 2, lnis.outbound.size());
// completion received back (DCS240 sequence) to SI write
log.debug("send E7 reply back");
slotmanager.message(new LocoNetMessage(new int[]{0xE7, 0x0E, 0x7C, 0x6B, 0x00, 0x00, 0x02, 0x47, 0x00, 0x0F, 0x02, 0x7F, 0x7F, 0x4A}));
Assert.assertEquals("no immediate reply", -999, status);
jmri.util.JUnitUtil.releaseThread(this, releaseTestDelay);
Assert.assertEquals("initial status", -999, status);
// check that final CV write happened
Assert.assertEquals("three messages sent", 3, lnis.outbound.size());
Assert.assertEquals("write final CV message",
"EF 0E 7C 6B 00 00 00 00 10 00 37 7F 7F 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
Assert.assertEquals("initial status", -999, status);
// LACK received back (DCS240 sequence) to final CV write
log.debug("send LACK back");
startedShortTimer = false;
startedLongTimer = false;
slotmanager.message(new LocoNetMessage(new int[]{0xB4, 0x6F, 0x01, 0x25}));
JUnitUtil.waitFor(()->{return startedShortTimer;},"startedShortTimer not set");
Assert.assertEquals("post-LACK status", -999, status);
Assert.assertTrue("started short timer", startedShortTimer);
Assert.assertFalse("didn't start long timer", startedLongTimer);
jmri.util.JUnitUtil.releaseThread(this, releaseTestDelay); // wait for slow reply
Assert.assertEquals("three messages sent", 3, lnis.outbound.size());
// completion received back (DCS240 sequence)
log.debug("send E7 reply back");
slotmanager.message(new LocoNetMessage(new int[]{0xE7, 0x0E, 0x7C, 0x6B, 0x00, 0x00, 0x02, 0x47, 0x10, 0x00, 0x37, 0x7F, 0x7F, 0x4A}));
Assert.assertEquals("no immediate reply", -999, status);
jmri.util.JUnitUtil.releaseThread(this, releaseTestDelay);
log.debug("checking..");
Assert.assertEquals("reply status", 0, status);
Assert.assertEquals("reply value", -1, value);
Assert.assertEquals("three messages sent", 3, lnis.outbound.size());
log.debug(".... end testWriteThroughFacade ...");
}
@Test
public void testReadThroughFacade() throws jmri.ProgrammerException {
log.debug(".... start testReadThroughFacade ...");
slotmanager.setMode(ProgrammingMode.DIRECTBYTEMODE);
// install Facades from ESU_LokSoundV4_0.xml
// <name>High Access via Double Index</name>
String top = "256";
String addrCVhigh = "96";
String addrCVlow = "97";
String valueCV = "99";
String modulo = "100";
jmri.implementation.AddressedHighCvProgrammerFacade pf1
= new jmri.implementation.AddressedHighCvProgrammerFacade(slotmanager, top, addrCVhigh, addrCVlow, valueCV, modulo);
// <name>Indexed CV access</name>
String PI = "31";
String SI = "16";
boolean cvFirst = false;
jmri.implementation.MultiIndexProgrammerFacade pf2
= new jmri.implementation.MultiIndexProgrammerFacade(pf1, PI, SI, cvFirst, false);
String CV1 = "16.2.257";
// Start overall sequence
pf2.readCV(CV1, lstn);
// Check for PI write
Assert.assertEquals("one message sent", 1, lnis.outbound.size());
Assert.assertEquals("initial status", -999, status);
Assert.assertEquals("write PI message",
"EF 0E 7C 6B 00 00 00 00 00 1E 10 7F 7F 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
Assert.assertEquals("one message sent", 1, lnis.outbound.size());
Assert.assertEquals("initial status", -999, status);
// LACK received back (DCS240 sequence) to PI write
log.debug("send LACK back");
startedShortTimer = false;
startedLongTimer = false;
slotmanager.message(new LocoNetMessage(new int[]{0xB4, 0x6F, 0x01, 0x25}));
jmri.util.JUnitUtil.releaseThread(this, releaseTestDelay);
Assert.assertEquals("post-LACK status", -999, status);
Assert.assertTrue("started short timer", startedShortTimer);
Assert.assertFalse("didn't start long timer", startedLongTimer);
jmri.util.JUnitUtil.releaseThread(this, releaseTestDelay); // wait for slow reply
Assert.assertEquals("still one message sent", 1, lnis.outbound.size());
Assert.assertEquals("initial status", -999, status);
// completion received back (DCS240 sequence) to PI write
log.debug("send E7 reply back");
slotmanager.message(new LocoNetMessage(new int[]{0xE7, 0x0E, 0x7C, 0x6B, 0x00, 0x00, 0x02, 0x47, 0x00, 0x1E, 0x10, 0x7F, 0x7F, 0x4A}));
Assert.assertEquals("no immediate reply", -999, status);
jmri.util.JUnitUtil.releaseThread(this, releaseTestDelay);
Assert.assertEquals("initial status", -999, status);
// check that SI write happened
Assert.assertEquals("two messages sent", 2, lnis.outbound.size());
Assert.assertEquals("write SI message",
"EF 0E 7C 6B 00 00 00 00 00 0F 02 7F 7F 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
Assert.assertEquals("initial status", -999, status);
// LACK received back (DCS240 sequence) to SI write
log.debug("send LACK back");
startedShortTimer = false;
startedLongTimer = false;
slotmanager.message(new LocoNetMessage(new int[]{0xB4, 0x6F, 0x01, 0x25}));
jmri.util.JUnitUtil.releaseThread(this, releaseTestDelay);
Assert.assertEquals("post-LACK status", -999, status);
Assert.assertTrue("started short timer", startedShortTimer);
Assert.assertFalse("didn't start long timer", startedLongTimer);
jmri.util.JUnitUtil.releaseThread(this, releaseTestDelay); // wait for slow reply
Assert.assertEquals("still two messages sent", 2, lnis.outbound.size());
// completion received back (DCS240 sequence) to SI write
log.debug("send E7 reply back");
slotmanager.message(new LocoNetMessage(new int[]{0xE7, 0x0E, 0x7C, 0x6B, 0x00, 0x00, 0x02, 0x47, 0x00, 0x0F, 0x02, 0x7F, 0x7F, 0x4A}));
Assert.assertEquals("no immediate reply", -999, status);
jmri.util.JUnitUtil.releaseThread(this, releaseTestDelay);
Assert.assertEquals("initial status", -999, status);
// check that final CV write happened
Assert.assertEquals("three messages sent", 3, lnis.outbound.size());
Assert.assertEquals("write final CV message",
"EF 0E 7C 2B 00 00 00 00 10 00 00 7F 7F 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
Assert.assertEquals("initial status", -999, status);
// LACK received back (DCS240 sequence) to final CV write
log.debug("send LACK back");
startedShortTimer = false;
startedLongTimer = false;
slotmanager.message(new LocoNetMessage(new int[]{0xB4, 0x6F, 0x01, 0x25}));
jmri.util.JUnitUtil.releaseThread(this, releaseTestDelay);
Assert.assertEquals("post-LACK status", -999, status);
Assert.assertTrue("started long timer", startedLongTimer);
Assert.assertFalse("didn't start short timer", startedShortTimer);
jmri.util.JUnitUtil.releaseThread(this, releaseTestDelay); // wait for slow reply
Assert.assertEquals("three messages sent", 3, lnis.outbound.size());
// completion received back (DCS240 sequence)
log.debug("send E7 reply back");
slotmanager.message(new LocoNetMessage(new int[]{0xE7, 0x0E, 0x7C, 0x6B, 0x00, 0x00, 0x02, 0x47, 0x10, 0x00, 0x37, 0x7F, 0x7F, 0x4A}));
Assert.assertEquals("no immediate reply", -999, status);
jmri.util.JUnitUtil.releaseThread(this, releaseTestDelay);
log.debug("checking..");
Assert.assertEquals("reply status", 0, status);
Assert.assertEquals("reply value", 55, value);
Assert.assertEquals("three messages sent", 3, lnis.outbound.size());
log.debug(".... end testReadThroughFacade ...");
}
@Test
public void testReadThroughFacadeFail() throws jmri.ProgrammerException {
log.debug(".... start testReadThroughFacadeFail ...");
slotmanager.setMode(ProgrammingMode.DIRECTBYTEMODE);
// install Facades from ESU_LokSoundV4_0.xml
// <name>High Access via Double Index</name>
String top = "256";
String addrCVhigh = "96";
String addrCVlow = "97";
String valueCV = "99";
String modulo = "100";
jmri.implementation.AddressedHighCvProgrammerFacade pf1
= new jmri.implementation.AddressedHighCvProgrammerFacade(slotmanager, top, addrCVhigh, addrCVlow, valueCV, modulo);
// <name>Indexed CV access</name>
String PI = "31";
String SI = "16";
boolean cvFirst = false;
jmri.implementation.MultiIndexProgrammerFacade pf2
= new jmri.implementation.MultiIndexProgrammerFacade(pf1, PI, SI, cvFirst, false);
String CV1 = "16.2.257";
// Start overall sequence
pf2.readCV(CV1, lstn);
// Check for PI write
Assert.assertEquals("one message sent", 1, lnis.outbound.size());
Assert.assertEquals("initial status", -999, status);
Assert.assertEquals("write PI message",
"EF 0E 7C 6B 00 00 00 00 00 1E 10 7F 7F 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
Assert.assertEquals("one message sent", 1, lnis.outbound.size());
Assert.assertEquals("initial status", -999, status);
// LACK received back (DCS240 sequence) to PI write: rejected
log.debug("send LACK back");
startedShortTimer = false;
startedLongTimer = false;
slotmanager.message(new LocoNetMessage(new int[]{0xB4, 0x6F, 0x0, 0x24}));
jmri.util.JUnitUtil.releaseThread(this, releaseTestDelay);
Assert.assertEquals("post-LACK status is fail", 4, status);
Assert.assertFalse("didn't start short timer", startedShortTimer);
Assert.assertFalse("didn't start long timer", startedLongTimer);
jmri.util.JUnitUtil.releaseThread(this, releaseTestDelay); // wait for slow reply
Assert.assertEquals("still one message sent", 1, lnis.outbound.size());
log.debug(".... end testReadThroughFacadeFail ...");
}
@Test
public void testGetProgrammingModes() {
List<ProgrammingMode> l = slotmanager.getSupportedModes();
Assert.assertEquals("programming mode list length ok", 5, l.size());
Assert.assertEquals("programming mode 0", ProgrammingMode.DIRECTBYTEMODE, l.get(0));
Assert.assertEquals("programming mode 1", ProgrammingMode.PAGEMODE, l.get(1));
Assert.assertEquals("programming mode 2", ProgrammingMode.REGISTERMODE, l.get(2));
Assert.assertEquals("programming mode 3", ProgrammingMode.ADDRESSMODE, l.get(3));
Assert.assertEquals("programming mode 4", "LOCONETCSOPSWMODE", l.get(4).getStandardName());
}
@Test
public void testSendPacket() {
byte msg[] = jmri.NmraPacket.accDecPktOpsMode(1, 4, 53);
slotmanager.sendPacket(msg, 1);
Assert.assertEquals("nmra packet 1",
"ED 0B 7F 50 07 01 70 6C 03 35 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
msg = jmri.NmraPacket.accDecPktOpsMode(128, 4, 53);
slotmanager.sendPacket(msg, 2);
Assert.assertEquals("nmra packet 2",
"ED 0B 7F 51 07 00 50 6C 03 35 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
msg= jmri.NmraPacket.accDecPktOpsMode(256, 4, 53);
slotmanager.sendPacket(msg, 3);
Assert.assertEquals("nmra packet 3",
"ED 0B 7F 52 07 00 30 6C 03 35 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
msg = jmri.NmraPacket.accDecPktOpsMode(1, 37, 53);
slotmanager.sendPacket(msg, 4);
Assert.assertEquals("nmra packet 4",
"ED 0B 7F 53 07 01 70 6C 24 35 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
msg = jmri.NmraPacket.accDecPktOpsMode(1, 129, 53);
slotmanager.sendPacket(msg, 5);
Assert.assertEquals("nmra packet 5",
"ED 0B 7F 54 0F 01 70 6C 00 35 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
msg = jmri.NmraPacket.accDecPktOpsMode(1, 10, 0);
slotmanager.sendPacket(msg, 6);
Assert.assertEquals("nmra packet 6",
"ED 0B 7F 55 07 01 70 6C 09 00 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
msg = jmri.NmraPacket.accDecPktOpsMode(1, 10, 128);
slotmanager.sendPacket(msg, 7);
Assert.assertEquals("nmra packet 7",
"ED 0B 7F 56 17 01 70 6C 09 00 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
msg = jmri.NmraPacket.accDecPktOpsMode(1, 10, 255);
slotmanager.sendPacket(msg, 8);
Assert.assertEquals("nmra packet 8",
"ED 0B 7F 57 17 01 70 6C 09 7F 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
msg = jmri.NmraPacket.accDecPktOpsMode(511, 255, 0);
slotmanager.sendPacket(msg, 9);
jmri.util.JUnitAppender.assertWarnMessage("Ops Mode Accessory Packet 'Send count' reduced from 9 to 8.");
Assert.assertEquals("nmra packet 9",
"ED 0B 7F 57 0F 3F 00 6C 7E 00 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
msg = jmri.NmraPacket.accSignalDecoderPkt(1, 31);
slotmanager.sendPacket(msg, 0);
jmri.util.JUnitAppender.assertWarnMessage("Ops Mode Accessory Packet 'Send count' of 0 is illegal and is forced to 1.");
Assert.assertEquals("nmra packet 10",
"ED 0B 7F 30 01 01 71 1F 00 00 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
msg = jmri.NmraPacket.accSignalDecoderPkt(2, 30);
slotmanager.sendPacket(msg, -1);
jmri.util.JUnitAppender.assertWarnMessage("Ops Mode Accessory Packet 'Send count' of -1 is illegal and is forced to 1.");
Assert.assertEquals("nmra packet 10",
"ED 0B 7F 30 01 01 73 1E 00 00 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
msg = jmri.NmraPacket.accSignalDecoderPkt(4, 29);
slotmanager.sendPacket(msg, 3);
Assert.assertEquals("nmra packet 10",
"ED 0B 7F 32 01 01 77 1D 00 00 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
msg = jmri.NmraPacket.accSignalDecoderPkt(8, 27);
slotmanager.sendPacket(msg, 2);
Assert.assertEquals("nmra packet 10",
"ED 0B 7F 31 01 02 77 1B 00 00 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
msg = jmri.NmraPacket.accSignalDecoderPkt(16, 23);
slotmanager.sendPacket(msg, 2);
Assert.assertEquals("nmra packet 10",
"ED 0B 7F 31 01 04 77 17 00 00 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
msg = jmri.NmraPacket.accSignalDecoderPkt(32, 15);
slotmanager.sendPacket(msg, 2);
Assert.assertEquals("nmra packet 10",
"ED 0B 7F 31 01 08 77 0F 00 00 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
msg = jmri.NmraPacket.accSignalDecoderPkt(64, 1);
slotmanager.sendPacket(msg, 2);
Assert.assertEquals("nmra packet 10",
"ED 0B 7F 31 01 10 77 01 00 00 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
msg = jmri.NmraPacket.accSignalDecoderPkt(128, 0);
slotmanager.sendPacket(msg, 2);
Assert.assertEquals("nmra packet 10",
"ED 0B 7F 31 01 20 77 00 00 00 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
msg = jmri.NmraPacket.accSignalDecoderPkt(256, 2);
slotmanager.sendPacket(msg, 2);
Assert.assertEquals("nmra packet 10",
"ED 0B 7F 31 01 00 67 02 00 00 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
msg = jmri.NmraPacket.accSignalDecoderPkt(512, 4);
slotmanager.sendPacket(msg, 2);
Assert.assertEquals("nmra packet 10",
"ED 0B 7F 31 01 00 57 04 00 00 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
msg = jmri.NmraPacket.accSignalDecoderPkt(1024, 8);
slotmanager.sendPacket(msg, 2);
Assert.assertEquals("nmra packet 10",
"ED 0B 7F 31 01 00 37 08 00 00 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
msg = jmri.NmraPacket.accSignalDecoderPkt(511, 16);
slotmanager.sendPacket(msg, 2);
Assert.assertEquals("nmra packet 10",
"ED 0B 7F 31 01 00 55 10 00 00 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
}
@Test
public void testOpcImmPacketRetry() {
byte msg[] = jmri.NmraPacket.accDecPktOpsMode(1, 4, 54);
slotmanager.sendPacket(msg, 1);
Assert.assertEquals("nmra packet 1 retry test",
"ED 0B 7F 50 07 01 70 6C 03 36 00",
lnis.outbound.elementAt(0).toString());
slotmanager.message(lnis.outbound.get(0));
Assert.assertNotNull("check immedPacket non null", slotmanager.immedPacket);
Assert.assertEquals("check that slotmanager remembers last opc_imm_packet (1)",
new LocoNetMessage(new int[]{0xED, 0x0B, 0x7F, 0x50, 0x07, 0x01, 0x70, 0x6C, 0x03, 0x36, 0x00}),
slotmanager.immedPacket);
slotmanager.message(new LocoNetMessage(new int[] {0xB4, 0x6D, 0x00, 0x00}));
JUnitUtil.waitFor(()->{return lnis.outbound.size() >1;},"retry message");
Assert.assertEquals("retry test two messages sent", 2, lnis.outbound.size());
Assert.assertEquals("nmra packet 2 retry test",
"ED 0B 7F 50 07 01 70 6C 03 36 00",
lnis.outbound.elementAt(1).toString());
msg = jmri.NmraPacket.accDecPktOpsMode(1, 4, 55);
slotmanager.sendPacket(msg, 1);
Assert.assertEquals("nmra packet 2 retry test",
"ED 0B 7F 50 07 01 70 6C 03 37 00",
lnis.outbound.elementAt(2).toString());
Assert.assertEquals("retry test two messages sent", 3, lnis.outbound.size());
slotmanager.message(lnis.outbound.get(2));
Assert.assertEquals("check that slotmanager remembers last opc_imm_packet (2)",
new LocoNetMessage(new int[]{0xED, 0x0B, 0x7F, 0x50, 0x07, 0x01, 0x70, 0x6C, 0x03, 0x37, 0x00}),
slotmanager.immedPacket);
slotmanager.message(new LocoNetMessage(new int[] {0xB4, 0x6D, 0x01, 0x00}));
Assert.assertEquals("retry test two (b) no new message sent", 3, lnis.outbound.size());
msg = jmri.NmraPacket.accDecPktOpsMode(1, 4, 56);
slotmanager.sendPacket(msg, 1);
Assert.assertEquals("nmra packet 3 retry test",
"ED 0B 7F 50 07 01 70 6C 03 38 00",
lnis.outbound.elementAt(3).toString());
Assert.assertEquals("retry test three (a) messages sent", 4, lnis.outbound.size());
slotmanager.message(lnis.outbound.get(3));
Assert.assertEquals("check that slotmanager remembers last opc_imm_packet (3)",
new LocoNetMessage(new int[]{0xED, 0x0B, 0x7F, 0x50, 0x07, 0x01, 0x70, 0x6C, 0x03, 0x38, 0x00}),
slotmanager.immedPacket);
slotmanager.message(new LocoNetMessage(new int[] {0xB4, 0x6C, 0x00, 0x00}));
Assert.assertEquals("retry test three no new message sent", 4, lnis.outbound.size());
msg = jmri.NmraPacket.accDecPktOpsMode(1, 4, 57);
slotmanager.sendPacket(msg, 1);
Assert.assertEquals("nmra packet 4 retry test",
"ED 0B 7F 50 07 01 70 6C 03 39 00",
lnis.outbound.elementAt(4).toString());
Assert.assertEquals("retry test four (a) messages sent", 5, lnis.outbound.size());
slotmanager.message(lnis.outbound.get(4));
Assert.assertEquals("check that slotmanager remembers last opc_imm_packet (4)",
new LocoNetMessage(new int[]{0xED, 0x0B, 0x7F, 0x50, 0x07, 0x01, 0x70, 0x6C, 0x03, 0x39, 0x00}),
slotmanager.immedPacket);
jmri.util.JUnitUtil.waitFor(500); // wait 1/2 second to ensure a retry does not happen.
Assert.assertEquals("retry test four (b) messages sent", 5, lnis.outbound.size());
slotmanager.message(new LocoNetMessage(new int[] {0xB3, 0x6d, 0x00, 0x00}));
Assert.assertEquals("check mTurnoutNoRetry", false, slotmanager.mTurnoutNoRetry);
slotmanager.setThrottledTransmitter(null, true);
Assert.assertEquals("check mTurnoutNoRetry (2)", true, slotmanager.mTurnoutNoRetry);
msg = jmri.NmraPacket.accDecPktOpsMode(1, 4, 33);
slotmanager.sendPacket(msg, 1);
Assert.assertEquals("nmra packet 5 retry test",
"ED 0B 7F 50 07 01 70 6C 03 21 00",
lnis.outbound.elementAt(5).toString());
Assert.assertEquals("retry test five (a) messages sent", 6, lnis.outbound.size());
slotmanager.message(lnis.outbound.get(5));
Assert.assertEquals("check that slotmanager remembers last opc_imm_packet (5)",
new LocoNetMessage(new int[]{0xED, 0x0B, 0x7F, 0x50, 0x07, 0x01, 0x70, 0x6C, 0x03, 0x21, 0x00}),
slotmanager.immedPacket);
slotmanager.message(new LocoNetMessage(new int[] {0xB4, 0x6C, 0x00, 0x00}));
jmri.util.JUnitUtil.waitFor(500); // wait 1/2 second to ensure a retry does not happen.
Assert.assertEquals("retry test five (b) messages sent", 6, lnis.outbound.size());
}
@Test
public void testSlotMessageOpcPktImmFunctions() {
testSlot = null;
SlotListener p2 = new SlotListener() {
@Override
public void notifyChangedSlot(LocoNetSlot l) {
testSlot = l;
}
};
slotmanager.slotFromLocoAddress(4121, p2);
Assert.assertEquals("number of transmitted messages so far (a)", 1, lnis.outbound.size());
Assert.assertEquals("slot request message",
"BF 20 19 00",
lnis.outbound.elementAt(lnis.outbound.size() - 1).toString());
Assert.assertEquals("hash length", 1, slotmanager.mLocoAddrHash.size());
Assert.assertEquals("key present", true,
slotmanager.mLocoAddrHash.containsKey(Integer.valueOf(4121)));
Assert.assertEquals("value present", true,
slotmanager.mLocoAddrHash.contains(p2));
Assert.assertNull("check testSlot still null (a)", testSlot);
// reflect the transmitted message back to the slot manager
slotmanager.message(lnis.outbound.elementAt(lnis.outbound.size()-1));
// reply says its in slot 10
LocoNetMessage m2 = new LocoNetMessage(14);
m2.setElement(0, 0xE7);
m2.setElement(1, 0x0E);
m2.setElement(2, 0x0A); // slot 10
m2.setElement(3, 3);
m2.setElement(4, 0x19);
m2.setElement(5, 0);
m2.setElement(6, 0);
m2.setElement(7, 4);