package art.servers.rtzserver.controller.RTZ32; import art.library.model.devices.DeviceStatus; import art.library.model.devices.colors.controller.RTZ32.RTZ32_Controller; import art.library.model.devices.colors.controller.RTZ32.RTZ32_ControllerConfiguration; import art.library.model.devices.colors.controller.RTZ32.alarms.RTZ32_Alarms; import art.library.model.devices.colors.controller.RTZ32.alarms.RTZ32_Alarms_Flashing; import art.library.model.devices.colors.controller.RTZ32.alarms.RTZ32_Alarms_Normal; import art.library.model.devices.colors.controller.RTZ32.configuration.RTZ32_Configuration; import art.library.model.devices.colors.controller.RTZ32.configuration.RTZ32_Configuration_Group; import art.library.model.devices.colors.controller.RTZ32.configuration.constants.RTZ32_Constants; import art.library.model.devices.colors.controller.RTZ32.configuration.constants.RTZ32_Constants_Colors; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.RTZ32_Configuration_Table; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.RTZ32_Configuration_Table_1; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.RTZ32_Configuration_Table_11_28; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.RTZ32_Configuration_Table_2; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.RTZ32_Configuration_Table_3; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.RTZ32_Configuration_Table_31; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.RTZ32_Configuration_Table_32; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.RTZ32_Configuration_Table_33; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.RTZ32_Configuration_Table_34; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.RTZ32_Configuration_Table_35; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.RTZ32_Configuration_Table_36; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.RTZ32_Configuration_Table_37; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.RTZ32_Configuration_Table_4; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.RTZ32_Configuration_Table_5; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.RTZ32_Configuration_Table_6; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.RTZ32_Configuration_Table_7; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.RTZ32_Configuration_Table_38_40; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.RTZ32_Configuration_Table_42; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.RTZ32_Configuration_Table_43; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.RTZ32_Configuration_Table_44; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.RTZ32_Configuration_Table_45; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.RTZ32_Configuration_Table_46; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.eprom.RTZ32_Configuration_Table_91; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.eprom.RTZ32_Configuration_Table_92; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.eprom.RTZ32_Configuration_Table_93; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.eprom.RTZ32_Configuration_Table_94; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.eprom.RTZ32_Configuration_Table_95; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.microregulation.RTZ32_Configuration_Table_65; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.microregulation.RTZ32_Configuration_Table_66; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.microregulation.RTZ32_Configuration_Table_67; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.microregulation.RTZ32_Configuration_Table_68; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.microregulation.RTZ32_Configuration_Table_69; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.timetables.RTZ32_Configuration_Table_50; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.timetables.RTZ32_Configuration_Table_51; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.timetables.RTZ32_Configuration_Table_52; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.timetables.RTZ32_Configuration_Table_53_60; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.trolleygroups.RTZ32_Configuration_Table_70; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.trolleygroups.RTZ32_Configuration_Table_71; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.trolleygroups.RTZ32_Configuration_Table_72; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.trolleygroups.RTZ32_Configuration_Table_73; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.trolleygroups.RTZ32_Configuration_Table_74; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.trolleygroups.RTZ32_Configuration_Table_75; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.trolleygroups.RTZ32_Configuration_Table_78; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.trolleygroups.RTZ32_Configuration_Table_79; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.trolleygroups.RTZ32_Configuration_Table_80; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.trolleygroups.RTZ32_Configuration_Table_81; import art.library.model.devices.colors.controller.RTZ32.configuration.tables.trolleygroups.RTZ32_Configuration_Table_82_85; import art.library.model.devices.colors.controller.RTZ32.realtime.RTZ32_Realtime; import art.library.model.devices.colors.controller.RTZ32.realtime.RTZ32_Realtime_Counters; import art.library.model.devices.colors.controller.RTZ32.realtime.RTZ32_Realtime_Detector; import art.library.model.devices.colors.controller.RTZ32.realtime.RTZ32_Realtime_Detectors; import art.library.model.devices.colors.controller.RTZ32.realtime.RTZ32_Realtime_Groups; import art.library.model.devices.colors.controller.RTZ32.realtime.RTZ32_Realtime_Impulse_Groups; import art.library.model.devices.colors.controller.RTZ32.realtime.RTZ32_Realtime_Impulse_Phase; import art.library.model.devices.colors.controller.RTZ32.realtime.RTZ32_Realtime_Phase; import art.library.model.devices.colors.controller.RTZ32.realtime.RTZ32_Realtime_Trolley; import art.library.model.devices.colors.controller.RTZ32.status.RTZ32_Status; import art.library.model.devices.colors.controller.RTZ32.status.RTZ32_Status_Card; import art.library.model.devices.colors.controller.RTZ32.status.RTZ32_Status_General; import art.library.model.devices.colors.controller.RTZ32.status.RTZ32_Status_Group; import art.library.model.devices.colors.controller.RTZ32.status.RTZ32_Status_GroupTrolley; import art.library.model.devices.colors.controller.RTZ32.status.RTZ32_Status_Plan; import art.library.model.devices.colors.controller.RTZ32.status.RTZ32_Status_Table; import art.library.model.devices.etd.EtdStatus; import art.library.model.devices.etd.status.EtdStatusLane; import art.library.utils.synchro.Mutex; import art.servers.Shared; import art.servers.rtzserver.controller.Controller_RTZ32; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.net.Socket; import java.util.ArrayList; public class RTZ32_Talker_Reader_Data { private RTZ32_Talker talker = null; private DataInputStream disData = null; private DataOutputStream dosControl = null; private String name = null; public RTZ32_Talker_Reader_Data(RTZ32_Talker talker, Socket socketData, Socket socketControl) throws Exception { this.talker = talker; this.disData = new DataInputStream(socketData.getInputStream()); this.dosControl = new DataOutputStream(socketControl.getOutputStream()); this.name = this.talker.name + " (Reader data)"; } public void read(RTZ32_Controller rtz32, Controller_RTZ32 controllerRTZ32) throws Exception { // Read response int value = 0; Shared.println(this.name, "Waiting data STX"); if ((value = disData.read()) != RTZ32_Talker.STX) { throw new Exception("STX was expected. Received" + " " + value); } ByteArrayOutputStream bos = new ByteArrayOutputStream(8192); bos.write(RTZ32_Talker.STX); Shared.println(this.name, "Waiting data ETX"); while ((value = disData.read()) != RTZ32_Talker.ETX) bos.write(value); bos.write(RTZ32_Talker.ETX); bos.close(); byte[] response = bos.toByteArray(); // Print response { String message = "< "; for (int i=0; i private void RES_DETECTORES (RTZ32_Controller rtz32, byte[] data, Controller_RTZ32 controllerRTZ32) throws Exception { try { // TODO: // Se ha de crear el EtdStatus del periodo actual con los datos recibidos // O crearlo y marcarlo como sin datos EtdStatus etdStatus = controllerRTZ32.createEtdStatus(); RTZ32_Realtime realtime = getRealtime(rtz32); if (data.length == 0) { realtime.detectors = null; } else { realtime.detectors = new RTZ32_Realtime_Detectors(); realtime.detectors.lastTimestampUpdate = System.currentTimeMillis(); realtime.detectors.detectors = new ArrayList<>(); for (int i=0; i= detector.number) { // Exist EtdStatusLane EtdStatusLane laneStatus = etdStatus.llane.get(detector.number-1); laneStatus.number = detector.number; laneStatus.status = DeviceStatus.STATUS_ONLINE; laneStatus.correctMeasurements = 1; laneStatus.totalMeasurements = 1; laneStatus.counting = detector.intensity; laneStatus.occupancy = (float)((float)detector.occupancy / (float)etdStatus.period); laneStatus.lengths = new int[1]; laneStatus.lengths[0] = detector.intensity; laneStatus.speeds = new int[1]; laneStatus.speeds[0] = detector.intensity; } else { // Not exist EtdStatusLane EtdStatusLane laneStatus = new EtdStatusLane(); laneStatus.number = detector.number; laneStatus.status = DeviceStatus.STATUS_ONLINE; laneStatus.correctMeasurements = 1; laneStatus.totalMeasurements = 1; laneStatus.counting = detector.intensity; laneStatus.occupancy = (float)((float)detector.occupancy / (float)etdStatus.period); laneStatus.lengths = new int[1]; laneStatus.lengths[0] = detector.intensity; laneStatus.speeds = new int[1]; laneStatus.speeds[0] = detector.intensity; etdStatus.llane.add(laneStatus); } } } // TODO: // Añadir el nuevo EtdStatus al regulador controllerRTZ32.addEtdStatus(etdStatus); } finally { releaseWrite(talker.mutex_PET_DETECTORES); } } private void RES_PLAN (RTZ32_Controller rtz32, byte[] data) throws Exception { try { RTZ32_Status status = getStatus(rtz32); if (status.plan == null) { status.plan = new RTZ32_Status_Plan(); } status.plan.number = data[0]; status.plan.offset = data[1]; } finally { releaseWrite(talker.mutex_PET_PLAN_DESFASE); } } private void RES_ESTADO (RTZ32_Controller rtz32, byte[] data) throws Exception { long timestamp = System.currentTimeMillis(); try { RTZ32_Status status = getStatus(rtz32); RTZ32_Alarms alarms = getAlarms(rtz32); RTZ32_Realtime realtime = getRealtime(rtz32); if (status.general == null) status.general = new RTZ32_Status_General(); if (alarms.flashing == null) alarms.flashing = new RTZ32_Alarms_Flashing(); if (alarms.normal == null) alarms.normal = new RTZ32_Alarms_Normal(); if (realtime.trolley == null) realtime.trolley = new RTZ32_Realtime_Trolley(); if ((data[0] & 0x03) != realtime.recording) { realtime.recording = (data[0] & 0x03); } if ((data[0] & 0x04) > 0) { status.general.state = RTZ32_Status_General.STATE_STARTUP; } else if ((data[0] & 0x08) == 0) { status.general.state = RTZ32_Status_General.STATE_COLORS; } else { status.general.state = RTZ32_Status_General.STATE_FLASHING; } status.general.emergency = (data[0] & 0x10) > 0; if ((data[0] & 0x20) > 0) { status.general.control = RTZ32_Status_General.CONTROL_COMPUTER; } else { status.general.control = RTZ32_Status_General.CONTROL_LOCAL; } status.general.synchronismType = (data[1] & 0x03); status.general.semiactuated = ((data[1] & 0x04) > 0); status.general.actuated = ((data[1] & 0x08) > 0); status.general.slave = ((data[1] & 0x10) > 0); status.general.master = ((data[1] & 0x20) > 0); status.general.microregulated = ((data[1] & 0x40) > 0); status.general.tmaxfases = (data[5] & 0x01) > 0; status.general.saturation = (data[5] & 0x02) > 0; status.general.trolleyAlgorithm = (data[5] & 0x04) > 0; status.general.messageFailure = (data[5] & 0x08) > 0; status.general.trolleyDemands = (data[5] >> 2) & 0x03; // Alarms switch (data[2] & 0x03) { case 0 : alarms.flashing.alarm_inputs_key = 0; alarms.flashing.alarm_inputs_computer = 0; alarms.flashing.alarm_inputs_timetable = 0; status.general.flashing = RTZ32_Status_General.FLASHING_NONE; break; case 1 : alarms.flashing.alarm_inputs_key = getTimestamp(alarms.flashing.alarm_inputs_key, timestamp, true); alarms.flashing.alarm_inputs_computer = 0; alarms.flashing.alarm_inputs_timetable = 0; status.general.flashing = RTZ32_Status_General.FLASHING_KEYGUARD; break; case 2 : alarms.flashing.alarm_inputs_key = 0; alarms.flashing.alarm_inputs_computer = getTimestamp(alarms.flashing.alarm_inputs_computer, timestamp, true); alarms.flashing.alarm_inputs_timetable = 0; status.general.flashing = RTZ32_Status_General.FLASHING_COMPUTER; break; case 3 : alarms.flashing.alarm_inputs_key = 0; alarms.flashing.alarm_inputs_computer = 0; alarms.flashing.alarm_inputs_timetable = getTimestamp(alarms.flashing.alarm_inputs_timetable, timestamp, true); status.general.flashing = RTZ32_Status_General.FLASHING_TIMETABLE; break; } alarms.flashing.alarm_incompatibility = getTimestamp(alarms.flashing.alarm_incompatibility, timestamp, (data[2] & 0x04) > 0); alarms.flashing.alarm_outputs = getTimestamp(alarms.flashing.alarm_outputs, timestamp, (data[2] & 0x08) > 0); alarms.flashing.alarm_lamp_red = getTimestamp(alarms.flashing.alarm_lamp_red, timestamp, (data[2] & 0x10) > 0); alarms.flashing.alarm_table_checksum = getTimestamp(alarms.flashing.alarm_table_checksum, timestamp, (data[2] & 0x20) > 0); alarms.flashing.alarm_bus_I2C = getTimestamp(alarms.flashing.alarm_bus_I2C, timestamp, (data[2] & 0x40) > 0); alarms.flashing.alarm_program = getTimestamp(alarms.flashing.alarm_program, timestamp, (data[3] & 0x04) > 0); alarms.flashing.alarm_cycle_error = getTimestamp(alarms.flashing.alarm_cycle_error, timestamp, (data[3] & 0x08) > 0); alarms.flashing.alarm_incompatibilities_unprotected = getTimestamp(alarms.flashing.alarm_incompatibilities_unprotected, timestamp, (data[3] & 0x10) > 0); alarms.flashing.alarm_watchdog = getTimestamp(alarms.flashing.alarm_watchdog, timestamp, (data[3] & 0x20) > 0); alarms.normal.alarm_lamp_green = getTimestamp(alarms.normal.alarm_lamp_green, timestamp, (data[4] & 0x01) > 0); alarms.normal.alarm_lamp_yellow = getTimestamp(alarms.normal.alarm_lamp_yellow, timestamp, (data[4] & 0x02) > 0); alarms.normal.alarm_lamp_red = getTimestamp(alarms.normal.alarm_lamp_red, timestamp, (data[4] & 0x04) > 0); alarms.normal.alarm_incompatibilities_unprotected = getTimestamp(alarms.normal.alarm_incompatibilities_unprotected, timestamp, (data[4] & 0x08) > 0); alarms.normal.alarm_synchronism = getTimestamp(alarms.normal.alarm_synchronism, timestamp, (data[4] & 0x10) > 0); alarms.normal.alarm_synchronized = getTimestamp(alarms.normal.alarm_synchronized, timestamp, (data[4] & 0x20) > 0); alarms.normal.alarm_correlation = getTimestamp(alarms.normal.alarm_correlation, timestamp, (data[4] & 0x40) > 0); if (alarms.normal.alarm_synchronized > 0) { status.general.synchronismState = RTZ32_Status_General.SYNCHRONISM_STATE_SYNCHRONIZED_NO; } else { status.general.synchronismState = RTZ32_Status_General.SYNCHRONISM_STATE_SYNCHRONIZED_YES; } if ((alarms.flashing.alarm_incompatibility > 0) || (alarms.flashing.alarm_outputs > 0) || (alarms.flashing.alarm_lamp_red > 0) || (alarms.flashing.alarm_table_checksum > 0) || (alarms.flashing.alarm_bus_I2C > 0) || (alarms.flashing.alarm_program > 0) || (alarms.flashing.alarm_cycle_error > 0) || (alarms.flashing.alarm_incompatibilities_unprotected > 0) || (alarms.flashing.alarm_watchdog > 0) ) status.general.flashing = RTZ32_Status_General.FLASHING_ALARM; } finally { releaseWrite(talker.mutex_ORD_GRABACION); releaseWrite(talker.mutex_PET_ESTADO); } } private void RES_FH (RTZ32_Controller rtz32, byte[] data) throws Exception { } private void RES_VERSION (RTZ32_Controller rtz32, byte[] data) throws Exception { try { RTZ32_Configuration configuration = rtz32.getDeviceConfiguration().rtz32; if ((configuration != null) && (configuration.isValid() == true)) { configuration.firmwareVersion = data[0]; } } finally { releaseWrite(talker.mutex_PET_VERSION); } } private void RES_SEND_TABLA (RTZ32_Controller rtz32, byte[] data) throws Exception { try { if (data[0] == 0x00) { // Ok rtz32.getDeviceRealtime().rtz32.writing.tableWrittenCorrect = true; Shared.println(this.name, "< RES_SEND_TABLA " + rtz32.getDeviceRealtime().rtz32.writing.table + " Ok"); } else { // Error rtz32.getDeviceRealtime().rtz32.writing.tableWrittenCorrect = false; Shared.println(this.name, "< RES_SEND_TABLA " + rtz32.getDeviceRealtime().rtz32.writing.table + " Error"); } } finally { releaseWrite(talker.mutex_ORD_TABLA); } } private void RES_TABLA (RTZ32_Controller rtz32, byte[] data) throws Exception { try { RTZ32_Status status = getStatus(rtz32); RTZ32_Configuration configuration = getConfiguration(rtz32); RTZ32_Configuration_Table table = null; int tableNumber = data[0]; Shared.println(this.name, "< RES_TABLA " + tableNumber); if ((tableNumber >= 11) && (tableNumber) <= 28) { table = new RTZ32_Configuration_Table_11_28(tableNumber); } else if ((tableNumber >= 38) && (tableNumber) <= 40) { table = new RTZ32_Configuration_Table_38_40(tableNumber); } else if ((tableNumber >= 53) && (tableNumber) <= 60) { table = new RTZ32_Configuration_Table_53_60(tableNumber); } else if ((tableNumber >= 82) && (tableNumber) <= 85) { table = new RTZ32_Configuration_Table_82_85(tableNumber); } else { switch (tableNumber) { case 1: table = new RTZ32_Configuration_Table_1(tableNumber); break; case 2: table = new RTZ32_Configuration_Table_2(tableNumber); break; case 3: table = new RTZ32_Configuration_Table_3(tableNumber); break; case 4: table = new RTZ32_Configuration_Table_4(tableNumber); break; case 5: table = new RTZ32_Configuration_Table_5(tableNumber); break; case 6: table = new RTZ32_Configuration_Table_6(tableNumber); break; case 7: table = new RTZ32_Configuration_Table_7(tableNumber); break; case 31: table = new RTZ32_Configuration_Table_31(tableNumber); break; case 32: table = new RTZ32_Configuration_Table_32(tableNumber); break; case 33: table = new RTZ32_Configuration_Table_33(tableNumber); break; case 34: table = new RTZ32_Configuration_Table_34(tableNumber); break; case 35: table = new RTZ32_Configuration_Table_35(tableNumber); break; case 36: table = new RTZ32_Configuration_Table_36(tableNumber); break; case 37: table = new RTZ32_Configuration_Table_37(tableNumber); break; case 42: table = new RTZ32_Configuration_Table_42(tableNumber); break; case 43: table = new RTZ32_Configuration_Table_43(tableNumber); break; case 44: table = new RTZ32_Configuration_Table_44(tableNumber); break; case 45: table = new RTZ32_Configuration_Table_45(tableNumber); break; case 46: table = new RTZ32_Configuration_Table_46(tableNumber); break; case 50: table = new RTZ32_Configuration_Table_50(tableNumber); break; case 51: table = new RTZ32_Configuration_Table_51(tableNumber); break; case 52: table = new RTZ32_Configuration_Table_52(tableNumber); break; case 65: table = new RTZ32_Configuration_Table_65(tableNumber); break; case 66: table = new RTZ32_Configuration_Table_66(tableNumber); break; case 67: table = new RTZ32_Configuration_Table_67(tableNumber); break; case 68: table = new RTZ32_Configuration_Table_68(tableNumber); break; case 69: table = new RTZ32_Configuration_Table_69(tableNumber); break; case 70: table = new RTZ32_Configuration_Table_70(tableNumber); break; case 71: table = new RTZ32_Configuration_Table_71(tableNumber); break; case 72: table = new RTZ32_Configuration_Table_72(tableNumber); break; case 73: table = new RTZ32_Configuration_Table_73(tableNumber); break; case 74: table = new RTZ32_Configuration_Table_74(tableNumber); break; case 75: table = new RTZ32_Configuration_Table_75(tableNumber); break; case 78: table = new RTZ32_Configuration_Table_78(tableNumber); break; case 79: table = new RTZ32_Configuration_Table_79(tableNumber); break; case 80: table = new RTZ32_Configuration_Table_80(tableNumber); break; case 81: table = new RTZ32_Configuration_Table_81(tableNumber); break; case 91: table = new RTZ32_Configuration_Table_91(tableNumber); break; case 92: table = new RTZ32_Configuration_Table_92(tableNumber); break; case 93: table = new RTZ32_Configuration_Table_93(tableNumber); break; case 94: table = new RTZ32_Configuration_Table_94(tableNumber); break; case 95: table = new RTZ32_Configuration_Table_95(tableNumber); break; default: table = new RTZ32_Configuration_Table(tableNumber); break; } } table.number = tableNumber; byte[] tabledata = new byte[data.length-1]; System.arraycopy(data, 1, tabledata, 0, data.length-1); table.deserialize(configuration, tabledata); status.tables.put(tableNumber, new RTZ32_Status_Table(tableNumber, System.currentTimeMillis())); } finally { releaseWrite(talker.mutex_PET_TABLA); } } private void RES_CONTADORES (RTZ32_Controller rtz32, byte[] data) throws Exception { long timestamp = System.currentTimeMillis(); try { RTZ32_Realtime realtime = getRealtime(rtz32); if (realtime.counters == null) realtime.counters = new RTZ32_Realtime_Counters(); realtime.counters.lastTimestampUpdate = timestamp; realtime.counters.cycle = ((data[0] & 0xFF) << 8) + data[1]; realtime.counters.cycleReal = ((data[2] & 0xFF) << 8) + data[3]; } finally { releaseWrite(talker.mutex_PET_CONTADORES); } } public void RES_GRUPOS (RTZ32_Controller rtz32, byte[] data) { // Initialise realtime long timestamp = System.currentTimeMillis(); try { RTZ32_Realtime realtime = getRealtime(rtz32); if (realtime.counters == null) realtime.counters = new RTZ32_Realtime_Counters(); if (realtime.groups == null) realtime.groups = new RTZ32_Realtime_Groups(); RTZ32_Realtime_Impulse_Groups impulse = new RTZ32_Realtime_Impulse_Groups(); impulse.timestamp = Math.floorDiv(timestamp, 1000) * 1000; // Update colors if (data.length == 1) { // Secuencia de entrada solo 1 byte int color = RTZ32_Constants_Colors.COLOR_UNKNOWN; switch (data[0]) { case 0x1F: color = RTZ32_Constants_Colors.COLOR_AIe; break; case 0x2F: color = RTZ32_Constants_Colors.COLOR_Ae; break; case 0x3F: color = RTZ32_Constants_Colors.COLOR_Re; break; case 0x4F: color = RTZ32_Constants_Colors.COLOR_OFFe; break; } for (int i=0; i> 6) & 0x01) << 7) + (data[32] & 0x7F); realtime.counters.cycleReal = (((data[34] >> 5) & 0x01) << 7) + (data[33] & 0x7F); impulse.cycle = realtime.counters.cycle; impulse.cycleReal = realtime.counters.cycleReal; } } realtime.addImpulse(impulse); realtime.groups.lastTimestampUpdate = timestamp; } catch (Exception exception) { } finally { releaseWrite(talker.mutex_PET_GRUPO); } } private void RES_CAMBIO_FASE (RTZ32_Controller rtz32, byte[] data) throws Exception { long timestamp = System.currentTimeMillis(); try { RTZ32_Realtime realtime = getRealtime(rtz32); if (realtime.phase == null) realtime.phase = new RTZ32_Realtime_Phase(); if (realtime.counters == null) realtime.counters = new RTZ32_Realtime_Counters(); realtime.phase.phaseNumber = (data[0] & 0x07) + 1; realtime.phase.variable = ((data[0] >> 3) & 0x01) > 0; realtime.phase.waitAlgorithm = ((data[0] >> 4) & 0x01) > 0; realtime.phase.cancellation = ((data[0] >> 5) & 0x01) > 0; realtime.phase.correlation = ((data[0] >> 6) & 0x01) > 0; realtime.phase.phaseType = data[1] & 0x03; realtime.phase.retractable = ((data[1] >> 2) & 0x01) > 0; realtime.phase.lastTimestampUpdate = timestamp; realtime.counters.lastTimestampUpdate = timestamp; realtime.counters.cycleReal = (((data[1] >> 5) & 0x01) << 7) + (data[3] & 0x7F); realtime.counters.cycle = (((data[1] >> 6) & 0x01) << 7) + (data[2] & 0x7F); RTZ32_Realtime_Impulse_Phase impulse = new RTZ32_Realtime_Impulse_Phase(); impulse.timestamp = Math.floorDiv(timestamp, 1000) * 1000; impulse.cycle = realtime.counters.cycle; impulse.cycleReal = realtime.counters.cycleReal; impulse.phaseNumber = realtime.phase.phaseNumber; impulse.variable = realtime.phase.variable; impulse.waitAlgorithm = realtime.phase.waitAlgorithm; impulse.cancellation = realtime.phase.cancellation; impulse.correlation = realtime.phase.correlation; impulse.phaseType = realtime.phase.phaseType; impulse.retractable = realtime.phase.retractable; realtime.addImpulse(impulse); } finally { releaseWrite(talker.mutex_PET_CAMBIO_FASE); } } private void RES_ALARMAS (RTZ32_Controller rtz32, byte[] data) throws Exception { try { long timestamp = System.currentTimeMillis(); // Initialise RTZ32_Status status = getStatus(rtz32); RTZ32_Alarms alarms = getAlarms(rtz32); RTZ32_Configuration configuration = getConfiguration(rtz32); if ((configuration == null) || (configuration.isValid() == false)) { // if ((rtz32.getDeviceRealtime().rtz32 == null) || (rtz32.getDeviceRealtime().rtz32.reading == null)) // { // talker.rtz32.getDeviceConfiguration().rtz32 = null; // } } else { if ((configuration.groups != null) && (status.groups.size() != configuration.groups.length)) { for (RTZ32_Configuration_Group configurationGroup : configuration.groups) { status.groups.add(new RTZ32_Status_Group(configurationGroup.number)); } } } if (status.trolleys.size() != 4) { for (int number=1; number<=4; number++) { status.trolleys.add(new RTZ32_Status_GroupTrolley(number)); } } if (status.cards.size() != 16) { for (int number=1; number<=16; number++) { status.cards.add(new RTZ32_Status_Card(number)); } } // Fill information Shared.println(this.name, "< RES_ALARMAS " + data[0]); switch (data[0]) { case 0x01 : // Error checksum tablas { long alarm_checksum_table = 0; for (int i=1; i<15; i++) { if ((data[i] & 0x7F) > 0) { alarm_checksum_table = timestamp; } status.setInout(1 + (7 * (i-1)), (data[i] & 0x01) > 0, timestamp); status.setInout(2 + (7 * (i-1)), (data[i] & 0x02) > 0, timestamp); status.setInout(3 + (7 * (i-1)), (data[i] & 0x04) > 0, timestamp); status.setInout(4 + (7 * (i-1)), (data[i] & 0x08) > 0, timestamp); status.setInout(5 + (7 * (i-1)), (data[i] & 0x10) > 0, timestamp); status.setInout(6 + (7 * (i-1)), (data[i] & 0x20) > 0, timestamp); status.setInout(7 + (7 * (i-1)), (data[i] & 0x40) > 0, timestamp); } alarms.alarm_checksum_table = alarm_checksum_table; break; } case 0x02 : // Incompatibilidades verde { long alarm_icompatibility_green = 0; for (int i=1; i<9; i++) { if ((data[i] & 0x7F) > 0) { alarm_icompatibility_green = timestamp; } status.setIncompatibilityGreen(1 + (4 * (i-1)), (data[i] & 0x01) > 0, timestamp); status.setIncompatibilityGreen(2 + (4 * (i-1)), (data[i] & 0x02) > 0, timestamp); status.setIncompatibilityGreen(3 + (4 * (i-1)), (data[i] & 0x04) > 0, timestamp); status.setIncompatibilityGreen(4 + (4 * (i-1)), (data[i] & 0x08) > 0, timestamp); } alarms.alarm_icompatibility_green = alarm_icompatibility_green; break; } case 0x03 : // Incompatibilidades no rojo { long alarm_icompatibility_not_red = 0; for (int i=1; i<9; i++) { if ((data[i] & 0x7F) > 0) { alarm_icompatibility_not_red = timestamp; } status.setIncompatibilityNoRed(1 + (4 * (i-1)), (data[i] & 0x01) > 0, timestamp); status.setIncompatibilityNoRed(2 + (4 * (i-1)), (data[i] & 0x02) > 0, timestamp); status.setIncompatibilityNoRed(3 + (4 * (i-1)), (data[i] & 0x04) > 0, timestamp); status.setIncompatibilityNoRed(4 + (4 * (i-1)), (data[i] & 0x08) > 0, timestamp); } alarms.alarm_icompatibility_not_red = alarm_icompatibility_not_red; break; } case 0x04 : // Salidas grupo { long alarm_damage_group = 0; for (int i=1; i<33; i++) { if ((data[i] & 0x7F) > 0) { alarm_damage_group = timestamp; } status.setInout(1 + (7 * (i-1)), (data[i] & 0x01) > 0, timestamp); status.setInout(2 + (7 * (i-1)), (data[i] & 0x02) > 0, timestamp); status.setInout(3 + (7 * (i-1)), (data[i] & 0x04) > 0, timestamp); status.setInout(4 + (7 * (i-1)), (data[i] & 0x08) > 0, timestamp); status.setInout(5 + (7 * (i-1)), (data[i] & 0x10) > 0, timestamp); status.setInout(6 + (7 * (i-1)), (data[i] & 0x20) > 0, timestamp); status.setInout(7 + (7 * (i-1)), (data[i] & 0x40) > 0, timestamp); } alarms.alarm_damage_group = alarm_damage_group; break; } case 0x05 : // Placas salidas, entradas { long alarm_inout_card = 0; for (int i=1; i<3; i++) { if ((data[i] & 0x7F) > 0) { alarm_inout_card = timestamp; } boolean green = (data[i] & 0x02) > 0; boolean yellow = ((data[i] >> 2) & 0x02) > 0; boolean red = ((data[i] >> 4) & 0x02) > 0; status.setDamageGroup(i, green, yellow, red, timestamp); } alarms.alarm_inout_card = alarm_inout_card; break; } case 0x06 : // Destellos por lámpara roja { long alarm_flashing_red_lamp = 0; for (int i=1; i<5; i++) { if ((data[i] & 0x7F) > 0) { alarm_flashing_red_lamp = timestamp; } status.setFlashingRedLamp(1 + (7 * (i-1)), (data[i] & 0x01) > 0, timestamp); status.setFlashingRedLamp(2 + (7 * (i-1)), (data[i] & 0x02) > 0, timestamp); status.setFlashingRedLamp(3 + (7 * (i-1)), (data[i] & 0x04) > 0, timestamp); status.setFlashingRedLamp(4 + (7 * (i-1)), (data[i] & 0x08) > 0, timestamp); status.setFlashingRedLamp(5 + (7 * (i-1)), (data[i] & 0x10) > 0, timestamp); status.setFlashingRedLamp(6 + (7 * (i-1)), (data[i] & 0x20) > 0, timestamp); status.setFlashingRedLamp(7 + (7 * (i-1)), (data[i] & 0x40) > 0, timestamp); } alarms.alarm_flashing_red_lamp = alarm_flashing_red_lamp; break; } case 0x07 : // Lámpara verde fundida { long alarm_blown_green_lamp = 0; for (int i=1; i<5; i++) { if ((data[i] & 0x7F) > 0) { alarm_blown_green_lamp = timestamp; } status.setBlownGreen(1 + (7 * (i-1)), (data[i] & 0x01) > 0, timestamp); status.setBlownGreen(2 + (7 * (i-1)), (data[i] & 0x02) > 0, timestamp); status.setBlownGreen(3 + (7 * (i-1)), (data[i] & 0x04) > 0, timestamp); status.setBlownGreen(4 + (7 * (i-1)), (data[i] & 0x08) > 0, timestamp); status.setBlownGreen(5 + (7 * (i-1)), (data[i] & 0x10) > 0, timestamp); status.setBlownGreen(6 + (7 * (i-1)), (data[i] & 0x20) > 0, timestamp); status.setBlownGreen(7 + (7 * (i-1)), (data[i] & 0x40) > 0, timestamp); } alarms.alarm_blown_green_lamp = alarm_blown_green_lamp; break; } case 0x08 : // Lámpara ámbar fundida { long alarm_blown_yellow_lamp = 0; for (int i=1; i<5; i++) { if ((data[i] & 0x7F) > 0) { alarm_blown_yellow_lamp = timestamp; } status.setBlownYellow(1 + (7 * (i-1)), (data[i] & 0x01) > 0, timestamp); status.setBlownYellow(2 + (7 * (i-1)), (data[i] & 0x02) > 0, timestamp); status.setBlownYellow(3 + (7 * (i-1)), (data[i] & 0x04) > 0, timestamp); status.setBlownYellow(4 + (7 * (i-1)), (data[i] & 0x08) > 0, timestamp); status.setBlownYellow(5 + (7 * (i-1)), (data[i] & 0x10) > 0, timestamp); status.setBlownYellow(6 + (7 * (i-1)), (data[i] & 0x20) > 0, timestamp); status.setBlownYellow(7 + (7 * (i-1)), (data[i] & 0x40) > 0, timestamp); } alarms.alarm_blown_yellow_lamp = alarm_blown_yellow_lamp; break; } case 0x09 : // Lámpara roja fundida { long alarm_blown_red_lamp = 0; for (int i=1; i<5; i++) { if ((data[i] & 0x7F) > 0) { alarm_blown_red_lamp = timestamp; } status.setBlownRed(1 + (7 * (i-1)), (data[i] & 0x01) > 0, timestamp); status.setBlownRed(2 + (7 * (i-1)), (data[i] & 0x02) > 0, timestamp); status.setBlownRed(3 + (7 * (i-1)), (data[i] & 0x04) > 0, timestamp); status.setBlownRed(4 + (7 * (i-1)), (data[i] & 0x08) > 0, timestamp); status.setBlownRed(5 + (7 * (i-1)), (data[i] & 0x10) > 0, timestamp); status.setBlownRed(6 + (7 * (i-1)), (data[i] & 0x20) > 0, timestamp); status.setBlownRed(7 + (7 * (i-1)), (data[i] & 0x40) > 0, timestamp); } alarms.alarm_blown_red_lamp = alarm_blown_red_lamp; break; } case 0x0A : // Lámpara fundida grupo TW { long alarm_blown_TW_lamp = 0; for (int i=1; i<5; i++) { if ((data[i] & 0x7F) > 0) { alarm_blown_TW_lamp = timestamp; } status.setBlownTrolley(i, (data[i] & 0x01) > 0, (data[i] & 0x02) > 0, (data[i] & 0x04) > 0, timestamp); status.setBlownTrolleyOpposite(i, (data[i] & 0x00) > 0, (data[i] & 0x10) > 0, (data[i] & 0x20) > 0, timestamp); } alarms.alarm_blown_TW_lamp = alarm_blown_TW_lamp; break; } case 0x0F : { long alarm_automatic_resend = 0; break; } } } finally { releaseWrite(talker.mutex_PET_ALARMAS); } } private long getTimestamp(long timestamp1, long timestamp2, boolean value) { if (value == false) return 0; if (timestamp1 == 0) return timestamp2; return Math.min(timestamp1, timestamp2); } private void releaseWrite(Mutex mutex) { if ((mutex != null) && (mutex.isWriteLocked() == true)) { mutex.releaseWrite(); } } private RTZ32_Status getStatus(RTZ32_Controller rtz32) { return rtz32.getDeviceStatus().rtz32; } private RTZ32_Alarms getAlarms(RTZ32_Controller rtz32) { return rtz32.getDeviceAlarms().rtz32; } private RTZ32_Configuration getConfiguration(RTZ32_Controller rtz32) { if (rtz32.getDeviceConfiguration() == null) { rtz32.configuration = new RTZ32_ControllerConfiguration(); } if (rtz32.getDeviceConfiguration().rtz32 == null) { rtz32.getDeviceConfiguration().rtz32 = new RTZ32_Configuration(); } return rtz32.getDeviceConfiguration().rtz32; } private RTZ32_Realtime getRealtime(RTZ32_Controller rtz32) { return rtz32.getDeviceRealtime().rtz32; } // }