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: Socket lwip-eth lwip-sys lwip
Dependents: CI-data-logger-server
Fork of EthernetInterface by
Revision 27:2124eae946f3, committed 2013-03-01
- Comitter:
- emilmont
- Date:
- Fri Mar 01 15:33:02 2013 +0000
- Parent:
- 26:dd9794ce1d64
- Child:
- 28:9b2d10dc0392
- Commit message:
- Update lwIP and socket libraries.; Add "getMACAddress".
Changed in this revision
--- a/EthernetInterface.cpp Fri Feb 15 17:01:20 2013 +0000
+++ b/EthernetInterface.cpp Fri Mar 01 15:33:02 2013 +0000
@@ -31,7 +31,8 @@
/* TCP/IP and Network Interface Initialisation */
static struct netif lpcNetif;
-static char ip_addr[16] = "\0";
+static char mac_addr[19];
+static char ip_addr[17] = "\0";
static bool use_dhcp = false;
static Semaphore tcpip_inited(0);
@@ -67,14 +68,23 @@
netif_set_status_callback(&lpcNetif, netif_status_callback);
}
+static void set_mac_address(void) {
+ char mac[6];
+ mbed_mac_address(mac);
+ snprintf(mac_addr, 19, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+}
+
int EthernetInterface::init() {
use_dhcp = true;
+ set_mac_address();
init_netif(NULL, NULL, NULL);
return 0;
}
int EthernetInterface::init(const char* ip, const char* mask, const char* gateway) {
use_dhcp = false;
+
+ set_mac_address();
strcpy(ip_addr, ip);
ip_addr_t ip_n, mask_n, gateway_n;
@@ -94,7 +104,7 @@
if (use_dhcp) {
dhcp_start(&lpcNetif);
- // Wait for an IP
+ // Wait for an IP Address
// -1: error, 0: timeout
inited = netif_up.wait(timeout_ms);
} else {
@@ -120,6 +130,10 @@
return 0;
}
+char* EthernetInterface::getMACAddress() {
+ return mac_addr;
+}
+
char* EthernetInterface::getIPAddress() {
return ip_addr;
}
--- a/EthernetInterface.h Fri Feb 15 17:01:20 2013 +0000 +++ b/EthernetInterface.h Fri Mar 01 15:33:02 2013 +0000 @@ -49,10 +49,10 @@ /** Connect * Bring the interface up, start DHCP if needed. - * \param timeout_ms timeout in ms (default: (12)s). + * \param timeout_ms timeout in ms (default: (10)s). * \return 0 on success, a negative number on failure */ - static int connect(unsigned int timeout_ms=12000); + static int connect(unsigned int timeout_ms=15000); /** Disconnect * Bring the interface down @@ -60,6 +60,14 @@ */ static int disconnect(); + /** Get the MAC address of your Ethernet interface + * \return a pointer to a string containing the MAC address + */ + static char* getMACAddress(); + + /** Get the IP address of your Ethernet interface + * \return a pointer to a string containing the IP address + */ static char* getIPAddress(); };
--- a/Socket.lib Fri Feb 15 17:01:20 2013 +0000 +++ b/Socket.lib Fri Mar 01 15:33:02 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/Socket/#41e3af01f58e +http://mbed.org/users/mbed_official/code/Socket/#2d471deff212
--- a/lwip-eth.lib Fri Feb 15 17:01:20 2013 +0000 +++ b/lwip-eth.lib Fri Mar 01 15:33:02 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/lwip-eth/#dd8b8f5b449a +http://mbed.org/users/mbed_official/code/lwip-eth/#d827a085afd9
--- a/lwip-sys.lib Fri Feb 15 17:01:20 2013 +0000 +++ b/lwip-sys.lib Fri Mar 01 15:33:02 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/lwip-sys/#b409691fb352 +http://mbed.org/users/mbed_official/code/lwip-sys/#742ae4a0ca3f
--- a/lwip.lib Fri Feb 15 17:01:20 2013 +0000 +++ b/lwip.lib Fri Mar 01 15:33:02 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/lwip/#b061c4dba951 +http://mbed.org/users/mbed_official/code/lwip/#f9d0ac9dd036
