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: mbed-rtos EthernetInterface FatFileSystemCpp MCP23S17 SDFileSystem mbed
Fork of HTTPServerHelloWorld by
Services/Network/EthernetService.cpp@4:a19825caaf41, 2014-02-01 (annotated)
- Committer:
- wyunreal
- Date:
- Sat Feb 01 17:29:15 2014 +0000
- Revision:
- 4:a19825caaf41
- Parent:
- Services/EthernetService.cpp@3:5dc0023e6284
creating the application model
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| wyunreal | 3:5dc0023e6284 | 1 | #include "EthernetService.h" |
| wyunreal | 3:5dc0023e6284 | 2 | |
| wyunreal | 3:5dc0023e6284 | 3 | EthernetService::EthernetService() { |
| wyunreal | 4:a19825caaf41 | 4 | ethernetLink = new Ethernet(); |
| wyunreal | 3:5dc0023e6284 | 5 | ethernetInterface = new EthernetNetIf(); |
| wyunreal | 3:5dc0023e6284 | 6 | ntpClient = new NTPClient(); |
| wyunreal | 4:a19825caaf41 | 7 | linkActive = 0; |
| wyunreal | 4:a19825caaf41 | 8 | needReconnection = 0; |
| wyunreal | 3:5dc0023e6284 | 9 | } |
| wyunreal | 3:5dc0023e6284 | 10 | |
| wyunreal | 3:5dc0023e6284 | 11 | EthernetService::~EthernetService() { |
| wyunreal | 3:5dc0023e6284 | 12 | delete ntpClient; |
| wyunreal | 3:5dc0023e6284 | 13 | delete ethernetInterface; |
| wyunreal | 4:a19825caaf41 | 14 | delete ethernetLink; |
| wyunreal | 3:5dc0023e6284 | 15 | } |
| wyunreal | 3:5dc0023e6284 | 16 | |
| wyunreal | 3:5dc0023e6284 | 17 | int EthernetService::setup() { |
| wyunreal | 3:5dc0023e6284 | 18 | EthernetErr ethErr = ethernetInterface->setup(); |
| wyunreal | 4:a19825caaf41 | 19 | linkActive = ethErr ? 0 : 1; |
| wyunreal | 4:a19825caaf41 | 20 | needReconnection = ! linkActive; |
| wyunreal | 4:a19825caaf41 | 21 | return linkActive; |
| wyunreal | 3:5dc0023e6284 | 22 | } |
| wyunreal | 3:5dc0023e6284 | 23 | |
| wyunreal | 3:5dc0023e6284 | 24 | int EthernetService::setRtcTime() { |
| wyunreal | 3:5dc0023e6284 | 25 | Host server(IpAddr(), 123, "0.es.pool.ntp.org"); |
| wyunreal | 3:5dc0023e6284 | 26 | ntpClient->setTime(server); |
| wyunreal | 3:5dc0023e6284 | 27 | return 1; |
| wyunreal | 4:a19825caaf41 | 28 | } |
| wyunreal | 4:a19825caaf41 | 29 | |
| wyunreal | 4:a19825caaf41 | 30 | void EthernetService::poll() { |
| wyunreal | 4:a19825caaf41 | 31 | linkActive = ethernetLink->link(); |
| wyunreal | 4:a19825caaf41 | 32 | if (linkActive) { |
| wyunreal | 4:a19825caaf41 | 33 | if (!needReconnection) { |
| wyunreal | 4:a19825caaf41 | 34 | Net::poll(); |
| wyunreal | 4:a19825caaf41 | 35 | } |
| wyunreal | 4:a19825caaf41 | 36 | } else { |
| wyunreal | 4:a19825caaf41 | 37 | needReconnection = 1; |
| wyunreal | 4:a19825caaf41 | 38 | } |
| wyunreal | 4:a19825caaf41 | 39 | } |
| wyunreal | 4:a19825caaf41 | 40 | |
| wyunreal | 4:a19825caaf41 | 41 | int EthernetService::isLinkRestored() { |
| wyunreal | 4:a19825caaf41 | 42 | return linkActive && needReconnection; |
| wyunreal | 3:5dc0023e6284 | 43 | } |
