Skip to content
Merged
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
10 changes: 7 additions & 3 deletions generator/sbpg/targets/resources/sbp_messages_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ use self::(((p.identifier|mod_name)))::(((m.identifier|camel_case)));
((*- endfor *))
((*- endfor *))

#[cfg(feature = "serialize")]
use serde::{Serialize, Deserialize};

pub trait SBPMessage {
const MSG_ID: u16;

fn get_sender_id(&self) -> Option<u16>;
fn set_sender_id(&mut self, new_id: u16);
}

#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug)]
pub enum SBP {
Unknown { msg_id: u16, sender_id: u16, payload: Vec<u8> },
Expand All @@ -36,8 +40,8 @@ pub enum SBP {
}

impl SBP {
pub fn parse(msg_id: u16, sender_id: u16, payload: &mut &[u8]) -> Result<SBP, ::Error> {
let x: Result<SBP, ::Error> = match msg_id {
pub fn parse(msg_id: u16, sender_id: u16, payload: &mut &[u8]) -> Result<SBP, crate::Error> {
let x: Result<SBP, crate::Error> = match msg_id {
((*- for m in msgs *))
(((m.sbp_id))) => {
let mut msg = (((m.identifier|camel_case)))::parse(payload)?;
Expand All @@ -49,7 +53,7 @@ impl SBP {
};
match x {
Ok(x) => Ok(x),
Err(_) => Err(::Error::ParseError),
Err(_) => Err(crate::Error::ParseError),
}
}
}
9 changes: 6 additions & 3 deletions generator/sbpg/targets/resources/sbp_messages_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
extern crate byteorder;
#[allow(unused_imports)]
use self::byteorder::{LittleEndian,ReadBytesExt};
#[cfg(feature = "serialize")]
use serde::{Serialize, Deserialize};

((*- for i in includes *))
use super::(((i)))::*;
Expand All @@ -30,6 +32,7 @@ use super::(((i)))::*;
(((m.desc|commentify)))
///
((*- endif *))
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug)]
#[allow(non_snake_case)]
pub struct (((m.identifier|camel_case))) {
Expand All @@ -45,7 +48,7 @@ pub struct (((m.identifier|camel_case))) {
}

impl (((m.identifier|camel_case))) {
pub fn parse(_buf: &mut &[u8]) -> Result<(((m.identifier|camel_case))), ::Error> {
pub fn parse(_buf: &mut &[u8]) -> Result<(((m.identifier|camel_case))), crate::Error> {
Ok( (((m.identifier|camel_case))){
((*- if m.sbp_id *))
sender_id: None,
Expand All @@ -57,15 +60,15 @@ impl (((m.identifier|camel_case))) {
}

((*- if not m.sbp_id *))
pub fn parse_array(buf: &mut &[u8]) -> Result<Vec<(((m.identifier|camel_case)))>, ::Error> {
pub fn parse_array(buf: &mut &[u8]) -> Result<Vec<(((m.identifier|camel_case)))>, crate::Error> {
let mut v = Vec::new();
while buf.len() > 0 {
v.push( (((m.identifier|camel_case)))::parse(buf)? );
}
Ok(v)
}

pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result<Vec<(((m.identifier|camel_case)))>, ::Error> {
pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result<Vec<(((m.identifier|camel_case)))>, crate::Error> {
let mut v = Vec::new();
for _ in 0..n {
v.push( (((m.identifier|camel_case)))::parse(buf)? );
Expand Down
8 changes: 4 additions & 4 deletions generator/sbpg/targets/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ def parse_type(field):
"""
if field.type_id == 'string':
if 'size' in field.options:
return "::parser::read_string_limit(_buf, %s)" % field.options['size'].value
return "crate::parser::read_string_limit(_buf, %s)" % field.options['size'].value
else:
return "::parser::read_string(_buf)"
return "crate::parser::read_string(_buf)"
elif field.type_id == 'u8':
return '_buf.read_u8()'
elif field.type_id == 's8':
Expand All @@ -85,9 +85,9 @@ def parse_type(field):
t = field.options['fill'].value
if t in TYPE_MAP.keys():
if 'size' in field.options:
return '::parser::read_%s_array_limit(_buf, %d)' % (t, field.options['size'].value)
return 'crate::parser::read_%s_array_limit(_buf, %d)' % (t, field.options['size'].value)
else:
return '::parser::read_%s_array(_buf)' % t
return 'crate::parser::read_%s_array(_buf)' % t
else:
if 'size' in field.options:
return '%s::parse_array_limit(_buf, %d)' % (t, field.options['size'].value)
Expand Down
5 changes: 5 additions & 0 deletions rust/sbp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ authors = ["Swift Navigation <dev@swiftnav.com>"]
repository = "https://github.com/swift-nav/libsbp"
license = "LGPL-3.0"
categories = ["parsing"]
edition = "2018"

[features]
serialize = ["serde"]

[dependencies]
byteorder = "1.2.1"
crc16 = "*"
nom = "5.0.0"
serde = { version = "1.0", features = ["derive"], optional = true }

[badges]
travis-ci = { repository = "swift-nav/libsbp" }
18 changes: 9 additions & 9 deletions rust/sbp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod tests {
0x28u8, 0xf4, 0x7a, 0x13, 0x96, 0x62, 0xee, 0xff, 0xbe, 0x40, 0x14, 0x00, 0xf6, 0xa3,
0x09, 0x00, 0x00, 0x00, 0x0e, 0x00,
];
let baseline_ecef_expectation = ::messages::navigation::MsgBaselineECEF {
let baseline_ecef_expectation = crate::messages::navigation::MsgBaselineECEF {
sender_id: Some(1234),
accuracy: 0,
flags: 0,
Expand All @@ -27,9 +27,9 @@ mod tests {
y: 1327294,
z: 631798,
};
let sbp_result = ::messages::SBP::parse(0x20b, 1234, &mut &baseline_ecef_payload[..]);
let sbp_result = crate::messages::SBP::parse(0x20b, 1234, &mut &baseline_ecef_payload[..]);
assert!(sbp_result.is_ok());
if let ::messages::SBP::MsgBaselineECEF(msg) = sbp_result.unwrap() {
if let crate::messages::SBP::MsgBaselineECEF(msg) = sbp_result.unwrap() {
assert_eq!(msg.sender_id, baseline_ecef_expectation.sender_id);
assert_eq!(msg.accuracy, baseline_ecef_expectation.accuracy);
assert_eq!(msg.flags, baseline_ecef_expectation.flags);
Expand All @@ -49,7 +49,7 @@ mod tests {
0x55u8, 0x0b, 0x02, 0xd3, 0x88, 0x14, 0x28, 0xf4, 0x7a, 0x13, 0x96, 0x62, 0xee, 0xff,
0xbe, 0x40, 0x14, 0x00, 0xf6, 0xa3, 0x09, 0x00, 0x00, 0x00, 0x0e, 0x00, 0xdb, 0xbf,
];
let baseline_ecef_expectation = ::messages::navigation::MsgBaselineECEF {
let baseline_ecef_expectation = crate::messages::navigation::MsgBaselineECEF {
sender_id: Some(0x88d3),
accuracy: 0,
flags: 0,
Expand All @@ -59,9 +59,9 @@ mod tests {
y: 1327294,
z: 631798,
};
let (sbp_result, _remaining_data) = ::parser::frame(&packet[..]);
let (sbp_result, _remaining_data) = crate::parser::frame(&packet[..]);
assert!(sbp_result.is_ok());
if let ::messages::SBP::MsgBaselineECEF(msg) = sbp_result.unwrap() {
if let crate::messages::SBP::MsgBaselineECEF(msg) = sbp_result.unwrap() {
assert_eq!(msg.sender_id, baseline_ecef_expectation.sender_id);
assert_eq!(msg.accuracy, baseline_ecef_expectation.accuracy);
assert_eq!(msg.flags, baseline_ecef_expectation.flags);
Expand All @@ -83,7 +83,7 @@ mod tests {
0x00, 0xdb, 0xbf, 0xde, 0xad, 0xbe, 0xef,
];
let mut reader = std::io::Cursor::new(packet);
let baseline_ecef_expectation = ::messages::navigation::MsgBaselineECEF {
let baseline_ecef_expectation = crate::messages::navigation::MsgBaselineECEF {
sender_id: Some(0x88d3),
accuracy: 0,
flags: 0,
Expand All @@ -93,12 +93,12 @@ mod tests {
y: 1327294,
z: 631798,
};
let mut parser = ::parser::Parser::new();
let mut parser = crate::parser::Parser::new();
// Iterate through the data until we hit something that is
// parsable
let sbp_result = parser.parse(&mut reader);
assert!(sbp_result.is_ok());
if let ::messages::SBP::MsgBaselineECEF(msg) = sbp_result.unwrap() {
if let crate::messages::SBP::MsgBaselineECEF(msg) = sbp_result.unwrap() {
assert_eq!(msg.sender_id, baseline_ecef_expectation.sender_id);
assert_eq!(msg.accuracy, baseline_ecef_expectation.accuracy);
assert_eq!(msg.flags, baseline_ecef_expectation.flags);
Expand Down
37 changes: 25 additions & 12 deletions rust/sbp/src/messages/acquisition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ extern crate byteorder;
#[allow(unused_imports)]
use self::byteorder::{LittleEndian, ReadBytesExt};
use super::gnss::*;
#[cfg(feature = "serialize")]
use serde::{Deserialize, Serialize};

/// Acq perfomance measurement and debug
///
/// Profile for a specific SV for debugging purposes
/// The message describes SV profile during acquisition time.
/// The message is used to debug and measure the performance.
///
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug)]
#[allow(non_snake_case)]
pub struct AcqSvProfile {
Expand Down Expand Up @@ -55,7 +58,7 @@ pub struct AcqSvProfile {
}

impl AcqSvProfile {
pub fn parse(_buf: &mut &[u8]) -> Result<AcqSvProfile, ::Error> {
pub fn parse(_buf: &mut &[u8]) -> Result<AcqSvProfile, crate::Error> {
Ok(AcqSvProfile {
job_type: _buf.read_u8()?,
status: _buf.read_u8()?,
Expand All @@ -71,15 +74,15 @@ impl AcqSvProfile {
cp: _buf.read_u32::<LittleEndian>()?,
})
}
pub fn parse_array(buf: &mut &[u8]) -> Result<Vec<AcqSvProfile>, ::Error> {
pub fn parse_array(buf: &mut &[u8]) -> Result<Vec<AcqSvProfile>, crate::Error> {
let mut v = Vec::new();
while buf.len() > 0 {
v.push(AcqSvProfile::parse(buf)?);
}
Ok(v)
}

pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result<Vec<AcqSvProfile>, ::Error> {
pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result<Vec<AcqSvProfile>, crate::Error> {
let mut v = Vec::new();
for _ in 0..n {
v.push(AcqSvProfile::parse(buf)?);
Expand All @@ -92,6 +95,7 @@ impl AcqSvProfile {
///
/// Deprecated.
///
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug)]
#[allow(non_snake_case)]
pub struct AcqSvProfileDep {
Expand Down Expand Up @@ -122,7 +126,7 @@ pub struct AcqSvProfileDep {
}

impl AcqSvProfileDep {
pub fn parse(_buf: &mut &[u8]) -> Result<AcqSvProfileDep, ::Error> {
pub fn parse(_buf: &mut &[u8]) -> Result<AcqSvProfileDep, crate::Error> {
Ok(AcqSvProfileDep {
job_type: _buf.read_u8()?,
status: _buf.read_u8()?,
Expand All @@ -138,15 +142,18 @@ impl AcqSvProfileDep {
cp: _buf.read_u32::<LittleEndian>()?,
})
}
pub fn parse_array(buf: &mut &[u8]) -> Result<Vec<AcqSvProfileDep>, ::Error> {
pub fn parse_array(buf: &mut &[u8]) -> Result<Vec<AcqSvProfileDep>, crate::Error> {
let mut v = Vec::new();
while buf.len() > 0 {
v.push(AcqSvProfileDep::parse(buf)?);
}
Ok(v)
}

pub fn parse_array_limit(buf: &mut &[u8], n: usize) -> Result<Vec<AcqSvProfileDep>, ::Error> {
pub fn parse_array_limit(
buf: &mut &[u8],
n: usize,
) -> Result<Vec<AcqSvProfileDep>, crate::Error> {
let mut v = Vec::new();
for _ in 0..n {
v.push(AcqSvProfileDep::parse(buf)?);
Expand All @@ -159,6 +166,7 @@ impl AcqSvProfileDep {
///
/// Deprecated.
///
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug)]
#[allow(non_snake_case)]
pub struct MsgAcqResultDepB {
Expand All @@ -175,7 +183,7 @@ pub struct MsgAcqResultDepB {
}

impl MsgAcqResultDepB {
pub fn parse(_buf: &mut &[u8]) -> Result<MsgAcqResultDepB, ::Error> {
pub fn parse(_buf: &mut &[u8]) -> Result<MsgAcqResultDepB, crate::Error> {
Ok(MsgAcqResultDepB {
sender_id: None,
snr: _buf.read_f32::<LittleEndian>()?,
Expand All @@ -201,6 +209,7 @@ impl super::SBPMessage for MsgAcqResultDepB {
///
/// Deprecated.
///
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug)]
#[allow(non_snake_case)]
pub struct MsgAcqResultDepA {
Expand All @@ -218,7 +227,7 @@ pub struct MsgAcqResultDepA {
}

impl MsgAcqResultDepA {
pub fn parse(_buf: &mut &[u8]) -> Result<MsgAcqResultDepA, ::Error> {
pub fn parse(_buf: &mut &[u8]) -> Result<MsgAcqResultDepA, crate::Error> {
Ok(MsgAcqResultDepA {
sender_id: None,
snr: _buf.read_f32::<LittleEndian>()?,
Expand All @@ -244,6 +253,7 @@ impl super::SBPMessage for MsgAcqResultDepA {
///
/// Deprecated.
///
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug)]
#[allow(non_snake_case)]
pub struct MsgAcqSvProfileDep {
Expand All @@ -253,7 +263,7 @@ pub struct MsgAcqSvProfileDep {
}

impl MsgAcqSvProfileDep {
pub fn parse(_buf: &mut &[u8]) -> Result<MsgAcqSvProfileDep, ::Error> {
pub fn parse(_buf: &mut &[u8]) -> Result<MsgAcqSvProfileDep, crate::Error> {
Ok(MsgAcqSvProfileDep {
sender_id: None,
acq_sv_profile: AcqSvProfileDep::parse_array(_buf)?,
Expand All @@ -276,6 +286,7 @@ impl super::SBPMessage for MsgAcqSvProfileDep {
///
/// Deprecated.
///
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug)]
#[allow(non_snake_case)]
pub struct MsgAcqResultDepC {
Expand All @@ -291,7 +302,7 @@ pub struct MsgAcqResultDepC {
}

impl MsgAcqResultDepC {
pub fn parse(_buf: &mut &[u8]) -> Result<MsgAcqResultDepC, ::Error> {
pub fn parse(_buf: &mut &[u8]) -> Result<MsgAcqResultDepC, crate::Error> {
Ok(MsgAcqResultDepC {
sender_id: None,
cn0: _buf.read_f32::<LittleEndian>()?,
Expand All @@ -318,6 +329,7 @@ impl super::SBPMessage for MsgAcqResultDepC {
/// The message describes all SV profiles during acquisition time.
/// The message is used to debug and measure the performance.
///
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug)]
#[allow(non_snake_case)]
pub struct MsgAcqSvProfile {
Expand All @@ -327,7 +339,7 @@ pub struct MsgAcqSvProfile {
}

impl MsgAcqSvProfile {
pub fn parse(_buf: &mut &[u8]) -> Result<MsgAcqSvProfile, ::Error> {
pub fn parse(_buf: &mut &[u8]) -> Result<MsgAcqSvProfile, crate::Error> {
Ok(MsgAcqSvProfile {
sender_id: None,
acq_sv_profile: AcqSvProfile::parse_array(_buf)?,
Expand All @@ -354,6 +366,7 @@ impl super::SBPMessage for MsgAcqSvProfile {
/// acquisition search space with the best carrier-to-noise (CN/0)
/// ratio.
///
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug)]
#[allow(non_snake_case)]
pub struct MsgAcqResult {
Expand All @@ -369,7 +382,7 @@ pub struct MsgAcqResult {
}

impl MsgAcqResult {
pub fn parse(_buf: &mut &[u8]) -> Result<MsgAcqResult, ::Error> {
pub fn parse(_buf: &mut &[u8]) -> Result<MsgAcqResult, crate::Error> {
Ok(MsgAcqResult {
sender_id: None,
cn0: _buf.read_f32::<LittleEndian>()?,
Expand Down
Loading