7
mirror of https://github.com/EEVengers/ThunderScope.git synced 2025-04-11 23:19:16 +00:00

Merge pull request from EEVengers/electron-pipe

Electron pipe
This commit is contained in:
ratanvarghese 2021-03-25 19:19:59 -04:00 committed by GitHub
commit 13ec88bef3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 125 additions and 44 deletions

View File

@ -44,7 +44,7 @@ Cmd | DataSize | Name | Description
0x24 | 2 (useless) | GetTriggerCh |
0x25 | 2 (useless) | GetEdgeType |
0x31 | 4 | SetWindowSize | Data has new window size as uint32
0x32 | 2 | SetCh | Data has ch 1, 2 or 4
0x32 | 4 | SetCh | Data: `[ch1, ch2, ch3, ch4]`, each 1 or 0
0x33 | 2 | SetLevel | Data has new level
0x34 | 2 | SetTriggerCh | Data has channel 1,2,3,4
0x35 | 2 | SetEdgeType | Data has 1 (rising) or 2 (falling)
@ -89,7 +89,7 @@ Cmd | DataSize | Name | Description
0x03 | 2 (useless) | GetData3 | Reserved, If we need 1 command/ch
0x04 | 2 (useless) | GetData4 | Reserved, If we need 1 command/ch
0x36 | 2? | SetBandwidth |
0x37 | 2? | SetVerticalScaling |
0x37 | 4 | SetVerticalScaling | Data has ch, mV/div as int16
0x38 | 2 | SetVerticalOffset | Data\[0\] has offset
0x39 | 2? | SetHorizontalOffset |
0x3A | 2 | SetCoupling | Data\[0\] has 0\1 for AC\DC

View File

@ -30,7 +30,7 @@ controller::controller(boost::lockfree::queue<buffer*, boost::lockfree::fixed_si
// set default values
setCh(1);
setTriggerCh(1);
setLevel(50);
setLevel(64);
setPerSize(1);
setWindowSize(1000);
@ -283,18 +283,33 @@ void controller::controllerLoop()
break;
case CMD_SetCh: {
INFO << "Packet command: SetCh";
const int packetSize = 2;
const int packetSize = 4;
if(currentPacket->dataSize != packetSize) {
ERROR << "Unexpected size for SetCh packet";
}
else {
int8_t ch = currentPacket->data[0];
if(ch == 1 || ch == 2 || ch == 4) {
setCh(currentPacket->data[0]);
int chCount = 0;
for(int i = 0; i < 4; i++) {
if(currentPacket->data[i]) {
chCount++;
}
}
if(chCount == 1 || chCount == 2 || chCount == 4) {
setCh(chCount);
}
else {
ERROR << "Bad Ch value";
ERROR << "Bad chCount for SetCh";
}
#ifndef NOHARDWARE
for(int i = 0; i < 4; i++) {
if(currentPacket->data[i]) {
hardWareCommand((int)enable_channel, i, 0, 0);
}
else {
hardWareCommand((int)disable_channel, i, 0, 0);
}
}
#endif
}
EVPacket* tempPacket = (EVPacket*) malloc(sizeof(EVPacket));
tempPacket->data = NULL;
@ -372,6 +387,34 @@ void controller::controllerLoop()
controllerQueue_tx.push(tempPacket);
}
break;
case CMD_SetVerticalScaling: {
INFO << "Packet command: SetVerticalScaling";
const int packetSize = 4;
if(currentPacket->dataSize != packetSize) {
ERROR << "Unexpected size for SetVerticalScaling packet";
}
else {
int16_t* data16 = (int16_t*) currentPacket->data;
int ch = data16[0];
int millivoltPerDiv = data16[1];
if(ch < 1 || ch > 4) {
ERROR << "Bad channel for SetVerticalScaling";
}
if(millivoltPerDiv < 0 || millivoltPerDiv > 10000) {
ERROR << "Bad millivoltPerDiv for SetVerticalScaling";
}
#ifndef NOHARDWARE
hardWareCommand((int)voltage_divison_set, ch-1, millivoltPerDiv, 0);
#endif
}
EVPacket* tempPacket = (EVPacket*) malloc(sizeof(EVPacket));
tempPacket->data = NULL;
tempPacket->dataSize = 0;
tempPacket->packetID = 0;
tempPacket->command = CMD_SetEdgeType;
controllerQueue_tx.push(tempPacket);
}
break;
case CMD_SetMath: {
INFO << "Packet command: SetMath";
const int packetSize = 4;
@ -822,7 +865,7 @@ void controller::hardWareCommand(int command, int channel, int val1, double val2
switch(cmd) {
case init_board:
break;
case adc_enable_ramp_test:

View File

@ -45,21 +45,32 @@ class TriggerWidget extends React.Component<any, any> {
// Trigger Level
increaseTriggerLevel = () => {
//TODO: Plumber call
//(TRIGGER LEVEL (V))/((VOLTAGE RANGExDIVISIONS)/256)
let tw = this.props.triggerWidget;
let lvl = tw.triggerLevel[tw.triggerChannel-1];
let vw = this.props.verticalWidget;
let div = vw.timePerDivision[tw.triggerChannel-1].coarse;
console.log(lvl);
Plumber.getInstance().handleSetLevel(lvl.value+1, lvl.unit, div.value, div.unit);
this.props.dispatch({type: 'trigger/increaseTriggerLevelValue'});
}
decreaseTriggerLevel = () => {
//TODO: Plumber call
//(TRIGGER LEVEL (V))/((VOLTAGE RANGExDIVISIONS)/256)
let tw = this.props.triggerWidget;
let lvl = tw.triggerLevel[tw.triggerChannel-1];
let vw = this.props.verticalWidget;
let div = vw.timePerDivision[tw.triggerChannel-1].coarse;
console.log(lvl);
Plumber.getInstance().handleSetLevel(lvl.value-1, lvl.unit, div.value, div.unit);
this.props.dispatch({type: 'trigger/decreaseTriggerLevelValue'});
}
// Trigger Level Unit
changeTriggerLevelUnit = (voltageUnit: VoltageUnit) => {
//TODO: unit analysis, plumber call
//(TRIGGER LEVEL (V))/((VOLTAGE RANGExDIVISIONS)/256)
let tw = this.props.triggerWidget;
let lvl = tw.triggerLevel[tw.triggerChannel-1];
let vw = this.props.verticalWidget;
let div = vw.timePerDivision[tw.triggerChannel-1].coarse;
Plumber.getInstance().handleSetLevel(lvl.value, voltageUnit, div.value, div.unit);
this.props.dispatch({type: 'trigger/changeTriggerLevelUnit', payload: voltageUnit});
}

View File

@ -18,22 +18,20 @@ class VerticalWidget extends React.Component<any, any> {
// Time Per Division
incrementTimePerDivision = () => {
let currentChannel = this.props.verticalWidget.activeChannel - 1;
let index = this.props.verticalWidget.timePerDivision[currentChannel].index;
if (index !== 0)
{
// Call C
let v = this.props.verticalWidget;
let idx = v.timePerDivision[v.activeChannel-1].index - 1;
Plumber.getInstance().handleVert(v.activeChannel, idx);
if(idx !== 0) {
this.props.dispatch({type: 'vertical/increaseTimePerDivision'});
};
}
}
decrementTimePerDivision = () => {
let currentChannel = this.props.verticalWidget.activeChannel - 1;
let index = this.props.verticalWidget.timePerDivision[currentChannel].index;
if (index < 12) {
// Call C
let v = this.props.verticalWidget;
let idx = v.timePerDivision[v.activeChannel-1].index + 1;
Plumber.getInstance().handleVert(v.activeChannel, idx);
if(idx < 12) {
this.props.dispatch({type: 'vertical/decreaseTimePerDivision'});
}
}

View File

@ -11,19 +11,19 @@ const TriggerWidgetInitialState = {
],
triggerLevel: [
{
value: 0.0,
value: 200.0,
unit: VoltageUnit.MilliVolt
},
{
value: 0.0,
value: 200.0,
unit: VoltageUnit.MilliVolt
},
{
value: 0.0,
value: 200.0,
unit: VoltageUnit.MilliVolt
},
{
value: 0.0,
value: 200.0,
unit: VoltageUnit.MilliVolt
}
]

View File

@ -108,7 +108,7 @@ const VerticalWidgetInitialState = {
unit: VoltageUnit.MilliVolt
}
],
getDataChannelOrder: [1, 2, 3, 4]
getDataChannelOrder: [1]
};
export default VerticalWidgetInitialState;

View File

@ -20,14 +20,14 @@ export default function TriggerWidgetReducer(state = TriggerWidgetInitialState,
};
case "trigger/increaseTriggerLevelValue":
tmp = state.triggerLevel;
tmp[channelIndex].value = Number((state.triggerLevel[channelIndex].value + 0.1).toFixed(1));
tmp[channelIndex].value = Number((state.triggerLevel[channelIndex].value + 1).toFixed(1));
return {
...state,
triggerLevel: tmp
};
case "trigger/decreaseTriggerLevelValue":
tmp = state.triggerLevel;
tmp[channelIndex].value = Number((state.triggerLevel[channelIndex].value - 0.1).toFixed(1));
tmp[channelIndex].value = Number((state.triggerLevel[channelIndex].value - 1).toFixed(1));
return {
...state,
triggerLevel: tmp

View File

@ -2,8 +2,9 @@ import CMD from '../configuration/enums/cmd';
import { SetChState } from './setChHelper';
import MathOperators from '../configuration/enums/mathOperators';
import DefaultValues from '../configuration/defaultValues';
import { convertTime } from './convert';
import { convertTime, convertVoltage } from './convert';
import TimeUnit from '../configuration/enums/timeUnit';
import VoltageUnit from '../configuration/enums/voltageUnit';
export enum SetMathOp {
SetMath_None = 0,
@ -118,7 +119,7 @@ export class Plumber {
bodyCheck: () => true,
cmd: CMD.CMD_SetCh,
id: 0,
writeData: [s.setCh, 0]
writeData: s.setCh
}
let setTriggerChArgs: PlumberArgs = {
headCheck: () => true,
@ -162,6 +163,34 @@ export class Plumber {
this.cycle(setWinArgs);
}
public handleVert(ch: number, idx: number) {
let bases = DefaultValues.x1ProbeValues;
let targIdx = (idx < 0) ? 0 : ((idx >= bases.length) ? bases.length : idx);
let targ = bases[targIdx];
let targMillivolt = convertVoltage(targ.value, targ.unit, VoltageUnit.MilliVolt);
let args = {
headCheck: () => true,
bodyCheck: () => true,
cmd: CMD.CMD_SetVerticalScaling,
id: 0,
writeData: new Int8Array((new Int16Array([ch,targMillivolt])).buffer)
}
this.cycle(args);
}
public handleSetLevel(lvl: number, lvlUnit: VoltageUnit, div: number, divUnit: VoltageUnit) {
let convertedLvl = convertVoltage(lvl, lvlUnit, divUnit);
let normLvl = 256 * convertedLvl/(div*DefaultValues.divisions.voltage);
let args = {
headCheck: () => true,
bodyCheck: () => true,
cmd: CMD.CMD_SetLevel,
id: 0,
writeData: new Int8Array([normLvl, 0])
}
this.cycle(args);
}
public decodeGetMinMax(args: PlumberArgs, a: Int8Array) {
let maxCh = 4;
let a64u = new BigUint64Array(a.buffer);

View File

@ -1,7 +1,5 @@
import setChMode from '../configuration/enums/setChMode';
export interface SetChState {
setCh: setChMode,
setCh: number[],
setTriggerCh: number,
chOrder: number[]
}
@ -18,10 +16,10 @@ export function setChHelper(
let quadChOrder = [1, 2, 3, 4];
var chOrder = quadChOrder.filter((a, i) => chList[i] || triggerChIdx === i);
var setCh = chOrder.length as setChMode;
if(setCh === 3) {
var setCh = chList.map(x => x ? 1 : 0);
if(setCh.length === 3) {
chOrder = quadChOrder;
setCh = quadChOrder.length;
setCh = quadChOrder.map(x => (x > 0) ? 1 : 0);
}
let setTriggerCh = chOrder.indexOf(triggerCh) + 1;

View File

@ -32,7 +32,7 @@ class TestPoints {
bodyCheck: () => true,
cmd: CMD.CMD_SetCh,
id: 0,
writeData: [state.verticalWidget.getDataChannelOrder.length, 0]
writeData: [1, 0, 0, 0]
}
this.setFileArgs = {
@ -71,7 +71,8 @@ class TestPoints {
if(this.setChDone && this.setFileDone && this.setWinDone) {
let state = store.getState();
let base = state.horizontalWidget.horizontalTimeBase.coarse;
let xLimit = convertTime(base.value, base.unit, TimeUnit.NanoSecond);
let dCount = DefaultValues.divisions.time;
let xLimit = dCount * convertTime(base.value, base.unit, TimeUnit.NanoSecond);
let doMath = state.mathWidget.mathEnabled as boolean;
let order = state.verticalWidget.getDataChannelOrder as number[];
@ -112,6 +113,7 @@ class TestPoints {
}
getData() {
console.log(this.scope_data);
return this.scope_data;
}
}