Doorlock and outlet drivers made by Yuting and Jiawei; the only problem is that outle...
[iot2.git] / benchmarks / other / DoorlockAndOutlet / ZigbeeTest_doorlock.java
1 import java.util.Map;
2 import java.net.*;
3 import java.io.*;
4 import java.util.*;
5
6 import iotruntime.*;
7 import iotruntime.zigbee.*;
8
9 import iotcode.interfaces.*;
10 import java.rmi.RemoteException;
11
12 //public class ZigbeeTest_doorlock implements IoTZigbeeCallback {
13 public class ZigbeeTest_doorlock implements SmartthingsSensorCallback {
14     public final int SOCKET_SEND_BUFFER_SIZE = 1024;
15     public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024;
16     private static final String MY_IP_ADDRESS = "127.0.0.1";
17     public static final String DEVIDE_MAC_ADDRESS = "002446fffd00b0ba"; //doorlock sensor
18
19     public void newReadingAvailable(SmartthingsSensor _sensor) {
20         //public void newReadingAvailable(SmartthingsSensor _sensor) throws RemoteException {
21         System.out.println("New Message!!!!");
22         int status = ((DoorlockSensor)_sensor).getStatus();
23         switch (status) {
24             case 0:
25                 System.out.println("Not fully locked");
26                 break;
27             case 1:
28                 System.out.println("Locked");
29                 break;
30             case 2:
31                 System.out.println("Unlocked");
32                 break;
33             default:
34                 System.out.println("Unknown value: " + status);
35                 break;
36         }
37     }
38
39     public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{
40
41         String message = "type: policy_set\n";
42         message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address
43         message += "port: " + "5959\n";  // port number
44         message += "device_address_long: " + DEVIDE_MAC_ADDRESS + "\n";
45         DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("127.0.0.1"), 5005); // address and port of the gateway which means Raspberry PI's IP address
46         DatagramSocket socket = new DatagramSocket(12345/*test number*/);
47         socket.setSendBufferSize(4096);
48         socket.setReceiveBufferSize(4096);
49         socket.send(sendPacket);
50         socket.setReuseAddress(true);
51         socket.close();
52
53         IoTDeviceAddress zigUdpAddr  = new IoTDeviceAddress("127.0.0.1", 5959, 5005,false,false);
54         IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS);
55
56         Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
57         zigSet.add(zigAddrLong);
58         IoTSet<IoTZigbeeAddress> zigIotSet = new IoTSet<IoTZigbeeAddress>(zigSet);
59
60         Set<IoTDeviceAddress> devSet = new HashSet<IoTDeviceAddress>();
61         devSet.add(zigUdpAddr);
62         IoTSet<IoTDeviceAddress> devIotSet = new IoTSet<IoTDeviceAddress>(devSet);
63         DoorlockSensor sen = new DoorlockSensor(devIotSet, zigIotSet);
64         
65         ZigbeeTest_doorlock zTest = new ZigbeeTest_doorlock();
66         sen.registerCallback(zTest);
67
68         System.out.println("About to init");
69         sen.init();
70
71         // ZigbeeTest_doorlock zTest = new ZigbeeTest_doorlock();
72         // sen.registerCallback(zTest);
73
74
75         System.out.println("Loop Begin");
76         while (true) {
77
78         }
79     }
80
81 }