1 package iotruntime.master;
4 import java.io.IOException;
5 import java.net.DatagramPacket;
6 import java.net.DatagramSocket;
7 import java.net.InetAddress;
8 import java.net.SocketException;
10 /** Class ZigbeeConfig is a class that configures the zigbee
11 * gateway in our network with the relevant policies
12 * through the usage of static methods;
14 * @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
18 public final class ZigbeeConfig {
23 public final int SOCKET_SEND_BUFFER_SIZE = 1024;
24 public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024;
27 * ZigbeeConfig properties
29 private String strZigbeeGatewayAddress;
30 private int iZigBeeGatewayPort;
31 private int iMasterPort;
32 private DatagramSocket socket;
33 private boolean bVerbose;
38 public ZigbeeConfig(String _strZigbeeGatewayAddress, int _iZigBeeGatewayPort, int _iMasterPort, boolean _bVerbose)
39 throws SocketException {
41 strZigbeeGatewayAddress = _strZigbeeGatewayAddress;
42 iZigBeeGatewayPort = _iZigBeeGatewayPort;
43 iMasterPort = _iMasterPort;
46 socket = new DatagramSocket(iMasterPort);
47 socket.setSendBufferSize(SOCKET_SEND_BUFFER_SIZE);
48 socket.setReceiveBufferSize(SOCKET_RECEIVE_BUFFER_SIZE);
50 RuntimeOutput.print("ZigbeeConfig: Zigbee gateway policy support for: " +
51 strZigbeeGatewayAddress + " with IoTMaster port: " + iMasterPort +
52 " and gateway port: " + iZigBeeGatewayPort, bVerbose);
56 * clearAllPolicies() method to delete the zigbee policies
60 public void clearAllPolicies() throws IOException {
62 // Clearing all policies on Zigbee gateway
63 RuntimeOutput.print("ZigbeeConfig: Accessing Zigbee gateway and deleting policies...", bVerbose);
65 String strMessage = "type: policy_clear\n";
66 DatagramPacket dpSendPacket = new DatagramPacket(strMessage.getBytes(),
67 strMessage.getBytes().length, InetAddress.getByName(strZigbeeGatewayAddress), iZigBeeGatewayPort);
68 socket.send(dpSendPacket);
70 RuntimeOutput.print("ZigbeeConfig: Sending policy message to Zigbee gateway: " + strMessage, bVerbose);
75 * setPolicy() method to set policies
77 * @param String Host address where the Zigbee driver is running as assigned by master
78 * @param int Host port number
79 * @param String String Zigbee device address
82 public void setPolicy(String strHostAddress, int iHostPort, String strZigbeeAddress) throws IOException {
84 // Clearing all policies on Zigbee gateway
85 RuntimeOutput.print("ZigbeeConfig: Accessing Zigbee gateway and sending a policy...", bVerbose);
87 String strMessage = "type: policy_set\n";
88 strMessage += "ip_address: " + strHostAddress + "\n";
89 strMessage += "port: " + iHostPort + "\n";
90 strMessage += "device_address_long: " + strZigbeeAddress + "\n";
92 DatagramPacket dpSendPacket = new DatagramPacket(strMessage.getBytes(),
93 strMessage.getBytes().length, InetAddress.getByName(strZigbeeGatewayAddress), iZigBeeGatewayPort);
94 socket.send(dpSendPacket);
96 RuntimeOutput.print("ZigbeeConfig: Sending policy message to Zigbee gateway: " + strMessage, bVerbose);
104 public void closeConnection() throws IOException {
105 socket.setReuseAddress(true);