function e(e,n,r){return(n=t(n))in e?Object.defineProperty(e,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[n]=r,e}function t(e){var t=n(e,`string`);return typeof t==`symbol`?t:t+``}function n(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}import{t as r}from"./chunk/Log.js";function i(e,t){let n=-2082826800;return n+=Number(e),n+=Number(t)/2**64,n}function a(e){return e===33?o.REV:e===25?o.CTRE:o.None}var o;(function(e){e[e.REV=0]=`REV`,e[e.CTRE=1]=`CTRE`,e[e.None=2]=`None`})(o||={});var s=class{constructor(t){e(this,`data`,void 0),e(this,`dataView`,void 0),e(this,`textDecoder`,new TextDecoder(`UTF-8`)),this.data=t,this.dataView=new DataView(t.buffer)}getVersion(){return this.dataView.getInt32(0)}isSupportedVersion(){return this.getVersion()===4}getTimestamp(){return i(this.dataView.getBigInt64(4),this.dataView.getBigUint64(12))}forEach(e){if(!this.isSupportedVersion())throw`Log is not a supported version`;let t=20,n=this.getTimestamp();for(;;){let r=i(this.dataView.getBigInt64(t),this.dataView.getBigUint64(t+8));t+=16;let a=this.dataView.getInt32(t);t+=4;let o=this.textDecoder.decode(this.data.subarray(t,t+a));t+=a;let s=r-n;if([`<TagVersion>`,`<time>`,`<count>`,`<flags>`,`<Code>`,`<location>`,`<stack>`].forEach(e=>{for(;o.includes(e);){let t=o.indexOf(e),n=o.indexOf(`<`,t+1);o=o.slice(0,t)+o.slice(n)}}),o=o.replaceAll(`<message> `,``),o=o.replaceAll(`<details> `,``),o=o.trim(),e({timestamp:s,text:o}),t>=this.data.length)break}}},c=class{constructor(t){e(this,`PERIOD_SECS`,.02),e(this,`data`,void 0),e(this,`dataView`,void 0),this.data=t,this.dataView=new DataView(t.buffer)}getVersion(){return this.dataView.getInt32(0)}isSupportedVersion(){return this.getVersion()===4}getTimestamp(){return i(this.dataView.getBigInt64(4),this.dataView.getBigUint64(12))}forEach(e){if(!this.isSupportedVersion())throw`Log is not a supported version`;let t=20,n=0,r=0;try{for(;;){let i=this.dataView.getUint8(t+5),s=this.dataView.getUint16(t+2)/2**8;s>20?s=r:r=s;let c={timestamp:n,tripTimeMs:this.dataView.getUint8(t)*.5,packetLoss:Math.min(Math.max(this.dataView.getInt8(t+1)*4*.01,0),1),batteryVolts:s,cpuUtilization:this.dataView.getUint8(t+4)*.5*.01,brownout:(i&128)==0,watchdog:(i&64)==0,dsTeleop:(i&32)==0,dsDisabled:(i&8)==0,robotTeleop:(i&4)==0,robotAuto:(i&2)==0,robotDisabled:(i&1)==0,canUtilization:this.dataView.getUint8(t+6)*.5*.01,wifiDb:this.dataView.getUint8(t+7)*.5,wifiMb:this.dataView.getUint16(t+8)/2**8,powerDistributionCurrents:[]};t+=10;let l=a(this.dataView.getUint8(t+3));t+=4;let u=[];switch(l){case o.REV:t+=1;let e=[];this.data.subarray(t,t+27).forEach(t=>{for(let n=0;n<8;n++)e.push((t&1<<n)!=0)}),t+=27;for(let t=0;t<20;t++){let n=Math.floor(t/3)*32+t%3*10,r=0;for(let t=0;t<10;t++)r+=e[n+t]?2**t:0;u.push(r/8)}for(let e=0;e<4;e++)u[e+20]=this.data[t+e]/16;t+=4,t+=1;break;case o.CTRE:t+=1;let n=[];this.data.subarray(t,t+21).forEach(e=>{for(let t=0;t<8;t++)n.push((e&1<<t)!=0)});for(let e=0;e<16;e++){let t=Math.floor(e/6)*64+e%6*10,r=0;for(let e=0;e<8;e++)r+=n[t+e]?2**e:0;u.push(r/8)}t+=24;break;case o.None:break}if(c.powerDistributionCurrents=u,e(c),n+=this.PERIOD_SECS,t>=this.data.length)break}}catch(e){console.error(`Problem reading DS log file, see below`),console.error(e)}}};function l(e){self.postMessage(e)}self.onmessage=async e=>{let t=e.data;if(t.type!==`start`)return;l({type:`progress`,value:1});let n=new r;if(t.data[0]!==null){let e=new c(t.data[0]);if(!e.isSupportedVersion()){l({type:`failed`});return}e.forEach(e=>{n.putNumber(`/DSLog/TripTimeMS`,e.timestamp,e.tripTimeMs),n.putNumber(`/DSLog/PacketLoss`,e.timestamp,e.packetLoss),n.putNumber(`/DSLog/BatteryVoltage`,e.timestamp,e.batteryVolts),n.putNumber(`/DSLog/CPUUtilization`,e.timestamp,e.cpuUtilization),n.putBoolean(`/DSLog/Status/Brownout`,e.timestamp,e.brownout),n.putBoolean(`/DSLog/Status/Watchdog`,e.timestamp,e.watchdog),n.putBoolean(`/DSLog/Status/DSTeleop`,e.timestamp,e.dsTeleop),n.putBoolean(`/DSLog/Status/DSDisabled`,e.timestamp,e.dsDisabled),n.putBoolean(`/DSLog/Status/RobotTeleop`,e.timestamp,e.robotTeleop),n.putBoolean(`/DSLog/Status/RobotAuto`,e.timestamp,e.robotAuto),n.putBoolean(`/DSLog/Status/RobotDisabled`,e.timestamp,e.robotDisabled),n.putNumber(`/DSLog/CANUtilization`,e.timestamp,e.canUtilization),n.putNumberArray(`/DSLog/PowerDistributionCurrents`,e.timestamp,e.powerDistributionCurrents)})}if(t.data[1]!==null){let e=new s(t.data[1]);if(!e.isSupportedVersion()){l({type:`failed`});return}e.forEach(e=>{n.putString(`/DSEvents`,e.timestamp,e.text)})}l({type:`initial`,log:n.toSerialized(),isPartial:!1})};