Add serial-logs script

This commit is contained in:
2023-04-26 18:38:54 +02:00
parent e544e86cfa
commit 05951e1b77
2 changed files with 59 additions and 15 deletions

37
run
View File

@ -1,19 +1,26 @@
#!/bin/sh
#!/usr/bin/env nu
set -e
# Build, flash, and run the firmware.
#
# Will also attach to serial logs
def main [
bin: string # Which firmware to run, 'left' or 'right'.
--serial (-s): string # The serial device to get logs from.
--probe (-p): bool # Flash & run using probe-run instead of elf2uf2
] {
if $probe {
cargo build --bin $bin
probe-run --chip RP2040 --speed 4000 ("./target/thumbv6m-none-eabi/debug/" + $bin)
} else {
cargo run --bin $bin
}
cargo run --bin $1
let log_script = ($env.FILE_PWD | path join "serial-logs")
printf "waiting for serial log"
if $serial == null {
nu $log_script
} else {
nu $log_script --serial $serial
}
}
SERIAL=/dev/ttyACM0
while [ ! -e $SERIAL ]
do
printf "."
sleep 1
done
echo
sleep 1
cat $SERIAL

37
serial-logs Executable file
View File

@ -0,0 +1,37 @@
#!/usr/bin/env nu
let level_colors = {
TRACE: (ansi m)
DEBUG: (ansi c)
INFO: (ansi g)
WARN: (ansi y)
ERROR: (ansi rb)
}
# Attach to serial logs of a running firmware
def main [
--serial (-s): string # The serial device to get logs from.
] {
let serial = if $serial == null {
"/dev/serial/by-id/usb-Tux_Tangentbord1_42069-if00"
} else {
$serial
}
print -n ("waiting for serial log " + $serial)
while not ($serial | path exists) {
print -n "."
sleep 500ms
}
echo
cat $serial |
parse -r '\[(?<timestamp>[0-9\.]*)\] \((?<level>\w*)\) (?<message>.*)' |
each { |it|
print -n "[" (ansi d) $it.timestamp (ansi reset) "] "
print -n "(" ($level_colors | get $it.level) $it.level (ansi reset) ") "
print $it.message
}
}