mirror of
https://github.com/undera/pylgbst.git
synced 2020-11-18 19:37:26 -08:00
* It's HUB ID * Rename file * Working with official doc * Some progress * AttachedIO msg * device action impl * some better device alert impl * restructuring * Some port commands handled * Some command feedback waiting * Some more request-reply things * Some more request-reply things * Reworked msg classes * Getting back to UTs * Getting back to UTs * Facing sync lock problems * Facing sync lock problems * Testing it * Covering more with tests * handle actions * Hub class is almost covered * done coverage for Hub * done coverage for MoveHub * Button is tested * remove debug server from examples * Current and voltage tested * color sensor basic test * cover tilt sensor * motor sensor tested * constant motor * motor is tested * hold_speed impl for motor * motor commands recorded * some cleanup * some cleanup * some cleanup * debug * debug * FIX a bug * acc/dec profiles figured out * UT motor ops * UT motor ops * Get rid of weird piggyback * fix UT * Fix encoding? * fix test mb * More robust * Checked demo works * cosmetics * cosmetics * Maybe better test * fetching and decoding some device caps * describing devs * describing devs works * Applying modes we've learned * Simple and extensible dev attach * Reworking peripherals based on modes * Applying modes we've learned * implemented getting sensor data * fixed port subscribe * Added led out cmds on vision sensor * Worked on color-distance sensor * Introduce some locking for consistency * Improved it all * Travis flags * improve * improve * improve docs
37 lines
760 B
Python
37 lines
760 B
Python
"""
|
|
This module offers some utilities, in a way they are work in both Python 2 and 3
|
|
"""
|
|
|
|
import binascii
|
|
import logging
|
|
import sys
|
|
from struct import unpack
|
|
|
|
if sys.version_info[0] == 2:
|
|
import Queue as queue
|
|
else:
|
|
import queue as queue
|
|
|
|
queue = queue # just to use it
|
|
|
|
|
|
def usbyte(seq, index):
|
|
return unpack("<B", seq[index:index + 1])[0]
|
|
|
|
|
|
def ushort(seq, index):
|
|
return unpack("<H", seq[index:index + 2])[0]
|
|
|
|
|
|
def usint(seq, index):
|
|
return unpack("<I", seq[index:index + 4])[0]
|
|
|
|
|
|
def str2hex(data): # we need it for python 2+3 compatibility
|
|
# if sys.version_info[0] == 3:
|
|
# data = bytes(data, 'ascii')
|
|
if not isinstance(data, bytes):
|
|
data = bytes(data, 'ascii')
|
|
hexed = binascii.hexlify(data)
|
|
return hexed
|