-2

So I was studying some tutorial code for a BLE implementation, and I came across this syntax which I have never seen before.

&p_ble_evt->evt.gatts_evt.params.write;

It is the &foo;bar-&baz part i'm unsure of.

I tried 'googleing' the code part, then tried running it through https://cdecl.org/. But without getting an understanding for what this code does/is.

/**@brief Function for handling the Write event.
 *
 * @param[in]   p_midi_service   LED Button Service structure.
 * @param[in]   p_ble_evt        Event received from the BLE stack.
 */
static void on_write(ble_midi_service_t * p_midi_service, ble_evt_t const * p_ble_evt)
{
    ble_gatts_evt_write_t * p_evt_write = (ble_gatts_evt_write_t *) &p_ble_evt->evt.gatts_evt.params.write;

    if ((p_evt_write->handle == p_midi_service->data_io_char_handles.value_handle) &&
        (p_evt_write->len == 1) &&
        (p_midi_service->evt_handler != NULL))
    {
      // Handle what happens on a write event to the characteristic value
    }

    // Check if the Custom value CCCD is written to and that the value is the appropriate length, i.e 2 bytes.
    if ((p_evt_write->handle == p_midi_service->data_io_char_handles.cccd_handle)
        && (p_evt_write->len == 2)
       )
    {
        // CCCD written, call application event handler
        if (p_midi_service->evt_handler != NULL)
        {
            ble_midi_evt_t evt;

            if (ble_srv_is_notification_enabled(p_evt_write->data))
            {
                evt.evt_type = BLE_DATA_IO_EVT_NOTIFICATION_ENABLED;
            }
            else
            {
                evt.evt_type = BLE_DATA_IO_EVT_NOTIFICATION_DISABLED;
            }

            p_midi_service->evt_handler(p_midi_service, &evt);
        }
    }
}

So if some kind soul would help enlighten me that would be much appreciated.

Thank you.

Sorenp
  • 320
  • 2
  • 12
  • 4
    Doesn't speak very well for the tutorial if they haven't ever tried following it themselves to see that the code copypasted from it doesn't work, since it has that HTML escape fail… You need to replace `&` with `&` and `>` with `>`. – Arkku Dec 05 '19 at 14:55
  • Thanks @Arkku, my knowledge of HTML just increase ever so slightly :) – Sorenp Dec 05 '19 at 14:57

1 Answers1

5

Looks like xml/html escape sequences, should read:

&p_ble_evt->evt.gatts_evt.params.write;
Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
  • That makes a lot of sense - Thanks for the help Alan. I was super confused because I do know my basic C syntax, so I thought it was some very memory optimized code in a weird way I have never seen before. but the end line statements in the middle made it all crumble – Sorenp Dec 05 '19 at 14:51
  • @Sorenp: at least you didn't have to deal with [trigraphs](https://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C). – John Bode Dec 05 '19 at 15:54