001package jmri.jmrix.loconet.sdf;
002
003/**
004 * Implement generic two-byte macros from the Digitrax sound definition language
005 *
006 * @author Bob Jacobsen Copyright (C) 2007
007 */
008public class TwoByteMacro extends SdfMacro {
009
010    public TwoByteMacro(int byte1, int byte2) {
011        bytes[0] = (byte) (byte1 & 0xFF);
012        bytes[1] = (byte) (byte2 & 0xFF);
013    }
014
015    @Override
016    public String name() {
017        return "Two Byte Macro"; // NOI18N
018    }
019
020    byte[] bytes = new byte[2];
021
022    @Override
023    public int length() {
024        return 2;
025    }
026
027    static public SdfMacro match(SdfBuffer buff) {
028        // always match
029        return new TwoByteMacro(buff.getAtIndexAndInc(), buff.getAtIndexAndInc());
030    }
031
032    /**
033     * Store into a buffer.
034     */
035    @Override
036    public void loadByteArray(SdfBuffer buffer) {
037        // data
038        buffer.setAtIndexAndInc(bytes[0]);
039        buffer.setAtIndexAndInc(bytes[1]);
040
041        // store children
042        super.loadByteArray(buffer);
043    }
044
045    @Override
046    public String toString() {
047        return name() + ' ' + jmri.util.StringUtil.hexStringFromBytes(bytes) + '\n';
048    }
049
050    @Override
051    public String oneInstructionString() {
052        return name() + ' ' + jmri.util.StringUtil.hexStringFromBytes(bytes) + '\n';
053    }
054
055    @Override
056    public String allInstructionString(String indent) {
057        return indent + oneInstructionString();
058    }
059}