bunti/src/main/java/de/ctdo/bunti/artnet/packets/ArtDmxPacket.java

122 lines
3.2 KiB
Java

/*
* This file is part of artnet4j.
*
* Copyright 2009 Karsten Schmidt (PostSpectacular Ltd.)
*
* artnet4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* artnet4j is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with artnet4j. If not, see <http://www.gnu.org/licenses/>.
*/
package de.ctdo.bunti.artnet.packets;
public class ArtDmxPacket extends ArtNetPacket {
private int numChannels;
private int sequenceID;
private int subnetID;
private int universeID;
public ArtDmxPacket() {
super(PacketType.ART_OUTPUT);
setData(new byte[530]);
setHeader();
setProtocol();
getData().setInt8(0x02, 13);
}
/**
* @return the actual packet size used. If an odd number DMX channels is
* used, the packet size is made even automatically.
*
* @see ArtNetPacket#getLength()
*/
@Override
public final int getLength() {
return 18 + (1 == numChannels % 2 ? numChannels + 1 : numChannels);
}
/**
* @return the number of DMX channels
*/
public final int getNumChannels() {
return numChannels;
}
/**
* @return the sequenceID
*/
public final int getSequenceID() {
return sequenceID;
}
/**
* @return the subnetID
*/
public final int getSubnetID() {
return subnetID;
}
/**
* @return the universeID
*/
public final int getUniverseID() {
return universeID;
}
@Override
public final boolean parse(byte[] raw) {
return false;
}
public final void setDMX(byte[] dmxData, int numChannels) {
this.numChannels = numChannels;
getData().setByteChunk(dmxData, 18, numChannels);
getData().setInt16((1 == numChannels % 2 ? numChannels + 1 : numChannels),
16);
}
/**
* @param numChannels
* the number of DMX channels to set
*/
public final void setNumChannels(int numChannels) {
this.numChannels = numChannels > 512 ? 512 : numChannels;
}
public final void setSequenceID(int id) {
sequenceID = id % 0xff;
getData().setInt8(id, 12);
}
/**
* @param subnetID
* the subnetID to set
*/
public final void setSubnetID(int subnetID) {
this.subnetID = subnetID & 0x0f;
}
public final void setUniverse(int subnetID, int universeID) {
this.subnetID = subnetID & 0x0f;
this.universeID = universeID & 0x0f;
getData().setInt16LE(subnetID << 4 | universeID, 14);
}
/**
* @param universeID
* the universeID to set
*/
public final void setUniverseID(int universeID) {
this.universeID = universeID & 0x0f;
}
}