001package jmri.jmrix.powerline.dmx512;
002
003import jmri.jmrix.powerline.SerialMessage;
004import jmri.util.StringUtil;
005
006/**
007 * Contains the data payload of a serial packet.
008 * <p>
009 * The transmission protocol can come in one of several forms:
010 * <ul>
011 * <li>If the interlocked parameter is false (default), the packet is just sent.
012 * If the response length is not zero, a reply of that length is expected.
013 * <li>If the interlocked parameter is true, the transmission will require a CRC
014 * interlock, which will be automatically added. (Design note: this is done to
015 * make sure that the messages remain atomic)
016 * </ul>
017 *
018 * @author Bob Jacobsen Copyright (C) 2001,2003, 2006, 2007, 2008
019 * @author Ken Cameron Copyright (C) 2023
020 */
021public class SpecificMessage extends SerialMessage {
022    // is this logically an abstract class?
023
024    public SpecificMessage(int l) {
025        super(l);
026        setResponseLength(0);  // only polls require a response
027        setBinary(true);
028        setTimeout(5000);
029    }
030
031    /**
032     * This ctor interprets the String as the exact sequence to send,
033     * byte-for-byte.
034     *
035     * @param m message
036     * @param l response length in bytes
037     */
038    public SpecificMessage(String m, int l) {
039        super(m, l);
040    }
041
042    boolean interlocked = false;
043
044    @Override
045    public void setInterlocked(boolean v) {
046        interlocked = v;
047    }
048
049    @Override
050    public boolean getInterlocked() {
051        return interlocked;
052    }
053
054    @SuppressWarnings("fallthrough")
055    @Override
056    public String toMonitorString() {
057        StringBuilder text = new StringBuilder();
058        return text + "\n";
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 reply
066     */
067    @Deprecated( since="5.13.5", forRemoval=true)
068    public SpecificMessage(byte[] a, int l) {
069        super(StringUtil.hexStringFromBytes(a).replaceAll("\\s", ""), l);
070    }
071
072    int responseLength = -1;  // -1 is an invalid value, indicating it hasn't been set
073
074    @Override
075    public void setResponseLength(int l) {
076        responseLength = l;
077    }
078
079    @Override
080    public int getResponseLength() {
081        return responseLength;
082    }
083
084}
085
086