/*
* Created on Aug 31, 2005
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package de.desy.tine.server.alarms;
import java.util.Arrays;
import de.desy.tine.client.TFilterLink;
import de.desy.tine.definitions.TStrings;
import de.desy.tine.server.equipment.TEquipmentModule;
import de.desy.tine.server.equipment.TEquipmentModuleFactory;
import de.desy.tine.server.logger.TFecLog;
import de.desy.tine.structUtils.TTaggedStructure;
public class TAlarmWatchEntry extends TTaggedStructure
{
private TEquipmentModule eqm;
private String devString = null;
private String prpString = null;
private String eqmString = null;
private char[] eqmName = new char[TStrings.EQM_NAME_SIZE];
private char[] dev = new char[TStrings.DEVICE_NAME_SIZE];
private char[] prp = new char[TStrings.PROPERTY_NAME_SIZE];
private int[] siz = new int[1];
private int[] fmt = new int[1];
private int[] atyp = new int[1]; /* array type */
private int[] asys = new int[1]; /* alarm system id */
private int[] sev = new int[1]; /* general highest severity */
private int[] hisev = new int[1]; /* high severity */
private int[] hiwarnsev = new int[1]; /* high warning severity */
private int[] losev = new int[1]; /* low severity */
private int[] lowarnsev = new int[1]; /* low warning severity */
private int[] chkNormal = new int[1]; /* TRUE => check vs normal; FALSE = check threshold */
private int[] mask = new int[1]; /* if fmt is an integer type */
private int[] normal = new int[1]; /* normal non-alarm state value (after mask) */
private int[] cnt = new int[1];
private int[] cntThreshold = new int[1]; /* set alarm when counter > threshold */
private float[] hi = new float[1]; /* high threshold */
private float[] lo = new float[1]; /* low threshold */
private float[] hiwarn = new float[1]; /* high warn threshold */
private float[] lowarn = new float[1]; /* low warn threshold */
private int code;
private int codeHigh;
private int codeLow;
private String tagHigh = null;
private String tagLow = null;
private TFilterLink filter = null;
public TFilterLink getFilter() { return filter; }
public void setFilter(TFilterLink filter)
{
String fstr = filter == null ? "none" : filter.toString();
TFecLog.log("TAlarmWatchEntry","set filter to "+fstr);
this.filter = filter;
}
public boolean isPastFilter()
{
if (filter != null && !filter.isActive())
{ // marked for removal;
filter = null;
}
return filter == null ? true : filter.isValid();
}
private void pushString(String s,char[] c)
{
if (s != null)
{
int len = s.length();
if (len > c.length) len = c.length;
s.getChars(0, len, c, 0);
}
}
private void initStructure()
{
addField(eqmName,"eqmName");
addField(dev,"device");
addField(prp,"property");
addField(siz,"size");
addField(fmt,"format");
addField(atyp,"arrayType");
addField(asys,"alarmSystem");
addField(sev,"genSeverity");
addField(hisev,"hiSeverity");
addField(hiwarnsev,"hiWarnSeverity");
addField(losev,"loSeverity");
addField(lowarnsev,"loWarnSeverity");
addField(chkNormal,"valueCheck");
addField(mask,"valueMask");
addField(normal,"valueNormal");
addField(cnt,"cnts");
addField(cntThreshold,"cntsThreshold");
addField(hi,"hiThreshold");
addField(lo,"loThreshold");
addField(hiwarn,"hiWarnThreshold");
addField(lowarn,"loWarnThreshold");
initDone();
}
public TAlarmWatchEntry()
{
super("AWSr4");
initStructure();
}
public TAlarmWatchEntry(TEquipmentModule equipmentModule,String devName,String devProperty,int size,
int format,int arrayType,int almSystem,int almSeverity,TAlarmWatchThreshold almThreshold)
{
this(equipmentModule,devName,devProperty,size,format,arrayType,almSystem,almSeverity,0,0,0,null,null,almThreshold);
}
public TAlarmWatchEntry(TEquipmentModule equipmentModule,String devName,String devProperty,int size,
int format,int arrayType,int almSystem,int almSeverity,int code,int codeHigh,int codeLow,TAlarmWatchThreshold almThreshold)
{
this(equipmentModule,devName,devProperty,size,format,arrayType,almSystem,almSeverity,code,codeHigh,codeLow,null,null,almThreshold);
}
public TAlarmWatchEntry(TEquipmentModule equipmentModule,String devName,String devProperty,int size,
int format,int arrayType,int almSystem,int almSeverity,int code,int codeHigh,int codeLow,String tagHigh,String tagLow,TAlarmWatchThreshold almThreshold)
{
super("AWSr4");
initStructure();
eqm = equipmentModule;
pushString(eqm.getLocalName(),eqmName);
pushString(devName,dev);
pushString(devProperty,prp);
siz[0] = size;
fmt[0] = format;
atyp[0] = arrayType;
asys[0] = almSystem;
sev[0] = almSeverity;
cnt[0] = 0;
cntThreshold[0] = almThreshold.getCnt();
hi[0] = almThreshold.getHi();
lo[0] = almThreshold.getLo();
hiwarn[0] = almThreshold.getHiwarn();
lowarn[0] = almThreshold.getLowarn();
mask[0] = almThreshold.getValueMask();
normal[0] = almThreshold.getValueNormal();
hisev[0] = sev[0];
hiwarnsev[0] = sev[0] > 2 ? sev[0] - 2 : sev[0];
losev[0] = sev[0];
lowarnsev[0] = sev[0] > 2 ? sev[0] - 2 : sev[0];
this.code = code;
this.codeHigh = codeHigh;
this.codeLow = codeLow;
this.tagHigh = tagHigh;
this.tagLow = tagLow;
if (mask[0] != 0)
{
chkNormal[0] = almThreshold.isNormalAlarm() ? -1 : 1;
}
}
public TAlarmWatchEntry(String eqmName,String devName,String devProperty,int size,
int format,int arrayType,int almSystem,int almSeverity,TAlarmWatchThreshold almThreshold)
{ // for queries and such ...
super("AWSr4");
initStructure();
eqm = null;
pushString(eqmName,this.eqmName);
pushString(devName,dev);
pushString(devProperty,prp);
siz[0] = size;
fmt[0] = format;
atyp[0] = arrayType;
asys[0] = almSystem;
sev[0] = almSeverity;
cnt[0] = 0;
cntThreshold[0] = almThreshold.getCnt();
hi[0] = almThreshold.getHi();
lo[0] = almThreshold.getLo();
hiwarn[0] = almThreshold.getHiwarn();
lowarn[0] = almThreshold.getLowarn();
mask[0] = almThreshold.getValueMask();
normal[0] = almThreshold.getValueNormal();
hisev[0] = sev[0];
hiwarnsev[0] = sev[0] > 2 ? sev[0] - 2 : sev[0];
losev[0] = sev[0];
lowarnsev[0] = sev[0] > 2 ? sev[0] - 2 : sev[0];
}
public void adjustFrom(TAlarmWatchEntry reference)
{
asys[0] = reference.asys[0];
sev[0] = reference.sev[0];
cntThreshold[0] = reference.cntThreshold[0];
hi[0] = reference.hi[0];
lo[0] = reference.lo[0];
hiwarn[0] = reference.hiwarn[0];
lowarn[0] = reference.lowarn[0];
mask[0] = reference.mask[0];
normal[0] = reference.normal[0];
if (mask[0] != 0)
{
chkNormal[0] = reference.chkNormal[0];
}
}
public void setEquipmentModule(String eqmName)
{
TEquipmentModule eq = TEquipmentModuleFactory.getInstance().getEquipmentModule(eqmName);
if (eq == null) return; // TODO: throw exception
setEquipmentModule(eq);
}
public void setEquipmentModule(TEquipmentModule eqm)
{
this.eqm = eqm;
pushString(eqm.getLocalName(),eqmName);
}
public int getAsys()
{
return asys[0];
}
public int getAtyp()
{
return atyp[0];
}
public int getCnt()
{
return cnt[0];
}
public void setCnt(int count) { cnt[0] = count; }
public int getCntThreshold()
{
return cntThreshold[0];
}
public String getDev()
{
if (devString == null) devString = new String(dev).trim();
return devString;
}
public TEquipmentModule getEqm()
{
return eqm;
}
public int getFmt()
{
return fmt[0];
}
public void setFmt(int format) { fmt[0] = format % 256; }
public float getHi()
{
return hi[0];
}
public float getHiwarn()
{
return hiwarn[0];
}
public float getLo()
{
return lo[0];
}
public float getLowarn()
{
return lowarn[0];
}
public String getPrp()
{
if (prpString == null) prpString = new String(prp).trim();
return prpString;
}
public String getEquipmentModule()
{
if (eqmString == null) eqmString = new String(eqmName).trim();
return eqmString;
}
public int getSev()
{
return sev[0];
}
public int getSiz()
{
return siz[0];
}
public void setSiz(int size) { siz[0] = size; }
public int checkNormal()
{
return chkNormal[0];
}
public int getMask()
{
return mask[0];
}
public int getNormal()
{
return normal[0];
}
public int hashCode()
{
final int PRIME = 31;
int result = 1;
result = PRIME * result + Arrays.hashCode(dev);
result = PRIME * result + Arrays.hashCode(eqmName);
result = PRIME * result + Arrays.hashCode(prp);
return result;
}
public boolean equals(Object obj)
{
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
final TAlarmWatchEntry other = (TAlarmWatchEntry) obj;
if (!Arrays.equals(dev, other.dev)) return false;
if (!Arrays.equals(eqmName, other.eqmName)) return false;
if (!Arrays.equals(prp, other.prp)) return false;
return true;
}
public int getCode()
{
return code;
}
public void setCode(int code)
{
this.code = code;
}
public int getCodeHigh()
{
return codeHigh;
}
public void setCodeHigh(int codeHigh)
{
this.codeHigh = codeHigh;
}
public int getCodeLow()
{
return codeLow;
}
public void setCodeLow(int codeLow)
{
this.codeLow = codeLow;
}
public String getTagHigh()
{
return tagHigh;
}
public void setTagHigh(String tag)
{
tagHigh = new String(tag);
}
public String getTagLow()
{
return tagLow;
}
public void setTagLow(String tag)
{
tagLow = new String(tag);
}
}