cleaned up from violations

This commit is contained in:
Lucas Pleß 2012-03-08 01:22:31 +01:00
parent e7ca20183a
commit 2f693b0f7e
8 changed files with 39 additions and 35 deletions

View File

@ -20,6 +20,11 @@
package de.ctdo.bunti.artnet;
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;
public ByteUtils(byte[] data) {
@ -27,21 +32,23 @@ public class ByteUtils {
}
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() {
return data;
}
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) {
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) {
@ -57,17 +64,17 @@ public class ByteUtils {
}
public final void setInt16(int val, int offset) {
data[offset] = (byte) (val >> 8 & 0xff);
data[offset + 1] = (byte) (val & 0xff);
data[offset] = (byte) (val >> BIT_PER_BYTE & BYTE_MAX);
data[offset + ONE_BYTE_OFFSET] = (byte) (val & BYTE_MAX);
}
public final void setInt16LE(int val, int offset) {
data[offset] = (byte) (val & 0xff);
data[offset + 1] = (byte) (val >> 8 & 0xff);
data[offset] = (byte) (val & BYTE_MAX);
data[offset + ONE_BYTE_OFFSET] = (byte) (val >> BIT_PER_BYTE & BYTE_MAX);
}
public final void setInt8(int val, int offset) {
data[offset] = (byte) (val & 0xff);
data[offset] = (byte) (val & BYTE_MAX);
}
}

View File

@ -42,7 +42,7 @@ public class SimpleArtNetSenderImpl implements SimpleArtNetSender {
byte[] arr = new byte[size];
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;

View File

@ -29,6 +29,7 @@ public class ArtDmxPacket extends ArtNetPacket {
private static final int OFFSET_UNIVERSE = 14;
private static final int OFFSET_DMX_LENGTH = 16;
private static final int LOWER_NIBBLE = 0x0f;
private static final int HALF_BYTE = 4;
private static final int SEQUENCE_ID_MAX = 0xff;
private int numChannels;
@ -38,7 +39,7 @@ public class ArtDmxPacket extends ArtNetPacket {
public ArtDmxPacket() {
super(PacketType.ART_OUTPUT, DMX_PACKET_MAX_LENGTH);
getData().setInt8(2, OFFSET_PHYSICAL);
getData().setInt8(0, OFFSET_PHYSICAL);
setUniverse(0, 0);
}
@ -122,6 +123,6 @@ public class ArtDmxPacket extends ArtNetPacket {
* @param universeID
*/
private void setUniverse(int subnetID, int universeID) {
getData().setInt16LE(subnetID << 4 | universeID, OFFSET_UNIVERSE);
getData().setInt16LE(subnetID << HALF_BYTE | universeID, OFFSET_UNIVERSE);
}
}

View File

@ -16,7 +16,7 @@ import de.ctdo.bunti.model.*;
@Component
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 BuntiDevicesDAO devicesDAO;
@ -36,7 +36,7 @@ public class BuntiControllerImpl implements BuntiController, ApplicationEventPub
if (device != null) {
this.applicationEventPublisher.publishEvent(new DeviceChangedEvent(this, device, options));
logger.debug("publishEvent in BuntiController");
LOGGER.debug("publishEvent in BuntiController");
return true;
}

View File

@ -35,7 +35,7 @@ public final class BuntiDevicesDAOImpl implements BuntiDevicesDAO {
@Override
public final Collection<BuntiDMXDevice> getAllDMXDevices() {
public Collection<BuntiDMXDevice> getAllDMXDevices() {
List<BuntiDMXDevice> list = new ArrayList<BuntiDMXDevice>();
for (BuntiDevice device : devices) {
if( device instanceof BuntiDMXDevice ) {
@ -46,12 +46,12 @@ public final class BuntiDevicesDAOImpl implements BuntiDevicesDAO {
}
@Override
public final Collection<BuntiDevice> getAllDevices() {
public Collection<BuntiDevice> getAllDevices() {
return Collections.unmodifiableCollection(devices);
}
@Override
public final BuntiDevice getDeviceById(int deviceId) {
public BuntiDevice getDeviceById(int deviceId) {
for (BuntiDevice dev : devices) {
if(dev.getDeviceId() == deviceId) {
return dev;

View File

@ -18,6 +18,7 @@ import java.util.Map;
@Component
public class DMXMixerImpl implements DMXMixer, ApplicationListener<DeviceChangedEvent> {
private static final Logger LOGGER = LoggerFactory.getLogger(DMXMixerImpl.class);
private static final int NET_SEND_INTERVAL = 100;
private String artNetDeviceAddress;
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() {
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 = 100)
@Scheduled(fixedDelay = NET_SEND_INTERVAL)
public final void sendOutDMXBuffer() {
if (dmxMap.size() == 0) {
initDMXData();

View File

@ -13,12 +13,12 @@ public class Par56Spot extends BuntiDMXDevice {
public Par56Spot(int deviceId, int startAddress, String deviceName) {
super(deviceId, startAddress, deviceName);
addChannel(new DMXChannel(0, CHANNEL_MODE));
addChannel(new DMXChannel(1, CHANNEL_RED));
addChannel(new DMXChannel(2, CHANNEL_GREEN));
addChannel(new DMXChannel(3, CHANNEL_BLUE));
addChannel(new DMXChannel(4, CHANNEL_SPEED));
int offset = 0;
addChannel(new DMXChannel(offset++, CHANNEL_MODE));
addChannel(new DMXChannel(offset++, CHANNEL_RED));
addChannel(new DMXChannel(offset++, CHANNEL_GREEN));
addChannel(new DMXChannel(offset++, CHANNEL_BLUE));
addChannel(new DMXChannel(offset, CHANNEL_SPEED));
}
public final void setColorRed(int value) {

View File

@ -1,24 +1,20 @@
package de.ctdo.bunti.web;
import javax.validation.Valid;
import de.ctdo.bunti.control.BuntiController;
import de.ctdo.bunti.webmodel.DeviceUpdate;
import org.springframework.beans.factory.annotation.Autowired;
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.servlet.ModelAndView;
@Controller
public class RestController {
private Validator validator;
// private Validator validator;
private BuntiController controller;
@Autowired
public void setValidator(Validator validator) {
this.validator = validator;
}
// @Autowired
// public void setValidator(Validator validator) {
// this.validator = validator;
// }
@Autowired
public final void setController(BuntiController controller) {