reef monitor
Dependencies: mbed-rtos EthernetInterface FatFileSystemCpp MCP23S17 SDFileSystem mbed
Fork of HTTPServerHelloWorld by
Model/Application.cpp
- Committer:
- wyunreal
- Date:
- 2014-03-02
- Revision:
- 10:372c882b5533
- Parent:
- 8:3655e9a98f28
- Child:
- 11:9366140ebe5f
File content as of revision 10:372c882b5533:
#include "Application.h" #define WATCH_DOG_TIMER_TRIGGER_TIME 5 //seconds extern "C" void mbed_reset(); Application::Application() { } void Application::setup() { // WatchDog reset ? if (WatchDogTimer::systemResetReason() == SYSTEM_RESET_WATCH_DOG) { handleFaultyResetRecovery(); } // 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); spiHandler->frequency(100000); // 100 khz for slow periperals intialization // starting the file systems localFileSystem = new LocalFileSystem("local"); sdFileSystem = new SDFileSystem(spiHandler, p8, "sd"); // starting the external actuators control group actuatorsController = new ActuatorsController(spiHandler); spiHandler->frequency(4000000); // 4 Mhz spi normal operation frequency // start the rest api server restServer = new RestServer(localFileSystem, sdFileSystem); restServer->bind(); // enable watchdog timer watchDog = new WatchDogTimer(WATCH_DOG_TIMER_TRIGGER_TIME); } void Application::handleFaultyResetRecovery() { } void Application::loop() { } 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(); } watchDog->feed(); } } void Application::applicationReset() { wait(5); mbed_reset(); } Application::~Application() { delete ethernetService; }