7
mirror of https://github.com/EEVengers/ThunderScope.git synced 2025-04-22 17:43:44 +00:00

getMax/getMin

This commit is contained in:
Ratan Varghese 2021-03-20 23:31:50 -04:00
parent 556e787488
commit 50f1a874c6
5 changed files with 110 additions and 10 deletions

View File

@ -34,6 +34,8 @@ Prepend the name with `CMD_` to find it in the Electron and C++ code.
Cmd | DataSize | Name | Description
-----|-----------------|---------------|------------------------
0x01 | 2 (useless) | GetData1 |
0x05 | 2 | GetMin | Data has ch 1,2,3 or 4
0x06 | 2 | GetMax | Data has ch 1,2,3 or 4
0x11 | 2 | SetFile | Number mapped to filename by C++
0x1F | 2 (useless) | RampDemo |
0x21 | 2 (useless) | GetWindowSize |
@ -61,6 +63,8 @@ Note that the encoding used by the protocol might not be same as the encoding us
Cmd | DataSize | Name | Description
-----|-----------------|---------------|------------------------
0x01 | ch * windowSize | GetData1 | Data for all ch
0x05 | 16 | GetMin | Data has x and y as uint64
0x06 | 16 | GetMax | Data has x and y as uint64
0x11 | 0 | SetFile | Set testdata filename
0x1F | 4096 | RampDemo | 4 ch, simple waves
0x21 | 4 | GetWindowSize | Data has window size as uint32
@ -84,8 +88,6 @@ Cmd | DataSize | Name | Description
0x02 | 2 (useless) | GetData2 | Reserved, If we need 1 command/ch
0x03 | 2 (useless) | GetData3 | Reserved, If we need 1 command/ch
0x04 | 2 (useless) | GetData4 | Reserved, If we need 1 command/ch
0x05 | 2 | GetMin | Data has ch 1,2,3 or 4
0x06 | 2 | GetMax | Data has ch 1,2,3 or 4
### C++ -> Electron
@ -94,8 +96,6 @@ Cmd | DataSize | Name | Description
0x02 | windowSize | Reserved | If we need 1 command/ch
0x03 | windowSize | Reserved | If we need 1 command/ch
0x04 | windowSize | Reserved | If we need 1 command/ch
0x05 | 16 | GetMin | Data has x and y as uint64
0x06 | 16 | GetMax | Data has x and y as uint64
## Proposed But Not Allocated

View File

@ -105,6 +105,64 @@ void controller::controllerLoop()
case CMD_GetData4:
ERROR << "Packet command: Reserved";
break;
case CMD_GetMin: {
INFO << "Packet command: GetMin";
const int incomingPacketSize = 2;
int ch = 1;
if(currentPacket->dataSize != incomingPacketSize) {
ERROR << "Unexpected size for GetMin packet";
}
else {
ch = currentPacket->data[0];
}
int8_t val;
uint64_t pos;
getMin(ch, &val, &pos);
const int outgoingPacketSize = 2*sizeof(uint64_t);
uint64_t* outgoingU = (uint64_t*) malloc(outgoingPacketSize);
int64_t* outgoingS = (int64_t*) outgoingU;
outgoingU[0] = pos;
outgoingS[1] = val;
EVPacket* tempPacket = (EVPacket*) malloc(sizeof(EVPacket));
tempPacket->data = (int8_t*)outgoingU;
tempPacket->dataSize = outgoingPacketSize;
tempPacket->packetID = 0;
tempPacket->command = CMD_GetMin;
controllerQueue_tx.push(tempPacket);
}
break;
case CMD_GetMax: {
INFO << "Packet command: GetMax";
const int incomingPacketSize = 2;
int ch = 1;
if(currentPacket->dataSize != incomingPacketSize) {
ERROR << "Unexpected size for GetMax packet";
}
else {
ch = currentPacket->data[0];
}
int8_t val;
uint64_t pos;
getMax(ch, &val, &pos);
INFO << "val: " << convert_int(val) << ", pos: " << convert_int(pos);
const int outgoingPacketSize = 2*sizeof(uint64_t);
uint64_t* outgoingU = (uint64_t*) malloc(outgoingPacketSize);
int64_t* outgoingS = (int64_t*) outgoingU;
outgoingU[0] = pos;
outgoingS[1] = val;
EVPacket* tempPacket = (EVPacket*) malloc(sizeof(EVPacket));
tempPacket->data = (int8_t*)outgoingU;
tempPacket->dataSize = outgoingPacketSize;
tempPacket->packetID = 0;
tempPacket->command = CMD_GetMax;
controllerQueue_tx.push(tempPacket);
}
break;
case CMD_SetFile: {
INFO << "Packet command: SetFile";
const int packetSize = 2;
@ -118,7 +176,7 @@ void controller::controllerLoop()
tempPacket->data = NULL;
tempPacket->dataSize = 0;
tempPacket->packetID = 0;
tempPacket->command = CMD_SetCh;
tempPacket->command = CMD_SetFile;
controllerQueue_tx.push(tempPacket);
}
break;

View File

@ -102,6 +102,16 @@ export class Plumber {
return packet8;
}
private commandNeedsQueueing(args: PlumberArgs) {
if(args.cmd <= CMD.CMD_GetData4) {
return false;
}
else if(args.cmd == CMD.CMD_RampDemo) {
return false;
}
return true;
}
public cycle(args: PlumberArgs) {
//console.log("cycle: " + args.cmd);
if(this.ready) {
@ -112,7 +122,7 @@ export class Plumber {
this.doRead(args);
});
}
else if(args.cmd >= 0x20 || args.cmd == 0x11) {
else if(this.commandNeedsQueueing(args)) {
//console.log("queue: " + args.cmd);
this.cmdQueue.push(args);
}
@ -121,4 +131,10 @@ export class Plumber {
public makeSetMathData(lhsChan: number, rhsChan: number, op: SetMathOp) {
return [lhsChan, rhsChan, op, 0];
}
public decodeGetMinMax(a: Int8Array) {
var a64u = new BigUint64Array(a.buffer);
var a64s = new BigInt64Array(a.buffer);
return {x: Number(a64u[0]), y: Number(a64s[1])};
}
}

View File

@ -1,4 +1,4 @@
import { CMD, PlumberArgs, Plumber, SetMathOp } from './plumber';
import { CMD, PlumberArgs, Plumber } from './plumber';
class TestConf {
getEdgeArgs: PlumberArgs;
@ -6,6 +6,9 @@ class TestConf {
getWinArgs: PlumberArgs;
setWinArgs: PlumberArgs;
getMinArgs: PlumberArgs;
getMaxArgs: PlumberArgs;
constructor() {
this.getEdgeArgs = {
@ -50,16 +53,38 @@ class TestConf {
writeData: new Int8Array((new Uint32Array([20])).buffer)
}
this.getMinArgs = {
headCheck: () => true,
bodyCheck: (args, bytesRead, body) => {
console.log(Plumber.getInstance().decodeGetMinMax(body));
return true;
},
cmd: CMD.CMD_GetMin,
id: 0,
writeData: [3, 0]
}
this.getMaxArgs = {
headCheck: () => true,
bodyCheck: (args, bytesRead, body) => {
console.log(Plumber.getInstance().decodeGetMinMax(body));
return true;
},
cmd: CMD.CMD_GetMax,
id: 0,
writeData: [3, 0]
}
}
update(get: boolean) {
if(get) {
/*if(get) {
Plumber.getInstance().cycle(this.getWinArgs);
}
else {
Plumber.getInstance().cycle(this.setWinArgs);
}
}*/
Plumber.getInstance().cycle(this.getMaxArgs);
}
}

View File

@ -111,6 +111,7 @@ class TestPoints {
getData() {
var chMax = this.effectiveChCount();
console.log(this.scope_data);
return this.scope_data.slice(0, chMax);
}
}