(function(q){var v=new function(){this.MDP=new function(){this.communicationtype=q.DevMan.CommunicationType.mdp;this.getState=function(){return _ModuleContainer.getRequest()};var t=function(f){var e=[],h=_ModuleContainer.getModuleListObj();if(void 0==h)return e;h=h.getModules();if(void 0==h)return e;for(var b=0;b<h.length;b++)h[b].name==f&&e.push(h[b]);return e},u=function(f,e){var h=_ModuleContainer.getModuleListObj().getModules();if(void 0!=h)for(var b=0;b<h.length;b++)if(h[b].name==f&&h[b].id==
e)return h[b]},s=function(f,e,h){var b='<?xml version="1.0" encoding="utf-8"?><s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><u:'+f+' xmlns:u="urn:beckhoff.com:service:cxconfig:1">';if(e)for(var g=0;g<e.length;g++)b+="<"+e[g]+">"+h[g]+"</"+e[g]+">";return b+("</u:"+f+"></s:Body></s:Envelope>")};this.getModuleItemCount=function(f){f=t(f);return void 0!=f?f.length:0};this.getServiceTransferParameterSize=function(f){f=
t(f);if(void 0!=f){for(var e=0,h=0;h<f[0].parameters.length;h++)switch(f[0].parameters[h].type){case "BOOLEAN":e+=1;break;case "SIGNED8":case "UNSIGNED8":e+=1;break;case "SIGNED16":case "UNSIGNED16":e+=2;break;case "SIGNED32":case "UNSIGNED32":e+=4;break;case "UNSIGNED64":break;case "REAL32":e+=4;break;case "STRING":case "VISIBLE STRING":e+=0;break;default:e+=0}return e}return 0};this.SingleCommand=function(f,e,h,b){var g=void 0;this.Start=function(){if(_ModuleContainer.getRequest().hasError)DevManResponse=
new Defines.Response(!0,_ModuleContainer.getRequest().error,void 0,!1);else if(_ModuleContainer.getRequest().isBusy)DevManResponse=new Defines.Response(!1,void 0,void 0,!0);else{g=u(f,e);if(void 0!=g){for(var a=new dataStream.DataWriter,c=0,k=0;k<g.parameters.length;k++){var d=h[k];switch(g.parameters[k].type){case "BOOLEAN":c+=1;break;case "SIGNED8":case "UNSIGNED8":c+=1;break;case "SIGNED16":case "UNSIGNED16":c+=2;break;case "SIGNED32":case "UNSIGNED32":c+=4;break;case "UNSIGNED64":break;case "REAL32":c+=
4;break;case "STRING":case "VISIBLE STRING":c+=d.length;break;default:c+=0}}a.writeDINT(0);a.writeDINT(g.address<<16|g.flags<<8|g.subIndex);a.writeDINT(c);for(k=0;k<g.parameters.length;k++)switch(d=h[k],g.parameters[k].type){case "BOOLEAN":a.writeBOOL(d);break;case "SIGNED8":case "UNSIGNED8":a.writeSINT(d);break;case "SIGNED16":case "UNSIGNED16":a.writeINT(d);break;case "SIGNED32":case "UNSIGNED32":a.writeDINT(d);break;case "REAL32":a.writeREAL(d);break;case "VISIBLE STRING":case "STRING":a.writeString(d,
d.length)}c=[];c.push("netId");c.push("nPort");c.push("indexGroup");c.push("indexOffset");c.push("cbRdLen");c.push("pwrData");k=[];k.push("");k.push("0");k.push(61569);k.push(1);k.push(4);k.push(a.getBase64EncodedData());a=s("ReadWrite",c,k);return q.DevMan.getSoapQueue().AddRequest(a,"ReadWrite",m)}a=new dataStream.RequestError(-1,"Unknown Function");DevManResponse=new Defines.Response(!0,a,void 0,!1)}void 0!=b&&"function"==typeof b&&b(DevManResponse)};var m=function(){l()},l=function(){var a=[];
a.push(g.name+"_State");a.push(g.name+"_Result");(new v.MDP.Request(a,d)).Start()},d=function(a){var c=void 0;if(a.hasError)c=new Defines.Response(!0,a.error,void 0,!1);else{c=new Defines.ServiceTransferResponse;c.moduleItem=g;var d=a.data[0].value[e];if(0!=a.data[1].error)c.hasError=!0,c.hasResult=!0,c.errCode=a.data[1].error;else{a=a.data[1].value[e];switch(d){case 0:c.hasError=!1;c.hasResult=!1;break;case 1:c.hasError=!1;c.hasResult=!0;c.result=a;a.charCodeAt(0);a.charCodeAt(1);break;case 2:c.hasError=
!0;c.hasResult=!1;break;case 3:c.hasError=!0,c.hasResult=!0,a.charCodeAt(0),a.charCodeAt(1),a=(a.charCodeAt(5)<<24|a.charCodeAt(4)<<16|a.charCodeAt(3)<<8|a.charCodeAt(2))>>>0,c.errCode=a}100<=d&&200>=d?(c.isBusy=!0,c.hasPercentage=!0,c.percentage=d-100,100>c.percentage&&setTimeout(l,200)):255==d&&(c.isBusy=!0,c.hasPercentage=!1,setTimeout(l,200))}c=new Defines.Response(!1,void 0,c,!1)}void 0!=b&&"function"==typeof b&&b(c)}};this.Request=function(f,e){var h=0,b=0;this.Start=function(){if(_ModuleContainer.getRequest().hasError)DevManResponse=
new Defines.Response(!0,_ModuleContainer.getRequest().error,void 0,!1),void 0!=e&&"function"==typeof e&&e(DevManResponse);else if(_ModuleContainer.getRequest().isBusy)DevManResponse=new Defines.Response(!1,void 0,void 0,!0),void 0!=e&&"function"==typeof e&&e(DevManResponse);else{for(var m="",m=new dataStream.DataWriter,l=0;l<f.length;l++)for(var d=t(f[l]),a=0;a<d.length;a++)h++,m.writeDINT(0),m.writeDINT(d[a].address<<16|d[a].flags<<8|d[a].subIndex),m.writeDINT(d[a].size),b+=d[a].size;return 0<h?
(b+=8*h,l=[],l.push("netId"),l.push("nPort"),l.push("indexGroup"),l.push("indexOffset"),l.push("cbRdLen"),l.push("pwrData"),d=[],d.push(""),d.push("0"),d.push(61568),d.push(h),d.push(b),d.push(m.getBase64EncodedData()),m=s("ReadWrite",l,d),q.DevMan.getSoapQueue().AddRequest(m,"ReadWrite",g)):!1}};var g=function(b){if(b.hasError)b=new Defines.Response(!0,b.error,void 0,!1);else{b=b.reader;for(var g=[],d=[],a=0;a<f.length;a++){for(var c=t(f[a]),k=[],h=[],p=0;p<c.length;p++)k.push(CommunicationModule_ERROR.UPnPErrToMdpErr(b.readDWORD())),
h.push(b.readDWORD());g.push(k);d.push(h)}k=[];for(a=0;a<f.length;a++){c=t(f[a]);h=[];for(p=0;p<c.length;p++)if(0==g[a][p]){switch(c[p].type){case "BOOLEAN":h.push(b.readBOOL());break;case "SIGNED8":h.push(b.readSINT());break;case "UNSIGNED8":h.push(b.readBYTE());break;case "SIGNED16":h.push(b.readINT());break;case "UNSIGNED16":h.push(b.readWORD());break;case "SIGNED32":h.push(b.readDINT());break;case "UNSIGNED32":h.push(b.readDWORD());break;case "UNSIGNED64":var n=b.readDWORD();0<b.readDWORD()&&
(n=-1);h.push(n);break;case "REAL32":h.push(b.readREAL());break;case "VISIBLE STRING":h.push(Helper.StringCut(b.readString(d[a][p])))}n=_ModuleContainer.getModuleListObj().IsArray(c[p].name);void 0!=n&&(n=new Defines.ArrayInfo(c[p],n[0],n[1],h[p]),h[p]=n)}c=new Defines.ValueInfo(f[a],h,g[a]);k.push(c)}b=new Defines.Response(!1,void 0,k,!1)}void 0!=e&&"function"==typeof e&&e(b)}};this.ArrayRequest=function(f,e){this.Start=function(){for(var b=0,g="",g=new dataStream.DataWriter,e=1;e<=f.length;e++){var l=
f.moduleItem.address,d=e,a=f.size;g.writeDINT(0);g.writeDINT(l<<16|0|d);g.writeDINT(a);b+=a}return 0<f.length?(b+=8*f.length,e=[],e.push("netId"),e.push("nPort"),e.push("indexGroup"),e.push("indexOffset"),e.push("cbRdLen"),e.push("pwrData"),l=[],l.push(""),l.push("0"),l.push(61568),l.push(f.length),l.push(b),l.push(g.getBase64EncodedData()),g=s("ReadWrite",e,l),q.DevMan.getSoapQueue().AddRequest(g,"ReadWrite",h)):!1};var h=function(b){if(b.hasError)g=new Defines.ValueInfo(f.moduleItem,"",""),b=new Defines.Response(!0,
b.error,g,!1);else{b=b.reader;for(var g=[],h=[],l=0;l<f.length;l++)g.push(CommunicationModule_ERROR.UPnPErrToMdpErr(b.readDWORD())),h.push(b.readDWORD());for(var d=[],l=0;l<f.length;l++)if(0==g[l])switch(f.type){case "BOOLEAN":d.push(b.readBOOL());break;case "SIGNED8":d.push(b.readSINT());break;case "UNSIGNED8":d.push(b.readBYTE());break;case "SIGNED16":d.push(b.readINT());break;case "UNSIGNED16":d.push(b.readWORD());break;case "SIGNED32":d.push(b.readDINT());break;case "UNSIGNED32":d.push(b.readDWORD());
break;case "UNSIGNED64":var a=b.readDWORD();0<b.readDWORD()&&(a=-1);d.push(a);break;case "REAL32":d.push(b.readREAL());break;case "VISIBLE STRING":d.push(Helper.StringCut(b.readString(h[l])))}else d.push("");var g=new Defines.ValueInfo(f.moduleItem,d,g);b=new Defines.Response(!1,void 0,g,!1)}void 0!=e&&"function"==typeof e&&e(b)}};this.Writer=function(f,e,h,b){var g=0,m=[];this.Start=function(){g=0;if(_ModuleContainer.getRequest().hasError)DevManResponse=new Defines.Response(!0,_ModuleContainer.getRequest().error,
void 0,!1),void 0!=b&&"function"==typeof b&&b(DevManResponse);else if(_ModuleContainer.getRequest().isBusy)DevManResponse=new Defines.Response(!1,void 0,void 0,!0),void 0!=b&&"function"==typeof b&&b(DevManResponse);else{for(var d=new dataStream.DataWriter,a=0;a<f.length;a++){var c=u(f[a],e[a]);if(void 0!=c&&("read-write"==c.access||"write-only"==c.access)){var k=c.size;"VISIBLE STRING"==c.type&&(k=h[a].length);d.writeDINT(0);d.writeDINT(c.address<<16|c.flags<<8|c.subIndex);d.writeDINT(k);g++;m.push(c)}}for(a=
0;a<f.length;a++)if(c=u(f[a],e[a]),void 0!=c&&(k=h[a],"read-write"==c.access||"write-only"==c.access))switch(c.type){case "BOOLEAN":d.writeBOOL(k);break;case "SIGNED8":d.writeSINT(k);case "UNSIGNED8":d.writeBYTE(k);break;case "SIGNED16":d.writeINT(k);case "UNSIGNED16":d.writeWORD(k);break;case "SIGNED32":d.writeDINT(k);case "UNSIGNED32":d.writeDWORD(k);break;case "REAL32":d.writeREAL(k);break;case "VISIBLE STRING":d.writeString(k,k.length)}return 0<g?(a=[],a.push("netId"),a.push("nPort"),a.push("indexGroup"),
a.push("indexOffset"),a.push("cbRdLen"),a.push("pwrData"),c=[],c.push(""),c.push("0"),c.push(61569),c.push(g),c.push(4*g),c.push(d.getBase64EncodedData()),d=s("ReadWrite",a,c),q.DevMan.getSoapQueue().AddRequest(d,"ReadWrite",l)):!1}};var l=function(d){var a=void 0;if(d.hasError)a=new Defines.Response(!0,d.error,void 0,!1);else{d=d.reader;for(var a=[],c=0;c<g;c++){var e=d.readDWORD(),e=CommunicationModule_ERROR.UPnPErrToMdpErr(e);a.push(e)}d=new Defines.WriteResponse(m,a);a=new Defines.Response(!1,
void 0,d,!1)}void 0!=b&&"function"==typeof b&&b(a)}};this.ArrayWriter=function(f,e,h,b,g){var m=0,l=[];this.Start=function(){m=0;if(_ModuleContainer.getRequest().hasError)DevManResponse=new Defines.Response(!0,_ModuleContainer.getRequest().error,void 0,!1),void 0!=g&&"function"==typeof g&&g(DevManResponse);else if(_ModuleContainer.getRequest().isBusy)DevManResponse=new Defines.Response(!1,void 0,void 0,!0),void 0!=g&&"function"==typeof g&&g(DevManResponse);else{for(var a=new dataStream.DataWriter,
c=0;c<f.length;c++){var k=u(f[c],e[c]);if(void 0!=k){var r=_ModuleContainer.getModuleListObj().IsArray(k.name);if(r){var p=r[0],r=r[1];"VISIBLE STRING"==p&&(r=b[c].length);a.writeDINT(0);a.writeDINT(k.address<<16|0|k.subIndex+h[c]);a.writeDINT(r);m++;l.push(k)}}}for(c=0;c<f.length;c++)if(k=u(f[c],e[c]),void 0!=k){var n=b[c];if(r=_ModuleContainer.getModuleListObj().IsArray(k.name))switch(p=r[0],p){case "BOOLEAN":a.writeBOOL(n);break;case "SIGNED8":a.writeSINT(n);case "UNSIGNED8":a.writeBYTE(n);break;
case "SIGNED16":a.writeINT(n);case "UNSIGNED16":a.writeWORD(n);break;case "SIGNED32":a.writeDINT(n);case "UNSIGNED32":a.writeDWORD(n);break;case "REAL32":a.writeREAL(n);break;case "VISIBLE STRING":a.writeString(n,n.length)}}return 0<m?(c=[],c.push("netId"),c.push("nPort"),c.push("indexGroup"),c.push("indexOffset"),c.push("cbRdLen"),c.push("pwrData"),k=[],k.push(""),k.push("0"),k.push(61569),k.push(m),k.push(4*m),k.push(a.getBase64EncodedData()),a=s("ReadWrite",c,k),q.DevMan.getSoapQueue().AddRequest(a,
"ReadWrite",d)):!1}};var d=function(a){var c=void 0;if(a.hasError)c=new Defines.Response(!0,a.error,void 0,!1);else{a=a.reader;for(var c=[],b=0;b<m;b++){var d=a.readDWORD(),d=CommunicationModule_ERROR.UPnPErrToMdpErr(d);c.push(d)}a=new Defines.WriteResponse(l,c);c=new Defines.Response(!1,void 0,a,!1)}void 0!=g&&"function"==typeof g&&g(c)}};_ModuleContainer=new function(){var f=new Defines.Response(!1,void 0,void 0,!0);this.getRequest=function(){return f};this.getModuleListObj=function(){return f.hasError||
f.isBusy?void 0:f.data};this.GetModules=function(){e()};var e=function(){var b=new dataStream.DataWriter;b.writeDINT(0);b.writeDINT(-266338048);b.writeDINT(1024);var e=[];e.push("netId");e.push("nPort");e.push("indexGroup");e.push("indexOffset");e.push("cbRdLen");e.push("pwrData");var f=[];f.push("");f.push(0);f.push(61568);f.push(1);f.push(1024);f.push(b.getBase64EncodedData());b=s("ReadWrite",e,f);q.DevMan.getSoapQueue().AddRequest(b,"ReadWrite",h)},h=function(b){if(b.hasError)b.isBusy?f=new Defines.Response(!1,
void 0,void 0,!0):b.hasError&&(f=new Defines.Response(!0,b.error,void 0,!1),setTimeout(e,1E3));else{b=b.reader;b.offset=0;b.readDWORD();b.readDWORD();ModuleCount=b.readSINT();b.offset++;for(var g=[],h=[],l=[],d=0;d<ModuleCount;d++){var a=b.readINT(),a=(16>a?"0":"")+a.toString(16)+"0";g.push(parseInt("0x8"+a,16));h.push(parseInt("0xB"+a,16));l.push(b.readINT())}f=new Defines.Response(!1,void 0,new q.CommunicationModule_moduleList.moduleList(g,h,l),!1)}}};_ModuleContainer.GetModules()}};q.DevMan.RegisterModule(v.MDP,
q.DevMan.ModuleType.CommunicationModule)})(window);
