123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading;
- using Uestc.Auto6.Dso.ComModel;
- using Uestc.Auto6.Dso.Hardware.Driver;
- using Uestc.Auto6.Dso.MathExt;
- namespace Uestc.Auto6.Dso.Core
- {
- internal class DataSrcFifo : IDataSource
- {
- private CohAverager Averager
- {
- get;
- init;
- }
- private Envelope Evlp
- {
- get;
- init;
- }
- private sealed record Parameter(WfmProperties Properties, List<UInt16> Buffer, Double Pos0ByAdc, AnaChnlCoupling Coupling, Boolean Inverted, AnaChnlAcqMode Mode, CancellationToken CancelToken);
- public Object? Prepare(Boolean init, ChannelId aid, CancellationToken ct)
- {
- _ = Hd.AnalogChannel!.TakeChannelWaveform((Int32)aid, out var buffer, out var si);
- var ach = (AnalogModel)DsoModel.Default.GetChannel(aid);
- var prop = new WfmProperties(ach.Name)
- {
- ChnlPosition = (ach.Conditioning.PosIndex, ach.Conditioning.PositionBymV),
- ChnlScale = ((Int32)ach.Conditioning.ScaleIndex, ach.Conditioning.ScaleBymV),
- ChnlUnit = (ach.Conditioning.Prefix, ach.Conditioning.Unit),
- TmbPosition = (ach.Sampling.PosIndex, ach.Sampling.PositionByus),
- TmbScale = ((Int32)ach.Sampling.ScaleIndex, ach.Sampling.ScaleByus),
- TmbUnit = (ach.Sampling.Prefix, ach.Sampling.Unit),
- SampleIntByus = si.SampleIntervalByus,
- Factor = si.SampleIntervalByus * Constants.IDX_PER_XDIV / ach.Sampling.ScaleByus,
- };
- Averager.MaxCnts = ach.Sampling.AverageCnt;
- //Evlp.MaxCnts = ach.Sampling.EnvelopeCnt;
- if (init)
- {
- Averager.Reset();
- //Evlp.Reset();
- }
- var pos0 = ach.Conditioning.PosIndex / Constants.IDX_PER_YDIV * Constants.SAMPS_PER_YDIV + Constants.MAX_ADC_RES / 2;
- return new Parameter(prop, buffer, pos0, ach.Conditioning.Coupling, ach.Conditioning.IsInverted, ach.Sampling.Mode, ct);
- }
- public (Double[,], Object)? Read(Object? param)
- {
- var pm = (Parameter)param!;
-
- return (pm.Buffer.Select((s) => (Double)s).ToRowVector(), pm.Properties);
- }
- public WfmPack Process((Double[,] Buffer, Object Prop) pkg, Object? param)
- {
- var pm = (Parameter)param!;
- for (Int32 i = 0; i < pkg.Buffer.GetLength(0); i++)
- {
- if (pm.Inverted)
- {
- Double temp = pm.Pos0ByAdc * 2;
- for (Int32 j = 0; j < pkg.Buffer.GetLength(1); j++)
- pkg.Buffer[i, j] = temp - pkg.Buffer[i, j];
- }
- for (Int32 j = 0; j < pkg.Buffer.GetLength(1); j++)
- {
- if (pkg.Buffer[i, j] > Constants.MAX_ADC_RES)
- pkg.Buffer[i, j] = Constants.MAX_ADC_RES;
- else if (pkg.Buffer[i, j] < 0)
- pkg.Buffer[i, j] = 0;
- pkg.Buffer[i, j] = (pkg.Buffer[i, j] - pm.Pos0ByAdc) / Constants.SAMPS_PER_YDIV * pm.Properties.ChnlScale.Value;
- }
- switch (pm.Mode)
- {
- case AnaChnlAcqMode.Average:
- pkg.Buffer = Averager.Run(pkg.Buffer, 0);
- break;
- //case AnaChnlAcqMode.Envelope:
- // matrix = Evlp.Run(matrix);
- // break;
- }
- }
- return new WfmPack(pkg.Buffer, 0, pkg.Buffer.GetLength(1), (WfmProperties)pkg.Prop);
- }
- public DataSrcFifo(Int32 length)
- {
- Averager = new(1, length);
- Evlp = new(1, length);
- }
- }
- }
|