![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
2018-12-21 3
Dependencies: DataStorage NetworkManager IR_Manager WheelManager RestAPI_Manager
module_for_all.cpp@1:dc6fd86fb7f9, 2018-12-21 (annotated)
- Committer:
- asaewing
- Date:
- Fri Dec 21 07:54:21 2018 +0000
- Revision:
- 1:dc6fd86fb7f9
- Parent:
- 0:8eda451f71fa
- Child:
- 4:acd433b7ecd7
First 2018-12-21
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 | 1:dc6fd86fb7f9 | 77 | void myPrint(const char* format, ...){ |
asaewing | 1:dc6fd86fb7f9 | 78 | char* tmpS; |
asaewing | 1:dc6fd86fb7f9 | 79 | //sprintf(tmpS, format); |
asaewing | 1:dc6fd86fb7f9 | 80 | //PC.printf(tmpS); |
asaewing | 1:dc6fd86fb7f9 | 81 | |
asaewing | 1:dc6fd86fb7f9 | 82 | va_list arg; |
asaewing | 1:dc6fd86fb7f9 | 83 | int done; |
asaewing | 1:dc6fd86fb7f9 | 84 | va_start (arg, format); |
asaewing | 1:dc6fd86fb7f9 | 85 | done = vsprintf (tmpS, format, arg); |
asaewing | 1:dc6fd86fb7f9 | 86 | va_end (arg); |
asaewing | 1:dc6fd86fb7f9 | 87 | |
asaewing | 1:dc6fd86fb7f9 | 88 | PC.printf(tmpS); |
asaewing | 1:dc6fd86fb7f9 | 89 | delete tmpS; |
asaewing | 1:dc6fd86fb7f9 | 90 | //printf(tmpS); |
asaewing | 1:dc6fd86fb7f9 | 91 | //wait(0.1); |
asaewing | 0:8eda451f71fa | 92 | } |
asaewing | 0:8eda451f71fa | 93 | |
asaewing | 0:8eda451f71fa | 94 | int countRoot(std::string& tmpString) { |
asaewing | 0:8eda451f71fa | 95 | int count = 0; |
asaewing | 1:dc6fd86fb7f9 | 96 | //char* tmpAPI = stringToChar(tmpString); |
asaewing | 1:dc6fd86fb7f9 | 97 | char* tmpAPI = new char [tmpString.length()+1]; |
asaewing | 1:dc6fd86fb7f9 | 98 | std::strcpy(tmpAPI, tmpString.c_str()); |
asaewing | 1:dc6fd86fb7f9 | 99 | |
asaewing | 0:8eda451f71fa | 100 | for (int ii=0;ii<strlen(tmpAPI);ii++) { |
asaewing | 0:8eda451f71fa | 101 | if(tmpAPI[ii]=='/') { |
asaewing | 0:8eda451f71fa | 102 | count++; |
asaewing | 0:8eda451f71fa | 103 | } |
asaewing | 0:8eda451f71fa | 104 | } |
asaewing | 1:dc6fd86fb7f9 | 105 | |
asaewing | 1:dc6fd86fb7f9 | 106 | delete [] tmpAPI; |
asaewing | 0:8eda451f71fa | 107 | return count; |
asaewing | 0:8eda451f71fa | 108 | } |