UNPKG

@w2a-iiot/raw-javascript-parsers

Version:

This packages contain the raw built javascript parsers for WIKA's IIoT devices.

1 lines 64.5 kB
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n)),l=o(((exports,t)=>{function n(e){"@babel/helpers - typeof";return t.exports=n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},t.exports.__esModule=!0,t.exports.default=t.exports,n(e)}t.exports=n,t.exports.__esModule=!0,t.exports.default=t.exports})),u=o(((exports,t)=>{var n=l().default;function r(e,t){if(n(e)!=`object`||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var i=r.call(e,t||`default`);if(n(i)!=`object`)return i;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}t.exports=r,t.exports.__esModule=!0,t.exports.default=t.exports})),d=o(((exports,t)=>{var n=l().default,r=u();function i(e){var t=r(e,`string`);return n(t)==`symbol`?t:t+``}t.exports=i,t.exports.__esModule=!0,t.exports.default=t.exports})),f=o(((exports,t)=>{var n=d();function r(e,t,r){return(t=n(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}t.exports=r,t.exports.__esModule=!0,t.exports.default=t.exports})),p=o(((exports,t)=>{var n=f();function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function i(e){for(var t=1;t<arguments.length;t++){var i=arguments[t]==null?{}:arguments[t];t%2?r(Object(i),!0).forEach(function(t){n(e,t,i[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):r(Object(i)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))})}return e}t.exports=i,t.exports.__esModule=!0,t.exports.default=t.exports})),m=o(((exports,t)=>{function n(e,t,n,r,i,a,o){try{var s=e[a](o),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,i)}function r(e){return function(){var t=this,r=arguments;return new Promise(function(i,a){var o=e.apply(t,r);function s(e){n(o,i,a,s,c,`next`,e)}function c(e){n(o,i,a,s,c,`throw`,e)}s(void 0)})}}t.exports=r,t.exports.__esModule=!0,t.exports.default=t.exports})),h=c(p(),1);m();var g;function _(e){var t,n,r;return{lang:(t=e==null?void 0:e.lang)==null?g==null?void 0:g.lang:t,message:e==null?void 0:e.message,abortEarly:(n=e==null?void 0:e.abortEarly)==null?g==null?void 0:g.abortEarly:n,abortPipeEarly:(r=e==null?void 0:e.abortPipeEarly)==null?g==null?void 0:g.abortPipeEarly:r}}var v;function y(e){return v==null?void 0:v.get(e)}var b;function x(e){return b==null?void 0:b.get(e)}var S;function C(e,t){var n;return S==null||(n=S.get(e))==null?void 0:n.get(t)}function w(e){let t=typeof e;if(t===`string`)return`"${e}"`;if(t===`number`||t===`bigint`||t===`boolean`)return`${e}`;if(t===`object`||t===`function`){var n,r;return(n=e&&((r=Object.getPrototypeOf(e))==null||(r=r.constructor)==null?void 0:r.name))==null?`null`:n}return t}function T(e,t,n,r,i){var a,o,s,c,l,u,d,f;let p=i&&`input`in i?i.input:n.value,m=(a=(o=i==null?void 0:i.expected)==null?e.expects:o)==null?null:a,h=(s=i==null?void 0:i.received)==null?w(p):s,g={kind:e.kind,type:e.type,input:p,expected:m,received:h,message:`Invalid ${t}: ${m?`Expected ${m} but r`:`R`}eceived ${h}`,requirement:e.requirement,path:i==null?void 0:i.path,issues:i==null?void 0:i.issues,lang:r.lang,abortEarly:r.abortEarly,abortPipeEarly:r.abortPipeEarly},_=e.kind===`schema`,v=(c=(l=(u=(d=(f=i==null?void 0:i.message)==null?e.message:f)==null?C(e.reference,g.lang):d)==null?_?x(g.lang):null:u)==null?r.message:l)==null?y(g.lang):c;v!==void 0&&(g.message=typeof v==`function`?v(g):v),_&&(n.typed=!1),n.issues?n.issues.push(g):n.issues=[g]}function E(e){return{version:1,vendor:`valibot`,validate(t){return e[`~run`]({value:t},_())}}}function ee(e,t){var n;let r=[...new Set(e)];return r.length>1?`(${r.join(` ${t} `)})`:(n=r[0])==null?`never`:n}var te=/^(?:0[hx])?[\da-fA-F]+$/u;function ne(e){return{kind:`validation`,type:`hexadecimal`,reference:ne,async:!1,expects:null,requirement:te,message:e,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&T(this,`hexadecimal`,e,t),e}}}function D(e){return{kind:`validation`,type:`integer`,reference:D,async:!1,expects:null,requirement:Number.isInteger,message:e,"~run"(e,t){return e.typed&&!this.requirement(e.value)&&T(this,`integer`,e,t),e}}}function O(e,t){return{kind:`validation`,type:`max_value`,reference:O,async:!1,expects:`<=${e instanceof Date?e.toJSON():w(e)}`,requirement:e,message:t,"~run"(e,t){return e.typed&&!(e.value<=this.requirement)&&T(this,`value`,e,t,{received:e.value instanceof Date?e.value.toJSON():w(e.value)}),e}}}function k(e,t){return{kind:`validation`,type:`min_value`,reference:k,async:!1,expects:`>=${e instanceof Date?e.toJSON():w(e)}`,requirement:e,message:t,"~run"(e,t){return e.typed&&!(e.value>=this.requirement)&&T(this,`value`,e,t,{received:e.value instanceof Date?e.value.toJSON():w(e.value)}),e}}}function re(e){return{kind:`transformation`,type:`transform`,reference:re,async:!1,operation:e,"~run"(e){return e.value=this.operation(e.value),e}}}function ie(e,t,n){return typeof e.fallback==`function`?e.fallback(t,n):e.fallback}function ae(e,t,n){return typeof e.default==`function`?e.default(t,n):e.default}function oe(e,t){return{kind:`schema`,type:`array`,reference:oe,expects:`Array`,async:!1,item:e,message:t,get"~standard"(){return E(this)},"~run"(e,t){let n=e.value;if(Array.isArray(n)){e.typed=!0,e.value=[];for(let i=0;i<n.length;i++){let a=n[i],o=this.item[`~run`]({value:a},t);if(o.issues){let s={type:`array`,origin:`value`,input:n,key:i,value:a};for(let t of o.issues){var r;t.path?t.path.unshift(s):t.path=[s],(r=e.issues)==null||r.push(t)}if(e.issues||(e.issues=o.issues),t.abortEarly){e.typed=!1;break}}o.typed||(e.typed=!1),e.value.push(o.value)}}else T(this,`type`,e,t);return e}}}function A(e){return{kind:`schema`,type:`number`,reference:A,expects:`number`,async:!1,message:e,get"~standard"(){return E(this)},"~run"(e,t){return typeof e.value==`number`&&!isNaN(e.value)?e.typed=!0:T(this,`type`,e,t),e}}}function j(e,t){return{kind:`schema`,type:`object`,reference:j,expects:`Object`,async:!1,entries:e,message:t,get"~standard"(){return E(this)},"~run"(e,t){let n=e.value;if(n&&typeof n==`object`)for(let i in e.typed=!0,e.value={},this.entries){let a=this.entries[i];if(i in n||(a.type===`exact_optional`||a.type===`optional`||a.type===`nullish`)&&a.default!==void 0){let o=i in n?n[i]:ae(a),s=a[`~run`]({value:o},t);if(s.issues){let a={type:`object`,origin:`value`,input:n,key:i,value:o};for(let t of s.issues){var r;t.path?t.path.unshift(a):t.path=[a],(r=e.issues)==null||r.push(t)}if(e.issues||(e.issues=s.issues),t.abortEarly){e.typed=!1;break}}s.typed||(e.typed=!1),e.value[i]=s.value}else if(a.fallback!==void 0)e.value[i]=ie(a);else if(a.type!==`exact_optional`&&a.type!==`optional`&&a.type!==`nullish`&&(T(this,`key`,e,t,{input:void 0,expected:`"${i}"`,path:[{type:`object`,origin:`key`,input:n,key:i,value:n[i]}]}),t.abortEarly))break}else T(this,`type`,e,t);return e}}}function M(e,t){return{kind:`schema`,type:`optional`,reference:M,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,get"~standard"(){return E(this)},"~run"(e,t){return e.value===void 0&&(this.default!==void 0&&(e.value=ae(this,e,t)),e.value===void 0)?(e.typed=!0,e):this.wrapped[`~run`](e,t)}}}function N(e){return{kind:`schema`,type:`string`,reference:N,expects:`string`,async:!1,message:e,get"~standard"(){return E(this)},"~run"(e,t){return typeof e.value==`string`?e.typed=!0:T(this,`type`,e,t),e}}}function se(e){let t;if(e)for(let n of e)t?t.push(...n.issues):t=n.issues;return t}function ce(e,t){return{kind:`schema`,type:`union`,reference:ce,expects:ee(e.map(e=>e.expects),`|`),async:!1,options:e,message:t,get"~standard"(){return E(this)},"~run"(e,t){let n,r,i;for(let a of this.options){let o=a[`~run`]({value:e.value},t);if(o.typed)if(o.issues)r?r.push(o):r=[o];else{n=o;break}else i?i.push(o):i=[o]}if(n)return n;if(r){if(r.length===1)return r[0];T(this,`type`,e,t,{issues:se(r)}),e.typed=!0}else if((i==null?void 0:i.length)===1)return i[0];else T(this,`type`,e,t,{issues:se(i)});return e}}}function P(...e){return(0,h.default)((0,h.default)({},e[0]),{},{pipe:e,get"~standard"(){return E(this)},"~run"(t,n){for(let r of e)if(r.kind!==`metadata`){if(t.issues&&(r.kind===`schema`||r.kind===`transformation`)){t.typed=!1;break}(!t.issues||!n.abortEarly&&!n.abortPipeEarly)&&(t=r[`~run`](t,n))}return t}})}function le(e,t,n){let r=e[`~run`]({value:t},_(n));return{typed:r.typed,success:!r.issues,output:r.value,issues:r.issues}}function ue(e,t){let n=new Set;e.forEach(e=>{if(e.start>=e.end)throw t?Error(`Invalid channel range in codec ${t}: ${e.start} >= ${e.end} in channel ${e.name}`):Error(`Invalid channel range: ${e.start} >= ${e.end} in channel ${e.name}`);if(n.has(e.name))throw t?Error(`Duplicate channel name found in codec ${t}: ${e.name}`):Error(`Duplicate channel name found: ${e.name}`);n.add(e.name)})}function de(e){if(e.length===0)throw Error(`At least one codec must be provided`);e.forEach(e=>{let t=e.getChannels();ue(t,e.name)}),e.forEach((t,n)=>{let r=e.filter((e,t)=>t!==n);if(r.find(e=>e.name===t.name))throw Error(`Codec names must be unique. Duplicate found: ${t.name}`)});let t=e[0].getChannels().map(e=>e.name);e.forEach((e,n)=>{if(n===0)return;let r=e.getChannels().map(e=>e.name),i={missing:[],extra:[]};if(r.forEach(e=>{t.includes(e)||i.extra.push(e)}),t.forEach(e=>{r.includes(e)||i.missing.push(e)}),i.extra.length>0)throw Error(`Codec ${e.name} has extra channels not present in other codecs: ${i.extra.join(`, `)}`);if(i.missing.length>0)throw Error(`Codec ${e.name} is missing channels present in other codecs: ${i.missing.join(`, `)}`)});let n=new Map;e.forEach(e=>{e.getChannels().forEach(e=>{let t=[e.start,e.end];if(n.has(e.name)){let r=n.get(e.name);if(r[0]!==t[0]||r[1]!==t[1])throw Error(`Channel ${e.name} has inconsistent ranges across codecs: ${JSON.stringify(r)} vs ${JSON.stringify(t)}`)}else n.set(e.name,t)})})}function fe(){return P(A(),k(1),O(255),D())}function pe(){return M(N())}function me(){return j({bytes:oe(P(A(),k(0),O(255),D())),fPort:M(P(A(),k(1),O(224),D())),recvTime:M(N())},"Uplink input should be an object with `bytes` and optional `fPort` and `recvTime` properties.")}function he(){return P(ce([j({bytes:P(N()),fPort:M(fe()),recvTime:pe()}),N()]),re(e=>typeof e==`string`?{bytes:e}:e))}function ge(e,t={}){let{threshold:n=4,maxDecimals:r=10}=t;if(Number.isNaN(e))return`NaN`;if(!isFinite(e)||Number.isInteger(e))return e.toString();let i=e.toFixed(r),a=-1,o=``,s=i.indexOf(`.`),c=s>=0?s+1:i.length;for(let e=c;e<i.length;e++){let t=i[e];if(t===`0`||t===`9`){let r=1,s=e+1;for(;s<i.length&&i[s]===t;)r++,s++;if(r>=n){a=e,o=t;break}e=s-1}}if(a!==-1){let e=i.substring(0,a);if(o===`9`){let t=e,n=Number.parseFloat(t),r=t.indexOf(`.`),i=r>=0?t.length-r-1:0,a=Math.pow(10,-i),o=n<0?n-a:n+a;e=i>0?o.toFixed(i):o.toString()}let t=e.replace(/\.?0+$/,``);return t.endsWith(`.`)&&(t=t.slice(0,-1)),(t===`-0.`||t===`0.`||t===`-0`||t===`0`)&&(t=`0`),t}let l=i.replace(/\.?0+$/,``);return l.endsWith(`.`)&&(l=l.slice(0,-1)),(l===`-0.`||l===`0.`||l===`-0`||l===`0`)&&(l=`0`),l}function F(e,t){let n=t==null?4:t;return e===void 0||Number.isNaN(e)||e===-1/0?n:e===1/0?1/0:Math.floor(e)>=0?Math.floor(e):n}function _e(e){let t=e.replaceAll(` `,``);t=t.startsWith(`0x`)?t.slice(2):t;let n=P(N(),ne()),r=le(n,t);if(!r.success)return null;let i=[];for(let e=0;e<r.output.length;e+=2){let t=Number.parseInt(r.output.slice(e,e+2),16);i.push(t)}return i}function ve(e,t){if(t.start>=t.end)throw RangeError(`Range start must be less than range end`);return(t.end-t.start)*(e/100)+t.start}function I(e,t){let n=(e-2500)*100/1e4+0;return ve(n,t)}function ye(e,t){if(e<0||e>1e4)throw RangeError(`Slope value must be between 0 and 10_000, is ${e}`);let n=e/100;return ve(n,t)}function L(e,t){if(t=typeof t==`number`?Math.min(Math.max(0,Math.floor(t)),100):void 0,Number.isInteger(e))return e;let n=ge(e+5*Number.EPSILON,{maxDecimals:t});return n===``?0:Number.parseFloat(n)}function be(e){let t=new ArrayBuffer(4),n=new DataView(t);return n.setUint8(0,e[0]&255),n.setUint8(1,e[1]&255),n.setUint8(2,e[2]&255),n.setUint8(3,e[3]&255),n.getFloat32(0)}function R(e,t=3){t=Math.max(0,Math.floor(t));let n=be(e);return Number.parseFloat(ge(n,{threshold:t}))}function xe(e){let{codecs:t,throwOnMultipleDecode:n=!0,parserName:r}=e,i=F(e.roundingDecimals);de(e.codecs);function a(e){return{errors:[`${r} (JS): ${e}`]}}function o(e){let r;if(t.forEach(t=>{let i=t.canTryDecode(e);if(i){if(!r)r=t;else if(n)throw Error(`Message could not be uniquely decoded. Multiple codecs matched the input.`)}}),!r)throw Error(`Message could not be decoded. No codec matched the input.`);return r.decode(e)}function s(e){try{let t=le(me(),e);if(!t.success)throw Error(`Input is not a valid for decoding. Check your input data.`);return o(t.output)}catch(t){return t instanceof Error?a(t.message):a(`Unknown error occurred during decoding in parser ${r} with input ${JSON.stringify(e)}`)}}function c(e){let t=le(he(),e);if(!t.success)return a(`Input is not a valid for decoding. Check your input data.`);let n=_e(t.output.bytes);return n?s({bytes:n,fPort:t.output.fPort,recvTime:t.output.recvTime}):a(`Input bytes is not a valid hexadecimal string.`)}function l(e){let n=t.find(t=>t.name===e.codec);if(!n)throw Error(`Codec ${e.codec} not found in parser. Input could not be encoded.`);if(!n.encode)throw Error(`Codec ${e.codec} does not support encoding. Input could not be encoded.`);return n.encode(e.input)}return{decodeUplink:s,decodeHexUplink:c,encodeDownlink:l,adjustMeasuringRange:(e,n)=>{t.forEach(t=>{t.adjustMeasuringRange(e,n)})},adjustRoundingDecimals:e=>{let n=F(e,i);t.forEach(e=>{e.adjustRoundingDecimals(n)})}}}function Se(e){let t=`${e.deviceName}TULIP2`,n=F(e.roundingDecimals);ue(e.channels),e.channels.forEach((e,n,r)=>{let i=r.find((t,r)=>t.channelId===e.channelId&&r!==n);if(i)throw Error(`Duplicate channel ID found: ${e.channelId} for channels ${e.name} and ${i.name} in ${t} Codec`)});function r(t){let n=t.bytes[0];return typeof n==`number`&&n in e.handlers}function i(r){let i=r.bytes[0];if(typeof i!=`number`)throw TypeError(`Input must have at least one byte for ${t} Codec`);let a=e.handlers[i];if(a)return a(r,{roundingDecimals:n,channels:e.channels});throw TypeError(`No handler registered for byte ${i} in ${t} Codec`)}return{name:t,encode:e.encodeHandler,getChannels:()=>e.channels.map(e=>({end:e.end,name:e.name,start:e.start})),canTryDecode:r,decode:i,adjustMeasuringRange:(t,n)=>{let r=e.channels.find(e=>e.name===t);if(!r)throw Error(`Channel ${t} not found in ${e.deviceName}TULIP2 Codec`);r.start=n.start,r.end=n.end},adjustRoundingDecimals:e=>{n=F(e,n)}}}const Ce={"low threshold":0,"high threshold":1,"falling slope":2,"rising slope":3,"low threshold with delay":4,"high threshold with delay":5},we={"ALU saturation error":1,"sensor memory integrity error":2,"sensor busy error":4,reserved:8,"sensor communication error":16,"pressure out of limit":32,"temperature out of limit":64},Te={"battery low":0,"acknowledged message not emitted":4},z={triggered:0,disappeared:1},Ee={generic:0,"device dependent":1},De={absolute:1,"gauge / relative":2},Oe={bar:7,MPa:237,psi:6};function ke(){return[{channelId:0,name:`pressure`,start:0,end:10},{channelId:1,name:`device temperature`,start:-45,end:110}]}const Ae=(e,t)=>{if(e.bytes.length!==7)throw Error(`Data message 01/02 needs 7 bytes but got ${e.bytes.length}`);let n=e.bytes[0],r=e.bytes[1],i=L(I(e.bytes[3]<<8|e.bytes[4],t.channels[0]),t.roundingDecimals),a=L(I(e.bytes[5]<<8|e.bytes[6],t.channels[1]),t.roundingDecimals),o=e.bytes[2]/10;return{data:{configurationId:r,messageType:n,measurement:{channels:[{channelId:0,channelName:`pressure`,value:i},{channelId:1,channelName:`device temperature`,value:a},{channelId:2,channelName:`battery voltage`,value:o}]}}}},je=(e,t)=>{if(e.bytes.length<5||(e.bytes.length-2)%3!=0)throw Error(`Process alarm 03 needs at least 5 bytes and got ${e.bytes.length}. Also all bytes for each alarm needed`);let n=e.bytes[1],r=[];for(let n=2;n<e.bytes.length;n+=3){let i=(e.bytes[n]&120)>>3,a=t.channels.find(e=>e.channelId===i);if(!a)throw TypeError(`Unknown channel ID: ${i} in process alarm message`);let o=e.bytes[n]&7,s=(e.bytes[n]&128)>>7,c=o===2||o===3?ye(e.bytes[n+1]<<8|e.bytes[n+2],a):I(e.bytes[n+1]<<8|e.bytes[n+2],a);r.push({channelId:i,channelName:a.name,value:L(c,t.roundingDecimals),event:s,alarmType:o,alarmTypeName:Object.keys(Ce).find(e=>Ce[e]===o),eventName:Object.keys(z).find(e=>z[e]===s)})}let i=[],a={data:{messageType:3,configurationId:n,processAlarms:r}};for(let e of r)e.value===65535&&i.push(`Invalid data for ${e.channelName}channel`);return i.length>0&&(a.warnings=i),a},Me=e=>{if(e.bytes.length!==3)throw Error(`Technical alarm 04 needs 3 bytes but got ${e.bytes.length}.`);let t=e.bytes[1],n=e.bytes[2],r=(n&128)>>7,i=n&127,a=[];Object.entries(we).forEach(([e,t])=>{(i&t)!==0&&a.push(e)});let o=Object.keys(z).find(e=>z[e]===r),s={data:{messageType:4,configurationId:t,technicalAlarms:[{event:r,eventName:o,alarmType:i,alarmTypeNames:a}]}};return s},Ne=e=>{if(e.bytes.length<3||e.bytes.length>4)throw Error(`Device alarm 05 needs 3 or 4 bytes but got ${e.bytes.length}.`);let t=e.bytes[1],n=e.bytes[2],r=(n&128)>>7,i=Object.keys(z).find(e=>z[e]===r),a=(n&96)>>6,o=Object.keys(Ee).find(e=>Ee[e]===a),s=n&31,c=Object.keys(Te).find(e=>Te[e]===s),l;s===0&&e.bytes.length===4&&(l=e.bytes[3]/10);let u={event:r,eventName:i,alarmType:s,alarmTypeName:c,causeOfFailure:a,causeOfFailureName:o};s===0&&(u.value=l);let d={data:{messageType:5,configurationId:t,deviceAlarm:u}};return d},Pe=e=>{if(e.bytes.length!==8&&e.bytes.length!==38)throw Error(`Identification message 07 needs 8 or 38 bytes but got ${e.bytes.length}`);let t=e.bytes[1],n=e.bytes[2];if(n!==11)throw Error(`Identification message 07 needs productId 11 but got ${n}`);let r=e.bytes[3];if(r!==0)throw Error(`Identification message 07 needs productSubId 0 but got ${r}`);let i=`${e.bytes[4]>>4&15}.${e.bytes[4]&15}.${e.bytes[5]}`,a=`${e.bytes[6]>>4&15}.${e.bytes[6]&15}.${e.bytes[7]}`;if(e.bytes.length===8)return{data:{messageType:7,configurationId:t,deviceInformation:{productId:n,productIdName:`PEW`,productSubId:r,productSubIdName:`LoRaWAN`,wirelessModuleFirmwareVersion:i,wirelessModuleHardwareVersion:a}}};let o=String.fromCharCode(...e.bytes.slice(8,19)),s=e.bytes[19];if(s!==1&&s!==2)throw Error(`Identification message 07 needs pressureTypeId 1 or 2 but got ${s}`);let c=Object.keys(De).find(e=>De[e]===s),l=L(R([e.bytes[20],e.bytes[21],e.bytes[22],e.bytes[23]])),u=L(R([e.bytes[24],e.bytes[25],e.bytes[26],e.bytes[27]])),d=L(R([e.bytes[28],e.bytes[29],e.bytes[30],e.bytes[31]])),f=L(R([e.bytes[32],e.bytes[33],e.bytes[34],e.bytes[35]])),p=e.bytes[36];if(![6,7,237].includes(p))throw Error(`Identification message 07 needs pressureUnit 6, 7, or 237 but got ${p}`);let m=Object.keys(Oe).find(e=>Oe[e]===p),h=e.bytes[37];if(h!==32)throw Error(`Identification message 07 needs deviceTemperatureUnit 32 but got ${h}`);return{data:{messageType:7,configurationId:t,deviceInformation:{productIdName:`PEW`,productId:n,productSubId:r,productSubIdName:`LoRaWAN`,wirelessModuleFirmwareVersion:i,wirelessModuleHardwareVersion:a,serialNumber:o,pressureType:c,measurementRangeStartPressure:l,measurementRangeEndPressure:u,measurementRangeStartDeviceTemperature:d,measurementRangeEndDeviceTemperature:f,pressureUnit:p,pressureUnitName:m,deviceTemperatureUnit:h,deviceTemperatureUnitName:`°C`}}}},Fe=e=>{if(e.bytes.length!==3)throw Error(`Keep alive message 08 needs 3 bytes but got ${e.bytes.length}.`);let t=e.bytes[1],n=e.bytes[2],r=(n&128)>>7==1,i=n&127,a={data:{messageType:8,configurationId:t,deviceStatistic:{batteryLevelNewEvent:r,batteryLevelPercent:i}}};return a};function Ie(){return Se({deviceName:un,roundingDecimals:4,channels:ke(),handlers:{1:Ae,2:Ae,3:je,4:Me,5:Ne,7:Pe,8:Fe}})}const Le={0:`Success`,1:`Unsupported command`,2:`Logical error`,3:`Memory error`,4:`Device error`,5:`Wrong frame format`,6:`Communication session lock`},Re={1:`BLE only`,2:`LoRaWAN class A`,3:`LoRaWAN class B`,4:`LoRaWAN class C`,5:`Mioty class Z`,6:`Mioty class A`,7:`Mioty class B`},ze={0:`Configuration received but not applied`,1:`Configuration received and applied with success`,2:`Configuration rejected - Tried to write a read only register`,3:`Configuration rejected - At least one register has an invalid value`,4:`Configuration rejected - The combination register start address/number of bytes is wrong`,5:`Entire configuration discarded because of invalid parameter combination`,6:`Entire configuration discarded because no answer from the cloud`,7:`Missing frame`,8:`Frame rejected - frame number already received`},Be={0:`float - IEEE754`,1:`int 24 - Fixed-point s16.7 (Q16.7)`,2:`int 16 - Fixed-point s10.5 (Q10.5)`,3:`uint16 - TULIP scale 2500 - 12500`},Ve={"float - IEEE754":4,"int 24 - Fixed-point s16.7 (Q16.7)":3,"int 16 - Fixed-point s10.5 (Q10.5)":2,"uint16 - TULIP scale 2500 - 12500":2},He={1:`Temperature`,2:`Temperature difference`,3:`Pressure (gauge)`,4:`Pressure (absolute)`,5:`Pressure (differential)`,6:`Flow (vol.)`,7:`Flow (mass)`,8:`Force`,9:`Mass`,10:`Level`,11:`Length`,12:`Volume`,13:`Current`,14:`Voltage`,15:`Resistance`,16:`Capacitance`,17:`Inductance`,18:`Relative`,19:`Time`,20:`Frequency`,21:`Speed`,22:`Acceleration`,23:`Density`,24:`Density (gauge pressure at 20 °C)`,25:`Density (absolute pressure at 20 °C)`,26:`Humidity (relative)`,27:`Humidity (absolute)`,28:`Angle of rotation / inclination`},Ue={1:`°C`,2:`°F`,3:`K`,4:`°R`,7:`bar`,8:`mbar`,9:`μbar`,10:`Pa`,11:`hPa`,12:`kPa`,13:`MPa`,14:`psi`,15:`lbf/ft²`,16:`kN/m²`,17:`N/cm²`,18:`atm`,19:`kg/cm²`,20:`kg/mm²`,21:`μmHg`,22:`mmHg`,23:`cmHg`,24:`inHg`,25:`mmH2O`,26:`mH2O`,27:`inH2O`,28:`ftH2O`,45:`N`,46:`daN`,47:`kN`,48:`MN`,49:`kp`,50:`lbf`,51:`ozf`,52:`dyn`,55:`kg`,56:`g`,57:`mg`,58:`lb`,60:`mm`,61:`cm`,62:`m`,63:`μm`,64:`ft`,65:`in`,70:`l`,71:`ml`,72:`m³`,73:`gal (UK)`,74:`gal (US)`,75:`ft³`,76:`in³`,82:`mΩ`,83:`Ω`,84:`kΩ`,86:`μV`,87:`mV`,88:`V`,90:`mA`,91:`μA`,93:`μF`,94:`nF`,95:`pF`,97:`mH`,98:`μH`,100:`%`,101:`‰`,102:`ppm`,105:`°`,106:`rad`,108:`counts`,110:`kg/m³`,111:`g/m³`,112:`mg/m³`,113:`μg/m³`,114:`kg/l`,115:`g/l`,116:`lb/ft³`,120:`l/min`,121:`l/s`,122:`m³/h`,123:`m³/s`,124:`cfm`,140:`kg/s`,141:`kg/h`,160:`s`,161:`min`,162:`h`,163:`d`,167:`Hz`,168:`kHz`,170:`m/s`,171:`cm/s`,172:`ft/min`,173:`ft/s`,180:`m/s²`,181:`ft/s²`};function We(e){return e===`__proto__`}function Ge(e){var t;return typeof e==`string`||typeof e==`symbol`?e:Object.is(e==null||(t=e.valueOf)==null?void 0:t.call(e),-0)?`-0`:String(e)}function Ke(e){let t=[],n=e.length;if(n===0)return t;let r=0,i=``,a=``,o=!1;for(e.charCodeAt(0)===46&&(t.push(``),r++);r<n;){let s=e[r];a?s===`\\`&&r+1<n?(r++,i+=e[r]):s===a?a=``:i+=s:o?s===`"`||s===`'`?a=s:s===`]`?(o=!1,t.push(i),i=``):i+=s:s===`[`?(o=!0,i&&(t.push(i),i=``)):s===`.`?i&&(t.push(i),i=``):i+=s,r++}return i&&t.push(i),t}function qe(e){return e!==null&&(typeof e==`object`||typeof e==`function`)}function Je(e,t){return e===t||Number.isNaN(e)&&Number.isNaN(t)}const Ye=/^(?:0|[1-9]\d*)$/;function Xe(e,t=9007199254740991){switch(typeof e){case`number`:return Number.isInteger(e)&&e>=0&&e<t;case`symbol`:return!1;case`string`:return Ye.test(e)}}function Ze(e){return typeof e==`symbol`||e instanceof Symbol}const Qe=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,$e=/^\w*$/;function et(e,t){return Array.isArray(e)?!1:typeof e==`number`||typeof e==`boolean`||e==null||Ze(e)?!0:typeof e==`string`&&($e.test(e)||!Qe.test(e))||t!=null&&Object.hasOwn(t,e)}const tt=(e,t,n)=>{let r=e[t];(!(Object.hasOwn(e,t)&&Je(r,n))||n===void 0&&!(t in e))&&(e[t]=n)};function nt(e,t,n,r){if(e==null&&!qe(e))return e;let i=et(t,e)?[t]:Array.isArray(t)?t:typeof t==`string`?Ke(t):[t],a=e;for(let t=0;t<i.length&&a!=null;t++){let o=Ge(i[t]);if(We(o))continue;let s;if(t===i.length-1)s=n(a[o]);else{let n=a[o],c=r==null?void 0:r(n,o,e);s=c===void 0?qe(n)?n:Xe(i[t+1])?[]:{}:c}tt(a,o,s),a=a[o]}return e}function rt(e,t,n){return nt(e,t,()=>n,()=>void 0)}function B(e){return String.fromCharCode(...e)}function V(e){return e[0]&255}function H(e){return(e[0]&255)<<8|e[1]&255}function U(e){return`${e[0]}.${e[1]}.${e[2]}`}function it(e){let t=e[0]+2e3,n=e[1].toString().padStart(2,`0`),r=e[2].toString().padStart(2,`0`);return`${t}-${n}-${r}`}function at(e){return!!(e[0]&255)}function ot(e){return(e[0]&255)<<24|(e[1]&255)<<16|(e[2]&255)<<8|e[3]&255}function st(e){let t=e[0]&255;return t>127?t-256:t}function ct(e){let t={};for(let n=1;n<=4;n++)t[`sensor${n}`]=!!(e[0]&1<<n-1);return t}function lt(e){let t={};for(let n=1;n<=8;n++)t[`channel${n}`]=!!(e[0]&1<<n-1);return t}function ut(e){let t=V(e),n=Re[t];if(n===void 0)throw Error(`Unknown product sub-ID value: ${t} (0x${t.toString(16).padStart(2,`0`)})`);return n}function dt(e){let t=V(e);return t}function ft(e){let t=V(e),n=He[t];if(n===void 0)throw Error(`Unknown measurand value: ${t} (0x${t.toString(16).padStart(2,`0`)})`);return n}function pt(e){let t=V(e),n=Ue[t];if(n===void 0)throw Error(`Unknown unit value: ${t} (0x${t.toString(16).padStart(2,`0`)})`);return n}function mt(e){let t=H(e);return t/1e3}function ht(e){let t={};for(let n=1;n<=8;n++)t[`channel${n}`]=!!(e[0]&1<<n-1);return t}function gt(e){let t=V(e);return Be[t]||`Unknown type: ${t}`}function _t(e){let t=e[0]&255;return{lowThreshold:!!(t&128),highThreshold:!!(t&64),fallingSlope:!!(t&32),risingSlope:!!(t&16),lowThresholdWithDelay:!!(t&8),highThresholdWithDelay:!!(t&4)}}function W(e,t,n){return{path:e,size:t,parsing:n}}function vt(e,t={}){let{startPosition:n=2}=t,r=[],i=n;for(;i<e.length;){if(i+1>=e.length){let t=e.length-i;throw RangeError(`Incomplete register block at position ${i}: Found ${t} byte(s) but need 2 bytes for addressing field. Data length: ${e.length}, Expected: addressing field (2 bytes) + register data. This suggests the data stream is truncated or malformed.`)}let t=e[i],n=e[i+1],a=t<<8|n,o=a>>5,s=n&31;if(i+2+s>e.length){let t=e.length-i-2;throw RangeError(`Incomplete register data for address 0x${o.toString(16)} at position ${i}: Need ${s} bytes but only ${t} bytes available in data stream. Total data length: ${e.length}, Current position: ${i}, Required: 2 bytes (addressing) + ${s} bytes (data) = ${2+s} bytes total. This suggests the data stream was cut off or the register size field is incorrect.`)}let c=e.slice(i+2,i+2+s);r.push({startRegisterAddress:o,value:c}),i+=2+s}return r}function yt(e,t){let n={};for(let r of t){let{startRegisterAddress:t,value:i}=r,a=t;for(;i.length>0;){let o=e[a];if(!o)throw ReferenceError(`Unknown register address 0x${a.toString(16)} in lookup table. This indicates an invalid message sent from the device. This register was expected during parsing of block starting at 0x${t.toString(16)}. This ${a===t?`is the first register in the block`:`is not the first register in the block`}. Starting address: 0x${t.toString(16)}. Available addresses in lookup: [${Object.keys(e).map(e=>`0x${Number(e).toString(16)}`).join(`, `)}]. `);if(i.length<o.size)throw RangeError(`Insufficient data for register 0x${a.toString(16)} (${o.path}): Expected ${o.size} bytes but only ${i.length} bytes remaining in block. Block started at address 0x${t.toString(16)} with ${r.value.length} total bytes. Current parsing position within block: ${r.value.length-i.length} bytes processed. This suggests a mismatch between register definitions and actual data structure.`);let s=i.slice(0,o.size);i.splice(0,o.size),a+=o.size;try{rt(n,o.path,o.parsing(s))}catch(e){let n=e instanceof Error?e.message:String(e);throw Error(`Failed to parse register 0x${(a-o.size).toString(16)} (${o.path}): ${n}. Register data: [${s.map(e=>`0x${e.toString(16).padStart(2,`0`)}`).join(`, `)}] (${s.length} bytes, expected ${o.size} bytes). Block started at address 0x${t.toString(16)}. This may indicate invalid data values or a parsing function error.`,{cause:e})}}}return n}function bt(e,t){let n=e>>2&31,r=ze[t];if(!r)throw TypeError(`Invalid status code: 0x${t.toString(16).padStart(2,`0`).toUpperCase()}`);return{frameNumber:n,status:r}}function xt(e){let{frameNumber:t,status:n}=bt(e[2],e[3]),r={frames:[{frameNumber:t,status:n}]};if(e.length===4)return r;if(e.length>4&&e.length<7)throw RangeError(`Invalid message length: expected 7 bytes minimum for apply config answer, got ${e.length}`);if(r.revisionCounter=e[4]<<8|e[5],r.totalWrongFrames=e[6],e.length===7)return r;if(e.length>7&&e.length%2==0)throw RangeError(`Invalid message length: expected odd number of bytes for apply config answer with additional frames, got ${e.length}`);let i=7;for(;i+1<e.length;){let t=bt(e[i],e[i+1]);r.frames.push(t),i+=2}return r}function St(e,t,n={}){let r=vt(e,n);return yt(t,r)}function Ct(e){return e&63}function G(e,t){let{expectedMessageType:n,allowedSubTypes:r,minLength:i,messageTypeName:a}=t;if(e.length<i){let t=a?`${a} message`:`Message`;throw RangeError(`${t} too short. Expected at least ${i} bytes but got ${e.length}`)}let o=Array.isArray(n)?n:[n],s=e[0];if(!o.includes(s)){let e=Array.isArray(n)?n.map(e=>`0x${e.toString(16).padStart(2,`0`).toUpperCase()}`).join(`, `):`0x${n.toString(16).padStart(2,`0`).toUpperCase()}`,t=`0x${s.toString(16).padStart(2,`0`).toUpperCase()}`;throw a?TypeError(`Invalid ${a.toLowerCase()} message type: expected ${e} but got ${t}`):TypeError(`Invalid message type: expected ${e} but got ${t}`)}let c=Ct(e[1]);if(!r.includes(c)){let e=`0x${c.toString(16).padStart(2,`0`).toUpperCase()}`,t=r.map(e=>`0x${e.toString(16).padStart(2,`0`).toUpperCase()}`).join(`, `);throw a?TypeError(`Unsupported ${a.toLowerCase()} message subtype: ${e}. Allowed subtypes: ${t}`):TypeError(`Invalid message subtype: expected one of [${t}] but got ${e}`)}return{messageType:s,messageSubType:c}}function wt(e){return 42+(e-1)*493}function Tt(e,t){return 42+(e-1)*464+e*29+(t-1)*58}function Et(){let e=[`sensor1`,`sensor2`,`sensor3`,`sensor4`],t=[`channel1`,`channel2`,`channel3`,`channel4`,`channel5`,`channel6`,`channel7`,`channel8`],n={};return n[0]=W(`communicationModule.measuringPeriodAlarmOff`,4,ot),n[4]=W(`communicationModule.measuringPeriodAlarmOn`,4,ot),n[8]=W(`communicationModule.transmissionRateAlarmOff`,2,H),n[10]=W(`communicationModule.transmissionRateAlarmOn`,2,H),n[12]=W(`communicationModule.overVoltageThreshold`,2,H),n[14]=W(`communicationModule.underVoltageThreshold`,2,H),n[16]=W(`communicationModule.overTemperatureCmChip`,1,st),n[17]=W(`communicationModule.underTemperatureCmChip`,1,st),n[18]=W(`communicationModule.downlinkAnswerTimeout`,1,V),n[19]=W(`communicationModule.fetchAdditionalDownlinkTimeInterval`,1,V),n[20]=W(`communicationModule.enableBleAdvertising`,1,at),e.forEach((e,r)=>{let i=r+1,a=wt(i);n[a+0]=W(`${e}.configuration.samplingChannels`,1,ht),n[a+1]=W(`${e}.configuration.bootTime`,2,H),n[a+3]=W(`${e}.configuration.communicationTimeout`,2,H),n[a+5]=W(`${e}.configuration.communicationRetryCount`,1,V),t.forEach((t,r)=>{let a=r+1,o=Tt(i,a);n[o+0]=W(`${e}.${t}.protocolDataType`,1,gt),n[o+1]=W(`${e}.${t}.processAlarmEnabled`,1,_t),n[o+2]=W(`${e}.${t}.processAlarmDeadBand`,4,R),n[o+6]=W(`${e}.${t}.lowThresholdAlarmValue`,4,R),n[o+10]=W(`${e}.${t}.highThresholdAlarmValue`,4,R),n[o+14]=W(`${e}.${t}.fallingSlopeAlarmValue`,4,R),n[o+18]=W(`${e}.${t}.risingSlopeAlarmValue`,4,R),n[o+22]=W(`${e}.${t}.lowThresholdWithDelayAlarmValue`,4,R),n[o+26]=W(`${e}.${t}.lowThresholdWithDelayAlarmDelay`,2,H),n[o+28]=W(`${e}.${t}.highThresholdWithDelayAlarmValue`,4,R),n[o+32]=W(`${e}.${t}.highThresholdWithDelayAlarmDelay`,2,H)})}),n}function Dt(e,t){if(!e.every(e=>t.includes(e))){let n=e.filter(e=>!t.includes(e)),r=n.length===1?`Sensor`:`Sensors`;throw TypeError(`${r} [${n.join(`, `)}] ${n.length===1?`is`:`are`} not supported by this device`)}}function Ot(e,t,n,r){for(let i of e){let e=Object.keys(t[i]||{}).filter(e=>e!==r),a=Object.keys(n[i]||{}).filter(e=>e!==r),o=e.filter(e=>!a.includes(e));if(o.length>0){let e=o.length===1?`Channel`:`Channels`;throw TypeError(`${e} ${o.join(`, `)} on sensor ${i} ${o.length===1?`is`:`are`} not supported by this device`)}}}function kt(e,t,n,r){e.forEach(e=>{let i=n[e];if(!i)return;let a=Object.keys(i).filter(e=>e!==r);a.forEach(n=>{let r=i[n],a=r==null?void 0:r.channelName;if(a){var o;!(t==null||(o=t[e])==null)&&o[n]&&(t[e][n].channelName=a)}})})}function At(e,t){let n=Object.keys(t),r=Object.keys(e).filter(e=>e!==`communicationModule`);Dt(r,n),r.forEach(n=>{var r;let i=Object.keys(t[n]||{}),a=(r=e[n])==null||(r=r.configuration)==null?void 0:r.samplingChannels;if(!a)return;let o=Object.keys(a||{}).filter(e=>!i.includes(e)),s=o.filter(e=>a[e]===!0);if(s.length>0)throw TypeError(`Sampling channels [${s.join(`, `)}] for sensor '${n}' are not expected for this device`)}),Ot(r,e,t,`configuration`),kt(n,e,t,`identification`)}function jt(e,t,n={}){let{messageType:r,messageSubType:i}=G(e,{expectedMessageType:21,allowedSubTypes:[1,2],minLength:4,messageTypeName:`Configuration`}),a=St(e,Et(),n);return At(a,t),{data:{messageType:r,messageSubType:i,configuration:a}}}function Mt(e){let{messageType:t,messageSubType:n}=G(e,{expectedMessageType:21,allowedSubTypes:[3],minLength:4,messageTypeName:`Configuration`}),r=xt(e);return{data:{messageType:t,messageSubType:n,configuration:r}}}var Nt=c(p(),1);function Pt(e,t=2){let n=[];for(;t<e.length;){let r=(e[t]&192)>>6,i=(e[t]&56)>>3,a=(e[t]&6)>>1,o=Be[a],s=Ve[o];if(t+s>e.length)throw RangeError(`${r}, ${i}, Not enough data left to finish reading measurement data block for ${o}. Expected ${s} bytes but got ${e.length-t}, with currentIndex ${t}`);let c;switch(o){case`float - IEEE754`:c=be(e.slice(t+1,t+1+4)),Number.isNaN(c)&&(c=`hasError`);break;case`uint16 - TULIP scale 2500 - 12500`:c=H(e.slice(t+1,t+1+2)),c===65535&&(c=`hasError`);break;case`int 24 - Fixed-point s16.7 (Q16.7)`:case`int 16 - Fixed-point s10.5 (Q10.5)`:throw TypeError(`Data type ${o} is not implemented yet`)}c===`hasError`?n.push({sensor:`sensor${r+1}`,sensorId:r,channel:`channel${i+1}`,channelId:i,sourceDataType:o,valueAcquisitionError:!0}):n.push({sensor:`sensor${r+1}`,sensorId:r,channel:`channel${i+1}`,channelId:i,sourceDataType:o,valueAcquisitionError:!1,value:c}),t+=s+1}if(n.length===0)throw RangeError(`Expected data message to contain at least one valid measurement, but got none`);return n}function Ft(e,t,n=4){let{messageType:r,messageSubType:i}=G(e,{expectedMessageType:[16,17],allowedSubTypes:[1],minLength:3,messageTypeName:`Data`}),a=Pt(e).map(e=>{var r;let i=(r=t[e.sensor])==null?void 0:r[e.channel];if(!i)throw TypeError(`Measurement from sensor ${e.sensor} channel ${e.channel} is not supported by the device profile.`);let a=i.measurementTypes.includes(e.sourceDataType);if(!a)throw TypeError(`Measurement from sensor ${e.sensor} channel ${e.channel} does not support data type ${e.sourceDataType}.`);if(e.sourceDataType===`uint16 - TULIP scale 2500 - 12500`&&e.value!==void 0)e.value=I(e.value,i);else if(e.sourceDataType!==`uint16 - TULIP scale 2500 - 12500`&&e.value!==void 0&&(e.value<i.start||e.value>i.end))throw RangeError(`Measurement for sensor ${e.sensor} channel ${e.channel} is out of range, got ${e.value}`);return typeof e.value==`number`&&(e.value=L(e.value,n)),(0,Nt.default)((0,Nt.default)({},e),{},{channelName:i.channelName})});return{data:{messageType:r,messageSubType:i,measurements:a}}}var It=c(p(),1);const Lt=K({localUserAccessDenied:1,cmChipLowTemperature:2,cmChipHighTemperature:4,airTimeLimitation:8,memoryError:16,lowVoltage:32,highVoltage:64}),Rt=K({sensorCommunicationError:1,sensorNotSupported:2,sensorInternalError:4}),zt=K({shortCondition:1,openCondition:2,outOfMinMeasurementRange:4,outOfMaxMeasurementRange:8,outOfMinPhysicalSensorLimit:16,outOfMaxPhysicalSensorLimit:32});function K(e,t){return(0,It.default)((0,It.default)({},t==null?{}:t),e)}function Bt(e,t){let n={};for(let[r,i]of Object.entries(e))t.includes(r)&&(n[r]=i);return n}function Vt(e,t){let n={};for(let[r,i]of Object.entries(t))n[r]=!!(e&i);return n}function Ht(e,t){let{messageType:n,messageSubType:r}=G(e,{expectedMessageType:19,allowedSubTypes:[1],minLength:4,messageTypeName:`Communication module alarm`});if(e.length!==4)throw RangeError(`Invalid data length for device alarm message: expected 4 but got ${e.length}`);let i=e[2]<<8|e[3];return{data:{messageType:n,messageSubType:r,communicationModuleAlarms:{alarmFlags:Vt(i,t)}}}}function Ut(e,t,n){let{messageType:r,messageSubType:i}=G(e,{expectedMessageType:19,allowedSubTypes:[2],minLength:5,messageTypeName:`Sensor alarm`}),a=2,o=[];for(;a<e.length;){if(a+2>=e.length)throw RangeError(`Not enough data left to finish reading sensor alarm entry. Expected 3 bytes but got ${e.length-a}. currentIndex ${a}`);let r=e[a],i=e[a+1],s=e[a+2],c=r>>6&3,l=`sensor${c+1}`;if(!t[l])throw TypeError(`Sensor alarm for ${String(l)} is not supported by the device profile.`);let u=i<<8|s;o.push({sensor:l,sensorId:c,alarmFlags:Vt(u,n)}),a+=3}return{data:{messageType:r,messageSubType:i,sensorAlarms:o}}}function Wt(e,t,n){let{messageType:r,messageSubType:i}=G(e,{expectedMessageType:19,allowedSubTypes:[3],minLength:5,messageTypeName:`Channel alarm`}),a=2,o=[];for(;a<e.length;){if(a+2>=e.length)throw RangeError(`Not enough data left to finish reading channel alarm entry. Expected 3 bytes but got ${e.length-a}. currentIndex ${a}`);let r=e[a],i=e[a+1],s=e[a+2],c=r>>6&3,l=r>>3&7,u=`sensor${c+1}`,d=`channel${l+1}`;if(!t[u])throw TypeError(`Channel alarm for ${String(u)} is not supported by the device profile.`);if(!t[u][d])throw TypeError(`Channel alarm for ${String(u)}/${String(d)} is not supported by the device profile.`);let f=t[u][d].channelName,p=i<<8|s;o.push({sensor:u,sensorId:c,channel:d,channelId:l,channelName:f,alarmFlags:Vt(p,n)}),a+=3}return{data:{messageType:r,messageSubType:i,channelAlarms:o}}}function Gt(e){return 60+(e-1)*460}function Kt(e,t){return 60+(e-1)*400+e*60+(t-1)*50}function qt(){let e=[`sensor1`,`sensor2`,`sensor3`,`sensor4`],t=[`channel1`,`channel2`,`channel3`,`channel4`,`channel5`,`channel6`,`channel7`,`channel8`],n={};return n[0]=W(`communicationModule.productId`,1,V),n[1]=W(`communicationModule.productSubId`,1,ut),n[2]=W(`communicationModule.channelPlan`,1,dt),n[3]=W(`communicationModule.connectedSensors`,1,ct),n[4]=W(`communicationModule.firmwareVersion`,3,U),n[7]=W(`communicationModule.hardwareVersion`,3,U),n[10]=W(`communicationModule.productionDate`,3,it),n[13]=W(`communicationModule.serialNumberPart1`,5,B),n[18]=W(`communicationModule.serialNumberPart2`,6,B),e.forEach((e,r)=>{let i=r+1,a=Gt(i);n[a+0]=W(`${e}.identification.sensorType`,2,H),n[a+2]=W(`${e}.identification.existingChannels`,1,lt),n[a+3]=W(`${e}.identification.firmwareVersion`,3,U),n[a+6]=W(`${e}.identification.hardwareVersion`,3,U),n[a+9]=W(`${e}.identification.productionDate`,3,it),n[a+12]=W(`${e}.identification.serialNumberPart1`,5,B),n[a+17]=W(`${e}.identification.serialNumberPart2`,6,B),t.forEach((t,r)=>{let a=r+1,o=Kt(i,a);n[o+0]=W(`${e}.channel${a}.measurand`,1,ft),n[o+1]=W(`${e}.channel${a}.unit`,1,pt),n[o+2]=W(`${e}.channel${a}.minMeasureRange`,4,R),n[o+6]=W(`${e}.channel${a}.maxMeasureRange`,4,R),n[o+10]=W(`${e}.channel${a}.minPhysicalLimit`,4,R),n[o+14]=W(`${e}.channel${a}.maxPhysicalLimit`,4,R),n[o+18]=W(`${e}.channel${a}.accuracy`,2,mt),n[o+20]=W(`${e}.channel${a}.offset`,4,R),n[o+24]=W(`${e}.channel${a}.gain`,4,R),n[o+28]=W(`${e}.channel${a}.calibrationDate`,3,it)})}),n}function Jt(e,t){var n;let r=Object.keys(t);!(e==null||(n=e.communicationModule)==null)&&n.connectedSensors&&Object.entries(e.communicationModule.connectedSensors).forEach(([e,t])=>{let n=r.includes(e);if(t!==n)throw TypeError(`Device sensor connection mismatch: ${e} is ${t?`connected`:`not connected`} but this device expects it to ${n?`be connected`:`not be connected`}`)});let i=Object.keys(e).filter(e=>e!==`communicationModule`);Dt(i,r),Ot(i,e,t,`identification`),kt(r,e,t,`identification`)}function Yt(e,t,n={}){let{messageType:r,messageSubType:i}=G(e,{expectedMessageType:20,allowedSubTypes:[1,2,4],minLength:4,messageTypeName:`Identification`}),a=St(e,qt(),n);return Jt(a,t),{data:{messageType:r,messageSubType:i,identification:a}}}function Xt(e){let{messageType:t,messageSubType:n}=G(e,{expectedMessageType:20,allowedSubTypes:[3],minLength:4,messageTypeName:`Identification`}),r=xt(e);return{data:{messageType:t,messageSubType:n,identification:r}}}function Zt(e){let{messageType:t,messageSubType:n}=G(e,{expectedMessageType:22,allowedSubTypes:[1],minLength:5,messageTypeName:`Keep alive`}),r=e[2],i=!!(r&128),a=!!(r&64),o=!!(r&32),s=e[3]<<8|e[4],c;if(a){if(e.length<6)throw RangeError(`Keep alive message missing battery level. Expected 6 bytes when battery level computation is enabled but got ${e.length}`);if(c=e[5],c<0||c>100)throw RangeError(`Invalid battery level: ${c}%. Must be between 0 and 100`)}else{if(e.length>5)throw RangeError(`Keep alive message has unexpected extra bytes. Expected 5 bytes when battery level computation is disabled but got ${e.length}`);c=void 0}return a?{data:{messageType:t,messageSubType:n,keepAliveData:{status:{mainPowered:i,ableToComputeBatteryLevel:!0,hasCommunicationModuleRestarted:o},revisionCounter:s,batteryLevel:c}}}:{data:{messageType:t,messageSubType:n,keepAliveData:{status:{mainPowered:i,ableToComputeBatteryLevel:!1,hasCommunicationModuleRestarted:o},revisionCounter:s}}}}function Qt(e,t){let{messageType:n,messageSubType:r}=G(e,{expectedMessageType:18,allowedSubTypes:[1],minLength:4,messageTypeName:`Process alarm`}),i=2,a=[];for(;i<e.length;){var o;if(i+1>=e.length)throw RangeError(`Not enough data left to finish reading process alarm entry. Expected 2 bytes but got ${e.length-i}. currentIndex ${i}`);let n=e[i],r=e[i+1],s=(n&192)>>6,c=(n&56)>>3,l=`sensor${s+1}`,u=`channel${c+1}`,d=(o=t[l])==null?void 0:o[u];if(!d)throw TypeError(`Process alarm for sensor ${l} channel ${u} is not supported by the device profile.`);a.push({sensor:l,sensorId:s,channel:u,channelId:c,channelName:d.channelName,alarmFlags:{lowThreshold:!!(r&128),highThreshold:!!(r&64),fallingSlope:!!(r&32),risingSlope:!!(r&16),lowThresholdWithDelay:!!(r&8),highThresholdWithDelay:!!(r&4)}}),i+=2}return{data:{messageType:n,messageSubType:r,processAlarms:a}}}const $t={1:[1,2],2:[1,2],3:[1,2,3],4:[1],5:[1]};function en(e){var t;let{messageType:n,messageSubType:r}=G(e,{expectedMessageType:23,allowedSubTypes:[1],minLength:5,messageTypeName:`Spontaneous downlink answer`}),i=e[2],a=Ct(e[3]),o={type:i,subType:a},s=(t=$t[i])==null?void 0:t.includes(a);if(!s)throw TypeError(`Answered downlink can not have a combination of type: ${i} and subType: ${a}`);let c=e[4],l=Le[c];if(!l)throw TypeError(`Invalid status byte: ${c}`);let u;if(c===4){if(e.length<6)throw RangeError(`Device error code missing for Device error status (expected 6 bytes)`);u=e[5]}else if(e.length>5)throw RangeError(`Spontaneous downlink answer message has unexpected extra bytes. Expected 5 bytes for status ${l} but got ${e.length}`);return u===void 0?{data:{messageType:n,messageSubType:r,spontaneousDownlinkAnswer:{answeredDownlink:o,status:l}}}:{data:{messageType:n,messageSubType:r,spontaneousDownlinkAnswer:{answeredDownlink:o,status:l,deviceErrorCode:u}}}}function tn(e){let{messageType:t,messageSubType:n}=G(e,{expectedMessageType:23,allowedSubTypes:[2],minLength:2,messageTypeName:`Spontaneous fetch additional downlink`});if(e.length!==2)throw RangeError(`Spontaneous fetch additional downlink message has invalid length. Expected 2 bytes but got ${e.length}`);return{data:{messageType:t,messageSubType:n}}}function nn(e){let t=`${e.deviceName}TULIP3Codec`,n=F(e.roundingDecimals);function r(){let t=[];return Object.values(e.sensorChannelConfig).forEach(e=>{Object.values(e).forEach(e=>{t.push({name:e.channelName,start:e.start,end:e.end})})}),t}ue(r(),t);function i(e){if(e.bytes.length<2)return!1;let t=e.bytes[0];return t>=16&&t<=23}function a(t){if(t.bytes.length<2)throw RangeError(`Invalid input length. Expected at least 2 bytes but got ${t.bytes.length}`);let r=t.bytes[0],i=Ct(t.bytes[1]);switch(r){case 16:case 17:return Ft(t.bytes,e.sensorChannelConfig,n);case 18:return Qt(t.bytes,e.sensorChannelConfig);case 19:switch(i){case 1:return Ht(t.bytes,e.deviceAlarmConfig.communicationModuleAlarms);case 2:return Ut(t.bytes,e.sensorChannelConfig,e.deviceAlarmConfig.sensorAlarms);case 3:return Wt(t.bytes,e.sensorChannelConfig,e.deviceAlarmConfig.sensorChannelAlarms);default:throw Error(`Unsupported sub message type 0x${i==null?void 0:i.toString(16)} for message type 0x13`)}case 20:switch(i){case 1:case 2:case 4:return Yt(t.bytes,e.sensorChannelConfig,{maxRegisterSize:e.identificationMessageMaxRegisterSize});case 3:return Xt(t.bytes);default:throw Error(`Unsupported sub message type 0x${i==null?void 0:i.toString(16)} for message type 0x14`)}case 21:switch(i){case 1:case 2:return jt(t.bytes,e.sensorChannelConfig,{maxRegisterSize:e.configurationMessageMaxRegisterSize});case 3:return Mt(t.bytes);default:throw Error(`Unsupported sub message type 0x${i==null?void 0:i.toString(16)} for message type 0x15`)}case 22:return Zt(t.bytes);case 23:switch(i){case 1:return en(t.bytes);case 2:return tn(t.bytes);default:throw Error(`Unsupported sub message type 0x${i==null?void 0:i.toString(16)} for message type 0x17`)}default:throw Error(`Unsupported message type 0x${r==null?void 0:r.toString(16)}`)}}return{name:t,adjustMeasuringRange:(t,n)=>{let r=Object.values(e.sensorChannelConfig);for(let e of r){let r=Object.values(e).find(e=>(e==null?void 0:e.channelName)===t);if(r){r.start=n.start,r.end=n.end;return}}},canTryDecode:i,getChannels:r,adjustRoundingDecimals:e=>{n=F(e,n)},decode:a}}function rn(e){return e}const an=Bt(Lt,[`lowVoltage`,`airTimeLimitation`,`memoryError`]),on=K(Bt(Rt,[`sensorCommunicationError`]),{sensorBusy:32768,sensorMemoryIntegrity:16384,sensorALUSaturation:8192}),sn=Bt(zt,[`outOfMaxPhysicalSensorLimit`,`outOfMinPhysicalSensorLimit`]);function cn(){return rn({deviceName:un,deviceAlarmConfig:{communicationModuleAlarms:an,sensorAlarms:on,sensorChannelAlarms:sn},sensorChannelConfig:{sensor1:{channel1:{channelName:`pressure`,start:0,end:10,measurementTypes:[`uint16 - TULIP scale 2500 - 12500`]},channel2:{channelName:`device temperature`,start:-45,end:110,measurementTypes:[`uint16 - TULIP scale 2500 - 12500`]}}}})}function ln(){return nn(cn())}const un=`PEW-1000`;function dn(){return xe({parserName:un,codecs:[Ie(),ln()]})}var fn=dn,pn=o((()=>{Array.prototype.includes||Object.defineProperty(Array.prototype,`includes`,{value:function(e,t){if(this==null)throw TypeError(`"this" is null or not defined`);var n=Object(this),r=n.length>>>0;if(r===0)return!1;var i=t|0,a=Math.max(i>=0?i:r-Math.abs(i),0);function o(e,t){return e===t||typeof e==`number`&&typeof t==`number`&&isNaN(e)&&isNaN(t)}for(;a<r;){if(o(n[a],e))return!0;a++}return!1}})})),mn=o(((exports,t)=>{t.exports=function(){var e=Number.isInteger;return typeof e==`function`?!e(`23`)&&e(34)&&!e(32.34):!1}})),hn=o(((exports,t)=>{t.exports=function(e){return typeof e==`number`?e%1==0:!1}})),gn=o((()=>{mn()()||Object.defineProperty(Number,`isInteger`,{value:hn(),configurable:!0,enumerable:!1,writable:!0})})),_n=o(((exports,t)=>{t.exports=function(){return typeof globalThis!=`object`||!globalThis?!1:globalThis.Array===Array}})),vn=o(((exports,t)=>{var n=function(){if(typeof self==`object`&&self)return self;if(typeof window==`object`&&window)return window;throw Error("Unable to resolve global `this`")};t.exports=(function(){if(this)return this;try{Object.defineProperty(Object.prototype,`__global__`,{get:function(){return this},configurable:!0})}catch(e){return n()}try{return __global__||n()}finally{delete Object.prototype.__global__}})()})),q=o(((exports,t)=>{t.exports=_n()()?globalThis:vn()})),yn=o(((exports,t)=>{var n=q(),r={object:!0,symbol:!0};t.exports=function(){var e=n.Symbol,t;return!(typeof e!=`function`||(t=e(`test symbol`),!r[typeof e.iterator])||!r[typeof e.toPrimitive]||!r[typeof e.toStringTag])}})),J=o(((exports,t)=>{var n=void 0;t.exports=function(e){return e!==n&&e!==null}})),bn=o(((exports,t)=>{var n=J(),r={object:!0,function:!0,undefined:!0};t.exports=function(e){return n(e)?hasOwnProperty.call(r,typeof e):!1}})),xn=o(((exports,t)=>{var n=bn();t.exports=function(e){if(!n(e))return!1;try{return e.constructor?e.constructor.prototype===e:!1}catch(e){return!1}}})),Sn=o(((exports,t)=>{var n=xn();t.exports=function(e){if(typeof e!=`function`||!hasOwnProperty.call(e,`length`))return!1;try{if(typeof e.length!=`number`||typeof e.call!=`function`||typeof e.apply!=`function`)return!1}catch(e){return!1}return!n(e)}})),Cn=o(((exports,t)=>{var n=Sn(),r=/^\s*class[\s{/}]/,i=Function.prototype.toString;t.exports=function(e){return!(!n(e)||r.test(i.call(e)))}})),wn=o(((exports,t)=>{t.exports=function(){var e=Object.assign,t;return typeof e==`function`?(t={foo:`raz`},e(t,{bar:`dwa`},{trzy:`trzy`}),t.foo+t.bar+t.trzy===`razdwatrzy`):!1}})),Tn=o(((exports,t)=>{t.exports=function(){try{return!0}catch(e){return!1}}})),En=o(((exports,t)=>{t.exports=function(){}})),Y=o(((exports,t)=>{var n=En()();t.exports=function(e){return e!==n&&e!==null}})),Dn=o(((exports,t)=>{var n=Y(),r=Object.keys;t.exports=function(e){return r(n(e)?Object(e):e)}})),On=o(((exports,t)=>{t.exports=Tn()()?Object.keys:Dn()})),X=o(((exports,t)=>{var n=Y();t.exports=function(e){if(!n(e))throw TypeError(`Cannot use null or u