From 64aeaf99edf9b24255fa42a07493d5e2120bb5e6 Mon Sep 17 00:00:00 2001 From: Kizarm Date: Fri, 8 Nov 2024 21:47:36 +0100 Subject: [PATCH] server add channel --- V203/usb/scope/bin/index.html | 16 ++++++++++++ V203/usb/scope/bin/index.js | 12 +++++++++ V203/usb/scope/server/Makefile | 3 +-- V203/usb/scope/server/wsclient.cpp | 41 +++++++++++++++++++++++++++--- V203/usb/scope/server/wsclient.h | 2 ++ 5 files changed, 69 insertions(+), 5 deletions(-) diff --git a/V203/usb/scope/bin/index.html b/V203/usb/scope/bin/index.html index 849fd95..706ab38 100644 --- a/V203/usb/scope/bin/index.html +++ b/V203/usb/scope/bin/index.html @@ -85,6 +85,22 @@ +
+ Channel A +
+
+
+ Channel B +
+
diff --git a/V203/usb/scope/bin/index.js b/V203/usb/scope/bin/index.js index 4c58e05..81b5c94 100644 --- a/V203/usb/scope/bin/index.js +++ b/V203/usb/scope/bin/index.js @@ -7,6 +7,8 @@ const MarkerVolt = document.getElementById ('volt'); const TimeBase = document.getElementById ('time_base'); const MoveElem = document.getElementById ('move'); +const VoltChA = document.getElementById ('setcha'); +const VoltChB = document.getElementById ('setchb'); const StartBut = document.getElementById ('Start'); const ConnectBut = document.getElementById ('Connect'); const Connected = document.getElementById ('Connected'); @@ -95,6 +97,8 @@ function RefreshSettings (obj) { document.getElementById('trigger_mode').value = obj.mode; document.getElementById('trigger_edge').value = obj.rising; document.getElementById('time_base' ).value = obj.tim; + document.getElementById('setcha' ).value = obj.cha; + document.getElementById('setchb' ).value = obj.chb; gTC.x = obj.offset; gTC.y = obj.value; PrepareBG(); DrawAll (); @@ -289,6 +293,14 @@ MoveElem.onchange = (event) => { gItemToMove = e.value; console.log(e); }; +VoltChA.onchange = (event) => { + const e = { type : "cha_set", value : parseInt(event.target.value, 10) }; + SendEvent (e); +}; +VoltChB.onchange = (event) => { + const e = { type : "chb_set", value : parseInt(event.target.value, 10) }; + SendEvent (e); +}; MarkerTime.onclick = (event) => { console.log ('time_mark'); gMark.type = 'time'; diff --git a/V203/usb/scope/server/Makefile b/V203/usb/scope/server/Makefile index 6a60285..b9a0ccd 100644 --- a/V203/usb/scope/server/Makefile +++ b/V203/usb/scope/server/Makefile @@ -2,9 +2,8 @@ PR = ../bin/wserver CC = g++ AS = as CFLAGS = -Wall -Os -CFLAGS+= -I$(HOME)/local/include MFLAGS = -o $(PR) -LFLAGS = -L$(HOME)/local/lib -lseasocks -lz -lpthread +LFLAGS = -lseasocks -lz -lpthread all: $(PR) diff --git a/V203/usb/scope/server/wsclient.cpp b/V203/usb/scope/server/wsclient.cpp index 16844bc..725ccc1 100644 --- a/V203/usb/scope/server/wsclient.cpp +++ b/V203/usb/scope/server/wsclient.cpp @@ -13,11 +13,23 @@ using json = nlohmann::json; using namespace std; using namespace seasocks; +static const uint8_t VoltageRangeTable [] = { + S100mV, S200mV, S500mV, + S1V, S2V, S5V, + S10V, S20V, S50V, +}; +static uint8_t find_index (uint8_t n) { + unsigned m = sizeof (VoltageRangeTable); + for (unsigned i=0u; i & a, const vector & b) { json msg; msg["a"] = a; msg["b"] = b; - return to_string(msg); + return msg.dump(); } bool WsClient::start() { cout << "Client Start\n"; @@ -146,13 +158,16 @@ static uint8_t from_hex (const char * ptr) { void WsClient::parse_reply(const char * data, const int len) { printf("(%d):%s\n", len, data); TrigerSettings ts; - AllSettings as (ts, 0); + ChannelVoltage cv; + AllSettings as (ts, 0, cv); const int bl = len >> 1; int k = 0; for (int n=0; nsend(s); } @@ -235,12 +252,30 @@ void WsClient::send(const char * data) { SettingChanged(1); } else if (type == "tim_bas") { SendBaseRange(value); + } else if (type == "cha_set") { + SendVoltage(0, VoltageRangeTable[value]); + } else if (type == "chb_set") { + SendVoltage(1, VoltageRangeTable[value]); } else if (type == "start") { Start (); } } // cout << "type=" << type << ", value=" << value << endl; } +void WsClient::SendVoltage(int ch, int n) { + const int k = (unsigned) n >= sizeof (VoltageRangeTable) ? (sizeof (VoltageRangeTable) - 1u) : n; + uint8_t v = VoltageRangeTable [k]; + RcvdHeader hdr; + hdr.common = 0u; + hdr.bits.destinat = ch == 0 ? DEST_CHA : DEST_CHB; + hdr.bits.cmd_value = v; + const unsigned len = 64; + char buffer [len]; + int r = snprintf(buffer, len, "$%04X\r\n", (int) hdr.common); + buffer [r] = '\0'; + write (buffer, r); +} + void WsClient::SendTrigerChan(int n) { trigerSettings.channel = static_cast (n); send_trig_mode(); diff --git a/V203/usb/scope/server/wsclient.h b/V203/usb/scope/server/wsclient.h index 42884a5..fc1f7c4 100644 --- a/V203/usb/scope/server/wsclient.h +++ b/V203/usb/scope/server/wsclient.h @@ -51,6 +51,8 @@ class WsClient { void SendTrigerChan (int n); void SendBaseRange (int n); void SettingChanged (int n); + void SendVoltage (int ch, int n); + void Start (); void send_trig_mode (); int write (const char * data, const int len);