diff --git a/tools/demo.py b/tools/demo.py index ab2fbe2a..4a06c260 100755 --- a/tools/demo.py +++ b/tools/demo.py @@ -3,6 +3,8 @@ Example usage of the ODrive python library to monitor and control ODrive devices """ +from __future__ import print_function + import odrive.core import time import math diff --git a/tools/odrive/core.py b/tools/odrive/core.py index c4888de7..bda8b58e 100644 --- a/tools/odrive/core.py +++ b/tools/odrive/core.py @@ -174,7 +174,7 @@ def create_object(name, json_data, namespace, channel, printer=noprint): attributes[member_name] = attribute # Create a type from the property list and instantiate it - jit_type = type(namespace, (object,), attributes) + jit_type = type(str(namespace), (object,), attributes) new_object = jit_type() return new_object diff --git a/tools/odrive/protocol.py b/tools/odrive/protocol.py index 1f8c9114..9d69aa08 100644 --- a/tools/odrive/protocol.py +++ b/tools/odrive/protocol.py @@ -2,7 +2,18 @@ import time import struct -from abc import ABC, abstractmethod +import sys + +import abc + +if sys.version_info >= (3, 4): + ABC = abc.ABC +else: + ABC = abc.ABCMeta('ABC', (), {}) + +if sys.version_info <= (3, 3): + from monotonic import monotonic + time.monotonic = monotonic SYNC_BYTE = 0xAA CRC8_INIT = 0x42 @@ -30,6 +41,8 @@ def calc_crc(remainder, value, polynomial, bitwidth): def calc_crc8(remainder, value): if isinstance(value, bytearray) or isinstance(value, bytes) or isinstance(value, list): for byte in value: + if not isinstance(byte,int): + byte = ord(byte) remainder = calc_crc(remainder, byte, CRC8_DEFAULT, 8) else: remainder = calc_crc(remainder, byte, CRC8_DEFAULT, 8) @@ -38,6 +51,8 @@ def calc_crc8(remainder, value): def calc_crc16(remainder, value): if isinstance(value, bytearray) or isinstance(value, bytes) or isinstance(value, list): for byte in value: + if not isinstance(byte, int): + byte = ord(byte) remainder = calc_crc(remainder, byte, CRC16_DEFAULT, 16) else: remainder = calc_crc(remainder, value, CRC16_DEFAULT, 16) @@ -59,22 +74,22 @@ class DeviceInitException(Exception): class StreamSource(ABC): - @abstractmethod + @abc.abstractmethod def get_bytes(self, deadline): pass class StreamSink(ABC): - @abstractmethod + @abc.abstractmethod def process_bytes(self, bytes): pass class PacketSource(ABC): - @abstractmethod + @abc.abstractmethod def get_packet(self, deadline): pass class PacketSink(ABC): - @abstractmethod + @abc.abstractmethod def process_packet(self, packet): pass @@ -272,7 +287,7 @@ class Channel(PacketSink): self._expected_acks[seq_no] = packet[2:] else: - #if (calc_crc16(crc16, struct.pack('