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
Revision 284:cc72206ea8e0, committed 2016-10-28
- Comitter:
- jinu
- Date:
- Fri Oct 28 18:44:12 2016 +0000
- Parent:
- 283:a09013615589
- Commit message:
- modified for live data testing
Changed in this revision
--- a/BLE/src/ble_main.cpp Fri Oct 28 16:28:44 2016 +0000
+++ b/BLE/src/ble_main.cpp Fri Oct 28 18:44:12 2016 +0000
@@ -29,7 +29,8 @@
/******************************************************************************/
BLE_INIT BLE_INIT;
extern volatile bool isDeviceConnected;
-
+uint8_t temp_buf[30];
+uint8_t dummy_bytes;
/*******************************************************************************
* Function: ConfigureBLEDevice()
* Description: Initialise and configure BLE
@@ -107,7 +108,7 @@
packet[3] =0x45;
packet[4] =0x4f;
packet[5] =0x46;
- memset(&packet[6], 0x45, 17);
+ memset(&packet[6], 0x40, 17);
packet[23]=BLE_EOT_CMD;
WriteSpiData(packet,24);
}
@@ -126,20 +127,23 @@
uint8_t num_writes,rem_bytes,start_index =0;
// GetFileName(); //TODO
/*added for testing purpose.Need to be removed*/
+ num_writes = ((len)/MAX_PAYLOAD_BYTES);
+ rem_bytes =((len)%MAX_PAYLOAD_BYTES);
+
uint8_t file_name[20];
file_name[0] =0x53;
file_name[1] =0x4f;
file_name[2] =0x46;
- memset(&file_name[3],0x5a,17);
+ file_name[3] = rem_bytes;
+ memset(&file_name[4],0x40,17);
/*TODO
SOF consist of information about packets.Now sending a string for testing
with mobile app
*/
SendSOF(file_name,16);
-
- num_writes = ((len)/MAX_PAYLOAD_BYTES);
- rem_bytes =((len)%MAX_PAYLOAD_BYTES);
+ SendSOF(file_name,16);
+
for(int i=0;i<(num_writes);i++)
{
@@ -148,13 +152,17 @@
}
if(rem_bytes)
{
- BLE_INIT.SendBleData(&json_file[start_index], rem_bytes);
+ dummy_bytes = 20-rem_bytes;
+ // BLE_INIT.SendBleData(&json_file[start_index], rem_bytes);
+ memcpy(temp_buf,&json_file[start_index],rem_bytes);
+ memset(&temp_buf[rem_bytes],0x40,dummy_bytes);
+ BLE_INIT.SendBleData(temp_buf, MAX_PAYLOAD_BYTES);
}
/*TODO
EOF indication that packets transfer compleated.
This information can be passed in SOF. */
- // SendEOF();
+ SendEOF();
}
--- a/BLE/src/ble_msg_handler.cpp Fri Oct 28 16:28:44 2016 +0000
+++ b/BLE/src/ble_msg_handler.cpp Fri Oct 28 18:44:12 2016 +0000
@@ -29,7 +29,7 @@
volatile bool isDeviceConnected;
static ble_data_ready_callback_t data_ready_cb;
uint8_t json_array[MAX_FILE_SIZE];
-uint8_t count,file_index,file_size;
+uint16_t count,file_index,file_size;
/*****************************************************************************
* Function: BLE data receive callback
* Description: Function used to register ble data receive callback
@@ -69,21 +69,27 @@
json Array.when it equals 3,ie 60 bytes(assuming that each time
we are sening 20 bytes), passing this to callback to main
function.
- */
-
- count++;
+ */
+
+ // if(file_receiving_flag ==true)
+ // {
+ // count++;
/*reassembling packets */
memcpy(&json_array[file_index],&spi_rcv_array[3], (spi_rcv_array[2]-4));
- file_index+= (spi_rcv_array[2]-4); //((spi_rcv_array[2]-4) contains packet length excluding headers
+ // file_index+= (spi_rcv_array[2]-4); //((spi_rcv_array[2]-4) contains packet length excluding headers
- if(count ==3) //added for testing. Need to change this to if(file_index == file_size)
- {
+ // if(count ==3) //added for testing. Need to change this to if(file_index == file_size)
+ // {
/*Passing the entire file to callback function*/
- data_ready_cb(json_array, file_index);
+ // data_ready_cb(json_array, file_index);
+ data_ready_cb(json_array, (spi_rcv_array[2]-4));
count= 0;
file_index =0;
- }
+ /* Reset the File Parameters */
+ file_receiving_flag = false;
+ // }
+ // }
break;
case BLE_DISCONNECTION_EVNT_CMD:
@@ -97,7 +103,7 @@
/*extract the json string length from SOF. */
- file_size = spi_rcv_array[3];
+ file_size = ((spi_rcv_array[3]<<8)|spi_rcv_array[4]);
break;
@@ -117,4 +123,4 @@
/******************************************************************************/
/* END OF FILE */
-/******************************************************************************/
+/******************************************************************************/
\ No newline at end of file
--- 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
--- a/src/BLEDataHandler/BLEDataHandler.h Fri Oct 28 16:28:44 2016 +0000 +++ b/src/BLEDataHandler/BLEDataHandler.h Fri Oct 28 18:44:12 2016 +0000 @@ -8,6 +8,6 @@ #define BLEDATAHANDLER_H void BLEDataHandler(void const *args); -void BLE_ReplyToHandler( std::string &id, int status, float value ); +//void BLE_ReplyToHandler( std::string &id, int status, float value ); #endif \ No newline at end of file
--- a/src/CloudDataHandler/CloudDataHandler.cpp Fri Oct 28 16:28:44 2016 +0000
+++ b/src/CloudDataHandler/CloudDataHandler.cpp Fri Oct 28 18:44:12 2016 +0000
@@ -17,33 +17,7 @@
printf("\r%s has started...\n", __func__);
while ( true ) {
-
- std::string tmp_buffer;
-
- if (!GLOBAL_mdot->getNetworkJoinStatus()) {
- logInfo("network not joined, joining network");
- if ((ret = GLOBAL_mdot->joinNetwork()) != mDot::MDOT_OK) {
- logError("failed to join network %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
- joined = false;
- }
- } else {
- joined = true;
- }
-
- sent = LogHandler( joined );
- if( sent == true ) {
- // sent a packet, try to receive back.
- logInfo("Sent to gateway: %s", tmp_buffer.c_str());
- std::vector<uint8_t> rcvData(256);
- rcvData.clear();
- if ((ret = GLOBAL_mdot->recv(rcvData)) == mDot::MDOT_OK) {
- if (!rcvData.empty()) {
- std::string rcv_string(rcvData.begin(), rcvData.end());
- logInfo("Received Data: %s", rcv_string.c_str());
- CloudFileReceiver( &rcv_string, GLOBAL_mdot );
- }
- }
- }
+ sent = LogHandler( false );
Thread::wait(1000);
}
-}
\ No newline at end of file
+}
--- a/src/CloudDataHandler/LogHandler.cpp Fri Oct 28 16:28:44 2016 +0000
+++ b/src/CloudDataHandler/LogHandler.cpp Fri Oct 28 18:44:12 2016 +0000
@@ -115,7 +115,7 @@
void ReplyToHandler( ThreadName_t replyTo, std::string &id, int ret, float value )
{
if( replyTo == BLE_HANDLER ) {
- BLE_ReplyToHandler( id, ret, value );
+ // BLE_ReplyToHandler( id, ret, value );
} else if( replyTo == CLOUD_DATA_HANDLER ) {
CDH_ReplyToHandler( id, ret, value );
} else {
