tabbing
[iotcloud.git] / version2 / src / java / light_fan_embed_benchmark / LightsController.java
1 import iotcloud.*;
2 import java.util.*;
3
4 class LightsController {
5
6     public static void main(String[] args) throws Exception {
7
8
9         // Bulb 1
10         byte[] bulbMacAdd1 = new byte[8];
11         bulbMacAdd1[0] = (byte)0xD0;
12         bulbMacAdd1[1] = (byte)0x73;
13         bulbMacAdd1[2] = (byte)0xD5;
14         bulbMacAdd1[3] = (byte)0x11;
15         bulbMacAdd1[4] = (byte)0x42;
16         bulbMacAdd1[5] = (byte)0xE5;
17         bulbMacAdd1[6] = (byte)0x00;
18         bulbMacAdd1[7] = (byte)0x00;
19
20         IoTDeviceAddress devAddr1 = new IoTDeviceAddress("192.168.2.216", 56700, 56700, false, false);
21         IoTUDP udp1 = new IoTUDP(devAddr1);
22         LightBulb bulb1 = new LifxLightBulb(udp1, bulbMacAdd1);
23
24
25
26         byte[] bulbMacAdd2 = new byte[8];
27         bulbMacAdd2[0] = (byte)0xD0;
28         bulbMacAdd2[1] = (byte)0x73;
29         bulbMacAdd2[2] = (byte)0xD5;
30         bulbMacAdd2[3] = (byte)0x12;
31         bulbMacAdd2[4] = (byte)0x8E;
32         bulbMacAdd2[5] = (byte)0x30;
33         bulbMacAdd2[6] = (byte)0x00;
34         bulbMacAdd2[7] = (byte)0x00;
35
36         IoTDeviceAddress devAddr2 = new IoTDeviceAddress("192.168.2.126", 56701, 56700, false, false);
37         IoTUDP udp2 = new IoTUDP(devAddr2);
38         LightBulb bulb2 = new LifxLightBulb(udp2, bulbMacAdd2);
39
40
41
42         byte[] bulbMacAdd3 = new byte[8];
43         bulbMacAdd3[0] = (byte)0xD0;
44         bulbMacAdd3[1] = (byte)0x73;
45         bulbMacAdd3[2] = (byte)0xD5;
46         bulbMacAdd3[3] = (byte)0x02;
47         bulbMacAdd3[4] = (byte)0x41;
48         bulbMacAdd3[5] = (byte)0xDA;
49         bulbMacAdd3[6] = (byte)0x00;
50         bulbMacAdd3[7] = (byte)0x00;
51
52         IoTDeviceAddress devAddr3 = new IoTDeviceAddress("192.168.2.232", 56702, 56700, false, false);
53         IoTUDP udp3 = new IoTUDP(devAddr3);
54         LightBulb bulb3 = new LifxLightBulb(udp3, bulbMacAdd3);
55
56
57         List<LightBulb> bulbs = new ArrayList<LightBulb>();
58         bulbs.add(bulb1);
59         bulbs.add(bulb2);
60         bulbs.add(bulb3);
61
62
63         String a1 = "bulb1";
64         String a2 = "bulb2";
65         String a3 = "bulb3";
66
67         IoTString ia1 = new IoTString(a1);
68         IoTString ia2 = new IoTString(a2);
69         IoTString ia3 = new IoTString(a3);
70
71
72         List<IoTString> keys = new ArrayList<IoTString>();
73         keys.add(ia1);
74         keys.add(ia2);
75         keys.add(ia3);
76
77
78         String valueA = "on";
79         IoTString iValueA = new IoTString(valueA);
80
81
82         String pingTimerKey = "bulbController";
83         IoTString ipingTimerKey = new IoTString(pingTimerKey);
84
85
86
87         System.out.println("Starting System");
88         int counter = 0;
89
90
91         Table t1 = null;
92         try {
93             t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 321, 6000);
94             t1.addLocalCommunication(1000, "192.168.2.50", 6001);
95
96             t1.rebuild();
97         } catch (Error e) {
98
99             e.printStackTrace();
100             for (int i = 0; i < 3; i++) {
101                 bulbs.get(i).setColor(0, 100, 100);
102             }
103
104
105
106             while (true) {
107                 for (int i = 0; i < 3; i++) {
108                     bulbs.get(i).turnOff();
109                 }
110                 Thread.sleep(1000);
111
112                 for (int i = 0; i < 3; i++) {
113                     bulbs.get(i).turnOn();
114                 }
115                 Thread.sleep(1000);
116             }
117         }
118
119
120
121
122         // Table t2 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 400, -1);
123         // t2.rebuild();
124
125
126         while (true) {
127
128             try {
129
130                 System.out.println("Loop");
131
132                 String pingTimer = Long.toString(System.currentTimeMillis());
133                 IoTString ipingTimer = new IoTString(pingTimer);
134
135                 // t1.update();
136                 t1.startTransaction();
137                 t1.addKV(ipingTimerKey, ipingTimer);
138                 t1.commitTransaction();
139
140                 // // t2.update();
141                 // t2.startTransaction();
142                 // t2.addKV(ipingTimerKey, ipingTimer);
143                 // t2.commitTransaction();
144
145
146
147
148
149
150
151                 for (int i = 0; i < 3; i++) {
152                     IoTString testValA1 = t1.getCommitted(keys.get(i));
153                     if ((testValA1 != null) && (testValA1.equals(iValueA) == true)) {
154                         bulbs.get(i).turnOn();
155                     } else {
156                         bulbs.get(i).turnOff();
157                     }
158                 }
159
160                 Thread.sleep(1000);
161
162             } catch (Error e) {
163
164                 e.printStackTrace();
165                 for (int i = 0; i < 3; i++) {
166                     bulbs.get(i).setColor(0, 100, 100);
167                 }
168
169
170
171                 while (true) {
172                     for (int i = 0; i < 3; i++) {
173                         bulbs.get(i).turnOff();
174                     }
175                     Thread.sleep(1000);
176
177                     for (int i = 0; i < 3; i++) {
178                         bulbs.get(i).turnOn();
179                     }
180                     Thread.sleep(1000);
181                 }
182             }
183         }
184     }
185 }