SampleReceiver/libwfr/src/MultiStreamOscilloscope.h
Wiesner András a6be70fb7b - MultiStreamOscilloscope first implementation done
- SlopeTrigger -> EdgeTrigger
- working Python example included
- libwfr.h introduced for easy including all libwfr headers
- ChannelBuffer is now template
- Semaphore moved
2022-05-05 22:19:52 +02:00

82 lines
3.4 KiB
C++

//
// Created by epagris on 2022.05.04..
//
#ifndef WFR_APP_MULTISTREAMOSCILLOSCOPE_H
#define WFR_APP_MULTISTREAMOSCILLOSCOPE_H
#include <condition_variable>
#include "ICreatable.h"
#include "MultiStreamProcessor.h"
#include "ChannelBuffer.h"
#include "Trigger.h"
class MultiStreamOscilloscope : public MultiStreamProcessor, public ICreatable<MultiStreamOscilloscope> {
public:
static constexpr size_t DRAW_WINDOW_PERIOD_NS_DEF = 50E+06; // default window length (50ms)
static constexpr double VOLT_PER_BIN_DEF = 42.80E-06; // default vertical resolution
static constexpr size_t TRIGGER_POS_PERCENT_DEF = 50; // trigger position is defaulted to the screen center
public:
struct SamplePoint {
int64_t t; // time
double x; // sample data
SamplePoint() {
t = 0;
x = 0;
}
};
private: // data acquisition related things
std::vector<std::shared_ptr<ChannelBuffer<SamplePoint>>> mpChBufs; // channel buffers
size_t mCaptureLength; // length of drawing sliding window in SAMPLES
size_t mFIFOBlockCnt; // number of blocks the FIFO consists of
//size_t mFIFOBlockSize; // FIFO block size in bytes
std::shared_ptr<SamplePoint> mpAssemblyBuffer; // buffer for assembling sample points
std::shared_ptr<SamplePoint> mpTriggerBuffer; // buffer for probing against trigger conditions
std::vector<std::vector<SamplePoint>> mCaptureBuffers; // buffer for last capture
std::mutex mCapture_mtx; // mutex for capture cv
std::condition_variable mCapture_cv; // condition variable on data capture
std::vector<bool> mFIFOFull; // stores FIFO fullness indicators, needed for proper triggering and capture
private:
void clearFIFOFullnessBits(); // clear fullness bits
bool isEveryFIFOFull() const; // are the FIFOs full?
public: // graphical displaying related things
size_t mTriggerPosition_percent; // trigger position on the screen
size_t mTriggerProbeBlock_idx; // index of block on which trigger will run
size_t mPreTriggerSamples; // samples displayed before the trigger point
size_t mCapturePeriod_ns; // (drawing window) screen period
public:
std::shared_ptr<TriggerSettings> trigger; // trigger settings
double verticalScale; // vertical resolution
private:
struct {
bool armed; // indicates wheter trigger is armed or not
bool trigd; // indicates if trigger has fired
int64_t triggerSampleTag;
bool samplesReady; // samples have been transferred to the output buffer
} mTrigState;
public:
void setup(const std::vector<in_addr_t> &nodes, const AcquisitionFormat &acqFmt) override;
bool input(size_t ch, const std::shared_ptr<Timestamp> &pTime, const void *pData, size_t size) override;
public:
MultiStreamOscilloscope();
void setScreenPeriod(size_t ns); // set screen (visible waveform window) time length
size_t getScreenPeriod() const; // get --- " ----
void setTriggerPosition(size_t percent); // set trigger position
size_t getTriggerPosition() const; // get trigger position
std::vector<int64_t> getScreenTimeLimits() const; // get time limits of the screen's edges
void triggerNow(); // make the scope trigger regardless conditions
void armTrigger(); // arm trigger for next acquisition
std::vector<std::vector<MultiStreamOscilloscope::SamplePoint>> capture(); // wait for captured data TODO to be renamed
};
#endif //WFR_APP_MULTISTREAMOSCILLOSCOPE_H