package art.servers.colorsserver.M.protocol; import art.library.interop.serialization.Serialization; import art.library.model.devices.colors.controller.M.M_Controller; import art.library.model.devices.colors.controller.M.M_ControllerInformation; import art.library.model.devices.colors.controller.M.configuration.SPTP.M_SPTP_Configuration; import art.library.model.devices.colors.controller.M.configuration.SPTP.M_SPTP_ConfigurationBusLocalPreferenceOperation; import art.library.model.devices.colors.controller.M.configuration.SPTP.M_SPTP_ConfigurationTimetableLocalPreferenceOperation; import art.library.model.devices.colors.controller.M.configuration.SPTP.M_SPTP_Configuration_BusLineAreaConfiguration; import art.library.model.devices.colors.controller.M.tables.M_Table; import art.library.model.devices.colors.controller.M.tables.M_TableWriter; import art.library.model.devices.colors.controller.M.tables.subcontroller.SPTP.M_Table_SPTP_BusLineAreaConfiguration; import art.library.model.devices.colors.controller.M.tables.subcontroller.SPTP.M_Table_SPTP_BusLocalPreferenceOperation; import art.library.model.devices.colors.controller.M.tables.subcontroller.SPTP.M_Table_SPTP_GeneralParameters; import art.library.model.devices.colors.controller.M.tables.subcontroller.SPTP.M_Table_SPTP_TimetableLocalPreferenceOperation; import art.servers.ColorsServer; import art.servers.colorsserver.Shared; import art.servers.colorsserver.controller.ControllerController; import java.io.InputStream; import java.io.OutputStream; import java.net.Socket; import java.util.ArrayList; import java.util.List; public class M_ControllerComunicator extends Thread { // private Socket socket = null; // private InputStream is = null; // private OutputStream os = null; private boolean hasCRC = false; private M_Controller m_controller = null; private ControllerController controllerController = null; public M_ControllerComunicator(M_Controller m_controller, ControllerController controllerController) { this.m_controller = m_controller; this.controllerController = controllerController; // this.socket = socket; // try{this.socket.setSoTimeout(15000);} catch (Exception e){}; // try{this.is = socket.getInputStream();} catch (Exception e){}; // try{this.os = socket.getOutputStream();} catch (Exception e){}; this.hasCRC = controllerController.hasCRC; } public void run() { } public void writeSPTPTables(int subcontroller, String configurationCode, String controllerNumber, M_SPTP_Configuration configuration) throws Exception { try { startRecordingTables(configurationCode, controllerNumber); if (this.m_controller.getDeviceInformation().type == M_ControllerInformation.TYPE_DYNAMIC) { writeTable(subcontroller, configuration, 0x4A); writeTable(subcontroller, configuration, 0x4B); writeTable(subcontroller, configuration, 0x4C); writeTable(subcontroller, configuration, 0x4D); } else { writeTable(subcontroller, configuration, M_Table.M_TABLE_SPTP_GENERAL_PARAMETERS); writeTable(subcontroller, configuration, M_Table.M_TABLE_SPTP_BUS_LINE_AREA_CONFIGURATION); writeTable(subcontroller, configuration, M_Table.M_TABLE_SPTP_BUS_LOCAL_PREFERENCE_OPERATION); writeTable(subcontroller, configuration, M_Table.M_TABLE_SPTP_TIMETABLE_LOCAL_PREFERENCE_OPERATION); } } catch (Exception e) { Shared.printstack("Comunicator", e); throw e; } finally { endRecordingTables(); } } public void writeTable(int subcontroller, M_SPTP_Configuration configuration, int tableCode) throws Exception { List lTableContent = new ArrayList(); switch (tableCode) { case M_Table.M_TABLE_SPTP_GENERAL_PARAMETERS: { M_Table_SPTP_GeneralParameters m_table = new M_Table_SPTP_GeneralParameters(); byte[] data = m_table.serialize(subcontroller, configuration); for (int i=0; i l = new M_Table_SPTP_BusLineAreaConfiguration().deserialize(res); Shared.println("Comunicator", ">>>>>>>>>>>>>>>>>>>>>>>> " + Serialization.toPrettyString(l)); } } break; case M_Table.M_TABLE_SPTP_BUS_LOCAL_PREFERENCE_OPERATION: { M_Table_SPTP_BusLocalPreferenceOperation m_table = new M_Table_SPTP_BusLocalPreferenceOperation(); byte[] data = m_table.serialize(subcontroller, configuration); for (int i=0; i l = new M_Table_SPTP_BusLocalPreferenceOperation().deserialize(res); Shared.println("Comunicator", ">>>>>>>>>>>>>>>>>>>>>>>> " + Serialization.toPrettyString(l)); } } break; case M_Table.M_TABLE_SPTP_TIMETABLE_LOCAL_PREFERENCE_OPERATION: { M_Table_SPTP_TimetableLocalPreferenceOperation m_table = new M_Table_SPTP_TimetableLocalPreferenceOperation(); byte[] data = m_table.serialize(subcontroller, configuration); for (int i=0; i l = new M_Table_SPTP_TimetableLocalPreferenceOperation().deserialize(res); Shared.println("Comunicator", ">>>>>>>>>>>>>>>>>>>>>>>> " + Serialization.toPrettyString(l)); } } break; case 0x4A: { M_Table_SPTP_GeneralParameters m_table = new M_Table_SPTP_GeneralParameters(); byte[] data = m_table.serialize(subcontroller, configuration); data[2] = (byte)(0xCA); for (int i=0; i> "; for (int i=0; i lTableContent = new ArrayList(); M_TableWriter writer = new M_TableWriter(); writer.STX(); writer.write(controller); writer.write(tableCode); writer.EOB12(); writer.ETX(); byte[] content = writer.toByteArray(); for (int i=0; i 0) // send(command); // return receive(); // } // catch (Exception e) // { // throw e; // } // } // // // // private void send(byte[] command) throws Exception // { // socket.getOutputStream().write(command); // socket.getOutputStream().flush(); // } // // // // private M_Message receive() throws Exception // { // boolean salir = false; // int res = 0; // byte[] trama = null; // // int longitud = 0; // // try // { // while ((res = is.read()) == 0){sleep(10);}; // // if (res != -1) // { // if ((res == 0x06) || (res == 0x15) || ((res >= 0x30) && (res <= 0x3F))) // { // M_Message message = new M_Message(); // int[] result = new int[1]; // result[0] = res; // message.setData(result); // return(message); // } // // int apuntador = 0; // trama = new byte[4096]; // trama[apuntador] = (byte)res; // apuntador++; // // // Obtenemos todos los datos disponibles // while (res != 0x03) // { // res = is.read(); // trama[apuntador] = (byte)res; // apuntador++; // } // // longitud = apuntador; // } // } // catch (Exception e) // { // throw e; // } // // if (res == -1) // throw new Exception(Shared.getMessage("Timeout Error")); // // // Enviamos el resultado // byte[] resultado = new byte[longitud]; // System.arraycopy(trama, 0, resultado, 0, longitud); // M_Message message = new M_Message(); // message.setData(resultado); // return(message); // } }