Thomas Morris
/
PROJ324_Final
Proj 324 Final
Fork of ELEC351_Group_T by
Diff: main.cpp
- Revision:
- 45:875f7e18a386
- Parent:
- 42:ae1640bca2e1
- Child:
- 46:bd9e7e40b3f9
--- a/main.cpp Mon Jan 08 15:38:53 2018 +0000 +++ b/main.cpp Mon Jan 08 18:43:58 2018 +0000 @@ -62,11 +62,11 @@ Thread::wait(Sample_Rate*1000); //Waits until a new is taken before checking again if(Write_Pointer == mailsize - 1) { - if(Log_Value==1){cout << "In SD_Card Thread" << endl;} + if(Log_Value==1){pc.printf("In SD_Card Thread\n\r");} //Open to WRITE FILE* fp = fopen("/sd/test.csv","a"); - if(Log_Value==1){cout << "File Opened" << endl;} + if(Log_Value==1){pc.printf("File Opened\n\r");} for(int SD_Card_Data_Pointer = 0; SD_Card_Data_Pointer != mailsize; SD_Card_Data_Pointer++) { @@ -78,32 +78,51 @@ int temp_hours = Time_Pointer->tm_hour; int temp_minute = Time_Pointer->tm_min; + int temp_seconds = Time_Pointer->tm_sec; float temp_temperature = Data_Buffer[SD_Card_Data_Pointer].get_temperature(); float temp_pressure = Data_Buffer[SD_Card_Data_Pointer].get_pressure(); float temp_light = Data_Buffer[SD_Card_Data_Pointer].get_light(); - fprintf(fp, "Date: %d/%d/%d,",temp_day,temp_month,temp_year);//Date - fprintf(fp, "Time: %d:%d,",temp_hours,temp_minute);//Time + fprintf(fp, "Date: %02d/%02d/%d,",temp_day,temp_month,temp_year);//Date + fprintf(fp, "Time: %02d:%02d:%02d,",temp_hours,temp_minute, temp_seconds);//Time fprintf(fp, "Temperature: %1.1f,",temp_temperature);//Temperature fprintf(fp, "Pressure: %1.1f,",temp_pressure);//Pressure fprintf(fp, "Light: %5.3f,",temp_light);//Light - fprintf(fp, "End of Data \n");//End of data + fprintf(fp, "End of Data \n\r");//End of data } - if(Log_Value==1){cout << "Dumped data to SD Card" <<endl;} + if(Log_Value==1){pc.printf("Dumped data to SD Card\n\r");} //Close File fclose(fp); } } } + +bool Decimal_Check(char Input[100]) +{ + for(int x = 0; x < mailsize; x++) + { + if(Input[x] == '.'){return true;} + } + return false; +} + +int Decimal_Position(char Input[100]) +{ + for(int x = 0; x < mailsize; x++) + { + if(Input[x] == '.'){return x;} + } + return 0; +} void Network() { while(1) { Thread::wait(NetworkWait);//Waits Network Wait amount of time - if(Log_Value==1){cout << "In Network Thread" << endl;} //Log this + if(Log_Value==1){pc.printf("In Network Thread\n\r");} - time_t Time = Data_Active.get_time(); + time_t Time = Data_Buffer[(Write_Pointer - 1)].get_time(); tm* Time_Pointer = localtime(&Time); int temp_day = Time_Pointer->tm_mday; int temp_month = (Time_Pointer->tm_mon+1);//Set to current month @@ -111,24 +130,25 @@ int temp_hours = Time_Pointer->tm_hour; int temp_minute = Time_Pointer->tm_min; + int temp_seconds = Time_Pointer->tm_sec; - float temp_temperature = Data_Active.get_temperature(); - float temp_pressure = Data_Active.get_pressure(); - float temp_light = Data_Active.get_light(); + float temp_temperature = Data_Buffer[(Write_Pointer - 1)].get_temperature(); + float temp_pressure = Data_Buffer[(Write_Pointer - 1)].get_pressure(); + float temp_light = Data_Buffer[(Write_Pointer - 1)].get_light(); - Networking(temp_day,temp_month,temp_year,temp_hours,temp_minute,temp_temperature,temp_pressure,temp_light);//Pass in networking data and time values + Networking(temp_day,temp_month,temp_year,temp_hours,temp_minute,temp_seconds,temp_temperature,temp_pressure,temp_light);//Pass in networking data and time values } } void LCD_Write_Year() { Time_Lock_Main.lock();//Appling lock for critial section - if(Log_Value == 1){cout<<"In LCD_Write_Year Time lock taken"<<endl;} + if(Log_Value == 1){pc.printf("In LCD_Write_Year Time lock taken\n\r");} time_t Time = time(NULL); tm* Time_Pointer = localtime(&Time); int Years = 1900 + Time_Pointer->tm_year; Time_Lock_Main.unlock();//Releasing lock for critial section - if(Log_Value == 1){cout<<"In LCD_Write_Year Time lock released"<<endl;} + if(Log_Value == 1){pc.printf("In LCD_Write_Year Time lock released\n\r");} stringstream ss; ss << Years; string Year_String = ss.str(); @@ -140,12 +160,12 @@ void LCD_Write_Month() { Time_Lock_Main.lock();//Appling lock for critial section - if(Log_Value == 1){cout<<"In LCD_Write_Month Time lock taken"<<endl;} + if(Log_Value == 1){pc.printf("In LCD_Write_Month Time lock taken\n\r");} time_t Time = time(NULL); tm* Time_Pointer = localtime(&Time); int Months = 1 + Time_Pointer->tm_mon; Time_Lock_Main.unlock();//Releasing lock for critial section - if(Log_Value == 1){cout<<"In LCD_Write_Month Time lock released"<<endl;} + if(Log_Value == 1){pc.printf("In LCD_Write_Month Time lock released\n\r");} stringstream ss; ss << Months; string Month_String = ss.str(); @@ -157,12 +177,12 @@ void LCD_Write_Day() { Time_Lock_Main.lock();//Appling lock for critial section - if(Log_Value == 1){cout<<"In LCD_Write_Day Time lock taken"<<endl;} + if(Log_Value == 1){pc.printf("In LCD_Write_Day Time lock taken\n\r");} time_t Time = time(NULL); tm* Time_Pointer = localtime(&Time); int Days = Time_Pointer->tm_mday; Time_Lock_Main.unlock();//Releasing lock for critial section - if(Log_Value == 1){cout<<"In LCD_Write_Day Time lock released"<<endl;} + if(Log_Value == 1){pc.printf("In LCD_Write_Day Time lock released\n\r");} stringstream ss; ss << Days; string Day_String = ss.str(); @@ -174,12 +194,12 @@ void LCD_Write_Hour() { Time_Lock_Main.lock();//Appling lock for critial section - if(Log_Value == 1){cout<<"In LCD_Write_Hour Time lock taken"<<endl;} + if(Log_Value == 1){pc.printf("In LCD_Write_Hour Time lock taken\n\r");} time_t Time = time(NULL); tm* Time_Pointer = localtime(&Time); int Hours = Time_Pointer->tm_hour; Time_Lock_Main.unlock();//Releasing lock for critial section - if(Log_Value == 1){cout<<"In LCD_Write_Hour Time lock released"<<endl;} + if(Log_Value == 1){pc.printf("In LCD_Write_Hour Time lock released\n\r");} stringstream ss; ss << Hours; string Hour_String = ss.str(); @@ -191,12 +211,12 @@ void LCD_Write_Minute() { Time_Lock_Main.lock();//Appling lock for critial section - if(Log_Value == 1){cout<<"In LCD_Write_Minute Time lock taken"<<endl;} + if(Log_Value == 1){pc.printf("In LCD_Write_Minute Time lock taken\n\r");} time_t Time = time(NULL); tm* Time_Pointer = localtime(&Time); int Minutes = Time_Pointer->tm_min; Time_Lock_Main.unlock();//Releasing lock for critial section - if(Log_Value == 1){cout<<"In LCD_Write_Minute Time lock released"<<endl;} + if(Log_Value == 1){pc.printf("In LCD_Write_Minute Time lock released\n\r");} stringstream ss; ss << Minutes; string Minute_String = ss.str(); @@ -208,12 +228,12 @@ void LCD_Write_Seconds() { Time_Lock_Main.lock();//Appling lock for critial section - if(Log_Value == 1){cout<<"In LCD_Write_Seconds Time lock taken"<<endl;} + if(Log_Value == 1){pc.printf("In LCD_Write_Seconds Time lock taken\n\r");} time_t Time = time(NULL); tm* Time_Pointer = localtime(&Time); int Seconds = Time_Pointer->tm_sec; Time_Lock_Main.unlock();//Releasing lock for critial section - if(Log_Value == 1){cout<<"In LCD_Write_Seconds Time lock released"<<endl;} + if(Log_Value == 1){pc.printf("In LCD_Write_Seconds Time lock released\n\r");} stringstream ss; ss << Seconds; string Second_String = ss.str(); @@ -230,10 +250,10 @@ Thread::wait(10);//Small wait if(mode == 0)//Default mode { - if(Log_Value == 1){cout << "In mode 0 " << endl;}//Log this + if(Log_Value == 1){pc.printf("In mode 0 \n\r");} Thread::wait(Default_Mode_Toggle_Time);//Wait for this amount of time - if(Log_Value == 1){cout<<"Writing Data to LCD"<<endl;} + if(Log_Value == 1){pc.printf("Writing Data to LCD\n\r");} sprintf (LCD_buffer, "%1.1f %1.1f %1.1f",Data_Active.get_temperature(),Data_Active.get_pressure(),Data_Active.get_light());//Used for converting to a sting LCD.DDRAM_Address(0x00); @@ -242,12 +262,12 @@ LCD.Write_String(LCD_buffer);//Print out current data values to the LCD Thread::wait(Default_Mode_Toggle_Time); //Wait for this amount of time - if(Log_Value == 1){cout<<"Writing Time and Date to LCD"<<endl;} + if(Log_Value == 1){pc.printf("Writing Time and Date to LCD\n\r");} Time_Lock_Main.lock();//lock Time_lock for critial section time_t Time = Data_Active.get_time(); tm* Time_Pointer = localtime(&Time); LCD.Display_Clear(); - sprintf (LCD_buffer, "%d:%d %d,%d",Time_Pointer->tm_hour,Time_Pointer->tm_min,(Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900));//Used for converting to a sting + sprintf (LCD_buffer, "%02d:%02d %02d,%d",Time_Pointer->tm_hour,Time_Pointer->tm_min,(Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900));//Used for converting to a sting Time_Lock_Main.unlock();//unlock Time_lock for critial section LCD.DDRAM_Address(0x00); @@ -255,7 +275,7 @@ LCD.DDRAM_Address(0x40); LCD.Write_String(LCD_buffer);//Print the current time to the LCD - if(Log_Value == 1){cout<<"Checking Switches for next mode"<<endl;} + if(Log_Value == 1){pc.printf("Checking Switches for next mode\n\r");} if(SW1.read() & SW2.read() == 1) { mode = 1; @@ -263,7 +283,7 @@ } else if(mode == 1)//Choose either date setting or time setting { - if(Log_Value == 1){cout << "In Mode 1" << endl;} + if(Log_Value == 1){pc.printf("In Mode 1\n\r");} LCD.Display_Clear(); while(1) { @@ -272,13 +292,13 @@ LCD.DDRAM_Address(0x40); LCD.Write_String("< >"); Thread::wait(1000); - if(Log_Value == 1){cout<<"Checking SW1 to go to Date setting"<<endl;} + if(Log_Value == 1){pc.printf("Checking SW1 to go to Date setting\n\r");} if(SW1.read() == 1 & SW2.read() == 0) { mode = 2;//Date Setting break; } - if(Log_Value == 1){cout<<"Checking SW2 to go to Time setting"<<endl;} + if(Log_Value == 1){pc.printf("Checking SW2 to go to Time setting\n\r");} if(SW2.read() == 1 & SW1.read() == 0) { mode = 5;//Time Setting @@ -288,24 +308,24 @@ } else if(mode == 2)//Set the Year { - if(Log_Value == 1){cout << "In Mode 2" << endl;} + if(Log_Value == 1){pc.printf("In Mode 2\n\r");} LCD.Display_Clear(); while(1) { LCD_Write_Year(); Thread::wait(1000); - if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go to Month setting"<<endl;} + if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go to Month setting\n\r");} if(SW1.read() & SW2.read() == 1) { mode = 3; break; } - if(Log_Value == 1){cout<<"Checking SW1 to add Year"<<endl;} + if(Log_Value == 1){pc.printf("Checking SW1 to add Year\n\r");} if(SW1.read() == 1 & SW2.read() == 0) { Add_Year(); } - if(Log_Value == 1){cout<<"Checking SW2 to subtract Year"<<endl;} + if(Log_Value == 1){pc.printf("Checking SW2 to subtract Year\n\r");} else if(SW2.read() == 1 & SW1.read() == 0) { Subtract_Year(); @@ -315,24 +335,24 @@ } else if(mode == 3)//Set the Month { - if(Log_Value == 1){cout << "In Mode 3" << endl;} + if(Log_Value == 1){pc.printf("In Mode 3\n\r");} LCD.Display_Clear(); while(1) { LCD_Write_Month(); Thread::wait(1000); - if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go to Day setting"<<endl;} + if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go to Day setting\n\r");} if(SW1.read() & SW2.read() == 1) { mode = 4; break; } - if(Log_Value == 1){cout<<"Checking SW1 to add Month"<<endl;} + if(Log_Value == 1){pc.printf("Checking SW1 to add Month\n\r");} if(SW1.read() == 1 & SW2.read() == 0) { Add_Month(); } - if(Log_Value == 1){cout<<"Checking SW2 to subtract Month"<<endl;} + if(Log_Value == 1){pc.printf("Checking SW2 to subtract Month\n\r");} else if(SW2.read() == 1 & SW1.read() == 0) { Subtract_Month(); @@ -342,24 +362,24 @@ } else if(mode == 4)//Set the Day { - if(Log_Value == 1){cout << "In Mode 4" << endl;} + if(Log_Value == 1){pc.printf("In Mode 4\n\r");} LCD.Display_Clear(); while(1) { LCD_Write_Day(); Thread::wait(1000); - if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go Default setting"<<endl;} + if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go Default setting\n\r");} if(SW1.read() & SW2.read() == 1) { mode = 0; break; } - if(Log_Value == 1){cout<<"Checking SW1 to add Day"<<endl;} + if(Log_Value == 1){pc.printf("Checking SW1 to add Day\n\r");} if(SW1.read() == 1 & SW2.read() == 0) { Add_Day(); } - if(Log_Value == 1){cout<<"Checking SW2 to subtract Day"<<endl;} + if(Log_Value == 1){pc.printf("Checking SW2 to subtract Day\n\r");} else if(SW2.read() == 1 & SW1.read() == 0) { Subtract_Day(); @@ -368,24 +388,24 @@ } else if(mode == 5)//Set the Hour { - if(Log_Value == 1){cout << "In Mode 5" << endl;} + if(Log_Value == 1){pc.printf("In Mode 5\n\r");} LCD.Display_Clear(); while(1) { LCD_Write_Hour(); Thread::wait(1000); - if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go Minute setting"<<endl;} + if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go Minute setting\n\r");} if(SW1.read() & SW2.read() == 1) { mode = 6; break; } - if(Log_Value == 1){cout<<"Checking SW1 to add Hour"<<endl;} + if(Log_Value == 1){pc.printf("Checking SW1 to add Hour\n\r");} if(SW1.read() == 1 & SW2.read() == 0) { Add_Hour(); } - if(Log_Value == 1){cout<<"Checking SW2 to subtract Hour"<<endl;} + if(Log_Value == 1){pc.printf("Checking SW2 to subtract Hour\n\r");} else if(SW2.read() == 1 & SW1.read() == 0) { Subtract_Hour(); @@ -394,24 +414,24 @@ } else if(mode == 6)//Set the Minute { - if(Log_Value == 1){cout << "In Mode 6" << endl;} + if(Log_Value == 1){pc.printf("In Mode 6\n\r");} LCD.Display_Clear(); while(1) { LCD_Write_Minute(); Thread::wait(1000); - if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go Seconds setting"<<endl;} + if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go Seconds setting\n\r");} if(SW1.read() & SW2.read() == 1) { mode = 7; break; } - if(Log_Value == 1){cout<<"Checking SW1 to add Minute"<<endl;} + if(Log_Value == 1){pc.printf("Checking SW1 to add Minute\n\r");} if(SW1.read() == 1 & SW2.read() == 0) { Add_Minute(); } - if(Log_Value == 1){cout<<"Checking SW2 to subtract Minute"<<endl;} + if(Log_Value == 1){pc.printf("Checking SW2 to subtract Minute\n\r");} else if(SW2.read() == 1 & SW1.read() == 0) { Subtract_Minute(); @@ -420,24 +440,24 @@ } else if(mode == 7)//Set the Seconds { - if(Log_Value == 1){cout << "In Mode 7" << endl;} + if(Log_Value == 1){pc.printf("In Mode 7\n\r");} LCD.Display_Clear(); while(1) { LCD_Write_Seconds(); Thread::wait(1000); - if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go Default setting"<<endl;} + if(Log_Value == 1){pc.printf("Checking SW1 and SW2 to go Default setting\n\r");} if(SW1.read() & SW2.read() == 1) { mode = 0; break; } - if(Log_Value == 1){cout<<"Checking SW1 to add Second"<<endl;} + if(Log_Value == 1){pc.printf("Checking SW1 to add Second\n\r");} if(SW1.read() == 1 & SW2.read() == 0) { Add_Second(); } - if(Log_Value == 1){cout<<"Checking SW1 to subtract Second"<<endl;} + if(Log_Value == 1){pc.printf("Checking SW1 to subtract Second\n\r");} else if(SW2.read() == 1 & SW1.read() == 0) { Subtract_Second(); @@ -446,7 +466,7 @@ } else { - if(Log_Value == 1){cout<<"Mode Error occured mode now set to 0"<<endl;} + if(Log_Value == 1){pc.printf("Mode Error occured mode now set to 0\n\r");} mode = 0; } } @@ -456,17 +476,17 @@ char input[100]; while(1) { - if(Log_Value == 1){cout<<"In Serial_Commands"<<endl;} + if(Log_Value == 1){pc.printf("In Serial_Commands\n\r");} for (int x = 0; x < 100; x++){input[x] = ' ';}; - cout << "Please type in a command" << endl;//Log this + pc.printf("Please type in a command\n\r");//Log this cin.getline(input,sizeof(input),'\r'); - //READ ALL FIX THIS + //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){cout<<"READ ALL Confirmed"<<endl;} + if(Log_Value == 1){pc.printf("READ ALL Confirmed\n\r");} Data_Buffer_Lock.lock();//Lock data buffer due to critical section int Start_Address_Read_All = Write_Pointer; @@ -482,12 +502,11 @@ time_t Time = Serial_Read_Data.get_time(); tm* Time_Pointer = localtime(&Time); - strftime(scom_time_buffer, 32, "%I:%M %p\t", Time_Pointer); //Format time as a string - pc.printf("Date = %d %d %d\t", Time_Pointer->tm_mday, (Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900)); - pc.printf("Time = %s", scom_time_buffer); //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\r", Serial_Read_Data.get_light()); //Print Light + 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\r", 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;} @@ -495,9 +514,9 @@ } //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' & input[10] == ' ') + 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){cout<<"DELETE ALL Confirmed"<<endl;} + if(Log_Value == 1){pc.printf("DELETE ALL Confirmed\n\r");} Data_Buffer_Lock.lock(); int Start_Address = Write_Pointer; @@ -514,6 +533,7 @@ else {x_Delete_All = x_Delete_All + 1;} } + pc.printf("DELETED %d RECORDS\n\r",mailsize); } //READ @@ -525,8 +545,12 @@ stringstream Number(ReadNumber); Number >> NumberToRead; + if(NumberToRead > mailsize) + { + NumberToRead = mailsize; + } - if(Log_Value == 1){cout<<"Getting Data"<<endl;} + if(Log_Value == 1){pc.printf("Getting Data\n\r");} Data_Buffer_Lock.lock();//Lock data buffer due to critical section int Start_Address = Write_Pointer; @@ -541,21 +565,17 @@ time_t Time = Serial_Read_Data.get_time(); tm* Time_Pointer = localtime(&Time); - - strftime(scom_time_buffer, 32, "%I:%M %p\t", Time_Pointer); //Format time as a string - pc.printf("Date = %d %d %d\t", Time_Pointer->tm_mday, (Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900)); - pc.printf("Time = %s", scom_time_buffer); //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\r", Serial_Read_Data.get_light()); //Print Light + + 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\r", Serial_Read_Data.get_light()); //Print Light if(x == mailsize - 1){x = 0;} else {x = x + 1;} - - Green_led.Toggle(); } - //Serial_Comms_Data_Get(); - if(Log_Value == 1){cout << "Read " << NumberToRead << " samples" << endl;} + if(Log_Value == 1){pc.printf("Read %d samples\n\r",NumberToRead);} } @@ -568,7 +588,11 @@ stringstream Number(DeleteNumber); Number >> NumberToDelete; - if(Log_Value == 1){cout << "Deleted " << NumberToDelete << " samples" << endl;} + if(NumberToDelete > mailsize) + { + NumberToDelete = mailsize; + } + if(Log_Value == 1){pc.printf("Deleted %d samples\n\r",NumberToDelete);} Data_Buffer_Lock.lock(); int Start_Address = Write_Pointer; @@ -585,9 +609,8 @@ else {x_Delete = x_Delete + 1;} } - //Serial_Comms_Data_Get(); - if(Log_Value == 1){cout << "Deleted " << NumberToDelete << " samples" << endl;} - + pc.printf("DELETED %d RECORDS\n\r",NumberToDelete); + if(Log_Value == 1){pc.printf("Deleted %d samples\n\r",NumberToDelete);} } //STATE @@ -599,8 +622,10 @@ stringstream Number(StateNumber); Number >> NumberToState; - if(NumberToState==0){Sampling_Timer.detach(); Console_Output_Timer.detach();}//Stop Sampling - if(NumberToState==1){Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);}//Start Sampling + if(NumberToState==0) {Sampling_Timer.detach(); Console_Output_Timer.detach(); pc.printf("SAMPLING 0\n\r");}//Stop Sampling + else if(NumberToState==1) {Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); pc.printf("SAMPLING 1\n\r");}//Start Sampling + else {pc.printf("Invalid State\n\r");} + } //SETDATE @@ -623,6 +648,7 @@ Number_3 >> NumberToYear; set_new_date(NumberToDay,NumberToMonth,NumberToYear); + pc.printf("DATE UPDATED TO %02d %02d %d\n\r",NumberToDay,NumberToMonth,NumberToYear); } //SETTIME @@ -644,26 +670,59 @@ stringstream Number_3(SecondNumber); Number_3 >> NumberToSecond; - set_new_time(NumberToHour,NumberToMinute,NumberToSecond); + set_new_time(NumberToHour,NumberToMinute,NumberToSecond); + pc.printf("TIME UPDATED TO %02d %02d %02d\n\r",NumberToHour,NumberToMinute,NumberToSecond); } //SETT else if(input[0] == 'S' & input[1] == 'E' & input[2] == 'T' & input[3] == 'T' & input[4] == ' ') { - int NumberOfChars = 0; int ArrayAddress = 0; string SettNumber; int NumberToSett; + 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++;} - for(int x=5; x < NumberOfChars; x++){SettNumber += input[x];} - stringstream Number(SettNumber); - Number >> NumberToSett; + + 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(NumberToSett >= 1){Sample_Rate = NumberToSett;} + if(NumberToSett >= 0.1 & NumberToSett <= 60) + { + Sample_Rate = NumberToSett; + pc.printf("T UPDATED TO %1.1f \n\r",NumberToSett); + } + else + { + Sample_Rate = Sample_Rate;//No change + pc.printf("OUT OF RANGE"); + } 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] == ' ') { @@ -672,10 +731,12 @@ for(int x=8; x < NumberOfChars; x++){LoggingNumber += input[x];} stringstream Number(LoggingNumber); Number >> NumberToLogging; - - cout << "Successfully entered logging" << endl; - cout << NumberToLogging << endl; + if(NumberToLogging != 1) + { + NumberToLogging = 0; + } Log_Value = NumberToLogging; + pc.printf("LOGGING %d\n\r",NumberToLogging); } //HELP @@ -683,33 +744,12 @@ { HELP();//Run HELP Command } - - //STOP - else if(input[0] == 'S' & input[1] == 'T' & input[2] == 'O' & input[3] == 'P') - { - Console_Output_Timer.detach(); //Stops Sampling - } else { - cout << "Please enter an acceptable command" << endl; + pc.printf("Please enter an acceptable command\n\r"); } } } -void Serial_Comms_Data_Get() -{ - if(Log_Value == 1){cout<<"Getting Data"<<endl;} - time_t Time = Data_Active.get_time(); - tm* Time_Pointer = localtime(&Time); - strftime(scom_time_buffer, 32, "%I:%M %p\t", Time_Pointer); //Format time as a string - pc.printf("Date = %d %d %d\t", Time_Pointer->tm_mday, (Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900)); - pc.printf("Time = %s", scom_time_buffer); //Print the string formatted time - pc.printf("Temperature = %f\t", Data_Active.get_temperature()); //Print Temperature - pc.printf("Pressure = %f\t", Data_Active.get_pressure()); //Print Pressure - pc.printf("Light = %f\n\r", Data_Active.get_light()); //Print Light - - Green_led.Toggle(); - -} void Sampling_ISR(){t1.signal_set(SamplingTime);} @@ -719,7 +759,7 @@ while(1) { Thread::signal_wait(SamplingTime); //Set the time between samples - if(Log_Value == 1){cout<<"Sample Time"<<endl;} + if(Log_Value == 1){pc.printf("Sample Time\n\r");} Data_Active.set_temperature(sensor.getTemperature()); //Read Temperature Data_Active.set_pressure(sensor.getPressure()); //Read Pressure Data_Active.set_light(adcIn.read()); //Read Light @@ -730,10 +770,10 @@ Data_Active.set_time(buffer_time); - Red_led.Toggle(); + Red_led.flash(0.02);//ahh he saved everyone of us Write_Pointer = Write_Data(Data_Active,Write_Pointer); t1.signal_set(NotSamplingTime); - if(Log_Value == 1){cout<<"New Sample avaliable"<<endl;} + if(Log_Value == 1){pc.printf("New Sample avaliable\n\r");} t2.signal_set(SD_Data_Ready); } } @@ -750,7 +790,7 @@ //Initialise the SD card (this needs to move) if ( sd.init() != 0) { - printf("Init failed \n"); + printf("SD Init failed \n"); LCD.Display_Clear(); LCD.Write_String("CANNOT INIT SD"); //Change me errorCode(FATAL); @@ -816,11 +856,8 @@ LCD.DDRAM_Address(0x40); LCD.Write_String("Unmounted"); LCD.DDRAM_Address(0x00); - cout << "SD Card Unmounted" << endl; + pc.printf("SD Card Unmounted\n\r"); + Green_led.switchOn(); } - greenLED = 1; - wait(0.5); - greenLED = 0; - wait(0.1); } -}//End of Main +} \ No newline at end of file