Skip to content

Commit cceb733

Browse files
committed
- improved Santoker connection logging
- check only second CRC byte of Santoker packages - accept both, WiFi and BT, Santoker package headers independent of the connection type
1 parent 28a9364 commit cceb733

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/artisanlib/santoker.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,12 @@ def register_reading(self, target:bytes, data:bytes) -> None:
224224
_log.debug('register_reading(%s,%s)',target,value)
225225
if target == self.BOARD:
226226
self._board = value / 10.0
227-
elif target in {self.BT, self.OLD_BT}:
227+
elif target in (self.BT, self.OLD_BT):
228228
BT = value / 10.0
229229
self._bt = (BT if self._bt == -1 else (2*BT + self._bt)/3)
230-
_log.debug('BT: %s',self._bt)
231-
elif target in {self.ET, self.OLD_ET}:
230+
if self._logging:
231+
_log.debug('BT: %s',self._bt)
232+
elif target in (self.ET, self.OLD_ET):
232233
ET = value / 10.0
233234
self._et = (ET if self._et == -1 else (2*ET + self._et)/3)
234235
if self._logging:
@@ -299,7 +300,9 @@ async def read_msg(self, stream: Union[asyncio.StreamReader, IteratorReader]) ->
299300
# look for the first header byte
300301
await stream.readuntil(self.HEADER[0:1])
301302
# check for the second header byte
302-
if await stream.readexactly(1) != self.HEADER[1:2]:
303+
# if await stream.readexactly(1) != self.HEADER[1:2]:
304+
# return
305+
if await stream.readexactly(1) not in (self.HEADER_BT[1:2], self.HEADER_WIFI[1:2]): # we always accept both headers, the one for WiFi and the one for BT
303306
return
304307
# read the data target (BT, ET,..)
305308
target = await stream.readexactly(1)
@@ -316,7 +319,8 @@ async def read_msg(self, stream: Union[asyncio.StreamReader, IteratorReader]) ->
316319
crc = await stream.readexactly(2)
317320
calculated_crc = FramerRTU.compute_CRC(self.CODE_HEADER + data_len + data).to_bytes(2, 'big')
318321
# if self._verify_crc and crc != calculated_crc: # for whatever reason, the first byte of the received CRC is often wrongly just \x00
319-
if self._verify_crc and crc != calculated_crc and crc[0] != 0:
322+
# if self._verify_crc and crc != calculated_crc and crc[0] != 0: # we accept a 0 as first CRC bit always!
323+
if self._verify_crc and crc[1] != calculated_crc[1]: # we only check the second CRC bit!
320324
if self._logging:
321325
_log.debug('CRC error')
322326
return
@@ -349,6 +353,7 @@ def send_msg(self, target:bytes, value: int) -> None:
349353

350354
def start(self, connect_timeout:float=5) -> None:
351355
if self._connect_using_ble and hasattr(self, '_ble_client') and self._ble_client is not None:
356+
self._ble_client.setLogging(self._logging)
352357
self._ble_client.start(case_sensitive=False)
353358
else:
354359
super().start(connect_timeout)

src/requirements-dev.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ types-python-dateutil==2.9.0.20241206
77
types-pytz>=2025.1.0.20250204
88
types-pyyaml>=6.0.12.20241230
99
types-requests>=2.32.0.20250306
10-
types-setuptools>=75.8.2.20250305
10+
types-setuptools>=76.0.0.20250313
1111
types-urllib3>=1.26.25.14
1212
types-docutils>=0.21.0.20241128
1313
lxml-stubs>=0.5.1
1414
mypy==1.15.0
1515
pyright==1.1.396
16-
ruff>=0.9.10
16+
ruff>=0.10.0
1717
pylint==3.3.5
1818
pre-commit>=4.1.0
1919
pytest>=8.3.5
@@ -25,7 +25,7 @@ pytest-cov==6.0.0
2525
#pytest-bdd==6.1.1
2626
#pytest-benchmark==4.0.0
2727
#pytest-mock==3.11.1
28-
hypothesis>=6.128.2
28+
hypothesis>=6.129.1
2929
coverage>=7.6.12
3030
coverage-badge==1.1.2
3131
codespell==2.4.1

0 commit comments

Comments
 (0)