Compare commits
5 Commits
696de12073
...
25a8b2150b
| Author | SHA1 | Date |
|---|---|---|
|
|
25a8b2150b | 20 hours ago |
|
|
2402bd81df | 6 months ago |
|
|
febc6291b8 | 11 months ago |
|
|
c696dc477d | 1 year ago |
|
|
34ea26c4b6 | 1 year ago |
@ -0,0 +1,13 @@
|
|||||||
|
### 该问题是怎么引起的?
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### 重现步骤
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### 报错信息
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -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,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,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.30</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,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,63 @@
|
|||||||
|
package cc.iotkit.plugins.emqx.conf;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class EventTypeMapper {
|
||||||
|
private static final Map<Integer, String> EVENT_TYPE_MAP = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
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(30, "自检");
|
||||||
|
EVENT_TYPE_MAP.put(31, "备电故障");
|
||||||
|
EVENT_TYPE_MAP.put(32, "主电故障");
|
||||||
|
EVENT_TYPE_MAP.put(33, "主电欠压");
|
||||||
|
EVENT_TYPE_MAP.put(34, "控制器复位");
|
||||||
|
EVENT_TYPE_MAP.put(35, "控制器开机");
|
||||||
|
EVENT_TYPE_MAP.put(36, "主电故障恢复");
|
||||||
|
EVENT_TYPE_MAP.put(37, "备电故障恢复");
|
||||||
|
EVENT_TYPE_MAP.put(38, "主电欠压恢复");
|
||||||
|
|
||||||
|
// 动火离人相关事件
|
||||||
|
EVENT_TYPE_MAP.put(50, "设备开机");
|
||||||
|
EVENT_TYPE_MAP.put(51, "动火离人报警");
|
||||||
|
EVENT_TYPE_MAP.put(52, "动火离人报警恢复");
|
||||||
|
EVENT_TYPE_MAP.put(53, "设备故障");
|
||||||
|
EVENT_TYPE_MAP.put(54, "设备故障恢复");
|
||||||
|
EVENT_TYPE_MAP.put(55, "断网故障");
|
||||||
|
EVENT_TYPE_MAP.put(56, "断网故障恢复");
|
||||||
|
|
||||||
|
// 正常上报事件
|
||||||
|
EVENT_TYPE_MAP.put(128, "燃气报警器正常数据上报");
|
||||||
|
EVENT_TYPE_MAP.put(129, "动火离人正常数据上报");
|
||||||
|
EVENT_TYPE_MAP.put(130, "联动控制箱正常数据上报");
|
||||||
|
EVENT_TYPE_MAP.put(151, "上报输出反馈状态变化");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getEventTypeName(int eventType) {
|
||||||
|
return EVENT_TYPE_MAP.getOrDefault(eventType, "未知事件类型");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
package cc.iotkit.plugins.emqx.conf;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class GasDetectorParser {
|
||||||
|
|
||||||
|
// 探测器精度映射
|
||||||
|
private static final Map<Integer, String> PRECISION_MAP = Map.of(
|
||||||
|
0b000, "*1",
|
||||||
|
0b001, "*0.1",
|
||||||
|
0b010, "*0.01",
|
||||||
|
0b011, "*0.001",
|
||||||
|
0b100, "*0.0001"
|
||||||
|
);
|
||||||
|
|
||||||
|
// 浓度单位映射
|
||||||
|
private static final Map<Integer, String> UNIT_MAP = Map.of(
|
||||||
|
0b000, "%LEL",
|
||||||
|
0b001, "PPM",
|
||||||
|
0b010, "%VOL"
|
||||||
|
);
|
||||||
|
|
||||||
|
// 气体类型映射
|
||||||
|
private static final Map<Integer, String> GAS_TYPE_MAP = Map.of(
|
||||||
|
0b0000, "甲烷",
|
||||||
|
0b0001, "一氧化碳",
|
||||||
|
0b0010, "丙烷",
|
||||||
|
0b0011, "氢气",
|
||||||
|
0b0100, "苯",
|
||||||
|
0b0101, "氧气"
|
||||||
|
);
|
||||||
|
|
||||||
|
public static String parse(int data) {
|
||||||
|
int precisionBits = (data >> 13) & 0b111; // 提取bit15-13
|
||||||
|
int unitBits = (data >> 10) & 0b111; // 提取bit12-10
|
||||||
|
int gasTypeBits = (data >> 6) & 0b1111; // 提取bit9-6
|
||||||
|
|
||||||
|
return String.format("探测器精度: %s, 浓度单位: %s, 测量气体: %s",
|
||||||
|
PRECISION_MAP.getOrDefault(precisionBits, "未知精度"),
|
||||||
|
UNIT_MAP.getOrDefault(unitBits, "未知单位"),
|
||||||
|
GAS_TYPE_MAP.getOrDefault(gasTypeBits, "未知气体")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,275 @@
|
|||||||
|
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 final int REPORT_RATE_LinkConstraint = 0x0100;
|
||||||
|
// 生成读取指令
|
||||||
|
// 反向映射Map
|
||||||
|
private static final Map<Integer, String> CONFIG_ID_TO_KEY = new HashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
// 初始化反向映射
|
||||||
|
CONFIG_ID_TO_KEY.put(IP_REALM, "ip");
|
||||||
|
CONFIG_ID_TO_KEY.put(PORT, "port");
|
||||||
|
CONFIG_ID_TO_KEY.put(REPORT_AWAIT_TIME, "reportAwaitTime");
|
||||||
|
CONFIG_ID_TO_KEY.put(REPORT_RETRY_TIMES, "reportRetryTimes");
|
||||||
|
CONFIG_ID_TO_KEY.put(CARD, "card");
|
||||||
|
CONFIG_ID_TO_KEY.put(USERNAME, "username");
|
||||||
|
CONFIG_ID_TO_KEY.put(PASSWORD, "password");
|
||||||
|
CONFIG_ID_TO_KEY.put(KEEP_ALIVE, "keepAlive");
|
||||||
|
CONFIG_ID_TO_KEY.put(PUBLISH_TOPIC, "publishTopicPrefix");
|
||||||
|
CONFIG_ID_TO_KEY.put(SUBSCRIBE_TOPIC, "subscribeTopicPrefix");
|
||||||
|
CONFIG_ID_TO_KEY.put(REPORT_RATE_UPPER, "reportRateUpper");
|
||||||
|
CONFIG_ID_TO_KEY.put(REPORT_CONCENTRATION_RANGE, "reportConcentrationRange");
|
||||||
|
CONFIG_ID_TO_KEY.put(REPORT_RATE_LOWER, "reportRateLower");
|
||||||
|
CONFIG_ID_TO_KEY.put(SIGNAL, "signal");
|
||||||
|
CONFIG_ID_TO_KEY.put(TIME_SYNC, "timeSyncInternal");
|
||||||
|
CONFIG_ID_TO_KEY.put(VERSION, "version");
|
||||||
|
CONFIG_ID_TO_KEY.put(REPORT_RATE_LinkConstraint, "controlOutput");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getKeyByConfigId(int configId) {
|
||||||
|
return CONFIG_ID_TO_KEY.get(configId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String generateReadCommand( int configId) {
|
||||||
|
ByteBuffer buf = ByteBuffer.allocate(2);
|
||||||
|
// 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 configId, byte[] data) {
|
||||||
|
|
||||||
|
ByteBuffer buf = ByteBuffer.allocate(3 + 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));
|
||||||
|
}
|
||||||
|
// CONFIG_ID_TO_KEY.get((int)result.get("configId"));
|
||||||
|
result.put("key", getKeyByConfigId((int)result.get("configId")));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* // 特殊格式解析方法
|
||||||
|
private static String parseTLVString(byte[] data) {
|
||||||
|
int len = data[0] & 0xFF;
|
||||||
|
int maxAvailable = data.length - 1; // 可用最大长度
|
||||||
|
if (maxAvailable <= 0 || len <= 0) {
|
||||||
|
return ""; // 或抛出自定义异常
|
||||||
|
}
|
||||||
|
return new String(data, 1, Math.min(len, maxAvailable), StandardCharsets.US_ASCII);
|
||||||
|
}*/
|
||||||
|
private static String parseTLVString(byte[] data) {
|
||||||
|
int maxAvailable = data.length; // 可用最大长度
|
||||||
|
if (maxAvailable <= 0) {
|
||||||
|
return ""; // 或抛出自定义异常
|
||||||
|
}
|
||||||
|
return new String(data, StandardCharsets.US_ASCII);
|
||||||
|
}
|
||||||
|
private static String parseSimCard(byte[] data) {
|
||||||
|
// int len = data[0] & 0xFF;
|
||||||
|
int maxAvailable = data.length; // 可用最大长度
|
||||||
|
if (maxAvailable <= 0) {
|
||||||
|
return ""; // 或抛出自定义异常
|
||||||
|
}
|
||||||
|
return new String(data, StandardCharsets.US_ASCII);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public 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;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* ip地址转换成TLV数据
|
||||||
|
* */
|
||||||
|
public static byte[] convertToFixedAscii(String input, int fixedLength) {
|
||||||
|
// 验证输入格式
|
||||||
|
if (!isValidIpOrDomain(input)) {
|
||||||
|
throw new IllegalArgumentException("Invalid IP/Domain format");
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] originBytes = input.getBytes(StandardCharsets.US_ASCII);
|
||||||
|
byte[] result = new byte[fixedLength];
|
||||||
|
|
||||||
|
// 复制原始数据并补0
|
||||||
|
System.arraycopy(originBytes, 0, result, 0, Math.min(originBytes.length, fixedLength));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
private static boolean isValidIpOrDomain(String input) {
|
||||||
|
// IP地址正则验证 (IPv4)
|
||||||
|
String ipPattern = "^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$";
|
||||||
|
// 域名正则验证 (支持国际化域名IDN的ASCII形式)
|
||||||
|
String domainPattern = "^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,6}$";
|
||||||
|
|
||||||
|
return input.matches(ipPattern) || input.matches(domainPattern);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* 构建单字节数据
|
||||||
|
* */
|
||||||
|
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, strBytes, 1, strBytes.length);
|
||||||
|
return strBytes;
|
||||||
|
}
|
||||||
|
// 构建BCD时间数据(YYMMDDhhmmss)
|
||||||
|
|
||||||
|
public static byte[] buildBcdTimeData(String time) {
|
||||||
|
/* DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyMMddHHmmss");
|
||||||
|
String formatted = LocalDateTime.now().format(formatter);*/
|
||||||
|
// 验证输入格式
|
||||||
|
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
LocalDateTime dateTime = LocalDateTime.parse(time, inputFormatter);
|
||||||
|
// 转换为yyMMddHHmmss格式字符串
|
||||||
|
String formatted = dateTime.format(DateTimeFormatter.ofPattern("yyMMddHHmmss"));
|
||||||
|
|
||||||
|
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,105 @@
|
|||||||
|
package cc.iotkit.plugins.emqx.conf;
|
||||||
|
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import io.vertx.core.json.JsonObject;
|
||||||
|
import io.vertx.mqtt.messages.MqttMessage;
|
||||||
|
import io.vertx.mqtt.messages.MqttPublishMessage;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
public class MqttDataProcessor {
|
||||||
|
private static final byte HEADER = (byte) 0xAA;
|
||||||
|
private static final byte FOOTER = (byte) 0x55;
|
||||||
|
private static final int CRC_START_INDEX = 3; // 帧长度开始位置
|
||||||
|
private static final String HEX_FORMAT = "0x%02X";
|
||||||
|
public static String bytesToHex(byte[] bytes) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (byte b : bytes) {
|
||||||
|
sb.append(String.format("%02X", b));
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
public static JsonObject parseFrame(byte[] frameData) {
|
||||||
|
|
||||||
|
// 基础校验
|
||||||
|
if (frameData[0] != HEADER || frameData[frameData.length - 1] != FOOTER) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提取各字段
|
||||||
|
ByteBuffer buffer = ByteBuffer.wrap(frameData);
|
||||||
|
byte type = buffer.get(1);
|
||||||
|
byte version = buffer.get(2);
|
||||||
|
int length = Short.toUnsignedInt(buffer.getShort(3));
|
||||||
|
byte mid = buffer.get(5);
|
||||||
|
byte cmd = buffer.get(6);
|
||||||
|
String hexCmd = String.format(HEX_FORMAT, cmd);
|
||||||
|
// 数据域提取
|
||||||
|
int dataLength = length - 10; // 总长减去固定字段长度
|
||||||
|
byte[] data = new byte[dataLength];
|
||||||
|
System.arraycopy(frameData, 7, data, 0, dataLength);
|
||||||
|
String data1 = parseToHexString(data);
|
||||||
|
// CRC校验
|
||||||
|
byte[] crcData = new byte[length - 6]; // 从LENGTH到DATA
|
||||||
|
System.arraycopy(frameData, 3, crcData, 0, crcData.length);
|
||||||
|
int receivedCrc = (frameData[length-2] & 0xFF) << 8 | (frameData[length-3] & 0xFF);
|
||||||
|
|
||||||
|
int calculatedCrc = calculateModbusCRC(crcData);
|
||||||
|
|
||||||
|
if (receivedCrc != calculatedCrc) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// 转换为16进制字符串
|
||||||
|
// 完整帧数据转16进制
|
||||||
|
StringBuilder frameHexBuilder = new StringBuilder();
|
||||||
|
for (byte b : frameData) {
|
||||||
|
frameHexBuilder.append(String.format("%02X", b));
|
||||||
|
}
|
||||||
|
String rawHex = frameHexBuilder.toString();
|
||||||
|
// 构建JSON
|
||||||
|
// ObjectMapper mapper = new ObjectMapper();
|
||||||
|
// ObjectNode json = mapper.createObjectNode();
|
||||||
|
JsonObject json = new JsonObject();
|
||||||
|
json.put("protocolType", type);
|
||||||
|
json.put("protocolVersion", version);
|
||||||
|
json.put("messageId", mid);
|
||||||
|
json.put("cmd", hexCmd);
|
||||||
|
json.put("data", data1);
|
||||||
|
json.put("rawHex", rawHex);
|
||||||
|
json.put("crcValid", true);
|
||||||
|
System.out.println("拿到的所有数据++++++++++" + json);
|
||||||
|
// JsonObject jsonObject = new JsonObject(json.toString());
|
||||||
|
return json;
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public static String parseToHexString(byte[] frameData) {
|
||||||
|
StringBuilder hexStr = new StringBuilder();
|
||||||
|
for (byte b : frameData) {
|
||||||
|
hexStr.append(String.format("%02X ", b));
|
||||||
|
}
|
||||||
|
return hexStr.toString().trim();
|
||||||
|
}
|
||||||
|
public static int calculateModbusCRC(byte[] data) {
|
||||||
|
int crc = 0xFFFF;
|
||||||
|
for (byte b : data) {
|
||||||
|
crc ^= (b & 0xFF);
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
if ((crc & 1) == 1) {
|
||||||
|
crc = (crc >>> 1) ^ 0xA001;
|
||||||
|
} else {
|
||||||
|
crc >>>= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,71 @@
|
|||||||
|
package cc.iotkit.plugins.emqx.conf;
|
||||||
|
|
||||||
|
import org.apache.commons.codec.DecoderException;
|
||||||
|
import org.apache.commons.codec.binary.Hex;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class MqttHexProcessor {
|
||||||
|
|
||||||
|
|
||||||
|
// 检测是否为HEX字符串格式
|
||||||
|
private static boolean isHexString(byte[] data) {
|
||||||
|
if (data.length % 2 != 0) return false;
|
||||||
|
for (byte b : data) {
|
||||||
|
char c = (char) b;
|
||||||
|
if (!(Character.isDigit(c) ||
|
||||||
|
(c >= 'A' && c <= 'F') ||
|
||||||
|
(c >= 'a' && c <= 'f') ||
|
||||||
|
Character.isWhitespace(c))) { // 新增空格检查
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// HEX字符串转字节数组
|
||||||
|
/* private static byte[] parseHexString(String s) {
|
||||||
|
int len = s.length();
|
||||||
|
byte[] data = new byte[len / 2];
|
||||||
|
for (int i = 0; i < len; i += 2) {
|
||||||
|
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
|
||||||
|
+ Character.digit(s.charAt(i+1), 16));
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
// 统一返回byte[]的入口方法
|
||||||
|
public static byte[] processToBytes(byte[] payload) {
|
||||||
|
try {
|
||||||
|
String payloadStr = new String(payload, StandardCharsets.UTF_8);
|
||||||
|
System.out.println("payloadStr:" + payloadStr);
|
||||||
|
System.out.println("payloadStr1:" + isHexString(payload));
|
||||||
|
return isHexString(payload) ?
|
||||||
|
Hex.decodeHex(payloadStr.replaceAll("\\s+", "")) :
|
||||||
|
payload; // 原始字节直接返回
|
||||||
|
} catch (Exception e) {
|
||||||
|
return payload; // 异常时返回原始数据
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*public static void main(String[] args) throws DecoderException {
|
||||||
|
String input = "AA 01 01 00 35001100013836323537313037393339313237393839383631313235323037303833363037383837000000000111b12255"; // 原始字符串
|
||||||
|
// byte[] result = convertHexStringToBytes(input);
|
||||||
|
byte[] bytes = Hex.decodeHex(input);
|
||||||
|
// 基础校验
|
||||||
|
|
||||||
|
|
||||||
|
// 提取各字段
|
||||||
|
ByteBuffer buffer = ByteBuffer.wrap(bytes);
|
||||||
|
byte type = buffer.get(1);
|
||||||
|
byte version = buffer.get(2);
|
||||||
|
System.out.println(String.format("%02X", bytes[0]));
|
||||||
|
System.out.println(type);
|
||||||
|
System.out.println(version);
|
||||||
|
|
||||||
|
}*/
|
||||||
|
}
|
||||||
@ -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,340 @@
|
|||||||
|
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.buffer.Buffer;
|
||||||
|
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.nio.ByteOrder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
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;
|
||||||
|
switch (key) {
|
||||||
|
case "ip":
|
||||||
|
configId = IP_REALM;
|
||||||
|
tlvData = convertToFixedAscii(value,50);
|
||||||
|
break;
|
||||||
|
case "port":
|
||||||
|
case "keepAlive":
|
||||||
|
case "reportRateUpper":
|
||||||
|
|
||||||
|
configId = (key.equals("port") ? PORT : key.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.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.equals("subscribeTopicPrefix") ? SUBSCRIBE_TOPIC : PUBLISH_TOPIC);
|
||||||
|
tlvData = buildStringData(value.toString(), 30);
|
||||||
|
break;
|
||||||
|
case "timeSyncInternal":
|
||||||
|
configId = TIME_SYNC;
|
||||||
|
tlvData = buildBcdTimeData(value);
|
||||||
|
break;
|
||||||
|
case "reportConcentrationRange":
|
||||||
|
configId = REPORT_CONCENTRATION_RANGE;
|
||||||
|
tlvData = ByteBuffer.allocate(2).putShort(Short.parseShort(value)).array();
|
||||||
|
break;
|
||||||
|
case "reportRateLower":
|
||||||
|
configId = REPORT_RATE_LOWER;
|
||||||
|
tlvData = ByteBuffer.allocate(2).putShort(Short.parseShort(value)).array();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "controlOutput":
|
||||||
|
configId = REPORT_RATE_LinkConstraint;
|
||||||
|
tlvData = ByteBuffer.allocate(4)
|
||||||
|
.order(ByteOrder.BIG_ENDIAN)
|
||||||
|
.putInt(Integer.parseUnsignedInt(value, 16)).array();
|
||||||
|
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(
|
||||||
|
configId, tlvData);
|
||||||
|
map.put("data", command);
|
||||||
|
list.add(map);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Map> processGetConfig(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();
|
||||||
|
Integer configId = null;
|
||||||
|
try {
|
||||||
|
switch (key) {
|
||||||
|
case "ip":
|
||||||
|
configId = IP_REALM;
|
||||||
|
break;
|
||||||
|
case "port":
|
||||||
|
configId = PORT;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "reportAwaitTime":
|
||||||
|
configId = REPORT_AWAIT_TIME;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "reportRetryTimes":
|
||||||
|
configId = REPORT_RETRY_TIMES;
|
||||||
|
break;
|
||||||
|
case "card":
|
||||||
|
configId = CARD;
|
||||||
|
break;
|
||||||
|
case "username":
|
||||||
|
configId = USERNAME;
|
||||||
|
break;
|
||||||
|
case "password":
|
||||||
|
configId = PASSWORD;
|
||||||
|
break;
|
||||||
|
case "keepAlive":
|
||||||
|
configId = KEEP_ALIVE;
|
||||||
|
break;
|
||||||
|
case "publishTopicPrefix":
|
||||||
|
configId = PUBLISH_TOPIC;
|
||||||
|
break;
|
||||||
|
case "subscribeTopicPrefix":
|
||||||
|
configId = SUBSCRIBE_TOPIC;
|
||||||
|
break;
|
||||||
|
case "reportRateUpper":
|
||||||
|
configId = REPORT_RATE_UPPER;
|
||||||
|
break;
|
||||||
|
case "reportConcentrationRange":
|
||||||
|
configId = REPORT_CONCENTRATION_RANGE;
|
||||||
|
break;
|
||||||
|
case "reportRateLower":
|
||||||
|
configId = REPORT_RATE_LOWER;
|
||||||
|
break;
|
||||||
|
case "signal":
|
||||||
|
configId = SIGNAL;
|
||||||
|
break;
|
||||||
|
case "timeSyncInternal":
|
||||||
|
configId = TIME_SYNC;
|
||||||
|
break;
|
||||||
|
case "version":
|
||||||
|
configId = VERSION;
|
||||||
|
break;
|
||||||
|
case "controlOutput":
|
||||||
|
configId = REPORT_RATE_LinkConstraint;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println("Unsupported config: " + key);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ObjectUtil.isNotNull(configId)) {
|
||||||
|
String command = IoTConfigProtocol.generateReadCommand(
|
||||||
|
configId);
|
||||||
|
map.put("data", command);
|
||||||
|
list.add(map);
|
||||||
|
System.out.println("ddddeeeeeeeeeeeeeeddddd" + map);
|
||||||
|
/* 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("ddddddddddddddddddddddddddddddddd" + list);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ActionResult config(DeviceConfig action) {
|
||||||
|
String topic = "FIGARO/request/"+ action.getDeviceName();
|
||||||
|
// Map data = JsonUtils.parseObject(action.getConfig(), Map.class);
|
||||||
|
/* int type = 0x0000;
|
||||||
|
switch (action.getProductKey()) {
|
||||||
|
case "CEMpmANABN7Tt6Jh0":
|
||||||
|
type = 0x0000;
|
||||||
|
break;
|
||||||
|
case "XmXYxjzihseT76As":
|
||||||
|
type = 0x0001;
|
||||||
|
break;
|
||||||
|
case "bAASX8tBjYQjBGFP":
|
||||||
|
type = 0x0002;
|
||||||
|
break;
|
||||||
|
case "WfpZZFkMxxbGfRca":
|
||||||
|
type = 0x0003;
|
||||||
|
break;
|
||||||
|
}*/
|
||||||
|
System.out.println("action.getProductKey()++++++++++++++++++++" + action.getProductKey());
|
||||||
|
if (action.getModule().equals("set")) {
|
||||||
|
List<Map> list = processConfig(action.getConfig());
|
||||||
|
System.out.println("listset++++++++++++++++++++" + list);
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
String replyMessage = buildFrame("01","01",
|
||||||
|
"00", "24", list.get(i).get("data").toString());
|
||||||
|
//循环发送配置指令
|
||||||
|
/* String replyMessage = buildFrame("01", "01",
|
||||||
|
"01", "24", "01" + list.get(i).get("data"));*/
|
||||||
|
System.out.println("配置指令" + replyMessage);
|
||||||
|
send(
|
||||||
|
topic,replyMessage
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
Thread.sleep(500);
|
||||||
|
}catch (Exception e){
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if(action.getModule().equals("get")){
|
||||||
|
System.out.println("action.getConfig()++++++++++++++++++++" + action.getConfig());
|
||||||
|
//配置获取指令下发
|
||||||
|
List<Map> list = processGetConfig(action.getConfig());
|
||||||
|
System.out.println("list++++++++++++++++++++" + list);
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
//循环发送配置指令
|
||||||
|
/* String replyMessage = buildFrame("01", "01",
|
||||||
|
"01", "23", "01" + list.get(i).get("data"));*/
|
||||||
|
String replyMessage = buildFrame("01","01",
|
||||||
|
"00", "23",list.get(i).get("data").toString());
|
||||||
|
|
||||||
|
send(
|
||||||
|
topic,replyMessage
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
Thread.sleep(500);
|
||||||
|
}catch (Exception e){
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private ActionResult send(String topic, String payload) {
|
||||||
|
try {
|
||||||
|
/* byte[] bytes = payload.getBytes(StandardCharsets.UTF_8);
|
||||||
|
Buffer buffer = Buffer.buffer(bytes);*/
|
||||||
|
|
||||||
|
client.publish(topic, Buffer.buffer(payload), 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: 123.57.78.108
|
||||||
|
port: 1883
|
||||||
|
topics: FIGARO/#
|
||||||
|
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
|
||||||
|
// 其他处理器...
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue