kopia lustrzana https://github.com/xdsopl/robot36
simplified calibration header detection: ignore leader tone
just rely on start bitpull/6/head
rodzic
fc6f434885
commit
be8a372034
|
@ -20,81 +20,52 @@ limitations under the License.
|
|||
#include "constants.rsh"
|
||||
#include "state.rsh"
|
||||
|
||||
static int calibration_detected(float dat_quantized, int cnt_quantized)
|
||||
static int calibration_detected(int cnt_quantized)
|
||||
{
|
||||
static int progress, countdown;
|
||||
static int leader_counter, break_counter;
|
||||
static int ssb_counter;
|
||||
int ssb_level = cnt_quantized == 0;
|
||||
int ssb_pulse = !ssb_level && ssb_counter >= ssb_length;
|
||||
ssb_counter = ssb_level ? ssb_counter + 1 : 0;
|
||||
|
||||
progress = countdown ? progress : 0;
|
||||
countdown -= !!countdown;
|
||||
static int bit_pos, vis_pos, vis_code;
|
||||
static int vis_counter, bit_counter;
|
||||
|
||||
int leader_level = dat_quantized == 0;
|
||||
int leader_pulse = !leader_level && leader_counter >= leader_length;
|
||||
leader_counter = leader_level ? leader_counter + 1 : 0;
|
||||
if (leader_pulse) {
|
||||
if (progress == 2) {
|
||||
progress = 3;
|
||||
countdown = vis_timeout;
|
||||
leader_length = first_leader_length;
|
||||
} else {
|
||||
progress = 1;
|
||||
countdown = break_timeout;
|
||||
leader_length = second_leader_length;
|
||||
}
|
||||
if (ssb_pulse) {
|
||||
vis_code = 0;
|
||||
bit_pos = 0;
|
||||
vis_pos = 2 * bit_length;
|
||||
bit_counter = 0;
|
||||
vis_counter = bit_length;
|
||||
}
|
||||
|
||||
int break_level = cnt_quantized == 0;
|
||||
int break_pulse = !break_level && break_counter >= break_length;
|
||||
break_counter = break_level ? break_counter + 1 : 0;
|
||||
if (break_pulse) {
|
||||
if (progress == 1) {
|
||||
progress = 2;
|
||||
countdown = leader_timeout;
|
||||
} else if (progress < 3) {
|
||||
progress = 0;
|
||||
leader_length = first_leader_length;
|
||||
}
|
||||
if (bit_pos >= 8)
|
||||
return -1;
|
||||
|
||||
if (++vis_counter < vis_pos) {
|
||||
bit_counter += cnt_quantized;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (progress == 3) {
|
||||
static int bit_pos, vis_pos, vis_code;
|
||||
static int vis_counter, bit_counter;
|
||||
if (leader_pulse) {
|
||||
bit_pos = 0;
|
||||
vis_pos = bit_length;
|
||||
bit_counter = 0;
|
||||
vis_counter = 0;
|
||||
}
|
||||
if (++vis_counter < vis_pos) {
|
||||
bit_counter += cnt_quantized;
|
||||
} else {
|
||||
if (bit_pos == 0 && 2 * abs(bit_counter) < bit_length) {
|
||||
vis_code = 0;
|
||||
} else if (0 < bit_pos && bit_pos < 9 && 2 * abs(bit_counter) > bit_length) {
|
||||
int bit_val = bit_counter < 0 ? 1 : 0;
|
||||
vis_code |= bit_val << (bit_pos - 1);
|
||||
} else if (bit_pos == 9 /* && 2 * abs(bit_counter) < bit_length */) {
|
||||
progress = 0;
|
||||
countdown = 0;
|
||||
//RS_DEBUG(vis_code);
|
||||
return vis_code;
|
||||
} else {
|
||||
progress = 0;
|
||||
countdown = 0;
|
||||
return -1;
|
||||
}
|
||||
++bit_pos;
|
||||
bit_counter = cnt_quantized;
|
||||
vis_pos += bit_length;
|
||||
}
|
||||
if (2 * abs(bit_counter) < bit_length) {
|
||||
bit_pos = 8;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
int bit_val = bit_counter < 0 ? 1 : 0;
|
||||
bit_counter = cnt_quantized;
|
||||
vis_code |= bit_val << bit_pos;
|
||||
vis_pos += bit_length;
|
||||
|
||||
if (++bit_pos < 8)
|
||||
return -1;
|
||||
|
||||
//RS_DEBUG(vis_code);
|
||||
return vis_code;
|
||||
}
|
||||
|
||||
static int calibration_detector(int dat_quantized, int cnt_quantized)
|
||||
static int calibration_detector(int cnt_quantized)
|
||||
{
|
||||
switch (calibration_detected(dat_quantized, cnt_quantized)) {
|
||||
switch (calibration_detected(cnt_quantized)) {
|
||||
case 0x88:
|
||||
return mode_robot36;
|
||||
case 0x0c:
|
||||
|
|
|
@ -284,7 +284,7 @@ void decode(int samples) {
|
|||
|
||||
static int reset_on_first_sync;
|
||||
if (automatic_mode_detection) {
|
||||
int detected_mode = calibration_detector(dat_quantized, cnt_quantized);
|
||||
int detected_mode = calibration_detector(cnt_quantized);
|
||||
if (detected_mode >= 0) {
|
||||
//RS_DEBUG(detected_mode);
|
||||
reset_on_first_sync = 1;
|
||||
|
|
|
@ -76,25 +76,12 @@ void initialize(float rate, int length, int iw, int ih, int sw, int sh, int sgw,
|
|||
maximum_abs_dev_20ms = 0.5f * pairwise_minimum_of_scanline_time_distances_20ms * sample_rate;
|
||||
maximum_variance = pown(0.0005f * sample_rate, 2);
|
||||
|
||||
const float first_leader_tolerance = 0.3f;
|
||||
const float second_leader_tolerance = 0.9f;
|
||||
const float break_tolerance = 0.5f;
|
||||
const float leader_timeout_tolerance = 1.2f;
|
||||
const float break_timeout_tolerance = 1.8f;
|
||||
const float vis_timeout_tolerance = 1.01f;
|
||||
const float leader_seconds = 0.3f;
|
||||
const float break_seconds = 0.01f;
|
||||
const float vis_seconds = 0.3f;
|
||||
const float bit_seconds = 0.03f;
|
||||
first_leader_length = first_leader_tolerance * leader_seconds * sample_rate;
|
||||
second_leader_length = second_leader_tolerance * leader_seconds * sample_rate;
|
||||
leader_length = first_leader_length;
|
||||
break_length = break_tolerance * break_seconds * sample_rate;
|
||||
const float ssb_tolerance = 0.9f;
|
||||
vis_length = vis_seconds * sample_rate;
|
||||
bit_length = bit_seconds * sample_rate;
|
||||
leader_timeout = leader_timeout_tolerance * leader_seconds * sample_rate;
|
||||
break_timeout = break_timeout_tolerance * break_seconds * sample_rate;
|
||||
vis_timeout = vis_timeout_tolerance * vis_seconds * sample_rate;
|
||||
ssb_length = ssb_tolerance * bit_seconds * sample_rate;
|
||||
|
||||
const float dat_carrier = 1900.0f;
|
||||
const float cnt_carrier = 1200.0f;
|
||||
|
|
|
@ -31,10 +31,7 @@ static int maximum_abs_dev_5ms, maximum_abs_dev_9ms, maximum_abs_dev_20ms;
|
|||
static int minimum_sync_length;
|
||||
static int min_sync_length_5ms, min_sync_length_9ms, min_sync_length_20ms;
|
||||
static int scanline_length, minimum_length, maximum_length;
|
||||
static int vis_timeout, vis_length, bit_length;
|
||||
static int break_timeout, break_length;
|
||||
static int leader_timeout, leader_length;
|
||||
static int first_leader_length, second_leader_length;
|
||||
static int vis_length, bit_length, ssb_length;
|
||||
static int buffer_length, buffer_mask, buffer_pos;
|
||||
static int buffer_cleared;
|
||||
static int bitmap_width, bitmap_height;
|
||||
|
|
Ładowanie…
Reference in New Issue