/*
* Created on Aug 24, 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.io.ByteArrayOutputStream;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import de.desy.tine.definitions.TFormat;
import de.desy.tine.server.equipment.TEquipmentModule;
import de.desy.tine.stringUtils.StringToBytes;
import de.desy.tine.structUtils.TStructBase;
import de.desy.tine.structUtils.TStructDescription;
import de.desy.tine.structUtils.TStructRegistry;
public class TAlarmMessage5 extends TStructBase
{
public String deviceServer; // 16 chars
public String deviceName; // 16 chars
public String almTag; // 16 chars
public int almCode;
public int almTime;
public int almMask;
public byte[] almData = new byte[6]; // 6 bytes
public byte almDataFormat;
public byte almDataArraySize;
public byte almSeverity;
public byte almDescriptor;
public short almSystem;
public static final int sizeInBytes = 72;
ByteArrayOutputStream dBuffer = new ByteArrayOutputStream(sizeInBytes);
private static TStructDescription almStruct = null;
private void pushByteArray(byte[] barray)
{
for (int i=0; i<6; i++) almData[i] = 0;
if (barray != null) for (int i=0; i<barray.length; i++) almData[i] = barray[i];
}
public static void initStructDescription()
{
if (almStruct != null) return;
almStruct = new TStructDescription("AMS");
almStruct.beginDefinition();
almStruct.addField(TFormat.CF_TEXT, 16);
almStruct.addField(TFormat.CF_TEXT, 16);
almStruct.addField(TFormat.CF_TEXT, 16);
almStruct.addField(TFormat.CF_LONG, 1);
almStruct.addField(TFormat.CF_LONG, 1);
almStruct.addField(TFormat.CF_LONG, 1);
almStruct.addField(TFormat.CF_BYTE, 6);
almStruct.addField(4,TFormat.CF_BYTE, 1);
almStruct.addField(TFormat.CF_SHORT, 1);
almStruct.setArraySize(100);
almStruct.endDefinition();
TStructRegistry.add(almStruct);
}
public TAlarmMessage5(TEquipmentModule eqm, String dev,TAlarm alm)
{
initStructDescription();
deviceServer = eqm.getExportName();
deviceName = dev == null ? "" : dev;
TAlarmDefinition adef = alm.getAlmDef();
if (adef != null)
{
almTag = adef.getAlarmTag();
almMask = adef.getAlarmMask();
almDataFormat = (byte)adef.getAlarmDataFormat();
almDataArraySize = (byte)adef.getAlarmDataArraySize();
almSeverity = (byte)adef.getAlarmSeverity();
almSystem = (short)adef.getAlarmSystem();
}
almCode = alm.getCode();
almTime = alm.getTimeStamp();
pushByteArray(alm.getData());
almDescriptor = alm.getDescriptor();
}
public void writeData(DataOutput dout) throws IOException
{
dout.write(StringToBytes.stringToFixedBytes(deviceServer, 16));
dout.write(StringToBytes.stringToFixedBytes(deviceName, 16));
dout.write(StringToBytes.stringToFixedBytes(almTag, 16));
dout.writeInt(almCode);
dout.writeInt(almTime);
dout.writeInt(almMask);
dout.write(almData);
dout.writeByte(almDataFormat);
dout.writeByte(almDataArraySize);
dout.writeByte(almSeverity);
dout.writeByte(almDescriptor);
dout.writeShort(almSystem);
}
public void readData(DataInput din) throws IOException
{
deviceServer = StringToBytes.readFixedString(din, 16);
deviceName = StringToBytes.readFixedString(din, 16);
almTag = StringToBytes.readFixedString(din, 16);
almCode = din.readInt();
almTime = din.readInt();
almMask = din.readInt();
din.readFully(almData,0,6);
almDataFormat = din.readByte();
almDataArraySize = din.readByte();
almSeverity = din.readByte();
almDescriptor = din.readByte();
almSystem = din.readShort();
}
}