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
c1dfa26a
Commit
c1dfa26a
authored
Oct 14, 2021
by
耿迪迪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
设备上报问题修改
parent
7e3a8a11
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
7 deletions
+6
-7
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
-3
No files found.
src/main/java/com/zehong/gassdevicereport/netty/handler/TCPServerHandler.java
View file @
c1dfa26a
...
...
@@ -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
));
int
checkVule
=
CrcUtil
.
getCrcToHex
(
bytes
,
true
);
String
checkVule
=
CrcUtil
.
getCrcToHex
(
bytes
,
true
);
String
checkCode
=
msgStr
.
substring
(
msgStr
.
length
()-
4
,
msgStr
.
length
());
if
(
checkVule
!=
Integer
.
parseInt
(
checkCode
,
16
)){
if
(
!
checkVule
.
equals
(
checkCode
)){
logger
.
error
(
"接收数据校验失败"
);
throw
new
Exception
(
"接收数据校验失败"
);
}
...
...
src/main/java/com/zehong/gassdevicereport/netty/handler/UDPServerHandler.java
View file @
c1dfa26a
...
...
@@ -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
));
int
checkVule
=
CrcUtil
.
getCrcToHex
(
bytes
,
true
);
String
checkVule
=
CrcUtil
.
getCrcToHex
(
bytes
,
true
);
String
checkCode
=
msgStr
.
substring
(
msgStr
.
length
()-
4
,
msgStr
.
length
());
if
(
checkVule
!=
Integer
.
parseInt
(
checkCode
,
16
)){
if
(
!
checkVule
.
equals
(
checkCode
)){
logger
.
error
(
"接收数据校验失败"
);
throw
new
Exception
(
"接收数据校验失败"
);
}
...
...
src/main/java/com/zehong/gassdevicereport/utils/CrcUtil.java
View file @
c1dfa26a
...
...
@@ -39,15 +39,14 @@ public class CrcUtil {
* @param reverse 是否转换高低位
* @return
*/
public
static
int
getCrcToHex
(
byte
[]
bytes
,
boolean
reverse
)
{
public
static
String
getCrcToHex
(
byte
[]
bytes
,
boolean
reverse
)
{
int
CRC
=
getCRC
(
bytes
);
//高低位转换,看情况使用(譬如本人这次对led彩屏的通讯开发就规定校验码高位在前低位在后,也就不需要转换高低位)
if
(
reverse
){
CRC
=
(
(
CRC
&
0x0000FF00
)
>>
8
)
|
(
(
CRC
&
0x000000FF
)
<<
8
);
}
return
CRC
;
return
Integer
.
toHexString
(
CRC
)
;
}
}
...
...
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