Search in sources :

Example 6 with VelbusPacket

use of org.openremote.agent.protocol.velbus.VelbusPacket in project openremote by openremote.

the class BlindProcessor method getPackets.

protected static List<VelbusPacket> getPackets(VelbusDevice velbusDevice, int channelNumber, VelbusPacket.OutboundCommand command, int durationSeconds, int position) {
    byte[] packetBytes = null;
    switch(command) {
        case BLIND_POSITION:
            position = Math.min(100, Math.max(0, position));
            packetBytes = new byte[2];
            packetBytes[1] = (byte) position;
            break;
        case BLIND_UP:
        case BLIND_DOWN:
        case BLIND_FORCE_UP:
        case BLIND_FORCE_DOWN:
        case BLIND_INHIBIT_UP:
        case BLIND_INHIBIT_DOWN:
        case LEVEL_ON_TIMER:
        case BLIND_LOCK:
        case INHIBIT:
            durationSeconds = durationSeconds == -1 ? 0xFFFFFF : durationSeconds;
            durationSeconds = Math.min(0xFFFFFF, Math.max(0, durationSeconds));
            packetBytes = new byte[4];
            packetBytes[1] = (byte) (durationSeconds >> 16);
            packetBytes[2] = (byte) (durationSeconds >> 8);
            packetBytes[3] = (byte) (durationSeconds);
            break;
        case BLIND_HALT:
        case INHIBIT_CANCEL:
        case BLIND_FORCE_UP_CANCEL:
        case BLIND_FORCE_DOWN_CANCEL:
        case LOCK_CANCEL:
        case BLIND_LOCK_CANCEL:
            packetBytes = new byte[1];
            break;
    }
    if (packetBytes != null) {
        packetBytes[0] = (byte) Math.pow(2, channelNumber - 1);
        return Collections.singletonList(new VelbusPacket(velbusDevice.getBaseAddress(), command.getCode(), VelbusPacket.PacketPriority.HIGH, packetBytes));
    }
    return null;
}
Also used : VelbusPacket(org.openremote.agent.protocol.velbus.VelbusPacket)

Example 7 with VelbusPacket

use of org.openremote.agent.protocol.velbus.VelbusPacket in project openremote by openremote.

the class BlindProcessor method getStatusRequestPackets.

@Override
public List<VelbusPacket> getStatusRequestPackets(VelbusDevice device) {
    List<VelbusPacket> packets = new ArrayList<>();
    for (int i = 1; i <= ChannelProcessor.getMaxChannelNumber(device.getDeviceType()); i++) {
        byte channelByte = (byte) Math.pow(2, i - 1);
        packets.add(new VelbusPacket(device.getBaseAddress(), VelbusPacket.OutboundCommand.MODULE_STATUS.getCode(), channelByte));
    }
    return packets;
}
Also used : VelbusPacket(org.openremote.agent.protocol.velbus.VelbusPacket)

Example 8 with VelbusPacket

use of org.openremote.agent.protocol.velbus.VelbusPacket in project openremote by openremote.

the class CounterProcessor method getStatusRequestPackets.

@Override
public List<VelbusPacket> getStatusRequestPackets(VelbusDevice device) {
    // Push default counter values as these aren't received unless the counter is enabled
    device.setProperty("COUNTER1_ENABLED", BooleanDevicePropertyValue.FALSE);
    device.setProperty("COUNTER2_ENABLED", BooleanDevicePropertyValue.FALSE);
    device.setProperty("COUNTER3_ENABLED", BooleanDevicePropertyValue.FALSE);
    device.setProperty("COUNTER4_ENABLED", BooleanDevicePropertyValue.FALSE);
    device.setProperty("COUNTER1", DoubleDevicePropertyValue.ZERO);
    device.setProperty("COUNTER2", DoubleDevicePropertyValue.ZERO);
    device.setProperty("COUNTER3", DoubleDevicePropertyValue.ZERO);
    device.setProperty("COUNTER4", DoubleDevicePropertyValue.ZERO);
    device.setProperty("COUNTER1_INSTANT", DoubleDevicePropertyValue.ZERO);
    device.setProperty("COUNTER2_INSTANT", DoubleDevicePropertyValue.ZERO);
    device.setProperty("COUNTER3_INSTANT", DoubleDevicePropertyValue.ZERO);
    device.setProperty("COUNTER4_INSTANT", DoubleDevicePropertyValue.ZERO);
    return Arrays.asList(new VelbusPacket(device.getBaseAddress(), VelbusPacket.OutboundCommand.COUNTER_STATUS.getCode(), (byte) 0x0F, (byte) 0x00), new VelbusPacket(device.getBaseAddress(), VelbusPacket.OutboundCommand.READ_MEMORY.getCode(), (byte) 0x03, (byte) 0xFE));
}
Also used : VelbusPacket(org.openremote.agent.protocol.velbus.VelbusPacket)

Example 9 with VelbusPacket

use of org.openremote.agent.protocol.velbus.VelbusPacket in project openremote by openremote.

the class InputProcessor method getChannelStatePackets.

protected static List<VelbusPacket> getChannelStatePackets(VelbusDevice velbusDevice, int address, int channelNumber, ChannelState channelState) {
    byte[] packetBytes = new byte[3];
    channelNumber = channelNumber % 8;
    int byteIndex = channelState == ChannelState.PRESSED ? 0 : channelState == ChannelState.RELEASED ? 1 : 2;
    packetBytes[byteIndex] = (byte) Math.pow(2, (channelNumber - 1));
    return Collections.singletonList(new VelbusPacket(address, VelbusPacket.OutboundCommand.BUTTON_STATUS.getCode(), VelbusPacket.PacketPriority.HIGH, packetBytes));
}
Also used : VelbusPacket(org.openremote.agent.protocol.velbus.VelbusPacket)

Example 10 with VelbusPacket

use of org.openremote.agent.protocol.velbus.VelbusPacket in project openremote by openremote.

the class InputProcessor method getLockStatePackets.

static List<VelbusPacket> getLockStatePackets(VelbusDevice velbusDevice, int channelNumber, int lockDurationSeconds) {
    boolean locked = lockDurationSeconds != 0;
    byte[] packetBytes = locked ? new byte[4] : new byte[1];
    packetBytes[0] = velbusDevice.getDeviceType() == VelbusDeviceType.VMB4AN ? (byte) (channelNumber - 1) : (byte) channelNumber;
    if (locked) {
        lockDurationSeconds = Math.min(lockDurationSeconds, 0xFFFFFE);
        // FFFFFF locks it permanently
        int duration = lockDurationSeconds > 0 ? lockDurationSeconds : 0xFFFFFF;
        packetBytes[1] = (byte) (duration >> 16);
        packetBytes[2] = (byte) (duration >> 8);
        packetBytes[3] = (byte) (duration);
    }
    VelbusPacket.OutboundCommand command = locked ? VelbusPacket.OutboundCommand.LOCK : VelbusPacket.OutboundCommand.LOCK_CANCEL;
    return Collections.singletonList(new VelbusPacket(velbusDevice.getBaseAddress(), command.getCode(), VelbusPacket.PacketPriority.HIGH, packetBytes));
}
Also used : VelbusPacket(org.openremote.agent.protocol.velbus.VelbusPacket)

Aggregations

VelbusPacket (org.openremote.agent.protocol.velbus.VelbusPacket)15 java.util (java.util)1 Level (java.util.logging.Level)1 LOG (org.openremote.agent.protocol.velbus.AbstractVelbusProtocol.LOG)1 AttributeType (org.openremote.model.attribute.AttributeType)1 EnumUtil (org.openremote.model.util.EnumUtil)1 Pair (org.openremote.model.util.Pair)1 Value (org.openremote.model.value.Value)1 ValueType (org.openremote.model.value.ValueType)1 Values (org.openremote.model.value.Values)1