Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ELEC351_Group_T by
SERIAL_COMMANDS.cpp@56:bc5345bc6650, 2018-07-16 (annotated)
- Committer:
- thomasmorris
- Date:
- Mon Jul 16 10:51:47 2018 +0000
- Revision:
- 56:bc5345bc6650
- Parent:
- 55:e0e684531825
- Child:
- 57:aba1296e51b1
Moves added to serial;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| thomasmorris | 47:6d128e500875 | 1 | #include "SERIAL_COMMANDS.hpp" |
| thomasmorris | 52:99915f5240b2 | 2 | int NetworkWaitTime; //Waiting time to update the network |
| thomasmorris | 52:99915f5240b2 | 3 | char input[100] = {}; //Character array initialised to NULL |
| thomasmorris | 53:71f59e195f06 | 4 | int steps = 0; |
| thomasmorris | 53:71f59e195f06 | 5 | int direction = 1; |
| thomasmorris | 53:71f59e195f06 | 6 | int Motor_To_Select = 1; |
| thomasmorris | 53:71f59e195f06 | 7 | float angle = 0; |
| thomasmorris | 52:99915f5240b2 | 8 | //Mutex Locks |
| thomasmorris | 52:99915f5240b2 | 9 | |
| thomasmorris | 52:99915f5240b2 | 10 | void Serial_Commands_Output() //Used for getting input from the user to determine the opperations to perform |
| thomasmorris | 47:6d128e500875 | 11 | { |
| thomasmorris | 52:99915f5240b2 | 12 | if(Log_Value == 4){pc.printf("In Serial_Commands\n");} //If logging is enabled, print debug statement |
| thomasmorris | 47:6d128e500875 | 13 | |
| thomasmorris | 52:99915f5240b2 | 14 | for (int x = 0; x < 100; x++){input[x] = ' ';}; //Fill input with spaces |
| thomasmorris | 47:6d128e500875 | 15 | |
| thomasmorris | 52:99915f5240b2 | 16 | pc.printf("Please type in a command\n"); //Request command in the terminal |
| thomasmorris | 52:99915f5240b2 | 17 | cin.getline(input,sizeof(input),'\r'); //Scan into input from the start of the line to the return character |
| thomasmorris | 53:71f59e195f06 | 18 | //cout << "Input is : " << input << endl; |
| thomasmorris | 47:6d128e500875 | 19 | |
| thomasmorris | 52:99915f5240b2 | 20 | //READ ALL |
| thomasmorris | 52:99915f5240b2 | 21 | if(input[0] == 'R' & input[1] == 'E' & input[2] == 'A' & input[3] == 'D' & input[4] == ' ' & input[5] == 'A' & input[6] == 'L' & input[7] == 'L') |
| thomasmorris | 52:99915f5240b2 | 22 | { |
| thomasmorris | 52:99915f5240b2 | 23 | if(Log_Value == 4){pc.printf("READ ALL Confirmed\n");} //If logging is enabled, print debug statement |
| thomasmorris | 53:71f59e195f06 | 24 | |
| thomasmorris | 52:99915f5240b2 | 25 | } |
| thomasmorris | 55:e0e684531825 | 26 | |
| thomasmorris | 52:99915f5240b2 | 27 | //LOGGING |
| thomasmorris | 52:99915f5240b2 | 28 | 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] == ' ') |
| thomasmorris | 52:99915f5240b2 | 29 | { |
| thomasmorris | 52:99915f5240b2 | 30 | int NumberOfChars = 0; int ArrayAddress = 0; string LoggingNumber; int NumberToLogging; //Declare required variables |
| thomasmorris | 52:99915f5240b2 | 31 | while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} //Count the number of characters entered into the console |
| thomasmorris | 52:99915f5240b2 | 32 | for(int x=8; x < NumberOfChars; x++){LoggingNumber += input[x];} //Concatenate the characters between the space and the end |
| thomasmorris | 52:99915f5240b2 | 33 | stringstream Number(LoggingNumber); //Convert string to stringstream |
| thomasmorris | 52:99915f5240b2 | 34 | Number >> NumberToLogging; //Convert stringstream to integer |
| thomasmorris | 52:99915f5240b2 | 35 | if (NumberToLogging == 0){pc.printf("NOT LOGGING\n");} //Not Logging |
| thomasmorris | 56:bc5345bc6650 | 36 | else if (NumberToLogging == 1){pc.printf("LOGGING Serial\n");} //Logging LCD |
| thomasmorris | 52:99915f5240b2 | 37 | else if (NumberToLogging == 2){pc.printf("LOGGING NETWORKING\n");} //Logging Networking |
| thomasmorris | 52:99915f5240b2 | 38 | else if (NumberToLogging == 3){pc.printf("LOGGING SAMPLING\n");} //Logging Sampling |
| thomasmorris | 52:99915f5240b2 | 39 | else if (NumberToLogging == 4){pc.printf("LOGGING SERIAL COMMANDS\n");} //Logging serial commands |
| thomasmorris | 52:99915f5240b2 | 40 | else if (NumberToLogging == 5){pc.printf("LOGGING SD CARD\n");} //Logging SD card |
| thomasmorris | 52:99915f5240b2 | 41 | else if (NumberToLogging >= 6){pc.printf("INVALID LOGGING COMMAND\n");} //Invalud Logging Command |
| thomasmorris | 52:99915f5240b2 | 42 | |
| thomasmorris | 52:99915f5240b2 | 43 | if (NumberToLogging <= 5){Log_Value = NumberToLogging;} //If inputted value is within bounds equate it to the log state |
| thomasmorris | 52:99915f5240b2 | 44 | } |
| thomasmorris | 55:e0e684531825 | 45 | |
| thomasmorris | 53:71f59e195f06 | 46 | //Motor Control |
| thomasmorris | 53:71f59e195f06 | 47 | else if(input[0] == 'M' & input[1] == 'o' & input[2] == 't' & input[3] == 'o' & input[4] == 'r' & input[5] == ' ') |
| thomasmorris | 53:71f59e195f06 | 48 | { |
| thomasmorris | 53:71f59e195f06 | 49 | int NumberOfChars = 0; int ArrayAddress = 0; string MotorNumber; int Motor_Number; //Declare required variables |
| thomasmorris | 53:71f59e195f06 | 50 | while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} //Count the number of characters entered into the console |
| thomasmorris | 53:71f59e195f06 | 51 | for(int x=6; x < NumberOfChars; x++){MotorNumber += input[x];} //Concatenate the characters between the space and the end |
| thomasmorris | 53:71f59e195f06 | 52 | stringstream Number(MotorNumber); //Convert string to stringstream |
| thomasmorris | 53:71f59e195f06 | 53 | Number >> Motor_Number; //Convert stringstream to integer |
| thomasmorris | 53:71f59e195f06 | 54 | if(Motor_Number < 1 || Motor_Number > 6) |
| thomasmorris | 53:71f59e195f06 | 55 | { |
| thomasmorris | 53:71f59e195f06 | 56 | Motor_Number =0; |
| thomasmorris | 53:71f59e195f06 | 57 | pc.printf("Please Select a motor from 1-6\n"); |
| thomasmorris | 53:71f59e195f06 | 58 | } |
| thomasmorris | 53:71f59e195f06 | 59 | Motor_To_Select = Motor_Number; |
| thomasmorris | 53:71f59e195f06 | 60 | //Step Control |
| thomasmorris | 53:71f59e195f06 | 61 | pc.printf("Enter the angle to rotate\n"); //Request command in the terminal |
| thomasmorris | 53:71f59e195f06 | 62 | scanf("%f",&angle); |
| thomasmorris | 53:71f59e195f06 | 63 | //cin.getline(input,sizeof(input),'\r'); //Scan into input from the start of the line to the return character |
| thomasmorris | 53:71f59e195f06 | 64 | //if(input[0] == 'S' & input[1] == 't' & input[2] == 'e' & input[3] == 'p' & input[4] == 's' & input[5] == ' ') |
| thomasmorris | 53:71f59e195f06 | 65 | { |
| thomasmorris | 53:71f59e195f06 | 66 | //angle = input; |
| thomasmorris | 53:71f59e195f06 | 67 | if(angle < 0) |
| thomasmorris | 53:71f59e195f06 | 68 | { |
| thomasmorris | 55:e0e684531825 | 69 | direction = 0;//Anti Clockwise |
| thomasmorris | 53:71f59e195f06 | 70 | } |
| thomasmorris | 53:71f59e195f06 | 71 | else |
| thomasmorris | 53:71f59e195f06 | 72 | { |
| thomasmorris | 55:e0e684531825 | 73 | direction = 1;//Clockwise |
| thomasmorris | 53:71f59e195f06 | 74 | } |
| thomasmorris | 55:e0e684531825 | 75 | float new_angle = abs(angle/1.8);//Converts input to steps |
| thomasmorris | 53:71f59e195f06 | 76 | steps = new_angle; |
| thomasmorris | 53:71f59e195f06 | 77 | pc.printf("The Motor is: %d\n The Number to step is: %d\n", Motor_Number, steps); |
| thomasmorris | 53:71f59e195f06 | 78 | } |
| thomasmorris | 53:71f59e195f06 | 79 | |
| thomasmorris | 53:71f59e195f06 | 80 | } |
| thomasmorris | 56:bc5345bc6650 | 81 | //MOVE |
| thomasmorris | 56:bc5345bc6650 | 82 | else if(input[0] == 'M' & input[1] == 'O' & input[2] == 'V' & input[3] == 'E') |
| thomasmorris | 56:bc5345bc6650 | 83 | { |
| thomasmorris | 56:bc5345bc6650 | 84 | pc.printf("Enter the Move\n"); //Request command in the terminal |
| thomasmorris | 56:bc5345bc6650 | 85 | cin.getline(input,sizeof(input),'\r');; |
| thomasmorris | 56:bc5345bc6650 | 86 | if(input[0] == 'C' & input[1] == 'L') |
| thomasmorris | 56:bc5345bc6650 | 87 | { |
| thomasmorris | 56:bc5345bc6650 | 88 | pc.printf("Test Successful\n"); |
| thomasmorris | 56:bc5345bc6650 | 89 | } |
| thomasmorris | 52:99915f5240b2 | 90 | //HELP |
| thomasmorris | 52:99915f5240b2 | 91 | else if(input[0] == 'H' & input[1] == 'E' & input[2] == 'L' & input[3] == 'P') |
| thomasmorris | 52:99915f5240b2 | 92 | { |
| thomasmorris | 52:99915f5240b2 | 93 | pc.printf("Avalible Commands are: \n"); //Print introduction line |
| thomasmorris | 55:e0e684531825 | 94 | pc.printf("Motor x selects a motor in the range of 1-6\n"); //Print list of commands |
| thomasmorris | 52:99915f5240b2 | 95 | } |
| thomasmorris | 52:99915f5240b2 | 96 | else |
| thomasmorris | 52:99915f5240b2 | 97 | { |
| thomasmorris | 52:99915f5240b2 | 98 | pc.printf("Please enter an acceptable command\n"); |
| thomasmorris | 52:99915f5240b2 | 99 | } |
| thomasmorris | 56:bc5345bc6650 | 100 | } |
| thomasmorris | 53:71f59e195f06 | 101 | } |
