Added TS.NET #234
1
Software/TS.NET
Submodule
1
Software/TS.NET
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit f0e327d8eb61256027a620e06fd545f65f1871b6
|
@ -1,336 +0,0 @@
|
|||||||
#include "scope_control.h"
|
|
||||||
#include "scope_serial.h"
|
|
||||||
#include <algorithm>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#include <windows.h>
|
|
||||||
#elif _POSIX_C_SOURCE >= 199309L
|
|
||||||
#include <time.h> // for nanosleep
|
|
||||||
#else
|
|
||||||
#include <unistd.h> // for usleep
|
|
||||||
#endif
|
|
||||||
|
|
||||||
scope_control::scope_control(){
|
|
||||||
ser = new scope_serial;
|
|
||||||
}
|
|
||||||
|
|
||||||
scope_control::~scope_control(){
|
|
||||||
delete ser;
|
|
||||||
}
|
|
||||||
|
|
||||||
int scope_control::configure_serial(char* path){
|
|
||||||
ser->open_port(path);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int scope_control::boot(){
|
|
||||||
|
|
||||||
unsigned char io_dir [6];
|
|
||||||
unsigned char cmd_temp [4];
|
|
||||||
|
|
||||||
std::copy(io_dir_init,io_dir_init+sizeof(io_dir_init),io_dir);
|
|
||||||
std::copy(io_out_init,io_out_init+sizeof(io_out_init),io_out);
|
|
||||||
|
|
||||||
ser->send_command(io_out,sizeof(io_out));
|
|
||||||
ser->send_command(io_dir,sizeof(io_dir));
|
|
||||||
|
|
||||||
std::copy(&pga_init[0][0],&pga_init[0][0]+16,&pga[0][0]);
|
|
||||||
std::copy(&dac_init[0][0],&dac_init[0][0]+16,&dac[0][0]);
|
|
||||||
|
|
||||||
//Reset ADC
|
|
||||||
std::copy(adc_reset,adc_reset+sizeof(adc_reset),cmd_temp);
|
|
||||||
ser->send_command(cmd_temp,sizeof(cmd_temp));
|
|
||||||
//Power Down ADC
|
|
||||||
std::copy(adc_power_down,adc_power_down+sizeof(adc_power_down),cmd_temp);
|
|
||||||
ser->send_command(cmd_temp,sizeof(cmd_temp));
|
|
||||||
//Course Gain On
|
|
||||||
std::copy(adc_cgain_cfg,adc_cgain_cfg+sizeof(adc_cgain_cfg),cmd_temp);
|
|
||||||
ser->send_command(cmd_temp,sizeof(cmd_temp));
|
|
||||||
//Course Gain 4-CH set
|
|
||||||
std::copy(adc_cgain4,adc_cgain4+sizeof(adc_cgain4),cmd_temp);
|
|
||||||
ser->send_command(cmd_temp,sizeof(cmd_temp));
|
|
||||||
//Course Gain 1-CH & 2-CH set
|
|
||||||
std::copy(adc_cgain12,adc_cgain12+sizeof(adc_cgain12),cmd_temp);
|
|
||||||
ser->send_command(cmd_temp,sizeof(cmd_temp));
|
|
||||||
//Enables twos complement mode
|
|
||||||
std::copy(adc_btc_mode,adc_btc_mode+sizeof(adc_btc_mode),cmd_temp);
|
|
||||||
ser->send_command(cmd_temp,sizeof(cmd_temp));
|
|
||||||
|
|
||||||
std::copy(adc_chnum_clkdiv_init,adc_chnum_clkdiv_init+sizeof(adc_chnum_clkdiv_init),adc_chnum_clkdiv);
|
|
||||||
std::copy(adc_in_sel_12_init,adc_in_sel_12_init+sizeof(adc_in_sel_12_init),adc_in_sel_12);
|
|
||||||
std::copy(adc_in_sel_34_init,adc_in_sel_34_init+sizeof(adc_in_sel_34_init),adc_in_sel_34);
|
|
||||||
|
|
||||||
//Program PLL R Counter
|
|
||||||
std::copy(pll_r_counter,pll_r_counter+sizeof(pll_r_counter),cmd_temp);
|
|
||||||
ser->send_command(cmd_temp,sizeof(cmd_temp));
|
|
||||||
//Program PLL Control Latch
|
|
||||||
std::copy(pll_control,pll_control+sizeof(pll_control),cmd_temp);
|
|
||||||
ser->send_command(cmd_temp,sizeof(cmd_temp));
|
|
||||||
//Wait 10 ms
|
|
||||||
sleep_ms(10);
|
|
||||||
//Program PLL N Counter
|
|
||||||
std::copy(pll_n_counter,pll_n_counter+sizeof(pll_n_counter),cmd_temp);
|
|
||||||
ser->send_command(cmd_temp,sizeof(cmd_temp));
|
|
||||||
|
|
||||||
num_ch_on = 0;
|
|
||||||
ch_is_on[0] = false;
|
|
||||||
ch_is_on[1] = false;
|
|
||||||
ch_is_on[2] = false;
|
|
||||||
ch_is_on[3] = false;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int scope_control::load_default(){
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int scope_control::ch_on(int ch_num){
|
|
||||||
|
|
||||||
if (ch_is_on[ch_num-1])
|
|
||||||
return 0; //Channel already on
|
|
||||||
|
|
||||||
num_ch_on++;
|
|
||||||
ch_is_on[ch_num-1] = true;
|
|
||||||
|
|
||||||
adc_ch_cfg();
|
|
||||||
|
|
||||||
if (ch_num == 1)
|
|
||||||
io_out[4] |= (1 << 7);
|
|
||||||
else if (ch_num == 2)
|
|
||||||
io_out[4] |= (1 << 2);
|
|
||||||
else if (ch_num == 3)
|
|
||||||
io_out[3] |= (1 << 5);
|
|
||||||
else if (ch_num == 4)
|
|
||||||
io_out[3] |= (1 << 0);
|
|
||||||
|
|
||||||
ser->send_command(io_out,sizeof(io_out));
|
|
||||||
|
|
||||||
//DAC and PGA forget settings on channel off, so rewrite to them
|
|
||||||
ser->send_command(dac[ch_num-1],sizeof(dac[1]));
|
|
||||||
ser->send_command(pga[ch_num-1],sizeof(pga[1]));
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int scope_control::ch_off(int ch_num){
|
|
||||||
|
|
||||||
if (!ch_is_on[ch_num-1])
|
|
||||||
return 0; //Channel already off
|
|
||||||
|
|
||||||
num_ch_on--;
|
|
||||||
ch_is_on[ch_num-1] = false;
|
|
||||||
|
|
||||||
adc_ch_cfg();
|
|
||||||
|
|
||||||
if (ch_num == 1)
|
|
||||||
io_out[4] &= ~(1 << 7);
|
|
||||||
else if (ch_num == 2)
|
|
||||||
io_out[4] &= ~(1 << 2);
|
|
||||||
else if (ch_num == 3)
|
|
||||||
io_out[3] &= ~(1 << 5);
|
|
||||||
else if (ch_num == 4)
|
|
||||||
io_out[3] &= ~(1 << 0);
|
|
||||||
|
|
||||||
ser->send_command(io_out,sizeof(io_out));
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int scope_control::dc_cpl(int ch_num){
|
|
||||||
if (ch_num == 1)
|
|
||||||
io_out[5] |= (1 << 3);
|
|
||||||
else if (ch_num == 2)
|
|
||||||
io_out[4] |= (1 << 6);
|
|
||||||
else if (ch_num == 3)
|
|
||||||
io_out[4] |= (1 << 1);
|
|
||||||
else if (ch_num == 4)
|
|
||||||
io_out[3] |= (1 << 4);
|
|
||||||
|
|
||||||
ser->send_command(io_out,sizeof(io_out));
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int scope_control::ac_cpl(int ch_num){
|
|
||||||
if (ch_num == 1)
|
|
||||||
io_out[5] &= ~(1 << 3);
|
|
||||||
else if (ch_num == 2)
|
|
||||||
io_out[4] &= ~(1 << 6);
|
|
||||||
else if (ch_num == 3)
|
|
||||||
io_out[4] &= ~(1 << 1);
|
|
||||||
else if (ch_num == 4)
|
|
||||||
io_out[3] &= ~(1 << 4);
|
|
||||||
|
|
||||||
ser->send_command(io_out,sizeof(io_out));
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int scope_control::vdiv_set(int ch_num, int vdiv){
|
|
||||||
|
|
||||||
if (vdiv > 100){ //Attenuator relay on for higher v/divs
|
|
||||||
if (ch_num == 1)
|
|
||||||
io_out[5] |= (1 << 1);
|
|
||||||
else if (ch_num == 2)
|
|
||||||
io_out[4] |= (1 << 4);
|
|
||||||
else if (ch_num == 3)
|
|
||||||
io_out[3] |= (1 << 7);
|
|
||||||
else if (ch_num == 4)
|
|
||||||
io_out[3] |= (1 << 2);
|
|
||||||
}
|
|
||||||
else{ //Attenuator relay off for lower v/divs
|
|
||||||
if (ch_num == 1)
|
|
||||||
io_out[5] &= ~(1 << 1);
|
|
||||||
else if (ch_num == 2)
|
|
||||||
io_out[4] &= ~(1 << 4);
|
|
||||||
else if (ch_num == 3)
|
|
||||||
io_out[3] &= ~(1 << 7);
|
|
||||||
else if (ch_num == 4)
|
|
||||||
io_out[3] &= ~(1 << 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vdiv == 10000 || vdiv == 100){
|
|
||||||
pga[ch_num-1][3] &= 0xE0;
|
|
||||||
pga[ch_num-1][3] |= 0x0A;
|
|
||||||
}
|
|
||||||
else if (vdiv == 5000 || vdiv == 50){
|
|
||||||
pga[ch_num-1][3] &= 0xE0;
|
|
||||||
pga[ch_num-1][3] |= 0x07;
|
|
||||||
}
|
|
||||||
else if (vdiv == 2000 || vdiv == 20){
|
|
||||||
pga[ch_num-1][3] &= 0xE0;
|
|
||||||
pga[ch_num-1][3] |= 0x03;
|
|
||||||
}
|
|
||||||
else if (vdiv == 1000 || vdiv == 10){
|
|
||||||
pga[ch_num-1][3] &= 0xE0;
|
|
||||||
pga[ch_num-1][3] |= 0x1A;
|
|
||||||
}
|
|
||||||
else if (vdiv == 500 || vdiv == 5){
|
|
||||||
pga[ch_num-1][3] &= 0xE0;
|
|
||||||
pga[ch_num-1][3] |= 0x17;
|
|
||||||
}
|
|
||||||
else if (vdiv == 200 || vdiv == 2){
|
|
||||||
pga[ch_num-1][3] &= 0xE0;
|
|
||||||
pga[ch_num-1][3] |= 0x13;
|
|
||||||
}
|
|
||||||
else if (vdiv == 1){
|
|
||||||
pga[ch_num-1][3] &= 0xE0;
|
|
||||||
pga[ch_num-1][3] |= 0x10;
|
|
||||||
}
|
|
||||||
|
|
||||||
ser->send_command(pga[ch_num-1],sizeof(pga[1]));
|
|
||||||
ser->send_command(io_out,sizeof(io_out));
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int scope_control::voffset_set(int ch_num, double voffset){
|
|
||||||
|
|
||||||
unsigned int dac_value = (unsigned int)round((voffset + 0.5) * 1023);
|
|
||||||
dac_value = dac_value << 2;
|
|
||||||
|
|
||||||
dac[ch_num-1][3] = (unsigned char)(0xFF & dac_value);
|
|
||||||
dac[ch_num-1][2] = (unsigned char)(0x0F & (dac_value >> 8));
|
|
||||||
|
|
||||||
ser->send_command(dac[ch_num-1],sizeof(dac[1]));
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int scope_control::bw_set(int ch_num, int bw){
|
|
||||||
if (bw == 20){
|
|
||||||
pga[ch_num-1][3] &= 0x1F;
|
|
||||||
pga[ch_num-1][3] |= 0x40;
|
|
||||||
}
|
|
||||||
else if (bw == 100){
|
|
||||||
pga[ch_num-1][3] &= 0x1F;
|
|
||||||
pga[ch_num-1][3] |= 0x80;
|
|
||||||
}
|
|
||||||
else if (bw == 200){
|
|
||||||
pga[ch_num-1][3] &= 0x1F;
|
|
||||||
pga[ch_num-1][3] |= 0xC0;
|
|
||||||
}
|
|
||||||
else if (bw == 350){
|
|
||||||
pga[ch_num-1][3] &= 0x1F;
|
|
||||||
}
|
|
||||||
|
|
||||||
ser->send_command(pga[ch_num-1],sizeof(pga[1]));
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int scope_control::adc_ch_cfg(){
|
|
||||||
unsigned char cmd_temp [4];
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (num_ch_on == 0){
|
|
||||||
std::copy(adc_power_down,adc_power_down+sizeof(adc_power_down),cmd_temp);
|
|
||||||
ser->send_command(cmd_temp,sizeof(cmd_temp));
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else if (num_ch_on == 1){
|
|
||||||
adc_chnum_clkdiv[3] = 0x01;
|
|
||||||
adc_chnum_clkdiv[2] = 0x00;
|
|
||||||
|
|
||||||
for (i=0; !ch_is_on[i]; i++); //Find channel that is on
|
|
||||||
|
|
||||||
adc_in_sel_12[3] = (2 << i); //Set all 4 ADCs to sample that channel
|
|
||||||
adc_in_sel_12[2] = (2 << i);
|
|
||||||
adc_in_sel_34[3] = (2 << i);
|
|
||||||
adc_in_sel_34[2] = (2 << i);
|
|
||||||
}
|
|
||||||
else if (num_ch_on == 2){
|
|
||||||
adc_chnum_clkdiv[3] = 0x02;
|
|
||||||
adc_chnum_clkdiv[2] = 0x01;
|
|
||||||
|
|
||||||
for (i=0; !ch_is_on[i]; i++); //Find first on channel
|
|
||||||
|
|
||||||
adc_in_sel_12[3] = (2 << i); //Set 2 ADCs to sample first channel
|
|
||||||
adc_in_sel_12[2] = (2 << i);
|
|
||||||
|
|
||||||
for (; !ch_is_on[i]; i++); //Find second on channel
|
|
||||||
|
|
||||||
adc_in_sel_34[3] = (2 << i); //Set 2 ADCs to sample second channel
|
|
||||||
adc_in_sel_34[2] = (2 << i);
|
|
||||||
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
adc_chnum_clkdiv[3] = 0x04;
|
|
||||||
adc_chnum_clkdiv[2] = 0x02;
|
|
||||||
adc_in_sel_12[3] = (2 << 0); //Set each ADC to sample one channel
|
|
||||||
adc_in_sel_12[2] = (2 << 1);
|
|
||||||
adc_in_sel_34[3] = (2 << 2);
|
|
||||||
adc_in_sel_34[2] = (2 << 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::copy(adc_power_down,adc_power_down+sizeof(adc_power_down),cmd_temp);
|
|
||||||
ser->send_command(cmd_temp,sizeof(cmd_temp));
|
|
||||||
|
|
||||||
ser->send_command(adc_chnum_clkdiv,sizeof(adc_chnum_clkdiv));
|
|
||||||
|
|
||||||
std::copy(adc_active,adc_active+sizeof(adc_active),cmd_temp);
|
|
||||||
ser->send_command(cmd_temp,sizeof(cmd_temp));
|
|
||||||
|
|
||||||
ser->send_command(adc_in_sel_12,sizeof(adc_in_sel_12));
|
|
||||||
ser->send_command(adc_in_sel_34,sizeof(adc_in_sel_34));
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void scope_control::sleep_ms(int milliseconds){ // cross-platform sleep function
|
|
||||||
#ifdef WIN32
|
|
||||||
Sleep(milliseconds);
|
|
||||||
#elif _POSIX_C_SOURCE >= 199309L
|
|
||||||
struct timespec ts;
|
|
||||||
ts.tv_sec = milliseconds / 1000;
|
|
||||||
ts.tv_nsec = (milliseconds % 1000) * 1000000;
|
|
||||||
nanosleep(&ts, NULL);
|
|
||||||
#else
|
|
||||||
if (milliseconds >= 1000)
|
|
||||||
sleep(milliseconds / 1000);
|
|
||||||
usleep((milliseconds % 1000) * 1000);
|
|
||||||
#endif
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
#ifndef SCOPE_CONTROL_H // To make sure you don't declare the function more than once by including the header multiple times.
|
|
||||||
#define SCOPE_CONTROL_H
|
|
||||||
|
|
||||||
#include "scope_serial.h"
|
|
||||||
|
|
||||||
class scope_control
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
scope_serial *ser;
|
|
||||||
|
|
||||||
const unsigned char io_dir_init [6] = {0xFF,0x44,0x8C,0x00,0x00,0x00};
|
|
||||||
const unsigned char io_out_init [6] = {0xFF,0x44,0x84,0x00,0x00,0x00};
|
|
||||||
unsigned char io_out [6];
|
|
||||||
//DAC Addressing not implemented yet, only one FE w/ addr 0x18 exists
|
|
||||||
const unsigned char dac_init [4][4] = {{0xFF,0x18,0x07,0x00},
|
|
||||||
{0xFF,0x18,0x07,0x00},
|
|
||||||
{0xFF,0x18,0x07,0x00},
|
|
||||||
{0xFF,0x18,0x07,0x00}};
|
|
||||||
unsigned char dac [4][4];
|
|
||||||
|
|
||||||
const unsigned char pga_init [4][4] = {{0xFB,0x00,0x04,0x0A},
|
|
||||||
{0xFA,0x00,0x04,0x0A},
|
|
||||||
{0xF9,0x00,0x04,0x0A},
|
|
||||||
{0xF8,0x00,0x04,0x0A}};
|
|
||||||
unsigned char pga [4][4];
|
|
||||||
|
|
||||||
const unsigned char adc_reset [4] = {0xFD,0x00,0x00,0x01};
|
|
||||||
const unsigned char adc_power_down [4] = {0xFD,0x0F,0x02,0x00};
|
|
||||||
const unsigned char adc_active [4] = {0xFD,0x0F,0x00,0x00};
|
|
||||||
const unsigned char adc_cgain_cfg [4] = {0xFD,0x33,0x00,0x00}; //db mode, fine gain off
|
|
||||||
const unsigned char adc_cgain4 [4] = {0xFD,0x2A,0x55,0x55}; //9db gain in 4ch mode
|
|
||||||
const unsigned char adc_cgain12 [4] = {0xFD,0x2B,0x05,0x55}; //9db gain in 1&2ch mode
|
|
||||||
//5db gain due to ADC HiZ input (not 100ohm diff)
|
|
||||||
const unsigned char adc_btc_mode [4] = {0xFD,0x46,0x00,0x04}; // enables twos complement mode
|
|
||||||
|
|
||||||
const unsigned char adc_chnum_clkdiv_init [4] = {0xFD,0x31,0x00,0x01};
|
|
||||||
const unsigned char adc_in_sel_12_init [4] = {0xFD,0x3A,0x10,0x10};
|
|
||||||
const unsigned char adc_in_sel_34_init [4] = {0xFD,0x3B,0x10,0x10};
|
|
||||||
|
|
||||||
unsigned char adc_chnum_clkdiv [4];
|
|
||||||
unsigned char adc_in_sel_12 [4];
|
|
||||||
unsigned char adc_in_sel_34 [4];
|
|
||||||
|
|
||||||
const unsigned char pll_r_counter[4] = {0xFC,0x34,0x00,0x09};
|
|
||||||
const unsigned char pll_control[4] = {0xFC,0x0F,0xF9,0xA0};
|
|
||||||
const unsigned char pll_n_counter[4] = {0xFC,0x00,0x0F,0x16};
|
|
||||||
|
|
||||||
int num_ch_on;
|
|
||||||
bool ch_is_on [4];
|
|
||||||
|
|
||||||
int adc_ch_cfg();
|
|
||||||
void sleep_ms(int milliseconds);
|
|
||||||
|
|
||||||
public:
|
|
||||||
scope_control();
|
|
||||||
~scope_control();
|
|
||||||
int configure_serial(char* path);
|
|
||||||
int boot();
|
|
||||||
int load_default();
|
|
||||||
int ch_on(int ch_num);
|
|
||||||
int ch_off(int ch_num);
|
|
||||||
int dc_cpl(int ch_num);
|
|
||||||
int ac_cpl(int ch_num);
|
|
||||||
int vdiv_set(int ch_num, int vdiv);
|
|
||||||
int voffset_set(int ch_num, double voffset);
|
|
||||||
int bw_set(int ch_num, int bw);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,127 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include "scope_control.h"
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
void ch_menu(int ch_num);
|
|
||||||
void vdiv_prompt(int ch_num);
|
|
||||||
void voffset_prompt (int ch_num);
|
|
||||||
void bw_prompt (int ch_num);
|
|
||||||
|
|
||||||
bool active_channels [4] = {false,false,false,false};
|
|
||||||
bool dc_coupling [4] = {false,false,false,false};
|
|
||||||
|
|
||||||
scope_control *scope = new scope_control;
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
int ch_num;
|
|
||||||
|
|
||||||
cout << "--------------------------------------------------" << endl;
|
|
||||||
cout << " Scope Hardware Control V0.01 " << endl;
|
|
||||||
cout << "--------------------------------------------------" << endl;
|
|
||||||
|
|
||||||
cout << "Path to serial port: ";
|
|
||||||
char path[32];
|
|
||||||
cin >> path;
|
|
||||||
|
|
||||||
scope->configure_serial(path);
|
|
||||||
|
|
||||||
cout << "--------------------------------------------------" << endl;
|
|
||||||
|
|
||||||
scope->boot();
|
|
||||||
|
|
||||||
while (1){
|
|
||||||
cout << "Select a channel (1-4) or 0 to quit: ";
|
|
||||||
cin >> ch_num;
|
|
||||||
if (ch_num == 0){
|
|
||||||
cout << "--------------------------------------------------" << endl;
|
|
||||||
delete scope;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
cout << "--------------------------------------------------" << endl;
|
|
||||||
ch_menu(ch_num);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ch_menu(int ch_num){
|
|
||||||
while (1){
|
|
||||||
cout << "0 - Back" << endl;
|
|
||||||
if (!active_channels[ch_num-1])
|
|
||||||
cout << "1 - Channel On" << endl;
|
|
||||||
else{
|
|
||||||
cout << "2 - Channel Off" << endl;
|
|
||||||
cout << "3 - V/Div Settings" << endl;
|
|
||||||
cout << "4 - V Offset Settings" << endl;
|
|
||||||
if (!dc_coupling[ch_num-1])
|
|
||||||
cout << "5 - DC Coupling" << endl;
|
|
||||||
else
|
|
||||||
cout << "6 - AC Coupling" << endl;
|
|
||||||
cout << "7 - Bandwidth Settings" << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "--------------------------------------------------" << endl;
|
|
||||||
cout << "Select an option for channel " << ch_num << ": ";
|
|
||||||
|
|
||||||
int option_num;
|
|
||||||
cin >> option_num;
|
|
||||||
|
|
||||||
if (option_num == 0){
|
|
||||||
cout << "--------------------------------------------------" << endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (active_channels[ch_num-1]){
|
|
||||||
if (option_num == 2){
|
|
||||||
scope->ch_off(ch_num);
|
|
||||||
active_channels[ch_num-1] = false;
|
|
||||||
}
|
|
||||||
else if (option_num == 3)
|
|
||||||
vdiv_prompt(ch_num);
|
|
||||||
else if (option_num == 4)
|
|
||||||
voffset_prompt(ch_num);
|
|
||||||
else if (option_num == 5 && !dc_coupling[ch_num-1]){
|
|
||||||
scope->dc_cpl(ch_num);
|
|
||||||
dc_coupling[ch_num-1] = true;
|
|
||||||
}
|
|
||||||
else if (option_num == 6 && dc_coupling[ch_num-1]){
|
|
||||||
scope->ac_cpl(ch_num);
|
|
||||||
dc_coupling[ch_num-1] = false;
|
|
||||||
}
|
|
||||||
else if (option_num == 7)
|
|
||||||
bw_prompt(ch_num);
|
|
||||||
}
|
|
||||||
else if (option_num == 1 && !active_channels[ch_num-1]){
|
|
||||||
scope->ch_on(ch_num);
|
|
||||||
active_channels[ch_num-1] = true;
|
|
||||||
}
|
|
||||||
cout << "--------------------------------------------------" << endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void vdiv_prompt(int ch_num){
|
|
||||||
cout << "--------------------------------------------------" << endl;
|
|
||||||
cout << "Enter a value in mV/Div (5,2,1 sequence): ";
|
|
||||||
int vdiv;
|
|
||||||
cin >> vdiv;
|
|
||||||
scope->vdiv_set(ch_num, vdiv);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void voffset_prompt(int ch_num){
|
|
||||||
cout << "--------------------------------------------------" << endl;
|
|
||||||
cout << "Enter a offset value in V (0 +/- 0.5V): ";
|
|
||||||
double voffset;
|
|
||||||
cin >> voffset;
|
|
||||||
scope->voffset_set(ch_num, voffset);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void bw_prompt(int ch_num){
|
|
||||||
cout << "--------------------------------------------------" << endl;
|
|
||||||
cout << "Enter a BW in MHz (20,100,200,350): ";
|
|
||||||
int bw;
|
|
||||||
cin >> bw;
|
|
||||||
scope->bw_set(ch_num, bw);
|
|
||||||
return;
|
|
||||||
}
|
|
@ -1,79 +0,0 @@
|
|||||||
#include "scope_serial.h"
|
|
||||||
// C library headers
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
// Linux headers
|
|
||||||
#include <fcntl.h> // Contains file controls like O_RDWR
|
|
||||||
#include <errno.h> // Error integer and strerror() function
|
|
||||||
#include <termios.h> // Contains POSIX terminal control definitions
|
|
||||||
#include <unistd.h> // write(), read(), close()
|
|
||||||
|
|
||||||
scope_serial::scope_serial(){
|
|
||||||
}
|
|
||||||
|
|
||||||
scope_serial::~scope_serial(){
|
|
||||||
close(serial_port);
|
|
||||||
}
|
|
||||||
|
|
||||||
int scope_serial::open_port(char* path){
|
|
||||||
|
|
||||||
serial_port = open(path, O_RDWR);
|
|
||||||
// Create new termios struc, we call it 'tty' for convention
|
|
||||||
struct termios tty;
|
|
||||||
memset(&tty, 0, sizeof tty);
|
|
||||||
// Read in existing settings, and handle any error
|
|
||||||
if(tcgetattr(serial_port, &tty) != 0)
|
|
||||||
printf("Error %i from tcgetattr: %s\n", errno, strerror(errno));
|
|
||||||
|
|
||||||
tty.c_cflag &= ~PARENB; // Clear parity bit, disabling parity (most common)
|
|
||||||
tty.c_cflag &= ~CSTOPB; // Clear stop field, only one stop bit used in communication (most common)
|
|
||||||
tty.c_cflag |= CS8; // 8 bits per byte (most common)
|
|
||||||
tty.c_cflag &= ~CRTSCTS; // Disable RTS/CTS hardware flow control (most common)
|
|
||||||
tty.c_cflag |= CREAD | CLOCAL; // Turn on READ & ignore ctrl lines (CLOCAL = 1)
|
|
||||||
tty.c_lflag &= ~ICANON;
|
|
||||||
tty.c_lflag &= ~ECHO; // Disable echo
|
|
||||||
tty.c_lflag &= ~ECHOE; // Disable erasure
|
|
||||||
tty.c_lflag &= ~ECHONL; // Disable new-line echo
|
|
||||||
tty.c_lflag &= ~ISIG; // Disable interpretation of INTR, QUIT and SUSP
|
|
||||||
tty.c_iflag &= ~(IXON | IXOFF | IXANY); // Turn off s/w flow ctrl
|
|
||||||
tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL); // Disable any special handling of received bytes
|
|
||||||
tty.c_oflag &= ~OPOST; // Prevent special interpretation of output bytes (e.g. newline chars)
|
|
||||||
tty.c_oflag &= ~ONLCR; // Prevent conversion of newline to carriage return/line feed
|
|
||||||
// tty.c_oflag &= ~OXTABS; // Prevent conversion of tabs to spaces (NOT PRESENT ON LINUX)
|
|
||||||
// tty.c_oflag &= ~ONOEOT; // Prevent removal of C-d chars (0x004) in output (NOT PRESENT ON LINUX)
|
|
||||||
tty.c_cc[VTIME] = 10; // Wait for up to 1s (10 deciseconds), returning as soon as any data is received.
|
|
||||||
tty.c_cc[VMIN] = 0;
|
|
||||||
|
|
||||||
// Set in/out baud rate to be 9600
|
|
||||||
cfsetispeed(&tty, B9600);
|
|
||||||
cfsetospeed(&tty, B9600);
|
|
||||||
|
|
||||||
// Save tty settings, also checking for error
|
|
||||||
if (tcsetattr(serial_port, TCSANOW, &tty) != 0)
|
|
||||||
printf("Error %i from tcsetattr: %s\n", errno, strerror(errno));
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int scope_serial::send_command(unsigned char* command, int len){
|
|
||||||
// Write to serial port
|
|
||||||
write(serial_port, command, len);
|
|
||||||
|
|
||||||
// Allocate memory for read buffer, set size according to your needs
|
|
||||||
char read_buf = 0;
|
|
||||||
|
|
||||||
// Read bytes. The behaviour of read() (e.g. does it block?,
|
|
||||||
// how long does it block for?) depends on the configuration
|
|
||||||
// settings above, specifically VMIN and VTIME
|
|
||||||
int num_bytes = read(serial_port, &read_buf, sizeof(read_buf));
|
|
||||||
|
|
||||||
// n may be 0 if no bytes were received, and can also be -1 to signal error.
|
|
||||||
if (num_bytes < 0) {
|
|
||||||
printf("Error reading: %s", strerror(errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (read_buf == '$')
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
#ifndef SCOPE_SERIAL_H // To make sure you don't declare the function more than once by including the header multiple times.
|
|
||||||
#define SCOPE_SERIAL_H
|
|
||||||
|
|
||||||
class scope_serial
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
int serial_port;
|
|
||||||
public:
|
|
||||||
scope_serial();
|
|
||||||
~scope_serial();
|
|
||||||
int open_port(char* path);
|
|
||||||
int send_command(unsigned char* command, int len);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,42 +0,0 @@
|
|||||||
{
|
|
||||||
"env": {
|
|
||||||
"development": {
|
|
||||||
"application/javascript": {
|
|
||||||
"presets": [
|
|
||||||
[
|
|
||||||
"env",
|
|
||||||
{
|
|
||||||
"targets": {
|
|
||||||
"electron": "3.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"react"
|
|
||||||
],
|
|
||||||
"plugins": [
|
|
||||||
"transform-async-to-generator"
|
|
||||||
],
|
|
||||||
"sourceMaps": "inline"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"production": {
|
|
||||||
"application/javascript": {
|
|
||||||
"presets": [
|
|
||||||
[
|
|
||||||
"env",
|
|
||||||
{
|
|
||||||
"targets": {
|
|
||||||
"electron": "3.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"react"
|
|
||||||
],
|
|
||||||
"plugins": [
|
|
||||||
"transform-async-to-generator"
|
|
||||||
],
|
|
||||||
"sourceMaps": "none"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
2
Software/web_worker_example/.gitignore
vendored
2
Software/web_worker_example/.gitignore
vendored
@ -1,2 +0,0 @@
|
|||||||
node_modules
|
|
||||||
out
|
|
@ -1,20 +0,0 @@
|
|||||||
# Electron Web Worker Example
|
|
||||||
|
|
||||||
Bare minimal example that shows a Web Worker running in Electron with Node
|
|
||||||
integration, meaning the Worker can use Node.js APIs (f.e. `require()` to import
|
|
||||||
NPM dependencies, etc).
|
|
||||||
|
|
||||||
## Run
|
|
||||||
|
|
||||||
To run the example:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm install
|
|
||||||
npm start
|
|
||||||
```
|
|
||||||
|
|
||||||
When the window opens, look at the console to see the logs from the worker script.
|
|
||||||
|
|
||||||
The `src/client.js` file starts the `src/worker.js` file in a `Worker`. The
|
|
||||||
`src/index.js` file creates the `BrowserWindow` with `nodeIntegrationInWorker`
|
|
||||||
set to `true` so that Node.js APIs are available in the Worker.
|
|
20848
Software/web_worker_example/package-lock.json
generated
20848
Software/web_worker_example/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,67 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "my-new-project",
|
|
||||||
"productName": "my-new-project",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "My Electron application description",
|
|
||||||
"main": "src/index.js",
|
|
||||||
"scripts": {
|
|
||||||
"start": "electron src/index.js",
|
|
||||||
"forge-start": "electron-forge start",
|
|
||||||
"package": "electron-forge package",
|
|
||||||
"make": "electron-forge make",
|
|
||||||
"publish": "electron-forge publish",
|
|
||||||
"lint": "eslint src --color"
|
|
||||||
},
|
|
||||||
"keywords": [],
|
|
||||||
"author": "trusktr",
|
|
||||||
"license": "MIT",
|
|
||||||
"config": {
|
|
||||||
"forge": {
|
|
||||||
"make_targets": {
|
|
||||||
"win32": [
|
|
||||||
"squirrel"
|
|
||||||
],
|
|
||||||
"darwin": [
|
|
||||||
"zip"
|
|
||||||
],
|
|
||||||
"linux": [
|
|
||||||
"deb",
|
|
||||||
"rpm"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"electronPackagerConfig": {
|
|
||||||
"packageManager": "yarn"
|
|
||||||
},
|
|
||||||
"electronWinstallerConfig": {
|
|
||||||
"name": "my_new_project"
|
|
||||||
},
|
|
||||||
"electronInstallerDebian": {},
|
|
||||||
"electronInstallerRedhat": {},
|
|
||||||
"github_repository": {
|
|
||||||
"owner": "",
|
|
||||||
"name": ""
|
|
||||||
},
|
|
||||||
"windowsStoreConfig": {
|
|
||||||
"packageName": "",
|
|
||||||
"name": "mynewproject"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"electron-compile": "^6.4.3",
|
|
||||||
"electron-squirrel-startup": "^1.0.0",
|
|
||||||
"lodash": "^4.17.11"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"babel-plugin-transform-async-to-generator": "^6.24.1",
|
|
||||||
"babel-preset-env": "^1.7.0",
|
|
||||||
"babel-preset-react": "^6.24.1",
|
|
||||||
"electron-forge": "^5.2.2",
|
|
||||||
"electron-prebuilt-compile": "3.0.6",
|
|
||||||
"eslint": "^3",
|
|
||||||
"eslint-config-airbnb": "^15",
|
|
||||||
"eslint-plugin-import": "^2",
|
|
||||||
"eslint-plugin-jsx-a11y": "^5",
|
|
||||||
"eslint-plugin-react": "^7"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
const path = require('path')
|
|
||||||
|
|
||||||
console.log('make a worker: ', path.resolve(__dirname, 'worker.js'))
|
|
||||||
|
|
||||||
const worker = new Worker(path.resolve(__dirname, 'worker.js'))
|
|
||||||
|
|
||||||
worker.onmessage = function(e) {
|
|
||||||
var result = e.data;
|
|
||||||
console.log(result);
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title></title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
See the console.
|
|
||||||
<script>
|
|
||||||
require('./client.js')
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,63 +0,0 @@
|
|||||||
import { app, BrowserWindow } from 'electron'
|
|
||||||
|
|
||||||
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
|
|
||||||
if (require('electron-squirrel-startup')) {
|
|
||||||
// eslint-disable-line global-require
|
|
||||||
app.quit()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Keep a global reference of the window object, if you don't, the window will
|
|
||||||
// be closed automatically when the JavaScript object is garbage collected.
|
|
||||||
let mainWindow
|
|
||||||
|
|
||||||
const createWindow = () => {
|
|
||||||
// Create the browser window.
|
|
||||||
mainWindow = new BrowserWindow({
|
|
||||||
width: 800,
|
|
||||||
height: 600,
|
|
||||||
webPreferences: {
|
|
||||||
// allow code inside this window to use use native window.open()
|
|
||||||
nativeWindowOpen: true,
|
|
||||||
nodeIntegrationInWorker: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
// and load the index.html of the app.
|
|
||||||
mainWindow.loadURL(`file://${__dirname}/index.html`)
|
|
||||||
|
|
||||||
// Open the DevTools.
|
|
||||||
mainWindow.webContents.openDevTools()
|
|
||||||
|
|
||||||
// Emitted when the window is closed.
|
|
||||||
mainWindow.on('closed', () => {
|
|
||||||
// Dereference the window object, usually you would store windows
|
|
||||||
// in an array if your app supports multi windows, this is the time
|
|
||||||
// when you should delete the corresponding element.
|
|
||||||
mainWindow = null
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// This method will be called when Electron has finished
|
|
||||||
// initialization and is ready to create browser windows.
|
|
||||||
// Some APIs can only be used after this event occurs.
|
|
||||||
app.on('ready', createWindow)
|
|
||||||
|
|
||||||
// Quit when all windows are closed.
|
|
||||||
app.on('window-all-closed', () => {
|
|
||||||
// On OS X it is common for applications and their menu bar
|
|
||||||
// to stay active until the user quits explicitly with Cmd + Q
|
|
||||||
if (process.platform !== 'darwin') {
|
|
||||||
app.quit()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
app.on('activate', () => {
|
|
||||||
// On OS X it's common to re-create a window in the app when the
|
|
||||||
// dock icon is clicked and there are no other windows open.
|
|
||||||
if (mainWindow === null) {
|
|
||||||
createWindow()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// In this file you can include the rest of your app's specific main process
|
|
||||||
// code. You can also put them in separate files and import them here.
|
|
@ -1,66 +0,0 @@
|
|||||||
/*const _ = require('lodash')
|
|
||||||
|
|
||||||
const sleep = async time => new Promise(r => setTimeout(r, time))
|
|
||||||
|
|
||||||
~(async function main() {
|
|
||||||
while (true) {
|
|
||||||
console.log('lodash map exists:', typeof _.map)
|
|
||||||
await sleep(1000)
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
*/
|
|
||||||
import * as fs from 'fs';
|
|
||||||
|
|
||||||
const SOCKET_PREFIX = (process.platform == "win32") ? "\\\\.\\pipe\\" : "/tmp/";
|
|
||||||
const SOCKETFILE_TX = SOCKET_PREFIX + "testPipeRX";
|
|
||||||
const SOCKETFILE_RX = SOCKET_PREFIX + "testPipeTX";
|
|
||||||
|
|
||||||
var TX_FD = -1;
|
|
||||||
var RX_FD = -1;
|
|
||||||
fs.open(SOCKETFILE_TX, "w", (err, fd) => {TX_FD = fd;});
|
|
||||||
fs.open(SOCKETFILE_RX, "r", (err, fd) => {RX_FD = fd;});
|
|
||||||
|
|
||||||
//Welcome to the future: https://www.electronjs.org/docs/tutorial/context-isolation
|
|
||||||
var thunderBridge = {
|
|
||||||
write: (buf, cb) => fs.write(TX_FD, buf, 0, cb),
|
|
||||||
read: (buf, cb) => fs.read(RX_FD, buf, 0, buf.length, 0, cb)
|
|
||||||
};
|
|
||||||
|
|
||||||
function tick() {
|
|
||||||
var testPacket16 = new Uint16Array(new ArrayBuffer(10));
|
|
||||||
testPacket16[0] = 0x1F;
|
|
||||||
testPacket16[1] = 0x1F2C;
|
|
||||||
testPacket16[2] = 4;
|
|
||||||
var testPacket = new Uint8Array(testPacket16.buffer);
|
|
||||||
testPacket[6] = 1;
|
|
||||||
testPacket[7] = 2;
|
|
||||||
testPacket[8] = 3;
|
|
||||||
testPacket[9] = 4;
|
|
||||||
|
|
||||||
thunderBridge.write(testPacket,() => {
|
|
||||||
var rxBuff = new Uint8Array(new ArrayBuffer(6));
|
|
||||||
thunderBridge.read(rxBuff, (err, bytesRead, bytes) => {
|
|
||||||
var bytes16 = new Uint16Array(bytes.buffer);
|
|
||||||
var dataSize = bytes16[2];
|
|
||||||
//console.log(bytes16);
|
|
||||||
//console.log(bytes);
|
|
||||||
|
|
||||||
var dataRxBuff = new Uint8Array(dataSize);
|
|
||||||
thunderBridge.read(dataRxBuff, (nestedErr, nestedBytesRead, nestedBytes) => {
|
|
||||||
var scope_data = [];
|
|
||||||
for(var i = 0; i < nestedBytes.length; i++) {
|
|
||||||
scope_data[i] = {x: i, y: nestedBytes[i]}
|
|
||||||
}
|
|
||||||
//console.log(nestedBytes);
|
|
||||||
//console.log(scope_data);
|
|
||||||
|
|
||||||
postMessage(scope_data);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
timerID = setInterval(
|
|
||||||
() => tick(),
|
|
||||||
33.33
|
|
||||||
)
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user