1import * as APPOTA from 'APPOTA' 2import * as event from 'events' 3 4class UTILS_APPOTA extends event.EventEmitter { 5 constructor(options){ 6 super(); 7 8 if (!options) { 9 throw new Error('options invalid'); 10 } 11 12 this._init(options); 13 } 14 15 _init(options) { 16 //console.log(iothandle) 17 APPOTA.otaInit(options, function(res) { 18 this.emit('new', res); 19 }.bind(this)); 20 } 21 22 download(options, cb) { 23 APPOTA.otaDownload(options, cb); 24 } 25 26 verify(options, cb) { 27 APPOTA.otaVerify(options, cb); 28 } 29 30 report(options) { 31 var res = APPOTA.otaReport(options); 32 if (res < 0) { 33 this.emit('error'); 34 } 35 } 36 37 upgrade(options, cb) { 38 APPOTA.otaUpgrade(options, cb); 39 } 40} 41 42export function open(options) { 43 return new UTILS_APPOTA(options); 44}