Wiljan Arias / WhexReefMonitor

Dependencies:   mbed-rtos EthernetInterface FatFileSystemCpp MCP23S17 SDFileSystem mbed

Fork of HTTPServerHelloWorld by Donatien Garnier

Revision:
4:a19825caaf41
Parent:
3:5dc0023e6284
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Services/Network/EthernetService.cpp	Sat Feb 01 17:29:15 2014 +0000
@@ -0,0 +1,43 @@
+#include "EthernetService.h"
+
+EthernetService::EthernetService() {
+      ethernetLink = new Ethernet();
+      ethernetInterface = new EthernetNetIf();
+      ntpClient = new NTPClient();
+      linkActive = 0;
+      needReconnection = 0;
+}
+
+EthernetService::~EthernetService() {
+    delete ntpClient;
+    delete ethernetInterface;
+    delete ethernetLink;
+}
+
+int EthernetService::setup() {
+    EthernetErr ethErr = ethernetInterface->setup();
+    linkActive = ethErr ? 0 : 1;
+    needReconnection = ! linkActive;
+    return linkActive;
+}
+
+int EthernetService::setRtcTime() {
+    Host server(IpAddr(), 123, "0.es.pool.ntp.org"); 
+    ntpClient->setTime(server);
+    return 1;
+}
+
+void EthernetService::poll() {
+    linkActive = ethernetLink->link();
+    if (linkActive) {
+        if (!needReconnection) {
+            Net::poll();
+        }
+    } else {
+        needReconnection = 1;
+    }
+}
+
+int EthernetService::isLinkRestored() {
+    return linkActive && needReconnection;
+}
\ No newline at end of file