Proj 324 Final

Fork of ELEC351_Group_T by Plymouth ELEC351 Group T

Revision:
34:c0b8705f183d
Parent:
33:3b5096f0126a
Child:
35:26b0a9b55d82
--- a/main.cpp	Sun Jan 07 00:45:11 2018 +0000
+++ b/main.cpp	Sun Jan 07 03:08:00 2018 +0000
@@ -16,20 +16,7 @@
 
 void Network()                                                                  //Interrupt service routine for handling the timeout
 {
-    osEvent evt_network = mail_box.get();                                       //Get the latest entry from "mail_box"
 
-    if (evt_network.status == osEventMail) {
-        DATA *Rec_Data_Network = (DATA*)evt_network.value.p;                    //Create pointer to mailbox
-        DATA msg_network;                                                       //Create temporary instance of DATA class
-
-        msg_network.set_time(Rec_Data_Network->get_time());                     //Copy time from mailbox to temporary instance
-        msg_network.set_temperature(Rec_Data_Network->get_temperature());       //Copy temperature from mailbox to temporary instance
-        msg_network.set_pressure(Rec_Data_Network->get_pressure());             //Copy pressure from mailbox to temporary instance
-        msg_network.set_light(Rec_Data_Network->get_light());                   //Copy light from mailbox to temporary instance
-        mail_box.free(Rec_Data_Network);                                        //Free space in the mailbox (delete earliest sample taken)
-
-        networktest();
-    }
 }
 void LCD_Write_Year()
 {
@@ -126,29 +113,17 @@
 }
 
 void LCD_Output()
-{          
+{      
     while(1)
     {
         Thread::wait(10);//Dont Delete
-        osEvent evt_lcd = mail_box.get();                        //Get the latest entry from "mail_box"
-        DATA msg_lcd;  //Create temporary instance of DATA class
-        if (evt_lcd.status == osEventMail)
-        {
-            DATA *Rec_Data_LCD = (DATA*)evt_lcd.value.p;                    //Create pointer to mailbox
-
-            msg_lcd.set_time(Rec_Data_LCD->get_time());                     //Copy time from mailbox to temporary instance
-            msg_lcd.set_temperature(Rec_Data_LCD->get_temperature());       //Copy temperature from mailbox to temporary instance
-            msg_lcd.set_pressure(Rec_Data_LCD->get_pressure());             //Copy pressure from mailbox to temporary instance
-            msg_lcd.set_light(Rec_Data_LCD->get_light());                   //Copy light from mailbox to temporary instance
-            mail_box.free(Rec_Data_LCD);                                    //Free space in the mailbox (delete earliest sample taken)
-        }
         if(mode == 0)//Default mode
         { 
-            cout << "In mode 0 " << endl;
+            if(Log_Value == 1){cout << "In mode 0 " << endl;}
             
             Thread::wait(3000);
     
-            sprintf (LCD_buffer, "%1.1f %1.1f %1.1f",msg_lcd.get_temperature(),msg_lcd.get_pressure(),msg_lcd.get_light());//Used for converting to a sting  
+            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);
             LCD.Write_String("Temp Pres  li");
@@ -158,8 +133,8 @@
             Thread::wait(3000);    
             
             Time_Lock_Main.lock();
-            time_t Time = time(NULL);
-            tm* Time_Pointer = localtime(&Time);            
+            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  
             Time_Lock_Main.unlock(); 
@@ -176,7 +151,7 @@
         }
         else if(mode == 1)//Choose either date setting or time setting
         {
-            cout << "In Mode 1" << endl;
+            if(Log_Value == 1){cout << "In Mode 1" << endl;}
             LCD.Display_Clear();
             while(1)
             {
@@ -199,7 +174,7 @@
         } 
         else if(mode == 2)//Set the Year
         {
-            cout << "In Mode 2" << endl;
+            if(Log_Value == 1){cout << "In Mode 2" << endl;}
             LCD.Display_Clear();
             while(1)
             {          
@@ -223,7 +198,7 @@
         } 
         else if(mode == 3)//Set the Month
         {
-            cout << "In Mode 3" << endl;
+            if(Log_Value == 1){cout << "In Mode 3" << endl;}
             LCD.Display_Clear();
             while(1)
             {
@@ -247,7 +222,7 @@
         }
         else if(mode == 4)//Set the Day
         {
-            cout << "In Mode 4" << endl;
+            if(Log_Value == 1){cout << "In Mode 4" << endl;}
             LCD.Display_Clear();
             while(1)
             {      
@@ -270,7 +245,7 @@
         } 
         else if(mode == 5)//Set the Hour
         {
-            cout << "In Mode 5" << endl;
+            if(Log_Value == 1){cout << "In Mode 5" << endl;}
             LCD.Display_Clear();
             while(1)
             {
@@ -289,13 +264,11 @@
                 {
                     Subtract_Hour();   
                 }
-                
-
             }
         } 
         else if(mode == 6)//Set the Minute
         {
-            cout << "In Mode 6" << endl;
+            if(Log_Value == 1){cout << "In Mode 6" << endl;}
             LCD.Display_Clear();
             while(1)
             {
@@ -318,7 +291,7 @@
         }  
         else if(mode == 7)//Set the Seconds
         {
-            cout << "In Mode 7" << endl;
+            if(Log_Value == 1){cout << "In Mode 7" << endl;}
             LCD.Display_Clear();
             while(1)
             {
@@ -348,15 +321,17 @@
 void Serial_Commands()//Used for getting input from the user to determine the opperations to perform
 {
     string Serial_Input;
+    int A,B,C;
     while(1) {
         Serial_Input = "Blank";
         cout << "Please type in a command" << endl;
-
-        cin >> Serial_Input;
+        
+        cin >> Serial_Input >> A >> B >> C;
 
         if (Serial_Input == "Test")
         {
             cout << "Test Confirmed" << endl;
+            cout << A << " " << B << " " << C << endl;
             cout << "This is the time " << get_current_time() << endl;
         } 
         else if(Serial_Input == "READALL")
@@ -370,43 +345,40 @@
         Console_Output_Timer.detach();
         for (int x = 0; x < mailsize; x++)
         {
-            DATA *Delete_Data = mail_box.alloc();       //Allocate a block from the memory pool, Type Data
-            mail_box.free(Delete_Data);                 //Puts "Send_Data" into the mailbox
+
         }
         Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);
         cout << "Sampling Restarted" << endl;
         } 
         else if(Serial_Input == "READ") 
         {
-            cout << "Please enter in the number of samples to read" <<endl;
-            int Loops;  cin >> Loops;
-            for (int x = 0; x < Loops; x++)
+            for (int x = 0; x < A; x++)
             {
                 Serial_Comms_Stealth_Mode();
+                if(Log_Value == 1){cout << "Read " << x << " samples" << endl;}
             }
         } 
         else if(Serial_Input == "DELETE")
         {
             Sampling_Timer.detach();
             Console_Output_Timer.detach();
-            cout << "Number of samples to delete:" << endl;
-            int Loops;  cin >> Loops;
-            for (int x = 0; x < Loops; x++){
-                DATA *Delete_Data = mail_box.alloc();       //Allocate a block from the memory pool, Type Data
-                mail_box.free(Delete_Data);                 //Puts "Send_Data" into the mailbox
+            for (int x = 0; x < A; x++){
+                if(Log_Value == 1){cout << "Deleted " << x << " samples" << endl;}
             }
             Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);
             cout << "Sampling Restarted" << endl;
         } 
         else if(Serial_Input == "SETDATE")
         {
-                set_time(SETDATE());
+            set_new_date(A,B,C);
+        }
+        else if(Serial_Input == "SETTIME")
+        {
+            set_new_time(A,B,C);    
         } 
         else if(Serial_Input == "SETT")
         {
-            float Temp_Sample_Rate = SETT();
-            
-            if(Temp_Sample_Rate >= 1){Sample_Rate = Temp_Sample_Rate;}
+            if(A >= 1){Sample_Rate = A;}
              
             Sampling_Timer.detach();
             Console_Output_Timer.detach();
@@ -414,16 +386,12 @@
         } 
         else if(Serial_Input == "STATE")
         {   
-            Sampling_Timer.detach(); Console_Output_Timer.detach();
-            cout << "Turn Sampling On or Off:" << endl;
-            string State;   cin >> State;
-            
-            if(State == "On"){Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);}
-            if(State == "Off"){Sampling_Timer.detach();}
+            if(A==0){Sampling_Timer.detach(); Console_Output_Timer.detach();}
+            if(A==1){Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);}
         } 
-        else if(Serial_Input == "LOGGING.<x>")
+        else if(Serial_Input == "LOGGING")
         {
-
+            Log_Value = A;
         } 
         else if(Serial_Input == "HELP")// Use this to display all of the availble commands
         { 
@@ -443,26 +411,19 @@
         }
     }
 }
-void Serial_Comms_Stealth_Mode()//Change this name
+void Serial_Comms_Stealth_Mode()                                                        //Change this name
 {
-    osEvent evt_serial = mail_box.get();                                    //Get the latest entry from "mail_box"
-
-    DATA *Rec_Data_Serial = (DATA*)evt_serial.value.p;                      //Create pointer to mailbox
-    DATA msg_serial;                                                        //Create temporary instance of DATA class
-    
-    msg_serial.set_time(Rec_Data_Serial->get_time());                       //Copy time from mailbox to temporary instance
-    msg_serial.set_temperature(Rec_Data_Serial->get_temperature());         //Copy teperature from mailbox to temporary instance
-    msg_serial.set_pressure(Rec_Data_Serial->get_pressure());               //Copy pressure from mailbox to temporary instance
-    msg_serial.set_light(Rec_Data_Serial->get_light());                     //Copy light from mailbox to temporary instance
-    mail_box.free(Rec_Data_Serial);                                         //Free space in the mailbox (delete earliest sample taken)
-    time_t scom_time = msg_serial.get_time();                               //Declare local variable for time
-    strftime(scom_time_buffer, 32, "%I:%M %p\t", localtime(&scom_time));    //Format time as a string
-    pc.printf("Time = %s", scom_time_buffer);                               //Print the string formatted time
-    pc.printf("Temperature = %f\t", msg_serial.get_temperature());          //Print Temperature
-    pc.printf("Pressure = %f\t", msg_serial.get_pressure());                //Print Pressure
-    pc.printf("Light = %f\n\r", msg_serial.get_light());                     //Print Light
+    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 Serial_Comms()//Thread for Serial Communications
 {
@@ -482,28 +443,16 @@
     {
         Thread::signal_wait(SamplingTime);      //Set the time between samples
 
-        temp = sensor.getTemperature();         //Read Temperature
-        pressure = sensor.getPressure();        //Read Pressure
-        lux = adcIn.read();                     //Read Light
+        Data_Active.set_temperature(sensor.getTemperature());   //Read Temperature
+        Data_Active.set_pressure(sensor.getPressure());         //Read Pressure
+        Data_Active.set_light(adcIn.read());                    //Read Light
         
         Time_Lock_Main.lock();
-        time_t buffer_time = time(NULL);        //Read Time
+        time_t buffer_time = time(NULL);        
         Time_Lock_Main.unlock();
 
-        DATA *Send_Data = mail_box.alloc();     //Allocate a block from the memory pool, Type Data
+        Data_Active.set_time(buffer_time);
 
-        if (Send_Data ==  NULL) {return;}
-        
-        Send_Data->set_time(buffer_time);       //Pass in Time
-        Send_Data->set_temperature(temp);       //Pass in Temp
-        Send_Data->set_pressure(pressure);      //Pass in Pres
-        Send_Data->set_light(lux);              //Pass in Light
-
-        osStatus stat = mail_box.put(Send_Data);    //Puts "Send_Data" into the mailbox
-
-        if (stat == osErrorResource) {  //If mailbox overfills
-            mail_box.free(Send_Data);   //Free the mail box
-        }
         Red_led.Toggle();
         t1.signal_set(NotSamplingTime);
     }