cdefmt-decoder

Crates.iocdefmt-decoder
lib.rscdefmt-decoder
version0.3.0
sourcesrc
created_at2024-08-16 12:38:03.069357
updated_at2024-08-16 12:38:03.069357
descriptionDecodes cdefmt log frames
homepage
repositoryhttps://github.com/risint96/cdefmt
max_upload_size
id1340318
size31,402
Tal Risin (RisinT96)

documentation

README

cdefmt

cdefmt ("c de format", short for "c deferred formatting") is a highly efficient logging framework that targets resource-constrained devices, like microcontrollers.

Inspired by https://github.com/knurling-rs/defmt/

Setup

c

  1. Add cdefmt modifications to the linkerscript:
    1. Update/add .note.gnu.build-id section to define the necessary memory locations:
      .note.gnu.build-id : {
          PROVIDE(__cdefmt_build_id = .);
          *(.note.gnu.build-id)
      }
      
    2. Add the cdefmt metadata section to the end of the linker script (or right before /DISCARD/ if it exists):
      /* CDEFMT: log metadata section */
      .cdefmt 0 (INFO) : {
          KEEP(*(.cdefmt.init .cdefmt.init.*))
          . = . + 8;
          KEEP(*(.cdefmt .cdefmt.*))
      }
      
  2. Make sure that you compile with the following flags:
    • -g - need debugging information in order to parse log arguments.
    • -Wl,--build-id - link build-id into the binary to verify elf compatibility on init.
  3. Add the header cdefmt.h to your project.
  4. Include the header wherever you want to use it.
  5. Implement cdefmt_log in your project.
  6. Call CDEFMT_GENERATE_INIT() somewhere in your main file.
  7. Call cdefmt_init() after your logging backend is initialized and cdefmt_log can be safely called.
  8. Enjoy.

Rust

TBD

Usage

Basically cdefmt_log should store/write log into the log sink, then these bytes should be provided to the parser as-is, accompanied with the elf binary.

See:

  • stdout for generating logs.
  • stdin for parsing the logs.

The easiest way to run the example would be to build the project using cmake:

cmake -S . -B build
cmake --build build/

Then run the stdout example and pipe it's stdout into the stdin example:

build/examples/stdout/example-stdout | build/stdin --elf build/examples/stdout/example-stdout

License

Commit count: 62

cargo fmt