Commit bd620fc4 authored by Gallacchi Mattia's avatar Gallacchi Mattia
Browse files

Raise expection if read timeout expires

parent 61a8177a
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -44,6 +44,21 @@ test-pages:
    - poetry install --only main,doc
    - cd doc && poetry run make html

test-pytest:
  stage: test
  tags:
    - docker
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
      when: always
      allow_failure: false
  script:
    - poetry install --only main,test
    - poetry run pytest -s -v --junitxml="test_result.xml" tests/
  artifacts:
    paths:
      - "tests/test_result.xml"

deploy-job:      # This job runs only when the merge is accepted
  stage: deploy  # It only runs when *both* jobs in the test stage complete successfully.
  tags:
+1 −1
Original line number Diff line number Diff line
[tool.poetry]
name = "pyrsvp"
version = "0.2.2"
version = "0.2.3"
description = "Implements RSVP communication protocol in Python"
authors = ["Mattia Gallacchi <mattia.gallacchi@he-arc.ch>"]
readme = "README.md"
+10 −6
Original line number Diff line number Diff line
@@ -170,6 +170,8 @@ class RsvpClientTcp(RsvpClient):
        ------
        RsvpTimeoutExpired : If while sending or receiving data the timeout expires
        RsvpClientInvalidCallback: If something is wrong with the callback
        RsvpMalformedReply: If the reply is not as expected
        RsvpNotAck: If the server didn't acknowledged
        """

        self.__connect()
@@ -202,7 +204,7 @@ class RsvpClientTcp(RsvpClient):
class RsvpClientSerial(RsvpClient):
    """RsvpClient using Serial as transport layer"""

    def __init__(self, port: str = "ttyUSB0", baud: int = 115200):
    def __init__(self, port: str = "ttyUSB0", baud: int = 115200, timeout=1.0):
        """RsvpClientSerial constructor

        Params
@@ -217,7 +219,7 @@ class RsvpClientSerial(RsvpClient):
        self.ser.port = port
        self.ser.baudrate = baud
        self.ser.write_timeout = 1.0
        self.ser.timeout = 1.0
        self.ser.timeout = timeout

        try:
            self.ser.open()
@@ -251,6 +253,7 @@ class RsvpClientSerial(RsvpClient):
        RsvpTimeoutExpired : If while sending or receiving data the timeout expires
        RsvpNotAck: If the server didn't acknowledged
        RsvpClientInvalidCallback: If something is wrong with the callback
        RsvpMalformedReply: If the reply is not as expected
        """

        cmd = self._build_command(cmd_name, args)
@@ -260,10 +263,11 @@ class RsvpClientSerial(RsvpClient):
        except serial.SerialTimeoutException as ex:
            raise RsvpTimeoutExpired(ex.__str__()) from ex

        try:
        data = self.ser.readline().strip()
        except serial.SerialTimeoutException as ex:
            raise RsvpTimeoutExpired(ex.__str__()) from ex
        if len(data) < 1:
            raise RsvpTimeoutExpired(
                f"No data was received and the timeout expired. Try to change the timeout value to fix this issue"
            )

        data = self._check_response(cmd_name, data.decode())