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 e75ea41c
authored
Nov 07, 2023
by
叶立庆
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]交易记录协议
1 parent
72852134
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
162 additions
and
5 deletions
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/data/interactive/TransactionRecordsReqData.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/data/interactive/TransactionRecordsRespData.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/interactive/req/ShutdownMachineReqHandler.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/interactive/req/TransactionRecordsReqHandler.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/interactive/resp/TransactionRecordsRespHandler.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/protocol/interactive/req/TransactionRecordsReq.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/protocol/interactive/resp/TransactionRecordsResp.java
platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/InteractiveTest.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/base/TcpMapper.java
View file @
e75ea41
...
@@ -2,6 +2,8 @@ package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base;
...
@@ -2,6 +2,8 @@ package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base;
import
java.util.Map
;
import
java.util.Map
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.interactive.req.TransactionRecordsReqHandler
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.interactive.resp.TransactionRecordsRespHandler
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.google.common.collect.Maps
;
import
com.google.common.collect.Maps
;
...
@@ -69,9 +71,9 @@ public final class TcpMapper {
...
@@ -69,9 +71,9 @@ public final class TcpMapper {
public
static
TcpMapper
CMD_REQ_STOP_CHARGING
=
regist
(
0x36
,
"运营平台远程停机"
,
ShutdownMachineReqHandler
.
class
);
public
static
TcpMapper
CMD_REQ_STOP_CHARGING
=
regist
(
0x36
,
"运营平台远程停机"
,
ShutdownMachineReqHandler
.
class
);
public
static
TcpMapper
CMD_REQ_TRADE_UPLOAD
=
regist
(
0x3B
,
"交易记录上报"
,
null
);
public
static
TcpMapper
CMD_REQ_TRADE_UPLOAD
=
regist
(
0x3B
,
"交易记录上报"
,
TransactionRecordsReqHandler
.
class
);
public
static
TcpMapper
CMD_RSP_TRADE_UPLOAD
=
regist
(
0x40
,
"交易记录上报确认"
,
null
);
public
static
TcpMapper
CMD_RSP_TRADE_UPLOAD
=
regist
(
0x40
,
"交易记录上报确认"
,
TransactionRecordsRespHandler
.
class
);
public
static
TcpMapper
CMD_REQ_CFG_DOWNLOAD
=
regist
(
0x52
,
"充电桩工作参数设置"
,
ParamSettingReqHandler
.
class
);
public
static
TcpMapper
CMD_REQ_CFG_DOWNLOAD
=
regist
(
0x52
,
"充电桩工作参数设置"
,
ParamSettingReqHandler
.
class
);
...
...
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/data/interactive/TransactionRecordsReqData.java
View file @
e75ea41
...
@@ -43,7 +43,7 @@ public class TransactionRecordsReqData extends TcpData {
...
@@ -43,7 +43,7 @@ public class TransactionRecordsReqData extends TcpData {
* 长度(Byte):7
* 长度(Byte):7
* 备注:不足7位补0
* 备注:不足7位补0
*/
*/
private
byte
[]
devic
eNumber
=
new
byte
[
7
];
private
byte
[]
pil
eNumber
=
new
byte
[
7
];
/**
/**
* 参数名称:枪号
* 参数名称:枪号
...
...
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/data/interactive/TransactionRecordsRespData.java
View file @
e75ea41
...
@@ -6,6 +6,11 @@ import lombok.Setter;
...
@@ -6,6 +6,11 @@ import lombok.Setter;
/**
/**
* @Description 交易记录确认
* @Description 交易记录确认
* 功能 运营平台接收到结算账单上传后,都需回复此确认信息。若桩未收到回复帧,则 5 分钟后继续
* 上送一次交易记录,此情况下无论平台是否成功回复都停止上送。这一帧仅是报文交互使用,
* 意指平台成功接收到交易记录报文,并不代表交易订单成功结算
* 样例报文 68(起始标志)15(数据长度)0002(序列号域)00(加密标志)40(类型)
* 55031412782305012018061910262392(交易流水号)00(确认结果)48B1(帧校验域)
* @Author yelq
* @Author yelq
* @Date 2023/11/7-16:57
* @Date 2023/11/7-16:57
* @Version 1.0
* @Version 1.0
...
@@ -13,4 +18,19 @@ import lombok.Setter;
...
@@ -13,4 +18,19 @@ import lombok.Setter;
@Getter
@Getter
@Setter
@Setter
public
class
TransactionRecordsRespData
extends
TcpData
{
public
class
TransactionRecordsRespData
extends
TcpData
{
/**
* 交易流水号
* 数据类型:byte[] (BCD码)
* 长度(Byte):16
* 备注:
*/
private
byte
[]
transactionSerialNumber
=
new
byte
[
16
];
/**
* 确认结果
* 数据类型:byte (BIN码)
* 长度(Byte):1
* 备注:0x00 上传成功 0x01 非法账单
*/
private
byte
confirmResult
;
}
}
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/interactive/req/ShutdownMachineReqHandler.java
View file @
e75ea41
...
@@ -20,8 +20,8 @@ public class ShutdownMachineReqHandler implements TcpHandler<ShutdownMachineReq,
...
@@ -20,8 +20,8 @@ public class ShutdownMachineReqHandler implements TcpHandler<ShutdownMachineReq,
@Override
@Override
public
ShutdownMachineResp
handle
(
Channel
channel
,
ShutdownMachineReq
shutdownMachineReq
)
{
public
ShutdownMachineResp
handle
(
Channel
channel
,
ShutdownMachineReq
shutdownMachineReq
)
{
/**请求日志打印*/
/**请求日志打印*/
log
.
info
(
"桩编号:
"
+
Ocpp16Helper
.
bcdToStr
(
shutdownMachineReq
.
getData
().
getPileNumber
()));
log
.
info
(
"桩编号:
{}"
,
Ocpp16Helper
.
bcdToStr
(
shutdownMachineReq
.
getData
().
getPileNumber
()));
log
.
info
(
"枪号:
"
+
shutdownMachineReq
.
getData
().
getGunNumber
());
log
.
info
(
"枪号:
{}"
,
shutdownMachineReq
.
getData
().
getGunNumber
());
/**请求日志打印*/
/**请求日志打印*/
ShutdownMachineResp
resp
=
new
ShutdownMachineResp
();
ShutdownMachineResp
resp
=
new
ShutdownMachineResp
();
ShutdownMachineRespData
data
=
new
ShutdownMachineRespData
();
ShutdownMachineRespData
data
=
new
ShutdownMachineRespData
();
...
...
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/interactive/req/TransactionRecordsReqHandler.java
0 → 100644
View file @
e75ea41
package
cn
.
com
.
glsx
.
charging
.
modules
.
gbt
.
ocpp16
.
tcp
.
handler
.
interactive
.
req
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.Ocpp16Helper
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpHandler
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive.TransactionRecordsReqData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive.TransactionRecordsRespData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.req.TransactionRecordsReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.resp.TransactionRecordsResp
;
import
cn.com.glsx.charging.util.ByteUtils
;
import
io.netty.channel.Channel
;
/**
* @Description 运营平台接收到结算账单上传后,都需回复此确认信息。若桩未收到回复帧,则 5 分钟后继续
* 上送一次交易记录,此情况下无论平台是否成功回复都停止上送。这一帧仅是报文交互使用,
* 意指平台成功接收到交易记录报文,并不代表交易订单成功结算
* @Author yelq
* @Date 2023/11/7-17:37
* @Version 1.0
*/
public
class
TransactionRecordsReqHandler
implements
TcpHandler
<
TransactionRecordsReq
,
TransactionRecordsResp
>
{
@Override
public
TransactionRecordsResp
handle
(
Channel
channel
,
TransactionRecordsReq
transactionRecordsReq
)
{
TransactionRecordsReqData
reqData
=
transactionRecordsReq
.
getData
();
/**解析参数日志打印*/
log
.
info
(
"交易流水号:{}"
,
Ocpp16Helper
.
bcdToStr
(
reqData
.
getTransactionSerialNumber
()));
String
pileNumber
=
Ocpp16Helper
.
bcdToStr
(
reqData
.
getPileNumber
());
log
.
info
(
"桩编号:{}"
,
pileNumber
);
log
.
info
(
"开始时间:{}"
,
ByteUtils
.
parseCp56Time2aStr
(
reqData
.
getStartTime
()));
log
.
info
(
"结束时间:{}"
,
ByteUtils
.
parseCp56Time2aStr
(
reqData
.
getEndTime
()));
log
.
info
(
"电动汽车唯一标识:{}"
,
Ocpp16Helper
.
bcdToStr
(
reqData
.
getVehicleIdentifier
()));
log
.
info
(
"峰单价:{}"
,
Ocpp16Helper
.
bcdToStr
(
reqData
.
getTopUnitPrice
()));
/**解析参数日志打印*/
TransactionRecordsResp
resp
=
new
TransactionRecordsResp
();
TransactionRecordsRespData
data
=
new
TransactionRecordsRespData
();
data
.
setTransactionSerialNumber
(
Ocpp16Helper
.
strToBcd
(
"55031412782305012018061910262392"
,
data
.
getTransactionSerialNumber
()));
data
.
setConfirmResult
((
byte
)
0
);
resp
.
setData
(
data
);
return
resp
;
}
}
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/interactive/resp/TransactionRecordsRespHandler.java
0 → 100644
View file @
e75ea41
package
cn
.
com
.
glsx
.
charging
.
modules
.
gbt
.
ocpp16
.
tcp
.
handler
.
interactive
.
resp
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpHandler
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.resp.TransactionRecordsResp
;
import
io.netty.channel.Channel
;
/**
* @Description 交易记录确认
* 功能 运营平台接收到结算账单上传后,都需回复此确认信息。若桩未收到回复帧,则 5 分钟后继续
* 上送一次交易记录,此情况下无论平台是否成功回复都停止上送。这一帧仅是报文交互使用,
* 意指平台成功接收到交易记录报文,并不代表交易订单成功结算
* @Author yelq
* @Date 2023/11/7-17:37
* @Version 1.0
*/
public
class
TransactionRecordsRespHandler
implements
TcpHandler
<
TransactionRecordsResp
,
TransactionRecordsResp
>
{
@Override
public
TransactionRecordsResp
handle
(
Channel
channel
,
TransactionRecordsResp
transactionRecordsResp
)
{
log
.
info
(
"客户端已经收到返回"
);
return
null
;
}
}
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/protocol/interactive/req/TransactionRecordsReq.java
0 → 100644
View file @
e75ea41
package
cn
.
com
.
glsx
.
charging
.
modules
.
gbt
.
ocpp16
.
tcp
.
protocol
.
interactive
.
req
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpMapper
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive.TransactionRecordsReqData
;
/**
* @Description 交易记录上报
* @Author yelq
* @Date 2023/11/7-17:38
* @Version 1.0
*/
public
class
TransactionRecordsReq
extends
TcpReq
<
TransactionRecordsReqData
>
{
public
TransactionRecordsReq
()
{
super
(
TcpMapper
.
CMD_REQ_TRADE_UPLOAD
.
getType
());
}
}
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/protocol/interactive/resp/TransactionRecordsResp.java
0 → 100644
View file @
e75ea41
package
cn
.
com
.
glsx
.
charging
.
modules
.
gbt
.
ocpp16
.
tcp
.
protocol
.
interactive
.
resp
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpMapper
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive.TransactionRecordsReqData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive.TransactionRecordsRespData
;
/**
* @Description 交易记录确认
* 功能 运营平台接收到结算账单上传后,都需回复此确认信息。若桩未收到回复帧,则 5 分钟后继续
* 上送一次交易记录,此情况下无论平台是否成功回复都停止上送。这一帧仅是报文交互使用,
* 意指平台成功接收到交易记录报文,并不代表交易订单成功结算
* @Author yelq
* @Date 2023/11/7-17:38
* @Version 1.0
*/
public
class
TransactionRecordsResp
extends
TcpReq
<
TransactionRecordsRespData
>
{
public
TransactionRecordsResp
()
{
super
(
TcpMapper
.
CMD_RSP_TRADE_UPLOAD
.
getType
());
}
}
platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/InteractiveTest.java
View file @
e75ea41
...
@@ -5,8 +5,10 @@ import cn.com.glsx.charging.modules.gbt.ocpp16.Ocpp16Helper;
...
@@ -5,8 +5,10 @@ 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.client.TcpClient
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive.ShutdownMachineReqData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive.ShutdownMachineReqData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive.StartMachineReqData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive.StartMachineReqData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive.TransactionRecordsReqData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.req.ShutdownMachineReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.req.ShutdownMachineReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.req.StartMachineReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.req.StartMachineReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.req.TransactionRecordsReq
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
org.mockito.junit.MockitoJUnitRunner
;
...
@@ -22,6 +24,37 @@ import org.mockito.junit.MockitoJUnitRunner;
...
@@ -22,6 +24,37 @@ import org.mockito.junit.MockitoJUnitRunner;
public
class
InteractiveTest
{
public
class
InteractiveTest
{
@Test
@Test
public
void
transactionRecordsTest
()
throws
Exception
{
Ocpp16Helper
.
scan
();
TcpClient
client
=
ClientMain
.
getInstance
(
"localhost"
,
8888
);
Thread
.
sleep
(
3000
);
/**
* 样例报文 68 (起始标志) A2 (数据长度) 8001 (序列号域) 00 (加密标志) 3B (类型)
* 55031412782305012018061910262392(交易流水号)55031412782305(桩编码)01(枪号:1
* 枪)98B70E11100314(开始时间:2020-03-16 17:14:47)98B70E11100314(结束时间:2020-03-16
* 17:14:47)D0FB0100(尖单价:1.30000)00000000(尖电量:0)00000000(计损尖电量:0)
* 00000000(尖金额:0)D0FB0100(峰单价: 1.30000)00000000(峰电量:0)00000000(计损
* 峰电量:0)00000000(峰金额:0)D0FB0100(平单价: 1.30000)00000000(平电量:0)00000000
* (计损平电量:0)00000000(平金额:0)D0FB0100(谷单价: 1.30000)00000000(谷电量:
* 0)00000000(计损谷电量:0)00000000(谷金额:0)0000000000(电表总起值:0)0000000000
* (电表总止值:0)00000000(总电量:0)00000000(计损总电量:0)00000000(消费金额:
* 0)0000000000000000000000000000000000(VIN 码)02(交易标识:app 启动)98B70E11100314
* (交易时间:2020-03-16 17:14:47)00(停止原因:无)00000000D14B0A54(物理卡号:D14B0A54)
*/
TransactionRecordsReq
req
=
new
TransactionRecordsReq
();
TransactionRecordsReqData
data
=
new
TransactionRecordsReqData
();
data
.
setTransactionSerialNumber
(
Ocpp16Helper
.
strToBcd
(
"55031412782305012018061910262392"
,
data
.
getTransactionSerialNumber
()));
data
.
setGunNumber
((
byte
)
1
);
data
.
setPileNumber
(
Ocpp16Helper
.
strToBcd
(
"32010200000001"
,
data
.
getPileNumber
()));
data
.
setTopUnitPrice
(
Ocpp16Helper
.
strToBcd
(
"D0FB0100"
,
data
.
getTopUnitPrice
()));
data
.
setVehicleIdentifier
(
Ocpp16Helper
.
strToBcd
(
"0000000000000000000000000000000001"
,
data
.
getVehicleIdentifier
()));
req
.
setData
(
data
);
client
.
sendSync
(
req
);
Thread
.
sleep
(
3000
);
System
.
out
.
println
(
"========================="
);
}
@Test
public
void
shutdownMachineTest
()
throws
Exception
{
public
void
shutdownMachineTest
()
throws
Exception
{
Ocpp16Helper
.
scan
();
Ocpp16Helper
.
scan
();
TcpClient
client
=
ClientMain
.
getInstance
(
"localhost"
,
8888
);
TcpClient
client
=
ClientMain
.
getInstance
(
"localhost"
,
8888
);
...
...
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