-
Notifications
You must be signed in to change notification settings - Fork 197
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
Bug fixes, send/receive debug logs and Unsigned 24 support #267
base: master
Are you sure you want to change the base?
Changes from 1 commit
5141b19
3ce8ab4
bc06df4
3fb146e
659899d
9b9efb7
a8fcd87
d0d9bba
b14f43e
56b206a
a108eee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -219,6 +219,17 @@ def add_member(self, variable): | |
self.subindices[variable.subindex] = variable | ||
self.names[variable.name] = variable | ||
|
||
class Unsigned24(struct.Struct): | ||
def __init__(self, *args, **kwargs): | ||
super(Unsigned24, self).__init__("<I", *args, **kwargs) | ||
|
||
def unpack(self, data, *args, **kwargs): | ||
if isinstance(data, bytearray): | ||
while len(data) < 4: | ||
data += b'\x00' | ||
else: | ||
logger.error(f"Unsigned24.unpack received wrong type - {type(data)}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
return super(Unsigned24, self).unpack(data, *args, **kwargs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another |
||
|
||
class Variable(object): | ||
"""Simple variable.""" | ||
|
@@ -232,6 +243,7 @@ class Variable(object): | |
UNSIGNED8: struct.Struct("B"), | ||
UNSIGNED16: struct.Struct("<H"), | ||
UNSIGNED32: struct.Struct("<L"), | ||
UNSIGNED24: Unsigned24(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be ordered by size? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
UNSIGNED64: struct.Struct("<Q"), | ||
REAL32: struct.Struct("<f"), | ||
REAL64: struct.Struct("<d") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we still trying to support Python 2? If not, this can be shortened to just
super()
.Also, why does this use
I
(unsigned int) whereas regular 32-bit ints useL
(unsigned long)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the super thing.
This isn't an attempt to convert the uint24 to a regular 32-bit. The only reason I'm converting it to an
I
is because that's the closest data typesStruct
supports.Then I'm using
Struct.unpack("<I)
to make that 32-bit int to python int.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to look it up in the Python library docs, but as I see it, the
<L
and<I
formats are equivalent, both using four bytes for the conversion. So your code seems correct, just wondering why not use the same letter when it doesn't really make a difference?