diff --git a/.gitignore b/.gitignore index 0dbf2f2..fcf0f30 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/controller_documentation/20231208_94d01600a8b0273f_440585560660_75100356767715_published_mp4_264_hd_taobao [20231208_94d01600a8b0273f_440585560660_75100356767715_published_mp4_264_hd_taobao].mp4 b/controller_documentation/20231208_94d01600a8b0273f_440585560660_75100356767715_published_mp4_264_hd_taobao [20231208_94d01600a8b0273f_440585560660_75100356767715_published_mp4_264_hd_taobao].mp4 new file mode 100644 index 0000000..43bfad3 Binary files /dev/null and b/controller_documentation/20231208_94d01600a8b0273f_440585560660_75100356767715_published_mp4_264_hd_taobao [20231208_94d01600a8b0273f_440585560660_75100356767715_published_mp4_264_hd_taobao].mp4 differ diff --git a/main.py b/lib/OCer.py similarity index 88% rename from main.py rename to lib/OCer.py index c614e93..fac91d5 100644 --- a/main.py +++ b/lib/OCer.py @@ -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 diff --git a/lib/lomka.py b/lib/lomka.py new file mode 100644 index 0000000..ff89c2d --- /dev/null +++ b/lib/lomka.py @@ -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 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f6c1a1f --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pyserial