reef monitor

Dependencies:   mbed-rtos EthernetInterface FatFileSystemCpp MCP23S17 SDFileSystem mbed

Fork of HTTPServerHelloWorld by Donatien Garnier

Committer:
wyunreal
Date:
Sat Jan 03 17:50:52 2015 +0000
Revision:
12:72e0c404017a
Parent:
11:9366140ebe5f
draft of file request handler;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wyunreal 4:a19825caaf41 1 #include "Application.h"
wyunreal 4:a19825caaf41 2
wyunreal 7:1fe91b525d9a 3 #define WATCH_DOG_TIMER_TRIGGER_TIME 5 //seconds
wyunreal 7:1fe91b525d9a 4
wyunreal 4:a19825caaf41 5 extern "C" void mbed_reset();
wyunreal 4:a19825caaf41 6
wyunreal 4:a19825caaf41 7 Application::Application() {
wyunreal 4:a19825caaf41 8 }
wyunreal 4:a19825caaf41 9
wyunreal 7:1fe91b525d9a 10 void Application::setup() {
wyunreal 7:1fe91b525d9a 11
wyunreal 7:1fe91b525d9a 12 // WatchDog reset ?
wyunreal 7:1fe91b525d9a 13 if (WatchDogTimer::systemResetReason() == SYSTEM_RESET_WATCH_DOG) {
wyunreal 7:1fe91b525d9a 14 handleFaultyResetRecovery();
wyunreal 4:a19825caaf41 15 }
wyunreal 7:1fe91b525d9a 16
wyunreal 5:df012c2caf40 17 // setup ethernet
wyunreal 11:9366140ebe5f 18
wyunreal 5:df012c2caf40 19
wyunreal 10:372c882b5533 20 // start spi
wyunreal 10:372c882b5533 21 spiHandler = new SPI(p5, p6, p7);
wyunreal 10:372c882b5533 22 spiHandler->frequency(100000); // 100 khz for slow periperals intialization
wyunreal 10:372c882b5533 23
wyunreal 10:372c882b5533 24 // starting the file systems
wyunreal 6:b2c4687b421d 25 localFileSystem = new LocalFileSystem("local");
wyunreal 10:372c882b5533 26 sdFileSystem = new SDFileSystem(spiHandler, p8, "sd");
wyunreal 10:372c882b5533 27
wyunreal 11:9366140ebe5f 28 spiHandler->frequency(16000000); // 4 Mhz spi normal operation frequency
wyunreal 10:372c882b5533 29
wyunreal 11:9366140ebe5f 30 // start the http api server
wyunreal 11:9366140ebe5f 31 httpServer = new HttpServer();
wyunreal 11:9366140ebe5f 32 httpServer->start();
wyunreal 7:1fe91b525d9a 33
wyunreal 7:1fe91b525d9a 34 // enable watchdog timer
wyunreal 7:1fe91b525d9a 35 watchDog = new WatchDogTimer(WATCH_DOG_TIMER_TRIGGER_TIME);
wyunreal 7:1fe91b525d9a 36 }
wyunreal 7:1fe91b525d9a 37
wyunreal 7:1fe91b525d9a 38 void Application::handleFaultyResetRecovery() {
wyunreal 7:1fe91b525d9a 39
wyunreal 4:a19825caaf41 40 }
wyunreal 4:a19825caaf41 41
wyunreal 4:a19825caaf41 42 void Application::loop() {
wyunreal 4:a19825caaf41 43
wyunreal 4:a19825caaf41 44 }
wyunreal 4:a19825caaf41 45
wyunreal 7:1fe91b525d9a 46 void Application::run() {
wyunreal 7:1fe91b525d9a 47 setup();
wyunreal 7:1fe91b525d9a 48 while(1) {
wyunreal 7:1fe91b525d9a 49 watchDog->feed();
wyunreal 11:9366140ebe5f 50 if (!isSystemOnline()) {
wyunreal 11:9366140ebe5f 51 recoverSystem();
wyunreal 7:1fe91b525d9a 52 }
wyunreal 7:1fe91b525d9a 53 watchDog->feed();
wyunreal 11:9366140ebe5f 54 loop();
wyunreal 11:9366140ebe5f 55 Thread::wait(100);
wyunreal 7:1fe91b525d9a 56 }
wyunreal 7:1fe91b525d9a 57 }
wyunreal 7:1fe91b525d9a 58
wyunreal 11:9366140ebe5f 59 int Application::isSystemOnline() {
wyunreal 11:9366140ebe5f 60 return httpServer->isAlive();
wyunreal 11:9366140ebe5f 61 }
wyunreal 11:9366140ebe5f 62
wyunreal 11:9366140ebe5f 63 void Application::recoverSystem() {
wyunreal 11:9366140ebe5f 64 httpServer->restart();
wyunreal 11:9366140ebe5f 65 }
wyunreal 11:9366140ebe5f 66
wyunreal 4:a19825caaf41 67 void Application::applicationReset() {
wyunreal 4:a19825caaf41 68 wait(5);
wyunreal 4:a19825caaf41 69 mbed_reset();
wyunreal 4:a19825caaf41 70 }
wyunreal 4:a19825caaf41 71
wyunreal 4:a19825caaf41 72 Application::~Application() {
wyunreal 11:9366140ebe5f 73
wyunreal 4:a19825caaf41 74 }