001package jmri.jmrix.ipocs.protocol.packets; 002 003import java.nio.ByteBuffer; 004 005import jmri.jmrix.ipocs.protocol.enums.RqAlarmState; 006 007/** 008 * An alarm packet that can be sent by any party when something goes wrong 009 * which is not covered by an Acknowledgement Packet (or one wasn't requested). 010 * 011 * @author Fredrik Elestedt Copyright (C) 2020 012 * @since 4.21.2 013 */ 014@org.openide.util.lookup.ServiceProvider(service = Packet.class) 015public class AlarmPacket extends Packet { 016 public final static byte IDENT = 16; 017 private short alarmCode; 018 private byte alarmLevel; 019 private RqAlarmState alarmState = null; 020 private int parameter1; 021 private int parameter2; 022 023 @Override 024 public byte getId() { 025 return IDENT; 026 } 027 028 @Override 029 protected void parseSpecific(ByteBuffer buffer) { 030 alarmCode = buffer.getShort(); 031 alarmLevel = buffer.get(); 032 alarmState = RqAlarmState.valueOf(buffer.get()); 033 parameter1 = buffer.getInt(); 034 parameter2 = buffer.getInt(); 035 } 036 037 @Override 038 protected byte[] serializeSpecific() { 039 ByteBuffer buffer = ByteBuffer.allocate(12); 040 buffer.putShort(alarmCode); 041 buffer.put(alarmLevel); 042 buffer.put(alarmState.value); 043 buffer.putInt(parameter1); 044 buffer.putInt(parameter2); 045 buffer.rewind(); 046 return buffer.array(); 047 } 048 049 public short getAlarmCode() { 050 return alarmCode; 051 } 052 053 public void setAlarmCode(short alarmCode) { 054 this.alarmCode = alarmCode; 055 } 056 057 public byte getAlarmLevel() { 058 return alarmLevel; 059 } 060 061 public void setAlarmLevel(byte alarmLevel) { 062 this.alarmLevel = alarmLevel; 063 } 064 065 public RqAlarmState getAlarmState() { 066 return alarmState; 067 } 068 069 public void setAlarmState(RqAlarmState alarmState) { 070 this.alarmState = alarmState; 071 } 072 073 public int getParameter1() { 074 return parameter1; 075 } 076 077 public void setParameter1(int parameter1) { 078 this.parameter1 = parameter1; 079 } 080 081 public int getParameter2() { 082 return parameter2; 083 } 084 085 public void setParameter2(int parameter2) { 086 this.parameter2 = parameter2; 087 } 088}