123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- #include <stddef.h>
- #include "ble_serialization.h"
- #include "nrf_soc.h"
- typedef uint32_t (*conn_mw_handler_t)(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len);
- typedef struct
- {
- uint8_t opcode;
- conn_mw_handler_t fp_handler;
- } conn_mw_item_t;
- #include "conn_mw_items.c"
- static const uint32_t conn_mw_item_len = sizeof (conn_mw_item) / sizeof (conn_mw_item[0]);
- static conn_mw_handler_t conn_mw_handler_get(uint8_t opcode)
- {
- conn_mw_handler_t fp_handler = NULL;
- uint32_t i;
- for (i = 0; i < conn_mw_item_len; i++)
- {
- if (opcode == conn_mw_item[i].opcode)
- {
- fp_handler = conn_mw_item[i].fp_handler;
- break;
- }
- }
- return fp_handler;
- }
- uint32_t conn_mw_handler(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- conn_mw_handler_t fp_handler;
- uint32_t err_code = NRF_SUCCESS;
- uint8_t opcode = p_rx_buf[SER_CMD_OP_CODE_POS];
- fp_handler = conn_mw_handler_get(opcode);
- if (fp_handler)
- {
- err_code = fp_handler(p_rx_buf, rx_buf_len, p_tx_buf, p_tx_buf_len);
- }
- else
- {
- err_code = NRF_ERROR_NOT_SUPPORTED;
- }
- return err_code;
- }
|