mgmt: mcumgr: Add event ID index callback function
Adds a function which gets the callback ID index of a given event ID. Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This commit is contained in:
parent
a9a6df9b50
commit
6c541e1af0
|
@ -227,6 +227,15 @@ struct mgmt_evt_op_cmd_arg {
|
|||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Get event ID index from event.
|
||||
*
|
||||
* @param event Event to get ID index from.
|
||||
*
|
||||
* @return Event index.
|
||||
*/
|
||||
uint8_t mgmt_evt_get_index(uint32_t event);
|
||||
|
||||
/**
|
||||
* @brief This function is called to notify registered callbacks about mcumgr notifications/events.
|
||||
*
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <zephyr/sys/slist.h>
|
||||
#include <zephyr/sys/byteorder.h>
|
||||
#include <zephyr/device.h>
|
||||
|
@ -167,6 +168,28 @@ enum mgmt_cb_return mgmt_callback_notify(uint32_t event, void *data, size_t data
|
|||
|
||||
return return_status;
|
||||
}
|
||||
|
||||
uint8_t mgmt_evt_get_index(uint32_t event)
|
||||
{
|
||||
uint8_t index = 0;
|
||||
|
||||
event &= MGMT_EVT_OP_ID_ALL;
|
||||
__ASSERT((event != 0), "Event cannot be 0.");
|
||||
|
||||
while (index < 16) {
|
||||
if (event & 0x1) {
|
||||
break;
|
||||
}
|
||||
|
||||
++index;
|
||||
event = event >> 1;
|
||||
}
|
||||
|
||||
event = event >> 1;
|
||||
__ASSERT((event == 0), "Event cannot contain multiple values.");
|
||||
|
||||
return index;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Processes all registered MCUmgr handlers at start up and registers them */
|
||||
|
|
Loading…
Reference in a new issue