Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,895 changes: 1,895 additions & 0 deletions mavlink-bindgen/src/codegen.rs

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions mavlink-bindgen/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use std::num::{ParseFloatError, ParseIntError};

use quick_xml::events::Event;
use thiserror::Error;

use crate::parser::MavXmlElement;

#[derive(Error, Debug)]
pub enum BindGenError {
/// Represents a failure to read the MAVLink definitions directory.
Expand All @@ -26,4 +31,53 @@ pub enum BindGenError {
source: std::io::Error,
dest_path: std::path::PathBuf,
},
/// Occurs when a MAVLink XML definition is not valid
#[error("MAVLink definition file {} is invalid: {source}", path.display())]
InvalidDefinitionFile {
source: MavXMLParseError,
path: std::path::PathBuf,
},
/// Occurs when a MAVLink XML definition refences an enum that is not defined in it or its includes
#[error("MAVLink definition file {} references undefined enum {enum_name}", path.display())]
InvalidEnumReference {
enum_name: String,
path: std::path::PathBuf,
},
#[error("bitflag enum field {field_name} of {message_name} must be able to fit all possible values for {enum_name}")]
BitflagEnumTypeToNarrow {
field_name: String,
message_name: String,
enum_name: String,
},
}

#[derive(Error, Debug)]
pub enum MavXMLParseError {
#[error("{0}")]
QuickXMLError(#[from] quick_xml::errors::Error),
#[error("{0}")]
ParseIntFailed(#[from] ParseIntError),
#[error("{0}")]
ParseFloatFailed(#[from] ParseFloatError),
#[error("Unexpected XML element {event:?} in {parent:?}")]
UnexpectedEvent {
event: Event<'static>,
parent: MavXmlElement,
},
#[error("Unexpected tag {element:?}")]
UnexpectedElement { element: MavXmlElement },
#[error("Expected text")]
ExpectedText,
#[error("MAVLink definition file ends unexpectedly")]
UnexpectedEnd,
#[error("Param index must be between 1 and 7")]
ParamIndexOutOfRange,
#[error("Expected start of MAVLink definition")]
ExpectedMAVLink,
#[error("Invalid field type: {mav_type}")]
InvalidType { mav_type: String },
#[error("Duplicate field '{field}' found in message '{message}' while generating bindings")]
DuplicateFieldName { field: String, message: String },
#[error("Message '{message}' must have between 1 and 64 fields")]
InvalidFieldCount { message: String },
}
5 changes: 3 additions & 2 deletions mavlink-bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use std::path::{Path, PathBuf};
use std::process::Command;

pub mod binder;
pub mod codegen;
pub mod error;
pub mod parser;
mod parser;
mod util;

#[derive(Debug)]
Expand Down Expand Up @@ -173,7 +174,7 @@ fn generate_single_file<P1: AsRef<Path>, P2: AsRef<Path>>(
})?);

// codegen
parser::generate(definitions_dir, &definition_filename, &mut outf)?;
codegen::generate(definitions_dir, &definition_filename, &mut outf)?;

Ok(GeneratedBinding {
module_name,
Expand Down
Loading
Loading