mirror of
https://github.com/DreamSourceLab/DSView.git
synced 2026-07-28 04:35:29 +00:00
fix: The disabled channel used another channel's data on analog mode
This commit is contained in:
@@ -45,7 +45,7 @@ AnalogSnapshot::AnalogSnapshot() :
|
||||
{
|
||||
memset(_envelope_levels, 0, sizeof(_envelope_levels));
|
||||
_unit_pitch = 0;
|
||||
_data = NULL;
|
||||
_data = NULL;
|
||||
}
|
||||
|
||||
AnalogSnapshot::~AnalogSnapshot()
|
||||
@@ -75,7 +75,7 @@ void AnalogSnapshot::init_all()
|
||||
_sample_count = 0;
|
||||
_ring_sample_count = 0;
|
||||
_memory_failed = false;
|
||||
_last_ended = true;
|
||||
_last_ended = true;
|
||||
|
||||
for (unsigned int i = 0; i < _channel_num; i++) {
|
||||
for (unsigned int level = 0; level < ScaleStepCount; level++) {
|
||||
@@ -112,10 +112,12 @@ void AnalogSnapshot::first_payload(const sr_datafeed_analog &analog, uint64_t to
|
||||
_unit_bytes = (analog.unit_bits + 7) / 8;
|
||||
assert(_unit_bytes > 0);
|
||||
assert(_unit_bytes <= sizeof(uint64_t));
|
||||
_channel_num = 0;
|
||||
|
||||
_channel_num = 0; // The enabled and disabled channels count.
|
||||
|
||||
for (const GSList *l = channels; l; l = l->next) {
|
||||
sr_channel *const probe = (sr_channel*)l->data;
|
||||
assert(probe);
|
||||
|
||||
// TODO: data of disabled channels should not be captured.
|
||||
if (probe->type == SR_CHANNEL_ANALOG) {
|
||||
_channel_num ++;
|
||||
@@ -124,54 +126,70 @@ void AnalogSnapshot::first_payload(const sr_datafeed_analog &analog, uint64_t to
|
||||
|
||||
bool isOk = true;
|
||||
uint64_t size = _total_sample_count * _channel_num * _unit_bytes + sizeof(uint64_t);
|
||||
|
||||
if (size != _capacity) {
|
||||
free_data();
|
||||
_data = malloc(size);
|
||||
|
||||
if (_data) {
|
||||
free_envelop();
|
||||
|
||||
for (unsigned int i = 0; i < _channel_num; i++) {
|
||||
uint64_t envelop_count = _total_sample_count / EnvelopeScaleFactor;
|
||||
for (unsigned int level = 0; level < ScaleStepCount; level++) {
|
||||
_envelope_levels[i][level].count = envelop_count;
|
||||
|
||||
if (envelop_count == 0)
|
||||
break;
|
||||
|
||||
_envelope_levels[i][level].samples = (EnvelopeSample*)malloc(envelop_count * sizeof(EnvelopeSample));
|
||||
|
||||
if (!_envelope_levels[i][level].samples) {
|
||||
isOk = false;
|
||||
break;
|
||||
}
|
||||
|
||||
envelop_count = envelop_count / EnvelopeScaleFactor;
|
||||
}
|
||||
if (!isOk)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
isOk = true;
|
||||
}
|
||||
else {
|
||||
isOk = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isOk) {
|
||||
_ch_index.clear();
|
||||
_enabled_channel_indexs.clear();
|
||||
|
||||
for (const GSList *l = channels; l; l = l->next) {
|
||||
sr_channel *const probe = (sr_channel*)l->data;
|
||||
assert(probe);
|
||||
// TODO: data of disabled channels should not be captured.
|
||||
|
||||
// TODO: get the enabled channel index.
|
||||
if (probe->type == SR_CHANNEL_ANALOG) {
|
||||
_ch_index.push_back(probe->index);
|
||||
|
||||
if (probe->enabled){
|
||||
_enabled_channel_indexs.push_back(probe->index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_capacity = size;
|
||||
_memory_failed = false;
|
||||
append_payload(analog);
|
||||
_last_ended = false;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
free_data();
|
||||
free_envelop();
|
||||
_memory_failed = true;
|
||||
}
|
||||
}
|
||||
|
||||
void AnalogSnapshot::append_payload(
|
||||
const sr_datafeed_analog &analog)
|
||||
void AnalogSnapshot::append_payload(const sr_datafeed_analog &analog)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
append_data(analog.data, analog.num_samples, analog.unit_pitch);
|
||||
@@ -202,7 +220,8 @@ void AnalogSnapshot::append_data(void *data, uint64_t samples, uint16_t pitch)
|
||||
data, samples * bytes_per_sample);
|
||||
_ring_sample_count += samples;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
while(samples--) {
|
||||
if (_unit_pitch == 0) {
|
||||
if (_sample_count < _total_sample_count)
|
||||
@@ -370,7 +389,7 @@ int AnalogSnapshot::get_scale_factor()
|
||||
|
||||
bool AnalogSnapshot::has_data(int index)
|
||||
{
|
||||
for (auto& iter:_ch_index) {
|
||||
for (int iter : _ch_index) {
|
||||
if (iter == index)
|
||||
return true;
|
||||
}
|
||||
@@ -399,9 +418,20 @@ uint64_t AnalogSnapshot::get_block_size(int block_index)
|
||||
}
|
||||
}
|
||||
|
||||
void* AnalogSnapshot::get_data(){
|
||||
void* AnalogSnapshot::get_data()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
bool AnalogSnapshot::has_enabled_channel(int index)
|
||||
{
|
||||
|
||||
for (int iter : _enabled_channel_indexs) {
|
||||
if (iter == index)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace data
|
||||
} // namespace pv
|
||||
|
||||
@@ -109,6 +109,8 @@ public:
|
||||
|
||||
void* get_data();
|
||||
|
||||
bool has_enabled_channel(int index);
|
||||
|
||||
private:
|
||||
void append_data(void *data, uint64_t samples, uint16_t pitch);
|
||||
void free_envelop();
|
||||
@@ -119,7 +121,8 @@ private:
|
||||
private:
|
||||
void *_data;
|
||||
struct Envelope _envelope_levels[DS_MAX_ANALOG_PROBES_NUM][ScaleStepCount];
|
||||
friend class AnalogSnapshotTest::Basic;
|
||||
friend class AnalogSnapshotTest::Basic;
|
||||
std::vector<int> _enabled_channel_indexs;
|
||||
};
|
||||
|
||||
} // namespace data
|
||||
|
||||
@@ -974,11 +974,12 @@ void StoreSession::export_proc(data::Snapshot *snapshot)
|
||||
|
||||
} else if (channel_type == SR_CHANNEL_ANALOG) {
|
||||
_unit_count = snapshot->get_sample_count();
|
||||
unsigned char* datat = (unsigned char*)analog_snapshot->get_data();
|
||||
void* data_buffer = analog_snapshot->get_data();
|
||||
unsigned int usize = 8192;
|
||||
unsigned int size = usize;
|
||||
struct sr_datafeed_analog ap;
|
||||
uint64_t unit_count = _unit_count;
|
||||
unsigned char* read_buf = (unsigned char*)data_buffer;
|
||||
|
||||
int ch_count = snapshot->get_channel_num();
|
||||
uint64_t i = 0;
|
||||
@@ -991,7 +992,7 @@ void StoreSession::export_proc(data::Snapshot *snapshot)
|
||||
if(unit_count - i < usize)
|
||||
size = unit_count - i;
|
||||
|
||||
ap.data = &datat[i*ch_count];
|
||||
ap.data = (unsigned char*)data_buffer + i * ch_count;
|
||||
ap.num_samples = size;
|
||||
p.type = SR_DF_ANALOG;
|
||||
p.status = SR_PKT_OK;
|
||||
|
||||
@@ -407,8 +407,6 @@ void AnalogSignal::paint_mid(QPainter &p, int left, int right, QColor fore, QCol
|
||||
const float zeroY = ratio2pos(get_zero_ratio());
|
||||
const int width = right - left + 1;
|
||||
|
||||
// dsv_info("zeroY:%f", zeroY);
|
||||
|
||||
const double scale = _view->scale();
|
||||
|
||||
assert(scale > 0);
|
||||
@@ -418,6 +416,11 @@ void AnalogSignal::paint_mid(QPainter &p, int left, int right, QColor fore, QCol
|
||||
if (order == -1)
|
||||
return;
|
||||
|
||||
//The channel have no data.
|
||||
if (_data->has_enabled_channel(get_index()) == false){
|
||||
return;
|
||||
}
|
||||
|
||||
const double pixels_offset = offset;
|
||||
const double samplerate = _data->samplerate();
|
||||
const int64_t cur_sample_count = _data->get_sample_count();
|
||||
@@ -493,20 +496,27 @@ void AnalogSignal::paint_trace(QPainter &p,
|
||||
const int hw_offset = get_hw_offset();
|
||||
float x = start_pixel;
|
||||
double pixels_per_sample = 1.0/samples_per_pixel;
|
||||
|
||||
for (int64_t sample = 0; sample < sample_count; sample++) {
|
||||
uint64_t index = (yindex * channel_num + order) * unit_bytes;
|
||||
float yvalue = samples[index];
|
||||
for(uint8_t i = 1; i < unit_bytes; i++)
|
||||
|
||||
for(uint8_t i = 1; i < unit_bytes; i++){
|
||||
yvalue += (samples[++index] << i*8);
|
||||
}
|
||||
|
||||
yvalue = zeroY + (yvalue - hw_offset) * _scale;
|
||||
yvalue = min(max(yvalue, top), bottom);
|
||||
*point++ = QPointF(x, yvalue);
|
||||
|
||||
if (yindex == pshot->get_ring_end())
|
||||
break;
|
||||
|
||||
yindex++;
|
||||
yindex %= pshot->get_sample_count();
|
||||
x += pixels_per_sample;
|
||||
}
|
||||
|
||||
p.drawPolyline(points, point - points);
|
||||
delete[] points;
|
||||
}
|
||||
|
||||
@@ -1261,6 +1261,13 @@ void DsoSignal::paint_hover_measure(QPainter &p, QColor fore, QColor back)
|
||||
// Hover measure
|
||||
if (_hover_en && _hover_point != QPointF(-1, -1)) {
|
||||
QString hover_str = get_voltage(hw_offset - _hover_value, 2);
|
||||
|
||||
//vf = (hw_offset - (double)(*p)) * mapRange / max_min_ref;
|
||||
//v = v * data_scale * k * _vDial->get_factor() * DS_CONF_DSO_VDIVS / get_view_rect().height();
|
||||
|
||||
// dsv_info("c:%d, hw_offset:%d",
|
||||
// hw_offset - _hover_value, hw_offset);
|
||||
|
||||
const int hover_width = p.boundingRect(0, 0, INT_MAX, INT_MAX,
|
||||
Qt::AlignLeft | Qt::AlignTop, hover_str).width() + 10;
|
||||
const int hover_height = p.boundingRect(0, 0, INT_MAX, INT_MAX,
|
||||
|
||||
@@ -305,6 +305,9 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
|
||||
int ch_cfg_dex = 0;
|
||||
double hw_offset = 0;
|
||||
double mapRange = 0;
|
||||
double mmax = 0;
|
||||
double mmin = 0;
|
||||
void *ptr;
|
||||
|
||||
for (i = 0; i < (uint64_t)analog->num_samples; i++) {
|
||||
ch_cfg_dex = 0;
|
||||
@@ -321,9 +324,12 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
|
||||
continue;
|
||||
}
|
||||
|
||||
p = analog->data + i * ch_num + j;
|
||||
ptr = (unsigned char*)analog->data + i * ch_num + j;
|
||||
p = (unsigned char*)ptr;
|
||||
hw_offset = (double)ctx->channel_offset[ch_cfg_dex];
|
||||
mapRange = (ctx->channel_mmax[ch_cfg_dex] - ctx->channel_mmin[ch_cfg_dex]);
|
||||
mmax = ctx->channel_mmax[ch_cfg_dex];
|
||||
mmin = ctx->channel_mmin[ch_cfg_dex];
|
||||
mapRange = (mmax - mmin);
|
||||
vf = (hw_offset - (double)(*p)) * mapRange / max_min_ref;
|
||||
|
||||
g_string_append_printf(*out, "%0.5f", vf);
|
||||
|
||||
Reference in New Issue
Block a user