public Task StartLogging(AcquisitionProtocolParameters acquisitionProtocol)
 {
     EIT = new EIT(RecordNumber++, EITDefaultChunkSize, acquisitionProtocol.AsJson(), fileId, groupEIT, Logger);
     //var acquisitionInformation = new AcquisitionInformation(acquisitionProtocol, fileId, groupEIT, Logger);
     //acquisitionInformation.FlushDataAndCloseObject();
     ECG = new ECG(fileId, groupRoot, ECGDefaultChunkSize, (int)acquisitionProtocol.ScanDescription.EcgParams.SampleRate, Logger);
     SystemEvents.StartLogging();
     RPosition.StartLogging();
     Tags.StartLogging();
     return(Task.CompletedTask);
 }
Exemple #2
0
        private async Task <List <EITEntry> > WriteEITData(AcquisitionProtocolParameters parameters,
                                                           KamaAcquisitionFile file, int loop, int sleepsBetweenWritesMilliseconds)
        {
            var result = await Task.Factory.StartNew(() =>
            {
                Random random = new Random();
                List <ElectrodeFrame> samples = new List <ElectrodeFrame>();
                for (int index = 0; index < loop; index++)
                {
                    ElectrodeFrame frame       = new ElectrodeFrame();
                    frame.ComplexCurrentMatrix = Enumerable.Range(0, 2441)
                                                 .Select(i => ((float)random.NextDouble(), (float)random.NextDouble())).ToArray();
                    frame.ComplexVoltageMatrix = Enumerable.Range(0, 2441)
                                                 .Select(i => ((float)random.NextDouble(), (float)random.NextDouble())).ToArray();
                    frame.PacketId       = (ulong)index;
                    var timestamp        = DateTimeOffset.Now;
                    frame.timestamp      = timestamp.ToUnixTimeMilliseconds();
                    ulong saturationMask = (ulong)random.Next();
                    saturationMask       = (saturationMask << 32);
                    saturationMask       = saturationMask | (ulong)random.Next();
                    frame.SaturationMask = saturationMask;
                    Thread.Sleep(sleepsBetweenWritesMilliseconds);
                    file.AppendElectrodeSample(frame);
                    samples.Add(frame);
                }

                EITEntry entry = new EITEntry
                {
                    Configuration = parameters.AsJson(),
                    StartDateTime = DateTimeOffset.FromUnixTimeMilliseconds(samples.First().timestamp).DateTime,
                    EndDateTime   = DateTimeOffset.FromUnixTimeMilliseconds(samples.Last().timestamp).DateTime,
                    VoltagesReal  = new float[samples.Count, samples[0].ComplexVoltageMatrix.Length],
                    VoltagesIm    = new float[samples.Count, samples[0].ComplexVoltageMatrix.Length],
                    CurrentsIm    = new float[samples.Count, samples[0].ComplexVoltageMatrix.Length],
                    CurrentsReal  = new float[samples.Count, samples[0].ComplexVoltageMatrix.Length],
                    Saturation    = new ulong[samples.Count, 1],
                    Timestamps    = new long[samples.Count, 1]
                };

                for (var i = 0; i < samples.Count; i++)
                {
                    ElectrodeFrame electrodeFrame = samples[i];

                    for (int j = 0; j < electrodeFrame.ComplexVoltageMatrix.Length; j++)
                    {
                        entry.VoltagesReal[i, j] = electrodeFrame.ComplexVoltageMatrix[j].Re;
                        entry.VoltagesIm[i, j]   = electrodeFrame.ComplexVoltageMatrix[j].Im;
                    }

                    for (int j = 0; j < electrodeFrame.ComplexCurrentMatrix.Length; j++)
                    {
                        entry.CurrentsReal[i, j] = electrodeFrame.ComplexCurrentMatrix[j].Re;
                        entry.CurrentsIm[i, j]   = electrodeFrame.ComplexCurrentMatrix[j].Im;
                    }

                    entry.Saturation[i, 0] = electrodeFrame.SaturationMask;
                    entry.Timestamps[i, 0] = electrodeFrame.timestamp;
                }

                return(entry);
            });

            return(new List <EITEntry>
            {
                result
            });
        }