"use strict";(function(){"use strict";global.Promise=require("bluebird");var e=require("co");var r=require("./deviceLinkPromise");var n=require("./jsUtil");var t=require("./deviceLink");function o(e){var r=e.connectInfo;if(r===undefined||r===null){r={protocal:"telnet",host:n.getPkgInfo().spec.info.racHost,port:"23",username:"",password:"ruijie",enablePassword:"apdebug",encoding:"GB2312"}}if(e.apIp!==undefined||e.apIp!==null){r.host=e.apIp}return r}exports.changeRapIp=function(n,a){var c=o(n);var s=n.apNewIp;var i=n.apNewGw;var u="ap-mode fit";var p="config\r\napip ipv4 "+s+" 255.255.255.0 "+i+"\r\nexit";console.log("command: "+u);console.log("command: "+p);var l=new t;return e(regeneratorRuntime.mark(function d(){var e,n;return regeneratorRuntime.wrap(function t(o){while(1){switch(o.prev=o.next){case 0:o.prev=0;console.debug("telnet to fit ap",c);o.next=4;return r.connectPro(l,c);case 4:o.next=13;break;case 6:o.prev=6;o.t0=o["catch"](0);console.log("ap fit mode login fail",c,o.t0);c.password="admin";c.enablePassword="admin";r.connectPro(l,c);console.log("use fat info to login",c);case 13:console.debug("change ap mode and ip by telnet",l);o.next=16;return r.execPro(l,u);case 16:e=o.sent;console.debug("change rap to fit rsp",e);o.next=20;return r.execPro(l,p);case 20:n=o.sent;console.debug("set ap a temp ip rsp",n);l.disConnect();return o.abrupt("return",Promise.resolve("success"));case 24:case"end":return o.stop()}}},d,this,[[0,6]])})).catch(function(e){console.error(e.toString());l.disConnect();return Promise.resolve(e)}).asCallback(a)};exports.recoverRap=function(n,a){var c=o(n);var s="config\r\nno apip ipv4";console.log("command: "+s);var i=new t;return e(regeneratorRuntime.mark(function u(){var e;return regeneratorRuntime.wrap(function n(t){while(1){switch(t.prev=t.next){case 0:t.next=2;return r.connectPro(i,c);case 2:t.next=4;return r.execPro(i,s);case 4:e=t.sent;console.debug("change rap to dhcp rsp",e);i.disConnect();return t.abrupt("return",Promise.resolve("success"));case 8:case"end":return t.stop()}}},u,this)})).catch(function(e){console.error(e.toString());i.disConnect();return Promise.resolve(e)}).asCallback(a)};exports.resetRap=function(n,a){var c=o(n);var s="ap factory-reset";console.log("command: "+s);var i=new t;return e(regeneratorRuntime.mark(function u(){var e;return regeneratorRuntime.wrap(function n(t){while(1){switch(t.prev=t.next){case 0:t.next=2;return r.connectPro(i,c);case 2:t.next=4;return r.execPro(i,s);case 4:e=t.sent;console.debug("reset rap,",e);i.disConnect();return t.abrupt("return",Promise.resolve("success"));case 8:case"end":return t.stop()}}},u,this)})).catch(function(e){console.error(e.toString());i.disConnect();return Promise.resolve(e)}).asCallback(a)};exports.getMacsOfDuplicateIp=function(a,c){var s=o(a);var i="show log | i Duplicate address "+n.getPkgInfo().spec.info.racHost;console.log("command: "+i);var u=new t;return e(regeneratorRuntime.mark(function p(){var e;return regeneratorRuntime.wrap(function n(t){while(1){switch(t.prev=t.next){case 0:t.next=2;return r.connectPro(u,s);case 2:t.next=4;return r.execPro(u,i);case 4:e=t.sent;console.debug("getMacsOfDuplicateIp rsp",e);u.disConnect();return t.abrupt("return",Promise.resolve(e));case 8:case"end":return t.stop()}}},p,this)})).catch(function(e){console.error(e.toString());u.disConnect();return Promise.resolve(e)}).asCallback(c)}})();