package art.servers.pvvserver.protocols.dgt;
|
|
import art.library.interop.serialization.Serialization;
|
import art.library.model.devices.vms.pvv.Pvv;
|
import art.library.model.devices.vms.pvv.PvvConfiguration;
|
import art.library.model.devices.vms.pvv.PvvStatus;
|
import art.library.model.devices.vms.pvv.information.PvvInformationConfigurationAddressSpeed;
|
import art.library.utils.common.NumberUtils;
|
import art.servers.PvvServer;
|
import art.servers.Shared;
|
|
public class PvvDgtProtocolAnalyser
|
{
|
|
public PvvDgtProtocolAnalyser()
|
{
|
}
|
|
public static void analyseResponseEyA(Pvv device, int[] information) throws Exception
|
{
|
// String s = device.getIdentifier() + " EyA < ";
|
// for (int i=0; i<information.length; i++)
|
// {
|
// s += String.format("%02X ", information[i]);
|
// }
|
// if (device.getIdentifier().indexOf("08-PVV-ED") == 0)
|
// {
|
// Shared.println("Analyser", s);
|
// }
|
|
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;
|
|
}
|
|
device.getDeviceStatus().brightnessLevel = PvvDgtProtocolConstructor.getBrightnessClientLevel(brightness, 100, device.getDeviceInformation().maximumBrightnessLevel);
|
|
if ((status & 0x01) != 0)
|
{
|
// AN
|
device.setAlarm("alarm_offline", false);
|
device.setAlarm("alarm_abnormal_state", false);
|
}
|
|
if ((status & 0x02) != 0)
|
{
|
// NC
|
device.setAlarm("alarm_offline", true);
|
device.setAlarm("alarm_abnormal_state", false);
|
}
|
|
if ((status & 0x04) != 0)
|
{
|
// EA
|
device.setAlarm("alarm_offline", false);
|
device.setAlarm("alarm_abnormal_state", true);
|
}
|
|
if (true) // PvvServer.MANAGE_ALARMS == true)
|
{
|
device.setAlarm("alarm_open_door", ((activeAlarms1 & 0x01) != 0));
|
device.setAlarm("alarm_configuration", ((activeAlarms1 & 0x02) != 0));
|
device.setAlarm("alarm_terminal", ((activeAlarms1 & 0x04) != 0));
|
device.setAlarm("alarm_ventilation_on", ((activeAlarms1 & 0x08) != 0));
|
device.setAlarm("alarm_ventilation_failure", ((activeAlarms1 & 0x10) != 0));
|
device.setAlarm("alarm_hardware_error", ((activeAlarms1 & 0x20) != 0));
|
device.setAlarm("alarm_temperature_high", ((activeAlarms1 & 0x80) != 0));
|
|
device.setAlarm("alarm_temperature_exceeded", ((activeAlarms2 & 0x01) != 0));
|
device.setAlarm("alarm_mains_voltage_error", ((activeAlarms2 & 0x02) != 0));
|
device.setAlarm("alarm_batteries_degraded", ((activeAlarms2 & 0x04) != 0));
|
device.setAlarm("alarm_power_stopped", ((activeAlarms2 & 0x08) != 0));
|
device.setAlarm("alarm_batteries_low", ((activeAlarms2 & 0x10) != 0));
|
device.setAlarm("alarm_batteries_disconnected", ((activeAlarms2 & 0x20) != 0));
|
device.setAlarm("alarm_heating_on", ((activeAlarms2 & 0x40) != 0));
|
device.setAlarm("alarm_batteries_not_totally_charged", ((activeAlarms2 & 0x80) != 0));
|
|
device.setAlarm("alarm_red_power_failure", ((activeAlarms3 & 0x01) != 0));
|
device.setAlarm("alarm_green_power_failure", ((activeAlarms3 & 0x02) != 0));
|
device.setAlarm("alarm_blue_power_failure", ((activeAlarms3 & 0x04) != 0));
|
device.setAlarm("alarm_yellow_power_failure", ((activeAlarms3 & 0x08) != 0));
|
device.setAlarm("alarm_white_power_failure", ((activeAlarms3 & 0x10) != 0));
|
device.setAlarm("alarm_led_failure", ((activeAlarms3 & 0x20) != 0));
|
|
device.setAlarm("alarm_power_failure", ((activeAlarms4 & 0x01) != 0));
|
device.setAlarm("alarm_photocell_failure", ((activeAlarms4 & 0x08) != 0));
|
device.setAlarm("alarm_power_contactor_failure", ((activeAlarms4 & 0x10) != 0));
|
device.setAlarm("alarm_start_delay_condensation", ((activeAlarms4 & 0x20) != 0));
|
device.setAlarm("alarm_humidity_sensor_failure", ((activeAlarms4 & 0x40) != 0));
|
}
|
else
|
{
|
device.setAlarm("alarm_open_door", false);
|
device.setAlarm("alarm_configuration", false);
|
device.setAlarm("alarm_terminal", false);
|
device.setAlarm("alarm_ventilation_on", false);
|
device.setAlarm("alarm_ventilation_failure", false);
|
device.setAlarm("alarm_hardware_error", false);
|
device.setAlarm("alarm_temperature_high", false);
|
|
device.setAlarm("alarm_temperature_exceeded", false);
|
device.setAlarm("alarm_mains_voltage_error", false);
|
device.setAlarm("alarm_batteries_degraded", false);
|
device.setAlarm("alarm_power_stopped", false);
|
device.setAlarm("alarm_batteries_low", false);
|
device.setAlarm("alarm_batteries_disconnected", false);
|
device.setAlarm("alarm_heating_on", false);
|
device.setAlarm("alarm_batteries_not_totally_charged", false);
|
|
device.setAlarm("alarm_red_power_failure", false);
|
device.setAlarm("alarm_green_power_failure", false);
|
device.setAlarm("alarm_blue_power_failure", false);
|
device.setAlarm("alarm_yellow_power_failure", false);
|
device.setAlarm("alarm_white_power_failure", false);
|
device.setAlarm("alarm_led_failure", ((activeAlarms3 & 0x20) != 0));
|
|
device.setAlarm("alarm_power_failure", false);
|
device.setAlarm("alarm_photocell_failure", false);
|
device.setAlarm("alarm_power_contactor_failure", false);
|
device.setAlarm("alarm_start_delay_condensation", false);
|
device.setAlarm("alarm_humidity_sensor_failure", false);
|
}
|
}
|
|
public static void analyseResponsePPDgtEru(Pvv device, int[] information) throws Exception
|
{
|
// String s = device.getIdentifier() + " PP < ";
|
// for (int i=0; i<information.length; i++)
|
// {
|
// s += String.format("%02X ", information[i]);
|
// }
|
// if (device.getIdentifier().indexOf("08-PVV-ED") == 0)
|
// {
|
// Shared.println("Analyser", s);
|
// }
|
// 08-PVV-ED-01 PP < 05 01 41 02 00 03 05 1E 05 00 06 00 00 00 00
|
|
device.configuration = new PvvConfiguration();
|
|
int numeroParametros = information[0];
|
int pointer = 1;
|
for (int i=0; i<numeroParametros; i++)
|
{
|
int tipoParametro = information[pointer++];
|
|
switch (tipoParametro)
|
{
|
case 1 :
|
{
|
int brightness = information[pointer++];
|
if (brightness == 'A')
|
{
|
device.getDeviceConfiguration().brightnessMode = PvvConfiguration.BRIGHTNESS_MODE_AUTO;
|
}
|
else
|
{
|
device.getDeviceConfiguration().brightnessMode = PvvConfiguration.BRIGHTNESS_MODE_MANUAL;
|
}
|
}
|
break;
|
|
case 2 :
|
{
|
int tiempoAlternancia = information[pointer++];
|
}
|
break;
|
|
case 3 :
|
{
|
device.getDeviceConfiguration().blinkOn = (float)((float)information[pointer++] / 10f);
|
device.getDeviceConfiguration().blinkOff = (float)((float)information[pointer++] / 10f);
|
}
|
break;
|
|
case 5 :
|
{
|
device.getDeviceConfiguration().timeout = information[pointer++];
|
}
|
break;
|
|
case 6 :
|
{
|
device.getDeviceConfiguration().flashPeriod = (float)((float)information[pointer++] / 10f);
|
device.getDeviceConfiguration().flashesxPeriod = information[pointer++];
|
device.getDeviceConfiguration().flashesOnPercentage = information[pointer++];
|
device.getDeviceConfiguration().flashStopTime = (float)((float)information[pointer++] / 10f);
|
}
|
break;
|
}
|
}
|
|
// if (device.getIdentifier().indexOf("08-PVV-ED") == 0)
|
// {
|
// Shared.println(device.getIdentifier(), Serialization.toPrettyString(device.getDeviceConfiguration()));
|
// }
|
}
|
|
public static void analyseResponsePP2(Pvv device, int[] information) throws Exception
|
{
|
device.configuration = new PvvConfiguration();
|
|
//Código 11h - Envío de configuración al PVV
|
//Byte 1: Tiempo máximo de interrupción de comunicaciones
|
device.getDeviceConfiguration().timeout = information[0];
|
|
//Byte 2: Control de luminosidad. (‘A’ = automático, de ‘0’ a ‘7’ manual)
|
//Si es auto se usa el calculado en Petición de luminosidad (43h), si es manual usamos el valor recibido
|
int brightness = information[1];
|
|
if (brightness == 'A')
|
{
|
device.getDeviceConfiguration().brightnessMode = PvvConfiguration.BRIGHTNESS_MODE_AUTO;
|
} else
|
{
|
device.getDeviceConfiguration().brightnessMode = PvvConfiguration.BRIGHTNESS_MODE_MANUAL;
|
}
|
|
//Byte 3: Dirección multipunto del panel
|
device.getDeviceConfiguration().address = information[2];
|
|
//Byte 4: no se usa information[3]
|
//Byte 5: Tiempo de ‘ON’ en intermitencia, décimas de segundo
|
device.getDeviceConfiguration().blinkOn = information[4];
|
|
//Byte 6: Tiempo de ‘OFF’ en intermitencia, décimas de segundo
|
device.getDeviceConfiguration().blinkOff = information[5];
|
|
//Byte 7: Tiempo del período de los flashes en décimas de segundo
|
device.getDeviceConfiguration().flashPeriod = information[6];
|
|
//Byte 8: Número de flashes por período
|
device.getDeviceConfiguration().flashesxPeriod = information[7];
|
|
//Byte 9: Porcentaje del tiempo de período con el flash a ON (0 a 100)
|
device.getDeviceConfiguration().flashesOnPercentage = information[8];
|
|
//Byte 10: Tiempo de parada (flashes OFF) entre periodos (décimas de segundo)
|
device.getDeviceConfiguration().flashStopTime = information[9];
|
|
//Bytes 11 - 14: Valores de corrección del brillo por degradación de los leds
|
//Bytes 15 - 16: Reservados para uso futuro
|
}
|
|
public static void analyseResponseEP(Pvv device, Pvv deviceclone, int[] information) throws Exception
|
{
|
|
int state = information[0];
|
|
if (state == PvvDgtConstants.PVV_OFF)
|
{
|
deviceclone.getDeviceStatus().state = PvvStatus.STATE_OFF;
|
} else if (state == PvvDgtConstants.PVV_FIX)
|
{
|
analyseFixState(device, deviceclone, information, 1);
|
} else
|
{
|
offline(device, deviceclone);
|
}
|
}
|
|
private static void analyseFixState(Pvv device, Pvv deviceclone, int[] information, int index) throws Exception
|
{
|
|
int pointer = index;
|
|
int topology = NumberUtils.AsciiToInt(information[pointer++]);
|
int numberOfSubpanels = NumberUtils.AsciiToInt(information[pointer++]);
|
int memory = -1;
|
boolean synchro = false;
|
boolean blinkingSpeed = false;
|
boolean blinkingCircle = false;
|
boolean blinkingFlashes = false;
|
boolean visibilitySpeed = true;
|
boolean visibilityCircle = true;
|
boolean visibilityFlashes = false;
|
|
for (int i = 0; i < numberOfSubpanels; i++)
|
{
|
int subpanel = NumberUtils.AsciiToInt(information[pointer++]);
|
|
if (subpanel == 1)
|
{
|
int contentType = NumberUtils.AsciiToInt(information[pointer++]);
|
|
switch (contentType)
|
{
|
|
/*
|
Parámetros para el tipo de contenido = Memoria (31h)
|
Número de Memoria 1 Byte hexadecimal
|
Intermitencia 1 Byte ‘S’ o ‘N’.
|
*/
|
case 1:
|
// Graphic memory content
|
memory = information[pointer++];
|
|
//Todos los blinking igual
|
blinkingSpeed = blinkingCircle = blinkingFlashes = (information[pointer++] == (int) 'S');
|
|
//Todos los visibility a true
|
visibilitySpeed = visibilityCircle = visibilityFlashes = true;
|
if (deviceclone.getDeviceInformation().model.equalsIgnoreCase("CLV") == true)
|
visibilityFlashes = false;
|
|
break;
|
/*
|
Parámetros para el tipo de contenido = Memoria Extendido (34h)
|
Número de Memoria 1 Byte hexadecimal
|
Activar al recibir sincro 1 Byte ‘S’ o ‘N’.
|
Intermitencia Velocidad 1 Byte ‘S’ o ‘N’.
|
Intermitencia Orla 1 Byte ‘S’ o ‘N’.
|
Intermitencia Flashes 1 Byte ‘S’ o ‘N’.
|
Visibilidad Velocidad 1 Byte ‘S’ o ‘N’.
|
Visibilidad Orla 1 Byte ‘S’ o ‘N’.
|
Visibilidad Flashes 1 Byte ‘S’ o ‘N’.
|
*/
|
case 4:
|
memory = information[pointer++];
|
|
synchro = (information[pointer++] == (int) 'S');
|
|
blinkingSpeed = (information[pointer++] == (int) 'S');
|
|
blinkingCircle = (information[pointer++] == (int) 'S');
|
|
blinkingFlashes = (information[pointer++] == (int) 'S');
|
|
visibilitySpeed = (information[pointer++] == (int) 'S');
|
|
visibilityCircle = (information[pointer++] == (int) 'S');
|
|
visibilityFlashes = (information[pointer++] == (int) 'S');
|
|
break;
|
|
default:
|
throw new Exception("Not valid content");
|
}
|
} else if (subpanel == 2)
|
{
|
throw new Exception("Not valid content");
|
} else if (subpanel == 3)
|
{
|
throw new Exception("Not valid content");
|
}
|
}
|
|
PvvStatus pvvStatus = deviceclone.getDeviceStatus();
|
PvvInformationConfigurationAddressSpeed addressSpeed = deviceclone.getDeviceInformation().configuration.getByAddress(memory);
|
|
if (addressSpeed == null)
|
{
|
offline(device, deviceclone);
|
return;
|
}
|
|
int speed = addressSpeed.speed;
|
if (speed < 0)
|
{
|
offline(device, deviceclone);
|
return;
|
}
|
|
pvvStatus.status = PvvStatus.STATUS_ONLINE;
|
pvvStatus.state = PvvStatus.STATE_ON;
|
pvvStatus.blinkingCircle = blinkingCircle;
|
pvvStatus.blinkingFlashes = blinkingFlashes;
|
pvvStatus.blinkingSpeed = blinkingSpeed;
|
pvvStatus.synchroActivation = synchro;
|
pvvStatus.speed = speed;
|
pvvStatus.visibilityCircle = visibilityCircle;
|
pvvStatus.visibilityFlashes = visibilityFlashes;
|
pvvStatus.visibilitySpeed = visibilitySpeed;
|
|
}
|
|
private static void offline(Pvv device, Pvv deviceclone) throws Exception
|
{
|
deviceclone.setAlarm("alarm_offline", System.currentTimeMillis());
|
Shared.model.updateDevice(device, deviceclone);
|
}
|
|
}
|