DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
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
14namespace DynExpInstr
15{
16 class DataStreamInstrument;
17
21 namespace DataStreamInstrumentTasks
22 {
35
48
61
66 {
67 public:
74
75 private:
77
78 const size_t BufferSizeInSamples;
79 };
80 }
81
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
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 >
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:
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:
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
808 enum class UnitType {
809 Arbitrary,
810 LogicLevel,
811 Counts,
812 Volt,
813 Ampere,
814 Power_W,
815 Power_dBm
816 };
817
823 static const char* UnitTypeToStr(const UnitType& Unit);
824
832
833 virtual ~DataStreamInstrumentData() = default;
834
841 DataStreamBasePtrType::element_type* GetSampleStream() const noexcept { return SampleStream.get(); }
842
849 template <typename T>
851 {
852 auto CastSampleStream = dynamic_cast<T*>(GetSampleStream());
853 if (!CastSampleStream)
855
856 return CastSampleStream;
857 }
858
859 ValueType GetHardwareMinValue() const noexcept { return HardwareMinValue; }
860 ValueType GetHardwareMaxValue() const noexcept { return HardwareMaxValue; }
861 UnitType GetValueUnit() const noexcept { return ValueUnit; }
862 void SetHardwareMinValue(ValueType Value) noexcept { HardwareMinValue = Value; }
863 void SetHardwareMaxValue(ValueType Value) noexcept { HardwareMaxValue = Value; }
864 void SetValueUnit(UnitType Unit) noexcept { ValueUnit = Unit; }
865
866 private:
867 void ResetImpl(dispatch_tag<InstrumentDataBase>) override final;
869
871
881 };
882
887 {
888 public:
893 DataStreamInstrumentParams(DynExp::ItemIDType ID, const DynExp::DynExpCore& Core) : InstrumentParamsBase(ID, Core) {}
894
895 virtual ~DataStreamInstrumentParams() = 0;
896
897 virtual const char* GetParamClassTag() const noexcept override { return "DataStreamInstrumentParams"; }
898
899 private:
902
903 DummyParam Dummy = { *this };
904 };
905
918
925 {
926 public:
930
939
940 constexpr static auto Name() noexcept { return "Data Stream Instrument"; }
941 constexpr static auto Category() noexcept { return "I/O"; }
942
946 DataStreamInstrument(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType&& Params)
947 : InstrumentBase(OwnerThreadID, std::move(Params)) {}
948
949 virtual ~DataStreamInstrument() = 0;
950
951 virtual std::string GetName() const override { return Name(); }
952 virtual std::string GetCategory() const override { return Category(); }
953
958
966
973 const char* GetValueUnitStr() const noexcept { return DataStreamInstrumentData::UnitTypeToStr(GetValueUnit()); }
974
983
988 virtual void ReadData(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
989
996 virtual void WriteData(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
997
1002 virtual void ClearData(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const {}
1003
1009 virtual void Start(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const {}
1010
1016 virtual void Stop(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const {}
1017
1024 virtual void Restart(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
1025
1033 virtual void SetStreamSize(size_t BufferSizeInSamples, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
1034
1040 virtual void ResetStreamSize(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const {}
1041
1050
1060
1067 bool CanRead(const std::chrono::milliseconds Timeout = GetInstrumentDataTimeoutDefault) const;
1068
1075 void Clear(const std::chrono::milliseconds Timeout = GetInstrumentDataTimeoutDefault) const;
1076
1077 private:
1078 void ResetImpl(dispatch_tag<InstrumentBase>) override final;
1080
1081 virtual std::unique_ptr<DynExp::InitTaskBase> MakeInitTask() const override { return DynExp::MakeTask<DataStreamInstrumentTasks::InitTask>(); }
1082 virtual std::unique_ptr<DynExp::ExitTaskBase> MakeExitTask() const override { return DynExp::MakeTask<DataStreamInstrumentTasks::ExitTask>(); }
1083 virtual std::unique_ptr<DynExp::UpdateTaskBase> MakeUpdateTask() const override { return DynExp::MakeTask<DataStreamInstrumentTasks::UpdateTask>(); }
1084 };
1085}
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.
std::vector< SampleT > ReadSamples(size_t Count)
Reads multiple samples from the stream's buffer StreamBuffer.
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.
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.
DataStreamBasePtrType::element_type * GetSampleStream() const noexcept
Getter for the data stream instrument's sample stream. Logical const-ness: always returns a non-const...
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.
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.
static constexpr auto Category() noexcept
Every derived class has to redefine this function.
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::InitTaskBase > MakeInitTask() const override
Factory function for an init task (InitTaskBase). Override to define the desired initialization task ...
static constexpr auto Name() noexcept
Every derived class has to redefine this function.
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.
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.
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...
const char * GetValueUnitStr() const noexcept
Builds and returns a descriptive string of the unit corresponding to the values managed by this DataS...
virtual Util::OptionalBool IsRunning() const
Determines whether the underlying hardware adapter is running a data acquisition or writing data.
virtual std::unique_ptr< DynExp::ExitTaskBase > MakeExitTask() const override
Factory function for an exit task (ExitTaskBase). Override to define the desired deinitialization tas...
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....
Refer to DynExp::ParamsBase::dispatch_tag.
Defines a task for initializing an instrument within an instrument inheritance hierarchy....
Refer to DynExp::ParamsBase::dispatch_tag.
Base class for instruments. Instruments comprise virtual devices (meta instruments) and physial devic...
Definition Instrument.h:480
Configurator class for InstrumentBase.
Definition Instrument.h:464
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:813
Parameter class for InstrumentBase.
Definition Instrument.h:430
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
Type owning a callback function which is invoked when a task has finished, failed,...
Definition Instrument.h:978
Base class for all tasks being processed by instruments. The class must not contain public virtual fu...
Definition Instrument.h:929
CallbackType CallbackFunc
This callback function is called after the task has finished (either successfully or not) with a poin...
TaskBase(CallbackType CallbackFunc=nullptr, std::chrono::system_clock::time_point DeferUntil={}) noexcept
Constructs an instrument task.
Defines the return type of task functions.
Definition Instrument.h:865
Defines a task for updating an instrument within an instrument inheritance hierarchy....
Refer to DynExp::ParamsBase::dispatch_tag.
Defines the configuration dialog. The dialog must be displayed by calling ParamsConfigDialog::Display...
double NumberType
Number type used for numeric parameters (DynExp::ParamsBase::Param)
Data to operate on is invalid for a specific purpose. This indicates a corrupted data structure or fu...
Definition Exception.h:164
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:249
Circular stream buffer to be used with the standard library's stream classes. Reading from or writing...
Definition circularbuf.h:20
DynExp's instrument namespace contains the implementation of DynExp instruments which extend DynExp's...
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.