Commit 7c7a8e0ce2b4865b46c3c6a52daa377b850b2228

Authored by 云中非
1 parent 92e8f8d5

refactor: 脚本引擎模板调整

1、输入参为:msg
2、输出参数为:out
@@ -26,6 +26,7 @@ public class YtTcpDeviceProfileTransportConfiguration implements DeviceProfileTr @@ -26,6 +26,7 @@ public class YtTcpDeviceProfileTransportConfiguration implements DeviceProfileTr
26 @NoXss 26 @NoXss
27 private TcpDataTypeEnum dataFormat = TcpDataTypeEnum.HEX; 27 private TcpDataTypeEnum dataFormat = TcpDataTypeEnum.HEX;
28 private String scriptId; 28 private String scriptId;
  29 + private String scriptText;
29 private String pingText; 30 private String pingText;
30 31
31 @Override 32 @Override
@@ -21,11 +21,11 @@ public class YtTcpScriptFactory { @@ -21,11 +21,11 @@ public class YtTcpScriptFactory {
21 21
22 public static final String RULE_NODE_FUNCTION_NAME = "tcpTransportFunc"; 22 public static final String RULE_NODE_FUNCTION_NAME = "tcpTransportFunc";
23 23
24 - private static final String JS_WRAPPER_PREFIX_TEMPLATE = "function %s(msgStr) { " +  
25 - " var msg = JSON.parse(msgStr); " + 24 + private static final String JS_WRAPPER_PREFIX_TEMPLATE = "function %s(msg) { " +
  25 + " var out = new Object(); " +
26 " return JSON.stringify(%s(msg));" + 26 " return JSON.stringify(%s(msg));" +
27 " function %s(%s) {"; 27 " function %s(%s) {";
28 - private static final String JS_WRAPPER_SUFFIX = "\n}" + 28 + private static final String JS_WRAPPER_SUFFIX = "return out; \n }" +
29 "\n}"; 29 "\n}";
30 30
31 31
@@ -119,11 +119,11 @@ public class DeviceSessionCtx extends DeviceAwareSessionContext { @@ -119,11 +119,11 @@ public class DeviceSessionCtx extends DeviceAwareSessionContext {
119 payloadType = TcpDataTypeEnum.HEX; 119 payloadType = TcpDataTypeEnum.HEX;
120 } 120 }
121 this.pingText = ByteUtils.getBytes(tcpConfiguration.getPingText(),ByteUtils.UTF_8); 121 this.pingText = ByteUtils.getBytes(tcpConfiguration.getPingText(),ByteUtils.UTF_8);
122 - String jsBody="return {msg: msg, metadata: 456, msgType: 789};"; 122 + String scriptBody = tcpConfiguration.getScriptText();
123 try { 123 try {
124 - this.scriptId = this.adaptor.getJsScriptEngineFunctionId(jsBody); 124 + this.scriptId = this.adaptor.getJsScriptEngineFunctionId(scriptBody);
125 } catch (ExecutionException e) { 125 } catch (ExecutionException e) {
126 - log.warn("设备配置【{}】的脚本【{}】解析异常",deviceProfile.getSearchText(),jsBody); 126 + log.warn("设备配置【{}】的脚本【{}】解析异常",deviceProfile.getSearchText(),scriptBody);
127 throw new RuntimeException(e); 127 throw new RuntimeException(e);
128 } catch (InterruptedException e) { 128 } catch (InterruptedException e) {
129 throw new RuntimeException(e); 129 throw new RuntimeException(e);