sparkplug: add getNodeDeviceName()
This commit is contained in:
parent
c6dbdeb23d
commit
d8e97dd74d
@ -399,7 +399,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
|
|||||||
case NBIRTH:
|
case NBIRTH:
|
||||||
case NCMD:
|
case NCMD:
|
||||||
case NDATA:
|
case NDATA:
|
||||||
sparkplugSessionHandler.onAttributesTelemetryProto(msgId, sparkplugBProtoNode, deviceSessionCtx.getDeviceInfo().getDeviceName(), sparkplugTopic);
|
sparkplugSessionHandler.onAttributesTelemetryProto(msgId, sparkplugBProtoNode, sparkplugTopic);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
@ -410,7 +410,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
|
|||||||
case DBIRTH:
|
case DBIRTH:
|
||||||
case DCMD:
|
case DCMD:
|
||||||
case DDATA:
|
case DDATA:
|
||||||
sparkplugSessionHandler.onAttributesTelemetryProto(msgId, sparkplugBProtoDevice, sparkplugTopic.getDeviceId(), sparkplugTopic);
|
sparkplugSessionHandler.onAttributesTelemetryProto(msgId, sparkplugBProtoDevice, sparkplugTopic);
|
||||||
break;
|
break;
|
||||||
case DDEATH:
|
case DDEATH:
|
||||||
sparkplugSessionHandler.onDeviceDisconnect(mqttMsg, sparkplugTopic.getDeviceId());
|
sparkplugSessionHandler.onDeviceDisconnect(mqttMsg, sparkplugTopic.getDeviceId());
|
||||||
@ -1067,8 +1067,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
|
|||||||
if (sparkplugTopicNode != null) {
|
if (sparkplugTopicNode != null) {
|
||||||
SparkplugBProto.Payload sparkplugBProtoNode = SparkplugBProto.Payload.parseFrom(connectMessage.payload().willMessageInBytes());
|
SparkplugBProto.Payload sparkplugBProtoNode = SparkplugBProto.Payload.parseFrom(connectMessage.payload().willMessageInBytes());
|
||||||
sparkplugSessionHandler = new SparkplugNodeSessionHandler(this, deviceSessionCtx, sessionId, sparkplugTopicNode);
|
sparkplugSessionHandler = new SparkplugNodeSessionHandler(this, deviceSessionCtx, sessionId, sparkplugTopicNode);
|
||||||
sparkplugSessionHandler.onAttributesTelemetryProto(0, sparkplugBProtoNode,
|
sparkplugSessionHandler.onAttributesTelemetryProto(0, sparkplugBProtoNode, sparkplugTopicNode);
|
||||||
deviceSessionCtx.getDeviceInfo().getDeviceName(), sparkplugTopicNode);
|
|
||||||
sessionMetaData.setOverwriteActivityTime(true);
|
sessionMetaData.setOverwriteActivityTime(true);
|
||||||
} else {
|
} else {
|
||||||
log.trace("[{}][{}] Failed to fetch sparkplugDevice connect: sparkplugTopicName without SparkplugMessageType.NDEATH.", sessionId, deviceSessionCtx.getDeviceInfo().getDeviceName());
|
log.trace("[{}][{}] Failed to fetch sparkplugDevice connect: sparkplugTopicName without SparkplugMessageType.NDEATH.", sessionId, deviceSessionCtx.getDeviceInfo().getDeviceName());
|
||||||
|
|||||||
@ -101,7 +101,8 @@ public class SparkplugNodeSessionHandler extends AbstractGatewaySessionHandler<S
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onAttributesTelemetryProto(int msgId, SparkplugBProto.Payload sparkplugBProto, String deviceName, SparkplugTopic topic) throws AdaptorException, ThingsboardException {
|
public void onAttributesTelemetryProto(int msgId, SparkplugBProto.Payload sparkplugBProto, SparkplugTopic topic) throws AdaptorException, ThingsboardException {
|
||||||
|
String deviceName = topic.getNodeDeviceName();
|
||||||
checkDeviceName(deviceName);
|
checkDeviceName(deviceName);
|
||||||
|
|
||||||
ListenableFuture<MqttDeviceAwareSessionContext> contextListenableFuture;
|
ListenableFuture<MqttDeviceAwareSessionContext> contextListenableFuture;
|
||||||
@ -113,7 +114,7 @@ public class SparkplugNodeSessionHandler extends AbstractGatewaySessionHandler<S
|
|||||||
}
|
}
|
||||||
contextListenableFuture = Futures.immediateFuture(this.deviceSessionCtx);
|
contextListenableFuture = Futures.immediateFuture(this.deviceSessionCtx);
|
||||||
} else {
|
} else {
|
||||||
ListenableFuture<SparkplugDeviceSessionContext> deviceCtx = onDeviceConnectProto(deviceName);
|
ListenableFuture<SparkplugDeviceSessionContext> deviceCtx = onDeviceConnectProto(topic);
|
||||||
contextListenableFuture = Futures.transform(deviceCtx, ctx -> {
|
contextListenableFuture = Futures.transform(deviceCtx, ctx -> {
|
||||||
if (topic.isType(DBIRTH)) {
|
if (topic.isType(DBIRTH)) {
|
||||||
sendSparkplugStateOnTelemetry(ctx.getSessionInfo(), deviceName, ONLINE,
|
sendSparkplugStateOnTelemetry(ctx.getSessionInfo(), deviceName, ONLINE,
|
||||||
@ -218,10 +219,10 @@ public class SparkplugNodeSessionHandler extends AbstractGatewaySessionHandler<S
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ListenableFuture<SparkplugDeviceSessionContext> onDeviceConnectProto(String deviceName) throws ThingsboardException {
|
private ListenableFuture<SparkplugDeviceSessionContext> onDeviceConnectProto(SparkplugTopic topic) throws ThingsboardException {
|
||||||
try {
|
try {
|
||||||
String deviceType = this.gateway.getDeviceType() + "-node";
|
String deviceType = this.gateway.getDeviceType() + "-node";
|
||||||
return onDeviceConnect(deviceName, deviceType);
|
return onDeviceConnect(topic.getNodeDeviceName(), deviceType);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
log.error("Failed Sparkplug Device connect proto!", e);
|
log.error("Failed Sparkplug Device connect proto!", e);
|
||||||
throw new ThingsboardException(e, ThingsboardErrorCode.BAD_REQUEST_PARAMS);
|
throw new ThingsboardException(e, ThingsboardErrorCode.BAD_REQUEST_PARAMS);
|
||||||
|
|||||||
@ -161,4 +161,9 @@ public class SparkplugTopic {
|
|||||||
public boolean isNode() {
|
public boolean isNode() {
|
||||||
return this.deviceId == null;
|
return this.deviceId == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getNodeDeviceName() {
|
||||||
|
return isNode() ? edgeNodeId : deviceId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user