Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Minor UDP updates

Rich Turner4161fb6c49b4
diff --git a/agent/src/main/java/org/openremote/agent/protocol/udp/AbstractUdpClientProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/udp/AbstractUdpClientProtocol.java
index 659dc6c49..301df0433 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/udp/AbstractUdpClientProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/udp/AbstractUdpClientProtocol.java
@@ -65,16 +65,16 @@ public abstract class AbstractUdpClientProtocol<T> extends AbstractIoClientProto
String host = Values.getMetaItemValueOrThrow(
protocolConfiguration,
META_PROTOCOL_HOST,
- true,
- true
+ false,
+ false
).flatMap(Values::getString).orElse(null);
- int port = Values.getMetaItemValueOrThrow(
+ Integer port = Values.getMetaItemValueOrThrow(
protocolConfiguration,
META_PROTOCOL_PORT,
- true,
- true
- ).flatMap(Values::getIntegerCoerced).orElse(0);
+ false,
+ false
+ ).flatMap(Values::getIntegerCoerced).orElse(null);
Integer bindPort = Values.getMetaItemValueOrThrow(
protocolConfiguration,
@@ -83,7 +83,7 @@ public abstract class AbstractUdpClientProtocol<T> extends AbstractIoClientProto
false
).flatMap(Values::getIntegerCoerced).orElse(null);
- if (port < 1 || port > 65536) {
+ if (port != null && (port < 1 || port > 65536)) {
throw new IllegalArgumentException("Port must be in the range 1-65536");
}
@@ -91,10 +91,6 @@ public abstract class AbstractUdpClientProtocol<T> extends AbstractIoClientProto
throw new IllegalArgumentException("Bind port must be in the range 1-65536 if specified");
}
- if (TextUtil.isNullOrEmpty(host)) {
- throw new IllegalArgumentException("Host cannot be empty");
- }
-
return new UdpIoClient<>(host, port, bindPort, executorService);
}
}
diff --git a/agent/src/main/java/org/openremote/agent/protocol/udp/UdpIoClient.java b/agent/src/main/java/org/openremote/agent/protocol/udp/UdpIoClient.java
index 64622d43a..fb3335ed3 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/udp/UdpIoClient.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/udp/UdpIoClient.java
@@ -53,11 +53,12 @@ public class UdpIoClient<T> extends AbstractNettyIoClient<T, InetSocketAddress>
protected int port;
protected int bindPort;
- public UdpIoClient(String host, int port, Integer bindPort, ProtocolExecutorService executorService) {
+ public UdpIoClient(String host, Integer port, Integer bindPort, ProtocolExecutorService executorService) {
super(executorService);
- TextUtil.requireNonNullAndNonEmpty(host);
- if (port < 1 || port > 65536) {
+ if (port == null) {
+ port = 0;
+ } else if (port < 1 || port > 65536) {
throw new IllegalArgumentException("Port must be between 1 and 65536");
}
@@ -77,7 +78,7 @@ public class UdpIoClient<T> extends AbstractNettyIoClient<T, InetSocketAddress>
channel.pipeline().addLast(new MessageToMessageEncoder<ByteBuf>() {
@Override
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
- out.add(new DatagramPacket(msg.retain(), new InetSocketAddress(host, port)));
+ out.add(new DatagramPacket(msg.retain(), host != null ? new InetSocketAddress(host, port) : new InetSocketAddress(port)));
}
});
@@ -103,7 +104,7 @@ public class UdpIoClient<T> extends AbstractNettyIoClient<T, InetSocketAddress>
@Override
public String getClientUri() {
- return "udp://" + host + ":" + port + " (bindPort: " + bindPort + ")";
+ return "udp://" + (host != null ? host : "0.0.0.0") + ":" + port + " (bindPort: " + bindPort + ")";
}
@Override
diff --git a/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptorImpl.java b/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptorImpl.java
index 65cb83841..a34633828 100644
--- a/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptorImpl.java
+++ b/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptorImpl.java
@@ -283,6 +283,23 @@ public class MetaItemDescriptorImpl implements MetaItemDescriptor {
isSecret);
}
+ @JsIgnore
+ public static MetaItemDescriptor metaItemNumber(String urn, Access access, boolean required, Double minValue, Double maxValue) {
+ return new MetaItemDescriptorImpl(
+ urn,
+ ValueType.NUMBER,
+ access,
+ required,
+ null,
+ null,
+ 1,
+ minValue != null ? Values.create(minValue) : null,
+ false,
+ minValue != null ? Values.create(minValue) : null,
+ maxValue != null ? Values.create(maxValue) : null,
+ null,
+ false);
+ }
@JsIgnore
public static MetaItemDescriptor metaItemInteger(String urn, Access access, boolean required, Integer minValue, Integer maxValue) {