-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addresses some of the comments in issue #14.
- Convert all values received by `Packet.parse_msg` to integers. - Replace `RadioPacket.sender` and `RadioPacket.destination` with lists of integers. Create corresponding functions for receiving hex and integer values. - Move commonly used stuff to `enocean.utils`
- Loading branch information
Showing
4 changed files
with
73 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- encoding: utf-8 -*- | ||
from __future__ import print_function, unicode_literals, division | ||
|
||
|
||
def _get_bit(byte, bit): | ||
''' Get bit value from byte ''' | ||
return (byte >> bit) & 0x01 | ||
|
||
|
||
def _combine_hex(data): | ||
''' Combine list of integer values to one big integer ''' | ||
output = 0x00 | ||
for i, d in enumerate(reversed(data)): | ||
output |= (d << i * 8) | ||
return output | ||
|
||
|
||
def _to_bitarray(data, width=8): | ||
''' Convert data (list of integers, bytearray or integer) to bitarray ''' | ||
if isinstance(data, list) or isinstance(data, bytearray): | ||
data = _combine_hex(data) | ||
return [True if digit == '1' else False for digit in bin(data)[2:].zfill(width)] | ||
|
||
|
||
def _from_bitarray(data): | ||
''' Convert bit array back to integer ''' | ||
return int(''.join(['1' if x else '0' for x in data]), 2) | ||
|
||
|
||
def _to_hex_string(data): | ||
''' Convert list of integers to a hex string, separated by ":" ''' | ||
if isinstance(data, int): | ||
return '%02X' % data | ||
return ':'.join([('%02X' % o) for o in data]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c2e3922
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.
a minor comment: the functions in
utils.py
are no more private and should not start with underscores anymorec2e3922
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.
Good point, fixing...