EipJsonTransformXml.prototype._ICPDASEIPDri_ = function()
{	
	var Class = new LoadFile();
	var EipModule = Class.ReadFile("./File/EIP_Module/Module.json", new Object());
	var EipSetting = Class.ReadFile("./File/EIP_Module/EipSetting.json", new Object());
	
	var EipVariable = Class.ReadFile("./File/EIP_Module/EipVariable.json", new Object());
	
	var EipConnectionParameters = Class.ReadFile("./File/EIP_Module/ConnectionParameters.json", new Object());
	var EipProductSpecification = Class.ReadFile("./File/EIP_Module/ProductSpecification.json", new Object());

	var IndexKey = Object.keys(EipModule["LAN"]);
	
	var EipDriData = new Object();
	EipDriData["EtherNetIPDriver"] = new Object();
	EipDriData["EtherNetIPDriver"]["EIPTask"] = new Array();

	for(var i=0; i<IndexKey.length; i++)
	{
		EipDriData["EtherNetIPDriver"]["EIPTask"][i] = new Object();
		var ModuleName = EipModule["LAN"][IndexKey[i]]["ModuleName"];
		//var ModuleName = EipSetting[IndexKey[i]]["NickName"];

		EipDriData["EtherNetIPDriver"]["EIPTask"][i]["AssemblyData"] = new Object();
		var EipDriAssemblyData = EipDriData["EtherNetIPDriver"]["EIPTask"][i]["AssemblyData"];
		EipJsonTransformXml.prototype._GetEipDriAssemblyData_(EipConnectionParameters, EipDriAssemblyData, ModuleName);
		
		var EipDriTaskData = EipDriData["EtherNetIPDriver"]["EIPTask"][i];
		EipJsonTransformXml.prototype._GetEipDriTaskData_(EipDriTaskData, EipSetting, IndexKey[i], ModuleName);
		
		/*var EipDriTaskData = EipDriData["EtherNetIPDriver"]["EIPTask"][i];
		EipDriTaskData["IP"] = EipSetting[IndexKey[i]]["IP"];
		EipDriTaskData["PollingRate"] = 100;
		EipDriTaskData["TaskID"] = -1;
		EipDriTaskData["TaskName"] = ModuleName;

		/*EipDriData["EtherNetIPDriver"]["EIPTask"][i]["IP"] = EipSetting[IndexKey[i]]["IP"];
		EipDriData["EtherNetIPDriver"]["EIPTask"][i]["PollingRate"] = 100;
		EipDriData["EtherNetIPDriver"]["EIPTask"][i]["TaskID"] = -1;
		EipDriData["EtherNetIPDriver"]["EIPTask"][i]["TaskName"] = ModuleName;*/

		EipDriData["EtherNetIPDriver"]["EIPTask"][i]["EIPItem"] = new Array();
		var ChannelTick = parseInt(EipSetting[IndexKey[i]]["ModeType"].split("-")[0]);

		for(var j = 0; j<ChannelTick;j++)
		{
			EipDriData["EtherNetIPDriver"]["EIPTask"][i]["EIPItem"][j] = new Object();
			
			var EipVariableKey = Object.keys(EipVariable[IndexKey[i]]);
			var TypeString = EipVariableKey[j].split("-")[0];
			
			var moduleId = parseInt(EipModule["LAN"][IndexKey[i]]["ModuleName"].split("-")[1]);
			var I_O_Property = EipJsonTransformXml.prototype._GetIOPropertyIndex_(TypeString);
			var channel = EipVariableKey[j].split("-")[2];
			var NickName = EipSetting[IndexKey[i]]["NickName"];
			EipDriData["EtherNetIPDriver"]["EIPTask"][i]["EIPItem"][j]["Name"] = "EIP_No." + IndexKey[i] + "_" + NickName + "_" + TypeString + "." + EipVariable[IndexKey[i]][EipVariableKey[j]]["VariableName"];
			EipDriData["EtherNetIPDriver"]["EIPTask"][i]["EIPItem"][j]["Property"] = I_O_Property;
			EipDriData["EtherNetIPDriver"]["EIPTask"][i]["EIPItem"][j]["IsReverse"] = 0;

			EipDriData["EtherNetIPDriver"]["EIPTask"][i]["EIPItem"][j]["InputByteOffset"] = EipJsonTransformXml.prototype._GetInputOffset_(moduleId, I_O_Property, channel);
			EipDriData["EtherNetIPDriver"]["EIPTask"][i]["EIPItem"][j]["OutputByteOffset"] = EipJsonTransformXml.prototype._GetOutputOffset_(moduleId, I_O_Property, channel);;
		}
	}
	EipDriData = EipJsonTransformXml.prototype._EipSortTaskId_(EipDriData);
	var xotree = new XML.ObjTree();
	var xml = xotree.writeXML(EipDriData);
	return xml;
}
EipJsonTransformXml.prototype._GetEipDriAssemblyData_ = function(EipConnectionParameters, EipDriAssemblyData, ModuleName)
{
	//EipDriAssemblyData = new Object();
	EipDriAssemblyData["InputAssembly"] = EipConnectionParameters[ModuleName]["Assembly"]["Input"];
	EipDriAssemblyData["InputByteSize"] = EipConnectionParameters[ModuleName]["Size"]["Input"];
	EipDriAssemblyData["OutputAssembly"] = EipConnectionParameters[ModuleName]["Assembly"]["Output"];
	EipDriAssemblyData["OutputByteSize"] = EipConnectionParameters[ModuleName]["Size"]["Output"];
}		
EipJsonTransformXml.prototype._GetEipDriTaskData_ = function(EipDriTaskData, EipSetting, number, ModuleName)
{		
	EipDriTaskData["IP"] = EipSetting[number]["IP"];
	EipDriTaskData["PollingRate"] = 100;
	EipDriTaskData["TaskID"] = -1;
	EipDriTaskData["TaskName"] = EipSetting[number]["NickName"];
	EipDriTaskData["ModuleName"] = ModuleName.split("-")[1];
}
EipJsonTransformXml.prototype._GetIOPropertyIndex_ = function(string)
{
	//var I_O = { "AI": 1, "AO": 2, "DI": 3, "DO":4,"DICounter":5,"Counter":6}
	if(string=='AI')
		return 1;
	else if(string=='AO')
		return 2;
	else if(string=='DI')
		return 3;
	else if(string=='DO')
		return 4;
}

EipJsonTransformXml.prototype._GetInputOffset_ = function(moduleId, I_O_Property, channel)
{
	var Segment = "";

    switch (I_O_Property) {
        case 1:
            switch (moduleId) {
                case 2017:
                case 2019:
                    Segment = channel*2;
                    break;
            }
            break;
        case 2:
            break;
        case 3:
            switch (moduleId) {
                case 2051:
                case 2055:
                case 2060:
                    Segment = parseInt(channel / 8) + "@" + channel % 8;
                    break;
            }
            break;
        case 4:
            switch (moduleId) {
                case 2042:
                    Segment = parseInt(channel / 8) + "@" + channel % 8;
                    break;
                case 2055:
                case 2060:
                    Segment = 1+parseInt(channel / 8) + "@" + channel % 8;
                    break;
            }
            break;
        case 5:
            switch (moduleId) {
                case 2051:
                case 2060:
                    Segment = 2 + channel * 4;
                    break;
            }
            break;
        default:
            break;
    }
    return Segment;
}

EipJsonTransformXml.prototype._GetOutputOffset_ = function(moduleId, I_O_Property, channel)
{
	var Segment = "";

    switch (I_O_Property)
    {
        case 4:
            switch (moduleId)
            {
                case 2042:
                case 2055:
                case 2060:
                    Segment = parseInt(channel / 8) + "@" + channel % 8;
                    break;
            }
            break;
        default:
            break;
    }
    return Segment;
}

EipJsonTransformXml.prototype._EipSortTaskId_ = function(object) {
    var length = object["EtherNetIPDriver"]["EIPTask"].length;
    for (var i = 0; i < length; i++) {
        object["EtherNetIPDriver"]["EIPTask"][i]["TaskID"] = i;
    }
    return object;
}