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 d61157ca
authored
Nov 17, 2023
by
zhouhaibao
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
[+]新增callback
2 parents
c734f580
5365aeb4
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
77 additions
and
23 deletions
platform-charging/src/main/java/cn/com/glsx/charging/modules/api/PileControlApiController.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/base/TcpMapper.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/server/ProxyHelper.java
platform-charging/src/test/java/cn/com/glsx/charging/api/FeignSerivceTest.java
platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/ModelSetTest.java
platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/TimeSettingTest.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/api/PileControlApiController.java
View file @
d61157c
...
...
@@ -53,7 +53,7 @@ public class PileControlApiController implements PileControlFeignClient {
data
.
setPileId
(
Ocpp16Helper
.
strToBcd
(
startBo
.
getPileId
(),
data
.
getPileId
()));
data
.
setGunNumber
(
startBo
.
getGunNumber
().
byteValue
());
data
.
setLogicalCardNumber
(
Ocpp16Helper
.
strToBcd
(
startBo
.
get
TransactionSerial
Number
(),
data
.
getLogicalCardNumber
()));
Ocpp16Helper
.
strToBcd
(
startBo
.
get
LogicalCard
Number
(),
data
.
getLogicalCardNumber
()));
byte
[]
bytes
=
Ocpp16Helper
.
binToBytes
(
Ocpp16Helper
.
hexToBinStr
(
startBo
.
getPhysicalCardNumber
()));
data
.
setPhysicalCardNumber
(
bytes
);
...
...
@@ -61,10 +61,11 @@ public class PileControlApiController implements PileControlFeignClient {
BigDecimal
.
valueOf
(
startBo
.
getAccountBalance
()),
2
);
data
.
setAccountBalance
(
accountBytes
);
req
.
setData
(
data
);
TcpCallback
<
TcpRsp
>
tcpRspTcpCallback
=
ServerMain
.
getServer
().
sendSync
(
req
);
TcpRsp
tcpRsp
=
tcpRspTcpCallback
.
get
();
/*
TcpCallback<TcpRsp> tcpRspTcpCallback = ServerMain.getServer().sendSync(req);
TcpRsp tcpRsp = tcpRspTcpCallback.get();
*/
return
Result
.
success
(
true
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
Result
.
failure
();
}
}
...
...
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/base/TcpMapper.java
View file @
d61157c
...
...
@@ -103,7 +103,7 @@ public final class TcpMapper {
public
static
TcpMapper
CMD_REQ_MODEL_SET
=
regist
(
0x58
,
"计费模型设置"
,
null
);
public
static
TcpMapper
CMD_RSP_MODEL_SET
=
regist
(
0x57
,
"
对时
设置应答"
,
ModelSetRspHandler
.
class
);
public
static
TcpMapper
CMD_RSP_MODEL_SET
=
regist
(
0x57
,
"
计费模型
设置应答"
,
ModelSetRspHandler
.
class
);
public
static
TcpMapper
CMD_REQ_BALANCE_UPDATE
=
regist
(
0x42
,
"远程账户余额更新"
,
null
);
...
...
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/server/ProxyHelper.java
View file @
d61157c
...
...
@@ -2,6 +2,7 @@ package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.server;
import
java.net.InetSocketAddress
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
com.google.common.collect.Maps
;
...
...
@@ -37,6 +38,27 @@ public class ProxyHelper {
private
static
Map
<
String
,
TcpCallback
<
TcpRsp
>>
callbackMap
=
Maps
.
newConcurrentMap
();
/**
* 协议帧对
*/
private
static
Map
<
String
,
String
>
typeMaps
;
static
{
// 初始化map
typeMaps
=
new
HashMap
<>();
typeMaps
.
put
(
"33"
,
"34"
);
typeMaps
.
put
(
"35"
,
"36"
);
typeMaps
.
put
(
"41"
,
"42"
);
typeMaps
.
put
(
"43"
,
"44"
);
typeMaps
.
put
(
"45"
,
"46"
);
typeMaps
.
put
(
"47"
,
"48"
);
typeMaps
.
put
(
"51"
,
"52"
);
typeMaps
.
put
(
"55"
,
"56"
);
typeMaps
.
put
(
"57"
,
"58"
);
typeMaps
.
put
(
"91"
,
"92"
);
typeMaps
.
put
(
"93"
,
"94"
);
}
// key -> TcpCallback
// private static Map<String, TcpCallback<? extends TcpRsp>> callbacks = Maps.newConcurrentMap();
...
...
@@ -166,11 +188,10 @@ public class ProxyHelper {
}
public
static
void
addCallback
(
String
key
,
TcpCallback
<
TcpRsp
>
callback
)
{
TcpCallback
<
TcpRsp
>
tcpRspTcpCallback
=
callbackMap
.
get
(
key
);
if
(
tcpRspTcpCallback
==
null
)
{
callbackMap
.
put
(
key
,
callback
);
}
else
{
callback
=
tcpRspTcpCallback
;
String
[]
split
=
key
.
split
(
"|"
);
if
(
split
.
length
>
1
)
{
callbackMap
.
put
(
split
[
0
],
callback
);
callbackMap
.
put
(
split
[
1
],
callback
);
}
}
...
...
@@ -181,16 +202,17 @@ public class ProxyHelper {
/**
* 获取callback的key
*
* @param data 请求体
* @param data
请求体
* @param channel 通道
* @return
* @param <T>
* @return
*/
public
static
<
T
extends
TcpBase
>
String
getCallbackKey
(
T
data
,
Channel
channel
)
{
if
(
channel
==
null
)
{
if
(
channel
==
null
)
{
throw
new
RuntimeException
(
"channel为null!!!"
);
}
return
channel
.
attr
(
ProxyHelper
.
PILE_ID_KEY
).
get
()
+
"+"
+
data
.
getSeq
();
return
channel
.
attr
(
ProxyHelper
.
PILE_ID_KEY
).
get
()
+
"+"
+
data
.
getSeq
()
+
"|"
+
channel
.
attr
(
ProxyHelper
.
PILE_ID_KEY
).
get
()
+
"+"
+
intToHex
(
data
.
getType
());
}
/**
...
...
@@ -202,12 +224,33 @@ public class ProxyHelper {
*/
public
static
<
T
extends
TcpBase
>
void
setCallback
(
Channel
channel
,
TcpRsp
rsp
)
{
String
key
=
getCallbackKey
(
rsp
,
channel
);
TcpCallback
<
TcpRsp
>
callback
=
ProxyHelper
.
getCallback
(
key
);
String
key
1
=
channel
.
attr
(
ProxyHelper
.
PILE_ID_KEY
).
get
()
+
"+"
+
rsp
.
getSeq
(
);
TcpCallback
<
TcpRsp
>
callback
=
ProxyHelper
.
getCallback
(
key
1
);
if
(
Objects
.
nonNull
(
callback
))
{
callback
.
callback
(
rsp
);
}
else
{
log
.
info
(
"key{},callback为空"
,
key
);
String
key2
=
channel
.
attr
(
ProxyHelper
.
PILE_ID_KEY
).
get
()
+
"+"
+
typeMaps
.
get
(
intToHex
(
rsp
.
getType
()));
TcpCallback
<
TcpRsp
>
tcpRspTcpCallback
=
ProxyHelper
.
getCallback
(
key2
);
if
(
Objects
.
nonNull
(
tcpRspTcpCallback
))
{
callback
.
callback
(
rsp
);
}
else
{
log
.
info
(
"key{},{},callback为空"
,
key1
,
key2
);
}
}
}
private
static
String
intToHex
(
int
n
)
{
//StringBuffer s = new StringBuffer();
StringBuilder
sb
=
new
StringBuilder
(
8
);
String
a
;
char
[]
b
=
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'A'
,
'B'
,
'C'
,
'D'
,
'E'
,
'F'
};
while
(
n
!=
0
){
sb
=
sb
.
append
(
b
[
n
%
16
]);
n
=
n
/
16
;
}
a
=
sb
.
reverse
().
toString
();
return
a
;
}
}
platform-charging/src/test/java/cn/com/glsx/charging/api/FeignSerivceTest.java
View file @
d61157c
...
...
@@ -3,6 +3,7 @@ package cn.com.glsx.charging.api;
import
cn.com.glsx.Application
;
import
cn.com.glsx.evbusiness.api.DataInteractionFeignClient
;
import
cn.com.glsx.evbusiness.modules.model.ocpp16.RealTimeUploadData
;
import
com.glsx.plat.core.web.Result
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -24,7 +25,7 @@ public class FeignSerivceTest {
@Test
public
void
Test
()
throws
Exception
{
Boolean
b
=
dataInteractionFeignClient
.
uploadRealTimeData
(
new
RealTimeUploadData
());
System
.
out
.
println
(
b
);
Result
<
Boolean
>
booleanResult
=
dataInteractionFeignClient
.
uploadRealTimeData
(
new
RealTimeUploadData
()
);
}
}
platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/ModelSetTest.java
View file @
d61157c
...
...
@@ -5,8 +5,13 @@ import cn.com.glsx.charging.modules.gbt.ocpp16.Ocpp16Helper;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.client.TcpClient
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.ModelSetRspData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.ModelValReqData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.TimeSettingReqData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.TimeSettingRspData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.ModelSetRsp
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.ModelValReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.TimeSettingRsp
;
import
cn.com.glsx.charging.util.ByteUtils
;
import
cn.hutool.core.util.HexUtil
;
/**
* 计费模型设置应答
...
...
@@ -26,12 +31,18 @@ public class ModelSetTest {
Thread
.
sleep
(
3000
);
ModelSetRsp
req
=
new
ModelSetRsp
();
/*
ModelSetRsp req = new ModelSetRsp();
req.setData(new ModelSetRspData());
req.getData().setPileId(Ocpp16Helper.strToBcd("55031412782305", req.getData().getPileId()));
req
.
getData
().
setSetResult
((
byte
)
0x01
);
req.getData().setSetResult((byte) 0x01);
*/
client
.
sendSync
(
req
);
TimeSettingRspData
data
=
new
TimeSettingRspData
();
data
.
setPileId
(
Ocpp16Helper
.
strToBcd
(
"55031412782305"
,
data
.
getPileId
()));
TimeSettingRsp
rsp
=
new
TimeSettingRsp
();
rsp
.
setData
(
data
);
client
.
sendSync
(
rsp
);
}
...
...
platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/TimeSettingTest.java
View file @
d61157c
...
...
@@ -58,8 +58,6 @@ public class TimeSettingTest {
TcpCallback
<
TcpRsp
>
callback
=
tcpServer
.
sendSync
(
req
);
Thread
.
sleep
(
10000
);
TcpRsp
rsp
=
callback
.
get
();
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