Initial commit
commit
34ea26c4b6
@ -0,0 +1,13 @@
|
|||||||
|
### 该问题是怎么引起的?
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### 重现步骤
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### 报错信息
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,33 @@
|
|||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
log
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Mobile Tools for Java (J2ME)
|
||||||
|
.mtj.tmp/
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
.idea
|
||||||
|
target
|
||||||
|
*.iml
|
||||||
|
data/elasticsearch
|
||||||
|
.init
|
||||||
|
*.db
|
||||||
|
.flattened-pom.xml
|
||||||
|
|
||||||
|
.DS_Store
|
||||||
|
dependency-reduced-pom.xml
|
@ -0,0 +1,87 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>iot-iita-plugins</artifactId>
|
||||||
|
<groupId>cc.iotkit.plugins</groupId>
|
||||||
|
<version>2.0.19</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>DLT645-plugin</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.vertx</groupId>
|
||||||
|
<artifactId>vertx-core</artifactId>
|
||||||
|
<version>${vertx.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-transport</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.13.2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>dev</id>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>true</activeByDefault>
|
||||||
|
</activation>
|
||||||
|
<properties>
|
||||||
|
<plugin.build.mode>dev</plugin.build.mode>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
|
||||||
|
<profile>
|
||||||
|
<id>prod</id>
|
||||||
|
<properties>
|
||||||
|
<plugin.build.mode>prod</plugin.build.mode>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.gitee.starblues</groupId>
|
||||||
|
<artifactId>spring-brick-maven-packager</artifactId>
|
||||||
|
<version>${spring-brick.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<mode>${plugin.build.mode}</mode>
|
||||||
|
<pluginInfo>
|
||||||
|
<id>DLT645-plugin</id>
|
||||||
|
<bootstrapClass>cc.iotkit.plugins.dlt645.Application</bootstrapClass>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<provider>iita</provider>
|
||||||
|
<description>DLT645示例插件</description>
|
||||||
|
<configFileName>application.yml</configFileName>
|
||||||
|
</pluginInfo>
|
||||||
|
<prodConfig>
|
||||||
|
<packageType>jar</packageType>
|
||||||
|
</prodConfig>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,143 @@
|
|||||||
|
di1h,di1l,di0h,di0l,format,length,unit,read,write,name
|
||||||
|
9,0,1,0,XXXXXX.XX,4,kWh,TRUE,FALSE,(当前)正向有功总电能
|
||||||
|
9,0,2,0,XXXXXX.XX,4,kWh,TRUE,FALSE,(当前)反向有功总电能
|
||||||
|
9,1,1,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(当前)正向无功总电能
|
||||||
|
9,1,2,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(当前)反向无功总电能
|
||||||
|
9,1,3,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(当前)一象限无功总电能
|
||||||
|
9,1,4,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(当前)四象限无功总电能
|
||||||
|
9,1,5,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(当前)二象限无功总电能
|
||||||
|
9,1,6,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(当前)三象限无功总电能
|
||||||
|
9,4,1,0,XXXXXX.XX,4,kWh,TRUE,FALSE,(上月)正向有功总电能
|
||||||
|
9,4,2,0,XXXXXX.XX,4,kWh,TRUE,FALSE,(上月)反向有功总电能
|
||||||
|
9,5,1,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(上月)正向无功总电能
|
||||||
|
9,5,2,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(上月)反向无功总电能
|
||||||
|
9,5,3,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(上月)一象限无功总电能
|
||||||
|
9,5,4,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(上月)四象限无功总电能
|
||||||
|
9,5,5,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(上月)二象限无功总电能
|
||||||
|
9,5,6,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(上月)三象限无功总电能
|
||||||
|
9,8,1,0,XXXXXX.XX,4,kWh,TRUE,FALSE,(上上月)正向有功总电能
|
||||||
|
9,8,2,0,XXXXXX.XX,4,kWh,TRUE,FALSE,(上上月)反向有功总电能
|
||||||
|
9,9,1,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(上上月)正向无功总电能
|
||||||
|
9,9,2,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(上上月)反向无功总电能
|
||||||
|
9,9,3,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(上上月)一象限无功总电能
|
||||||
|
9,9,4,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(上上月)四象限无功总电能
|
||||||
|
9,9,5,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(上上月)二象限无功总电能
|
||||||
|
9,9,6,0,XXXXXX.XX,4,kvarh,TRUE,FALSE,(上上月)三象限无功总电能
|
||||||
|
A,0,1,0,XX.XXXX,3,kW,TRUE,FALSE,(当前)正向有功总最大需量
|
||||||
|
A,0,2,0,XX.XXXX,3,kW,TRUE,FALSE,(当前)反向有功总最大需量
|
||||||
|
A,1,1,0,XX.XXXX,3,kvar,TRUE,FALSE,(当前)正向无功总最大需量
|
||||||
|
A,1,2,0,XX.XXXX,3,kvar,TRUE,FALSE,(当前)反向无功总最大需量
|
||||||
|
A,1,3,0,XX.XXXX,3,kvar,TRUE,FALSE,(当前)一象限无功最大需量
|
||||||
|
A,1,4,0,XX.XXXX,3,kvar,TRUE,FALSE,(当前)四象限无功最大需量
|
||||||
|
A,1,5,0,XX.XXXX,3,kvar,TRUE,FALSE,(当前)二象限无功最大需量
|
||||||
|
A,1,6,0,XX.XXXX,3,kvar,TRUE,FALSE,(当前)三象限无功最大需量
|
||||||
|
A,4,1,0,XX.XXXX,3,kW,TRUE,FALSE,(上月)正向有功总最大需量
|
||||||
|
A,4,2,0,XX.XXXX,3,kW,TRUE,FALSE,(上月)反向有功总最大需量
|
||||||
|
A,5,1,0,XX.XXXX,3,kvar,TRUE,FALSE,(上月)正向无功总最大需量
|
||||||
|
A,5,2,0,XX.XXXX,3,kvar,TRUE,FALSE,(上月)反向无功总最大需量
|
||||||
|
A,5,3,0,XX.XXXX,3,kvar,TRUE,FALSE,(上月)一象限无功最大需量
|
||||||
|
A,5,4,0,XX.XXXX,3,kvar,TRUE,FALSE,(上月)四象限无功最大需量
|
||||||
|
A,5,5,0,XX.XXXX,3,kvar,TRUE,FALSE,(上月)二象限无功最大需量
|
||||||
|
A,5,6,0,XX.XXXX,3,kvar,TRUE,FALSE,(上月)三象限无功最大需量
|
||||||
|
A,8,1,0,XX.XXXX,3,kvar,TRUE,FALSE,(上上月)正向有功总最大需量
|
||||||
|
A,8,2,0,XX.XXXX,3,kvar,TRUE,FALSE,(上上月)反向有功总最大需量
|
||||||
|
A,9,1,0,XX.XXXX,3,kvar,TRUE,FALSE,(上上月)正向无功总最大需量
|
||||||
|
A,9,2,0,XX.XXXX,3,kvar,TRUE,FALSE,(上上月)反向无功总最大需量
|
||||||
|
A,9,3,0,XX.XXXX,3,kvar,TRUE,FALSE,(上上月)一象限无功最大需量
|
||||||
|
A,9,4,0,XX.XXXX,3,kvar,TRUE,FALSE,(上上月)四象限无功最大需量
|
||||||
|
A,9,5,0,XX.XXXX,3,kvar,TRUE,FALSE,(上上月)二象限无功最大需量
|
||||||
|
A,9,6,0,XX.XXXX,3,kvar,TRUE,FALSE,(上上月)三象限无功最大需量
|
||||||
|
B,0,1,0,MMDDHHmm,4,,TRUE,FALSE,(当前)正向有功总最大需量发生时间
|
||||||
|
B,0,2,0,MMDDHHmm,4,,TRUE,FALSE,(当前)反向有功总最大需量发生时间
|
||||||
|
B,1,1,0,MMDDHHmm,4,,TRUE,FALSE,(当前)正向无功总最大需量发生时间
|
||||||
|
B,1,2,0,MMDDHHmm,4,,TRUE,FALSE,(当前)反向无功总最大需量发生时间
|
||||||
|
B,1,3,0,MMDDHHmm,4,,TRUE,FALSE,(当前)一象限无功最大需量发生时间
|
||||||
|
B,1,4,0,MMDDHHmm,4,,TRUE,FALSE,(当前)四象限无功最大需量发生时间
|
||||||
|
B,1,5,0,MMDDHHmm,4,,TRUE,FALSE,(当前)二象限无功最大需量发生时间
|
||||||
|
B,1,6,0,MMDDHHmm,4,,TRUE,FALSE,(当前)三象限无功最大需量发生时间
|
||||||
|
B,4,1,0,MMDDHHmm,4,,TRUE,FALSE,(上月)正向有功总最大需量发生时间
|
||||||
|
B,4,2,0,MMDDHHmm,4,,TRUE,FALSE,(上月)反向有功总最大需量发生时间
|
||||||
|
B,5,1,0,MMDDHHmm,4,,TRUE,FALSE,(上月)正向无功总最大需量发生时间
|
||||||
|
B,5,2,0,MMDDHHmm,4,,TRUE,FALSE,(上月)反向无功总最大需量发生时间
|
||||||
|
B,5,3,0,MMDDHHmm,4,,TRUE,FALSE,(上月)一象限无功最大需量发生时间
|
||||||
|
B,5,4,0,MMDDHHmm,4,,TRUE,FALSE,(上月)四象限无功最大需量发生时间
|
||||||
|
B,5,5,0,MMDDHHmm,4,,TRUE,FALSE,(上月)二象限无功最大需量发生时间
|
||||||
|
B,5,6,0,MMDDHHmm,4,,TRUE,FALSE,(上月)三象限无功最大需量发生时间
|
||||||
|
B,8,1,0,MMDDHHmm,4,,TRUE,FALSE,(上上月)正向有功总最大需量发生时间
|
||||||
|
B,8,2,0,MMDDHHmm,4,,TRUE,FALSE,(上上月)反向有功总最大需量发生时间
|
||||||
|
B,9,1,0,MMDDHHmm,4,,TRUE,FALSE,(上上月)正向无功总最大需量发生时间
|
||||||
|
B,9,2,0,MMDDHHmm,4,,TRUE,FALSE,(上上月)反向无功总最大需量发生时间
|
||||||
|
B,9,3,0,MMDDHHmm,4,,TRUE,FALSE,(上上月)一象限无功最大需量发生时间
|
||||||
|
B,9,4,0,MMDDHHmm,4,,TRUE,FALSE,(上上月)四象限无功最大需量发生时间
|
||||||
|
B,9,5,0,MMDDHHmm,4,,TRUE,FALSE,(上上月)二象限无功最大需量发生时间
|
||||||
|
B,9,6,0,MMDDHHmm,4,,TRUE,FALSE,(上上月)三象限无功最大需量发生时间
|
||||||
|
B,2,1,0,MMDDHHmm,4,,TRUE,FALSE,最近一次编程时间
|
||||||
|
B,2,1,1,MMDDHHmm,4,,TRUE,FALSE,最近一次最大需量清零时间
|
||||||
|
B,2,1,2,NNNN,2,,TRUE,FALSE,编程次数
|
||||||
|
B,2,1,3,NNNN,2,,TRUE,FALSE,最大需量清零次数
|
||||||
|
B,2,1,4,NNNNNN,3,min,TRUE,FALSE,电池工作时间
|
||||||
|
B,3,1,0,NNNN,2,,TRUE,FALSE,总断相次数
|
||||||
|
B,3,1,1,NNNN,2,,TRUE,FALSE,A 相断相次数
|
||||||
|
B,3,1,2,NNNN,2,,TRUE,FALSE,B 相断相次数
|
||||||
|
B,3,1,3,NNNN,2,,TRUE,FALSE,C 相断相次数
|
||||||
|
B,3,2,0,NNNNNN,3,min,TRUE,FALSE,断相时间累计值
|
||||||
|
B,3,2,1,NNNNNN,3,min,TRUE,FALSE,A 断相时间累计值
|
||||||
|
B,3,2,2,NNNNNN,3,min,TRUE,FALSE,B 断相时间累计值
|
||||||
|
B,3,2,3,NNNNNN,3,min,TRUE,FALSE,C 断相时间累计值
|
||||||
|
B,3,3,0,MMDDHHmm,4,,TRUE,FALSE,最近一次断相起始时刻
|
||||||
|
B,3,3,1,MMDDHHmm,4,,TRUE,FALSE,A 相最近断相起始时刻
|
||||||
|
B,3,3,2,MMDDHHmm,4,,TRUE,FALSE,B 相最近断相起始时刻
|
||||||
|
B,3,3,3,MMDDHHmm,4,,TRUE,FALSE,C相最近断相起始时刻
|
||||||
|
B,3,4,0,MMDDHHmm,4,,TRUE,FALSE,最近一次断相的结束时刻
|
||||||
|
B,3,4,1,MMDDHHmm,4,,TRUE,FALSE,A 相最近一次断相的结束时刻
|
||||||
|
B,3,4,2,MMDDHHmm,4,,TRUE,FALSE,B 相最近一次断相的结束时刻
|
||||||
|
B,3,4,3,MMDDHHmm,4,,TRUE,FALSE,C 相最近一次断相的结束时刻
|
||||||
|
B,6,1,1,XXX,2,V,TRUE,FALSE,A相电压
|
||||||
|
B,6,1,2,XXX,2,V,TRUE,FALSE,B相电压
|
||||||
|
B,6,1,3,XXX,2,V,TRUE,FALSE,C相电压
|
||||||
|
B,6,2,1,XX.XX,2,A,TRUE,FALSE,A相电流
|
||||||
|
B,6,2,2,XX.XX,2,A,TRUE,FALSE,B相电流
|
||||||
|
B,6,2,3,XX.XX,2,A,TRUE,FALSE,C相电流
|
||||||
|
B,6,3,0,XX.XXXX,3,kW,TRUE,FALSE,瞬时有功功率
|
||||||
|
B,6,3,1,XX.XXXX,3,kW,TRUE,FALSE,A相有功功率
|
||||||
|
B,6,3,2,XX.XXXX,3,kW,TRUE,FALSE,B相有功功率
|
||||||
|
B,6,3,3,XX.XXXX,3,kW,TRUE,FALSE,C相有功功率
|
||||||
|
B,6,3,4,XX.XX,2,kW,TRUE,TRUE,正向有功功率上限值
|
||||||
|
B,6,3,5,XX.XX,2,kW,TRUE,TRUE,反向有功功率上限值
|
||||||
|
B,6,4,0,XX.XX,2,kvarh,TRUE,FALSE,瞬时无功功率
|
||||||
|
B,6,4,1,XX.XX,2,kvarh,TRUE,FALSE,A相无功功率
|
||||||
|
B,6,4,2,XX.XX,2,kvarh,TRUE,FALSE,B相无功功率
|
||||||
|
B,6,4,3,XX.XX,2,kvarh,TRUE,FALSE,C相无功功率
|
||||||
|
B,6,5,0,XX.XX,2,kvarh,TRUE,FALSE,总功率因数
|
||||||
|
B,6,5,1,XX.XX,3,kvarh,TRUE,FALSE,A 相功率因数
|
||||||
|
B,6,5,2,XX.XX,4,kvarh,TRUE,FALSE,B 相功率因数
|
||||||
|
B,6,5,3,XX.XX,5,kvarh,TRUE,FALSE,C 相功率因数
|
||||||
|
C,0,1,0,YYMMDDWW,4,,TRUE,TRUE,日期及周次
|
||||||
|
C,0,1,1,hhmmss,3,,TRUE,TRUE,时间
|
||||||
|
C,0,2,0,电表运行状态字,1,,TRUE,TRUE,电表运行状态字
|
||||||
|
C,0,2,1,电网状态字,1,,TRUE,TRUE,电网状态字
|
||||||
|
C,0,2,2,周休日状态字,1,,TRUE,TRUE,周休日状态字
|
||||||
|
C,0,3,0,NNNNNN,3,p/(kWh),TRUE,TRUE,电表常数(有功)
|
||||||
|
C,0,3,1,NNNNNN,3,p/(kvarh),TRUE,TRUE,电表常数(无功)
|
||||||
|
C,0,3,2,NN...NN,6,,TRUE,TRUE,表号
|
||||||
|
C,0,3,3,NN...NN,6,,TRUE,TRUE,用户号
|
||||||
|
C,0,3,4,NN...NN,6,,TRUE,TRUE,设备码
|
||||||
|
C,1,1,1,XX,1,min,TRUE,TRUE,最大需量周期
|
||||||
|
C,1,1,2,XX,1,min,TRUE,TRUE,滑差时间
|
||||||
|
C,1,1,3,XX,1,s,TRUE,TRUE,循显时间
|
||||||
|
C,1,1,4,XX,1,s,TRUE,TRUE,停显时间
|
||||||
|
C,1,1,5,NN,1,,TRUE,TRUE,显示电能小数位数
|
||||||
|
C,1,1,6,NN,1,,TRUE,TRUE,显示功率(最大需量)小数位数
|
||||||
|
C,1,1,7,DDhh,2,,TRUE,TRUE,自动抄表日期
|
||||||
|
C,1,1,8,NN,1,,TRUE,TRUE,负荷代表日
|
||||||
|
C,1,1,9,NNNNNN.N,4,kWh,TRUE,TRUE,有功电能起始读数
|
||||||
|
C,1,1,A,NNNNNN.N,4,kvarh,TRUE,TRUE,无功电能起始读数
|
||||||
|
C,2,1,1,NNNN,2,ms,TRUE,TRUE,输出脉冲宽度
|
||||||
|
C,2,1,2,NNNNNNNN,4,,FALSE,TRUE,密码权限及密码
|
||||||
|
C,3,1,0,NN,1,,TRUE,TRUE,年时区数
|
||||||
|
C,3,1,1,NN,1,,TRUE,TRUE,日时段表数
|
||||||
|
C,3,1,2,NN,1,,TRUE,TRUE,日时段(每日切换数)m≤10
|
||||||
|
C,3,1,3,NN,1,,TRUE,TRUE,费率数 k≤14
|
||||||
|
C,3,1,4,NN,1,,TRUE,TRUE,公共假日数
|
||||||
|
C,5,1,0,MMDDhhmm,4,,TRUE,TRUE,负荷记录起始时间
|
||||||
|
C,5,1,1,mmmm,2,min,TRUE,TRUE,负荷记录间隔时间
|
|
|
@ -0,0 +1,8 @@
|
|||||||
|
plugin:
|
||||||
|
runMode: prod
|
||||||
|
mainPackage: cc.iotkit.plugin
|
||||||
|
|
||||||
|
tcp:
|
||||||
|
host: 25on621889.goho.co
|
||||||
|
port: 43161
|
||||||
|
interval: 10000
|
@ -0,0 +1,23 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "host",
|
||||||
|
"name": "服务端ip",
|
||||||
|
"type": "text",
|
||||||
|
"value": "25on621889.goho.co",
|
||||||
|
"desc": "服务端ip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "port",
|
||||||
|
"name": "服务端端口",
|
||||||
|
"type": "number",
|
||||||
|
"value": 43161,
|
||||||
|
"desc": "服务端端口"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "interval",
|
||||||
|
"name": "采集频率",
|
||||||
|
"type": "number",
|
||||||
|
"value": 10000,
|
||||||
|
"desc": "采集频率"
|
||||||
|
}
|
||||||
|
]
|
@ -0,0 +1,201 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
@ -0,0 +1,36 @@
|
|||||||
|
# iot-iita-plugins
|
||||||
|
|
||||||
|
#### Description
|
||||||
|
官方插件示例仓库
|
||||||
|
|
||||||
|
#### Software Architecture
|
||||||
|
Software architecture description
|
||||||
|
|
||||||
|
#### Installation
|
||||||
|
|
||||||
|
1. xxxx
|
||||||
|
2. xxxx
|
||||||
|
3. xxxx
|
||||||
|
|
||||||
|
#### Instructions
|
||||||
|
|
||||||
|
1. xxxx
|
||||||
|
2. xxxx
|
||||||
|
3. xxxx
|
||||||
|
|
||||||
|
#### Contribution
|
||||||
|
|
||||||
|
1. Fork the repository
|
||||||
|
2. Create Feat_xxx branch
|
||||||
|
3. Commit your code
|
||||||
|
4. Create Pull Request
|
||||||
|
|
||||||
|
|
||||||
|
#### Gitee Feature
|
||||||
|
|
||||||
|
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
|
||||||
|
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
|
||||||
|
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
|
||||||
|
4. The most valuable open source project [GVP](https://gitee.com/gvp)
|
||||||
|
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
|
||||||
|
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
@ -0,0 +1,37 @@
|
|||||||
|
# iot-iita-plugins
|
||||||
|
|
||||||
|
#### 介绍
|
||||||
|
官方插件示例仓库
|
||||||
|
|
||||||
|
#### 软件架构
|
||||||
|
软件架构说明
|
||||||
|
|
||||||
|
|
||||||
|
#### 安装教程
|
||||||
|
|
||||||
|
1. xxxx
|
||||||
|
2. xxxx
|
||||||
|
3. xxxx
|
||||||
|
|
||||||
|
#### 使用说明
|
||||||
|
|
||||||
|
1. xxxx
|
||||||
|
2. xxxx
|
||||||
|
3. xxxx
|
||||||
|
|
||||||
|
#### 参与贡献
|
||||||
|
|
||||||
|
1. Fork 本仓库
|
||||||
|
2. 新建 Feat_xxx 分支
|
||||||
|
3. 提交代码
|
||||||
|
4. 新建 Pull Request
|
||||||
|
|
||||||
|
|
||||||
|
#### 特技
|
||||||
|
|
||||||
|
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
|
||||||
|
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
|
||||||
|
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
|
||||||
|
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
|
||||||
|
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
|
||||||
|
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
@ -0,0 +1,86 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>iot-iita-plugins</artifactId>
|
||||||
|
<groupId>cc.iotkit.plugins</groupId>
|
||||||
|
<version>2.10.19</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>emqx-plugin</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.vertx</groupId>
|
||||||
|
<artifactId>vertx-core</artifactId>
|
||||||
|
<version>${vertx.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.vertx</groupId>
|
||||||
|
<artifactId>vertx-mqtt</artifactId>
|
||||||
|
<version>${vertx.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.vertx</groupId>
|
||||||
|
<artifactId>vertx-web-proxy</artifactId>
|
||||||
|
<version>${vertx.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>dev</id>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>true</activeByDefault>
|
||||||
|
</activation>
|
||||||
|
<properties>
|
||||||
|
<plugin.build.mode>dev</plugin.build.mode>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
|
||||||
|
<profile>
|
||||||
|
<id>prod</id>
|
||||||
|
<properties>
|
||||||
|
<plugin.build.mode>prod</plugin.build.mode>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.gitee.starblues</groupId>
|
||||||
|
<artifactId>spring-brick-maven-packager</artifactId>
|
||||||
|
<version>${spring-brick.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<mode>${plugin.build.mode}</mode>
|
||||||
|
<pluginInfo>
|
||||||
|
<id>emqx-plugin</id>
|
||||||
|
<bootstrapClass>cc.iotkit.plugins.emqx.Application</bootstrapClass>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<provider>iita</provider>
|
||||||
|
<description>emqx示例插件</description>
|
||||||
|
<configFileName>application.yml</configFileName>
|
||||||
|
</pluginInfo>
|
||||||
|
<prodConfig>
|
||||||
|
<packageType>jar</packageType>
|
||||||
|
</prodConfig>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,19 @@
|
|||||||
|
package cc.iotkit.plugins.emqx;
|
||||||
|
|
||||||
|
import com.gitee.starblues.bootstrap.SpringPluginBootstrap;
|
||||||
|
import com.gitee.starblues.bootstrap.annotation.OneselfConfig;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sjg
|
||||||
|
*/
|
||||||
|
@SpringBootApplication(scanBasePackages = "cc.iotkit.plugins.emqx")
|
||||||
|
@OneselfConfig(mainConfigFileName = {"application.yml"})
|
||||||
|
@EnableConfigurationProperties
|
||||||
|
public class Application extends SpringPluginBootstrap {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new Application().run(Application.class, args);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package cc.iotkit.plugins.emqx.conf;
|
||||||
|
|
||||||
|
import cc.iotkit.plugin.core.IPluginConfig;
|
||||||
|
import cc.iotkit.plugin.core.LocalPluginConfig;
|
||||||
|
import cc.iotkit.plugin.core.thing.IThingService;
|
||||||
|
import cc.iotkit.plugins.emqx.service.FakeThingService;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sjg
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class BeanConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnProperty(name = "plugin.runMode", havingValue = "dev")
|
||||||
|
IThingService getThingService() {
|
||||||
|
return new FakeThingService();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnProperty(name = "plugin.runMode", havingValue = "dev")
|
||||||
|
IPluginConfig getPluginConfig(){
|
||||||
|
return new LocalPluginConfig();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
package cc.iotkit.plugins.emqx.conf;
|
||||||
|
|
||||||
|
public class CRC16ModbusUtil {
|
||||||
|
private static final int POLY = 0xA001;
|
||||||
|
private static final int INIT_VALUE = 0xFFFF;
|
||||||
|
|
||||||
|
public static String calculate(String hexStr) {
|
||||||
|
byte[] data = hexToByteArray(hexStr);
|
||||||
|
int crc = calculateCrc(data);
|
||||||
|
return String.format("%04X", crc);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int calculateCrc(byte[] data) {
|
||||||
|
int crc = INIT_VALUE;
|
||||||
|
for (byte b : data) {
|
||||||
|
crc ^= (b & 0xFF);
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
boolean lsb = (crc & 1) == 1;
|
||||||
|
crc >>>= 1;
|
||||||
|
if (lsb) crc ^= POLY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] hexToByteArray(String hexStr) {
|
||||||
|
if (hexStr.length() % 2 != 0) {
|
||||||
|
throw new IllegalArgumentException("Hex string must have even length");
|
||||||
|
}
|
||||||
|
byte[] bytes = new byte[hexStr.length() / 2];
|
||||||
|
for (int i = 0; i < bytes.length; i++) {
|
||||||
|
String byteStr = hexStr.substring(2*i, 2*i+2);
|
||||||
|
bytes[i] = (byte) Integer.parseInt(byteStr, 16);
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
*3.1 帧结构
|
||||||
|
* 字段名 长度 代号 备注
|
||||||
|
* 帧头 1 HEAD 固定为0xaa
|
||||||
|
* 协议类型 1 TYPE
|
||||||
|
* 协议版本 1 VERSION
|
||||||
|
* 帧长度 2 LENGTH
|
||||||
|
* 消息序号 1 MID
|
||||||
|
* 命令码 1 CMD
|
||||||
|
* 数据域 N DATA
|
||||||
|
* 帧校验 2 CRC 采用CRC16-MODBUS校验方式
|
||||||
|
* 帧尾 1 TAIL 固定为0x55
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
public static String buildFrame(
|
||||||
|
String type, String version,
|
||||||
|
String mid, String cmd, String dataHex
|
||||||
|
) {
|
||||||
|
String headerLength = "AA" + type + version + mid + cmd + dataHex +"crc1"+ "55";
|
||||||
|
Integer length =headerLength.length()/2;
|
||||||
|
String header = "AA" + type + version + length + mid + cmd;
|
||||||
|
String crcData = length + mid + cmd + dataHex;
|
||||||
|
String crc = calculate(crcData);
|
||||||
|
return header + dataHex + crc + "55";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,99 @@
|
|||||||
|
package cc.iotkit.plugins.emqx.conf;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static cc.iotkit.common.utils.HexUtil.hexStringToByteArray;
|
||||||
|
|
||||||
|
public class DeviceStatusParser {
|
||||||
|
|
||||||
|
private static final int COMMAND_CODE = 0x11;
|
||||||
|
public static Map<String, Object> parseStatusReportToMap(String hexData) {
|
||||||
|
byte[] data = GasAlarmDataParser.hexStringToByteArray(hexData);
|
||||||
|
return parseStatusReport(data);
|
||||||
|
}
|
||||||
|
public static Map<String, Object> parseStatusReport(byte[] hexData) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
ByteBuffer buffer = ByteBuffer.wrap(hexData);
|
||||||
|
|
||||||
|
// 验证命令码
|
||||||
|
/* int cmd = buffer.get() & 0xFF;
|
||||||
|
if (cmd != COMMAND_CODE) {
|
||||||
|
throw new IllegalArgumentException("Invalid command code: 0x" + Integer.toHexString(cmd));
|
||||||
|
}*/
|
||||||
|
|
||||||
|
// 解析终端类型 (2字节)
|
||||||
|
int deviceType = buffer.getShort() & 0xFFFF;
|
||||||
|
result.put("deviceType", deviceType);
|
||||||
|
|
||||||
|
// 解析设备编号IMEI (15字节) 对应程序的
|
||||||
|
byte[] imeiBytes = new byte[15];
|
||||||
|
buffer.get(imeiBytes);
|
||||||
|
result.put("imei", new String(imeiBytes).trim());
|
||||||
|
|
||||||
|
// 解析ICCID卡号 (20字节)
|
||||||
|
byte[] iccidBytes = new byte[20];
|
||||||
|
buffer.get(iccidBytes);
|
||||||
|
result.put("iccid", new String(iccidBytes).trim());
|
||||||
|
|
||||||
|
// 解析软件版本 (4字节)
|
||||||
|
byte[] versionBytes = new byte[4];
|
||||||
|
buffer.get(versionBytes);
|
||||||
|
result.put("version", bytesToVersion(versionBytes));
|
||||||
|
|
||||||
|
// 解析通信模式 (1字节)
|
||||||
|
int commMode = buffer.get() & 0xFF;
|
||||||
|
result.put("communicationMode", commMode);
|
||||||
|
|
||||||
|
// 解析信号强度 (1字节)
|
||||||
|
int signal = buffer.get() & 0xFF;
|
||||||
|
result.put("signalStrength", signal);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getDeviceTypeName(int type) {
|
||||||
|
switch (type) {
|
||||||
|
case 0: return "家用报警器";
|
||||||
|
case 1: return "独立式报警器";
|
||||||
|
case 2: return "工商业控制器";
|
||||||
|
case 3: return "动火离人设备";
|
||||||
|
default: return "未知设备类型";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getCommModeName(int mode) {
|
||||||
|
switch (mode) {
|
||||||
|
case 0: return "NB-IoT";
|
||||||
|
case 1: return "4G";
|
||||||
|
case 2: return "WiFi";
|
||||||
|
default: return "未知通信模式";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String bytesToVersion(byte[] bytes) {
|
||||||
|
return String.format("%d.%d.%d.%d",
|
||||||
|
bytes[0] & 0xFF,
|
||||||
|
bytes[1] & 0xFF,
|
||||||
|
bytes[2] & 0xFF,
|
||||||
|
bytes[3] & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// 示例16进制数据 (命令码0x11 + 测试数据)
|
||||||
|
byte[] testData = new byte[] {
|
||||||
|
// 0x11, // 命令码
|
||||||
|
0x00, 0x02, // 工商业控制器
|
||||||
|
'8','6','1','2','3','4','0','0','0','0','1','2','3','4','5', // IMEI
|
||||||
|
'8','9','8','6','0','0','0','0','0','0','0','0','0','0','0','1','2','3','4','5', // ICCID
|
||||||
|
0x01, 0x02, 0x03, 0x04, // 软件版本1.2.3.4
|
||||||
|
0x01, // 4G通信
|
||||||
|
0x5A,0X5A // 信号强度90
|
||||||
|
};
|
||||||
|
|
||||||
|
Map<String, Object> result = DeviceStatusParser.parseStatusReport(testData);
|
||||||
|
System.out.println("解析结果: " + result);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
package cc.iotkit.plugins.emqx.conf;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class EventTypeMapper {
|
||||||
|
private static final Map<Integer, String> EVENT_TYPE_MAP = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
// 节点相关事件
|
||||||
|
EVENT_TYPE_MAP.put(1, "首警高");
|
||||||
|
EVENT_TYPE_MAP.put(2, "首警低");
|
||||||
|
EVENT_TYPE_MAP.put(3, "报警高");
|
||||||
|
EVENT_TYPE_MAP.put(4, "报警低");
|
||||||
|
EVENT_TYPE_MAP.put(5, "低限报警恢复");
|
||||||
|
EVENT_TYPE_MAP.put(6, "高限报警恢复");
|
||||||
|
EVENT_TYPE_MAP.put(7, "探头传感器故障");
|
||||||
|
EVENT_TYPE_MAP.put(8, "节点通讯断网故障");
|
||||||
|
EVENT_TYPE_MAP.put(9, "探头传感器故障恢复");
|
||||||
|
EVENT_TYPE_MAP.put(10, "节点通讯断网故障恢复");
|
||||||
|
EVENT_TYPE_MAP.put(11, "自检/模块联动");
|
||||||
|
EVENT_TYPE_MAP.put(12, "阀门动作");
|
||||||
|
|
||||||
|
// 控制器相关事件
|
||||||
|
EVENT_TYPE_MAP.put(13, "自检");
|
||||||
|
EVENT_TYPE_MAP.put(14, "备电故障");
|
||||||
|
EVENT_TYPE_MAP.put(15, "主电故障");
|
||||||
|
EVENT_TYPE_MAP.put(16, "主电欠压");
|
||||||
|
EVENT_TYPE_MAP.put(17, "控制器复位");
|
||||||
|
EVENT_TYPE_MAP.put(18, "控制器开机");
|
||||||
|
EVENT_TYPE_MAP.put(19, "主电故障恢复");
|
||||||
|
EVENT_TYPE_MAP.put(20, "备电故障恢复");
|
||||||
|
EVENT_TYPE_MAP.put(21, "主电欠压恢复");
|
||||||
|
|
||||||
|
// 动火离人相关事件
|
||||||
|
EVENT_TYPE_MAP.put(22, "设备开机");
|
||||||
|
EVENT_TYPE_MAP.put(23, "动火离人报警");
|
||||||
|
EVENT_TYPE_MAP.put(24, "动火离人报警恢复");
|
||||||
|
EVENT_TYPE_MAP.put(25, "设备故障");
|
||||||
|
EVENT_TYPE_MAP.put(26, "设备故障恢复");
|
||||||
|
EVENT_TYPE_MAP.put(27, "断网故障");
|
||||||
|
EVENT_TYPE_MAP.put(28, "断网故障恢复");
|
||||||
|
|
||||||
|
// 正常上报事件
|
||||||
|
EVENT_TYPE_MAP.put(128, "燃气报警器正常数据上报");
|
||||||
|
EVENT_TYPE_MAP.put(129, "动火离人正常数据上报");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getEventTypeName(int eventType) {
|
||||||
|
return EVENT_TYPE_MAP.getOrDefault(eventType, "未知事件类型");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,197 @@
|
|||||||
|
package cc.iotkit.plugins.emqx.conf;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class IoTConfigProtocol {
|
||||||
|
// 配置项常量定义(完整版)
|
||||||
|
public static final int IP_REALM = 0x0000;
|
||||||
|
public static final int PORT = 0x0001;
|
||||||
|
public static final int REPORT_AWAIT_TIME = 0x0002;
|
||||||
|
public static final int REPORT_RETRY_TIMES = 0x0003;
|
||||||
|
public static final int CARD = 0x0004;
|
||||||
|
public static final int USERNAME = 0x0010;
|
||||||
|
public static final int PASSWORD = 0x0011;
|
||||||
|
public static final int KEEP_ALIVE = 0x0012;
|
||||||
|
public static final int PUBLISH_TOPIC = 0x0016;
|
||||||
|
public static final int SUBSCRIBE_TOPIC = 0x0017;
|
||||||
|
public static final int REPORT_RATE_UPPER = 0x0021;
|
||||||
|
public static final int REPORT_CONCENTRATION_RANGE = 0x0022;
|
||||||
|
public static final int REPORT_RATE_LOWER = 0x0023;
|
||||||
|
public static final int SIGNAL = 0x0024;
|
||||||
|
public static final int TIME_SYNC = 0x0025;
|
||||||
|
public static final int VERSION = 0x0026;
|
||||||
|
// 生成读取指令
|
||||||
|
public static String generateReadCommand(int terminalType, int configId) {
|
||||||
|
ByteBuffer buf = ByteBuffer.allocate(4);
|
||||||
|
// buf.putShort((short) 0xAA23); // 起始符+命令码
|
||||||
|
// buf.putShort((short) 4); // 数据长度
|
||||||
|
buf.putShort((short) terminalType);
|
||||||
|
buf.putShort((short) configId);
|
||||||
|
return bytesToHex(buf.array());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成写入指令
|
||||||
|
public static String generateWriteCommand(int terminalType, int configId, byte[] data) {
|
||||||
|
|
||||||
|
ByteBuffer buf = ByteBuffer.allocate(5 + data.length);
|
||||||
|
//buf.putShort((short) (5 + data.length)); // 数据长度
|
||||||
|
buf.putShort((short) terminalType);
|
||||||
|
buf.putShort((short) configId);
|
||||||
|
buf.put((byte) data.length); // 数据长度字节
|
||||||
|
buf.put(data); // 实际数据
|
||||||
|
|
||||||
|
return bytesToHex(buf.array());
|
||||||
|
}
|
||||||
|
// 完整读取响应解析
|
||||||
|
public static Map<String, Object> parseReadResponse(String hexResp) {
|
||||||
|
byte[] data = hexToBytes(hexResp);
|
||||||
|
ByteBuffer buf = ByteBuffer.wrap(data);
|
||||||
|
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
result.put("commandCode", buf.get() & 0xFF);
|
||||||
|
result.put("configId", buf.getShort() & 0xFFFF);
|
||||||
|
|
||||||
|
int dataLen = buf.get() & 0xFF;
|
||||||
|
byte[] value = new byte[dataLen];
|
||||||
|
buf.get(value);
|
||||||
|
|
||||||
|
// 根据配置ID进行类型化解析
|
||||||
|
switch((int)result.get("configId")) {
|
||||||
|
case IP_REALM:
|
||||||
|
case PUBLISH_TOPIC:
|
||||||
|
case SUBSCRIBE_TOPIC:
|
||||||
|
result.put("value", parseTLVString(value));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PORT:
|
||||||
|
case KEEP_ALIVE:
|
||||||
|
case REPORT_RATE_UPPER:
|
||||||
|
case REPORT_CONCENTRATION_RANGE:
|
||||||
|
case REPORT_RATE_LOWER:
|
||||||
|
result.put("value", ByteBuffer.wrap(value).getShort());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case REPORT_AWAIT_TIME:
|
||||||
|
case REPORT_RETRY_TIMES:
|
||||||
|
case SIGNAL:
|
||||||
|
result.put("value", value[0] & 0xFF);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CARD:
|
||||||
|
result.put("value", parseSimCard(value));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TIME_SYNC:
|
||||||
|
result.put("value", parseBcdTime(value));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VERSION:
|
||||||
|
result.put("value", parseVersion(value));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
result.put("value", bytesToHex(value));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 特殊格式解析方法
|
||||||
|
private static String parseTLVString(byte[] data) {
|
||||||
|
int len = data[0] & 0xFF;
|
||||||
|
return new String(data, 1, Math.min(len, data.length-1), StandardCharsets.US_ASCII);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String parseSimCard(byte[] data) {
|
||||||
|
int len = data[0] & 0xFF;
|
||||||
|
return new String(data, 1, Math.min(len, 20), StandardCharsets.US_ASCII);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String parseBcdTime(byte[] data) {
|
||||||
|
return String.format("20%02d-%02d-%02d %02d:%02d:%02d",
|
||||||
|
bcdToInt(data[0]), bcdToInt(data[1]), bcdToInt(data[2]),
|
||||||
|
bcdToInt(data[3]), bcdToInt(data[4]), bcdToInt(data[5]));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int bcdToInt(byte b) {
|
||||||
|
return ((b >> 4) & 0x0F)*10 + (b & 0x0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String parseVersion(byte[] data) {
|
||||||
|
return String.format("%d.%d.%d.%d",
|
||||||
|
data[0] & 0xFF, data[1] & 0xFF,
|
||||||
|
data[2] & 0xFF, data[3] & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 字节数组与16进制转换工具
|
||||||
|
private static String bytesToHex(byte[] bytes) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (byte b : bytes) {
|
||||||
|
sb.append(String.format("%02X", b));
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* ip地址转换成TLV数据
|
||||||
|
* */
|
||||||
|
public static byte[] buildTLVData(byte[] value) {
|
||||||
|
byte[] data = new byte[value.length + 1];
|
||||||
|
data[0] = (byte)value.length;
|
||||||
|
System.arraycopy(value, 0, data, 1, value.length);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* 构建单字节数据
|
||||||
|
* */
|
||||||
|
public static byte[] buildByteData(int value) {
|
||||||
|
return new byte[] { (byte)(value & 0xFF) };
|
||||||
|
}
|
||||||
|
// 构建字符串类型数据(带长度前缀)
|
||||||
|
public static byte[] buildStringData(String value, int maxLength) {
|
||||||
|
byte[] strBytes = value.getBytes(StandardCharsets.US_ASCII);
|
||||||
|
if(strBytes.length > maxLength) {
|
||||||
|
throw new IllegalArgumentException("Value exceeds max length");
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] data = new byte[strBytes.length+1];
|
||||||
|
data[0] = (byte) strBytes.length;
|
||||||
|
System.arraycopy(strBytes, 0, data, 1, strBytes.length);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
// 构建BCD时间数据(YYMMDDhhmmss)
|
||||||
|
public static byte[] buildBcdTimeData(String time) {
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyMMddHHmmss");
|
||||||
|
String formatted = LocalDateTime.now().format(formatter);
|
||||||
|
|
||||||
|
byte[] bcdData = new byte[6];
|
||||||
|
for(int i = 0; i < 6; i++) {
|
||||||
|
int pair = Integer.parseInt(formatted.substring(i*2, i*2+2));
|
||||||
|
bcdData[i] = (byte)(((pair / 10) << 4) | (pair % 10));
|
||||||
|
}
|
||||||
|
return bcdData;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建版本号数据(4字节)
|
||||||
|
/* public static byte[] buildVersionData(String version) {
|
||||||
|
String[] parts = version.split("\\.");
|
||||||
|
if(parts.length != 4) throw new IllegalArgumentException();
|
||||||
|
|
||||||
|
byte[] data = new byte[4];
|
||||||
|
for(int i = 0; i < 4; i++) {
|
||||||
|
data[i] = (byte)Integer.parseInt(parts[i]);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}*/
|
||||||
|
private static byte[] hexToBytes(String hex) {
|
||||||
|
hex = hex.replaceAll("\\s", "");
|
||||||
|
byte[] data = new byte[hex.length()/2];
|
||||||
|
for (int i=0; i<hex.length(); i+=2) {
|
||||||
|
data[i/2] = (byte)Integer.parseInt(hex.substring(i,i+2),16);
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* +----------------------------------------------------------------------
|
||||||
|
* | Copyright (c) 奇特物联 2021-2022 All rights reserved.
|
||||||
|
* +----------------------------------------------------------------------
|
||||||
|
* | Licensed 未经许可不能去掉「奇特物联」相关版权
|
||||||
|
* +----------------------------------------------------------------------
|
||||||
|
* | Author: xw2sy@163.com
|
||||||
|
* +----------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
package cc.iotkit.plugins.emqx.conf;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Component
|
||||||
|
@ConfigurationProperties(prefix = "emqx")
|
||||||
|
public class MqttConfig {
|
||||||
|
|
||||||
|
private String host;
|
||||||
|
|
||||||
|
private int port;
|
||||||
|
|
||||||
|
private boolean ssl;
|
||||||
|
|
||||||
|
private String topics;
|
||||||
|
|
||||||
|
private int authPort;
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
package cc.iotkit.plugins.emqx.conf;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static cc.iotkit.plugins.emqx.conf.IoTConfigProtocol.buildTLVData;
|
||||||
|
|
||||||
|
public class ProtocolTest {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// 1. IP/域名配置 (TLV格式)
|
||||||
|
String ip = "192.168.1.100";
|
||||||
|
byte[] ipData = buildTLVData(ip.getBytes());
|
||||||
|
String writeIpCmd = IoTConfigProtocol.generateWriteCommand(0x01,
|
||||||
|
IoTConfigProtocol.IP_REALM, ipData);
|
||||||
|
System.out.println("写入IP指令: " + writeIpCmd);
|
||||||
|
|
||||||
|
// 2. 端口配置 (2字节大端序)
|
||||||
|
short port = 1883;
|
||||||
|
byte[] portData = ByteBuffer.allocate(2).putShort(port).array();
|
||||||
|
String writePortCmd = IoTConfigProtocol.generateWriteCommand(0x01,
|
||||||
|
IoTConfigProtocol.PORT, portData);
|
||||||
|
System.out.println("写入端口指令: " + writePortCmd);
|
||||||
|
|
||||||
|
// 3. SIM卡号读取 (只读)
|
||||||
|
String readCardCmd = IoTConfigProtocol.generateReadCommand(0x01,
|
||||||
|
IoTConfigProtocol.CARD);
|
||||||
|
System.out.println("读取SIM卡指令: " + readCardCmd);
|
||||||
|
|
||||||
|
// 4. 时间同步设置 (BCD编码)
|
||||||
|
byte[] timeData = new byte[6];
|
||||||
|
String currentTime = new SimpleDateFormat("yyMMddHHmmss")
|
||||||
|
.format(new Date());
|
||||||
|
for(int i=0; i<6; i++){
|
||||||
|
int digit = Integer.parseInt(currentTime.substring(i*2, i*2+2));
|
||||||
|
timeData[i] = (byte)(((digit/10)<<4) | (digit%10));
|
||||||
|
}
|
||||||
|
String writeTimeCmd = IoTConfigProtocol.generateWriteCommand(0x01,
|
||||||
|
IoTConfigProtocol.TIME_SYNC, timeData);
|
||||||
|
System.out.println("时间同步指令: " + writeTimeCmd);
|
||||||
|
|
||||||
|
// 5. 版本号读取 (4字节)
|
||||||
|
String readVerCmd = IoTConfigProtocol.generateReadCommand(0x01,
|
||||||
|
IoTConfigProtocol.VERSION);
|
||||||
|
System.out.println("读取版本指令: " + readVerCmd);
|
||||||
|
|
||||||
|
// 6. 信号强度读取 (1字节)
|
||||||
|
String readSignalCmd = IoTConfigProtocol.generateReadCommand(0x01,
|
||||||
|
IoTConfigProtocol.SIGNAL);
|
||||||
|
System.out.println("读取信号指令: " + readSignalCmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建TLV格式数据
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package cc.iotkit.plugins.emqx.conf;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ResponseParserDemo {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// 模拟IP响应数据 000100000E0D3139322E3136382E312E313030
|
||||||
|
String ipResponse = "0000000E0D3139322E3136382E312E313030";
|
||||||
|
Map<String, Object> ipResult = IoTConfigProtocol.parseReadResponse(ipResponse);
|
||||||
|
System.out.println("IP解析结果: " + ipResult.get("value"));
|
||||||
|
|
||||||
|
// 模拟端口响应
|
||||||
|
String portResponse = "000001020383";
|
||||||
|
Map<String, Object> portResult = IoTConfigProtocol.parseReadResponse(portResponse);
|
||||||
|
System.out.println("端口解析结果: " + portResult.get("value"));
|
||||||
|
|
||||||
|
// 模拟SIM卡响应
|
||||||
|
String cardResponse = "00001800040015464347413230313233343536373839303132";
|
||||||
|
Map<String, Object> cardResult = IoTConfigProtocol.parseReadResponse(cardResponse);
|
||||||
|
System.out.println("SIM卡解析结果: " + cardResult.get("value"));
|
||||||
|
|
||||||
|
// 模拟时间响应
|
||||||
|
String timeResponse = "00000D00250605143000";
|
||||||
|
Map<String, Object> timeResult = IoTConfigProtocol.parseReadResponse(timeResponse);
|
||||||
|
System.out.println("时间解析结果: " + timeResult.get("value"));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package cc.iotkit.plugins.emqx.handler;
|
||||||
|
|
||||||
|
import io.vertx.core.json.JsonObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sjg
|
||||||
|
*/
|
||||||
|
public interface IMsgHandler {
|
||||||
|
|
||||||
|
void handle(String topic, JsonObject payload);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
package cc.iotkit.plugins.emqx.service;
|
||||||
|
|
||||||
|
import cc.iotkit.plugin.core.thing.IThingService;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.ActionResult;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.IDeviceAction;
|
||||||
|
import cc.iotkit.plugin.core.thing.model.ThingDevice;
|
||||||
|
import cc.iotkit.plugin.core.thing.model.ThingProduct;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试服务
|
||||||
|
*
|
||||||
|
* @author sjg
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class FakeThingService implements IThingService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加测试产品
|
||||||
|
*/
|
||||||
|
private static final Map<String, String> PRODUCTS = Map.of(
|
||||||
|
"hbtgIA0SuVw9lxjB", "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
|
||||||
|
"Rf4QSjbm65X45753", "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
|
||||||
|
"cGCrkK7Ex4FESAwe", "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU"
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加测试设备
|
||||||
|
*/
|
||||||
|
private static final Map<String, String> DEVICES = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
DEVICES.put("TEST:GW:" + StringUtils.leftPad(i + "", 6, "0"), "hbtgIA0SuVw9lxjB");
|
||||||
|
DEVICES.put("TEST_SW_" + StringUtils.leftPad(i + "", 6, "0"), "Rf4QSjbm65X45753");
|
||||||
|
DEVICES.put("TEST_SC_" + StringUtils.leftPad(i + "", 6, "0"), "cGCrkK7Ex4FESAwe");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult post(String pluginId, IDeviceAction action) {
|
||||||
|
log.info("post action:{}", action);
|
||||||
|
return ActionResult.builder().code(0).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ThingProduct getProduct(String pk) {
|
||||||
|
return ThingProduct.builder()
|
||||||
|
.productKey(pk)
|
||||||
|
.productSecret(PRODUCTS.get(pk))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ThingDevice getDevice(String dn) {
|
||||||
|
return ThingDevice.builder()
|
||||||
|
.productKey(DEVICES.get(dn))
|
||||||
|
.deviceName(dn)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, ?> getProperty(String dn) {
|
||||||
|
return new HashMap<>(0);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,186 @@
|
|||||||
|
package cc.iotkit.plugins.emqx.service;
|
||||||
|
|
||||||
|
import cc.iotkit.common.enums.ErrCode;
|
||||||
|
import cc.iotkit.common.exception.BizException;
|
||||||
|
import cc.iotkit.common.utils.JsonUtils;
|
||||||
|
import cc.iotkit.plugin.core.thing.IDevice;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.ActionResult;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.down.DeviceConfig;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.down.PropertyGet;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.down.PropertySet;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.down.ServiceInvoke;
|
||||||
|
import cc.iotkit.plugins.emqx.conf.IoTConfigProtocol;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import io.netty.handler.codec.mqtt.MqttQoS;
|
||||||
|
import io.vertx.core.json.JsonObject;
|
||||||
|
import io.vertx.mqtt.MqttClient;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static cc.iotkit.plugins.emqx.conf.BCDClockGenerator.formatBCDToHex;
|
||||||
|
import static cc.iotkit.plugins.emqx.conf.BCDClockGenerator.generateBCDTime;
|
||||||
|
import static cc.iotkit.plugins.emqx.conf.CRC16ModbusUtil.buildFrame;
|
||||||
|
import static cc.iotkit.plugins.emqx.conf.IoTConfigProtocol.*;
|
||||||
|
|
||||||
|
import static cn.hutool.core.util.NumberUtil.parseNumber;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mqtt设备下行接口
|
||||||
|
*
|
||||||
|
* @author sjg
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class MqttDevice implements IDevice {
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
private MqttClient client;
|
||||||
|
public List<Map> processConfig(Map<String, Object> config) {
|
||||||
|
if (config == null || config.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Config map cannot be null or empty");
|
||||||
|
}
|
||||||
|
List<Map> list = new ArrayList<>();
|
||||||
|
for (Map.Entry<String, Object> entry : config.entrySet()) {
|
||||||
|
Map map = new HashMap();
|
||||||
|
String key = entry.getKey();
|
||||||
|
String value = entry.getValue().toString();
|
||||||
|
Integer configId = null;
|
||||||
|
try {
|
||||||
|
byte[] tlvData = null;
|
||||||
|
// int configId = getConfigId(key);
|
||||||
|
|
||||||
|
/* if (configId == -1) {
|
||||||
|
System.err.println("Unknown config key: " + key);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
switch(key.toLowerCase()) {
|
||||||
|
case "ip/realm":
|
||||||
|
configId = IP_REALM;
|
||||||
|
tlvData = buildTLVData(value.getBytes());
|
||||||
|
break;
|
||||||
|
case "port":
|
||||||
|
case "keepalive":
|
||||||
|
case "reportrateupper":
|
||||||
|
|
||||||
|
configId = (key.toLowerCase().equals("port") ? PORT : key.toLowerCase().equals("keepalive") ?KEEP_ALIVE :REPORT_RATE_UPPER);
|
||||||
|
tlvData= ByteBuffer.allocate(2).putShort( Short.parseShort(value)).array();
|
||||||
|
// tlvData = buildShortData(parseNumber(value));
|
||||||
|
break;
|
||||||
|
case "reportawaittime":
|
||||||
|
case "reportretrytimes":
|
||||||
|
configId = (key.toLowerCase().equals("reportawaittime") ? REPORT_AWAIT_TIME :REPORT_RETRY_TIMES);
|
||||||
|
tlvData = buildByteData(Integer.valueOf(value));
|
||||||
|
break;
|
||||||
|
// case "username":
|
||||||
|
// case "password":
|
||||||
|
// tlvData = buildStringData(value.toString(), MAX_AUTH_LENGTH);
|
||||||
|
// break;
|
||||||
|
case "publishtopicprefix":
|
||||||
|
case "subscribetopicprefix":
|
||||||
|
configId = (key.toLowerCase().equals("publishtopicprefix") ? PUBLISH_TOPIC :SUBSCRIBE_TOPIC);
|
||||||
|
tlvData = buildStringData(value.toString(), 30);
|
||||||
|
break;
|
||||||
|
case "timesyncinternal":
|
||||||
|
configId = TIME_SYNC;
|
||||||
|
tlvData = buildBcdTimeData(value);
|
||||||
|
break;
|
||||||
|
case "card":
|
||||||
|
case "signal":
|
||||||
|
case "version":
|
||||||
|
System.out.println(key + " is read-only, skip writing");
|
||||||
|
continue;
|
||||||
|
default:
|
||||||
|
System.out.println("Unsupported config: " + key);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(ObjectUtil.isNotNull(configId)) {
|
||||||
|
String command = IoTConfigProtocol.generateWriteCommand(
|
||||||
|
0x01, configId, tlvData);
|
||||||
|
map.put("date",command);
|
||||||
|
System.out.printf("Generated command for %s (ID:0x%04X): %s%n",
|
||||||
|
key, configId, command);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.printf("Error processing %s: %s%n", key, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public ActionResult config(DeviceConfig action) {
|
||||||
|
String topic = String.format("/sys/%s/%s/c/config/set", action.getProductKey(), action.getDeviceName());
|
||||||
|
// Map data = JsonUtils.parseObject(action.getConfig(), Map.class);
|
||||||
|
List<Map> list= processConfig(action.getConfig());
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
//循环发送配置指令
|
||||||
|
String replyMessage = buildFrame("01","01",
|
||||||
|
"01","01","01"+ list.get(i).get("data"));
|
||||||
|
send(
|
||||||
|
topic,
|
||||||
|
new JsonObject()
|
||||||
|
.put("id", action.getId())
|
||||||
|
.put("method", "thing.config.set")
|
||||||
|
.put("params", action.getConfig())
|
||||||
|
.put("data", replyMessage)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ActionResult.builder().code(0).reason("").build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult propertyGet(PropertyGet action) {
|
||||||
|
String topic = String.format("/sys/%s/%s/c/service/property/get", action.getProductKey(), action.getDeviceName());
|
||||||
|
return send(
|
||||||
|
topic,
|
||||||
|
new JsonObject()
|
||||||
|
.put("id", action.getId())
|
||||||
|
.put("method", "thing.service.property.get")
|
||||||
|
.put("params", action.getKeys())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult propertySet(PropertySet action) {
|
||||||
|
String topic = String.format("/sys/%s/%s/c/service/property/set", action.getProductKey(), action.getDeviceName());
|
||||||
|
return send(
|
||||||
|
topic,
|
||||||
|
new JsonObject()
|
||||||
|
.put("id", action.getId())
|
||||||
|
.put("method", "thing.service.property.set")
|
||||||
|
.put("params", action.getParams())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult serviceInvoke(ServiceInvoke action) {
|
||||||
|
String topic = String.format("/sys/%s/%s/c/service/%s", action.getProductKey(), action.getDeviceName(), action.getName());
|
||||||
|
return send(
|
||||||
|
topic,
|
||||||
|
new JsonObject()
|
||||||
|
.put("id", action.getId())
|
||||||
|
.put("method", "thing.service." + action.getName())
|
||||||
|
.put("params", action.getParams())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ActionResult send(String topic, JsonObject payload) {
|
||||||
|
try {
|
||||||
|
client.publish(topic, payload.toBuffer(), MqttQoS.AT_LEAST_ONCE, false, false);
|
||||||
|
return ActionResult.builder().code(0).reason("").build();
|
||||||
|
} catch (BizException e) {
|
||||||
|
return ActionResult.builder().code(e.getCode()).reason(e.getMessage()).build();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return ActionResult.builder().code(ErrCode.UNKNOWN_EXCEPTION.getKey()).reason(e.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
plugin:
|
||||||
|
runMode: dev
|
||||||
|
mainPackage: cc.iotkit.plugin
|
||||||
|
|
||||||
|
emqx:
|
||||||
|
host: 127.0.0.1
|
||||||
|
port: 1883
|
||||||
|
topics: /sys/#
|
||||||
|
authPort: 8104
|
@ -0,0 +1,19 @@
|
|||||||
|
package cc.iotkit.plugins.http;
|
||||||
|
|
||||||
|
import com.gitee.starblues.bootstrap.SpringPluginBootstrap;
|
||||||
|
import com.gitee.starblues.bootstrap.annotation.OneselfConfig;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sjg
|
||||||
|
*/
|
||||||
|
@SpringBootApplication(scanBasePackages = "cc.iotkit.plugins.http")
|
||||||
|
@OneselfConfig(mainConfigFileName = {"application.yml"})
|
||||||
|
@EnableConfigurationProperties
|
||||||
|
public class Application extends SpringPluginBootstrap {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new Application().run(Application.class, args);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package cc.iotkit.plugins.http.conf;
|
||||||
|
|
||||||
|
import cc.iotkit.plugin.core.IPluginConfig;
|
||||||
|
import cc.iotkit.plugin.core.LocalPluginConfig;
|
||||||
|
import cc.iotkit.plugin.core.thing.IThingService;
|
||||||
|
import cc.iotkit.plugins.http.service.FakeThingService;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sjg
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class BeanConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnProperty(name = "plugin.runMode", havingValue = "dev")
|
||||||
|
IThingService getThingService() {
|
||||||
|
return new FakeThingService();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnProperty(name = "plugin.runMode", havingValue = "dev")
|
||||||
|
IPluginConfig getPluginConfig(){
|
||||||
|
return new LocalPluginConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* +----------------------------------------------------------------------
|
||||||
|
* | Copyright (c) 奇特物联 2021-2022 All rights reserved.
|
||||||
|
* +----------------------------------------------------------------------
|
||||||
|
* | Licensed 未经许可不能去掉「奇特物联」相关版权
|
||||||
|
* +----------------------------------------------------------------------
|
||||||
|
* | Author: xw2sy@163.com
|
||||||
|
* +----------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
package cc.iotkit.plugins.http.conf;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* http配置
|
||||||
|
*
|
||||||
|
* @author sjg
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Component
|
||||||
|
@ConfigurationProperties(prefix = "http")
|
||||||
|
public class HttpConfig {
|
||||||
|
|
||||||
|
private int port;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package cc.iotkit.plugins.http.service;
|
||||||
|
|
||||||
|
import cc.iotkit.plugin.core.thing.IThingService;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.ActionResult;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.IDeviceAction;
|
||||||
|
import cc.iotkit.plugin.core.thing.model.ThingDevice;
|
||||||
|
import cc.iotkit.plugin.core.thing.model.ThingProduct;
|
||||||
|
import io.vertx.core.json.JsonObject;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试服务
|
||||||
|
*
|
||||||
|
* @author sjg
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class FakeThingService implements IThingService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult post(String pluginId, IDeviceAction action) {
|
||||||
|
log.info("post action:{}", action);
|
||||||
|
return ActionResult.builder().code(0).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ThingProduct getProduct(String pk) {
|
||||||
|
return ThingProduct.builder()
|
||||||
|
.productKey("cGCrkK7Ex4FESAwe")
|
||||||
|
.productSecret("xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ThingDevice getDevice(String dn) {
|
||||||
|
return ThingDevice.builder()
|
||||||
|
.productKey("cGCrkK7Ex4FESAwe")
|
||||||
|
.deviceName(dn)
|
||||||
|
.secret("mBCr3TKstTj2KeM6")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, ?> getProperty(String dn) {
|
||||||
|
return new JsonObject().put("powerstate", 1).getMap();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package cc.iotkit.plugins.http.service;
|
||||||
|
|
||||||
|
import cc.iotkit.plugin.core.thing.IDevice;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.ActionResult;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.down.DeviceConfig;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.down.PropertyGet;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.down.PropertySet;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.down.ServiceInvoke;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* http设备下行接口
|
||||||
|
*
|
||||||
|
* @author sjg
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class HttpDevice implements IDevice {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private HttpVerticle httpVerticle;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult config(DeviceConfig action) {
|
||||||
|
return ActionResult.builder().code(0).reason("").build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult propertyGet(PropertyGet action) {
|
||||||
|
throw new UnsupportedOperationException("不支持该功能");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult propertySet(PropertySet action) {
|
||||||
|
throw new UnsupportedOperationException("不支持该功能");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult serviceInvoke(ServiceInvoke action) {
|
||||||
|
throw new UnsupportedOperationException("不支持该功能");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,91 @@
|
|||||||
|
package cc.iotkit.plugins.http.service;
|
||||||
|
|
||||||
|
import cc.iotkit.common.utils.JsonUtils;
|
||||||
|
import cc.iotkit.plugin.core.IPluginConfig;
|
||||||
|
import cc.iotkit.plugins.http.conf.HttpConfig;
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.bean.copier.CopyOptions;
|
||||||
|
import com.gitee.starblues.bootstrap.annotation.AutowiredType;
|
||||||
|
import com.gitee.starblues.bootstrap.realize.PluginCloseListener;
|
||||||
|
import com.gitee.starblues.core.PluginCloseType;
|
||||||
|
import com.gitee.starblues.core.PluginInfo;
|
||||||
|
import io.vertx.core.Future;
|
||||||
|
import io.vertx.core.Vertx;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.support.GenericApplicationContext;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sjg
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class HttpPlugin implements PluginCloseListener {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PluginInfo pluginInfo;
|
||||||
|
@Autowired
|
||||||
|
private HttpVerticle httpVerticle;
|
||||||
|
@Autowired
|
||||||
|
private HttpConfig httpConfig;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@AutowiredType(AutowiredType.Type.MAIN_PLUGIN)
|
||||||
|
private IPluginConfig pluginConfig;
|
||||||
|
|
||||||
|
private Vertx vertx;
|
||||||
|
private String deployedId;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
vertx = Vertx.vertx();
|
||||||
|
try {
|
||||||
|
//获取插件最新配置替换当前配置
|
||||||
|
Map<String, Object> config = pluginConfig.getConfig(pluginInfo.getPluginId());
|
||||||
|
log.info("get config:{}", JsonUtils.toJsonString(config));
|
||||||
|
BeanUtil.copyProperties(config, httpConfig, CopyOptions.create().ignoreNullValue());
|
||||||
|
httpVerticle.setConfig(httpConfig);
|
||||||
|
|
||||||
|
Future<String> future = vertx.deployVerticle(httpVerticle);
|
||||||
|
future.onSuccess((s -> {
|
||||||
|
deployedId = s;
|
||||||
|
log.info("http plugin startup success");
|
||||||
|
}));
|
||||||
|
future.onFailure((e) -> {
|
||||||
|
log.error("http plugin startup failed", e);
|
||||||
|
});
|
||||||
|
} catch (Throwable e) {
|
||||||
|
log.error("http plugin startup error", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close(GenericApplicationContext applicationContext, PluginInfo pluginInfo, PluginCloseType closeType) {
|
||||||
|
try {
|
||||||
|
log.info("plugin close,type:{},pluginId:{}", closeType, pluginInfo.getPluginId());
|
||||||
|
if (deployedId != null) {
|
||||||
|
CountDownLatch wait = new CountDownLatch(1);
|
||||||
|
Future<Void> future = vertx.undeploy(deployedId);
|
||||||
|
future.onSuccess(unused -> {
|
||||||
|
log.info("http plugin stopped success");
|
||||||
|
wait.countDown();
|
||||||
|
});
|
||||||
|
future.onFailure(h -> {
|
||||||
|
log.info("tcp plugin stopped failed");
|
||||||
|
h.printStackTrace();
|
||||||
|
wait.countDown();
|
||||||
|
});
|
||||||
|
wait.await(5, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
log.error("http plugin stop error", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
plugin:
|
||||||
|
runMode: prod
|
||||||
|
mainPackage: cc.iotkit.plugin
|
||||||
|
|
||||||
|
http:
|
||||||
|
port: 9081
|
@ -0,0 +1,36 @@
|
|||||||
|
package cc.iotkit.test.http;
|
||||||
|
|
||||||
|
import cc.iotkit.common.utils.ThreadUtil;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.RandomUtil;
|
||||||
|
import cn.hutool.http.HttpResponse;
|
||||||
|
import cn.hutool.http.HttpUtil;
|
||||||
|
import io.vertx.core.json.JsonObject;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class HttpTest {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
ScheduledThreadPoolExecutor timer = ThreadUtil.newScheduled(1, "http-test");
|
||||||
|
timer.scheduleWithFixedDelay(HttpTest::report, 0, 3, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void report() {
|
||||||
|
HttpResponse rst = HttpUtil.createPost("http://127.0.0.1:9084/sys/cGCrkK7Ex4FESAwe/cz00001/properties")
|
||||||
|
.header("secret", "mBCr3TKstTj2KeM6")
|
||||||
|
.body(new JsonObject()
|
||||||
|
.put("id", IdUtil.fastSimpleUUID())
|
||||||
|
.put("params", new JsonObject()
|
||||||
|
.put("powerstate", RandomUtil.randomInt(0, 2))
|
||||||
|
.put("rssi", RandomUtil.randomInt(-127, 127))
|
||||||
|
.getMap()
|
||||||
|
).encode()
|
||||||
|
).execute();
|
||||||
|
log.info("send result:status={},body={}", rst.getStatus(), rst.body());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>iot-iita-plugins</artifactId>
|
||||||
|
<groupId>cc.iotkit.plugins</groupId>
|
||||||
|
<version>2.0.19</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>hydrovalve-plugin</artifactId>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>dev</id>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>true</activeByDefault>
|
||||||
|
</activation>
|
||||||
|
<properties>
|
||||||
|
<plugin.build.mode>dev</plugin.build.mode>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
|
||||||
|
<profile>
|
||||||
|
<id>prod</id>
|
||||||
|
<properties>
|
||||||
|
<plugin.build.mode>prod</plugin.build.mode>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.gitee.starblues</groupId>
|
||||||
|
<artifactId>spring-brick-maven-packager</artifactId>
|
||||||
|
<version>${spring-brick.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<mode>${plugin.build.mode}</mode>
|
||||||
|
<pluginInfo>
|
||||||
|
<id>hydrovalve-plugin</id>
|
||||||
|
<bootstrapClass>cc.iotkit.plugins.hydrovalve.Application</bootstrapClass>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<provider>iita</provider>
|
||||||
|
<description>modbus插件</description>
|
||||||
|
<configFileName>application.yml</configFileName>
|
||||||
|
</pluginInfo>
|
||||||
|
<prodConfig>
|
||||||
|
<packageType>jar</packageType>
|
||||||
|
</prodConfig>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,8 @@
|
|||||||
|
plugin:
|
||||||
|
runMode: prod
|
||||||
|
mainPackage: cc.iotkit.plugin
|
||||||
|
|
||||||
|
hydrovalve:
|
||||||
|
host: xxxx
|
||||||
|
port: 38807
|
||||||
|
interval: 20000
|
@ -0,0 +1,23 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "host",
|
||||||
|
"name": "服务端ip",
|
||||||
|
"type": "text",
|
||||||
|
"value": "25on621889.goho.co",
|
||||||
|
"desc": "服务端ip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "port",
|
||||||
|
"name": "服务端端口",
|
||||||
|
"type": "number",
|
||||||
|
"value": 38807,
|
||||||
|
"desc": "服务端端口"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "interval",
|
||||||
|
"name": "采集频率",
|
||||||
|
"type": "number",
|
||||||
|
"value": 20000,
|
||||||
|
"desc": "采集频率"
|
||||||
|
}
|
||||||
|
]
|
@ -0,0 +1,74 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>iot-iita-plugins</artifactId>
|
||||||
|
<groupId>cc.iotkit.plugins</groupId>
|
||||||
|
<version>2.0.19</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>modbus-plugin</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.digitalpetri.modbus</groupId>
|
||||||
|
<artifactId>modbus-master-tcp</artifactId>
|
||||||
|
<version>1.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>dev</id>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>true</activeByDefault>
|
||||||
|
</activation>
|
||||||
|
<properties>
|
||||||
|
<plugin.build.mode>dev</plugin.build.mode>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
|
||||||
|
<profile>
|
||||||
|
<id>prod</id>
|
||||||
|
<properties>
|
||||||
|
<plugin.build.mode>prod</plugin.build.mode>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.gitee.starblues</groupId>
|
||||||
|
<artifactId>spring-brick-maven-packager</artifactId>
|
||||||
|
<version>${spring-brick.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<mode>${plugin.build.mode}</mode>
|
||||||
|
<pluginInfo>
|
||||||
|
<id>modbus-plugin</id>
|
||||||
|
<bootstrapClass>cc.iotkit.plugins.modbus.Application</bootstrapClass>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<provider>iita</provider>
|
||||||
|
<description>modbus示例插件</description>
|
||||||
|
<configFileName>application.yml</configFileName>
|
||||||
|
</pluginInfo>
|
||||||
|
<prodConfig>
|
||||||
|
<packageType>jar</packageType>
|
||||||
|
</prodConfig>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,21 @@
|
|||||||
|
package cc.iotkit.plugins.modbus;
|
||||||
|
|
||||||
|
import com.gitee.starblues.bootstrap.SpringPluginBootstrap;
|
||||||
|
import com.gitee.starblues.bootstrap.annotation.OneselfConfig;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sjg
|
||||||
|
*/
|
||||||
|
@SpringBootApplication(scanBasePackages = "cc.iotkit.plugins.modbus")
|
||||||
|
@OneselfConfig(mainConfigFileName = {"application.yml"})
|
||||||
|
@EnableConfigurationProperties
|
||||||
|
@EnableScheduling
|
||||||
|
public class Application extends SpringPluginBootstrap {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new Application().run(Application.class, args);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package cc.iotkit.plugins.modbus.conf;
|
||||||
|
|
||||||
|
import cc.iotkit.plugin.core.IPluginConfig;
|
||||||
|
import cc.iotkit.plugin.core.IPluginScript;
|
||||||
|
import cc.iotkit.plugin.core.LocalPluginConfig;
|
||||||
|
import cc.iotkit.plugin.core.LocalPluginScript;
|
||||||
|
import cc.iotkit.plugin.core.thing.IThingService;
|
||||||
|
import cc.iotkit.plugins.modbus.service.FakeThingService;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sjg
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class BeanConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnProperty(name = "plugin.runMode", havingValue = "dev")
|
||||||
|
IThingService getThingService() {
|
||||||
|
return new FakeThingService();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnProperty(name = "plugin.runMode", havingValue = "dev")
|
||||||
|
IPluginScript getPluginScript() {
|
||||||
|
return new LocalPluginScript("script.js");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnProperty(name = "plugin.runMode", havingValue = "dev")
|
||||||
|
IPluginConfig getPluginConfig(){
|
||||||
|
return new LocalPluginConfig();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package cc.iotkit.plugins.modbus.service;
|
||||||
|
|
||||||
|
import cc.iotkit.plugin.core.thing.IThingService;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.ActionResult;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.IDeviceAction;
|
||||||
|
import cc.iotkit.plugin.core.thing.model.ThingDevice;
|
||||||
|
import cc.iotkit.plugin.core.thing.model.ThingProduct;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试服务
|
||||||
|
*
|
||||||
|
* @author sjg
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class FakeThingService implements IThingService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult post(String pluginId, IDeviceAction action) {
|
||||||
|
log.info("post action:{}", action);
|
||||||
|
return ActionResult.builder().code(0).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ThingProduct getProduct(String pk) {
|
||||||
|
return ThingProduct.builder()
|
||||||
|
.productKey("cGCrkK7Ex4FESAwe")
|
||||||
|
.productSecret("aaaaaaaa")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ThingDevice getDevice(String dn) {
|
||||||
|
return ThingDevice.builder()
|
||||||
|
.productKey("cGCrkK7Ex4FESAwe")
|
||||||
|
.deviceName(dn)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, ?> getProperty(String dn) {
|
||||||
|
return new HashMap<>(0);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,132 @@
|
|||||||
|
package cc.iotkit.plugins.modbus.service;
|
||||||
|
|
||||||
|
import cc.iotkit.plugin.core.IPluginScript;
|
||||||
|
import cc.iotkit.plugin.core.thing.IThingService;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.DeviceState;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.up.DeviceRegister;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.up.DeviceStateChange;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.up.PropertyReport;
|
||||||
|
import cc.iotkit.script.IScriptEngine;
|
||||||
|
import com.digitalpetri.modbus.master.ModbusTcpMaster;
|
||||||
|
import com.digitalpetri.modbus.master.ModbusTcpMasterConfig;
|
||||||
|
import com.digitalpetri.modbus.requests.ReadHoldingRegistersRequest;
|
||||||
|
import com.digitalpetri.modbus.responses.ReadHoldingRegistersResponse;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.gitee.starblues.bootstrap.annotation.AutowiredType;
|
||||||
|
import com.gitee.starblues.bootstrap.realize.PluginCloseListener;
|
||||||
|
import com.gitee.starblues.core.PluginCloseType;
|
||||||
|
import com.gitee.starblues.core.PluginInfo;
|
||||||
|
import io.netty.buffer.ByteBufUtil;
|
||||||
|
import io.netty.util.ReferenceCountUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.support.GenericApplicationContext;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sjg
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class ModbusPlugin implements PluginCloseListener {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PluginInfo pluginInfo;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@AutowiredType(AutowiredType.Type.MAIN_PLUGIN)
|
||||||
|
private IPluginScript pluginScript;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@AutowiredType(AutowiredType.Type.MAIN_PLUGIN)
|
||||||
|
private IThingService thingService;
|
||||||
|
|
||||||
|
private IScriptEngine scriptEngine;
|
||||||
|
|
||||||
|
private final ModbusTcpMasterConfig config = new ModbusTcpMasterConfig.Builder("localhost").setPort(502).build();
|
||||||
|
private ModbusTcpMaster master;
|
||||||
|
|
||||||
|
private final Set<Integer> registeredDevice = new HashSet<>();
|
||||||
|
|
||||||
|
private final int[] slaves = new int[]{1, 2, 3};
|
||||||
|
|
||||||
|
private final Map<Integer, String> DATA_CACHE = new HashMap<>();
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
master = new ModbusTcpMaster(config);
|
||||||
|
CompletableFuture<ModbusTcpMaster> connect = master.connect();
|
||||||
|
connect.thenAccept(modbusTcpMaster -> System.out.println("111:" + modbusTcpMaster.getConfig()));
|
||||||
|
|
||||||
|
//获取脚本引擎
|
||||||
|
scriptEngine = pluginScript.getScriptEngine(pluginInfo.getPluginId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Scheduled(initialDelay = 3000, fixedDelay = 1000)
|
||||||
|
public void taskRead() {
|
||||||
|
for (int slave : slaves) {
|
||||||
|
CompletableFuture<ReadHoldingRegistersResponse> future =
|
||||||
|
master.sendRequest(new ReadHoldingRegistersRequest(0, 10), slave);
|
||||||
|
|
||||||
|
future.thenAccept(response -> {
|
||||||
|
String rspBytes = ByteBufUtil.hexDump(response.getRegisters());
|
||||||
|
ReferenceCountUtil.release(response);
|
||||||
|
|
||||||
|
log.info("receive Response: " + rspBytes);
|
||||||
|
//相同数据不处理
|
||||||
|
if (DATA_CACHE.getOrDefault(slave, "").equals(rspBytes)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DATA_CACHE.put(slave, rspBytes);
|
||||||
|
|
||||||
|
if (!registeredDevice.contains(slave)) {
|
||||||
|
//第一次读取自动注册设备
|
||||||
|
thingService.post(pluginInfo.getPluginId(), DeviceRegister.builder()
|
||||||
|
.id(UUID.randomUUID().toString())
|
||||||
|
.productKey("cGCrkK7Ex4FESAwe")
|
||||||
|
.deviceName(String.format("modbus_%d", slave))
|
||||||
|
.build());
|
||||||
|
registeredDevice.add(slave);
|
||||||
|
//并上线
|
||||||
|
thingService.post(pluginInfo.getPluginId(), DeviceStateChange.builder()
|
||||||
|
.id(UUID.randomUUID().toString())
|
||||||
|
.productKey("cGCrkK7Ex4FESAwe")
|
||||||
|
.deviceName(String.format("modbus_%d", slave))
|
||||||
|
.state(DeviceState.ONLINE)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
//调用脚本解码
|
||||||
|
Map<String, Object> rst = scriptEngine.invokeMethod(new TypeReference<>() {
|
||||||
|
}, "decode", rspBytes);
|
||||||
|
if (rst == null || rst.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//属性上报
|
||||||
|
thingService.post(pluginInfo.getPluginId(), PropertyReport.builder()
|
||||||
|
.id(UUID.randomUUID().toString())
|
||||||
|
.productKey("cGCrkK7Ex4FESAwe")
|
||||||
|
.deviceName(String.format("modbus_%d", slave))
|
||||||
|
.params(rst)
|
||||||
|
.build());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close(GenericApplicationContext applicationContext, PluginInfo pluginInfo, PluginCloseType closeType) {
|
||||||
|
try {
|
||||||
|
log.info("plugin close,type:{},pluginId:{}", closeType, pluginInfo.getPluginId());
|
||||||
|
master.disconnect();
|
||||||
|
} catch (Throwable e) {
|
||||||
|
log.error("modbus plugin stop error", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
plugin:
|
||||||
|
runMode: prod
|
||||||
|
mainPackage: cc.iotkit.plugin
|
||||||
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
|||||||
|
function hexToByte(hexString) {
|
||||||
|
if (hexString.length % 2 !== 0) {
|
||||||
|
throw new Error('Invalid hex string. String must have an even number of characters.');
|
||||||
|
}
|
||||||
|
|
||||||
|
let byteArray = [];
|
||||||
|
for (let i = 0; i < hexString.length; i += 4) {
|
||||||
|
byteArray.push(parseInt(hexString.substr(i, 4), 16));
|
||||||
|
}
|
||||||
|
|
||||||
|
return byteArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.decode=function(hex){
|
||||||
|
try{
|
||||||
|
const bytes=hexToByte(hex);
|
||||||
|
return {
|
||||||
|
"rssi":bytes[0],
|
||||||
|
"powerstate":bytes[1]
|
||||||
|
};
|
||||||
|
}catch(e){
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,85 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>iot-iita-plugins</artifactId>
|
||||||
|
<groupId>cc.iotkit.plugins</groupId>
|
||||||
|
<version>2.10.19</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>mqtt-plugin</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.vertx</groupId>
|
||||||
|
<artifactId>vertx-core</artifactId>
|
||||||
|
<version>${vertx.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.vertx</groupId>
|
||||||
|
<artifactId>vertx-mqtt</artifactId>
|
||||||
|
<version>${vertx.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-codec-mqtt</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>dev</id>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>true</activeByDefault>
|
||||||
|
</activation>
|
||||||
|
<properties>
|
||||||
|
<plugin.build.mode>dev</plugin.build.mode>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
|
||||||
|
<profile>
|
||||||
|
<id>prod</id>
|
||||||
|
<properties>
|
||||||
|
<plugin.build.mode>prod</plugin.build.mode>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.gitee.starblues</groupId>
|
||||||
|
<artifactId>spring-brick-maven-packager</artifactId>
|
||||||
|
<version>${spring-brick.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<mode>${plugin.build.mode}</mode>
|
||||||
|
<pluginInfo>
|
||||||
|
<id>mqtt-plugin</id>
|
||||||
|
<bootstrapClass>cc.iotkit.plugins.mqtt.Application</bootstrapClass>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<provider>iita</provider>
|
||||||
|
<description>mqtt示例插件</description>
|
||||||
|
<configFileName>application.yml</configFileName>
|
||||||
|
</pluginInfo>
|
||||||
|
<prodConfig>
|
||||||
|
<packageType>jar</packageType>
|
||||||
|
</prodConfig>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,19 @@
|
|||||||
|
package cc.iotkit.plugins.mqtt;
|
||||||
|
|
||||||
|
import com.gitee.starblues.bootstrap.SpringPluginBootstrap;
|
||||||
|
import com.gitee.starblues.bootstrap.annotation.OneselfConfig;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sjg
|
||||||
|
*/
|
||||||
|
@SpringBootApplication(scanBasePackages = "cc.iotkit.plugins.mqtt")
|
||||||
|
@OneselfConfig(mainConfigFileName = {"application.yml"})
|
||||||
|
@EnableConfigurationProperties
|
||||||
|
public class Application extends SpringPluginBootstrap {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new Application().run(Application.class, args);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package cc.iotkit.plugins.mqtt.conf;
|
||||||
|
|
||||||
|
import cc.iotkit.plugin.core.IPluginConfig;
|
||||||
|
import cc.iotkit.plugin.core.LocalPluginConfig;
|
||||||
|
import cc.iotkit.plugin.core.thing.IThingService;
|
||||||
|
import cc.iotkit.plugins.mqtt.service.FakeThingService;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sjg
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class BeanConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnProperty(name = "plugin.runMode", havingValue = "dev")
|
||||||
|
IThingService getThingService() {
|
||||||
|
return new FakeThingService();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnProperty(name = "plugin.runMode", havingValue = "dev")
|
||||||
|
IPluginConfig getPluginConfig(){
|
||||||
|
return new LocalPluginConfig();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* +----------------------------------------------------------------------
|
||||||
|
* | Copyright (c) 奇特物联 2021-2022 All rights reserved.
|
||||||
|
* +----------------------------------------------------------------------
|
||||||
|
* | Licensed 未经许可不能去掉「奇特物联」相关版权
|
||||||
|
* +----------------------------------------------------------------------
|
||||||
|
* | Author: xw2sy@163.com
|
||||||
|
* +----------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
package cc.iotkit.plugins.mqtt.conf;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Component
|
||||||
|
@ConfigurationProperties(prefix = "mqtt")
|
||||||
|
public class MqttConfig {
|
||||||
|
|
||||||
|
private int port;
|
||||||
|
|
||||||
|
private String sslKey;
|
||||||
|
|
||||||
|
private String sslCert;
|
||||||
|
|
||||||
|
private boolean ssl;
|
||||||
|
|
||||||
|
private boolean useWebSocket;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
package cc.iotkit.plugins.mqtt.service;
|
||||||
|
|
||||||
|
import cc.iotkit.plugin.core.thing.IThingService;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.ActionResult;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.IDeviceAction;
|
||||||
|
import cc.iotkit.plugin.core.thing.model.ThingDevice;
|
||||||
|
import cc.iotkit.plugin.core.thing.model.ThingProduct;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试服务
|
||||||
|
*
|
||||||
|
* @author sjg
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class FakeThingService implements IThingService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加测试产品
|
||||||
|
*/
|
||||||
|
private static final Map<String, String> PRODUCTS = Map.of(
|
||||||
|
"hbtgIA0SuVw9lxjB", "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
|
||||||
|
"Rf4QSjbm65X45753", "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU",
|
||||||
|
"cGCrkK7Ex4FESAwe", "xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU"
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加测试设备
|
||||||
|
*/
|
||||||
|
private static final Map<String, String> DEVICES = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
DEVICES.put("TEST:GW:" + StringUtils.leftPad(i + "", 6, "0"), "hbtgIA0SuVw9lxjB");
|
||||||
|
DEVICES.put("TEST_SW_" + StringUtils.leftPad(i + "", 6, "0"), "Rf4QSjbm65X45753");
|
||||||
|
DEVICES.put("TEST_SC_" + StringUtils.leftPad(i + "", 6, "0"), "cGCrkK7Ex4FESAwe");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult post(String pluginId, IDeviceAction action) {
|
||||||
|
log.info("post action:{}", action);
|
||||||
|
return ActionResult.builder().code(0).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ThingProduct getProduct(String pk) {
|
||||||
|
return ThingProduct.builder()
|
||||||
|
.productKey(pk)
|
||||||
|
.productSecret(PRODUCTS.get(pk))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ThingDevice getDevice(String dn) {
|
||||||
|
return ThingDevice.builder()
|
||||||
|
.productKey(DEVICES.get(dn))
|
||||||
|
.deviceName(dn)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, ?> getProperty(String dn) {
|
||||||
|
return new HashMap<>(0);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,88 @@
|
|||||||
|
package cc.iotkit.plugins.mqtt.service;
|
||||||
|
|
||||||
|
import cc.iotkit.common.enums.ErrCode;
|
||||||
|
import cc.iotkit.common.exception.BizException;
|
||||||
|
import cc.iotkit.plugin.core.thing.IDevice;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.ActionResult;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.down.DeviceConfig;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.down.PropertyGet;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.down.PropertySet;
|
||||||
|
import cc.iotkit.plugin.core.thing.actions.down.ServiceInvoke;
|
||||||
|
import io.vertx.core.json.JsonObject;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mqtt设备下行接口
|
||||||
|
*
|
||||||
|
* @author sjg
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class MqttDevice implements IDevice {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MqttVerticle mqttVerticle;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult config(DeviceConfig action) {
|
||||||
|
return ActionResult.builder().code(0).reason("").build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult propertyGet(PropertyGet action) {
|
||||||
|
String topic = String.format("/sys/%s/%s/c/service/property/get", action.getProductKey(), action.getDeviceName());
|
||||||
|
return send(
|
||||||
|
topic,
|
||||||
|
action.getDeviceName(),
|
||||||
|
new JsonObject()
|
||||||
|
.put("id", action.getId())
|
||||||
|
.put("method", "thing.service.property.get")
|
||||||
|
.put("params", action.getKeys())
|
||||||
|
.toString()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult propertySet(PropertySet action) {
|
||||||
|
String topic = String.format("/sys/%s/%s/c/service/property/set", action.getProductKey(), action.getDeviceName());
|
||||||
|
return send(
|
||||||
|
topic,
|
||||||
|
action.getDeviceName(),
|
||||||
|
new JsonObject()
|
||||||
|
.put("id", action.getId())
|
||||||
|
.put("method", "thing.service.property.set")
|
||||||
|
.put("params", action.getParams())
|
||||||
|
.toString()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult serviceInvoke(ServiceInvoke action) {
|
||||||
|
String topic = String.format("/sys/%s/%s/c/service/%s", action.getProductKey(), action.getDeviceName(), action.getName());
|
||||||
|
return send(
|
||||||
|
topic,
|
||||||
|
action.getDeviceName(),
|
||||||
|
new JsonObject()
|
||||||
|
.put("id", action.getId())
|
||||||
|
.put("method", "thing.service." + action.getName())
|
||||||
|
.put("params", action.getParams())
|
||||||
|
.toString()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ActionResult send(String topic, String deviceName, String payload) {
|
||||||
|
try {
|
||||||
|
mqttVerticle.publish(
|
||||||
|
deviceName,
|
||||||
|
topic,
|
||||||
|
payload
|
||||||
|
);
|
||||||
|
return ActionResult.builder().code(0).reason("").build();
|
||||||
|
} catch (BizException e) {
|
||||||
|
return ActionResult.builder().code(e.getCode()).reason(e.getMessage()).build();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return ActionResult.builder().code(ErrCode.UNKNOWN_EXCEPTION.getKey()).reason(e.getMessage()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,94 @@
|
|||||||
|
package cc.iotkit.plugins.mqtt.service;
|
||||||
|
|
||||||
|
import cc.iotkit.plugin.core.IPlugin;
|
||||||
|
import cc.iotkit.plugin.core.IPluginConfig;
|
||||||
|
import cc.iotkit.plugins.mqtt.conf.MqttConfig;
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.bean.copier.CopyOptions;
|
||||||
|
import com.gitee.starblues.bootstrap.annotation.AutowiredType;
|
||||||
|
import com.gitee.starblues.bootstrap.realize.PluginCloseListener;
|
||||||
|
import com.gitee.starblues.core.PluginCloseType;
|
||||||
|
import com.gitee.starblues.core.PluginInfo;
|
||||||
|
import io.vertx.core.Future;
|
||||||
|
import io.vertx.core.Vertx;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.support.GenericApplicationContext;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author sjg
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class MqttPlugin implements PluginCloseListener, IPlugin {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PluginInfo pluginInfo;
|
||||||
|
@Autowired
|
||||||
|
private MqttVerticle mqttVerticle;
|
||||||
|
@Autowired
|
||||||
|
private MqttConfig mqttConfig;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@AutowiredType(AutowiredType.Type.MAIN_PLUGIN)
|
||||||
|
private IPluginConfig pluginConfig;
|
||||||
|
|
||||||
|
private Vertx vertx;
|
||||||
|
private String deployedId;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
vertx = Vertx.vertx();
|
||||||
|
try {
|
||||||
|
//获取插件最新配置替换当前配置
|
||||||
|
Map<String, Object> config = pluginConfig.getConfig(pluginInfo.getPluginId());
|
||||||
|
BeanUtil.copyProperties(config, mqttConfig, CopyOptions.create().ignoreNullValue());
|
||||||
|
mqttVerticle.setConfig(mqttConfig);
|
||||||
|
|
||||||
|
Future<String> future = vertx.deployVerticle(mqttVerticle);
|
||||||
|
future.onSuccess((s -> {
|
||||||
|
deployedId = s;
|
||||||
|
log.info("mqtt plugin started success");
|
||||||
|
}));
|
||||||
|
future.onFailure((e) -> {
|
||||||
|
log.error("mqtt plugin startup failed", e);
|
||||||
|
});
|
||||||
|
} catch (Throwable e) {
|
||||||
|
log.error("mqtt plugin startup error", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close(GenericApplicationContext applicationContext, PluginInfo pluginInfo, PluginCloseType closeType) {
|
||||||
|
try {
|
||||||
|
log.info("plugin close,type:{},pluginId:{}", closeType, pluginInfo.getPluginId());
|
||||||
|
if (deployedId != null) {
|
||||||
|
CountDownLatch wait = new CountDownLatch(1);
|
||||||
|
Future<Void> future = vertx.undeploy(deployedId);
|
||||||
|
future.onSuccess(unused -> {
|
||||||
|
log.info("mqtt plugin stopped success");
|
||||||
|
wait.countDown();
|
||||||
|
});
|
||||||
|
future.onFailure(h -> {
|
||||||
|
log.info("tcp plugin stopped failed");
|
||||||
|
h.printStackTrace();
|
||||||
|
wait.countDown();
|
||||||
|
});
|
||||||
|
wait.await(5, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
log.error("mqtt plugin stop error", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getLinkInfo(String pk, String dn) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package cc.iotkit.plugins.mqtt.service;
|
||||||
|
|
||||||
|
import io.netty.channel.ChannelInitializer;
|
||||||
|
import io.netty.channel.socket.SocketChannel;
|
||||||
|
import io.netty.handler.codec.mqtt.MqttDecoder;
|
||||||
|
|
||||||
|
public class MyChannelInitializer extends ChannelInitializer<SocketChannel> {
|
||||||
|
@Override
|
||||||
|
protected void initChannel(SocketChannel ch) throws Exception {
|
||||||
|
System.out.println("initChannel设置最大帧大小为");
|
||||||
|
ch.pipeline().addLast("decoder", new MqttDecoder(10485760)); // c10MB
|
||||||
|
// 其他处理器...
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
plugin:
|
||||||
|
runMode: prod
|
||||||
|
mainPackage: cc.iotkit.plugin
|
||||||
|
|
||||||
|
mqtt:
|
||||||
|
port: 1883
|
@ -0,0 +1,87 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>cc.iotkit.plugins</groupId>
|
||||||
|
<artifactId>mqtt-test-client</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
|
<maven.compiler.target>11</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.vertx</groupId>
|
||||||
|
<artifactId>vertx-core</artifactId>
|
||||||
|
<version>4.2.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.vertx</groupId>
|
||||||
|
<artifactId>vertx-mqtt</artifactId>
|
||||||
|
<version>4.2.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.26</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
<version>3.12.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-codec</groupId>
|
||||||
|
<artifactId>commons-codec</artifactId>
|
||||||
|
<version>1.15</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-core</artifactId>
|
||||||
|
<version>2.14.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>2.14.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
|
<version>2.7.13</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>2.7.13</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,10 @@
|
|||||||
|
package cc.iotkit.test.mqtt;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
@SpringBootApplication(scanBasePackages = {"cc.iotkit"})
|
||||||
|
public class Application {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(Application.class, args);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package cc.iotkit.test.mqtt.config;
|
||||||
|
|
||||||
|
|
||||||
|
import cc.iotkit.test.mqtt.performance.ConnectionTest;
|
||||||
|
import cc.iotkit.test.mqtt.performance.ReportTest;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class BeanConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnProperty(name = "case", havingValue = "ConnectionTest")
|
||||||
|
ConnectionTest getConnectionTest() {
|
||||||
|
return new ConnectionTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnProperty(name = "case", havingValue = "ReportTest")
|
||||||
|
ReportTest getReportTest() {
|
||||||
|
return new ReportTest();
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue