def _readWriteChecks(charUUID, descrUUID): ENABLE_TC_WRITE_LONG = 1 if (ENABLE_TC_WRITE_LONG == 1): #enable long write test long_value = "1" * ( runTest.MTU_SIZE + 10 ) #TODO: get correct mtu size, assume 200 for now bleAdapter.writeCharacteristic(charUUID, long_value) ENABLE_TC_WRITE_NORMAL = 1 if (ENABLE_TC_WRITE_NORMAL == 1): bleAdapter.writeCharacteristic(charUUID, charUUID) bleAdapter.writeDescriptor(descrUUID, descrUUID) (isTestSuccessfull, charRead) = bleAdapter.readCharacteristic(charUUID) (isTestSuccessfull, descrRead) = bleAdapter.readDescriptor(descrUUID) if charRead != charUUID: isTestSuccessfull = False print("readWriteSimpleConnection test: Expected char uuid:" + charUUID + " got:" + charRead) if descrRead != descrUUID: isTestSuccessfull = False print("readWriteSimpleConnection test: Expected descr uuid:" + descrUUID + " got:" + descrRead) sys.stdout.flush() return isTestSuccessfull
def _readWriteChecks(charUUID, descrUUID): bleAdapter.writeCharacteristic(charUUID, charUUID) bleAdapter.writeDescriptor(descrUUID, descrUUID) (isTestSuccessfull, charRead) = bleAdapter.readCharacteristic(charUUID) (isTestSuccessfull, descrRead) = bleAdapter.readDescriptor(descrUUID) if charRead != charUUID: isTestSuccessfull = False print( "readWriteSimpleConnection test: Expected char uuid:" + charUUID + " got:" + charRead) if descrRead != descrUUID: isTestSuccessfull = False print( "readWriteSimpleConnection test: Expected descr uuid:" + descrUUID + " got:" + descrRead) sys.stdout.flush() return isTestSuccessfull
def pairing(): isTestSuccessFull = True if bleAdapter.isPaired() == False: bleAdapter.writeCharacteristic(runTest.DUT_ENCRYPT_CHAR_UUID, runTest.DUT_ENCRYPT_CHAR_UUID) #should trigger a pairing event isTestSuccessFull = bleAdapter.isPaired() else: isTestSuccessFull = False return isTestSuccessFull
def writereadLongCharacteristic(): long_value = "1" * runTest.LONG_READ_WRITE_LEN bleAdapter.writeCharacteristic(runTest.DUT_OPEN_CHAR_UUID, long_value) (isTestSuccessfull, charRead) = bleAdapter.readCharacteristic(runTest.DUT_OPEN_CHAR_UUID) if charRead != long_value: isTestSuccessfull = False print("readWriteSimpleConnection test: Expected value:" + long_value + " got:" + charRead) sys.stdout.flush() return isTestSuccessfull
def writereadLongCharacteristic(): # TODO: get correct mtu size, assume 200 for now long_value = "1" * (runTest.MTU_SIZE + 10) bleAdapter.writeCharacteristic(runTest.DUT_OPEN_CHAR_UUID, long_value) (isTestSuccessfull, charRead) = bleAdapter.readCharacteristic(runTest.DUT_OPEN_CHAR_UUID) if charRead != long_value: isTestSuccessfull = False print("readWriteSimpleConnection test: Expected value:" + long_value + " got:" + charRead) sys.stdout.flush() return isTestSuccessfull
def _readWriteProtectedAttributes(pairingStatus): if pairingStatus == True: expectedSuccess = True else: expectedSuccess = False isTestSuccessfull = bleAdapter.writeDescriptor( runTest.DUT_ENCRYPT_DESCR_UUID, runTest.DUT_ENCRYPT_DESCR_UUID) if isTestSuccessfull != expectedSuccess: print( "readWriteProtectedAttributes test: Error while reading protect descriptor, pairing status was " + str(pairingStatus) + " Operation success was " + str(isTestSuccessfull)) sys.stdout.flush() return False isTestSuccessfull = bleAdapter.writeCharacteristic( runTest.DUT_ENCRYPT_CHAR_UUID, runTest.DUT_ENCRYPT_CHAR_UUID) if isTestSuccessfull != expectedSuccess: print( "readWriteProtectedAttributes test: Error while writing protect characteristic, pairing status was " + str(pairingStatus) + " Operation success was " + str(isTestSuccessfull)) sys.stdout.flush() return False return True
def reconnectWhileBonded(): isTestSuccessFull = bleAdapter.connect(runTest.testDevice) #since there is a bond with DUT, pairing is automatic if (isTestSuccessFull == True): isTestSuccessfull = bleAdapter.writeCharacteristic( runTest.DUT_ENCRYPT_CHAR_UUID, runTest.DUT_ENCRYPT_CHAR_UUID) runTest.submitTestResult(isTestSuccessFull, runTest.reconnectWhileBonded)
def writeWithoutResponse(): return bleAdapter.writeCharacteristic( runTest.DUT_WRITE_NO_RESP_CHAR_UUID, runTest.DUT_WRITE_NO_RESP_CHAR_UUID, False)
def Send_Data_After_Disconnected(scan_filter, bleAdapter): runTest._advertisement_start( scan_filter=scan_filter, UUID=runTest.DUT_UUID_128, discoveryEvent_Cb=runTest.discoveryEventCb, bleAdapter=bleAdapter) runTest._simple_connect() isTestSuccessFull = runTest.discoverPrimaryServices() runTest.submitTestResult(isTestSuccessFull, runTest.discoverPrimaryServices) bleAdapter.gatt.updateLocalAttributeTable() # Check device not present. After discovery of services, advertisement # should have stopped. runTest.stopAdvertisement(scan_filter) # Check write and read bleAdapter.writeCharacteristic(runTest.DUT_OPEN_CHAR_UUID, runTest.DUT_OPEN_DESCR_UUID) bleAdapter.readCharacteristic(runTest.DUT_OPEN_CHAR_UUID) # Enable and receive notification and indication then disable. bleAdapter.subscribeForNotification(runTest.DUT_NOTIFY_CHAR_UUID) bleAdapter.subscribeForNotification( runTest.DUT_INDICATE_CHAR_UUID) # subscribe for next test time.sleep(2) # wait for connection parameters update # Check Notification and Indication bleAdapter.setNotificationCallBack(runTest.notificationCb) isTestSuccessFull = True runTest.mainloop.run() runTest.submitTestResult(isTestSuccessFull, runTest.notification) bleAdapter.setNotificationCallBack(runTest.indicationCb) isTestSuccessFull = True runTest.mainloop.run() runTest.submitTestResult(isTestSuccessFull, runTest.indication) isTestSuccessFull &= bleAdapter.disconnect() # Second time connection # wait for DUT to start advertising bleAdapter.startDiscovery(runTest.discoveryStartedCb) runTest.mainloop.run() bleAdapter.stopDiscovery() runTest._simple_connect() bleAdapter.subscribeForNotification(runTest.DUT_NOTIFY_CHAR_UUID) bleAdapter.subscribeForNotification( runTest.DUT_INDICATE_CHAR_UUID) # subscribe for next test # Check write and read after reconnection bleAdapter.writeCharacteristic(runTest.DUT_OPEN_CHAR_UUID, runTest.DUT_OPEN_DESCR_UUID) bleAdapter.readCharacteristic(runTest.DUT_OPEN_CHAR_UUID) # Check Notification and Indication after reconnection bleAdapter.setNotificationCallBack(runTest.notificationCb) isTestSuccessFull = True runTest.mainloop.run() runTest.submitTestResult(isTestSuccessFull, runTest.notification) bleAdapter.setNotificationCallBack(runTest.indicationCb) isTestSuccessFull = True runTest.mainloop.run() runTest.submitTestResult(isTestSuccessFull, runTest.indication) isTestSuccessFull = bleAdapter.subscribeForNotification( runTest.DUT_NOTIFY_CHAR_UUID, subscribe=False) # unsubscribe isTestSuccessFull = True runTest.submitTestResult(isTestSuccessFull, runTest.removeNotification) isTestSuccessFull = bleAdapter.subscribeForNotification( runTest.DUT_INDICATE_CHAR_UUID, subscribe=False) # unsubscribe isTestSuccessFull = True runTest.submitTestResult(isTestSuccessFull, runTest.removeIndication) isTestSuccessFull &= bleAdapter.disconnect() testutils.removeBondedDevices() return isTestSuccessFull
def writeLongCharacteristic(): long_value = "1" * (runTest.MTU_SIZE + 10 ) #TODO: get correct mtu size, assume 200 for now return bleAdapter.writeCharacteristic(runTest.DUT_OPEN_CHAR_UUID, long_value)