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

This commit is contained in:
YunaiV 2025-05-28 13:22:22 +08:00
parent 70a0df54e4
commit 6cf2eb07d7
18 changed files with 247 additions and 3 deletions

View File

@ -12,6 +12,7 @@
<module>yudao-module-iot-net-components</module>
<module>yudao-module-iot-protocol</module>
<module>yudao-module-iot-core</module>
<module>yudao-module-iot-gateway</module>
</modules>
<modelVersion>4.0.0</modelVersion>

View File

@ -8,6 +8,7 @@
<version>${revision}</version>
</parent>
<modules>
<module>yudao-module-iot-common</module>
<module>yudao-module-iot-message-bus</module>
</modules>
<modelVersion>4.0.0</modelVersion>
@ -17,7 +18,7 @@
<name>${project.artifactId}</name>
<description>
iot 模块下,提供 biz 和 gateway-server 模块的核心功能。
iot 模块下,提供 iot-biz 和 iot-gateway 模块的核心功能。
例如说:消息总线、消息协议(编解码)等。
</description>

View File

@ -0,0 +1,26 @@
<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>yudao-module-iot-core</artifactId>
<groupId>cn.iocoder.boot</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>yudao-module-iot-common</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>
iot 模块下,提供通用的功能。
1. 跨 iot-biz 和 iot-gateway 的设备消息
2. 查询设备信息的通用 API
</description>
<dependencies>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-common</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,5 @@
package cn.iocoder.yudao.module.iot.common.biz;
// TODO @芋艿待实现
public interface IotDeviceCommonApi {
}

View File

@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.iot.common.enums;
/**
* IoT 通用的枚举
*
* @author 芋道源码
*/
public interface IotCommonConstants {
/**
* 消息总线应用的设备消息 Topic iot-gateway 发给 iot-biz 进行消费
*/
String MESSAGE_BUS_DEVICE_MESSAGE_TOPIC = "iot_device_message";
/**
* 消息总线设备消息 Topic iot-biz 发送给 iot-gateway 的某个 server(protocol) 进行消费
*
* 其中%s 就是该server(protocol) 的标识
*/
String MESSAGE_BUS_GATEWAY_DEVICE_MESSAGE_TOPIC = MESSAGE_BUS_DEVICE_MESSAGE_TOPIC + "/%s";
}

View File

@ -0,0 +1,45 @@
package cn.iocoder.yudao.module.iot.common.enums;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
// TODO @芋艿需要添加对应的 DTO以及上下行的链路网关网关服务设备等
/**
* IoT 设备消息标识符枚举
*/
@Getter
@RequiredArgsConstructor
public enum IotDeviceMessageIdentifierEnum {
PROPERTY_GET("get"), // 下行 TODO 芋艿讨论貌似这个上行更合理device 主动拉取配置 IotDevicePropertyGetReqDTO 一样的配置
PROPERTY_SET("set"), // 下行
PROPERTY_REPORT("report"), // 上行
STATE_ONLINE("online"), // 上行
STATE_OFFLINE("offline"), // 上行
CONFIG_GET("get"), // 上行 TODO 芋艿讨论暂时没有上行的场景
CONFIG_SET("set"), // 下行
SERVICE_INVOKE("${identifier}"), // 下行
SERVICE_REPLY_SUFFIX("_reply"), // 芋艿TODO 芋艿讨论上行 or 下行
OTA_UPGRADE("upgrade"), // 下行
OTA_PULL("pull"), // 上行
OTA_PROGRESS("progress"), // 上行
OTA_REPORT("report"), // 上行
REGISTER_REGISTER("register"), // 上行
REGISTER_REGISTER_SUB("register_sub"), // 上行
REGISTER_UNREGISTER_SUB("unregister_sub"), // 下行
TOPOLOGY_ADD("topology_add"), // 下行;
;
/**
* 标志符
*/
private final String identifier;
}

View File

@ -0,0 +1,37 @@
package cn.iocoder.yudao.module.iot.common.enums;
import cn.iocoder.yudao.framework.common.core.ArrayValuable;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.util.Arrays;
/**
* IoT 设备消息类型枚举
*/
@Getter
@RequiredArgsConstructor
public enum IotDeviceMessageTypeEnum implements ArrayValuable<String> {
STATE("state"), // 设备状态
PROPERTY("property"), // 设备属性可参考 https://help.aliyun.com/zh/iot/user-guide/device-properties-events-and-services 设备属性事件服务
EVENT("event"), // 设备事件可参考 https://help.aliyun.com/zh/iot/user-guide/device-properties-events-and-services 设备属性事件服务
SERVICE("service"), // 设备服务可参考 https://help.aliyun.com/zh/iot/user-guide/device-properties-events-and-services 设备属性事件服务
CONFIG("config"), // 设备配置可参考 https://help.aliyun.com/zh/iot/user-guide/remote-configuration-1 远程配置
OTA("ota"), // 设备 OTA可参考 https://help.aliyun.com/zh/iot/user-guide/ota-update OTA 升级
REGISTER("register"), // 设备注册可参考 https://help.aliyun.com/zh/iot/user-guide/register-devices 设备身份注册
TOPOLOGY("topology"),; // 设备拓扑可参考 https://help.aliyun.com/zh/iot/user-guide/manage-topological-relationships 设备拓扑
public static final String[] ARRAYS = Arrays.stream(values()).map(IotDeviceMessageTypeEnum::getType).toArray(String[]::new);
/**
* 属性
*/
private final String type;
@Override
public String[] array() {
return ARRAYS;
}
}

View File

@ -0,0 +1,77 @@
package cn.iocoder.yudao.module.iot.common.message;
import cn.iocoder.yudao.module.iot.common.enums.IotDeviceMessageIdentifierEnum;
import cn.iocoder.yudao.module.iot.common.enums.IotDeviceMessageTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
// TODO @芋艿参考阿里云的物模型优化 IoT 上下行消息的设计尽量保持一致渐进式不要一口气
/**
* IoT 设备消息
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class IotDeviceMessage {
/**
* 请求编号
*/
private String requestId;
/**
* 设备信息
*/
private String productKey;
/**
* 设备名称
*/
private String deviceName;
/**
* 设备标识
*/
private String deviceKey;
/**
* 消息类型
*
* 枚举 {@link IotDeviceMessageTypeEnum}
*/
private String type;
/**
* 标识符
*
* 枚举 {@link IotDeviceMessageIdentifierEnum}
*/
private String identifier;
/**
* 请求参数
*
* 例如说属性上报的 properties事件上报的 params
*/
private Object data;
/**
* 响应码
*
* 目前只有 server 下行消息给 device 设备时才会有响应码
*/
private Integer code;
/**
* 上报时间
*/
private LocalDateTime reportTime;
/**
* 租户编号
*/
private Long tenantId;
}

View File

@ -0,0 +1,19 @@
<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>yudao-module-iot</artifactId>
<groupId>cn.iocoder.boot</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>yudao-module-iot-gateway</artifactId>
<name>${project.artifactId}</name>
<description>
iot 模块下,设备网关:
① 功能一接收来自设备的消息并进行解码decode发送到消息网关提供给 iot-biz 进行处理
② 功能二:接收来自消息网关的消息(由 iot-biz 发送并进行编码encode发送给设备
</description>
</project>

View File

@ -0,0 +1 @@
package cn.iocoder.yudao.module.iot.gateway.codec.alink;

View File

@ -0,0 +1 @@
package cn.iocoder.yudao.module.iot.gateway.codec.modbus;

View File

@ -0,0 +1 @@
package cn.iocoder.yudao.module.iot.gateway.codec;

View File

@ -0,0 +1 @@
package cn.iocoder.yudao.module.iot.gateway;

View File

@ -0,0 +1 @@
package cn.iocoder.yudao.module.iot.gateway.protocol.http;

View File

@ -0,0 +1 @@
package cn.iocoder.yudao.module.iot.gateway.protocol.mqtt;

View File

@ -0,0 +1,4 @@
/**
* TODO 占位
*/
package cn.iocoder.yudao.module.iot.gateway.protocol;

View File

@ -0,0 +1 @@
package cn.iocoder.yudao.module.iot.gateway.protocol.tcp;

View File

@ -15,7 +15,7 @@
<name>${project.artifactId}</name>
<description>
物联网协议模块,提供 topic 解析、协议转换等功能
作为 yudao-module-iot-biz 和 yudao-module-iot-gateway-server 的共享包
作为 iot-biz 和 iot-gateway 的共享包
</description>
<dependencies>