Skip to content
Snippets Groups Projects
Commit 3eaefa8a authored by Antonin Hottois's avatar Antonin Hottois Committed by Antonin Hottois
Browse files

1.0.2: Change initialisation process, removed LastStates property

parent aaba25c2
Branches
Tags
No related merge requests found
.settings/ .settings/
target/ target/
.project .project
Antonin/
*.log
deserver/
\ No newline at end of file
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<groupId>fr.soleil.device</groupId> <groupId>fr.soleil.device</groupId>
<artifactId>MessageTrigger</artifactId> <artifactId>MessageTrigger</artifactId>
<version>1.0.1-SNAPSHOT</version> <version>1.0.2-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<!-- <!--
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
<dependency> <dependency>
<groupId>org.tango-controls</groupId> <groupId>org.tango-controls</groupId>
<artifactId>JTango</artifactId> <artifactId>JTango</artifactId>
<version>10.0.0</version> <version>9.5.18</version>
<type>pom</type> <type>pom</type>
</dependency> </dependency>
<dependency> <dependency>
...@@ -97,7 +97,7 @@ ...@@ -97,7 +97,7 @@
</descriptorRefs> </descriptorRefs>
<archive> <archive>
<manifest> <manifest>
<mainClass>fr.soleil.device.MessageTrigger.MessageTrigger</mainClass> <mainClass>fr.soleil.device.messagetrigger.MessageTrigger</mainClass>
</manifest> </manifest>
</archive> </archive>
</configuration> </configuration>
......
package fr.soleil.device.MessageTrigger; package fr.soleil.device.messagetrigger;
import org.tango.utils.DevFailedUtils; import org.tango.utils.DevFailedUtils;
...@@ -11,7 +11,6 @@ public class AttributeParser{ ...@@ -11,7 +11,6 @@ public class AttributeParser{
final private TangoAttribute m_attribute; final private TangoAttribute m_attribute;
final private String m_true_message; final private String m_true_message;
final private String m_false_message; final private String m_false_message;
final private boolean m_is_false_message;
private boolean m_previous_state; private boolean m_previous_state;
...@@ -19,32 +18,16 @@ public class AttributeParser{ ...@@ -19,32 +18,16 @@ public class AttributeParser{
public AttributeParser(String str, TangoDevice tango_parser) throws DevFailed public AttributeParser(String str, TangoDevice tango_parser) throws DevFailed
{ {
String[] tokens = str.split(";"); String[] tokens = str.split(";");
if(tokens.length == 2)
{ if(tokens.length != 3)
m_is_false_message = false;
m_false_message ="";
}
else if(tokens.length == 3)
{
if(tokens[2].equalsIgnoreCase("NULL"))
{
m_is_false_message = false;
m_false_message ="";
}
else
{
m_is_false_message = true;
m_false_message = tokens[2];
}
}
else
{ {
throw DevFailedUtils.newDevFailed("Message is not formated properly: it should be Attribute1;MessageIfTrue;(MessageIfFalse)"); throw DevFailedUtils.newDevFailed("Message is not formated properly: it should be Attribute1;MessageIfTrue;(MessageIfFalse)");
} }
m_attribute = tango_parser.getTangoAttribute(tokens[0]); m_attribute = new TangoAttribute(tokens[0]);
m_true_message = tokens[1]; m_true_message = tokens[1];
m_previous_state = false; m_false_message = tokens[2];
m_previous_state = m_attribute.read(boolean.class);
} }
public String check_attribute() throws DevFailed public String check_attribute() throws DevFailed
...@@ -53,11 +36,11 @@ public class AttributeParser{ ...@@ -53,11 +36,11 @@ public class AttributeParser{
if(result != m_previous_state) if(result != m_previous_state)
{ {
m_previous_state = result; m_previous_state = result;
if(result) if(result && !m_true_message.contentEquals("") && !m_true_message.equalsIgnoreCase("NULL"))
{ {
return m_true_message; return m_true_message;
} }
else if(m_is_false_message) if(!result && !m_false_message.contentEquals("") && !m_false_message.equalsIgnoreCase("NULL"))
{ {
return m_false_message; return m_false_message;
} }
......
package fr.soleil.device.MessageTrigger; package fr.soleil.device.messagetrigger;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
...@@ -7,22 +7,20 @@ public class MessageListArray { ...@@ -7,22 +7,20 @@ public class MessageListArray {
private String[] m_message_list; private String[] m_message_list;
private int m_index; private int m_index;
final private int m_nb_messages; final private int m_nb_messages;
private final Object m_lock;
public MessageListArray(String[] message_list, int nb_messages, Object lock) public MessageListArray(String[] message_list, int nb_messages)
{ {
m_message_list = message_list; m_message_list = message_list;
Arrays.fill(m_message_list, ""); Arrays.fill(m_message_list, "");
m_nb_messages = nb_messages; m_nb_messages = nb_messages;
m_index = 0; m_index = 0;
m_lock = lock;
} }
public void push_message(String message) public void push_message(String message)
{ {
Date date=new Date(); Date date=new Date();
synchronized(m_lock) synchronized(m_message_list)
{ {
if(m_index == m_nb_messages) if(m_index == m_nb_messages)
{ {
...@@ -40,7 +38,7 @@ public class MessageListArray { ...@@ -40,7 +38,7 @@ public class MessageListArray {
public void clear_messages() public void clear_messages()
{ {
synchronized(m_lock) synchronized(m_message_list)
{ {
for(int i = 0; i < m_nb_messages-1; i++) for(int i = 0; i < m_nb_messages-1; i++)
{ {
......
package fr.soleil.device.MessageTrigger; package fr.soleil.device.messagetrigger;
import java.util.Vector; import java.util.Vector;
...@@ -38,9 +38,7 @@ public class MessageTrigger implements StateUpdates{ ...@@ -38,9 +38,7 @@ public class MessageTrigger implements StateUpdates{
private TangoDevice m_text_talker; private TangoDevice m_text_talker;
private Vector<AttributeParser> m_monitored_attributes_list; private Vector<AttributeParser> m_monitored_attributes_list;
private Object m_message_lock = new Object(); private static final int MSG_LOG_SIZE = 100;
private static final int MSG_LOG_SIZE = 50;
...@@ -55,28 +53,28 @@ public class MessageTrigger implements StateUpdates{ ...@@ -55,28 +53,28 @@ public class MessageTrigger implements StateUpdates{
// PROPERTIES // PROPERTIES
//----------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------
@DeviceProperty (defaultValue = {"Attribute1;MessageIfTrue;(MessageIfFalse)"}, description = "List of the attributes and messages to be sent") @DeviceProperty (defaultValue = {"Attribute1;MessageIfTrue;(MessageIfFalse)"}, description = "List of the attributes and messages to be sent.\nFor example: Attribute1;(MessageIfTrue);(MessageIfFalse)")
private String[] MessageList; private String[] MessageList;
public void setMessageList(String[] MessageList) { public void setMessageList(String[] MessageList) {
this.MessageList = MessageList; this.MessageList = MessageList;
} }
@DeviceProperty (defaultValue = "N/A", description = "Name of the Tango Parser Proxy in the database") @DeviceProperty (description = "Name/Path of the Tango Parser Proxy in the database.\nFor example: test/test/parser", isMandatory = true)
private String TangoParserProxyName; private String TangoParserProxyName;
public void setTangoParserProxyName(String TangoParserProxyName) { public void setTangoParserProxyName(String TangoParserProxyName) {
this.TangoParserProxyName = TangoParserProxyName; this.TangoParserProxyName = TangoParserProxyName;
} }
@DeviceProperty (defaultValue = "N/A", description = "Name of the Text Talker Proxy in the database") @DeviceProperty (description = "Name/Path of the Text Talker Proxy in the database.\nFor example: test/test/talker", isMandatory = true)
private String TextTalkerProxyName; private String TextTalkerProxyName;
public void setTextTalkerProxyName(String TextTalkerProxyName) { public void setTextTalkerProxyName(String TextTalkerProxyName) {
this.TextTalkerProxyName = TextTalkerProxyName; this.TextTalkerProxyName = TextTalkerProxyName;
} }
@DeviceProperty (defaultValue = "1000", description = "Polling period in seconds.") @DeviceProperty (defaultValue = "1000", description = "Polling period in milliseconds.")
private int PollingPeriod; private int PollingPeriod;
public void setPollingPeriod(int PollingPeriod) { public void setPollingPeriod(int PollingPeriod) {
...@@ -147,7 +145,7 @@ public class MessageTrigger implements StateUpdates{ ...@@ -147,7 +145,7 @@ public class MessageTrigger implements StateUpdates{
sentMessageList = new String[MSG_LOG_SIZE]; sentMessageList = new String[MSG_LOG_SIZE];
m_message_array = new MessageListArray( sentMessageList, MSG_LOG_SIZE , m_message_lock); m_message_array = new MessageListArray( sentMessageList, MSG_LOG_SIZE);
if(!(PollingPeriod>10)) if(!(PollingPeriod>10))
{ {
...@@ -190,7 +188,7 @@ public class MessageTrigger implements StateUpdates{ ...@@ -190,7 +188,7 @@ public class MessageTrigger implements StateUpdates{
return; return;
} }
setState(DeviceState.STANDBY); setState(DeviceState.OFF);
setStatus("Ready! Standing by..."); setStatus("Ready! Standing by...");
} }
...@@ -211,7 +209,7 @@ public class MessageTrigger implements StateUpdates{ ...@@ -211,7 +209,7 @@ public class MessageTrigger implements StateUpdates{
public String[] getSentMessageList() public String[] getSentMessageList()
{ {
logger.debug("getSentMessageList"); logger.debug("getSentMessageList");
synchronized(m_message_lock) synchronized(sentMessageList)
{ {
return sentMessageList; return sentMessageList;
} }
...@@ -222,21 +220,19 @@ public class MessageTrigger implements StateUpdates{ ...@@ -222,21 +220,19 @@ public class MessageTrigger implements StateUpdates{
//----------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------
@Command @Command
@StateMachine(deniedStates = { DeviceState.FAULT, DeviceState.ALARM, DeviceState.STANDBY, DeviceState.INIT}) @StateMachine(deniedStates = { DeviceState.FAULT, DeviceState.ALARM, DeviceState.OFF, DeviceState.INIT}, endState = DeviceState.OFF)
public void Stop() public void Stop()
{ {
if(m_trigger_task!=null) m_trigger_task.stop(); if(m_trigger_task!=null) m_trigger_task.stop();
setState(DeviceState.STANDBY);
setStatus("Trigger service stopped!\nDevice standing by..."); setStatus("Trigger service stopped!\nDevice standing by...");
} }
@Command @Command
@StateMachine(deniedStates = { DeviceState.FAULT, DeviceState.ALARM, DeviceState.RUNNING, DeviceState.INIT}) @StateMachine(deniedStates = { DeviceState.FAULT, DeviceState.ALARM, DeviceState.ON, DeviceState.INIT}, endState = DeviceState.ON)
public void Start() public void Start()
{ {
m_trigger_task = new TriggerPulserTask( PollingPeriod, m_monitored_attributes_list, m_tango_parser, m_text_talker, m_message_array, this ); m_trigger_task = new TriggerPulserTask( PollingPeriod, m_monitored_attributes_list, m_tango_parser, m_text_talker, m_message_array, this );
setState(DeviceState.RUNNING); setStatus("Trigger service started!\nDevice ON...");
setStatus("Trigger service started!\nDevice running...");
} }
@Command @Command
...@@ -246,21 +242,15 @@ public class MessageTrigger implements StateUpdates{ ...@@ -246,21 +242,15 @@ public class MessageTrigger implements StateUpdates{
m_message_array.clear_messages(); m_message_array.clear_messages();
} }
@Command
//@StateMachine(deniedStates = { DeviceState.FAULT, DeviceState.ALARM})
public void DefferedInit()
{
}
@Override @Override
public void send_error(DevFailed e, String desc) { public void send_error(DevFailed e, String desc) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
if(m_trigger_task!=null) m_trigger_task.stop(); if(m_trigger_task!=null) m_trigger_task.stop();
logger.error(desc,e); logger.error(desc,e);
logger.error(DevFailedUtils.toString(e)); //logger.error(DevFailedUtils.toString(e));
setState(DeviceState.FAULT); setState(DeviceState.FAULT);
setStatus(desc); setStatus(desc+"\n"+DevFailedUtils.toString(e));
} }
@Override @Override
......
package fr.soleil.device.MessageTrigger; package fr.soleil.device.messagetrigger;
import fr.esrf.Tango.DevFailed; import fr.esrf.Tango.DevFailed;
......
package fr.soleil.device.MessageTrigger; package fr.soleil.device.messagetrigger;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
......
...@@ -3,10 +3,11 @@ package fr.soleil.device.MessageTrigger; ...@@ -3,10 +3,11 @@ package fr.soleil.device.MessageTrigger;
import static org.hamcrest.core.Is.is; import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import fr.soleil.device.MessageTrigger.MessageTrigger;
import org.junit.Test; import org.junit.Test;
import org.tango.DeviceState; import org.tango.DeviceState;
import fr.soleil.device.messagetrigger.MessageTrigger;
public class MessageTriggerTest { public class MessageTriggerTest {
// @Test // @Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment