Repo. for the ELEC351 Coursework - Oliver Thompson
Dependencies: BMP280 ELEC350-Practicals-FZ429- TextLCD watchdog_RTOS BME280 ntp-client
main.cpp@19:c3b396b65f2a, 2018-12-13 (annotated)
- Committer:
- O_Thom
- Date:
- Thu Dec 13 16:09:54 2018 +0000
- Revision:
- 19:c3b396b65f2a
- Parent:
- 18:a036c2e5ff89
- Child:
- 20:2ce28a5032d5
Post merge commit
Who changed what in which revision?
User | Revision | Line number | New 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 | 14:dbb0741ce576 | 6 | #define SerialRxFlag 1 |
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 | 14:dbb0741ce576 | 10 | void SERIAL_IRQ(void); |
O_Thom | 19:c3b396b65f2a | 11 | void Network_Thread(void); |
O_Thom | 6:b7f6e0c0f646 | 12 | |
O_Thom | 19:c3b396b65f2a | 13 | Thread tLCD, tSAMP, tSERIAL, tSD, tNET; |
O_Thom | 5:f87129ac8bf3 | 14 | |
O_Thom | 10:08c366434f2b | 15 | //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 | 16 | //Watchdog_RTOS SerialWatch; |
O_Thom | 10:08c366434f2b | 17 | //Watchdog_RTOS SampleWatch; |
O_Thom | 10:08c366434f2b | 18 | //Watchdog_RTOS LCDWatch; |
O_Thom | 10:08c366434f2b | 19 | //Watchdog_RTOS SDWatch; |
O_Thom | 10:08c366434f2b | 20 | //Watchdog_RTOS NetWatch; |
O_Thom | 10:08c366434f2b | 21 | |
O_Thom | 18:a036c2e5ff89 | 22 | Serial m_oSerial(m_oSampler); // Pass a reference to the Sampler object |
O_Thom | 10:08c366434f2b | 23 | |
O_Thom | 10:08c366434f2b | 24 | |
O_Thom | 6:b7f6e0c0f646 | 25 | // Define member object |
O_Thom | 10:08c366434f2b | 26 | // LCD Defined in Cpp due to use in Sampler.hpp |
O_Thom | 10:08c366434f2b | 27 | |
O_Thom | 5:f87129ac8bf3 | 28 | |
O_Thom | 6:b7f6e0c0f646 | 29 | int main() |
O_Thom | 6:b7f6e0c0f646 | 30 | { |
O_Thom | 6:b7f6e0c0f646 | 31 | tLCD.start(LCD_Thread); |
O_Thom | 6:b7f6e0c0f646 | 32 | tSAMP.start(SAMP_Thread); |
O_Thom | 6:b7f6e0c0f646 | 33 | tSERIAL.start(SERIAL_Thread); |
O_Thom | 9:654e14de9d74 | 34 | //tSD.start(SD_Thread); |
O_Thom | 19:c3b396b65f2a | 35 | tNET.start(Network_Thread); |
O_Thom | 6:b7f6e0c0f646 | 36 | Thread::wait(osWaitForever); |
O_Thom | 6:b7f6e0c0f646 | 37 | } |
O_Thom | 0:f9a18207d99c | 38 | |
O_Thom | 6:b7f6e0c0f646 | 39 | void LCD_Thread() |
O_Thom | 6:b7f6e0c0f646 | 40 | { |
O_Thom | 9:654e14de9d74 | 41 | vector<int> ErrorCodes; |
O_Thom | 10:08c366434f2b | 42 | // LCDWatch.kick(WatchDogTimeout); |
O_Thom | 6:b7f6e0c0f646 | 43 | while(1) |
O_Thom | 6:b7f6e0c0f646 | 44 | { |
O_Thom | 10:08c366434f2b | 45 | // m_oDisplay.LCD_Queue.call_every(1500, LCDWatch.kick); |
O_Thom | 9:654e14de9d74 | 46 | 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 | 47 | m_oDisplay.LCD_Queue.dispatch(); // Enters WAITING state when blocking |
O_Thom | 9:654e14de9d74 | 48 | ErrorCodes.push_back(ERROR_LCD_EXIT); // Update Error Vector |
O_Thom | 9:654e14de9d74 | 49 | m_oSerial.SERIAL_Queue.call(&m_oSerial, &Serialcomms::updateErrors, ErrorCodes); // Pass error vector to the serial thread |
O_Thom | 6:b7f6e0c0f646 | 50 | } |
O_Thom | 6:b7f6e0c0f646 | 51 | } |
O_Thom | 0:f9a18207d99c | 52 | |
O_Thom | 6:b7f6e0c0f646 | 53 | void SAMP_Thread() |
O_Thom | 9:654e14de9d74 | 54 | { |
O_Thom | 9:654e14de9d74 | 55 | vector<int> ErrorCodes; |
O_Thom | 10:08c366434f2b | 56 | // SamplerWatch.kick(WatchDogTimeout); |
O_Thom | 10:08c366434f2b | 57 | |
O_Thom | 6:b7f6e0c0f646 | 58 | while(1) |
O_Thom | 6:b7f6e0c0f646 | 59 | { |
O_Thom | 10:08c366434f2b | 60 | // m_oSample.SAMP_Queue.call_every(1500, SamplerWatch.kick); |
O_Thom | 9:654e14de9d74 | 61 | m_oSample.SAMP_Queue.call_every(500, &m_oSample, &Sampler::publishSample); // Publish sample |
O_Thom | 9:654e14de9d74 | 62 | m_oSample.SAMP_Queue.dispatch(); // Enters WAITING state when blocking |
O_Thom | 9:654e14de9d74 | 63 | ErrorCodes.push_back(ERROR_SAMPLER_EXIT); // Update Error Vector |
O_Thom | 9:654e14de9d74 | 64 | m_oSerial.SERIAL_Queue.call(&m_oSerial, &Serialcomms::updateErrors, ErrorCodes); // Pass error vector to the serial thread |
O_Thom | 10:08c366434f2b | 65 | |
O_Thom | 6:b7f6e0c0f646 | 66 | } |
O_Thom | 6:b7f6e0c0f646 | 67 | } |
O_Thom | 6:b7f6e0c0f646 | 68 | |
O_Thom | 6:b7f6e0c0f646 | 69 | void SERIAL_Thread() |
O_Thom | 0:f9a18207d99c | 70 | { |
O_Thom | 12:88d33b87ecb2 | 71 | vector<int> ErrorCodes; |
O_Thom | 10:08c366434f2b | 72 | // SerialWatch.kick(WatchDogTimeout); |
O_Thom | 9:654e14de9d74 | 73 | while(1) |
O_Thom | 6:b7f6e0c0f646 | 74 | { |
O_Thom | 10:08c366434f2b | 75 | //m_oSerial.SERIAL_Queue.call_every(1500, SerialWatch.kick); |
O_Thom | 9:654e14de9d74 | 76 | m_oSerial.SERIAL_Queue.dispatch(); // Enters WAITING state when blocking |
O_Thom | 9:654e14de9d74 | 77 | ErrorCodes.push_back(ERROR_SERIAL_EXIT); // Update Error Vector |
O_Thom | 10:08c366434f2b | 78 | |
O_Thom | 6:b7f6e0c0f646 | 79 | } |
O_Thom | 0:f9a18207d99c | 80 | } |
O_Thom | 6:b7f6e0c0f646 | 81 | |
O_Thom | 19:c3b396b65f2a | 82 | |
O_Thom | 19:c3b396b65f2a | 83 | void Network_Thread() |
O_Thom | 19:c3b396b65f2a | 84 | { |
O_Thom | 19:c3b396b65f2a | 85 | while(1) |
O_Thom | 19:c3b396b65f2a | 86 | { |
O_Thom | 19:c3b396b65f2a | 87 | m_oNet.Network_Queue.call_every(10, &m_oNet, &Network::NetPush); |
O_Thom | 19:c3b396b65f2a | 88 | m_oNet.Network_Queue.dispatch(); |
O_Thom | 19:c3b396b65f2a | 89 | |
O_Thom | 19:c3b396b65f2a | 90 | while(true) |
O_Thom | 19:c3b396b65f2a | 91 | { // Flash if the event queue is exited. |
O_Thom | 19:c3b396b65f2a | 92 | greenLED = 1; |
O_Thom | 19:c3b396b65f2a | 93 | wait(0.5); |
O_Thom | 19:c3b396b65f2a | 94 | greenLED = 0; |
O_Thom | 19:c3b396b65f2a | 95 | wait(0.1); |
O_Thom | 19:c3b396b65f2a | 96 | |
O_Thom | 19:c3b396b65f2a | 97 | } |
O_Thom | 19:c3b396b65f2a | 98 | } |
O_Thom | 19:c3b396b65f2a | 99 | } |