Exemplo n.º 1
0
        /// <summary>
        /// Scans provided collection of frequencies against specified Squelch value.
        /// </summary>
        /// <param name="frequency">a collection of frequency bands which should get scanned</param>
        /// <param name="threshold">Raw squelch value [0-256]</param>
        /// <remarks> The block scanning automatically ends when scanned RAW signal strength value rises <see cref="G313BlockScanner.FrequencyScanned"/>the event.</remarks>
        /// <returns>Returns true if the operation is started</returns>
        /// <exception cref="InvalidOperationException">Cannot start when scanning is in-progress.</exception>
        public bool Start(ICollection <uint> frequency, int threshold = 256)
        {
            if (_started)
            {
                throw new InvalidOperationException("block scanning already in progress");
            }

            _frequencies = frequency.ToArray();
            _rawStrength = new uint[_frequencies.Count()];
            _frequencies.CopyTo(_rawStrength, 0);
            _threshold = threshold;

            _gcHandle = GCHandle.Alloc(_rawStrength, GCHandleType.Pinned);

            var result = G313Api.BlockScan(_parent.Handle.ToInt32(), _gcHandle.AddrOfPinnedObject(), (uint)_frequencies.Length, threshold, uint.MaxValue, IntPtr.Zero, 0);

            if (!result)
            {
                _gcHandle.Free();
                return(false);
            }

            _started = true;

            _task = TaskUtility.Run(MonitorScan);
            //_task = Task.Run(() => MonitorScan());

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets Automatic gain control mode.
        /// </summary>
        /// <returns>Returns <see cref="G313.Agc"/> Automatic gain control state</returns>
        public Agc Agc()
        {
            var result = G313Api.GetAGC(GetHandle());

            CheckResultOnNegative(result);

            return((Agc)result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retrieves the PLLs lock status.
        /// </summary>
        /// <returns>If the function succeeds, the return value is a combination of the PLLs lock bits. Otherwise 0 is returned.</returns>
        public uint PllLock()
        {
            var result = G313Api.GetLock(GetHandle(), 0);

            CheckResultOnZero(result);

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Retrieves the current reference clock frequency.
        /// </summary>
        /// <returns>Returns current clock.</returns>
        public uint ReferenceClock()
        {
            var result = G313Api.GetRefClock(GetHandle());

            CheckResultOnMax(result);

            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Retrieves the current IF2 frequency.
        /// </summary>
        /// <returns>The current receiver frequency in Hz. If the handle is invalid, 0 is returned instead.</returns>
        public int If2Frequency()
        {
            var result = G313Api.GetIF2Frequency(GetHandle());

            CheckResultOnZero(result);

            return(result);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Retrieves IF gain value.
        /// </summary>
        /// <returns>returns IF gain value.</returns>
        public int IfGain()
        {
            var result = G313Api.GetIFGain(GetHandle());

            CheckResultOnNegative(result);

            return(result);
        }
Exemplo n.º 7
0
        public override void Dispose()
        {
            var result = G313Api.CloseRadioDevice(GetHandle());

            if (!result)
            {
                throw new InvalidOperationException("failed to close device");
            }
        }
Exemplo n.º 8
0
        public ICollection <LegacyRadioInfo> ListLegacy()
        {
            var info = new NativeDefinitions.OldRadioInfo();
            var ptr  = Marshal.AllocHGlobal(info.bLength);

            var count = G313Api.G3GetRadioList(ptr, info.bLength);

            Marshal.PtrToStructure(ptr, info);
            Marshal.FreeHGlobal(ptr);

            return(count > 1 ? ListLegacyBig((int)count, info.bLength) : new[] { new LegacyRadioInfo(info) });
        }
Exemplo n.º 9
0
        /// <summary>
        /// Retrieves the system pathname of the receiver.
        /// </summary>
        /// <returns>Returns path name.</returns>
        public string SystemPath()
        {
            var ptr = G313Api.GetPath2(GetHandle());

            if (ptr.ToInt32() == 0)
            {
                throw new OperationFailedException("failed to retrieve system path", this);
            }

            var path = Marshal.PtrToStringAuto(ptr);

            return(path);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Opens a radio device by its index to allow you to control the device using the other API functions.
        /// </summary>
        /// <param name="index">Radio device number that you would like to open from 1 to 255. If zero is specified, it will open thenext available device.</param>
        /// <param name="radio">G313Radio instance</param>
        /// <returns>Returns true if the operation is successful</returns>
        public bool TryOpen(int index, out G313Radio radio)
        {
            var handle = G313Api.OpenRadioDevice(index);

            if (handle == 0)
            {
                radio = null;
                return(false);
            }

            radio = new G313Radio(new IntPtr(handle));
            return(true);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Opens a radio device by its serial number to allow you to control the device using the other API functions.
        /// </summary>
        /// <param name="serial">Radio device serial number that you would like to open. If NULL is specified, a demo receiver will beopened. The serial number is a null-terminated string.</param>
        /// <param name="radio">G313Radio instance</param>
        /// <returns>Returns true if the operation is successful</returns>
        public bool TryOpen(string serial, out G313Radio radio)
        {
            var handle = G313Api.Open(serial);

            if (handle == 0)
            {
                radio = null;
                return(false);
            }

            radio = new G313Radio(new IntPtr(handle));
            return(true);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Retrieves receiver information.
        /// </summary>
        /// <returns>Returns <see cref="RadioInfo"/> retrieved information.</returns>
        public RadioInfo Info()
        {
            var info = new NativeDefinitions.RadioInfo2();
            var ptr  = Marshal.AllocHGlobal((int)info.bLength);

            Marshal.StructureToPtr(info, ptr, true);

            G313Api.GetInfo(GetHandle(), ptr);

            Marshal.PtrToStructure(ptr, info);
            Marshal.FreeHGlobal(ptr);

            CachedInfo = new RadioInfo(info);
            return(CachedInfo);
        }
Exemplo n.º 13
0
        /// <summary>
        /// The DSP must be initialized before any signal processing, including signal strength measurement, can commence. When initializing the demodulator the full path to a valid calibration data file may be provided if signal strength measuremen must be calibrated. If not so, the passed pointer should be NULL.
        /// </summary>
        /// <param name="calibrateDataPath">The file containing the calibration data for the receiver in use.</param>
        /// <returns>Returns <see cref="G313Demodulator"/> context of demodulator.</returns>
        public G313Demodulator Demodulator(string calibrateDataPath = null)
        {
            if (DemodulatorInitialized)
            {
                return(_demodulator);
            }

            DemodulatorInitialized = G313Api.InitializeDemodulator(GetHandle(), calibrateDataPath);
            if (!DemodulatorInitialized)
            {
                throw new InvalidOperationException("failed to initialize demodulator.");
            }
            _demodulator.SetupStreams();

            return(_demodulator);
        }
Exemplo n.º 14
0
        private static ICollection <LegacyRadioInfo> ListLegacyBig(int deviceCount, int size)
        {
            var bufferSize = deviceCount * size;
            var ptr        = Marshal.AllocHGlobal(bufferSize);

            var count = G313Api.G3GetRadioList(ptr, bufferSize);

            var buffer = ToManagedStructure <NativeDefinitions.OldRadioInfo>(ptr, size, (int)count);

            Marshal.FreeHGlobal(ptr);

            if (count != deviceCount)
            {
                throw new InvalidOperationException("device count mismatch!");
            }

            return(buffer.Select(raw => new LegacyRadioInfo(raw)).ToArray());
        }
Exemplo n.º 15
0
        public ICollection <CompleteRadioInfo> ListComplete()
        {
            var info = new NativeDefinitions.RadioInfo();
            var ptr  = Marshal.AllocHGlobal(info.bLength);

            var structSize = 0;
            var count      = G313Api.G3GetRadioList2(ptr, info.bLength, ref structSize);

            if (info.bLength != structSize)
            {
                throw new InvalidOperationException("info size mismatch");
            }

            Marshal.PtrToStructure(ptr, info);
            Marshal.FreeHGlobal(ptr);

            return(count > 1 ? ListCompleteBig((int)count, structSize) : new[] { new CompleteRadioInfo(info) });
        }
Exemplo n.º 16
0
 /// <summary>
 /// Specifies the reference clock frequency and allows switching between internal and external references.
 /// </summary>
 /// <param name="value">Specified value</param>
 /// <returns>Returns true if the specified value is set</returns>
 public bool TryReferenceClock(uint value)
 {
     return(G313Api.SetRefClock(GetHandle(), value));
 }
Exemplo n.º 17
0
        /// <summary>
        /// The GetInternalRSSI function returns a combination of the RSSI and AGC values read from the receiver hardware.
        /// </summary>
        /// <returns>Returns <see cref="G313.InternalRssi"/> read parameters from receiver</returns>
        public InternalRssi InternalRssi()
        {
            var result = G313Api.GetInternalRSSI(GetHandle());

            return(new InternalRssi(result));
        }
Exemplo n.º 18
0
 /// <summary>
 /// Waits for the end of a receiver tunning started by a <see cref="FrequencyAsync"/> call.
 /// </summary>
 /// <returns>Returns true on successful block.</returns>
 public bool WaitFrequencyAsync()
 {
     return(G313Api.WaitFreqAsync(GetHandle()));
 }
Exemplo n.º 19
0
 /// <summary>
 /// Starts the sequence of hardware commands that sets the frequency the device is to be tuned to. In order to insure the sequence has been executed and that the hardware is properly tuned, WaitFrequencyAsync function must be called.
 /// </summary>
 /// <param name="frequency">Specified frequency.</param>
 /// <returns>Returns true if the command is issued.</returns>
 public bool TryFrequencyAsync(uint frequency)
 {
     CheckFrequency(frequency);
     return(G313Api.SetFreqAsync(GetHandle(), frequency));
 }
Exemplo n.º 20
0
 /// <summary>
 /// Determines device connection.
 /// </summary>
 /// <returns>Returns true if the device is connected.</returns>
 public bool Connected()
 {
     return(G313Api.IsDeviceConnected(GetHandle()));
 }
Exemplo n.º 21
0
 /// <summary>
 /// sets the center frequency of the last IF signal.
 /// </summary>
 /// <param name="frequency">Specifies the IF2 frequency. It can be either positive or negative, negative values causing an IF2 spectrum inversion</param>
 /// <returns>Returns true if the specified value is set.</returns>
 public bool TryIf2Frequency(int frequency)
 {
     return(G313Api.SetIF2Frequency(GetHandle(), frequency));
 }
Exemplo n.º 22
0
 /// <summary>
 /// Sets Radio panel LED patterns
 /// </summary>
 /// <param name="mask">Specified mask pattern</param>
 /// <returns>Returns true if the specified pattern is set.</returns>
 public bool TryLedPattern(byte mask)
 {
     return(G313Api.SetLEDFlashPattern(GetHandle(), mask));
 }
Exemplo n.º 23
0
 /// <summary>
 /// Activates or deactivates the RF input attenuator. It is used to prevent overloading of the receiver with strong signals.
 /// </summary>
 /// <param name="state">Specified state.</param>
 /// <returns>Returns true if the specified state is set.</returns>
 public bool TryAttenuator(bool state)
 {
     return(G313Api.SetAtten(GetHandle(), state));
 }
Exemplo n.º 24
0
 /// <summary>
 /// Retrieves the RF input attenuator setting.
 /// </summary>
 /// <returns>Returns the attenuator value.</returns>
 public bool Attenuator()
 {
     return(G313Api.GetAtten(GetHandle()));
 }
Exemplo n.º 25
0
 /// <summary>
 /// Checks the receiver whether it is ready to accept commands.
 /// </summary>
 /// <returns>Returns true if the device is busy.</returns>
 public bool Busy()
 {
     return(G313Api.IsBusy(GetHandle()));
 }
Exemplo n.º 26
0
 /// <summary>
 /// Sets radio power state.
 /// </summary>
 /// <param name="state">Specified power state.</param>
 /// <returns>Returns true if the specified value is set.</returns>
 public bool TryPower(bool state)
 {
     return(G313Api.SetPower(GetHandle(), state));
 }
Exemplo n.º 27
0
 /// <summary>
 /// Retrieves radio power state.
 /// </summary>
 /// <returns>Returns power state.</returns>
 public bool Power()
 {
     return(G313Api.GetPower(GetHandle()));
 }
Exemplo n.º 28
0
 /// <summary>
 /// Specifies default reference clock frequency and allows switching between internal and external references.
 /// </summary>
 /// <returns>Returns true if internal clock is used.</returns>
 public bool TryUseInternalClock()
 {
     return(G313Api.SetRefClock(GetHandle(), 0));
 }
Exemplo n.º 29
0
 /// <summary>
 /// Sets Automatic gain control mode.
 /// </summary>
 /// <param name="value"><see cref="G313.Agc"/> Specified mode</param>
 /// <returns>Returns true if the specified mode is set.</returns>
 public bool TryAgc(Agc value)
 {
     return(G313Api.SetAGC(GetHandle(), (int)value));
 }
Exemplo n.º 30
0
 /// <summary>
 /// Sets IFGain value.
 /// </summary>
 /// <param name="value">Specified value</param>
 /// <returns>Returns true if the specified value is set.</returns>
 public bool TryIfGain(int value)
 {
     CheckIfGain(value);
     return(G313Api.SetIFGain(GetHandle(), value));
 }