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 46365e7a
authored
Nov 09, 2023
by
叶立庆
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]测试用例完善、协议转换完善
1 parent
b6c62fce
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
109 additions
and
50 deletions
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/ShutdownMachineReqHandler.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/StartMachineReqHandler.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/TransactionRecordsReqHandler.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/TransactionRecordsRespHandler.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/handler/ShutdownMachineReqHandler.java
View file @
46365e7
...
...
@@ -25,10 +25,10 @@ public class ShutdownMachineReqHandler implements TcpHandler<ShutdownMachineReq,
/**请求日志打印*/
ShutdownMachineResp
resp
=
new
ShutdownMachineResp
();
ShutdownMachineRespData
data
=
new
ShutdownMachineRespData
();
data
.
setPileId
(
Ocpp16Helper
.
strToBcd
(
"32010200000001"
,
data
.
getPileId
()
));
data
.
setGunNumber
(
(
byte
)
1
);
data
.
setPileId
(
shutdownMachineReq
.
getData
().
getPileId
(
));
data
.
setGunNumber
(
shutdownMachineReq
.
getData
().
getGunNumber
()
);
data
.
setShutdownResult
((
byte
)
1
);
data
.
setFailureReason
((
byte
)
0
);
data
.
setFailureReason
((
byte
)
0
x00
);
resp
.
setData
(
data
);
return
resp
;
}
...
...
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/StartMachineReqHandler.java
View file @
46365e7
...
...
@@ -9,6 +9,7 @@ import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.StartMachineReqData;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.StartMachineRspData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.StartMachineReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.StartMachineResp
;
import
cn.com.glsx.charging.util.ByteUtils
;
import
io.netty.channel.Channel
;
/**
...
...
@@ -23,28 +24,26 @@ public class StartMachineReqHandler implements TcpHandler<StartMachineReq, Start
/**请求参数打印*/
StartMachineReqData
reqData
=
startMachineReq
.
getData
();
String
transactionSerialNumber
=
Ocpp16Helper
.
bcdToStr
(
reqData
.
getTransactionSerialNumber
());
System
.
out
.
println
(
"交易流水号"
+
transactionSerialNumber
);
String
pile
Number
=
Ocpp16Helper
.
bcdToStr
(
reqData
.
getPileId
());
System
.
out
.
println
(
"桩编号"
+
pileNumber
);
log
.
info
(
"交易流水号:{}"
,
transactionSerialNumber
);
String
pile
Id
=
Ocpp16Helper
.
bcdToStr
(
reqData
.
getPileId
());
log
.
info
(
"桩编号:{}"
,
pileId
);
byte
gunNumber
=
reqData
.
getGunNumber
();
System
.
out
.
println
(
"枪号"
+
gunNumber
);
log
.
info
(
"枪号:{}"
,
gunNumber
);
String
logicalCardNumber
=
Ocpp16Helper
.
bcdToStr
(
reqData
.
getLogicalCardNumber
());
System
.
out
.
println
(
"逻辑卡号"
+
logicalCardNumber
);
String
physicalCardNumber
=
Ocpp16Helper
.
bcdToStr
(
reqData
.
getPhysicalCardNumber
());
System
.
out
.
println
(
"物理卡号"
+
physicalCardNumber
);
String
accountBalance
=
Ocpp16Helper
.
bcdToStr
(
reqData
.
getAccountBalance
());
long
aLong
=
Ocpp16Helper
.
binaryStringToLong
(
Ocpp16Helper
.
hexToBinaryString
(
accountBalance
));
BigDecimal
divide
=
new
BigDecimal
(
String
.
valueOf
(
aLong
)).
divide
(
new
BigDecimal
(
"100"
),
2
,
RoundingMode
.
HALF_DOWN
);
System
.
out
.
println
(
"账户余额"
+
divide
);
log
.
info
(
"逻辑卡号:{}"
,
logicalCardNumber
);
String
physicalCardNumber
=
ByteUtils
.
toHex
(
reqData
.
getPhysicalCardNumber
());
log
.
info
(
"物理卡号:{}"
,
physicalCardNumber
);
String
accountBalance
=
ByteUtils
.
toHex
(
reqData
.
getAccountBalance
());
log
.
info
(
"账户余额:{}"
,
accountBalance
);
// TODO: 2023/11/7 业务代码
/**请求参数打印*/
StartMachineResp
resp
=
new
StartMachineResp
();
StartMachineRspData
data
=
new
StartMachineRspData
();
data
.
setTransactionSerialNumber
(
Ocpp16Helper
.
strToBcd
(
"32010200000000111511161555350260"
,
data
.
getTransactionSerialNumber
()));
data
.
setPileId
(
Ocpp16Helper
.
strToBcd
(
"32010200000001"
,
data
.
getPileId
()));
data
.
setTransactionSerialNumber
(
Ocpp16Helper
.
strToBcd
(
transactionSerialNumber
,
data
.
getTransactionSerialNumber
()));
data
.
setPileId
(
Ocpp16Helper
.
strToBcd
(
pileId
,
data
.
getPileId
()));
data
.
setGunNumber
((
byte
)
1
);
data
.
setFailureReason
((
byte
)
0
);
data
.
setStartResult
((
byte
)
1
);
data
.
setFailureReason
((
byte
)
0x00
);
resp
.
setData
(
data
);
return
resp
;
}
...
...
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/TransactionRecordsReqHandler.java
View file @
46365e7
...
...
@@ -20,22 +20,46 @@ import io.netty.channel.Channel;
public
class
TransactionRecordsReqHandler
implements
TcpHandler
<
TransactionRecordsReq
,
TransactionRecordsResp
>
{
@Override
public
TransactionRecordsResp
handle
(
Channel
channel
,
TransactionRecordsReq
transactionRecordsReq
)
{
TransactionRecordsReqData
reqD
ata
=
transactionRecordsReq
.
getData
();
TransactionRecordsReqData
d
ata
=
transactionRecordsReq
.
getData
();
/** 解析参数日志打印 */
log
.
info
(
"交易流水号:{}"
,
Ocpp16Helper
.
bcdToStr
(
reqData
.
getTransactionSerialNumber
()));
String
pileNumber
=
Ocpp16Helper
.
bcdToStr
(
reqData
.
getPileId
());
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
()));
log
.
info
(
"交易流水号:{}"
,
Ocpp16Helper
.
bcdToStr
(
data
.
getTransactionSerialNumber
()));
log
.
info
(
"桩编号:{}"
,
Ocpp16Helper
.
bcdToStr
(
data
.
getPileId
()));
log
.
info
(
"枪号:{}"
,
data
.
getGunNumber
());
log
.
info
(
"开始时间:{}"
,
ByteUtils
.
toHex
(
data
.
getStartTime
()));
log
.
info
(
"结束时间:{}"
,
ByteUtils
.
toHex
(
data
.
getEndTime
()));
log
.
info
(
"尖单价:{}"
,
ByteUtils
.
toHex
(
data
.
getPeakUnitPrice
()));
log
.
info
(
"尖电量:{}"
,
ByteUtils
.
toHex
(
data
.
getPeakElectricity
()));
log
.
info
(
"计损尖电量:{}"
,
ByteUtils
.
toHex
(
data
.
getPeakElectricityLoss
()));
log
.
info
(
"尖金额:{}"
,
ByteUtils
.
toHex
(
data
.
getPeakAmount
()));
log
.
info
(
"峰单价:{}"
,
ByteUtils
.
toHex
(
data
.
getTopUnitPrice
()));
log
.
info
(
"峰电量:{}"
,
ByteUtils
.
toHex
(
data
.
getTopElectricity
()));
log
.
info
(
"计损峰电量:{}"
,
ByteUtils
.
toHex
(
data
.
getTopElectricityLoss
()));
log
.
info
(
"峰金额:{}"
,
ByteUtils
.
toHex
(
data
.
getTopAmount
()));
log
.
info
(
"平单价:{}"
,
ByteUtils
.
toHex
(
data
.
getFlatUnitPrice
()));
log
.
info
(
"平电量:{}"
,
ByteUtils
.
toHex
(
data
.
getFlatElectricity
()));
log
.
info
(
"计损平电量:{}"
,
ByteUtils
.
toHex
(
data
.
getFlatElectricityLoss
()));
log
.
info
(
"平金额:{}"
,
ByteUtils
.
toHex
(
data
.
getFlatAmount
()));
log
.
info
(
"谷单价:{}"
,
ByteUtils
.
toHex
(
data
.
getValleyUnitPrice
()));
log
.
info
(
"谷电量:{}"
,
ByteUtils
.
toHex
(
data
.
getValleyElectricity
()));
log
.
info
(
"计损谷电量:{}"
,
ByteUtils
.
toHex
(
data
.
getValleyElectricityLoss
()));
log
.
info
(
"谷金额:{}"
,
ByteUtils
.
toHex
(
data
.
getValleyAmount
()));
log
.
info
(
"电表总起值:{}"
,
ByteUtils
.
toHex
(
data
.
getTotalStartValue
()));
log
.
info
(
"电表总止值:{}"
,
ByteUtils
.
toHex
(
data
.
getTotalEndValue
()));
log
.
info
(
"总电量:{}"
,
ByteUtils
.
toHex
(
data
.
getTotalElectricity
()));
log
.
info
(
"计损总电量:{}"
,
ByteUtils
.
toHex
(
data
.
getTotalElectricityLoss
()));
log
.
info
(
"消费金额:{}"
,
ByteUtils
.
toHex
(
data
.
getTotalAmount
()));
log
.
info
(
"电动汽车唯一标识:{}"
,
ByteUtils
.
toHex
(
data
.
getVehicleIdentifier
()));
log
.
info
(
"交易标识:{}"
,
data
.
getTransactionIdentifier
());
log
.
info
(
"交易日期、时间:{}"
,
ByteUtils
.
toHex
(
data
.
getTransactionDateTime
()));
log
.
info
(
"停止原因:{}"
,
data
.
getStopReason
());
log
.
info
(
"物理卡号:{}"
,
ByteUtils
.
toHex
(
data
.
getPhysicalCardNumber
()));
/** 解析参数日志打印 */
TransactionRecordsResp
resp
=
new
TransactionRecordsResp
();
TransactionRecordsRespData
d
ata
=
new
TransactionRecordsRespData
();
data
.
setTransactionSerialNumber
(
Ocpp16Helper
.
strToBcd
(
"55031412782305012018061910262392"
,
data
.
getTransactionSerialNumber
()
));
d
ata
.
setConfirmResult
((
byte
)
0
);
TransactionRecordsRespData
respD
ata
=
new
TransactionRecordsRespData
();
respData
.
setTransactionSerialNumber
(
data
.
getTransactionSerialNumber
(
));
respD
ata
.
setConfirmResult
((
byte
)
0
);
resp
.
setData
(
d
ata
);
resp
.
setData
(
respD
ata
);
return
resp
;
}
}
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/TransactionRecordsRespHandler.java
View file @
46365e7
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.protocol.TransactionRecordsResp
;
import
io.netty.channel.Channel
;
...
...
@@ -17,7 +18,8 @@ public class TransactionRecordsRespHandler implements TcpHandler<TransactionReco
@Override
public
TransactionRecordsResp
handle
(
Channel
channel
,
TransactionRecordsResp
transactionRecordsResp
)
{
log
.
info
(
"交易流水号:{}"
,
Ocpp16Helper
.
bcdToStr
(
transactionRecordsResp
.
getData
().
getTransactionSerialNumber
()));
log
.
info
(
"确认结果:{}"
,
transactionRecordsResp
.
getData
().
getConfirmResult
());
log
.
info
(
"客户端已经收到返回"
);
return
null
;
}
...
...
platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/InteractiveTest.java
View file @
46365e7
...
...
@@ -9,6 +9,10 @@ import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.TransactionRecordsReqDat
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.util.ByteUtils
;
import
cn.com.glsx.charging.util.DateUtil
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.junit.MockitoJUnitRunner
;
...
...
@@ -23,11 +27,23 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
InteractiveTest
{
@Test
public
void
transactionRecordsTest
()
throws
Exception
{
private
TcpClient
client
;
@Before
public
void
beforeTest
()
throws
InterruptedException
{
Ocpp16Helper
.
scan
();
TcpClient
client
=
ClientMain
.
getInstance
(
"localhost"
,
8888
);
this
.
client
=
ClientMain
.
getInstance
(
"localhost"
,
8888
);
Thread
.
sleep
(
3000
);
}
@After
public
void
afterTest
()
throws
InterruptedException
{
Thread
.
sleep
(
3000
);
System
.
out
.
println
(
"========================="
);
}
@Test
public
void
transactionRecordsTest
()
throws
Exception
{
/**
* 样例报文 68 (起始标志) A2 (数据长度) 8001 (序列号域) 00 (加密标志) 3B (类型)
* 55031412782305012018061910262392(交易流水号)55031412782305(桩编码)01(枪号:1
...
...
@@ -44,46 +60,64 @@ public class InteractiveTest {
TransactionRecordsReq
req
=
new
TransactionRecordsReq
();
TransactionRecordsReqData
data
=
new
TransactionRecordsReqData
();
data
.
setTransactionSerialNumber
(
Ocpp16Helper
.
strToBcd
(
"55031412782305012018061910262392"
,
data
.
getTransactionSerialNumber
()));
data
.
setPileId
(
Ocpp16Helper
.
strToBcd
(
"55031412782305"
,
data
.
getPileId
()));
data
.
setGunNumber
((
byte
)
1
);
data
.
setPileId
(
Ocpp16Helper
.
strToBcd
(
"32010200000001"
,
data
.
getPileId
()));
data
.
setTopUnitPrice
(
Ocpp16Helper
.
strToBcd
(
"D0FB0100"
,
data
.
getTopUnitPrice
()));
data
.
setVehicleIdentifier
(
Ocpp16Helper
.
strToBcd
(
"0000000000000000000000000000000001"
,
data
.
getVehicleIdentifier
()));
data
.
setStartTime
(
ByteUtils
.
fromHex
(
"98B70E11100314"
));
data
.
setEndTime
(
ByteUtils
.
fromHex
(
"98B70E11100314"
));
data
.
setPeakUnitPrice
(
ByteUtils
.
fromHex
(
"D0FB0100"
));
data
.
setPeakElectricity
(
ByteUtils
.
fromHex
(
"00000000"
));
data
.
setPeakElectricityLoss
(
ByteUtils
.
fromHex
(
"00000000"
));
data
.
setPeakAmount
(
ByteUtils
.
fromHex
(
"00000000"
));
data
.
setTopUnitPrice
(
ByteUtils
.
fromHex
(
"D0FB0100"
));
data
.
setTopElectricity
(
ByteUtils
.
fromHex
(
"00000000"
));
data
.
setTopElectricityLoss
(
ByteUtils
.
fromHex
(
"00000000"
));
data
.
setTopAmount
(
ByteUtils
.
fromHex
(
"00000000"
));
data
.
setFlatUnitPrice
(
ByteUtils
.
fromHex
(
"D0FB0100"
));
data
.
setFlatElectricity
(
ByteUtils
.
fromHex
(
"00000000"
));
data
.
setFlatElectricityLoss
(
ByteUtils
.
fromHex
(
"00000000"
));
data
.
setFlatAmount
(
ByteUtils
.
fromHex
(
"00000000"
));
data
.
setValleyUnitPrice
(
ByteUtils
.
fromHex
(
"D0FB0100"
));
data
.
setFlatElectricity
(
ByteUtils
.
fromHex
(
"00000000"
));
data
.
setValleyElectricityLoss
(
ByteUtils
.
fromHex
(
"00000000"
));
data
.
setValleyAmount
(
ByteUtils
.
fromHex
(
"00000000"
));
data
.
setTotalStartValue
(
ByteUtils
.
fromHex
(
"00000000"
));
data
.
setTotalEndValue
(
ByteUtils
.
fromHex
(
"00000000"
));
data
.
setTotalElectricity
(
ByteUtils
.
fromHex
(
"00000000"
));
data
.
setTotalElectricityLoss
(
ByteUtils
.
fromHex
(
"00000000"
));
data
.
setTotalAmount
(
ByteUtils
.
fromHex
(
"00000000"
));
data
.
setVehicleIdentifier
(
Ocpp16Helper
.
strToAscii
(
"0000000000000000000000000000000001"
,
data
.
getVehicleIdentifier
()));
data
.
setTransactionIdentifier
((
byte
)
0x01
);
data
.
setTransactionDateTime
(
ByteUtils
.
fromHex
(
"98B70E11100314"
));
data
.
setStopReason
((
byte
)
0x00
);
data
.
setPhysicalCardNumber
(
ByteUtils
.
fromHex
(
"00000000D14B0A54"
));
req
.
setData
(
data
);
client
.
sendSync
(
req
);
Thread
.
sleep
(
3000
);
System
.
out
.
println
(
"========================="
);
}
@Test
public
void
shutdownMachineTest
()
throws
Exception
{
Ocpp16Helper
.
scan
();
TcpClient
client
=
ClientMain
.
getInstance
(
"localhost"
,
8888
);
Thread
.
sleep
(
3000
);
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
);
Thread
.
sleep
(
3000
);
System
.
out
.
println
(
"========================="
);
}
@Test
public
void
startMachineReqTest
()
throws
Exception
{
Ocpp16Helper
.
scan
();
TcpClient
client
=
ClientMain
.
getInstance
(
"localhost"
,
8888
);
Thread
.
sleep
(
3000
);
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
(
"1000000573"
,
data
.
getLogicalCardNumber
()));
data
.
setPhysicalCardNumber
(
Ocpp16Helper
.
strToBcd
(
"D14B0A54"
,
data
.
getPhysicalCardNumber
()));
data
.
setAccountBalance
(
Ocpp16Helper
.
strToBcd
(
"00000064"
,
data
.
getAccountBalance
()));
data
.
setLogicalCardNumber
(
Ocpp16Helper
.
strToBcd
(
"0000001000000573"
,
data
.
getLogicalCardNumber
()));
byte
[]
bytes
=
Ocpp16Helper
.
binToBytes
(
Ocpp16Helper
.
hexToBinaryString
(
"00000000D14B0A54"
));
data
.
setPhysicalCardNumber
(
bytes
);
byte
[]
accountBytes
=
Ocpp16Helper
.
binToBytes
(
Ocpp16Helper
.
hexToBinaryString
(
"A0860100"
));
data
.
setAccountBalance
(
accountBytes
);
req
.
setData
(
data
);
client
.
sendSync
(
req
);
System
.
out
.
println
(
"========================="
);
}
}
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