For coursework of group 3 in SOFT564Z

Dependencies:   Motordriver ros_lib_kinetic

Committer:
Jonathan738
Date:
Mon Dec 02 13:13:15 2019 +0000
Revision:
5:207e0cd8b9de
Parent:
4:8afc50a3e4ac
Child:
6:3872858b7844
Child:
7:2796f0b5228d
Added re-purposed code for date and time management.

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