From: rtrimana Date: Tue, 27 Feb 2018 23:35:26 +0000 (-0800) Subject: Adjusting and cleaning up ZigbeeTest to install Vigilia ZigBee gateway and devices. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=iot2.git;a=commitdiff_plain;h=8e565033fd19c4696f67862ade27f0ebbacf5682 Adjusting and cleaning up ZigbeeTest to install Vigilia ZigBee gateway and devices. --- diff --git a/benchmarks/other/XbeePythonDriver/xbee_driver.py b/benchmarks/other/XbeePythonDriver/xbee_driver.py index 955ed9c..488effe 100644 --- a/benchmarks/other/XbeePythonDriver/xbee_driver.py +++ b/benchmarks/other/XbeePythonDriver/xbee_driver.py @@ -1,3 +1,10 @@ +# ----------------------------------------------------------------------------- +# ZigBee Gateway Driver for Vigilia v.1.0 +# Created by Ali Younis +# Modified by Rahmadi Trimananda, Lee Changwoo, Jiawei +# (c) 2016-2018 University of California, Irvine +# ----------------------------------------------------------------------------- + from xbee import ZigBee import serial import time @@ -17,9 +24,7 @@ import threading UDP_RECEIVE_PORT = 5005 # port used for incoming UDP data UDP_RECEIVE_BUFFER_SIZE = 4096 # max buffer size of an incoming UDP packet SYSTEM_MASTER_ADDRESS = ("192.168.1.198", 12345) # ip address and portof the system master node -#SYSTEM_MASTER_ADDRESS = ("192.168.2.108", 22222) # ip address and portof the system master node -#SYSTEM_MASTER_ADDRESS2 = ("192.168.2.108", 11111) -#SYSTEM_MASTER_ADDRESS3 = ("192.168.2.108", 11222) +LOCAL_ADDRESS = "192.168.1.192" # local IP address # time for messages to wait for a response before the system clears away that # sequence identifier @@ -30,7 +35,6 @@ ZIGBEE_SERIAL_PORT = "/dev/ttyUSB0" ZIGBEE_SERIAL_BAUD = 115200 # Baud rate for above port # address of our local zigbee radio -#ZIGBEE_DEVICE_ADDRESS = "0013a20040d99cb4" ZIGBEE_DEVICE_ADDRESS = "xxxxxxxxxxxxxxxx" # ----------------------------------------------------------------------------- @@ -45,7 +49,7 @@ didGetLocalRadioLowAddress = False; zigbeeConnection = None zigbeeConnectionMutex = Lock() -#singleton mabe by changwoo +#singleton mabe by Changwoo matchDescriptorReqSingleton = True deviceAnnouncementSingleton = True ManagementPermitJoiningReqSuccess = False @@ -59,12 +63,12 @@ zigbeeLongShortAddrMutex = Lock() zigbeeSeqNumberToClient = dict() zigbeeSeqNumberToClientMutex = Lock() -zigeeBindRequest = dict() -zigeeBindRequestMutex = Lock() +zigbeeBindRequest = dict() +zigbeeBindRequestMutex = Lock() # Keeps record of where to send callbacks to when an HA message is received zibeeHACallback = dict() -zibeeHACallbackMutex = Lock() +zigbeeHACallbackMutex = Lock() # Keeps a record of device addresses whose short addresses have not been @@ -79,14 +83,14 @@ doEndFlag = False # 2 sockets, one for sending (not bound to a port manually) # and one for receiving, known port binding by application # both UDP sockets -sendSoceket = socket(AF_INET, SOCK_DGRAM) -receiveSoceket = socket(AF_INET, SOCK_DGRAM) +sendSocket = socket(AF_INET, SOCK_DGRAM) +receiveSocket = socket(AF_INET, SOCK_DGRAM) # zigbee address authority list zigbeeAddressAuthorityDict = dict() -# made by changwoo +# Added by Changwoo seqNumberForNotification = dict() # ----------------------------------------------------------------------------- @@ -373,7 +377,6 @@ def getConnectedRadioLongAddress(): zigbeeConnection.send('at', command="SL") # sleep for a bit to give the radio time to respond before we check again - #time.sleep(2) time.sleep(0.5) def addressUpdateWorkerMethod(): @@ -426,7 +429,6 @@ def addressUpdateWorkerMethod(): ) zigbeeConnectionMutex.release() - #time.sleep(8) time.sleep(1) @@ -445,7 +447,7 @@ def sendUdpSuccessFail(addr, packetTypeStr, packetIdStr, sucOrFail, reason=None) ''' - global sendSoceket + global sendSocket # construct the message message = "type: " + packetTypeStr.strip() + "\n" @@ -458,7 +460,7 @@ def sendUdpSuccessFail(addr, packetTypeStr, packetIdStr, sucOrFail, reason=None) message += "reason: " + reason + "\n" # send message in a UDP packet - sendSoceket.sendto(message,addr) + sendSocket.sendto(message,addr) def processUdpZdoBindReqMessage(parsedData, addr): @@ -470,7 +472,7 @@ def processUdpZdoBindReqMessage(parsedData, addr): return else: return - + # get the short address for this device long address if possible zigbeeLongShortAddrMutex.acquire() if(zigbeeLongShortAddr.has_key(parsedData['device_address_long'])): @@ -481,6 +483,7 @@ def processUdpZdoBindReqMessage(parsedData, addr): # if there is not one then we cannot since we need both the short and # the long address if(shortAddr != None): + print "> Short address exists", shortAddr # get a request number seqNumber = createSequenceNumberForClient(addr, parsedData['packet_id']) @@ -494,12 +497,12 @@ def processUdpZdoBindReqMessage(parsedData, addr): # a bind request was made so must store and wait for response # before we setup callbacks, so keep just the data we need to create the callback - zigeeBindRequestMutex.acquire() - zigeeBindRequest[seqNumber] = (parsedData['device_address_long'], + zigbeeBindRequestMutex.acquire() + zigbeeBindRequest[seqNumber] = (parsedData['device_address_long'], parsedData['cluster_id'], parsedData['packet_id'], addr) - zigeeBindRequestMutex.release() + zigbeeBindRequestMutex.release() # construct the short and long addresses of the message for sending # make sure they are in the correct format @@ -538,10 +541,10 @@ def processUdpZdoBindReqMessage(parsedData, addr): pass def processUdpZdoUnBindReqMessage(parsedData, addr): - zibeeHACallbackMutex.acquire(); + zigbeeHACallbackMutex.acquire(); if(zibeeHACallback.has_key(parsedData['device_address_long'], parsedData['cluster_id'])): zibeeHACallback(parsedData['device_address_long'], parsedData['cluster_id']).remove(addr) - zibeeHACallbackMutex.release() + zigbeeHACallbackMutex.release() sendUdpSuccessFail(addr, 'zdo_unbind_request', parsedData['packet_id'], True) @@ -556,7 +559,7 @@ def processUdpSendAddressMessage(parsedData, addr): global zigbeeLongShortAddrMutex global zigbeeUnregisteredAddresses global zigbeeUnregisteredAddressesMutex - global sendSoceket + global sendSocket print "process send address" @@ -567,7 +570,7 @@ def processUdpSendAddressMessage(parsedData, addr): message += "response: success\n" # tell client that we got their request - sendSoceket.sendto(message,addr) + sendSocket.sendto(message,addr) print "responding", message # construct @@ -586,13 +589,13 @@ def processUdpSendAddressMessage(parsedData, addr): -#made by changwoo +# Added by Changwoo def processUdpEnrollmentResponse(parsedData, addr): global zigbeeLongShortAddr global zigbeeLongShortAddrMutex - global zigeeBindRequestMutex - global zigeeBindRequest + global zigbeeBindRequestMutex + global zigbeeBindRequest global zigbeeConnectionMutex global zigbeeConnection shortAddr = None @@ -658,13 +661,13 @@ def processUdpEnrollmentResponse(parsedData, addr): -#made by changwoo +# Added by Changwoo def processUdpZclWriteAttributesMessage(parsedData, addr): global zigbeeLongShortAddr global zigbeeLongShortAddrMutex - global zigeeBindRequestMutex - global zigeeBindRequest + global zigbeeBindRequestMutex + global zigbeeBindRequest global zigbeeConnectionMutex global zigbeeConnection shortAddr = None @@ -703,7 +706,6 @@ def processUdpZclWriteAttributesMessage(parsedData, addr): payloadData += '\x02' payloadData += '\x10\x00' payloadData += '\xF0' -# payloadData += '\xDA\x9A\xD9\x40\x00\xA2\x13\x00' payloadData += hexStringToZigbeeHexString(changeEndian(ZIGBEE_DEVICE_ADDRESS)) zigbeeConnectionMutex.acquire() @@ -729,13 +731,13 @@ def processUdpZclWriteAttributesMessage(parsedData, addr): sendUdpSuccessFail(addr, 'zcl_write_attributes', parsedData['packet_id'], False, 'short_address_unknown') pass -#made by changwoo +# Added by Changwoo def processUdpZclChangeSwitchReqMessage(parsedData, addr): global zigbeeLongShortAddr global zigbeeLongShortAddrMutex - global zigeeBindRequestMutex - global zigeeBindRequest + global zigbeeBindRequestMutex + global zigbeeBindRequest global zigbeeConnectionMutex global zigbeeConnection shortAddr = None @@ -799,13 +801,13 @@ def processUdpZclChangeSwitchReqMessage(parsedData, addr): pass -#made by Jiawei +# Added by Jiawei def processUdpZclLockOrUnlockDoorReqMessage(parsedData, addr): global zigbeeLongShortAddr global zigbeeLongShortAddrMutex - global zigeeBindRequestMutex - global zigeeBindRequest + global zigbeeBindRequestMutex + global zigbeeBindRequest global zigbeeConnectionMutex global zigbeeConnection shortAddr = None @@ -869,13 +871,13 @@ def processUdpZclLockOrUnlockDoorReqMessage(parsedData, addr): sendUdpSuccessFail(addr, 'lock_or_unlock_door_request', parsedData['packet_id'], False, 'short_address_unknown') -#made by Jiawei +# Added by Jiawei def processUdpZclReadDoorStatusReqMessage(parsedData, addr): global zigbeeLongShortAddr global zigbeeLongShortAddrMutex - global zigeeBindRequestMutex - global zigeeBindRequest + global zigbeeBindRequestMutex + global zigbeeBindRequest global zigbeeConnectionMutex global zigbeeConnection shortAddr = None @@ -908,9 +910,6 @@ def processUdpZclReadDoorStatusReqMessage(parsedData, addr): dstEndpoint = hexStringToZigbeeHexString(parsedData['device_endpoint']) clusterId = hexStringToZigbeeHexString(parsedData['cluster_id']) profileId = hexStringToZigbeeHexString(parsedData['profile_id']) - # framecontrol = hexStringToZigbeeHexString(parsedData['framecontrol']) - # commandframe = hexStringToZigbeeHexString(parsedData['commandframe']) - # attribute_id = hexStringToZigbeeHexString(parsedData['attribute_id']) # create and send binding command zigbeeConnectionMutex.acquire() @@ -935,13 +934,13 @@ def processUdpZclReadDoorStatusReqMessage(parsedData, addr): sendUdpSuccessFail(addr, 'read_door_status_request', parsedData['packet_id'], False, 'short_address_unknown') -# made by changwoo +# Added by Changwoo def processUdpBroadcastingRouteRecordReqMessage(parsedData, addr): global zigbeeLongShortAddr global zigbeeLongShortAddrMutex - global zigeeBindRequestMutex - global zigeeBindRequest + global zigbeeBindRequestMutex + global zigbeeBindRequest global zigbeeConnectionMutex global zigbeeConnection shortAddr = None @@ -999,13 +998,13 @@ def processUdpBroadcastingRouteRecordReqMessage(parsedData, addr): pass -#made by changwoo +# Added by Changwoo def processUdpManagementPermitJoiningReqMessage(parsedData, addr): global zigbeeLongShortAddr global zigbeeLongShortAddrMutex - global zigeeBindRequestMutex - global zigeeBindRequest + global zigbeeBindRequestMutex + global zigbeeBindRequest global zigbeeConnectionMutex global zigbeeConnection global matchDescriptorReqSingleton @@ -1079,8 +1078,8 @@ def processUdpZclReadAttributesMessage(parsedData, addr): global zigbeeLongShortAddr global zigbeeLongShortAddrMutex - global zigeeBindRequestMutex - global zigeeBindRequest + global zigbeeBindRequestMutex + global zigbeeBindRequest global zigbeeConnectionMutex global zigbeeConnection @@ -1170,8 +1169,8 @@ def processUdpZclConfigureReportingMessage(parsedData, addr): global zigbeeLongShortAddr global zigbeeLongShortAddrMutex - global zigeeBindRequestMutex - global zigeeBindRequest + global zigbeeBindRequestMutex + global zigbeeBindRequest global zigbeeConnectionMutex global zigbeeConnection @@ -1257,7 +1256,6 @@ def processUdpPolicySet(parsedData, addr): # do nothing if wrong source - #if addr == SYSTEM_MASTER_ADDRESS or addr == SYSTEM_MASTER_ADDRESS2 or addr == SYSTEM_MASTER_ADDRESS3 : if addr == SYSTEM_MASTER_ADDRESS : key = (parsedData['ip_address'], int(parsedData['port'])) if (zigbeeAddressAuthorityDict.has_key(key)): @@ -1325,8 +1323,8 @@ def processZigbeeRxExplicitCommandMessage(parsedData): parsedData -- Pre-parsed (into a dict) data from message. ''' - global zigeeBindRequestMutex - global zigeeBindRequest + global zigbeeBindRequestMutex + global zigbeeBindRequest global zigbeeConnectionMutex global zigbeeConnection global ManagementPermitJoiningReqSuccess @@ -1352,7 +1350,7 @@ def processZigbeeRxExplicitCommandMessage(parsedData): global deviceAnnouncementSingleton global seqNumberForNotification - #made by Jiawei + # Added by Jiawei #doorlock response if (parsedData['cluster'] == '\x01\x01' and parsedData['profile'] == '\x01\x04'): zclSeqNumber = parsedData['rf_data'][1] @@ -1437,7 +1435,7 @@ def processZigbeeRxExplicitCommandMessage(parsedData): if(tup == None): # cant really do anything here return - sendSoceket.sendto(message,tup[0]) + sendSocket.sendto(message,tup[0]) elif command == '\x07': status = rfdata[3] print '' @@ -1456,7 +1454,7 @@ def processZigbeeRxExplicitCommandMessage(parsedData): if(tup == None): # cant really do anything here return - sendSoceket.sendto(message,tup[0]) + sendSocket.sendto(message,tup[0]) else: print "Configure report unsuccessfully, status =", zigbeeHexStringToHexString(status) elif(command == '\x0A'): @@ -1504,25 +1502,22 @@ def processZigbeeRxExplicitCommandMessage(parsedData): # get callback clients to respond to callbackIndex = (zigbeeHexStringToHexString(parsedData['source_addr_long']), zigbeeHexStringToHexString(parsedData['cluster'])) retAddr = None - zibeeHACallbackMutex.acquire() + zigbeeHACallbackMutex.acquire() if(zibeeHACallback.has_key(callbackIndex)): retAddr = zibeeHACallback[callbackIndex] - zibeeHACallbackMutex.release() + zigbeeHACallbackMutex.release() # no one to respond to so do nothing here if(retAddr == None): return for ra in retAddr: - sendSoceket.sendto(message,ra) + sendSocket.sendto(message,ra) return # if this is a ZDO message/response - #print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" - #print parsedData - #print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" if(parsedData['profile'] == '\x00\x00'): - # made by changwoo + # Added by Changwoo # if this is a Match Descriptor Request so we need to answer. if(parsedData['cluster'] == '\x00\x06' and matchDescriptorReqSingleton): zigbeeConnectionMutex.acquire() @@ -1558,7 +1553,6 @@ def processZigbeeRxExplicitCommandMessage(parsedData): # if this is a device announcement so we can get some useful data from it elif(parsedData['cluster'] == '\x00\x13' and deviceAnnouncementSingleton): - #print parsedData # pick out the correct parts of the payload longAddr = zigbeeHexStringToHexString(parsedData['rf_data'][3:11]) shortAddr = zigbeeHexStringToHexString(parsedData['rf_data'][1:3]) @@ -1579,8 +1573,7 @@ def processZigbeeRxExplicitCommandMessage(parsedData): zigbeeUnregisteredAddresses.remove(longAddr) zigbeeUnregisteredAddressesMutex.release() - - # made by changwoo + # Added by Changwoo zigbeeConnectionMutex.acquire() zigbeeConnection.send('tx_explicit', frame_id='\x08', @@ -1606,15 +1599,15 @@ def processZigbeeRxExplicitCommandMessage(parsedData): # get the status and sequence number from the message seqNumber = parsedData['rf_data'][0] statusCode = parsedData['rf_data'][1] - print ">response to a zdo bind_req message parsedData>" + print "> response to a zdo bind_req message parsedData" # get the bind tuple information # for this specific bind request tup = None - zigeeBindRequestMutex.acquire() - if(zigeeBindRequest.has_key(ord(seqNumber))): - tup = zigeeBindRequest[ord(seqNumber)] - zigeeBindRequestMutex.release() + zigbeeBindRequestMutex.acquire() + if(zigbeeBindRequest.has_key(ord(seqNumber))): + tup = zigbeeBindRequest[ord(seqNumber)] + zigbeeBindRequestMutex.release() if(tup == None): # cant really do anything in this case... @@ -1626,16 +1619,18 @@ def processZigbeeRxExplicitCommandMessage(parsedData): # add a callback for this specific device and cluster # to the HA callback dict - zibeeHACallbackMutex.acquire(); + zigbeeHACallbackMutex.acquire(); if(zibeeHACallback.has_key((tup[0], tup[1]))): if(tup[3] not in zibeeHACallback[(tup[0], tup[1])]): zibeeHACallback[(tup[0], tup[1])].append(tup[3]) else: zibeeHACallback[(tup[0], tup[1])] = [tup[3]] - zibeeHACallbackMutex.release() - + zigbeeHACallbackMutex.release() + # send success message sendUdpSuccessFail(tup[3], 'zdo_bind_request', tup[2], True) + + print "> Success message sent!" # Not Supported elif (ord(statusCode) == 170): @@ -1651,7 +1646,7 @@ def processZigbeeRxExplicitCommandMessage(parsedData): # if this is a response to a short address query elif(parsedData['cluster'] == '\x80\x00'): - print ">response to a short address query 0x8000" + #print ">response to a short address query 0x8000" # get a status code statusCode = parsedData['rf_data'][0] @@ -1676,13 +1671,13 @@ def processZigbeeRxExplicitCommandMessage(parsedData): zigbeeLongShortAddr[longAddr] = shortAddr zigbeeLongShortAddrMutex.release() - #made by changwoo + # Added by Changwoo elif(parsedData['cluster'] == '\x80\x06'): print '' print '[ 0x8006 ] get Match Descriptor Response' print '> rfdata : '+zigbeeHexStringToHexString(parsedData['rf_data']) - #made by changwoo + # Added by Changwoo elif(parsedData['cluster'] == '\x80\x36'): print '' print '[ 0x8036 ] get Management Permit Joining Response' @@ -1690,7 +1685,7 @@ def processZigbeeRxExplicitCommandMessage(parsedData): ManagementPermitJoiningReqSuccess = True - #made by changwoo + # Added by Changwoo else : print '' print '[ '+zigbeeHexStringToHexString(parsedData['cluster'])+' ] ...' @@ -1706,7 +1701,7 @@ def processZigbeeRxExplicitCommandMessage(parsedData): zclCommand = parsedData['rf_data'][2] zclStatus = parsedData['rf_data'][3] - #made by changwoo + # Added by Changwoo if(zclCommand == '\x00'): print '' print '> ('+zigbeeHexStringToHexString(zclStatus)+') notification! : '+ zigbeeHexStringToHexString( parsedData['rf_data'] ) @@ -1736,7 +1731,7 @@ def processZigbeeRxExplicitCommandMessage(parsedData): message += "attributes: success" message += "\n" # send the socket - sendSoceket.sendto(message,tup[0]) + sendSocket.sendto(message,tup[0]) print(">port : ", tup[0][1]) @@ -1832,13 +1827,10 @@ def processZigbeeRxExplicitCommandMessage(parsedData): message = message[0:len(message) - 1] message += "\n" # send the socket - sendSoceket.sendto(message,tup[0]) - + sendSocket.sendto(message,tup[0]) - - - # made by changwoo - # this is a zcl write attribute response + # Added by Changwoo + # this is a zcl write attribute response elif(zclCommand == '\x04'): # get the zcl payload @@ -1868,7 +1860,7 @@ def processZigbeeRxExplicitCommandMessage(parsedData): message += "attributes: success" message += "\n" # send the socket - sendSoceket.sendto(message,tup[0]) + sendSocket.sendto(message,tup[0]) print '' print '[ 0x0500 ] get Write Attribute Response success' print '> rfdata : '+zigbeeHexStringToHexString(parsedData['rf_data']) @@ -1911,7 +1903,7 @@ def processZigbeeRxExplicitCommandMessage(parsedData): # if all the configurations are a success then only send back a success # based on zigbee specs message += "all_success \n"; - sendSoceket.sendto(message,tup[0]) + sendSocket.sendto(message,tup[0]) else: attibuteResponseList = [] @@ -1949,7 +1941,7 @@ def processZigbeeRxExplicitCommandMessage(parsedData): message = message[0:len(message) - 1] message += "\n" - sendSoceket.sendto(message,tup[0]) + sendSocket.sendto(message,tup[0]) # this is a zcl report attribute message elif(zclCommand == '\x0a'): @@ -1980,10 +1972,10 @@ def processZigbeeRxExplicitCommandMessage(parsedData): # get callback clients to respond to callbackIndex = (zigbeeHexStringToHexString(parsedData['source_addr_long']), zigbeeHexStringToHexString(parsedData['cluster'])) retAddr = None - zibeeHACallbackMutex.acquire() + zigbeeHACallbackMutex.acquire() if(zibeeHACallback.has_key(callbackIndex)): retAddr = zibeeHACallback[callbackIndex] - zibeeHACallbackMutex.release() + zigbeeHACallbackMutex.release() # no one to respond to so do nothing here if(retAddr == None): @@ -2020,7 +2012,7 @@ def processZigbeeRxExplicitCommandMessage(parsedData): # send to all client that want this callback for ra in retAddr: - sendSoceket.sendto(message,ra) + sendSocket.sendto(message,ra) # ----------------------------------------------------------------------------- # Communication Callback/Parse Methods @@ -2032,20 +2024,20 @@ def handleNewZigbeeMessage(parsedData): ''' #print "==================================================================" #print '' - print "New Zigbee Message" + #print "New Zigbee Message" #printMessageData(parsedData) # dispatch to the correct zigbee handler if (parsedData['id'] == 'at_response'): - print "parsedDataID : at_response" + #print "parsedDataID : at_response" processZigbeeATCommandMessage(parsedData) elif (parsedData['id'] == 'rx_explicit'): - print "parsedDataID : rx_explicit" + #print "parsedDataID : rx_explicit" processZigbeeRxExplicitCommandMessage(parsedData) - else: - print "Unknown API format" + #else: + #print "Unknown API format" #print "==================================================================" @@ -2098,25 +2090,25 @@ def handleNewUdpPacket(data, addr): elif(parsedData["type"] == "zcl_read_attributes"): processUdpZclReadAttributesMessage(parsedData, addr) elif(parsedData["type"] == "zcl_configure_reporting"): - print "> zcl_configure_reporting call" + print "> processUdpZclConfigureReportingMessage call" processUdpZclConfigureReportingMessage(parsedData, addr) elif(parsedData["type"] == "policy_set"): processUdpPolicySet(parsedData, addr) elif(parsedData["type"] == "policy_clear"): processUdpPolicyClear(parsedData, addr) - elif(parsedData["type"] == "management_permit_joining_request"): #made by changwoo - processUdpManagementPermitJoiningReqMessage(parsedData, addr) - elif(parsedData["type"] == "zcl_write_attributes" and ManagementPermitJoiningReqSuccess): #made by changwoo + elif(parsedData["type"] == "management_permit_joining_request"): # Added by Changwoo + processUdpManagementPermitJoiningReqMessage(parsedData, addr) + elif(parsedData["type"] == "zcl_write_attributes" and ManagementPermitJoiningReqSuccess): # Added by Changwoo processUdpZclWriteAttributesMessage(parsedData, addr) - elif(parsedData["type"] == "zcl_enrollment_response"): #made by changwoo - processUdpEnrollmentResponse(parsedData, addr) - elif(parsedData["type"] == "zdo_broadcast_route_record_request"): #made by changwoo - processUdpBroadcastingRouteRecordReqMessage(parsedData, addr) - elif(parsedData["type"] == "zcl_change_switch_request"): #made by changwoo - processUdpZclChangeSwitchReqMessage(parsedData, addr) - elif(parsedData["type"] == "zcl_lock_or_unlock_door_request"): #made by Jiawei + elif(parsedData["type"] == "zcl_enrollment_response"): # Added by Changwoo + processUdpEnrollmentResponse(parsedData, addr) + elif(parsedData["type"] == "zdo_broadcast_route_record_request"): # Added by Changwoo + processUdpBroadcastingRouteRecordReqMessage(parsedData, addr) + elif(parsedData["type"] == "zcl_change_switch_request"): # Added by Changwoo + processUdpZclChangeSwitchReqMessage(parsedData, addr) + elif(parsedData["type"] == "zcl_lock_or_unlock_door_request"): # Added by Jiawei processUdpZclLockOrUnlockDoorReqMessage(parsedData, addr) - elif(parsedData["type"] == "zcl_read_door_status_request"): #made by Jiawei + elif(parsedData["type"] == "zcl_read_door_status_request"): # Added by Jiawei processUdpZclReadDoorStatusReqMessage(parsedData, addr) else: #print "unknown Packet: " + parsedData["type"] @@ -2161,8 +2153,7 @@ def main(): # setup incoming UDP socket and bind it to self and specified UDP port # sending socket does not need to be bound to anything - #receiveSoceket.bind(('192.168.2.227', UDP_RECEIVE_PORT)) - receiveSoceket.bind(('192.168.1.192', UDP_RECEIVE_PORT)) + receiveSocket.bind((LOCAL_ADDRESS, UDP_RECEIVE_PORT)) # create the thread that does short address lookups addressUpdateWorkerThread = threading.Thread(target=addressUpdateWorkerMethod) @@ -2173,12 +2164,12 @@ def main(): while(True): print "==================================================================" print '' - print "Waiting..." + print "Waiting..." print "==================================================================" # wait for an incoming UDP packet # this is a blocking call - data, addr = receiveSoceket.recvfrom(4096) + data, addr = receiveSocket.recvfrom(4096) # handle the UDP packet appropriately handleNewUdpPacket(data, addr) @@ -2200,8 +2191,8 @@ def main(): # make sure to close all the connections zigbeeConnection.halt() - receiveSoceket.close() - sendSoceket.close() + receiveSocket.close() + sendSocket.close() if __name__ == "__main__": # call main function since this is being run as the start diff --git a/benchmarks/other/ZigbeeTest/DoorlockSensor.java b/benchmarks/other/ZigbeeTest/DoorlockSensor.java deleted file mode 100644 index c069949..0000000 --- a/benchmarks/other/ZigbeeTest/DoorlockSensor.java +++ /dev/null @@ -1,283 +0,0 @@ -//package iotcode.DoorlockSensor; - -// Standard Java Packages -import java.util.*; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.Semaphore; - -// Checker annotations -//import iotchecker.qual.*; -import iotcode.annotation.*; - -// IoT Packages -import iotruntime.slave.*; -import iotcode.interfaces.*; -import iotruntime.zigbee.*; - -/** Class Smartthings sensor driver for Smartthings sensor devices. - * - * @author Changwoo Lee, Rahmadi Trimananda - * @version 1.0 - * @since 2016-12-01 - */ -public class DoorlockSensor implements IoTZigbeeCallback, SmartthingsSensor { - - private final int TIMEOUT_FOR_RESEND_MSEC = 900; - - private IoTZigbee zigConnection = null; - private boolean didClose; // make sure that the clean up was done correctly - private boolean detectStatus = false; - - private int detectedValue = 0; - private Date timestampOfLastDetecting = null; - - private AtomicBoolean didAlreadyClose = new AtomicBoolean(true); - private AtomicBoolean didAlreadyInit = new AtomicBoolean(false); - private AtomicBoolean didWriteAttrb = new AtomicBoolean(false); - private AtomicBoolean didMatchDscr = new AtomicBoolean(false); - private AtomicBoolean didBind = new AtomicBoolean(false); - private AtomicBoolean didDoorLockConfigureReporting = new AtomicBoolean(false); //made by Jiawei - static Semaphore gettingLatestDataMutex = new Semaphore(1); - - private List < SmartthingsSensorCallback > callbackList = new CopyOnWriteArrayList < SmartthingsSensorCallback > (); - - private int sensorId = 0; - - @config private IoTSet DoorlockSensorUdpAddress; // - @config private IoTSet DoorlockSensorZigbeeAddress;// - - public DoorlockSensor(IoTSet dSet, IoTSet zigSet) { - DoorlockSensorUdpAddress = dSet; - DoorlockSensorZigbeeAddress = zigSet; - } - - public DoorlockSensor() { - } - - public void init() { - - if (didAlreadyInit.compareAndSet(false, true) == false) { - return; // already init - } - - didAlreadyClose.set(false); - - try { - Iterator itrUdp = DoorlockSensorUdpAddress.iterator(); - Iterator itrZig = DoorlockSensorZigbeeAddress.iterator(); - - zigConnection = new IoTZigbee((IoTDeviceAddress)itrUdp.next(), (IoTZigbeeAddress)itrZig.next()); - - // DEBUG - System.out.println("DEBUG: Allocate iterators to print out addresses!"); - Iterator itrDebugUdp = DoorlockSensorUdpAddress.iterator(); - IoTDeviceAddress iotaddDebug = (IoTDeviceAddress)itrDebugUdp.next(); - System.out.println("IP address: " + iotaddDebug.getCompleteAddress()); - System.out.println("Source port: " + iotaddDebug.getSourcePortNumber()); - System.out.println("Destination port: " + iotaddDebug.getDestinationPortNumber()); - - Iterator itrDebugZig = DoorlockSensorZigbeeAddress.iterator(); - IoTZigbeeAddress iotzbaddDebug = (IoTZigbeeAddress)itrDebugZig.next(); - System.out.println("Zigbee address: " + iotzbaddDebug.getAddress()); - - zigConnection.registerCallback(this); - System.out.println("Register callback!"); - zigConnection.init(); - System.out.println("Initialized!"); - - - - //made by changwoo - sleep(10); - - // System.out.println("BroadcastingRouteRecordRequest "); - // zigConnection.sendBroadcastingRouteRecordRequest(0x0001); - // sleep(6); - - System.out.println("Sending Management Permit Joining Request"); - // for(int z=0; z<3; z++){ - zigConnection.sendManagementPermitJoiningRequest(0x0002, 0x0036, 0x00); - sleep(0); - // } - - - while(!didBind.get()){ - System.out.println("Sending Bind Request"); - zigConnection.sendBindRequest(0x0003, 0x0101, 0x02); - sleep(0); - } - - while(!didDoorLockConfigureReporting.get()){ - System.out.println("Sending Door Lock: Configure Reporting"); - zigConnection.sendConfigureReportingCommand(0x0004, 0x0101, 0x0104, 0x01, 0x02, 0x0000, 0x30, 0x0000, 0x100E, null); - sleep(0); - } - - while(true){ - Scanner in = new Scanner(System.in); - System.out.println("\nUnlock door: 0"); - System.out.println("Lock door: 1"); - System.out.println("Read status: 2 (or anything else)"); - String str = in.next(); - if(str.equals("1")) { - System.out.println("the doorlock sensor is locking"); - zigConnection.sendLockOrUnlockDoorRequest(0x0005, 0x0101, 0x0104, 0x02, 0); - sleep(0); - }else if(str.equals("0")){ - System.out.println("the doorlock sensor is unlocking"); - zigConnection.sendLockOrUnlockDoorRequest(0x0005, 0x0101, 0x0104, 0x02, 1); - sleep(0); - }else{ - System.out.println("Let's see the doorlock sensor's status currently"); - zigConnection.sendReadDoorStatusRequest(0x0005, 0x0101, 0x0104, 0x02, 0x10, 0x00, 0x0000); - sleep(0); - } - } - - - } catch (Exception e) { - e.printStackTrace(); - } - } - - //made by changwoo - private void sleep(int multipleTime){ - if(multipleTime<=0){ - multipleTime=1; - } - try{ - Thread.sleep(TIMEOUT_FOR_RESEND_MSEC*multipleTime); - } catch(Exception e){ - e.printStackTrace(); - } - } - - // made by Jiawei - //public int getStatus() { - public int getValue() { - int tmp = 0; - - try { - gettingLatestDataMutex.acquire(); - tmp = detectedValue; - - } catch (Exception e) { - e.printStackTrace(); - } - gettingLatestDataMutex.release(); - - return tmp; - } - - public boolean isActiveValue() { - - int tmp = getValue(); - if (tmp == 1) - detectStatus = true; // Door is locked - else - detectStatus = false; // Door is not locked/not fully locked - return detectStatus; - } - - public void close() { - - if (didAlreadyClose.compareAndSet(false, true) == false) { - return; // already init - } - - didAlreadyInit.set(false); - - - try { - zigConnection.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void Finalize() { - if (!didClose) { - close(); - } - } - - public void setId(int id) { - - sensorId = id; - - } - - public int getId() { - - return sensorId; - - } - - - public long getTimestampOfLastReading() { - - Date tmp = null; - try { - gettingLatestDataMutex.acquire(); - tmp = (Date)timestampOfLastDetecting.clone(); - - } catch (Exception e) { - e.printStackTrace(); - } - gettingLatestDataMutex.release(); - long retLong = tmp.getTime(); - - return retLong; - } - - public void newMessageAvailable(IoTZigbeeMessage _zm) { - - //made by yuting - if (_zm instanceof IoTZigbeeMessageZdoBindResponse) { - IoTZigbeeMessageZdoBindResponse message = (IoTZigbeeMessageZdoBindResponse)_zm; - if (message.getSucceeded()) { - didBind.set(true); - } - } - else if (_zm instanceof IoTZigbeeMessageZclConfigureReportingResponse){ - IoTZigbeeMessageZclConfigureReportingResponse message = (IoTZigbeeMessageZclConfigureReportingResponse)_zm; - if (message.getAllSuccess()) { - didDoorLockConfigureReporting.set(true); - } - } - else if (_zm instanceof IoTZigbeeMessageZclReadAttributesResponse) { - IoTZigbeeMessageZclReadAttributesResponse message = (IoTZigbeeMessageZclReadAttributesResponse)_zm; - List attrList = message.getAttributes(); - - if (attrList.size() == 1) { - if(attrList.get(0).getAttributeId() == 0) { - byte[] data = attrList.get(0).getData(); - int value = data[0]; - - try { - gettingLatestDataMutex.acquire(); - detectedValue = value; - timestampOfLastDetecting = new Date(); - } catch (Exception e) { - e.printStackTrace(); - } - gettingLatestDataMutex.release(); - - try { - for (SmartthingsSensorCallback cb : callbackList) { - cb.newReadingAvailable(this.getValue(), this.isActiveValue()); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - } - } - } - - //public void registerCallback(SmartthingsSensorSmartCallback _callbackTo) { - public void registerCallback(SmartthingsSensorCallback _callbackTo) { - callbackList.add(_callbackTo); - } -} diff --git a/benchmarks/other/ZigbeeTest/IoTAddress.java b/benchmarks/other/ZigbeeTest/IoTAddress.java deleted file mode 100644 index 8e82847..0000000 --- a/benchmarks/other/ZigbeeTest/IoTAddress.java +++ /dev/null @@ -1,77 +0,0 @@ - -// Java packages -import java.net.Socket; -import java.net.ServerSocket; -import java.net.InetAddress; -import java.net.UnknownHostException; - -/** Class IoTAddress is a wrapper class to pass - * IoTSet of any addresses from master to slave - * - * @author Rahmadi Trimananda - * @version 1.0 - * @since 2016-04-22 - */ -public class IoTAddress { - - /** - * IoTDeviceAddress class properties - */ - protected final InetAddress inetAddress; - - /** - * Class constructor - * - * @param sAddress String address - */ - public IoTAddress(String sAddress) throws UnknownHostException { - - inetAddress = InetAddress.getByName(sAddress); - } - - /** - * getHostAddress() method - * - * @return String - */ - public String getHostAddress() { - - return inetAddress.getHostAddress(); - - } - - /** - * getHostName() method - * - * @return String - */ - public String getHostName() { - - return inetAddress.getHostName(); - - } - - /** - * getUrl() method - * - * @return String - */ - public String getURL(String strURLComplete) { - - //e.g. http:// + inetAddress.getHostAddress() + strURLComplete - // http://192.168.2.254/cgi-bin/mjpg/video.cgi? - return "http://" + inetAddress.getHostAddress() + strURLComplete; - - } - - /** - * getCompleteAddress() method - * - * @return String - */ - public String getCompleteAddress() { - - return inetAddress.toString(); - - } -} diff --git a/benchmarks/other/ZigbeeTest/IoTDeviceAddress.java b/benchmarks/other/ZigbeeTest/IoTDeviceAddress.java deleted file mode 100644 index 1dff865..0000000 --- a/benchmarks/other/ZigbeeTest/IoTDeviceAddress.java +++ /dev/null @@ -1,138 +0,0 @@ - -// Java packages -import java.net.Socket; -import java.net.ServerSocket; -import java.net.InetAddress; -import java.net.UnknownHostException; - -/** Class IoTDeviceAddress is a wrapper class to pass - * IoTSet of device addresses from master to slave - * - * @author Rahmadi Trimananda - * @version 1.0 - * @since 2016-02-18 - */ -public class IoTDeviceAddress extends IoTAddress { - - /** - * IoTDeviceAddress class properties - */ - private int iSrcPort; - private int iDstPort; - private final String sAddress; - - // the wildcard status of this address - private final boolean isSrcPortWildCard; - private final boolean isDstPortWildCard; - - - /** - * Class constructor - * - * @param sAddress String address - * @param _iSrcPort Source port number - * @param _iDstPort Destination port number - * @param _isSrcPortWildCard Is this source port a wild card (=can change port number)? - * @param _isDstPortWildCard Is this destination port a wild card (=can change port number)? - */ - public IoTDeviceAddress(String _sAddress, int _iSrcPort, int _iDstPort, boolean _isSrcPortWildCard, - boolean _isDstPortWildCard) throws UnknownHostException { - - super(_sAddress); - sAddress = _sAddress; - iSrcPort = _iSrcPort; - iDstPort = _iDstPort; - - isSrcPortWildCard = _isSrcPortWildCard; - isDstPortWildCard = _isDstPortWildCard; - } - - /** - * getSourcePortNumber() method - * - * @return int - */ - public int getSourcePortNumber() { - - return iSrcPort; - - } - - /** - * getDestinationPortNumber() method - * - * @return int - */ - public int getDestinationPortNumber() { - - return iDstPort; - - } - - /** - * setSrcPort() method - * - * @param port Port number - * @return void - */ - public void setSrcPort(int port) { - if (isSrcPortWildCard) { - iSrcPort = port; - } - } - - /** - * setDstPort() method - * - * @param port Port number - * @return void - */ - public void setDstPort(int port) { - if (isDstPortWildCard) { - iDstPort = port; - } - } - - /** - * getAddress() method - * - * @return String - */ - public String getAddress() { - return sAddress; - } - - /** - * getHostAddress() method - * - * @return String - */ - public static String getLocalHostAddress() { - - String strLocalHostAddress = null; - try { - strLocalHostAddress = InetAddress.getLocalHost().getHostAddress(); - } catch (UnknownHostException ex) { - ex.printStackTrace(); - } - return strLocalHostAddress; - } - - /** - * getIsSrcPortWildcard() method - * - * @return boolean - */ - public boolean getIsSrcPortWildcard() { - return isSrcPortWildCard; - } - - /** - * getIsDstPortWildcard() method - * - * @return boolean - */ - public boolean getIsDstPortWildcard() { - return isDstPortWildCard; - } -} diff --git a/benchmarks/other/ZigbeeTest/IoTRelation.java b/benchmarks/other/ZigbeeTest/IoTRelation.java deleted file mode 100644 index 438b3d3..0000000 --- a/benchmarks/other/ZigbeeTest/IoTRelation.java +++ /dev/null @@ -1,105 +0,0 @@ - -import java.lang.UnsupportedOperationException; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - - -/** Class IoTRelation is the actual implementation of @config IoTRelation<...>. - * Upon extracting DB information, RelationInstrumenter class will use - * this class to actually instantiate the Map as IoTRelation uses a - * combination between a HashMap and a IoTSet; we don't provide interfaces - * to modify the contents, but we do provide means to read them out. - * The add method is just used the first time it is needed to add new objects, - * then it is going to be made immutable - * - * @author Rahmadi Trimananda - * @version 1.0 - * @since 2015-12-01 - */ -public final class IoTRelation { - - /** - * Reference to an object Map - */ - private Map > mapRelation; - private int iSize; - - /** - * Class constructor (pass the reference to this immutable wrapper) - */ - protected IoTRelation(Map> mapRel, int _iSize) { - mapRelation = mapRel; - iSize = _iSize; - } - - /** - * Method containsKey() inherited from Map interface - * - * @param key The first Object that is usually a key in a Map - * @return boolean - */ - public boolean containsKey(K key) { - - return mapRelation.containsKey(key); - - } - - /** - * Method entrySet() inherited from Map interface - * - * @return Set>> - */ - public Set>> entrySet() { - - return new HashSet>>(mapRelation.entrySet()); - - } - - /** - * Method keySet() inherited from Map interface - * - * @return Set - */ - public Set keySet() { - - return new HashSet(mapRelation.keySet()); - - } - - /** - * Method get() inherited from Map interface - * - * @param key The first Object that is usually a key in a Map - * @return HashSet - */ - public HashSet get(K key) { - - return new HashSet(mapRelation.get(key)); - - } - - /** - * Method isEmpty() inherited from Map interface - * - * @return boolean - */ - public boolean isEmpty() { - - return mapRelation.isEmpty(); - - } - - /** - * size() method - * - * @return int - */ - public int size() { - - return this.iSize; - - } -} diff --git a/benchmarks/other/ZigbeeTest/IoTSet.java b/benchmarks/other/ZigbeeTest/IoTSet.java deleted file mode 100644 index 0f316cd..0000000 --- a/benchmarks/other/ZigbeeTest/IoTSet.java +++ /dev/null @@ -1,80 +0,0 @@ - -import java.lang.UnsupportedOperationException; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.Spliterator; - - -/** Class IoTSet is the actual implementation of @config IoTSet<...>. - * Upon extracting DB information, SetInstrumenter class will use - * this class to actually instantiate the Set as IoTSet that uses - * Java Set to implement; we don't provide interfaces to modify - * the contents, but we do provide means to read them out - * - * @author Rahmadi Trimananda - * @version 1.0 - * @since 2015-12-01 - */ -public final class IoTSet { - - /** - * Reference to an object Set - */ - private Set set; - - /** - * Class constructor (pass the reference to this immutable wrapper) - */ - public IoTSet(Set s) { - - set = s; - } - - /** - * contains() method inherited from Set interface - */ - public boolean contains(T o) { - - return set.contains(o); - - } - - /** - * isEmpty() method inherited from Set interface - */ - public boolean isEmpty() { - - return set.isEmpty(); - - } - - /** - * iterator() method inherited from Set interface - */ - public Iterator iterator() { - - return new HashSet(set).iterator(); - - } - - /** - * size() method inherited from Set interface - */ - public int size() { - - return set.size(); - - } - - /** - * values() method to return Set object values for easy iteration - */ - public Set values() { - - return new HashSet(set); - - } -} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbee.java b/benchmarks/other/ZigbeeTest/IoTZigbee.java deleted file mode 100644 index dd12352..0000000 --- a/benchmarks/other/ZigbeeTest/IoTZigbee.java +++ /dev/null @@ -1,542 +0,0 @@ - -// Java packages -import java.io.IOException; -import java.net.DatagramPacket; -import java.net.DatagramSocket; -import java.net.InetAddress; -import java.net.SocketException; -import java.net.UnknownHostException; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.List; -import java.util.ArrayList; -import java.util.Map; -import java.util.HashMap; -import java.util.concurrent.ConcurrentHashMap; -import java.util.Set; -import java.util.HashSet; -import java.nio.charset.StandardCharsets; -import java.util.concurrent.Semaphore; - - -/** Class IoTZigbee - * - * @author Ali Younis , Changwoo Lee - * @version 1.0 - * @since 2016-04-12, 2016-10-28 - */ -public class IoTZigbee { - - public final int SOCKET_SEND_BUFFER_SIZE = 1024; - public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024; - public final int SHORT_ADDRESS_UPDATE_TIME_MSEC = 10000; - public final int SHORT_ADDRESS_UPDATE_TIME_FAST_MSEC = 500; - public final int RESEND_WAIT_TIME = 500; - - /** - * IoTZigbee class properties - */ - - // UDP connection stuff - private final String strHostAddress; - private final int iSrcPort; - private final int iDstPort; - private DatagramSocket socket; // the socket interface that we are guarding - private boolean didClose; // make sure that the clean up was done correctly - - private final IoTZigbeeAddress zigbeeAddress; - - // list that holds the callbacks - private List callbackList = new ArrayList(); - - /** - * IoTZigbee class concurrency and concurrency control - */ - private Thread receiveThread = null; - - private AtomicBoolean endTask = new AtomicBoolean(false); - private AtomicBoolean didSuccesfullySendAddress = new AtomicBoolean(false); - - /** - * Class constructor - */ - public IoTZigbee(IoTDeviceAddress iotDevAdd, IoTZigbeeAddress zigAddress) throws SocketException, IOException, InterruptedException { - - strHostAddress = iotDevAdd.getHostAddress(); - iSrcPort = iotDevAdd.getSourcePortNumber(); - iDstPort = iotDevAdd.getDestinationPortNumber(); - didClose = false; - zigbeeAddress = zigAddress; - - socket = new DatagramSocket(iSrcPort); - socket.setSendBufferSize(SOCKET_SEND_BUFFER_SIZE); - socket.setReceiveBufferSize(SOCKET_RECEIVE_BUFFER_SIZE); - - receiveThread = new Thread(new Runnable() { - public void run() { - receieveWorker(); - } - }); - receiveThread.start(); - } - - public void init() throws IOException { - while (!didSuccesfullySendAddress.get()) { - - sendDeviceAddress(); - - try { - Thread.sleep(RESEND_WAIT_TIME); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - //made by changwoo - public void sendChangeSwtichRequest(int packetId, int clusterId, int profileId, int value, int deviceEndpoint) throws IOException { - String message = "type: zcl_change_switch_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 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"; - message += "packet_id: " + String.format("%04x", packetId) + "\n"; - message += "device_address_long: " + zigbeeAddress.getAddress() + "\n"; - DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort); - socket.send(sendPacket); - } - - //made by changwoo - public void sendEnrollmentResponse(int packetId, int clusterId, int profileId, int deviceEndpoint) throws IOException { - String message = "type: zcl_enrollment_response\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"; - DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort); - socket.send(sendPacket); - } - - //made by changwoo - public void sendWriteAttributesCommand(int packetId, int clusterId, int profileId, int deviceEndpoint) throws IOException { - String message = "type: zcl_write_attributes\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"; - DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort); - socket.send(sendPacket); - } - - //made by changwoo - public void sendManagementPermitJoiningRequest(int packetId, int clusterId, int deviceEndpoint) throws IOException { - String message = "type: management_permit_joining_request\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 += "device_endpoint: " + String.format("%02x", deviceEndpoint) + "\n"; - DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort); - socket.send(sendPacket); - } - - public void sendBindRequest(int packetId, int clusterId, int deviceEndpoint) throws IOException { - String message = "type: zdo_bind_request\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 += "device_endpoint: " + String.format("%02x", deviceEndpoint) + "\n"; - DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort); - socket.send(sendPacket); - } - - public void sendUnBindRequest(int packetId, int clusterId, int deviceEndpoint) throws IOException { - String message = "type: zdo_unbind_request\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 += "device_endpoint: " + String.format("%02x", deviceEndpoint) + "\n"; - DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort); - socket.send(sendPacket); - } - - public void sendReadAttributesCommand(int packetId, int clusterId, int profileId, int deviceEndpoint, List attributeIds) throws IOException { - String message = "type: zcl_read_attributes\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 += "attribute_ids: "; - - for (Integer i : attributeIds) { - message += String.format("%04x", i) + ","; - } - - message = message.substring(0, message.length() - 1); - message += "\n"; - - DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort); - socket.send(sendPacket); - } - - 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 += "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"; - message += "max_reporting_interval: " + String.format("%04x", maxReportingInterval) + "\n"; - - if (reportableChange != null) { - message += "reportable_change: "; - for (Byte b : reportableChange) { - message += String.format("%02x", (int)b); - } - message += "\n"; - } - - DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort); - 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); - - } - - public void close() throws InterruptedException { - endTask.set(true); - - // wait for the threads to end - receiveThread.join(); - - socket.close(); - didClose = true; - } - - /** - * close() called by the garbage collector right before trashing object - */ - public void Finalize() throws SocketException, InterruptedException { - - if (!didClose) { - close(); - throw new SocketException("Socket not closed before object destruction, must call close method."); - } - } - - private void sendDeviceAddress() throws IOException { - 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); - } - - private void receieveWorker() { - while (!(endTask.get())) { - - byte[] recBuffer = new byte[SOCKET_RECEIVE_BUFFER_SIZE]; - try { - DatagramPacket recPacket = new DatagramPacket(recBuffer, recBuffer.length); - socket.receive(recPacket); - - // Convert the UDP data into a string format - String dataString = new String(recPacket.getData()); - - // split the data by line so we can start procesisng - String[] lines = dataString.split("\n"); - - Map packetData = new HashMap(); - for (String line : lines) { - - // trim the line - String trimmedLine = line.trim(); - // make sure this is a valid data line and not just blank - if (trimmedLine.length() == 0) { - continue; - } - - // Split the data into parts - String[] parts = trimmedLine.split(":"); - parts[0] = parts[0].trim(); - parts[1] = parts[1].trim(); - packetData.put(parts[0], parts[1]); - } - - if (packetData.get("type").equals("send_address_response")) { - didSuccesfullySendAddress.set(true); - - } else { - IoTZigbeeMessage callbackMessage = null; - -/* - // made by changwoo - if (packetData.get("type").equals("zcl_match_descriptor_response")) { - System.out.println("zcl_match_descriptor_response message arrives"); - - 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); - boolean successOrFail = false; - if(packetData.get("attributes").equals("success")) successOrFail=true; - - callbackMessage = new IoTZigbeeMessageMatchDescriptorResponse(packetId, clusterId, profileId, successOrFail); - - } -*/ - - // made by changwoo - if (packetData.get("type").equals("zcl_zone_status_change_notification")){ - 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 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")) { - - 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); - boolean successOrFail = false; - if(packetData.get("attributes").equals("success")) successOrFail=true; - - callbackMessage = new IoTZigbeeMessageZclWriteAttributesResponse(packetId, clusterId, profileId, successOrFail); - - } else if (packetData.get("type").equals("zcl_read_attributes_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); - - List attrList = new ArrayList(); - - String[] attributes = packetData.get("attributes").split(";"); - for (String attr : attributes) { - attr = attr.trim(); - String[] parts = attr.split(","); - - if (parts.length == 2) { - parts[0] = parts[0].trim(); - parts[1] = parts[1].trim(); - - IoTZigbeeMessageZclReadAttributesResponse.Attribute at = new IoTZigbeeMessageZclReadAttributesResponse.Attribute(Integer.parseInt(parts[0], 16), 0, false, null); - attrList.add(at); - } else { - parts[0] = parts[0].trim(); - parts[1] = parts[1].trim(); - parts[2] = parts[2].trim(); - parts[3] = parts[3].trim(); - IoTZigbeeMessageZclReadAttributesResponse.Attribute at = new IoTZigbeeMessageZclReadAttributesResponse.Attribute(Integer.parseInt(parts[0], 16), Integer.parseInt(parts[1], 16), true, hexStringToByteArray(parts[3])); - attrList.add(at); - } - } - - callbackMessage = new IoTZigbeeMessageZclReadAttributesResponse(packetId, clusterId, profileId, attrList); - - } else if (packetData.get("type").equals("zcl_configure_reporting_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); - - if (packetData.get("attributes").equals("all_success")) { - callbackMessage = new IoTZigbeeMessageZclConfigureReportingResponse(packetId, clusterId, profileId, true, null); - } else { - List attrList = new ArrayList(); - - String[] attributes = packetData.get("attributes").split(";"); - for (String attr : attributes) { - attr = attr.trim(); - String[] parts = attr.split(","); - parts[0] = parts[0].trim(); - parts[1] = parts[1].trim(); - parts[2] = parts[2].trim(); - IoTZigbeeMessageZclConfigureReportingResponse.Attribute at = new IoTZigbeeMessageZclConfigureReportingResponse.Attribute(Integer.parseInt(parts[0], 16), parts[1].equals("success"), parts[2].equals("reported")); - attrList.add(at); - } - callbackMessage = new IoTZigbeeMessageZclConfigureReportingResponse(packetId, clusterId, profileId, false, attrList); - } - - } else if (packetData.get("type").equals("zcl_report_attributes")) { - 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); - - List attrList = new ArrayList(); - - String[] attributes = packetData.get("attributes").split(";"); - for (String attr : attributes) { - attr = attr.trim(); - String[] parts = attr.split(","); - - parts[0] = parts[0].trim(); - parts[1] = parts[1].trim(); - parts[2] = parts[2].trim(); - IoTZigbeeMessageZclReportAttributes.Attribute at = new IoTZigbeeMessageZclReportAttributes.Attribute(Integer.parseInt(parts[0], 16), Integer.parseInt(parts[1], 16), hexStringToByteArray(parts[2])); - attrList.add(at); - } - - callbackMessage = new IoTZigbeeMessageZclReportAttributes(packetId, clusterId, profileId, attrList); - - } else if (packetData.get("type").equals("zcl_read_attributes")) { - int packetId = Integer.parseInt(packetData.get("packet_id"), 16); - boolean success = packetData.get("response").equals("success"); - - if (success) { - callbackMessage = new IoTZigbeeMessageZclReadAttributes(packetId, success, ""); - } else { - callbackMessage = new IoTZigbeeMessageZclReadAttributes(packetId, success, packetData.get("reason")); - } - - } else if (packetData.get("type").equals("zcl_configure_reporting")) { - int packetId = Integer.parseInt(packetData.get("packet_id"), 16); - boolean success = packetData.get("response").equals("success"); - - if (success) { - callbackMessage = new IoTZigbeeMessageZclConfigureReporting(packetId, success, ""); - } else { - callbackMessage = new IoTZigbeeMessageZclConfigureReporting(packetId, success, packetData.get("reason")); - } - - } else if (packetData.get("type").equals("zdo_bind_request")) { - int packetId = Integer.parseInt(packetData.get("packet_id"), 16); - boolean success = packetData.get("response").equals("success"); - - if (success) { - callbackMessage = new IoTZigbeeMessageZdoBindResponse(packetId, success, ""); - } else { - callbackMessage = new IoTZigbeeMessageZdoBindResponse(packetId, success, packetData.get("reason")); - } - } - - else if (packetData.get("type").equals("zdo_unbind_request")) { - int packetId = Integer.parseInt(packetData.get("packet_id"), 16); - boolean success = packetData.get("response").equals("success"); - - if (success) { - callbackMessage = new IoTZigbeeMessageZdoUnBindResponse(packetId, success, ""); - } else { - callbackMessage = new IoTZigbeeMessageZdoUnBindResponse(packetId, success, packetData.get("reason")); - } - } - - if (callbackMessage != null) { - for (IoTZigbeeCallback c : callbackList) { - c.newMessageAvailable(callbackMessage); - } - } - } - - - - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - public static String changeHexEndianness(String hexData) { - - List pairedValues = new ArrayList(); - for (int i = 0; i < hexData.length(); i += 2) { - String part = hexData.substring(i, Math.min(i + 2, hexData.length())); - pairedValues.add(part); - } - - String retString = ""; - for (int i = (pairedValues.size() - 1); i >= 0; i--) { - retString += pairedValues.get(i); - } - return retString; - } - - // taken from: http://stackoverflow.com/questions/140131/convert-a-string-representation-of-a-hex-dump-to-a-byte-array-using-java - public static byte[] hexStringToByteArray(String s) { - int len = s.length(); - byte[] data = new byte[len / 2]; - for (int i = 0; i < len; i += 2) { - data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) - + Character.digit(s.charAt(i + 1), 16)); - } - return data; - } - -} - - - - - - - - - - - - - - - - diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeAddress.java b/benchmarks/other/ZigbeeTest/IoTZigbeeAddress.java deleted file mode 100644 index e15c518..0000000 --- a/benchmarks/other/ZigbeeTest/IoTZigbeeAddress.java +++ /dev/null @@ -1,49 +0,0 @@ - -/** Class IoTZigbeeAddress is a wrapper class to pass - * IoTSet of device addresses from master to slave - * - * @author Ali Younis - * @version 1.0 - * @since 2016-04-12 - */ -public class IoTZigbeeAddress { - - /** - * IoTZigbeeAddress class properties - */ - private final String zigbeeAddress; - private final byte[] zigbeeAddressByteArray; - - /** - * Class constructor - * - * @param zAddress Zigbee long address - */ - public IoTZigbeeAddress(String zAddress) { - zigbeeAddress = zAddress; - // convert to byte array - zigbeeAddressByteArray = new byte[zAddress.length() / 2]; - for (int i = 0; i < zAddress.length(); i += 2) { - zigbeeAddressByteArray[i / 2] = (byte) ((Character.digit(zAddress.charAt(i), 16) << 4) - + Character.digit(zAddress.charAt(i + 1), 16)); - } - } - - /** - * getAddress() method that returns the zigbee address as a human readable String - * - * @return String - */ - public String getAddress() { - return zigbeeAddress; - } - - /** - * getAddressBytes() method that returns the zigbee address as a byte array - * - * @return byte[] - */ - public byte[] getAddressBytes() { - return zigbeeAddressByteArray; - } -} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeCallback.java b/benchmarks/other/ZigbeeTest/IoTZigbeeCallback.java deleted file mode 100644 index 94d75db..0000000 --- a/benchmarks/other/ZigbeeTest/IoTZigbeeCallback.java +++ /dev/null @@ -1,17 +0,0 @@ - -/** Zigbee Callback for when a zigbee message is received. - * - * @author Ali Younis - * @version 1.0 - * @since 2016-04-12 - */ -public interface IoTZigbeeCallback { - - /** Callback method for when data comes from the zigbee object - * - * @param zigbee message class [IoTZigbeeMessage] . - * - * @return [void] None. - */ - public void newMessageAvailable(IoTZigbeeMessage _zm); -} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessage.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessage.java deleted file mode 100644 index c1df838..0000000 --- a/benchmarks/other/ZigbeeTest/IoTZigbeeMessage.java +++ /dev/null @@ -1,30 +0,0 @@ - -/** Zigbee Message generic class. - * - * @author Ali Younis - * @version 1.0 - * @since 2016-04-19 - */ -public class IoTZigbeeMessage { - - // private variables - private int packetId; - - /** - * Constructor - */ - public IoTZigbeeMessage(int _packetId) { - packetId = _packetId; - } - - - /** - * getPacketId() method that returns the packet id of the received message - * - * @return int - */ - public int getPacketId() { - return packetId; - } - -} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageSendAddressResponse.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageSendAddressResponse.java deleted file mode 100644 index cfb31c1..0000000 --- a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageSendAddressResponse.java +++ /dev/null @@ -1,31 +0,0 @@ - - -/** Zigbee Message Send Address Response. - * - * @author Ali Younis - * @version 1.0 - * @since 2016-04-19 - */ -public class IoTZigbeeMessageSendAddressResponse extends IoTZigbeeMessage { - - // private variables - private boolean succeeded; - private String message; - - /** - * Constructor - */ - public IoTZigbeeMessageSendAddressResponse(int _packetId, boolean _succeded) { - super(_packetId); - succeeded = _succeded; - } - - /** - * getSucceeded() method that returns the success status - * - * @return boolean - */ - public boolean getSucceeded() { - return succeeded; - } -} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclChangeSwitchResponse.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclChangeSwitchResponse.java deleted file mode 100644 index 0071d22..0000000 --- a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclChangeSwitchResponse.java +++ /dev/null @@ -1,37 +0,0 @@ -/** Zigbee Message Zcl Change Switch Response - * - * @author Yuting Tan - * @version 1.0 - * @since 2017-2-28 - */ -public class IoTZigbeeMessageZclChangeSwitchResponse extends IoTZigbeeMessage { - - private boolean SuccessOrFail=false; - private int clusterId; - private int profileId; - private int status; - - public IoTZigbeeMessageZclChangeSwitchResponse(int _packetId, int _clusterId, int _profileId, int _status, boolean _SuccessOrFail){ - super(_packetId); - - clusterId = _clusterId; - profileId = _profileId; - status = _status; - SuccessOrFail = _SuccessOrFail; - } - public boolean getSuccessOrFail(){ - return SuccessOrFail; - } - - public int getClusterId() { - return clusterId; - } - - public int getProfileId() { - return profileId; - } - - public int getStatus(){ - return status; - } -} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclConfigureReporting.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclConfigureReporting.java deleted file mode 100644 index 60a98cb..0000000 --- a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclConfigureReporting.java +++ /dev/null @@ -1,41 +0,0 @@ - -/** Zigbee Message Zcl Configure Reporting. - * - * @author Ali Younis - * @version 1.0 - * @since 2016-04-19 - */ -public class IoTZigbeeMessageZclConfigureReporting extends IoTZigbeeMessage { - - // private variables - private boolean succeeded; - private String message; - - /** - * Constructor - */ - public IoTZigbeeMessageZclConfigureReporting(int _packetId, boolean _succeded, String _message) { - super(_packetId); - message = _message; - succeeded = _succeded; - } - - - /** - * getSucceeded() method that returns the success status - * - * @return boolean - */ - public boolean getSucceeded() { - return succeeded; - } - - /** - * getMessage() method that returns the error message - * - * @return String - */ - public String getMessage() { - return message; - } -} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclConfigureReportingResponse.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclConfigureReportingResponse.java deleted file mode 100644 index 05fda4b..0000000 --- a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclConfigureReportingResponse.java +++ /dev/null @@ -1,109 +0,0 @@ - -import java.util.List; - -/** Zigbee Message Zcl Configure Reporting Response. - * - * @author Ali Younis - * @version 1.0 - * @since 2016-04-19 - */ -public class IoTZigbeeMessageZclConfigureReportingResponse extends IoTZigbeeMessage { - - static public class Attribute { - - // private variables - private int attributeId; - private boolean successOrFail; - private boolean isReport; - - /** - * Constructor - */ - public Attribute(int _attributeId, boolean _successOrFail, boolean _isReport) { - attributeId = _attributeId; - successOrFail = _successOrFail; - isReport = _isReport; - } - - /** - * getAttributeId() method that returns attribute id - * - * @return int - */ - public int getAttributeId() { - return attributeId; - } - - /** - * getIsReport() method that gets if the direction is report of receive - * - * @return boolean - */ - public boolean getIsReport() { - return isReport; - } - - /** - * getSuccessOrFail() method is if the configure for this attribute failed or succeeded - * - * @return boolean - */ - public boolean getSuccessOrFail() { - return successOrFail; - } - } - - // private variables - private int clusterId; - private int profileId; - private boolean allSuccess; - private List attributes; - - /** - * Constructor - */ - public IoTZigbeeMessageZclConfigureReportingResponse(int _packetId, int _clusterId, int _profileId, boolean _allSuccess, List _attributes) { - super(_packetId); - - clusterId = _clusterId; - profileId = _profileId; - allSuccess = _allSuccess; - attributes = _attributes; - } - - /** - * getAllSuccess() method that returns if all the configurations succeeded - * - * @return boolean - */ - public boolean getAllSuccess() { - return allSuccess; - } - - /** - * getClusterId() method that returns the cluster id - * - * @return int - */ - public int getClusterId() { - return clusterId; - } - - /** - * getProfileId() method that returns the profile id - * - * @return int - */ - public int getProfileId() { - return profileId; - } - - /** - * getAttributes() method that returns if all attributes if one of there was a failure to configure - * - * @return List - */ - public List getAttributes() { - return attributes; - } -} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclReadAttributes.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclReadAttributes.java deleted file mode 100644 index bb20d9d..0000000 --- a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclReadAttributes.java +++ /dev/null @@ -1,40 +0,0 @@ - -/** Zigbee Message Zcl Read Attributes. - * - * @author Ali Younis - * @version 1.0 - * @since 2016-04-19 - */ -public class IoTZigbeeMessageZclReadAttributes extends IoTZigbeeMessage { - - // private variables - private boolean succeeded; - private String message; - - /** - * Constructor - */ - public IoTZigbeeMessageZclReadAttributes(int _packetId, boolean _succeded, String _message) { - super(_packetId); - message = _message; - succeeded = _succeded; - } - - /** - * getSucceeded() method that returns the success status - * - * @return boolean - */ - public boolean getSucceeded() { - return succeeded; - } - - /** - * getMessage() method that returns the error message - * - * @return String - */ - public String getMessage() { - return message; - } -} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclReadAttributesResponse.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclReadAttributesResponse.java deleted file mode 100644 index bd6f75a..0000000 --- a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclReadAttributesResponse.java +++ /dev/null @@ -1,113 +0,0 @@ - -import java.util.List; - -/** Zigbee Message Zcl Read Attributes Response. - * - * @author Ali Younis - * @version 1.0 - * @since 2016-04-19 - */ -public class IoTZigbeeMessageZclReadAttributesResponse extends IoTZigbeeMessage { - - static class Attribute { - - // private variables - private int attributeId; - private int dataType; - private boolean successOrFail; - private byte[] data; - - /** - * Constructor - */ - public Attribute(int _attributeId, int _dataType, boolean _successOrFail, byte[] _data) { - attributeId = _attributeId; - dataType = _dataType; - successOrFail = _successOrFail; - data = _data; - } - - - /** - * getAttributeId() method that returns attribute id - * - * @return int - */ - public int getAttributeId() { - return attributeId; - } - - - /** - * getDataType() method that returns attribute data type - * - * @return int - */ - public int getDataType() { - return dataType; - } - - - /** - * getSuccessOrFail() method is if the configure for this attribute failed or succeeded - * - * @return boolean - */ - public boolean getSuccessOrFail() { - return successOrFail; - } - - - /** - * getData() method that returns attribute data - * - * @return byte[] - */ - public byte[] getData() { - return data; - } - } - - // private variables - private int clusterId; - private int profileId; - private List attributes; - - /** - * Constructor - */ - public IoTZigbeeMessageZclReadAttributesResponse(int _packetId, int _clusterId, int _profileId, List _attributes) { - super(_packetId); - - clusterId = _clusterId; - profileId = _profileId; - attributes = _attributes; - } - - /** - * getClusterId() method that returns the cluster id - * - * @return int - */ - public int getClusterId() { - return clusterId; - } - - /** - * getProfileId() method that returns the profile id - * - * @return int - */ - public int getProfileId() { - return profileId; - } - - /** - * getAttributes() method that returns all attributes data - * - * @return List - */ - public List getAttributes() { - return attributes; - } -} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclReportAttributes.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclReportAttributes.java deleted file mode 100644 index de1bfd0..0000000 --- a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclReportAttributes.java +++ /dev/null @@ -1,101 +0,0 @@ - -import java.util.List; - -/** Zigbee Message Zcl Report Attributes. - * - * @author Ali Younis - * @version 1.0 - * @since 2016-04-19 - */ -public class IoTZigbeeMessageZclReportAttributes extends IoTZigbeeMessage { - - static public class Attribute { - - // private variables - private int attributeId; - private int dataType; - private byte[] data; - - /** - * Constructor - */ - public Attribute(int _attributeId, int _dataType, byte[] _data) { - attributeId = _attributeId; - dataType = _dataType; - data = _data; - } - - /** - * getAttributeId() method that returns attribute id - * - * @return int - */ - public int getAttributeId() { - return attributeId; - } - - - /** - * getDataType() method that returns attribute data type - * - * @return int - */ - public int getDataType() { - return dataType; - } - - - /** - * getData() method that returns attribute data - * - * @return byte[] - */ - public byte[] getData() { - return data; - } - - } - - // private variables - private int clusterId; - private int profileId; - private List attributes; - - /** - * Constructor - */ - public IoTZigbeeMessageZclReportAttributes(int _packetId, int _clusterId, int _profileId, List _attributes) { - super(_packetId); - - clusterId = _clusterId; - profileId = _profileId; - attributes = _attributes; - } - - /** - * getClusterId() method that returns the cluster id - * - * @return int - */ - public int getClusterId() { - return clusterId; - } - - /** - * getProfileId() method that returns the profile id - * - * @return int - */ - public int getProfileId() { - return profileId; - } - - /** - * getAttributes() method that returns all attributes data - * - * @return List - */ - public List getAttributes() { - return attributes; - } -} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclWriteAttributesResponse.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclWriteAttributesResponse.java deleted file mode 100644 index ac045c8..0000000 --- a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclWriteAttributesResponse.java +++ /dev/null @@ -1,31 +0,0 @@ -/** Zigbee Message Zcl Write Attributes Response. - * - * @author changwoo Lee - * @version 1.0 - * @since 2016-10-18 - */ -public class IoTZigbeeMessageZclWriteAttributesResponse extends IoTZigbeeMessage { - - private boolean SuccessOrFail=false; - private int clusterId; - private int profileId; - - public IoTZigbeeMessageZclWriteAttributesResponse(int _packetId, int _clusterId, int _profileId, boolean _SuccessOrFail){ - super(_packetId); - - clusterId = _clusterId; - profileId = _profileId; - SuccessOrFail = _SuccessOrFail; - } - public boolean getSuccessOrFail(){ - return SuccessOrFail; - } - - public int getClusterId() { - return clusterId; - } - - public int getProfileId() { - return profileId; - } -} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclZoneStatusChangeNotification.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclZoneStatusChangeNotification.java deleted file mode 100644 index fd633fe..0000000 --- a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclZoneStatusChangeNotification.java +++ /dev/null @@ -1,37 +0,0 @@ -/** Zigbee Message Zcl Zone Status Change Notification. - * - * @author changwoo Lee - * @version 1.0 - * @since 2016-10-28 - */ -public class IoTZigbeeMessageZclZoneStatusChangeNotification extends IoTZigbeeMessage { - - private boolean SuccessOrFail=false; - private int clusterId; - private int profileId; - private int status; - - public IoTZigbeeMessageZclZoneStatusChangeNotification(int _packetId, int _clusterId, int _profileId, int _status, boolean _SuccessOrFail){ - super(_packetId); - - clusterId = _clusterId; - profileId = _profileId; - status = _status; - SuccessOrFail = _SuccessOrFail; - } - public boolean getSuccessOrFail(){ - return SuccessOrFail; - } - - public int getClusterId() { - return clusterId; - } - - public int getProfileId() { - return profileId; - } - - public int getStatus(){ - return status; - } -} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZdoBindResponse.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZdoBindResponse.java deleted file mode 100644 index f1d27d4..0000000 --- a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZdoBindResponse.java +++ /dev/null @@ -1,40 +0,0 @@ - -/** Zigbee Message Zdo Bind Response. - * - * @author Ali Younis - * @version 1.0 - * @since 2016-04-19 - */ -public class IoTZigbeeMessageZdoBindResponse extends IoTZigbeeMessage { - - // private variables - private boolean succeeded; - private String message; - - /** - * Constructor - */ - public IoTZigbeeMessageZdoBindResponse(int _packetId, boolean _succeded, String _message) { - super(_packetId); - message = _message; - succeeded = _succeded; - } - - /** - * getSucceeded() method that returns the success status - * - * @return boolean - */ - public boolean getSucceeded() { - return succeeded; - } - - /** - * getMessage() method that returns the error message - * - * @return String - */ - public String getMessage() { - return message; - } -} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZdoUnBindResponse.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZdoUnBindResponse.java deleted file mode 100644 index edb5534..0000000 --- a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZdoUnBindResponse.java +++ /dev/null @@ -1,40 +0,0 @@ - -/** Zigbee Message Zdo UnBind Response. - * - * @author Ali Younis - * @version 1.0 - * @since 2016-05-04 - */ -public class IoTZigbeeMessageZdoUnBindResponse extends IoTZigbeeMessage { - - // private variables - private boolean succeeded; - private String message; - - /** - * Constructor - */ - public IoTZigbeeMessageZdoUnBindResponse(int _packetId, boolean _succeded, String _message) { - super(_packetId); - message = _message; - succeeded = _succeded; - } - - /** - * getSucceeded() method that returns the success status - * - * @return boolean - */ - public boolean getSucceeded() { - return succeeded; - } - - /** - * getMessage() method that returns the error message - * - * @return String - */ - public String getMessage() { - return message; - } -} diff --git a/benchmarks/other/ZigbeeTest/Makefile b/benchmarks/other/ZigbeeTest/Makefile new file mode 100644 index 0000000..a425dab --- /dev/null +++ b/benchmarks/other/ZigbeeTest/Makefile @@ -0,0 +1,36 @@ + +BASE := ../../../ + +include $(BASE)/common.mk + +all: build + +PHONY += build +build: + javac -cp ./zbtest.jar:. *.java + +PHONY += clean +clean: + rm -rf *.class + +PHONY += run-moisture +run-moisture: + java -cp ./zbtest.jar:. ZigbeeTestMoisture + +PHONY += run-motion +run-motion: + java -cp ./zbtest.jar:. ZigbeeTestMotion + +PHONY += run-multipurpose +run-multipurpose: + java -cp ./zbtest.jar:. ZigbeeTestMultipurpose + +PHONY += run-waterleak +run-waterleak: + java -cp ./zbtest.jar:. ZigbeeTestWaterleak + +PHONY += run-doorlock +run-doorlock: + java -cp ./zbtest.jar:. ZigbeeTestDoorlock + +.PHONY: $(PHONY) diff --git a/benchmarks/other/ZigbeeTest/MoistureSensor.java b/benchmarks/other/ZigbeeTest/MoistureSensor.java deleted file mode 100644 index 573bd70..0000000 --- a/benchmarks/other/ZigbeeTest/MoistureSensor.java +++ /dev/null @@ -1,11 +0,0 @@ -import java.util.List; -import java.util.ArrayList; - -public interface MoistureSensor { - public void init(); - public float getMoisture(); - public long getTimestampOfLastReading(); - public void setId(int id); - public int getId(); - public void registerCallback(MoistureSensorSmartCallback _callbackTo); -} diff --git a/benchmarks/other/ZigbeeTest/MoistureSensorCallback.java b/benchmarks/other/ZigbeeTest/MoistureSensorCallback.java deleted file mode 100644 index d45e698..0000000 --- a/benchmarks/other/ZigbeeTest/MoistureSensorCallback.java +++ /dev/null @@ -1,6 +0,0 @@ -import java.util.List; -import java.util.ArrayList; - -public interface MoistureSensorCallback { - public void newReadingAvailable(int sensorId, float moisture, long timeStampOfLastReading); -} diff --git a/benchmarks/other/ZigbeeTest/MoistureSensorSmart.java b/benchmarks/other/ZigbeeTest/MoistureSensorSmart.java deleted file mode 100644 index 1496146..0000000 --- a/benchmarks/other/ZigbeeTest/MoistureSensorSmart.java +++ /dev/null @@ -1,12 +0,0 @@ -import java.util.List; -import java.util.ArrayList; - -public interface MoistureSensorSmart { - - public long getTimestampOfLastReading(); - public int getId(); - public void registerCallback(MoistureSensorCallback _callbackTo); - public float getMoisture(); - public void setId(int id); - public void init(); -} diff --git a/benchmarks/other/ZigbeeTest/MoistureSensorSmartCallback.java b/benchmarks/other/ZigbeeTest/MoistureSensorSmartCallback.java deleted file mode 100644 index c69e9cc..0000000 --- a/benchmarks/other/ZigbeeTest/MoistureSensorSmartCallback.java +++ /dev/null @@ -1,7 +0,0 @@ -import java.util.List; -import java.util.ArrayList; - -public interface MoistureSensorSmartCallback { - - public void newReadingAvailable(int sensorId, float moisture, long timeStampOfLastReading); -} diff --git a/benchmarks/other/ZigbeeTest/MotionSensor.java b/benchmarks/other/ZigbeeTest/MotionSensor.java deleted file mode 100644 index 5fe888a..0000000 --- a/benchmarks/other/ZigbeeTest/MotionSensor.java +++ /dev/null @@ -1,225 +0,0 @@ -// Standard Java Packages -import java.util.*; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.Semaphore; - -// Checker annotations -//import iotchecker.qual.*; -//import iotcode.annotation.*; - -// IoT Packages -import iotruntime.slave.*; -//import iotcode.interfaces.*; -import iotruntime.zigbee.*; - -/** Class Smartthings sensor driver for Smartthings sensor devices. - * - * @author Changwoo Lee, Rahmadi Trimananda - * @version 1.0 - * @since 2016-12-01 - */ -public class MotionSensor implements IoTZigbeeCallback, SmartthingsSensor { - - private final int TIMEOUT_FOR_RESEND_MSEC = 900; - - private IoTZigbee zigConnection = null; - private boolean didClose; // make sure that the clean up was done correctly - private boolean detectStatus = false; - - private int detectedValue = 0; - private Date timestampOfLastDetecting = null; - - private AtomicBoolean didAlreadyClose = new AtomicBoolean(true); - private AtomicBoolean didAlreadyInit = new AtomicBoolean(false); - private AtomicBoolean didWriteAttrb = new AtomicBoolean(false); - private AtomicBoolean didMatchDscr = new AtomicBoolean(false); - static Semaphore gettingLatestDataMutex = new Semaphore(1); - - private List < SmartthingsSensorCallback > callbackList = new CopyOnWriteArrayList < SmartthingsSensorCallback > (); - - @config private IoTSet devUdpAddress; - @config private IoTSet devZigbeeAddress; - - public MotionSensor(IoTSet dSet, IoTSet zigSet) { - devUdpAddress = dSet; - devZigbeeAddress = zigSet; - } - - public void init() { - - if (didAlreadyInit.compareAndSet(false, true) == false) { - return; // already init - } - - didAlreadyClose.set(false); - - try { - Iterator itrUdp = devUdpAddress.iterator(); - Iterator itrZig = devZigbeeAddress.iterator(); - - zigConnection = new IoTZigbee((IoTDeviceAddress)itrUdp.next(), (IoTZigbeeAddress)itrZig.next()); - - // DEBUG - System.out.println("DEBUG: Allocate iterators to print out addresses!"); - Iterator itrDebugUdp = devUdpAddress.iterator(); - IoTDeviceAddress iotaddDebug = (IoTDeviceAddress)itrDebugUdp.next(); - System.out.println("IP address: " + iotaddDebug.getCompleteAddress()); - System.out.println("Source port: " + iotaddDebug.getSourcePortNumber()); - System.out.println("Destination port: " + iotaddDebug.getDestinationPortNumber()); - - Iterator itrDebugZig = devZigbeeAddress.iterator(); - IoTZigbeeAddress iotzbaddDebug = (IoTZigbeeAddress)itrDebugZig.next(); - System.out.println("Zigbee address: " + iotzbaddDebug.getAddress()); - - zigConnection.registerCallback(this); - System.out.println("Register callback!"); - zigConnection.init(); - System.out.println("Initialized!"); - - //made by changwoo - sleep(10); - - //System.out.println("Sending Management Permit Joining Request"); - for(int z=0; z<3; z++){ - zigConnection.sendManagementPermitJoiningRequest(0x0001, 0x0036, 0x00); - System.out.println("Sending Management Permit Joining Request"); - sleep(0); - } - - //made by changwoo - while (!didWriteAttrb.get()) { - System.out.println("Sending Write Attribute Request"); - zigConnection.sendWriteAttributesCommand(0x0002, 0x0500, 0x0104, 0x01); - sleep(0); - } - - //made by changwoo - System.out.println("Sending Enrollment Reponse"); - zigConnection.sendEnrollmentResponse(0x0003, 0x0500, 0x0104, 0x01); - sleep(0); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - //made by changwoo - private void sleep(int multipleTime){ - if(multipleTime<=0){ - multipleTime=1; - } - try{ - Thread.sleep(TIMEOUT_FOR_RESEND_MSEC*multipleTime); - } catch(Exception e){ - e.printStackTrace(); - } - } - - public void close() { - - if (didAlreadyClose.compareAndSet(false, true) == false) { - return; // already init - } - - didAlreadyInit.set(false); - - - try { - zigConnection.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - - public void Finalize() { - if (!didClose) { - close(); - } - } - - public int getValue() { - - int tmp = 0; - try { - gettingLatestDataMutex.acquire(); - tmp = detectedValue; - - } catch (Exception e) { - e.printStackTrace(); - } - gettingLatestDataMutex.release(); - - return tmp; - } - - // MotionSensor: - // - 24 = no motion = false - // - 26 = motion = true - // After getting 26, if there is no motion for ~12 seconds then we get back 24 - public boolean isActiveValue() { - - int tmp = getValue(); - if (tmp == 26) - detectStatus = true; - else // Getting 24 here - detectStatus = false; - - return detectStatus; - } - - public long getTimestampOfLastReading() { - - Date tmp = null; - try { - gettingLatestDataMutex.acquire(); - tmp = (Date)timestampOfLastDetecting.clone(); - - } catch (Exception e) { - e.printStackTrace(); - } - gettingLatestDataMutex.release(); - long retLong = tmp.getTime(); - - return retLong; - } - - public void newMessageAvailable(IoTZigbeeMessage _zm) { - - //made by changwoo - if(_zm instanceof IoTZigbeeMessageZclZoneStatusChangeNotification){ - IoTZigbeeMessageZclZoneStatusChangeNotification message = (IoTZigbeeMessageZclZoneStatusChangeNotification)_zm; - if(message.getSuccessOrFail()){ - //do something! - - try { - gettingLatestDataMutex.acquire(); - detectedValue = message.getStatus(); - timestampOfLastDetecting = new Date(); - } catch (Exception e) { - e.printStackTrace(); - } - gettingLatestDataMutex.release(); - try { - for (SmartthingsSensorCallback cb : callbackList) { - cb.newReadingAvailable(this.getValue(), this.isActiveValue()); - } - } catch (Exception e) { - e.printStackTrace(); - } - }//if - - //made by changwoo - } else if (_zm instanceof IoTZigbeeMessageZclWriteAttributesResponse) { - IoTZigbeeMessageZclWriteAttributesResponse message = (IoTZigbeeMessageZclWriteAttributesResponse)_zm; - if (message.getSuccessOrFail()) { - didWriteAttrb.set(true); - } - } - } - - public void registerCallback(SmartthingsSensorCallback _callbackTo) { - callbackList.add(_callbackTo); - } -} diff --git a/benchmarks/other/ZigbeeTest/MultipurposeSensor.java b/benchmarks/other/ZigbeeTest/MultipurposeSensor.java deleted file mode 100644 index a21155f..0000000 --- a/benchmarks/other/ZigbeeTest/MultipurposeSensor.java +++ /dev/null @@ -1,221 +0,0 @@ -// Standard Java Packages -import java.util.*; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.Semaphore; - -// Checker annotations -//import iotchecker.qual.*; -//import iotcode.annotation.*; - -// IoT Packages -import iotruntime.slave.*; -import iotcode.interfaces.*; -import iotruntime.zigbee.*; - -/** Class Smartthings sensor driver for Smartthings sensor devices. - * - * @author Changwoo Lee, Rahmadi Trimananda - * @version 1.0 - * @since 2016-12-01 - */ -public class MultipurposeSensor implements IoTZigbeeCallback, SmartthingsSensor { - - private final int TIMEOUT_FOR_RESEND_MSEC = 900; - - private IoTZigbee zigConnection = null; - private boolean didClose; // make sure that the clean up was done correctly - private boolean detectStatus = false; - - private int detectedValue = 0; - private Date timestampOfLastDetecting = null; - - private AtomicBoolean didAlreadyClose = new AtomicBoolean(true); - private AtomicBoolean didAlreadyInit = new AtomicBoolean(false); - private AtomicBoolean didWriteAttrb = new AtomicBoolean(false); - private AtomicBoolean didMatchDscr = new AtomicBoolean(false); - static Semaphore gettingLatestDataMutex = new Semaphore(1); - - private List < SmartthingsSensorCallback > callbackList = new CopyOnWriteArrayList < SmartthingsSensorCallback > (); - - @config private IoTSet devUdpAddress; - @config private IoTSet devZigbeeAddress; - - public MultipurposeSensor(IoTSet dSet, IoTSet zigSet) { - devUdpAddress = dSet; - devZigbeeAddress = zigSet; - } - - public void init() { - - if (didAlreadyInit.compareAndSet(false, true) == false) { - return; // already init - } - - didAlreadyClose.set(false); - - try { - Iterator itrUdp = devUdpAddress.iterator(); - Iterator itrZig = devZigbeeAddress.iterator(); - - zigConnection = new IoTZigbee((IoTDeviceAddress)itrUdp.next(), (IoTZigbeeAddress)itrZig.next()); - - // DEBUG - System.out.println("DEBUG: Allocate iterators to print out addresses!"); - Iterator itrDebugUdp = devUdpAddress.iterator(); - IoTDeviceAddress iotaddDebug = (IoTDeviceAddress)itrDebugUdp.next(); - System.out.println("IP address: " + iotaddDebug.getCompleteAddress()); - System.out.println("Source port: " + iotaddDebug.getSourcePortNumber()); - System.out.println("Destination port: " + iotaddDebug.getDestinationPortNumber()); - - Iterator itrDebugZig = devZigbeeAddress.iterator(); - IoTZigbeeAddress iotzbaddDebug = (IoTZigbeeAddress)itrDebugZig.next(); - System.out.println("Zigbee address: " + iotzbaddDebug.getAddress()); - - zigConnection.registerCallback(this); - System.out.println("Register callback!"); - zigConnection.init(); - System.out.println("Initialized!"); - - //made by changwoo - sleep(10); - System.out.println("Sending Management Permit Joining Request"); - for(int z=0; z<3; z++){ - zigConnection.sendManagementPermitJoiningRequest(0x0001, 0x0036, 0x00); - sleep(0); - } - - //made by changwoo - while (!didWriteAttrb.get()) { - System.out.println("Sending Write Attribute Request"); - zigConnection.sendWriteAttributesCommand(0x0002, 0x0500, 0x0104, 0x01); - sleep(0); - } - - //made by changwoo - System.out.println("Sending Enrollment Reponse"); - zigConnection.sendEnrollmentResponse(0x0003, 0x0500, 0x0104, 0x01); - sleep(0); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - //made by changwoo - private void sleep(int multipleTime){ - if(multipleTime<=0){ - multipleTime=1; - } - try{ - Thread.sleep(TIMEOUT_FOR_RESEND_MSEC*multipleTime); - } catch(Exception e){ - e.printStackTrace(); - } - } - - public void close() { - - if (didAlreadyClose.compareAndSet(false, true) == false) { - return; // already init - } - - didAlreadyInit.set(false); - - - try { - zigConnection.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void Finalize() { - if (!didClose) { - close(); - } - } - - public int getValue() { - - int tmp = 0; - try { - gettingLatestDataMutex.acquire(); - tmp = detectedValue; - - } catch (Exception e) { - e.printStackTrace(); - } - gettingLatestDataMutex.release(); - - return tmp; - } - - // MultipurposeSensor: - // - 24 = close = false - // - 25 = open = true - public boolean isActiveValue() { - - int tmp = getValue(); - if (tmp == 25) - detectStatus = true; - else // Getting 24 here - detectStatus = false; - - return detectStatus; - } - - public long getTimestampOfLastReading() { - - Date tmp = null; - try { - gettingLatestDataMutex.acquire(); - tmp = (Date)timestampOfLastDetecting.clone(); - - } catch (Exception e) { - e.printStackTrace(); - } - gettingLatestDataMutex.release(); - long retLong = tmp.getTime(); - - return retLong; - } - - public void newMessageAvailable(IoTZigbeeMessage _zm) { - - //made by changwoo - if(_zm instanceof IoTZigbeeMessageZclZoneStatusChangeNotification){ - IoTZigbeeMessageZclZoneStatusChangeNotification message = (IoTZigbeeMessageZclZoneStatusChangeNotification)_zm; - if(message.getSuccessOrFail()){ - //do something! - try { - gettingLatestDataMutex.acquire(); - detectedValue = message.getStatus(); - timestampOfLastDetecting = new Date(); - } catch (Exception e) { - e.printStackTrace(); - } - gettingLatestDataMutex.release(); - try { - for (SmartthingsSensorCallback cb : callbackList) { - cb.newReadingAvailable(this.getValue(), this.isActiveValue()); - } - } catch (Exception e) { - e.printStackTrace(); - } - }//if - - //made by changwoo - }//if - else if (_zm instanceof IoTZigbeeMessageZclWriteAttributesResponse) { - IoTZigbeeMessageZclWriteAttributesResponse message = (IoTZigbeeMessageZclWriteAttributesResponse)_zm; - if (message.getSuccessOrFail()) { - didWriteAttrb.set(true); - }//if - }//else if - } - - public void registerCallback(SmartthingsSensorCallback _callbackTo) { - callbackList.add(_callbackTo); - } -} diff --git a/benchmarks/other/ZigbeeTest/SmartthingsSensor.java b/benchmarks/other/ZigbeeTest/SmartthingsSensor.java deleted file mode 100644 index d739f19..0000000 --- a/benchmarks/other/ZigbeeTest/SmartthingsSensor.java +++ /dev/null @@ -1,71 +0,0 @@ -// Standard Java Packages -import java.util.Date; - -//RMI packages -import java.rmi.Remote; -import java.rmi.RemoteException; - -// Checker annotations -//import iotchecker.qual.*; - - -/** Class Smartthings sensor interface for Smartthings sensor devices. - * - * @author Rahmadi Trimananda , Changwoo Lee - * @version 1.0 - * @since 2016-12-21 - */ -public interface SmartthingsSensor extends Remote { - - /** Method to get the latests moisture reading from the sensor - * - * @return [float] Moisture as a percentage. - */ - public int getValue() throws RemoteException; - - - /** Method to probe the sensor for active value - * - * @return [boolean] True means sensor is actively detecting something. - */ - public boolean isActiveValue() throws RemoteException; - - - /** Method to get the latests moisture reading timestamp from the sensor - * - * @return [Date] timestamp of latest moisture reading, null if no reading occurred yet. - */ - public long getTimestampOfLastReading() throws RemoteException; - - - /** Method to initialize the moisture sensor. - * - * @param None. - * - * @return [void] None. - */ - public void init() throws RemoteException; - - - /** Register an object to retrieve callbacks when new sensor reading is available - * - * @param _callbackTo [MoistureSensorCallback]. - * - * @return [void] None. - */ - public void registerCallback(SmartthingsSensorCallback _callbackTo) throws RemoteException; -} - - - - - - - - - - - - - - diff --git a/benchmarks/other/ZigbeeTest/SmartthingsSensorCallback.java b/benchmarks/other/ZigbeeTest/SmartthingsSensorCallback.java deleted file mode 100644 index 2367da1..0000000 --- a/benchmarks/other/ZigbeeTest/SmartthingsSensorCallback.java +++ /dev/null @@ -1,16 +0,0 @@ -// Checker annotations -//import iotchecker.qual.*; - - -/** Smartthings Sensor Callback for when a camera changes state (new frame available). - * - * @author Rahmadi Trimananda , Changwoo Lee - * @version 1.0 - * @since 2016-12-21 - */ - -public interface SmartthingsSensorCallback { - - //public void newReadingAvailable(@NonLocalRemote SmartthingsSensor _sensor) throws RemoteException; - public void newReadingAvailable(int _value, boolean _activeValue); -} diff --git a/benchmarks/other/ZigbeeTest/SpruceSensor.java b/benchmarks/other/ZigbeeTest/SpruceSensor.java deleted file mode 100644 index 7dccc1f..0000000 --- a/benchmarks/other/ZigbeeTest/SpruceSensor.java +++ /dev/null @@ -1,217 +0,0 @@ -// Standard Java Packages -import java.util.Iterator; -import java.util.List; -import java.util.ArrayList; -import java.util.Date; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.Semaphore; - - -// Checker annotations -//import iotchecker.qual.*; - -// IoT Packages -import iotruntime.slave.*; -//import iotcode.interfaces.MoistureSensor; -//import iotcode.interfaces.MoistureSensorSmartCallback; -import iotruntime.zigbee.*; -//import iotcode.annotation.*; - -public class SpruceSensor implements IoTZigbeeCallback, MoistureSensor { - - private final int TIMEOUT_FOR_RESEND_MSEC = 1000; - - private IoTZigbee zigConnection = null; - private boolean didClose; // make sure that the clean up was done correctly - - private float humidity = 0; - private Date timestampOfLastHumidity = null; - - private AtomicBoolean didBind = new AtomicBoolean(false); - private AtomicBoolean didConfigureReporting = new AtomicBoolean(false); - private AtomicBoolean didAlreadyInit = new AtomicBoolean(false); - private AtomicBoolean didAlreadyClose = new AtomicBoolean(true); - static Semaphore gettingLatestDataMutex = new Semaphore(1); - - private List < MoistureSensorSmartCallback > callbackList = new CopyOnWriteArrayList < MoistureSensorSmartCallback > (); - - private int sensorId = 0; - - @config private IoTSet devUdpAddress; - @config private IoTSet devZigbeeAddress; - - public SpruceSensor(IoTSet _devUdpAddress, IoTSet _devZigbeeAddress) { - devUdpAddress = _devUdpAddress; - devZigbeeAddress = _devZigbeeAddress; - } - - public void init() { - - if (didAlreadyInit.compareAndSet(false, true) == false) { - return; // already init - } - - didAlreadyClose.set(false); - - try { - Iterator itrUdp = devUdpAddress.iterator(); - Iterator itrZig = devZigbeeAddress.iterator(); - - zigConnection = new IoTZigbee((IoTDeviceAddress)itrUdp.next(), (IoTZigbeeAddress)itrZig.next()); - - // DEBUG - System.out.println("DEBUG: Allocate iterators to print out addresses!"); - Iterator itrDebugUdp = devUdpAddress.iterator(); - IoTDeviceAddress iotaddDebug = (IoTDeviceAddress)itrDebugUdp.next(); - System.out.println("IP address: " + iotaddDebug.getCompleteAddress()); - System.out.println("Source port: " + iotaddDebug.getSourcePortNumber()); - System.out.println("Destination port: " + iotaddDebug.getDestinationPortNumber()); - - Iterator itrDebugZig = devZigbeeAddress.iterator(); - IoTZigbeeAddress iotzbaddDebug = (IoTZigbeeAddress)itrDebugZig.next(); - System.out.println("Zigbee address: " + iotzbaddDebug.getAddress()); - - zigConnection.registerCallback(this); - System.out.println("Register callback!"); - zigConnection.init(); - System.out.println("Initialized!"); - - while (!didBind.get()) { - zigConnection.sendBindRequest(0x0001, 0x0405, 0x01); - System.out.println("Sending bind request!"); - try { - Thread.sleep(TIMEOUT_FOR_RESEND_MSEC); - } catch (Exception e) { - e.printStackTrace(); - } - } - - while (!didConfigureReporting.get()) { - zigConnection.sendConfigureReportingCommand(0x0001, 0x0405, 0x0104, 0x01, 0x0000, 0x21, 0x0001, 0x0001, null); - try { - Thread.sleep(TIMEOUT_FOR_RESEND_MSEC); - } catch (Exception e) { - e.printStackTrace(); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void close() { - - if (didAlreadyClose.compareAndSet(false, true) == false) { - return; // already init - } - - didAlreadyInit.set(false); - - - try { - zigConnection.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void Finalize() { - if (!didClose) { - close(); - } - } - - public void setId(int id) { - - sensorId = id; - - } - - public int getId() { - - return sensorId; - - } - - public float getMoisture() { - - float tmp = 0; - try { - gettingLatestDataMutex.acquire(); - tmp = humidity; - - } catch (Exception e) { - e.printStackTrace(); - } - gettingLatestDataMutex.release(); - - return tmp; - } - - public long getTimestampOfLastReading() { - - Date tmp = null; - try { - gettingLatestDataMutex.acquire(); - tmp = (Date)timestampOfLastHumidity.clone(); - - } catch (Exception e) { - e.printStackTrace(); - } - gettingLatestDataMutex.release(); - long retLong = tmp.getTime(); - - return retLong; - } - - public void newMessageAvailable(IoTZigbeeMessage _zm) { - - if (_zm instanceof IoTZigbeeMessageZdoBindResponse) { - IoTZigbeeMessageZdoBindResponse message = (IoTZigbeeMessageZdoBindResponse)_zm; - if (message.getSucceeded()) { - didBind.set(true); - } - - } else if (_zm instanceof IoTZigbeeMessageZclConfigureReportingResponse) { - IoTZigbeeMessageZclConfigureReportingResponse message = (IoTZigbeeMessageZclConfigureReportingResponse)_zm; - if (message.getAllSuccess()) { - didConfigureReporting.set(true); - } - - } else if (_zm instanceof IoTZigbeeMessageZclReportAttributes) { - IoTZigbeeMessageZclReportAttributes message = (IoTZigbeeMessageZclReportAttributes)_zm; - List attrList = message.getAttributes(); - - if (attrList.size() == 1) { - if (attrList.get(0).getAttributeId() == 0) { - byte[] data = attrList.get(0).getData(); - - int value = (data[0] * 256) + data[1]; - - try { - gettingLatestDataMutex.acquire(); - humidity = (float)value / (float)100.0; - timestampOfLastHumidity = new Date(); - } catch (Exception e) { - e.printStackTrace(); - } - gettingLatestDataMutex.release(); - - try { - for (MoistureSensorSmartCallback cb : callbackList) { - cb.newReadingAvailable(this.getId(), this.getMoisture(), this.getTimestampOfLastReading()); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - } - } - - public void registerCallback(MoistureSensorSmartCallback _callbackTo) { - callbackList.add(_callbackTo); - } -} diff --git a/benchmarks/other/ZigbeeTest/WaterLeakSensor.java b/benchmarks/other/ZigbeeTest/WaterLeakSensor.java deleted file mode 100644 index 75923a4..0000000 --- a/benchmarks/other/ZigbeeTest/WaterLeakSensor.java +++ /dev/null @@ -1,222 +0,0 @@ -// Standard Java Packages -import java.util.*; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.Semaphore; - -// Checker annotations -//import iotchecker.qual.*; -//import iotcode.annotation.*; - -// IoT Packages -import iotruntime.slave.*; -import iotcode.interfaces.*; -import iotruntime.zigbee.*; - -/** Class Smartthings sensor driver for Smartthings sensor devices. - * - * @author Changwoo Lee, Rahmadi Trimananda - * @version 1.0 - * @since 2016-12-01 - */ -public class WaterLeakSensor implements IoTZigbeeCallback, SmartthingsSensor { - - private final int TIMEOUT_FOR_RESEND_MSEC = 900; - - private IoTZigbee zigConnection = null; - private boolean didClose; // make sure that the clean up was done correctly - private boolean detectStatus = false; - - private int detectedValue = 0; - private Date timestampOfLastDetecting = null; - - private AtomicBoolean didAlreadyInit = new AtomicBoolean(false); - private AtomicBoolean didAlreadyClose = new AtomicBoolean(true); - private AtomicBoolean didWriteAttrb = new AtomicBoolean(false); - private AtomicBoolean didMatchDscr = new AtomicBoolean(false); - static Semaphore gettingLatestDataMutex = new Semaphore(1); - - private List < SmartthingsSensorCallback > callbackList = new CopyOnWriteArrayList < SmartthingsSensorCallback > (); - - @config private IoTSet devUdpAddress; - @config private IoTSet devZigbeeAddress; - - public WaterLeakSensor(IoTSet dSet, IoTSet zigSet) { - devUdpAddress = dSet; - devZigbeeAddress = zigSet; - } - - public void init() { - - if (didAlreadyInit.compareAndSet(false, true) == false) { - return; // already init - } - - didAlreadyClose.set(false); - - try { - Iterator itrUdp = devUdpAddress.iterator(); - Iterator itrZig = devZigbeeAddress.iterator(); - - zigConnection = new IoTZigbee((IoTDeviceAddress)itrUdp.next(), (IoTZigbeeAddress)itrZig.next()); - - // DEBUG - System.out.println("DEBUG: Allocate iterators to print out addresses!"); - Iterator itrDebugUdp = devUdpAddress.iterator(); - IoTDeviceAddress iotaddDebug = (IoTDeviceAddress)itrDebugUdp.next(); - System.out.println("IP address: " + iotaddDebug.getCompleteAddress()); - System.out.println("Source port: " + iotaddDebug.getSourcePortNumber()); - System.out.println("Destination port: " + iotaddDebug.getDestinationPortNumber()); - - Iterator itrDebugZig = devZigbeeAddress.iterator(); - IoTZigbeeAddress iotzbaddDebug = (IoTZigbeeAddress)itrDebugZig.next(); - System.out.println("Zigbee address: " + iotzbaddDebug.getAddress()); - - zigConnection.registerCallback(this); - System.out.println("Register callback!"); - zigConnection.init(); - System.out.println("Initialized!"); - - //made by changwoo - sleep(10); - System.out.println("Sending Management Permit Joining Request"); - for(int z=0; z<3; z++){ - zigConnection.sendManagementPermitJoiningRequest(0x0001, 0x0036, 0x00); - sleep(0); - } - - //made by changwoo - while (!didWriteAttrb.get()) { - System.out.println("Sending Write Attribute Request"); - zigConnection.sendWriteAttributesCommand(0x0002, 0x0500, 0x0104, 0x01); - sleep(0); - } - - //made by changwoo - System.out.println("Sending Enrollment Reponse"); - zigConnection.sendEnrollmentResponse(0x0003, 0x0500, 0x0104, 0x01); - sleep(0); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - //made by changwoo - private void sleep(int multipleTime){ - if(multipleTime<=0){ - multipleTime=1; - } - try{ - Thread.sleep(TIMEOUT_FOR_RESEND_MSEC*multipleTime); - } catch(Exception e){ - e.printStackTrace(); - } - } - - public void close() { - - if (didAlreadyClose.compareAndSet(false, true) == false) { - return; // already init - } - - didAlreadyInit.set(false); - - - try { - zigConnection.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void Finalize() { - if (!didClose) { - close(); - } - } - - public int getValue() { - - int tmp = 0; - try { - gettingLatestDataMutex.acquire(); - tmp = detectedValue; - - } catch (Exception e) { - e.printStackTrace(); - } - gettingLatestDataMutex.release(); - - return tmp; - } - - // WaterLeakSensor: - // - 24 = no leak = false - // - 25 = leak = true - public boolean isActiveValue() { - - int tmp = getValue(); - if (tmp == 25) - detectStatus = true; - else // Getting 24 here - detectStatus = false; - - return detectStatus; - } - - public long getTimestampOfLastReading() { - - Date tmp = null; - try { - gettingLatestDataMutex.acquire(); - tmp = (Date)timestampOfLastDetecting.clone(); - - } catch (Exception e) { - e.printStackTrace(); - } - gettingLatestDataMutex.release(); - long retLong = tmp.getTime(); - - return retLong; - } - - public void newMessageAvailable(IoTZigbeeMessage _zm) { - - //made by changwoo - if(_zm instanceof IoTZigbeeMessageZclZoneStatusChangeNotification){ - IoTZigbeeMessageZclZoneStatusChangeNotification message = (IoTZigbeeMessageZclZoneStatusChangeNotification)_zm; - if(message.getSuccessOrFail()){ - //do something! - - try { - gettingLatestDataMutex.acquire(); - detectedValue = message.getStatus(); - timestampOfLastDetecting = new Date(); - } catch (Exception e) { - e.printStackTrace(); - } - gettingLatestDataMutex.release(); - try { - for (SmartthingsSensorCallback cb : callbackList) { - cb.newReadingAvailable(this.getValue(), this.isActiveValue()); - } - } catch (Exception e) { - e.printStackTrace(); - } - }//if - - //made by changwoo - }//if - else if (_zm instanceof IoTZigbeeMessageZclWriteAttributesResponse) { - IoTZigbeeMessageZclWriteAttributesResponse message = (IoTZigbeeMessageZclWriteAttributesResponse)_zm; - if (message.getSuccessOrFail()) { - didWriteAttrb.set(true); - }//if - }//else if - } - - public void registerCallback(SmartthingsSensorCallback _callbackTo) { - callbackList.add(_callbackTo); - } -} diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTest.java b/benchmarks/other/ZigbeeTest/ZigbeeTest.java deleted file mode 100644 index 9fe8cbe..0000000 --- a/benchmarks/other/ZigbeeTest/ZigbeeTest.java +++ /dev/null @@ -1,78 +0,0 @@ -import java.util.Map; -import java.net.*; -import java.io.*; -import java.util.*; - -import iotruntime.*; -import iotruntime.zigbee.*; - -//import iotcode.interfaces.*; -import java.rmi.RemoteException; - -public class ZigbeeTest implements MoistureSensorSmartCallback { - - public final int SOCKET_SEND_BUFFER_SIZE = 1024; - public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024; - - - public ZigbeeTest() { - } - - - public void newReadingAvailable(int sensorId, float moisture, long timeStampOfLastReading) { - System.out.println("New Message!!!!"); - System.out.println(moisture); - System.out.println("Reading time: " + timeStampOfLastReading); - } - - - - - - - public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{ - - String message = "type: policy_set\n"; - message += "ip_address: " + "192.168.2.108\n"; // local ip address - //message += "port: " + "5959\n"; // port number - message += "port: " + "5557\n"; // port number - message += "device_address_long: " + "000d6f0003ebf2ee" + "\n"; - //DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("128.195.204.110"), 5005); // address and port of the gateway - DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.2.192"), 5005); // address and port of the gateway - - DatagramSocket socket = new DatagramSocket(); - socket.setSendBufferSize(4096); - socket.setReceiveBufferSize(4096); - - socket.send(sendPacket); - - - - - //IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("128.195.204.110", 5557, 5005,false,false); - IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.192", 5557, 5005,false,false); - IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress("000d6f0003ebf2ee"); - - Set zigSet = new HashSet(); - zigSet.add(zigAddrLong); - IoTSet zigIotSet = new IoTSet(zigSet); - - Set devSet = new HashSet(); - devSet.add(zigUdpAddr); - IoTSet devIotSet = new IoTSet(devSet); - SpruceSensor sen = new SpruceSensor(devIotSet, zigIotSet); - - System.out.println("About to init"); - sen.init(); - System.out.println("Passed init!"); - ZigbeeTest zTest = new ZigbeeTest(); - System.out.println("ZigbeeTest created!"); - sen.registerCallback(zTest); - - - System.out.println("Loop Begin"); - while (true) { - - } - } -} diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTestDoorlock.class b/benchmarks/other/ZigbeeTest/ZigbeeTestDoorlock.class new file mode 100644 index 0000000..49e2c3d Binary files /dev/null and b/benchmarks/other/ZigbeeTest/ZigbeeTestDoorlock.class differ diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTestDoorlock.java b/benchmarks/other/ZigbeeTest/ZigbeeTestDoorlock.java new file mode 100644 index 0000000..66811ae --- /dev/null +++ b/benchmarks/other/ZigbeeTest/ZigbeeTestDoorlock.java @@ -0,0 +1,72 @@ +import java.util.Map; +import java.net.*; +import java.io.*; +import java.util.*; + +public class ZigbeeTestDoorlock implements SmartthingsSensorCallback { + public final int SOCKET_SEND_BUFFER_SIZE = 1024; + public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024; + private static final String MY_IP_ADDRESS = "192.168.1.198"; + private static final String DEVICE_MAC_ADDRESS = "002446fffd00b0ba"; //doorlock sensor + private static final String GATEWAY = "192.168.1.192"; + private static final int LOCAL_COMM_SOCKET = 5960; + + public void newReadingAvailable(int _value, boolean _activeValue) { + + System.out.println("New Message!!!!"); + int status = _value; + switch (status) { + case 0: + System.out.println("Not fully locked"); + break; + case 1: + System.out.println("Locked"); + break; + case 2: + System.out.println("Unlocked"); + break; + default: + System.out.println("Unknown value: " + status); + break; + } + } + + public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException { + + String message = "type: policy_set\n"; + message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address + message += "port: " + LOCAL_COMM_SOCKET + "\n"; // port number + message += "device_address_long: " + DEVICE_MAC_ADDRESS + "\n"; + DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(GATEWAY), 5005); // address and port of the gateway which means Raspberry PI's IP address + DatagramSocket socket = new DatagramSocket(12345); + socket.setSendBufferSize(4096); + socket.setReceiveBufferSize(4096); + socket.send(sendPacket); + socket.setReuseAddress(true); + socket.close(); + + IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress(GATEWAY, LOCAL_COMM_SOCKET, 5005,false,false); + IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVICE_MAC_ADDRESS); + + Set zigSet = new HashSet(); + zigSet.add(zigAddrLong); + IoTSet zigIotSet = new IoTSet(zigSet); + + Set devSet = new HashSet(); + devSet.add(zigUdpAddr); + IoTSet devIotSet = new IoTSet(devSet); + DoorlockSensor sen = new DoorlockSensor(devIotSet, zigIotSet); + + ZigbeeTestDoorlock zTest = new ZigbeeTestDoorlock(); + sen.registerCallback(zTest); + + System.out.println("About to init"); + sen.init(); + + System.out.println("Loop Begin"); + while (true) { + + } + } + +} diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTestMoisture.class b/benchmarks/other/ZigbeeTest/ZigbeeTestMoisture.class new file mode 100644 index 0000000..3ea6145 Binary files /dev/null and b/benchmarks/other/ZigbeeTest/ZigbeeTestMoisture.class differ diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTestMoisture.java b/benchmarks/other/ZigbeeTest/ZigbeeTestMoisture.java new file mode 100644 index 0000000..6c07a7e --- /dev/null +++ b/benchmarks/other/ZigbeeTest/ZigbeeTestMoisture.java @@ -0,0 +1,65 @@ +import java.util.Map; +import java.net.*; +import java.io.*; +import java.util.*; + +public class ZigbeeTestMoisture implements MoistureSensorSmartCallback { + + public final int SOCKET_SEND_BUFFER_SIZE = 1024; + public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024; + private static final String MY_IP_ADDRESS = "192.168.1.198"; + private static final String DEVICE_MAC_ADDRESS = "000d6f0003ebf2ee"; //doorlock sensor + private static final String GATEWAY = "192.168.1.192"; + private static final int LOCAL_COMM_SOCKET = 5557; + + + public ZigbeeTestMoisture() { + } + + + public void newReadingAvailable(int sensorId, float moisture, long timeStampOfLastReading) { + System.out.println("New Message!!!!"); + System.out.println(moisture); + System.out.println("Reading time: " + timeStampOfLastReading); + } + + + public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException { + + String message = "type: policy_set\n"; + message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address + message += "port: " + LOCAL_COMM_SOCKET + "\n"; // port number + message += "device_address_long: " + DEVICE_MAC_ADDRESS + "\n"; + DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(GATEWAY), 5005); // address and port of the gateway + + DatagramSocket socket = new DatagramSocket(12345); + socket.setSendBufferSize(4096); + socket.setReceiveBufferSize(4096); + socket.send(sendPacket); + socket.setReuseAddress(true); + socket.close(); + + IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress(GATEWAY, LOCAL_COMM_SOCKET, 5005,false,false); + IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVICE_MAC_ADDRESS); + + Set zigSet = new HashSet(); + zigSet.add(zigAddrLong); + IoTSet zigIotSet = new IoTSet(zigSet); + + Set devSet = new HashSet(); + devSet.add(zigUdpAddr); + IoTSet devIotSet = new IoTSet(devSet); + SpruceSensor sen = new SpruceSensor(devIotSet, zigIotSet); + + System.out.println("About to init"); + sen.init(); + System.out.println("Passed init!"); + ZigbeeTestMoisture zTest = new ZigbeeTestMoisture(); + sen.registerCallback(zTest); + + System.out.println("Loop Begin"); + while (true) { + + } + } +} diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTestMotion.class b/benchmarks/other/ZigbeeTest/ZigbeeTestMotion.class new file mode 100644 index 0000000..335ce8d Binary files /dev/null and b/benchmarks/other/ZigbeeTest/ZigbeeTestMotion.class differ diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTestMotion.java b/benchmarks/other/ZigbeeTest/ZigbeeTestMotion.java new file mode 100644 index 0000000..9278c11 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/ZigbeeTestMotion.java @@ -0,0 +1,57 @@ +import java.util.Map; +import java.net.*; +import java.io.*; +import java.util.*; + +public class ZigbeeTestMotion implements SmartthingsSensorCallback { + public final int SOCKET_SEND_BUFFER_SIZE = 1024; + public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024; + private static final String MY_IP_ADDRESS = "192.168.1.198"; + private static final String DEVICE_MAC_ADDRESS = "000d6f000bbd5398"; //motion + private static final String GATEWAY = "192.168.1.192"; + private static final int LOCAL_COMM_SOCKET = 5956; + + public void newReadingAvailable(int _value, boolean _activeValue) { + System.out.println("New Message!!!!"); + System.out.println("motion : "+ _value); + System.out.println("active? : "+ _activeValue); + } + + public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException { + + String message = "type: policy_set\n"; + message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address + message += "port: " + LOCAL_COMM_SOCKET + "\n"; // port number + message += "device_address_long: " + DEVICE_MAC_ADDRESS + "\n"; + DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(GATEWAY), 5005); // address and port of the gateway which means Raspberry PI's IP address + DatagramSocket socket = new DatagramSocket(12345); + socket.setSendBufferSize(4096); + socket.setReceiveBufferSize(4096); + socket.send(sendPacket); + socket.setReuseAddress(true); + socket.close(); + + IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress(GATEWAY, LOCAL_COMM_SOCKET, 5005,false,false); + IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVICE_MAC_ADDRESS); + + Set zigSet = new HashSet(); + zigSet.add(zigAddrLong); + IoTSet zigIotSet = new IoTSet(zigSet); + + Set devSet = new HashSet(); + devSet.add(zigUdpAddr); + IoTSet devIotSet = new IoTSet(devSet); + MotionSensor sen = new MotionSensor(devIotSet, zigIotSet); + + System.out.println("About to init"); + sen.init(); + + ZigbeeTestMotion zTest = new ZigbeeTestMotion(); + sen.registerCallback(zTest); + + System.out.println("Loop Begin"); + while (true) { + + } + } +} diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTestMultipurpose.class b/benchmarks/other/ZigbeeTest/ZigbeeTestMultipurpose.class new file mode 100644 index 0000000..3a8d536 Binary files /dev/null and b/benchmarks/other/ZigbeeTest/ZigbeeTestMultipurpose.class differ diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTestMultipurpose.java b/benchmarks/other/ZigbeeTest/ZigbeeTestMultipurpose.java new file mode 100644 index 0000000..8bc1f50 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/ZigbeeTestMultipurpose.java @@ -0,0 +1,57 @@ +import java.util.Map; +import java.net.*; +import java.io.*; +import java.util.*; + +public class ZigbeeTestMultipurpose implements SmartthingsSensorCallback { + public final int SOCKET_SEND_BUFFER_SIZE = 1024; + public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024; + private static final String MY_IP_ADDRESS = "192.168.1.198"; + private static final String DEVICE_MAC_ADDRESS = "000d6f000bbd3413"; //Multipurpose sensor + private static final String GATEWAY = "192.168.1.192"; + private static final int LOCAL_COMM_SOCKET = 5957; + + public void newReadingAvailable(int _value, boolean _activeValue) { + System.out.println("New Message!!!!"); + System.out.println("multipurpose : "+ _value); + System.out.println("active? : "+ _activeValue); + } + + public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException { + + String message = "type: policy_set\n"; + message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address + message += "port: " + LOCAL_COMM_SOCKET + "\n"; // port number + message += "device_address_long: " + DEVICE_MAC_ADDRESS + "\n"; + DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(GATEWAY), 5005); + DatagramSocket socket = new DatagramSocket(12345); + socket.setSendBufferSize(4096); + socket.setReceiveBufferSize(4096); + socket.send(sendPacket); + socket.setReuseAddress(true); + socket.close(); + + IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress(GATEWAY, LOCAL_COMM_SOCKET, 5005,false,false); + IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVICE_MAC_ADDRESS); + + Set zigSet = new HashSet(); + zigSet.add(zigAddrLong); + IoTSet zigIotSet = new IoTSet(zigSet); + + Set devSet = new HashSet(); + devSet.add(zigUdpAddr); + IoTSet devIotSet = new IoTSet(devSet); + MultipurposeSensor sen = new MultipurposeSensor(devIotSet, zigIotSet); + + System.out.println("About to init"); + sen.init(); + + ZigbeeTestMultipurpose zTest = new ZigbeeTestMultipurpose(); + sen.registerCallback(zTest); + + System.out.println("Loop Begin"); + while (true) { + + } + } +} diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTestWaterleak.class b/benchmarks/other/ZigbeeTest/ZigbeeTestWaterleak.class new file mode 100644 index 0000000..f1304d6 Binary files /dev/null and b/benchmarks/other/ZigbeeTest/ZigbeeTestWaterleak.class differ diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTestWaterleak.java b/benchmarks/other/ZigbeeTest/ZigbeeTestWaterleak.java new file mode 100644 index 0000000..9d7281f --- /dev/null +++ b/benchmarks/other/ZigbeeTest/ZigbeeTestWaterleak.java @@ -0,0 +1,57 @@ +import java.util.Map; +import java.net.*; +import java.io.*; +import java.util.*; + +public class ZigbeeTestWaterleak implements SmartthingsSensorCallback { + public final int SOCKET_SEND_BUFFER_SIZE = 1024; + public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024; + private static final String MY_IP_ADDRESS = "192.168.1.198"; + private static final String DEVICE_MAC_ADDRESS = "000d6f000ada75e3"; //water leak + private static final String GATEWAY = "192.168.1.192"; + private static final int LOCAL_COMM_SOCKET = 5958; + + public void newReadingAvailable(int _value, boolean _activeValue) { + System.out.println("New Message!!!!"); + System.out.println("water leak : "+ _value); + System.out.println("active? : "+ _activeValue); + } + + public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException { + + String message = "type: policy_set\n"; + message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address + message += "port: " + LOCAL_COMM_SOCKET + "\n"; // port number + message += "device_address_long: " + DEVICE_MAC_ADDRESS + "\n"; + DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(GATEWAY), 5005); // address and port of the gateway which means Raspberry PI's IP address + DatagramSocket socket = new DatagramSocket(12345); + socket.setSendBufferSize(4096); + socket.setReceiveBufferSize(4096); + socket.send(sendPacket); + socket.setReuseAddress(true); + socket.close(); + + IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress(GATEWAY, LOCAL_COMM_SOCKET, 5005,false,false); + IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVICE_MAC_ADDRESS); + + Set zigSet = new HashSet(); + zigSet.add(zigAddrLong); + IoTSet zigIotSet = new IoTSet(zigSet); + + Set devSet = new HashSet(); + devSet.add(zigUdpAddr); + IoTSet devIotSet = new IoTSet(devSet); + WaterLeakSensor sen = new WaterLeakSensor(devIotSet, zigIotSet); + + System.out.println("About to init"); + sen.init(); + + ZigbeeTestWaterleak zTest = new ZigbeeTestWaterleak(); + sen.registerCallback(zTest); + + System.out.println("Loop Begin"); + while (true) { + + } + } +} diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTest_doorlock.java b/benchmarks/other/ZigbeeTest/ZigbeeTest_doorlock.java deleted file mode 100644 index 5582191..0000000 --- a/benchmarks/other/ZigbeeTest/ZigbeeTest_doorlock.java +++ /dev/null @@ -1,83 +0,0 @@ -import java.util.Map; -import java.net.*; -import java.io.*; -import java.util.*; - -import iotruntime.*; -import iotruntime.zigbee.*; - -import iotcode.interfaces.*; -import java.rmi.RemoteException; - -//public class ZigbeeTest_doorlock implements IoTZigbeeCallback { -public class ZigbeeTest_doorlock implements SmartthingsSensorCallback { - public final int SOCKET_SEND_BUFFER_SIZE = 1024; - public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024; - private static final String MY_IP_ADDRESS = "192.168.1.198"; - public static final String DEVIDE_MAC_ADDRESS = "002446fffd00b0ba"; //doorlock sensor - - //public void newReadingAvailable(SmartthingsSensor _sensor) { - public void newReadingAvailable(int _value, boolean _activeValue) { - - System.out.println("New Message!!!!"); - //int status = ((DoorlockSensor)_sensor).getStatus(); - int status = _value; - switch (status) { - case 0: - System.out.println("Not fully locked"); - break; - case 1: - System.out.println("Locked"); - break; - case 2: - System.out.println("Unlocked"); - break; - default: - System.out.println("Unknown value: " + status); - break; - } - } - - public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{ - - String message = "type: policy_set\n"; - message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address - message += "port: " + "5959\n"; // port number - message += "device_address_long: " + DEVIDE_MAC_ADDRESS + "\n"; - DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.1.192"), 5005); // address and port of the gateway which means Raspberry PI's IP address - DatagramSocket socket = new DatagramSocket(12345/*test number*/); - socket.setSendBufferSize(4096); - socket.setReceiveBufferSize(4096); - socket.send(sendPacket); - socket.setReuseAddress(true); - socket.close(); - - IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.1.192", 5959, 5005,false,false); - IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS); - - Set zigSet = new HashSet(); - zigSet.add(zigAddrLong); - IoTSet zigIotSet = new IoTSet(zigSet); - - Set devSet = new HashSet(); - devSet.add(zigUdpAddr); - IoTSet devIotSet = new IoTSet(devSet); - DoorlockSensor sen = new DoorlockSensor(devIotSet, zigIotSet); - - ZigbeeTest_doorlock zTest = new ZigbeeTest_doorlock(); - sen.registerCallback(zTest); - - System.out.println("About to init"); - sen.init(); - - // ZigbeeTest_doorlock zTest = new ZigbeeTest_doorlock(); - // sen.registerCallback(zTest); - - - System.out.println("Loop Begin"); - while (true) { - - } - } - -} diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTest_motion.java b/benchmarks/other/ZigbeeTest/ZigbeeTest_motion.java deleted file mode 100644 index b19eca9..0000000 --- a/benchmarks/other/ZigbeeTest/ZigbeeTest_motion.java +++ /dev/null @@ -1,65 +0,0 @@ -import java.util.Map; -import java.net.*; -import java.io.*; -import java.util.*; - -import iotruntime.*; -import iotruntime.zigbee.*; - -//import iotcode.interfaces.*; -import java.rmi.RemoteException; - -public class ZigbeeTest_motion implements SmartthingsSensorCallback { - public final int SOCKET_SEND_BUFFER_SIZE = 1024; - public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024; - private static final String MY_IP_ADDRESS = "192.168.1.198"; - public static final String DEVIDE_MAC_ADDRESS = "000d6f000bbd5398"; //motion - -//000d6f000bbd5398 -//000d6f00057c92a7 - public void newReadingAvailable(int _value, boolean _activeValue) { - System.out.println("New Message!!!!"); - System.out.println("motion : "+ _value); - System.out.println("active? : "+ _activeValue); - } - - public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{ - - String message = "type: policy_set\n"; - message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address - message += "port: " + "5956\n"; // port number - message += "device_address_long: " + DEVIDE_MAC_ADDRESS + "\n"; - DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.1.192"), 5005); // address and port of the gateway which means Raspberry PI's IP address - //DatagramSocket socket = new DatagramSocket(11222); - DatagramSocket socket = new DatagramSocket(12345); - socket.setSendBufferSize(4096); - socket.setReceiveBufferSize(4096); - socket.send(sendPacket); - socket.setReuseAddress(true); - socket.close(); - - //IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", 5956, 5005,false,false); - IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.1.192", 5956, 5005,false,false); - IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS); - - Set zigSet = new HashSet(); - zigSet.add(zigAddrLong); - IoTSet zigIotSet = new IoTSet(zigSet); - - Set devSet = new HashSet(); - devSet.add(zigUdpAddr); - IoTSet devIotSet = new IoTSet(devSet); - MotionSensor sen = new MotionSensor(devIotSet, zigIotSet); - - System.out.println("About to init"); - sen.init(); - - ZigbeeTest_motion zTest = new ZigbeeTest_motion(); - sen.registerCallback(zTest); - - System.out.println("Loop Begin"); - while (true) { - - } - } -} diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTest_multipurpose.java b/benchmarks/other/ZigbeeTest/ZigbeeTest_multipurpose.java deleted file mode 100644 index bb5c836..0000000 --- a/benchmarks/other/ZigbeeTest/ZigbeeTest_multipurpose.java +++ /dev/null @@ -1,64 +0,0 @@ -import java.util.Map; -import java.net.*; -import java.io.*; -import java.util.*; - -import iotruntime.*; -import iotruntime.zigbee.*; - -//import iotcode.interfaces.*; -import java.rmi.RemoteException; - -public class ZigbeeTest_multipurpose implements SmartthingsSensorCallback { - public final int SOCKET_SEND_BUFFER_SIZE = 1024; - public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024; - private static final String MY_IP_ADDRESS = "192.168.1.198"; - public static final String DEVIDE_MAC_ADDRESS = "000d6f000bbd3413"; //Multipurpose sensor - - public void newReadingAvailable(int _value, boolean _activeValue) { - System.out.println("New Message!!!!"); - System.out.println("multipurpose : "+ _value); - System.out.println("active? : "+ _activeValue); - } - - public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{ - - String message = "type: policy_set\n"; - message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address - message += "port: " + "5957\n"; // port number - //message += "port: " + "5956\n"; // port number - message += "device_address_long: " + DEVIDE_MAC_ADDRESS + "\n"; - DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.1.192"), 5005); - //DatagramSocket socket = new DatagramSocket(11111); - DatagramSocket socket = new DatagramSocket(12345); - socket.setSendBufferSize(4096); - socket.setReceiveBufferSize(4096); - socket.send(sendPacket); - socket.setReuseAddress(true); - socket.close(); - - IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.1.192", 5957, 5005,false,false); - //IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", 5956, 5005,false,false); - IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS); - - Set zigSet = new HashSet(); - zigSet.add(zigAddrLong); - IoTSet zigIotSet = new IoTSet(zigSet); - - Set devSet = new HashSet(); - devSet.add(zigUdpAddr); - IoTSet devIotSet = new IoTSet(devSet); - MultipurposeSensor sen = new MultipurposeSensor(devIotSet, zigIotSet); - - System.out.println("About to init"); - sen.init(); - - ZigbeeTest_multipurpose zTest = new ZigbeeTest_multipurpose(); - sen.registerCallback(zTest); - - System.out.println("Loop Begin"); - while (true) { - - } - } -} diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTest_waterleak.java b/benchmarks/other/ZigbeeTest/ZigbeeTest_waterleak.java deleted file mode 100644 index 11dbb30..0000000 --- a/benchmarks/other/ZigbeeTest/ZigbeeTest_waterleak.java +++ /dev/null @@ -1,64 +0,0 @@ -import java.util.Map; -import java.net.*; -import java.io.*; -import java.util.*; - -import iotruntime.*; -import iotruntime.zigbee.*; - -//import iotcode.interfaces.*; -import java.rmi.RemoteException; - -public class ZigbeeTest_waterleak implements SmartthingsSensorCallback { - public final int SOCKET_SEND_BUFFER_SIZE = 1024; - public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024; - private static final String MY_IP_ADDRESS = "192.168.1.198"; - private static final int PORT_NUMBER = 5959; - public static final String DEVIDE_MAC_ADDRESS = "000d6f000ada75e3"; //water leak - - public void newReadingAvailable(int _value, boolean _activeValue) { - System.out.println("New Message!!!!"); - System.out.println("water leak : "+ _value); - System.out.println("active? : "+ _activeValue); - } - - public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{ - - String message = "type: policy_set\n"; - message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address - message += "port: " + PORT_NUMBER + "\n"; // port number - message += "device_address_long: " + DEVIDE_MAC_ADDRESS + "\n"; - DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.1.192"), 5005); // address and port of the gateway which means Raspberry PI's IP address - //DatagramSocket socket = new DatagramSocket(22222); - DatagramSocket socket = new DatagramSocket(12345); - socket.setSendBufferSize(4096); - socket.setReceiveBufferSize(4096); - socket.send(sendPacket); - socket.setReuseAddress(true); - socket.close(); - - //IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", PORT_NUMBER, 5005,false,false); - IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.1.192", PORT_NUMBER, 5005,false,false); - IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS); - - Set zigSet = new HashSet(); - zigSet.add(zigAddrLong); - IoTSet zigIotSet = new IoTSet(zigSet); - - Set devSet = new HashSet(); - devSet.add(zigUdpAddr); - IoTSet devIotSet = new IoTSet(devSet); - WaterLeakSensor sen = new WaterLeakSensor(devIotSet, zigIotSet); - - System.out.println("About to init"); - sen.init(); - - ZigbeeTest_waterleak zTest = new ZigbeeTest_waterleak(); - sen.registerCallback(zTest); - - System.out.println("Loop Begin"); - while (true) { - - } - } -} diff --git a/benchmarks/other/ZigbeeTest/build.bash b/benchmarks/other/ZigbeeTest/build.bash deleted file mode 100755 index b74dfc1..0000000 --- a/benchmarks/other/ZigbeeTest/build.bash +++ /dev/null @@ -1,3 +0,0 @@ -cwd=$(pwd) -cd $cwd -javac -cp ./../iotjava:./../../../bin:.:../../packages/build *.java diff --git a/benchmarks/other/ZigbeeTest/buildall.bash b/benchmarks/other/ZigbeeTest/buildall.bash deleted file mode 100755 index 8dc832d..0000000 --- a/benchmarks/other/ZigbeeTest/buildall.bash +++ /dev/null @@ -1,11 +0,0 @@ -cwd=$(pwd) -cd ./../../.. -make iotjava -cd benchmarks -make nocheck -cd $cwd -cd ../../packages/ -# ./clean.bash -# ./build.bash -cd $cwd -javac -cp ./../../../bin:.:../../packages/build *.java \ No newline at end of file diff --git a/benchmarks/other/ZigbeeTest/clean.bash b/benchmarks/other/ZigbeeTest/clean.bash deleted file mode 100755 index 73c03ab..0000000 --- a/benchmarks/other/ZigbeeTest/clean.bash +++ /dev/null @@ -1 +0,0 @@ -rm -rf *.class diff --git a/benchmarks/other/ZigbeeTest/config.java b/benchmarks/other/ZigbeeTest/config.java deleted file mode 100644 index 9a7fde7..0000000 --- a/benchmarks/other/ZigbeeTest/config.java +++ /dev/null @@ -1,15 +0,0 @@ -//package iotcode.annotation; - -import java.lang.annotation.*; - -/** @config annotation - * This annotation is for the runtime system to instrument IoTSet and IoTRelation - * Re-instated on 12/12/2016 - * - * @author Rahmadi Trimananda - * @version 1.0 - * @since 2016-12-12 - */ -@Retention(RetentionPolicy.RUNTIME) -public @interface config { -} diff --git a/benchmarks/other/ZigbeeTest/run.bash b/benchmarks/other/ZigbeeTest/run.bash deleted file mode 100755 index 35f58eb..0000000 --- a/benchmarks/other/ZigbeeTest/run.bash +++ /dev/null @@ -1,2 +0,0 @@ -#java -cp ./../../../bin:.:../../packages/build ZigbeeTest -java -cp ./../iotjava:./../../../bin:. ZigbeeTest diff --git a/benchmarks/other/ZigbeeTest/run_doorlock.bash b/benchmarks/other/ZigbeeTest/run_doorlock.bash deleted file mode 100755 index 688e338..0000000 --- a/benchmarks/other/ZigbeeTest/run_doorlock.bash +++ /dev/null @@ -1 +0,0 @@ -java -cp ./../iotjava:./../../../bin:. ZigbeeTest_doorlock diff --git a/benchmarks/other/ZigbeeTest/run_motion.bash b/benchmarks/other/ZigbeeTest/run_motion.bash deleted file mode 100755 index e5baba1..0000000 --- a/benchmarks/other/ZigbeeTest/run_motion.bash +++ /dev/null @@ -1 +0,0 @@ -java -cp ./../iotjava:./../../../bin:. ZigbeeTest_motion diff --git a/benchmarks/other/ZigbeeTest/run_multipurpose.bash b/benchmarks/other/ZigbeeTest/run_multipurpose.bash deleted file mode 100755 index 653b0a2..0000000 --- a/benchmarks/other/ZigbeeTest/run_multipurpose.bash +++ /dev/null @@ -1,2 +0,0 @@ -#java -cp ./../../../bin:.:../../packages/build ZigbeeTest -java -cp ./../iotjava:./../../../bin:. ZigbeeTest_multipurpose diff --git a/benchmarks/other/ZigbeeTest/run_waterleak.bash b/benchmarks/other/ZigbeeTest/run_waterleak.bash deleted file mode 100755 index 76ae633..0000000 --- a/benchmarks/other/ZigbeeTest/run_waterleak.bash +++ /dev/null @@ -1 +0,0 @@ -java -cp ./../iotjava:./../../../bin:. ZigbeeTest_waterleak diff --git a/benchmarks/other/ZigbeeTest/zbtest.jar b/benchmarks/other/ZigbeeTest/zbtest.jar new file mode 100644 index 0000000..48c240f Binary files /dev/null and b/benchmarks/other/ZigbeeTest/zbtest.jar differ diff --git a/iotjava/Makefile b/iotjava/Makefile index 83ba1ba..16d9e07 100644 --- a/iotjava/Makefile +++ b/iotjava/Makefile @@ -1,3 +1,4 @@ + BASE := .. include $(BASE)/common.mk diff --git a/localconfig/iotruntime/run.bash b/localconfig/iotruntime/run.bash index 13f3dbb..16d8e3e 100755 --- a/localconfig/iotruntime/run.bash +++ b/localconfig/iotruntime/run.bash @@ -1,10 +1,10 @@ #!/bin/bash -java -cp .:/usr/share/java/*:./../:./../iotcode/:./../iotcode/Lifxtest/ iotruntime.master.IoTMaster Lifxtest -#java -cp .:/usr/share/java/*:./../:./../iotcode/:./../iotcode/Lifxtest/ iotruntime.master.IoTMaster SmartLightsController -#java -cp .:/usr/share/java/*:./../:./../iotcode/:./../iotcode/Lifxtest/ iotruntime.master.IoTMaster IrrigationController -#java -cp .:/usr/share/java/*:./../:./../iotcode/:./../iotcode/Lifxtest/ iotruntime.master.IoTMaster SpeakerController -#java -cp .:/usr/share/java/*:./../:./../iotcode/:./../iotcode/Lifxtest/ iotruntime.master.IoTMaster HomeSecurityController +java -cp .:/usr/share/java/*:./../:./../iotcode/ iotruntime.master.IoTMaster Lifxtest +#java -cp .:/usr/share/java/*:./../:./../iotcode/ iotruntime.master.IoTMaster SmartLightsController +#java -cp .:/usr/share/java/*:./../:./../iotcode/ iotruntime.master.IoTMaster IrrigationController +#java -cp .:/usr/share/java/*:./../:./../iotcode/ iotruntime.master.IoTMaster SpeakerController +#java -cp .:/usr/share/java/*:./../:./../iotcode/ iotruntime.master.IoTMaster HomeSecurityController # Combination -#java -cp .:/usr/share/java/*:./../:./../iotcode/:./../iotcode/Lifxtest/ iotruntime.master.IoTMaster HomeSecurityController SmartLightsController SpeakerController IrrigationController +#java -cp .:/usr/share/java/*:./../:./../iotcode/ iotruntime.master.IoTMaster HomeSecurityController SmartLightsController SpeakerController IrrigationController