Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
taks committed Oct 10, 2024
1 parent da3cd95 commit 7de7fe7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/client/ble_writer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
ble,
utilities::{as_void_ptr, voidp_to_ref},
utilities::{as_void_ptr, ble_hs_mbuf_from_flat, voidp_to_ref},
BLEError, Signal,
};
use esp_idf_svc::sys as esp_idf_sys;
Expand Down Expand Up @@ -48,7 +48,7 @@ impl BLEWriter {
as_void_ptr(self),
))?;
} else {
let om = esp_idf_sys::ble_hs_mbuf_from_flat(data.as_ptr() as _, data.len() as _);
let om = ble_hs_mbuf_from_flat(data);
ble!(esp_idf_sys::ble_gattc_write_long(
self.conn_handle,
self.handle,
Expand Down
8 changes: 4 additions & 4 deletions src/server/ble_characteristic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use crate::cpfd::Cpfd;
use crate::{
ble,
utilities::{
ble_npl_hw_enter_critical, ble_npl_hw_exit_critical, mutex::Mutex, os_mbuf_append,
voidp_to_ref, BleUuid,
ble_hs_mbuf_from_flat, ble_npl_hw_enter_critical, ble_npl_hw_exit_critical, mutex::Mutex,
os_mbuf_append, voidp_to_ref, BleUuid,
},
AttValue, BLEConnDesc, BLEDescriptor, BLEDevice, BLEError, DescriptorProperties, OnWriteArgs,
BLE2904,
Expand Down Expand Up @@ -280,7 +280,7 @@ impl BLECharacteristic {
return BLEError::convert(sys::BLE_HS_EBUSY);
}

let om = unsafe { sys::ble_hs_mbuf_from_flat(value.as_ptr() as _, value.len() as _) };
let om = ble_hs_mbuf_from_flat(value);

let rc = unsafe { sys::ble_gatts_indicate_custom(conn_handle, self.handle, om) };
if rc != 0 {
Expand All @@ -289,7 +289,7 @@ impl BLECharacteristic {
BLEError::convert(rc as _)
} else if flag.contains(NimbleSub::NOTIFY) && self.properties.contains(NimbleProperties::NOTIFY)
{
let om = unsafe { sys::ble_hs_mbuf_from_flat(value.as_ptr() as _, value.len() as _) };
let om = ble_hs_mbuf_from_flat(value);
ble!(unsafe { sys::ble_gatts_notify_custom(conn_handle, self.handle, om) })
} else {
BLEError::convert(sys::BLE_HS_EINVAL)
Expand Down
12 changes: 8 additions & 4 deletions src/utilities/os_mbuf.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use core::ffi::c_int;
use esp_idf_svc::sys as esp_idf_sys;
use esp_idf_sys::os_mbuf;
use esp_idf_svc::sys;
use sys::os_mbuf;

#[cfg(not(esp_idf_soc_esp_nimble_controller))]
use esp_idf_sys::os_mbuf_append as _os_mbuf_append;
use sys::os_mbuf_append as _os_mbuf_append;

#[cfg(esp_idf_soc_esp_nimble_controller)]
use esp_idf_sys::r_os_mbuf_append as _os_mbuf_append;
use sys::r_os_mbuf_append as _os_mbuf_append;

/// Append data onto a mbuf
#[inline]
Expand All @@ -19,3 +19,7 @@ pub(crate) fn os_mbuf_append(m: *mut os_mbuf, data: &[u8]) -> c_int {
pub(crate) fn os_mbuf_into_slice<'a>(m: *const os_mbuf) -> &'a [u8] {
unsafe { core::slice::from_raw_parts((*m).om_data, (*m).om_len as _) }
}

pub(crate) fn ble_hs_mbuf_from_flat(buf: &[u8]) -> *mut os_mbuf {
unsafe { sys::ble_hs_mbuf_from_flat(buf.as_ptr() as _, buf.len() as _) }
}

0 comments on commit 7de7fe7

Please # to comment.