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 1c1b5932
authored
Nov 21, 2023
by
谢海旭
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
添加 Ocpp16Helper.strToBcd 方法
1 parent
06bcbf71
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
2 deletions
platform-charging/src/main/java/cn/com/glsx/charging/modules/gbt/ocpp16/Ocpp16Helper.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/Ocpp16Helper.java
View file @
1c1b593
...
@@ -22,6 +22,7 @@ import cn.com.glsx.charging.util.PluralCache;
...
@@ -22,6 +22,7 @@ import cn.com.glsx.charging.util.PluralCache;
import
io.netty.buffer.ByteBuf
;
import
io.netty.buffer.ByteBuf
;
import
io.netty.buffer.Unpooled
;
import
io.netty.buffer.Unpooled
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.util.StringUtils
;
@Slf4j
@Slf4j
@SuppressWarnings
(
"rawtypes"
)
@SuppressWarnings
(
"rawtypes"
)
...
@@ -176,6 +177,35 @@ public class Ocpp16Helper {
...
@@ -176,6 +177,35 @@ public class Ocpp16Helper {
}
}
/**
/**
* 字符串转单个bcd字节
*
* @param str
* @return
*/
public
static
byte
strToBcd
(
String
str
)
{
if
(!
StringUtils
.
hasLength
(
str
))
{
throw
new
IllegalArgumentException
(
"str cannot be empty"
);
}
int
len
=
str
.
length
();
if
(
len
>
2
)
{
throw
new
IllegalArgumentException
(
"Invalid str"
);
}
if
(
len
==
1
)
{
str
=
"0"
+
str
;
// 补齐偶数位
}
char
highChar
=
str
.
charAt
(
0
);
char
lowChar
=
str
.
charAt
(
1
);
int
high
=
Character
.
digit
(
highChar
,
10
);
int
low
=
Character
.
digit
(
lowChar
,
10
);
return
(
byte
)
((
high
<<
4
)
|
low
);
}
/**
* 字符串 转ascii字节数组
* 字符串 转ascii字节数组
* 不足指定长度,默认后面补零
* 不足指定长度,默认后面补零
*
*
...
...
platform-charging/src/test/java/cn/com/glsx/charging/gbt/ocpp16/ClientSimulateTest.java
View file @
1c1b593
...
@@ -31,17 +31,22 @@ public class ClientSimulateTest {
...
@@ -31,17 +31,22 @@ public class ClientSimulateTest {
req
.
getData
().
setPileId
(
Ocpp16Helper
.
strToBcd
(
"55031412782305"
,
req
.
getData
().
getPileId
()));
req
.
getData
().
setPileId
(
Ocpp16Helper
.
strToBcd
(
"55031412782305"
,
req
.
getData
().
getPileId
()));
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
().
setProtocolVersion
((
byte
)
10
);
req
.
getData
().
setProtocolVersion
((
byte
)
10
);
req
.
getData
().
setSoftVersion
(
Ocpp16Helper
.
strToAscii
(
"v4.1.50"
,
req
.
getData
().
getSoftVersion
()));
req
.
getData
().
setNetwork
((
byte
)
0x03
);
req
.
getData
().
setSim
(
Ocpp16Helper
.
strToBcd
(
"01010101010101010101"
,
req
.
getData
().
getSim
()));
req
.
getData
().
setOperator
((
byte
)
0x04
);
client
.
sendSync
(
req
);
client
.
sendSync
(
req
);
// 定期心跳
// 定期心跳
while
(
true
)
{
while
(
true
)
{
HeartbeatReq
heartbeat
=
new
HeartbeatReq
();
HeartbeatReqData
hdata
=
new
HeartbeatReqData
();
HeartbeatReqData
hdata
=
new
HeartbeatReqData
();
hdata
.
setPileId
(
req
.
getData
().
getPileId
());
hdata
.
setPileId
(
req
.
getData
().
getPileId
());
hdata
.
setGunNo
(
Ocpp16Helper
.
strToBcd
(
"2"
));
hdata
.
setStatus
((
byte
)
0
);
hdata
.
setStatus
((
byte
)
0
);
HeartbeatReq
heartbeat
=
new
HeartbeatReq
();
heartbeat
.
setData
(
hdata
);
heartbeat
.
setData
(
hdata
);
client
.
sendSync
(
heartbeat
);
client
.
sendSync
(
heartbeat
);
...
...
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