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