server add channel
This commit is contained in:
parent
7a02a41fc8
commit
64aeaf99ed
5 changed files with 69 additions and 5 deletions
|
@ -85,6 +85,22 @@
|
|||
<option value="4">Time base zoom</option>
|
||||
</select></div>
|
||||
</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>
|
||||
</tr></table>
|
||||
</div>
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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<m; i++) {
|
||||
if (n == VoltageRangeTable [i]) return i;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static string channels_to_json (const vector<int> & a, const vector<int> & 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; n<bl; n++) {
|
||||
as.common [n] = from_hex (data + k);
|
||||
k += 2;
|
||||
}
|
||||
as.part.asc = find_index(as.part.asc);
|
||||
as.part.bsc = find_index(as.part.bsc);
|
||||
// ulož zpět, synchronizace serveru
|
||||
memcpy (&trigerSettings, &as.part.trg, sizeof(TrigerSettings));
|
||||
json msg;
|
||||
|
@ -162,7 +177,9 @@ void WsClient::parse_reply(const char * data, const int len) {
|
|||
msg["offset"] = as.part.trg.offset;
|
||||
msg["value"] = as.part.trg.value;
|
||||
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;
|
||||
ws->send(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<ADC_CHANNELS> (n);
|
||||
send_trig_mode();
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue