Sfoglia il codice sorgente

add coap网络组件

18339543638 4 anni fa
parent
commit
0af8d77d47

+ 7 - 1
jetlinks-components/network-component/coap-component/src/main/java/org/jetlinks/community/network/coap/gateway/CoapServerDeviceGateway.java

@@ -168,7 +168,13 @@ public class CoapServerDeviceGateway implements DeviceGateway, MonitorSupportDev
     private Mono<?> decodeAndHandleMessage(DeviceOperator operator, CoapExchangeMessage exchangeMessage) {
         return operator
             .getProtocol()
-            .flatMap(protocol -> protocol.getMessageCodec(getTransport()))
+            .flatMap(protocol -> {
+                if(coapServer.isDtls()){
+                    return  protocol.getMessageCodec(DefaultTransport.CoAP_DTLS);
+                }else {
+                    return  protocol.getMessageCodec(DefaultTransport.CoAP);
+                }
+            })
             .flatMapMany(codec -> codec.decode(FromDeviceMessageContext.of(sessionManager.getSession(operator.getDeviceId()), exchangeMessage, registry)))
             .cast(DeviceMessage.class)
             .flatMap(msg -> {

+ 4 - 3
jetlinks-components/network-component/coap-component/src/main/java/org/jetlinks/community/network/coap/server/NetWorkCoapServer.java

@@ -12,7 +12,6 @@ import org.jetlinks.community.network.coap.resources.*;
 import org.jetlinks.core.message.codec.CoapExchangeMessage;
 import reactor.core.publisher.EmitterProcessor;
 import reactor.core.publisher.Flux;
-import reactor.core.publisher.FluxSink;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.function.Function;
 
@@ -20,7 +19,7 @@ import java.util.function.Function;
  * @author lifang
  * @version 1.0.0
  * @ClassName NetWorkCoapServer.java
- * @Description TODO
+ * @Description coap服务
  * @createTime 2021年12月16日 08:57:00
  */
 public class NetWorkCoapServer extends CoapServer implements Network {
@@ -31,7 +30,6 @@ public class NetWorkCoapServer extends CoapServer implements Network {
     @Getter
     private String id;
     private final EmitterProcessor<CoapExchangeMessage> processor=EmitterProcessor.create();
-    private final FluxSink<CoapExchangeMessage> sink=processor.sink(FluxSink.OverflowStrategy.BUFFER);
 
     public NetWorkCoapServer( CoapServerProperties properties,String id){
         super();
@@ -81,6 +79,9 @@ public class NetWorkCoapServer extends CoapServer implements Network {
         }
     }
 
+    public boolean isDtls(){
+        return Boolean.TRUE.equals(properties.isEnableDtls());
+    }
 
     public Flux<CoapExchangeMessage> handleAuthRequest(){
         return processor.map(Function.identity());

+ 1 - 1
jetlinks-components/network-component/network-core/src/main/java/org/jetlinks/community/support/JetLinksExtendCoapDTLSDeviceMessageCodec.java

@@ -32,7 +32,7 @@ public class JetLinksExtendCoapDTLSDeviceMessageCodec extends JetlinksExtendTopi
             String sign = message.getStringOption(2110).orElse(null);
             String token = message.getStringOption(2111).orElse(null);
             String payload = message.getPayload().toString(StandardCharsets.UTF_8);
-            if ("/auth".equals(path)) {
+            if (path.endsWith("/auth")) {
                 //认证
                 return context.getDevice()
                         .getConfig("secureKey")

+ 28 - 0
jetlinks-manager/device-manager/src/main/java/org/jetlinks/community/device/web/DictionaryController.java

@@ -0,0 +1,28 @@
+package org.jetlinks.community.device.web;
+
+
+import lombok.AllArgsConstructor;
+import org.hswebframework.web.authorization.annotation.Resource;
+import org.jetlinks.community.device.enums.DeviceLogType;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import reactor.core.publisher.Flux;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName DictionaryController.java
+ * @Description TODO
+ * @createTime 2021年12月22日 17:36:00
+ */
+@RestController
+@RequestMapping("dictionary/")
+@Resource(id = "dictionary", name = "字典")
+@AllArgsConstructor
+public class DictionaryController {
+    @GetMapping("device-log-type/items")
+    public Flux<DeviceLogType> deviceLogType(){
+        return Flux.fromArray(DeviceLogType.values());
+    }
+}