private TelegramContainer createSeries(Task task, int numOfCommands, LastReplyPrecondition[] teleStopPrec, byte[][] teleData, Telegram.Callback callback) { TelegramContainer container = new TelegramContainer(); container.clear(); for (int i = 0; i < numOfCommands; i++) { Telegram tele = new Telegram(5) { uniqId = GlobalServices.uniqTelegramId(), parentUniqId = -1, type = TelegramType.Command, protocol = Protocol.DCP, DCPCmdSet = 4, lastReplyPrecondition = teleStopPrec[i], userData = (int) task, portHandler = this._ioph, mainWin = this }; tele.clearEventHandler(); tele.CallbackEvent += callback; tele.data.copy(teleData[i]); if (i == (numOfCommands - 1)) { tele.UserDataExt.addUserData("RetVal", 0); } container.addTelegramContainerItem(new TelegramContainerItem(tele)); } return container; }
private TelegramContainer createSeries(Task task, int numOfCommands, LastReplyPrecondition[] teleStopPrec, byte[][] teleData, Telegram.Callback callback, bool isGeneralCmd) { TelegramContainer container = new TelegramContainer(); container.clear(); for (int i = 0; i < numOfCommands; i++) { Telegram tele = new Telegram(5) { uniqId = GlobalServices.uniqTelegramId(), parentUniqId = -1, type = TelegramType.Command }; if (_ioph is IOPH_DATA) { tele.protocol = Protocol.DCP2; if (isGeneralCmd) { tele.DCPCmdSet = 0x18; } else { tele.DCPCmdSet = 0x1c; } } else { tele.protocol = Protocol.DCP; tele.DCPCmdSet = 4; } tele.lastReplyPrecondition = teleStopPrec[i]; tele.UserDataExt.addUserData("Task", task); tele.portHandler = _ioph; tele.mainWin = this; tele.clearEventHandler(); tele.CallbackEvent += callback; tele.data.copy(teleData[i]); container.addTelegramContainerItem(new TelegramContainerItem(tele)); } return container; }
private void matlabCalc_FormClosing(object sender, EventArgs e) { TelegramContainerItem[] itemArray; string str3; TelegramContainer teleContainer = new TelegramContainer(); string logMessage = string.Empty; string str2 = string.Empty; if (sender == null) { goto Label_095F; } base.Enabled = true; switch (this._matlabCalcForm.MatlabResult) { case Result.Success: if (this._matlabCalcForm.RegularOutput == null) { goto Label_095F; } if ((!this.chbEnableIqCalibration.Checked || (this._matlabCalcForm.IqOutput == null)) || ((this._matlabCalcForm.IqOutput.propertyValues == null) || (this._matlabCalcForm.IqOutput.propertyValues.Count <= 0))) { goto Label_0399; } if (this._matlabCalcForm.getInputRef().RF_Frequency <= 0x1f4add40) { this._calibrateCommandString.Append((string) this._appResources.GetObject("App_Si4060CP_IQ_LowBand_For_Si4463")); break; } this._calibrateCommandString.Append((string) this._appResources.GetObject("App_Si4060CP_IQ_HighBand_For_Si4463")); break; case Result.Cancelled: return; default: MessageBox.Show("Matlab calculation failed!\n" + this._matlabCalcForm.LogFileContent + "\n" + this._matlabCalcForm.MatlabResult.ToString()); return; } uint num5 = Convert.ToUInt32((decimal) (this.nudXtalFrequency.Value * 1000000M)); byte num = BitConverter.GetBytes(num5)[3]; byte num2 = BitConverter.GetBytes(num5)[2]; byte num3 = BitConverter.GetBytes(num5)[1]; byte num4 = BitConverter.GetBytes(num5)[0]; this._calibrateCommandString = this._calibrateCommandString.Replace("<POWER_UP>", "'POWER_UP' 01 00 " + num.ToString("X2") + " " + num2.ToString("X2") + " " + num3.ToString("X2") + " " + num4.ToString("X2")); this._calibrateCommandString = this._calibrateCommandString.Replace("<CAP_BANK>", "'SET_PROPERTY' 'GLOBAL_XO_TUNE' " + ((byte) this.nudXtalCapBank.Value).ToString("X2")); foreach (Pro2Calc.PropertyValuePair pair in this._matlabCalcForm.IqOutput.propertyValues) { this._calibrateCommandString = this._calibrateCommandString.Replace("<INSERT_HERE>", "'SET_PROPERTY' '" + pair.name + "' " + pair.value.ToString("X2") + "\r\n<INSERT_HERE>"); } this._calibrateCommandString = this._calibrateCommandString.Replace("<INSERT_HERE>", "\r\n"); if (((itemArray = SPI_tool_PRO2.createTelegramsFromBatchString(this._calibrateCommandString.ToString(), this._ioph, this, false, this._registerDescriptor, this._chipApiDescriptor, out str3)) == null) || (itemArray.Length < 4)) { MessageBox.Show("Invalid Command, cannot execute!"); _log.Error("Problem in calibration commands generation. No commands, or to few commands were generated!"); return; } for (int i = 0; i < itemArray.Length; i++) { itemArray[i].telegram.SenderInfo = null; itemArray[i].telegram.clearEventHandler(); itemArray[i].telegram.CallbackEvent += new Telegram.Callback(this.updateExecutionEventHandler); itemArray[i].telegram.UserDataExt.addUserData("Task", Task.Update); teleContainer.addTelegramContainerItem(itemArray[i]); } Label_0399: foreach (Pro2Calc.PropertyValuePair pair2 in this._matlabCalcForm.RegularOutput.propertyValues) { if (this.cbbModulationType.SelectedItem.ToString().StartsWith("4") && (pair2.name == "MODEM_FSK4_MAP")) { pair2.value = (byte) this.cbb4GfskMap.SelectedIndex; } ChipProperty property = this._chipApiDescriptor.getPropertyByName(pair2.name); byte[] item = new byte[] { 0x10, 0, 0, 0x11, 0, 1, 0, 0 }; item[4] = BitConverter.GetBytes(property.PropID)[1]; item[6] = BitConverter.GetBytes(property.PropID)[0]; item[7] = pair2.value; this._updateCommandByte.Add(item); this._updateCommandReplyType.Add(LastReplyPrecondition.Indication); this._updateCommandString.AppendLine("'SET_PROPERTY' '" + pair2.name + "' " + pair2.value.ToString("X2")); } this._headerContent.AppendLine(""); this._headerContent.AppendLine("/* Input file content:"); this._headerContent.AppendLine(this._matlabCalcForm.InputFile + "*/"); this._headerContent.AppendLine(""); this._headerContent.AppendLine("#define CENTER_FREQ " + this._matlabCalcForm.getInputRef().RF_Frequency.ToString()); this._headerContent.AppendLine("#define XTAL_FREQ " + this._matlabCalcForm.getInputRef().CrystalFrequency.ToString()); this._headerContent.AppendLine("#define CHANNEL_SPACING " + ((int) (this.nudChannelSpacing.Value * 1000M)).ToString()); this._headerContent.AppendLine("#define CHANNEL_NUMBER " + this.nudChannelNumber.Value.ToString()); this._headerContent.AppendLine("#define XTAL_CAP_BANK 0x" + ((int) this.nudXtalCapBank.Value).ToString("X2")); this._headerContent.AppendLine("#define MODULATION_TYPE \"" + this.cbbModulationType.SelectedItem.ToString() + "\""); this._headerContent.AppendLine("#define MODULATION_TYPE_VALUE " + (this.rdbRX.Checked ? ((this.cbbModulationType.SelectedIndex + 1)).ToString() : this.cbbModulationType.SelectedIndex.ToString())); this._headerContent.AppendLine("#define MANCHESTER_CODE \"" + this.cbbManchesterMode.SelectedItem.ToString() + "\""); this._headerContent.AppendLine("#define MANCHESTER_CODE_VALUE " + this.cbbManchesterMode.SelectedIndex.ToString()); this._headerContent.AppendLine("#define DEVIATION " + this._matlabCalcForm.getInputRef().FrequencyDeviation.ToString()); this._headerContent.AppendLine("#define DATA_RATE " + this._matlabCalcForm.getInputRef().SymbolRate.ToString()); this._headerContent.AppendLine("#define ANTENNA_DIVERSITY \"" + this.cbbAntennaDiversity.SelectedItem.ToString() + "\""); this._headerContent.AppendLine("#define ANTENNA_DIVERSITY_VALUE " + this.cbbAntennaDiversity.SelectedIndex.ToString()); this._headerContent.AppendLine(""); int index = this._matlabCalcForm.LogFileContent.IndexOf("# WB"); if (index != -1) { logMessage = this._matlabCalcForm.LogFileContent.Substring(index); int length = logMessage.IndexOf("\n"); logMessage = logMessage.Substring(0, length); this._headerContent.AppendLine(""); this._headerContent.AppendLine("// " + logMessage + "\n"); this.showLocalLog(logMessage); } int num9 = (2 * this._matlabCalcForm.getInputRef().FrequencyDeviation) / this._matlabCalcForm.getInputRef().SymbolRate; this._headerContent.AppendLine("// Modulation index: " + num9.ToString() + "\n"); this.showLocalLog("# Modulation index: " + num9.ToString()); if (this._matlabCalcForm.LogFileContent.Contains("# Warning:")) { str2 = this._matlabCalcForm.LogFileContent.Substring(this._matlabCalcForm.LogFileContent.IndexOf("# Warning:")).Trim(); this.showLocalLog(str2); str2 = str2.Replace("\n", "\n// "); this._headerContent.AppendLine(""); this._headerContent.AppendLine("// " + str2 + "\n"); } this._headerContent = new StringBuilder(this._headerContent.ToString() + this._matlabCalcForm.HeaderFileContent); Label_095F: this.addPACommand(); this.addTRXCommand(); switch (this._calcPurpose) { case CalculationPurpose.Update: { TelegramContainer tc = this.createSeries(Task.Update, this._updateCommandByte.Count, this._updateCommandReplyType.ToArray(), this._updateCommandByte.ToArray(), null, new bool[this._updateCommandByte.Count]); tc.insertTelegramContainer(teleContainer, 0); if (this._teleProcessor != null) { if (this._teleProcessor.initSeries(tc)) { this.sbProgressBar.Reset(); this.sbProgressBar.EndPoint = tc.Count; this._teleProcessor.execTelegramSeries(); return; } MessageBox.Show("Device is BUSY!"); return; } for (int j = 0; j < tc.Count; j++) { tc[j].telegram.clearEventHandler(); tc[j].telegram.CallbackEvent += new Telegram.Callback(this.updateExecutionEventHandler); tc[j].telegram.UserDataExt.addUserData("SentData", "> " + WDSConverters.ToHexString(tc[j].telegram.data.Buf, tc[j].telegram.data.NumItems)); } this.sbProgressBar.Reset(); this.sbProgressBar.EndPoint = tc.Count; this.sbDeviceStatePane.Text = this.getStatusString((Task) tc[0].telegram.UserDataExt.StoredUserData["Task"]); if (this._adtRec.isSimuation) { this.logSimulationModeCommandSeries(tc); return; } if (this._ioph.telegramSeriesFromMainWin(tc, SeriesExecutionState.Run, true) != -1) { break; } MessageBox.Show("Device is BUSY!"); return; } case CalculationPurpose.CodeGenerate: this.rtbCHeaderPreview.Clear(); if (this.rdbAddTextName.Checked && (this.txbDeviceName.Text != "")) { this._headerContent.Replace("#define ", "#define " + this.txbDeviceName.Text + "_"); } this.rtbCHeaderPreview.AppendText(this._headerContent.ToString()); return; case CalculationPurpose.SaveBatch: { Stream stream; string currentDirectory = Directory.GetCurrentDirectory(); SaveFileDialog dialog = new SaveFileDialog { Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*", FilterIndex = 0, FileName = Path.Combine(Application.LocalUserAppDataPath, "Batch_" + this._chipType + ".txt") }; DialogResult result = dialog.ShowDialog(); Directory.SetCurrentDirectory(currentDirectory); if ((result == DialogResult.OK) && ((stream = dialog.OpenFile()) != null)) { TextWriter writer = new StreamWriter(stream); writer.WriteLine("#BatchName " + this._chipType); if (this._matlabCalcForm != null) { writer.WriteLine("#" + this._matlabCalcForm.InputFile.Replace("\r\n", "\r\n#")); writer.WriteLine("# " + logMessage); writer.WriteLine("# " + str2); writer.WriteLine(""); } if (this.chbEnableIqCalibration.Checked) { writer.Write(this._calibrateCommandString); writer.WriteLine(""); } writer.Write(this._updateCommandString.ToString()); writer.Close(); stream.Close(); } break; } default: return; } }
private void loadBatchCommands(string batchCommands) { string str; TelegramContainer telegramSeries = new TelegramContainer(); TelegramContainerItem[] itemArray = SPI_tool_PRO2.createTelegramsFromBatchString(batchCommands, this._ioph, this, false, this._registerDescriptor, this._chipApiDescriptor, out str); if (itemArray == null) { MessageBox.Show("Invalid Command, cannot execute!"); } else { for (int i = 0; i < itemArray.Length; i++) { itemArray[i].telegram.clearEventHandler(); itemArray[i].telegram.UserDataExt.addUserData("Task", Task.PER); telegramSeries.addTelegramContainerItem(itemArray[i]); } if (this._teleProcessor == null) { for (int j = 0; j < telegramSeries.Count; j++) { telegramSeries[j].telegram.UserDataExt.addUserData("SentData", "> " + WDSConverters.ToHexString(telegramSeries[j].telegram.data.Buf, telegramSeries[j].telegram.data.NumItems)); } this.sbProgressBar.Reset(); this.sbProgressBar.EndPoint = telegramSeries.Count; this.sbDeviceStatePane.Text = this.getStatusString((Task) telegramSeries[0].telegram.UserDataExt.StoredUserData["Task"]); if (this._adtRec.isSimuation) { this.logSimulationModeCommandSeries(telegramSeries); } else if (this._ioph.telegramSeriesFromMainWin(telegramSeries, SeriesExecutionState.Run, true) == -1) { MessageBox.Show("Device is BUSY!"); } } else if (this._teleProcessor.initSeries(telegramSeries)) { this._teleProcessor.execTelegramSeries(); } else { MessageBox.Show("Device is BUSY!"); } } }
private TelegramContainer createSeries(Task task, int numOfCommands, byte[][] dcpPrefixCommandSet, byte[][] rfCommandSet, Telegram.Callback callback, bool[] isGeneralCmdIndicatorSet) { try { TelegramContainer container = new TelegramContainer(); container.clear(); for (int i = 0; i < numOfCommands; i++) { Telegram tele = new Telegram(5) { uniqId = GlobalServices.uniqTelegramId(), parentUniqId = -1, type = TelegramType.Command, protocol = Protocol.DCP2 }; if (isGeneralCmdIndicatorSet[i]) { tele.DCPCmdSet = 0x18; } else { tele.DCPCmdSet = 0x1c; } tele.lastReplyPrecondition = LastReplyPrecondition.Indication; tele.UserDataExt.addUserData("Task", task); tele.portHandler = this._ioph; tele.mainWin = this; tele.clearEventHandler(); tele.CallbackEvent += callback; if ((dcpPrefixCommandSet != null) && (dcpPrefixCommandSet.Length >= i)) { tele.data.copy(dcpPrefixCommandSet[i]); } if ((rfCommandSet != null) && (rfCommandSet.Length >= i)) { tele.data.append(rfCommandSet[i], rfCommandSet[i].Length); } container.addTelegramContainerItem(new TelegramContainerItem(tele)); } return container; } catch (Exception exception) { _log.Error("Could not create command series! " + exception.Message); return null; } }
private TelegramContainer createSpiCommanSeries(int numOfCommands, byte[][] teleData, Telegram.Callback callback, bool resetChip, bool shutdownChip) { TelegramContainer container = new TelegramContainer(); container.clear(); if (shutdownChip) { foreach (TelegramContainerItem item in createShutdownCommandSeries()) { container.addTelegramContainerItem(item); } return container; } if (resetChip) { foreach (TelegramContainerItem item2 in createResetCommandSeries()) { container.addTelegramContainerItem(item2); } } for (int i = 0; i < numOfCommands; i++) { Telegram tele = new Telegram(5) { uniqId = GlobalServices.uniqTelegramId(), parentUniqId = -1, type = TelegramType.Command, protocol = Protocol.DCP2, DCPCmdSet = 0x1c, portHandler = _ioph, mainWin = this }; tele.clearEventHandler(); tele.CallbackEvent += callback; byte[] buf = new byte[3]; buf[0] = 0x10; tele.data.copy(buf); tele.data.append(teleData[i], teleData[i].Length); tele.UserDataExt.addUserData("SentData", "> " + WDSConverters.ToHexString(teleData[i], teleData[i].Length)); container.addTelegramContainerItem(new TelegramContainerItem(tele)); } return container; }
private TelegramContainer createShutdownCommandSeries() { TelegramContainer container = new TelegramContainer(); container.clear(); for (int i = 0; (i < RESET_COMMAND_SET.Length) || (i < 2); i++) { Telegram tele = new Telegram(5) { uniqId = GlobalServices.uniqTelegramId(), parentUniqId = -1, type = TelegramType.Command, protocol = Protocol.DCP2, DCPCmdSet = 0x1c, portHandler = _ioph, mainWin = this }; tele.clearEventHandler(); tele.data.copy(RESET_COMMAND_SET[i]); container.addTelegramContainerItem(new TelegramContainerItem(tele)); } return container; }