Преглед изворни кода

+ Refactored file format and updated serial port.

DLIMIKO пре 10 месеци
родитељ
комит
a3b1074243

+ 1 - 1
nbus_hal/crc8.py

@@ -18,7 +18,7 @@ crc8_table = [
 ]
 
 
-def crc8(data: list[int]) -> int:
+def crc8(data: bytes) -> int:
     """
     Create 8-bit cyclic redundancy code.
     :param data: input data

+ 19 - 3
nbus_hal/nbus_serial/serial_port.py

@@ -34,6 +34,10 @@ class NBusSerialPort(NBusPort):
     Class representing nBus serial port.
     """
     def __init__(self, config: NBusSerialConfig):
+        """
+        Constructor.
+        :param config: configuration
+        """
         self._port = serial.Serial(timeout=config.timeout)
         self._port.port = config.port_name
         self._port.parity = config.parity.value
@@ -48,6 +52,18 @@ class NBusSerialPort(NBusPort):
     ================================================================================================================
     """
 
+    def change_configuration(self, config: NBusSerialConfig):
+        """
+        Change port configuration.
+        :param config: configuration
+        """
+        self._port.timeout = config.timeout
+        self._port.port = config.port_name
+        self._port.parity = config.parity.value
+        self._port.baudrate = config.baud.value
+        self._enable_log = config.enable_log
+        self._request_attempts = config.request_attempts
+
     def open(self) -> None:
         """
         Open port.
@@ -83,8 +99,8 @@ class NBusSerialPort(NBusPort):
         :param command: command id
         :param data: command data to send
         """
-        request = self._create_packet([0, 0, 0, command.value], data)
-        self._log("\tBRQ>", request)
+        request = self._create_packet(bytearray([0, 0, 0, command.value]), data)
+        self._log("\tBRQ>", list(request))
         self._port.write(request)  # send message
 
     def request_module(self, module_addr: NBusModuleAddress, command: NBusCommand, data: bytearray,
@@ -130,7 +146,7 @@ class NBusSerialPort(NBusPort):
         :return: response length | response
         """
         request = self._create_packet(bytearray([0, module, sensor, command]), data)  # create request
-        self._log('d', sensor, "\tRQ>", request)  # log request
+        self._log('d', sensor, "\tRQ>", list(request))  # log request
 
         counter = 0  # err. trials
 

+ 0 - 8
nbus_types/nbus_info_type.py

@@ -28,11 +28,3 @@ class NBusInfo:
     memory_id: Annotated[int, Is[lambda value: 0 <= value <= np.iinfo(np.uint64).max]]
     read_only_sensors: Annotated[int, Is[lambda value: 0 <= value <= 31]]
     read_write_sensors: Annotated[int, Is[lambda value: 0 <= value <= 31]]
-
-
-
-
-
-
-
-

+ 0 - 2
nbus_types/nbus_parameter_type.py

@@ -20,5 +20,3 @@ class NBusParameterID(Enum):
     PARAM_RANGE = 5
     PARAM_RANGE0 = 6
     PARAM_FILTER = 7
-
-

+ 1 - 1
nbus_types/nbus_sensor_count_type.py

@@ -15,4 +15,4 @@ class NBusSensorCount:
     :ivar read_write_count: count of read-write devices
     """
     read_only_count: Annotated[int, Is[lambda value: 0 <= value <= 31]]
-    read_write_count: Annotated[int, Is[lambda value: 0 <= value <= 31]]
+    read_write_count: Annotated[int, Is[lambda value: 0 <= value <= 31]]

+ 0 - 0
main.py → test.py