From 7d980f2c59aa60e359a1b206e28e711a4ea656c2 Mon Sep 17 00:00:00 2001 From: nanovna <54525305+nanovna@users.noreply.github.com> Date: Fri, 3 Apr 2020 11:30:03 +0000 Subject: [PATCH] dynamically adjust chunkPoints based on sweep speed --- libxavna/xavna_cpp.C | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/libxavna/xavna_cpp.C b/libxavna/xavna_cpp.C index 7037057..35c4a95 100644 --- a/libxavna/xavna_cpp.C +++ b/libxavna/xavna_cpp.C @@ -4,8 +4,10 @@ #include "include/workarounds.H" #include #include +#include using namespace std; +using namespace std::chrono; namespace xaxaxa { static void* _mainThread_(void* param); @@ -210,7 +212,8 @@ namespace xaxaxa { uint32_t last_measurementCnt = _measurementCnt; int lastFreqIndex = -1; int measurementEndPoint = -1; - int chunkPoints = 16; + double currChunkPoints = 16.; + int chunkPoints = (int)currChunkPoints; int nValues = this->nValues; int collectDataState = 0; int cnt = 0; @@ -226,10 +229,13 @@ namespace xaxaxa { autoSweepDataPoint values[chunkValues]; // read a chunk of values + steady_clock::time_point t1 = steady_clock::now(); if(xavna_read_autosweep(_dev, values, chunkValues)<0) { backgroundErrorCallback(runtime_error("xavna_read_autosweep failed: " + string(strerror(errno)))); return NULL; } + steady_clock::time_point t2 = steady_clock::now(); + double readChunkTimeSeconds = duration_cast>(t2 - t1).count(); // process chunk for(int i=0; i 128) newChunkPoints = 128; + if(newChunkPoints < 8) newChunkPoints = 8; + currChunkPoints = currChunkPoints * 0.7 + newChunkPoints * 0.3; + chunkPoints = (int)currChunkPoints; + fprintf(stderr, "chunkPoints %d\n", chunkPoints); } return NULL; }