Implemented first part of serial decoding.

So far, only UART decoding works. SPI, I2C, etc. still needs to be implemented.
merge-requests/1/head
Teuniz 2016-12-04 11:25:10 +01:00
rodzic 42cf49b89b
commit 01531a8538
3 zmienionych plików z 381 dodań i 118 usunięć

Wyświetl plik

@ -35,7 +35,7 @@
#define PROGRAM_NAME "DSRemote"
#define PROGRAM_VERSION "0.33_1612032335"
#define PROGRAM_VERSION "0.33_1612041119"
#define MAX_PATHLEN 4096
@ -120,7 +120,7 @@ struct device_settings
char serialnr[128];
char softwvers[128];
int modelserie; // 1=DS1000, 2=DS2000, etc.
int hordivisions; // number of horizontal divisions
int hordivisions; // number of horizontal divisions, 12 or 14
int screentimerival;
@ -214,9 +214,12 @@ struct device_settings
int math_decode_uart_width; // databits, 5-8
int math_decode_uart_stop; // stopbits, 0=1, 1=1.5, 2=2
int math_decode_uart_par; // parity, 0=none, 1=odd, 2=even
int math_decode_uart_nval; // number of decoded characters
char math_decode_uart_val[DECODE_MAX_UART_CHARS]; // array with decoded characters
int math_decode_uart_val_pos[DECODE_MAX_UART_CHARS]; // array with position of the decoded characters
int math_decode_uart_tx_nval; // number of decoded characters
unsigned char math_decode_uart_tx_val[DECODE_MAX_UART_CHARS]; // array with decoded characters
int math_decode_uart_tx_val_pos[DECODE_MAX_UART_CHARS]; // array with position of the decoded characters
int math_decode_uart_rx_nval; // number of decoded characters
unsigned char math_decode_uart_rx_val[DECODE_MAX_UART_CHARS]; // array with decoded characters
int math_decode_uart_rx_val_pos[DECODE_MAX_UART_CHARS]; // array with position of the decoded characters
char *screenshot_buf;
short *wavebuf[MAX_CHNS];

Wyświetl plik

@ -32,14 +32,23 @@ void UI_Mainwindow::serial_decoder(void)
{
int i, j,
threshold[MAX_CHNS],
uart_sample_per_bit,
uart_start,
data_bit,
val=0;
y_range[MAX_CHNS],
uart_tx_start,
data_tx_bit,
uart_rx_start,
data_rx_bit;
unsigned int val=0;
short s_max, s_min;
devparms.math_decode_uart_nval = 0;
double uart_sample_per_bit,
uart_tx_x_pos,
uart_rx_x_pos;
devparms.math_decode_uart_tx_nval = 0;
devparms.math_decode_uart_rx_nval = 0;
if(devparms.wavebufsz < 32) return;
@ -56,6 +65,8 @@ void UI_Mainwindow::serial_decoder(void)
if(devparms.wavebuf[j][i] < s_min) s_min = devparms.wavebuf[j][i];
}
y_range[j] = s_max - s_min;
threshold[j] = (s_max + s_min) / 2;
}
}
@ -76,116 +87,246 @@ void UI_Mainwindow::serial_decoder(void)
if(devparms.math_decode_mode == DECODE_MODE_UART)
{
devparms.math_decode_uart_nval = 0;
devparms.math_decode_uart_tx_nval = 0;
devparms.math_decode_uart_rx_nval = 0;
if(devparms.timebasedelayenable)
{
uart_sample_per_bit = (100.0 / devparms.timebasedelayscale) / devparms.math_decode_uart_baud;
uart_sample_per_bit = (100.0 / devparms.timebasedelayscale) / (double)devparms.math_decode_uart_baud;
}
else
{
uart_sample_per_bit = (100.0 / devparms.timebasescale) / devparms.math_decode_uart_baud;
uart_sample_per_bit = (100.0 / devparms.timebasescale) / (double)devparms.math_decode_uart_baud;
}
if(uart_sample_per_bit < 8) return;
if(uart_sample_per_bit < 3) return;
uart_start = 0;
uart_tx_start = 0;
data_bit = 0;
data_tx_bit = 0;
uart_tx_x_pos = 1;
uart_rx_start = 0;
data_rx_bit = 0;
uart_rx_x_pos = 1;
if(devparms.math_decode_uart_tx)
{
for(i=1; i<devparms.wavebufsz; i++)
if(y_range[devparms.math_decode_uart_tx - 1] > 10) // don't try to decode if amplitude of signal is too low...
{
if(devparms.math_decode_uart_nval >= DECODE_MAX_UART_CHARS)
for(i=1; i<devparms.wavebufsz; i++)
{
break;
}
if(!uart_start)
{
if(devparms.math_decode_uart_pol)
if(devparms.math_decode_uart_tx_nval >= DECODE_MAX_UART_CHARS)
{
if(devparms.wavebuf[devparms.math_decode_uart_tx - 1][i-1] >= threshold[devparms.math_decode_uart_tx - 1])
break;
}
if(!uart_tx_start)
{
if(devparms.math_decode_uart_pol)
{
if(devparms.wavebuf[devparms.math_decode_uart_tx - 1][i] < threshold[devparms.math_decode_uart_tx - 1])
if(devparms.wavebuf[devparms.math_decode_uart_tx - 1][i-1] >= threshold[devparms.math_decode_uart_tx - 1])
{
uart_start = 1;
if(devparms.wavebuf[devparms.math_decode_uart_tx - 1][i] < threshold[devparms.math_decode_uart_tx - 1])
{
uart_tx_start = 1;
val = 0;
val = 0;
i += ((uart_sample_per_bit * 3) / 2) - 1;
uart_tx_x_pos = (uart_sample_per_bit * 1.5) + i;
i = uart_tx_x_pos - 1;
}
}
}
else
{
if(devparms.wavebuf[devparms.math_decode_uart_tx - 1][i-1] < threshold[devparms.math_decode_uart_tx - 1])
{
if(devparms.wavebuf[devparms.math_decode_uart_tx - 1][i] >= threshold[devparms.math_decode_uart_tx - 1])
{
uart_tx_start = 1;
val = 0;
uart_tx_x_pos = (uart_sample_per_bit * 1.5) + i;
i = uart_tx_x_pos - 1;
}
}
}
}
else
{
if(devparms.wavebuf[devparms.math_decode_uart_tx - 1][i-1] < threshold[devparms.math_decode_uart_tx - 1])
if(devparms.math_decode_uart_pol)
{
if(devparms.wavebuf[devparms.math_decode_uart_tx - 1][i] >= threshold[devparms.math_decode_uart_tx - 1])
{
uart_start = 1;
val = 0;
i += ((uart_sample_per_bit * 3) / 2) - 1;
val += (1 << data_tx_bit);
}
}
else
{
if(devparms.wavebuf[devparms.math_decode_uart_tx - 1][i] < threshold[devparms.math_decode_uart_tx - 1])
{
val += (1 << data_tx_bit);
}
}
if(++data_tx_bit == devparms.math_decode_uart_width)
{
if((devparms.math_decode_uart_end) && (devparms.math_decode_format != 4)) // little endian?
{
val = reverse_bitorder(val);
val >>= (8 - data_tx_bit);
}
devparms.math_decode_uart_tx_val[devparms.math_decode_uart_tx_nval] = val;
devparms.math_decode_uart_tx_val_pos[devparms.math_decode_uart_tx_nval++] = i - (data_tx_bit * uart_sample_per_bit);
data_tx_bit = 0;
uart_tx_start = 0;
uart_tx_x_pos += uart_sample_per_bit;
if(devparms.math_decode_uart_stop == 1)
{
uart_tx_x_pos += uart_sample_per_bit / 2;
}
else if(devparms.math_decode_uart_stop == 2)
{
uart_tx_x_pos += uart_sample_per_bit;
}
if(devparms.math_decode_uart_par)
{
uart_tx_x_pos += uart_sample_per_bit;
}
i = uart_tx_x_pos - 1;
}
else
{
uart_tx_x_pos += uart_sample_per_bit;
i = uart_tx_x_pos - 1;
}
}
}
else
}
}
if(devparms.math_decode_uart_rx)
{
if(y_range[devparms.math_decode_uart_rx - 1] > 10) // don't try to decode if amplitude of signal is too low...
{
for(i=1; i<devparms.wavebufsz; i++)
{
if(devparms.math_decode_uart_pol)
if(devparms.math_decode_uart_rx_nval >= DECODE_MAX_UART_CHARS)
{
if(devparms.wavebuf[devparms.math_decode_uart_tx - 1][i] >= threshold[devparms.math_decode_uart_tx - 1])
break;
}
if(!uart_rx_start)
{
if(devparms.math_decode_uart_pol)
{
val += (1 << data_bit);
if(devparms.wavebuf[devparms.math_decode_uart_rx - 1][i-1] >= threshold[devparms.math_decode_uart_rx - 1])
{
if(devparms.wavebuf[devparms.math_decode_uart_rx - 1][i] < threshold[devparms.math_decode_uart_rx - 1])
{
uart_rx_start = 1;
val = 0;
uart_rx_x_pos = (uart_sample_per_bit * 1.5) + i;
i = uart_rx_x_pos - 1;
}
}
}
else
{
if(devparms.wavebuf[devparms.math_decode_uart_rx - 1][i-1] < threshold[devparms.math_decode_uart_rx - 1])
{
if(devparms.wavebuf[devparms.math_decode_uart_rx - 1][i] >= threshold[devparms.math_decode_uart_rx - 1])
{
uart_rx_start = 1;
val = 0;
uart_rx_x_pos = (uart_sample_per_bit * 1.5) + i;
i = uart_rx_x_pos - 1;
}
}
}
}
else
{
if(devparms.wavebuf[devparms.math_decode_uart_tx - 1][i] < threshold[devparms.math_decode_uart_tx - 1])
if(devparms.math_decode_uart_pol)
{
val += (1 << data_bit);
}
}
if(++data_bit == devparms.math_decode_uart_width)
{
if(devparms.math_decode_uart_end)
{
val = reverse_bitorder(val);
val >>= (8 - data_bit);
}
devparms.math_decode_uart_val[devparms.math_decode_uart_nval] = val;
devparms.math_decode_uart_val_pos[devparms.math_decode_uart_nval++] = i - (data_bit * uart_sample_per_bit);
data_bit = 0;
uart_start = 0;
i += uart_sample_per_bit - 1;
if(devparms.math_decode_uart_stop == 1)
{
i += uart_sample_per_bit / 2;
}
else if(devparms.math_decode_uart_stop == 2)
if(devparms.wavebuf[devparms.math_decode_uart_rx - 1][i] >= threshold[devparms.math_decode_uart_rx - 1])
{
i += uart_sample_per_bit;
val += (1 << data_rx_bit);
}
}
else
{
if(devparms.wavebuf[devparms.math_decode_uart_rx - 1][i] < threshold[devparms.math_decode_uart_rx - 1])
{
val += (1 << data_rx_bit);
}
}
if(++data_rx_bit == devparms.math_decode_uart_width)
{
if((devparms.math_decode_uart_end) && (devparms.math_decode_format != 4)) // little endian?
{
val = reverse_bitorder(val);
val >>= (8 - data_rx_bit);
}
if(devparms.math_decode_uart_par)
{
i += uart_sample_per_bit;
devparms.math_decode_uart_rx_val[devparms.math_decode_uart_rx_nval] = val;
devparms.math_decode_uart_rx_val_pos[devparms.math_decode_uart_rx_nval++] = i - (data_rx_bit * uart_sample_per_bit);
data_rx_bit = 0;
uart_rx_start = 0;
uart_rx_x_pos += uart_sample_per_bit;
if(devparms.math_decode_uart_stop == 1)
{
uart_rx_x_pos += uart_sample_per_bit / 2;
}
else if(devparms.math_decode_uart_stop == 2)
{
uart_rx_x_pos += uart_sample_per_bit;
}
if(devparms.math_decode_uart_par)
{
uart_rx_x_pos += uart_sample_per_bit;
}
i = uart_rx_x_pos - 1;
}
else
{
uart_rx_x_pos += uart_sample_per_bit;
i = uart_rx_x_pos - 1;
}
}
else
{
i += uart_sample_per_bit - 1;
}
}
}

Wyświetl plik

@ -2255,75 +2255,194 @@ bool SignalCurve::hasMoveEvent(void)
void SignalCurve::draw_decoder(QPainter *painter, int dw, int dh)
{
int i, j, line_h;
int i, j,
cell_width,
base_line,
line_h_uart_tx=0,
line_h_uart_rx=0;
double pix_per_smpl;
char str[256];
line_h = ((double)dh / 400.0) * devparms->math_decode_pos;
base_line = ((double)dh / 400.0) * devparms->math_decode_pos;
pix_per_smpl = (double)dw / (devparms->hordivisions * 100.0);
painter->setPen(Qt::green);
painter->drawLine(0, line_h, dw, line_h);
if(devparms->math_decode_mode == DECODE_MODE_UART)
switch(devparms->math_decode_format)
{
for(i=0; i<devparms->math_decode_uart_nval; i++)
{
painter->fillRect(devparms->math_decode_uart_val_pos[i] * pix_per_smpl, line_h - 13, 70, 26, Qt::black);
painter->drawRect(devparms->math_decode_uart_val_pos[i] * pix_per_smpl, line_h - 13, 70, 26);
}
case 0: cell_width = 40; // hex
break;
case 1: cell_width = 30; // ASCII
break;
case 2: cell_width = 30; // decimal;
break;
case 3: cell_width = 70; // binary
break;
default: cell_width = 70; // line
break;
}
painter->setPen(Qt::white);
if(devparms->math_decode_mode == DECODE_MODE_UART)
{
for(i=0; i<devparms->math_decode_uart_nval; i++)
painter->setPen(Qt::green);
if(devparms->math_decode_uart_tx && devparms->math_decode_uart_rx)
{
if(devparms->math_decode_format == 0) // hex
line_h_uart_tx = base_line - 5;
line_h_uart_rx = base_line + 45;
painter->drawLine(0, line_h_uart_tx, dw, line_h_uart_tx);
painter->drawLine(0, line_h_uart_rx, dw, line_h_uart_rx);
}
else if(devparms->math_decode_uart_tx)
{
sprintf(str, "0x%02X", devparms->math_decode_uart_val[i]);
line_h_uart_tx = base_line;
painter->drawText(devparms->math_decode_uart_val_pos[i] * pix_per_smpl, line_h - 13, 70, 30, Qt::AlignCenter, str);
painter->drawLine(0, line_h_uart_tx, dw, line_h_uart_tx);
}
else if(devparms->math_decode_format == 1) // ASCII
else if(devparms->math_decode_uart_rx)
{
str[0]= devparms->math_decode_uart_val[i];
line_h_uart_rx = base_line;
if(str[0] < 32) str[0] = '.';
str[1] = 0;
painter->drawText(devparms->math_decode_uart_val_pos[i] * pix_per_smpl, line_h - 13, 70, 30, Qt::AlignCenter, str);
painter->drawLine(0, line_h_uart_rx, dw, line_h_uart_rx);
}
else if(devparms->math_decode_format == 2) // decimal
if(devparms->math_decode_uart_tx)
{
for(i=0; i<devparms->math_decode_uart_tx_nval; i++)
{
painter->fillRect(devparms->math_decode_uart_tx_val_pos[i] * pix_per_smpl, line_h_uart_tx - 13, cell_width, 26, Qt::black);
painter->drawRect(devparms->math_decode_uart_tx_val_pos[i] * pix_per_smpl, line_h_uart_tx - 13, cell_width, 26);
}
}
if(devparms->math_decode_uart_rx)
{
for(i=0; i<devparms->math_decode_uart_rx_nval; i++)
{
painter->fillRect(devparms->math_decode_uart_rx_val_pos[i] * pix_per_smpl, line_h_uart_rx - 13, cell_width, 26, Qt::black);
painter->drawRect(devparms->math_decode_uart_rx_val_pos[i] * pix_per_smpl, line_h_uart_rx - 13, cell_width, 26);
}
}
painter->setPen(Qt::white);
if(devparms->math_decode_uart_tx)
{
painter->drawText(5, line_h_uart_tx - 35, 25, 30, Qt::AlignCenter, "TX");
for(i=0; i<devparms->math_decode_uart_tx_nval; i++)
{
if(devparms->math_decode_format == 0) // hex
{
sprintf(str, "0x%02X", devparms->math_decode_uart_tx_val[i]);
painter->drawText(devparms->math_decode_uart_tx_val_pos[i] * pix_per_smpl, line_h_uart_tx - 13, cell_width, 30, Qt::AlignCenter, str);
}
else if(devparms->math_decode_format == 1) // ASCII
{
sprintf(str, "%u", (unsigned int)devparms->math_decode_uart_val[i]);
str[0]= devparms->math_decode_uart_tx_val[i];
painter->drawText(devparms->math_decode_uart_val_pos[i] * pix_per_smpl, line_h - 13, 70, 30, Qt::AlignCenter, str);
if(str[0] < 32) str[0] = '.';
str[1] = 0;
painter->drawText(devparms->math_decode_uart_tx_val_pos[i] * pix_per_smpl, line_h_uart_tx - 13, cell_width, 30, Qt::AlignCenter, str);
}
else if(devparms->math_decode_format == 3) // binary
else if(devparms->math_decode_format == 2) // decimal
{
sprintf(str, "%u", (unsigned int)devparms->math_decode_uart_val[i]);
sprintf(str, "%u", (unsigned int)devparms->math_decode_uart_tx_val[i]);
str[0] = '0';
str[1] = 'b';
for(j=7; j>=0; j--)
{
str[9-j] = ((((unsigned char *)devparms->math_decode_uart_val)[i] >> j) & 1) + '0';
}
str[10] = 0;
painter->drawText(devparms->math_decode_uart_val_pos[i] * pix_per_smpl, line_h - 13, 70, 30, Qt::AlignCenter, str);
painter->drawText(devparms->math_decode_uart_tx_val_pos[i] * pix_per_smpl, line_h_uart_tx - 13, cell_width, 30, Qt::AlignCenter, str);
}
else if(devparms->math_decode_format == 3) // binary
{
str[0] = '0';
str[1] = 'b';
for(j=7; j>=0; j--)
{
str[9-j] = ((devparms->math_decode_uart_tx_val[i] >> j) & 1) + '0';
}
str[10] = 0;
painter->drawText(devparms->math_decode_uart_tx_val_pos[i] * pix_per_smpl, line_h_uart_tx - 13, cell_width, 30, Qt::AlignCenter, str);
}
else if(devparms->math_decode_format == 4) // line
{
for(j=0; j<8; j++)
{
str[j] = ((devparms->math_decode_uart_rx_val[i] >> j) & 1) + '0';
}
str[8] = 0;
painter->drawText(devparms->math_decode_uart_tx_val_pos[i] * pix_per_smpl, line_h_uart_tx - 13, cell_width, 30, Qt::AlignCenter, str);
}
}
}
if(devparms->math_decode_uart_rx)
{
painter->drawText(5, line_h_uart_rx - 35, 25, 30, Qt::AlignCenter, "RX");
for(i=0; i<devparms->math_decode_uart_rx_nval; i++)
{
if(devparms->math_decode_format == 0) // hex
{
sprintf(str, "0x%02X", devparms->math_decode_uart_rx_val[i]);
painter->drawText(devparms->math_decode_uart_rx_val_pos[i] * pix_per_smpl, line_h_uart_rx - 13, cell_width, 30, Qt::AlignCenter, str);
}
else if(devparms->math_decode_format == 1) // ASCII
{
str[0]= devparms->math_decode_uart_rx_val[i];
if(str[0] < 32) str[0] = '.';
str[1] = 0;
painter->drawText(devparms->math_decode_uart_rx_val_pos[i] * pix_per_smpl, line_h_uart_rx - 13, cell_width, 30, Qt::AlignCenter, str);
}
else if(devparms->math_decode_format == 2) // decimal
{
sprintf(str, "%u", (unsigned int)devparms->math_decode_uart_rx_val[i]);
painter->drawText(devparms->math_decode_uart_rx_val_pos[i] * pix_per_smpl, line_h_uart_rx - 13, cell_width, 30, Qt::AlignCenter, str);
}
else if(devparms->math_decode_format == 3) // binary
{
str[0] = '0';
str[1] = 'b';
for(j=7; j>=0; j--)
{
str[9-j] = ((devparms->math_decode_uart_rx_val[i] >> j) & 1) + '0';
}
str[10] = 0;
painter->drawText(devparms->math_decode_uart_rx_val_pos[i] * pix_per_smpl, line_h_uart_rx - 13, cell_width, 30, Qt::AlignCenter, str);
}
else if(devparms->math_decode_format == 4) // line
{
for(j=0; j<8; j++)
{
str[j] = ((devparms->math_decode_uart_rx_val[i] >> j) & 1) + '0';
}
str[8] = 0;
painter->drawText(devparms->math_decode_uart_rx_val_pos[i] * pix_per_smpl, line_h_uart_rx - 13, cell_width, 30, Qt::AlignCenter, str);
}
}
}
}
}