
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:
- 11:b8e687d97537
- Parent:
- 10:09d1a403eb14
- Child:
- 12:c7a8a7fe76fd
diff -r 09d1a403eb14 -r b8e687d97537 ble_msg_handler.cpp --- a/ble_msg_handler.cpp Tue Oct 04 11:05:45 2016 +0000 +++ b/ble_msg_handler.cpp Thu Oct 06 09:42:38 2016 +0000 @@ -22,13 +22,15 @@ #include "ble_types.h" #include "UARTService.h" #include "ble_msg_handler.h" - +#include "spi_slave.h" /******************************************************************************/ /* extern function definations */ /******************************************************************************/ extern void ble_data_rx_cb_register(ble_data_ready_callback_t data_rx_callback); +extern void spi_data_rx_cb_register(spi_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); +extern void spi_slave_tx_data(uint8_t *tx_buf, uint8_t len); /******************************************************************************/ /* Global Variables */ @@ -41,7 +43,6 @@ /******************************************************************************/ /* Static Functions */ /******************************************************************************/ - /** * @brief BLE_UART data Receive Callback * @param @@ -57,7 +58,7 @@ send_buf[len + 2] = BLE_EOT_CMD; // TODO Send the data to SPI - // spi_send(send_buf, len + 3); + spi_slave_tx_data(send_buf, len + 3); } @@ -66,17 +67,17 @@ * @param * @retval */ -static void spi_rx_Data_Callback(uint8_t *rx_data, uint8_t len) +void spi_rx_Data_Callback(uint8_t *rx_data, uint8_t len) { - uint8_t tmp_buf[16]; - - if (rx_data[0] == 0xFF) { + 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]) { + } else if (rx_data[1] == BLE_SOF_CMD) { + switch (rx_data[2]) { case BLE_INIT_CMD: - // TODO: Get the BLE Device name from rx_data and pass it to ble_init + // TODO: Get the BLE Device name from rx_data and pass it to ble_init ble_init(); + toggle_led(); break; case BLE_START_ADV_CMD: @@ -84,8 +85,9 @@ break; case BLE_SEND_DATA_CMD: - memcpy(tmp_buf, &rx_data[3], rx_data[2]); - ble_send_data(tmp_buf, rx_data[2]); + toggle_led(); + memcpy(tmp_buf, &rx_data[4], rx_data[3]); + ble_send_data(tmp_buf, rx_data[3]); break; default : @@ -107,7 +109,7 @@ void ble_data_handler_init(void) { ble_data_rx_cb_register(ble_rx_Data_Callback); - //spi_data_rx_cb_register(spi_rx_Data_Callback); + spi_data_rx_cb_register(spi_rx_Data_Callback); } /******************************************************************************/