BLE Nano Code.Tested with Integrated mDot code
Dependencies: BLE_API mbed nRF51822
Fork of eco_Labs_ble_Client by
Diff: ble_msg_handler.cpp
- Revision:
- 10:09d1a403eb14
- Child:
- 11:b8e687d97537
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ble_msg_handler.cpp Tue Oct 04 11:05:45 2016 +0000 @@ -0,0 +1,115 @@ +/** + ****************************************************************************** + * @file ble_msg_handler.cpp + * @author Happiesstminds Firmware Team + * @version v1.0 + * @date 4-Oct-2016 + * @brief + * + ****************************************************************************** + * @attention + * + * + ****************************************************************************** + */ + +/******************************************************************************/ +/* Include Files*/ +/******************************************************************************/ +#include <string.h> +#include "mbed.h" +#include "BLE.h" +#include "ble_types.h" +#include "UARTService.h" +#include "ble_msg_handler.h" + +/******************************************************************************/ +/* extern function definations */ +/******************************************************************************/ +extern void ble_data_rx_cb_register(ble_data_ready_callback_t data_rx_callback); +extern eStatus_t ble_send_data(uint8_t *tx_buf, uint8_t length); +extern void ble_init(void); + +/******************************************************************************/ +/* Global Variables */ +/******************************************************************************/ + +/******************************************************************************/ +/* Static Variable Declarations */ +/******************************************************************************/ + +/******************************************************************************/ +/* Static Functions */ +/******************************************************************************/ + +/** + * @brief BLE_UART data Receive Callback + * @param + * @retval + */ +static void ble_rx_Data_Callback(uint8_t *rx_data, uint8_t len) +{ + uint8_t send_buf[16]; + + send_buf[0] = BLE_SOF_CMD; + send_buf[1] = BLE_REC_DATA_CMD; + memcpy(&send_buf[2], rx_data, len); + send_buf[len + 2] = BLE_EOT_CMD; + + // TODO Send the data to SPI + // spi_send(send_buf, len + 3); +} + + +/** + * @brief SPI data Receive Callback + * @param + * @retval + */ +static void spi_rx_Data_Callback(uint8_t *rx_data, uint8_t len) +{ + uint8_t tmp_buf[16]; + + if (rx_data[0] == 0xFF) { + // TODO: DUMMY Read, send dummy byte back + } else if (rx_data[0] == BLE_SOF_CMD) { + switch (rx_data[1]) { + case BLE_INIT_CMD: + // TODO: Get the BLE Device name from rx_data and pass it to ble_init + ble_init(); + break; + + case BLE_START_ADV_CMD: + // TODO: As of now Advertising is done from the ble_init + break; + + case BLE_SEND_DATA_CMD: + memcpy(tmp_buf, &rx_data[3], rx_data[2]); + ble_send_data(tmp_buf, rx_data[2]); + break; + + default : + break; + + } + } else { + // Invalid Packet received, ignore as of now + } +} +/******************************************************************************/ +/* Global Functions */ +/******************************************************************************/ +/** + * @brief Data Handler Init, register for the BLE & SPI callbacks + * @param + * @retval + */ +void ble_data_handler_init(void) +{ + ble_data_rx_cb_register(ble_rx_Data_Callback); + //spi_data_rx_cb_register(spi_rx_Data_Callback); +} + +/******************************************************************************/ +/* END OF FILE */ +/******************************************************************************/