Wiljan Arias / WhexReefMonitor

Dependencies:   mbed-rtos EthernetInterface FatFileSystemCpp MCP23S17 SDFileSystem mbed

Fork of HTTPServerHelloWorld by Donatien Garnier

Committer:
wyunreal
Date:
Sat Feb 01 18:54:20 2014 +0000
Revision:
5:df012c2caf40
Parent:
4:a19825caaf41
Adding a FS handler to the webserver and mounting it to the local file system

Who changed what in which revision?

UserRevisionLine numberNew 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 }