![](/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
Diff: SERIAL_COMMANDS.cpp
- Revision:
- 48:244d6d81bb52
- Parent:
- 47:6d128e500875
--- a/SERIAL_COMMANDS.cpp Mon Jan 08 21:53:40 2018 +0000 +++ b/SERIAL_COMMANDS.cpp Tue Jan 09 00:37:01 2018 +0000 @@ -1,6 +1,6 @@ #include "SERIAL_COMMANDS.hpp" - -extern char input[100] = {}; +int NetworkWaitTime; +char input[100] = {}; Ticker Console_Output_Timer; Ticker Sampling_Timer;//Controls Sampling @@ -8,7 +8,7 @@ void Serial_Commands_Output()//Used for getting input from the user to determine the opperations to perform { - if(Log_Value == 1){pc.printf("In Serial_Commands\n");} + 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 @@ -18,7 +18,7 @@ //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 == 1){pc.printf("READ ALL Confirmed\n");} + 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; @@ -28,7 +28,7 @@ { 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(); @@ -48,7 +48,7 @@ //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 == 1){pc.printf("DELETE ALL Confirmed\n");} + if(Log_Value == 4){pc.printf("DELETE ALL Confirmed\n");} Data_Buffer_Lock.lock(); int Start_Address = Write_Pointer; @@ -56,6 +56,7 @@ 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;} @@ -71,25 +72,24 @@ //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; } - - if(Log_Value == 1){pc.printf("Getting Data\n");} - 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;} @@ -99,7 +99,7 @@ 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("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 @@ -107,13 +107,13 @@ if(x == mailsize - 1){x = 0;} else {x = x + 1;} } - if(Log_Value == 1){pc.printf("Read %d samples\n",NumberToRead);} - + 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];} @@ -124,7 +124,7 @@ { NumberToDelete = mailsize; } - if(Log_Value == 1){pc.printf("Deleted %d samples\n",NumberToDelete);} + if(Log_Value == 4){pc.printf("Deleted %d samples\n",NumberToDelete);} Data_Buffer_Lock.lock(); int Start_Address = Write_Pointer; @@ -132,6 +132,7 @@ 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;} @@ -142,17 +143,19 @@ } pc.printf("DELETED %d RECORDS\n",NumberToDelete); - if(Log_Value == 1){pc.printf("Deleted %d samples\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 @@ -163,6 +166,7 @@ //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; @@ -178,7 +182,7 @@ 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); } @@ -186,6 +190,7 @@ //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; @@ -201,7 +206,7 @@ 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); } @@ -209,7 +214,7 @@ //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; @@ -240,7 +245,11 @@ 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; @@ -263,19 +272,47 @@ for(int x=8; x < NumberOfChars; x++){LoggingNumber += input[x];} stringstream Number(LoggingNumber); Number >> NumberToLogging; - if(NumberToLogging != 1) - { - NumberToLogging = 0; - } - Log_Value = NumberToLogging; - pc.printf("LOGGING %d\n",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 { - HELP();//Run HELP Command + 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");