Browse Source

zdatachanel记录上一次接收到消息的时间

master
zhaohe 1 year ago
parent
commit
a0a8566a64
  1. 2
      include/zdatachannel_service.h
  2. 13
      src/zdatachannel_service.c

2
include/zdatachannel_service.h

@ -87,6 +87,8 @@ static inline uint32_t zdatachannel_block_data_send2(uint8_t* p_data, uint16_t p
return zdatachannel_block_data_send(p_data, &p_length);
}
uint32_t zdatachannel_last_rx_data_haspassed_s();
#ifdef __cplusplus
}
#endif

13
src/zdatachannel_service.c

@ -21,7 +21,8 @@
} /**< Used vendor specific UUID. */
static zdatachannel_t *p_datachannel;
//static uint32_t m_mtusize;
static uint32_t m_last_rx_data_tp;
// static uint32_t m_mtusize;
static bool notification_enable(uint16_t conn_handle, uint16_t cccd_handle) {
ret_code_t err_code;
@ -48,6 +49,7 @@ static void on_write(zdatachannel_t *p_nus, ble_evt_t const *p_ble_evt) {
ble_gatts_evt_write_t const *p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
memset(&evt, 0, sizeof(zdatachannel_evt_t));
m_last_rx_data_tp = znordic_getpower_on_s();
if ((p_evt_write->handle == p_nus->cmd_tx_handles.cccd_handle) && (p_evt_write->len == 2)) {
if (ble_srv_is_notification_enabled(p_evt_write->data)) {
@ -223,3 +225,12 @@ uint32_t zdatachannel_block_data_send(uint8_t *p_data, uint16_t *p_length) {
return sd_ble_gatts_hvx(p_datachannel->conn_handle, &hvx_params);
}
uint32_t zdatachannel_last_rx_data_haspassed_s() { //
uint32_t now = znordic_getpower_on_s();
if (now > m_last_rx_data_tp) {
return now - m_last_rx_data_tp;
} else {
return 0;
}
}
Loading…
Cancel
Save