Commit fe8044c8a1fc5695c2d3fcf0bd58b98052b1d29c

Authored by YunaiV
1 parent 9031c068

feat(iot):Modbus 支持 Master/Slave 双模式,配置表单和详情按协议类型区分展示

Showing 34 changed files with 270 additions and 260 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/device/IotDeviceModbusPointDO.java
... ... @@ -30,12 +30,6 @@ public class IotDeviceModbusPointDO extends TenantBaseDO {
30 30 @TableId
31 31 private Long id;
32 32 /**
33   - * 产品编号
34   - *
35   - * 关联 {@link cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO#getId()}
36   - */
37   - private Long productId;
38   - /**
39 33 * 设备编号
40 34 *
41 35 * 关联 {@link IotDeviceDO#getId()}
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/IotDeviceModbusConfigServiceImpl.java
... ... @@ -75,14 +75,14 @@ public class IotDeviceModbusConfigServiceImpl implements IotDeviceModbusConfigSe
75 75 if (protocolTypeEnum == null) {
76 76 return;
77 77 }
78   - if (protocolTypeEnum == IotProtocolTypeEnum.MODBUS_TCP_MASTER) {
79   - Assert.isTrue(StrUtil.isNotEmpty(saveReqVO.getIp()), "Master 模式下,IP 地址不能为空");
80   - Assert.notNull(saveReqVO.getPort(), "Master 模式下,端口不能为空");
81   - Assert.notNull(saveReqVO.getTimeout(), "Master 模式下,连接超时时间不能为空");
82   - Assert.notNull(saveReqVO.getRetryInterval(), "Master 模式下,重试间隔不能为空");
83   - } else if (protocolTypeEnum == IotProtocolTypeEnum.MODBUS_TCP_SLAVE) {
84   - Assert.notNull(saveReqVO.getMode(), "Slave 模式下,工作模式不能为空");
85   - Assert.notNull(saveReqVO.getFrameFormat(), "Slave 模式下,数据帧格式不能为空");
  78 + if (protocolTypeEnum == IotProtocolTypeEnum.MODBUS_TCP_CLIENT) {
  79 + Assert.isTrue(StrUtil.isNotEmpty(saveReqVO.getIp()), "Client 模式下,IP 地址不能为空");
  80 + Assert.notNull(saveReqVO.getPort(), "Client 模式下,端口不能为空");
  81 + Assert.notNull(saveReqVO.getTimeout(), "Client 模式下,连接超时时间不能为空");
  82 + Assert.notNull(saveReqVO.getRetryInterval(), "Client 模式下,重试间隔不能为空");
  83 + } else if (protocolTypeEnum == IotProtocolTypeEnum.MODBUS_TCP_SERVER) {
  84 + Assert.notNull(saveReqVO.getMode(), "Server 模式下,工作模式不能为空");
  85 + Assert.notNull(saveReqVO.getFrameFormat(), "Server 模式下,数据帧格式不能为空");
86 86 }
87 87 }
88 88  
... ...
yudao-module-iot/yudao-module-iot-core/src/main/java/cn/iocoder/yudao/module/iot/core/enums/IotProtocolTypeEnum.java
... ... @@ -25,8 +25,8 @@ public enum IotProtocolTypeEnum implements ArrayValuable<String> {
25 25 MQTT("mqtt"),
26 26 EMQX("emqx"),
27 27 COAP("coap"),
28   - MODBUS_TCP_MASTER("modbus_tcp_master"),
29   - MODBUS_TCP_SLAVE("modbus_tcp_slave");
  28 + MODBUS_TCP_CLIENT("modbus_tcp_client"),
  29 + MODBUS_TCP_SERVER("modbus_tcp_server");
30 30  
31 31 public static final String[] ARRAYS = Arrays.stream(values()).map(IotProtocolTypeEnum::getType).toArray(String[]::new);
32 32  
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/config/IotGatewayProperties.java
... ... @@ -4,8 +4,8 @@ import cn.iocoder.yudao.module.iot.core.enums.IotProtocolTypeEnum;
4 4 import cn.iocoder.yudao.module.iot.gateway.protocol.coap.IotCoapConfig;
5 5 import cn.iocoder.yudao.module.iot.gateway.protocol.emqx.IotEmqxConfig;
6 6 import cn.iocoder.yudao.module.iot.gateway.protocol.http.IotHttpConfig;
7   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster.IotModbusTcpMasterConfig;
8   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.IotModbusTcpSlaveConfig;
  7 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient.IotModbusTcpClientConfig;
  8 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.IotModbusTcpServerConfig;
9 9 import cn.iocoder.yudao.module.iot.gateway.protocol.mqtt.IotMqttConfig;
10 10 import cn.iocoder.yudao.module.iot.gateway.protocol.tcp.IotTcpConfig;
11 11 import cn.iocoder.yudao.module.iot.gateway.protocol.udp.IotUdpConfig;
... ... @@ -169,16 +169,16 @@ public class IotGatewayProperties {
169 169 private IotEmqxConfig emqx;
170 170  
171 171 /**
172   - * Modbus TCP Master 协议配置
  172 + * Modbus TCP Client 协议配置
173 173 */
174 174 @Valid
175   - private IotModbusTcpMasterConfig modbusTcpMaster;
  175 + private IotModbusTcpClientConfig modbusTcpClient;
176 176  
177 177 /**
178   - * Modbus TCP Slave 协议配置
  178 + * Modbus TCP Server 协议配置
179 179 */
180 180 @Valid
181   - private IotModbusTcpSlaveConfig modbusTcpSlave;
  181 + private IotModbusTcpServerConfig modbusTcpServer;
182 182  
183 183 }
184 184  
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/IotProtocolManager.java
... ... @@ -7,8 +7,8 @@ import cn.iocoder.yudao.module.iot.gateway.config.IotGatewayProperties;
7 7 import cn.iocoder.yudao.module.iot.gateway.protocol.coap.IotCoapProtocol;
8 8 import cn.iocoder.yudao.module.iot.gateway.protocol.emqx.IotEmqxProtocol;
9 9 import cn.iocoder.yudao.module.iot.gateway.protocol.http.IotHttpProtocol;
10   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster.IotModbusTcpMasterProtocol;
11   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.IotModbusTcpSlaveProtocol;
  10 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient.IotModbusTcpClientProtocol;
  11 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.IotModbusTcpServerProtocol;
12 12 import cn.iocoder.yudao.module.iot.gateway.protocol.mqtt.IotMqttProtocol;
13 13 import cn.iocoder.yudao.module.iot.gateway.protocol.tcp.IotTcpProtocol;
14 14 import cn.iocoder.yudao.module.iot.gateway.protocol.udp.IotUdpProtocol;
... ... @@ -114,10 +114,10 @@ public class IotProtocolManager implements SmartLifecycle {
114 114 return createMqttProtocol(config);
115 115 case EMQX:
116 116 return createEmqxProtocol(config);
117   - case MODBUS_TCP_MASTER:
118   - return createModbusTcpMasterProtocol(config);
119   - case MODBUS_TCP_SLAVE:
120   - return createModbusTcpSlaveProtocol(config);
  117 + case MODBUS_TCP_CLIENT:
  118 + return createModbusTcpClientProtocol(config);
  119 + case MODBUS_TCP_SERVER:
  120 + return createModbusTcpServerProtocol(config);
121 121 default:
122 122 throw new IllegalArgumentException(String.format(
123 123 "[createProtocol][协议实例 %s 的协议类型 %s 暂不支持]", config.getId(), protocolType));
... ... @@ -195,23 +195,23 @@ public class IotProtocolManager implements SmartLifecycle {
195 195 }
196 196  
197 197 /**
198   - * 创建 Modbus TCP Master 协议实例
  198 + * 创建 Modbus TCP Client 协议实例
199 199 *
200 200 * @param config 协议实例配置
201   - * @return Modbus TCP Master 协议实例
  201 + * @return Modbus TCP Client 协议实例
202 202 */
203   - private IotModbusTcpMasterProtocol createModbusTcpMasterProtocol(IotGatewayProperties.ProtocolProperties config) {
204   - return new IotModbusTcpMasterProtocol(config);
  203 + private IotModbusTcpClientProtocol createModbusTcpClientProtocol(IotGatewayProperties.ProtocolProperties config) {
  204 + return new IotModbusTcpClientProtocol(config);
205 205 }
206 206  
207 207 /**
208   - * 创建 Modbus TCP Slave 协议实例
  208 + * 创建 Modbus TCP Server 协议实例
209 209 *
210 210 * @param config 协议实例配置
211   - * @return Modbus TCP Slave 协议实例
  211 + * @return Modbus TCP Server 协议实例
212 212 */
213   - private IotModbusTcpSlaveProtocol createModbusTcpSlaveProtocol(IotGatewayProperties.ProtocolProperties config) {
214   - return new IotModbusTcpSlaveProtocol(config);
  213 + private IotModbusTcpServerProtocol createModbusTcpServerProtocol(IotGatewayProperties.ProtocolProperties config) {
  214 + return new IotModbusTcpServerProtocol(config);
215 215 }
216 216  
217 217 }
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/common/utils/IotModbusCommonUtils.java
... ... @@ -9,7 +9,7 @@ import cn.iocoder.yudao.module.iot.core.biz.dto.IotModbusDeviceConfigRespDTO;
9 9 import cn.iocoder.yudao.module.iot.core.biz.dto.IotModbusPointRespDTO;
10 10 import cn.iocoder.yudao.module.iot.core.enums.modbus.IotModbusByteOrderEnum;
11 11 import cn.iocoder.yudao.module.iot.core.enums.modbus.IotModbusRawDataTypeEnum;
12   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.codec.IotModbusFrame;
  12 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.codec.IotModbusFrame;
13 13 import lombok.experimental.UtilityClass;
14 14 import lombok.extern.slf4j.Slf4j;
15 15  
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/common/utils/IotModbusTcpMasterUtils.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/common/utils/IotModbusTcpClientUtils.java
1 1 package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.common.utils;
2 2  
3 3 import cn.iocoder.yudao.module.iot.core.biz.dto.IotModbusPointRespDTO;
4   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster.manager.IotModbusTcpMasterConnectionManager;
  4 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient.manager.IotModbusTcpClientConnectionManager;
5 5 import com.ghgande.j2mod.modbus.io.ModbusTCPTransaction;
6 6 import com.ghgande.j2mod.modbus.msg.*;
7 7 import com.ghgande.j2mod.modbus.procimg.InputRegister;
... ... @@ -19,14 +19,14 @@ import static cn.iocoder.yudao.module.iot.gateway.protocol.modbus.common.utils.I
19 19 * <p>
20 20 * 封装基于 j2mod 的 Modbus TCP 读写操作:
21 21 * 1. 根据功能码创建对应的 Modbus 读/写请求
22   - * 2. 通过 {@link IotModbusTcpMasterConnectionManager.ModbusConnection} 执行事务
  22 + * 2. 通过 {@link IotModbusTcpClientConnectionManager.ModbusConnection} 执行事务
23 23 * 3. 从响应中提取原始值
24 24 *
25 25 * @author 芋道源码
26 26 */
27 27 @UtilityClass
28 28 @Slf4j
29   -public class IotModbusTcpMasterUtils {
  29 +public class IotModbusTcpClientUtils {
30 30  
31 31 /**
32 32 * 读取 Modbus 数据
... ... @@ -36,7 +36,7 @@ public class IotModbusTcpMasterUtils {
36 36 * @param point 点位配置
37 37 * @return 原始值(int 数组)
38 38 */
39   - public static Future<int[]> read(IotModbusTcpMasterConnectionManager.ModbusConnection connection,
  39 + public static Future<int[]> read(IotModbusTcpClientConnectionManager.ModbusConnection connection,
40 40 Integer slaveId,
41 41 IotModbusPointRespDTO point) {
42 42 return connection.executeBlocking(tcpConnection -> {
... ... @@ -70,7 +70,7 @@ public class IotModbusTcpMasterUtils {
70 70 * @param values 要写入的值
71 71 * @return 是否成功
72 72 */
73   - public static Future<Boolean> write(IotModbusTcpMasterConnectionManager.ModbusConnection connection,
  73 + public static Future<Boolean> write(IotModbusTcpClientConnectionManager.ModbusConnection connection,
74 74 Integer slaveId,
75 75 IotModbusPointRespDTO point,
76 76 int[] values) {
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpmaster/IotModbusTcpMasterConfig.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpclient/IotModbusTcpClientConfig.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient;
2 2  
3 3 import jakarta.validation.constraints.Min;
4 4 import jakarta.validation.constraints.NotNull;
5 5 import lombok.Data;
6 6  
7 7 /**
8   - * IoT Modbus TCP Master 协议配置
  8 + * IoT Modbus TCP Client 协议配置
9 9 *
10 10 * @author 芋道源码
11 11 */
12 12 @Data
13   -public class IotModbusTcpMasterConfig {
  13 +public class IotModbusTcpClientConfig {
14 14  
15 15 /**
16 16 * 配置刷新间隔(秒)
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpmaster/IotModbusTcpMasterProtocol.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpclient/IotModbusTcpClientProtocol.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient;
2 2  
3 3 import cn.hutool.core.lang.Assert;
4 4 import cn.hutool.extra.spring.SpringUtil;
... ... @@ -9,12 +9,12 @@ import cn.iocoder.yudao.module.iot.core.messagebus.core.IotMessageBus;
9 9 import cn.iocoder.yudao.module.iot.core.util.IotDeviceMessageUtils;
10 10 import cn.iocoder.yudao.module.iot.gateway.config.IotGatewayProperties.ProtocolProperties;
11 11 import cn.iocoder.yudao.module.iot.gateway.protocol.IotProtocol;
12   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster.handler.downstream.IotModbusTcpMasterDownstreamHandler;
13   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster.handler.downstream.IotModbusTcpMasterDownstreamSubscriber;
14   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster.handler.upstream.IotModbusTcpMasterUpstreamHandler;
15   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster.manager.IotModbusTcpMasterConfigCacheService;
16   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster.manager.IotModbusTcpMasterConnectionManager;
17   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster.manager.IotModbusTcpMasterPollScheduler;
  12 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient.handler.downstream.IotModbusTcpClientDownstreamHandler;
  13 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient.handler.downstream.IotModbusTcpClientDownstreamSubscriber;
  14 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient.handler.upstream.IotModbusTcpClientUpstreamHandler;
  15 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient.manager.IotModbusTcpClientConfigCacheService;
  16 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient.manager.IotModbusTcpClientConnectionManager;
  17 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient.manager.IotModbusTcpClientPollScheduler;
18 18 import cn.iocoder.yudao.module.iot.gateway.service.device.message.IotDeviceMessageService;
19 19 import io.vertx.core.Vertx;
20 20 import lombok.Getter;
... ... @@ -26,12 +26,12 @@ import java.util.Set;
26 26 import java.util.concurrent.TimeUnit;
27 27  
28 28 /**
29   - * IoT 网关 Modbus TCP Master 协议:主动轮询 Modbus 从站设备数据
  29 + * IoT 网关 Modbus TCP Client 协议:主动轮询 Modbus 从站设备数据
30 30 *
31 31 * @author 芋道源码
32 32 */
33 33 @Slf4j
34   -public class IotModbusTcpMasterProtocol implements IotProtocol {
  34 +public class IotModbusTcpClientProtocol implements IotProtocol {
35 35  
36 36 /**
37 37 * 协议配置
... ... @@ -61,18 +61,18 @@ public class IotModbusTcpMasterProtocol implements IotProtocol {
61 61 /**
62 62 * 连接管理器
63 63 */
64   - private final IotModbusTcpMasterConnectionManager connectionManager;
  64 + private final IotModbusTcpClientConnectionManager connectionManager;
65 65 /**
66 66 * 下行消息订阅者
67 67 */
68   - private IotModbusTcpMasterDownstreamSubscriber downstreamSubscriber;
  68 + private IotModbusTcpClientDownstreamSubscriber downstreamSubscriber;
69 69  
70   - private final IotModbusTcpMasterConfigCacheService configCacheService;
71   - private final IotModbusTcpMasterPollScheduler pollScheduler;
  70 + private final IotModbusTcpClientConfigCacheService configCacheService;
  71 + private final IotModbusTcpClientPollScheduler pollScheduler;
72 72  
73   - public IotModbusTcpMasterProtocol(ProtocolProperties properties) {
74   - IotModbusTcpMasterConfig modbusTcpMasterConfig = properties.getModbusTcpMaster();
75   - Assert.notNull(modbusTcpMasterConfig, "Modbus TCP Master 协议配置(modbusTcpMaster)不能为空");
  73 + public IotModbusTcpClientProtocol(ProtocolProperties properties) {
  74 + IotModbusTcpClientConfig modbusTcpClientConfig = properties.getModbusTcpClient();
  75 + Assert.notNull(modbusTcpClientConfig, "Modbus TCP Client 协议配置(modbusTcpClient)不能为空");
76 76 this.properties = properties;
77 77 this.serverId = IotDeviceMessageUtils.generateServerId(properties.getPort());
78 78  
... ... @@ -83,15 +83,15 @@ public class IotModbusTcpMasterProtocol implements IotProtocol {
83 83 RedissonClient redissonClient = SpringUtil.getBean(RedissonClient.class);
84 84 IotDeviceCommonApi deviceApi = SpringUtil.getBean(IotDeviceCommonApi.class);
85 85 IotDeviceMessageService messageService = SpringUtil.getBean(IotDeviceMessageService.class);
86   - this.configCacheService = new IotModbusTcpMasterConfigCacheService(deviceApi);
87   - this.connectionManager = new IotModbusTcpMasterConnectionManager(redissonClient, vertx,
  86 + this.configCacheService = new IotModbusTcpClientConfigCacheService(deviceApi);
  87 + this.connectionManager = new IotModbusTcpClientConnectionManager(redissonClient, vertx,
88 88 messageService, configCacheService, serverId);
89 89  
90 90 // 初始化 Handler
91   - IotModbusTcpMasterUpstreamHandler upstreamHandler = new IotModbusTcpMasterUpstreamHandler(messageService, serverId);
  91 + IotModbusTcpClientUpstreamHandler upstreamHandler = new IotModbusTcpClientUpstreamHandler(messageService, serverId);
92 92  
93 93 // 初始化轮询调度器
94   - this.pollScheduler = new IotModbusTcpMasterPollScheduler(vertx, connectionManager, upstreamHandler, configCacheService);
  94 + this.pollScheduler = new IotModbusTcpClientPollScheduler(vertx, connectionManager, upstreamHandler, configCacheService);
95 95 }
96 96  
97 97 @Override
... ... @@ -101,13 +101,13 @@ public class IotModbusTcpMasterProtocol implements IotProtocol {
101 101  
102 102 @Override
103 103 public IotProtocolTypeEnum getType() {
104   - return IotProtocolTypeEnum.MODBUS_TCP_MASTER;
  104 + return IotProtocolTypeEnum.MODBUS_TCP_CLIENT;
105 105 }
106 106  
107 107 @Override
108 108 public void start() {
109 109 if (running) {
110   - log.warn("[start][IoT Modbus TCP Master 协议 {} 已经在运行中]", getId());
  110 + log.warn("[start][IoT Modbus TCP Client 协议 {} 已经在运行中]", getId());
111 111 return;
112 112 }
113 113  
... ... @@ -115,22 +115,22 @@ public class IotModbusTcpMasterProtocol implements IotProtocol {
115 115 // 1.1 首次加载配置
116 116 refreshConfig();
117 117 // 1.2 启动配置刷新定时器
118   - int refreshInterval = properties.getModbusTcpMaster().getConfigRefreshInterval();
  118 + int refreshInterval = properties.getModbusTcpClient().getConfigRefreshInterval();
119 119 configRefreshTimerId = vertx.setPeriodic(
120 120 TimeUnit.SECONDS.toMillis(refreshInterval),
121 121 id -> refreshConfig()
122 122 );
123 123 running = true;
124   - log.info("[start][IoT Modbus TCP Master 协议 {} 启动成功,serverId={}]", getId(), serverId);
  124 + log.info("[start][IoT Modbus TCP Client 协议 {} 启动成功,serverId={}]", getId(), serverId);
125 125  
126 126 // 2. 启动下行消息订阅者
127 127 IotMessageBus messageBus = SpringUtil.getBean(IotMessageBus.class);
128   - IotModbusTcpMasterDownstreamHandler downstreamHandler = new IotModbusTcpMasterDownstreamHandler(connectionManager,
  128 + IotModbusTcpClientDownstreamHandler downstreamHandler = new IotModbusTcpClientDownstreamHandler(connectionManager,
129 129 configCacheService);
130   - this.downstreamSubscriber = new IotModbusTcpMasterDownstreamSubscriber(this, downstreamHandler, messageBus);
  130 + this.downstreamSubscriber = new IotModbusTcpClientDownstreamSubscriber(this, downstreamHandler, messageBus);
131 131 this.downstreamSubscriber.start();
132 132 } catch (Exception e) {
133   - log.error("[start][IoT Modbus TCP Master 协议 {} 启动失败]", getId(), e);
  133 + log.error("[start][IoT Modbus TCP Client 协议 {} 启动失败]", getId(), e);
134 134 stop0();
135 135 throw e;
136 136 }
... ... @@ -149,9 +149,9 @@ public class IotModbusTcpMasterProtocol implements IotProtocol {
149 149 if (downstreamSubscriber != null) {
150 150 try {
151 151 downstreamSubscriber.stop();
152   - log.info("[stop][IoT Modbus TCP Master 协议 {} 下行消息订阅者已停止]", getId());
  152 + log.info("[stop][IoT Modbus TCP Client 协议 {} 下行消息订阅者已停止]", getId());
153 153 } catch (Exception e) {
154   - log.error("[stop][IoT Modbus TCP Master 协议 {} 下行消息订阅者停止失败]", getId(), e);
  154 + log.error("[stop][IoT Modbus TCP Client 协议 {} 下行消息订阅者停止失败]", getId(), e);
155 155 }
156 156 downstreamSubscriber = null;
157 157 }
... ... @@ -170,13 +170,13 @@ public class IotModbusTcpMasterProtocol implements IotProtocol {
170 170 if (vertx != null) {
171 171 try {
172 172 vertx.close().result();
173   - log.info("[stop][IoT Modbus TCP Master 协议 {} Vertx 已关闭]", getId());
  173 + log.info("[stop][IoT Modbus TCP Client 协议 {} Vertx 已关闭]", getId());
174 174 } catch (Exception e) {
175   - log.error("[stop][IoT Modbus TCP Master 协议 {} Vertx 关闭失败]", getId(), e);
  175 + log.error("[stop][IoT Modbus TCP Client 协议 {} Vertx 关闭失败]", getId(), e);
176 176 }
177 177 }
178 178 running = false;
179   - log.info("[stop][IoT Modbus TCP Master 协议 {} 已停止]", getId());
  179 + log.info("[stop][IoT Modbus TCP Client 协议 {} 已停止]", getId());
180 180 }
181 181  
182 182 /**
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpmaster/handler/downstream/IotModbusTcpMasterDownstreamHandler.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpclient/handler/downstream/IotModbusTcpClientDownstreamHandler.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster.handler.downstream;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient.handler.downstream;
2 2  
3 3 import cn.hutool.core.util.ObjUtil;
4 4 import cn.iocoder.yudao.module.iot.core.biz.dto.IotModbusDeviceConfigRespDTO;
... ... @@ -6,16 +6,16 @@ import cn.iocoder.yudao.module.iot.core.biz.dto.IotModbusPointRespDTO;
6 6 import cn.iocoder.yudao.module.iot.core.enums.IotDeviceMessageMethodEnum;
7 7 import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
8 8 import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.common.utils.IotModbusCommonUtils;
9   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.common.utils.IotModbusTcpMasterUtils;
10   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster.manager.IotModbusTcpMasterConfigCacheService;
11   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster.manager.IotModbusTcpMasterConnectionManager;
  9 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.common.utils.IotModbusTcpClientUtils;
  10 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient.manager.IotModbusTcpClientConfigCacheService;
  11 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient.manager.IotModbusTcpClientConnectionManager;
12 12 import lombok.RequiredArgsConstructor;
13 13 import lombok.extern.slf4j.Slf4j;
14 14  
15 15 import java.util.Map;
16 16  
17 17 /**
18   - * IoT Modbus TCP Master 下行消息处理器
  18 + * IoT Modbus TCP Client 下行消息处理器
19 19 * <p>
20 20 * 负责:
21 21 * 1. 处理下行消息(如属性设置 thing.service.property.set)
... ... @@ -25,10 +25,10 @@ import java.util.Map;
25 25 */
26 26 @RequiredArgsConstructor
27 27 @Slf4j
28   -public class IotModbusTcpMasterDownstreamHandler {
  28 +public class IotModbusTcpClientDownstreamHandler {
29 29  
30   - private final IotModbusTcpMasterConnectionManager connectionManager;
31   - private final IotModbusTcpMasterConfigCacheService configCacheService;
  30 + private final IotModbusTcpClientConnectionManager connectionManager;
  31 + private final IotModbusTcpClientConfigCacheService configCacheService;
32 32  
33 33 /**
34 34 * 处理下行消息
... ... @@ -36,8 +36,11 @@ public class IotModbusTcpMasterDownstreamHandler {
36 36 @SuppressWarnings({"unchecked", "DuplicatedCode"})
37 37 public void handle(IotDeviceMessage message) {
38 38 // 1.1 检查是否是属性设置消息
  39 + if (ObjUtil.equals(IotDeviceMessageMethodEnum.PROPERTY_POST.getMethod(), message.getMethod())) {
  40 + return;
  41 + }
39 42 if (ObjUtil.notEqual(IotDeviceMessageMethodEnum.PROPERTY_SET.getMethod(), message.getMethod())) {
40   - log.debug("[handle][忽略非属性设置消息: {}]", message.getMethod());
  43 + log.warn("[handle][忽略非属性设置消息: {}]", message.getMethod());
41 44 return;
42 45 }
43 46 // 1.2 获取设备配置
... ... @@ -79,7 +82,7 @@ public class IotModbusTcpMasterDownstreamHandler {
79 82 */
80 83 private void writeProperty(IotModbusDeviceConfigRespDTO config, IotModbusPointRespDTO point, Object value) {
81 84 // 1.1 获取连接
82   - IotModbusTcpMasterConnectionManager.ModbusConnection connection = connectionManager.getConnection(config.getDeviceId());
  85 + IotModbusTcpClientConnectionManager.ModbusConnection connection = connectionManager.getConnection(config.getDeviceId());
83 86 if (connection == null) {
84 87 log.warn("[writeProperty][设备 {} 没有连接]", config.getDeviceId());
85 88 return;
... ... @@ -94,7 +97,7 @@ public class IotModbusTcpMasterDownstreamHandler {
94 97 // 2.1 转换属性值为原始值
95 98 int[] rawValues = IotModbusCommonUtils.convertToRawValues(value, point);
96 99 // 2.2 执行 Modbus 写入
97   - IotModbusTcpMasterUtils.write(connection, slaveId, point, rawValues)
  100 + IotModbusTcpClientUtils.write(connection, slaveId, point, rawValues)
98 101 .onSuccess(success -> log.info("[writeProperty][写入成功, deviceId={}, identifier={}, value={}]",
99 102 config.getDeviceId(), point.getIdentifier(), value))
100 103 .onFailure(e -> log.error("[writeProperty][写入失败, deviceId={}, identifier={}]",
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpmaster/handler/downstream/IotModbusTcpMasterDownstreamSubscriber.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpclient/handler/downstream/IotModbusTcpClientDownstreamSubscriber.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster.handler.downstream;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient.handler.downstream;
2 2  
3 3 import cn.iocoder.yudao.module.iot.core.messagebus.core.IotMessageBus;
4 4 import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
5 5 import cn.iocoder.yudao.module.iot.gateway.protocol.AbstractIotProtocolDownstreamSubscriber;
6   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster.IotModbusTcpMasterProtocol;
  6 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient.IotModbusTcpClientProtocol;
7 7 import lombok.extern.slf4j.Slf4j;
8 8  
9 9 /**
... ... @@ -12,12 +12,12 @@ import lombok.extern.slf4j.Slf4j;
12 12 * @author 芋道源码
13 13 */
14 14 @Slf4j
15   -public class IotModbusTcpMasterDownstreamSubscriber extends AbstractIotProtocolDownstreamSubscriber {
  15 +public class IotModbusTcpClientDownstreamSubscriber extends AbstractIotProtocolDownstreamSubscriber {
16 16  
17   - private final IotModbusTcpMasterDownstreamHandler downstreamHandler;
  17 + private final IotModbusTcpClientDownstreamHandler downstreamHandler;
18 18  
19   - public IotModbusTcpMasterDownstreamSubscriber(IotModbusTcpMasterProtocol protocol,
20   - IotModbusTcpMasterDownstreamHandler downstreamHandler,
  19 + public IotModbusTcpClientDownstreamSubscriber(IotModbusTcpClientProtocol protocol,
  20 + IotModbusTcpClientDownstreamHandler downstreamHandler,
21 21 IotMessageBus messageBus) {
22 22 super(protocol, messageBus);
23 23 this.downstreamHandler = downstreamHandler;
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpmaster/handler/upstream/IotModbusTcpMasterUpstreamHandler.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpclient/handler/upstream/IotModbusTcpClientUpstreamHandler.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster.handler.upstream;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient.handler.upstream;
2 2  
3 3 import cn.hutool.core.map.MapUtil;
4 4 import cn.iocoder.yudao.module.iot.core.biz.dto.IotModbusDeviceConfigRespDTO;
... ... @@ -17,13 +17,13 @@ import java.util.Map;
17 17 * @author 芋道源码
18 18 */
19 19 @Slf4j
20   -public class IotModbusTcpMasterUpstreamHandler {
  20 +public class IotModbusTcpClientUpstreamHandler {
21 21  
22 22 private final IotDeviceMessageService messageService;
23 23  
24 24 private final String serverId;
25 25  
26   - public IotModbusTcpMasterUpstreamHandler(IotDeviceMessageService messageService,
  26 + public IotModbusTcpClientUpstreamHandler(IotDeviceMessageService messageService,
27 27 String serverId) {
28 28 this.messageService = messageService;
29 29 this.serverId = serverId;
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpmaster/manager/IotModbusTcpMasterConfigCacheService.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpclient/manager/IotModbusTcpClientConfigCacheService.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster.manager;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient.manager;
2 2  
3 3 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
4 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
... ... @@ -19,13 +19,13 @@ import java.util.concurrent.ConcurrentHashMap;
19 19 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
20 20  
21 21 /**
22   - * IoT Modbus TCP Master 配置缓存服务
  22 + * IoT Modbus TCP Client 配置缓存服务
23 23 *
24 24 * @author 芋道源码
25 25 */
26 26 @RequiredArgsConstructor
27 27 @Slf4j
28   -public class IotModbusTcpMasterConfigCacheService {
  28 +public class IotModbusTcpClientConfigCacheService {
29 29  
30 30 private final IotDeviceCommonApi deviceApi;
31 31  
... ... @@ -51,7 +51,7 @@ public class IotModbusTcpMasterConfigCacheService {
51 51 // 1. 从远程获取配置
52 52 CommonResult<List<IotModbusDeviceConfigRespDTO>> result = deviceApi.getModbusDeviceConfigList(
53 53 new IotModbusDeviceConfigListReqDTO().setStatus(CommonStatusEnum.ENABLE.getStatus())
54   - .setMode(IotModbusModeEnum.POLLING.getMode()).setProtocolType(IotProtocolTypeEnum.MODBUS_TCP_MASTER.getType()));
  54 + .setMode(IotModbusModeEnum.POLLING.getMode()).setProtocolType(IotProtocolTypeEnum.MODBUS_TCP_CLIENT.getType()));
55 55 result.checkError();
56 56 List<IotModbusDeviceConfigRespDTO> configs = result.getData();
57 57  
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpmaster/manager/IotModbusTcpMasterConnectionManager.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpclient/manager/IotModbusTcpClientConnectionManager.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster.manager;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient.manager;
2 2  
3 3 import cn.hutool.core.util.ObjUtil;
4 4 import cn.iocoder.yudao.module.iot.core.biz.dto.IotModbusDeviceConfigRespDTO;
... ... @@ -30,14 +30,14 @@ import java.util.concurrent.ConcurrentHashMap;
30 30 * @author 芋道源码
31 31 */
32 32 @Slf4j
33   -public class IotModbusTcpMasterConnectionManager {
  33 +public class IotModbusTcpClientConnectionManager {
34 34  
35 35 private static final String LOCK_KEY_PREFIX = "iot:modbus-tcp:connection:";
36 36  
37 37 private final RedissonClient redissonClient;
38 38 private final Vertx vertx;
39 39 private final IotDeviceMessageService messageService;
40   - private final IotModbusTcpMasterConfigCacheService configCacheService;
  40 + private final IotModbusTcpClientConfigCacheService configCacheService;
41 41 private final String serverId;
42 42  
43 43 /**
... ... @@ -50,9 +50,9 @@ public class IotModbusTcpMasterConnectionManager {
50 50 */
51 51 private final Map<Long, String> deviceConnectionMap = new ConcurrentHashMap<>();
52 52  
53   - public IotModbusTcpMasterConnectionManager(RedissonClient redissonClient, Vertx vertx,
  53 + public IotModbusTcpClientConnectionManager(RedissonClient redissonClient, Vertx vertx,
54 54 IotDeviceMessageService messageService,
55   - IotModbusTcpMasterConfigCacheService configCacheService,
  55 + IotModbusTcpClientConfigCacheService configCacheService,
56 56 String serverId) {
57 57 this.redissonClient = redissonClient;
58 58 this.vertx = vertx;
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpmaster/manager/IotModbusTcpMasterPollScheduler.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpclient/manager/IotModbusTcpClientPollScheduler.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster.manager;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient.manager;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.lang.Assert;
... ... @@ -6,27 +6,27 @@ import cn.iocoder.yudao.module.iot.core.biz.dto.IotModbusDeviceConfigRespDTO;
6 6 import cn.iocoder.yudao.module.iot.core.biz.dto.IotModbusPointRespDTO;
7 7 import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.common.manager.AbstractIotModbusPollScheduler;
8 8 import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.common.utils.IotModbusCommonUtils;
9   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.common.utils.IotModbusTcpMasterUtils;
10   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster.handler.upstream.IotModbusTcpMasterUpstreamHandler;
  9 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.common.utils.IotModbusTcpClientUtils;
  10 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient.handler.upstream.IotModbusTcpClientUpstreamHandler;
11 11 import io.vertx.core.Vertx;
12 12 import lombok.extern.slf4j.Slf4j;
13 13  
14 14 /**
15   - * IoT Modbus TCP Master 轮询调度器:管理点位的轮询定时器,调度读取任务并上报结果
  15 + * IoT Modbus TCP Client 轮询调度器:管理点位的轮询定时器,调度读取任务并上报结果
16 16 *
17 17 * @author 芋道源码
18 18 */
19 19 @Slf4j
20   -public class IotModbusTcpMasterPollScheduler extends AbstractIotModbusPollScheduler {
  20 +public class IotModbusTcpClientPollScheduler extends AbstractIotModbusPollScheduler {
21 21  
22   - private final IotModbusTcpMasterConnectionManager connectionManager;
23   - private final IotModbusTcpMasterUpstreamHandler upstreamHandler;
24   - private final IotModbusTcpMasterConfigCacheService configCacheService;
  22 + private final IotModbusTcpClientConnectionManager connectionManager;
  23 + private final IotModbusTcpClientUpstreamHandler upstreamHandler;
  24 + private final IotModbusTcpClientConfigCacheService configCacheService;
25 25  
26   - public IotModbusTcpMasterPollScheduler(Vertx vertx,
27   - IotModbusTcpMasterConnectionManager connectionManager,
28   - IotModbusTcpMasterUpstreamHandler upstreamHandler,
29   - IotModbusTcpMasterConfigCacheService configCacheService) {
  26 + public IotModbusTcpClientPollScheduler(Vertx vertx,
  27 + IotModbusTcpClientConnectionManager connectionManager,
  28 + IotModbusTcpClientUpstreamHandler upstreamHandler,
  29 + IotModbusTcpClientConfigCacheService configCacheService) {
30 30 super(vertx);
31 31 this.connectionManager = connectionManager;
32 32 this.upstreamHandler = upstreamHandler;
... ... @@ -54,7 +54,7 @@ public class IotModbusTcpMasterPollScheduler extends AbstractIotModbusPollSchedu
54 54 }
55 55  
56 56 // 2.1 获取连接
57   - IotModbusTcpMasterConnectionManager.ModbusConnection connection = connectionManager.getConnection(deviceId);
  57 + IotModbusTcpClientConnectionManager.ModbusConnection connection = connectionManager.getConnection(deviceId);
58 58 if (connection == null) {
59 59 log.warn("[pollPoint][设备 {} 没有连接]", deviceId);
60 60 return;
... ... @@ -64,7 +64,7 @@ public class IotModbusTcpMasterPollScheduler extends AbstractIotModbusPollSchedu
64 64 Assert.notNull(slaveId, "设备 {} 没有配置 slaveId", deviceId);
65 65  
66 66 // 3. 执行 Modbus 读取
67   - IotModbusTcpMasterUtils.read(connection, slaveId, point)
  67 + IotModbusTcpClientUtils.read(connection, slaveId, point)
68 68 .onSuccess(rawValue -> upstreamHandler.handleReadResult(config, point, rawValue))
69 69 .onFailure(e -> log.error("[pollPoint][读取点位失败, deviceId={}, identifier={}]",
70 70 deviceId, point.getIdentifier(), e));
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpmaster/package-info.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpclient/package-info.java
1 1 /**
2   - * Modbus TCP Master(主站)协议:网关主动连接并轮询 Modbus 从站设备
  2 + * Modbus TCP Client(主站)协议:网关主动连接并轮询 Modbus 从站设备
3 3 * <p>
4 4 * 基于 j2mod 实现,支持 FC01-04 读、FC05/06/15/16 写,定时轮询 + 下发属性设置
5 5 */
6   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster;
  6 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient;
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpslave/IotModbusTcpSlaveConfig.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpserver/IotModbusTcpServerConfig.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver;
2 2  
3 3 import jakarta.validation.constraints.Max;
4 4 import jakarta.validation.constraints.Min;
... ... @@ -6,12 +6,12 @@ import jakarta.validation.constraints.NotNull;
6 6 import lombok.Data;
7 7  
8 8 /**
9   - * IoT Modbus TCP Slave 协议配置
  9 + * IoT Modbus TCP Server 协议配置
10 10 *
11 11 * @author 芋道源码
12 12 */
13 13 @Data
14   -public class IotModbusTcpSlaveConfig {
  14 +public class IotModbusTcpServerConfig {
15 15  
16 16 /**
17 17 * 配置刷新间隔(秒)
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpslave/IotModbusTcpSlaveProtocol.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpserver/IotModbusTcpServerProtocol.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.lang.Assert;
... ... @@ -11,16 +11,16 @@ import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
11 11 import cn.iocoder.yudao.module.iot.core.util.IotDeviceMessageUtils;
12 12 import cn.iocoder.yudao.module.iot.gateway.config.IotGatewayProperties.ProtocolProperties;
13 13 import cn.iocoder.yudao.module.iot.gateway.protocol.IotProtocol;
14   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.codec.IotModbusFrameDecoder;
15   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.codec.IotModbusFrameEncoder;
16   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.handler.downstream.IotModbusTcpSlaveDownstreamHandler;
17   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.handler.downstream.IotModbusTcpSlaveDownstreamSubscriber;
18   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.handler.upstream.IotModbusTcpSlaveUpstreamHandler;
19   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.manager.IotModbusTcpSlaveConfigCacheService;
20   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.manager.IotModbusTcpSlaveConnectionManager;
21   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.manager.IotModbusTcpSlaveConnectionManager.ConnectionInfo;
22   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.manager.IotModbusTcpSlavePendingRequestManager;
23   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.manager.IotModbusTcpSlavePollScheduler;
  14 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.codec.IotModbusFrameDecoder;
  15 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.codec.IotModbusFrameEncoder;
  16 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.handler.downstream.IotModbusTcpServerDownstreamHandler;
  17 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.handler.downstream.IotModbusTcpServerDownstreamSubscriber;
  18 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.handler.upstream.IotModbusTcpServerUpstreamHandler;
  19 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.manager.IotModbusTcpServerConfigCacheService;
  20 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.manager.IotModbusTcpServerConnectionManager;
  21 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.manager.IotModbusTcpServerConnectionManager.ConnectionInfo;
  22 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.manager.IotModbusTcpServerPendingRequestManager;
  23 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.manager.IotModbusTcpServerPollScheduler;
24 24 import cn.iocoder.yudao.module.iot.gateway.service.device.IotDeviceService;
25 25 import cn.iocoder.yudao.module.iot.gateway.service.device.message.IotDeviceMessageService;
26 26 import io.vertx.core.Vertx;
... ... @@ -37,7 +37,7 @@ import java.util.concurrent.TimeUnit;
37 37 import java.util.concurrent.atomic.AtomicInteger;
38 38  
39 39 /**
40   - * IoT 网关 Modbus TCP Slave 协议
  40 + * IoT 网关 Modbus TCP Server 协议
41 41 * <p>
42 42 * 作为 TCP Server 接收设备主动连接:
43 43 * 1. 设备通过自定义功能码(FC 65)发送认证请求
... ... @@ -46,7 +46,7 @@ import java.util.concurrent.atomic.AtomicInteger;
46 46 * @author 芋道源码
47 47 */
48 48 @Slf4j
49   -public class IotModbusTcpSlaveProtocol implements IotProtocol {
  49 +public class IotModbusTcpServerProtocol implements IotProtocol {
50 50  
51 51 /**
52 52 * 协议配置
... ... @@ -84,25 +84,25 @@ public class IotModbusTcpSlaveProtocol implements IotProtocol {
84 84 /**
85 85 * 连接管理器
86 86 */
87   - private final IotModbusTcpSlaveConnectionManager connectionManager;
  87 + private final IotModbusTcpServerConnectionManager connectionManager;
88 88 /**
89 89 * 下行消息订阅者
90 90 */
91   - private IotModbusTcpSlaveDownstreamSubscriber downstreamSubscriber;
  91 + private IotModbusTcpServerDownstreamSubscriber downstreamSubscriber;
92 92  
93 93 private final IotModbusFrameDecoder frameDecoder;
94 94 @SuppressWarnings("FieldCanBeLocal")
95 95 private final IotModbusFrameEncoder frameEncoder;
96 96  
97   - private final IotModbusTcpSlaveConfigCacheService configCacheService;
98   - private final IotModbusTcpSlavePendingRequestManager pendingRequestManager;
99   - private final IotModbusTcpSlaveUpstreamHandler upstreamHandler;
100   - private final IotModbusTcpSlavePollScheduler pollScheduler;
  97 + private final IotModbusTcpServerConfigCacheService configCacheService;
  98 + private final IotModbusTcpServerPendingRequestManager pendingRequestManager;
  99 + private final IotModbusTcpServerUpstreamHandler upstreamHandler;
  100 + private final IotModbusTcpServerPollScheduler pollScheduler;
101 101 private final IotDeviceMessageService messageService;
102 102  
103   - public IotModbusTcpSlaveProtocol(ProtocolProperties properties) {
104   - IotModbusTcpSlaveConfig slaveConfig = properties.getModbusTcpSlave();
105   - Assert.notNull(slaveConfig, "Modbus TCP Slave 协议配置(modbusTcpSlave)不能为空");
  103 + public IotModbusTcpServerProtocol(ProtocolProperties properties) {
  104 + IotModbusTcpServerConfig slaveConfig = properties.getModbusTcpServer();
  105 + Assert.notNull(slaveConfig, "Modbus TCP Server 协议配置(modbusTcpServer)不能为空");
106 106 this.properties = properties;
107 107 this.serverId = IotDeviceMessageUtils.generateServerId(properties.getPort());
108 108  
... ... @@ -111,9 +111,9 @@ public class IotModbusTcpSlaveProtocol implements IotProtocol {
111 111  
112 112 // 初始化 Manager
113 113 IotDeviceCommonApi deviceApi = SpringUtil.getBean(IotDeviceCommonApi.class);
114   - this.connectionManager = new IotModbusTcpSlaveConnectionManager();
115   - this.configCacheService = new IotModbusTcpSlaveConfigCacheService(deviceApi);
116   - this.pendingRequestManager = new IotModbusTcpSlavePendingRequestManager();
  114 + this.connectionManager = new IotModbusTcpServerConnectionManager();
  115 + this.configCacheService = new IotModbusTcpServerConfigCacheService(deviceApi);
  116 + this.pendingRequestManager = new IotModbusTcpServerPendingRequestManager();
117 117  
118 118 // 初始化帧编解码器
119 119 this.frameDecoder = new IotModbusFrameDecoder(slaveConfig.getCustomFunctionCode());
... ... @@ -122,14 +122,14 @@ public class IotModbusTcpSlaveProtocol implements IotProtocol {
122 122 // 初始化共享事务 ID 自增器(PollScheduler 和 DownstreamHandler 共用,避免 transactionId 冲突)
123 123 AtomicInteger transactionIdCounter = new AtomicInteger(0);
124 124 // 初始化轮询调度器
125   - this.pollScheduler = new IotModbusTcpSlavePollScheduler(
  125 + this.pollScheduler = new IotModbusTcpServerPollScheduler(
126 126 vertx, connectionManager, frameEncoder, pendingRequestManager,
127 127 slaveConfig.getRequestTimeout(), transactionIdCounter, configCacheService);
128 128  
129 129 // 初始化 Handler
130 130 this.messageService = SpringUtil.getBean(IotDeviceMessageService.class);
131 131 IotDeviceService deviceService = SpringUtil.getBean(IotDeviceService.class);
132   - this.upstreamHandler = new IotModbusTcpSlaveUpstreamHandler(
  132 + this.upstreamHandler = new IotModbusTcpServerUpstreamHandler(
133 133 deviceApi, this.messageService, frameEncoder,
134 134 connectionManager, configCacheService, pendingRequestManager,
135 135 pollScheduler, deviceService, serverId);
... ... @@ -142,19 +142,19 @@ public class IotModbusTcpSlaveProtocol implements IotProtocol {
142 142  
143 143 @Override
144 144 public IotProtocolTypeEnum getType() {
145   - return IotProtocolTypeEnum.MODBUS_TCP_SLAVE;
  145 + return IotProtocolTypeEnum.MODBUS_TCP_SERVER;
146 146 }
147 147  
148 148 @Override
149 149 public void start() {
150 150 if (running) {
151   - log.warn("[start][IoT Modbus TCP Slave 协议 {} 已经在运行中]", getId());
  151 + log.warn("[start][IoT Modbus TCP Server 协议 {} 已经在运行中]", getId());
152 152 return;
153 153 }
154 154  
155 155 try {
156 156 // 1. 启动配置刷新定时器
157   - IotModbusTcpSlaveConfig slaveConfig = properties.getModbusTcpSlave();
  157 + IotModbusTcpServerConfig slaveConfig = properties.getModbusTcpServer();
158 158 configRefreshTimerId = vertx.setPeriodic(
159 159 TimeUnit.SECONDS.toMillis(slaveConfig.getConfigRefreshInterval()),
160 160 id -> refreshConfig());
... ... @@ -167,18 +167,18 @@ public class IotModbusTcpSlaveProtocol implements IotProtocol {
167 167 slaveConfig.getRequestCleanupInterval(),
168 168 id -> pendingRequestManager.cleanupExpired());
169 169 running = true;
170   - log.info("[start][IoT Modbus TCP Slave 协议 {} 启动成功, serverId={}, port={}]",
  170 + log.info("[start][IoT Modbus TCP Server 协议 {} 启动成功, serverId={}, port={}]",
171 171 getId(), serverId, properties.getPort());
172 172  
173 173 // 3. 启动下行消息订阅
174 174 IotMessageBus messageBus = SpringUtil.getBean(IotMessageBus.class);
175   - IotModbusTcpSlaveDownstreamHandler downstreamHandler = new IotModbusTcpSlaveDownstreamHandler(
  175 + IotModbusTcpServerDownstreamHandler downstreamHandler = new IotModbusTcpServerDownstreamHandler(
176 176 connectionManager, configCacheService, frameEncoder, this.pollScheduler.getTransactionIdCounter());
177   - this.downstreamSubscriber = new IotModbusTcpSlaveDownstreamSubscriber(
  177 + this.downstreamSubscriber = new IotModbusTcpServerDownstreamSubscriber(
178 178 this, downstreamHandler, messageBus);
179 179 downstreamSubscriber.start();
180 180 } catch (Exception e) {
181   - log.error("[start][IoT Modbus TCP Slave 协议 {} 启动失败]", getId(), e);
  181 + log.error("[start][IoT Modbus TCP Server 协议 {} 启动失败]", getId(), e);
182 182 stop0();
183 183 throw e;
184 184 }
... ... @@ -238,7 +238,7 @@ public class IotModbusTcpSlaveProtocol implements IotProtocol {
238 238 }
239 239 }
240 240 running = false;
241   - log.info("[stop][IoT Modbus TCP Slave 协议 {} 已停止]", getId());
  241 + log.info("[stop][IoT Modbus TCP Server 协议 {} 已停止]", getId());
242 242 }
243 243  
244 244 /**
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpslave/codec/IotModbusFrame.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpserver/codec/IotModbusFrame.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.codec;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.codec;
2 2  
3 3 import cn.iocoder.yudao.module.iot.core.enums.modbus.IotModbusFrameFormatEnum;
4 4 import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.common.utils.IotModbusCommonUtils;
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpslave/codec/IotModbusFrameDecoder.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpserver/codec/IotModbusFrameDecoder.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.codec;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.codec;
2 2  
3 3 import cn.iocoder.yudao.module.iot.core.enums.modbus.IotModbusFrameFormatEnum;
4 4 import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.common.utils.IotModbusCommonUtils;
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpslave/codec/IotModbusFrameEncoder.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpserver/codec/IotModbusFrameEncoder.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.codec;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.codec;
2 2  
3 3 import cn.iocoder.yudao.module.iot.core.enums.modbus.IotModbusFrameFormatEnum;
4 4 import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.common.utils.IotModbusCommonUtils;
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpslave/handler/downstream/IotModbusTcpSlaveDownstreamHandler.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpserver/handler/downstream/IotModbusTcpServerDownstreamHandler.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.handler.downstream;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.handler.downstream;
2 2  
3 3 import cn.hutool.core.lang.Assert;
4 4 import cn.hutool.core.util.ObjUtil;
... ... @@ -8,17 +8,17 @@ import cn.iocoder.yudao.module.iot.core.enums.IotDeviceMessageMethodEnum;
8 8 import cn.iocoder.yudao.module.iot.core.enums.modbus.IotModbusFrameFormatEnum;
9 9 import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
10 10 import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.common.utils.IotModbusCommonUtils;
11   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.codec.IotModbusFrameEncoder;
12   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.manager.IotModbusTcpSlaveConfigCacheService;
13   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.manager.IotModbusTcpSlaveConnectionManager;
14   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.manager.IotModbusTcpSlaveConnectionManager.ConnectionInfo;
  11 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.codec.IotModbusFrameEncoder;
  12 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.manager.IotModbusTcpServerConfigCacheService;
  13 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.manager.IotModbusTcpServerConnectionManager;
  14 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.manager.IotModbusTcpServerConnectionManager.ConnectionInfo;
15 15 import lombok.extern.slf4j.Slf4j;
16 16  
17 17 import java.util.Map;
18 18 import java.util.concurrent.atomic.AtomicInteger;
19 19  
20 20 /**
21   - * IoT Modbus TCP Slave 下行消息处理器
  21 + * IoT Modbus TCP Server 下行消息处理器
22 22 * <p>
23 23 * 负责:
24 24 * 1. 处理下行消息(如属性设置 thing.service.property.set)
... ... @@ -27,10 +27,10 @@ import java.util.concurrent.atomic.AtomicInteger;
27 27 * @author 芋道源码
28 28 */
29 29 @Slf4j
30   -public class IotModbusTcpSlaveDownstreamHandler {
  30 +public class IotModbusTcpServerDownstreamHandler {
31 31  
32   - private final IotModbusTcpSlaveConnectionManager connectionManager;
33   - private final IotModbusTcpSlaveConfigCacheService configCacheService;
  32 + private final IotModbusTcpServerConnectionManager connectionManager;
  33 + private final IotModbusTcpServerConfigCacheService configCacheService;
34 34 private final IotModbusFrameEncoder frameEncoder;
35 35  
36 36 /**
... ... @@ -38,8 +38,8 @@ public class IotModbusTcpSlaveDownstreamHandler {
38 38 */
39 39 private final AtomicInteger transactionIdCounter;
40 40  
41   - public IotModbusTcpSlaveDownstreamHandler(IotModbusTcpSlaveConnectionManager connectionManager,
42   - IotModbusTcpSlaveConfigCacheService configCacheService,
  41 + public IotModbusTcpServerDownstreamHandler(IotModbusTcpServerConnectionManager connectionManager,
  42 + IotModbusTcpServerConfigCacheService configCacheService,
43 43 IotModbusFrameEncoder frameEncoder,
44 44 AtomicInteger transactionIdCounter) {
45 45 this.connectionManager = connectionManager;
... ... @@ -54,6 +54,9 @@ public class IotModbusTcpSlaveDownstreamHandler {
54 54 @SuppressWarnings({"unchecked", "DuplicatedCode"})
55 55 public void handle(IotDeviceMessage message) {
56 56 // 1.1 检查是否是属性设置消息
  57 + if (ObjUtil.equals(IotDeviceMessageMethodEnum.PROPERTY_POST.getMethod(), message.getMethod())) {
  58 + return;
  59 + }
57 60 if (ObjUtil.notEqual(IotDeviceMessageMethodEnum.PROPERTY_SET.getMethod(), message.getMethod())) {
58 61 log.debug("[handle][忽略非属性设置消息: {}]", message.getMethod());
59 62 return;
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpslave/handler/downstream/IotModbusTcpSlaveDownstreamSubscriber.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpserver/handler/downstream/IotModbusTcpServerDownstreamSubscriber.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.handler.downstream;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.handler.downstream;
2 2  
3 3 import cn.iocoder.yudao.module.iot.core.messagebus.core.IotMessageBus;
4 4 import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
5 5 import cn.iocoder.yudao.module.iot.gateway.protocol.AbstractIotProtocolDownstreamSubscriber;
6   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.IotModbusTcpSlaveProtocol;
  6 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.IotModbusTcpServerProtocol;
7 7 import lombok.extern.slf4j.Slf4j;
8 8  
9 9 /**
10   - * IoT Modbus TCP Slave 下行消息订阅器:订阅消息总线的下行消息并转发给处理器
  10 + * IoT Modbus TCP Server 下行消息订阅器:订阅消息总线的下行消息并转发给处理器
11 11 *
12 12 * @author 芋道源码
13 13 */
14 14 @Slf4j
15   -public class IotModbusTcpSlaveDownstreamSubscriber extends AbstractIotProtocolDownstreamSubscriber {
  15 +public class IotModbusTcpServerDownstreamSubscriber extends AbstractIotProtocolDownstreamSubscriber {
16 16  
17   - private final IotModbusTcpSlaveDownstreamHandler downstreamHandler;
  17 + private final IotModbusTcpServerDownstreamHandler downstreamHandler;
18 18  
19   - public IotModbusTcpSlaveDownstreamSubscriber(IotModbusTcpSlaveProtocol protocol,
20   - IotModbusTcpSlaveDownstreamHandler downstreamHandler,
  19 + public IotModbusTcpServerDownstreamSubscriber(IotModbusTcpServerProtocol protocol,
  20 + IotModbusTcpServerDownstreamHandler downstreamHandler,
21 21 IotMessageBus messageBus) {
22 22 super(protocol, messageBus);
23 23 this.downstreamHandler = downstreamHandler;
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpslave/handler/upstream/IotModbusTcpSlaveUpstreamHandler.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpserver/handler/upstream/IotModbusTcpServerUpstreamHandler.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.handler.upstream;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.handler.upstream;
2 2  
3 3 import cn.hutool.core.lang.Assert;
4 4 import cn.hutool.core.map.MapUtil;
... ... @@ -20,14 +20,14 @@ import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
20 20 import cn.iocoder.yudao.module.iot.core.topic.IotDeviceIdentity;
21 21 import cn.iocoder.yudao.module.iot.core.util.IotDeviceAuthUtils;
22 22 import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.common.utils.IotModbusCommonUtils;
23   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.codec.IotModbusFrame;
24   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.codec.IotModbusFrameEncoder;
25   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.manager.IotModbusTcpSlaveConfigCacheService;
26   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.manager.IotModbusTcpSlaveConnectionManager;
27   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.manager.IotModbusTcpSlaveConnectionManager.ConnectionInfo;
28   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.manager.IotModbusTcpSlavePendingRequestManager;
29   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.manager.IotModbusTcpSlavePendingRequestManager.PendingRequest;
30   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.manager.IotModbusTcpSlavePollScheduler;
  23 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.codec.IotModbusFrame;
  24 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.codec.IotModbusFrameEncoder;
  25 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.manager.IotModbusTcpServerConfigCacheService;
  26 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.manager.IotModbusTcpServerConnectionManager;
  27 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.manager.IotModbusTcpServerConnectionManager.ConnectionInfo;
  28 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.manager.IotModbusTcpServerPendingRequestManager;
  29 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.manager.IotModbusTcpServerPendingRequestManager.PendingRequest;
  30 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.manager.IotModbusTcpServerPollScheduler;
31 31 import cn.iocoder.yudao.module.iot.gateway.service.device.IotDeviceService;
32 32 import cn.iocoder.yudao.module.iot.gateway.service.device.message.IotDeviceMessageService;
33 33 import io.vertx.core.net.NetSocket;
... ... @@ -40,7 +40,7 @@ import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeC
40 40 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.invalidParamException;
41 41  
42 42 /**
43   - * IoT Modbus TCP Slave 上行数据处理器
  43 + * IoT Modbus TCP Server 上行数据处理器
44 44 * <p>
45 45 * 处理:
46 46 * 1. 自定义 FC 认证
... ... @@ -49,28 +49,28 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU
49 49 * @author 芋道源码
50 50 */
51 51 @Slf4j
52   -public class IotModbusTcpSlaveUpstreamHandler {
  52 +public class IotModbusTcpServerUpstreamHandler {
53 53  
54 54 private static final String METHOD_AUTH = "auth";
55 55  
56 56 private final IotDeviceCommonApi deviceApi;
57 57 private final IotDeviceMessageService messageService;
58 58 private final IotModbusFrameEncoder frameEncoder;
59   - private final IotModbusTcpSlaveConnectionManager connectionManager;
60   - private final IotModbusTcpSlaveConfigCacheService configCacheService;
61   - private final IotModbusTcpSlavePendingRequestManager pendingRequestManager;
62   - private final IotModbusTcpSlavePollScheduler pollScheduler;
  59 + private final IotModbusTcpServerConnectionManager connectionManager;
  60 + private final IotModbusTcpServerConfigCacheService configCacheService;
  61 + private final IotModbusTcpServerPendingRequestManager pendingRequestManager;
  62 + private final IotModbusTcpServerPollScheduler pollScheduler;
63 63 private final IotDeviceService deviceService;
64 64  
65 65 private final String serverId;
66 66  
67   - public IotModbusTcpSlaveUpstreamHandler(IotDeviceCommonApi deviceApi,
  67 + public IotModbusTcpServerUpstreamHandler(IotDeviceCommonApi deviceApi,
68 68 IotDeviceMessageService messageService,
69 69 IotModbusFrameEncoder frameEncoder,
70   - IotModbusTcpSlaveConnectionManager connectionManager,
71   - IotModbusTcpSlaveConfigCacheService configCacheService,
72   - IotModbusTcpSlavePendingRequestManager pendingRequestManager,
73   - IotModbusTcpSlavePollScheduler pollScheduler,
  70 + IotModbusTcpServerConnectionManager connectionManager,
  71 + IotModbusTcpServerConfigCacheService configCacheService,
  72 + IotModbusTcpServerPendingRequestManager pendingRequestManager,
  73 + IotModbusTcpServerPollScheduler pollScheduler,
74 74 IotDeviceService deviceService,
75 75 String serverId) {
76 76 this.deviceApi = deviceApi;
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpslave/manager/IotModbusTcpSlaveConfigCacheService.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpserver/manager/IotModbusTcpServerConfigCacheService.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.manager;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.manager;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
... ... @@ -18,13 +18,13 @@ import java.util.Set;
18 18 import java.util.concurrent.ConcurrentHashMap;
19 19  
20 20 /**
21   - * IoT Modbus TCP Slave 配置缓存:认证时按需加载,断连时清理,定时刷新已连接设备
  21 + * IoT Modbus TCP Server 配置缓存:认证时按需加载,断连时清理,定时刷新已连接设备
22 22 *
23 23 * @author 芋道源码
24 24 */
25 25 @RequiredArgsConstructor
26 26 @Slf4j
27   -public class IotModbusTcpSlaveConfigCacheService {
  27 +public class IotModbusTcpServerConfigCacheService {
28 28  
29 29 private final IotDeviceCommonApi deviceApi;
30 30  
... ... @@ -45,7 +45,7 @@ public class IotModbusTcpSlaveConfigCacheService {
45 45 IotModbusDeviceConfigListReqDTO reqDTO = new IotModbusDeviceConfigListReqDTO()
46 46 .setStatus(CommonStatusEnum.ENABLE.getStatus())
47 47 .setMode(IotModbusModeEnum.POLLING.getMode())
48   - .setProtocolType(IotProtocolTypeEnum.MODBUS_TCP_SLAVE.getType())
  48 + .setProtocolType(IotProtocolTypeEnum.MODBUS_TCP_SERVER.getType())
49 49 .setDeviceIds(Collections.singleton(deviceId));
50 50 CommonResult<List<IotModbusDeviceConfigRespDTO>> result = deviceApi.getModbusDeviceConfigList(reqDTO);
51 51 result.checkError();
... ... @@ -81,7 +81,7 @@ public class IotModbusTcpSlaveConfigCacheService {
81 81 CommonResult<List<IotModbusDeviceConfigRespDTO>> result = deviceApi.getModbusDeviceConfigList(
82 82 new IotModbusDeviceConfigListReqDTO().setStatus(CommonStatusEnum.ENABLE.getStatus())
83 83 .setMode(IotModbusModeEnum.POLLING.getMode())
84   - .setProtocolType(IotProtocolTypeEnum.MODBUS_TCP_SLAVE.getType())
  84 + .setProtocolType(IotProtocolTypeEnum.MODBUS_TCP_SERVER.getType())
85 85 .setDeviceIds(connectedDeviceIds));
86 86 List<IotModbusDeviceConfigRespDTO> modbusConfigs = result.getCheckedData();
87 87  
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpslave/manager/IotModbusTcpSlaveConnectionManager.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpserver/manager/IotModbusTcpServerConnectionManager.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.manager;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.manager;
2 2  
3 3 import cn.iocoder.yudao.module.iot.core.enums.modbus.IotModbusFrameFormatEnum;
4 4 import io.vertx.core.Future;
... ... @@ -15,14 +15,14 @@ import java.util.Set;
15 15 import java.util.concurrent.ConcurrentHashMap;
16 16  
17 17 /**
18   - * IoT Modbus TCP Slave 连接管理器
  18 + * IoT Modbus TCP Server 连接管理器
19 19 * <p>
20 20 * 管理设备 TCP 连接:socket ↔ 设备双向映射
21 21 *
22 22 * @author 芋道源码
23 23 */
24 24 @Slf4j
25   -public class IotModbusTcpSlaveConnectionManager {
  25 +public class IotModbusTcpServerConnectionManager {
26 26  
27 27 /**
28 28 * socket → 连接信息
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpslave/manager/IotModbusTcpSlavePendingRequestManager.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpserver/manager/IotModbusTcpServerPendingRequestManager.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.manager;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.manager;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.iocoder.yudao.module.iot.core.enums.modbus.IotModbusFrameFormatEnum;
5 5 import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.common.utils.IotModbusCommonUtils;
6   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.codec.IotModbusFrame;
  6 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.codec.IotModbusFrame;
7 7 import lombok.AllArgsConstructor;
8 8 import lombok.Data;
9 9 import lombok.extern.slf4j.Slf4j;
... ... @@ -15,7 +15,7 @@ import java.util.concurrent.ConcurrentHashMap;
15 15 import java.util.concurrent.ConcurrentLinkedDeque;
16 16  
17 17 /**
18   - * IoT Modbus TCP Slave 待响应请求管理器
  18 + * IoT Modbus TCP Server 待响应请求管理器
19 19 * <p>
20 20 * 管理轮询下发的请求,用于匹配设备响应:
21 21 * - TCP 模式:按 transactionId 精确匹配
... ... @@ -24,7 +24,7 @@ import java.util.concurrent.ConcurrentLinkedDeque;
24 24 * @author 芋道源码
25 25 */
26 26 @Slf4j
27   -public class IotModbusTcpSlavePendingRequestManager {
  27 +public class IotModbusTcpServerPendingRequestManager {
28 28  
29 29 /**
30 30 * deviceId → 有序队列
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpslave/manager/IotModbusTcpSlavePollScheduler.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpserver/manager/IotModbusTcpServerPollScheduler.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.manager;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.manager;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.lang.Assert;
... ... @@ -7,9 +7,9 @@ import cn.iocoder.yudao.module.iot.core.biz.dto.IotModbusPointRespDTO;
7 7 import cn.iocoder.yudao.module.iot.core.enums.modbus.IotModbusFrameFormatEnum;
8 8 import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.common.manager.AbstractIotModbusPollScheduler;
9 9 import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.common.utils.IotModbusCommonUtils;
10   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.codec.IotModbusFrameEncoder;
11   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.manager.IotModbusTcpSlaveConnectionManager.ConnectionInfo;
12   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.manager.IotModbusTcpSlavePendingRequestManager.PendingRequest;
  10 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.codec.IotModbusFrameEncoder;
  11 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.manager.IotModbusTcpServerConnectionManager.ConnectionInfo;
  12 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.manager.IotModbusTcpServerPendingRequestManager.PendingRequest;
13 13 import io.vertx.core.Vertx;
14 14 import lombok.Getter;
15 15 import lombok.extern.slf4j.Slf4j;
... ... @@ -17,17 +17,17 @@ import lombok.extern.slf4j.Slf4j;
17 17 import java.util.concurrent.atomic.AtomicInteger;
18 18  
19 19 /**
20   - * IoT Modbus TCP Slave 轮询调度器:编码读请求帧,通过 TCP 连接发送到设备,注册 PendingRequest 等待响应
  20 + * IoT Modbus TCP Server 轮询调度器:编码读请求帧,通过 TCP 连接发送到设备,注册 PendingRequest 等待响应
21 21 *
22 22 * @author 芋道源码
23 23 */
24 24 @Slf4j
25   -public class IotModbusTcpSlavePollScheduler extends AbstractIotModbusPollScheduler {
  25 +public class IotModbusTcpServerPollScheduler extends AbstractIotModbusPollScheduler {
26 26  
27   - private final IotModbusTcpSlaveConnectionManager connectionManager;
  27 + private final IotModbusTcpServerConnectionManager connectionManager;
28 28 private final IotModbusFrameEncoder frameEncoder;
29   - private final IotModbusTcpSlavePendingRequestManager pendingRequestManager;
30   - private final IotModbusTcpSlaveConfigCacheService configCacheService;
  29 + private final IotModbusTcpServerPendingRequestManager pendingRequestManager;
  30 + private final IotModbusTcpServerConfigCacheService configCacheService;
31 31 private final int requestTimeout;
32 32 /**
33 33 * TCP 事务 ID 自增器(与 DownstreamHandler 共享)
... ... @@ -35,13 +35,13 @@ public class IotModbusTcpSlavePollScheduler extends AbstractIotModbusPollSchedul
35 35 @Getter
36 36 private final AtomicInteger transactionIdCounter;
37 37  
38   - public IotModbusTcpSlavePollScheduler(Vertx vertx,
39   - IotModbusTcpSlaveConnectionManager connectionManager,
  38 + public IotModbusTcpServerPollScheduler(Vertx vertx,
  39 + IotModbusTcpServerConnectionManager connectionManager,
40 40 IotModbusFrameEncoder frameEncoder,
41   - IotModbusTcpSlavePendingRequestManager pendingRequestManager,
  41 + IotModbusTcpServerPendingRequestManager pendingRequestManager,
42 42 int requestTimeout,
43 43 AtomicInteger transactionIdCounter,
44   - IotModbusTcpSlaveConfigCacheService configCacheService) {
  44 + IotModbusTcpServerConfigCacheService configCacheService) {
45 45 super(vertx);
46 46 this.connectionManager = connectionManager;
47 47 this.frameEncoder = frameEncoder;
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpslave/package-info.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpserver/package-info.java
1 1 /**
2   - * Modbus TCP Slave(从站)协议:设备主动连接网关,自定义 FC65 认证后由网关云端轮询
  2 + * Modbus TCP Server(从站)协议:设备主动连接网关,自定义 FC65 认证后由网关云端轮询
3 3 * <p>
4 4 * TCP Server 模式,支持 MODBUS_TCP / MODBUS_RTU 帧格式自动检测
5 5 */
6   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave;
  6 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver;
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/tcp/handler/downstream/IotTcpDownstreamHandler.java
1 1 package cn.iocoder.yudao.module.iot.gateway.protocol.tcp.handler.downstream;
2 2  
  3 +import cn.hutool.core.util.ObjUtil;
  4 +import cn.iocoder.yudao.module.iot.core.enums.IotDeviceMessageMethodEnum;
3 5 import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
4 6 import cn.iocoder.yudao.module.iot.gateway.protocol.tcp.codec.IotTcpFrameCodec;
5 7 import cn.iocoder.yudao.module.iot.gateway.protocol.tcp.manager.IotTcpConnectionManager;
... ... @@ -33,9 +35,17 @@ public class IotTcpDownstreamHandler {
33 35 */
34 36 public void handle(IotDeviceMessage message) {
35 37 try {
  38 + // 1.1 检查是否是属性设置消息
  39 + if (ObjUtil.equals(IotDeviceMessageMethodEnum.PROPERTY_POST.getMethod(), message.getMethod())) {
  40 + return;
  41 + }
  42 + if (ObjUtil.notEqual(IotDeviceMessageMethodEnum.PROPERTY_SET.getMethod(), message.getMethod())) {
  43 + log.warn("[handle][忽略非属性设置消息: {}]", message.getMethod());
  44 + return;
  45 + }
36 46 log.info("[handle][处理下行消息,设备 ID: {},方法: {},消息 ID: {}]",
37 47 message.getDeviceId(), message.getMethod(), message.getId());
38   - // 1. 检查设备连接
  48 + // 1.2 检查设备连接
39 49 IotTcpConnectionManager.ConnectionInfo connectionInfo = connectionManager.getConnectionInfoByDeviceId(
40 50 message.getDeviceId());
41 51 if (connectionInfo == null) {
... ...
yudao-module-iot/yudao-module-iot-gateway/src/main/resources/application.yaml
... ... @@ -164,22 +164,22 @@ yudao:
164 164 trust-store-path: "classpath:certs/trust.jks" # 信任的 CA 证书库路径
165 165 trust-store-password: "your-truststore-password" # 信任的 CA 证书库密码
166 166 # ====================================
167   - # 针对引入的 Modbus TCP Master 组件的配置
  167 + # 针对引入的 Modbus TCP Client 组件的配置
168 168 # ====================================
169   - - id: modbus-tcp-master-1
  169 + - id: modbus-tcp-client-1
170 170 enabled: false
171   - protocol: modbus_tcp_master
  171 + protocol: modbus_tcp_client
172 172 port: 502
173   - modbus-tcp-master:
  173 + modbus-tcp-client:
174 174 config-refresh-interval: 30 # 配置刷新间隔(秒)
175 175 # ====================================
176   - # 针对引入的 Modbus TCP Slave 组件的配置
  176 + # 针对引入的 Modbus TCP Server 组件的配置
177 177 # ====================================
178   - - id: modbus-tcp-slave-1
  178 + - id: modbus-tcp-server-1
179 179 enabled: false
180   - protocol: modbus_tcp_slave
  180 + protocol: modbus_tcp_server
181 181 port: 503
182   - modbus-tcp-slave:
  182 + modbus-tcp-server:
183 183 config-refresh-interval: 30 # 配置刷新间隔(秒)
184 184 custom-function-code: 65 # 自定义功能码(用于认证等扩展交互)
185 185 request-timeout: 5000 # Pending Request 超时时间(毫秒)
... ...
yudao-module-iot/yudao-module-iot-gateway/src/test/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpmaster/IoTModbusTcpMasterIntegrationTest.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/test/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpclient/IoTModbusTcpClientIntegrationTest.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpmaster;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpclient;
2 2  
3 3 import com.ghgande.j2mod.modbus.procimg.*;
4 4 import com.ghgande.j2mod.modbus.slave.ModbusSlave;
... ... @@ -10,13 +10,13 @@ import org.junit.jupiter.api.Test;
10 10 /**
11 11 * Modbus TCP 从站模拟器(手动测试)
12 12 *
13   - * <p>测试场景:模拟一个标准 Modbus TCP 从站设备,供 Modbus TCP Master 网关连接和读写数据
  13 + * <p>测试场景:模拟一个标准 Modbus TCP 从站设备,供 Modbus TCP Client 网关连接和读写数据
14 14 *
15 15 * <p>使用步骤:
16 16 * <ol>
17 17 * <li>运行 {@link #testStartSlaveSimulator()} 启动模拟从站(默认端口 5020,从站地址 1)</li>
18   - * <li>启动 yudao-module-iot-gateway 服务(需开启 modbus-tcp-master 协议)</li>
19   - * <li>确保数据库有对应的 Modbus Master 设备配置(ip=127.0.0.1, port=5020, slaveId=1)</li>
  18 + * <li>启动 yudao-module-iot-gateway 服务(需开启 modbus-tcp-client 协议)</li>
  19 + * <li>确保数据库有对应的 Modbus Client 设备配置(ip=127.0.0.1, port=5020, slaveId=1)</li>
20 20 * <li>网关会自动连接模拟从站并开始轮询读取寄存器数据</li>
21 21 * <li>模拟器每 5 秒自动更新输入寄存器和保持寄存器的值,模拟传感器数据变化</li>
22 22 * </ol>
... ... @@ -33,7 +33,7 @@ import org.junit.jupiter.api.Test;
33 33 */
34 34 @Slf4j
35 35 @Disabled
36   -public class IoTModbusTcpMasterIntegrationTest {
  36 +public class IoTModbusTcpClientIntegrationTest {
37 37  
38 38 private static final int PORT = 5020;
39 39 private static final int SLAVE_ID = 1;
... ...
yudao-module-iot/yudao-module-iot-gateway/src/test/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpslave/IotModbusTcpSlaveRtuIntegrationTest.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/test/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpserver/IotModbusTcpServerRtuIntegrationTest.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver;
2 2  
3 3 import cn.hutool.core.util.HexUtil;
4 4 import cn.hutool.json.JSONObject;
... ... @@ -7,9 +7,9 @@ import cn.iocoder.yudao.module.iot.core.biz.dto.IotDeviceAuthReqDTO;
7 7 import cn.iocoder.yudao.module.iot.core.enums.modbus.IotModbusFrameFormatEnum;
8 8 import cn.iocoder.yudao.module.iot.core.util.IotDeviceAuthUtils;
9 9 import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.common.utils.IotModbusCommonUtils;
10   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.codec.IotModbusFrame;
11   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.codec.IotModbusFrameDecoder;
12   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.codec.IotModbusFrameEncoder;
  10 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.codec.IotModbusFrame;
  11 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.codec.IotModbusFrameDecoder;
  12 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.codec.IotModbusFrameEncoder;
13 13 import io.vertx.core.Vertx;
14 14 import io.vertx.core.buffer.Buffer;
15 15 import io.vertx.core.net.NetClient;
... ... @@ -28,13 +28,13 @@ import java.util.concurrent.TimeUnit;
28 28 import static org.junit.jupiter.api.Assertions.assertEquals;
29 29  
30 30 /**
31   - * IoT Modbus TCP Slave 协议集成测试 — MODBUS_RTU 帧格式(手动测试)
  31 + * IoT Modbus TCP Server 协议集成测试 — MODBUS_RTU 帧格式(手动测试)
32 32 *
33 33 * <p>测试场景:设备(TCP Client)连接到网关(TCP Server),使用 MODBUS_RTU(CRC16)帧格式通信
34 34 *
35 35 * <p>使用步骤:
36 36 * <ol>
37   - * <li>启动 yudao-module-iot-gateway 服务(需开启 modbus-tcp-slave 协议,默认端口 503)</li>
  37 + * <li>启动 yudao-module-iot-gateway 服务(需开启 modbus-tcp-server 协议,默认端口 503)</li>
38 38 * <li>确保数据库有对应的 Modbus 设备配置(mode=1, frameFormat=modbus_rtu)</li>
39 39 * <li>运行以下测试方法:
40 40 * <ul>
... ... @@ -49,7 +49,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
49 49 */
50 50 @Slf4j
51 51 @Disabled
52   -public class IotModbusTcpSlaveRtuIntegrationTest {
  52 +public class IotModbusTcpServerRtuIntegrationTest {
53 53  
54 54 private static final String SERVER_HOST = "127.0.0.1";
55 55 private static final int SERVER_PORT = 503;
... ... @@ -68,8 +68,8 @@ public class IotModbusTcpSlaveRtuIntegrationTest {
68 68  
69 69 // ===================== 设备信息(根据实际情况修改,从 iot_device 表查询) =====================
70 70  
71   - private static final String PRODUCT_KEY = "modbus_tcp_slave_product_demo";
72   - private static final String DEVICE_NAME = "modbus_tcp_slave_device_demo_rtu";
  71 + private static final String PRODUCT_KEY = "modbus_tcp_server_product_demo";
  72 + private static final String DEVICE_NAME = "modbus_tcp_server_device_demo_rtu";
73 73 private static final String DEVICE_SECRET = "af01c55eb8e3424bb23fc6c783936b2e";
74 74  
75 75 @BeforeAll
... ...
yudao-module-iot/yudao-module-iot-gateway/src/test/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpslave/IotModbusTcpSlaveTcpIntegrationTest.java renamed to yudao-module-iot/yudao-module-iot-gateway/src/test/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpserver/IotModbusTcpServerTcpIntegrationTest.java
1   -package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave;
  1 +package cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver;
2 2  
3 3 import cn.hutool.core.util.HexUtil;
4 4 import cn.hutool.json.JSONObject;
... ... @@ -6,9 +6,9 @@ import cn.hutool.json.JSONUtil;
6 6 import cn.iocoder.yudao.module.iot.core.biz.dto.IotDeviceAuthReqDTO;
7 7 import cn.iocoder.yudao.module.iot.core.enums.modbus.IotModbusFrameFormatEnum;
8 8 import cn.iocoder.yudao.module.iot.core.util.IotDeviceAuthUtils;
9   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.codec.IotModbusFrame;
10   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.codec.IotModbusFrameDecoder;
11   -import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpslave.codec.IotModbusFrameEncoder;
  9 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.codec.IotModbusFrame;
  10 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.codec.IotModbusFrameDecoder;
  11 +import cn.iocoder.yudao.module.iot.gateway.protocol.modbus.tcpserver.codec.IotModbusFrameEncoder;
12 12 import io.vertx.core.Vertx;
13 13 import io.vertx.core.buffer.Buffer;
14 14 import io.vertx.core.net.NetClient;
... ... @@ -29,13 +29,13 @@ import java.util.concurrent.TimeUnit;
29 29 import static org.junit.jupiter.api.Assertions.assertEquals;
30 30  
31 31 /**
32   - * IoT Modbus TCP Slave 协议集成测试 — MODBUS_TCP 帧格式(手动测试)
  32 + * IoT Modbus TCP Server 协议集成测试 — MODBUS_TCP 帧格式(手动测试)
33 33 *
34 34 * <p>测试场景:设备(TCP Client)连接到网关(TCP Server),使用 MODBUS_TCP(MBAP 头)帧格式通信
35 35 *
36 36 * <p>使用步骤:
37 37 * <ol>
38   - * <li>启动 yudao-module-iot-gateway 服务(需开启 modbus-tcp-slave 协议,默认端口 503)</li>
  38 + * <li>启动 yudao-module-iot-gateway 服务(需开启 modbus-tcp-server 协议,默认端口 503)</li>
39 39 * <li>确保数据库有对应的 Modbus 设备配置(mode=1, frameFormat=modbus_tcp)</li>
40 40 * <li>运行以下测试方法:
41 41 * <ul>
... ... @@ -50,7 +50,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
50 50 */
51 51 @Slf4j
52 52 @Disabled
53   -public class IotModbusTcpSlaveTcpIntegrationTest {
  53 +public class IotModbusTcpServerTcpIntegrationTest {
54 54  
55 55 private static final String SERVER_HOST = "127.0.0.1";
56 56 private static final int SERVER_PORT = 503;
... ... @@ -69,8 +69,8 @@ public class IotModbusTcpSlaveTcpIntegrationTest {
69 69  
70 70 // ===================== 设备信息(根据实际情况修改,从 iot_device 表查询) =====================
71 71  
72   - private static final String PRODUCT_KEY = "modbus_tcp_slave_product_demo";
73   - private static final String DEVICE_NAME = "modbus_tcp_slave_device_demo_tcp";
  72 + private static final String PRODUCT_KEY = "modbus_tcp_server_product_demo";
  73 + private static final String DEVICE_NAME = "modbus_tcp_server_device_demo_tcp";
74 74 private static final String DEVICE_SECRET = "8e4adeb3d25342ab88643421d3fba3f6";
75 75  
76 76 @BeforeAll
... ...