Proj 324 Final

Fork of ELEC351_Group_T by Plymouth ELEC351 Group T

Revision:
14:45630ba388e1
Parent:
13:db857b3744c6
diff -r db857b3744c6 -r 45630ba388e1 main.cpp
--- a/main.cpp	Wed Dec 20 15:37:12 2017 +0000
+++ b/main.cpp	Wed Dec 20 21:32:57 2017 +0000
@@ -69,11 +69,14 @@
 
 int mode = 0;
 
-Mail<DATA, 120> mail_box;       //Mail Queue, Type DATA, Capacity 120, name mail_box
+Mail<DATA, 120> mail_box_network;           //Mail Queue, Type DATA, Capacity 120, name mail_box_network
+Mail<DATA, 120> mail_box_sd;                //Mail Queue, Type DATA, Capacity 120, name mail_box_sd
+Mail<DATA, 120> mail_box_lcd;               //Mail Queue, Type DATA, Capacity 120, name mail_box_lcd
+Mail<DATA, 120> mail_box_serial;            //Mail Queue, Type DATA, Capacity 120, name mail_box_serial
 
 void Network()                                  //Interrupt service routine for handling the timeout
 {
-    osEvent evt_network = mail_box.get();                        //Get the latest entry from "mail_box"
+    osEvent evt_network = mail_box_network.get();                        //Get the latest entry from "mail_box"
         
     if (evt_network.status == osEventMail)
     {
@@ -96,7 +99,7 @@
 }
 void SDWrite()//End of skype chat
 {
-    osEvent evt_sd = mail_box.get();                        //Get the latest entry from "mail_box"
+    osEvent evt_sd = mail_box_sd.get();                        //Get the latest entry from "mail_box"
         
     if (evt_sd.status == osEventMail)
     {
@@ -129,7 +132,7 @@
 
         Thread::wait(1000);
         
-        osEvent evt_lcd = mail_box.get();                        //Get the latest entry from "mail_box"
+        osEvent evt_lcd = mail_box_lcd.get();                        //Get the latest entry from "mail_box"
         
         if (evt_lcd.status == osEventMail)
         {
@@ -193,7 +196,7 @@
     pc.printf("Hello World \n");
     while(1)
     {
-        osEvent evt_serial = mail_box.get();                                   //Get the latest entry from "mail_box"
+        osEvent evt_serial = mail_box_serial.get();                                   //Get the latest entry from "mail_box"
         
         if (evt_serial.status == osEventMail)
         {
@@ -232,25 +235,43 @@
         lux = adcIn.read();                     //Read Light
         buffer_time = buffer;                   //Read Time
         
-        DATA *Send_Data = mail_box.alloc();           //Allocate a block from the memory pool, Type Data
+        DATA *Send_Data_network = mail_box_network.alloc();           //Allocate a block from the memory pool, Type Data
+        DATA *Send_Data_sd      = mail_box_sd.alloc();                //Allocate a block from the memory pool, Type Data
+        DATA *Send_Data_lcd     = mail_box_lcd.alloc();               //Allocate a block from the memory pool, Type Data
+        DATA *Send_Data_serial  = mail_box_serial.alloc();            //Allocate a block from the memory pool, Type Data
+        
+        if (Send_Data_network ==  NULL){return;}
+        if (Send_Data_sd      ==  NULL){return;}
+        if (Send_Data_lcd     ==  NULL){return;}
+        if (Send_Data_serial  ==  NULL){return;}
+        
+        Send_Data_network->set_time(buffer_time);   Send_Data_sd->set_time(buffer_time);    Send_Data_lcd->set_time(buffer_time);   Send_Data_serial->set_time(buffer_time);       //Pass in Time
+        Send_Data_network->set_temperature(temp);   Send_Data_sd->set_temperature(temp);    Send_Data_lcd->set_temperature(temp);   Send_Data_serial->set_temperature(temp);       //Pass in Temp
+        Send_Data_network->set_pressure(pressure);  Send_Data_sd->set_pressure(pressure);   Send_Data_lcd->set_pressure(pressure);  Send_Data_serial->set_pressure(pressure);      //Pass in Pres
+        Send_Data_network->set_light(lux);          Send_Data_sd->set_light(lux);           Send_Data_lcd->set_light(lux);          Send_Data_serial->set_light(lux);              //Pass in Light                                                        //Pass in Light
         
-        if (Send_Data ==  NULL){                     //If Data is empty
-            //pc.printf("Out of memory\n\r");     //Print out of memory warning
+        osStatus stat_network = mail_box_network.put(Send_Data_network);        //Puts "Send_Data" into the mailbox
+        if (stat_network == osErrorResource){                           //If mailbox overfills
+            mail_box_network.free(Send_Data_network);                   //Free the mail box
+            return;
+        }
+        osStatus stat_sd = mail_box_sd.put(Send_Data_sd);             //Puts "Send_Data" into the mailbox
+        if (stat_sd == osErrorResource){                           //If mailbox overfills
+            mail_box_sd.free(Send_Data_sd);                        //Free the mail box
+            return;
+        }
+        osStatus stat_lcd = mail_box_lcd.put(Send_Data_lcd);            //Puts "Send_Data" into the mailbox
+        if (stat_lcd == osErrorResource){                           //If mailbox overfills
+            mail_box_lcd.free(Send_Data_lcd);                       //Free the mail box
+            return;
+        }   
+        osStatus stat_serial = mail_box_serial.put(Send_Data_serial);         //Puts "Send_Data" into the mailbox
+        if (stat_serial == osErrorResource){                           //If mailbox overfills
+            mail_box_serial.free(Send_Data_serial);                    //Free the mail box
             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
-            //pc.printf("queue->put() Error code: %4Xh, Resource not available\r\n", stat);      //Print error message
-            mail_box.free(Send_Data);   //Free the mail box
-            return;
-        }
         Red_led.Toggle();
         t1.signal_set(NotSamplingTime);
     }