Thomas Morris
/
PROJ324_Final
Proj 324 Final
Fork of ELEC351_Group_T by
Diff: SERIAL_COMMANDS.cpp
- Revision:
- 55:e0e684531825
- Parent:
- 53:71f59e195f06
- Child:
- 56:bc5345bc6650
diff -r a4c5949707ca -r e0e684531825 SERIAL_COMMANDS.cpp --- a/SERIAL_COMMANDS.cpp Wed May 16 19:57:52 2018 +0000 +++ b/SERIAL_COMMANDS.cpp Thu May 24 13:31:20 2018 +0000 @@ -4,12 +4,9 @@ int steps = 0; int direction = 1; int Motor_To_Select = 1; -float Sample_Rate = 15.0; //Initial sampling rate float angle = 0; -Ticker Sampling_Timer; //Controls Sampling Rate //Mutex Locks -Mutex SERIAL_COMMANDS_Lock; void Serial_Commands_Output() //Used for getting input from the user to determine the opperations to perform { if(Log_Value == 4){pc.printf("In Serial_Commands\n");} //If logging is enabled, print debug statement @@ -25,56 +22,8 @@ { if(Log_Value == 4){pc.printf("READ ALL Confirmed\n");} //If logging is enabled, print debug statement - } - //SETDATE - else if(input[0] == 'S' & input[1] == 'E' & input[2] == 'T' & input[3] == 'D' & input[4] == 'A' & input[5] == 'T' & input[6] == 'E' & input[7] == ' ' & input[10] == ' ' & input[13] == ' ') - { - if(Log_Value == 4){pc.printf("SETDATE Confirmed\n");} //If logging is enabled, print debug statement - string DayNumber, MonthNumber, YearNumber; //Declare required variables - int NumberToDay, NumberToMonth, NumberToYear; //Declare required variables - - for(int x=8; x < 10; x++){DayNumber += input[x];} //Concatenate characters from the first space to the second - stringstream Number_1(DayNumber); //Convert string to stringstream - Number_1 >> NumberToDay; //Convert stringstream to integer - - for(int x=11; x < 13; x++){MonthNumber += input[x];} //Concatenate characters from the second space to the third - stringstream Number_2(MonthNumber); //Convert string to stringstream - Number_2 >> NumberToMonth; //Convert stringstream to integer - - for(int x=14; x < 18; x++){YearNumber += input[x];} //Concatenate characters from the third space to the end - stringstream Number_3(YearNumber); //Convert string to stringstream - Number_3 >> NumberToYear; //Convert stringstream to string - - if(Log_Value == 4){pc.printf("Year Input %d Month Input %d Day Input %d\n",NumberToYear,NumberToMonth,NumberToDay);} //If logging is enabled, print debug statement - - set_new_date(NumberToDay,NumberToMonth,NumberToYear); //Set New Date - pc.printf("DATE UPDATED TO %02d %02d %d\n",NumberToDay,NumberToMonth,NumberToYear); //Print Updated Date - } - - //SETTIME - else if(input[0] == 'S' & input[1] == 'E' & input[2] == 'T' & input[3] == 'T' & input[4] == 'I' & input[5] == 'M' & input[6] == 'E' & input[7] == ' ' & input[10] == ' ' & input[13] == ' ') - { - if(Log_Value == 4){pc.printf("SETTIME Confirmed\n");} //If logging is enabled, print debug statement - string HourNumber, MinuteNumber, SecondNumber; //Declare required variables - int NumberToHour, NumberToMinute, NumberToSecond; //Declare required variables - - for(int x=8; x < 10; x++){HourNumber += input[x];} //Concatenate characters from the third space to the end - stringstream Number_1(HourNumber); //Convert string to stringstream - Number_1 >> NumberToHour; //Convert stringstream to string - - for(int x=11; x < 13; x++){MinuteNumber += input[x];} //Concatenate characters from the third space to the end - stringstream Number_2(MinuteNumber); //Convert string to stringstream - Number_2 >> NumberToMinute; //Convert stringstream to string - - for(int x=14; x < 16; x++){SecondNumber += input[x];} //Concatenate characters from the third space to the end - stringstream Number_3(SecondNumber); //Convert string to stringstream - Number_3 >> NumberToSecond; //Convert stringstream to string - - if(Log_Value == 4){pc.printf("Hour Input %d Minute Input %d Seconds Input %d",NumberToHour,NumberToMinute,NumberToSecond);} //If logging is enabled, print debug statement - - set_new_time(NumberToHour,NumberToMinute,NumberToSecond); //Set New Time - pc.printf("TIME UPDATED TO %02d %02d %02d\n",NumberToHour,NumberToMinute,NumberToSecond); //Print Updated Time } + //LOGGING else if(input[0] == 'L' & input[1] == 'O' & input[2] == 'G' & input[3] == 'G' & input[4] == 'I' & input[5] == 'N' & input[6] == 'G' & input[7] == ' ') { @@ -93,23 +42,7 @@ if (NumberToLogging <= 5){Log_Value = NumberToLogging;} //If inputted value is within bounds equate it to the log state } - //Steps - /* - else if(input[0] == 'S' & input[1] == 't' & input[2] == 'e' & input[3] == 'p' & input[4] == 's' & input[5] == ' ') - { - int NumberOfChars = 0; int ArrayAddress = 0; string SteppingNumber; int NumberToStep; //Declare required variables - while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} //Count the number of characters entered into the console - for(int x=6; x < NumberOfChars; x++){SteppingNumber += input[x];} //Concatenate the characters between the space and the end - stringstream Number(SteppingNumber); //Convert string to stringstream - Number >> NumberToStep; //Convert stringstream to integer - if(NumberToStep <0) - { - NumberToStep =0; - } - steps = NumberToStep; - pc.printf("Number to step is %d\n", steps); - } - */ + //Motor Control else if(input[0] == 'M' & input[1] == 'o' & input[2] == 't' & input[3] == 'o' & input[4] == 'r' & input[5] == ' ') { @@ -133,41 +66,23 @@ //angle = input; if(angle < 0) { - direction = 0; + direction = 0;//Anti Clockwise } else { - direction = 1; + direction = 1;//Clockwise } - float new_angle = abs(angle/1.8); + float new_angle = abs(angle/1.8);//Converts input to steps steps = new_angle; pc.printf("The Motor is: %d\n The Number to step is: %d\n", Motor_Number, steps); } } - //Motor Direction - else if(strcmp(input,"Motor") == 0) - { - motor_direction = 1; - pc.printf("Motor direction set to clockwise\n"); - } - else if(strcmp(input,"AntiClockwise") == 0) - { - motor_direction = 0; - pc.printf("Motor direction set to Anti clockwise\n"); - } - //Test - else if(strcmp(input,"Test") == 0) - { - pc.printf("Test Passed\n"); - } //HELP else if(input[0] == 'H' & input[1] == 'E' & input[2] == 'L' & input[3] == 'P') { pc.printf("Avalible Commands are: \n"); //Print introduction line - pc.printf("READ ALL\nDELETE ALL\nREAD <n>\nDELETE <n>\nSETDATE <dd> <mm> <yyyy>\nSETTIME <hh> <mm> <ss>\n"); //Print list of commands - pc.printf("SETT <T>\nSTATE <x>\nLOGGING <x>\t 1:LCD\t 2:Networking\t 3:Sampling\t 4:Serial Commands\t 5:SD Card\nNETSET <n>\nHELP\n"); //Print list of commands - + pc.printf("Motor x selects a motor in the range of 1-6\n"); //Print list of commands } else {