Plymouth ELEC351 Group T
/
ELEC351_Group_T
FINAL PROJECT isn't it
Fork of ELEC351 by
Diff: main.cpp
- Revision:
- 42:ae1640bca2e1
- Parent:
- 41:859b5e1e3d9a
- Child:
- 43:fb9faec1dc72
- Child:
- 45:875f7e18a386
--- a/main.cpp Mon Jan 08 14:20:30 2018 +0000 +++ b/main.cpp Mon Jan 08 15:38:53 2018 +0000 @@ -1,13 +1,16 @@ /* ELEC 351 Group T Team Members : Christopher Hills, Thomas Morris -Current Verision 18 -Overiew: Working Tasks 1,2,3,5,6,7,8,9,10,11,12,13 +Current Verision 19 +Overiew: Working Tasks 1,2,3,5,6,7,8,9,10,11,12,13,14,15 Last Revision: Added Mail Box to serial Todo: -make a mailbox within SD card, LCD, network so they can be used from within -Fix the network so it uses the mail box data. +Add functionality to SD card import chris's work on delete serial commnads +Commnet code +Check for race conditions +Move code around +Other fixes */ #include "SETUP.hpp" @@ -47,7 +50,6 @@ } void Delete_Data(int Delete_Pointer) { - Thread::signal_wait(Do_Delete_Data); Data_Buffer_Lock.lock();//Appling lock for critial section Data_Buffer[Delete_Pointer].set_all_zero(); Data_Buffer_Lock.unlock();//Releasing lock for critial section @@ -57,34 +59,41 @@ { while(1) { - Thread::signal_wait(SD_Data_Ready); //Waits till the sampler has data avaliable - if(Log_Value==1){cout << "In SD_Card Thread" << endl;} - - //Open to WRITE - FILE* fp = fopen("/sd/test.csv","a"); - time_t Time = Data_Active.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 - int temp_year = (Time_Pointer->tm_year+1900);//Set to current year - - int temp_hours = Time_Pointer->tm_hour; - int temp_minute = Time_Pointer->tm_min; + 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;} - float temp_temperature = Data_Active.get_temperature(); - float temp_pressure = Data_Active.get_pressure(); - float temp_light = Data_Active.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, "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 - - //Close File - fclose(fp); - //dump all Data_Buffer[mailsize]; + //Open to WRITE + FILE* fp = fopen("/sd/test.csv","a"); + if(Log_Value==1){cout << "File Opened" << endl;} + + for(int SD_Card_Data_Pointer = 0; SD_Card_Data_Pointer != mailsize; SD_Card_Data_Pointer++) + { + time_t Time = Data_Buffer[SD_Card_Data_Pointer].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 + int temp_year = (Time_Pointer->tm_year+1900);//Set to current year + + int temp_hours = Time_Pointer->tm_hour; + int temp_minute = Time_Pointer->tm_min; + + 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, "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 + } + if(Log_Value==1){cout << "Dumped data to SD Card" <<endl;} + //Close File + fclose(fp); + } } } void Network() @@ -485,14 +494,26 @@ } } - //DELETE ALL FIX THIS + //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] == ' ') { - Sampling_Timer.detach(); - Console_Output_Timer.detach(); - Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); - cout << "Sampling Restarted" << endl; if(Log_Value == 1){cout<<"DELETE ALL Confirmed"<<endl;} + + 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(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;} + + } } //READ @@ -538,13 +559,9 @@ } - //DELETE look into this + //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] == ' ') { - Sampling_Timer.detach();//Stop the Sample timer - Console_Output_Timer.detach();//Stop Console Printing - - 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];} @@ -553,8 +570,24 @@ if(Log_Value == 1){cout << "Deleted " << NumberToDelete << " samples" << endl;} - Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);//Start Sample timer - cout << "Sampling Restarted" << endl; + 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(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;} + + } + //Serial_Comms_Data_Get(); + if(Log_Value == 1){cout << "Deleted " << NumberToDelete << " samples" << endl;} + } //STATE