예제 #1
0
파일: scanner.py 프로젝트: hbock/bgasync
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)
예제 #2
0
파일: scanner.py 프로젝트: hbock/bgasync
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)
예제 #3
0
파일: scanner.py 프로젝트: hbock/bgasync
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()
예제 #4
0
파일: scanner.py 프로젝트: hbock/bgasync
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()
예제 #5
0
 def test_get_error_code_string_unknown(self):
     self.assertEqual("Unknown error (0x5643)", api.get_error_code_string(0x5643))
예제 #6
0
 def test_get_error_code_string(self):
     self.assertEqual("Device in wrong state to receive command", api.get_error_code_string(0x181))