UNPKG

node-red-contrib-modbus

Version:

The all in one Modbus TCP and Serial contribution long term supported package for Node-RED.

3 lines (2 loc) 13.2 kB
function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _regeneratorRuntime(){_regeneratorRuntime=function(){return u};var s,u={},e=Object.prototype,c=e.hasOwnProperty,l=Object.defineProperty||function(e,t,r){e[t]=r.value},t="function"==typeof Symbol?Symbol:{},n=t.iterator||"@@iterator",r=t.asyncIterator||"@@asyncIterator",o=t.toStringTag||"@@toStringTag";function i(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{i({},"")}catch(s){i=function(e,t,r){return e[t]=r}}function a(e,t,r,n){var o,i,u,a,t=t&&t.prototype instanceof m?t:m,t=Object.create(t.prototype),n=new E(n||[]);return l(t,"_invoke",{value:(o=e,i=r,u=n,a=d,function(e,t){if(a===v)throw Error("Generator is already running");if(a===p){if("throw"===e)throw t;return{value:s,done:!0}}for(u.method=e,u.arg=t;;){var r=u.delegate;if(r){r=function e(t,r){var n=r.method,o=t.iterator[n];if(o===s)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=s,e(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),g;n=h(o,t.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,g;o=n.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=s),r.delegate=null,g):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,g)}(r,u);if(r){if(r===g)continue;return r}}if("next"===u.method)u.sent=u._sent=u.arg;else if("throw"===u.method){if(a===d)throw a=p,u.arg;u.dispatchException(u.arg)}else"return"===u.method&&u.abrupt("return",u.arg);a=v;r=h(o,i,u);if("normal"===r.type){if(a=u.done?p:f,r.arg===g)continue;return{value:r.arg,done:u.done}}"throw"===r.type&&(a=p,u.method="throw",u.arg=r.arg)}})}),t}function h(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}u.wrap=a;var d="suspendedStart",f="suspendedYield",v="executing",p="completed",g={};function m(){}function y(){}function L(){}var t={},w=(i(t,n,function(){return this}),Object.getPrototypeOf),w=w&&w(w(O([]))),b=(w&&w!==e&&c.call(w,n)&&(t=w),L.prototype=m.prototype=Object.create(t));function S(e){["next","throw","return"].forEach(function(t){i(e,t,function(e){return this._invoke(t,e)})})}function Q(u,a){var t;l(this,"_invoke",{value:function(r,n){function e(){return new a(function(e,t){!function t(e,r,n,o){var i,e=h(u[e],u,r);if("throw"!==e.type)return(r=(i=e.arg).value)&&"object"==_typeof(r)&&c.call(r,"__await")?a.resolve(r.__await).then(function(e){t("next",e,n,o)},function(e){t("throw",e,n,o)}):a.resolve(r).then(function(e){i.value=e,n(i)},function(e){return t("throw",e,n,o)});o(e.arg)}(r,n,e,t)})}return t=t?t.then(e,e):e()}})}function R(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function x(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function E(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(R,this),this.reset(!0)}function O(t){if(t||""===t){var r,e=t[n];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length))return r=-1,(e=function e(){for(;++r<t.length;)if(c.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=s,e.done=!0,e}).next=e}throw new TypeError(_typeof(t)+" is not iterable")}return l(b,"constructor",{value:y.prototype=L,configurable:!0}),l(L,"constructor",{value:y,configurable:!0}),y.displayName=i(L,o,"GeneratorFunction"),u.isGeneratorFunction=function(e){e="function"==typeof e&&e.constructor;return!!e&&(e===y||"GeneratorFunction"===(e.displayName||e.name))},u.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,L):(e.__proto__=L,i(e,o,"GeneratorFunction")),e.prototype=Object.create(b),e},u.awrap=function(e){return{__await:e}},S(Q.prototype),i(Q.prototype,r,function(){return this}),u.AsyncIterator=Q,u.async=function(e,t,r,n,o){void 0===o&&(o=Promise);var i=new Q(a(e,t,r,n),o);return u.isGeneratorFunction(t)?i:i.next().then(function(e){return e.done?e.value:i.next()})},S(b),i(b,o,"Generator"),i(b,n,function(){return this}),i(b,"toString",function(){return"[object Generator]"}),u.keys=function(e){var t,r=Object(e),n=[];for(t in r)n.push(t);return n.reverse(),function e(){for(;n.length;){var t=n.pop();if(t in r)return e.value=t,e.done=!1,e}return e.done=!0,e}},u.values=O,E.prototype={constructor:E,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=s,this.done=!1,this.delegate=null,this.method="next",this.arg=s,this.tryEntries.forEach(x),!e)for(var t in this)"t"===t.charAt(0)&&c.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=s)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var n=this;function e(e,t){return i.type="throw",i.arg=r,n.next=e,t&&(n.method="next",n.arg=s),!!t}for(var t=this.tryEntries.length-1;0<=t;--t){var o=this.tryEntries[t],i=o.completion;if("root"===o.tryLoc)return e("end");if(o.tryLoc<=this.prev){var u=c.call(o,"catchLoc"),a=c.call(o,"finallyLoc");if(u&&a){if(this.prev<o.catchLoc)return e(o.catchLoc,!0);if(this.prev<o.finallyLoc)return e(o.finallyLoc)}else if(u){if(this.prev<o.catchLoc)return e(o.catchLoc,!0)}else{if(!a)throw Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return e(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;0<=r;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&c.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}var i=(o=o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc?null:o)?o.completion:{};return i.type=e,i.arg=t,o?(this.method="next",this.next=o.finallyLoc,g):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),g},finish:function(e){for(var t=this.tryEntries.length-1;0<=t;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),x(r),g}},catch:function(e){for(var t=this.tryEntries.length-1;0<=t;--t){var r,n,o=this.tryEntries[t];if(o.tryLoc===e)return"throw"===(r=o.completion).type&&(n=r.arg,x(o)),n}throw Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:O(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=s),g}},u}function asyncGeneratorStep(e,t,r,n,o,i,u){try{var a=e[i](u),s=a.value}catch(e){return void r(e)}a.done?t(s):Promise.resolve(s).then(n,o)}function _asyncToGenerator(a){return function(){var e=this,u=arguments;return new Promise(function(t,r){var n=a.apply(e,u);function o(e){asyncGeneratorStep(n,t,r,o,i,"next",e)}function i(e){asyncGeneratorStep(n,t,r,o,i,"throw",e)}o(void 0)})}}module.exports=function(p){require("source-map-support").install();var g=require("./modbus-basics"),m=require("./core/modbus-queue-core"),y=require("debug")("contribModbus:queue");p.nodes.registerType("modbus-queue-info",function(e){p.nodes.createNode(this,e);var t=e.name,r=e.topic,n=e.unitid,o=e.lowLowLevel,i=e.lowLevel,u=e.highLevel,a=e.highHighLevel,s=e.errorOnHighLevel,c=e.queueReadIntervalTime,l=e.showStatusActivities,h=e.updateOnAllQueueChanges,d=e.updateOnAllUnitQueues,f=(this.name=t,this.topic=r,this.unitid=parseInt(n)||1,this.lowLowLevel=parseInt(o),this.lowLevel=parseInt(i),this.highLevel=parseInt(u),this.highHighLevel=parseInt(a),this.errorOnHighLevel=s,this.queueReadIntervalTime=c||1e3,this.showStatusActivities=l,this.updateOnAllQueueChanges=h,this.updateOnAllUnitQueues=d,this.internalDebugLog=y,this),v=(f.queueReadInterval=null,f.updateStatusRunning=!1,f.unitsWithQueue=new Map,g.setNodeStatusTo("waiting",f),p.nodes.getNode(e.server));v&&(v.registerForModbus(f),f.initUnitQueueStates=function(){for(var e=0;e<256;e+=1)f.unitsWithQueue.set(e,{}),f.resetStates(e)},f.resetStates=function(e){e=f.unitsWithQueue.has(e)?f.unitsWithQueue.get(e):{};e.lowLowLevelReached=!0,e.lowLevelReached=!1,e.highLevelReached=!1,e.highHighLevelReached=!1},f.errorProtocolMsg=function(e,t){f.showErrors&&g.logMsgError(f,e,t)},f.initUnitQueueStates(),f.checkLowLevelReached=function(e,t,r){var n=e.unitsWithQueue.get(r);!n.lowLevelReached&&t>e.lowLowLevel&&t<e.lowLevel&&(n.lowLevelReached=!0,n={payload:Date.now(),topic:e.topic,state:"low level reached",unitid:r,modbusClientName:v.name,bufferCommandListLength:t},e.send(n))},f.checkHighLevelReached=function(e,t,r){var n=e.unitsWithQueue.get(r);!n.highLevelReached&&t>e.lowLevel&&t>e.highLevel&&(n.highLevelReached=!0,n={payload:Date.now(),topic:e.topic,state:"high level reached",unitid:r,modbusClientName:v.name||v.id,highLevel:e.highLevel,bufferCommandListLength:t},e.errorOnHighLevel?e.error(new Error("Queue High Level Reached"),n):e.warn(n),e.send(n))},f.checkHighHighLevelReached=function(e,t,r){var n=e.unitsWithQueue.get(r);!n.highHighLevelReached&&t>e.highLevel&&t>e.highHighLevel&&(n.highHighLevelReached=!0,n={payload:Date.now(),topic:e.topic,state:"high high level reached",unitid:r,modbusClientName:v.name||v.id,highLevel:e.highLevel,highHighLevel:e.highHighLevel,bufferCommandListLength:t},e.error(new Error("Queue High High Level Reached"),n),e.send(n))},f.getStatusSituationFillColor=function(e){var e=f.unitsWithQueue.get(e),t="blue";switch(!0){case e.lowLevelReached:t="green";break;case e.highLevelReached:t=f.errorOnHighLevel?"red":"yellow";break;case e.highHighLevelReached:t="red"}return t},f.setNodeStatusByActivity=function(e,t){f.showStatusActivities&&f.status({fill:f.getStatusSituationFillColor(f.unitid),shape:"ring",text:e?"active unit ".concat(t," queue items: ").concat(e):"active (Unit-Id: ".concat(t,") empty")})},f.readFromQueue=_asyncToGenerator(_regeneratorRuntime().mark(function e(){var t,r;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(f.updateStatusRunning)return e.abrupt("return");e.next=2;break;case 2:t=f.unitid<1||255<f.unitid?1:f.unitid,v.bufferCommands?(e.prev=4,f.updateStatusRunning=!0,r=v.bufferCommandList.get(t).length,f.checkQueueStates(r,t),f.setNodeStatusByActivity(r,t),f.updateStatusRunning=!1,e.next=16):e.next=18;break;case 12:throw e.prev=12,e.t0=e.catch(4),f.updateStatusRunning=!1,e.t0;case 16:e.next=19;break;case 18:f.showStatusActivities&&f.setNodeStatusByActivity(null,t);case 19:case"end":return e.stop()}},e,null,[[4,12]])})),f.checkQueueStates=function(e,t){!f.unitsWithQueue.get(t).lowLowLevelReached&&e<f.lowLowLevel&&f.resetStates(t),f.checkLowLevelReached(f,e,t),f.checkHighLevelReached(f,e,t),f.checkHighHighLevelReached(f,e,t)},f.readFromAllUnitQueues=function(){return!f.updateStatusRunning&&v.bufferCommands?new Promise(function(e,t){try{f.updateStatusRunning=!0;for(var r,n=0;n<256;n+=1)(r=v.bufferCommandList.get(n).length)&&f.checkQueueStates(r,n);f.updateStatusRunning=!1,e()}catch(e){f.updateStatusRunning=!1,t(e)}}):void 0},f.registerModbusQueueActionsToNode=function(e){f.updateOnAllQueueChanges&&v.on("mbqueue",e),v.on("mbactive",e),v.on("mbinit",e),v.on("mbconnected",e),v.on("mberror",e),v.on("mbclosed",e),f.queueReadInterval=setInterval(e,f.queueReadIntervalTime)},f.removeModbusQueueActionsFromNode=function(e){v.removeListener("mbqueue",e),v.removeListener("mbactive",e),v.removeListener("mbinit",e),v.removeListener("mbconnected",e),v.removeListener("mberror",e),v.removeListener("mbclosed",e)},f.updateOnAllUnitQueues?(f.registerModbusQueueActionsToNode(f.readFromAllUnitQueues),g.setNodeStatusTo("active for all queues",f)):f.registerModbusQueueActionsToNode(f.readFromQueue),f.on("input",function(t){var r=f.unitid;if(t.payload.queueEnabled=v.bufferCommands,f.updateOnAllUnitQueues)t.payload.allQueueData=!0,t.payload.queues=v.bufferCommandList;else{try{r=t.payload.resetQueue?parseInt(t.payload.unitId)||f.unitid:parseInt(t.payload)||f.unitid}catch(e){f.errorProtocolMsg(e,t),g.sendEmptyMsgOnFail(f,e,t),r=f.unitid}t.payload.allQueueData=!1,t.payload.unitid=r,t.payload.queue=v.bufferCommandList.get(r)}t.payload.queueOptions={date:Date.now(),state:"queue request",modbusClientName:v.name||v.id,lowlowLevel:f.lowlowLevel,unitId:r,lowLevel:f.lowLevel,highLevel:f.highLevel,highHighLevel:f.highHighLevel},(t.payload.resetQueue||t.resetQueue)&&v.bufferCommands&&(m.initQueue(v),p.settings.verbose&&(v.warn(r="Init Queue By External Node"),y(r)),f.initUnitQueueStates(),f.showStatusActivities&&f.status({fill:"blue",shape:"ring",text:"active empty unit queue"}),t.payload.queueOptions.state="queue reset done"),f.send(t)}),f.on("close",function(e){f.updateOnAllUnitQueues?f.removeModbusQueueActionsFromNode(f.readFromAllUnitQueues):f.removeModbusQueueActionsFromNode(f.readFromQueue),g.setNodeStatusTo("closed",f),f.queueReadInterval&&clearInterval(f.queueReadInterval),f.queueReadInterval=null,v.deregisterForModbus(f.id,e)}),f.showStatusActivities||g.setNodeDefaultStatus(f))})}; //# sourceMappingURL=maps/modbus-queue-info.js.map