package art.servers.asfserver.protocols.dgt; import art.library.model.devices.vms.asf.Asf; import art.library.model.devices.vms.asf.AsfCommands; import art.library.model.devices.vms.asf.AsfStatus; import art.library.model.devices.vms.asf.information.AsfInformationConfigurationAddressState; import art.library.model.devices.vms.general.VmsGeneral; import art.library.utils.common.ArrayUtils; import java.util.ArrayList; import java.util.List; public class AsfDgtProtocolConstructor { public AsfDgtProtocolConstructor() { } /** * ORDCC * * @param device * @return * @throws Exception */ public static byte[] ORDCC(VmsGeneral device) throws Exception { return new byte[0]; } /** * ASF status query * * @param address * @return * @throws java.lang.Exception */ public static byte[] readAlarms(int address) throws Exception { AsfDgtPDU requestAlarms = new AsfDgtPDU(); requestAlarms.stx = AsfDgtConstants.ASF_STX; requestAlarms.etx = AsfDgtConstants.ASF_ETX; requestAlarms.address = address; requestAlarms.function = AsfDgtConstants.STR_PASF_ALR; requestAlarms.information = new int[0]; byte[] send = requestAlarms.createMessage(); return (send); } /** * ASF configuration query * * @param address * @return * @throws java.lang.Exception */ public static byte[] readConfiguration(int address) throws Exception { AsfDgtPDU requestConfiguration = new AsfDgtPDU(); requestConfiguration.stx = AsfDgtConstants.ASF_STX; requestConfiguration.etx = AsfDgtConstants.ASF_ETX; requestConfiguration.address = address; requestConfiguration.function = AsfDgtConstants.STR_PASF_PP; requestConfiguration.information = new int[0]; byte[] send = requestConfiguration.createMessage(); return (send); } /** * ASF message query * * @param address * @return * @throws java.lang.Exception */ public static byte[] readMessage(int address) throws Exception { AsfDgtPDU requestConfiguration = new AsfDgtPDU(); requestConfiguration.stx = AsfDgtConstants.ASF_STX; requestConfiguration.etx = AsfDgtConstants.ASF_ETX; requestConfiguration.address = address; requestConfiguration.function = AsfDgtConstants.STR_PASF_EP; requestConfiguration.information = new int[0]; byte[] send = requestConfiguration.createMessage(); return (send); } /** * ASF reset order * * @param address * @return * @throws java.lang.Exception */ public static byte[] reset(int address) throws Exception { AsfDgtPDU orderReset = new AsfDgtPDU(); orderReset.stx = AsfDgtConstants.ASF_STX; orderReset.etx = AsfDgtConstants.ASF_ETX; orderReset.address = address; //ASF reset, STR_OASF_RES = 0x15 orderReset.function = AsfDgtConstants.STR_OASF_RES; //Without associated information, empty array orderReset.information = new int[0]; byte[] send = orderReset.createMessage(); return (send); } /** * ASF mep order * * @param address * @param command * @param deviceclone * @return * @throws java.lang.Exception */ public static byte[] mep(int address, AsfCommands command, Asf deviceclone) throws Exception { AsfDgtPDU orderReset = new AsfDgtPDU(); orderReset.stx = AsfDgtConstants.ASF_STX; orderReset.etx = AsfDgtConstants.ASF_ETX; orderReset.address = address; //ASF MEP, STR_OASF_RES = 0x1A orderReset.function = AsfDgtConstants.STR_OASF_MEP; orderReset.information = ArrayUtils.toIntArray(getBodyContentMessage(command.state, deviceclone)); byte[] send = orderReset.createMessage(); return (send); } /** * Get body content message of MEP * * @param commandState * @param deviceclone * @return */ public static byte[] getBodyContentMessage(int commandState, Asf deviceclone) { byte[] result; //Off if (commandState == AsfCommands.STATE_OFF) { //AsfDgtConstants.ASF_OFF = '0' = 0x30 result = new byte[] { AsfDgtConstants.ASF_OFF }; //Fix state } else { List informationList = new ArrayList<>(); informationList.add((byte) AsfDgtConstants.ASF_FIX); informationList.add((byte) AsfDgtConstants.ASF_TOPOLOGY_1); informationList.add((byte) '1'); List lgraphicA = new ArrayList<>(); AsfInformationConfigurationAddressState addressState = deviceclone.getDeviceInformation().configuration.getByState(commandState); lgraphicA.add((byte) '1'); lgraphicA.add((byte) '1'); lgraphicA.add((byte) addressState.address); lgraphicA.add((byte) (addressState.blinking ? 'S' : 'N')); informationList.addAll(lgraphicA); result = new byte[informationList.size()]; int index = 0; for (byte elem : informationList) { result[index++] = elem; } } return result; } /** * ASF timeout order * * @param address * @param command * @param deviceclone * @return * @throws java.lang.Exception */ public static byte[] timeout(int address, AsfCommands command, Asf deviceclone) throws Exception { int brightness = -1; // Auto if (deviceclone.getDeviceStatus().brightnessMode != AsfStatus.BRIGHTNESS_MODE_AUTO) { brightness = deviceclone.getDeviceStatus().brightnessLevel; } int blinkOn = (int) Math.round(deviceclone.getDeviceStatus().blinkOn * 1000); int blinkOff = (int) Math.round(deviceclone.getDeviceStatus().blinkOff * 1000); if (blinkOn == 0) { blinkOn = 500; } if (blinkOff == 0) { blinkOff = 500; } int messagetime = 2; if (brightness == -1) { brightness = 'A'; } else { brightness = AsfDgtProtocolConstructor.getBrightnessDGTLevel(brightness, deviceclone.getDeviceInformation().maximumBrightnessLevel); } AsfDgtPDU request = new AsfDgtPDU(); request.stx = AsfDgtConstants.ASF_STX; request.etx = AsfDgtConstants.ASF_ETX; request.address = address; //ASF MPP, send panel configuration, STR_OASF_MPP = 0x11 request.function = AsfDgtConstants.STR_OASF_MPP; request.information = new int[] { //Byte 1 command.timeout == -1 ? deviceclone.getDeviceConfiguration().timeout : command.timeout, //Byte 2 brightness, //Byte 3 address, //Byte 4 messagetime, //Byte 5 blinkOn, //Byte 6 blinkOff, //Bytes from 7 to 16: reserved /*7*/ 0, /*8*/ 0, /*9*/ 0, /*10*/ 0, /*11*/ 0, /*12*/ 0, /*13*/ 0, /*14*/ 0, /*15*/ 0, /*16*/ 0 }; byte[] send = request.createMessage(); return (send); } /** * ASF mpp order * * @param address * @param command * @param deviceclone * @return * @throws java.lang.Exception */ public static byte[] mpp(int address, AsfCommands command, Asf deviceclone) throws Exception { int brightness = -1; // Auto if (deviceclone.getDeviceStatus().brightnessMode != AsfStatus.BRIGHTNESS_MODE_AUTO) { brightness = deviceclone.getDeviceStatus().brightnessLevel; } if (command.brightness != -2) { brightness = command.brightness; } int blinkOn = (int) Math.round(deviceclone.getDeviceStatus().blinkOn * 1000); if (command.blinkOn > -1) { blinkOn = (int) Math.round(command.blinkOn * 1000); } int blinkOff = (int) Math.round(deviceclone.getDeviceStatus().blinkOff * 1000); if (command.blinkOff > -1) { blinkOff = (int) Math.round(command.blinkOff * 1000); } if (blinkOn == 0) { blinkOn = 500; } if (blinkOff == 0) { blinkOff = 500; } int messagetime = 2; if (brightness == -1) { brightness = 'A'; } else { brightness = AsfDgtProtocolConstructor.getBrightnessDGTLevel(brightness, deviceclone.getDeviceInformation().maximumBrightnessLevel); } AsfDgtPDU request = new AsfDgtPDU(); request.stx = AsfDgtConstants.ASF_STX; request.etx = AsfDgtConstants.ASF_ETX; request.address = address; //ASF MPP, send panel configuration, STR_OASF_MPP = 0x11 request.function = AsfDgtConstants.STR_OASF_MPP; request.information = new int[] { //Byte 1 command.timeout == -1 ? deviceclone.getDeviceConfiguration().timeout : command.timeout, //Byte 2 brightness, //Byte 3 address, //Byte 4 messagetime, //Byte 5 blinkOn, //Byte 6 blinkOff, //Bytes from 7 to 16: reserved /*7*/ 0, /*8*/ 0, /*9*/ 0, /*10*/ 0, /*11*/ 0, /*12*/ 0, /*13*/ 0, /*14*/ 0, /*15*/ 0, /*16*/ 0 }; byte[] send = request.createMessage(); return (send); } /** * BrightnessDGTLevel * * @param input * @param maximum * @return */ public static int getBrightnessDGTLevel(int input, int maximum) { // Input is a 0-100 value return ((int) Math.round(((float) input * (float) maximum) / 100f)); } /** * BrightnessClientLevel * * @param input * @param maximum * @param maximumVms * @return */ public static int getBrightnessClientLevel(int input, int maximum, int maximumVms) { // Input is a 0-7 value int result = (int) Math.round(((float) input * (float) maximum) / (float) maximumVms); if (result > 100) { result = 100; } return (result); } }