org.bdware.dogp.sample.DOGPOp1TestClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of doip-audit-tool Show documentation
Show all versions of doip-audit-tool Show documentation
doip audit tool developed by bdware
package org.bdware.dogp.sample;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bdware.dogp.client.NettyDOGPUDPClientChannelWithOpChanger;
import org.bdware.doip.codec.doipMessage.DoipMessage;
import org.bdware.doip.endpoint.EndpointFactory;
import org.bdware.doip.endpoint.client.ClientConfig;
import org.bdware.doip.endpoint.client.DoipClientImpl;
import org.bdware.doip.endpoint.client.DoipMessageCallback;
import java.util.concurrent.atomic.AtomicInteger;
public class DOGPOp1TestClient {
private final int port;
private final String id;
private final String ip;
private final byte changedOp;
DoipClientImpl client;
static Logger LOGGER = LogManager.getLogger(DOGPTestClient.class);
public DOGPOp1TestClient(String ip, int port, String id, byte changedOp) {
this.ip = ip;
this.port = port;
this.id = id;
this.changedOp = changedOp;
LOGGER.info(String.format("client configuration, ip:%s port:%d id:%s changedop:%d", ip, port, id, changedOp));
}
public void init() {
ClientConfig config;
config = ClientConfig.fromUrl(String.format("udpdogp://%s:%d", ip, port));
client = new DoipClientImpl();
EndpointFactory.addClientChannel("udpdogp", new NettyDOGPUDPClientChannelWithOpChanger(changedOp));
client.connect(config);
}
public static void main(String[] args) {
String ip = "127.0.0.1";
int port = 21034;
String id = "defaulttest/id/1";
if (args.length > 0) {
String[] ipAndPort = args[0].split(":");
ip = ipAndPort[0];
port = Integer.valueOf(ipAndPort[1]);
}
if (args.length > 1)
id = args[1];
int changedop = 0;
if (args.length > 2)
changedop = Integer.valueOf(args[2]);
DOGPOp1TestClient client1 = new DOGPOp1TestClient(ip, port, id, (byte) changedop);
client1.init();
client1.sendMsg();
}
public void sendMsg() {
AtomicInteger i = new AtomicInteger(0);
client.hello(id, new DoipMessageCallback() {
@Override
public void onResult(DoipMessage msg) {
LOGGER.info(String.format("header:0x%x doid:%s operation:%s req:%d bodyDataLen:%d bd:%s",
msg.header.getFlag(), msg.header.parameters.id, msg.header.parameters.operation,
msg.requestID, msg.body.encodedData.length, msg.body.encodedData.length > 0 ? msg.body.getDataAsJsonString() : "-empty-"));
i.incrementAndGet();
}
});
for (; i.get() == 0; ) Thread.yield();
}
}