server add channel

This commit is contained in:
Kizarm 2024-11-08 21:47:36 +01:00
parent 7a02a41fc8
commit 64aeaf99ed
5 changed files with 69 additions and 5 deletions

View file

@ -85,6 +85,22 @@
<option value="4">Time base zoom</option> <option value="4">Time base zoom</option>
</select></div> </select></div>
</fieldset></td> </fieldset></td>
<td><fieldset>
<legend>Channel A</legend>
<div><select id="setcha" name="setcha">
<option value="0">100mV</option><option value="1">200mV</option><option value="2">500mV</option>
<option value="3">1V</option><option value="4">2V</option><option value="5">5V</option>
<option value="6">10V</option><option value="7">20V</option><option value="8">50V</option>
</select></div>
</fieldset></td>
<td><fieldset>
<legend>Channel B</legend>
<div><select id="setchb" name="setchb">
<option value="0">100mV</option><option value="1">200mV</option><option value="2">500mV</option>
<option value="3">1V</option><option value="4">2V</option><option value="5">5V</option>
<option value="6">10V</option><option value="7">20V</option><option value="8">50V</option>
</select></div>
</fieldset></td>
<td><input type="button" class="start" id="Start" value="Start" onclick="Start();" disabled></td> <td><input type="button" class="start" id="Start" value="Start" onclick="Start();" disabled></td>
</tr></table> </tr></table>
</div> </div>

View file

@ -7,6 +7,8 @@ const MarkerVolt = document.getElementById ('volt');
const TimeBase = document.getElementById ('time_base'); const TimeBase = document.getElementById ('time_base');
const MoveElem = document.getElementById ('move'); const MoveElem = document.getElementById ('move');
const VoltChA = document.getElementById ('setcha');
const VoltChB = document.getElementById ('setchb');
const StartBut = document.getElementById ('Start'); const StartBut = document.getElementById ('Start');
const ConnectBut = document.getElementById ('Connect'); const ConnectBut = document.getElementById ('Connect');
const Connected = document.getElementById ('Connected'); const Connected = document.getElementById ('Connected');
@ -95,6 +97,8 @@ function RefreshSettings (obj) {
document.getElementById('trigger_mode').value = obj.mode; document.getElementById('trigger_mode').value = obj.mode;
document.getElementById('trigger_edge').value = obj.rising; document.getElementById('trigger_edge').value = obj.rising;
document.getElementById('time_base' ).value = obj.tim; 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; gTC.x = obj.offset; gTC.y = obj.value;
PrepareBG(); PrepareBG();
DrawAll (); DrawAll ();
@ -289,6 +293,14 @@ MoveElem.onchange = (event) => {
gItemToMove = e.value; gItemToMove = e.value;
console.log(e); 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) => { MarkerTime.onclick = (event) => {
console.log ('time_mark'); console.log ('time_mark');
gMark.type = 'time'; gMark.type = 'time';

View file

@ -2,9 +2,8 @@ PR = ../bin/wserver
CC = g++ CC = g++
AS = as AS = as
CFLAGS = -Wall -Os CFLAGS = -Wall -Os
CFLAGS+= -I$(HOME)/local/include
MFLAGS = -o $(PR) MFLAGS = -o $(PR)
LFLAGS = -L$(HOME)/local/lib -lseasocks -lz -lpthread LFLAGS = -lseasocks -lz -lpthread
all: $(PR) all: $(PR)

View file

@ -13,11 +13,23 @@ using json = nlohmann::json;
using namespace std; using namespace std;
using namespace seasocks; 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<m; i++) {
if (n == VoltageRangeTable [i]) return i;
}
return 0;
}
static string channels_to_json (const vector<int> & a, const vector<int> & b) { static string channels_to_json (const vector<int> & a, const vector<int> & b) {
json msg; json msg;
msg["a"] = a; msg["a"] = a;
msg["b"] = b; msg["b"] = b;
return to_string(msg); return msg.dump();
} }
bool WsClient::start() { bool WsClient::start() {
cout << "Client Start\n"; 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) { void WsClient::parse_reply(const char * data, const int len) {
printf("(%d):%s\n", len, data); printf("(%d):%s\n", len, data);
TrigerSettings ts; TrigerSettings ts;
AllSettings as (ts, 0); ChannelVoltage cv;
AllSettings as (ts, 0, cv);
const int bl = len >> 1; const int bl = len >> 1;
int k = 0; int k = 0;
for (int n=0; n<bl; n++) { for (int n=0; n<bl; n++) {
as.common [n] = from_hex (data + k); as.common [n] = from_hex (data + k);
k += 2; k += 2;
} }
as.part.asc = find_index(as.part.asc);
as.part.bsc = find_index(as.part.bsc);
// ulož zpět, synchronizace serveru // ulož zpět, synchronizace serveru
memcpy (&trigerSettings, &as.part.trg, sizeof(TrigerSettings)); memcpy (&trigerSettings, &as.part.trg, sizeof(TrigerSettings));
json msg; json msg;
@ -162,7 +177,9 @@ void WsClient::parse_reply(const char * data, const int len) {
msg["offset"] = as.part.trg.offset; msg["offset"] = as.part.trg.offset;
msg["value"] = as.part.trg.value; msg["value"] = as.part.trg.value;
msg["tim"] = as.part.tim; msg["tim"] = as.part.tim;
string s = to_string (msg); msg["cha"] = as.part.asc;
msg["chb"] = as.part.bsc;
string s = msg.dump ();
cout << s << endl; cout << s << endl;
ws->send(s); ws->send(s);
} }
@ -235,12 +252,30 @@ void WsClient::send(const char * data) {
SettingChanged(1); SettingChanged(1);
} else if (type == "tim_bas") { } else if (type == "tim_bas") {
SendBaseRange(value); SendBaseRange(value);
} else if (type == "cha_set") {
SendVoltage(0, VoltageRangeTable[value]);
} else if (type == "chb_set") {
SendVoltage(1, VoltageRangeTable[value]);
} else if (type == "start") { } else if (type == "start") {
Start (); Start ();
} }
} }
// cout << "type=" << type << ", value=" << value << endl; // 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) { void WsClient::SendTrigerChan(int n) {
trigerSettings.channel = static_cast<ADC_CHANNELS> (n); trigerSettings.channel = static_cast<ADC_CHANNELS> (n);
send_trig_mode(); send_trig_mode();

View file

@ -51,6 +51,8 @@ class WsClient {
void SendTrigerChan (int n); void SendTrigerChan (int n);
void SendBaseRange (int n); void SendBaseRange (int n);
void SettingChanged (int n); void SettingChanged (int n);
void SendVoltage (int ch, int n);
void Start (); void Start ();
void send_trig_mode (); void send_trig_mode ();
int write (const char * data, const int len); int write (const char * data, const int len);