Skip to content

Commit

Permalink
Patch for crash with string field as first field
Browse files Browse the repository at this point in the history
  • Loading branch information
LiamBindle committed Feb 4, 2017
1 parent f4c1ee8 commit d2be710
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions pyvesc/messages/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def unpack(msg_bytes):
msg_id = struct.unpack_from(VESCMessage._endian_fmt + VESCMessage._id_fmt, msg_bytes, 0)
msg_type = VESCMessage.msg_type(*msg_id)
data = None
if msg_type._string_field:
if not (msg_type._string_field is None):
# string field
fmt_wo_string = msg_type._fmt_fields.replace('%u', '')
fmt_wo_string = fmt_wo_string.replace('s', '')
len_string = len(msg_bytes) - struct.calcsize(VESCMessage._endian_fmt + fmt_wo_string) - 1
Expand All @@ -71,7 +72,7 @@ def unpack(msg_bytes):
else:
data = struct.unpack_from(VESCMessage._endian_fmt + msg_type._fmt_fields, msg_bytes, 1)
msg = msg_type(*data)
if msg_type._string_field:
if not (msg_type._string_field is None):
string_field_name = msg_type._field_names[msg_type._string_field]
setattr(msg,
string_field_name,
Expand All @@ -83,7 +84,8 @@ def pack(instance):
field_values = []
for field_name in instance._field_names:
field_values.append(getattr(instance, field_name))
if instance._string_field:
if not (instance._string_field is None):
# string field
string_field_name = instance._field_names[instance._string_field]
string_length = len(getattr(instance, string_field_name))
fmt = VESCMessage._endian_fmt + VESCMessage._id_fmt + (instance._fmt_fields % (string_length))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup

VERSION = '1.0.1'
VERSION = '1.0.2'

setup(
name = 'pyvesc',
Expand Down

0 comments on commit d2be710

Please sign in to comment.