001package jmri.jmrix.cmri.serial; 002 003 004/** 005 * Contains the data payload of a CMRI serial reply packet. Note that _only_ the 006 * payload, not the header or trailer, nor the padding DLE characters are 007 * included. But it does include addressing characters, etc. 008 * 009 * @author Bob Jacobsen Copyright (C) 2002 010 * @author Chuck Catania Copyright (C) 2014, 2015, 2016 CMRInet changes 011 012 */ 013public class SerialReply extends jmri.jmrix.AbstractMRReply { 014 015 // create a new one 016 public SerialReply() { 017 super(); 018 } 019 020 public SerialReply(String s) { 021 super(s); 022 } 023 024 public SerialReply(SerialReply l) { 025 super(l); 026 } 027 028 @Override 029 public int maxSize() { 030 return 520; // large enough to include any reasonable SUSIC contents 031 } 032 033 @Override 034 public String toString() { 035 StringBuilder s = new StringBuilder(); 036 for (int i = 0; i < getNumDataElements(); i++) { 037 if (i != 0) { 038 s.append(" "); 039 } 040 if (getElement(i) < 16) { 041 s.append("0"); 042 } 043 s.append(Integer.toHexString(getElement(i) & 0xFF)); 044 } 045 return s.toString(); 046 } 047 048 // recognize format 049 public boolean isRcv() { 050 return getElement(1) == 0x52; 051 } 052 053 public int getUA() { 054 return getElement(0) - 65; 055 } 056 057 // CMRI-E Extended Protocol Messages c2 058 public boolean isEOT() { return (getElement(1)==0x45); } // 'E' 059 public boolean isQUERY() { return (getElement(1)==0x51); } // 'Q' 060 public boolean isDGREAD() { return (getElement(1)==0x44); } // 'D' 061 public boolean isDGWRITE() { return (getElement(1)==0x57); } // 'W' 062 public boolean isDGACK() { return (getElement(1)==0x41) && // 'A' 063 (getElement(2)==0x06); } // ACK 064 public boolean isDGNAK() { return (getElement(1)==0x41) && // 'A' 065 (getElement(2)==0x15); } // NAK 066 067 @Override 068 protected int skipPrefix(int index) { 069 // doesn't have to do anything 070 return index; 071 } 072 073}