![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Time: 17:33 Date: 10/12/2017 Description: Task 1,7,8 Currently Functioning
Dependencies: BME280 BMP280 TextLCD
Working Repository
SERIAL_COMMANDS.cpp
- Committer:
- thomasmorris
- Date:
- 2018-01-09
- Revision:
- 48:244d6d81bb52
- Parent:
- 47:6d128e500875
File content as of revision 48:244d6d81bb52:
#include "SERIAL_COMMANDS.hpp" int NetworkWaitTime; char input[100] = {}; Ticker Console_Output_Timer; Ticker Sampling_Timer;//Controls Sampling 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");} for (int x = 0; x < 100; x++){input[x] = ' ';}; pc.printf("Please type in a command\n");//Log this cin.getline(input,sizeof(input),'\r'); //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");} Data_Buffer_Lock.lock();//Lock data buffer due to critical section int Start_Address_Read_All = Write_Pointer; Data_Buffer_Lock.unlock();//unLock data buffer due to critical section for(int x_Read_All = (Start_Address_Read_All - mailsize); x_Read_All != Start_Address_Read_All; x_Read_All = x_Read_All ) { if(x_Read_All < 0){x_Read_All = x_Read_All + mailsize;} else {x_Read_All = x_Read_All;} if(Log_Value == 4){pc.printf("Address Reading From: %d\n",x_Read_All);} DATA Serial_Read_Data = Read_Data(x_Read_All); time_t Time = Serial_Read_Data.get_time(); tm* Time_Pointer = localtime(&Time); pc.printf("Date = %02d %02d %d ,\t", Time_Pointer->tm_mday, (Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900)); pc.printf("Time = %02d:%02d:%02d ,\t", Time_Pointer->tm_hour, Time_Pointer->tm_min, Time_Pointer->tm_sec); //Print the string formatted time pc.printf("Temperature = %f ,\t", Serial_Read_Data.get_temperature()); //Print Temperature pc.printf("Pressure = %f ,\t", Serial_Read_Data.get_pressure()); //Print Pressure pc.printf("Light = %f ,\n", Serial_Read_Data.get_light()); //Print Light if(x_Read_All == mailsize - 1){x_Read_All = 0;} else {x_Read_All = x_Read_All + 1;} } } //DELETE ALL FIX THIS - Might need to disable sampling during the delete 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') { if(Log_Value == 4){pc.printf("DELETE ALL Confirmed\n");} Data_Buffer_Lock.lock(); int Start_Address = Write_Pointer; Data_Buffer_Lock.unlock(); for(int x_Delete_All = (Start_Address - mailsize); x_Delete_All != Start_Address; x_Delete_All = x_Delete_All) { if(Log_Value == 4){pc.printf("Address Deleting From: %d\n",x_Delete_All);} if(x_Delete_All < 0){x_Delete_All = x_Delete_All + mailsize;} else {x_Delete_All = x_Delete_All;} Delete_Data(x_Delete_All); if(x_Delete_All == mailsize - 1){x_Delete_All = 0;} else {x_Delete_All = x_Delete_All + 1;} } pc.printf("DELETED %d RECORDS\n",mailsize); } //READ else if(input[0] == 'R' & input[1] == 'E' & input[2] == 'A' & input[3] == 'D' & input[4] == ' ') { if(Log_Value == 4){pc.printf("READ n Confirmed\n");} int NumberOfChars = 0; int ArrayAddress = 0; string ReadNumber; int NumberToRead; while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} for(int x=5; x < NumberOfChars; x++){ReadNumber += input[x];} stringstream Number(ReadNumber); Number >> NumberToRead; if(Log_Value == 4){pc.printf("Number of samples to Read %d\n",NumberToRead);} if(NumberToRead > mailsize) { NumberToRead = mailsize; } Data_Buffer_Lock.lock();//Lock data buffer due to critical section int Start_Address = Write_Pointer; Data_Buffer_Lock.unlock();//unLock data buffer due to critical section for(int x = (Start_Address - NumberToRead); x != Start_Address; x = x ) { if(Log_Value == 4){pc.printf("Address Reading From: %d\n",x);} if(x < 0){x = x + mailsize;} else {x = x;} DATA Serial_Read_Data = Read_Data(x); time_t Time = Serial_Read_Data.get_time(); tm* Time_Pointer = localtime(&Time); pc.printf("Date = %02d %02d %d ,\t", Time_Pointer->tm_mday, (Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900)); pc.printf("Time = %02d:%02d:%02d ,\t", Time_Pointer->tm_hour, Time_Pointer->tm_min, Time_Pointer->tm_sec);//Print the string formatted time pc.printf("Temperature = %f ,\t", Serial_Read_Data.get_temperature()); //Print Temperature pc.printf("Pressure = %f ,\t", Serial_Read_Data.get_pressure()); //Print Pressure pc.printf("Light = %f ,\n", Serial_Read_Data.get_light()); //Print Light if(x == mailsize - 1){x = 0;} else {x = x + 1;} } if(Log_Value == 4){pc.printf("Read %d samples\n",NumberToRead);} } //DELETE look into this mgiht need to turn off sampling else if(input[0] == 'D' & input[1] == 'E' & input[2] == 'L' & input[3] == 'E' & input[4] == 'T' & input[5] == 'E' & input[6] == ' ') { if(Log_Value == 4){pc.printf("DELETE N Confirmed\n");} int NumberOfChars = 0; int ArrayAddress = 0; string DeleteNumber; int NumberToDelete; while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} for(int x=7; x < NumberOfChars; x++){DeleteNumber += input[x];} stringstream Number(DeleteNumber); Number >> NumberToDelete; if(NumberToDelete > mailsize) { NumberToDelete = mailsize; } if(Log_Value == 4){pc.printf("Deleted %d samples\n",NumberToDelete);} Data_Buffer_Lock.lock(); int Start_Address = Write_Pointer; Data_Buffer_Lock.unlock(); for(int x_Delete = (Start_Address - NumberToDelete); x_Delete != Start_Address; x_Delete = x_Delete ) { if(Log_Value == 4){pc.printf("Address Deleting From: %d\n",x_Delete);} if(x_Delete < 0){x_Delete = x_Delete + mailsize;} else {x_Delete = x_Delete;} Delete_Data(x_Delete); if(x_Delete == mailsize - 1){x_Delete = 0;} else {x_Delete = x_Delete + 1;} } pc.printf("DELETED %d RECORDS\n",NumberToDelete); if(Log_Value == 4){pc.printf("Deleted %d samples\n",NumberToDelete);} } //STATE else if(input[0] == 'S' & input[1] == 'T' & input[2] == 'A' & input[3] == 'T' & input[4] == 'E' & input[5] == ' ') { if(Log_Value == 4){pc.printf("STATE Confirmed\n");} int NumberOfChars = 0; int ArrayAddress = 0; string StateNumber; int NumberToState; while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} for(int x=6; x < NumberOfChars; x++){StateNumber += input[x];} stringstream Number(StateNumber); Number >> NumberToState; if(Log_Value == 4){pc.printf("STATE Set to %d\n",NumberToState);} if(NumberToState==0) {Sampling_Timer.detach(); Console_Output_Timer.detach(); pc.printf("SAMPLING 0\n");}//Stop Sampling else if(NumberToState==1) {Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); pc.printf("SAMPLING 1\n");}//Start Sampling else {pc.printf("Invalid State\n");} } //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");} //int NumberOfChars = 0; int ArrayAddress = 0; string DayNumber, MonthNumber, YearNumber; int NumberToDay, NumberToMonth, NumberToYear; for(int x=8; x < 10; x++){DayNumber += input[x];} stringstream Number_1(DayNumber); Number_1 >> NumberToDay; for(int x=11; x < 13; x++){MonthNumber += input[x];} stringstream Number_2(MonthNumber); Number_2 >> NumberToMonth; for(int x=14; x < 18; x++){YearNumber += input[x];} stringstream Number_3(YearNumber); Number_3 >> NumberToYear; if(Log_Value == 4){pc.printf("Year Input %d Month Input %d Day Input %d\n",NumberToYear,NumberToMonth,NumberToDay);} set_new_date(NumberToDay,NumberToMonth,NumberToYear); pc.printf("DATE UPDATED TO %02d %02d %d\n",NumberToDay,NumberToMonth,NumberToYear); } //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");} //int NumberOfChars = 0; int ArrayAddress = 0; string HourNumber, MinuteNumber, SecondNumber; int NumberToHour, NumberToMinute, NumberToSecond; for(int x=8; x < 10; x++){HourNumber += input[x];} stringstream Number_1(HourNumber); Number_1 >> NumberToHour; for(int x=11; x < 13; x++){MinuteNumber += input[x];} stringstream Number_2(MinuteNumber); Number_2 >> NumberToMinute; for(int x=14; x < 16; x++){SecondNumber += input[x];} stringstream Number_3(SecondNumber); Number_3 >> NumberToSecond; if(Log_Value == 4){pc.printf("Hour Input %d Minute Input %d Seconds Input %d",NumberToHour,NumberToMinute,NumberToSecond);} set_new_time(NumberToHour,NumberToMinute,NumberToSecond); pc.printf("TIME UPDATED TO %02d %02d %02d\n",NumberToHour,NumberToMinute,NumberToSecond); } //SETT else if(input[0] == 'S' & input[1] == 'E' & input[2] == 'T' & input[3] == 'T' & input[4] == ' ') { if(Log_Value == 4){pc.printf("SETT Confirmed\n");} int NumberOfChars = 0; int ArrayAddress = 0; string SettNumber; double NumberToSett; int Decimal_Divider = 10; float Sample_Rate_Integer = 0; string Sample_Rate_Integer_String; float Sample_Rate_Decimal = 0; string Sample_Rate_Decimal_String; while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} if (Decimal_Check(input) == true) { for(int x = 5; x < Decimal_Position(input); x++){Sample_Rate_Integer_String += input[x];} stringstream Number_1(Sample_Rate_Integer_String); Number_1 >> Sample_Rate_Integer; for(int x = Decimal_Position(input) + 1; x < NumberOfChars; x++){Sample_Rate_Decimal_String += input[x];} stringstream Number_2(Sample_Rate_Decimal_String); Number_2 >> Sample_Rate_Decimal; for(int tens_power = 1; tens_power != NumberOfChars - Decimal_Position(input) - 1; tens_power++) { Decimal_Divider = Decimal_Divider * 10; } NumberToSett = Sample_Rate_Integer + (Sample_Rate_Decimal / float(Decimal_Divider)); } else { for(int x=5; x < NumberOfChars; x++){SettNumber += input[x];} stringstream Number_3(SettNumber); Number_3 >> NumberToSett; } if(Log_Value == 4){pc.printf("Sample Rate Input %d\n",NumberToSett);} if(Log_Value == 4){pc.printf("Decimal Rate Input %d\n",Sample_Rate_Decimal);} if(Log_Value == 4){pc.printf("Integer Rate Input %d\n",Sample_Rate_Integer);} if(NumberToSett >= 0.1 & NumberToSett <= 60) { Sample_Rate = NumberToSett; pc.printf("T UPDATED TO %1.1f \n",NumberToSett); } else { Sample_Rate = Sample_Rate;//No change pc.printf("OUT OF RANGE\n"); } Sampling_Timer.detach(); Console_Output_Timer.detach(); Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); } //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; while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} for(int x=8; x < NumberOfChars; x++){LoggingNumber += input[x];} stringstream Number(LoggingNumber); Number >> NumberToLogging; if (NumberToLogging == 0){pc.printf("NOT LOGGING\n");} else if (NumberToLogging == 1){pc.printf("LOGGING LCD\n");} else if (NumberToLogging == 2){pc.printf("LOGGING NETWORKING\n");} else if (NumberToLogging == 3){pc.printf("LOGGING SAMPLING\n");} else if (NumberToLogging == 4){pc.printf("LOGGING SERIAL COMMANDS\n");} else if (NumberToLogging == 5){pc.printf("LOGGING SD CARD\n");} else if (NumberToLogging >= 6){pc.printf("INVALID LOGGING COMMAND\n");} if (NumberToLogging <= 5){Log_Value = NumberToLogging;} } //HELP else if(input[0] == 'H' & input[1] == 'E' & input[2] == 'L' & input[3] == 'P')// Use this to display all of the availble commands { pc.printf("Avalible Commands are: \n"); pc.printf("READ ALL\nDELETE ALL\nREAD <n>\nDELETE <n>\nSETDATE <dd> <mm> <yyyy>\nSETTIME <hh> <mm> <ss>\nSETT <T>\nSTATE <x>\nLOGGING <x>\nNETSET <n>\nHELP\n"); } //NETSET 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 { if(Log_Value == 4){pc.printf("NETSET confirmed\n");} int NumberOfChars = 0; int ArrayAddress = 0; string NetSetNumber; int NumberToNetSet; while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} for(int x=7; x < NumberOfChars; x++){NetSetNumber += input[x];} stringstream Number(NetSetNumber); Number >> NumberToNetSet; if(Log_Value == 4){pc.printf("NETSET Number %d",NumberToNetSet);} if(NumberToNetSet < 1) { NumberToNetSet = 1; } else { NumberToNetSet = NumberToNetSet; } NetworkWaitTime = (NumberToNetSet * 1000); } else { pc.printf("Please enter an acceptable command\n"); } }