Ejemplo n.º 1
0
class MsgDgnssStatus(SBP):
    """SBP class for message MSG_DGNSS_STATUS (0xFF02).

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

  
  This message provides information about the receipt of Differential
corrections.  It is expected to be sent with each receipt of a complete
corrections packet.


  Parameters
  ----------
  sbp : SBP
    SBP parent object to inherit from.
  flags : int
    Status flags
  latency : int
    Latency of observation receipt
  num_signals : int
    Number of signals from base station
  source : string
    Corrections source string
  sender : int
    Optional sender ID, defaults to SENDER_ID (see sbp/msg.py).

  """
    _parser = Struct(
        "MsgDgnssStatus",
        ULInt8('flags'),
        ULInt16('latency'),
        ULInt8('num_signals'),
        greedy_string('source'),
    )
    __slots__ = [
        'flags',
        'latency',
        'num_signals',
        'source',
    ]

    def __init__(self, sbp=None, **kwargs):
        if sbp:
            super(MsgDgnssStatus,
                  self).__init__(sbp.msg_type, sbp.sender, sbp.length,
                                 sbp.payload, sbp.crc)
            self.from_binary(sbp.payload)
        else:
            super(MsgDgnssStatus, self).__init__()
            self.msg_type = SBP_MSG_DGNSS_STATUS
            self.sender = kwargs.pop('sender', SENDER_ID)
            self.flags = kwargs.pop('flags')
            self.latency = kwargs.pop('latency')
            self.num_signals = kwargs.pop('num_signals')
            self.source = kwargs.pop('source')

    def __repr__(self):
        return fmt_repr(self)

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

    """
        d = json.loads(s)
        return MsgDgnssStatus.from_json_dict(d)

    @staticmethod
    def from_json_dict(d):
        sbp = SBP.from_json_dict(d)
        return MsgDgnssStatus(sbp, **d)

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

    """
        p = MsgDgnssStatus._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

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

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

    def to_json_dict(self):
        self.to_binary()
        d = super(MsgDgnssStatus, self).to_json_dict()
        j = walk_json_dict(exclude_fields(self))
        d.update(j)
        return d
Ejemplo n.º 2
0
class MsgFileioRemove(SBP):
    """SBP class for message MSG_FILEIO_REMOVE (0x00AC).

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

  
  The file remove message deletes a file from the file system.
If the message is invalid, a followup MSG_PRINT message will
print "Invalid fileio remove message". A device will only
process this message when it is received from sender ID 0x42.


  Parameters
  ----------
  sbp : SBP
    SBP parent object to inherit from.
  filename : string
    Name of the file to delete
  sender : int
    Optional sender ID, defaults to SENDER_ID (see sbp/msg.py).

  """
    _parser = Struct(
        "MsgFileioRemove",
        greedy_string('filename'),
    )
    __slots__ = [
        'filename',
    ]

    def __init__(self, sbp=None, **kwargs):
        if sbp:
            super(MsgFileioRemove,
                  self).__init__(sbp.msg_type, sbp.sender, sbp.length,
                                 sbp.payload, sbp.crc)
            self.from_binary(sbp.payload)
        else:
            super(MsgFileioRemove, self).__init__()
            self.msg_type = SBP_MSG_FILEIO_REMOVE
            self.sender = kwargs.pop('sender', SENDER_ID)
            self.filename = kwargs.pop('filename')

    def __repr__(self):
        return fmt_repr(self)

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

    """
        d = json.loads(s)
        return MsgFileioRemove.from_json_dict(d)

    @staticmethod
    def from_json_dict(d):
        sbp = SBP.from_json_dict(d)
        return MsgFileioRemove(sbp, **d)

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

    """
        p = MsgFileioRemove._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

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

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

    def to_json_dict(self):
        self.to_binary()
        d = super(MsgFileioRemove, self).to_json_dict()
        j = walk_json_dict(exclude_fields(self))
        d.update(j)
        return d
Ejemplo n.º 3
0
class MsgFileioWriteReq(SBP):
    """SBP class for message MSG_FILEIO_WRITE_REQ (0x00AD).

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

  
  The file write message writes a certain length (up to 255 bytes)
of data to a file at a given offset. Returns a copy of the
original MSG_FILEIO_WRITE_RESP message to check integrity of
the write. The sequence number in the request will be returned
in the response. If message is invalid, a followup MSG_PRINT
message will print "Invalid fileio write message". A device will
only  process this message when it is received from sender ID
0x42.


  Parameters
  ----------
  sbp : SBP
    SBP parent object to inherit from.
  sequence : int
    Write sequence number
  offset : int
    Offset into the file at which to start writing in bytes
  filename : string
    Name of the file to write to
  data : array
    Variable-length array of data to write
  sender : int
    Optional sender ID, defaults to SENDER_ID (see sbp/msg.py).

  """
    _parser = Struct(
        "MsgFileioWriteReq",
        ULInt32('sequence'),
        ULInt32('offset'),
        greedy_string('filename'),
        OptionalGreedyRange(ULInt8('data')),
    )
    __slots__ = [
        'sequence',
        'offset',
        'filename',
        'data',
    ]

    def __init__(self, sbp=None, **kwargs):
        if sbp:
            super(MsgFileioWriteReq,
                  self).__init__(sbp.msg_type, sbp.sender, sbp.length,
                                 sbp.payload, sbp.crc)
            self.from_binary(sbp.payload)
        else:
            super(MsgFileioWriteReq, self).__init__()
            self.msg_type = SBP_MSG_FILEIO_WRITE_REQ
            self.sender = kwargs.pop('sender', SENDER_ID)
            self.sequence = kwargs.pop('sequence')
            self.offset = kwargs.pop('offset')
            self.filename = kwargs.pop('filename')
            self.data = kwargs.pop('data')

    def __repr__(self):
        return fmt_repr(self)

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

    """
        d = json.loads(s)
        return MsgFileioWriteReq.from_json_dict(d)

    @staticmethod
    def from_json_dict(d):
        sbp = SBP.from_json_dict(d)
        return MsgFileioWriteReq(sbp, **d)

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

    """
        p = MsgFileioWriteReq._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

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

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

    def to_json_dict(self):
        self.to_binary()
        d = super(MsgFileioWriteReq, self).to_json_dict()
        j = walk_json_dict(exclude_fields(self))
        d.update(j)
        return d
Ejemplo n.º 4
0
class MsgFileioReadDirReq(SBP):
    """SBP class for message MSG_FILEIO_READ_DIR_REQ (0x00A9).

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

  
  The read directory message lists the files in a directory on the
device's onboard flash file system.  The offset parameter can be
used to skip the first n elements of the file list. Returns a
MSG_FILEIO_READ_DIR_RESP message containing the directory
listings as a NULL delimited list. The listing is chunked over
multiple SBP packets. The sequence number in the request will be
returned in the response.  If message is invalid, a followup
MSG_PRINT message will print "Invalid fileio read message".
A device will only respond to this message when it is received
from sender ID 0x42.


  Parameters
  ----------
  sbp : SBP
    SBP parent object to inherit from.
  sequence : int
    Read sequence number
  offset : int
    The offset to skip the first n elements of the file list

  dirname : string
    Name of the directory to list
  sender : int
    Optional sender ID, defaults to SENDER_ID (see sbp/msg.py).

  """
    _parser = Struct(
        "MsgFileioReadDirReq",
        ULInt32('sequence'),
        ULInt32('offset'),
        greedy_string('dirname'),
    )
    __slots__ = [
        'sequence',
        'offset',
        'dirname',
    ]

    def __init__(self, sbp=None, **kwargs):
        if sbp:
            super(MsgFileioReadDirReq,
                  self).__init__(sbp.msg_type, sbp.sender, sbp.length,
                                 sbp.payload, sbp.crc)
            self.from_binary(sbp.payload)
        else:
            super(MsgFileioReadDirReq, self).__init__()
            self.msg_type = SBP_MSG_FILEIO_READ_DIR_REQ
            self.sender = kwargs.pop('sender', SENDER_ID)
            self.sequence = kwargs.pop('sequence')
            self.offset = kwargs.pop('offset')
            self.dirname = kwargs.pop('dirname')

    def __repr__(self):
        return fmt_repr(self)

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

    """
        d = json.loads(s)
        return MsgFileioReadDirReq.from_json_dict(d)

    @staticmethod
    def from_json_dict(d):
        sbp = SBP.from_json_dict(d)
        return MsgFileioReadDirReq(sbp, **d)

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

    """
        p = MsgFileioReadDirReq._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

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

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

    def to_json_dict(self):
        self.to_binary()
        d = super(MsgFileioReadDirReq, self).to_json_dict()
        j = walk_json_dict(exclude_fields(self))
        d.update(j)
        return d
Ejemplo n.º 5
0
class MsgFileioReadReq(SBP):
    """SBP class for message MSG_FILEIO_READ_REQ (0x00A8).

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

  
  The file read message reads a certain length (up to 255 bytes)
from a given offset into a file, and returns the data in a
MSG_FILEIO_READ_RESP message where the message length field
indicates how many bytes were succesfully read.The sequence
number in the request will be returned in the response.
If the message is invalid, a followup MSG_PRINT message will
print "Invalid fileio read message". A device will only respond
to this message when it is received from sender ID 0x42.


  Parameters
  ----------
  sbp : SBP
    SBP parent object to inherit from.
  sequence : int
    Read sequence number
  offset : int
    File offset
  chunk_size : int
    Chunk size to read
  filename : string
    Name of the file to read from
  sender : int
    Optional sender ID, defaults to SENDER_ID (see sbp/msg.py).

  """
    _parser = Struct(
        "MsgFileioReadReq",
        ULInt32('sequence'),
        ULInt32('offset'),
        ULInt8('chunk_size'),
        greedy_string('filename'),
    )
    __slots__ = [
        'sequence',
        'offset',
        'chunk_size',
        'filename',
    ]

    def __init__(self, sbp=None, **kwargs):
        if sbp:
            super(MsgFileioReadReq,
                  self).__init__(sbp.msg_type, sbp.sender, sbp.length,
                                 sbp.payload, sbp.crc)
            self.from_binary(sbp.payload)
        else:
            super(MsgFileioReadReq, self).__init__()
            self.msg_type = SBP_MSG_FILEIO_READ_REQ
            self.sender = kwargs.pop('sender', SENDER_ID)
            self.sequence = kwargs.pop('sequence')
            self.offset = kwargs.pop('offset')
            self.chunk_size = kwargs.pop('chunk_size')
            self.filename = kwargs.pop('filename')

    def __repr__(self):
        return fmt_repr(self)

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

    """
        d = json.loads(s)
        return MsgFileioReadReq.from_json_dict(d)

    @staticmethod
    def from_json_dict(d):
        sbp = SBP.from_json_dict(d)
        return MsgFileioReadReq(sbp, **d)

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

    """
        p = MsgFileioReadReq._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

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

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

    def to_json_dict(self):
        self.to_binary()
        d = super(MsgFileioReadReq, self).to_json_dict()
        j = walk_json_dict(exclude_fields(self))
        d.update(j)
        return d
Ejemplo n.º 6
0
class MsgSettingsReadByIndexResp(SBP):
  """SBP class for message MSG_SETTINGS_READ_BY_INDEX_RESP (0x00A7).

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

  
  The settings message for iterating through the settings
values. It will read the setting at an index, returning a
NULL-terminated and delimited string with contents
[SECTION_SETTING, SETTING, VALUE].


  Parameters
  ----------
  sbp : SBP
    SBP parent object to inherit from.
  index : int
    An index into the device settings, with values ranging from
0 to length(settings)

  setting : string
    A NULL-terminated and delimited string with contents
[SECTION_SETTING, SETTING, VALUE].

  sender : int
    Optional sender ID, defaults to SENDER_ID (see sbp/msg.py).

  """
  _parser = Struct("MsgSettingsReadByIndexResp",
                   ULInt16('index'),
                   greedy_string('setting'),)
  __slots__ = [
               'index',
               'setting',
              ]

  def __init__(self, sbp=None, **kwargs):
    if sbp:
      super( MsgSettingsReadByIndexResp,
             self).__init__(sbp.msg_type, sbp.sender, sbp.length,
                            sbp.payload, sbp.crc)
      self.from_binary(sbp.payload)
    else:
      super( MsgSettingsReadByIndexResp, self).__init__()
      self.msg_type = SBP_MSG_SETTINGS_READ_BY_INDEX_RESP
      self.sender = kwargs.pop('sender', SENDER_ID)
      self.index = kwargs.pop('index')
      self.setting = kwargs.pop('setting')

  def __repr__(self):
    return fmt_repr(self)

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

    """
    d = json.loads(s)
    return MsgSettingsReadByIndexResp.from_json_dict(d)

  @staticmethod
  def from_json_dict(d):
    sbp = SBP.from_json_dict(d)
    return MsgSettingsReadByIndexResp(sbp, **d)

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

    """
    p = MsgSettingsReadByIndexResp._parser.parse(d)
    for n in self.__class__.__slots__:
      setattr(self, n, getattr(p, n))

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

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

  def to_json_dict(self):
    self.to_binary()
    d = super( MsgSettingsReadByIndexResp, self).to_json_dict()
    j = walk_json_dict(exclude_fields(self))
    d.update(j)
    return d
Ejemplo n.º 7
0
class MsgSettingsWrite(SBP):
  """SBP class for message MSG_SETTINGS_WRITE (0x00A0).

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

  
  The setting message writes the device configuration.

  Parameters
  ----------
  sbp : SBP
    SBP parent object to inherit from.
  setting : string
    A NULL-terminated and delimited string with contents
[SECTION_SETTING, SETTING, VALUE]. A device will only
process to this message when it is received from sender ID
0x42.

  sender : int
    Optional sender ID, defaults to SENDER_ID (see sbp/msg.py).

  """
  _parser = Struct("MsgSettingsWrite",
                   greedy_string('setting'),)
  __slots__ = [
               'setting',
              ]

  def __init__(self, sbp=None, **kwargs):
    if sbp:
      super( MsgSettingsWrite,
             self).__init__(sbp.msg_type, sbp.sender, sbp.length,
                            sbp.payload, sbp.crc)
      self.from_binary(sbp.payload)
    else:
      super( MsgSettingsWrite, self).__init__()
      self.msg_type = SBP_MSG_SETTINGS_WRITE
      self.sender = kwargs.pop('sender', SENDER_ID)
      self.setting = kwargs.pop('setting')

  def __repr__(self):
    return fmt_repr(self)

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

    """
    d = json.loads(s)
    return MsgSettingsWrite.from_json_dict(d)

  @staticmethod
  def from_json_dict(d):
    sbp = SBP.from_json_dict(d)
    return MsgSettingsWrite(sbp, **d)

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

    """
    p = MsgSettingsWrite._parser.parse(d)
    for n in self.__class__.__slots__:
      setattr(self, n, getattr(p, n))

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

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

  def to_json_dict(self):
    self.to_binary()
    d = super( MsgSettingsWrite, self).to_json_dict()
    j = walk_json_dict(exclude_fields(self))
    d.update(j)
    return d
Ejemplo n.º 8
0
class MsgCommandReq(SBP):
    """SBP class for message MSG_COMMAND_REQ (0x00B8).

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

  
  Request the recipient to execute an command.
Output will be sent in MSG_LOG messages, and the exit
code will be returned with MSG_COMMAND_RESP.


  Parameters
  ----------
  sbp : SBP
    SBP parent object to inherit from.
  sequence : int
    Sequence number
  command : string
    Command line to execute
  sender : int
    Optional sender ID, defaults to SENDER_ID (see sbp/msg.py).

  """
    _parser = Struct(
        "MsgCommandReq",
        ULInt32('sequence'),
        greedy_string('command'),
    )
    __slots__ = [
        'sequence',
        'command',
    ]

    def __init__(self, sbp=None, **kwargs):
        if sbp:
            super(MsgCommandReq,
                  self).__init__(sbp.msg_type, sbp.sender, sbp.length,
                                 sbp.payload, sbp.crc)
            self.from_binary(sbp.payload)
        else:
            super(MsgCommandReq, self).__init__()
            self.msg_type = SBP_MSG_COMMAND_REQ
            self.sender = kwargs.pop('sender', SENDER_ID)
            self.sequence = kwargs.pop('sequence')
            self.command = kwargs.pop('command')

    def __repr__(self):
        return fmt_repr(self)

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

    """
        d = json.loads(s)
        return MsgCommandReq.from_json_dict(d)

    @staticmethod
    def from_json_dict(d):
        sbp = SBP.from_json_dict(d)
        return MsgCommandReq(sbp, **d)

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

    """
        p = MsgCommandReq._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

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

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

    def to_json_dict(self):
        self.to_binary()
        d = super(MsgCommandReq, self).to_json_dict()
        j = walk_json_dict(exclude_fields(self))
        d.update(j)
        return d
Ejemplo n.º 9
0
class MsgLog(SBP):
    """SBP class for message MSG_LOG (0x0401).

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

  
  This message contains a human-readable payload string from the
device containing errors, warnings and informational messages at
ERROR, WARNING, DEBUG, INFO logging levels.


  Parameters
  ----------
  sbp : SBP
    SBP parent object to inherit from.
  level : int
    Logging level
  text : string
    Human-readable string
  sender : int
    Optional sender ID, defaults to SENDER_ID (see sbp/msg.py).

  """
    _parser = Struct(
        "MsgLog",
        ULInt8('level'),
        greedy_string('text'),
    )
    __slots__ = [
        'level',
        'text',
    ]

    def __init__(self, sbp=None, **kwargs):
        if sbp:
            super(MsgLog, self).__init__(sbp.msg_type, sbp.sender, sbp.length,
                                         sbp.payload, sbp.crc)
            self.from_binary(sbp.payload)
        else:
            super(MsgLog, self).__init__()
            self.msg_type = SBP_MSG_LOG
            self.sender = kwargs.pop('sender', SENDER_ID)
            self.level = kwargs.pop('level')
            self.text = kwargs.pop('text')

    def __repr__(self):
        return fmt_repr(self)

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

    """
        d = json.loads(s)
        return MsgLog.from_json_dict(d)

    @staticmethod
    def from_json_dict(d):
        sbp = SBP.from_json_dict(d)
        return MsgLog(sbp, **d)

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

    """
        p = MsgLog._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

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

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

    def to_json_dict(self):
        self.to_binary()
        d = super(MsgLog, self).to_json_dict()
        j = walk_json_dict(exclude_fields(self))
        d.update(j)
        return d
Ejemplo n.º 10
0
class MsgPrintDep(SBP):
    """SBP class for message MSG_PRINT_DEP (0x0010).

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

  
  Deprecated.

  Parameters
  ----------
  sbp : SBP
    SBP parent object to inherit from.
  text : string
    Human-readable string
  sender : int
    Optional sender ID, defaults to SENDER_ID (see sbp/msg.py).

  """
    _parser = Struct(
        "MsgPrintDep",
        greedy_string('text'),
    )
    __slots__ = [
        'text',
    ]

    def __init__(self, sbp=None, **kwargs):
        if sbp:
            super(MsgPrintDep, self).__init__(sbp.msg_type, sbp.sender,
                                              sbp.length, sbp.payload, sbp.crc)
            self.from_binary(sbp.payload)
        else:
            super(MsgPrintDep, self).__init__()
            self.msg_type = SBP_MSG_PRINT_DEP
            self.sender = kwargs.pop('sender', SENDER_ID)
            self.text = kwargs.pop('text')

    def __repr__(self):
        return fmt_repr(self)

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

    """
        d = json.loads(s)
        return MsgPrintDep.from_json_dict(d)

    @staticmethod
    def from_json_dict(d):
        sbp = SBP.from_json_dict(d)
        return MsgPrintDep(sbp, **d)

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

    """
        p = MsgPrintDep._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

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

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

    def to_json_dict(self):
        self.to_binary()
        d = super(MsgPrintDep, self).to_json_dict()
        j = walk_json_dict(exclude_fields(self))
        d.update(j)
        return d
Ejemplo n.º 11
0
class MsgFwd(SBP):
    """SBP class for message MSG_FWD (0x0402).

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

  
  This message provides the ability to forward messages over SBP.  This may take the form
of wrapping up SBP messages received by Piksi for logging purposes or wrapping 
another protocol with SBP.

The source identifier indicates from what interface a forwarded stream derived.
The protocol identifier identifies what the expected protocol the forwarded msg contains.
Protocol 0 represents SBP and the remaining values are implementation defined.


  Parameters
  ----------
  sbp : SBP
    SBP parent object to inherit from.
  source : int
    source identifier
  protocol : int
    protocol identifier
  fwd_payload : string
    variable length wrapped binary message
  sender : int
    Optional sender ID, defaults to SENDER_ID (see sbp/msg.py).

  """
    _parser = Struct(
        "MsgFwd",
        ULInt8('source'),
        ULInt8('protocol'),
        greedy_string('fwd_payload'),
    )
    __slots__ = [
        'source',
        'protocol',
        'fwd_payload',
    ]

    def __init__(self, sbp=None, **kwargs):
        if sbp:
            super(MsgFwd, self).__init__(sbp.msg_type, sbp.sender, sbp.length,
                                         sbp.payload, sbp.crc)
            self.from_binary(sbp.payload)
        else:
            super(MsgFwd, self).__init__()
            self.msg_type = SBP_MSG_FWD
            self.sender = kwargs.pop('sender', SENDER_ID)
            self.source = kwargs.pop('source')
            self.protocol = kwargs.pop('protocol')
            self.fwd_payload = kwargs.pop('fwd_payload')

    def __repr__(self):
        return fmt_repr(self)

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

    """
        d = json.loads(s)
        return MsgFwd.from_json_dict(d)

    @staticmethod
    def from_json_dict(d):
        sbp = SBP.from_json_dict(d)
        return MsgFwd(sbp, **d)

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

    """
        p = MsgFwd._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

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

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

    def to_json_dict(self):
        self.to_binary()
        d = super(MsgFwd, self).to_json_dict()
        j = walk_json_dict(exclude_fields(self))
        d.update(j)
        return d
Ejemplo n.º 12
0
class MsgBootloaderHandshakeResp(SBP):
    """SBP class for message MSG_BOOTLOADER_HANDSHAKE_RESP (0x00B4).

  You can have MSG_BOOTLOADER_HANDSHAKE_RESP inherit 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_REQ.  The
payload contains the bootloader version number and the SBP
protocol version number.


  Parameters
  ----------
  sbp : SBP
    SBP parent object to inherit from.
  flags : int
    Bootloader flags
  version : string
    Bootloader version number
  sender : int
    Optional sender ID, defaults to SENDER_ID (see sbp/msg.py).

  """
    _parser = Struct(
        "MsgBootloaderHandshakeResp",
        ULInt32('flags'),
        greedy_string('version'),
    )
    __slots__ = [
        'flags',
        'version',
    ]

    def __init__(self, sbp=None, **kwargs):
        if sbp:
            super(MsgBootloaderHandshakeResp,
                  self).__init__(sbp.msg_type, sbp.sender, sbp.length,
                                 sbp.payload, sbp.crc)
            self.from_binary(sbp.payload)
        else:
            super(MsgBootloaderHandshakeResp, self).__init__()
            self.msg_type = SBP_MSG_BOOTLOADER_HANDSHAKE_RESP
            self.sender = kwargs.pop('sender', SENDER_ID)
            self.flags = kwargs.pop('flags')
            self.version = kwargs.pop('version')

    def __repr__(self):
        return fmt_repr(self)

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

    """
        d = json.loads(s)
        return MsgBootloaderHandshakeResp.from_json_dict(d)

    @staticmethod
    def from_json_dict(d):
        sbp = SBP.from_json_dict(d)
        return MsgBootloaderHandshakeResp(sbp, **d)

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

    """
        p = MsgBootloaderHandshakeResp._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

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

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

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