cleaned up from violations
This commit is contained in:
parent
e7ca20183a
commit
2f693b0f7e
|
@ -20,6 +20,11 @@
|
||||||
package de.ctdo.bunti.artnet;
|
package de.ctdo.bunti.artnet;
|
||||||
|
|
||||||
public class ByteUtils {
|
public class ByteUtils {
|
||||||
|
private static final int BYTE_OVERFLOW = 256;
|
||||||
|
private static final int BYTE_MAX = 0xff;
|
||||||
|
private static final int BIT_PER_BYTE = 8;
|
||||||
|
private static final int ONE_BYTE_OFFSET = 1;
|
||||||
|
|
||||||
private final byte[] data;
|
private final byte[] data;
|
||||||
|
|
||||||
public ByteUtils(byte[] data) {
|
public ByteUtils(byte[] data) {
|
||||||
|
@ -27,21 +32,23 @@ public class ByteUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int byteToUint(byte b) {
|
public static final int byteToUint(byte b) {
|
||||||
return (b < 0 ? 256 + b : b);
|
return (b < 0 ? BYTE_OVERFLOW + b : b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final byte uintToByte(int i) {
|
||||||
|
return (byte)(i & BYTE_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
public final byte[] getBytes() {
|
public final byte[] getBytes() {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int getInt16(int offset) {
|
public final int getInt16(int offset) {
|
||||||
return (byteToUint(data[offset]) << 8) | byteToUint(data[offset + 1]);
|
return (byteToUint(data[offset]) << BIT_PER_BYTE) | byteToUint(data[offset + 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public final int getInt16LE(int offset) {
|
public final int getInt16LE(int offset) {
|
||||||
return (byteToUint(data[offset + 1]) << 8) | byteToUint(data[offset]);
|
return (byteToUint(data[offset + ONE_BYTE_OFFSET]) << BIT_PER_BYTE) | byteToUint(data[offset]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int getInt8(int offset) {
|
public final int getInt8(int offset) {
|
||||||
|
@ -57,17 +64,17 @@ public class ByteUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setInt16(int val, int offset) {
|
public final void setInt16(int val, int offset) {
|
||||||
data[offset] = (byte) (val >> 8 & 0xff);
|
data[offset] = (byte) (val >> BIT_PER_BYTE & BYTE_MAX);
|
||||||
data[offset + 1] = (byte) (val & 0xff);
|
data[offset + ONE_BYTE_OFFSET] = (byte) (val & BYTE_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setInt16LE(int val, int offset) {
|
public final void setInt16LE(int val, int offset) {
|
||||||
data[offset] = (byte) (val & 0xff);
|
data[offset] = (byte) (val & BYTE_MAX);
|
||||||
data[offset + 1] = (byte) (val >> 8 & 0xff);
|
data[offset + ONE_BYTE_OFFSET] = (byte) (val >> BIT_PER_BYTE & BYTE_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setInt8(int val, int offset) {
|
public final void setInt8(int val, int offset) {
|
||||||
data[offset] = (byte) (val & 0xff);
|
data[offset] = (byte) (val & BYTE_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class SimpleArtNetSenderImpl implements SimpleArtNetSender {
|
||||||
byte[] arr = new byte[size];
|
byte[] arr = new byte[size];
|
||||||
|
|
||||||
for (int i = 0; i < dmxData.size(); i++) {
|
for (int i = 0; i < dmxData.size(); i++) {
|
||||||
arr[i] = (byte)(dmxData.get(i + DMX.DMX_STARTADDRESS_OFFSET) & 0xff);
|
arr[i] = ByteUtils.uintToByte(dmxData.get(i + DMX.DMX_STARTADDRESS_OFFSET));
|
||||||
}
|
}
|
||||||
|
|
||||||
return arr;
|
return arr;
|
||||||
|
|
|
@ -29,6 +29,7 @@ public class ArtDmxPacket extends ArtNetPacket {
|
||||||
private static final int OFFSET_UNIVERSE = 14;
|
private static final int OFFSET_UNIVERSE = 14;
|
||||||
private static final int OFFSET_DMX_LENGTH = 16;
|
private static final int OFFSET_DMX_LENGTH = 16;
|
||||||
private static final int LOWER_NIBBLE = 0x0f;
|
private static final int LOWER_NIBBLE = 0x0f;
|
||||||
|
private static final int HALF_BYTE = 4;
|
||||||
private static final int SEQUENCE_ID_MAX = 0xff;
|
private static final int SEQUENCE_ID_MAX = 0xff;
|
||||||
|
|
||||||
private int numChannels;
|
private int numChannels;
|
||||||
|
@ -38,7 +39,7 @@ public class ArtDmxPacket extends ArtNetPacket {
|
||||||
|
|
||||||
public ArtDmxPacket() {
|
public ArtDmxPacket() {
|
||||||
super(PacketType.ART_OUTPUT, DMX_PACKET_MAX_LENGTH);
|
super(PacketType.ART_OUTPUT, DMX_PACKET_MAX_LENGTH);
|
||||||
getData().setInt8(2, OFFSET_PHYSICAL);
|
getData().setInt8(0, OFFSET_PHYSICAL);
|
||||||
setUniverse(0, 0);
|
setUniverse(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,6 +123,6 @@ public class ArtDmxPacket extends ArtNetPacket {
|
||||||
* @param universeID
|
* @param universeID
|
||||||
*/
|
*/
|
||||||
private void setUniverse(int subnetID, int universeID) {
|
private void setUniverse(int subnetID, int universeID) {
|
||||||
getData().setInt16LE(subnetID << 4 | universeID, OFFSET_UNIVERSE);
|
getData().setInt16LE(subnetID << HALF_BYTE | universeID, OFFSET_UNIVERSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,7 +16,7 @@ import de.ctdo.bunti.model.*;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class BuntiControllerImpl implements BuntiController, ApplicationEventPublisherAware {
|
public class BuntiControllerImpl implements BuntiController, ApplicationEventPublisherAware {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(BuntiControllerImpl.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(BuntiControllerImpl.class);
|
||||||
private ApplicationEventPublisher applicationEventPublisher = null;
|
private ApplicationEventPublisher applicationEventPublisher = null;
|
||||||
private BuntiDevicesDAO devicesDAO;
|
private BuntiDevicesDAO devicesDAO;
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ public class BuntiControllerImpl implements BuntiController, ApplicationEventPub
|
||||||
|
|
||||||
if (device != null) {
|
if (device != null) {
|
||||||
this.applicationEventPublisher.publishEvent(new DeviceChangedEvent(this, device, options));
|
this.applicationEventPublisher.publishEvent(new DeviceChangedEvent(this, device, options));
|
||||||
logger.debug("publishEvent in BuntiController");
|
LOGGER.debug("publishEvent in BuntiController");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ public final class BuntiDevicesDAOImpl implements BuntiDevicesDAO {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final Collection<BuntiDMXDevice> getAllDMXDevices() {
|
public Collection<BuntiDMXDevice> getAllDMXDevices() {
|
||||||
List<BuntiDMXDevice> list = new ArrayList<BuntiDMXDevice>();
|
List<BuntiDMXDevice> list = new ArrayList<BuntiDMXDevice>();
|
||||||
for (BuntiDevice device : devices) {
|
for (BuntiDevice device : devices) {
|
||||||
if( device instanceof BuntiDMXDevice ) {
|
if( device instanceof BuntiDMXDevice ) {
|
||||||
|
@ -46,12 +46,12 @@ public final class BuntiDevicesDAOImpl implements BuntiDevicesDAO {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final Collection<BuntiDevice> getAllDevices() {
|
public Collection<BuntiDevice> getAllDevices() {
|
||||||
return Collections.unmodifiableCollection(devices);
|
return Collections.unmodifiableCollection(devices);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final BuntiDevice getDeviceById(int deviceId) {
|
public BuntiDevice getDeviceById(int deviceId) {
|
||||||
for (BuntiDevice dev : devices) {
|
for (BuntiDevice dev : devices) {
|
||||||
if(dev.getDeviceId() == deviceId) {
|
if(dev.getDeviceId() == deviceId) {
|
||||||
return dev;
|
return dev;
|
||||||
|
|
|
@ -18,6 +18,7 @@ import java.util.Map;
|
||||||
@Component
|
@Component
|
||||||
public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChangedEvent> {
|
public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChangedEvent> {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(DMXMixerImpl.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(DMXMixerImpl.class);
|
||||||
|
private static final int NET_SEND_INTERVAL = 100;
|
||||||
private String artNetDeviceAddress;
|
private String artNetDeviceAddress;
|
||||||
|
|
||||||
private final Map<Integer, Integer> dmxMap = Collections.synchronizedMap(new HashMap<Integer, Integer>());
|
private final Map<Integer, Integer> dmxMap = Collections.synchronizedMap(new HashMap<Integer, Integer>());
|
||||||
|
@ -35,12 +36,11 @@ public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChanged
|
||||||
|
|
||||||
public final void initDMXData() {
|
public final void initDMXData() {
|
||||||
for (int i = DMX.DMX_CHANNEL_INDEX_MIN; i <= DMX.DMX_CHANNEL_INDEX_MAX; i++) {
|
for (int i = DMX.DMX_CHANNEL_INDEX_MIN; i <= DMX.DMX_CHANNEL_INDEX_MAX; i++) {
|
||||||
dmxMap.put(i, 0);
|
dmxMap.put(i, DMX.DMX_CHANNEL_VALUE_MIN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Scheduled(fixedDelay = NET_SEND_INTERVAL)
|
||||||
@Scheduled(fixedDelay = 100)
|
|
||||||
public final void sendOutDMXBuffer() {
|
public final void sendOutDMXBuffer() {
|
||||||
if (dmxMap.size() == 0) {
|
if (dmxMap.size() == 0) {
|
||||||
initDMXData();
|
initDMXData();
|
||||||
|
|
|
@ -13,12 +13,12 @@ public class Par56Spot extends BuntiDMXDevice {
|
||||||
|
|
||||||
public Par56Spot(int deviceId, int startAddress, String deviceName) {
|
public Par56Spot(int deviceId, int startAddress, String deviceName) {
|
||||||
super(deviceId, startAddress, deviceName);
|
super(deviceId, startAddress, deviceName);
|
||||||
|
int offset = 0;
|
||||||
addChannel(new DMXChannel(0, CHANNEL_MODE));
|
addChannel(new DMXChannel(offset++, CHANNEL_MODE));
|
||||||
addChannel(new DMXChannel(1, CHANNEL_RED));
|
addChannel(new DMXChannel(offset++, CHANNEL_RED));
|
||||||
addChannel(new DMXChannel(2, CHANNEL_GREEN));
|
addChannel(new DMXChannel(offset++, CHANNEL_GREEN));
|
||||||
addChannel(new DMXChannel(3, CHANNEL_BLUE));
|
addChannel(new DMXChannel(offset++, CHANNEL_BLUE));
|
||||||
addChannel(new DMXChannel(4, CHANNEL_SPEED));
|
addChannel(new DMXChannel(offset, CHANNEL_SPEED));
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setColorRed(int value) {
|
public final void setColorRed(int value) {
|
||||||
|
|
|
@ -1,24 +1,20 @@
|
||||||
package de.ctdo.bunti.web;
|
package de.ctdo.bunti.web;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import de.ctdo.bunti.control.BuntiController;
|
import de.ctdo.bunti.control.BuntiController;
|
||||||
import de.ctdo.bunti.webmodel.DeviceUpdate;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.validation.BindingResult;
|
|
||||||
import org.springframework.validation.Validator;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class RestController {
|
public class RestController {
|
||||||
private Validator validator;
|
// private Validator validator;
|
||||||
private BuntiController controller;
|
private BuntiController controller;
|
||||||
|
|
||||||
@Autowired
|
// @Autowired
|
||||||
public void setValidator(Validator validator) {
|
// public void setValidator(Validator validator) {
|
||||||
this.validator = validator;
|
// this.validator = validator;
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public final void setController(BuntiController controller) {
|
public final void setController(BuntiController controller) {
|
||||||
|
|
Loading…
Reference in New Issue