Compare commits
28
Commits
00dc0e21b7
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cbb6572f29 | ||
|
|
5ad14b5784 | ||
|
|
c9412423cb | ||
|
|
aca4dcb2e9 | ||
|
|
aa54e9a089 | ||
|
|
fba79df24b | ||
|
|
e07a507df5 | ||
|
|
76e59f2d1b | ||
|
|
997b888636 | ||
|
|
f7971c874d | ||
|
|
486a811f3b | ||
|
|
d450e3b8b3 | ||
|
|
1eb2505e37 | ||
|
|
b9559cbe8c | ||
|
|
8175d1cba0 | ||
|
|
70b5557be9 | ||
|
|
4a0740539b | ||
|
|
bee128dec7 | ||
|
|
94df442395 | ||
|
|
38a76ead58 | ||
|
|
deb21dc681 | ||
|
|
61ac134424 | ||
|
|
4aded6604a | ||
|
|
d36fb23470 | ||
|
|
9b9b7a79ad | ||
|
|
4e69bb67e2 | ||
|
|
71bf90f003 | ||
|
|
f462e65cc2 |
@@ -28,6 +28,7 @@ exec "$BIN" \
|
|||||||
di1_group_avg \
|
di1_group_avg \
|
||||||
duration_ms:100 \
|
duration_ms:100 \
|
||||||
packet_limit:0 \
|
packet_limit:0 \
|
||||||
|
do1_toggle_per_frame \
|
||||||
profile:amplitude \
|
profile:amplitude \
|
||||||
"tty:${TTY_PATH}" \
|
"tty:${TTY_PATH}" \
|
||||||
"$@"
|
"$@"
|
||||||
|
|||||||
Executable
+45
@@ -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}" \
|
||||||
|
"$@"
|
||||||
Executable
+33
@@ -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}" \
|
||||||
|
"$@"
|
||||||
Executable
+33
@@ -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}" \
|
||||||
|
"$@"
|
||||||
Executable
+35
@@ -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}" \
|
||||||
|
"$@"
|
||||||
@@ -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
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user