public static void CreateGSD4tMEMSConfigFile(string fullHostAppPath, ref HostAppConfigParams hostAppConfigParams) { DirectoryInfo parent = Directory.GetParent(fullHostAppPath); if (hostAppConfigParams.HostSWFilePath == fullHostAppPath) { parent = Directory.GetParent(parent.FullName); } string str = @"\" + hostAppConfigParams.SiRFLiveInterfacePortName; string path = string.Empty; if (parent.FullName.Contains(str)) { path = parent.FullName; } else { path = parent.FullName + str; } if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } FileInfo info2 = new FileInfo(fullHostAppPath); hostAppConfigParams.HostSWFilePath = path + @"\" + info2.Name; if (!File.Exists(hostAppConfigParams.HostSWFilePath)) { File.Copy(fullHostAppPath, hostAppConfigParams.HostSWFilePath, true); } hostAppConfigParams.HostAppMEMSCfgPath = path + @"\SensCfg4t.txt"; if (!File.Exists(hostAppConfigParams.HostAppMEMSCfgPath)) { string str3 = clsGlobal.InstalledDirectory + @"\Config\SensCfg4t.txt"; if (File.Exists(str3)) { File.Copy(str3, hostAppConfigParams.HostAppMEMSCfgPath, true); } else { StreamWriter writer = new StreamWriter(hostAppConfigParams.HostAppMEMSCfgPath, false); FileInfo[] files = parent.GetFiles("*.bin"); StringBuilder builder = new StringBuilder(); if (files.Length > 0) { builder.Append("program_file "); builder.Append(files[0].FullName); builder.Append("\r\n"); } builder.Append("// Sensors Configuration (ALL VALUES MUST BE IN HEX FORMAT WITH EXACT NUMBER OF DIGITS. EX: 1 BYTE: 0x01, 2 BYTES: 0x0001)\r\n"); builder.Append("0x02 // Number of Sensors (1 - 4)\r\n"); builder.Append("0x02 // I2C bus speed (0 - Low, 1 - Standard, 2 - Fast, 3 - Fast_Plus, 4 - High)\r\n"); builder.Append("\n// Configuration for Sensor #1 (AK8974/AMI304)\r\n"); builder.Append("0x000E // Sensor I2C Address (7 or 10 bit)\r\n"); builder.Append("0x02 // Sensor Type (1 - Accel, 2 - Magn, 3 - Press, 4 - Gyro, 5 - Accel_Gyro, 6 - Accel_Magn, 7 - Gyro_Magn, 8 - Accel_Magn_Gyro)\r\n"); builder.Append("0x00 // Initialization period after power up for Sensor, unit: 10ms\r\n"); builder.Append("0xCD // Data type (bit 0), Number of bytes to read from each register (bits 1-3) and Data Resolution (bits 4-7)\r\n"); builder.Append("0x05 // Sample rate: 1- 1hz, 2- 2hz, 3- 5hz, 4- 10hz, 5- 25hz, 6- 50hz, 7- 100Hz\r\n"); builder.Append("0x03 // Send Rate: 1- 1hz, 2- 2hz, 3- 5hz, 4- 10hz, 5- 25hz, 6- 50hz, 7- 100Hz\r\n"); builder.Append("0x00 // Data decimation method (bits 0-2): 0- raw, 1- averaging, 2- sliding median\r\n"); builder.Append("0x20 // Acquisition time delay, unit: 10us\r\n"); builder.Append("0x01 // Number of sensor read registers\r\n"); builder.Append("0x01 // Measurement State: 0 - auto (sensor configured) 1 - forced (sw controlling) was 0x00\r\n"); builder.Append(" 0x03, 0x10 // Read Register #1: (Read Operation, Register Address)\r\n"); builder.Append(" // Read Operation Bit Definition:\r\n"); builder.Append(" //Bit7 ~ Bit4: Number of Right Shift before sending to host\r\n"); builder.Append(" //Bit3 ~ Bit2: Reserved\t\r\n"); builder.Append(" //Bit1: Endian, 0 - big, 1 - little\r\n"); builder.Append(" //Bit0: Read mode, 0 - read only, 1 - write with repeated start read\r\n"); builder.Append("0x1B // Address of the Register that controls the sensor power states\r\n"); builder.Append("0x00 // Setting for Stand-by (low power) mode\r\n"); builder.Append("0x80 // Setting for Active mode\r\n"); builder.Append("0x04 // Number of Initialization Registers to be read\r\n"); builder.Append(" 0x1B, 0x01 // Init Read Register #1: (Register Address, Number of Bytes)\r\n"); builder.Append(" 0x1C, 0x01 // Init Read Register #2: (Register Address, Number of Bytes)\r\n"); builder.Append(" 0x1D, 0x01 // Init Read Register #3: (Register Address, Number of Bytes)\r\n"); builder.Append(" 0x0B, 0x01 // Init Read Register #4: (Register Address, Number of Bytes)\r\n"); builder.Append("0x04 // Number of sensor control registers\r\n"); builder.Append("0x20 // Time delay between two consecutive register writes, unit: ms\r\n"); builder.Append(" 0x1B, 0x90 // CNTL1 Register (Register Address, Value)\tValue: PwrCtrl, OutDatRate, FuncState\r\n"); builder.Append(" 0x1C, 0x0C // CNTL2 Register (Register Address, Value) Value: IntEnb, DRDYEnb, DRDYPolarity\r\n"); builder.Append(" 0x1D, 0x00 // CNTL3 Register (Register Address, Value) Value: SoftReset, StartFORCEMeas, SelfTest\r\n"); builder.Append(" 0x0B, 0x05 // ACNTL1 Register (Register Address, Value) Value: SensCorrByPass, OVF, OVFOut, BITS\r\n"); builder.Append("\n// Configuration for Sensor #2 (KXTF9)\r\n"); builder.Append("0x000F // Sensor I2C Address (7 or 10 bit)\r\n"); builder.Append("0x01 // Sensor Type (1 - Accel, 2 - Magn, 3 - Press, 4 - Gyro, 5 - Accel_Gyro, 6 - Accel_Magn, 7 - Gyro_Magn, 8 - Accel_Magn_Gyro)\r\n"); builder.Append("0x00 // Initialization period after power up for Sensor, unit: 10ms\r\n"); builder.Append("0xCD // Data type (bit 0), Number of bytes to read from each register (bits 1-3) and Data Resolution (bits 4-7)\r\n"); builder.Append("0x06 // Sample rate: 1- 1hz, 2- 2hz, 3- 5hz, 4- 10hz, 5- 25hz, 6- 50hz, 7- 100Hz\r\n"); builder.Append("0x03 // Send Rate: 1- 1hz, 2- 2hz, 3- 5hz, 4- 10hz, 5- 25hz, 6- 50hz, 7- 100Hz\r\n"); builder.Append("0x00 // Data decimation method (bits 0-2): 0- raw, 1- averaging, 2- sliding median\r\n"); builder.Append("0x20 // Acquisition time delay, unit: 10us\r\n"); builder.Append("0x01 // Number of sensor read registers\r\n"); builder.Append("0x01 // Measurement State: 0 - auto (sensor configured) 1 - forced (sw controlling) was 0x00\r\n"); builder.Append(" 0x43, 0x06 // Read Register #1: (Read Operation, Register Address)\r\n"); builder.Append(" // Read Operation Bit Definition:\r\n"); builder.Append(" //Bit7 ~ Bit4: Number of Right Shift before sending to host\r\n"); builder.Append(" //Bit3 ~ Bit2: Reserved\t\r\n"); builder.Append(" //Bit1: Endian, 0 - big, 1 - little\r\n"); builder.Append(" //Bit0: Read mode, 0 - read only, 1 - write with repeated start read\r\n"); builder.Append("0x1B // Address of the Register to controls the sensor power states\r\n"); builder.Append("0x00 // Setting for Stand-by (OFF) mode\r\n"); builder.Append("0x80 // Setting for Operating (ON) mode\r\n"); builder.Append("0x02 // Number of Initialization Registers to be read\r\n"); builder.Append(" 0x1B, 0x01 // Init Read Register #1: (Register Address, Number of Bytes)\r\n"); builder.Append(" 0x1D, 0x01 // Init Read Register #2: (Register Address, Number of Bytes)\r\n"); builder.Append("0x02 // Number of sensor control registers\r\n"); builder.Append("0x20 // Time delay between two consecutive register writes, unit: ms\r\n"); builder.Append(" 0x1B, 0xC0 // CTRL_REG1: (Register Address, Value) OpMode, Ressolution 12bit\r\n"); builder.Append(" 0x1D, 0x4D // CTRL_REG3: (Register Address, Value) Default\r\n"); builder.Append("\n0x01 // Sensor Data Processing Rate\r\n"); builder.Append("\n0x00 // sensor #1 Zero Point Value\r\n"); builder.Append("0x01 // sensor #1 Scale Factor (sensitivity)\r\n"); builder.Append("\n0x0000 // sensor #2 Zero Point Value\r\n"); builder.Append("0x0400 // sensor #2 Scale Factor (sensitivity)\r\n"); writer.WriteLine(builder.ToString()); writer.Close(); File.Copy(hostAppConfigParams.HostAppMEMSCfgPath, str3, true); } } }
private void frmCommSettingsOkBtn_Click(object sender, EventArgs e) { this.comm.RequireHostRun = this.hostAppRunHostChkBox.Checked; this.comm.TrackerPort = this.hostAppCboTrackerPort.Text; this.comm.ResetPort = this.hostAppCboResetPort.Text; this.CMC.HostAppClient.TCPClientHostName = this.COMClientIPAddrTextBox.Text; this.CMC.HostAppServer.TCPServerHostName = this.COMServerIPTextBox.Text; this.comm.LNAType = this.hostAppLnaComboBox.SelectedIndex; this.comm.LDOMode = this.hostAppLDOModeComboBox.SelectedIndex; this.comm.RxName = this.frmCommSettingsRxNameTxtBox.Text; if (this.comm.RxName == string.Empty) { this.comm.RxName = "SiRF_EVK"; } this.comm.RequireEE = this.hostAppEEChkBox.Checked; this.comm.EESelect = this.extEphComboBox_Select.Text; this.comm.ServerName = this.extEphComboBox_ServerName.Text; this.comm.ServerPort = this.extEphEditBox_ServerPort.Text; this.comm.AuthenticationCode = this.extEphEditBox_AuthCode.Text; this.comm.EEDayNum = this.extEphComboBox_EEDay.Text; this.comm.BankTime = this.extEphEditBox_BankTime.Text; this.comm.IsAutoDetectBaud = this.autoBaudChkBox.Checked; this.comm.IsVersion4_1_A8AndAbove = this.hostAppVersionCheckBox.Checked; if (this.comm.RequireHostRun) { if ((this.comm.TrackerPort == this.comm.ResetPort) && (this.comm.ProductFamily == CommonClass.ProductType.GSD4t)) { MessageBox.Show("Error: Same port set for tracker and reset!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); base.DialogResult = System.Windows.Forms.DialogResult.Cancel; this._errorDetected = true; return; } this.COMDeviceTabControl.SelectedIndex = 0; } if (this.hostAppRS232RadioBtn.Checked) { if (this.comm.RequireHostRun) { this.COMDeviceTabControl.SelectedIndex = 0; } else { this.COMDeviceTabControl.SelectedIndex = 1; } if (this.comm.RequireHostRun && (this.comm.ProductFamily == CommonClass.ProductType.GSD4t)) { List<string> inList = new List<string>(); inList.Add(this.hostAppCboTrackerPort.Text); inList.Add(this.hostAppCboResetPort.Text); inList.Add(this.hostAppCboHostPair1.Text); inList.Add(this.hostAppCboHostPair2.Text); if (HelperFunctions.IsDuplicateString(inList)) { MessageBox.Show("Dupliate port settings detected!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); base.DialogResult = System.Windows.Forms.DialogResult.Cancel; this._errorDetected = true; return; } } this.SetupRS232Comm(); } else if (this.hostAppI2CRadioBtn.Checked) { this.SetupI2CComm(); } else { if (this.COMTcpIPClientRadioButton.Checked) { if (this.comm.RequireHostRun && (this.CMC.HostAppClient.TCPClientHostName == "")) { this.COMDeviceTabControl.SelectedIndex = 2; } else { this.COMDeviceTabControl.SelectedIndex = 0; } } else if (this.comm.RequireHostRun && (this.CMC.HostAppServer.TCPServerHostName == "")) { this.COMDeviceTabControl.SelectedIndex = 2; } else { this.COMDeviceTabControl.SelectedIndex = 0; } this.SetupTcpIpComm(); } if (this.comm.RequireHostRun) { if (!File.Exists(this.hostAppSWDirTxtBox.Text)) { MessageBox.Show("Host SW does not exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); base.DialogResult = System.Windows.Forms.DialogResult.Cancel; this._errorDetected = true; return; } HostAppConfigParams hostAppConfigParams = new HostAppConfigParams(); hostAppConfigParams.SiRFLiveInterfacePortName = "SW_" + this.comm.PortName; hostAppConfigParams.TrackerPort = this.comm.TrackerPort; hostAppConfigParams.TrackerPortSelect = this.comm.TrackerPortSelect; hostAppConfigParams.BaudRate = this.comm.BaudRate; hostAppConfigParams.ResetPort = this.comm.ResetPort; hostAppConfigParams.WarmupDelay = this.comm.WarmupDelay; hostAppConfigParams.OnOffLineUsage = this.comm.OnOffLineUsage; hostAppConfigParams.ExtSResetNLineUsage = this.comm.ExtSResetNLineUsage; hostAppConfigParams.DebugSettings = this.comm.DebugSettings; hostAppConfigParams.LNAType = this.comm.LNAType; hostAppConfigParams.LDOMode = this.comm.LDOMode; hostAppConfigParams.DefaultTCXOFreq = this.comm.DefaultTCXOFreq; hostAppConfigParams.HostSWFilePath = this.comm.HostSWFilePath; if (this.hostAppVersionCheckBox.Checked) { hostAppConfigParams.OnOffLineUsage = "uart_rts"; } CreateGSD4tConfigFile(this.hostAppSWDirTxtBox.Text, ref hostAppConfigParams); CreateGSD4tMEMSConfigFile(this.hostAppSWDirTxtBox.Text, ref hostAppConfigParams); this.comm.HostAppCfgFilePath = hostAppConfigParams.HostAppCfgFilePath; this.comm.HostAppMEMSCfgPath = hostAppConfigParams.HostAppMEMSCfgPath; this.comm.HostSWFilePath = hostAppConfigParams.HostSWFilePath; } base.DialogResult = DialogResult.OK; base.Close(); }
public static void CreateGSD4tConfigFile(string fullHostAppPath, ref HostAppConfigParams hostAppConfigParams) { DirectoryInfo parent = Directory.GetParent(fullHostAppPath); if (hostAppConfigParams.HostSWFilePath == fullHostAppPath) { parent = Directory.GetParent(parent.FullName); } string str = @"\" + hostAppConfigParams.SiRFLiveInterfacePortName; string path = string.Empty; if (parent.FullName.Contains(str)) { path = parent.FullName; } else { path = parent.FullName + str; } if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } FileInfo info2 = new FileInfo(fullHostAppPath); hostAppConfigParams.HostSWFilePath = path + @"\" + info2.Name; if (!File.Exists(hostAppConfigParams.HostSWFilePath)) { File.Copy(fullHostAppPath, hostAppConfigParams.HostSWFilePath, true); } hostAppConfigParams.HostAppCfgFilePath = path + @"\sirfLiveHostConfig.txt"; StreamWriter writer = new StreamWriter(hostAppConfigParams.HostAppCfgFilePath, false); FileInfo[] files = parent.GetFiles("*.bin"); StringBuilder builder = new StringBuilder(); if (files.Length > 0) { builder.Append("program_file "); builder.Append(files[0].FullName); builder.Append("\r\n"); } files = new DirectoryInfo(path).GetFiles("NVM*"); if (files.Length > 0) { foreach (FileInfo info4 in files) { try { File.Delete(info4.FullName); } catch { } } } builder.Append("tracker_port_select "); builder.Append(string.Format("{0}\r\n", hostAppConfigParams.TrackerPortSelect)); builder.Append(string.Format("uart_baud_rate {0}\r\n", hostAppConfigParams.BaudRate)); builder.Append(@"tracker_port \\.\"); builder.Append(hostAppConfigParams.TrackerPort); builder.Append("\r\n"); builder.Append(@"on_off_port \\.\"); builder.Append(hostAppConfigParams.ResetPort); builder.Append(string.Format("\r\non_off_line_usage {0}\r\next_sreset_n_line_usage {1}\r\n", hostAppConfigParams.OnOffLineUsage, hostAppConfigParams.ExtSResetNLineUsage)); builder.Append(string.Format("ref_clk_frequency {0}\r\n", hostAppConfigParams.DefaultTCXOFreq)); builder.Append(string.Format("ref_clk_warmup_delay {0}\r\ndebug_settings {1}\r\n", hostAppConfigParams.WarmupDelay, hostAppConfigParams.DebugSettings)); if (hostAppConfigParams.LNAType == 0) { builder.Append("lna_type internal\r\n"); } else { builder.Append("lna_type external\r\n"); } if (hostAppConfigParams.LDOMode == 0) { builder.Append("internal_backup_LDO_mode disable\r\n"); } else { builder.Append("internal_backup_LDO_mode enable\r\n"); } builder.Append("\n// I2C DR GPIO settings\r\n"); builder.Append("io_pin_configuration_mode enable\r\n"); builder.Append("\n// set the enable bit (0x04) on both GPIO0 and GPIO1, mode = 0 (DR_I2C)\r\n"); builder.Append("// [0:1] 0x000 = I2C DR mode\r\n"); builder.Append("// [2:5] 0x03C = each power state enable bit\r\n"); builder.Append("// [6:9] 0x3C0 = each power state DS setting\r\n"); builder.Append("// |= 0x3FC = 1020\r\n"); builder.Append("io_pin_0_configuration 0x3FC\r\n"); builder.Append("io_pin_1_configuration 0x3FC\r\n"); builder.Append("io_pin_3_configuration 0x003C"); writer.WriteLine(builder.ToString()); writer.Close(); }