Asa Ewing / Mbed OS mbed-os-rest-api-V1-2

Dependencies:   DataStorage NetworkManager IR_Manager WheelManager RestAPI_Manager

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers module_for_all.cpp Source File

module_for_all.cpp

00001 #include "module_for_all.h"
00002 
00003 DigitalOut led1(LED1);
00004 DigitalOut led2(LED2);
00005 DigitalOut led3(LED3);
00006 
00007 Serial PC(SERIAL_TX, SERIAL_RX);
00008 
00009 void split(const std::string& tmpString,
00010             std::vector<std::string>& stringVector,
00011             const char* delim = " ") {
00012     stringVector.clear();
00013     char* buffer = new char[tmpString.size() + 1];
00014     std::copy(tmpString.begin(), tmpString.end(), buffer);
00015     char* p = std::strtok(buffer, delim);
00016     do {
00017         stringVector.push_back(p);
00018     } while ((p = std::strtok(NULL, delim)));
00019     
00020     delete [] buffer;
00021 }
00022 
00023 /*char* stringToChar(std::string tmpString) {
00024     char* tmpChar = new char [tmpString.length()+1];
00025     std::strcpy(tmpChar, tmpString.c_str());
00026     return tmpChar;
00027 }*/
00028 
00029 void stringToChar(char* tmpChar, std::string tmpString) {
00030     //char* tmpChar = new char [tmpString.length()+1];
00031     std::strcpy(tmpChar, tmpString.c_str());
00032     //return tmpChar;
00033 }
00034 
00035 int stringToInt(std::string tmpString) {
00036     int tmpInt;
00037     istringstream is(tmpString);
00038     is>>tmpInt;
00039     return tmpInt;
00040 }
00041 
00042 std::string intToString(int tmpInt) {
00043     ostringstream stream;
00044     stream << tmpInt;
00045     std::string tmpInt_s = stream.str();
00046     return tmpInt_s;
00047 }
00048 
00049 std::string floatToString(float tmpFloat) {
00050     ostringstream stream;
00051     stream << tmpFloat;
00052     std::string tmpFloat_s = stream.str();
00053     return tmpFloat_s;
00054 }
00055 
00056 void LED_PowerStart() {
00057     led1 = 1;
00058     led2 = 0;
00059     led3 = 0;
00060     //wait(0.1);
00061 }
00062 
00063 void LED_NetWait() {
00064     led1 = 0;
00065     led2 = 1;
00066     led3 = 0;
00067     //wait(0.1);
00068 }
00069 
00070 void LED_NetProcess() {
00071     led1 = 0;
00072     led2 = 0;
00073     led3 = 1;
00074     //wait(0.1);
00075 }
00076 
00077 void LED_NetProcess_checkServer() {
00078     led1 = 1;
00079     led2 = 0;
00080     led3 = 1;
00081 
00082     if (DataStorage::isNoConnectServer) {
00083         led1 = 0;
00084         wait(0.1);
00085 
00086         led1 = 1;
00087         wait(0.1);
00088 
00089         led1 = 0;
00090         wait(0.1);
00091 
00092         led1 = 1;
00093     }
00094 }
00095 
00096 void myPrint(const char* format, ...){
00097     char* tmpS;
00098     //sprintf(tmpS, format);
00099     //PC.printf(tmpS);
00100     
00101     va_list arg;
00102     int done;
00103     va_start (arg, format);
00104     done = vsprintf (tmpS, format, arg);
00105     va_end (arg);
00106     
00107     PC.printf(tmpS);
00108     delete tmpS;
00109     //printf(tmpS);
00110     //wait(0.1);
00111 }
00112 
00113 int countRoot(std::string& tmpString) {
00114     int count = 0;
00115     //char* tmpAPI = stringToChar(tmpString);
00116     char* tmpAPI = new char [tmpString.length()+1];
00117     std::strcpy(tmpAPI, tmpString.c_str());
00118     
00119     for (int ii=0;ii<strlen(tmpAPI);ii++) {
00120         if(tmpAPI[ii]=='/') {
00121             count++;
00122         }
00123     }
00124     
00125     delete [] tmpAPI;
00126     return count;
00127 }