123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- #include <string.h>
- #include <stdint.h>
- #include "app_error.h"
- #include "app_scheduler.h"
- #include "ble_serialization.h"
- #include "ser_config.h"
- #include "ser_hal_transport.h"
- #include "ser_conn_event_encoder.h"
- #include "ser_conn_handlers.h"
- #include "nrf_log.h"
- #ifdef BLE_STACK_SUPPORT_REQD
- #include "ble_conn.h"
- #endif
- #ifdef ANT_STACK_SUPPORT_REQD
- #include "ant_event.h"
- #endif
- #ifdef BLE_STACK_SUPPORT_REQD
- extern bool m_reset_ongoing;
- void ser_conn_ble_event_encoder(void * p_event_data, uint16_t event_size)
- {
- if (m_reset_ongoing)
- {
- NRF_LOG_INFO("Dropping BLE event (during reset).");
- return;
- }
- if (NULL == p_event_data)
- {
- APP_ERROR_CHECK(NRF_ERROR_NULL);
- }
- UNUSED_PARAMETER(event_size);
- uint32_t err_code = NRF_SUCCESS;
- uint8_t * p_tx_buf = NULL;
- uint32_t tx_buf_len = 0;
- ble_evt_t * p_ble_evt = (ble_evt_t *)p_event_data;
-
- 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 (err_code == NRF_ERROR_NO_MEM);
- APP_ERROR_CHECK(err_code);
-
- p_tx_buf[SER_PKT_TYPE_POS] = SER_PKT_TYPE_EVT;
- tx_buf_len -= SER_PKT_TYPE_SIZE;
-
- err_code = ble_event_enc(p_ble_evt, 0, &p_tx_buf[SER_PKT_OP_CODE_POS], &tx_buf_len);
- if (NRF_ERROR_NOT_SUPPORTED != err_code)
- {
- APP_ERROR_CHECK(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);
- APP_ERROR_CHECK(err_code);
-
- if (!m_reset_ongoing)
- {
- app_sched_pause();
- }
- }
- else
- {
-
- err_code = ser_hal_transport_tx_pkt_free(p_tx_buf);
- APP_ERROR_CHECK(err_code);
- APP_ERROR_CHECK(SER_WARNING_CODE);
- }
- }
- #endif
- #ifdef ANT_STACK_SUPPORT_REQD
- void ser_conn_ant_event_encoder(void * p_event_data, uint16_t event_size)
- {
- if (NULL == p_event_data)
- {
- APP_ERROR_CHECK(NRF_ERROR_NULL);
- }
- UNUSED_PARAMETER(event_size);
- uint32_t err_code = NRF_SUCCESS;
- uint8_t * p_tx_buf = NULL;
- uint32_t tx_buf_len = 0;
- ant_evt_t * p_ant_evt = (ant_evt_t *)p_event_data;
-
- do
- {
- err_code = ser_hal_transport_tx_pkt_alloc(&p_tx_buf, (uint16_t *)&tx_buf_len);
- }
- while (err_code == NRF_ERROR_NO_MEM);
- APP_ERROR_CHECK(err_code);
-
- p_tx_buf[SER_PKT_TYPE_POS] = SER_PKT_TYPE_ANT_EVT;
- tx_buf_len -= SER_PKT_TYPE_SIZE;
-
- err_code = ant_event_enc(p_ant_evt, 0, &p_tx_buf[SER_PKT_OP_CODE_POS], &tx_buf_len);
- if (NRF_ERROR_NOT_SUPPORTED != err_code)
- {
- APP_ERROR_CHECK(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);
- APP_ERROR_CHECK(err_code);
-
- app_sched_pause();
- }
- else
- {
-
- err_code = ser_hal_transport_tx_pkt_free(p_tx_buf);
- APP_ERROR_CHECK(err_code);
- APP_ERROR_CHECK(SER_WARNING_CODE);
- }
- }
- #endif
|