Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
H
haikang-client
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
杨立
haikang-client
Commits
2b3bdf4d
提交
2b3bdf4d
authored
9月 16, 2021
作者:
wangqiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
硬件接口实现
上级
6832128c
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
288 行增加
和
2 行删除
+288
-2
HttpController.java
...va/com/priusis/client/extensions/http/HttpController.java
+1
-1
MqttRpcDataMessage.java
...n/java/com/priusis/client/service/MqttRpcDataMessage.java
+2
-0
pom.xml
apq-pc-control/pom.xml
+6
-0
ApqControlApplication.java
...trol/src/main/java/com/priusis/ApqControlApplication.java
+172
-0
HwPortControllerDto.java
...ol/src/main/java/com/priusis/dto/HwPortControllerDto.java
+104
-0
MqttRpcDataMessage.java
...trol/src/main/java/com/priusis/vo/MqttRpcDataMessage.java
+2
-0
RestTest.java
apq-pc-control/src/test/java/com/priusis/RestTest.java
+1
-1
没有找到文件。
apq-pc-client/src/main/java/com/priusis/client/extensions/http/HttpController.java
浏览文件 @
2b3bdf4d
...
...
@@ -44,7 +44,7 @@ public class HttpController {
@RequestMapping
(
value
=
"/rpc_cmd"
,
method
=
RequestMethod
.
POST
)
public
void
handleRpcCmdDataRequest
(
@RequestBody
String
body
)
{
JsonNode
payload
=
fromString
(
body
);
MqttRpcDataMessage
mqttRpcDataMessage
=
MqttRpcDataMessage
.
builder
()
MqttRpcDataMessage
mqttRpcDataMessage
=
MqttRpcDataMessage
.
builder
()
.
sendTime
(
payload
.
get
(
"sendTime"
).
asLong
())
.
method
(
payload
.
get
(
"method"
).
asText
()).
params
(
payload
.
get
(
"params"
).
toPrettyString
()).
build
();
// 存储rpc下发的数据
try
{
...
...
apq-pc-client/src/main/java/com/priusis/client/service/MqttRpcDataMessage.java
浏览文件 @
2b3bdf4d
...
...
@@ -13,12 +13,14 @@ public class MqttRpcDataMessage implements Serializable {
private
int
requestId
;
private
String
method
;
private
Long
sendTime
;
private
String
params
;
@Override
public
String
toString
()
{
return
"{requestId="
+
requestId
+
", method="
+
method
+
", sendTime="
+
sendTime
+
", params="
+
params
+
'}'
;
}
...
...
apq-pc-control/pom.xml
浏览文件 @
2b3bdf4d
...
...
@@ -54,6 +54,12 @@
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
<version>
5.7.11
</version>
</dependency>
<dependency>
<groupId>
com.sun.jna
</groupId>
<artifactId>
jna
</artifactId>
...
...
apq-pc-control/src/main/java/com/priusis/ApqControlApplication.java
浏览文件 @
2b3bdf4d
package
com
.
priusis
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.priusis.dto.HwPortControllerDto
;
import
com.priusis.utils.IHwPortController
;
import
com.priusis.vo.MqttRpcDataMessage
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.web.client.RestTemplate
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
@Slf4j
@EnableScheduling
@SpringBootApplication
(
exclude
=
{
DataSourceAutoConfiguration
.
class
,
SecurityAutoConfiguration
.
class
})
public
class
ApqControlApplication
{
// 一分钟一次上报
private
final
Long
FIXED_DELAY
=
60000L
;
@Autowired
private
RestTemplate
restTemplate
;
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
ApqControlApplication
.
class
,
args
);
}
@Scheduled
(
fixedDelay
=
FIXED_DELAY
)
protected
void
controlProgramTask
()
{
// 获取硬件监控配置 params == data
ResponseEntity
<
MqttRpcDataMessage
>
forEntity
=
restTemplate
.
getForEntity
(
"http://localhost:8765/rpc_cmd/controll"
,
MqttRpcDataMessage
.
class
);
if
(
null
!=
forEntity
)
{
MqttRpcDataMessage
body
=
forEntity
.
getBody
();
String
params
=
body
.
getParams
();
if
(
StrUtil
.
isNotBlank
(
params
))
{
Long
sendTime
=
body
.
getSendTime
();
long
current
=
System
.
currentTimeMillis
();
List
<
HwPortControllerDto
>
hwPortControllerDtos
=
JSONUtil
.
toList
(
params
,
HwPortControllerDto
.
class
);
// 初始化硬件接口管理模块
int
result
=
IHwPortController
.
instanceDll
.
APQ_HWPORT_Initialize
();
log
.
info
(
"APQ_HWPORT_Initialize ret:{}"
,
result
);
if
(
current
-
sendTime
<=
FIXED_DELAY
&&
CollUtil
.
isNotEmpty
(
hwPortControllerDtos
))
{
// 收到硬件策略下发请求
log
.
info
(
"收到硬件策略下发请求, sendTime:{}, params:{}"
,
sendTime
,
params
);
for
(
HwPortControllerDto
hwPortControllerDto
:
hwPortControllerDtos
)
{
HwPortControllerDto
.
DeviceHardwareEnum
deviceHardwareEnum
=
hwPortControllerDto
.
getKey
();
int
doType
=
hwPortControllerDto
.
getDoType
();
int
limitType
=
hwPortControllerDto
.
getLimitType
();
int
value
=
hwPortControllerDto
.
getValue
();
List
<
Integer
>
hwDeviceIds
=
deviceHardwareEnum
.
getHwDeviceIds
();
String
hwDeviceName
=
deviceHardwareEnum
.
getName
();
// 设置普通设备权限
if
(
Objects
.
equals
(
deviceHardwareEnum
.
getHwGroup
(),
"Normal"
))
{
// 1F/2T
for
(
Integer
hwDeviceId
:
hwDeviceIds
)
{
int
perm
=
(
doType
==
1
?
2
:
1
);
int
result32
=
IHwPortController
.
instanceDll
.
APQ_HWPORT_set_normal_device_permit
(
hwDeviceId
,
perm
,
null
);
log
.
info
(
"APQ_HWPORT_set_normal_device_permit doType:{}, limitType;{},value:{}, hwDeviceId:{}, name;{}, perm:{}, ret:{}"
,
doType
,
limitType
,
value
,
hwDeviceId
,
hwDeviceName
,
perm
,
result32
);
}
}
else
if
(
Objects
.
equals
(
deviceHardwareEnum
.
getHwGroup
(),
"Storage"
))
{
// 设置存储设备权限
// 1F/2T/3T-ALL/4T-R/5T-CI/6T-CO 拷出目前无用!! Storage移动硬盘,TYPEC 无效 !!
for
(
Integer
hwDeviceId
:
hwDeviceIds
)
{
int
perm
=
(
doType
==
1
?
2
:
1
);
if
(
perm
==
2
)
{
// limitType 1读写 2只读 3拷入 4拷出 5不限速 6限速
perm
=
(
limitType
==
1
?
3
:
limitType
==
2
?
4
:
limitType
==
3
?
5
:
limitType
==
4
?
6
:
3
);
}
int
result32
=
IHwPortController
.
instanceDll
.
APQ_HWPORT_set_storage_device_permit
(
hwDeviceId
,
perm
,
null
);
log
.
info
(
"APQ_HWPORT_set_storage_device_permit doType:{}, limitType;{},value:{}, hwDeviceId:{}, name;{}, perm:{}, ret:{}"
,
doType
,
limitType
,
value
,
hwDeviceId
,
hwDeviceName
,
perm
,
result32
);
}
}
else
if
(
Objects
.
equals
(
deviceHardwareEnum
.
getHwGroup
(),
"NET"
))
{
// 设置网络设备权限
// 1F/2T/3T-NS/4T-S-200 网口,4G/5G模块,无线WIFI区分不了 !!
for
(
Integer
hwDeviceId
:
hwDeviceIds
)
{
int
perm
=
(
doType
==
1
?
2
:
1
);
if
(
perm
==
2
)
{
// limitType 1读写 2只读 3拷入 4拷出 5不限速 6限速
perm
=
(
limitType
==
5
?
3
:
limitType
==
6
?
4
:
2
);
}
int
result32
=
IHwPortController
.
instanceDll
.
APQ_HWPORT_set_net_device_permit
(
hwDeviceId
,
perm
,
value
,
null
);
log
.
info
(
"APQ_HWPORT_set_net_device_permit doType:{}, limitType;{},value:{}, hwDeviceId:{}, name;{}, perm:{}, ret:{}"
,
doType
,
limitType
,
value
,
hwDeviceId
,
hwDeviceName
,
perm
,
result32
);
}
}
// 应用硬件接口管理模块的配置内容
int
result5
=
IHwPortController
.
instanceDll
.
APQ_HWPORT_Apply
();
log
.
info
(
"APQ_HWPORT_Apply ret:{}"
,
result5
);
}
}
else
{
log
.
info
(
"执行硬件监控, sendTime:{}, params:{}"
,
sendTime
,
params
);
// 上报硬件监控数据
Map
mapRequest
=
new
HashMap
();
for
(
HwPortControllerDto
hwPortControllerDto
:
hwPortControllerDtos
)
{
HwPortControllerDto
.
DeviceHardwareEnum
deviceHardwareEnum
=
hwPortControllerDto
.
getKey
();
int
doType
=
hwPortControllerDto
.
getDoType
();
int
limitType
=
hwPortControllerDto
.
getLimitType
();
int
value
=
hwPortControllerDto
.
getValue
();
List
<
Integer
>
hwDeviceIds
=
deviceHardwareEnum
.
getHwDeviceIds
();
String
hwDeviceName
=
deviceHardwareEnum
.
getName
();
// 设置普通设备权限
if
(
Objects
.
equals
(
deviceHardwareEnum
.
getHwGroup
(),
"Normal"
))
{
// 1F/2T
for
(
Integer
hwDeviceId
:
hwDeviceIds
)
{
int
perm
=
(
doType
==
1
?
2
:
1
);
if
(
perm
==
1
)
{
// 获取普通设备权限
int
result31
=
IHwPortController
.
instanceDll
.
APQ_HWPORT_get_normal_device_permit
(
hwDeviceId
);
log
.
debug
(
"APQ_HWPORT_get_normal_device_permit doType:{}, limitType;{},value:{}, hwDeviceId:{}, name;{}, perm:{}, ret:{}"
,
doType
,
limitType
,
value
,
hwDeviceId
,
hwDeviceName
,
perm
,
result31
);
if
(
result31
==
2
)
{
mapRequest
.
put
(
deviceHardwareEnum
.
name
(),
perm
);
}
}
}
}
else
if
(
Objects
.
equals
(
deviceHardwareEnum
.
getHwGroup
(),
"Storage"
))
{
// 设置存储设备权限
// 1F/2T/3T-ALL/4T-R/5T-CI/6T-CO 拷出目前无用!! Storage移动硬盘,TYPEC 无效 !!
for
(
Integer
hwDeviceId
:
hwDeviceIds
)
{
int
perm
=
(
doType
==
1
?
2
:
1
);
if
(
perm
==
2
)
{
// limitType 1读写 2只读 3拷入 4拷出 5不限速 6限速
perm
=
(
limitType
==
1
?
3
:
limitType
==
2
?
4
:
limitType
==
3
?
5
:
limitType
==
4
?
6
:
3
);
}
int
result32
=
IHwPortController
.
instanceDll
.
APQ_HWPORT_get_storage_device_permit
(
hwDeviceId
);
log
.
info
(
"APQ_HWPORT_get_storage_device_permit doType:{}, limitType;{},value:{}, hwDeviceId:{}, name;{}, perm:{}, ret:{}"
,
doType
,
limitType
,
value
,
hwDeviceId
,
hwDeviceName
,
perm
,
result32
);
if
(
perm
!=
result32
)
{
mapRequest
.
put
(
deviceHardwareEnum
.
name
(),
perm
);
}
}
}
else
if
(
Objects
.
equals
(
deviceHardwareEnum
.
getHwGroup
(),
"NET"
))
{
// 设置网络设备权限
// 1F/2T/3T-NS/4T-S-200 网口,4G/5G模块,无线WIFI区分不了 !!
for
(
Integer
hwDeviceId
:
hwDeviceIds
)
{
int
perm
=
(
doType
==
1
?
2
:
1
);
if
(
perm
==
2
)
{
// limitType 1读写 2只读 3拷入 4拷出 5不限速 6限速
perm
=
(
limitType
==
5
?
3
:
limitType
==
6
?
4
:
2
);
}
int
result32
=
IHwPortController
.
instanceDll
.
APQ_HWPORT_get_net_device_permit
(
hwDeviceId
,
0
);
log
.
info
(
"APQ_HWPORT_get_net_device_permit doType:{}, limitType;{},value:{}, hwDeviceId:{}, name;{}, perm:{}, ret:{}"
,
doType
,
limitType
,
value
,
hwDeviceId
,
hwDeviceName
,
perm
,
result32
);
if
(
perm
!=
result32
)
{
mapRequest
.
put
(
deviceHardwareEnum
.
name
(),
perm
);
}
}
}
}
if
(
mapRequest
.
size
()
>
0
)
{
Map
map
=
restTemplate
.
postForObject
(
"http://localhost:8765/uplink_event/oc-client"
,
mapRequest
,
Map
.
class
);
log
.
info
(
"存在硬件接口扫码告警,上报告警事件: mapData:{}, ret:{}"
,
mapRequest
,
map
);
}
}
// 清理硬件接口管理模块
int
result2
=
IHwPortController
.
instanceDll
.
APQ_HWPORT_Uninitialize
();
log
.
info
(
"APQ_HWPORT_Uninitialize ret:{}"
,
result2
);
}
else
{
log
.
info
(
"未获取到获取硬件监控配置"
);
}
}
else
{
log
.
info
(
"未获取到获取硬件监控配置"
);
}
}
}
apq-pc-control/src/main/java/com/priusis/dto/HwPortControllerDto.java
0 → 100644
浏览文件 @
2b3bdf4d
package
com
.
priusis
.
dto
;
import
lombok.Data
;
import
lombok.Getter
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
@Data
public
class
HwPortControllerDto
{
// doType: 1允许 2禁止
// limitType:1读写 2只读 3拷入 4拷出 5不限速 6限速
// [
// {"key":"USB_DRIVE","doType":1,"limitType":1},
// {"key":"NETWORK_PORT","doType":1,"limitType":1,"value":10},
// {"key":"SERIAL_PORT","doType":1}
// ]
/**
* 设备硬件类型
* <p>
* U盘-USB_DRIVE Storage 0 1F/2T/3T-ALL/4T-R/5T-CI/6T-CO 拷出目前无用!!
* 移动硬盘-MOBILE_DRIVE Storage 0 1F/2T/3T-ALL/4T-R/5T-CI/6T-CO 拷出目前无用!!
* 驱动-CD_DRIVE Storage 0 1F/2T/3T-ALL/4T-R/5T-CI/6T-CO 拷出目前无用!!
* TYPE-C-TYPE-C Storage Storage移动硬盘,TYPEC 无效 !!
* <p>
* 鼠标键盘-MOUSE_KEYBOARD Normal 3+4 1F/2T
* 加密狗-DONGLE Normal 2 1F/2T
* USB转换-USB_TRANSFORM Normal 6 1F/2T
* 摄像头-CAMERA Normal 5 1F/2T
* 串口-SERIAL_PORT Normal 0 1F/2T
* GPIO-GPIO Normal 1 1F/2T
* 无线蓝牙-BLUETOOTH Normal 7 1F/2T
* <p>
* 网口,4G/5G模块,无线WIFI区分不了 !!
* 网口-NETWORK_PORT NET 0 1F/2T/3T-NS/4T-S-200
* 4G/5G模块-MODULE_45G
* 无线WIFI-WIFI
*/
private
DeviceHardwareEnum
key
;
/**
* 1允许 2禁止
*/
private
int
doType
;
/**
* 1读写 2只读 3拷入 4拷出 5不限速 6限速
*/
private
int
limitType
;
/**
* 限速值
*/
private
int
value
;
/**
* 定义普通类设备ID(如USB设备)枚举类型
*/
@Getter
public
enum
DeviceHardwareEnum
{
// Storage 1F/2T/3T-ALL/4T-R/5T-CI/6T-CO 拷出目前无用!! Storage移动硬盘,TYPEC 无效 !!
USB_DRIVE
(
0
,
"Storage"
,
"U盘"
),
MOBILE_DRIVE
(
0
,
"Storage"
,
"移动硬盘"
),
CD_DRIVE
(
0
,
"Storage"
,
"驱动"
),
TYPE_C
(
0
,
"Storage"
,
"TYPE_C"
),
// Normal 1F/2T
MOUSE_KEYBOARD
(
Arrays
.
asList
(
3
,
4
),
"Normal"
,
"鼠标键盘"
),
DONGLE
(
2
,
"Normal"
,
"加密狗"
),
USB_TRANSFORM
(
6
,
"Normal"
,
"USB转换"
),
CAMERA
(
5
,
"Normal"
,
"摄像头"
),
SERIAL_PORT
(
0
,
"Normal"
,
"串口"
),
GPIO
(
1
,
"Normal"
,
"GPIO"
),
BLUETOOTH
(
7
,
"Normal"
,
"无线蓝牙"
),
// NET 1F/2T/3T-NS/4T-S-200 网口,4G/5G模块,无线WIFI区分不了 !!
NETWORK_PORT
(
0
,
"NET"
,
"网口"
),
MODULE_45G
(
0
,
"NET"
,
"4G/5G模块"
),
WIFI
(
0
,
"NET"
,
"无线WIFI"
),
;
private
List
<
Integer
>
hwDeviceIds
;
private
String
hwGroup
;
private
String
name
;
DeviceHardwareEnum
(
List
<
Integer
>
hwDeviceIds
,
String
hwGroup
,
String
name
)
{
this
.
hwDeviceIds
=
hwDeviceIds
;
this
.
hwGroup
=
hwGroup
;
this
.
name
=
name
;
}
DeviceHardwareEnum
(
Integer
hwDeviceId
,
String
hwGroup
,
String
name
)
{
this
.
hwDeviceIds
=
new
ArrayList
<>();
this
.
hwDeviceIds
.
add
(
hwDeviceId
);
this
.
hwGroup
=
hwGroup
;
this
.
name
=
name
;
}
}
}
apq-pc-control/src/main/java/com/priusis/vo/MqttRpcDataMessage.java
浏览文件 @
2b3bdf4d
...
...
@@ -11,11 +11,13 @@ public class MqttRpcDataMessage implements Serializable {
private
int
requestId
;
private
String
method
;
private
Long
sendTime
;
private
String
params
;
@Override
public
String
toString
()
{
return
"{requestId="
+
requestId
+
", sendTime="
+
sendTime
+
", method="
+
method
+
", params="
+
params
+
'}'
;
...
...
apq-pc-control/src/test/java/com/priusis/RestTest.java
浏览文件 @
2b3bdf4d
...
...
@@ -22,7 +22,7 @@ public class RestTest {
@Test
public
void
test1
()
throws
Exception
{
// 获取硬件监控配置 params == data
ResponseEntity
<
MqttRpcDataMessage
>
forEntity
=
restTemplate
.
getForEntity
(
"http://localhost:8765/rpc_cmd/
info
"
,
MqttRpcDataMessage
.
class
);
ResponseEntity
<
MqttRpcDataMessage
>
forEntity
=
restTemplate
.
getForEntity
(
"http://localhost:8765/rpc_cmd/
controll
"
,
MqttRpcDataMessage
.
class
);
System
.
out
.
println
(
forEntity
.
getBody
().
getMethod
());
System
.
out
.
println
(
forEntity
.
getBody
().
getParams
());
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论