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 09dae9f3
authored
Nov 09, 2023
by
叶立庆
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]测试用例完善、协议转换完善
1 parent
81366567
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
10 deletions
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/Ocpp16Helper.java
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/StartMachineReqHandler.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/Ocpp16Helper.java
View file @
09dae9f
...
@@ -2,6 +2,10 @@ package cn.com.glsx.charging.modules.gbt.ocpp16;
...
@@ -2,6 +2,10 @@ package cn.com.glsx.charging.modules.gbt.ocpp16;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Modifier
;
import
java.lang.reflect.Modifier
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.math.RoundingMode
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.atomic.AtomicInteger
;
...
@@ -327,7 +331,7 @@ public class Ocpp16Helper {
...
@@ -327,7 +331,7 @@ public class Ocpp16Helper {
* @param byteCount
* @param byteCount
* @return
* @return
*/
*/
public
static
String
longToBin
aryString
(
long
number
,
int
byteCount
)
{
public
static
String
longToBin
Str
(
long
number
,
int
byteCount
)
{
String
binaryString
=
Long
.
toBinaryString
(
number
);
String
binaryString
=
Long
.
toBinaryString
(
number
);
// 计算需要补零的位数
// 计算需要补零的位数
...
@@ -349,7 +353,7 @@ public class Ocpp16Helper {
...
@@ -349,7 +353,7 @@ public class Ocpp16Helper {
* @param hexString
* @param hexString
* @return
* @return
*/
*/
public
static
String
hexToBin
aryString
(
String
hexString
)
{
public
static
String
hexToBin
Str
(
String
hexString
)
{
StringBuilder
binaryString
=
new
StringBuilder
();
StringBuilder
binaryString
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
hexString
.
length
();
i
++)
{
for
(
int
i
=
0
;
i
<
hexString
.
length
();
i
++)
{
...
@@ -367,7 +371,7 @@ public class Ocpp16Helper {
...
@@ -367,7 +371,7 @@ public class Ocpp16Helper {
* @param binaryString
* @param binaryString
* @return
* @return
*/
*/
public
static
long
bin
aryString
ToLong
(
String
binaryString
)
{
public
static
long
bin
Str
ToLong
(
String
binaryString
)
{
long
result
=
0
;
long
result
=
0
;
int
length
=
binaryString
.
length
();
int
length
=
binaryString
.
length
();
...
@@ -411,4 +415,52 @@ public class Ocpp16Helper {
...
@@ -411,4 +415,52 @@ public class Ocpp16Helper {
return
hexString
.
toString
();
return
hexString
.
toString
();
}
}
/**
* 十六进制字符串转换为long类型数值
* @param hexString
* @return
*/
public
static
long
hexToLong
(
String
hexString
)
{
long
longNum
=
0
;
int
length
=
hexString
.
length
();
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
char
c
=
hexString
.
charAt
(
i
);
int
digit
=
Character
.
digit
(
c
,
16
);
longNum
=
longNum
*
16
+
digit
;
}
return
longNum
;
}
/**
* 协议中【BIN码】字节转换为带指定小数的数值
* @param bytesBin 协议中的BIN码字节
* @param scale 小数位数
* @return
*/
public
static
BigDecimal
bytesBinToBigDecimal
(
byte
[]
bytesBin
,
int
scale
){
byte
[]
bytes
=
Arrays
.
copyOf
(
bytesBin
,
bytesBin
.
length
);
ByteUtils
.
reverse
(
bytes
);
return
hexStrToBigDecimal
(
ByteUtils
.
toHex
(
bytes
),
scale
);
}
public
static
BigDecimal
hexStrToBigDecimal
(
String
hexString
,
int
scale
)
{
// 将十六进制字符串转换为 BigInteger
BigInteger
bigIntegerValue
=
new
BigInteger
(
hexString
,
16
);
// 将 BigInteger 转换为 BigDecimal
BigDecimal
decimalValue
=
new
BigDecimal
(
bigIntegerValue
);
// 计算缩放因子
BigDecimal
scalingFactor
=
BigDecimal
.
TEN
.
pow
(
scale
);
// 应用缩放因子
decimalValue
=
decimalValue
.
divide
(
scalingFactor
,
scale
,
RoundingMode
.
HALF_UP
);
return
decimalValue
;
}
}
}
\ No newline at end of file
\ No newline at end of file
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/StartMachineReqHandler.java
View file @
09dae9f
package
cn
.
com
.
glsx
.
charging
.
modules
.
gbt
.
ocpp16
.
tcp
.
handler
;
package
cn
.
com
.
glsx
.
charging
.
modules
.
gbt
.
ocpp16
.
tcp
.
handler
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.Ocpp16Helper
;
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.base.TcpHandler
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.StartMachineReqData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.StartMachineReqData
;
...
@@ -34,7 +31,7 @@ public class StartMachineReqHandler implements TcpHandler<StartMachineReq, Start
...
@@ -34,7 +31,7 @@ public class StartMachineReqHandler implements TcpHandler<StartMachineReq, Start
String
physicalCardNumber
=
ByteUtils
.
toHex
(
reqData
.
getPhysicalCardNumber
());
String
physicalCardNumber
=
ByteUtils
.
toHex
(
reqData
.
getPhysicalCardNumber
());
log
.
info
(
"物理卡号:{}"
,
physicalCardNumber
);
log
.
info
(
"物理卡号:{}"
,
physicalCardNumber
);
String
accountBalance
=
ByteUtils
.
toHex
(
reqData
.
getAccountBalance
());
String
accountBalance
=
ByteUtils
.
toHex
(
reqData
.
getAccountBalance
());
log
.
info
(
"账户余额:{}
"
,
accountBalance
);
log
.
info
(
"账户余额:{}
,解析后的值:{}"
,
accountBalance
,
Ocpp16Helper
.
bytesBinToBigDecimal
(
reqData
.
getAccountBalance
(),
2
)
);
// TODO: 2023/11/7 业务代码
// TODO: 2023/11/7 业务代码
/**请求参数打印*/
/**请求参数打印*/
StartMachineResp
resp
=
new
StartMachineResp
();
StartMachineResp
resp
=
new
StartMachineResp
();
...
...
platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/InteractiveTest.java
View file @
09dae9f
...
@@ -10,7 +10,6 @@ import cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.ShutdownMachineReq;
...
@@ -10,7 +10,6 @@ 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.StartMachineReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.TransactionRecordsReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.TransactionRecordsReq
;
import
cn.com.glsx.charging.util.ByteUtils
;
import
cn.com.glsx.charging.util.ByteUtils
;
import
cn.com.glsx.charging.util.DateUtil
;
import
org.junit.After
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
...
@@ -113,9 +112,9 @@ public class InteractiveTest {
...
@@ -113,9 +112,9 @@ public class InteractiveTest {
data
.
setPileId
(
Ocpp16Helper
.
strToBcd
(
"32010200000001"
,
data
.
getPileId
()));
data
.
setPileId
(
Ocpp16Helper
.
strToBcd
(
"32010200000001"
,
data
.
getPileId
()));
data
.
setGunNumber
((
byte
)
1
);
data
.
setGunNumber
((
byte
)
1
);
data
.
setLogicalCardNumber
(
Ocpp16Helper
.
strToBcd
(
"0000001000000573"
,
data
.
getLogicalCardNumber
()));
data
.
setLogicalCardNumber
(
Ocpp16Helper
.
strToBcd
(
"0000001000000573"
,
data
.
getLogicalCardNumber
()));
byte
[]
bytes
=
Ocpp16Helper
.
binToBytes
(
Ocpp16Helper
.
hexToBin
aryString
(
"00000000D14B0A54"
));
byte
[]
bytes
=
Ocpp16Helper
.
binToBytes
(
Ocpp16Helper
.
hexToBin
Str
(
"00000000D14B0A54"
));
data
.
setPhysicalCardNumber
(
bytes
);
data
.
setPhysicalCardNumber
(
bytes
);
byte
[]
accountBytes
=
Ocpp16Helper
.
binToBytes
(
Ocpp16Helper
.
hexToBin
aryString
(
"A0860100"
));
byte
[]
accountBytes
=
Ocpp16Helper
.
binToBytes
(
Ocpp16Helper
.
hexToBin
Str
(
"A0860100"
));
data
.
setAccountBalance
(
accountBytes
);
data
.
setAccountBalance
(
accountBytes
);
req
.
setData
(
data
);
req
.
setData
(
data
);
client
.
sendSync
(
req
);
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