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 String toString() {
030        StringBuilder s = new StringBuilder();
031        for (int i = 0; i < getNumDataElements(); i++) {
032            if (i != 0) {
033                s.append(" ");
034            }
035            if (getElement(i) < 16) {
036                s.append("0");
037            }
038            s.append(Integer.toHexString(getElement(i) & 0xFF));
039        }
040        return s.toString();
041    }
042
043    // recognize format
044    public boolean isRcv() {
045        return getElement(1) == 0x52;
046    }
047
048    public int getUA() {
049        return getElement(0) - 65;
050    }
051    
052    // CMRI-E  Extended Protocol Messages  c2
053    public boolean isEOT()     { return (getElement(1)==0x45); }   // 'E'
054    public boolean isQUERY()   { return (getElement(1)==0x51); }   // 'Q'
055    public boolean isDGREAD()  { return (getElement(1)==0x44); }   // 'D'
056    public boolean isDGWRITE() { return (getElement(1)==0x57); }   // 'W'
057    public boolean isDGACK()   { return (getElement(1)==0x41) &&   // 'A'
058                                        (getElement(2)==0x06); }   //  ACK
059    public boolean isDGNAK()   { return (getElement(1)==0x41) &&   // 'A'
060                                        (getElement(2)==0x15); }   //  NAK
061
062    @Override
063    protected int skipPrefix(int index) {
064        // doesn't have to do anything
065        return index;
066    }
067
068}