finally working
This commit is contained in:
66
main.cpp
66
main.cpp
@ -1513,8 +1513,7 @@ struct Do1PairSubtractAverageState {
|
||||
double pending_ch1_raw = 0.0;
|
||||
bool pending_ch1_di1_high = false;
|
||||
bool pending_ch1_di2_high = false;
|
||||
bool pending_ch1_di8_settled_high = false;
|
||||
bool pending_ch1_di8_in_guard = false;
|
||||
bool pending_ch1_di8_high = false; // raw DI8 level (not guard-filtered)
|
||||
|
||||
uint16_t next_index = 1;
|
||||
|
||||
@ -1531,8 +1530,7 @@ struct Do1PairSubtractAverageState {
|
||||
pending_ch1_raw = 0.0;
|
||||
pending_ch1_di1_high = false;
|
||||
pending_ch1_di2_high = false;
|
||||
pending_ch1_di8_settled_high = false;
|
||||
pending_ch1_di8_in_guard = false;
|
||||
pending_ch1_di8_high = false;
|
||||
}
|
||||
|
||||
void reset_packet() {
|
||||
@ -1555,13 +1553,12 @@ struct Do1PairSubtractAverageState {
|
||||
}
|
||||
|
||||
void add_pending_ch1(double raw_code, bool di1_high, bool di2_high,
|
||||
bool di8_settled_high = false, bool di8_in_guard = false) {
|
||||
bool di8_high_level = false) {
|
||||
pending_ch1_valid = true;
|
||||
pending_ch1_raw = raw_code;
|
||||
pending_ch1_di1_high = di1_high;
|
||||
pending_ch1_di2_high = di2_high;
|
||||
pending_ch1_di8_settled_high = di8_settled_high;
|
||||
pending_ch1_di8_in_guard = di8_in_guard;
|
||||
pending_ch1_di8_high = di8_high_level;
|
||||
}
|
||||
|
||||
void add_pair_sample(bool di2_high, double ch1_value, double ch2_value) {
|
||||
@ -2212,6 +2209,13 @@ int run(const Config& cfg) {
|
||||
uint64_t packet_di2_low_clocks = 0;
|
||||
uint64_t packet_di8_high_clocks = 0;
|
||||
uint64_t packet_di8_low_clocks = 0;
|
||||
uint64_t packet_di8_samples_accumulated = 0;
|
||||
uint64_t packet_di8_ref_frames_emitted = 0;
|
||||
uint64_t packet_di8_no_complete = 0;
|
||||
uint64_t packet_di8_no_standard = 0;
|
||||
uint64_t packet_di8_both_high = 0;
|
||||
uint64_t packet_di8_both_normal = 0;
|
||||
uint64_t packet_di8_mixed = 0;
|
||||
|
||||
bool capture_started = false;
|
||||
bool stop_loop_requested = false;
|
||||
@ -2464,6 +2468,7 @@ int run(const Config& cfg) {
|
||||
return;
|
||||
}
|
||||
if (!tty_di8_state.has_complete_step(cfg.channel_count)) {
|
||||
++packet_di8_no_complete;
|
||||
tty_di8_state.clear_step();
|
||||
return;
|
||||
}
|
||||
@ -2484,6 +2489,7 @@ int run(const Config& cfg) {
|
||||
}
|
||||
|
||||
if (!tty_di8_state.last_standard_valid) {
|
||||
++packet_di8_no_standard;
|
||||
tty_di8_state.clear_step();
|
||||
return;
|
||||
}
|
||||
@ -2492,6 +2498,7 @@ int run(const Config& cfg) {
|
||||
tty_di8_state.last_standard_index,
|
||||
static_cast<uint16_t>(pack_raw_code_to_int16(ch1_avg)),
|
||||
static_cast<uint16_t>(pack_raw_code_to_int16(ch2_avg)));
|
||||
++packet_di8_ref_frames_emitted;
|
||||
tty_di8_state.clear_step();
|
||||
};
|
||||
|
||||
@ -2521,6 +2528,13 @@ int run(const Config& cfg) {
|
||||
packet_di2_low_clocks = 0;
|
||||
packet_di8_high_clocks = 0;
|
||||
packet_di8_low_clocks = 0;
|
||||
packet_di8_samples_accumulated = 0;
|
||||
packet_di8_ref_frames_emitted = 0;
|
||||
packet_di8_no_complete = 0;
|
||||
packet_di8_no_standard = 0;
|
||||
packet_di8_both_high = 0;
|
||||
packet_di8_both_normal = 0;
|
||||
packet_di8_mixed = 0;
|
||||
if (!fast_tty_avg_stream_mode) {
|
||||
current_packet.reset(target_frames, cfg.channel_count);
|
||||
}
|
||||
@ -2591,7 +2605,14 @@ int run(const Config& cfg) {
|
||||
<< ", di2_low_clocks=" << packet_di2_low_clocks;
|
||||
if (cfg.do8_freq_ref) {
|
||||
std::cout << ", di8_high_clocks=" << packet_di8_high_clocks
|
||||
<< ", di8_low_clocks=" << packet_di8_low_clocks;
|
||||
<< ", di8_low_clocks=" << packet_di8_low_clocks
|
||||
<< ", di8_pairs=" << packet_di8_samples_accumulated
|
||||
<< ", di8_ref_frames=" << packet_di8_ref_frames_emitted
|
||||
<< ", di8_no_complete=" << packet_di8_no_complete
|
||||
<< ", di8_no_std=" << packet_di8_no_standard
|
||||
<< ", di8_hi=" << packet_di8_both_high
|
||||
<< ", di8_lo=" << packet_di8_both_normal
|
||||
<< ", di8_mix=" << packet_di8_mixed;
|
||||
}
|
||||
std::cout << ", avg_steps=" << packet_avg_steps
|
||||
<< "\n";
|
||||
@ -2695,6 +2716,13 @@ int run(const Config& cfg) {
|
||||
packet_di2_low_clocks = 0;
|
||||
packet_di8_high_clocks = 0;
|
||||
packet_di8_low_clocks = 0;
|
||||
packet_di8_samples_accumulated = 0;
|
||||
packet_di8_ref_frames_emitted = 0;
|
||||
packet_di8_no_complete = 0;
|
||||
packet_di8_no_standard = 0;
|
||||
packet_di8_both_high = 0;
|
||||
packet_di8_both_normal = 0;
|
||||
packet_di8_mixed = 0;
|
||||
if (!fast_tty_avg_stream_mode) {
|
||||
current_packet.reset(target_frames, cfg.channel_count);
|
||||
}
|
||||
@ -3016,27 +3044,30 @@ int run(const Config& cfg) {
|
||||
if (tty_do1_pair_subtract_avg) {
|
||||
if (lch == 0U) {
|
||||
tty_do1_pair_state.add_pending_ch1(adc_raw_value, di1_level, di2_level,
|
||||
di8_settled_high, di8_in_guard);
|
||||
di8_level);
|
||||
} else if (lch == 1U) {
|
||||
if (tty_do1_pair_state.pending_ch1_valid) {
|
||||
const bool pair_di1_matches =
|
||||
(tty_do1_pair_state.pending_ch1_di1_high == di1_level);
|
||||
const bool pair_di2_matches =
|
||||
(tty_do1_pair_state.pending_ch1_di2_high == di2_level);
|
||||
const bool either_di8_guard =
|
||||
tty_do1_pair_state.pending_ch1_di8_in_guard || di8_in_guard;
|
||||
// Use raw DI8 level for pair matching (not guard-filtered).
|
||||
// Guard-based filtering consumed ALL settled HIGH samples
|
||||
// due to per-DIN-sample guard counting vs per-DOUT-tick transitions.
|
||||
// Mixed-level pairs (transition boundaries) are still discarded.
|
||||
const bool both_di8_high =
|
||||
tty_do1_pair_state.pending_ch1_di8_settled_high && di8_settled_high;
|
||||
tty_do1_pair_state.pending_ch1_di8_high && di8_level;
|
||||
const bool both_di8_normal =
|
||||
!tty_do1_pair_state.pending_ch1_di8_settled_high &&
|
||||
!tty_do1_pair_state.pending_ch1_di8_in_guard &&
|
||||
!di8_settled_high && !di8_in_guard;
|
||||
!tty_do1_pair_state.pending_ch1_di8_high && !di8_level;
|
||||
|
||||
if (pair_di1_matches && pair_di2_matches && !either_di8_guard) {
|
||||
if (pair_di1_matches && pair_di2_matches) {
|
||||
if (both_di8_high) {
|
||||
tty_di8_state.add_sample(0U, tty_do1_pair_state.pending_ch1_raw);
|
||||
tty_di8_state.add_sample(1U, adc_raw_value);
|
||||
++packet_di8_samples_accumulated;
|
||||
++packet_di8_both_high;
|
||||
} else if (both_di8_normal) {
|
||||
++packet_di8_both_normal;
|
||||
if (!tty_do1_pair_state.run_initialized) {
|
||||
tty_do1_pair_state.start_run(di1_level);
|
||||
} else if (tty_do1_pair_state.run_di1_high != di1_level) {
|
||||
@ -3048,8 +3079,9 @@ int run(const Config& cfg) {
|
||||
tty_do1_pair_state.add_pair_sample(di2_level,
|
||||
tty_do1_pair_state.pending_ch1_raw,
|
||||
adc_raw_value);
|
||||
} else {
|
||||
++packet_di8_mixed; // mixed DI8 pair -- discard
|
||||
}
|
||||
// else: mixed DI8 state pair -- discard
|
||||
}
|
||||
}
|
||||
tty_do1_pair_state.clear_pending_ch1();
|
||||
|
||||
Reference in New Issue
Block a user