SSDP Server - working version provides SSDP based network discovery, and with a companion web server, may provide other functionalities.

Dependents:   X10Svr SSDP_Server

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Sun Jul 19 15:07:14 2020 +0000
Parent:
13:bcabd901d344
Commit message:
Change the SSDP listener thread to "normal", and tweak a few debug statements.

Changed in this revision

SSDP.cpp Show annotated file Show diff for this revision Revisions of this file
SSDP.h Show annotated file Show diff for this revision Revisions of this file
--- a/SSDP.cpp	Sat Jul 18 18:44:08 2020 +0000
+++ b/SSDP.cpp	Sun Jul 19 15:07:14 2020 +0000
@@ -78,7 +78,7 @@
 // The SSDP listener thread
 static void SSDPListener(void const * args) {
     UDPSocket server;
-    SSDP_Config_T * cfg = (SSDP_Config_T *)args;
+    SSDP_Config_T * cfg = (SSDP_Config_T*)args;
     
     server.bind(MCAST_PORT);
     int r = server.join_multicast_group(MCAST_GRP);
@@ -99,13 +99,13 @@
             buffer[n] = '\0';
             INFO("SSDP Recv %d bytes from %s:%d", n, 
                 client.get_address(), client.get_port());
-            INFO("RecvMessage:  <<<<<<<<<<<<<<\r\n%s<<<<<<<<<<<<<<<", buffer);
+            INFO("RecvMessage:\r\n<<<<<<<<<<<<<<\r\n%s>>>>>>>>>>>>>>>", buffer);
             char * p = buffer;
             while (*p) {
                 char * e = strstr(p, "\r\n");
                 if (e && (e - buffer) < n) {
                     *e = '\0';
-                    INFO("EVAL '%s'", p);
+                    //INFO("EVAL '%s'", p);
                     if (sw_stristr(p, "M-SEARCH * HTTP/1.1")) {
                         mask |= 0x01;                               // M-SEARCH * HTTP/1.1
                     } else if (sw_stristr(p, "MAN:") && sw_stristr(p,"\"ssdp:discover\"")) {
@@ -130,7 +130,7 @@
                             pColon = '\0';
                         }
                     }
-                    INFO("    mask: %02X", mask);
+                    //INFO("    mask: %02X", mask);
                     p = e + 1;
                 }
                 p++;
@@ -143,7 +143,7 @@
                     sprintf(out_buffer, SSDP_HTTP, cfg->ipAddr, cfg->port, cfg->ident, cfg->ident);
                     // It would be polite to delay, but the recommendation is from 1 to 5 seconds,
                     // and that will stall this thread.
-                    INFO("SSDPListener: reply >>>>>>> %s:%d >>>>>>>>>>>>>>>>>>>>>>>>>>>>>", client.get_address(),
+                    INFO("SSDPListener: reply >>>>>>> %s:%d >>>>>>>>>>>>>", client.get_address(),
                         client.get_port());
                     INFO("\r\n%s", out_buffer);
                     int i = server.sendTo(client, out_buffer, strlen(out_buffer));
@@ -270,7 +270,7 @@
 }
 
 void SSDP::StartListener() {
-    pThr = new Thread(SSDPListener, (void *)&_config, osPriorityLow, 768);
+    pThr = new Thread(SSDPListener, (void *)&_config, osPriorityNormal, 768);
     INFO("SSDP Listener Started: %p", pThr);
 }
 
--- a/SSDP.h	Sat Jul 18 18:44:08 2020 +0000
+++ b/SSDP.h	Sun Jul 19 15:07:14 2020 +0000
@@ -12,7 +12,6 @@
 #include "mbed.h"
 #include "rtos.h"
 
-
 /// Configuration data for the SSDP server.
 ///
 /// When internal to the SSDP server, it will manage the memory (dynamic allocations
@@ -31,7 +30,6 @@
 } SSDP_Config_T;
 
 
-
 /// SSDP Server
 /// 
 /// This file documents the SSDP Server, which can be implanted into a node
@@ -59,6 +57,8 @@
 /// @endcode
 ///
 class SSDP {
+private:
+    
 public:
     /// Constructor for the SSDP server
     ///
@@ -115,6 +115,7 @@
     ///
     bool SetPort(int port);
     
+  
 private:
 
     /// Delete the friendly name that was assigned.
@@ -140,6 +141,8 @@
     ///
     void StartListener();
     
+    Thread * pThr;
+
     /// Type of Notification
     typedef enum {
         nt_root,        ///< upnp:rootdevice notification