![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
First attempt at some form of autodiscovery of an mbed based device by periodically broadcasting our IP in a UDP packet.
main.cpp@0:c1be031ca851, 2010-06-18 (annotated)
- Committer:
- darran
- Date:
- Fri Jun 18 09:09:57 2010 +0000
- Revision:
- 0:c1be031ca851
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
darran | 0:c1be031ca851 | 1 | /* |
darran | 0:c1be031ca851 | 2 | * Auto Discovery |
darran | 0:c1be031ca851 | 3 | * Broadcasts information about this mbed on port 2010 |
darran | 0:c1be031ca851 | 4 | * Enables other devices on the same network to find it |
darran | 0:c1be031ca851 | 5 | */ |
darran | 0:c1be031ca851 | 6 | |
darran | 0:c1be031ca851 | 7 | #define LWIP_NETIF_HOSTNAME "mbed_dms" |
darran | 0:c1be031ca851 | 8 | |
darran | 0:c1be031ca851 | 9 | #include "mbed.h" |
darran | 0:c1be031ca851 | 10 | #include "EthernetNetIf.h" |
darran | 0:c1be031ca851 | 11 | |
darran | 0:c1be031ca851 | 12 | #include "AutoDiscoveryBroadcaster.h" |
darran | 0:c1be031ca851 | 13 | |
darran | 0:c1be031ca851 | 14 | // Our Ethernet interface |
darran | 0:c1be031ca851 | 15 | EthernetNetIf eth; |
darran | 0:c1be031ca851 | 16 | // Static IP address information |
darran | 0:c1be031ca851 | 17 | /* |
darran | 0:c1be031ca851 | 18 | EthernetNetIf eth( |
darran | 0:c1be031ca851 | 19 | IpAddr(192,168,1,158), //IP Address |
darran | 0:c1be031ca851 | 20 | IpAddr(255,255,255,0), //Network Mask |
darran | 0:c1be031ca851 | 21 | IpAddr(192,168,1,254), //Gateway |
darran | 0:c1be031ca851 | 22 | IpAddr(192,168,1,2) //DNS |
darran | 0:c1be031ca851 | 23 | ); |
darran | 0:c1be031ca851 | 24 | */ |
darran | 0:c1be031ca851 | 25 | // Our AutoDiscoveryBroadcaster server |
darran | 0:c1be031ca851 | 26 | AutoDiscoveryBroadcaster adb; |
darran | 0:c1be031ca851 | 27 | |
darran | 0:c1be031ca851 | 28 | /* |
darran | 0:c1be031ca851 | 29 | Function: main |
darran | 0:c1be031ca851 | 30 | |
darran | 0:c1be031ca851 | 31 | Sets up the Ethernet interface using DHCP, sets |
darran | 0:c1be031ca851 | 32 | up the AutoDiscoveryBroadcaster which then |
darran | 0:c1be031ca851 | 33 | fires out UDP datagrams with info about the mbed |
darran | 0:c1be031ca851 | 34 | */ |
darran | 0:c1be031ca851 | 35 | int main() { |
darran | 0:c1be031ca851 | 36 | |
darran | 0:c1be031ca851 | 37 | printf("\r\nSetting up...\r\n"); |
darran | 0:c1be031ca851 | 38 | EthernetErr ethErr = eth.setup(); |
darran | 0:c1be031ca851 | 39 | if (ethErr) { |
darran | 0:c1be031ca851 | 40 | printf("Error %d in setup on DHCP.\r\n", ethErr); |
darran | 0:c1be031ca851 | 41 | return -1; |
darran | 0:c1be031ca851 | 42 | } |
darran | 0:c1be031ca851 | 43 | printf("Trying to get IP address\r\n"); |
darran | 0:c1be031ca851 | 44 | IpAddr ip = eth.getIp(); |
darran | 0:c1be031ca851 | 45 | printf("mbed IP Address is %d.%d.%d.%d\r\n", ip[0], ip[1], ip[2], ip[3]); |
darran | 0:c1be031ca851 | 46 | |
darran | 0:c1be031ca851 | 47 | adb.start(); |
darran | 0:c1be031ca851 | 48 | |
darran | 0:c1be031ca851 | 49 | printf("Entering while loop Net::poll()ing\r\n"); |
darran | 0:c1be031ca851 | 50 | while (1) { |
darran | 0:c1be031ca851 | 51 | Net::poll(); |
darran | 0:c1be031ca851 | 52 | } |
darran | 0:c1be031ca851 | 53 | } |