From c510df3154cda140199ef5f5b593e11ab2a1e96a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 18 Apr 2024 18:38:50 +0200 Subject: [PATCH] continue networking code --- pytmtc/tcp_server.py | 6 +++++- pytmtc/tests/server-test.py | 5 ++--- scripts/bld-deploy-remote.py | 12 ++++++------ src/interface/tcp_spp_client.rs | 5 +++-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/pytmtc/tcp_server.py b/pytmtc/tcp_server.py index 14cd551..1e4570f 100644 --- a/pytmtc/tcp_server.py +++ b/pytmtc/tcp_server.py @@ -1,5 +1,6 @@ from typing import Any, Optional import socket +import logging from threading import Thread, Event, Lock from collections import deque @@ -7,6 +8,9 @@ from tmtccmd.com import ComInterface from tmtccmd.tmtc import TelemetryListT +_LOGGER = logging.getLogger(__name__) + + class TcpServer(ComInterface): def __init__(self, port: int): self.port = port @@ -56,7 +60,7 @@ class TcpServer(ComInterface): while True and not self._kill_signal.is_set(): self._server_socket.listen() (conn_socket, conn_addr) = self._server_socket.accept() - print("TCP client {} connected", conn_addr) + _LOGGER.info("TCP client {} connected", conn_addr) while True: bytes_recvd = conn_socket.recv(4096) if len(bytes_recvd) > 0: diff --git a/pytmtc/tests/server-test.py b/pytmtc/tests/server-test.py index 5761687..da8b67e 100755 --- a/pytmtc/tests/server-test.py +++ b/pytmtc/tests/server-test.py @@ -17,17 +17,16 @@ def main(): while True: server_socket.listen() (conn_socket, conn_addr) = server_socket.accept() - print("TCP client {} connected", conn_addr) + print(f"TCP client {conn_addr} connected") while True: bytes_recvd = conn_socket.recv(4096) if len(bytes_recvd) > 0: - print(f"Received bytes from TCP client: {bytes_recvd.decode()}") + print(f"Received bytes from TCP client: {bytes_recvd}") elif len(bytes_recvd) == 0: break else: print("error receiving data from TCP client") if SEND_PING_ONCE: - print("sending back ping") ping_tc = PusTelecommand(service=17, subservice=1, seq_count=0, apid=APID) conn_socket.sendall(ping_tc.pack()) SEND_PING_ONCE = False diff --git a/scripts/bld-deploy-remote.py b/scripts/bld-deploy-remote.py index 9bce107..e208083 100755 --- a/scripts/bld-deploy-remote.py +++ b/scripts/bld-deploy-remote.py @@ -4,7 +4,6 @@ on a remote machine, e.g. a Raspberry Pi""" import argparse import os import sys -import platform import time from typing import Final @@ -16,10 +15,10 @@ BUILDER = "cross" # remote configurations by tweaking / hardcoding these parameter, which generally are constant # for a given board DEFAULT_USER_NAME: Final = "root" -DEFAULT_ADDRESS: Final = "192.254.108.30" +DEFAULT_ADDRESS: Final = "small_flatsat" DEFAULT_TOOLCHAIN: Final = "armv7-unknown-linux-gnueabihf" DEFAULT_APP_NAME: Final = "ops-sat-rs" -DEFAULT_TARGET_FOLDER: Final = "/tmp" +DEFAULT_TARGET_FOLDER: Final = "/home/exp278/" DEFAULT_DEBUG_PORT: Final = "1234" DEFAULT_GDB_APP = "gdb-multiarch" @@ -140,10 +139,11 @@ def bld_deploy_run(args): sshpass_args = f"-f {args.sshfile}" elif args.sshenv: sshpass_args = "-e" - ssh_target_ident = f"{args.user}@{args.address}" + # ssh_target_ident = f"{args.user}@{args.address}" + ssh_target_ident = "small_flatsat" sshpass_cmd = "" - if platform.system() != "Windows": - sshpass_cmd = f"sshpass {sshpass_args}" + # if platform.system() != "Windows": + # sshpass_cmd = f"sshpass {sshpass_args}" dest_path = f"{args.dest}/{args.app}" if not args.source: source_path = f"{os.getcwd()}/target/{args.tc}/{build_folder}/{args.app}" diff --git a/src/interface/tcp_spp_client.rs b/src/interface/tcp_spp_client.rs index 3b55cbb..186491a 100644 --- a/src/interface/tcp_spp_client.rs +++ b/src/interface/tcp_spp_client.rs @@ -89,14 +89,15 @@ impl TcpSppClient { } pub fn handle_client_operation(&mut self, client: &mut TcpStream) -> Result<(), ClientError> { - self.read_from_server(client)?; self.write_to_server(client)?; + client.shutdown(std::net::Shutdown::Write)?; + self.read_from_server(client)?; Ok(()) } pub fn read_from_server(&mut self, client: &mut TcpStream) -> Result<(), ClientError> { match client.read(&mut self.read_buf) { - Ok(0) => return Err(io::Error::from(io::ErrorKind::BrokenPipe).into()), + Ok(0) => (), Ok(read_bytes) => self.handle_read_bytstream(read_bytes)?, Err(e) => return Err(e.into()), }