Wiljan Arias / WhexReefMonitor

Dependencies:   mbed-rtos EthernetInterface FatFileSystemCpp MCP23S17 SDFileSystem mbed

Fork of HTTPServerHelloWorld by Donatien Garnier

Model/Application.cpp

Committer:
wyunreal
Date:
2014-02-02
Revision:
6:b2c4687b421d
Parent:
5:df012c2caf40
Child:
7:1fe91b525d9a

File content as of revision 6:b2c4687b421d:

#include "Application.h"

extern "C" void mbed_reset();

Application::Application() {
}

void Application::run() {
    setup();
    while(1) {
        loop();
        ethernetService->poll();
        if (ethernetService->isLinkRestored()) {
            // if ethernet link is restored, application needs to be restarted
            applicationReset();
        }
    }
}

void Application::setup() {
    // setup ethernet
    ethernetService = new EthernetService();
    if(!ethernetService->setup()) {
        applicationReset();
    }
    // set the system time from NTP
    ethernetService->setRtcTime();
    
    // starting the file system
    localFileSystem = new LocalFileSystem("local");
    mscFileSystem = new MSCFileSystem("msc");
    
    // start the rest api server
    restServer = new RestServer(localFileSystem, mscFileSystem);
    restServer->bind();
}

void Application::loop() {
    
}

void Application::applicationReset() {
    wait(5);
    mbed_reset();    
}

Application::~Application() {
    delete ethernetService;
}