|
1 | 1 | import struct |
2 | 2 | import logging |
3 | 3 | import io |
4 | | -import binascii |
5 | 4 | import time |
6 | 5 | try: |
7 | 6 | import queue |
@@ -458,7 +457,7 @@ def __init__(self, sdo_client, index, subindex=0): |
458 | 457 | self._done = False |
459 | 458 | self.sdo_client = sdo_client |
460 | 459 | self.pos = 0 |
461 | | - self._crc = 0 |
| 460 | + self._crc = sdo_client.crc_cls() |
462 | 461 | self._server_crc = None |
463 | 462 | self._ackseq = 0 |
464 | 463 |
|
@@ -523,9 +522,9 @@ def read(self, size=-1): |
523 | 522 | else: |
524 | 523 | data = response[1:8] |
525 | 524 | if self.crc_supported: |
526 | | - self._crc = binascii.crc_hqx(data, self._crc) |
| 525 | + self._crc.process(data) |
527 | 526 | if self._done: |
528 | | - if self._server_crc != self._crc: |
| 527 | + if self._server_crc != self._crc.final(): |
529 | 528 | self.sdo_client.abort(0x05040004) |
530 | 529 | raise SdoCommunicationError("CRC is not OK") |
531 | 530 | logger.info("CRC is OK") |
@@ -612,7 +611,7 @@ def __init__(self, sdo_client, index, subindex=0, size=None): |
612 | 611 | self.pos = 0 |
613 | 612 | self._done = False |
614 | 613 | self._seqno = 0 |
615 | | - self._crc = 0 |
| 614 | + self._crc = sdo_client.crc_cls() |
616 | 615 | self._last_bytes_sent = 0 |
617 | 616 | command = REQUEST_BLOCK_DOWNLOAD | INITIATE_BLOCK_TRANSFER | CRC_SUPPORTED |
618 | 617 | request = bytearray(8) |
@@ -694,7 +693,7 @@ def send(self, b, end=False): |
694 | 693 | self.pos += len(b) |
695 | 694 | if self.crc_supported: |
696 | 695 | # Calculate CRC |
697 | | - self._crc = binascii.crc_hqx(b, self._crc) |
| 696 | + self._crc.process(b) |
698 | 697 | if self._seqno >= self._blksize: |
699 | 698 | # End of this block, wait for ACK |
700 | 699 | self._block_ack() |
@@ -738,7 +737,7 @@ def close(self): |
738 | 737 | request[0] = command |
739 | 738 | if self.crc_supported: |
740 | 739 | # Add CRC |
741 | | - struct.pack_into("<H", request, 1, self._crc) |
| 740 | + struct.pack_into("<H", request, 1, self._crc.final()) |
742 | 741 | logger.debug("Ending block transfer...") |
743 | 742 | response = self.sdo_client.request_response(request) |
744 | 743 | res_command, = struct.unpack_from("B", response) |
|
0 commit comments