@w2a-iiot/raw-javascript-parsers
Version:
This packages contain the raw built javascript parsers for WIKA's IIoT devices.
2 lines • 71.3 kB
JavaScript
var __commonJSMin=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);function _typeof(e){"@babel/helpers - typeof";return _typeof=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},_typeof(e)}function toPrimitive(e,n){if(_typeof(e)!=`object`||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var i=r.call(e,n||`default`);if(_typeof(i)!=`object`)return i;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(n===`string`?String:Number)(e)}function toPropertyKey(e){var r=toPrimitive(e,`string`);return _typeof(r)==`symbol`?r:r+``}function _defineProperty(e,t,n){return(t=toPropertyKey(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function ownKeys(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 _objectSpread2(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?ownKeys(Object(n),!0).forEach(function(t){_defineProperty(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function getGlobalConfig(e){return{lang:e?.lang??void 0,message:e?.message,abortEarly:e?.abortEarly??void 0,abortPipeEarly:e?.abortPipeEarly??void 0}}function _stringify(e){var t;let n=typeof e;return n===`string`?`"${e}"`:n===`number`||n===`bigint`||n===`boolean`?`${e}`:n===`object`||n===`function`?(e&&((t=Object.getPrototypeOf(e))==null||(t=t.constructor)==null?void 0:t.name))??`null`:n}function _addIssue(e,t,n,r,i){let a=i&&`input`in i?i.input:n.value,o=i?.expected??e.expects??null,s=i?.received??_stringify(a),l={kind:e.kind,type:e.type,input:a,expected:o,received:s,message:`Invalid ${t}: ${o?`Expected ${o} but r`:`R`}eceived ${s}`,requirement:e.requirement,path:i?.path,issues:i?.issues,lang:r.lang,abortEarly:r.abortEarly,abortPipeEarly:r.abortPipeEarly},u=e.kind===`schema`,d=i?.message??e.message??(e.reference,l.lang,void 0)??(u?(l.lang,void 0):null)??r.message??(l.lang,void 0);d!==void 0&&(l.message=typeof d==`function`?d(l):d),u&&(n.typed=!1),n.issues?n.issues.push(l):n.issues=[l]}function _getStandardProps(e){return{version:1,vendor:`valibot`,validate(t){return e[`~run`]({value:t},getGlobalConfig())}}}function _joinExpects(e,t){let n=[...new Set(e)];return n.length>1?`(${n.join(` ${t} `)})`:n[0]??`never`}function getDotPath(e){if(e.path){let t=``;for(let n of e.path)if(typeof n.key==`string`||typeof n.key==`number`)t?t+=`.${n.key}`:t+=n.key;else return null;return t}return null}const HEXADECIMAL_REGEX=/^(?:0[hx])?[\da-fA-F]+$/u;function hexadecimal(e){return{kind:`validation`,type:`hexadecimal`,reference:hexadecimal,async:!1,expects:null,requirement:HEXADECIMAL_REGEX,message:e,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&_addIssue(this,`hexadecimal`,e,t),e}}}function integer(e){return{kind:`validation`,type:`integer`,reference:integer,async:!1,expects:null,requirement:Number.isInteger,message:e,"~run"(e,t){return e.typed&&!this.requirement(e.value)&&_addIssue(this,`integer`,e,t),e}}}function maxValue(e,t){return{kind:`validation`,type:`max_value`,reference:maxValue,async:!1,expects:`<=${e instanceof Date?e.toJSON():_stringify(e)}`,requirement:e,message:t,"~run"(e,t){return e.typed&&!(e.value<=this.requirement)&&_addIssue(this,`value`,e,t,{received:e.value instanceof Date?e.value.toJSON():_stringify(e.value)}),e}}}function minValue(e,t){return{kind:`validation`,type:`min_value`,reference:minValue,async:!1,expects:`>=${e instanceof Date?e.toJSON():_stringify(e)}`,requirement:e,message:t,"~run"(e,t){return e.typed&&!(e.value>=this.requirement)&&_addIssue(this,`value`,e,t,{received:e.value instanceof Date?e.value.toJSON():_stringify(e.value)}),e}}}function transform(e){return{kind:`transformation`,type:`transform`,reference:transform,async:!1,operation:e,"~run"(e){return e.value=this.operation(e.value),e}}}function getFallback(e,t,n){return typeof e.fallback==`function`?e.fallback(t,n):e.fallback}function getDefault(e,t,n){return typeof e.default==`function`?e.default(t,n):e.default}function array(e,t){return{kind:`schema`,type:`array`,reference:array,expects:`Array`,async:!1,item:e,message:t,get"~standard"(){return _getStandardProps(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||=o.issues,t.abortEarly){e.typed=!1;break}}o.typed||(e.typed=!1),e.value.push(o.value)}}else _addIssue(this,`type`,e,t);return e}}}function boolean(e){return{kind:`schema`,type:`boolean`,reference:boolean,expects:`boolean`,async:!1,message:e,get"~standard"(){return _getStandardProps(this)},"~run"(e,t){return typeof e.value==`boolean`?e.typed=!0:_addIssue(this,`type`,e,t),e}}}function literal(e,t){return{kind:`schema`,type:`literal`,reference:literal,expects:_stringify(e),async:!1,literal:e,message:t,get"~standard"(){return _getStandardProps(this)},"~run"(e,t){return e.value===this.literal?e.typed=!0:_addIssue(this,`type`,e,t),e}}}function number(e){return{kind:`schema`,type:`number`,reference:number,expects:`number`,async:!1,message:e,get"~standard"(){return _getStandardProps(this)},"~run"(e,t){return typeof e.value==`number`&&!isNaN(e.value)?e.typed=!0:_addIssue(this,`type`,e,t),e}}}function object(e,t){return{kind:`schema`,type:`object`,reference:object,expects:`Object`,async:!1,entries:e,message:t,get"~standard"(){return _getStandardProps(this)},"~run"(e,t){let n=e.value;if(n&&typeof n==`object`){e.typed=!0,e.value={};for(let i in 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]:getDefault(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||=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]=getFallback(a);else if(a.type!==`exact_optional`&&a.type!==`optional`&&a.type!==`nullish`&&(_addIssue(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 _addIssue(this,`type`,e,t);return e}}}function optional(e,t){return{kind:`schema`,type:`optional`,reference:optional,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,get"~standard"(){return _getStandardProps(this)},"~run"(e,t){return e.value===void 0&&(this.default!==void 0&&(e.value=getDefault(this,e,t)),e.value===void 0)?(e.typed=!0,e):this.wrapped[`~run`](e,t)}}}function picklist(e,t){return{kind:`schema`,type:`picklist`,reference:picklist,expects:_joinExpects(e.map(_stringify),`|`),async:!1,options:e,message:t,get"~standard"(){return _getStandardProps(this)},"~run"(e,t){return this.options.includes(e.value)?e.typed=!0:_addIssue(this,`type`,e,t),e}}}function string(e){return{kind:`schema`,type:`string`,reference:string,expects:`string`,async:!1,message:e,get"~standard"(){return _getStandardProps(this)},"~run"(e,t){return typeof e.value==`string`?e.typed=!0:_addIssue(this,`type`,e,t),e}}}function _subIssues(e){let t;if(e)for(let n of e)t?t.push(...n.issues):t=n.issues;return t}function union(e,t){return{kind:`schema`,type:`union`,reference:union,expects:_joinExpects(e.map(e=>e.expects),`|`),async:!1,options:e,message:t,get"~standard"(){return _getStandardProps(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];_addIssue(this,`type`,e,t,{issues:_subIssues(r)}),e.typed=!0}else if(i?.length===1)return i[0];else _addIssue(this,`type`,e,t,{issues:_subIssues(i)});return e}}}function variant(e,t,n){return{kind:`schema`,type:`variant`,reference:variant,expects:`Object`,async:!1,key:e,options:t,message:n,get"~standard"(){return _getStandardProps(this)},"~run"(e,t){let n=e.value;if(n&&typeof n==`object`){let r,i=0,a=this.key,o=[],s=(e,c)=>{for(let l of e.options){if(l.type===`variant`)s(l,new Set(c).add(l.key));else{let e=!0,s=0;for(let t of c){let r=l.entries[t];if(t in n?r[`~run`]({typed:!1,value:n[t]},{abortEarly:!0}).issues:r.type!==`exact_optional`&&r.type!==`optional`&&r.type!==`nullish`){e=!1,a!==t&&(i<s||i===s&&t in n&&!(a in n))&&(i=s,a=t,o=[]),a===t&&o.push(l.entries[t].expects);break}s++}if(e){let e=l[`~run`]({value:n},t);(!r||!r.typed&&e.typed)&&(r=e)}}if(r&&!r.issues)break}};if(s(this,new Set([this.key])),r)return r;_addIssue(this,`type`,e,t,{input:n[a],expected:_joinExpects(o,`|`),path:[{type:`object`,origin:`value`,input:n,key:a,value:n[a]}]})}else _addIssue(this,`type`,e,t);return e}}}function pipe(...e){return _objectSpread2(_objectSpread2({},e[0]),{},{pipe:e,get"~standard"(){return _getStandardProps(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 safeParse(e,t,n){let r=e[`~run`]({value:t},getGlobalConfig(n));return{typed:r.typed,success:!r.issues,output:r.value,issues:r.issues}}function summarize(e){let t=``;for(let n of e){t&&(t+=`
`),t+=`× ${n.message}`;let e=getDotPath(n);e&&(t+=`\n → at ${e}`)}return t}function checkChannelsValidity(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 checkCodecsValidity(e){if(e.length===0)throw Error(`At least one codec must be provided`);e.forEach(e=>{checkChannelsValidity(e.getChannels(),e.name)}),e.forEach((t,n)=>{if(e.filter((e,t)=>t!==n).some(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,r={};return e.forEach(e=>{e.getChannels().forEach(e=>{let t=[e.start,e.end],i=e.adjustMeasurementRangeDisallowed??!1;if(n.has(e.name)){let a=n.get(e.name);if(a[0]!==t[0]||a[1]!==t[1])throw Error(`Channel ${e.name} has inconsistent ranges across codecs: ${JSON.stringify(a)} vs ${JSON.stringify(t)}`);let o=r[e.name];if(o!==i)throw Error(`Channel ${e.name} has inconsistent adjustMeasurementRangeDisallowed settings across codecs: ${o} vs ${i}`)}else n.set(e.name,t),r[e.name]=i})}),r}function createFPortSchema(){return pipe(number(),minValue(1),maxValue(255),integer())}function createRecvTimeSchema(){return optional(string())}function createUplinkInputSchema(){return object({bytes:array(pipe(number(),minValue(0),maxValue(255),integer())),fPort:optional(pipe(number(),minValue(1),maxValue(224),integer())),recvTime:optional(string())},"Uplink input should be an object with `bytes` and optional `fPort` and `recvTime` properties.")}function createHexUplinkInputSchema(){return pipe(union([object({bytes:pipe(string()),fPort:optional(createFPortSchema()),recvTime:createRecvTimeSchema()}),string()]),transform(e=>typeof e==`string`?{bytes:e}:e))}function nstr(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=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 getRoundingDecimals(e,t){let n=t??4;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 hexStringToIntArray(e){let t=e.replaceAll(` `,``);t=t.startsWith(`0x`)?t.slice(2):t;let n=safeParse(pipe(string(),hexadecimal()),t);if(!n.success)return null;let r=[];for(let e=0;e<n.output.length;e+=2){let t=Number.parseInt(n.output.slice(e,e+2),16);r.push(t)}return r}function percentageToValue(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 TULIPValueToValue(e,t){return percentageToValue((e-2500)*100/1e4+0,t)}function slopeValueToValue(e,t){if(e<0||e>1e4)throw RangeError(`Slope value must be between 0 and 10_000, is ${e}`);let n=e/100,r=t.end-t.start;return n/100*r}function roundValue(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=nstr(e+5*2**-52,{maxDecimals:t});return n===``?0:Number.parseFloat(n)}function intTuple4ToFloat32(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 intTuple4ToFloat32WithThreshold(e,t=3){t=Math.max(0,Math.floor(t));let n=intTuple4ToFloat32(e);return Number.parseFloat(nstr(n,{threshold:t}))}function defineParser(e){let{codecs:t,throwOnMultipleDecode:n=!0,parserName:r}=e,i=getRoundingDecimals(e.roundingDecimals),a=checkCodecsValidity(e.codecs);function o(e){return{errors:[s(e)]}}function s(e){return`${r} (JS): ${e}`}function c(e){let r;if(t.forEach(t=>{if(t.canTryDecode(e)){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 l(e){try{let t=safeParse(createUplinkInputSchema(),e);if(!t.success)throw Error(`Input is not a valid for decoding. Check your input data.`);let n=c(t.output);return n.warnings&&=n.warnings.map(s),n}catch(t){return t instanceof Error?o(t.message):o(`Unknown error occurred during decoding in parser ${r} with input ${JSON.stringify(e)}`)}}function u(e){let t=safeParse(createHexUplinkInputSchema(),e);if(!t.success)return o(`Input is not a valid for decoding. Check your input data.`);let n=hexStringToIntArray(t.output.bytes);return n?l({bytes:n,fPort:t.output.fPort,recvTime:t.output.recvTime}):o(`Input bytes is not a valid hexadecimal string.`)}function d(e){try{let n=t.find(t=>t.protocol===e.protocol);if(!n)throw Error(`Codec with protocol ${e.protocol} not found in parser. Available protocols: ${t.map(e=>e.protocol).join(`, `)}`);if(!(`encode`in n))throw Error(`Codec with protocol ${e.protocol} does not support encoding. Input could not be encoded.`);return n.encode(e.input)}catch(t){return t instanceof Error?o(t.message):o(`Unknown error occurred during encoding in parser ${r} with input ${JSON.stringify(e)}`)}}function f(e){try{let n=t.find(t=>t.protocol===e.protocol);if(!n)throw Error(`Codec with protocol ${e.protocol} not found in parser. Available protocols: ${t.map(e=>e.protocol).join(`, `)}`);if(!(`encodeMultiple`in n))throw Error(`Codec with protocol ${e.protocol} does not support multiple encoding. Input could not be encoded.`);return n.encodeMultiple(e.input)}catch(t){return t instanceof Error?o(t.message):o(`Unknown error occurred during multiple encoding in parser ${r} with input ${JSON.stringify(e)}`)}}return{decodeUplink:l,decodeHexUplink:u,encodeDownlink:d,encodeMultipleDownlinks:f,adjustMeasuringRange:(e,n)=>{if(!(e in a))throw Error(`Channel ${e} does not exist in parser ${r}. Cannot adjust measuring range.`);if(a[e])throw Error(`Channel ${e} does not allow adjusting the measuring range in parser ${r}.`);t.forEach(t=>{t.adjustMeasuringRange(e,n)})},adjustRoundingDecimals:e=>{let n=getRoundingDecimals(e,i);t.forEach(e=>{e.adjustRoundingDecimals(n)})}}}function defineTULIP2Codec(e){let t=`${e.deviceName}TULIP2`,n=getRoundingDecimals(e.roundingDecimals);checkChannelsValidity(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`)}function a(){return e.channels.map(e=>_objectSpread2({end:e.end,name:e.name,start:e.start},e.adjustMeasurementRangeDisallowed?{adjustMeasurementRangeDisallowed:!0}:{}))}let s={name:t,protocol:`TULIP2`,getChannels:a,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=getRoundingDecimals(e,n)}};return e.encoderFactory&&(s.encode=e.encoderFactory({getChannels:()=>e.channels})),e.multipleEncodeFactory&&(s.encodeMultiple=e.multipleEncodeFactory({getChannels:()=>e.channels})),s}function createConfigurationIdSchema(e){return optional(pipe(number(`configurationId needs to be a number`),minValue(1,`configurationId needs to be at least 1`),maxValue(e,`configurationId needs to be at most ${e}`),integer(`configurationId needs to be an integer`)))}function createByteLimitSchema(){return optional(pipe(number(),minValue(0),integer()))}function createGenericTULIP2DownlinkActionSchema(e){let t=e.meta?.configurationId??!0,n=e.meta?.byteLimit??!0,r=e.extension??{};return object(_objectSpread2(t&&n?{deviceAction:literal(e.action),configurationId:createConfigurationIdSchema(e.maxConfigId),byteLimit:createByteLimitSchema()}:t?{deviceAction:literal(e.action),configurationId:createConfigurationIdSchema(e.maxConfigId)}:n?{deviceAction:literal(e.action),byteLimit:createByteLimitSchema()}:{deviceAction:literal(e.action)},r))}function createTULIP2DownlinkActionSchemaFactory(e){return t=>createGenericTULIP2DownlinkActionSchema({action:t.action,maxConfigId:e,extension:t.extension,meta:t.meta})}function createTulip2DownlinkMainConfigurationSchema(e){let t={publicationFactorWhenAlarm:pipe(number(),minValue(1),maxValue(2880),integer()),publicationFactorWhenNoAlarm:pipe(number(),minValue(1),maxValue(2880),integer())};return e.mainConfigBLE&&Object.assign(t,{isBLEEnabled:boolean()}),e.mainConfigSingleMeasuringRate?Object.assign(t,{measuringRate:pipe(number(),minValue(60),maxValue(86400),integer())}):Object.assign(t,{measuringRateWhenNoAlarm:pipe(number(),minValue(60),maxValue(86400),integer()),measuringRateWhenAlarm:pipe(number(),minValue(60),maxValue(86400),integer())}),object(t)}function createTulip2DownlinkChannelSchema(e,t,n){let r=e.end-e.start,i=n?.deadBandMaxSpanFactor??1,a=n?.slopeMaxSpanFactor??1,o=n?.measureOffsetMinSpanFactor??1,s=n?.measureOffsetMaxSpanFactor??1,c={alarms:optional(object({deadBand:pipe(number(),minValue(0),maxValue(r*i),transform(e=>Math.round(e/r*100*100))),lowThreshold:optional(pipe(number(),minValue(e.start),maxValue(e.end),transform(t=>Math.round((t-e.start)/r*100*100+2500)))),highThreshold:optional(pipe(number(),minValue(e.start),maxValue(e.end),transform(t=>Math.round((t-e.start)/r*100*100+2500)))),lowThresholdWithDelay:optional(object({value:pipe(number(),minValue(e.start),maxValue(e.end),transform(t=>Math.round((t-e.start)/r*100*100+2500))),delay:pipe(number(),minValue(0),maxValue(65535),integer())})),highThresholdWithDelay:optional(object({value:pipe(number(),minValue(e.start),maxValue(e.end),transform(t=>Math.round((t-e.start)/r*100*100+2500))),delay:pipe(number(),minValue(0),maxValue(65535),integer())})),risingSlope:optional(pipe(number(),minValue(0),maxValue(r*a),transform(e=>Math.round(e/r*100*100)))),fallingSlope:optional(pipe(number(),minValue(0),maxValue(r*a),transform(e=>Math.round(e/r*100*100))))}))};return t.channelsStartupTime&&Object.assign(c,{startUpTime:optional(pipe(number(),minValue(.1),maxValue(15),transform(e=>Math.round(e*10))))}),t.channelsMeasureOffset&&Object.assign(c,{measureOffset:optional(pipe(number(),minValue(-o*r),maxValue(s*r),transform(e=>Math.round(e/r*100*100))))}),object(c)}function createTULIP2DownlinkConfigurationActionSchema(e,t,n){let r=createTULIP2DownlinkActionSchemaFactory(t.maxConfigId),i=new Set(t.channelsBooleanOnly??[]),a=e.reduce((e,r)=>{let a=`channel${r.channelId}`;return i.has(a)?(e[a]=optional(union([literal(!1),literal(!0)])),e):(e[a]=optional(union([literal(!1),literal(!0),createTulip2DownlinkChannelSchema(r,t,n)])),e)},{});return r({action:`configuration`,extension:_objectSpread2({mainConfiguration:optional(createTulip2DownlinkMainConfigurationSchema(t))},a)})}function createDownlinkResetToFactorySchema(){return object({deviceAction:literal(`resetToFactory`)})}function createDownlinkResetBatteryIndicatorSchema(e){return createTULIP2DownlinkActionSchemaFactory(e.maxConfigId)({action:`resetBatteryIndicator`,meta:{byteLimit:!1}})}function createTULIP2DownlinkSchema(e,t,n,r){return variant(`deviceAction`,[createDownlinkResetToFactorySchema(),createTULIP2DownlinkConfigurationActionSchema(e,t,r),...n??[]])}function validateTULIP2DownlinkInput(e,t,n,r,i){let a=safeParse(createTULIP2DownlinkSchema(t,n,r,i),e);if(!a.success)throw Error(summarize(a.issues));return a.output}function createGD20WTULIP2Channels(){return[{channelId:0,name:`channel0`,start:0,end:12},{channelId:1,name:`channel1`,start:-1.013,end:10.987},{channelId:2,name:`channel2`,start:0,end:85.7879104614},{channelId:3,name:`channel3`,start:-1.013,end:14.7351512909},{channelId:4,name:`channel4`,start:0,end:15.7481508255},{channelId:5,name:`channel5`,start:-40,end:80}]}const ALARM_EVENTS={triggered:0,disappeared:1},PROCESS_ALARM_TYPES={"low threshold":0,"high threshold":1,"falling slope":2,"rising slope":3,"low threshold with delay":4,"high threshold with delay":5},SENSOR_TECHNICAL_ALARMS_BY_ID={0:`modbus sensor communication error`,1:`internal pressure sensor signal above upper limit`,3:`internal temperature sensor signal below lower limit (< -40°C | -40°F)`,4:`internal temperature sensor signal above upper limit (> 80°C | 178°F)`,5:`communication error with internal pressure or temperature sensor`,6:`liquefaction of SF6 detected (internal sensor)`,7:`gas density above upper limit (based on the full scale of the density measuring range in bar abs. at 20°C | 68°F)`,10:`recurring modbus communication error`},SENSOR_TECHNICAL_ALARM_VALID_BITS=[0,1,3,4,5,6,7,10],DEVICE_ALARMS_BY_ID={0:`low battery`,2:`duty cycle alarm`,3:`configuration error`,8:`device specific alarm`,9:`device specific alarm`,10:`device specific alarm`,11:`device specific alarm`,12:`device specific alarm`,13:`device specific alarm`,14:`device specific alarm`,15:`device specific alarm`},DEVICE_ALARM_VALID_BITS=[0,2,3,8,9,10,11,12,13,14,15],CONFIGURATION_STATUS_BY_ID={2:`configuration successful`,3:`configuration rejected`,4:`configuration discarded`,6:`command success`,7:`command failed`},UNITS_BY_ID={1:`°C`,2:`°F`,3:`K`,7:`bar`,10:`Pa`,12:`kPa`,13:`MPa`,14:`Psi`,17:`N/cm²`,110:`kg/m³`,115:`g/l`},MEASURANDS_BY_ID={1:`Temperature`,3:`Pressure gauge`,4:`Pressure absolute`,23:`Density`,24:`Density (gauge pressure at 20 °C)`,25:`Density (absolute pressure at 20 °C)`};Object.keys(MEASURANDS_BY_ID).map(e=>Number.parseInt(e)),Object.values(MEASURANDS_BY_ID),Object.keys(UNITS_BY_ID).map(e=>Number.parseInt(e)),Object.values(UNITS_BY_ID),Object.values(PROCESS_ALARM_TYPES),Object.values(ALARM_EVENTS),Object.values(SENSOR_TECHNICAL_ALARMS_BY_ID),Object.values(DEVICE_ALARMS_BY_ID),Object.keys(CONFIGURATION_STATUS_BY_ID).map(Number),Object.values(CONFIGURATION_STATUS_BY_ID),createGD20WTULIP2Channels().map(e=>e.channelId),createGD20WTULIP2Channels().map(e=>e.name);function getConfigurationChannelSchema(){return optional(union([literal(!0),object({alarms:optional(literal(!0))})]))}function createGD20WTULIP2GetConfigurationSchema(){return createTULIP2DownlinkActionSchemaFactory(255)({action:`getConfiguration`,extension:{mainConfiguration:optional(literal(!0)),channel0:getConfigurationChannelSchema(),channel1:getConfigurationChannelSchema(),channel2:getConfigurationChannelSchema(),channel3:getConfigurationChannelSchema(),channel4:getConfigurationChannelSchema(),channel5:getConfigurationChannelSchema()}})}const GD20W_DOWNLINK_FEATURE_FLAGS={maxConfigId:255,channelsStartupTime:!1,channelsMeasureOffset:!1,mainConfigBLE:!1,mainConfigSingleMeasuringRate:!1},GD20W_COMMANDS={RESET_FACTORY:1,SET_MAIN_CONFIG:2,GET_MAIN_CONFIG:4,GENERAL_DEVICE_COMMAND:5,ENABLE_DISABLE_CHANNEL:17,SET_PROCESS_ALARM:32,GET_PROCESS_ALARM:64},GD20W_GENERAL_DEVICE_COMMANDS={RESET_BATTERY_INDICATOR:0};function getChannelKeys(e){return Object.keys(e).filter(e=>/^channel\d+$/.test(e))}function formatMainConfigurationInput(e){return e.mainConfiguration}function formatDisableChannelInput(e){let t={},n=!1,r=getChannelKeys(e);for(let i of r)e[i]===!1&&(t[i]=!0,n=!0);return n?t:void 0}function formatProcessAlarmInput(e){let t={},n=!1,r=getChannelKeys(e);for(let i of r){let r=e[i];r&&(r===!0?(t[i]=!0,n=!0):typeof r==`object`&&`alarms`in r&&typeof r.alarms==`object`&&(t[i]=r.alarms,n=!0))}return n?t:void 0}function ffd(e,t){if(t=Math.floor(t),t<=0)throw Error(`Limit must be greater than 0`);let n=[];return e.sort((e,t)=>t.length-e.length).forEach(e=>{let r=e.length;if(r>t)throw Error(`Packet is too big to fit in any bin`);let i=!1;for(let a of n)if(t-a.length>=r){a.push(...e),i=!0;break}i||n.push(e)}),n}function buildDownlinkFrame(e,t){if(e.length===0)throw Error(`No Downlink commands were provided to build the downlink frame.`);let n=[t.configId];for(let t of e)n.push(...t);if(n.length===0)throw Error(`No bytes were generated for the downlink frame.`);if(n.length>t.byteLimit)throw Error(`Downlink frame exceeds byte limit of ${t.byteLimit} bytes (got ${n.length} bytes).`);return n}function buildDownlinkFrames(e,t){if(e.length===0)throw Error(`No Downlink commands were provided for encoding.`);let n=ffd(e,t.byteLimit-1),r=[],i=t.configId;for(let e of n)r.push([i,...e]),i++,i>t.maxConfigId&&(i=t.configId);return r}function formatDownlinkOutput(e){return{bytes:e,fPort:1}}function formatMultipleDownlinkOutput(e){return{frames:e,fPort:1}}function pushUint32(e,t){e.push(t>>24&255,t>>16&255,t>>8&255,t&255)}function pushUint16(e,t){e.push(t>>8&255,t&255)}function buildResetFactoryCommand(){return[GD20W_COMMANDS.RESET_FACTORY]}function buildResetBatteryCommand(){return[GD20W_COMMANDS.GENERAL_DEVICE_COMMAND,GD20W_GENERAL_DEVICE_COMMANDS.RESET_BATTERY_INDICATOR]}function buildGetMainConfigCommand(){return[GD20W_COMMANDS.GET_MAIN_CONFIG]}function buildGetProcessAlarmConfigCommand(e){return[GD20W_COMMANDS.GET_PROCESS_ALARM,e]}const MAX_MEASURING_RATE_SECONDS=604800;function buildGD20WMainConfigCommand(e){if(!e)return[];if(e.measuringRateWhenNoAlarm<60||e.measuringRateWhenNoAlarm>MAX_MEASURING_RATE_SECONDS)throw Error(`measuringRateWhenNoAlarm must be between 60 and ${MAX_MEASURING_RATE_SECONDS} seconds.`);if(e.measuringRateWhenAlarm<60||e.measuringRateWhenAlarm>MAX_MEASURING_RATE_SECONDS)throw Error(`measuringRateWhenAlarm must be between 60 and ${MAX_MEASURING_RATE_SECONDS} seconds.`);let t=[GD20W_COMMANDS.SET_MAIN_CONFIG];return pushUint32(t,e.measuringRateWhenNoAlarm),pushUint16(t,e.publicationFactorWhenNoAlarm),pushUint32(t,e.measuringRateWhenAlarm),pushUint16(t,e.publicationFactorWhenAlarm),t.push(0),[t]}function buildGD20WDisableChannelCommands(e){if(!e)return[];let t=Object.keys(e).filter(t=>e[t]===!0).map(e=>{let t=Number.parseInt(e.replace(`channel`,``),10);if(Number.isNaN(t)||t<0||t>5)throw Error(`Invalid channel number ${t} in disable channel configuration. Must be between 0 and 5.`);return t});if(t.length===0)return[];let n=[GD20W_COMMANDS.ENABLE_DISABLE_CHANNEL,t.length];for(let e of t)n.push(e),n.push(0);return[n]}function buildGD20WProcessAlarmCommands(e){if(!e)return[];let t=[];return Object.keys(e).forEach(n=>{let r=Number.parseInt(n.replace(`channel`,``),10);if(Number.isNaN(r)||r<0||r>5)throw Error(`Invalid channel number ${r} in process alarm configuration. Must be between 0 and 5.`);let i=e[n],a=[GD20W_COMMANDS.SET_PROCESS_ALARM,r];if(i===!0){a.push(0,0,0),t.push(a);return}pushUint16(a,i.deadBand);let o=0;i.lowThreshold!==void 0&&(o|=128),i.highThreshold!==void 0&&(o|=64),i.fallingSlope!==void 0&&(o|=32),i.risingSlope!==void 0&&(o|=16),i.lowThresholdWithDelay!==void 0&&(o|=8),i.highThresholdWithDelay!==void 0&&(o|=4),a.push(o),i.lowThreshold!==void 0&&pushUint16(a,i.lowThreshold),i.highThreshold!==void 0&&pushUint16(a,i.highThreshold),i.fallingSlope!==void 0&&pushUint16(a,i.fallingSlope),i.risingSlope!==void 0&&pushUint16(a,i.risingSlope),i.lowThresholdWithDelay!==void 0&&(pushUint16(a,i.lowThresholdWithDelay.value),pushUint16(a,i.lowThresholdWithDelay.delay)),i.highThresholdWithDelay!==void 0&&(pushUint16(a,i.highThresholdWithDelay.value),pushUint16(a,i.highThresholdWithDelay.delay)),t.push(a)}),t}function GD20WTULIP2EncodeHandler(e,t=!1){switch(e.deviceAction){case`resetToFactory`:{let e=encodeResetToFactory();return t?formatMultipleDownlinkOutput([e]):formatDownlinkOutput(e)}case`resetBatteryIndicator`:{let n=encodeResetBatteryIndicator(e);return t?formatMultipleDownlinkOutput([n]):formatDownlinkOutput(n)}case`getConfiguration`:return encodeGetConfiguration(e,t);case`configuration`:return encodeDownlinkConfiguration(e,t);default:throw Error(`Unknown device action: ${e.deviceAction}`)}}function encodeResetToFactory(){return buildDownlinkFrame([buildResetFactoryCommand()],{configId:0,maxConfigId:GD20W_DOWNLINK_FEATURE_FLAGS.maxConfigId,byteLimit:1/0})}function encodeResetBatteryIndicator(e){let t=e.configurationId??1;return buildDownlinkFrame([buildResetBatteryCommand()],{configId:t,maxConfigId:GD20W_DOWNLINK_FEATURE_FLAGS.maxConfigId,byteLimit:1/0})}function encodeDownlinkConfiguration(e,t){let n=e.configurationId??1,r=e.byteLimit??51,i=[...buildGD20WMainConfigCommand(formatMainConfigurationInput(e)),...buildGD20WDisableChannelCommands(formatDisableChannelInput(e)),...buildGD20WProcessAlarmCommands(formatProcessAlarmInput(e))];if(i.length===0)throw Error(`No configuration commands were provided for the downlink frame.`);return t?formatMultipleDownlinkOutput(buildDownlinkFrames(i,{configId:n,maxConfigId:GD20W_DOWNLINK_FEATURE_FLAGS.maxConfigId,byteLimit:r})):formatDownlinkOutput(buildDownlinkFrame(i,{configId:n,maxConfigId:GD20W_DOWNLINK_FEATURE_FLAGS.maxConfigId,byteLimit:r}))}function encodeGetConfiguration(e,t){let n=[];e.mainConfiguration&&n.push(buildGetMainConfigCommand());let r=(e,t)=>{if(t===!0){n.push(buildGetProcessAlarmConfigCommand(e));return}t&&typeof t==`object`&&`alarms`in t&&t.alarms&&n.push(buildGetProcessAlarmConfigCommand(e))};if(r(0,e.channel0),r(1,e.channel1),r(2,e.channel2),r(3,e.channel3),r(4,e.channel4),r(5,e.channel5),n.length===0)throw Error(`No get configuration commands were provided.`);let i=e.configurationId??1,a=e.byteLimit??1/0,o=buildDownlinkFrame(n,{configId:i,maxConfigId:GD20W_DOWNLINK_FEATURE_FLAGS.maxConfigId,byteLimit:a});return t?formatMultipleDownlinkOutput([o]):formatDownlinkOutput(o)}const ERROR_VALUE=65535,handleDataMessage=(e,t)=>{if(e.bytes.length<5)throw Error(`Data message (0x01/0x02) requires at least 5 bytes, but received ${e.bytes.length} bytes`);let n=(e.bytes.length-2)%3!=0,r=e.bytes[0],i=e.bytes[1],a=[];for(let t=2;t+2<e.bytes.length;t+=3)a.push([e.bytes[t],e.bytes[t+1],e.bytes[t+2]]);let o={data:{messageType:r,configurationId:i,measurements:{channels:a.map(([e,n,r])=>{let i=getChannelById(t.channels,e),a=n<<8|r,o=a===ERROR_VALUE?ERROR_VALUE:roundValue(TULIPValueToValue(a,i),t.roundingDecimals);return{channelId:i.channelId,channelName:i.name,value:o}})}}};return n&&(o.warnings=o.warnings??[],o.warnings.push(`Data message contains an invalid number of bytes. Bytes must have a length of 2 + 3n (n = 1, 2, 3,...). Data might been decoded incorrectly. Contains ${e.bytes.length} bytes.`)),o},handleProcessAlarmMessage=(e,t)=>{if(e.bytes.length<6||(e.bytes.length-2)%4!=0)throw Error(`Process alarm message (0x03) requires at least 6 bytes (and target byte count 4n+2), but received ${e.bytes.length} bytes`);let n=e.bytes[1],r=[];for(let n=2;n<e.bytes.length;n+=4){let i=e.bytes[n],a=getChannelById(t.channels,i),o=e.bytes[n+1],{sense:s,alarmType:c}=getProcessAlarmType(o),l=e.bytes[n+2],u=e.bytes[n+3],d=l<<8|u,f=c===PROCESS_ALARM_TYPES[`falling slope`]||c===PROCESS_ALARM_TYPES[`rising slope`]?roundValue(slopeValueToValue(d,a),t.roundingDecimals):roundValue(TULIPValueToValue(d,a),t.roundingDecimals);r.push({channelName:a.name,channelId:a.channelId,alarmType:c,alarmTypeName:getProcessAlarmTypeName(c),event:s,eventName:getProcessAlarmEventName(s),value:f})}return{data:{messageType:3,configurationId:n,processAlarms:r}}},handleSensorTechnicalAlarmMessage=(e,t)=>{let n=[];e.bytes.length>5&&n.push(`Sensor technical alarm message contains more than 5 bytes. Data might have been decoded incorrectly. Contains ${e.bytes.length} bytes.`);let r=e.bytes[1],i=e.bytes[2],a=getChannelById(t.channels,i),o=e.bytes[3]<<8|e.bytes[4],s=[],c=[];for(let e=0;e<16;e++)o&1<<e&&(SENSOR_TECHNICAL_ALARM_VALID_BITS.includes(e)?s.push(e):c.push(e));c.length>0&&n.push(`Sensor technical alarm message contains invalid alarm bits: ${c.join(`, `)}. Only bits ${SENSOR_TECHNICAL_ALARM_VALID_BITS.join(`, `)} are valid.`);let l={data:{messageType:4,configurationId:r,sensorTechnicalAlarms:s.map(e=>({channelName:a.name,channelId:i,alarmType:e,alarmDescription:SENSOR_TECHNICAL_ALARMS_BY_ID[e]}))}};return n.length>0&&(l.warnings=n),l},handleDeviceAlarmMessage=e=>{if(e.bytes.length<4)throw Error(`Device alarm message (0x05) requires 4 bytes, but received ${e.bytes.length} bytes`);let t=[];e.bytes.length>4&&t.push(`Device alarm message contains more than 4 bytes. Data might have been decoded incorrectly. Contains ${e.bytes.length} bytes.`);let n=e.bytes[1],r=e.bytes[2]<<8|e.bytes[3],i=[],a=[];for(let e=0;e<16;e++)r&1<<e&&(DEVICE_ALARM_VALID_BITS.includes(e)?i.push(e):a.push(e));a.length>0&&t.push(`Sensor technical alarm message contains invalid alarm bits: ${a.join(`, `)}. Only bits ${DEVICE_ALARM_VALID_BITS.join(`, `)} are valid.`);let o={data:{messageType:5,configurationId:n,deviceAlarms:i.map(e=>({alarmType:e,alarmDescription:DEVICE_ALARMS_BY_ID[e]}))}};return t.length>0&&(o.warnings=t),o},handleConfigurationStatusMessage=e=>{let t=e.bytes[1],n=e.bytes[2]>>4;if(!(n in CONFIGURATION_STATUS_BY_ID))throw Error(`Unknown status ${n} in configuration status message`);let r=e.bytes[3];if(r!==4&&r<64)throw Error(`Unknown command type ${r} in configuration status message`);let i=[];if(r===4){if(e.bytes.length<17)throw Error(`Configuration status message contains an invalid length for main configuration: ${e.bytes.length}`);e.bytes.length>17&&i.push(`Configuration status message for main configuration contains more than 17 bytes. Data might have been decoded incorrectly. Contains ${e.bytes.length} bytes.`)}else{if(e.bytes.length<8)throw Error(`Configuration status message contains an invalid length for channel configuration: ${e.bytes.length}`);e.bytes.length>16&&i.push(`Configuration status message for channel configuration contains more than 16 bytes. Data might have been decoded incorrectly. Contains ${e.bytes.length} bytes.`)}let a=CONFIGURATION_STATUS_BY_ID[n],s=r===4?{commandType:4,mainConfiguration:parseMainConfigurationData(e,i)}:{commandType:r,channelConfiguration:parseChannelConfigurationData(e,i)},c={data:{messageType:6,configurationId:t,configurationStatus:_objectSpread2({status:n,statusDescription:a},s)}};return i.length>0&&(c.warnings=i),c};function createChannelIdentification(e,t,n){if(!(e in MEASURANDS_BY_ID))throw Error(`Unknown measurand ${e} for channel ${n} in device identification message`);if(!(t in UNITS_BY_ID))throw Error(`Unknown unit ${t} for channel ${n} in device identification message`);return{measurandId:e,measurand:MEASURANDS_BY_ID[e],unitId:t,unit:UNITS_BY_ID[t]}}const handleDeviceIdentificationMessage=e=>{let t=[];if(e.bytes.length<39)throw Error(`Device identification message (0x07) requires at least 39 bytes, but received ${e.bytes.length} bytes`);e.bytes.length>39&&t.push(`Device identification message contains more than 39 bytes. Data might been decoded incorrectly. Contains ${e.bytes.length} bytes.`);let n=e.bytes[1],r=e.bytes[2];if(r!==21)throw Error(`Invalid productId ${r} in device identification message. Expected 21 (GD20W).`);let i=e.bytes[3];if(i!==64)throw Error(`Unknown productSubId ${i} in device identification message. Only LoRaWAN (0) is supported.`);let a=`${e.bytes[4]>>4}.${e.bytes[4]&15}.${e.bytes[5]}`,o=`${e.bytes[6]>>4}.${e.bytes[6]&15}.${e.bytes[7]}`,s=checkSemVerVersions([a,o]);s&&t.push(...s);let c={data:{messageType:7,configurationId:n,deviceIdentification:{productId:21,productSubId:64,wirelessModuleFirmwareVersion:a,wirelessModuleHardwareVersion:o,serialNumber:String.fromCharCode(...e.bytes.slice(8,18)),channels:{channel0:createChannelIdentification(e.bytes[19],e.bytes[20],0),channel1:createChannelIdentification(e.bytes[21],e.bytes[22],1),channel2:createChannelIdentification(e.bytes[23],e.bytes[24],2),channel3:createChannelIdentification(e.bytes[25],e.bytes[26],3),channel4:createChannelIdentification(e.bytes[27],e.bytes[28],4),channel5:createChannelIdentification(e.bytes[29],e.bytes[30],5)},gasMixtures:{SF6:e.bytes[31],N2:e.bytes[32],CF4:e.bytes[33],O2:e.bytes[34],C02:e.bytes[35],Novec4710:e.bytes[36],He:e.bytes[37],Ar:e.bytes[38]}}}};return t.length>0&&(c.warnings=t),c},handleDeviceStatisticsMessage=e=>{if(e.bytes.length<3)throw Error(`Keep alive message (0x08) requires at least 3 bytes, but received ${e.bytes.length} bytes`);let t=[];e.bytes.length>3&&t.push(`Keep alive message contains more than 3 bytes. Data might been decoded incorrectly. Contains ${e.bytes.length} bytes.`);let n=e.bytes[1],r=e.bytes[2],i={data:{messageType:8,configurationId:n,batteryLevelIndicator:{restartedSinceLastKeepAlive:(r&128)==128,batteryLevelPercent:r&127,batteryLevelCalculationError:(r&127)==127,batteryPresent:(r&255)!=0}}};return t.length>0&&(i.warnings=t),i},handleExtendedDeviceIdentificationMessage=e=>{let t=[];if(e.bytes.length<50)throw Error(`Extended device identification message (0x09) requires at least 50 bytes, but received ${e.bytes.length} bytes`);e.bytes.length>50&&t.push(`Extended device identification message contains more than 50 bytes. Data might been decoded incorrectly. Contains ${e.bytes.length} bytes.`);let n={data:{messageType:9,configurationId:e.bytes[1],channelRanges:{channel0:{min:readFloat32(e.bytes,2),max:readFloat32(e.bytes,6)},channel1:{min:readFloat32(e.bytes,10),max:readFloat32(e.bytes,14)},channel2:{min:readFloat32(e.bytes,18),max:readFloat32(e.bytes,22)},channel3:{min:readFloat32(e.bytes,26),max:readFloat32(e.bytes,30)},channel4:{min:readFloat32(e.bytes,34),max:readFloat32(e.bytes,38)},channel5:{min:readFloat32(e.bytes,42),max:readFloat32(e.bytes,46)}}}};return t.length>0&&(n.warnings=t),n},gd20wEncoderFactory=e=>{let t=GD20W_DOWNLINK_FEATURE_FLAGS;return n=>GD20WTULIP2EncodeHandler(validateTULIP2DownlinkInput(n,e.getChannels(),t,[createDownlinkResetBatteryIndicatorSchema(t),createGD20WTULIP2GetConfigurationSchema()]))},gd20wMultipleEncodeFactory=e=>{let t=GD20W_DOWNLINK_FEATURE_FLAGS;return n=>GD20WTULIP2EncodeHandler(validateTULIP2DownlinkInput(n,e.getChannels(),t,[createDownlinkResetBatteryIndicatorSchema(t),createGD20WTULIP2GetConfigurationSchema()]),!0)};function createTULIP2GD20WCodec(){return defineTULIP2Codec({deviceName:GD20W_NAME,roundingDecimals:3,channels:createGD20WTULIP2Channels(),encoderFactory:gd20wEncoderFactory,multipleEncodeFactory:gd20wMultipleEncodeFactory,handlers:{1:handleDataMessage,2:handleDataMessage,3:handleProcessAlarmMessage,4:handleSensorTechnicalAlarmMessage,5:handleDeviceAlarmMessage,6:handleConfigurationStatusMessage,7:handleDeviceIdentificationMessage,8:handleDeviceStatisticsMessage,9:handleExtendedDeviceIdentificationMessage}})}function getChannelById(e,t){let n=e.find(e=>e.channelId===t);if(!n)throw Error(`Unknown channel id ${t}`);return n}function getProcessAlarmType(e){let t=(e&128)>>7,n=e&7;if(!Number.isInteger(n)||n<0||n>5)throw Error(`Unknown alarmType ${n} in process alarm message`);return{sense:t,alarmType:n}}function getProcessAlarmTypeName(e){let t=Object.entries(PROCESS_ALARM_TYPES).find(([,t])=>t===e);if(!t)throw Error(`Unknown alarmType ${e} in process alarm message`);return t[0]}function getProcessAlarmEventName(e){let t=Object.entries(ALARM_EVENTS).find(([,t])=>t===e);if(!t)throw Error(`Unknown event ${e} in process alarm message`);return t[0]}function parseMainConfigurationData(e,t){let n=e.bytes[4]<<24|e.bytes[5]<<16|e.bytes[6]<<8|e.bytes[7],r=e.bytes[8]<<8|e.bytes[9],i=e.bytes[10]<<24|e.bytes[11]<<16|e.bytes[12]<<8|e.bytes[13],a=e.bytes[14]<<8|e.bytes[15];return n!==0&&n%r!==0&&t.push(`Acquisition time alarms off must be a multiple of publication time factor alarms off`),i!==0&&i%a!==0&&t.push(`Acquisition time alarms on must be a multiple of publication time factor alarms on`),{acquisitionTimeAlarmsOff:n===0?`unauthorized`:n,publicationTimeFactorAlarmsOff:r===0?`unauthorized`:r,acquisitionTimeAlarmsOn:i===0?`unauthorized`:i,publicationTimeFactorAlarmsOn:a===0?`unauthorized`:a}}function parseChannelConfigurationData(e,t){let n=e.bytes[4];[0,1,2,3,4,5].includes(n)||t.push(`Invalid sensor or channel id`);let r=e.bytes[5]<<8|e.bytes[6],i=e.bytes[7];i&3&&t.push(`Reserved alarm flags 0 and/or 1 are set`);let a={isAlarm1Enabled:!!(i&128),isAlarm2Enabled:!!(i&64),isAlarm3Enabled:!!(i&32),isAlarm4Enabled:!!(i&16),isAlarm5Enabled:!!(i&8),isAlarm6Enabled:!!(i&4)},o=[];for(let t=8;t<e.bytes.length;t+=2)o.push(e.bytes[t]<<8|e.bytes[t+1]);let s=0,c={sensorOrChannelId:n,deadBand:r};return a.isAlarm1Enabled&&(c.alarm1Threshold=o[s++]),a.isAlarm2Enabled&&(c.alarm2Threshold=o[s++]),a.isAlarm3Enabled&&(c.alarm3Slope=o[s++]),a.isAlarm4Enabled&&(c.alarm4Slope=o[s++]),a.isAlarm5Enabled&&(c.alarm5Threshold=o[s++],c.alarm5Period=o[s++]),a.isAlarm6Enabled&&(c.alarm6Threshold=o[s++],c.alarm6Period=o[s++]),c}function checkSemVerVersions(e){let t=[];for(let n of e){let e=n.split(`.`);if(e.length!==3)throw Error(`Invalid semantic version format: ${n}`);let[r,i,a]=e,o=Number.parseInt(r),s=Number.parseInt(i),c=Number.parseInt(a);if(o.toString()!==r||s.toString()!==i||c.toString()!==a)throw Error(`Semantic version contains non-integer value: ${n}`);(o<0||o>16)&&t.push(`Major version ${o} is out of range for semver ${n}`),(s<0||s>16)&&t.push(`Minor version ${s} is out of range for semver ${n}`),(c<0||c>255)&&t.push(`Patch version ${c} is out of range for semver ${n}`)}return t.length>0?t:null}function readFloat32(e,t){return intTuple4ToFloat32WithThreshold([e[t],e[t+1],e[t+2],e[t+3]])}const GD20W_NAME=`GD-20-W`;function useParser(){return defineParser({parserName:GD20W_NAME,codecs:[createTULIP2GD20WCodec()]})}var require_es7_array_prototype_includes=__commonJSMin((()=>{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}})})),require_is_implemented$9=__commonJSMin(((e,t)=>{t.exports=function(){var e=Number.isInteger;return typeof e==`function`?!e(`23`)&&e(34)&&!e(32.34):!1}})),require_shim$8=__commonJSMin(((e,t)=>{t.exports=function(e){return typeof e==`number`?e%1==0:!1}})),require_implement$2=__commonJSMin((()=>{require_is_implemented$9()()||Object.defineProperty(Number,`isInteger`,{value:require_shim$8(),configurable:!0,enumerable:!1,writable:!0})})),require_is_implemented$8=__commonJSMin(((e,t)=>{t.exports=function(){return typeof globalThis!=`object`||!globalThis?!1:globalThis.Array===Array}})),require_implementation=__commonJSMin(((e,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{return n()}try{return __global__||n()}finally{delete Object.prototype.__global__}})()})),require_global_this=__commonJSMin(((e,t)=>{t.exports=require_is_implemented$8()()?globalThis:require_implementation()})),require_is_implemented$7=__commonJSMin(((e,t)=>{var n=require_global_this(),r={object:!0,symbol:!0};t.exports=function(){var e=n.Symbol;return!(typeof e!=`function`||(e(`test symbol`),!r[typeof e.iterator])||!r[typeof e.toPrimitive]||!r[typeof e.toStringTag])}})),require_is$4=__commonJSMin(((e,t)=>{var n=void 0;t.exports=function(e){return e!==n&&e!==null}})),require_is$3=__commonJSMin(((e,t)=>{var n=require_is$4(),r={object:!0,function:!0,undefined:!0};t.exports=function(e){return n(e)?hasOwnProperty.call(r,typeof e):!1}})),require_is$2=__commonJSMin(((e,t)=>{var n=require_is$3();t.exports=function(e){if(!n(e))return!1;try{return e.constructor?e.constructor.prototype===e:!1}catch{return!1}}})),require_is$1=__commonJSMin(((e,t)=>{var n=require_is$2();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{return!1}return!n(e)}})),require_is=__commonJSMin(((e,t)=>{var n=require_is$1(),r=/^\s*class[\s{/}]/,i=Function.prototype.toString;t.exports=function(e){return!(!n(e)||r.test(i.call(e)))}})),require_is_implemented$6=__commonJSMin(((e,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}})),require_is_implemented$5=__commonJSMin(((e,t)=>{t.exports=function(){try{return!0}catch{return!1}}})),require_noop=__commonJSMin(((e,t)=>{t.exports=function(){}})),require_is_value=__commonJSMin(((e,t)=>{var n=require_noop()();t.exports=function(e){return e!==n&&e!==null}})),require_shim$7=__commonJSMin(((e,t)=>{var n=require_is_value(),r=Object.keys;t.exports=function(e){return r(n(e)?Object(e):e)}})),require_keys=__commonJSMin(((e,t)=>{t.exports=require_is_implemented$5()()?Object.keys:require_shim$7()})),require_valid_value=__commonJSMin(((e,t)=>{var n=require_is_value();t.exports=function(e){if(!n(e))throw TypeError(`Cannot use null or undefined`);return e}})),require_shim$6=__commonJSMin(((e,t)=>{var n=require_keys(),r=require_valid_value(),i=Math.max;t.exports=function(e,t){var a,o,s=i(arguments.length,2),c;for(e=Object(r(e)),c=function(n){try{e[n]=t[n]}catch(e){a||=e}},o=1;o<s;++o)t=arguments[o],n(t).forEach(c);if(a!==void 0)throw a;return e}})),require_assign=__commonJSMin(((e,t)=>{t.exports=require_is_implemented$6()()?Object.assign:require_shim$6()})),require_normalize_options=__commonJSMin(((e,t)=>{var n=require_is_value(),r=Array.prototype.forEach,i=Object.create,a=function(e,t){for(var n in e)t[n]=e[n]};t.exports=function(e){var t=i(null);return r.call(arguments,function(e){n(e)&&a(Object(e),t)}),t}})),require_is_implemented$4=__commonJSMin(((e,t)=>{var n=`razdwatrzy`;t.exports=function(){return typeof n.contains==`function`?n.contains(`dwa`)===!0&&n.contains(`foo`)===!1:!1}})),require_shim$5=__commonJSMin(((e,t)=>{var n=String.prototype.indexOf;t.exports=function(e){return n.call(this,e,arguments[1])>-1}})),require_contains=__commonJSMin(((e,t)=>{t.exports=require_is_implemented$4()()?String.prototype.contains:require_shim$5()})),require_d=__commonJSMin(((e,t)=>{var n=require_is$4(),r=require_is(),i=require_assign(),a=require_normalize_options(),o=require_contains(),s=t.exports=function(e,t){var r,s,c,l,u;return arguments.length<2||typeof e!=`string`?(l=t,t=e,e=null):l=arguments[2],n(e)?(r=o.call(e,`c`),s=o.call(e,`e`),c=o.call(e,`w`)):(r=c=!0,s=!1),u={value:t,configurable:r,enumerable:s,writable:c},l?i(a(l),u):u};s.gs=function(e,t,s){var c,l,u,d;return typeof e==`string`?u=arguments[3]:(u=s,s=t,t=e,e=null),n(t)?r(t)?n(s)?r(s)||(u=s,s=void 0):s=void 0:(u=t,t=s=void 0):t=void 0,n(e)?(c=o.call(e,`c`),l=o.call(e,`e`)):(c=!0,l=!1),d={get:t,set:s,configurable:c,enumerable:l},u?i(a(u),d):d}})),require_is_symbol=__commonJSMin(((e,t)=>{t.exports=function(e){return e?typeof e==`symbol`?!0:!e.constructor||e.constructor.name!==`Symbol`?!1:e[e.constructor.toStringTag]===`Symbol`:!1}})),require_validate_symbol=__commonJSMin(((e,t)=>{var n=require_is_symbol();t.exports=function(e){if(!n(e))throw TypeError(e+` is not a symbol`);return e}})),require_generate_name=__commonJSMin(((e,t)=>{var n=require_d(),r=Object.create,i=Object.definePr