Beispiel #1
0
void main(void)
#endif
{
	int err;
	err = bt_enable(NULL);

	if (err) {
		printk("Bluetooth init failed (err %d)\n", err);
		return;
	}

	printk("Bluetooth initialized\n");

	bt_conn_cb_register(&conn_callbacks);

	err = bt_le_scan_start(BT_LE_SCAN_ACTIVE, device_found);

	if (err) {
		printk("Scanning failed to start (err %d)\n", err);
		return;
	}

	printk("Scanning successfully started\n");

	while (1) {
		task_sleep(SLEEPTICKS);
	}
}
Beispiel #2
0
void main(void)
{
	int err;

	err = bt_enable(bt_ready);
	if (err) {
		printk("Bluetooth init failed (err %d)\n", err);
		return;
	}

	bt_conn_cb_register(&conn_callbacks);
	bt_conn_auth_cb_register(&auth_cb_display);

	/* Implement notification. At the moment there is no suitable way
	 * of starting delayed work so we do it here
	 */
	while (1) {
		k_sleep(MSEC_PER_SEC);

		/* Heartrate measurements simulation */
		hrs_notify();

		/* Battery level simulation */
		bas_notify();
	}
}
Beispiel #3
0
void main(void)
{
	int err;

	err = bt_enable(NULL);
	if (err) {
		printk("Bluetooth init failed (err %d)\n", err);
		return;
	}

	printk("Bluetooth initialized\n");

	gap_init(DEVICE_NAME, APPEARANCE);

	bt_conn_auth_cb_register(&auth_cb_display);
	bt_conn_cb_register(&conn_callbacks);

	err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad),
			      sd, ARRAY_SIZE(sd));
	if (err) {
		printk("Advertising failed to start (err %d)\n", err);
		return;
	}

	printk("Advertising successfully started\n");
}
Beispiel #4
0
void main(void)
{
	struct device *ipm;
	int rc;
	uint32_t value32;

	rc = bt_enable(bt_ready);
	if (rc) {
		printk("Bluetooth init failed (err %d)\n", rc);
		return;
	}
	bt_conn_cb_register(&conn_callbacks);
	bt_conn_auth_cb_register(&auth_cb_display);

	ipm = device_get_binding("power_ipm");
	ipm_register_callback(ipm, sensor_ipm_callback, NULL);
	ipm_set_enabled(ipm, 1);

	while (1) {
		if (default_conn) {
			value32 = sys_cpu_to_le32(consumption_value);
			bt_gatt_notify(default_conn, &attrs[2], &value32,
					sizeof(value32));
			k_sleep(INTERVAL);

			value32 = sys_cpu_to_le32(solar_value);
			bt_gatt_notify(default_conn, &attrs[6], &value32,
					sizeof(value32));
		}
		k_sleep(INTERVAL);
	}
}
Beispiel #5
0
void main(void)
#endif
{
	int err;

	err = bt_enable(NULL);
	if (err) {
		printk("Bluetooth init failed (err %d)\n", err);
		return;
	}

	printk("Bluetooth initialized\n");

	bt_gatt_register(attrs, ARRAY_SIZE(attrs));

	bt_conn_cb_register(&conn_callbacks);

	net_init();

	err = bt_le_adv_start(BT_LE_ADV(BT_LE_ADV_IND), ad, ARRAY_SIZE(ad),
			      sd, ARRAY_SIZE(sd));
	if (err) {
		printk("Advertising failed to start (err %d)\n", err);
		return;
	}

	printk("Advertising successfully started\n");

	listen();
}
Beispiel #6
0
void main(void)
#endif
{
	int err;

	err = bt_enable(bt_ready);
	if (err) {
		printk("Bluetooth init failed (err %d)\n", err);
		return;
	}

	bt_conn_cb_register(&conn_callbacks);

	while (1) {
		task_sleep(sys_clock_ticks_per_sec);

		/* CSC simulation */
		if (csc_simulate) {
			csc_simulation();
		}

		/* Battery level simulation */
		bas_notify();
	}
}
Beispiel #7
0
static int network_setup(void)
{

#if defined(CONFIG_NET_L2_BT)
	const char *progress_mark = "/-\\|";
	int i = 0;
	int rc;

	rc = bt_enable(NULL);
	if (rc) {
		printk("bluetooth init failed\n");
		return rc;
	}

	bt_conn_cb_register(&bt_conn_cb);

	printk("\nwaiting for bt connection: ");
	while (bt_connected == false) {
		k_sleep(250);
		printk("%c\b", progress_mark[i]);
		i = (i + 1) % (sizeof(progress_mark) - 1);
	}
	printk("\n");
#endif

	return 0;
}
Beispiel #8
0
static int net_bt_init(struct device *dev)
{
	NET_DBG("dev %p driver_data %p", dev, dev->driver_data);

#if defined(CONFIG_NET_L2_BLUETOOTH_MGMT)
	bt_conn_cb_register(&conn_callbacks);
#endif
	bt_l2cap_server_register(&server);

	return 0;
}
Beispiel #9
0
void main(void)
{
	int err;

	err = bt_enable(bt_ready);
	if (err) {
		printk("Bluetooth init failed (err %d)\n", err);
		return;
	}

	bt_conn_cb_register(&conn_callbacks);
	bt_conn_auth_cb_register(&auth_cb_display);
}
Beispiel #10
0
int ble_rscs_init(void)
{
	int err;

	err = bt_gatt_register((struct bt_gatt_attr *)rscs_attrs,
			       ARRAY_SIZE(rscs_attrs));

	if (err < 0) {
		goto out;
	}
	bt_conn_cb_register(&conn_callbacks);
out:
	return err;
}
Beispiel #11
0
/* Handles BLE enable message */
static void handle_msg_id_ble_enable_rsp(struct cfw_message *msg)
{
	struct ble_enable_rsp *rsp = container_of(msg, struct ble_enable_rsp,
						  header);

	if (!rsp->status) {
		_ble_app_cb.flags |= BLE_APP_ENABLED;
		_ble_app_cb.my_bd_addr = rsp->bd_addr;

		/* If the name is still not configured, build one */
		if (!_ble_app_cb.device_name[0]) {
			snprintf(_ble_app_cb.device_name,
				 sizeof(_ble_app_cb.device_name),
				 CONFIG_BLE_DEV_NAME "%02x%02x%02x%02x%02x%02x",
				 rsp->bd_addr.val[5], rsp->bd_addr.val[4],
				 rsp->bd_addr.val[3],
				 rsp->bd_addr.val[2], rsp->bd_addr.val[1],
				 rsp->bd_addr.val[0]);
		}

		bt_conn_cb_register(&conn_callbacks);
#ifdef CONFIG_TCMD_BLE
		ble_tcmd_init();
#endif

#if CONFIG_BLE_TX_POWER != 0
		ble_gap_set_tx_power(CONFIG_BLE_TX_POWER);
#endif

		/* registers all services */
		_ble_register_services();

		pr_info(LOG_MODULE_BLE, "ble_enable_rsp: addr/type: "
			"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x/%d",
			rsp->bd_addr.val[5], rsp->bd_addr.val[4],
			rsp->bd_addr.val[3], rsp->bd_addr.val[2],
			rsp->bd_addr.val[1], rsp->bd_addr.val[0],
			rsp->bd_addr.type);

		ble_app_start_advertisement(BLE_ADV_STARTUP);

#ifdef CONFIG_BLE_APP_USE_BAT
		if (_ble_app_cb.p_batt_conn)
			battery_service_get_info(_ble_app_cb.p_batt_conn,
						 BATTERY_DATA_LEVEL, NULL);
#endif
	} else {
		pr_error(LOG_MODULE_BLE, "enable_rsp err %d", rsp->status);
	}
}
Beispiel #12
0
uint8_t tester_init_gap(void)
{
	if (bt_enable(NULL) < 0) {
		return BTP_STATUS_FAILED;
	}

	atomic_clear(&current_settings);
	atomic_set_bit(&current_settings, GAP_SETTINGS_POWERED);
	atomic_set_bit(&current_settings, GAP_SETTINGS_CONNECTABLE);
	atomic_set_bit(&current_settings, GAP_SETTINGS_BONDABLE);
	atomic_set_bit(&current_settings, GAP_SETTINGS_LE);

	bt_conn_cb_register(&conn_callbacks);

	return BTP_STATUS_SUCCESS;
}
Beispiel #13
0
void main(void)
{
	int err;

	err = bt_enable(bt_ready);
	if (err) {
		printk("Bluetooth init failed (err %d)\n", err);
		return;
	}

	bt_conn_cb_register(&conn_callbacks);
	bt_conn_auth_cb_register(&auth_cb_display);

	/* Implement notification. At the moment there is no suitable way
	 * of starting delayed work so we do it here
	 */
	while (1) {
		task_sleep(sys_clock_ticks_per_sec);

		/* Current Time Service updates only when time is changed */
		cts_notify();

		/* Heartrate measurements simulation */
		hrs_notify();

		/* Battery level simulation */
		bas_notify();

		/* Vendor indication simulation */
		if (simulate_vnd) {
			if (indicating) {
				continue;
			}

			ind_params.attr = &vnd_attrs[2];
			ind_params.func = indicate_cb;
			ind_params.data = &indicating;
			ind_params.len = sizeof(indicating);

			if (bt_gatt_indicate(NULL, &ind_params) == 0) {
				indicating = 1;
			}
		}
	}
}
Beispiel #14
0
static void tester_init_gap_cb(int err)
{
	if (err) {
		tester_rsp(BTP_SERVICE_ID_CORE, CORE_REGISTER_SERVICE,
			   BTP_INDEX_NONE, BTP_STATUS_FAILED);
		return;
	}

	atomic_clear(&current_settings);
	atomic_set_bit(&current_settings, GAP_SETTINGS_POWERED);
	atomic_set_bit(&current_settings, GAP_SETTINGS_CONNECTABLE);
	atomic_set_bit(&current_settings, GAP_SETTINGS_BONDABLE);
	atomic_set_bit(&current_settings, GAP_SETTINGS_LE);

	bt_conn_cb_register(&conn_callbacks);

	tester_rsp(BTP_SERVICE_ID_CORE, CORE_REGISTER_SERVICE, BTP_INDEX_NONE,
		   BTP_STATUS_SUCCESS);
}
Beispiel #15
0
void main(void)
{
	struct device *ipm;
	int rc;
	uint16_t value16;
	uint32_t value32;

	rc = bt_enable(bt_ready);
	if (rc) {
		printk("Bluetooth init failed (err %d)\n", rc);
		return;
	}
	bt_conn_cb_register(&conn_callbacks);
	bt_conn_auth_cb_register(&auth_cb_display);

	ipm = device_get_binding("ess_ipm");
	ipm_register_callback(ipm, sensor_ipm_callback, NULL);
	ipm_set_enabled(ipm, 1);

	while (1) {
		/* Notify value changes via BLE here so that the notification intervals can be controlled. */
		if (default_conn) {
			value16 = sys_cpu_to_le16(temp_value);
			bt_gatt_notify(default_conn, &attrs[2], &value16, sizeof(value16));
			k_sleep(INTERVAL);

			value16 = sys_cpu_to_le16(humidity_value);
			bt_gatt_notify(default_conn, &attrs[6], &value16, sizeof(value16));
			k_sleep(INTERVAL);

			value32 = sys_cpu_to_le32(pressure_value);
			bt_gatt_notify(default_conn, &attrs[10], &value32, sizeof(value32));
			k_sleep(INTERVAL);

			value16 = sys_cpu_to_le16(uv_index_value);
			bt_gatt_notify(default_conn, &attrs[14], &uv_index_value, sizeof(uv_index_value));
		}
		k_sleep(INTERVAL);
	}
}
Beispiel #16
0
void main(void)
#endif
{
	int err;

	err = bt_enable(bt_ready);
	if (err) {
		printk("Bluetooth init failed (err %d)\n", err);
		return;
	}

	bt_conn_cb_register(&conn_callbacks);

	while (1) {
		task_sleep(sys_clock_ticks_per_sec);

		/* CSC simulation */
		if (csc_simulate) {
			csc_simulation();
		}

		/* Battery level simulation */
		if (bas_simulate) {
			blvl -= 1;

			if (!blvl) {
				/* Software eco battery charger */
				blvl = 100;
			}

			bt_gatt_notify(NULL, &bas_attrs[2], &blvl,
				       sizeof(blvl));
		}

	}
}