Device_Simulator_DTS_Tester/bin/com/dev/bts/data/FBS9100_ComBase.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/modbus/MyModBusRtu.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/SPCommPower.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/dev/Power_ACData.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/dev/Power_AlmParam.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/dev/Power_AlmState.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/dev/Power_ComBase.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/dev/Power_LIBMSData.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/dev/Power_ModelData.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/dev/Power_Param.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/dev/Power_RoadState.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/dev/Power_TimeControl$TimeControl.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/dev/Power_TimeControl.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$1$1.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$1.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$10.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$11.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$12.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$13.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$14.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$15.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$16.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$17.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$18.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$19.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$2.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$20.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$21.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$22.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$23.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$24.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$25.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$26.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$27.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$28.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$29.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$3.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$30.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$31.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$32.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$33.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$34.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$35.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$36.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$37.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$38.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$39.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$4.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$40.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$41.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$42.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$43.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$44.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$45.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$46.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$47.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$48.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$49.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$5.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$50.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$51.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$52.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$53.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$54.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$55.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$56.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$57.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$58.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$59.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$6.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$60.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$61.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$62.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$63.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$64.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$65$1.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$65.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$66.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$67.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$68.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$69.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$7.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$8.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base$9.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_page_base.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/dev/simpower/power_util.classBinary files differ
Device_Simulator_DTS_Tester/bin/com/ueky/ukeycfg_page_base.classBinary files differ
Device_Simulator_DTS_Tester/bin/icon/61850_ide.png
Device_Simulator_DTS_Tester/bin/icon/dis_bts.png
Device_Simulator_DTS_Tester/bin/icon/group_model.png
Device_Simulator_DTS_Tester/bin/icon/mon_ied.png
Device_Simulator_DTS_Tester/bin/icon/ukey_ide.png
Device_Simulator_DTS_Tester/bin/main/main_window_computer$1.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$10.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$11.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$12.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$13.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$14.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$15.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$16.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$17.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$18.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$19.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$2.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$20.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$21.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$22.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$23.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$24.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$25.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$3.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$4.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$5.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$6.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$7.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$8.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer$9.classBinary files differ
Device_Simulator_DTS_Tester/bin/main/main_window_computer.classBinary files differ
Device_Simulator_DTS_Tester/bin/user_app_form/MySch_Util$1.classBinary files differ
Device_Simulator_DTS_Tester/bin/user_app_form/MySch_Util.classBinary files differ
Device_Simulator_DTS_Tester/bin/user_app_form/pscp_util.classBinary files differ
Device_Simulator_DTS_Tester/src/com/dev/bts/data/FBS9100_ComBase.java
@@ -245,6 +245,11 @@ int tmp = data & 0xFFFF; return (float)(tmp); } public static float changeSigleShortToFloat(short data) { int tmp = data; return (float)(tmp); } //------------------------------------------------------------------------------ public static short changeFloatToShort(float data) { Device_Simulator_DTS_Tester/src/com/dev/modbus/MyModBusRtu.java
New file @@ -0,0 +1,86 @@ package com.dev.modbus; import java.nio.ByteBuffer; import com.ComBase; import com.Crc16; public class MyModBusRtu { public static final int BYTE_LEN = 5; public static final short CMD_TYPE_READ = 0x03; //读 public static final short CMD_TYPE_WRITE_YC = 0x05; public static final short CMD_TYPE_WRITE_STD = 0x06; //单点写入 public static final short CMD_TYPE_WRITE_MULTY = 0x10; //多点写入 public static final short CMD_TYPE_Read_UpdateFile = 0x23; //读取升级文件 public static final short CMD_TYPE_WRITE_SysUpdate = 0x26; //系统升级相关控制 public int addr; //设备地址 public int Cmd; //功能码 public int reg_addr; //寄存器地址 public int reg_count; //寄存器数量 public int data_count; //数据区字节数量 public int result; //返回操作结果 public int crc; //crc校验 public MyModBusRtu() { } public MyModBusRtu(int Cmd,int reg_addr) { this.Cmd = Cmd; this.reg_addr = reg_addr; } public void clear() { this.addr = 0; //设备地址 this.Cmd = 0; //功能码 this.reg_addr = 0; //寄存器地址 this.reg_count = 0; //寄存器数量 this.data_count = 0; //数据区字节数量 this.result = 0; //返回操作结果 } public boolean putByteBuffer(final ByteBuffer bf) { if(bf.limit() < BYTE_LEN) return false; ByteBuffer tmpbuf = bf; int crc0 = tmpbuf.getShort(bf.limit()-2) & 0xFFFF; int crc1 = Crc16.CalCRC16(tmpbuf, bf.limit()-2) & 0xFFFF; if(crc0 != crc1) { System.err.println("CRC error "+crc0+"==="+crc1); return false; } tmpbuf.position(0); this.addr = tmpbuf.get()&0xFF; //设备地址 this.Cmd = tmpbuf.get()&0xFF; //功能码 if(CMD_TYPE_READ == this.Cmd) { this.data_count = tmpbuf.get()&0xFF; }else if(CMD_TYPE_WRITE_STD == this.Cmd || CMD_TYPE_WRITE_MULTY == this.Cmd || CMD_TYPE_WRITE_SysUpdate == this.Cmd){ this.reg_addr = tmpbuf.getShort()&0xFFFF; //寄存器地址 this.result = tmpbuf.getShort()&0xFFFF; }else if(CMD_TYPE_Read_UpdateFile == this.Cmd) { //后面即升级包 this.result = tmpbuf.getShort()&0xFFFF; //数据包索引 } tmpbuf.compact(); tmpbuf.flip(); return true; } } Device_Simulator_DTS_Tester/src/com/dev/simpower/SPCommPower.java
New file @@ -0,0 +1,851 @@ package com.dev.simpower; import gnu.io.SerialPort; import gnu.io.UnsupportedCommOperationException; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.Date; import javax.swing.JOptionPane; import javax.swing.JTextArea; import org.apache.logging.log4j.Logger; import sp_comm.CommSerialPort; import sp_comm.Comm_Socket; import main.page_debug_inf; import com.Com; import com.ComFn; import com.Crc16; import com.PlaySound; import com.dev.bts.data.FBS9100_ComBase; import com.dev.bts.data.FBS9100_DFU; import com.dev.fbs9600_mon.SPCommMon; import com.dev.modbus.MyModBusRtu; import com.dev.simpower.dev.Power_ACData; import com.dev.simpower.dev.Power_AlmParam; import com.dev.simpower.dev.Power_AlmState; import com.dev.simpower.dev.Power_ComBase; import com.dev.simpower.dev.Power_LIBMSData; import com.dev.simpower.dev.Power_ModelData; import com.dev.simpower.dev.Power_Param; import com.dev.simpower.dev.Power_RoadState; import com.dev.simpower.dev.Power_TimeControl; public class SPCommPower implements Runnable/*, SerialPortEventListener*/ { public static final byte MODBUS_TYPE_YC = 0x01; public static final byte MODBUS_TYPE_STD = 0x02; public static final short CMD_TYPE_READ = 0x03; public static final short CMD_TYPE_WRITE_YC = 0x05; public static final short CMD_TYPE_WRITE_STD = 0x06; public static final short CMD_TYPE_WRITE_MULTY = 0x10; public static final int DEV_PARAM_DATA_STATE_NULL = 0; public static final int DEV_PARAM_DATA_STATE_QUERY = 1; public static final int DEV_PARAM_DATA_STATE_UPDATE = 2; private ByteBuffer dt_databuffer = ByteBuffer.allocate(0); //遥控遥调数据 private short dt_user_cmd = Power_ComBase.CMD_NULL; private int dt_user_cmd_regaddr = 0; //用户控制时的寄存器地址 /*********************************************************************/ public short m_CMD_TYPE_WRITE = CMD_TYPE_WRITE_YC; private byte m_MODBUS_TYPE = MODBUS_TYPE_YC; private boolean CommThreadRunning = false; public boolean AutoStartResTestEn = false; public Date AutoStartResTestTime = new Date(); public Date AutoSaveResDataTime = new Date(); public boolean AutoSaveResDataEn = false; public int AutoSaveResDataCount = 0; public String AutoSaveDataFileName = ""; private ByteBuffer CommRxBuffer = ByteBuffer.allocate(1500); private ByteBuffer CommTxBuffer = ByteBuffer.allocate(1048); public int comm_tx_cnt = 0; public int comm_rx_cnt = 0; private int comm_bautrate = 9600; public int dt_target_addr = 0; public int m_ZDHJ_REG_CNT = 1; public int ZDHJ_BattCount = -1; //--------------------------------------------------------// public int dev_param_data_state = 0; public int dev_param_addr = 0; public int dev_param_curr_range = 0; public double dev_param_FloatCurrLev = 0; public double dev_param_float_curr_lev = 0; public double dev_param_wenbo_curr_lev = 0; public int dev_param_auto_restest_interval = 0; public int dev_param_res_test_type = 0; public int dev_param_ResDisTestMethod = 0; public int dev_param_Batt_StdCap = 0; public double dev_param_res_dis_slope = 0; public double dev_param_res_wenbo_slope = 0; public int dev_param_monnum_setmode = 0; public int dev_param_devid = 0; public double[] dev_param_resparam_d = new double[4]; public double[] dev_param_resparam_s = new double[4]; //--------------------------------------------------------// public int dev_stat_version = 0; public int dev_stat_state = 0; public double GroupVol = 0; public double BattCurr = 0; public int BattState = 0; public int BattCurrDir = 0; public double AvgWenBoCurr = 0; public double PeakWenBoCurr = 0; public int SpiCommErrCount = 0; //SPI通信错误计数 public int ResTestCount = 0; //内阻测试次数 public int CurentResTestMode = 0; //当前内阻测试方法 public int BianhaoErrNum = 0; //编号错误单体号 public double ExTemp = 0; //外部温度 //--------------------------------------------------------// public short mAddrSettedNow = 0; private short dt_cmd = CMD_TYPE_READ; public int dt_cmd_ack = Power_ComBase.CMD_NULL; public MyModBusRtu rtu_rt; public MyModBusRtu rtu_rx; public Date dt_cmd_ack_time = new Date(); private short dt_cmd_regaddr = 0; private short dt_cmd_regcnt = 0; private short[] dt_cmd_regdata = null; private int dt_cmd_cnt = 0; private page_debug_inf dt_debug_inf; private int m_COMM_PORT_TYPE = 0; private CommSerialPort m_SP_Comm = null; private Comm_Socket m_SocketComm = null; private Logger m_Log = null; private int read_libms_index = 0; //读取锂电池包索引 private int read_model_index = 0; //读取电源模块索引 public Power_ACData m_AcData; public Power_LIBMSData[] m_LibmsDatas; public Power_ModelData[] m_ModelDatas; public Power_AlmState m_AlmState; public Power_Param m_ParamFromDev; //设备读取的参数 public Power_TimeControl m_TimeControlFromDev; //设备读取的参数 public Power_RoadState m_RoadStateFromDev; //设备读取的参数 public Power_AlmParam m_AlmParamFromDev; //设备读取的告警参数 public String op_result_sysparam = ""; //系统参数结果字符串 public String op_result_powerparam = ""; //电源结果字符串 public String op_result_almaram = ""; //电源告警结果字符串 public String op_result_jiaozhun = ""; //电源校准结果字符串 public short dt_user_cmd_ack = Power_ComBase.CMD_NULL; //操作返回结果,用于界面判断geng'xin private boolean dt_dfu_en = false; //远程升级标识 private JTextArea dt_show_msg; //升级文本信息域 private String dt_dfuFileName; //升级文件名称 public SPCommPower(int addr_t, int bitrate, page_debug_inf debug, Logger log) { dt_target_addr = addr_t & 0x00FF; comm_bautrate = bitrate; dt_debug_inf = debug; m_Log = log; rtu_rx = new MyModBusRtu(); m_RoadStateFromDev = new Power_RoadState(); m_TimeControlFromDev = new Power_TimeControl(); m_ParamFromDev = new Power_Param(); m_AcData = new Power_ACData(); m_AlmState = new Power_AlmState(); m_LibmsDatas = new Power_LIBMSData[Power_ComBase.LIBMSDATA_MAX_COUNT]; for(int i =0;i<m_LibmsDatas.length;i++) { m_LibmsDatas[i] = new Power_LIBMSData(); } m_ModelDatas = new Power_ModelData[Power_ComBase.LIMODEL_MAX_COUNT]; for(int i =0;i<m_LibmsDatas.length;i++) { m_ModelDatas[i] = new Power_ModelData(); } } public void setCommBautrate(int bt_rate) { if(SPCommMon.COMM_PORT_TYPE_Serial != m_COMM_PORT_TYPE) { return; } try { comm_bautrate = bt_rate; m_SP_Comm.serialPort.setSerialPortParams(comm_bautrate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1,SerialPort.PARITY_NONE); } catch (UnsupportedCommOperationException e) { // TODO Auto-generated catch block e.printStackTrace(); } } //初始化串口 public boolean OpenCommPort(int comm_port_type, String comm_name_or_ip, int bitrate_or_comm_port) { boolean res = false; m_COMM_PORT_TYPE = comm_port_type; if(SPCommMon.COMM_PORT_TYPE_Serial == m_COMM_PORT_TYPE) { m_SP_Comm = new CommSerialPort(bitrate_or_comm_port, m_Log); res = m_SP_Comm.OpenCommPort(comm_name_or_ip); } else { m_SocketComm = new Comm_Socket(comm_name_or_ip, bitrate_or_comm_port); res = true; } if(true == res) { CommTxBuffer.order(ByteOrder.BIG_ENDIAN); CommRxBuffer.order(ByteOrder.BIG_ENDIAN); comm_tx_cnt = 0; comm_rx_cnt = 0; CommThreadRunning = true; } return res; } private void makeCommTxData() { CommTxBuffer.clear(); rtu_rt = new MyModBusRtu(); ByteBuffer dt_data = ByteBuffer.allocate(0); rtu_rt.addr = dt_target_addr; if(dt_user_cmd == Power_ComBase.CMD_NULL) { //随机读取实时数据 if(++dt_cmd_cnt > 1000) { dt_cmd_cnt = 0; } rtu_rt.Cmd = MyModBusRtu.CMD_TYPE_READ; if(dt_cmd_cnt%3 == 0) { //读取电源遥测数据-测 rtu_rt.reg_addr = Power_ComBase.PWD_ACData_RegAddr_Start; rtu_rt.reg_count = Power_ACData.REG_Count; //rtu_rt.reg_count = 17; //测试时最多读取17个寄存器 }else if(dt_cmd_cnt%3 == 1) { //读取锂电池包数据 rtu_rt.reg_addr = Power_ComBase.PWD_LIBMSData_RegAddr_Start[read_libms_index]; rtu_rt.reg_count = Power_LIBMSData.REG_Count; }else if(dt_cmd_cnt%3 == 2) { //读取电源模块数据 rtu_rt.reg_addr = Power_ComBase.PWD_ModelData_RegAddr_Start[read_model_index]; rtu_rt.reg_count = Power_ModelData.REG_Count; } if(dt_cmd_cnt%5 == 0) { //读取告警状态 rtu_rt.reg_addr = Power_ComBase.PWD_ModelAlm_RegAddr_Start; rtu_rt.reg_count = Power_AlmState.REG_Count; } if(dt_cmd_cnt%5 == 1) { //分路开关状态 rtu_rt.reg_addr = Power_ComBase.PWD_LoadControl_RegAddr_Start; rtu_rt.reg_count = Power_RoadState.REG_Count; } } else { //数据 dt_data = dt_databuffer; //遥调遥控数据 rtu_rt.Cmd = dt_user_cmd; dt_user_cmd = Power_ComBase.CMD_NULL; rtu_rt.reg_addr = dt_user_cmd_regaddr; if(dt_data.capacity() > 0) { rtu_rt.reg_count = dt_data.capacity()/2; }else if(Power_ComBase.PWD_SysParam_RegAddr_Start == rtu_rt.reg_addr) { rtu_rt.reg_count = Power_Param.REG_Count; }else if(Power_ComBase.PWD_LoadControl_RegAddr_Start <= rtu_rt.reg_addr && rtu_rt.reg_addr <= Power_ComBase.PWD_LoadControl_RegAddr_Start) { //分路控制以及门磁控制 rtu_rt.reg_count = Power_Param.Reg_Count_Control; }else if(Power_ComBase.PWD_AlmParam_RegAddr_Start == rtu_rt.reg_addr) { //告警参数 rtu_rt.reg_count = Power_AlmParam.REG_Count; }else if(Power_ComBase.PWD_PowerParam_RegAddr_Start == rtu_rt.reg_addr) { //电源参数 rtu_rt.reg_count = Power_Param.REG_Count_Power; }else if(Power_ComBase.PWD_SchoolTime_RegAddr_Start == rtu_rt.reg_addr) { //校时参数 rtu_rt.reg_count = Power_Param.REG_Count_Time; }else if(Power_ComBase.PWD_Load1Time_RegAddr_Start == rtu_rt.reg_addr) { //分路定时控制1-6 rtu_rt.reg_count = Power_TimeControl.REG_Count; }else if(Power_ComBase.PWD_Load7Time_RegAddr_Start == rtu_rt.reg_addr) { //分路定时控制7-12 rtu_rt.reg_count = Power_TimeControl.REG_Count; } } makeRTData(rtu_rt,dt_data); } public void makeRTData(MyModBusRtu rtu,ByteBuffer bf) { CommTxBuffer.position(0); CommTxBuffer.put((byte)rtu.addr); CommTxBuffer.put((byte)rtu.Cmd); CommTxBuffer.putShort((short)rtu.reg_addr); if(rtu.Cmd == MyModBusRtu.CMD_TYPE_READ) { //读取 CommTxBuffer.putShort((short)rtu.reg_count); } else if( rtu.Cmd == MyModBusRtu.CMD_TYPE_WRITE_STD || rtu.Cmd == MyModBusRtu.CMD_TYPE_WRITE_SysUpdate || rtu.Cmd == MyModBusRtu.CMD_TYPE_Read_UpdateFile ) { //单点写入 CommTxBuffer.put(bf); } else if(rtu.Cmd == MyModBusRtu.CMD_TYPE_WRITE_MULTY) { //多点写入 CommTxBuffer.putShort((short)rtu.reg_count); CommTxBuffer.put((byte)bf.capacity()); CommTxBuffer.put(bf); } int crc = Crc16.CalCRC16(CommTxBuffer, CommTxBuffer.position()) & 0xFFFF; CommTxBuffer.putShort((short) crc); CommTxBuffer.flip(); //System.out.println("发送数据长度:" + CommTxBuffer.remaining()); } public void tr_Msg(ByteBuffer bbf_tx, ByteBuffer bbf_rx, boolean showdat) { if(++comm_tx_cnt > 32500) { comm_tx_cnt = 0; } if(SPCommMon.COMM_PORT_TYPE_Serial == m_COMM_PORT_TYPE) { m_SP_Comm.SP_Comm(bbf_tx, bbf_rx, CommSerialPort.mutycomm_Type_Samd09, dt_debug_inf, showdat); } else { m_SocketComm.SocketComm(bbf_tx, bbf_rx, dt_debug_inf, showdat); } } public void CloseCommPort() { CommThreadRunning = false; } public void setCommCmd(short cmd, int cmd_reg_addr, short[] reg_data, int reg_len) { if(dt_cmd_regaddr > 0) { return; } dt_cmd = cmd; dt_cmd_regaddr = (short) cmd_reg_addr; dt_cmd_regdata = reg_data; dt_cmd_regcnt = (short) reg_len; } public void setCommCmd(short cmd, int cmd_user_reg_addr, ByteBuffer bf) { if(dt_cmd_regaddr > 0) { return; } dt_user_cmd = cmd; //命令 dt_user_cmd_regaddr = (short) cmd_user_reg_addr; //寄存器地址 dt_databuffer = bf; //遥控或遥调数据 } public void setCommCmdAck(int ack_t) { dt_cmd_ack = ack_t; dt_cmd_ack_time = new Date(); //System.out.println(Com.get_DTF(dt_cmd_ack_time, Com.DTF_YMDhms) + ", " + dev_param_data_state); String wav_f = "6133.wav"; if(ack_t%2 == 0) { wav_f = "4577.wav"; } if(ack_t > 0) { new PlaySound(wav_f); } } private boolean processRxData(ByteBuffer bbf_rx) { rtu_rx.clear(); boolean isSuccess = false; if(rtu_rx.putByteBuffer(bbf_rx)) { if(MyModBusRtu.CMD_TYPE_READ == rtu_rx.Cmd) { if(Power_ComBase.PWD_ACData_RegAddr_Start == rtu_rt.reg_addr) { //读取极简化电源遥测数据 if(m_AcData.putByteBuffer(bbf_rx)) { isSuccess = true; } }else if(Power_ComBase.PWD_LIBMSData_RegAddr_Start1 <= rtu_rt.reg_addr && rtu_rt.reg_addr <= Power_ComBase.PWD_LIBMSData_RegAddr_Start4) { //锂电池包数据 if(m_LibmsDatas[read_libms_index].putByteBuffer(bbf_rx)) { //System.out.println("锂电池包:"+(read_libms_index+1)+"读取成功"); read_libms_index ++; if(read_libms_index >= Power_ComBase.LIBMSDATA_MAX_COUNT) { read_libms_index = 0; } isSuccess = true; } }else if(Power_ComBase.PWD_ModelData_RegAddr_Start1 <= rtu_rt.reg_addr && rtu_rt.reg_addr <= Power_ComBase.PWD_ModelData_RegAddr_Start4) { //电源模块数据 if(m_ModelDatas[read_model_index].putByteBuffer(bbf_rx)) { //System.out.println("电源模块:"+(read_model_index+1)+"读取成功"); read_model_index ++; if(read_model_index >= Power_ComBase.LIMODEL_MAX_COUNT) { read_model_index = 0; } isSuccess = true; } }else if(Power_ComBase.PWD_ModelAlm_RegAddr_Start == rtu_rt.reg_addr) { if(m_AlmState.putByteBuffer(bbf_rx)) { isSuccess = true; } }else if(Power_ComBase.PWD_SysParam_RegAddr_Start == rtu_rt.reg_addr) { if(m_ParamFromDev.putByteBuffer(bbf_rx)) { dt_user_cmd_ack = Power_ComBase.PWD_SysParam_Read_ACK; op_result_sysparam = "读取电源系统参数成功" + Com.get_DTF(new Date(), Com.DTF_YMDhms); isSuccess = true; } }else if(Power_ComBase.PWD_PowerParam_RegAddr_Start == rtu_rt.reg_addr) { //System.out.println("999"); if(m_ParamFromDev.putPowerByteBuffer(bbf_rx)) { dt_user_cmd_ack = Power_ComBase.PWD_PwdParam_Read_ACK; op_result_powerparam = "读取电源参数成功" + Com.get_DTF(new Date(), Com.DTF_YMDhms); isSuccess = true; } }else if(Power_ComBase.PWD_AlmParam_RegAddr_Start == rtu_rt.reg_addr) { m_AlmParamFromDev = new Power_AlmParam(); if(m_AlmParamFromDev.putByteBuffer(bbf_rx)) { dt_user_cmd_ack = Power_ComBase.PWD_AlmParam_Read_ACK; op_result_almaram = "读取电源告警参数成功" + Com.get_DTF(new Date(), Com.DTF_YMDhms); isSuccess = true; } }else if(Power_ComBase.PWD_SchoolTime_RegAddr_Start == rtu_rt.reg_addr) { if(m_ParamFromDev.putTimeByteBuffer(bbf_rx)) { dt_user_cmd_ack = Power_ComBase.PWD_SchoolTime_Read_ACK; op_result_jiaozhun = "读取设备时间成功" + Com.get_DTF(new Date(), Com.DTF_YMDhms); isSuccess = true; } }else if(Power_ComBase.PWD_Load1Time_RegAddr_Start == rtu_rt.reg_addr) { if(m_TimeControlFromDev.putByteBuffer1(bbf_rx)) { dt_user_cmd_ack = Power_ComBase.PWD_Load1Time_Read_ACK; op_result_jiaozhun = "读取1-6路分时参数成功" + Com.get_DTF(new Date(), Com.DTF_YMDhms); isSuccess = true; } }else if(Power_ComBase.PWD_Load7Time_RegAddr_Start == rtu_rt.reg_addr) { if(m_TimeControlFromDev.putByteBuffer2(bbf_rx)) { dt_user_cmd_ack = Power_ComBase.PWD_Load2Time_Read_ACK; op_result_jiaozhun = "读取7-12路分时参数成功" + Com.get_DTF(new Date(), Com.DTF_YMDhms); isSuccess = true; } }else if(Power_ComBase.PWD_LoadControl_RegAddr_Start == rtu_rt.reg_addr) { if(m_RoadStateFromDev.putByteBuffer(bbf_rx)) { //System.err.println("读取分路1~12分路状态成功" + m_RoadStateFromDev); isSuccess = true; } } }else if(MyModBusRtu.CMD_TYPE_WRITE_STD == rtu_rx.Cmd) { if(Power_ComBase.PWD_DoorControl_RegAddr_Start == rtu_rx.reg_addr) { //门磁控制 if(Power_ComBase.CMD_Fail != rtu_rx.result) { op_result_sysparam = "控制门磁打开成功" + Com.get_DTF(new Date(), Com.DTF_YMDhms); }else { op_result_sysparam = "控制门磁关闭成功" + Com.get_DTF(new Date(), Com.DTF_YMDhms); } isSuccess = true; }else if(Power_ComBase.PWD_LoadControl_RegAddr_Start <= rtu_rx.reg_addr && rtu_rx.reg_addr < Power_ComBase.PWD_BackControl_RegAddr_Start) { //分路1~12控制 int idx = rtu_rx.reg_addr - Power_ComBase.PWD_LoadControl_RegAddr_Start +1; if(Power_ComBase.CMD_Fail != rtu_rx.result) { op_result_sysparam = "控制分路" + idx + "打开成功" + Com.get_DTF(new Date(), Com.DTF_YMDhms); }else { op_result_sysparam = "控制分路" + idx + "关闭成功" + Com.get_DTF(new Date(), Com.DTF_YMDhms); } isSuccess = true; }else if(Power_ComBase.PWD_BackControl_RegAddr_Start <= rtu_rx.reg_addr && rtu_rx.reg_addr < Power_ComBase.PWD_DoorControl_RegAddr_Start) { //分路1~12备电控制 int idx = rtu_rx.reg_addr - Power_ComBase.PWD_BackControl_RegAddr_Start +1; if(Power_ComBase.CMD_Fail != rtu_rx.result) { op_result_sysparam = "控制分路" + idx + "备电控制打开成功" + Com.get_DTF(new Date(), Com.DTF_YMDhms); }else { op_result_sysparam = "控制分路" + idx + "备电控制关闭失败" + Com.get_DTF(new Date(), Com.DTF_YMDhms); } isSuccess = true; } }else if(MyModBusRtu.CMD_TYPE_WRITE_MULTY == rtu_rx.Cmd) { if(Power_ComBase.PWD_PowerParam_RegAddr_Start == rtu_rx.reg_addr) { //设置电源参数 if(rtu_rx.result == Power_Param.REG_Count_Power) { op_result_powerparam = "设置电源参数成功" + Com.get_DTF(new Date(), Com.DTF_YMDhms); isSuccess = true; }else { op_result_powerparam = "设置电源参数失败" + Com.get_DTF(new Date(), Com.DTF_YMDhms); } }else if(Power_ComBase.PWD_AlmParam_RegAddr_Start == rtu_rx.reg_addr) { //设置电源告警参数 if(rtu_rx.result == Power_AlmParam.REG_Count) { op_result_almaram = "设置电源告警参数成功" + Com.get_DTF(new Date(), Com.DTF_YMDhms); isSuccess = true; }else { op_result_almaram = "设置电源告警参数失败" + Com.get_DTF(new Date(), Com.DTF_YMDhms); } }else if(Power_ComBase.PWD_SysParam_RegAddr_Start == rtu_rx.reg_addr) { //设置电源系统参数 if(rtu_rx.result == Power_Param.REG_Count) { op_result_sysparam = "设置电源系统参数成功" + Com.get_DTF(new Date(), Com.DTF_YMDhms); isSuccess = true; }else { op_result_sysparam = "设置电源系统参数失败" + Com.get_DTF(new Date(), Com.DTF_YMDhms); } }else if(Power_ComBase.PWD_SchoolTime_RegAddr_Start == rtu_rx.reg_addr) { //设置电源校时 if(rtu_rx.result == Power_Param.REG_Count_Time) { op_result_jiaozhun = "设置电源校时成功" + Com.get_DTF(new Date(), Com.DTF_YMDhms); isSuccess = true; }else { op_result_jiaozhun = "设置电源校时失败" + Com.get_DTF(new Date(), Com.DTF_YMDhms); } }else if(Power_ComBase.PWD_Load1Time_RegAddr_Start == rtu_rx.reg_addr) { //设置分路1-6分时控制 if(rtu_rx.result == Power_TimeControl.REG_Count) { op_result_jiaozhun = "设置分路1-6分时参数成功" + Com.get_DTF(new Date(), Com.DTF_YMDhms); isSuccess = true; }else { op_result_jiaozhun = "设置分路1-6分时参数失败" + Com.get_DTF(new Date(), Com.DTF_YMDhms); } }else if(Power_ComBase.PWD_Load7Time_RegAddr_Start == rtu_rx.reg_addr) { //设置分路7-12分时控制 if(rtu_rx.result == Power_TimeControl.REG_Count) { op_result_jiaozhun = "设置分路7-12分时参数成功" + Com.get_DTF(new Date(), Com.DTF_YMDhms); isSuccess = true; }else { op_result_jiaozhun = "设置分路7-12分时参数失败" + Com.get_DTF(new Date(), Com.DTF_YMDhms); } } } else if(MyModBusRtu.CMD_TYPE_WRITE_SysUpdate == rtu_rx.Cmd) { if(Power_ComBase.PWD_SysReStart_RegAddr_Start == rtu_rx.reg_addr) { //远程重启设备 if(rtu_rx.result == 0xBBBB) { //设备远程重启成功 dt_user_cmd_ack = Power_ComBase.PWD_SysRestart_Success_ACK; isSuccess = true; }else { //设备远程重启失败 dt_user_cmd_ack = Power_ComBase.PWD_SysRestart_Fail_ACK; } }else if(Power_ComBase.PWD_TransUpdateFile_RegAddr_Start == rtu_rx.reg_addr) { if(rtu_rx.result != 0) { isSuccess = true; } }else if(Power_ComBase.PWD_StartUpdate_RegAddr_Start == rtu_rx.reg_addr) { if(rtu_rx.result != 0) { isSuccess = true; appendUppdateInfo("System Update Success ... " + Com.get_DTF(new Date(), Com.DTF_YMDhms) + "\n"); }else { appendUppdateInfo("System Update Fail ... " + Com.get_DTF(new Date(), Com.DTF_YMDhms) + "\n"); } } } else if(MyModBusRtu.CMD_TYPE_Read_UpdateFile == rtu_rx.Cmd) { if(Power_ComBase.PWD_TransUpdateFile_RegAddr_Start == rtu_rt.reg_addr) { if(bbf_rx.remaining() > 2) { isSuccess = true; }else { System.err.println("返回数据长度不足"); } } } } if(bbf_rx.limit() > 0 && isSuccess) { if(++comm_rx_cnt > 32500) { comm_rx_cnt = 0; } } return isSuccess; } public void setAutoStartRestTest(String filename, int type, boolean en) { AutoSaveDataFileName = filename; AutoStartResTestEn = en; AutoSaveResDataCount = 0; } private void closeSPCommPort() { if(SPCommMon.COMM_PORT_TYPE_Serial == m_COMM_PORT_TYPE) { m_SP_Comm.serialPort.close(); } else { m_SocketComm.socketClose(); } } public void run() { while(true == CommThreadRunning) { try { Thread.sleep(200); if(dt_dfu_en == false) { makeCommTxData(); tr_Msg(CommTxBuffer, CommRxBuffer, true); processRxData(CommRxBuffer); } else { //--------------------------- BOOTLOADER_CMD_WRITE-----------------------------// dt_show_msg.append("---------------------------------------------------\n"); String dfu_text_inf = "Power System Update Start." + Com.get_DTF(new Date(), Com.DTF_YMDhms) + "\n"; appendUppdateInfo(dfu_text_inf); boolean prog_ok = false; FileInputStream fis = null; try { File f = new File(dt_dfuFileName); long file_len = f.length(); byte[] buf_to_flash = new byte[Power_ComBase.DFU_BUF_LEN]; Thread.sleep(100); fis = new FileInputStream(f); int dfu_datablock_num = 1; int percent = 0; while(true) { //====================================// if((false == dt_dfu_en) || (false == CommThreadRunning)) { dfu_text_inf = "DFU Manual Stop . . .\n"; appendUppdateInfo(dfu_text_inf); break; } //====================================// for(int n=0; n<buf_to_flash.length; n++) { buf_to_flash[n] = (byte) 0xFF; } //====================================// int data_len_towrite = fis.read(buf_to_flash); if(data_len_towrite > 0) { Thread.sleep(1); for(int cnt_t=0; cnt_t<3; cnt_t++) { //构造发送数据 makeSendFileData(buf_to_flash,dfu_datablock_num); dt_user_cmd = MyModBusRtu.CMD_TYPE_WRITE_SysUpdate; dt_user_cmd_regaddr = Power_ComBase.PWD_TransUpdateFile_RegAddr_Start; makeCommTxData(); tr_Msg(CommTxBuffer, CommRxBuffer, true); if(true == processRxData(CommRxBuffer)) { if(rtu_rx.result == dfu_datablock_num) { prog_ok = true; break; } } else { prog_ok = false; Thread.sleep(500); } } if(false == prog_ok) { dfu_text_inf = "DFU Write Error!\n"; appendUppdateInfo(dfu_text_inf); break; } else { dfu_datablock_num += 1; } int tran_len_t = dfu_datablock_num*FBS9100_DFU.DFU_BUF_LEN; if(percent < (tran_len_t*100)/file_len) { percent = (int) ((tran_len_t*100)/file_len); if(percent > 100) { percent = 100; } appendUppdateInfo(String.format("DFU Write: %d%% Done.\n", percent)); } } else { dfu_text_inf = "DFU Write: 100% Done!\n"; appendUppdateInfo(dfu_text_inf); //System.out.println(dfu_text_inf); break; } } } catch (IOException | InterruptedException e1) { e1.printStackTrace(); } finally { try { fis.close(); } catch (IOException e1) { e1.printStackTrace(); } } if((true == prog_ok) && (true == dt_dfu_en) && (true == CommThreadRunning)) { boolean check_ok = false; FileInputStream fis_ck = null; try { File f_ck = new File(dt_dfuFileName); long file_len_ck = f_ck.length(); byte[] buf_check = new byte[Power_ComBase.DFU_BUF_LEN]; Thread.sleep(100); fis_ck = new FileInputStream(f_ck); int check_datablock_num = 1; int percent = 0; while(true) { //====================================// if((false == dt_dfu_en) || (false == CommThreadRunning)) { dfu_text_inf = "DFU Check Manual Stop . . .\n"; appendUppdateInfo(dfu_text_inf); break; } //====================================// for(int n=0; n<buf_check.length; n++) { buf_check[n] = (byte) 0xFF; } //====================================// int len_buf_check = fis_ck.read(buf_check); if(len_buf_check > 0) { Thread.sleep(1); for(int cnt_t=0; cnt_t<3; cnt_t++) { //构造发送数据 dt_databuffer = power_util.createSysUpdateControlByteBuffer(check_datablock_num); dt_user_cmd = MyModBusRtu.CMD_TYPE_Read_UpdateFile; dt_user_cmd_regaddr = Power_ComBase.PWD_TransUpdateFile_RegAddr_Start; makeCommTxData(); tr_Msg(CommTxBuffer, CommRxBuffer, true); if(true == processRxData(CommRxBuffer)) { if(rtu_rx.result == check_datablock_num) { if(true == checkDfuReadAckBuf(CommRxBuffer, buf_check)) { check_ok = true; } else { check_ok = false; Thread.sleep(500); } if(true == check_ok) { break; } } } } if(false == check_ok) { dfu_text_inf = "DFU File Check Error!\n "; appendUppdateInfo(dfu_text_inf); break; } else { check_datablock_num += 1; } int tran_len_t = check_datablock_num*FBS9100_DFU.DFU_BUF_LEN; if(percent < (tran_len_t*100)/file_len_ck) { percent = (int) ((tran_len_t*100)/file_len_ck); if(percent > 100) { percent = 100; } appendUppdateInfo(String.format("DFU File Check: %d%% Done.\n", percent)); } } else { dfu_text_inf = "DFU File Check: 100% Done!\n"; appendUppdateInfo(dfu_text_inf); setCommCmd(MyModBusRtu.CMD_TYPE_WRITE_SysUpdate, Power_ComBase.PWD_StartUpdate_RegAddr_Start, power_util.createSysUpdateControlByteBuffer(0xDFDF)); //setCommCmd(FBS9100_ComBase.CMD_SystemUpdate, ByteBuffer.allocate(0)); break; } } } catch (IOException | InterruptedException e1) { e1.printStackTrace(); } finally { try { fis_ck.close(); } catch (IOException e1) { e1.printStackTrace(); } } } //---------------------------------------------------------------------------------// dt_dfu_en = false; //---------------------------------------------------------------------------------// } } catch (InterruptedException e) { e.printStackTrace(); CloseCommPort(); JOptionPane.showMessageDialog(null, "ZDHJ CommPort 串口异常: " + e.getMessage()); } } /******************************************/ closeSPCommPort(); /******************************************/ dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S) + " ZDHJ CommPort is quit," + " COMM_PORT_TYPE: " + m_COMM_PORT_TYPE + "\n"); /******************************************/ } public void makeSendFileData(byte[] data,int block_num) { dt_databuffer = ByteBuffer.allocate(data.length + 2); dt_databuffer.order(ByteOrder.BIG_ENDIAN); dt_databuffer.putShort(FBS9100_ComBase.changeIntToShort(block_num)); dt_databuffer.put(data); dt_databuffer.flip(); } public void setCommCmd_DFU(boolean dfu_en, String dfu_file, JTextArea show_area) { dt_dfu_en = dfu_en; dt_show_msg = show_area; dt_dfuFileName = dfu_file; } public boolean checkDfuReadAckBuf(ByteBuffer bf,byte[] data) { boolean check_ok = false; if(data.length <= bf.remaining()) { check_ok = true; for(int k = 0 ;k< data.length;k++) { if(data[k] != bf.get()) { System.err.println("校验字节:" + k + "失败"); check_ok = false; break; } } }else { //System.err.println("bf:"+ComFn.bytesToHexString(bf.array(), bf.array().length)); //System.err.println("data:"+ComFn.bytesToHexString(data, data.length)); //System.err.println("data.length:" + data.length + "\tbf.remaining():"+bf.remaining()); } return check_ok; } public void appendUppdateInfo(String msg) { StringBuffer buffer = new StringBuffer(dt_show_msg.getText()); dt_show_msg.setText(msg); dt_show_msg.append(buffer.toString()); } } Device_Simulator_DTS_Tester/src/com/dev/simpower/dev/Power_ACData.java
New file @@ -0,0 +1,82 @@ package com.dev.simpower.dev; import java.nio.ByteBuffer; import java.util.Arrays; import com.dev.bts.data.FBS9100_ComBase; public class Power_ACData { public static final int LOAD_COUNT = 8; //public static final int REG_Count = 17; //寄存器数量 public static final int REG_Count = 36; //寄存器数量 public float acin_vol; //交流输入电压 0.1V public float acin_curr; //交流输入电流 0.1A public float acin_power; //交流输入功率 0.1W public float group_vol; //组端电压 0.1V public float batt_curr; //电池电流 0.1A,有符号数,“+”代表充电,“-”代表放电 public float total_curr; //负荷总电流 0.1A public float[] load_curr; //分路电流1~8 分路测量的电流,1~8路,0.1A public float dev_temp; //设备主板温度 0.1℃,有符号数 public float envir_temp; //环境温度 0.1℃,有符号数 public float envir_humid; //环境湿度 0.1%RH public float[] load_kwh; //分路计量电量1 0.1KWH,2个寄存器 public int[] dev_version; //设备版本号 public Power_ACData() { load_curr = new float[LOAD_COUNT]; load_kwh = new float[LOAD_COUNT]; dev_version = new int[3]; } public boolean putByteBuffer(ByteBuffer bbf_rx) { if(bbf_rx.limit() < REG_Count*2) { System.out.println("bbf_rx.limit()"+bbf_rx.limit()); return false; } this.acin_vol = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //交流输入电压 0.1V this.acin_curr = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //交流输入电流 0.1A this.acin_power = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //交流输入功率 0.1W this.group_vol = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //组端电压 0.1V this.batt_curr = FBS9100_ComBase.changeSigleShortToFloat(bbf_rx.getShort())/10; //电池电流 0.1A,有符号数,“+”代表充电,“-”代表放电 this.total_curr = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //负荷总电流 0.1A for(int i = 0;i< load_curr.length;i++) { load_curr[i] = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //分路电流1~8 分路测量的电流,1~8路,0.1A } this.dev_temp = FBS9100_ComBase.changeSigleShortToFloat(bbf_rx.getShort())/10; //设备主板温度 0.1℃,有符号数 this.envir_temp = FBS9100_ComBase.changeSigleShortToFloat(bbf_rx.getShort())/10; //环境温度 0.1℃,有符号数 this.envir_humid = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //环境湿度 0.1%RH for(int k = 0;k<load_kwh.length;k++) { float aa = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort()); float dd = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())*65536; //int aa = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //int dd = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort())<<16&0xFFFFFFFF; load_kwh[k] = (aa+dd)/10; //分路1-8计量电量1 0.1KWH,2个寄存器 } //System.err.println(" position: " + bbf_rx.position()); for(int k = 0;k<dev_version.length;k++) { dev_version[k] = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //设备版本号 VXX.XX.XX } //System.err.println(this); return true; } @Override public String toString() { return "Power_ACData [acin_vol=" + acin_vol + ", acin_curr=" + acin_curr + ", acin_power=" + acin_power + ", group_vol=" + group_vol + ", batt_curr=" + batt_curr + ", total_curr=" + total_curr + ", load_curr=" + Arrays.toString(load_curr) + ", dev_temp=" + dev_temp + ", envir_temp=" + envir_temp + ", envir_humid=" + envir_humid + ", load_kwh=" + Arrays.toString(load_kwh) + ", dev_version=" + Arrays.toString(dev_version) + "]"; } } Device_Simulator_DTS_Tester/src/com/dev/simpower/dev/Power_AlmParam.java
New file @@ -0,0 +1,71 @@ package com.dev.simpower.dev; import java.nio.ByteBuffer; import java.nio.ByteOrder; import com.dev.bts.data.FBS9100_ComBase; /** * 电源告警参数 * @author DELL * */ public class Power_AlmParam { public static final int REG_Count = 11; //系统参数寄存器数量 public float acin_vol_high; //2400 交流输入高阈值 0.1V public float acin_vol_low; //2401 交流输入低阈值 0.1V public float groupvol_high; //2402 组端电压高阈值 0.1V public float groupvol_low; //2403 组端电压低阈值 0.1V public float monvol_high; //2404 单体电压高阈值 0.001V public float monvol_low; //2405 单体电压低阈值 0.001V public float discurr_high; //2406 放电电流大阈值 A public float chrcurr_high; //2407 充电电流大阈值 A public float dcoutputcurr_high; //2408 直流输出电流大阈值 A public float dev_temp_high; //2409 设备内部温度高阈值 0.1℃ public float dev_temp_low; //2410 设备内部温度低阈值 0.1℃ public boolean putByteBuffer(ByteBuffer bbf_rx) { if(bbf_rx.limit() < REG_Count*2) { return false; } bbf_rx.position(0); this.acin_vol_high = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //2400 交流输入高阈值 0.1V this.acin_vol_low = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //2401 交流输入低阈值 0.1V this.groupvol_high = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //2402 组端电压高阈值 0.1V this.groupvol_low = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //2403 组端电压低阈值 0.1V this.monvol_high = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/1000; //2404 单体电压高阈值 0.001V this.monvol_low = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/1000; //2405 单体电压低阈值 0.001V this.discurr_high = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort()); //2406 放电电流大阈值 A this.chrcurr_high = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort()); //2407 充电电流大阈值 A this.dcoutputcurr_high = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort()); //2408 直流输出电流大阈值 A this.dev_temp_high = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //2409 设备内部温度高阈值 0.1℃ this.dev_temp_low = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //2410 设备内部温度低阈值 0.1℃ //System.out.println(this); return true; } public ByteBuffer getByteBuffer() { ByteBuffer buffer = ByteBuffer.allocate(REG_Count*2); buffer.order(ByteOrder.BIG_ENDIAN); buffer.position(0); buffer.putShort(FBS9100_ComBase.changeFloatToShort(this.acin_vol_high*10)); buffer.putShort(FBS9100_ComBase.changeFloatToShort(this.acin_vol_low*10)); buffer.putShort(FBS9100_ComBase.changeFloatToShort(this.groupvol_high*10)); buffer.putShort(FBS9100_ComBase.changeFloatToShort(this.groupvol_low*10)); buffer.putShort(FBS9100_ComBase.changeFloatToShort(this.monvol_high*1000)); buffer.putShort(FBS9100_ComBase.changeFloatToShort(this.monvol_low*1000)); buffer.putShort(FBS9100_ComBase.changeFloatToShort(this.discurr_high)); buffer.putShort(FBS9100_ComBase.changeFloatToShort(this.chrcurr_high)); buffer.putShort(FBS9100_ComBase.changeFloatToShort(this.dcoutputcurr_high)); buffer.putShort(FBS9100_ComBase.changeFloatToShort(this.dev_temp_high*10)); buffer.putShort(FBS9100_ComBase.changeFloatToShort(this.dev_temp_low*10)); buffer.flip(); return buffer; } } Device_Simulator_DTS_Tester/src/com/dev/simpower/dev/Power_AlmState.java
New file @@ -0,0 +1,98 @@ package com.dev.simpower.dev; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import com.dev.bts.data.FBS9100_ComBase; /** * 设备温度告警 * @author DELL * */ public class Power_AlmState { public static final int REG_Count = 76; //寄存器数量 public int ac_powerdown; //1500 交流停电告警 0-无告警,1-停电告警 public int access_open; //1501 门禁开启告警 0-无告警,1-门禁开启 public int water_alm; //1502 水浸告警 0-无告警,1-水浸告警 public int ligh_alm; //1503 防雷器告警 0-无告警,1-防雷器异常 public int licomm_alm; //1504 锂电池BMS通信异常告警 0-无告警,1-通信异常 public int powercomm_alm; //1505 电源模块通信异常告警 0-无告警,1-通信异常 public int acin_poweralm; //1506 交流输入告警 0-无告警,1-超过上限告警,2-低于下限告警 public int groupvol_alm; //1507 组端电压告警 0-无告警,1-超过上限告警,2-低于下限告警 public int mon_vol_alm[] = new int[64]; //1508~1571 单体电压告警 1~64节(4*16)告警,0-无告警,1-超过上限告警,2-低于下限告警 public int discurr_high; //1572 电池放电电流大告警 0-无告警,1-电池放电电流大 public int chrcurr_high; //1573 电池充电电流大告警 0-无告警,1-电池充电电流大 public int dcoutputcurr_high; //1574 直流输出电流大告警 0-无告警,1-直流输出电流大 public int devtemp_high; //1575 设备温度高告警 0-无告警,1-设备温度高 public boolean putByteBuffer(ByteBuffer bbf_rx) { if(bbf_rx.limit() < REG_Count*2) { return false; } bbf_rx.position(0); this.ac_powerdown = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //1500 交流停电告警 0-无告警,1-停电告警 this.access_open = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //1501 门禁开启告警 0-无告警,1-门禁开启 this.water_alm = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //1502 水浸告警 0-无告警,1-水浸告警 this.ligh_alm = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //1503 防雷器告警 0-无告警,1-防雷器异常 this.licomm_alm = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //1504 锂电池BMS通信异常告警 0-无告警,1-通信异常 this.powercomm_alm = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //1505 电源模块通信异常告警 0-无告警,1-通信异常 this.acin_poweralm = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //1506 交流输入告警 0-无告警,1-超过上限告警,2-低于下限告警 this.groupvol_alm = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //1507 组端电压告警 0-无告警,1-超过上限告警,2-低于下限告警 for (int i = 0; i < mon_vol_alm.length; i++) { this.mon_vol_alm[i] = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //1508~1571 单体电压告警 1~64节(4*16)告警,0-无告警,1-超过上限告警,2-低于下限告警 } this.discurr_high = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //1572 电池放电电流大告警 0-无告警,1-电池放电电流大 this.chrcurr_high = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //1573 电池充电电流大告警 0-无告警,1-电池充电电流大 this.dcoutputcurr_high = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //1574 直流输出电流大告警 0-无告警,1-直流输出电流大 this.devtemp_high = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //1575 设备温度高告警 0-无告警,1-设备温度高 //System.out.println(this); return true; } public List<String> getPowerAlarmState(){ List<String> alm_state = new ArrayList<>(); alm_state.add(ac_powerdown==0?"无告警":"停电告警"); alm_state.add(access_open==0?"无告警":"门禁开启"); alm_state.add(water_alm==0?"无告警":"水浸告警"); alm_state.add(ligh_alm==0?"无告警":"防雷器告警"); alm_state.add(licomm_alm==0?"无告警":"通信异常"); alm_state.add(powercomm_alm==0?"无告警":"通信异常"); alm_state.add(acin_poweralm==0?"无告警":acin_poweralm==1?"上限告警":acin_poweralm==2?"下限告警":"其他"); alm_state.add(groupvol_alm==0?"无告警":groupvol_alm==1?"上限告警":groupvol_alm==2?"下限告警":"其他"); for(int k = 0;k<mon_vol_alm.length;k++) { int vol_alm = mon_vol_alm[k]; alm_state.add(vol_alm==0?"无告警":vol_alm==1?"上限告警":vol_alm==2?"下限告警":"其他"); } alm_state.add(discurr_high==0?"无告警":"电池放电电流大"); alm_state.add(chrcurr_high==0?"无告警":"电池充电电流大"); alm_state.add(dcoutputcurr_high==0?"无告警":"直流输出电流大"); alm_state.add(devtemp_high==0?"无告警":"设备温度高"); return alm_state; } @Override public String toString() { return "Power_AlmState [ac_powerdown=" + ac_powerdown + ", access_open=" + access_open + ", water_alm=" + water_alm + ", ligh_alm=" + ligh_alm + ", licomm_alm=" + licomm_alm + ", powercomm_alm=" + powercomm_alm + ", acin_poweralm=" + acin_poweralm + ", groupvol_alm=" + groupvol_alm + ", mon_vol_alm=" + Arrays.toString(mon_vol_alm) + ", discurr_high=" + discurr_high + ", chrcurr_high=" + chrcurr_high + ", dcoutputcurr_high=" + dcoutputcurr_high + ", devtemp_high=" + devtemp_high + "]"; } } Device_Simulator_DTS_Tester/src/com/dev/simpower/dev/Power_ComBase.java
New file @@ -0,0 +1,99 @@ package com.dev.simpower.dev; public class Power_ComBase { public static final int Control_RegCount = 1; //控制寄存器个数 public static final int LIBMSDATA_MAX_COUNT = 4; //锂电池包最大数量 public static final int LIMODEL_MAX_COUNT = 4; //电源模块最大数量 public static final int MON_MAX_COUNT = 16; //电源模块最大数量 public static final int CMD_NULL = 0; //交流电源数据 public static final int CMD_Fail = 0xFFEE; //交流电源数据 public static final int DFU_BUF_LEN = 256; //远程升级包长度 public static final int PWD_ACData_RegAddr_Start = 0; //交流电源数据 public static final int PWD_LIBMSData_RegAddr_Start1 = 500; //锂电池包1BMS信息 public static final int PWD_LIBMSData_RegAddr_Start2 = 590; //锂电池包2BMS信息 public static final int PWD_LIBMSData_RegAddr_Start3 = 680; //锂电池包3BMS信息 public static final int PWD_LIBMSData_RegAddr_Start4 = 770; //锂电池包4BMS信息 public static final int[] PWD_LIBMSData_RegAddr_Start = new int[] { PWD_LIBMSData_RegAddr_Start1, PWD_LIBMSData_RegAddr_Start2, PWD_LIBMSData_RegAddr_Start3, PWD_LIBMSData_RegAddr_Start4 }; public static final int PWD_ModelData_RegAddr_Start1 = 1000; //电源模块1数据 public static final int PWD_ModelData_RegAddr_Start2 = 1031; //电源模块2数据 public static final int PWD_ModelData_RegAddr_Start3 = 1061; //电源模块3数据 public static final int PWD_ModelData_RegAddr_Start4 = 1091; //电源模块4数据 public static final int[] PWD_ModelData_RegAddr_Start = new int[] { PWD_ModelData_RegAddr_Start1, PWD_ModelData_RegAddr_Start2, PWD_ModelData_RegAddr_Start3, PWD_ModelData_RegAddr_Start4 }; public static final int PWD_ModelAlm_RegAddr_Start = 1500; //电源告警 public static final int PWD_SysParam_RegAddr_Start = 2000; //系统参数 public static final int PWD_LoadControl_RegAddr_Start = 2200; //分路控制参数 public static final int PWD_BackControl_RegAddr_Start = 2212; //分路备电控制参数 public static final int PWD_DoorControl_RegAddr_Start = 2224; //门磁控制 public static final int PWD_AlmParam_RegAddr_Start = 2400; //告警参数 public static final int PWD_PowerParam_RegAddr_Start = 2600; //电源参数 public static final int PWD_SchoolTime_RegAddr_Start = 2800; //校时地址 public static final int PWD_Load1Time_RegAddr_Start = 3000; //分路1定时开关 public static final int PWD_Load2Time_RegAddr_Start = 3014; //分路2定时开关 public static final int PWD_Load3Time_RegAddr_Start = 3028; //分路3定时开关 public static final int PWD_Load4Time_RegAddr_Start = 3042; //分路4定时开关 public static final int PWD_Load5Time_RegAddr_Start = 3056; //分路5定时开关 public static final int PWD_Load6Time_RegAddr_Start = 3070; //分路6定时开关 public static final int PWD_Load7Time_RegAddr_Start = 3084; //分路7定时开关 public static final int PWD_Load8Time_RegAddr_Start = 3098; //分路8定时开关 public static final int PWD_Load9Time_RegAddr_Start = 3012; //分路9定时开关 public static final int PWD_Load10Time_RegAddr_Start = 3026; //分路10定时开关 public static final int PWD_Load11Time_RegAddr_Start = 3040; //分路11定时开关 public static final int PWD_Load12Time_RegAddr_Start = 3054; //分路12定时开关 public static final int PWD_TransUpdateFile_RegAddr_Start = 0xF000; //传输升级文件寄存器地址 public static final int PWD_StartUpdate_RegAddr_Start = 0xF001; //启动升级寄存器地址 public static final int PWD_SysReStart_RegAddr_Start = 0xF002; //远程重启寄存器地址 public static final int PWD_AlmParam_Read_ACK = 0x10; //读取告警参数成功 public static final int PWD_SysParam_Read_ACK = 0x11; //读取系统参数成功 public static final int PWD_PwdParam_Read_ACK = 0x12; //读取电源参数成功 public static final int PWD_SchoolTime_Read_ACK = 0x13; //读取校时参数成功 public static final int PWD_Load1Time_Read_ACK = 0x14; //读取分路1-6定时参数成功 public static final int PWD_Load2Time_Read_ACK = 0x15; //读取分路7-12定时参数成功 // public static final int PWD_Load3Time_Read_ACK = 0x16; //读取分路定时参数成功 // public static final int PWD_Load4Time_Read_ACK = 0x17; //读取分路定时参数成功 // public static final int PWD_Load5Time_Read_ACK = 0x18; //读取分路定时参数成功 // public static final int PWD_Load6Time_Read_ACK = 0x19; //读取分路定时参数成功 // public static final int PWD_Load7Time_Read_ACK = 0x1A; //读取分路定时参数成功 // public static final int PWD_Load8Time_Read_ACK = 0x1B; //读取分路定时参数成功 // public static final int PWD_Load9Time_Read_ACK = 0x1C; //读取分路定时参数成功 // public static final int PWD_Load10Time_Read_ACK = 0x1D; //读取分路定时参数成功 // public static final int PWD_Load11Time_Read_ACK = 0x1E; //读取分路定时参数成功 // public static final int PWD_Load12Time_Read_ACK = 0x1F; //读取分路定时参数成功 public static final int PWD_SysRestart_Success_ACK = 0x20; //读取校时参数成功 public static final int PWD_SysRestart_Fail_ACK = 0x21; //读取校时参数失败 } Device_Simulator_DTS_Tester/src/com/dev/simpower/dev/Power_LIBMSData.java
New file @@ -0,0 +1,103 @@ package com.dev.simpower.dev; import java.nio.ByteBuffer; import java.util.Arrays; import com.dev.bts.data.FBS9100_ComBase; /** * 锂电池BMS包信息 * @author DELL * */ public class Power_LIBMSData { public static final int LOAD_COUNT = 8; public static final int MONCNT_COUNT = 16; public static final int REG_Count = 90; //寄存器数量 public int reserve1[] = new int[2]; //500 保留 public int mon_cout; //502 单体电池数量 一般固定16 public float mon_vol[] = new float[16]; //503~518 单体电池电压 0.001V,1~16节单体电压 public int montemp_cout; //519 电芯温度数量 一般固定4 public float mon_temp[] = new float[4]; //520~523 电芯温度 0.1℃,1~4个电芯温度数据 public float envir_temp; //524 环境温度 0.1℃ public float mos_temp; //525 MOS管温度 0.1℃ public float batt_curr; //526 电池电流 0.01A public float batt_totalvol; //527 电池总压 0.01V public float rest_cap; //528 剩余容量 0.01AH public float total_cap; //529 总容量 0.01AH public int battcyclecount; //530 电池循环次数 public int reserve2; //531 保留 public int soc_state; //532 SOC 电池荷电状态 public int soh_state; //533 SOH 电池健康状态 public int[] reserve3 = new int[10]; //534~543 保留 public int mon_vol_alm[] = new int[16]; //544~559 单体电池电压告警状态 1~16节单体电压告警 (*见注释1) public int mon_tmp_count; //560 电芯温度数量 一般固定为4 public int mon_tmp_alm[] = new int[4]; //561~564 电芯温度告警状态 1~4个电芯温度告警(*见注释1) public int reserve4[] = new int[25]; //565~589 保留 public boolean putByteBuffer(ByteBuffer bbf_rx) { if(bbf_rx.limit() < REG_Count*2) { return false; } for(int k = 0;k<reserve1.length;k++) { this.reserve1[k] = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //500 保留 } this.mon_cout = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //502 单体电池数量 一般固定16 for(int k = 0;k<mon_vol.length;k++) { this.mon_vol[k] = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/1000; //503~518 单体电池电压 0.001V,1~16节单体电压 } this.montemp_cout = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //519 电芯温度数量 一般固定4 for(int k = 0;k<mon_temp.length;k++) { this.mon_temp[k] = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //520~523 电芯温度 0.1℃,1~4个电芯温度数据 } this.envir_temp = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //524 环境温度 0.1℃ this.mos_temp = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //525 MOS管温度 0.1℃ this.batt_curr = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/100; //526 电池电流 0.01A this.batt_totalvol = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/100; //527 电池总压 0.01V this.rest_cap = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/100; //528 剩余容量 0.01AH this.total_cap = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/100; //529 总容量 0.01AH this.battcyclecount = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //530 电池循环次数 this.reserve2 = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //531 保留 this.soc_state = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //532 SOC 电池荷电状态 this.soh_state = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //533 SOH 电池健康状态 for(int k =0;k<reserve3.length;k++) { reserve3[k] = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //534~543 保留 } for(int k = 0;k<mon_vol_alm.length;k++) { this.mon_vol_alm[k] = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //544~559 单体电池电压告警状态 1~16节单体电压告警 (*见注释1) } this.mon_tmp_count = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //560 电芯温度数量 一般固定为4 for(int k = 0;k<mon_tmp_alm.length;k++) { this.mon_tmp_alm[k] = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //561~564 电芯温度告警状态 1~4个电芯温度告警(*见注释1) } for(int k = 0;k<reserve4.length;k++) { this.reserve4[k] = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //565~589 保留 } //System.out.println(this); return true; } @Override public String toString() { return "Power_LIBMSData [reserve1=" + Arrays.toString(reserve1) + ", mon_cout=" + mon_cout + ", mon_vol=" + Arrays.toString(mon_vol) + ", montemp_cout=" + montemp_cout + ", mon_temp=" + Arrays.toString(mon_temp) + ", envir_temp=" + envir_temp + ", mos_temp=" + mos_temp + ", batt_curr=" + batt_curr + ", batt_totalvol=" + batt_totalvol + ", rest_cap=" + rest_cap + ", total_cap=" + total_cap + ", battcyclecount=" + battcyclecount + ", reserve2=" + reserve2 + ", soc_state=" + soc_state + ", soh_state=" + soh_state + ", reserve3=" + Arrays.toString(reserve3) + ", mon_vol_alm=" + Arrays.toString(mon_vol_alm) + ", mon_tmp_count=" + mon_tmp_count + ", mon_tmp_alm=" + Arrays.toString(mon_tmp_alm) + ", reserve4=" + Arrays.toString(reserve4) + "]"; } } Device_Simulator_DTS_Tester/src/com/dev/simpower/dev/Power_ModelData.java
New file @@ -0,0 +1,74 @@ package com.dev.simpower.dev; import java.nio.ByteBuffer; import java.util.Arrays; import com.dev.bts.data.FBS9100_ComBase; /** * 电源模块信息 * @author DELL * */ public class Power_ModelData { public static final int REG_Count = 31; //电源模块寄存器数量 public int hardware_ver; //1000 硬件版本 public int dcdc_ver; //1001 DCDC版本 public int pfc_ver; //1002 PFC版本 public float outputvol; //1003 输出电压 0.1V public float outputlimitcurr; //1004 实际输出限流点 0.01 public float inputvol; //1005 输入电压 0.1V public float inertemp; //1006 内部温度 0.1℃ public float envirtemp; //1007 进风口环境温度 0.1℃ public float outputcurr; //1008 输出电流 0.1A public int almstate1; //1009 告警状态1 public int almstate2; //1010~1011 告警状态2 public float ratedcurr; //1012 模块额定电流 0.01A public int commst; //1013 通信异常标识 0通信正常,1通信异常 public int reserve[] = new int[17]; //1014~1030 保留 public boolean putByteBuffer(ByteBuffer bbf_rx) { if(bbf_rx.limit() < REG_Count*2) { return false; } this.hardware_ver = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //1000 硬件版本 this.dcdc_ver = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //1001 DCDC版本 this.pfc_ver = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //1002 PFC版本 this.outputvol = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //1003 输出电压 0.1V this.outputlimitcurr = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/100; //1004 实际输出限流点 0.01 this.inputvol = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //1005 输入电压 0.1V this.inertemp = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //1006 内部温度 0.1℃ this.envirtemp = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //1007 进风口环境温度 0.1℃ this.outputcurr = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //1008 输出电流 0.1A this.almstate1 = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //1009 告警状态1 int alm21 = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); int alm22 = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); this.almstate2 = alm21<<16 + alm22;; //1010~1011 告警状态2 this.ratedcurr = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/100; //1012 模块额定电流 0.01A this.commst = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //1013 通信异常标识 0通信正常,1通信异常 for(int k = 0;k<reserve.length;k++) { this.reserve[k] = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //1014~1030 保留 } //System.out.println(this); return true; } @Override public String toString() { return "Power_ModelData [hardware_ver=" + hardware_ver + ", dcdc_ver=" + dcdc_ver + ", pfc_ver=" + pfc_ver + ", outputvol=" + outputvol + ", outputlimitcurr=" + outputlimitcurr + ", inputvol=" + inputvol + ", inertemp=" + inertemp + ", envirtemp=" + envirtemp + ", outputcurr=" + outputcurr + ", almstate1=" + almstate1 + ", almstate2=" + almstate2 + ", ratedcurr=" + ratedcurr + ", commst=" + commst + ", reserve=" + Arrays.toString(reserve) + "]"; } } Device_Simulator_DTS_Tester/src/com/dev/simpower/dev/Power_Param.java
New file @@ -0,0 +1,147 @@ package com.dev.simpower.dev; import java.nio.ByteBuffer; import java.nio.ByteOrder; import com.dev.bts.data.FBS9100_ComBase; public class Power_Param { public static final int REG_Count = 7; //系统参数寄存器数量 public static final int REG_Count_Power = 2; //电源参数寄存器数量 public static final int REG_Count_Time = 6; //电源时间校准寄存器数量 public static final int REG_Count_Regular = 14; //电源定时控制寄存器数量 public static final int Reg_Count_Control = 1; //系统参数寄存器数量 public int dev_comm_addr; //2000 设备通信地址 Modbus设备地址,1~250 public int libms_count; //2001 锂电池包个数 1~4 public int model_count; //2002 电源模块个数 1~4 public float power_downvol; //2003 电池下电电压 0.1V public int back_time; //2004 液晶屏背光时间 Min,15~99 public int charcurr_limit; //2005 充电限流 A public int back_control_en; //2006 备电控制使能 0-禁用备电使能 1-启用备电控制使能 public float output_vol; //2600 电源输出电压设定 0.1V public float output_curr; //2601 电源输出限流点设定 A //读取 public int dev_year; //2800 年 0~100,例:2024年,2024-2000=24 public int dev_month; //2801 月 public int dev_day; //2802 日 public int dev_hour; //2803 ʱ public int dev_minute; //2804 分 public int dev_second; //2805 秒 public boolean putByteBuffer(ByteBuffer bbf_rx) { if(bbf_rx.limit() < REG_Count*2) { return false; } bbf_rx.position(0); this.dev_comm_addr = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //2000 设备通信地址 Modbus设备地址,1~250 this.libms_count = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //2001 锂电池包个数 1~4 this.model_count = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //2002 电源模块个数 1~4 this.power_downvol = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //2003 电池下电电压 0.1V this.back_time = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //2004 液晶屏背光时间 Min,15~99 this.charcurr_limit = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //2005 充电限流 A this.back_control_en = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //2006 备电控制使能 0-禁用备电使能 1-启用备电控制使能 //System.out.println(this); return true; } public boolean putPowerByteBuffer(ByteBuffer bbf_rx) { if(bbf_rx.limit() < REG_Count_Power*2) { return false; } bbf_rx.position(0); this.output_vol = FBS9100_ComBase.changeShortToFloat(bbf_rx.getShort())/10; //2003 电池下电电压 0.1V this.output_curr = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //2004 液晶屏背光时间 Min,15~99 return true; } public boolean putTimeByteBuffer(ByteBuffer bbf_rx) { if(bbf_rx.limit() < REG_Count_Time*2) { return false; } bbf_rx.position(0); this.dev_year = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()) + 2000; //2800 年 0~100,例:2024年,2024-2000=24 this.dev_month = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //2801 月 this.dev_day = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //2802 日 this.dev_hour = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //2803 ʱ this.dev_minute = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //2804 分 this.dev_second = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //2805 秒 return true; } public ByteBuffer getByteBuffer() { ByteBuffer buffer = ByteBuffer.allocate(REG_Count*2); buffer.order(ByteOrder.BIG_ENDIAN); buffer.position(0); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.dev_comm_addr)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.libms_count)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.model_count)); buffer.putShort(FBS9100_ComBase.changeFloatToShort(this.power_downvol*10)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.back_time)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.charcurr_limit)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.back_control_en)); buffer.flip(); return buffer; } public ByteBuffer getPowerByteBuffer() { ByteBuffer buffer = ByteBuffer.allocate(REG_Count_Power*2); buffer.order(ByteOrder.BIG_ENDIAN); buffer.position(0); buffer.putShort(FBS9100_ComBase.changeFloatToShort(this.output_vol*10)); buffer.putShort(FBS9100_ComBase.changeFloatToShort(this.output_curr)); buffer.flip(); return buffer; } public ByteBuffer getTimeByteBuffer() { ByteBuffer buffer = ByteBuffer.allocate(REG_Count_Time*2); buffer.order(ByteOrder.BIG_ENDIAN); buffer.position(0); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.dev_year - 2000)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.dev_month)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.dev_day)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.dev_hour)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.dev_minute)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.dev_second)); buffer.flip(); return buffer; } @Override public String toString() { return "Power_Param [dev_comm_addr=" + dev_comm_addr + ", libms_count=" + libms_count + ", model_count=" + model_count + ", power_downvol=" + power_downvol + ", back_time=" + back_time + ", output_vol=" + output_vol + ", output_curr=" + output_curr + "]"; } } Device_Simulator_DTS_Tester/src/com/dev/simpower/dev/Power_RoadState.java
New file @@ -0,0 +1,45 @@ package com.dev.simpower.dev; import java.nio.ByteBuffer; import java.util.Arrays; import com.dev.bts.data.FBS9100_ComBase; public class Power_RoadState { public static final int REG_Count = 24; public static final int MAX_Road_Count = 12; public int[] sysroadstate; //分路状态 1-打开,0-关闭 public int[] sysroadbackstate; //分路备点状态 1-打开,0-关闭 public int sysgate_st; //门磁状态 public Power_RoadState() { sysroadstate = new int[MAX_Road_Count]; sysroadbackstate = new int[MAX_Road_Count]; } public boolean putByteBuffer(ByteBuffer bbf_rx) { if(bbf_rx.limit() < REG_Count*2) { return false; } bbf_rx.position(0); for(int k = 0;k<sysroadstate.length;k++) { sysroadstate[k] = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); } for(int k = 0;k<sysroadstate.length;k++) { sysroadbackstate[k] = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); } //sysgate_st = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); return true; } @Override public String toString() { return "Power_RoadState [sysroadstate=" + Arrays.toString(sysroadstate) + ", sysroadbackstate=" + Arrays.toString(sysroadbackstate) + ", sysgate_st=" + sysgate_st + "]"; } } Device_Simulator_DTS_Tester/src/com/dev/simpower/dev/Power_TimeControl.java
New file @@ -0,0 +1,186 @@ package com.dev.simpower.dev; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.Arrays; import com.dev.bts.data.FBS9100_ComBase; /** * 极简化电源分时控制参数 * @author DELL * */ public class Power_TimeControl { public static final int REG_Count = 14 * 6; public static final int Total_Load_Count = 12; //总路数 public static final int Total_Load_Count_Sigle = 6; //单次设置路数 public TimeControl[] timeControls = new TimeControl[Total_Load_Count]; public Power_TimeControl() { for(int i = 0;i<timeControls.length;i++) { timeControls[i] = new TimeControl(); } } public boolean putByteBuffer1(ByteBuffer bbf_rx) { if(bbf_rx.limit() < REG_Count * 2) { return false; } bbf_rx.position(0); for(int k = 0;k<Total_Load_Count_Sigle;k++) { timeControls[k].putTimeByteBuffer(bbf_rx); } bbf_rx.compact(); bbf_rx.flip(); return true; } public ByteBuffer getByteBuffer1() { ByteBuffer buffer = ByteBuffer.allocate(REG_Count*2); buffer.order(ByteOrder.BIG_ENDIAN); buffer.position(0); for(int k = 0;k<Total_Load_Count_Sigle;k++) { buffer.put(timeControls[k].getTimeByteBuffer()); } buffer.flip(); return buffer; } public boolean putByteBuffer2(ByteBuffer bbf_rx) { if(bbf_rx.limit() < REG_Count * 2) { return false; } bbf_rx.position(0); for(int k = Total_Load_Count_Sigle;k<timeControls.length;k++) { timeControls[k].putTimeByteBuffer(bbf_rx); } bbf_rx.compact(); bbf_rx.flip(); return true; } public ByteBuffer getByteBuffer2() { ByteBuffer buffer = ByteBuffer.allocate(REG_Count*2); buffer.order(ByteOrder.BIG_ENDIAN); buffer.position(0); for(int k = Total_Load_Count_Sigle;k<timeControls.length;k++) { buffer.put(timeControls[k].getTimeByteBuffer()); } buffer.flip(); return buffer; } public class TimeControl{ public static final int REG_Count = 14; public int time_close_en; //3000 分路1定时关断使能 1:使能定时关断 public int time_close_year; //3001 分路1关断时间—年 0~100,例:2024年,2024-2000=24 public int time_close_month; //3002 分路1关断时间—月 public int time_close_day; //3003 分路1关断时间—日 public int time_close_hour; //3004 分路1关断时间—时 public int time_close_minute; //3005 分路1关断时间—分 public int time_close_second; //3006 分路1关断时间—秒 public int time_repetcomm_en; //3007 分路1定时复通使能 public int time_repetcomm_year; //3008 分路1复通时间—年 0~100,例:2024年,2024-2000=24 public int time_repetcomm_month; //3009 分路1复通时间—月 public int time_repetcomm_day; //3010 分路1复通时间—日 public int time_repetcomm_hour; //3011 分路1复通时间—时 public int time_repetcomm_minute; //3012 分路1复通时间—分 public int time_repetcomm_second; //3013 分路1复通时间—秒 public TimeControl() { } public boolean putTimeByteBuffer(ByteBuffer bbf_rx) { if(bbf_rx.limit() < REG_Count * 2) { return false; } bbf_rx.position(0); this.time_close_en = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); this.time_close_year = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()) + 2000; //2800 年 0~100,例:2024年,2024-2000=24 this.time_close_month = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //2801 月 this.time_close_day = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //2802 日 this.time_close_hour = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //2803 ʱ this.time_close_minute = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //2804 分 this.time_close_second = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //2805 秒 this.time_repetcomm_en = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); this.time_repetcomm_year = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()) + 2000; //2800 年 0~100,例:2024年,2024-2000=24 this.time_repetcomm_month = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //2801 月 this.time_repetcomm_day = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //2802 日 this.time_repetcomm_hour = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //2803 ʱ this.time_repetcomm_minute = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //2804 分 this.time_repetcomm_second = FBS9100_ComBase.changeShortToInt(bbf_rx.getShort()); //2805 秒 bbf_rx.compact(); bbf_rx.flip(); System.err.println(this); return true; } public ByteBuffer getTimeByteBuffer() { ByteBuffer buffer = ByteBuffer.allocate(REG_Count*2); buffer.order(ByteOrder.BIG_ENDIAN); buffer.position(0); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.time_close_en)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.time_close_year - 2000)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.time_close_month)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.time_close_day)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.time_close_hour)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.time_close_minute)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.time_close_second)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.time_repetcomm_en)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.time_repetcomm_year - 2000)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.time_repetcomm_month)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.time_repetcomm_day)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.time_repetcomm_hour)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.time_repetcomm_minute)); buffer.putShort(FBS9100_ComBase.changeIntToShort(this.time_repetcomm_second)); buffer.flip(); return buffer; } @Override public String toString() { return "TimeControl [time_close_en=" + time_close_en + ", time_close_year=" + time_close_year + ", time_close_month=" + time_close_month + ", time_close_day=" + time_close_day + ", time_close_hour=" + time_close_hour + ", time_close_minute=" + time_close_minute + ", time_close_second=" + time_close_second + ", time_repetcomm_en=" + time_repetcomm_en + ", time_repetcomm_year=" + time_repetcomm_year + ", time_repetcomm_month=" + time_repetcomm_month + ", time_repetcomm_day=" + time_repetcomm_day + ", time_repetcomm_hour=" + time_repetcomm_hour + ", time_repetcomm_minute=" + time_repetcomm_minute + ", time_repetcomm_second=" + time_repetcomm_second + "]"; } } @Override public String toString() { return "Power_TimeControl [timeControls=" + Arrays.toString(timeControls) + "]"; } } Device_Simulator_DTS_Tester/src/com/dev/simpower/power_page_base.java
New file Diff too large Device_Simulator_DTS_Tester/src/com/dev/simpower/power_util.java
New file @@ -0,0 +1,69 @@ package com.dev.simpower; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; import java.util.List; import com.dev.bts.data.FBS9100_ComBase; import com.dev.simpower.dev.Power_ComBase; public class power_util { /** * 构造电源告警名称数组 * @return */ public static List<String> createPowerAlmName() { List<String> power_almname = new ArrayList<>(); power_almname.add("交流停电告警"); power_almname.add("门禁开启告警"); power_almname.add("水浸告警"); power_almname.add("防雷器告警"); power_almname.add("锂电池BMS通信异常告警"); power_almname.add("电源模块通信异常告警"); power_almname.add("交流输入告警"); power_almname.add("组端电压告警"); for(int n = 0;n<Power_ComBase.LIBMSDATA_MAX_COUNT;n++) { for(int k = 0;k<Power_ComBase.MON_MAX_COUNT;k++) { power_almname.add("锂电池包"+(n+1)+"=>#"+(k+1)+"单体电压告警"); } } power_almname.add("电池放电电流大告警"); power_almname.add("电池充电电流大告警"); power_almname.add("直流输出电流大告警"); power_almname.add("设备温度高告警"); return power_almname; } public static ByteBuffer createControlByteBuffer(boolean control) { ByteBuffer buffer = ByteBuffer.allocate(2); buffer.order(ByteOrder.BIG_ENDIAN); buffer.position(0); buffer.putShort(FBS9100_ComBase.changeIntToShort(control?1:0)); buffer.flip(); return buffer; } public static ByteBuffer createSysUpdateControlByteBuffer(int control) { ByteBuffer buffer = ByteBuffer.allocate(2); buffer.order(ByteOrder.BIG_ENDIAN); buffer.position(0); buffer.putShort(FBS9100_ComBase.changeIntToShort(control)); buffer.flip(); return buffer; } // public static void main(String[] args) { // System.out.println(createPowerAlmName()); // System.out.println(createPowerAlmName().size()); // } } Device_Simulator_DTS_Tester/src/com/ueky/ukeycfg_page_base.java
@@ -112,7 +112,7 @@ //调试信息 panel_debug = new page_debug_inf(); // tabbedPane.addTab("\u8C03\u8BD5\u4FE1\u606F",null, panel_debug, null); tabbedPane.addTab("\u8C03\u8BD5\u4FE1\u606F", new ImageIcon(bts4810_page_base.class.getResource("/png_32x32/debuglog.png")), panel_debug, null); // tabbedPane.addTab("\u8C03\u8BD5\u4FE1\u606F", new ImageIcon(bts4810_page_base.class.getResource("/png_32x32/debuglog.png")), panel_debug, null); Device_Simulator_DTS_Tester/src/icon/61850_ide.png
Device_Simulator_DTS_Tester/src/icon/dis_bts.png
Device_Simulator_DTS_Tester/src/icon/group_model.png
Device_Simulator_DTS_Tester/src/icon/mon_ied.png
Device_Simulator_DTS_Tester/src/icon/ukey_ide.png
Device_Simulator_DTS_Tester/src/main/main_window_computer.java
@@ -59,6 +59,7 @@ import com.dev.fbs9600_zdhj.zdhj_page_base; import com.dev.nrf_lora_tester.loratester_page_base; import com.dev.ntm.ntm_page_base; import com.dev.simpower.power_page_base; import com.dev.switchdev.SwitchDevice_page_base; import com.ueky.ukeycfg_page_base; @@ -97,6 +98,7 @@ public static int CommDevType_DummyLoad = -1; //12 假负载 public static int CommDevType_IEC61850 = -1; //13 IEC61850 public static int CommDevType_UKEY = -1; //14 UKEY public static int CommDevType_SIMPOWER = -1; //15 极简化电源 public static final int CommDevType_MAX = 17; @@ -126,8 +128,9 @@ public static final boolean APP_DummyLoad_EN = false; //假负载 public static final boolean APP_IEC61850_EN = true; //IEC61850 public static final boolean APP_UKEY_EN = true; //UKEY public static final boolean APP_SIMPOWER_EN = true; //极简化电源 public int CommDevType = 2; //默认显示tab选项卡 public int CommDevType = 5; //默认显示tab选项卡 public static final int DebugMode_TYPE_Debug = 0; //调试模拟 public static final int DebugMode_TYPE_Package = 1; //电脑打包模式 @@ -171,6 +174,7 @@ private JPanel main_TabbedTopPane12; private JPanel main_TabbedTopPane13; private JPanel main_TabbedTopPane14; private JPanel main_TabbedTopPane15; private JPanel main_TabbedRightPane0; private JPanel main_TabbedRightPane1; @@ -187,6 +191,7 @@ private JPanel main_TabbedRightPane12; private JPanel main_TabbedRightPane13; private JPanel main_TabbedRightPane14; private JPanel main_TabbedRightPane15; private JButton btn_renew_commport; @@ -223,6 +228,8 @@ private DummyLoad_page_base panel_dummyload_base; // private iec61850_page_base panel_iec61850_base; // private ukeycfg_page_base panel_ueky_page_base; private power_page_base panel_power_page_base; //极简化电源 private List<JPanel> pre_panels = new ArrayList<>(); //前置面板空白面板 @@ -305,7 +312,8 @@ frmSerialport.setFont(new Font("宋体", Font.PLAIN, 12)); //frmSerialport.setResizable(false); frmSerialport.setIconImage(Toolkit.getDefaultToolkit().getImage(main_window_computer.class.getResource("/main/fuguang.png"))); //frmSerialport.setIconImage(Toolkit.getDefaultToolkit().getImage(main_window_computer.class.getResource("/main/fuguang.png"))); frmSerialport.setIconImage(Toolkit.getDefaultToolkit().getImage(main_window_computer.class.getResource("/main/12164006.png"))); frmSerialport.setBounds(100, 100, 1180, 640); frmSerialport.setMinimumSize(new Dimension(1160, 640)); //frmSerialport.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); @@ -319,7 +327,7 @@ //前置界面 pre_panel = new JPanel(); pre_panel.setLayout(new GridLayout(0, 4, 20, 20)); pre_panel.setLayout(new GridLayout(0,4, 20, 20)); //设置边框宽度 pre_panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); @@ -356,7 +364,8 @@ JButton btn_mon = new JButton(new ImageIcon(main_window_computer.class.getResource("/png_32x32/batt_mon.png"))); btn_mon.setText("单体模块调试工具"); //JButton btn_mon = new JButton(new ImageIcon(main_window_computer.class.getResource("/icon/mon_ied.png"))); btn_mon.setText("单体模块"); setButtonType(btn_mon); btn_mon.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { @@ -382,7 +391,7 @@ JButton btn_curr = new JButton(new ImageIcon(main_window_computer.class.getResource("/png_32x32/curr_model.png"))); btn_curr.setText("电流模块调试工具"); btn_curr.setText("电流模块"); setButtonType(btn_curr); btn_curr.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { @@ -405,7 +414,7 @@ }); JButton btn_groupvol = new JButton(new ImageIcon(main_window_computer.class.getResource("/png_32x32/groupvol.png"))); btn_groupvol.setText("组压模块调试工具"); btn_groupvol.setText("组压模块"); setButtonType(btn_groupvol); btn_groupvol.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { @@ -429,7 +438,7 @@ JButton btn_fcf651vol = new JButton(new ImageIcon(main_window_computer.class.getResource("/png_32x32/groupvol1.png"))); btn_fcf651vol.setText("FCF组压调试工具"); btn_fcf651vol.setText("FCF组压"); setButtonType(btn_fcf651vol); btn_fcf651vol.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { @@ -452,7 +461,7 @@ }); JButton btn_zdhj = new JButton(new ImageIcon(main_window_computer.class.getResource("/png_32x32/zdhj_mon.png"))); btn_zdhj.setText("汇集模块调试工具"); btn_zdhj.setText("组端汇集模块"); setButtonType(btn_zdhj); btn_zdhj.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { @@ -466,7 +475,7 @@ setJTableSelectIndex(CommDevType_ZDHJ); mTitle = "汇集模块调试工具"; mTitle = "组端汇集模块调试工具"; frmSerialport.setTitle(mTitle+ mVerSioin + " " + Com.get_DTF(new Date(), Com.DTF_YMDhms)); frmSerialport.getContentPane().revalidate(); // 重新验证布局 @@ -476,7 +485,7 @@ }); JButton btn_fbs9100 = new JButton(new ImageIcon(main_window_computer.class.getResource("/png_32x32/control.png"))); btn_fbs9100.setText("BTS主控调试工具"); btn_fbs9100.setText("BTS主控"); setButtonType(btn_fbs9100); btn_fbs9100.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { @@ -499,7 +508,7 @@ }); JButton btn_ntm = new JButton(new ImageIcon(main_window_computer.class.getResource("/png_32x32/dis_ele.png"))); btn_ntm.setText("NTM放电仪调试工具"); btn_ntm.setText("NTM放电仪"); setButtonType(btn_ntm); btn_ntm.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { @@ -523,7 +532,7 @@ JButton btn_lora = new JButton(new ImageIcon(main_window_computer.class.getResource("/png_32x32/mcs_lora_on.png"))); btn_lora.setText("Lora测试调试工具"); btn_lora.setText("Lora测试"); setButtonType(btn_lora); btn_lora.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { @@ -547,7 +556,7 @@ JButton btn_bybb = new JButton(new ImageIcon(main_window_computer.class.getResource("/png_32x32/board_main.png"))); btn_bybb.setText("BYBB测试调试工具"); btn_bybb.setText("BYBB测试"); setButtonType(btn_bybb); btn_bybb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { @@ -571,7 +580,7 @@ JButton btn_fbo4830 = new JButton(new ImageIcon(main_window_computer.class.getResource("/png_32x32/dis_instrument.png"))); btn_fbo4830.setText("FBO4830调试工具"); btn_fbo4830.setText("FBO4830"); setButtonType(btn_fbo4830); btn_fbo4830.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { @@ -594,7 +603,7 @@ }); JButton btn_bts4810 = new JButton(new ImageIcon(main_window_computer.class.getResource("/png_32x32/dis_instrument1.png"))); btn_bts4810.setText("BTS4810调试工具"); btn_bts4810.setText("核容主机"); setButtonType(btn_bts4810); btn_bts4810.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { @@ -608,7 +617,7 @@ System.out.println("CommDevType_BTS4810:"+CommDevType_BTS4810+"\tmain_TabbedPane.getTabCount():"+main_TabbedPane.getTabCount()); setJTableSelectIndex(CommDevType_BTS4810); mTitle = "BTS4810调试工具"; mTitle = "核容主机调试工具"; frmSerialport.setTitle(mTitle+ mVerSioin + " " + Com.get_DTF(new Date(), Com.DTF_YMDhms)); frmSerialport.getContentPane().revalidate(); // 重新验证布局 @@ -619,7 +628,7 @@ JButton btn_switch= new JButton(new ImageIcon(main_window_computer.class.getResource("/png_32x32/change_instrument.png"))); btn_switch.setText("切换装置调试工具"); btn_switch.setText("切换装置"); setButtonType(btn_switch); btn_switch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { @@ -642,7 +651,7 @@ }); JButton btn_load= new JButton(new ImageIcon(main_window_computer.class.getResource("/png_32x32/dummy_load.png"))); btn_load.setText("假负载装置调试工具"); btn_load.setText("假负载装置"); setButtonType(btn_load); btn_load.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { @@ -665,7 +674,7 @@ }); JButton btn_iec61850= new JButton(new ImageIcon(main_window_computer.class.getResource("/png_32x32/61850_logo.png"))); btn_iec61850.setText("IEC61850调试工具"); btn_iec61850.setText("61850Эת"); setButtonType(btn_iec61850); btn_iec61850.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { @@ -681,7 +690,7 @@ setJTableSelectIndex(CommDevType_IEC61850); mTitle = "IEC61850调试工具"; mTitle = "61850协转调试工具"; frmSerialport.setTitle(mTitle+ mVerSioin + " " + Com.get_DTF(new Date(), Com.DTF_YMDhms)); frmSerialport.getContentPane().revalidate(); // 重新验证布局 @@ -692,7 +701,7 @@ JButton btn_ukey= new JButton(new ImageIcon(main_window_computer.class.getResource("/png_32x32/ukey_logo.png"))); btn_ukey.setText("UKEY调试工具"); btn_ukey.setText("UKEY"); setButtonType(btn_ukey); btn_ukey.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { @@ -765,6 +774,8 @@ main_TabbedTopPane13.setLayout(new BoxLayout(main_TabbedTopPane13, BoxLayout.X_AXIS)); main_TabbedTopPane14 = new JPanel(); main_TabbedTopPane14.setLayout(new BoxLayout(main_TabbedTopPane14, BoxLayout.X_AXIS)); main_TabbedTopPane15 = new JPanel(); main_TabbedTopPane15.setLayout(new BoxLayout(main_TabbedTopPane15, BoxLayout.X_AXIS)); main_TabbedRightPane0 = new JPanel(); @@ -797,6 +808,8 @@ main_TabbedRightPane13.setLayout(new BorderLayout()); main_TabbedRightPane14 = new JPanel(); main_TabbedRightPane14.setLayout(new BorderLayout()); main_TabbedRightPane15 = new JPanel(); main_TabbedRightPane15.setLayout(new BorderLayout()); top_panel1 = new JPanel(); top_panel1.setLayout(new BoxLayout(top_panel1, BoxLayout.X_AXIS)); @@ -994,8 +1007,12 @@ //使用table选中的列表 int main_DevType = main_TabbedPane.getSelectedIndex(); //int main_DevType = CommDevType; boolean comm_open_res = true; System.err.println("main_DevType:"+main_DevType); if(DebugMode == DebugMode_TYPE_Package) { main_DevType = CommDevType; } boolean comm_open_res = true; //System.err.println("main_DevType:"+main_DevType); int monomer_devType = cb_dev_type.getSelectedIndex(); if(main_window_computer.CommDevType_MON == main_DevType) { int comm_multy_type = CommSerialPort.mutycomm_Type_Samd09; @@ -1075,7 +1092,18 @@ int tcp_type = cb_tcp_udp.getSelectedIndex(); System.out.println("tcp_type:" + tcp_type); } } } else if(main_window_computer.CommDevType_SIMPOWER == main_DevType) { if(SPCommMon.COMM_PORT_TYPE_Serial == comm_type) { //串口通信 int dev_addr = Integer.parseInt(tf_target_addr.getText().trim()); comm_open_res = panel_power_page_base.openCommPort(comm_type, spname_or_ipaddr, bitrate_or_ipport, dev_addr, m_Log); }else if(SPCommMon.COMM_PORT_TYPE_Socket == comm_type){ //客户端通信 int tcp_type = cb_tcp_udp.getSelectedIndex(); System.out.println("tcp_type:" + tcp_type); } } if(true == comm_open_res) { CommDevType = main_DevType; @@ -1160,6 +1188,9 @@ if(null != panel_dummyload_base) { panel_dummyload_base.closeCommPort(); } if(null != panel_power_page_base) { panel_power_page_base.closeCommPort(); } tf_target_addr.setEditable(true); btn_renew_commport.setEnabled(true); @@ -1218,16 +1249,18 @@ main_TabbedPane.setFont(new Font("宋体", Font.PLAIN, 20)); main_TabbedPane.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent arg0) { System.out.println("监听到软件切换:" + main_TabbedPane.getSelectedIndex() + " CommDevType:" + CommDevType); if(DebugMode_TYPE_Screen == DebugMode) { //显示屏模式时会出现头部组件小时问题,提前结束 if (DebugMode_TYPE_Screen == DebugMode || DebugMode_TYPE_Package == DebugMode ) { //显示屏模式时会出现头部组件消失问题,提前结束 return; } int tab_index = main_TabbedPane.getSelectedIndex(); System.out.println("tab_index:"+tab_index); if(tab_index >=0 && tab_index < tabbedTopPanes.size()) { JPanel topPanel = tabbedTopPanes.get(tab_index); //System.out.println("topPanel:"+topPanel); if(topPanel != null) { topPanel.removeAll(); topPanel.add(top_panel1); @@ -1724,6 +1757,39 @@ pre_panels.add(new JPanel()); } if(APP_SIMPOWER_EN) { CommDevType_SIMPOWER = jtable_index++; String bybb_title = "极简化电源"; panel_power_page_base = new power_page_base(); if(DebugMode == DebugMode_TYPE_Screen) { main_TabbedPane.add(bybb_title, new JPanel()); }else { main_TabbedPane.add(bybb_title, main_TabbedRightPane15); // main_TabbedPane.add(bybb_title, panel_dummyload_base); main_TabbedPane.setIconAt(CommDevType_SIMPOWER, new ImageIcon(main_window_computer.class.getResource("/png_16x16/layer_treansparent.png"))); } main_TabbedRightPane15.add(main_TabbedTopPane15,BorderLayout.NORTH); main_TabbedRightPane15.add(panel_power_page_base,BorderLayout.CENTER); tabbedTopPanes.add(main_TabbedTopPane15); tabbedRightPanes.add(main_TabbedRightPane15); if(CommDevType == CommDevType_SIMPOWER) { //当默认是极简化电源时 cb_comm_bitrate.setSelectedIndex(2); //默认波特率9600 tf_target_addr.setText("1"); //默认设备地址1 } }else { pre_panels.add(new JPanel()); } if(pre_panels.size() > 0) { for (JPanel jPanel : pre_panels) { pre_panel.add(jPanel); @@ -1735,31 +1801,43 @@ main_TabbedPane.setEnabled(false); } /**************************************************************************/ System.out.println("$$$$$$$$$$$"+CommDevType); //打包模式判断选项--隐藏左侧选卡并设置调试软件名称 if(CommDevType >= CommDevType_MON && CommDevType <= CommDevType_MAX) { //System.out.println("CommDevType$$$$$$$$$$$--"+CommDevType); //选中默认选项卡 main_TabbedPane.setSelectedIndex(CommDevType); int tab_index = main_TabbedPane.getSelectedIndex(); //System.out.println("222:"+main_TabbedPane.getSelectedIndex()+"\tCommDevType"+CommDevType); if(DebugMode == DebugMode_TYPE_Package) { //System.out.println("tab_index$$$$$$$$$$$--"+tab_index); if(DebugMode == DebugMode_TYPE_Package) { //打包模式时 会出现 main_TabbedPane.getSelectedIndex 与 CommDevType 不一致 tab_index = CommDevType; //移除返回按钮 top_panel1.remove(panel_10); main_TabbedPane.setVisible(false); JPanel topPanel = tabbedTopPanes.get(tab_index); JPanel rightPanel = tabbedRightPanes.get(tab_index); //System.out.println(main_TabbedTopPane0+"==="+topPanel + "=="+ rightPanel); //System.err.println(main_TabbedTopPane0+"==="+topPanel + "=="+ rightPanel); if(topPanel != null && rightPanel != null) { frmSerialport.getContentPane().removeAll(); //System.out.println("333:"+main_TabbedPane.getSelectedIndex()+"\tCommDevType"+CommDevType); frmSerialport.getContentPane().add(topPanel, BorderLayout.NORTH); frmSerialport.getContentPane().add(rightPanel, BorderLayout.CENTER); frmSerialport.setMinimumSize(new Dimension(1030, 640)); //System.out.println("222:"+main_TabbedPane.getSelectedIndex()+"\tCommDevType"+CommDevType); } if(CommDevType_MON == CommDevType){ //frmSerialport.getContentPane().add(panel_mon_base, BorderLayout.CENTER); @@ -1801,14 +1879,29 @@ //frmSerialport.getContentPane().add(panel_dummyload_base, BorderLayout.CENTER); }else if(CommDevType_UKEY == CommDevType) { mTitle = "UKEY调试工具"; }else if(CommDevType_SIMPOWER == CommDevType) { mTitle = "极简化电源调试工具"; //System.out.println("头部容器:"+top_panel1.getParent()); //极简化电源 cb_comm_bitrate.setSelectedIndex(2); frmSerialport.getContentPane().add(top_panel1, BorderLayout.NORTH); }else if(CommDevType_IEC61850 == CommDevType) { frmSerialport.getContentPane().remove(topPanel); } } else if(DebugMode == DebugMode_TYPE_Screen){ //btn_back = null; frmSerialport.getContentPane().removeAll(); frmSerialport.getContentPane().add(pre_panel); } else { System.err.println("调试模式中...."); top_panel1.remove(panel_10); } } //System.out.println("444:"+main_TabbedPane.getSelectedIndex()+"\tCommDevType"+CommDevType); frmSerialport.setTitle(mTitle+ mVerSioin + " " + Com.get_DTF(new Date(), Com.DTF_YMDhms)); @@ -1816,7 +1909,6 @@ frmSerialport.setTitle(this.mTitle + "_EN" + " " + Com.get_DTF(new Date(), Com.DTF_YMDhms)); } //System.out.println("333:"+main_TabbedPane.getSelectedIndex()); /**************************************************************************/ mMainFormTimer = new Timer(200, new ActionListener() { @Override @@ -1824,6 +1916,8 @@ updateData(); } }); /**************************************************************************/ } @@ -1838,6 +1932,10 @@ frmSerialport.setTitle(mTitle+ mVerSioin + " " + Com.get_DTF(new Date(), Com.DTF_YMDhms)); int main_DevType = main_TabbedPane.getSelectedIndex(); if(DebugMode == DebugMode_TYPE_Package) { main_DevType = CommDevType; } if(CommDevType_MON == main_DevType) { tf_txcnt.setText(String.format("TX:%d", panel_mon_base.Comm_Mon.comm_tx_cnt)); tf_rxcnt.setText(String.format("RX:%d", panel_mon_base.Comm_Mon.comm_rx_cnt)); @@ -1868,43 +1966,48 @@ tf_rxcnt.setText(String.format("RX:%d", panel_FBS9100_base.Comm_BTS.comm_rx_cnt)); panel_FBS9100_base.updateData(); } if(CommDevType_NTM == main_DevType) { } else if(CommDevType_NTM == main_DevType) { tf_txcnt.setText(String.format("TX:%d", panel_NTM_base.Comm_NTM.comm_tx_cnt)); tf_rxcnt.setText(String.format("RX:%d", panel_NTM_base.Comm_NTM.comm_rx_cnt)); panel_NTM_base.updateData(); } if(CommDevType_LoraTest == main_DevType) { } else if(CommDevType_LoraTest == main_DevType) { tf_txcnt.setText(String.format("TX:%d", panel_LoraTest_base.Comm_LoraTester.comm_tx_cnt)); tf_rxcnt.setText(String.format("RX:%d", panel_LoraTest_base.Comm_LoraTester.comm_rx_cnt)); panel_LoraTest_base.updateData(); } if(CommDevType_BYBB == main_DevType) { } else if(CommDevType_BYBB == main_DevType) { tf_txcnt.setText(String.format("TX:%d", panel_bybb_base.Comm_BYBB.comm_tx_cnt)); tf_rxcnt.setText(String.format("RX:%d", panel_bybb_base.Comm_BYBB.comm_rx_cnt)); panel_bybb_base.updateData(); } if(CommDevType_BTS4810 == main_DevType) { } else if(CommDevType_BTS4810 == main_DevType) { tf_txcnt.setText(String.format("TX:%d", panel_bts4810_base.Comm_BTS4810.comm_tx_cnt)); tf_rxcnt.setText(String.format("RX:%d", panel_bts4810_base.Comm_BTS4810.comm_rx_cnt)); panel_bts4810_base.updateData(); } if(CommDevType_SwitchDevice == main_DevType) { } else if(CommDevType_SwitchDevice == main_DevType) { tf_txcnt.setText(String.format("TX:%d", panel_switchdevice_base.Comm_Swit.comm_tx_cnt)); tf_rxcnt.setText(String.format("RX:%d", panel_switchdevice_base.Comm_Swit.comm_rx_cnt)); panel_switchdevice_base.updateData(); } if(CommDevType_DummyLoad == main_DevType) { } else if(CommDevType_DummyLoad == main_DevType) { tf_txcnt.setText(String.format("TX:%d", panel_dummyload_base.Comm_Swit.comm_tx_cnt)); tf_rxcnt.setText(String.format("RX:%d", panel_dummyload_base.Comm_Swit.comm_rx_cnt)); panel_dummyload_base.updateData(); } if(CommDevType_UKEY == main_DevType) { } else if(CommDevType_UKEY == main_DevType) { tf_txcnt.setText(String.format("TX:%d", panel_ueky_page_base.Comm_ukey.comm_tx_cnt)); tf_rxcnt.setText(String.format("RX:%d", panel_ueky_page_base.Comm_ukey.comm_rx_cnt)); panel_ueky_page_base.updateData(); } } else if(CommDevType_SIMPOWER == main_DevType) { tf_txcnt.setText(String.format("TX:%d", panel_power_page_base.Comm_POWER.comm_tx_cnt)); tf_rxcnt.setText(String.format("RX:%d", panel_power_page_base.Comm_POWER.comm_rx_cnt)); panel_power_page_base.updateData(); } } catch (Exception e) { m_Log.error(e.toString(), e); } @@ -1921,6 +2024,7 @@ } public void setJTableSelectIndex(int jt_index) { System.out.println("###########################"); if(jt_index < main_TabbedPane.getTabCount() && jt_index >= 0) { main_TabbedPane.setSelectedIndex(jt_index); } Device_Simulator_DTS_Tester/src/user_app_form/MySch_Util.java
New file @@ -0,0 +1,286 @@ package user_app_form; import java.util.Map; import com.jcraft.jsch.ChannelExec; import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.ChannelShell; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; public class MySch_Util { public static final int Connect_Status_Error = 0; //连接异常 public static final int Connect_Status_OK = 1; //连接正常 private String hostName; private String port; private String userName; private String passWord; private static String CPUMESSAGE = "cat /proc/cpuinfo | grep name | cut -f2 -d: |uniq -c"; private static String CPUCOMMAND = "vmstat|awk 'NR==3''{print $13, $14, $16, $15}'"; private static String MEMCOMMAND = "cat /proc/meminfo |grep 'MemTotal\\|MemFree'|awk '{print $2}'"; private static String DISKCOMMAND = "df -h|grep -v Filesystem"; private static String ENCODESET = "export LC_CTYPE=zh_CN.UTF-8;"; private static Map<String, String> CONMANDMAP = new HashMap<String, String>(){ { put("CPUMESSAGE",CPUMESSAGE); put("CPUCOMMAND",CPUCOMMAND); put("MEMCOMMAND",MEMCOMMAND); put("DISKCOMMAND",DISKCOMMAND); } }; public MySch_Util(String hostName,String port, String userName, String passWord) { this.hostName = hostName; this.port = port; this.userName = userName; this.passWord = passWord; } /** * 服务器连接状态检查(1:正常 0:异常) * @return */ public int serverCheck() { int status = 1; JSch jSch = new JSch(); try{ jSch.getSession(userName,hostName,Integer.parseInt(port)); }catch (Exception e) { status = 0; e.printStackTrace(); } return status; } /** * session检测 * @return * @throws JSchException */ public Session getSession() throws JSchException { JSch jSch = new JSch(); Session session = jSch.getSession(userName, hostName, Integer.parseInt(port)); session.setPassword(passWord); session.setConfig("StrictHostKeyChecking", "no"); session.connect(); return session; } /** * 获取CPU使用情况 * @return */ public Map<String, String> getCpuUsage() throws JSchException { Map<String, String> map = new HashMap<>(); List<String> result = executeCommand(CPUCOMMAND); if(result != null && result.size() > 0){ String[] cpuInfo = result.get(0).split(" "); map.put("用户CPU时间",cpuInfo[0]); map.put("系统CPU时间",cpuInfo[1]); map.put("等待IO CPU时间",cpuInfo[2]); map.put("空闲CPU时间",cpuInfo[3]); double others = 100.00-Double.parseDouble(cpuInfo[0])-Double.parseDouble(cpuInfo[1])- Double.parseDouble(cpuInfo[2])-Double.parseDouble(cpuInfo[3]); DecimalFormat df = new DecimalFormat("0.0"); map.put("其他时间",df.format(others)); }else{ map.put("用户CPU时间","0"); map.put("系统CPU时间","0"); map.put("等待IO CPU时间","0"); map.put("空闲CPU时间","0"); map.put("其他时间","0"); } return map; } public List<String> executeCommand(String command) throws JSchException { Session session = getSession(); ChannelExec channel = null; List<String> resultLines = new ArrayList<>(); InputStream input = null; try { channel = (ChannelExec) session.openChannel("exec"); channel.setCommand(ENCODESET+command); input = channel.getInputStream(); channel.connect(); BufferedReader inputReader = new BufferedReader(new InputStreamReader(input)); String inputLine = null; resultLines.add(command); while ((inputLine = inputReader.readLine()) != null) { //System.out.println(inputLine); resultLines.add(inputLine); } } catch (IOException e) { e.printStackTrace(); } finally { if (input != null) { try { input.close(); } catch (Exception e) { e.printStackTrace(); } } if (channel != null) { try { channel.disconnect(); } catch (Exception e) { e.printStackTrace(); } } } return resultLines; } public List<String> uploadFile(byte[] sourcefile,String dstfilepath) { List<String> resultLines = new ArrayList<>(); try { Session session = getSession(); ChannelShell openChannelShell = openChannelShell(session); openChannelShell.setInputStream(System.in); openChannelShell.setOutputStream(System.out); ChannelSftp openChannelSftp = openChannelSftp(session); ByteArrayInputStream inputStream = new ByteArrayInputStream(sourcefile); openChannelSftp.put(inputStream, dstfilepath, ChannelSftp.OVERWRITE); //删除文件可用如下方法,进入某文件所在的目录后删除该文件 //openChannelSftp.cd(dstfilepath); //openChannelSftp.rm(sourcefile); //System.out.println(openChannelShell.getOutputStream()); } catch (Exception e) { e.printStackTrace(); resultLines.add("transmits file error: There was a problem while connecting to " + hostName + ":" + port); } return resultLines; } /** * 连接shell * * @param session * session * @return {@link ChannelShell} */ private static ChannelShell openChannelShell(Session session) { ChannelShell channel = null; try { channel = (ChannelShell) session.openChannel("shell"); channel.setEnv("LANG", "en_US.UTF-8"); channel.setAgentForwarding(false); channel.setPtySize(500, 500, 1000, 1000); channel.connect(); } catch (Exception e) { e.printStackTrace(); } if (channel == null) { throw new IllegalArgumentException("The channle init was wrong"); } return channel; } /** * 连接sftp * * @param session * @return {@link ChannelSftp} */ private static ChannelSftp openChannelSftp(Session session) { ChannelSftp channel = null; try { channel = (ChannelSftp) session.openChannel("sftp"); channel.connect(); } catch (Exception e) { e.printStackTrace(); } return channel; } /** * 根据配置执行命令并返回结果 * @return */ public Map<String,Object> executeCommand() throws JSchException { Session session = getSession(); ChannelExec channel = null; Map<String,Object> commandResult = new HashMap<String, Object>(); DecimalFormat df = new DecimalFormat("0.00"); try { for (String key : CONMANDMAP.keySet()) { String command = CONMANDMAP.get(key); channel = (ChannelExec) session.openChannel("exec"); channel.setCommand(ENCODESET+command); channel.connect(); InputStream input = channel.getInputStream(); BufferedReader inputReader = new BufferedReader(new InputStreamReader(input)); String inputLine = null; List<String> results = new ArrayList<String>(); Map<String, String> temp = new HashMap<String, String>(); while ((inputLine = inputReader.readLine())!=null){ results.add(inputLine); } if("CPUCOMMAND".equals(key)){ if(results.size() > 0){ String[] cpuInfo = results.get(0).split(" "); temp.put("用户CPU时间",cpuInfo[0]); temp.put("系统CPU时间",cpuInfo[1]); temp.put("等待IO CPU时间",cpuInfo[2]); temp.put("空闲CPU时间",cpuInfo[3]); }else{ temp.put("用户CPU时间","0"); temp.put("系统CPU时间","0"); temp.put("等待IO CPU时间","0"); temp.put("空闲CPU时间","0"); } commandResult.put(key,temp); }else if("MEMCOMMAND".equals(key)){ if(results.size() > 0){ double memTotal = Double.parseDouble(results.get(0))/1024/1024; double memFree = Double.parseDouble(results.get(1))/1024/1024; double memUsed = memTotal-memFree; temp.put("总内存",df.format(memTotal)+"G"); temp.put("已使用",df.format(memUsed)+"G"); temp.put("空闲",df.format(memFree)+"G"); }else{ temp.put("总内存","0"); temp.put("已使用","0"); temp.put("空闲","0"); } commandResult.put(key,temp); }else { commandResult.put(key,results); } input.close(); } } catch (Exception e) { e.printStackTrace(); } finally { if (channel != null) { try { channel.disconnect(); } catch (Exception e) { e.printStackTrace(); } } } return commandResult; } } Device_Simulator_DTS_Tester/src/user_app_form/pscp_util.java
@@ -2,11 +2,14 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.swing.JButton; public class pscp_util implements Runnable { public static final String SSH_Port = "22"; private String m_host; private String m_log_name; private String m_pwd; @@ -29,35 +32,66 @@ private void update_ta_line(String line) { m_ta.add(line + "\n"); } private void update_ta_line(List<String> line) { for (String string : line) { m_ta.add(string + "\n"); } } @Override public void run() { // TODO Auto-generated method stub update_ta_line("start app file transmits to " + m_host); ssh2_util ssh2 = new ssh2_util(); MySch_Util ssh2 = new MySch_Util(m_host,SSH_Port, m_log_name, m_pwd); try { String res = ssh2.connectLinux(m_host, m_log_name, m_pwd, "rm -rf /app/zjdy"); update_ta_line(res); res = ssh2.scpPut(m_host, m_log_name, m_pwd, m_filedata, "zjdy", "/app"); update_ta_line(res); List<String> line = ssh2.executeCommand("rm -rf /app/zjdy"); update_ta_line(line); res = ssh2.connectLinux(m_host, m_log_name, m_pwd, "chmod 777 /app/zjdy"); update_ta_line(res); line = ssh2.uploadFile(m_filedata ,"/app/zjdy"); update_ta_line(line); res = ssh2.connectLinux(m_host, m_log_name, m_pwd, "ls -l /app/zjdy"); update_ta_line(res); line = ssh2.executeCommand("chmod 777 /app/zjdy"); update_ta_line(line); line = ssh2.executeCommand("ls -l /app/zjdy"); update_ta_line(line); update_ta_line("transmits app file done!\n"); } catch (IOException e) { } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); update_ta_line("transmits file error: " + e.getMessage()); } finally { m_btn.setEnabled(true); } // update_ta_line("start app file transmits to " + m_host); // // ssh2_util ssh2 = new ssh2_util(); // try { // String res = ssh2.connectLinux(m_host, m_log_name, m_pwd, "rm -rf /app/zjdy"); // update_ta_line(res); // // res = ssh2.scpPut(m_host, m_log_name, m_pwd, m_filedata, "zjdy", "/app"); // update_ta_line(res); // // res = ssh2.connectLinux(m_host, m_log_name, m_pwd, "chmod 777 /app/zjdy"); // update_ta_line(res); // // res = ssh2.connectLinux(m_host, m_log_name, m_pwd, "ls -l /app/zjdy"); // update_ta_line(res); // // update_ta_line("transmits app file done!\n"); // } catch (IOException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // update_ta_line("transmits file error: " + e.getMessage()); // } finally { // m_btn.setEnabled(true); // } } public void stop_ping() {