Thomas Morris
/
PROJ324_Final
Proj 324 Final
Fork of ELEC351_Group_T by
SERIAL_COMMANDS.cpp@52:99915f5240b2, 2018-01-09 (annotated)
- Committer:
- thomasmorris
- Date:
- Tue Jan 09 22:27:49 2018 +0000
- Revision:
- 52:99915f5240b2
- Parent:
- 48:244d6d81bb52
- Child:
- 53:71f59e195f06
ITS THE FINAL COMMIT MESSAGE DO DO DO DO DO
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 | 52:99915f5240b2 | 4 | float Sample_Rate = 15.0; //Initial sampling rate |
thomasmorris | 47:6d128e500875 | 5 | |
thomasmorris | 52:99915f5240b2 | 6 | Ticker Sampling_Timer; //Controls Sampling Rate |
thomasmorris | 52:99915f5240b2 | 7 | //Mutex Locks |
thomasmorris | 52:99915f5240b2 | 8 | |
thomasmorris | 52:99915f5240b2 | 9 | Mutex SERIAL_COMMANDS_Lock; |
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 | 47:6d128e500875 | 18 | |
thomasmorris | 52:99915f5240b2 | 19 | //READ ALL |
thomasmorris | 52:99915f5240b2 | 20 | 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 | 21 | { |
thomasmorris | 52:99915f5240b2 | 22 | if(Log_Value == 4){pc.printf("READ ALL Confirmed\n");} //If logging is enabled, print debug statement |
thomasmorris | 52:99915f5240b2 | 23 | |
thomasmorris | 52:99915f5240b2 | 24 | SERIAL_COMMANDS_Lock.lock(); //Apply MUTEX lock |
thomasmorris | 52:99915f5240b2 | 25 | int Start_Address_Read_All = Write_Pointer; //Store Write_Pointer in temporary variable |
thomasmorris | 52:99915f5240b2 | 26 | SERIAL_COMMANDS_Lock.unlock(); //Release MUTEX lock |
thomasmorris | 52:99915f5240b2 | 27 | |
thomasmorris | 52:99915f5240b2 | 28 | for(int x_Read_All = (Start_Address_Read_All - mailsize); x_Read_All != Start_Address_Read_All; x_Read_All = x_Read_All ) //From the oldest sample to the newest sample |
thomasmorris | 47:6d128e500875 | 29 | { |
thomasmorris | 52:99915f5240b2 | 30 | if(x_Read_All < 0){x_Read_All = x_Read_All + mailsize;} //If the address has gone below 0 add mailsize to it |
thomasmorris | 52:99915f5240b2 | 31 | else {x_Read_All = x_Read_All;} //If the adress hasn't gone below 0 keep it the same |
thomasmorris | 52:99915f5240b2 | 32 | if(Log_Value == 4){pc.printf("Address Reading From: %d\n",x_Read_All);} //If logging is enabled, print debug statement |
thomasmorris | 52:99915f5240b2 | 33 | |
thomasmorris | 52:99915f5240b2 | 34 | DATA Serial_Read_Data = Read_Data(x_Read_All); //Read from target address into temporary variable |
thomasmorris | 47:6d128e500875 | 35 | |
thomasmorris | 52:99915f5240b2 | 36 | time_t Time = Serial_Read_Data.get_time(); //Assign the sampled time to Time |
thomasmorris | 52:99915f5240b2 | 37 | tm* Time_Pointer = localtime(&Time); //Create pointer to Time |
thomasmorris | 52:99915f5240b2 | 38 | |
thomasmorris | 52:99915f5240b2 | 39 | pc.printf("Date = %02d %02d %d ,\t", Time_Pointer->tm_mday, (Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900)); //Print Date String |
thomasmorris | 52:99915f5240b2 | 40 | pc.printf("Time = %02d:%02d:%02d ,\t", Time_Pointer->tm_hour, Time_Pointer->tm_min, Time_Pointer->tm_sec); //Print Time sTRING |
thomasmorris | 52:99915f5240b2 | 41 | pc.printf("Temperature = %f ,\t", Serial_Read_Data.get_temperature()); //Print Temperature |
thomasmorris | 52:99915f5240b2 | 42 | pc.printf("Pressure = %f ,\t", Serial_Read_Data.get_pressure()); //Print Pressure |
thomasmorris | 52:99915f5240b2 | 43 | pc.printf("Light = %f ,\n", Serial_Read_Data.get_light()); //Print Light |
thomasmorris | 52:99915f5240b2 | 44 | |
thomasmorris | 52:99915f5240b2 | 45 | if(x_Read_All == mailsize - 1){x_Read_All = 0;} //If read address is mailsize - 1 set the read adress to 0 |
thomasmorris | 52:99915f5240b2 | 46 | else {x_Read_All = x_Read_All + 1;} //If read address is not mailsize increment the read address |
thomasmorris | 52:99915f5240b2 | 47 | } |
thomasmorris | 52:99915f5240b2 | 48 | } |
thomasmorris | 47:6d128e500875 | 49 | |
thomasmorris | 52:99915f5240b2 | 50 | //DELETE ALL |
thomasmorris | 52:99915f5240b2 | 51 | else if(input[0] == 'D' & input[1] == 'E' & input[2] == 'L' & input[3] == 'E' & input[4] == 'T' & input[5] == 'E' & input[6] == ' ' & input[7] == 'A' & input[8] == 'L' & input[9] == 'L') |
thomasmorris | 52:99915f5240b2 | 52 | { |
thomasmorris | 52:99915f5240b2 | 53 | Sampling_Timer.detach(); //Detach the sampling interrupt |
thomasmorris | 52:99915f5240b2 | 54 | if(Log_Value == 4){pc.printf("DELETE ALL Confirmed\n");} //If logging is enabled, print debug statement |
thomasmorris | 52:99915f5240b2 | 55 | |
thomasmorris | 52:99915f5240b2 | 56 | SERIAL_COMMANDS_Lock.lock(); //Apply MUTEX lock |
thomasmorris | 52:99915f5240b2 | 57 | int Start_Address = Write_Pointer; //Store Write_Pointer in a temporary variable |
thomasmorris | 52:99915f5240b2 | 58 | SERIAL_COMMANDS_Lock.unlock(); //Release MUTEX lock |
thomasmorris | 52:99915f5240b2 | 59 | |
thomasmorris | 52:99915f5240b2 | 60 | for(int x_Delete_All = (Start_Address - mailsize); x_Delete_All != Start_Address; x_Delete_All = x_Delete_All) //From the oldest sample to the newest sample |
thomasmorris | 47:6d128e500875 | 61 | { |
thomasmorris | 52:99915f5240b2 | 62 | if(x_Delete_All < 0){x_Delete_All = x_Delete_All + mailsize;} //If the target is less than 0 add mailsize to the target |
thomasmorris | 52:99915f5240b2 | 63 | else {x_Delete_All = x_Delete_All;} //If the target is not less than 0 keep it the same |
thomasmorris | 52:99915f5240b2 | 64 | if(Log_Value == 4){pc.printf("Address Deleting From: %d\n",x_Delete_All);} //If logging is enabled, print debug statement |
thomasmorris | 47:6d128e500875 | 65 | |
thomasmorris | 52:99915f5240b2 | 66 | Delete_Data(x_Delete_All); //Delete DATA in the target address |
thomasmorris | 47:6d128e500875 | 67 | |
thomasmorris | 52:99915f5240b2 | 68 | if(x_Delete_All == mailsize - 1){x_Delete_All = 0;} //If the target is mailsize - 1 then set the new target to 0 |
thomasmorris | 52:99915f5240b2 | 69 | else {x_Delete_All = x_Delete_All + 1;} //If the target is not mailsize - 1 then increment the target |
thomasmorris | 47:6d128e500875 | 70 | |
thomasmorris | 47:6d128e500875 | 71 | } |
thomasmorris | 52:99915f5240b2 | 72 | pc.printf("DELETED %d RECORDS\n",mailsize); //Print number of records which have been deleted |
thomasmorris | 52:99915f5240b2 | 73 | Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); //Reattach the sampling interrupt |
thomasmorris | 52:99915f5240b2 | 74 | } |
thomasmorris | 47:6d128e500875 | 75 | |
thomasmorris | 52:99915f5240b2 | 76 | //READ |
thomasmorris | 52:99915f5240b2 | 77 | else if(input[0] == 'R' & input[1] == 'E' & input[2] == 'A' & input[3] == 'D' & input[4] == ' ') |
thomasmorris | 52:99915f5240b2 | 78 | { |
thomasmorris | 52:99915f5240b2 | 79 | if(Log_Value == 4){pc.printf("READ n Confirmed\n");} //If logging is enabled, print the debug statement |
thomasmorris | 52:99915f5240b2 | 80 | int NumberOfChars = 0; int ArrayAddress = 0; string ReadNumber; int NumberToRead; //Declare required variables |
thomasmorris | 52:99915f5240b2 | 81 | while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} //Count the number of characters typed in the console |
thomasmorris | 52:99915f5240b2 | 82 | for(int x=5; x < NumberOfChars; x++){ReadNumber += input[x];} //Concatenate characters from console into a string |
thomasmorris | 52:99915f5240b2 | 83 | stringstream Number(ReadNumber); //Convert string into a stringstream |
thomasmorris | 52:99915f5240b2 | 84 | Number >> NumberToRead; //Convert stringstream into an integer |
thomasmorris | 47:6d128e500875 | 85 | |
thomasmorris | 52:99915f5240b2 | 86 | if(Log_Value == 4){pc.printf("Number of samples to Read %d\n",NumberToRead);} //If logging is enabled, print the debug statement |
thomasmorris | 52:99915f5240b2 | 87 | |
thomasmorris | 52:99915f5240b2 | 88 | if(NumberToRead > mailsize){NumberToRead = mailsize;} //If more records are chosen than exist in the buffer limit the selection to the buffer size |
thomasmorris | 47:6d128e500875 | 89 | |
thomasmorris | 52:99915f5240b2 | 90 | SERIAL_COMMANDS_Lock.lock(); //Apply MUTEX lock |
thomasmorris | 52:99915f5240b2 | 91 | int Start_Address = Write_Pointer; //Copy Write_Pointer into temporary variable |
thomasmorris | 52:99915f5240b2 | 92 | SERIAL_COMMANDS_Lock.unlock(); //Release MUTEX lock |
thomasmorris | 52:99915f5240b2 | 93 | |
thomasmorris | 52:99915f5240b2 | 94 | for(int x = (Start_Address - NumberToRead); x != Start_Address; x = x ) //From newest - input number to newest |
thomasmorris | 47:6d128e500875 | 95 | { |
thomasmorris | 52:99915f5240b2 | 96 | if(Log_Value == 4){pc.printf("Address Reading From: %d\n",x);} //If logging is enabled, print the debug statement |
thomasmorris | 52:99915f5240b2 | 97 | if(x < 0){x = x + mailsize;} //If target is less than 0 add mailsize |
thomasmorris | 52:99915f5240b2 | 98 | else {x = x;} //If target is not less than 0 keep it the same |
thomasmorris | 52:99915f5240b2 | 99 | |
thomasmorris | 52:99915f5240b2 | 100 | DATA Serial_Read_Data = Read_Data(x); //Read DATA from target |
thomasmorris | 52:99915f5240b2 | 101 | |
thomasmorris | 52:99915f5240b2 | 102 | time_t Time = Serial_Read_Data.get_time(); //Assign sampled time to Time |
thomasmorris | 52:99915f5240b2 | 103 | tm* Time_Pointer = localtime(&Time); //Create a pointer to Time |
thomasmorris | 47:6d128e500875 | 104 | |
thomasmorris | 52:99915f5240b2 | 105 | pc.printf("Date = %02d %02d %d ,\t", Time_Pointer->tm_mday, (Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900)); //Print the Date |
thomasmorris | 52:99915f5240b2 | 106 | pc.printf("Time = %02d:%02d:%02d ,\t", Time_Pointer->tm_hour, Time_Pointer->tm_min, Time_Pointer->tm_sec); //Print the Time |
thomasmorris | 52:99915f5240b2 | 107 | pc.printf("Temperature = %f ,\t", Serial_Read_Data.get_temperature()); //Print the Temperature |
thomasmorris | 52:99915f5240b2 | 108 | pc.printf("Pressure = %f ,\t", Serial_Read_Data.get_pressure()); //Print the Pressure |
thomasmorris | 52:99915f5240b2 | 109 | pc.printf("Light = %f ,\n", Serial_Read_Data.get_light()); //Print the Light |
thomasmorris | 52:99915f5240b2 | 110 | |
thomasmorris | 52:99915f5240b2 | 111 | if(x == mailsize - 1){x = 0;} //If target is mailsize - 1 set the new target to 0 |
thomasmorris | 52:99915f5240b2 | 112 | else {x = x + 1;} //If target is not mailsize - 1 increment the target |
thomasmorris | 52:99915f5240b2 | 113 | } |
thomasmorris | 52:99915f5240b2 | 114 | if(Log_Value == 4){pc.printf("Read %d samples\n",NumberToRead);} //If logging is enabled, print the debug statement |
thomasmorris | 52:99915f5240b2 | 115 | } |
thomasmorris | 52:99915f5240b2 | 116 | |
thomasmorris | 52:99915f5240b2 | 117 | //DELETE |
thomasmorris | 52:99915f5240b2 | 118 | else if(input[0] == 'D' & input[1] == 'E' & input[2] == 'L' & input[3] == 'E' & input[4] == 'T' & input[5] == 'E' & input[6] == ' ') |
thomasmorris | 52:99915f5240b2 | 119 | { |
thomasmorris | 52:99915f5240b2 | 120 | Sampling_Timer.detach(); //Detach sampling interrupt |
thomasmorris | 52:99915f5240b2 | 121 | if(Log_Value == 4){pc.printf("DELETE N Confirmed\n");} //If logging is enabled, print debug statement |
thomasmorris | 52:99915f5240b2 | 122 | int NumberOfChars = 0; int ArrayAddress = 0; string DeleteNumber; int NumberToDelete; //Declare required variables |
thomasmorris | 52:99915f5240b2 | 123 | while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} //Count the number of characters typed in the console |
thomasmorris | 52:99915f5240b2 | 124 | for(int x=7; x < NumberOfChars; x++){DeleteNumber += input[x];} //Concatenate characters from console into a string |
thomasmorris | 52:99915f5240b2 | 125 | stringstream Number(DeleteNumber); //Convert string into a stringstream |
thomasmorris | 52:99915f5240b2 | 126 | Number >> NumberToDelete; //Convert stringstream into an integer |
thomasmorris | 48:244d6d81bb52 | 127 | |
thomasmorris | 52:99915f5240b2 | 128 | if(NumberToDelete > mailsize){NumberToDelete = mailsize;} //If more records are chosen than exist in the buffer limit the selection to the buffer size |
thomasmorris | 52:99915f5240b2 | 129 | |
thomasmorris | 52:99915f5240b2 | 130 | if(Log_Value == 4){pc.printf("Deleted %d samples\n",NumberToDelete);} //If logging is enabled, print debug statement |
thomasmorris | 52:99915f5240b2 | 131 | |
thomasmorris | 52:99915f5240b2 | 132 | SERIAL_COMMANDS_Lock.lock(); //Apply MUTEX lock |
thomasmorris | 52:99915f5240b2 | 133 | int Start_Address = Write_Pointer; //Copy Write_Pointer into temporary variable |
thomasmorris | 52:99915f5240b2 | 134 | SERIAL_COMMANDS_Lock.unlock(); //Release MUTEX lock |
thomasmorris | 52:99915f5240b2 | 135 | |
thomasmorris | 52:99915f5240b2 | 136 | for(int x_Delete = (Start_Address - NumberToDelete); x_Delete != Start_Address; x_Delete = x_Delete ) //From newest - input number to newest |
thomasmorris | 47:6d128e500875 | 137 | { |
thomasmorris | 52:99915f5240b2 | 138 | if(Log_Value == 4){pc.printf("Address Deleting From: %d\n",x_Delete);} //If logging is enabled, print debug statement |
thomasmorris | 52:99915f5240b2 | 139 | if(x_Delete < 0){x_Delete = x_Delete + mailsize;} //If target is less than 0 add mailsize |
thomasmorris | 52:99915f5240b2 | 140 | else {x_Delete = x_Delete;} //If target is not less than 0 keep it the same |
thomasmorris | 52:99915f5240b2 | 141 | |
thomasmorris | 52:99915f5240b2 | 142 | Delete_Data(x_Delete); //Delete DATA at specified address |
thomasmorris | 52:99915f5240b2 | 143 | |
thomasmorris | 52:99915f5240b2 | 144 | if(x_Delete == mailsize - 1){x_Delete = 0;} //If target is mailsize - 1 set target to 0 |
thomasmorris | 52:99915f5240b2 | 145 | else {x_Delete = x_Delete + 1;} //If target is not mailsize - 1 increment the target |
thomasmorris | 48:244d6d81bb52 | 146 | |
thomasmorris | 47:6d128e500875 | 147 | } |
thomasmorris | 52:99915f5240b2 | 148 | pc.printf("DELETED %d RECORDS\n",NumberToDelete); //Print number of records which have been deleted |
thomasmorris | 52:99915f5240b2 | 149 | if(Log_Value == 4){pc.printf("Deleted %d samples\n",NumberToDelete);} //If logging is enabled, print the debug statement |
thomasmorris | 52:99915f5240b2 | 150 | Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); //Attach sampling interrupt |
thomasmorris | 52:99915f5240b2 | 151 | } |
thomasmorris | 48:244d6d81bb52 | 152 | |
thomasmorris | 52:99915f5240b2 | 153 | //STATE |
thomasmorris | 52:99915f5240b2 | 154 | else if(input[0] == 'S' & input[1] == 'T' & input[2] == 'A' & input[3] == 'T' & input[4] == 'E' & input[5] == ' ') |
thomasmorris | 52:99915f5240b2 | 155 | { |
thomasmorris | 52:99915f5240b2 | 156 | if(Log_Value == 4){pc.printf("STATE Confirmed\n");} //If logging is enabled, print debug statement |
thomasmorris | 52:99915f5240b2 | 157 | int NumberOfChars = 0; int ArrayAddress = 0; string StateNumber; int NumberToState; //Declare required variables |
thomasmorris | 52:99915f5240b2 | 158 | while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} //Count the number of characters typed in the console |
thomasmorris | 52:99915f5240b2 | 159 | for(int x=6; x < NumberOfChars; x++){StateNumber += input[x];} //Concatenate characters from console into a string |
thomasmorris | 52:99915f5240b2 | 160 | stringstream Number(StateNumber); //Convert string into a stringstream |
thomasmorris | 52:99915f5240b2 | 161 | Number >> NumberToState; //Convert stringstream into an integer |
thomasmorris | 52:99915f5240b2 | 162 | |
thomasmorris | 52:99915f5240b2 | 163 | if(Log_Value == 4){pc.printf("STATE Set to %d\n",NumberToState);} //If logging is enabled, print debug statement |
thomasmorris | 52:99915f5240b2 | 164 | |
thomasmorris | 52:99915f5240b2 | 165 | if(NumberToState==0) {Sampling_Timer.detach(); pc.printf("SAMPLING 0\n");} //If input is 0 stop sampling |
thomasmorris | 52:99915f5240b2 | 166 | else if(NumberToState==1) {Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);pc.printf("SAMPLING 1\n");} //If input is 1 start sampling |
thomasmorris | 52:99915f5240b2 | 167 | else {pc.printf("Invalid State\n");} //If other input received return error message |
thomasmorris | 52:99915f5240b2 | 168 | |
thomasmorris | 52:99915f5240b2 | 169 | } |
thomasmorris | 52:99915f5240b2 | 170 | |
thomasmorris | 52:99915f5240b2 | 171 | //SETDATE |
thomasmorris | 52:99915f5240b2 | 172 | 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] == ' ') |
thomasmorris | 52:99915f5240b2 | 173 | { |
thomasmorris | 52:99915f5240b2 | 174 | if(Log_Value == 4){pc.printf("SETDATE Confirmed\n");} //If logging is enabled, print debug statement |
thomasmorris | 52:99915f5240b2 | 175 | string DayNumber, MonthNumber, YearNumber; //Declare required variables |
thomasmorris | 52:99915f5240b2 | 176 | int NumberToDay, NumberToMonth, NumberToYear; //Declare required variables |
thomasmorris | 52:99915f5240b2 | 177 | |
thomasmorris | 52:99915f5240b2 | 178 | for(int x=8; x < 10; x++){DayNumber += input[x];} //Concatenate characters from the first space to the second |
thomasmorris | 52:99915f5240b2 | 179 | stringstream Number_1(DayNumber); //Convert string to stringstream |
thomasmorris | 52:99915f5240b2 | 180 | Number_1 >> NumberToDay; //Convert stringstream to integer |
thomasmorris | 52:99915f5240b2 | 181 | |
thomasmorris | 52:99915f5240b2 | 182 | for(int x=11; x < 13; x++){MonthNumber += input[x];} //Concatenate characters from the second space to the third |
thomasmorris | 52:99915f5240b2 | 183 | stringstream Number_2(MonthNumber); //Convert string to stringstream |
thomasmorris | 52:99915f5240b2 | 184 | Number_2 >> NumberToMonth; //Convert stringstream to integer |
thomasmorris | 52:99915f5240b2 | 185 | |
thomasmorris | 52:99915f5240b2 | 186 | for(int x=14; x < 18; x++){YearNumber += input[x];} //Concatenate characters from the third space to the end |
thomasmorris | 52:99915f5240b2 | 187 | stringstream Number_3(YearNumber); //Convert string to stringstream |
thomasmorris | 52:99915f5240b2 | 188 | Number_3 >> NumberToYear; //Convert stringstream to string |
thomasmorris | 52:99915f5240b2 | 189 | |
thomasmorris | 52:99915f5240b2 | 190 | 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 |
thomasmorris | 52:99915f5240b2 | 191 | |
thomasmorris | 52:99915f5240b2 | 192 | set_new_date(NumberToDay,NumberToMonth,NumberToYear); //Set New Date |
thomasmorris | 52:99915f5240b2 | 193 | pc.printf("DATE UPDATED TO %02d %02d %d\n",NumberToDay,NumberToMonth,NumberToYear); //Print Updated Date |
thomasmorris | 52:99915f5240b2 | 194 | } |
thomasmorris | 52:99915f5240b2 | 195 | |
thomasmorris | 52:99915f5240b2 | 196 | //SETTIME |
thomasmorris | 52:99915f5240b2 | 197 | 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] == ' ') |
thomasmorris | 52:99915f5240b2 | 198 | { |
thomasmorris | 52:99915f5240b2 | 199 | if(Log_Value == 4){pc.printf("SETTIME Confirmed\n");} //If logging is enabled, print debug statement |
thomasmorris | 52:99915f5240b2 | 200 | string HourNumber, MinuteNumber, SecondNumber; //Declare required variables |
thomasmorris | 52:99915f5240b2 | 201 | int NumberToHour, NumberToMinute, NumberToSecond; //Declare required variables |
thomasmorris | 52:99915f5240b2 | 202 | |
thomasmorris | 52:99915f5240b2 | 203 | for(int x=8; x < 10; x++){HourNumber += input[x];} //Concatenate characters from the third space to the end |
thomasmorris | 52:99915f5240b2 | 204 | stringstream Number_1(HourNumber); //Convert string to stringstream |
thomasmorris | 52:99915f5240b2 | 205 | Number_1 >> NumberToHour; //Convert stringstream to string |
thomasmorris | 52:99915f5240b2 | 206 | |
thomasmorris | 52:99915f5240b2 | 207 | for(int x=11; x < 13; x++){MinuteNumber += input[x];} //Concatenate characters from the third space to the end |
thomasmorris | 52:99915f5240b2 | 208 | stringstream Number_2(MinuteNumber); //Convert string to stringstream |
thomasmorris | 52:99915f5240b2 | 209 | Number_2 >> NumberToMinute; //Convert stringstream to string |
thomasmorris | 52:99915f5240b2 | 210 | |
thomasmorris | 52:99915f5240b2 | 211 | for(int x=14; x < 16; x++){SecondNumber += input[x];} //Concatenate characters from the third space to the end |
thomasmorris | 52:99915f5240b2 | 212 | stringstream Number_3(SecondNumber); //Convert string to stringstream |
thomasmorris | 52:99915f5240b2 | 213 | Number_3 >> NumberToSecond; //Convert stringstream to string |
thomasmorris | 52:99915f5240b2 | 214 | |
thomasmorris | 52:99915f5240b2 | 215 | 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 |
thomasmorris | 52:99915f5240b2 | 216 | |
thomasmorris | 52:99915f5240b2 | 217 | set_new_time(NumberToHour,NumberToMinute,NumberToSecond); //Set New Time |
thomasmorris | 52:99915f5240b2 | 218 | pc.printf("TIME UPDATED TO %02d %02d %02d\n",NumberToHour,NumberToMinute,NumberToSecond); //Print Updated Time |
thomasmorris | 52:99915f5240b2 | 219 | } |
thomasmorris | 52:99915f5240b2 | 220 | |
thomasmorris | 52:99915f5240b2 | 221 | //SETT |
thomasmorris | 52:99915f5240b2 | 222 | else if(input[0] == 'S' & input[1] == 'E' & input[2] == 'T' & input[3] == 'T' & input[4] == ' ') |
thomasmorris | 52:99915f5240b2 | 223 | { |
thomasmorris | 52:99915f5240b2 | 224 | if(Log_Value == 4){pc.printf("SETT Confirmed\n");} //If logging is enabled, print debug statement |
thomasmorris | 52:99915f5240b2 | 225 | int NumberOfChars = 0; int ArrayAddress = 0; //Declare required variables |
thomasmorris | 52:99915f5240b2 | 226 | string SettNumber; double NumberToSett; //Declare required variables |
thomasmorris | 52:99915f5240b2 | 227 | int Decimal_Divider = 10; //Declare required variables |
thomasmorris | 52:99915f5240b2 | 228 | float Sample_Rate_Integer = 0; string Sample_Rate_Integer_String; //Declare required variables |
thomasmorris | 52:99915f5240b2 | 229 | float Sample_Rate_Decimal = 0; string Sample_Rate_Decimal_String; //Declare required variables |
thomasmorris | 52:99915f5240b2 | 230 | |
thomasmorris | 52:99915f5240b2 | 231 | while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} //Count the number of characters entered into the console |
thomasmorris | 52:99915f5240b2 | 232 | |
thomasmorris | 52:99915f5240b2 | 233 | if (Decimal_Check(input) == true) //If a decimal is present |
thomasmorris | 52:99915f5240b2 | 234 | { |
thomasmorris | 52:99915f5240b2 | 235 | for(int x = 5; x < Decimal_Position(input); x++){Sample_Rate_Integer_String += input[x];} //Concatenate characters from the space to the decimal |
thomasmorris | 52:99915f5240b2 | 236 | stringstream Number_1(Sample_Rate_Integer_String); //Convert string to a stringstream |
thomasmorris | 52:99915f5240b2 | 237 | Number_1 >> Sample_Rate_Integer; //Convert stringstream to a integer |
thomasmorris | 52:99915f5240b2 | 238 | |
thomasmorris | 52:99915f5240b2 | 239 | for(int x = Decimal_Position(input) + 1; x < NumberOfChars; x++){Sample_Rate_Decimal_String += input[x];} //Concatenate characters from the decimal to the end |
thomasmorris | 52:99915f5240b2 | 240 | stringstream Number_2(Sample_Rate_Decimal_String); //Convert string to a stringstream |
thomasmorris | 52:99915f5240b2 | 241 | Number_2 >> Sample_Rate_Decimal; //Convert stringstream to a integer |
thomasmorris | 52:99915f5240b2 | 242 | |
thomasmorris | 52:99915f5240b2 | 243 | for(int tens_power = 1; tens_power != NumberOfChars - Decimal_Position(input) - 1; tens_power++) //For each position after the decimal place |
thomasmorris | 48:244d6d81bb52 | 244 | { |
thomasmorris | 52:99915f5240b2 | 245 | Decimal_Divider = Decimal_Divider * 10; //Multiply the divider by another power of 10 |
thomasmorris | 48:244d6d81bb52 | 246 | } |
thomasmorris | 52:99915f5240b2 | 247 | NumberToSett = Sample_Rate_Integer + (Sample_Rate_Decimal / float(Decimal_Divider)); //Divide the number after the decimal by the number of characters after the decimal |
thomasmorris | 52:99915f5240b2 | 248 | } |
thomasmorris | 52:99915f5240b2 | 249 | else //If a decimal is not present |
thomasmorris | 52:99915f5240b2 | 250 | { |
thomasmorris | 52:99915f5240b2 | 251 | for(int x=5; x < NumberOfChars; x++){SettNumber += input[x];} //Concatenate characters from the space to the end |
thomasmorris | 52:99915f5240b2 | 252 | stringstream Number_3(SettNumber); //Convert string to a stringstream |
thomasmorris | 52:99915f5240b2 | 253 | Number_3 >> NumberToSett; //Convert stringstream to an integer |
thomasmorris | 52:99915f5240b2 | 254 | } |
thomasmorris | 52:99915f5240b2 | 255 | |
thomasmorris | 52:99915f5240b2 | 256 | if(Log_Value == 4){pc.printf("Sample Rate Input %d\n",NumberToSett);} //If logging is enabled, print debug statement |
thomasmorris | 52:99915f5240b2 | 257 | if(Log_Value == 4){pc.printf("Decimal Rate Input %d\n",Sample_Rate_Decimal);} //If logging is enabled, print debug statement |
thomasmorris | 52:99915f5240b2 | 258 | if(Log_Value == 4){pc.printf("Integer Rate Input %d\n",Sample_Rate_Integer);} //If logging is enabled, print debug statement |
thomasmorris | 52:99915f5240b2 | 259 | |
thomasmorris | 52:99915f5240b2 | 260 | if(NumberToSett >= 0.1 & NumberToSett <= 60) //If inputted number is between 0.1 and 60.0 |
thomasmorris | 52:99915f5240b2 | 261 | { |
thomasmorris | 52:99915f5240b2 | 262 | Sample_Rate = NumberToSett; //Set the sample rate to that input number |
thomasmorris | 52:99915f5240b2 | 263 | pc.printf("T UPDATED TO %1.1f \n",NumberToSett); //Print updated sample rate |
thomasmorris | 48:244d6d81bb52 | 264 | } |
thomasmorris | 52:99915f5240b2 | 265 | else //If inputted number is not within bounds |
thomasmorris | 52:99915f5240b2 | 266 | { |
thomasmorris | 52:99915f5240b2 | 267 | Sample_Rate = Sample_Rate; //Don't change the sample rate |
thomasmorris | 52:99915f5240b2 | 268 | pc.printf("OUT OF RANGE\n"); //Print out of range error warning |
thomasmorris | 52:99915f5240b2 | 269 | } |
thomasmorris | 52:99915f5240b2 | 270 | Sampling_Timer.detach(); //Detach the sampling interrupt |
thomasmorris | 52:99915f5240b2 | 271 | Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); //Reattach the sampling interrupt with the new rate |
thomasmorris | 52:99915f5240b2 | 272 | } |
thomasmorris | 52:99915f5240b2 | 273 | //LOGGING |
thomasmorris | 52:99915f5240b2 | 274 | 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 | 275 | { |
thomasmorris | 52:99915f5240b2 | 276 | int NumberOfChars = 0; int ArrayAddress = 0; string LoggingNumber; int NumberToLogging; //Declare required variables |
thomasmorris | 52:99915f5240b2 | 277 | while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} //Count the number of characters entered into the console |
thomasmorris | 52:99915f5240b2 | 278 | for(int x=8; x < NumberOfChars; x++){LoggingNumber += input[x];} //Concatenate the characters between the space and the end |
thomasmorris | 52:99915f5240b2 | 279 | stringstream Number(LoggingNumber); //Convert string to stringstream |
thomasmorris | 52:99915f5240b2 | 280 | Number >> NumberToLogging; //Convert stringstream to integer |
thomasmorris | 52:99915f5240b2 | 281 | if (NumberToLogging == 0){pc.printf("NOT LOGGING\n");} //Not Logging |
thomasmorris | 52:99915f5240b2 | 282 | else if (NumberToLogging == 1){pc.printf("LOGGING LCD\n");} //Logging LCD |
thomasmorris | 52:99915f5240b2 | 283 | else if (NumberToLogging == 2){pc.printf("LOGGING NETWORKING\n");} //Logging Networking |
thomasmorris | 52:99915f5240b2 | 284 | else if (NumberToLogging == 3){pc.printf("LOGGING SAMPLING\n");} //Logging Sampling |
thomasmorris | 52:99915f5240b2 | 285 | else if (NumberToLogging == 4){pc.printf("LOGGING SERIAL COMMANDS\n");} //Logging serial commands |
thomasmorris | 52:99915f5240b2 | 286 | else if (NumberToLogging == 5){pc.printf("LOGGING SD CARD\n");} //Logging SD card |
thomasmorris | 52:99915f5240b2 | 287 | else if (NumberToLogging >= 6){pc.printf("INVALID LOGGING COMMAND\n");} //Invalud Logging Command |
thomasmorris | 52:99915f5240b2 | 288 | |
thomasmorris | 52:99915f5240b2 | 289 | if (NumberToLogging <= 5){Log_Value = NumberToLogging;} //If inputted value is within bounds equate it to the log state |
thomasmorris | 52:99915f5240b2 | 290 | } |
thomasmorris | 48:244d6d81bb52 | 291 | |
thomasmorris | 52:99915f5240b2 | 292 | //HELP |
thomasmorris | 52:99915f5240b2 | 293 | else if(input[0] == 'H' & input[1] == 'E' & input[2] == 'L' & input[3] == 'P') |
thomasmorris | 52:99915f5240b2 | 294 | { |
thomasmorris | 52:99915f5240b2 | 295 | pc.printf("Avalible Commands are: \n"); //Print introduction line |
thomasmorris | 52:99915f5240b2 | 296 | pc.printf("READ ALL\nDELETE ALL\nREAD <n>\nDELETE <n>\nSETDATE <dd> <mm> <yyyy>\nSETTIME <hh> <mm> <ss>\n"); //Print list of commands |
thomasmorris | 52:99915f5240b2 | 297 | 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 |
thomasmorris | 52:99915f5240b2 | 298 | |
thomasmorris | 52:99915f5240b2 | 299 | } |
thomasmorris | 52:99915f5240b2 | 300 | |
thomasmorris | 52:99915f5240b2 | 301 | //NETSET |
thomasmorris | 52:99915f5240b2 | 302 | else if(input[0] == 'N' & input[1] == 'E' & input[2] == 'T' & input[3] == 'S' & input[4] == 'E' & input[5] == 'T' & input[6] == ' ')// Use this to display all of the availble commands |
thomasmorris | 52:99915f5240b2 | 303 | { |
thomasmorris | 52:99915f5240b2 | 304 | if(Log_Value == 4){pc.printf("NETSET confirmed\n");} |
thomasmorris | 52:99915f5240b2 | 305 | int NumberOfChars = 0; int ArrayAddress = 0; string NetSetNumber; int NumberToNetSet; |
thomasmorris | 52:99915f5240b2 | 306 | while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} |
thomasmorris | 52:99915f5240b2 | 307 | for(int x=7; x < NumberOfChars; x++){NetSetNumber += input[x];} |
thomasmorris | 52:99915f5240b2 | 308 | stringstream Number(NetSetNumber); |
thomasmorris | 52:99915f5240b2 | 309 | Number >> NumberToNetSet; |
thomasmorris | 52:99915f5240b2 | 310 | if(Log_Value == 4){pc.printf("NETSET Number %d",NumberToNetSet);} |
thomasmorris | 52:99915f5240b2 | 311 | if(NumberToNetSet < 1) |
thomasmorris | 47:6d128e500875 | 312 | { |
thomasmorris | 52:99915f5240b2 | 313 | NumberToNetSet = 1; |
thomasmorris | 52:99915f5240b2 | 314 | } |
thomasmorris | 52:99915f5240b2 | 315 | else |
thomasmorris | 52:99915f5240b2 | 316 | { |
thomasmorris | 52:99915f5240b2 | 317 | NumberToNetSet = NumberToNetSet; |
thomasmorris | 47:6d128e500875 | 318 | } |
thomasmorris | 52:99915f5240b2 | 319 | NetworkWaitTime = (NumberToNetSet * 1000); |
thomasmorris | 52:99915f5240b2 | 320 | } |
thomasmorris | 52:99915f5240b2 | 321 | |
thomasmorris | 52:99915f5240b2 | 322 | else |
thomasmorris | 52:99915f5240b2 | 323 | { |
thomasmorris | 52:99915f5240b2 | 324 | pc.printf("Please enter an acceptable command\n"); |
thomasmorris | 52:99915f5240b2 | 325 | } |
thomasmorris | 47:6d128e500875 | 326 | |
thomasmorris | 47:6d128e500875 | 327 | } |