001package jmri.jmrix.powerline; 002 003/** 004 * Represent a sequence of one or more Dmx commands (unit and intensity). 005 * <p> 006 * These are Dmx specific, but not device/interface specific. 007 * <p> 008 * A sequence should consist of addressing (1 or more), and then one or more 009 * commands. It can address multiple devices. 010 * 011 * @author Bob Coleman Copyright (C) 2010 012 * @author Bob Jacobsen Copyright (C) 2008 013 * @author Ken Cameron Copyright (C) 2023 014 */ 015public class DmxSequence { 016 017 // First implementation of this class uses a fixed length 018 // array to hold the sequence; there's a practical limit to how 019 // many Dmx commands anybody would want to send at once! 020 private static final int MAXINDEX = 32; 021 private int index = 0; 022 private Command[] cmds = new Cmd[MAXINDEX]; // doesn't scale, but that's for another day 023 024 /** 025 * Append a new "do command" operation to the sequence 026 * @param unit 1st id value 027 * @param value 2nd id value 028 */ 029 public void addCommand(int unit, byte value) { 030 if (index >= MAXINDEX) { 031 throw new IllegalArgumentException("Sequence too long"); 032 } 033 cmds[index] = new Cmd(unit, value); 034 index++; 035 } 036 037 /** 038 * Next getCommand will be the first in the sequence 039 */ 040 public void reset() { 041 index = 0; 042 } 043 044 /** 045 * Retrieve the next command in the sequence 046 * @return single DMx cmd 047 */ 048 public Command getCommand() { 049 return cmds[index++]; 050 } 051 052 /** 053 * Represent a single Dmx command, which is a unit and intensity pair 054 */ 055 public interface Command { 056 057 public int getUnit(); 058 059 public byte getValue(); 060 } 061 062 /** 063 * Represent a single Dmx command 064 */ 065 public static class Cmd implements Command { 066 067 int unit; 068 byte value; 069 public Cmd(int unit, byte value) { 070 this.unit = unit; 071 this.value = value; 072 } 073 074 @Override 075 public int getUnit() { 076 return unit; 077 } 078 079 @Override 080 public byte getValue() { 081 return value; 082 } 083 } 084 085}