Пример #1
0
def main(serial_port):
    print "Serial port used: {}".format(serial_port)
    ble_driver.sd_rpc_serial_port_name_set(serial_port)
    ble_driver.sd_rpc_serial_baud_rate_set(115200)
    ble_driver.sd_rpc_log_handler_set(log_message_handler)
    ble_driver.sd_rpc_evt_handler_set(ble_evt_handler)
    error_code = ble_driver.sd_rpc_open()

    if error_code != ble_driver.NRF_SUCCESS:
        print "Failed to open the nRF51 BLE Driver. Error code: 0x{0:X}.".format(error_code)
        return

    error_code = init_ble_stack()

    if error_code != ble_driver.NRF_SUCCESS:
        return

    init_connection_params()
    init_scan_params()
    start_scan()

    cccd_value = 0

    while True:
        sys.stdin.readline()
        cccd_value ^= CCCD_NOTIFY
        set_hrm_cccd(cccd_value)

    error_code = ble_driver.sd_rpc_close()

    if error_code != ble_driver.NRF_SUCCESS:
        print "Failed to close the nRF51 BLE Driver. Error code: 0x{0:X}".format(error_code)
        return

    print "Closed"
Пример #2
0
def main(serial_port):
    print "Serial port used: {}".format(serial_port)
    ble_driver.sd_rpc_serial_port_name_set(serial_port)
    ble_driver.sd_rpc_serial_baud_rate_set(115200)
    ble_driver.sd_rpc_evt_handler_set(ble_evt_handler)
    ble_driver.sd_rpc_log_handler_set(log_message_handler)

    error_code = ble_driver.sd_rpc_open()

    if error_code != ble_driver.NRF_SUCCESS:
        print "Failed to open the nRF51 BLE Driver"
        return

    error_code = init_ble_stack()

    if error_code != ble_driver.NRF_SUCCESS:
        return

    set_adv_data()
    start_advertising()

    while not advertisement_timed_out:
        sleep(1)

    ble_driver.sd_rpc_close()

    print "Closing"
Пример #3
0
def main(serial_port):
    print "Serial port used: {}".format(serial_port)
    ble_driver.sd_rpc_serial_port_name_set(serial_port)
    ble_driver.sd_rpc_serial_baud_rate_set(115200)
    ble_driver.sd_rpc_log_handler_set(log_message_handler)
    ble_driver.sd_rpc_evt_handler_set(ble_evt_handler)
    error_code = ble_driver.sd_rpc_open()

    if error_code != ble_driver.NRF_SUCCESS:
        print "Failed to open the nRF51 BLE Driver. Error code: 0x{0:X}.".format(
            error_code)
        return

    error_code = init_ble_stack()

    if error_code != ble_driver.NRF_SUCCESS:
        return

    init_connection_params()
    init_scan_params()

    error_code = init_services()

    if error_code != ble_driver.NRF_SUCCESS:
        return

    set_adv_data()

    start_scan()

    cccd_value = 0

    while True:
        char = sys.stdin.readline()
        if 'q' in char:
            break
        else:
            print "Received character {}".format(char)
        cccd_value ^= CCCD_NOTIFY
        set_hrm_cccd(cccd_value)

    if peripheral_connection_handle != ble_driver.BLE_CONN_HANDLE_INVALID:
        ble_driver.sd_ble_gap_disconnect(
            peripheral_connection_handle,
            ble_driver.BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION)

    if central_connection_handle != ble_driver.BLE_CONN_HANDLE_INVALID:
        ble_driver.sd_ble_gap_disconnect(
            peripheral_connection_handle,
            ble_driver.BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION)

    error_code = ble_driver.sd_rpc_close()

    if error_code != ble_driver.NRF_SUCCESS:
        print "Failed to close the nRF51 BLE Driver. Error code: 0x{0:X}".format(
            error_code)
        return

    print "Closed"
Пример #4
0
def main(serial_port):
    intro_message()
    print "Serial port used: {}".format(serial_port)
    ble_driver.sd_rpc_serial_port_name_set(serial_port)
    ble_driver.sd_rpc_serial_baud_rate_set(115200)
    ble_driver.sd_rpc_evt_handler_set(ble_evt_handler)
    ble_driver.sd_rpc_log_handler_set(log_message_handler)
    ble_driver.sd_rpc_open()
    init_ble_stack()
    init_connection_params()
    init_scan_params()
    start_scan()

    while True:
        sleep(1)

    ble_driver.sd_rpc_close()
Пример #5
0
def main(serial_port):
    print "Serial port used: {}".format(serial_port)
    ble_driver.sd_rpc_serial_port_name_set(serial_port)
    ble_driver.sd_rpc_serial_baud_rate_set(115200)
    ble_driver.sd_rpc_log_handler_set(log_message_handler)
    ble_driver.sd_rpc_evt_handler_set(ble_evt_handler)
    error_code = ble_driver.sd_rpc_open()

    if error_code != ble_driver.NRF_SUCCESS:
        print "Failed to open the nRF51 BLE Driver. Error code: 0x{0:X}.".format(error_code)
        return

    error_code = init_ble_stack()

    if error_code != ble_driver.NRF_SUCCESS:
        return

    init_connection_params()
    init_scan_params()

    error_code = init_services()

    if error_code != ble_driver.NRF_SUCCESS:
        return

    set_adv_data()

    start_scan()

    cccd_value = 0

    while True:
        char = sys.stdin.readline()
        if 'q' in char:
            break
        else:
            print "Received character {}".format(char)
        cccd_value ^= CCCD_NOTIFY
        set_hrm_cccd(cccd_value)

    if peripheral_connection_handle != ble_driver.BLE_CONN_HANDLE_INVALID:
        ble_driver.sd_ble_gap_disconnect(peripheral_connection_handle,
                                         ble_driver.BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION)

    if central_connection_handle != ble_driver.BLE_CONN_HANDLE_INVALID:
        ble_driver.sd_ble_gap_disconnect(peripheral_connection_handle,
                                         ble_driver.BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION)

    error_code = ble_driver.sd_rpc_close()

    if error_code != ble_driver.NRF_SUCCESS:
        print "Failed to close the nRF51 BLE Driver. Error code: 0x{0:X}".format(error_code)
        return

    print "Closed"
Пример #6
0
def main(serial_port):
    print "Serial port used: {}".format(serial_port)
    ble_driver.sd_rpc_serial_port_name_set(serial_port)
    ble_driver.sd_rpc_serial_baud_rate_set(115200)
    ble_driver.sd_rpc_evt_handler_set(ble_evt_handler)
    ble_driver.sd_rpc_log_handler_set(log_message_handler)

    error_code = ble_driver.sd_rpc_open()

    if error_code != ble_driver.NRF_SUCCESS:
        print "Failed to open the nRF51 BLE Driver. Error code: 0x{0:02X}".format(error_code)
        return error_code

    error_code = init_ble_stack()

    if error_code != ble_driver.NRF_SUCCESS:
        return

    error_code = init_services()

    if error_code != ble_driver.NRF_SUCCESS:
        return error_code

    set_adv_data()
    start_advertising()

    while not advertisement_timed_out:
        time.sleep(1)
        if connection_handle != ble_driver.BLE_CONN_HANDLE_INVALID and send_notifications:
            error_code = send_heart_rate_measurement()

            if error_code != ble_driver.NRF_SUCCESS:
                break

    error_code = ble_driver.sd_rpc_close()

    if error_code != ble_driver.NRF_SUCCESS:
        print "Failed to close the nRF51 BLE Driver. Error code: 0x{0:02X}".format(error_code)
        return error_code

    print "Closed"
Пример #7
0
def main(serial_port):
    print "Serial port used: {}".format(serial_port)
    ble_driver.sd_rpc_serial_port_name_set(serial_port)
    ble_driver.sd_rpc_serial_baud_rate_set(115200)
    ble_driver.sd_rpc_evt_handler_set(ble_evt_handler)
    ble_driver.sd_rpc_log_handler_set(log_message_handler)

    error_code = ble_driver.sd_rpc_open()

    if error_code != ble_driver.NRF_SUCCESS:
        print "Failed to open the nRF51 BLE Driver. Error code: 0x{0:02X}".format(error_code)
        return error_code

    error_code = init_ble_stack()

    if error_code != ble_driver.NRF_SUCCESS:
        return

    error_code = init_services()

    if error_code != ble_driver.NRF_SUCCESS:
        return error_code

    set_adv_data()
    start_advertising()

    while not advertisement_timed_out:
        time.sleep(1)
        if connection_handle != ble_driver.BLE_CONN_HANDLE_INVALID and send_notifications:
            error_code = send_heart_rate_measurement()

            if error_code != ble_driver.NRF_SUCCESS:
                break

    error_code = ble_driver.sd_rpc_close()

    if error_code != ble_driver.NRF_SUCCESS:
        print "Failed to close the nRF51 BLE Driver. Error code: 0x{0:02X}".format(error_code)
        return error_code

    print "Closed"