Program for the water play project for the course Software Testing Practical 2016 given at the VU University

Dependencies:   mbed DRV88255 TextLCD Ping mbed-rtos

Revision:
27:4f73f754fdc9
Parent:
20:521f795ea9d7
Child:
38:930469a33001
--- a/AlarmController.cpp	Mon Jun 13 13:57:38 2016 +0000
+++ b/AlarmController.cpp	Tue Jun 14 09:23:29 2016 +0000
@@ -1,26 +1,37 @@
 #include "AlarmController.h"
-
+//timers
 Timer temptimer;
 Timer salttimer;
+Timer overflowtimer;
 
+//outputpins for alarm
 DigitalOut buzzer(p17);
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
 DigitalOut led3(LED3);
 DigitalOut led4(LED4);
 
+//tresholds for temperature (in celcius)
 float temp_value_min_crit = 30.0f;
 float temp_value_min_undesired = 32.0f;
 float temp_value_max_crit = 40.0f;
 float temp_value_max_undesired = 38.0f;
 
+//tresholds for salinity (in ppt)
 float salt_value_min_crit = 3.0f;
 float salt_value_min_undesired = 6.0f;
 float salt_value_max_crit = 12.0f;
 float salt_value_max_undesired = 9.0f;
 
+//tresholds for overflow (in ml)
+float overflow_value_min_crit = 0.0f;
+float overflow_value_min_undesired = 100.0f;
+float overflow_value_max_crit = 1000.0f;
+float overflow_value_max_undesired = 900.0f;
+
 float readtemp;
 float readsalt;
+float readoverflow;
 
 void AlarmController::update() {
     readtemp = this->temp->getValue();
@@ -57,6 +68,21 @@
         this->saltiscrit = false;
     }    
     
+    readoverflow = this->proximity->getValue();
+        if ((readoverflow < overflow_value_min_undesired) || (readoverflow > overflow_value_max_undesired))
+    {
+        if ((readoverflow < overflow_value_min_crit) || (readoverflow > overflow_value_max_crit))
+        {
+            this->raiseAlarmOverFlow(true);
+        } else {
+            this->raiseAlarmOverFlow(false);
+        }
+    } else {
+        //clear alarm
+        overflowtimer.stop();
+        this->overflowiscrit = false;
+    }  
+    
 }
 
 void AlarmController::raiseAlarmTemp(bool isCrit)
@@ -69,6 +95,9 @@
         if ((readtimer >= 30 && tempiscrit) || (readtimer >= 300 && !tempiscrit))
         {
             //DO STUFF!!
+            
+            this->error = true;
+            if (this->tempiscrit) {this->error_msg = "Crit temp!"; } else { this->error_msg = "Undes temp!"; }
             printf("### Temperature alarm has been triggered after %d ###\r\n",readtimer);
             buzzOnce();
             temptimer.stop();
@@ -90,6 +119,9 @@
         if ((readtimer >= 30 && saltiscrit) || (readtimer >= 300 && !saltiscrit))
         {
             //DO STUFF!!
+            
+            this->error = true;
+            if (this->saltiscrit) {this->error_msg = "Crit salt!"; } else { this->error_msg = "Undes salt!"; }
             printf("### Salt alarm has been triggered after %d seconds ###\r\n",readtimer);
             buzzOnce();
             salttimer.stop();
@@ -101,6 +133,30 @@
     }
 }
 
+void AlarmController::raiseAlarmOverFlow(bool isCrit)
+{
+    this->overflowiscrit = isCrit;
+    int readtimer = overflowtimer.read();
+    if (isCrit) printf("Received a critical overflow alarm (%.3f), timer is at %d\r\n",readoverflow,readtimer);
+    if (!isCrit) printf("Received a non-critical overflow alarm (%.3f), timer is at %d\r\n",readoverflow,readtimer);
+    if (readtimer > 0 ) { //already running
+        if ((readtimer >= 30 && overflowiscrit) || (readtimer >= 300 && !overflowiscrit))
+        {
+            //DO STUFF!!
+            this->error = true;
+            if (this->overflowiscrit) {this->error_msg = "Crit volume!"; } else { this->error_msg = "Undes volume!"; }
+            
+            printf("### Overflow alarm has been triggered after %d seconds ###\r\n",readtimer);
+            buzzOnce();
+            overflowtimer.stop();
+            overflowtimer.reset();
+            this->overflowiscrit = false;
+        }
+    } else {
+        overflowtimer.start();    
+    }
+}
+
 std::string AlarmController::get_name() {
     return "AlarmController";    
 }