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:
- 283:a09013615589
- Parent:
- 282:2dc06137f1ec
- Child:
- 284:cc72206ea8e0
diff -r 2dc06137f1ec -r a09013615589 src/BLEDataHandler/BLEDataHandler.cpp --- a/src/BLEDataHandler/BLEDataHandler.cpp Thu Oct 27 21:44:25 2016 +0000 +++ b/src/BLEDataHandler/BLEDataHandler.cpp Fri Oct 28 16:28:44 2016 +0000 @@ -6,6 +6,8 @@ *****************************************************************************/ #include "global.h" #include <stdio.h> +#include <sstream> +#include <iostream> #include "BLEDataHandler.h" #include "CloudDataHandler.h" #include "LoggerApi.h" @@ -33,6 +35,18 @@ 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 @@ -42,8 +56,10 @@ * @param length * @return none *****************************************************************************/ -char * fake_string = "{ \"mtype\":1200, \"getreadings\":[ { \"tag\":\"i_tra01\" } ] }"; // use this to fake a message out requesting i_tra01 readings +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\":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) { memset( BLE_ReceiveString, 0, BLE_RECEIVE_BUFFER_SIZE ); @@ -101,7 +117,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;