Ejemplo n.º 1
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);
	}
}
bool BLECharacteristicImp::writeValue(const byte value[], int length, int offset)
{
    int status;
    bool retVal = false;
    
    _setValue(value, length, offset);
    
    // Address same is GATT server. Send notification if CCCD enabled
    // Different is GATT client. Send write request
    if (true == BLEUtils::isLocalBLE(_ble_device) &&
        NULL != _attr_chrc_value)
    {
        // Notify for peripheral.
        status = bt_gatt_notify(NULL, _attr_chrc_value, value, length, NULL);
	// Sid.  KW found status is always 0.
	//        if (!status)
	//        {
            retVal = true;
	//        }
    }
    
    //Not schedule write request for central
    // The write request may failed. 
    // If user want to get latest set value. Call read and get the real value
    return retVal;
}
Ejemplo n.º 3
0
int ble_hrs_update(uint8_t value)
{
	struct ble_hrs_measurement measurement;

	measurement.flags = 0;
	measurement.value = value;
	return bt_gatt_notify(NULL, hrs_value, &measurement,
			      sizeof(measurement), NULL);
}
Ejemplo n.º 4
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);
	}
}
Ejemplo n.º 5
0
void bas_notify(void)
{
	if (!simulate_blvl) {
		return;
	}

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

	bt_gatt_notify(NULL, &attrs[2], &battery, sizeof(battery));
}
Ejemplo n.º 6
0
void temperature_ipm_callback(void *context, uint32_t id, volatile void *data)
{
    struct bt_conn *conn = (struct bt_conn *) context;

    switch(id) {
      case 1:
        temperature = *(int32_t*) data;
        printk("Got temperature from ARC %d\n", temperature);
        bt_gatt_notify(conn, &attrs[2], &temperature, sizeof(temperature));
        break;
      case 2:
        humidity = *(uint32_t*) data;
        printk("Got humidity from ARC %d\n", humidity);
        break;
    }
}
Ejemplo n.º 7
0
Archivo: main.c Proyecto: hudkmr/zephyr
static void ctrl_point_ind(struct bt_conn *conn, uint8_t req_op, uint8_t status,
			   const void *data, uint16_t data_len)
{
	struct sc_ctrl_point_ind *ind;
	uint8_t buf[sizeof(*ind) + data_len];

	ind = (void *) buf;
	ind->op = SC_CP_OP_RESPONSE;
	ind->req_op = req_op;
	ind->status = status;

	/* Send data (supported locations) if present */
	if (data && data_len) {
		memcpy(ind->data, data, data_len);
	}

	bt_gatt_notify(conn, &csc_attrs[9], buf, sizeof(buf));
}
bool
BLECharacteristic::setValue(const unsigned char value[], uint16_t length)
{
    int status;

     _setValue(value, length);

    if (_attr_chrc_value)
    {
        // TODO: Notify for peripheral.
        //        Write request for central.
        status = bt_gatt_notify(NULL, _attr_chrc_value, value, length, NULL);
        if (0 != status)
        {
            return false;
        }
    }
    return true;
}
Ejemplo n.º 9
0
static int bas_update_bat_level(struct bt_conn *conn, uint16_t char_handle,
				uint16_t len, uint8_t *p_data,
				struct ble_update_data_rsp *p_rsp)
{
	struct _bt_gatt_ccc *ccc = bas_attrs[BLVL_CCC_HANDLE_IDX].user_data;

	/* use CCCD value for ble service specific purpose to save ram.
	 * notif & indication use the 2 LSBs. */
	if ((ccc->value & (BLE_SVC_BAS_NOTIF_SUP_ON | BT_GATT_CCC_NOTIFY)) ==
			(BLE_SVC_BAS_NOTIF_SUP_ON | BT_GATT_CCC_NOTIFY)) {
		cli_rsp = p_rsp;
		bt_gatt_notify(conn, char_handle, (const void *)p_data,
				   len, bat_lvl_notified);
	} else {
		struct ble_gatts_set_attribute_params params;

		params.value_handle = char_handle;
		params.offset = 0;
		ble_gatts_set_attribute_value_req(&params, p_data, len, p_rsp);
	}
	return BLE_STATUS_SUCCESS;
}
Ejemplo n.º 10
0
Archivo: main.c Proyecto: hudkmr/zephyr
static void measurement_nfy(struct bt_conn *conn, uint32_t cwr, uint16_t lwet,
			    uint16_t ccr, uint16_t lcet)
{
	struct csc_measurement_nfy *nfy;
	uint8_t buf[sizeof(*nfy) +
		    (cwr ? sizeof(struct wheel_rev_data_nfy) : 0) +
		    (ccr ? sizeof(struct crank_rev_data_nfy) : 0)];
	uint16_t len = 0;

	nfy = (void *) buf;
	nfy->flags = 0;

	/* Send Wheel Revolution data is present */
	if (cwr) {
		struct wheel_rev_data_nfy data;

		nfy->flags |= CSC_WHEEL_REV_DATA_PRESENT;
		data.cwr = sys_cpu_to_le32(cwr);
		data.lwet = sys_cpu_to_le16(lwet);

		memcpy(nfy->data, &data, sizeof(data));
		len += sizeof(data);
	}

	/* Send Crank Revolution data is present */
	if (ccr) {
		struct crank_rev_data_nfy data;

		nfy->flags |= CSC_CRANK_REV_DATA_PRESENT;
		data.ccr = sys_cpu_to_le16(ccr);
		data.lcet = sys_cpu_to_le16(lcet);

		memcpy(nfy->data + len, &data, sizeof(data));
	}

	bt_gatt_notify(NULL, &csc_attrs[2], buf, sizeof(buf));
}
Ejemplo n.º 11
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));
		}

	}
}