Compare commits
4 Commits
082c2c6a6c
...
13e7553d09
Author | SHA1 | Date | |
---|---|---|---|
13e7553d09 | |||
e6b1595bae | |||
cf50df7468 | |||
18b602bbca |
@ -1,4 +1,6 @@
|
|||||||
#include "app_utils.h"
|
#include "app_utils.h"
|
||||||
|
#include <math.h>
|
||||||
|
#include "wm_crypto_hard.h"
|
||||||
|
|
||||||
static uint32_t millis_cnt = 0;
|
static uint32_t millis_cnt = 0;
|
||||||
|
|
||||||
@ -52,4 +54,23 @@ void ms_delay(uint32_t ms)
|
|||||||
while(tls_timer_read(timer_id) < ms);
|
while(tls_timer_read(timer_id) < ms);
|
||||||
|
|
||||||
tls_timer_destroy(timer_id);
|
tls_timer_destroy(timer_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t random_gen_6_digit(void)
|
||||||
|
{
|
||||||
|
unsigned char random_buf[6] = {0};
|
||||||
|
uint32_t output_num = 0;
|
||||||
|
|
||||||
|
tls_crypto_random_init(0x19031998, CRYPTO_RNG_SWITCH_16);
|
||||||
|
tls_crypto_random_bytes(random_buf, sizeof random_buf);
|
||||||
|
tls_crypto_random_stop();
|
||||||
|
|
||||||
|
for(uint8_t i = 0; i < sizeof random_buf; i++)
|
||||||
|
{
|
||||||
|
// Ensures the last digit is not 0
|
||||||
|
if(i == (sizeof random_buf) - 1 && random_buf[i] % 10 == 0)random_buf[i]++;
|
||||||
|
output_num += (random_buf[i] % 10) * pow(10, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return output_num;
|
||||||
}
|
}
|
@ -11,4 +11,6 @@ void us_delay(uint32_t us);
|
|||||||
|
|
||||||
void ms_delay(uint32_t ms);
|
void ms_delay(uint32_t ms);
|
||||||
|
|
||||||
|
uint32_t random_gen_6_digit(void);
|
||||||
|
|
||||||
#endif //APP_UTILS_H
|
#endif //APP_UTILS_H
|
@ -2,6 +2,7 @@
|
|||||||
#include "app_common.h"
|
#include "app_common.h"
|
||||||
#include "host/ble_hs.h"
|
#include "host/ble_hs.h"
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
|
#include "wm_bt.h"
|
||||||
#include "wm_bt_def.h"
|
#include "wm_bt_def.h"
|
||||||
#include "wm_bt_app.h"
|
#include "wm_bt_app.h"
|
||||||
#include "wm_bt_util.h"
|
#include "wm_bt_util.h"
|
||||||
@ -10,6 +11,8 @@
|
|||||||
//Is needed for the BT off workaround
|
//Is needed for the BT off workaround
|
||||||
#include "wm_wifi.h"
|
#include "wm_wifi.h"
|
||||||
|
|
||||||
|
static bool _ble_modem_is_sleeping = false;
|
||||||
|
|
||||||
bool ble_modem_on(bool bluetoothOnly, bool startService)
|
bool ble_modem_on(bool bluetoothOnly, bool startService)
|
||||||
{
|
{
|
||||||
int status = BLE_HS_ENOERR;
|
int status = BLE_HS_ENOERR;
|
||||||
@ -33,9 +36,18 @@ bool ble_modem_on(bool bluetoothOnly, bool startService)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// We disable the sleep mode if it was enabled
|
||||||
|
if(!ble_modem_is_sleeping())
|
||||||
|
{
|
||||||
|
if(!ble_modem_wake())
|
||||||
|
TLS_BT_APPL_TRACE_ERROR("%s, ble_modem_wake failed"NEW_LINE, __FUNCTION__);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// If we successfully started the modem, we can set it's working mode.
|
// If we successfully started the modem, we can set it's working mode.
|
||||||
if(bluetoothOnly)
|
if(bluetoothOnly)
|
||||||
tls_rf_bt_mode(true);
|
tls_rf_bt_mode(true);
|
||||||
|
|
||||||
// Start the ble service if it was asked and if it is not yet started
|
// Start the ble service if it was asked and if it is not yet started
|
||||||
if(startService && !ble_service_is_started())
|
if(startService && !ble_service_is_started())
|
||||||
serviceStartSuccess = ble_service_start();
|
serviceStartSuccess = ble_service_start();
|
||||||
@ -56,6 +68,12 @@ bool ble_modem_off(void)
|
|||||||
return TLS_BT_STATUS_SUCCESS;
|
return TLS_BT_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(ble_modem_is_sleeping())
|
||||||
|
{
|
||||||
|
if(!ble_modem_wake())
|
||||||
|
TLS_BT_APPL_TRACE_ERROR("%s, ble_modem_wake failed"NEW_LINE, __FUNCTION__);
|
||||||
|
}
|
||||||
|
|
||||||
if(ble_service_is_started())
|
if(ble_service_is_started())
|
||||||
{
|
{
|
||||||
serviceStopSuccess = ble_service_stop();
|
serviceStopSuccess = ble_service_stop();
|
||||||
@ -96,3 +114,22 @@ bool is_ble_modem_on(void)
|
|||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ble_modem_sleep(void)
|
||||||
|
{
|
||||||
|
bool status = tls_bt_ctrl_sleep(true);
|
||||||
|
if(status)_ble_modem_is_sleeping = true;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_modem_wake(void)
|
||||||
|
{
|
||||||
|
bool status = tls_bt_ctrl_sleep(false);
|
||||||
|
if(status)_ble_modem_is_sleeping = false;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ble_modem_is_sleeping(void)
|
||||||
|
{
|
||||||
|
return _ble_modem_is_sleeping;
|
||||||
|
}
|
||||||
|
@ -29,4 +29,32 @@ bool ble_modem_off(void);
|
|||||||
*/
|
*/
|
||||||
bool is_ble_modem_on(void);
|
bool is_ble_modem_on(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the BLE modem to sleep during IDLE times.
|
||||||
|
* This will lead to a latency penalty of arround 10 seconds,
|
||||||
|
* upon receiving a new frame but reduces power consumption when using BLE.
|
||||||
|
*
|
||||||
|
* @return true if the modem was successfully set to sleep.
|
||||||
|
* @return false if not
|
||||||
|
*/
|
||||||
|
bool ble_modem_sleep(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Disables the sleep state of the BLE modem. Latency will increase and power
|
||||||
|
* consumption also.
|
||||||
|
*
|
||||||
|
* @return true if the modem woke up successfully
|
||||||
|
* @return false otherwise
|
||||||
|
*/
|
||||||
|
bool ble_modem_wake(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns true if the BLE modem is allowed to sleep during IDLE times, false
|
||||||
|
* if it is not allowed to sleep.
|
||||||
|
*
|
||||||
|
* @return true if it is sleeping or allowed to sleep
|
||||||
|
* @return false otherwise
|
||||||
|
*/
|
||||||
|
bool ble_modem_is_sleeping(void);
|
||||||
|
|
||||||
#endif //BLE_MODEM_H
|
#endif //BLE_MODEM_H
|
||||||
|
@ -17,6 +17,7 @@ static uint32_t _pairing_passkey = 0;
|
|||||||
/* Connection handle to the connected device : only one simultaneous connection */
|
/* Connection handle to the connected device : only one simultaneous connection */
|
||||||
static uint16_t ble_device_conn_handle = BLE_HS_CONN_HANDLE_NONE;
|
static uint16_t ble_device_conn_handle = BLE_HS_CONN_HANDLE_NONE;
|
||||||
static uint16_t usable_mtu = USABLE_DEFAULT_MTU;
|
static uint16_t usable_mtu = USABLE_DEFAULT_MTU;
|
||||||
|
static uint8_t _device_mac_address[6] = {0x00};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Structure used to store the various data to carry out a chunked notification or indication data transfer
|
* @brief Structure used to store the various data to carry out a chunked notification or indication data transfer
|
||||||
@ -31,7 +32,8 @@ typedef struct
|
|||||||
bool transfer_in_progress; // Is a transfer already in progress ?
|
bool transfer_in_progress; // Is a transfer already in progress ?
|
||||||
} data_being_sent_t;
|
} data_being_sent_t;
|
||||||
|
|
||||||
// Only one transfer of a type () can occur at any given time
|
// Only one transfer of a type can occur at any given time ie
|
||||||
|
// one notification and one indication can happen at the same time but not more.
|
||||||
static data_being_sent_t notification_data = {.data = NULL, .length = 0, .offset = 0, .transfer_in_progress = false};
|
static data_being_sent_t notification_data = {.data = NULL, .length = 0, .offset = 0, .transfer_in_progress = false};
|
||||||
static data_being_sent_t indication_data = {.data = NULL, .length = 0, .offset = 0, .transfer_in_progress = false};
|
static data_being_sent_t indication_data = {.data = NULL, .length = 0, .offset = 0, .transfer_in_progress = false};
|
||||||
|
|
||||||
@ -284,6 +286,28 @@ bool ble_service_is_device_connected(void)
|
|||||||
return _ble_service_state == BLE_SERVICE_MODE_CONNECTED;
|
return _ble_service_state == BLE_SERVICE_MODE_CONNECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const uint8_t *ble_service_get_device_mac_address(void)
|
||||||
|
{
|
||||||
|
// We only need to read from efuse section once.
|
||||||
|
if(
|
||||||
|
_device_mac_address[0] == 0 &&
|
||||||
|
_device_mac_address[1] == 0 &&
|
||||||
|
_device_mac_address[2] == 0 &&
|
||||||
|
_device_mac_address[3] == 0 &&
|
||||||
|
_device_mac_address[4] == 0 &&
|
||||||
|
_device_mac_address[5] == 0
|
||||||
|
)
|
||||||
|
{
|
||||||
|
extern int tls_get_bt_mac_addr(u8 *mac);
|
||||||
|
tls_get_bt_mac_addr(_device_mac_address);
|
||||||
|
|
||||||
|
// Make sure the device address is compliant with the random address specification :
|
||||||
|
_device_mac_address[5] |= 0xC0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _device_mac_address;
|
||||||
|
}
|
||||||
|
|
||||||
void ble_service_register_state_change_cb(ble_service_state_change_fn_t ble_service_state_change_cb)
|
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_change_cb = ble_service_state_change_cb;
|
||||||
@ -299,6 +323,11 @@ void ble_service_set_pairing_passkey(uint32_t passkey)
|
|||||||
_pairing_passkey = passkey;
|
_pairing_passkey = passkey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t ble_service_get_active_pairing_passkey(void)
|
||||||
|
{
|
||||||
|
return _pairing_passkey;
|
||||||
|
}
|
||||||
|
|
||||||
bool ble_service_update_connection_parameters(
|
bool ble_service_update_connection_parameters(
|
||||||
uint16_t itvl_min,
|
uint16_t itvl_min,
|
||||||
uint16_t itvl_max,
|
uint16_t itvl_max,
|
||||||
@ -323,7 +352,7 @@ bool ble_service_update_connection_parameters(
|
|||||||
gap_params_to_apply.min_ce_len = min_ce_len;
|
gap_params_to_apply.min_ce_len = min_ce_len;
|
||||||
gap_params_to_apply.max_ce_len = max_ce_len;
|
gap_params_to_apply.max_ce_len = max_ce_len;
|
||||||
|
|
||||||
if ((status = ble_gap_update_params(ble_device_conn_handle, &gap_params_to_apply)) != BLE_HS_ENOERR)
|
if((status = ble_gap_update_params(ble_device_conn_handle, &gap_params_to_apply)) != BLE_HS_ENOERR)
|
||||||
{
|
{
|
||||||
TLS_BT_APPL_TRACE_ERROR("%s, ble_gap_update_params failed %s" NEW_LINE, __FUNCTION__, tls_bt_rc_2_str(status));
|
TLS_BT_APPL_TRACE_ERROR("%s, ble_gap_update_params failed %s" NEW_LINE, __FUNCTION__, tls_bt_rc_2_str(status));
|
||||||
return false;
|
return false;
|
||||||
@ -360,6 +389,8 @@ bool ble_service_send_nus_data(const uint8_t *data, uint16_t length)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(ble_modem_is_sleeping())ble_modem_wake();
|
||||||
|
|
||||||
notification_data.transfer_in_progress = true;
|
notification_data.transfer_in_progress = true;
|
||||||
notification_data.data = data;
|
notification_data.data = data;
|
||||||
notification_data.length = length;
|
notification_data.length = length;
|
||||||
@ -488,15 +519,9 @@ static bool ble_service_advertise(bool enable)
|
|||||||
advertisement_fields.appearance = ble_svc_gap_device_appearance();
|
advertisement_fields.appearance = ble_svc_gap_device_appearance();
|
||||||
advertisement_fields.appearance_is_present = 1;
|
advertisement_fields.appearance_is_present = 1;
|
||||||
|
|
||||||
// Set the name of a watch supported by GB
|
// Set the name of the BLE device
|
||||||
#ifdef GADGETBRIDGE_SUPPORT
|
|
||||||
static const char dev_name[12] = "Bangle.js 2";
|
|
||||||
advertisement_fields.name = (uint8_t *)dev_name;//ble_svc_gap_device_name();
|
|
||||||
advertisement_fields.name_len = 11;//strlen(ble_svc_gap_device_name());
|
|
||||||
#else
|
|
||||||
advertisement_fields.name = (uint8_t *)ble_svc_gap_device_name();
|
advertisement_fields.name = (uint8_t *)ble_svc_gap_device_name();
|
||||||
advertisement_fields.name_len = strlen(ble_svc_gap_device_name());
|
advertisement_fields.name_len = strlen(ble_svc_gap_device_name());
|
||||||
#endif
|
|
||||||
|
|
||||||
advertisement_fields.name_is_complete = 1;
|
advertisement_fields.name_is_complete = 1;
|
||||||
|
|
||||||
@ -514,15 +539,10 @@ static bool ble_service_advertise(bool enable)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We the device address
|
// We set the device address
|
||||||
uint8_t device_addr[6] = {0};
|
const uint8_t *device_mac_address = ble_service_get_device_mac_address();
|
||||||
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 :
|
if((status = ble_hs_id_set_rnd(device_mac_address)) != BLE_HS_ENOERR)
|
||||||
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_set_rnd 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;
|
return false;
|
||||||
@ -531,12 +551,12 @@ static bool ble_service_advertise(bool enable)
|
|||||||
{
|
{
|
||||||
TLS_BT_APPL_TRACE_VERBOSE("addr type : %s"NEW_LINE"device addr : %02X:%02X:%02X:%02X:%02X:%02X"NEW_LINE,
|
TLS_BT_APPL_TRACE_VERBOSE("addr type : %s"NEW_LINE"device addr : %02X:%02X:%02X:%02X:%02X:%02X"NEW_LINE,
|
||||||
tls_bt_addr_type_2_str(own_addr_type),
|
tls_bt_addr_type_2_str(own_addr_type),
|
||||||
device_addr[5],
|
device_mac_address[5],
|
||||||
device_addr[4],
|
device_mac_address[4],
|
||||||
device_addr[3],
|
device_mac_address[3],
|
||||||
device_addr[2],
|
device_mac_address[2],
|
||||||
device_addr[1],
|
device_mac_address[1],
|
||||||
device_addr[0]);
|
device_mac_address[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We are now ready to configure the advertisement parameters
|
// We are now ready to configure the advertisement parameters
|
||||||
@ -593,6 +613,8 @@ static int ble_gap_event_cb(struct ble_gap_event *event, void *arg)
|
|||||||
usable_mtu = USABLE_DEFAULT_MTU;
|
usable_mtu = USABLE_DEFAULT_MTU;
|
||||||
ble_device_conn_handle = event->connect.conn_handle;
|
ble_device_conn_handle = event->connect.conn_handle;
|
||||||
|
|
||||||
|
// We register an event callback on the connection,
|
||||||
|
// this allows to be notified on the passkey action event
|
||||||
if((status = ble_gap_set_event_cb(event->connect.conn_handle, &(ble_conn_gap_event_cb), NULL)) != BLE_HS_ENOERR)
|
if((status = ble_gap_set_event_cb(event->connect.conn_handle, &(ble_conn_gap_event_cb), NULL)) != BLE_HS_ENOERR)
|
||||||
{
|
{
|
||||||
TLS_BT_APPL_TRACE_WARNING("%s, ble_gap_set_event_cb %s"NEW_LINE, __FUNCTION__, tls_bt_rc_2_str(status));
|
TLS_BT_APPL_TRACE_WARNING("%s, ble_gap_set_event_cb %s"NEW_LINE, __FUNCTION__, tls_bt_rc_2_str(status));
|
||||||
@ -600,7 +622,7 @@ static int ble_gap_event_cb(struct ble_gap_event *event, void *arg)
|
|||||||
//We call the state change callback if registered
|
//We call the state change callback if registered
|
||||||
if(_ble_service_state_change_cb)_ble_service_state_change_cb(_ble_service_state);
|
if(_ble_service_state_change_cb)_ble_service_state_change_cb(_ble_service_state);
|
||||||
|
|
||||||
tls_bt_ctrl_sleep(false);
|
if(ble_modem_is_sleeping())ble_modem_wake();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -691,6 +713,20 @@ static int ble_gap_event_cb(struct ble_gap_event *event, void *arg)
|
|||||||
event->subscribe.cur_notify,
|
event->subscribe.cur_notify,
|
||||||
event->subscribe.prev_notify
|
event->subscribe.prev_notify
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if(gatt_nus_char_tx_handle == event->subscribe.attr_handle)
|
||||||
|
{
|
||||||
|
if(event->subscribe.cur_notify || event->subscribe.cur_indicate)
|
||||||
|
{
|
||||||
|
//We call the state change callback if registered
|
||||||
|
if(_ble_service_state_change_cb)_ble_service_state_change_cb(BLE_SERVICE_MODE_SUBSCRIBED);
|
||||||
|
}
|
||||||
|
else if(!event->subscribe.cur_notify && !event->subscribe.cur_indicate)
|
||||||
|
{
|
||||||
|
//We call the state change callback if registered
|
||||||
|
if(_ble_service_state_change_cb)_ble_service_state_change_cb(BLE_SERVICE_MODE_UNSUBSCRIBED);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case BLE_GAP_EVENT_MTU:
|
case BLE_GAP_EVENT_MTU:
|
||||||
TLS_BT_APPL_TRACE_VERBOSE("MTU update : %u"NEW_LINE, event->mtu.value);
|
TLS_BT_APPL_TRACE_VERBOSE("MTU update : %u"NEW_LINE, event->mtu.value);
|
||||||
@ -729,6 +765,7 @@ static int ble_gap_event_cb(struct ble_gap_event *event, void *arg)
|
|||||||
TLS_BT_APPL_TRACE_VERBOSE("last data chunk sent, end of the transfer"NEW_LINE);
|
TLS_BT_APPL_TRACE_VERBOSE("last data chunk sent, end of the transfer"NEW_LINE);
|
||||||
// All data have been sent, end of the transfer
|
// All data have been sent, end of the transfer
|
||||||
reset_data_being_sent(¬ification_data);
|
reset_data_being_sent(¬ification_data);
|
||||||
|
if(!ble_modem_is_sleeping())ble_modem_sleep();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // Indication
|
else // Indication
|
||||||
|
@ -15,6 +15,8 @@ typedef enum
|
|||||||
BLE_SERVICE_MODE_IDLE,
|
BLE_SERVICE_MODE_IDLE,
|
||||||
BLE_SERVICE_MODE_ADVERTISING,
|
BLE_SERVICE_MODE_ADVERTISING,
|
||||||
BLE_SERVICE_MODE_CONNECTED,
|
BLE_SERVICE_MODE_CONNECTED,
|
||||||
|
BLE_SERVICE_MODE_SUBSCRIBED,
|
||||||
|
BLE_SERVICE_MODE_UNSUBSCRIBED,
|
||||||
BLE_SERVICE_MODE_INDICATING,
|
BLE_SERVICE_MODE_INDICATING,
|
||||||
BLE_SERVICE_MODE_EXITING
|
BLE_SERVICE_MODE_EXITING
|
||||||
} ble_service_state_e;
|
} ble_service_state_e;
|
||||||
@ -61,6 +63,13 @@ bool ble_service_is_started(void);
|
|||||||
*/
|
*/
|
||||||
bool ble_service_is_device_connected(void);
|
bool ble_service_is_device_connected(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the MAC address of the BLE device.
|
||||||
|
*
|
||||||
|
* @return a pointer to a constant array of size 6 containing the address.
|
||||||
|
*/
|
||||||
|
const uint8_t *ble_service_get_device_mac_address(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Registers a callback function called every time the state of the BLE service changes.
|
* @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
|
* For example, you can register a callback to know if a device connected to the service, or disconnected
|
||||||
@ -70,19 +79,27 @@ bool ble_service_is_device_connected(void);
|
|||||||
void ble_service_register_state_change_cb(ble_service_state_change_fn_t ble_service_state_change_cb);
|
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
|
* @brief Returns the current state of the ble service.
|
||||||
*
|
*
|
||||||
* @return ble_service_state_e
|
* @return ble_service_state_e enum value
|
||||||
*/
|
*/
|
||||||
ble_service_state_e ble_service_get_state(void);
|
ble_service_state_e ble_service_get_state(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief Sets the passkey which is asked by the phone when trying to pair the device for the first time.
|
||||||
*
|
*
|
||||||
* @param passkey
|
* @param passkey the passkey to set, might be mandatory to be a 6 digit number.
|
||||||
*/
|
*/
|
||||||
void ble_service_set_pairing_passkey(uint32_t passkey);
|
void ble_service_set_pairing_passkey(uint32_t passkey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the passkey needed for pairing which was previously set by the @ref ble_service_set_pairing_passkey
|
||||||
|
* function.
|
||||||
|
*
|
||||||
|
* @return uint32_t the number representing the passkey.
|
||||||
|
*/
|
||||||
|
uint32_t ble_service_get_active_pairing_passkey(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Asks to update the current connection parameters
|
* @brief Asks to update the current connection parameters
|
||||||
* /!\ A connection should be already active before calling this function.
|
* /!\ A connection should be already active before calling this function.
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "ble_service.h"
|
#include "ble_service.h"
|
||||||
#include "wm_mem.h"
|
#include "wm_mem.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
/* Internal enum definition */
|
/* Internal enum definition */
|
||||||
typedef enum gadget_bridge_parser_fsm
|
typedef enum gadget_bridge_parser_fsm
|
||||||
@ -30,6 +31,9 @@ typedef enum gadget_bridge_parser_fsm
|
|||||||
GADGET_BRIDGE_PARSER_FSM_FOUND_TITLE,
|
GADGET_BRIDGE_PARSER_FSM_FOUND_TITLE,
|
||||||
GADGET_BRIDGE_PARSER_FSM_PARSING_TITLE_CONTENT,
|
GADGET_BRIDGE_PARSER_FSM_PARSING_TITLE_CONTENT,
|
||||||
|
|
||||||
|
GADGET_BRIDGE_PARSER_FSM_FOUND_SUBJECT,
|
||||||
|
GADGET_BRIDGE_PARSER_FSM_PARSING_SUBJECT_BODY_CONTENT,
|
||||||
|
|
||||||
GADGET_BRIDGE_PARSER_FSM_FOUND_ID_SRC,
|
GADGET_BRIDGE_PARSER_FSM_FOUND_ID_SRC,
|
||||||
GADGET_BRIDGE_PARSER_FSM_FOUND_SRC_BODY,
|
GADGET_BRIDGE_PARSER_FSM_FOUND_SRC_BODY,
|
||||||
GADGET_BRIDGE_PARSER_FSM_PARSING_BODY_CONTENT,
|
GADGET_BRIDGE_PARSER_FSM_PARSING_BODY_CONTENT,
|
||||||
@ -243,7 +247,7 @@ static bool _parser_extract_bool(char *start, char *end, bool *data);
|
|||||||
gadget_bridge_parser_code_e gadget_bridge_parser_run(void)
|
gadget_bridge_parser_code_e gadget_bridge_parser_run(void)
|
||||||
{
|
{
|
||||||
if(!_gadget_bridge_internals.new_data) return GADGET_BRIDGE_PARSER_CODE_OK;
|
if(!_gadget_bridge_internals.new_data) return GADGET_BRIDGE_PARSER_CODE_OK;
|
||||||
char *start = NULL, *end = NULL;
|
char *start = NULL, *end = NULL, *end2 = NULL; // end2 is used when more than one next tag is possible
|
||||||
bool free_some_space = false;
|
bool free_some_space = false;
|
||||||
gadget_bridge_parser_code_e to_return = GADGET_BRIDGE_PARSER_CODE_PARSING;
|
gadget_bridge_parser_code_e to_return = GADGET_BRIDGE_PARSER_CODE_PARSING;
|
||||||
|
|
||||||
@ -426,10 +430,20 @@ gadget_bridge_parser_code_e gadget_bridge_parser_run(void)
|
|||||||
else to_return = GADGET_BRIDGE_PARSER_CODE_OK;
|
else to_return = GADGET_BRIDGE_PARSER_CODE_OK;
|
||||||
break;
|
break;
|
||||||
case GADGET_BRIDGE_PARSER_FSM_FOUND_ID_SRC:
|
case GADGET_BRIDGE_PARSER_FSM_FOUND_ID_SRC:
|
||||||
if((start = strstr(_gadget_bridge_internals.buffer, "src:"))
|
if((start = strstr(_gadget_bridge_internals.buffer, "src:")) &&
|
||||||
&& (end = strstr(_gadget_bridge_internals.buffer, ",title")))
|
((end = strstr(_gadget_bridge_internals.buffer, ",title")) || (end2 = strstr(_gadget_bridge_internals.buffer, ",subject"))))
|
||||||
{
|
{
|
||||||
//printf("###Found TITLE\n");
|
if((end && !end2) || (end != NULL && end < end2))
|
||||||
|
{
|
||||||
|
//printf("###Found TITLE\n");
|
||||||
|
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_FOUND_TITLE;
|
||||||
|
}
|
||||||
|
else if((!end && end2) || (end2 != NULL && end2 < end))
|
||||||
|
{
|
||||||
|
//printf("###Found SUBJECT\n");
|
||||||
|
end = end2;
|
||||||
|
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_FOUND_SUBJECT;
|
||||||
|
}
|
||||||
|
|
||||||
_parser_extract_src(start + 5, end - 1);
|
_parser_extract_src(start + 5, end - 1);
|
||||||
|
|
||||||
@ -438,7 +452,6 @@ gadget_bridge_parser_code_e gadget_bridge_parser_run(void)
|
|||||||
_parser_free_buffer(
|
_parser_free_buffer(
|
||||||
end -_gadget_bridge_internals.buffer
|
end -_gadget_bridge_internals.buffer
|
||||||
);
|
);
|
||||||
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_FOUND_TITLE;
|
|
||||||
}
|
}
|
||||||
else if((start = strstr(_gadget_bridge_internals.buffer, "GB(")))
|
else if((start = strstr(_gadget_bridge_internals.buffer, "GB(")))
|
||||||
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_NEW_MESSAGE;
|
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_NEW_MESSAGE;
|
||||||
@ -485,7 +498,7 @@ gadget_bridge_parser_code_e gadget_bridge_parser_run(void)
|
|||||||
// Then we have a very long title, in this case we juste keep the max set up
|
// Then we have a very long title, in this case we juste keep the max set up
|
||||||
else if(!end && _gadget_bridge_internals.buffer_content_size >= GADGET_BRIDGE_PARSER_MAX_TITLE_SIZE)
|
else if(!end && _gadget_bridge_internals.buffer_content_size >= GADGET_BRIDGE_PARSER_MAX_TITLE_SIZE)
|
||||||
{
|
{
|
||||||
printf("###NOTIFICATION (MAX TITLE SIZE)\n");
|
//printf("###NOTIFICATION (MAX TITLE SIZE)\n");
|
||||||
|
|
||||||
_parser_extract_char_str(_gadget_bridge_internals.buffer, _gadget_bridge_internals.buffer + GADGET_BRIDGE_PARSER_MAX_TITLE_SIZE, &_gadget_bridge_internals.event_data.notification.title);
|
_parser_extract_char_str(_gadget_bridge_internals.buffer, _gadget_bridge_internals.buffer + GADGET_BRIDGE_PARSER_MAX_TITLE_SIZE, &_gadget_bridge_internals.event_data.notification.title);
|
||||||
|
|
||||||
@ -510,6 +523,10 @@ gadget_bridge_parser_code_e gadget_bridge_parser_run(void)
|
|||||||
_parser_free_buffer(
|
_parser_free_buffer(
|
||||||
start -_gadget_bridge_internals.buffer
|
start -_gadget_bridge_internals.buffer
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if(_gadget_bridge_internals.event_data.notification.notification_type == GADGET_BRIDGE_NOTIFICATION_TYPE_GADGET_BRIDGE)
|
||||||
|
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_PARSING_SUBJECT_BODY_CONTENT;
|
||||||
|
else
|
||||||
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_PARSING_BODY_CONTENT;
|
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_PARSING_BODY_CONTENT;
|
||||||
}
|
}
|
||||||
else if((start = strstr(_gadget_bridge_internals.buffer, "GB(")))
|
else if((start = strstr(_gadget_bridge_internals.buffer, "GB(")))
|
||||||
@ -574,6 +591,63 @@ gadget_bridge_parser_code_e gadget_bridge_parser_run(void)
|
|||||||
else to_return = GADGET_BRIDGE_PARSER_CODE_OK;
|
else to_return = GADGET_BRIDGE_PARSER_CODE_OK;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case GADGET_BRIDGE_PARSER_FSM_PARSING_SUBJECT_BODY_CONTENT:
|
||||||
|
{
|
||||||
|
end = strstr(_gadget_bridge_internals.buffer, ",sender");
|
||||||
|
if(end)
|
||||||
|
{
|
||||||
|
// We don't care about the sender nor the tel tag
|
||||||
|
//printf("###TEST NOTIFICATION Type done\n");
|
||||||
|
|
||||||
|
_parser_extract_char_str(_gadget_bridge_internals.buffer, end - 1, &_gadget_bridge_internals.event_data.notification.body);
|
||||||
|
|
||||||
|
// We remove the parsed part from the buffer
|
||||||
|
end += 7;
|
||||||
|
_parser_free_buffer(
|
||||||
|
end -_gadget_bridge_internals.buffer
|
||||||
|
);
|
||||||
|
|
||||||
|
// If a callback was registered, we call it and pass the data to it
|
||||||
|
if(_gadget_bridge_internals.parser_event_callback)
|
||||||
|
{
|
||||||
|
_gadget_bridge_internals.parser_event_callback(&_gadget_bridge_internals.event_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Free the allocated data
|
||||||
|
_free_event_data();
|
||||||
|
|
||||||
|
// The end of the road for this object
|
||||||
|
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_NEW_MESSAGE;
|
||||||
|
}
|
||||||
|
else if((start = strstr(_gadget_bridge_internals.buffer, "GB(")))
|
||||||
|
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_NEW_MESSAGE;
|
||||||
|
// Then we have a very long body, in this case we juste keep the max set up
|
||||||
|
else if(!end && _gadget_bridge_internals.buffer_content_size >= GADGET_BRIDGE_PARSER_MAX_BODY_SIZE)
|
||||||
|
{
|
||||||
|
//printf("###TEST NOTIFICATION (MAX BODY SIZE) Type done\n");
|
||||||
|
|
||||||
|
_parser_extract_char_str(_gadget_bridge_internals.buffer, _gadget_bridge_internals.buffer + GADGET_BRIDGE_PARSER_MAX_BODY_SIZE, &_gadget_bridge_internals.event_data.notification.body);
|
||||||
|
|
||||||
|
// We remove the parsed part from the buffer
|
||||||
|
_parser_free_buffer(
|
||||||
|
GADGET_BRIDGE_PARSER_MAX_BODY_SIZE + 1
|
||||||
|
);
|
||||||
|
|
||||||
|
// If a callback was registered, we call it and pass the data to it
|
||||||
|
if(_gadget_bridge_internals.parser_event_callback)
|
||||||
|
{
|
||||||
|
_gadget_bridge_internals.parser_event_callback(&_gadget_bridge_internals.event_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Free the allocated data
|
||||||
|
_free_event_data();
|
||||||
|
|
||||||
|
// The end of the road for this object
|
||||||
|
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_NEW_MESSAGE;
|
||||||
|
}
|
||||||
|
else to_return = GADGET_BRIDGE_PARSER_CODE_OK;
|
||||||
|
}
|
||||||
|
break;
|
||||||
/*case GADGET_BRIDGE_PARSER_FSM_FOUND_ID_BODY:
|
/*case GADGET_BRIDGE_PARSER_FSM_FOUND_ID_BODY:
|
||||||
if((start = strstr(_gadget_bridge_internals.buffer, "body:"))
|
if((start = strstr(_gadget_bridge_internals.buffer, "body:"))
|
||||||
&& (end = strstr(_gadget_bridge_internals.buffer, ",sender")))
|
&& (end = strstr(_gadget_bridge_internals.buffer, ",sender")))
|
||||||
@ -631,6 +705,24 @@ gadget_bridge_parser_code_e gadget_bridge_parser_run(void)
|
|||||||
|
|
||||||
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_NEW_MESSAGE;
|
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_NEW_MESSAGE;
|
||||||
break;*/
|
break;*/
|
||||||
|
case GADGET_BRIDGE_PARSER_FSM_FOUND_SUBJECT:
|
||||||
|
if((start = strstr(_gadget_bridge_internals.buffer, "subject:")))
|
||||||
|
{
|
||||||
|
//printf("###Parsing SUBJECT content\n");
|
||||||
|
|
||||||
|
// We remove the parsed part from the buffer
|
||||||
|
start += 9;
|
||||||
|
_parser_free_buffer(
|
||||||
|
start -_gadget_bridge_internals.buffer
|
||||||
|
);
|
||||||
|
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_PARSING_TITLE_CONTENT;
|
||||||
|
}
|
||||||
|
else if((start = strstr(_gadget_bridge_internals.buffer, "GB(")))
|
||||||
|
_gadget_bridge_internals.gadget_bridge_parser_fsm = GADGET_BRIDGE_PARSER_FSM_NEW_MESSAGE;
|
||||||
|
else if(_gadget_bridge_internals.buffer_content_size > GADGET_BRIDGE_PARSER_BUFFER_THRESHOLD)
|
||||||
|
free_some_space = true;
|
||||||
|
else to_return = GADGET_BRIDGE_PARSER_CODE_OK;
|
||||||
|
break;
|
||||||
case GADGET_BRIDGE_PARSER_FSM_FOUND_CALL:
|
case GADGET_BRIDGE_PARSER_FSM_FOUND_CALL:
|
||||||
if((start = strstr(_gadget_bridge_internals.buffer, "cmd:"))
|
if((start = strstr(_gadget_bridge_internals.buffer, "cmd:"))
|
||||||
&& (end = strstr(_gadget_bridge_internals.buffer, ",name")))
|
&& (end = strstr(_gadget_bridge_internals.buffer, ",name")))
|
||||||
@ -1151,6 +1243,7 @@ const char *gadget_bridge_notification_type_2_str(gadget_bridge_notification_typ
|
|||||||
{
|
{
|
||||||
CASE_RETURN_STR(GADGET_BRIDGE_NOTIFICATION_TYPE_SMS)
|
CASE_RETURN_STR(GADGET_BRIDGE_NOTIFICATION_TYPE_SMS)
|
||||||
CASE_RETURN_STR(GADGET_BRIDGE_NOTIFICATION_TYPE_EMAIL)
|
CASE_RETURN_STR(GADGET_BRIDGE_NOTIFICATION_TYPE_EMAIL)
|
||||||
|
CASE_RETURN_STR(GADGET_BRIDGE_NOTIFICATION_TYPE_GADGET_BRIDGE)
|
||||||
CASE_RETURN_STR(GADGET_BRIDGE_NOTIFICATION_TYPE_UNKNOWN)
|
CASE_RETURN_STR(GADGET_BRIDGE_NOTIFICATION_TYPE_UNKNOWN)
|
||||||
default:
|
default:
|
||||||
return "Unknown notification type";
|
return "Unknown notification type";
|
||||||
@ -1326,6 +1419,8 @@ static void _parser_extract_src(char *start, char *end)
|
|||||||
_gadget_bridge_internals.event_data.notification.notification_type = GADGET_BRIDGE_NOTIFICATION_TYPE_SMS;
|
_gadget_bridge_internals.event_data.notification.notification_type = GADGET_BRIDGE_NOTIFICATION_TYPE_SMS;
|
||||||
else if(strcmp(start, "E-mail") == 0)
|
else if(strcmp(start, "E-mail") == 0)
|
||||||
_gadget_bridge_internals.event_data.notification.notification_type = GADGET_BRIDGE_NOTIFICATION_TYPE_EMAIL;
|
_gadget_bridge_internals.event_data.notification.notification_type = GADGET_BRIDGE_NOTIFICATION_TYPE_EMAIL;
|
||||||
|
else if(strcmp(start, "Gadgetbridge") == 0)
|
||||||
|
_gadget_bridge_internals.event_data.notification.notification_type = GADGET_BRIDGE_NOTIFICATION_TYPE_GADGET_BRIDGE;
|
||||||
else
|
else
|
||||||
_gadget_bridge_internals.event_data.notification.notification_type = GADGET_BRIDGE_NOTIFICATION_TYPE_UNKNOWN;
|
_gadget_bridge_internals.event_data.notification.notification_type = GADGET_BRIDGE_NOTIFICATION_TYPE_UNKNOWN;
|
||||||
|
|
||||||
|
@ -129,6 +129,7 @@ typedef enum gadget_bridge_notification_type
|
|||||||
{
|
{
|
||||||
GADGET_BRIDGE_NOTIFICATION_TYPE_SMS = 0,
|
GADGET_BRIDGE_NOTIFICATION_TYPE_SMS = 0,
|
||||||
GADGET_BRIDGE_NOTIFICATION_TYPE_EMAIL,
|
GADGET_BRIDGE_NOTIFICATION_TYPE_EMAIL,
|
||||||
|
GADGET_BRIDGE_NOTIFICATION_TYPE_GADGET_BRIDGE,
|
||||||
GADGET_BRIDGE_NOTIFICATION_TYPE_UNKNOWN,
|
GADGET_BRIDGE_NOTIFICATION_TYPE_UNKNOWN,
|
||||||
} gadget_bridge_notification_type_e;
|
} gadget_bridge_notification_type_e;
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include "lwip/netif.h"
|
#include "lwip/netif.h"
|
||||||
#include "app_common.h"
|
#include "app_common.h"
|
||||||
|
#include "app_utils.h"
|
||||||
#include "nano_shell_interface.h"
|
#include "nano_shell_interface.h"
|
||||||
#include "wm_gpio_afsel.h"
|
#include "wm_gpio_afsel.h"
|
||||||
#include "wm_cpu.h"
|
#include "wm_cpu.h"
|
||||||
@ -182,7 +183,7 @@ static void nus_data_rx_cb(const uint8_t *data, uint16_t length)
|
|||||||
gadget_bridge_parser_code_e code;
|
gadget_bridge_parser_code_e code;
|
||||||
while((code = gadget_bridge_parser_run()) == GADGET_BRIDGE_PARSER_CODE_PARSING);
|
while((code = gadget_bridge_parser_run()) == GADGET_BRIDGE_PARSER_CODE_PARSING);
|
||||||
shell_printf("Gadget bridge parser code : %s"NEW_LINE, gadget_bridge_parser_code_2_str(code));
|
shell_printf("Gadget bridge parser code : %s"NEW_LINE, gadget_bridge_parser_code_2_str(code));
|
||||||
tls_bt_ctrl_sleep(false);
|
//ble_modem_wake();
|
||||||
//shell_puts("#"NEW_LINE);
|
//shell_puts("#"NEW_LINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -655,13 +656,11 @@ int _rtc(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|||||||
void tls_bt_controller_sleep_enter_cb(uint32_t sleep_duration_ms)
|
void tls_bt_controller_sleep_enter_cb(uint32_t sleep_duration_ms)
|
||||||
{
|
{
|
||||||
//shell_printf("BT CTRL sleep for %u"NEW_LINE, sleep_duration_ms);
|
//shell_printf("BT CTRL sleep for %u"NEW_LINE, sleep_duration_ms);
|
||||||
//tls_bt_ctrl_wakeup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tls_bt_controller_sleep_exit_cb(void)
|
void tls_bt_controller_sleep_exit_cb(void)
|
||||||
{
|
{
|
||||||
//shell_printf("BT CTRL wakeup"NEW_LINE);
|
//shell_printf("BT CTRL wakeup"NEW_LINE);
|
||||||
//tls_bt_ctrl_sleep(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
||||||
@ -707,6 +706,17 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|||||||
{
|
{
|
||||||
shell_printf("MTU exchange request : %d"NEW_LINE, ble_service_request_mtu_exchange());
|
shell_printf("MTU exchange request : %d"NEW_LINE, ble_service_request_mtu_exchange());
|
||||||
}
|
}
|
||||||
|
else if(strcmp(argv[1], "mac_addr") == 0)
|
||||||
|
{
|
||||||
|
const uint8_t *mac = ble_service_get_device_mac_address();
|
||||||
|
shell_printf("The device MAC address is : %02X:%02X:%02X:%02X:%02X:%02X"NEW_LINE,
|
||||||
|
mac[5],
|
||||||
|
mac[4],
|
||||||
|
mac[3],
|
||||||
|
mac[2],
|
||||||
|
mac[1],
|
||||||
|
mac[0]);
|
||||||
|
}
|
||||||
else if(strcmp(argv[1], "send_ble_notif") == 0 && argc > 2)
|
else if(strcmp(argv[1], "send_ble_notif") == 0 && argc > 2)
|
||||||
{
|
{
|
||||||
char cmd[200] = "";
|
char cmd[200] = "";
|
||||||
@ -853,7 +863,8 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|||||||
if(argc == 3)
|
if(argc == 3)
|
||||||
{
|
{
|
||||||
bool sleeping = strtoul(argv[2], NULL, 10);
|
bool sleeping = strtoul(argv[2], NULL, 10);
|
||||||
shell_printf("BLE modem set to sleeping : %d"NEW_LINE, tls_bt_ctrl_sleep(sleeping));
|
bool status = sleeping ? ble_modem_sleep() : ble_modem_wake();
|
||||||
|
shell_printf("BLE modem set to sleeping : %d"NEW_LINE, status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(strcmp(argv[1], "ble_modem_wake") == 0)
|
else if(strcmp(argv[1], "ble_modem_wake") == 0)
|
||||||
@ -880,13 +891,20 @@ int _bluetooth(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
shell_printf("List of bluetooth actions :"NEW_LINE"enable 0|1 0|1"NEW_LINE"disable"NEW_LINE"start_demo"NEW_LINE"stop_demo"NEW_LINE"send_ble_notif toast \"msg\"|bat \"%%\"|findPhone|music|notify"NEW_LINE"mtu_exch"NEW_LINE
|
shell_printf("List of bluetooth actions :"NEW_LINE
|
||||||
|
"enable 0|1 0|1"NEW_LINE
|
||||||
|
"disable"NEW_LINE
|
||||||
|
"start_demo"NEW_LINE
|
||||||
|
"stop_demo"NEW_LINE
|
||||||
|
"send_ble_notif toast \"msg\"|bat \"%%\"|findPhone|music|notify"NEW_LINE
|
||||||
|
"mtu_exch"NEW_LINE
|
||||||
"up_conn_param itvl_min itvl_max latency supervision_timeout min_ce_len max_ce_len"NEW_LINE
|
"up_conn_param itvl_min itvl_max latency supervision_timeout min_ce_len max_ce_len"NEW_LINE
|
||||||
"ble_tx_power 1|2|3|4|5"NEW_LINE
|
"ble_tx_power 1|2|3|4|5"NEW_LINE
|
||||||
"bt_tx_power 1|2|3|4|5"NEW_LINE
|
"bt_tx_power 1|2|3|4|5"NEW_LINE
|
||||||
"ble_modem_sleep 1|0"NEW_LINE
|
"ble_modem_sleep 1|0"NEW_LINE
|
||||||
"ble_modem_wake"NEW_LINE
|
"ble_modem_wake"NEW_LINE
|
||||||
"ble_modem_mode bt|bt_wifi"NEW_LINE);
|
"ble_modem_mode bt|bt_wifi"NEW_LINE
|
||||||
|
"mac_addr"NEW_LINE);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -925,6 +943,24 @@ int _exit_remote_access(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int _utils(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
||||||
|
{
|
||||||
|
if(argc > 1)
|
||||||
|
{
|
||||||
|
if(strcmp(argv[1], "random") == 0)
|
||||||
|
{
|
||||||
|
uint32_t random = random_gen_6_digit();
|
||||||
|
shell_printf("Random 6 digit number is : %u"NEW_LINE, random);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shell_printf("List of %s actions :"NEW_LINE
|
||||||
|
"random"NEW_LINE, argv[0]);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
NANO_SHELL_ADD_CMD(bus,
|
NANO_SHELL_ADD_CMD(bus,
|
||||||
_bus,
|
_bus,
|
||||||
"Command to interact with the SPI bus",
|
"Command to interact with the SPI bus",
|
||||||
@ -977,3 +1013,7 @@ NANO_SHELL_ADD_CMD(exit,
|
|||||||
_exit_remote_access,
|
_exit_remote_access,
|
||||||
"Disconnect from Nano-Shell remote access",
|
"Disconnect from Nano-Shell remote access",
|
||||||
" Use this command to disconnect from Nano-Shell remote access"NEW_LINE);
|
" Use this command to disconnect from Nano-Shell remote access"NEW_LINE);
|
||||||
|
NANO_SHELL_ADD_CMD(utils,
|
||||||
|
_utils,
|
||||||
|
"Command used to test various utils functions",
|
||||||
|
" Use this command to try various utility functions out lilke random and more"NEW_LINE);
|
||||||
|
Loading…
Reference in New Issue
Block a user