Plymouth ELEC351 Group T
/
ELEC351_Group_T
FINAL PROJECT isn't it
Fork of ELEC351 by
Diff: SERIAL_COMMANDS.cpp
- Revision:
- 57:aba1296e51b1
- Parent:
- 56:bc5345bc6650
diff -r bc5345bc6650 -r aba1296e51b1 SERIAL_COMMANDS.cpp --- a/SERIAL_COMMANDS.cpp Mon Jul 16 10:51:47 2018 +0000 +++ b/SERIAL_COMMANDS.cpp Wed Aug 15 21:34:59 2018 +0000 @@ -5,6 +5,10 @@ int direction = 1; int Motor_To_Select = 1; float angle = 0; +bool move_loop = 0; +bool List_move_loop = 0; + + //Mutex Locks void Serial_Commands_Output() //Used for getting input from the user to determine the opperations to perform @@ -14,18 +18,11 @@ 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 - - } + cin.getline(input,sizeof(input),'\r'); //Scan into input from the start of the line to the return character + //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] == ' ') + 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 @@ -33,12 +30,7 @@ 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 Serial\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 + else if (NumberToLogging == 1){pc.printf("LOGGING SPI\n");} //Logging SPI if (NumberToLogging <= 5){Log_Value = NumberToLogging;} //If inputted value is within bounds equate it to the log state } @@ -81,21 +73,236 @@ //MOVE else if(input[0] == 'M' & input[1] == 'O' & input[2] == 'V' & input[3] == 'E') { - pc.printf("Enter the Move\n"); //Request command in the terminal - cin.getline(input,sizeof(input),'\r');; - if(input[0] == 'C' & input[1] == 'L') + move_loop = 1; + pc.printf("Enter the Move\n"); //Request command in the terminal + while(move_loop == 1) + { + cin.getline(input,sizeof(input),'\r'); + + if(input[0] == 'A' & input[1] == 'F'){STEPPER_MOTOR_1.Rotate_Steps(50 ,1);} + else if(input[0] == 'C' & input[1] == 'F'){STEPPER_MOTOR_1.Rotate_Steps(50 ,0);} + else if(input[0] == 'A' & input[1] == 'B'){STEPPER_MOTOR_2.Rotate_Steps(50 ,1);} + else if(input[0] == 'C' & input[1] == 'B'){STEPPER_MOTOR_2.Rotate_Steps(50 ,0);} + else if(input[0] == 'A' & input[1] == 'L'){STEPPER_MOTOR_3.Rotate_Steps(50 ,1);} + else if(input[0] == 'C' & input[1] == 'L'){STEPPER_MOTOR_3.Rotate_Steps(50 ,0);} + else if(input[0] == 'A' & input[1] == 'R'){STEPPER_MOTOR_4.Rotate_Steps(50 ,1);} + else if(input[0] == 'C' & input[1] == 'R'){STEPPER_MOTOR_4.Rotate_Steps(50 ,0);} + else if(input[0] == 'A' & input[1] == 'U'){STEPPER_MOTOR_5.Rotate_Steps(50 ,1);} + else if(input[0] == 'C' & input[1] == 'U'){STEPPER_MOTOR_5.Rotate_Steps(50 ,0);} + else if(input[0] == 'A' & input[1] == 'D'){STEPPER_MOTOR_6.Rotate_Steps(50 ,1);} + else if(input[0] == 'C' & input[1] == 'D'){STEPPER_MOTOR_6.Rotate_Steps(50 ,0);} + else if(input[0] == 'M' & input[1] == 'O' & input[2] == 'V' & input[3] == 'E') + { + move_loop = 0; + pc.printf("Exiting Move loop\n"); + //Exit moves function + } + else + { + pc.printf("Error please enter a allowed move\n"); + //Error case + } + + } + } + //LIST + else if(input[0] == 'L' & input[1] == 'I' & input[2] == 'S' & input[3] == 'T')//This is where the move list shall be added to + { + List_move_loop = 1; + pc.printf("Entered the Move_List Section\n"); //Request command in the terminal + while(List_move_loop == 1) + { + cin.getline(input,sizeof(input),'\r'); + + if(input[0] == 'A' & input[1] == 'F'){Move_list[Move_list_pointer] = 1; Move_list_pointer = Move_list_pointer + 1;} + else if(input[0] == 'C' & input[1] == 'F'){Move_list[Move_list_pointer] = 2; Move_list_pointer = Move_list_pointer + 1;} + else if(input[0] == 'A' & input[1] == 'B'){Move_list[Move_list_pointer] = 3; Move_list_pointer = Move_list_pointer + 1;} + else if(input[0] == 'C' & input[1] == 'B'){Move_list[Move_list_pointer] = 4; Move_list_pointer = Move_list_pointer + 1;} + else if(input[0] == 'A' & input[1] == 'L'){Move_list[Move_list_pointer] = 5; Move_list_pointer = Move_list_pointer + 1;} + else if(input[0] == 'C' & input[1] == 'L'){Move_list[Move_list_pointer] = 6; Move_list_pointer = Move_list_pointer + 1;} + else if(input[0] == 'A' & input[1] == 'R'){Move_list[Move_list_pointer] = 7; Move_list_pointer = Move_list_pointer + 1;} + else if(input[0] == 'C' & input[1] == 'R'){Move_list[Move_list_pointer] = 8; Move_list_pointer = Move_list_pointer + 1;} + else if(input[0] == 'A' & input[1] == 'U'){Move_list[Move_list_pointer] = 9; Move_list_pointer = Move_list_pointer + 1;} + else if(input[0] == 'C' & input[1] == 'U'){Move_list[Move_list_pointer] = 10;Move_list_pointer = Move_list_pointer + 1;} + else if(input[0] == 'A' & input[1] == 'D'){Move_list[Move_list_pointer] = 11;Move_list_pointer = Move_list_pointer + 1;} + else if(input[0] == 'C' & input[1] == 'D'){Move_list[Move_list_pointer] = 12;Move_list_pointer = Move_list_pointer + 1;} + + + else if(input[0] == 'D' & input[1] == 'E' & input[2] == 'L' & input[3] == 'E' & input[4] =='T' & input[5] == 'E') + { + pc.printf("Delete Clear Test\n"); + memset(Move_list, 0, sizeof(Move_list)); + Move_list_pointer = 0; + pc.printf("Move List array and pointer reset\n"); + List_move_loop = 0; + pc.printf("Exiting Move List loop\n"); + } + else if(input[0] == 'L' & input[1] == 'I' & input[2] == 'S' & input[3] == 'T') + { + List_move_loop = 0; + pc.printf("Exiting Move List loop\n"); + //Exit moves function + } + else if(input[0] == 'R' & input[1] == 'E' & input[2] == 'A' & input[3] == 'D') + { + pc.printf("Printing out the move list\n"); + for(int i=0;i <= Move_list_pointer; i+=1) + { + pc.printf("Value %d is %d\n",i,Move_list[i]); + } + pc.printf("Move List test passed\n"); + List_move_loop = 0; + pc.printf("Exiting Move List loop\n"); + //Exit moves function + } + else if(input[0] == 'R' & input[1] == 'U' & input[2] == 'N') + { + List_move_loop = 0; + { + pc.printf("Move point value is : %d\n",Move_list_pointer); + for(int i = 0; i<= Move_list_pointer; i += 1) + { + if(Move_list[i] == 0){pc.printf("Move List Finished\n");} + else if (Move_list[i] == 1){STEPPER_MOTOR_1.Rotate_Steps(50 ,1);} + else if (Move_list[i] == 2){STEPPER_MOTOR_1.Rotate_Steps(50 ,0);} + else if (Move_list[i] == 3){STEPPER_MOTOR_2.Rotate_Steps(50 ,1);} + else if (Move_list[i] == 4){STEPPER_MOTOR_2.Rotate_Steps(50 ,0);} + else if (Move_list[i] == 5){STEPPER_MOTOR_3.Rotate_Steps(50 ,1);} + else if (Move_list[i] == 6){STEPPER_MOTOR_3.Rotate_Steps(50 ,0);} + else if (Move_list[i] == 7){STEPPER_MOTOR_4.Rotate_Steps(50 ,1);} + else if (Move_list[i] == 8){STEPPER_MOTOR_4.Rotate_Steps(50 ,0);} + else if (Move_list[i] == 9){STEPPER_MOTOR_5.Rotate_Steps(50 ,1);} + else if (Move_list[i] == 10){STEPPER_MOTOR_5.Rotate_Steps(50 ,0);} + else if (Move_list[i] == 11){STEPPER_MOTOR_6.Rotate_Steps(50 ,1);} + else if (Move_list[i] == 12){STEPPER_MOTOR_6.Rotate_Steps(50 ,0);} + else pc.printf("Finished\n"); + } + pc.printf("List Run sucessful\n"); + } + pc.printf("List execution finished\n"); + } + //TEST RUN + else if(input[0] == 'T' & input[1] == 'E' & input[2] == 'S' & input[3] == 'T' & input[4] == '_' & input[5] == 'R' & input[6] == 'U' & input[7] == 'N')//This is the test run code + { + memset(Move_list, 0, sizeof(Move_list)); + Move_list_pointer = 0; + Move_list[Move_list_pointer] = 1 ;Move_list_pointer = Move_list_pointer + 1; + Move_list[Move_list_pointer] = 2 ;Move_list_pointer = Move_list_pointer + 1; + Move_list[Move_list_pointer] = 3 ;Move_list_pointer = Move_list_pointer + 1; + Move_list[Move_list_pointer] = 4 ;Move_list_pointer = Move_list_pointer + 1; + Move_list[Move_list_pointer] = 5 ;Move_list_pointer = Move_list_pointer + 1; + Move_list[Move_list_pointer] = 6 ;Move_list_pointer = Move_list_pointer + 1; + Move_list[Move_list_pointer] = 7 ;Move_list_pointer = Move_list_pointer + 1; + Move_list[Move_list_pointer] = 8 ;Move_list_pointer = Move_list_pointer + 1; + Move_list[Move_list_pointer] = 9 ;Move_list_pointer = Move_list_pointer + 1; + Move_list[Move_list_pointer] = 10 ;Move_list_pointer = Move_list_pointer + 1; + Move_list[Move_list_pointer] = 11 ;Move_list_pointer = Move_list_pointer + 1; + Move_list[Move_list_pointer] = 12 ;Move_list_pointer = Move_list_pointer + 1; + + pc.printf("Array filled for test\n"); + List_move_loop = 0; + pc.printf("Exiting Move List loop\n"); + } + else + { + pc.printf("Error please enter a allowed move\n"); + //Error case + } + + } + } + //Colours + if(input[0] == 'C' & input[1] == 'O' & input[2] == 'L' & input[3] == 'O' & input[4] == 'U' & input[5] == 'R' & input[6] == 'S' & input[7] == ' ') { - pc.printf("Test Successful\n"); + int NumberOfChars = 0; int ArrayAddress = 0; string COLOURSNUBMER; int NUMBERTOCOLOUR; //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++){COLOURSNUBMER += input[x];} //Concatenate the characters between the space and the end + stringstream Number(COLOURSNUBMER); //Convert string to stringstream + Number >> NUMBERTOCOLOUR; + int n = NUMBERTOCOLOUR -1 ; //Convert stringstream to integer + pc.printf("Showing side %D\n",NUMBERTOCOLOUR); + + + pc.printf("%c,%c,%c\n%c,%c,%c\n%c,%c,%c\n", + Value_convert(CubeMap[n][0][0]),Value_convert(CubeMap[n][0][1]),Value_convert(CubeMap[n][0][2]) + ,Value_convert(CubeMap[n][1][0]),Value_convert(CubeMap[n][1][1]),Value_convert(CubeMap[n][1][2]) + ,Value_convert(CubeMap[n][2][0]),Value_convert(CubeMap[n][2][1]),Value_convert(CubeMap[n][2][2]));;//Side n + + + } + //SIDE_ADD + if(input[0] == 'S' & input[1] == 'I' & input[2] == 'D' & input[3] == 'E' & input[4] == '_' & input[5] == 'A' & input[6] == 'D' & input[7] == 'D' & input[8] == ' ') + { + int NumberOfChars = 0; int ArrayAddress = 0; string SIDENUMBER; int NUMBERTOSIDE; //Declare required variables + while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} //Count the number of characters entered into the console + for(int x=9; x < NumberOfChars; x++){SIDENUMBER += input[x];} //Concatenate the characters between the space and the end + stringstream Number(SIDENUMBER); //Convert string to stringstream + Number >> NUMBERTOSIDE; + pc.printf("Please enter in the colour of segment 1:\n"); + int Colour_value; + cin >>Colour_value; + NUMBERTOSIDE = NUMBERTOSIDE - 1; + + CubeMap[NUMBERTOSIDE][0][0] = convert(Colour_value); + pc.printf("Please enter in the colour of segment 2:\n"); + cin >>Colour_value; + CubeMap[NUMBERTOSIDE][0][1] = convert(Colour_value); + pc.printf("Please enter in the colour of segment 3:\n"); + cin >>Colour_value; + CubeMap[NUMBERTOSIDE][0][2] = convert(Colour_value); + pc.printf("Please enter in the colour of segment 4:\n"); + cin >>Colour_value; + CubeMap[NUMBERTOSIDE][1][0] = convert(Colour_value); + pc.printf("Please enter in the colour of segment 5:\n"); + cin >>Colour_value; + CubeMap[NUMBERTOSIDE][1][1] = convert(Colour_value); + pc.printf("Please enter in the colour of segment 6:\n"); + cin >>Colour_value; + CubeMap[NUMBERTOSIDE][1][2] = convert(Colour_value); + pc.printf("Please enter in the colour of segment 7:\n"); + cin >>Colour_value; + CubeMap[NUMBERTOSIDE][2][0] = convert(Colour_value); + pc.printf("Please enter in the colour of segment 8:\n"); + cin >>Colour_value; + CubeMap[NUMBERTOSIDE][2][1] = convert(Colour_value); + pc.printf("Please enter in the colour of segment 9:\n"); + cin >>Colour_value; + CubeMap[NUMBERTOSIDE][2][2] = convert(Colour_value); + pc.printf("Side filled\n"); + cin.getline(input,sizeof(input),'\r'); + } + //SIDE_CLEAR + if(input[0] == 'S' & input[1] == 'I' & input[2] == 'D' & input[3] == 'E' & input[4] == '_' & input[5] == 'C' & input[6] == 'L' & input[7] == 'E' & input[8] == 'A' & input[9] == 'R') + { + + for(int i =0; i<=6;i++) + { + CubeMap[i][0][0] = convert(0); + CubeMap[i][0][1] = convert(0); + CubeMap[i][0][2] = convert(0); + CubeMap[i][1][0] = convert(0); + CubeMap[i][1][1] = convert(0); + CubeMap[i][1][2] = convert(0); + CubeMap[i][2][0] = convert(0); + CubeMap[i][2][1] = convert(0); + CubeMap[i][2][2] = convert(0); + } + pc.printf("All sides cleared of data\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("Motor x selects a motor in the range of 1-6\n"); //Print list of commands + pc.printf("Please specify the function you would like help in\nMOTOR , LOGGING , MOVE \n"); //Print introduction line + cin.getline(input,sizeof(input),'\r'); + if(input[0] == 'M' & input[1] == 'O' & input[2] == 'T' & input[3] == 'O' & input[4] == 'R'){pc.printf("Motor x selects a motor in the range of 1-6\nThen you issue the angle which is a number either positive or negative\n");} + else if(input[0] == 'L' & input[1] == 'O' & input[2] == 'G' & input[3] == 'G' & input[4] == 'I' & input[5] == 'N' & input[6] == 'G'){pc.printf("Logging enables to user to get more information from the specific area which is logged\n");} + else if(input[0] == 'M' & input[1] == 'O' & input[2] == 'V' & input[3] == 'E'){pc.printf("Allows the user to enter in a movement\n");} + else if(input[0] == 'L' & input[1] == 'I' & input[2] == 'S' & input[3] == 'T'){pc.printf("Allows the user to to view / set a list of movements that can be performed\n");} + else if(input[0] == 'C' & input[1] == 'O' & input[2] == 'L' & input[3] == 'O' & input[4] == 'U' & input[5] == 'R' & input[6] == 'S'){pc.printf("Allows the user to view and set the information upon the cubemap\n");} + else{pc.printf("Enter the specific help area for more information\n");} } else { pc.printf("Please enter an acceptable command\n"); } -} } \ No newline at end of file