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: src/BLEDataHandler/BLEDataHandler.cpp
- Revision:
- 284:cc72206ea8e0
- Parent:
- 283:a09013615589
diff -r a09013615589 -r cc72206ea8e0 src/BLEDataHandler/BLEDataHandler.cpp --- a/src/BLEDataHandler/BLEDataHandler.cpp Fri Oct 28 16:28:44 2016 +0000 +++ b/src/BLEDataHandler/BLEDataHandler.cpp Fri Oct 28 18:44:12 2016 +0000 @@ -6,8 +6,6 @@ *****************************************************************************/ #include "global.h" #include <stdio.h> -#include <sstream> -#include <iostream> #include "BLEDataHandler.h" #include "CloudDataHandler.h" #include "LoggerApi.h" @@ -35,18 +33,6 @@ bool BLE_StringReceived = false; char BLE_ReceiveString[BLE_RECEIVE_BUFFER_SIZE]; -void BLE_ReplyToHandler( std::string &id, int status, float value ) -{ - std::ostringstream mb_reply; - - BLEHandlerReq_t *mail = BLEHandlerMailBox.alloc(); - mb_reply << "{ \"mtype\":1001, \"mbreply\":{ \"id\":\"" << id.c_str() << "\"," "\"status\":\"" << status << "\"," "\"value\":\"" << value << "\"} }"; - std::string string_reply = mb_reply.str(); - strncpy( mail->reply, string_reply.c_str(), (sizeof(mail->reply)-1)); - printf("%s:%d: Reply is: %s\r\n",__func__,__LINE__, mail->reply); - BLEHandlerMailBox.put(mail); -} - /***************************************************************************** * Function: BLE data receive callback * Description: Process BLE data @@ -56,12 +42,11 @@ * @param length * @return none *****************************************************************************/ -char * fake_string = "{ \"mtype\":1200, \"getreadings\":[ { \"tag\":\"i_tra01\" }, { \"tag\":\"i_bdcond01\" }, { \"tag\":\"i_cond_temp01\" } ] }"; // use this to fake a message out requesting i_tra01 readings +char * fake_string = "{ \"mtype\":1200, \"getreadings\":[ { \"tag\":\"i_tra01\" } ] }"; // use this to fake a message out requesting i_tra01 readings //char * fake_string = "{ \"mtype\":1000, \"mbcommand\":{ \"id\":\"READ_TRASAR\"," "\"node\":\"1\"," "\"func\":\"4\"," "\"sreg\":\"9\"," "\"nreg\":\"2\"," "\"dtype\":\"0\"," "\"order\":\"2\"," "\"value\":\"0\" } }"; // use this to fake a message out requesting i_tra01 readings -//char * fake_string = "{ \"mtype\":1000, \"mbcommand\":{ \"id\":\"WRITE_MULTIPLE\"," "\"node\":\"21\"," "\"func\":\"16\"," "\"sreg\":\"0\"," "\"nreg\":\"3\"," "\"dtype\":\"5\"," "\"order\":\"2\"," "\"value\":\"0\", \"data\":[ { \"v\":\"20\" }, { \"v\":\"16\" }, { \"v\":\"0\" } ] } }"; // use this to fake a message out requesting i_tra01 readings - static void BleRxDataCallback(uint8_t *rx_data, uint8_t len) { +#if 0 //commented for Demo testing memset( BLE_ReceiveString, 0, BLE_RECEIVE_BUFFER_SIZE ); if( len >= BLE_RECEIVE_BUFFER_SIZE ) { printf("Received file larger than buffer (len=%d)\r\n", len ); @@ -73,10 +58,46 @@ memcpy( BLE_ReceiveString, fake_string, strlen(fake_string) ); BLE_StringReceived = true; // printf("Data Received: %s\r\n", BLE_ReceiveString); +#endif + + printf("Data Received: "); + for(int i=0;i<len;i++) + { + printf("%c",rx_data[i]); + + if(rx_data[0] == 0x61) + { + BLE_StringReceived =true; + } + } + printf("\n\r"); } void BLEDataHandler(void const *args) { + uint8_t tx_array[500]; + uint8_t event_status; + + /*TODO + Getting the init status from Nano BLE register and + Proceed based on the status. + */ + event_status = BLE.ConfigureBLEDevice(BLE_DEVICE_NAME); + BleDataRxCbRegister(BleRxDataCallback); + while(1) { + + event_status = PollBLEEvents(); + if(event_status == true && BLE_StringReceived == true) { + GetCurrentReadings( (char *)tx_array, sizeof(tx_array)); + BLE.SendFile(tx_array,strlen((char *)tx_array)); + BLE_StringReceived = false; + } + Thread::wait(100); + } +} +#if 0 +void BLEDataHandler(void const *args) +{ uint8_t tx_array[BLE_TRANSMIT_BUFFER_SIZE]; uint8_t event_status; @@ -117,7 +138,7 @@ std::string payload_string = cJSON_PrintUnformatted(mbcommand); printf("%s:%d: Sending Command Request to ModbusMaster: %s\r\n",__func__,__LINE__,payload_string.c_str()); - + ModbusMasterReq_t *mail = ModbusMasterMailBox.alloc(); mail->action = ACTION_EXEC_CMD; mail->replyThread = BLE_HANDLER; @@ -142,4 +163,6 @@ BLEHandlerMailBox.free(mail); } } -} \ No newline at end of file +} + +#endif \ No newline at end of file