TDataType din = new TDataType();
TAccess access = new TAccess(TAccess.CA_ALARM + TAccess.CA_READ);
TAlarmWatchEntry awe = null;
TAlarmDefinition adef = null;
TAlarm alm = null;
TDevice dev = null;
int cc = 0, cnt = 0, siz = 0, sev = 0, devNr, code = 0, asys = 0;
String tag = null;
float fvals[] = null;
int ivals[] = null;
byte[] abytes = null;
synchronized (gAlarmWatchList)
{
TEquipmentModuleFactory f = getEquipmentModuleFactory();
f.setCurrentContractEntry(f.awtcon);
int awlength = gAlarmWatchList.size();
for (int i=0; i<awlength; i++)
{
awe = (TAlarmWatchEntry)gAlarmWatchList.get(i);
int chk = awe.checkNormal();
if (chk != 0)
{
ivals = new int[awe.getSiz()];
dout = new TDataType(ivals);
cc = callProperty(awe.getPrp(),awe.getDev(),dout,din,access);
}
else
{
fvals = new float[awe.getSiz()];
dout = new TDataType(fvals);
cc = callProperty(awe.getPrp(),awe.getDev(),dout,din,access);
}
if (cc != 0) continue;
boolean hasAlarm = false;
devNr = deviceList.getDeviceNumber(awe.getDev());
cnt = 0; siz = awe.getSiz();
for (int j=0; j<siz; j++)
{
if (awe.getAtyp() == TArrayType.AT_CHANNEL) devNr = j;
if (awe.getAtyp() != TArrayType.AT_WAVEFORM && siz == deviceList.getNumberOfDevices())
devNr = j; /* assume array of devices */
dev = deviceList.getDevice(devNr);
hasAlarm = false;
if (ivals != null)
{
int nval = awe.getNormal();
if ((chk == 1 && nval != (awe.getMask() & ivals[j])) ||
(chk == -1 && nval == (awe.getMask() & ivals[j])) )
{
if (TEquipmentModuleFactory.debugLevel > 1)
DbgLog.log("checkAlarmsInWatchTable", awe.getPrp()+" "+awe.getDev()+
" alarm state ! : "+(awe.getMask() & ivals[j])+" vs "+nval);
code = awe.getCode();
if (code == 0) code = TErrorList.invalid_data;
sev = awe.getSev();
asys = awe.getAsys();
hasAlarm = true;
}
abytes = Swap.LongToBytes(ivals[j]);
}
else if (fvals != null)
{
if (fvals[j] > awe.getHi())
{
if (TEquipmentModuleFactory.debugLevel > 1)
DbgLog.log("checkAlarmsInWatchTable", awe.getPrp()+" "+awe.getDev()+
" alarm state ! : "+fvals[j]+" > "+awe.getHi());
code = awe.getCode();
if (code == 0) code = awe.getCodeHigh();
if (code == 0) code = TErrorList.value_too_high;
sev = awe.getSev();
asys = awe.getAsys();
tag = awe.getTagHigh();
hasAlarm = true;
}
else if (fvals[j] > awe.getHiwarn())
{
if (TEquipmentModuleFactory.debugLevel > 1)
DbgLog.log("checkAlarmsInWatchTable", awe.getPrp()+" "+awe.getDev()+
" warn state ! : "+fvals[j]+" > "+awe.getHiwarn());
code = awe.getCode();
if (code == 0) code = awe.getCodeHigh();
if (code == 0) code = TErrorList.warn_too_high;
sev = awe.getSev()-2;
asys = awe.getAsys();
tag = awe.getTagHigh();
hasAlarm = true;
}
else if (fvals[j] < awe.getLo())
{
if (TEquipmentModuleFactory.debugLevel > 1)
DbgLog.log("checkAlarmsInWatchTable", awe.getPrp()+" "+awe.getDev()+
" alarm state ! : "+fvals[j]+" < "+awe.getLo());
code = awe.getCode();
if (code == 0) code = awe.getCodeLow();
if (code == 0) code = TErrorList.value_too_low;
sev = awe.getSev();
asys = awe.getAsys();
tag = awe.getTagLow();
hasAlarm = true;
}
else if (fvals[j] < awe.getLowarn())
{
if (TEquipmentModuleFactory.debugLevel > 1)
DbgLog.log("checkAlarmsInWatchTable", awe.getPrp()+" "+awe.getDev()+
" warn state ! : "+fvals[j]+" < "+awe.getLowarn());
code = awe.getCode();
if (code == 0) code = awe.getCodeLow();
if (code == 0) code = TErrorList.warn_too_low;
sev = awe.getSev()-2;
asys = awe.getAsys();
tag = awe.getTagLow();
hasAlarm = true;
}
abytes = Swap.Float(fvals[j]);
}
if (!hasAlarm)
{ // run through clearAlarm()
dev.clearAlarm(TErrorList.invalid_data,awe);
dev.clearAlarm(TErrorList.value_too_high,awe);
dev.clearAlarm(TErrorList.value_too_low,awe);
dev.clearAlarm(TErrorList.warn_too_high,awe);
dev.clearAlarm(TErrorList.warn_too_low,awe);
if (awe.getCode() > 0) dev.clearAlarm(awe.getCode(),awe);
if (awe.getCodeHigh() > 0) dev.clearAlarm(awe.getCodeHigh(),awe);
if (awe.getCodeLow() > 0) dev.clearAlarm(awe.getCodeLow(),awe);
continue;
}
if (code == 0) continue;
if (!awe.isPastFilter()) continue;
cnt = awe.getCnt() + 1;
awe.setCnt(cnt);
if (cnt > awe.getCntThreshold() && dev != null)
{
alm = dev.setAlarm(code,abytes,awe);
if (alm != null)
{
adef = alm.getAlmDef();
if (sev != 0) adef.setAlarmSeverity(sev);
if (asys != 0) adef.setAlarmSystem(asys);