diff --git a/pyproject.toml b/pyproject.toml index 355a085..4cebc73 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "infuse_iot" -version = "0.3.0" +version = "0.4.0" authors = [{name = "Embeint Holdings Pty Ltd", email = "support@embeint.com"}] description = "Infuse-IoT Platform python package" classifiers = [ diff --git a/src/infuse_iot/serial_comms.py b/src/infuse_iot/serial_comms.py index 2788ab1..568a818 100644 --- a/src/infuse_iot/serial_comms.py +++ b/src/infuse_iot/serial_comms.py @@ -62,6 +62,10 @@ def write(self, packet: bytes): def close(self): """Close the serial port""" + @abstractmethod + def __str__(self): + """Human readable description of the port""" + class SerialPort(SerialLike): """Serial Port handling""" @@ -78,23 +82,28 @@ def __init__(self, serial_port, baudrate=115200): def open(self): self._ser.open() - def read_bytes(self, num): + def read_bytes(self, num) -> bytes: return self._ser.read(num) - def ping(self): + def ping(self) -> None: self._ser.write(self._prefix + SerialFrame.SYNC + b"\x01\x00" + b"\x4d") self._ser.flush() - def write(self, packet: bytes): + def write(self, packet: bytes) -> None: # Add header pkt = self._prefix + SerialFrame.SYNC + len(packet).to_bytes(2, "little") + packet # Write packet to serial port self._ser.write(pkt) self._ser.flush() - def close(self): + def close(self) -> None: self._ser.close() + def __str__(self) -> str: + if self._ser.port: + return f"Serial: {self._ser.port}" + return "Serial: N/A" + class RttPort(SerialLike): """Segger RTT handling""" @@ -157,11 +166,15 @@ def close(self): self._modem_trace.flush() self._modem_trace.close() + def __str__(self) -> str: + return f"RTT: {self._name}" + class PyOcdPort(SerialLike): """PyOcd RTT handling""" def __init__(self, target: str): + self._name = target self._session = ConnectHelper.session_with_chosen_probe(auto_open=False, options={"target_override": target}) self._target = self._session.target self._rtt = GenericRTTControlBlock(self._target) @@ -191,3 +204,6 @@ def write(self, packet: bytes): def close(self): self._session.close() + + def __str__(self) -> str: + return f"PYOCD: {self._name}" diff --git a/src/infuse_iot/tools/gateway.py b/src/infuse_iot/tools/gateway.py index 2428ed2..08839b9 100644 --- a/src/infuse_iot/tools/gateway.py +++ b/src/infuse_iot/tools/gateway.py @@ -458,6 +458,7 @@ def __init__(self, args: argparse.Namespace): def run(self): # Open the serial port self.port.open() + Console.log_info(f"Port '{str(self.port)}' opened") # Ping the port to get the local device ID self.port.ping()