From a70ae2fd6167975d653436423daf9273b54d47de Mon Sep 17 00:00:00 2001
From: gscalamera <graziano.scalamera@elettra.eu>
Date: Tue, 11 Apr 2017 08:44:13 +0200
Subject: [PATCH] fixed bug when on/off delay and command execution

---
 src/Alarm.cpp       |  2 +-
 src/alarm_table.cpp | 14 ++++++++++----
 src/cmd_thread.cpp  |  6 +++---
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/Alarm.cpp b/src/Alarm.cpp
index 8df09c1..77f12bf 100644
--- a/src/Alarm.cpp
+++ b/src/Alarm.cpp
@@ -1666,7 +1666,7 @@ void Alarm::load(Tango::DevString argin)
 			try {
 				i->second.dp_n = new Tango::DeviceProxy(i->second.cmd_dp_n);
 				i->second.dp_n->ping();
-				Tango::CommandInfo info = i->second.dp_n->command_query(i->second.cmd_action_a);
+				Tango::CommandInfo info = i->second.dp_n->command_query(i->second.cmd_action_n);
 				if(info.in_type != Tango::DEV_STRING)
 				{
 					ostringstream err;
diff --git a/src/alarm_table.cpp b/src/alarm_table.cpp
index ad3ddc6..9042d87 100644
--- a/src/alarm_table.cpp
+++ b/src/alarm_table.cpp
@@ -529,8 +529,8 @@ bool alarm_table::timer_update()
 	vlock->readerIn();
 	for(alarm_container_t::iterator i = v_alarm.begin(); i != v_alarm.end(); i++)
 	{		
-		bool status_on_delay;
-		bool status_off_delay;
+		bool status_on_delay=false;
+		bool status_off_delay=false;
 		if(i->second.on_delay == 0 && i->second.off_delay == 0 && !i->second.shelved && i->second.silenced <=0)
 			continue;	//if not enabled on or off delay, nothing to do in timer
 		if(i->second.on_delay > 0)		//if enabled on delay
@@ -623,9 +623,9 @@ bool alarm_table::timer_update()
 					cmdloop->list.push_back(arg);
 				}
 			}
-			else if(status_off_delay)
+			else if(status_off_delay && (i->second.stat == S_ALARM))
 			{
-				if(i->second.dp_a && ((ts.tv_sec - startup_complete.tv_sec) > 10))
+				if(i->second.dp_n && ((ts.tv_sec - startup_complete.tv_sec) > 10))
 				{
 					/*try {
 						long call_id;
@@ -670,6 +670,12 @@ bool alarm_table::timer_update()
 				}
 			}
 
+			if((int)(status_on_delay)) {
+				i->second.off_counter = 0;
+			} else if(status_off_delay) {
+				i->second.on_counter = 0;
+			}
+
 			if(!i->second.enabled)
 				*(i->second.attr_value) = _OOSRV;
 			else if(i->second.shelved && i->second.silenced > 0)
diff --git a/src/cmd_thread.cpp b/src/cmd_thread.cpp
index e73ca5b..2e0a09a 100644
--- a/src/cmd_thread.cpp
+++ b/src/cmd_thread.cpp
@@ -206,7 +206,7 @@ void cmd_list::push_back(cmd_t& cmd)
 {
 	this->lock();
 
-	//cout << "event_list::push_back: " << e.name << " value=" << e.value[0] << endl;
+	//cout << "cmd_list::push_back: cmd_id=" << cmd.cmd_id << " call_id=" << cmd.call_id << endl;
 	try{
 		l_cmd.push_back(cmd);		
 		empty.signal();
@@ -222,7 +222,7 @@ void cmd_list::push_back(cmd_t& cmd)
 	{
 		ostringstream err;
 		err << "exception  signaling omni_condition: '" << ex.errors[0].desc << "'" << ends;
-		//WARN_STREAM << "event_list::push_back(): " << err.str() << endl;	
+		//WARN_STREAM << "cmd_list::push_back(): " << err.str() << endl;
 		printf("cmd_list::push_back: %s", err.str().c_str());
 		Tango::Except::print_exception(ex);	
 	}		
@@ -273,7 +273,7 @@ const cmd_t cmd_list::pop_front(void)
 	/*const*/ cmd_t cmd;
 
 	cmd = *(l_cmd.begin());
-	//cout << "event_list::pop_front: " << e.name << " value=" << e.value[0] << endl; 
+	//cout << "cmd_list::pop_front: " << e.name << " value=" << e.value[0] << endl;
 	l_cmd.pop_front();
 
 	this->unlock();
-- 
GitLab