1 line
41 KiB
JavaScript
1 line
41 KiB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).avrbro=t()}(this,(function(){function e(){return(e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}const t=function(){function e(){}return e.prototype.then=function(t,n){const o=new e,i=this.s;if(i){const e=1&i?t:n;if(e){try{r(o,1,e(this.v))}catch(e){r(o,2,e)}return o}return this}return this.o=function(e){try{const i=e.v;1&e.s?r(o,1,t?t(i):i):n?r(o,1,n(i)):r(o,2,i)}catch(e){r(o,2,e)}},o},e}();function r(e,n,o){if(!e.s){if(o instanceof t){if(!o.s)return void(o.o=r.bind(null,e,n));1&n&&(n=o.s),o=o.v}if(o&&o.then)return void o.then(r.bind(null,e,n),r.bind(null,e,2));e.s=n,e.v=o;const i=e.o;i&&i(e)}}function n(e){return e instanceof t&&1&e.s}function o(e,o,i){for(var u;;){var a=e();if(n(a)&&(a=a.v),!a)return s;if(a.then){u=0;break}var s=i();if(s&&s.then){if(!n(s)){u=1;break}s=s.s}if(o){var f=o();if(f&&f.then&&!n(f)){u=2;break}}}var c=new t,h=r.bind(null,c,2);return(0===u?a.then(p):1===u?s.then(l):f.then(d)).then(void 0,h),c;function l(t){s=t;do{if(o&&(f=o())&&f.then&&!n(f))return void f.then(d).then(void 0,h);if(!(a=e())||n(a)&&!a.v)return void r(c,1,s);if(a.then)return void a.then(p).then(void 0,h);n(s=i())&&(s=s.v)}while(!s||!s.then);s.then(l).then(void 0,h)}function p(e){e?(s=i())&&s.then?s.then(l).then(void 0,h):l(s):r(c,1,s)}function d(){(a=e())?a.then?a.then(p).then(void 0,h):p(a):r(c,1,s)}}function i(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));for(var u=[{name:"uno",baud:115200,signature:[30,149,15],pageSize:128,numPages:256,timeout:400,productId:["0x0043","0x7523","0x0001","0xea60"],productPage:"https://store.arduino.cc/arduino-uno-rev3",protocol:"stk500v1"},{name:"micro",baud:57600,signature:[67,65,84,69,82,73,78],productId:["0x0037","0x8037","0x0036","0x0237"],productPage:"https://store.arduino.cc/arduino-micro",protocol:"avr109"},{name:"imuduino",baud:57600,signature:[67,65,84,69,82,73,78],productId:["0x0036","0x8037","0x8036"],productPage:"https://www.kickstarter.com/projects/1265095814/imuduino-wireless-3d-motion-html-js-apps-arduino-p?lang=de",protocol:"avr109"},{name:"leonardo",baud:57600,signature:[67,65,84,69,82,73,78],productId:["0x0036","0x8036","0x800c"],productPage:"https://store.arduino.cc/leonardo",protocol:"avr109"},{name:"arduboy",baud:57600,signature:[67,65,84,69,82,73,78],productId:["0x0036","0x8036","0x800c"],productPage:"https://arduboy.com/",protocol:"avr109"},{name:"feather",baud:57600,signature:[67,65,84,69,82,73,78],productId:["0x800c","0x000c"],productPage:"https://www.adafruit.com/feather",protocol:"avr109"},{name:"little-bits",baud:57600,signature:[67,65,84,69,82,73,78],productId:["0x0036","0x8036"],productPage:"https://littlebits.com/collections/bits-and-accessories/products/arduino-bit",protocol:"avr109"},{name:"blend-micro",baud:57600,signature:[67,65,84,69,82,73,78],productId:["0x2404"],productPage:"https://redbear.cc/product/retired/blend-micro.html",protocol:"avr109"},{name:"nano",baud:57600,signature:[30,149,15],pageSize:128,numPages:256,timeout:400,productId:["0x6001","0x7523"],productPage:"https://web.archive.org/web/20150813095112/https://www.arduino.cc/en/Main/ArduinoBoardNano",protocol:"stk500v1"},{name:"nano (new bootloader)",baud:115200,signature:[30,149,15],pageSize:128,numPages:256,timeout:400,productId:["0x6001","0x7523"],productPage:"https://store.arduino.cc/arduino-nano",protocol:"stk500v1"},{name:"duemilanove168",baud:19200,signature:[30,148,6],pageSize:128,numPages:128,timeout:400,productId:["0x6001"],productPage:"https://www.arduino.cc/en/Main/arduinoBoardDuemilanove",protocol:"stk500v1"},{name:"duemilanove328",baud:57600,signature:[30,149,20],pageSize:128,numPages:256,timeout:400,productId:["0x6001"],productPage:"https://www.arduino.cc/en/Main/arduinoBoardDuemilanove",protocol:"stk500v1"},{name:"tinyduino",baud:57600,signature:[30,149,15],pageSize:128,numPages:256,timeout:400,productId:["0x6015"],productPage:"https://tinycircuits.com/pages/tinyduino-overview",protocol:"stk500v1",aliases:["tinduino"]},{name:"mega",baud:115200,signature:[30,152,1],pageSize:256,delay1:10,delay2:1,timeout:200,stabDelay:100,cmdexeDelay:25,synchLoops:32,byteDelay:0,pollValue:83,pollIndex:3,productId:["0x0042","0x6001","0x0010","0x7523"],productPage:"https://store.arduino.cc/mega-2560-r3",protocol:"stk500v2"},{name:"adk",baud:115200,signature:[30,152,1],pageSize:256,delay1:10,delay2:1,timeout:200,stabDelay:100,cmdexeDelay:25,synchLoops:32,byteDelay:0,pollValue:83,pollIndex:3,productId:["0x0044","0x6001","0x003F"],productPage:"https://store.arduino.cc/arduino-mega-adk-rev3",protocol:"stk500v2"},{name:"sf-pro-micro",baud:57600,signature:[67,65,84,69,82,73,78],productId:["0x9206","0x9205"],productPage:"https://www.sparkfun.com/products/12640",protocol:"avr109"},{name:"pro-mini",baud:57600,signature:[30,149,15],pageSize:128,numPages:256,timeout:400,productPage:"https://store.arduino.cc/arduino-pro-mini",protocol:"stk500v1"},{name:"qduino",baud:57600,signature:[67,65,84,69,82,73,78],productId:["0x516d","0x514d"],productPage:"https://www.sparkfun.com/products/13614",protocol:"avr109"},{name:"pinoccio",baud:115200,signature:[30,168,2],pageSize:256,delay1:10,delay2:1,timeout:200,stabDelay:100,cmdexeDelay:25,synchLoops:32,byteDelay:0,pollValue:83,pollIndex:3,productId:["0x6051"],productPage:"https://www.mouser.de/new/crowd-supply/crowd-supply-pinoccio-microcontroller/",protocol:"stk500v2"},{name:"lilypad-usb",baud:57600,signature:[67,65,84,69,82,73,78],productId:["0x9207","0x9208","0x1B4F"],productPage:"https://www.sparkfun.com/products/12049",protocol:"avr109"},{name:"yun",baud:57600,signature:[67,65,84,69,82,73,78],productId:["0x0041","0x8041"],productPage:"https://store.arduino.cc/arduino-yun",protocol:"avr109"},{name:"esplora",baud:57600,signature:[67,65,84,69,82,73,78],productId:["0x003C","0x803C"],productPage:"https://store.arduino.cc/arduino-esplora",protocol:"avr109"},{name:"circuit-playground-classic",baud:57600,signature:[67,65,84,69,82,73,78],productId:["0x0011","0x8011"],productPage:"https://www.adafruit.com/product/3000",protocol:"avr109"},{name:"zumjunior",baud:115200,signature:[30,149,15],pageSize:128,numPages:256,timeout:400,productId:["0xEA60"],productPage:"https://store-de.bq.com/de/zum-kit-junior",protocol:"stk500v1"},{name:"zumcore2",baud:115200,signature:[30,149,15],pageSize:128,numPages:256,timeout:400,productId:["0xEA60"],productPage:"https://www.bq.com/de/zum-core-2-0",protocol:"stk500v1"},{name:"bqZum",baud:19200,signature:[30,149,15],pageSize:128,numPages:256,timeout:400,productId:["0x6001","0x7523"],productPage:"http://diwo.bq.com/zum-bt-328-especificaciones-tecnicas/",protocol:"stk500v1"},{name:"xprov4",baud:115200,signature:[30,149,22],pageSize:128,numPages:256,timeout:400,productId:["0x0043","0x7523","0x0001","0xea60"],productPage:"http://www.spark-concepts.com/cnc-xpro-v4-controller/",protocol:"stk500v1"}],a=function(e){var t=u.filter((function(t){return t.name===e||t.aliases&&-1!==t.aliases.indexOf(e)}));if(!t||0===t.length)throw new Error("no board named '"+e+"' was found!");if(t.length>1)throw new Error("several boards named '"+e+"' were found!");return t[0]},s={__proto__:null,boards:u,getBoard:a},f=[],c=[],h="undefined"!=typeof Uint8Array?Uint8Array:Array,l="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",p=0,d=l.length;p<d;++p)f[p]=l[p],c[l.charCodeAt(p)]=p;function g(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function m(e,t,r){for(var n,o=[],i=t;i<r;i+=3)o.push(f[(n=(e[i]<<16&16711680)+(e[i+1]<<8&65280)+(255&e[i+2]))>>18&63]+f[n>>12&63]+f[n>>6&63]+f[63&n]);return o.join("")}c["-".charCodeAt(0)]=62,c["_".charCodeAt(0)]=63;var y={byteLength:function(e){var t=g(e),r=t[1];return 3*(t[0]+r)/4-r},toByteArray:function(e){var t,r,n=g(e),o=n[0],i=n[1],u=new h(function(e,t,r){return 3*(t+r)/4-r}(0,o,i)),a=0,s=i>0?o-4:o;for(r=0;r<s;r+=4)t=c[e.charCodeAt(r)]<<18|c[e.charCodeAt(r+1)]<<12|c[e.charCodeAt(r+2)]<<6|c[e.charCodeAt(r+3)],u[a++]=t>>16&255,u[a++]=t>>8&255,u[a++]=255&t;return 2===i&&(t=c[e.charCodeAt(r)]<<2|c[e.charCodeAt(r+1)]>>4,u[a++]=255&t),1===i&&(t=c[e.charCodeAt(r)]<<10|c[e.charCodeAt(r+1)]<<4|c[e.charCodeAt(r+2)]>>2,u[a++]=t>>8&255,u[a++]=255&t),u},fromByteArray:function(e){for(var t,r=e.length,n=r%3,o=[],i=0,u=r-n;i<u;i+=16383)o.push(m(e,i,i+16383>u?u:i+16383));return 1===n?o.push(f[(t=e[r-1])>>2]+f[t<<4&63]+"=="):2===n&&o.push(f[(t=(e[r-2]<<8)+e[r-1])>>10]+f[t>>4&63]+f[t<<2&63]+"="),o.join("")}},v={read:function(e,t,r,n,o){var i,u,a=8*o-n-1,s=(1<<a)-1,f=s>>1,c=-7,h=r?o-1:0,l=r?-1:1,p=e[t+h];for(h+=l,i=p&(1<<-c)-1,p>>=-c,c+=a;c>0;i=256*i+e[t+h],h+=l,c-=8);for(u=i&(1<<-c)-1,i>>=-c,c+=n;c>0;u=256*u+e[t+h],h+=l,c-=8);if(0===i)i=1-f;else{if(i===s)return u?NaN:Infinity*(p?-1:1);u+=Math.pow(2,n),i-=f}return(p?-1:1)*u*Math.pow(2,i-n)},write:function(e,t,r,n,o,i){var u,a,s,f=8*i-o-1,c=(1<<f)-1,h=c>>1,l=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,d=n?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||Infinity===t?(a=isNaN(t)?1:0,u=c):(u=Math.floor(Math.log(t)/Math.LN2),t*(s=Math.pow(2,-u))<1&&(u--,s*=2),(t+=u+h>=1?l/s:l*Math.pow(2,1-h))*s>=2&&(u++,s/=2),u+h>=c?(a=0,u=c):u+h>=1?(a=(t*s-1)*Math.pow(2,o),u+=h):(a=t*Math.pow(2,h-1)*Math.pow(2,o),u=0));o>=8;e[r+p]=255&a,p+=d,a/=256,o-=8);for(u=u<<o|a,f+=o;f>0;e[r+p]=255&u,p+=d,u/=256,f-=8);e[r+p-d]|=128*g}},w=function(e,t){return function(e,t){var r="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;t.Buffer=i,t.SlowBuffer=function(e){return+e!=e&&(e=0),i.alloc(+e)},t.INSPECT_MAX_BYTES=50;var n=2147483647;function o(e){if(e>n)throw new RangeError('The value "'+e+'" is invalid for option "size"');var t=new Uint8Array(e);return Object.setPrototypeOf(t,i.prototype),t}function i(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return s(e)}return u(e,t,r)}function u(e,t,r){if("string"==typeof e)return function(e,t){if("string"==typeof t&&""!==t||(t="utf8"),!i.isEncoding(t))throw new TypeError("Unknown encoding: "+t);var r=0|h(e,t),n=o(r),u=n.write(e,t);return u!==r&&(n=n.slice(0,u)),n}(e,t);if(ArrayBuffer.isView(e))return f(e);if(null==e)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(M(e,ArrayBuffer)||e&&M(e.buffer,ArrayBuffer))return function(e,t,r){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');var n;return n=void 0===t&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,t):new Uint8Array(e,t,r),Object.setPrototypeOf(n,i.prototype),n}(e,t,r);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');var n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return i.from(n,t,r);var u=function(e){if(i.isBuffer(e)){var t=0|c(e.length),r=o(t);return 0===r.length?r:(e.copy(r,0,0,t),r)}return void 0!==e.length?"number"!=typeof e.length||K(e.length)?o(0):f(e):"Buffer"===e.type&&Array.isArray(e.data)?f(e.data):void 0}(e);if(u)return u;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return i.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function a(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function s(e){return a(e),o(e<0?0:0|c(e))}function f(e){for(var t=e.length<0?0:0|c(e.length),r=o(t),n=0;n<t;n+=1)r[n]=255&e[n];return r}function c(e){if(e>=n)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+n.toString(16)+" bytes");return 0|e}function h(e,t){if(i.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||M(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);var r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;for(var o=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return D(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return j(e).length;default:if(o)return n?-1:D(e).length;t=(""+t).toLowerCase(),o=!0}}function l(e,t,r){var n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return B(this,t,r);case"utf8":case"utf-8":return I(this,t,r);case"ascii":return _(this,t,r);case"latin1":case"binary":return T(this,t,r);case"base64":return x(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return O(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function p(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function d(e,t,r,n,o){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),K(r=+r)&&(r=o?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(o)return-1;r=e.length-1}else if(r<0){if(!o)return-1;r=0}if("string"==typeof t&&(t=i.from(t,n)),i.isBuffer(t))return 0===t.length?-1:g(e,t,r,n,o);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):g(e,[t],r,n,o);throw new TypeError("val must be string, number or Buffer")}function g(e,t,r,n,o){var i,u=1,a=e.length,s=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;u=2,a/=2,s/=2,r/=2}function f(e,t){return 1===u?e[t]:e.readUInt16BE(t*u)}if(o){var c=-1;for(i=r;i<a;i++)if(f(e,i)===f(t,-1===c?0:i-c)){if(-1===c&&(c=i),i-c+1===s)return c*u}else-1!==c&&(i-=i-c),c=-1}else for(r+s>a&&(r=a-s),i=r;i>=0;i--){for(var h=!0,l=0;l<s;l++)if(f(e,i+l)!==f(t,l)){h=!1;break}if(h)return i}return-1}function m(e,t,r,n){r=Number(r)||0;var o=e.length-r;n?(n=Number(n))>o&&(n=o):n=o;var i=t.length;n>i/2&&(n=i/2);for(var u=0;u<n;++u){var a=parseInt(t.substr(2*u,2),16);if(K(a))return u;e[r+u]=a}return u}function w(e,t,r,n){return N(D(t,e.length-r),e,r,n)}function b(e,t,r,n){return N(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function E(e,t,r,n){return b(e,t,r,n)}function P(e,t,r,n){return N(j(t),e,r,n)}function S(e,t,r,n){return N(function(e,t){for(var r,n,o=[],i=0;i<e.length&&!((t-=2)<0);++i)n=(r=e.charCodeAt(i))>>8,o.push(r%256),o.push(n);return o}(t,e.length-r),e,r,n)}function x(e,t,r){return y.fromByteArray(0===t&&r===e.length?e:e.slice(t,r))}function I(e,t,r){r=Math.min(e.length,r);for(var n=[],o=t;o<r;){var i,u,a,s,f=e[o],c=null,h=f>239?4:f>223?3:f>191?2:1;if(o+h<=r)switch(h){case 1:f<128&&(c=f);break;case 2:128==(192&(i=e[o+1]))&&(s=(31&f)<<6|63&i)>127&&(c=s);break;case 3:u=e[o+2],128==(192&(i=e[o+1]))&&128==(192&u)&&(s=(15&f)<<12|(63&i)<<6|63&u)>2047&&(s<55296||s>57343)&&(c=s);break;case 4:u=e[o+2],a=e[o+3],128==(192&(i=e[o+1]))&&128==(192&u)&&128==(192&a)&&(s=(15&f)<<18|(63&i)<<12|(63&u)<<6|63&a)>65535&&s<1114112&&(c=s)}null===c?(c=65533,h=1):c>65535&&(n.push((c-=65536)>>>10&1023|55296),c=56320|1023&c),n.push(c),o+=h}return function(e){var t=e.length;if(t<=A)return String.fromCharCode.apply(String,e);for(var r="",n=0;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=A));return r}(n)}t.kMaxLength=n,(i.TYPED_ARRAY_SUPPORT=function(){try{var e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),42===e.foo()}catch(e){return!1}}())||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(i.prototype,"parent",{enumerable:!0,get:function(){if(i.isBuffer(this))return this.buffer}}),Object.defineProperty(i.prototype,"offset",{enumerable:!0,get:function(){if(i.isBuffer(this))return this.byteOffset}}),"undefined"!=typeof Symbol&&null!=Symbol.species&&i[Symbol.species]===i&&Object.defineProperty(i,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),i.poolSize=8192,i.from=function(e,t,r){return u(e,t,r)},Object.setPrototypeOf(i.prototype,Uint8Array.prototype),Object.setPrototypeOf(i,Uint8Array),i.alloc=function(e,t,r){return function(e,t,r){return a(e),e<=0?o(e):void 0!==t?"string"==typeof r?o(e).fill(t,r):o(e).fill(t):o(e)}(e,t,r)},i.allocUnsafe=function(e){return s(e)},i.allocUnsafeSlow=function(e){return s(e)},i.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==i.prototype},i.compare=function(e,t){if(M(e,Uint8Array)&&(e=i.from(e,e.offset,e.byteLength)),M(t,Uint8Array)&&(t=i.from(t,t.offset,t.byteLength)),!i.isBuffer(e)||!i.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;for(var r=e.length,n=t.length,o=0,u=Math.min(r,n);o<u;++o)if(e[o]!==t[o]){r=e[o],n=t[o];break}return r<n?-1:n<r?1:0},i.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},i.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return i.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=i.allocUnsafe(t),o=0;for(r=0;r<e.length;++r){var u=e[r];if(M(u,Uint8Array)&&(u=i.from(u)),!i.isBuffer(u))throw new TypeError('"list" argument must be an Array of Buffers');u.copy(n,o),o+=u.length}return n},i.byteLength=h,i.prototype._isBuffer=!0,i.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)p(this,t,t+1);return this},i.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)p(this,t,t+3),p(this,t+1,t+2);return this},i.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)p(this,t,t+7),p(this,t+1,t+6),p(this,t+2,t+5),p(this,t+3,t+4);return this},i.prototype.toLocaleString=i.prototype.toString=function(){var e=this.length;return 0===e?"":0===arguments.length?I(this,0,e):l.apply(this,arguments)},i.prototype.equals=function(e){if(!i.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===i.compare(this,e)},i.prototype.inspect=function(){var e="",r=t.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"},r&&(i.prototype[r]=i.prototype.inspect),i.prototype.compare=function(e,t,r,n,o){if(M(e,Uint8Array)&&(e=i.from(e,e.offset,e.byteLength)),!i.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),t<0||r>e.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&t>=r)return 0;if(n>=o)return-1;if(t>=r)return 1;if(this===e)return 0;for(var u=(o>>>=0)-(n>>>=0),a=(r>>>=0)-(t>>>=0),s=Math.min(u,a),f=this.slice(n,o),c=e.slice(t,r),h=0;h<s;++h)if(f[h]!==c[h]){u=f[h],a=c[h];break}return u<a?-1:a<u?1:0},i.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},i.prototype.indexOf=function(e,t,r){return d(this,e,t,r,!0)},i.prototype.lastIndexOf=function(e,t,r){return d(this,e,t,r,!1)},i.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var o=this.length-t;if((void 0===r||r>o)&&(r=o),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i=!1;;)switch(n){case"hex":return m(this,e,t,r);case"utf8":case"utf-8":return w(this,e,t,r);case"ascii":return b(this,e,t,r);case"latin1":case"binary":return E(this,e,t,r);case"base64":return P(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return S(this,e,t,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},i.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var A=4096;function _(e,t,r){var n="";r=Math.min(e.length,r);for(var o=t;o<r;++o)n+=String.fromCharCode(127&e[o]);return n}function T(e,t,r){var n="";r=Math.min(e.length,r);for(var o=t;o<r;++o)n+=String.fromCharCode(e[o]);return n}function B(e,t,r){var n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);for(var o="",i=t;i<r;++i)o+=q[e[i]];return o}function O(e,t,r){for(var n=e.slice(t,r),o="",i=0;i<n.length;i+=2)o+=String.fromCharCode(n[i]+256*n[i+1]);return o}function R(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function C(e,t,r,n,o,u){if(!i.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>o||t<u)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}function k(e,t,r,n,o,i){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function L(e,t,r,n,o){return t=+t,r>>>=0,o||k(e,0,r,4),v.write(e,t,r,n,23,4),r+4}function U(e,t,r,n,o){return t=+t,r>>>=0,o||k(e,0,r,8),v.write(e,t,r,n,52,8),r+8}i.prototype.slice=function(e,t){var r=this.length;(e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e);var n=this.subarray(e,t);return Object.setPrototypeOf(n,i.prototype),n},i.prototype.readUIntLE=function(e,t,r){e>>>=0,t>>>=0,r||R(e,t,this.length);for(var n=this[e],o=1,i=0;++i<t&&(o*=256);)n+=this[e+i]*o;return n},i.prototype.readUIntBE=function(e,t,r){e>>>=0,t>>>=0,r||R(e,t,this.length);for(var n=this[e+--t],o=1;t>0&&(o*=256);)n+=this[e+--t]*o;return n},i.prototype.readUInt8=function(e,t){return e>>>=0,t||R(e,1,this.length),this[e]},i.prototype.readUInt16LE=function(e,t){return e>>>=0,t||R(e,2,this.length),this[e]|this[e+1]<<8},i.prototype.readUInt16BE=function(e,t){return e>>>=0,t||R(e,2,this.length),this[e]<<8|this[e+1]},i.prototype.readUInt32LE=function(e,t){return e>>>=0,t||R(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},i.prototype.readUInt32BE=function(e,t){return e>>>=0,t||R(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},i.prototype.readIntLE=function(e,t,r){e>>>=0,t>>>=0,r||R(e,t,this.length);for(var n=this[e],o=1,i=0;++i<t&&(o*=256);)n+=this[e+i]*o;return n>=(o*=128)&&(n-=Math.pow(2,8*t)),n},i.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||R(e,t,this.length);for(var n=t,o=1,i=this[e+--n];n>0&&(o*=256);)i+=this[e+--n]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*t)),i},i.prototype.readInt8=function(e,t){return e>>>=0,t||R(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},i.prototype.readInt16LE=function(e,t){e>>>=0,t||R(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},i.prototype.readInt16BE=function(e,t){e>>>=0,t||R(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},i.prototype.readInt32LE=function(e,t){return e>>>=0,t||R(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},i.prototype.readInt32BE=function(e,t){return e>>>=0,t||R(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},i.prototype.readFloatLE=function(e,t){return e>>>=0,t||R(e,4,this.length),v.read(this,e,!0,23,4)},i.prototype.readFloatBE=function(e,t){return e>>>=0,t||R(e,4,this.length),v.read(this,e,!1,23,4)},i.prototype.readDoubleLE=function(e,t){return e>>>=0,t||R(e,8,this.length),v.read(this,e,!0,52,8)},i.prototype.readDoubleBE=function(e,t){return e>>>=0,t||R(e,8,this.length),v.read(this,e,!1,52,8)},i.prototype.writeUIntLE=function(e,t,r,n){e=+e,t>>>=0,r>>>=0,n||C(this,e,t,r,Math.pow(2,8*r)-1,0);var o=1,i=0;for(this[t]=255&e;++i<r&&(o*=256);)this[t+i]=e/o&255;return t+r},i.prototype.writeUIntBE=function(e,t,r,n){e=+e,t>>>=0,r>>>=0,n||C(this,e,t,r,Math.pow(2,8*r)-1,0);var o=r-1,i=1;for(this[t+o]=255&e;--o>=0&&(i*=256);)this[t+o]=e/i&255;return t+r},i.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,1,255,0),this[t]=255&e,t+1},i.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},i.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},i.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},i.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},i.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t>>>=0,!n){var o=Math.pow(2,8*r-1);C(this,e,t,r,o-1,-o)}var i=0,u=1,a=0;for(this[t]=255&e;++i<r&&(u*=256);)e<0&&0===a&&0!==this[t+i-1]&&(a=1),this[t+i]=(e/u>>0)-a&255;return t+r},i.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t>>>=0,!n){var o=Math.pow(2,8*r-1);C(this,e,t,r,o-1,-o)}var i=r-1,u=1,a=0;for(this[t+i]=255&e;--i>=0&&(u*=256);)e<0&&0===a&&0!==this[t+i+1]&&(a=1),this[t+i]=(e/u>>0)-a&255;return t+r},i.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},i.prototype.writeInt16LE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},i.prototype.writeInt16BE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},i.prototype.writeInt32LE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},i.prototype.writeInt32BE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},i.prototype.writeFloatLE=function(e,t,r){return L(this,e,t,!0,r)},i.prototype.writeFloatBE=function(e,t,r){return L(this,e,t,!1,r)},i.prototype.writeDoubleLE=function(e,t,r){return U(this,e,t,!0,r)},i.prototype.writeDoubleBE=function(e,t,r){return U(this,e,t,!1,r)},i.prototype.copy=function(e,t,r,n){if(!i.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);var o=n-r;if(this===e&&"function"==typeof Uint8Array.prototype.copyWithin)this.copyWithin(t,r,n);else if(this===e&&r<t&&t<n)for(var u=o-1;u>=0;--u)e[u+t]=this[u+r];else Uint8Array.prototype.set.call(e,this.subarray(r,n),t);return o},i.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!i.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===e.length){var o=e.charCodeAt(0);("utf8"===n&&o<128||"latin1"===n)&&(e=o)}}else"number"==typeof e?e&=255:"boolean"==typeof e&&(e=Number(e));if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;var u;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(u=t;u<r;++u)this[u]=e;else{var a=i.isBuffer(e)?e:i.from(e,n),s=a.length;if(0===s)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(u=0;u<r-t;++u)this[u+t]=a[u%s]}return this};var z=/[^+/0-9A-Za-z-_]/g;function D(e,t){var r;t=t||Infinity;for(var n=e.length,o=null,i=[],u=0;u<n;++u){if((r=e.charCodeAt(u))>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}if(u+1===n){(t-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(t-=3)>-1&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((t-=1)<0)break;i.push(r)}else if(r<2048){if((t-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function j(e){return y.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(z,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function N(e,t,r,n){for(var o=0;o<n&&!(o+r>=t.length||o>=e.length);++o)t[o+r]=e[o];return o}function M(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function K(e){return e!=e}var q=function(){for(var e=new Array(256),t=0;t<16;++t)for(var r=16*t,n=0;n<16;++n)e[r+n]="0123456789abcdef"[t]+"0123456789abcdef"[n];return e}()}(t={exports:{}},t.exports),t.exports}().Buffer,b={Cmnd_STK_GET_SYNC:48,Cmnd_STK_SET_DEVICE:66,Cmnd_STK_ENTER_PROGMODE:80,Cmnd_STK_LOAD_ADDRESS:85,Cmnd_STK_PROG_PAGE:100,Cmnd_STK_LEAVE_PROGMODE:81,Cmnd_STK_READ_SIGN:117,Sync_CRC_EOP:32,Resp_STK_OK:16,Resp_STK_INSYNC:20,Resp_STK_NOSYNC:21,Cmnd_STK_READ_PAGE:116,OK_RESPONSE:w.from([20,16])},E=function(e,t){var r=e.reader,n=e.writer;try{var u=t.timeout||0,a=null,s=0;t.responseData&&t.responseData.length>0&&(a=t.responseData),a&&(s=a.length),t.responseLength&&(s=t.responseLength);var f=t.cmd;if(f instanceof Array&&(f=w.from(f.concat(b.Sync_CRC_EOP))),r&&n){try{n.write(f)}catch(e){throw new Error("Sending "+f.toString("hex")+" : {err.message}")}return Promise.resolve(i((function(){return Promise.resolve(function(e,t,r){try{var n=[b.Resp_STK_INSYNC],u=w.alloc(0),a=!1,s=null,f=!1,c=null,h=function(e){s&&clearTimeout(s),f=!1,c=e};if(t&&t>0&&(s=setTimeout((function(){s=null,h(new Error("receiveData timeout after "+t+"ms"))}),t)),e){var l=function(e){if(c)throw c;return u},p=!1;f=!0;var d=o((function(){return!p&&!!f}),void 0,(function(){return i((function(){return Promise.resolve(e.read()).then((function(e){e.done?p=!0:function(e){for(var t=0;!a&&t<e.length;)-1!==n.indexOf(e[t])&&(e=e.slice(t,e.length-t),a=!0),t++;a&&(u=w.concat([u,e])),u.length>r?h(new Error("buffer overflow "+u.length+" > "+r)):u.length==r&&h()}(e.value)}))}),(function(e){throw e}))}));return Promise.resolve(d&&d.then?d.then(l):l())}throw new Error("serial port not found")}catch(e){return Promise.reject(e)}}(r,u,s)).then((function(e){if(a&&!function(e,t){if(w.isBuffer(e)&&w.isBuffer(t)){if("function"==typeof e.equals)return e.equals(t);if(e.length!==t.length)return!1;for(var r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}}(e,a))throw new Error(f+" response mismatch: "+e.toString("hex")+", "+a.toString("hex"));return e}))}),(function(e){throw new Error("Sending "+f.toString("hex")+": "+e.message)})))}throw new Error("serial port not found")}catch(e){return Promise.reject(e)}},P=function(e,t,r){var n=r.timeout,u=r.debug;try{var a=function(e){if(s)return e;throw new Error("Sync failed after "+t+" attempts")},s=!1;u&&console.log("sync");var f={cmd:[b.Cmnd_STK_GET_SYNC],responseData:b.OK_RESPONSE,timeout:n},c=0,h=o((function(){return!s&&c<=t}),void 0,(function(){function r(e){if(s)return e;c<=t&&u&&console.log("failed! will try again ("+c+")")}c+=1;var n=i((function(){return Promise.resolve(E(e,f)).then((function(e){return u&&console.log("sync complete",e,c),s=!0,e}))}),(function(e){console.log(e)}));return n&&n.then?n.then(r):r(n)}));return Promise.resolve(h&&h.then?h.then(a):a(h))}catch(e){return Promise.reject(e)}},S=function(e,t,r){var n=r.timeout,o=r.debug;try{o&&console.log("load address");var u={cmd:[b.Cmnd_STK_LOAD_ADDRESS,255&t,t>>8&255],responseData:b.OK_RESPONSE,timeout:n};return Promise.resolve(i((function(){return Promise.resolve(E(e,u)).then((function(e){return o&&console.log("loaded address",e),e}))}),(function(e){throw e})))}catch(e){return Promise.reject(e)}},x=function(e){var t=e.port,r=e.reader,n=e.writer;try{return n.releaseLock(),r.releaseLock(),Promise.resolve(t.close()).then((function(){}))}catch(e){return Promise.reject(e)}},I=function(e){return new Promise((function(t){return setTimeout(t,e)}))},A=function(e){try{return e.port.setSignals({requestToSend:!0,dataTerminalReady:!0}),Promise.resolve(I(250)).then((function(){return e.port.setSignals({requestToSend:!1,dataTerminalReady:!1}),Promise.resolve(I(50)).then((function(){}))}))}catch(e){return Promise.reject(e)}};return{isAvailable:function(){return navigator&&navigator.serial},openSerial:function(e){void 0===e&&(e={});try{var t=!1,r=e.baudRate,n=void 0===r?57600:r,o=e.filters,u=void 0===o?null:o,a=i((function(){function e(){return Promise.resolve(r.open({baudRate:n})).then((function(){var e=r.readable.getReader(),n=r.writable.getWriter();return t=!0,{port:r,reader:e,writer:n}}))}var r,o=u?Promise.resolve(navigator.serial.requestPort(u)).then((function(e){r=e})):Promise.resolve(navigator.serial.requestPort()).then((function(e){r=e}));return o&&o.then?o.then(e):e()}),(function(e){console.log(e)}));return Promise.resolve(a&&a.then?a.then((function(e){return t?e:null})):t?a:null)}catch(e){return Promise.reject(e)}},closeSerial:x,parseHex:function(e){return function(e,t){e instanceof w&&(e=e.toString("ascii"));for(var r=w.alloc(8192),n=0,o=0,i=null,u=null,a=0,s=0;s+11<=e.length;){if(":"!==e.charAt(s++))throw new Error("Line "+(a+1)+" does not start with a colon (:).");a++;var f=parseInt(e.substr(s,2),16);s+=2;var c=parseInt(e.substr(s,4),16);s+=4;var h=parseInt(e.substr(s,2),16),l=e.substr(s+=2,2*f),p=w.from(l,"hex");s+=2*f;var d=parseInt(e.substr(s,2),16);s+=2;for(var g=f+(c>>8)+c+h&255,m=0;m<f;m++)g=g+p[m]&255;if(d!==(g=256-g&255))throw new Error("Invalid checksum on line "+a+": got "+d+", but expected "+g);switch(h){case 0:var y=o+c;if(y+f>=r.length){var v=w.alloc(2*(y+f));r.copy(v,0,0,n),r=v}y>n&&r.fill(255,n,y),p.copy(r,y),n=Math.max(n,y+f);break;case 1:if(0!==f)throw new Error("Invalid EOF record on line "+a+".");return{data:r.slice(0,n),startSegmentAddress:i,startLinearAddress:u};case 2:if(2!==f||0!==c)throw new Error("Invalid extended segment address record on line "+a+".");o=parseInt(l,16)<<4;break;case 3:if(4!==f||0!==c)throw new Error("Invalid start segment address record on line "+a+".");i=parseInt(l,16);break;case 4:if(2!==f||0!==c)throw new Error("Invalid extended linear address record on line "+a+".");o=parseInt(l,16)<<16;break;case 5:if(4!==f||0!==c)throw new Error("Invalid start linear address record on line "+a+".");u=parseInt(l,16);break;default:throw new Error("Invalid record type ("+h+") on line "+a+".")}"\r"===e.charAt(s)&&s++,"\n"===e.charAt(s)&&s++}throw new Error("Unexpected end of input: missing or invalid EOF record.")}(e).data},flash:function(t,r,n){try{if(!n)throw new Error("I need options to do this!");var u=n.debug,s=n.boardName,f=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)t.indexOf(r=i[n])>=0||(o[r]=e[r]);return o}(n,["debug","boardName"]),c=e({debug:u},f);if(u&&console.log("will flash .hex file on board..."),s){var h=a(s);c=e({},c,{},h)}if(!c.name)throw new Error("Cannot find board name!");return Promise.resolve(t.open({baudRate:c.baud})).then((function(){var e=t.readable.getReader(),n=t.writable.getWriter(),a={port:t,reader:e,writer:n};return i((function(){return Promise.resolve(A(a)).then((function(){return Promise.resolve(function(e,t,r){try{var n={pagesizehigh:r.pagesizehigh<<8&255,pagesizelow:255&r.pagesizelow},u=i((function(){return Promise.resolve(P(e,3,r)).then((function(){return Promise.resolve(P(e,3,r)).then((function(){return Promise.resolve(P(e,3,r)).then((function(){var u=w.from(r.signature);return Promise.resolve(function(e,t,r){var n=r.timeout,o=r.debug;try{o&&console.log("verify signature");var u=w.concat([w.from([b.Resp_STK_INSYNC]),t,w.from([b.Resp_STK_OK])]),a={cmd:[b.Cmnd_STK_READ_SIGN],responseLength:u.length,timeout:n};return Promise.resolve(i((function(){return Promise.resolve(E(e,a)).then((function(e){return e?o&&console.log("confirm signature",e,e.toString("hex")):o&&console.log("confirm signature","no data"),e}))}),(function(e){throw e})))}catch(e){return Promise.reject(e)}}(e,u,r)).then((function(){return Promise.resolve(function(e,t,r){var n=r.timeout,o=r.debug;try{o&&console.log("set device");var u={cmd:[b.Cmnd_STK_SET_DEVICE,t.devicecode||0,t.revision||0,t.progtype||0,t.parmode||0,t.polling||0,t.selftimed||0,t.lockbytes||0,t.fusebytes||0,t.flashpollval1||0,t.flashpollval2||0,t.eeprompollval1||0,t.eeprompollval2||0,t.pagesizehigh||0,t.pagesizelow||0,t.eepromsizehigh||0,t.eepromsizelow||0,t.flashsize4||0,t.flashsize3||0,t.flashsize2||0,t.flashsize1||0],responseData:b.OK_RESPONSE,timeout:n};return Promise.resolve(i((function(){return Promise.resolve(E(e,u)).then((function(e){return o&&console.log("setOptions",e),e}))}),(function(e){throw e})))}catch(e){return Promise.reject(e)}}(e,n,r)).then((function(){return Promise.resolve(function(e,t){var r=t.timeout,n=t.debug;try{n&&console.log("send enter programming mode");var o={cmd:[b.Cmnd_STK_ENTER_PROGMODE],responseData:b.OK_RESPONSE,timeout:r};return Promise.resolve(i((function(){return Promise.resolve(E(e,o)).then((function(e){return n&&console.log("sent enter programming mode",e),e}))}),(function(e){throw e})))}catch(e){return Promise.reject(e)}}(e,r)).then((function(){return Promise.resolve(function(e,t,r){try{var n=function(e){return u?e:(a&&console.log("upload done"),!0)},u=!1,a=r.debug,s=r.pageSize;a&&console.log("program");var f,c=0,h=i((function(){var n=o((function(){return c<t.length}),void 0,(function(){return a&&console.log("program page"),Promise.resolve(S(e,c>>1,r)).then((function(){return f=t.slice(c,t.length>s?c+s:t.length-1),Promise.resolve(function(e,t,r){var n=r.timeout,o=r.debug;try{o&&console.log("load page");var u=w.concat([w.from([b.Cmnd_STK_PROG_PAGE,t.length>>8,255&t.length,70]),t,w.from([b.Sync_CRC_EOP])]),a={responseData:b.OK_RESPONSE,cmd:u,timeout:n};return Promise.resolve(i((function(){return Promise.resolve(E(e,a)).then((function(e){return o&&console.log("loaded page",e),e}))}),(function(e){throw e})))}catch(e){return Promise.reject(e)}}(e,f,r)).then((function(){return a&&console.log("programmed page"),c+=f.length,Promise.resolve(new Promise((function(e){return setTimeout(e,4)}))).then((function(){a&&console.log("page done")}))}))}))}));if(n&&n.then)return n.then((function(){}))}),(function(e){throw e}));return Promise.resolve(h&&h.then?h.then(n):n(h))}catch(e){return Promise.reject(e)}}(e,t,r)).then((function(){return Promise.resolve(function(e,t,r){try{var n=function(e){return u?e:(a&&console.log("verify done"),!0)},u=!1,a=r.debug,s=r.pageSize;a&&console.log("verify");var f,c=0,h=i((function(){var n=o((function(){return c<t.length}),void 0,(function(){return a&&console.log("verify page"),Promise.resolve(S(e,c>>1,r)).then((function(){return f=t.slice(c,t.length>s?c+s:t.length-1),Promise.resolve(function(e,t,r){try{var n=r.pageSize,o=r.timeout,u=r.debug;u&&console.log("verify page");var a=w.concat([w.from([b.Resp_STK_INSYNC]),t,w.from([b.Resp_STK_OK])]),s=t.length>=n?n:t.length,f={cmd:[b.Cmnd_STK_READ_PAGE,s>>8&255,255&s,70],responseLength:a.length,timeout:o};return Promise.resolve(i((function(){return Promise.resolve(E(e,f)).then((function(e){return u&&console.log("confirm page",e,e.toString("hex")),e}))}),(function(e){throw e})))}catch(e){return Promise.reject(e)}}(e,f,r)).then((function(){return a&&console.log("verified page"),c+=f.length,Promise.resolve(new Promise((function(e){return setTimeout(e,4)}))).then((function(){a&&console.log("page done")}))}))}))}));if(n&&n.then)return n.then((function(){}))}),(function(e){throw e}));return Promise.resolve(h&&h.then?h.then(n):n(h))}catch(e){return Promise.reject(e)}}(e,t,r)).then((function(){return Promise.resolve(function(e,t){var r=t.timeout,n=t.debug;try{n&&console.log("send leave programming mode");var o={cmd:[b.Cmnd_STK_LEAVE_PROGMODE],responseData:b.OK_RESPONSE,timeout:r};return Promise.resolve(i((function(){return Promise.resolve(E(e,o)).then((function(e){return n&&console.log("sent leave programming mode",e),e}))}),(function(e){throw e})))}catch(e){return Promise.reject(e)}}(e,r)).then((function(){}))}))}))}))}))}))}))}))}))}),(function(e){throw e}));return Promise.resolve(!u||!u.then||u.then((function(e){return!0})))}catch(e){return Promise.reject(e)}}(a,r,c)).then((function(e){return u&&console.log("flash complete successfully"),e}))}))}),(function(e){return Promise.resolve(x(a)).then((function(){throw u&&console.log("encountered errors during flash :("),e}))}))}))}catch(e){return Promise.reject(e)}},reset:A,boardsHelper:s}})); |