Sync
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
test/
|
||||
# ---> Python
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
@@ -15,7 +16,7 @@ dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
# lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
|
||||
Binary file not shown.
@@ -53,11 +53,6 @@ class caser:
|
||||
if self.device_hwid in port.hwid:
|
||||
logger.info(f"Found the correct port: {port.device}")
|
||||
return str(port.device)
|
||||
|
||||
def set_controller_capacity(self, capacity: int):
|
||||
'''Устанавливает количество доступных замков'''
|
||||
|
||||
|
||||
|
||||
def set_port_device(self, port_device=None):
|
||||
'''Устанавливает com port'''
|
||||
@@ -117,12 +112,30 @@ class caser:
|
||||
if confirm:
|
||||
try:
|
||||
return self.send_command(0, self.default_consts[True],
|
||||
self.default_consts["MANIPULATE_HEADER"],
|
||||
self.default_consts["READ_HEADER"],
|
||||
bytes_count=self.controller_capacity)
|
||||
except Exception as error:
|
||||
return str(error)
|
||||
else:
|
||||
return 1
|
||||
|
||||
def set_controller_capacity(self, capacity=0) -> str:
|
||||
'''Устанавливает количество доступных замков'''
|
||||
if capacity != 0:
|
||||
self.controller_capacity = capacity
|
||||
return self.controller_capacity
|
||||
else:
|
||||
# тут должно быть автоматическое определение кол-ва замков на контроллере
|
||||
# try:
|
||||
# return self.send_command(0, self.default_consts[True],
|
||||
# self.default_consts["MANIPULATE_HEADER"],
|
||||
# bytes_count=self.controller_capacity)
|
||||
# except Exception as error:
|
||||
# return str(error)
|
||||
pass
|
||||
|
||||
def watchdog(self):
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
#consts&confs
|
||||
42
lib/lomka.py
Normal file
42
lib/lomka.py
Normal file
@@ -0,0 +1,42 @@
|
||||
class BCCCalculator:
|
||||
"""
|
||||
Класс для работы с BCC
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def xor_bcc(data):
|
||||
"""XOR BCC"""
|
||||
if isinstance(data, str):
|
||||
data = data.encode('utf-8')
|
||||
elif isinstance(data, list):
|
||||
data = bytes(data)
|
||||
|
||||
bcc = 0
|
||||
for byte in data:
|
||||
bcc ^= byte
|
||||
return bcc
|
||||
|
||||
@staticmethod
|
||||
def sum_bcc(data):
|
||||
"""Суммирование BCC"""
|
||||
if isinstance(data, str):
|
||||
data = data.encode('utf-8')
|
||||
elif isinstance(data, list):
|
||||
data = bytes(data)
|
||||
|
||||
total = sum(data)
|
||||
return total & 0xFF
|
||||
|
||||
@staticmethod
|
||||
def verify_bcc(data_with_bcc):
|
||||
"""
|
||||
Проверка BCC в данных
|
||||
"""
|
||||
if len(data_with_bcc) < 2:
|
||||
return False
|
||||
|
||||
data = data_with_bcc[:-1]
|
||||
expected_bcc = data_with_bcc[-1]
|
||||
calculated_bcc = BCCCalculator.xor_bcc(data)
|
||||
|
||||
return expected_bcc == calculated_bcc
|
||||
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@@ -0,0 +1 @@
|
||||
pyserial
|
||||
Reference in New Issue
Block a user