Skip to content
Snippets Groups Projects
Commit 80e77eeb authored by schneider's avatar schneider
Browse files

feat(ble): Trigger different events when pairing

parent ec228319
Branches
No related tags found
No related merge requests found
...@@ -44,6 +44,8 @@ ...@@ -44,6 +44,8 @@
#include "modules/log.h" #include "modules/log.h"
static bool active; static bool active;
static uint32_t ble_event;
/************************************************************************************************** /**************************************************************************************************
Macros Macros
**************************************************************************************************/ **************************************************************************************************/
...@@ -392,22 +394,48 @@ uint32_t epic_ble_get_compare_value(void) ...@@ -392,22 +394,48 @@ uint32_t epic_ble_get_compare_value(void)
return pair_confirm_value; return pair_confirm_value;
} }
void epic_ble_confirm_compare_value(void) void epic_ble_compare_response(bool confirmed)
{ {
if(!active) {
return;
}
if(pair_connId != DM_CONN_ID_NONE) { if(pair_connId != DM_CONN_ID_NONE) {
LOG_INFO("ble", "Confirming"); LOG_INFO("ble", "Value confirmed: %u", confirmed);
DmSecCompareRsp(pair_connId, TRUE); DmSecCompareRsp(pair_connId, confirmed);
} else { } else {
//TODO: error condition /* error condition */
}
}
static void trigger_event(uint32_t event)
{
bool enabled;
epic_interrupt_is_enabled(EPIC_INT_BLE, &enabled);
if(ble_event & enabled) {
LOG_WARN("ble", "Application missed event %lu", ble_event);
} }
ble_event = event;
api_interrupt_trigger(EPIC_INT_BLE);
}
uint32_t epic_ble_get_event(void)
{
uint32_t event = ble_event;
ble_event = 0;
return event;
} }
void bleHandleNumericComparison(dmSecCnfIndEvt_t *pCnfInd) static void bleHandleNumericComparison(dmSecCnfIndEvt_t *pCnfInd)
{ {
if(!active) {
return;
}
pair_connId = (dmConnId_t)pCnfInd->hdr.param; pair_connId = (dmConnId_t)pCnfInd->hdr.param;
pair_confirm_value = DmSecGetCompareValue(pCnfInd->confirm); pair_confirm_value = DmSecGetCompareValue(pCnfInd->confirm);
LOG_INFO("ble", "Confirm Value: %ld", pair_confirm_value); LOG_INFO("ble", "Confirm Value: %ld", pair_confirm_value);
api_interrupt_trigger(EPIC_INT_BLE_NUMERIC_COMPARISON); trigger_event(1);
} }
/*************************************************************************************************/ /*************************************************************************************************/
...@@ -503,6 +531,7 @@ static void bleProcMsg(bleMsg_t *pMsg) ...@@ -503,6 +531,7 @@ static void bleProcMsg(bleMsg_t *pMsg)
uiEvent = APP_UI_SEC_PAIR_CMPL; uiEvent = APP_UI_SEC_PAIR_CMPL;
/* After a successful pairing, bonding is disabled again. /* After a successful pairing, bonding is disabled again.
* We don't want that for now. */ * We don't want that for now. */
trigger_event(3);
AppSetBondable(TRUE); AppSetBondable(TRUE);
break; break;
...@@ -523,6 +552,7 @@ static void bleProcMsg(bleMsg_t *pMsg) ...@@ -523,6 +552,7 @@ static void bleProcMsg(bleMsg_t *pMsg)
} }
pair_connId = DM_CONN_ID_NONE; pair_connId = DM_CONN_ID_NONE;
uiEvent = APP_UI_SEC_PAIR_FAIL; uiEvent = APP_UI_SEC_PAIR_FAIL;
trigger_event(2);
break; break;
case DM_SEC_ENCRYPT_IND: case DM_SEC_ENCRYPT_IND:
......
...@@ -149,8 +149,9 @@ typedef _Bool bool; ...@@ -149,8 +149,9 @@ typedef _Bool bool;
#define API_CONFIG_SET_STRING 0x133 #define API_CONFIG_SET_STRING 0x133
#define API_BLE_GET_COMPARE_VALUE 0x140 #define API_BLE_GET_COMPARE_VALUE 0x140
#define API_BLE_CONFIRM_COMPARE_VALUE 0x141 #define API_BLE_COMPARE_RESPONSE 0x141
#define API_BLE_SET_BONDABLE 0x142 #define API_BLE_SET_BONDABLE 0x142
#define API_BLE_GET_EVENT 0x143
/* clang-format on */ /* clang-format on */
...@@ -217,7 +218,7 @@ API(API_INTERRUPT_IS_ENABLED, int epic_interrupt_is_enabled(api_int_id_t int_id, ...@@ -217,7 +218,7 @@ API(API_INTERRUPT_IS_ENABLED, int epic_interrupt_is_enabled(api_int_id_t int_id,
/** MAX86150 ECG and PPG sensor. See :c:func:`epic_isr_max86150`. */ /** MAX86150 ECG and PPG sensor. See :c:func:`epic_isr_max86150`. */
#define EPIC_INT_MAX86150 9 #define EPIC_INT_MAX86150 9
#define EPIC_INT_BLE_NUMERIC_COMPARISON 10 #define EPIC_INT_BLE 10
/* Number of defined interrupts. */ /* Number of defined interrupts. */
#define EPIC_INT_NUM 11 #define EPIC_INT_NUM 11
/* clang-format on */ /* clang-format on */
...@@ -2091,8 +2092,9 @@ API(API_CONFIG_GET_STRING, int epic_config_get_string(const char *key, char *buf ...@@ -2091,8 +2092,9 @@ API(API_CONFIG_GET_STRING, int epic_config_get_string(const char *key, char *buf
API(API_CONFIG_SET_STRING, int epic_config_set_string(const char *key, const char *value)); API(API_CONFIG_SET_STRING, int epic_config_set_string(const char *key, const char *value));
API(API_BLE_GET_COMPARE_VALUE, uint32_t epic_ble_get_compare_value(void)); API(API_BLE_GET_COMPARE_VALUE, uint32_t epic_ble_get_compare_value(void));
API(API_BLE_CONFIRM_COMPARE_VALUE, void epic_ble_confirm_compare_value(void)); API(API_BLE_COMPARE_RESPONSE, void epic_ble_compare_response(bool confirmed));
API_ISR(EPIC_INT_BLE_NUMERIC_COMPARISON, epic_isr_ble_numeric_comparison);
API(API_BLE_SET_BONDABLE, void epic_ble_set_bondable(bool bondable)); API(API_BLE_SET_BONDABLE, void epic_ble_set_bondable(bool bondable));
API(API_BLE_GET_EVENT, uint32_t epic_ble_get_event(void));
API_ISR(EPIC_INT_BLE, epic_isr_ble);
#endif /* _EPICARDIUM_H */ #endif /* _EPICARDIUM_H */
...@@ -197,4 +197,5 @@ Q(ble) ...@@ -197,4 +197,5 @@ Q(ble)
Q(get_compare_value) Q(get_compare_value)
Q(confirm_compare_value) Q(confirm_compare_value)
Q(set_bondable) Q(set_bondable)
Q(get_event)
...@@ -6,12 +6,13 @@ ...@@ -6,12 +6,13 @@
#include <stdint.h> #include <stdint.h>
static mp_obj_t mp_ble_confirm_compare_value(void) static mp_obj_t mp_ble_confirm_compare_value(mp_obj_t confirmed_obj)
{ {
epic_ble_confirm_compare_value(); bool confirmed = mp_obj_is_true(confirmed_obj);
epic_ble_compare_response(confirmed);
return mp_const_none; return mp_const_none;
} }
static MP_DEFINE_CONST_FUN_OBJ_0(ble_confirm_compare_value_obj, mp_ble_confirm_compare_value); static MP_DEFINE_CONST_FUN_OBJ_1(ble_confirm_compare_value_obj, mp_ble_confirm_compare_value);
static mp_obj_t mp_ble_get_compare_value(void) static mp_obj_t mp_ble_get_compare_value(void)
{ {
...@@ -19,6 +20,13 @@ static mp_obj_t mp_ble_get_compare_value(void) ...@@ -19,6 +20,13 @@ static mp_obj_t mp_ble_get_compare_value(void)
} }
static MP_DEFINE_CONST_FUN_OBJ_0(ble_get_compare_value_obj, mp_ble_get_compare_value); static MP_DEFINE_CONST_FUN_OBJ_0(ble_get_compare_value_obj, mp_ble_get_compare_value);
static mp_obj_t mp_ble_get_event(void)
{
return mp_obj_new_int(epic_ble_get_event());
}
static MP_DEFINE_CONST_FUN_OBJ_0(ble_get_event_obj, mp_ble_get_event);
static mp_obj_t mp_ble_set_bondable(mp_obj_t bondable_obj) static mp_obj_t mp_ble_set_bondable(mp_obj_t bondable_obj)
{ {
bool bondable = mp_obj_is_true(bondable_obj); bool bondable = mp_obj_is_true(bondable_obj);
...@@ -31,6 +39,7 @@ static const mp_rom_map_elem_t ble_module_globals_table[] = { ...@@ -31,6 +39,7 @@ static const mp_rom_map_elem_t ble_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sys_ble) }, { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sys_ble) },
{ MP_ROM_QSTR(MP_QSTR_confirm_compare_value), MP_ROM_PTR(&ble_confirm_compare_value_obj) }, { MP_ROM_QSTR(MP_QSTR_confirm_compare_value), MP_ROM_PTR(&ble_confirm_compare_value_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_compare_value), MP_ROM_PTR(&ble_get_compare_value_obj) }, { MP_ROM_QSTR(MP_QSTR_get_compare_value), MP_ROM_PTR(&ble_get_compare_value_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_event), MP_ROM_PTR(&ble_get_event_obj) },
{ MP_ROM_QSTR(MP_QSTR_set_bondable), MP_ROM_PTR(&ble_set_bondable_obj) }, { MP_ROM_QSTR(MP_QSTR_set_bondable), MP_ROM_PTR(&ble_set_bondable_obj) },
}; };
static MP_DEFINE_CONST_DICT(ble_module_globals, ble_module_globals_table); static MP_DEFINE_CONST_DICT(ble_module_globals, ble_module_globals_table);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment