package art.servers.colorsserver; import art.library.interop.InteropParameters; import art.library.interop.serialization.Serialization; import art.library.interop.serialization.SerializationException; 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 art.library.model.devices.colors.controller.M.M_Controller; import art.library.model.devices.colors.controller.M.M_ControllerCommands; import art.library.model.devices.colors.controller.M.M_ControllerConfiguration; import art.library.model.devices.colors.controller.M.M_ControllerInformation; import art.library.model.devices.colors.controller.M.M_ControllerStatus; import art.library.model.devices.colors.controller.M.M_ControllerStatusSubcontroller; import art.servers.colorsserver.controller.ControllerConnection; import art.servers.colorsserver.controller.ControllerDynamicController; import art.servers.colorsserver.controller.ControllerRtacController; import art.servers.colorsserver.controller.ControllerTelventController; import art.servers.controller.ControllerDevice; import java.io.File; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.List; public class Shared extends art.servers.Shared { public static String ipcontrollerlog = "-"; public static int portcontrollerlog = -1; private static HashMap hcontrollerConnection = new HashMap(); private static HashMap hcontrollerConnectionReadTables = new HashMap(); private static HashMap hcontrollerConnectionGroupsRealtime = new HashMap(); private static HashMap hcontrollerConnectionCurrentPlan = new HashMap(); public static Model getModel() { return (art.servers.colorsserver.Model)model; } public static ControllerConnection getControllerConnectionReadTables (String key) { return(hcontrollerConnectionReadTables.get(key)); } public static ControllerConnection getControllerConnectionGroupsRealtime (String key) { return(hcontrollerConnectionGroupsRealtime.get(key)); } public static ControllerConnection getControllerConnectionCurrentPlan (String key) { return(hcontrollerConnectionCurrentPlan.get(key)); } public static ControllerConnection getControllerConnection (String key) { return(hcontrollerConnection.get(key)); } public static void addControllerConnection (String key, ControllerConnection controller) { hcontrollerConnection.putIfAbsent(key, controller); } public static void addControllerConnectionCurrentPlan (String key, ControllerConnection controller) { hcontrollerConnectionCurrentPlan.putIfAbsent(key, controller); } public static void addControllerConnectionReadTables (String key, ControllerConnection controller) { hcontrollerConnectionReadTables.putIfAbsent(key, controller); } public static void addControllerConnectionGroupsRealtime (String key, ControllerConnection controller) { hcontrollerConnectionGroupsRealtime.putIfAbsent(key, controller); } public static DeviceAction[] responseError (M_Controller device, InteropParameters parameters, Exception exception) throws SerializationException, Exception { List result = new ArrayList(); String language = (String)parameters.getParameterValue("language"); // M_ControllerCommands m_controllerCommands = (M_ControllerCommands)(Serialization.deserialize(M_ControllerCommands.class, (String)parameters.getParameterValue("body-content"))); M_ControllerCommands m_controllerCommands = parameters.getBodyContentValue(M_ControllerCommands.class); if (m_controllerCommands.operationMode != M_ControllerCommands.OPERATIONMODE_NOTHING) { M_ControllerCommands command = new M_ControllerCommands(); command.operationMode = m_controllerCommands.operationMode; DeviceAction action = new DeviceAction(device, parameters, command); action.actionName = command.getActionName(); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); result.add(action); } if (m_controllerCommands.userControlManual != M_ControllerCommands.CONDITION_NOTHING) { M_ControllerCommands command = new M_ControllerCommands(); command.userControlManual = m_controllerCommands.userControlManual; DeviceAction action = new DeviceAction(device, parameters, command); action.actionName = command.getActionName(); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); result.add(action); } if (m_controllerCommands.shiftPhase != M_ControllerCommands.CONDITION_YES) { M_ControllerCommands command = new M_ControllerCommands(); command.shiftPhase = m_controllerCommands.shiftPhase; DeviceAction action = new DeviceAction(device, parameters, command); action.actionName = command.getActionName(); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); result.add(action); } if (m_controllerCommands.userControlPlan != M_ControllerCommands.CONDITION_NOTHING) { M_ControllerCommands command = new M_ControllerCommands(); command.userControlPlan = m_controllerCommands.userControlPlan; DeviceAction action = new DeviceAction(device, parameters, command); action.actionName = command.getActionName(); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); result.add(action); } if (m_controllerCommands.recordablePlan != null) { M_ControllerCommands command = new M_ControllerCommands(); command.recordablePlan = m_controllerCommands.recordablePlan; DeviceAction action = new DeviceAction(device, parameters, command); action.actionName = command.getActionName(); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); result.add(action); } if (m_controllerCommands.localPlan != DeviceCommands.CONDITION_NOTHING) { M_ControllerCommands command = new M_ControllerCommands(); command.localPlan = m_controllerCommands.localPlan; DeviceAction action = new DeviceAction(device, parameters, command); action.actionName = command.getActionName(); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); result.add(action); } if (m_controllerCommands.clearAlarms == DeviceCommands.CONDITION_YES) { M_ControllerCommands command = new M_ControllerCommands(); command.clearAlarms = m_controllerCommands.clearAlarms; DeviceAction action = new DeviceAction(device, parameters, command); action.actionName = command.getActionName(); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); result.add(action); } if (m_controllerCommands.colorsMode != M_ControllerCommands.COLORS_NOTHING) { M_ControllerCommands command = new M_ControllerCommands(); command.colorsMode = m_controllerCommands.colorsMode; DeviceAction action = new DeviceAction(device, parameters, command); action.actionName = command.getActionName(); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); result.add(action); } if (m_controllerCommands.updateTime != M_ControllerCommands.CONDITION_YES) { M_ControllerCommands command = new M_ControllerCommands(); command.updateTime = m_controllerCommands.updateTime; DeviceAction action = new DeviceAction(device, parameters, command); action.actionName = command.getActionName(); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); result.add(action); } if (m_controllerCommands.realtime != DeviceCommands.CONDITION_NOTHING) { M_ControllerCommands command = new M_ControllerCommands(); command.realtime = m_controllerCommands.realtime; DeviceAction action = new DeviceAction(device, parameters, command); action.actionName = command.getActionName(); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); result.add(action); } if (m_controllerCommands.emergency != DeviceCommands.CONDITION_NOTHING) { M_ControllerCommands command = new M_ControllerCommands(); command.emergency = m_controllerCommands.emergency; DeviceAction action = new DeviceAction(device, parameters, command); action.actionName = command.getActionName(); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); result.add(action); } return result.toArray(new DeviceAction[result.size()]); } public static void createControllers() throws Exception { HashMap> hcontrollers = new HashMap>(); Device[] ldevice = Shared.model.getDevices(); for (Device device : ldevice) { try { M_Controller m_controller = (M_Controller)device; if (m_controller.getDeviceConfiguration().lsubcontroller.size() == 0) { try { m_controller.status = new M_ControllerStatus(); M_ControllerConfiguration configuration = Serialization.deserialize(M_ControllerConfiguration.class, new File("configs/" + m_controller.getDeviceInformation().number + ".json")); if (configuration != null) { m_controller.configuration = Serialization.clone(configuration); } } catch (Exception e) { Shared.printstack("Shared: " + m_controller.getIdentifier(), e); } } List lcontrollers = hcontrollers.get(m_controller.getDeviceInformation().address + ":" + m_controller.getDeviceInformation().portM); if (lcontrollers == null) { boolean hasCRC = false; if ((m_controller.getDeviceInformation().type == M_ControllerInformation.TYPE_RTAC) || (m_controller.getDeviceInformation().type == M_ControllerInformation.TYPE_CMY)) hasCRC = true; ControllerConnection controllerConnection = new ControllerConnection(m_controller.getDeviceInformation().address, m_controller.getDeviceInformation().portM, m_controller.getDeviceInformation().timeout, hasCRC); Shared.addControllerConnection(m_controller.getDeviceInformation().address + ":" + m_controller.getDeviceInformation().portM, controllerConnection); controllerConnection.start(); lcontrollers = new ArrayList(); hcontrollers.put(m_controller.getDeviceInformation().address + ":" + m_controller.getDeviceInformation().portM, lcontrollers); } lcontrollers.add(m_controller); } catch (Exception e) { Shared.printstack("Shared", e); } } Collection> lvalues = hcontrollers.values(); Iterator> iterator = lvalues.iterator(); while (iterator.hasNext()) { List lcontroller = iterator.next(); if (lcontroller.size() == 1) { M_Controller m_controller = lcontroller.get(0); if (m_controller.getDeviceInformation().timeout < 100) { m_controller.getDeviceInformation().timeout = 15000; } M_ControllerStatus status = m_controller.getDeviceStatus(); if (status.lsubcontroller != null) { if (status.lsubcontroller.size() == 0) { M_ControllerStatusSubcontroller statussubcontroller = new M_ControllerStatusSubcontroller(); statussubcontroller.number = m_controller.getDeviceInformation().subcontroller; status.lsubcontroller.add(statussubcontroller); } } if (m_controller.getDeviceInformation().type == M_ControllerInformation.TYPE_DYNAMIC) { ControllerDevice controller = new ControllerDynamicController(m_controller, false); Shared.lcontroller.add(controller); controller.start(); } else if (m_controller.getDeviceInformation().type == M_ControllerInformation.TYPE_RMY) { ControllerDevice controller = new ControllerTelventController(m_controller, false); Shared.lcontroller.add(controller); controller.start(); } else if (m_controller.getDeviceInformation().type == M_ControllerInformation.TYPE_RTAC) { ControllerDevice controller = new ControllerRtacController(m_controller, true); Shared.lcontroller.add(controller); controller.start(); } else if (m_controller.getDeviceInformation().type == M_ControllerInformation.TYPE_CMY) { ControllerDevice controller = new ControllerTelventController(m_controller, true); Shared.lcontroller.add(controller); controller.start(); } } else { M_Controller m_controller = null; for (M_Controller m_controllerSub : lcontroller) { M_ControllerStatus status = m_controllerSub.getDeviceStatus(); if (status.lsubcontroller != null) { if (status.lsubcontroller.size() == 0) { M_ControllerStatusSubcontroller statussubcontroller = new M_ControllerStatusSubcontroller(); statussubcontroller.number = m_controllerSub.getDeviceInformation().subcontroller; status.lsubcontroller.add(statussubcontroller); } } if (m_controller == null) { m_controller = Serialization.clone(m_controllerSub); } else { m_controller.getDeviceConfiguration().lsubcontroller.addAll(m_controllerSub.getDeviceConfiguration().lsubcontroller); m_controller.getDeviceStatus().lsubcontroller.addAll(m_controllerSub.getDeviceStatus().lsubcontroller); m_controller.getDeviceStatus().lsubcontrollerUpdate.addAll(m_controllerSub.getDeviceStatus().lsubcontrollerUpdate); } } String currentIdentifier = m_controller.getDeviceInformation().getIdentifier(); String identifier = currentIdentifier.substring(0, currentIdentifier.length()-1); identifier = identifier + "0"; m_controller.getDeviceInformation().setIdentifier(identifier); if (m_controller.getDeviceInformation().type == M_ControllerInformation.TYPE_DYNAMIC) { ControllerDevice controller = new ControllerDynamicController(m_controller, lcontroller, false); Shared.lcontroller.add(controller); controller.start(); } else if (m_controller.getDeviceInformation().type == M_ControllerInformation.TYPE_RMY) { ControllerDevice controller = new ControllerTelventController(m_controller, lcontroller, false); Shared.lcontroller.add(controller); controller.start(); } else if (m_controller.getDeviceInformation().type == M_ControllerInformation.TYPE_RTAC) { ControllerDevice controller = new ControllerRtacController(m_controller, lcontroller, true); Shared.lcontroller.add(controller); controller.start(); } else if (m_controller.getDeviceInformation().type == M_ControllerInformation.TYPE_CMY) { ControllerDevice controller = new ControllerTelventController(m_controller, lcontroller, true); Shared.lcontroller.add(controller); controller.start(); } } } } }