Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DebugLib Socket lwip lwip-sys
Fork of NetworkingCoreLib by
Revision 10:14ef6ceb4e75, committed 2012-06-20
- Comitter:
- donatien
- Date:
- Wed Jun 20 13:14:57 2012 +0000
- Parent:
- 8:387f573a6813
- Child:
- 11:9952709b2ee3
- Commit message:
- Blocking connect() and disconnect() functions, recovery of interface state & IP address
Changed in this revision
--- a/main/if/IPInterface.cpp Fri Jun 15 14:17:23 2012 +0000
+++ b/main/if/IPInterface.cpp Wed Jun 20 13:14:57 2012 +0000
@@ -25,6 +25,8 @@
#include "IPInterface.h"
+#include <cstring> //For strcpy
+
IPInterface::IPInterface()
{
@@ -52,3 +54,32 @@
}
/*static*/ IPInterface* IPInterface::s_pDefaultInterface = NULL;
+
+
+char* IPInterface::getIPAddress() //Get IP Address as a string ('a.b.c.d')
+{
+ if(isConnected())
+ {
+ return m_ipAddr;
+ }
+ else
+ {
+ return NULL;
+ }
+}
+
+bool IPInterface::isConnected() //Is the interface connected?
+{
+ return m_connected;
+}
+
+void IPInterface::setIPAddress(char* ipAddr)
+{
+ std::strcpy(m_ipAddr, ipAddr); //Let's trust the derived class not to buffer overflow us
+}
+
+void IPInterface::setConnected(bool connected)
+{
+ m_connected = connected;
+}
+
--- a/main/if/IPInterface.h Fri Jun 15 14:17:23 2012 +0000
+++ b/main/if/IPInterface.h Wed Jun 20 13:14:57 2012 +0000
@@ -36,9 +36,12 @@
virtual ~IPInterface();
//int init(); //Initialize interface; no connection should be performed at this stage
- //int connect(); //Do connect the interface
- //int disconnect();
+ virtual int connect() = 0; //Do connect the interface
+ virtual int disconnect() = 0;
//It is encouraged that the derived class implement a "setup(...)" function to configure the interface before the connection
+
+ char* getIPAddress(); //Get IP Address as a string ('a.b.c.d')
+ bool isConnected(); //Is the interface connected?
static IPInterface* getDefaultInterface(); //For use by TCP, UDP sockets library
@@ -46,7 +49,15 @@
void registerAsDefaultInterface(); //First come, first served
void unregisterAsDefaultInterface(); //Must be called before inst is destroyed to avoid invalid ptr fault
+protected:
+ //Must be called by subclasses
+ void setIPAddress(char* ipAddr);
+ void setConnected(bool connected);
+
private:
+ char m_ipAddr[16];
+ bool m_connected;
+
static IPInterface* s_pDefaultInterface;
};
--- a/main/if/LwIPInterface.h Fri Jun 15 14:17:23 2012 +0000
+++ b/main/if/LwIPInterface.h Wed Jun 20 13:14:57 2012 +0000
@@ -39,7 +39,7 @@
virtual ~LwIPInterface();
int init(); //Init LwIP-specific stuff, create the right bindings, etc
-
+
private:
static void tcpipRdyCb(void* ctx); //Result of TCP/IP thread launch
Semaphore m_rdySphre;
