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
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ gen-rust:
-o $(SWIFTNAV_ROOT)/rust/ \
-r $(SBP_MAJOR_VERSION).$(SBP_MINOR_VERSION).$(SBP_PATCH_VERSION) \
--rust

$(call announce-begin,"Generating Rust tests")
cd $(SWIFTNAV_ROOT)/generator; \
$(SBP_GEN_BIN) -i $(SBP_TESTS_SPEC_DIR) \
-o $(SWIFTNAV_ROOT)/rust/sbp/tests/ \
-r $(SBP_MAJOR_VERSION).$(SBP_MINOR_VERSION).$(SBP_PATCH_VERSION) \
--test-rust

cd $(SWIFTNAV_ROOT)/rust/sbp && cargo fmt
$(call announce-begin,"Finished generating Rust bindings")

Expand Down
14 changes: 13 additions & 1 deletion c/include/libsbp/cpp/message_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@

namespace sbp {

/**
* Type traits containing meta-information for each SBP message type.
*
* These are only meant to be used by the C++ library at compile time.
* These are automatically generated, DO NOT EDIT.
*/
template<typename>
struct MessageTraits { };
struct MessageTraits;


template<>
Expand Down Expand Up @@ -803,6 +809,12 @@ struct MessageTraits<msg_vel_ecef_cov_t> {
};


template<>
struct MessageTraits<msg_protection_level_t> {
static constexpr u16 id = 534;
};


template<>
struct MessageTraits<msg_orient_quat_t> {
static constexpr u16 id = 544;
Expand Down
18 changes: 9 additions & 9 deletions c/test/auto_check_sbp_navigation_13.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,18 @@ START_TEST( test_auto_check_sbp_navigation_13 )
msg_pos_ecef_cov_t* msg = ( msg_pos_ecef_cov_t *)((void *)last_msg + 6);
// Run tests against fields
fail_unless(msg != 0, "stub to prevent warnings if msg isn't used");
fail_unless(msg->cov_x_x == 8, "incorrect value for cov_x_x, expected 8, is %d", msg->cov_x_x);
fail_unless(msg->cov_x_y == 7, "incorrect value for cov_x_y, expected 7, is %d", msg->cov_x_y);
fail_unless(msg->cov_x_z == 2, "incorrect value for cov_x_z, expected 2, is %d", msg->cov_x_z);
fail_unless(msg->cov_y_y == 6, "incorrect value for cov_y_y, expected 6, is %d", msg->cov_y_y);
fail_unless(msg->cov_y_z == 8, "incorrect value for cov_y_z, expected 8, is %d", msg->cov_y_z);
fail_unless(msg->cov_z_z == 5, "incorrect value for cov_z_z, expected 5, is %d", msg->cov_z_z);
fail_unless((msg->cov_x_x*100 - 8.0*100) < 0.05, "incorrect value for cov_x_x, expected 8.0, is %f", msg->cov_x_x);
fail_unless((msg->cov_x_y*100 - 7.0*100) < 0.05, "incorrect value for cov_x_y, expected 7.0, is %f", msg->cov_x_y);
fail_unless((msg->cov_x_z*100 - 2.0*100) < 0.05, "incorrect value for cov_x_z, expected 2.0, is %f", msg->cov_x_z);
fail_unless((msg->cov_y_y*100 - 6.0*100) < 0.05, "incorrect value for cov_y_y, expected 6.0, is %f", msg->cov_y_y);
fail_unless((msg->cov_y_z*100 - 8.0*100) < 0.05, "incorrect value for cov_y_z, expected 8.0, is %f", msg->cov_y_z);
fail_unless((msg->cov_z_z*100 - 5.0*100) < 0.05, "incorrect value for cov_z_z, expected 5.0, is %f", msg->cov_z_z);
fail_unless(msg->flags == 5, "incorrect value for flags, expected 5, is %d", msg->flags);
fail_unless(msg->n_sats == 4, "incorrect value for n_sats, expected 4, is %d", msg->n_sats);
fail_unless(msg->tow == 7, "incorrect value for tow, expected 7, is %d", msg->tow);
fail_unless(msg->x == 6, "incorrect value for x, expected 6, is %d", msg->x);
fail_unless(msg->y == 1, "incorrect value for y, expected 1, is %d", msg->y);
fail_unless(msg->z == 4, "incorrect value for z, expected 4, is %d", msg->z);
fail_unless((msg->x*100 - 6.0*100) < 0.05, "incorrect value for x, expected 6.0, is %f", msg->x);
fail_unless((msg->y*100 - 1.0*100) < 0.05, "incorrect value for y, expected 1.0, is %f", msg->y);
fail_unless((msg->z*100 - 4.0*100) < 0.05, "incorrect value for z, expected 4.0, is %f", msg->z);
}
}
END_TEST
Expand Down
18 changes: 9 additions & 9 deletions c/test/auto_check_sbp_navigation_16.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,16 @@ START_TEST( test_auto_check_sbp_navigation_16 )
msg_pos_llh_cov_t* msg = ( msg_pos_llh_cov_t *)((void *)last_msg + 6);
// Run tests against fields
fail_unless(msg != 0, "stub to prevent warnings if msg isn't used");
fail_unless(msg->cov_d_d == 2, "incorrect value for cov_d_d, expected 2, is %d", msg->cov_d_d);
fail_unless(msg->cov_e_d == 1, "incorrect value for cov_e_d, expected 1, is %d", msg->cov_e_d);
fail_unless(msg->cov_e_e == 6, "incorrect value for cov_e_e, expected 6, is %d", msg->cov_e_e);
fail_unless(msg->cov_n_d == 8, "incorrect value for cov_n_d, expected 8, is %d", msg->cov_n_d);
fail_unless(msg->cov_n_e == 5, "incorrect value for cov_n_e, expected 5, is %d", msg->cov_n_e);
fail_unless(msg->cov_n_n == 7, "incorrect value for cov_n_n, expected 7, is %d", msg->cov_n_n);
fail_unless((msg->cov_d_d*100 - 2.0*100) < 0.05, "incorrect value for cov_d_d, expected 2.0, is %f", msg->cov_d_d);
fail_unless((msg->cov_e_d*100 - 1.0*100) < 0.05, "incorrect value for cov_e_d, expected 1.0, is %f", msg->cov_e_d);
fail_unless((msg->cov_e_e*100 - 6.0*100) < 0.05, "incorrect value for cov_e_e, expected 6.0, is %f", msg->cov_e_e);
fail_unless((msg->cov_n_d*100 - 8.0*100) < 0.05, "incorrect value for cov_n_d, expected 8.0, is %f", msg->cov_n_d);
fail_unless((msg->cov_n_e*100 - 5.0*100) < 0.05, "incorrect value for cov_n_e, expected 5.0, is %f", msg->cov_n_e);
fail_unless((msg->cov_n_n*100 - 7.0*100) < 0.05, "incorrect value for cov_n_n, expected 7.0, is %f", msg->cov_n_n);
fail_unless(msg->flags == 5, "incorrect value for flags, expected 5, is %d", msg->flags);
fail_unless(msg->height == 0, "incorrect value for height, expected 0, is %d", msg->height);
fail_unless(msg->lat == 0, "incorrect value for lat, expected 0, is %d", msg->lat);
fail_unless(msg->lon == 7, "incorrect value for lon, expected 7, is %d", msg->lon);
fail_unless((msg->height*100 - 0.0*100) < 0.05, "incorrect value for height, expected 0.0, is %f", msg->height);
fail_unless((msg->lat*100 - 0.0*100) < 0.05, "incorrect value for lat, expected 0.0, is %f", msg->lat);
fail_unless((msg->lon*100 - 7.0*100) < 0.05, "incorrect value for lon, expected 7.0, is %f", msg->lon);
fail_unless(msg->n_sats == 5, "incorrect value for n_sats, expected 5, is %d", msg->n_sats);
fail_unless(msg->tow == 7, "incorrect value for tow, expected 7, is %d", msg->tow);
}
Expand Down
12 changes: 6 additions & 6 deletions c/test/auto_check_sbp_navigation_18.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ START_TEST( test_auto_check_sbp_navigation_18 )
msg_vel_body_t* msg = ( msg_vel_body_t *)((void *)last_msg + 6);
// Run tests against fields
fail_unless(msg != 0, "stub to prevent warnings if msg isn't used");
fail_unless(msg->cov_x_x == 0, "incorrect value for cov_x_x, expected 0, is %d", msg->cov_x_x);
fail_unless(msg->cov_x_y == 5, "incorrect value for cov_x_y, expected 5, is %d", msg->cov_x_y);
fail_unless(msg->cov_x_z == 7, "incorrect value for cov_x_z, expected 7, is %d", msg->cov_x_z);
fail_unless(msg->cov_y_y == 7, "incorrect value for cov_y_y, expected 7, is %d", msg->cov_y_y);
fail_unless(msg->cov_y_z == 3, "incorrect value for cov_y_z, expected 3, is %d", msg->cov_y_z);
fail_unless(msg->cov_z_z == 2, "incorrect value for cov_z_z, expected 2, is %d", msg->cov_z_z);
fail_unless((msg->cov_x_x*100 - 0.0*100) < 0.05, "incorrect value for cov_x_x, expected 0.0, is %f", msg->cov_x_x);
fail_unless((msg->cov_x_y*100 - 5.0*100) < 0.05, "incorrect value for cov_x_y, expected 5.0, is %f", msg->cov_x_y);
fail_unless((msg->cov_x_z*100 - 7.0*100) < 0.05, "incorrect value for cov_x_z, expected 7.0, is %f", msg->cov_x_z);
fail_unless((msg->cov_y_y*100 - 7.0*100) < 0.05, "incorrect value for cov_y_y, expected 7.0, is %f", msg->cov_y_y);
fail_unless((msg->cov_y_z*100 - 3.0*100) < 0.05, "incorrect value for cov_y_z, expected 3.0, is %f", msg->cov_y_z);
fail_unless((msg->cov_z_z*100 - 2.0*100) < 0.05, "incorrect value for cov_z_z, expected 2.0, is %f", msg->cov_z_z);
fail_unless(msg->flags == 8, "incorrect value for flags, expected 8, is %d", msg->flags);
fail_unless(msg->n_sats == 3, "incorrect value for n_sats, expected 3, is %d", msg->n_sats);
fail_unless(msg->tow == 1, "incorrect value for tow, expected 1, is %d", msg->tow);
Expand Down
12 changes: 6 additions & 6 deletions c/test/auto_check_sbp_navigation_20.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ START_TEST( test_auto_check_sbp_navigation_20 )
msg_vel_ecef_cov_t* msg = ( msg_vel_ecef_cov_t *)((void *)last_msg + 6);
// Run tests against fields
fail_unless(msg != 0, "stub to prevent warnings if msg isn't used");
fail_unless(msg->cov_x_x == 2, "incorrect value for cov_x_x, expected 2, is %d", msg->cov_x_x);
fail_unless(msg->cov_x_y == 2, "incorrect value for cov_x_y, expected 2, is %d", msg->cov_x_y);
fail_unless(msg->cov_x_z == 2, "incorrect value for cov_x_z, expected 2, is %d", msg->cov_x_z);
fail_unless(msg->cov_y_y == 2, "incorrect value for cov_y_y, expected 2, is %d", msg->cov_y_y);
fail_unless(msg->cov_y_z == 1, "incorrect value for cov_y_z, expected 1, is %d", msg->cov_y_z);
fail_unless(msg->cov_z_z == 3, "incorrect value for cov_z_z, expected 3, is %d", msg->cov_z_z);
fail_unless((msg->cov_x_x*100 - 2.0*100) < 0.05, "incorrect value for cov_x_x, expected 2.0, is %f", msg->cov_x_x);
fail_unless((msg->cov_x_y*100 - 2.0*100) < 0.05, "incorrect value for cov_x_y, expected 2.0, is %f", msg->cov_x_y);
fail_unless((msg->cov_x_z*100 - 2.0*100) < 0.05, "incorrect value for cov_x_z, expected 2.0, is %f", msg->cov_x_z);
fail_unless((msg->cov_y_y*100 - 2.0*100) < 0.05, "incorrect value for cov_y_y, expected 2.0, is %f", msg->cov_y_y);
fail_unless((msg->cov_y_z*100 - 1.0*100) < 0.05, "incorrect value for cov_y_z, expected 1.0, is %f", msg->cov_y_z);
fail_unless((msg->cov_z_z*100 - 3.0*100) < 0.05, "incorrect value for cov_z_z, expected 3.0, is %f", msg->cov_z_z);
fail_unless(msg->flags == 4, "incorrect value for flags, expected 4, is %d", msg->flags);
fail_unless(msg->n_sats == 3, "incorrect value for n_sats, expected 3, is %d", msg->n_sats);
fail_unless(msg->tow == 2, "incorrect value for tow, expected 2, is %d", msg->tow);
Expand Down
12 changes: 6 additions & 6 deletions c/test/auto_check_sbp_navigation_23.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ START_TEST( test_auto_check_sbp_navigation_23 )
msg_vel_ned_cov_t* msg = ( msg_vel_ned_cov_t *)((void *)last_msg + 6);
// Run tests against fields
fail_unless(msg != 0, "stub to prevent warnings if msg isn't used");
fail_unless(msg->cov_d_d == 1, "incorrect value for cov_d_d, expected 1, is %d", msg->cov_d_d);
fail_unless(msg->cov_e_d == 1, "incorrect value for cov_e_d, expected 1, is %d", msg->cov_e_d);
fail_unless(msg->cov_e_e == 1, "incorrect value for cov_e_e, expected 1, is %d", msg->cov_e_e);
fail_unless(msg->cov_n_d == 1, "incorrect value for cov_n_d, expected 1, is %d", msg->cov_n_d);
fail_unless(msg->cov_n_e == 1, "incorrect value for cov_n_e, expected 1, is %d", msg->cov_n_e);
fail_unless(msg->cov_n_n == 1, "incorrect value for cov_n_n, expected 1, is %d", msg->cov_n_n);
fail_unless((msg->cov_d_d*100 - 1.0*100) < 0.05, "incorrect value for cov_d_d, expected 1.0, is %f", msg->cov_d_d);
fail_unless((msg->cov_e_d*100 - 1.0*100) < 0.05, "incorrect value for cov_e_d, expected 1.0, is %f", msg->cov_e_d);
fail_unless((msg->cov_e_e*100 - 1.0*100) < 0.05, "incorrect value for cov_e_e, expected 1.0, is %f", msg->cov_e_e);
fail_unless((msg->cov_n_d*100 - 1.0*100) < 0.05, "incorrect value for cov_n_d, expected 1.0, is %f", msg->cov_n_d);
fail_unless((msg->cov_n_e*100 - 1.0*100) < 0.05, "incorrect value for cov_n_e, expected 1.0, is %f", msg->cov_n_e);
fail_unless((msg->cov_n_n*100 - 1.0*100) < 0.05, "incorrect value for cov_n_n, expected 1.0, is %f", msg->cov_n_n);
fail_unless(msg->e == 1, "incorrect value for e, expected 1, is %d", msg->e);
fail_unless(msg->flags == 0, "incorrect value for flags, expected 0, is %d", msg->flags);
fail_unless(msg->n == 1, "incorrect value for n, expected 1, is %d", msg->n);
Expand Down
6 changes: 3 additions & 3 deletions c/test/auto_check_sbp_orientation_28.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ START_TEST( test_auto_check_sbp_orientation_28 )
fail_unless(msg != 0, "stub to prevent warnings if msg isn't used");
fail_unless(msg->flags == 3, "incorrect value for flags, expected 3, is %d", msg->flags);
fail_unless(msg->pitch == 2, "incorrect value for pitch, expected 2, is %d", msg->pitch);
fail_unless(msg->pitch_accuracy == 3, "incorrect value for pitch_accuracy, expected 3, is %d", msg->pitch_accuracy);
fail_unless((msg->pitch_accuracy*100 - 3.0*100) < 0.05, "incorrect value for pitch_accuracy, expected 3.0, is %f", msg->pitch_accuracy);
fail_unless(msg->roll == 1, "incorrect value for roll, expected 1, is %d", msg->roll);
fail_unless(msg->roll_accuracy == 7, "incorrect value for roll_accuracy, expected 7, is %d", msg->roll_accuracy);
fail_unless((msg->roll_accuracy*100 - 7.0*100) < 0.05, "incorrect value for roll_accuracy, expected 7.0, is %f", msg->roll_accuracy);
fail_unless(msg->tow == 1, "incorrect value for tow, expected 1, is %d", msg->tow);
fail_unless(msg->yaw == 8, "incorrect value for yaw, expected 8, is %d", msg->yaw);
fail_unless(msg->yaw_accuracy == 7, "incorrect value for yaw_accuracy, expected 7, is %d", msg->yaw_accuracy);
fail_unless((msg->yaw_accuracy*100 - 7.0*100) < 0.05, "incorrect value for yaw_accuracy, expected 7.0, is %f", msg->yaw_accuracy);
}
}
END_TEST
Expand Down
8 changes: 4 additions & 4 deletions c/test/auto_check_sbp_orientation_29.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ START_TEST( test_auto_check_sbp_orientation_29 )
fail_unless(msg->flags == 1, "incorrect value for flags, expected 1, is %d", msg->flags);
fail_unless(msg->tow == 0, "incorrect value for tow, expected 0, is %d", msg->tow);
fail_unless(msg->w == 3, "incorrect value for w, expected 3, is %d", msg->w);
fail_unless(msg->w_accuracy == 3, "incorrect value for w_accuracy, expected 3, is %d", msg->w_accuracy);
fail_unless((msg->w_accuracy*100 - 3.0*100) < 0.05, "incorrect value for w_accuracy, expected 3.0, is %f", msg->w_accuracy);
fail_unless(msg->x == 7, "incorrect value for x, expected 7, is %d", msg->x);
fail_unless(msg->x_accuracy == 4, "incorrect value for x_accuracy, expected 4, is %d", msg->x_accuracy);
fail_unless((msg->x_accuracy*100 - 4.0*100) < 0.05, "incorrect value for x_accuracy, expected 4.0, is %f", msg->x_accuracy);
fail_unless(msg->y == 8, "incorrect value for y, expected 8, is %d", msg->y);
fail_unless(msg->y_accuracy == 8, "incorrect value for y_accuracy, expected 8, is %d", msg->y_accuracy);
fail_unless((msg->y_accuracy*100 - 8.0*100) < 0.05, "incorrect value for y_accuracy, expected 8.0, is %f", msg->y_accuracy);
fail_unless(msg->z == 4, "incorrect value for z, expected 4, is %d", msg->z);
fail_unless(msg->z_accuracy == 3, "incorrect value for z_accuracy, expected 3, is %d", msg->z_accuracy);
fail_unless((msg->z_accuracy*100 - 3.0*100) < 0.05, "incorrect value for z_accuracy, expected 3.0, is %f", msg->z_accuracy);
}
}
END_TEST
Expand Down
10 changes: 8 additions & 2 deletions generator/sbpg/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def get_args():
parser.add_argument('--rust',
action="store_true",
help='Target language: Rust.')
parser.add_argument('--test-rust',
action="store_true",
help='Target language: Rust tests.')
parser.add_argument('--latex',
action="store_true",
help='Target language: LaTeX.')
Expand All @@ -81,7 +84,7 @@ def main():
# Parse and validate arguments.
args = get_args().parse_args()
verbose = args.verbose
assert args.jsonschema or 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, \
assert args.jsonschema or 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 or args.test_rust, \
"Please specify a target language."
input_file = os.path.abspath(args.input_file[0])
assert len(args.input_file) == 1
Expand All @@ -92,7 +95,7 @@ def main():
assert os.path.exists(output_dir), \
"Invalid output directory: %s. Exiting!" % output_dir
# Ingest, parse, and validate.
test_mode = args.test_c
test_mode = args.test_c or args.test_rust

if test_mode:
file_index = yaml.resolve_test_deps(*yaml.get_files(input_file))
Expand Down Expand Up @@ -146,6 +149,9 @@ def main():
elif args.rust:
import sbpg.targets.rust as rs
rs.render_source(output_dir, parsed)
elif args.test_rust:
import sbpg.targets.test_rust as test_rs
test_rs.render_source(output_dir, parsed)
elif args.protobuf:
import sbpg.targets.protobuf as pb
pb.render_source(output_dir, parsed)
Expand Down
29 changes: 29 additions & 0 deletions generator/sbpg/targets/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python
# Copyright (C) 2019 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.

def string_type(value):
return type(value) == str

def array_type(value):
return type(value) == list

def dict_type(value):
return type(value) == dict

def float_type(value):
return type(value) == float

def is_empty(value):
return len(value) == 0

def to_str(value):
return str(value)

10 changes: 5 additions & 5 deletions generator/sbpg/targets/resources/sbp_c_test.c.j2
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ START_TEST( test_(((s.suite_name))) )
//

((*- macro compare_value(prefix, value) *))
((*- if value is stringType *))
((*- if value is string_type *))
fail_unless(strstr(msg->(((prefix))), (((value|str_escape)))) != NULL, "incorrect value for msg->(((prefix))), expected string '%s', is '%s'", (((value|str_escape))), msg->(((prefix))));
((*- elif value is arrayType *))
((*- for ff in value *))((( compare_value( (((prefix))) + '[' + (((loop.index0|toStr))) + ']', (((ff))) ) )))((*- endfor *))
((*- elif value is dictType *))
((*- elif value is array_type *))
((*- for ff in value *))((( compare_value( (((prefix))) + '[' + (((loop.index0|to_str))) + ']', (((ff))) ) )))((*- endfor *))
((*- elif value is dict_type *))
((*- for k in (((value|sorted))) *))((( compare_value( (((prefix))) + '.' + (((k))), (((value[k]))) ) )))((*- endfor *))
((*- elif value is floatType *))((=
((*- elif value is float_type *))((=
Note: the ("%.12g"|format(value)|float) filter is intended to keep float
literal precision unchanged whether generated under Python 2.7 or 3.x. =))
fail_unless((msg->(((prefix)))*100 - ((("%.12g"|format(value)|float)))*100) < 0.05, "incorrect value for (((prefix))), expected ((("%.12g"|format(value)|float))), is %f", msg->(((prefix))));
Expand Down
2 changes: 1 addition & 1 deletion generator/sbpg/targets/resources/sbp_messages_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use self::(((p.identifier|mod_name)))::(((m.identifier|camel_case)));
((*- endfor *))
((*- endfor *))

trait SBPMessage {
pub trait SBPMessage {
const MSG_ID: u16;

fn get_sender_id(&self) -> Option<u16>;
Expand Down
Loading