package art.servers.pvvserver.protocols.dgt.clv;
|
|
import art.library.model.devices.vms.pvv.Pvv;
|
import art.library.model.devices.vms.pvv.PvvStatus;
|
import art.library.model.devices.vms.pvv.information.PvvInformationConfigurationAddressSpeed;
|
import art.library.utils.common.ArrayUtils;
|
import art.library.utils.common.NumberUtils;
|
import java.util.List;
|
|
public class ClvDgtProtocolAnalyser
|
{
|
|
public ClvDgtProtocolAnalyser()
|
{
|
}
|
|
public static void analyseResponseReset(int[] information) throws Exception
|
{
|
checkAck(information);
|
}
|
|
public static void analyseResponseTimeout(int[] information) throws Exception
|
{
|
checkAck(information);
|
}
|
|
public static void analyseResponseMPP(Pvv deviceclone, int[] information) throws Exception
|
{
|
checkAck(information);
|
}
|
|
public static void analyseResponseMEP(Pvv deviceclone, int[] information) throws Exception
|
{
|
int state = information[0];
|
|
switch (state)
|
{
|
|
case ClvDgtConstants.CLV_OFF:
|
deviceclone.getDeviceStatus().state = PvvStatus.STATE_OFF;
|
break;
|
|
case ClvDgtConstants.CLV_FIX:
|
analyseFixState(deviceclone, information, 1);
|
break;
|
default:
|
throw new Exception("Invalid operation");
|
}
|
}
|
|
public static void analyseResponseEyA(Pvv deviceclone, int[] information) throws Exception
|
{
|
int status = information[0];
|
int brightness = information[1];
|
int technology = information[2];
|
int activeAlarms1 = information[3];
|
int activeAlarms2 = information[4];
|
int activeAlarms3 = information[5];
|
int activeAlarms4 = information[6];
|
|
if (brightness >= 0x30)
|
{
|
brightness = brightness - 0x30;
|
}
|
deviceclone.getDeviceStatus().brightnessLevel = ClvDgtProtocolConstructor.getBrightnessClientLevel(brightness, 100, deviceclone.getDeviceInformation().maximumBrightnessLevel);
|
|
if ((status & 0x01) != 0)
|
{
|
// AN
|
deviceclone.setAlarm("alarm_offline", false);
|
deviceclone.setAlarm("alarm_abnormal_state", false);
|
}
|
|
if ((status & 0x02) != 0)
|
{
|
// NC
|
deviceclone.setAlarm("alarm_offline", true);
|
deviceclone.setAlarm("alarm_abnormal_state", false);
|
}
|
|
if ((status & 0x04) != 0)
|
{
|
// EA
|
deviceclone.setAlarm("alarm_offline", false);
|
deviceclone.setAlarm("alarm_abnormal_state", true);
|
}
|
|
setAlarm(deviceclone, "alarm_open_door", ((activeAlarms1 & 0x01) != 0));
|
setAlarm(deviceclone, "alarm_open_door", ((activeAlarms1 & 0x01) != 0));
|
setAlarm(deviceclone, "alarm_configuration", ((activeAlarms1 & 0x02) != 0));
|
setAlarm(deviceclone, "alarm_terminal", ((activeAlarms1 & 0x04) != 0));
|
setAlarm(deviceclone, "alarm_ventilation_on", ((activeAlarms1 & 0x08) != 0));
|
setAlarm(deviceclone, "alarm_ventilation_failure", ((activeAlarms1 & 0x10) != 0));
|
setAlarm(deviceclone, "alarm_hardware_error", ((activeAlarms1 & 0x20) != 0));
|
setAlarm(deviceclone, "alarm_temperature_high", ((activeAlarms1 & 0x80) != 0));
|
|
setAlarm(deviceclone, "alarm_temperature_exceeded", ((activeAlarms2 & 0x01) != 0));
|
setAlarm(deviceclone, "alarm_mains_voltage_error", ((activeAlarms2 & 0x02) != 0));
|
setAlarm(deviceclone, "alarm_batteries_degraded", ((activeAlarms2 & 0x04) != 0));
|
setAlarm(deviceclone, "alarm_power_stopped", ((activeAlarms2 & 0x08) != 0));
|
setAlarm(deviceclone, "alarm_batteries_low", ((activeAlarms2 & 0x10) != 0));
|
setAlarm(deviceclone, "alarm_batteries_disconnected", ((activeAlarms2 & 0x20) != 0));
|
setAlarm(deviceclone, "alarm_heating_on", ((activeAlarms2 & 0x40) != 0));
|
setAlarm(deviceclone, "alarm_batteries_not_totally_charged", ((activeAlarms2 & 0x80) != 0));
|
|
setAlarm(deviceclone, "alarm_red_power_failure", ((activeAlarms3 & 0x01) != 0));
|
setAlarm(deviceclone, "alarm_green_power_failure", ((activeAlarms3 & 0x02) != 0));
|
setAlarm(deviceclone, "alarm_blue_power_failure", ((activeAlarms3 & 0x04) != 0));
|
setAlarm(deviceclone, "alarm_yellow_power_failure", ((activeAlarms3 & 0x08) != 0));
|
setAlarm(deviceclone, "alarm_white_power_failure", ((activeAlarms3 & 0x10) != 0));
|
setAlarm(deviceclone, "alarm_led_failure", ((activeAlarms3 & 0x20) != 0));
|
|
setAlarm(deviceclone, "alarm_power_failure", ((activeAlarms4 & 0x01) != 0));
|
setAlarm(deviceclone, "alarm_photocell_failure", ((activeAlarms4 & 0x08) != 0));
|
setAlarm(deviceclone, "alarm_power_contactor_failure", ((activeAlarms4 & 0x10) != 0));
|
setAlarm(deviceclone, "alarm_start_delay_condensation", ((activeAlarms4 & 0x20) != 0));
|
setAlarm(deviceclone, "alarm_humidity_sensor_failure", ((activeAlarms4 & 0x40) != 0));
|
}
|
|
|
private static void setAlarm (Pvv deviceclone, String alarm, boolean value)
|
{
|
if (isAlarmUsed(deviceclone.getDeviceInformation().alarms, alarm) == true)
|
deviceclone.setAlarm(alarm, value);
|
else
|
deviceclone.setAlarm(alarm, false);
|
}
|
|
|
private static boolean isAlarmUsed (List<String> alarms, String alarm)
|
{
|
if (alarms == null) return(true);
|
if (alarms.size() == 0) return(true);
|
|
for (String s : alarms)
|
{
|
if (s.equalsIgnoreCase(alarm) == true) return(true);
|
}
|
|
return(false);
|
}
|
|
|
public static void analyseResponseEP(Pvv deviceclone, int[] information) throws Exception
|
{
|
int state = information[0];
|
|
if (state == ClvDgtConstants.CLV_OFF)
|
{
|
deviceclone.getDeviceStatus().state = PvvStatus.STATE_OFF;
|
return;
|
}
|
|
switch (state)
|
{
|
case ClvDgtConstants.CLV_FIX:
|
analyseFixState(deviceclone, information, 1);
|
break;
|
case ClvDgtConstants.CLV_ALTERNANT:
|
case ClvDgtConstants.CLV_SEQUENCE:
|
throw new Exception("Operation not supported");
|
default:
|
throw new Exception("Invalid operation");
|
}
|
}
|
|
public static void analyseResponsePP(Pvv deviceclone, int[] information) throws Exception
|
{
|
int numberParameters = information[0];
|
int pointer = 1;
|
for (int i = 0; i < numberParameters; i++)
|
{
|
int parameterType = information[pointer++];
|
switch (parameterType)
|
{
|
case ClvDgtConstants.CLV_BRIGHTNESS_PARAMETER:
|
{
|
int brightnessMode = information[pointer++];
|
if (brightnessMode == 'A')
|
{
|
int brightnessModeAux = PvvStatus.BRIGHTNESS_MODE_AUTO;
|
} else
|
{
|
int brightnessModeAux = PvvStatus.BRIGHTNESS_MODE_MANUAL;
|
}
|
}
|
break;
|
|
case ClvDgtConstants.CLV_ALTERNANCE_TIME_PARAMETER:
|
{
|
int alternatingTime = information[pointer++];
|
}
|
break;
|
|
case ClvDgtConstants.CLV_BLINK_TIMES_PARAMETER:
|
{
|
float blinkOn = (float) ((float) information[pointer++] / 10f);
|
float blinkOff = (float) ((float) information[pointer++] / 10f);
|
}
|
break;
|
}
|
}
|
}
|
|
private static void checkAck(int[] information) throws Exception
|
{
|
if (ArrayUtils.isNullOrEmpty(information) || information[0] != ClvDgtConstants.CLV_ACK)
|
{
|
throw new Exception("No ack received");
|
}
|
}
|
|
private static void analyseFixState(Pvv deviceclone, int[] information, int index) throws Exception
|
{
|
NumberUtils.AsciiToInt(information[index++]); //Topology
|
int numberOfSubpanels = NumberUtils.AsciiToInt(information[index++]);
|
int memory = -1;
|
boolean blinking = false;
|
|
for (int i = 0; i < numberOfSubpanels; i++)
|
{
|
int subpanel = NumberUtils.AsciiToInt(information[index++]);
|
|
if (subpanel == 1)
|
{
|
int contentType = NumberUtils.AsciiToInt(information[index++]);
|
if (contentType == 1)
|
{
|
// Graphic memory content
|
memory = information[index++];
|
//Blinking
|
blinking = (information[index++] == (int) 'S');
|
} else
|
{
|
throw new Exception("Not valid content");
|
}
|
} else
|
{
|
throw new Exception("Not valid content");
|
}
|
}
|
|
PvvStatus pvvStatus = deviceclone.getDeviceStatus();
|
|
PvvInformationConfigurationAddressSpeed addressSpeed = deviceclone.getDeviceInformation().configuration.getByAddress(memory);
|
if (addressSpeed == null || addressSpeed.speed < 0)
|
{
|
throw new Exception("Invalid address speed");
|
}
|
|
pvvStatus.state = PvvStatus.STATE_ON;
|
pvvStatus.speed = addressSpeed.speed;
|
}
|
|
}
|