From e33026ce9045e9beaedc8a34e7a3b21bf9c96a67 Mon Sep 17 00:00:00 2001 From: bambooww Date: Thu, 12 Dec 2024 20:21:09 +0800 Subject: [PATCH] 1.7.4 --- core/pom.xml | 2 +- .../main/java/org/iottree/core/ConnPt.java | 3 +- core/src/main/java/org/iottree/core/UACh.java | 20 +- .../java/org/iottree/core/UANodeOCTags.java | 22 +- .../src/main/java/org/iottree/core/UAPrj.java | 29 +- .../src/main/java/org/iottree/core/UATag.java | 8 +- .../org/iottree/core/conn/ConnProUDP.java | 60 +++- .../iottree/core/conn/ConnPtMSGMultiTcp.java | 90 +++--- .../java/org/iottree/core/conn/ConnPtMsg.java | 80 ++++- .../org/iottree/core/conn/ConnPtUDPMsg.java | 269 ++++++++++++++-- .../java/org/iottree/core/cxt/UAContext.java | 11 +- .../java/org/iottree/core/msgnet/MNBase.java | 3 + .../java/org/iottree/core/msgnet/MNNet.java | 14 + .../msgnet/modules/RelationalDB_Table.java | 53 ++++ .../core/msgnet/nodes/NM_Template.java | 2 + .../org/iottree/core/msgnet/nodes/lang.xml | 2 +- .../iottree/core/node/PrjShareManager.java | 18 +- .../java/org/iottree/core/sim/SimContext.java | 79 ++++- .../org/iottree/core/sim/SimInstance.java | 2 +- .../org/iottree/driver/common/JsonJSDrv.java | 2 +- .../org/iottree/driver/common/MsgJSDrv.java | 286 ++++++++++++++++++ .../org/iottree/driver/common/prop_lang.xml | 2 + driver-parent/driver-opc/pom.xml | 2 +- ext-parent/ext-basic/pom.xml | 4 +- .../org/iottree/ext/msg_net/TCPClient_NM.java | 161 ++++++++++ .../org/iottree/ext/msg_net/UDPIn_NS.java | 6 + .../org/iottree/ext/msg_net/UDPOut_NE.java | 6 + .../java/org/iottree/ext/msg_net/lang.xml | 14 + ext-parent/pom.xml | 4 +- server/pom.xml | 2 +- web/ROOT/pom.xml | 2 +- web/admin/conn/cpt_edit_multi_tcp_msg.jsp | 4 +- web/admin/conn/cpt_edit_udp_msg.jsp | 230 ++++++++++++++ web/admin/mn/nodes/_func.template.pm.jsp | 16 +- .../mn/nodes/_storage.r_db.r_db_tb.pm.jsp | 16 +- web/admin/pom.xml | 2 +- web/admin/ua/drv/drv.msg_js.config.jsp | 214 +++++++++++++ web/admin/ua_cxt/cxt_script.jsp | 4 + web/admin/ua_cxt/tag_trans_edit.jsp | 2 +- web/doc/pom.xml | 2 +- web/main/pom.xml | 2 +- web/pom.xml | 2 +- 42 files changed, 1644 insertions(+), 108 deletions(-) create mode 100644 driver-parent/driver-common/src/main/java/org/iottree/driver/common/MsgJSDrv.java create mode 100644 ext-parent/ext-basic/src/main/java/org/iottree/ext/msg_net/TCPClient_NM.java create mode 100644 ext-parent/ext-basic/src/main/java/org/iottree/ext/msg_net/UDPIn_NS.java create mode 100644 ext-parent/ext-basic/src/main/java/org/iottree/ext/msg_net/UDPOut_NE.java create mode 100644 ext-parent/ext-basic/src/main/java/org/iottree/ext/msg_net/lang.xml create mode 100644 web/admin/conn/cpt_edit_udp_msg.jsp create mode 100644 web/admin/ua/drv/drv.msg_js.config.jsp diff --git a/core/pom.xml b/core/pom.xml index 409972e5..48ed947e 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -5,7 +5,7 @@ org.iottree iottree-parent - 1.7.3 + 1.7.4 ../pom.xml diff --git a/core/src/main/java/org/iottree/core/ConnPt.java b/core/src/main/java/org/iottree/core/ConnPt.java index eac9bf89..31dba495 100644 --- a/core/src/main/java/org/iottree/core/ConnPt.java +++ b/core/src/main/java/org/iottree/core/ConnPt.java @@ -8,6 +8,7 @@ import java.util.LinkedList; import java.util.List; +import org.iottree.core.cxt.JSObMap; import org.iottree.core.util.CompressUUID; import org.iottree.core.util.Convert; import org.iottree.core.util.xmldata.IXmlDataValidator; @@ -20,7 +21,7 @@ * @author jason.zhu * */ -public abstract class ConnPt implements IXmlDataValidator +public abstract class ConnPt extends JSObMap implements IXmlDataValidator { private static int cc = 0 ; private static long last_id_dt = -1 ; diff --git a/core/src/main/java/org/iottree/core/UACh.java b/core/src/main/java/org/iottree/core/UACh.java index 07b330c5..a2484df0 100644 --- a/core/src/main/java/org/iottree/core/UACh.java +++ b/core/src/main/java/org/iottree/core/UACh.java @@ -592,6 +592,15 @@ public boolean delFromParent() throws Exception * 1��node��s self prop group * 2) driver's group */ + + public static final String PG_DRV_SPC_CONF = "ch_drv_spc_conf" ; + public static final String PI_DRV_CONF = "ch_drv_conf" ; + + public String getDrvSpcConfigTxt() + { + return (String)getPropValue(PG_DRV_SPC_CONF,PI_DRV_CONF); + } + @Override public List listPropGroups() { @@ -609,8 +618,8 @@ public List listPropGroups() if(uad.hasDriverConfigPage()) { Lan lan = Lan.getPropLangInPk(this.getClass()) ; - PropGroup gp = new PropGroup("ch_drv_spc_conf",lan);//"Timing");; - gp.addPropItem(new PropItem("ch_drv_conf",lan,PValTP.vt_str,false,null,null,"") + PropGroup gp = new PropGroup(PG_DRV_SPC_CONF,lan);//"Timing");; + gp.addPropItem(new PropItem(PI_DRV_CONF,lan,PValTP.vt_str,false,null,null,"") .withPop("drv_spc") ); pgs.add(gp) ; @@ -824,7 +833,12 @@ public boolean RT_startDriver(StringBuilder failedr) throws Exception } //finally - return drv.RT_start(failedr) ; + boolean ret = drv.RT_start(failedr) ; + if(!ret) + { + + } + return ret ; } public boolean RT_stopDriver(boolean bforce) diff --git a/core/src/main/java/org/iottree/core/UANodeOCTags.java b/core/src/main/java/org/iottree/core/UANodeOCTags.java index 9f3e4907..2857d2bf 100644 --- a/core/src/main/java/org/iottree/core/UANodeOCTags.java +++ b/core/src/main/java/org/iottree/core/UANodeOCTags.java @@ -568,6 +568,11 @@ public UATag addTag(DevItem item) throws Exception } public UATag addTag(String name,String title,String desc,UAVal.ValTP vt,boolean bsave) throws Exception + { + return addTag(name,title,desc,vt,false,bsave); + } + + public UATag addTag(String name,String title,String desc,UAVal.ValTP vt,boolean canwrite,boolean bsave) throws Exception { UAUtil.assertUAName(name); UANode tmpn = getSubNodeByName(name); @@ -581,15 +586,22 @@ public UATag addTag(String name,String title,String desc,UAVal.ValTP vt,boolean UATag d = new UATag(name,title,desc,null,vt,0,false,200); d.id = this.getNextIdByRoot(); + d.bCanWrite = canwrite; tags.add(d); constructNodeTree(); this.bDirty = true ; + this.clearJsNames(); if(bsave) save(); return d; } public UATag getOrAddTag(String name,String title,String desc,UAVal.ValTP vt,boolean bsave) throws Exception + { + return getOrAddTag(name,title,desc,vt,false,bsave) ; + } + + public UATag getOrAddTag(String name,String title,String desc,UAVal.ValTP vt,boolean canwrite,boolean bsave) throws Exception { UANode tmpn = this.getSubNodeByName(name) ; if(tmpn!=null) @@ -600,16 +612,16 @@ public UATag getOrAddTag(String name,String title,String desc,UAVal.ValTP vt,boo return (UATag)tmpn ; } - return addTag(name,title,desc,vt,bsave) ; + return addTag(name,title,desc,vt,canwrite,bsave) ; } - @JsDef - private UATag get_add_tag(String name,String title,String desc,String vtstr,boolean bsave) throws Exception + @JsDef(method_params_title="name,title,description,val tp str,canwrite,bsave") + private UATag get_add_tag(String name,String title,String desc,String vtstr,boolean canwrite,boolean bsave) throws Exception { UAVal.ValTP vt = UAVal.getValTp(vtstr) ; if(vt==null) throw new IllegalArgumentException("unknown vt "+vtstr) ; - return getOrAddTag(name,title,desc, vt,bsave) ; + return getOrAddTag(name,title,desc, vt,canwrite,bsave) ; } public boolean delTag(UATag t) throws Exception @@ -1032,7 +1044,7 @@ protected void RT_flush() { } - + final void RT_runFlush() { this.RT_flush(); diff --git a/core/src/main/java/org/iottree/core/UAPrj.java b/core/src/main/java/org/iottree/core/UAPrj.java index 49f6f60c..6502f156 100644 --- a/core/src/main/java/org/iottree/core/UAPrj.java +++ b/core/src/main/java/org/iottree/core/UAPrj.java @@ -1472,7 +1472,7 @@ public void run() if(!b_station_ins) { - RT_runFlush(); + runFlush(); runMidTagsScript(); runScriptInterval(); runShareInterval(); @@ -1517,7 +1517,7 @@ public void run() stopPrj(); - RT_runFlush(); + runFlush(); AlertManager.getInstance(UAPrj.this.getId()).RT_stop(); @@ -1562,6 +1562,31 @@ public PrjSharer getSharer() { return PrjShareManager.getInstance().getSharer(this.getId()); } + + private transient long lastRunFlush = -1 ; + + final void runFlush() + { + if(System.currentTimeMillis()-lastRunFlush<500) + return ; + + try + { + this.RT_runFlush(); + for (UANode subn : this.getSubNodes()) + { + if (subn instanceof UANodeOCTags) + { + ((UANodeOCTags) subn).RT_runFlush(); + } + } + } + finally + { + lastRunFlush = System.currentTimeMillis() ; + } + } + private void runShareInterval() { diff --git a/core/src/main/java/org/iottree/core/UATag.java b/core/src/main/java/org/iottree/core/UATag.java index 6a223af9..1ce1b1f2 100644 --- a/core/src/main/java/org/iottree/core/UATag.java +++ b/core/src/main/java/org/iottree/core/UATag.java @@ -1192,7 +1192,10 @@ UAVal CXT_calMidVal() //this.RT_set return null; } + //long st = System.currentTimeMillis() ; + //long stn = System.nanoTime() ; Object ob = ci.runCode() ; + //System.out.println("cost="+(System.currentTimeMillis()-st)+" nano="+(System.nanoTime()-stn)) ; return this.RT_setValRaw(ob); //v.setVal(true, ob, System.currentTimeMillis()); @@ -1537,8 +1540,9 @@ private boolean RT_writeValDriver(Object v) StringBuilder sb = new StringBuilder() ; DevAddr da = this.getDevAddr(sb); - if(da==null) - return false; + //if(da==null) + // return false; + UACh ch = this.getBelongToCh() ; if(ch==null) return false; //must has channel diff --git a/core/src/main/java/org/iottree/core/conn/ConnProUDP.java b/core/src/main/java/org/iottree/core/conn/ConnProUDP.java index b445fdec..34d436d9 100644 --- a/core/src/main/java/org/iottree/core/conn/ConnProUDP.java +++ b/core/src/main/java/org/iottree/core/conn/ConnProUDP.java @@ -1,11 +1,13 @@ package org.iottree.core.conn; +import java.util.List; + import org.iottree.core.ConnProvider; import org.iottree.core.ConnPt; public class ConnProUDP extends ConnProvider { - public static final String TP ="udp" ; + public static final String TP ="udp_msg" ; @Override @@ -17,7 +19,7 @@ public String getProviderType() @Override public String getProviderTpt() { - return "UDP" ; + return "UDP Msg" ; } @Override @@ -39,10 +41,62 @@ protected long connpRunInterval() { return 1000; } + + public void start() throws Exception + { + List pts = this.listConns() ; + if(pts==null||pts.size()<=0) + return ; + + super.start(); + + for(ConnPt ci:pts) + { + if(!ci.isEnable()) + continue ; + try + { + ConnPtUDPMsg conn = (ConnPtUDPMsg)ci ; + conn.RT_start() ; + } + catch(Exception e) + { + e.printStackTrace(); + } + } + } @Override - protected void connpRunInLoop() throws Exception + public void stop() { + super.stop() ; + for(ConnPt ci:this.listConns()) + { + try + { + ConnPtUDPMsg conn = (ConnPtUDPMsg)ci ; + conn.RT_stop(); + } + catch(Exception e) + { + e.printStackTrace(); + } + } + } + + + + @Override + protected void connpRunInLoop() throws Exception + { +// for(ConnPt ci:this.listConns()) +// { +// if(!ci.isEnable()) +// continue ; +// +// ConnPtUDPMsg citc = (ConnPtUDPMsg)ci ; +// citc.RT_checkConn() ; +// } } } diff --git a/core/src/main/java/org/iottree/core/conn/ConnPtMSGMultiTcp.java b/core/src/main/java/org/iottree/core/conn/ConnPtMSGMultiTcp.java index e9e0dcaf..e5a2504f 100644 --- a/core/src/main/java/org/iottree/core/conn/ConnPtMSGMultiTcp.java +++ b/core/src/main/java/org/iottree/core/conn/ConnPtMSGMultiTcp.java @@ -806,9 +806,10 @@ public void RT_runInLoop(SockItem si) throws Exception switch(RT_st) { case 0: - int len = inputs.available() ; + int len = RT_chkAvailableTO(inputs) ; if(len<=0) return ; + RT_lastDT = System.currentTimeMillis() ; RT_rlen = len ; RT_st = 1 ; @@ -1093,6 +1094,7 @@ boolean RT_sendOut(byte[] bs,StringBuilder failedr) failedr.append(ee.getMessage()) ; if(log.isDebugEnabled()) log.debug(ee); + si.dispose(); return false; } } @@ -1598,6 +1600,8 @@ private static TcpRunner transJO2Runner(JSONObject jo) public static final String TP = "multi_tcp_msg" ; + //long recv_broken_to = 60000 ; + TcpRunner tcpRunner = null ; TcpDataPro dataPro = null ; @@ -1614,6 +1618,15 @@ public String getStaticTxt() { return null; } + +// /** +// * will tcp broken ,when recv no data during this to +// * @return +// */ +// public long getRecvBrokenTO() +// { +// return recv_broken_to; +// } @Override public void RT_checkConn() @@ -1647,6 +1660,7 @@ public TcpDataPro getTcpDataPro() public XmlData toXmlData() { XmlData xd = super.toXmlData() ; + //xd.setParamValue("recv_broken_to", recv_broken_to); if(tcpRunner!=null) xd.setSubDataSingle("tcp_run", tcpRunner.toXmlData()); if(dataPro!=null) @@ -1658,6 +1672,10 @@ public boolean fromXmlData(XmlData xd,StringBuilder failedr) { if(!super.fromXmlData(xd, failedr)) return false; +// recv_broken_to = xd.getParamValueInt64("recv_broken_to", 60000) ; +// if(recv_broken_to<=0) +// recv_broken_to = 60000 ; + XmlData tmpxd = xd.getSubDataSingle("tcp_run") ; this.tcpRunner = transXD2Runner(tmpxd) ; tmpxd = xd.getSubDataSingle("data_pro") ; @@ -1670,6 +1688,9 @@ protected void injectByJson(JSONObject jo) throws Exception if(this.RT_isRunning()) throw new Exception("cannot set while in running") ; super.injectByJson(jo); +// recv_broken_to = jo.optLong("recv_broken_to",60000) ; +// if(recv_broken_to<=0) +// recv_broken_to = 60000 ; JSONObject tmpjo = jo.optJSONObject("tcp_run") ; this.tcpRunner = transJO2Runner(tmpjo) ; tmpjo = jo.optJSONObject("data_pro") ; @@ -1685,39 +1706,39 @@ protected void injectByJson(JSONObject jo) throws Exception // } - private transient boolean drvMsgOnlyGotten = false; - private transient DevDriverMsgOnly drvMsgOnly = null ; - - private DevDriverMsgOnly getDriverMsgOnly() - { - if(drvMsgOnlyGotten) - return drvMsgOnly ; - - try - { - UACh ch = this.getJoinedCh() ; - if(ch==null) - return null; - DevDriver dd = ch.getDriver() ; - if(dd==null) - return null; - - if(dd instanceof DevDriverMsgOnly) - { - drvMsgOnly = (DevDriverMsgOnly)dd ; - } - return drvMsgOnly ; - } - catch(Exception e) - { - log.warn(e); - return null ; - } - finally - { - drvMsgOnlyGotten = true ; - } - } +// private transient boolean drvMsgOnlyGotten = false; +// private transient DevDriverMsgOnly drvMsgOnly = null ; +// +// private DevDriverMsgOnly getDriverMsgOnly() +// { +// if(drvMsgOnlyGotten) +// return drvMsgOnly ; +// +// try +// { +// UACh ch = this.getJoinedCh() ; +// if(ch==null) +// return null; +// DevDriver dd = ch.getDriver() ; +// if(dd==null) +// return null; +// +// if(dd instanceof DevDriverMsgOnly) +// { +// drvMsgOnly = (DevDriverMsgOnly)dd ; +// } +// return drvMsgOnly ; +// } +// catch(Exception e) +// { +// log.warn(e); +// return null ; +// } +// finally +// { +// drvMsgOnlyGotten = true ; +// } +// } private void RT_onMsgGit(byte[] msg) { @@ -1732,7 +1753,6 @@ private void RT_onMsgGit(byte[] msg) @Override public boolean RT_supportSendMsgOut() { - return true; } diff --git a/core/src/main/java/org/iottree/core/conn/ConnPtMsg.java b/core/src/main/java/org/iottree/core/conn/ConnPtMsg.java index dbd1956c..1dc8a1a7 100644 --- a/core/src/main/java/org/iottree/core/conn/ConnPtMsg.java +++ b/core/src/main/java/org/iottree/core/conn/ConnPtMsg.java @@ -2,19 +2,75 @@ import org.iottree.core.ConnProvider; import org.iottree.core.ConnPt; +import org.iottree.core.DevDriver; +import org.iottree.core.DevDriverMsgOnly; +import org.iottree.core.UACh; import org.iottree.core.UAPrj; +import org.iottree.core.cxt.IJsProp; +import org.iottree.core.cxt.JsDef; +import org.iottree.core.cxt.JsProp; import org.iottree.core.msgnet.MNManager; -public abstract class ConnPtMsg extends ConnPt +public abstract class ConnPtMsg extends ConnPt implements IJsProp { public ConnPtMsg() {} - + public ConnPtMsg(ConnProvider cp,String name,String title,String desc) { super(cp,name,title,desc) ; } + private JsProp jsP = null; + + @Override + public JsProp toJsProp() + { + if(jsP!=null) + return jsP ; + jsP = new JsProp("$connpt",this,null,true,"ConnPtMsg","Channel relateed ConnPtMsg") ; + return jsP; + } + + @Override + public void constructSubForCxtHelper() + { + + } + + private transient boolean drvMsgOnlyGotten = false; + private transient DevDriverMsgOnly drvMsgOnly = null ; + + protected final DevDriverMsgOnly getDriverMsgOnly() + { + if(drvMsgOnlyGotten) + return drvMsgOnly ; + + try + { + UACh ch = this.getJoinedCh() ; + if(ch==null) + return null; + DevDriver dd = ch.getDriver() ; + if(dd==null) + return null; + + if(dd instanceof DevDriverMsgOnly) + { + drvMsgOnly = (DevDriverMsgOnly)dd ; + } + return drvMsgOnly ; + } + catch(Exception e) + { + e.printStackTrace(); + return null ; + } + finally + { + drvMsgOnlyGotten = true ; + } + } /** * top level recved msg * @param topic @@ -29,14 +85,34 @@ protected void RT_onMsgRecved(String topic,Object msgob) mnmgr.RT_onConnPtMsgRecved(this,topic,msgob); } + @JsDef public boolean RT_supportSendMsgOut() { return false; } + public boolean RT_sendMsgOut(String topic,byte[] msg,StringBuilder failedr) throws Exception { failedr.append("no impl") ; return false; } + + @JsDef(method_params_title = "topic,msg bytes") + public Object rt_send_msg_bytes(String topic,byte[] msg) throws Exception + { + StringBuilder failedr = new StringBuilder() ; + if(!RT_sendMsgOut(topic,msg,failedr)) + return failedr.toString() ; + return true ; + } + + @JsDef(method_params_title = "topic,msg string") + public Object rt_send_msg_str(String topic,String msg) throws Exception + { + StringBuilder failedr = new StringBuilder() ; + if(!RT_sendMsgOut(topic,msg.getBytes("UTF-8"),failedr)) + return failedr.toString() ; + return true ; + } } diff --git a/core/src/main/java/org/iottree/core/conn/ConnPtUDPMsg.java b/core/src/main/java/org/iottree/core/conn/ConnPtUDPMsg.java index c9e72a6c..8b5aa346 100644 --- a/core/src/main/java/org/iottree/core/conn/ConnPtUDPMsg.java +++ b/core/src/main/java/org/iottree/core/conn/ConnPtUDPMsg.java @@ -1,71 +1,304 @@ package org.iottree.core.conn; +import java.net.DatagramPacket; import java.net.DatagramSocket; +import java.net.InetAddress; +import org.iottree.core.ConnProvider; +import org.iottree.core.DevDriver; +import org.iottree.core.DevDriverMsgOnly; +import org.iottree.core.UACh; +import org.iottree.core.util.Convert; import org.iottree.core.util.logger.ILogger; import org.iottree.core.util.logger.LoggerManager; +import org.iottree.core.util.xmldata.XmlData; +import org.json.JSONObject; public class ConnPtUDPMsg extends ConnPtMsg { + public static final String TP = "udp_msg"; + static ILogger log = LoggerManager.getLogger(ConnPtUDPMsg.class) ; - DatagramSocket dgSock = null ; + int recvLocPort = 9001 ; + + String recvLocIP = null ; + + String host = null ; + + int port = 9002 ; + + private transient Thread recvTh = null ; + + private DatagramSocket socket = null;// new DatagramSocket(PORT) + //DatagramSocket dgSock = null ; + + private InetAddress hostAddr = null ; + public ConnPtUDPMsg() + {} + + public ConnPtUDPMsg(ConnProvider cp, String name, String title, String desc) + { + super(cp, name, title, desc); + } + + @Override + public String getConnType() + { + return TP; + } + @Override - protected void RT_connInit() throws Exception + public String getStaticTxt() + { + return this.host+":"+this.port; + } + + public String getHost() { - super.RT_connInit(); + if(this.host==null) + return "" ; + return this.host ; + } + + public int getPort() + { + return this.port ; + } + + public int getRecvLocPort() + { + return this.recvLocPort; + } + + public String getRecvLocIP() + { + if(this.recvLocIP==null) + return "" ; + return this.recvLocIP ; } - @Override - public String getConnType() + public XmlData toXmlData() { - return "udp_msg"; + XmlData xd = super.toXmlData(); + xd.setParamValue("host", host); + xd.setParamValue("port", port); + xd.setParamValue("loc_ip", this.recvLocIP); + xd.setParamValue("loc_port", this.recvLocPort); + return xd; } @Override - public String getStaticTxt() + public boolean fromXmlData(XmlData xd, StringBuilder failedr) { - // TODO Auto-generated method stub - return null; + boolean r = super.fromXmlData(xd, failedr); + this.host = xd.getParamValueStr("host"); + this.port = xd.getParamValueInt32("port", 9002); + this.recvLocIP = xd.getParamValueStr("loc_ip"); + this.recvLocPort = xd.getParamValueInt32("loc_port", 9001); + return r; } + protected void injectByJson(JSONObject jo) throws Exception + { + super.injectByJson(jo); + + this.host = jo.getString("host"); + this.port = jo.optInt("port",9002); + this.recvLocIP = jo.optString("loc_ip"); + this.recvLocPort = jo.optInt("loc_port",9001); + if(this.recvLocPort<=0) + this.recvLocPort = 9001 ; + } + + + @Override public boolean isConnReady() { - // TODO Auto-generated method stub - return false; + return socket!=null; } - private long lastChk = -1 ; + //private long lastChk = -1 ; public void RT_checkConn() { - if(System.currentTimeMillis()-lastChk<5000) + + } + + private Runnable recvRunner = new Runnable() { + + @Override + public void run() + { + RT_runRecv() ; + }} ; + + private transient InetAddress lastRecvRemoteAddr = null ; + + private transient int lastRecvRemotePort = -1 ; + + private void RT_runRecv() + { + try + { + byte[] buffer = new byte[2048]; + DatagramPacket packet = new DatagramPacket(buffer, buffer.length); + + while(recvTh!=null) + { + socket.receive(packet); + lastRecvRemoteAddr = packet.getAddress() ; + lastRecvRemotePort = packet.getPort() ; + + onRecvData(packet.getData(),packet.getLength()); + } + } + catch(Exception ee) + { + if(log.isDebugEnabled()) + log.debug(ee); + } + finally + { + recvTh = null ; + disconnect() ; + } + } + + private void onRecvData(byte[] data,int len) + { + byte[] msg = new byte[len] ; + System.arraycopy(data, 0, msg, 0, len); + this.RT_onMsgRecved(null,msg); + + DevDriverMsgOnly drv = getDriverMsgOnly() ; + if(drv==null) return ; + drv.RT_onConnMsgIn(msg); + } + + @Override + public boolean RT_supportSendMsgOut() + { + return true; + } + + @Override + public boolean RT_sendMsgOut(String topic,byte[] msg,StringBuilder failedr) throws Exception + { + if(this.socket==null) + { + failedr.append("no udp socket") ; + return false; + } + + InetAddress tar_addr = hostAddr; + int tar_port = this.port; + if(tar_addr==null) + { + tar_addr = this.lastRecvRemoteAddr ; + tar_port = this.lastRecvRemotePort ; + } + if(tar_addr==null||tar_port<=0) + { + failedr.append("no remote host port set or found") ; + return false; + } + DatagramPacket pk = new DatagramPacket(msg, msg.length, tar_addr, tar_port); + socket.send(pk); + return true; + } + + public synchronized boolean RT_start() + { + if(recvTh!=null) + { + return true ; + } try { - //connectToWS(); + if(Convert.isNotNullEmpty(this.host)) + hostAddr = InetAddress.getByName(host) ; + + if(Convert.isNotNullEmpty(this.recvLocIP)) + { + InetAddress locaddr= InetAddress.getByName(recvLocIP); + socket = new DatagramSocket(this.recvLocPort, locaddr) ; + } + else + { + socket = new DatagramSocket(this.recvLocPort) ; + } + //start recv + recvTh = new Thread(recvRunner) ; + recvTh.start(); + return true ; } catch(Exception e) { if(log.isDebugEnabled()) - log.debug("connect to websocket",e); + log.debug("listen udp local failed",e); + return false; } finally { - lastChk = System.currentTimeMillis() ; + //lastChk = System.currentTimeMillis() ; } } + + public synchronized void RT_stop() + { + if(recvTh==null) + return ; + recvTh.interrupt(); + disconnect(); + recvTh = null ; + } + + public boolean RT_isRunning() + { + return recvTh!=null; + } @Override public String getConnErrInfo() { - // TODO Auto-generated method stub - return null; + if (socket == null) + return "local udp bind err"; + else + return null; + } + + @Override + public String RT_getConnRunInfo() + { + if(this.lastRecvRemoteAddr!=null) + return "Last Recv "+this.lastRecvRemoteAddr.toString()+":"+this.lastRecvRemotePort ; + return "" ; + } + + synchronized void disconnect() // throws IOException + { + if (socket == null) + return; + + try + { + socket.close(); + } + catch ( Exception e) + { + e.printStackTrace(); + } + finally + { + socket = null; + } } } diff --git a/core/src/main/java/org/iottree/core/cxt/UAContext.java b/core/src/main/java/org/iottree/core/cxt/UAContext.java index ad4b8aa0..f712df5c 100644 --- a/core/src/main/java/org/iottree/core/cxt/UAContext.java +++ b/core/src/main/java/org/iottree/core/cxt/UAContext.java @@ -37,6 +37,8 @@ import org.iottree.core.util.js.GSys; import org.iottree.core.util.js.GUtil; +import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine; + public class UAContext { // private static HashMap GVAR2OBJ = null ; @@ -211,8 +213,13 @@ public synchronized void scriptEval(String jstxt) throws ScriptException public synchronized Object scriptInvoke(String fn,Object... paramvals) throws NoSuchMethodException, ScriptException { - Invocable inv = (Invocable)getScriptEngine() ; - return inv.invokeFunction(fn, paramvals) ; + GraalJSScriptEngine se = (GraalJSScriptEngine)getScriptEngine() ; + Value func = se.getPolyglotContext().getBindings("js").getMember(fn) ; + Value res = func.execute(paramvals) ; + return res.as(Object.class) ; + +// Invocable inv = (Invocable)getScriptEngine() ; +// return inv.invokeFunction(fn, paramvals) ; } public CompiledScript scriptCompile(boolean bblock,String jstxt) throws ScriptException diff --git a/core/src/main/java/org/iottree/core/msgnet/MNBase.java b/core/src/main/java/org/iottree/core/msgnet/MNBase.java index 971e3194..423c1b42 100644 --- a/core/src/main/java/org/iottree/core/msgnet/MNBase.java +++ b/core/src/main/java/org/iottree/core/msgnet/MNBase.java @@ -346,6 +346,9 @@ protected void onAfterLoaded() // -- RT + protected void RT_onBeforeNetRun() + {} + public void RT_clean() { this.RT_CXT_clean(); diff --git a/core/src/main/java/org/iottree/core/msgnet/MNNet.java b/core/src/main/java/org/iottree/core/msgnet/MNNet.java index 625bf3a7..c83f903a 100644 --- a/core/src/main/java/org/iottree/core/msgnet/MNNet.java +++ b/core/src/main/java/org/iottree/core/msgnet/MNNet.java @@ -924,6 +924,18 @@ void onAfterLoaded() // - + void RT_onBeforeNetRun() + { + for(MNNode n:this.id2node.values()) + { + n.RT_onBeforeNetRun(); + } + for(MNModule m:this.id2module.values()) + { + m.RT_onBeforeNetRun(); + } + } + public JSONObject RT_getNetUpdate(List div_ids) { JSONObject jo = this.RT_toJO(true) ;//new JSONObject() ; @@ -1025,6 +1037,8 @@ public void RT_startNetFlow(StringBuilder failedr) return ; } + RT_onBeforeNetRun() ; + List ns = getStartNodes() ; for(MNNodeStart n:ns) { diff --git a/core/src/main/java/org/iottree/core/msgnet/modules/RelationalDB_Table.java b/core/src/main/java/org/iottree/core/msgnet/modules/RelationalDB_Table.java index 61f80320..3057cb48 100644 --- a/core/src/main/java/org/iottree/core/msgnet/modules/RelationalDB_Table.java +++ b/core/src/main/java/org/iottree/core/msgnet/modules/RelationalDB_Table.java @@ -1,9 +1,12 @@ package org.iottree.core.msgnet.modules; +import java.sql.Connection; +import java.util.Arrays; import java.util.List; import org.iottree.core.msgnet.MNNodeRes; import org.iottree.core.store.SourceJDBC; +import org.iottree.core.store.gdb.DBUtil; import org.iottree.core.store.gdb.connpool.DBConnPool; import org.iottree.core.store.gdb.connpool.IConnPool; import org.iottree.core.util.Convert; @@ -13,6 +16,7 @@ public class RelationalDB_Table extends MNNodeRes { String tableName = null ; + String createSql = null ; // @Override // public int getOutNum() // { @@ -53,6 +57,11 @@ public String getTableName() { return this.tableName ; } + + public String getCreateSql() + { + return createSql ; + } @Override public boolean isParamReady(StringBuilder failedr) @@ -70,6 +79,7 @@ public JSONObject getParamJO() { JSONObject jo = new JSONObject() ; jo.putOpt("table", this.tableName) ; + jo.putOpt("create_sql", this.createSql) ; return jo; } @@ -77,6 +87,7 @@ public JSONObject getParamJO() protected void setParamJO(JSONObject jo) { this.tableName = jo.optString("table") ; + this.createSql = jo.optString("create_sql") ; } // rt lines @@ -110,4 +121,46 @@ public DBConnPool RT_getConnPool() return null ; return sorjdbc.getConnPool() ; } + + protected void RT_onBeforeNetRun() + { + StringBuilder failedr = new StringBuilder() ; + createNoExistedTable(failedr) ; + } + + private boolean createNoExistedTable(StringBuilder failedr) + { + if(Convert.isNullOrEmpty(this.createSql)) + { + failedr.append("no create sql found") ; + return false; + } + DBConnPool cp = RT_getConnPool() ; + if(cp==null) + { + failedr.append("no conn pool found") ; + return false; + } + Connection conn = null ; + try + { + conn = cp.getConnection() ; + if(DBUtil.tableExists(conn, cp.getDatabase(), this.tableName)) + return true ; + + DBUtil.runSqls(conn, Arrays.asList(this.createSql)); + return true ; + } + catch(Exception ee) + { + failedr.append(ee.getMessage()) ; + RT_DEBUG_ERR.fire("RDB_table", ee.getMessage(), ee); + return false; + } + finally + { + if(conn!=null) + cp.free(conn); + } + } } diff --git a/core/src/main/java/org/iottree/core/msgnet/nodes/NM_Template.java b/core/src/main/java/org/iottree/core/msgnet/nodes/NM_Template.java index 7cb3a23c..785cbacc 100644 --- a/core/src/main/java/org/iottree/core/msgnet/nodes/NM_Template.java +++ b/core/src/main/java/org/iottree/core/msgnet/nodes/NM_Template.java @@ -132,6 +132,8 @@ protected RTOut RT_onMsgIn(MNConn in_conn, MNMsg msg) if(hd!=null) scopes.put("heads", hd); scopes.put("payload",msg.CXT_PK_getPayload()); + scopes.put("msg_dt",msg.getMsgDT()); + scopes.put("msg_id",msg.getMsgId()); scopes.put("node", this.CXT_PK_toMap()); scopes.put("flow", this.getBelongTo().CXT_PK_toMap()); diff --git a/core/src/main/java/org/iottree/core/msgnet/nodes/lang.xml b/core/src/main/java/org/iottree/core/msgnet/nodes/lang.xml index 75fa9085..e8aca7d8 100644 --- a/core/src/main/java/org/iottree/core/msgnet/nodes/lang.xml +++ b/core/src/main/java/org/iottree/core/msgnet/nodes/lang.xml @@ -65,7 +65,7 @@ desc_en="By selecting a tag, listen for changes in the value of the tag during runtime, and generate message output based on a certain strategy" /> - + id2share = new HashMap<>() ; + private HashMap id2share = new HashMap<>() ; private PrjShareManager() {} @@ -63,10 +63,15 @@ public PrjSharer setSharer(String prjid,boolean enbale, public PrjSharer getSharer(String prjid)// throws Exception { - PrjSharer ps = id2share.get(prjid); - if(ps!=null) - return ps ; + Object obj = id2share.get(prjid); + if(obj!=null) + { + if(obj instanceof PrjSharer) + return (PrjSharer)obj ; + return null ; + } + PrjSharer ps = null; try { ps = loadSharer(prjid); @@ -74,10 +79,15 @@ public PrjSharer getSharer(String prjid)// throws Exception { id2share.put(prjid, ps) ; } + else + { + id2share.put(prjid,"") ; + } } catch(Exception e) { e.printStackTrace(); + id2share.put(prjid,"") ; } return ps ; } diff --git a/core/src/main/java/org/iottree/core/sim/SimContext.java b/core/src/main/java/org/iottree/core/sim/SimContext.java index 1a9d54a9..e617a552 100644 --- a/core/src/main/java/org/iottree/core/sim/SimContext.java +++ b/core/src/main/java/org/iottree/core/sim/SimContext.java @@ -2,6 +2,7 @@ import java.io.PrintWriter; import java.io.StringWriter; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -14,6 +15,7 @@ import javax.script.ScriptEngineManager; import javax.script.ScriptException; +import org.graalvm.polyglot.Value; import org.iottree.core.cxt.IJSOb; import org.iottree.core.cxt.JsProp; import org.iottree.core.dict.DictManager; @@ -24,6 +26,8 @@ import org.iottree.core.util.js.GSys; import org.iottree.core.util.js.GUtil; +import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine; + public class SimContext { private transient ScriptEngine scriptEng = null; @@ -109,8 +113,79 @@ public synchronized void scriptEval(String jstxt) throws ScriptException public synchronized Object scriptInvoke(String fn,Object... paramvals) throws NoSuchMethodException, ScriptException { - Invocable inv = (Invocable)getScriptEngine() ; - return inv.invokeFunction(fn, paramvals) ; + //long st = System.currentTimeMillis() ; + //long stn = System.nanoTime() ; + try + { + GraalJSScriptEngine se = (GraalJSScriptEngine)getScriptEngine() ; + Value func = se.getPolyglotContext().getBindings("js").getMember(fn) ; + Value res = func.execute(paramvals) ; + return res.as(Object.class) ; + //return transGraalValueToMapListObj(res) ; + + +// Invocable inv = (Invocable)getScriptEngine() ; +// return inv.invokeFunction(fn, paramvals) ; + } + finally + { + //System.out.println("cost="+(System.currentTimeMillis()-st)+" nano="+(System.nanoTime()-stn)) ; + } + } + + public static Object transGraalValueToMapListObj(Value res) + { + if(res.isNull()) + return null ; + + if(res.hasArrayElements()) + { + ArrayList ret = new ArrayList<>() ; + long sz = res.getArraySize() ; + for(int i = 0 ; i < sz ; i ++) + { + Value tmpv = res.getArrayElement(i);//.as(Object.class) ; + Object obj = transGraalValueToMapListObj(tmpv) ; + ret.add(obj) ; + } + return ret ; + } + + if(res.hasMembers()) + { + HashMap tmpm = new HashMap<>(); + for(String mkey:res.getMemberKeys()) + { + Value val = res.getMember(mkey); + Object obj = transGraalValueToMapListObj(val) ; + if(obj==null) + continue ; + tmpm.put(mkey, obj) ; + } + return tmpm ; + } + + return res.as(Object.class) ; + } + + public static Map transGraalParamToMapListObj(Map pm) + { + HashMap tmpm = new HashMap<>(); + for(String mkey:pm.keySet()) + { + Object val = pm.get(mkey) ; + if(val instanceof Value) + val = transGraalValueToMapListObj((Value)val) ; + else if(val instanceof Map) + { + //PolyglotMap polymm ; + val = transGraalParamToMapListObj((Map)val) ; + } + if(val==null) + continue ; + tmpm.put(mkey, val) ; + } + return tmpm ; } public CompiledScript scriptCompile(boolean bblock,String jstxt) throws ScriptException diff --git a/core/src/main/java/org/iottree/core/sim/SimInstance.java b/core/src/main/java/org/iottree/core/sim/SimInstance.java index 47d513a5..6f139355 100644 --- a/core/src/main/java/org/iottree/core/sim/SimInstance.java +++ b/core/src/main/java/org/iottree/core/sim/SimInstance.java @@ -506,7 +506,7 @@ public void run() { try { - Thread.sleep(10); + Thread.sleep(100); } catch(Exception e) {} diff --git a/driver-parent/driver-common/src/main/java/org/iottree/driver/common/JsonJSDrv.java b/driver-parent/driver-common/src/main/java/org/iottree/driver/common/JsonJSDrv.java index d026453e..2dcfe21b 100644 --- a/driver-parent/driver-common/src/main/java/org/iottree/driver/common/JsonJSDrv.java +++ b/driver-parent/driver-common/src/main/java/org/iottree/driver/common/JsonJSDrv.java @@ -43,7 +43,7 @@ public String getTitle() @Override public Class supportConnPtClass() { - return org.iottree.core.conn.ConnPtMSG.class; + return org.iottree.core.conn.ConnPtMSGNor.class; } @Override diff --git a/driver-parent/driver-common/src/main/java/org/iottree/driver/common/MsgJSDrv.java b/driver-parent/driver-common/src/main/java/org/iottree/driver/common/MsgJSDrv.java new file mode 100644 index 00000000..34e660df --- /dev/null +++ b/driver-parent/driver-common/src/main/java/org/iottree/driver/common/MsgJSDrv.java @@ -0,0 +1,286 @@ +package org.iottree.driver.common; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.iottree.core.ConnDev; +import org.iottree.core.ConnPt; +import org.iottree.core.DevAddr; +import org.iottree.core.DevDriver; +import org.iottree.core.DevDriverMsgOnly; +import org.iottree.core.UACh; +import org.iottree.core.UADev; +import org.iottree.core.UATag; +import org.iottree.core.ConnPt.DataTp; +import org.iottree.core.basic.PropGroup; +import org.iottree.core.basic.PropItem; +import org.iottree.core.basic.PropItem.PValTP; +import org.iottree.core.conn.*; +import org.iottree.core.cxt.UAContext; +import org.iottree.core.util.Convert; +import org.iottree.core.util.Lan; +import org.json.JSONArray; +import org.json.JSONObject; +/** + * + * @author jason.zhu + * + */ +public class MsgJSDrv extends DevDriverMsgOnly +{ + String onInitJS = null ; + + String onMsgInJS = null ; + boolean hasMsgInJS = false ; + boolean msgInStr = true; + + String onTagWriteJS = null ; + boolean hasTagWriteJS = false ; + + String onLoopJS = null ; + boolean hasLoopJS = false ; + + @Override + public String getName() + { + return "msg_js"; + } + + @Override + public String getTitle() + { + return "Msg JS Handler"; + } + + @Override + public boolean checkPropValue(String groupn, String itemn, String strv, StringBuilder failedr) + { + return true; + } + + @Override + public DevDriver copyMe() + { + return new MsgJSDrv(); + } + + @Override + public Class supportConnPtClass() + { + return ConnPtMsg.class; + } + + @Override + public boolean supportDevFinder() + { + return false; + } + + @Override + public List getPropGroupsForDevDef() + { + return null; + } + + @Override + public List getPropGroupsForCh(UACh ch) + { +// ArrayList rets = new ArrayList<>() ; +// Lan lan = Lan.getPropLangInPk(this.getClass()) ; +// +// PropGroup pg = new PropGroup("msg_js",lan);//"Ping"); +// +// pg.addPropItem(new PropItem("on_msg_in",lan,PValTP.vt_str,false,null,null,3000)); //"Check Timeout","Check Timeout(ms),too small may check error" +// pg.addPropItem(new PropItem("script", lan, PValTP.vt_str, false, null, null, +// "").withTxtMultiLine(true)); +// rets.add(pg); +// return rets; + return null ; + } + + @Override + public List getPropGroupsForDevInCh(UADev d) + { + return null; + } + + @Override + public DevAddr getSupportAddr() + { + return null; + } + + @Override + public boolean hasDriverConfigPage() + {//有驱动特殊配置页面 + return true; + } + + protected boolean initDriver(StringBuilder failedr) throws Exception + { + if(!super.initDriver(failedr)) + return false; + + UACh ch = this.getBelongToCh() ; + if(ch==null) + { + failedr.append("no belong to ch found") ; + return false; + } + String txt = ch.getDrvSpcConfigTxt() ; + if(Convert.isNullOrEmpty(txt)) + { + failedr.append("ch is not set special configuration") ; + return false; + } + JSONObject jo = new JSONObject(txt) ; + onInitJS = jo.optString("on_init_js","") ; + onMsgInJS = jo.optString("on_msgin_js") ; + msgInStr = jo.optBoolean("msg_in_str", true) ; + onTagWriteJS = jo.optString("on_tagw_js") ; + onLoopJS = jo.optString("on_loop_js") ; + if(Convert.isNullOrEmpty(onMsgInJS) && Convert.isNullOrEmpty(onTagWriteJS)) + { + failedr.append("ch is not set special configuration") ; + return false; + } + + String js_uid = ch.getId() ; + + UAContext cxt = ch.RT_getContext() ; + String tmps = onInitJS +"\r\n" ; + + if(Convert.isNotNullTrimEmpty(onMsgInJS)) + { + tmps += "function on_msgin_"+js_uid+"($ch,$connpt,$msg){\r\n"; + tmps += onMsgInJS ; + tmps += "\r\n}" ; + + hasMsgInJS = true ; + } + + if(Convert.isNotNullTrimEmpty(onTagWriteJS)) + { + tmps += "function on_tagw_"+js_uid+"($ch,$connpt,$tag,$input){\r\n"; + tmps += onTagWriteJS ; + tmps += "\r\n}" ; + + hasTagWriteJS = true ; + } + + if(Convert.isNotNullTrimEmpty(onLoopJS)) + { + tmps += "function on_loop_"+js_uid+"($ch,$connpt){\r\n"; + tmps += onLoopJS ; + tmps += "\r\n}" ; + + hasLoopJS = true ; + } + + cxt.scriptEval(tmps); + + return true; + } + + @Override + public void RT_onConnMsgIn(byte[] msgbs) + { + //System.out.println("on msg in="+new String(msgbs)) ; + if(!hasMsgInJS) + return ; + Object msg = msgbs ; + if(msgInStr) + { + try + { + msg = new String(msgbs,"UTF-8") ; + } + catch(Exception ee) + { + throw new RuntimeException(ee) ; + } + } + + UACh ch = this.getBelongToCh() ; + String js_uid = ch.getId() ; + ConnPtMsg cpm = (ConnPtMsg)this.getBindedConnPt() ; + //cpm.sen + UAContext cxt = ch.RT_getContext() ; + try + { + cxt.scriptInvoke("on_msgin_"+js_uid, ch,cpm,msg) ; + } + catch(Exception ee) + { + ee.printStackTrace(); + } + } + + + @Override + public boolean RT_writeVal(UACh ch, UADev dev, UATag tag, DevAddr da, Object v) + { + if(!hasTagWriteJS) + return false; + + String js_uid = ch.getId() ; + ConnPtMsg cpm = (ConnPtMsg)this.getBindedConnPt() ; + //cpm.sen + UAContext cxt = ch.RT_getContext() ; + try + { + cxt.scriptInvoke("on_tagw_"+js_uid, ch,cpm,tag,v) ; + return true; + } + catch(Exception ee) + { + ee.printStackTrace(); + return false; + } + } + + + @Override + protected void RT_onConnReady(ConnPt cp, UACh ch, UADev dev) throws Exception + { + + } + + @Override + protected void RT_onConnInvalid(ConnPt cp, UACh ch, UADev dev) throws Exception + { + + } + + @Override + protected boolean RT_runInLoop(UACh ch, UADev dev, StringBuilder failedr) throws Exception + { + if(!hasLoopJS) + return true; + + String js_uid = ch.getId() ; + ConnPtMsg cpm = (ConnPtMsg)this.getBindedConnPt() ; + //cpm.sen + UAContext cxt = ch.RT_getContext() ; + try + { + cxt.scriptInvoke("on_loop_"+js_uid, ch,cpm) ; + return true; + } + catch(Exception ee) + { + ee.printStackTrace(); + return false; + } + } + + + + @Override + public boolean RT_writeVals(UACh ch, UADev dev, UATag[] tags, DevAddr[] da, Object[] v) + { + return false; + } + +} diff --git a/driver-parent/driver-common/src/main/java/org/iottree/driver/common/prop_lang.xml b/driver-parent/driver-common/src/main/java/org/iottree/driver/common/prop_lang.xml index d72fc88e..19754532 100644 --- a/driver-parent/driver-common/src/main/java/org/iottree/driver/common/prop_lang.xml +++ b/driver-parent/driver-common/src/main/java/org/iottree/driver/common/prop_lang.xml @@ -20,6 +20,8 @@ + + diff --git a/driver-parent/driver-opc/pom.xml b/driver-parent/driver-opc/pom.xml index a4ca9d73..584617e0 100644 --- a/driver-parent/driver-opc/pom.xml +++ b/driver-parent/driver-opc/pom.xml @@ -4,7 +4,7 @@ driver-parent org.iottree.driver - 1.7.3 + 1.7.4 diff --git a/ext-parent/ext-basic/pom.xml b/ext-parent/ext-basic/pom.xml index 28c59ff4..c6b98a08 100644 --- a/ext-parent/ext-basic/pom.xml +++ b/ext-parent/ext-basic/pom.xml @@ -3,7 +3,7 @@ ext-parent org.iottree.ext - 1.7.3 + 1.7.4 ../pom.xml iottree-ext-basic @@ -21,7 +21,7 @@ org.iottree iottree-core - 1.7.3 + 1.7.4 diff --git a/ext-parent/ext-basic/src/main/java/org/iottree/ext/msg_net/TCPClient_NM.java b/ext-parent/ext-basic/src/main/java/org/iottree/ext/msg_net/TCPClient_NM.java new file mode 100644 index 00000000..45b9c700 --- /dev/null +++ b/ext-parent/ext-basic/src/main/java/org/iottree/ext/msg_net/TCPClient_NM.java @@ -0,0 +1,161 @@ +package org.iottree.ext.msg_net; + +import org.iottree.core.msgnet.MNConn; +import org.iottree.core.msgnet.MNMsg; +import org.iottree.core.msgnet.MNNodeMid; +import org.iottree.core.msgnet.RTOut; +import org.iottree.core.util.Convert; +import org.iottree.core.util.Lan; +import org.iottree.core.util.logger.ILogger; +import org.iottree.core.util.logger.LoggerManager; +import org.json.JSONObject; + +public class TCPClient_NM extends MNNodeMid +{ + static ILogger log = LoggerManager.getLogger(TCPClient_NM.class) ; + + static Lan lan = Lan.getLangInPk(TCPClient_NM.class) ; + + public static enum RetMode + { + buf, //byte[] + str; // + + public String getTitle() + { + return lan.g(this.name()) ; + } + } + + public static enum CloseMode + { + never(0), + aft_fixed_to(1), + recv_char(2), + recv_char_num(3), + immediately(4); + + private final int val ; + + CloseMode(int v) + { + val = v ; + } + + public int getVal() + { + return this.val ; + } + + public String getTitle() + { + return lan.g(this.name()) ; + } + } + + String serverAddr ; + + int serverPort ; + + int localPort = -1; + + RetMode retMode = RetMode.buf ; + + CloseMode closeMode = CloseMode.never ; + + @Override + public int getOutNum() + { + return 3; + } + + @Override + public String getTP() + { + return "tcp_client"; + } + + @Override + public String getTPTitle() + { + return "TCP Client"; + } + + @Override + public String getColor() + { + return "#c0c0c0"; + } + + @Override + public String getIcon() + { + return "\\uf0ec"; + } + + @Override + public boolean isParamReady(StringBuilder failedr) + { + if(Convert.isNullOrEmpty(this.serverAddr)) + { + failedr.append("no server set") ; + return false; + } + if(serverPort<=0) + { + failedr.append("no server port set") ; + return false; + } + return true; + } + + @Override + public JSONObject getParamJO() + { + JSONObject jo = new JSONObject() ; + jo.putOpt("server", this.serverAddr) ; + jo.putOpt("port", this.serverPort) ; + jo.putOpt("loc_port", this.serverAddr) ; + jo.putOpt("server", this.serverAddr) ; + jo.putOpt("server", this.serverAddr) ; + return jo; + } + + @Override + protected void setParamJO(JSONObject jo) + { + + } + + + @Override + protected RTOut RT_onMsgIn(MNConn in_conn, MNMsg msg) throws Exception + { + return null; + } + + @Override + public String RT_getOutColor(int idx) + { + if(idx==1) + return "#25b541"; + else if(idx==2) + return "#e13c2f" ; + return null; + } + + @Override + public String RT_getOutTitle(int idx) + { + switch(idx) + { + case 0: + return "Received Data in payload" ; + case 1: + return "Connect server ready msg"; + case 2: + return "Connection is broken msg"; + } + return null ; + } +} diff --git a/ext-parent/ext-basic/src/main/java/org/iottree/ext/msg_net/UDPIn_NS.java b/ext-parent/ext-basic/src/main/java/org/iottree/ext/msg_net/UDPIn_NS.java new file mode 100644 index 00000000..1bbc8db5 --- /dev/null +++ b/ext-parent/ext-basic/src/main/java/org/iottree/ext/msg_net/UDPIn_NS.java @@ -0,0 +1,6 @@ +package org.iottree.ext.msg_net; + +public class UDPIn_NS +{ + +} diff --git a/ext-parent/ext-basic/src/main/java/org/iottree/ext/msg_net/UDPOut_NE.java b/ext-parent/ext-basic/src/main/java/org/iottree/ext/msg_net/UDPOut_NE.java new file mode 100644 index 00000000..62c08206 --- /dev/null +++ b/ext-parent/ext-basic/src/main/java/org/iottree/ext/msg_net/UDPOut_NE.java @@ -0,0 +1,6 @@ +package org.iottree.ext.msg_net; + +public class UDPOut_NE +{ + +} diff --git a/ext-parent/ext-basic/src/main/java/org/iottree/ext/msg_net/lang.xml b/ext-parent/ext-basic/src/main/java/org/iottree/ext/msg_net/lang.xml new file mode 100644 index 00000000..f58c254b --- /dev/null +++ b/ext-parent/ext-basic/src/main/java/org/iottree/ext/msg_net/lang.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ext-parent/pom.xml b/ext-parent/pom.xml index c5a0d062..be67b900 100644 --- a/ext-parent/pom.xml +++ b/ext-parent/pom.xml @@ -4,7 +4,7 @@ org.iottree iottree-parent - 1.7.3 + 1.7.4 ../pom.xml org.iottree.ext @@ -34,7 +34,7 @@ org.iottree iottree-core - 1.7.3 + 1.7.4 diff --git a/server/pom.xml b/server/pom.xml index aab1a23b..738b6400 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -4,7 +4,7 @@ iottree-parent org.iottree - 1.7.3 + 1.7.4 iottree-server diff --git a/web/ROOT/pom.xml b/web/ROOT/pom.xml index ecea5d4e..312af169 100644 --- a/web/ROOT/pom.xml +++ b/web/ROOT/pom.xml @@ -4,7 +4,7 @@ org.iottree.web web-parent - 1.7.3 + 1.7.4 ROOT diff --git a/web/admin/conn/cpt_edit_multi_tcp_msg.jsp b/web/admin/conn/cpt_edit_multi_tcp_msg.jsp index db259308..9e7973b3 100644 --- a/web/admin/conn/cpt_edit_multi_tcp_msg.jsp +++ b/web/admin/conn/cpt_edit_multi_tcp_msg.jsp @@ -580,6 +580,8 @@ function do_submit(cb) if(desc==null) desc ='' ; + let recv_broken_to = get_input_val("recv_broken_to",60000,true) ; + let tcp_run_tp = $("#tcp_run_tp").val() ; let tcp_run = null ; if(tcp_run_tp=='s') @@ -618,7 +620,7 @@ function do_submit(cb) data_pro = {_tp:data_pro_tp} ; } - cb(true,{id:conn_id,name:n,title:tt,desc:desc,enable:ben, + cb(true,{id:conn_id,name:n,title:tt,desc:desc,enable:ben,recv_broken_to:recv_broken_to, tcp_run:tcp_run,data_pro:data_pro}); } diff --git a/web/admin/conn/cpt_edit_udp_msg.jsp b/web/admin/conn/cpt_edit_udp_msg.jsp new file mode 100644 index 00000000..acb138d5 --- /dev/null +++ b/web/admin/conn/cpt_edit_udp_msg.jsp @@ -0,0 +1,230 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> +<%@ page import=" + org.json.*, + org.iottree.core.*, + org.iottree.core.conn.*, + org.iottree.core.util.*, + org.iottree.core.basic.*, + java.io.*, + java.util.*, + java.net.*, + java.util.* + "%><%@ taglib uri="wb_tag" prefix="wbt"%><% + if(!Convert.checkReqEmpty(request, out, "prjid")) + return; +String repid = request.getParameter("prjid") ; +String cptp = ConnProUDP.TP; +ConnProUDP cp = (ConnProUDP)ConnManager.getInstance().getOrCreateConnProviderSingle(repid, cptp); +if(cp==null) +{ + out.print("no single provider found with "+cptp); + return ; +} + +String cpid = cp.getId();//.getParameter("cpid") ; +String connid = request.getParameter("connid") ; +//ConnProTcpClient cp = (ConnProTcpClient)ConnManager.getInstance().getConnProviderById(repid, cpid) ; +ConnPtUDPMsg cpt = null ; +if(Convert.isNullOrEmpty(connid)) +{ + cpt = new ConnPtUDPMsg() ; + connid = cpt.getId() ; +} +else +{ + cpt = (ConnPtUDPMsg)cp.getConnById(connid) ; + if(cpt==null) + { + out.print("no connection found") ; + return ; + } +} + +String name = cpt.getName() ; +String title= cpt.getTitle() ; +String chked = "" ; +if(cpt.isEnable()) + chked = "checked='checked'" ; +String desc = cpt.getDesc(); +int connto = -1;//cpt.getConnTimeout(); +String cp_tp = cp.getProviderType() ; + +String host = cpt.getHost() ; +int port = cpt.getPort() ; + +String loc_ip = cpt.getRecvLocIP() ; +int loc_port = cpt.getRecvLocPort() ; + +%> + + + + + + + + + + +
+
+ +
+ +
+
title:
+
+ +
+
enable:
+
+ lay-skin="switch" lay-filter="enable" class="layui-input"> +
+
+ +
+ + +
Listen on Port:
+
+ +
+
Local IP:
+
+ +
+ +
+ +
+ +
host:
+
+ +
+
port:
+
+ +
+
+ + +
+ +
+ +
+
+ +
+ + + \ No newline at end of file diff --git a/web/admin/mn/nodes/_func.template.pm.jsp b/web/admin/mn/nodes/_func.template.pm.jsp index 9e60a14b..90675a14 100644 --- a/web/admin/mn/nodes/_func.template.pm.jsp +++ b/web/admin/mn/nodes/_func.template.pm.jsp @@ -49,7 +49,7 @@ + + +
+
+ +
+      +
+
+ +
+ +
+ ($ch,$connpt,$msg)=>{ Msg In String
+      +
    } +
+
+
+ +
+ ($ch,$connpt,$tag,$input)=>{
+      +
    } +
+
+
+ +
+ ($ch,$connpt)=>{
+      +
    } +
+
+
+ + + \ No newline at end of file diff --git a/web/admin/ua_cxt/cxt_script.jsp b/web/admin/ua_cxt/cxt_script.jsp index b6db9034..59a5ec37 100644 --- a/web/admin/ua_cxt/cxt_script.jsp +++ b/web/admin/ua_cxt/cxt_script.jsp @@ -273,6 +273,10 @@ function init() $("#script_test").val(jsstr) ; } } + else + { + jsstr = dlg.get_opener_opt("js_txt")||""; + } js_edit_init(jsstr); //editor=CodeMirror.fromTextArea(document.getElementById("script_test"),{ diff --git a/web/admin/ua_cxt/tag_trans_edit.jsp b/web/admin/ua_cxt/tag_trans_edit.jsp index aa25ec18..f4fd4e9b 100644 --- a/web/admin/ua_cxt/tag_trans_edit.jsp +++ b/web/admin/ua_cxt/tag_trans_edit.jsp @@ -186,7 +186,7 @@ var transdd = ow.trans_dd ; if(transdd==null) transdd={} ; var path=node_path ; -console.log(transdd); +//console.log(transdd); layui.use('form', function(){ form = layui.form; diff --git a/web/doc/pom.xml b/web/doc/pom.xml index a25a13ba..237ba98e 100644 --- a/web/doc/pom.xml +++ b/web/doc/pom.xml @@ -4,7 +4,7 @@ org.iottree.web web-parent - 1.7.3 + 1.7.4 doc diff --git a/web/main/pom.xml b/web/main/pom.xml index 7d7a7797..acdb363a 100644 --- a/web/main/pom.xml +++ b/web/main/pom.xml @@ -3,7 +3,7 @@ org.iottree.web web-parent - 1.7.3 + 1.7.4 main