// Public members are defined using this.member // Private members are defined using "var member" or "function member" function newDatahubRequest (usexml) { var req; // Mozilla/Safari if (null) { } else if (window.XMLHttpRequest) { req = new XMLHttpRequest(); try { if (usexml) req.overrideMimeType('text/xml'); else req.overrideMimeType('text/plain'); } catch (E) { } } // IE else if (window.ActiveXObject) { try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { req = null; } } } return (req); } function DatahubCommand (command) { var xmlHttpReq = newDatahubRequest(false); var strSubmit = "command=" + encodeURIComponent(command); xmlHttpReq.abort(); xmlHttpReq.open ('POST', '/ajax', false); xmlHttpReq.send(strSubmit); } function DatahubConnector (inhost, inport) { // public: this.requestPoints = ""; this.onBeginPointUpdate = null; this.onEndPointUpdate = null; this.timerTick = 1000; this.host = inhost; this.port = inport; this.baseURL = "/points"; this.extraURLArgs = ""; // private: // Mapping DataHub points into functions var Fnmap = {}; var Oldvalmap = {}; var Oldqualmap = {}; var count = 0; var timerID = 0; var _conn = this; var usexml = true; var in_transaction = false; var xmlHttpReq = newDatahubRequest(usexml); // private: function do_fn_map (pointname, value, quality, timestamp) { var oldval = Oldvalmap[pointname]; var oldqual = Oldqualmap[pointname]; if (oldval != value || oldqual != quality) { var map = Fnmap[pointname]; if (map) { for (var i=0; i= 10 || x < 0 ? "" : "0") + x; } // Prepend a zero to a single-digit number as string function lz(x) { var t = String(x); return t.length == 1 ? "0" + t : t; } // Prepend enough zeros to make a number 3 digits long function LZZ(x) { return x < 0 || x >= 100 ? "" + x : "0" + LZ(x); } // Convert a floating point number of seconds (the format of // a DataHub timestamp from ajax) into a string. function S2T(Secs) { var T1; T1 = (new Date(Secs * 1000)).toUTCString().match(/\S{8}/); return T1 + "." + LZZ(Math.floor(Secs * 1000) % 1000); } Date.prototype.ISOlocaltimeStr = new Function(" /* Date.ISOlocaltimeStr hh:mm:ss */\n" + " with (this)\n return" + " LZ(getHours())+':'+LZ(getMinutes())+':'+LZ(getSeconds())") Date.prototype.ISOlocaldateStr = new Function(" /* Date.ISOlocaldateStr YYYY-MM-DD */\n" + " with (this)\n return " + "getFullYear()+'-'+LZ(getMonth()+1)+'-'+LZ(getDate())") Date.prototype.ISOlocalDTstr = new Function(" /* Date.ISOlocalDTstr YYYY-MM-DD hh:mm:ss */\n" + " with (this)\n return " + "ISOlocaldateStr()+' '+ISOlocaltimeStr()")