JavaLikeCalc.JavaScript
function prmAdd(req, path, pId, pNm, pTp, pSrc, pLogLnk) {
	req.childAdd("add").setAttr("path",path+"/%2fbr%2fprm_").setAttr("id",pId).setText(pNm);
	req.childAdd("set").setAttr("path",path+"/prm_"+pId+"/%2fprm%2fst%2ftype").setText(pTp);
	req.childAdd("set").setAttr("path",path+"/prm_"+pId+"/%2fprm%2fcfg%2fEN").setText(1);
	if(pTp == "Prm" && pSrc != null)
		req.childAdd("set").setAttr("path",path+"/prm_"+pId+"/%2fprm%2fcfg%2fPRM").setText(pSrc);
	if(pTp == "PrmRefl" && pSrc != null)
		req.childAdd("set").setAttr("path",path+"/prm_"+pId+"/%2fprm%2fcfg%2fPSRC").setText(pSrc);
	req.childAdd("set").setAttr("path",path+"/prm_"+pId+"/%2fprm%2fst%2fen").setText(1);
	if(pTp == "Prm" && pLogLnk != null)
		req.childAdd("set").setAttr("path",path+"/prm_"+pId+"/%2fcfg%2fprm%2fel_0").setText(pLogLnk);
}

if(f_start) {
	inTransport_ = "", inTr = null;
	prcTr = "";
	prcCon = new Object();
	noAccess = new Object();
	return;	//Do no work on the start time
}

//Checking the transport change and connect
tErr = "";
if(inTr == null || inTransport != inTransport_) {
	inTransport_ = inTransport;
	inTr = SYS.Transport[inTransport.parse(0)]["in_"+inTransport.parse(1)];
}

if(inTr == null)	tErr = "1:"+tr("Input transport '%1' error.").replace("%1",inTransport);
else {
	//Processing the input connections
	outTrs = inTr.associateTrsList();
	for(iTr = 0; iTr < outTrs.length; iTr++) {
		oTrNm = outTrs[iTr];
		if((oTrO=SYS.Transport[inTransport.parse(0)]["out_"+oTrNm]) == null || !oTrO.start() || oTrO.conPrm("initConID").length)
			continue;

		//Getting the host address
		hostAddr = (hostAddr=oTrO.status().match(" '(.+)'\\.")).length ? hostAddr[1] : "";
		
		//Getting the station name and the DataSource key
		req = SYS.XMLNode("CntrReqs").setAttr("rqDir","1").setAttr("rqUser",cntrUser).setAttr("rqPass",cntrPass).setAttr("conTm",conTm)
				.setAttr("path","/");
		req.childAdd("get").setAttr("path","/%2fgen%2fstat");
		req.childAdd("get").setAttr("path","/DAQ/LogicLev/"+cntrObj+"/%2fcntr%2fcfg%2fDESCR");
		req.childAdd("get").setAttr("path","/%2fgen%2fenv%2fhost");
		if((rez=oTrO.messIO(req,"SelfSystem")).toInt()) {
			SYS.messNote("/InitRem/"+this.cfg("SHIFR"), (tVl=tr("Error requesting the remote host '%1': %2")
									.replace("%1",hostAddr).replace("%2",rez)));
			//tErr += (tErr.length?"":"10:") + tVl;
		}
		else {
			stNm = req.childGet(2).text()+"-"+req.childGet(0).text();
			if(noAccess[stNm] != null && accessTm >= 0 && (SYS.time()-noAccess[stNm]) > accessTm*60*60) {
				delete noAccess[stNm];
				delete prcCon[stNm];
			}
		}
		if(rez.toInt() || noAccess[stNm] != null) { oTrO.start(false); continue; }

		stSrcKey = rand(999).toString();
		isSrcInited = isHostReqPresent = false;
		if(!req.childGet(1).attr("rez").toInt() && (tVl=req.childGet(1).text().match("^SrcKey: *([^\\n]+)$","m")).length)
			isSrcInited = true, stSrcKey = tVl[1];

		stSrcId = req.childGet(2).text() + req.childGet(0).text() + stSrcKey;
		for(stLen = req.childGet(2).text().length, hostLen = req.childGet(0).text().length; stSrcId.length > 20; ) {
			if(stLen > hostLen)	stLen--; else hostLen--;
			stSrcId = req.childGet(2).text().slice(0,stLen) + req.childGet(0).text().slice(0,hostLen) + stSrcKey;
		}
		stSrcId = oTrO.conPrm("initConID", SYS.strEncode(stSrcId,"OscdID"));
		prcCon[stSrcId] = stSrcId+": "+oTrNm+", "+hostAddr+", "+SYS.strftime(SYS.time());

		//Record to the table of the OpenSCADA remote hosts
		// Checking presence
		req = SYS.XMLNode("get").setAttr("path","/Transport/%2fsub%2fehost");
		SYS.cntrReq(req);
		for(iH = 0; iH < req.childGet(0).childSize(); iH++)
			if(req.childGet(0).childGet(iH).text() == stSrcId)
			{ isHostReqPresent = true; break; }

		// Appending/updating
		if(!rez.toInt() && !isHostReqPresent) {
			req = SYS.XMLNode("CntrReqs").setAttr("path","/Transport");
			req.childAdd("add").setAttr("path","/%2fsub%2fehost");
			req.childAdd("set").setAttr("path","/%2fsub%2fehost").setAttr("key_id","newHost").setAttr("col","id").setText(stSrcId);
			req.childAdd("set").setAttr("path","/%2fsub%2fehost").setAttr("key_id",stSrcId).setAttr("col","name").setText(stNm+" ("+stSrcKey+")");
			req.childAdd("set").setAttr("path","/%2fsub%2fehost").setAttr("key_id",stSrcId).setAttr("col","transp").setText(inTransport.parse(0)+".in_"+inTransport.parse(1));
			req.childAdd("set").setAttr("path","/%2fsub%2fehost").setAttr("key_id",stSrcId).setAttr("col","addr").setText(stSrcId);
			req.childAdd("set").setAttr("path","/%2fsub%2fehost").setAttr("key_id",stSrcId).setAttr("col","user").setText(cntrUser);
			req.childAdd("set").setAttr("path","/%2fsub%2fehost").setAttr("key_id",stSrcId).setAttr("col","pass").setText(cntrPass);
			req.childAdd("set").setAttr("path","/%2fsub%2fehost").setAttr("key_id",stSrcId).setAttr("col","mode").setText(2);
			req.childAdd("save").setAttr("path","/%2fobj");
			SYS.cntrReq(req);
		}

		//Initialisation
		if(!rez.toInt() && !isSrcInited) {
			// Creating the main control object of the Data Sources
			req = SYS.XMLNode("CntrReqs").setAttr("path","/DAQ/LogicLev");
			req.childAdd("add").setAttr("path","/%2fbr%2fcntr_").setAttr("id",cntrObj).setText("Sources for remote aggregator");
			req.childAdd("set").setAttr("path","/"+cntrObj+"/%2fcntr%2fst%2frunSt").setText(1);
			req.childAdd("set").setAttr("path","/"+cntrObj+"/%2fcntr%2fcfg%2fSTART").setText(1);
			req.childAdd("save").setAttr("path","/"+cntrObj+"/%2fobj");
			rez = SYS.cntrReq(req, stSrcId);

			//No access
			if(!rez.toInt() && req.childGet(0).attr("rez").toInt()) {
				req = SYS.XMLNode("CntrReqs").setAttr("path","/Transport");
				req.childAdd("del").setAttr("path","/%2fsub%2fehost").setAttr("key_id",stSrcId);
				req.childAdd("save").setAttr("path","/%2fobj");
				SYS.cntrReq(req);

				noAccess[stNm] = SYS.time();
				delete prcCon[stSrcId];
				prcCon[stNm] = stSrcId+": "+oTrNm+", "+hostAddr+", "+SYS.strftime(SYS.time())+" - NO ACCESS";

				SYS.messNote("/InitRem/"+this.cfg("SHIFR"), (tVl=tr("Error accessing the remote station '%1': %2. ")
											.replace("%1",stNm).replace("%2",req.childGet(0).text())));

				oTrO.start(false);
				continue;
			}

			//Primary sources in DAQ.System
			// Getting allowed ones
			reqSys = SYS.XMLNode("get").setAttr("path","/DAQ/System/%2fbr%2fcntr_");
			rez = SYS.cntrReq(reqSys, stSrcId);

			// Creation one at missing any one
			if(!rez.toInt() && !reqSys.childSize()) {
				req = SYS.XMLNode("CntrReqs").setAttr("path","/DAQ/System");
				req.childAdd("add").setAttr("path","/%2fbr%2fcntr_").setAttr("id",cntrObj).setText("Remote sources");
				req.childAdd("set").setAttr("path","/"+cntrObj+"/%2fcntr%2fcfg%2fAUTO_FILL").setText(3);
				req.childAdd("set").setAttr("path","/"+cntrObj+"/%2fcntr%2fst%2frunSt").setText(1);
				req.childAdd("set").setAttr("path","/"+cntrObj+"/%2fcntr%2fcfg%2fSTART").setText(1);
				req.childAdd("save").setAttr("path","/"+cntrObj+"/%2fobj");
				rez = SYS.cntrReq(req, stSrcId);
				reqSys.childAdd("el").setAttr("id",cntrObj).setText("Remote sources");
			}

			// Reading lists of the parameters of the System sources with reading parameters of the sources
			// and creation their representing on the Logical Level
			reqLogic = SYS.XMLNode("CntrReqs").setAttr("path","/DAQ/LogicLev/"+cntrObj);
			prmAdd(reqLogic, "/", "SYS", "System", "Prm");
			prmAdd(reqLogic, "/", "DISK", "Disk", "Prm");
			prmAdd(reqLogic, "/", "NET", "Network", "Prm");

			for(iEl = 0; !rez.toInt() && iEl < reqSys.childSize(); iEl++) {
				cntrId = reqSys.childGet(iEl).attr("id");
				reqSysPrms = SYS.XMLNode("get").setAttr("path","/DAQ/System/"+cntrId+"/%2fbr%2fprm_");
				rez = SYS.cntrReq(reqSysPrms, stSrcId);

				for(iEl2 = 0; !rez.toInt() && iEl2 < reqSysPrms.childSize(); iEl2++) {
					pId = reqSysPrms.childGet(iEl2).attr("id");
					req = SYS.XMLNode("get").setAttr("path","/DAQ/System/"+cntrId+"/prm_"+pId+"/%2fprm%2fcfg%2fTYPE");
					rez = SYS.cntrReq(req, stSrcId);

					//  Completely reflected sources
					if((tVl=req.text()) == "CPU" || tVl == "MEM" || tVl == "sensors" || tVl == "Power" || tVl == "uptime")
						prmAdd(reqLogic, "/prm_SYS", pId, reqSysPrms.childGet(iEl2).text(), "PrmRefl", "System."+cntrId+"."+pId);
					else if(tVl == "fs" || tVl == "hddstat" || tVl == "hddsmart") {
						prmAdd(reqLogic, "/prm_DISK", pId, reqSysPrms.childGet(iEl2).text(), "PrmRefl", "System."+cntrId+"."+pId);
						if(tVl == "hddsmart")
							prmAdd(reqLogic, "/prm_DISK", "log_"+pId, reqSysPrms.childGet(iEl2).text()+" - processing", "Prm", "base.DiskSMART", "System."+cntrId+"."+pId);
					}
					else if(tVl == "netstat")
						prmAdd(reqLogic, "/prm_NET", pId, reqSysPrms.childGet(iEl2).text(), "PrmRefl", "System."+cntrId+"."+pId);
					else if(tVl == "ups") {
						prmAdd(reqLogic, "/", pId, reqSysPrms.childGet(iEl2).text(), "PrmRefl", "System."+cntrId+"."+pId);
						prmAdd(reqLogic, "/", "log_"+pId, reqSysPrms.childGet(iEl2).text()+" - processing", "Prm", "base.UPS", "System."+cntrId+"."+pId);
					}
					else SYS.messNote("/InitRem/"+this.cfg("SHIFR"), "Implement the type '"+tVl+"'");
				}
			}

			//Mark the Logical Level controller as finished in the initialisation and save
			reqLogic.childAdd("set").setAttr("path","/%2fcntr%2fcfg%2fDESCR").setText("SrcKey: "+stSrcKey+"\n");
			reqLogic.childAdd("save").setAttr("path","/%2fobj");
			rez = SYS.cntrReq(reqLogic, stSrcId);
			delete reqLogic;
			delete reqSysPrms;
			delete reqSys;
		}

		//Creation the DAQGate object
		if(!rez.toInt() && SYS.DAQ.DAQGate[stSrcId] == null) {
			//Creation the DAQGate object in the end and no error
			req = SYS.XMLNode("CntrReqs").setAttr("path","/DAQ/DAQGate");
			req.childAdd("add").setAttr("path","/%2fbr%2fcntr_").setAttr("id",stSrcId).setText(stNm+" ("+stSrcKey+")");
			req.childAdd("set").setAttr("path","/"+stSrcId+"/%2fcntr%2fcfg%2fSTATIONS").setText(stSrcId);
			req.childAdd("set").setAttr("path","/"+stSrcId+"/%2fcntr%2fcfg%2fCNTRPRM").setText("LogicLev."+cntrObj);
			req.childAdd("set").setAttr("path","/"+stSrcId+"/%2fcntr%2fcfg%2fSTART").setText(1);
			req.childAdd("set").setAttr("path","/"+stSrcId+"/%2fcntr%2fst%2frunSt").setText(1);
			req.childAdd("save").setAttr("path","/"+stSrcId+"/%2fobj");
			SYS.cntrReq(req);
		}

		delete req;
	}
	delete oTrO;

	//Checking live of the established connections
	if(accessTm > 0) {
		daqs = SYS.DAQ.DAQGate.nodeList("cntr_");
		for(iEl = 0; iEl < daqs.length; iEl++)
			if((daqO=SYS.DAQ.DAQGate[daqs[iEl]]).cfg("CNTRPRM") == "LogicLev.RemCntr" &&
					daqO.status().toInt() && prcCon[(daqID=daqs[iEl].slice(5))] != null &&
					(tVl=daqO.status().match("([0-9]{2}-[0-9]{2}-[0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2})")).length &&
					(tVl=SYS.strptime(tVl[1],"%d-%m-%Y %H:%M:%S")) > 24*60*60 && (SYS.time()-tVl) > accessTm*60*60)
			{
				delete daqO;
				delete prcCon[daqID];

				req = SYS.XMLNode("CntrReqs").setAttr("path","/");
				req.childAdd("del").setAttr("path","/DAQ/DAQGate/%2fbr%2fcntr_").setAttr("id",daqID);
				req.childAdd("del").setAttr("path","/Transport/%2fsub%2fehost").setAttr("key_id",daqID);
				SYS.cntrReq(req);
			}
		delete daqO;
	}
}

//Updating the processed list
prcTr = "";
for(var iEl in prcCon)
	prcTr += (prcTr.length?"\n":"") + prcCon[iEl];

//Error set
if(tErr.length)	f_err = tErr;
else f_err = "0";