![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Proj 324 Final
Fork of ELEC351_Group_T by
Diff: main.cpp
- Revision:
- 39:5c499989d2b9
- Parent:
- 38:8d86e0d8a816
- Child:
- 40:d04aec00504f
- Child:
- 41:859b5e1e3d9a
--- a/main.cpp Sun Jan 07 21:08:34 2018 +0000 +++ b/main.cpp Sun Jan 07 23:01:38 2018 +0000 @@ -41,7 +41,6 @@ } DATA Read_Data(int Read_Pointer) { - Thread::signal_wait(Do_Read_Data); Data_Buffer_Lock.lock(); DATA Temp_Data = Data_Buffer[Read_Pointer]; Data_Buffer_Lock.unlock(); @@ -427,10 +426,35 @@ cin.getline(input,sizeof(input),'\r'); //READ ALL FIX THIS - if(input[0] == 'R' & input[1] == 'E' & input[2] == 'A' & input[3] == 'D' & input[4] == ' ' & input[5] == 'A' & input[6] == 'L' & input[7] == 'L' & input[8] == ' ') + if(input[0] == 'R' & input[1] == 'E' & input[2] == 'A' & input[3] == 'D' & input[4] == ' ' & input[5] == 'A' & input[6] == 'L' & input[7] == 'L') { - Console_Output_Timer.attach(&Console_Output_ISR,Sample_Rate); + if(Log_Value == 1){cout<<"READ ALL Confirmed"<<endl;} + + Data_Buffer_Lock.lock(); + int Start_Address_Read_All = Write_Pointer; + Data_Buffer_Lock.unlock(); + + 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;} + + DATA Serial_Read_Data = Read_Data(x_Read_All); + + 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 + + if(x_Read_All == mailsize - 1){x_Read_All = 0;} + else {x_Read_All = x_Read_All + 1;} + } } //DELETE ALL FIX THIS @@ -452,7 +476,36 @@ stringstream Number(ReadNumber); Number >> NumberToRead; - Serial_Comms_Data_Get(); + + if(Log_Value == 1){cout<<"Getting Data"<<endl;} + + Data_Buffer_Lock.lock(); + int Start_Address = Write_Pointer; + Data_Buffer_Lock.unlock(); + + for(int x = (Start_Address - NumberToRead); x != Start_Address; x = 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); + + 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 + + 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;} } @@ -596,17 +649,7 @@ Green_led.Toggle(); } -void Serial_Comms()//Thread for Serial Communications -{ - while(1) - { - Thread::signal_wait(SerialCommsTime);//Stupid 0 Bug - Serial_Comms_Data_Get(); - if(Log_Value == 1){cout<<"In Serial Comms"<<endl;} - } -} -void Console_Output_ISR() {t2.signal_set(SerialCommsTime);} void Sampling_ISR() {t1.signal_set(SamplingTime);} @@ -627,6 +670,7 @@ Data_Active.set_time(buffer_time); Red_led.Toggle(); + Write_Pointer = Write_Data(Data_Active,Write_Pointer); t1.signal_set(NotSamplingTime); if(Log_Value == 1){cout<<"New Sample avaliable"<<endl;} } @@ -681,7 +725,6 @@ Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); t1.start(Sample); - t2.start(Serial_Comms); t3.start(LCD_Output); t4.start(Network); t5.start(Serial_Commands);