|
6 | 6 | import logging
|
7 | 7 | import datetime
|
8 | 8 |
|
9 |
| -from PyCRC.CRC16Kermit import CRC16Kermit |
| 9 | +from utils import Crc |
10 | 10 | from multiprocessing import log_to_stderr
|
11 | 11 |
|
12 | 12 | from models import *
|
@@ -47,7 +47,7 @@ def __init__(
|
47 | 47 | self.pos_id = pos_id
|
48 | 48 | self.transaction = None
|
49 | 49 | self.my_key = key
|
50 |
| - self.poll_address = poll_address |
| 50 | + self.poll_address= poll_address |
51 | 51 | self.perpetual = perpetual
|
52 | 52 |
|
53 | 53 | # Init the Logging system
|
@@ -139,7 +139,7 @@ def open(self):
|
139 | 139 | raise SASOpenError
|
140 | 140 |
|
141 | 141 | def _conf_event_port(self):
|
142 |
| - """Do magick to make SAS Happy and work with their effing parity""" |
| 142 | + """Do magick to make SAS Happy and work with their effing wakeup bit""" |
143 | 143 | self.open()
|
144 | 144 | self.connection.flush()
|
145 | 145 | self.connection.timeout = self.poll_timeout
|
@@ -167,8 +167,7 @@ def _send_command(
|
167 | 167 | buf_header.extend(command)
|
168 | 168 |
|
169 | 169 | if crc_need:
|
170 |
| - crc = CRC16Kermit().calculate(bytearray(buf_header).decode("utf-8")) |
171 |
| - buf_header.extend([((crc >> 8) & 0xFF), (crc & 0xFF)]) |
| 170 | + buf_header.extend(Crc.calculate(bytes(buf_header))) |
172 | 171 |
|
173 | 172 | self.connection.write([self.poll_address, self.address])
|
174 | 173 |
|
@@ -210,12 +209,10 @@ def _check_response(rsp):
|
210 | 209 | if rsp == "":
|
211 | 210 | raise NoSasConnection
|
212 | 211 |
|
213 |
| - tmp_crc = binascii.hexlify(rsp[-2:]) |
214 |
| - crc1 = CRC16Kermit().calculate(rsp[0:-2]) |
215 |
| - crc1 = hex(crc1).zfill(4) |
216 |
| - crc1 = bytes(crc1, "utf-8")[2:] |
| 212 | + mac_crc = [int.from_bytes(rsp[-2:-1]), int.from_bytes(rsp[-1:])] |
| 213 | + my_crc = Crc.calculate(rsp[0:-2]) |
217 | 214 |
|
218 |
| - if tmp_crc != crc1: |
| 215 | + if mac_crc != my_crc: |
219 | 216 | raise BadCRC(binascii.hexlify(rsp))
|
220 | 217 | else:
|
221 | 218 | return rsp[1:-2]
|
|
0 commit comments