Thomas Morris
/
PROJ324_Final
Proj 324 Final
Fork of ELEC351_Group_T by
SERIAL_COMMANDS.cpp
- Committer:
- thomasmorris
- Date:
- 2018-05-24
- Revision:
- 55:e0e684531825
- Parent:
- 53:71f59e195f06
- Child:
- 56:bc5345bc6650
File content as of revision 55:e0e684531825:
#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 angle = 0; //Mutex Locks 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 } //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 } //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;//Anti Clockwise } else { direction = 1;//Clockwise } 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); } } //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("Motor x selects a motor in the range of 1-6\n"); //Print list of commands } else { pc.printf("Please enter an acceptable command\n"); } }