Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DataStorage NetworkManager IR_Manager WheelManager RestAPI_Manager
Revision 1:dc6fd86fb7f9, committed 2018-12-21
- Comitter:
- asaewing
- Date:
- Fri Dec 21 07:54:21 2018 +0000
- Parent:
- 0:8eda451f71fa
- Child:
- 2:7581451de520
- Commit message:
- First 2018-12-21
Changed in this revision
--- a/CPU_Usage.lib Mon Oct 08 00:50:33 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://os.mbed.com/users/dextorslabs/code/CPU_Usage/#807947fd7dde
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DataStorage.lib Fri Dec 21 07:54:21 2018 +0000 @@ -0,0 +1,1 @@ +DataStorage#833da29046f9
--- a/NetworkManager.lib Mon Oct 08 00:50:33 2018 +0000 +++ b/NetworkManager.lib Fri Dec 21 07:54:21 2018 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/users/asaewing/code/NetworkManager/#b12dd3a065c0 +http://os.mbed.com/users/asaewing/code/NetworkManager/#358fcf86ddab
--- a/RestAPI_Manager.lib Mon Oct 08 00:50:33 2018 +0000 +++ b/RestAPI_Manager.lib Fri Dec 21 07:54:21 2018 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/users/asaewing/code/RestAPI_Manager/#b3b078af7b16 +https://os.mbed.com/users/asaewing/code/RestAPI_Manager/#4db49ba6e885
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WheelManager.lib Fri Dec 21 07:54:21 2018 +0000 @@ -0,0 +1,1 @@ +WheelManager#61923a9dd110
--- a/main.cpp Mon Oct 08 00:50:33 2018 +0000 +++ b/main.cpp Fri Dec 21 07:54:21 2018 +0000 @@ -1,88 +0,0 @@ -#if !FEATURE_LWIP - #error [NOT_SUPPORTED] LWIP not supported for this target -#endif - -#include "module_for_all.h" - -#define PORT 8080 - -#define IP1 "192.168.20.101" -#define IP2 "192.168.20.102" -#define GATEWAY "192.168.20.1" -#define MASK "255.255.255.0" - -const char* ip = 0; -const char* mac = 0; - -DigitalIn IP_Select2(PG_2); - -NetworkManager net_manager(IP1, GATEWAY, MASK, PORT); -RestAPI_Manager restAPI_manager(IP1, "1"); - -//NetworkManager net_manager(); -//RestAPI_Manager restAPI_manager(); - -Timer t; -CPU_Usage cpu(t, 1); - -bool EventLoop() { - uint8_t value = 0; - while (true) { - printf("$$ EventLoop New\r\n"); - LED_NetWait(); - - net_manager.AcceptEvent(); - //printf("$$ EventLoop run Response\r\n"); - LED_NetProcess(); - - std::string http_method = net_manager.getHttpMethod(); - std::string api_command = net_manager.getApiCommand(); - - std::string response = restAPI_manager.runCommand(http_method, api_command); - - value = cpu.update(); - //printf("CPU %i", value); - - net_manager.SendResponseEvent(response); - printf("$$ EventLoop Finish\r\n"); - } - - printf("$$ EventLoop ALL Finish\r\n"); - return false; -} - -/* Main function */ -int main(){ - - printf("mbed Power Start\r\n"); - LED_PowerStart(); - cpu.working(); - - if (IP_Select2.read() == 1){ - net_manager.SetConfig(IP2, GATEWAY, MASK, PORT); - restAPI_manager.SetConfig(IP2, "2"); - printf("mbed 02 Start\r\n"); - - } else { - net_manager.SetConfig(IP1, GATEWAY, MASK, PORT); - restAPI_manager.SetConfig(IP1, "1"); - printf("mbed 01 Start\r\n"); - } - - net_manager.ServerInit(); - printf("ServerInit\r\n"); - - if (net_manager.OpenServer()) return 0; - printf("OpenServer\r\n"); - - if (net_manager.BindPort()) return 0; - printf("BindPort\r\n"); - - if (net_manager.ListenConnections()) return 0; - printf("ListenConnections\r\n"); - - if (EventLoop()) { - cpu.stopped(); - return 0; - } -} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main3.md Fri Dec 21 07:54:21 2018 +0000 @@ -0,0 +1,146 @@ +#if !FEATURE_LWIP + #error [NOT_SUPPORTED] LWIP not supported for this target +#endif + +#include "module_for_all.h" + +#define PORT 8080 + +#define IP1 "192.168.20.101" +#define IP2 "192.168.20.102" +#define IP3 "192.168.20.103" +#define IP4 "192.168.20.104" +#define GATEWAY "192.168.20.1" +#define MASK "255.255.255.0" + +const char* ip = 0; +const char* mac = 0; +Thread threadMain00; +DataStorage ds_manager(""); + +//DigitalIn IP_Select2(PG_2); + +//DigitalIn Test_Mode(PC_14); + +NetworkManager net_manager(IP1, GATEWAY, MASK, PORT); +RestAPI_Manager restAPI_manager(&ds_manager, &threadMain00, IP1, "1"); + +//NetworkManager net_manager(); +//RestAPI_Manager restAPI_manager(); + +bool EventLoop() { + while (true) { + printf("$$ EventLoop New\r\n"); + + Thread threadMain01; + restAPI_manager.changeThread(&threadMain01); + + printf("$$ EventLoop Change Thread\r\n"); + + LED_NetWait(); + + printf("$$ EventLoop Waiting\r\n"); + + net_manager.AcceptEvent(); + //printf("$$ EventLoop run Response\r\n"); + LED_NetProcess(); + + std::string http_method = net_manager.getHttpMethod(); + std::string api_command = net_manager.getApiCommand(); + + std::string response = restAPI_manager.runCommand(http_method, api_command); + + net_manager.SendResponseEvent(response); + printf("$$ EventLoop Finish\r\n"); + } + + //printf("$$ EventLoop ALL Finish\r\n"); + return false; +} + +/* Main function */ +int main(){ + + DigitalIn IP_Select1(PD_7); + DigitalIn IP_Select2(PD_6); + + //DigitalIn IP_Select21(PC_15); + //DigitalIn IP_Select22(PH_1); + + printf("mbed Power Start\r\n"); + LED_PowerStart(); + + /*if (IP_Select2.read() == 1){ + net_manager.SetConfig(IP2, GATEWAY, MASK, PORT); + restAPI_manager.SetConfig(IP2, "2"); + printf("mbed 02 Start\r\n"); + + } else { + net_manager.SetConfig(IP1, GATEWAY, MASK, PORT); + restAPI_manager.SetConfig(IP1, "1"); + printf("mbed 01 Start\r\n"); + }*/ + + int ipSelect = 1; + + if (IP_Select1.read() == 1){ + ipSelect += 1; + } + + if (IP_Select2.read() == 1){ + ipSelect += 2; + } + + char* tmp_IP = 0; + + switch(ipSelect) { + case 1: + tmp_IP = IP1; + break; + case 2: + tmp_IP = IP2; + break; + case 3: + tmp_IP = IP3; + break; + case 4: + tmp_IP = IP4; + break; + } + + std::string tmp_IP_s = intToString(ipSelect); + + + net_manager.SetConfig(tmp_IP, GATEWAY, MASK, PORT); + restAPI_manager.SetConfig(tmp_IP, tmp_IP_s); + + printf("mbed %d Start\r\n", ipSelect); + + wait(1); + + /*int kk = 0; + while(1){ + if (!net_manager.ServerInit()){ + break; + } + wait(4); + kk++; + printf("## again %d n\r\n", kk); + }*/ + + net_manager.ServerInit(); + printf("ServerInit\r\n"); + + if (net_manager.OpenServer()) return 0; + printf("OpenServer\r\n"); + + if (net_manager.BindPort()) return 0; + printf("BindPort\r\n"); + + if (net_manager.ListenConnections()) return 0; + printf("ListenConnections\r\n"); + + if (EventLoop()) { + return 0; + } +} \ No newline at end of file
--- 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
--- a/module_for_all.h Mon Oct 08 00:50:33 2018 +0000 +++ b/module_for_all.h Fri Dec 21 07:54:21 2018 +0000 @@ -11,22 +11,43 @@ #include "EthernetInterface.h" #include "TCPServer.h" #include "TCPSocket.h" +//#include "TCPSocketConnection.h" #include "mbed.h" +#include "DataStorage.h" #include "NetworkManager.h" #include "RestAPI_Manager.h" -#include "CPU_Usage.h" +#include "WheelManager.h" + +#include "rtos.h" +/* +DigitalOut _W1_A(PC_6); +DigitalOut _W1_B(PD_8); + +DigitalOut _W2_A(PA_12); +DigitalOut _W2_B(PA_11); + +DigitalOut _W3_A(PB_12); +DigitalOut _W3_B(PB_11); + +DigitalOut _W4_A(PB_2); +DigitalOut _W4_B(PB_15);*/ void split(const std::string&, std::vector<std::string>&, const char*); -char* stringToChar(std::string); +void stringToChar(char* tmpChar, std::string); +int stringToInt(std::string); + +std::string intToString(int); +std::string floatToString(float); void LED_PowerStart(); void LED_NetWait(); void LED_NetProcess(); +void myPrint(const char*, ...); int countRoot(std::string&); #endif \ No newline at end of file