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 6:b7f6e0c0f646 1 #include "mbed.h"
O_Thom 14:dbb0741ce576 2 #include "mbed_events.h"
O_Thom 20:2ce28a5032d5 3 #include <string>
O_Thom 11:b8e8630c7e3b 4 #include <iostream>
O_Thom 9:654e14de9d74 5 #include <vector>
O_Thom 10:08c366434f2b 6
O_Thom 9:654e14de9d74 7 #define ERROR_LCD_EXIT 1
O_Thom 9:654e14de9d74 8 #define ERROR_SERIAL_EXIT 2
O_Thom 9:654e14de9d74 9 #define ERROR_SD_EXIT 3
O_Thom 9:654e14de9d74 10 #define ERROR_NET_EXIT 4
O_Thom 9:654e14de9d74 11 #define ERROR_SAMPLER_EXIT 5
O_Thom 16:73af0e3ddcaa 12 #define cmdRow 36
O_Thom 16:73af0e3ddcaa 13 #define cmdCol 37
O_Thom 18:a036c2e5ff89 14
O_Thom 13:37a7c57f4641 15 Serial pc(USBTX, USBRX); // USB Tx and Rx Connections
O_Thom 6:b7f6e0c0f646 16
O_Thom 17:da78a552339d 17 const int buffer_size = 30;
O_Thom 13:37a7c57f4641 18 char rx_buffer[buffer_size+1];
O_Thom 13:37a7c57f4641 19
O_Thom 20:2ce28a5032d5 20 Queue<uint32_t,5> Serial2Sampler; // Serial -> Sampler Message Queue. 5 Elements Wide
O_Thom 20:2ce28a5032d5 21 Mail<SD_message, 5> Serial2SD; // Serial -> SD Mailbox Time&Date + Sample Management
O_Thom 18:a036c2e5ff89 22
O_Thom 6:b7f6e0c0f646 23 class Serialcomms
O_Thom 20:2ce28a5032d5 24 {
O_Thom 18:a036c2e5ff89 25 private:
O_Thom 18:a036c2e5ff89 26 float fTemp; //current temperature of sensor
O_Thom 18:a036c2e5ff89 27 float fPressure; //current pressure of sensor
O_Thom 18:a036c2e5ff89 28 float fLDR; //current light level from LDR
O_Thom 20:2ce28a5032d5 29 bool Logging;
O_Thom 20:2ce28a5032d5 30 bool SampleEN;
O_Thom 9:654e14de9d74 31 vector<int> ErrorCodes;
O_Thom 15:f8748fd0c5b1 32 int rx_in;
O_Thom 15:f8748fd0c5b1 33 int cmdCount;
O_Thom 16:73af0e3ddcaa 34 int rxInputFlag;
O_Thom 16:73af0e3ddcaa 35 char RxIn[buffer_size+1];
O_Thom 16:73af0e3ddcaa 36 char clearingArray[buffer_size+1];
O_Thom 20:2ce28a5032d5 37 char timestampArray[15+1];
O_Thom 18:a036c2e5ff89 38
O_Thom 11:b8e8630c7e3b 39 public:
O_Thom 9:654e14de9d74 40 EventQueue SERIAL_Queue; //Initialise the EventQueue
O_Thom 20:2ce28a5032d5 41
O_Thom 20:2ce28a5032d5 42 void addtoSerial2Sampler(uint32_t Data) // Producer for the Queue
O_Thom 20:2ce28a5032d5 43 {
O_Thom 20:2ce28a5032d5 44 osStatus Stat = Serial2Sampler.put((uint32_t*)Data); // Put the data into the message queue
O_Thom 20:2ce28a5032d5 45 if (Stat == osErrorResource) // Try catch & Error Handling
O_Thom 20:2ce28a5032d5 46 {
O_Thom 20:2ce28a5032d5 47 printf("Serial2Sampler->put() Error code: %4Xh, Resource not available\r\n", Stat);
O_Thom 20:2ce28a5032d5 48 }
O_Thom 20:2ce28a5032d5 49 }
O_Thom 20:2ce28a5032d5 50
O_Thom 20:2ce28a5032d5 51 void addtoSerial2Net() // Producer for the Mailbox
O_Thom 20:2ce28a5032d5 52 {
O_Thom 20:2ce28a5032d5 53 time_and_date *mail = Serial2Net.alloc(); // Allocatte space in the memory pool
O_Thom 20:2ce28a5032d5 54 mail -> current_time = timestampArray;
O_Thom 20:2ce28a5032d5 55 osStatus Stat = Serial2Net.put(mail); // Pointer to teh data package
O_Thom 20:2ce28a5032d5 56 if (Stat == osErrorResource) // Try catch & Error Handling
O_Thom 20:2ce28a5032d5 57 {
O_Thom 20:2ce28a5032d5 58 printf("Serial2Net->put() Error code: %4Xh, Resource not available\r\n", Stat);
O_Thom 20:2ce28a5032d5 59 }
O_Thom 20:2ce28a5032d5 60 }
O_Thom 20:2ce28a5032d5 61
O_Thom 20:2ce28a5032d5 62 void addtoSerial2LCD() // Producer for the Mailbox
O_Thom 20:2ce28a5032d5 63 {
O_Thom 20:2ce28a5032d5 64 time_and_date *mail = Serial2Net.alloc();
O_Thom 20:2ce28a5032d5 65 mail -> current_time = timestampArray;
O_Thom 20:2ce28a5032d5 66 osStatus Stat = Serial2LCD.put(mail); // Put the data into the message queue
O_Thom 20:2ce28a5032d5 67 if (Stat == osErrorResource) // Try catch & Error Handling
O_Thom 20:2ce28a5032d5 68 {
O_Thom 20:2ce28a5032d5 69 printf("Serial2LCD->put() Error code: %4Xh, Resource not available\r\n", Stat);
O_Thom 20:2ce28a5032d5 70 }
O_Thom 20:2ce28a5032d5 71 }
O_Thom 20:2ce28a5032d5 72
O_Thom 14:dbb0741ce576 73 void displayFrame()
O_Thom 20:2ce28a5032d5 74 {
O_Thom 14:dbb0741ce576 75 printf("\033[2J"); // Clear screen
O_Thom 14:dbb0741ce576 76 printf("\033[0;0H"); // Home Positon Reset
O_Thom 16:73af0e3ddcaa 77 printf("*********************************************************************************\n"
O_Thom 16:73af0e3ddcaa 78 "* ELEC351 COURSEWORK ENVIRONMENTAL SYSTEM *\n"
O_Thom 16:73af0e3ddcaa 79 "*********************************************************************************\n"
O_Thom 16:73af0e3ddcaa 80 "* Sensor Readout * Terminal *\n"
O_Thom 16:73af0e3ddcaa 81 "*********************************************************************************\n"
O_Thom 16:73af0e3ddcaa 82 "* Timestamp: * *\n" // Col 5 Row 13
O_Thom 16:73af0e3ddcaa 83 "* Temperature: * *\n" // Col 6 Row 15
O_Thom 16:73af0e3ddcaa 84 "* Pressure: * *\n" // Col 7 Row 12
O_Thom 16:73af0e3ddcaa 85 "* Light Level: * *\n" // Col 8 Row15
O_Thom 16:73af0e3ddcaa 86 "********************************* *\n"
O_Thom 20:2ce28a5032d5 87 "* Error Codes * *\n" // Col 10
O_Thom 16:73af0e3ddcaa 88 "********************************* *\n" // Col 11 Row 2
O_Thom 16:73af0e3ddcaa 89 "* * *\n"
O_Thom 16:73af0e3ddcaa 90 "* * *\n"
O_Thom 16:73af0e3ddcaa 91 "* * *\n"
O_Thom 16:73af0e3ddcaa 92 "* * *\n"
O_Thom 16:73af0e3ddcaa 93 "* * *\n"
O_Thom 16:73af0e3ddcaa 94 "* * *\n"
O_Thom 16:73af0e3ddcaa 95 "* * *\n"
O_Thom 16:73af0e3ddcaa 96 "* * *\n"
O_Thom 16:73af0e3ddcaa 97 "* * *\n"
O_Thom 16:73af0e3ddcaa 98 "* * *\n"
O_Thom 16:73af0e3ddcaa 99 "* * *\n"
O_Thom 16:73af0e3ddcaa 100 "********************************* *\n"
O_Thom 16:73af0e3ddcaa 101 "* Thread Health * *\n"
O_Thom 16:73af0e3ddcaa 102 "********************************* *\n"
O_Thom 16:73af0e3ddcaa 103 "* * *\n"
O_Thom 16:73af0e3ddcaa 104 "* * *\n"
O_Thom 16:73af0e3ddcaa 105 "* * *\n"
O_Thom 16:73af0e3ddcaa 106 "* * *\n"
O_Thom 16:73af0e3ddcaa 107 "* * *\n"
O_Thom 16:73af0e3ddcaa 108 "* * *\n"
O_Thom 16:73af0e3ddcaa 109 "* * *\n"
O_Thom 16:73af0e3ddcaa 110 "* * *\n"
O_Thom 16:73af0e3ddcaa 111 "* * *\n"
O_Thom 16:73af0e3ddcaa 112 "* * *\n"
O_Thom 16:73af0e3ddcaa 113 "* * *\n"
O_Thom 16:73af0e3ddcaa 114 "* * *\n" // cmd position r:36 c:37
O_Thom 16:73af0e3ddcaa 115 "*********************************************************************************\n\n"
O_Thom 14:dbb0741ce576 116 );
O_Thom 16:73af0e3ddcaa 117 printf("\033[%d;%dfcmd: ", cmdRow, cmdCol);
O_Thom 14:dbb0741ce576 118 }
O_Thom 14:dbb0741ce576 119
O_Thom 19:c3b396b65f2a 120 Serialcomms() // Take the reference of the sampler object and state in m_oSamplerRef
O_Thom 10:08c366434f2b 121 {
O_Thom 10:08c366434f2b 122 pc.baud(9600);
O_Thom 18:a036c2e5ff89 123 rx_in = 0;
O_Thom 15:f8748fd0c5b1 124 cmdCount = 0;
O_Thom 15:f8748fd0c5b1 125 fTemp = 0;
O_Thom 15:f8748fd0c5b1 126 fPressure = 0;
O_Thom 15:f8748fd0c5b1 127 fLDR = 0;
O_Thom 20:2ce28a5032d5 128 Logging = 0;
O_Thom 20:2ce28a5032d5 129 SampleEN = 0;
O_Thom 16:73af0e3ddcaa 130 for (int i = 0; i < buffer_size+1; i++)
O_Thom 16:73af0e3ddcaa 131 {
O_Thom 16:73af0e3ddcaa 132 clearingArray[i] = ' ';
O_Thom 17:da78a552339d 133 rx_buffer[i] = 0;
O_Thom 20:2ce28a5032d5 134 if (i < 16)
O_Thom 20:2ce28a5032d5 135 {
O_Thom 20:2ce28a5032d5 136 timestampArray[i] = ' ';
O_Thom 20:2ce28a5032d5 137 }
O_Thom 20:2ce28a5032d5 138
O_Thom 16:73af0e3ddcaa 139 }
O_Thom 20:2ce28a5032d5 140 timestampArray[8] = ':';
O_Thom 14:dbb0741ce576 141 displayFrame();
O_Thom 16:73af0e3ddcaa 142 SERIAL_Queue.call_every(1000, callback(this, &Serialcomms::updateTerminal));
O_Thom 20:2ce28a5032d5 143 SERIAL_Queue.call_every(50, callback(this, &Serialcomms::ReadData)); // Start the periodic event to check the serial buffer
O_Thom 10:08c366434f2b 144 }
O_Thom 13:37a7c57f4641 145
O_Thom 10:08c366434f2b 146 ~Serialcomms()
O_Thom 10:08c366434f2b 147 {
O_Thom 11:b8e8630c7e3b 148 printf("Closing Serial Comms.");
O_Thom 10:08c366434f2b 149 }
O_Thom 10:08c366434f2b 150
O_Thom 6:b7f6e0c0f646 151 void setsampledata(sample_message msg) // Update internal values
O_Thom 6:b7f6e0c0f646 152 {
O_Thom 20:2ce28a5032d5 153 fTemp = msg.temp;
O_Thom 20:2ce28a5032d5 154 fPressure = msg.pressure;
O_Thom 20:2ce28a5032d5 155 fLDR = msg.ldr;
O_Thom 6:b7f6e0c0f646 156 }
O_Thom 6:b7f6e0c0f646 157
O_Thom 9:654e14de9d74 158 sample_message getsampledata() // Retrieves the data
O_Thom 6:b7f6e0c0f646 159 {
O_Thom 6:b7f6e0c0f646 160 sample_message msg;
O_Thom 6:b7f6e0c0f646 161 msg.temp = fTemp;
O_Thom 6:b7f6e0c0f646 162 msg.pressure = fPressure;
O_Thom 6:b7f6e0c0f646 163 msg.ldr = fLDR;
O_Thom 6:b7f6e0c0f646 164 return msg;
O_Thom 6:b7f6e0c0f646 165 }
O_Thom 16:73af0e3ddcaa 166
O_Thom 6:b7f6e0c0f646 167 void updateTerminal() // Print internal values of sensors
O_Thom 17:da78a552339d 168 {
O_Thom 17:da78a552339d 169 printf("\033[6;16f%s", timestampArray);
O_Thom 15:f8748fd0c5b1 170 printf("\033[7;16f%5.2f", fTemp);
O_Thom 15:f8748fd0c5b1 171 printf("\033[8;16f%5.2f", fPressure);
O_Thom 15:f8748fd0c5b1 172 printf("\033[9;16f%5.2f", fLDR);
O_Thom 9:654e14de9d74 173 if (ErrorCodes.size() == 0)
O_Thom 9:654e14de9d74 174 {
O_Thom 16:73af0e3ddcaa 175 printf("\033[13;3fNo Error Codes Raised\n");
O_Thom 9:654e14de9d74 176 }
O_Thom 9:654e14de9d74 177 else
O_Thom 9:654e14de9d74 178 {
O_Thom 9:654e14de9d74 179 for (int idx = 0; idx < ErrorCodes.size(); idx++)
O_Thom 9:654e14de9d74 180 {
O_Thom 16:73af0e3ddcaa 181 printf("\033[%d;3: %d\n",(11+idx),ErrorCodes[idx]);
O_Thom 9:654e14de9d74 182 }
O_Thom 9:654e14de9d74 183 }
O_Thom 15:f8748fd0c5b1 184 // Add code to receive feedback from watchdog and place into thread safe section
O_Thom 9:654e14de9d74 185 }
O_Thom 16:73af0e3ddcaa 186
O_Thom 16:73af0e3ddcaa 187
O_Thom 16:73af0e3ddcaa 188 void printstringtoTerminal(char Data[])
O_Thom 16:73af0e3ddcaa 189 {
O_Thom 16:73af0e3ddcaa 190 printf("\033[%d;%df%s", (cmdRow-(cmdCount+1)),(cmdCol+5), Data); // Confirmation of Command
O_Thom 16:73af0e3ddcaa 191 cmdCount++;
O_Thom 16:73af0e3ddcaa 192 }
O_Thom 16:73af0e3ddcaa 193 void printintegertoTerminal(int Data)
O_Thom 16:73af0e3ddcaa 194 {
O_Thom 16:73af0e3ddcaa 195 printf("\033[%d;%df%d", (cmdRow-(cmdCount+1)),(cmdCol+5), Data); // Confirmation of Command
O_Thom 16:73af0e3ddcaa 196 cmdCount++;
O_Thom 16:73af0e3ddcaa 197 }
O_Thom 16:73af0e3ddcaa 198
O_Thom 16:73af0e3ddcaa 199 int searchInput(char stream[], char command[])
O_Thom 16:73af0e3ddcaa 200 {
O_Thom 16:73af0e3ddcaa 201 int match = 0;
O_Thom 17:da78a552339d 202 const int commandLength = strlen(command);
O_Thom 16:73af0e3ddcaa 203 for (int i = 0; i < commandLength; i++)
O_Thom 16:73af0e3ddcaa 204 {
O_Thom 16:73af0e3ddcaa 205 if (stream[i] == command[i])
O_Thom 16:73af0e3ddcaa 206 {
O_Thom 16:73af0e3ddcaa 207 match = i; // Return the position of the last command character
O_Thom 16:73af0e3ddcaa 208 }
O_Thom 16:73af0e3ddcaa 209 else
O_Thom 16:73af0e3ddcaa 210 {
O_Thom 17:da78a552339d 211 match = 0;
O_Thom 17:da78a552339d 212 i = commandLength-1;
O_Thom 16:73af0e3ddcaa 213 }
O_Thom 17:da78a552339d 214 }
O_Thom 16:73af0e3ddcaa 215 return match;
O_Thom 16:73af0e3ddcaa 216 }
O_Thom 16:73af0e3ddcaa 217
O_Thom 16:73af0e3ddcaa 218
O_Thom 13:37a7c57f4641 219 void handleInput()
O_Thom 16:73af0e3ddcaa 220 {
O_Thom 16:73af0e3ddcaa 221 if (int readall = searchInput(RxIn, "READ ALL") > 0)
O_Thom 16:73af0e3ddcaa 222 {
O_Thom 20:2ce28a5032d5 223 printstringtoTerminal("READING ALL");
O_Thom 9:654e14de9d74 224 }
O_Thom 20:2ce28a5032d5 225
O_Thom 16:73af0e3ddcaa 226 else if(int readall = searchInput(RxIn, "DELETE ALL") > 0)
O_Thom 16:73af0e3ddcaa 227 {
O_Thom 16:73af0e3ddcaa 228 printf("\033[%d;%df%s", (cmdRow-(cmdCount+1)),(cmdCol+5), "DELETING ALL"); // Confirmation of Command
O_Thom 16:73af0e3ddcaa 229 cmdCount++;
O_Thom 16:73af0e3ddcaa 230 }
O_Thom 16:73af0e3ddcaa 231 else if(int read = searchInput(RxIn, "READ") > 0)
O_Thom 9:654e14de9d74 232 {
O_Thom 17:da78a552339d 233 read = searchInput(RxIn, "READ");
O_Thom 16:73af0e3ddcaa 234 char count[buffer_size] = {0};
O_Thom 16:73af0e3ddcaa 235 for (int i = read; i < strlen(RxIn); i++)
O_Thom 16:73af0e3ddcaa 236 {
O_Thom 17:da78a552339d 237 count[i-read] = RxIn[i+1];
O_Thom 16:73af0e3ddcaa 238 }
O_Thom 17:da78a552339d 239 }
O_Thom 16:73af0e3ddcaa 240 else if(int del = searchInput(RxIn, "DELETE") > 0)
O_Thom 9:654e14de9d74 241 {
O_Thom 17:da78a552339d 242 del = searchInput(RxIn, "DELETE");
O_Thom 17:da78a552339d 243 char count[buffer_size] = {0};
O_Thom 17:da78a552339d 244 for (int i = del; i < strlen(RxIn); i++)
O_Thom 17:da78a552339d 245 {
O_Thom 17:da78a552339d 246 count[i-del] = RxIn[i+1];
O_Thom 17:da78a552339d 247 }
O_Thom 9:654e14de9d74 248 }
O_Thom 16:73af0e3ddcaa 249 else if(int setdate = searchInput(RxIn, "SETDATE") > 0) //<dd> <mm> <yyyy>
O_Thom 17:da78a552339d 250 {
O_Thom 20:2ce28a5032d5 251 setdate = searchInput(RxIn, "SETDATE"); // Returns the index of the last character
O_Thom 17:da78a552339d 252 char count[buffer_size] = {0};
O_Thom 17:da78a552339d 253 for (int i = setdate; i < strlen(RxIn); i++)
O_Thom 17:da78a552339d 254 {
O_Thom 20:2ce28a5032d5 255 if (RxIn[i+1] != ' ')
O_Thom 20:2ce28a5032d5 256 {
O_Thom 17:da78a552339d 257 count[i-setdate] = RxIn[i+1];
O_Thom 20:2ce28a5032d5 258 timestampArray[i-setdate] = RxIn[i+1];
O_Thom 20:2ce28a5032d5 259 }
O_Thom 17:da78a552339d 260 }
O_Thom 20:2ce28a5032d5 261 addtoSerial2LCD(); // Update the DATE on the LCD
O_Thom 20:2ce28a5032d5 262 addtoSerial2Net(); // Update the DATE on the Webpage
O_Thom 9:654e14de9d74 263 }
O_Thom 16:73af0e3ddcaa 264 else if(int settime = searchInput(RxIn, "SETTIME") > 0) //<hh> <mm> <ss>
O_Thom 9:654e14de9d74 265 {
O_Thom 17:da78a552339d 266 settime = searchInput(RxIn, "SETTIME");
O_Thom 17:da78a552339d 267 char count[buffer_size] = {0};
O_Thom 17:da78a552339d 268 for (int i = settime; i < strlen(RxIn); i++)
O_Thom 20:2ce28a5032d5 269 {
O_Thom 20:2ce28a5032d5 270 if (RxIn[i+1] != ' ')
O_Thom 20:2ce28a5032d5 271 {
O_Thom 17:da78a552339d 272 count[i-settime] = RxIn[i+1];
O_Thom 20:2ce28a5032d5 273 timestampArray[i-settime+9] = RxIn[i+1];
O_Thom 20:2ce28a5032d5 274 }
O_Thom 20:2ce28a5032d5 275 }
O_Thom 20:2ce28a5032d5 276 addtoSerial2LCD(); // Update the TIME on the LCD
O_Thom 20:2ce28a5032d5 277 addtoSerial2Net(); // Update the TIME on the Webpage
O_Thom 17:da78a552339d 278 }
O_Thom 20:2ce28a5032d5 279 else if(int sett = searchInput(RxIn, "STATE") > 0)
O_Thom 9:654e14de9d74 280 {
O_Thom 20:2ce28a5032d5 281 SampleEN = !SampleEN;
O_Thom 20:2ce28a5032d5 282 if (SampleEN)
O_Thom 20:2ce28a5032d5 283 {
O_Thom 20:2ce28a5032d5 284 printstringtoTerminal("SAMPLING");
O_Thom 20:2ce28a5032d5 285 }
O_Thom 20:2ce28a5032d5 286 else
O_Thom 20:2ce28a5032d5 287 {
O_Thom 20:2ce28a5032d5 288 printstringtoTerminal("SAMPLING DISABLED");
O_Thom 20:2ce28a5032d5 289 }
O_Thom 20:2ce28a5032d5 290 addtoSerial2Sampler(SampleEN);
O_Thom 20:2ce28a5032d5 291 // uint32_t bit = (uint32_t)(RxIn[5] - '0'); // Take the last character after the "SETT" string and push it onto the queue
O_Thom 20:2ce28a5032d5 292 // if ((bit == 1) || (bit == 0))
O_Thom 20:2ce28a5032d5 293 // {
O_Thom 20:2ce28a5032d5 294 // addtoSerial2Sampler(bit);
O_Thom 20:2ce28a5032d5 295 // }
O_Thom 20:2ce28a5032d5 296 // else
O_Thom 20:2ce28a5032d5 297 // {
O_Thom 20:2ce28a5032d5 298 // printf("Invalid STATE Entry");
O_Thom 20:2ce28a5032d5 299 // }
O_Thom 20:2ce28a5032d5 300 }
O_Thom 20:2ce28a5032d5 301 else if(int state = searchInput(RxIn, "SETT") > 0) // PENDING WORK -> Set the time period of sampling
O_Thom 9:654e14de9d74 302 {
O_Thom 20:2ce28a5032d5 303 uint32_t bit = 0; // Re-init
O_Thom 20:2ce28a5032d5 304 bit += (uint32_t)(RxIn[4] - '0'); // Take the last character after the "SETT" string and push it onto the queue
O_Thom 20:2ce28a5032d5 305 // Modify the enable sampling bit
O_Thom 20:2ce28a5032d5 306 if (bit > 0)
O_Thom 20:2ce28a5032d5 307 {
O_Thom 20:2ce28a5032d5 308 addtoSerial2Sampler(bit);
O_Thom 20:2ce28a5032d5 309 }
O_Thom 20:2ce28a5032d5 310 }
O_Thom 16:73af0e3ddcaa 311 else if(int logging = searchInput(RxIn, "LOGGING") > 0) // Verbose logging
O_Thom 16:73af0e3ddcaa 312 {
O_Thom 20:2ce28a5032d5 313 Logging = !Logging; // Toggle the private Logging Bool Variable
O_Thom 20:2ce28a5032d5 314 if (Logging)
O_Thom 20:2ce28a5032d5 315 {
O_Thom 20:2ce28a5032d5 316 printstringtoTerminal("LOGGING");
O_Thom 20:2ce28a5032d5 317 }
O_Thom 20:2ce28a5032d5 318 else
O_Thom 20:2ce28a5032d5 319 {
O_Thom 20:2ce28a5032d5 320 printstringtoTerminal("LOGGING DISABLED");
O_Thom 20:2ce28a5032d5 321 }
O_Thom 16:73af0e3ddcaa 322 }
O_Thom 20:2ce28a5032d5 323 else if(int clearall = searchInput(RxIn, "CLEARALL") > 0) // Reset the terminal
O_Thom 16:73af0e3ddcaa 324 {
O_Thom 17:da78a552339d 325 cmdCount = 0;
O_Thom 17:da78a552339d 326 for (int i = 0; i < 22; i++)
O_Thom 17:da78a552339d 327 {
O_Thom 17:da78a552339d 328 printstringtoTerminal(clearingArray);
O_Thom 17:da78a552339d 329 }
O_Thom 20:2ce28a5032d5 330 displayFrame();
O_Thom 17:da78a552339d 331 cmdCount = 0;
O_Thom 16:73af0e3ddcaa 332 }
O_Thom 16:73af0e3ddcaa 333 else
O_Thom 9:654e14de9d74 334 {
O_Thom 16:73af0e3ddcaa 335 printstringtoTerminal("UNKNOWN COMMAND");
O_Thom 16:73af0e3ddcaa 336 }
O_Thom 16:73af0e3ddcaa 337
O_Thom 16:73af0e3ddcaa 338 for (int i = 0; i < (buffer_size+1); i++) // Init
O_Thom 16:73af0e3ddcaa 339 {
O_Thom 16:73af0e3ddcaa 340 RxIn[i] = 0;
O_Thom 20:2ce28a5032d5 341 rx_buffer[i] = ' ';
O_Thom 16:73af0e3ddcaa 342 }
O_Thom 20:2ce28a5032d5 343 printf("\033[%d;%dfcmd: %s", cmdRow, cmdCol, rx_buffer); // Reset to cmd location
O_Thom 9:654e14de9d74 344 }
O_Thom 10:08c366434f2b 345
O_Thom 13:37a7c57f4641 346
O_Thom 13:37a7c57f4641 347 void ReadData()
O_Thom 10:08c366434f2b 348 {
O_Thom 16:73af0e3ddcaa 349 while(pc.readable()) // While there's data in the Rx buffer
O_Thom 10:08c366434f2b 350 {
O_Thom 16:73af0e3ddcaa 351 char c = pc.getc(); // Take a character off the buffer
O_Thom 16:73af0e3ddcaa 352 if (c == 0x0D) // Enter ASCII Code
O_Thom 13:37a7c57f4641 353 {
O_Thom 16:73af0e3ddcaa 354 printf("\033[%d;%df%s", (cmdRow-(cmdCount+1)),(cmdCol+5), rx_buffer); // Echo the Command back to the terminal
O_Thom 16:73af0e3ddcaa 355 rx_in = 0; // Reset the buffer indexer
O_Thom 16:73af0e3ddcaa 356 int stringLength = strlen(rx_buffer); //finds length of the array
O_Thom 16:73af0e3ddcaa 357 for (int i = 0; i < stringLength; i++) {
O_Thom 16:73af0e3ddcaa 358 RxIn[i] = rx_buffer[i]; // Copies buffer into global // stringLength-1-i
O_Thom 16:73af0e3ddcaa 359 }
O_Thom 16:73af0e3ddcaa 360 RxIn[stringLength] = '\0'; //adds NULL character
O_Thom 16:73af0e3ddcaa 361 SERIAL_Queue.call(callback(this, &Serialcomms::handleInput));
O_Thom 16:73af0e3ddcaa 362
O_Thom 16:73af0e3ddcaa 363 for (int i = 0 ; i < stringLength; i++)
O_Thom 15:f8748fd0c5b1 364 {
O_Thom 16:73af0e3ddcaa 365 rx_buffer[i] = 0; // Clear the buffer with spaces
O_Thom 15:f8748fd0c5b1 366 }
O_Thom 16:73af0e3ddcaa 367 printf("\033[%d;%df%s", cmdRow, (cmdCol+5), clearingArray); // Clear the Command entry space
O_Thom 16:73af0e3ddcaa 368 //printf("\033[%d;%df%s", (cmdRow -(cmdCount+2)), cmdCol, clearingArray); // Clear above the oldest record Command
O_Thom 15:f8748fd0c5b1 369
O_Thom 16:73af0e3ddcaa 370 if (cmdCount >= 20)
O_Thom 15:f8748fd0c5b1 371 {
O_Thom 15:f8748fd0c5b1 372 cmdCount = 0;
O_Thom 15:f8748fd0c5b1 373 }
O_Thom 15:f8748fd0c5b1 374 cmdCount++;
O_Thom 15:f8748fd0c5b1 375
O_Thom 15:f8748fd0c5b1 376 break;
O_Thom 13:37a7c57f4641 377 }
O_Thom 13:37a7c57f4641 378 rx_buffer[rx_in] = c;
O_Thom 16:73af0e3ddcaa 379 printf("\033[%d;%df%s",cmdRow, (cmdCol+5), rx_buffer); // Echo
O_Thom 13:37a7c57f4641 380 rx_in += 1; // Increase received indexer
O_Thom 11:b8e8630c7e3b 381 }
O_Thom 10:08c366434f2b 382 }
O_Thom 13:37a7c57f4641 383
O_Thom 9:654e14de9d74 384 void updateErrors(vector<int> ErrorsIn)
O_Thom 9:654e14de9d74 385 {
O_Thom 9:654e14de9d74 386 for (int idx = 0; idx < ErrorsIn.size() ; idx++) // Add the Error Codes to the vector
O_Thom 9:654e14de9d74 387 {
O_Thom 9:654e14de9d74 388 ErrorCodes.push_back(ErrorsIn[idx]);
O_Thom 9:654e14de9d74 389 }
O_Thom 6:b7f6e0c0f646 390 }
O_Thom 6:b7f6e0c0f646 391 void updateTimeDate()
O_Thom 20:2ce28a5032d5 392 {
O_Thom 20:2ce28a5032d5 393 }
O_Thom 1:f89c930c6491 394 };
O_Thom 7:8664a45f5ce1 395