示例#1
0
        private void StopThreads()
        {
            if (USBRX != null)
            {
                USBRX.CurrentMode = LibRXFFT.Libraries.eTransferMode.Stopped;
            }

            if (PowerUpdateThread != null)
            {
                PowerUpdateThread.Abort();
                PowerUpdateThread = null;
            }

            if (DemodDlg != null)
            {
                DemodDlg.Close();
                DemodDlg = null;
            }

            if (Demod != null)
            {
                Demod.AudioInSampleSource.Close();
                Demod.AudioOutShmem.Close();
                Demod.Stop();
                Demod = null;
            }

            if (USBRX != null)
            {
                USBRX.Close();
                USBRX = null;
            }
        }
示例#2
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            if (USBRX == null)
            {
                USBRXDevice device = new USBRXDevice();

                device.ShowConsole(false);
                device.TunerCombination = USBRXDevice.eCombinationType.AR5000;

                try
                {
                    if (!device.Init())
                    {
                        ErrorMessage = "There was no USB-RX found on USB bus.";
                        return;
                    }
                }
                catch (BadImageFormatException ex)
                {
                    ErrorMessage = "Unsupported architecture.";
                    return;
                }
                catch (Exception ex)
                {
                    ErrorMessage = "Unhandled exception." + Environment.NewLine + e;
                    return;
                }

                USBRX = device;

                FilterList.NCOFreq = USBRX.Atmel.TCXOFreq;
                FilterList.UpdateFilters("Filter");
                FilterList.AddFilters("..\\..\\..\\Filter");
                FilterList.FilterSelected += new EventHandler(FilterList_FilterSelected);

                frequencySelector1.UpperLimit = USBRX.Tuner.HighestFrequency;
                frequencySelector1.LowerLimit = USBRX.Tuner.LowestFrequency;

                /* bar update thread */
                InSampleSource            = new ShmemSampleSource("RX-Radio Reader", USBRX.ShmemChannel, 1, 0);
                InSampleSource.DataFormat = ByteUtil.eSampleFormat.Direct16BitIQFixedPointLE;
                PowerUpdateThread         = new Thread(() =>
                {
                    InSampleSource.SamplesPerBlock = 1024;
                    while (true)
                    {
                        InSampleSource.Flush();
                        InSampleSource.Read();

                        double maxValue = DBTools.MaximumDb(InSampleSource.SourceSamplesI, InSampleSource.SourceSamplesQ);
                        BeginInvoke(new Action(() =>
                        {
                            powerBar.Amplitude    = (maxValue + 100) / 100;
                            powerBar.LinePosition = (maxValue + 100) / 100;
                            powerBar.Enabled      = true;
                            powerBar.Invalidate();
                        }));

                        Thread.Sleep(250);
                    }
                });
                PowerUpdateThread.Start();

                /* demodulator */
                Demod = new AudioDemodulator();
                Demod.AudioInSampleSource            = new ShmemSampleSource("RX-FFT Audio Decoder", USBRX.ShmemChannel, 1, 0);
                Demod.AudioInSampleSource.DataFormat = ByteUtil.eSampleFormat.Direct16BitIQFixedPointLE;
                Demod.AudioOutShmem = new SharedMem(-2, 1, "RX-Radio Demodulated Audio");

                lock (Demod.DemodOptions)
                {
                    Demod.DemodOptions.SoundDevice = new DXSoundDevice(Handle);
                }
                Demod.Start();

                /* demodulator dialog */
                DemodDlg = new DemodulationDialog(Demod.DemodOptions);
                DemodDlg.Show();


                /* finished */
                USBRX.CurrentMode = LibRXFFT.Libraries.eTransferMode.Stopped;

                btnOpen.Text = "Close";
            }
            else
            {
                StopThreads();
                btnOpen.Text = "Open";
            }
        }