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
SensorAlarmController.cpp
- Committer:
- joran
- Date:
- 2016-06-20
- Revision:
- 67:851db0511c7c
- Parent:
- 64:735009c4c8aa
- Child:
- 72:f8c4f731f0fe
File content as of revision 67:851db0511c7c:
#include "SensorAlarmController.h" //outputpins for alarm static DigitalOut buzzer(p17); static DigitalOut led1(LED1); static DigitalOut led2(LED2); static DigitalOut led3(LED3); static DigitalOut led4(LED4); void SensorAlarmController::update() { #ifndef TEST_MODE if(this->num_iters < STARTUP_ITERATIONS) { cout << this->getName() << ": not running, startup phase"; return; } #endif value = sensor->getValue(); if ((value < min_undesired) || (value > max_undesired)) { if ((value < min_crit) || (value > max_crit)) { this->raiseAlarm(true); } else { this->raiseAlarm(false); } } else { //clear alarm timer.stop(); this->is_crit = false; sensor->setLed(false); } } void SensorAlarmController::raiseAlarm(bool isCrit) { this->is_crit = isCrit; int readtimer = timer.read(); if (isCrit) cout << "Received a critical " << this->sensor->getName() << " alarm " << value << " timer is at " << readtimer << "\r\n"; if (!isCrit) cout << "Received a non-critical " << this->sensor->getName() << " alarm " << value << " timer is at " << readtimer << "\r\n"; if (readtimer > 0 ) { //already running if ((readtimer >= NUMBER_OF_SEC_BEFORE_CRITICAL_ALARM && is_crit) || (readtimer >= NUMBER_OF_SEC_BEFORE_UNDESIRED_ALARM && !is_crit)) { this->error = true; if (this->is_crit) { this->error_msg = this->error_msg_critical; } else { this->error_msg = this->error_msg_undesired; } cout << "### " << this->getName() << " alarm has been triggered after " << " ###" << readtimer << "\r\n"; sensor->setLed(true); buzzOnce(); timer.stop(); timer.reset(); this->is_crit = false; } } else { timer.start(); } } std::string SensorAlarmController::getName() { return "AlarmController[" + this->sensor->getName() + "]"; } bool SensorAlarmController::isError() { return this->error; } std::string SensorAlarmController::getErrorMessage() { return this->error_msg; } void SensorAlarmController::setCriticalErrorMsg(std::string msg) { this->error_msg_critical = msg; } void SensorAlarmController::setUndesiredErrorMsg(std::string msg) { this->error_msg_undesired = msg; } void SensorAlarmController::buzzOnce() { buzzer = 1; wait(0.1); buzzer = 0; }