Exemple #1
0
def command_response_cb(response, protocol, duration):
    if response.result != 0:
        print("Error setting scan parameters: {}".format(
            api.get_error_code_string(response.result)))

    response = yield protocol.send_command(
        api.command_gap_discover(
            mode=api.gap_discover_mode.discover_observation.value))
    if response.result != 0:
        print("Error starting discovery! {}".format(
            api.get_error_code_string(response.result)))

        # If we're in the wrong state, we may have simply exited
        # while still discovering.
        # Try to fix it by ending the GAP procedure and start over.
        if response.result == api.ERR_BGAPI_DEVICE_IN_WRONG_STATE:
            response = yield protocol.send_command(
                api.command_gap_end_procedure())

            # Need a Deferred delay, but no action.
            yield deferLater(reactor, 0.1, lambda: None)

            response = yield protocol.send_command(
                api.command_gap_discover(
                    mode=api.gap_discover_mode.discover_observation.value))

        # Otherwise, we're unable to proceed.
        else:
            print("Terminating on error.")
            reactor.stop()

    else:
        print("Discovery started.")
        reactor.callLater(duration, stop_discovery, protocol)
Exemple #2
0
def command_response_cb(response, protocol, duration):
    if response.result != 0:
        print("Error setting scan parameters: {}".format(api.get_error_code_string(response.result)))

    response = yield protocol.send_command(api.command_gap_discover(mode=api.gap_discover_mode.discover_observation.value))
    if response.result != 0:
        print("Error starting discovery! {}".format(api.get_error_code_string(response.result)))

        # If we're in the wrong state, we may have simply exited
        # while still discovering.
        # Try to fix it by ending the GAP procedure and start over.
        if response.result == api.ERR_BGAPI_DEVICE_IN_WRONG_STATE:
            response = yield protocol.send_command(api.command_gap_end_procedure())

            # Need a Deferred delay, but no action.
            yield deferLater(reactor, 0.1, lambda: None)

            response = yield protocol.send_command(api.command_gap_discover(mode=api.gap_discover_mode.discover_observation.value))

        # Otherwise, we're unable to proceed.
        else:
            print("Terminating on error.")
            reactor.stop()

    else:
        print("Discovery started.")
        reactor.callLater(duration, stop_discovery, protocol)
Exemple #3
0
def stop_discovery(protocol):
    print("Stopping discovery.")
    response = yield protocol.send_command(api.command_gap_end_procedure())
    if response.result != 0:
        print("Error stopping discovery! {}".format(api.get_error_code_string(response.result)))

    # End program
    reactor.stop()
Exemple #4
0
def stop_discovery(protocol):
    print("Stopping discovery.")
    response = yield protocol.send_command(api.command_gap_end_procedure())
    if response.result != 0:
        print("Error stopping discovery! {}".format(
            api.get_error_code_string(response.result)))

    # End program
    reactor.stop()