⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csdslider.js

📁  PSoC(可编程片上系统)是Cypress半导体公司生产的包含有8位微处理器核和数字与模拟混合的信号阵列芯片
💻 JS
字号:
//////////////////////////////////////////////////////////////////////////
//  FILENAME:    CSDSLIDER.js
//
//  @Version@
//
//  DESCRIPTION: Generates CSDSLIDER Metadata
//   
//------------------------------------------------------------------------
//  Copyright (c) Cypress MicroSystems 2006. All Rights Reserved.
//////////////////////////////////////////////////////////////////////////

//********************
// Globals
//********************
var g_UM_debug = false; // controls printing output in the script host
var g_UM_BankSwitch_xmlDoc;
var g_UM_BankSwitch_xmlLogicOut;

var g_UM_BankSwitch_BaseIODriver;
var g_UM_BankSwitch_DriverList;
var g_UM_BankSwitch_BasePropertyList;
var g_UM_BankSwitch_NumberOfSwitches;
var g_UM_BankSwitch_SubNameList;
var g_UM_BankSwitch_VariableList;
var g_UM_BankSwitch_ContainerInstanceName;
var g_UM_BankSwitch_PackedInputValName = "Position";

var g_TFListSave	= null;
var g_ValueListSaveTrigger = null;
var g_ValueListSaveStatus = null;
var g_CMXTuningEnabled = null;
var g_CSDSLIDER_InstanceName;

/*************
function setPSoC()
{
	g_UM_BankSwitch_xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	g_UM_BankSwitch_xmlDoc.async = false
	g_UM_BankSwitch_xmlDoc.load("c:\\wtest\\local\\sphinx\\work\\BankSwitchInput.xml")
	//print("Hello from BankSwitch.js");
}
***********/

/***************
function onAccept() 
{
	transformBankSwitch();
	g_UM_BankSwitch_xmlDoc.save("c:\\wtest\\local\\sphinx\\work\\BankSwitchOutput.xml");	
}
***************/


function transformContainer(sInstanceName, sDOM) 
{

	
	g_UM_BankSwitch_xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	g_UM_BankSwitch_xmlDoc.async = false
	g_UM_BankSwitch_xmlDoc.loadXML(sDOM);
	
	try
	{
		g_CSDSLIDER_InstanceName = sInstanceName;
		saveTF();
		saveValueList();
		clearOldData();
		setContainerInstanceName(sInstanceName);
		getNumberofSwitches();
		createSubNameList();
		createVariableList();
		createDriverList();

	}
	catch(kuku)
	{
		alert("Exception in transformContainer " +  kuku);
	}

	return g_UM_BankSwitch_xmlDoc.xml;
}


function saveTF()
{
	g_TFListSave = g_UM_BankSwitch_xmlDoc.selectSingleNode("//CMX_IO_DRIVER/CMX_VARIABLE_CONTAINER/CMX_VARIABLE_LIST/CMX_VARIABLE/CMX_TRANSFERFUNCTION_LIST");
}

function saveValueList()
{
	g_ValueListSaveStatus = g_UM_BankSwitch_xmlDoc.selectSingleNode("//CMX_IO_DRIVER/CMX_VARIABLE_CONTAINER/CMX_VARIABLE_LIST/CMX_VARIABLE/CMX_VALUE_LIST");
}

function clearOldData()
{

	// remove the old stuff and replace with empty elements
	try
	{
		var parent;
		var replacementNode = g_UM_BankSwitch_xmlDoc.createElement("CMX_SUB_NAME_LIST");
		var nodeToRemove = g_UM_BankSwitch_xmlDoc.selectSingleNode("//CMX_IO_DRIVER/CMX_VARIABLE_CONTAINER/CMX_SUB_NAME_LIST");
		if (nodeToRemove != null) 
		{
			parent = nodeToRemove.parentNode;
			parent.removeChild(nodeToRemove);
			parent.appendChild(replacementNode);
		} 

		replacementNode = g_UM_BankSwitch_xmlDoc.createElement("CMX_VARIABLE_LIST");
		nodeToRemove = g_UM_BankSwitch_xmlDoc.selectSingleNode("//CMX_IO_DRIVER/CMX_VARIABLE_CONTAINER/CMX_VARIABLE_LIST");
		if (nodeToRemove != null) 
		{
			parent = nodeToRemove.parentNode;
			parent.removeChild(nodeToRemove);
			parent.appendChild(replacementNode);
		}

		replacementNode = g_UM_BankSwitch_xmlDoc.createElement("CMX_IO_DRIVER_LIST");
		nodeToRemove = g_UM_BankSwitch_xmlDoc.selectSingleNode("//CMX_IO_DRIVER/CMX_VARIABLE_CONTAINER/CMX_IO_DRIVER_LIST");
		if (nodeToRemove != null) 
		{
			parent = nodeToRemove.parentNode;
			parent.removeChild(nodeToRemove);
			parent.appendChild(replacementNode);
		}
	}
	catch(kuku)
	{
		alert("Exception clearOldData " + kuku);
	}
	//end remove the old stuff
}

function getNumberofSwitches()
{
    g_UM_BankSwitch_BaseIODriver = g_UM_BankSwitch_xmlDoc.selectSingleNode("//CMX_IO_DRIVER");
    if (g_UM_BankSwitch_BaseIODriver != null)
    {
		g_UM_BankSwitch_BasePropertyList = g_UM_BankSwitch_BaseIODriver.selectSingleNode("CMX_PROPERTY_LIST");
		if (g_UM_BankSwitch_BasePropertyList != null)
    	{
			var NumberOfSwitchesProperty = g_UM_BankSwitch_BasePropertyList.selectSingleNode("CMX_PROPERTY[@NAME=\"Number of Sensor Pins\"]");
			if (NumberOfSwitchesProperty != null)
    		{
				//print("XPATH is da bomb");
				g_UM_BankSwitch_NumberOfSwitches = parseInt(NumberOfSwitchesProperty.getAttribute("CURRENT_VALUE"));
			}
		}
	}
	else
	{
		//print("Error, BaseIODriver is null\n");
	}
	
	g_CMXTuningEnabled = getContainerTuningEnabled();
}

function setContainerInstanceName(sInstanceName)
{
	var Container = g_UM_BankSwitch_xmlDoc.selectSingleNode("//CMX_IO_DRIVER/CMX_VARIABLE_CONTAINER");
	
	if (Container != null) 
	{
		g_UM_BankSwitch_ContainerInstanceName  = sInstanceName;

		Container.setAttribute("INSTANCE_NAME", sInstanceName);
	} 	
}

//Data looks like:
//<CMX_SUB_NAME NAME="bit0" TYPE="DRIVER" ORDINAL="0"/>
//<CMX_SUB_NAME NAME="packed_val" TYPE="VARIABLE" ORDINAL="1"/>
function createSubNameList()
{
	g_UM_BankSwitch_SubNameList = g_UM_BankSwitch_xmlDoc.selectSingleNode("//CMX_IO_DRIVER/CMX_VARIABLE_CONTAINER/CMX_SUB_NAME_LIST");
	if (g_UM_BankSwitch_SubNameList != null)
    {
		var CMXSubName;
		var OrdinalCount;
		// create the bitN variable sub names
		for (OrdinalCount = 0; OrdinalCount < g_UM_BankSwitch_NumberOfSwitches; OrdinalCount++)
		{
			CMXSubName = g_UM_BankSwitch_xmlDoc.createElement("CMX_SUB_NAME"); // create a sub name
			CMXSubName.setAttribute("NAME", "csdslider"+OrdinalCount);
			CMXSubName.setAttribute("TYPE", "DRIVER");
			CMXSubName.setAttribute("ORDINAL", OrdinalCount);
			g_UM_BankSwitch_SubNameList.appendChild(CMXSubName);
		}

		if(g_CMXTuningEnabled == "Yes")
		{
			for (OrdinalCount = 0; OrdinalCount < g_UM_BankSwitch_NumberOfSwitches; OrdinalCount++)
			{
				// create the packed_input_val2 variable sub name
				CMXSubName = g_UM_BankSwitch_xmlDoc.createElement("CMX_SUB_NAME"); // create a sub name
				var tmp = OrdinalCount;
				CMXSubName.setAttribute("NAME", "Tuning"+tmp+"_Difference");
				CMXSubName.setAttribute("TYPE", "VARIABLE");
		//		CMXSubName.setAttribute("IO_TYPE", "INPUT");
				CMXSubName.setAttribute("ORDINAL", g_UM_BankSwitch_NumberOfSwitches + OrdinalCount);
				g_UM_BankSwitch_SubNameList.appendChild(CMXSubName);
			}
		}
		
		// create the packed_input_val variable sub name
		CMXSubName = g_UM_BankSwitch_xmlDoc.createElement("CMX_SUB_NAME"); // create a sub name
		CMXSubName.setAttribute("NAME", g_UM_BankSwitch_PackedInputValName);
		CMXSubName.setAttribute("TYPE", "VARIABLE");
		CMXSubName.setAttribute("IO_TYPE", "INPUT");
		CMXSubName.setAttribute("ORDINAL", OrdinalCount*2);
		g_UM_BankSwitch_SubNameList.appendChild(CMXSubName);
	}
}

//Data looks like:
//<CMX_VARIABLE NAME="MySwitchBank_packed_val" WRITEABLE="FALSE" VALUE_TYPE="CMX_DISCRETE" DEFAULT_VALUE="" ORDINAL="0" CONTAINER_NAME="MySwitchBank">
//</CMX_VARIABLE>
function createVariableList()
{
	g_UM_BankSwitch_VariableList = g_UM_BankSwitch_xmlDoc.selectSingleNode("//CMX_IO_DRIVER/CMX_VARIABLE_CONTAINER/CMX_VARIABLE_LIST");
	
	if (g_UM_BankSwitch_VariableList != null)
    {
		var CMXVariable;

		// create the packed_input_val variable
		CMXVariable = g_UM_BankSwitch_xmlDoc.createElement("CMX_VARIABLE"); // create a variable
		CMXVariable.setAttribute("NAME", g_UM_BankSwitch_ContainerInstanceName + "_" + g_UM_BankSwitch_PackedInputValName);
		CMXVariable.setAttribute("WRITEABLE", "FALSE");
		CMXVariable.setAttribute("VALUE_TYPE", "CONTINUOUS");
//		CMXVariable.setAttribute("DRIVER_TYPE", "INPUT");
		CMXVariable.setAttribute("DEFAULT_VALUE", "0");
		CMXVariable.setAttribute("ORDINAL", "1");
		CMXVariable.setAttribute("CONTAINER_NAME", g_UM_BankSwitch_ContainerInstanceName);
		CMXVariable.setAttribute("VARIABLE_TYPE", "BYTE");
		CMXVariable.setAttribute("VARIABLE_SIZE", "1");
		CMXVariable.setAttribute("WIDGMIN", "0");
		CMXVariable.setAttribute("WIDGMAX", parseInt(getContainerSliderResolution(), 10)-1);
		CMXVariable.setAttribute("WIDGSCALE", "1");

		if(g_ValueListSaveStatus==null)
		{
			var CMXV_TFList = g_UM_BankSwitch_xmlDoc.createElement("CMX_VALUE_LIST"); // create a tf list
			CMXVariable.appendChild(CMXV_TFList);
		}
		else
		{
			CMXVariable.appendChild(g_ValueListSaveStatus);
		}
		g_UM_BankSwitch_VariableList.appendChild(CMXVariable);
		
		if(g_CMXTuningEnabled == "Yes")
		{
			for (OrdinalCount = 0; OrdinalCount < g_UM_BankSwitch_NumberOfSwitches; OrdinalCount++)
			{
				// create the packed_input2_val variable
				CMXVariable = g_UM_BankSwitch_xmlDoc.createElement("CMX_VARIABLE"); // create a variable
				var tmp = OrdinalCount;
				CMXVariable.setAttribute("NAME", g_UM_BankSwitch_ContainerInstanceName + "_Tuning"+tmp+"_Difference");
				CMXVariable.setAttribute("WRITEABLE", "FALSE");
				CMXVariable.setAttribute("VALUE_TYPE", "CONTINUOUS");
		//		CMXVariable.setAttribute("DRIVER_TYPE", "INPUT");
				CMXVariable.setAttribute("DEFAULT_VALUE", "0");
				CMXVariable.setAttribute("ORDINAL", 2+OrdinalCount);
				CMXVariable.setAttribute("CONTAINER_NAME", g_UM_BankSwitch_ContainerInstanceName);
				CMXVariable.setAttribute("VARIABLE_TYPE", "int");
				CMXVariable.setAttribute("VARIABLE_SIZE", "2");
				CMXVariable.setAttribute("WIDGMIN", "0");
				CMXVariable.setAttribute("WIDGMAX", "32000");
				CMXVariable.setAttribute("WIDGSCALE", "1");
				CMXVariable.setAttribute("TFEXPOSED", "FALSE");

				g_UM_BankSwitch_VariableList.appendChild(CMXVariable);
			}
		}

	}
}

function createDriverList()
{
	g_UM_BankSwitch_DriverList = g_UM_BankSwitch_xmlDoc.selectSingleNode("//CMX_IO_DRIVER/CMX_VARIABLE_CONTAINER/CMX_IO_DRIVER_LIST");
	if (g_UM_BankSwitch_DriverList != null)
    {
		//print("found driver list");
		for (var i = 0; i < g_UM_BankSwitch_NumberOfSwitches; i++)
		{
			var LogicOutDriverElement = getLogicOutDriverElement();
			var DesiredProperty;
			if (LogicOutDriverElement != null)
			{
				// Set instance name
				DesiredProperty = g_UM_BankSwitch_ContainerInstanceName+"_CSD_Slider";
				if (i<10) DesiredProperty += "0";
				LogicOutDriverElement.setAttribute("DRIVER_INSTANCE", DesiredProperty+i);
				// Set the same sub_tree_selection as the Base IO Driver
				LogicOutDriverElement.setAttribute("SUB_TREE_SELECTION", g_UM_BankSwitch_BaseIODriver.getAttribute("SUB_TREE_SELECTION"));
				// Set the Resolution property
				DriveModeProperty = LogicOutDriverElement.selectSingleNode("//CMX_PROPERTY_LIST/CMX_PROPERTY[@NAME=\"SliderResolution\"]");
				DriveModeProperty.setAttribute("CURRENT_VALUE", getContainerSliderResolution());
				// Set the Diplexing property
				DriveModeProperty = LogicOutDriverElement.selectSingleNode("//CMX_PROPERTY_LIST/CMX_PROPERTY[@NAME=\"Diplexing\"]");
				DriveModeProperty.setAttribute("CURRENT_VALUE", getContainerSliderDiplex());
				
				// Set the Index property
				DriveModeProperty = LogicOutDriverElement.selectSingleNode("//CMX_HIDDEN_PROPERTY_LIST/CMX_PROPERTY[@NAME=\"Index\"]");
				DriveModeProperty.setAttribute("CURRENT_VALUE", i);
				// Set the ParentInstance property
				DriveModeProperty = LogicOutDriverElement.selectSingleNode("//CMX_HIDDEN_PROPERTY_LIST/CMX_PROPERTY[@NAME=\"ParentInstance\"]");
				DriveModeProperty.setAttribute("CURRENT_VALUE", g_CSDSLIDER_InstanceName);
				// Append to the IO Driver List
				g_UM_BankSwitch_DriverList.appendChild(LogicOutDriverElement);
			}
		}
	}
}

function getContainerSliderDiplex()
{
    g_UM_BankSwitch_BaseIODriver = g_UM_BankSwitch_xmlDoc.selectSingleNode("//CMX_IO_DRIVER");
    if (g_UM_BankSwitch_BaseIODriver != null)
    {
		g_UM_BankSwitch_BasePropertyList = g_UM_BankSwitch_BaseIODriver.selectSingleNode("CMX_PROPERTY_LIST");
		if (g_UM_BankSwitch_BasePropertyList != null)
    	{
			var BaseDriveModeProperty = g_UM_BankSwitch_BasePropertyList.selectSingleNode("CMX_PROPERTY[@NAME=\"Diplexing\"]");
			if (BaseDriveModeProperty != null)
    		{
				return BaseDriveModeProperty.getAttribute("CURRENT_VALUE");
			}
		}
	}
	else
	{
		return "getContainerDriveMode Script Error";
	}
}

function getContainerSliderResolution()
{
    g_UM_BankSwitch_BaseIODriver = g_UM_BankSwitch_xmlDoc.selectSingleNode("//CMX_IO_DRIVER");
    if (g_UM_BankSwitch_BaseIODriver != null)
    {
		g_UM_BankSwitch_BasePropertyList = g_UM_BankSwitch_BaseIODriver.selectSingleNode("CMX_PROPERTY_LIST");
		if (g_UM_BankSwitch_BasePropertyList != null)
    	{
			var BaseDriveModeProperty = g_UM_BankSwitch_BasePropertyList.selectSingleNode("CMX_PROPERTY[@NAME=\"SliderResolution\"]");
			if (BaseDriveModeProperty != null)
    		{
				return BaseDriveModeProperty.getAttribute("CURRENT_VALUE");
			}
		}
	}
	else
	{
		return "getContainerDriveMode Script Error";
	}
}


function getLogicOutDriverElement()
{
	var LogicOutDriver	= g_pDlg.GetData("GET_CATALOG_IO_DRIVER", "CSDSLIDEBASE", "");
	
	var dm1				= new ActiveXObject("Microsoft.XMLDOM");
	dm1.async			= false
	dm1.loadXML(LogicOutDriver);

	var nodeXML = dm1.selectSingleNode("//CMX_IO_DRIVER");

	return nodeXML;
}	
/***************************
//function print(Output)
//{
//	if (g_UM_debug == true)
//	{
//		WScript.echo(Output);
//	}
//}
****************************/

function getContainerTuningEnabled()
{
    g_UM_BankSwitch_BaseIODriver = g_UM_BankSwitch_xmlDoc.selectSingleNode("//CMX_IO_DRIVER");
    if (g_UM_BankSwitch_BaseIODriver != null)
    {
		g_UM_BankSwitch_BasePropertyList = g_UM_BankSwitch_BaseIODriver.selectSingleNode("CMX_PROPERTY_LIST");
		if (g_UM_BankSwitch_BasePropertyList != null)
    	{
			var BaseDriveModeProperty = g_UM_BankSwitch_BasePropertyList.selectSingleNode("CMX_PROPERTY[@NAME=\"Expose Tuning Values\"]");
			if (BaseDriveModeProperty != null)
    		{
				return BaseDriveModeProperty.getAttribute("CURRENT_VALUE");
			}
		}
	}
	else
	{
		return "getContainerDriveMode Script Error";
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -