This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to run proxy and Nus at the same time

Hi all, 

when I insert ble_nus into mesh_gatt . I realized there are two pulse functions with the same function: 

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void ble_nus_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
{
if ((p_context == NULL) || (p_ble_evt == NULL))
{
return;
}
ble_nus_t * p_nus = (ble_nus_t *)p_context;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
on_connect(p_nus, p_ble_evt);
break;
case BLE_GATTS_EVT_WRITE:
on_write(p_nus, p_ble_evt);
break;
case BLE_GATTS_EVT_HVN_TX_COMPLETE:
on_hvx_tx_complete(p_nus, p_ble_evt);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

and 

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void mesh_gatt_on_ble_evt(const ble_evt_t * p_ble_evt, void * p_context)
{
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
connect_evt_handle(p_ble_evt);
break;
case BLE_GAP_EVT_DISCONNECTED:
disconnect_evt_handle(p_ble_evt);
break;
case BLE_GATTS_EVT_WRITE:
write_evt_handle(p_ble_evt);
break;
case BLE_GATTS_EVT_HVN_TX_COMPLETE:
tx_complete_handle(p_ble_evt->evt.gatts_evt.conn_handle);
break;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

if they let them coexist , when I use nrf_connect connect and use mesh_app connect , It jump to 2 function , and I only want , if I connect to nus , it jump to ble_nus_on_ble_evt , If I connect to proxy , It jump to mesh_gatt_on_ble_evt . Is this feasible? Can you give me advice ? Thank !!!

Parents
  • In the regular ble examples there is a dispatch function that calls all *_ble_evt functions for the project. I suggest to take the same approach. All the individual handlers ( on_disconnect/ disconnect_evt_handle etc.) should check if the message is for them, and if not, ignore it. Therefore, writing a dispatch function and calling both should work. 

Reply
  • In the regular ble examples there is a dispatch function that calls all *_ble_evt functions for the project. I suggest to take the same approach. All the individual handlers ( on_disconnect/ disconnect_evt_handle etc.) should check if the message is for them, and if not, ignore it. Therefore, writing a dispatch function and calling both should work. 

Children
  • In BLE_GAP_EVT_CONNECTED , how to know the connection of nus or proxy ? 

  • At the point of the BLE_GAP_EVT_CONNECTED, there is no distinction yet. The differences are only on events like BLE_GATTS_EVT_WRITE and BLE_GATTS_EVT_HVN_TX_COMPLETE. It's the same connection, but one reads/writes to different characteristics. Ones accessing a characteristic, one compares the handle in the p_ble_evt with the handle of the characteristic of the NUS or Proxy to determine if it is being addressed.

  • Can you give me an example? Thank !!!
  • I have this example, which I am still working on. It's not "clean" as I cann the nus event handler from the mesh gatt event handler in stead of making a dispatcher. But it's a part of a project I've been working on myself.

    At least this code gets into the nus data handler with the data I sent to it. That's as far as I have tested this code.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    void mesh_gatt_on_ble_evt(const ble_evt_t * p_ble_evt, void * p_context)
    {
    /// we need to put in this NUS this somewhere... this not not neat
    // to do it here... but until I find a better structure to support this
    // within the mesh sdk.
    ble_nus_on_ble_evt(p_ble_evt, &g_nus); // curious, did the parameters swap on this SDK version?
    ///!!!
    switch (p_ble_evt->header.evt_id)
    {
    case BLE_GAP_EVT_CONNECTED:
    // added for nus support
    //
    connect_evt_handle(p_ble_evt);
    break;
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Thank for help !!!

    This my code modified : 

    Fullscreen
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    But it still error . If I run NUS service , it jump mesh handle and error ?

    NUS part will run correct if I only use :

    case BLE_GATTS_EVT_WRITE:
    on_write(p_nus, p_ble_evt);
    // write_evt_handle(p_ble_evt);
    break;

    case BLE_GATTS_EVT_HVN_TX_COMPLETE:
    on_hvx_tx_complete(p_nus, p_ble_evt);
    // tx_complete_handle(p_ble_evt->evt.gatts_evt.conn_handle);
    break;

    and error if use : 

    case BLE_GATTS_EVT_WRITE:
    on_write(p_nus, p_ble_evt);
    write_evt_handle(p_ble_evt);
    break;

    case BLE_GATTS_EVT_HVN_TX_COMPLETE:
    on_hvx_tx_complete(p_nus, p_ble_evt);
    tx_complete_handle(p_ble_evt->evt.gatts_evt.conn_handle);
    break;

    can you help me , I really need this ! Thank very much !!!