package art.servers.rtzserver.controller; import art.library.interop.InteropParameters; import art.library.model.devices.DeviceAction; import art.library.model.devices.DeviceActionResult; import art.library.model.devices.colors.controller.RTZ32.RTZ32_Controller; import art.library.model.devices.colors.controller.RTZ32.RTZ32_ControllerCommands; import art.library.model.devices.colors.controller.RTZ32.status.RTZ32_Status_Centralized; import art.servers.Shared; import java.util.ArrayList; import java.util.List; public class Controller_RTZ32_Actions { public static DeviceAction[] sendCommands(Controller_RTZ32 controller, RTZ32_Controller device, InteropParameters parameters, RTZ32_ControllerCommands commands) { List result = new ArrayList(); boolean updateRealtime = false; try { if (commands.control != null) { RTZ32_ControllerCommands command = new RTZ32_ControllerCommands(); command.control = commands.control; result.add(control(controller, parameters, command)); } else if (commands.computerMode != null) { RTZ32_ControllerCommands command = new RTZ32_ControllerCommands(); command.computerMode = commands.computerMode; result.add(computerMode(controller, parameters, command)); } else if (commands.centralized != null) { RTZ32_ControllerCommands command = new RTZ32_ControllerCommands(); command.centralized = commands.centralized; result.add(centralized(controller, parameters, command)); } else if (commands.realtimeJunction != null) { RTZ32_ControllerCommands command = new RTZ32_ControllerCommands(); command.realtimeJunction = commands.realtimeJunction; command.realtimePhases = commands.realtimePhases; result.add(realtimeJunction(controller, parameters, command)); updateRealtime = true; } else if (commands.realtimePhases != null) { RTZ32_ControllerCommands command = new RTZ32_ControllerCommands(); command.realtimePhases = commands.realtimePhases; result.add(realtimePhases(controller, parameters, command)); updateRealtime = true; } else if (commands.realtimeGroups != null) { RTZ32_ControllerCommands command = new RTZ32_ControllerCommands(); command.realtimeGroups = commands.realtimeGroups; result.add(realtimeGroups(controller, parameters, command)); updateRealtime = true; } else if (commands.colorsMode != null) { RTZ32_ControllerCommands command = new RTZ32_ControllerCommands(); command.colorsMode = commands.colorsMode; result.add(colorsMode(controller, parameters, command)); updateRealtime = true; } else if ((commands.clearAlarms != null) && (commands.clearAlarms.booleanValue() == true)) { RTZ32_ControllerCommands command = new RTZ32_ControllerCommands(); command.clearAlarms = commands.clearAlarms; result.add(clearAlarms(controller, parameters, command)); updateRealtime = true; } else if (commands.communications != null) { RTZ32_ControllerCommands command = new RTZ32_ControllerCommands(); command.communications = commands.communications; result.add(communications(controller, parameters, command)); updateRealtime = true; } else if (commands.reset != null) { RTZ32_ControllerCommands command = new RTZ32_ControllerCommands(); command.reset = commands.reset; result.add(reset(controller, parameters, command)); updateRealtime = true; } else if (commands.plan != null) { RTZ32_ControllerCommands command = new RTZ32_ControllerCommands(); command.plan = commands.plan; result.add(plan(controller, parameters, command)); updateRealtime = true; } else if (commands.configurationRead != null) { RTZ32_ControllerCommands command = new RTZ32_ControllerCommands(); command.configurationRead = commands.configurationRead; result.add(configurationRead(controller, parameters, command)); updateRealtime = true; } else if (commands.configurationWrite != null) { RTZ32_ControllerCommands command = new RTZ32_ControllerCommands(); command.configurationWrite = commands.configurationWrite; result.add(configurationWrite(controller, parameters, command)); updateRealtime = true; } else if (commands.timestamp != null) { RTZ32_ControllerCommands command = new RTZ32_ControllerCommands(); command.timestamp = commands.timestamp; result.add(timestamp(controller, parameters, command)); updateRealtime = true; } if (updateRealtime == true) { update(controller); } } catch (Exception exception) { } return result.toArray(new DeviceAction[result.size()]); } private static DeviceAction control(Controller_RTZ32 controller, InteropParameters parameters, RTZ32_ControllerCommands command) { DeviceAction action = new DeviceAction(controller.getController(), parameters, command); try { controller.talker.writer.ORD_LOCAL_ORDENADOR(command.control); action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_CORRECT)); } catch (Exception exception) { action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception)); } Shared.model.addAction(action); return action; } private static DeviceAction computerMode(Controller_RTZ32 controller, InteropParameters parameters, RTZ32_ControllerCommands command) { DeviceAction action = new DeviceAction(controller.getController(), parameters, command); try { controller.talker.writer.ORD_ORDENADOR(command.computerMode); action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_CORRECT)); } catch (Exception exception) { action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception)); } Shared.model.addAction(action); return action; } private static DeviceAction centralized(Controller_RTZ32 controller, InteropParameters parameters, RTZ32_ControllerCommands command) { DeviceAction action = new DeviceAction(controller.getController(), parameters, command); try { controller.centralized = new RTZ32_Status_Centralized(); controller.centralized.centralized = command.centralized.centralized; Thread thread = new Thread(new Runnable() { public void run() { try { controller.update(); } catch (Exception exception) {}; } }); thread.start(); action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_CORRECT)); } catch (Exception exception) { action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception)); } Shared.model.addAction(action); return action; } private static DeviceAction realtimeJunction(Controller_RTZ32 controller, InteropParameters parameters, RTZ32_ControllerCommands command) { DeviceAction action = new DeviceAction(controller.getController(), parameters, command); try { controller.talker.writer.ORD_TIEMPO_REAL_CRUCE(command.realtimeJunction); controller.talker.writer.ORD_TIEMPO_REAL_FASES(command.realtimePhases); action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_CORRECT)); } catch (Exception exception) { action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception)); } Shared.model.addAction(action); return action; } private static DeviceAction realtimePhases(Controller_RTZ32 controller, InteropParameters parameters, RTZ32_ControllerCommands command) { DeviceAction action = new DeviceAction(controller.getController(), parameters, command); try { controller.talker.writer.ORD_TIEMPO_REAL_FASES(command.realtimePhases); action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_CORRECT)); } catch (Exception exception) { action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception)); } Shared.model.addAction(action); return action; } private static DeviceAction realtimeGroups(Controller_RTZ32 controller, InteropParameters parameters, RTZ32_ControllerCommands command) { DeviceAction action = new DeviceAction(controller.getController(), parameters, command); try { controller.talker.writer.ORD_TIEMPO_REAL_CRUCE(command.realtimeGroups); action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_CORRECT)); } catch (Exception exception) { action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception)); } Shared.model.addAction(action); return action; } private static DeviceAction colorsMode(Controller_RTZ32 controller, InteropParameters parameters, RTZ32_ControllerCommands command) { DeviceAction action = new DeviceAction(controller.getController(), parameters, command); try { controller.talker.writer.ORD_COLORES(command.colorsMode); action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_CORRECT)); } catch (Exception exception) { action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception)); } Shared.model.addAction(action); return action; } private static DeviceAction clearAlarms(Controller_RTZ32 controller, InteropParameters parameters, RTZ32_ControllerCommands command) { DeviceAction action = new DeviceAction(controller.getController(), parameters, command); try { controller.talker.writer.ORD_BORRADO_ALARMAS(command.clearAlarms); action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_CORRECT)); } catch (Exception exception) { action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception)); } Shared.model.addAction(action); return action; } private static DeviceAction communications(Controller_RTZ32 controller, InteropParameters parameters, RTZ32_ControllerCommands command) { DeviceAction action = new DeviceAction(controller.getController(), parameters, command); try { controller.talker.writer.ORD_COMMS(command.communications); action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_CORRECT)); } catch (Exception exception) { action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception)); } Shared.model.addAction(action); return action; } private static DeviceAction reset(Controller_RTZ32 controller, InteropParameters parameters, RTZ32_ControllerCommands command) { DeviceAction action = new DeviceAction(controller.getController(), parameters, command); try { controller.talker.writer.ORD_RESET(command.reset); action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_CORRECT)); } catch (Exception exception) { action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception)); } Shared.model.addAction(action); return action; } private static DeviceAction plan(Controller_RTZ32 controller, InteropParameters parameters, RTZ32_ControllerCommands command) { DeviceAction action = new DeviceAction(controller.getController(), parameters, command); try { controller.talker.writer.ORD_PLAN(command.plan); action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_CORRECT)); } catch (Exception exception) { action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception)); } Shared.model.addAction(action); return action; } private static DeviceAction configurationRead(Controller_RTZ32 controller, InteropParameters parameters, RTZ32_ControllerCommands command) { DeviceAction action = new DeviceAction(controller.getController(), parameters, command); try { Thread thread = new Thread(new Runnable() { public void run() { try { String username = (String)parameters.getParameterValue("username"); controller.configurationRead(username); } catch (Exception exception) { Shared.printstack(controller.name, exception); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); } } }); thread.start(); action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_CORRECT)); } catch (Exception exception) { action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage())); } Shared.model.addAction(action); return action; } private static DeviceAction configurationWrite(Controller_RTZ32 controller, InteropParameters parameters, RTZ32_ControllerCommands command) { DeviceAction action = new DeviceAction(controller.getController(), parameters, command); try { Thread thread = new Thread(new Runnable() { public void run() { try { String username = (String)parameters.getParameterValue("username"); controller.configurationWrite(username, command.configurationWrite); } catch (Exception exception) { Shared.printstack(controller.name, exception); DeviceActionResult actionResult = new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage()); action.setResult(actionResult); Shared.model.addAction(action); } } }); thread.start(); action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_CORRECT)); } catch (Exception exception) { action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception.getMessage())); } Shared.model.addAction(action); return action; } private static DeviceAction timestamp(Controller_RTZ32 controller, InteropParameters parameters, RTZ32_ControllerCommands command) { DeviceAction action = new DeviceAction(controller.getController(), parameters, command); try { controller.talker.writer.ORD_FH(System.currentTimeMillis()); action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_CORRECT)); } catch (Exception exception) { action.setResult(new DeviceActionResult(DeviceActionResult.RESULT_ERROR, exception)); } Shared.model.addAction(action); return action; } private static void update(Controller_RTZ32 controller) { Thread thread = new Thread(new Runnable() { public void run() { try { controller.update(); } catch (Exception exception) {}; } }); thread.start(); } }