Completing ZigbeeTest with doorlock test
[iot2.git] / benchmarks / other / ZigbeeTest / IoTZigbee.java
index 31c1d8a..6f0ad69 100644 (file)
@@ -104,6 +104,34 @@ public class IoTZigbee {
                socket.send(sendPacket);
        }
 
+       //made by Jiawei
+       public void sendLockOrUnlockDoorRequest(int packetId, int clusterId, int profileId, int deviceEndpoint, int value) throws IOException {
+               String message = "type: zcl_lock_or_unlock_door_request\n";
+               message += "packet_id: " + String.format("%04x", packetId) + "\n";
+               message += "value: " + String.format("%01x", value) + "\n";
+               message += "cluster_id: " + String.format("%04x", clusterId) + "\n";
+               message += "profile_id: " + String.format("%04x", profileId) + "\n";
+               message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
+               message += "device_endpoint: " + String.format("%02x", deviceEndpoint) + "\n";
+               DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort);
+               socket.send(sendPacket);
+       }
+
+       //made by Jiawei
+       public void sendReadDoorStatusRequest(int packetId, int clusterId, int profileId, int deviceEndpoint, int framecontrol, int commandframe, int attribute_id) throws IOException {
+               String message = "type: zcl_read_door_status_request\n";
+               message += "packet_id: " + String.format("%04x", packetId) + "\n";
+               message += "framecontrol: " + String.format("%02x", framecontrol) + "\n";
+               message += "cluster_id: " + String.format("%04x", clusterId) + "\n";
+               message += "profile_id: " + String.format("%04x", profileId) + "\n";
+               message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
+               message += "device_endpoint: " + String.format("%02x", deviceEndpoint) + "\n";
+               message += "commandframe: " + String.format("%02x", commandframe) + "\n";
+               message += "attribute_id: " + String.format("%04x", attribute_id) + "\n";
+               DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort);
+               socket.send(sendPacket);
+       }
+
        //made by changwoo
        public void sendBroadcastingRouteRecordRequest(int packetId) throws IOException {
                String message = "type: zdo_broadcast_route_record_request\n";
@@ -189,13 +217,14 @@ public class IoTZigbee {
                socket.send(sendPacket);
        }
 
-       public void sendConfigureReportingCommand(int packetId, int clusterId, int profileId, int deviceEndpoint, int attributeId, int dataType, int minReportingInterval, int maxReportingInterval, byte[] reportableChange) throws IOException {
+       public void sendConfigureReportingCommand(int packetId, int clusterId, int profileId, int src_endpoint, int dest_endpoint, int attributeId, int dataType, int minReportingInterval, int maxReportingInterval, byte[] reportableChange) throws IOException {
                String message = "type: zcl_configure_reporting\n";
                message += "packet_id: " + String.format("%04x", packetId) + "\n";
                message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
                message += "cluster_id: " + String.format("%04x", clusterId) + "\n";
                message += "profile_id: " + String.format("%04x", profileId) + "\n";
-               message += "device_endpoint: " + String.format("%02x", deviceEndpoint) + "\n";
+               message += "src_endpoint: " + String.format("%02x", src_endpoint) + "\n";
+               message += "device_endpoint: " + String.format("%02x", dest_endpoint) + "\n";
                message += "attribute_id: " + String.format("%04x", attributeId) + "\n";
                message += "data_type: " + String.format("%02x", dataType) + "\n";
                message += "min_reporting_interval: " + String.format("%04x", minReportingInterval) + "\n";
@@ -213,6 +242,10 @@ public class IoTZigbee {
                socket.send(sendPacket);
        }
 
+       public void sendConfigureReportingCommand(int packetId, int clusterId, int profileId, int dest_endpoint, int attributeId, int dataType, int minReportingInterval, int maxReportingInterval, byte[] reportableChange) throws IOException {
+               sendConfigureReportingCommand(packetId, clusterId, profileId, 0x00, dest_endpoint, attributeId, dataType, minReportingInterval, maxReportingInterval, reportableChange);
+       }
+
        public void registerCallback(IoTZigbeeCallback callbackTo) {
 
                callbackList.add(callbackTo);
@@ -244,6 +277,7 @@ public class IoTZigbee {
                String message = "type: send_address\n";
                message += "packet_id: 00\n";
                message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
+               System.out.println(message);
                DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort);
                socket.send(sendPacket);
        }
@@ -300,6 +334,7 @@ public class IoTZigbee {
 
                                        }
 */
+
                                        // made by changwoo
                                        if (packetData.get("type").equals("zcl_zone_status_change_notification")){
                                                int packetId = Integer.parseInt(packetData.get("packet_id"), 16);
@@ -310,6 +345,16 @@ public class IoTZigbee {
                                                if(packetData.get("attributes").equals("success")) successOrFail=true;
                                                callbackMessage = new IoTZigbeeMessageZclZoneStatusChangeNotification(packetId, clusterId, profileId, status, successOrFail);
 
+                                               // made by yuting
+                                       }else if (packetData.get("type").equals("zcl_change_switch_response")){
+                                               int packetId = Integer.parseInt(packetData.get("packet_id"), 16);
+                                               int clusterId = Integer.parseInt(packetData.get("cluster_id"), 16);
+                                               int profileId = Integer.parseInt(packetData.get("profile_id"), 16);
+                                               int status = Integer.parseInt(packetData.get("status"), 10);
+                                               boolean successOrFail = false;
+                                               if(packetData.get("attributes").equals("success")) successOrFail=true;
+                                               callbackMessage = new IoTZigbeeMessageZclChangeSwitchResponse(packetId, clusterId, profileId, status, successOrFail);
+
                                        //made by changwoo
                                        } else if (packetData.get("type").equals("zcl_write_attributes_response")) {