2019-06-05

Dependencies:   DataStorage NetworkManager IR_Manager WheelManager RestAPI_Manager

Revision:
1:dc6fd86fb7f9
Parent:
0:8eda451f71fa
Child:
4:acd433b7ecd7
--- a/module_for_all.cpp	Mon Oct 08 00:50:33 2018 +0000
+++ b/module_for_all.cpp	Fri Dec 21 07:54:21 2018 +0000
@@ -4,6 +4,8 @@
 DigitalOut led2(LED2);
 DigitalOut led3(LED3);
 
+Serial PC(SERIAL_TX, SERIAL_RX);
+
 void split(const std::string& tmpString,
             std::vector<std::string>& stringVector,
             const char* delim = " ") {
@@ -14,42 +16,93 @@
     do {
         stringVector.push_back(p);
     } while ((p = std::strtok(NULL, delim)));
+    
+    delete [] buffer;
 }
 
-char* stringToChar(std::string tmpString) {
+/*char* stringToChar(std::string tmpString) {
     char* tmpChar = new char [tmpString.length()+1];
     std::strcpy(tmpChar, tmpString.c_str());
     return tmpChar;
+}*/
+
+void stringToChar(char* tmpChar, std::string tmpString) {
+    //char* tmpChar = new char [tmpString.length()+1];
+    std::strcpy(tmpChar, tmpString.c_str());
+    //return tmpChar;
+}
+
+int stringToInt(std::string tmpString) {
+    int tmpInt;
+    istringstream is(tmpString);
+    is>>tmpInt;
+    return tmpInt;
+}
+
+std::string intToString(int tmpInt) {
+    ostringstream stream;
+    stream << tmpInt;
+    std::string tmpInt_s = stream.str();
+    return tmpInt_s;
+}
+
+std::string floatToString(float tmpFloat) {
+    ostringstream stream;
+    stream << tmpFloat;
+    std::string tmpFloat_s = stream.str();
+    return tmpFloat_s;
 }
 
 void LED_PowerStart() {
     led1 = 1;
     led2 = 0;
     led3 = 0;
-    wait(0.1);
+    //wait(0.1);
 }
 
 void LED_NetWait() {
     led1 = 0;
     led2 = 1;
     led3 = 0;
-    wait(0.1);
+    //wait(0.1);
 }
 
 void LED_NetProcess() {
     led1 = 0;
     led2 = 0;
     led3 = 1;
-    wait(0.1);
+    //wait(0.1);
+}
+
+void myPrint(const char* format, ...){
+    char* tmpS;
+    //sprintf(tmpS, format);
+    //PC.printf(tmpS);
+    
+    va_list arg;
+    int done;
+    va_start (arg, format);
+    done = vsprintf (tmpS, format, arg);
+    va_end (arg);
+    
+    PC.printf(tmpS);
+    delete tmpS;
+    //printf(tmpS);
+    //wait(0.1);
 }
 
 int countRoot(std::string& tmpString) {
     int count = 0;
-    char* tmpAPI = stringToChar(tmpString);
+    //char* tmpAPI = stringToChar(tmpString);
+    char* tmpAPI = new char [tmpString.length()+1];
+    std::strcpy(tmpAPI, tmpString.c_str());
+    
     for (int ii=0;ii<strlen(tmpAPI);ii++) {
         if(tmpAPI[ii]=='/') {
             count++;
         }
     }
+    
+    delete [] tmpAPI;
     return count;
 }
\ No newline at end of file