Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5920a6e
Add rust template from cargo
gsmcmullin Mar 12, 2018
1dfcb5b
rust: First cut at frame decoding.
gsmcmullin Mar 12, 2018
1e6e5dc
rust: Message structure generation
gsmcmullin Mar 13, 2018
4058370
rust: Try parsing messages
gsmcmullin Mar 13, 2018
37cd827
rust: Parse arrays and clean up warnings.
gsmcmullin Mar 14, 2018
1b0245b
rust: Better error reporting
gsmcmullin Mar 14, 2018
3ffbde0
rust: Don't panic on parse errors
gsmcmullin Mar 14, 2018
5ba8bfd
Add cargo for Travis
gsmcmullin Mar 15, 2018
cba53fb
rust: Add generated junk
gsmcmullin Mar 15, 2018
925a6b1
Merge branch 'master' into gareth/rust-hackathon
May 23, 2018
3ca0a96
Merge remote-tracking branch 'origin/master' into jbangelo/rust-dev
jbangelo Jun 15, 2019
d435b69
Regenerated all the messages
jbangelo Jun 17, 2019
239ffce
Reimplemented the de-framing function using nom. Added a new "parser"…
jbangelo Jun 17, 2019
f698cd8
Simplified the parser code
jbangelo Jul 17, 2019
b11fd88
Added sender ID to the messages, and added a basic SBPMessage trait
jbangelo Jul 17, 2019
81f629a
Regnerated messages
jbangelo Jul 17, 2019
a24824f
Merge remote-tracking branch 'origin/master' into jbangelo/rust-dev
jbangelo Jul 17, 2019
c5d3557
Fixed up the travis config
jbangelo Jul 17, 2019
57ac74f
Fixed tests
jbangelo Jul 18, 2019
f2b58d5
Added rust build to the travis config
jbangelo Jul 18, 2019
8aa3570
Enabled verbose tests
jbangelo Jul 18, 2019
f36cbc2
Changed rust generator to make doc comments
jbangelo Jul 22, 2019
69d0634
Regenerated all of the rust code
jbangelo Jul 22, 2019
eb0bf56
Removed the unneeded MessageError enum
jbangelo Jul 22, 2019
7ce631e
Added a crate description and some missing doc comments about the par…
jbangelo Jul 22, 2019
bd6d619
Fixed up the module level comments
jbangelo Jul 22, 2019
a56f123
Changed rust doc comments to keep message module description short
jbangelo Jul 23, 2019
52cf351
Updated the Cargo file with more info
jbangelo Jul 23, 2019
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.DS_Store
*.*~
limbo/
.idea/

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down Expand Up @@ -71,4 +72,7 @@ sbp_out.*
.stack-work/
.build/

# rust
Cargo.lock

python/sbp/_version.py
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ matrix:
- make test-c
after_success:
bash <(curl -s https://codecov.io/bash) -s c/build || echo "Codecov did not collect coverage reports";
- env:
language: rust
rust:
- stable
script:
- make test-rust

deploy:
provider: releases
Expand Down
30 changes: 25 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SBP_PATCH_VERSION := $(word 3, $(subst ., , $(SBP_VERSION)))

CHANGELOG_MAX_ISSUES := 100

.PHONY: help test release dist clean all docs pdf html c deps-c gen-c test-c python deps-python gen-python test-python javascript deps-javascript gen-javascript test-javascript java deps-java gen-java test-java haskell deps-haskell gen-haskell test-haskell haskell deps-protobuf gen-protobuf test-protobuf verify-prereq-generator verify-prereq-c verify-prereq-javascript verify-prereq-python verify-prereq-java verify-prereq-haskell verify-prereq-protobuf mapping
.PHONY: help test release dist clean all docs pdf html c deps-c gen-c test-c python deps-python gen-python test-python javascript deps-javascript gen-javascript test-javascript java deps-java gen-java test-java haskell deps-haskell gen-haskell test-haskell haskell deps-protobuf gen-protobuf test-protobuf verify-prereq-generator verify-prereq-c verify-prereq-javascript verify-prereq-python verify-prereq-java verify-prereq-haskell verify-prereq-protobuf mapping rust deps-rust gen-rust test-rust

# Functions
define announce-begin
Expand Down Expand Up @@ -53,12 +53,13 @@ help:
@echo " pythonNG to make Python (JIT) bindings"
@echo " haskell to make Haskell bindings"
@echo " java to make Java bindings"
@echo " rust to make Rust bindings"
@echo " protobuf to make Protocol Buffer bindings"
@echo " release to handle some release tasks"
@echo " test to run all tests"
@echo

all: c python pythonNG javascript java docs haskell protobuf
all: c python pythonNG javascript java docs haskell protobuf rust
clean:
@echo "Removing the ./c/build directory..."
rm -r $(SWIFTNAV_ROOT)/c/build
Expand All @@ -70,6 +71,7 @@ pythonNG: deps-python gen-pythonNG
javascript: deps-javascript gen-javascript test-javascript
java: deps-java gen-java test-java
haskell: deps-haskell gen-haskell test-haskell
rust: deps-rust gen-rust test-rust
protobuf: deps-protobuf gen-protobuf test-protobuf

# Prerequisite verification
Expand Down Expand Up @@ -100,7 +102,9 @@ verify-prereq-java: verify-prereq-generator

verify-prereq-haskell: verify-prereq-generator

verify-prereq-protobuf: verify-prereq-generator
verify-prereq-rust: ;

verify-prereq-protobuf: verify-prereq-protobuf

verify-prereq-docs: verify-prereq-generator
@command -v pdflatex 1>/dev/null 2>/dev/null || { echo >&2 -e "I require \`pdflatex\` but it's not installed. Aborting.\n\nHave you installed pdflatex? See the generator readme (Installing instructions) at \`generator/README.md\` for setup instructions.\n"; exit 1; }
Expand All @@ -122,6 +126,8 @@ deps-java: verify-prereq-java

deps-haskell: verify-prereq-haskell

deps-rust: verify-prereq-rust

deps-protobuf: verify-prereq-protobuf

# Generators
Expand Down Expand Up @@ -192,6 +198,16 @@ gen-haskell:
--haskell
$(call announce-begin,"Finished generating Haskell bindings")

gen-rust:
$(call announce-begin,"Generating Rust bindings")
cd $(SWIFTNAV_ROOT)/generator; \
$(SBP_GEN_BIN) -i $(SBP_SPEC_DIR) \
-o $(SWIFTNAV_ROOT)/rust/ \
-r $(SBP_MAJOR_VERSION).$(SBP_MINOR_VERSION).$(SBP_PATCH_VERSION) \
--rust
cd $(SWIFTNAV_ROOT)/rust/sbp && cargo fmt
$(call announce-begin,"Finished generating Rust bindings")

gen-protobuf:
$(call announce-begin,"Generating Protocol Buffers bindings")
cd $(SWIFTNAV_ROOT)/generator; \
Expand All @@ -201,10 +217,9 @@ gen-protobuf:
--protobuf
$(call announce-begin,"Finished generating Protocol Buffers bindings")


# Testers

test: test-all-begin test-c test-java test-python test-haskell test-javascript test-all-end
test: test-all-begin test-c test-java test-python test-haskell test-javascript test-rust test-all-end

test-all-begin:
$(call announce-begin,"Running all tests")
Expand Down Expand Up @@ -245,6 +260,11 @@ test-haskell:
cd $(SWIFTNAV_ROOT)/haskell/ && stack build --test --allow-different-user
$(call announce-end,"Finished running Haskell tests")

test-rust:
$(call announce-begin,"Running Rust tests")
cd $(SWIFTNAV_ROOT)/rust/sbp && cargo test --verbose
$(call announce-end,"Finished running Rust tests")

test-protobuf:
$(call announce-begin,"Running Protocol Buffer tests")
$(call announce-end,"Finished running Protocol Buffer tests")
Expand Down
11 changes: 10 additions & 1 deletion generator/sbpg/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import sbpg.targets.python as py
import sbpg.targets.pythonNG as pyNG
import sbpg.targets.javascript as js
import sbpg.targets.rust as rs

def get_args():
parser = argparse.ArgumentParser(description='Swift Navigation SBP generator.')
Expand Down Expand Up @@ -61,6 +62,9 @@ def get_args():
parser.add_argument('--java',
action="store_true",
help='Target language: Java!')
parser.add_argument('--rust',
action="store_true",
help='Target language: Rust.')
parser.add_argument('--latex',
action="store_true",
help='Target language: LaTeX.')
Expand All @@ -84,7 +88,7 @@ def main():
# Parse and validate arguments.
args = get_args().parse_args()
verbose = args.verbose
assert args.pythonNG or args.python or args.javascript or args.c or args.test_c or args.haskell or args.latex or args.protobuf or args.java, \
assert args.pythonNG or args.python or args.javascript or args.c or args.test_c or args.haskell or args.latex or args.protobuf or args.java or args.rust, \
"Please specify a target language."
input_file = os.path.abspath(args.input_file[0])
assert len(args.input_file) == 1
Expand Down Expand Up @@ -138,6 +142,8 @@ def main():
hs.render_source(output_dir, parsed)
elif args.java:
java.render_source(output_dir, parsed)
elif args.rust:
rs.render_source(output_dir, parsed)
elif args.protobuf:
pb.render_source(output_dir, parsed)
if args.c:
Expand All @@ -151,6 +157,9 @@ def main():
elif args.java:
parsed = [yaml.parse_spec(spec) for _, spec in file_index_items]
java.render_table(output_dir, parsed)
elif args.rust:
parsed = [yaml.parse_spec(spec) for spec in file_index.values()]
rs.render_mod(output_dir, parsed)
elif args.test_c:
test_c.render_check_suites(output_dir, all_specs)
test_c.render_check_main(output_dir, all_specs)
Expand Down
55 changes: 55 additions & 0 deletions generator/sbpg/targets/resources/sbp_messages_mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (C) 2015-2018 Swift Navigation Inc.
// Contact: Swift Navigation <dev@swiftnav.com>
//
// This source is subject to the license found in the file 'LICENSE' which must
// be be distributed together with this source. All other rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

((*- for m in mods *))
pub mod (((m)));
((*- endfor *))

((*- for p in packages *))
((*- for m in p.definitions *))
((*- if m.sbp_id *))
use self::(((p.identifier|mod_name)))::(((m.identifier|camel_case)));
((*- endif *))
((*- endfor *))
((*- endfor *))

trait SBPMessage {
const MSG_ID: u16;

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

#[derive(Debug)]
pub enum SBP {
Unknown { msg_id: u16, sender_id: u16, payload: Vec<u8> },
((*- for m in msgs *))
(((m.identifier|camel_case)))( (((m.identifier|camel_case))) ),
((*- endfor *))
}

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 {
((*- for m in msgs *))
(((m.sbp_id))) => {
let mut msg = (((m.identifier|camel_case)))::parse(payload)?;
msg.set_sender_id(sender_id);
Ok(SBP::(((m.identifier|camel_case)))(msg))
},
((*- endfor *))
_ => Ok(SBP::Unknown { msg_id: msg_id, sender_id: sender_id, payload: payload.to_vec() })
};
match x {
Ok(x) => Ok(x),
Err(_) => Err(::Error::ParseError),
}
}
}
92 changes: 92 additions & 0 deletions generator/sbpg/targets/resources/sbp_messages_template.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright (C) 2015-2018 Swift Navigation Inc.
// Contact: Swift Navigation <dev@swiftnav.com>
//
// This source is subject to the license found in the file 'LICENSE' which must
// be be distributed together with this source. All other rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

//****************************************************************************
// Automatically generated from yaml/(((filepath)))
// with generate.py. Please do not hand edit!
//****************************************************************************/

//! (((description | replace("\n", "\n//! "))))

extern crate byteorder;
#[allow(unused_imports)]
use self::byteorder::{LittleEndian,ReadBytesExt};

((*- for i in includes *))
use super::(((i)))::*;
((*- endfor *))

((* for m in msgs *))
((*- if m.desc *))
/// (((m.short_desc)))
///
(((m.desc|commentify)))
///
((*- endif *))
#[derive(Debug)]
#[allow(non_snake_case)]
pub struct (((m.identifier|camel_case))) {
((*- if m.sbp_id *))
pub sender_id: Option<u16>,
((*- endif *))
((*- for f in m.fields *))
((*- if f.desc *))
/// (((f.desc | replace("\n", " ") | wordwrap(width=72, wrapstring="\n /// "))))
((*- endif *))
pub (((f.identifier))): (((f|type_map))),
((*- endfor *))
}

impl (((m.identifier|camel_case))) {
pub fn parse(_buf: &mut &[u8]) -> Result<(((m.identifier|camel_case))), ::Error> {
Ok( (((m.identifier|camel_case))){
((*- if m.sbp_id *))
sender_id: None,
((*- endif *))
((*- for f in m.fields *))
(((f.identifier))): (((f|parse_type)))?,
((*- endfor *))
} )
}

((*- if not m.sbp_id *))
pub fn parse_array(buf: &mut &[u8]) -> Result<Vec<(((m.identifier|camel_case)))>, ::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> {
let mut v = Vec::new();
for _ in 0..n {
v.push( (((m.identifier|camel_case)))::parse(buf)? );
}
Ok(v)
}
((*- endif *))
}

((*- if m.sbp_id *))
impl super::SBPMessage for (((m.identifier|camel_case))) {
const MSG_ID: u16 = (((m.sbp_id)));

fn get_sender_id(&self) -> Option<u16> {
self.sender_id
}

fn set_sender_id(&mut self, new_id: u16) {
self.sender_id = Some(new_id);
}
}
((*- endif *))

((* endfor *))
Loading