001package jmri.jmrix.loconet.sdf;
002
003/**
004 * Implement the SDL_VERSION macro from the Digitrax sound definition language
005 *
006 * @author Bob Jacobsen Copyright (C) 2007
007 */
008public class SdlVersion extends SdfMacro {
009
010    public SdlVersion(int version) {
011        this.version = version;
012    }
013
014    @Override
015    public String name() {
016        return "SDL_VERSION"; // NOI18N
017    }
018
019    int version;
020
021    @Override
022    public int length() {
023        return 2;
024    }
025
026    static public SdfMacro match(SdfBuffer buff) {
027        if ((buff.getAtIndex() & 0xFF) != 0x82) {
028            return null;
029        }
030        buff.getAtIndexAndInc(); // drop op code
031        return new SdlVersion(buff.getAtIndexAndInc());
032    }
033
034    /**
035     * Store into a buffer.
036     */
037    @Override
038    public void loadByteArray(SdfBuffer buffer) {
039        // data
040        buffer.setAtIndexAndInc(0x82);
041        buffer.setAtIndexAndInc(version);
042
043        // store children
044        super.loadByteArray(buffer);
045    }
046
047    @Override
048    public String toString() {
049        return "Version " + (version == 0x10 ? "1" : "<unknown code>") + '\n'; // NOI18N
050    }
051
052    @Override
053    public String oneInstructionString() {
054        return name() + ' ' + (version == 0x10 ? "VERSION_1" : "Unknown code " + version) + '\n'; // NOI18N
055    }
056
057    @Override
058    public String allInstructionString(String indent) {
059        return indent + oneInstructionString();
060    }
061}