Ejemplo n.º 1
0
        private void cbLogGPS_CheckedChanged(object sender, EventArgs e)
        {
            if (cbLogGPS.Checked)
            {
                try
                {
                    if (gpsAccess == null)
                    {
                        gpsAccess = new GPSAccess();
                    }
                    if (gpsAccess != null)
                    {
                        gpsAccess.StartGPS(getPortNumber(), getBaudRate());
                        if (waitForGPS()) return;
                        if (!gpsAccess.isRunning)
                        {
                            gpsAccess.StartGPS(getPortNumber(), 4800);
                            if (waitForGPS()) return;
                            if (!gpsAccess.isRunning)
                            {
                                Cursor cursor = this.Cursor;
                                this.Cursor = Cursors.WaitCursor;
                                gpsAccess.StartGPS(getPortNumber(), 4800);
                                waitForGPS();
                                return;

                            }
                        }
                    }
                }
                catch (Exception) { }
                finally
                {
                    if (!gpsAccess.isRunning)
                    {
                        cbLogGPS.Checked = false;
                    }
                }

            }
            else
            {
                gpsAccess.StopGPS();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Closes down the system gently when the main form closes for any reason.
        /// A flag is used to ensure that the function cannot recurse.
        /// Any recordings in progress are terminated gently and the termination
        /// event is recorded in the log file.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SoundRecorderForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!isClosing)
            {
                isClosing = true;
                try
                {
                    if (isRecording)
                    {
                        ToggleRecording();
                    }

                    AudioSource.Enabled = false;
                    waterfall1.Enabled = false;
                    audioOut1.Enabled = false;
                    Properties.Settings.Default.File_Path = filePath;
                    Properties.Settings.Default.File_Name_Template = fileTemplate;
                    Properties.Settings.Default.Initial_Index = index;
                    Properties.Settings.Default.AppendDateTime = addDateTime;
                    Properties.Settings.Default.AppendIndex = addIndex;
                    Properties.Settings.Default.Brightness = waterfall1.Levels.Axis.Max;
                    Properties.Settings.Default.Contrast = waterfall1.Levels.Axis.Min;
                    Properties.Settings.Default.SampleAdvance = (int)fourier1.SamplingWindowStep;
                    Properties.Settings.Default.FourierOrder = (int)fourier1.Order;
                    Properties.Settings.Default.LocalOscillator = signalGen1.SignalType.ToString().Trim();
                   // Debug.WriteLine(signalGen1.SignalType.ToString().Trim());
                    Properties.Settings.Default.BufferSize = (int)AudioSource.AudioFormat.BufferSize;
                    Properties.Settings.Default.WordSize = (int)AudioSource.AudioFormat.Bits;
                    Properties.Settings.Default.SampleRate = (int)AudioSource.AudioFormat.SampleRate;
                    switch (fourier1.WindowType)
                    {
                        case Mitov.SignalLab.ExtendedWindowType.Bartlett:
                            Properties.Settings.Default.FourierWindow = "Bartlett"; break;
                        case Mitov.SignalLab.ExtendedWindowType.Blackman:
                            Properties.Settings.Default.FourierWindow = "Blackman"; break;
                        case Mitov.SignalLab.ExtendedWindowType.CosSum:
                            Properties.Settings.Default.FourierWindow = "CosSum"; break;
                        case Mitov.SignalLab.ExtendedWindowType.FlatTop:
                            Properties.Settings.Default.FourierWindow = "FlatTop"; break;
                        case Mitov.SignalLab.ExtendedWindowType.Hamming:
                            Properties.Settings.Default.FourierWindow = "Hamming"; break;
                        case Mitov.SignalLab.ExtendedWindowType.Hanning:
                            Properties.Settings.Default.FourierWindow = "Hanning"; break;
                        case Mitov.SignalLab.ExtendedWindowType.Kaiser:
                            Properties.Settings.Default.FourierWindow = "Kaiser"; break;
                        case Mitov.SignalLab.ExtendedWindowType.Rect:
                            Properties.Settings.Default.FourierWindow = "Rect"; break;
                        default:
                            Properties.Settings.Default.FourierWindow = "Hamming"; break;
                    }

                    Properties.Settings.Default.Save();
                    if (isRecording)
                    {
                        waveLogger1.Close();
                        waveLogger1.Enabled = false;
                        isRecording = false;
                    }
                    AudioSource.Stop();
                    //AudioSource.Close();
                    File.AppendAllText(logFileName, @"

            Session Ended at " + DateTime.Now.ToShortTimeString());

                    if (gpsMain != null)
                    {
                        if (gpsMain.isRunning)
                        {
                            gpsMain.StopGPS();
                            gpsMain = null;
                        }
                    }
                }
                catch (Exception ex)
                {
                    try
                    {
                        File.AppendAllText(logFileName, @"ERROR closing form
            " + ex.ToString() + @"
            " + ex.Message + @"
            " + ex.StackTrace);
                    }
                    catch (Exception) { }
                }
            }
        }
Ejemplo n.º 3
0
        private void preferencesToolStfripButton_Click(object sender, EventArgs e)
        {
            try
            {
                AudioSource.Enabled = false;
                using (Preferences preferences = new Preferences())
                {
                    preferences.gpsAccess = this.gpsMain;

                    preferences.tbFileSavePath.Text = filePath;
                    preferences.tbFileNameTemplate.Text = fileTemplate;
                    preferences.nudInitialIndex.Value = index;
                    preferences.cbAppendDateTime.Checked = addDateTime;
                    preferences.cbAppendIndex.Checked = addIndex;

                    preferences.nudBrightness.Value = (decimal)waterfall1.Levels.Axis.Max;
                    preferences.nudContrast.Value = (decimal)waterfall1.Levels.Axis.Min;
                    preferences.cbColour.Checked = !waterfall1.Levels.GrayScale;

                    preferences.cbxFourierWindow.Items.Clear();

                    preferences.cbxFourierWindow.Items.Add(Mitov.SignalLab.ExtendedWindowType.Bartlett);
                    preferences.cbxFourierWindow.Items.Add(Mitov.SignalLab.ExtendedWindowType.Blackman);
                    preferences.cbxFourierWindow.Items.Add(Mitov.SignalLab.ExtendedWindowType.CosSum);
                    preferences.cbxFourierWindow.Items.Add(Mitov.SignalLab.ExtendedWindowType.FlatTop);
                    preferences.cbxFourierWindow.Items.Add(Mitov.SignalLab.ExtendedWindowType.Hamming);
                    preferences.cbxFourierWindow.Items.Add(Mitov.SignalLab.ExtendedWindowType.Hanning);
                    preferences.cbxFourierWindow.Items.Add(Mitov.SignalLab.ExtendedWindowType.Kaiser);
                    preferences.cbxFourierWindow.Items.Add(Mitov.SignalLab.ExtendedWindowType.Rect);

                    preferences.cbxFourierWindow.SelectedItem = fourier1.WindowType;
                    preferences.FourierOrderNumericUpDown.Value = (decimal)fourier1.Order;
                    preferences.nudSampleAdvance.Value = (decimal)fourier1.SamplingWindowStep;

                    preferences.LocalOscillatorComboBox.SelectedItem = signalGen1.SignalType.ToString();

                    preferences.BufferSizeComboBox.SelectedItem = AudioSource.AudioFormat.BufferSize.ToString();
                    preferences.cbxSampleRate.SelectedItem = AudioSource.AudioFormat.SampleRate.ToString();
                    preferences.cbxWordSize.SelectedItem = AudioSource.AudioFormat.Bits.ToString();

                    var result = preferences.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        try
                        {
                            String newPath = preferences.tbFileSavePath.Text;
                            if (!String.IsNullOrWhiteSpace(newPath))
                            {
                                if (!newPath.EndsWith(@"\")) newPath = newPath + @"\";
                                if (!Directory.Exists(newPath))
                                {
                                    Directory.CreateDirectory(newPath);
                                }
                                if (newPath != filePath)
                                {

                                    filePath = newPath;
                                    CreateLogFile();

                                }
                            }
                        }
                        catch (Exception) { }

                        try
                        {
                            String newTemplate = preferences.tbFileNameTemplate.Text;
                            if (!String.IsNullOrWhiteSpace(newTemplate))
                            {
                                fileTemplate = newTemplate;
                            }
                        }
                        catch (Exception ex) { File.AppendAllText(filePath + fileTemplate + "ERROR.txt",DateTime.Now.ToString()+ex.Message + ex.StackTrace); }

                        try
                        {
                            index = (int)preferences.nudInitialIndex.Value;
                        }
                        catch (Exception ex) {
                            File.AppendAllText(filePath + fileTemplate + "ERROR.txt",DateTime.Now.ToString()+ex.Message + ex.StackTrace);
                        }

                        addDateTime = preferences.cbAppendDateTime.Checked;
                        addIndex = preferences.cbAppendIndex.Checked;
                        waterfall1.Levels.Axis.Max = (double)preferences.nudBrightness.Value;
                        waterfall1.Levels.Axis.Min = (double)preferences.nudContrast.Value;
                        waterfall1.Levels.GrayScale = !preferences.cbColour.Checked;
                        fourier1.WindowType = (Mitov.SignalLab.ExtendedWindowType)(preferences.cbxFourierWindow.SelectedItem ?? Mitov.SignalLab.ExtendedWindowType.Hamming);
                        fourier1.SamplingWindowStep = (uint)preferences.nudSampleAdvance.Value;
                        fourier1.Order = (int)preferences.FourierOrderNumericUpDown.Value;

                        SetSignalGeneratorSignalType((String)preferences.LocalOscillatorComboBox.SelectedItem??"");

                        uint uval = 1024;
                        uint.TryParse((string)preferences.BufferSizeComboBox.SelectedItem, out uval);
                        AudioSource.AudioFormat.BufferSize = uval;
                        uval = 24;
                        uint.TryParse((string)preferences.cbxWordSize.SelectedItem, out uval);
                        AudioSource.AudioFormat.Bits = uval;
                        uval = 192000;
                        uint.TryParse((string)preferences.cbxSampleRate.SelectedItem, out uval);
                        AudioSource.AudioFormat.SampleRate = uval;
                        this.gpsMain = preferences.gpsAccess;
                        if (gpsMain.isRunning)
                        {
                            GPSPositionLabel.Text = gpsMain.getPosition();

                        }
                        else
                        {
                            GPSPositionLabel.Text = "GPS Off";
                        }

                    }

                }
            }
            catch (Exception ex)
            {
                try
                {
                    error(ex.Message);
                    //File.AppendAllText(filePath + fileTemplate + "ERROR.txt",DateTime.Now.ToString()+ex.Message + ex.StackTrace);
                }
                catch (Exception) { }
            }
            finally
            {
                AudioSource.Enabled = true;
                waterfall1.Focus();
            }
        }