예제 #1
0
 public RHDDataFrame(RHDDataBlock dataBlock, int hardware_clock_hz)
 {
     Clock         = GetClock(dataBlock.Clock);
     Time          = GetTime(dataBlock.Clock, hardware_clock_hz);
     EphysData     = GetEphysData(dataBlock.EphysData);
     AuxiliaryData = GetAuxiliaryData(dataBlock.AuxiliaryData);
 }
예제 #2
0
        public RHDDevice()
        {
            // Reference to context
            this.oni_ref = ONIManager.ReserveDAQ();

            // Find the hardware clock rate
            var sample_clock_hz = (int)50e6; // TODO: oni_ref.DAQ.AcquisitionClockHz;

            // Find all RHD devices
            devices = oni_ref.DAQ.DeviceMap.Where(
                pair => pair.Value.id == (uint)Device.DeviceID.RHD2132 || pair.Value.id == (uint)Device.DeviceID.RHD2164
                ).ToDictionary(x => x.Key, x => x.Value);

            // Stop here if there are no devices to use
            if (devices.Count == 0)
            {
                throw new oni.ONIException((int)oni.lib.Error.DEVIDX);
            }

            DeviceIndex         = new DeviceIndexSelection();
            DeviceIndex.Indices = devices.Keys.ToArray();

            // Set defaults here, these settings can be manipulated in the outer scope and affect the functionality of the Task, I think.
            SampleRate         = AmplifierSampleRate.SampleRate30000Hz;
            LowerBandwidth     = 0.1;
            UpperBandwidth     = 7500.0;
            DspCutoffFrequency = 1.0;
            DspEnabled         = true;

            source = Observable.Create <RHDDataFrame>(observer =>
            {
                EventHandler <FrameReceivedEventArgs> inputReceived;
                var data_block = new RHDDataBlock(NumEphysChannels((int)devices[DeviceIndex.SelectedIndex].id), BlockSize);

                oni_ref.Environment.Start();

                inputReceived = (sender, e) =>
                {
                    var frame = e.Value;
                    //If this frame contaisn data from the selected device_index
                    if (frame.DeviceIndices.Contains(DeviceIndex.SelectedIndex))
                    {
                        // Pull the sample
                        if (data_block.FillFromFrame(frame, DeviceIndex.SelectedIndex))
                        {
                            observer.OnNext(new RHDDataFrame(data_block, sample_clock_hz)); //TODO: Does this deep copy??
                            data_block = new RHDDataBlock(NumEphysChannels((int)devices[DeviceIndex.SelectedIndex].id), BlockSize);
                        }
                    }
                };

                oni_ref.Environment.FrameInputReceived += inputReceived;
                return(Disposable.Create(() =>
                {
                    oni_ref.Environment.FrameInputReceived -= inputReceived;
                    oni_ref.Environment.Stop();
                    oni_ref.Dispose();
                }));
            });
        }