Compare commits

...

2 commits

Author SHA1 Message Date
Kizarm
0b9c978a6d add reload settings from device 2024-10-26 12:22:17 +02:00
Kizarm
f8e00791c1 small change 2024-10-25 19:58:06 +02:00
13 changed files with 169 additions and 6 deletions

View file

@ -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;

View file

@ -6,6 +6,10 @@ uint32_t SampleRing::Up (const char * data, const uint32_t len) {
for (unsigned n=0; n<len; n++) {
const char c = data [n];
switch (c) {
case '?':
rcvd_counter = 0;
SendSettings();
break;
case '$':
rcvd_counter = 0;
rcvd_status = RCVD_DATA;
@ -44,6 +48,27 @@ void SampleRing::CmdReceived() {
}
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) {
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<TRIGGER_CMD> (header.bits.cmd_type);

View file

@ -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

View file

@ -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;

View file

@ -72,7 +72,7 @@ int main (int /*argc*/, const char * /*argv*/[]) {
epoll_ctl (myEpoll, EPOLL_CTL_ADD, server.fd(), &wakeSeasocks);
while (true) {
constexpr auto maxEvents = 2;
constexpr auto maxEvents = 10;
epoll_event events[maxEvents];
auto res = epoll_wait (myEpoll, events, maxEvents, -1);
if (res < 0) {

View file

@ -60,8 +60,10 @@ 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 true;
return running;
}
void WsClient::stop() {
cout << "Client Stop\n";
@ -98,6 +100,10 @@ void WsClient::parse_input(const char * data, const long len) {
for (long i=0; i<len; i++) {
const char c = data [i];
switch (c) {
case '!':
state = StateReply;
packet_cnt = 0;
break;
case '$':
state = StateHeader;
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() {
if (state == StateReply) {
packet_buf[packet_cnt] = '\0';
parse_reply(packet_buf, packet_cnt);
return;
}
vector<int> ChA, ChB;
if (state != StateData) return;
int k=0;
@ -263,6 +305,7 @@ void WsClient::send_trig_mode() {
write (buffer, r);
}
int WsClient::write(const char * data, const int len) {
if (!running) return 0;
string out (data, len);
cout << out;
int r = ::write (fd, data, len);

View file

@ -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

View file

@ -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<len; i++) {
const char c = data [i];
switch (c) {
case '!':
state = StateReply;
packet_cnt = 0;
break;
case '$':
state = StateHeader;
packet_cnt = 0;
@ -73,7 +78,41 @@ void DataSource::parse_header() {
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() {
if (state == StateReply) {
packet_buf[packet_cnt] = '\0';
parse_reply(packet_buf, packet_cnt);
return;
}
QVector<int> ChA, ChB;
if (state != StateData) return;
bool ok = false;

View file

@ -11,6 +11,7 @@ enum ParserState {
StateIdle = 0,
StateHeader,
StateData,
StateReply,
};
/**
*/
@ -41,10 +42,12 @@ class DataSource : public QObject {
signals:
void Channels_received(QVector<int>, QVector<int>);
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 ();
};

View file

@ -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());

View file

@ -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<int>, QVector<int>);
void DispChannels (QVector<int>, QVector<int>);
signals:
void SettingsChanged (int n);
protected:

View file

@ -44,6 +44,7 @@ MainWindow::MainWindow (QWidget * parent)
connect (&firmware, SIGNAL (Channels_received(QVector<int>, QVector<int>)),
ui->Display, SLOT (DispChannels (QVector<int>, QVector<int>)));
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;

View file

@ -25,6 +25,7 @@ public slots:
void RestSettings (bool);
void PaketTriggered ();
void Started ();
void SetSelections (AllSettings);
private:
Ui_MainWindow * ui;
DataSource firmware;