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 c1017c49
authored
Nov 07, 2023
by
叶立庆
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]运营平台远程控制启机协议
1 parent
ccac3024
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
328 additions
and
15 deletions
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/ClientMain.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/data/interactive/StartMachineReqData.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/data/interactive/StartMachineRspData.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/interactive/req/StartMachineReqHandler.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/interactive/resp/StartMachineRespHandler.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/protocol/interactive/req/StartMachineReq.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/protocol/interactive/resp/StartMachineResp.java
platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/ClientSimulateTest.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/ClientMain.java
View file @
c1017c4
package
cn
.
com
.
glsx
.
charging
.
modules
.
gbt
.
ocpp16
;
package
cn
.
com
.
glsx
.
charging
.
modules
.
gbt
.
ocpp16
;
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.StartMachineReqData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.login.LoginReqData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.login.LoginReqData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.req.StartMachineReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.login.LoginReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.login.LoginReq
;
import
cn.com.glsx.charging.util.ByteUtils
;
public
class
ClientMain
{
public
class
ClientMain
{
...
@@ -33,28 +36,40 @@ public class ClientMain {
...
@@ -33,28 +36,40 @@ public class ClientMain {
public
static
void
main
(
String
[]
args
)
throws
Exception
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
Ocpp16Helper
.
scan
();
Ocpp16Helper
.
scan
();
String
host
=
"12
1.199.192.223
"
;
String
host
=
"12
7.0.0.1
"
;
int
port
=
8
76
8
;
int
port
=
8
88
8
;
TcpClient
client
=
getInstance
(
host
,
port
);
TcpClient
client
=
getInstance
(
host
,
port
);
// TcpClient client = getInstance();
// TcpClient client = getInstance();
Thread
.
sleep
(
3000
);
Thread
.
sleep
(
3000
);
LoginReq
req
=
new
LoginReq
();
// LoginReq req = new LoginReq();
req
.
setData
(
new
LoginReqData
());
// req.setData(new LoginReqData());
req
.
getData
().
setPointId
(
Ocpp16Helper
.
strToBcd
(
"55031412782305"
,
req
.
getData
().
getPointId
()));
// req.getData().setPointId(Ocpp16Helper.strToBcd("55031412782305", req.getData().getPointId()));
req
.
getData
().
setPointType
((
byte
)
0
);
// req.getData().setPointType((byte) 0);
req
.
getData
().
setGunCount
((
byte
)
2
);
// req.getData().setGunCount((byte) 2);
req
.
getData
().
setSoftVersion
(
Ocpp16Helper
.
strToBcd
(
"v4.1.50"
,
req
.
getData
().
getSoftVersion
()));
// req.getData().setSoftVersion(Ocpp16Helper.strToBcd("v4.1.50", req.getData().getSoftVersion()));
req
.
getData
().
setProtocolVersion
((
byte
)
10
);
// req.getData().setProtocolVersion((byte) 10);
//
// client.sendSync(req);
StartMachineReq
req
=
new
StartMachineReq
();
StartMachineReqData
data
=
new
StartMachineReqData
();
data
.
setTransactionSerialNumber
(
Ocpp16Helper
.
strToBcd
(
"32010200000000111511161555350260"
,
data
.
getTransactionSerialNumber
()));
data
.
setPileNumber
(
Ocpp16Helper
.
strToBcd
(
"32010200000001"
,
data
.
getPileNumber
()));
data
.
setGunNumber
((
byte
)
1
);
data
.
setLogicalCardNumber
(
Ocpp16Helper
.
strToBcd
(
"1000000573"
,
data
.
getLogicalCardNumber
()));
data
.
setPhysicalCardNumber
(
Ocpp16Helper
.
strToBcd
(
"D14B0A54"
,
data
.
getPhysicalCardNumber
()));
data
.
setAccountBalance
(
Ocpp16Helper
.
strToBcd
(
"A0860100"
,
data
.
getAccountBalance
()));
// Ocpp16Helper.binToBytes()
req
.
setData
(
data
);
client
.
sendSync
(
req
);
client
.
sendSync
(
req
);
System
.
out
.
println
(
"========================="
);
while
(
true
)
{
//
while (true) {
Thread
.
sleep
(
300
);
//
Thread.sleep(300);
client
.
sendSync
(
req
);
//
client.sendSync(req);
}
//
}
// 定期心跳
// 定期心跳
...
...
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/base/TcpMapper.java
View file @
c1017c4
package
cn
.
com
.
glsx
.
charging
.
modules
.
gbt
.
ocpp16
.
tcp
.
base
;
package
cn
.
com
.
glsx
.
charging
.
modules
.
gbt
.
ocpp16
.
tcp
.
base
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.interactive.req.StartMachineReqHandler
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.interactive.resp.StartMachineRespHandler
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.login.req.ModelChargingReqHandler
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.login.req.ModelChargingReqHandler
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.login.req.ModelValReqHandler
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.login.req.ModelValReqHandler
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -51,6 +53,13 @@ public final class TcpMapper {
...
@@ -51,6 +53,13 @@ public final class TcpMapper {
public
static
TcpMapper
CMD_NOTIFY_TIME
=
regist
(
0x56
,
"对时设置"
,
TimeNotifyHandler
.
class
);
public
static
TcpMapper
CMD_NOTIFY_TIME
=
regist
(
0x56
,
"对时设置"
,
TimeNotifyHandler
.
class
);
//运营交互帧类型码数据定义 0x31~0x47
public
static
TcpMapper
FTCD_RSP_REMOTE_START_CHARGING
=
regist
(
0x33
,
"远程启动充电命令回复"
,
StartMachineRespHandler
.
class
);
public
static
TcpMapper
FTCD_REQ_REMOTE_CONTROL_STARTUP
=
regist
(
0x34
,
"运营平台远程控制启机"
,
StartMachineReqHandler
.
class
);
public
static
TcpMapper
FTCD_RSP_REMOTE_SHUTDOWN
=
regist
(
0x35
,
"远程停机命令回复"
,
null
);
public
static
TcpMapper
FTCD_REQ_REMOTE_SHUTDOWN
=
regist
(
0x36
,
"运营平台远程停机"
,
null
);
public
static
TcpMapper
FTCD_REQ_TRANSACTION_RECORDS
=
regist
(
0x3B
,
"交易记录"
,
null
);
public
static
TcpMapper
FTCD_RSP_TRANSACTION_CONFIRMATION
=
regist
(
0x40
,
"交易记录确认"
,
null
);
public
static
TcpMapper
fromType
(
byte
type
)
{
public
static
TcpMapper
fromType
(
byte
type
)
{
TcpMapper
c
=
mappers
.
get
(
type
);
TcpMapper
c
=
mappers
.
get
(
type
);
if
(
c
==
null
)
{
if
(
c
==
null
)
{
...
...
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/data/interactive/StartMachineReqData.java
0 → 100644
View file @
c1017c4
package
cn
.
com
.
glsx
.
charging
.
modules
.
gbt
.
ocpp16
.
tcp
.
data
.
interactive
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.Ocpp16Helper
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpData
;
import
lombok.Getter
;
import
lombok.Setter
;
/**
* @Description 当用户通过远程启动充电时,发送本命令
* 报文示例:
* 68 (起始标志) 30 (数据长度) 007C (序列号域) 00 (加密标志) 34 (类型)
* 55031412782305012018061914444680(交易流水号)55031412782305(桩编码)01(枪号:1
* 枪)0000001000000573(逻辑卡号:1000000573)00000000D14B0A54(物理卡号:D14B0A54)
* A0860100(账户余额:1000.00)4622
* @Author yelq
* @Date 2023/11/6-19:16
* @Version 1.0
*/
@Getter
@Setter
public
class
StartMachineReqData
extends
TcpData
{
/**
* 交易流水号
* 数据类型: (BCD码)
* 长度(Byte):16
* 备注:见名词解释
*/
private
byte
[]
transactionSerialNumber
=
new
byte
[
16
];
/**
* 桩编号
* 数据类型: (BCD码)
* 长度(Byte):7
* 备注:不足7位补0
*/
private
byte
[]
pileNumber
=
new
byte
[
7
];
/**
* 枪号
* 数据类型: (BCD码)
* 长度(Byte):1
* 备注:
*/
private
byte
gunNumber
;
/**
* 逻辑卡号
* 数据类型: (BCD码)
* 长度(Byte):8
* 备注:显示在屏幕上,不足补零,逻辑卡号为卡面印刷卡号
*/
private
byte
[]
logicalCardNumber
=
new
byte
[
8
];
/**
* 物理卡号
* 数据类型: (BIN码)
* 长度(Byte):8
* 备注:不足补零,桩与平台交互需使用的物理卡号
*/
private
byte
[]
physicalCardNumber
=
new
byte
[
8
];
/**
* 账户余额
* 数据类型: (BIN码)
* 长度(Byte):4
* 备注:保留到小数点两位
*/
private
byte
[]
accountBalance
=
new
byte
[
4
];
/**
* 将字节数组转换为二进制字符串
* @param bytes 字节数组
* @return 二进制字符串
*/
public
static
String
bytesToBinaryString
(
byte
[]
bytes
)
{
StringBuilder
binaryString
=
new
StringBuilder
();
for
(
byte
b
:
bytes
)
{
for
(
int
i
=
7
;
i
>=
0
;
i
--)
{
binaryString
.
append
((
b
>>
i
)
&
1
);
}
}
return
binaryString
.
toString
();
}
/**
* 将字节数组转换为十进制数
* @param bytes 字节数组
* @return 十进制数
*/
public
static
long
bytesToDecimal
(
byte
[]
bytes
)
{
long
decimal
=
0
;
for
(
int
i
=
0
;
i
<
bytes
.
length
;
i
++)
{
decimal
=
(
decimal
<<
8
)
|
(
bytes
[
i
]
&
0xFF
);
}
return
decimal
;
}
//0000100011001011
public
static
void
main
(
String
[]
args
)
{
byte
[]
bytes1
=
Ocpp16Helper
.
binToBytes
(
"0000100011001011"
);
System
.
out
.
println
(
bytesToDecimal
(
bytes1
));
System
.
out
.
println
(
bytesToBinaryString
(
bytes1
));
}
}
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/data/interactive/StartMachineRspData.java
0 → 100644
View file @
c1017c4
package
cn
.
com
.
glsx
.
charging
.
modules
.
gbt
.
ocpp16
.
tcp
.
data
.
interactive
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpData
;
import
lombok.Getter
;
import
lombok.Setter
;
/**
* @Description 远程启动充电命令回复
* 样例报文
* 68(起始标志)1E(数据长度)0002(序列号域)00(加密标志)33(类型)
* 32010200000000111511161555350260(交易流水号)32010200000001(桩编码)01(枪号:1
* 枪)01(启动结果:成功)00(失败原因:无)0FE2(帧校验域)
* @Author yelq
* @Date 2023/11/6-20:23
* @Version 1.0
*/
@Getter
@Setter
public
class
StartMachineRspData
extends
TcpData
{
/**
* 交易流水号
* 数据类型:byte[] (BCD码)
* 长度(Byte):16
* 备注:
*/
private
byte
[]
transactionSerialNumber
=
new
byte
[
16
];
/**
* 桩编号
* 数据类型:byte[] (BCD码)
* 长度(Byte):7
* 备注:不足7位补0
*/
private
byte
[]
pileNumber
=
new
byte
[
7
];
/**
* 枪号
* 数据类型:byte[] (BCD码)
* 长度(Byte):1
* 备注:
*/
private
byte
gunNumber
;
/**
* 启动结果
* 数据类型:byte[] (BCD码)
* 长度(Byte):1
* 备注:0x00失败 0x01成功
*/
private
byte
startResult
;
/**
* 失败原因
* 数据类型:byte[] (BIN码)
* 长度(Byte):1
* 备注:
* 0x00 无
* 0x01 设备编号不匹配
* 0x02 枪已在充电
* 0x03 设备故障
* 0x04 设备离线
* 0x05 未插枪
* 桩在收到启充命令后,检测到未插枪则发送0x33报文回复充电失败。
* 若在60秒(以收到0x34时间开始计算)内检测到枪重新连接,
* 则补送0x33成功报文;超时或者离线等其他异常,桩不启充、不补发0x33报文。
*/
private
byte
failureReason
;
}
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/interactive/req/StartMachineReqHandler.java
0 → 100644
View file @
c1017c4
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.StartMachineRspData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.req.StartMachineReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.resp.StartMachineResp
;
import
cn.com.glsx.charging.util.ByteUtils
;
import
io.netty.channel.Channel
;
/**
* @Description 远程启动充电请求处理类
* @Author yelq
* @Date 2023/11/6-20:16
* @Version 1.0
*/
public
class
StartMachineReqHandler
implements
TcpHandler
<
StartMachineReq
,
StartMachineResp
>
{
@Override
public
StartMachineResp
handle
(
Channel
channel
,
StartMachineReq
startMachineReq
)
{
StartMachineResp
resp
=
new
StartMachineResp
();
StartMachineRspData
data
=
new
StartMachineRspData
();
data
.
setTransactionSerialNumber
(
Ocpp16Helper
.
strToBcd
(
"32010200000000111511161555350260"
,
data
.
getTransactionSerialNumber
()));
data
.
setPileNumber
(
Ocpp16Helper
.
strToBcd
(
"32010200000001"
,
data
.
getPileNumber
()));
data
.
setGunNumber
((
byte
)
1
);
data
.
setFailureReason
((
byte
)
0
);
resp
.
setData
(
data
);
return
resp
;
}
}
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/interactive/resp/StartMachineRespHandler.java
0 → 100644
View file @
c1017c4
package
cn
.
com
.
glsx
.
charging
.
modules
.
gbt
.
ocpp16
.
tcp
.
handler
.
interactive
.
resp
;
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.StartMachineRspData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.req.StartMachineReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.resp.StartMachineResp
;
import
cn.com.glsx.charging.util.ByteUtils
;
import
io.netty.channel.Channel
;
/**
* @Description 远程启动充电命令回复处理类
* @Author yelq
* @Date 2023/11/6-20:16
* @Version 1.0
*/
public
class
StartMachineRespHandler
implements
TcpHandler
<
StartMachineResp
,
StartMachineResp
>
{
@Override
public
StartMachineResp
handle
(
Channel
channel
,
StartMachineResp
startMachineResp
)
{
//68(起始标志)1E(数据长度)0002(序列号域)00(加密标志)33(类型)
//32010200000000111511161555350260(交易流水号)32010200000001(桩编码)01(枪号:1
//枪)01(启动结果:成功)00(失败原因:无)0FE2(帧校验域)
StartMachineResp
resp
=
new
StartMachineResp
();
StartMachineRspData
data
=
new
StartMachineRspData
();
data
.
setTransactionSerialNumber
(
Ocpp16Helper
.
strToBcd
(
"32010200000000111511161555350260"
,
data
.
getTransactionSerialNumber
()));
data
.
setPileNumber
(
Ocpp16Helper
.
strToBcd
(
"32010200000001"
,
data
.
getPileNumber
()));
data
.
setGunNumber
((
byte
)
1
);
data
.
setFailureReason
((
byte
)
0
);
resp
.
setData
(
data
);
return
resp
;
}
}
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/protocol/interactive/req/StartMachineReq.java
0 → 100644
View file @
c1017c4
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.StartMachineReqData
;
/**
* @Description todo
* @Author yelq
* @Date 2023/11/6-19:14
* @Version 1.0
*/
public
class
StartMachineReq
extends
TcpReq
<
StartMachineReqData
>
{
public
StartMachineReq
()
{
super
(
TcpMapper
.
FTCD_REQ_REMOTE_CONTROL_STARTUP
.
getType
());
}
}
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/protocol/interactive/resp/StartMachineResp.java
0 → 100644
View file @
c1017c4
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.TcpRsp
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive.StartMachineRspData
;
/**
* @Description 远程启动充电命令回复
* @Author yelq
* @Date 2023/11/6-20:26
* @Version 1.0
*/
public
class
StartMachineResp
extends
TcpRsp
<
StartMachineRspData
>
{
public
StartMachineResp
()
{
super
(
TcpMapper
.
FTCD_RSP_REMOTE_START_CHARGING
.
getType
());
}
}
platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/ClientSimulateTest.java
View file @
c1017c4
package
cn
.
com
.
glsx
.
charging
.
gbt
.
ocpp16
;
package
cn
.
com
.
glsx
.
charging
.
gbt
.
ocpp16
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.req.StartMachineReq
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.ClientMain
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.ClientMain
;
...
@@ -23,6 +24,26 @@ import cn.com.glsx.charging.util.CrcUtils;
...
@@ -23,6 +24,26 @@ import cn.com.glsx.charging.util.CrcUtils;
public
class
ClientSimulateTest
{
public
class
ClientSimulateTest
{
@Test
@Test
public
void
Test
()
throws
Exception
{
//6830007C0034550314127823050120180619144446805503141278230501000000100000057300000000D14B0A54A08601004622
Ocpp16Helper
.
scan
();
// 68(起始标志)0C(数据长度)0000(序列号域)00(加密标志)02(类型)55 03 14 12 78 23 05(桩编码)00(登陆结果:成功)DA 4C(帧校验域)
String
hex
=
"6830007C0034550314127823050120180619144446805503141278230501000000100000057300000000D14B0A54A08601004622"
;
System
.
out
.
println
(
hex
);
byte
[]
bytes
=
ByteUtils
.
fromHex
(
hex
);
StartMachineReq
rsp
=
Ocpp16Helper
.
parse
(
bytes
);
System
.
out
.
println
(
"expect: "
+
rsp
.
getCrc
());
byte
[]
data
=
ByteUtils
.
getBytes
(
bytes
,
2
,
bytes
.
length
-
4
);
System
.
out
.
println
(
"actual: "
+
CrcUtils
.
calculateCRC
(
data
));
System
.
out
.
println
(
"actual1: "
+
CrcUtils
.
calculateCRC1
(
data
));
System
.
out
.
println
(
"actual2: "
+
CrcUtils
.
calculateCRC2
(
data
));
System
.
out
.
println
(
"actual3: "
+
CrcUtils
.
calculateCRC3
(
data
));
}
@Test
public
void
testCrc
()
{
public
void
testCrc
()
{
Ocpp16Helper
.
scan
();
Ocpp16Helper
.
scan
();
...
...
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