ADENUIS - Analog And Power

Sensor

Codec Description

Codec for ADENUIS - Analog-And-Power (v1.0.0).

Codec Preview

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 i(e){if(null==e)throw TypeError();return Object(e)}function a(e){return e>>0}function c(e){return e>>>0}const{LN2:s}=Math,{abs:u}=Math,{floor:f}=Math,{log:l}=Math,{max:p}=Math,{min:h}=Math,{pow:y}=Math,{round:d}=Math;function g(e,t){const r=32-t;return e<>r}function b(e,t){const r=32-t;return e<>>r}function E(e){return[255&e]}function v(e){return g(e[0],8)}function m(e){return[255&e]}function T(e){return b(e[0],8)}function P(e){return[(e=d(Number(e)))<0?0:e>255?255:255&e]}function O(e){return[255&e,e>>8&255]}function _(e){return g(e[1]<<8|e[0],16)}function w(e){return[255&e,e>>8&255]}function A(e){return b(e[1]<<8|e[0],16)}function j(e){return[255&e,e>>8&255,e>>16&255,e>>24&255]}function I(e){return g(e[3]<<24|e[2]<<16|e[1]<<8|e[0],32)}function B(e){return[255&e,e>>8&255,e>>16&255,e>>24&255]}function S(e){return b(e[3]<<24|e[2]<<16|e[1]<<8|e[0],32)}function x(e,t,r){const n=(1<.5?t+1:t%2?t+1:t}let i,a,c;if(e!=e)a=(1<=y(2,1-n)){a=h(f(l(e)/s),1023);let i=e/y(2,a);i<1&&(a-=1,i*=2),i>=2&&(a+=1,i/=2);const u=y(2,r);a+=n,(c=o(i*u)-u)/u>=1&&(a+=1,c=0),a>2*n&&(a=(1<>=1;return n.reverse(),c=n.join(""),s=(1<0?u*y(2,f-s)*(1+l/y(2,r)):0!==l?u*y(2,-(s-1))*(l/y(2,r)):u<0?-0:0}function U(e){return C(e,11,52)}function N(e){return x(e,11,52)}function R(e){return C(e,8,23)}function D(e){return x(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 s(e){if((e=a(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 l)return function(e){if(this.constructor!==e.constructor)throw TypeError();const t=e.length*this.BYTES_PER_ELEMENT;Object.defineProperty(this,"buffer",{value:new s(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 l)&&!(arguments[0]instanceof s||"ArrayBuffer"===n(arguments[0])))return function(e){const t=e.length*this.BYTES_PER_ELEMENT;Object.defineProperty(this,"buffer",{value:new s(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 s||"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||s,Object.defineProperty(l,"from",{value(e){return new this(e)}}),Object.defineProperty(l,"of",{value(){return new this(arguments)}});const y={};function d(r,n,o){var i=function(){Object.defineProperty(this,"constructor",{value:i}),l.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(u,n._getter(l)),l+=g,u+=g,b-=1;return n}}),Object.defineProperty(l.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 a=0;for(;a1?arguments[1]:void 0;let a=0;for(;a0&&((n=Number(arguments[1]))!=n?n=0:0!==n&&n!==1/0&&n!==-1/0&&(n=(n>0||-1)*f(u(n)))),n>=r)return-1;let o=n>=0?n:p(r-u(n),0);for(;o1&&((n=Number(arguments[1]))!=n?n=0:0!==n&&n!==1/0&&n!==-1/0&&(n=(n>0||-1)*f(u(n))));let o=n>=0?h(n,r-1):r-u(n);for(;o>=0;o--)if(t._getter(o)===e)return o;return-1}}),Object.defineProperty(l.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 i=arguments[1];for(let o=0;o=2?arguments[1]:t._getter(i++);i=2?arguments[1]:t._getter(i--);i>=0;)n=e.call(void 0,n,t._getter(i),i,t),i--;return n}}),Object.defineProperty(l.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,l=r.length*this.BYTES_PER_ELEMENT,r.buffer===this.buffer){for(p=[],a=0,s=r.byteOffset;athis.length)throw RangeError("Offset plus length of array is out of range");for(a=0;ar?1:0}),o=0;or?r:e}e=a(e),t=a(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 g=d(1,E,v),b=d(1,m,T),x=d(1,P,T),C=d(2,O,_),L=d(2,w,A),M=d(4,j,I),F=d(4,B,S),Y=d(4,D,R),V=d(8,N,U);e.Int8Array=e.Int8Array||g,e.Uint8Array=e.Uint8Array||b,e.Uint8ClampedArray=e.Uint8ClampedArray||x,e.Int16Array=e.Int16Array||C,e.Uint16Array=e.Uint16Array||L,e.Int32Array=e.Int32Array||M,e.Uint32Array=e.Uint32Array||F,e.Float32Array=e.Float32Array||Y,e.Float64Array=e.Float64Array||V}(),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 i(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 a(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 i=new Uint8Array(this.buffer,n,e.BYTES_PER_ELEMENT),a=[];for(let r=0;rthis.byteLength)throw RangeError("Array index out of range");const a=new e([o]),s=new Uint8Array(a.buffer),u=[];let f,l;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 t(){this.deviceType="analog",this.frameCode=16}return t.prototype.parseFrame=function(t,r,n){const o={type:"0x10 Analog configuration"},i={name:"channel A"},a={name:"channel B"};2===t[8]?(o.transmissionPeriodKeepAlive={unit:"s",value:20*t[2]},o.transmissionPeriodData={unit:"s",value:20*t[3]}):(o.transmissionPeriodKeepAlive={unit:"m",value:10*t[2]},o.transmissionPeriodData={unit:"m",value:10*t[3]});let c=this.getDebounceText(t[5]>>4);return i.id=(240&t[4])>>4,i.type=this.getSensorTypeText(15&t[4]),15&t[4]&&(i.threshold=this.getThresholdTriggeringText(3&t[5]),i.externalTrigger={type:this.getThresholdTriggeringText(t[5]>>2&3),debounceDuration:{unit:c[1],value:c[0]}}),c=this.getDebounceText(t[7]>>4),a.id=(240&t[6])>>4,a.type=this.getSensorTypeText(15&t[6]),15&t[6]&&(a.threshold=this.getThresholdTriggeringText(3&t[7]),a.externalTrigger={type:this.getThresholdTriggeringText(t[7]>>2&3),debounceDuration:{unit:c[1],value:c[0]}}),o.channels=[i,a],o.productMode=e.PlateformCommonUtils.getProductModeText(t[8]),o},t.prototype.getSensorTypeText=function(e){switch(e){case 0:return"deactivated";case 1:return"0-10V";case 2:return"4-20mA";default:return""}},t.prototype.getThresholdTriggeringText=function(e){switch(e){case 0:return"none";case 1:return"low";case 2:return"high";case 3:return"both";default:return""}},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"];default:return[0,"s"]}},t}();e.Analog0x10Parser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="analog",this.frameCode=17}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x11 Analog configuration"};return n.threshold={name:"channel A",unit:"µV or 10 nA",high:{value:16777215&e.readUInt32BE(1),hysteresis:16777215&e.readUInt32BE(4)}},n},e}();e.Analog0x11Parser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="analog",this.frameCode=18}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x12 Analog configuration"};return n.threshold={name:"channel A",unit:"µV or 10 nA",low:{value:16777215&e.readUInt32BE(1),hysteresis:16777215&e.readUInt32BE(4)}},n},e}();e.Analog0x12Parser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="analog",this.frameCode=19}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x13 Analog configuration"};return n.threshold={name:"channel B",unit:"µV or 10 nA",high:{value:16777215&e.readUInt32BE(1),hysteresis:16777215&e.readUInt32BE(4)}},n},e}();e.Analog0x13Parser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="analog",this.frameCode=20}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x14 Analog configuration"};return n.threshold={name:"channel B",unit:"µV or 10 nA",low:{value:16777215&e.readUInt32BE(1),hysteresis:16777215&e.readUInt32BE(4)}},n},e}();e.Analog0x14Parser=t}(codec||(codec={})),function(e){const t=function(){function t(){this.deviceType="analog",this.frameCode=48,this.parser=new e.Analog0x42Parser}return t.prototype.parseFrame=function(e,t,r){const n=this.parser.parseFrame(e,t,r);return n.type="0x30 Analog keep alive",n},t}();e.Analog0x30Parser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="analog",this.frameCode=66}return e.prototype.parseFrame=function(e,t,r){const n={type:"0x42 Analog data"},o={name:"channel A"},i={name:"channel B"};let a=15&e[2],c=16777215&e.readUInt32BE(2);return 1===a?(o.unit="V",o.value=parseFloat((c/1e6).toFixed(3))):2===a?(o.unit="mA",o.value=parseFloat((c/1e5).toFixed(3))):o.state="deactivated",a=15&e[6],c=16777215&e.readUInt32BE(6),1===a?(i.unit="V",i.value=parseFloat((c/1e6).toFixed(3))):2===a?(i.unit="mA",i.value=parseFloat((c/1e5).toFixed(3))):i.state="deactivated",n.channels=[o,i],n},e}();e.Analog0x42Parser=t}(codec||(codec={})),function(e){const t=function(){function t(){this.deviceType="analog",this.frameCode=0}return t.prototype.parseFrame=function(t,r,n){let o={};return(o=(new e.GenericStatusByteParser).parseFrame(t,r)).alarmChannelA=Boolean(8&t[1]),o.alarmChannelB=Boolean(16&t[1]),{status:o}},t}();e.AnalogStatusByteParser=t}(codec||(codec={})),function(e){const t=function(){function e(){this.deviceType="any",this.frameCode=0}return e.prototype.parseFrame=function(e,t){const r={};return r.frameCounter=(224&e[1])>>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){let t;!function(e){e[e.NONE=0]="NONE",e[e.MISSING_NETWORK=1]="MISSING_NETWORK",e[e.MISSING_CONFIGURATION=2]="MISSING_CONFIGURATION"}(t=e.PartialDecodingReason||(e.PartialDecodingReason={}))}(codec||(codec={})),function(e){const t=function(){function t(t){void 0===t&&(t="Unknown"),this.type=t,this.partialDecoding=e.PartialDecodingReason.NONE}return t.merge=function(){const e=[];for(let t=0;te.replace(/ /g,"_").toLowerCase();function inspectFormat(e,t,r){let n=[];for(const r in e)if(r!=="lng".toLowerCase()&&"longitude"!==r.toLowerCase())if(r==="lat".toLowerCase()||"latitude"===r.toLowerCase()){const o=e.lng||e.longitude||e.Longitude;n.push({variable:"location",value:`${e[r]}, ${o}`,location:{lat:Number(e[r]),lng:Number(o)},group:t})}else"object"==typeof e[r]?e[r].value?n.push({variable:fixVariable(r),value:e[r].value,location:e[r].location,group:t,unit:e[r].unit}):n=n.concat(inspectFormat(e[r],t,r)):n.push({variable:fixVariable(r),value:e[r],group:t});return n}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.

Community Feedback