Repo. for the ELEC351 Coursework - Oliver Thompson

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

Committer:
O_Thom
Date:
Wed Jan 02 12:12:30 2019 +0000
Revision:
20:2ce28a5032d5
Parent:
19:c3b396b65f2a
Serial Messaging Complete - SD Class need to handle commands. LCD and Networking Time and Date Update Needs Testing.

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 #define WatchDogTimeout 2000
O_Thom 14:dbb0741ce576 5 #define SerialRxFlag 1
O_Thom 6:b7f6e0c0f646 6
O_Thom 19:c3b396b65f2a 7 Thread tLCD, tSAMP, tSERIAL, tSD, tNET;
O_Thom 5:f87129ac8bf3 8
O_Thom 10:08c366434f2b 9 //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 10 //Watchdog_RTOS SerialWatch;
O_Thom 10:08c366434f2b 11 //Watchdog_RTOS SampleWatch;
O_Thom 10:08c366434f2b 12 //Watchdog_RTOS LCDWatch;
O_Thom 10:08c366434f2b 13 //Watchdog_RTOS SDWatch;
O_Thom 10:08c366434f2b 14 //Watchdog_RTOS NetWatch;
O_Thom 10:08c366434f2b 15
O_Thom 20:2ce28a5032d5 16 void LCD_Thread()
O_Thom 20:2ce28a5032d5 17 {
O_Thom 20:2ce28a5032d5 18 vector<int> ErrorCodes;
O_Thom 20:2ce28a5032d5 19 // LCDWatch.kick(WatchDogTimeout);
O_Thom 20:2ce28a5032d5 20 while(1)
O_Thom 20:2ce28a5032d5 21 {
O_Thom 20:2ce28a5032d5 22 // m_oDisplay.LCD_Queue.call_every(1500, LCDWatch.kick);
O_Thom 20:2ce28a5032d5 23 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 20:2ce28a5032d5 24 m_oDisplay.LCD_Queue.call_every(1000, &m_oDisplay, &LCD_Data::getSerial2LCD); //Displays the current sensor information onto the LCD screen every x miliseconds
O_Thom 20:2ce28a5032d5 25 m_oDisplay.LCD_Queue.dispatch(); // Enters WAITING state when blocking
O_Thom 20:2ce28a5032d5 26 ErrorCodes.push_back(ERROR_LCD_EXIT); // Update Error Vector
O_Thom 20:2ce28a5032d5 27 m_oSerial.SERIAL_Queue.call(&m_oSerial, &Serialcomms::updateErrors, ErrorCodes); // Pass error vector to the serial thread
O_Thom 20:2ce28a5032d5 28 }
O_Thom 20:2ce28a5032d5 29 }
O_Thom 20:2ce28a5032d5 30
O_Thom 20:2ce28a5032d5 31 void SAMP_Thread()
O_Thom 20:2ce28a5032d5 32 {
O_Thom 20:2ce28a5032d5 33 vector<int> ErrorCodes;
O_Thom 20:2ce28a5032d5 34 //SamplerWatch.kick(WatchDogTimeout);
O_Thom 20:2ce28a5032d5 35 while(1)
O_Thom 20:2ce28a5032d5 36 {
O_Thom 20:2ce28a5032d5 37 //m_oSample.SAMP_Queue.call_every(1500, SamplerWatch.kick);
O_Thom 20:2ce28a5032d5 38 m_oSample.SAMP_Queue.call_every(500, &m_oSample, &Sampler::publishSample); // Publish sample default (0.5 Second Tp)
O_Thom 20:2ce28a5032d5 39 m_oSample.SAMP_Queue.call_every(500, &m_oSample, &Sampler::getSerial2Sampler); // Start the periodic event to check the serial buffer
O_Thom 20:2ce28a5032d5 40 m_oSample.SAMP_Queue.dispatch(); // Enters WAITING state when blocking
O_Thom 20:2ce28a5032d5 41 ErrorCodes.push_back(ERROR_SAMPLER_EXIT); // Update Error Vector
O_Thom 20:2ce28a5032d5 42 m_oSerial.SERIAL_Queue.call(&m_oSerial, &Serialcomms::updateErrors, ErrorCodes); // Pass error vector to the serial thread
O_Thom 20:2ce28a5032d5 43 }
O_Thom 20:2ce28a5032d5 44 }
O_Thom 20:2ce28a5032d5 45
O_Thom 20:2ce28a5032d5 46 void SERIAL_Thread()
O_Thom 20:2ce28a5032d5 47 {
O_Thom 20:2ce28a5032d5 48 vector<int> ErrorCodes;
O_Thom 20:2ce28a5032d5 49 //SerialWatch.kick(WatchDogTimeout);
O_Thom 20:2ce28a5032d5 50 while(1)
O_Thom 20:2ce28a5032d5 51 {
O_Thom 20:2ce28a5032d5 52 //m_oSerial.SERIAL_Queue.call_every(1500, SerialWatch.kick);
O_Thom 20:2ce28a5032d5 53 m_oSerial.SERIAL_Queue.dispatch(); // Enters WAITING state when blocking
O_Thom 20:2ce28a5032d5 54 ErrorCodes.push_back(ERROR_SERIAL_EXIT); // Update Error Vector
O_Thom 20:2ce28a5032d5 55 }
O_Thom 20:2ce28a5032d5 56 }
O_Thom 10:08c366434f2b 57
O_Thom 10:08c366434f2b 58
O_Thom 20:2ce28a5032d5 59 void Network_Thread()
O_Thom 20:2ce28a5032d5 60 {
O_Thom 20:2ce28a5032d5 61 vector<int> ErrorCodes;
O_Thom 20:2ce28a5032d5 62 while(1)
O_Thom 20:2ce28a5032d5 63 {
O_Thom 20:2ce28a5032d5 64
O_Thom 20:2ce28a5032d5 65 m_oNet.Network_Queue.call_every(5000, &m_oNet, &Network::NetPush);
O_Thom 20:2ce28a5032d5 66 m_oNet.Network_Queue.call_every(1000, &m_oNet, &Network::getSerial2Net); // Poll the mailbox for an update in time and date
O_Thom 20:2ce28a5032d5 67 m_oNet.Network_Queue.dispatch();
O_Thom 20:2ce28a5032d5 68 ErrorCodes.push_back(ERROR_NET_EXIT); // Update Error Vector
O_Thom 20:2ce28a5032d5 69 // m_oNet.Network_Queue.call(&m_oNet, &Network::updateErrors, ErrorCodes); // Pass error vector to the serial thread
O_Thom 20:2ce28a5032d5 70 }
O_Thom 20:2ce28a5032d5 71 }
O_Thom 10:08c366434f2b 72
O_Thom 20:2ce28a5032d5 73 void SD_Thread()
O_Thom 20:2ce28a5032d5 74 {
O_Thom 20:2ce28a5032d5 75 while(1)
O_Thom 20:2ce28a5032d5 76 {
O_Thom 20:2ce28a5032d5 77 m_oSD.SDcard_Queue.call_every(5000, &m_oSD, &SDcard::Save_Data);
O_Thom 20:2ce28a5032d5 78 m_oSD.SDcard_Queue.dispatch();
O_Thom 20:2ce28a5032d5 79 }
O_Thom 20:2ce28a5032d5 80 }
O_Thom 5:f87129ac8bf3 81
O_Thom 20:2ce28a5032d5 82
O_Thom 6:b7f6e0c0f646 83 int main()
O_Thom 6:b7f6e0c0f646 84 {
O_Thom 6:b7f6e0c0f646 85 tLCD.start(LCD_Thread);
O_Thom 6:b7f6e0c0f646 86 tSAMP.start(SAMP_Thread);
O_Thom 6:b7f6e0c0f646 87 tSERIAL.start(SERIAL_Thread);
O_Thom 9:654e14de9d74 88 //tSD.start(SD_Thread);
O_Thom 19:c3b396b65f2a 89 tNET.start(Network_Thread);
O_Thom 6:b7f6e0c0f646 90 Thread::wait(osWaitForever);
O_Thom 6:b7f6e0c0f646 91 }
O_Thom 0:f9a18207d99c 92