For coursework of group 3 in SOFT564Z

Dependencies:   Motordriver ros_lib_kinetic

Committer:
Jonathan738
Date:
Sun Jan 05 15:42:22 2020 +0000
Revision:
12:82b8fe254222
Parent:
8:e406c6f728bd
Added working version of TOF code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jonathan738 4:8afc50a3e4ac 1 /*------------------------------------------------------------------------------
Jonathan738 4:8afc50a3e4ac 2 Creator : Jonathan Wheadon
Jonathan738 4:8afc50a3e4ac 3 Date : 29/11/2019
Jonathan738 4:8afc50a3e4ac 4 ------------------------------------------------------------------------------*/
Jonathan738 4:8afc50a3e4ac 5 #include "mbed.h"
Jonathan738 4:8afc50a3e4ac 6 #include "rtos.h"
Jonathan738 4:8afc50a3e4ac 7 #include "Debug.hpp"
Jonathan738 7:2796f0b5228d 8 //#include "dateTime.hpp"
Jonathan738 4:8afc50a3e4ac 9 #include "General.hpp"
Jonathan738 4:8afc50a3e4ac 10 #include "Pins.h"
Jonathan738 4:8afc50a3e4ac 11
Jonathan738 4:8afc50a3e4ac 12 // queue for Terminal events
Jonathan738 4:8afc50a3e4ac 13 EventQueue TerminalQueue(32 * EVENTS_EVENT_SIZE);
Jonathan738 5:207e0cd8b9de 14 /* The EventQueue object is part of mbed's rtos.h */
Jonathan738 5:207e0cd8b9de 15
Jonathan738 4:8afc50a3e4ac 16
Jonathan738 4:8afc50a3e4ac 17 // Create Object PC of class Terminal with Set SERIAL_TX and SERIAL_RX pins
Jonathan738 4:8afc50a3e4ac 18 Terminal PC(SERIAL_TX, SERIAL_RX);
Jonathan738 5:207e0cd8b9de 19 /* Terminal object defined in Debug.hpp */
Jonathan738 4:8afc50a3e4ac 20
Jonathan738 8:e406c6f728bd 21 DigitalOut debugLED(LED2);
Jonathan738 8:e406c6f728bd 22 DigitalOut debugLED_temp(LED3);
Jonathan738 8:e406c6f728bd 23
Jonathan738 4:8afc50a3e4ac 24 /*------------------------------------------------------------------------------
Jonathan738 4:8afc50a3e4ac 25 Thread for handiling the terminal
Jonathan738 4:8afc50a3e4ac 26 ------------------------------------------------------------------------------*/
Jonathan738 4:8afc50a3e4ac 27 void TerminalThread(void)
Jonathan738 4:8afc50a3e4ac 28 {
Jonathan738 4:8afc50a3e4ac 29 // Initialise the terminal printing the table.
Jonathan738 4:8afc50a3e4ac 30 PC.init();
Jonathan738 8:e406c6f728bd 31
Jonathan738 4:8afc50a3e4ac 32 // Enter Forever loop
Jonathan738 4:8afc50a3e4ac 33 while(1) {
Jonathan738 4:8afc50a3e4ac 34 // loop forever dispatching any function called to the queue
Jonathan738 4:8afc50a3e4ac 35 TerminalQueue.dispatch_forever();
Jonathan738 4:8afc50a3e4ac 36 }
Jonathan738 4:8afc50a3e4ac 37 }
Jonathan738 4:8afc50a3e4ac 38
Jonathan738 4:8afc50a3e4ac 39
Jonathan738 4:8afc50a3e4ac 40 /*------------------------------------------------------------------------------
Jonathan738 4:8afc50a3e4ac 41 initialize terminal, print table, initialize variables and attach interupts
Jonathan738 4:8afc50a3e4ac 42 ------------------------------------------------------------------------------*/
Jonathan738 4:8afc50a3e4ac 43 void Terminal::init(void)
Jonathan738 4:8afc50a3e4ac 44 {
Jonathan738 4:8afc50a3e4ac 45 CurrentIDX = 0;
Jonathan738 4:8afc50a3e4ac 46 col = false;
Jonathan738 8:e406c6f728bd 47
Jonathan738 8:e406c6f728bd 48 debugLED_temp = 0;
Jonathan738 8:e406c6f728bd 49
Jonathan738 4:8afc50a3e4ac 50 // Set baud rate for serial object pc
Jonathan738 4:8afc50a3e4ac 51 pc.baud (115200);
Jonathan738 4:8afc50a3e4ac 52
Jonathan738 4:8afc50a3e4ac 53 // Hide cursor, move to x 0 y 0 and change print colour to green
Jonathan738 4:8afc50a3e4ac 54 pc.printf("\x1b[?25l");
Jonathan738 4:8afc50a3e4ac 55 Cursor(0,0);
Jonathan738 4:8afc50a3e4ac 56 Colour(ColourGREEN);
Jonathan738 4:8afc50a3e4ac 57
Jonathan738 4:8afc50a3e4ac 58 // Print DATA table to present data
Jonathan738 8:e406c6f728bd 59 pc.printf("| PROJ515 : DEBUG MENU | |\n\r"
Jonathan738 4:8afc50a3e4ac 60 "|***********************************************************************************************|\n\r"
Jonathan738 8:e406c6f728bd 61 "| Error Type | Time Stamp | Error MSG |\n\r"
Jonathan738 4:8afc50a3e4ac 62 "|-----------------------|-----------------------|-----------------------------------------------|\n\r");
Jonathan738 4:8afc50a3e4ac 63 for(char idx = 0; idx < Rows; idx++) {
Jonathan738 4:8afc50a3e4ac 64 pc.printf("| | | |\n\r");
Jonathan738 4:8afc50a3e4ac 65 }
Jonathan738 4:8afc50a3e4ac 66 pc.printf("|***********************************************************************************************|\n\r"
Jonathan738 4:8afc50a3e4ac 67 "| Input Command Line : |\n\r"
Jonathan738 4:8afc50a3e4ac 68 "|-----------------------------------------------------------------------------------------------|\n\r"
Jonathan738 4:8afc50a3e4ac 69 "| |\n\r"
Jonathan738 4:8afc50a3e4ac 70 "|***********************************************************************************************|\n\r"
Jonathan738 4:8afc50a3e4ac 71 " ");
Jonathan738 4:8afc50a3e4ac 72
Jonathan738 4:8afc50a3e4ac 73 // initialise variables
Jonathan738 4:8afc50a3e4ac 74 buffer_pointer = 0;
Jonathan738 4:8afc50a3e4ac 75
Jonathan738 4:8afc50a3e4ac 76 // Attach interupts
Jonathan738 4:8afc50a3e4ac 77 pc.attach(this, &Terminal::Input_Handler,pc.RxIrq); // This interupt fires whenever data is added to the terminal buffer and calls function input handler
Jonathan738 4:8afc50a3e4ac 78 }
Jonathan738 4:8afc50a3e4ac 79
Jonathan738 4:8afc50a3e4ac 80 /*------------------------------------------------------------------------------
Jonathan738 4:8afc50a3e4ac 81 Move cursor of pc terminal to co-ordinates 'X' and 'Y' (between 0 and 255)
Jonathan738 4:8afc50a3e4ac 82 ------------------------------------------------------------------------------*/
Jonathan738 4:8afc50a3e4ac 83 void Terminal::Cursor(char X, char Y)
Jonathan738 4:8afc50a3e4ac 84 {
Jonathan738 4:8afc50a3e4ac 85 pc.printf("\x1b[%d;%dH",Y,X);
Jonathan738 4:8afc50a3e4ac 86 }
Jonathan738 4:8afc50a3e4ac 87
Jonathan738 4:8afc50a3e4ac 88 /*------------------------------------------------------------------------------
Jonathan738 4:8afc50a3e4ac 89 Change pc terminal print colour (8 bit colour) to colour defined by "COLOUR"
Jonathan738 4:8afc50a3e4ac 90 ------------------------------------------------------------------------------*/
Jonathan738 4:8afc50a3e4ac 91 void Terminal::Colour(char COLOUR)
Jonathan738 4:8afc50a3e4ac 92 {
Jonathan738 4:8afc50a3e4ac 93 pc.printf("\x1b[38;5;%dm",COLOUR);
Jonathan738 4:8afc50a3e4ac 94 }
Jonathan738 4:8afc50a3e4ac 95
Jonathan738 4:8afc50a3e4ac 96 /*------------------------------------------------------------------------------
Jonathan738 4:8afc50a3e4ac 97 Prints data(STRING) to cell in table defined by IDX
Jonathan738 4:8afc50a3e4ac 98 ------------------------------------------------------------------------------*/
Jonathan738 4:8afc50a3e4ac 99 void Terminal::PrintDATA(char* STRING, char IDX)
Jonathan738 4:8afc50a3e4ac 100 {
Jonathan738 8:e406c6f728bd 101 char Y = (IDX/3)+5;
Jonathan738 8:e406c6f728bd 102 char X = ((IDX%3)*24)+3;
Jonathan738 4:8afc50a3e4ac 103 Cursor(X,Y);
Jonathan738 4:8afc50a3e4ac 104 pc.printf("%s",STRING);
Jonathan738 4:8afc50a3e4ac 105 }
Jonathan738 4:8afc50a3e4ac 106
Jonathan738 4:8afc50a3e4ac 107 /*------------------------------------------------------------------------------
Jonathan738 4:8afc50a3e4ac 108 Function checks terminal buffer to see which key has been entered and saves to
Jonathan738 4:8afc50a3e4ac 109 internal buffer, if carridge return (0x0D) has been pressed it calls function
Jonathan738 4:8afc50a3e4ac 110 to decode the command and add the relavant function to the event QUEUE
Jonathan738 4:8afc50a3e4ac 111 ------------------------------------------------------------------------------*/
Jonathan738 4:8afc50a3e4ac 112 void Terminal::checkKEY(void)
Jonathan738 4:8afc50a3e4ac 113 {
Jonathan738 4:8afc50a3e4ac 114 // read char in buffer and save as gotkey
Jonathan738 4:8afc50a3e4ac 115 char gotkey;
Jonathan738 4:8afc50a3e4ac 116 gotkey=pc.getc();
Jonathan738 4:8afc50a3e4ac 117
Jonathan738 4:8afc50a3e4ac 118 // if not byte is found do nothing and exit
Jonathan738 4:8afc50a3e4ac 119 if(gotkey == NULL) {
Jonathan738 4:8afc50a3e4ac 120 // do nothing
Jonathan738 4:8afc50a3e4ac 121
Jonathan738 4:8afc50a3e4ac 122 // if key is enter (carridge return) call handleCOMMAND function
Jonathan738 4:8afc50a3e4ac 123 } else if (gotkey == 0x0D) {
Jonathan738 4:8afc50a3e4ac 124 Terminal_buffer[buffer_pointer] = 0x00;
Jonathan738 4:8afc50a3e4ac 125 TerminalQueue.call(&PC, &Terminal::HandleCOMMAND);
Jonathan738 4:8afc50a3e4ac 126 buffer_pointer = 0;
Jonathan738 4:8afc50a3e4ac 127 Cursor((24),(Rows+6));
Jonathan738 4:8afc50a3e4ac 128 pc.printf(" ");
Jonathan738 4:8afc50a3e4ac 129
Jonathan738 4:8afc50a3e4ac 130 // if key entered is backspace print " " over last printed char and shift bufferpointer back
Jonathan738 4:8afc50a3e4ac 131 } else if (gotkey == 0x7f) {
Jonathan738 4:8afc50a3e4ac 132 if (buffer_pointer > 0) {
Jonathan738 4:8afc50a3e4ac 133 buffer_pointer -= 1;
Jonathan738 4:8afc50a3e4ac 134 Cursor((24 + buffer_pointer),(Rows+6));
Jonathan738 4:8afc50a3e4ac 135 pc.printf(" ");
Jonathan738 4:8afc50a3e4ac 136 } else {
Jonathan738 4:8afc50a3e4ac 137 //do nothing
Jonathan738 4:8afc50a3e4ac 138 }
Jonathan738 4:8afc50a3e4ac 139
Jonathan738 4:8afc50a3e4ac 140 // if input not specific command save the char to the internal buffer
Jonathan738 4:8afc50a3e4ac 141 } else {
Jonathan738 4:8afc50a3e4ac 142 Colour(ColourWHITE);
Jonathan738 4:8afc50a3e4ac 143 if(buffer_pointer == 30) {
Jonathan738 4:8afc50a3e4ac 144 // do error thing
Jonathan738 4:8afc50a3e4ac 145 } else {
Jonathan738 4:8afc50a3e4ac 146 pc.printf("\x1b[4m");
Jonathan738 4:8afc50a3e4ac 147 Cursor((24 + buffer_pointer),(Rows+6));
Jonathan738 4:8afc50a3e4ac 148 Colour(ColourWHITE);
Jonathan738 4:8afc50a3e4ac 149 pc.printf("%c",gotkey);
Jonathan738 4:8afc50a3e4ac 150 pc.printf("\x1b[24m");
Jonathan738 4:8afc50a3e4ac 151 Terminal_buffer[buffer_pointer] = gotkey;
Jonathan738 4:8afc50a3e4ac 152 buffer_pointer++;
Jonathan738 4:8afc50a3e4ac 153 }
Jonathan738 4:8afc50a3e4ac 154 }
Jonathan738 4:8afc50a3e4ac 155 // re attach the interupt on the serial input flag
Jonathan738 4:8afc50a3e4ac 156 pc.attach(this, &Terminal::Input_Handler,pc.RxIrq);
Jonathan738 7:2796f0b5228d 157 wait_ms(100);
Jonathan738 4:8afc50a3e4ac 158 }
Jonathan738 4:8afc50a3e4ac 159
Jonathan738 4:8afc50a3e4ac 160 /*------------------------------------------------------------------------------
Jonathan738 4:8afc50a3e4ac 161 Function decodes command that has been input on input command line and performs
Jonathan738 4:8afc50a3e4ac 162 any necasary action
Jonathan738 4:8afc50a3e4ac 163 ------------------------------------------------------------------------------*/
Jonathan738 4:8afc50a3e4ac 164 void Terminal::HandleCOMMAND(void)
Jonathan738 4:8afc50a3e4ac 165 {
Jonathan738 4:8afc50a3e4ac 166 int commandSize = 0;
Jonathan738 4:8afc50a3e4ac 167 int dataSIZE = 0;
Jonathan738 4:8afc50a3e4ac 168 bool searchingCOMMAND = true;
Jonathan738 4:8afc50a3e4ac 169 bool searchingDATA = true;
Jonathan738 4:8afc50a3e4ac 170 while(searchingCOMMAND) {
Jonathan738 4:8afc50a3e4ac 171 if((Terminal_buffer[commandSize] == ' ') || (Terminal_buffer[commandSize] == 0x00)) {
Jonathan738 4:8afc50a3e4ac 172 searchingCOMMAND = false;
Jonathan738 4:8afc50a3e4ac 173 } else {
Jonathan738 4:8afc50a3e4ac 174 commandSize++;
Jonathan738 4:8afc50a3e4ac 175 }
Jonathan738 4:8afc50a3e4ac 176
Jonathan738 4:8afc50a3e4ac 177 // debug break loop if too big
Jonathan738 8:e406c6f728bd 178 if(commandSize > 4) {
Jonathan738 4:8afc50a3e4ac 179 break;
Jonathan738 4:8afc50a3e4ac 180 }
Jonathan738 4:8afc50a3e4ac 181 }
Jonathan738 4:8afc50a3e4ac 182 while(searchingDATA) {
Jonathan738 4:8afc50a3e4ac 183 if((Terminal_buffer[commandSize+dataSIZE+1] == ' ') || (Terminal_buffer[commandSize+dataSIZE+1] == 0x00)) {
Jonathan738 4:8afc50a3e4ac 184 searchingDATA = false;
Jonathan738 4:8afc50a3e4ac 185 } else {
Jonathan738 4:8afc50a3e4ac 186 dataSIZE++;
Jonathan738 4:8afc50a3e4ac 187 }
Jonathan738 4:8afc50a3e4ac 188
Jonathan738 4:8afc50a3e4ac 189 // debug break loop if too big
Jonathan738 8:e406c6f728bd 190 if(dataSIZE > 3) {
Jonathan738 4:8afc50a3e4ac 191 break;
Jonathan738 4:8afc50a3e4ac 192 }
Jonathan738 4:8afc50a3e4ac 193 }
Jonathan738 8:e406c6f728bd 194
Jonathan738 8:e406c6f728bd 195 if(commandSize == 4) {
Jonathan738 8:e406c6f728bd 196 // Action for input of MOVE command
Jonathan738 8:e406c6f728bd 197 if((Terminal_buffer[0] == 'M') && (Terminal_buffer[1] == 'O') && (Terminal_buffer[2] == 'V') && (Terminal_buffer[3] == 'E')) {
Jonathan738 8:e406c6f728bd 198 if(dataSIZE != 3) {
Jonathan738 8:e406c6f728bd 199 Error msgs;
Jonathan738 8:e406c6f728bd 200 msgs.ErrorCode = warning;
Jonathan738 8:e406c6f728bd 201 msgs.TimeStamp = "TimeStamp";
Jonathan738 8:e406c6f728bd 202 msgs.ErrorMSGS = "input Value is not valid for command \"MOVE\"";
Jonathan738 8:e406c6f728bd 203 ERROR_MSGS(msgs);
Jonathan738 8:e406c6f728bd 204 } else if((Terminal_buffer[4] != ' ') || (Terminal_buffer[6] != '.')) {
Jonathan738 8:e406c6f728bd 205 Error msgs;
Jonathan738 8:e406c6f728bd 206 msgs.ErrorCode = warning;
Jonathan738 8:e406c6f728bd 207 msgs.TimeStamp = "TimeStamp";
Jonathan738 8:e406c6f728bd 208 msgs.ErrorMSGS = "Value input is incorrect format for command \"READ\"";
Jonathan738 8:e406c6f728bd 209 ERROR_MSGS(msgs);
Jonathan738 8:e406c6f728bd 210 } else {
Jonathan738 8:e406c6f728bd 211 float inputVAL;
Jonathan738 8:e406c6f728bd 212 BYTE tempARRAY[4] = {'0', Terminal_buffer[5], Terminal_buffer[6], Terminal_buffer[7]};
Jonathan738 8:e406c6f728bd 213 inputVAL = strTOflt(tempARRAY);
Jonathan738 8:e406c6f728bd 214
Jonathan738 8:e406c6f728bd 215 char buffer_Temp[20];
Jonathan738 8:e406c6f728bd 216 sprintf(buffer_Temp, "%1.1f", inputVAL);
Jonathan738 8:e406c6f728bd 217 printDEBUG(buffer_Temp);
Jonathan738 8:e406c6f728bd 218
Jonathan738 8:e406c6f728bd 219 }
Jonathan738 8:e406c6f728bd 220 }
Jonathan738 8:e406c6f728bd 221 }
Jonathan738 4:8afc50a3e4ac 222 }
Jonathan738 4:8afc50a3e4ac 223
Jonathan738 4:8afc50a3e4ac 224 /*------------------------------------------------------------------------------
Jonathan738 4:8afc50a3e4ac 225 ISR for whenever data is in terminal buffer, add function to terminal queue
Jonathan738 4:8afc50a3e4ac 226 to check which charecteter has been entered and add it to a buffer.
Jonathan738 4:8afc50a3e4ac 227 ------------------------------------------------------------------------------*/
Jonathan738 4:8afc50a3e4ac 228 void Terminal::Input_Handler(void)
Jonathan738 8:e406c6f728bd 229 {
Jonathan738 8:e406c6f728bd 230 char gotkey;
Jonathan738 8:e406c6f728bd 231 pc.attach(0);
Jonathan738 8:e406c6f728bd 232 gotkey=pc.getc();
Jonathan738 4:8afc50a3e4ac 233 // remove the interupt from the serial input flag
Jonathan738 8:e406c6f728bd 234 //pc.attach(NULL,pc.RxIrq);
Jonathan738 8:e406c6f728bd 235 debugLED_temp = 1;
Jonathan738 4:8afc50a3e4ac 236 // if data is in the buffer call function to check which key has been entered
Jonathan738 8:e406c6f728bd 237 if(pc.readable()!= 0)
Jonathan738 8:e406c6f728bd 238 {
Jonathan738 4:8afc50a3e4ac 239 TerminalQueue.call(&PC, &Terminal::checkKEY);
Jonathan738 8:e406c6f728bd 240
Jonathan738 8:e406c6f728bd 241 // if no data present in the buffer re attach the interupt
Jonathan738 4:8afc50a3e4ac 242 } else {
Jonathan738 4:8afc50a3e4ac 243 pc.attach(this, &Terminal::Input_Handler,pc.RxIrq);
Jonathan738 4:8afc50a3e4ac 244 }
Jonathan738 4:8afc50a3e4ac 245 }
Jonathan738 4:8afc50a3e4ac 246
Jonathan738 4:8afc50a3e4ac 247 /*------------------------------------------------------------------------------
Jonathan738 4:8afc50a3e4ac 248 Function prints debug messages to screen
Jonathan738 4:8afc50a3e4ac 249 ------------------------------------------------------------------------------*/
Jonathan738 4:8afc50a3e4ac 250 void Terminal::printDEBUG(char* msgs)
Jonathan738 4:8afc50a3e4ac 251 {
Jonathan738 4:8afc50a3e4ac 252 // first delete any messages shown in the debug line
Jonathan738 4:8afc50a3e4ac 253 Cursor(3,(Rows+8));
Jonathan738 4:8afc50a3e4ac 254 Colour(ColourWHITE);
Jonathan738 4:8afc50a3e4ac 255 pc.printf(" ");
Jonathan738 4:8afc50a3e4ac 256 // now print the new data to the line
Jonathan738 4:8afc50a3e4ac 257 Cursor(3,(Rows+8));
Jonathan738 4:8afc50a3e4ac 258 pc.printf(msgs);
Jonathan738 4:8afc50a3e4ac 259 }
Jonathan738 4:8afc50a3e4ac 260
Jonathan738 4:8afc50a3e4ac 261 /*------------------------------------------------------------------------------
Jonathan738 4:8afc50a3e4ac 262 Function prints ERROR messages to screen
Jonathan738 4:8afc50a3e4ac 263 ------------------------------------------------------------------------------*/
Jonathan738 4:8afc50a3e4ac 264 void Terminal::ERROR_MSGS(Error msgs)
Jonathan738 4:8afc50a3e4ac 265 {
Jonathan738 4:8afc50a3e4ac 266 // first delete any messages shown in the debug line
Jonathan738 4:8afc50a3e4ac 267 Cursor(3,(Rows+8));
Jonathan738 4:8afc50a3e4ac 268 pc.printf(" ");
Jonathan738 4:8afc50a3e4ac 269 Cursor(3,(Rows+8));
Jonathan738 4:8afc50a3e4ac 270
Jonathan738 4:8afc50a3e4ac 271 // Print diferent messages dependent on the Error code attached in the struct Error
Jonathan738 4:8afc50a3e4ac 272 switch(msgs.ErrorCode) {
Jonathan738 4:8afc50a3e4ac 273 case warning :
Jonathan738 4:8afc50a3e4ac 274 Colour(ColourYELLOW);
Jonathan738 8:e406c6f728bd 275 PrintDATA("Warning", CurrentIDX);
Jonathan738 8:e406c6f728bd 276 PrintDATA(msgs.TimeStamp, CurrentIDX+1);
Jonathan738 8:e406c6f728bd 277 PrintDATA(msgs.ErrorMSGS, CurrentIDX+2);
Jonathan738 4:8afc50a3e4ac 278 break;
Jonathan738 4:8afc50a3e4ac 279
Jonathan738 4:8afc50a3e4ac 280 case fault :
Jonathan738 4:8afc50a3e4ac 281 Colour(ColourAMBER);
Jonathan738 8:e406c6f728bd 282 PrintDATA("Fault", CurrentIDX);
Jonathan738 8:e406c6f728bd 283 PrintDATA(msgs.TimeStamp, CurrentIDX+1);
Jonathan738 8:e406c6f728bd 284 PrintDATA(msgs.ErrorMSGS, CurrentIDX+2);
Jonathan738 4:8afc50a3e4ac 285 break;
Jonathan738 4:8afc50a3e4ac 286
Jonathan738 4:8afc50a3e4ac 287 case criticalERROR :
Jonathan738 4:8afc50a3e4ac 288 Colour(ColourRED);
Jonathan738 8:e406c6f728bd 289 PrintDATA("Critical ERROR", CurrentIDX);
Jonathan738 8:e406c6f728bd 290 PrintDATA(msgs.TimeStamp, CurrentIDX+1);
Jonathan738 8:e406c6f728bd 291 PrintDATA(msgs.ErrorMSGS, CurrentIDX+2);
Jonathan738 4:8afc50a3e4ac 292 break;
Jonathan738 4:8afc50a3e4ac 293
Jonathan738 4:8afc50a3e4ac 294 case criticalFAILURE :
Jonathan738 4:8afc50a3e4ac 295 Colour(ColourRED);
Jonathan738 8:e406c6f728bd 296 PrintDATA("Critical FAILURE", CurrentIDX);
Jonathan738 8:e406c6f728bd 297 PrintDATA(msgs.TimeStamp, CurrentIDX+1);
Jonathan738 8:e406c6f728bd 298 PrintDATA(msgs.ErrorMSGS, CurrentIDX+2);
Jonathan738 5:207e0cd8b9de 299 break;
Jonathan738 8:e406c6f728bd 300
Jonathan738 8:e406c6f728bd 301 default :
Jonathan738 4:8afc50a3e4ac 302 // This point should never be reached as it would indicate a full
Jonathan738 4:8afc50a3e4ac 303 // failure which would cause the watchdog to reset the system
Jonathan738 4:8afc50a3e4ac 304 break;
Jonathan738 4:8afc50a3e4ac 305 }
Jonathan738 8:e406c6f728bd 306
Jonathan738 8:e406c6f728bd 307 if(CurrentIDX > MaxDATA-6)
Jonathan738 8:e406c6f728bd 308 {
Jonathan738 8:e406c6f728bd 309 CurrentIDX = 0;
Jonathan738 8:e406c6f728bd 310 } else {
Jonathan738 8:e406c6f728bd 311 CurrentIDX += 3;
Jonathan738 8:e406c6f728bd 312 }
Jonathan738 4:8afc50a3e4ac 313 }
Jonathan738 4:8afc50a3e4ac 314
Jonathan738 4:8afc50a3e4ac 315 /*------------------------------------------------------------------------------
Jonathan738 4:8afc50a3e4ac 316 Function converts string to float, one decimal place expected must be 4 bytes
Jonathan738 4:8afc50a3e4ac 317 long, PAd with '0', example 1.2f would be "01.2" and 12.3f would be "12.3"
Jonathan738 4:8afc50a3e4ac 318 ------------------------------------------------------------------------------*/
Jonathan738 4:8afc50a3e4ac 319 float strTOflt(char ary[4])
Jonathan738 4:8afc50a3e4ac 320 {
Jonathan738 4:8afc50a3e4ac 321 //check that values entered are in format "00.0"
Jonathan738 4:8afc50a3e4ac 322 for(int tester = 0; tester < 4; tester++) {
Jonathan738 4:8afc50a3e4ac 323 if(tester != 2) {
Jonathan738 4:8afc50a3e4ac 324 int testing = (int)(ary[tester]-'0');
Jonathan738 4:8afc50a3e4ac 325 if((testing > 9) || (testing < 0)) {
Jonathan738 4:8afc50a3e4ac 326 return NULL;
Jonathan738 4:8afc50a3e4ac 327 }
Jonathan738 4:8afc50a3e4ac 328 } else if(ary[tester] != '.') {
Jonathan738 4:8afc50a3e4ac 329 return NULL;
Jonathan738 4:8afc50a3e4ac 330 }
Jonathan738 4:8afc50a3e4ac 331 }
Jonathan738 4:8afc50a3e4ac 332
Jonathan738 4:8afc50a3e4ac 333 float retFlt;
Jonathan738 4:8afc50a3e4ac 334
Jonathan738 4:8afc50a3e4ac 335 retFlt = ((float)(ary[0]-'0'))*10.0f;
Jonathan738 4:8afc50a3e4ac 336 retFlt += ((float)(ary[1]-'0'));
Jonathan738 4:8afc50a3e4ac 337 retFlt += ((float)(ary[3]-'0'))/10.0f;
Jonathan738 4:8afc50a3e4ac 338
Jonathan738 4:8afc50a3e4ac 339 if(retFlt > 60.0f) {
Jonathan738 4:8afc50a3e4ac 340 return NULL;
Jonathan738 4:8afc50a3e4ac 341 } else {
Jonathan738 4:8afc50a3e4ac 342 return retFlt;
Jonathan738 4:8afc50a3e4ac 343 }
Jonathan738 4:8afc50a3e4ac 344 }
Jonathan738 4:8afc50a3e4ac 345
Jonathan738 4:8afc50a3e4ac 346 /*------------------------------------------------------------------------------
Jonathan738 4:8afc50a3e4ac 347 Function converts string to int.
Jonathan738 4:8afc50a3e4ac 348 expected format allows upto 3 digits, 1 to 999
Jonathan738 4:8afc50a3e4ac 349 ------------------------------------------------------------------------------*/
Jonathan738 4:8afc50a3e4ac 350 int strTOint(char ary[3])
Jonathan738 4:8afc50a3e4ac 351 {
Jonathan738 4:8afc50a3e4ac 352 //check that values entered are in format "000"
Jonathan738 4:8afc50a3e4ac 353 for(int tester = 0; tester < 3; tester++) {
Jonathan738 4:8afc50a3e4ac 354 int testing = (int)(ary[tester]-'0');
Jonathan738 4:8afc50a3e4ac 355 if((testing > 9) || (testing < 0)) {
Jonathan738 4:8afc50a3e4ac 356 return NULL;
Jonathan738 4:8afc50a3e4ac 357 }
Jonathan738 4:8afc50a3e4ac 358 }
Jonathan738 4:8afc50a3e4ac 359
Jonathan738 4:8afc50a3e4ac 360 int temp_int = (int)(ary[0]-'0')*100;
Jonathan738 4:8afc50a3e4ac 361 temp_int += (int)(ary[1]-'0')*10;
Jonathan738 4:8afc50a3e4ac 362 temp_int += (int)(ary[2]-'0');
Jonathan738 4:8afc50a3e4ac 363
Jonathan738 4:8afc50a3e4ac 364 return temp_int;
Jonathan738 4:8afc50a3e4ac 365 }
Jonathan738 4:8afc50a3e4ac 366 /*------------------------------------------------------------------------------
Jonathan738 4:8afc50a3e4ac 367 Function to create and send an error message
Jonathan738 4:8afc50a3e4ac 368 ------------------------------------------------------------------------------*/
Jonathan738 4:8afc50a3e4ac 369 void Flag_Error(int ErrorCode, char* ErrorMSG)
Jonathan738 4:8afc50a3e4ac 370 {
Jonathan738 8:e406c6f728bd 371 //BYTE SampleTimeTag [20];
Jonathan738 7:2796f0b5228d 372 //strcpy(SampleTimeTag, getSystemDateTime());
Jonathan738 8:e406c6f728bd 373
Jonathan738 4:8afc50a3e4ac 374 Error msgs;
Jonathan738 4:8afc50a3e4ac 375 msgs.ErrorCode = ErrorCode;
Jonathan738 7:2796f0b5228d 376 msgs.TimeStamp = "Temp";
Jonathan738 4:8afc50a3e4ac 377 msgs.ErrorMSGS = ErrorMSG;
Jonathan738 4:8afc50a3e4ac 378 TerminalQueue.call(&PC, &Terminal::ERROR_MSGS, msgs);
firnenenrif 6:3872858b7844 379 }