package sp_comm;
|
|
import java.nio.ByteBuffer;
|
|
import org.apache.logging.log4j.Logger;
|
|
import main.page_debug_inf;
|
|
public class SP_COMM {
|
public final static int COMM_TYPE_Serial = 0;
|
public final static int COMM_TYPE_Socket = 1;
|
|
public CommSerialPort m_SP_Comm = null;
|
public Comm_Socket m_SocketComm = null;
|
|
public int m_CommType = COMM_TYPE_Socket;
|
public int local_udp_port = 4830;
|
private Logger m_Log = null;
|
|
public SP_COMM(int type, int udp_port, Logger log) {
|
m_CommType = type;
|
if(m_CommType > COMM_TYPE_Serial) {
|
m_CommType = COMM_TYPE_Socket;
|
}
|
|
local_udp_port = udp_port;
|
m_Log = log;
|
}
|
|
public boolean openCommPort(String comm_name_or_ip, int bitrate_or_comm_port) {
|
boolean res = false;
|
if(COMM_TYPE_Serial == m_CommType) {
|
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;
|
}
|
return res;
|
}
|
|
public boolean tr_Msg(ByteBuffer bbf_tx, ByteBuffer bbf_rx, int mult_comm_or_use_tcp,
|
page_debug_inf debug_inf, boolean showdat) {
|
boolean res = false;
|
if(COMM_TYPE_Serial == m_CommType) {
|
m_SP_Comm.SP_Comm(bbf_tx, bbf_rx, mult_comm_or_use_tcp, debug_inf, showdat);
|
res = true;
|
} else {
|
if(1 == mult_comm_or_use_tcp) {
|
res = m_SocketComm.SocketComm(bbf_tx, bbf_rx, debug_inf, showdat);
|
} else {
|
res = Comm_Socket.SocketUdpComm(local_udp_port, m_SocketComm.mDevIp, m_SocketComm.mPort,
|
bbf_tx, bbf_rx, debug_inf, showdat);
|
}
|
}
|
|
return res;
|
}
|
|
public void closeCommPort() {
|
if(COMM_TYPE_Serial == m_CommType) {
|
m_SP_Comm.serialPort.close();
|
} else {
|
m_SocketComm.socketClose();
|
}
|
}
|
}
|