sloppified ai example but working, yaaaaaay, :,)
This commit is contained in:
parent
45a60d64b9
commit
1d3d25e6ae
@ -39,10 +39,10 @@ deploy_and_build() {
|
||||
return $BUILD_STATUS
|
||||
}
|
||||
|
||||
deploy_and_build 10.91.51.165 &
|
||||
deploy_and_build 10.91.51.166 &
|
||||
PID1=$!
|
||||
|
||||
deploy_and_build 10.91.51.166 &
|
||||
deploy_and_build 10.91.51.165 &
|
||||
PID2=$!
|
||||
|
||||
wait $PID1
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
// lora_rx.cpp — LR1121 receive test
|
||||
// Usage: sudo ./lora_rx [-v] [--433|--868|--24|freq_hz] [--reset]
|
||||
// lora_rx.cpp — LR1121 receive test (robust RX loop)
|
||||
// Usage: sudo ./lora_rx [-v] [--433|--868|--24|freq_hz] [--reset] [--tmo=ms]
|
||||
// [--busy-gpio=N] [--reset-gpio=N] [--dio9-gpio=N]
|
||||
// -v verbose step labels (shows exactly where init hangs)
|
||||
// --433 433.05 MHz (default)
|
||||
// --868 868 MHz
|
||||
@ -24,6 +25,7 @@ int main(int argc, char **argv)
|
||||
cfg.bw = 0x04; // 125 kHz
|
||||
cfg.cr = 0x01; // CR 4/5
|
||||
bool do_reset = false;
|
||||
uint32_t rx_timeout_ms = 1000; // Short timeout keeps RX loop responsive.
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (std::strcmp(argv[i], "-v") == 0) cfg.verbose = true;
|
||||
@ -32,11 +34,16 @@ int main(int argc, char **argv)
|
||||
else if (std::strcmp(argv[i], "--24") == 0 ||
|
||||
std::strcmp(argv[i], "--2g4") == 0) cfg.freq_hz = lr1121::FREQ_2400;
|
||||
else if (std::strcmp(argv[i], "--reset") == 0) do_reset = true;
|
||||
else if (std::strncmp(argv[i], "--tmo=", 6) == 0) rx_timeout_ms = (uint32_t)std::strtoul(argv[i] + 6, nullptr, 10);
|
||||
else if (std::strncmp(argv[i], "--busy-gpio=", 12) == 0) cfg.busy_gpio = (unsigned)std::strtoul(argv[i] + 12, nullptr, 10);
|
||||
else if (std::strncmp(argv[i], "--reset-gpio=", 13) == 0) cfg.reset_gpio = (unsigned)std::strtoul(argv[i] + 13, nullptr, 10);
|
||||
else if (std::strncmp(argv[i], "--dio9-gpio=", 12) == 0) cfg.dio9_gpio = (unsigned)std::strtoul(argv[i] + 12, nullptr, 10);
|
||||
else cfg.freq_hz = (uint32_t)std::strtoul(argv[i], nullptr, 10);
|
||||
}
|
||||
|
||||
std::printf("lora_rx: %u Hz SF%u BW=0x%02X%s\n",
|
||||
std::printf("lora_rx: %u Hz SF%u BW=0x%02X CR=0x%02X tmo=%ums gpio(busy=%u reset=%u dio9=%u)%s\n",
|
||||
cfg.freq_hz, cfg.sf, cfg.bw,
|
||||
cfg.cr, rx_timeout_ms, cfg.busy_gpio, cfg.reset_gpio, cfg.dio9_gpio,
|
||||
cfg.verbose ? " [verbose]" : "");
|
||||
|
||||
if (do_reset) {
|
||||
@ -75,18 +82,62 @@ int main(int argc, char **argv)
|
||||
|
||||
uint8_t buf[256];
|
||||
int pkt = 0;
|
||||
int timeouts_in_row = 0;
|
||||
int crc_in_row = 0;
|
||||
uint32_t timeout_total = 0;
|
||||
uint32_t crc_total = 0;
|
||||
|
||||
for (;;) {
|
||||
lr1121::RxInfo info{};
|
||||
int r = radio.receive(buf, (uint8_t)(sizeof(buf) - 1), 30'000, &info);
|
||||
int r = radio.receive(buf, (uint8_t)(sizeof(buf) - 1), rx_timeout_ms, &info);
|
||||
|
||||
if (r > 0) {
|
||||
buf[r] = '\0';
|
||||
std::printf("[%4d] %d B rssi=%d dBm snr=%d dB '%s'\n",
|
||||
++pkt, r, info.rssi_dbm, info.snr_db, buf);
|
||||
timeouts_in_row = 0;
|
||||
crc_in_row = 0;
|
||||
} else if (r == -1) {
|
||||
std::printf(" timeout (30s), still listening...\n");
|
||||
++timeouts_in_row;
|
||||
++timeout_total;
|
||||
if ((timeout_total % 10u) == 0u) {
|
||||
std::printf(" timeout x%u total (current streak=%d)\n",
|
||||
timeout_total, timeouts_in_row);
|
||||
}
|
||||
|
||||
// If RX keeps stalling, fully reinitialize to recover reliably.
|
||||
if (timeouts_in_row >= 20) {
|
||||
std::printf(" RX stalled (timeouts streak=%d) -> reinitializing radio...\n",
|
||||
timeouts_in_row);
|
||||
radio.end();
|
||||
if (!radio.begin(cfg)) {
|
||||
std::fprintf(stderr, "ERROR: radio reinit failed, retrying in 1s...\n");
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
} else {
|
||||
std::printf(" radio reinitialized, listening...\n");
|
||||
timeouts_in_row = 0;
|
||||
crc_in_row = 0;
|
||||
}
|
||||
}
|
||||
} else if (r == -2) {
|
||||
std::printf(" CRC error\n");
|
||||
++crc_in_row;
|
||||
++crc_total;
|
||||
std::printf(" CRC error (streak=%d total=%u)\n", crc_in_row, crc_total);
|
||||
|
||||
if (crc_in_row >= 8) {
|
||||
std::printf(" too many CRC errors -> reinitializing radio...\n");
|
||||
radio.end();
|
||||
if (!radio.begin(cfg)) {
|
||||
std::fprintf(stderr, "ERROR: radio reinit failed, retrying in 1s...\n");
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
} else {
|
||||
std::printf(" radio reinitialized, listening...\n");
|
||||
timeouts_in_row = 0;
|
||||
crc_in_row = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
std::printf(" RX unexpected code=%d\n", r);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
// lora_tx.cpp — LR1121 transmit test
|
||||
// Usage: sudo ./lora_tx [-v] [--433|--868|--24|freq_hz]
|
||||
// Usage: sudo ./lora_tx [-v] [--433|--868|--24|freq_hz] [--lp|--hp] [--dbm=N]
|
||||
// [--busy-gpio=N] [--reset-gpio=N] [--dio9-gpio=N]
|
||||
// -v verbose step labels (shows exactly where init hangs)
|
||||
// --433 433.05 MHz (default)
|
||||
// --868 868 MHz
|
||||
@ -18,8 +19,8 @@ int main(int argc, char **argv)
|
||||
{
|
||||
lr1121::Config cfg;
|
||||
cfg.verbose = false;
|
||||
cfg.pa_sel = 0x01; // HP PA — most modules; change to 0x00 for LP
|
||||
cfg.tx_dbm = 14;
|
||||
cfg.pa_sel = 0x00; // LP default: avoids LBD on weak VBAT rails
|
||||
cfg.tx_dbm = 10;
|
||||
cfg.sf = 0x07; // SF7
|
||||
cfg.bw = 0x04; // 125 kHz
|
||||
cfg.cr = 0x01; // CR 4/5
|
||||
@ -30,12 +31,19 @@ int main(int argc, char **argv)
|
||||
else if (std::strcmp(argv[i], "--868") == 0) cfg.freq_hz = lr1121::FREQ_868;
|
||||
else if (std::strcmp(argv[i], "--24") == 0 ||
|
||||
std::strcmp(argv[i], "--2g4") == 0) cfg.freq_hz = lr1121::FREQ_2400;
|
||||
else if (std::strcmp(argv[i], "--hp") == 0) cfg.pa_sel = 0x01;
|
||||
else if (std::strcmp(argv[i], "--lp") == 0) cfg.pa_sel = 0x00;
|
||||
else if (std::strncmp(argv[i], "--dbm=", 6) == 0) cfg.tx_dbm = (int8_t)std::atoi(argv[i] + 6);
|
||||
else if (std::strncmp(argv[i], "--busy-gpio=", 12) == 0) cfg.busy_gpio = (unsigned)std::strtoul(argv[i] + 12, nullptr, 10);
|
||||
else if (std::strncmp(argv[i], "--reset-gpio=", 13) == 0) cfg.reset_gpio = (unsigned)std::strtoul(argv[i] + 13, nullptr, 10);
|
||||
else if (std::strncmp(argv[i], "--dio9-gpio=", 12) == 0) cfg.dio9_gpio = (unsigned)std::strtoul(argv[i] + 12, nullptr, 10);
|
||||
else cfg.freq_hz = (uint32_t)std::strtoul(argv[i], nullptr, 10);
|
||||
}
|
||||
|
||||
std::printf("lora_tx: %u Hz SF%u BW=0x%02X PA=%s%s\n",
|
||||
std::printf("lora_tx: %u Hz SF%u BW=0x%02X PA=%s PWR=%d dBm gpio(busy=%u reset=%u dio9=%u)%s\n",
|
||||
cfg.freq_hz, cfg.sf, cfg.bw,
|
||||
cfg.pa_sel ? "HP" : "LP",
|
||||
cfg.pa_sel ? "HP" : "LP", (int)cfg.tx_dbm,
|
||||
cfg.busy_gpio, cfg.reset_gpio, cfg.dio9_gpio,
|
||||
cfg.verbose ? " [verbose]" : "");
|
||||
|
||||
lr1121::Radio radio;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
32
test/flake.nix
Normal file
32
test/flake.nix
Normal file
@ -0,0 +1,32 @@
|
||||
{
|
||||
description = "cpp project";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs }:
|
||||
let
|
||||
system = "x86_64-linux";
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
in
|
||||
{
|
||||
devShells.${system}.default = pkgs.mkShell {
|
||||
packages = with pkgs; [
|
||||
clang
|
||||
clang-tools
|
||||
pkg-config
|
||||
|
||||
libcamera
|
||||
libGL
|
||||
mesa
|
||||
|
||||
egl-wayland
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
echo "dev shell ready"
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user