package com.dev.bybb;
|
|
import java.nio.ByteBuffer;
|
import java.util.ArrayList;
|
import java.util.Date;
|
|
import javax.swing.JTextField;
|
|
import main.page_debug_inf;
|
import sp_comm.Comm_Socket;
|
|
import com.Com;
|
import com.Crc16;
|
|
public class BYBB_UdpSender implements Runnable{
|
private boolean running_en = true;
|
private boolean auto_send_en = false;
|
private boolean manul_send_en = false;
|
private String TarUdpIP = "";
|
private int TarUdpPort = 0;
|
private String TarCanIP = "";
|
private int TarCanPort = 0;
|
private JTextField tf_send_inf = null;
|
private page_debug_inf dt_debug_inf = null;
|
|
public ArrayList<byte[]> EthDataCpt1 = new ArrayList<byte[]>();
|
public ArrayList<byte[]> EthDataCpt2 = new ArrayList<byte[]>();
|
public ArrayList<byte[]> EthDataWGU1 = new ArrayList<byte[]>();
|
public ArrayList<byte[]> EthDataWGU2 = new ArrayList<byte[]>();
|
public ArrayList<byte[]> CanDataCpt1 = new ArrayList<byte[]>();
|
public ArrayList<byte[]> CanDataCpt2 = new ArrayList<byte[]>();
|
public ArrayList<byte[]> CanDataWGU1 = new ArrayList<byte[]>();
|
public ArrayList<byte[]> CanDataWGU2 = new ArrayList<byte[]>();
|
public ArrayList<byte[]> D_EthDataLCU11 = new ArrayList<byte[]>();
|
public ArrayList<byte[]> D_EthDataLCU12 = new ArrayList<byte[]>();
|
public ArrayList<byte[]> D_EthDataLCU21 = new ArrayList<byte[]>();
|
public ArrayList<byte[]> D_EthDataLCU22 = new ArrayList<byte[]>();
|
public ArrayList<byte[]> D_CanDataLCU11 = new ArrayList<byte[]>();
|
public ArrayList<byte[]> D_CanDataLCU12 = new ArrayList<byte[]>();
|
public ArrayList<byte[]> D_CanDataLCU21 = new ArrayList<byte[]>();
|
public ArrayList<byte[]> D_CanDataLCU22 = new ArrayList<byte[]>();
|
|
public ArrayList<byte[]> EthDataStartSelfCheck = new ArrayList<byte[]>();
|
//public ArrayList<byte[]> EthDataStopSelfCheck = new ArrayList<byte[]>();
|
|
public long Data_SendEN = 0;
|
public ArrayList<byte[]> mUsrDataSend = null;
|
|
public BYBB_UdpSender() {
|
byte[] b_Cpt1 = new byte[300];
|
b_Cpt1[0] = 0x76;//0x08;
|
b_Cpt1[1] = 0x76;//0x28;
|
b_Cpt1[2] = 0x0D;
|
b_Cpt1[3] = 0x0E;
|
b_Cpt1[4] = 0x00;
|
b_Cpt1[5] = (byte) 0x85;
|
EthDataCpt1.add(b_Cpt1);
|
|
byte[] b_Cpt2 = new byte[300];
|
b_Cpt2[0] = 0x77;//0x08;
|
b_Cpt2[1] = 0x77;//0x29;
|
b_Cpt2[2] = 0x0D;
|
b_Cpt2[3] = 0x0E;
|
b_Cpt2[4] = 0x00;
|
b_Cpt2[5] = (byte) 0x85;
|
EthDataCpt2.add(b_Cpt2);
|
|
byte[] b_wg1 = new byte[300];
|
b_wg1[0] = 0x72;
|
b_wg1[1] = 0x72;
|
b_wg1[2] = 0x0D;
|
b_wg1[3] = 0x0E;
|
b_wg1[4] = 0x00;
|
b_wg1[5] = (byte) 0x85;
|
EthDataWGU1.add(b_wg1);
|
|
byte[] b_wg2 = new byte[300];
|
b_wg2[0] = 0x75;
|
b_wg2[1] = 0x75;
|
b_wg2[2] = 0x0D;
|
b_wg2[3] = 0x0E;
|
b_wg2[4] = 0x00;
|
b_wg2[5] = (byte) 0x85;
|
EthDataWGU2.add(b_wg2);
|
|
byte[] can_id = new byte[4];
|
can_id[0] = (byte) 0x1E; can_id[1] = (byte) 0x86;
|
can_id[2] = (byte) 0x48; can_id[3] = (byte) 0x00;
|
CanDataCpt1 = BYBB_Data.iniCanFrameData(can_id, 10);
|
|
can_id[2] = (byte) 0x50; can_id[3] = (byte) 0x00;
|
CanDataCpt2 = BYBB_Data.iniCanFrameData(can_id, 10);
|
|
can_id[2] = (byte) 0x68; can_id[3] = (byte) 0x00;
|
CanDataWGU1 = BYBB_Data.iniCanFrameData(can_id, 10);
|
|
can_id[2] = (byte) 0x80; can_id[3] = (byte) 0x00;
|
CanDataWGU2 = BYBB_Data.iniCanFrameData(can_id, 10);
|
|
byte[] b_lcu11 = new byte[60];
|
b_lcu11[0] = 0x70;
|
b_lcu11[1] = 0x70;
|
b_lcu11[2] = 0x0D;
|
b_lcu11[3] = 0x0E;
|
b_lcu11[4] = 0x00;
|
b_lcu11[5] = 0x38;
|
D_EthDataLCU11.add(b_lcu11);
|
|
byte[] b_lcu12 = new byte[60];
|
b_lcu12[0] = 0x71;
|
b_lcu12[1] = 0x71;
|
b_lcu12[2] = 0x0D;
|
b_lcu12[3] = 0x0E;
|
b_lcu12[4] = 0x00;
|
b_lcu12[5] = 0x38;
|
D_EthDataLCU12.add(b_lcu12);
|
|
byte[] b_lcu21 = new byte[60];
|
b_lcu21[0] = 0x73;
|
b_lcu21[1] = 0x73;
|
b_lcu21[2] = 0x0D;
|
b_lcu21[3] = 0x0E;
|
b_lcu21[4] = 0x00;
|
b_lcu21[5] = 0x38;
|
D_EthDataLCU21.add(b_lcu21);
|
|
byte[] b_lcu22 = new byte[60];
|
b_lcu22[0] = 0x74;
|
b_lcu22[1] = 0x74;
|
b_lcu22[2] = 0x0D;
|
b_lcu22[3] = 0x0E;
|
b_lcu22[4] = 0x00;
|
b_lcu22[5] = 0x38;
|
D_EthDataLCU22.add(b_lcu22);
|
|
can_id[2] = (byte) 0x58; can_id[3] = (byte) 0x00;
|
D_CanDataLCU11 = BYBB_Data.iniCanFrameData(can_id, 3);
|
|
can_id[2] = (byte) 0x60; can_id[3] = (byte) 0x00;
|
D_CanDataLCU12 = BYBB_Data.iniCanFrameData(can_id, 3);
|
|
can_id[2] = (byte) 0x70; can_id[3] = (byte) 0x00;
|
D_CanDataLCU21 = BYBB_Data.iniCanFrameData(can_id, 3);
|
|
can_id[2] = (byte) 0x78; can_id[3] = (byte) 0x00;
|
D_CanDataLCU22 = BYBB_Data.iniCanFrameData(can_id, 3);
|
|
byte[] b_startcheck = new byte[30];
|
b_startcheck[0] = 0x76;
|
b_startcheck[1] = 0x76;
|
b_startcheck[2] = 0x18;
|
b_startcheck[3] = 0x18;
|
b_startcheck[4] = 0x00;
|
b_startcheck[5] = 0x0B;
|
b_startcheck[6] = 0x00;
|
b_startcheck[7] = 0x00;
|
b_startcheck[8] = 0x00;
|
b_startcheck[9] = 0x02;
|
b_startcheck[10] = 0x00;
|
b_startcheck[11] = 0x00;
|
b_startcheck[12] = 0x00;
|
b_startcheck[13] = 0x01;
|
EthDataStartSelfCheck.add(b_startcheck);
|
}
|
|
public void setDebugInfText(JTextField tf, page_debug_inf inf) {
|
tf_send_inf = tf;
|
dt_debug_inf = inf;
|
running_en = true;
|
}
|
|
public ArrayList<byte[]> getCanByteBuf(int sel_index) {
|
ArrayList<byte[]> dat_buf = new ArrayList<byte[]>();
|
switch(sel_index) {
|
case 0 : dat_buf = EthDataCpt1; break;
|
case 1 : dat_buf = EthDataCpt2; break;
|
case 2 : dat_buf = EthDataWGU1; break;
|
case 3 : dat_buf = EthDataWGU2; break;
|
|
case 4 : dat_buf = CanDataCpt1; break;
|
case 5 : dat_buf = CanDataCpt2; break;
|
case 6 : dat_buf = CanDataWGU1; break;
|
case 7 : dat_buf = CanDataWGU2; break;
|
|
case 8 : dat_buf = D_EthDataLCU11; break;
|
case 9 : dat_buf = D_EthDataLCU12; break;
|
case 10 : dat_buf = D_EthDataLCU21; break;
|
case 11 : dat_buf = D_EthDataLCU22; break;
|
|
case 12 : dat_buf = D_CanDataLCU11; break;
|
case 13 : dat_buf = D_CanDataLCU12; break;
|
case 14 : dat_buf = D_CanDataLCU21; break;
|
case 15 : dat_buf = D_CanDataLCU22; break;
|
|
default : break;
|
}
|
return dat_buf;
|
}
|
|
private ArrayList<byte[]> getDataUdpBuf(int index) {
|
ArrayList<byte[]> dat_buf = new ArrayList<byte[]>();
|
switch(index) {
|
case 0 : dat_buf = EthDataCpt1; break;
|
case 1 : dat_buf = EthDataCpt2; break;
|
case 2 : dat_buf = EthDataWGU1; break;
|
case 3 : dat_buf = EthDataWGU2; break;
|
|
case 4 : dat_buf = CanDataCpt1; break;
|
case 5 : dat_buf = CanDataCpt2; break;
|
case 6 : dat_buf = CanDataWGU1; break;
|
case 7 : dat_buf = CanDataWGU2; break;
|
|
case 8 : dat_buf = D_EthDataLCU11; break;
|
case 9 : dat_buf = D_EthDataLCU12; break;
|
case 10 : dat_buf = D_EthDataLCU21; break;
|
case 11 : dat_buf = D_EthDataLCU22; break;
|
|
case 12 : dat_buf = D_CanDataLCU11; break;
|
case 13 : dat_buf = D_CanDataLCU12; break;
|
case 14 : dat_buf = D_CanDataLCU21; break;
|
case 15 : dat_buf = D_CanDataLCU22; break;
|
|
default : break;
|
}
|
return dat_buf;
|
}
|
|
public void setDataSendEn(int index, boolean stat) {
|
if(true == stat) {
|
Data_SendEN |= ((long)1)<<index;
|
} else {
|
Data_SendEN &= ~(((long)1)<<index);
|
}
|
}
|
public boolean getDataSendEn(int index) {
|
boolean stat = false;
|
if((Data_SendEN & (((long)1)<<index)) > 0) {
|
stat = true;
|
}
|
return stat;
|
}
|
|
public void setManulSendEn(String ip, int port, String can_ip, int can_port, page_debug_inf debug_inf) {
|
TarUdpIP = ip;
|
TarUdpPort = port;
|
|
TarCanIP = can_ip;
|
TarCanPort = can_port;
|
|
dt_debug_inf = debug_inf;
|
|
manul_send_en = true;
|
}
|
|
public void setAutoSendStat(boolean en) {
|
auto_send_en = en;
|
}
|
|
public void sendUsrDataEn() {
|
mUsrDataSend = EthDataStartSelfCheck;
|
}
|
|
public void exitThread() {
|
running_en = false;
|
}
|
|
@Override
|
public void run() {
|
// TODO Auto-generated method stub
|
while(true == running_en) {
|
try {
|
Thread.sleep(20);
|
} catch (InterruptedException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
/*
|
if((m_DataIndex < 0) || (m_DataIndex > 15)) {
|
continue;
|
}
|
*/
|
if((false == auto_send_en) && (false == manul_send_en)) {
|
continue;
|
}
|
manul_send_en = false;
|
|
if(null != mUsrDataSend) {
|
ArrayList<byte[]> dat_buf = mUsrDataSend;
|
mUsrDataSend = null;
|
|
for(int n=0; n<dat_buf.size(); n++) {
|
byte[] dat = dat_buf.get(n);
|
ByteBuffer bbf_tx = ByteBuffer.allocate(dat.length+2);
|
ByteBuffer bbf_rx = ByteBuffer.allocate(300);
|
bbf_tx.put(dat);
|
short crc = Crc16.CalCRC16(dat, dat.length);
|
bbf_tx.put((byte) ((crc>>8)&0xFF));
|
bbf_tx.put((byte) (crc&0xFF));
|
bbf_tx.flip();
|
Comm_Socket.SocketUdpComm(10020, TarUdpIP, TarUdpPort, bbf_tx, bbf_rx, dt_debug_inf, true);
|
try {
|
Thread.sleep(30);
|
} catch (InterruptedException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
}
|
tf_send_inf.setText("TX CK @" + Com.get_DTF(new Date(), Com.DTF_hms));
|
|
continue;
|
}
|
|
for(int dn=0; dn<16; dn++) {
|
if(true == getDataSendEn(dn)) {
|
ArrayList<byte[]> dat_buf = getDataUdpBuf(dn);
|
String t_ip = "";
|
int port = 10000;
|
boolean need_crc = false;
|
if((dn<=3) || ((dn>=8)&&(dn<=11))) {
|
t_ip = TarUdpIP;
|
port = TarUdpPort;
|
need_crc = true;
|
} else if(((dn>=4)&&(dn<=7)) || ((dn>=12)&&(dn<=15))) {
|
t_ip = TarCanIP;
|
port = TarCanPort;
|
}
|
|
for(int n=0; n<dat_buf.size(); n++) {
|
byte[] dat = dat_buf.get(n);
|
int tx_dat_len = dat.length;
|
short crc = 0;
|
if(true == need_crc) {
|
crc = Crc16.CalCRC16(dat, tx_dat_len);
|
tx_dat_len += 2;
|
}
|
ByteBuffer bbf_tx = ByteBuffer.allocate(tx_dat_len);
|
ByteBuffer bbf_rx = ByteBuffer.allocate(0);
|
bbf_tx.put(dat);
|
if(true == need_crc) {
|
bbf_tx.put((byte) ((crc>>8)&0xFF));
|
bbf_tx.put((byte) (crc&0xFF));
|
}
|
bbf_tx.flip();
|
Comm_Socket.SocketUdpComm(10020, t_ip, port, bbf_tx, bbf_rx, dt_debug_inf, true);
|
try {
|
Thread.sleep(30);
|
} catch (InterruptedException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
}
|
tf_send_inf.setText("TXD: " + (dn+1) + " @" + Com.get_DTF(new Date(), Com.DTF_hms));
|
}
|
}
|
}
|
|
dt_debug_inf.addDebugInf(Com.get_DTF(new Date(), Com.DTF_YMDhms_S)
|
+ " UDP Comm Thread is quit, Dev Id: BYBB\n");
|
}
|
}
|