예제 #1
0
        static void Main(string[] args)
        {
            var devices = NetHackrf.HackrfDeviceList(); // get list of all connected hackrf transceivers

            if (devices.Length == 0)                    // if no hackrfs discovered
            {
                System.Console.WriteLine("No hackrf devices were found");
                System.Console.WriteLine("Press any key to close application");
                System.Console.ReadKey();
                return;
            }
            System.Console.WriteLine("Press any key to stop the application...");
            NetHackrf device = devices[0].OpenDevice(); // connecting to the first transceiver in the list

            device.CarrierFrequencyMHz = 104.7;
            device.SampleFrequencyMHz  = 2.016; // 48kHz * 42
            device.LNAGainDb           = 40;    // setting amlpifiers gain values
            device.VGAGainDb           = 40;
            device.FilterBandwidthMHz  = 0.2;

            FileStream output = new FileStream("test.wav", FileMode.OpenOrCreate); // opening wave file
            Stream     stream = device.StartRX();

            byte[] buffer = new byte[1000000];

            bool started = false;

            AddWaveHeader(output, 0); // adding wave header with zero file length placeholders (we will change them later)

            int file_length = 0;

            try {
                while (System.Console.KeyAvailable == false)
                {
                    stream.Read(buffer, 0, buffer.Length);     // reading interpolated IQ data from stream
                    System.Console.WriteLine("demodulating...");
                    var IQ_data = ConvertToIQ(buffer);         // converting interpolated IQ data to complex array
                    IQ_data = LPF1(IQ_data);                   // low pass filter to cutoff other frequencies
                    var demod = DemodFMsamples(IQ_data, 4000); // FM demodulator
                    demod = LPF2(demod);                       // low pass filter to cutoff pilot tone, stereo fm subcarrier and RDS
                    demod = Decimate(demod, 42);               // changing sample frequency to 48kHz
                    var bytes = ConvertToBuffer(demod);        // converting array of double to array of bytes
                    file_length += bytes.Length;
                    output.Write(bytes);                       // writing sound data to the file
                }

                stream.Close();
                output.Close();                                     // closing stream and file

                output = new FileStream("test.wav", FileMode.Open); // changing length values in the header to correct ones
                AddWaveHeader(output, file_length);
                output.Close();
            }
            catch (Exception)
            {
                device.Reset(); // reset hackRF if something goes wrong
            }
        }
예제 #2
0
        static public void Main(string[] args)
        {
            System.Console.WriteLine(NetHackrf.HackrfLibraryVersion());
            System.Console.WriteLine(NetHackrf.HackrfLibraryRelease());
            var devices = NetHackrf.HackrfDeviceList(); // get list of all connected hackrf transceivers

            foreach (var i in devices)
            {
                System.Console.WriteLine($"serial=\"{i.serial_number}\", boardId=\"{i.usb_board_id}\", index={i.usb_device_index}"); // print information about each hackrf
            }
            if (devices.Length == 0)                                                                                                 // if no hackrfs discovered
            {
                System.Console.WriteLine("No hackrf devices were found");
                System.Console.WriteLine("Press any key to close application");
                System.Console.ReadKey();
                return;
            }
            NetHackrf device = devices[0].OpenDevice(); // connect to a first hackrf in the list



            System.Console.WriteLine(device.HackrfVersion);
            System.Console.WriteLine(device.UsbApiVersion);
            device.CarrierFrequencyMHz = 444.0; // set carrier frequency
            device.SampleFrequencyMHz  = 2;     // set sample frequency
            device.FilterBandwidthMHz  = 0.5;
            device.TXVGAGainDb         = 20;    // set TX amplifier gain
            byte[] buf   = new byte[20000000];
            double phase = 0;

            for (int i = 0; i < buf.Length; i += 2) // calculate NFM test signal
            {
                double signal = 50.0 * Math.Sin((double)i / 4000.0 * Math.PI * 2.0);
                phase     += signal * 0.0001;
                buf[i]     = (byte)((sbyte)(Math.Sin(phase) * 120.0));
                buf[i + 1] = (byte)((sbyte)(Math.Cos(phase) * 120.0));
            }
            var writer = device.StartTX(); // start tx stream

            for (int i = 0; i < 10; i++)
            {
                writer.Write(buf, 0, 2000000); // send NFM signal to hackrf
                System.Console.WriteLine($"Writing block #{i}...");
            }
            writer.Dispose(); // stop tx stream
            System.Console.WriteLine("Press any key to close application");
            System.Console.ReadKey();
        }
예제 #3
0
        static public void Main(string[] args)
        {
            System.Console.WriteLine(NetHackrf.HackrfLibraryVersion());
            System.Console.WriteLine(NetHackrf.HackrfLibraryRelease());
            var devices = NetHackrf.HackrfDeviceList();

            foreach (var i in devices)
            {
                System.Console.WriteLine($"serial=\"{i.serial_number}\", boardId=\"{i.usb_board_id}\", index={i.usb_device_index}");
            }
            if (devices.Length == 0)
            {
                System.Console.WriteLine("No hackrf devices were found");
                System.Console.WriteLine("Press any key to close application");
                System.Console.ReadKey();
                return;
            }
            NetHackrf device = devices[0].OpenDevice();

            System.Console.WriteLine(device.HackrfVersion);
            System.Console.WriteLine(device.UsbApiVersion);
            device.CarrierFrequencyMHz = 444.0;
            device.SampleFrequencyMHz  = 2;
            device.FilterBandwidthMHz  = 0.5;
            device.TXVGAGainDb         = 20;
            byte[] buf   = new byte[20000000];
            double phase = 0;

            for (int i = 0; i < buf.Length; i += 2)
            {
                double signal = 50.0 * Math.Sin((double)i / 4000.0 * Math.PI * 2.0);
                phase     += signal * 0.0001;
                buf[i]     = (byte)((sbyte)(Math.Sin(phase) * 120.0));
                buf[i + 1] = (byte)((sbyte)(Math.Cos(phase) * 120.0));
            }
            var writer = device.StartTX();

            for (int i = 0; i < 10; i++)
            {
                writer.Write(buf, 0, 2000000);
                System.Console.WriteLine($"Writing block #{i}...");
            }
            writer.Dispose();
            System.Console.WriteLine("Press any key to close application");
            System.Console.ReadKey();
        }