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:
- 282:2dc06137f1ec
- Parent:
- 281:a362a9450b81
- Child:
- 283:a09013615589
diff -r a362a9450b81 -r 2dc06137f1ec src/BLEDataHandler/BLEDataHandler.cpp --- a/src/BLEDataHandler/BLEDataHandler.cpp Wed Oct 26 21:26:52 2016 +0000 +++ b/src/BLEDataHandler/BLEDataHandler.cpp Thu Oct 27 21:44:25 2016 +0000 @@ -43,15 +43,15 @@ * @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\":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 static void BleRxDataCallback(uint8_t *rx_data, uint8_t len) { memset( BLE_ReceiveString, 0, BLE_RECEIVE_BUFFER_SIZE ); - if( len >= BLE_RECEIVE_BUFFER_SIZE ) - { + if( len >= BLE_RECEIVE_BUFFER_SIZE ) { printf("Received file larger than buffer (len=%d)\r\n", len ); return; } - + // memcpy( BLE_ReceiveString, rx_data, len ); // comment out and use line below until we receive JSON from APP // temporary until we receive actual string from APP memcpy( BLE_ReceiveString, fake_string, strlen(fake_string) ); @@ -94,6 +94,21 @@ BLE.SendFile(tx_array,strlen((char *)tx_array)); break; } + case BT_MODBUS_COMMAND_MTYPE: { + printf("%s:%d: GOT MODBUS COMMAND\r\n",__func__,__LINE__); + + cJSON *mbcommand = cJSON_GetObjectItem(root, "mbcommand"); + 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; + strncpy( mail->controlFile, payload_string.c_str(), (sizeof(mail->controlFile)-1)); + ModbusMasterMailBox.put(mail); + break; + } default: printf("unknown mtype received\r\n"); break;