001package jmri.jmrix.rfid; 002 003/** 004 * Contains the data payload of a serial packet. 005 * <p> 006 * The transmission protocol can come in one of several forms: 007 * <ul> 008 * <li>If the interlocked parameter is false (default), the packet is just sent. 009 * If the response length is not zero, a reply of that length is expected. 010 * <li>If the interlocked parameter is true, the transmission will require a CRC 011 * interlock, which will be automatically added. (Design note: this is done to 012 * make sure that the messages remain atomic) 013 * </ul> 014 * 015 * @author Bob Jacobsen Copyright (C) 2001,2003, 2006, 2007, 2008 016 * @author Matthew Harris Copyright (C) 2011 017 * @since 2.11.4 018 */ 019abstract public class RfidMessage extends jmri.jmrix.AbstractMRMessage { 020 // is this logically an abstract class? 021 022 /** 023 * Suppress the default ctor, as the length must always be specified 024 */ 025 protected RfidMessage() { 026 } 027 028 public RfidMessage(int l) { 029 super(l); 030 setResponseLength(0); // only polls require a response 031 setBinary(true); 032 setTimeout(5000); 033 } 034 035 /** 036 * This ctor interprets the String as the exact sequence to send, 037 * byte-for-byte. 038 * 039 * @param m String to send 040 * @param l length of expected response 041 */ 042 public RfidMessage(String m, int l) { 043 super(m); 044 setResponseLength(l); 045 setBinary(true); 046 setTimeout(5000); 047 } 048 049 boolean interlocked = false; 050 051 public void setInterlocked(boolean v) { 052 interlocked = v; 053 } 054 055 public boolean getInterlocked() { 056 return interlocked; 057 } 058 059 /** 060 * This ctor interprets the byte array as a sequence of characters to send. 061 * 062 * @param a Array of bytes to send 063 * @param l length of expected response 064 */ 065 public RfidMessage(byte[] a, int l) { 066 super(String.valueOf(a)); 067 setResponseLength(l); 068 setBinary(true); 069 setTimeout(5000); 070 } 071 072 int responseLength = -1; // -1 is an invalid value, indicating it hasn't been set 073 074 /** 075 * Sets the length of an expected response 076 * 077 * @param l length of expected response 078 */ 079 public final void setResponseLength(int l) { 080 responseLength = l; 081 } 082 083 /** 084 * Returns the length of an expected response 085 * 086 * @return length of expected response 087 */ 088 public int getResponseLength() { 089 return responseLength; 090 } 091 092}