Thomas Morris
/
PROJ324_Final
Proj 324 Final
Fork of ELEC351_Group_T by
SERIAL_COMMANDS.cpp
- Committer:
- thomasmorris
- Date:
- 2018-05-07
- Revision:
- 53:71f59e195f06
- Parent:
- 52:99915f5240b2
- Child:
- 55:e0e684531825
File content as of revision 53:71f59e195f06:
#include "SERIAL_COMMANDS.hpp" int NetworkWaitTime; //Waiting time to update the network char input[100] = {}; //Character array initialised to NULL 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 for (int x = 0; x < 100; x++){input[x] = ' ';}; //Fill input with spaces pc.printf("Please type in a command\n"); //Request command in the terminal cin.getline(input,sizeof(input),'\r'); //Scan into input from the start of the line to the return character //cout << "Input is : " << input << endl; //READ ALL if(input[0] == 'R' & input[1] == 'E' & input[2] == 'A' & input[3] == 'D' & input[4] == ' ' & input[5] == 'A' & input[6] == 'L' & input[7] == 'L') { 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] == ' ') { int NumberOfChars = 0; int ArrayAddress = 0; string LoggingNumber; int NumberToLogging; //Declare required variables while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} //Count the number of characters entered into the console for(int x=8; x < NumberOfChars; x++){LoggingNumber += input[x];} //Concatenate the characters between the space and the end stringstream Number(LoggingNumber); //Convert string to stringstream Number >> NumberToLogging; //Convert stringstream to integer if (NumberToLogging == 0){pc.printf("NOT LOGGING\n");} //Not Logging else if (NumberToLogging == 1){pc.printf("LOGGING LCD\n");} //Logging LCD else if (NumberToLogging == 2){pc.printf("LOGGING NETWORKING\n");} //Logging Networking else if (NumberToLogging == 3){pc.printf("LOGGING SAMPLING\n");} //Logging Sampling else if (NumberToLogging == 4){pc.printf("LOGGING SERIAL COMMANDS\n");} //Logging serial commands else if (NumberToLogging == 5){pc.printf("LOGGING SD CARD\n");} //Logging SD card else if (NumberToLogging >= 6){pc.printf("INVALID LOGGING COMMAND\n");} //Invalud Logging Command 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] == ' ') { int NumberOfChars = 0; int ArrayAddress = 0; string MotorNumber; int Motor_Number; //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++){MotorNumber += input[x];} //Concatenate the characters between the space and the end stringstream Number(MotorNumber); //Convert string to stringstream Number >> Motor_Number; //Convert stringstream to integer if(Motor_Number < 1 || Motor_Number > 6) { Motor_Number =0; pc.printf("Please Select a motor from 1-6\n"); } Motor_To_Select = Motor_Number; //Step Control pc.printf("Enter the angle to rotate\n"); //Request command in the terminal scanf("%f",&angle); //cin.getline(input,sizeof(input),'\r'); //Scan into input from the start of the line to the return character //if(input[0] == 'S' & input[1] == 't' & input[2] == 'e' & input[3] == 'p' & input[4] == 's' & input[5] == ' ') { //angle = input; if(angle < 0) { direction = 0; } else { direction = 1; } float new_angle = abs(angle/1.8); 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 } else { pc.printf("Please enter an acceptable command\n"); } }