diff --git a/V203/usb/scope/bin/index.js b/V203/usb/scope/bin/index.js index 7457ada..795ddf8 100644 --- a/V203/usb/scope/bin/index.js +++ b/V203/usb/scope/bin/index.js @@ -53,6 +53,10 @@ function initWebSocket() { }; websocket.onmessage = function (evt) { const obj = JSON.parse (evt.data); + if (Object.hasOwn (obj, 'channel')) { + RefreshSettings (obj); + return; + } DrawTrig (); DrawPolyLine (0, obj.a, '#FF0000'); DrawPolyLine (1, obj.b, '#00FF00'); @@ -65,6 +69,15 @@ function initWebSocket() { } } /************************************************************************/ +function RefreshSettings (obj) { + console.log (obj); + document.getElementById('trigger_src' ).value = obj.channel; + document.getElementById('trigger_mode').value = obj.mode; + document.getElementById('trigger_edge').value = obj.rising; + document.getElementById('time_base' ).value = obj.tim; + gTC.x = obj.offset; gTC.y = obj.value; + DrawTrig (); +}; function ReloadMatrix (sz) { const xz = sz.x / MAX_X; const yz = sz.y / MAX_Y; diff --git a/V203/usb/scope/firmware/samplering.cpp b/V203/usb/scope/firmware/samplering.cpp index 4c03808..28085de 100644 --- a/V203/usb/scope/firmware/samplering.cpp +++ b/V203/usb/scope/firmware/samplering.cpp @@ -6,6 +6,10 @@ uint32_t SampleRing::Up (const char * data, const uint32_t len) { for (unsigned n=0; n> 4]; + buf [idx++] = hexstr [c & 0xF]; + } + buf [idx++] = '\r'; + buf [idx++] = '\n'; + buf [idx] = '\0'; + BlockSend (buf, idx); +} + void SampleRing::CommandPass(const unsigned int cmd) { RcvdHeader header; header.common = cmd & 0xFFFF; @@ -53,7 +78,8 @@ void SampleRing::CommandPass(const unsigned int cmd) { case DEST_CHB: break; case DEST_BASE: - ReloadTimer (header.bits.cmd_value); + m_time_base_order = header.bits.cmd_value; + ReloadTimer (m_time_base_order); break; case DEST_TRIG: { const TRIGGER_CMD command = static_cast (header.bits.cmd_type); diff --git a/V203/usb/scope/firmware/samplering.h b/V203/usb/scope/firmware/samplering.h index a78c2c5..da2e77c 100644 --- a/V203/usb/scope/firmware/samplering.h +++ b/V203/usb/scope/firmware/samplering.h @@ -26,6 +26,7 @@ class SampleRing : public BaseLayer { bool m_trigered; volatile bool m_finished; TIME_BASE_MODE m_mode, o_mode; + unsigned m_time_base_order; [[gnu::aligned(4)]]char rcvd_buffer [RCVD_BUFLEN]; unsigned rcvd_counter; @@ -33,7 +34,7 @@ class SampleRing : public BaseLayer { 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), o_mode (TIME_BASE_TRIGERED), + m_mode (TIME_BASE_TRIGERED), o_mode (TIME_BASE_TRIGERED), m_time_base_order(6u), rcvd_counter(0u), rcvd_status (RCVD_IDLE) {}; uint32_t Up (const char * data, const uint32_t len) override; void write (DATA_BLOCK const * data); @@ -46,6 +47,7 @@ class SampleRing : public BaseLayer { void CmdReceived (); void CommandPass (const unsigned cmd); void ReloadTimer (const unsigned n); + void SendSettings(); }; #endif // SAMPLERING_H diff --git a/V203/usb/scope/firmware/structures.h b/V203/usb/scope/firmware/structures.h index 4f2ad8b..221b600 100644 --- a/V203/usb/scope/firmware/structures.h +++ b/V203/usb/scope/firmware/structures.h @@ -27,6 +27,22 @@ struct TrigerSettings { explicit TrigerSettings () noexcept : value(0x80u), offset(100u), mode(TRIGER_MODE_AUTO), channel(V1_VSENSE), rising(false) {} }; static_assert (sizeof(TrigerSettings) == 10, "TrigerSettings error"); +union AllSettings { + struct _x { + TrigerSettings trg; + uint16_t tim; + } part; + uint8_t common [sizeof (_x)]; + explicit AllSettings (const TrigerSettings & ts, const unsigned n) noexcept { + part.trg.value = ts.value; + part.trg.offset = ts.offset; + part.trg.mode = ts.mode; + part.trg.channel = ts.channel; + part.trg.rising = ts.rising; + part.tim = n; + } +}; +static_assert (sizeof(AllSettings) == 12, "TrigerSettings error"); union SendHeader { struct s_bits { uint16_t pack_len : 15; diff --git a/V203/usb/scope/server/wsclient.cpp b/V203/usb/scope/server/wsclient.cpp index 70b883e..f4f571c 100644 --- a/V203/usb/scope/server/wsclient.cpp +++ b/V203/usb/scope/server/wsclient.cpp @@ -60,6 +60,8 @@ bool WsClient::start() { printf ("Port %s opened (%d)\r\n", name, fd); usleep (1000); + const int r = ::write (fd, "?\r\n", 3); + (void) r; running = true; return running; } @@ -98,6 +100,10 @@ void WsClient::parse_input(const char * data, const long len) { for (long i=0; i '9' ? c - 'A' + 10 : c - '0'; + result += v; + } + return result; +} +void WsClient::parse_reply(const char * data, const int len) { + printf("(%d):%s\n", len, data); + TrigerSettings ts; + AllSettings as (ts, 0); + const int bl = len >> 1; + int k = 0; + for (int n=0; nsend(s); +} void WsClient::parse_packet() { + if (state == StateReply) { + packet_buf[packet_cnt] = '\0'; + parse_reply(packet_buf, packet_cnt); + return; + } vector ChA, ChB; if (state != StateData) return; int k=0; diff --git a/V203/usb/scope/server/wsclient.h b/V203/usb/scope/server/wsclient.h index 9277902..42884a5 100644 --- a/V203/usb/scope/server/wsclient.h +++ b/V203/usb/scope/server/wsclient.h @@ -13,6 +13,7 @@ enum ParserState { StateIdle = 0, StateHeader, StateData, + StateReply, }; class WsClient { @@ -57,6 +58,7 @@ class WsClient { void parse_input (const char * data, const long len); void parse_header (); void parse_packet (); + void parse_reply (const char * data, const int len); }; #endif // WSCLIENT_H diff --git a/V203/usb/scope/software/datasource.cpp b/V203/usb/scope/software/datasource.cpp index 152c018..13d284e 100644 --- a/V203/usb/scope/software/datasource.cpp +++ b/V203/usb/scope/software/datasource.cpp @@ -14,6 +14,7 @@ DataSource::DataSource(QObject * p) : QObject (p), connect (&usart, SIGNAL (readyRead()), this, SLOT (read_data())); usart.open (QIODevice::ReadWrite); + usart.write("?\r\n", 3); } DataSource::~DataSource() { usart.close(); @@ -34,6 +35,10 @@ void DataSource::parse_input(const char * data, const long len) { for (long i=0; i '9' ? c - 'A' + 10 : c - '0'; + result += v; + } + return result; +} +void DataSource::parse_reply(const char * data, const int len) { + printf("(%d):%s\n", len, data); + TrigerSettings ts; + AllSettings as (ts, 0); + const int bl = len >> 1; + int k = 0; + for (int n=0; n ChA, ChB; if (state != StateData) return; bool ok = false; diff --git a/V203/usb/scope/software/datasource.h b/V203/usb/scope/software/datasource.h index eeb94c5..dc1383b 100644 --- a/V203/usb/scope/software/datasource.h +++ b/V203/usb/scope/software/datasource.h @@ -11,6 +11,7 @@ enum ParserState { StateIdle = 0, StateHeader, StateData, + StateReply, }; /** */ @@ -41,10 +42,12 @@ class DataSource : public QObject { signals: void Channels_received(QVector, QVector); void PaketTriggered (); + void SettingReceived (AllSettings); protected: void parse_input (const char * data, const long len); void parse_packet (); void parse_header (); + void parse_reply (const char * data, const int len); protected: void send_trig_mode (); }; diff --git a/V203/usb/scope/software/displaywidget.cpp b/V203/usb/scope/software/displaywidget.cpp index 61233bb..b4d3806 100644 --- a/V203/usb/scope/software/displaywidget.cpp +++ b/V203/usb/scope/software/displaywidget.cpp @@ -182,7 +182,10 @@ void DisplayWidget::reloadMatrix(const QSize & sz) { m_forward = tm; m_inverse = m_forward.inverted(); } - +void DisplayWidget::Refresh() { + drawBackground(); + update(); +} void DisplayWidget::TimeBaseRange(int n) { m_timeBase = n; reloadMatrix (size()); diff --git a/V203/usb/scope/software/displaywidget.h b/V203/usb/scope/software/displaywidget.h index 7d93985..82f03ad 100644 --- a/V203/usb/scope/software/displaywidget.h +++ b/V203/usb/scope/software/displaywidget.h @@ -39,6 +39,7 @@ class DisplayWidget : public QWidget { void MarkerChanged (bool); void saveSettings (QSettings & setting); void restSettings (QSettings & setting); + void Refresh (); void resizeEvent (QResizeEvent * event) override; void paintEvent (QPaintEvent * event) override; @@ -46,7 +47,7 @@ class DisplayWidget : public QWidget { void mousePressEvent(QMouseEvent * event) override; public slots: - void DispChannels (QVector, QVector); + void DispChannels (QVector, QVector); signals: void SettingsChanged (int n); protected: diff --git a/V203/usb/scope/software/mainwindow.cpp b/V203/usb/scope/software/mainwindow.cpp index 65fe66a..c811bbf 100644 --- a/V203/usb/scope/software/mainwindow.cpp +++ b/V203/usb/scope/software/mainwindow.cpp @@ -44,6 +44,7 @@ MainWindow::MainWindow (QWidget * parent) connect (&firmware, SIGNAL (Channels_received(QVector, QVector)), ui->Display, SLOT (DispChannels (QVector, QVector))); connect (&firmware, SIGNAL (PaketTriggered()), this, SLOT(PaketTriggered())); + connect (&firmware, SIGNAL (SettingReceived(AllSettings)), this, SLOT(SetSelections(AllSettings))); connect (ui->Display, SIGNAL(SettingsChanged(int)), &firmware, SLOT(SettingChanged(int))); connect (ui->buttonStart,SIGNAL(pressed()), this, SLOT(Started())); @@ -62,6 +63,19 @@ MainWindow::MainWindow (QWidget * parent) ui->comboTimeRange->setCurrentIndex(6); ui->buttonStart->setEnabled(false); } +void MainWindow::SetSelections(AllSettings as) { + printf("channel : %d\n", as.part.trg.channel); + printf("mode : %d\n", as.part.trg.mode); + printf("rising : %d\n", as.part.trg.rising); + printf("offset : %d\n", as.part.trg.offset); + printf("value : %d\n", as.part.trg.value); + printf("tim bas : %d\n", as.part.tim); + ui->comboChannel ->setCurrentIndex(as.part.trg.channel); + ui->comboMode ->setCurrentIndex(as.part.trg.mode); + ui->comboRissing ->setCurrentIndex(as.part.trg.rising ? 1 : 0); + ui->comboTimeRange->setCurrentIndex(as.part.tim); + ui->Display->Refresh(); +} MainWindow::~MainWindow () { delete ui; diff --git a/V203/usb/scope/software/mainwindow.h b/V203/usb/scope/software/mainwindow.h index ebaaade..ac9d0de 100644 --- a/V203/usb/scope/software/mainwindow.h +++ b/V203/usb/scope/software/mainwindow.h @@ -25,6 +25,7 @@ public slots: void RestSettings (bool); void PaketTriggered (); void Started (); + void SetSelections (AllSettings); private: Ui_MainWindow * ui; DataSource firmware;