Erick / Mbed 2 deprecated ICE_BLE_TEST

Dependencies:   NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed

Fork of ICE by Erick

Revision:
283:a09013615589
Parent:
238:e35cac576620
Child:
284:cc72206ea8e0
--- a/src/CloudDataHandler/LogHandler.cpp	Thu Oct 27 21:44:25 2016 +0000
+++ b/src/CloudDataHandler/LogHandler.cpp	Fri Oct 28 16:28:44 2016 +0000
@@ -1,8 +1,13 @@
+#include "global.h"
+#include <stdio.h>
+#include <sstream>
+#include <iostream>
 #include "LogHandler.h"
 #include "LogLocalApi.h"
+#include "LoggerApi.h"
+#include "BLEDataHandler.h"
 #include "CloudFileReceiver.h"
 #include "MTSLog.h"
-#include "global.h"
 
 Mail<LoggerQueue_t, 16> LoggerQueue;
 
@@ -63,8 +68,7 @@
             tmp_buffer = "{\"mtype\":\"20\"}";
         } else {
 //            printf("%s:%d: Nothing to send to the cloud\r\n", __func__, __LINE__);
-            if( CloudDataHandler_RcvFile != true )
-            {
+            if( CloudDataHandler_RcvFile != true ) {
                 return false;
             }
             printf("%s:%d: currently receiveing a file\r\n", __func__, __LINE__);
@@ -91,4 +95,30 @@
 //        printf("%s:%d: Could not send to cloud, nothing to store in EEPROM\r\n", __func__, __LINE__);
     }
     return false;
+}
+
+void CDH_ReplyToHandler( std::string &id, int status, float value )
+{
+    std::ostringstream reply_oss;
+    
+    LoggerQueue_t *LoggerEvent = LoggerQueue.alloc();
+    memset( LoggerEvent->log_entry, 0, sizeof(LoggerEvent->log_entry) );
+
+    reply_oss << "{  \"mtype\":1001, \"mbreply\":{ \"id\":\"" << id.c_str() << "\"," "\"status\":\"0\"," "\"value\":\"" << value << "\"} }";
+    std::string string_reply = reply_oss.str();
+    strncpy( LoggerEvent->log_entry, string_reply.c_str(), (sizeof(LoggerEvent->log_entry)-1));
+    printf("%s:%d: Reply is: %s\r\n",__func__,__LINE__, LoggerEvent->log_entry);
+    LoggerEvent->position = 0;
+    LoggerQueue.put(LoggerEvent);
+}
+
+void ReplyToHandler( ThreadName_t replyTo, std::string &id, int ret, float value )
+{
+    if( replyTo == BLE_HANDLER ) {
+        BLE_ReplyToHandler( id, ret, value );
+    } else if( replyTo == CLOUD_DATA_HANDLER ) {
+        CDH_ReplyToHandler( id, ret, value );
+    } else {
+        logError("Unknown Thread for Command Reply");
+    }
 }
\ No newline at end of file