Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5a31370
Add benchmark for jit crc method
silverjam Feb 26, 2019
5f1dfb7
Change iterator behavior to support sbp2json
silverjam Feb 26, 2019
ed5dc63
Allow clients to wait on Handler thread exit
silverjam Feb 26, 2019
f36fa44
Add flake8 config
silverjam Feb 27, 2019
17ecd62
Generator for numba based parsing
silverjam Feb 27, 2019
ca4f942
Add generated sbp classess
silverjam Feb 27, 2019
d6e7d08
Add module for parsing packed float values
silverjam Feb 27, 2019
cd831f4
Fix get_f64() return value type float to double
pmiettinen Apr 3, 2019
e9a289b
Fix unit tests
pmiettinen Mar 25, 2019
d47e75b
Use standard_b64encode() to omit newlines
pmiettinen Apr 4, 2019
25cd75d
payload as str as in the original msg.py
pmiettinen Apr 4, 2019
3b305d7
Add preamble and sender elements
pmiettinen Apr 4, 2019
6705f78
Disregard null incase of get_fixed_string()
pmiettinen Apr 4, 2019
10991cb
Retain float precision metadata
pmiettinen Apr 4, 2019
fb8c06a
Handle setting string NULL delimiters
pmiettinen Apr 5, 2019
52af16d
Search for preamble
pmiettinen Apr 5, 2019
4c2b830
Do not return valid msg_type if crc is not in window
pmiettinen Apr 5, 2019
fa61a40
Implement _unpack_members() for message with no payload
pmiettinen Apr 5, 2019
99fc0d7
Streamline parse_members()
pmiettinen Apr 5, 2019
c69aea2
Fix get_fixed_array()
pmiettinen Apr 5, 2019
ebb3945
Use correct getter in get_fixed_array
pmiettinen Apr 9, 2019
c1545e7
Add payload size metadata
pmiettinen Apr 9, 2019
0425fb1
Do not discriminate messages with no payload
pmiettinen Apr 10, 2019
ff73ab4
Payload size fixes
pmiettinen Apr 10, 2019
3405374
Add comments to _payload_size()
pmiettinen Apr 10, 2019
6a9ae26
Decode bytes to strings
pmiettinen Apr 10, 2019
ed4b3f6
Add class variable switch for floating point meta
pmiettinen Apr 10, 2019
1a78481
Fix unit tests for strings
pmiettinen Apr 10, 2019
be5c991
Do not output numba types
pmiettinen Apr 17, 2019
60ee7f4
Add generated sbp.jit classes
pmiettinen Apr 4, 2019
5175a66
Add format and benchmark checks
pmiettinen Apr 15, 2019
268efca
set -e
pmiettinen Apr 15, 2019
7ebbf9d
Combine python and haskel-tools targets
pmiettinen Apr 15, 2019
f011049
More generic haskell installation dir
pmiettinen Apr 15, 2019
4c8a80e
Run sbp2prettyjson only if necessary
pmiettinen Apr 15, 2019
f24f1f9
Path to Haskell tools as a script argument
pmiettinen Apr 16, 2019
12a7365
Update cmd line argument
pmiettinen Apr 17, 2019
232b6c9
Fix log string
pmiettinen May 8, 2019
c412d6e
Update threshold from 2.0 to 1.8
pmiettinen May 8, 2019
4f52489
parse_float_c module build on import
pmiettinen May 10, 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
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
max-line-length = 120
28 changes: 14 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,27 @@ cache:
matrix:
include:
- env:
- TRAVIS_TARGET=python
- TRAVIS_TARGET=python-haskell
language: python
python: 3.7-dev
before_install:
- sudo apt-get -qq update
- sudo apt-get install python2.7 python2.7-dev
- sudo apt-get install python3.5 python3.5-dev
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
- sudo pip install tox
script: make test-python
- git clone https://github.com/swift-nav/piksi_tools.git ../piksi_tools
- git -C ../piksi_tools fetch
- git -C ../piksi_tools checkout silverjam/sbp2json
script: |
pushd haskell
docker build -t sbp2json .
docker run --rm --name sbp2json sbp2json >sbp_linux_tools.tar
tar xf sbp_linux_tools.tar
gzip sbp_linux_tools.tar
ls -l
popd
make test-python
- env:
- TRAVIS_TARGET=default JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
before_install:
Expand All @@ -54,18 +66,6 @@ matrix:
- npm install -g mocha
- npm install
script: make test-c test-haskell test-java test-javascript
- env:
- TRAVIS_TARGET=haskell-tools
before_install: |
sudo apt-get update
sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
script: |
pushd haskell
docker build -t sbp2json .
docker run --rm --name sbp2json sbp2json >sbp_linux_tools.tar
gzip sbp_linux_tools.tar
ls -l
popd

deploy:
provider: releases
Expand Down
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ docs: verify-prereq-docs pdf html

c: deps-c gen-c test-c
python: deps-python gen-python test-python
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
Expand Down Expand Up @@ -144,6 +145,15 @@ gen-python:
--python
$(call announce-end,"Finished generating Python bindings. Please check $(SWIFTNAV_ROOT)/python/sbp")

gen-pythonNG:
$(call announce-begin,"Generating Python bindings")
cd $(SWIFTNAV_ROOT)/generator; \
$(SBP_GEN_BIN) -i $(SBP_SPEC_DIR) \
-o $(SWIFTNAV_ROOT)/python/sbp/jit \
-r $(SBP_MAJOR_VERSION).$(SBP_MINOR_VERSION).$(SBP_PATCH_VERSION) \
--pythonNG
$(call announce-end,"Finished generating Python bindings. Please check $(SWIFTNAV_ROOT)/python/sbp")

gen-javascript:
$(call announce-begin,"Generating JavaScript bindings")
cd $(SWIFTNAV_ROOT)/generator; \
Expand Down Expand Up @@ -206,7 +216,7 @@ test-c:
test-python:
$(call announce-begin,"Running Python tests")
ifdef TRAVIS_TARGET
cd $(SWIFTNAV_ROOT)/python/ && tox
cd $(SWIFTNAV_ROOT)/python/ && tox -- $(SWIFTNAV_ROOT)/haskell
else
cd $(SWIFTNAV_ROOT)/python/ && tox --skip-missing-interpreters
endif
Expand Down
8 changes: 7 additions & 1 deletion generator/sbpg/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import sbpg.targets.haskell as hs
import sbpg.targets.protobuf as pb
import sbpg.targets.python as py
import sbpg.targets.pythonNG as pyNG
import sbpg.targets.javascript as js

def get_args():
Expand All @@ -42,6 +43,9 @@ def get_args():
parser.add_argument('--python',
action="store_true",
help='Target language: Python.')
parser.add_argument('--pythonNG',
action="store_true",
help='Target language: Python.')
parser.add_argument('--javascript',
action="store_true",
help='Target language: JavaScript.')
Expand Down Expand Up @@ -80,7 +84,7 @@ def main():
# Parse and validate arguments.
args = get_args().parse_args()
verbose = args.verbose
assert 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, \
"Please specify a target language."
input_file = os.path.abspath(args.input_file[0])
assert len(args.input_file) == 1
Expand Down Expand Up @@ -122,6 +126,8 @@ def main():
continue
if args.python:
py.render_source(output_dir, parsed)
if args.pythonNG:
pyNG.render_source(output_dir, parsed)
elif args.javascript:
js.render_source(output_dir, parsed)
elif args.c:
Expand Down
191 changes: 191 additions & 0 deletions generator/sbpg/targets/pythonNG.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
#!/usr/bin/env python
# Copyright (C) 2015 Swift Navigation Inc.
# Contact: Bhaskar Mookerji <mookerji@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.

"""Generator for Python target.

This module consumes the YAML spec and generates some message class
files.

"""

from sbpg.targets.templating import JENV, ACRONYMS
from sbpg.utils import comment_links
import copy

TEMPLATE_NAME = "sbp_numba.py.j2"

NUMBA_TYPE = {
'u8': 'u1',
'u16': 'u2',
'u32': 'u4',
'u64': 'u8',
's8': 'i1',
's16': 'i2',
's32': 'i4',
's64': 'i8',
'float': 'f4',
'double': 'f8',
}

NUMBA_GET_FN = {
'u8': 'get_u8',
'u16': 'get_u16',
'u32': 'get_u32',
'u64': 'get_u64',
's8': 'get_s8',
's16': 'get_s16',
's32': 'get_s32',
's64': 'get_s64',
'float': 'get_f32',
'double': 'get_f64',
}

NUMBA_TY_BYTES = {
'u8': 1,
'u16': 2,
'u32': 4,
'u64': 8,
's8': 1,
's16': 2,
's32': 4,
's64': 8,
'float': 4,
'double': 8,
}

PYDOC_CODE = {
'u8': 'int',
'u16': 'int',
'u32': 'int',
'u64': 'int',
's8': 'int',
's16': 'int',
's32': 'int',
's64': 'int',
'float': 'float',
'double': 'double',
}


def is_array():
return False


def numba_type(f):
if f.type_id == 'float':
return 'judicious_round(nb.' + NUMBA_TYPE[f.type_id] + \
'(__' + f.identifier + ')) if SBP.judicious_rounding else __' + f.identifier
else:
return '__' + f.identifier


def numba_size(f):
# the worst case 255 - 6 (header) - 2 (crc)
UNKNOWN_LEN = 255 - 6 - 2

if f.type_id in NUMBA_TY_BYTES:
return NUMBA_TY_BYTES[f.type_id]
elif f.type_id == 'string':
if f.options.get('size', None) is not None:
return f.options.get('size', None).value
return UNKNOWN_LEN
elif f.type_id == 'array':
# NOTE: arrays of arrays are not supported
t = f.options['fill'].value
count = f.options.get('size', None)
if count:
if t in NUMBA_TY_BYTES:
return "%d * %d" % (NUMBA_TY_BYTES[t], count.value)
else:
return t + "._payload_size() * %d" % (count.value)
else:
return UNKNOWN_LEN
else:
return f.type_id + '._payload_size()'


def numba_format(f):
if NUMBA_GET_FN.get(f.type_id, None):
return NUMBA_GET_FN.get(f.type_id)
elif f.type_id == 'string' and f.identifier == 'setting' and not f.options.get('size', None):
# setting string with null delimiters as a special case
return 'get_setting'
elif f.type_id == 'string' and f.options.get('size', None):
s = f.options.get('size', None).value
return 'get_fixed_string(%d)' % (s,)
elif f.type_id == 'string' and not f.options.get('size', None):
return 'get_string'
elif f.type_id == 'array' and f.options.get('size', None):
count = f.options.get('size', None).value
t = f.options['fill'].value
if t in NUMBA_GET_FN:
fill_func = NUMBA_GET_FN[t]
el_size = NUMBA_TY_BYTES[t]
if f.options['fill'].value == 'float':
return "get_fixed_array(%s, %d, %d, %s if SBP.judicious_rounding else None)" \
% (fill_func, count, el_size, 'nb.f4')
else:
return "get_fixed_array(%s, %d, %d)" % (fill_func, count, el_size)
else:
fill_func = f.options['fill'].value + '._unpack_members'
el_size = f.options['fill'].value + '._payload_size()'
return "get_fixed_array(%s, %d, %s)" % (fill_func, count, el_size)
elif f.type_id == 'array':
fill = f.options['fill'].value
f_ = copy.copy(f)
f_.type_id = fill
return "get_array(%s)" % (numba_format(f_),)
else:
return '%s.parse_members' % (f.type_id)
raise NotImplementedError()


def pydoc_format(type_id, pydoc=PYDOC_CODE):
"""
Formats type for pydoc.
"""
return pydoc.get(type_id, type_id)


def classnameify(s):
"""
Makes a classname.
"""
return ''.join(w if w in ACRONYMS else w.title() for w in s.split('_'))


JENV.filters['numba_py'] = numba_format
JENV.filters['numba_type'] = numba_type
JENV.filters['numba_size'] = numba_size
JENV.filters['classnameify'] = classnameify
JENV.filters['pydoc'] = pydoc_format
JENV.filters['comment_links'] = comment_links


def render_source(output_dir, package_spec, jenv=JENV):
"""
Render and output
"""
path, name = package_spec.filepath
directory = output_dir
destination_filename = "%s/%s.py" % (directory, name)
py_template = jenv.get_template(TEMPLATE_NAME)
module_path = ".".join(package_spec.identifier.split(".")[1:-1])
includes = [".".join(i.split(".")[:-1]) for i in package_spec.includes]
includes = [i for i in includes if i != "types"]
print(destination_filename, includes)
with open(destination_filename, 'w') as f:
f.write(py_template.render(msgs=package_spec.definitions,
filepath="/".join(package_spec.filepath) + ".yaml",
module_path=module_path,
include=includes,
timestamp=package_spec.creation_timestamp,
description=package_spec.description))
Loading