blob: 17d9bd787647db7a2a898259dc2d3136b799da6f (
plain)
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
|
package net.tuschhcm.routercontrol.router;
import java.io.PrintStream;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
/**
* Router implementation for a ShinyBow SB-5544
*
*/
public class ShinyBow5544Router implements Router {
private final SerialPort mSerialPort;
private final PrintStream mOut;
/**
* Create a new ShinyBow router using the given comm port.
*
* @param portName Com port name
*/
public ShinyBow5544Router(final String portName) {
try {
CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(portName);
// 9600 baud, 8 bit, no parity, 1 stop bit
mSerialPort = (SerialPort) portId.open("routercontrol", 1000);
mSerialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
mOut = new PrintStream(mSerialPort.getOutputStream());
} catch (Exception e) {
throw new IllegalArgumentException("Unable to open serial port: " + e.getMessage(), e);
}
}
@Override
public void switchInput(int output, int input)
throws IllegalArgumentException {
if (output < 1 || output > 4) {
throw new IllegalArgumentException("Invalid Output");
}
if (input < 1 || input > 4) {
throw new IllegalArgumentException("Invalid Input");
}
mOut.format("SBI0%dO0%d", output, input);
}
@Override
public void setPower(boolean on) {
if (on) {
mOut.print("SBSYSMON");
} else {
mOut.print("SBSYSMOF");
}
}
@Override
public void setLockControls(boolean enabled) {
if (enabled) {
mOut.print("SBSYSMLK");
} else {
mOut.print("SBSYSMUK");
}
}
@Override
public void close() {
mOut.close();
mSerialPort.close();
}
}
|