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.Model;
|
import art.library.model.devices.Device;
|
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 static art.library.model.devices.colors.controller.M.M_ControllerCommands.COLORS_COLORS;
|
import static art.library.model.devices.colors.controller.M.M_ControllerCommands.COLORS_FLASHING;
|
import static art.library.model.devices.colors.controller.M.M_ControllerCommands.COLORS_OFF;
|
import static art.library.model.devices.colors.controller.M.M_ControllerCommands.OPERATIONMODE_ACTUATED;
|
import static art.library.model.devices.colors.controller.M.M_ControllerCommands.OPERATIONMODE_FIXED;
|
import static art.library.model.devices.colors.controller.M.M_ControllerCommands.OPERATIONMODE_SEMIACTUATED;
|
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_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.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.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.etd.EtdStatus;
|
import art.library.model.devices.etd.status.EtdStatusLane;
|
import art.servers.ServerException;
|
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_Request;
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.Date;
|
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;
|
protected boolean hasCRC = false;
|
// protected ControllerConnection controllerConnection = null;
|
protected String name = null;
|
|
|
protected EtdStatus etdStatus = null;
|
protected int forceRealtime = -1;
|
protected int[] forcedUserControlPlan = new int[1];
|
protected List<M_ControllerStatusSubcontroller> lsubcontrollerUpdate = new ArrayList<M_ControllerStatusSubcontroller>();
|
|
protected List<M_Controller> lcontroller = new ArrayList<M_Controller>();
|
|
|
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;
|
}
|
|
|
public ControllerController(M_Controller m_controller, List<M_Controller> lcontroller, boolean hasCRC)
|
{
|
super(m_controller);
|
this.controller = m_controller;
|
this.lcontroller = lcontroller;
|
this.hasCRC = hasCRC;
|
|
forcedUserControlPlan = new int[lcontroller.size()];
|
for (int i=0; i<forcedUserControlPlan.length; i++)
|
forcedUserControlPlan[i] = M_ControllerCommands.CONDITION_NOTHING;
|
}
|
|
|
public M_Controller getController()
|
{
|
return controller;
|
}
|
|
|
|
// <editor-fold defaultstate="collapsed" desc="Actions">
|
|
// <editor-fold defaultstate="collapsed" desc="Send commands">
|
|
public DeviceAction[] sendCommands(int subcontroller, InteropParameters parameters) throws SerializationException
|
{
|
try
|
{
|
List<DeviceAction> result = new ArrayList<DeviceAction>();
|
|
M_ControllerCommands m_controllerCommands = (M_ControllerCommands)(Serialization.deserialize(M_ControllerCommands.class, (String)parameters.getParameterValue("body-content")));
|
|
if ((m_controllerCommands.colorsMode != M_ControllerCommands.COLORS_NOTHING) ||
|
(m_controllerCommands.operationMode != M_ControllerCommands.OPERATIONMODE_NOTHING) ||
|
(m_controllerCommands.userControlManual != M_ControllerCommands.CONDITION_NOTHING) ||
|
(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;
|
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;
|
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.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));
|
}
|
|
return result.toArray(new DeviceAction[result.size()]);
|
}
|
finally
|
{
|
}
|
}
|
|
// </editor-fold>
|
|
|
|
public void checkNewUpdateCommands (M_Controller controllerclone)
|
{
|
try
|
{
|
List<M_ControllerStatusSubcontroller> lremove = new ArrayList<M_ControllerStatusSubcontroller>();
|
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<M_ControllerStatusSubcontroller>();
|
controllerclone.getDeviceStatus().lsubcontrollerUpdate.add(statusSubcontroller);
|
}
|
}
|
|
if (controllerclone.getDeviceStatus().lsubcontrollerUpdate != null)
|
{
|
controllerclone.getDeviceStatus().lsubcontrollerUpdate.removeAll(lremove);
|
}
|
|
this.lsubcontrollerUpdate.clear();
|
|
lremove.clear();
|
HashMap<Integer, Integer> hsubcontrollers = new HashMap<Integer, Integer>();
|
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);
|
}
|
}
|
}
|
|
Shared.model.updateDevice(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)
|
{
|
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)
|
{
|
|
}
|
}
|
|
|
|
|
// <editor-fold defaultstate="collapsed" desc="Set recordable plan">
|
|
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 = Shared.getMessage(language, "Recordable plan");
|
|
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<recordablePlan.lPhase.size(); i++)
|
{
|
int duration = recordablePlan.lPhase.get(i).maximumTime;
|
if (duration > 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)
|
{
|
exception.printStackTrace();
|
DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage());
|
action.setResult(actionResult);
|
Shared.model.addAction(action);
|
return action;
|
}
|
}
|
|
// </editor-fold>
|
|
|
|
|
// <editor-fold defaultstate="collapsed" desc="Save recordable plan">
|
|
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 = Shared.getMessage(language, "Recordable plan");
|
|
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<recordablePlan.lPhase.size(); i++)
|
{
|
int duration = recordablePlan.lPhase.get(i).maximumTime;
|
if (duration > 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)
|
{
|
exception.printStackTrace();
|
DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage());
|
action.setResult(actionResult);
|
Shared.model.addAction(action);
|
return action;
|
}
|
}
|
|
// </editor-fold>
|
|
|
|
|
// <editor-fold defaultstate="collapsed" desc="Set local plan">
|
|
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 = Shared.getMessage(language, "Local plan");
|
|
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)
|
{
|
exception.printStackTrace();
|
DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage());
|
action.setResult(actionResult);
|
Shared.model.addAction(action);
|
return action;
|
}
|
}
|
|
// </editor-fold>
|
|
// <editor-fold defaultstate="collapsed" desc="Set user control plan">
|
|
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);
|
if (command.userControlPlan == M_ControllerCommands.CONDITION_YES)
|
action.actionName = Shared.getMessage(language, "User forced plan (on)");
|
else if (command.userControlPlan == M_ControllerCommands.CONDITION_NO)
|
action.actionName = Shared.getMessage(language, "User forced plan (off)");
|
|
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)
|
{
|
exception.printStackTrace();
|
DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage());
|
action.setResult(actionResult);
|
Shared.model.addAction(action);
|
return action;
|
}
|
}
|
|
// </editor-fold>
|
|
// <editor-fold defaultstate="collapsed" desc="Set plan">
|
|
public List<DeviceAction> setPlanSubcontroller(int subcontroller, InteropParameters parameters, M_ControllerCommands command) throws SerializationException
|
{
|
List<DeviceAction> lresult = new ArrayList<DeviceAction>();
|
|
String language = (String)parameters.getParameterValue("language");
|
DeviceAction action = new DeviceAction(controller, parameters, command);
|
action.actionName = Shared.getMessage(language, "Select plan");
|
|
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<DeviceAction> 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;
|
}
|
}
|
|
// </editor-fold>
|
|
// <editor-fold defaultstate="collapsed" desc="Send local plan">
|
|
public List<DeviceAction> sendLocalPlanSubcontroller(int subcontroller, InteropParameters parameters, M_ControllerCommands command) throws SerializationException
|
{
|
List<DeviceAction> lresult = new ArrayList<DeviceAction>();
|
|
String language = (String)parameters.getParameterValue("language");
|
DeviceAction action = new DeviceAction(controller, parameters, command);
|
action.actionName = Shared.getMessage(language, "Select local plan");
|
|
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<DeviceAction> 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;
|
}
|
}
|
|
// </editor-fold>
|
|
|
// <editor-fold defaultstate="collapsed" desc="Update time">
|
|
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 = Shared.getMessage(language, "Update time");
|
|
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;
|
}
|
}
|
|
// </editor-fold>
|
|
|
// <editor-fold defaultstate="collapsed" desc="Set realtime detectors">
|
|
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 = Shared.getMessage(language, "Disable realtime detectors");
|
|
try
|
{
|
if (command.realtime == DeviceCommands.CONDITION_ENABLED)
|
{
|
action.actionName = Shared.getMessage(language, "Enable realtime");
|
this.forceRealtime = 1;
|
}
|
else if (command.realtime == DeviceCommands.CONDITION_DISABLED)
|
{
|
action.actionName = Shared.getMessage(language, "Disable realtime");
|
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;
|
}
|
}
|
|
// </editor-fold>
|
|
|
// <editor-fold defaultstate="collapsed" desc="Set state subcontroller">
|
|
public List<DeviceAction> setStateSubcontroller(int subcontroller, int adaptative, int adaptativeDetectors, int centralizedMode, int controlComputerDirectGroups,
|
int coordinationMode, int planSelection, InteropParameters parameters, M_ControllerCommands command) throws SerializationException
|
{
|
String language = (String)parameters.getParameterValue("language");
|
List<DeviceAction> laction = new ArrayList<DeviceAction>();
|
|
try
|
{
|
int colorsMode = command.colorsMode;
|
int operationMode = command.operationMode;
|
int userControlManual = command.userControlManual;
|
int emergency = command.emergency;
|
|
M_ControllerConfiguration controllerConfiguration = controller.getDeviceConfiguration();
|
M_SubcontrollerConfiguration subcontrollerConfiguration = controllerConfiguration.getSubcontroller(subcontroller);
|
if (subcontrollerConfiguration == null)
|
{
|
if (command.colorsMode != M_ControllerCommands.COLORS_NOTHING)
|
{
|
DeviceAction action = new DeviceAction(controller, parameters, command);
|
|
switch (command.colorsMode)
|
{
|
case COLORS_COLORS: action.actionName = Shared.getMessage(language, "Colors on"); break;
|
case COLORS_FLASHING: action.actionName = Shared.getMessage(language, "Colors flashing yellow"); break;
|
case COLORS_OFF: action.actionName = Shared.getMessage(language, "Colors off"); break;
|
}
|
|
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)
|
{
|
DeviceAction action2 = new DeviceAction(controller, parameters, command);
|
|
switch (command.operationMode)
|
{
|
case OPERATIONMODE_FIXED: action2.actionName = Shared.getMessage(language, "Fixed times"); break;
|
case OPERATIONMODE_ACTUATED: action2.actionName = Shared.getMessage(language, "Actuated"); break;
|
case OPERATIONMODE_SEMIACTUATED: action2.actionName = Shared.getMessage(language, "Semiactuated"); break;
|
}
|
|
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)
|
{
|
DeviceAction action2 = new DeviceAction(controller, parameters, command);
|
|
switch (command.userControlManual)
|
{
|
case CONDITION_YES: action2.actionName = Shared.getMessage(language, "User manual control (on)"); break;
|
case CONDITION_NO: action2.actionName = Shared.getMessage(language, "User manual control (off)"); break;
|
}
|
|
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)
|
{
|
DeviceAction action2 = new DeviceAction(controller, parameters, command);
|
|
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_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 ((colorsMode < M_ControllerCommands.COLORS_OFF) || (colorsMode > M_ControllerCommands.COLORS_COLORS))
|
{
|
DeviceAction action = new DeviceAction(controller, parameters, command);
|
|
switch (command.colorsMode)
|
{
|
case COLORS_COLORS: action.actionName = Shared.getMessage(language, "Colors on"); break;
|
case COLORS_FLASHING: action.actionName = Shared.getMessage(language, "Colors flashing yellow"); break;
|
case COLORS_OFF: action.actionName = Shared.getMessage(language, "Colors off"); break;
|
}
|
|
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)
|
{
|
DeviceAction action2 = new DeviceAction(controller, parameters, command);
|
|
switch (command.operationMode)
|
{
|
case OPERATIONMODE_FIXED: action2.actionName = Shared.getMessage(language, "Fixed times"); break;
|
case OPERATIONMODE_ACTUATED: action2.actionName = Shared.getMessage(language, "Actuated"); break;
|
case OPERATIONMODE_SEMIACTUATED: action2.actionName = Shared.getMessage(language, "Semiactuated"); break;
|
}
|
|
DeviceActionResult actionResult2 = new DeviceActionResult(DeviceActionResult.RESULT_NOTSEND);
|
action2.setResult(actionResult2);
|
Shared.model.addAction(action2);
|
laction.add(action2);
|
}
|
|
if (command.userControlManual != M_ControllerCommands.CONDITION_NOTHING)
|
{
|
DeviceAction action2 = new DeviceAction(controller, parameters, command);
|
|
switch (command.userControlManual)
|
{
|
case CONDITION_YES: action2.actionName = Shared.getMessage(language, "User manual control (on)"); break;
|
case CONDITION_NO: action2.actionName = Shared.getMessage(language, "User manual control (off)"); break;
|
}
|
|
DeviceActionResult actionResult2 = new DeviceActionResult(DeviceActionResult.RESULT_NOTSEND);
|
action2.setResult(actionResult2);
|
Shared.model.addAction(action2);
|
laction.add(action2);
|
}
|
|
if (command.emergency != M_ControllerCommands.CONDITION_NOTHING)
|
{
|
DeviceAction action2 = new DeviceAction(controller, parameters, command);
|
|
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 ((operationMode < M_ControllerCommands.OPERATIONMODE_FIXED) || (operationMode > M_ControllerCommands.OPERATIONMODE_ACTUATED))
|
{
|
if (command.colorsMode != M_ControllerCommands.COLORS_NOTHING)
|
{
|
DeviceAction action = new DeviceAction(controller, parameters, command);
|
|
switch (command.colorsMode)
|
{
|
case COLORS_COLORS: action.actionName = Shared.getMessage(language, "Colors on"); break;
|
case COLORS_FLASHING: action.actionName = Shared.getMessage(language, "Colors flashing yellow"); break;
|
case COLORS_OFF: action.actionName = Shared.getMessage(language, "Colors off"); break;
|
}
|
|
DeviceActionResult actionResult2 = new DeviceActionResult(DeviceActionResult.RESULT_NOTSEND);
|
action.setResult(actionResult2);
|
Shared.model.addAction(action);
|
laction.add(action);
|
}
|
|
DeviceAction action = new DeviceAction(controller, parameters, command);
|
|
switch (command.operationMode)
|
{
|
case OPERATIONMODE_FIXED: action.actionName = Shared.getMessage(language, "Fixed times"); break;
|
case OPERATIONMODE_ACTUATED: action.actionName = Shared.getMessage(language, "Actuated"); break;
|
case OPERATIONMODE_SEMIACTUATED: action.actionName = Shared.getMessage(language, "Semiactuated"); break;
|
}
|
|
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)
|
{
|
DeviceAction action2 = new DeviceAction(controller, parameters, command);
|
|
switch (command.userControlManual)
|
{
|
case CONDITION_YES: action2.actionName = Shared.getMessage(language, "User manual control (on)"); break;
|
case CONDITION_NO: action2.actionName = Shared.getMessage(language, "User manual control (off)"); break;
|
}
|
|
DeviceActionResult actionResult2 = new DeviceActionResult(DeviceActionResult.RESULT_NOTSEND);
|
action2.setResult(actionResult2);
|
Shared.model.addAction(action2);
|
laction.add(action2);
|
}
|
|
if (command.emergency != M_ControllerCommands.CONDITION_NOTHING)
|
{
|
DeviceAction action2 = new DeviceAction(controller, parameters, command);
|
|
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, emergency, hasCRC);
|
getControllerConnection().send(request.toByteArray());
|
|
if (command.colorsMode != M_ControllerCommands.COLORS_NOTHING)
|
{
|
DeviceAction action = new DeviceAction(controller, parameters, command);
|
|
switch (command.colorsMode)
|
{
|
case COLORS_COLORS: action.actionName = Shared.getMessage(language, "Colors on"); break;
|
case COLORS_FLASHING: action.actionName = Shared.getMessage(language, "Colors flashing yellow"); break;
|
case COLORS_OFF: action.actionName = Shared.getMessage(language, "Colors off"); break;
|
}
|
|
DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_CORRECT);
|
action.setResult(actionResult);
|
Shared.model.addAction(action);
|
laction.add(action);
|
}
|
|
if (command.operationMode != M_ControllerCommands.OPERATIONMODE_NOTHING)
|
{
|
DeviceAction action = new DeviceAction(controller, parameters, command);
|
|
switch (command.operationMode)
|
{
|
case OPERATIONMODE_FIXED: action.actionName = Shared.getMessage(language, "Fixed times"); break;
|
case OPERATIONMODE_ACTUATED: action.actionName = Shared.getMessage(language, "Actuated"); break;
|
case OPERATIONMODE_SEMIACTUATED: action.actionName = Shared.getMessage(language, "Semiactuated"); break;
|
}
|
|
DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_CORRECT);
|
action.setResult(actionResult);
|
Shared.model.addAction(action);
|
laction.add(action);
|
}
|
|
if (command.userControlManual != M_ControllerCommands.CONDITION_NOTHING)
|
{
|
DeviceAction action = new DeviceAction(controller, parameters, command);
|
|
switch (command.userControlManual)
|
{
|
case CONDITION_YES: action.actionName = Shared.getMessage(language, "User manual control (on)"); break;
|
case CONDITION_NO: action.actionName = Shared.getMessage(language, "User manual control (off)"); break;
|
}
|
|
DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_CORRECT);
|
action.setResult(actionResult);
|
Shared.model.addAction(action);
|
laction.add(action);
|
}
|
|
if (command.emergency != M_ControllerCommands.CONDITION_NOTHING)
|
{
|
DeviceAction action = new DeviceAction(controller, parameters, command);
|
|
switch (command.emergency)
|
{
|
case CONDITION_ENABLED: action.actionName = Shared.getMessage(language, "Emergency (on)"); break;
|
case CONDITION_DISABLED: action.actionName = Shared.getMessage(language, "Emergency (off)"); break;
|
}
|
|
DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_CORRECT);
|
action.setResult(actionResult);
|
Shared.model.addAction(action);
|
laction.add(action);
|
}
|
|
return laction;
|
}
|
catch (Exception exception)
|
{
|
exception.printStackTrace();
|
if (command.colorsMode != M_ControllerCommands.COLORS_NOTHING)
|
{
|
DeviceAction action = new DeviceAction(controller, parameters, command);
|
|
switch (command.colorsMode)
|
{
|
case COLORS_COLORS: action.actionName = Shared.getMessage(language, "Colors on"); break;
|
case COLORS_FLASHING: action.actionName = Shared.getMessage(language, "Colors flashing yellow"); break;
|
case COLORS_OFF: action.actionName = Shared.getMessage(language, "Colors off"); break;
|
}
|
|
DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception);
|
action.setResult(actionResult);
|
Shared.model.addAction(action);
|
laction.add(action);
|
}
|
|
if (command.operationMode != M_ControllerCommands.OPERATIONMODE_NOTHING)
|
{
|
DeviceAction action = new DeviceAction(controller, parameters, command);
|
|
switch (command.operationMode)
|
{
|
case OPERATIONMODE_FIXED: action.actionName = Shared.getMessage(language, "Fixed times"); break;
|
case OPERATIONMODE_ACTUATED: action.actionName = Shared.getMessage(language, "Actuated"); break;
|
case OPERATIONMODE_SEMIACTUATED: action.actionName = Shared.getMessage(language, "Semiactuated"); break;
|
}
|
|
DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception);
|
action.setResult(actionResult);
|
Shared.model.addAction(action);
|
laction.add(action);
|
}
|
|
if (command.userControlManual != M_ControllerCommands.CONDITION_NOTHING)
|
{
|
DeviceAction action = new DeviceAction(controller, parameters, command);
|
|
switch (command.userControlManual)
|
{
|
case CONDITION_YES: action.actionName = Shared.getMessage(language, "User manual control (on)"); break;
|
case CONDITION_NO: action.actionName = Shared.getMessage(language, "User manual control (off)"); break;
|
}
|
|
DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception);
|
action.setResult(actionResult);
|
Shared.model.addAction(action);
|
laction.add(action);
|
}
|
|
if (command.emergency != M_ControllerCommands.CONDITION_NOTHING)
|
{
|
DeviceAction action = new DeviceAction(controller, parameters, command);
|
|
switch (command.emergency)
|
{
|
case CONDITION_ENABLED: action.actionName = Shared.getMessage(language, "Emergency (on)"); break;
|
case CONDITION_DISABLED: action.actionName = Shared.getMessage(language, "Emergency (off)"); break;
|
}
|
|
DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception);
|
action.setResult(actionResult);
|
Shared.model.addAction(action);
|
laction.add(action);
|
}
|
|
return laction;
|
}
|
}
|
|
// </editor-fold>
|
|
|
// <editor-fold defaultstate="collapsed" desc="Shift phase">
|
|
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 = Shared.getMessage(language, "Shift phase");
|
|
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;
|
}
|
}
|
|
// </editor-fold>
|
|
|
// <editor-fold defaultstate="collapsed" desc="Set direct group output">
|
|
// 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 = Shared.getMessage(language, "Set direct group output");
|
//
|
// try
|
// {
|
// List<M_ControllerCommandsDirectGroupOutput> 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;
|
// }
|
// }
|
|
// </editor-fold>
|
|
|
// <editor-fold defaultstate="collapsed" desc="Clear alarms">
|
|
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 = Shared.getMessage(language, "Clear alarms");
|
|
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;
|
}
|
}
|
|
// </editor-fold>
|
|
|
// <editor-fold defaultstate="collapsed" desc="Get status functions">
|
|
protected void getCurrentSubcontrollersState(M_Controller m_controllerClone) throws ServerException, Exception
|
{
|
if (m_controllerClone.getDeviceStatus().lsubcontroller.size() == 0)
|
{
|
createStatusSubcontrollers(m_controllerClone);
|
}
|
else
|
{
|
for (M_ControllerStatusSubcontroller m_controllerStatusSubcontroller : m_controllerClone.getDeviceStatus().lsubcontroller)
|
{
|
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);
|
if (recordablePlan == null)
|
{
|
M_Plan subcontrollerRecordablePlan = controller.getDeviceStatus().getStatusSubcontroller(subcontroller).recordablePlan;
|
if (subcontrollerRecordablePlan == null)
|
{
|
// System.out.println(Device.getDate(System.currentTimeMillis()) + this.controller.getIdentifier() + " > " + Shared.getMessage("Recordable plan is not configured") + ", " + Shared.getMessage("Subcontroller") + " : " + subcontroller);
|
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)
|
{
|
e.printStackTrace();
|
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<Integer, Integer> hdestination = new HashMap<Integer, Integer>();
|
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;
|
}
|
}
|
}
|
|
// int cycleTime = 0;
|
// for (Integer duration : recordablePlan.lPhaseTime)
|
// {
|
// cycleTime += duration.intValue();
|
// }
|
//
|
// M_IntergreenToTimeTable transitionsToTimeTable = subcontrollerConfiguration.getIntergreenToTimeTable(recordablePlan.transitionsToTimesTable);
|
// for (M_Assignment assignment : transitionsToTimeTable.lAssignment)
|
// {
|
// M_IntergreensPositionTimes intergreensPositionTimes = subcontrollerConfiguration.getIntergreensPositionTimes(assignment.timetable);
|
// for (M_IntergreenPositionTimes intergreen : intergreensPositionTimes.lIntegreenTimes)
|
// {
|
// if (intergreen.intergreen == assignment.intergreen)
|
// {
|
// for (Integer time : intergreen.times)
|
// {
|
// cycleTime += time.intValue();
|
// }
|
// }
|
// }
|
// }
|
|
recordablePlan.cycleTime = cycleTime;
|
|
return(recordablePlan);
|
}
|
|
// </editor-fold>
|
|
|
|
// <editor-fold defaultstate="collapsed" desc="Get realtime functions">
|
|
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");
|
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)));
|
// System.out.println(controller.information.getIdentifier() + " - " + 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);
|
|
M_ProtocolAnalyser.analyseCurrentPresenceDetectorsResponse(m_controllerClone, request.response, 0x00);
|
}
|
|
|
protected long getCurrentTime(M_Controller m_controllerClone) throws ServerException, Exception
|
{
|
M_Message 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));
|
}
|
|
|
protected void getCurrentStatusGroups(M_Controller m_controllerClone) throws ServerException, Exception
|
{
|
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);
|
}
|
|
// </editor-fold>
|
|
|
// <editor-fold defaultstate="collapsed" desc="Get traffic data functions">
|
|
protected void getCurrentCountingDetectors(M_Controller m_controllerClone) throws ServerException, Exception
|
{
|
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);
|
this.etdStatus = newEtdStatus;
|
}
|
|
// </editor-fold>
|
|
|
// <editor-fold defaultstate="collapsed" desc="Get realtime traffic data">
|
|
public EtdStatus getRealtimeTrafficData(long timestamp) throws ServerException, Exception
|
{
|
if (this.etdStatus.measurementTimestamp > timestamp)
|
{
|
return(this.etdStatus);
|
}
|
|
throw new ServerException(Shared.getMessage("Not new information"));
|
}
|
|
// </editor-fold>
|
|
// <editor-fold defaultstate="collapsed" desc="Private functions">
|
|
private void updateStatusSubcontroller(M_ControllerStatusSubcontroller currentRealStatus, M_ControllerStatusSubcontroller currentStatus, M_ControllerStatusSubcontroller newStatus) throws Exception
|
{
|
if (this.controller.getIdentifier().equalsIgnoreCase("controller-accra-0137") == true)
|
{
|
if ((currentRealStatus != null) && (currentStatus != null))
|
{
|
System.out.println(Device.getDate(System.currentTimeMillis()) + " - " + this.controller.getIdentifier() + " - STARTING");
|
System.out.println(Serialization.toPrettyString(currentRealStatus));
|
System.out.println("------------------------");
|
System.out.println(Serialization.toPrettyString(currentStatus));
|
System.out.println("------------------------");
|
}
|
}
|
|
if (newStatus != null)
|
{
|
if (this.controller.getIdentifier().equalsIgnoreCase("controller-accra-0137") == true)
|
{
|
System.out.println(Serialization.toPrettyString(newStatus));
|
System.out.println("------------------------");
|
}
|
|
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;
|
|
if (this.controller.getIdentifier().equalsIgnoreCase("controller-accra-0137") == true)
|
{
|
if (currentStatus != null)
|
{
|
System.out.println(Device.getDate(System.currentTimeMillis()) + " - " + this.controller.getIdentifier() + " - END");
|
System.out.println(Serialization.toPrettyString(currentStatus));
|
System.out.println("------------------------");
|
}
|
}
|
}
|
|
|
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);
|
|
int cycleTime = 0;
|
for (ALUVISA_Phase phase : aluvisaPlan.lPhase)
|
{
|
cycleTime += phase.maximumTime;
|
}
|
|
HashMap<Integer, Integer> hdestination = new HashMap<Integer, Integer>();
|
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;
|
}
|
}
|
}
|
|
// int cycleTime = 0;
|
// for (Integer duration : plan.lPhaseTime)
|
// {
|
// cycleTime += duration.intValue();
|
// }
|
//
|
// M_SubcontrollerConfiguration subcontrollerConfiguration = controller.getDeviceConfiguration().getSubcontroller(subcontroller);
|
// M_IntergreenToTimeTable transitionsToTimeTable = subcontrollerConfiguration.getIntergreenToTimeTable(plan.transitionsToTimesTable);
|
// for (M_Assignment assignment : transitionsToTimeTable.lAssignment)
|
// {
|
// M_IntergreensPositionTimes intergreensPositionTimes = subcontrollerConfiguration.getIntergreensPositionTimes(assignment.timetable);
|
// for (M_IntergreenPositionTimes intergreen : intergreensPositionTimes.lIntegreenTimes)
|
// {
|
// if (intergreen.intergreen == assignment.intergreen)
|
// {
|
// for (Integer time : intergreen.times)
|
// {
|
// cycleTime += time.intValue();
|
// }
|
// }
|
// }
|
// }
|
|
return(cycleTime);
|
}
|
|
|
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<m_controllerClone.getDeviceStatus().lsubcontroller.size(); i++)
|
{
|
m_controllerClone.getDeviceStatus().lsubcontroller.remove(m_controllerClone.getDeviceStatus().lsubcontroller.size()-1);
|
}
|
}
|
else if (m_controllerClone.getDeviceStatus().lsubcontroller.size() < m_controllerClone.getDeviceConfiguration().lsubcontroller.size())
|
{
|
for (int i=1; i<=4; i++)
|
{
|
try
|
{
|
M_ControllerStatusSubcontroller statusSubcontroller = new M_ControllerStatusSubcontroller();
|
statusSubcontroller.number = i;
|
M_Message command = M_ProtocolConstructor.getCurrentState(i, 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(statusSubcontroller, request.response, i);
|
m_controllerClone.getDeviceStatus().lsubcontroller.add(statusSubcontroller);
|
}
|
catch (Exception e)
|
{
|
i = 5;
|
}
|
}
|
}
|
}
|
|
protected void createStatusSubcontrollers(M_Controller m_controllerClone) throws ServerException, Exception
|
{
|
for (int i=1; i<=4; i++)
|
{
|
try
|
{
|
M_ControllerStatusSubcontroller statusSubcontroller = new M_ControllerStatusSubcontroller();
|
statusSubcontroller.number = i;
|
M_Message command = M_ProtocolConstructor.getCurrentState(i, 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(statusSubcontroller, request.response, i);
|
m_controllerClone.getDeviceStatus().lsubcontroller.add(statusSubcontroller);
|
}
|
catch (Exception e)
|
{
|
i = 5;
|
}
|
}
|
}
|
|
|
protected void createRealtimeSubcontrollers(M_Controller m_controllerClone) throws ServerException, Exception
|
{
|
for (int i=1; i<=4; i++)
|
{
|
try
|
{
|
M_ControllerRealtimeSubcontroller realtimeSubcontroller = new M_ControllerRealtimeSubcontroller();
|
realtimeSubcontroller.number = i;
|
M_Message command = M_ProtocolConstructor.getCurrentPlan(i, 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(realtimeSubcontroller.number), realtimeSubcontroller, request.response, i);
|
m_controllerClone.getDeviceRealtime().lsubcontroller.add(realtimeSubcontroller);
|
}
|
catch (Exception e)
|
{
|
i = 5;
|
}
|
}
|
}
|
|
|
protected EtdStatus createEtdStatus() throws ServerException, Exception
|
{
|
EtdStatus result = new EtdStatus();
|
result.period = this.controller.getDeviceInformation().pollingTrafficData;
|
result.llane = new ArrayList<EtdStatusLane>();
|
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();
|
}
|
}
|
|
// </editor-fold>
|
|
|
// <editor-fold defaultstate="collapsed" desc="Read tables functions">
|
|
public M_ControllerConfiguration readAllTables() throws ServerException, Exception
|
{
|
ControllerConnection controllerRead = null;
|
|
try
|
{
|
controllerRead = new ControllerConnection(controller.getDeviceInformation().address, controller.getDeviceInformation().portM, controller.getDeviceInformation().timeout, hasCRC);
|
controllerRead.connect();
|
|
List<Byte> lTableData = new ArrayList<Byte>();
|
|
lTableData.addAll(readTable(controllerRead, 0x00, M_Table.M_TABLE_A_GROUPS));
|
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
|
{
|
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<M_ControllerConfiguration.MAXIMUM_NUMBER_SUBCONTROLLERS; i++)
|
for (int i=0; i<1; i++)
|
{
|
List<Byte> 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<numberOfSubcontrollers; i++) lTableData.addAll(readTable(controllerRead, i+1, M_Table.M_TABLE_B_PHASES_TRANSITIONS));
|
for (int i=0; i<numberOfSubcontrollers; i++) lTableData.addAll(readTable(controllerRead, i+1, M_Table.M_TABLE_C_TRANSITIONS));
|
for (int i=0; i<numberOfSubcontrollers; i++) lTableData.addAll(readTable(controllerRead, i+1, M_Table.M_TABLE_D_STRUCTURES));
|
for (int i=0; i<numberOfSubcontrollers; i++) lTableData.addAll(readTable(controllerRead, i+1, M_Table.M_TABLE_E_ACTION_ON_DEMAND));
|
for (int i=0; i<numberOfSubcontrollers; i++) lTableData.addAll(readTable(controllerRead, i+1, M_Table.M_TABLE_F_TRANSITIONS_TO_TIMES));
|
for (int i=0; i<numberOfSubcontrollers; i++) lTableData.addAll(readTable(controllerRead, i+1, M_Table.M_TABLE_G_TRANSITIONS_TIMES));
|
for (int i=0; i<numberOfSubcontrollers; i++) lTableData.addAll(readTable(controllerRead, i+1, M_Table.M_TABLE_H_MINIMUM_EXTENSION_TIMES));
|
for (int i=0; i<numberOfSubcontrollers; i++) lTableData.addAll(readTable(controllerRead, i+1, M_Table.M_TABLE_I_PLANS));
|
for (int i=0; i<numberOfSubcontrollers; i++) lTableData.addAll(readTable(controllerRead, i+1, M_Table.M_TABLE_J_EMERGENCY));
|
for (int i=0; i<numberOfSubcontrollers; i++) lTableData.addAll(readTable(controllerRead, i+1, M_Table.M_TABLE_K_STARTUP));
|
for (int i=0; i<numberOfSubcontrollers; i++) lTableData.addAll(readTable(controllerRead, i+1, M_Table.M_TABLE_L_CONFLICTIVE_TRANSITIONS));
|
for (int i=0; i<numberOfSubcontrollers; i++) lTableData.addAll(readTable(controllerRead, i+1, M_Table.M_TABLE_M_TIMETABLE));
|
for (int i=0; i<numberOfSubcontrollers; i++) lTableData.addAll(readTable(controllerRead, i+1, M_Table.M_TABLE_N_SPARE_TIMES));
|
|
byte[] result = new byte[lTableData.size()];
|
|
for (int i=0; i<result.length; i++)
|
{
|
result[i] = lTableData.get(i).byteValue();
|
}
|
|
M_ControllerConfiguration controllerConfiguration = new M_ControllerReader().load(result);
|
|
for (M_SubcontrollerConfiguration subcontrollerConfiguration : controllerConfiguration.lsubcontroller)
|
{
|
for (M_Plan m_plan : subcontrollerConfiguration.lplan)
|
{
|
int cycleTime = 0;
|
for (Integer duration : m_plan.lPhaseTime)
|
{
|
cycleTime += duration.intValue();
|
}
|
|
M_Structure structure = subcontrollerConfiguration.getStructure(m_plan.structure);
|
M_IntergreenToTimeTable transitionsToTimeTable = subcontrollerConfiguration.getIntergreenToTimeTable(m_plan.transitionsToTimesTable);
|
for (M_Assignment assignment : transitionsToTimeTable.lAssignment)
|
{
|
M_IntergreensPositionTimes intergreensPositionTimes = subcontrollerConfiguration.getIntergreensPositionTimes(assignment.timetable);
|
for (M_IntergreenPositionTimes intergreen : intergreensPositionTimes.lIntegreenTimes)
|
{
|
if (intergreen.intergreen == assignment.intergreen)
|
{
|
for (Integer time : intergreen.times)
|
{
|
cycleTime += time.intValue();
|
}
|
}
|
}
|
}
|
|
m_plan.cycleTime = cycleTime;
|
}
|
}
|
|
System.out.println(Device.getDate(System.currentTimeMillis()) + " - " + this.controller.getIdentifier() + " - Readed tables from controller");
|
return(controllerConfiguration);
|
}
|
catch (Exception e)
|
{
|
e.printStackTrace();
|
System.out.println(Device.getDate(System.currentTimeMillis()) + " - " + this.controller.getIdentifier() + " - Error Reading tables from controller: " + e.toString());
|
throw e;
|
}
|
finally
|
{
|
try{controllerRead.disconnect();} catch (Exception e){};
|
}
|
}
|
|
|
public List<Byte> readTable(ControllerConnection controllerRead, int controller, int tableCode) throws ServerException, Exception
|
{
|
byte[] command = M_ProtocolConstructor.readTableMessage(controller, tableCode, hasCRC);
|
M_Message response = controllerRead.read(command);
|
controllerRead.ack();
|
|
boolean salir = false;
|
int retries = 0;
|
while ((salir == false) && (retries < MAX_RETRIES))
|
{
|
if (M_ProtocolAnalyser.isReadTableMessage(response, controller, tableCode) == true)
|
{
|
List<Byte> lTableData = M_ProtocolAnalyser.analyseReadTable(response, tableCode, hasCRC);
|
controllerRead.ack();
|
|
System.out.println(Device.getDate(System.currentTimeMillis()) + " - " + this.controller.getIdentifier() + " - Readed table: " + tableCode + " from controller: " + controller);
|
return(lTableData);
|
}
|
|
response = controllerRead.receive();
|
controllerRead.ack();
|
retries++;
|
}
|
|
throw new Exception("Error reading table " + controller + " - " + tableCode);
|
}
|
|
// </editor-fold>
|
|
|
// <editor-fold defaultstate="collapsed" desc="Write tables functions">
|
|
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<Byte> lTableContent = null;
|
if (subcontrollerConfiguration == null)
|
lTableContent = M_ControllerWriter.getTableController(controllerConfiguration, tableCode);
|
else
|
lTableContent = M_ControllerWriter.getTableSubcontroller(controllerConfiguration, subcontrollerConfiguration, tableCode);
|
|
if (lTableContent.size() <= 0) return;
|
|
byte[] command = M_ProtocolConstructor.writeTableMessage(controller, lTableContent, hasCRC);
|
M_Message response = controllerWrite.read(command);
|
|
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();
|
retries++;
|
}
|
}
|
|
|
public void writeEmptyTable(ControllerConnection controllerWrite, int controller, int tableCode) throws ServerException, Exception
|
{
|
List<Byte> lTableContent = new ArrayList<Byte>();
|
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<content.length; i++)
|
lTableContent.add(new Byte(content[i]));
|
|
byte[] command = M_ProtocolConstructor.writeTableMessage(controller, lTableContent, hasCRC);
|
M_Message response = controllerWrite.read(command);
|
|
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();
|
retries++;
|
}
|
|
throw new Exception(Shared.getMessage("Error sending table %1 (invalid)").replaceAll("%1", "" + tableCode));
|
}
|
|
|
protected void startRecordingTables(ControllerConnection controllerWrite, M_ControllerConfiguration controllerConfiguration) throws ServerException, Exception
|
{
|
byte[] command = M_ProtocolConstructor.startRecordingTablesMessage(0x00, controllerConfiguration.propietary.configurationCode, controllerConfiguration.propietary.controllerNumber, hasCRC);
|
M_Message response = controllerWrite.read(command);
|
|
boolean salir = false;
|
int retries = 0;
|
while ((salir == false) && (retries < MAX_RETRIES))
|
{
|
if (M_ProtocolAnalyser.isStartRecordingResponse(response) == true)
|
{
|
return;
|
}
|
else if (M_ProtocolAnalyser.isNACKMessage(response) == true)
|
{
|
throw new Exception(Shared.getMessage("Error starting recording (nack)"));
|
}
|
|
response = controllerWrite.receive();
|
retries++;
|
}
|
|
throw new Exception(Shared.getMessage("Error starting recording (invalid)"));
|
}
|
|
|
protected void endRecordingTables(ControllerConnection controllerWrite, M_ControllerConfiguration controllerConfiguration) throws ServerException, Exception
|
{
|
byte[] command = M_ProtocolConstructor.endRecordingTablesMessage(0x00, hasCRC);
|
controllerWrite.setTimeout(60000);
|
M_Message response = controllerWrite.read(command);
|
|
boolean salir = false;
|
int retries = 0;
|
while ((salir == false) && (retries < MAX_RETRIES))
|
{
|
if (M_ProtocolAnalyser.isEndRecordingResponse(response) == true)
|
{
|
M_ProtocolAnalyser.analyseEndRecordingResponse(response);
|
}
|
else if (M_ProtocolAnalyser.isNACKMessage(response) == true)
|
{
|
throw new Exception(Shared.getMessage("End recording response is NACK"));
|
}
|
|
response = controllerWrite.receive();
|
retries++;
|
}
|
}
|
|
// </editor-fold>
|
|
|
public M_ControllerRealtimeCountingDetector[][] getTrafficDataPeriod(long timestamp1, long timestamp2) throws ServerException, Exception
|
{
|
throw new ServerException ("Not supported");
|
}
|
|
|
private boolean splitsDifferent (List<Integer> l1, List<Integer> l2)
|
{
|
try
|
{
|
if (l1.size() != l2.size()) return(true);
|
for (int i=0; i<l1.size(); i++)
|
{
|
int v1 = l1.get(i).intValue();
|
int v2 = l2.get(i).intValue();
|
if (v1 != v2)return(true);
|
}
|
|
return(false);
|
}
|
catch (Exception exception)
|
{
|
exception.printStackTrace();
|
}
|
|
return(true);
|
}
|
|
|
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))
|
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);
|
}
|
|
|
|
|
private ControllerConnection getControllerConnection()
|
{
|
return(Shared.getControllerConnection(controller.getDeviceInformation().address + ":" + controller.getDeviceInformation().portM));
|
}
|
|
}
|