package art.servers.pvvserver.protocols.dgt.clv;
|
|
import art.library.model.devices.vms.general.VmsGeneral;
|
import art.library.model.devices.vms.pvv.Pvv;
|
import art.library.model.devices.vms.pvv.PvvCommands;
|
import art.library.model.devices.vms.pvv.information.PvvInformationConfigurationAddressSpeed;
|
import art.library.utils.common.ArrayUtils;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
public class ClvDgtProtocolConstructor
|
{
|
|
public ClvDgtProtocolConstructor()
|
{
|
}
|
|
/**
|
* 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
|
{
|
ClvDgtPDU requestAlarms = new ClvDgtPDU();
|
requestAlarms.stx = ClvDgtConstants.CLV_STX;
|
requestAlarms.etx = ClvDgtConstants.CLV_ETX;
|
requestAlarms.address = address;
|
requestAlarms.function = ClvDgtConstants.STR_PCLV_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
|
{
|
ClvDgtPDU requestConfiguration = new ClvDgtPDU();
|
requestConfiguration.stx = ClvDgtConstants.CLV_STX;
|
requestConfiguration.etx = ClvDgtConstants.CLV_ETX;
|
requestConfiguration.address = address;
|
requestConfiguration.function = ClvDgtConstants.STR_PCLV_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
|
{
|
ClvDgtPDU requestConfiguration = new ClvDgtPDU();
|
requestConfiguration.stx = ClvDgtConstants.CLV_STX;
|
requestConfiguration.etx = ClvDgtConstants.CLV_ETX;
|
requestConfiguration.address = address;
|
requestConfiguration.function = ClvDgtConstants.STR_PCLV_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
|
{
|
ClvDgtPDU orderReset = new ClvDgtPDU();
|
orderReset.stx = ClvDgtConstants.CLV_STX;
|
orderReset.etx = ClvDgtConstants.CLV_ETX;
|
orderReset.address = address;
|
//ASF reset, STR_OCLV_RES = 0x15
|
orderReset.function = ClvDgtConstants.STR_OCLV_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, PvvCommands command, Pvv deviceclone) throws Exception
|
{
|
ClvDgtPDU orderReset = new ClvDgtPDU();
|
orderReset.stx = ClvDgtConstants.CLV_STX;
|
orderReset.etx = ClvDgtConstants.CLV_ETX;
|
orderReset.address = address;
|
//ASF MEP, STR_OCLV_RES = 0x1A
|
orderReset.function = ClvDgtConstants.STR_OCLV_MEP;
|
orderReset.information = ArrayUtils.toIntArray(getBodyContentMessage(command.message.speed, deviceclone));
|
byte[] send = orderReset.createMessage();
|
return (send);
|
}
|
|
/**
|
* Get body content message of MEP
|
*
|
* @param commandSpeed
|
* @param deviceclone
|
* @return
|
*/
|
public static byte[] getBodyContentMessage(int commandSpeed, Pvv deviceclone)
|
{
|
byte[] result;
|
//Off
|
if (commandSpeed <= 0)
|
{
|
//AsfDgtConstants.ASF_OFF = '0' = 0x30
|
result = new byte[]
|
{
|
ClvDgtConstants.CLV_OFF
|
};
|
//Fix state
|
} else
|
{
|
List<Byte> informationList = new ArrayList<>();
|
informationList.add((byte) ClvDgtConstants.CLV_FIX);
|
informationList.add((byte) ClvDgtConstants.CLV_TOPOLOGY_1);
|
informationList.add((byte) '1');
|
|
List<Byte> lgraphicA = new ArrayList<>();
|
PvvInformationConfigurationAddressSpeed addressSpeed = deviceclone.getDeviceInformation().configuration.getBySpeed(commandSpeed);
|
lgraphicA.add((byte) '1');
|
lgraphicA.add((byte) '1');
|
lgraphicA.add((byte) addressSpeed.address);
|
lgraphicA.add((byte) 'N');
|
|
informationList.addAll(lgraphicA);
|
|
result = new byte[informationList.size()];
|
int index = 0;
|
for (byte elem : informationList)
|
{
|
result[index++] = elem;
|
}
|
}
|
return result;
|
}
|
|
|
/**
|
* ASF mpp order
|
*
|
* @param address
|
* @param command
|
* @param deviceclone
|
* @return
|
* @throws java.lang.Exception
|
*/
|
/*
|
public static byte[] mpp(int address, PvvCommands command, Pvv deviceclone) throws Exception
|
{
|
int brightness = -1; // Auto
|
if (deviceclone.getDeviceStatus().brightnessLevel != 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 = ClvDgtProtocolConstructor.getBrightnessDGTLevel(brightness, deviceclone.getDeviceInformation().maximumBrightnessLevel);
|
}
|
|
ClvDgtPDU request = new ClvDgtPDU();
|
request.stx = ClvDgtConstants.CLV_STX;
|
request.etx = ClvDgtConstants.CLV_ETX;
|
request.address = address;
|
//ASF MPP, send panel configuration, STR_OCLV_MPP = 0x11
|
request.function = ClvDgtConstants.STR_OCLV_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
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 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);
|
}
|
}
|