123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- #include <stdint.h>
- #include <string.h>
- #include "nordic_common.h"
- #include "app_error.h"
- #include "ble_serialization.h"
- #include "ser_config.h"
- #include "conn_mw.h"
- #include "ser_hal_transport.h"
- #include "ser_conn_cmd_decoder.h"
- #include "ser_conn_handlers.h"
- #include "nrf_log_ctrl.h"
- #define NRF_LOG_MODULE_NAME ser_conn_dec
- #include "nrf_log.h"
- NRF_LOG_MODULE_REGISTER();
- uint32_t ser_conn_command_process(uint8_t * p_command, uint16_t command_len)
- {
- SER_ASSERT_NOT_NULL(p_command);
- SER_ASSERT_LENGTH_LEQ(SER_OP_CODE_SIZE, command_len);
- uint32_t err_code = NRF_SUCCESS;
- uint8_t * p_tx_buf = NULL;
- uint32_t tx_buf_len = 0;
- uint8_t opcode = p_command[SER_CMD_OP_CODE_POS];
- uint32_t index = 0;
-
- NRF_LOG_INFO("Command process start");
- do
- {
- err_code = ser_hal_transport_tx_pkt_alloc(&p_tx_buf, (uint16_t *)&tx_buf_len);
- if (err_code == NRF_ERROR_NO_MEM)
- {
- ser_conn_on_no_mem_handler();
- }
- }
- while (NRF_ERROR_NO_MEM == err_code);
- NRF_LOG_INFO("Tx buffer allocated");
- if (NRF_SUCCESS == err_code)
- {
-
- p_tx_buf[SER_PKT_TYPE_POS] = SER_PKT_TYPE_RESP;
- tx_buf_len -= SER_PKT_TYPE_SIZE;
-
- err_code = conn_mw_handler
- (p_command, command_len, &p_tx_buf[SER_PKT_OP_CODE_POS], &tx_buf_len);
-
- if (NRF_ERROR_NOT_SUPPORTED == err_code)
- {
- NRF_LOG_ERROR("Command not supported opcode:%d", p_tx_buf[SER_PKT_OP_CODE_POS]);
- APP_ERROR_CHECK(SER_WARNING_CODE);
- err_code = op_status_enc
- (opcode, NRF_ERROR_NOT_SUPPORTED,
- &p_tx_buf[SER_PKT_OP_CODE_POS], &tx_buf_len, &index);
- if (NRF_SUCCESS == err_code)
- {
- tx_buf_len += SER_PKT_TYPE_SIZE;
- err_code = ser_hal_transport_tx_pkt_send(p_tx_buf, (uint16_t)tx_buf_len);
-
- if (NRF_SUCCESS != err_code)
- {
- err_code = NRF_ERROR_INTERNAL;
- }
- }
- else
- {
- err_code = NRF_ERROR_INTERNAL;
- }
- }
- else if (NRF_SUCCESS == err_code)
- {
- tx_buf_len += SER_PKT_TYPE_SIZE;
- err_code = ser_hal_transport_tx_pkt_send(p_tx_buf, (uint16_t)tx_buf_len);
-
- if (NRF_SUCCESS != err_code)
- {
- err_code = NRF_ERROR_INTERNAL;
- }
- }
- else
- {
- NRF_LOG_ERROR("Internal error during command decoding.");
- err_code = NRF_ERROR_INTERNAL;
- }
- }
- else
- {
- err_code = NRF_ERROR_INTERNAL;
- }
- return err_code;
- }
|