Exemple #1
0
def blehr_client_task(dut_addr, dut):
    interface = 'hci0'
    ble_devname = 'blehr_sensor_1.0'
    hr_srv_uuid = '180d'
    hr_char_uuid = '2a37'

    # Get BLE client module
    ble_client_obj = lib_ble_client.BLE_Bluez_Client(interface,
                                                     devname=ble_devname,
                                                     devaddr=dut_addr)
    if not ble_client_obj:
        raise RuntimeError("Failed to get DBus-Bluez object")

    # Discover Bluetooth Adapter and power on
    is_adapter_set = ble_client_obj.set_adapter()
    if not is_adapter_set:
        raise RuntimeError("Adapter Power On failed !!")

    # Connect BLE Device
    is_connected = ble_client_obj.connect()
    if not is_connected:
        Utility.console_log("Connection to device ", ble_devname, "failed !!")
        # Call disconnect to perform cleanup operations before exiting application
        ble_client_obj.disconnect()
        return

    # Read Services
    services_ret = ble_client_obj.get_services()
    if services_ret:
        print("\nServices\n")
        print(services_ret)
    else:
        print("Failure: Read Services failed")
        ble_client_obj.disconnect()
        return
    '''
    Blehr application run:
        Start Notifications
        Retrieve updated value
        Stop Notifications
    '''
    blehr_ret = ble_client_obj.hr_update_simulation(hr_srv_uuid, hr_char_uuid)
    if blehr_ret:
        print("Success: blehr example test passed")
    else:
        print("Failure: blehr example test failed")

    # Call disconnect to perform cleanup operations before exiting application
    ble_client_obj.disconnect()
Exemple #2
0
def bleprph_client_task(prph_obj, dut, dut_addr):
    interface = 'hci0'
    ble_devname = 'nimble-bleprph'
    srv_uuid = '2f12'

    # Get BLE client module
    ble_client_obj = lib_ble_client.BLE_Bluez_Client(interface, devname=ble_devname, devaddr=dut_addr)
    if not ble_client_obj:
        raise RuntimeError("Failed to get DBus-Bluez object")

    # Discover Bluetooth Adapter and power on
    is_adapter_set = ble_client_obj.set_adapter()
    if not is_adapter_set:
        raise RuntimeError("Adapter Power On failed !!")

    # Connect BLE Device
    is_connected = ble_client_obj.connect()
    if not is_connected:
        # Call disconnect to perform cleanup operations before exiting application
        ble_client_obj.disconnect()
        raise RuntimeError("Connection to device " + ble_devname + " failed !!")

    # Check dut responses
    dut.expect("GAP procedure initiated: advertise;", timeout=30)

    # Read Services
    services_ret = ble_client_obj.get_services(srv_uuid)
    if services_ret:
        Utility.console_log("\nServices\n")
        Utility.console_log(str(services_ret))
    else:
        ble_client_obj.disconnect()
        raise RuntimeError("Failure: Read Services failed")

    # Read Characteristics
    chars_ret = {}
    chars_ret = ble_client_obj.read_chars()
    if chars_ret:
        Utility.console_log("\nCharacteristics retrieved")
        for path, props in chars_ret.items():
            Utility.console_log("\n\tCharacteristic: " + str(path))
            Utility.console_log("\tCharacteristic UUID: " + str(props[2]))
            Utility.console_log("\tValue: " + str(props[0]))
            Utility.console_log("\tProperties: : " + str(props[1]))
    else:
        ble_client_obj.disconnect()
        raise RuntimeError("Failure: Read Characteristics failed")

    '''
    Write Characteristics
    - write 'A' to characteristic with write permission
    '''
    chars_ret_on_write = {}
    chars_ret_on_write = ble_client_obj.write_chars('A')
    if chars_ret_on_write:
        Utility.console_log("\nCharacteristics after write operation")
        for path, props in chars_ret_on_write.items():
            Utility.console_log("\n\tCharacteristic:" + str(path))
            Utility.console_log("\tCharacteristic UUID: " + str(props[2]))
            Utility.console_log("\tValue:" + str(props[0]))
            Utility.console_log("\tProperties: : " + str(props[1]))
    else:
        ble_client_obj.disconnect()
        raise RuntimeError("Failure: Write Characteristics failed")

    # Call disconnect to perform cleanup operations before exiting application
    ble_client_obj.disconnect()
Exemple #3
0
def test_example_app_ble_central(env, extra_data):
    """
        Steps:
            1. Discover Bluetooth Adapter and Power On
    """

    interface = 'hci0'
    adv_host_name = "BleCentTestApp"
    adv_iface_index = 0
    adv_type = 'peripheral'
    adv_uuid = '1811'

    subprocess.check_output(['rm', '-rf', '/var/lib/bluetooth/*'])
    subprocess.check_output(['hciconfig', 'hci0', 'reset'])
    # Acquire DUT
    dut = env.get_dut("blecent", "examples/bluetooth/nimble/blecent")

    # Get binary file
    binary_file = os.path.join(dut.app.binary_path, "blecent.bin")
    bin_size = os.path.getsize(binary_file)
    IDF.log_performance("blecent_bin_size", "{}KB".format(bin_size // 1024))

    # Upload binary and start testing
    Utility.console_log("Starting blecent example test app")
    dut.start_app()
    dut.reset()

    device_addr = ':'.join(re.findall('..', '%012x' % uuid.getnode()))

    # Get BLE client module
    ble_client_obj = lib_ble_client.BLE_Bluez_Client(interface)
    if not ble_client_obj:
        raise RuntimeError("Get DBus-Bluez object failed !!")

    # Discover Bluetooth Adapter and power on
    is_adapter_set = ble_client_obj.set_adapter()
    if not is_adapter_set:
        raise RuntimeError("Adapter Power On failed !!")

    # Write device address to dut
    dut.expect("BLE Host Task Started", timeout=60)
    dut.write(device_addr + "\n")
    '''
    Blecent application run:
        Create GATT data
        Register GATT Application
        Create Advertising data
        Register advertisement
        Start advertising
    '''
    ble_client_obj.start_advertising(adv_host_name, adv_iface_index, adv_type,
                                     adv_uuid)

    # Call disconnect to perform cleanup operations before exiting application
    ble_client_obj.disconnect()

    # Check dut responses
    dut.expect("Connection established", timeout=30)

    dut.expect("Service discovery complete; status=0", timeout=30)
    print("Service discovery passed\n\tService Discovery Status: 0")

    dut.expect("GATT procedure initiated: read;", timeout=30)
    dut.expect("Read complete; status=0", timeout=30)
    print(
        "Read passed\n\tSupportedNewAlertCategoryCharacteristic\n\tRead Status: 0"
    )

    dut.expect("GATT procedure initiated: write;", timeout=30)
    dut.expect("Write complete; status=0", timeout=30)
    print(
        "Write passed\n\tAlertNotificationControlPointCharacteristic\n\tWrite Status: 0"
    )

    dut.expect("GATT procedure initiated: write;", timeout=30)
    dut.expect("Subscribe complete; status=0", timeout=30)
    print(
        "Subscribe passed\n\tClientCharacteristicConfigurationDescriptor\n\tSubscribe Status: 0"
    )