package com.dev.bybb; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.ArrayList; public class BYBB_Data { private final int BYTE_ETH_DATA_LEN = 66*4 + 2; private final int BYTE_ETH_STAT_LEN = 56; int DC_AnDian_Vol_1; int DC_AnDian_Curr_1; int DC_AnDian_Vol_2; int DC_AnDian_Curr_2; int Batt_GroupVol_1; int Batt_GroupCurr_1; int Batt_GroupVol_2; int Batt_GroupCurr_2; int QiFa_Vol_1; int QiFa_Curr_1; int QiFa_Vol_2; int QiFa_Curr_2; int DianJi_Speed; int DianJi_Power; int NiBian_Power1_VolAB; int NiBian_Power1_VolBC; int NiBian_Power1_VolCA; int NiBian_Power1_Power; int NiBian_Power2_VolAB; int NiBian_Power2_VolBC; int NiBian_Power2_VolCA; int NiBian_Power2_Power; int NiBian_Power3_VolAB; int NiBian_Power3_VolBC; int NiBian_Power3_VolCA; int NiBian_Power3_Power; int NiBian_Power4_VolAB; int NiBian_Power4_VolBC; int NiBian_Power4_VolCA; int NiBian_Power4_Power; int AC_AnDian_VolAB; int AC_AnDian_VolBC; int AC_AnDian_VolCA; int AC_AnDian_Power; int DC_230V_Fault; int DC_25V_Fault; int MonitSys_Fault; int QD103_Curr; int QD105_Curr; int QD203_Curr; int QD205_Curr; int QD206_Curr; int QD302_Curr; int QD304_Curr; int QD305_Curr; int QD306_Curr; int QD307_Curr; int QD308_Curr; int QD402_Curr; int QD404_Curr; int QD405_Curr; int QD407_Curr; int QD408_Curr; int QA101_A_Curr; int QA105_A_Curr; int QA201_A_Curr; int QA205_A_Curr; int QA206_A_Curr; int QA301_A_Curr; int QA302_A_Curr; int QA305_A_Curr; int QA306_A_Curr; int QA401_A_Curr; int QA402_A_Curr; int QA403_A_Curr; int QA405_A_Curr; int crc; private void genRandomData() { DC_AnDian_Vol_1 = (int) (900 + Math.random()*100); DC_AnDian_Curr_1 = (int) (200 + Math.random()*10); DC_AnDian_Vol_2 = (int) (910 + Math.random()*100); DC_AnDian_Curr_2 = (int) (100 + Math.random()*10); Batt_GroupVol_1 = (int) (900 + Math.random()*100); Batt_GroupCurr_1 = (int) (-100/* + Math.random()*10*/); Batt_GroupVol_2 = (int) (910 + Math.random()*100); Batt_GroupCurr_2 = (int) (-200/* + Math.random()*10*/); QiFa_Vol_1 = (int) (900 + Math.random()*100); QiFa_Curr_1 = (int) (300 + Math.random()*50); QiFa_Vol_2 = (int) (910 + Math.random()*100); QiFa_Curr_2 = (int) (300 + Math.random()*50); DianJi_Speed = (int) (100 + Math.random()*50); DianJi_Power = (int) (10 + Math.random()*10); NiBian_Power1_VolAB = (int) (380 + Math.random()*10); NiBian_Power1_VolBC = (int) (380 + Math.random()*10); NiBian_Power1_VolCA = (int) (380 + Math.random()*10); NiBian_Power1_Power = (int) (650 + Math.random()*100); NiBian_Power2_VolAB = (int) (380 + Math.random()*10); NiBian_Power2_VolBC = (int) (380 + Math.random()*10); NiBian_Power2_VolCA = (int) (380 + Math.random()*10); NiBian_Power2_Power = (int) (600 + Math.random()*100); NiBian_Power3_VolAB = (int) (380 + Math.random()*10); NiBian_Power3_VolBC = (int) (380 + Math.random()*10); NiBian_Power3_VolCA = (int) (380 + Math.random()*10); NiBian_Power3_Power = (int) (500 + Math.random()*100); NiBian_Power4_VolAB = (int) (380 + Math.random()*10); NiBian_Power4_VolBC = (int) (380 + Math.random()*10); NiBian_Power4_VolCA = (int) (380 + Math.random()*10); NiBian_Power4_Power = (int) (400 + Math.random()*100); AC_AnDian_VolAB = (int) (380 + Math.random()*10); AC_AnDian_VolBC = (int) (380 + Math.random()*10); AC_AnDian_VolCA = (int) (380 + Math.random()*10); AC_AnDian_Power = (int) (2000 + Math.random()*100); DC_230V_Fault = (int) (Math.random() + 0.5); DC_25V_Fault = (int) (Math.random() + 0.5); MonitSys_Fault = (int) (Math.random() + 0.5); QD103_Curr = (int) (100 + Math.random()*50); QD105_Curr = (int) (100 + Math.random()*50); QD203_Curr = (int) (100 + Math.random()*50); QD205_Curr = (int) (100 + Math.random()*50); QD206_Curr = (int) (100 + Math.random()*50); QD302_Curr = (int) (100 + Math.random()*50); QD304_Curr = (int) (100 + Math.random()*50); QD305_Curr = (int) (100 + Math.random()*50); QD306_Curr = (int) (100 + Math.random()*50); QD307_Curr = (int) (100 + Math.random()*50); QD308_Curr = (int) (100 + Math.random()*50); QD402_Curr = (int) (100 + Math.random()*50); QD404_Curr = (int) (100 + Math.random()*50); QD405_Curr = (int) (100 + Math.random()*50); QD407_Curr = (int) (100 + Math.random()*50); QD408_Curr = (int) (100 + Math.random()*50); QA101_A_Curr = (int) (100 + Math.random()*50); QA105_A_Curr = (int) (100 + Math.random()*50); QA201_A_Curr = (int) (100 + Math.random()*50); QA205_A_Curr = (int) (100 + Math.random()*50); QA206_A_Curr = (int) (100 + Math.random()*50); QA301_A_Curr = (int) (100 + Math.random()*50); QA302_A_Curr = (int) (100 + Math.random()*50); QA305_A_Curr = (int) (100 + Math.random()*50); QA306_A_Curr = (int) (100 + Math.random()*50); QA401_A_Curr = (int) (100 + Math.random()*50); QA402_A_Curr = (int) (100 + Math.random()*50); QA403_A_Curr = (int) (100 + Math.random()*50); QA405_A_Curr = (int) (100 + Math.random()*50); } public ArrayList makeEthData(short dev_id) { genRandomData(); ByteBuffer bf = ByteBuffer.allocate(500); bf.order(ByteOrder.BIG_ENDIAN); bf.putShort( dev_id ); bf.putShort( (short) 0x0D0E ); bf.putShort( (short) (BYTE_ETH_DATA_LEN / 2) ); bf.putFloat((float)DC_AnDian_Vol_1 ); bf.putFloat((float)DC_AnDian_Curr_1 ); bf.putFloat((float)DC_AnDian_Vol_2 ); bf.putFloat((float)DC_AnDian_Curr_2 ); bf.putFloat((float)Batt_GroupVol_1 ); bf.putFloat((float)Batt_GroupCurr_1 ); bf.putFloat((float)Batt_GroupVol_2 ); bf.putFloat((float)Batt_GroupCurr_2 ); bf.putFloat((float)QiFa_Vol_1 ); bf.putFloat((float)QiFa_Curr_1 ); bf.putFloat((float)QiFa_Vol_2 ); bf.putFloat((float)QiFa_Curr_2 ); bf.putFloat((float)DianJi_Speed ); bf.putFloat((float)DianJi_Power ); bf.putFloat((float)NiBian_Power1_VolAB ); bf.putFloat((float)NiBian_Power1_VolBC ); bf.putFloat((float)NiBian_Power1_VolCA ); bf.putFloat((float)NiBian_Power1_Power ); bf.putFloat((float)NiBian_Power2_VolAB ); bf.putFloat((float)NiBian_Power2_VolBC ); bf.putFloat((float)NiBian_Power2_VolCA ); bf.putFloat((float)NiBian_Power2_Power ); bf.putFloat((float)NiBian_Power3_VolAB ); bf.putFloat((float)NiBian_Power3_VolBC ); bf.putFloat((float)NiBian_Power3_VolCA ); bf.putFloat((float)NiBian_Power3_Power ); bf.putFloat((float)NiBian_Power4_VolAB ); bf.putFloat((float)NiBian_Power4_VolBC ); bf.putFloat((float)NiBian_Power4_VolCA ); bf.putFloat((float)NiBian_Power4_Power ); bf.putFloat((float)AC_AnDian_VolAB ); bf.putFloat((float)AC_AnDian_VolBC ); bf.putFloat((float)AC_AnDian_VolCA ); bf.putFloat((float)AC_AnDian_Power ); bf.putInt( DC_230V_Fault ); bf.putInt( DC_25V_Fault ); bf.putInt( MonitSys_Fault ); bf.putFloat((float)QD103_Curr ); bf.putFloat((float)QD105_Curr ); bf.putFloat((float)QD203_Curr ); bf.putFloat((float)QD205_Curr ); bf.putFloat((float)QD206_Curr ); bf.putInt( QD302_Curr ); bf.putInt( QD304_Curr ); bf.putInt( QD305_Curr ); bf.putInt( QD306_Curr ); bf.putInt( QD307_Curr ); bf.putInt( QD308_Curr ); bf.putInt( QD402_Curr ); bf.putInt( QD404_Curr ); bf.putInt( QD405_Curr ); bf.putInt( QD407_Curr ); bf.putInt( QD408_Curr ); bf.putInt( QA101_A_Curr ); bf.putInt( QA105_A_Curr ); bf.putInt( QA201_A_Curr ); bf.putInt( QA205_A_Curr ); bf.putInt( QA206_A_Curr ); bf.putInt( QA301_A_Curr ); bf.putInt( QA302_A_Curr ); bf.putInt( QA305_A_Curr ); bf.putInt( QA306_A_Curr ); bf.putInt( QA401_A_Curr ); bf.putInt( QA402_A_Curr ); bf.putInt( QA403_A_Curr ); bf.putInt( QA405_A_Curr ); /* bf.putInt( DC_AnDian_Vol_1 ); bf.putInt( DC_AnDian_Curr_1 ); bf.putInt( DC_AnDian_Vol_2 ); bf.putInt( DC_AnDian_Curr_2 ); bf.putInt( Batt_GroupVol_1 ); bf.putInt( Batt_GroupCurr_1 ); bf.putInt( Batt_GroupVol_2 ); bf.putInt( Batt_GroupCurr_2 ); bf.putInt( QiFa_Vol_1 ); bf.putInt( QiFa_Curr_1 ); bf.putInt( QiFa_Vol_2 ); bf.putInt( QiFa_Curr_2 ); bf.putInt( DianJi_Speed ); bf.putInt( DianJi_Power ); bf.putInt( NiBian_Power1_VolAB ); bf.putInt( NiBian_Power1_VolBC ); bf.putInt( NiBian_Power1_VolCA ); bf.putInt( NiBian_Power1_Power ); bf.putInt( NiBian_Power2_VolAB ); bf.putInt( NiBian_Power2_VolBC ); bf.putInt( NiBian_Power2_VolCA ); bf.putInt( NiBian_Power2_Power ); bf.putInt( NiBian_Power3_VolAB ); bf.putInt( NiBian_Power3_VolBC ); bf.putInt( NiBian_Power3_VolCA ); bf.putInt( NiBian_Power3_Power ); bf.putInt( NiBian_Power4_VolAB ); bf.putInt( NiBian_Power4_VolBC ); bf.putInt( NiBian_Power4_VolCA ); bf.putInt( NiBian_Power4_Power ); bf.putInt( AC_AnDian_VolAB ); bf.putInt( AC_AnDian_VolBC ); bf.putInt( AC_AnDian_VolCA ); bf.putInt( AC_AnDian_Power ); bf.putInt( DC_230V_Fault ); bf.putInt( DC_25V_Fault ); bf.putInt( MonitSys_Fault ); bf.putInt( QD103_Curr ); bf.putInt( QD105_Curr ); bf.putInt( QD203_Curr ); bf.putInt( QD205_Curr ); bf.putInt( QD206_Curr ); bf.putInt( QD302_Curr ); bf.putInt( QD304_Curr ); bf.putInt( QD305_Curr ); bf.putInt( QD306_Curr ); bf.putInt( QD307_Curr ); bf.putInt( QD308_Curr ); bf.putInt( QD402_Curr ); bf.putInt( QD404_Curr ); bf.putInt( QD405_Curr ); bf.putInt( QD407_Curr ); bf.putInt( QD408_Curr ); bf.putInt( QA101_A_Curr ); bf.putInt( QA105_A_Curr ); bf.putInt( QA201_A_Curr ); bf.putInt( QA205_A_Curr ); bf.putInt( QA206_A_Curr ); bf.putInt( QA301_A_Curr ); bf.putInt( QA302_A_Curr ); bf.putInt( QA305_A_Curr ); bf.putInt( QA306_A_Curr ); bf.putInt( QA401_A_Curr ); bf.putInt( QA402_A_Curr ); bf.putInt( QA403_A_Curr ); bf.putInt( QA405_A_Curr ); */ //bf.putInt( crc ); bf.flip(); ArrayList ret_dat = new ArrayList(); byte[] bb = new byte[bf.limit()]; bf.get(bb); ret_dat.add(bb); return ret_dat; } public ArrayList makeEthStatData(short dev_id) { ByteBuffer bf = ByteBuffer.allocate(500); bf.order(ByteOrder.BIG_ENDIAN); bf.putShort( dev_id ); bf.putShort( (short) 0x0D0E ); bf.putShort( (short) (BYTE_ETH_STAT_LEN / 2) ); for(int n=6; n ret_dat = new ArrayList(); byte[] bb = new byte[bf.limit()]; bf.get(bb); ret_dat.add(bb); return ret_dat; } static private byte[] genCanFrame(byte[] can_id, int val1, int val2, int val3, int val4, int dat_cnt) { ByteBuffer bf = ByteBuffer.allocate(100); bf.order(ByteOrder.LITTLE_ENDIAN); byte[] dat = new byte[13]; bf.clear(); bf.put((byte) ((byte)0x80 + (byte)(dat_cnt*2))); bf.put(can_id); bf.putShort( (short) val1 ); bf.putShort( (short) val2 ); bf.putShort( (short) val3 ); bf.putShort( (short) val4 ); bf.flip(); bf.get(dat); return dat; } ArrayList makeCanData() { ArrayList al_bytes = new ArrayList(); genRandomData(); byte[] can_id = new byte[4]; can_id[0] = (byte) 0x1E; can_id[1] = (byte) 0x86; can_id[2] = (byte) 0x68; can_id[3] = (byte) 0x00; al_bytes.add(genCanFrame(can_id, DC_AnDian_Vol_1, DC_AnDian_Curr_1, DC_AnDian_Vol_2, DC_AnDian_Curr_2, 4)); can_id[3] += 1; al_bytes.add(genCanFrame(can_id, Batt_GroupVol_1, Batt_GroupCurr_1, Batt_GroupVol_2, Batt_GroupCurr_2, 4)); can_id[3] += 1; al_bytes.add(genCanFrame(can_id, QiFa_Vol_1, QiFa_Curr_1, QiFa_Vol_2, QiFa_Curr_2, 4)); can_id[3] += 1; al_bytes.add(genCanFrame(can_id, DianJi_Speed, DianJi_Power, 0, 0, 4)); can_id[3] += 1; al_bytes.add(genCanFrame(can_id, NiBian_Power1_VolAB, NiBian_Power1_VolBC, NiBian_Power1_VolCA, NiBian_Power1_Power, 4)); can_id[3] += 1; al_bytes.add(genCanFrame(can_id, NiBian_Power2_VolAB, NiBian_Power2_VolBC, NiBian_Power2_VolCA, NiBian_Power2_Power, 4)); can_id[3] += 1; al_bytes.add(genCanFrame(can_id, NiBian_Power3_VolAB, NiBian_Power3_VolBC, NiBian_Power3_VolCA, NiBian_Power3_Power, 4)); can_id[3] += 1; al_bytes.add(genCanFrame(can_id, NiBian_Power4_VolAB, NiBian_Power4_VolBC, NiBian_Power4_VolCA, NiBian_Power4_Power, 4)); can_id[3] += 1; al_bytes.add(genCanFrame(can_id, AC_AnDian_VolAB, AC_AnDian_VolBC, AC_AnDian_VolCA, AC_AnDian_Power, 4)); can_id[3] += 1; al_bytes.add(genCanFrame(can_id, DC_230V_Fault, DC_25V_Fault, MonitSys_Fault, 0, 3)); return al_bytes; } ArrayList makeCanStatData(){ ArrayList al_bytes = new ArrayList(); byte[] can_id = new byte[4]; can_id[0] = (byte) 0x1E; can_id[1] = (byte) 0x86; can_id[2] = (byte) 0x68; can_id[3] = (byte) 0x00; al_bytes.add(genCanFrame(can_id, (short)(Math.random()*100000), (short)(Math.random()*100000), (short)(Math.random()*100000), (short)(Math.random()*100000), 4)); can_id[3] += 1; al_bytes.add(genCanFrame(can_id, (short)(Math.random()*100000), (short)(Math.random()*100000), (short)(Math.random()*100000), (short)(Math.random()*100000), 4)); can_id[3] += 1; al_bytes.add(genCanFrame(can_id, (short)(Math.random()*100000), (short)(Math.random()*100000), (short)(Math.random()*100000), (short)(Math.random()*100000), 4)); return al_bytes; } static public ArrayList iniCanFrameData(byte[] can_id, int frame_cnt) { ArrayList al_bytes = new ArrayList(); for(int n=0; n