![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
2019-06-05
Dependencies: DataStorage NetworkManager IR_Manager WheelManager RestAPI_Manager
module_for_all.cpp@4:acd433b7ecd7, 2019-06-05 (annotated)
- Committer:
- asaewing
- Date:
- Wed Jun 05 07:54:20 2019 +0000
- Revision:
- 4:acd433b7ecd7
- Parent:
- 1:dc6fd86fb7f9
1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
asaewing | 0:8eda451f71fa | 1 | #include "module_for_all.h" |
asaewing | 0:8eda451f71fa | 2 | |
asaewing | 0:8eda451f71fa | 3 | DigitalOut led1(LED1); |
asaewing | 0:8eda451f71fa | 4 | DigitalOut led2(LED2); |
asaewing | 0:8eda451f71fa | 5 | DigitalOut led3(LED3); |
asaewing | 0:8eda451f71fa | 6 | |
asaewing | 1:dc6fd86fb7f9 | 7 | Serial PC(SERIAL_TX, SERIAL_RX); |
asaewing | 1:dc6fd86fb7f9 | 8 | |
asaewing | 0:8eda451f71fa | 9 | void split(const std::string& tmpString, |
asaewing | 0:8eda451f71fa | 10 | std::vector<std::string>& stringVector, |
asaewing | 0:8eda451f71fa | 11 | const char* delim = " ") { |
asaewing | 0:8eda451f71fa | 12 | stringVector.clear(); |
asaewing | 0:8eda451f71fa | 13 | char* buffer = new char[tmpString.size() + 1]; |
asaewing | 0:8eda451f71fa | 14 | std::copy(tmpString.begin(), tmpString.end(), buffer); |
asaewing | 0:8eda451f71fa | 15 | char* p = std::strtok(buffer, delim); |
asaewing | 0:8eda451f71fa | 16 | do { |
asaewing | 0:8eda451f71fa | 17 | stringVector.push_back(p); |
asaewing | 0:8eda451f71fa | 18 | } while ((p = std::strtok(NULL, delim))); |
asaewing | 1:dc6fd86fb7f9 | 19 | |
asaewing | 1:dc6fd86fb7f9 | 20 | delete [] buffer; |
asaewing | 0:8eda451f71fa | 21 | } |
asaewing | 0:8eda451f71fa | 22 | |
asaewing | 1:dc6fd86fb7f9 | 23 | /*char* stringToChar(std::string tmpString) { |
asaewing | 0:8eda451f71fa | 24 | char* tmpChar = new char [tmpString.length()+1]; |
asaewing | 0:8eda451f71fa | 25 | std::strcpy(tmpChar, tmpString.c_str()); |
asaewing | 0:8eda451f71fa | 26 | return tmpChar; |
asaewing | 1:dc6fd86fb7f9 | 27 | }*/ |
asaewing | 1:dc6fd86fb7f9 | 28 | |
asaewing | 1:dc6fd86fb7f9 | 29 | void stringToChar(char* tmpChar, std::string tmpString) { |
asaewing | 1:dc6fd86fb7f9 | 30 | //char* tmpChar = new char [tmpString.length()+1]; |
asaewing | 1:dc6fd86fb7f9 | 31 | std::strcpy(tmpChar, tmpString.c_str()); |
asaewing | 1:dc6fd86fb7f9 | 32 | //return tmpChar; |
asaewing | 1:dc6fd86fb7f9 | 33 | } |
asaewing | 1:dc6fd86fb7f9 | 34 | |
asaewing | 1:dc6fd86fb7f9 | 35 | int stringToInt(std::string tmpString) { |
asaewing | 1:dc6fd86fb7f9 | 36 | int tmpInt; |
asaewing | 1:dc6fd86fb7f9 | 37 | istringstream is(tmpString); |
asaewing | 1:dc6fd86fb7f9 | 38 | is>>tmpInt; |
asaewing | 1:dc6fd86fb7f9 | 39 | return tmpInt; |
asaewing | 1:dc6fd86fb7f9 | 40 | } |
asaewing | 1:dc6fd86fb7f9 | 41 | |
asaewing | 1:dc6fd86fb7f9 | 42 | std::string intToString(int tmpInt) { |
asaewing | 1:dc6fd86fb7f9 | 43 | ostringstream stream; |
asaewing | 1:dc6fd86fb7f9 | 44 | stream << tmpInt; |
asaewing | 1:dc6fd86fb7f9 | 45 | std::string tmpInt_s = stream.str(); |
asaewing | 1:dc6fd86fb7f9 | 46 | return tmpInt_s; |
asaewing | 1:dc6fd86fb7f9 | 47 | } |
asaewing | 1:dc6fd86fb7f9 | 48 | |
asaewing | 1:dc6fd86fb7f9 | 49 | std::string floatToString(float tmpFloat) { |
asaewing | 1:dc6fd86fb7f9 | 50 | ostringstream stream; |
asaewing | 1:dc6fd86fb7f9 | 51 | stream << tmpFloat; |
asaewing | 1:dc6fd86fb7f9 | 52 | std::string tmpFloat_s = stream.str(); |
asaewing | 1:dc6fd86fb7f9 | 53 | return tmpFloat_s; |
asaewing | 0:8eda451f71fa | 54 | } |
asaewing | 0:8eda451f71fa | 55 | |
asaewing | 0:8eda451f71fa | 56 | void LED_PowerStart() { |
asaewing | 0:8eda451f71fa | 57 | led1 = 1; |
asaewing | 0:8eda451f71fa | 58 | led2 = 0; |
asaewing | 0:8eda451f71fa | 59 | led3 = 0; |
asaewing | 1:dc6fd86fb7f9 | 60 | //wait(0.1); |
asaewing | 0:8eda451f71fa | 61 | } |
asaewing | 0:8eda451f71fa | 62 | |
asaewing | 0:8eda451f71fa | 63 | void LED_NetWait() { |
asaewing | 0:8eda451f71fa | 64 | led1 = 0; |
asaewing | 0:8eda451f71fa | 65 | led2 = 1; |
asaewing | 0:8eda451f71fa | 66 | led3 = 0; |
asaewing | 1:dc6fd86fb7f9 | 67 | //wait(0.1); |
asaewing | 0:8eda451f71fa | 68 | } |
asaewing | 0:8eda451f71fa | 69 | |
asaewing | 0:8eda451f71fa | 70 | void LED_NetProcess() { |
asaewing | 0:8eda451f71fa | 71 | led1 = 0; |
asaewing | 0:8eda451f71fa | 72 | led2 = 0; |
asaewing | 0:8eda451f71fa | 73 | led3 = 1; |
asaewing | 1:dc6fd86fb7f9 | 74 | //wait(0.1); |
asaewing | 1:dc6fd86fb7f9 | 75 | } |
asaewing | 1:dc6fd86fb7f9 | 76 | |
asaewing | 4:acd433b7ecd7 | 77 | void LED_NetProcess_checkServer() { |
asaewing | 4:acd433b7ecd7 | 78 | led1 = 1; |
asaewing | 4:acd433b7ecd7 | 79 | led2 = 0; |
asaewing | 4:acd433b7ecd7 | 80 | led3 = 1; |
asaewing | 4:acd433b7ecd7 | 81 | |
asaewing | 4:acd433b7ecd7 | 82 | if (DataStorage::isNoConnectServer) { |
asaewing | 4:acd433b7ecd7 | 83 | led1 = 0; |
asaewing | 4:acd433b7ecd7 | 84 | wait(0.1); |
asaewing | 4:acd433b7ecd7 | 85 | |
asaewing | 4:acd433b7ecd7 | 86 | led1 = 1; |
asaewing | 4:acd433b7ecd7 | 87 | wait(0.1); |
asaewing | 4:acd433b7ecd7 | 88 | |
asaewing | 4:acd433b7ecd7 | 89 | led1 = 0; |
asaewing | 4:acd433b7ecd7 | 90 | wait(0.1); |
asaewing | 4:acd433b7ecd7 | 91 | |
asaewing | 4:acd433b7ecd7 | 92 | led1 = 1; |
asaewing | 4:acd433b7ecd7 | 93 | } |
asaewing | 4:acd433b7ecd7 | 94 | } |
asaewing | 4:acd433b7ecd7 | 95 | |
asaewing | 1:dc6fd86fb7f9 | 96 | void myPrint(const char* format, ...){ |
asaewing | 1:dc6fd86fb7f9 | 97 | char* tmpS; |
asaewing | 1:dc6fd86fb7f9 | 98 | //sprintf(tmpS, format); |
asaewing | 1:dc6fd86fb7f9 | 99 | //PC.printf(tmpS); |
asaewing | 1:dc6fd86fb7f9 | 100 | |
asaewing | 1:dc6fd86fb7f9 | 101 | va_list arg; |
asaewing | 1:dc6fd86fb7f9 | 102 | int done; |
asaewing | 1:dc6fd86fb7f9 | 103 | va_start (arg, format); |
asaewing | 1:dc6fd86fb7f9 | 104 | done = vsprintf (tmpS, format, arg); |
asaewing | 1:dc6fd86fb7f9 | 105 | va_end (arg); |
asaewing | 1:dc6fd86fb7f9 | 106 | |
asaewing | 1:dc6fd86fb7f9 | 107 | PC.printf(tmpS); |
asaewing | 1:dc6fd86fb7f9 | 108 | delete tmpS; |
asaewing | 1:dc6fd86fb7f9 | 109 | //printf(tmpS); |
asaewing | 1:dc6fd86fb7f9 | 110 | //wait(0.1); |
asaewing | 0:8eda451f71fa | 111 | } |
asaewing | 0:8eda451f71fa | 112 | |
asaewing | 0:8eda451f71fa | 113 | int countRoot(std::string& tmpString) { |
asaewing | 0:8eda451f71fa | 114 | int count = 0; |
asaewing | 1:dc6fd86fb7f9 | 115 | //char* tmpAPI = stringToChar(tmpString); |
asaewing | 1:dc6fd86fb7f9 | 116 | char* tmpAPI = new char [tmpString.length()+1]; |
asaewing | 1:dc6fd86fb7f9 | 117 | std::strcpy(tmpAPI, tmpString.c_str()); |
asaewing | 1:dc6fd86fb7f9 | 118 | |
asaewing | 0:8eda451f71fa | 119 | for (int ii=0;ii<strlen(tmpAPI);ii++) { |
asaewing | 0:8eda451f71fa | 120 | if(tmpAPI[ii]=='/') { |
asaewing | 0:8eda451f71fa | 121 | count++; |
asaewing | 0:8eda451f71fa | 122 | } |
asaewing | 0:8eda451f71fa | 123 | } |
asaewing | 1:dc6fd86fb7f9 | 124 | |
asaewing | 1:dc6fd86fb7f9 | 125 | delete [] tmpAPI; |
asaewing | 0:8eda451f71fa | 126 | return count; |
asaewing | 0:8eda451f71fa | 127 | } |