feat:【IoT 物联网】增加 iot-common 和 iot-gateway 包
This commit is contained in:
parent
70a0df54e4
commit
6cf2eb07d7
|
@ -12,6 +12,7 @@
|
||||||
<module>yudao-module-iot-net-components</module>
|
<module>yudao-module-iot-net-components</module>
|
||||||
<module>yudao-module-iot-protocol</module>
|
<module>yudao-module-iot-protocol</module>
|
||||||
<module>yudao-module-iot-core</module>
|
<module>yudao-module-iot-core</module>
|
||||||
|
<module>yudao-module-iot-gateway</module>
|
||||||
</modules>
|
</modules>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
<version>${revision}</version>
|
<version>${revision}</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modules>
|
<modules>
|
||||||
|
<module>yudao-module-iot-common</module>
|
||||||
<module>yudao-module-iot-message-bus</module>
|
<module>yudao-module-iot-message-bus</module>
|
||||||
</modules>
|
</modules>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -17,7 +18,7 @@
|
||||||
|
|
||||||
<name>${project.artifactId}</name>
|
<name>${project.artifactId}</name>
|
||||||
<description>
|
<description>
|
||||||
iot 模块下,提供 biz 和 gateway-server 模块的核心功能。
|
iot 模块下,提供 iot-biz 和 iot-gateway 模块的核心功能。
|
||||||
例如说:消息总线、消息协议(编解码)等。
|
例如说:消息总线、消息协议(编解码)等。
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
|
|
|
@ -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>
|
|
@ -0,0 +1,5 @@
|
||||||
|
package cn.iocoder.yudao.module.iot.common.biz;
|
||||||
|
|
||||||
|
// TODO @芋艿:待实现
|
||||||
|
public interface IotDeviceCommonApi {
|
||||||
|
}
|
|
@ -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";
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
}
|
|
@ -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>
|
|
@ -0,0 +1 @@
|
||||||
|
package cn.iocoder.yudao.module.iot.gateway.codec.alink;
|
|
@ -0,0 +1 @@
|
||||||
|
package cn.iocoder.yudao.module.iot.gateway.codec.modbus;
|
|
@ -0,0 +1 @@
|
||||||
|
package cn.iocoder.yudao.module.iot.gateway.codec;
|
|
@ -0,0 +1 @@
|
||||||
|
package cn.iocoder.yudao.module.iot.gateway;
|
|
@ -0,0 +1 @@
|
||||||
|
package cn.iocoder.yudao.module.iot.gateway.protocol.http;
|
|
@ -0,0 +1 @@
|
||||||
|
package cn.iocoder.yudao.module.iot.gateway.protocol.mqtt;
|
|
@ -0,0 +1,4 @@
|
||||||
|
/**
|
||||||
|
* TODO 占位
|
||||||
|
*/
|
||||||
|
package cn.iocoder.yudao.module.iot.gateway.protocol;
|
|
@ -0,0 +1 @@
|
||||||
|
package cn.iocoder.yudao.module.iot.gateway.protocol.tcp;
|
|
@ -15,7 +15,7 @@
|
||||||
<name>${project.artifactId}</name>
|
<name>${project.artifactId}</name>
|
||||||
<description>
|
<description>
|
||||||
物联网协议模块,提供 topic 解析、协议转换等功能
|
物联网协议模块,提供 topic 解析、协议转换等功能
|
||||||
作为 yudao-module-iot-biz 和 yudao-module-iot-gateway-server 的共享包
|
作为 iot-biz 和 iot-gateway 的共享包
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -68,4 +68,4 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
Loading…
Reference in New Issue