"use strict";(function(){"use strict";global.Promise=require("bluebird");var e=require("co");var r=require("./deviceLinkPromise");var n=require("./maccRequest");var t=require("util");var s=require("./jsUtil");exports.launch=function(n,t,s,o,a){var i=require("./deviceLink");var c=new i;return e(regeneratorRuntime.mark(function u(){var e,s;return regeneratorRuntime.wrap(function o(a){while(1){switch(a.prev=a.next){case 0:a.next=2;return r.connectPro(c,n);case 2:e=c.getDeviceSn();if(!(e==undefined||e=="")){a.next=5;break}return a.abrupt("return",Promise.reject("sn is null"));case 5:a.next=7;return r.execPro(c,"config");case 7:s=a.sent;console.log("resp:",s);a.next=11;return r.execPro(c,"cwmp");case 11:s=a.sent;console.log("resp",s);a.next=15;return r.execPro(c,"cpe inform interval 180");case 15:s=a.sent;console.log("resp",s);a.next=19;return r.execPro(c,"acs url "+t+"/service/tr069servlet");case 19:s=a.sent;console.log("resp",s);a.next=23;return r.execPro(c,"end");case 23:s=a.sent;console.log("resp",s);a.next=27;return r.execPro(c,"write");case 27:s=a.sent;console.log("resp",s);c.disConnect();return a.abrupt("return","success");case 31:case"end":return a.stop()}}},u,this)})).catch(function(e){console.log("outer error occur:",e.toString());c.disConnect();return Promise.reject(e)}).asCallback(a)};function o(e){var r=e.split(/AP.+'s version:\r?\n/g);var n=[];r.forEach(function(e){if(e.indexOf("MAC address")!==-1){var r={};var t=e.split(/\r?\n/gi);t.forEach(function(e){if(e.indexOf("Product ID")!==-1){r.productClass=e.split(":")[1].trim()}if(e.indexOf("Hardware version")!==-1){r.hardwareVersion=e.split(":")[1].trim()}if(e.indexOf("Software version")!==-1){r.softwareVersion=e.split(":")[1].trim()}if(e.indexOf("Serial number")!==-1){r.serialNumber=e.split(":")[1].trim()}if(e.indexOf("MAC address")!==-1){r.mac=e.split(":")[1].trim()}});if(s.countObjLength(r)>0){n.push(r)}}});return n}function a(e){var r=e.split(/\r?\n/gi);var n=[];r.forEach(function(e){var r=e.match(/([a-z0-9\.\-]*)\s*([0-9\.\-]*)\s*([a-z0-9\.\-]*)\s*(.*)(Run|Quit)/i);if(Array.isArray(r)&&r.length>=6){var t={mac:r[3].trim(),name:r[1].trim(),localIp:r[2].trim(),onlineStatus:r[5].indexOf("Run")!==-1?"ON":"OFF"};n.push(t)}});return n}exports.uploadDatas=function(t,i,c,u){var l=require("./deviceLink");var f=new l;return e(regeneratorRuntime.mark(function d(){var e,i,u,l,p,v,m,x,g,h,b,w,P,C;return regeneratorRuntime.wrap(function V(d){while(1){switch(d.prev=d.next){case 0:d.next=2;return r.connectPro(f,t);case 2:e=f.getDeviceInfo();d.next=5;return r.execPro(f,"show run");case 5:i=d.sent;d.next=8;return r.execPro(f,"show version all");case 8:u=d.sent;d.next=11;return r.execPro(f,"show ap-config summary");case 11:l=d.sent;f.disConnect();p=o(u);v=a(l);console.log("versionInfos:",p);console.log("configInfos:",v);m=new Map;v.forEach(function(e){m.set(e.mac,e)});p.forEach(function(e){var r=m.get(e.mac);if(r!=undefined){r.productClass=e.productClass;r.hardwareVersion=e.hardwareVersion;r.softwareVersion=e.softwareVersion;r.serialNumber=e.serialNumber}else{console.log("infos not in ap-config summary, info:",e);m.set(e.mac,e)}});x=true;g=false;h=undefined;d.prev=23;for(b=m.values()[Symbol.iterator]();!(x=(w=b.next()).done);x=true){P=w.value;console.log("value:",P)}d.next=31;break;case 27:d.prev=27;d.t0=d["catch"](23);g=true;h=d.t0;case 31:d.prev=31;d.prev=32;if(!x&&b.return){b.return()}case 34:d.prev=34;if(!g){d.next=37;break}throw h;case 37:return d.finish(34);case 38:return d.finish(31);case 39:d.next=41;return s.postStatistics(n.getHost(),"/service/api/device/plugin/import?appid=5fee49bb21014503ae88fe60e847dfbd&secret=fbb8e69bcdc1431db81dcc717adfe16a",{acSn:e.seriaNo,productClass:e.deviceModel,softWareVersion:e.softVer,hardWareVersion:e.hardVer,commandInfo:i,apList:Array.from(m.values())});case 41:C=d.sent;console.log("import result:",C);d.next=45;return s.postStatistics(n.getHost(),"/service/api/tool/diagnose/feedback?token=4b8d224aff2446d2a020f114ae3fe302",{list:[{sn:e.seriaNo,productClass:e.deviceModel,hardwareVersion:e.hardVer,softwareVersion:e.softVer,reason:"其它模块",reasonCode:t.sourceCode,result:10,detail:c}]});case 45:C=d.sent;console.log("times result:",C);if(!(C.code!=0)){d.next=49;break}return d.abrupt("return",Promise.reject(C));case 49:return d.abrupt("return","success");case 50:case"end":return d.stop()}}},d,this,[[23,27,31,39],[32,,34,38]])})).catch(function(e){f.disConnect();console.error("in uploadDatas, error:",e);return Promise.reject(e)}).asCallback(u)}})();