GithubHelp home page GithubHelp logo

defmt-persist's People

Contributors

eupn avatar mathiaskoch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

eupn

defmt-persist's Issues

COBS encode from Postcard

Currently the COBS encoding decoding is done "manually", but should be possible to get working as a postcard flavor

Documentation & examples

The general documentation state of the crate is rather low:

  • Readme
  • Docs.rs
  • Cargo.toml
  • Examples
  • Repository description

Allow wrapping storage (circular storage)

It would be nice to be able to configure defmt-persist to be either the n first log frames, or the n latest log frames, where n depends on the storage available.

Periodic persisting of log records fails

Hello @MathiasKoch! Thanks for this crate, I find it useful and this is exactly what I had in mind for my project for quite some time!

I'm currently trying to plug this into my project that uses an STM32 MCU that has a typical FLASH controller that requires the page to be erased to be written to.

From my understanding, this requirement poses a challenge, that it isn't possible to periodically call drain_storage to flush records into the FLASH as it will fail on consequent calls due to the page with the header not being erased.

Currently, I can imagine some solutions to this:

  1. Keep the header in a separate FLASH page and erase it every time the header needs to be updated. This solution is pretty lame and wasteful of the FLASH resource but could work in the short term, or
  2. Do not use the header and rely on the fact that "empty" data in FLASH are always 0xFFs. Probably, the log records could have some magic number at the beginning (and/or the end) and during the write, we will skim through the log area to find an empty spot that is only 0xFFs and doesn't have that magic number at the beginning, or
  3. Use some more advanced data structure that is more suitable for a FLASH memory, probably similar to those used in filesystems

Hope it makes sense. What are your thoughts on this?

Allow log persistence alongside "streaming" defmt transports

It could be useful to run the firmware with probe-run, see some logs there that it's running OK, and then remove the probe or deploy the device in the field while still be able to read logs, but later and from storage. Both achieved by the same firmware.

This would have to happen behind an opt-in feature flag.

[RFC] Motivation and design thoughts

This is our company RFC for the feature, copied here to give people an insight into the thoughts and usecase behind this crate.

Motivation

Currently all logging have been changed to use defmt (https://defmt.ferrous-systems.com/), which makes for a fast debug logging framework.

We should be able to use the two facts about defmt that it is transfer-agnostic and small sized on device to implement a global logger that writes to our external flash instead of RTT.

Background knowledge

NOTE This is slightly outdated, as the format of defmt has been changed to use tags and JSON, but for this project, the description is valid nevertheless.

The way defmtworks is:
Say we have a log statement defmt::info!("This would be awesome to log, but contains a lot of characters that is expensive to include in my binary! This is a variable: {:?}", 5), it would store the string This would be awesome to log, but contains a lot of characters that is expensive to include in my binary! This is a variable: {:?} in a debug section of the ELF, that would not be flashed onto the device, at a known index (in this example index 1).

The log statement on the device would then be changed to send

let bytes = [
    1,  // index
    2,  // timestamp
    5,  // argument
];

through whatever global logger transport is enabled on the device (eg. defmt-rtt)

The timestamp is generated from a function on the device, and could be an actual timestamp (eg. UTC), or just an incrementing number (eg. 1, 2, 3).

A decoder would then be needed to decode these bytes, based on the original ELF containing the aforementioned debug section.

This means that the logging itself is completely transport agnostic (could be serial based, network based, stored and read or whatever. As long as the ELF on the device matches the one used by the decoder)

Proposed Solution

The proposed solution involves writing a defmt-persist crate, that initializes a global logger to write to a given flash area.
The flash area should have an MQTT based API to read the log messages, eg. write to <DeviceType>/log/get/<UUID> and the device will start publishing log statements to <DeviceType>/log/<UUID> or something similar.
Furthermore we need some tooling to read logs and decode them based on the matching elf file from S3.

Implementation Steps

Changes needed to implement the feature:

Follow-up task would be to have devices send the full log to MQTT in case of a panic, with a lambda/IoT rule to log it to cloudwatch automatically, so we always persist logs leading up to a panic

Storage format

Considerations around storage format?

  • Perhaps just zero-terminate every message?

Document overhead

Document the overhead of

  • CRC
  • COBS

in terms of storage size & wire size.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.