1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.indi.examples;
20
21 import java.io.IOException;
22
23 import org.indi.clientmessages.GetProperties;
24 import org.indi.objects.Permission;
25 import org.indi.objects.State;
26 import org.indi.objects.Switch;
27 import org.indi.objects.SwitchRule;
28 import org.indi.objects.SwitchVector;
29 import org.indi.server.BasicDevice;
30 import org.indi.server.IndiServer;
31
32
33
34
35
36
37
38 public class SimpleDevice extends BasicDevice {
39
40
41
42 private final SwitchVector powerswitch;
43
44
45
46 private final String vectorname = "CONNECTION";
47
48
49
50 private Switch connectswitch = null;
51
52
53
54 private final String name = "Simple Device";
55
56
57
58
59
60
61
62 public SimpleDevice(IndiServer server) {
63 super(server);
64 this.powerswitch = new SwitchVector(this.name, this.vectorname,
65 "Connection", "Main Control", State.Idle, Permission.ReadWrite,
66 SwitchRule.OneOfMany, 0);
67 this.connectswitch = new Switch("CONNECT", "Connect", Switch.State.Off);
68 this.powerswitch.add(this.connectswitch);
69 this.powerswitch.add(new Switch("DISCONNECT", "Disconnect",
70 Switch.State.On));
71 }
72
73 @Override
74 public void onGetProperties(GetProperties o) {
75 def(this.powerswitch);
76 }
77
78 @Override
79 public void onNew(SwitchVector vector) {
80 if ((this.vectorname.equals(vector.getName()))
81 && (this.name.equals(vector.getDevice()))) {
82 this.powerswitch.update(vector);
83 }
84 switch (this.connectswitch.getState()) {
85 case On:
86 this.powerswitch.setState(State.Ok);
87 set(this.powerswitch, "Connection to Simple Device is successful.");
88 break;
89 case Off:
90 this.powerswitch.setState(State.Idle);
91 set(this.powerswitch, "Simple Device has been disconneced.");
92 break;
93 }
94 }
95
96
97
98
99
100 public static void main(String[] args) throws IOException {
101 IndiServer s = new IndiServer();
102 new SimpleDevice(s);
103 while (true) {
104 s.reactor.handleEvents(10);
105 }
106 }
107
108 }