Repo. for the ELEC351 Coursework - Oliver Thompson

Dependencies:   BMP280 ELEC350-Practicals-FZ429- TextLCD watchdog_RTOS BME280 ntp-client

Committer:
O_Thom
Date:
Tue Dec 04 15:26:46 2018 +0000
Revision:
10:08c366434f2b
Parent:
9:654e14de9d74
Child:
12:88d33b87ecb2
Serial Callbacks Included. Changing classes to access each others member functions without the use of objects.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
O_Thom 5:f87129ac8bf3 1 #include "mbed.h"
O_Thom 0:f9a18207d99c 2 #include "sample_hardware.hpp"
O_Thom 0:f9a18207d99c 3 #include "Sampler.hpp"
O_Thom 10:08c366434f2b 4 //#include <watchdog_RTOS.h>
O_Thom 10:08c366434f2b 5 #define WatchDogTimeout 2000
O_Thom 6:b7f6e0c0f646 6
O_Thom 6:b7f6e0c0f646 7 void LCD_Thread(void);
O_Thom 6:b7f6e0c0f646 8 void SAMP_Thread(void);
O_Thom 6:b7f6e0c0f646 9 void SERIAL_Thread(void);
O_Thom 6:b7f6e0c0f646 10
O_Thom 6:b7f6e0c0f646 11 Thread tLCD, tSAMP, tSERIAL, tSD;
O_Thom 5:f87129ac8bf3 12
O_Thom 10:08c366434f2b 13 //Watchdog Initialisation - Implement Custom to only reset the thread which is faulty. Include a top level Watchdog to reset everything in Main
O_Thom 10:08c366434f2b 14 //Watchdog_RTOS SerialWatch;
O_Thom 10:08c366434f2b 15 //Watchdog_RTOS SampleWatch;
O_Thom 10:08c366434f2b 16 //Watchdog_RTOS LCDWatch;
O_Thom 10:08c366434f2b 17 //Watchdog_RTOS SDWatch;
O_Thom 10:08c366434f2b 18 //Watchdog_RTOS NetWatch;
O_Thom 10:08c366434f2b 19
O_Thom 10:08c366434f2b 20
O_Thom 10:08c366434f2b 21
O_Thom 6:b7f6e0c0f646 22 // Define member object
O_Thom 10:08c366434f2b 23 Sampler m_oSample;
O_Thom 10:08c366434f2b 24 // LCD Defined in Cpp due to use in Sampler.hpp
O_Thom 10:08c366434f2b 25
O_Thom 5:f87129ac8bf3 26
O_Thom 6:b7f6e0c0f646 27 int main()
O_Thom 6:b7f6e0c0f646 28 {
O_Thom 6:b7f6e0c0f646 29 tLCD.start(LCD_Thread);
O_Thom 6:b7f6e0c0f646 30 tSAMP.start(SAMP_Thread);
O_Thom 6:b7f6e0c0f646 31 tSERIAL.start(SERIAL_Thread);
O_Thom 9:654e14de9d74 32 //tSD.start(SD_Thread);
O_Thom 6:b7f6e0c0f646 33 Thread::wait(osWaitForever);
O_Thom 6:b7f6e0c0f646 34 }
O_Thom 0:f9a18207d99c 35
O_Thom 6:b7f6e0c0f646 36 void LCD_Thread()
O_Thom 6:b7f6e0c0f646 37 {
O_Thom 9:654e14de9d74 38 vector<int> ErrorCodes;
O_Thom 10:08c366434f2b 39 // LCDWatch.kick(WatchDogTimeout);
O_Thom 6:b7f6e0c0f646 40 while(1)
O_Thom 6:b7f6e0c0f646 41 {
O_Thom 10:08c366434f2b 42 // m_oDisplay.LCD_Queue.call_every(1500, LCDWatch.kick);
O_Thom 9:654e14de9d74 43 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
O_Thom 9:654e14de9d74 44 m_oDisplay.LCD_Queue.dispatch(); // Enters WAITING state when blocking
O_Thom 9:654e14de9d74 45 ErrorCodes.push_back(ERROR_LCD_EXIT); // Update Error Vector
O_Thom 9:654e14de9d74 46 m_oSerial.SERIAL_Queue.call(&m_oSerial, &Serialcomms::updateErrors, ErrorCodes); // Pass error vector to the serial thread
O_Thom 6:b7f6e0c0f646 47 }
O_Thom 6:b7f6e0c0f646 48 }
O_Thom 0:f9a18207d99c 49
O_Thom 6:b7f6e0c0f646 50 void SAMP_Thread()
O_Thom 9:654e14de9d74 51 {
O_Thom 9:654e14de9d74 52 vector<int> ErrorCodes;
O_Thom 10:08c366434f2b 53 // SamplerWatch.kick(WatchDogTimeout);
O_Thom 10:08c366434f2b 54
O_Thom 6:b7f6e0c0f646 55 while(1)
O_Thom 6:b7f6e0c0f646 56 {
O_Thom 10:08c366434f2b 57 // m_oSample.SAMP_Queue.call_every(1500, SamplerWatch.kick);
O_Thom 9:654e14de9d74 58 m_oSample.SAMP_Queue.call_every(500, &m_oSample, &Sampler::publishSample); // Publish sample
O_Thom 9:654e14de9d74 59 m_oSample.SAMP_Queue.dispatch(); // Enters WAITING state when blocking
O_Thom 9:654e14de9d74 60 ErrorCodes.push_back(ERROR_SAMPLER_EXIT); // Update Error Vector
O_Thom 9:654e14de9d74 61 m_oSerial.SERIAL_Queue.call(&m_oSerial, &Serialcomms::updateErrors, ErrorCodes); // Pass error vector to the serial thread
O_Thom 10:08c366434f2b 62
O_Thom 6:b7f6e0c0f646 63 }
O_Thom 6:b7f6e0c0f646 64 }
O_Thom 6:b7f6e0c0f646 65
O_Thom 6:b7f6e0c0f646 66 void SERIAL_Thread()
O_Thom 0:f9a18207d99c 67 {
O_Thom 9:654e14de9d74 68 vector<int> ErrorCodes;
O_Thom 10:08c366434f2b 69 // SerialWatch.kick(WatchDogTimeout);
O_Thom 9:654e14de9d74 70 while(1)
O_Thom 6:b7f6e0c0f646 71 {
O_Thom 10:08c366434f2b 72 //m_oSerial.SERIAL_Queue.call_every(1500, SerialWatch.kick);
O_Thom 10:08c366434f2b 73 //m_oSerial.SERIAL_Queue.call_every(1000, &m_oSerial, &Serialcomms::updateTerminal); // Publish sample
O_Thom 9:654e14de9d74 74 m_oSerial.SERIAL_Queue.dispatch(); // Enters WAITING state when blocking
O_Thom 9:654e14de9d74 75 ErrorCodes.push_back(ERROR_SERIAL_EXIT); // Update Error Vector
O_Thom 10:08c366434f2b 76
O_Thom 6:b7f6e0c0f646 77 }
O_Thom 0:f9a18207d99c 78 }
O_Thom 6:b7f6e0c0f646 79