public EZRadio2Config(string chipType, string chipRevision) { _chipType = chipType; _chipRev = chipRevision; _chipApiDescriptor = new ChipCommandAndPpropertyDescriptor(); _chipApiDescriptor.createDescriptorFromXML("Si4460", _chipRev); }
public Pro2ApiCommandManager(string chipType, string chipRevision) { this.ChipType = chipType; this.ChipRevision = chipRevision; this._chipApiDescriptor = new ChipCommandAndPpropertyDescriptor(); this._chipApiDescriptor.createDescriptorFromXML(this.ChipType, this.ChipRevision); this._configurationCommands = new List<PRO2_Command>(); }
public static TelegramContainerItem[] createTelegramsFromBatchString(string commands, IIOPortHandler ioph, IAppMainWindow mainWin, bool ctsPoll, DeviceRegisterSet deviceRegSet, ChipCommandAndPpropertyDescriptor chipApiDescriptor, out string errorMessage) { errorMessage = "No Error"; string[] strArray = commands.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); List<TelegramContainerItem> list = new List<TelegramContainerItem>(); bool flag = false; for (int i = 0; i < strArray.Length; i++) { Telegram telegram; LastReplyPrecondition invalid; byte[] buffer; byte[][] bufferArray4; byte[] buffer8; flag = false; if ((strArray[i].Trim().Length >= 2) && !strArray[i].Trim().StartsWith("#")) { if (strArray[i].Trim().ToUpper().StartsWith("DELAY")) { int num2; if (int.TryParse(strArray[i].Trim().ToUpper().Replace("DELAY", "").Trim(), out num2)) { list.Add(new TelegramContainerItem(num2)); } } else if (strArray[i].Trim().ToUpper().StartsWith("RESET")) { bufferArray4 = new byte[5][]; bufferArray4[0] = new byte[] { 0x12, 6, 1, 0 }; bufferArray4[1] = new byte[] { 0x13, 6, 1 }; buffer8 = new byte[3]; buffer8[0] = 0x13; buffer8[1] = 6; bufferArray4[2] = buffer8; byte[] buffer9 = new byte[4]; buffer9[0] = 0x12; buffer9[1] = 0x1b; bufferArray4[3] = buffer9; bufferArray4[4] = new byte[] { 20, 0x1b }; byte[][] bufferArray = bufferArray4; LastReplyPrecondition[] preconditionArray = new LastReplyPrecondition[] { LastReplyPrecondition.ACK, LastReplyPrecondition.ACK, LastReplyPrecondition.ACK, LastReplyPrecondition.ACK, LastReplyPrecondition.DataACK }; for (int j = 0; j < bufferArray.Length; j++) { telegram = new Telegram(bufferArray[j].Length) { uniqId = GlobalServices.uniqTelegramId(), parentUniqId = -1, type = TelegramType.Command }; if (ioph is IOPH_DCP) { telegram.protocol = Protocol.DCP; telegram.DCPCmdSet = 4; } else { telegram.protocol = Protocol.DCP2; telegram.DCPCmdSet = 0x1c; } telegram.lastReplyPrecondition = preconditionArray[j]; telegram.replySize = 15; telegram.UserData = new object[] { false }; if (j == 0) { telegram.SenderInfo = new object[] { strArray[i].Trim(new char[] { '\r' }).Trim() }; telegram.UserDataExt.addUserData("CmdName", strArray[i].Trim(new char[] { '\r' }).Trim()); } if (telegram.replySize == -1) { throw new Exception("Not supported command."); } telegram.data.copy(bufferArray[j]); telegram.portHandler = ioph; telegram.mainWin = mainWin; list.Add(new TelegramContainerItem(telegram)); } } else if (strArray[i].Trim().ToUpper().StartsWith("SHUTDOWN")) { byte[][] bufferArray2 = new byte[][] { new byte[] { 0x12, 6, 1, 0 }, new byte[] { 0x13, 6, 1 } }; LastReplyPrecondition[] preconditionArray2 = new LastReplyPrecondition[] { LastReplyPrecondition.ACK, LastReplyPrecondition.ACK }; for (int k = 0; k < bufferArray2.Length; k++) { telegram = new Telegram(bufferArray2[k].Length) { uniqId = GlobalServices.uniqTelegramId(), parentUniqId = -1, type = TelegramType.Command }; if (ioph is IOPH_DCP) { telegram.protocol = Protocol.DCP; telegram.DCPCmdSet = 4; } else { telegram.protocol = Protocol.DCP2; telegram.DCPCmdSet = 0x1c; } telegram.lastReplyPrecondition = preconditionArray2[k]; telegram.replySize = 15; telegram.UserData = new object[] { false }; if (k == 0) { telegram.UserDataExt.addUserData("CmdName", strArray[i].Trim(new char[] { '\r' }).Trim()); telegram.SenderInfo = new object[] { strArray[i].Trim(new char[] { '\r' }).Trim() }; } if (telegram.replySize == -1) { throw new Exception("Not supported command."); } telegram.data.copy(bufferArray2[k]); telegram.portHandler = ioph; telegram.mainWin = mainWin; list.Add(new TelegramContainerItem(telegram)); } } else { if (!strArray[i].Trim().ToUpper().StartsWith("DCP")) { goto Label_064D; } invalid = LastReplyPrecondition.Invalid; buffer = new byte[1]; if (strArray[i].Trim().Length <= 3) { goto Label_0523; } switch (strArray[i].Trim().ToUpper()[3]) { case 'A': invalid = LastReplyPrecondition.ACK; goto Label_04F9; case 'D': invalid = LastReplyPrecondition.DataACK; goto Label_04F9; case 'I': invalid = LastReplyPrecondition.Indication; goto Label_04F9; } } } continue; Label_04F9: buffer = WDSConverters.ToByteArray(strArray[i].Substring(4).Trim().Replace(" ", "").ToUpper()); Label_0523: telegram = new Telegram(buffer.Length); telegram.uniqId = GlobalServices.uniqTelegramId(); telegram.parentUniqId = -1; telegram.type = TelegramType.Command; if (ioph is IOPH_DCP) { telegram.protocol = Protocol.DCP; telegram.DCPCmdSet = 4; } else { telegram.protocol = Protocol.DCP2; telegram.DCPCmdSet = 0x1c; } telegram.lastReplyPrecondition = invalid; telegram.replySize = 15; telegram.UserData = new object[] { false }; telegram.SenderInfo = new object[] { strArray[i].Trim(new char[] { '\r' }).Trim() }; telegram.UserDataExt.addUserData("CmdName", strArray[i].Trim(new char[] { '\r' }).Trim()); if (telegram.replySize == -1) { throw new Exception("Not supported command."); } telegram.data.copy(buffer); telegram.portHandler = ioph; telegram.mainWin = mainWin; list.Add(new TelegramContainerItem(telegram)); continue; Label_064D: if (strArray[i].Trim().ToUpper().StartsWith("RAM")) { string str; if (!getDataFromFwLoadCommand(strArray[i].Trim(), out str)) { _log.Error("Cannot create RAM Load telegram from command string"); } else { string str2; StreamReader reader = File.OpenText(str); byte[] buf = new byte[0x800]; int index = 0; while (((str2 = reader.ReadLine()) != null) && (index < buf.Length)) { if (byte.TryParse(str2, NumberStyles.HexNumber, (IFormatProvider) null, out buf[index])) { index++; } } if (index == 0) { _log.Error("Could not read any RAM data from the RAM Load file"); } else { bufferArray4 = new byte[0x11][]; buffer8 = new byte[4]; buffer8[0] = 0x10; buffer8[3] = 1; bufferArray4[0] = buffer8; bufferArray4[1] = new byte[] { 0x10, 3, 0, 7, 80 }; bufferArray4[2] = new byte[] { 0x10, 4, 0, 7, 80, 0 }; bufferArray4[3] = new byte[] { 0x10, 4, 0, 7, 80, 0 }; bufferArray4[4] = new byte[] { 0x10, 3, 0, 7, 80 }; bufferArray4[5] = new byte[] { 0x10, 4, 0, 0x6d, 80, 1 }; bufferArray4[6] = new byte[] { 0x10, 4, 0, 1, 80, 0xff }; bufferArray4[7] = new byte[] { 0x10, 4, 0, 0xac, 80, 0x1f }; bufferArray4[8] = new byte[] { 0x10, 7, 0, 0x94, 0x54, 0x53 }; bufferArray4[9] = new byte[] { 0x10, 7, 0, 0x95, 0x54, 0x30 }; bufferArray4[10] = new byte[] { 0x10, 0x45, 0, 0x88 }; buffer8 = new byte[3]; buffer8[0] = 0x10; buffer8[1] = 0x85; bufferArray4[11] = buffer8; buffer8 = new byte[3]; buffer8[0] = 0x10; buffer8[1] = 0xc5; bufferArray4[12] = buffer8; bufferArray4[13] = new byte[] { 0x10, 3, 0, 7, 80 }; bufferArray4[14] = new byte[] { 0x10, 4, 0, 7, 80, 9 }; bufferArray4[15] = new byte[] { 0x10, 4, 0, 7, 80, 9 }; bufferArray4[0x10] = new byte[] { 0x10, 3, 0, 7, 80 }; byte[][] bufferArray3 = bufferArray4; int num6 = 0; for (int m = 0; m < bufferArray3.Length; m++) { telegram = new Telegram(bufferArray3[m].Length) { uniqId = GlobalServices.uniqTelegramId(), parentUniqId = -1, type = TelegramType.Command }; if (ioph is IOPH_DCP) { telegram.protocol = Protocol.DCP; telegram.DCPCmdSet = 4; } else { telegram.protocol = Protocol.DCP2; telegram.DCPCmdSet = 0x1c; } telegram.lastReplyPrecondition = LastReplyPrecondition.Indication; telegram.replySize = 15; telegram.UserData = new object[] { false }; if (m == 0) { telegram.UserDataExt.addUserData("CmdName", strArray[i].Trim(new char[] { '\r' }).Trim()); telegram.SenderInfo = new object[] { strArray[i].Trim(new char[] { '\r' }).Trim() }; } if (telegram.replySize == -1) { throw new Exception("Not supported command."); } telegram.data.copy(bufferArray3[m]); if ((m == 11) && (num6 < 0x10)) { telegram.data.appendFromStartIdx(buf, num6 * 0x79, 0x79); num6++; m--; } else if (m == 12) { telegram.data.appendFromStartIdx(buf, buf.Length - 0x70, 0x70); } else if (m == 11) { continue; } telegram.portHandler = ioph; telegram.mainWin = mainWin; list.Add(new TelegramContainerItem(telegram)); } } } } else if (strArray[i].Trim().ToUpper().StartsWith("PATCH")) { string str3; if (!getDataFromFwLoadCommand(strArray[i].Trim(), out str3)) { _log.Error("Cannot create PATCH Load telegram from command string"); } else { string str4; StreamReader reader2 = File.OpenText(str3); List<byte[]> list2 = new List<byte[]>(); while ((str4 = reader2.ReadLine()) != null) { byte[] item = new byte[8]; if (!str4.Trim().StartsWith("#")) { string[] strArray2 = str4.Split(new char[] { ',' }); for (int n = 0; (n < strArray2.Length) && (n < item.Length); n++) { string s = strArray2[n]; if (strArray2[n].StartsWith("0x")) { s = s.Substring(2); } if (!byte.TryParse(s, NumberStyles.HexNumber, (IFormatProvider) null, out item[n])) { _log.Error("Invalid data in PATCH Load file"); } } list2.Add(item); } } if (list2.Count == 0) { _log.Error("Could not read any PATCH data from the RAM Load file"); } else { buffer8 = new byte[3]; buffer8[0] = 0x10; byte[] buffer4 = buffer8; byte[] buffer5 = new byte[] { 0x10, 0, 0, 0x44, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; for (int num9 = 0; num9 < (list2.Count * 2); num9++) { telegram = new Telegram(10) { uniqId = GlobalServices.uniqTelegramId(), parentUniqId = -1, type = TelegramType.Command }; if (ioph is IOPH_DCP) { telegram.protocol = Protocol.DCP; telegram.DCPCmdSet = 4; } else { telegram.protocol = Protocol.DCP2; telegram.DCPCmdSet = 0x1c; } telegram.lastReplyPrecondition = LastReplyPrecondition.Indication; telegram.replySize = 15; if (num9 == 0) { telegram.UserDataExt.addUserData("CmdName", strArray[i].Trim(new char[] { '\r' }).Trim()); telegram.SenderInfo = new object[] { strArray[i].Trim(new char[] { '\r' }).Trim() }; } if (telegram.replySize == -1) { throw new Exception("Not supported command."); } if ((num9 % 2) == 0) { telegram.data.copy(buffer4); telegram.data.appendFromStartIdx(list2[num9 / 2], 0, list2[num9 / 2].Length); } else { telegram.data.copy(buffer5); } telegram.portHandler = ioph; telegram.mainWin = mainWin; list.Add(new TelegramContainerItem(telegram)); } } } } else if (strArray[i].Trim().ToUpper().StartsWith("TCL")) { int num10; string str6; if (!getDataFromTclCommand(strArray[i].Trim(), out num10, out str6)) { _log.Error("Cannot create TCL telegram from command string"); } else { telegram = new Telegram(str6.Length) { TimeOut = num10 * 0x3e8, uniqId = GlobalServices.uniqTelegramId(), parentUniqId = -1, type = TelegramType.ExecuteTclScript }; if (ioph is IOPH_DCP) { telegram.protocol = Protocol.DCP; telegram.DCPCmdSet = 4; } else { telegram.protocol = Protocol.DCP2; telegram.DCPCmdSet = 0x1c; } telegram.replySize = 15; telegram.UserData = new object[] { false }; telegram.SenderInfo = new object[] { strArray[i].Trim(new char[] { '\r' }).Trim() }; telegram.UserDataExt.addUserData("CmdName", strArray[i].Trim(new char[] { '\r' }).Trim()); if (telegram.replySize == -1) { throw new Exception("Not supported command."); } telegram.data.copy(str6); telegram.userData = 3; telegram.portHandler = ioph; telegram.mainWin = mainWin; list.Add(new TelegramContainerItem(telegram)); } } else { int numberOfReplyData = 0; List<byte> list3 = new List<byte>(); string[] strArray3 = strArray[i].Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); bool flag2 = false; bool isPeekPoke = false; byte num12 = 0; bool flag4 = false; bool flag5 = false; for (int num13 = 0; num13 < strArray3.Length; num13++) { if ((strArray3[num13].Trim().ToUpper() == "DW") || (strArray3[num13].Trim().ToUpper() == "DR")) { flag2 = true; isPeekPoke = false; flag4 = true; if (strArray3[num13].Trim() == "DW") { num12 = 4; } else { num12 = 3; flag5 = true; } } else { if ((strArray3[num13].Trim().ToUpper() == "'PEEK'") || (strArray3[num13].Trim().ToUpper() == "'POKE'")) { isPeekPoke = true; } byte[] array = null; if (strArray3[num13].Trim().StartsWith("'")) { if (!isPeekPoke || (num13 == 0)) { array = chipApiDescriptor.getByteRepresentationByAPIName(strArray3[num13].Trim(new char[] { '\'' })); } if (array == null) { array = SPI_tools.getByteRepresentationByRegisterName(strArray3[num13].Trim(new char[] { '\'' }), isPeekPoke, deviceRegSet); } if (array == null) { errorMessage = "Line number: " + i.ToString() + "\nInvalid command: " + strArray[i].Trim(); return null; } if ((num13 == 0) && (chipApiDescriptor.getCommandById(array[0]).NumberOfReplyData > 1)) { flag = true; numberOfReplyData = chipApiDescriptor.getCommandById(array[0]).NumberOfReplyData; } if (flag2) { Array.Reverse(array); flag2 = false; } if (((list3.Count == 1) && ((list3[0] == chipApiDescriptor.SetPropertyCommandId) || (list3[0] == chipApiDescriptor.GetPropertyCommandId))) && (array.Length == 2)) { List<byte> list4 = new List<byte>(array); list4.Insert(1, 1); array = list4.ToArray(); } if ((flag4 && (array.Length == 2)) && (array[1] == 0x54)) { num12 = (byte) (num12 + 3); } if ((isPeekPoke && (array.Length == 2)) && (array[0] == 0x54)) { array[0] = 0; } foreach (byte num14 in array) { list3.Add(num14); } } else { byte num15; if ((strArray3[num13].Trim().Length <= 2) && byte.TryParse(strArray3[num13].Trim(), NumberStyles.HexNumber, (IFormatProvider) null, out num15)) { if ((num13 == 0) && (chipApiDescriptor.getCommandById(num15).NumberOfReplyData > 1)) { flag = true; numberOfReplyData = chipApiDescriptor.getCommandById(num15).NumberOfReplyData; } list3.Add(num15); } else { errorMessage = "Line number: " + i.ToString() + "\nInvalid command: " + strArray[i].Trim(); return null; } } } } if (list3.Count != 0) { if (list3.Count == 1) { list3.Add(0); } telegram = new Telegram(list3.Count + 3) { uniqId = GlobalServices.uniqTelegramId(), parentUniqId = -1, type = TelegramType.Command, lastReplyPrecondition = LastReplyPrecondition.Indication, }; if (ioph is IOPH_DCP) { telegram.protocol = Protocol.DCP; telegram.DCPCmdSet = 4; } else { telegram.protocol = Protocol.DCP2; telegram.DCPCmdSet = 0x1c; } buffer8 = new byte[3]; buffer8[0] = 0x10; buffer8[1] = num12; telegram.data.copy(buffer8); telegram.data.append(list3.ToArray(), list3.Count); telegram.SenderInfo = new object[] { strArray[i].Trim(new char[] { '\r' }).Trim() }; telegram.UserDataExt.addUserData("CmdName", strArray[i].Trim(new char[] { '\r' }).Trim()); telegram.portHandler = ioph; telegram.mainWin = mainWin; list.Add(new TelegramContainerItem(telegram)); if (flag) { telegram = new Telegram(13) { uniqId = GlobalServices.uniqTelegramId(), parentUniqId = -1, type = TelegramType.Command, lastReplyPrecondition = LastReplyPrecondition.Indication }; if (ioph is IOPH_DCP) { telegram.protocol = Protocol.DCP; telegram.DCPCmdSet = 4; } else { telegram.protocol = Protocol.DCP2; telegram.DCPCmdSet = 0x1c; } buffer8 = new byte[4]; buffer8[0] = 0x10; buffer8[3] = 0x44; telegram.data.copy(buffer8); byte[] buffer7 = new byte[numberOfReplyData]; for (int num16 = 0; num16 < buffer7.Length; num16++) { buffer7[num16] = 0xff; } telegram.data.append(buffer7, buffer7.Length); telegram.UserDataExt.addUserData("normalLogReply", true); telegram.portHandler = ioph; telegram.mainWin = mainWin; list.Add(new TelegramContainerItem(telegram)); } else if (((list[list.Count - 1].telegram.data.NumItems != 5) || (list[list.Count - 1].telegram.data.Buf[3] != 0x34)) && ctsPoll) { if (!flag4) { telegram = new Telegram(13) { uniqId = GlobalServices.uniqTelegramId(), parentUniqId = -1, type = TelegramType.Command, lastReplyPrecondition = LastReplyPrecondition.Indication }; if (ioph is IOPH_DCP) { telegram.protocol = Protocol.DCP; telegram.DCPCmdSet = 4; } else { telegram.protocol = Protocol.DCP2; telegram.DCPCmdSet = 0x1c; } telegram.data.copy(new byte[] { 0x10, 0, 0, 0x44, 0xff }); telegram.UserDataExt.addUserData("normalLogReply", true); telegram.portHandler = ioph; telegram.mainWin = mainWin; list.Add(new TelegramContainerItem(telegram)); } else if (flag5) { list[list.Count - 1].telegram.UserDataExt.addUserData("debugLogReply", true); } } } } } if (list.Count == 0) { errorMessage = "Did not recognized any executable commands!"; return null; } return list.ToArray(); }
private void AppWin_Si4460_CP_Load(object sender, EventArgs e) { this._chipType = this._adtRec.DeviceInfo.EBID.ChipType; this._chipRev = this._adtRec.DeviceInfo.EBID.ChipRevision; this.Text = this._chipType + " " + this.Text; this._chipApiDescriptor = new ChipCommandAndPpropertyDescriptor(); this._chipApiDescriptor.createDescriptorFromXML(this._chipType, this._chipRev); this._registerDescriptor = SPI_tools.FromXml2DeviceRecordSet(this._chipType, this._chipRev, "SPI_tools_PRO2.xml", "NewWDS.Applications.App_SPI_Tool_Pro2"); this.modeSelectionChanged(this.rdbReady, null); this.initChipSpecificData(); this.initFifoControl(); this.initPer(); }
private void initExtendedTabs() { this.tbcMain.TabPages.Remove(this.tbpInfo); this._chipApiDescriptor = new ChipCommandAndPpropertyDescriptor(); this._chipApiDescriptor.createDescriptorFromXML(this._chipType, this._chipRev); this.reloadCommandGrid(); this.setupCommandGridButtonColoring(); this.reloadPropertyGrid(); this.setupPropertyGridButtonColoring(); this.setupScriptCallButtonColoring(); this.setupRamLoadCallButtonColoring(); this.setupPatchLoadCallButtonColoring(); }