Skip to content

Commit 90263ca

Browse files
committed
both uinput and out put tests
1 parent 2b22c86 commit 90263ca

File tree

1 file changed

+73
-43
lines changed

1 file changed

+73
-43
lines changed

test/java/src/junit/test/neuronrobotics/namespace/DyIONamespaceTest.java

Lines changed: 73 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
public class DyIONamespaceTest {
1818

19-
private static DyIO tester=null;
20-
private static DyIO target=null;
19+
private static DyIO harness=null;
20+
private static DyIO testDevice=null;
2121

2222
@Before
2323
public void setUp() throws Exception {
@@ -26,111 +26,141 @@ public void setUp() throws Exception {
2626

2727
SerialConnection testerConection = SerialConnection.getConnectionByMacAddress(new MACAddress("74:F7:26:80:00:7C"));
2828
assertTrue(testerConection!=null);
29-
tester = new DyIO(testerConection);
30-
tester.connect();
29+
harness = new DyIO(testerConection);
30+
harness.connect();
3131

3232
SerialConnection targetConection = SerialConnection.getConnectionByMacAddress(new MACAddress("74:F7:26:00:00:00"));
3333
assertTrue(targetConection!=null);
34-
targetConection.setSynchronusPacketTimeoutTime(5000);
35-
target = new DyIO(targetConection);
36-
target.connect();
34+
targetConection.setSynchronusPacketTimeoutTime(10000);
35+
testDevice = new DyIO(targetConection);
36+
testDevice.connect();
3737

3838

3939
}
4040

4141
@After
4242
public void shutdownDevices(){
43-
target.disconnect();
44-
if(tester!=null)
45-
tester.disconnect();
43+
44+
testDevice.disconnect();
45+
if(harness!=null)
46+
harness.disconnect();
4647
}
4748

4849
@Test public void DyIONameTest(){
4950

50-
if(!target.isAvailable())
51+
if(!testDevice.isAvailable())
5152
fail();
5253

53-
String name = target.getInfo();
54+
String name = testDevice.getInfo();
5455

5556
String setName;
5657
if(name.contains("My DyIO"))
5758
setName="My DyIO2";
5859
else
5960
setName="My DyIO";
6061

61-
target.setInfo(setName);
62+
testDevice.setInfo(setName);
6263

63-
String newName = target.getInfo();
64+
String newName = testDevice.getInfo();
6465

6566

66-
target.setInfo(name);
67+
testDevice.setInfo(name);
6768

6869
assertTrue(setName.contains(newName));
69-
assertTrue(name.contains(target.getInfo()));
70-
assertTrue(target.ping() );
70+
assertTrue(name.contains(testDevice.getInfo()));
71+
assertTrue(testDevice.ping() );
7172

7273
}
7374

7475
@Test public void DyIOPowerTest(){
75-
if(!target.isAvailable())
76+
if(!testDevice.isAvailable())
7677
fail();
77-
double volts = target.getBatteryVoltage(true);
78+
double volts = testDevice.getBatteryVoltage(true);
7879

79-
target.setServoPowerSafeMode(true);
80+
testDevice.setServoPowerSafeMode(true);
8081

8182

8283
}
8384

8485
@Test public void DyIOModesTest(){
85-
if(!target.isAvailable())
86+
if(!testDevice.isAvailable())
8687
fail();
8788

88-
ArrayList<DyIOChannelMode> modes = target.getAllChannelModes();
89+
ArrayList<DyIOChannelMode> modes = testDevice.getAllChannelModes();
8990
for(int i=0;i<modes.size();i++){
9091

9192
if(modes.get(i)==DyIOChannelMode.DIGITAL_IN){
9293
modes.set(i, DyIOChannelMode.DIGITAL_OUT);
9394
}else{
9495
modes.set(i, DyIOChannelMode.DIGITAL_IN);
9596
}
96-
target.setMode(i, modes.get(i));
97+
testDevice.setMode(i, modes.get(i));
9798
}
9899

99-
ArrayList<DyIOChannelMode> modesAfter = target.getAllChannelModes();
100+
ArrayList<DyIOChannelMode> modesAfter = testDevice.getAllChannelModes();
100101
for(int i=0;i<modes.size();i++){
101102
assertTrue(modes.get(i)==modesAfter.get(i));
102-
assertTrue(modes.get(i)==target.getMode(i));
103+
assertTrue(modes.get(i)==testDevice.getMode(i));
104+
}
105+
}
106+
@Test public void DyIOInputTest(){
107+
if(!testDevice.isAvailable() || harness == null)
108+
fail();
109+
int numPins = testDevice.getDyIOChannelCount();
110+
111+
//Test device as input
112+
for(int i=0;i<numPins;i++){
113+
if(!(i==16 || i==17)){
114+
int testerIndex = numPins-1-i;
115+
harness.setMode(testerIndex, DyIOChannelMode.DIGITAL_OUT);
116+
testDevice.setMode(i, DyIOChannelMode.DIGITAL_IN);
117+
118+
boolean state=true;
119+
for(int j=0;j<5;j++){
120+
int pinState = state?1:0;
121+
harness.setValue(testerIndex, pinState);
122+
int gotValue = testDevice.getValue(i);
123+
System.out.println(" Pin:"+i+" Tester:"+testerIndex+" setting to: "+pinState+" got:"+gotValue);
124+
assertTrue(gotValue==pinState);
125+
state = !state;
126+
}
127+
}
103128
}
129+
104130
}
105131

106-
@Test public void DyIOValuesTest(){
107-
if(!target.isAvailable() || tester == null)
132+
@Test public void DyIOOutputTest(){
133+
if(!testDevice.isAvailable() || harness == null)
108134
fail();
109-
int numPins = target.getDyIOChannelCount();
135+
int numPins = testDevice.getDyIOChannelCount();
136+
137+
//test device as output
110138
for(int i=0;i<numPins;i++){
111-
int testerIndex = numPins-1-i;
112-
tester.setMode(testerIndex, DyIOChannelMode.DIGITAL_OUT);
113-
target.setMode(i, DyIOChannelMode.DIGITAL_IN);
114-
115-
boolean state=true;
116-
for(int j=0;j<5;j++){
117-
int pinState = state?1:0;
118-
tester.setValue(testerIndex, pinState);
119-
int gotValue = target.getValue(i);
120-
System.out.println(" Pin:"+i+" Tester:"+testerIndex+" setting to: "+pinState+" got:"+gotValue);
121-
assertTrue(gotValue==pinState);
122-
state = !state;
139+
if(!(i==16 || i==17)){
140+
int testerIndex = numPins-1-i;
141+
harness.setMode(testerIndex, DyIOChannelMode.DIGITAL_IN);
142+
testDevice.setMode(i, DyIOChannelMode.DIGITAL_OUT);
143+
144+
boolean state=true;
145+
for(int j=0;j<5;j++){
146+
int pinState = state?1:0;
147+
testDevice.setValue(i, pinState);
148+
int gotValue = harness.getValue(testerIndex);
149+
System.out.println(" Pin:"+i+" Tester:"+testerIndex+" setting to: "+pinState+" got:"+gotValue);
150+
assertTrue(gotValue==pinState);
151+
state = !state;
152+
}
123153
}
124154
}
125155

126156
}
127157

128158
@Test
129159
public void dyioNamespaceTest() {
130-
if(!target.isAvailable())
160+
if(!testDevice.isAvailable())
131161
fail();
132-
assertTrue(target.hasNamespace("neuronrobotics.dyio.*"));
133-
target.getRevisions();
162+
assertTrue(testDevice.hasNamespace("neuronrobotics.dyio.*"));
163+
testDevice.getRevisions();
134164

135165
}
136166

0 commit comments

Comments
 (0)