package art.servers.colorsserver.M.protocol;
|
|
|
import art.library.model.devices.Device;
|
import art.library.model.devices.DeviceStatus;
|
import art.library.model.devices.colors.controller.M.*;
|
import art.library.model.devices.colors.controller.M.tables.*;
|
import art.library.model.devices.colors.controller.M.realtime.M_ControllerRealtimeCountingDetector;
|
import art.library.model.devices.colors.controller.M.realtime.M_ControllerRealtimeGroup;
|
import art.library.model.devices.colors.controller.M.realtime.M_ControllerRealtimePresenceDetector;
|
import art.library.model.devices.colors.controller.M.realtime.M_ControllerRealtimeSubcontroller;
|
import art.library.model.devices.colors.controller.M.status.M_ControllerStatusGroup;
|
import art.library.model.devices.colors.controller.M.M_ControllerStatusSubcontroller;
|
import art.library.model.devices.colors.controller.M.configuration.M_Plan;
|
import art.library.model.devices.colors.controller.M.types.SPTP.M_SPTP_Demand;
|
import art.library.model.devices.etd.EtdStatus;
|
import art.library.model.devices.etd.status.EtdStatusLane;
|
import art.library.utils.common.TimeUtils;
|
import art.servers.ServerException;
|
import art.servers.colorsserver.Shared;
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
|
|
public class M_ProtocolAnalyser
|
{
|
public static final int STX = 0x02;
|
public static final int ETX = 0x03;
|
public static final int ACK = 0x06;
|
public static final int NACK = 0x15;
|
public static final int EOB12 = 0x0A;
|
public static final int EOB14 = 0x0C;
|
public static final int EOB15 = 0x0D;
|
|
|
public static void analyseGetBusDemandsResponse(String device, M_Message message, int controllerCode) throws ServerException, Exception
|
{
|
message.reset();
|
|
try
|
{
|
while (message.readByte() != STX);
|
}
|
catch (Exception e)
|
{
|
throw new ServerException(Shared.getMessage("Message not start with 0x02"));
|
}
|
|
int controller = message.readByte() & 0x7F;
|
if (controller != controllerCode)
|
{
|
throw new ServerException(Shared.getMessage("Message does not correspond to controller"));
|
}
|
|
int function = message.readByte() & 0x7F;
|
if (function != M_ProtocolWriter.M_BUS_DETECTIONS_QUERY)
|
{
|
return;
|
}
|
|
while (message.eof() == false)
|
{
|
M_SPTP_Demand demand = new M_SPTP_Demand();
|
demand.device = device;
|
demand.line = message.readByte() & 0x7F;
|
demand.trackAngle = ((message.readByte() & 0x7F) << 7) + (message.readByte() & 0x7F);
|
demand.vehicleIdentifier = "" + (((message.readByte() & 0x7F) << 7) + (message.readByte() & 0x7F));
|
demand.delay = ((message.readByte() & 0x7F) << 7) + (message.readByte() & 0x7F);
|
int dia = message.readByte() & 0x7F;
|
int mes = message.readByte() & 0x7F;
|
int anyo = (message.readByte() & 0x7F) + 2000;
|
int hora = message.readByte() & 0x7F;
|
int min = message.readByte() & 0x7F;
|
int sec = message.readByte() & 0x7F;
|
demand.timestampActivation = TimeUtils.toTimestamp(dia, mes, anyo, hora, min, sec);
|
dia = message.readByte() & 0x7F;
|
mes = message.readByte() & 0x7F;
|
anyo = (message.readByte() & 0x7F) + 2000;
|
hora = message.readByte() & 0x7F;
|
min = message.readByte() & 0x7F;
|
sec = message.readByte() & 0x7F;
|
demand.timestampDeactivation = TimeUtils.toTimestamp(dia, mes, anyo, hora, min, sec);
|
int granted = message.readByte() & 0x7F;
|
int discardReason = message.readByte() & 0x7F;
|
demand.granted = (granted == 1);
|
|
if ((discardReason & 0x01) != 0) demand.discardReason = M_SPTP_Demand.SPTP_BUS_DEMAND_DISCARD_REASON_INSUFFICIENT_DELAY;
|
if ((discardReason & 0x02) != 0) demand.discardReason = M_SPTP_Demand.SPTP_BUS_DEMAND_DISCARD_REASON_NOT_PREFERRED_LINE;
|
if ((discardReason & 0x04) != 0) demand.discardReason = M_SPTP_Demand.SPTP_BUS_DEMAND_DISCARD_REASON_NOT_WINDOW_TIME;
|
if ((discardReason & 0x08) != 0) demand.discardReason = M_SPTP_Demand.SPTP_BUS_DEMAND_DISCARD_REASON_ATTENDING_OTHER_DEMANDS;
|
if ((discardReason & 0x10) != 0) demand.discardReason = M_SPTP_Demand.SPTP_BUS_DEMAND_DISCARD_REASON_IN_WAITING_TIME;
|
|
message.readByte(); // EOB
|
|
try
|
{
|
Shared.println("Analyser", "Demand: Act: " + Device.getDate(demand.timestampActivation) + ", Desact: " + Device.getDate(demand.timestampDeactivation));
|
// Insert in database
|
Shared.controllerDatabase.historical_addObject(demand);
|
}
|
catch (Exception e)
|
{
|
Shared.printstack("Analyse get bus demands response", e);
|
}
|
}
|
}
|
|
|
public static boolean isReadTableMessage(M_Controller controllerM, M_Message message, int controller, int tableCode) throws Exception
|
{
|
message.reset();
|
|
try
|
{
|
while (message.readByte() != STX);
|
}
|
catch (Exception e)
|
{
|
return(false);
|
}
|
|
int controllerReaded = message.readByte() & 0x7F;
|
if (controllerReaded != M_ProtocolWriter.M_READ_TABLE_FULL)
|
{
|
int function = message.readByte() & 0x7F;
|
if ((controller == controllerReaded) && (function == M_ProtocolWriter.M_READ_TABLE_FULL))
|
{
|
int tableCodeRead = message.readByte() & 0x7F;
|
if (tableCode == tableCodeRead)
|
return(true);
|
}
|
|
if ((controller == controllerReaded) && (function == M_ProtocolWriter.M_READ_TABLE_PARTIAL))
|
{
|
int blockNumber = message.readByte() & 0x7F;
|
int tableCodeRead = message.readByte() & 0x7F;
|
if (tableCode == tableCodeRead)
|
return(true);
|
}
|
}
|
else
|
{
|
return(true);
|
}
|
|
return(false);
|
}
|
|
|
public static boolean isReadPartialTableMessage(M_Message message, int controller, int tableCode) throws Exception
|
{
|
message.reset();
|
|
try
|
{
|
while (message.readByte() != STX);
|
}
|
catch (Exception e)
|
{
|
return(false);
|
}
|
|
int controllerReaded = message.readByte() & 0x7F;
|
int function = message.readByte() & 0x7F;
|
if ((controller == controllerReaded) && (function == M_ProtocolWriter.M_READ_TABLE_PARTIAL))
|
{
|
int blockNumber = message.readByte() & 0x7F;
|
int tableCodeRead = message.readByte() & 0x7F;
|
if (tableCode == tableCodeRead)
|
return(true);
|
}
|
|
return(false);
|
}
|
|
|
public static boolean isACKMessage(M_Message message) throws Exception
|
{
|
return (message.readByte() == ACK);
|
}
|
|
|
public static boolean isNACKMessage(M_Message message) throws Exception
|
{
|
return (message.readByte() == NACK);
|
}
|
|
|
public static boolean isStartRecordingResponse(M_Message message) throws Exception
|
{
|
if (message.readByte() != STX)
|
{
|
return(false);
|
}
|
|
int controller = message.readByte();
|
int function = message.readByte() & 0x7F;
|
if (function == M_ProtocolWriter.M_START_RECORDING_RESPONSE)
|
return(true);
|
|
return(false);
|
}
|
|
|
public static boolean isEndRecordingResponse(M_Message message) throws Exception
|
{
|
if (message.readByte() != STX)
|
{
|
return(false);
|
}
|
|
int controller = message.readByte();
|
int function = message.readByte() & 0x7F;
|
if (function == M_ProtocolWriter.M_END_RECORDING_RESPONSE)
|
return(true);
|
|
return(false);
|
}
|
|
|
public static void analyseCurrentPlanResponse(M_ControllerStatusSubcontroller m_controllerStatusSubcontroller, M_ControllerRealtimeSubcontroller m_controllerRealtimeSubcontroller, M_Message message, int subcontroller) throws ServerException, Exception
|
{
|
message.reset();
|
|
try
|
{
|
while (message.readByte() != STX);
|
}
|
catch (Exception e)
|
{
|
throw new ServerException(Shared.getMessage("Message not start with 0x02"));
|
}
|
|
int controller = message.readByte() & 0x7F;
|
if (controller != subcontroller)
|
{
|
throw new ServerException(Shared.getMessage("Message does not correspond to controller"));
|
}
|
|
int function = message.readByte() & 0x7F;
|
if (function != M_ProtocolWriter.M_CURRENT_PLAN_QUERY)
|
{
|
return;
|
}
|
|
|
if (m_controllerStatusSubcontroller.colorsMode != M_ControllerStatusSubcontroller.COLORS_COLORS)
|
{
|
m_controllerRealtimeSubcontroller.cycle = 0;
|
m_controllerRealtimeSubcontroller.adjust = 0;
|
m_controllerRealtimeSubcontroller.phase = 0;
|
m_controllerRealtimeSubcontroller.startTimestamp = 0;
|
m_controllerStatusSubcontroller.plan = m_controllerRealtimeSubcontroller.plan;
|
}
|
else
|
{
|
try
|
{
|
SimpleDateFormat sdh = new SimpleDateFormat("HH:mm:ss");
|
|
m_controllerRealtimeSubcontroller.plan = message.readByte() & 0x7F;
|
int hour = message.readByte() & 0x7F;
|
int minute = message.readByte() & 0x7F;
|
int second = message.readByte() & 0x7F;
|
m_controllerRealtimeSubcontroller.phase = message.readByte() & 0x7F;
|
m_controllerRealtimeSubcontroller.cycle = ((message.readByte() & 0x7F) << 7) + (message.readByte() & 0x7F);
|
m_controllerRealtimeSubcontroller.adjust = (byte)(message.readByte() & 0x7F);
|
String time = String.format("%02d:%02d:%02d", hour, minute, second);
|
m_controllerRealtimeSubcontroller.startTimestamp = sdh.parse(time).getTime();
|
|
m_controllerStatusSubcontroller.plan = m_controllerRealtimeSubcontroller.plan;
|
}
|
catch (Exception e)
|
{
|
|
}
|
}
|
}
|
|
|
public static int analyseAlarmsResponse(M_Controller m_controller, M_Message message, int controllerCode) throws ServerException, Exception
|
{
|
message.reset();
|
|
try
|
{
|
while (message.readByte() != STX);
|
}
|
catch (Exception e)
|
{
|
throw new ServerException(Shared.getMessage("Message not start with 0x02"));
|
}
|
|
int controller = message.readByte() & 0x7F;
|
if (controller != controllerCode)
|
{
|
throw new ServerException(Shared.getMessage("Message does not correspond to controller"));
|
}
|
|
int function = message.readByte() & 0x7F;
|
if (function != M_ProtocolWriter.M_ALARMS_QUERY)
|
{
|
return(0);
|
}
|
|
int alarms1 = message.readByte() & 0x7F;
|
int alarms2 = message.readByte() & 0x7F;
|
int alarms3 = message.readByte() & 0x7F;
|
int alarms4 = message.readByte() & 0x7F;
|
|
m_controller.setAlarm("alarm_incompatibility", ((alarms1 & 0x01) != 0), System.currentTimeMillis());
|
m_controller.setAlarm("alarm_sincronization", ((alarms1 & 0x02) != 0), System.currentTimeMillis());
|
m_controller.setAlarm("alarm_transmission", ((alarms1 & 0x04) != 0), System.currentTimeMillis());
|
m_controller.setAlarm("alarm_damaged_group", ((alarms1 & 0x08) != 0), System.currentTimeMillis());
|
m_controller.setAlarm("alarm_blown_lamp", ((alarms1 & 0x10) != 0), System.currentTimeMillis());
|
m_controller.setAlarm("alarm_damage_detector", ((alarms1 & 0x20) != 0), System.currentTimeMillis());
|
m_controller.setAlarm("alarm_open_door", ((alarms1 & 0x40) != 0), System.currentTimeMillis());
|
|
m_controller.setAlarm("alarm_manual_control", ((alarms2 & 0x01) != 0), System.currentTimeMillis());
|
|
if (m_controller.getDeviceInformation().type == M_ControllerInformation.TYPE_RTAC)
|
{
|
m_controller.setAlarm("alarm_autotest", false);
|
m_controller.setAlarm("alarm_reset", false);
|
}
|
else
|
{
|
m_controller.setAlarm("alarm_autotest", ((alarms2 & 0x02) != 0), System.currentTimeMillis());
|
m_controller.setAlarm("alarm_reset", ((alarms2 & 0x04) != 0), System.currentTimeMillis());
|
}
|
|
m_controller.setAlarm("alarm_clock", ((alarms2 & 0x08) != 0), System.currentTimeMillis());
|
|
if (m_controller.getDeviceInformation().type == M_ControllerInformation.TYPE_RTAC)
|
{
|
m_controller.setAlarm("alarm_temperature", false);
|
}
|
else
|
{
|
m_controller.setAlarm("alarm_temperature", ((alarms2 & 0x10) != 0), System.currentTimeMillis());
|
}
|
|
m_controller.setAlarm("alarm_data_checksum", ((alarms2 & 0x20) != 0), System.currentTimeMillis());
|
m_controller.setAlarm("alarm_voltage", ((alarms2 & 0x40) != 0), System.currentTimeMillis());
|
|
m_controller.setAlarm("alarm_local_recording", ((alarms3 & 0x01) != 0), System.currentTimeMillis());
|
m_controller.setAlarm("alarm_remote_recording", ((alarms3 & 0x02) != 0), System.currentTimeMillis());
|
m_controller.setAlarm("alarm_incorrect_access", ((alarms3 & 0x04) != 0), System.currentTimeMillis());
|
|
m_controller.setAlarm("alarm_programmed_1", ((alarms4 & 0x01) != 0), System.currentTimeMillis());
|
m_controller.setAlarm("alarm_programmed_2", ((alarms4 & 0x02) != 0), System.currentTimeMillis());
|
m_controller.setAlarm("alarm_programmed_3", ((alarms4 & 0x04) != 0), System.currentTimeMillis());
|
m_controller.setAlarm("alarm_programmed_4", ((alarms4 & 0x08) != 0), System.currentTimeMillis());
|
m_controller.setAlarm("alarm_programmed_5", ((alarms4 & 0x10) != 0), System.currentTimeMillis());
|
m_controller.setAlarm("alarm_programmed_6", ((alarms4 & 0x20) != 0), System.currentTimeMillis());
|
m_controller.setAlarm("alarm_programmed_7", ((alarms4 & 0x40) != 0), System.currentTimeMillis());
|
|
int result = 0;
|
if ((alarms1 & 0x01) != 0) result += 0x04;
|
if ((alarms1 & 0x08) != 0) result += 0x02;
|
if ((alarms1 & 0x10) != 0) result += 0x01;
|
|
return(result);
|
}
|
|
|
public static void analyseBlownLampsAlarmsResponse(M_Controller m_controller, M_Message message, int controllerCode) throws ServerException, Exception
|
{
|
message.reset();
|
|
try
|
{
|
while (message.readByte() != STX);
|
}
|
catch (Exception e)
|
{
|
throw new ServerException(Shared.getMessage("Message not start with 0x02"));
|
}
|
|
int controller = message.readByte() & 0x7F;
|
if (controller != controllerCode)
|
{
|
throw new ServerException(Shared.getMessage("Message does not correspond to controller"));
|
}
|
|
int function = message.readByte() & 0x7F;
|
if (function != M_ProtocolWriter.M_BLOWN_LAMPS_ALARMS_QUERY)
|
{
|
return;
|
}
|
|
HashMap<Integer, Integer> hgroupsAlarms = new HashMap<Integer, Integer>();
|
while (message.eof() == false)
|
{
|
int group = message.readByte() & 0x7F;
|
int lampAlarms = message.readByte() & 0x7F;
|
|
boolean found = false;
|
for (M_ControllerStatusGroup statusGroup : m_controller.getDeviceStatus().lgroup)
|
{
|
if (statusGroup.number == group)
|
{
|
found = true;
|
hgroupsAlarms.put(new Integer(group), new Integer(group));
|
|
if ((lampAlarms & 0x01) != 0) statusGroup.redOutputBlown = M_ControllerStatusGroup.YES;
|
else statusGroup.redOutputBlown = M_ControllerStatusGroup.NO;
|
if ((lampAlarms & 0x02) != 0) statusGroup.yellowOutputBlown = M_ControllerStatusGroup.YES;
|
else statusGroup.yellowOutputBlown = M_ControllerStatusGroup.NO;
|
if ((lampAlarms & 0x04) != 0) statusGroup.greenOutputBlown = M_ControllerStatusGroup.YES;
|
else statusGroup.greenOutputBlown = M_ControllerStatusGroup.NO;
|
}
|
}
|
|
if (found == false)
|
{
|
M_ControllerStatusGroup statusGroup = new M_ControllerStatusGroup();
|
statusGroup.number = group;
|
hgroupsAlarms.put(new Integer(group), new Integer(group));
|
|
if ((lampAlarms & 0x01) != 0) statusGroup.redOutputBlown = M_ControllerStatusGroup.YES;
|
else statusGroup.redOutputBlown = M_ControllerStatusGroup.NO;
|
if ((lampAlarms & 0x02) != 0) statusGroup.yellowOutputBlown = M_ControllerStatusGroup.YES;
|
else statusGroup.yellowOutputBlown = M_ControllerStatusGroup.NO;
|
if ((lampAlarms & 0x04) != 0) statusGroup.greenOutputBlown = M_ControllerStatusGroup.YES;
|
else statusGroup.greenOutputBlown = M_ControllerStatusGroup.NO;
|
|
m_controller.getDeviceStatus().lgroup.add(statusGroup);
|
}
|
}
|
|
for (M_ControllerStatusGroup statusGroup : m_controller.getDeviceStatus().lgroup)
|
{
|
if (hgroupsAlarms.containsKey(new Integer(statusGroup.number)) == false)
|
{
|
statusGroup.redOutputBlown = M_ControllerStatusGroup.NO;
|
statusGroup.yellowOutputBlown = M_ControllerStatusGroup.NO;
|
statusGroup.greenOutputBlown = M_ControllerStatusGroup.NO;
|
}
|
}
|
}
|
|
|
public static void analyseDamagedGroupAlarmsResponse(M_Controller m_controller, M_Message message, int controllerCode) throws ServerException, Exception
|
{
|
message.reset();
|
|
try
|
{
|
while (message.readByte() != STX);
|
}
|
catch (Exception e)
|
{
|
throw new ServerException(Shared.getMessage("Message not start with 0x02"));
|
}
|
|
int controller = message.readByte() & 0x7F;
|
if (controller != controllerCode)
|
{
|
throw new ServerException(Shared.getMessage("Message does not correspond to controller"));
|
}
|
|
int function = message.readByte() & 0x7F;
|
if (function != M_ProtocolWriter.M_DAMAGED_GROUP_ALARMS_QUERY)
|
{
|
return;
|
}
|
|
HashMap<Integer, Integer> hgroupsAlarms = new HashMap<Integer, Integer>();
|
while (message.eof() == false)
|
{
|
int group = message.readByte() & 0x7F;
|
int outputAlarms = message.readByte() & 0x7F;
|
|
boolean found = false;
|
for (M_ControllerStatusGroup statusGroup : m_controller.getDeviceStatus().lgroup)
|
{
|
if (statusGroup.number == group)
|
{
|
found = true;
|
hgroupsAlarms.put(new Integer(group), new Integer(group));
|
|
if ((outputAlarms & 0x01) != 0) statusGroup.redOutputDamaged = M_ControllerStatusGroup.YES;
|
else statusGroup.redOutputDamaged = M_ControllerStatusGroup.NO;
|
if ((outputAlarms & 0x02) != 0) statusGroup.yellowOutputDamaged = M_ControllerStatusGroup.YES;
|
else statusGroup.yellowOutputDamaged = M_ControllerStatusGroup.NO;
|
if ((outputAlarms & 0x04) != 0) statusGroup.greenOutputDamaged = M_ControllerStatusGroup.YES;
|
else statusGroup.greenOutputDamaged = M_ControllerStatusGroup.NO;
|
}
|
}
|
|
if (found == false)
|
{
|
M_ControllerStatusGroup statusGroup = new M_ControllerStatusGroup();
|
statusGroup.number = group;
|
hgroupsAlarms.put(new Integer(group), new Integer(group));
|
|
if ((outputAlarms & 0x01) != 0) statusGroup.redOutputDamaged = M_ControllerStatusGroup.YES;
|
else statusGroup.redOutputDamaged = M_ControllerStatusGroup.NO;
|
if ((outputAlarms & 0x02) != 0) statusGroup.yellowOutputDamaged = M_ControllerStatusGroup.YES;
|
else statusGroup.yellowOutputDamaged = M_ControllerStatusGroup.NO;
|
if ((outputAlarms & 0x04) != 0) statusGroup.greenOutputDamaged = M_ControllerStatusGroup.YES;
|
else statusGroup.greenOutputDamaged = M_ControllerStatusGroup.NO;
|
|
m_controller.getDeviceStatus().lgroup.add(statusGroup);
|
}
|
}
|
|
for (M_ControllerStatusGroup statusGroup : m_controller.getDeviceStatus().lgroup)
|
{
|
if (hgroupsAlarms.containsKey(new Integer(statusGroup.number)) == false)
|
{
|
statusGroup.redOutputDamaged = M_ControllerStatusGroup.NO;
|
statusGroup.yellowOutputDamaged = M_ControllerStatusGroup.NO;
|
statusGroup.greenOutputDamaged = M_ControllerStatusGroup.NO;
|
}
|
}
|
}
|
|
|
public static void analyseIncompatibilityAlarmsResponse(M_Controller m_controller, M_Message message, int controllerCode) throws ServerException, Exception
|
{
|
message.reset();
|
|
try
|
{
|
while (message.readByte() != STX);
|
}
|
catch (Exception e)
|
{
|
throw new ServerException(Shared.getMessage("Message not start with 0x02"));
|
}
|
|
int controller = message.readByte() & 0x7F;
|
if (controller != controllerCode)
|
{
|
throw new ServerException(Shared.getMessage("Message does not correspond to controller"));
|
}
|
|
int function = message.readByte() & 0x7F;
|
if (function != M_ProtocolWriter.M_INCOMPATIBILITY_ALARMS_QUERY)
|
{
|
return;
|
}
|
|
HashMap<Integer, M_ControllerStatusGroup> hgroupsIncompatibilities = new HashMap<Integer, M_ControllerStatusGroup>();
|
while (message.eof() == false)
|
{
|
int group = message.readByte() & 0x7F;
|
int groupIncompatible = message.readByte() & 0x7F;
|
M_ControllerStatusGroup groupIncompatibility = hgroupsIncompatibilities.get(new Integer(group));
|
if (groupIncompatibility != null)
|
{
|
groupIncompatibility.lincompatibility.add(new Integer(groupIncompatible));
|
}
|
else
|
{
|
boolean found = false;
|
for (M_ControllerStatusGroup statusGroup : m_controller.getDeviceStatus().lgroup)
|
{
|
if (statusGroup.number == group)
|
{
|
found = true;
|
hgroupsIncompatibilities.put(new Integer(group), statusGroup);
|
statusGroup.lincompatibility.clear();
|
statusGroup.lincompatibility.add(new Integer(groupIncompatible));
|
}
|
}
|
|
if (found == false)
|
{
|
M_ControllerStatusGroup statusGroup = new M_ControllerStatusGroup();
|
statusGroup.number = group;
|
hgroupsIncompatibilities.put(new Integer(group), statusGroup);
|
statusGroup.lincompatibility.clear();
|
statusGroup.lincompatibility.add(new Integer(groupIncompatible));
|
|
m_controller.getDeviceStatus().lgroup.add(statusGroup);
|
}
|
}
|
}
|
|
for (M_ControllerStatusGroup statusGroup : m_controller.getDeviceStatus().lgroup)
|
{
|
if (hgroupsIncompatibilities.containsKey(new Integer(statusGroup.number)) == false)
|
{
|
statusGroup.lincompatibility.clear();
|
}
|
}
|
}
|
|
|
public static long[] analyseCurrentTimeResponse(M_Controller m_controller, M_Message message, int controllerCode) throws ServerException, Exception
|
{
|
long[] result = new long[2];
|
|
message.reset();
|
|
try
|
{
|
while (message.readByte() != STX);
|
}
|
catch (Exception e)
|
{
|
throw new ServerException(Shared.getMessage("Message not start with 0x02"));
|
}
|
|
int controller = message.readByte() & 0x7F;
|
if (controller != controllerCode)
|
{
|
throw new ServerException(Shared.getMessage("Message does not correspond to controller"));
|
}
|
|
int function = message.readByte() & 0x7F;
|
if (function != M_ProtocolWriter.M_CURRENT_TIME_QUERY)
|
{
|
throw new ServerException("Incorrect function code");
|
}
|
|
try
|
{
|
result[1] = message.readByte() & 0x7F;
|
int hour = message.readByte() & 0x7F;
|
int minute = message.readByte() & 0x7F;
|
int second = message.readByte() & 0x7F;
|
int day = message.readByte() & 0x7F;
|
int month = message.readByte() & 0x7F;
|
int year = (message.readByte() & 0x7F) + 2000;
|
|
SimpleDateFormat sdfh = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
String stime = String.format("%02d/%02d/%04d %02d:%02d:%02d", day, month, year, hour, minute, second);
|
result[0] = sdfh.parse(stime).getTime();
|
try{m_controller.getDeviceRealtime().controllerDateTime = result[0];} catch (Exception e){};
|
return(result);
|
}
|
catch (Exception e)
|
{
|
throw e;
|
// result[0] = m_controller.getDeviceRealtime().controllerDateTime;
|
// return(result);
|
}
|
}
|
|
|
public static void analyseCurrentStatusGroupsResponse(M_Controller m_controller, M_Message message, int controllerCode) throws ServerException, Exception
|
{
|
message.reset();
|
|
try
|
{
|
while (message.readByte() != STX);
|
}
|
catch (Exception e)
|
{
|
throw new ServerException(Shared.getMessage("Message not start with 0x02"));
|
}
|
|
int controller = message.readByte() & 0x7F;
|
if (controller != controllerCode)
|
{
|
throw new ServerException(Shared.getMessage("Message does not correspond to controller"));
|
}
|
|
int function = message.readByte() & 0x7F;
|
if (function != M_ProtocolWriter.M_CURRENT_STATUS_GROUPS_QUERY)
|
{
|
return;
|
}
|
|
try
|
{
|
int group = 1;
|
|
while (message.eof() == false)
|
{
|
// 1BGGYYRR
|
// B --> 0 Normal flashing, Tilt flashing
|
// GG YY RR --> 0 Off, 1 On, 2 Flashing fast, 3 Flashing slow
|
int status = message.readByte() & 0x7F;
|
boolean found = false;
|
for (M_ControllerRealtimeGroup realtimeGroup : m_controller.getDeviceRealtime().lgroup)
|
{
|
if (realtimeGroup.number == group)
|
{
|
found = true;
|
if ((status & 0x40) != 0) realtimeGroup.tilt = M_ControllerRealtimeGroup.YES;
|
else realtimeGroup.tilt = M_ControllerRealtimeGroup.NO;
|
realtimeGroup.redOutputStatus = (byte)(status & 0x03);
|
realtimeGroup.yellowOutputStatus = (byte)((status >> 2) & 0x03);
|
realtimeGroup.greenOutputStatus = (byte)((status >> 4) & 0x03);
|
}
|
}
|
|
|
if (found == false)
|
{
|
M_ControllerRealtimeGroup statusGroup = new M_ControllerRealtimeGroup();
|
statusGroup.number = group;
|
if ((status & 0x40) != 0) statusGroup.tilt = M_ControllerRealtimeGroup.YES;
|
else statusGroup.tilt = M_ControllerRealtimeGroup.NO;
|
statusGroup.redOutputStatus = (byte)(status & 0x03);
|
statusGroup.yellowOutputStatus = (byte)((status >> 2) & 0x03);
|
statusGroup.greenOutputStatus = (byte)((status >> 4) & 0x03);
|
m_controller.getDeviceRealtime().lgroup.add(statusGroup);
|
}
|
|
group++;
|
}
|
}
|
catch (Exception e)
|
{
|
|
}
|
}
|
|
|
public static void analyseCurrentStateResponse(M_ControllerStatusSubcontroller m_controllerStatusSubcontroller, M_Message message, int subcontroller) throws ServerException, Exception
|
{
|
message.reset();
|
|
try
|
{
|
while (message.readByte() != STX);
|
}
|
catch (Exception e)
|
{
|
throw new ServerException(Shared.getMessage("Message not start with 0x02"));
|
}
|
|
int controller = message.readByte() & 0x7F;
|
if (controller != subcontroller)
|
{
|
throw new ServerException(Shared.getMessage("Message does not correspond to controller"));
|
}
|
|
int function = message.readByte() & 0x7F;
|
if (function != M_ProtocolWriter.M_CURRENT_SUBCONTROLLER_STATE_QUERY)
|
{
|
return;
|
}
|
|
m_controllerStatusSubcontroller.colorsMode = message.readByte() & 0x7F;
|
int controlMode = message.readByte() & 0x7F;
|
int coordination = message.readByte() & 0x7F;
|
int operation = message.readByte() & 0x7F;
|
|
if ((controlMode & 0x01) == 0) m_controllerStatusSubcontroller.planSelection = M_ControllerStatusSubcontroller.PLANSELECTION_TIMETABLE;
|
if ((controlMode & 0x01) != 0) m_controllerStatusSubcontroller.planSelection = M_ControllerStatusSubcontroller.PLANSELECTION_EXTERNAL_PLANS;
|
if ((controlMode & 0x02) != 0) m_controllerStatusSubcontroller.planSelection = M_ControllerStatusSubcontroller.PLANSELECTION_ICF;
|
if ((controlMode & 0x04) != 0) m_controllerStatusSubcontroller.planSelection = M_ControllerStatusSubcontroller.PLANSELECTION_COMPUTER;
|
if (((controlMode & 0x08) != 0))
|
m_controllerStatusSubcontroller.planSelectionComputer = M_ControllerStatusSubcontroller.PLANSELECTION_COMPUTER_ADAPTATIVE;
|
else
|
{
|
if (m_controllerStatusSubcontroller.planSelection != M_ControllerStatusSubcontroller.PLANSELECTION_COMPUTER)
|
m_controllerStatusSubcontroller.planSelectionComputer = M_ControllerStatusSubcontroller.UNKNOWN;
|
else
|
m_controllerStatusSubcontroller.planSelectionComputer = M_ControllerStatusSubcontroller.PLANSELECTION_COMPUTER_PLAN_SELECTION;
|
}
|
|
if ((controlMode & 0x10) != 0)
|
m_controllerStatusSubcontroller.adaptativeDetectors = M_ControllerStatusSubcontroller.YES;
|
else
|
m_controllerStatusSubcontroller.adaptativeDetectors = M_ControllerStatusSubcontroller.NO;
|
|
if ((coordination & 0x01) == 0) m_controllerStatusSubcontroller.coordinationMode = M_ControllerStatusSubcontroller.COORDINATION_EXTERNAL;
|
if ((coordination & 0x01) != 0) m_controllerStatusSubcontroller.coordinationMode = M_ControllerStatusSubcontroller.COORDINATION_INTERNAL_CLOCK;
|
if ((coordination & 0x02) != 0) m_controllerStatusSubcontroller.coordinationMode = M_ControllerStatusSubcontroller.COORDINATION_COMPUTER;
|
if ((coordination & 0x04) != 0) m_controllerStatusSubcontroller.centralizedMode = M_ControllerStatusSubcontroller.YES;
|
else m_controllerStatusSubcontroller.centralizedMode = M_ControllerStatusSubcontroller.NO;
|
|
if (m_controllerStatusSubcontroller.userControlManual == M_ControllerCommands.CONDITION_YES)
|
{
|
if ((coordination & 0x08) != 0) m_controllerStatusSubcontroller.localControl = M_ControllerStatusSubcontroller.YES;
|
else m_controllerStatusSubcontroller.localControl = M_ControllerStatusSubcontroller.NO;
|
}
|
|
if ((coordination & 0x10) != 0) m_controllerStatusSubcontroller.controlComputerDirectGroups = M_ControllerStatusSubcontroller.YES;
|
else m_controllerStatusSubcontroller.controlComputerDirectGroups = M_ControllerStatusSubcontroller.NO;
|
|
if ((operation & 0x01) == 0) m_controllerStatusSubcontroller.operationMode = M_ControllerStatusSubcontroller.OPERATIONMODE_FIXED;
|
if ((operation & 0x01) != 0) m_controllerStatusSubcontroller.operationMode = M_ControllerStatusSubcontroller.OPERATIONMODE_SEMIACTUATED;
|
if ((operation & 0x02) != 0) m_controllerStatusSubcontroller.operationMode = M_ControllerStatusSubcontroller.OPERATIONMODE_ACTUATED;
|
if ((operation & 0x04) != 0) m_controllerStatusSubcontroller.emergency = M_ControllerStatusSubcontroller.YES;
|
else m_controllerStatusSubcontroller.emergency = M_ControllerStatusSubcontroller.NO;
|
if ((operation & 0x08) != 0) m_controllerStatusSubcontroller.sptpOperation = M_ControllerStatusSubcontroller.SPTP_OPERATION_LOCAL;
|
if ((operation & 0x10) != 0) m_controllerStatusSubcontroller.sptpOperation = M_ControllerStatusSubcontroller.SPTP_OPERATION_COORDINATED;
|
if (((operation & 0x08) == 0) && ((operation & 0x10) == 0)) m_controllerStatusSubcontroller.sptpOperation = M_ControllerStatusSubcontroller.SPTP_OPERATION_NONE;
|
}
|
|
|
public static void analyseCurrentPresenceDetectorsResponse(M_Controller m_controller, M_Message message, int controllerCode) throws ServerException, Exception
|
{
|
message.reset();
|
|
try
|
{
|
while (message.readByte() != STX);
|
}
|
catch (Exception e)
|
{
|
throw new ServerException(Shared.getMessage("Message not start with 0x02"));
|
}
|
|
int controller = message.readByte() & 0x7F;
|
if (controller != controllerCode)
|
{
|
throw new ServerException(Shared.getMessage("Message does not correspond to controller"));
|
}
|
|
int function = message.readByte() & 0x7F;
|
if (function != M_ProtocolWriter.M_CURRENT_PRESENCE_DETECTORS)
|
{
|
return;
|
}
|
|
try
|
{
|
int status1 = message.readByte() & 0x7F;
|
int status2 = message.readByte() & 0x7F;
|
int status3 = message.readByte() & 0x7F;
|
|
if (m_controller.getDeviceRealtime().lpresence.size() == 0)
|
{
|
for (int i=1; i<=21; i++)
|
{
|
M_ControllerRealtimePresenceDetector presenceDetector = new M_ControllerRealtimePresenceDetector();
|
presenceDetector.number = i;
|
m_controller.getDeviceRealtime().lpresence.add(presenceDetector);
|
}
|
}
|
|
for (M_ControllerRealtimePresenceDetector presenceDetector : m_controller.getDeviceRealtime().lpresence)
|
{
|
int presence = M_ControllerRealtimePresenceDetector.PRESENCE_NO;
|
int byteStatus = status1;
|
int bit = 0;
|
if ((presenceDetector.number >= 1) && (presenceDetector.number <= 7))
|
{
|
byteStatus = status1;
|
bit = presenceDetector.number-1;
|
}
|
if ((presenceDetector.number >= 8) && (presenceDetector.number <= 14))
|
{
|
byteStatus = status2;
|
bit = presenceDetector.number-8;
|
}
|
if (presenceDetector.number > 14)
|
{
|
byteStatus = status3;
|
bit = presenceDetector.number-14;
|
}
|
|
if ((byteStatus & (int)(Math.pow(2, bit))) != 0)
|
presence = M_ControllerRealtimePresenceDetector.PRESENCE_YES;
|
else
|
presence = M_ControllerRealtimePresenceDetector.PRESENCE_NO;
|
|
if (presenceDetector.presence != presence)
|
presenceDetector.timestamp = System.currentTimeMillis();
|
presenceDetector.presence = presence;
|
}
|
}
|
catch (Exception exception)
|
{
|
|
}
|
}
|
|
|
public static void analyseCurrentCountingDetectorsResponse(M_Controller m_controller, M_Message message, int controllerCode, EtdStatus etdStatus) throws ServerException, Exception
|
{
|
message.reset();
|
|
if (m_controller.getIdentifier().indexOf("286") > -1)
|
{
|
Shared.println("Analyzer", m_controller.getIdentifier() + " - 1.Analyse_B3: " + controllerCode);
|
}
|
|
try
|
{
|
while (message.readByte() != STX);
|
}
|
catch (Exception e)
|
{
|
throw new ServerException(Shared.getMessage("Message not start with 0x02"));
|
}
|
|
if (m_controller.getIdentifier().indexOf("286") > -1)
|
{
|
Shared.println("Analyzer", m_controller.getIdentifier() + " - 2.Analyse_B3: " + controllerCode);
|
}
|
|
int controller = message.readByte() & 0x7F;
|
if (controller != controllerCode)
|
{
|
throw new ServerException(Shared.getMessage("Message does not correspond to controller"));
|
}
|
|
if (m_controller.getIdentifier().indexOf("286") > -1)
|
{
|
Shared.println("Analyzer", m_controller.getIdentifier() + " - 3.Analyse_B3: " + controllerCode);
|
}
|
|
int function = message.readByte() & 0x7F;
|
if (function != M_ProtocolWriter.M_CURRENT_COUNTING_DETECTORS)
|
{
|
return;
|
}
|
|
if (m_controller.getIdentifier().indexOf("286") > -1)
|
{
|
Shared.println("Analyzer", m_controller.getIdentifier() + " - 4.Analyse_B3: " + controllerCode);
|
}
|
|
int length = message.length() - 4;
|
int resto = (length % 8);
|
boolean tieneHora = false;
|
if (resto > 1) tieneHora = true;
|
|
if (m_controller.getIdentifier().indexOf("286") > -1)
|
{
|
Shared.println("Analyzer", m_controller.getIdentifier() + " - 4.Analyse_B3: " + length + " - " + resto + " - " + tieneHora);
|
}
|
|
int hour = -1;
|
int minute = -1;
|
String sfecha = "";
|
String sfechahora = "";
|
// long timestamp = System.currentTimeMillis();
|
if (tieneHora == true)
|
{
|
hour = message.readByte() & 0x7F;
|
minute = message.readByte() & 0x7F;
|
// sfecha = sdf.format(new Date());
|
// sfechahora = sfecha + " " + String.format("%02d:%02d:00", hour, minute);
|
// timestamp = sdfh.parse(sfechahora).getTime();
|
if (m_controller.getIdentifier().indexOf("286") > -1)
|
{
|
Shared.println("Analyzer", m_controller.getIdentifier() + " - 5.Analyse_B3: " + hour + ":" + minute);
|
}
|
}
|
|
long measurementTimestamp = TimeUtils.thisperiod(etdStatus.period);
|
etdStatus.setMeasurementTimestamp(Device.getDate(measurementTimestamp));
|
|
if (m_controller.getIdentifier().indexOf("286") > -1)
|
{
|
Shared.println("Analyzer", m_controller.getIdentifier() + " - 6.Analyse_B3: " + etdStatus.getMeasurementTimestamp());
|
}
|
|
try
|
{
|
int detector = 1;
|
while (message.eof() == false)
|
{
|
int counting1 = message.readByte() & 0x0F;
|
int counting2 = message.readByte() & 0x0F;
|
int counting3 = message.readByte() & 0x0F;
|
int counting4 = message.readByte() & 0x0F;
|
int occupancy1 = message.readByte() & 0x0F;
|
int occupancy2 = message.readByte() & 0x0F;
|
int occupancy3 = message.readByte() & 0x0F;
|
int occupancy4 = message.readByte() & 0x0F;
|
|
int counting = (counting1 << 12) + (counting2 << 8) + (counting3 << 4) + counting4;
|
int occupancy = (occupancy1 << 12) + (occupancy2 << 8) + (occupancy3 << 4) + occupancy4;
|
|
if (m_controller.getIdentifier().indexOf("286") > -1)
|
{
|
Shared.println("Analyzer", m_controller.getIdentifier() + " - 7.Analyse_B3: D" + detector + " - " + counting + " - " + occupancy);
|
}
|
|
boolean found = false;
|
|
for (M_ControllerRealtimeCountingDetector countingDetector : m_controller.getDeviceRealtime().lcounting)
|
{
|
if (countingDetector.number == detector)
|
{
|
found = true;
|
countingDetector.counting = counting;
|
countingDetector.occupancy = occupancy;
|
countingDetector.timestamp = measurementTimestamp;
|
}
|
}
|
|
if (found == false)
|
{
|
M_ControllerRealtimeCountingDetector countingDetector = new M_ControllerRealtimeCountingDetector();
|
countingDetector.number = detector;
|
countingDetector.counting = counting;
|
countingDetector.occupancy = occupancy;
|
countingDetector.timestamp = measurementTimestamp;
|
|
m_controller.getDeviceRealtime().lcounting.add(countingDetector);
|
}
|
|
// Put data in EtdStatus
|
if (etdStatus.llane.size() >= detector)
|
{
|
// Exist EtdStatusLane
|
EtdStatusLane laneStatus = etdStatus.llane.get(detector-1);
|
laneStatus.number = detector;
|
laneStatus.status = DeviceStatus.STATUS_ONLINE;
|
laneStatus.correctMeasurements = 1;
|
laneStatus.totalMeasurements = 1;
|
laneStatus.counting = counting;
|
laneStatus.occupancy = occupancy;
|
laneStatus.lengths = new int[1];
|
laneStatus.lengths[0] = counting;
|
laneStatus.speeds = new int[1];
|
laneStatus.speeds[0] = counting;
|
if (m_controller.getIdentifier().indexOf("286") > -1)
|
{
|
Shared.println("Analyzer", m_controller.getIdentifier() + " - 8.Analyse_B3: D" + laneStatus.number + " - " + laneStatus.status + " - " + laneStatus.counting + " - " + laneStatus.occupancy + " - " + laneStatus.totalMeasurements + " - " + laneStatus.correctMeasurements);
|
}
|
}
|
else
|
{
|
// Not exist EtdStatusLane
|
EtdStatusLane laneStatus = new EtdStatusLane();
|
laneStatus.number = detector;
|
laneStatus.status = DeviceStatus.STATUS_ONLINE;
|
laneStatus.correctMeasurements = 1;
|
laneStatus.totalMeasurements = 1;
|
laneStatus.counting = counting;
|
laneStatus.occupancy = occupancy;
|
laneStatus.lengths = new int[1];
|
laneStatus.lengths[0] = counting;
|
laneStatus.speeds = new int[1];
|
laneStatus.speeds[0] = counting;
|
etdStatus.llane.add(laneStatus);
|
if (m_controller.getIdentifier().indexOf("286") > -1)
|
{
|
Shared.println("Analyzer", m_controller.getIdentifier() + " - 9.Analyse_B3: D" + detector + " - " + etdStatus.llane.size());
|
}
|
}
|
|
detector++;
|
}
|
}
|
catch (Exception e)
|
{
|
if (m_controller.getIdentifier().indexOf("286") > -1)
|
{
|
Shared.printstack("Analyzer", e);
|
}
|
}
|
}
|
|
|
public static void analyseEndRecordingResponse(M_Message message) throws ServerException, Exception
|
{
|
message.reset();
|
|
try
|
{
|
while (message.readByte() != STX);
|
}
|
catch (Exception e)
|
{
|
throw new ServerException(Shared.getMessage("Message not start with 0x02"));
|
}
|
|
int controller = message.readByte() & 0x7F;
|
if (controller != 0x00)
|
{
|
throw new ServerException(Shared.getMessage("Message does not correspond to controller"));
|
}
|
|
int function = message.readByte() & 0x7F;
|
|
int byteGeneral1 = message.readByte() & 0x7F;
|
int byteGeneral2 = message.readByte() & 0x7F;
|
int byteGeneral3 = message.readByte() & 0x7F;
|
|
int byte1Subregulador1 = message.readByte() & 0x7F;
|
int byte2Subregulador1 = message.readByte() & 0x7F;
|
int byte3Subregulador1 = message.readByte() & 0x7F;
|
int byte4Subregulador1 = message.readByte() & 0x7F;
|
|
int byte1Subregulador2 = message.readByte() & 0x7F;
|
int byte2Subregulador2 = message.readByte() & 0x7F;
|
int byte3Subregulador2 = message.readByte() & 0x7F;
|
int byte4Subregulador2 = message.readByte() & 0x7F;
|
|
int byte1Subregulador3 = message.readByte() & 0x7F;
|
int byte2Subregulador3 = message.readByte() & 0x7F;
|
int byte3Subregulador3 = message.readByte() & 0x7F;
|
int byte4Subregulador3 = message.readByte() & 0x7F;
|
|
int byte1Subregulador4 = message.readByte() & 0x7F;
|
int byte2Subregulador4 = message.readByte() & 0x7F;
|
int byte3Subregulador4 = message.readByte() & 0x7F;
|
int byte4Subregulador4 = message.readByte() & 0x7F;
|
|
String msg = "";
|
|
int errorCode = byteGeneral1 & 0x0F;
|
int subcontroller = (byteGeneral1 >> 4) & 0x07;
|
|
// General Error Code
|
if (errorCode == 1)
|
{
|
msg += Shared.getMessage("Error recording tables") + Shared.getMessage("Too much data received") + "\r\n";
|
}
|
else if (errorCode == 2)
|
{
|
msg += Shared.getMessage("Error recording tables") + Shared.getMessage("Cannot record data") + "\r\n";
|
}
|
else if (errorCode == 3)
|
{
|
msg += Shared.getMessage("Error recording tables") + Shared.getMessage("Failure recording data") + "\r\n";
|
}
|
else if (errorCode == 4)
|
{
|
msg += Shared.getMessage("Error recording tables") + Shared.getMessage("Error deleting a table") + "\r\n";
|
}
|
else if (errorCode == 5)
|
{
|
msg += Shared.getMessage("Error recording tables") + Shared.getMessage("Tables reception error") + "\r\n";
|
}
|
|
|
// Error tables 1 to 7 of controller 0
|
|
if ((byteGeneral2 & 0x01) > 0)
|
{
|
msg += getMessageControllerTableError(M_Table.M_TABLE_A_GROUPS);
|
}
|
|
if ((byteGeneral2 & 0x02) > 0)
|
{
|
msg += getMessageControllerTableError(M_Table.M_TABLE_B_PHYSICAL_DETECTORS);
|
}
|
|
if ((byteGeneral2 & 0x04) > 0)
|
{
|
msg += getMessageControllerTableError(M_Table.M_TABLE_C_LOGICAL_DETECTORS);
|
}
|
|
if ((byteGeneral2 & 0x08) > 0)
|
{
|
msg += getMessageControllerTableError(M_Table.M_TABLE_D_DEMANDS);
|
}
|
|
if ((byteGeneral2 & 0x10) > 0)
|
{
|
msg += getMessageControllerTableError(M_Table.M_TABLE_E_INCOMPATIBILITIES);
|
}
|
|
if ((byteGeneral2 & 0x20) > 0)
|
{
|
msg += getMessageControllerTableError(M_Table.M_TABLE_F_SPECIAL_DAYS);
|
}
|
|
if ((byteGeneral2 & 0x40) > 0)
|
{
|
msg += getMessageControllerTableError(M_Table.M_TABLE_G_INTERMITENCES);
|
}
|
|
|
// Error tables 8 to 14 of controller 0
|
|
if ((byteGeneral3 & 0x01) > 0)
|
{
|
msg += getMessageControllerTableError(M_Table.M_TABLE_H_OPERATION_MODE);
|
}
|
|
if ((byteGeneral3 & 0x02) > 0)
|
{
|
msg += getMessageControllerTableError(M_Table.M_TABLE_I_ALARMS_MANAGEMENT);
|
}
|
|
if ((byteGeneral3 & 0x04) > 0)
|
{
|
msg += getMessageControllerTableError(M_Table.M_TABLE_DYNAMIC_LAMPS);
|
}
|
|
if ((byteGeneral3 & 0x08) > 0)
|
{
|
msg += getMessageControllerTableError(M_Table.M_TABLE_DYNAMIC_DETECTORS);
|
}
|
|
if ((byteGeneral3 & 0x10) > 0)
|
{
|
msg += getMessageControllerTableError(M_Table.M_TABLE_DYNAMIC_GENERAL_PARAMETERS);
|
}
|
|
if ((byteGeneral3 & 0x20) > 0)
|
{
|
msg += getMessageControllerTableError(M_Table.M_TABLE_DYNAMIC_BUTTON_GUARD);
|
}
|
|
if ((byteGeneral3 & 0x40) > 0)
|
{
|
msg += getMessageControllerTableError(M_Table.M_TABLE_DYNAMIC_ALARMS_CONFIGURATION);
|
}
|
|
msg += analyseSubcontrollerTablesErrors(1, byte1Subregulador1, byte2Subregulador1, byte3Subregulador1, byte4Subregulador1);
|
msg += analyseSubcontrollerTablesErrors(2, byte1Subregulador2, byte2Subregulador2, byte3Subregulador2, byte4Subregulador2);
|
msg += analyseSubcontrollerTablesErrors(3, byte1Subregulador3, byte2Subregulador3, byte3Subregulador3, byte4Subregulador3);
|
msg += analyseSubcontrollerTablesErrors(4, byte1Subregulador4, byte2Subregulador4, byte3Subregulador4, byte4Subregulador4);
|
|
if (msg.length() > 0)
|
throw new Exception(msg);
|
}
|
|
|
public static List<Byte> analyseReadTable(M_Message message, int tableCode, boolean hasCRC) throws ServerException, Exception
|
{
|
message.reset();
|
|
try
|
{
|
while (message.readByte() != STX);
|
}
|
catch (Exception e)
|
{
|
return(new ArrayList<Byte>());
|
}
|
|
int controller = message.readByte() & 0x7F;
|
if (controller == 0x00)
|
{
|
return(analyseReadTableController(message, hasCRC));
|
}
|
else
|
{
|
return(analyseReadTableSubcontroller(message, hasCRC));
|
}
|
}
|
|
|
private static List<Byte> analyseReadTableController(M_Message message, boolean hasCRC) throws ServerException, Exception
|
{
|
int function = message.readByte() & 0x7F;
|
switch (function)
|
{
|
case M_ProtocolWriter.M_READ_TABLE_FULL:
|
{
|
return(getTableDataController(message, hasCRC));
|
}
|
}
|
|
return(new ArrayList<Byte>());
|
}
|
|
|
private static List<Byte> analyseReadTableSubcontroller(M_Message message, boolean hasCRC) throws ServerException, Exception
|
{
|
int function = message.readByte() & 0x7F;
|
switch (function)
|
{
|
case M_ProtocolWriter.M_READ_TABLE_FULL:
|
{
|
return(getTableDataSubcontroller(message, hasCRC));
|
}
|
|
case M_ProtocolWriter.M_READ_TABLE_PARTIAL:
|
{
|
int blockNumber = message.readByte() & 0x7F;
|
return(getTableDataSubcontrollerPartial(message, hasCRC));
|
}
|
}
|
|
return(new ArrayList<Byte>());
|
}
|
|
|
public static M_Plan analyseGetRecordablePlanResponse(M_Message message, int subcontroller, int phasesnumber) throws ServerException, Exception
|
{
|
try
|
{
|
message.reset();
|
|
try
|
{
|
while (message.readByte() != STX);
|
}
|
catch (Exception e)
|
{
|
throw new ServerException(Shared.getMessage("Message not start with 0x02"));
|
}
|
|
int controller = message.readByte() & 0x7F;
|
if (controller != subcontroller)
|
{
|
throw new ServerException(Shared.getMessage("Message does not correspond to controller"));
|
}
|
|
int function = message.readByte() & 0x7F;
|
if (function != M_ProtocolWriter.M_RECORDABLE_PLAN_QUERY)
|
{
|
return null;
|
}
|
|
M_Plan recordablePlan = new M_Plan();
|
recordablePlan.structure = message.readByte() & 0x7F;
|
recordablePlan.transitionsToTimesTable = message.readByte() & 0x7F;
|
recordablePlan.minimumAndExtensionTimesTable = message.readByte() & 0x7F;
|
int offset1 = message.readByte() & 0x7F;
|
int offset2 = message.readByte() & 0x7F;
|
recordablePlan.offset = (offset1 << 7) + offset2;
|
recordablePlan.controlMode = message.readByte() & 0x7F;
|
|
while ((message.eof() == false) && (recordablePlan.lPhaseTime.size() < phasesnumber))
|
{
|
recordablePlan.lPhaseTime.add(new Integer(message.readByte() & 0x7F));
|
}
|
|
return(recordablePlan);
|
}
|
catch (ServerException exception)
|
{
|
throw exception;
|
}
|
catch (Exception exception)
|
{
|
return(null);
|
}
|
}
|
|
|
private static List<Byte> getTableDataController(M_Message message, boolean hasCRC) throws ServerException, Exception
|
{
|
int tableCode = message.readByte() & 0x7F;
|
return(readTable(message, tableCode, hasCRC));
|
}
|
|
|
private static List<Byte> getTableDataSubcontroller(M_Message message, boolean hasCRC) throws ServerException, Exception
|
{
|
int tableCode = message.readByte() & 0x7F;
|
return(readTable(message, tableCode, hasCRC));
|
}
|
|
|
private static List<Byte> getTableDataSubcontrollerPartial(M_Message message, boolean hasCRC) throws ServerException, Exception
|
{
|
int tableCode = message.readByte() & 0x7F;
|
return(readTablePartial(message, tableCode, hasCRC));
|
}
|
|
|
private static List<Byte> readTable(M_Message message, int tableCode, boolean hasCRC) throws ServerException, Exception
|
{
|
List<Byte> lContent = new ArrayList<Byte>();
|
|
byte[] messageData = message.toByteArray();
|
int tabledatalen = messageData.length-1;
|
if (hasCRC == true) tabledatalen = messageData.length-2;
|
byte[] tableData = new byte[tabledatalen];
|
System.arraycopy(messageData, 0, tableData, 0, 2);
|
System.arraycopy(messageData, 3, tableData, 2, tabledatalen-2);
|
|
if (hasCRC == true) tableData[tableData.length-1] = ETX;
|
|
for (int i=0; i<tableData.length; i++)
|
lContent.add(new Byte(tableData[i]));
|
return(lContent);
|
}
|
|
|
private static List<Byte> readTablePartial(M_Message message, int tableCode, boolean hasCRC) throws ServerException, Exception
|
{
|
List<Byte> lContent = new ArrayList<Byte>();
|
|
byte[] messageData = message.toByteArray();
|
int tabledatalen = messageData.length-1;
|
if (hasCRC == true) tabledatalen = messageData.length-2;
|
byte[] tableData = new byte[tabledatalen];
|
System.arraycopy(messageData, 0, tableData, 0, 2);
|
System.arraycopy(messageData, 3, tableData, 2, tabledatalen-2);
|
|
if (hasCRC == true) tableData[tableData.length-1] = ETX;
|
|
int indexSTX = 0;
|
for (int i=0; i<tableData.length; i++)
|
{
|
boolean add = true;
|
if (tableData[i] == STX)
|
{
|
if (indexSTX > 0)
|
{
|
lContent.remove(lContent.size()-1);
|
add = false;
|
i += 3;
|
}
|
|
indexSTX++;
|
}
|
if (add == true) lContent.add(new Byte(tableData[i]));
|
}
|
return(lContent);
|
}
|
|
|
public static String analyseSubcontrollerTablesErrors(int subcontroller, int byte1, int byte2, int byte3, int byte4) throws ServerException, Exception
|
{
|
String msg = "";
|
|
// Error tables 15 to 21 of subcontroller
|
|
if ((byte1 & 0x01) > 0)
|
{
|
msg += getMessageSubcontrollerTableError(subcontroller, M_Table.M_TABLE_A_PHASES_STABLES);
|
}
|
|
if ((byte1 & 0x02) > 0)
|
{
|
msg += getMessageSubcontrollerTableError(subcontroller, M_Table.M_TABLE_B_PHASES_TRANSITIONS);
|
}
|
|
if ((byte1 & 0x04) > 0)
|
{
|
msg += getMessageSubcontrollerTableError(subcontroller, M_Table.M_TABLE_C_TRANSITIONS);
|
}
|
|
if ((byte1 & 0x08) > 0)
|
{
|
msg += getMessageSubcontrollerTableError(subcontroller, M_Table.M_TABLE_D_STRUCTURES);
|
}
|
|
if ((byte1 & 0x10) > 0)
|
{
|
msg += getMessageSubcontrollerTableError(subcontroller, M_Table.M_TABLE_E_ACTION_ON_DEMAND);
|
}
|
|
if ((byte1 & 0x20) > 0)
|
{
|
msg += getMessageSubcontrollerTableError(subcontroller, M_Table.M_TABLE_F_TRANSITIONS_TO_TIMES);
|
}
|
|
if ((byte1 & 0x40) > 0)
|
{
|
msg += getMessageSubcontrollerTableError(subcontroller, M_Table.M_TABLE_G_TRANSITIONS_TIMES);
|
}
|
|
|
|
// Error tables 22 to 28 of subcontroller
|
|
if ((byte2 & 0x01) > 0)
|
{
|
msg += getMessageSubcontrollerTableError(subcontroller, M_Table.M_TABLE_H_MINIMUM_EXTENSION_TIMES);
|
}
|
|
if ((byte2 & 0x02) > 0)
|
{
|
msg += getMessageSubcontrollerTableError(subcontroller, M_Table.M_TABLE_I_PLANS);
|
}
|
|
if ((byte2 & 0x04) > 0)
|
{
|
msg += getMessageSubcontrollerTableError(subcontroller, M_Table.M_TABLE_J_EMERGENCY);
|
}
|
|
if ((byte2 & 0x08) > 0)
|
{
|
msg += getMessageSubcontrollerTableError(subcontroller, M_Table.M_TABLE_K_STARTUP);
|
}
|
|
if ((byte2 & 0x10) > 0)
|
{
|
msg += getMessageSubcontrollerTableError(subcontroller, M_Table.M_TABLE_L_CONFLICTIVE_TRANSITIONS);
|
}
|
|
if ((byte2 & 0x20) > 0)
|
{
|
msg += getMessageSubcontrollerTableError(subcontroller, M_Table.M_TABLE_M_TIMETABLE);
|
}
|
|
if ((byte2 & 0x40) > 0)
|
{
|
msg += getMessageSubcontrollerTableError(subcontroller, M_Table.M_TABLE_N_SPARE_TIMES);
|
}
|
|
return(msg);
|
}
|
|
|
private static String getMessageControllerTableError(int tableCode) throws Exception
|
{
|
switch (tableCode)
|
{
|
case M_Table.M_TABLE_A_GROUPS: return(Shared.getMessage("Error recording controller table") + " : " + Shared.getMessage("Table A Groups") + "\r\n");
|
case M_Table.M_TABLE_B_PHYSICAL_DETECTORS: return(Shared.getMessage("Error recording controller table") + " : " + Shared.getMessage("Table B Physical Detectors") + "\r\n");
|
case M_Table.M_TABLE_C_LOGICAL_DETECTORS: return(Shared.getMessage("Error recording controller table") + " : " + Shared.getMessage("Table C Logical Detectors") + "\r\n");
|
case M_Table.M_TABLE_D_DEMANDS: return(Shared.getMessage("Error recording controller table") + " : " + Shared.getMessage("Table D Demands") + "\r\n");
|
case M_Table.M_TABLE_E_INCOMPATIBILITIES: return(Shared.getMessage("Error recording controller table") + " : " + Shared.getMessage("Table E Incompatibilities") + "\r\n");
|
case M_Table.M_TABLE_F_SPECIAL_DAYS: return(Shared.getMessage("Error recording controller table") + " : " + Shared.getMessage("Table F Special Days") + "\r\n");
|
case M_Table.M_TABLE_G_INTERMITENCES: return(Shared.getMessage("Error recording controller table") + " : " + Shared.getMessage("Table G Intermitences") + "\r\n");
|
case M_Table.M_TABLE_H_OPERATION_MODE: return(Shared.getMessage("Error recording controller table") + " : " + Shared.getMessage("Table H Operation Mode") + "\r\n");
|
case M_Table.M_TABLE_I_ALARMS_MANAGEMENT: return(Shared.getMessage("Error recording controller table") + " : " + Shared.getMessage("Table I Alarms Management") + "\r\n");
|
case M_Table.M_TABLE_DYNAMIC_LAMPS: return(Shared.getMessage("Error recording controller table") + " : " + Shared.getMessage("Table Dynamic Control Lamps") + "\r\n");
|
case M_Table.M_TABLE_DYNAMIC_DETECTORS: return(Shared.getMessage("Error recording controller table") + " : " + Shared.getMessage("Table Dynamic Control Detectors") + "\r\n");
|
case M_Table.M_TABLE_DYNAMIC_GENERAL_PARAMETERS: return(Shared.getMessage("Error recording controller table") + " : " + Shared.getMessage("Table Dynamic General Parameters") + "\r\n");
|
case M_Table.M_TABLE_DYNAMIC_BUTTON_GUARD: return(Shared.getMessage("Error recording controller table") + " : " + Shared.getMessage("Table Dynamic Button Guard Configuration") + "\r\n");
|
case M_Table.M_TABLE_DYNAMIC_ALARMS_CONFIGURATION: return(Shared.getMessage("Error recording controller table") + " : " + Shared.getMessage("Table Dynamic Alarms Configuration") + "\r\n");
|
}
|
|
return(Shared.getMessage("Error recording controller table") + " : " + Shared.getMessage("Unknown table") + " : " + tableCode + "\r\n");
|
}
|
|
|
private static String getMessageSubcontrollerTableError(int subcontroller, int tableCode) throws Exception
|
{
|
switch (tableCode)
|
{
|
case M_Table.M_TABLE_A_PHASES_STABLES: return(Shared.getMessage("Error recording subcontroller %1, table").replaceAll("%1", "" + subcontroller) + " " + Shared.getMessage("Table A Phases Stables") + "\r\n");
|
case M_Table.M_TABLE_B_PHASES_TRANSITIONS: return(Shared.getMessage("Error recording subcontroller %1, table").replaceAll("%1", "" + subcontroller) + " " + Shared.getMessage("Table B Phases Transitions") + "\r\n");
|
case M_Table.M_TABLE_C_TRANSITIONS: return(Shared.getMessage("Error recording subcontroller %1, table").replaceAll("%1", "" + subcontroller) + " " + Shared.getMessage("Table C Transitions")) + "\r\n";
|
case M_Table.M_TABLE_D_STRUCTURES: return(Shared.getMessage("Error recording subcontroller %1, table").replaceAll("%1", "" + subcontroller) + " " + Shared.getMessage("Table D Structures")) + "\r\n";
|
case M_Table.M_TABLE_E_ACTION_ON_DEMAND: return(Shared.getMessage("Error recording subcontroller %1, table").replaceAll("%1", "" + subcontroller) + " " + Shared.getMessage("Table E Action on Demand") + "\r\n");
|
case M_Table.M_TABLE_F_TRANSITIONS_TO_TIMES: return(Shared.getMessage("Error recording subcontroller %1, table").replaceAll("%1", "" + subcontroller) + " " + Shared.getMessage("Table F Transition to Times") + "\r\n");
|
case M_Table.M_TABLE_G_TRANSITIONS_TIMES: return(Shared.getMessage("Error recording subcontroller %1, table").replaceAll("%1", "" + subcontroller) + " " + Shared.getMessage("Table G Transitions Times") + "\r\n");
|
case M_Table.M_TABLE_H_MINIMUM_EXTENSION_TIMES: return(Shared.getMessage("Error recording subcontroller %1, table").replaceAll("%1", "" + subcontroller) + " " + Shared.getMessage("Table H Minimum Extension Times") + "\r\n");
|
case M_Table.M_TABLE_I_PLANS: return(Shared.getMessage("Error recording subcontroller %1, table").replaceAll("%1", "" + subcontroller) + " " + Shared.getMessage("Table I Plans") + "\r\n");
|
case M_Table.M_TABLE_J_EMERGENCY: return(Shared.getMessage("Error recording subcontroller %1, table").replaceAll("%1", "" + subcontroller) + " " + Shared.getMessage("Table J Emergency") + "\r\n");
|
case M_Table.M_TABLE_K_STARTUP: return(Shared.getMessage("Error recording subcontroller %1, table").replaceAll("%1", "" + subcontroller) + " " + Shared.getMessage("Table K Startup") + "\r\n");
|
case M_Table.M_TABLE_L_CONFLICTIVE_TRANSITIONS: return(Shared.getMessage("Error recording subcontroller %1, table").replaceAll("%1", "" + subcontroller) + " " + Shared.getMessage("Table L Conflictive Transitions") + "\r\n");
|
case M_Table.M_TABLE_M_TIMETABLE: return(Shared.getMessage("Error recording subcontroller %1, table").replaceAll("%1", "" + subcontroller) + " " + Shared.getMessage("Table M Timetable") + "\r\n");
|
case M_Table.M_TABLE_N_SPARE_TIMES: return(Shared.getMessage("Error recording subcontroller %1, table").replaceAll("%1", "" + subcontroller) + " " + Shared.getMessage("Table N Spare Times") + "\r\n");
|
}
|
|
return(Shared.getMessage("Error recording subcontroller %1, table").replaceAll("%1", "" + subcontroller) + " " + Shared.getMessage("Unknown table") + " : " + tableCode + "\r\n");
|
}
|
|
}
|