Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
GnssServer
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhushanglei
GnssServer
Commits
ae7d5e06
Commit
ae7d5e06
authored
Apr 01, 2022
by
zhushanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
336c5057
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
2 deletions
+39
-2
pom.xml
pom.xml
+5
-0
TcpServer.java
src/main/java/server/TcpServer.java
+2
-2
TcpServerHandler.java
src/main/java/server/TcpServerHandler.java
+32
-0
No files found.
pom.xml
View file @
ae7d5e06
...
@@ -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>
...
...
src/main/java/server/TcpServer.java
View file @
ae7d5e06
...
@@ -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"
);
}
}
...
...
src/main/java/server/TcpServerHandler.java
View file @
ae7d5e06
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment