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

Dependents:   X10Svr SSDP_Server

Committer:
WiredHome
Date:
Tue Jul 03 00:46:34 2018 +0000
Revision:
1:def15d0b2fae
Parent:
0:f782e7bc66ad
Child:
2:3d6d70556fca
Documentation update.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 0:f782e7bc66ad 1 //
WiredHome 0:f782e7bc66ad 2 //
WiredHome 0:f782e7bc66ad 3 //
WiredHome 0:f782e7bc66ad 4
WiredHome 0:f782e7bc66ad 5 #include "mbed.h"
WiredHome 0:f782e7bc66ad 6 #include "rtos.h"
WiredHome 0:f782e7bc66ad 7
WiredHome 0:f782e7bc66ad 8
WiredHome 1:def15d0b2fae 9 /// Configuration data for the SSDP server.
WiredHome 1:def15d0b2fae 10 ///
WiredHome 1:def15d0b2fae 11 /// When internal to the SSDP server, it will manage the memory (dynamic allocations
WiredHome 1:def15d0b2fae 12 /// and free).
WiredHome 1:def15d0b2fae 13 ///
WiredHome 1:def15d0b2fae 14 /// When an instance of this structure is passed to the SSDP constructor, it is
WiredHome 1:def15d0b2fae 15 /// up to the caller to ensure that the data being pointed to is persistent, where
WiredHome 1:def15d0b2fae 16 /// it should be. The 'name' is one field that could be changed at runtime, in
WiredHome 1:def15d0b2fae 17 /// order to reflect the name change to the network.
WiredHome 0:f782e7bc66ad 18 ///
WiredHome 0:f782e7bc66ad 19 typedef struct {
WiredHome 1:def15d0b2fae 20 char * name; ///< pointer to the friendly name
WiredHome 0:f782e7bc66ad 21 char * ident; ///< pointer to a unique identity number, like a mac address
WiredHome 0:f782e7bc66ad 22 char * ipAddr; ///< pointer to the node IP address
WiredHome 0:f782e7bc66ad 23 int port; ///< port number of the local server
WiredHome 0:f782e7bc66ad 24 } SSDP_Config_T;
WiredHome 0:f782e7bc66ad 25
WiredHome 0:f782e7bc66ad 26
WiredHome 0:f782e7bc66ad 27 ///
WiredHome 0:f782e7bc66ad 28 /// SSDP Server
WiredHome 0:f782e7bc66ad 29 ///
WiredHome 0:f782e7bc66ad 30 /// This file documents the SSDP Server, which can be implanted into a node
WiredHome 0:f782e7bc66ad 31 /// so that it is discoverable on Ethernet, and in Windows Network Explorer
WiredHome 0:f782e7bc66ad 32 /// view.
WiredHome 0:f782e7bc66ad 33 ///
WiredHome 0:f782e7bc66ad 34 /// Many basics are defined in order to satisfy the SSDP discovery process.
WiredHome 0:f782e7bc66ad 35 /// - the hosting node has a web server running, which will serve various responses.
WiredHome 0:f782e7bc66ad 36 /// - the hosting node shall provide a /setup.xml which satisfies the SSDP requirements.
WiredHome 0:f782e7bc66ad 37 /// - depending on the application, many additional files may need to be supported.
WiredHome 0:f782e7bc66ad 38 ///
WiredHome 0:f782e7bc66ad 39 /// @code
WiredHome 0:f782e7bc66ad 40 /// HTTPServer svr(Server_Port, Server_Root, 15, 30, 20, 50, &pc);
WiredHome 0:f782e7bc66ad 41 /// svr.RegisterHandler("/", RootPage);
WiredHome 0:f782e7bc66ad 42 /// svr.RegisterHandler("/setup.xml", Setup_xml);
WiredHome 0:f782e7bc66ad 43 /// SSDP ssdp("Friendly Node", eth.getMACAddress(), eth.getIPAddress(), Server_Port);
WiredHome 0:f782e7bc66ad 44 ///
WiredHome 0:f782e7bc66ad 45 /// while (1) {
WiredHome 0:f782e7bc66ad 46 /// led4 = !led4;
WiredHome 0:f782e7bc66ad 47 /// svr.Poll(); // non-blocking, but also not deterministic
WiredHome 0:f782e7bc66ad 48 /// Thread::yield();
WiredHome 0:f782e7bc66ad 49 /// if (criteria)
WiredHome 0:f782e7bc66ad 50 /// ssdp.SetFriendlyName("New Node Name");
WiredHome 0:f782e7bc66ad 51 /// }
WiredHome 0:f782e7bc66ad 52 /// @endcode
WiredHome 0:f782e7bc66ad 53 ///
WiredHome 0:f782e7bc66ad 54 class SSDP {
WiredHome 0:f782e7bc66ad 55 public:
WiredHome 0:f782e7bc66ad 56 /// Constructor for the SSDP server
WiredHome 0:f782e7bc66ad 57 ///
WiredHome 0:f782e7bc66ad 58 /// @param[in] name is a pointer to a string containing the name.
WiredHome 0:f782e7bc66ad 59 /// @param[in] ident is a pointer to an identity string of this node, e.g. a mac address.
WiredHome 0:f782e7bc66ad 60 /// @param[in] ipAddr is a pointer to an IP Address string of this node.
WiredHome 0:f782e7bc66ad 61 /// @param[in] port is an integer port number for the local web server.
WiredHome 0:f782e7bc66ad 62 ///
WiredHome 0:f782e7bc66ad 63 SSDP(const char * name, const char * ident, const char * ipAddr, int port);
WiredHome 0:f782e7bc66ad 64
WiredHome 0:f782e7bc66ad 65 /// Constructor for the SSDP server, as an alternate to the parameter version.
WiredHome 0:f782e7bc66ad 66 ///
WiredHome 0:f782e7bc66ad 67 /// @param[in] config is a pointer to configuration structure which contains
WiredHome 0:f782e7bc66ad 68 /// the individual elements;
WiredHome 0:f782e7bc66ad 69 /// - pointer to the const char * friendly name
WiredHome 0:f782e7bc66ad 70 /// - pointer to the const char * identity
WiredHome 0:f782e7bc66ad 71 /// - pointer to the const char * IP Address of this node
WiredHome 0:f782e7bc66ad 72 /// - port number for the web server
WiredHome 0:f782e7bc66ad 73 ///
WiredHome 1:def15d0b2fae 74 /// @note the items being pointed to in this structure must be persistent. Only
WiredHome 1:def15d0b2fae 75 /// the friendly name can change at runtime.
WiredHome 1:def15d0b2fae 76 ///
WiredHome 0:f782e7bc66ad 77 SSDP(const SSDP_Config_T * config);
WiredHome 0:f782e7bc66ad 78
WiredHome 0:f782e7bc66ad 79 /// Destructor
WiredHome 0:f782e7bc66ad 80 ///
WiredHome 0:f782e7bc66ad 81 ~SSDP();
WiredHome 0:f782e7bc66ad 82
WiredHome 0:f782e7bc66ad 83 /// Set the friendly name for this node
WiredHome 0:f782e7bc66ad 84 ///
WiredHome 0:f782e7bc66ad 85 /// @param[in] name is a pointer to a string containing the name.
WiredHome 0:f782e7bc66ad 86 /// @returns true if the name was set (memory was available).
WiredHome 0:f782e7bc66ad 87 ///
WiredHome 0:f782e7bc66ad 88 bool SetFriendlyName(const char * name);
WiredHome 0:f782e7bc66ad 89
WiredHome 0:f782e7bc66ad 90 /// Delete the friendly name that was assigned.
WiredHome 0:f782e7bc66ad 91 ///
WiredHome 0:f782e7bc66ad 92 /// This frees the memory that was previously allocated.
WiredHome 0:f782e7bc66ad 93 ///
WiredHome 0:f782e7bc66ad 94 void DelFriendlyName();
WiredHome 0:f782e7bc66ad 95
WiredHome 0:f782e7bc66ad 96 /// Set the identity for this node
WiredHome 0:f782e7bc66ad 97 ///
WiredHome 0:f782e7bc66ad 98 /// @param[in] ident is a pointer to a string containing the identity.
WiredHome 0:f782e7bc66ad 99 /// @returns true if the name was set (memory was available).
WiredHome 0:f782e7bc66ad 100 ///
WiredHome 0:f782e7bc66ad 101 bool SetIdentity(const char * ident);
WiredHome 0:f782e7bc66ad 102
WiredHome 0:f782e7bc66ad 103 /// Delete the identity that was assigned.
WiredHome 0:f782e7bc66ad 104 ///
WiredHome 0:f782e7bc66ad 105 /// This frees the memory that was previously allocated.
WiredHome 0:f782e7bc66ad 106 ///
WiredHome 0:f782e7bc66ad 107 void DelIdentity();
WiredHome 0:f782e7bc66ad 108
WiredHome 0:f782e7bc66ad 109 /// Set the IP Address for this node
WiredHome 0:f782e7bc66ad 110 ///
WiredHome 0:f782e7bc66ad 111 /// @param[in] ipAddr is a pointer to a string containing the ipAddress.
WiredHome 0:f782e7bc66ad 112 /// @returns true if the IP Address was set (memory was available).
WiredHome 0:f782e7bc66ad 113 ///
WiredHome 0:f782e7bc66ad 114 bool SetIPAddress(const char * ipAddr);
WiredHome 0:f782e7bc66ad 115
WiredHome 0:f782e7bc66ad 116 /// Delete the friendly IP Address that was assigned.
WiredHome 0:f782e7bc66ad 117 ///
WiredHome 0:f782e7bc66ad 118 /// This frees the memory that was previously allocated.
WiredHome 0:f782e7bc66ad 119 ///
WiredHome 0:f782e7bc66ad 120 void DelIPAddress();
WiredHome 0:f782e7bc66ad 121
WiredHome 0:f782e7bc66ad 122 /// Set the Port
WiredHome 0:f782e7bc66ad 123 ///
WiredHome 0:f782e7bc66ad 124 /// @param[in] port is the port number of the local web server.
WiredHome 0:f782e7bc66ad 125 /// @returns true if the port number was set.
WiredHome 0:f782e7bc66ad 126 ///
WiredHome 0:f782e7bc66ad 127 bool SetPort(int port);
WiredHome 0:f782e7bc66ad 128
WiredHome 0:f782e7bc66ad 129 private:
WiredHome 0:f782e7bc66ad 130
WiredHome 0:f782e7bc66ad 131 void StartListener();
WiredHome 0:f782e7bc66ad 132 void SendNotify();
WiredHome 0:f782e7bc66ad 133
WiredHome 0:f782e7bc66ad 134 SSDP_Config_T _config; ///< the configuration
WiredHome 0:f782e7bc66ad 135
WiredHome 0:f782e7bc66ad 136 Thread * pThr;
WiredHome 0:f782e7bc66ad 137 };