Compare commits
4 Commits
286eb408ab
...
a20b35b600
Author | SHA1 | Date | |
---|---|---|---|
|
a20b35b600 | ||
|
d97db47fad | ||
|
5387213c06 | ||
|
3faa1162e2 |
@ -58,13 +58,13 @@ bool ble_modem_off(void)
|
||||
uint8_t timeout = 0;
|
||||
while(ble_service_is_started())
|
||||
{
|
||||
tls_os_time_delay(pdMS_TO_TICKS(1));
|
||||
tls_os_time_delay(pdMS_TO_TICKS(5));
|
||||
|
||||
// Service is stuck ?
|
||||
if(++timeout > 10)
|
||||
// Service is stuck ? waiting up to 300 ms for it to stop
|
||||
if(++timeout > 60)
|
||||
{
|
||||
serviceStopSuccess = false;
|
||||
break;
|
||||
TLS_BT_APPL_TRACE_ERROR("%s, ble_service_stop timeout "NEW_LINE, __FUNCTION__);
|
||||
return serviceStopSuccess;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -134,7 +134,7 @@ bool ble_service_start(void)
|
||||
// 1 We first check if the BLE service is stopped
|
||||
if(_ble_service_state != BLE_SERVICE_MODE_STOPPED)
|
||||
{
|
||||
TLS_BT_APPL_TRACE_WARNING("%s, ble service already running"NEW_LINE, __FUNCTION__);
|
||||
TLS_BT_APPL_TRACE_WARNING("%s, ble service already running (%s)"NEW_LINE, __FUNCTION__, ble_service_state_2_str(_ble_service_state));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -327,7 +327,7 @@ bool ble_service_request_mtu_exchange(void)
|
||||
|
||||
bool ble_service_nus_send_data(const uint8_t *data, uint16_t length)
|
||||
{
|
||||
// The NUS is TX is using notification
|
||||
// The NUS TX is using notifications
|
||||
if(notification_data.transfer_in_progress)
|
||||
{
|
||||
TLS_BT_APPL_TRACE_WARNING("%s, a transfer is already in progress"NEW_LINE, __FUNCTION__);
|
||||
@ -487,9 +487,12 @@ static bool ble_service_advertise(bool enable)
|
||||
extern int tls_get_bt_mac_addr(u8 *mac);
|
||||
tls_get_bt_mac_addr(device_addr);
|
||||
|
||||
// Make sure the the device address is compliant with the random address specification :
|
||||
device_addr[5] |= 0xC0;
|
||||
|
||||
if((status = ble_hs_id_set_rnd(device_addr)) != BLE_HS_ENOERR)
|
||||
{
|
||||
TLS_BT_APPL_TRACE_ERROR("%s, ble_hs_id_infer_auto failed : %s"NEW_LINE, __FUNCTION__, tls_bt_rc_2_str(status));
|
||||
TLS_BT_APPL_TRACE_ERROR("%s, ble_hs_id_set_rnd failed : %s"NEW_LINE, __FUNCTION__, tls_bt_rc_2_str(status));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
|
@ -523,9 +523,46 @@ int _rtc(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
||||
|
||||
int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
||||
{
|
||||
if(argc >= 3)
|
||||
if(argc > 1)
|
||||
{
|
||||
if(strcmp(argv[1], "send_ble_notif") == 0)
|
||||
if(strcmp(argv[1], "enable") == 0)
|
||||
{
|
||||
if(argc == 3)
|
||||
{
|
||||
bool result = ble_modem_on(true);
|
||||
shell_printf("Enabling bluetooth modem with ble service : %d"NEW_LINE, result);
|
||||
|
||||
if(result)
|
||||
ble_service_nus_register_data_rx_cb(&(nus_data_rx_cb));
|
||||
}
|
||||
else
|
||||
{
|
||||
shell_printf("Enabling bluetooth modem only : %d"NEW_LINE, ble_modem_on(false));
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[1], "disable") == 0)
|
||||
{
|
||||
shell_printf("Disabling bluetooth : %d"NEW_LINE, ble_modem_off());
|
||||
}
|
||||
else if(strcmp(argv[1], "start_demo") == 0)
|
||||
{
|
||||
bool result = ble_service_start();
|
||||
shell_printf("Starting demo : %d"NEW_LINE"Use a BLE app to find the device"NEW_LINE, result /*demo_ble_server_on()*/);
|
||||
if(result)
|
||||
{
|
||||
ble_service_nus_register_data_rx_cb(&(nus_data_rx_cb));
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[1], "stop_demo") == 0)
|
||||
{
|
||||
shell_printf("Stopping demo : %d"NEW_LINE, ble_service_stop() /*demo_ble_server_off()*/);
|
||||
ble_service_nus_register_data_rx_cb(NULL);
|
||||
}
|
||||
else if(strcmp(argv[1], "mtu_exch") == 0)
|
||||
{
|
||||
shell_printf("MTU exchange request : %d"NEW_LINE, ble_service_request_mtu_exchange());
|
||||
}
|
||||
else if(strcmp(argv[1], "send_ble_notif") == 0 && argc > 2)
|
||||
{
|
||||
char cmd[200] = "";
|
||||
bool found = false;
|
||||
@ -583,51 +620,7 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
shell_printf("Unknown %s action"NEW_LINE, argv[0]);
|
||||
}
|
||||
}
|
||||
else if(argc > 1)
|
||||
{
|
||||
if(strcmp(argv[1], "enable") == 0)
|
||||
{
|
||||
if(argc == 3)
|
||||
{
|
||||
bool result = ble_modem_on(true);
|
||||
shell_printf("Enabling bluetooth modem with ble service : %d"NEW_LINE, result);
|
||||
|
||||
if(result)
|
||||
ble_service_nus_register_data_rx_cb(&(nus_data_rx_cb));
|
||||
}
|
||||
else
|
||||
{
|
||||
shell_printf("Enabling bluetooth modem only : %d"NEW_LINE, ble_modem_on(false));
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[1], "disable") == 0)
|
||||
{
|
||||
shell_printf("Disabling bluetooth : %d"NEW_LINE, ble_modem_off());
|
||||
}
|
||||
else if(strcmp(argv[1], "start_demo") == 0)
|
||||
{
|
||||
bool result = ble_service_start();
|
||||
shell_printf("Starting demo : %d"NEW_LINE"Use a BLE app to find the device"NEW_LINE, result /*demo_ble_server_on()*/);
|
||||
if(result)
|
||||
{
|
||||
ble_service_nus_register_data_rx_cb(&(nus_data_rx_cb));
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[1], "stop_demo") == 0)
|
||||
{
|
||||
shell_printf("Stopping demo : %d"NEW_LINE, ble_service_stop() /*demo_ble_server_off()*/);
|
||||
ble_service_nus_register_data_rx_cb(NULL);
|
||||
}
|
||||
else if(strcmp(argv[1], "mtu_exch") == 0)
|
||||
{
|
||||
shell_printf("MTU exchange request : %d"NEW_LINE, ble_service_request_mtu_exchange());
|
||||
}
|
||||
else
|
||||
{
|
||||
shell_printf("Unknown %s action"NEW_LINE, argv[0]);
|
||||
shell_printf("Unknown %s action"NEW_LINE, argv[1]);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -17,7 +17,7 @@ void tls_nimble_start(void)
|
||||
{
|
||||
tls_host_task_stack_ptr = (void *)tls_mem_alloc(MYNEWT_VAL(OS_HS_STACK_SIZE) * sizeof(uint32_t));
|
||||
assert(tls_host_task_stack_ptr != NULL);
|
||||
tls_os_task_create(&tls_host_task_hdl, "bth",
|
||||
tls_os_task_create(&tls_host_task_hdl, "ble_svc",
|
||||
nimble_host_task,
|
||||
(void *)0,
|
||||
(void *)tls_host_task_stack_ptr,
|
||||
|
Loading…
Reference in New Issue
Block a user