"use strict";(function(){"use strict";global.Promise=require("bluebird");var e=require("co");var r=require("./jsUtil.js");var n=require("./deviceLinkPromise");function t(){var e=r.getPkgInfo();console.log("pkgInfo:",e);if(e==undefined||e.spec==undefined||e.spec.info==undefined||e.spec.info.connServ==undefined){return"http://172.18.128.23:1337"}return e.spec.info.connServ}exports.syncDevices=function(s,o,c,i){if(o==undefined||typeof o.addDeviceLink!=="function"){return Promise.reject("invalid mgr").asCallback(i)}if(s==undefined){s=t()}e(regeneratorRuntime.mark(function a(){var e,t,i,d,u,l,f,p,m,v,g,h;return regeneratorRuntime.wrap(function b(a){while(1){switch(a.prev=a.next){case 0:e=[];t=0;i=0;d=o.adminItems.length;c(t,i,d);u=0;case 6:if(!(u<o.adminItems.length)){a.next=27;break}console.log("----- process------:",u+1," of ",o.adminItems.length);l=o.adminItems[u].instance;f=o.adminItems[u].params;if(!(typeof f.host==="string"&&f.host.length>0)){a.next=24;break}a.prev=11;a.next=14;return n.connectPro(l,f);case 14:p=l.getDeviceInfo();if(typeof p.deviceModel==="string"){console.log("host:",f.host,"deviceModel:",p.deviceModel);e.push({productor:"ruijie",deviceName:f.host,host:f.host,port:f.port,encoding:f.encoding,serialNo:p.seriaNo,protocal:f.protocal,username:f.username,password:f.password,enablePassword:f.enablePassword,deviceModel:p.deviceModel,deviceType:p.deviceType,softVer:p.softVer,hardVer:p.hardVer});t++}else{i++}a.next=22;break;case 18:a.prev=18;a.t0=a["catch"](11);console.log("cannot connect ip:",f.host," error:",a.t0);i++;case 22:l.disConnect();c(t,i,d);case 24:u++;a.next=6;break;case 27:m=0;v=t;u=0;case 30:if(!(v>0)){a.next=47;break}g=[];if(v>100){g=e.slice(u*100,u*100+100)}else{g=e.slice(u*100,u*100+v)}a.next=35;return r.commonPost2(s,"/update",g,true);case 35:h=a.sent;if(!(h.code==0)){a.next=40;break}m+=h.saveNum;a.next=42;break;case 40:console.error("syncDevices: send device error: code:",h.code," msg:",h.msg);return a.abrupt("return",Promise.reject(h.msg));case 42:v-=100;console.log("save times:"+(u+1));case 44:u++;a.next=30;break;case 47:return a.abrupt("return",m);case 48:case"end":return a.stop()}}},a,this,[[11,18]])})).catch(function(e){return Promise.reject(e)}).asCallback(i)}})();