mirror of
https://github.com/EEVengers/ThunderScope.git
synced 2025-04-08 06:25:30 +00:00
commit
ff98295b97
Software/waveview
@ -33,13 +33,17 @@ 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 |
|
||||
0x22 | 2 (useless) | GetCh |
|
||||
0x23 | 2 (useless) | GetLevel |
|
||||
0x24 | 2 (useless) | GetTriggerCh |
|
||||
0x25 | 2 (useless) | GetEdgeType |
|
||||
0x31 | 4 | SetWindowSize | Data has new window size
|
||||
0x31 | 4 | SetWindowSize | Data has new window size as uint32
|
||||
0x32 | 2 | SetCh | Data has ch 1, 2 or 4
|
||||
0x33 | 2 | SetLevel | Data has new level
|
||||
0x34 | 2 | SetTriggerCh | Data has channel 1,2,3,4
|
||||
@ -58,17 +62,21 @@ 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 and int64
|
||||
0x06 | 16 | GetMax | Data has x and y as uint64 and int64
|
||||
0x11 | 0 | SetFile | Set testdata filename
|
||||
0x1F | 4096 | RampDemo | 4 ch, simple waves
|
||||
0x21 | 4 | GetWindowSize | Data has window size
|
||||
0x21 | 4 | GetWindowSize | Data has window size as uint32
|
||||
0x22 | 2 | GetCh | Data has ch 1, 2, or 4
|
||||
0x23 | 2 | GetLevel | Data has new level
|
||||
0x24 | 2 | GetTriggerCh | Data has channel 1,2,3,4
|
||||
0x24 | 2 | GetTriggerCh | Data has channel 1,2,3 or 4
|
||||
0x25 | 2 | GetEdgeType | Data has 1 (rising) or 2 (falling)
|
||||
0x31 | 0 | SetWindowSize |
|
||||
0x32 | 0 | SetCh |
|
||||
0x33 | 0 | SetLevel |
|
||||
0x34 | 0 | SetTriggerCh |
|
||||
0x35 | 0 | SetEdgeType |
|
||||
0x35 | 0 | SetEdgeType |
|
||||
0x3F | 0 | SetMath |
|
||||
|
||||
## Allocated But Not Implemented
|
||||
@ -77,25 +85,18 @@ Cmd | DataSize | Name | Description
|
||||
|
||||
Cmd | DataSize | Name | Description
|
||||
-----|-----------------|---------------|------------------------
|
||||
0x01 | 2 (useless) | GetData |
|
||||
0x02 | 2 (useless) | Reserved | If we need 1 command/ch
|
||||
0x03 | 2 (useless) | Reserved | If we need 1 command/ch
|
||||
0x04 | 2 (useless) | Reserved | If we need 1 command/ch
|
||||
0x11 | 2 | SetFile | Number mapped to filename by C++
|
||||
|
||||
|
||||
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
|
||||
|
||||
### C++ -> Electron
|
||||
|
||||
Cmd | DataSize | Name | Description
|
||||
-----|-----------------|---------------|------------------------
|
||||
0x01 | ch * windowSize | GetData | Data for all ch
|
||||
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
|
||||
0x11 | 0 | SetFile | Set testdata filename
|
||||
|
||||
|
||||
## Proposed But Not Allocated
|
||||
|
||||
+ getMax/getMin: obsolete if scope data packets also have math
|
||||
+ (none)
|
||||
|
@ -70,6 +70,8 @@ enum CMD {
|
||||
CMD_GetData2 = 0x02,
|
||||
CMD_GetData3 = 0x03,
|
||||
CMD_GetData4 = 0x04,
|
||||
CMD_GetMin = 0x05,
|
||||
CMD_GetMax = 0x06,
|
||||
|
||||
//Demo commands
|
||||
CMD_SetFile = 0x11,
|
||||
|
@ -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;
|
||||
@ -135,19 +193,15 @@ void controller::controllerLoop()
|
||||
break;
|
||||
case CMD_GetWindowSize: {
|
||||
INFO << "Packet command: GetWindowSize";
|
||||
const int packetSize = 4;
|
||||
|
||||
EVPacket* tempPacket = (EVPacket*) malloc(sizeof(EVPacket));
|
||||
tempPacket->data = (int8_t*) malloc(packetSize);
|
||||
const int packetSize = sizeof(uint32_t);
|
||||
uint32_t* windata = (uint32_t*) malloc(packetSize);
|
||||
windata[0] = getWindowSize();
|
||||
tempPacket->data = (int8_t*) windata;
|
||||
tempPacket->dataSize = packetSize;
|
||||
tempPacket->packetID = 0;
|
||||
tempPacket->command = CMD_GetWindowSize;
|
||||
|
||||
int32_t windowSize = getWindowSize();
|
||||
tempPacket->data[0] = (windowSize >> 24) & 0xFF;
|
||||
tempPacket->data[1] = (windowSize >> 16) & 0xFF;
|
||||
tempPacket->data[2] = (windowSize >> 8) & 0xFF;
|
||||
tempPacket->data[3] = windowSize & 0xFF;
|
||||
controllerQueue_tx.push(tempPacket);
|
||||
}
|
||||
break;
|
||||
@ -210,12 +264,8 @@ void controller::controllerLoop()
|
||||
ERROR << "Unexpected size for SetWindowSize packet";
|
||||
}
|
||||
else {
|
||||
int32_t windowSize = 0;
|
||||
windowSize |= currentPacket->data[0] << 24;
|
||||
windowSize |= currentPacket->data[1] << 16;
|
||||
windowSize |= currentPacket->data[2] << 8;
|
||||
windowSize |= currentPacket->data[3];
|
||||
setWindowSize(windowSize);
|
||||
uint32_t* windowSize = (uint32_t*)currentPacket->data;
|
||||
setWindowSize(windowSize[0]);
|
||||
}
|
||||
EVPacket* tempPacket = (EVPacket*) malloc(sizeof(EVPacket));
|
||||
tempPacket->data = NULL;
|
||||
@ -333,6 +383,9 @@ void controller::controllerLoop()
|
||||
rhsChan = -1;
|
||||
}
|
||||
//Do something with these.
|
||||
setMathCh_1(lhsChan);
|
||||
setMathCh_2(rhsChan);
|
||||
setMathSign(op == 1);
|
||||
}
|
||||
EVPacket* tempPacket = (EVPacket*) malloc(sizeof(EVPacket));
|
||||
tempPacket->data = NULL;
|
||||
|
@ -21,7 +21,7 @@ class App extends React.Component {
|
||||
constructor(props: any) {
|
||||
super(props);
|
||||
this.state = initialState;
|
||||
this.generator = new TestPoints(1000, 30);
|
||||
this.generator = new TestPoints(50, 50);
|
||||
this.conf = new TestConf();
|
||||
}
|
||||
|
||||
@ -41,7 +41,8 @@ class App extends React.Component {
|
||||
let tickCount = this.state.tickCount + 1;
|
||||
this.generator.update();
|
||||
if(tickCount % 100 === 0) {
|
||||
//this.conf.update(tickCount % 1000 !== 0);
|
||||
console.log(tickCount);
|
||||
this.conf.update(tickCount % 500 !== 0);
|
||||
//this.conf.mathUpdate();
|
||||
}
|
||||
this.setState({tickCount: tickCount});
|
||||
|
@ -4,6 +4,8 @@ export enum CMD {
|
||||
CMD_GetData2 = 0x02,
|
||||
CMD_GetData3 = 0x03,
|
||||
CMD_GetData4 = 0x04,
|
||||
CMD_GetMin = 0x05,
|
||||
CMD_GetMax = 0x06,
|
||||
|
||||
//Demo commands
|
||||
CMD_SetFile = 0x11,
|
||||
@ -36,7 +38,7 @@ export interface PlumberArgs {
|
||||
bodyCheck: (args: PlumberArgs, bytesRead: number, body: Int8Array) => boolean;
|
||||
cmd: CMD;
|
||||
id: number;
|
||||
writeData: number[];
|
||||
writeData: number[] | Int8Array;
|
||||
}
|
||||
|
||||
export class Plumber {
|
||||
@ -59,7 +61,7 @@ export class Plumber {
|
||||
}
|
||||
|
||||
private nextCycle() {
|
||||
console.log("nextCycle");
|
||||
//console.log("nextCycle");
|
||||
var args = this.cmdQueue.shift();
|
||||
this.ready = true;
|
||||
if(args) {
|
||||
@ -100,18 +102,28 @@ 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);
|
||||
//console.log("cycle: " + args.cmd);
|
||||
if(this.ready) {
|
||||
var packet8 = this.argsToPacket(args);
|
||||
this.ready = false;
|
||||
console.log("write: " + args.cmd);
|
||||
//console.log("write: " + args.cmd);
|
||||
this.bridge.write(packet8,() => {
|
||||
this.doRead(args);
|
||||
});
|
||||
}
|
||||
else if(args.cmd >= 0x20 || args.cmd == 0x11) {
|
||||
console.log("queue: " + args.cmd);
|
||||
else if(this.commandNeedsQueueing(args)) {
|
||||
//console.log("queue: " + args.cmd);
|
||||
this.cmdQueue.push(args);
|
||||
}
|
||||
}
|
||||
@ -119,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])};
|
||||
}
|
||||
}
|
@ -1,31 +1,15 @@
|
||||
import { CMD, PlumberArgs, Plumber, SetMathOp } from './plumber';
|
||||
import { CMD, PlumberArgs, Plumber } from './plumber';
|
||||
|
||||
class TestConf {
|
||||
getChArgs: PlumberArgs;
|
||||
setChArgs: PlumberArgs;
|
||||
setMathArgs: PlumberArgs;
|
||||
getEdgeArgs: PlumberArgs;
|
||||
setEdgeArgs: PlumberArgs;
|
||||
getWinArgs: PlumberArgs;
|
||||
setWinArgs: PlumberArgs;
|
||||
|
||||
getMinArgs: PlumberArgs;
|
||||
getMaxArgs: PlumberArgs;
|
||||
|
||||
constructor() {
|
||||
this.getChArgs = {
|
||||
headCheck: (a, head) => true,
|
||||
bodyCheck: (a, bytesRead, body) => {
|
||||
console.log("C++ channel count: " + body[0]);
|
||||
return true;
|
||||
},
|
||||
cmd: CMD.CMD_GetCh,
|
||||
id: 0,
|
||||
writeData: [0, 0]
|
||||
}
|
||||
|
||||
this.setChArgs = {
|
||||
headCheck: () => true,
|
||||
bodyCheck: () => true,
|
||||
cmd: CMD.CMD_SetCh,
|
||||
id: 0,
|
||||
writeData: [4, 0]
|
||||
}
|
||||
|
||||
this.getEdgeArgs = {
|
||||
headCheck: (a, head) => true,
|
||||
@ -46,29 +30,61 @@ class TestConf {
|
||||
writeData: [2, 0]
|
||||
}
|
||||
|
||||
this.setMathArgs = {
|
||||
this.getWinArgs = {
|
||||
headCheck: () => true,
|
||||
bodyCheck: () => {
|
||||
console.log("I did it, I set the math");
|
||||
bodyCheck: (args, bytesRead, body) => {
|
||||
var body32 = new Uint32Array(body.buffer);
|
||||
console.log(body32);
|
||||
return true;
|
||||
},
|
||||
cmd: CMD.CMD_SetMath,
|
||||
cmd: CMD.CMD_GetWindowSize,
|
||||
id: 0,
|
||||
writeData: Plumber.getInstance().makeSetMathData(0, 2, SetMathOp.SetMath_Plus)
|
||||
writeData: [0, 0]
|
||||
}
|
||||
|
||||
this.setWinArgs = {
|
||||
headCheck: () => {
|
||||
console.log("I set win");
|
||||
return true;
|
||||
},
|
||||
bodyCheck: () => true,
|
||||
cmd: CMD.CMD_SetWindowSize,
|
||||
id: 0,
|
||||
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) {
|
||||
Plumber.getInstance().cycle(this.getChArgs);
|
||||
/*if(get) {
|
||||
Plumber.getInstance().cycle(this.getWinArgs);
|
||||
}
|
||||
else {
|
||||
Plumber.getInstance().cycle(this.setChArgs);
|
||||
}
|
||||
}
|
||||
|
||||
mathUpdate() {
|
||||
Plumber.getInstance().cycle(this.setMathArgs);
|
||||
Plumber.getInstance().cycle(this.setWinArgs);
|
||||
}*/
|
||||
Plumber.getInstance().cycle(this.getMaxArgs);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { CMD, PlumberArgs, Plumber } from './plumber';
|
||||
import { CMD, PlumberArgs, Plumber, SetMathOp } from './plumber';
|
||||
|
||||
class Range {
|
||||
dataMin: number = 0;
|
||||
@ -17,21 +17,27 @@ class Range {
|
||||
class TestPoints {
|
||||
x: Range;
|
||||
y: Range;
|
||||
ready: Boolean = true;
|
||||
scope_data: any[][] = [];
|
||||
scope_data: any[][] = []; //[ch-1] for channel, [5] for math
|
||||
scope_data_max_idx = 5;
|
||||
|
||||
chCount: number = 4;
|
||||
doMath: Boolean = true;
|
||||
|
||||
rampArgs: PlumberArgs;
|
||||
setChArgs: PlumberArgs;
|
||||
setFileArgs: PlumberArgs;
|
||||
setMathArgs: PlumberArgs;
|
||||
setChDone: Boolean = false;
|
||||
setFileDone: Boolean = false;
|
||||
setMathDone: Boolean = false;
|
||||
|
||||
constructor(xRange: number, yRange: number) {
|
||||
this.x = new Range(0, xRange);
|
||||
this.y = new Range(-yRange, yRange);
|
||||
|
||||
for(var j = 0; j < 4; j++) {
|
||||
for(var j = 0; j < this.scope_data_max_idx; j++) {
|
||||
this.scope_data[j] = [];
|
||||
for(var i = 0; i < 1024; i++) {
|
||||
for(var i = 0; i < 1; i++) {
|
||||
this.scope_data[j][i] = {x: i, y: 0};
|
||||
}
|
||||
}
|
||||
@ -39,8 +45,9 @@ class TestPoints {
|
||||
this.rampArgs = {
|
||||
headCheck: () => true,
|
||||
bodyCheck: (a, bytesRead, body) => {
|
||||
var perChannel = body.length/4;
|
||||
for(var channel = 0; channel < 4; channel++) {
|
||||
var chMax = this.effectiveChCount();
|
||||
var perChannel = Math.floor(body.length/chMax);
|
||||
for(var channel = 0; channel < chMax; channel++) {
|
||||
for(var i = 0; i < perChannel; i++) {
|
||||
this.scope_data[channel][i] = {x: i, y: body[channel*perChannel + i]};
|
||||
}
|
||||
@ -60,7 +67,7 @@ class TestPoints {
|
||||
bodyCheck: () => true,
|
||||
cmd: CMD.CMD_SetCh,
|
||||
id: 0,
|
||||
writeData: [4, 0]
|
||||
writeData: [this.chCount, 0]
|
||||
}
|
||||
|
||||
this.setFileArgs = {
|
||||
@ -73,21 +80,38 @@ class TestPoints {
|
||||
id: 0,
|
||||
writeData: [74, 0]
|
||||
}
|
||||
|
||||
this.setMathArgs = {
|
||||
headCheck: () => {
|
||||
this.setMathDone = true;
|
||||
return true;
|
||||
},
|
||||
bodyCheck: () => true,
|
||||
cmd: CMD.CMD_SetMath,
|
||||
id: 0,
|
||||
writeData: Plumber.getInstance().makeSetMathData(2, 4, SetMathOp.SetMath_Plus)
|
||||
}
|
||||
}
|
||||
|
||||
mountCalls() {
|
||||
Plumber.getInstance().cycle(this.setChArgs);
|
||||
Plumber.getInstance().cycle(this.setFileArgs);
|
||||
Plumber.getInstance().cycle(this.setMathArgs);
|
||||
}
|
||||
|
||||
update() {
|
||||
if(this.setChDone && this.setFileDone) {
|
||||
if(this.setChDone && this.setFileDone && this.setMathDone) {
|
||||
Plumber.getInstance().cycle(this.rampArgs);
|
||||
}
|
||||
}
|
||||
|
||||
effectiveChCount() {
|
||||
return (this.doMath) ? this.chCount + 1: this.chCount;
|
||||
}
|
||||
|
||||
getData() {
|
||||
return this.scope_data;
|
||||
var chMax = this.effectiveChCount();
|
||||
return this.scope_data.slice(0, chMax);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user