IOP / httpServer_orgel

Fork of httpServer-orgel by justin kim

Files at this revision

API Documentation at this revision

Comitter:
justinkim
Date:
Wed Sep 02 02:03:22 2015 +0000
Parent:
1:772534e3b627
Child:
3:87bec0b34de7
Commit message:
network + analog in added

Changed in this revision

HTTPConnection.cpp Show annotated file Show diff for this revision Revisions of this file
HTTPRequestHandler.cpp Show annotated file Show diff for this revision Revisions of this file
HTTPRequestHandler.h Show annotated file Show diff for this revision Revisions of this file
HTTPServer.cpp Show annotated file Show diff for this revision Revisions of this file
HTTPServer.h Show annotated file Show diff for this revision Revisions of this file
Handler/FsHandler.cpp Show annotated file Show diff for this revision Revisions of this file
Handler/FsHandler.h Show annotated file Show diff for this revision Revisions of this file
--- a/HTTPConnection.cpp	Tue Jun 30 00:21:41 2015 +0000
+++ b/HTTPConnection.cpp	Wed Sep 02 02:03:22 2015 +0000
@@ -285,3 +285,5 @@
     
     return 0;
 }
+
+
--- a/HTTPRequestHandler.cpp	Tue Jun 30 00:21:41 2015 +0000
+++ b/HTTPRequestHandler.cpp	Wed Sep 02 02:03:22 2015 +0000
@@ -174,3 +174,5 @@
 {
     INFO("Ending Response !");
 }
+
+
--- a/HTTPRequestHandler.h	Tue Jun 30 00:21:41 2015 +0000
+++ b/HTTPRequestHandler.h	Wed Sep 02 02:03:22 2015 +0000
@@ -134,6 +134,7 @@
         virtual int handlePostRequest() = 0;
         
         void getStandardHeaders(HTTPHeaders& header, const char* fext = NULL);
+        
 };
 
 #endif //   __HTTPREQUESTHANDLER_H__
\ No newline at end of file
--- a/HTTPServer.cpp	Tue Jun 30 00:21:41 2015 +0000
+++ b/HTTPServer.cpp	Wed Sep 02 02:03:22 2015 +0000
@@ -43,6 +43,7 @@
     } else {
         //  In the case that the ethernet interface is provided, it is assumed that a connection has already been created.
         INFO("Using connection IP %s", pEthernet->getIPAddress());
+        m_pEthernet = pEthernet;
     }
     
     INFO("Binding to port %d...", port);
@@ -125,3 +126,5 @@
             delete phdl;
     }
 }
+
+
--- a/HTTPServer.h	Tue Jun 30 00:21:41 2015 +0000
+++ b/HTTPServer.h	Wed Sep 02 02:03:22 2015 +0000
@@ -207,4 +207,4 @@
         
  };
  
- #endif //__HTTPSERVER_H__
\ No newline at end of file
+ #endif //__HTTPSERVER_H__
--- a/Handler/FsHandler.cpp	Tue Jun 30 00:21:41 2015 +0000
+++ b/Handler/FsHandler.cpp	Wed Sep 02 02:03:22 2015 +0000
@@ -9,7 +9,8 @@
 DigitalOut led_blue(LED3);
 
 DigitalIn  din(PC_14);
-
+AnalogIn   ain0(A0);
+AnalogIn   ain1(A1);
 
 static int matchstrings(const char* one, const char* two)
 {
@@ -60,30 +61,33 @@
 {
 }
 
+std::map<int, EthernetInterface*> HTTPFsRequestHandler::m_eth_list;
+
 int HTTPFsRequestHandler::handleGetRequest()
 {
     HTTPHeaders headers;
+    EthernetInterface test_eth;
     int retval = 0;   //success
-    uint8_t pin_state;
     
-    if( std::string::npos != msg.uri.find("get_dio14.cgi") )
+    if( std::string::npos != msg.uri.find("get_netinfo.cgi") )
     {
-        if(din)
-            pin_state = 1;
-        else 
-            pin_state = 0;
+        char buf[256];
         
-        /*
-        *len = sprintf((char *)buf, "DioCallback({\"dio_p\":\"14\",\
-                                            \"dio_s\":\"%d\"\
-                                            });",
-                                            pin_state              // Digital io status
-                                            );
+        sprintf(buf, "NetinfoCallback({\"mac\":\"%s\",\"ip\":\"%s\",\"sn\":\"%s\",\"gw\":\"%s\"});"
+                    ,m_eth_list[0]->getMACAddress(),m_eth_list[0]->getIPAddress(),m_eth_list[0]->getNetworkMask(),m_eth_list[0]->getGateway());
+                
+        tcp.send(buf, strlen(buf));
+    }
+    
+    else if( std::string::npos != msg.uri.find("get_ain.cgi") )
+    {        
+        char buf[256];
         
-            
-        Tcp.
-        */
+        sprintf(buf, "AinCallback({\"ain_v0\":\"%.3f\",\"ain_v1\":\"%.3f\"});",ain0.read()*100, ain1.read()*100);
+                
+        tcp.send(buf, strlen(buf));
     }
+    
     else //read html pages
     {
         if (m_localPath.length() > 4) 
@@ -209,3 +213,4 @@
     return ret;
 }
 
+
--- a/Handler/FsHandler.h	Tue Jun 30 00:21:41 2015 +0000
+++ b/Handler/FsHandler.h	Wed Sep 02 02:03:22 2015 +0000
@@ -25,8 +25,11 @@
 
 #include "mbed.h"
 #include "HTTPRequestHandler.h"
+#include "HTTPConnection.h"
+#include "EthernetInterface.h"
 
 #include <map>
+#include <list>
 #include <string>
 
 /** class HTTPFsRequestHandler serves requests with file-system objects
@@ -37,6 +40,7 @@
         std::string m_localPath;
 
     public:
+
         /** constructor for HTTPFsRequestHandler object and stores the request related data locally. 
         * the request handling will be initiated from within the constructor.
         * @param rootPath : The path under which the handler was registered.
@@ -74,10 +78,15 @@
         */
         static void mount(const char* requestPath, const char* localPath) { m_fsMap[requestPath] = localPath; }
         
+        //Test
+        //static std::list<EthernetInterface> m_eth_list;
+        static std::map<int, EthernetInterface*> m_eth_list;
+        static void mount_eth(EthernetInterface* eth) { m_eth_list[0] = eth; }
+        
         /** Parse a uri string for uri file name and argument:value pairs
         */
         int parseUriArgs(string uri, map<string, string>& args);
         
         uint32_t get_http_param_value(char* param_name);
 };
-#endif // __FSHANDLER_H__
\ No newline at end of file
+#endif // __FSHANDLER_H__