package art.servers.colorsserver.controller; import art.library.interop.InteropParameters; import art.library.interop.serialization.Serialization; import art.library.interop.serialization.SerializationException; import art.library.model.devices.DeviceAction; import art.library.model.devices.DeviceActionResult; import art.library.model.devices.DeviceCommands; import static art.library.model.devices.DeviceCommands.CONDITION_DISABLED; import static art.library.model.devices.DeviceCommands.CONDITION_ENABLED; import static art.library.model.devices.DeviceCommands.CONDITION_NO; import static art.library.model.devices.DeviceCommands.CONDITION_YES; import art.library.model.devices.colors.controller.M.M_Controller; import art.library.model.devices.colors.controller.M.M_ControllerCommands; import art.library.model.devices.colors.controller.M.M_ControllerConfiguration; import art.library.model.devices.colors.controller.M.M_ControllerInformation; import art.library.model.devices.colors.controller.M.M_ControllerRealtime; import art.library.model.devices.colors.controller.M.M_ControllerStatus; import art.library.model.devices.colors.controller.M.realtime.M_ControllerRealtimeCountingDetector; import art.library.model.devices.colors.controller.M.M_ControllerStatusSubcontroller; import art.library.model.devices.colors.controller.M.M_SubcontrollerConfiguration; import art.library.model.devices.colors.controller.M.commands.M_ControllerCommandsSpecialDemand; import art.library.model.devices.colors.controller.M.commands.M_ControllerCommands_SPTP; import art.library.model.devices.colors.controller.M.commands.M_ControllerCommands_SPTP_Demands; import art.library.model.devices.colors.controller.M.commands.M_ControllerCommands_SPTP_OperationMode; import art.library.model.devices.colors.controller.M.configuration.ALUVISA_Link; import art.library.model.devices.colors.controller.M.configuration.ALUVISA_Phase; import art.library.model.devices.colors.controller.M.configuration.ALUVISA_Plan; import art.library.model.devices.colors.controller.M.configuration.M_Assignment; import art.library.model.devices.colors.controller.M.configuration.M_Intergreen; import art.library.model.devices.colors.controller.M.configuration.M_IntergreenPositionTimes; import art.library.model.devices.colors.controller.M.configuration.M_IntergreenToTimeTable; import art.library.model.devices.colors.controller.M.configuration.M_IntergreensPositionTimes; import art.library.model.devices.colors.controller.M.configuration.M_MinimumExtension; import art.library.model.devices.colors.controller.M.configuration.M_PhysicalDetectorStrategical; import art.library.model.devices.colors.controller.M.configuration.M_Plan; import art.library.model.devices.colors.controller.M.configuration.M_Structure; import art.library.model.devices.colors.controller.M.configuration.M_TrafficGroup; import art.library.model.devices.colors.controller.M.configuration.SPTP.M_SPTP_Configuration; import art.library.model.devices.colors.controller.M.realtime.M_ControllerRealtimeGroup; 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.tables.M_ControllerReader; import art.library.model.devices.colors.controller.M.tables.M_ControllerWriter; import art.library.model.devices.colors.controller.M.tables.M_Table; import art.library.model.devices.colors.controller.M.tables.M_TableWriter; import art.library.model.devices.colors.controller.M.types.SPTP.M_SPTP_Demand; import art.library.model.devices.colors.controller.M.types.SPTP.M_SPTP_Demand_Result; import art.library.model.devices.etd.EtdStatus; import art.library.model.devices.etd.status.EtdStatusLane; import art.library.persistence.Persistence; import art.servers.ColorsServer; import art.servers.ServerException; import art.servers.colorsserver.M.protocol.M_ControllerComunicator; import art.servers.colorsserver.Shared; import art.servers.colorsserver.M.protocol.M_Message; import art.servers.colorsserver.M.protocol.M_ProtocolAnalyser; import art.servers.colorsserver.M.protocol.M_ProtocolConstructor; import art.servers.colorsserver.M.protocol.M_ProtocolWriter; import art.servers.colorsserver.M.protocol.M_Request; import art.servers.controller.Controller; import static art.servers.controller.ListenerImplementation.getTimestamp; import static java.lang.Thread.sleep; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; import java.util.List; public class ControllerController extends art.servers.controller.ControllerDevice { private SimpleDateFormat sdh = new SimpleDateFormat("HH:mm"); public static final int MAX_RETRIES = 6; protected M_Controller controller = null; public boolean hasCRC = false; protected String name = null; protected EtdStatus etdStatus = null; protected int forceRealtime = -1; protected int[] forcedUserControlPlan = new int[1]; protected int forceCentralized = -1; protected List lsubcontrollerUpdate = new ArrayList(); protected List lcontroller = new ArrayList(); protected long lastQueryDetectorsRealtime = 0; protected long lastQueryGroupsRealtime = 0; protected long lastQueryStatus = 0; protected long lastQueryTrafficData = 0; protected long lastQueryTables = 0; protected boolean firstTime = true; private boolean usePRH = false; private boolean checkedPRH = false; private ControllerTrafficData controllerTrafficData = null; public M_ControllerCommands_SPTP_Demands commandsDemands = null; public M_SPTP_Configuration commandsConfiguration = null; public ControllerController(M_Controller m_controller, boolean hasCRC) { super(m_controller); this.controller = m_controller; this.forcedUserControlPlan[0] = M_ControllerCommands.CONDITION_NOTHING; this.hasCRC = hasCRC; this.name = "Controller " + m_controller.getIdentifier(); } public ControllerController(M_Controller m_controller, List lcontroller, boolean hasCRC) { super(m_controller); this.controller = m_controller; this.lcontroller = lcontroller; this.hasCRC = hasCRC; this.name = "Controller " + m_controller.getIdentifier() + " - " + lcontroller.size(); forcedUserControlPlan = new int[lcontroller.size()]; for (int i=0; i public void run() { // Shared.traceInformation(name, Shared.getMessage("Starting")); // while ((isInterrupted() == false) && (exit == false)) { long startTimestamp = System.currentTimeMillis(); try { if (art.servers.Shared.isServerEnabled() == true) { if (this.controllerTrafficData == null) { this.controllerTrafficData = new ControllerTrafficData(); this.controllerTrafficData.start(); } if (forceCentralized == 0) { stopController(); } else { resumeController(); } update(); } } catch (Exception e) { } try { if (startTimestamp > System.currentTimeMillis()) { startTimestamp = System.currentTimeMillis(); } long stopTimestamp = startTimestamp + 1000; while ((System.currentTimeMillis() < stopTimestamp) && (exit == false)) { try { sleep(50); } catch (Exception e) { } } try{sleep(50);}catch (Exception e){}; } catch (Exception e) { try { sleep(1000); } catch (Exception ex) { } } } this.controllerTrafficData.close(); // Shared.traceInformation(name, Shared.getMessage("Finishing")); // } public void stopController() { try{getControllerConnection().stopConnection();} catch (Exception e){}; } public void resumeController() { try{getControllerConnection().resumeconnection();} catch (Exception e){}; } protected void update() throws ServerException, Exception { } public M_Controller cloneController() { M_Controller controllerclone = (M_Controller)Serialization.clone(controller); if (controller.realtime == null) { controller.realtime = new M_ControllerRealtime(); } controllerclone.realtime = controller.realtime; controllerclone.getDeviceRealtime().identifier = controllerclone.getIdentifier(); if (controllerclone.getDeviceRealtime().lastTimestampUpdate <= 0) { controllerclone.getDeviceRealtime().lastTimestampUpdate = System.currentTimeMillis(); } if (ColorsServer.ACTIVATE_REALTIME == true) { this.forceRealtime = 1; } if (forceRealtime == 0) { controllerclone.getDeviceStatus().detectorsRealtime = M_ControllerStatus.NO; controllerclone.getDeviceStatus().groupsRealtime = M_ControllerStatus.NO; controllerclone.getDeviceRealtime().lpresence.clear(); controllerclone.getDeviceRealtime().lgroup.clear(); forceRealtime = -1; } else if (forceRealtime == 1) { controllerclone.getDeviceStatus().detectorsRealtime = M_ControllerStatus.YES; controllerclone.getDeviceStatus().groupsRealtime = M_ControllerStatus.YES; forceRealtime = -1; } if (controllerclone.getDeviceStatus().detectorsRealtime != M_ControllerStatus.YES) { controllerclone.getDeviceRealtime().lpresence.clear(); } if (controllerclone.getDeviceStatus().groupsRealtime != M_ControllerStatus.YES) { controllerclone.getDeviceRealtime().lgroup.clear(); } if ((controllerclone.getDeviceStatus().detectorsRealtime != M_ControllerStatus.NO) && (controllerclone.getDeviceStatus().detectorsRealtime != M_ControllerStatus.YES)) { controllerclone.getDeviceStatus().detectorsRealtime = M_ControllerStatus.NO; } if ((controllerclone.getDeviceStatus().groupsRealtime != M_ControllerStatus.NO) && (controllerclone.getDeviceStatus().groupsRealtime != M_ControllerStatus.YES)) { controllerclone.getDeviceStatus().groupsRealtime = M_ControllerStatus.NO; } for (M_ControllerStatusSubcontroller subcontrollerStatus : controllerclone.getDeviceStatus().lsubcontroller) { if ((subcontrollerStatus.userControlManual != M_ControllerStatus.NO) && (subcontrollerStatus.userControlManual != M_ControllerStatus.YES)) { subcontrollerStatus.userControlManual = M_ControllerStatus.NO; } if ((subcontrollerStatus.userControlPlan != M_ControllerStatus.NO) && (subcontrollerStatus.userControlPlan != M_ControllerStatus.YES)) { subcontrollerStatus.userControlPlan = M_ControllerStatus.NO; } } for (int i=0; i 0) { if ((controllerclone.alarms.alarm_offline <= 0) || (firstTime == true)) { firstTime = false; String message = art.servers.Shared.getMessage("Controller offline"); art.servers.Shared.println(name, message); } controllerclone.setAlarm("alarm_offline", System.currentTimeMillis()); controllerclone.getDeviceInformation().serverAddress = art.servers.Shared.configuration.listener.address; controllerclone.getDeviceInformation().serverPort = art.servers.Shared.configuration.listener.port; controllerclone.getDeviceInformation().serverAddressExternal = art.servers.Shared.configuration.listener.addressExternal; controllerclone.getDeviceInformation().serverPortExternal = art.servers.Shared.configuration.listener.portExternal; controllerclone.getDeviceInformation().serverServiceName = art.servers.Shared.controllerStatus.getApplication().getDeviceInformation().serverServiceName; if (controllerclone.getDeviceStatus().lsubcontrollerUpdate != null) { if (controllerclone.getDeviceStatus().lsubcontrollerUpdate.size() <= 0) { controllerclone.getDeviceStatus().lsubcontrollerUpdate = null; } } M_ControllerStatus statusController = controllerclone.getDeviceStatus(); if (statusController.lsubcontroller != null) { if (statusController.lsubcontroller.size() == 0) { M_ControllerStatusSubcontroller statussubcontroller = new M_ControllerStatusSubcontroller(); statussubcontroller.number = controllerclone.getDeviceInformation().subcontroller; statusController.lsubcontroller.add(statussubcontroller); } } M_ControllerConfiguration configurationController = controllerclone.getDeviceConfiguration(); if (configurationController.lsubcontroller != null) { for (M_SubcontrollerConfiguration configurationSubcontroller : configurationController.lsubcontroller) { for (M_Plan m_plan : configurationSubcontroller.lplan) { ALUVISA_Plan plan = m_plan.toAluvisaPlan(configurationSubcontroller); m_plan.numberOfPaths = plan.getPaths().size(); } } } try { controllerclone.getDeviceRealtime().lcounting.clear(); controllerclone.getDeviceRealtime().lgroup.clear(); controllerclone.getDeviceRealtime().lpresence.clear(); } catch (Exception e) { } // Have more than one subcontroller // Must be clone for every subcontroller for (M_Controller m_controllerSubcontroller : this.lcontroller) { M_Controller m_subcontroller = getSubcontrollerOffline(controllerclone, m_controllerSubcontroller); M_Controller m_subcontrollerCurrent = (M_Controller)Shared.model.getDevice(m_controllerSubcontroller.getIdentifier()); Shared.model.updateDevice(m_subcontrollerCurrent, m_subcontroller); } // this.controller.updateDevice(controllerclone); this.controller = controllerclone; try { this.controller.getDeviceConfiguration().toAluvisa(); } catch (Exception e) { } } lastQueryDetectorsRealtime = 0; lastQueryGroupsRealtime = 0; lastQueryStatus = 0; lastQueryTrafficData = 0; lastQueryTables = 0; } public void disable(M_Controller controllerclone)throws Exception { if (this.lcontroller.size() == 0) { if ((controllerclone.alarms.alarm_disabled <= 0) || (firstTime == true)) { firstTime = false; String message = art.servers.Shared.getMessage("Controller disabled"); art.servers.Shared.println(name, message); } controllerclone.setAlarm("alarm_disabled", System.currentTimeMillis()); if (controllerclone.getDeviceStatus().lsubcontrollerUpdate != null) { if (controllerclone.getDeviceStatus().lsubcontrollerUpdate.size() <= 0) { controllerclone.getDeviceStatus().lsubcontrollerUpdate = null; } } M_ControllerStatus statusController = controllerclone.getDeviceStatus(); if (statusController.lsubcontroller != null) { if (statusController.lsubcontroller.size() == 0) { M_ControllerStatusSubcontroller statussubcontroller = new M_ControllerStatusSubcontroller(); statussubcontroller.number = controllerclone.getDeviceInformation().subcontroller; statusController.lsubcontroller.add(statussubcontroller); } } M_ControllerConfiguration configurationController = controllerclone.getDeviceConfiguration(); if (configurationController.lsubcontroller != null) { for (M_SubcontrollerConfiguration configurationSubcontroller : configurationController.lsubcontroller) { for (M_Plan m_plan : configurationSubcontroller.lplan) { ALUVISA_Plan plan = m_plan.toAluvisaPlan(configurationSubcontroller); m_plan.numberOfPaths = plan.getPaths().size(); } } } try { controllerclone.getDeviceRealtime().lcounting.clear(); controllerclone.getDeviceRealtime().lgroup.clear(); controllerclone.getDeviceRealtime().lpresence.clear(); } catch (Exception e) { } Shared.model.updateDevice(controller, controllerclone); } else if (this.lcontroller.size() > 0) { if ((controllerclone.alarms.alarm_disabled <= 0) || (firstTime == true)) { firstTime = false; String message = art.servers.Shared.getMessage("Controller disabled"); art.servers.Shared.println(name, message); } controllerclone.setAlarm("alarm_disabled", System.currentTimeMillis()); controllerclone.getDeviceInformation().serverAddress = art.servers.Shared.configuration.listener.address; controllerclone.getDeviceInformation().serverPort = art.servers.Shared.configuration.listener.port; controllerclone.getDeviceInformation().serverAddressExternal = art.servers.Shared.configuration.listener.addressExternal; controllerclone.getDeviceInformation().serverPortExternal = art.servers.Shared.configuration.listener.portExternal; controllerclone.getDeviceInformation().serverServiceName = art.servers.Shared.controllerStatus.getApplication().getDeviceInformation().serverServiceName; if (controllerclone.getDeviceStatus().lsubcontrollerUpdate != null) { if (controllerclone.getDeviceStatus().lsubcontrollerUpdate.size() <= 0) { controllerclone.getDeviceStatus().lsubcontrollerUpdate = null; } } M_ControllerStatus statusController = controllerclone.getDeviceStatus(); if (statusController.lsubcontroller != null) { if (statusController.lsubcontroller.size() == 0) { M_ControllerStatusSubcontroller statussubcontroller = new M_ControllerStatusSubcontroller(); statussubcontroller.number = controllerclone.getDeviceInformation().subcontroller; statusController.lsubcontroller.add(statussubcontroller); } } M_ControllerConfiguration configurationController = controllerclone.getDeviceConfiguration(); if (configurationController.lsubcontroller != null) { for (M_SubcontrollerConfiguration configurationSubcontroller : configurationController.lsubcontroller) { for (M_Plan m_plan : configurationSubcontroller.lplan) { ALUVISA_Plan plan = m_plan.toAluvisaPlan(configurationSubcontroller); m_plan.numberOfPaths = plan.getPaths().size(); } } } try { controllerclone.getDeviceRealtime().lcounting.clear(); controllerclone.getDeviceRealtime().lgroup.clear(); controllerclone.getDeviceRealtime().lpresence.clear(); } catch (Exception e) { } // Have more than one subcontroller // Must be clone for every subcontroller for (M_Controller m_controllerSubcontroller : this.lcontroller) { M_Controller m_subcontroller = getSubcontrollerOffline(controllerclone, m_controllerSubcontroller); M_Controller m_subcontrollerCurrent = (M_Controller)Shared.model.getDevice(m_controllerSubcontroller.getIdentifier()); Shared.model.updateDevice(m_subcontrollerCurrent, m_subcontroller); } // this.controller.updateDevice(controllerclone); this.controller = controllerclone; try { this.controller.getDeviceConfiguration().toAluvisa(); } catch (Exception e) { } } lastQueryDetectorsRealtime = 0; lastQueryGroupsRealtime = 0; lastQueryStatus = 0; lastQueryTrafficData = 0; lastQueryTables = 0; } public void online(M_Controller controllerclone) throws ServerException, Exception { if (this.lcontroller.size() == 0) { // Only have one subcontroller, so it works how until now if ((controllerclone.alarms.alarm_offline > 0) || (firstTime == true)) { firstTime = false; String message = art.servers.Shared.getMessage("Controller online"); art.servers.Shared.println(name, message); } controllerclone.setAlarm("alarm_offline", false); controllerclone.setAlarm("alarm_disabled", false); controllerclone.setAlarm("alarm_invalid", false); // Update alarm_off and alarm_flashing boolean alarm_off = false; boolean alarm_flashing = false; for (M_ControllerStatusSubcontroller statusSubcontroller : controllerclone.getDeviceStatus().lsubcontroller) { if (statusSubcontroller.colorsMode == M_ControllerStatusSubcontroller.COLORS_OFF) alarm_off = true; if (statusSubcontroller.colorsMode == M_ControllerStatusSubcontroller.COLORS_FLASHING) alarm_flashing = true; } controllerclone.setAlarm("alarm_off", alarm_off); controllerclone.setAlarm("alarm_flashing", alarm_flashing); if (controllerclone.getAlarm("alarm_manual_control") > 0) { for (M_ControllerStatusSubcontroller statusSubcontroller : controllerclone.getDeviceStatus().lsubcontroller) { statusSubcontroller.localControl = DeviceCommands.CONDITION_YES; } } else if (controllerclone.getAlarm("alarm_manual_control") <= 0) { for (M_ControllerStatusSubcontroller statusSubcontroller : controllerclone.getDeviceStatus().lsubcontroller) { if (statusSubcontroller.userControlManual == DeviceCommands.CONDITION_NO) statusSubcontroller.localControl = DeviceCommands.CONDITION_NO; } } for (M_SubcontrollerConfiguration subcontrollerConfiguration : controllerclone.getDeviceConfiguration().lsubcontroller) { for (M_Plan m_plan : subcontrollerConfiguration.lplan) { m_plan.cycleTime = calculateCycleTime(m_plan, controllerclone, subcontrollerConfiguration.number); ALUVISA_Plan plan = m_plan.toAluvisaPlan(subcontrollerConfiguration); m_plan.numberOfPaths = plan.getPaths().size(); } } if (controllerclone.getDeviceStatus().lsubcontrollerUpdate != null) { if (controllerclone.getDeviceStatus().lsubcontrollerUpdate.size() <= 0) { controllerclone.getDeviceStatus().lsubcontrollerUpdate = null; } } Shared.model.updateDevice(controller, controllerclone); try { this.controller.getDeviceConfiguration().toAluvisa(); } catch (Exception e) { } } else if (this.lcontroller.size() > 0) { if ((controllerclone.alarms.alarm_offline > 0) || (firstTime == true)) { firstTime = false; String message = art.servers.Shared.getMessage("Controller online"); art.servers.Shared.println(name, message); } controllerclone.setAlarm("alarm_offline", false); controllerclone.setAlarm("alarm_disabled", false); controllerclone.setAlarm("alarm_invalid", false); controllerclone.getDeviceInformation().serverAddress = art.servers.Shared.configuration.listener.address; controllerclone.getDeviceInformation().serverPort = art.servers.Shared.configuration.listener.port; controllerclone.getDeviceInformation().serverAddressExternal = art.servers.Shared.configuration.listener.addressExternal; controllerclone.getDeviceInformation().serverPortExternal = art.servers.Shared.configuration.listener.portExternal; controllerclone.getDeviceInformation().serverServiceName = art.servers.Shared.controllerStatus.getApplication().getDeviceInformation().serverServiceName; for (M_SubcontrollerConfiguration subcontrollerConfiguration : controllerclone.getDeviceConfiguration().lsubcontroller) { for (M_Plan m_plan : subcontrollerConfiguration.lplan) { m_plan.cycleTime = calculateCycleTime(m_plan, controllerclone, subcontrollerConfiguration.number); ALUVISA_Plan plan = m_plan.toAluvisaPlan(subcontrollerConfiguration); m_plan.numberOfPaths = plan.getPaths().size(); } } // Have more than one subcontroller // Must be clone for every subcontroller for (M_Controller m_controllerSubcontroller : this.lcontroller) { M_Controller m_subcontroller = getSubcontrollerOnline(controllerclone, m_controllerSubcontroller); M_Controller m_subcontrollerCurrent = (M_Controller)Shared.model.getDevice(m_controllerSubcontroller.getIdentifier()); if (controllerclone.getDeviceStatus().lsubcontrollerUpdate != null) { if (controllerclone.getDeviceStatus().lsubcontrollerUpdate.size() <= 0) { controllerclone.getDeviceStatus().lsubcontrollerUpdate = null; } } Shared.model.updateDevice(m_subcontrollerCurrent, m_subcontroller); try { m_subcontrollerCurrent.getDeviceConfiguration().toAluvisa(); } catch (Exception e) { } } // this.controller.updateDevice(controllerclone); this.controller = controllerclone; try { this.controller.getDeviceConfiguration().toAluvisa(); } catch (Exception e) { } } } private M_Controller getSubcontrollerOffline(M_Controller controllerInput, M_Controller m_controllerSubcontroller) { int subcontroller = m_controllerSubcontroller.getDeviceInformation().subcontroller; M_Controller m_subcontroller = Serialization.clone(controllerInput); m_subcontroller.realtime = Serialization.clone(controllerInput.getDeviceRealtime()); m_subcontroller.getDeviceRealtime().identifier = m_controllerSubcontroller.getIdentifier(); // Update M_ControllerInformation with subcontroller information m_subcontroller.information = m_controllerSubcontroller.getDeviceInformation(); // Remove from M_ControllerConfiguration.lsubcontroller the other subcontrollers List lremoveConfiguration = new ArrayList(); for (M_SubcontrollerConfiguration subcontrollerConfiguration : m_subcontroller.getDeviceConfiguration().lsubcontroller) { if (subcontrollerConfiguration.number != subcontroller) { lremoveConfiguration.add(subcontrollerConfiguration); } } m_subcontroller.getDeviceConfiguration().lsubcontroller.removeAll(lremoveConfiguration); // Remove from M_ControllerStatus.lsubcontroller the other subcontrollers List lremoveStatus = new ArrayList(); for (M_ControllerStatusSubcontroller subcontrollerStatus : m_subcontroller.getDeviceStatus().lsubcontroller) { if (subcontrollerStatus.number != subcontroller) { lremoveStatus.add(subcontrollerStatus); } } m_subcontroller.getDeviceStatus().lsubcontroller.removeAll(lremoveStatus); if (m_subcontroller.getDeviceStatus().lsubcontrollerUpdate != null) { // Remove from M_ControllerStatus.lsubcontrollerUpdate the other subcontrollers List lremoveStatusUpdate = new ArrayList(); for (M_ControllerStatusSubcontroller subcontrollerStatusUpdate : m_subcontroller.getDeviceStatus().lsubcontrollerUpdate) { if (subcontrollerStatusUpdate.number != subcontroller) { lremoveStatusUpdate.add(subcontrollerStatusUpdate); } } m_subcontroller.getDeviceStatus().lsubcontrollerUpdate.removeAll(lremoveStatusUpdate); } // Remove from M_ControllerRealtime.lsubcontroller the other subcontrollers List lremoveRealtime = new ArrayList(); for (M_ControllerRealtimeSubcontroller subcontrollerRealtime : m_subcontroller.getDeviceRealtime().lsubcontroller) { if (subcontrollerRealtime.number != subcontroller) { lremoveRealtime.add(subcontrollerRealtime); } } m_subcontroller.getDeviceRealtime().lsubcontroller.removeAll(lremoveRealtime); return(m_subcontroller); } private M_Controller getSubcontrollerOnline(M_Controller controllerInput, M_Controller m_controllerSubcontroller) { int subcontroller = m_controllerSubcontroller.getDeviceInformation().subcontroller; M_Controller m_subcontroller = Serialization.clone(controllerInput); m_subcontroller.realtime = Serialization.clone(controllerInput.getDeviceRealtime()); m_subcontroller.getDeviceRealtime().identifier = m_controllerSubcontroller.getIdentifier(); // Update M_ControllerInformation with subcontroller information m_subcontroller.information = m_controllerSubcontroller.getDeviceInformation(); // Remove from M_ControllerConfiguration.lsubcontroller the other subcontrollers List lremoveConfiguration = new ArrayList(); for (M_SubcontrollerConfiguration subcontrollerConfiguration : m_subcontroller.getDeviceConfiguration().lsubcontroller) { if (subcontrollerConfiguration.number != subcontroller) { lremoveConfiguration.add(subcontrollerConfiguration); } } m_subcontroller.getDeviceConfiguration().lsubcontroller.removeAll(lremoveConfiguration); // Remove from M_ControllerStatus.lsubcontroller the other subcontrollers List lremoveStatus = new ArrayList(); for (M_ControllerStatusSubcontroller subcontrollerStatus : m_subcontroller.getDeviceStatus().lsubcontroller) { if (subcontrollerStatus.number != subcontroller) { lremoveStatus.add(subcontrollerStatus); } } m_subcontroller.getDeviceStatus().lsubcontroller.removeAll(lremoveStatus); // Remove from M_ControllerStatus.lsubcontrollerUpdate the other subcontrollers List lremoveStatusUpdate = new ArrayList(); for (M_ControllerStatusSubcontroller subcontrollerStatusUpdate : m_subcontroller.getDeviceStatus().lsubcontrollerUpdate) { if (subcontrollerStatusUpdate.number != subcontroller) { lremoveStatusUpdate.add(subcontrollerStatusUpdate); } } m_subcontroller.getDeviceStatus().lsubcontrollerUpdate.removeAll(lremoveStatusUpdate); // Remove from M_ControllerRealtime.lsubcontroller the other subcontrollers List lremoveRealtime = new ArrayList(); for (M_ControllerRealtimeSubcontroller subcontrollerRealtime : m_subcontroller.getDeviceRealtime().lsubcontroller) { if (subcontrollerRealtime.number != subcontroller) { lremoveRealtime.add(subcontrollerRealtime); } } m_subcontroller.getDeviceRealtime().lsubcontroller.removeAll(lremoveRealtime); // Update alarm_off and alarm_flashing boolean alarm_off = false; boolean alarm_flashing = false; for (M_ControllerStatusSubcontroller statusSubcontroller : m_subcontroller.getDeviceStatus().lsubcontroller) { if (statusSubcontroller.colorsMode == M_ControllerStatusSubcontroller.COLORS_OFF) alarm_off = true; if (statusSubcontroller.colorsMode == M_ControllerStatusSubcontroller.COLORS_FLASHING) alarm_flashing = true; } m_subcontroller.setAlarm("alarm_off", alarm_off); m_subcontroller.setAlarm("alarm_flashing", alarm_flashing); if (controllerInput.getAlarm("alarm_manual_control") > 0) { for (M_ControllerStatusSubcontroller statusSubcontroller : controllerInput.getDeviceStatus().lsubcontroller) { statusSubcontroller.localControl = DeviceCommands.CONDITION_YES; } } else if (controllerInput.getAlarm("alarm_manual_control") <= 0) { for (M_ControllerStatusSubcontroller statusSubcontroller : controllerInput.getDeviceStatus().lsubcontroller) { if (statusSubcontroller.userControlManual == DeviceCommands.CONDITION_NO) statusSubcontroller.localControl = DeviceCommands.CONDITION_NO; } } return(m_subcontroller); } // // // public DeviceAction[] sendCommands(int subcontroller, InteropParameters parameters) throws SerializationException, Exception { try { List result = new ArrayList(); M_ControllerCommands m_controllerCommands = parameters.getBodyContentValue(M_ControllerCommands.class); Shared.println(name, this.controller.getIdentifier() + " - Commands:"); Shared.println(name, Serialization.toPrettyString(m_controllerCommands)); if (m_controllerCommands.centralized != M_ControllerCommands.CONDITION_NOTHING) { M_ControllerCommands command = new M_ControllerCommands(); command.centralized = m_controllerCommands.centralized; result.add(centralized(subcontroller, parameters, command)); } if (m_controllerCommands.specialDemandSelection != null) { M_ControllerCommands command = new M_ControllerCommands(); command.specialDemandSelection = m_controllerCommands.specialDemandSelection; result.add(selectSpecialDemandSubcontroller(subcontroller, parameters, command)); } if (m_controllerCommands.specialDemandCancel != null) { M_ControllerCommands command = new M_ControllerCommands(); command.specialDemandCancel = m_controllerCommands.specialDemandCancel; result.add(cancelSpecialDemandSubcontroller(subcontroller, parameters, command)); } if ((m_controllerCommands.colorsMode != M_ControllerCommands.COLORS_NOTHING) || (m_controllerCommands.operationMode != M_ControllerCommands.OPERATIONMODE_NOTHING) || (m_controllerCommands.userControlManual != M_ControllerCommands.CONDITION_NOTHING) || ((m_controllerCommands.sptp != null) && (m_controllerCommands.sptp.operationMode != null)) || (m_controllerCommands.emergency != M_ControllerCommands.CONDITION_NOTHING)) { M_ControllerCommands command = new M_ControllerCommands(); command.colorsMode = m_controllerCommands.colorsMode; command.operationMode = m_controllerCommands.operationMode; command.userControlManual = m_controllerCommands.userControlManual; command.emergency = m_controllerCommands.emergency; if ((m_controllerCommands.sptp != null) && (m_controllerCommands.sptp.operationMode != null)) { command.sptp = new M_ControllerCommands_SPTP(); command.sptp.operationMode = new M_ControllerCommands_SPTP_OperationMode(); command.sptp.operationMode.mode = m_controllerCommands.sptp.operationMode.mode; } int planSelection = -1; // M_ControllerStatusSubcontroller.PLANSELECTION_COMPUTER; int coordinationMode = M_ControllerStatusSubcontroller.COORDINATION_COMPUTER; int centralizedMode = DeviceCommands.CONDITION_YES; int controlComputerDirectGroups = CONDITION_NO; int adaptative = DeviceCommands.CONDITION_NO; int adaptativeDetectors = DeviceCommands.CONDITION_NO; result.addAll(setStateSubcontroller(subcontroller, adaptative, adaptativeDetectors, centralizedMode, controlComputerDirectGroups, coordinationMode, planSelection, parameters, command)); } int userControlPlan = this.controller.getDeviceStatus().getStatusSubcontroller(subcontroller).userControlPlan; if (m_controllerCommands.userControlPlan != DeviceCommands.CONDITION_NOTHING) { userControlPlan = m_controllerCommands.userControlPlan; M_ControllerCommands command = new M_ControllerCommands(); command.userControlPlan = m_controllerCommands.userControlPlan; result.add(setUserControlPlan(subcontroller, parameters, command)); } if ((m_controllerCommands.recordablePlan != null) && (userControlPlan == DeviceCommands.CONDITION_YES)) { M_ControllerCommands command = new M_ControllerCommands(); command.recordablePlan = m_controllerCommands.recordablePlan; result.add(setRecordablePlanSubcontroller(subcontroller, parameters, command)); } if ((m_controllerCommands.recordablePlan != null) && (userControlPlan != DeviceCommands.CONDITION_YES)) { M_ControllerCommands command = new M_ControllerCommands(); command.recordablePlan = m_controllerCommands.recordablePlan; result.add(saveRecordablePlanSubcontroller(subcontroller, parameters, command)); } if ((m_controllerCommands.localPlan != DeviceCommands.CONDITION_NOTHING) && (userControlPlan == DeviceCommands.CONDITION_YES)) { M_ControllerCommands command = new M_ControllerCommands(); command.localPlan = m_controllerCommands.localPlan; result.add(setLocalPlanSubcontroller(subcontroller, parameters, command)); } if ((m_controllerCommands.forceCycle != null) && (userControlPlan == DeviceCommands.CONDITION_YES)) { M_ControllerCommands command = new M_ControllerCommands(); command.forceCycle = m_controllerCommands.forceCycle; result.add(createForceCycleRecordablePlan(subcontroller, command, parameters)); if (command.recordablePlan != null) { result.add(setRecordablePlanSubcontroller(subcontroller, parameters, command)); } } if (m_controllerCommands.updateTime == M_ControllerCommands.CONDITION_YES) { M_ControllerCommands command = new M_ControllerCommands(); command.updateTime = m_controllerCommands.updateTime; result.add(updateTime(parameters, command)); } if (m_controllerCommands.realtime != DeviceCommands.CONDITION_NOTHING) { M_ControllerCommands command = new M_ControllerCommands(); command.realtime = m_controllerCommands.realtime; result.add(setRealtime(parameters, command)); } if (m_controllerCommands.clearAlarms == DeviceCommands.CONDITION_YES) { M_ControllerCommands command = new M_ControllerCommands(); command.clearAlarms = m_controllerCommands.clearAlarms; result.add(clearAlarms(parameters, command)); } if (m_controllerCommands.shiftPhase == M_ControllerCommands.CONDITION_YES) { M_ControllerCommands command = new M_ControllerCommands(); command.shiftPhase = m_controllerCommands.shiftPhase; result.add(shiftPhase(parameters, command)); } if ((m_controllerCommands.sptp != null) && (m_controllerCommands.sptp.configuration != null)) { M_ControllerCommands command = new M_ControllerCommands(); command.sptp = new M_ControllerCommands_SPTP(); command.sptp.configuration = m_controllerCommands.sptp.configuration; result.add(sendSPTPConfiguration(subcontroller, parameters, command)); } if ((m_controllerCommands.sptp != null) && (m_controllerCommands.sptp.demands != null)) { M_ControllerCommands command = new M_ControllerCommands(); command.sptp = new M_ControllerCommands_SPTP(); command.sptp.demands = m_controllerCommands.sptp.demands; result.add(getBusDemandsController(subcontroller, parameters, command)); } return result.toArray(new DeviceAction[result.size()]); } finally { } } // public DeviceAction centralized(int subcontroller, InteropParameters parameters, M_ControllerCommands command) throws SerializationException { String language = (String)parameters.getParameterValue("language"); DeviceAction action = new DeviceAction(controller, parameters, command); action.actionName = command.getActionName(); try { M_SubcontrollerConfiguration subcontrollerConfiguration = controller.getDeviceConfiguration().getSubcontroller(subcontroller); if (subcontrollerConfiguration == null) throw new ServerException(Shared.getMessage("Subcontroller does not exist")); if (command.centralized == DeviceCommands.CONDITION_YES) { Shared.println(name, "CENTRALIZED!!!!!!"); this.forceCentralized = 1; } else if (command.centralized == DeviceCommands.CONDITION_NO) { Shared.println(name, "NOT CENTRALIZED!!!!!!"); this.forceCentralized = 0; } DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_CORRECT); action.setResult(actionResult); Shared.model.addAction(action); return action; } catch (Exception exception) { Shared.printstack(name, exception); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); return action; } } public DeviceAction sendSPTPConfiguration(int subcontroller, InteropParameters parameters, M_ControllerCommands command) throws SerializationException { String language = (String)parameters.getParameterValue("language"); DeviceAction action = new DeviceAction(controller, parameters, command); action.actionName = command.getActionName(); try { M_SubcontrollerConfiguration subcontrollerConfiguration = controller.getDeviceConfiguration().getSubcontroller(subcontroller); if (subcontrollerConfiguration == null) throw new ServerException(Shared.getMessage("Subcontroller does not exist")); Shared.println(name, command.sptp.configuration); commandsConfiguration = Serialization.deserialize(M_SPTP_Configuration.class, command.sptp.configuration); String resource = Serialization.toPrettyString(commandsConfiguration); Shared.traceInformation(name, "Activate sending of SPTP configuration tables", resource); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_CORRECT); action.setResult(actionResult); Shared.model.addAction(action); return action; } catch (Exception exception) { Shared.traceError(name, "Activate sending of SPTP configuration tables", exception); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); return action; } } public DeviceAction getBusDemandsController(int subcontroller, InteropParameters parameters, M_ControllerCommands command) throws SerializationException { String language = (String)parameters.getParameterValue("language"); DeviceAction action = new DeviceAction(controller, parameters, command); action.actionName = command.getActionName(); try { SimpleDateFormat sdfh = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); M_SubcontrollerConfiguration subcontrollerConfiguration = controller.getDeviceConfiguration().getSubcontroller(subcontroller); if (subcontrollerConfiguration == null) throw new ServerException(Shared.getMessage("Subcontroller does not exist")); String resource = Serialization.toPrettyString(command.sptp.demands); Shared.traceInformation(name, "Activate the request for bus demands", resource); commandsDemands = command.sptp.demands; DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_CORRECT); action.setResult(actionResult); Shared.model.addAction(action); return action; } catch (Exception exception) { Shared.traceError(name, "Activate the request for bus demands", exception); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); return action; } } public void getBusDemandsControllerReal(int subcontroller) throws SerializationException { try { SimpleDateFormat sdfh = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); M_SubcontrollerConfiguration subcontrollerConfiguration = controller.getDeviceConfiguration().getSubcontroller(subcontroller); if (subcontrollerConfiguration == null) throw new ServerException(Shared.getMessage("Subcontroller does not exist")); Calendar calendarStart = Calendar.getInstance(); calendarStart.setTimeInMillis(commandsDemands.starttime); Calendar calendarEnd = Calendar.getInstance(); calendarEnd.setTimeInMillis(commandsDemands.endtime); String resource = "From: " + sdfh.format(calendarStart.getTimeInMillis()) + ", To: " + sdfh.format(calendarEnd.getTimeInMillis()); Shared.traceInformation(name, "Asking for bus demands", resource); M_Message command = M_ProtocolConstructor.getBusDetectionsPeriod(subcontroller, calendarStart, calendarEnd, hasCRC); M_Request request = new M_Request(); request.controller = this; request.request = command; if (ColorsServer.TEST_SPTP == true) { String s = "Get Bus detections >> "; byte[] data = command.toByteArray(); for (int i=0; i=? AND activation<=?"); statement.setLong(1, from); statement.setLong(2, to); Shared.traceInformation(name, "Getting bus demands - count query", statement.toString()); resultSet = statement.executeQuery(); if (resultSet.next() == true) { result.total = resultSet.getInt(1); } } finally { try{resultSet.close();} catch (Exception e){}; try{statement.close();} catch (Exception e){}; } try { String query = "SELECT value FROM SPTP_DEMANDS WHERE activation>=? AND activation<=?"; query += " ORDER BY activation ASC"; if (offset >= 0) query += " OFFSET " + offset; if (limit > 0) query += " LIMIT " + limit; statement = persistence.getPreparedStatement(query); statement.setLong(1, from); statement.setLong(2, to); Shared.traceInformation(name, "Getting bus demands - results query", statement.toString()); resultSet = statement.executeQuery(); while (resultSet.next() == true) { String value = resultSet.getString(1); M_SPTP_Demand demand = Serialization.deserialize(M_SPTP_Demand.class, value); result.demands.add(demand); } } finally { try{resultSet.close();} catch (Exception e){}; try{statement.close();} catch (Exception e){}; } } catch (Exception exception) { Shared.traceError(name, "Get bus demands", exception); throw new SerializationException(Shared.getMessage("Error getting bus demands"), exception); } finally { try{resultSet.close();} catch (Exception e){}; try{statement.close();} catch (Exception e){}; } } public void addBusDemands(InteropParameters parameters) throws SerializationException { try { M_SPTP_Demand[] demands = parameters.getBodyContentValue(M_SPTP_Demand[].class); for (M_SPTP_Demand demand : demands) { Shared.controllerDatabase.historical_addObject(demand); } } catch (Exception exception) { Shared.traceError(name, "Get bus demands", exception); throw new SerializationException(Shared.getMessage("Error getting bus demands"), exception); } } public void checkNewUpdateCommands (M_Controller controllerclone) { try { List lremove = new ArrayList(); for (M_ControllerStatusSubcontroller statusSubcontroller : this.lsubcontrollerUpdate) { boolean found = false; if (controllerclone.getDeviceStatus().lsubcontrollerUpdate != null) { for (M_ControllerStatusSubcontroller statusSubcontrollerUpdate : controllerclone.getDeviceStatus().lsubcontrollerUpdate) { if (statusSubcontrollerUpdate.number == statusSubcontroller.number) { if (found == true) { lremove.add(statusSubcontrollerUpdate); } else { M_ControllerStatusSubcontroller currentStatusSubcontroller = controllerclone.getDeviceStatus().getStatusSubcontroller(statusSubcontroller.number); updateStatusSubcontroller(currentStatusSubcontroller, statusSubcontrollerUpdate, statusSubcontroller); found = true; } } } } if (found == false) { if (controllerclone.getDeviceStatus().lsubcontrollerUpdate == null) controllerclone.getDeviceStatus().lsubcontrollerUpdate = new ArrayList(); controllerclone.getDeviceStatus().lsubcontrollerUpdate.add(statusSubcontroller); } } if (controllerclone.getDeviceStatus().lsubcontrollerUpdate != null) { controllerclone.getDeviceStatus().lsubcontrollerUpdate.removeAll(lremove); } this.lsubcontrollerUpdate.clear(); lremove.clear(); HashMap hsubcontrollers = new HashMap(); if (controllerclone.getDeviceStatus().lsubcontrollerUpdate != null) { for (M_ControllerStatusSubcontroller statusSubcontrollerUpdate : controllerclone.getDeviceStatus().lsubcontrollerUpdate) { if (hsubcontrollers.containsKey(statusSubcontrollerUpdate.number) == true) { lremove.add(statusSubcontrollerUpdate); } else { hsubcontrollers.put(statusSubcontrollerUpdate.number, statusSubcontrollerUpdate.number); } } controllerclone.getDeviceStatus().lsubcontrollerUpdate.removeAll(lremove); if (controllerclone.getDeviceStatus().lsubcontrollerUpdate.size() == 0) { controllerclone.getDeviceStatus().lsubcontrollerUpdate = null; } else { for (M_ControllerStatusSubcontroller statusSubcontrollerUpdate : controllerclone.getDeviceStatus().lsubcontrollerUpdate) { M_ControllerStatusSubcontroller currentStatusSubcontroller = controllerclone.getDeviceStatus().getStatusSubcontroller(statusSubcontrollerUpdate.number); updateStatusSubcontroller(currentStatusSubcontroller, statusSubcontrollerUpdate, null); } } } if (this.lcontroller.size() == 0) { Shared.model.updateDevice(controller, controllerclone); } else if (this.lcontroller.size() > 0) { this.controller = controllerclone; } } catch (Exception e) { } } public void checkUpdateStatus (M_Controller controllerclone) { try { for (int i=1; i<=controllerclone.getDeviceConfiguration().lsubcontroller.size(); i++) { try { boolean remove = true; M_ControllerStatusSubcontroller currentStatusSubcontroller = controllerclone.getDeviceStatus().getStatusSubcontroller(i); M_ControllerStatusSubcontroller statusSubcontrollerUpdate = controllerclone.getDeviceStatus().getStatusSubcontrollerUpdate(i); if ((statusSubcontrollerUpdate.recordablePlan != null) && (currentStatusSubcontroller.recordablePlan != null)) { if (Serialization.equals(statusSubcontrollerUpdate.recordablePlan, currentStatusSubcontroller.recordablePlan) == false) { remove = false; // Send again save recordable plan command M_ControllerCommands commands = new M_ControllerCommands(); commands.recordablePlan = new ALUVISA_Plan(); commands.recordablePlan.initialise(controllerclone.getDeviceConfiguration().getSubcontroller(currentStatusSubcontroller.number), statusSubcontrollerUpdate.recordablePlan); InteropParameters parameters = new InteropParameters(); parameters.addParameter("language", "en-GB"); parameters.addParameter("username", "system"); parameters.addParameter("computer", controller.getDeviceInformation().serverAddress); parameters.addBodycontent(commands); sendCommands(currentStatusSubcontroller.number, parameters); } } else if ((statusSubcontrollerUpdate.recordablePlan != null) && (currentStatusSubcontroller.recordablePlan == null)) { remove = false; // Send again save recordable plan command M_ControllerCommands commands = new M_ControllerCommands(); commands.recordablePlan = new ALUVISA_Plan(); commands.recordablePlan.initialise(controllerclone.getDeviceConfiguration().getSubcontroller(currentStatusSubcontroller.number), statusSubcontrollerUpdate.recordablePlan); InteropParameters parameters = new InteropParameters(); parameters.addParameter("language", "en-GB"); parameters.addParameter("username", "system"); parameters.addParameter("computer", controller.getDeviceInformation().serverAddress); parameters.addBodycontent(commands); sendCommands(currentStatusSubcontroller.number, parameters); } if (stateSubcontrollerDifferent(currentStatusSubcontroller, statusSubcontrollerUpdate) == true) { remove = false; // Send again set state subcontroller command M_ControllerCommands commands = new M_ControllerCommands(); int adaptative = CONDITION_NO; int adaptativeDetectors = statusSubcontrollerUpdate.adaptativeDetectors; int centralizedMode = statusSubcontrollerUpdate.centralizedMode; commands.colorsMode = statusSubcontrollerUpdate.colorsMode; int controlComputerDirectGroups = statusSubcontrollerUpdate.controlComputerDirectGroups; int coordinationMode = statusSubcontrollerUpdate.coordinationMode; commands.emergency = statusSubcontrollerUpdate.emergency; commands.userControlManual = statusSubcontrollerUpdate.userControlManual; commands.operationMode = statusSubcontrollerUpdate.operationMode; int planSelection = statusSubcontrollerUpdate.planSelection; InteropParameters parameters = new InteropParameters(); parameters.addParameter("language", "en-GB"); parameters.addParameter("username", "system"); parameters.addParameter("computer", controller.getDeviceInformation().serverAddress); parameters.addBodycontent(commands); setStateSubcontroller(statusSubcontrollerUpdate.number, adaptative, adaptativeDetectors, centralizedMode, controlComputerDirectGroups, coordinationMode, planSelection, parameters, commands); } if ((statusSubcontrollerUpdate.plan != currentStatusSubcontroller.plan) && (currentStatusSubcontroller.planSelection != M_ControllerStatusSubcontroller.PLANSELECTION_TIMETABLE) && (statusSubcontrollerUpdate.planSelection != M_ControllerStatusSubcontroller.PLANSELECTION_TIMETABLE)) { remove = false; if (statusSubcontrollerUpdate.plan == 0) { // Send again set plan command M_ControllerCommands commands = new M_ControllerCommands(); InteropParameters parameters = new InteropParameters(); parameters.addParameter("language", "en-GB"); parameters.addParameter("username", "system"); parameters.addParameter("computer", controller.getDeviceInformation().serverAddress); parameters.addBodycontent(commands); setPlanSubcontroller(currentStatusSubcontroller.number, parameters, commands); } else if (statusSubcontrollerUpdate.plan > 0) { // Send again set plan command M_ControllerCommands commands = new M_ControllerCommands(); commands.localPlan = statusSubcontrollerUpdate.plan; InteropParameters parameters = new InteropParameters(); parameters.addParameter("language", "en-GB"); parameters.addParameter("username", "system"); parameters.addParameter("computer", controller.getDeviceInformation().serverAddress); parameters.addBodycontent(commands); setLocalPlanSubcontroller(currentStatusSubcontroller.number, parameters, commands); } } if ((remove == true) && (controllerclone.getDeviceStatus().lsubcontrollerUpdate != null)) { controllerclone.getDeviceStatus().lsubcontrollerUpdate.remove(statusSubcontrollerUpdate); } } catch (Exception e) { } } } catch (Exception e) { // Shared.printstack(name, e); } } private DeviceAction createForceCycleRecordablePlan (int subcontroller, M_ControllerCommands commands, InteropParameters parameters) { String language = (String)parameters.getParameterValue("language"); DeviceAction action = new DeviceAction(controller, parameters, commands); action.actionName = commands.getActionName(); try { M_ControllerStatusSubcontroller statusSubcontroller = this.controller.getDeviceStatus().getStatusSubcontroller(subcontroller); M_SubcontrollerConfiguration configurationSubcontroller = this.controller.getDeviceConfiguration().getSubcontroller(subcontroller); commands.recordablePlan = configurationSubcontroller.getAluvisaPlan(statusSubcontroller.plan); if (commands.recordablePlan.structure != commands.forceCycle.structure) { commands.recordablePlan = null; DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, Shared.getMessage("Structure not valid")); action.setResult(actionResult); Shared.model.addAction(action); return action; } if (commands.recordablePlan.changeCycle(commands.forceCycle.cycle) == false) { commands.recordablePlan = null; DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, Shared.getMessage("Error forcing cycle time")); action.setResult(actionResult); Shared.model.addAction(action); return action; } float[] lphases = new float[commands.forceCycle.lphases.size()]; for (int i=0; i public DeviceAction setRecordablePlanSubcontroller(int subcontroller, InteropParameters parameters, M_ControllerCommands command) throws SerializationException { String language = (String)parameters.getParameterValue("language"); DeviceAction action = new DeviceAction(controller, parameters, command); action.actionName = command.getActionName(); try { M_ControllerStatusSubcontroller currentStatusSubcontroller = controller.getDeviceStatus().getStatusSubcontroller(subcontroller); // Y el algoritmo como lo envía?????? // if ((command.userControlPlan != M_ControllerCommands.CONDITION_YES) && // (currentStatusSubcontroller.userControlPlan != M_ControllerCommands.CONDITION_YES)) // { // DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, Shared.getMessage("User control plan not enabled")); // action.setResult(actionResult); // Shared.model.addAction(action); // return action; // } ALUVISA_Plan recordablePlan = command.recordablePlan; if (recordablePlan.offset > 256) { DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, Shared.getMessage("Offset value is not valid")); action.setResult(actionResult); Shared.model.addAction(action); return action; } M_ControllerConfiguration controllerConfiguration = controller.getDeviceConfiguration(); M_SubcontrollerConfiguration subcontrollerConfiguration = controllerConfiguration.getSubcontroller(subcontroller); if (subcontrollerConfiguration == null) throw new ServerException(Shared.getMessage("Subcontroller does not exist")); try { M_Structure structure = subcontrollerConfiguration.getStructure(recordablePlan.structure); } catch (Exception exception) { DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); return action; } ALUVISA_Link link1 = command.recordablePlan.lLink.get(0); M_Intergreen intergren = subcontrollerConfiguration.getIntergreenPositionsTime(link1); M_IntergreensPositionTimes intergreensPositionTimes = subcontrollerConfiguration.getIntergreensPositionTimes(intergren); int transitionsToTimesTable = intergreensPositionTimes.number; try { M_IntergreenToTimeTable intergreenTable = subcontrollerConfiguration.getIntergreenToTimeTable(transitionsToTimesTable); } catch (Exception exception) { DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); return action; } M_MinimumExtension minimumExtension = subcontrollerConfiguration.getMinimumExtension(command.recordablePlan); int minimumAndExtensionTimesTable = minimumExtension.number; M_MinimumExtension minimumTable = null; try { minimumTable = subcontrollerConfiguration.getMinimumExtension(minimumAndExtensionTimesTable); } catch (Exception exception) { DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); return action; } for (int i=0; i 120) { DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, Shared.getMessage("Phase duration is not valid")); action.setResult(actionResult); Shared.model.addAction(action); return action; } if (duration < minimumTable.lMinimum.get(i).intValue()) { DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, Shared.getMessage("Phase duration lower than minimum time defined")); action.setResult(actionResult); Shared.model.addAction(action); return action; } } boolean found = false; for (M_ControllerStatusSubcontroller statusSubcontroller : this.lsubcontrollerUpdate) { if (statusSubcontroller.number == subcontroller) { found = true; if (statusSubcontroller.recordablePlan == null) statusSubcontroller.recordablePlan = new M_Plan(); statusSubcontroller.recordablePlan.controlMode = recordablePlan.controlMode; statusSubcontroller.recordablePlan.minimumAndExtensionTimesTable = minimumAndExtensionTimesTable; statusSubcontroller.recordablePlan.offset = recordablePlan.offset; statusSubcontroller.recordablePlan.number = 0; // recordablePlan.number; statusSubcontroller.recordablePlan.structure = recordablePlan.structure; statusSubcontroller.recordablePlan.transitionsToTimesTable = transitionsToTimesTable; statusSubcontroller.recordablePlan.lPhaseTime.clear(); for (ALUVISA_Phase phase : recordablePlan.lPhase) { statusSubcontroller.recordablePlan.lPhaseTime.add(phase.maximumTime); } } } if (found == false) { M_ControllerStatusSubcontroller statusSubcontroller = new M_ControllerStatusSubcontroller(); statusSubcontroller.number = subcontroller; if (statusSubcontroller.recordablePlan == null) statusSubcontroller.recordablePlan = new M_Plan(); statusSubcontroller.recordablePlan.controlMode = recordablePlan.controlMode; statusSubcontroller.recordablePlan.minimumAndExtensionTimesTable = minimumAndExtensionTimesTable; statusSubcontroller.recordablePlan.offset = recordablePlan.offset; statusSubcontroller.recordablePlan.number = 0; // recordablePlan.number; statusSubcontroller.recordablePlan.structure = recordablePlan.structure; statusSubcontroller.recordablePlan.transitionsToTimesTable = transitionsToTimesTable; statusSubcontroller.recordablePlan.lPhaseTime.clear(); for (ALUVISA_Phase phase : recordablePlan.lPhase) { statusSubcontroller.recordablePlan.lPhaseTime.add(phase.maximumTime); } this.lsubcontrollerUpdate.add(statusSubcontroller); } M_Message request = M_ProtocolConstructor.setRecordablePlan(recordablePlan, subcontroller, transitionsToTimesTable, minimumAndExtensionTimesTable, hasCRC); getControllerConnection().send(request.toByteArray()); setPlanSubcontroller(subcontroller, parameters, command); // long referenceTime = 0; // M_Message requestPlan = M_ProtocolConstructor.setPlan(0, referenceTime, subcontroller, hasCRC); // getControllerConnection().send(requestPlan.toByteArray()); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_CORRECT); action.setResult(actionResult); Shared.model.addAction(action); return action; } catch (Exception exception) { Shared.printstack(name, exception); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); return action; } } // // public DeviceAction saveRecordablePlanSubcontroller(int subcontroller, InteropParameters parameters, M_ControllerCommands command) throws SerializationException { String language = (String)parameters.getParameterValue("language"); DeviceAction action = new DeviceAction(controller, parameters, command); action.actionName = command.getActionName(); try { M_ControllerStatusSubcontroller currentStatusSubcontroller = controller.getDeviceStatus().getStatusSubcontroller(subcontroller); ALUVISA_Plan recordablePlan = command.recordablePlan; if (recordablePlan.offset > 256) { DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, Shared.getMessage("Offset value is not valid")); action.setResult(actionResult); Shared.model.addAction(action); return action; } M_ControllerConfiguration controllerConfiguration = controller.getDeviceConfiguration(); M_SubcontrollerConfiguration subcontrollerConfiguration = controllerConfiguration.getSubcontroller(subcontroller); if (subcontrollerConfiguration == null) throw new ServerException(Shared.getMessage("Subcontroller does not exist")); try { M_Structure structure = subcontrollerConfiguration.getStructure(recordablePlan.structure); } catch (Exception exception) { DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); return action; } ALUVISA_Link link1 = command.recordablePlan.lLink.get(0); M_Intergreen intergren = subcontrollerConfiguration.getIntergreenPositionsTime(link1); M_IntergreensPositionTimes intergreensPositionTimes = subcontrollerConfiguration.getIntergreensPositionTimes(intergren); int transitionsToTimesTable = intergreensPositionTimes.number; try { M_IntergreenToTimeTable intergreenTable = subcontrollerConfiguration.getIntergreenToTimeTable(transitionsToTimesTable); } catch (Exception exception) { DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); return action; } M_MinimumExtension minimumExtension = subcontrollerConfiguration.getMinimumExtension(command.recordablePlan); int minimumAndExtensionTimesTable = minimumExtension.number; M_MinimumExtension minimumTable = null; try { minimumTable = subcontrollerConfiguration.getMinimumExtension(minimumAndExtensionTimesTable); } catch (Exception exception) { DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); return action; } for (int i=0; i 120) { DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, Shared.getMessage("Phase duration is not valid")); action.setResult(actionResult); Shared.model.addAction(action); return action; } if (duration < minimumTable.lMinimum.get(i).intValue()) { DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, Shared.getMessage("Phase duration lower than minimum time defined")); action.setResult(actionResult); Shared.model.addAction(action); return action; } } boolean found = false; for (M_ControllerStatusSubcontroller statusSubcontroller : this.lsubcontrollerUpdate) { if (statusSubcontroller.number == subcontroller) { found = true; statusSubcontroller.recordablePlan.controlMode = recordablePlan.controlMode; statusSubcontroller.recordablePlan.minimumAndExtensionTimesTable = minimumAndExtensionTimesTable; statusSubcontroller.recordablePlan.offset = recordablePlan.offset; statusSubcontroller.recordablePlan.number = 0; // recordablePlan.number; statusSubcontroller.recordablePlan.structure = recordablePlan.structure; statusSubcontroller.recordablePlan.transitionsToTimesTable = transitionsToTimesTable; statusSubcontroller.recordablePlan.lPhaseTime.clear(); for (ALUVISA_Phase phase : recordablePlan.lPhase) { statusSubcontroller.recordablePlan.lPhaseTime.add(phase.maximumTime); } } } if (found == false) { M_ControllerStatusSubcontroller statusSubcontroller = new M_ControllerStatusSubcontroller(); statusSubcontroller.number = subcontroller; statusSubcontroller.recordablePlan = new M_Plan(); statusSubcontroller.recordablePlan.controlMode = recordablePlan.controlMode; statusSubcontroller.recordablePlan.minimumAndExtensionTimesTable = minimumAndExtensionTimesTable; statusSubcontroller.recordablePlan.offset = recordablePlan.offset; statusSubcontroller.recordablePlan.number = 0; // recordablePlan.number; statusSubcontroller.recordablePlan.structure = recordablePlan.structure; statusSubcontroller.recordablePlan.transitionsToTimesTable = transitionsToTimesTable; statusSubcontroller.recordablePlan.lPhaseTime.clear(); for (ALUVISA_Phase phase : recordablePlan.lPhase) { statusSubcontroller.recordablePlan.lPhaseTime.add(phase.maximumTime); } this.lsubcontrollerUpdate.add(statusSubcontroller); } M_Message request = M_ProtocolConstructor.setRecordablePlan(recordablePlan, subcontroller, transitionsToTimesTable, minimumAndExtensionTimesTable, hasCRC); getControllerConnection().send(request.toByteArray()); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_CORRECT); action.setResult(actionResult); Shared.model.addAction(action); return action; } catch (Exception exception) { Shared.printstack(name, exception); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); return action; } } // // public DeviceAction selectSpecialDemandSubcontroller(int subcontroller, InteropParameters parameters, M_ControllerCommands command) throws SerializationException { String language = (String)parameters.getParameterValue("language"); DeviceAction action = new DeviceAction(controller, parameters, command); action.actionName = command.getActionName(); try { M_ControllerStatusSubcontroller currentStatusSubcontroller = controller.getDeviceStatus().getStatusSubcontroller(subcontroller); M_ControllerConfiguration controllerConfiguration = controller.getDeviceConfiguration(); M_SubcontrollerConfiguration subcontrollerConfiguration = controller.getDeviceConfiguration().getSubcontroller(subcontroller); if (subcontrollerConfiguration == null) throw new ServerException(Shared.getMessage("Subcontroller does not exist")); M_ControllerCommandsSpecialDemand commandsSpecialDemand = command.specialDemandSelection; M_Message request = M_ProtocolConstructor.selectSpecialDemand(commandsSpecialDemand, subcontroller, hasCRC); getControllerConnection().send(request.toByteArray()); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_CORRECT); action.setResult(actionResult); Shared.model.addAction(action); return action; } catch (Exception exception) { Shared.printstack(name, exception); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); return action; } } // // public DeviceAction cancelSpecialDemandSubcontroller(int subcontroller, InteropParameters parameters, M_ControllerCommands command) throws SerializationException { String language = (String)parameters.getParameterValue("language"); DeviceAction action = new DeviceAction(controller, parameters, command); action.actionName = command.getActionName(); try { M_ControllerStatusSubcontroller currentStatusSubcontroller = controller.getDeviceStatus().getStatusSubcontroller(subcontroller); M_ControllerConfiguration controllerConfiguration = controller.getDeviceConfiguration(); M_SubcontrollerConfiguration subcontrollerConfiguration = controller.getDeviceConfiguration().getSubcontroller(subcontroller); if (subcontrollerConfiguration == null) throw new ServerException(Shared.getMessage("Subcontroller does not exist")); M_ControllerCommandsSpecialDemand commandsSpecialDemand = command.specialDemandSelection; M_Message request = M_ProtocolConstructor.cancelSpecialDemand(commandsSpecialDemand, subcontroller, hasCRC); getControllerConnection().send(request.toByteArray()); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_CORRECT); action.setResult(actionResult); Shared.model.addAction(action); return action; } catch (Exception exception) { Shared.printstack(name, exception); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); return action; } } // // public DeviceAction setLocalPlanSubcontroller(int subcontroller, InteropParameters parameters, M_ControllerCommands command) throws SerializationException { String language = (String)parameters.getParameterValue("language"); DeviceAction action = new DeviceAction(controller, parameters, command); action.actionName = command.getActionName(); try { M_ControllerConfiguration controllerConfiguration = controller.getDeviceConfiguration(); M_SubcontrollerConfiguration subcontrollerConfiguration = controllerConfiguration.getSubcontroller(subcontroller); if (subcontrollerConfiguration == null) throw new ServerException(Shared.getMessage("Subcontroller does not exist")); try { M_Plan m_plan = subcontrollerConfiguration.getMPlan(command.localPlan); } catch (Exception exception) { DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.toString()); action.setResult(actionResult); Shared.model.addAction(action); return action; } boolean found = false; for (M_ControllerStatusSubcontroller statusSubcontroller : this.lsubcontrollerUpdate) { if (statusSubcontroller.number == subcontroller) { found = true; statusSubcontroller.plan = command.localPlan; } } if (found == false) { M_ControllerStatusSubcontroller statusSubcontroller = new M_ControllerStatusSubcontroller(); statusSubcontroller.number = subcontroller; statusSubcontroller.plan = command.localPlan; this.lsubcontrollerUpdate.add(statusSubcontroller); } sendLocalPlanSubcontroller(subcontroller, parameters, command); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_CORRECT); action.setResult(actionResult); Shared.model.addAction(action); return action; } catch (Exception exception) { Shared.printstack(name, exception); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); return action; } } // // public DeviceAction setUserControlPlan(int subcontroller, InteropParameters parameters, M_ControllerCommands command) throws SerializationException { String language = (String)parameters.getParameterValue("language"); DeviceAction action = new DeviceAction(controller, parameters, command); action.actionName = command.getActionName(); try { this.forcedUserControlPlan[subcontroller-1] = command.userControlPlan; if (command.userControlPlan == DeviceCommands.CONDITION_NO) { // TODO // Release forced plan // Now for Ghana I will send timetable M_ControllerCommands commandsTimetable = new M_ControllerCommands(); int planSelection = M_ControllerStatusSubcontroller.PLANSELECTION_TIMETABLE; int coordinationMode = M_ControllerStatusSubcontroller.COORDINATION_COMPUTER; int centralizedMode = DeviceCommands.CONDITION_YES; int controlComputerDirectGroups = CONDITION_NO; int adaptative = DeviceCommands.CONDITION_NO; int adaptativeDetectors = DeviceCommands.CONDITION_NO; setStateSubcontroller(subcontroller, adaptative, adaptativeDetectors, centralizedMode, controlComputerDirectGroups, coordinationMode, planSelection, parameters, commandsTimetable); } DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_CORRECT); action.setResult(actionResult); Shared.model.addAction(action); return action; } catch (Exception exception) { Shared.printstack(name, exception); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); return action; } } // // public List setPlanSubcontroller(int subcontroller, InteropParameters parameters, M_ControllerCommands command) throws SerializationException { List lresult = new ArrayList(); String language = (String)parameters.getParameterValue("language"); DeviceAction action = new DeviceAction(controller, parameters, command); action.actionName = command.getActionName(); try { // Before setting plan controller must be configure in computer mode and with centralized enabled M_ControllerCommands stateCommand = new M_ControllerCommands(); int planSelection = M_ControllerStatusSubcontroller.PLANSELECTION_COMPUTER; int coordinationMode = M_ControllerStatusSubcontroller.COORDINATION_COMPUTER; int centralizedMode = DeviceCommands.CONDITION_YES; int controlComputerDirectGroups = CONDITION_NO; int adaptative = DeviceCommands.CONDITION_NO; int adaptativeDetectors = DeviceCommands.CONDITION_NO; List stateAction = setStateSubcontroller(subcontroller, adaptative, adaptativeDetectors, centralizedMode, controlComputerDirectGroups, coordinationMode, planSelection, parameters, stateCommand); lresult.addAll(stateAction); M_ControllerConfiguration controllerConfiguration = controller.getDeviceConfiguration(); M_SubcontrollerConfiguration subcontrollerConfiguration = controllerConfiguration.getSubcontroller(subcontroller); if (subcontrollerConfiguration == null) { DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, Shared.getMessage("Subcontroller does not exist")); action.setResult(actionResult); Shared.model.addAction(action); lresult.add(action); return lresult; } // It is the recordable plan (0) // Must be checked that everything is ok M_ControllerStatus controllerStatus = controller.getDeviceStatus(); M_ControllerStatusSubcontroller subcontrollerStatus = controllerStatus.getStatusSubcontroller(subcontroller); if (subcontrollerStatus.recordablePlan == null) { DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, Shared.getMessage("Recordable plan does not exist")); action.setResult(actionResult); Shared.model.addAction(action); lresult.add(action); return lresult; } boolean found = false; for (M_ControllerStatusSubcontroller statusSubcontroller : this.lsubcontrollerUpdate) { if (statusSubcontroller.number == subcontroller) { found = true; statusSubcontroller.plan = 0; statusSubcontroller.planSelectionComputer = M_ControllerStatusSubcontroller.PLANSELECTION_COMPUTER_PLAN_SELECTION; statusSubcontroller.number = subcontroller; } } if (found == false) { M_ControllerStatusSubcontroller statusSubcontroller = new M_ControllerStatusSubcontroller(); statusSubcontroller.number = subcontroller; statusSubcontroller.plan = 0; statusSubcontroller.planSelectionComputer = M_ControllerStatusSubcontroller.PLANSELECTION_COMPUTER_PLAN_SELECTION; statusSubcontroller.number = subcontroller; this.lsubcontrollerUpdate.add(statusSubcontroller); } long referenceTime = 0; M_Message request = M_ProtocolConstructor.setPlan(0, referenceTime, subcontroller, hasCRC); getControllerConnection().send(request.toByteArray()); this.controller.getDeviceStatus().getStatusSubcontroller(subcontroller).planSelectionComputer = M_ControllerStatusSubcontroller.PLANSELECTION_COMPUTER_PLAN_SELECTION; DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_CORRECT); action.setResult(actionResult); Shared.model.addAction(action); lresult.add(action); return lresult; } catch (Exception exception) { DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); lresult.add(action); return lresult; } } // // public List sendLocalPlanSubcontroller(int subcontroller, InteropParameters parameters, M_ControllerCommands command) throws SerializationException { List lresult = new ArrayList(); String language = (String)parameters.getParameterValue("language"); DeviceAction action = new DeviceAction(controller, parameters, command); action.actionName = command.getActionName(); try { // Before setting plan controller must be configure in computer mode and with centralized enabled M_ControllerCommands stateCommand = new M_ControllerCommands(); int planSelection = M_ControllerStatusSubcontroller.PLANSELECTION_COMPUTER; int coordinationMode = M_ControllerStatusSubcontroller.COORDINATION_COMPUTER; int centralizedMode = DeviceCommands.CONDITION_YES; int controlComputerDirectGroups = CONDITION_NO; int adaptative = DeviceCommands.CONDITION_NO; int adaptativeDetectors = DeviceCommands.CONDITION_NO; List stateAction = setStateSubcontroller(subcontroller, adaptative, adaptativeDetectors, centralizedMode, controlComputerDirectGroups, coordinationMode, planSelection, parameters, stateCommand); lresult.addAll(stateAction); M_ControllerConfiguration controllerConfiguration = controller.getDeviceConfiguration(); M_SubcontrollerConfiguration subcontrollerConfiguration = controllerConfiguration.getSubcontroller(subcontroller); if (subcontrollerConfiguration == null) { DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, Shared.getMessage("Subcontroller does not exist")); action.setResult(actionResult); Shared.model.addAction(action); lresult.add(action); return lresult; } boolean found = false; for (M_ControllerStatusSubcontroller statusSubcontroller : this.lsubcontrollerUpdate) { if (statusSubcontroller.number == subcontroller) { found = true; statusSubcontroller.plan = command.localPlan; statusSubcontroller.planSelectionComputer = M_ControllerStatusSubcontroller.PLANSELECTION_COMPUTER_PLAN_SELECTION; statusSubcontroller.number = subcontroller; } } if (found == false) { M_ControllerStatusSubcontroller statusSubcontroller = new M_ControllerStatusSubcontroller(); statusSubcontroller.number = subcontroller; statusSubcontroller.plan = command.localPlan; statusSubcontroller.planSelectionComputer = M_ControllerStatusSubcontroller.PLANSELECTION_COMPUTER_PLAN_SELECTION; statusSubcontroller.number = subcontroller; this.lsubcontrollerUpdate.add(statusSubcontroller); } long referenceTime = 0; // TODO?????? M_Message request = M_ProtocolConstructor.setPlan(command.localPlan, referenceTime, subcontroller, hasCRC); getControllerConnection().send(request.toByteArray()); this.controller.getDeviceStatus().getStatusSubcontroller(subcontroller).planSelectionComputer = M_ControllerStatusSubcontroller.PLANSELECTION_COMPUTER_PLAN_SELECTION; DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_CORRECT); action.setResult(actionResult); Shared.model.addAction(action); lresult.add(action); return lresult; } catch (Exception exception) { DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); lresult.add(action); return lresult; } } // // public DeviceAction updateTime(InteropParameters parameters, M_ControllerCommands command) throws SerializationException { String language = (String)parameters.getParameterValue("language"); DeviceAction action = new DeviceAction(controller, parameters, command); action.actionName = command.getActionName(); try { M_Message request = M_ProtocolConstructor.setDateTime(0x00, System.currentTimeMillis()+1000, hasCRC); getControllerConnection().send(request.toByteArray()); M_Message requestHTR = M_ProtocolConstructor.HTR(); getControllerConnection().send(requestHTR.toByteArray()); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_CORRECT); action.setResult(actionResult); Shared.model.addAction(action); return action; } catch (Exception exception) { DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); return action; } } // // public DeviceAction setRealtime(InteropParameters parameters, M_ControllerCommands command) throws SerializationException { String language = (String)parameters.getParameterValue("language"); DeviceAction action = new DeviceAction(controller, parameters, command); action.actionName = command.getActionName(); try { if (command.realtime == DeviceCommands.CONDITION_ENABLED) { this.forceRealtime = 1; } else if (command.realtime == DeviceCommands.CONDITION_DISABLED) { this.forceRealtime = 0; } DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_CORRECT); action.setResult(actionResult); Shared.model.addAction(action); return action; } catch (Exception exception) { DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); return action; } } // // public List setStateSubcontroller(int subcontroller, int adaptative, int adaptativeDetectors, int centralizedMode, int controlComputerDirectGroups, int coordinationMode, int planSelectionReceived, InteropParameters parameters, M_ControllerCommands command) throws SerializationException { String language = (String)parameters.getParameterValue("language"); List laction = new ArrayList(); try { int colorsMode = command.colorsMode; int operationMode = command.operationMode; int userControlManual = command.userControlManual; int emergency = command.emergency; int sptpOperationMode = -1; if ((command.sptp != null) && (command.sptp.operationMode != null)) { sptpOperationMode = command.sptp.operationMode.mode; } M_ControllerConfiguration controllerConfiguration = controller.getDeviceConfiguration(); M_SubcontrollerConfiguration subcontrollerConfiguration = controllerConfiguration.getSubcontroller(subcontroller); if (subcontrollerConfiguration == null) { if (command.colorsMode != M_ControllerCommands.COLORS_NOTHING) { M_ControllerCommands specificCommand = new M_ControllerCommands(); specificCommand.colorsMode = command.colorsMode; DeviceAction action = new DeviceAction(controller, parameters, specificCommand); action.actionName = specificCommand.getActionName(); DeviceActionResult actionResult2 = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, Shared.getMessage("Subcontroller does not exist")); action.setResult(actionResult2); Shared.model.addAction(action); laction.add(action); } if (command.operationMode != M_ControllerCommands.OPERATIONMODE_NOTHING) { M_ControllerCommands specificCommand = new M_ControllerCommands(); specificCommand.operationMode = command.operationMode; DeviceAction action2 = new DeviceAction(controller, parameters, specificCommand); action2.actionName = specificCommand.getActionName(); DeviceActionResult actionResult2 = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, Shared.getMessage("Subcontroller does not exist")); action2.setResult(actionResult2); Shared.model.addAction(action2); laction.add(action2); } if (command.userControlManual != M_ControllerCommands.CONDITION_NOTHING) { M_ControllerCommands specificCommand = new M_ControllerCommands(); specificCommand.userControlManual = command.userControlManual; DeviceAction action2 = new DeviceAction(controller, parameters, specificCommand); action2.actionName = specificCommand.getActionName(); DeviceActionResult actionResult2 = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, Shared.getMessage("Subcontroller does not exist")); action2.setResult(actionResult2); Shared.model.addAction(action2); laction.add(action2); } if (command.emergency != M_ControllerCommands.CONDITION_NOTHING) { M_ControllerCommands specificCommand = new M_ControllerCommands(); specificCommand.emergency = command.emergency; DeviceAction action2 = new DeviceAction(controller, parameters, specificCommand); action2.actionName = specificCommand.getActionName(); DeviceActionResult actionResult2 = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, Shared.getMessage("Subcontroller does not exist")); action2.setResult(actionResult2); Shared.model.addAction(action2); laction.add(action2); } return laction; } M_ControllerStatusSubcontroller subcontrollerStatus = this.controller.getDeviceStatus().getStatusSubcontroller(subcontroller); boolean allNothing = true; if (colorsMode == M_ControllerCommands.COLORS_NOTHING) { colorsMode = subcontrollerStatus.colorsMode; } else { allNothing = false; } if (userControlManual == M_ControllerCommands.CONDITION_NOTHING) { userControlManual = subcontrollerStatus.userControlManual; } else { allNothing = false; } if (operationMode == M_ControllerCommands.OPERATIONMODE_NOTHING) { operationMode = subcontrollerStatus.operationMode; } else { allNothing = false; } if (emergency == M_ControllerCommands.CONDITION_NOTHING) { emergency = subcontrollerStatus.emergency; } else { allNothing = false; } if (sptpOperationMode == -1) { sptpOperationMode = subcontrollerStatus.sptpOperation; } else { allNothing = false; } int planSelection = planSelectionReceived; if (planSelection < 0) { planSelection = subcontrollerStatus.planSelection; if (planSelection < 0) { planSelection = M_ControllerStatusSubcontroller.PLANSELECTION_COMPUTER; } } if ((colorsMode < M_ControllerCommands.COLORS_OFF) || (colorsMode > M_ControllerCommands.COLORS_COLORS)) { M_ControllerCommands specificCommand = new M_ControllerCommands(); specificCommand.colorsMode = command.colorsMode; DeviceAction action = new DeviceAction(controller, parameters, specificCommand); action.actionName = specificCommand.getActionName(); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, Shared.getMessage("Colors mode value is not valid")); action.setResult(actionResult); Shared.model.addAction(action); laction.add(action); if (command.operationMode != M_ControllerCommands.OPERATIONMODE_NOTHING) { specificCommand = new M_ControllerCommands(); specificCommand.operationMode = command.operationMode; DeviceAction action2 = new DeviceAction(controller, parameters, specificCommand); action2.actionName = specificCommand.getActionName(); DeviceActionResult actionResult2 = new DeviceActionResult(DeviceActionResult.RESULT_NOTSEND); action2.setResult(actionResult2); Shared.model.addAction(action2); laction.add(action2); } if (command.userControlManual != M_ControllerCommands.CONDITION_NOTHING) { specificCommand = new M_ControllerCommands(); specificCommand.userControlManual = command.userControlManual; DeviceAction action2 = new DeviceAction(controller, parameters, specificCommand); action2.actionName = specificCommand.getActionName(); DeviceActionResult actionResult2 = new DeviceActionResult(DeviceActionResult.RESULT_NOTSEND); action2.setResult(actionResult2); Shared.model.addAction(action2); laction.add(action2); } if (command.emergency != M_ControllerCommands.CONDITION_NOTHING) { specificCommand = new M_ControllerCommands(); specificCommand.emergency = command.emergency; DeviceAction action2 = new DeviceAction(controller, parameters, specificCommand); action2.actionName = specificCommand.getActionName(); DeviceActionResult actionResult2 = new DeviceActionResult(DeviceActionResult.RESULT_NOTSEND); action2.setResult(actionResult2); Shared.model.addAction(action2); laction.add(action2); } return laction; } if ((operationMode < M_ControllerCommands.OPERATIONMODE_FIXED) || (operationMode > M_ControllerCommands.OPERATIONMODE_ACTUATED)) { if (command.colorsMode != M_ControllerCommands.COLORS_NOTHING) { M_ControllerCommands specificCommand = new M_ControllerCommands(); specificCommand.colorsMode = command.colorsMode; DeviceAction action = new DeviceAction(controller, parameters, specificCommand); action.actionName = specificCommand.getActionName(); DeviceActionResult actionResult2 = new DeviceActionResult(DeviceActionResult.RESULT_NOTSEND); action.setResult(actionResult2); Shared.model.addAction(action); laction.add(action); } M_ControllerCommands specificCommand = new M_ControllerCommands(); specificCommand.operationMode = command.operationMode; DeviceAction action = new DeviceAction(controller, parameters, specificCommand); action.actionName = specificCommand.getActionName(); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, Shared.getMessage("Operation mode value is not valid")); action.setResult(actionResult); Shared.model.addAction(action); laction.add(action); if (command.userControlManual != M_ControllerCommands.CONDITION_NOTHING) { specificCommand = new M_ControllerCommands(); specificCommand.userControlManual = command.userControlManual; DeviceAction action2 = new DeviceAction(controller, parameters, specificCommand); action2.actionName = specificCommand.getActionName(); DeviceActionResult actionResult2 = new DeviceActionResult(DeviceActionResult.RESULT_NOTSEND); action2.setResult(actionResult2); Shared.model.addAction(action2); laction.add(action2); } if (command.emergency != M_ControllerCommands.CONDITION_NOTHING) { specificCommand = new M_ControllerCommands(); specificCommand.emergency = command.emergency; DeviceAction action2 = new DeviceAction(controller, parameters, specificCommand); action2.actionName = specificCommand.getActionName(); switch (command.emergency) { case CONDITION_ENABLED: action2.actionName = Shared.getMessage(language, "Emergency (on)"); break; case CONDITION_DISABLED: action2.actionName = Shared.getMessage(language, "Emergency (off)"); break; } DeviceActionResult actionResult2 = new DeviceActionResult(DeviceActionResult.RESULT_NOTSEND); action2.setResult(actionResult2); Shared.model.addAction(action2); laction.add(action2); } return laction; } if ((centralizedMode < M_ControllerCommands.CONDITION_NO) || (centralizedMode > M_ControllerCommands.CONDITION_YES)) { centralizedMode = CONDITION_YES; } if ((userControlManual < M_ControllerCommands.CONDITION_NO) || (userControlManual > M_ControllerCommands.CONDITION_YES)) { userControlManual = CONDITION_NO; } if ((controlComputerDirectGroups < M_ControllerCommands.CONDITION_NO) || (controlComputerDirectGroups > M_ControllerCommands.CONDITION_YES)) { controlComputerDirectGroups = CONDITION_NO; } if ((emergency < M_ControllerCommands.CONDITION_NO) || (emergency > M_ControllerCommands.CONDITION_YES)) { emergency = CONDITION_NO; } boolean found = false; for (M_ControllerStatusSubcontroller statusSubcontroller : this.lsubcontrollerUpdate) { if (statusSubcontroller.number == subcontroller) { found = true; // if (allNothing == true) // statusSubcontroller.planSelectionComputer = M_ControllerStatusSubcontroller.UNKNOWN; // else // statusSubcontroller.planSelectionComputer = M_ControllerStatusSubcontroller.PLANSELECTION_COMPUTER_PLAN_SELECTION; statusSubcontroller.adaptativeDetectors = adaptativeDetectors; statusSubcontroller.centralizedMode = centralizedMode; statusSubcontroller.colorsMode = colorsMode; statusSubcontroller.controlComputerDirectGroups = controlComputerDirectGroups; statusSubcontroller.coordinationMode = coordinationMode; statusSubcontroller.emergency = emergency; statusSubcontroller.userControlManual = userControlManual; statusSubcontroller.operationMode = operationMode; statusSubcontroller.planSelection = planSelection; statusSubcontroller.number = subcontroller; } } if (found == false) { M_ControllerStatusSubcontroller statusSubcontroller = new M_ControllerStatusSubcontroller(); statusSubcontroller.number = subcontroller; // if (allNothing == true) // statusSubcontroller.planSelectionComputer = M_ControllerStatusSubcontroller.UNKNOWN; // else // statusSubcontroller.planSelectionComputer = M_ControllerStatusSubcontroller.PLANSELECTION_COMPUTER_PLAN_SELECTION; statusSubcontroller.adaptativeDetectors = adaptativeDetectors; statusSubcontroller.centralizedMode = centralizedMode; statusSubcontroller.colorsMode = colorsMode; statusSubcontroller.controlComputerDirectGroups = controlComputerDirectGroups; statusSubcontroller.coordinationMode = coordinationMode; statusSubcontroller.emergency = emergency; statusSubcontroller.userControlPlan = userControlManual; statusSubcontroller.operationMode = operationMode; statusSubcontroller.planSelection = planSelection; statusSubcontroller.number = subcontroller; this.lsubcontrollerUpdate.add(statusSubcontroller); } M_Message request = M_ProtocolConstructor.setState(subcontroller, colorsMode, planSelection, adaptative, adaptativeDetectors, coordinationMode, centralizedMode, userControlManual, controlComputerDirectGroups, operationMode, sptpOperationMode, emergency, hasCRC); if (ColorsServer.TEST_SPTP == true) { String s = "Set State >> "; byte[] data = request.toByteArray(); for (int i=0; i // public DeviceAction shiftPhase(InteropParameters parameters, M_ControllerCommands command) throws SerializationException { String language = (String)parameters.getParameterValue("language"); DeviceAction action = new DeviceAction(controller, parameters, command); action.actionName = command.getActionName(); try { // M_ControllerCommandsPhaseChanging phaseChangingCommands = command.phaseChanging; // M_ControllerConfiguration controllerConfiguration = controller.getDeviceConfiguration(); // M_SubcontrollerConfiguration subcontrollerConfiguration = controllerConfiguration.getSubcontroller(phaseChangingCommands.subcontroller); // if (subcontrollerConfiguration == null) // { // DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, Shared.getMessage("Subcontroller does not exist")); // action.setResult(actionResult); // Shared.model.addAction(action); // return action; // } // // M_Message request = M_ProtocolConstructor.phaseChanging(phaseChangingCommands, hasCRC); // getControllerConnection().send(request.toByteArray()); // // DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_CORRECT); // action.setResult(actionResult); // Shared.model.addAction(action); // return action; DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_NOTSEND); action.setResult(actionResult); Shared.model.addAction(action); return action; } catch (Exception exception) { DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); return action; } } // // // public DeviceAction setDirectGroupOutput(InteropParameters parameters, M_ControllerCommands command) throws SerializationException // { // String language = (String)parameters.getParameterValue("language"); // DeviceAction action = new DeviceAction(controller, parameters, command); // action.actionName = command.getActionName(); // // try // { // List ldirectGroupCommand = command.ldirectGroupOutput; // M_ControllerConfiguration controllerConfiguration = controller.getDeviceConfiguration(); // // for (M_ControllerCommandsDirectGroupOutput directGroupOutput : ldirectGroupCommand) // { // try // { // controllerConfiguration.getDirectGroup(directGroupOutput.group); // } // catch (Exception exception) // { // DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, Shared.getMessage("Direct group %1 does not exists").replace("%1", "" + directGroupOutput.group)); // action.setResult(actionResult); // Shared.model.addAction(action); // return action; // } // } // // M_Message request = M_ProtocolConstructor.setDirectGroupOutput(0x00, ldirectGroupCommand, hasCRC); // getControllerConnection().send(request.toByteArray()); // // DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_CORRECT); // action.setResult(actionResult); // Shared.model.addAction(action); // return action; // } // catch (Exception exception) // { // DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); // action.setResult(actionResult); // Shared.model.addAction(action); // return action; // } // } // // public DeviceAction clearAlarms(InteropParameters parameters, M_ControllerCommands command) throws SerializationException { String language = (String)parameters.getParameterValue("language"); DeviceAction action = new DeviceAction(controller, parameters, command); action.actionName = command.getActionName(); try { M_Message request = M_ProtocolConstructor.clearAlarms(0x00, hasCRC); getControllerConnection().send(request.toByteArray()); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_CORRECT); action.setResult(actionResult); Shared.model.addAction(action); return action; } catch (Exception exception) { DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); return action; } } // // protected void getCurrentSubcontrollersState(M_Controller m_controllerClone) throws ServerException, Exception { if (m_controllerClone.getDeviceStatus().lsubcontroller.size() == 0) { createStatusSubcontrollers(m_controllerClone); } else { int number = 1; for (M_ControllerStatusSubcontroller m_controllerStatusSubcontroller : m_controllerClone.getDeviceStatus().lsubcontroller) { m_controllerStatusSubcontroller.number = number++; M_Message command = M_ProtocolConstructor.getCurrentState(m_controllerStatusSubcontroller.number, hasCRC); M_Request request = new M_Request(); request.controller = this; request.request = command; this.getControllerConnection().addM_Request(request); request.waitResponse(m_controllerClone.getDeviceInformation().timeout); M_ProtocolAnalyser.analyseCurrentStateResponse(m_controllerStatusSubcontroller, request.response, m_controllerStatusSubcontroller.number); } } } protected int getAlarms(M_Controller m_controllerClone) throws ServerException, Exception { if (m_controllerClone.getDeviceStatus().lgroup.size() == 0) { M_ControllerConfiguration configuration = m_controllerClone.getDeviceConfiguration(); for (M_TrafficGroup trafficGroup : configuration.ltrafficGroup) { M_ControllerStatusGroup group = new M_ControllerStatusGroup(); group.number = trafficGroup.number; m_controllerClone.getDeviceStatus().lgroup.add(group); } } M_Message command = M_ProtocolConstructor.getAlarms(0x00, hasCRC); M_Request request = new M_Request(); request.controller = this; request.request = command; this.getControllerConnection().addM_Request(request); request.waitResponse(m_controllerClone.getDeviceInformation().timeout); int result = M_ProtocolAnalyser.analyseAlarmsResponse(m_controllerClone, request.response, 0x00); return(result); } protected void getBlownLampAlarms(M_Controller m_controllerClone) throws ServerException, Exception { M_Message command = M_ProtocolConstructor.getBlownLampsAlarms(0x00, hasCRC); M_Request request = new M_Request(); request.controller = this; request.request = command; this.getControllerConnection().addM_Request(request); request.waitResponse(m_controllerClone.getDeviceInformation().timeout); M_ProtocolAnalyser.analyseBlownLampsAlarmsResponse(m_controllerClone, request.response, 0x00); } protected void getDamagedGroupAlarms(M_Controller m_controllerClone) throws ServerException, Exception { M_Message command = M_ProtocolConstructor.getDamagedGroupAlarms(0x00, hasCRC); M_Request request = new M_Request(); request.controller = this; request.request = command; this.getControllerConnection().addM_Request(request); request.waitResponse(m_controllerClone.getDeviceInformation().timeout); M_ProtocolAnalyser.analyseDamagedGroupAlarmsResponse(m_controllerClone, request.response, 0x00); } protected void getIncompatibilityAlarms(M_Controller m_controllerClone) throws ServerException, Exception { M_Message command = M_ProtocolConstructor.getIncompatibilityAlarms(0x00, hasCRC); M_Request request = new M_Request(); request.controller = this; request.request = command; this.getControllerConnection().addM_Request(request); request.waitResponse(m_controllerClone.getDeviceInformation().timeout); M_ProtocolAnalyser.analyseIncompatibilityAlarmsResponse(m_controllerClone, request.response, 0x00); } protected M_Plan getCurrentRecordablePlan(int subcontroller) throws ServerException, Exception { M_ControllerConfiguration controllerConfiguration = controller.getDeviceConfiguration(); M_SubcontrollerConfiguration subcontrollerConfiguration = controllerConfiguration.getSubcontroller(subcontroller); if (subcontrollerConfiguration == null) throw new ServerException(Shared.getMessage("Subcontroller does not exist")); M_Message command = M_ProtocolConstructor.getRecordablePlan(subcontroller, hasCRC); M_Request request = new M_Request(); request.controller = this; request.request = command; this.getControllerConnection().addM_Request(request); request.waitResponse(controller.getDeviceInformation().timeout); M_Plan recordablePlan = M_ProtocolAnalyser.analyseGetRecordablePlanResponse(request.response, subcontroller, subcontrollerConfiguration.lphaseStable.size()); if (recordablePlan == null) { M_Plan subcontrollerRecordablePlan = controller.getDeviceStatus().getStatusSubcontroller(subcontroller).recordablePlan; if (subcontrollerRecordablePlan == null) { throw new ServerException(Shared.getMessage("Recordable plan is not configured") + ", " + Shared.getMessage("Subcontroller") + " : " + subcontroller); } try { // Send again save recordable plan command M_ControllerCommands commands = new M_ControllerCommands(); // commands.userControlPlan = CONDITION_YES; commands.recordablePlan = new ALUVISA_Plan(); commands.recordablePlan.initialise(subcontrollerConfiguration, subcontrollerRecordablePlan); InteropParameters parameters = new InteropParameters(); parameters.addParameter("language", "en-GB"); parameters.addParameter("username", "system"); parameters.addParameter("computer", controller.getDeviceInformation().serverAddress); parameters.addBodycontent(commands); DeviceAction[] laction = sendCommands(subcontroller, parameters); } catch (Exception e) { Shared.printstack(name, e); throw e; } throw new ServerException(Shared.getMessage("Recordable plan is not configured") + ", " + Shared.getMessage("Subcontroller") + " : " + subcontroller); } ALUVISA_Plan aluvisaPlan = new ALUVISA_Plan(); aluvisaPlan.initialise(this.controller.getDeviceConfiguration().getSubcontroller(subcontroller), recordablePlan); int cycleTime = 0; for (ALUVISA_Phase phase : aluvisaPlan.lPhase) { cycleTime += phase.maximumTime; } HashMap hdestination = new HashMap(); for (ALUVISA_Link link : aluvisaPlan.lLink) { if (hdestination.containsKey(link.destination) == false) { hdestination.put(link.destination, link.destination); for (ALUVISA_Phase phase : link.lTransition) { cycleTime += phase.maximumTime; } } } recordablePlan.cycleTime = cycleTime; return(recordablePlan); } // // protected void getCurrentPlan(M_Controller m_controllerClone) throws ServerException, Exception { if (m_controllerClone.getDeviceRealtime().lsubcontroller.size() == 0) { createRealtimeSubcontrollers(m_controllerClone); } else { for (M_ControllerRealtimeSubcontroller m_controllerRealtimeSubcontroller : m_controllerClone.getDeviceRealtime().lsubcontroller) { M_Message command = M_ProtocolConstructor.getCurrentPlan(m_controllerRealtimeSubcontroller.number, hasCRC); M_Request request = new M_Request(); request.controller = this; request.request = command; this.getControllerConnection().addM_Request(request); request.waitResponse(m_controllerClone.getDeviceInformation().timeout); M_ProtocolAnalyser.analyseCurrentPlanResponse(m_controllerClone.getDeviceStatus().getStatusSubcontroller(m_controllerRealtimeSubcontroller.number), m_controllerRealtimeSubcontroller, request.response, m_controllerRealtimeSubcontroller.number); // String message = Shared.getMessage("Subcontroller = %1, Current Plan = %2, Phase = %3, Time = %4, Starttime = %5, Adjust = %6"); // message = message.replace("%1", "" + m_controllerRealtimeSubcontroller.number); // message = message.replace("%2", "" + m_controllerRealtimeSubcontroller.plan); // message = message.replace("%3", "" + m_controllerRealtimeSubcontroller.phase); // message = message.replace("%4", "" + m_controllerRealtimeSubcontroller.cycle); // message = message.replace("%5", sdh.format(new Date(m_controllerRealtimeSubcontroller.startTimestamp))); // message = message.replace("%6", "" + m_controllerRealtimeSubcontroller.adjust); // Shared.println(name, "\t" + this.controller.getIdentifier() + " - 1.CurrentPlan: " + message); } } } protected void getCurrentPresenceDetectors(M_Controller m_controllerClone) throws ServerException, Exception { M_Message command = M_ProtocolConstructor.getCurrentPresenceDetectors(0x00, hasCRC); M_Request request = new M_Request(); request.controller = this; request.request = command; this.getControllerConnection().addM_Request(request); request.waitResponse(m_controllerClone.getDeviceInformation().timeout); try{M_ProtocolAnalyser.analyseCurrentPresenceDetectorsResponse(m_controllerClone, request.response, 0x00);} catch (Exception e){}; } protected long[] getCurrentTime(M_Controller m_controllerClone) throws ServerException, Exception { try { if (m_controllerClone.getDeviceInformation().type == M_ControllerInformation.TYPE_RTAC) { M_Message command = null; if (checkedPRH == false) { command = M_ProtocolConstructor.PRH(); M_Request request = new M_Request(); request.controller = this; request.request = command; this.getControllerConnection().addM_Request(request); request.waitResponse(m_controllerClone.getDeviceInformation().timeout); checkedPRH = true; if (request.response == null) { usePRH = false; } else { usePRH = true; } return(M_ProtocolAnalyser.analyseCurrentTimeResponse(m_controllerClone, request.response, 0x00)); } else { if (usePRH == true) { command = M_ProtocolConstructor.PRH(); } else { command = M_ProtocolConstructor.getCurrentTime(0x00, hasCRC); } M_Request request = new M_Request(); request.controller = this; request.request = command; this.getControllerConnection().addM_Request(request); request.waitResponse(m_controllerClone.getDeviceInformation().timeout); return(M_ProtocolAnalyser.analyseCurrentTimeResponse(m_controllerClone, request.response, 0x00)); } } else { M_Message command = null; if (m_controllerClone.getDeviceInformation().type == M_ControllerInformation.TYPE_RTAC) { command = M_ProtocolConstructor.PRH(); } else { command = M_ProtocolConstructor.getCurrentTime(0x00, hasCRC); } M_Request request = new M_Request(); request.controller = this; request.request = command; this.getControllerConnection().addM_Request(request); request.waitResponse(m_controllerClone.getDeviceInformation().timeout); return(M_ProtocolAnalyser.analyseCurrentTimeResponse(m_controllerClone, request.response, 0x00)); } } catch (Exception e) { throw e; } } protected void getCurrentStatusGroups(M_Controller m_controllerClone) throws ServerException, Exception { try { M_Message command = M_ProtocolConstructor.getCurrentStatusGroups(0x00, hasCRC); M_Request request = new M_Request(); request.controller = this; request.request = command; this.getControllerConnection().addM_Request(request); request.waitResponse(m_controllerClone.getDeviceInformation().timeout); M_ProtocolAnalyser.analyseCurrentStatusGroupsResponse(m_controllerClone, request.response, 0x00); } catch (Exception e) { } } // // protected void getCurrentCountingDetectors(M_Controller m_controllerClone) throws ServerException, Exception { try { M_Message command = M_ProtocolConstructor.getCurrentCountingDetectors(0x00); M_Request request = new M_Request(); request.controller = this; request.request = command; this.getControllerConnection().addM_Request(request); request.waitResponse(m_controllerClone.getDeviceInformation().timeout); EtdStatus newEtdStatus = createEtdStatus(); M_ProtocolAnalyser.analyseCurrentCountingDetectorsResponse(m_controllerClone, request.response, 0x00, newEtdStatus); Shared.println(name, "1.EtdStatus: " + newEtdStatus.getMeasurementTimestamp() + ", " + newEtdStatus.status + ", " + newEtdStatus.period + ", " + newEtdStatus.total + ", " + newEtdStatus.llane.size()); Shared.println(name, "2.EtdStatus: " + newEtdStatus.getMeasurementTimestamp() + ", " + newEtdStatus.total.correctMeasurements + ", " + newEtdStatus.total.totalMeasurements); Shared.println(name, "3.EtdStatus: " + newEtdStatus.getMeasurementTimestamp() + ", " + newEtdStatus.total.counting + ", " + newEtdStatus.total.occupancy + ", " + newEtdStatus.total.status); this.etdStatus = newEtdStatus; Shared.println(name, "4.EtdStatus: " + this.etdStatus.getMeasurementTimestamp() + ", " + this.etdStatus.status + ", " + this.etdStatus.period + ", " + this.etdStatus.total + ", " + this.etdStatus.llane.size()); Shared.println(name, "5.EtdStatus: " + this.etdStatus.getMeasurementTimestamp() + ", " + this.etdStatus.total.correctMeasurements + ", " + this.etdStatus.total.totalMeasurements); Shared.println(name, "6.EtdStatus: " + this.etdStatus.getMeasurementTimestamp() + ", " + this.etdStatus.total.counting + ", " + this.etdStatus.total.occupancy + ", " + this.etdStatus.total.status); } catch (Exception e) { Shared.printstack(name, e); // throw e; } } // // public EtdStatus getRealtimeTrafficData(long timestamp) throws ServerException, Exception { if (this.etdStatus.measurementTimestamp > timestamp) { return(this.etdStatus); } else { // QUITARLO if (this.etdStatus.measurementTimestamp > 0) { this.etdStatus.measurementTimestamp = this.etdStatus.measurementTimestamp + 60000L; } } throw new ServerException(Shared.getMessage("Not new information")); } // // private void updateStatusSubcontroller(M_ControllerStatusSubcontroller currentRealStatus, M_ControllerStatusSubcontroller currentStatus, M_ControllerStatusSubcontroller newStatus) throws Exception { if (newStatus != null) { if (newStatus.adaptativeDetectors != M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.adaptativeDetectors = newStatus.adaptativeDetectors; if (newStatus.centralizedMode != M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.centralizedMode = newStatus.centralizedMode; if (newStatus.colorsMode != M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.colorsMode = newStatus.colorsMode; if (newStatus.controlComputerDirectGroups != M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.controlComputerDirectGroups = newStatus.controlComputerDirectGroups; if (newStatus.coordinationMode != M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.coordinationMode = newStatus.coordinationMode; if (newStatus.emergency != M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.emergency = newStatus.emergency; if (newStatus.userControlManual != M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.userControlManual = newStatus.userControlManual; if (newStatus.operationMode != M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.operationMode = newStatus.operationMode; if (newStatus.plan != M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.plan = newStatus.plan; if (newStatus.planSelection != M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.planSelection = newStatus.planSelection; if (newStatus.localControl != M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.localControl = newStatus.localControl; if (newStatus.userControlPlan != M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.userControlPlan = newStatus.userControlPlan; if (newStatus.planSelectionComputer != M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.planSelectionComputer = newStatus.planSelectionComputer; if (newStatus.recordablePlan != null) { if (currentStatus.recordablePlan == null) currentStatus.recordablePlan = newStatus.recordablePlan; else { currentStatus.recordablePlan.controlMode = newStatus.recordablePlan.controlMode; currentStatus.recordablePlan.minimumAndExtensionTimesTable = newStatus.recordablePlan.minimumAndExtensionTimesTable; currentStatus.recordablePlan.offset = newStatus.recordablePlan.offset; currentStatus.recordablePlan.number = 0; // newStatus.recordablePlan.number; currentStatus.recordablePlan.structure = newStatus.recordablePlan.structure; currentStatus.recordablePlan.transitionsToTimesTable = newStatus.recordablePlan.transitionsToTimesTable; currentStatus.recordablePlan.lPhaseTime.clear(); currentStatus.recordablePlan.lPhaseTime.addAll(newStatus.recordablePlan.lPhaseTime); } currentStatus.recordablePlan.cycleTime = calculateCycleTime(currentStatus.recordablePlan, this.controller, currentStatus.number); } } if (currentStatus.adaptativeDetectors == M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.adaptativeDetectors = currentRealStatus.adaptativeDetectors; if (currentStatus.centralizedMode == M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.centralizedMode = currentRealStatus.centralizedMode; if (currentStatus.colorsMode == M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.colorsMode = currentRealStatus.colorsMode; if (currentStatus.controlComputerDirectGroups == M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.controlComputerDirectGroups = currentRealStatus.controlComputerDirectGroups; if (currentStatus.coordinationMode == M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.coordinationMode = currentRealStatus.coordinationMode; if (currentStatus.emergency == M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.emergency = currentRealStatus.emergency; if (currentStatus.userControlManual == M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.userControlManual = currentRealStatus.userControlManual; if (currentStatus.operationMode == M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.operationMode = currentRealStatus.operationMode; if (currentStatus.plan == M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.plan = currentRealStatus.plan; if (currentStatus.planSelection == M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.planSelection = currentRealStatus.planSelection; if (currentStatus.localControl == M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.localControl = currentRealStatus.localControl; if (currentStatus.userControlPlan == M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.userControlPlan = currentRealStatus.userControlPlan; if (currentStatus.planSelectionComputer == M_ControllerStatusSubcontroller.UNKNOWN) currentStatus.planSelectionComputer = currentRealStatus.planSelectionComputer; if (currentStatus.recordablePlan == null) currentStatus.recordablePlan = currentRealStatus.recordablePlan; } protected int calculateCycleTime(M_Plan plan, M_Controller controller, int subcontroller) throws Exception { controller.getDeviceConfiguration().toAluvisa(); ALUVISA_Plan aluvisaPlan = new ALUVISA_Plan(); aluvisaPlan.initialise(controller.getDeviceConfiguration().getSubcontroller(subcontroller), plan); return(aluvisaPlan.getCycleTime()); } protected void recreateStatus(M_Controller m_controllerClone) throws ServerException, Exception { if (m_controllerClone.getDeviceStatus().lsubcontroller.size() > m_controllerClone.getDeviceConfiguration().lsubcontroller.size()) { for (int i=m_controllerClone.getDeviceConfiguration().lsubcontroller.size(); i(); for (M_PhysicalDetectorStrategical strategicalDetector : this.controller.getDeviceConfiguration().lstrategicalDetector) { EtdStatusLane lane = new EtdStatusLane(); result.llane.add(lane); } result.total = new EtdStatusLane(); return(result); } protected void clearBlownLampsGroupAlarms(M_Controller m_controllerClone) { for (M_ControllerStatusGroup m_controllerStatusGroup : m_controllerClone.getDeviceStatus().lgroup) { m_controllerStatusGroup.redOutputBlown = M_ControllerRealtimeGroup.NO; m_controllerStatusGroup.yellowOutputBlown = M_ControllerRealtimeGroup.NO; m_controllerStatusGroup.greenOutputBlown = M_ControllerRealtimeGroup.NO; } } protected void clearDamagedGroupAlarms(M_Controller m_controllerClone) { for (M_ControllerStatusGroup m_controllerStatusGroup : m_controllerClone.getDeviceStatus().lgroup) { m_controllerStatusGroup.redOutputDamaged = M_ControllerRealtimeGroup.NO; m_controllerStatusGroup.yellowOutputDamaged = M_ControllerRealtimeGroup.NO; m_controllerStatusGroup.greenOutputDamaged = M_ControllerRealtimeGroup.NO; } } protected void clearIncompatibilityGroupAlarms(M_Controller m_controllerClone) { for (M_ControllerStatusGroup m_controllerStatusGroup : m_controllerClone.getDeviceStatus().lgroup) { m_controllerStatusGroup.lincompatibility.clear(); } } // // public M_ControllerConfiguration readAllTables() throws ServerException, Exception { ControllerConnection controllerRead = null; try { if (controller.getDeviceInformation().type == M_ControllerInformation.TYPE_DYNAMIC) { controllerRead = new ControllerConnection(controller.getDeviceInformation().address, controller.getDeviceInformation().portM, controller.getDeviceInformation().timeout, hasCRC); controllerRead.connect(); } else { if (controller.getIdentifier().equalsIgnoreCase("controller-almeria-00740") == true) { Shared.println(name, "1.ReadAllTables"); } controllerRead = getControllerConnection(); if (controller.getIdentifier().equalsIgnoreCase("controller-almeria-00740") == true) { Shared.println(name, "2.ReadAllTables"); } } List lTableData = new ArrayList(); if (controller.getIdentifier().equalsIgnoreCase("controller-almeria-00740") == true) { Shared.println(name, "3.ReadAllTables"); } lTableData.addAll(readTable(controllerRead, 0x00, M_Table.M_TABLE_A_GROUPS)); if (controller.getIdentifier().equalsIgnoreCase("controller-almeria-00740") == true) { Shared.println(name, "4.ReadAllTables"); } lTableData.addAll(readTable(controllerRead, 0x00, M_Table.M_TABLE_B_PHYSICAL_DETECTORS)); lTableData.addAll(readTable(controllerRead, 0x00, M_Table.M_TABLE_C_LOGICAL_DETECTORS)); lTableData.addAll(readTable(controllerRead, 0x00, M_Table.M_TABLE_D_DEMANDS)); lTableData.addAll(readTable(controllerRead, 0x00, M_Table.M_TABLE_E_INCOMPATIBILITIES)); lTableData.addAll(readTable(controllerRead, 0x00, M_Table.M_TABLE_F_SPECIAL_DAYS)); lTableData.addAll(readTable(controllerRead, 0x00, M_Table.M_TABLE_G_INTERMITENCES)); lTableData.addAll(readTable(controllerRead, 0x00, M_Table.M_TABLE_H_OPERATION_MODE)); lTableData.addAll(readTable(controllerRead, 0x00, M_Table.M_TABLE_I_ALARMS_MANAGEMENT)); try { // TODO Los reguladores dynamics viejos no tienen estas tablas // if (controller.getDeviceInformation().type == M_ControllerInformation.TYPE_DYNAMIC) // { // lTableData.addAll(readTable(controllerRead, 0x00, M_Table.M_TABLE_DYNAMIC_LAMPS)); // lTableData.addAll(readTable(controllerRead, 0x00, M_Table.M_TABLE_DYNAMIC_DETECTORS)); // lTableData.addAll(readTable(controllerRead, 0x00, M_Table.M_TABLE_DYNAMIC_GENERAL_PARAMETERS)); // lTableData.addAll(readTable(controllerRead, 0x00, M_Table.M_TABLE_DYNAMIC_BUTTON_GUARD)); // lTableData.addAll(readTable(controllerRead, 0x00, M_Table.M_TABLE_DYNAMIC_ALARMS_CONFIGURATION)); // } } catch (Exception e) { } // Reading M_TABLE_A_PHASES_STABLES we can detect how many subcontrollers // are really configured in controller (1, 2, 3 or 4) // And then we can request only the correspondant tables. // It will not be necessary to ask for tables of subcontrollers that we know that don't exist. int numberOfSubcontrollers = 0; for (int i=0; i ldata = readTable(controllerRead, i+1, M_Table.M_TABLE_A_PHASES_STABLES); if (ldata.size() > 5) { lTableData.addAll(ldata); numberOfSubcontrollers = numberOfSubcontrollers + 1; } else { i = M_ControllerConfiguration.MAXIMUM_NUMBER_SUBCONTROLLERS; } } for (int i=0; i readTable(ControllerConnection controllerRead, int controller, int tableCode) throws ServerException, Exception { if (this.controller.getIdentifier().equalsIgnoreCase("controller-almeria-00740") == true) { Shared.println(name, "1.ReadTable: " + controller + " - " + tableCode); } M_Message message = M_ProtocolConstructor.readTableMessage(controller, tableCode, hasCRC); if (this.controller.getIdentifier().equalsIgnoreCase("controller-almeria-00740") == true) { Shared.println(name, "2.ReadTable: " + controller + " - " + tableCode); } M_Request request = new M_Request(); request.controller = this; request.request = message; this.getControllerConnection().addM_Request(request); request.waitResponse(this.controller.getDeviceInformation().timeout); M_Message response = request.response; // M_Message response = controllerRead.read(command); if (this.controller.getIdentifier().equalsIgnoreCase("controller-almeria-00740") == true) { Shared.println(name, "3.ReadTable: " + controller + " - " + tableCode + " - " + response); } // controllerRead.ack(); if (this.controller.getIdentifier().equalsIgnoreCase("controller-almeria-00740") == true) { Shared.println(name, "4.ReadTable: " + controller + " - " + tableCode + " - " + response); } boolean salir = false; int retries = 0; while ((salir == false) && (retries < MAX_RETRIES)) { if (M_ProtocolAnalyser.isReadTableMessage(this.controller, response, controller, tableCode) == true) { if (this.controller.getIdentifier().equalsIgnoreCase("controller-almeria-00740") == true) { Shared.println(name, "5.ReadTable: " + controller + " - " + tableCode + " - " + response); } List lTableData = M_ProtocolAnalyser.analyseReadTable(response, tableCode, hasCRC); if (this.controller.getIdentifier().equalsIgnoreCase("controller-almeria-00740") == true) { Shared.println(name, "6.ReadTable: " + controller + " - " + tableCode + " - " + lTableData.size()); } controllerRead.ack(); if (this.controller.getIdentifier().equalsIgnoreCase("controller-almeria-00740") == true) { Shared.println(name, "7.ReadTable: " + controller + " - " + tableCode + " - " + lTableData.size()); } return(lTableData); } if (this.controller.getIdentifier().equalsIgnoreCase("controller-almeria-00740") == true) { Shared.println(name, "8.ReadTable: " + controller + " - " + tableCode + " - " + retries); } // response = controllerRead.receive(); request = new M_Request(); request.controller = this; request.request = message; this.getControllerConnection().addM_Request(request); request.waitResponse(this.controller.getDeviceInformation().timeout); response = request.response; if (this.controller.getIdentifier().equalsIgnoreCase("controller-almeria-00740") == true) { Shared.println(name, "9.ReadTable: " + controller + " - " + tableCode + " - " + retries); } // controllerRead.ack(); if (this.controller.getIdentifier().equalsIgnoreCase("controller-almeria-00740") == true) { Shared.println(name, "10.ReadTable: " + controller + " - " + tableCode + " - " + retries); } retries++; } throw new Exception("Error reading table " + controller + " - " + tableCode); } // // public void writeAllTables(M_ControllerConfiguration controllerConfiguration) throws ServerException, Exception { ControllerConnection controllerWrite = null; try { controllerWrite = new ControllerConnection(controller.getDeviceInformation().address, controller.getDeviceInformation().portM, controller.getDeviceInformation().timeout, hasCRC); controllerWrite.connect(); startRecordingTables(controllerWrite, controllerConfiguration); writeTable(controllerWrite, 0x00, controllerConfiguration, null, M_Table.M_TABLE_A_GROUPS); writeTable(controllerWrite, 0x00, controllerConfiguration, null, M_Table.M_TABLE_B_PHYSICAL_DETECTORS); writeTable(controllerWrite, 0x00, controllerConfiguration, null, M_Table.M_TABLE_C_LOGICAL_DETECTORS); writeTable(controllerWrite, 0x00, controllerConfiguration, null, M_Table.M_TABLE_D_DEMANDS); writeTable(controllerWrite, 0x00, controllerConfiguration, null, M_Table.M_TABLE_E_INCOMPATIBILITIES); writeTable(controllerWrite, 0x00, controllerConfiguration, null, M_Table.M_TABLE_F_SPECIAL_DAYS); writeTable(controllerWrite, 0x00, controllerConfiguration, null, M_Table.M_TABLE_G_INTERMITENCES); writeTable(controllerWrite, 0x00, controllerConfiguration, null, M_Table.M_TABLE_H_OPERATION_MODE); writeTable(controllerWrite, 0x00, controllerConfiguration, null, M_Table.M_TABLE_I_ALARMS_MANAGEMENT); try { if (controller.getDeviceInformation().type == M_ControllerInformation.TYPE_DYNAMIC) { writeTable(controllerWrite, 0x00, controllerConfiguration, null, M_Table.M_TABLE_DYNAMIC_LAMPS); writeTable(controllerWrite, 0x00, controllerConfiguration, null, M_Table.M_TABLE_DYNAMIC_DETECTORS); writeTable(controllerWrite, 0x00, controllerConfiguration, null, M_Table.M_TABLE_DYNAMIC_GENERAL_PARAMETERS); writeTable(controllerWrite, 0x00, controllerConfiguration, null, M_Table.M_TABLE_DYNAMIC_BUTTON_GUARD); writeTable(controllerWrite, 0x00, controllerConfiguration, null, M_Table.M_TABLE_DYNAMIC_ALARMS_CONFIGURATION); } } catch (Exception e) { } int number = 0; for (M_SubcontrollerConfiguration subcontrollerConfiguration : controllerConfiguration.lsubcontroller) { writeTable(controllerWrite, subcontrollerConfiguration.number, controllerConfiguration, subcontrollerConfiguration, M_Table.M_TABLE_A_PHASES_STABLES); writeTable(controllerWrite, subcontrollerConfiguration.number, controllerConfiguration, subcontrollerConfiguration, M_Table.M_TABLE_B_PHASES_TRANSITIONS); writeTable(controllerWrite, subcontrollerConfiguration.number, controllerConfiguration, subcontrollerConfiguration, M_Table.M_TABLE_C_TRANSITIONS); writeTable(controllerWrite, subcontrollerConfiguration.number, controllerConfiguration, subcontrollerConfiguration, M_Table.M_TABLE_D_STRUCTURES); writeTable(controllerWrite, subcontrollerConfiguration.number, controllerConfiguration, subcontrollerConfiguration, M_Table.M_TABLE_E_ACTION_ON_DEMAND); writeTable(controllerWrite, subcontrollerConfiguration.number, controllerConfiguration, subcontrollerConfiguration, M_Table.M_TABLE_F_TRANSITIONS_TO_TIMES); writeTable(controllerWrite, subcontrollerConfiguration.number, controllerConfiguration, subcontrollerConfiguration, M_Table.M_TABLE_G_TRANSITIONS_TIMES); writeTable(controllerWrite, subcontrollerConfiguration.number, controllerConfiguration, subcontrollerConfiguration, M_Table.M_TABLE_H_MINIMUM_EXTENSION_TIMES); writeTable(controllerWrite, subcontrollerConfiguration.number, controllerConfiguration, subcontrollerConfiguration, M_Table.M_TABLE_I_PLANS); writeTable(controllerWrite, subcontrollerConfiguration.number, controllerConfiguration, subcontrollerConfiguration, M_Table.M_TABLE_J_EMERGENCY); writeTable(controllerWrite, subcontrollerConfiguration.number, controllerConfiguration, subcontrollerConfiguration, M_Table.M_TABLE_K_STARTUP); writeTable(controllerWrite, subcontrollerConfiguration.number, controllerConfiguration, subcontrollerConfiguration, M_Table.M_TABLE_L_CONFLICTIVE_TRANSITIONS); writeTable(controllerWrite, subcontrollerConfiguration.number, controllerConfiguration, subcontrollerConfiguration, M_Table.M_TABLE_M_TIMETABLE); writeTable(controllerWrite, subcontrollerConfiguration.number, controllerConfiguration, subcontrollerConfiguration, M_Table.M_TABLE_N_SPARE_TIMES); number = subcontrollerConfiguration.number; } if (number > 0) { number++; for (int i=number; i<=4; i++) { writeEmptyTable(controllerWrite, i, M_Table.M_TABLE_A_PHASES_STABLES); writeEmptyTable(controllerWrite, i, M_Table.M_TABLE_B_PHASES_TRANSITIONS); writeEmptyTable(controllerWrite, i, M_Table.M_TABLE_C_TRANSITIONS); writeEmptyTable(controllerWrite, i, M_Table.M_TABLE_D_STRUCTURES); writeEmptyTable(controllerWrite, i, M_Table.M_TABLE_E_ACTION_ON_DEMAND); writeEmptyTable(controllerWrite, i, M_Table.M_TABLE_F_TRANSITIONS_TO_TIMES); writeEmptyTable(controllerWrite, i, M_Table.M_TABLE_G_TRANSITIONS_TIMES); writeEmptyTable(controllerWrite, i, M_Table.M_TABLE_H_MINIMUM_EXTENSION_TIMES); writeEmptyTable(controllerWrite, i, M_Table.M_TABLE_I_PLANS); writeEmptyTable(controllerWrite, i, M_Table.M_TABLE_J_EMERGENCY); writeEmptyTable(controllerWrite, i, M_Table.M_TABLE_K_STARTUP); writeEmptyTable(controllerWrite, i, M_Table.M_TABLE_L_CONFLICTIVE_TRANSITIONS); writeEmptyTable(controllerWrite, i, M_Table.M_TABLE_M_TIMETABLE); writeEmptyTable(controllerWrite, i, M_Table.M_TABLE_N_SPARE_TIMES); } } } catch (Exception e) { throw e; } finally { endRecordingTables(controllerWrite, controllerConfiguration); try{controllerWrite.disconnect();} catch (Exception e){}; } } public void writeTable(ControllerConnection controllerWrite, int controller, M_ControllerConfiguration controllerConfiguration, M_SubcontrollerConfiguration subcontrollerConfiguration, int tableCode) throws ServerException, Exception { List lTableContent = null; if (subcontrollerConfiguration == null) lTableContent = M_ControllerWriter.getTableController(controllerConfiguration, tableCode); else lTableContent = M_ControllerWriter.getTableSubcontroller(controllerConfiguration, subcontrollerConfiguration, tableCode); if (lTableContent.size() <= 0) return; M_Message message = M_ProtocolConstructor.writeTableMessage(controller, lTableContent, hasCRC); // M_Message response = controllerWrite.read(command); M_Request request = new M_Request(); request.controller = this; request.request = message; this.getControllerConnection().addM_Request(request); request.waitResponse(this.controller.getDeviceInformation().timeout); M_Message response = request.response; boolean salir = false; int retries = 0; while ((salir == false) && (retries < MAX_RETRIES)) { if (M_ProtocolAnalyser.isACKMessage(response) == true) { return; } else if (M_ProtocolAnalyser.isNACKMessage(response) == true) { throw new Exception(Shared.getMessage("Error sending table %1 (nack)").replaceAll("%1", "" + tableCode)); } // response = controllerWrite.receive(); request = new M_Request(); request.controller = this; request.request = message; this.getControllerConnection().addM_Request(request); request.waitResponse(this.controller.getDeviceInformation().timeout); response = request.response; retries++; } } public void writeEmptyTable(ControllerConnection controllerWrite, int controller, int tableCode) throws ServerException, Exception { List lTableContent = new ArrayList(); M_TableWriter writer = new M_TableWriter(); writer.STX(); writer.write(controller); writer.write(tableCode); writer.EOB12(); writer.ETX(); byte[] content = writer.toByteArray(); for (int i=0; i public M_ControllerRealtimeCountingDetector[][] getTrafficDataPeriod(long from, long to) throws ServerException, Exception { // TODO in all controllers of the different controller types (Dynamic, Rtac, Telvent, etc) throw new ServerException ("Not supported"); } private void removeSubcontrollerUpdate(M_Controller controllerclone, int subcontroller) { try { M_ControllerStatusSubcontroller subcontroller1 = controllerclone.getDeviceStatus().getStatusSubcontroller(subcontroller); for (M_ControllerStatusSubcontroller subcontroller2 : controllerclone.getDeviceStatus().lsubcontrollerUpdate) { if (subcontroller2.number == subcontroller1.number) { if (Serialization.equals(subcontroller1, subcontroller2) == true) { controllerclone.getDeviceStatus().lsubcontrollerUpdate.remove(subcontroller2); return; } } } } catch (Exception e) { } } private boolean stateSubcontrollerDifferent(M_ControllerStatusSubcontroller currentStatus, M_ControllerStatusSubcontroller updateStatus) { try { if ((updateStatus.adaptativeDetectors != M_ControllerStatusSubcontroller.UNKNOWN) && (updateStatus.adaptativeDetectors != currentStatus.adaptativeDetectors)) return(true); if ((updateStatus.centralizedMode != M_ControllerStatusSubcontroller.UNKNOWN) && (updateStatus.centralizedMode != currentStatus.centralizedMode)) return(true); if ((updateStatus.colorsMode != M_ControllerStatusSubcontroller.UNKNOWN) && (updateStatus.colorsMode != currentStatus.colorsMode)) return(true); if ((updateStatus.controlComputerDirectGroups != M_ControllerStatusSubcontroller.UNKNOWN) && (updateStatus.controlComputerDirectGroups != currentStatus.controlComputerDirectGroups)) return(true); if ((updateStatus.coordinationMode != M_ControllerStatusSubcontroller.UNKNOWN) && (updateStatus.coordinationMode != currentStatus.coordinationMode) && (currentStatus.planSelection != M_ControllerStatusSubcontroller.PLANSELECTION_TIMETABLE) && (updateStatus.planSelection != M_ControllerStatusSubcontroller.PLANSELECTION_TIMETABLE)) return(true); if ((updateStatus.emergency != M_ControllerStatusSubcontroller.UNKNOWN) && (updateStatus.emergency != currentStatus.emergency)) return(true); // if ((updateStatus.manualControl != M_ControllerStatusSubcontroller.UNKNOWN) && (updateStatus.manualControl != currentStatus.manualControl)) // return(true); if ((updateStatus.operationMode != M_ControllerStatusSubcontroller.UNKNOWN) && (updateStatus.operationMode != currentStatus.operationMode)) return(true); if ((updateStatus.planSelection != M_ControllerStatusSubcontroller.UNKNOWN) && (updateStatus.planSelection != currentStatus.planSelection)) return(true); } catch (Exception exception) { } return(false); } public ControllerConnection getControllerConnection() { return(Shared.getControllerConnection(controller.getDeviceInformation().address + ":" + controller.getDeviceInformation().portM)); } private M_Message generateExampleResponse(int subcontroller, Calendar calendarStart, Calendar calendarEnd, boolean hasCRC) { M_Message response = new M_Message(); try { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(calendarStart.getTimeInMillis()); M_ProtocolWriter writer = new M_ProtocolWriter(); writer.STX(); writer.write(subcontroller); writer.write(writer.M_BUS_DETECTIONS_QUERY); int numDemands = 10; for (int i=0; i> 7) & 0x7F); writer.write(trackAngle & 0x7F); writer.write((vehicle >> 7) & 0x7F); writer.write(vehicle & 0x7F); writer.write((delay >> 7) & 0x7F); writer.write(delay & 0x7F); // Start { writer.write(calendar.get(Calendar.DATE)); writer.write(calendar.get(Calendar.MONTH) + 1); writer.write(calendar.get(Calendar.YEAR) - 2000); writer.write(calendar.get(Calendar.HOUR_OF_DAY)); writer.write(calendar.get(Calendar.MINUTE)); writer.write(calendar.get(Calendar.SECOND)); } long millis = (i+1)*60000L; calendar.setTimeInMillis(calendar.getTimeInMillis() + millis); // End { writer.write(calendar.get(Calendar.DATE)); writer.write(calendar.get(Calendar.MONTH) + 1); writer.write(calendar.get(Calendar.YEAR) - 2000); writer.write(calendar.get(Calendar.HOUR_OF_DAY)); writer.write(calendar.get(Calendar.MINUTE)); writer.write(calendar.get(Calendar.SECOND)); } boolean granted = ((i%2) == 0); if (granted == true) { writer.write(0x01); writer.write(0x00); } else { writer.write(0x00); int reason = (i % 5); reason = (int)Math.pow(2, reason); writer.write(reason); } if (i < (numDemands-1)) writer.EOB14(); } writer.EOB12(); writer.ETX(hasCRC); response = writer.createMessage(subcontroller); } catch (Exception exception) { } return(response); } public class ControllerTrafficData extends Controller { public void run () { boolean second0Found = false; boolean query = false; while (exit == false) { try { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); if ((calendar.get(Calendar.SECOND) == 0) || (query == true)) { if (second0Found == false) { second0Found = true; query = true; if (controller.getDeviceConfiguration().lstrategicalDetector.size() > 0) { // d - 1 min (Detectores contaje) getCurrentCountingDetectors(controller); query = false; } } } else { second0Found = false; } } catch (Exception e) { } try{sleep(100);} catch (Exception e){}; } } } }