From 776ffd5bd263ad01fc98729a31ede0523c0c732d Mon Sep 17 00:00:00 2001 From: Kizarm Date: Tue, 22 Oct 2024 17:07:37 +0200 Subject: [PATCH] small changes --- V203/usb/scope/firmware/samplering.cpp | 19 +++++++---- V203/usb/scope/firmware/samplering.h | 7 ++-- V203/usb/scope/software/datasource.cpp | 3 ++ V203/usb/scope/software/displaywidget.cpp | 41 ++++++++++------------- V203/usb/scope/software/mainwindow.cpp | 2 ++ 5 files changed, 39 insertions(+), 33 deletions(-) diff --git a/V203/usb/scope/firmware/samplering.cpp b/V203/usb/scope/firmware/samplering.cpp index 490490a..0c291db 100644 --- a/V203/usb/scope/firmware/samplering.cpp +++ b/V203/usb/scope/firmware/samplering.cpp @@ -77,6 +77,13 @@ void SampleRing::CommandPass(const unsigned int cmd) { void SampleRing::write(DATA_BLOCK const * data) { if (m_finished) return; + /** BUG : Tady je problém - tato funkce běží pod přerušením s vyšší prioritou, + * takže m_mode se během tt. funkce změnit nemůže. Z toho vyplývá, že se + * odeslání dat musí vykonat a nelze tedy změnit m_mode dokud se data + * meodešlou do ring_buffer všechna. Tedy to funguje, pokud je TRIGER_MODE_AUTO. + * Kde zde vzít informaci, že se m_mode nějak změnilo a nějak jí použít + * zatím nevím, nejjednodušší je nechat to být a přenést do software. + * */ unsigned t_head = m_head; // dočasné proměnné kvůli zrychlení unsigned t_lenght = m_lenght; // následujícího cyklu if (m_mode == TIME_BASE_TRIGERED) { @@ -94,7 +101,7 @@ void SampleRing::write(DATA_BLOCK const * data) { } } m_old_triger = !compare; - if (t_lenght >= RING_LEN) { + if (t_lenght >= RING_LEN) { // je fuk o kolik je to delší // zastavit odesílání dat, pokud není AUTO a není splněna podmínka trigeru if ((m_settings.mode != TRIGER_MODE_AUTO) and !m_trigered) continue; t_lenght = RING_LEN; @@ -106,9 +113,9 @@ void SampleRing::write(DATA_BLOCK const * data) { } else { const DATA_BLOCK & sample = data [0]; ring_buffer [t_head].common_data = sample.common_data; - t_head += 1u; - t_head &= RING_MSK; - t_lenght += 1u; + t_head += 1u; + t_head &= RING_MSK; + t_lenght += 1u; m_finished = true; } m_head = t_head; // vrať zpátky hodnoty @@ -141,9 +148,7 @@ uint32_t SampleRing::BlockSend (const char * buf, const uint32_t len) { } void SampleRing::pass() { - if (!m_finished) { - return; - } + if (!m_finished) return; SendPrefix(); DATA_BLOCK data; while (read(data)) { diff --git a/V203/usb/scope/firmware/samplering.h b/V203/usb/scope/firmware/samplering.h index ccab247..15a24bb 100644 --- a/V203/usb/scope/firmware/samplering.h +++ b/V203/usb/scope/firmware/samplering.h @@ -25,16 +25,17 @@ class SampleRing : public BaseLayer { bool m_old_triger; bool m_trigered; volatile bool m_finished; - TIME_BASE_MODE m_mode; + TIME_BASE_MODE m_mode; //, o_mode; [[gnu::aligned(4)]]char rcvd_buffer [RCVD_BUFLEN]; unsigned rcvd_counter; RCVD_STATUS rcvd_status; public: explicit SampleRing () noexcept : BaseLayer(), m_settings(), m_head(0), m_tail(0), m_lenght(0), - m_old_triger(false), m_trigered(false), m_finished(false), m_mode (TIME_BASE_TRIGERED), + m_old_triger(false), m_trigered(false), m_finished(false), + m_mode (TIME_BASE_TRIGERED), // o_mode (TIME_BASE_TRIGERED), rcvd_counter(0u), rcvd_status (RCVD_IDLE) {}; - uint32_t Up (const char * data, const uint32_t len) override; + uint32_t Up (const char * data, const uint32_t len) override; void write (DATA_BLOCK const * data); void pass (); protected: diff --git a/V203/usb/scope/software/datasource.cpp b/V203/usb/scope/software/datasource.cpp index c06fa00..4c9c7a9 100644 --- a/V203/usb/scope/software/datasource.cpp +++ b/V203/usb/scope/software/datasource.cpp @@ -97,6 +97,9 @@ void DataSource::parse_packet() { bool sok = true; if (ChA.size() != (int) header.bits.pack_len) sok = false; if (ChB.size() != (int) header.bits.pack_len) sok = false; + const size_t al = ChA.size(), bl = ChB.size(); + if ((al != 1ul) and (al != 1024ul)) { qDebug ("A packet len = %zd", al); } + if ((bl != 1ul) and (bl != 1024ul)) { qDebug ("B packet len = %zd", bl); } if (sok) { if (trigerSettings.mode == TRIGER_MODE_SINGLE) { if (catching) { diff --git a/V203/usb/scope/software/displaywidget.cpp b/V203/usb/scope/software/displaywidget.cpp index cc5b62a..61233bb 100644 --- a/V203/usb/scope/software/displaywidget.cpp +++ b/V203/usb/scope/software/displaywidget.cpp @@ -16,13 +16,15 @@ static const double TimeBaseSteps [] = { static const double ChannelsSteps [] = { 1.0, 2.0, 5.0, }; -static constexpr double REF_Y = 3.3; // maximum napětí převodníku -static constexpr double MAX_Y = double (1 << 12); // 12. bit rozlišení - 4096 steps -static constexpr double STEP_Y = REF_Y / MAX_Y; // jeden krok ve Voltech +static constexpr double REF_Y = 3.3; // maximum napětí převodníku +static constexpr double MAX_Y = double (1 << 12); // 12. bit rozlišení - 4096 steps +static constexpr double STEP_Y = REF_Y / MAX_Y; // jeden krok ve Voltech +static constexpr unsigned T_SIZE = 1u << 10; +static constexpr unsigned T_MASK = T_SIZE - 1u; DisplayWidget::DisplayWidget(QWidget * p) : QWidget(p), ACopy(), BCopy(), m_forward(), m_inverse(), background(), m_ts(nullptr), - ChA (1024), ChB(1024), m_items (MOVE_VALUE), m_timeBase(6), m_ChBase(0), m_timeCount(0u) { - x_lenght = 1024; + ChA (T_SIZE), ChB(T_SIZE), m_items (MOVE_VALUE), m_timeBase(6), m_ChBase(0), m_timeCount(0u) { + x_lenght = T_SIZE; m_time.a = 200.0; m_time.b = 300.0; m_volt.a = 1.0 / STEP_Y; @@ -143,15 +145,12 @@ void DisplayWidget::DispChannels(QVector cha, QVector chb) { reloadData(); update(); } -static constexpr unsigned T_SIZE = 1u << 10; -static constexpr unsigned T_MASK = T_SIZE - 1u; void DisplayWidget::reloadData () { - const int Alen = ACopy.size(); - const int Blen = BCopy.size(); - QVector va (Alen), vb (Blen); - if (Alen == 1 and Blen == 1) { // kontinuální mód - if (ChA.size() != T_SIZE) { ChA = QPolygonF (T_SIZE); } - if (ChB.size() != T_SIZE) { ChB = QPolygonF (T_SIZE); } + const size_t Alen = ACopy.size(); + const size_t Blen = BCopy.size(); + const size_t Amin = Alen < T_SIZE ? Alen : T_SIZE; + const size_t Bmin = Blen < T_SIZE ? Blen : T_SIZE; + if ((Alen == 1u) and (Blen == 1u)) { // kontinuální mód const QPointF pta (m_timeCount, ACopy [0]), ptb (m_timeCount, BCopy [0]); ChA[m_timeCount] = pta; ChB[m_timeCount] = ptb; @@ -160,18 +159,14 @@ void DisplayWidget::reloadData () { m_timeCount &= T_MASK; return; } - for (int n=0u; n Blen ? Alen : Blen; if (l != x_lenght) { x_lenght = l; diff --git a/V203/usb/scope/software/mainwindow.cpp b/V203/usb/scope/software/mainwindow.cpp index 27f1a77..ff332b1 100644 --- a/V203/usb/scope/software/mainwindow.cpp +++ b/V203/usb/scope/software/mainwindow.cpp @@ -79,8 +79,10 @@ void MainWindow::TriggerValues (int n) { void MainWindow::SendTrigerMode (int n) { if (n == TRIGER_MODE_SINGLE) ui->buttonStart->setEnabled(true); else ui->buttonStart->setEnabled(false); + if (n == TRIGER_MODE_AUTO) ui->comboTimeRange->setEnabled(true); // BUG - jinak dojde při přepínání k chybě else ui->comboTimeRange->setEnabled(false); // TODO + firmware.SendTrigerMode(n); } void MainWindow::SendTrigerEdge (int n) {