Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python client updates: materialization and tests. #96

Merged
merged 1 commit into from
Apr 13, 2015
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 23 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ MAKEFLAGS += SWIFTNAV_ROOT=$(SWIFTNAV_ROOT)
SBP_SPEC_DIR := $(SWIFTNAV_ROOT)/spec/yaml/swiftnav/sbp/
SBP_GEN_BIN := python sbpg/generator.py

.PHONY: help all c python docs pdf html
.PHONY: help all c python docs pdf html test

help:
@echo
Expand All @@ -16,13 +16,14 @@ help:
@echo " help to display this help message"
@echo " all to make SBP clients across all languages"
@echo " c to make C headers"
@echo " python to make Python bindings"
@echo " docs to make HTML and pdf documentation"
@echo " html to make all HTML language docs"
@echo " pdf to make SBP LaTeX datasheet"
@echo " docs to make HTML and pdf documentation"
@echo " python to make Python bindings"
@echo " test to run all tests"
@echo

all: c python docs
all: c python test docs

c:
@echo "Generating C headers..."
Expand Down Expand Up @@ -77,3 +78,21 @@ html:
cd $(SWIFTNAV_ROOT);
@echo
@echo "Finished!"

test:
@echo
@echo "Run tests..."
@echo
@echo "Running C tests..."
@echo
cd $(SWIFTNAV_ROOT)/c; \
mkdir -p build/ && cd build/; \
cmake ../; \
make test;
@echo
@echo "Running Python tests..."
@echo
cd $(SWIFTNAV_ROOT)/python/ && tox
cd $(SWIFTNAV_ROOT);
@echo
@echo "Finished!"
35 changes: 29 additions & 6 deletions generator/sbpg/targets/resources/sbp_construct_template.py.j2
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from construct import *
from sbp import SBP
from sbp.utils import fmt_repr
from sbp.utils import fmt_repr, exclude_fields
import six

((*- for i in include *))
Expand Down Expand Up @@ -80,6 +80,11 @@ class ((( m.identifier )))(object):
SBP_(((m.identifier))) = ((('0x%04X'|format(m.sbp_id))))
class ((( m.identifier | classnameify )))(SBP):
"""SBP class for message (((m.identifier))) ((('(0x%04X)'|format(m.sbp_id)))).

You can have (((m.identifier))) inherent its fields directly
from an inherited SBP object, or construct it inline using a dict
of its fields.

((* if m.desc *))
(((m.desc)))
((*- endif *))
Expand All @@ -88,6 +93,8 @@ class ((( m.identifier | classnameify )))(SBP):

Parameters
----------
sbp : SBP
SBP parent object to inherit from.
((*- for f in m.fields *))
(((f.identifier))) : (((f.type_id|pydoc)))
((*- if f.desc *))
Expand All @@ -104,23 +111,39 @@ class ((( m.identifier | classnameify )))(SBP):
((*- endfor *)))
((*- endif *))

def __init__(self, sbp):
self.__dict__.update(sbp.__dict__)
def __init__(self, sbp=None, **kwargs):
if sbp:
self.__dict__.update(sbp.__dict__)
((*- if m.fields *))
self.from_binary(sbp.payload)
self.from_binary(sbp.payload)
((*- else *))
self.payload = sbp.payload
self.payload = sbp.payload
((*- endif *))
((*- if m.fields*))
else:
((*- for f in m.fields *))
self.(((f.identifier))) = kwargs.pop('(((f.identifier)))')
((*- endfor *))
((*- endif *))

def __repr__(self):
return fmt_repr(self)
((* if m.fields *))
def from_binary(self, d):
"""Given a binary payload d, update the appropriate payload fields of
the message.

"""
p = ((( m.identifier | classnameify )))._parser.parse(d)
self.__dict__.update(dict(p.viewitems()))

def to_binary(self):
return ((( m.identifier | classnameify ))).build(self.__dict__)
"""Produce a framed/packed SBP message.

"""
c = Container(**exclude_fields(self))
self.payload = ((( m.identifier | classnameify )))._parser.build(c)
return self.pack()
((*- endif *))
((* endif *))
((*- else *))
Expand Down
47 changes: 37 additions & 10 deletions python/sbp/acquisition.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,28 @@
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.


"""
Satellite acquisition messages from the Piksi.
"""

from construct import *
from sbp import SBP
from sbp.utils import fmt_repr
from sbp.utils import fmt_repr, exclude_fields
import six

# Automatically generated from piksi/yaml/swiftnav/sbp/acquisition.yaml
# with generate.py at 2015-04-06 23:40:11.138411. Please do not hand edit!
# with generate.py at 2015-04-12 20:54:10.838143. Please do not hand edit!


SBP_MSG_ACQ_RESULT = 0x0015
class MsgAcqResult(SBP):
"""SBP class for message MSG_ACQ_RESULT (0x0015).

You can have MSG_ACQ_RESULT inherent its fields directly
from an inherited SBP object, or construct it inline using a dict
of its fields.


This message describes the results from an attempted GPS signal
acquisition search for a satellite PRN over a code phase/carrier
Expand All @@ -31,15 +41,17 @@ class MsgAcqResult(SBP):

Parameters
----------
sbp : SBP
SBP parent object to inherit from.
snr : float
SNR of best point.
SNR of best point
cp : float
Code phase of best point.
Code phase of best point
cf : float
Carrier frequency of best point.
Carrier frequency of best point
prn : int
PRN identifier of the satellite signal for which
acquisition was attempted.
acquisition was attempted


"""
Expand All @@ -49,19 +61,34 @@ class MsgAcqResult(SBP):
LFloat32('cf'),
ULInt8('prn'),)

def __init__(self, sbp):
self.__dict__.update(sbp.__dict__)
self.from_binary(sbp.payload)
def __init__(self, sbp=None, **kwargs):
if sbp:
self.__dict__.update(sbp.__dict__)
self.from_binary(sbp.payload)
else:
self.snr = kwargs.pop('snr')
self.cp = kwargs.pop('cp')
self.cf = kwargs.pop('cf')
self.prn = kwargs.pop('prn')

def __repr__(self):
return fmt_repr(self)

def from_binary(self, d):
"""Given a binary payload d, update the appropriate payload fields of
the message.

"""
p = MsgAcqResult._parser.parse(d)
self.__dict__.update(dict(p.viewitems()))

def to_binary(self):
return MsgAcqResult.build(self.__dict__)
"""Produce a framed/packed SBP message.

"""
c = Container(**exclude_fields(self))
self.payload = MsgAcqResult._parser.build(c)
return self.pack()


msg_classes = {
Expand Down