diff --git a/common/modules/web-modules/avrbro.min.js b/common/modules/web-modules/avrbro.min.js index f76283f4..793338e3 100644 --- a/common/modules/web-modules/avrbro.min.js +++ b/common/modules/web-modules/avrbro.min.js @@ -1 +1 @@ -!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;t1)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;p0)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>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>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;iu?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<>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<>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<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=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;ia&&(r=a-s),i=r;i>=0;i--){for(var h=!0,l=0;lo&&(n=o):n=o;var i=t.length;n>i/2&&(n=i/2);for(var u=0;u>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;o239?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;nr&&(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>>=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;on)&&(r=n);for(var o="",i=t;ir)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||te.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>>=0,t>>>=0,r||R(e,t,this.length);for(var n=this[e],o=1,i=0;++i>>=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=(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>>=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>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=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=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>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(u=t;u55295&&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=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&&tr?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>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=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=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>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>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}})); \ No newline at end of file +!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;t1)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;p0)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>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>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;iu?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<>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<>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<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=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;ia&&(r=a-s),i=r;i>=0;i--){for(var h=!0,l=0;lo&&(n=o):n=o;var i=t.length;n>i/2&&(n=i/2);for(var u=0;u>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;o239?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;nr&&(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>>=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;on)&&(r=n);for(var o="",i=t;ir)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||te.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>>=0,t>>>=0,r||R(e,t,this.length);for(var n=this[e],o=1,i=0;++i>>=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=(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>>=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>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=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=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>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(u=t;u55295&&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=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&&tr?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>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=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=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>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>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"),Promise.resolve(x(a)).then((function(){return 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}})); \ No newline at end of file