reef monitor
Dependencies: mbed-rtos EthernetInterface FatFileSystemCpp MCP23S17 SDFileSystem mbed
Fork of HTTPServerHelloWorld by
Model/Application.cpp@8:3655e9a98f28, 2014-03-02 (annotated)
- Committer:
- wyunreal
- Date:
- Sun Mar 02 12:35:42 2014 +0000
- Revision:
- 8:3655e9a98f28
- Parent:
- 7:1fe91b525d9a
- Child:
- 10:372c882b5533
replacing msc file system by sd file system;
Who changed what in which revision?
User | Revision | Line number | New 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 | 4:a19825caaf41 | 18 | ethernetService = new EthernetService(); |
wyunreal | 4:a19825caaf41 | 19 | if(!ethernetService->setup()) { |
wyunreal | 4:a19825caaf41 | 20 | applicationReset(); |
wyunreal | 4:a19825caaf41 | 21 | } |
wyunreal | 5:df012c2caf40 | 22 | // set the system time from NTP |
wyunreal | 4:a19825caaf41 | 23 | ethernetService->setRtcTime(); |
wyunreal | 5:df012c2caf40 | 24 | |
wyunreal | 5:df012c2caf40 | 25 | // starting the file system |
wyunreal | 6:b2c4687b421d | 26 | localFileSystem = new LocalFileSystem("local"); |
wyunreal | 8:3655e9a98f28 | 27 | sdFileSystem = new SDFileSystem(p5, p6, p7, p8, "sd"); |
wyunreal | 5:df012c2caf40 | 28 | |
wyunreal | 5:df012c2caf40 | 29 | // start the rest api server |
wyunreal | 8:3655e9a98f28 | 30 | restServer = new RestServer(localFileSystem, sdFileSystem); |
wyunreal | 5:df012c2caf40 | 31 | restServer->bind(); |
wyunreal | 7:1fe91b525d9a | 32 | |
wyunreal | 7:1fe91b525d9a | 33 | // enable watchdog timer |
wyunreal | 7:1fe91b525d9a | 34 | watchDog = new WatchDogTimer(WATCH_DOG_TIMER_TRIGGER_TIME); |
wyunreal | 7:1fe91b525d9a | 35 | } |
wyunreal | 7:1fe91b525d9a | 36 | |
wyunreal | 7:1fe91b525d9a | 37 | void Application::handleFaultyResetRecovery() { |
wyunreal | 7:1fe91b525d9a | 38 | |
wyunreal | 4:a19825caaf41 | 39 | } |
wyunreal | 4:a19825caaf41 | 40 | |
wyunreal | 4:a19825caaf41 | 41 | void Application::loop() { |
wyunreal | 4:a19825caaf41 | 42 | |
wyunreal | 4:a19825caaf41 | 43 | } |
wyunreal | 4:a19825caaf41 | 44 | |
wyunreal | 7:1fe91b525d9a | 45 | void Application::run() { |
wyunreal | 7:1fe91b525d9a | 46 | setup(); |
wyunreal | 7:1fe91b525d9a | 47 | while(1) { |
wyunreal | 7:1fe91b525d9a | 48 | loop(); |
wyunreal | 7:1fe91b525d9a | 49 | watchDog->feed(); |
wyunreal | 7:1fe91b525d9a | 50 | ethernetService->poll(); |
wyunreal | 7:1fe91b525d9a | 51 | if (ethernetService->isLinkRestored()) { |
wyunreal | 7:1fe91b525d9a | 52 | // if ethernet link is restored, application needs to be restarted |
wyunreal | 7:1fe91b525d9a | 53 | applicationReset(); |
wyunreal | 7:1fe91b525d9a | 54 | } |
wyunreal | 7:1fe91b525d9a | 55 | watchDog->feed(); |
wyunreal | 7:1fe91b525d9a | 56 | } |
wyunreal | 7:1fe91b525d9a | 57 | } |
wyunreal | 7:1fe91b525d9a | 58 | |
wyunreal | 4:a19825caaf41 | 59 | void Application::applicationReset() { |
wyunreal | 4:a19825caaf41 | 60 | wait(5); |
wyunreal | 4:a19825caaf41 | 61 | mbed_reset(); |
wyunreal | 4:a19825caaf41 | 62 | } |
wyunreal | 4:a19825caaf41 | 63 | |
wyunreal | 4:a19825caaf41 | 64 | Application::~Application() { |
wyunreal | 4:a19825caaf41 | 65 | delete ethernetService; |
wyunreal | 4:a19825caaf41 | 66 | } |