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/CloudDataHandler/CloudFileReceiver.cpp
- Revision:
- 174:515a8b684803
- Parent:
- 171:fb29030d4eaf
- Parent:
- 173:acfb464a4aec
- Child:
- 175:5e533c43bffc
diff -r 51dfb4aabc57 -r 515a8b684803 src/CloudDataHandler/CloudFileReceiver.cpp
--- a/src/CloudDataHandler/CloudFileReceiver.cpp Tue Oct 04 12:26:14 2016 +0000
+++ b/src/CloudDataHandler/CloudFileReceiver.cpp Tue Oct 04 12:32:52 2016 +0000
@@ -376,21 +376,21 @@
return true;
}
-MbedJSONValue CloudFileReceiverFinalJson;
-MbedJSONValue CloudFileReceiveJson;
bool CloudDataHandler_RcvFile = false;
bool CloudFileReceiver( std::string *recv_string, mDot *dot )
{
-
+
+ MbedJSONValue incomingJson;
+
bool status;
- parse( CloudFileReceiveJson, recv_string->c_str() );
- int sequence = CloudFileReceiveJson["seq"].get<int>();
+ parse( incomingJson, recv_string->c_str() );
+ int sequence = incomingJson["seq"].get<int>();
CloudDataHandler_RcvFile = false;
// sequence of -1 means string sent in 1 chunk.
if( sequence == -1 ) {
- return StoreReceivedFile( dot, CloudFileReceiveJson );
+ return StoreReceivedFile( dot, incomingJson );
} else if( sequence == 0 ) {
memset(CloudFileReceiverWriteBuf,0,sizeof(CloudFileReceiverWriteBuf));
@@ -407,6 +407,8 @@
} else if( sequence == -2 ) {
+ MbedJSONValue finalJson;
+
logInfo("(%d)READING BACK scratch.json FILE FOR LAST PACKET", __LINE__);
// read the file back
@@ -416,17 +418,21 @@
return false;
}
- snprintf(CloudFileReceiverWriteBuf, sizeof(CloudFileReceiverWriteBuf), "%s%s%s", CloudFileReceiverReadBuf, CloudFileReceiveJson["pay"].get<std::string>().c_str(), "}" );
+ snprintf(CloudFileReceiverWriteBuf, sizeof(CloudFileReceiverWriteBuf), "%s%s%s", CloudFileReceiverReadBuf, incomingJson["pay"].get<std::string>().c_str(), "}" );
logInfo("(%d)Final String Length=%d, %s", __LINE__, strlen(CloudFileReceiverWriteBuf), CloudFileReceiverWriteBuf );
- parse( CloudFileReceiverFinalJson, CloudFileReceiverWriteBuf );
+ std::string err;
+ parse( finalJson, CloudFileReceiverWriteBuf, CloudFileReceiverWriteBuf + strlen(CloudFileReceiverWriteBuf), &err );
+ printf("finished parse\r\n" );
- int sequence = CloudFileReceiverFinalJson["seq"].get<int>();
- int mType = CloudFileReceiverFinalJson["pay"]["mtype"].get<int>();
+ Thread::wait(1000);
+
+ int sequence = finalJson["seq"].get<int>();
+ int mType = finalJson["pay"]["mtype"].get<int>();
printf("MESSAGE TYPE=%d\r\n",mType);
- status = StoreReceivedFile( dot, CloudFileReceiverFinalJson );
+ status = StoreReceivedFile( dot, finalJson );
if( status != true ) {
logError("(%d)save file failed, status=%d", __LINE__, status);
}
@@ -449,7 +455,7 @@
return false;
}
- snprintf(CloudFileReceiverWriteBuf, sizeof(CloudFileReceiverWriteBuf), "%s%s", CloudFileReceiverReadBuf, CloudFileReceiveJson["pay"].get<std::string>().c_str() );
+ snprintf(CloudFileReceiverWriteBuf, sizeof(CloudFileReceiverWriteBuf), "%s%s", CloudFileReceiverReadBuf, incomingJson["pay"].get<std::string>().c_str() );
logInfo("(%d)Writing String Length=%d, %s", __LINE__, strlen(CloudFileReceiverWriteBuf), CloudFileReceiverWriteBuf );
status = dot->saveUserFile("scratch.json", (void *)CloudFileReceiverWriteBuf, 512);
