Rephrased comment

This commit is contained in:
Th3maz1ng 2023-03-31 16:09:54 +02:00
parent f7c692c751
commit c04c035a4a
4 changed files with 32 additions and 11 deletions

View File

@ -88,4 +88,4 @@ bool is_ble_modem_on(void)
if(bt_adapter_state == WM_BT_STATE_OFF || bt_system_action != WM_BT_SYSTEM_ACTION_IDLE)
return false;
return true;
}
}

View File

@ -11,6 +11,7 @@
/* ble service internal workings attributes */
static volatile ble_service_state_e _ble_service_state = BLE_SERVICE_MODE_STOPPED;
static nus_data_rx_fn_t _ble_service_nus_data_rx_cb = NULL;
static ble_service_state_change_fn_t _ble_service_state_change_cb = NULL;
/* Connection handle to the connected device : only one simultaneous connection */
static uint16_t ble_device_conn_handle = BLE_HS_CONN_HANDLE_NONE;
@ -268,6 +269,11 @@ bool ble_service_is_device_connected(void)
return _ble_service_state == BLE_SERVICE_MODE_CONNECTED;
}
void ble_service_register_state_change_cb(ble_service_state_change_fn_t ble_service_state_change_cb)
{
_ble_service_state_change_cb = ble_service_state_change_cb;
}
ble_service_state_e ble_service_get_state(void)
{
return _ble_service_state;
@ -325,7 +331,7 @@ bool ble_service_request_mtu_exchange(void)
return true;
}
bool ble_service_nus_send_data(const uint8_t *data, uint16_t length)
bool ble_service_send_nus_data(const uint8_t *data, uint16_t length)
{
// The NUS TX is using notifications
if(notification_data.transfer_in_progress)
@ -341,7 +347,7 @@ bool ble_service_nus_send_data(const uint8_t *data, uint16_t length)
return ble_service_send_custom_notification(gatt_nus_char_tx_handle, &notification_data);
}
void ble_service_nus_register_data_rx_cb(nus_data_rx_fn_t nus_data_rx_cb)
void ble_service_register_nus_data_rx_cb(nus_data_rx_fn_t nus_data_rx_cb)
{
_ble_service_nus_data_rx_cb = nus_data_rx_cb;
}
@ -560,6 +566,9 @@ static int ble_gap_event_cb(struct ble_gap_event *event, void *arg)
_ble_service_state = BLE_SERVICE_MODE_CONNECTED;
usable_mtu = USABLE_DEFAULT_MTU;
ble_device_conn_handle = event->connect.conn_handle;
//We call the state change callback if registered
if(_ble_service_state_change_cb)_ble_service_state_change_cb(_ble_service_state);
}
else
{
@ -623,6 +632,9 @@ static int ble_gap_event_cb(struct ble_gap_event *event, void *arg)
}
_ble_service_state = BLE_SERVICE_MODE_ADVERTISING;
}
//We call the state change callback if registered
if(_ble_service_state_change_cb)_ble_service_state_change_cb(_ble_service_state);
break;
case BLE_GAP_EVENT_CONN_UPDATE:
TLS_BT_APPL_TRACE_DEBUG("Conn update status : %d"NEW_LINE, event->conn_update.status);
@ -683,7 +695,7 @@ static int ble_gap_event_cb(struct ble_gap_event *event, void *arg)
else
{
TLS_BT_APPL_TRACE_VERBOSE("last data chunk sent, end of the transfer"NEW_LINE);
// All data has been sent, end of the transfer
// All data have been sent, end of the transfer
reset_data_being_sent(&notification_data);
}
}
@ -729,8 +741,7 @@ static int battery_level_char_access_cb(uint16_t conn_handle, uint16_t attr_hand
static int gatt_nus_char_access_cb(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg)
{
TLS_BT_APPL_TRACE_EVENT("gatt_nus_char_access_cb op : %s"NEW_LINE, tls_bt_access_opt_2_str(ctxt->op));
//TLS_BT_APPL_TRACE_EVENT("gatt_nus_char_access_cb op : %s"NEW_LINE, tls_bt_access_opt_2_str(ctxt->op));
switch(ctxt->op)
{
case BLE_GATT_ACCESS_OP_WRITE_CHR:
@ -774,4 +785,4 @@ static void reset_data_being_sent(data_being_sent_t * const data)
{
memset(data, 0, sizeof(data_being_sent_t));
}
}
}

View File

@ -19,6 +19,8 @@ typedef enum
BLE_SERVICE_MODE_EXITING
} ble_service_state_e;
typedef void (*ble_service_state_change_fn_t)(ble_service_state_e service_state);
/**
* @brief Resturns the corresponding enum name as a string
*
@ -59,6 +61,14 @@ bool ble_service_is_started(void);
*/
bool ble_service_is_device_connected(void);
/**
* @brief Registers a callback function called every time the state of the BLE service changes.
* For example, you can register a callback to know if a device connected to the service, or disconnected
*
* @param ble_service_state_change_cb the function to register as the callback. The ble_service_state parameter is set to the new state.
*/
void ble_service_register_state_change_cb(ble_service_state_change_fn_t ble_service_state_change_cb);
/**
* @brief Returns the current state of the ble service
*
@ -103,7 +113,7 @@ bool ble_service_request_mtu_exchange(void);
* @return true on success
* @return false on failure
*/
bool ble_service_nus_send_data(const uint8_t *data, uint16_t length);
bool ble_service_send_nus_data(const uint8_t *data, uint16_t length);
/**
* @brief Registers a function which will be called every time data is received by the nus rx
@ -111,6 +121,6 @@ bool ble_service_nus_send_data(const uint8_t *data, uint16_t length);
*
* @param nus_data_rx_cb a pointer to the function to call of type nus_data_rx_fn_t
*/
void ble_service_nus_register_data_rx_cb(nus_data_rx_fn_t nus_data_rx_cb);
void ble_service_register_nus_data_rx_cb(nus_data_rx_fn_t nus_data_rx_cb);
#endif //BLE_APP_H
#endif //BLE_APP_H

View File

@ -2,7 +2,7 @@
#define BLUETOOTH_SIG_VALUES_H
#define BLE_DEVICE_APPEARANCE (0x00C2) //Smart Watch
#define BLE_DEVICE_NAME "W800SmartWatch"
#define BLE_DEVICE_NAME "MDBT42Q_DEV"
#define BLE_DEVICE_ADV_SERVICE (0x180F) //Battery Service