001package jmri.jmrix.ieee802154.xbee;
002
003import com.digi.xbee.api.packet.UnknownXBeePacket;
004import com.digi.xbee.api.packet.XBeePacket;
005
006/**
007 * Contains the data payload of a serial reply packet. Note that it's _only_ the
008 * payload.
009 *
010 * @author Bob Jacobsen Copyright (C) 2002, 2006, 2007, 2008 Converted to
011 * multiple connection
012 * @author kcameron Copyright (C) 2011 Modified for IEEE 802.15.4 connection
013 * @author Paul Bender Copyright (C) 2013
014 */
015public class XBeeReply extends jmri.jmrix.ieee802154.IEEE802154Reply {
016
017    XBeePacket xbresponse = null;
018
019    // create a new one
020    public XBeeReply() {
021        super();
022        setBinary(true);
023    }
024
025    public XBeeReply(String s) {
026        super(s);
027        setBinary(true);
028        byte[] ba = jmri.util.StringUtil.bytesFromHexString(s);
029        for(int i=0;i<ba.length;i++) {
030           _dataChars[i] = ba[i];
031        }
032        _nDataChars=ba.length;
033        xbresponse = UnknownXBeePacket.createPacket(ba);
034    }
035
036    public XBeeReply(XBeeReply l) {
037        super(l);
038        xbresponse = l.xbresponse;
039        byte[] data = xbresponse.getPacketData();
040        for(int i=0;i<data.length;i++) {
041           _dataChars[i] = data[i];
042        }
043        _nDataChars=data.length;
044        setBinary(true);
045    }
046
047    public XBeeReply(XBeePacket xbr) {
048        super();
049        xbresponse = xbr;
050        byte[] data = xbr.getPacketData();
051        for(int i=0;i<data.length;i++) {
052           _dataChars[i] = data[i];
053        }
054        _nDataChars=data.length;
055        setBinary(true);
056    }
057
058    @Override
059    public String toMonitorString() {
060        return xbresponse.toPrettyString();
061    }
062
063    @Override
064    public String toString() {
065        return xbresponse.toString();
066    }
067
068    public XBeePacket getXBeeResponse() {
069        return xbresponse;
070    }
071
072    public void setXBeeResponse(XBeePacket xbr) {
073        xbresponse = xbr;
074    }
075
076}
077
078