Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
platform
/
platform-charging-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit ff393b86
authored
Nov 09, 2023
by
zhouhaibao
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]服务端发送消息
1 parent
b6c62fce
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
11 deletions
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/TimeSettingRspHandler.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/server/ProxyHelper.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/server/TcpServer.java
platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/TimeSettingTest.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/TimeSettingRspHandler.java
View file @
ff393b8
...
@@ -29,7 +29,7 @@ public class TimeSettingRspHandler implements TcpHandler<TimeSettingRsp, TimeSet
...
@@ -29,7 +29,7 @@ public class TimeSettingRspHandler implements TcpHandler<TimeSettingRsp, TimeSet
.
parseCp56Time2aStr
(
data
.
getTime
())
/* DateUtils.datetimeToStr(ByteUtils.parseCp56Time2a(timeSettingRsp.getData().getTime())) */
);
.
parseCp56Time2aStr
(
data
.
getTime
())
/* DateUtils.datetimeToStr(ByteUtils.parseCp56Time2a(timeSettingRsp.getData().getTime())) */
);
// TODO
// TODO
String
key
=
channel
.
attr
(
ProxyHelper
.
PILE_ID_KEY
).
get
()
+
"+"
+
rsp
.
getSeq
(
);
String
key
=
ProxyHelper
.
getCallbackKey
(
rsp
,
channel
);
TcpCallback
<
TcpRsp
>
callback
=
ProxyHelper
.
getCallback
(
key
);
TcpCallback
<
TcpRsp
>
callback
=
ProxyHelper
.
getCallback
(
key
);
callback
.
callback
(
rsp
);
callback
.
callback
(
rsp
);
...
...
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/server/ProxyHelper.java
View file @
ff393b8
package
cn
.
com
.
glsx
.
charging
.
modules
.
gbt
.
ocpp16
.
tcp
.
server
;
package
cn
.
com
.
glsx
.
charging
.
modules
.
gbt
.
ocpp16
.
tcp
.
server
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpBase
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpCallback
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpCallback
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpRsp
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpRsp
;
import
java.net.InetSocketAddress
;
import
java.net.InetSocketAddress
;
...
@@ -174,4 +175,11 @@ public class ProxyHelper {
...
@@ -174,4 +175,11 @@ public class ProxyHelper {
public
static
TcpCallback
<
TcpRsp
>
getCallback
(
String
key
)
{
public
static
TcpCallback
<
TcpRsp
>
getCallback
(
String
key
)
{
return
callbackMap
.
get
(
key
);
return
callbackMap
.
get
(
key
);
}
}
public
static
<
T
extends
TcpBase
>
String
getCallbackKey
(
T
data
,
Channel
channel
)
{
if
(
channel
==
null
)
{
throw
new
RuntimeException
(
"channel为null!!!"
);
}
return
channel
.
attr
(
ProxyHelper
.
PILE_ID_KEY
).
get
()
+
"+"
+
data
.
getSeq
();
}
}
}
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/server/TcpServer.java
View file @
ff393b8
...
@@ -34,10 +34,15 @@ public class TcpServer {
...
@@ -34,10 +34,15 @@ public class TcpServer {
public
static
Integer
PROTOCOL_MAX_LENGTH
=
200
;
public
static
Integer
PROTOCOL_MAX_LENGTH
=
200
;
/** 用于分配处理业务线程的线程组个数 */
/**
* 用于分配处理业务线程的线程组个数
*/
protected
static
final
int
BIZGROUPSIZE
=
Runtime
.
getRuntime
().
availableProcessors
();
// 默认
protected
static
final
int
BIZGROUPSIZE
=
Runtime
.
getRuntime
().
availableProcessors
();
// 默认
/** 业务线程大小 */
/**
protected
static
final
int
BIZTHREADSIZE
=
Math
.
max
(
Runtime
.
getRuntime
().
availableProcessors
()
*
2
,
16
);
* 业务线程大小
*/
protected
static
final
int
BIZTHREADSIZE
=
Math
.
max
(
Runtime
.
getRuntime
().
availableProcessors
()
*
2
,
16
);
private
final
String
host
;
private
final
String
host
;
private
final
int
port
;
private
final
int
port
;
...
@@ -61,7 +66,8 @@ public class TcpServer {
...
@@ -61,7 +66,8 @@ public class TcpServer {
public
void
initChannel
(
SocketChannel
ch
)
throws
Exception
{
public
void
initChannel
(
SocketChannel
ch
)
throws
Exception
{
ChannelPipeline
pipeline
=
ch
.
pipeline
();
ChannelPipeline
pipeline
=
ch
.
pipeline
();
pipeline
.
addLast
(
"lengthDecoder"
,
new
LengthFieldBasedFrameDecoder
(
PROTOCOL_MAX_LENGTH
,
1
,
1
,
2
,
0
));
pipeline
.
addLast
(
"lengthDecoder"
,
new
LengthFieldBasedFrameDecoder
(
PROTOCOL_MAX_LENGTH
,
1
,
1
,
2
,
0
));
pipeline
.
addLast
(
"decoder"
,
new
ByteArrayDecoder
());
pipeline
.
addLast
(
"decoder"
,
new
ByteArrayDecoder
());
pipeline
.
addLast
(
"encoder"
,
new
ByteArrayEncoder
());
pipeline
.
addLast
(
"encoder"
,
new
ByteArrayEncoder
());
pipeline
.
addLast
(
"handler"
,
new
TcpServerHandler
());
pipeline
.
addLast
(
"handler"
,
new
TcpServerHandler
());
...
@@ -111,10 +117,10 @@ public class TcpServer {
...
@@ -111,10 +117,10 @@ public class TcpServer {
log
.
info
(
"【{}】关闭TCP服务器!!!!!!"
,
port
);
log
.
info
(
"【{}】关闭TCP服务器!!!!!!"
,
port
);
}
}
@SuppressWarnings
({
"rawtypes"
})
@SuppressWarnings
({
"rawtypes"
})
public
<
T
extends
TcpBase
>
TcpCallback
<
TcpRsp
>
sendSync
(
T
data
)
{
public
<
T
extends
TcpBase
>
TcpCallback
<
TcpRsp
>
sendSync
(
T
data
)
{
ProxyInfo
proxyInfo
=
ProxyHelper
.
getProxyInfo
(
data
.
getData
().
getPileIdStr
());
ProxyInfo
proxyInfo
=
ProxyHelper
.
getProxyInfo
(
data
.
getData
().
getPileIdStr
());
String
ip
=
proxyInfo
.
getIp
();
String
ip
=
proxyInfo
.
getIp
();
// seq字段处理
// seq字段处理
String
seqKey
=
ip
;
String
seqKey
=
ip
;
if
(
data
.
getData
()
!=
null
)
{
if
(
data
.
getData
()
!=
null
)
{
...
@@ -124,7 +130,7 @@ public class TcpServer {
...
@@ -124,7 +130,7 @@ public class TcpServer {
byte
[]
bs
=
Ocpp16Helper
.
build
(
data
);
byte
[]
bs
=
Ocpp16Helper
.
build
(
data
);
log
.
info
(
"【{}】读取proxyInfo:{}"
,
data
.
getData
().
getPileIdStr
(),
proxyInfo
);
log
.
info
(
"【{}】读取proxyInfo:{}"
,
data
.
getData
().
getPileIdStr
(),
proxyInfo
);
String
key
=
proxyInfo
.
getChannel
().
attr
(
ProxyHelper
.
PILE_ID_KEY
).
get
()
+
"+"
+
data
.
getSeq
(
);
String
key
=
ProxyHelper
.
getCallbackKey
(
data
,
proxyInfo
.
getChannel
()
);
TcpCallback
<
TcpRsp
>
callback
=
new
TcpCallback
<>(
TcpRsp
.
class
);
TcpCallback
<
TcpRsp
>
callback
=
new
TcpCallback
<>(
TcpRsp
.
class
);
ProxyHelper
.
addCallback
(
key
,
callback
);
ProxyHelper
.
addCallback
(
key
,
callback
);
...
@@ -138,7 +144,7 @@ public class TcpServer {
...
@@ -138,7 +144,7 @@ public class TcpServer {
private
void
sendSync
(
byte
[]
bs
,
Channel
channel
)
{
private
void
sendSync
(
byte
[]
bs
,
Channel
channel
)
{
try
{
try
{
if
(
channel
==
null
)
{
if
(
channel
==
null
)
{
log
.
info
(
"channel null ..."
);
log
.
info
(
"channel null ..."
);
return
;
return
;
}
}
...
...
platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/TimeSettingTest.java
View file @
ff393b8
...
@@ -54,11 +54,11 @@ public class TimeSettingTest {
...
@@ -54,11 +54,11 @@ public class TimeSettingTest {
req
.
setData
(
data
);
req
.
setData
(
data
);
Thread
.
sleep
(
3
0000
);
Thread
.
sleep
(
2
0000
);
TcpCallback
<
TcpRsp
>
callback
=
tcpServer
.
sendSync
(
req
);
TcpCallback
<
TcpRsp
>
callback
=
tcpServer
.
sendSync
(
req
);
Thread
.
sleep
(
3
0000
);
Thread
.
sleep
(
1
0000
);
TcpRsp
rsp
=
callback
.
get
();
TcpRsp
rsp
=
callback
.
get
();
log
.
info
(
"callback{}"
,
req
);
log
.
info
(
"callback{}"
,
req
);
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment