Skip to content

Commit

Permalink
Fix kaitai generator
Browse files Browse the repository at this point in the history
  • Loading branch information
woodfell committed Dec 14, 2023
1 parent d71844e commit 7d18e77
Show file tree
Hide file tree
Showing 251 changed files with 13,598 additions and 60 deletions.
2 changes: 1 addition & 1 deletion generator/sbpg/targets/kaitai.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def get_type(f, type_map=KAITAI_CODE):
s = f.options['size'].value
return """{}
repeat: expr
repeat-expr: {}""".format(type_map.get(f_.type_id, 'u8'), s)
repeat-expr: {}""".format(type_map.get(f_.type_id, get_custom_type(fill)), s)
else:
return """{}
repeat: eos""".format(type_map.get(fill, get_custom_type(fill)))
Expand Down
2 changes: 2 additions & 0 deletions generator/sbpg/targets/test_kaitai_perl.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def render_source(output_dir, package_spec, jenv=JENV):
"""
Render and output a .t file containing test cases
"""
if len(package_spec.tests) == 0:
return
path, name = package_spec.filepath
destination_filename = "{}/{}.t".format(output_dir, name)
test_template = JENV.get_template(TEMPLATE_NAME)
Expand Down
2 changes: 2 additions & 0 deletions generator/sbpg/targets/test_kaitai_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def render_source(output_dir, package_spec, jenv=JENV):
"""
Render and output a .py file containing test cases
"""
if len(package_spec.tests) == 0:
return
path, name = package_spec.filepath
destination_filename = "{}/test_{}.py".format(output_dir, name)
test_template = JENV.get_template(TEMPLATE_NAME)
Expand Down
4 changes: 2 additions & 2 deletions kaitai/ksy/sbp.ksy
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
#
# Kaitai Struct definition file for Swift Binary Protocol 4.15.1-alpha
# Kaitai Struct definition file for Swift Binary Protocol 5.0.4-alpha
#
# Automatically generated with generate.py. Do not hand edit!

Expand Down Expand Up @@ -590,4 +590,4 @@ types:
2307: vehicle::msg_odometry
2308: vehicle::msg_wheeltick
- id: crc
type: u2
type: u2
6 changes: 3 additions & 3 deletions kaitai/ksy/tracking.ksy
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ types:
- id: corrs
doc: |
Early, Prompt and Late correlations
type: u8
type: tracking_channel_correlation
repeat: expr
repeat-expr: 3

Expand Down Expand Up @@ -333,7 +333,7 @@ types:
- id: corrs
doc: |
Early, Prompt and Late correlations
type: u8
type: tracking_channel_correlation_dep
repeat: expr
repeat-expr: 3

Expand All @@ -352,7 +352,7 @@ types:
- id: corrs
doc: |
Early, Prompt and Late correlations
type: u8
type: tracking_channel_correlation_dep
repeat: expr
repeat-expr: 3

Expand Down
5 changes: 1 addition & 4 deletions kaitai/perl/KaitaiSbp/FileIo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,7 @@ sub _read {
my ($self) = @_;

$self->{sequence} = $self->{_io}->read_u4le();
$self->{contents} = [];
while (!$self->{_io}->is_eof()) {
push @{$self->{contents}}, $self->{_io}->read_u1();
}
$self->{contents} = Encode::decode("ascii", $self->{_io}->read_bytes_full());
}

sub sequence {
Expand Down
6 changes: 3 additions & 3 deletions kaitai/perl/KaitaiSbp/Tracking.pm
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ sub _read {
$self->{corrs} = [];
my $n_corrs = 3;
for (my $i = 0; $i < $n_corrs; $i++) {
push @{$self->{corrs}}, $self->{_io}->read_u8le();
push @{$self->{corrs}}, Tracking::TrackingChannelCorrelationDep->new($self->{_io}, $self, $self->{_root});
}
}

Expand Down Expand Up @@ -645,7 +645,7 @@ sub _read {
$self->{corrs} = [];
my $n_corrs = 3;
for (my $i = 0; $i < $n_corrs; $i++) {
push @{$self->{corrs}}, $self->{_io}->read_u8le();
push @{$self->{corrs}}, Tracking::TrackingChannelCorrelation->new($self->{_io}, $self, $self->{_root});
}
}

Expand Down Expand Up @@ -942,7 +942,7 @@ sub _read {
$self->{corrs} = [];
my $n_corrs = 3;
for (my $i = 0; $i < $n_corrs; $i++) {
push @{$self->{corrs}}, $self->{_io}->read_u8le();
push @{$self->{corrs}}, Tracking::TrackingChannelCorrelationDep->new($self->{_io}, $self, $self->{_root});
}
}

Expand Down
62 changes: 62 additions & 0 deletions kaitai/perl/KaitaiSbp/t/auto_check_sbp_acquisition_MsgAcqResult.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/perl -w
#
# Copyright (C) 2015-2023 Swift Navigation Inc.
# Contact: https://support.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.
#
# Test cases automatically generated from spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqResult.yaml
# with generate.py. Do not modify by hand!

use strict;

BEGIN {
# add grandparent directory to include path
use Cwd qw(realpath);
use File::Basename;
unshift @INC, realpath(dirname($0))."/../../";
}

use KaitaiSbp::Sbp;
use KaitaiSbp::ParseUtils;
use IO::KaitaiStruct;
use Test::More;
use JSON::PP;
use MIME::Base64;
sub test_auto_check_sbp_acquisition_msg_acq_result_1() {
my $buf = decode_base64("VS8AwwQOAABoQWZmkELNxABGCADPvQ==");
my $stream = IO::KaitaiStruct::Stream->new($buf);
my $msg = ParseUtils::get_flattened_msg(Sbp::SbpMessage->new($stream));

is($msg->{'crc'}, 0xbdcf, "crc");

is($msg->{'length'}, 14, "length");

is($msg->{'msg_type'}, 0x2f, "msg_type");

is($msg->{'payload'}, "AABoQWZmkELNxABGCAA=", "payload");

is($msg->{'preamble'}, 0x55, "preamble");

is($msg->{'sender'}, 0x04c3, "sender");

my $json = JSON::PP->new->convert_blessed->canonical;

is($msg->cf(), 8241.2001953125, "cf");

is($msg->cn0(), 14.5, "cn0");

is($msg->cp(), 72.19999694824219, "cp");

is($json->encode($msg->sid()), $json->encode($json->decode(q{{"code":0,"sat":8}})), "sid");

is($json->encode($msg), $json->encode($json->decode(q{{"cf":8241.2001953125,"cn0":14.5,"cp":72.19999694824219,"crc":48591,"length":14,"msg_type":47,"payload":"AABoQWZmkELNxABGCAA=","preamble":85,"sender":1219,"sid":{"code":0,"sat":8}}})), "raw_json");
}
test_auto_check_sbp_acquisition_msg_acq_result_1();

done_testing();
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/perl -w
#
# Copyright (C) 2015-2023 Swift Navigation Inc.
# Contact: https://support.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.
#
# Test cases automatically generated from spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqSvProfile.yaml
# with generate.py. Do not modify by hand!

use strict;

BEGIN {
# add grandparent directory to include path
use Cwd qw(realpath);
use File::Basename;
unshift @INC, realpath(dirname($0))."/../../";
}

use KaitaiSbp::Sbp;
use KaitaiSbp::ParseUtils;
use IO::KaitaiStruct;
use Test::More;
use JSON::PP;
use MIME::Base64;
sub test_auto_check_sbp_acquisition_msg_acq_sv_profile_1() {
my $buf = decode_base64("VS4AwwRjBw0mAGEWAK4ANAAAADEAAAA9AAAAkwAAAC8AAACMAAAAptI7AP0XAXkAvgAAAK8AAACvAAAAjgAAAO0AAAAMAAAAflgVAJkYAAgAggAAAKwAAABbAAAAvwAAAFQAAABSAAAAqLE=");
my $stream = IO::KaitaiStruct::Stream->new($buf);
my $msg = ParseUtils::get_flattened_msg(Sbp::SbpMessage->new($stream));

is($msg->{'crc'}, 0xb1a8, "crc");

is($msg->{'length'}, 99, "length");

is($msg->{'msg_type'}, 0x2e, "msg_type");

is($msg->{'payload'}, "Bw0mAGEWAK4ANAAAADEAAAA9AAAAkwAAAC8AAACMAAAAptI7AP0XAXkAvgAAAK8AAACvAAAAjgAAAO0AAAAMAAAAflgVAJkYAAgAggAAAKwAAABbAAAAvwAAAFQAAABSAAAA", "payload");

is($msg->{'preamble'}, 0x55, "preamble");

is($msg->{'sender'}, 0x04c3, "sender");

my $json = JSON::PP->new->convert_blessed->canonical;

is($json->encode($msg->acq_sv_profile()), $json->encode($json->decode(q{[{"bin_width":174,"cf":47,"cf_max":147,"cf_min":61,"cn0":38,"cp":140,"int_time":97,"job_type":7,"sid":{"code":0,"sat":22},"status":13,"time_spent":49,"timestamp":52},{"bin_width":121,"cf":237,"cf_max":142,"cf_min":175,"cn0":59,"cp":12,"int_time":253,"job_type":166,"sid":{"code":1,"sat":23},"status":210,"time_spent":175,"timestamp":190},{"bin_width":8,"cf":84,"cf_max":191,"cf_min":91,"cn0":21,"cp":82,"int_time":153,"job_type":126,"sid":{"code":0,"sat":24},"status":88,"time_spent":172,"timestamp":130}]})), "acq_sv_profile");

is($json->encode($msg), $json->encode($json->decode(q{{"acq_sv_profile":[{"bin_width":174,"cf":47,"cf_max":147,"cf_min":61,"cn0":38,"cp":140,"int_time":97,"job_type":7,"sid":{"code":0,"sat":22},"status":13,"time_spent":49,"timestamp":52},{"bin_width":121,"cf":237,"cf_max":142,"cf_min":175,"cn0":59,"cp":12,"int_time":253,"job_type":166,"sid":{"code":1,"sat":23},"status":210,"time_spent":175,"timestamp":190},{"bin_width":8,"cf":84,"cf_max":191,"cf_min":91,"cn0":21,"cp":82,"int_time":153,"job_type":126,"sid":{"code":0,"sat":24},"status":88,"time_spent":172,"timestamp":130}],"crc":45480,"length":99,"msg_type":46,"payload":"Bw0mAGEWAK4ANAAAADEAAAA9AAAAkwAAAC8AAACMAAAAptI7AP0XAXkAvgAAAK8AAACvAAAAjgAAAO0AAAAMAAAAflgVAJkYAAgAggAAAKwAAABbAAAAvwAAAFQAAABSAAAA","preamble":85,"sender":1219}})), "raw_json");
}
test_auto_check_sbp_acquisition_msg_acq_sv_profile_1();

done_testing();
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/perl -w
#
# Copyright (C) 2015-2023 Swift Navigation Inc.
# Contact: https://support.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.
#
# Test cases automatically generated from spec/tests/yaml/swiftnav/sbp/acquisition/test_MsgAcqSvProfileDep.yaml
# with generate.py. Do not modify by hand!

use strict;

BEGIN {
# add grandparent directory to include path
use Cwd qw(realpath);
use File::Basename;
unshift @INC, realpath(dirname($0))."/../../";
}

use KaitaiSbp::Sbp;
use KaitaiSbp::ParseUtils;
use IO::KaitaiStruct;
use Test::More;
use JSON::PP;
use MIME::Base64;
sub test_auto_check_sbp_acquisition_msg_acq_sv_profile_dep_1() {
my $buf = decode_base64("VR4AwwRpQ2eXAAwWAAAAuwBbAAAASwAAAIQAAAAkAAAAPAAAAPEAAADuJm8AsxcAAQCwAKYAAADqAAAAmwAAABgAAADUAAAA9wAAAI7VRAA1GAAAADQAMQAAAPUAAABMAAAA+AAAANQAAABlAAAAQ4Q=");
my $stream = IO::KaitaiStruct::Stream->new($buf);
my $msg = ParseUtils::get_flattened_msg(Sbp::SbpMessage->new($stream));

is($msg->{'crc'}, 0x8443, "crc");

is($msg->{'length'}, 105, "length");

is($msg->{'msg_type'}, 0x1e, "msg_type");

is($msg->{'payload'}, "Q2eXAAwWAAAAuwBbAAAASwAAAIQAAAAkAAAAPAAAAPEAAADuJm8AsxcAAQCwAKYAAADqAAAAmwAAABgAAADUAAAA9wAAAI7VRAA1GAAAADQAMQAAAPUAAABMAAAA+AAAANQAAABlAAAA", "payload");

is($msg->{'preamble'}, 0x55, "preamble");

is($msg->{'sender'}, 0x04c3, "sender");

my $json = JSON::PP->new->convert_blessed->canonical;

is($json->encode($msg->acq_sv_profile()), $json->encode($json->decode(q{[{"bin_width":187,"cf":60,"cf_max":36,"cf_min":132,"cn0":151,"cp":241,"int_time":12,"job_type":67,"sid":{"code":0,"reserved":0,"sat":22},"status":103,"time_spent":75,"timestamp":91},{"bin_width":176,"cf":212,"cf_max":24,"cf_min":155,"cn0":111,"cp":247,"int_time":179,"job_type":238,"sid":{"code":1,"reserved":0,"sat":23},"status":38,"time_spent":234,"timestamp":166},{"bin_width":52,"cf":212,"cf_max":248,"cf_min":76,"cn0":68,"cp":101,"int_time":53,"job_type":142,"sid":{"code":0,"reserved":0,"sat":24},"status":213,"time_spent":245,"timestamp":49}]})), "acq_sv_profile");

is($json->encode($msg), $json->encode($json->decode(q{{"acq_sv_profile":[{"bin_width":187,"cf":60,"cf_max":36,"cf_min":132,"cn0":151,"cp":241,"int_time":12,"job_type":67,"sid":{"code":0,"reserved":0,"sat":22},"status":103,"time_spent":75,"timestamp":91},{"bin_width":176,"cf":212,"cf_max":24,"cf_min":155,"cn0":111,"cp":247,"int_time":179,"job_type":238,"sid":{"code":1,"reserved":0,"sat":23},"status":38,"time_spent":234,"timestamp":166},{"bin_width":52,"cf":212,"cf_max":248,"cf_min":76,"cn0":68,"cp":101,"int_time":53,"job_type":142,"sid":{"code":0,"reserved":0,"sat":24},"status":213,"time_spent":245,"timestamp":49}],"crc":33859,"length":105,"msg_type":30,"payload":"Q2eXAAwWAAAAuwBbAAAASwAAAIQAAAAkAAAAPAAAAPEAAADuJm8AsxcAAQCwAKYAAADqAAAAmwAAABgAAADUAAAA9wAAAI7VRAA1GAAAADQAMQAAAPUAAABMAAAA+AAAANQAAABlAAAA","preamble":85,"sender":1219}})), "raw_json");
}
test_auto_check_sbp_acquisition_msg_acq_sv_profile_dep_1();

done_testing();
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/perl -w
#
# Copyright (C) 2015-2023 Swift Navigation Inc.
# Contact: https://support.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.
#
# Test cases automatically generated from spec/tests/yaml/swiftnav/sbp/bootload/test_MsgBootloaderHandshakeReq.yaml
# with generate.py. Do not modify by hand!

use strict;

BEGIN {
# add grandparent directory to include path
use Cwd qw(realpath);
use File::Basename;
unshift @INC, realpath(dirname($0))."/../../";
}

use KaitaiSbp::Sbp;
use KaitaiSbp::ParseUtils;
use IO::KaitaiStruct;
use Test::More;
use JSON::PP;
use MIME::Base64;
sub test_auto_check_sbp_bootload_msg_bootloader_handshake_req_1() {
my $buf = decode_base64("VbMAiPcAQdg=");
my $stream = IO::KaitaiStruct::Stream->new($buf);
my $msg = ParseUtils::get_flattened_msg(Sbp::SbpMessage->new($stream));

is($msg->{'crc'}, 0xd841, "crc");

is($msg->{'length'}, 0, "length");

is($msg->{'msg_type'}, 0xb3, "msg_type");

is($msg->{'payload'}, "", "payload");

is($msg->{'preamble'}, 0x55, "preamble");

is($msg->{'sender'}, 0xf788, "sender");

my $json = JSON::PP->new->convert_blessed->canonical;

is($json->encode($msg), $json->encode($json->decode(q{{"crc":55361,"length":0,"msg_type":179,"payload":"","preamble":85,"sender":63368}})), "raw_json");
}
test_auto_check_sbp_bootload_msg_bootloader_handshake_req_1();

done_testing();
Loading

0 comments on commit 7d18e77

Please sign in to comment.