|
@@ -9,8 +9,14 @@ import org.hswebframework.web.authorization.annotation.QueryAction;
|
|
|
import org.hswebframework.web.authorization.annotation.Resource;
|
|
|
import org.hswebframework.web.authorization.annotation.SaveAction;
|
|
|
import org.hswebframework.web.crud.web.reactive.ReactiveServiceCrudController;
|
|
|
+import org.jetlinks.community.device.web.protocol.ProtocolDetail;
|
|
|
+import org.jetlinks.community.device.web.protocol.ProtocolInfo;
|
|
|
+import org.jetlinks.community.device.web.protocol.TransportInfo;
|
|
|
+import org.jetlinks.community.device.web.request.ProtocolDecodeRequest;
|
|
|
+import org.jetlinks.community.device.web.request.ProtocolEncodeRequest;
|
|
|
import org.jetlinks.core.ProtocolSupport;
|
|
|
import org.jetlinks.core.ProtocolSupports;
|
|
|
+import org.jetlinks.core.message.Message;
|
|
|
import org.jetlinks.core.message.codec.DefaultTransport;
|
|
|
import org.jetlinks.core.message.codec.Transport;
|
|
|
import org.jetlinks.core.metadata.ConfigMetadata;
|
|
@@ -18,6 +24,8 @@ import org.jetlinks.core.metadata.unit.ValueUnit;
|
|
|
import org.jetlinks.core.metadata.unit.ValueUnits;
|
|
|
import org.jetlinks.community.device.entity.ProtocolSupportEntity;
|
|
|
import org.jetlinks.community.device.service.LocalProtocolSupportService;
|
|
|
+import org.jetlinks.supports.protocol.management.ProtocolSupportDefinition;
|
|
|
+import org.jetlinks.supports.protocol.management.ProtocolSupportLoader;
|
|
|
import org.jetlinks.supports.protocol.management.ProtocolSupportLoaderProvider;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -43,6 +51,9 @@ public class ProtocolSupportController implements
|
|
|
@Autowired
|
|
|
private List<ProtocolSupportLoaderProvider> providers;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ProtocolSupportLoader supportLoader;
|
|
|
+
|
|
|
@PostMapping("/{id}/_deploy")
|
|
|
@SaveAction
|
|
|
public Mono<Boolean> deploy(@PathVariable String id) {
|
|
@@ -88,37 +99,48 @@ public class ProtocolSupportController implements
|
|
|
.map(TransportInfo::of);
|
|
|
}
|
|
|
|
|
|
- @GetMapping("/units")
|
|
|
- @Authorize(merge = false)
|
|
|
- public Flux<ValueUnit> allUnits() {
|
|
|
- return Flux.fromIterable(ValueUnits.getAllUnit());
|
|
|
+ @PostMapping("/convert")
|
|
|
+ @QueryAction
|
|
|
+ public Mono<ProtocolDetail> convertToDetail(@RequestBody Mono<ProtocolSupportEntity> entity) {
|
|
|
+ return entity.map(ProtocolSupportEntity::toDeployDefinition)
|
|
|
+ .doOnNext(def -> def.setId("_debug"))
|
|
|
+ .flatMap(def -> supportLoader.load(def))
|
|
|
+ .flatMap(ProtocolDetail::of);
|
|
|
}
|
|
|
|
|
|
- @Getter
|
|
|
- @Setter
|
|
|
- @AllArgsConstructor(staticName = "of")
|
|
|
- @NoArgsConstructor
|
|
|
- public static class TransportInfo {
|
|
|
- private String id;
|
|
|
-
|
|
|
- private String name;
|
|
|
-
|
|
|
- static TransportInfo of(Transport support) {
|
|
|
- return of(support.getId(), support.getName());
|
|
|
- }
|
|
|
+ @PostMapping("/decode")
|
|
|
+ @SaveAction
|
|
|
+ public Flux<Message> decode(@RequestBody Mono<ProtocolDecodeRequest> entity) {
|
|
|
+ return entity
|
|
|
+ .flatMapMany(request -> {
|
|
|
+ ProtocolSupportDefinition supportEntity = request.getEntity().toDeployDefinition();
|
|
|
+ supportEntity.setId("_debug");
|
|
|
+ return supportLoader.load(supportEntity)
|
|
|
+ .flatMapMany(protocol -> request
|
|
|
+ .getRequest()
|
|
|
+ .doDecode(protocol, null));
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- @Getter
|
|
|
- @Setter
|
|
|
- @AllArgsConstructor(staticName = "of")
|
|
|
- @NoArgsConstructor
|
|
|
- public static class ProtocolInfo {
|
|
|
- private String id;
|
|
|
+ @PostMapping("/encode")
|
|
|
+ @SaveAction
|
|
|
+ public Flux<Object> encode(@RequestBody Mono<ProtocolEncodeRequest> entity) {
|
|
|
+ return entity
|
|
|
+ .flatMapMany(request -> {
|
|
|
+ ProtocolSupportDefinition supportEntity = request.getEntity().toDeployDefinition();
|
|
|
+ supportEntity.setId("_debug");
|
|
|
+ return supportLoader.load(supportEntity)
|
|
|
+ .flatMapMany(protocol -> request
|
|
|
+ .getRequest()
|
|
|
+ .doEncode(protocol, null));
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- private String name;
|
|
|
|
|
|
- static ProtocolInfo of(ProtocolSupport support) {
|
|
|
- return of(support.getId(), support.getName());
|
|
|
- }
|
|
|
+ @GetMapping("/units")
|
|
|
+ @Authorize(merge = false)
|
|
|
+ public Flux<ValueUnit> allUnits() {
|
|
|
+ return Flux.fromIterable(ValueUnits.getAllUnit());
|
|
|
}
|
|
|
+
|
|
|
}
|