//Takes commandCode and returns CommandName from dictionary public string GetCommandName(int commandCode) { SspCommand SspCom = new SspCommand(); if (commandsDictionary.ContainsKey(commandCode)) { SspCom = commandsDictionary[commandCode]; return(SspCom.CommandName); } return("Unknown Command"); }
//Reads data from Resources/Commands.xml private void CSspReadCommandsData() { commandsDictionary = new Dictionary <int, SspCommand>(); XmlDocument document = new XmlDocument(); SspCommand SspCom = new SspCommand(); int i = 0; document.Load("Resources/Commands.xml"); XmlNodeList nodeList = document.DocumentElement.SelectNodes("/Root/CommandInfo"); //Loop through all CommandInfo nodes in /Root. foreach (XmlNode node in nodeList) { //The xml document contains a CommandInfo node for every possible (0x00 to 0xFF) value of CommandCode. //Only process nodes witha a <"CommandName"/> child if (node.SelectSingleNode("CommandName") != null) { i = Int32.Parse(node.SelectSingleNode("CommandCode").InnerText); //Put CommandName into struct SspCom.CommandName = node.SelectSingleNode("CommandName").InnerText; //Add any other elements, if present in xml if (node.SelectSingleNode("Length") != null) { SspCom.Length = Int32.Parse(node.SelectSingleNode("Length").InnerText); } else { SspCom.Length = 0; } if (node.SelectSingleNode("LengthByte") != null) { SspCom.LengthByte = Int32.Parse(node.SelectSingleNode("LengthByte").InnerText); } else { SspCom.LengthByte = 0; } if (node.SelectSingleNode("Multiply") != null) { SspCom.Multiply = Int32.Parse(node.SelectSingleNode("Multiply").InnerText); } else { SspCom.Multiply = 0; } if (node.SelectSingleNode("Add") != null) { SspCom.Add = Int32.Parse(node.SelectSingleNode("Add").InnerText); } else { SspCom.Add = 0; } //Add entry to dictionary commandsDictionary.Add(i, SspCom); } } }