26 Commits
Author SHA1 Message Date
awe cbb6572f29 finally working 2026-05-29 16:55:32 +03:00
awe 5ad14b5784 fix di8 2026-05-29 15:36:31 +03:00
awe c9412423cb fix 2026-05-29 15:01:18 +03:00
awe aca4dcb2e9 fix 2026-05-29 12:37:48 +03:00
awe aa54e9a089 fix 2026-05-29 12:29:43 +03:00
awe fba79df24b fix and listener 2026-05-28 16:13:53 +03:00
awe e07a507df5 new start treshhold 2026-05-28 16:09:34 +03:00
awe 76e59f2d1b new di8do8 switch 2026-05-28 16:06:45 +03:00
awe 997b888636 do 2 hugh 2026-05-08 13:55:19 +03:00
awe f7971c874d new rezhim 2026-04-29 17:37:36 +03:00
awe 486a811f3b add new test start variant 2026-04-28 19:17:03 +03:00
awe d450e3b8b3 fix 2026-04-27 20:25:10 +03:00
awe 1eb2505e37 fix 2026-04-27 20:15:51 +03:00
awe b9559cbe8c new do1_noise_subtract logic 2026-04-27 19:54:07 +03:00
awe 8175d1cba0 di 1 incre 2026-04-24 18:01:45 +03:00
awe 70b5557be9 fix 2026-04-24 17:04:13 +03:00
awe 4a0740539b noise sub mode 2026-04-24 14:10:47 +03:00
awe bee128dec7 2 ticks upd 2026-04-24 13:52:12 +03:00
awe 94df442395 fix 2026-04-21 22:55:20 +03:00
awe 38a76ead58 fix 2026-04-21 22:15:12 +03:00
awe deb21dc681 fix 2026-04-21 22:05:39 +03:00
awe 61ac134424 fix 2026-04-21 21:27:42 +03:00
awe 4aded6604a test new 2026-04-21 21:09:25 +03:00
awe d36fb23470 fix 2026-04-21 20:40:17 +03:00
awe 9b9b7a79ad remove svg csv save 2026-04-21 19:36:45 +03:00
awe 4e69bb67e2 upd fix do 2026-04-21 19:34:07 +03:00
7 changed files with 1316 additions and 163 deletions
+1055 -156
View File
File diff suppressed because it is too large Load Diff
+45
View File
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
BIN="${BIN:-./main.exe}"
TTY_PATH="${TTY_PATH:-/tmp/ttyADC_data}"
LIB_DIR="${LIB_DIR:-$HOME/.local/lib}"
NOISE_AVG_STEPS="${NOISE_AVG_STEPS:-}"
if [[ ! -x "$BIN" ]]; then
echo "Binary '$BIN' not found or not executable. Run ./build_main.sh first." >&2
exit 1
fi
if [[ -z "$NOISE_AVG_STEPS" ]]; then
echo "Set NOISE_AVG_STEPS to a positive integer, for example: NOISE_AVG_STEPS=16" >&2
exit 1
fi
if ! [[ "$NOISE_AVG_STEPS" =~ ^[0-9]+$ ]] || [[ "$NOISE_AVG_STEPS" -eq 0 ]]; then
echo "NOISE_AVG_STEPS must be a positive integer, got '$NOISE_AVG_STEPS'" >&2
exit 1
fi
if [[ -d "$LIB_DIR" ]]; then
export LD_LIBRARY_PATH="${LIB_DIR}${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"
fi
exec "$BIN" \
clock:internal \
internal_ref_hz:2000000 \
start:di_syn2_rise \
stop:di_syn2_fall \
sample_clock_hz:max \
range:5 \
duration_ms:100 \
packet_limit:0 \
do1_toggle_per_frame \
do1_noise_subtract \
"noise_avg_steps:${NOISE_AVG_STEPS}" \
profile:phase \
"tty:${TTY_PATH}" \
"$@"
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
BIN="${BIN:-./main.exe}"
TTY_PATH="${TTY_PATH:-/tmp/ttyADC_data}"
LIB_DIR="${LIB_DIR:-$HOME/.local/lib}"
if [[ ! -x "$BIN" ]]; then
echo "Binary '$BIN' not found or not executable. Run ./build_main.sh first." >&2
exit 1
fi
if [[ -d "$LIB_DIR" ]]; then
export LD_LIBRARY_PATH="${LIB_DIR}${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"
fi
exec "$BIN" \
profile:phase \
clock:internal \
internal_ref_hz:2000000 \
start:di_syn2_rise \
stop:di_syn2_fall \
sample_clock_hz:max \
range:5 \
duration_ms:100 \
packet_limit:0 \
do1_toggle_per_frame \
do1_pair_subtract_avg \
"tty:${TTY_PATH}" \
"$@"
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
BIN="${BIN:-./main.exe}"
TTY_PATH="${TTY_PATH:-/tmp/ttyADC_data}"
LIB_DIR="${LIB_DIR:-$HOME/.local/lib}"
if [[ ! -x "$BIN" ]]; then
echo "Binary '$BIN' not found or not executable. Run ./build_main.sh first." >&2
exit 1
fi
if [[ -d "$LIB_DIR" ]]; then
export LD_LIBRARY_PATH="${LIB_DIR}${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"
fi
exec "$BIN" \
profile:phase \
clock:internal \
internal_ref_hz:2000000 \
start:di_syn2_rise \
stop:di_syn2_fall \
sample_clock_hz:max \
range:5 \
duration_ms:100 \
packet_limit:0 \
do1_toggle_per_frame \
do1_raw_tty_marked \
"tty:${TTY_PATH}" \
"$@"
+35
View File
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
BIN="${BIN:-./main.exe}"
TTY_PATH="${TTY_PATH:-/tmp/ttyADC_data}"
LIB_DIR="${LIB_DIR:-$HOME/.local/lib}"
if [[ ! -x "$BIN" ]]; then
echo "Binary '$BIN' not found or not executable. Run ./build_main.sh first." >&2
exit 1
fi
if [[ -d "$LIB_DIR" ]]; then
export LD_LIBRARY_PATH="${LIB_DIR}${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"
fi
exec "$BIN" \
profile:phase \
clock:internal \
internal_ref_hz:2000000 \
start:di_syn2_rise \
stop:di_syn2_fall \
sample_clock_hz:max \
range:5 \
duration_ms:100 \
packet_limit:0 \
do1_toggle_per_frame \
do1_pair_subtract_avg \
do8_freq_ref \
do8_cycle_period:8 \
"tty:${TTY_PATH}" \
"$@"
+102
View File
@@ -0,0 +1,102 @@
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cerrno>
#include <fcntl.h>
#include <unistd.h>
static constexpr uint16_t kMarkerDi8High = 0x00A8U;
static constexpr uint16_t kMarkerStandard = 0x000AU;
static constexpr uint16_t kMarkerAmplitude = 0x001AU;
static constexpr uint16_t kMarkerDo1Low = 0x00A3U;
static constexpr uint16_t kMarkerDo1High = 0x00A4U;
static const char* marker_name(uint16_t m) {
switch (m) {
case kMarkerDi8High: return "DI8_REF";
case kMarkerStandard: return "STD";
case kMarkerAmplitude: return "AMP";
case kMarkerDo1Low: return "DO1_LO";
case kMarkerDo1High: return "DO1_HI";
default: return "???";
}
}
int main(int argc, char** argv) {
bool show_all = false;
const char* path = "/tmp/ttyADC_data";
for (int i = 1; i < argc; ++i) {
if (std::strcmp(argv[i], "--all") == 0 || std::strcmp(argv[i], "-a") == 0) {
show_all = true;
} else if (std::strcmp(argv[i], "-h") == 0 || std::strcmp(argv[i], "--help") == 0) {
std::fprintf(stderr,
"Usage: %s [OPTIONS] [tty_path]\n"
" tty_path path to TTY device (default: /tmp/ttyADC_data)\n"
" -a, --all show all frames, not just 0x00A8\n"
" -h, --help this message\n", argv[0]);
return 0;
} else {
path = argv[i];
}
}
std::fprintf(stderr, "Opening %s ...\n", path);
const int fd = open(path, O_RDONLY);
if (fd < 0) {
std::fprintf(stderr, "open(%s): %s\n", path, std::strerror(errno));
return 1;
}
std::fprintf(stderr, "Listening (filter: %s). Ctrl+C to stop.\n",
show_all ? "all frames" : "0x00A8 only");
uint8_t buf[8];
std::size_t buf_fill = 0;
uint64_t frame_seq = 0;
uint64_t di8_count = 0;
for (;;) {
const ssize_t n = read(fd, buf + buf_fill, sizeof(buf) - buf_fill);
if (n <= 0) {
if (n == 0) {
break;
}
if (errno == EINTR) {
continue;
}
std::fprintf(stderr, "read: %s\n", std::strerror(errno));
break;
}
buf_fill += static_cast<std::size_t>(n);
if (buf_fill < 8) {
continue;
}
uint16_t words[4];
std::memcpy(words, buf, 8);
buf_fill = 0;
const uint16_t marker = words[0];
const uint16_t step = words[1];
const int16_t ch1 = static_cast<int16_t>(words[2]);
const int16_t ch2 = static_cast<int16_t>(words[3]);
++frame_seq;
if (marker == kMarkerDi8High) {
++di8_count;
std::printf("#%-8lu [%s] step=%5u ch1=%6d ch2=%6d (di8_total=%lu)\n",
frame_seq, marker_name(marker), step, ch1, ch2, di8_count);
std::fflush(stdout);
} else if (show_all) {
std::printf("#%-8lu [%s] step=%5u ch1=%6d ch2=%6d\n",
frame_seq, marker_name(marker), step, ch1, ch2);
}
}
close(fd);
std::fprintf(stderr, "Done. Total frames: %lu, DI8 ref frames: %lu\n", frame_seq, di8_count);
return 0;
}
+13 -7
View File
@@ -77,6 +77,7 @@ namespace {
constexpr std::size_t kFrameWordCount = 4U; constexpr std::size_t kFrameWordCount = 4U;
constexpr std::size_t kFrameByteCount = kFrameWordCount * sizeof(uint16_t); constexpr std::size_t kFrameByteCount = kFrameWordCount * sizeof(uint16_t);
constexpr std::size_t kWriteBatchFrames = 256U;
using EncodedFrame = std::array<std::uint8_t, kFrameByteCount>; using EncodedFrame = std::array<std::uint8_t, kFrameByteCount>;
@@ -377,7 +378,8 @@ void TtyProtocolWriter::enqueue_frame(uint16_t word0, uint16_t word1, uint16_t w
void TtyProtocolWriter::worker_loop() { void TtyProtocolWriter::worker_loop() {
for (;;) { for (;;) {
EncodedFrame frame {}; std::array<std::uint8_t, kWriteBatchFrames * kFrameByteCount> write_batch;
std::size_t batch_count = 0;
{ {
std::unique_lock<std::mutex> lock(impl_->mutex); std::unique_lock<std::mutex> lock(impl_->mutex);
impl_->data_ready_cv.wait(lock, [this]() { impl_->data_ready_cv.wait(lock, [this]() {
@@ -388,13 +390,17 @@ void TtyProtocolWriter::worker_loop() {
return; return;
} }
frame = impl_->ring[impl_->head]; batch_count = std::min<std::size_t>(impl_->size, kWriteBatchFrames);
impl_->head = (impl_->head + 1U) % impl_->capacity_frames; for (std::size_t i = 0; i < batch_count; ++i) {
--impl_->size; const EncodedFrame& frame = impl_->ring[impl_->head];
std::memcpy(write_batch.data() + (i * kFrameByteCount), frame.data(), kFrameByteCount);
impl_->head = (impl_->head + 1U) % impl_->capacity_frames;
--impl_->size;
}
} }
const std::uint8_t* bytes = frame.data(); const std::uint8_t* bytes = write_batch.data();
std::size_t remaining = frame.size(); std::size_t remaining = batch_count * kFrameByteCount;
while (remaining != 0U) { while (remaining != 0U) {
const ssize_t written = ::write(impl_->fd, bytes, remaining); const ssize_t written = ::write(impl_->fd, bytes, remaining);
if (written < 0) { if (written < 0) {
@@ -436,7 +442,7 @@ void TtyProtocolWriter::worker_loop() {
{ {
std::lock_guard<std::mutex> lock(impl_->mutex); std::lock_guard<std::mutex> lock(impl_->mutex);
++impl_->stats.frames_written; impl_->stats.frames_written += static_cast<std::uint64_t>(batch_count);
} }
} }
} }