Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
ioc_sixiang_license
Project
Project
Details
Activity
Releases
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
zengtianlai3
ioc_sixiang_license
Commits
c108a349
Commit
c108a349
authored
Dec 08, 2022
by
AfirSraftGarrier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
上报错误方法改变
parent
0493c149
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
9 deletions
+60
-9
DeviceServerHandler.java
.../java/iot/sixiang/license/device/DeviceServerHandler.java
+52
-6
DeviceClientLicenseEvent.java
...a/iot/sixiang/license/event/DeviceClientLicenseEvent.java
+1
-0
DeviceClientLicenseEventHandler.java
...ixiang/license/event/DeviceClientLicenseEventHandler.java
+7
-3
No files found.
license/src/main/java/iot/sixiang/license/device/DeviceServerHandler.java
View file @
c108a349
package
iot
.
sixiang
.
license
.
device
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
io.netty.channel.ChannelHandler
;
import
io.netty.channel.ChannelHandlerContext
;
...
...
@@ -10,11 +11,14 @@ import iot.sixiang.license.auth.AuthManager;
import
iot.sixiang.license.consts.Constant
;
import
iot.sixiang.license.event.CreateForwardClientEvent
;
import
iot.sixiang.license.event.DeviceClientInactiveEvent
;
import
iot.sixiang.license.event.DeviceClientLicenseEvent
;
import
iot.sixiang.license.event.EventPublisher
;
import
iot.sixiang.license.event.ForwardClientRequestEvent
;
import
iot.sixiang.license.idreader.Safety
;
import
iot.sixiang.license.model.SessionContext
;
import
iot.sixiang.license.model.dto.ReportErrorMsgDTO
;
import
iot.sixiang.license.service.PmsUseService
;
import
iot.sixiang.license.service.TerminalDeviceService
;
import
iot.sixiang.license.util.CommonUtil
;
import
iot.sixiang.license.util.HexUtil
;
import
iot.sixiang.license.util.SpringUtil
;
...
...
@@ -24,17 +28,21 @@ import org.springframework.stereotype.Component;
import
javax.annotation.Resource
;
import
java.net.InetSocketAddress
;
import
java.util.List
;
@Component
@ChannelHandler
.
Sharable
@Slf4j
public
class
DeviceServerHandler
extends
SimpleChannelInboundHandler
<
Object
>
{
@Autowired
EventPublisher
eventPublisher
;
@Autowired
Safety
safety
;
@Resource
private
PmsUseService
pmsUseService
;
@Resource
TerminalDeviceService
terminalDeviceService
;
public
DeviceServerHandler
()
{
super
();
...
...
@@ -56,12 +64,17 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
boolean
auth
=
false
;
if
(
cmdInt
==
Constant
.
CMD_LICENSE
)
{
auth
=
handlerCheckAuth
(
channel
,
remoteIp
,
remotePort
,
protocol
);
auth
=
handleCheckAuth
(
channel
,
remoteIp
,
remotePort
,
protocol
);
}
else
if
(
cmdInt
==
Constant
.
CMD_UPLOAD_ERROR
)
{
auth
=
handleCheckAuthStatus
(
channel
,
remoteIp
,
remotePort
,
protocol
);
if
(
auth
)
{
handleUploadError
(
channel
,
remoteIp
,
remotePort
,
protocol
);
}
}
else
{
auth
=
handle
r
CheckAuthStatus
(
channel
,
remoteIp
,
remotePort
,
protocol
);
auth
=
handleCheckAuthStatus
(
channel
,
remoteIp
,
remotePort
,
protocol
);
if
(
auth
)
{
log
.
info
(
"auth valid..."
);
handle
r
Forward
(
channel
,
remoteIp
,
remotePort
,
protocol
);
handleForward
(
channel
,
remoteIp
,
remotePort
,
protocol
);
}
}
...
...
@@ -110,7 +123,7 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
ctx
.
close
();
}
private
boolean
handle
r
CheckAuth
(
SocketChannel
channel
,
String
remoteIp
,
int
remotePort
,
DeviceProtocol
protocol
)
{
private
boolean
handleCheckAuth
(
SocketChannel
channel
,
String
remoteIp
,
int
remotePort
,
DeviceProtocol
protocol
)
{
// 正式代码要放开
byte
[]
bytes
=
safety
.
decodeExtendedPayload
(
protocol
.
getContent
(),
0
,
protocol
.
getContent
().
length
);
if
(
bytes
==
null
)
{
...
...
@@ -163,17 +176,50 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
return
license
;
}
private
boolean
handlerCheckAuthStatus
(
SocketChannel
channel
,
String
remoteIp
,
int
remotePort
,
DeviceProtocol
protocol
)
{
private
void
handleUploadError
(
SocketChannel
channel
,
String
remoteIp
,
int
remotePort
,
DeviceProtocol
protocol
)
{
byte
[]
bytes
=
safety
.
decodeExtendedPayload
(
protocol
.
getContent
(),
0
,
protocol
.
getContent
().
length
);
if
(
bytes
==
null
)
{
return
;
}
String
decodeInfo
=
CommonUtil
.
bytesToStr
(
bytes
);
log
.
info
(
"upload error byte to string:"
+
decodeInfo
);
if
(
decodeInfo
==
null
)
{
return
;
}
List
<
ReportErrorMsgDTO
>
reportErrorMsgDTOS
=
JSONArray
.
parseArray
(
decodeInfo
,
ReportErrorMsgDTO
.
class
);
terminalDeviceService
.
reportErrorMsg
(
reportErrorMsgDTOS
);
short
stx
=
21930
;
byte
ack
=
0x0
;
int
len
=
3
;
byte
cmd
=
0x2
;
byte
[]
content
=
new
byte
[
1
];
content
[
0
]
=
0x7e
;
byte
end
=
0x1
;
DeviceProtocol
theProtocol
=
new
DeviceProtocol
(
stx
,
len
,
cmd
,
ack
,
content
,
end
);
handleClient
(
channel
,
theProtocol
);
}
private
boolean
handleCheckAuthStatus
(
SocketChannel
channel
,
String
remoteIp
,
int
remotePort
,
DeviceProtocol
protocol
)
{
String
channelId
=
channel
.
id
().
asLongText
();
DeviceManager
deviceManager
=
SpringUtil
.
getBean
(
DeviceManager
.
class
);
return
deviceManager
.
getAuthStatusByChannelId
(
channelId
);
}
private
void
handle
r
Forward
(
SocketChannel
channel
,
String
remoteIp
,
int
remotePort
,
DeviceProtocol
protocol
)
{
private
void
handleForward
(
SocketChannel
channel
,
String
remoteIp
,
int
remotePort
,
DeviceProtocol
protocol
)
{
String
channelId
=
channel
.
id
().
asLongText
();
ForwardClientRequestEvent
forwardClientRequestEvent
=
new
ForwardClientRequestEvent
();
forwardClientRequestEvent
.
setDeviceChannelId
(
channelId
);
forwardClientRequestEvent
.
setProtocol
(
protocol
);
eventPublisher
.
publishEvent
(
forwardClientRequestEvent
);
}
private
void
handleClient
(
SocketChannel
channel
,
DeviceProtocol
protocol
)
{
String
channelId
=
channel
.
id
().
asLongText
();
DeviceClientLicenseEvent
deviceClientLicenseEvent
=
new
DeviceClientLicenseEvent
();
deviceClientLicenseEvent
.
setDeviceChannelId
(
channelId
);
deviceClientLicenseEvent
.
setProtocol
(
protocol
);
eventPublisher
.
publishEvent
(
deviceClientLicenseEvent
);
}
}
license/src/main/java/iot/sixiang/license/event/DeviceClientLicenseEvent.java
View file @
c108a349
...
...
@@ -6,5 +6,6 @@ import lombok.Data;
@Data
public
class
DeviceClientLicenseEvent
extends
BaseEvent
{
private
String
sn
;
private
String
deviceChannelId
;
private
DeviceProtocol
protocol
;
}
license/src/main/java/iot/sixiang/license/event/DeviceClientLicenseEventHandler.java
View file @
c108a349
...
...
@@ -17,15 +17,19 @@ public class DeviceClientLicenseEventHandler {
EventPublisher
eventPublisher
;
public
DeviceClientLicenseEventHandler
()
{
}
@EventListener
public
void
handlerEvent
(
DeviceClientLicenseEvent
event
)
{
String
appId
=
event
.
getSn
();
String
sn
=
event
.
getSn
();
DeviceProtocol
protocol
=
event
.
getProtocol
();
SessionContext
session
=
null
;
if
(
sn
!=
null
)
{
session
=
deviceManager
.
getSessionContextBySN
(
sn
);
}
else
if
(
event
.
getDeviceChannelId
()
!=
null
)
{
session
=
deviceManager
.
getSessionByChannelId
(
event
.
getDeviceChannelId
());
}
SessionContext
session
=
deviceManager
.
getSessionContextBySN
(
appId
);
if
(
session
==
null
)
{
log
.
debug
(
"device client license undo ..."
);
return
;
...
...
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