yodaldevoid / dts_viewer Goto Github PK
View Code? Open in Web Editor NEWA viewer for DTS files to aid in debugging.
License: MIT License
A viewer for DTS files to aid in debugging.
License: MIT License
Hi. When I run this tool and point it to a .dts file, I get the following:
test/system-device-tree-zynq.dts: CPP
|- : CPP
|- |- : CPP
Enter alias or path:
What is this suppost to be? I thought this tool would somehow traverse includes and produce an easy way to understand the whole picture.
definitely:
maybe:
I am using the device_tree_source
library and I was wondering what your reasons were for making Property and Node enums?
My use case is to parse the device tree to create some structs of my own to be consumed by another tool. I am finding it fairly difficult to keep parsing these nested enums while looking for specific information.
Consider a function where I expect a node to have a property where the value is a single string:
fn get_node_prop_string(n: &Node, prop: &str) -> Option<String> {
match n {
Node::Existing { proplist, .. } =>
{
match proplist.get(prop)? {
Property::Existing { val, .. } => {
val.as_ref()?.iter().next().map(|z| match z {
Data::String(s) => Some(s.clone()),
_ => None,
}).flatten()
},
Property::Deleted { .. } => None,
}
},
Node::Deleted { name, .. } => None,
}
}
I need to have 3 matches in there, because there are 3 nested enums. I can make it cleaner with some other helper functions:
fn get_node_proplist(n: &Node) -> Option<&HashMap<String, Property>> {
match n {
Node::Existing { proplist, .. } => Some(proplist),
Node::Deleted { .. } => None,
}
}
fn get_property_val(p: &Property) -> &Option<Vec<Data>> {
match p {
Property::Existing { val, .. } => val,
Property::Deleted { .. } => &None,
}
}
fn get_node_prop_string(n: &Node, prop: &str) -> Option<String> {
let p = get_node_proplist(n)?.get(prop)?;
let vals = get_property_val(p).as_ref()?;
match &vals[0] {
Data::String(s) => Some(s.clone()),
_ => None,
}
}
But I need to write those functions myself.
Here is an alternative approach:
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct PropertyInner {
val: Option<Vec<Data>>,
labels: Vec<String>,
}
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct Property {
name: String,
offset: usize,
exists: Option<PropertyInner>,
}
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct NodeInner {
proplist: HashMap<String, Property>,
children: HashMap<String, Node>,
labels: Vec<String>,
}
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct Node {
name: NodeName,
offset: usize,
exists: Option<NodeInner>,
}
Then my function becomes a lot cleaner by default:
fn node_get_prop_string_by_name(node: &Node, prop: &str) -> Option<String> {
let vals = node.exists.as_ref()?
.proplist.get(prop)?
.exists.as_ref()?
.val.clone()?;
match &vals[0] {
Data::String(s) => Some(s.clone()),
_ => None,
}
}
This simplifies my use case, but also still lets you tell if a node or property is deleted. You just need to check the exists
option.
I am fairly new to rust so I may be missing something here.
This is labels within property data as labels on properties is already implemented.
It is currently set to 0 and never changed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.