Search in sources :

Example 1 with VelbusPacket

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

the class AnalogOutputProcessor method getPackets.

protected List<VelbusPacket> getPackets(VelbusDevice velbusDevice, int channelNumber, VelbusPacket.OutboundCommand command, int level, int speedSeconds, int durationSeconds) {
    byte[] packetBytes = null;
    switch(command) {
        case SET_VALUE:
        case SET_LEVEL:
        case SET_LEVEL_LAST:
            speedSeconds = Math.min(0xFFFF, Math.max(0, speedSeconds));
            if (command == SET_VALUE) {
                packetBytes = new byte[5];
                packetBytes[1] = (byte) (level >> 8);
                packetBytes[2] = (byte) level;
                packetBytes[3] = (byte) (speedSeconds >> 8);
                packetBytes[4] = (byte) speedSeconds;
            } else {
                level = Math.min(100, Math.max(0, level));
                packetBytes = new byte[4];
                packetBytes[1] = (byte) level;
                packetBytes[2] = (byte) (speedSeconds >> 8);
                packetBytes[3] = (byte) speedSeconds;
            }
            break;
        case FORCE_ON:
        case LEVEL_ON_TIMER:
        case 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 SET_LEVEL_HALT:
            // for some reason the module doesn't reliable update the LED status when a halt command is sent
            String ledProp = getChannelPrefix(velbusDevice.getDeviceType()) + channelNumber + "_LED";
            LedState ledState = (LedState) velbusDevice.getPropertyValue(ledProp);
            if (ledState == LedState.FAST) {
                velbusDevice.setProperty(ledProp, LedState.ON);
            }
        case INHIBIT_CANCEL:
        case FORCE_ON_CANCEL:
        case LOCK_CANCEL:
            packetBytes = new byte[1];
            break;
    }
    if (packetBytes != null) {
        if (velbusDevice.getDeviceType() == VelbusDeviceType.VMB4AN) {
            packetBytes[0] = (byte) (channelNumber + 11);
        } else {
            packetBytes[0] = (byte) Math.pow(2, channelNumber - 1);
        }
        // For LEVEL_ON_TIMER we must also send a SET_LEVEL to make sure the dimmer is on
        if (command == LEVEL_ON_TIMER) {
            return Arrays.asList(new VelbusPacket(velbusDevice.getBaseAddress(), SET_LEVEL.getCode(), VelbusPacket.PacketPriority.HIGH, packetBytes[0], (byte) 100, (byte) 0, (byte) 0), new VelbusPacket(velbusDevice.getBaseAddress(), command.getCode(), VelbusPacket.PacketPriority.HIGH, packetBytes));
        }
        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 2 with VelbusPacket

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

the class ProgramsProcessor method getProgramStepsPackets.

protected static List<VelbusPacket> getProgramStepsPackets(VelbusDevice device, int channelNumber, boolean enabled, int durationSeconds) {
    byte[] packetBytes = enabled ? new byte[1] : new byte[4];
    packetBytes[0] = (byte) channelNumber;
    if (!enabled) {
        durationSeconds = Math.min(durationSeconds, 0xFFFFFE);
        // FFFFFF locks it permanently
        int duration = durationSeconds > 0 ? durationSeconds : 0xFFFFFF;
        packetBytes[1] = (byte) (duration >> 16);
        packetBytes[2] = (byte) (duration >> 8);
        packetBytes[3] = (byte) (duration);
    }
    VelbusPacket.OutboundCommand command = enabled ? VelbusPacket.OutboundCommand.PROGRAM_STEPS_ENABLE : VelbusPacket.OutboundCommand.PROGRAM_STEPS_DISABLE;
    return Collections.singletonList(new VelbusPacket(device.getBaseAddress(), command.getCode(), VelbusPacket.PacketPriority.LOW, packetBytes));
}
Also used : VelbusPacket(org.openremote.agent.protocol.velbus.VelbusPacket)

Example 3 with VelbusPacket

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

the class RelayProcessor method getPackets.

protected static List<VelbusPacket> getPackets(VelbusDevice velbusDevice, int channelNumber, VelbusPacket.OutboundCommand command, int durationSeconds) {
    byte[] packetBytes = null;
    switch(command) {
        case FORCE_ON:
        case RELAY_ON_TIMER:
        case RELAY_BLINK_TIMER:
        case 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 RELAY_ON:
        case RELAY_OFF:
        case INHIBIT_CANCEL:
        case FORCE_ON_CANCEL:
        case 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 4 with VelbusPacket

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

the class VelbusDevice method createTimeInjectionPackets.

public static VelbusPacket[] createTimeInjectionPackets() {
    Calendar c = Calendar.getInstance();
    int dst = c.get(Calendar.DST_OFFSET) > 0 ? 1 : 0;
    int dow = (c.get(Calendar.DAY_OF_WEEK) + 5) % 7;
    int dom = c.get(Calendar.DAY_OF_MONTH);
    int month = c.get(Calendar.MONTH) + 1;
    int hours = c.get(Calendar.HOUR_OF_DAY);
    int mins = c.get(Calendar.MINUTE);
    int year = c.get(Calendar.YEAR);
    VelbusPacket[] packets = new VelbusPacket[3];
    // Time packet
    packets[0] = new VelbusPacket(0x00, VelbusPacket.OutboundCommand.REALTIME_CLOCK_SET.getCode(), (byte) dow, (byte) hours, (byte) mins);
    // Date packet
    packets[1] = new VelbusPacket(0x00, VelbusPacket.OutboundCommand.REALTIME_DATE_SET.getCode(), (byte) dom, (byte) month, (byte) (year >>> 8), (byte) year);
    // DST packet
    packets[2] = new VelbusPacket(0x00, VelbusPacket.OutboundCommand.DAYLIGHT_SAVING_SET.getCode(), (byte) dst);
    return packets;
}
Also used : VelbusPacket(org.openremote.agent.protocol.velbus.VelbusPacket)

Example 5 with VelbusPacket

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

the class AnalogInputProcessor method getStatusRequestPackets.

@Override
public List<VelbusPacket> getStatusRequestPackets(VelbusDevice device) {
    if (device.getDeviceType() == VelbusDeviceType.VMBMETEO) {
        return Collections.singletonList(new VelbusPacket(device.getBaseAddress(), VelbusPacket.OutboundCommand.SENSOR_READOUT.getCode(), (byte) 0x0F, (byte) 0x00));
    }
    if (device.getDeviceType() == VelbusDeviceType.VMB4AN) {
        // Initialise the text char arrays for sensors
        device.setProperty("SENSOR1_TEXT", new StringDevicePropertyValue(EmptySensorText));
        device.setProperty("SENSOR2_TEXT", new StringDevicePropertyValue(EmptySensorText));
        device.setProperty("SENSOR3_TEXT", new StringDevicePropertyValue(EmptySensorText));
        device.setProperty("SENSOR4_TEXT", new StringDevicePropertyValue(EmptySensorText));
        return Arrays.asList(new VelbusPacket(device.getBaseAddress(), VelbusPacket.OutboundCommand.SENSOR_READOUT.getCode(), (byte) 0x08, (byte) 0x00), new VelbusPacket(device.getBaseAddress(), VelbusPacket.OutboundCommand.SENSOR_READOUT.getCode(), (byte) 0x09, (byte) 0x00), new VelbusPacket(device.getBaseAddress(), VelbusPacket.OutboundCommand.SENSOR_READOUT.getCode(), (byte) 0x0A, (byte) 0x00), new VelbusPacket(device.getBaseAddress(), VelbusPacket.OutboundCommand.SENSOR_READOUT.getCode(), (byte) 0x0B, (byte) 0x00), new VelbusPacket(device.getBaseAddress(), VelbusPacket.OutboundCommand.SENSOR_SETTINGS.getCode(), (byte) 0x08), new VelbusPacket(device.getBaseAddress(), VelbusPacket.OutboundCommand.SENSOR_SETTINGS.getCode(), (byte) 0x09), new VelbusPacket(device.getBaseAddress(), VelbusPacket.OutboundCommand.SENSOR_SETTINGS.getCode(), (byte) 0x0A), new VelbusPacket(device.getBaseAddress(), VelbusPacket.OutboundCommand.SENSOR_SETTINGS.getCode(), (byte) 0x0B));
    }
    return null;
}
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