reef monitor
Dependencies: mbed-rtos EthernetInterface FatFileSystemCpp MCP23S17 SDFileSystem mbed
Fork of HTTPServerHelloWorld by
Diff: Model/Application.cpp
- Revision:
- 11:9366140ebe5f
- Parent:
- 10:372c882b5533
--- a/Model/Application.cpp Sun Mar 02 18:15:47 2014 +0000 +++ b/Model/Application.cpp Fri Jan 02 22:44:42 2015 +0000 @@ -15,12 +15,7 @@ } // setup ethernet - ethernetService = new EthernetService(); - if(!ethernetService->setup()) { - applicationReset(); - } - // set the system time from NTP - ethernetService->setRtcTime(); + // start spi spiHandler = new SPI(p5, p6, p7); @@ -30,14 +25,11 @@ localFileSystem = new LocalFileSystem("local"); sdFileSystem = new SDFileSystem(spiHandler, p8, "sd"); - // starting the external actuators control group - actuatorsController = new ActuatorsController(spiHandler); + spiHandler->frequency(16000000); // 4 Mhz spi normal operation frequency - spiHandler->frequency(4000000); // 4 Mhz spi normal operation frequency - - // start the rest api server - restServer = new RestServer(localFileSystem, sdFileSystem); - restServer->bind(); + // start the http api server + httpServer = new HttpServer(); + httpServer->start(); // enable watchdog timer watchDog = new WatchDogTimer(WATCH_DOG_TIMER_TRIGGER_TIME); @@ -54,22 +46,29 @@ void Application::run() { setup(); while(1) { - loop(); watchDog->feed(); - ethernetService->poll(); - if (ethernetService->isLinkRestored()) { - // if ethernet link is restored, application needs to be restarted - applicationReset(); + if (!isSystemOnline()) { + recoverSystem(); } watchDog->feed(); + loop(); + Thread::wait(100); } } +int Application::isSystemOnline() { + return httpServer->isAlive(); +} + +void Application::recoverSystem() { + httpServer->restart(); +} + void Application::applicationReset() { wait(5); mbed_reset(); } Application::~Application() { - delete ethernetService; + } \ No newline at end of file