add reload settings from device
This commit is contained in:
parent
f8e00791c1
commit
0b9c978a6d
12 changed files with 166 additions and 4 deletions
|
@ -53,6 +53,10 @@ function initWebSocket() {
|
||||||
};
|
};
|
||||||
websocket.onmessage = function (evt) {
|
websocket.onmessage = function (evt) {
|
||||||
const obj = JSON.parse (evt.data);
|
const obj = JSON.parse (evt.data);
|
||||||
|
if (Object.hasOwn (obj, 'channel')) {
|
||||||
|
RefreshSettings (obj);
|
||||||
|
return;
|
||||||
|
}
|
||||||
DrawTrig ();
|
DrawTrig ();
|
||||||
DrawPolyLine (0, obj.a, '#FF0000');
|
DrawPolyLine (0, obj.a, '#FF0000');
|
||||||
DrawPolyLine (1, obj.b, '#00FF00');
|
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) {
|
function ReloadMatrix (sz) {
|
||||||
const xz = sz.x / MAX_X;
|
const xz = sz.x / MAX_X;
|
||||||
const yz = sz.y / MAX_Y;
|
const yz = sz.y / MAX_Y;
|
||||||
|
|
|
@ -6,6 +6,10 @@ uint32_t SampleRing::Up (const char * data, const uint32_t len) {
|
||||||
for (unsigned n=0; n<len; n++) {
|
for (unsigned n=0; n<len; n++) {
|
||||||
const char c = data [n];
|
const char c = data [n];
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
case '?':
|
||||||
|
rcvd_counter = 0;
|
||||||
|
SendSettings();
|
||||||
|
break;
|
||||||
case '$':
|
case '$':
|
||||||
rcvd_counter = 0;
|
rcvd_counter = 0;
|
||||||
rcvd_status = RCVD_DATA;
|
rcvd_status = RCVD_DATA;
|
||||||
|
@ -44,6 +48,27 @@ void SampleRing::CmdReceived() {
|
||||||
}
|
}
|
||||||
CommandPass (result);
|
CommandPass (result);
|
||||||
}
|
}
|
||||||
|
/* in adcscope.cpp
|
||||||
|
void SampleRing::ReloadTimer(const unsigned int n) {
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
void SampleRing::SendSettings() {
|
||||||
|
const unsigned max = 64;
|
||||||
|
char buf [max];
|
||||||
|
unsigned idx = 0;
|
||||||
|
AllSettings as (m_settings, m_time_base_order);
|
||||||
|
buf [idx++] = '!';
|
||||||
|
for (unsigned n=0u; n<sizeof(as); n++) {
|
||||||
|
const uint8_t c = as.common[n];
|
||||||
|
buf [idx++] = hexstr [c >> 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) {
|
void SampleRing::CommandPass(const unsigned int cmd) {
|
||||||
RcvdHeader header;
|
RcvdHeader header;
|
||||||
header.common = cmd & 0xFFFF;
|
header.common = cmd & 0xFFFF;
|
||||||
|
@ -53,7 +78,8 @@ void SampleRing::CommandPass(const unsigned int cmd) {
|
||||||
case DEST_CHB:
|
case DEST_CHB:
|
||||||
break;
|
break;
|
||||||
case DEST_BASE:
|
case DEST_BASE:
|
||||||
ReloadTimer (header.bits.cmd_value);
|
m_time_base_order = header.bits.cmd_value;
|
||||||
|
ReloadTimer (m_time_base_order);
|
||||||
break;
|
break;
|
||||||
case DEST_TRIG: {
|
case DEST_TRIG: {
|
||||||
const TRIGGER_CMD command = static_cast<TRIGGER_CMD> (header.bits.cmd_type);
|
const TRIGGER_CMD command = static_cast<TRIGGER_CMD> (header.bits.cmd_type);
|
||||||
|
|
|
@ -26,6 +26,7 @@ class SampleRing : public BaseLayer {
|
||||||
bool m_trigered;
|
bool m_trigered;
|
||||||
volatile bool m_finished;
|
volatile bool m_finished;
|
||||||
TIME_BASE_MODE m_mode, o_mode;
|
TIME_BASE_MODE m_mode, o_mode;
|
||||||
|
unsigned m_time_base_order;
|
||||||
|
|
||||||
[[gnu::aligned(4)]]char rcvd_buffer [RCVD_BUFLEN];
|
[[gnu::aligned(4)]]char rcvd_buffer [RCVD_BUFLEN];
|
||||||
unsigned rcvd_counter;
|
unsigned rcvd_counter;
|
||||||
|
@ -33,7 +34,7 @@ class SampleRing : public BaseLayer {
|
||||||
public:
|
public:
|
||||||
explicit SampleRing () noexcept : BaseLayer(), m_settings(), m_head(0), m_tail(0), m_lenght(0),
|
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_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) {};
|
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 write (DATA_BLOCK const * data);
|
||||||
|
@ -46,6 +47,7 @@ class SampleRing : public BaseLayer {
|
||||||
void CmdReceived ();
|
void CmdReceived ();
|
||||||
void CommandPass (const unsigned cmd);
|
void CommandPass (const unsigned cmd);
|
||||||
void ReloadTimer (const unsigned n);
|
void ReloadTimer (const unsigned n);
|
||||||
|
void SendSettings();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SAMPLERING_H
|
#endif // SAMPLERING_H
|
||||||
|
|
|
@ -27,6 +27,22 @@ struct TrigerSettings {
|
||||||
explicit TrigerSettings () noexcept : value(0x80u), offset(100u), mode(TRIGER_MODE_AUTO), channel(V1_VSENSE), rising(false) {}
|
explicit TrigerSettings () noexcept : value(0x80u), offset(100u), mode(TRIGER_MODE_AUTO), channel(V1_VSENSE), rising(false) {}
|
||||||
};
|
};
|
||||||
static_assert (sizeof(TrigerSettings) == 10, "TrigerSettings error");
|
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 {
|
union SendHeader {
|
||||||
struct s_bits {
|
struct s_bits {
|
||||||
uint16_t pack_len : 15;
|
uint16_t pack_len : 15;
|
||||||
|
|
|
@ -60,6 +60,8 @@ bool WsClient::start() {
|
||||||
|
|
||||||
printf ("Port %s opened (%d)\r\n", name, fd);
|
printf ("Port %s opened (%d)\r\n", name, fd);
|
||||||
usleep (1000);
|
usleep (1000);
|
||||||
|
const int r = ::write (fd, "?\r\n", 3);
|
||||||
|
(void) r;
|
||||||
running = true;
|
running = true;
|
||||||
return running;
|
return running;
|
||||||
}
|
}
|
||||||
|
@ -98,6 +100,10 @@ void WsClient::parse_input(const char * data, const long len) {
|
||||||
for (long i=0; i<len; i++) {
|
for (long i=0; i<len; i++) {
|
||||||
const char c = data [i];
|
const char c = data [i];
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
case '!':
|
||||||
|
state = StateReply;
|
||||||
|
packet_cnt = 0;
|
||||||
|
break;
|
||||||
case '$':
|
case '$':
|
||||||
state = StateHeader;
|
state = StateHeader;
|
||||||
packet_cnt = 0;
|
packet_cnt = 0;
|
||||||
|
@ -135,7 +141,43 @@ void WsClient::parse_header() {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
static uint8_t from_hex (const char * ptr) {
|
||||||
|
uint8_t result = 0u;
|
||||||
|
for (unsigned n=0; n<2u; n++) {
|
||||||
|
result *= 0x10;
|
||||||
|
const char c = ptr [n];
|
||||||
|
const uint8_t v = c > '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; n<bl; n++) {
|
||||||
|
as.common [n] = from_hex (data + k);
|
||||||
|
k += 2;
|
||||||
|
}
|
||||||
|
json msg;
|
||||||
|
msg["channel"] = as.part.trg.channel;
|
||||||
|
msg["mode"] = as.part.trg.mode;
|
||||||
|
msg["rising"] = as.part.trg.rising ? 1 : 0;
|
||||||
|
msg["offset"] = as.part.trg.offset;
|
||||||
|
msg["value"] = as.part.trg.value;
|
||||||
|
msg["tim"] = as.part.tim;
|
||||||
|
string s = to_string (msg);
|
||||||
|
cout << s << endl;
|
||||||
|
ws->send(s);
|
||||||
|
}
|
||||||
void WsClient::parse_packet() {
|
void WsClient::parse_packet() {
|
||||||
|
if (state == StateReply) {
|
||||||
|
packet_buf[packet_cnt] = '\0';
|
||||||
|
parse_reply(packet_buf, packet_cnt);
|
||||||
|
return;
|
||||||
|
}
|
||||||
vector<int> ChA, ChB;
|
vector<int> ChA, ChB;
|
||||||
if (state != StateData) return;
|
if (state != StateData) return;
|
||||||
int k=0;
|
int k=0;
|
||||||
|
|
|
@ -13,6 +13,7 @@ enum ParserState {
|
||||||
StateIdle = 0,
|
StateIdle = 0,
|
||||||
StateHeader,
|
StateHeader,
|
||||||
StateData,
|
StateData,
|
||||||
|
StateReply,
|
||||||
};
|
};
|
||||||
|
|
||||||
class WsClient {
|
class WsClient {
|
||||||
|
@ -57,6 +58,7 @@ class WsClient {
|
||||||
void parse_input (const char * data, const long len);
|
void parse_input (const char * data, const long len);
|
||||||
void parse_header ();
|
void parse_header ();
|
||||||
void parse_packet ();
|
void parse_packet ();
|
||||||
|
void parse_reply (const char * data, const int len);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WSCLIENT_H
|
#endif // WSCLIENT_H
|
||||||
|
|
|
@ -14,6 +14,7 @@ DataSource::DataSource(QObject * p) : QObject (p),
|
||||||
|
|
||||||
connect (&usart, SIGNAL (readyRead()), this, SLOT (read_data()));
|
connect (&usart, SIGNAL (readyRead()), this, SLOT (read_data()));
|
||||||
usart.open (QIODevice::ReadWrite);
|
usart.open (QIODevice::ReadWrite);
|
||||||
|
usart.write("?\r\n", 3);
|
||||||
}
|
}
|
||||||
DataSource::~DataSource() {
|
DataSource::~DataSource() {
|
||||||
usart.close();
|
usart.close();
|
||||||
|
@ -34,6 +35,10 @@ void DataSource::parse_input(const char * data, const long len) {
|
||||||
for (long i=0; i<len; i++) {
|
for (long i=0; i<len; i++) {
|
||||||
const char c = data [i];
|
const char c = data [i];
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
case '!':
|
||||||
|
state = StateReply;
|
||||||
|
packet_cnt = 0;
|
||||||
|
break;
|
||||||
case '$':
|
case '$':
|
||||||
state = StateHeader;
|
state = StateHeader;
|
||||||
packet_cnt = 0;
|
packet_cnt = 0;
|
||||||
|
@ -73,7 +78,41 @@ void DataSource::parse_header() {
|
||||||
emit PaketTriggered ();
|
emit PaketTriggered ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static uint8_t from_hex (const char * ptr) {
|
||||||
|
uint8_t result = 0u;
|
||||||
|
for (unsigned n=0; n<2u; n++) {
|
||||||
|
result *= 0x10;
|
||||||
|
const char c = ptr [n];
|
||||||
|
const uint8_t v = c > '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<bl; n++) {
|
||||||
|
as.common [n] = from_hex (data + k);
|
||||||
|
k += 2;
|
||||||
|
}
|
||||||
|
trigerSettings.channel = as.part.trg.channel;
|
||||||
|
trigerSettings.mode = as.part.trg.mode;
|
||||||
|
trigerSettings.rising = as.part.trg.rising;
|
||||||
|
trigerSettings.offset = as.part.trg.offset;
|
||||||
|
trigerSettings.value = as.part.trg.value;
|
||||||
|
//trigerSettings. = as.part.trg.channel;
|
||||||
|
emit SettingReceived (as);
|
||||||
|
}
|
||||||
|
|
||||||
void DataSource::parse_packet() {
|
void DataSource::parse_packet() {
|
||||||
|
if (state == StateReply) {
|
||||||
|
packet_buf[packet_cnt] = '\0';
|
||||||
|
parse_reply(packet_buf, packet_cnt);
|
||||||
|
return;
|
||||||
|
}
|
||||||
QVector<int> ChA, ChB;
|
QVector<int> ChA, ChB;
|
||||||
if (state != StateData) return;
|
if (state != StateData) return;
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
|
|
|
@ -11,6 +11,7 @@ enum ParserState {
|
||||||
StateIdle = 0,
|
StateIdle = 0,
|
||||||
StateHeader,
|
StateHeader,
|
||||||
StateData,
|
StateData,
|
||||||
|
StateReply,
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
|
@ -41,10 +42,12 @@ class DataSource : public QObject {
|
||||||
signals:
|
signals:
|
||||||
void Channels_received(QVector<int>, QVector<int>);
|
void Channels_received(QVector<int>, QVector<int>);
|
||||||
void PaketTriggered ();
|
void PaketTriggered ();
|
||||||
|
void SettingReceived (AllSettings);
|
||||||
protected:
|
protected:
|
||||||
void parse_input (const char * data, const long len);
|
void parse_input (const char * data, const long len);
|
||||||
void parse_packet ();
|
void parse_packet ();
|
||||||
void parse_header ();
|
void parse_header ();
|
||||||
|
void parse_reply (const char * data, const int len);
|
||||||
protected:
|
protected:
|
||||||
void send_trig_mode ();
|
void send_trig_mode ();
|
||||||
};
|
};
|
||||||
|
|
|
@ -182,7 +182,10 @@ void DisplayWidget::reloadMatrix(const QSize & sz) {
|
||||||
m_forward = tm;
|
m_forward = tm;
|
||||||
m_inverse = m_forward.inverted();
|
m_inverse = m_forward.inverted();
|
||||||
}
|
}
|
||||||
|
void DisplayWidget::Refresh() {
|
||||||
|
drawBackground();
|
||||||
|
update();
|
||||||
|
}
|
||||||
void DisplayWidget::TimeBaseRange(int n) {
|
void DisplayWidget::TimeBaseRange(int n) {
|
||||||
m_timeBase = n;
|
m_timeBase = n;
|
||||||
reloadMatrix (size());
|
reloadMatrix (size());
|
||||||
|
|
|
@ -39,6 +39,7 @@ class DisplayWidget : public QWidget {
|
||||||
void MarkerChanged (bool);
|
void MarkerChanged (bool);
|
||||||
void saveSettings (QSettings & setting);
|
void saveSettings (QSettings & setting);
|
||||||
void restSettings (QSettings & setting);
|
void restSettings (QSettings & setting);
|
||||||
|
void Refresh ();
|
||||||
|
|
||||||
void resizeEvent (QResizeEvent * event) override;
|
void resizeEvent (QResizeEvent * event) override;
|
||||||
void paintEvent (QPaintEvent * event) override;
|
void paintEvent (QPaintEvent * event) override;
|
||||||
|
|
|
@ -44,6 +44,7 @@ MainWindow::MainWindow (QWidget * parent)
|
||||||
connect (&firmware, SIGNAL (Channels_received(QVector<int>, QVector<int>)),
|
connect (&firmware, SIGNAL (Channels_received(QVector<int>, QVector<int>)),
|
||||||
ui->Display, SLOT (DispChannels (QVector<int>, QVector<int>)));
|
ui->Display, SLOT (DispChannels (QVector<int>, QVector<int>)));
|
||||||
connect (&firmware, SIGNAL (PaketTriggered()), this, SLOT(PaketTriggered()));
|
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->Display, SIGNAL(SettingsChanged(int)), &firmware, SLOT(SettingChanged(int)));
|
||||||
connect (ui->buttonStart,SIGNAL(pressed()), this, SLOT(Started()));
|
connect (ui->buttonStart,SIGNAL(pressed()), this, SLOT(Started()));
|
||||||
|
@ -62,6 +63,19 @@ MainWindow::MainWindow (QWidget * parent)
|
||||||
ui->comboTimeRange->setCurrentIndex(6);
|
ui->comboTimeRange->setCurrentIndex(6);
|
||||||
ui->buttonStart->setEnabled(false);
|
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 () {
|
MainWindow::~MainWindow () {
|
||||||
delete ui;
|
delete ui;
|
||||||
|
|
|
@ -25,6 +25,7 @@ public slots:
|
||||||
void RestSettings (bool);
|
void RestSettings (bool);
|
||||||
void PaketTriggered ();
|
void PaketTriggered ();
|
||||||
void Started ();
|
void Started ();
|
||||||
|
void SetSelections (AllSettings);
|
||||||
private:
|
private:
|
||||||
Ui_MainWindow * ui;
|
Ui_MainWindow * ui;
|
||||||
DataSource firmware;
|
DataSource firmware;
|
||||||
|
|
Loading…
Reference in a new issue