Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed
Fork of ICE by
Diff: BLE/src/ble_main.cpp
- Revision:
- 249:68ed571e0002
- Child:
- 259:341f04be325e
diff -r e156e33b8b38 -r 68ed571e0002 BLE/src/ble_main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BLE/src/ble_main.cpp Fri Oct 21 13:48:57 2016 +0000 @@ -0,0 +1,152 @@ +/** + ****************************************************************************** + * @file ble_uart.cpp + * @author Happiesstminds Firmware Team + * @version v1.0 + * @date 4-Oct-2016 + * @brief + * + ****************************************************************************** + * @attention + * + * + ****************************************************************************** + */ + +/******************************************************************************/ +/* Include Files*/ +/******************************************************************************/ +#include "mbed.h" +#include "ble_main.h" +#include "ble_spi.h" +#include "ble_msg_handler.h" +#include "ble_init.h" + +#define BLE_DEVICE_NAME "Ecolab" + +/******************************************************************************/ +/* Global Functions */ +/******************************************************************************/ +BLE_INIT BLE_INIT; + + +/***************************************************************************** + * Function: ConfigureBLEDevice() + * Description: Initialise and configure BLE + * + * @param none + * @return none + *****************************************************************************/ + +uint8_t BLE_FILE :: ConfigureBLEDevice(void) +{ + + uint8_t status = SUCCESS; + BLE_INIT.InitBLEModule(); //initialising BLE SPI GPIO etc. + BLE_INIT.SetDeviceName(); //setting device name + BLE_INIT.SetAdvertisingData(); //setting advdata + BLE_INIT.SendInitBleCommand((const uint8_t *) BLE_DEVICE_NAME); //initializing BLE +// StartAdvertisingData(); //starting adv data + return status; +} + +/***************************************************************************** + * Function: SendSOF() + * Description: This function send Start of File transfer frame + * + * @param tx_buf +* @param data length + * @return none + *****************************************************************************/ +uint8_t SendSOF(uint8_t *tx_buf, uint8_t len) +{ + int i,j =0; + uint8_t packet[100]; + uint8_t status = SUCCESS; + uint8_t packetlength; + // uint8_t array_length[10]; + packetlength = len + 4; + + packet[0]= BLE_SOF_CMD; + packet[1]= BLE_START_OF_FILE; + packet[2]= len; + + memcpy(&packet[3], tx_buf, len); + packet[len + 3]= BLE_EOT_CMD; + + WriteSpiData(packet, packetlength); + return status; +} +/***************************************************************************** + * Function: SendEOF() + * Description: This function send End of File transfer frame + * + * @param none + * @return none + *****************************************************************************/ +void SendEOF(void) +{ + uint8_t packet[4]; + + packet[0]= BLE_SOF_CMD; + packet[1]= BLE_END_OF_FILE; + packet[2]= DATA_LENGTH; + packet[3]= BLE_EOT_CMD; + WriteSpiData(packet,COMMAND_LENGTH); +} +/***************************************************************************** + * Function: GetFileName() + * Description: This function extract File name + * + * @param json file data + * @return none + *****************************************************************************/ +void GetFileName(uint8_t json_file) +{ + //TODO +} + +/***************************************************************************** + * Function: SendFile() + * Description: This function receive the json file data and transmit + data over BLE + * + * @param json file data + * @param data length + * @return none + *****************************************************************************/ +void BLE_FILE :: SendFile(uint8_t* json_file,uint8_t len) +{ + uint8_t num_writes,rem_bytes,start_index =0; + // GetFileName(); //TODO + /*added for testing purpose.Need to be removed*/ + uint8_t file_name[20]; + file_name[0] =0x30; + file_name[1] =0x30; + file_name[2] =0x31; + file_name[3] =0x30; + file_name[4] =0x74; + file_name[5] =0x65; + file_name[6] =0x73; + file_name[7] =0x74; + /***********************************************/ + SendSOF(file_name,8); //Currently Sending "0010test " TODO - need to get the file name. + num_writes = ((len)/MAX_PAYLOAD_BYTES); + rem_bytes =((len)%MAX_PAYLOAD_BYTES); + + for(int i=0;i<(num_writes);i++) + { + BLE_INIT.SendBleData(&json_file[start_index], MAX_PAYLOAD_BYTES); + start_index= start_index+MAX_PAYLOAD_BYTES; + } + if(rem_bytes) + { + BLE_INIT.SendBleData(&json_file[start_index], rem_bytes); + } + + SendEOF(); //TODO + +} +/******************************************************************************/ +/* END OF FILE */ +/******************************************************************************/ \ No newline at end of file