Sensor
function Buffer(e,t){return fromHexString(e)}function fromHexString(e){const t=e.match(/.{1,2}/g);return t?new Uint8Array(t.map(function(e){return parseInt(e,16)})):new Uint8Array}!function(e){const t=1e5;function r(e){switch(typeof e){case"undefined":return"undefined";case"boolean":return"boolean";case"number":return"number";case"string":return"string";default:return null===e?"null":"object"}}function n(e){return Object.prototype.toString.call(e).replace(/^\[object *|\]$/g,"")}function o(e){return"function"==typeof e}function a(e){if(null==e)throw TypeError();return Object(e)}function i(e){return e>>0}function c(e){return e>>>0}const{LN2:u}=Math,{abs:s}=Math,{floor:f}=Math,{log:p}=Math,{max:d}=Math,{min:l}=Math,{pow:y}=Math,{round:h}=Math;function m(e,t){const r=32-t;return e<>r}function g(e,t){const r=32-t;return e<>>r}function v(e){return[255&e]}function b(e){return m(e[0],8)}function E(e){return[255&e]}function T(e){return g(e[0],8)}function P(e){return[(e=h(Number(e)))<0?0:e>255?255:255&e]}function B(e){return[255&e,e>>8&255]}function I(e){return m(e[1]<<8|e[0],16)}function w(e){return[255&e,e>>8&255]}function C(e){return g(e[1]<<8|e[0],16)}function x(e){return[255&e,e>>8&255,e>>16&255,e>>24&255]}function U(e){return m(e[3]<<24|e[2]<<16|e[1]<<8|e[0],32)}function O(e){return[255&e,e>>8&255,e>>16&255,e>>24&255]}function S(e){return g(e[3]<<24|e[2]<<16|e[1]<<8|e[0],32)}function _(e,t,r){const n=(1<.5?t+1:t%2?t+1:t}let a,i,c;if(e!=e)i=(1<=y(2,1-n)){i=l(f(p(e)/u),1023);let a=e/y(2,i);a<1&&(i-=1,a*=2),a>=2&&(i+=1,a/=2);const s=y(2,r);i+=n,(c=o(a*s)-s)/s>=1&&(i+=1,c=0),i>2*n&&(i=(1<>=1;return n.reverse(),c=n.join(""),u=(1<0?s*y(2,f-u)*(1+p/y(2,r)):0!==p?s*y(2,-(u-1))*(p/y(2,r)):s<0?-0:0}function A(e){return D(e,11,52)}function j(e){return _(e,11,52)}function F(e){return D(e,8,23)}function N(e){return _(e,8,23)}!function(){const e=Object.defineProperty,t=!function(){try{return Object.defineProperty({},"x",{})}catch(e){return!1}}();e&&!t||(Object.defineProperty=function(t,r,n){if(e)try{return e(t,r,n)}catch(e){}if(t!==Object(t))throw TypeError("Object.defineProperty called on non-object");return Object.prototype.__defineGetter__&&"get"in n&&Object.prototype.__defineGetter__.call(t,r,n.get),Object.prototype.__defineSetter__&&"set"in n&&Object.prototype.__defineSetter__.call(t,r,n.set),"value"in n&&(t[r]=n.value),t})}(),function(){function u(e){if((e=i(e))<0)throw RangeError("ArrayBuffer size is not a small enough positive integer.");Object.defineProperty(this,"byteLength",{value:e}),Object.defineProperty(this,"_bytes",{value:Array(e)});for(let t=0;t=1&&"object"===r(arguments[0])&&arguments[0]instanceof p)return function(e){if(this.constructor!==e.constructor)throw TypeError();const t=e.length*this.BYTES_PER_ELEMENT;Object.defineProperty(this,"buffer",{value:new u(t)}),Object.defineProperty(this,"byteLength",{value:t}),Object.defineProperty(this,"byteOffset",{value:0}),Object.defineProperty(this,"length",{value:e.length});for(let t=0;t=1&&"object"===r(arguments[0])&&!(arguments[0]instanceof p)&&!(arguments[0]instanceof u||"ArrayBuffer"===n(arguments[0])))return function(e){const t=e.length*this.BYTES_PER_ELEMENT;Object.defineProperty(this,"buffer",{value:new u(t)}),Object.defineProperty(this,"byteLength",{value:t}),Object.defineProperty(this,"byteOffset",{value:0}),Object.defineProperty(this,"length",{value:e.length});for(let t=0;t=1&&"object"===r(arguments[0])&&(arguments[0]instanceof u||"ArrayBuffer"===n(arguments[0])))return function(e,t,r){if((t=c(t))>e.byteLength)throw RangeError("byteOffset out of range");if(t%this.BYTES_PER_ELEMENT)throw RangeError("buffer length minus the byteOffset is not a multiple of the element size.");if(void 0===r){var n=e.byteLength-t;if(n%this.BYTES_PER_ELEMENT)throw RangeError("length of buffer minus byteOffset not a multiple of the element size");r=n/this.BYTES_PER_ELEMENT}else n=(r=c(r))*this.BYTES_PER_ELEMENT;if(t+n>e.byteLength)throw RangeError("byteOffset and length reference an area beyond the end of the buffer");Object.defineProperty(this,"buffer",{value:e}),Object.defineProperty(this,"byteLength",{value:n}),Object.defineProperty(this,"byteOffset",{value:t}),Object.defineProperty(this,"length",{value:r})}.apply(this,arguments);throw TypeError()}e.ArrayBuffer=e.ArrayBuffer||u,Object.defineProperty(p,"from",{value(e){return new this(e)}}),Object.defineProperty(p,"of",{value(){return new this(arguments)}});const y={};function h(r,n,o){var a=function(){Object.defineProperty(this,"constructor",{value:a}),p.apply(this,arguments),function(r){if("TYPED_ARRAY_POLYFILL_NO_ARRAY_ACCESSORS"in e)return;if(r.length>t)throw RangeError("Array too large for polyfill");function n(e){Object.defineProperty(r,e,{get:()=>r._getter(e),set(t){r._setter(e,t)},enumerable:!0,configurable:!1})}let o;for(o=0;o=this.length)return;const t=[];let r,n;for(r=0,n=this.byteOffset+e*this.BYTES_PER_ELEMENT;r=this.length)return;const r=this._pack(t);let n,o;for(n=0,o=this.byteOffset+e*this.BYTES_PER_ELEMENT;n0;)n._setter(s,n._getter(p)),p+=m,s+=m,g-=1;return n}}),Object.defineProperty(p.prototype,"every",{value(e){if(null==this)throw TypeError();const t=Object(this),r=c(t.length);if(!o(e))throw TypeError();const n=arguments[1];for(let o=0;o1?arguments[1]:void 0;let i=0;for(;i1?arguments[1]:void 0;let i=0;for(;i0&&((n=Number(arguments[1]))!=n?n=0:0!==n&&n!==1/0&&n!==-1/0&&(n=(n>0||-1)*f(s(n)))),n>=r)return-1;let o=n>=0?n:d(r-s(n),0);for(;o1&&((n=Number(arguments[1]))!=n?n=0:0!==n&&n!==1/0&&n!==-1/0&&(n=(n>0||-1)*f(s(n))));let o=n>=0?l(n,r-1):r-s(n);for(;o>=0;o--)if(t._getter(o)===e)return o;return-1}}),Object.defineProperty(p.prototype,"map",{value(e){if(null==this)throw TypeError();const t=Object(this),r=c(t.length);if(!o(e))throw TypeError();const n=[];n.length=r;const a=arguments[1];for(let o=0;o=2?arguments[1]:t._getter(a++);a=2?arguments[1]:t._getter(a--);a>=0;)n=e.call(void 0,n,t._getter(a),a,t),a--;return n}}),Object.defineProperty(p.prototype,"reverse",{value(){if(null==this)throw TypeError();const e=Object(this),t=c(e.length),r=f(t/2);for(let n=0,o=t-1;nthis.length)throw RangeError("Offset plus length of array is out of range");if(f=this.byteOffset+o*this.BYTES_PER_ELEMENT,p=r.length*this.BYTES_PER_ELEMENT,r.buffer===this.buffer){for(d=[],i=0,u=r.byteOffset;ithis.length)throw RangeError("Offset plus length of array is out of range");for(i=0;ir?1:0}),o=0;or?r:e}e=i(e),t=i(t),arguments.length<1&&(e=0),arguments.length<2&&(t=this.length),e<0&&(e=this.length+e),t<0&&(t=this.length+t),e=r(e,0,this.length);let n=(t=r(t,0,this.length))-e;return n<0&&(n=0),new this.constructor(this.buffer,this.byteOffset+e*this.BYTES_PER_ELEMENT,n)}});const m=h(1,v,b),g=h(1,E,T),_=h(1,P,T),D=h(2,B,I),R=h(2,w,C),L=h(4,x,U),M=h(4,O,S),G=h(4,N,F),k=h(8,j,A);e.Int8Array=e.Int8Array||m,e.Uint8Array=e.Uint8Array||g,e.Uint8ClampedArray=e.Uint8ClampedArray||_,e.Int16Array=e.Int16Array||D,e.Uint16Array=e.Uint16Array||R,e.Int32Array=e.Int32Array||L,e.Uint32Array=e.Uint32Array||M,e.Float32Array=e.Float32Array||G,e.Float64Array=e.Float64Array||k}(),function(){function t(e,t){return o(e.get)?e.get(t):e[t]}const r=function(){const e=new Uint16Array([4660]);return 18===t(new Uint8Array(e.buffer),0)}();function a(e,t,r){if(!(e instanceof ArrayBuffer||"ArrayBuffer"===n(e)))throw TypeError();if((t=c(t))>e.byteLength)throw RangeError("byteOffset out of range");if(t+(r=void 0===r?e.byteLength-t:c(r))>e.byteLength)throw RangeError("byteOffset and length reference an area beyond the end of the buffer");Object.defineProperty(this,"buffer",{value:e}),Object.defineProperty(this,"byteLength",{value:r}),Object.defineProperty(this,"byteOffset",{value:t})}function i(e){return function(n,o){if((n=c(n))+e.BYTES_PER_ELEMENT>this.byteLength)throw RangeError("Array index out of range");n+=this.byteOffset;const a=new Uint8Array(this.buffer,n,e.BYTES_PER_ELEMENT),i=[];for(let r=0;rthis.byteLength)throw RangeError("Array index out of range");const i=new e([o]),u=new Uint8Array(i.buffer),s=[];let f,p;for(f=0;f0},t.prototype.getActiveParsers=function(e,t){const r=this;let n=[],o=this.parsers.filter(function(n){return r.isCompatibleDeviceType(n,e)&&(n.frameCode<0||n.frameCode===t)});if(0===o.length&&"repeater"!==e){const e=this.parsers.filter(function(e){return"any"===e.deviceType&&(e.frameCode<0||e.frameCode===t)});o=n.concat(e)}if(o.length>0){const t=this.parsers.filter(function(t){return r.isCompatibleDeviceType(t,e)&&0===t.frameCode});if(n=n.concat(t),0===t.length){const e=this.parsers.filter(function(e){return"any"===e.deviceType&&0===e.frameCode});n=n.concat(e)}}return n=n.concat(o)},t}();e.Decoder=t}(codec||(codec={})),function(e){const t=function(){function t(){this.builders=[new e.Repeater0x01Builder,new e.Repeater0x02Builder,new e.Repeater0x03Builder,new e.Repeater0x04Builder,new e.Repeater0x05Builder]}return t.prototype.getSupported=function(){return this.builders.map(function(e){return{deviceType:e.deviceType,frameCode:e.frameCode}})},t.prototype.getInputDataTypes=function(e,t){const r=this.builders.find(function(r){return r.deviceType===e&&r.frameCode===t});if(!r)return{};const n={},o=new r.inputDataClass;for(const e in o)o.hasOwnProperty(e)&&(n[e]=typeof o[e]);return n},t.prototype.encode=function(e,t,r,n){void 0===r&&(r="unknown");const o=this.builders.find(function(r){return r.deviceType===e&&r.frameCode===t});return o?o.buildFrame(n||new o.inputDataClass,r).toString("hex"):""},t}();e.Encoder=t}(codec||(codec={})),"undefined"!=typeof module&&(module.exports=codec),"undefined"!=typeof process&&"test"===process.env.NODE_ENV&&(global.codec=codec),function(e){const t=function(){function e(){this.store={}}return e.prototype.getItem=function(e){return this.store[e]},e.prototype.removeItem=function(e){delete this.store[e]},e.prototype.setItem=function(e,t){this.store[e]=t},e}();e.InternalCodecStorage=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="comfort",this.frameCode=16}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x10 Comfort configuration"};return n.transmissionPeriodKeepAlive={unit:"s",value:10*e.readUInt16BE(2)},n.numberOfHistorizationBeforeSending=e.readUInt16BE(4),n.numberOfSamplingBeforeHistorization=e.readUInt16BE(6),n.samplingPeriod={unit:"s",value:2*e.readUInt16BE(8)},n.calculatedPeriodRecording={unit:"s",value:e.readUInt16BE(8)*e.readUInt16BE(6)*2},n.calculatedSendingPeriod={unit:"s",value:e.readUInt16BE(8)*e.readUInt16BE(6)*e.readUInt16BE(4)*2},n},e}();e.Comfort0x10Parser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="comfort",this.frameCode=76}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x4c Comfort data"};let o;const a=[],i=[];for(let t=2;t>4?"active":"inactive",temperature:{unit:"°C",value:e.readInt16BE(3)/10}},n.alarmHumidity={alarmStatus:1&e.readUInt8(2)?"active":"inactive",humidity:{unit:"%",value:e.readUInt8(5)}},n},e}();e.Comfort0x4dParser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="comfortCo2",this.frameCode=16}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x10 Comfort CO2 configuration"};return n.dailyFrameActivated=Boolean(0!==e.readUInt16BE(2)),n.numberOfHistorizationBeforeSending=e.readUInt16BE(4),n.numberOfSamplingBeforeHistorization=e.readUInt16BE(6),n.samplingPeriod={unit:"s",value:2*e.readUInt16BE(8)},n.redundantSamples=e.readUInt8(10),n.calculatedPeriodRecording={unit:"s",value:e.readUInt16BE(8)*e.readUInt16BE(6)*2},n.calculatedSendingPeriod={unit:"s",value:e.readUInt16BE(8)*e.readUInt16BE(6)*e.readUInt16BE(4)*2},e.byteLength>=12&&(n.blackOutDuration={unit:"h",value:e.readUInt8(11)},n.blackOutStartTime={unit:"h",value:e.readUInt8(12)}),n},e}();e.ComfortCo20x10Parser=t}(codec||(codec={})),function(e){const t=function(){function t(){this.deviceType="comfortCo2",this.frameCode=48}return t.prototype.parseFrame=function(t,r,n){const o={type:"0x30 Comfort CO2 Daily frame"};if(4&t[1]){const e=new Date(1e3*(t.readUInt32BE(19)+1356998400));o.timestamp=e.toJSON().replace("Z","")}switch(o.icone=t.readUInt8(2),o.qaiRedDuration={unit:"min",value:10*t.readUInt8(3)},o.temperatureMax={unit:"°C",value:t.readInt16BE(4)/10},o.co2Max={unit:"ppm",value:t.readUInt16BE(6)},o.humidityMax={unit:"%",value:t.readUInt8(8)},o.temperatureMin={unit:"°C",value:t.readInt16BE(9)/10},t.byteLength){case 11:break;case 19:case 23:o.co2Min={unit:"ppm",value:t.readUInt16BE(11)},o.humidityMin={unit:"%",value:t.readUInt8(13)},o.temperatureAverage={unit:"°C",value:t.readInt16BE(14)/10},o.co2Average={unit:"ppm",value:t.readUInt16BE(16)},o.humidityAverage={unit:"%",value:t.readUInt8(18)};break;default:o.partialDecoding=e.PartialDecodingReason.MISSING_NETWORK}return o},t}();e.ComfortCo20x30Parser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="comfortCo2",this.frameCode=106}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x6a Comfort CO2 data"},o=4&e[1]?e.byteLength-4:e.byteLength;if(4&e[1]){const t=new Date(1e3*(e.readUInt32BE(o)+1356998400));n.timestamp=t.toJSON().replace("Z","")}let a;const i=[],c=[],u=[];for(let t=2;t>4?"active":"inactive",temperature:{unit:"°C",value:e.readInt16BE(3)/10}},n.alarmHumidity={alarmStatus:1&e.readUInt8(2)?"active":"inactive",humidity:{unit:"%",value:e.readUInt8(5)}},n},e}();e.Comfort20x4dParser=t}(codec||(codec={})),function(e){const t=function(){function t(){this.deviceType="comfort2",this.frameCode=0}return t.prototype.parseFrame=function(t,r,n){let o={};return(o=(new e.GenericStatusByteParser).parseFrame(t,r)).configurationInconsistency=Boolean(8&t[1]),o.timestamp=Boolean(4&t[1]),{status:o}},t}();e.Comfort2StatusByteParser=t}(codec||(codec={})),function(e){const t=function(){function t(){this.deviceType="drycontacts",this.frameCode=16}return t.prototype.parseFrame=function(t,r,n){const o={type:"0x10 Dry Contacts configuration"};o.productMode=e.PlateformCommonUtils.getProductModeText(t[8]),1===t[8]?(o.keepAlivePeriod={unit:"m",value:10*t.readUInt8(2)},o.transmitPeriod={unit:"m",value:10*t.readUInt8(3)}):(o.keepAlivePeriod={unit:"s",value:20*t.readUInt8(2)},o.transmitPeriod={unit:"s",value:20*t.readUInt8(3)});let a=this.getDebounceText(t[4]>>4),i=this.getTypeText(15&t[4]);return"disabled"===i[0]?o.channelA={type:i[0]}:o.channelA={type:i[0],edge:i[1],debounceDuration:{unit:a[1],value:a[0]}},a=this.getDebounceText(t[5]>>4),"disabled"===(i=this.getTypeText(15&t[5]))[0]?o.channelB={type:i[0]}:o.channelB={type:i[0],edge:i[1],debounceDuration:{unit:a[1],value:a[0]}},a=this.getDebounceText(t[6]>>4),"disabled"===(i=this.getTypeText(15&t[6]))[0]?o.channelC={type:i[0]}:o.channelC={type:i[0],edge:i[1],debounceDuration:{unit:a[1],value:a[0]}},a=this.getDebounceText(t[7]>>4),"disabled"===(i=this.getTypeText(15&t[7]))[0]?o.channelD={type:i[0]}:o.channelD={type:i[0],edge:i[1],debounceDuration:{unit:a[1],value:a[0]}},o},t.prototype.getTypeText=function(e){switch(e){case 0:return["disabled",""];case 1:return["inputPeriodic","high"];case 2:return["inputPeriodic","low"];case 3:return["inputPeriodic","both"];case 4:return["inputEvent","high"];case 5:return["inputEvent","low"];case 6:return["inputEvent","both"];case 7:return["output","high"];case 8:return["output","low"];default:return["disabled",""]}},t.prototype.getDebounceText=function(e){switch(e){case 0:return[0,"s"];case 1:return[10,"ms"];case 2:return[20,"ms"];case 3:return[50,"ms"];case 4:return[100,"ms"];case 5:return[200,"ms"];case 6:return[500,"ms"];case 7:return[1,"s"];case 8:return[2,"s"];case 9:return[5,"s"];case 10:return[10,"s"];case 11:return[20,"s"];case 12:return[40,"s"];case 13:return[60,"s"];case 14:return[5,"m"];case 15:return[10,"m"];default:return[0,"s"]}},t}();e.Drycontacts0x10Parser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="drycontacts",this.frameCode=64}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x40 Dry Contacts data",decodingInfo:"true: ON/CLOSED, false: OFF/OPEN"};return n.channelA={value:e.readUInt16BE(2),currentState:Boolean(1&e[10]),previousFrameState:Boolean(2&e[10])},n.channelB={value:e.readUInt16BE(4),currentState:Boolean(4&e[10]),previousFrameState:Boolean(8&e[10])},n.channelC={value:e.readUInt16BE(6),currentState:Boolean(16&e[10]),previousFrameState:Boolean(32&e[10])},n.channelD={value:e.readUInt16BE(8),currentState:Boolean(64&e[10]),previousFrameState:Boolean(128&e[10])},n},e}();e.Drycontacts0x40Parser=t}(codec||(codec={})),function(e){const t=function(){function t(){this.deviceType="drycontacts",this.frameCode=0}return t.prototype.parseFrame=function(t,r){let n={};return{status:n=(new e.GenericStatusByteParser).parseFrame(t,r)}},t}();e.DrycontactsStatusByteParser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="drycontacts2",this.frameCode=16}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x10 Dry Contacts 2 configuration"};n.keepAlivePeriod={unit:"s",value:10*e.readUInt16BE(2)},n.transmitPeriod={unit:"s",value:10*e.readUInt16BE(4)};let o=this.getDebounceText(e[6]>>4),a=this.getTypeText(15&e[6]);return"disabled"===a[0]||"output"===a[0]?n.channelA={type:a[0]}:n.channelA={type:a[0],edge:a[1],debounceDuration:{unit:o[1],value:o[0]}},o=this.getDebounceText(e[7]>>4),"disabled"===(a=this.getTypeText(15&e[7]))[0]||"output"===a[0]?n.channelB={type:a[0]}:n.channelB={type:a[0],edge:a[1],debounceDuration:{unit:o[1],value:o[0]}},o=this.getDebounceText(e[8]>>4),"disabled"===(a=this.getTypeText(15&e[8]))[0]||"output"===a[0]?n.channelC={type:a[0]}:n.channelC={type:a[0],edge:a[1],debounceDuration:{unit:o[1],value:o[0]}},o=this.getDebounceText(e[9]>>4),"disabled"===(a=this.getTypeText(15&e[9]))[0]||"output"===a[0]?n.channelD={type:a[0]}:n.channelD={type:a[0],edge:a[1],debounceDuration:{unit:o[1],value:o[0]}},n},e.prototype.getTypeText=function(e){switch(e){case 0:return["disabled",""];case 1:return["input","high"];case 2:return["input","low"];case 3:return["input","both"];case 4:return["output",""];default:return["disabled",""]}},e.prototype.getDebounceText=function(e){switch(e){case 0:return[0,"s"];case 1:return[10,"ms"];case 2:return[20,"ms"];case 3:return[50,"ms"];case 4:return[100,"ms"];case 5:return[200,"ms"];case 6:return[500,"ms"];case 7:return[1,"s"];case 8:return[2,"s"];case 9:return[5,"s"];case 10:return[10,"s"];case 11:return[20,"s"];case 12:return[40,"s"];case 13:return[60,"s"];case 14:return[5,"m"];case 15:return[10,"m"];default:return[0,"s"]}},e}();e.Drycontacts20x10Parser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="drycontacts2",this.frameCode=48}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x30 Dry Contacts 2 keep alive"};if(4&e[1]){const t=new Date(1e3*(e.readUInt32BE(11)+1356998400));n.timestamp=t.toJSON().replace("Z","")}return n.channelA={value:e.readUInt16BE(2),state:Boolean(1&e[10])},n.channelB={value:e.readUInt16BE(4),state:Boolean(2&e[10])},n.channelC={value:e.readUInt16BE(6),state:Boolean(4&e[10])},n.channelD={value:e.readUInt16BE(8),state:Boolean(8&e[10])},n},e}();e.Drycontacts20x30Parser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="drycontacts2",this.frameCode=64}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x40 Dry Contacts 2 data"};if(4&e[1]){const t=new Date(1e3*(e.readUInt32BE(11)+1356998400));n.timestamp=t.toJSON().replace("Z","")}return n.decodingInfo="true: ON/CLOSED, false: OFF/OPEN",n.channelA={value:e.readUInt16BE(2),currentState:Boolean(1&e[10]),previousFrameState:Boolean(2&e[10])},n.channelB={value:e.readUInt16BE(4),currentState:Boolean(4&e[10]),previousFrameState:Boolean(8&e[10])},n.channelC={value:e.readUInt16BE(6),currentState:Boolean(16&e[10]),previousFrameState:Boolean(32&e[10])},n.channelD={value:e.readUInt16BE(8),currentState:Boolean(64&e[10]),previousFrameState:Boolean(128&e[10])},n},e}();e.Drycontacts20x40Parser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="drycontacts2",this.frameCode=65}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x41 Dry Contacts 2 duration alarm"};if(4&e[1]){const t=new Date(1e3*(e.readUInt32BE(5)+1356998400));n.timestamp=t.toJSON().replace("Z","")}return n.channel=e.readUInt8(2),n.durationThreshold={unit:"min",value:e.readUInt16BE(3)},n},e}();e.Drycontacts20x41Parser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="drycontacts2",this.frameCode=89}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x59 Dry Contacts 2 time counting data"};if(4&e[1]){const t=new Date(1e3*(e.readUInt32BE(e.length-4)+1356998400));n.timestamp=t.toJSON().replace("Z","")}let o=3;return 1&e[2]&&(n.channelATimeCounter={unit:"s",value:e.readUInt32BE(o)},o+=4),2&e[2]&&(n.channelBTimeCounter={unit:"s",value:e.readUInt32BE(o)},o+=4),4&e[2]&&(n.channelCTimeCounter={unit:"s",value:e.readUInt32BE(o)},o+=4),8&e[2]&&(n.channelDTimeCounter={unit:"s",value:e.readUInt32BE(o)}),n},e}();e.Drycontacts20x59Parser=t}(codec||(codec={})),function(e){const t=function(){function t(){this.deviceType="drycontacts2",this.frameCode=0}return t.prototype.parseFrame=function(t,r,n){let o={};return(o=(new e.GenericStatusByteParser).parseFrame(t,r)).timestamp=Boolean(4&t[1]),{status:o}},t}();e.Drycontacts2StatusByteParser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="comfort|comfort2|comfortCo2|breath",this.frameCode=31}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x1f digital input configuration"},o={},a={};return o.type=this.getTypeText(15&e[2]),o.debouncingPeriod={unit:"ms",value:this.getDebouncingPeriodText((240&e[2])>>4)},o.threshold=e.readUInt16BE(3),a.type=this.getTypeText(15&e[5]),a.debouncingPeriod={unit:"ms",value:this.getDebouncingPeriodText((240&e[5])>>4)},a.threshold=e.readUInt16BE(6),n.digitalInput1=o,n.digitalInput2=a,n},e.prototype.getDebouncingPeriodText=function(e){switch(e){case 0:return 0;case 1:return 10;case 2:return 20;case 3:return 500;case 4:return 100;case 5:return 200;case 6:return 500;case 7:return 1e3;case 8:return 2e3;case 9:return 5e3;case 10:return 1e4;case 11:return 2e4;case 12:return 4e4;case 13:return 6e4;case 14:return 3e5;case 15:return 6e5;default:return 0}},e.prototype.getTypeText=function(e){switch(e){case 0:return"deactivated";case 1:return"highEdge";case 2:return"lowEdge";case 3:return"bothEdges";default:return""}},e}();e.Generic0x1fParser=t}(codec||(codec={})),function(e){const t=function(){function t(){this.deviceType="any",this.frameCode=32}return t.prototype.parseFrame=function(t,r,n,o){const a={type:"0x20 Configuration"};switch(t.byteLength){case 4:a.loraAdr=Boolean(1&t[2]),a.loraProvisioningMode=0===t[3]?"ABP":"OTAA","analog"!==o&&"drycontacts"!==o&&"pulse"!==o&&"temp"!==o&&(a.loraDutycyle=4&t[2]?"activated":"deactivated",a.loraClassMode=32&t[2]?"CLASS C":"CLASS A");break;case 3:case 5:a.sigfoxRetry=3&t[2],5===t.byteLength&&(a.sigfoxDownlinkPeriod={unit:"m",value:t.readInt16BE(3)});break;default:a.partialDecoding=e.PartialDecodingReason.MISSING_NETWORK}return a},t}();e.Generic0x20Parser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="drycontacts|drycontacts2|temp4",this.frameCode=47}return e.prototype.parseFrame=function(e,t){const r={type:"0x2f Downlink ack"};return r.downlinkFramecode=`0x${e[2].toString(16)}`,r.requestStatus=this.getRequestStatusText(e[3]),r},e.prototype.getRequestStatusText=function(e){switch(e){case 1:return"success";case 2:return"errorGeneric";case 3:return"errorWrongState";case 4:return"errorInvalidRequest";default:return"errorOtherReason"}},e}();e.Generic0x2fParser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="any",this.frameCode=48}return e.prototype.parseFrame=function(e,t,r){return{type:"0x30 Keep alive"}},e}();e.Generic0x30Parser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="drycontacts|drycontacts2|pulse3|pulse4|temp3|temp4|comfort|comfort2|comfortCo2|breath",this.frameCode=51}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x33 Set register status"};return n.requestStatus=this.getRequestStatusText(e[2]),n.registerId=e.readUInt16BE(3),n},e.prototype.getRequestStatusText=function(e){switch(e){case 1:return"success";case 2:return"successNoUpdate";case 3:return"errorCoherency";case 4:return"errorInvalidRegister";case 5:return"errorInvalidValue";case 6:return"errorTruncatedValue";case 7:return"errorAccesNotAllowed";default:return"errorOtherReason"}},e}();e.Generic0x33Parser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="temp4",this.frameCode=54}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x36 Alert message"};switch(e[2]){case 0:n.alertCode="normalState";break;case 1:n.alertCode="uplinkDownlinkForbidden"}return n},e}();e.Generic0x36Parser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="temp4|comfort2|comfortCo2|breath",this.frameCode=55}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x37 Software version"};return n.appVersion=`${e.readUInt8(2)}.${e.readUInt8(3)}.${e.readUInt8(4)}`,n.rtuVersion=`${e.readUInt8(5)}.${e.readUInt8(6)}.${e.readUInt8(7)}`,n},e}();e.Generic0x37Parser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="comfort|comfort2|comfortCo2|breath",this.frameCode=81}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x51 digital input 1 alarm"};if(4&e[1]){const t=new Date(1e3*(e.readUInt32BE(9)+1356998400));n.timestamp=t.toJSON().replace("Z","")}return n.state={previousFrame:Boolean(e.readUInt8(2)>>1&1),current:Boolean(e.readUInt8(2)>>0&1)},n.counter={global:e.readUInt32BE(3),instantaneous:e.readUInt16BE(7)},n},e}();e.Generic0x51Parser=t}(codec||(codec={}));var codec,__assign=this&&this.__assign||function(){return(__assign=Object.assign||function(e){for(var t,r=1,n=arguments.length;r>5,r.hardwareError=!1,r.lowBattery=Boolean(2&e[1]),r.configurationDone=Boolean(1&e[1]),r},e}();e.GenericStatusByteParser=t}(codec||(codec={})),function(e){const t=function(){function t(){this.deviceType="pulse",this.frameCode=16,this.pulse0x11Parser=new e.Pulse0x11Parser,this.pulse0x12Parser=new e.Pulse0x12Parser}return t.prototype.parseFrame=function(t,r,n){const o={type:"0x10 Pulse configuration"},a={name:"channel A"},i={name:"channel B"};o.productMode=e.PlateformCommonUtils.getProductModeText(t[2]);const c=this.inferNetwork(t.byteLength);let u=0;return 2===t[8]?"sigfox"===c?(o.transmissionPeriod={unit:"s",value:20*t[3]},u=-1):o.transmissionPeriod={unit:"s",value:20*t.readUInt16BE(3)}:"sigfox"===c?(o.transmissionPeriod={unit:"m",value:10*t[3]},u=-1):o.transmissionPeriod={unit:"m",value:t.readUInt16BE(3)},2===t[2]?o.flowCalculationPeriod={unit:"s",value:20*t.readUInt16BE(u+8)}:o.flowCalculationPeriod={unit:"m",value:t.readUInt16BE(u+8)},o.historicMode=this.getHistoricModeText(t[u+6]),a.state=this.getStateText(Boolean(1&t[u+5])),a.type=this.getTypeText(Boolean(2&t[u+5])),a.tamperActivated=Boolean(8&t[u+5]),a.debouncingPeriod={unit:"ms",value:this.getDebouncingPeriod(15&t[u+7])},"lora868"===c&&(a.leakageDetection={overflowAlarmTriggerThreshold:t.readUInt16BE(10),threshold:t.readUInt16BE(14),dailyPeriodsBelowWhichLeakageAlarmTriggered:t.readUInt16BE(18)}),i.state=this.getStateText(Boolean(16&t[u+5])),i.type=this.getTypeText(Boolean(32&t[u+5])),i.tamperActivated=Boolean(128&t[u+5]),i.debouncingPeriod={unit:"ms",value:this.getDebouncingPeriod((240&t[u+7])>>4)},"lora868"===c&&(i.leakageDetection={overflowAlarmTriggerThreshold:t.readUInt16BE(12),threshold:t.readUInt16BE(16),dailyPeriodsBelowWhichLeakageAlarmTriggered:t.readUInt16BE(20)}),o.channels=[a,i],o},t.prototype.inferNetwork=function(e){switch(e){case 22:return"lora868";case 9:return"sigfox";default:return"unknown"}},t.prototype.getStateText=function(e){return e?"enabled":"disabled"},t.prototype.getTypeText=function(e){return e?"gasPullUpOn":"otherPullUpOff"},t.prototype.getHistoricModeText=function(e){switch(e){case 0:return"noHistoric";case 1:return"historicLogEvery10min";case 2:return"historicLogEvery1h";default:return""}},t.prototype.getDebouncingPeriod=function(e){switch(e){case 0:return 0;case 1:return 1;case 2:return 10;case 3:return 20;case 4:return 50;case 5:return 100;case 6:return 200;case 7:return 500;case 8:return 1e3;case 9:return 2e3;case 10:return 5e3;case 11:return 1e4;default:return 0}},t}();e.Pulse0x10Parser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="temp",this.frameCode=17}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x11 Temperature configuration"};return n.threshold={name:"probe 1",unit:"°C",high:{value:e.readInt16BE(2)/10,hysteresis:e[4]/10},low:{value:e.readInt16BE(5)/10,hysteresis:e[7]/10}},n.superSamplingFactor=e[8],n},e}();e.Temp0x11Parser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="temp",this.frameCode=18}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x12 Temperature configuration"};return n.threshold={name:"probe 2",unit:"°C",high:{value:e.readInt16BE(2)/10,hysteresis:e[4]/10},low:{value:e.readInt16BE(5)/10,hysteresis:e[7]/10}},n},e}();e.Temp0x12Parser=t}(codec||(codec={})),function(e){const t=function(){function t(){this.deviceType="temp",this.frameCode=48,this.temp0x43Parser=new e.Temp0x43Parser}return t.prototype.parseFrame=function(e,t,r){const n=this.temp0x43Parser.parseFrame(e,t,r);return n.type="0x30 Temperature keep alive",n},t}();e.Temp0x30Parser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="temp",this.frameCode=67}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x43 Temperature data"},o={name:"probe 1"},a={name:"probe 2"};return o.id=(240&e[2])>>4,o.unit="°C",o.value=e.readInt16BE(3)/10,a.id=(240&e[5])>>4,a.unit="°C",a.value=e.readInt16BE(6)/10,2!=(15&e[5])&&(o.state=1&e[2]?"activated":"deactivated",a.state=1&e[5]?"activated":"deactivated"),n.temperatures=[o,a],n},e}();e.Temp0x43Parser=t}(codec||(codec={})),function(e){const t=function(){function t(){this.deviceType="temp",this.frameCode=0}return t.prototype.parseFrame=function(t,r,n){let o={};return(o=(new e.GenericStatusByteParser).parseFrame(t,r)).probe1Alarm=Boolean(8&t[1]),o.probe2Alarm=Boolean(16&t[1]),{status:o}},t}();e.TempStatusByteParser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="temp3",this.frameCode=16}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x10 Temp 3 configuration"};return n.transmissionPeriodKeepAlive={unit:"s",value:10*e.readUInt16BE(2)},n.numberOfHistorizationBeforeSending=e.readUInt16BE(4),n.numberOfSamplingBeforeHistorization=e.readUInt16BE(6),n.samplingPeriod={unit:"s",value:2*e.readUInt16BE(8)},n.redundantSamples=e.readUInt8(10),n.calculatedPeriodRecording={unit:"s",value:e.readUInt16BE(8)*e.readUInt16BE(6)*2},n.calculatedSendingPeriod={unit:"s",value:e.readUInt16BE(8)*e.readUInt16BE(6)*e.readUInt16BE(4)*2},n},e}();e.TempV30x10Parser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="temp3",this.frameCode=48}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x30 Temp 3 keep alive"},o=16&e[1]?2:1,a=[];return a.push({name:"temperature 1",unit:"°C",value:e.readInt16BE(2)/10}),2===o&&a.push({name:"temperature 2",unit:"°C",value:e.readInt16BE(4)/10}),n.temperatures=a,n},e}();e.TempV30x30Parser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="temp3",this.frameCode=87}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x57 Temp 3 periodic data"},o=16&e[1]?2:1;let a;const i=[],c=[],u=[];for(let t=2;te.replace(/ /g,"_").toLowerCase();function inspectFormat(e,t,r){let n=[];for(const r in e)"object"==typeof e[r]?e[r].frameCounter?n=n.concat(inspectFormat(e[r],t,r)):n.push({variable:fixVariable(r),value:e[r].value,location:e[r].location,group:t,unit:e[r].unit},{variable:`${fixVariable(r)}_currentstate`,value:e[r].currentState,location:e[r].location,group:t,unit:e[r].unit},{variable:`${fixVariable(r)}_previousFrameState`,value:e[r].previousFrameState,location:e[r].location,group:t,unit:e[r].unit}):n.push({variable:fixVariable(r),value:e[r],group:t});return n}function Decoder(e){const t=new codec.Decoder,r=device.params.find(e=>"parse_type"===e.key);return r&&r.value?(t.setDeviceType(r.value),t.decode(e)):(console.error("Type unsupported. Set the configuration parameter parse_type"),{})}const payload_raw=payload.find(e=>"payload_raw"===e.variable||"payload"===e.variable||"data"===e.variable);if(payload_raw)try{const e=String(Date.now()),t=Decoder(payload_raw.value);if(t.channels){for(const e of t.channels)t[e.name]=e;delete t.channels}const r=inspectFormat(t,e);payload=payload.concat(r.map(t=>({...t,group:e})))}catch(e){console.error(e),payload=[{variable:"parse_error",value:e.message}]}
This codec is sourced from TagoIO Github. All rights belong to TagoIO Github.
This codec is licensed under the GNU General Public License v3 (GPL v3). Modifications, if any, are clearly marked. You are free to use, modify, and distribute the codec under the terms of GPL v3.