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 89107f5c
authored
Nov 09, 2023
by
叶立庆
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]测试用例完善、协议转换完善
1 parent
f252dbb5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
49 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/handler/StartMachineRespHandler.java
platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/RemoteChargingTest.java
platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/InteractiveTest.java → platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/TransactionRecordsTest.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/ClientMain.java
View file @
89107f5
...
...
@@ -59,7 +59,7 @@ public class ClientMain {
data
.
setGunNumber
((
byte
)
1
);
data
.
setLogicalCardNumber
(
Ocpp16Helper
.
strToBcd
(
"1000000573"
,
data
.
getLogicalCardNumber
()));
data
.
setPhysicalCardNumber
(
Ocpp16Helper
.
strToBcd
(
"D14B0A54"
,
data
.
getPhysicalCardNumber
()));
data
.
setAccountBalance
(
Ocpp16Helper
.
strToBcd
(
"
00000064
"
,
data
.
getAccountBalance
()));
data
.
setAccountBalance
(
Ocpp16Helper
.
strToBcd
(
"
A0860100
"
,
data
.
getAccountBalance
()));
// Ocpp16Helper.binToBytes()
req
.
setData
(
data
);
client
.
sendSync
(
req
);
...
...
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/StartMachineRespHandler.java
View file @
89107f5
package
cn
.
com
.
glsx
.
charging
.
modules
.
gbt
.
ocpp16
.
tcp
.
handler
;
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.StartMachineRspData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.StartMachineResp
;
import
io.netty.channel.Channel
;
...
...
@@ -14,18 +16,17 @@ public class StartMachineRespHandler implements TcpHandler<StartMachineResp, Sta
@Override
public
StartMachineResp
handle
(
Channel
channel
,
StartMachineResp
startMachineResp
)
{
log
.
info
(
"已经成功接收==StartMachineRespHandler"
);
//68(起始标志)1E(数据长度)0002(序列号域)00(加密标志)33(类型)
//32010200000000111511161555350260(交易流水号)32010200000001(桩编码)01(枪号:1
//枪)01(启动结果:成功)00(失败原因:无)0FE2(帧校验域)
// StartMachineResp resp = new StartMachineResp();
// StartMachineRspData data = new StartMachineRspData();
// data.setTransactionSerialNumber(Ocpp16Helper.strToBcd("32010200000000111511161555350261", data.getTransactionSerialNumber()));
// data.setPileNumber(Ocpp16Helper.strToBcd("32010200000002",data.getPileNumber()));
// data.setGunNumber((byte) 1);
// data.setFailureReason((byte) 0);
// resp.setData(data);
// return resp;
log
.
info
(
"已经成功接收==StartMachineRespHandler"
);
return
null
;
StartMachineResp
resp
=
new
StartMachineResp
();
StartMachineRspData
data
=
new
StartMachineRspData
();
data
.
setTransactionSerialNumber
(
startMachineResp
.
getData
().
getTransactionSerialNumber
());
data
.
setPileId
(
startMachineResp
.
getData
().
getPileId
());
data
.
setGunNumber
((
byte
)
1
);
data
.
setFailureReason
((
byte
)
0
);
resp
.
setData
(
data
);
return
resp
;
}
}
platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/RemoteChargingTest.java
0 → 100644
View file @
89107f5
package
cn
.
com
.
glsx
.
charging
.
gbt
.
ocpp16
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.Ocpp16Helper
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.ServerMain
;
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.data.ShutdownMachineReqData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.StartMachineReqData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.ShutdownMachineReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.StartMachineReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.server.TcpServer
;
import
lombok.extern.slf4j.Slf4j
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.junit.MockitoJUnitRunner
;
/**
* @Description 运营交互帧类型码数据定义协议测试类
* @Author yelq
* @Date 2023/11/7-15:19
* @Version 1.0
*/
@Slf4j
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
RemoteChargingTest
{
private
static
TcpServer
server
;
@Before
public
void
beforeTest
()
throws
InterruptedException
{
Ocpp16Helper
.
scan
();
String
host
=
"localhost"
;
int
port
=
8888
;
server
=
ServerMain
.
start
(
host
,
port
);
Thread
.
sleep
(
10000
);
}
@After
public
void
afterTest
()
throws
InterruptedException
{
Thread
.
sleep
(
30000
);
System
.
out
.
println
(
"========================="
);
}
/**
* 远程关闭充电桩
* @throws Exception
*/
@Test
public
void
shutdownMachineTest
()
throws
Exception
{
ShutdownMachineReq
req
=
new
ShutdownMachineReq
();
ShutdownMachineReqData
data
=
new
ShutdownMachineReqData
();
data
.
setGunNumber
((
byte
)
1
);
data
.
setPileId
(
Ocpp16Helper
.
strToBcd
(
"32010200000001"
,
data
.
getPileId
()));
req
.
setData
(
data
);
server
.
sendSync
(
req
);
}
//远程启动充电桩
@Test
public
void
startMachineReqTest
()
throws
Exception
{
StartMachineReq
req
=
new
StartMachineReq
();
StartMachineReqData
data
=
new
StartMachineReqData
();
data
.
setTransactionSerialNumber
(
Ocpp16Helper
.
strToBcd
(
"32010200000000111511161555350261"
,
data
.
getTransactionSerialNumber
()));
data
.
setPileId
(
Ocpp16Helper
.
strToBcd
(
"32010200000001"
,
data
.
getPileId
()));
data
.
setGunNumber
((
byte
)
1
);
data
.
setLogicalCardNumber
(
Ocpp16Helper
.
strToBcd
(
"0000001000000573"
,
data
.
getLogicalCardNumber
()));
byte
[]
bytes
=
Ocpp16Helper
.
binToBytes
(
Ocpp16Helper
.
hexToBinStr
(
"00000000D14B0A54"
));
data
.
setPhysicalCardNumber
(
bytes
);
byte
[]
accountBytes
=
Ocpp16Helper
.
binToBytes
(
Ocpp16Helper
.
hexToBinStr
(
"A0860100"
));
data
.
setAccountBalance
(
accountBytes
);
req
.
setData
(
data
);
TcpCallback
<
TcpRsp
>
callback
=
server
.
sendSync
(
req
);
TcpRsp
tcpRsp
=
callback
.
get
();
log
.
info
(
"callback:{}"
,
tcpRsp
);
}
}
platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/
Interactive
Test.java
→
platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/
TransactionRecords
Test.java
View file @
89107f5
...
...
@@ -2,14 +2,13 @@ package cn.com.glsx.charging.gbt.ocpp16;
import
cn.com.glsx.charging.modules.gbt.ocpp16.ClientMain
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.Ocpp16Helper
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.ServerMain
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.client.TcpClient
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.ShutdownMachineReqData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.StartMachineReqData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.TransactionRecordsReqData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.ShutdownMachineReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.StartMachineReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.TransactionRecordsReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.server.TcpServer
;
import
cn.com.glsx.charging.util.ByteUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -17,27 +16,28 @@ import org.junit.runner.RunWith;
import
org.mockito.junit.MockitoJUnitRunner
;
/**
* @Description
运营交互帧类型码数据定义协议测试类
* @Description
todo
* @Author yelq
* @Date 2023/11/
7-15:1
9
* @Date 2023/11/
9-15:2
9
* @Version 1.0
*/
@Slf4j
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
InteractiveTest
{
private
TcpClient
client
;
public
class
TransactionRecordsTest
{
private
static
TcpClient
client
;
@Before
public
void
beforeTest
()
throws
InterruptedException
{
Ocpp16Helper
.
scan
();
this
.
client
=
ClientMain
.
getInstance
(
"localhost"
,
8888
);
String
host
=
"localhost"
;
int
port
=
8888
;
client
=
ClientMain
.
getInstance
(
host
,
port
);
Thread
.
sleep
(
3000
);
}
@After
public
void
afterTest
()
throws
InterruptedException
{
Thread
.
sleep
(
3000
);
Thread
.
sleep
(
3000
0
);
System
.
out
.
println
(
"========================="
);
}
...
...
@@ -93,30 +93,4 @@ public class InteractiveTest {
client
.
sendSync
(
req
);
}
@Test
public
void
shutdownMachineTest
()
throws
Exception
{
ShutdownMachineReq
req
=
new
ShutdownMachineReq
();
ShutdownMachineReqData
data
=
new
ShutdownMachineReqData
();
data
.
setGunNumber
((
byte
)
1
);
data
.
setPileId
(
Ocpp16Helper
.
strToBcd
(
"32010200000001"
,
data
.
getPileId
()));
req
.
setData
(
data
);
client
.
sendSync
(
req
);
}
@Test
public
void
startMachineReqTest
()
throws
Exception
{
StartMachineReq
req
=
new
StartMachineReq
();
StartMachineReqData
data
=
new
StartMachineReqData
();
data
.
setTransactionSerialNumber
(
Ocpp16Helper
.
strToBcd
(
"32010200000000111511161555350261"
,
data
.
getTransactionSerialNumber
()));
data
.
setPileId
(
Ocpp16Helper
.
strToBcd
(
"32010200000001"
,
data
.
getPileId
()));
data
.
setGunNumber
((
byte
)
1
);
data
.
setLogicalCardNumber
(
Ocpp16Helper
.
strToBcd
(
"0000001000000573"
,
data
.
getLogicalCardNumber
()));
byte
[]
bytes
=
Ocpp16Helper
.
binToBytes
(
Ocpp16Helper
.
hexToBinStr
(
"00000000D14B0A54"
));
data
.
setPhysicalCardNumber
(
bytes
);
byte
[]
accountBytes
=
Ocpp16Helper
.
binToBytes
(
Ocpp16Helper
.
hexToBinStr
(
"A0860100"
));
data
.
setAccountBalance
(
accountBytes
);
req
.
setData
(
data
);
client
.
sendSync
(
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