networking library files

Dependents:   ELEC350_Project2

Revision:
9:e22fd5795831
Parent:
8:8d2f71a08a31
Child:
10:b8214cc88e85
diff -r 8d2f71a08a31 -r e22fd5795831 Networking.cpp
--- a/Networking.cpp	Fri Dec 28 10:03:42 2018 +0000
+++ b/Networking.cpp	Fri Dec 28 12:04:38 2018 +0000
@@ -30,11 +30,14 @@
         //Block and wait on an incoming connection
         srv.accept(&clt_sock, &clt_addr);
         
-        network_tout.attach(network_toutISR,TOUT_TIME);
+        network_tout.attach(network_toutISR,TOUT_TIME_DEF);
         
-        printlock.lock();
-        pc->printf("Incoming connection accepted on %s:%d\n\r", clt_addr.get_ip_address(), clt_addr.get_port());
-        printlock.unlock();
+        if(logging)
+        {
+            printlock.lock();
+            printf("Incoming connection accepted on %s:%d\r\n", clt_addr.get_ip_address(), clt_addr.get_port());
+            printlock.unlock();
+        }
         
         //Uses a C++ string to make it easier to concatinate
         {
@@ -51,7 +54,7 @@
             bufferLock.unlock();        
             
             //Convert to a C String
-            printlock.lock();
+            printlock.lock(); //necessary?
             sprintf(temp_str, "%5.2f", temp);
             sprintf(press_str, "%5.2f", press);
             sprintf(light_str, "%5.2f", light);
@@ -78,7 +81,14 @@
             printlock.unlock();
                     
             //Send static HTML response (as a C string)
-            clt_sock.send(response.c_str(), response.size());  
+            clt_sock.send(response.c_str(), response.size());
+            
+            if(logging)
+            {
+                printlock.lock();
+                pc->printf("Network thread responded with time: %s, temperature: %s, pressure:%s and light level: %s\r\n\n",time_str, temp_str, press_str, light_str);
+                printlock.unlock();   
+            } 
         }
         network_tout.detach();  
     }