Commit ae7d5e06 authored by zhushanglei's avatar zhushanglei

init

parent 336c5057
...@@ -9,6 +9,11 @@ ...@@ -9,6 +9,11 @@
<version>1.0</version> <version>1.0</version>
<dependencies> <dependencies>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.9.3</version>
</dependency>
<dependency> <dependency>
<groupId>com.fazecast</groupId> <groupId>com.fazecast</groupId>
<artifactId>jSerialComm</artifactId> <artifactId>jSerialComm</artifactId>
......
...@@ -29,7 +29,7 @@ public class TcpServer { ...@@ -29,7 +29,7 @@ public class TcpServer {
// 服务器地址端口 // 服务器地址端口
// private static final String IP = "192.168.0.112"; // private static final String IP = "192.168.0.112";
// private static final String IP = "192.168.0.107"; private static final String IP = "192.168.0.107";
private static final int PORT = 9200; private static final int PORT = 9200;
/** 用于分配处理业务线程的线程组个数 */ /** 用于分配处理业务线程的线程组个数 */
...@@ -86,7 +86,7 @@ public class TcpServer { ...@@ -86,7 +86,7 @@ public class TcpServer {
} }
logger.info("mac: "+sb.toString()); logger.info("mac: "+sb.toString());
logger.info("Local host name: "+hostname); logger.info("Local host name: "+hostname);
b.bind(addr.getHostAddress(), PORT).sync(); b.bind(IP, PORT).sync();
logger.info("TCP Server Started"); logger.info("TCP Server Started");
} }
......
...@@ -3,9 +3,12 @@ package server; ...@@ -3,9 +3,12 @@ package server;
import com.fazecast.jSerialComm.SerialPort; import com.fazecast.jSerialComm.SerialPort;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
import okhttp3.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException;
/** /**
* @author yuli * @author yuli
* @ClassName TcpServerHandler * @ClassName TcpServerHandler
...@@ -14,6 +17,7 @@ public class TcpServerHandler extends SimpleChannelInboundHandler<Object> { ...@@ -14,6 +17,7 @@ public class TcpServerHandler extends SimpleChannelInboundHandler<Object> {
private static Logger logger = LoggerFactory.getLogger(TcpServerHandler.class); private static Logger logger = LoggerFactory.getLogger(TcpServerHandler.class);
private static final String serverUrl = "http://localhost:8001/gps";
/** /**
* 打印接收到的内容,并回传 * 打印接收到的内容,并回传
// * @param [ctx, msg] // * @param [ctx, msg]
...@@ -34,6 +38,34 @@ public class TcpServerHandler extends SimpleChannelInboundHandler<Object> { ...@@ -34,6 +38,34 @@ public class TcpServerHandler extends SimpleChannelInboundHandler<Object> {
openComm(); openComm();
} }
logger.info("**COM口读出数据<<start:" + result +">>end"); logger.info("**COM口读出数据<<start:" + result +">>end");
sendGnss(result);
}
private void sendGnss(String msg) {
try {
String result = post(serverUrl,msg);
logger.info(result);
} catch (IOException e) {
e.printStackTrace();
}
}
public static final MediaType JSON
= MediaType.get("application/json; charset=utf-8");
OkHttpClient client = new OkHttpClient();
String post(String url, String json) throws IOException {
RequestBody body = RequestBody.create(json, JSON);
Request request = new Request.Builder()
.url(url)
.post(body)
.build();
try (Response response = client.newCall(request).execute()) {
return response.body().string();
}
} }
private static SerialPort serialPort; private static SerialPort serialPort;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment