Crates.io | yule_log |
lib.rs | yule_log |
version | 0.3.2 |
created_at | 2025-02-13 18:18:27.628401+00 |
updated_at | 2025-09-25 11:49:23.827671+00 |
description | A streaming parser for PX4 ULOG files. |
homepage | |
repository | https://github.com/annoybot/yule_log |
max_upload_size | |
id | 1554551 |
size | 39,231,027 |
A streaming ULOG parser written in Rust.
yule_log
handle arbitrarily large files in real time without fully loading them into memory.macros
feature.The macros
feature provides a serde-like experience, allowing ULOG data to be mapped directly into your own structs.
With this feature, there is no need to manually track subscription names, msg_ids, or field indices, the macros handle all of that for you automatically. The stream-oriented nature of the underlying parser is fully preserved.
yule_log = { version="0.3", features = ["macros"] }
Define one struct for each ULOG subscription you want to map,
and annotate it with: #[derive(ULogData)]
.
Example:
#[derive(ULogData)]
pub struct VehicleLocalPosition {
pub timestamp: u64,
pub x: f32,
pub y: f32,
pub z: f32,
pub extra_field: Option<f32>,
}
In most cases, no extra config is needed—just name your struct and fields to match the names used in the ULOG. Only include the fields you need.
The macros will infer the ULOG names by converting your struct and field names to snake case.
By default, struct fields will be validated
against the ULOG file, and any missing fields will cause an error. This can be overriden by making a field an Option<T>
, as shown above for extra_field
.
💡Subscription and field names can also be specified using the #[yule_log]
attribute. For
more information refer to the ULogData API docs.
Declare an enum where each variant wraps one of your ULogData structs, and annotate it with:
#[derive(ULogMessages)]
.
#[derive(ULogMessages)]
pub enum LoggedMessages {
VehicleLocalPosition(VehicleLocalPosition),
ActuatorOutputs(ActuatorOutputs),
}
This enum will then become your interface to the data.
💡 Raw ULOG messages can also be captured by annotating an enum variant as follows:
#[yule_log(forward_other)]
Other(yule_log::model::msg::UlogMessage),
The derive macro will generate a ::stream()
method on your enum, allowing the
messages to be easily retrieved.
Full example:
use std::fs::File;
use std::io::BufReader;
use yule_log::model::msg::UlogMessage;
use yule_log::{ULogData, ULogMessages};
#[derive(ULogMessages)]
pub enum LoggedMessages {
VehicleLocalPosition(VehicleLocalPosition),
ActuatorOutputs(ActuatorOutputs),
#[yule_log(forward_other)]
Other(yule_log::model::msg::UlogMessage),
}
#[derive(ULogData)]
pub struct VehicleLocalPosition {
pub timestamp: u64,
pub x: f32,
pub y: f32,
pub z: f32,
}
#[derive(ULogData)]
#[yule_log(multi_id = 1)]
pub struct ActuatorOutputs {
pub timestamp: u64,
pub output: Vec<f32>,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let reader = BufReader::new(File::open("sample.ulg")?);
let stream = LoggedMessages::stream(reader)?;
for msg_res in stream {
let msg = msg_res?;
match msg {
LoggedMessages::VehicleLocalPosition(v) => {
println!("VehicleLocalPosition: {}: x={} y={} z={}",
v.timestamp, v.x, v.y, v.z);
}
LoggedMessages::ActuatorOutputs(a) => {
println!("ActuatorOutputs: {}: {:?}",
a.timestamp, a.output);
}
LoggedMessages::Other(msg) => {
if let UlogMessage::Info(info) = msg {
println!("INFO: {info}");
}
}
}
}
Ok(())
}
For those requiring complete control over the parsing process, the original low level API is still available.
Example:
let reader = BufReader::new(File::open(ulog_path.clone())?);
let parser = ULogParserBuilder::new(reader)
.include_header(true)
.include_timestamp(true)
.include_padding(true)
.build()?;
for result in parser {
let ulog_message = result?;
match ulog_message {
UlogMessage::Header(header) => println!("HEADER: {header:?}"),
UlogMessage::FlagBits(flag_bits) => println!("FLAG_BITS: {flag_bits:?}"),
UlogMessage::Info(info) => println!("INFO: {info}"),
UlogMessage::MultiInfo(multi_info) => println!("MULTI INFO: {multi_info}"),
UlogMessage::FormatDefinition(format) => println!("FORMAT_DEFINITION: {format:?}"),
UlogMessage::Parameter(param) => println!("PARAM: {param}"),
UlogMessage::DefaultParameter(param) => println!("PARAM DEFAULT: {param}"),
UlogMessage::LoggedData(data) => println!("LOGGED_DATA: {data:?}"),
UlogMessage::AddSubscription(sub) => println!("SUBSCRIPTION: {sub:?}"),
UlogMessage::LoggedString(log) => println!("LOGGED_STRING: {log}"),
UlogMessage::TaggedLoggedString(log) => println!("TAGGED_LOGGED_STRING: {log}"),
UlogMessage::Unhandled { msg_type, .. } => println!("Unhandled msg type: {}", msg_type as char),
UlogMessage::Ignored { msg_type, .. } => println!("Ignored msg type: {}", msg_type as char),
}
}
This example is also available in the examples
directory as simple.rs
.
This project is licensed under the MIT Licence.