Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gass-device-report
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
耿迪迪
gass-device-report
Commits
7e3a8a11
Commit
7e3a8a11
authored
Oct 13, 2021
by
耿迪迪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
设备上报校验规则修改 gengdidi
parent
d68f0ac9
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
7 additions
and
21 deletions
+7
-21
TCPServerHandler.java
...hong/gassdevicereport/netty/handler/TCPServerHandler.java
+2
-2
UDPServerHandler.java
...hong/gassdevicereport/netty/handler/UDPServerHandler.java
+2
-2
CrcUtil.java
src/main/java/com/zehong/gassdevicereport/utils/CrcUtil.java
+2
-16
application.yml
src/main/resources/application.yml
+1
-1
No files found.
src/main/java/com/zehong/gassdevicereport/netty/handler/TCPServerHandler.java
View file @
7e3a8a11
...
...
@@ -79,9 +79,9 @@ public class TCPServerHandler extends ChannelInboundHandlerAdapter {
String
msgStr
=
HexUtils
.
bytesToHex
(
bytes1
);
logger
.
info
(
"receiveTCPMsgstr======="
+
msgStr
);
byte
[]
bytes
=
HexUtils
.
hexToByteArray
(
msgStr
.
substring
(
0
,
msgStr
.
length
()-
4
));
String
checkVule
=
CrcUtil
.
getCrcToHex
(
bytes
,
true
);
int
checkVule
=
CrcUtil
.
getCrcToHex
(
bytes
,
true
);
String
checkCode
=
msgStr
.
substring
(
msgStr
.
length
()-
4
,
msgStr
.
length
());
if
(
!
checkVule
.
equals
(
checkCode
)){
if
(
checkVule
!=
Integer
.
parseInt
(
checkCode
,
16
)){
logger
.
error
(
"接收数据校验失败"
);
throw
new
Exception
(
"接收数据校验失败"
);
}
...
...
src/main/java/com/zehong/gassdevicereport/netty/handler/UDPServerHandler.java
View file @
7e3a8a11
...
...
@@ -44,9 +44,9 @@ public class UDPServerHandler extends SimpleChannelInboundHandler<DatagramPacket
String
msgStr
=
HexUtils
.
bytesToHex
(
bytes1
);
logger
.
info
(
"receiveUPDMsgstr======="
+
msgStr
);
byte
[]
bytes
=
HexUtils
.
hexToByteArray
(
msgStr
.
substring
(
0
,
msgStr
.
length
()-
4
));
String
checkVule
=
CrcUtil
.
getCrcToHex
(
bytes
,
true
);
int
checkVule
=
CrcUtil
.
getCrcToHex
(
bytes
,
true
);
String
checkCode
=
msgStr
.
substring
(
msgStr
.
length
()-
4
,
msgStr
.
length
());
if
(
!
checkVule
.
equals
(
checkCode
)){
if
(
checkVule
!=
Integer
.
parseInt
(
checkCode
,
16
)){
logger
.
error
(
"接收数据校验失败"
);
throw
new
Exception
(
"接收数据校验失败"
);
}
...
...
src/main/java/com/zehong/gassdevicereport/utils/CrcUtil.java
View file @
7e3a8a11
...
...
@@ -39,29 +39,15 @@ public class CrcUtil {
* @param reverse 是否转换高低位
* @return
*/
public
static
String
getCrcToHex
(
byte
[]
bytes
,
boolean
reverse
)
{
public
static
int
getCrcToHex
(
byte
[]
bytes
,
boolean
reverse
)
{
int
CRC
=
getCRC
(
bytes
);
//高低位转换,看情况使用(譬如本人这次对led彩屏的通讯开发就规定校验码高位在前低位在后,也就不需要转换高低位)
if
(
reverse
){
CRC
=
(
(
CRC
&
0x0000FF00
)
>>
8
)
|
(
(
CRC
&
0x000000FF
)
<<
8
);
}
return
Integer
.
toHexString
(
CRC
)
;
return
CRC
;
}
public
static
void
main
(
String
[]
args
)
{
//字符串转16进制byte数组
String
str16
=
"0806040303030004040803070309010002032108271532404136cb5fdbd2b0004132f1e60000000042ef193b42d3cd6742012c5242edf73a0000000080a6"
;
/* byte[] bytes = HexUtils.hexToByteArray(str16);
// byte[] bytes = str16.getBytes();
System.out.println("str16:" + str16);
System.out.println(getCrcToHex(bytes,true));
System.out.println("str16:" + str16.substring(0,str16.length()-4));
System.out.println(str16.substring(str16.length()-4,str16.length()));*/
//System.out.println(HexUtils.hexToByte(str16.substring(0,36)));
System
.
out
.
println
(
Integer
.
parseInt
(
str16
.
substring
(
0
,
36
),
16
));
}
}
...
...
src/main/resources/application.yml
View file @
7e3a8a11
...
...
@@ -15,7 +15,7 @@ server:
spring
:
profiles
:
active
:
prd
active
:
test
#mybatis的相关配置
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment