Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BMP280 ELEC350-Practicals-FZ429- TextLCD watchdog_RTOS BME280 ntp-client
Diff: SerialComms.hpp
- Revision:
- 11:b8e8630c7e3b
- Parent:
- 10:08c366434f2b
- Child:
- 12:88d33b87ecb2
--- a/SerialComms.hpp Tue Dec 04 15:26:46 2018 +0000 +++ b/SerialComms.hpp Tue Dec 04 17:39:43 2018 +0000 @@ -1,5 +1,6 @@ #include "mbed.h" #include<string> +#include <iostream> #include <vector> #define ERROR_LCD_EXIT 1 @@ -11,17 +12,18 @@ //enum ErrorCodes {ERROR_LCD_EXIT,ERROR_SERIAL_EXIT,ERROR_SD_EXIT,ERROR_NET_EXIT}; Serial pc(USBTX, USBRX); // USB Tx and Rx Connections - +using namespace std; class Serialcomms { - friend class Serial; private: float fTemp; //current temperature of sensor float fPressure; //current pressure of sensor float fLDR; //current light level from LDR vector<int> ErrorCodes; - public: + string RxIn; // Init + + public: EventQueue SERIAL_Queue; //Initialise the EventQueue @@ -35,10 +37,12 @@ { pc.baud(9600); printf("Serial Comms Initialised, Baud: 9600\n"); + printf("COMMAND: \n"); pc.attach(callback(this, &Serialcomms::Rx_Interrupt), Serial::RxIrq); // Interrupt if data is received } ~Serialcomms() { + printf("Closing Serial Comms."); } void setsampledata(sample_message msg) // Update internal values @@ -91,50 +95,52 @@ - void handleInput(vector<char> RxIn) + void handleInput(string RxIn) { - string Input = ( RxIn.begin(), RxIn.end() ); // Place into a string - printf("Inputted String: %s", Input); // Debug + printf("Echo: %s", RxIn); // Debug - if (Input == "READ ALL") // Sends a comma seperate list of all measurements. + if (RxIn == "READ ALL") // Sends a comma seperate list of all measurements. { } - else if(Input == "DELETE ALL") + else if(RxIn == "DELETE ALL") { } - else if(Input == "READ") + else if(RxIn == "READ") { } - else if(Input == "DELETE") + else if(RxIn == "DELETE") { } - else if(Input == "SETDATE") + else if(RxIn == "SETDATE") { } - else if(Input == "SETTIME") + else if(RxIn == "SETTIME") { } - else if(Input == "SETT") + else if(RxIn == "SETT") { } - else if(Input == "STATE") + else if(RxIn == "STATE") { } - else if(Input == "LOGGING") // Verbose logging + else if(RxIn == "LOGGING") // Verbose logging { - } + } + RxIn = ""; // Reset the input string } void ReadData() { - char c; - vector<char> RxIn; - do // While there is data in the buffer + char c = pc.getc(); + + if (c != '\n') { - c = pc.getc(); // Receive the character from the serial buffer - RxIn.push_back(c); // Push the next character in the buffer onto the vector - } while(c != '\n'); // BLOCKING - SERIAL_Queue.call(callback(this, &Serialcomms::handleInput), RxIn); // Process the input + RxIn.append(1,c); // Push the next character in the buffer onto the vector + } + else // If the command is terminated + { + SERIAL_Queue.call(callback(this, &Serialcomms::handleInput), RxIn); // Process the inpuT + } } @@ -154,5 +160,3 @@ }; -Serialcomms m_oSerial; -