DynExp
Highly flexible laboratory automation for dynamically changing experiments.
DataStreamInstrument.h
Go to the documentation of this file.
1 // This file is part of DynExp.
2 
9 #pragma once
10 
11 #include "stdafx.h"
12 #include "Instrument.h"
13 
14 namespace DynExpInstr
15 {
16  class DataStreamInstrument;
17 
21  namespace DataStreamInstrumentTasks
22  {
27  {
29 
34  };
35 
40  {
42 
47  };
48 
53  {
55 
60  };
61 
65  class SetStreamSizeTask final : public DynExp::TaskBase
66  {
67  public:
74 
75  private:
77 
78  const size_t BufferSizeInSamples;
79  };
80  }
81 
85  struct BasicSample
86  {
87  using DataType = double;
88 
92  constexpr BasicSample() noexcept : Value(0), Time(0) {}
93 
98  constexpr BasicSample(DataType Value) noexcept : Value(Value), Time(0) {}
99 
105  constexpr BasicSample(DataType Value, DataType Time) noexcept : Value(Value), Time(Time) {}
106 
109  };
110 
116  {
117  public:
121  using BasicSampleListType = std::vector<BasicSample>;
122 
123  virtual ~DataStreamBase() = default;
124 
129 
135  virtual bool IsBasicSampleConvertible() const noexcept { return false; }
136 
144  virtual bool IsBasicSampleTimeUsed() const noexcept { return false; }
145 
151  virtual void SeekBeg(std::ios_base::openmode Which = std::ios_base::in | std::ios_base::out) = 0;
152 
159  virtual void SeekEnd(std::ios_base::openmode Which = std::ios_base::in | std::ios_base::out) = 0;
160 
167  virtual bool SeekEqual(std::ios_base::openmode Which = std::ios_base::in | std::ios_base::out) = 0;
168 
173  virtual size_t GetStreamSizeRead() const noexcept = 0;
174 
179  virtual size_t GetStreamSizeWrite() const noexcept = 0;
180 
187  virtual size_t GetNumSamplesWritten() const noexcept = 0;
188 
193  virtual void SetStreamSize(size_t BufferSizeInSamples) = 0;
195 
201  bool CanRead() const { return GetStreamSizeRead(); }
202 
206  void Clear() { ClearChild(); }
207 
212  void WriteBasicSample(const BasicSample& Sample) { WriteBasicSampleChild(Sample); }
213 
219 
224  void WriteBasicSamples(const BasicSampleListType& Samples);
225 
231 
232  private:
237 
242  virtual void WriteBasicSampleChild(const BasicSample& Sample);
243 
250 
251  virtual void ClearChild() = 0;
253  };
254 
258  template <typename T>
259  using DataStreamPtrType = std::unique_ptr<T>;
260 
265 
270  {
271  protected:
273  virtual ~CircularDataStreamBase() = default;
274 
275  public:
280 
285  virtual size_t GetNumAvailableSamplesToReadTillEnd() const noexcept = 0;
286 
292  virtual size_t GetNumFreeSamplesToWrite() const noexcept = 0;
293 
299  virtual std::streampos GetReadPosition() const noexcept = 0;
300 
306  virtual std::streampos GetWritePosition() const noexcept = 0;
307 
317  virtual bool SeekRel(signed long long OffsetInSamples, std::ios_base::seekdir SeekDir,
318  std::ios_base::openmode Which = std::ios_base::in | std::ios_base::out) = 0;
319 
327  virtual bool SeekAbs(unsigned long long PositionInSamples, std::ios_base::openmode Which = std::ios_base::in | std::ios_base::out) = 0;
329 
339  size_t GetNumRecentBasicSamples(size_t Count) const;
340 
348  };
349 
354  template <
355  typename SampleT,
356  std::enable_if_t<std::is_trivially_copyable_v<SampleT>, int> = 0
357  >
359  {
360  public:
361  using SampleType = SampleT;
362 
367  CircularDataStream(size_t BufferSizeInSamples)
368  : StreamBuffer(sizeof(SampleT) * BufferSizeInSamples), Stream(&StreamBuffer), NumSamplesWritten(0)
369  {
370  Stream.exceptions(std::iostream::failbit | std::iostream::badbit);
371  }
372 
373  virtual ~CircularDataStream() = default;
374 
379  constexpr auto GetBytesPerSample() noexcept { return sizeof(SampleT); }
380 
381  size_t GetNumAvailableSamplesToReadTillEnd() const noexcept override { return (StreamBuffer.gsize() - StreamBuffer.gtellp()) / sizeof(SampleT); }
382  size_t GetNumFreeSamplesToWrite() const noexcept override { return (StreamBuffer.psize() - StreamBuffer.ptellp()) / sizeof(SampleT); }
383  std::streampos GetReadPosition() const noexcept override { return StreamBuffer.gtellp() / sizeof(SampleT); }
384  std::streampos GetWritePosition() const noexcept override { return StreamBuffer.ptellp() / sizeof(SampleT); }
385 
386  virtual bool SeekRel(signed long long OffsetInSamples, std::ios_base::seekdir SeekDir,
387  std::ios_base::openmode Which = std::ios_base::in | std::ios_base::out) override
388  {
389  return StreamBuffer.pubseekoff(OffsetInSamples * sizeof(SampleT), SeekDir, Which) !=
390  Util::circularbuf::pos_type(Util::circularbuf::off_type(-1));
391  }
392 
393  virtual bool SeekAbs(unsigned long long PositionInSamples,
394  std::ios_base::openmode Which = std::ios_base::in | std::ios_base::out) override
395  {
396  return StreamBuffer.pubseekpos(PositionInSamples * sizeof(SampleT), Which) !=
397  Util::circularbuf::pos_type(Util::circularbuf::off_type(-1));
398  }
399 
400  virtual void SeekBeg(std::ios_base::openmode Which = std::ios_base::in | std::ios_base::out) override
401  {
402  SeekAbs(0, Which);
403  }
404 
405  virtual void SeekEnd(std::ios_base::openmode Which = std::ios_base::in | std::ios_base::out) override
406  {
407  if (Which & std::ios_base::in)
408  SeekRel(-1, std::ios_base::end, std::ios_base::in);
409  if (Which & std::ios_base::out)
410  SeekRel(0, std::ios_base::end, std::ios_base::out);
411  }
412 
413  virtual bool SeekEqual(std::ios_base::openmode Which = std::ios_base::in | std::ios_base::out) override
414  {
415  if (Which & std::ios_base::in)
416  {
417  StreamBuffer.pubsync();
418 
420  SeekAbs(GetWritePosition(), std::ios_base::in);
421  else
422  return false;
423  }
424 
425  // Read buffer is never larger than write buffer.
426  if (Which & std::ios_base::out)
427  SeekAbs(GetReadPosition(), std::ios_base::out);
428 
429  return true;
430  }
431 
432  virtual size_t GetStreamSizeRead() const noexcept override { return StreamBuffer.gsize() / sizeof(SampleT);}
433  virtual size_t GetStreamSizeWrite() const noexcept override { return StreamBuffer.psize() / sizeof(SampleT); }
434  virtual size_t GetNumSamplesWritten() const noexcept override { return NumSamplesWritten; }
435  virtual void SetStreamSize(size_t BufferSizeInSamples) override { StreamBuffer.resize(sizeof(SampleT) * BufferSizeInSamples); }
436 
441 
445  void WriteSample(const SampleT& Sample)
446  {
447  ValidateSample(Sample);
448 
449  Stream.write(reinterpret_cast<const char*>(&Sample), sizeof(SampleT));
450 
451  // Should never overflow. Let's assume 10 Gb/s = 1.25e9 B/s transmission rate:
452  // Overflows in (2^64 - 1) B / 1.25e9 B/s / 60 / 60 / 24 / 365 = 468 years.
453  if (NumSamplesWritten < std::numeric_limits<decltype(NumSamplesWritten)>::max())
454  ++NumSamplesWritten;
455  }
456 
465  template <typename Rep, typename Period>
466  void WriteSample(const std::chrono::duration<Rep, Period>& Sample)
467  {
468  WriteSample(Sample.count());
469  }
470 
475  SampleT ReadSample()
476  {
477  SampleT Sample;
478  Stream.read(reinterpret_cast<char*>(&Sample), sizeof(SampleT));
479 
480  return Sample;
481  }
482 
488  template <typename T>
489  void WriteSamples(const std::vector<T>& Samples)
490  {
491  for (const auto& Sample : Samples)
492  WriteSample(Sample);
493  }
494 
500  std::vector<SampleT> ReadSamples(size_t Count)
501  {
502  std::vector<SampleT> Samples;
503 
504  for (decltype(Count) i = 0; i < Count; ++i)
505  Samples.push_back(ReadSample());
506 
507  return Samples;
508  }
509 
510  protected:
511  virtual void ClearChild() override
512  {
513  Stream.clear();
514  StreamBuffer.clear();
515  }
516 
517  private:
522 
529  virtual void ValidateSample(const SampleT& Sample) const {}
531 
533  std::iostream Stream;
535  };
536 
541  class BasicSampleStream : public CircularDataStream<BasicSample>
542  {
543  public:
548  BasicSampleStream(size_t BufferSizeInSamples) : CircularDataStream(BufferSizeInSamples) {}
549 
550  virtual ~BasicSampleStream() = default;
551 
552  bool IsBasicSampleConvertible() const noexcept override final { return true; }
553  bool IsBasicSampleTimeUsed() const noexcept override final { return true; }
554 
555  private:
556  virtual void WriteBasicSampleChild(const BasicSample& Sample) override { WriteSample(Sample); }
557  virtual BasicSample ReadBasicSampleChild() override { return ReadSample(); }
558  };
559 
565  template <
566  typename SampleT,
567  std::enable_if_t<std::is_arithmetic_v<SampleT>, int> = 0
568  >
569  class NumericSampleStream : public CircularDataStream<SampleT>
570  {
571  public:
577  NumericSampleStream(size_t BufferSizeInSamples) : CircularDataStream<SampleT>(BufferSizeInSamples),
578  MinValue(std::numeric_limits<SampleT>::lowest()), MaxValue(std::numeric_limits<SampleT>::max()) {}
579 
587  NumericSampleStream(size_t BufferSizeInSamples, SampleT MinValue, SampleT MaxValue)
588  : CircularDataStream<SampleT>(BufferSizeInSamples), MinValue(MinValue), MaxValue(MaxValue) {}
589 
590  virtual ~NumericSampleStream() = default;
591 
592  bool IsBasicSampleConvertible() const noexcept override final { return true; }
593 
599  void SetLimits(SampleT MinValue, SampleT MaxValue)
600  {
601  this->MinValue = MinValue;
602  this->MaxValue = MaxValue;
603  }
604 
609  auto GetMinValue() const noexcept { return MinValue; }
610 
615  auto GetMaxValue() const noexcept { return MaxValue; }
616 
617  private:
623  virtual void WriteBasicSampleChild(const BasicSample& Sample) override
624  {
625  CircularDataStream<SampleT>::WriteSample(static_cast<SampleT>(Sample.Value));
626  }
627 
633  {
634  BasicSample Sample;
635 
636  // Ignore time value (set it to 0). It has been considered (and discarded) to set it to
637  // std::chrono::system_clock::now() instead. This would be misleading since a timestamp
638  // which is set here refers to the time when the sample is read from the buffer - not
639  // to the time when it is actually acquired by the underlying hardware.
640  Sample.Time = 0;
641  Sample.Value = static_cast<decltype(Sample.Value)>(CircularDataStream<SampleT>::ReadSample());
642 
643  return Sample;
644  }
645 
646  virtual void ValidateSample(const SampleT& Sample) const override
647  {
648  if (Sample < MinValue || Sample > MaxValue)
650  "A sample cannot be written to a stream buffer because it exceeds the specified limits (min: " + std::to_string(MinValue)
651  + ", max: " + std::to_string(MaxValue) + ", sample: " + std::to_string(Sample) + ")");
652  }
653 
654  SampleT MinValue;
655  SampleT MaxValue;
656  };
657 
662 
667  {
668  static constexpr ParamsConfigDialog::NumberType DefaultStreamSize = 1000;
669 
670  public:
675  struct ValueType
676  {
677  ParamsConfigDialog::NumberType StreamSize = DefaultStreamSize;
678  };
679 
688  ParamsConfigDialog::NumberType DefaultValue = DefaultStreamSize, ParamsConfigDialog::NumberType MinValue = 1,
689  ParamsConfigDialog::NumberType MaxValue = static_cast<double>(std::numeric_limits<size_t>::max()))
690  : StreamSize{ Owner, "StreamSize", "Stream size",
691  "Size of the instrument's sample stream buffer in samples.", true, DefaultValue, MinValue, MaxValue, 1, 0 }
692  {}
693 
697  void DisableUserEditable();
698 
704  ValueType Values() const { return { StreamSize }; }
705 
711  };
712 
717  {
718  public:
722  enum SamplingModeType { Single, Continuous };
733  private:
734  static constexpr ParamsConfigDialog::NumberType DefaultSamplingRate = 1;
735  static constexpr SamplingModeType DefaultSamplingMode = SamplingModeType::Single;
736 
737  public:
742  struct ValueType
743  {
744  ParamsConfigDialog::NumberType SamplingRate = DefaultSamplingRate;
745  SamplingModeType SamplingMode = DefaultSamplingMode;
746  };
747 
752  static Util::TextValueListType<SamplingModeType> SamplingModeTypeStrList();
753 
759  : SamplingRate{ Owner, "SamplingRate", "Sampling rate",
760  "Sampling rate in samples per second.", true, DefaultSamplingRate, 0, std::numeric_limits<ParamsConfigDialog::NumberType>::max(), 1, 3 },
761  SamplingMode{ Owner, SamplingModeTypeStrList(), "SamplingMode", "Sampling mode",
762  "Determines whether reading/writing happens only once or continuously.", true, DefaultSamplingMode }
763  {}
764 
768  void DisableUserEditable();
769 
775  ValueType Values() const { return { SamplingRate, SamplingMode}; }
776 
782 
788  };
789 
794  {
795  public:
800  using ValueType = double;
801 
807  enum class UnitType {
808  Arbitrary,
809  LogicLevel,
810  Counts,
811  Volt,
812  Ampere,
813  Power_W,
814  Power_dBm
815  };
816 
822  static const char* UnitTypeToStr(const UnitType& Unit);
823 
831 
832  virtual ~DataStreamInstrumentData() = default;
833 
840  DataStreamBasePtrType::element_type* GetSampleStream() const noexcept { return SampleStream.get(); }
841 
848  template <typename T>
849  auto GetCastSampleStream() const
850  {
851  auto CastSampleStream = dynamic_cast<T*>(GetSampleStream());
852  if (!CastSampleStream)
853  throw Util::TypeErrorException();
854 
855  return CastSampleStream;
856  }
857 
858  ValueType GetHardwareMinValue() const noexcept { return HardwareMinValue; }
859  ValueType GetHardwareMaxValue() const noexcept { return HardwareMaxValue; }
860  UnitType GetValueUnit() const noexcept { return ValueUnit; }
861  void SetHardwareMinValue(ValueType Value) noexcept { HardwareMinValue = Value; }
862  void SetHardwareMaxValue(ValueType Value) noexcept { HardwareMaxValue = Value; }
863  void SetValueUnit(UnitType Unit) noexcept { ValueUnit = Unit; }
864 
865  private:
866  void ResetImpl(dispatch_tag<InstrumentDataBase>) override final;
868 
870 
880  };
881 
886  {
887  public:
892  DataStreamInstrumentParams(DynExp::ItemIDType ID, const DynExp::DynExpCore& Core) : InstrumentParamsBase(ID, Core) {}
893 
894  virtual ~DataStreamInstrumentParams() = 0;
895 
896  virtual const char* GetParamClassTag() const noexcept override { return "DataStreamInstrumentParams"; }
897 
898  private:
901 
902  DummyParam Dummy = { *this };
903  };
904 
909  {
910  public:
913 
915  virtual ~DataStreamInstrumentConfigurator() = 0;
916  };
917 
924  {
925  public:
929 
938 
939  constexpr static auto Name() noexcept { return "Data Stream Instrument"; }
940  constexpr static auto Category() noexcept { return "I/O"; }
941 
945  DataStreamInstrument(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType&& Params)
946  : InstrumentBase(OwnerThreadID, std::move(Params)) {}
947 
948  virtual ~DataStreamInstrument() = 0;
949 
950  virtual std::string GetName() const override { return Name(); }
951  virtual std::string GetCategory() const override { return Category(); }
952 
957 
965 
972  const char* GetValueUnitStr() const noexcept { return DataStreamInstrumentData::UnitTypeToStr(GetValueUnit()); }
973 
982 
987  virtual void ReadData(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
988 
995  virtual void WriteData(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
996 
1001  virtual void ClearData(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const {}
1002 
1008  virtual void Start(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const {}
1009 
1015  virtual void Stop(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const {}
1016 
1023  virtual void Restart(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
1024 
1032  virtual void SetStreamSize(size_t BufferSizeInSamples, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
1033 
1039  virtual void ResetStreamSize(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const {}
1040 
1049 
1059 
1066  bool CanRead(const std::chrono::milliseconds Timeout = GetInstrumentDataTimeoutDefault) const;
1067 
1074  void Clear(const std::chrono::milliseconds Timeout = GetInstrumentDataTimeoutDefault) const;
1075 
1076  private:
1077  void ResetImpl(dispatch_tag<InstrumentBase>) override final;
1079 
1080  virtual std::unique_ptr<DynExp::InitTaskBase> MakeInitTask() const override { return DynExp::MakeTask<DataStreamInstrumentTasks::InitTask>(); }
1081  virtual std::unique_ptr<DynExp::ExitTaskBase> MakeExitTask() const override { return DynExp::MakeTask<DataStreamInstrumentTasks::ExitTask>(); }
1082  virtual std::unique_ptr<DynExp::UpdateTaskBase> MakeUpdateTask() const override { return DynExp::MakeTask<DataStreamInstrumentTasks::UpdateTask>(); }
1083  };
1084 }
Implementation of DynExp instrument objects.
Implements a circular data stream based on Util::circularbuf using samples of type BasicSample.
virtual void WriteBasicSampleChild(const BasicSample &Sample) override
Writes a single basic sample to the stream.
virtual ~BasicSampleStream()=default
virtual BasicSample ReadBasicSampleChild() override
Reads a single basic sample from the stream.
BasicSampleStream(size_t BufferSizeInSamples)
Constructs a BasicSampleStream instance.
bool IsBasicSampleTimeUsed() const noexcept override final
Determines whether the data stream holds basic samples (IsBasicSampleConvertible() returns true) whic...
bool IsBasicSampleConvertible() const noexcept override final
Determines whether the data stream holds samples which are compatible to BasicSample.
Base class for all circular data streams based on Util::circularbuf.
virtual ~CircularDataStreamBase()=default
size_t GetNumRecentBasicSamples(size_t Count) const
Determines the amount of samples which have been written to the stream after the last Count samples....
virtual bool SeekAbs(unsigned long long PositionInSamples, std::ios_base::openmode Which=std::ios_base::in|std::ios_base::out)=0
Moves the stream's read/write pointer(s) to an absolute position.
virtual size_t GetNumFreeSamplesToWrite() const noexcept=0
Determines the amount of samples which can be written to the stream untill the stream's end is reache...
BasicSampleListType ReadRecentBasicSamples(size_t Count)
Reads the most recent samples from the stream skipping Count samples. Also refer to GetNumRecentBasic...
virtual std::streampos GetReadPosition() const noexcept=0
Determines the current position of the stream's read (get) pointer in samples.
virtual bool SeekRel(signed long long OffsetInSamples, std::ios_base::seekdir SeekDir, std::ios_base::openmode Which=std::ios_base::in|std::ios_base::out)=0
Moves the stream's read/write pointer(s) to a position relative to SeekDir.
virtual size_t GetNumAvailableSamplesToReadTillEnd() const noexcept=0
Determines the amount of samples which can be read from the stream's current get pointer position til...
virtual std::streampos GetWritePosition() const noexcept=0
Determines the current position of the stream's write (put) pointer in samples.
Implements a circular data stream based on Util::circularbuf.
virtual bool SeekAbs(unsigned long long PositionInSamples, std::ios_base::openmode Which=std::ios_base::in|std::ios_base::out) override
Moves the stream's read/write pointer(s) to an absolute position.
size_t GetNumAvailableSamplesToReadTillEnd() const noexcept override
Determines the amount of samples which can be read from the stream's current get pointer position til...
void WriteSamples(const std::vector< T > &Samples)
Writes multiple samples to the stream's buffer StreamBuffer.
SampleT ReadSample()
Reads a single sample from the stream's buffer StreamBuffer.
std::streampos GetWritePosition() const noexcept override
Determines the current position of the stream's write (put) pointer in samples.
void WriteSample(const SampleT &Sample)
Writes a single sample to the stream's buffer StreamBuffer.
size_t NumSamplesWritten
Amount of samples which have been written to Stream in total.
std::streampos GetReadPosition() const noexcept override
Determines the current position of the stream's read (get) pointer in samples.
virtual size_t GetStreamSizeRead() const noexcept override
Determines the stream's read buffer size in samples.
virtual void ClearChild() override
Removes all samples from the stream's buffer.
size_t GetNumFreeSamplesToWrite() const noexcept override
Determines the amount of samples which can be written to the stream untill the stream's end is reache...
virtual size_t GetStreamSizeWrite() const noexcept override
Determines the stream's write buffer size in samples.
virtual void SetStreamSize(size_t BufferSizeInSamples) override
Sets the stream size in samples.
CircularDataStream(size_t BufferSizeInSamples)
Constructs a CircularDataStream instance.
virtual void ValidateSample(const SampleT &Sample) const
Checks whether a sample is considered valid. Derived classes can define rules to check the sample for...
constexpr auto GetBytesPerSample() noexcept
Determines the size of a single sample in bytes.
virtual bool SeekRel(signed long long OffsetInSamples, std::ios_base::seekdir SeekDir, std::ios_base::openmode Which=std::ios_base::in|std::ios_base::out) override
Moves the stream's read/write pointer(s) to a position relative to SeekDir.
virtual bool SeekEqual(std::ios_base::openmode Which=std::ios_base::in|std::ios_base::out) override
Moves the read/write pointer to the respective other one.
SampleT SampleType
Alias for SampleT.
virtual void SeekEnd(std::ios_base::openmode Which=std::ios_base::in|std::ios_base::out) override
Moves the read pointer to the last sample in the stream and/or moves the write pointer after the last...
virtual void SeekBeg(std::ios_base::openmode Which=std::ios_base::in|std::ios_base::out) override
Moves the read/write pointer to the first sample in the stream.
std::vector< SampleT > ReadSamples(size_t Count)
Reads multiple samples from the stream's buffer StreamBuffer.
virtual ~CircularDataStream()=default
void WriteSample(const std::chrono::duration< Rep, Period > &Sample)
Writes a single sample to the stream's buffer StreamBuffer by implicitly constructing the sample from...
Util::circularbuf StreamBuffer
Circular stream buffer.
std::iostream Stream
Stream to operate on StreamBuffer.
virtual size_t GetNumSamplesWritten() const noexcept override
Determines the number of samples which have been written to the stream in total. Before overflowing,...
Base class for all data streams compatible with the data stream instrument's data class DataStreamIns...
virtual void ClearChild()=0
Removes all samples from the stream's buffer.
void Clear()
Removes all samples from the stream's buffer.
virtual size_t GetStreamSizeWrite() const noexcept=0
Determines the stream's write buffer size in samples.
virtual ~DataStreamBase()=default
bool CanRead() const
Determines whether the stream contains at least one sample which can be read (i.e....
virtual void WriteBasicSampleChild(const BasicSample &Sample)
Writes a single basic sample to the stream.
BasicSampleListType ReadBasicSamples(size_t Count)
Reads a list of basic sample from the stream.
std::vector< BasicSample > BasicSampleListType
Type of a list containing data stream samples of type BasicSample.
BasicSample ReadBasicSample()
Reads a single basic sample from the stream.
virtual BasicSample ReadBasicSampleChild()
Reads a single basic sample from the stream.
virtual void SeekBeg(std::ios_base::openmode Which=std::ios_base::in|std::ios_base::out)=0
Moves the read/write pointer to the first sample in the stream.
virtual bool IsBasicSampleConvertible() const noexcept
Determines whether the data stream holds samples which are compatible to BasicSample.
void WriteBasicSamples(const BasicSampleListType &Samples)
Writes a list of basic sample to the stream.
virtual bool IsBasicSampleTimeUsed() const noexcept
Determines whether the data stream holds basic samples (IsBasicSampleConvertible() returns true) whic...
virtual bool SeekEqual(std::ios_base::openmode Which=std::ios_base::in|std::ios_base::out)=0
Moves the read/write pointer to the respective other one.
void WriteBasicSample(const BasicSample &Sample)
Writes a single basic sample to the stream.
virtual void SeekEnd(std::ios_base::openmode Which=std::ios_base::in|std::ios_base::out)=0
Moves the read pointer to the last sample in the stream and/or moves the write pointer after the last...
virtual size_t GetStreamSizeRead() const noexcept=0
Determines the stream's read buffer size in samples.
virtual void SetStreamSize(size_t BufferSizeInSamples)=0
Sets the stream size in samples.
virtual size_t GetNumSamplesWritten() const noexcept=0
Determines the number of samples which have been written to the stream in total. Before overflowing,...
Configurator class for DataStreamInstrument.
Data class for DataStreamInstrument.
virtual void ResetImpl(dispatch_tag< DataStreamInstrumentData >)
UnitType
Units which can be used for data stream instruments.
auto GetCastSampleStream() const
Casts the data stream instrument's sample stream to a derived data stream type.
virtual ~DataStreamInstrumentData()=default
ValueType GetHardwareMaxValue() const noexcept
Returns HardwareMaxValue.
ValueType HardwareMaxValue
Maximal possible value to read/write from/to the hardware adapter.
void SetHardwareMaxValue(ValueType Value) noexcept
Sets HardwareMaxValue.
double ValueType
Data type to represent hardware limits on the sample values to write to the hardware adapter assigned...
UnitType ValueUnit
Unit type of the values to be read/written from/to the hardware adapter.
static const char * UnitTypeToStr(const UnitType &Unit)
Returns a descriptive string of a respective unit to be e.g. used in plots.
DataStreamBasePtrType::element_type * GetSampleStream() const noexcept
Getter for the data stream instrument's sample stream. Logical const-ness: always returns a non-const...
const DataStreamBasePtrType SampleStream
Refer to DynExp::InstrumentDataBase::Reset(). Using tag dispatch mechanism to ensure that ResetImpl()...
void SetHardwareMinValue(ValueType Value) noexcept
Sets HardwareMinValue.
UnitType GetValueUnit() const noexcept
Returns ValueUnit.
void SetValueUnit(UnitType Unit) noexcept
Sets ValueUnit.
ValueType GetHardwareMinValue() const noexcept
Returns HardwareMinValue.
ValueType HardwareMinValue
Minimal possible value to read/write from/to the hardware adapter.
Parameter class for DataStreamInstrument.
virtual const char * GetParamClassTag() const noexcept override
This function is intended to be overridden once in each derived class returning the name of the respe...
DataStreamInstrumentParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
Constructs the parameters for a DataStreamInstrument instance.
void ConfigureParamsImpl(dispatch_tag< InstrumentParamsBase >) override final
virtual void ConfigureParamsImpl(dispatch_tag< DataStreamInstrumentParams >)
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
Defines a task for deinitializing an instrument within an instrument inheritance hierarchy....
void ExitFuncImpl(dispatch_tag< ExitTaskBase >, DynExp::InstrumentInstance &Instance) override final
virtual void ExitFuncImpl(dispatch_tag< ExitTask >, DynExp::InstrumentInstance &Instance)
Deinitializes the respective instrument within the instrument inheritance hierarchy....
Defines a task for initializing an instrument within an instrument inheritance hierarchy....
virtual void InitFuncImpl(dispatch_tag< InitTask >, DynExp::InstrumentInstance &Instance)
Initializes the respective instrument within the instrument inheritance hierarchy....
void InitFuncImpl(dispatch_tag< InitTaskBase >, DynExp::InstrumentInstance &Instance) override final
Task to set the size of the related data stream instrument's stream.
const size_t BufferSizeInSamples
New stream buffer size in samples.
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
SetStreamSizeTask(size_t BufferSizeInSamples, CallbackType CallbackFunc) noexcept
Constructs a SetStreamSizeTask instance.
Defines a task for updating an instrument within an instrument inheritance hierarchy....
virtual void UpdateFuncImpl(dispatch_tag< UpdateTask >, DynExp::InstrumentInstance &Instance)
Updates the respective instrument within the instrument inheritance hierarchy. Call UpdateFuncImpl() ...
void UpdateFuncImpl(dispatch_tag< UpdateTaskBase >, DynExp::InstrumentInstance &Instance) override final
Implementation of the data stream meta instrument, which is a base class for all instruments reading/...
virtual Util::OptionalBool HasFinished() const
Determines whether the underlying hardware adapter finished data acquisition or writing data.
virtual void ClearData(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Enqueues a task to clear the underlying hardware adapter's buffer.
constexpr static auto Category() noexcept
Every derived class has to redefine this function.
virtual std::unique_ptr< DynExp::InitTaskBase > MakeInitTask() const override
Factory function for an init task (InitTaskBase). Override to define the desired initialization task ...
virtual void Start(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Enqueues a task to make the underlying hardware adapter start data acquisition or writing data.
virtual std::unique_ptr< DynExp::UpdateTaskBase > MakeUpdateTask() const override
Factory function for an update task (UpdateTaskBase). Override to define the desired update task in d...
virtual DataStreamInstrumentData::UnitType GetValueUnit() const =0
Determines which unit corresponds to the values managed by this DataStreamInstrument instance....
virtual std::string GetCategory() const override
Returns the category of this Object type.
constexpr static auto Name() noexcept
Every derived class has to redefine this function.
DataStreamInstrument(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
Constructs an instrument instance.
virtual std::string GetName() const override
Returns the name of this Object type.
virtual void ResetImpl(dispatch_tag< DataStreamInstrument >)=0
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
virtual void Stop(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Enqueues a task to make the underlying hardware adapter stop data acquisition or writing data.
virtual void ResetStreamSize(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Enqueues a task to reset the size of the instrument's sample stream to its default value.
const char * GetValueUnitStr() const noexcept
Builds and returns a descriptive string of the unit corresponding to the values managed by this DataS...
virtual std::unique_ptr< DynExp::ExitTaskBase > MakeExitTask() const override
Factory function for an exit task (ExitTaskBase). Override to define the desired deinitialization tas...
virtual Util::OptionalBool IsRunning() const
Determines whether the underlying hardware adapter is running a data acquisition or writing data.
Bundles parameters to describe a NumericSampleStream's sampling properties.
DynExp::ParamsBase::Param< ParamsConfigDialog::NumberType > SamplingRate
Sampling rate of the related DataStreamInstrument instance's sample stream in samples per second.
SamplingModeType
Type to determine how to record/play back to/from the stream.
DynExp::ParamsBase::Param< SamplingModeType > SamplingMode
Sampling mode of the related DataStreamInstrument instance's sample stream. Indicates whether reading...
ValueType Values() const
Creates and returns a ValueType instance containing the bundled parameters' values.
NumericSampleStreamParamsExtension(DynExp::ParamsBase &Owner)
Constructs a NumericSampleStreamParamsExtension instance.
Type containing the values of all the parameters belonging to NumericSampleStreamParamsExtension.
Implements a circular data stream based on Util::circularbuf using samples of an arithmetic type Samp...
NumericSampleStream(size_t BufferSizeInSamples, SampleT MinValue, SampleT MaxValue)
Constructs a NumericSampleStream instance setting the limits on the sample values to the the range [M...
NumericSampleStream(size_t BufferSizeInSamples)
Constructs a NumericSampleStream instance setting the limits on the sample values to the respective d...
auto GetMinValue() const noexcept
Getter for the minimal allowed sample value.
virtual ~NumericSampleStream()=default
auto GetMaxValue() const noexcept
Getter for the maximal allowed sample value.
virtual BasicSample ReadBasicSampleChild() override
Reads a single basic sample from the stream.
SampleT MaxValue
Maximal allowed sample value.
SampleT MinValue
Minimal allowed sample value.
virtual void ValidateSample(const SampleT &Sample) const override
Checks whether a sample is considered valid. Derived classes can define rules to check the sample for...
bool IsBasicSampleConvertible() const noexcept override final
Determines whether the data stream holds samples which are compatible to BasicSample.
void SetLimits(SampleT MinValue, SampleT MaxValue)
Sets new sample value limits.
virtual void WriteBasicSampleChild(const BasicSample &Sample) override
Writes a single basic sample to the stream.
Bundles parameters to describe a data stream's stream size.
ValueType Values() const
Creates and returns a ValueType instance containing the bundled parameters' values.
StreamSizeParamsExtension(DynExp::ParamsBase &Owner, ParamsConfigDialog::NumberType DefaultValue=DefaultStreamSize, ParamsConfigDialog::NumberType MinValue=1, ParamsConfigDialog::NumberType MaxValue=static_cast< double >(std::numeric_limits< size_t >::max()))
Constructs a StreamSizeParamsExtension instance.
DynExp::ParamsBase::Param< ParamsConfigDialog::NumberType > StreamSize
Stream size of the related DataStreamInstrument instance's sample stream in samples.
Type containing the values of all the parameters belonging to StreamSizeParamsExtension.
DynExp's core class acts as the interface between the user interface and DynExp's internal data like ...
Definition: DynExpCore.h:127
Defines a task for deinitializing an instrument within an instrument inheritance hierarchy....
Definition: Instrument.h:1144
Refer to DynExp::ParamsBase::dispatch_tag.
Definition: Instrument.h:1151
Defines a task for initializing an instrument within an instrument inheritance hierarchy....
Definition: Instrument.h:1113
Refer to DynExp::ParamsBase::dispatch_tag.
Definition: Instrument.h:1120
Base class for instruments. Instruments comprise virtual devices (meta instruments) and physial devic...
Definition: Instrument.h:451
Configurator class for InstrumentBase.
Definition: Instrument.h:435
Data structure to contain data which is synchronized in between different threads....
Definition: Instrument.h:135
Refer to ParamsBase::dispatch_tag.
Definition: Instrument.h:146
Defines data for a thread belonging to a InstrumentBase instance. Refer to RunnableInstance.
Definition: Instrument.h:772
Parameter class for InstrumentBase.
Definition: Instrument.h:401
Refer to ParamsBase::dispatch_tag.
Definition: Object.h:2018
Dummy parameter which is to be owned once by parameter classes that do not contain any other paramete...
Definition: Object.h:522
Abstract base class for object parameter classes. Each class derived from class Object must be accomp...
Definition: Object.h:326
Tag for function dispatching mechanism within this class used when derived classes are not intended t...
Definition: Object.h:349
Base class for all tasks being processed by instruments. The class must not contain public virtual fu...
Definition: Instrument.h:892
std::function< void(const TaskBase &, ExceptionContainer &)> CallbackType
Type of a callback function which is invoked when a task has finished, failed or has been aborted....
Definition: Instrument.h:939
TaskBase(CallbackType CallbackFunc=nullptr) noexcept
Constructs an instrument task.
Definition: Instrument.h:979
const CallbackType CallbackFunc
This callback function is called after the task has finished (either successfully or not) with a refe...
Definition: Instrument.h:1072
Defines the return type of task functions.
Definition: Instrument.h:824
Defines a task for updating an instrument within an instrument inheritance hierarchy....
Definition: Instrument.h:1175
Refer to DynExp::ParamsBase::dispatch_tag.
Definition: Instrument.h:1182
Defines the configuration dialog. The dialog must be displayed by calling ParamsConfigDialog::Display...
Definition: ParamsConfig.h:72
double NumberType
Number type used for numeric parameters (DynExp::ParamsBase::Param)
Definition: ParamsConfig.h:76
Data to operate on is invalid for a specific purpose. This indicates a corrupted data structure or fu...
Definition: Exception.h:163
Data type which stores an optional bool value (unknown, false, true). The type evaluates to bool whil...
Definition: Util.h:549
Thrown when an attempt was made to convert two incompatible types into each other.
Definition: Exception.h:248
Circular stream buffer to be used with the standard library's stream classes. Reading from or writing...
Definition: circularbuf.h:20
@ Continuous
Run continuously disabling the trigger.
DynExp's instrument namespace contains the implementation of DynExp instruments which extend DynExp's...
Definition: Instrument.h:1254
DataStreamPtrType< AnalogSampleStream > AnalogSampleStreamPtrType
Alias for a pointer owning a AnalogSampleStream instance.
DataStreamPtrType< DigitalSampleStream > DigitalSampleStreamPtrType
Alias for a pointer owning a DigitalSampleStream instance.
DataStreamPtrType< DataStreamBase > DataStreamBasePtrType
Type of a pointer owning a DataStreamBase instance.
std::unique_ptr< T > DataStreamPtrType
Type of a pointer owning a data stream instance derived from DataStreamBase.
std::unique_ptr< ParamsBase > ParamsBasePtrType
Alias for a pointer to the parameter system base class ParamsBase.
Definition: Object.h:1807
size_t ItemIDType
ID type of objects/items managed by DynExp.
std::vector< std::pair< TextType, ValueType > > TextValueListType
Type of a list containing key-value pairs where key is a text of type Util::TextType.
Definition: QtUtil.h:37
Accumulates include statements to provide a precompiled header.
Defines a trivially-copyable basic sample as time (t)-value (f(t)) pairs (t, f(t)).
DataType Value
Value in a unit as specified by the class derived from DataStreamInstrument.
double DataType
Data type of time and value.
constexpr BasicSample() noexcept
Constructs a BasicSample instance setting Value and Time to zero.
DataType Time
Time in seconds.
constexpr BasicSample(DataType Value) noexcept
Constructs a BasicSample instance setting Time to zero.
constexpr BasicSample(DataType Value, DataType Time) noexcept
Constructs a BasicSample instance.