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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ sbp_out.*

# Virtual Envs
/*env

RELEASE-VERSION
9 changes: 5 additions & 4 deletions c/include/libsbp/bootload.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@
* The handshake message response from the device establishes a
* handshake between the device bootloader and the host. The
* request from the host is MSG_BOOTLOADER_HANDSHAKE_HOST. The
* payload string contains the bootloader version number, but
* returns an empty string for earlier versions.
* payload contains the bootloader version number and the SBP
* protocol version number.
*/
#define SBP_MSG_BOOTLOADER_HANDSHAKE_DEVICE 0x00B0
#define SBP_MSG_BOOTLOADER_HANDSHAKE_DEVICE 0x00B4
typedef struct __attribute__((packed)) {
u8 handshake[0]; /**< Version number string (not NULL terminated) */
u32 flags; /**< Bootloader flags */
char* version; /**< Bootloader version number */
} msg_bootloader_handshake_device_t;


Expand Down
16 changes: 15 additions & 1 deletion c/include/libsbp/deprecated.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,25 @@
#include "common.h"


/** Bootloading handshake response (host <= device)
*
* The handshake message response from the device establishes a
* handshake between the device bootloader and the host. The
* request from the host is MSG_BOOTLOADER_HANDSHAKE_HOST. The
* payload string contains the bootloader version number, but
* returns an empty string for earlier versions.
*/
#define SBP_MSG_BOOTLOADER_HANDSHAKE_DEPRECATED 0x00B0
typedef struct __attribute__((packed)) {
u8 handshake[0]; /**< Version number string (not NULL terminated) */
} msg_bootloader_handshake_deprecated_t;


/** Deprecated
*
* Deprecated.
*/
#define SBP_MSG_EPHEMERIS_DEPRECATED 0x001A
#define SBP_MSG_EPHEMERIS_DEPRECATED 0x001A
typedef struct __attribute__((packed)) {
double tgd; /**< Group delay differential between L1 and L2 [s] */
double c_rs; /**< Amplitude of the sine harmonic correction term to the orbit radius [m] */
Expand Down
22 changes: 13 additions & 9 deletions python/sbp/bootload.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def __repr__(self):
return fmt_repr(self)


SBP_MSG_BOOTLOADER_HANDSHAKE_DEVICE = 0x00B0
SBP_MSG_BOOTLOADER_HANDSHAKE_DEVICE = 0x00B4
class MsgBootloaderHandshakeDevice(SBP):
"""SBP class for message MSG_BOOTLOADER_HANDSHAKE_DEVICE (0x00B0).
"""SBP class for message MSG_BOOTLOADER_HANDSHAKE_DEVICE (0x00B4).

You can have MSG_BOOTLOADER_HANDSHAKE_DEVICE inherent its fields directly
from an inherited SBP object, or construct it inline using a dict
Expand All @@ -71,22 +71,25 @@ class MsgBootloaderHandshakeDevice(SBP):
The handshake message response from the device establishes a
handshake between the device bootloader and the host. The
request from the host is MSG_BOOTLOADER_HANDSHAKE_HOST. The
payload string contains the bootloader version number, but
returns an empty string for earlier versions.
payload contains the bootloader version number and the SBP
protocol version number.


Parameters
----------
sbp : SBP
SBP parent object to inherit from.
handshake : array
Version number string (not NULL terminated)
flags : int
Bootloader flags
version : string
Bootloader version number
sender : int
Optional sender ID, defaults to 0

"""
_parser = Struct("MsgBootloaderHandshakeDevice",
OptionalGreedyRange(ULInt8('handshake')),)
ULInt32('flags'),
CString('version', six.b('\n')),)

def __init__(self, sbp=None, **kwargs):
if sbp:
Expand All @@ -96,7 +99,8 @@ def __init__(self, sbp=None, **kwargs):
super( MsgBootloaderHandshakeDevice, self).__init__()
self.msg_type = SBP_MSG_BOOTLOADER_HANDSHAKE_DEVICE
self.sender = kwargs.pop('sender', 0)
self.handshake = kwargs.pop('handshake')
self.flags = kwargs.pop('flags')
self.version = kwargs.pop('version')

def __repr__(self):
return fmt_repr(self)
Expand Down Expand Up @@ -315,7 +319,7 @@ def to_json_dict(self):

msg_classes = {
0x00B3: MsgBootloaderHandshakeHost,
0x00B0: MsgBootloaderHandshakeDevice,
0x00B4: MsgBootloaderHandshakeDevice,
0x00B1: MsgBootloaderJumpToApp,
0x00DE: MsgNapDeviceDnaHost,
0x00DD: MsgNapDeviceDnaDevice,
Expand Down
75 changes: 75 additions & 0 deletions python/sbp/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,80 @@
# Please do not hand edit!


SBP_MSG_BOOTLOADER_HANDSHAKE_DEPRECATED = 0x00B0
class MsgBootloaderHandshakeDeprecated(SBP):
"""SBP class for message MSG_BOOTLOADER_HANDSHAKE_DEPRECATED (0x00B0).

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


The handshake message response from the device establishes a
handshake between the device bootloader and the host. The
request from the host is MSG_BOOTLOADER_HANDSHAKE_HOST. The
payload string contains the bootloader version number, but
returns an empty string for earlier versions.


Parameters
----------
sbp : SBP
SBP parent object to inherit from.
handshake : array
Version number string (not NULL terminated)
sender : int
Optional sender ID, defaults to 0

"""
_parser = Struct("MsgBootloaderHandshakeDeprecated",
OptionalGreedyRange(ULInt8('handshake')),)

def __init__(self, sbp=None, **kwargs):
if sbp:
self.__dict__.update(sbp.__dict__)
self.from_binary(sbp.payload)
else:
super( MsgBootloaderHandshakeDeprecated, self).__init__()
self.msg_type = SBP_MSG_BOOTLOADER_HANDSHAKE_DEPRECATED
self.sender = kwargs.pop('sender', 0)
self.handshake = kwargs.pop('handshake')

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 = MsgBootloaderHandshakeDeprecated._parser.parse(d)
self.__dict__.update(dict(p.viewitems()))

def to_binary(self):
"""Produce a framed/packed SBP message.

"""
c = containerize(exclude_fields(self))
self.payload = MsgBootloaderHandshakeDeprecated._parser.build(c)
return self.pack()

@staticmethod
def from_json(s):
"""Given a JSON-encoded string s, build a message object.

"""
d = json.loads(s)
sbp = SBP.from_json_dict(d)
return MsgBootloaderHandshakeDeprecated(sbp)

def to_json_dict(self):
self.to_binary()
d = super( MsgBootloaderHandshakeDeprecated, self).to_json_dict()
j = walk_json_dict(exclude_fields(self))
d.update(j)
return d

SBP_MSG_EPHEMERIS_DEPRECATED = 0x001A
class MsgEphemerisDeprecated(SBP):
"""SBP class for message MSG_EPHEMERIS_DEPRECATED (0x001A).
Expand Down Expand Up @@ -195,5 +269,6 @@ def to_json_dict(self):


msg_classes = {
0x00B0: MsgBootloaderHandshakeDeprecated,
0x001A: MsgEphemerisDeprecated,
}
120 changes: 120 additions & 0 deletions python/sbp/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Douglas Creager <dcreager@dcreager.net>
# This file is placed into the public domain.
# Adapted from Gist: https://gist.github.com/3067886

# Calculates the current version number. If possible, this is the
# output of “git describe”, modified to conform to the versioning
# scheme that setuptools uses. If “git describe” returns an error
# (most likely because we're in an unpacked copy of a release tarball,
# rather than in a git working copy), then we fall back on reading the
# contents of the RELEASE-VERSION file.
#
# To use this script, simply import it your setup.py file, and use the
# results of get_git_version() as your package version:
#
# from version import *
#
# setup(
# version=get_git_version(),
# .
# .
# .
# )
#
# This will automatically update the RELEASE-VERSION file, if
# necessary. Note that the RELEASE-VERSION file should *not* be
# checked into git; please add it to your top-level .gitignore file.
#
# You'll probably want to distribute the RELEASE-VERSION file in your
# sdist tarballs; to do this, just create a MANIFEST.in file that
# contains the following line:
#
# include RELEASE-VERSION

__all__ = ("get_git_version")

from subprocess import Popen, PIPE
import os

def call_git_describe():
try:
p = Popen(['git', 'describe', '--tags', '--dirty', '--always'],
stdout=PIPE, stderr=PIPE)
p.stderr.close()
line = p.stdout.readlines()[0]
return line.strip()
except:
return None


def read_release_version():
try:
f = open(os.path.join(os.path.dirname(__file__), 'RELEASE-VERSION'), "r")
try:
version = f.readlines()[0]
return version.strip()
finally:
f.close()
except:
return None


def write_release_version(version):
f = open(os.path.join(os.path.dirname(__file__), 'RELEASE-VERSION'), "w")
f.write("%s\n" % version)
f.close()


def get_git_version():
# Read in the version that's currently in RELEASE-VERSION.
release_version = read_release_version()

# First try to get the current version using “git describe”.
version = call_git_describe()

# Take off the leading if present.
if version is not None and version[0] == 'v':
version = version[1:]

#adapt to PEP 386 compatible versioning scheme
version = pep386adapt(version)

# If that doesn't work, fall back on the value that's in
# RELEASE-VERSION.
if version is None:
version = release_version

# If we still don't have anything, that's an error.
if version is None:
raise ValueError("Cannot find the version number!")

# If the current version is different from what's in the
# RELEASE-VERSION file, update the file to be current.
if version != release_version:
write_release_version(version)

# Finally, return the current version.
return version


def pep386adapt(version):
if version is not None and '-' in version:
# adapt git-describe version to be in line with PEP 386
# Break PEP 386 a bit here and append the Git hash
parts = version.split('-')
if len(parts) > 2:
version = '%s.post%s-%s' % (
parts[0], parts[1],
'-'.join(parts[2:])
)
return version
else:
return version

VERSION = get_git_version()

if __name__ == "__main__":
print get_git_version()

8 changes: 6 additions & 2 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from setuptools import setup
import os

VERSION = "0.43"
from sbp.version import VERSION

CLASSIFIERS = [
'Intended Audience :: Developers',
Expand All @@ -30,6 +29,10 @@
'win32',
]

PACKAGE_DATA = { 'sbp' : [
'RELEASE-VERSION',
] }

cwd = os.path.abspath(os.path.dirname(__file__))
with open(cwd + '/README.rst') as f:
readme = f.read()
Expand All @@ -47,6 +50,7 @@
classifiers=CLASSIFIERS,
packages=PACKAGES,
platforms=PLATFORMS,
package_data=PACKAGE_DATA,
install_requires=INSTALL_REQUIRES,
use_2to3=False,
zip_safe=False)
2 changes: 1 addition & 1 deletion python/tests/sbp/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_table_count():
Test number of available messages to deserialize.

"""
number_of_messages = 51
number_of_messages = 52
assert len(_SBP_TABLE) == number_of_messages

def test_table_unqiue_count():
Expand Down
Loading