Skip to content

Commit

Permalink
Add offset arg to read_cb and offset and flags args to write_cb
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnny Robeson committed Apr 26, 2024
1 parent 44f06a3 commit 27c62a5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
7 changes: 5 additions & 2 deletions include/ble_utils/ble_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ class Characteristic
* @return Number of bytes read, or in case of an error
* BT_GATT_ERR() with a specific BT_ATT_ERR_* error code.
*/
virtual ssize_t read_cb(void *buf, uint16_t len)
virtual ssize_t read_cb(void *buf, uint16_t len, uint16_t offset)
{
ARG_UNUSED(buf);
ARG_UNUSED(len);
ARG_UNUSED(offset);
return 0;
};

Expand All @@ -78,10 +79,12 @@ class Characteristic
* @return Number of bytes written, or in case of an error
* BT_GATT_ERR() with a specific BT_ATT_ERR_* error code.
*/
virtual ssize_t write_cb(const void *buf,uint16_t len)
virtual ssize_t write_cb(const void *buf,uint16_t len, uint16_t offset, uint8_t flags)
{
ARG_UNUSED(buf);
ARG_UNUSED(len);
ARG_UNUSED(offset);
ARG_UNUSED(flags);
return 0;
}

Expand Down
3 changes: 2 additions & 1 deletion samples/uptime/src/uptime_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ Basic::Basic():
{
}

ssize_t Basic::read_cb(void *buf, uint16_t len)
ssize_t Basic::read_cb(void *buf, uint16_t len, uint16_t offset)
{
ARG_UNUSED(offset);
uint8_t * pUptime = static_cast<uint8_t*>(buf);
pUptime[0] = m_uptime & 0xFF;
pUptime[1] = m_uptime>>8 & 0xFF;
Expand Down
2 changes: 1 addition & 1 deletion samples/uptime/src/uptime_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Basic final: public ble_utils::gatt::Characteristic
Basic();
void update(uint32_t uptime);
private:
ssize_t read_cb(void *buf, uint16_t len) override;
ssize_t read_cb(void *buf, uint16_t len, uint16_t offset) override;
uint32_t m_uptime{0};
};

Expand Down
8 changes: 3 additions & 5 deletions src/ble_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ ssize_t Characteristic::_read_cb(struct bt_conn *conn,
uint16_t offset)
{
ARG_UNUSED(conn);
ARG_UNUSED(offset);
auto instance = static_cast<Characteristic *>(attr->user_data);
return instance->read_cb(buf, len);
return instance->read_cb(buf, len, offset);
}
ssize_t Characteristic::_write_cb(struct bt_conn *conn,
const struct bt_gatt_attr *attr,
Expand All @@ -78,10 +77,8 @@ ssize_t Characteristic::_write_cb(struct bt_conn *conn,
uint8_t flags)
{
ARG_UNUSED(conn);
ARG_UNUSED(offset);
ARG_UNUSED(flags);
auto instance = static_cast<Characteristic *>(attr->user_data);
return instance->write_cb(buf, len);
return instance->write_cb(buf, len, offset, flags);
}

Service::Service(const bt_uuid *uuid):
Expand Down Expand Up @@ -112,6 +109,7 @@ void Service::register_char(const Characteristic * chrc)
ICharacteristicCCC::attr_size
: Characteristic::attr_size;
const auto req_size{m_gatt_service.attr_count + chrc_attr_size};
ARG_UNUSED(req_size);
__ASSERT(req_size <= MAX_ATTR, "Max. attribute size reached");
attrs[m_gatt_service.attr_count++] = chrc->m_attr;
attrs[m_gatt_service.attr_count++] = chrc->m_attr_value;
Expand Down

0 comments on commit 27c62a5

Please sign in to comment.