001package jmri.jmrix.powerline.dmx512;
002
003import jmri.jmrix.powerline.SerialMessage;
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 Ken Cameron Copyright (C) 2023
019 */
020public class SpecificMessage extends SerialMessage {
021    // is this logically an abstract class?
022
023    public SpecificMessage(int l) {
024        super(l);
025        setResponseLength(0);  // only polls require a response
026        setBinary(true);
027        setTimeout(5000);
028    }
029
030    /**
031     * This ctor interprets the String as the exact sequence to send,
032     * byte-for-byte.
033     *
034     * @param m message
035     * @param l response length in bytes
036     */
037    public SpecificMessage(String m, int l) {
038        super(m, l);
039    }
040
041    boolean interlocked = false;
042
043    @Override
044    public void setInterlocked(boolean v) {
045        interlocked = v;
046    }
047
048    @Override
049    public boolean getInterlocked() {
050        return interlocked;
051    }
052
053    @SuppressWarnings("fallthrough")
054    @Override
055    public String toMonitorString() {
056        StringBuilder text = new StringBuilder();
057        return text + "\n";
058    }
059
060    /**
061     * This ctor interprets the byte array as a sequence of characters to send.
062     *
063     * @param a Array of bytes to send
064     * @param l lenght of expected reply
065     */
066    public SpecificMessage(byte[] a, int l) {
067        super(a, l);
068    }
069
070    int responseLength = -1;  // -1 is an invalid value, indicating it hasn't been set
071
072    @Override
073    public void setResponseLength(int l) {
074        responseLength = l;
075    }
076
077    @Override
078    public int getResponseLength() {
079        return responseLength;
080    }
081
082}
083
084