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 9c3cd2bd
authored
Nov 07, 2023
by
zhouhaibao
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'master' of
http://192.168.3.233:8090/platform/platform-charging-server
2 parents
a137f4b4
1b8ece9d
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
124 additions
and
37 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/Ocpp16Helper.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/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/ClientMain.java
View file @
9c3cd2b
...
@@ -54,6 +54,7 @@ public class ClientMain {
...
@@ -54,6 +54,7 @@ public class ClientMain {
//
//
// client.sendSync(req);
// client.sendSync(req);
//000100343201020000000011151116155535026032010200000001011000000573000000F1FFFF5400000000F0860100
StartMachineReq
req
=
new
StartMachineReq
();
StartMachineReq
req
=
new
StartMachineReq
();
StartMachineReqData
data
=
new
StartMachineReqData
();
StartMachineReqData
data
=
new
StartMachineReqData
();
data
.
setTransactionSerialNumber
(
Ocpp16Helper
.
strToBcd
(
"32010200000000111511161555350260"
,
data
.
getTransactionSerialNumber
()));
data
.
setTransactionSerialNumber
(
Ocpp16Helper
.
strToBcd
(
"32010200000000111511161555350260"
,
data
.
getTransactionSerialNumber
()));
...
@@ -61,7 +62,7 @@ public class ClientMain {
...
@@ -61,7 +62,7 @@ public class ClientMain {
data
.
setGunNumber
((
byte
)
1
);
data
.
setGunNumber
((
byte
)
1
);
data
.
setLogicalCardNumber
(
Ocpp16Helper
.
strToBcd
(
"1000000573"
,
data
.
getLogicalCardNumber
()));
data
.
setLogicalCardNumber
(
Ocpp16Helper
.
strToBcd
(
"1000000573"
,
data
.
getLogicalCardNumber
()));
data
.
setPhysicalCardNumber
(
Ocpp16Helper
.
strToBcd
(
"D14B0A54"
,
data
.
getPhysicalCardNumber
()));
data
.
setPhysicalCardNumber
(
Ocpp16Helper
.
strToBcd
(
"D14B0A54"
,
data
.
getPhysicalCardNumber
()));
data
.
setAccountBalance
(
Ocpp16Helper
.
strToBcd
(
"
A0860100
"
,
data
.
getAccountBalance
()));
data
.
setAccountBalance
(
Ocpp16Helper
.
strToBcd
(
"
00000064
"
,
data
.
getAccountBalance
()));
// Ocpp16Helper.binToBytes()
// Ocpp16Helper.binToBytes()
req
.
setData
(
data
);
req
.
setData
(
data
);
client
.
sendSync
(
req
);
client
.
sendSync
(
req
);
...
...
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/Ocpp16Helper.java
View file @
9c3cd2b
...
@@ -315,4 +315,93 @@ public class Ocpp16Helper {
...
@@ -315,4 +315,93 @@ public class Ocpp16Helper {
return
p
;
return
p
;
}
}
/**
* long类型值转换成指定长度的二进制字符串
* @param number
* @param byteCount
* @return
*/
public
static
String
longToBinaryString
(
long
number
,
int
byteCount
)
{
String
binaryString
=
Long
.
toBinaryString
(
number
);
// 计算需要补零的位数
int
leadingZeros
=
byteCount
*
8
-
binaryString
.
length
();
// 在二进制字符串前面补零
StringBuilder
paddedString
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
leadingZeros
;
i
++)
{
paddedString
.
append
(
"0"
);
}
paddedString
.
append
(
binaryString
);
return
paddedString
.
toString
();
}
/**
* 十六进制字符串转二进制字符串
* @param hexString
* @return
*/
public
static
String
hexToBinaryString
(
String
hexString
)
{
StringBuilder
binaryString
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
hexString
.
length
();
i
++)
{
char
hexChar
=
hexString
.
charAt
(
i
);
String
binary
=
Integer
.
toBinaryString
(
Character
.
digit
(
hexChar
,
16
));
binaryString
.
append
(
String
.
format
(
"%04d"
,
Integer
.
parseInt
(
binary
)));
}
return
binaryString
.
toString
();
}
/**
* 二进制字符串转成对应Long数值
* @param binaryString
* @return
*/
public
static
long
binaryStringToLong
(
String
binaryString
)
{
long
result
=
0
;
int
length
=
binaryString
.
length
();
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
char
bit
=
binaryString
.
charAt
(
length
-
1
-
i
);
if
(
bit
==
'1'
)
{
result
+=
Math
.
pow
(
2
,
i
);
}
}
return
result
;
}
/**
* 二进制字符串转成16进制字符串
* @param binaryString
* @return
*/
public
static
String
binaryToHexString
(
String
binaryString
)
{
// 确保二进制字符串的长度是4的倍数
int
length
=
binaryString
.
length
();
if
(
length
%
4
!=
0
)
{
int
paddingZeros
=
4
-
(
length
%
4
);
StringBuilder
paddedString
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
paddingZeros
;
i
++)
{
paddedString
.
append
(
"0"
);
}
binaryString
=
paddedString
.
toString
()
+
binaryString
;
}
StringBuilder
hexString
=
new
StringBuilder
();
// 将每4位二进制字符串转换为对应的十六进制字符
for
(
int
i
=
0
;
i
<
binaryString
.
length
();
i
+=
4
)
{
String
binarySubstring
=
binaryString
.
substring
(
i
,
i
+
4
);
int
decimalValue
=
Integer
.
parseInt
(
binarySubstring
,
2
);
hexString
.
append
(
Integer
.
toHexString
(
decimalValue
));
}
return
hexString
.
toString
();
}
}
}
\ 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/data/interactive/StartMachineReqData.java
View file @
9c3cd2b
package
cn
.
com
.
glsx
.
charging
.
modules
.
gbt
.
ocpp16
.
tcp
.
data
.
interactive
;
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
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.base.TcpData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.req.StartMachineReq
;
import
cn.com.glsx.charging.util.ByteUtils
;
import
cn.com.glsx.charging.util.CrcUtils
;
import
lombok.Getter
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.Setter
;
...
@@ -69,24 +65,4 @@ public class StartMachineReqData extends TcpData {
...
@@ -69,24 +65,4 @@ public class StartMachineReqData extends TcpData {
* 备注:保留到小数点两位
* 备注:保留到小数点两位
*/
*/
private
byte
[]
accountBalance
=
new
byte
[
4
];
private
byte
[]
accountBalance
=
new
byte
[
4
];
public
static
void
main
(
String
[]
args
)
{
Ocpp16Helper
.
scan
();
// 68 (起始标志) 30 (数据长度) 007C (序列号域) 00 (加密标志) 34
// (类型)55031412782305012018061914444680(交易流水号)55031412782305(桩编码)01(枪号:1枪)0000001000000573(逻辑卡号:1000000573)00000000D14B0A54(物理卡号:D14B0A54)A0860100(账户余额:1000.00)4622
String
hex
=
"6830007C0034550314127823050120180619144446805503141278230501000000100000057300000000D14B0A54A08601004622"
;
System
.
out
.
println
(
hex
);
byte
[]
bytes
=
ByteUtils
.
fromHex
(
hex
);
StartMachineReq
protocol
=
Ocpp16Helper
.
parse
(
bytes
);
System
.
out
.
println
(
"expect: "
+
protocol
.
getCrc
());
System
.
out
.
println
(
protocol
);
byte
[]
data
=
ByteUtils
.
getBytes
(
bytes
,
2
,
bytes
.
length
-
4
);
System
.
out
.
println
(
"actual: "
+
CrcUtils
.
calculateCRC
(
data
));
bytes
=
Ocpp16Helper
.
build
(
protocol
);
System
.
out
.
println
(
ByteUtils
.
toHex
(
bytes
));
}
}
}
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/interactive/req/StartMachineReqHandler.java
View file @
9c3cd2b
...
@@ -2,12 +2,16 @@ package cn.com.glsx.charging.modules.gbt.ocpp16.tcp.handler.interactive.req;
...
@@ -2,12 +2,16 @@ 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.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.interactive.StartMachineReqData
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.data.interactive.StartMachineRspData
;
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.req.StartMachineReq
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.resp.StartMachineResp
;
import
cn.com.glsx.charging.modules.gbt.ocpp16.tcp.protocol.interactive.resp.StartMachineResp
;
import
cn.com.glsx.charging.util.ByteUtils
;
import
cn.com.glsx.charging.util.ByteUtils
;
import
io.netty.channel.Channel
;
import
io.netty.channel.Channel
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
/**
/**
* @Description 远程启动充电请求处理类
* @Description 远程启动充电请求处理类
* @Author yelq
* @Author yelq
...
@@ -17,12 +21,31 @@ import io.netty.channel.Channel;
...
@@ -17,12 +21,31 @@ import io.netty.channel.Channel;
public
class
StartMachineReqHandler
implements
TcpHandler
<
StartMachineReq
,
StartMachineResp
>
{
public
class
StartMachineReqHandler
implements
TcpHandler
<
StartMachineReq
,
StartMachineResp
>
{
@Override
@Override
public
StartMachineResp
handle
(
Channel
channel
,
StartMachineReq
startMachineReq
)
{
public
StartMachineResp
handle
(
Channel
channel
,
StartMachineReq
startMachineReq
)
{
/**请求参数打印*/
StartMachineReqData
reqData
=
startMachineReq
.
getData
();
String
transactionSerialNumber
=
Ocpp16Helper
.
bcdToStr
(
reqData
.
getTransactionSerialNumber
());
System
.
out
.
println
(
"交易流水号"
+
transactionSerialNumber
);
String
pileNumber
=
Ocpp16Helper
.
bcdToStr
(
reqData
.
getPileNumber
());
System
.
out
.
println
(
"桩编号"
+
pileNumber
);
byte
gunNumber
=
reqData
.
getGunNumber
();
System
.
out
.
println
(
"枪号"
+
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
);
// TODO: 2023/11/7 业务代码
/**请求参数打印*/
StartMachineResp
resp
=
new
StartMachineResp
();
StartMachineResp
resp
=
new
StartMachineResp
();
StartMachineRspData
data
=
new
StartMachineRspData
();
StartMachineRspData
data
=
new
StartMachineRspData
();
data
.
setTransactionSerialNumber
(
Ocpp16Helper
.
strToBcd
(
"32010200000000111511161555350260"
,
data
.
getTransactionSerialNumber
()));
data
.
setTransactionSerialNumber
(
Ocpp16Helper
.
strToBcd
(
"32010200000000111511161555350260"
,
data
.
getTransactionSerialNumber
()));
data
.
setPileNumber
(
Ocpp16Helper
.
strToBcd
(
"32010200000001"
,
data
.
getPileNumber
()));
data
.
setPileNumber
(
Ocpp16Helper
.
strToBcd
(
"32010200000001"
,
data
.
getPileNumber
()));
data
.
setGunNumber
((
byte
)
1
);
data
.
setGunNumber
((
byte
)
1
);
data
.
setFailureReason
((
byte
)
0
);
data
.
setFailureReason
((
byte
)
0
);
data
.
setStartResult
((
byte
)
1
);
resp
.
setData
(
data
);
resp
.
setData
(
data
);
return
resp
;
return
resp
;
}
}
...
...
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/tcp/handler/interactive/resp/StartMachineRespHandler.java
View file @
9c3cd2b
package
cn
.
com
.
glsx
.
charging
.
modules
.
gbt
.
ocpp16
.
tcp
.
handler
.
interactive
.
resp
;
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.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.modules.gbt.ocpp16.tcp.protocol.interactive.resp.StartMachineResp
;
import
cn.com.glsx.charging.util.ByteUtils
;
import
io.netty.channel.Channel
;
import
io.netty.channel.Channel
;
/**
/**
...
@@ -21,13 +17,15 @@ public class StartMachineRespHandler implements TcpHandler<StartMachineResp, Sta
...
@@ -21,13 +17,15 @@ public class StartMachineRespHandler implements TcpHandler<StartMachineResp, Sta
//68(起始标志)1E(数据长度)0002(序列号域)00(加密标志)33(类型)
//68(起始标志)1E(数据长度)0002(序列号域)00(加密标志)33(类型)
//32010200000000111511161555350260(交易流水号)32010200000001(桩编码)01(枪号:1
//32010200000000111511161555350260(交易流水号)32010200000001(桩编码)01(枪号:1
//枪)01(启动结果:成功)00(失败原因:无)0FE2(帧校验域)
//枪)01(启动结果:成功)00(失败原因:无)0FE2(帧校验域)
StartMachineResp
resp
=
new
StartMachineResp
();
// StartMachineResp resp = new StartMachineResp();
StartMachineRspData
data
=
new
StartMachineRspData
();
// StartMachineRspData data = new StartMachineRspData();
data
.
setTransactionSerialNumber
(
Ocpp16Helper
.
strToBcd
(
"32010200000000111511161555350260"
,
data
.
getTransactionSerialNumber
()));
// data.setTransactionSerialNumber(Ocpp16Helper.strToBcd("32010200000000111511161555350261", data.getTransactionSerialNumber()));
data
.
setPileNumber
(
Ocpp16Helper
.
strToBcd
(
"32010200000001"
,
data
.
getPileNumber
()));
// data.setPileNumber(Ocpp16Helper.strToBcd("32010200000002",data.getPileNumber()));
data
.
setGunNumber
((
byte
)
1
);
// data.setGunNumber((byte) 1);
data
.
setFailureReason
((
byte
)
0
);
// data.setFailureReason((byte) 0);
resp
.
setData
(
data
);
// resp.setData(data);
return
resp
;
// return resp;
log
.
info
(
"已经成功接收==StartMachineRespHandler"
);
return
null
;
}
}
}
}
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