No ACL setup yet! Denying access to everyone.
en:edu:zmitac:s2:aih:lab:nrf52zephyrbleperipheral
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:edu:zmitac:s2:aih:lab:nrf52zephyrbleperipheral [2024/01/13 14:19] – [Adding the possibility of reading the characteristic] ktokarz | en:edu:zmitac:s2:aih:lab:nrf52zephyrbleperipheral [2024/01/13 15:23] (current) – [Adding the possibility of reading the characteristic] ktokarz | ||
|---|---|---|---|
| Line 102: | Line 102: | ||
| * write the callback function that calls bt_gatt_attr_read() (example function in the following code) | * write the callback function that calls bt_gatt_attr_read() (example function in the following code) | ||
| * register callback function within the BT_GATT_CHARACTERISTIC macro using the " | * register callback function within the BT_GATT_CHARACTERISTIC macro using the " | ||
| - | An example of the callback function which simulates the thermometer value can look like this: | + | Notice that the temperature data sent in the original example by indications is encoded in the following format, which can be automatically decoded by nRF Connect software. |
| - | < | + | |
| - | static ssize_t read_ht(struct bt_conn *conn, | + | |
| - | const struct bt_gatt_attr *attr, void *buf, | + | |
| - | | + | |
| - | { | + | |
| - | uint8_t lvl8 = 36; | + | |
| - | return bt_gatt_attr_read(conn, | + | |
| - | } | + | |
| - | </ | + | |
| - | Notice that the temperature data which is sent in the original example by indications is encoded in the following format: | + | |
| < | < | ||
| bool temp_in_fahr_units | bool temp_in_fahr_units | ||
| Line 122: | Line 112: | ||
| uint8_t temp_type | uint8_t temp_type | ||
| </ | </ | ||
| - | All boolean flags are set to 0 (the first byte which is sent is 0x00), so the only data is the temperature expressed as a 32-bit floating point number encoded as an 8-bit exponent and 24-bit mantissa. This format is not compatible | + | All boolean flags are set to 0 (the first byte which is sent is 0x00), so the only data is the temperature expressed as a 32-bit floating point number encoded as an 8-bit exponent and 24-bit mantissa |
| + | < | ||
| + | In the ieee_float32_t format, the exponent is encoded as a signed 8-bit binary 10-based number. The mantissa is encoded as a signed 24-bit binary number. This format is incompatible | ||
| + | </ | ||
| + | An example of the callback function which simulates the thermometer value can look like this: | ||
| + | < | ||
| + | static ssize_t read_ht(struct bt_conn *conn, | ||
| + | const struct bt_gatt_attr *attr, void *buf, | ||
| + | | ||
| + | { | ||
| + | uint8_t temp_buffer[5]; | ||
| + | double temp_read; | ||
| + | uint32_t mantissa; | ||
| + | uint8_t exponent; | ||
| + | |||
| + | temp_read = 36.6; | ||
| + | temp_buffer[0] = 0x00; | ||
| + | |||
| + | // | ||
| + | //mantissa is 24 bits signed binary | ||
| + | //exponent is 8 bits signed 10-base binary | ||
| + | |||
| + | mantissa = (uint32_t)(temp_read * 100); | ||
| + | exponent = (uint8_t)-2; | ||
| + | sys_put_le24(mantissa, | ||
| + | temp_buffer[4] = exponent; | ||
| + | return bt_gatt_attr_read(conn, | ||
| + | } | ||
| + | </ | ||
| ===== Tasks to do during the laboratory ===== | ===== Tasks to do during the laboratory ===== | ||
| - Import the peripheral_ht example. | - Import the peripheral_ht example. | ||
en/edu/zmitac/s2/aih/lab/nrf52zephyrbleperipheral.1705151999.txt.gz · Last modified: by ktokarz
