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:
- 45:3b9e1923cb15
- Parent:
- 31:4b1587034318
- Child:
- 49:0456ee2271be
--- a/src/CloudDataHandler/CloudFileReceiver.cpp Mon Sep 12 14:38:39 2016 +0000
+++ b/src/CloudDataHandler/CloudFileReceiver.cpp Mon Sep 12 22:19:27 2016 +0000
@@ -3,28 +3,28 @@
#include "MbedJSONValue.h"
#include "global.h"
+char CloudFileReceiverDataBuf[1024];
+
bool CloudFileReceiver( std::string *recv_string, mDot *dot )
{
MbedJSONValue from_json;
bool status;
-
+
parse( from_json, recv_string->c_str() );
int sequence = from_json["seq"].get<int>();
- logInfo("Received command: %s", recv_string->c_str());
+// printf("Received command: %s\r\n", recv_string->c_str());
// sequence of -1 means string sent in 1 chunk.
if( sequence == -1 ) {
-
FILENAME_STRING filename;
int mType = from_json["pay"]["mtype"].get<int>();
- logInfo("mtype=%d", mType);
+ logInfo("mtype=%d\r\n", mType);
memset( filename, '\0', sizeof(FILENAME_STRING) );
switch( mType ) {
- case SETPOINT_CONTROL_MTYPE:
- {
+ case SETPOINT_CONTROL_MTYPE: {
logInfo("PROCESSING SETPONT CONTROL FILE");
snprintf( filename, sizeof(FILENAME_STRING), "%s_%s%s",
from_json["pay"]["spcontrol"]["id"].get<std::string>().c_str(),
@@ -35,15 +35,46 @@
}
case TIMER_CONTROL_MTYPE:
break;
- case INPUT_CONFIG_MTYPE:
- {
- logInfo("PROCESSING INPUT CONFIG FILE");
+ case INPUT_CONFIG_MTYPE: {
snprintf( filename, sizeof(FILENAME_STRING), "input_%s%s",
from_json["pay"]["input"]["id"].get<std::string>().c_str(),
- ".json" );
+ ".jsn" );
logInfo("INPUT CONFIG FILENAME=%s", filename);
- logInfo("Sending Mail To ModbusMasterMailBox, filename=%s");
+ memset( CloudFileReceiverDataBuf, '\0', 1024 );
+ snprintf(CloudFileReceiverDataBuf, sizeof(CloudFileReceiverDataBuf),
+ "{ "
+ "\"id\":\"%s\", "
+ "\"name\":\"%s\", "
+ "\"units\":\"%s\", "
+ "\"min\":\"%s\", "
+ "\"max\":\"%s\", "
+ "\"node\":\"%s\", "
+ "\"reg\":\"%s\", "
+ "\"rtype\":\"%s\", "
+ "\"type\":\"%s\", "
+ "\"size\":\"%s\", "
+ "\"order\":\"%s\" } ",
+ from_json["pay"]["input"]["id"].get<std::string>().c_str(),
+ from_json["pay"]["input"]["name"].get<std::string>().c_str(),
+ from_json["pay"]["input"]["units"].get<std::string>().c_str(),
+ from_json["pay"]["input"]["min"].get<std::string>().c_str(),
+ from_json["pay"]["input"]["max"].get<std::string>().c_str(),
+ from_json["pay"]["input"]["node"].get<std::string>().c_str(),
+ from_json["pay"]["input"]["reg"].get<std::string>().c_str(),
+ from_json["pay"]["input"]["rtype"].get<std::string>().c_str(),
+ from_json["pay"]["input"]["type"].get<std::string>().c_str(),
+ from_json["pay"]["input"]["size"].get<std::string>().c_str(),
+ from_json["pay"]["input"]["order"].get<std::string>().c_str()
+ );
+
+ logInfo("saving string%s", CloudFileReceiverDataBuf);
+ bool status = GLOBAL_mdot->saveUserFile(filename, (void *)CloudFileReceiverDataBuf, 1024);
+ if( status != true ) {
+ logInfo("(%d)save file failed, status=%d", __LINE__, status);
+ }
+
+ logInfo("Sending Mail To ModbusMasterMailBox, filename=%s", filename);
Message_t *mail = ModbusMasterMailBox.alloc();
mail->action = ACTION_READ_FILE;
strncpy( mail->controlFile, filename, (sizeof(mail->controlFile)-1));
