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

Dependencies:   DataStorage NetworkManager IR_Manager WheelManager RestAPI_Manager

Files at this revision

API Documentation at this revision

Comitter:
asaewing
Date:
Wed Jun 05 07:54:20 2019 +0000
Parent:
3:ba8ecd64c329
Child:
5:aaab7ef5dccf
Commit message:
1.0

Changed in this revision

DataStorage.lib Show annotated file Show diff for this revision Revisions of this file
IR_Manager.lib Show annotated file Show diff for this revision Revisions of this file
NetworkManager.lib Show annotated file Show diff for this revision Revisions of this file
RestAPI_Manager.lib Show annotated file Show diff for this revision Revisions of this file
WheelManager.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
module_for_all.cpp Show annotated file Show diff for this revision Revisions of this file
module_for_all.h Show annotated file Show diff for this revision Revisions of this file
--- a/DataStorage.lib	Fri Dec 21 14:21:24 2018 +0000
+++ b/DataStorage.lib	Wed Jun 05 07:54:20 2019 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/asaewing/code/DataStorage/#833da29046f9
+https://os.mbed.com/users/asaewing/code/DataStorage/#3b10241770d7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IR_Manager.lib	Wed Jun 05 07:54:20 2019 +0000
@@ -0,0 +1,1 @@
+IR_Manager#3714c3af7602
--- a/NetworkManager.lib	Fri Dec 21 14:21:24 2018 +0000
+++ b/NetworkManager.lib	Wed Jun 05 07:54:20 2019 +0000
@@ -1,1 +1,1 @@
-http://os.mbed.com/users/asaewing/code/NetworkManager/#358fcf86ddab
+http://os.mbed.com/users/asaewing/code/NetworkManager/#304e92340942
--- a/RestAPI_Manager.lib	Fri Dec 21 14:21:24 2018 +0000
+++ b/RestAPI_Manager.lib	Wed Jun 05 07:54:20 2019 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/asaewing/code/RestAPI_Manager/#4db49ba6e885
+https://os.mbed.com/users/asaewing/code/RestAPI_Manager/#1ebb951bd156
--- a/WheelManager.lib	Fri Dec 21 14:21:24 2018 +0000
+++ b/WheelManager.lib	Wed Jun 05 07:54:20 2019 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/asaewing/code/WheelManager/#61923a9dd110
+https://os.mbed.com/users/asaewing/code/WheelManager/#b794ac1a3aa6
--- a/main.cpp	Fri Dec 21 14:21:24 2018 +0000
+++ b/main.cpp	Wed Jun 05 07:54:20 2019 +0000
@@ -1,28 +1,28 @@
-#if !FEATURE_LWIP 
-    #error [NOT_SUPPORTED] LWIP not supported for this target
+
+#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"
+#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;
-DataStorage ds_manager("");
+const char *ip = 0;
+const char *mac = 0;
 
-//DigitalIn  IP_Select2(PG_2);
+DataStorage ds_manager("");
+IR_Manager ir_manager("");
+WheelManager wheel_manager("");
 
-//DigitalIn  Test_Mode(PC_14);
-
-NetworkManager*  net_manager = new NetworkManager(IP1, GATEWAY, MASK, PORT);
-RestAPI_Manager* restAPI_manager = new RestAPI_Manager(&ds_manager, IP1, "1");
+NetworkManager *net_manager = new NetworkManager(IP1, GATEWAY, MASK, PORT);
+RestAPI_Manager *restAPI_manager = new RestAPI_Manager(&ds_manager, &ir_manager, &wheel_manager, IP1, "1");
 
 //NetworkManager  net_manager();
 //RestAPI_Manager restAPI_manager();
@@ -31,7 +31,10 @@
 {
     //TCPSocket socket;
 
-    printf("Sending HTTP request to www.arm.com...\r\n");
+    printf("checkServer Start...\r\n");
+
+    ir_manager.digitalTest();
+    ir_manager.analogTest();
 
     // Open a socket on the network interface, and create a TCP connection to www.arm.com
     net_manager->clt_sock.open(&(net_manager->eth));
@@ -40,43 +43,41 @@
     // Send a simple http request
     //char sbuffer[] = "GET /iamok/ HTTP/1.1\r\nHost: 192.168.20.1\r\n\r\n";
     std::string sbuffer_str = "GET /iamok/ HTTP/1.1\r\nHost: 192.168.20.1\r\n\r\n";
-    char* sbuffer = new char [sbuffer_str.length()+1];
-    
+    char *sbuffer = new char[sbuffer_str.length() + 1];
+
     //tmpString = stringToChar(tmpResponse);
     stringToChar(sbuffer, sbuffer_str);
-    
+
     //clt_sock.send(tmpString, strlen(tmpString));
-    
+
     int scount = net_manager->clt_sock.send(sbuffer, strlen(sbuffer));
-    printf("sent %d [%.*s]\r\n", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer);
-    
-    if (scount>=0){
+    printf("sent %d [%.*s]\r\n", scount, strstr(sbuffer, "\r\n") - sbuffer, sbuffer);
+
+    if (scount >= 0)
+    {
         // Recieve a simple http response and print out the response line
-        char* rbuffer = new char[1024];
+        char *rbuffer = new char[1024];
         //char* buf = new char[1024];
         //int rcount = net_manager->clt_sock.recv(rbuffer, sizeof rbuffer);
         int rcount = net_manager->clt_sock.recv(rbuffer, 100);
-        printf("recv %d [%.*s]\r\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer);
-        delete [] rbuffer;
-    } else {
-        DataStorage::_W1_A = 0;
-        DataStorage::_W1_B = 0;
-        
-        DataStorage::_W2_A = 0;
-        DataStorage::_W2_B = 0;
-        
-        DataStorage::_W3_A = 0;
-        DataStorage::_W3_B = 0;
-        
-        DataStorage::_W4_A = 0;
-        DataStorage::_W4_B = 0;
-        
-        for (int ii=0;ii<5;ii++){
+        printf("recv %d [%.*s]\r\n", rcount, strstr(rbuffer, "\r\n") - rbuffer, rbuffer);
+        delete[] rbuffer;
+        DataStorage::isNoConnectServer = false;
+    }
+    else
+    {
+        DataStorage::set_PWM_status(1, 0, 0);
+        DataStorage::set_PWM_status(2, 0, 0);
+        DataStorage::set_PWM_status(3, 0, 0);
+        DataStorage::set_PWM_status(4, 0, 0);
+
+        for (int ii = 0; ii < 5; ii++)
+        {
             DataStorage::WM_PWM[ii][0] = 1;
             DataStorage::WM_PWM[ii][1] = 0;
         }
-        
-        (DataStorage::_WM_PWM_out01).period(DataStorage::WM_PWM[0][0]);
+
+        /*(DataStorage::_WM_PWM_out01).period(DataStorage::WM_PWM[0][0]);
         (DataStorage::_WM_PWM_out02).period(DataStorage::WM_PWM[1][0]);
         (DataStorage::_WM_PWM_out03).period(DataStorage::WM_PWM[2][0]);
         (DataStorage::_WM_PWM_out04).period(DataStorage::WM_PWM[3][0]);
@@ -84,147 +85,179 @@
         (DataStorage::_WM_PWM_out01).write(DataStorage::WM_PWM[0][1]);
         (DataStorage::_WM_PWM_out02).write(DataStorage::WM_PWM[1][1]);
         (DataStorage::_WM_PWM_out03).write(DataStorage::WM_PWM[2][1]);
-        (DataStorage::_WM_PWM_out04).write(DataStorage::WM_PWM[3][1]);
+        (DataStorage::_WM_PWM_out04).write(DataStorage::WM_PWM[3][1]);*/
+        for (int ii = 0; ii < 4; ii++)
+            ds_manager.set_PWM_period(ii, 1);
+        for (int ii = 0; ii < 4; ii++)
+            ds_manager.set_PWM_write(ii, 0);
+        DataStorage::isNoConnectServer = true;
     }
 
     // Close the socket to return its memory and bring down the network interface
     net_manager->clt_sock.close();
-    
-    delete [] sbuffer;
-    
+
+    delete[] sbuffer;
+    printf("checkServer Over...\r\n");
 }
 
-void checkServerLoop() {
-    while (true) {
+void checkServerLoop()
+{
+    while (true)
+    {
         checkServer();
     }
 }
 
-void checkServerThread() {
+void checkServerThread()
+{
     Thread thread_connect;
     thread_connect.start(checkServerLoop);
 }
 
+bool EventLoop()
+{
+    while (true)
+    {
+        printf("$$ EventLoop New\r\n");
 
-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");
-        if (DataStorage::isAccept){
+        if (DataStorage::isAccept)
+        {
             LED_NetProcess();
             DataStorage::http_method = net_manager->getHttpMethod();
             DataStorage::api_command = net_manager->getApiCommand();
             DataStorage::response = restAPI_manager->runCommand(DataStorage::http_method, DataStorage::api_command);
             net_manager->SendResponseEvent(DataStorage::response);
-        } else {
+            DataStorage::noAcceptCount = 0;
+        }
+        else
+        {
             DataStorage::noAcceptCount += 1;
-            if (DataStorage::noAcceptCount==20) {
+            if (DataStorage::noAcceptCount == 20)
+            {
                 DataStorage::noAcceptCount = 0;
-                checkServer();
+                if (!DataStorage::isTestMode)
+                {
+                    LED_NetProcess_checkServer();
+                    checkServer();
+                }
             }
         }
-        
+
         //DataStorage::http_method = net_manager->getHttpMethod();
         //DataStorage::api_command = net_manager->getApiCommand();
-        
+
         //DataStorage::response = restAPI_manager->runCommand(DataStorage::http_method, DataStorage::api_command);
         //net_manager->SendResponseEvent(DataStorage::response);
-        
+
         DataStorage::isAccept = false;
         printf("$$ EventLoop Finish\r\n");
     }
-    
+
     //printf("$$ EventLoop ALL Finish\r\n");
     return false;
 }
 
-void checkIP(){
-    DigitalIn  IP_Select1(PD_7);
-    DigitalIn  IP_Select2(PD_6);
+void checkIP_Mode()
+{
+    DigitalIn IP_Select1(PD_7);
+    DigitalIn IP_Select2(PD_6);
+
+    DigitalIn Test_Mode(PC_14);
 
     DataStorage::ipSelect = 1;
-    
-    if (IP_Select1.read() == 1){
+
+    if (IP_Select1.read() == 1)
+    {
         DataStorage::ipSelect += 1;
     }
-    
-    if (IP_Select2.read() == 1){
+
+    if (IP_Select2.read() == 1)
+    {
         DataStorage::ipSelect += 2;
     }
-    
-    //char* tmp_IP = 0;
-    
-    switch(DataStorage::ipSelect) {
-        case 1: 
-            //tmp_IP = IP1;
-            DataStorage::ipChar = IP1;
-            break;
-        case 2: 
-            //tmp_IP = IP2;
-            DataStorage::ipChar = IP2;
-            break;
-        case 3: 
-            //tmp_IP = IP3;
-            DataStorage::ipChar = IP3;
-            break;
-        case 4: 
-            //tmp_IP = IP4;
-            DataStorage::ipChar = IP4;
-            break;
+
+    switch (DataStorage::ipSelect)
+    {
+    case 1:
+        DataStorage::ipChar = IP1;
+        break;
+    case 2:
+        DataStorage::ipChar = IP2;
+        break;
+    case 3:
+        DataStorage::ipChar = IP3;
+        break;
+    case 4:
+        DataStorage::ipChar = IP4;
+        break;
     }
 
-    //std::string tmp_IP_s = intToString(DataStorage::ipSelect);
     DataStorage::ipStr = intToString(DataStorage::ipSelect);
 
-    
     net_manager->SetConfig(DataStorage::ipChar, GATEWAY, MASK, PORT);
     restAPI_manager->SetConfig(DataStorage::ipChar, DataStorage::ipStr);
-    
+
     printf("mbed %d Start\r\n", DataStorage::ipSelect);
-    
-    //delete tmp_IP;
+
+    if (Test_Mode.read() == 1)
+    {
+        DataStorage::isTestMode = true;
+        printf("mbed %d mode Test\r\n", DataStorage::ipSelect);
+    }
+    else
+    {
+        DataStorage::isTestMode = false;
+        printf("mbed %d mode Normal\r\n", DataStorage::ipSelect);
+    }
 }
 
-int netInit(){
+int netInit()
+{
     net_manager->ServerInit();
     printf("ServerInit\r\n");
-    
-    if (net_manager->OpenServer()) return -1;
+
+    if (net_manager->OpenServer())
+        return -1;
     printf("OpenServer\r\n");
-    
-    if (net_manager->BindPort()) return -1;
+
+    if (net_manager->BindPort())
+        return -1;
     printf("BindPort\r\n");
-    
-    if (net_manager->ListenConnections()) return -1;
+
+    if (net_manager->ListenConnections())
+        return -1;
     printf("ListenConnections\r\n");
-    
+
     return 0;
 }
 
-void start(){
+void start()
+{
     printf("mbed Power Start\r\n");
     LED_PowerStart();
-    
-    checkIP();
+
+    checkIP_Mode();
     wait(0.5);
     netInit();
 }
 /* Main function */
-int main(){
+int main()
+{
     start();
-    
-    if (EventLoop()) {
+
+    if (EventLoop())
+    {
         return 0;
     }
 }
\ No newline at end of file
--- a/module_for_all.cpp	Fri Dec 21 14:21:24 2018 +0000
+++ b/module_for_all.cpp	Wed Jun 05 07:54:20 2019 +0000
@@ -74,6 +74,25 @@
     //wait(0.1);
 }
 
+void LED_NetProcess_checkServer() {
+    led1 = 1;
+    led2 = 0;
+    led3 = 1;
+
+    if (DataStorage::isNoConnectServer) {
+        led1 = 0;
+        wait(0.1);
+
+        led1 = 1;
+        wait(0.1);
+
+        led1 = 0;
+        wait(0.1);
+
+        led1 = 1;
+    }
+}
+
 void myPrint(const char* format, ...){
     char* tmpS;
     //sprintf(tmpS, format);
--- a/module_for_all.h	Fri Dec 21 14:21:24 2018 +0000
+++ b/module_for_all.h	Wed Jun 05 07:54:20 2019 +0000
@@ -19,8 +19,10 @@
 #include "NetworkManager.h"
 #include "RestAPI_Manager.h"
 #include "WheelManager.h"
+#include "IR_Manager.h"
 
 #include "rtos.h"
+#include "math.h"
 /*
 DigitalOut  _W1_A(PC_6);
 DigitalOut  _W1_B(PD_8);
@@ -47,6 +49,7 @@
 void LED_PowerStart();
 void LED_NetWait();
 void LED_NetProcess();
+void LED_NetProcess_checkServer();
 void myPrint(const char*, ...);
 int countRoot(std::string&);