Repo. for the ELEC351 Coursework - Oliver Thompson
Dependencies: BMP280 ELEC350-Practicals-FZ429- TextLCD watchdog_RTOS BME280 ntp-client
main.cpp
- Committer:
- O_Thom
- Date:
- 2018-12-13
- Revision:
- 19:c3b396b65f2a
- Parent:
- 18:a036c2e5ff89
- Child:
- 20:2ce28a5032d5
File content as of revision 19:c3b396b65f2a:
#include "mbed.h" #include "sample_hardware.hpp" #include "Sampler.hpp" //#include <watchdog_RTOS.h> #define WatchDogTimeout 2000 #define SerialRxFlag 1 void LCD_Thread(void); void SAMP_Thread(void); void SERIAL_Thread(void); void SERIAL_IRQ(void); void Network_Thread(void); Thread tLCD, tSAMP, tSERIAL, tSD, tNET; //Watchdog Initialisation - Implement Custom to only reset the thread which is faulty. Include a top level Watchdog to reset everything in Main //Watchdog_RTOS SerialWatch; //Watchdog_RTOS SampleWatch; //Watchdog_RTOS LCDWatch; //Watchdog_RTOS SDWatch; //Watchdog_RTOS NetWatch; Serial m_oSerial(m_oSampler); // Pass a reference to the Sampler object // Define member object // LCD Defined in Cpp due to use in Sampler.hpp int main() { tLCD.start(LCD_Thread); tSAMP.start(SAMP_Thread); tSERIAL.start(SERIAL_Thread); //tSD.start(SD_Thread); tNET.start(Network_Thread); Thread::wait(osWaitForever); } void LCD_Thread() { vector<int> ErrorCodes; // LCDWatch.kick(WatchDogTimeout); while(1) { // m_oDisplay.LCD_Queue.call_every(1500, LCDWatch.kick); m_oDisplay.LCD_Queue.call_every(1000, &m_oDisplay, &LCD_Data::display_LCD); //Displays the current sensor information onto the LCD screen every x miliseconds m_oDisplay.LCD_Queue.dispatch(); // Enters WAITING state when blocking ErrorCodes.push_back(ERROR_LCD_EXIT); // Update Error Vector m_oSerial.SERIAL_Queue.call(&m_oSerial, &Serialcomms::updateErrors, ErrorCodes); // Pass error vector to the serial thread } } void SAMP_Thread() { vector<int> ErrorCodes; // SamplerWatch.kick(WatchDogTimeout); while(1) { // m_oSample.SAMP_Queue.call_every(1500, SamplerWatch.kick); m_oSample.SAMP_Queue.call_every(500, &m_oSample, &Sampler::publishSample); // Publish sample m_oSample.SAMP_Queue.dispatch(); // Enters WAITING state when blocking ErrorCodes.push_back(ERROR_SAMPLER_EXIT); // Update Error Vector m_oSerial.SERIAL_Queue.call(&m_oSerial, &Serialcomms::updateErrors, ErrorCodes); // Pass error vector to the serial thread } } void SERIAL_Thread() { vector<int> ErrorCodes; // SerialWatch.kick(WatchDogTimeout); while(1) { //m_oSerial.SERIAL_Queue.call_every(1500, SerialWatch.kick); m_oSerial.SERIAL_Queue.dispatch(); // Enters WAITING state when blocking ErrorCodes.push_back(ERROR_SERIAL_EXIT); // Update Error Vector } } void Network_Thread() { while(1) { m_oNet.Network_Queue.call_every(10, &m_oNet, &Network::NetPush); m_oNet.Network_Queue.dispatch(); while(true) { // Flash if the event queue is exited. greenLED = 1; wait(0.5); greenLED = 0; wait(0.1); } } }