Commit 6cf2eb07d707a25acf975463ea7557daa172a8c7

Authored by YunaiV
1 parent 70a0df54

feat:【IoT 物联网】增加 iot-common 和 iot-gateway 包

Showing 18 changed files with 247 additions and 3 deletions
yudao-module-iot/pom.xml
@@ -12,6 +12,7 @@ @@ -12,6 +12,7 @@
12 <module>yudao-module-iot-net-components</module> 12 <module>yudao-module-iot-net-components</module>
13 <module>yudao-module-iot-protocol</module> 13 <module>yudao-module-iot-protocol</module>
14 <module>yudao-module-iot-core</module> 14 <module>yudao-module-iot-core</module>
  15 + <module>yudao-module-iot-gateway</module>
15 </modules> 16 </modules>
16 <modelVersion>4.0.0</modelVersion> 17 <modelVersion>4.0.0</modelVersion>
17 18
yudao-module-iot/yudao-module-iot-core/pom.xml
@@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
8 <version>${revision}</version> 8 <version>${revision}</version>
9 </parent> 9 </parent>
10 <modules> 10 <modules>
  11 + <module>yudao-module-iot-common</module>
11 <module>yudao-module-iot-message-bus</module> 12 <module>yudao-module-iot-message-bus</module>
12 </modules> 13 </modules>
13 <modelVersion>4.0.0</modelVersion> 14 <modelVersion>4.0.0</modelVersion>
@@ -17,7 +18,7 @@ @@ -17,7 +18,7 @@
17 18
18 <name>${project.artifactId}</name> 19 <name>${project.artifactId}</name>
19 <description> 20 <description>
20 - iot 模块下,提供 biz 和 gateway-server 模块的核心功能。 21 + iot 模块下,提供 iot-biz 和 iot-gateway 模块的核心功能。
21 例如说:消息总线、消息协议(编解码)等。 22 例如说:消息总线、消息协议(编解码)等。
22 </description> 23 </description>
23 24
yudao-module-iot/yudao-module-iot-core/yudao-module-iot-common/pom.xml 0 → 100644
  1 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3 + <parent>
  4 + <artifactId>yudao-module-iot-core</artifactId>
  5 + <groupId>cn.iocoder.boot</groupId>
  6 + <version>${revision}</version>
  7 + </parent>
  8 + <modelVersion>4.0.0</modelVersion>
  9 + <artifactId>yudao-module-iot-common</artifactId>
  10 + <packaging>jar</packaging>
  11 +
  12 + <name>${project.artifactId}</name>
  13 + <description>
  14 + iot 模块下,提供通用的功能。
  15 + 1. 跨 iot-biz 和 iot-gateway 的设备消息
  16 + 2. 查询设备信息的通用 API
  17 + </description>
  18 +
  19 + <dependencies>
  20 + <dependency>
  21 + <groupId>cn.iocoder.boot</groupId>
  22 + <artifactId>yudao-common</artifactId>
  23 + </dependency>
  24 + </dependencies>
  25 +
  26 +</project>
yudao-module-iot/yudao-module-iot-core/yudao-module-iot-common/src/main/java/cn/iocoder/yudao/module/iot/common/biz/IotDeviceCommonApi.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.common.biz;
  2 +
  3 +// TODO @芋艿:待实现
  4 +public interface IotDeviceCommonApi {
  5 +}
yudao-module-iot/yudao-module-iot-core/yudao-module-iot-common/src/main/java/cn/iocoder/yudao/module/iot/common/enums/IotCommonConstants.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.common.enums;
  2 +
  3 +/**
  4 + * IoT 通用的枚举
  5 + *
  6 + * @author 芋道源码
  7 + */
  8 +public interface IotCommonConstants {
  9 +
  10 + /**
  11 + * 【消息总线】应用的设备消息 Topic,由 iot-gateway 发给 iot-biz 进行消费
  12 + */
  13 + String MESSAGE_BUS_DEVICE_MESSAGE_TOPIC = "iot_device_message";
  14 +
  15 + /**
  16 + * 【消息总线】设备消息 Topic,由 iot-biz 发送给 iot-gateway 的某个 “server”(protocol) 进行消费
  17 + *
  18 + * 其中,%s 就是该“server”(protocol) 的标识
  19 + */
  20 + String MESSAGE_BUS_GATEWAY_DEVICE_MESSAGE_TOPIC = MESSAGE_BUS_DEVICE_MESSAGE_TOPIC + "/%s";
  21 +
  22 +}
yudao-module-iot/yudao-module-iot-core/yudao-module-iot-common/src/main/java/cn/iocoder/yudao/module/iot/common/enums/IotDeviceMessageIdentifierEnum.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.common.enums;
  2 +
  3 +import lombok.Getter;
  4 +import lombok.RequiredArgsConstructor;
  5 +
  6 +// TODO @芋艿:需要添加对应的 DTO,以及上下行的链路,网关、网关服务、设备等
  7 +
  8 +/**
  9 + * IoT 设备消息标识符枚举
  10 + */
  11 +@Getter
  12 +@RequiredArgsConstructor
  13 +public enum IotDeviceMessageIdentifierEnum {
  14 +
  15 + PROPERTY_GET("get"), // 下行 TODO 芋艿:【讨论】貌似这个“上行”更合理?device 主动拉取配置。和 IotDevicePropertyGetReqDTO 一样的配置
  16 + PROPERTY_SET("set"), // 下行
  17 + PROPERTY_REPORT("report"), // 上行
  18 +
  19 + STATE_ONLINE("online"), // 上行
  20 + STATE_OFFLINE("offline"), // 上行
  21 +
  22 + CONFIG_GET("get"), // 上行 TODO 芋艿:【讨论】暂时没有上行的场景
  23 + CONFIG_SET("set"), // 下行
  24 +
  25 + SERVICE_INVOKE("${identifier}"), // 下行
  26 + SERVICE_REPLY_SUFFIX("_reply"), // 芋艿:TODO 芋艿:【讨论】上行 or 下行
  27 +
  28 + OTA_UPGRADE("upgrade"), // 下行
  29 + OTA_PULL("pull"), // 上行
  30 + OTA_PROGRESS("progress"), // 上行
  31 + OTA_REPORT("report"), // 上行
  32 +
  33 + REGISTER_REGISTER("register"), // 上行
  34 + REGISTER_REGISTER_SUB("register_sub"), // 上行
  35 + REGISTER_UNREGISTER_SUB("unregister_sub"), // 下行
  36 +
  37 + TOPOLOGY_ADD("topology_add"), // 下行;
  38 + ;
  39 +
  40 + /**
  41 + * 标志符
  42 + */
  43 + private final String identifier;
  44 +
  45 +}
0 \ No newline at end of file 46 \ No newline at end of file
yudao-module-iot/yudao-module-iot-core/yudao-module-iot-common/src/main/java/cn/iocoder/yudao/module/iot/common/enums/IotDeviceMessageTypeEnum.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.common.enums;
  2 +
  3 +import cn.iocoder.yudao.framework.common.core.ArrayValuable;
  4 +import lombok.Getter;
  5 +import lombok.RequiredArgsConstructor;
  6 +
  7 +import java.util.Arrays;
  8 +
  9 +/**
  10 + * IoT 设备消息类型枚举
  11 + */
  12 +@Getter
  13 +@RequiredArgsConstructor
  14 +public enum IotDeviceMessageTypeEnum implements ArrayValuable<String> {
  15 +
  16 + STATE("state"), // 设备状态
  17 + PROPERTY("property"), // 设备属性:可参考 https://help.aliyun.com/zh/iot/user-guide/device-properties-events-and-services 设备属性、事件、服务
  18 + EVENT("event"), // 设备事件:可参考 https://help.aliyun.com/zh/iot/user-guide/device-properties-events-and-services 设备属性、事件、服务
  19 + SERVICE("service"), // 设备服务:可参考 https://help.aliyun.com/zh/iot/user-guide/device-properties-events-and-services 设备属性、事件、服务
  20 + CONFIG("config"), // 设备配置:可参考 https://help.aliyun.com/zh/iot/user-guide/remote-configuration-1 远程配置
  21 + OTA("ota"), // 设备 OTA:可参考 https://help.aliyun.com/zh/iot/user-guide/ota-update OTA 升级
  22 + REGISTER("register"), // 设备注册:可参考 https://help.aliyun.com/zh/iot/user-guide/register-devices 设备身份注册
  23 + TOPOLOGY("topology"),; // 设备拓扑:可参考 https://help.aliyun.com/zh/iot/user-guide/manage-topological-relationships 设备拓扑
  24 +
  25 + public static final String[] ARRAYS = Arrays.stream(values()).map(IotDeviceMessageTypeEnum::getType).toArray(String[]::new);
  26 +
  27 + /**
  28 + * 属性
  29 + */
  30 + private final String type;
  31 +
  32 + @Override
  33 + public String[] array() {
  34 + return ARRAYS;
  35 + }
  36 +
  37 +}
yudao-module-iot/yudao-module-iot-core/yudao-module-iot-common/src/main/java/cn/iocoder/yudao/module/iot/common/message/IotDeviceMessage.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.common.message;
  2 +
  3 +import cn.iocoder.yudao.module.iot.common.enums.IotDeviceMessageIdentifierEnum;
  4 +import cn.iocoder.yudao.module.iot.common.enums.IotDeviceMessageTypeEnum;
  5 +import lombok.AllArgsConstructor;
  6 +import lombok.Builder;
  7 +import lombok.Data;
  8 +import lombok.NoArgsConstructor;
  9 +
  10 +import java.time.LocalDateTime;
  11 +
  12 +// TODO @芋艿:参考阿里云的物模型,优化 IoT 上下行消息的设计,尽量保持一致(渐进式,不要一口气)!
  13 +
  14 +/**
  15 + * IoT 设备消息
  16 + */
  17 +@Data
  18 +@NoArgsConstructor
  19 +@AllArgsConstructor
  20 +@Builder
  21 +public class IotDeviceMessage {
  22 +
  23 + /**
  24 + * 请求编号
  25 + */
  26 + private String requestId;
  27 +
  28 + /**
  29 + * 设备信息
  30 + */
  31 + private String productKey;
  32 + /**
  33 + * 设备名称
  34 + */
  35 + private String deviceName;
  36 + /**
  37 + * 设备标识
  38 + */
  39 + private String deviceKey;
  40 +
  41 + /**
  42 + * 消息类型
  43 + *
  44 + * 枚举 {@link IotDeviceMessageTypeEnum}
  45 + */
  46 + private String type;
  47 + /**
  48 + * 标识符
  49 + *
  50 + * 枚举 {@link IotDeviceMessageIdentifierEnum}
  51 + */
  52 + private String identifier;
  53 +
  54 + /**
  55 + * 请求参数
  56 + *
  57 + * 例如说:属性上报的 properties、事件上报的 params
  58 + */
  59 + private Object data;
  60 + /**
  61 + * 响应码
  62 + *
  63 + * 目前只有 server 下行消息给 device 设备时,才会有响应码
  64 + */
  65 + private Integer code;
  66 +
  67 + /**
  68 + * 上报时间
  69 + */
  70 + private LocalDateTime reportTime;
  71 +
  72 + /**
  73 + * 租户编号
  74 + */
  75 + private Long tenantId;
  76 +
  77 +}
yudao-module-iot/yudao-module-iot-gateway/pom.xml 0 → 100644
  1 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3 + <parent>
  4 + <artifactId>yudao-module-iot</artifactId>
  5 + <groupId>cn.iocoder.boot</groupId>
  6 + <version>${revision}</version>
  7 + </parent>
  8 + <modelVersion>4.0.0</modelVersion>
  9 + <packaging>jar</packaging>
  10 + <artifactId>yudao-module-iot-gateway</artifactId>
  11 +
  12 + <name>${project.artifactId}</name>
  13 + <description>
  14 + iot 模块下,设备网关:
  15 + ① 功能一:接收来自设备的消息,并进行解码(decode)后,发送到消息网关,提供给 iot-biz 进行处理
  16 + ② 功能二:接收来自消息网关的消息(由 iot-biz 发送),并进行编码(encode)后,发送给设备
  17 + </description>
  18 +
  19 +</project>
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/codec/alink/package-info.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.gateway.codec.alink;
0 \ No newline at end of file 2 \ No newline at end of file
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/codec/modbus/package-info.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.gateway.codec.modbus;
0 \ No newline at end of file 2 \ No newline at end of file
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/codec/package-info.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.gateway.codec;
0 \ No newline at end of file 2 \ No newline at end of file
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/package-info.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.gateway;
0 \ No newline at end of file 2 \ No newline at end of file
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/http/package-info.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.http;
0 \ No newline at end of file 2 \ No newline at end of file
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/mqtt/package-info.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.mqtt;
0 \ No newline at end of file 2 \ No newline at end of file
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/package-info.java 0 → 100644
  1 +/**
  2 + * TODO 占位
  3 + */
  4 +package cn.iocoder.yudao.module.iot.gateway.protocol;
0 \ No newline at end of file 5 \ No newline at end of file
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/tcp/package-info.java 0 → 100644
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.tcp;
0 \ No newline at end of file 2 \ No newline at end of file
yudao-module-iot/yudao-module-iot-protocol/pom.xml
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 <name>${project.artifactId}</name> 15 <name>${project.artifactId}</name>
16 <description> 16 <description>
17 物联网协议模块,提供 topic 解析、协议转换等功能 17 物联网协议模块,提供 topic 解析、协议转换等功能
18 - 作为 yudao-module-iot-biz 和 yudao-module-iot-gateway-server 的共享包 18 + 作为 iot-biz 和 iot-gateway 的共享包
19 </description> 19 </description>
20 20
21 <dependencies> 21 <dependencies>
@@ -68,4 +68,4 @@ @@ -68,4 +68,4 @@
68 </dependency> 68 </dependency>
69 </dependencies> 69 </dependencies>
70 70
71 -</project>  
72 \ No newline at end of file 71 \ No newline at end of file
  72 +</project>
73 \ No newline at end of file 73 \ No newline at end of file